Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Driver |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2015 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 | |
| 31 | #ifdef CONFIG_SPARC |
| 32 | #include <asm/idprom.h> |
| 33 | #include <asm/prom.h> |
| 34 | #endif |
| 35 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 36 | /* Local includes */ |
| 37 | #include "i40e.h" |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 38 | #include "i40e_diag.h" |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 39 | #if IS_ENABLED(CONFIG_VXLAN) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 40 | #include <net/vxlan.h> |
| 41 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 42 | #if IS_ENABLED(CONFIG_GENEVE) |
| 43 | #include <net/geneve.h> |
| 44 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 45 | |
| 46 | const char i40e_driver_name[] = "i40e"; |
| 47 | static const char i40e_driver_string[] = |
| 48 | "Intel(R) Ethernet Connection XL710 Network Driver"; |
| 49 | |
| 50 | #define DRV_KERN "-k" |
| 51 | |
Catherine Sullivan | e8e724d | 2014-07-10 07:58:26 +0000 | [diff] [blame] | 52 | #define DRV_VERSION_MAJOR 1 |
Catherine Sullivan | 1c2df9e | 2015-10-21 19:56:24 -0400 | [diff] [blame] | 53 | #define DRV_VERSION_MINOR 4 |
Catherine Sullivan | 4f9e697 | 2015-12-10 11:38:51 -0800 | [diff] [blame] | 54 | #define DRV_VERSION_BUILD 10 |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 55 | #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ |
| 56 | __stringify(DRV_VERSION_MINOR) "." \ |
| 57 | __stringify(DRV_VERSION_BUILD) DRV_KERN |
| 58 | const char i40e_driver_version_str[] = DRV_VERSION; |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 59 | static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation."; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 60 | |
| 61 | /* a bit of forward declarations */ |
| 62 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi); |
| 63 | static void i40e_handle_reset_warning(struct i40e_pf *pf); |
| 64 | static int i40e_add_vsi(struct i40e_vsi *vsi); |
| 65 | 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] | 66 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 67 | static int i40e_setup_misc_vector(struct i40e_pf *pf); |
| 68 | static void i40e_determine_queue_usage(struct i40e_pf *pf); |
| 69 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 70 | static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 71 | u16 rss_table_size, u16 rss_size); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 72 | static void i40e_fdir_sb_setup(struct i40e_pf *pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 73 | static int i40e_veb_get_bw_info(struct i40e_veb *veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 74 | |
| 75 | /* i40e_pci_tbl - PCI Device ID Table |
| 76 | * |
| 77 | * Last entry must be all 0s |
| 78 | * |
| 79 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 80 | * Class, Class Mask, private data (not used) } |
| 81 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 82 | static const struct pci_device_id i40e_pci_tbl[] = { |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 83 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 84 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 85 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0}, |
| 86 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 87 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0}, |
| 88 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0}, |
| 89 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0}, |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 90 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0}, |
Shannon Nelson | bc5166b9 | 2015-08-26 15:14:10 -0400 | [diff] [blame] | 91 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0}, |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 92 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
Anjali Singhai Jain | 35dae51 | 2015-12-22 14:25:03 -0800 | [diff] [blame] | 93 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0}, |
| 94 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0}, |
Anjali Singhai Jain | 87e6c1d | 2015-06-05 12:20:25 -0400 | [diff] [blame] | 95 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0}, |
| 96 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0}, |
| 97 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0}, |
Shannon Nelson | 48a3b51 | 2015-07-23 16:54:39 -0400 | [diff] [blame] | 98 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
| 99 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0}, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 100 | /* required last entry */ |
| 101 | {0, } |
| 102 | }; |
| 103 | MODULE_DEVICE_TABLE(pci, i40e_pci_tbl); |
| 104 | |
| 105 | #define I40E_MAX_VF_COUNT 128 |
| 106 | static int debug = -1; |
| 107 | module_param(debug, int, 0); |
| 108 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 109 | |
| 110 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); |
| 111 | MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver"); |
| 112 | MODULE_LICENSE("GPL"); |
| 113 | MODULE_VERSION(DRV_VERSION); |
| 114 | |
| 115 | /** |
| 116 | * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code |
| 117 | * @hw: pointer to the HW structure |
| 118 | * @mem: ptr to mem struct to fill out |
| 119 | * @size: size of memory requested |
| 120 | * @alignment: what to align the allocation to |
| 121 | **/ |
| 122 | int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem, |
| 123 | u64 size, u32 alignment) |
| 124 | { |
| 125 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 126 | |
| 127 | mem->size = ALIGN(size, alignment); |
| 128 | mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size, |
| 129 | &mem->pa, GFP_KERNEL); |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 130 | if (!mem->va) |
| 131 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 132 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 133 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /** |
| 137 | * i40e_free_dma_mem_d - OS specific memory free for shared code |
| 138 | * @hw: pointer to the HW structure |
| 139 | * @mem: ptr to mem struct to free |
| 140 | **/ |
| 141 | int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) |
| 142 | { |
| 143 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 144 | |
| 145 | dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa); |
| 146 | mem->va = NULL; |
| 147 | mem->pa = 0; |
| 148 | mem->size = 0; |
| 149 | |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code |
| 155 | * @hw: pointer to the HW structure |
| 156 | * @mem: ptr to mem struct to fill out |
| 157 | * @size: size of memory requested |
| 158 | **/ |
| 159 | int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem, |
| 160 | u32 size) |
| 161 | { |
| 162 | mem->size = size; |
| 163 | mem->va = kzalloc(size, GFP_KERNEL); |
| 164 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 165 | if (!mem->va) |
| 166 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 167 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 168 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /** |
| 172 | * i40e_free_virt_mem_d - OS specific memory free for shared code |
| 173 | * @hw: pointer to the HW structure |
| 174 | * @mem: ptr to mem struct to free |
| 175 | **/ |
| 176 | int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem) |
| 177 | { |
| 178 | /* it's ok to kfree a NULL pointer */ |
| 179 | kfree(mem->va); |
| 180 | mem->va = NULL; |
| 181 | mem->size = 0; |
| 182 | |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * i40e_get_lump - find a lump of free generic resource |
| 188 | * @pf: board private structure |
| 189 | * @pile: the pile of resource to search |
| 190 | * @needed: the number of items needed |
| 191 | * @id: an owner id to stick on the items assigned |
| 192 | * |
| 193 | * Returns the base item index of the lump, or negative for error |
| 194 | * |
| 195 | * The search_hint trick and lack of advanced fit-finding only work |
| 196 | * because we're highly likely to have all the same size lump requests. |
| 197 | * Linear search time and any fragmentation should be minimal. |
| 198 | **/ |
| 199 | static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile, |
| 200 | u16 needed, u16 id) |
| 201 | { |
| 202 | int ret = -ENOMEM; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 203 | int i, j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 204 | |
| 205 | if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) { |
| 206 | dev_info(&pf->pdev->dev, |
| 207 | "param err: pile=%p needed=%d id=0x%04x\n", |
| 208 | pile, needed, id); |
| 209 | return -EINVAL; |
| 210 | } |
| 211 | |
| 212 | /* start the linear search with an imperfect hint */ |
| 213 | i = pile->search_hint; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 214 | while (i < pile->num_entries) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 215 | /* skip already allocated entries */ |
| 216 | if (pile->list[i] & I40E_PILE_VALID_BIT) { |
| 217 | i++; |
| 218 | continue; |
| 219 | } |
| 220 | |
| 221 | /* do we have enough in this lump? */ |
| 222 | for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) { |
| 223 | if (pile->list[i+j] & I40E_PILE_VALID_BIT) |
| 224 | break; |
| 225 | } |
| 226 | |
| 227 | if (j == needed) { |
| 228 | /* there was enough, so assign it to the requestor */ |
| 229 | for (j = 0; j < needed; j++) |
| 230 | pile->list[i+j] = id | I40E_PILE_VALID_BIT; |
| 231 | ret = i; |
| 232 | pile->search_hint = i + j; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 233 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 234 | } |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 235 | |
| 236 | /* not enough, so skip over it and continue looking */ |
| 237 | i += j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | return ret; |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * i40e_put_lump - return a lump of generic resource |
| 245 | * @pile: the pile of resource to search |
| 246 | * @index: the base item index |
| 247 | * @id: the owner id of the items assigned |
| 248 | * |
| 249 | * Returns the count of items in the lump |
| 250 | **/ |
| 251 | static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id) |
| 252 | { |
| 253 | int valid_id = (id | I40E_PILE_VALID_BIT); |
| 254 | int count = 0; |
| 255 | int i; |
| 256 | |
| 257 | if (!pile || index >= pile->num_entries) |
| 258 | return -EINVAL; |
| 259 | |
| 260 | for (i = index; |
| 261 | i < pile->num_entries && pile->list[i] == valid_id; |
| 262 | i++) { |
| 263 | pile->list[i] = 0; |
| 264 | count++; |
| 265 | } |
| 266 | |
| 267 | if (count && index < pile->search_hint) |
| 268 | pile->search_hint = index; |
| 269 | |
| 270 | return count; |
| 271 | } |
| 272 | |
| 273 | /** |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 274 | * i40e_find_vsi_from_id - searches for the vsi with the given id |
| 275 | * @pf - the pf structure to search for the vsi |
| 276 | * @id - id of the vsi it is searching for |
| 277 | **/ |
| 278 | struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id) |
| 279 | { |
| 280 | int i; |
| 281 | |
| 282 | for (i = 0; i < pf->num_alloc_vsi; i++) |
| 283 | if (pf->vsi[i] && (pf->vsi[i]->id == id)) |
| 284 | return pf->vsi[i]; |
| 285 | |
| 286 | return NULL; |
| 287 | } |
| 288 | |
| 289 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 290 | * i40e_service_event_schedule - Schedule the service task to wake up |
| 291 | * @pf: board private structure |
| 292 | * |
| 293 | * If not already scheduled, this puts the task into the work queue |
| 294 | **/ |
| 295 | static void i40e_service_event_schedule(struct i40e_pf *pf) |
| 296 | { |
| 297 | if (!test_bit(__I40E_DOWN, &pf->state) && |
| 298 | !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) && |
| 299 | !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state)) |
| 300 | schedule_work(&pf->service_task); |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * i40e_tx_timeout - Respond to a Tx Hang |
| 305 | * @netdev: network interface device structure |
| 306 | * |
| 307 | * If any port has noticed a Tx timeout, it is likely that the whole |
| 308 | * device is munged, not just the one netdev port, so go for the full |
| 309 | * reset. |
| 310 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 311 | #ifdef I40E_FCOE |
| 312 | void i40e_tx_timeout(struct net_device *netdev) |
| 313 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 314 | static void i40e_tx_timeout(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 315 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 316 | { |
| 317 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 318 | struct i40e_vsi *vsi = np->vsi; |
| 319 | struct i40e_pf *pf = vsi->back; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 320 | struct i40e_ring *tx_ring = NULL; |
| 321 | unsigned int i, hung_queue = 0; |
| 322 | u32 head, val; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 323 | |
| 324 | pf->tx_timeout_count++; |
| 325 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 326 | /* find the stopped queue the same way the stack does */ |
| 327 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 328 | struct netdev_queue *q; |
| 329 | unsigned long trans_start; |
| 330 | |
| 331 | q = netdev_get_tx_queue(netdev, i); |
| 332 | trans_start = q->trans_start ? : netdev->trans_start; |
| 333 | if (netif_xmit_stopped(q) && |
| 334 | time_after(jiffies, |
| 335 | (trans_start + netdev->watchdog_timeo))) { |
| 336 | hung_queue = i; |
| 337 | break; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | if (i == netdev->num_tx_queues) { |
| 342 | netdev_info(netdev, "tx_timeout: no netdev hung queue found\n"); |
| 343 | } else { |
| 344 | /* now that we have an index, find the tx_ring struct */ |
| 345 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 346 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 347 | if (hung_queue == |
| 348 | vsi->tx_rings[i]->queue_index) { |
| 349 | tx_ring = vsi->tx_rings[i]; |
| 350 | break; |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 356 | if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20))) |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 357 | pf->tx_timeout_recovery_level = 1; /* reset after some time */ |
| 358 | else if (time_before(jiffies, |
| 359 | (pf->tx_timeout_last_recovery + netdev->watchdog_timeo))) |
| 360 | return; /* don't do any new action before the next timeout */ |
| 361 | |
| 362 | if (tx_ring) { |
| 363 | head = i40e_get_head(tx_ring); |
| 364 | /* Read interrupt register */ |
| 365 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 366 | val = rd32(&pf->hw, |
| 367 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 368 | tx_ring->vsi->base_vector - 1)); |
| 369 | else |
| 370 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 371 | |
| 372 | 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", |
| 373 | vsi->seid, hung_queue, tx_ring->next_to_clean, |
| 374 | head, tx_ring->next_to_use, |
| 375 | readl(tx_ring->tail), val); |
| 376 | } |
| 377 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 378 | pf->tx_timeout_last_recovery = jiffies; |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 379 | netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n", |
| 380 | pf->tx_timeout_recovery_level, hung_queue); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 381 | |
| 382 | switch (pf->tx_timeout_recovery_level) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 383 | case 1: |
| 384 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 385 | break; |
| 386 | case 2: |
| 387 | set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 388 | break; |
| 389 | case 3: |
| 390 | set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 391 | break; |
| 392 | default: |
| 393 | netdev_err(netdev, "tx_timeout recovery unsuccessful\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 394 | break; |
| 395 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 396 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 397 | i40e_service_event_schedule(pf); |
| 398 | pf->tx_timeout_recovery_level++; |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * i40e_release_rx_desc - Store the new tail and head values |
| 403 | * @rx_ring: ring to bump |
| 404 | * @val: new head index |
| 405 | **/ |
| 406 | static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val) |
| 407 | { |
| 408 | rx_ring->next_to_use = val; |
| 409 | |
| 410 | /* Force memory writes to complete before letting h/w |
| 411 | * know there are new descriptors to fetch. (Only |
| 412 | * applicable for weak-ordered memory model archs, |
| 413 | * such as IA-64). |
| 414 | */ |
| 415 | wmb(); |
| 416 | writel(val, rx_ring->tail); |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * i40e_get_vsi_stats_struct - Get System Network Statistics |
| 421 | * @vsi: the VSI we care about |
| 422 | * |
| 423 | * Returns the address of the device statistics structure. |
| 424 | * The statistics are actually updated from the service task. |
| 425 | **/ |
| 426 | struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi) |
| 427 | { |
| 428 | return &vsi->net_stats; |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * i40e_get_netdev_stats_struct - Get statistics for netdev interface |
| 433 | * @netdev: network interface device structure |
| 434 | * |
| 435 | * Returns the address of the device statistics structure. |
| 436 | * The statistics are actually updated from the service task. |
| 437 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 438 | #ifdef I40E_FCOE |
| 439 | struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 440 | struct net_device *netdev, |
| 441 | struct rtnl_link_stats64 *stats) |
| 442 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 443 | static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 444 | struct net_device *netdev, |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 445 | struct rtnl_link_stats64 *stats) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 446 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 447 | { |
| 448 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 449 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 450 | struct i40e_vsi *vsi = np->vsi; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 451 | struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi); |
| 452 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 453 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 454 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 455 | return stats; |
| 456 | |
Jesse Brandeburg | 3c325ce | 2013-12-14 03:26:45 -0800 | [diff] [blame] | 457 | if (!vsi->tx_rings) |
| 458 | return stats; |
| 459 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 460 | rcu_read_lock(); |
| 461 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 462 | u64 bytes, packets; |
| 463 | unsigned int start; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 464 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 465 | tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); |
| 466 | if (!tx_ring) |
| 467 | continue; |
| 468 | |
| 469 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 470 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 471 | packets = tx_ring->stats.packets; |
| 472 | bytes = tx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 473 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 474 | |
| 475 | stats->tx_packets += packets; |
| 476 | stats->tx_bytes += bytes; |
| 477 | rx_ring = &tx_ring[1]; |
| 478 | |
| 479 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 480 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 481 | packets = rx_ring->stats.packets; |
| 482 | bytes = rx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 483 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 484 | |
| 485 | stats->rx_packets += packets; |
| 486 | stats->rx_bytes += bytes; |
| 487 | } |
| 488 | rcu_read_unlock(); |
| 489 | |
Akeem G Abodunrin | a5282f4 | 2014-05-10 04:49:03 +0000 | [diff] [blame] | 490 | /* following stats updated by i40e_watchdog_subtask() */ |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 491 | stats->multicast = vsi_stats->multicast; |
| 492 | stats->tx_errors = vsi_stats->tx_errors; |
| 493 | stats->tx_dropped = vsi_stats->tx_dropped; |
| 494 | stats->rx_errors = vsi_stats->rx_errors; |
Jesse Brandeburg | d8201e2 | 2015-07-23 16:54:35 -0400 | [diff] [blame] | 495 | stats->rx_dropped = vsi_stats->rx_dropped; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 496 | stats->rx_crc_errors = vsi_stats->rx_crc_errors; |
| 497 | stats->rx_length_errors = vsi_stats->rx_length_errors; |
| 498 | |
| 499 | return stats; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | /** |
| 503 | * i40e_vsi_reset_stats - Resets all stats of the given vsi |
| 504 | * @vsi: the VSI to have its stats reset |
| 505 | **/ |
| 506 | void i40e_vsi_reset_stats(struct i40e_vsi *vsi) |
| 507 | { |
| 508 | struct rtnl_link_stats64 *ns; |
| 509 | int i; |
| 510 | |
| 511 | if (!vsi) |
| 512 | return; |
| 513 | |
| 514 | ns = i40e_get_vsi_stats_struct(vsi); |
| 515 | memset(ns, 0, sizeof(*ns)); |
| 516 | memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets)); |
| 517 | memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats)); |
| 518 | memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets)); |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 519 | if (vsi->rx_rings && vsi->rx_rings[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 520 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 521 | memset(&vsi->rx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 522 | sizeof(vsi->rx_rings[i]->stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 523 | memset(&vsi->rx_rings[i]->rx_stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 524 | sizeof(vsi->rx_rings[i]->rx_stats)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 525 | memset(&vsi->tx_rings[i]->stats, 0, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 526 | sizeof(vsi->tx_rings[i]->stats)); |
| 527 | memset(&vsi->tx_rings[i]->tx_stats, 0, |
| 528 | sizeof(vsi->tx_rings[i]->tx_stats)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 529 | } |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 530 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 531 | vsi->stat_offsets_loaded = false; |
| 532 | } |
| 533 | |
| 534 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 535 | * 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] | 536 | * @pf: the PF to be reset |
| 537 | **/ |
| 538 | void i40e_pf_reset_stats(struct i40e_pf *pf) |
| 539 | { |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 540 | int i; |
| 541 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 542 | memset(&pf->stats, 0, sizeof(pf->stats)); |
| 543 | memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); |
| 544 | pf->stat_offsets_loaded = false; |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 545 | |
| 546 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 547 | if (pf->veb[i]) { |
| 548 | memset(&pf->veb[i]->stats, 0, |
| 549 | sizeof(pf->veb[i]->stats)); |
| 550 | memset(&pf->veb[i]->stats_offsets, 0, |
| 551 | sizeof(pf->veb[i]->stats_offsets)); |
| 552 | pf->veb[i]->stat_offsets_loaded = false; |
| 553 | } |
| 554 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | /** |
| 558 | * i40e_stat_update48 - read and update a 48 bit stat from the chip |
| 559 | * @hw: ptr to the hardware info |
| 560 | * @hireg: the high 32 bit reg to read |
| 561 | * @loreg: the low 32 bit reg to read |
| 562 | * @offset_loaded: has the initial offset been loaded yet |
| 563 | * @offset: ptr to current offset value |
| 564 | * @stat: ptr to the stat |
| 565 | * |
| 566 | * Since the device stats are not reset at PFReset, they likely will not |
| 567 | * be zeroed when the driver starts. We'll save the first values read |
| 568 | * and use them as offsets to be subtracted from the raw values in order |
| 569 | * to report stats that count from zero. In the process, we also manage |
| 570 | * the potential roll-over. |
| 571 | **/ |
| 572 | static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, |
| 573 | bool offset_loaded, u64 *offset, u64 *stat) |
| 574 | { |
| 575 | u64 new_data; |
| 576 | |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 577 | if (hw->device_id == I40E_DEV_ID_QEMU) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 578 | new_data = rd32(hw, loreg); |
| 579 | new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; |
| 580 | } else { |
| 581 | new_data = rd64(hw, loreg); |
| 582 | } |
| 583 | if (!offset_loaded) |
| 584 | *offset = new_data; |
| 585 | if (likely(new_data >= *offset)) |
| 586 | *stat = new_data - *offset; |
| 587 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 588 | *stat = (new_data + BIT_ULL(48)) - *offset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 589 | *stat &= 0xFFFFFFFFFFFFULL; |
| 590 | } |
| 591 | |
| 592 | /** |
| 593 | * i40e_stat_update32 - read and update a 32 bit stat from the chip |
| 594 | * @hw: ptr to the hardware info |
| 595 | * @reg: the hw reg to read |
| 596 | * @offset_loaded: has the initial offset been loaded yet |
| 597 | * @offset: ptr to current offset value |
| 598 | * @stat: ptr to the stat |
| 599 | **/ |
| 600 | static void i40e_stat_update32(struct i40e_hw *hw, u32 reg, |
| 601 | bool offset_loaded, u64 *offset, u64 *stat) |
| 602 | { |
| 603 | u32 new_data; |
| 604 | |
| 605 | new_data = rd32(hw, reg); |
| 606 | if (!offset_loaded) |
| 607 | *offset = new_data; |
| 608 | if (likely(new_data >= *offset)) |
| 609 | *stat = (u32)(new_data - *offset); |
| 610 | else |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 611 | *stat = (u32)((new_data + BIT_ULL(32)) - *offset); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | /** |
| 615 | * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. |
| 616 | * @vsi: the VSI to be updated |
| 617 | **/ |
| 618 | void i40e_update_eth_stats(struct i40e_vsi *vsi) |
| 619 | { |
| 620 | int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); |
| 621 | struct i40e_pf *pf = vsi->back; |
| 622 | struct i40e_hw *hw = &pf->hw; |
| 623 | struct i40e_eth_stats *oes; |
| 624 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 625 | |
| 626 | es = &vsi->eth_stats; |
| 627 | oes = &vsi->eth_stats_offsets; |
| 628 | |
| 629 | /* Gather up the stats that the hw collects */ |
| 630 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 631 | vsi->stat_offsets_loaded, |
| 632 | &oes->tx_errors, &es->tx_errors); |
| 633 | i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), |
| 634 | vsi->stat_offsets_loaded, |
| 635 | &oes->rx_discards, &es->rx_discards); |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 636 | i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx), |
| 637 | vsi->stat_offsets_loaded, |
| 638 | &oes->rx_unknown_protocol, &es->rx_unknown_protocol); |
| 639 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 640 | vsi->stat_offsets_loaded, |
| 641 | &oes->tx_errors, &es->tx_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 642 | |
| 643 | i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), |
| 644 | I40E_GLV_GORCL(stat_idx), |
| 645 | vsi->stat_offsets_loaded, |
| 646 | &oes->rx_bytes, &es->rx_bytes); |
| 647 | i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), |
| 648 | I40E_GLV_UPRCL(stat_idx), |
| 649 | vsi->stat_offsets_loaded, |
| 650 | &oes->rx_unicast, &es->rx_unicast); |
| 651 | i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), |
| 652 | I40E_GLV_MPRCL(stat_idx), |
| 653 | vsi->stat_offsets_loaded, |
| 654 | &oes->rx_multicast, &es->rx_multicast); |
| 655 | i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), |
| 656 | I40E_GLV_BPRCL(stat_idx), |
| 657 | vsi->stat_offsets_loaded, |
| 658 | &oes->rx_broadcast, &es->rx_broadcast); |
| 659 | |
| 660 | i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), |
| 661 | I40E_GLV_GOTCL(stat_idx), |
| 662 | vsi->stat_offsets_loaded, |
| 663 | &oes->tx_bytes, &es->tx_bytes); |
| 664 | i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), |
| 665 | I40E_GLV_UPTCL(stat_idx), |
| 666 | vsi->stat_offsets_loaded, |
| 667 | &oes->tx_unicast, &es->tx_unicast); |
| 668 | i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), |
| 669 | I40E_GLV_MPTCL(stat_idx), |
| 670 | vsi->stat_offsets_loaded, |
| 671 | &oes->tx_multicast, &es->tx_multicast); |
| 672 | i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), |
| 673 | I40E_GLV_BPTCL(stat_idx), |
| 674 | vsi->stat_offsets_loaded, |
| 675 | &oes->tx_broadcast, &es->tx_broadcast); |
| 676 | vsi->stat_offsets_loaded = true; |
| 677 | } |
| 678 | |
| 679 | /** |
| 680 | * i40e_update_veb_stats - Update Switch component statistics |
| 681 | * @veb: the VEB being updated |
| 682 | **/ |
| 683 | static void i40e_update_veb_stats(struct i40e_veb *veb) |
| 684 | { |
| 685 | struct i40e_pf *pf = veb->pf; |
| 686 | struct i40e_hw *hw = &pf->hw; |
| 687 | struct i40e_eth_stats *oes; |
| 688 | struct i40e_eth_stats *es; /* device's eth stats */ |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 689 | struct i40e_veb_tc_stats *veb_oes; |
| 690 | struct i40e_veb_tc_stats *veb_es; |
| 691 | int i, idx = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 692 | |
| 693 | idx = veb->stats_idx; |
| 694 | es = &veb->stats; |
| 695 | oes = &veb->stats_offsets; |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 696 | veb_es = &veb->tc_stats; |
| 697 | veb_oes = &veb->tc_stats_offsets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 698 | |
| 699 | /* Gather up the stats that the hw collects */ |
| 700 | i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), |
| 701 | veb->stat_offsets_loaded, |
| 702 | &oes->tx_discards, &es->tx_discards); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 703 | if (hw->revision_id > 0) |
| 704 | i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), |
| 705 | veb->stat_offsets_loaded, |
| 706 | &oes->rx_unknown_protocol, |
| 707 | &es->rx_unknown_protocol); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 708 | i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), |
| 709 | veb->stat_offsets_loaded, |
| 710 | &oes->rx_bytes, &es->rx_bytes); |
| 711 | i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), |
| 712 | veb->stat_offsets_loaded, |
| 713 | &oes->rx_unicast, &es->rx_unicast); |
| 714 | i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), |
| 715 | veb->stat_offsets_loaded, |
| 716 | &oes->rx_multicast, &es->rx_multicast); |
| 717 | i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), |
| 718 | veb->stat_offsets_loaded, |
| 719 | &oes->rx_broadcast, &es->rx_broadcast); |
| 720 | |
| 721 | i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), |
| 722 | veb->stat_offsets_loaded, |
| 723 | &oes->tx_bytes, &es->tx_bytes); |
| 724 | i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), |
| 725 | veb->stat_offsets_loaded, |
| 726 | &oes->tx_unicast, &es->tx_unicast); |
| 727 | i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), |
| 728 | veb->stat_offsets_loaded, |
| 729 | &oes->tx_multicast, &es->tx_multicast); |
| 730 | i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), |
| 731 | veb->stat_offsets_loaded, |
| 732 | &oes->tx_broadcast, &es->tx_broadcast); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 733 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 734 | i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx), |
| 735 | I40E_GLVEBTC_RPCL(i, idx), |
| 736 | veb->stat_offsets_loaded, |
| 737 | &veb_oes->tc_rx_packets[i], |
| 738 | &veb_es->tc_rx_packets[i]); |
| 739 | i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx), |
| 740 | I40E_GLVEBTC_RBCL(i, idx), |
| 741 | veb->stat_offsets_loaded, |
| 742 | &veb_oes->tc_rx_bytes[i], |
| 743 | &veb_es->tc_rx_bytes[i]); |
| 744 | i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx), |
| 745 | I40E_GLVEBTC_TPCL(i, idx), |
| 746 | veb->stat_offsets_loaded, |
| 747 | &veb_oes->tc_tx_packets[i], |
| 748 | &veb_es->tc_tx_packets[i]); |
| 749 | i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx), |
| 750 | I40E_GLVEBTC_TBCL(i, idx), |
| 751 | veb->stat_offsets_loaded, |
| 752 | &veb_oes->tc_tx_bytes[i], |
| 753 | &veb_es->tc_tx_bytes[i]); |
| 754 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 755 | veb->stat_offsets_loaded = true; |
| 756 | } |
| 757 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 758 | #ifdef I40E_FCOE |
| 759 | /** |
| 760 | * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters. |
| 761 | * @vsi: the VSI that is capable of doing FCoE |
| 762 | **/ |
| 763 | static void i40e_update_fcoe_stats(struct i40e_vsi *vsi) |
| 764 | { |
| 765 | struct i40e_pf *pf = vsi->back; |
| 766 | struct i40e_hw *hw = &pf->hw; |
| 767 | struct i40e_fcoe_stats *ofs; |
| 768 | struct i40e_fcoe_stats *fs; /* device's eth stats */ |
| 769 | int idx; |
| 770 | |
| 771 | if (vsi->type != I40E_VSI_FCOE) |
| 772 | return; |
| 773 | |
| 774 | idx = (pf->pf_seid - I40E_BASE_PF_SEID) + I40E_FCOE_PF_STAT_OFFSET; |
| 775 | fs = &vsi->fcoe_stats; |
| 776 | ofs = &vsi->fcoe_stats_offsets; |
| 777 | |
| 778 | i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx), |
| 779 | vsi->fcoe_stat_offsets_loaded, |
| 780 | &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets); |
| 781 | i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx), |
| 782 | vsi->fcoe_stat_offsets_loaded, |
| 783 | &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords); |
| 784 | i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx), |
| 785 | vsi->fcoe_stat_offsets_loaded, |
| 786 | &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped); |
| 787 | i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx), |
| 788 | vsi->fcoe_stat_offsets_loaded, |
| 789 | &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets); |
| 790 | i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx), |
| 791 | vsi->fcoe_stat_offsets_loaded, |
| 792 | &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords); |
| 793 | i40e_stat_update32(hw, I40E_GL_FCOECRC(idx), |
| 794 | vsi->fcoe_stat_offsets_loaded, |
| 795 | &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc); |
| 796 | i40e_stat_update32(hw, I40E_GL_FCOELAST(idx), |
| 797 | vsi->fcoe_stat_offsets_loaded, |
| 798 | &ofs->fcoe_last_error, &fs->fcoe_last_error); |
| 799 | i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx), |
| 800 | vsi->fcoe_stat_offsets_loaded, |
| 801 | &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count); |
| 802 | |
| 803 | vsi->fcoe_stat_offsets_loaded = true; |
| 804 | } |
| 805 | |
| 806 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 807 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 808 | * i40e_update_vsi_stats - Update the vsi statistics counters. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 809 | * @vsi: the VSI to be updated |
| 810 | * |
| 811 | * There are a few instances where we store the same stat in a |
| 812 | * couple of different structs. This is partly because we have |
| 813 | * the netdev stats that need to be filled out, which is slightly |
| 814 | * different from the "eth_stats" defined by the chip and used in |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 815 | * VF communications. We sort it out here. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 816 | **/ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 817 | static void i40e_update_vsi_stats(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 818 | { |
| 819 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 820 | struct rtnl_link_stats64 *ons; |
| 821 | struct rtnl_link_stats64 *ns; /* netdev stats */ |
| 822 | struct i40e_eth_stats *oes; |
| 823 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 824 | u32 tx_restart, tx_busy; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 825 | struct i40e_ring *p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 826 | u32 rx_page, rx_buf; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 827 | u64 bytes, packets; |
| 828 | unsigned int start; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 829 | u64 tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 830 | u64 tx_force_wb; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 831 | u64 rx_p, rx_b; |
| 832 | u64 tx_p, tx_b; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 833 | u16 q; |
| 834 | |
| 835 | if (test_bit(__I40E_DOWN, &vsi->state) || |
| 836 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 837 | return; |
| 838 | |
| 839 | ns = i40e_get_vsi_stats_struct(vsi); |
| 840 | ons = &vsi->net_stats_offsets; |
| 841 | es = &vsi->eth_stats; |
| 842 | oes = &vsi->eth_stats_offsets; |
| 843 | |
| 844 | /* Gather up the netdev and vsi stats that the driver collects |
| 845 | * on the fly during packet processing |
| 846 | */ |
| 847 | rx_b = rx_p = 0; |
| 848 | tx_b = tx_p = 0; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 849 | tx_restart = tx_busy = tx_linearize = tx_force_wb = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 850 | rx_page = 0; |
| 851 | rx_buf = 0; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 852 | rcu_read_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 853 | for (q = 0; q < vsi->num_queue_pairs; q++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 854 | /* locate Tx ring */ |
| 855 | p = ACCESS_ONCE(vsi->tx_rings[q]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 856 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 857 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 858 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 859 | packets = p->stats.packets; |
| 860 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 861 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 862 | tx_b += bytes; |
| 863 | tx_p += packets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 864 | tx_restart += p->tx_stats.restart_queue; |
| 865 | tx_busy += p->tx_stats.tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 866 | tx_linearize += p->tx_stats.tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 867 | tx_force_wb += p->tx_stats.tx_force_wb; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 868 | |
| 869 | /* Rx queue is part of the same block as Tx queue */ |
| 870 | p = &p[1]; |
| 871 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 872 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 873 | packets = p->stats.packets; |
| 874 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 875 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 876 | rx_b += bytes; |
| 877 | rx_p += packets; |
Mitch Williams | 420136c | 2013-12-18 13:45:59 +0000 | [diff] [blame] | 878 | rx_buf += p->rx_stats.alloc_buff_failed; |
| 879 | rx_page += p->rx_stats.alloc_page_failed; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 880 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 881 | rcu_read_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 882 | vsi->tx_restart = tx_restart; |
| 883 | vsi->tx_busy = tx_busy; |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 884 | vsi->tx_linearize = tx_linearize; |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 885 | vsi->tx_force_wb = tx_force_wb; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 886 | vsi->rx_page_failed = rx_page; |
| 887 | vsi->rx_buf_failed = rx_buf; |
| 888 | |
| 889 | ns->rx_packets = rx_p; |
| 890 | ns->rx_bytes = rx_b; |
| 891 | ns->tx_packets = tx_p; |
| 892 | ns->tx_bytes = tx_b; |
| 893 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 894 | /* update netdev stats from eth stats */ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 895 | i40e_update_eth_stats(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 896 | ons->tx_errors = oes->tx_errors; |
| 897 | ns->tx_errors = es->tx_errors; |
| 898 | ons->multicast = oes->rx_multicast; |
| 899 | ns->multicast = es->rx_multicast; |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 900 | ons->rx_dropped = oes->rx_discards; |
| 901 | ns->rx_dropped = es->rx_discards; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 902 | ons->tx_dropped = oes->tx_discards; |
| 903 | ns->tx_dropped = es->tx_discards; |
| 904 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 905 | /* pull in a couple PF stats if this is the main vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 906 | if (vsi == pf->vsi[pf->lan_vsi]) { |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 907 | ns->rx_crc_errors = pf->stats.crc_errors; |
| 908 | ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes; |
| 909 | ns->rx_length_errors = pf->stats.rx_length_errors; |
| 910 | } |
| 911 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 912 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 913 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 914 | * i40e_update_pf_stats - Update the PF statistics counters. |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 915 | * @pf: the PF to be updated |
| 916 | **/ |
| 917 | static void i40e_update_pf_stats(struct i40e_pf *pf) |
| 918 | { |
| 919 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 920 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 921 | struct i40e_hw *hw = &pf->hw; |
| 922 | u32 val; |
| 923 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 924 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 925 | i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), |
| 926 | I40E_GLPRT_GORCL(hw->port), |
| 927 | pf->stat_offsets_loaded, |
| 928 | &osd->eth.rx_bytes, &nsd->eth.rx_bytes); |
| 929 | i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), |
| 930 | I40E_GLPRT_GOTCL(hw->port), |
| 931 | pf->stat_offsets_loaded, |
| 932 | &osd->eth.tx_bytes, &nsd->eth.tx_bytes); |
| 933 | i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), |
| 934 | pf->stat_offsets_loaded, |
| 935 | &osd->eth.rx_discards, |
| 936 | &nsd->eth.rx_discards); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 937 | i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port), |
| 938 | I40E_GLPRT_UPRCL(hw->port), |
| 939 | pf->stat_offsets_loaded, |
| 940 | &osd->eth.rx_unicast, |
| 941 | &nsd->eth.rx_unicast); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 942 | i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), |
| 943 | I40E_GLPRT_MPRCL(hw->port), |
| 944 | pf->stat_offsets_loaded, |
| 945 | &osd->eth.rx_multicast, |
| 946 | &nsd->eth.rx_multicast); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 947 | i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port), |
| 948 | I40E_GLPRT_BPRCL(hw->port), |
| 949 | pf->stat_offsets_loaded, |
| 950 | &osd->eth.rx_broadcast, |
| 951 | &nsd->eth.rx_broadcast); |
| 952 | i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port), |
| 953 | I40E_GLPRT_UPTCL(hw->port), |
| 954 | pf->stat_offsets_loaded, |
| 955 | &osd->eth.tx_unicast, |
| 956 | &nsd->eth.tx_unicast); |
| 957 | i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port), |
| 958 | I40E_GLPRT_MPTCL(hw->port), |
| 959 | pf->stat_offsets_loaded, |
| 960 | &osd->eth.tx_multicast, |
| 961 | &nsd->eth.tx_multicast); |
| 962 | i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port), |
| 963 | I40E_GLPRT_BPTCL(hw->port), |
| 964 | pf->stat_offsets_loaded, |
| 965 | &osd->eth.tx_broadcast, |
| 966 | &nsd->eth.tx_broadcast); |
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_TDOLD(hw->port), |
| 969 | pf->stat_offsets_loaded, |
| 970 | &osd->tx_dropped_link_down, |
| 971 | &nsd->tx_dropped_link_down); |
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_CRCERRS(hw->port), |
| 974 | pf->stat_offsets_loaded, |
| 975 | &osd->crc_errors, &nsd->crc_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 976 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 977 | i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), |
| 978 | pf->stat_offsets_loaded, |
| 979 | &osd->illegal_bytes, &nsd->illegal_bytes); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 980 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 981 | i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), |
| 982 | pf->stat_offsets_loaded, |
| 983 | &osd->mac_local_faults, |
| 984 | &nsd->mac_local_faults); |
| 985 | i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), |
| 986 | pf->stat_offsets_loaded, |
| 987 | &osd->mac_remote_faults, |
| 988 | &nsd->mac_remote_faults); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 989 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 990 | i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), |
| 991 | pf->stat_offsets_loaded, |
| 992 | &osd->rx_length_errors, |
| 993 | &nsd->rx_length_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 994 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 995 | i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), |
| 996 | pf->stat_offsets_loaded, |
| 997 | &osd->link_xon_rx, &nsd->link_xon_rx); |
| 998 | i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), |
| 999 | pf->stat_offsets_loaded, |
| 1000 | &osd->link_xon_tx, &nsd->link_xon_tx); |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 1001 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), |
| 1002 | pf->stat_offsets_loaded, |
| 1003 | &osd->link_xoff_rx, &nsd->link_xoff_rx); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1004 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), |
| 1005 | pf->stat_offsets_loaded, |
| 1006 | &osd->link_xoff_tx, &nsd->link_xoff_tx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1007 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1008 | for (i = 0; i < 8; i++) { |
Neerav Parikh | 95db239 | 2015-11-06 15:26:09 -0800 | [diff] [blame] | 1009 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), |
| 1010 | pf->stat_offsets_loaded, |
| 1011 | &osd->priority_xoff_rx[i], |
| 1012 | &nsd->priority_xoff_rx[i]); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1013 | i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1014 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1015 | &osd->priority_xon_rx[i], |
| 1016 | &nsd->priority_xon_rx[i]); |
| 1017 | i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1018 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1019 | &osd->priority_xon_tx[i], |
| 1020 | &nsd->priority_xon_tx[i]); |
| 1021 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1022 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1023 | &osd->priority_xoff_tx[i], |
| 1024 | &nsd->priority_xoff_tx[i]); |
| 1025 | i40e_stat_update32(hw, |
| 1026 | I40E_GLPRT_RXON2OFFCNT(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1027 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1028 | &osd->priority_xon_2_xoff[i], |
| 1029 | &nsd->priority_xon_2_xoff[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1032 | i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), |
| 1033 | I40E_GLPRT_PRC64L(hw->port), |
| 1034 | pf->stat_offsets_loaded, |
| 1035 | &osd->rx_size_64, &nsd->rx_size_64); |
| 1036 | i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), |
| 1037 | I40E_GLPRT_PRC127L(hw->port), |
| 1038 | pf->stat_offsets_loaded, |
| 1039 | &osd->rx_size_127, &nsd->rx_size_127); |
| 1040 | i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), |
| 1041 | I40E_GLPRT_PRC255L(hw->port), |
| 1042 | pf->stat_offsets_loaded, |
| 1043 | &osd->rx_size_255, &nsd->rx_size_255); |
| 1044 | i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), |
| 1045 | I40E_GLPRT_PRC511L(hw->port), |
| 1046 | pf->stat_offsets_loaded, |
| 1047 | &osd->rx_size_511, &nsd->rx_size_511); |
| 1048 | i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), |
| 1049 | I40E_GLPRT_PRC1023L(hw->port), |
| 1050 | pf->stat_offsets_loaded, |
| 1051 | &osd->rx_size_1023, &nsd->rx_size_1023); |
| 1052 | i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), |
| 1053 | I40E_GLPRT_PRC1522L(hw->port), |
| 1054 | pf->stat_offsets_loaded, |
| 1055 | &osd->rx_size_1522, &nsd->rx_size_1522); |
| 1056 | i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), |
| 1057 | I40E_GLPRT_PRC9522L(hw->port), |
| 1058 | pf->stat_offsets_loaded, |
| 1059 | &osd->rx_size_big, &nsd->rx_size_big); |
| 1060 | |
| 1061 | i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), |
| 1062 | I40E_GLPRT_PTC64L(hw->port), |
| 1063 | pf->stat_offsets_loaded, |
| 1064 | &osd->tx_size_64, &nsd->tx_size_64); |
| 1065 | i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), |
| 1066 | I40E_GLPRT_PTC127L(hw->port), |
| 1067 | pf->stat_offsets_loaded, |
| 1068 | &osd->tx_size_127, &nsd->tx_size_127); |
| 1069 | i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), |
| 1070 | I40E_GLPRT_PTC255L(hw->port), |
| 1071 | pf->stat_offsets_loaded, |
| 1072 | &osd->tx_size_255, &nsd->tx_size_255); |
| 1073 | i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), |
| 1074 | I40E_GLPRT_PTC511L(hw->port), |
| 1075 | pf->stat_offsets_loaded, |
| 1076 | &osd->tx_size_511, &nsd->tx_size_511); |
| 1077 | i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), |
| 1078 | I40E_GLPRT_PTC1023L(hw->port), |
| 1079 | pf->stat_offsets_loaded, |
| 1080 | &osd->tx_size_1023, &nsd->tx_size_1023); |
| 1081 | i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), |
| 1082 | I40E_GLPRT_PTC1522L(hw->port), |
| 1083 | pf->stat_offsets_loaded, |
| 1084 | &osd->tx_size_1522, &nsd->tx_size_1522); |
| 1085 | i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), |
| 1086 | I40E_GLPRT_PTC9522L(hw->port), |
| 1087 | pf->stat_offsets_loaded, |
| 1088 | &osd->tx_size_big, &nsd->tx_size_big); |
| 1089 | |
| 1090 | i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), |
| 1091 | pf->stat_offsets_loaded, |
| 1092 | &osd->rx_undersize, &nsd->rx_undersize); |
| 1093 | i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), |
| 1094 | pf->stat_offsets_loaded, |
| 1095 | &osd->rx_fragments, &nsd->rx_fragments); |
| 1096 | i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), |
| 1097 | pf->stat_offsets_loaded, |
| 1098 | &osd->rx_oversize, &nsd->rx_oversize); |
| 1099 | i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), |
| 1100 | pf->stat_offsets_loaded, |
| 1101 | &osd->rx_jabber, &nsd->rx_jabber); |
| 1102 | |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1103 | /* FDIR stats */ |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1104 | i40e_stat_update32(hw, |
| 1105 | 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] | 1106 | pf->stat_offsets_loaded, |
| 1107 | &osd->fd_atr_match, &nsd->fd_atr_match); |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1108 | i40e_stat_update32(hw, |
| 1109 | 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] | 1110 | pf->stat_offsets_loaded, |
| 1111 | &osd->fd_sb_match, &nsd->fd_sb_match); |
Anjali Singhai Jain | 60ccd45 | 2015-04-16 20:06:01 -0400 | [diff] [blame] | 1112 | i40e_stat_update32(hw, |
| 1113 | I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)), |
| 1114 | pf->stat_offsets_loaded, |
| 1115 | &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match); |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1116 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1117 | val = rd32(hw, I40E_PRTPM_EEE_STAT); |
| 1118 | nsd->tx_lpi_status = |
| 1119 | (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >> |
| 1120 | I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT; |
| 1121 | nsd->rx_lpi_status = |
| 1122 | (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >> |
| 1123 | I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT; |
| 1124 | i40e_stat_update32(hw, I40E_PRTPM_TLPIC, |
| 1125 | pf->stat_offsets_loaded, |
| 1126 | &osd->tx_lpi_count, &nsd->tx_lpi_count); |
| 1127 | i40e_stat_update32(hw, I40E_PRTPM_RLPIC, |
| 1128 | pf->stat_offsets_loaded, |
| 1129 | &osd->rx_lpi_count, &nsd->rx_lpi_count); |
| 1130 | |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 1131 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED && |
| 1132 | !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) |
| 1133 | nsd->fd_sb_status = true; |
| 1134 | else |
| 1135 | nsd->fd_sb_status = false; |
| 1136 | |
| 1137 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED && |
| 1138 | !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 1139 | nsd->fd_atr_status = true; |
| 1140 | else |
| 1141 | nsd->fd_atr_status = false; |
| 1142 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1143 | pf->stat_offsets_loaded = true; |
| 1144 | } |
| 1145 | |
| 1146 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1147 | * i40e_update_stats - Update the various statistics counters. |
| 1148 | * @vsi: the VSI to be updated |
| 1149 | * |
| 1150 | * Update the various stats for this VSI and its related entities. |
| 1151 | **/ |
| 1152 | void i40e_update_stats(struct i40e_vsi *vsi) |
| 1153 | { |
| 1154 | struct i40e_pf *pf = vsi->back; |
| 1155 | |
| 1156 | if (vsi == pf->vsi[pf->lan_vsi]) |
| 1157 | i40e_update_pf_stats(pf); |
| 1158 | |
| 1159 | i40e_update_vsi_stats(vsi); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1160 | #ifdef I40E_FCOE |
| 1161 | i40e_update_fcoe_stats(vsi); |
| 1162 | #endif |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1166 | * i40e_find_filter - Search VSI filter list for specific mac/vlan filter |
| 1167 | * @vsi: the VSI to be searched |
| 1168 | * @macaddr: the MAC address |
| 1169 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1170 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1171 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1172 | * |
| 1173 | * Returns ptr to the filter object or NULL |
| 1174 | **/ |
| 1175 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, |
| 1176 | u8 *macaddr, s16 vlan, |
| 1177 | bool is_vf, bool is_netdev) |
| 1178 | { |
| 1179 | struct i40e_mac_filter *f; |
| 1180 | |
| 1181 | if (!vsi || !macaddr) |
| 1182 | return NULL; |
| 1183 | |
| 1184 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1185 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1186 | (vlan == f->vlan) && |
| 1187 | (!is_vf || f->is_vf) && |
| 1188 | (!is_netdev || f->is_netdev)) |
| 1189 | return f; |
| 1190 | } |
| 1191 | return NULL; |
| 1192 | } |
| 1193 | |
| 1194 | /** |
| 1195 | * i40e_find_mac - Find a mac addr in the macvlan filters list |
| 1196 | * @vsi: the VSI to be searched |
| 1197 | * @macaddr: the MAC address we are searching for |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1198 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1199 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1200 | * |
| 1201 | * Returns the first filter with the provided MAC address or NULL if |
| 1202 | * MAC address was not found |
| 1203 | **/ |
| 1204 | struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr, |
| 1205 | bool is_vf, bool is_netdev) |
| 1206 | { |
| 1207 | struct i40e_mac_filter *f; |
| 1208 | |
| 1209 | if (!vsi || !macaddr) |
| 1210 | return NULL; |
| 1211 | |
| 1212 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1213 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1214 | (!is_vf || f->is_vf) && |
| 1215 | (!is_netdev || f->is_netdev)) |
| 1216 | return f; |
| 1217 | } |
| 1218 | return NULL; |
| 1219 | } |
| 1220 | |
| 1221 | /** |
| 1222 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode |
| 1223 | * @vsi: the VSI to be searched |
| 1224 | * |
| 1225 | * Returns true if VSI is in vlan mode or false otherwise |
| 1226 | **/ |
| 1227 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) |
| 1228 | { |
| 1229 | struct i40e_mac_filter *f; |
| 1230 | |
| 1231 | /* Only -1 for all the filters denotes not in vlan mode |
| 1232 | * so we have to go through all the list in order to make sure |
| 1233 | */ |
| 1234 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Greg Rose | d9b68f8 | 2015-07-23 16:54:31 -0400 | [diff] [blame] | 1235 | if (f->vlan >= 0 || vsi->info.pvid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1236 | return true; |
| 1237 | } |
| 1238 | |
| 1239 | return false; |
| 1240 | } |
| 1241 | |
| 1242 | /** |
| 1243 | * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans |
| 1244 | * @vsi: the VSI to be searched |
| 1245 | * @macaddr: the mac address to be filtered |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1246 | * @is_vf: true if it is a VF |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1247 | * @is_netdev: true if it is a netdev |
| 1248 | * |
| 1249 | * Goes through all the macvlan filters and adds a |
| 1250 | * macvlan filter for each unique vlan that already exists |
| 1251 | * |
| 1252 | * Returns first filter found on success, else NULL |
| 1253 | **/ |
| 1254 | struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1255 | bool is_vf, bool is_netdev) |
| 1256 | { |
| 1257 | struct i40e_mac_filter *f; |
| 1258 | |
| 1259 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Mitch Williams | ecbb44e | 2015-07-10 19:35:56 -0400 | [diff] [blame] | 1260 | if (vsi->info.pvid) |
| 1261 | f->vlan = le16_to_cpu(vsi->info.pvid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1262 | if (!i40e_find_filter(vsi, macaddr, f->vlan, |
| 1263 | is_vf, is_netdev)) { |
| 1264 | if (!i40e_add_filter(vsi, macaddr, f->vlan, |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 1265 | is_vf, is_netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1266 | return NULL; |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | return list_first_entry_or_null(&vsi->mac_filter_list, |
| 1271 | struct i40e_mac_filter, list); |
| 1272 | } |
| 1273 | |
| 1274 | /** |
Mitch Williams | b36e9ab | 2015-11-19 11:34:16 -0800 | [diff] [blame] | 1275 | * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS |
| 1276 | * @vsi: the VSI to be searched |
| 1277 | * @macaddr: the mac address to be removed |
| 1278 | * @is_vf: true if it is a VF |
| 1279 | * @is_netdev: true if it is a netdev |
| 1280 | * |
| 1281 | * Removes a given MAC address from a VSI, regardless of VLAN |
| 1282 | * |
| 1283 | * Returns 0 for success, or error |
| 1284 | **/ |
| 1285 | int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1286 | bool is_vf, bool is_netdev) |
| 1287 | { |
| 1288 | struct i40e_mac_filter *f = NULL; |
| 1289 | int changed = 0; |
| 1290 | |
| 1291 | WARN(!spin_is_locked(&vsi->mac_filter_list_lock), |
| 1292 | "Missing mac_filter_list_lock\n"); |
| 1293 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1294 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1295 | (is_vf == f->is_vf) && |
| 1296 | (is_netdev == f->is_netdev)) { |
| 1297 | f->counter--; |
| 1298 | f->changed = true; |
| 1299 | changed = 1; |
| 1300 | } |
| 1301 | } |
| 1302 | if (changed) { |
| 1303 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1304 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1305 | return 0; |
| 1306 | } |
| 1307 | return -ENOENT; |
| 1308 | } |
| 1309 | |
| 1310 | /** |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1311 | * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM |
| 1312 | * @vsi: the PF Main VSI - inappropriate for any other VSI |
| 1313 | * @macaddr: the MAC address |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1314 | * |
| 1315 | * Some older firmware configurations set up a default promiscuous VLAN |
| 1316 | * filter that needs to be removed. |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1317 | **/ |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1318 | static int i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr) |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1319 | { |
| 1320 | struct i40e_aqc_remove_macvlan_element_data element; |
| 1321 | struct i40e_pf *pf = vsi->back; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1322 | i40e_status ret; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1323 | |
| 1324 | /* Only appropriate for the PF main VSI */ |
| 1325 | if (vsi->type != I40E_VSI_MAIN) |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1326 | return -EINVAL; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1327 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1328 | memset(&element, 0, sizeof(element)); |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1329 | ether_addr_copy(element.mac_addr, macaddr); |
| 1330 | element.vlan_tag = 0; |
| 1331 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH | |
| 1332 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1333 | ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1334 | if (ret) |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1335 | return -ENOENT; |
| 1336 | |
| 1337 | return 0; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1341 | * i40e_add_filter - Add a mac/vlan filter to the VSI |
| 1342 | * @vsi: the VSI to be searched |
| 1343 | * @macaddr: the MAC address |
| 1344 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1345 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1346 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1347 | * |
| 1348 | * Returns ptr to the filter object or NULL when no memory available. |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1349 | * |
| 1350 | * NOTE: This function is expected to be called with mac_filter_list_lock |
| 1351 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1352 | **/ |
| 1353 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, |
| 1354 | u8 *macaddr, s16 vlan, |
| 1355 | bool is_vf, bool is_netdev) |
| 1356 | { |
| 1357 | struct i40e_mac_filter *f; |
| 1358 | |
| 1359 | if (!vsi || !macaddr) |
| 1360 | return NULL; |
| 1361 | |
| 1362 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1363 | if (!f) { |
| 1364 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1365 | if (!f) |
| 1366 | goto add_filter_out; |
| 1367 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1368 | ether_addr_copy(f->macaddr, macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1369 | f->vlan = vlan; |
| 1370 | f->changed = true; |
| 1371 | |
| 1372 | INIT_LIST_HEAD(&f->list); |
Kiran Patil | 04d5a21 | 2015-12-09 15:50:23 -0800 | [diff] [blame] | 1373 | list_add_tail(&f->list, &vsi->mac_filter_list); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | /* increment counter and add a new flag if needed */ |
| 1377 | if (is_vf) { |
| 1378 | if (!f->is_vf) { |
| 1379 | f->is_vf = true; |
| 1380 | f->counter++; |
| 1381 | } |
| 1382 | } else if (is_netdev) { |
| 1383 | if (!f->is_netdev) { |
| 1384 | f->is_netdev = true; |
| 1385 | f->counter++; |
| 1386 | } |
| 1387 | } else { |
| 1388 | f->counter++; |
| 1389 | } |
| 1390 | |
| 1391 | /* changed tells sync_filters_subtask to |
| 1392 | * push the filter down to the firmware |
| 1393 | */ |
| 1394 | if (f->changed) { |
| 1395 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1396 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1397 | } |
| 1398 | |
| 1399 | add_filter_out: |
| 1400 | return f; |
| 1401 | } |
| 1402 | |
| 1403 | /** |
| 1404 | * i40e_del_filter - Remove a mac/vlan filter from the VSI |
| 1405 | * @vsi: the VSI to be searched |
| 1406 | * @macaddr: the MAC address |
| 1407 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1408 | * @is_vf: make sure it's a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1409 | * @is_netdev: make sure it's a netdev filter, else doesn't matter |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1410 | * |
| 1411 | * NOTE: This function is expected to be called with mac_filter_list_lock |
| 1412 | * being held. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1413 | **/ |
| 1414 | void i40e_del_filter(struct i40e_vsi *vsi, |
| 1415 | u8 *macaddr, s16 vlan, |
| 1416 | bool is_vf, bool is_netdev) |
| 1417 | { |
| 1418 | struct i40e_mac_filter *f; |
| 1419 | |
| 1420 | if (!vsi || !macaddr) |
| 1421 | return; |
| 1422 | |
| 1423 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1424 | if (!f || f->counter == 0) |
| 1425 | return; |
| 1426 | |
| 1427 | if (is_vf) { |
| 1428 | if (f->is_vf) { |
| 1429 | f->is_vf = false; |
| 1430 | f->counter--; |
| 1431 | } |
| 1432 | } else if (is_netdev) { |
| 1433 | if (f->is_netdev) { |
| 1434 | f->is_netdev = false; |
| 1435 | f->counter--; |
| 1436 | } |
| 1437 | } else { |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1438 | /* make sure we don't remove a filter in use by VF or netdev */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1439 | int min_f = 0; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1440 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1441 | min_f += (f->is_vf ? 1 : 0); |
| 1442 | min_f += (f->is_netdev ? 1 : 0); |
| 1443 | |
| 1444 | if (f->counter > min_f) |
| 1445 | f->counter--; |
| 1446 | } |
| 1447 | |
| 1448 | /* counter == 0 tells sync_filters_subtask to |
| 1449 | * remove the filter from the firmware's list |
| 1450 | */ |
| 1451 | if (f->counter == 0) { |
| 1452 | f->changed = true; |
| 1453 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1454 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | /** |
| 1459 | * i40e_set_mac - NDO callback to set mac address |
| 1460 | * @netdev: network interface device structure |
| 1461 | * @p: pointer to an address structure |
| 1462 | * |
| 1463 | * Returns 0 on success, negative on failure |
| 1464 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1465 | #ifdef I40E_FCOE |
| 1466 | int i40e_set_mac(struct net_device *netdev, void *p) |
| 1467 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1468 | static int i40e_set_mac(struct net_device *netdev, void *p) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1469 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1470 | { |
| 1471 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1472 | struct i40e_vsi *vsi = np->vsi; |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1473 | struct i40e_pf *pf = vsi->back; |
| 1474 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1475 | struct sockaddr *addr = p; |
| 1476 | struct i40e_mac_filter *f; |
| 1477 | |
| 1478 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1479 | return -EADDRNOTAVAIL; |
| 1480 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1481 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) { |
| 1482 | netdev_info(netdev, "already using mac address %pM\n", |
| 1483 | addr->sa_data); |
| 1484 | return 0; |
| 1485 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1486 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1487 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 1488 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 1489 | return -EADDRNOTAVAIL; |
| 1490 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1491 | if (ether_addr_equal(hw->mac.addr, addr->sa_data)) |
| 1492 | netdev_info(netdev, "returning to hw mac address %pM\n", |
| 1493 | hw->mac.addr); |
| 1494 | else |
| 1495 | netdev_info(netdev, "set new mac address %pM\n", addr->sa_data); |
| 1496 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1497 | if (vsi->type == I40E_VSI_MAIN) { |
| 1498 | i40e_status ret; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1499 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1500 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
Shannon Nelson | cc41222 | 2014-06-04 01:23:21 +0000 | [diff] [blame] | 1501 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1502 | addr->sa_data, NULL); |
| 1503 | if (ret) { |
| 1504 | netdev_info(netdev, |
| 1505 | "Addr change for Main VSI failed: %d\n", |
| 1506 | ret); |
| 1507 | return -EADDRNOTAVAIL; |
| 1508 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1509 | } |
| 1510 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1511 | if (ether_addr_equal(netdev->dev_addr, hw->mac.addr)) { |
| 1512 | struct i40e_aqc_remove_macvlan_element_data element; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1513 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1514 | memset(&element, 0, sizeof(element)); |
| 1515 | ether_addr_copy(element.mac_addr, netdev->dev_addr); |
| 1516 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1517 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1518 | } else { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1519 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 6c8ad1b | 2014-06-04 01:23:22 +0000 | [diff] [blame] | 1520 | i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, |
| 1521 | false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1522 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 6c8ad1b | 2014-06-04 01:23:22 +0000 | [diff] [blame] | 1523 | } |
| 1524 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1525 | if (ether_addr_equal(addr->sa_data, hw->mac.addr)) { |
| 1526 | struct i40e_aqc_add_macvlan_element_data element; |
| 1527 | |
| 1528 | memset(&element, 0, sizeof(element)); |
| 1529 | ether_addr_copy(element.mac_addr, hw->mac.addr); |
| 1530 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 1531 | i40e_aq_add_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1532 | } else { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1533 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1534 | f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY, |
| 1535 | false, false); |
| 1536 | if (f) |
| 1537 | f->is_laa = true; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1538 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1539 | } |
| 1540 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1541 | ether_addr_copy(netdev->dev_addr, addr->sa_data); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1542 | |
| 1543 | return i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | /** |
| 1547 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1548 | * @vsi: the VSI being setup |
| 1549 | * @ctxt: VSI context structure |
| 1550 | * @enabled_tc: Enabled TCs bitmap |
| 1551 | * @is_add: True if called before Add VSI |
| 1552 | * |
| 1553 | * Setup VSI queue mapping for enabled traffic classes. |
| 1554 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1555 | #ifdef I40E_FCOE |
| 1556 | void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1557 | struct i40e_vsi_context *ctxt, |
| 1558 | u8 enabled_tc, |
| 1559 | bool is_add) |
| 1560 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1561 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1562 | struct i40e_vsi_context *ctxt, |
| 1563 | u8 enabled_tc, |
| 1564 | bool is_add) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1565 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1566 | { |
| 1567 | struct i40e_pf *pf = vsi->back; |
| 1568 | u16 sections = 0; |
| 1569 | u8 netdev_tc = 0; |
| 1570 | u16 numtc = 0; |
| 1571 | u16 qcount; |
| 1572 | u8 offset; |
| 1573 | u16 qmap; |
| 1574 | int i; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1575 | u16 num_tc_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1576 | |
| 1577 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1578 | offset = 0; |
| 1579 | |
| 1580 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1581 | /* Find numtc from enabled TC bitmap */ |
| 1582 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1583 | if (enabled_tc & BIT(i)) /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1584 | numtc++; |
| 1585 | } |
| 1586 | if (!numtc) { |
| 1587 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1588 | numtc = 1; |
| 1589 | } |
| 1590 | } else { |
| 1591 | /* At least TC0 is enabled in case of non-DCB case */ |
| 1592 | numtc = 1; |
| 1593 | } |
| 1594 | |
| 1595 | vsi->tc_config.numtc = numtc; |
| 1596 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1597 | /* Number of queues per enabled TC */ |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1598 | /* In MFP case we can have a much lower count of MSIx |
| 1599 | * vectors available and so we need to lower the used |
| 1600 | * q count. |
| 1601 | */ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1602 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 1603 | qcount = min_t(int, vsi->alloc_queue_pairs, pf->num_lan_msix); |
| 1604 | else |
| 1605 | qcount = vsi->alloc_queue_pairs; |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1606 | num_tc_qps = qcount / numtc; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 1607 | 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] | 1608 | |
| 1609 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1610 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1611 | /* See if the given TC is enabled for the given VSI */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 1612 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1613 | /* TC is enabled */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1614 | int pow, num_qps; |
| 1615 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1616 | switch (vsi->type) { |
| 1617 | case I40E_VSI_MAIN: |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 1618 | qcount = min_t(int, pf->alloc_rss_size, |
| 1619 | num_tc_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1620 | break; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1621 | #ifdef I40E_FCOE |
| 1622 | case I40E_VSI_FCOE: |
| 1623 | qcount = num_tc_qps; |
| 1624 | break; |
| 1625 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1626 | case I40E_VSI_FDIR: |
| 1627 | case I40E_VSI_SRIOV: |
| 1628 | case I40E_VSI_VMDQ2: |
| 1629 | default: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1630 | qcount = num_tc_qps; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1631 | WARN_ON(i != 0); |
| 1632 | break; |
| 1633 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1634 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1635 | vsi->tc_config.tc_info[i].qcount = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1636 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 1637 | /* find the next higher power-of-2 of num queue pairs */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1638 | num_qps = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1639 | pow = 0; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1640 | while (num_qps && (BIT_ULL(pow) < qcount)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1641 | pow++; |
| 1642 | num_qps >>= 1; |
| 1643 | } |
| 1644 | |
| 1645 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1646 | qmap = |
| 1647 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1648 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1649 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1650 | offset += qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1651 | } else { |
| 1652 | /* TC is not enabled so set the offset to |
| 1653 | * default queue and allocate one queue |
| 1654 | * for the given TC. |
| 1655 | */ |
| 1656 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1657 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1658 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1659 | |
| 1660 | qmap = 0; |
| 1661 | } |
| 1662 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1663 | } |
| 1664 | |
| 1665 | /* Set actual Tx/Rx queue pairs */ |
| 1666 | vsi->num_queue_pairs = offset; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1667 | if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) { |
| 1668 | if (vsi->req_queue_pairs > 0) |
| 1669 | vsi->num_queue_pairs = vsi->req_queue_pairs; |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 1670 | else if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1671 | vsi->num_queue_pairs = pf->num_lan_msix; |
| 1672 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1673 | |
| 1674 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1675 | if (is_add) { |
| 1676 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1677 | |
| 1678 | ctxt->info.up_enable_bits = enabled_tc; |
| 1679 | } |
| 1680 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1681 | ctxt->info.mapping_flags |= |
| 1682 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1683 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1684 | ctxt->info.queue_mapping[i] = |
| 1685 | cpu_to_le16(vsi->base_queue + i); |
| 1686 | } else { |
| 1687 | ctxt->info.mapping_flags |= |
| 1688 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1689 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1690 | } |
| 1691 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1692 | } |
| 1693 | |
| 1694 | /** |
| 1695 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1696 | * @netdev: network interface device structure |
| 1697 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1698 | #ifdef I40E_FCOE |
| 1699 | void i40e_set_rx_mode(struct net_device *netdev) |
| 1700 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1701 | static void i40e_set_rx_mode(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1702 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1703 | { |
| 1704 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1705 | struct i40e_mac_filter *f, *ftmp; |
| 1706 | struct i40e_vsi *vsi = np->vsi; |
| 1707 | struct netdev_hw_addr *uca; |
| 1708 | struct netdev_hw_addr *mca; |
| 1709 | struct netdev_hw_addr *ha; |
| 1710 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1711 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1712 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1713 | /* add addr if not already in the filter list */ |
| 1714 | netdev_for_each_uc_addr(uca, netdev) { |
| 1715 | if (!i40e_find_mac(vsi, uca->addr, false, true)) { |
| 1716 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1717 | i40e_put_mac_in_vlan(vsi, uca->addr, |
| 1718 | false, true); |
| 1719 | else |
| 1720 | i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY, |
| 1721 | false, true); |
| 1722 | } |
| 1723 | } |
| 1724 | |
| 1725 | netdev_for_each_mc_addr(mca, netdev) { |
| 1726 | if (!i40e_find_mac(vsi, mca->addr, false, true)) { |
| 1727 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1728 | i40e_put_mac_in_vlan(vsi, mca->addr, |
| 1729 | false, true); |
| 1730 | else |
| 1731 | i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY, |
| 1732 | false, true); |
| 1733 | } |
| 1734 | } |
| 1735 | |
| 1736 | /* remove filter if not in netdev list */ |
| 1737 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1738 | |
| 1739 | if (!f->is_netdev) |
| 1740 | continue; |
| 1741 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1742 | netdev_for_each_mc_addr(mca, netdev) |
| 1743 | if (ether_addr_equal(mca->addr, f->macaddr)) |
| 1744 | goto bottom_of_search_loop; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1745 | |
Shannon Nelson | 2f41f33 | 2015-08-26 15:14:20 -0400 | [diff] [blame] | 1746 | netdev_for_each_uc_addr(uca, netdev) |
| 1747 | if (ether_addr_equal(uca->addr, f->macaddr)) |
| 1748 | goto bottom_of_search_loop; |
| 1749 | |
| 1750 | for_each_dev_addr(netdev, ha) |
| 1751 | if (ether_addr_equal(ha->addr, f->macaddr)) |
| 1752 | goto bottom_of_search_loop; |
| 1753 | |
| 1754 | /* f->macaddr wasn't found in uc, mc, or ha list so delete it */ |
| 1755 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, false, true); |
| 1756 | |
| 1757 | bottom_of_search_loop: |
| 1758 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1759 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1760 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1761 | |
| 1762 | /* check for other flag changes */ |
| 1763 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1764 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1765 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | /** |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1770 | * i40e_mac_filter_entry_clone - Clones a MAC filter entry |
| 1771 | * @src: source MAC filter entry to be clones |
| 1772 | * |
| 1773 | * Returns the pointer to newly cloned MAC filter entry or NULL |
| 1774 | * in case of error |
| 1775 | **/ |
| 1776 | static struct i40e_mac_filter *i40e_mac_filter_entry_clone( |
| 1777 | struct i40e_mac_filter *src) |
| 1778 | { |
| 1779 | struct i40e_mac_filter *f; |
| 1780 | |
| 1781 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1782 | if (!f) |
| 1783 | return NULL; |
| 1784 | *f = *src; |
| 1785 | |
| 1786 | INIT_LIST_HEAD(&f->list); |
| 1787 | |
| 1788 | return f; |
| 1789 | } |
| 1790 | |
| 1791 | /** |
| 1792 | * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries |
| 1793 | * @vsi: pointer to vsi struct |
| 1794 | * @from: Pointer to list which contains MAC filter entries - changes to |
| 1795 | * those entries needs to be undone. |
| 1796 | * |
| 1797 | * MAC filter entries from list were slated to be removed from device. |
| 1798 | **/ |
| 1799 | static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi, |
| 1800 | struct list_head *from) |
| 1801 | { |
| 1802 | struct i40e_mac_filter *f, *ftmp; |
| 1803 | |
| 1804 | list_for_each_entry_safe(f, ftmp, from, list) { |
| 1805 | f->changed = true; |
| 1806 | /* Move the element back into MAC filter list*/ |
| 1807 | list_move_tail(&f->list, &vsi->mac_filter_list); |
| 1808 | } |
| 1809 | } |
| 1810 | |
| 1811 | /** |
| 1812 | * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries |
| 1813 | * @vsi: pointer to vsi struct |
| 1814 | * |
| 1815 | * MAC filter entries from list were slated to be added from device. |
| 1816 | **/ |
| 1817 | static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi) |
| 1818 | { |
| 1819 | struct i40e_mac_filter *f, *ftmp; |
| 1820 | |
| 1821 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1822 | if (!f->changed && f->counter) |
| 1823 | f->changed = true; |
| 1824 | } |
| 1825 | } |
| 1826 | |
| 1827 | /** |
| 1828 | * i40e_cleanup_add_list - Deletes the element from add list and release |
| 1829 | * memory |
| 1830 | * @add_list: Pointer to list which contains MAC filter entries |
| 1831 | **/ |
| 1832 | static void i40e_cleanup_add_list(struct list_head *add_list) |
| 1833 | { |
| 1834 | struct i40e_mac_filter *f, *ftmp; |
| 1835 | |
| 1836 | list_for_each_entry_safe(f, ftmp, add_list, list) { |
| 1837 | list_del(&f->list); |
| 1838 | kfree(f); |
| 1839 | } |
| 1840 | } |
| 1841 | |
| 1842 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1843 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 1844 | * @vsi: ptr to the VSI |
| 1845 | * |
| 1846 | * Push any outstanding VSI filter changes through the AdminQ. |
| 1847 | * |
| 1848 | * Returns 0 or error value |
| 1849 | **/ |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 1850 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1851 | { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1852 | struct list_head tmp_del_list, tmp_add_list; |
| 1853 | struct i40e_mac_filter *f, *ftmp, *fclone; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1854 | bool promisc_forced_on = false; |
| 1855 | bool add_happened = false; |
| 1856 | int filter_list_len = 0; |
| 1857 | u32 changed_flags = 0; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1858 | i40e_status aq_ret = 0; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1859 | bool err_cond = false; |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1860 | int retval = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1861 | struct i40e_pf *pf; |
| 1862 | int num_add = 0; |
| 1863 | int num_del = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1864 | int aq_err = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1865 | u16 cmd_flags; |
| 1866 | |
| 1867 | /* empty array typed pointers, kcalloc later */ |
| 1868 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 1869 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 1870 | |
| 1871 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 1872 | usleep_range(1000, 2000); |
| 1873 | pf = vsi->back; |
| 1874 | |
| 1875 | if (vsi->netdev) { |
| 1876 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 1877 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 1878 | } |
| 1879 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1880 | INIT_LIST_HEAD(&tmp_del_list); |
| 1881 | INIT_LIST_HEAD(&tmp_add_list); |
| 1882 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1883 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 1884 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 1885 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1886 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1887 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1888 | if (!f->changed) |
| 1889 | continue; |
| 1890 | |
| 1891 | if (f->counter != 0) |
| 1892 | continue; |
| 1893 | f->changed = false; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1894 | |
| 1895 | /* Move the element into temporary del_list */ |
| 1896 | list_move_tail(&f->list, &tmp_del_list); |
| 1897 | } |
| 1898 | |
| 1899 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1900 | if (!f->changed) |
| 1901 | continue; |
| 1902 | |
| 1903 | if (f->counter == 0) |
| 1904 | continue; |
| 1905 | f->changed = false; |
| 1906 | |
| 1907 | /* Clone MAC filter entry and add into temporary list */ |
| 1908 | fclone = i40e_mac_filter_entry_clone(f); |
| 1909 | if (!fclone) { |
| 1910 | err_cond = true; |
| 1911 | break; |
| 1912 | } |
| 1913 | list_add_tail(&fclone->list, &tmp_add_list); |
| 1914 | } |
| 1915 | |
| 1916 | /* if failed to clone MAC filter entry - undo */ |
| 1917 | if (err_cond) { |
| 1918 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
| 1919 | i40e_undo_add_filter_entries(vsi); |
| 1920 | } |
| 1921 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 1922 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1923 | if (err_cond) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1924 | i40e_cleanup_add_list(&tmp_add_list); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1925 | retval = -ENOMEM; |
| 1926 | goto out; |
| 1927 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | /* Now process 'del_list' outside the lock */ |
| 1931 | if (!list_empty(&tmp_del_list)) { |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1932 | int del_list_size; |
| 1933 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1934 | filter_list_len = pf->hw.aq.asq_buf_size / |
| 1935 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1936 | del_list_size = filter_list_len * |
| 1937 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
| 1938 | del_list = kzalloc(del_list_size, GFP_KERNEL); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1939 | if (!del_list) { |
| 1940 | i40e_cleanup_add_list(&tmp_add_list); |
| 1941 | |
| 1942 | /* Undo VSI's MAC filter entry element updates */ |
| 1943 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 1944 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
| 1945 | i40e_undo_add_filter_entries(vsi); |
| 1946 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1947 | retval = -ENOMEM; |
| 1948 | goto out; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | list_for_each_entry_safe(f, ftmp, &tmp_del_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1952 | cmd_flags = 0; |
| 1953 | |
| 1954 | /* add to delete list */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1955 | ether_addr_copy(del_list[num_del].mac_addr, f->macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1956 | del_list[num_del].vlan_tag = |
| 1957 | cpu_to_le16((u16)(f->vlan == |
| 1958 | I40E_VLAN_ANY ? 0 : f->vlan)); |
| 1959 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1960 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1961 | del_list[num_del].flags = cmd_flags; |
| 1962 | num_del++; |
| 1963 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1964 | /* flush a full buffer */ |
| 1965 | if (num_del == filter_list_len) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1966 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, |
| 1967 | vsi->seid, |
| 1968 | del_list, |
| 1969 | num_del, |
| 1970 | NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1971 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1972 | num_del = 0; |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 1973 | memset(del_list, 0, del_list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1974 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1975 | if (aq_ret && aq_err != I40E_AQ_RC_ENOENT) { |
| 1976 | retval = -EIO; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1977 | dev_err(&pf->pdev->dev, |
| 1978 | "ignoring delete macvlan error, err %s, aq_err %s while flushing a full buffer\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1979 | i40e_stat_str(&pf->hw, aq_ret), |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1980 | i40e_aq_str(&pf->hw, aq_err)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1981 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1982 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1983 | /* Release memory for MAC filter entries which were |
| 1984 | * synced up with HW. |
| 1985 | */ |
| 1986 | list_del(&f->list); |
| 1987 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1988 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 1989 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1990 | if (num_del) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1991 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, |
| 1992 | del_list, num_del, |
| 1993 | NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1994 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1995 | num_del = 0; |
| 1996 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 1997 | if (aq_ret && aq_err != I40E_AQ_RC_ENOENT) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1998 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1999 | "ignoring delete macvlan error, err %s aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2000 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2001 | i40e_aq_str(&pf->hw, aq_err)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | kfree(del_list); |
| 2005 | del_list = NULL; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | if (!list_empty(&tmp_add_list)) { |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2009 | int add_list_size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2010 | |
| 2011 | /* do all the adds now */ |
| 2012 | filter_list_len = pf->hw.aq.asq_buf_size / |
| 2013 | sizeof(struct i40e_aqc_add_macvlan_element_data), |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2014 | add_list_size = filter_list_len * |
| 2015 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
| 2016 | add_list = kzalloc(add_list_size, GFP_KERNEL); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2017 | if (!add_list) { |
| 2018 | /* Purge element from temporary lists */ |
| 2019 | i40e_cleanup_add_list(&tmp_add_list); |
| 2020 | |
| 2021 | /* Undo add filter entries from VSI MAC filter list */ |
| 2022 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2023 | i40e_undo_add_filter_entries(vsi); |
| 2024 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2025 | retval = -ENOMEM; |
| 2026 | goto out; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2027 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2028 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2029 | list_for_each_entry_safe(f, ftmp, &tmp_add_list, list) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2030 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2031 | add_happened = true; |
| 2032 | cmd_flags = 0; |
| 2033 | |
| 2034 | /* add to add array */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 2035 | ether_addr_copy(add_list[num_add].mac_addr, f->macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2036 | add_list[num_add].vlan_tag = |
| 2037 | cpu_to_le16( |
| 2038 | (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan)); |
| 2039 | add_list[num_add].queue_number = 0; |
| 2040 | |
| 2041 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2042 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 2043 | num_add++; |
| 2044 | |
| 2045 | /* flush a full buffer */ |
| 2046 | if (num_add == filter_list_len) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2047 | aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, |
| 2048 | add_list, num_add, |
| 2049 | NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2050 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2051 | num_add = 0; |
| 2052 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2053 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2054 | break; |
Shannon Nelson | f119999 | 2015-11-19 11:34:23 -0800 | [diff] [blame] | 2055 | memset(add_list, 0, add_list_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2056 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2057 | /* Entries from tmp_add_list were cloned from MAC |
| 2058 | * filter list, hence clean those cloned entries |
| 2059 | */ |
| 2060 | list_del(&f->list); |
| 2061 | kfree(f); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2062 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2063 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2064 | if (num_add) { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2065 | aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, |
| 2066 | add_list, num_add, NULL); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2067 | aq_err = pf->hw.aq.asq_last_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2068 | num_add = 0; |
| 2069 | } |
| 2070 | kfree(add_list); |
| 2071 | add_list = NULL; |
| 2072 | |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2073 | if (add_happened && aq_ret && aq_err != I40E_AQ_RC_EINVAL) { |
| 2074 | retval = i40e_aq_rc_to_posix(aq_ret, aq_err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2075 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2076 | "add filter failed, err %s aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2077 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2078 | i40e_aq_str(&pf->hw, aq_err)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2079 | if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) && |
| 2080 | !test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2081 | &vsi->state)) { |
| 2082 | promisc_forced_on = true; |
| 2083 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2084 | &vsi->state); |
| 2085 | dev_info(&pf->pdev->dev, "promiscuous mode forced on\n"); |
| 2086 | } |
| 2087 | } |
| 2088 | } |
| 2089 | |
| 2090 | /* check for changes in promiscuous modes */ |
| 2091 | if (changed_flags & IFF_ALLMULTI) { |
| 2092 | bool cur_multipromisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2093 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2094 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2095 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 2096 | vsi->seid, |
| 2097 | cur_multipromisc, |
| 2098 | NULL); |
| 2099 | if (aq_ret) { |
| 2100 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2101 | pf->hw.aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2102 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2103 | "set multi promisc failed, err %s aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2104 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2105 | i40e_aq_str(&pf->hw, |
| 2106 | pf->hw.aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2107 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2108 | } |
| 2109 | if ((changed_flags & IFF_PROMISC) || promisc_forced_on) { |
| 2110 | bool cur_promisc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 2111 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2112 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
| 2113 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 2114 | &vsi->state)); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2115 | if (vsi->type == I40E_VSI_MAIN && pf->lan_veb != I40E_NO_VEB) { |
| 2116 | /* set defport ON for Main VSI instead of true promisc |
| 2117 | * this way we will get all unicast/multicast and VLAN |
| 2118 | * promisc behavior but will not get VF or VMDq traffic |
| 2119 | * replicated on the Main VSI. |
| 2120 | */ |
| 2121 | if (pf->cur_promisc != cur_promisc) { |
| 2122 | pf->cur_promisc = cur_promisc; |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2123 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2124 | } |
| 2125 | } else { |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2126 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous( |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2127 | &vsi->back->hw, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2128 | vsi->seid, |
| 2129 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2130 | if (aq_ret) { |
| 2131 | retval = |
| 2132 | i40e_aq_rc_to_posix(aq_ret, |
| 2133 | pf->hw.aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2134 | dev_info(&pf->pdev->dev, |
| 2135 | "set unicast promisc failed, err %d, aq_err %d\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2136 | aq_ret, pf->hw.aq.asq_last_status); |
| 2137 | } |
| 2138 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous( |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2139 | &vsi->back->hw, |
| 2140 | vsi->seid, |
| 2141 | cur_promisc, NULL); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2142 | if (aq_ret) { |
| 2143 | retval = |
| 2144 | i40e_aq_rc_to_posix(aq_ret, |
| 2145 | pf->hw.aq.asq_last_status); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2146 | dev_info(&pf->pdev->dev, |
| 2147 | "set multicast promisc failed, err %d, aq_err %d\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2148 | aq_ret, pf->hw.aq.asq_last_status); |
| 2149 | } |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 2150 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2151 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
| 2152 | vsi->seid, |
| 2153 | cur_promisc, NULL); |
| 2154 | if (aq_ret) { |
| 2155 | retval = i40e_aq_rc_to_posix(aq_ret, |
| 2156 | pf->hw.aq.asq_last_status); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 2157 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2158 | "set brdcast promisc failed, err %s, aq_err %s\n", |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2159 | i40e_stat_str(&pf->hw, aq_ret), |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2160 | i40e_aq_str(&pf->hw, |
| 2161 | pf->hw.aq.asq_last_status)); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2162 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2163 | } |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2164 | out: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2165 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
Mitch Williams | ea02e90 | 2015-11-09 15:35:50 -0800 | [diff] [blame] | 2166 | return retval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2167 | } |
| 2168 | |
| 2169 | /** |
| 2170 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 2171 | * @pf: board private structure |
| 2172 | **/ |
| 2173 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 2174 | { |
| 2175 | int v; |
| 2176 | |
| 2177 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 2178 | return; |
| 2179 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 2180 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 2181 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2182 | if (pf->vsi[v] && |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 2183 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) { |
| 2184 | int ret = i40e_sync_vsi_filters(pf->vsi[v]); |
| 2185 | |
| 2186 | if (ret) { |
| 2187 | /* come back and try again later */ |
| 2188 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 2189 | break; |
| 2190 | } |
| 2191 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2192 | } |
| 2193 | } |
| 2194 | |
| 2195 | /** |
| 2196 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 2197 | * @netdev: network interface device structure |
| 2198 | * @new_mtu: new value for maximum frame size |
| 2199 | * |
| 2200 | * Returns 0 on success, negative on failure |
| 2201 | **/ |
| 2202 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 2203 | { |
| 2204 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 61a46a4 | 2014-04-23 04:50:05 +0000 | [diff] [blame] | 2205 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2206 | struct i40e_vsi *vsi = np->vsi; |
| 2207 | |
| 2208 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 2209 | if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER)) |
| 2210 | return -EINVAL; |
| 2211 | |
| 2212 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 2213 | netdev->mtu, new_mtu); |
| 2214 | netdev->mtu = new_mtu; |
| 2215 | if (netif_running(netdev)) |
| 2216 | i40e_vsi_reinit_locked(vsi); |
| 2217 | |
| 2218 | return 0; |
| 2219 | } |
| 2220 | |
| 2221 | /** |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2222 | * i40e_ioctl - Access the hwtstamp interface |
| 2223 | * @netdev: network interface device structure |
| 2224 | * @ifr: interface request data |
| 2225 | * @cmd: ioctl command |
| 2226 | **/ |
| 2227 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 2228 | { |
| 2229 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2230 | struct i40e_pf *pf = np->vsi->back; |
| 2231 | |
| 2232 | switch (cmd) { |
| 2233 | case SIOCGHWTSTAMP: |
| 2234 | return i40e_ptp_get_ts_config(pf, ifr); |
| 2235 | case SIOCSHWTSTAMP: |
| 2236 | return i40e_ptp_set_ts_config(pf, ifr); |
| 2237 | default: |
| 2238 | return -EOPNOTSUPP; |
| 2239 | } |
| 2240 | } |
| 2241 | |
| 2242 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2243 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 2244 | * @vsi: the vsi being adjusted |
| 2245 | **/ |
| 2246 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 2247 | { |
| 2248 | struct i40e_vsi_context ctxt; |
| 2249 | i40e_status ret; |
| 2250 | |
| 2251 | if ((vsi->info.valid_sections & |
| 2252 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2253 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 2254 | return; /* already enabled */ |
| 2255 | |
| 2256 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2257 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2258 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 2259 | |
| 2260 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2261 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2262 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2263 | if (ret) { |
| 2264 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2265 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2266 | i40e_stat_str(&vsi->back->hw, ret), |
| 2267 | i40e_aq_str(&vsi->back->hw, |
| 2268 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2269 | } |
| 2270 | } |
| 2271 | |
| 2272 | /** |
| 2273 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 2274 | * @vsi: the vsi being adjusted |
| 2275 | **/ |
| 2276 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 2277 | { |
| 2278 | struct i40e_vsi_context ctxt; |
| 2279 | i40e_status ret; |
| 2280 | |
| 2281 | if ((vsi->info.valid_sections & |
| 2282 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2283 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 2284 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 2285 | return; /* already disabled */ |
| 2286 | |
| 2287 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2288 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2289 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 2290 | |
| 2291 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2292 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2293 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2294 | if (ret) { |
| 2295 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2296 | "update vlan stripping failed, err %s aq_err %s\n", |
| 2297 | i40e_stat_str(&vsi->back->hw, ret), |
| 2298 | i40e_aq_str(&vsi->back->hw, |
| 2299 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2300 | } |
| 2301 | } |
| 2302 | |
| 2303 | /** |
| 2304 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 2305 | * @netdev: network interface to be adjusted |
| 2306 | * @features: netdev features to test if VLAN offload is enabled or not |
| 2307 | **/ |
| 2308 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 2309 | { |
| 2310 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2311 | struct i40e_vsi *vsi = np->vsi; |
| 2312 | |
| 2313 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2314 | i40e_vlan_stripping_enable(vsi); |
| 2315 | else |
| 2316 | i40e_vlan_stripping_disable(vsi); |
| 2317 | } |
| 2318 | |
| 2319 | /** |
| 2320 | * i40e_vsi_add_vlan - Add vsi membership for given vlan |
| 2321 | * @vsi: the vsi being configured |
| 2322 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
| 2323 | **/ |
| 2324 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2325 | { |
| 2326 | struct i40e_mac_filter *f, *add_f; |
| 2327 | bool is_netdev, is_vf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2328 | |
| 2329 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 2330 | is_netdev = !!(vsi->netdev); |
| 2331 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2332 | /* Locked once because all functions invoked below iterates list*/ |
| 2333 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2334 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2335 | if (is_netdev) { |
| 2336 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid, |
| 2337 | is_vf, is_netdev); |
| 2338 | if (!add_f) { |
| 2339 | dev_info(&vsi->back->pdev->dev, |
| 2340 | "Could not add vlan filter %d for %pM\n", |
| 2341 | vid, vsi->netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2342 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2343 | return -ENOMEM; |
| 2344 | } |
| 2345 | } |
| 2346 | |
| 2347 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2348 | add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 2349 | if (!add_f) { |
| 2350 | dev_info(&vsi->back->pdev->dev, |
| 2351 | "Could not add vlan filter %d for %pM\n", |
| 2352 | vid, f->macaddr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2353 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2354 | return -ENOMEM; |
| 2355 | } |
| 2356 | } |
| 2357 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2358 | /* Now if we add a vlan tag, make sure to check if it is the first |
| 2359 | * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag" |
| 2360 | * with 0, so we now accept untagged and specified tagged traffic |
| 2361 | * (and not any taged and untagged) |
| 2362 | */ |
| 2363 | if (vid > 0) { |
| 2364 | if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr, |
| 2365 | I40E_VLAN_ANY, |
| 2366 | is_vf, is_netdev)) { |
| 2367 | i40e_del_filter(vsi, vsi->netdev->dev_addr, |
| 2368 | I40E_VLAN_ANY, is_vf, is_netdev); |
| 2369 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0, |
| 2370 | is_vf, is_netdev); |
| 2371 | if (!add_f) { |
| 2372 | dev_info(&vsi->back->pdev->dev, |
| 2373 | "Could not add filter 0 for %pM\n", |
| 2374 | vsi->netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2375 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2376 | return -ENOMEM; |
| 2377 | } |
| 2378 | } |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2379 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2380 | |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2381 | /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */ |
| 2382 | if (vid > 0 && !vsi->info.pvid) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2383 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2384 | if (!i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2385 | is_vf, is_netdev)) |
| 2386 | continue; |
| 2387 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2388 | is_vf, is_netdev); |
| 2389 | add_f = i40e_add_filter(vsi, f->macaddr, |
| 2390 | 0, is_vf, is_netdev); |
| 2391 | if (!add_f) { |
| 2392 | dev_info(&vsi->back->pdev->dev, |
| 2393 | "Could not add filter 0 for %pM\n", |
| 2394 | f->macaddr); |
| 2395 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2396 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2397 | } |
| 2398 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2399 | } |
| 2400 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2401 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2402 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2403 | /* schedule our worker thread which will take care of |
| 2404 | * applying the new filter changes |
| 2405 | */ |
| 2406 | i40e_service_event_schedule(vsi->back); |
| 2407 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | /** |
| 2411 | * i40e_vsi_kill_vlan - Remove vsi membership for given vlan |
| 2412 | * @vsi: the vsi being configured |
| 2413 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2414 | * |
| 2415 | * Return: 0 on success or negative otherwise |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2416 | **/ |
| 2417 | int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2418 | { |
| 2419 | struct net_device *netdev = vsi->netdev; |
| 2420 | struct i40e_mac_filter *f, *add_f; |
| 2421 | bool is_vf, is_netdev; |
| 2422 | int filter_count = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2423 | |
| 2424 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 2425 | is_netdev = !!(netdev); |
| 2426 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2427 | /* Locked once because all functions invoked below iterates list */ |
| 2428 | spin_lock_bh(&vsi->mac_filter_list_lock); |
| 2429 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2430 | if (is_netdev) |
| 2431 | i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev); |
| 2432 | |
| 2433 | list_for_each_entry(f, &vsi->mac_filter_list, list) |
| 2434 | i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 2435 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2436 | /* go through all the filters for this VSI and if there is only |
| 2437 | * vid == 0 it means there are no other filters, so vid 0 must |
| 2438 | * be replaced with -1. This signifies that we should from now |
| 2439 | * on accept any traffic (with any tag present, or untagged) |
| 2440 | */ |
| 2441 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2442 | if (is_netdev) { |
| 2443 | if (f->vlan && |
| 2444 | ether_addr_equal(netdev->dev_addr, f->macaddr)) |
| 2445 | filter_count++; |
| 2446 | } |
| 2447 | |
| 2448 | if (f->vlan) |
| 2449 | filter_count++; |
| 2450 | } |
| 2451 | |
| 2452 | if (!filter_count && is_netdev) { |
| 2453 | i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev); |
| 2454 | f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, |
| 2455 | is_vf, is_netdev); |
| 2456 | if (!f) { |
| 2457 | dev_info(&vsi->back->pdev->dev, |
| 2458 | "Could not add filter %d for %pM\n", |
| 2459 | I40E_VLAN_ANY, netdev->dev_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2460 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2461 | return -ENOMEM; |
| 2462 | } |
| 2463 | } |
| 2464 | |
| 2465 | if (!filter_count) { |
| 2466 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2467 | i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev); |
| 2468 | add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2469 | is_vf, is_netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2470 | if (!add_f) { |
| 2471 | dev_info(&vsi->back->pdev->dev, |
| 2472 | "Could not add filter %d for %pM\n", |
| 2473 | I40E_VLAN_ANY, f->macaddr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2474 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2475 | return -ENOMEM; |
| 2476 | } |
| 2477 | } |
| 2478 | } |
| 2479 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 2480 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 2481 | |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2482 | /* schedule our worker thread which will take care of |
| 2483 | * applying the new filter changes |
| 2484 | */ |
| 2485 | i40e_service_event_schedule(vsi->back); |
| 2486 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2487 | } |
| 2488 | |
| 2489 | /** |
| 2490 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 2491 | * @netdev: network interface to be adjusted |
| 2492 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2493 | * |
| 2494 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2495 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2496 | #ifdef I40E_FCOE |
| 2497 | int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2498 | __always_unused __be16 proto, u16 vid) |
| 2499 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2500 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2501 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2502 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2503 | { |
| 2504 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2505 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2506 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2507 | |
| 2508 | if (vid > 4095) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2509 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2510 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2511 | netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid); |
| 2512 | |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2513 | /* If the network stack called us with vid = 0 then |
| 2514 | * it is asking to receive priority tagged packets with |
| 2515 | * vlan id 0. Our HW receives them by default when configured |
| 2516 | * to receive untagged packets so there is no need to add an |
| 2517 | * extra filter for vlan 0 tagged packets. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2518 | */ |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2519 | if (vid) |
| 2520 | ret = i40e_vsi_add_vlan(vsi, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2521 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2522 | if (!ret && (vid < VLAN_N_VID)) |
| 2523 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2524 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2525 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2526 | } |
| 2527 | |
| 2528 | /** |
| 2529 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 2530 | * @netdev: network interface to be adjusted |
| 2531 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2532 | * |
Akeem G Abodunrin | fdfd943 | 2014-02-11 08:24:15 +0000 | [diff] [blame] | 2533 | * net_device_ops implementation for removing vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2534 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2535 | #ifdef I40E_FCOE |
| 2536 | int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2537 | __always_unused __be16 proto, u16 vid) |
| 2538 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2539 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2540 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2541 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2542 | { |
| 2543 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2544 | struct i40e_vsi *vsi = np->vsi; |
| 2545 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2546 | netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid); |
| 2547 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2548 | /* return code is ignored as there is nothing a user |
| 2549 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2550 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2551 | */ |
| 2552 | i40e_vsi_kill_vlan(vsi, vid); |
| 2553 | |
| 2554 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2555 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2556 | return 0; |
| 2557 | } |
| 2558 | |
| 2559 | /** |
| 2560 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 2561 | * @vsi: the vsi being brought back up |
| 2562 | **/ |
| 2563 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 2564 | { |
| 2565 | u16 vid; |
| 2566 | |
| 2567 | if (!vsi->netdev) |
| 2568 | return; |
| 2569 | |
| 2570 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2571 | |
| 2572 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 2573 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 2574 | vid); |
| 2575 | } |
| 2576 | |
| 2577 | /** |
| 2578 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2579 | * @vsi: the vsi being adjusted |
| 2580 | * @vid: the vlan id to set as a PVID |
| 2581 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2582 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2583 | { |
| 2584 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2585 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2586 | |
| 2587 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2588 | vsi->info.pvid = cpu_to_le16(vid); |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2589 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
| 2590 | I40E_AQ_VSI_PVLAN_INSERT_PVID | |
Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2591 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2592 | |
| 2593 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2594 | ctxt.info = vsi->info; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2595 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2596 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2597 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 2598 | "add pvid failed, err %s aq_err %s\n", |
| 2599 | i40e_stat_str(&vsi->back->hw, ret), |
| 2600 | i40e_aq_str(&vsi->back->hw, |
| 2601 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2602 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2603 | } |
| 2604 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2605 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | /** |
| 2609 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2610 | * @vsi: the vsi being adjusted |
| 2611 | * |
| 2612 | * Just use the vlan_rx_register() service to put it back to normal |
| 2613 | **/ |
| 2614 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2615 | { |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2616 | i40e_vlan_stripping_disable(vsi); |
| 2617 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2618 | vsi->info.pvid = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2619 | } |
| 2620 | |
| 2621 | /** |
| 2622 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2623 | * @vsi: ptr to the VSI |
| 2624 | * |
| 2625 | * If this function returns with an error, then it's possible one or |
| 2626 | * more of the rings is populated (while the rest are not). It is the |
| 2627 | * callers duty to clean those orphaned rings. |
| 2628 | * |
| 2629 | * Return 0 on success, negative on failure |
| 2630 | **/ |
| 2631 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2632 | { |
| 2633 | int i, err = 0; |
| 2634 | |
| 2635 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2636 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2637 | |
| 2638 | return err; |
| 2639 | } |
| 2640 | |
| 2641 | /** |
| 2642 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2643 | * @vsi: ptr to the VSI |
| 2644 | * |
| 2645 | * Free VSI's transmit software resources |
| 2646 | **/ |
| 2647 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2648 | { |
| 2649 | int i; |
| 2650 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2651 | if (!vsi->tx_rings) |
| 2652 | return; |
| 2653 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2654 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2655 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2656 | i40e_free_tx_resources(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2657 | } |
| 2658 | |
| 2659 | /** |
| 2660 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 2661 | * @vsi: ptr to the VSI |
| 2662 | * |
| 2663 | * If this function returns with an error, then it's possible one or |
| 2664 | * more of the rings is populated (while the rest are not). It is the |
| 2665 | * callers duty to clean those orphaned rings. |
| 2666 | * |
| 2667 | * Return 0 on success, negative on failure |
| 2668 | **/ |
| 2669 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 2670 | { |
| 2671 | int i, err = 0; |
| 2672 | |
| 2673 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2674 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2675 | #ifdef I40E_FCOE |
| 2676 | i40e_fcoe_setup_ddp_resources(vsi); |
| 2677 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2678 | return err; |
| 2679 | } |
| 2680 | |
| 2681 | /** |
| 2682 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 2683 | * @vsi: ptr to the VSI |
| 2684 | * |
| 2685 | * Free all receive software resources |
| 2686 | **/ |
| 2687 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 2688 | { |
| 2689 | int i; |
| 2690 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2691 | if (!vsi->rx_rings) |
| 2692 | return; |
| 2693 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2694 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2695 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2696 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2697 | #ifdef I40E_FCOE |
| 2698 | i40e_fcoe_free_ddp_resources(vsi); |
| 2699 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2700 | } |
| 2701 | |
| 2702 | /** |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2703 | * i40e_config_xps_tx_ring - Configure XPS for a Tx ring |
| 2704 | * @ring: The Tx ring to configure |
| 2705 | * |
| 2706 | * This enables/disables XPS for a given Tx descriptor ring |
| 2707 | * based on the TCs enabled for the VSI that ring belongs to. |
| 2708 | **/ |
| 2709 | static void i40e_config_xps_tx_ring(struct i40e_ring *ring) |
| 2710 | { |
| 2711 | struct i40e_vsi *vsi = ring->vsi; |
| 2712 | cpumask_var_t mask; |
| 2713 | |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2714 | if (!ring->q_vector || !ring->netdev) |
| 2715 | return; |
| 2716 | |
| 2717 | /* Single TC mode enable XPS */ |
| 2718 | if (vsi->tc_config.numtc <= 1) { |
| 2719 | if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2720 | netif_set_xps_queue(ring->netdev, |
| 2721 | &ring->q_vector->affinity_mask, |
| 2722 | ring->queue_index); |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2723 | } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) { |
| 2724 | /* Disable XPS to allow selection based on TC */ |
| 2725 | bitmap_zero(cpumask_bits(mask), nr_cpumask_bits); |
| 2726 | netif_set_xps_queue(ring->netdev, mask, ring->queue_index); |
| 2727 | free_cpumask_var(mask); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2728 | } |
Jesse Brandeburg | 0e4425e | 2015-11-05 17:01:01 -0800 | [diff] [blame] | 2729 | |
| 2730 | /* schedule our worker thread which will take care of |
| 2731 | * applying the new filter changes |
| 2732 | */ |
| 2733 | i40e_service_event_schedule(vsi->back); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2737 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 2738 | * @ring: The Tx ring to configure |
| 2739 | * |
| 2740 | * Configure the Tx descriptor ring in the HMC context. |
| 2741 | **/ |
| 2742 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 2743 | { |
| 2744 | struct i40e_vsi *vsi = ring->vsi; |
| 2745 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2746 | struct i40e_hw *hw = &vsi->back->hw; |
| 2747 | struct i40e_hmc_obj_txq tx_ctx; |
| 2748 | i40e_status err = 0; |
| 2749 | u32 qtx_ctl = 0; |
| 2750 | |
| 2751 | /* some ATR related tx ring init */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2752 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2753 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 2754 | ring->atr_count = 0; |
| 2755 | } else { |
| 2756 | ring->atr_sample_rate = 0; |
| 2757 | } |
| 2758 | |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2759 | /* configure XPS */ |
| 2760 | i40e_config_xps_tx_ring(ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2761 | |
| 2762 | /* clear the context structure first */ |
| 2763 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 2764 | |
| 2765 | tx_ctx.new_context = 1; |
| 2766 | tx_ctx.base = (ring->dma / 128); |
| 2767 | tx_ctx.qlen = ring->count; |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2768 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
| 2769 | I40E_FLAG_FD_ATR_ENABLED)); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2770 | #ifdef I40E_FCOE |
| 2771 | tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2772 | #endif |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2773 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 2774 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
| 2775 | if (vsi->type != I40E_VSI_FDIR) |
| 2776 | tx_ctx.head_wb_ena = 1; |
| 2777 | tx_ctx.head_wb_addr = ring->dma + |
| 2778 | (ring->count * sizeof(struct i40e_tx_desc)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2779 | |
| 2780 | /* As part of VSI creation/update, FW allocates certain |
| 2781 | * Tx arbitration queue sets for each TC enabled for |
| 2782 | * the VSI. The FW returns the handles to these queue |
| 2783 | * sets as part of the response buffer to Add VSI, |
| 2784 | * Update VSI, etc. AQ commands. It is expected that |
| 2785 | * these queue set handles be associated with the Tx |
| 2786 | * queues by the driver as part of the TX queue context |
| 2787 | * initialization. This has to be done regardless of |
| 2788 | * DCB as by default everything is mapped to TC0. |
| 2789 | */ |
| 2790 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 2791 | tx_ctx.rdylist_act = 0; |
| 2792 | |
| 2793 | /* clear the context in the HMC */ |
| 2794 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 2795 | if (err) { |
| 2796 | dev_info(&vsi->back->pdev->dev, |
| 2797 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 2798 | ring->queue_index, pf_q, err); |
| 2799 | return -ENOMEM; |
| 2800 | } |
| 2801 | |
| 2802 | /* set the context in the HMC */ |
| 2803 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 2804 | if (err) { |
| 2805 | dev_info(&vsi->back->pdev->dev, |
| 2806 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 2807 | ring->queue_index, pf_q, err); |
| 2808 | return -ENOMEM; |
| 2809 | } |
| 2810 | |
| 2811 | /* Now associate this queue with this PCI function */ |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2812 | if (vsi->type == I40E_VSI_VMDQ2) { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2813 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2814 | qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
| 2815 | I40E_QTX_CTL_VFVM_INDX_MASK; |
| 2816 | } else { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2817 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2818 | } |
| 2819 | |
Shannon Nelson | 13fd97749 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 2820 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 2821 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2822 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 2823 | i40e_flush(hw); |
| 2824 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2825 | /* cache tail off for easier writes later */ |
| 2826 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 2827 | |
| 2828 | return 0; |
| 2829 | } |
| 2830 | |
| 2831 | /** |
| 2832 | * i40e_configure_rx_ring - Configure a receive ring context |
| 2833 | * @ring: The Rx ring to configure |
| 2834 | * |
| 2835 | * Configure the Rx descriptor ring in the HMC context. |
| 2836 | **/ |
| 2837 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 2838 | { |
| 2839 | struct i40e_vsi *vsi = ring->vsi; |
| 2840 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 2841 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2842 | struct i40e_hw *hw = &vsi->back->hw; |
| 2843 | struct i40e_hmc_obj_rxq rx_ctx; |
| 2844 | i40e_status err = 0; |
| 2845 | |
| 2846 | ring->state = 0; |
| 2847 | |
| 2848 | /* clear the context structure first */ |
| 2849 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 2850 | |
| 2851 | ring->rx_buf_len = vsi->rx_buf_len; |
| 2852 | ring->rx_hdr_len = vsi->rx_hdr_len; |
| 2853 | |
| 2854 | rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT; |
| 2855 | rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT; |
| 2856 | |
| 2857 | rx_ctx.base = (ring->dma / 128); |
| 2858 | rx_ctx.qlen = ring->count; |
| 2859 | |
| 2860 | if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) { |
| 2861 | set_ring_16byte_desc_enabled(ring); |
| 2862 | rx_ctx.dsize = 0; |
| 2863 | } else { |
| 2864 | rx_ctx.dsize = 1; |
| 2865 | } |
| 2866 | |
| 2867 | rx_ctx.dtype = vsi->dtype; |
| 2868 | if (vsi->dtype) { |
| 2869 | set_ring_ps_enabled(ring); |
| 2870 | rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 | |
| 2871 | I40E_RX_SPLIT_IP | |
| 2872 | I40E_RX_SPLIT_TCP_UDP | |
| 2873 | I40E_RX_SPLIT_SCTP; |
| 2874 | } else { |
| 2875 | rx_ctx.hsplit_0 = 0; |
| 2876 | } |
| 2877 | |
| 2878 | rx_ctx.rxmax = min_t(u16, vsi->max_frame, |
| 2879 | (chain_len * ring->rx_buf_len)); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 2880 | if (hw->revision_id == 0) |
| 2881 | rx_ctx.lrxqthresh = 0; |
| 2882 | else |
| 2883 | rx_ctx.lrxqthresh = 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2884 | rx_ctx.crcstrip = 1; |
| 2885 | rx_ctx.l2tsel = 1; |
Jesse Brandeburg | c4bbac3 | 2015-09-28 11:21:48 -0700 | [diff] [blame] | 2886 | /* this controls whether VLAN is stripped from inner headers */ |
| 2887 | rx_ctx.showiv = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2888 | #ifdef I40E_FCOE |
| 2889 | rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2890 | #endif |
Catherine Sullivan | acb3676 | 2014-03-06 09:02:30 +0000 | [diff] [blame] | 2891 | /* set the prefena field to 1 because the manual says to */ |
| 2892 | rx_ctx.prefena = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2893 | |
| 2894 | /* clear the context in the HMC */ |
| 2895 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 2896 | if (err) { |
| 2897 | dev_info(&vsi->back->pdev->dev, |
| 2898 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2899 | ring->queue_index, pf_q, err); |
| 2900 | return -ENOMEM; |
| 2901 | } |
| 2902 | |
| 2903 | /* set the context in the HMC */ |
| 2904 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 2905 | if (err) { |
| 2906 | dev_info(&vsi->back->pdev->dev, |
| 2907 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2908 | ring->queue_index, pf_q, err); |
| 2909 | return -ENOMEM; |
| 2910 | } |
| 2911 | |
| 2912 | /* cache tail for quicker writes, and clear the reg before use */ |
| 2913 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 2914 | writel(0, ring->tail); |
| 2915 | |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 2916 | if (ring_is_ps_enabled(ring)) { |
| 2917 | i40e_alloc_rx_headers(ring); |
| 2918 | i40e_alloc_rx_buffers_ps(ring, I40E_DESC_UNUSED(ring)); |
| 2919 | } else { |
| 2920 | i40e_alloc_rx_buffers_1buf(ring, I40E_DESC_UNUSED(ring)); |
| 2921 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2922 | |
| 2923 | return 0; |
| 2924 | } |
| 2925 | |
| 2926 | /** |
| 2927 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 2928 | * @vsi: VSI structure describing this set of rings and resources |
| 2929 | * |
| 2930 | * Configure the Tx VSI for operation. |
| 2931 | **/ |
| 2932 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 2933 | { |
| 2934 | int err = 0; |
| 2935 | u16 i; |
| 2936 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2937 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 2938 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2939 | |
| 2940 | return err; |
| 2941 | } |
| 2942 | |
| 2943 | /** |
| 2944 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 2945 | * @vsi: the VSI being configured |
| 2946 | * |
| 2947 | * Configure the Rx VSI for operation. |
| 2948 | **/ |
| 2949 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 2950 | { |
| 2951 | int err = 0; |
| 2952 | u16 i; |
| 2953 | |
| 2954 | if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN)) |
| 2955 | vsi->max_frame = vsi->netdev->mtu + ETH_HLEN |
| 2956 | + ETH_FCS_LEN + VLAN_HLEN; |
| 2957 | else |
| 2958 | vsi->max_frame = I40E_RXBUFFER_2048; |
| 2959 | |
| 2960 | /* figure out correct receive buffer length */ |
| 2961 | switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED | |
| 2962 | I40E_FLAG_RX_PS_ENABLED)) { |
| 2963 | case I40E_FLAG_RX_1BUF_ENABLED: |
| 2964 | vsi->rx_hdr_len = 0; |
| 2965 | vsi->rx_buf_len = vsi->max_frame; |
| 2966 | vsi->dtype = I40E_RX_DTYPE_NO_SPLIT; |
| 2967 | break; |
| 2968 | case I40E_FLAG_RX_PS_ENABLED: |
| 2969 | vsi->rx_hdr_len = I40E_RX_HDR_SIZE; |
| 2970 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 2971 | vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT; |
| 2972 | break; |
| 2973 | default: |
| 2974 | vsi->rx_hdr_len = I40E_RX_HDR_SIZE; |
| 2975 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 2976 | vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS; |
| 2977 | break; |
| 2978 | } |
| 2979 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2980 | #ifdef I40E_FCOE |
| 2981 | /* setup rx buffer for FCoE */ |
| 2982 | if ((vsi->type == I40E_VSI_FCOE) && |
| 2983 | (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) { |
| 2984 | vsi->rx_hdr_len = 0; |
| 2985 | vsi->rx_buf_len = I40E_RXBUFFER_3072; |
| 2986 | vsi->max_frame = I40E_RXBUFFER_3072; |
| 2987 | vsi->dtype = I40E_RX_DTYPE_NO_SPLIT; |
| 2988 | } |
| 2989 | |
| 2990 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2991 | /* round up for the chip's needs */ |
| 2992 | vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len, |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2993 | BIT_ULL(I40E_RXQ_CTX_HBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2994 | vsi->rx_buf_len = ALIGN(vsi->rx_buf_len, |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2995 | BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2996 | |
| 2997 | /* set up individual rings */ |
| 2998 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2999 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3000 | |
| 3001 | return err; |
| 3002 | } |
| 3003 | |
| 3004 | /** |
| 3005 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 3006 | * @vsi: ptr to the VSI |
| 3007 | **/ |
| 3008 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 3009 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3010 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3011 | u16 qoffset, qcount; |
| 3012 | int i, n; |
| 3013 | |
Parikh, Neerav | cd238a3 | 2015-02-21 06:43:37 +0000 | [diff] [blame] | 3014 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 3015 | /* Reset the TC information */ |
| 3016 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 3017 | rx_ring = vsi->rx_rings[i]; |
| 3018 | tx_ring = vsi->tx_rings[i]; |
| 3019 | rx_ring->dcb_tc = 0; |
| 3020 | tx_ring->dcb_tc = 0; |
| 3021 | } |
| 3022 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3023 | |
| 3024 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 3025 | if (!(vsi->tc_config.enabled_tc & BIT_ULL(n))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3026 | continue; |
| 3027 | |
| 3028 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 3029 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 3030 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 3031 | rx_ring = vsi->rx_rings[i]; |
| 3032 | tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3033 | rx_ring->dcb_tc = n; |
| 3034 | tx_ring->dcb_tc = n; |
| 3035 | } |
| 3036 | } |
| 3037 | } |
| 3038 | |
| 3039 | /** |
| 3040 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 3041 | * @vsi: ptr to the VSI |
| 3042 | **/ |
| 3043 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 3044 | { |
| 3045 | if (vsi->netdev) |
| 3046 | i40e_set_rx_mode(vsi->netdev); |
| 3047 | } |
| 3048 | |
| 3049 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3050 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters |
| 3051 | * @vsi: Pointer to the targeted VSI |
| 3052 | * |
| 3053 | * This function replays the hlist on the hw where all the SB Flow Director |
| 3054 | * filters were saved. |
| 3055 | **/ |
| 3056 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) |
| 3057 | { |
| 3058 | struct i40e_fdir_filter *filter; |
| 3059 | struct i40e_pf *pf = vsi->back; |
| 3060 | struct hlist_node *node; |
| 3061 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 3062 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 3063 | return; |
| 3064 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3065 | hlist_for_each_entry_safe(filter, node, |
| 3066 | &pf->fdir_filter_list, fdir_node) { |
| 3067 | i40e_add_del_fdir(vsi, filter, true); |
| 3068 | } |
| 3069 | } |
| 3070 | |
| 3071 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3072 | * i40e_vsi_configure - Set up the VSI for action |
| 3073 | * @vsi: the VSI being configured |
| 3074 | **/ |
| 3075 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 3076 | { |
| 3077 | int err; |
| 3078 | |
| 3079 | i40e_set_vsi_rx_mode(vsi); |
| 3080 | i40e_restore_vlan(vsi); |
| 3081 | i40e_vsi_config_dcb_rings(vsi); |
| 3082 | err = i40e_vsi_configure_tx(vsi); |
| 3083 | if (!err) |
| 3084 | err = i40e_vsi_configure_rx(vsi); |
| 3085 | |
| 3086 | return err; |
| 3087 | } |
| 3088 | |
| 3089 | /** |
| 3090 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 3091 | * @vsi: the VSI being configured |
| 3092 | **/ |
| 3093 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 3094 | { |
| 3095 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3096 | struct i40e_hw *hw = &pf->hw; |
| 3097 | u16 vector; |
| 3098 | int i, q; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3099 | u32 qp; |
| 3100 | |
| 3101 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 3102 | * and PFINT_LNKLSTn registers, e.g.: |
| 3103 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 3104 | */ |
| 3105 | qp = vsi->base_queue; |
| 3106 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3107 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3108 | struct i40e_q_vector *q_vector = vsi->q_vectors[i]; |
| 3109 | |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3110 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3111 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting); |
| 3112 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3113 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 3114 | q_vector->rx.itr); |
| 3115 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting); |
| 3116 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3117 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 3118 | q_vector->tx.itr); |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3119 | wr32(hw, I40E_PFINT_RATEN(vector - 1), |
| 3120 | INTRL_USEC_TO_REG(vsi->int_rate_limit)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3121 | |
| 3122 | /* Linked list for the queuepairs assigned to this vector */ |
| 3123 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 3124 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 3125 | u32 val; |
| 3126 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3127 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3128 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3129 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 3130 | (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
| 3131 | (I40E_QUEUE_TYPE_TX |
| 3132 | << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
| 3133 | |
| 3134 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3135 | |
| 3136 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3137 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3138 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 3139 | ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| |
| 3140 | (I40E_QUEUE_TYPE_RX |
| 3141 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3142 | |
| 3143 | /* Terminate the linked list */ |
| 3144 | if (q == (q_vector->num_ringpairs - 1)) |
| 3145 | val |= (I40E_QUEUE_END_OF_LIST |
| 3146 | << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3147 | |
| 3148 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3149 | qp++; |
| 3150 | } |
| 3151 | } |
| 3152 | |
| 3153 | i40e_flush(hw); |
| 3154 | } |
| 3155 | |
| 3156 | /** |
| 3157 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 3158 | * @hw: ptr to the hardware info |
| 3159 | **/ |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3160 | static void i40e_enable_misc_int_causes(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3161 | { |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3162 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3163 | u32 val; |
| 3164 | |
| 3165 | /* clear things first */ |
| 3166 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 3167 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 3168 | |
| 3169 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 3170 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 3171 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 3172 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 3173 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3174 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 3175 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 3176 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3177 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3178 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) |
| 3179 | val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3180 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3181 | if (pf->flags & I40E_FLAG_PTP) |
| 3182 | val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
| 3183 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3184 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 3185 | |
| 3186 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 3187 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
| 3188 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3189 | |
| 3190 | /* OTHER_ITR_IDX = 0 */ |
| 3191 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 3192 | } |
| 3193 | |
| 3194 | /** |
| 3195 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 3196 | * @vsi: the VSI being configured |
| 3197 | **/ |
| 3198 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 3199 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3200 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3201 | struct i40e_pf *pf = vsi->back; |
| 3202 | struct i40e_hw *hw = &pf->hw; |
| 3203 | u32 val; |
| 3204 | |
| 3205 | /* set the ITR configuration */ |
Jesse Brandeburg | ee2319c | 2015-09-28 14:16:54 -0400 | [diff] [blame] | 3206 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3207 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting); |
| 3208 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 3209 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
| 3210 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting); |
| 3211 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 3212 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 3213 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 3214 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3215 | |
| 3216 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 3217 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 3218 | |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 3219 | /* Associate the queue pair to the vector and enable the queue int */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3220 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3221 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 3222 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 3223 | |
| 3224 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 3225 | |
| 3226 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3227 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 3228 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 3229 | |
| 3230 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 3231 | i40e_flush(hw); |
| 3232 | } |
| 3233 | |
| 3234 | /** |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 3235 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 |
| 3236 | * @pf: board private structure |
| 3237 | **/ |
| 3238 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) |
| 3239 | { |
| 3240 | struct i40e_hw *hw = &pf->hw; |
| 3241 | |
| 3242 | wr32(hw, I40E_PFINT_DYN_CTL0, |
| 3243 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 3244 | i40e_flush(hw); |
| 3245 | } |
| 3246 | |
| 3247 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3248 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 3249 | * @pf: board private structure |
| 3250 | **/ |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3251 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3252 | { |
| 3253 | struct i40e_hw *hw = &pf->hw; |
| 3254 | u32 val; |
| 3255 | |
| 3256 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
| 3257 | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK | |
| 3258 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 3259 | |
| 3260 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 3261 | i40e_flush(hw); |
| 3262 | } |
| 3263 | |
| 3264 | /** |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 3265 | * i40e_irq_dynamic_disable - Disable default interrupt generation settings |
| 3266 | * @vsi: pointer to a vsi |
Greg Rose | 0314777 | 2015-01-24 09:58:29 +0000 | [diff] [blame] | 3267 | * @vector: disable a particular Hw Interrupt vector |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 3268 | **/ |
| 3269 | void i40e_irq_dynamic_disable(struct i40e_vsi *vsi, int vector) |
| 3270 | { |
| 3271 | struct i40e_pf *pf = vsi->back; |
| 3272 | struct i40e_hw *hw = &pf->hw; |
| 3273 | u32 val; |
| 3274 | |
| 3275 | val = I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT; |
| 3276 | wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val); |
| 3277 | i40e_flush(hw); |
| 3278 | } |
| 3279 | |
| 3280 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3281 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 3282 | * @irq: interrupt number |
| 3283 | * @data: pointer to a q_vector |
| 3284 | **/ |
| 3285 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 3286 | { |
| 3287 | struct i40e_q_vector *q_vector = data; |
| 3288 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3289 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3290 | return IRQ_HANDLED; |
| 3291 | |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3292 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3293 | |
| 3294 | return IRQ_HANDLED; |
| 3295 | } |
| 3296 | |
| 3297 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3298 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 3299 | * @vsi: the VSI being configured |
| 3300 | * @basename: name for the vector |
| 3301 | * |
| 3302 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 3303 | **/ |
| 3304 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 3305 | { |
| 3306 | int q_vectors = vsi->num_q_vectors; |
| 3307 | struct i40e_pf *pf = vsi->back; |
| 3308 | int base = vsi->base_vector; |
| 3309 | int rx_int_idx = 0; |
| 3310 | int tx_int_idx = 0; |
| 3311 | int vector, err; |
| 3312 | |
| 3313 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3314 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3315 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3316 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3317 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3318 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 3319 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3320 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3321 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3322 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3323 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3324 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3325 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 3326 | } else { |
| 3327 | /* skip this unused q_vector */ |
| 3328 | continue; |
| 3329 | } |
| 3330 | err = request_irq(pf->msix_entries[base + vector].vector, |
| 3331 | vsi->irq_handler, |
| 3332 | 0, |
| 3333 | q_vector->name, |
| 3334 | q_vector); |
| 3335 | if (err) { |
| 3336 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3337 | "MSIX request_irq failed, error: %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3338 | goto free_queue_irqs; |
| 3339 | } |
| 3340 | /* assign the mask for this irq */ |
| 3341 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 3342 | &q_vector->affinity_mask); |
| 3343 | } |
| 3344 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3345 | vsi->irqs_ready = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3346 | return 0; |
| 3347 | |
| 3348 | free_queue_irqs: |
| 3349 | while (vector) { |
| 3350 | vector--; |
| 3351 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 3352 | NULL); |
| 3353 | free_irq(pf->msix_entries[base + vector].vector, |
| 3354 | &(vsi->q_vectors[vector])); |
| 3355 | } |
| 3356 | return err; |
| 3357 | } |
| 3358 | |
| 3359 | /** |
| 3360 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 3361 | * @vsi: the VSI being un-configured |
| 3362 | **/ |
| 3363 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 3364 | { |
| 3365 | struct i40e_pf *pf = vsi->back; |
| 3366 | struct i40e_hw *hw = &pf->hw; |
| 3367 | int base = vsi->base_vector; |
| 3368 | int i; |
| 3369 | |
| 3370 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3371 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); |
| 3372 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3373 | } |
| 3374 | |
| 3375 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3376 | for (i = vsi->base_vector; |
| 3377 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 3378 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 3379 | |
| 3380 | i40e_flush(hw); |
| 3381 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 3382 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 3383 | } else { |
| 3384 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 3385 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 3386 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 3387 | i40e_flush(hw); |
| 3388 | synchronize_irq(pf->pdev->irq); |
| 3389 | } |
| 3390 | } |
| 3391 | |
| 3392 | /** |
| 3393 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 3394 | * @vsi: the VSI being configured |
| 3395 | **/ |
| 3396 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 3397 | { |
| 3398 | struct i40e_pf *pf = vsi->back; |
| 3399 | int i; |
| 3400 | |
| 3401 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3402 | for (i = 0; i < vsi->num_q_vectors; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3403 | i40e_irq_dynamic_enable(vsi, i); |
| 3404 | } else { |
| 3405 | i40e_irq_dynamic_enable_icr0(pf); |
| 3406 | } |
| 3407 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 3408 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3409 | return 0; |
| 3410 | } |
| 3411 | |
| 3412 | /** |
| 3413 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events |
| 3414 | * @pf: board private structure |
| 3415 | **/ |
| 3416 | static void i40e_stop_misc_vector(struct i40e_pf *pf) |
| 3417 | { |
| 3418 | /* Disable ICR 0 */ |
| 3419 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 3420 | i40e_flush(&pf->hw); |
| 3421 | } |
| 3422 | |
| 3423 | /** |
| 3424 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 3425 | * @irq: interrupt number |
| 3426 | * @data: pointer to a q_vector |
| 3427 | * |
| 3428 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 3429 | * with both queue and non-queue interrupts. This is also used in |
| 3430 | * MSIX mode to handle the non-queue interrupts. |
| 3431 | **/ |
| 3432 | static irqreturn_t i40e_intr(int irq, void *data) |
| 3433 | { |
| 3434 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 3435 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3436 | irqreturn_t ret = IRQ_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3437 | u32 icr0, icr0_remaining; |
| 3438 | u32 val, ena_mask; |
| 3439 | |
| 3440 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3441 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3442 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3443 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 3444 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3445 | goto enable_intr; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3446 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 3447 | /* if interrupt but no bits showing, must be SWINT */ |
| 3448 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 3449 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 3450 | pf->sw_int_count++; |
| 3451 | |
Anjali Singhai Jain | 0d8e143 | 2015-06-05 12:20:32 -0400 | [diff] [blame] | 3452 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
| 3453 | (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) { |
| 3454 | ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3455 | icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; |
| 3456 | dev_info(&pf->pdev->dev, "cleared PE_CRITERR\n"); |
| 3457 | } |
| 3458 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3459 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 3460 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3461 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 3462 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3463 | |
| 3464 | /* temporarily disable queue cause for NAPI processing */ |
| 3465 | u32 qval = rd32(hw, I40E_QINT_RQCTL(0)); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3466 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3467 | qval &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK; |
| 3468 | wr32(hw, I40E_QINT_RQCTL(0), qval); |
| 3469 | |
| 3470 | qval = rd32(hw, I40E_QINT_TQCTL(0)); |
| 3471 | qval &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK; |
| 3472 | wr32(hw, I40E_QINT_TQCTL(0), qval); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3473 | |
| 3474 | if (!test_bit(__I40E_DOWN, &pf->state)) |
Alexander Duyck | 5d3465a | 2015-09-29 15:19:50 -0700 | [diff] [blame] | 3475 | napi_schedule_irqoff(&q_vector->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3476 | } |
| 3477 | |
| 3478 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 3479 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3480 | set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 3481 | } |
| 3482 | |
| 3483 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 3484 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 3485 | set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 3486 | } |
| 3487 | |
| 3488 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 3489 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
| 3490 | set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
| 3491 | } |
| 3492 | |
| 3493 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
| 3494 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
| 3495 | set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 3496 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 3497 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 3498 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 3499 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3500 | if (val == I40E_RESET_CORER) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3501 | pf->corer_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3502 | } else if (val == I40E_RESET_GLOBR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3503 | pf->globr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3504 | } else if (val == I40E_RESET_EMPR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3505 | pf->empr_count++; |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 3506 | set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3507 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3508 | } |
| 3509 | |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3510 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 3511 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; |
| 3512 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
Anjali Singhai Jain | 25fc0e6 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 3513 | dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n", |
| 3514 | rd32(hw, I40E_PFHMC_ERRORINFO), |
| 3515 | rd32(hw, I40E_PFHMC_ERRORDATA)); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3516 | } |
| 3517 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3518 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
| 3519 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); |
| 3520 | |
| 3521 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { |
Jacob Keller | cafa1fc | 2014-04-24 18:05:03 -0700 | [diff] [blame] | 3522 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3523 | i40e_ptp_tx_hwtstamp(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3524 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3525 | } |
| 3526 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3527 | /* If a critical error is pending we have no choice but to reset the |
| 3528 | * device. |
| 3529 | * Report and mask out any remaining unexpected interrupts. |
| 3530 | */ |
| 3531 | icr0_remaining = icr0 & ena_mask; |
| 3532 | if (icr0_remaining) { |
| 3533 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 3534 | icr0_remaining); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3535 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3536 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
Anjali Singhai Jain | c0c2897 | 2014-02-12 01:45:34 +0000 | [diff] [blame] | 3537 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3538 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
| 3539 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 3540 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3541 | } |
| 3542 | ena_mask &= ~icr0_remaining; |
| 3543 | } |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3544 | ret = IRQ_HANDLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3545 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3546 | enable_intr: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3547 | /* re-enable interrupt causes */ |
| 3548 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3549 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 3550 | i40e_service_event_schedule(pf); |
| 3551 | i40e_irq_dynamic_enable_icr0(pf); |
| 3552 | } |
| 3553 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3554 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3555 | } |
| 3556 | |
| 3557 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3558 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes |
| 3559 | * @tx_ring: tx ring to clean |
| 3560 | * @budget: how many cleans we're allowed |
| 3561 | * |
| 3562 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 3563 | **/ |
| 3564 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) |
| 3565 | { |
| 3566 | struct i40e_vsi *vsi = tx_ring->vsi; |
| 3567 | u16 i = tx_ring->next_to_clean; |
| 3568 | struct i40e_tx_buffer *tx_buf; |
| 3569 | struct i40e_tx_desc *tx_desc; |
| 3570 | |
| 3571 | tx_buf = &tx_ring->tx_bi[i]; |
| 3572 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 3573 | i -= tx_ring->count; |
| 3574 | |
| 3575 | do { |
| 3576 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 3577 | |
| 3578 | /* if next_to_watch is not set then there is no work pending */ |
| 3579 | if (!eop_desc) |
| 3580 | break; |
| 3581 | |
| 3582 | /* prevent any other reads prior to eop_desc */ |
| 3583 | read_barrier_depends(); |
| 3584 | |
| 3585 | /* if the descriptor isn't done, no work yet to do */ |
| 3586 | if (!(eop_desc->cmd_type_offset_bsz & |
| 3587 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
| 3588 | break; |
| 3589 | |
| 3590 | /* clear next_to_watch to prevent false hangs */ |
| 3591 | tx_buf->next_to_watch = NULL; |
| 3592 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3593 | tx_desc->buffer_addr = 0; |
| 3594 | tx_desc->cmd_type_offset_bsz = 0; |
| 3595 | /* move past filter desc */ |
| 3596 | tx_buf++; |
| 3597 | tx_desc++; |
| 3598 | i++; |
| 3599 | if (unlikely(!i)) { |
| 3600 | i -= tx_ring->count; |
| 3601 | tx_buf = tx_ring->tx_bi; |
| 3602 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3603 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3604 | /* unmap skb header data */ |
| 3605 | dma_unmap_single(tx_ring->dev, |
| 3606 | dma_unmap_addr(tx_buf, dma), |
| 3607 | dma_unmap_len(tx_buf, len), |
| 3608 | DMA_TO_DEVICE); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3609 | if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB) |
| 3610 | kfree(tx_buf->raw_buf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3611 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3612 | tx_buf->raw_buf = NULL; |
| 3613 | tx_buf->tx_flags = 0; |
| 3614 | tx_buf->next_to_watch = NULL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3615 | dma_unmap_len_set(tx_buf, len, 0); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3616 | tx_desc->buffer_addr = 0; |
| 3617 | tx_desc->cmd_type_offset_bsz = 0; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3618 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3619 | /* 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] | 3620 | tx_buf++; |
| 3621 | tx_desc++; |
| 3622 | i++; |
| 3623 | if (unlikely(!i)) { |
| 3624 | i -= tx_ring->count; |
| 3625 | tx_buf = tx_ring->tx_bi; |
| 3626 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3627 | } |
| 3628 | |
| 3629 | /* update budget accounting */ |
| 3630 | budget--; |
| 3631 | } while (likely(budget)); |
| 3632 | |
| 3633 | i += tx_ring->count; |
| 3634 | tx_ring->next_to_clean = i; |
| 3635 | |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3636 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) |
Jesse Brandeburg | 7845548 | 2015-07-23 16:54:41 -0400 | [diff] [blame] | 3637 | i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 3638 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3639 | return budget > 0; |
| 3640 | } |
| 3641 | |
| 3642 | /** |
| 3643 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring |
| 3644 | * @irq: interrupt number |
| 3645 | * @data: pointer to a q_vector |
| 3646 | **/ |
| 3647 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) |
| 3648 | { |
| 3649 | struct i40e_q_vector *q_vector = data; |
| 3650 | struct i40e_vsi *vsi; |
| 3651 | |
| 3652 | if (!q_vector->tx.ring) |
| 3653 | return IRQ_HANDLED; |
| 3654 | |
| 3655 | vsi = q_vector->tx.ring->vsi; |
| 3656 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); |
| 3657 | |
| 3658 | return IRQ_HANDLED; |
| 3659 | } |
| 3660 | |
| 3661 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3662 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3663 | * @vsi: the VSI being configured |
| 3664 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3665 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3666 | **/ |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3667 | 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] | 3668 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3669 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3670 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 3671 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3672 | |
| 3673 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3674 | tx_ring->next = q_vector->tx.ring; |
| 3675 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3676 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3677 | |
| 3678 | rx_ring->q_vector = q_vector; |
| 3679 | rx_ring->next = q_vector->rx.ring; |
| 3680 | q_vector->rx.ring = rx_ring; |
| 3681 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3682 | } |
| 3683 | |
| 3684 | /** |
| 3685 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 3686 | * @vsi: the VSI being configured |
| 3687 | * |
| 3688 | * This function maps descriptor rings to the queue-specific vectors |
| 3689 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 3690 | * one vector per queue pair, but on a constrained vector budget, we |
| 3691 | * group the queue pairs as "efficiently" as possible. |
| 3692 | **/ |
| 3693 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 3694 | { |
| 3695 | int qp_remaining = vsi->num_queue_pairs; |
| 3696 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3697 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3698 | int v_start = 0; |
| 3699 | int qp_idx = 0; |
| 3700 | |
| 3701 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 3702 | * group them so there are multiple queues per vector. |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3703 | * It is also important to go through all the vectors available to be |
| 3704 | * sure that if we don't use all the vectors, that the remaining vectors |
| 3705 | * are cleared. This is especially important when decreasing the |
| 3706 | * number of queues in use. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3707 | */ |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3708 | for (; v_start < q_vectors; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3709 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 3710 | |
| 3711 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 3712 | |
| 3713 | q_vector->num_ringpairs = num_ringpairs; |
| 3714 | |
| 3715 | q_vector->rx.count = 0; |
| 3716 | q_vector->tx.count = 0; |
| 3717 | q_vector->rx.ring = NULL; |
| 3718 | q_vector->tx.ring = NULL; |
| 3719 | |
| 3720 | while (num_ringpairs--) { |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 3721 | i40e_map_vector_to_qp(vsi, v_start, qp_idx); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3722 | qp_idx++; |
| 3723 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3724 | } |
| 3725 | } |
| 3726 | } |
| 3727 | |
| 3728 | /** |
| 3729 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 3730 | * @vsi: the VSI being configured |
| 3731 | * @basename: name for the vector |
| 3732 | **/ |
| 3733 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 3734 | { |
| 3735 | struct i40e_pf *pf = vsi->back; |
| 3736 | int err; |
| 3737 | |
| 3738 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 3739 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 3740 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 3741 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3742 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3743 | else |
| 3744 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3745 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3746 | |
| 3747 | if (err) |
| 3748 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 3749 | |
| 3750 | return err; |
| 3751 | } |
| 3752 | |
| 3753 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3754 | /** |
| 3755 | * i40e_netpoll - A Polling 'interrupt'handler |
| 3756 | * @netdev: network interface device structure |
| 3757 | * |
| 3758 | * This is used by netconsole to send skbs without having to re-enable |
| 3759 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 3760 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3761 | #ifdef I40E_FCOE |
| 3762 | void i40e_netpoll(struct net_device *netdev) |
| 3763 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3764 | static void i40e_netpoll(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3765 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3766 | { |
| 3767 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3768 | struct i40e_vsi *vsi = np->vsi; |
| 3769 | struct i40e_pf *pf = vsi->back; |
| 3770 | int i; |
| 3771 | |
| 3772 | /* if interface is down do nothing */ |
| 3773 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 3774 | return; |
| 3775 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3776 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3777 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3778 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3779 | } else { |
| 3780 | i40e_intr(pf->pdev->irq, netdev); |
| 3781 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3782 | } |
| 3783 | #endif |
| 3784 | |
| 3785 | /** |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3786 | * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled |
| 3787 | * @pf: the PF being configured |
| 3788 | * @pf_q: the PF queue |
| 3789 | * @enable: enable or disable state of the queue |
| 3790 | * |
| 3791 | * This routine will wait for the given Tx queue of the PF to reach the |
| 3792 | * enabled or disabled state. |
| 3793 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3794 | * multiple retries; else will return 0 in case of success. |
| 3795 | **/ |
| 3796 | static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3797 | { |
| 3798 | int i; |
| 3799 | u32 tx_reg; |
| 3800 | |
| 3801 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3802 | tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q)); |
| 3803 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 3804 | break; |
| 3805 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3806 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3807 | } |
| 3808 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3809 | return -ETIMEDOUT; |
| 3810 | |
| 3811 | return 0; |
| 3812 | } |
| 3813 | |
| 3814 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3815 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 3816 | * @vsi: the VSI being configured |
| 3817 | * @enable: start or stop the rings |
| 3818 | **/ |
| 3819 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 3820 | { |
| 3821 | struct i40e_pf *pf = vsi->back; |
| 3822 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3823 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3824 | u32 tx_reg; |
| 3825 | |
| 3826 | pf_q = vsi->base_queue; |
| 3827 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3828 | |
| 3829 | /* warn the TX unit of coming changes */ |
| 3830 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); |
| 3831 | if (!enable) |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3832 | usleep_range(10, 20); |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3833 | |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3834 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3835 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3836 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3837 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3838 | break; |
| 3839 | usleep_range(1000, 2000); |
| 3840 | } |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3841 | /* Skip if the queue is already in the requested state */ |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3842 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3843 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3844 | |
| 3845 | /* turn on/off the queue */ |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3846 | if (enable) { |
| 3847 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3848 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3849 | } else { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3850 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3851 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3852 | |
| 3853 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 3854 | /* No waiting for the Tx queue to disable */ |
| 3855 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3856 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3857 | |
| 3858 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3859 | ret = i40e_pf_txq_wait(pf, pf_q, enable); |
| 3860 | if (ret) { |
| 3861 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3862 | "VSI seid %d Tx ring %d %sable timeout\n", |
| 3863 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3864 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3865 | } |
| 3866 | } |
| 3867 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3868 | if (hw->revision_id == 0) |
| 3869 | mdelay(50); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3870 | return ret; |
| 3871 | } |
| 3872 | |
| 3873 | /** |
| 3874 | * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled |
| 3875 | * @pf: the PF being configured |
| 3876 | * @pf_q: the PF queue |
| 3877 | * @enable: enable or disable state of the queue |
| 3878 | * |
| 3879 | * This routine will wait for the given Rx queue of the PF to reach the |
| 3880 | * enabled or disabled state. |
| 3881 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3882 | * multiple retries; else will return 0 in case of success. |
| 3883 | **/ |
| 3884 | static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3885 | { |
| 3886 | int i; |
| 3887 | u32 rx_reg; |
| 3888 | |
| 3889 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3890 | rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q)); |
| 3891 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3892 | break; |
| 3893 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3894 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3895 | } |
| 3896 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3897 | return -ETIMEDOUT; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3898 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3899 | return 0; |
| 3900 | } |
| 3901 | |
| 3902 | /** |
| 3903 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 3904 | * @vsi: the VSI being configured |
| 3905 | * @enable: start or stop the rings |
| 3906 | **/ |
| 3907 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 3908 | { |
| 3909 | struct i40e_pf *pf = vsi->back; |
| 3910 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3911 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3912 | u32 rx_reg; |
| 3913 | |
| 3914 | pf_q = vsi->base_queue; |
| 3915 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3916 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3917 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3918 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3919 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3920 | break; |
| 3921 | usleep_range(1000, 2000); |
| 3922 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3923 | |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3924 | /* Skip if the queue is already in the requested state */ |
| 3925 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3926 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3927 | |
| 3928 | /* turn on/off the queue */ |
| 3929 | if (enable) |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3930 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3931 | else |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3932 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3933 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
| 3934 | |
| 3935 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3936 | ret = i40e_pf_rxq_wait(pf, pf_q, enable); |
| 3937 | if (ret) { |
| 3938 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 3939 | "VSI seid %d Rx ring %d %sable timeout\n", |
| 3940 | vsi->seid, pf_q, (enable ? "en" : "dis")); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3941 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3942 | } |
| 3943 | } |
| 3944 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3945 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3946 | } |
| 3947 | |
| 3948 | /** |
| 3949 | * i40e_vsi_control_rings - Start or stop a VSI's rings |
| 3950 | * @vsi: the VSI being configured |
| 3951 | * @enable: start or stop the rings |
| 3952 | **/ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 3953 | int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3954 | { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3955 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3956 | |
| 3957 | /* do rx first for enable and last for disable */ |
| 3958 | if (request) { |
| 3959 | ret = i40e_vsi_control_rx(vsi, request); |
| 3960 | if (ret) |
| 3961 | return ret; |
| 3962 | ret = i40e_vsi_control_tx(vsi, request); |
| 3963 | } else { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3964 | /* Ignore return value, we need to shutdown whatever we can */ |
| 3965 | i40e_vsi_control_tx(vsi, request); |
| 3966 | i40e_vsi_control_rx(vsi, request); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3967 | } |
| 3968 | |
| 3969 | return ret; |
| 3970 | } |
| 3971 | |
| 3972 | /** |
| 3973 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 3974 | * @vsi: the VSI being configured |
| 3975 | **/ |
| 3976 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 3977 | { |
| 3978 | struct i40e_pf *pf = vsi->back; |
| 3979 | struct i40e_hw *hw = &pf->hw; |
| 3980 | int base = vsi->base_vector; |
| 3981 | u32 val, qp; |
| 3982 | int i; |
| 3983 | |
| 3984 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3985 | if (!vsi->q_vectors) |
| 3986 | return; |
| 3987 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3988 | if (!vsi->irqs_ready) |
| 3989 | return; |
| 3990 | |
| 3991 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3992 | for (i = 0; i < vsi->num_q_vectors; i++) { |
| 3993 | u16 vector = i + base; |
| 3994 | |
| 3995 | /* free only the irqs that were actually requested */ |
Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 3996 | if (!vsi->q_vectors[i] || |
| 3997 | !vsi->q_vectors[i]->num_ringpairs) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3998 | continue; |
| 3999 | |
| 4000 | /* clear the affinity_mask in the IRQ descriptor */ |
| 4001 | irq_set_affinity_hint(pf->msix_entries[vector].vector, |
| 4002 | NULL); |
| 4003 | free_irq(pf->msix_entries[vector].vector, |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4004 | vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4005 | |
| 4006 | /* Tear down the interrupt queue link list |
| 4007 | * |
| 4008 | * We know that they come in pairs and always |
| 4009 | * the Rx first, then the Tx. To clear the |
| 4010 | * link list, stick the EOL value into the |
| 4011 | * next_q field of the registers. |
| 4012 | */ |
| 4013 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 4014 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4015 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4016 | val |= I40E_QUEUE_END_OF_LIST |
| 4017 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4018 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 4019 | |
| 4020 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 4021 | u32 next; |
| 4022 | |
| 4023 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4024 | |
| 4025 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4026 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4027 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4028 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4029 | |
| 4030 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4031 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4032 | |
| 4033 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4034 | |
| 4035 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4036 | |
| 4037 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 4038 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 4039 | |
| 4040 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4041 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4042 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4043 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4044 | |
| 4045 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4046 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4047 | |
| 4048 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4049 | qp = next; |
| 4050 | } |
| 4051 | } |
| 4052 | } else { |
| 4053 | free_irq(pf->pdev->irq, pf); |
| 4054 | |
| 4055 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 4056 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 4057 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 4058 | val |= I40E_QUEUE_END_OF_LIST |
| 4059 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 4060 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 4061 | |
| 4062 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 4063 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 4064 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 4065 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 4066 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 4067 | |
| 4068 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 4069 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 4070 | |
| 4071 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 4072 | |
| 4073 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 4074 | |
| 4075 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 4076 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 4077 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 4078 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 4079 | |
| 4080 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 4081 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 4082 | |
| 4083 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 4084 | } |
| 4085 | } |
| 4086 | |
| 4087 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4088 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 4089 | * @vsi: the VSI being configured |
| 4090 | * @v_idx: Index of vector to be freed |
| 4091 | * |
| 4092 | * This function frees the memory allocated to the q_vector. In addition if |
| 4093 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4094 | * to freeing the q_vector. |
| 4095 | **/ |
| 4096 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 4097 | { |
| 4098 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4099 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4100 | |
| 4101 | if (!q_vector) |
| 4102 | return; |
| 4103 | |
| 4104 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 4105 | i40e_for_each_ring(ring, q_vector->tx) |
| 4106 | ring->q_vector = NULL; |
| 4107 | |
| 4108 | i40e_for_each_ring(ring, q_vector->rx) |
| 4109 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4110 | |
| 4111 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 4112 | if (vsi->netdev) |
| 4113 | netif_napi_del(&q_vector->napi); |
| 4114 | |
| 4115 | vsi->q_vectors[v_idx] = NULL; |
| 4116 | |
| 4117 | kfree_rcu(q_vector, rcu); |
| 4118 | } |
| 4119 | |
| 4120 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4121 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 4122 | * @vsi: the VSI being un-configured |
| 4123 | * |
| 4124 | * This frees the memory allocated to the q_vectors and |
| 4125 | * deletes references to the NAPI struct. |
| 4126 | **/ |
| 4127 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 4128 | { |
| 4129 | int v_idx; |
| 4130 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4131 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 4132 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4133 | } |
| 4134 | |
| 4135 | /** |
| 4136 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 4137 | * @pf: board private structure |
| 4138 | **/ |
| 4139 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 4140 | { |
| 4141 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 4142 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4143 | pci_disable_msix(pf->pdev); |
| 4144 | kfree(pf->msix_entries); |
| 4145 | pf->msix_entries = NULL; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 4146 | kfree(pf->irq_pile); |
| 4147 | pf->irq_pile = NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4148 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 4149 | pci_disable_msi(pf->pdev); |
| 4150 | } |
| 4151 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 4152 | } |
| 4153 | |
| 4154 | /** |
| 4155 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 4156 | * @pf: board private structure |
| 4157 | * |
| 4158 | * We go through and clear interrupt specific resources and reset the structure |
| 4159 | * to pre-load conditions |
| 4160 | **/ |
| 4161 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 4162 | { |
| 4163 | int i; |
| 4164 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 4165 | i40e_stop_misc_vector(pf); |
| 4166 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 4167 | synchronize_irq(pf->msix_entries[0].vector); |
| 4168 | free_irq(pf->msix_entries[0].vector, pf); |
| 4169 | } |
| 4170 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4171 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4172 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4173 | if (pf->vsi[i]) |
| 4174 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 4175 | i40e_reset_interrupt_capability(pf); |
| 4176 | } |
| 4177 | |
| 4178 | /** |
| 4179 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 4180 | * @vsi: the VSI being configured |
| 4181 | **/ |
| 4182 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 4183 | { |
| 4184 | int q_idx; |
| 4185 | |
| 4186 | if (!vsi->netdev) |
| 4187 | return; |
| 4188 | |
| 4189 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4190 | napi_enable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4191 | } |
| 4192 | |
| 4193 | /** |
| 4194 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 4195 | * @vsi: the VSI being configured |
| 4196 | **/ |
| 4197 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 4198 | { |
| 4199 | int q_idx; |
| 4200 | |
| 4201 | if (!vsi->netdev) |
| 4202 | return; |
| 4203 | |
| 4204 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 4205 | napi_disable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4206 | } |
| 4207 | |
| 4208 | /** |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4209 | * i40e_vsi_close - Shut down a VSI |
| 4210 | * @vsi: the vsi to be quelled |
| 4211 | **/ |
| 4212 | static void i40e_vsi_close(struct i40e_vsi *vsi) |
| 4213 | { |
| 4214 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) |
| 4215 | i40e_down(vsi); |
| 4216 | i40e_vsi_free_irq(vsi); |
| 4217 | i40e_vsi_free_tx_resources(vsi); |
| 4218 | i40e_vsi_free_rx_resources(vsi); |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 4219 | vsi->current_netdev_flags = 0; |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4220 | } |
| 4221 | |
| 4222 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4223 | * i40e_quiesce_vsi - Pause a given VSI |
| 4224 | * @vsi: the VSI being paused |
| 4225 | **/ |
| 4226 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 4227 | { |
| 4228 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 4229 | return; |
| 4230 | |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4231 | /* No need to disable FCoE VSI when Tx suspended */ |
| 4232 | if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) && |
| 4233 | vsi->type == I40E_VSI_FCOE) { |
| 4234 | dev_dbg(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4235 | "VSI seid %d skipping FCoE VSI disable\n", vsi->seid); |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4236 | return; |
| 4237 | } |
| 4238 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4239 | set_bit(__I40E_NEEDS_RESTART, &vsi->state); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4240 | if (vsi->netdev && netif_running(vsi->netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4241 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 4242 | else |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4243 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4244 | } |
| 4245 | |
| 4246 | /** |
| 4247 | * i40e_unquiesce_vsi - Resume a given VSI |
| 4248 | * @vsi: the VSI being resumed |
| 4249 | **/ |
| 4250 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 4251 | { |
| 4252 | if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) |
| 4253 | return; |
| 4254 | |
| 4255 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 4256 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 4257 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 4258 | else |
Shannon Nelson | 8276f75 | 2014-03-14 07:32:27 +0000 | [diff] [blame] | 4259 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4260 | } |
| 4261 | |
| 4262 | /** |
| 4263 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 4264 | * @pf: the PF |
| 4265 | **/ |
| 4266 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 4267 | { |
| 4268 | int v; |
| 4269 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4270 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4271 | if (pf->vsi[v]) |
| 4272 | i40e_quiesce_vsi(pf->vsi[v]); |
| 4273 | } |
| 4274 | } |
| 4275 | |
| 4276 | /** |
| 4277 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 4278 | * @pf: the PF |
| 4279 | **/ |
| 4280 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 4281 | { |
| 4282 | int v; |
| 4283 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4284 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4285 | if (pf->vsi[v]) |
| 4286 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 4287 | } |
| 4288 | } |
| 4289 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4290 | #ifdef CONFIG_I40E_DCB |
| 4291 | /** |
| 4292 | * i40e_vsi_wait_txq_disabled - Wait for VSI's queues to be disabled |
| 4293 | * @vsi: the VSI being configured |
| 4294 | * |
| 4295 | * This function waits for the given VSI's Tx queues to be disabled. |
| 4296 | **/ |
| 4297 | static int i40e_vsi_wait_txq_disabled(struct i40e_vsi *vsi) |
| 4298 | { |
| 4299 | struct i40e_pf *pf = vsi->back; |
| 4300 | int i, pf_q, ret; |
| 4301 | |
| 4302 | pf_q = vsi->base_queue; |
| 4303 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4304 | /* Check and wait for the disable status of the queue */ |
| 4305 | ret = i40e_pf_txq_wait(pf, pf_q, false); |
| 4306 | if (ret) { |
| 4307 | dev_info(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 4308 | "VSI seid %d Tx ring %d disable timeout\n", |
| 4309 | vsi->seid, pf_q); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4310 | return ret; |
| 4311 | } |
| 4312 | } |
| 4313 | |
| 4314 | return 0; |
| 4315 | } |
| 4316 | |
| 4317 | /** |
| 4318 | * i40e_pf_wait_txq_disabled - Wait for all queues of PF VSIs to be disabled |
| 4319 | * @pf: the PF |
| 4320 | * |
| 4321 | * This function waits for the Tx queues to be in disabled state for all the |
| 4322 | * VSIs that are managed by this PF. |
| 4323 | **/ |
| 4324 | static int i40e_pf_wait_txq_disabled(struct i40e_pf *pf) |
| 4325 | { |
| 4326 | int v, ret = 0; |
| 4327 | |
| 4328 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4329 | /* No need to wait for FCoE VSI queues */ |
| 4330 | if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) { |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4331 | ret = i40e_vsi_wait_txq_disabled(pf->vsi[v]); |
| 4332 | if (ret) |
| 4333 | break; |
| 4334 | } |
| 4335 | } |
| 4336 | |
| 4337 | return ret; |
| 4338 | } |
| 4339 | |
| 4340 | #endif |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4341 | |
| 4342 | /** |
| 4343 | * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue |
| 4344 | * @q_idx: TX queue number |
| 4345 | * @vsi: Pointer to VSI struct |
| 4346 | * |
| 4347 | * This function checks specified queue for given VSI. Detects hung condition. |
| 4348 | * Sets hung bit since it is two step process. Before next run of service task |
| 4349 | * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not, |
| 4350 | * hung condition remain unchanged and during subsequent run, this function |
| 4351 | * issues SW interrupt to recover from hung condition. |
| 4352 | **/ |
| 4353 | static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi) |
| 4354 | { |
| 4355 | struct i40e_ring *tx_ring = NULL; |
| 4356 | struct i40e_pf *pf; |
| 4357 | u32 head, val, tx_pending; |
| 4358 | int i; |
| 4359 | |
| 4360 | pf = vsi->back; |
| 4361 | |
| 4362 | /* now that we have an index, find the tx_ring struct */ |
| 4363 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 4364 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { |
| 4365 | if (q_idx == vsi->tx_rings[i]->queue_index) { |
| 4366 | tx_ring = vsi->tx_rings[i]; |
| 4367 | break; |
| 4368 | } |
| 4369 | } |
| 4370 | } |
| 4371 | |
| 4372 | if (!tx_ring) |
| 4373 | return; |
| 4374 | |
| 4375 | /* Read interrupt register */ |
| 4376 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4377 | val = rd32(&pf->hw, |
| 4378 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + |
| 4379 | tx_ring->vsi->base_vector - 1)); |
| 4380 | else |
| 4381 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); |
| 4382 | |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4383 | /* Bail out if interrupts are disabled because napi_poll |
| 4384 | * execution in-progress or will get scheduled soon. |
| 4385 | * napi_poll cleans TX and RX queues and updates 'next_to_clean'. |
| 4386 | */ |
| 4387 | if (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK)) |
| 4388 | return; |
| 4389 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4390 | head = i40e_get_head(tx_ring); |
| 4391 | |
| 4392 | tx_pending = i40e_get_tx_pending(tx_ring); |
| 4393 | |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4394 | /* HW is done executing descriptors, updated HEAD write back, |
| 4395 | * but SW hasn't processed those descriptors. If interrupt is |
| 4396 | * not generated from this point ON, it could result into |
| 4397 | * dev_watchdog detecting timeout on those netdev_queue, |
| 4398 | * hence proactively trigger SW interrupt. |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4399 | */ |
Kiran Patil | 9c6c125 | 2015-11-06 15:26:02 -0800 | [diff] [blame] | 4400 | if (tx_pending) { |
| 4401 | /* NAPI Poll didn't run and clear since it was set */ |
| 4402 | if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4403 | &tx_ring->q_vector->hung_detected)) { |
| 4404 | netdev_info(vsi->netdev, "VSI_seid %d, Hung TX queue %d, tx_pending: %d, NTC:0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x\n", |
| 4405 | vsi->seid, q_idx, tx_pending, |
| 4406 | tx_ring->next_to_clean, head, |
| 4407 | tx_ring->next_to_use, |
| 4408 | readl(tx_ring->tail)); |
| 4409 | netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n", |
| 4410 | vsi->seid, q_idx, val); |
| 4411 | i40e_force_wb(vsi, tx_ring->q_vector); |
| 4412 | } else { |
| 4413 | /* First Chance - detected possible hung */ |
| 4414 | set_bit(I40E_Q_VECTOR_HUNG_DETECT, |
| 4415 | &tx_ring->q_vector->hung_detected); |
| 4416 | } |
| 4417 | } |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 4418 | } |
| 4419 | |
| 4420 | /** |
| 4421 | * i40e_detect_recover_hung - Function to detect and recover hung_queues |
| 4422 | * @pf: pointer to PF struct |
| 4423 | * |
| 4424 | * LAN VSI has netdev and netdev has TX queues. This function is to check |
| 4425 | * each of those TX queues if they are hung, trigger recovery by issuing |
| 4426 | * SW interrupt. |
| 4427 | **/ |
| 4428 | static void i40e_detect_recover_hung(struct i40e_pf *pf) |
| 4429 | { |
| 4430 | struct net_device *netdev; |
| 4431 | struct i40e_vsi *vsi; |
| 4432 | int i; |
| 4433 | |
| 4434 | /* Only for LAN VSI */ |
| 4435 | vsi = pf->vsi[pf->lan_vsi]; |
| 4436 | |
| 4437 | if (!vsi) |
| 4438 | return; |
| 4439 | |
| 4440 | /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */ |
| 4441 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 4442 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 4443 | return; |
| 4444 | |
| 4445 | /* Make sure type is MAIN VSI */ |
| 4446 | if (vsi->type != I40E_VSI_MAIN) |
| 4447 | return; |
| 4448 | |
| 4449 | netdev = vsi->netdev; |
| 4450 | if (!netdev) |
| 4451 | return; |
| 4452 | |
| 4453 | /* Bail out if netif_carrier is not OK */ |
| 4454 | if (!netif_carrier_ok(netdev)) |
| 4455 | return; |
| 4456 | |
| 4457 | /* Go thru' TX queues for netdev */ |
| 4458 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 4459 | struct netdev_queue *q; |
| 4460 | |
| 4461 | q = netdev_get_tx_queue(netdev, i); |
| 4462 | if (q) |
| 4463 | i40e_detect_recover_hung_queue(i, vsi); |
| 4464 | } |
| 4465 | } |
| 4466 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4467 | /** |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4468 | * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4469 | * @pf: pointer to PF |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4470 | * |
| 4471 | * Get TC map for ISCSI PF type that will include iSCSI TC |
| 4472 | * and LAN TC. |
| 4473 | **/ |
| 4474 | static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf) |
| 4475 | { |
| 4476 | struct i40e_dcb_app_priority_table app; |
| 4477 | struct i40e_hw *hw = &pf->hw; |
| 4478 | u8 enabled_tc = 1; /* TC0 is always enabled */ |
| 4479 | u8 tc, i; |
| 4480 | /* Get the iSCSI APP TLV */ |
| 4481 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4482 | |
| 4483 | for (i = 0; i < dcbcfg->numapps; i++) { |
| 4484 | app = dcbcfg->app[i]; |
| 4485 | if (app.selector == I40E_APP_SEL_TCPIP && |
| 4486 | app.protocolid == I40E_APP_PROTOID_ISCSI) { |
| 4487 | tc = dcbcfg->etscfg.prioritytable[app.priority]; |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4488 | enabled_tc |= BIT(tc); |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4489 | break; |
| 4490 | } |
| 4491 | } |
| 4492 | |
| 4493 | return enabled_tc; |
| 4494 | } |
| 4495 | |
| 4496 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4497 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 4498 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4499 | * |
| 4500 | * Return the number of TCs from given DCBx configuration |
| 4501 | **/ |
| 4502 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 4503 | { |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4504 | u8 num_tc = 0; |
| 4505 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4506 | |
| 4507 | /* Scan the ETS Config Priority Table to find |
| 4508 | * traffic class enabled for a given priority |
| 4509 | * and use the traffic class index to get the |
| 4510 | * number of traffic classes enabled |
| 4511 | */ |
| 4512 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4513 | if (dcbcfg->etscfg.prioritytable[i] > num_tc) |
| 4514 | num_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4515 | } |
| 4516 | |
| 4517 | /* Traffic class index starts from zero so |
| 4518 | * increment to return the actual count |
| 4519 | */ |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4520 | return num_tc + 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4521 | } |
| 4522 | |
| 4523 | /** |
| 4524 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 4525 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4526 | * |
| 4527 | * Query the current DCB configuration and return the number of |
| 4528 | * traffic classes enabled from the given DCBX config |
| 4529 | **/ |
| 4530 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 4531 | { |
| 4532 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 4533 | u8 enabled_tc = 1; |
| 4534 | u8 i; |
| 4535 | |
| 4536 | for (i = 0; i < num_tc; i++) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4537 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4538 | |
| 4539 | return enabled_tc; |
| 4540 | } |
| 4541 | |
| 4542 | /** |
| 4543 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 4544 | * @pf: PF being queried |
| 4545 | * |
| 4546 | * Return number of traffic classes enabled for the given PF |
| 4547 | **/ |
| 4548 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 4549 | { |
| 4550 | struct i40e_hw *hw = &pf->hw; |
| 4551 | u8 i, enabled_tc; |
| 4552 | u8 num_tc = 0; |
| 4553 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4554 | |
| 4555 | /* If DCB is not enabled then always in single TC */ |
| 4556 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4557 | return 1; |
| 4558 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4559 | /* SFP mode will be enabled for all TCs on port */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4560 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4561 | return i40e_dcb_get_num_tc(dcbcfg); |
| 4562 | |
| 4563 | /* MFP mode return count of enabled TCs for this PF */ |
| 4564 | if (pf->hw.func_caps.iscsi) |
| 4565 | enabled_tc = i40e_get_iscsi_tc_map(pf); |
| 4566 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4567 | return 1; /* Only TC0 */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4568 | |
| 4569 | /* At least have TC0 */ |
| 4570 | enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 4571 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4572 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4573 | num_tc++; |
| 4574 | } |
| 4575 | return num_tc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4576 | } |
| 4577 | |
| 4578 | /** |
| 4579 | * i40e_pf_get_default_tc - Get bitmap for first enabled TC |
| 4580 | * @pf: PF being queried |
| 4581 | * |
| 4582 | * Return a bitmap for first enabled traffic class for this PF. |
| 4583 | **/ |
| 4584 | static u8 i40e_pf_get_default_tc(struct i40e_pf *pf) |
| 4585 | { |
| 4586 | u8 enabled_tc = pf->hw.func_caps.enabled_tcmap; |
| 4587 | u8 i = 0; |
| 4588 | |
| 4589 | if (!enabled_tc) |
| 4590 | return 0x1; /* TC0 */ |
| 4591 | |
| 4592 | /* Find the first enabled TC */ |
| 4593 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4594 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4595 | break; |
| 4596 | } |
| 4597 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 4598 | return BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4599 | } |
| 4600 | |
| 4601 | /** |
| 4602 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 4603 | * @pf: PF being queried |
| 4604 | * |
| 4605 | * Return a bitmap for enabled traffic classes for this PF. |
| 4606 | **/ |
| 4607 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 4608 | { |
| 4609 | /* If DCB is not enabled for this PF then just return default TC */ |
| 4610 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4611 | return i40e_pf_get_default_tc(pf); |
| 4612 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4613 | /* SFP mode we want PF to be enabled for all TCs */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4614 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4615 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); |
| 4616 | |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4617 | /* MFP enabled and iSCSI PF type */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4618 | if (pf->hw.func_caps.iscsi) |
| 4619 | return i40e_get_iscsi_tc_map(pf); |
| 4620 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4621 | return i40e_pf_get_default_tc(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4622 | } |
| 4623 | |
| 4624 | /** |
| 4625 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 4626 | * @vsi: the VSI being queried |
| 4627 | * |
| 4628 | * Returns 0 on success, negative value on failure |
| 4629 | **/ |
| 4630 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 4631 | { |
| 4632 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 4633 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 4634 | struct i40e_pf *pf = vsi->back; |
| 4635 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4636 | i40e_status ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4637 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4638 | int i; |
| 4639 | |
| 4640 | /* Get the VSI level BW configuration */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4641 | ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
| 4642 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4643 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4644 | "couldn't get PF vsi bw config, err %s aq_err %s\n", |
| 4645 | i40e_stat_str(&pf->hw, ret), |
| 4646 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4647 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4648 | } |
| 4649 | |
| 4650 | /* Get the VSI level BW configuration per TC */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4651 | ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
| 4652 | NULL); |
| 4653 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4654 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4655 | "couldn't get PF vsi ets bw config, err %s aq_err %s\n", |
| 4656 | i40e_stat_str(&pf->hw, ret), |
| 4657 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4658 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4659 | } |
| 4660 | |
| 4661 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 4662 | dev_info(&pf->pdev->dev, |
| 4663 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 4664 | bw_config.tc_valid_bits, |
| 4665 | bw_ets_config.tc_valid_bits); |
| 4666 | /* Still continuing */ |
| 4667 | } |
| 4668 | |
| 4669 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 4670 | vsi->bw_max_quanta = bw_config.max_bw; |
| 4671 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 4672 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 4673 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4674 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 4675 | vsi->bw_ets_limit_credits[i] = |
| 4676 | le16_to_cpu(bw_ets_config.credits[i]); |
| 4677 | /* 3 bits out of 4 for each TC */ |
| 4678 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 4679 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4680 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4681 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4682 | } |
| 4683 | |
| 4684 | /** |
| 4685 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 4686 | * @vsi: the VSI being configured |
| 4687 | * @enabled_tc: TC bitmap |
| 4688 | * @bw_credits: BW shared credits per TC |
| 4689 | * |
| 4690 | * Returns 0 on success, negative value on failure |
| 4691 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4692 | 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] | 4693 | u8 *bw_share) |
| 4694 | { |
| 4695 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4696 | i40e_status ret; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4697 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4698 | |
| 4699 | bw_data.tc_valid_bits = enabled_tc; |
| 4700 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4701 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 4702 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4703 | ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 4704 | NULL); |
| 4705 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4706 | dev_info(&vsi->back->pdev->dev, |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4707 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
| 4708 | vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4709 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4710 | } |
| 4711 | |
| 4712 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4713 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 4714 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4715 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4716 | } |
| 4717 | |
| 4718 | /** |
| 4719 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 4720 | * @vsi: the VSI being configured |
| 4721 | * @enabled_tc: TC map to be enabled |
| 4722 | * |
| 4723 | **/ |
| 4724 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4725 | { |
| 4726 | struct net_device *netdev = vsi->netdev; |
| 4727 | struct i40e_pf *pf = vsi->back; |
| 4728 | struct i40e_hw *hw = &pf->hw; |
| 4729 | u8 netdev_tc = 0; |
| 4730 | int i; |
| 4731 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4732 | |
| 4733 | if (!netdev) |
| 4734 | return; |
| 4735 | |
| 4736 | if (!enabled_tc) { |
| 4737 | netdev_reset_tc(netdev); |
| 4738 | return; |
| 4739 | } |
| 4740 | |
| 4741 | /* Set up actual enabled TCs on the VSI */ |
| 4742 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 4743 | return; |
| 4744 | |
| 4745 | /* set per TC queues for the VSI */ |
| 4746 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4747 | /* Only set TC queues for enabled tcs |
| 4748 | * |
| 4749 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 4750 | * enabled_tc bitmap would be 0x00001001; the driver |
| 4751 | * will set the numtc for netdev as 2 that will be |
| 4752 | * referenced by the netdev layer as TC 0 and 1. |
| 4753 | */ |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4754 | if (vsi->tc_config.enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4755 | netdev_set_tc_queue(netdev, |
| 4756 | vsi->tc_config.tc_info[i].netdev_tc, |
| 4757 | vsi->tc_config.tc_info[i].qcount, |
| 4758 | vsi->tc_config.tc_info[i].qoffset); |
| 4759 | } |
| 4760 | |
| 4761 | /* Assign UP2TC map for the VSI */ |
| 4762 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4763 | /* Get the actual TC# for the UP */ |
| 4764 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4765 | /* Get the mapped netdev TC# for the UP */ |
| 4766 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 4767 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 4768 | } |
| 4769 | } |
| 4770 | |
| 4771 | /** |
| 4772 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 4773 | * @vsi: the VSI being configured |
| 4774 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 4775 | **/ |
| 4776 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 4777 | struct i40e_vsi_context *ctxt) |
| 4778 | { |
| 4779 | /* copy just the sections touched not the entire info |
| 4780 | * since not all sections are valid as returned by |
| 4781 | * update vsi params |
| 4782 | */ |
| 4783 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 4784 | memcpy(&vsi->info.queue_mapping, |
| 4785 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 4786 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 4787 | sizeof(vsi->info.tc_mapping)); |
| 4788 | } |
| 4789 | |
| 4790 | /** |
| 4791 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 4792 | * @vsi: VSI to be configured |
| 4793 | * @enabled_tc: TC bitmap |
| 4794 | * |
| 4795 | * This configures a particular VSI for TCs that are mapped to the |
| 4796 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 4797 | * VSIs to configure TC for a particular VSI. |
| 4798 | * |
| 4799 | * NOTE: |
| 4800 | * It is expected that the VSI queues have been quisced before calling |
| 4801 | * this function. |
| 4802 | **/ |
| 4803 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4804 | { |
| 4805 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 4806 | struct i40e_vsi_context ctxt; |
| 4807 | int ret = 0; |
| 4808 | int i; |
| 4809 | |
| 4810 | /* Check if enabled_tc is same as existing or new TCs */ |
| 4811 | if (vsi->tc_config.enabled_tc == enabled_tc) |
| 4812 | return ret; |
| 4813 | |
| 4814 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 4815 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4816 | if (enabled_tc & BIT(i)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4817 | bw_share[i] = 1; |
| 4818 | } |
| 4819 | |
| 4820 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 4821 | if (ret) { |
| 4822 | dev_info(&vsi->back->pdev->dev, |
| 4823 | "Failed configuring TC map %d for VSI %d\n", |
| 4824 | enabled_tc, vsi->seid); |
| 4825 | goto out; |
| 4826 | } |
| 4827 | |
| 4828 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 4829 | ctxt.seid = vsi->seid; |
| 4830 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 4831 | ctxt.vf_num = 0; |
| 4832 | ctxt.uplink_seid = vsi->uplink_seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 4833 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4834 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 4835 | |
| 4836 | /* Update the VSI after updating the VSI queue-mapping information */ |
| 4837 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 4838 | if (ret) { |
| 4839 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4840 | "Update vsi tc config failed, err %s aq_err %s\n", |
| 4841 | i40e_stat_str(&vsi->back->hw, ret), |
| 4842 | i40e_aq_str(&vsi->back->hw, |
| 4843 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4844 | goto out; |
| 4845 | } |
| 4846 | /* update the local VSI info with updated queue map */ |
| 4847 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 4848 | vsi->info.valid_sections = 0; |
| 4849 | |
| 4850 | /* Update current VSI BW information */ |
| 4851 | ret = i40e_vsi_get_bw_info(vsi); |
| 4852 | if (ret) { |
| 4853 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4854 | "Failed updating vsi bw info, err %s aq_err %s\n", |
| 4855 | i40e_stat_str(&vsi->back->hw, ret), |
| 4856 | i40e_aq_str(&vsi->back->hw, |
| 4857 | vsi->back->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4858 | goto out; |
| 4859 | } |
| 4860 | |
| 4861 | /* Update the netdev TC setup */ |
| 4862 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 4863 | out: |
| 4864 | return ret; |
| 4865 | } |
| 4866 | |
| 4867 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4868 | * i40e_veb_config_tc - Configure TCs for given VEB |
| 4869 | * @veb: given VEB |
| 4870 | * @enabled_tc: TC bitmap |
| 4871 | * |
| 4872 | * Configures given TC bitmap for VEB (switching) element |
| 4873 | **/ |
| 4874 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) |
| 4875 | { |
| 4876 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; |
| 4877 | struct i40e_pf *pf = veb->pf; |
| 4878 | int ret = 0; |
| 4879 | int i; |
| 4880 | |
| 4881 | /* No TCs or already enabled TCs just return */ |
| 4882 | if (!enabled_tc || veb->enabled_tc == enabled_tc) |
| 4883 | return ret; |
| 4884 | |
| 4885 | bw_data.tc_valid_bits = enabled_tc; |
| 4886 | /* bw_data.absolute_credits is not set (relative) */ |
| 4887 | |
| 4888 | /* Enable ETS TCs with equal BW Share for now */ |
| 4889 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 4890 | if (enabled_tc & BIT(i)) |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4891 | bw_data.tc_bw_share_credits[i] = 1; |
| 4892 | } |
| 4893 | |
| 4894 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, |
| 4895 | &bw_data, NULL); |
| 4896 | if (ret) { |
| 4897 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4898 | "VEB bw config failed, err %s aq_err %s\n", |
| 4899 | i40e_stat_str(&pf->hw, ret), |
| 4900 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4901 | goto out; |
| 4902 | } |
| 4903 | |
| 4904 | /* Update the BW information */ |
| 4905 | ret = i40e_veb_get_bw_info(veb); |
| 4906 | if (ret) { |
| 4907 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4908 | "Failed getting veb bw config, err %s aq_err %s\n", |
| 4909 | i40e_stat_str(&pf->hw, ret), |
| 4910 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4911 | } |
| 4912 | |
| 4913 | out: |
| 4914 | return ret; |
| 4915 | } |
| 4916 | |
| 4917 | #ifdef CONFIG_I40E_DCB |
| 4918 | /** |
| 4919 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs |
| 4920 | * @pf: PF struct |
| 4921 | * |
| 4922 | * Reconfigure VEB/VSIs on a given PF; it is assumed that |
| 4923 | * the caller would've quiesce all the VSIs before calling |
| 4924 | * this function |
| 4925 | **/ |
| 4926 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) |
| 4927 | { |
| 4928 | u8 tc_map = 0; |
| 4929 | int ret; |
| 4930 | u8 v; |
| 4931 | |
| 4932 | /* Enable the TCs available on PF to all VEBs */ |
| 4933 | tc_map = i40e_pf_get_tc_map(pf); |
| 4934 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 4935 | if (!pf->veb[v]) |
| 4936 | continue; |
| 4937 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); |
| 4938 | if (ret) { |
| 4939 | dev_info(&pf->pdev->dev, |
| 4940 | "Failed configuring TC for VEB seid=%d\n", |
| 4941 | pf->veb[v]->seid); |
| 4942 | /* Will try to configure as many components */ |
| 4943 | } |
| 4944 | } |
| 4945 | |
| 4946 | /* Update each VSI */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4947 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4948 | if (!pf->vsi[v]) |
| 4949 | continue; |
| 4950 | |
| 4951 | /* - Enable all TCs for the LAN VSI |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4952 | #ifdef I40E_FCOE |
| 4953 | * - For FCoE VSI only enable the TC configured |
| 4954 | * as per the APP TLV |
| 4955 | #endif |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4956 | * - For all others keep them at TC0 for now |
| 4957 | */ |
| 4958 | if (v == pf->lan_vsi) |
| 4959 | tc_map = i40e_pf_get_tc_map(pf); |
| 4960 | else |
| 4961 | tc_map = i40e_pf_get_default_tc(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4962 | #ifdef I40E_FCOE |
| 4963 | if (pf->vsi[v]->type == I40E_VSI_FCOE) |
| 4964 | tc_map = i40e_get_fcoe_tc_map(pf); |
| 4965 | #endif /* #ifdef I40E_FCOE */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4966 | |
| 4967 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); |
| 4968 | if (ret) { |
| 4969 | dev_info(&pf->pdev->dev, |
| 4970 | "Failed configuring TC for VSI seid=%d\n", |
| 4971 | pf->vsi[v]->seid); |
| 4972 | /* Will try to configure as many components */ |
| 4973 | } else { |
Neerav Parikh | 0672a09 | 2014-04-01 07:11:47 +0000 | [diff] [blame] | 4974 | /* Re-configure VSI vectors based on updated TC map */ |
| 4975 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4976 | if (pf->vsi[v]->netdev) |
| 4977 | i40e_dcbnl_set_all(pf->vsi[v]); |
| 4978 | } |
| 4979 | } |
| 4980 | } |
| 4981 | |
| 4982 | /** |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 4983 | * i40e_resume_port_tx - Resume port Tx |
| 4984 | * @pf: PF struct |
| 4985 | * |
| 4986 | * Resume a port's Tx and issue a PF reset in case of failure to |
| 4987 | * resume. |
| 4988 | **/ |
| 4989 | static int i40e_resume_port_tx(struct i40e_pf *pf) |
| 4990 | { |
| 4991 | struct i40e_hw *hw = &pf->hw; |
| 4992 | int ret; |
| 4993 | |
| 4994 | ret = i40e_aq_resume_port_tx(hw, NULL); |
| 4995 | if (ret) { |
| 4996 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 4997 | "Resume Port Tx failed, err %s aq_err %s\n", |
| 4998 | i40e_stat_str(&pf->hw, ret), |
| 4999 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5000 | /* Schedule PF reset to recover */ |
| 5001 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5002 | i40e_service_event_schedule(pf); |
| 5003 | } |
| 5004 | |
| 5005 | return ret; |
| 5006 | } |
| 5007 | |
| 5008 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5009 | * i40e_init_pf_dcb - Initialize DCB configuration |
| 5010 | * @pf: PF being configured |
| 5011 | * |
| 5012 | * Query the current DCB configuration and cache it |
| 5013 | * in the hardware structure |
| 5014 | **/ |
| 5015 | static int i40e_init_pf_dcb(struct i40e_pf *pf) |
| 5016 | { |
| 5017 | struct i40e_hw *hw = &pf->hw; |
| 5018 | int err = 0; |
| 5019 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 5020 | /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */ |
| 5021 | if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) || |
| 5022 | (pf->hw.aq.fw_maj_ver < 4)) |
| 5023 | goto out; |
| 5024 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5025 | /* Get the initial DCB configuration */ |
| 5026 | err = i40e_init_dcb(hw); |
| 5027 | if (!err) { |
| 5028 | /* Device/Function is not DCBX capable */ |
| 5029 | if ((!hw->func_caps.dcb) || |
| 5030 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { |
| 5031 | dev_info(&pf->pdev->dev, |
| 5032 | "DCBX offload is not supported or is disabled for this PF.\n"); |
| 5033 | |
| 5034 | if (pf->flags & I40E_FLAG_MFP_ENABLED) |
| 5035 | goto out; |
| 5036 | |
| 5037 | } else { |
| 5038 | /* When status is not DISABLED then DCBX in FW */ |
| 5039 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | |
| 5040 | DCB_CAP_DCBX_VER_IEEE; |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5041 | |
| 5042 | pf->flags |= I40E_FLAG_DCB_CAPABLE; |
| 5043 | /* Enable DCB tagging only when more than one TC */ |
| 5044 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
| 5045 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5046 | dev_dbg(&pf->pdev->dev, |
| 5047 | "DCBX offload is supported for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5048 | } |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 5049 | } else { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 5050 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5051 | "Query for DCB configuration failed, err %s aq_err %s\n", |
| 5052 | i40e_stat_str(&pf->hw, err), |
| 5053 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5054 | } |
| 5055 | |
| 5056 | out: |
| 5057 | return err; |
| 5058 | } |
| 5059 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5060 | #define SPEED_SIZE 14 |
| 5061 | #define FC_SIZE 8 |
| 5062 | /** |
| 5063 | * i40e_print_link_message - print link up or down |
| 5064 | * @vsi: the VSI for which link needs a message |
| 5065 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5066 | void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5067 | { |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5068 | char *speed = "Unknown"; |
| 5069 | char *fc = "Unknown"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5070 | |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 5071 | if (vsi->current_isup == isup) |
| 5072 | return; |
| 5073 | vsi->current_isup = isup; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5074 | if (!isup) { |
| 5075 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| 5076 | return; |
| 5077 | } |
| 5078 | |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 5079 | /* Warn user if link speed on NPAR enabled partition is not at |
| 5080 | * least 10GB |
| 5081 | */ |
| 5082 | if (vsi->back->hw.func_caps.npar_enable && |
| 5083 | (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB || |
| 5084 | vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB)) |
| 5085 | netdev_warn(vsi->netdev, |
| 5086 | "The partition detected link speed that is less than 10Gbps\n"); |
| 5087 | |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5088 | switch (vsi->back->hw.phy.link_info.link_speed) { |
| 5089 | case I40E_LINK_SPEED_40GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5090 | speed = "40 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5091 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5092 | case I40E_LINK_SPEED_20GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5093 | speed = "20 G"; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 5094 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5095 | case I40E_LINK_SPEED_10GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5096 | speed = "10 G"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5097 | break; |
| 5098 | case I40E_LINK_SPEED_1GB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5099 | speed = "1000 M"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5100 | break; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5101 | case I40E_LINK_SPEED_100MB: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5102 | speed = "100 M"; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 5103 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5104 | default: |
| 5105 | break; |
| 5106 | } |
| 5107 | |
| 5108 | switch (vsi->back->hw.fc.current_mode) { |
| 5109 | case I40E_FC_FULL: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5110 | fc = "RX/TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5111 | break; |
| 5112 | case I40E_FC_TX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5113 | fc = "TX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5114 | break; |
| 5115 | case I40E_FC_RX_PAUSE: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5116 | fc = "RX"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5117 | break; |
| 5118 | default: |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5119 | fc = "None"; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5120 | break; |
| 5121 | } |
| 5122 | |
Shannon Nelson | a916549 | 2015-09-03 17:19:00 -0400 | [diff] [blame] | 5123 | 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] | 5124 | speed, fc); |
| 5125 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5126 | |
| 5127 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5128 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 5129 | * @vsi: the VSI being configured |
| 5130 | **/ |
| 5131 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 5132 | { |
| 5133 | struct i40e_pf *pf = vsi->back; |
| 5134 | int err; |
| 5135 | |
| 5136 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5137 | i40e_vsi_configure_msix(vsi); |
| 5138 | else |
| 5139 | i40e_configure_msi_and_legacy(vsi); |
| 5140 | |
| 5141 | /* start rings */ |
| 5142 | err = i40e_vsi_control_rings(vsi, true); |
| 5143 | if (err) |
| 5144 | return err; |
| 5145 | |
| 5146 | clear_bit(__I40E_DOWN, &vsi->state); |
| 5147 | i40e_napi_enable_all(vsi); |
| 5148 | i40e_vsi_enable_irq(vsi); |
| 5149 | |
| 5150 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 5151 | (vsi->netdev)) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5152 | i40e_print_link_message(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5153 | netif_tx_start_all_queues(vsi->netdev); |
| 5154 | netif_carrier_on(vsi->netdev); |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 5155 | } else if (vsi->netdev) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 5156 | i40e_print_link_message(vsi, false); |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 5157 | /* need to check for qualified module here*/ |
| 5158 | if ((pf->hw.phy.link_info.link_info & |
| 5159 | I40E_AQ_MEDIA_AVAILABLE) && |
| 5160 | (!(pf->hw.phy.link_info.an_info & |
| 5161 | I40E_AQ_QUALIFIED_MODULE))) |
| 5162 | netdev_err(vsi->netdev, |
| 5163 | "the driver failed to link because an unqualified module was detected."); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5164 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5165 | |
| 5166 | /* replay FDIR SB filters */ |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5167 | if (vsi->type == I40E_VSI_FDIR) { |
| 5168 | /* reset fd counters */ |
| 5169 | pf->fd_add_err = pf->fd_atr_cnt = 0; |
| 5170 | if (pf->fd_tcp_rule > 0) { |
| 5171 | pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5172 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5173 | 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] | 5174 | pf->fd_tcp_rule = 0; |
| 5175 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 5176 | i40e_fdir_filter_restore(vsi); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5177 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5178 | i40e_service_event_schedule(pf); |
| 5179 | |
| 5180 | return 0; |
| 5181 | } |
| 5182 | |
| 5183 | /** |
| 5184 | * i40e_vsi_reinit_locked - Reset the VSI |
| 5185 | * @vsi: the VSI being configured |
| 5186 | * |
| 5187 | * Rebuild the ring structs after some configuration |
| 5188 | * has changed, e.g. MTU size. |
| 5189 | **/ |
| 5190 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 5191 | { |
| 5192 | struct i40e_pf *pf = vsi->back; |
| 5193 | |
| 5194 | WARN_ON(in_interrupt()); |
| 5195 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 5196 | usleep_range(1000, 2000); |
| 5197 | i40e_down(vsi); |
| 5198 | |
| 5199 | /* Give a VF some time to respond to the reset. The |
| 5200 | * two second wait is based upon the watchdog cycle in |
| 5201 | * the VF driver. |
| 5202 | */ |
| 5203 | if (vsi->type == I40E_VSI_SRIOV) |
| 5204 | msleep(2000); |
| 5205 | i40e_up(vsi); |
| 5206 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 5207 | } |
| 5208 | |
| 5209 | /** |
| 5210 | * i40e_up - Bring the connection back up after being down |
| 5211 | * @vsi: the VSI being configured |
| 5212 | **/ |
| 5213 | int i40e_up(struct i40e_vsi *vsi) |
| 5214 | { |
| 5215 | int err; |
| 5216 | |
| 5217 | err = i40e_vsi_configure(vsi); |
| 5218 | if (!err) |
| 5219 | err = i40e_up_complete(vsi); |
| 5220 | |
| 5221 | return err; |
| 5222 | } |
| 5223 | |
| 5224 | /** |
| 5225 | * i40e_down - Shutdown the connection processing |
| 5226 | * @vsi: the VSI being stopped |
| 5227 | **/ |
| 5228 | void i40e_down(struct i40e_vsi *vsi) |
| 5229 | { |
| 5230 | int i; |
| 5231 | |
| 5232 | /* It is assumed that the caller of this function |
| 5233 | * sets the vsi->state __I40E_DOWN bit. |
| 5234 | */ |
| 5235 | if (vsi->netdev) { |
| 5236 | netif_carrier_off(vsi->netdev); |
| 5237 | netif_tx_disable(vsi->netdev); |
| 5238 | } |
| 5239 | i40e_vsi_disable_irq(vsi); |
| 5240 | i40e_vsi_control_rings(vsi, false); |
| 5241 | i40e_napi_disable_all(vsi); |
| 5242 | |
| 5243 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5244 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
| 5245 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5246 | } |
| 5247 | } |
| 5248 | |
| 5249 | /** |
| 5250 | * i40e_setup_tc - configure multiple traffic classes |
| 5251 | * @netdev: net device to configure |
| 5252 | * @tc: number of traffic classes to enable |
| 5253 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5254 | #ifdef I40E_FCOE |
| 5255 | int i40e_setup_tc(struct net_device *netdev, u8 tc) |
| 5256 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5257 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5258 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5259 | { |
| 5260 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5261 | struct i40e_vsi *vsi = np->vsi; |
| 5262 | struct i40e_pf *pf = vsi->back; |
| 5263 | u8 enabled_tc = 0; |
| 5264 | int ret = -EINVAL; |
| 5265 | int i; |
| 5266 | |
| 5267 | /* Check if DCB enabled to continue */ |
| 5268 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 5269 | netdev_info(netdev, "DCB is not enabled for adapter\n"); |
| 5270 | goto exit; |
| 5271 | } |
| 5272 | |
| 5273 | /* Check if MFP enabled */ |
| 5274 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 5275 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); |
| 5276 | goto exit; |
| 5277 | } |
| 5278 | |
| 5279 | /* Check whether tc count is within enabled limit */ |
| 5280 | if (tc > i40e_pf_get_num_tc(pf)) { |
| 5281 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); |
| 5282 | goto exit; |
| 5283 | } |
| 5284 | |
| 5285 | /* Generate TC map for number of tc requested */ |
| 5286 | for (i = 0; i < tc; i++) |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 5287 | enabled_tc |= BIT(i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5288 | |
| 5289 | /* Requesting same TC configuration as already enabled */ |
| 5290 | if (enabled_tc == vsi->tc_config.enabled_tc) |
| 5291 | return 0; |
| 5292 | |
| 5293 | /* Quiesce VSI queues */ |
| 5294 | i40e_quiesce_vsi(vsi); |
| 5295 | |
| 5296 | /* Configure VSI for enabled TCs */ |
| 5297 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 5298 | if (ret) { |
| 5299 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 5300 | vsi->seid); |
| 5301 | goto exit; |
| 5302 | } |
| 5303 | |
| 5304 | /* Unquiesce VSI */ |
| 5305 | i40e_unquiesce_vsi(vsi); |
| 5306 | |
| 5307 | exit: |
| 5308 | return ret; |
| 5309 | } |
| 5310 | |
| 5311 | /** |
| 5312 | * i40e_open - Called when a network interface is made active |
| 5313 | * @netdev: network interface device structure |
| 5314 | * |
| 5315 | * The open entry point is called when a network interface is made |
| 5316 | * active by the system (IFF_UP). At this point all resources needed |
| 5317 | * for transmit and receive operations are allocated, the interrupt |
| 5318 | * handler is registered with the OS, the netdev watchdog subtask is |
| 5319 | * enabled, and the stack is notified that the interface is ready. |
| 5320 | * |
| 5321 | * Returns 0 on success, negative value on failure |
| 5322 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5323 | int i40e_open(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5324 | { |
| 5325 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5326 | struct i40e_vsi *vsi = np->vsi; |
| 5327 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5328 | int err; |
| 5329 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 5330 | /* disallow open during test or if eeprom is broken */ |
| 5331 | if (test_bit(__I40E_TESTING, &pf->state) || |
| 5332 | test_bit(__I40E_BAD_EEPROM, &pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5333 | return -EBUSY; |
| 5334 | |
| 5335 | netif_carrier_off(netdev); |
| 5336 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5337 | err = i40e_vsi_open(vsi); |
| 5338 | if (err) |
| 5339 | return err; |
| 5340 | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 5341 | /* configure global TSO hardware offload settings */ |
| 5342 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | |
| 5343 | TCP_FLAG_FIN) >> 16); |
| 5344 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | |
| 5345 | TCP_FLAG_FIN | |
| 5346 | TCP_FLAG_CWR) >> 16); |
| 5347 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); |
| 5348 | |
Singhai, Anjali | 6633d38 | 2015-12-03 23:49:31 -0800 | [diff] [blame] | 5349 | #ifdef CONFIG_I40E_VXLAN |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5350 | vxlan_get_rx_port(netdev); |
| 5351 | #endif |
Singhai, Anjali | cd86660 | 2015-12-14 12:21:21 -0800 | [diff] [blame] | 5352 | #ifdef CONFIG_I40E_GENEVE |
| 5353 | geneve_get_rx_port(netdev); |
| 5354 | #endif |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5355 | |
| 5356 | return 0; |
| 5357 | } |
| 5358 | |
| 5359 | /** |
| 5360 | * i40e_vsi_open - |
| 5361 | * @vsi: the VSI to open |
| 5362 | * |
| 5363 | * Finish initialization of the VSI. |
| 5364 | * |
| 5365 | * Returns 0 on success, negative value on failure |
| 5366 | **/ |
| 5367 | int i40e_vsi_open(struct i40e_vsi *vsi) |
| 5368 | { |
| 5369 | struct i40e_pf *pf = vsi->back; |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 5370 | char int_name[I40E_INT_NAME_STR_LEN]; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5371 | int err; |
| 5372 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5373 | /* allocate descriptors */ |
| 5374 | err = i40e_vsi_setup_tx_resources(vsi); |
| 5375 | if (err) |
| 5376 | goto err_setup_tx; |
| 5377 | err = i40e_vsi_setup_rx_resources(vsi); |
| 5378 | if (err) |
| 5379 | goto err_setup_rx; |
| 5380 | |
| 5381 | err = i40e_vsi_configure(vsi); |
| 5382 | if (err) |
| 5383 | goto err_setup_rx; |
| 5384 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5385 | if (vsi->netdev) { |
| 5386 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 5387 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); |
| 5388 | err = i40e_vsi_request_irq(vsi, int_name); |
| 5389 | if (err) |
| 5390 | goto err_setup_rx; |
| 5391 | |
| 5392 | /* Notify the stack of the actual queue counts. */ |
| 5393 | err = netif_set_real_num_tx_queues(vsi->netdev, |
| 5394 | vsi->num_queue_pairs); |
| 5395 | if (err) |
| 5396 | goto err_set_queues; |
| 5397 | |
| 5398 | err = netif_set_real_num_rx_queues(vsi->netdev, |
| 5399 | vsi->num_queue_pairs); |
| 5400 | if (err) |
| 5401 | goto err_set_queues; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5402 | |
| 5403 | } else if (vsi->type == I40E_VSI_FDIR) { |
Carolyn Wyborny | e240f67 | 2014-12-11 07:06:37 +0000 | [diff] [blame] | 5404 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir", |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5405 | dev_driver_string(&pf->pdev->dev), |
| 5406 | dev_name(&pf->pdev->dev)); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5407 | err = i40e_vsi_request_irq(vsi, int_name); |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 5408 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 5409 | } else { |
Jean Sacren | ce9ccb1 | 2014-05-01 14:31:18 +0000 | [diff] [blame] | 5410 | err = -EINVAL; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 5411 | goto err_setup_rx; |
| 5412 | } |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5413 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5414 | err = i40e_up_complete(vsi); |
| 5415 | if (err) |
| 5416 | goto err_up_complete; |
| 5417 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5418 | return 0; |
| 5419 | |
| 5420 | err_up_complete: |
| 5421 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5422 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5423 | i40e_vsi_free_irq(vsi); |
| 5424 | err_setup_rx: |
| 5425 | i40e_vsi_free_rx_resources(vsi); |
| 5426 | err_setup_tx: |
| 5427 | i40e_vsi_free_tx_resources(vsi); |
| 5428 | if (vsi == pf->vsi[pf->lan_vsi]) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5429 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5430 | |
| 5431 | return err; |
| 5432 | } |
| 5433 | |
| 5434 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5435 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 5436 | * @pf: Pointer to PF |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5437 | * |
| 5438 | * This function destroys the hlist where all the Flow Director |
| 5439 | * filters were saved. |
| 5440 | **/ |
| 5441 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) |
| 5442 | { |
| 5443 | struct i40e_fdir_filter *filter; |
| 5444 | struct hlist_node *node2; |
| 5445 | |
| 5446 | hlist_for_each_entry_safe(filter, node2, |
| 5447 | &pf->fdir_filter_list, fdir_node) { |
| 5448 | hlist_del(&filter->fdir_node); |
| 5449 | kfree(filter); |
| 5450 | } |
| 5451 | pf->fdir_pf_active_filters = 0; |
| 5452 | } |
| 5453 | |
| 5454 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5455 | * i40e_close - Disables a network interface |
| 5456 | * @netdev: network interface device structure |
| 5457 | * |
| 5458 | * The close entry point is called when an interface is de-activated |
| 5459 | * by the OS. The hardware is still under the driver's control, but |
| 5460 | * this netdev interface is disabled. |
| 5461 | * |
| 5462 | * Returns 0, this is not allowed to fail |
| 5463 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5464 | #ifdef I40E_FCOE |
| 5465 | int i40e_close(struct net_device *netdev) |
| 5466 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5467 | static int i40e_close(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5468 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5469 | { |
| 5470 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5471 | struct i40e_vsi *vsi = np->vsi; |
| 5472 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 5473 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5474 | |
| 5475 | return 0; |
| 5476 | } |
| 5477 | |
| 5478 | /** |
| 5479 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 5480 | * @pf: board private structure |
| 5481 | * @reset_flags: which reset is requested |
| 5482 | * |
| 5483 | * The essential difference in resets is that the PF Reset |
| 5484 | * doesn't clear the packet buffers, doesn't reset the PE |
| 5485 | * firmware, and doesn't bother the other PFs on the chip. |
| 5486 | **/ |
| 5487 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags) |
| 5488 | { |
| 5489 | u32 val; |
| 5490 | |
| 5491 | WARN_ON(in_interrupt()); |
| 5492 | |
Mitch Williams | 263fc48 | 2014-04-23 04:50:11 +0000 | [diff] [blame] | 5493 | if (i40e_check_asq_alive(&pf->hw)) |
| 5494 | i40e_vc_notify_reset(pf); |
| 5495 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5496 | /* do the biggest reset indicated */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5497 | if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5498 | |
| 5499 | /* Request a Global Reset |
| 5500 | * |
| 5501 | * This will start the chip's countdown to the actual full |
| 5502 | * chip reset event, and a warning interrupt to be sent |
| 5503 | * to all PFs, including the requestor. Our handler |
| 5504 | * for the warning interrupt will deal with the shutdown |
| 5505 | * and recovery of the switch setup. |
| 5506 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5507 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5508 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5509 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; |
| 5510 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5511 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5512 | } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5513 | |
| 5514 | /* Request a Core Reset |
| 5515 | * |
| 5516 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 5517 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5518 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5519 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5520 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 5521 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5522 | i40e_flush(&pf->hw); |
| 5523 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5524 | } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5525 | |
| 5526 | /* Request a PF Reset |
| 5527 | * |
| 5528 | * Resets only the PF-specific registers |
| 5529 | * |
| 5530 | * This goes directly to the tear-down and rebuild of |
| 5531 | * the switch, since we need to do all the recovery as |
| 5532 | * for the Core Reset. |
| 5533 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5534 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5535 | i40e_handle_reset_warning(pf); |
| 5536 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5537 | } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5538 | int v; |
| 5539 | |
| 5540 | /* Find the VSI(s) that requested a re-init */ |
| 5541 | dev_info(&pf->pdev->dev, |
| 5542 | "VSI reinit requested\n"); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5543 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5544 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5545 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5546 | if (vsi != NULL && |
| 5547 | test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { |
| 5548 | i40e_vsi_reinit_locked(pf->vsi[v]); |
| 5549 | clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 5550 | } |
| 5551 | } |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 5552 | } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) { |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5553 | int v; |
| 5554 | |
| 5555 | /* Find the VSI(s) that needs to be brought down */ |
| 5556 | dev_info(&pf->pdev->dev, "VSI down requested\n"); |
| 5557 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
| 5558 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 5559 | |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5560 | if (vsi != NULL && |
| 5561 | test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) { |
| 5562 | set_bit(__I40E_DOWN, &vsi->state); |
| 5563 | i40e_down(vsi); |
| 5564 | clear_bit(__I40E_DOWN_REQUESTED, &vsi->state); |
| 5565 | } |
| 5566 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5567 | } else { |
| 5568 | dev_info(&pf->pdev->dev, |
| 5569 | "bad reset request 0x%08x\n", reset_flags); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5570 | } |
| 5571 | } |
| 5572 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5573 | #ifdef CONFIG_I40E_DCB |
| 5574 | /** |
| 5575 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig |
| 5576 | * @pf: board private structure |
| 5577 | * @old_cfg: current DCB config |
| 5578 | * @new_cfg: new DCB config |
| 5579 | **/ |
| 5580 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, |
| 5581 | struct i40e_dcbx_config *old_cfg, |
| 5582 | struct i40e_dcbx_config *new_cfg) |
| 5583 | { |
| 5584 | bool need_reconfig = false; |
| 5585 | |
| 5586 | /* Check if ETS configuration has changed */ |
| 5587 | if (memcmp(&new_cfg->etscfg, |
| 5588 | &old_cfg->etscfg, |
| 5589 | sizeof(new_cfg->etscfg))) { |
| 5590 | /* If Priority Table has changed reconfig is needed */ |
| 5591 | if (memcmp(&new_cfg->etscfg.prioritytable, |
| 5592 | &old_cfg->etscfg.prioritytable, |
| 5593 | sizeof(new_cfg->etscfg.prioritytable))) { |
| 5594 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5595 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5596 | } |
| 5597 | |
| 5598 | if (memcmp(&new_cfg->etscfg.tcbwtable, |
| 5599 | &old_cfg->etscfg.tcbwtable, |
| 5600 | sizeof(new_cfg->etscfg.tcbwtable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5601 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5602 | |
| 5603 | if (memcmp(&new_cfg->etscfg.tsatable, |
| 5604 | &old_cfg->etscfg.tsatable, |
| 5605 | sizeof(new_cfg->etscfg.tsatable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5606 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5607 | } |
| 5608 | |
| 5609 | /* Check if PFC configuration has changed */ |
| 5610 | if (memcmp(&new_cfg->pfc, |
| 5611 | &old_cfg->pfc, |
| 5612 | sizeof(new_cfg->pfc))) { |
| 5613 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5614 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5615 | } |
| 5616 | |
| 5617 | /* Check if APP Table has changed */ |
| 5618 | if (memcmp(&new_cfg->app, |
| 5619 | &old_cfg->app, |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5620 | sizeof(new_cfg->app))) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5621 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5622 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5623 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5624 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5625 | dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5626 | return need_reconfig; |
| 5627 | } |
| 5628 | |
| 5629 | /** |
| 5630 | * i40e_handle_lldp_event - Handle LLDP Change MIB event |
| 5631 | * @pf: board private structure |
| 5632 | * @e: event info posted on ARQ |
| 5633 | **/ |
| 5634 | static int i40e_handle_lldp_event(struct i40e_pf *pf, |
| 5635 | struct i40e_arq_event_info *e) |
| 5636 | { |
| 5637 | struct i40e_aqc_lldp_get_mib *mib = |
| 5638 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; |
| 5639 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5640 | struct i40e_dcbx_config tmp_dcbx_cfg; |
| 5641 | bool need_reconfig = false; |
| 5642 | int ret = 0; |
| 5643 | u8 type; |
| 5644 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5645 | /* Not DCB capable or capability disabled */ |
| 5646 | if (!(pf->flags & I40E_FLAG_DCB_CAPABLE)) |
| 5647 | return ret; |
| 5648 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5649 | /* Ignore if event is not for Nearest Bridge */ |
| 5650 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) |
| 5651 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5652 | 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] | 5653 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
| 5654 | return ret; |
| 5655 | |
| 5656 | /* Check MIB Type and return if event for Remote MIB update */ |
| 5657 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5658 | dev_dbg(&pf->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 5659 | "LLDP event mib type %s\n", type ? "remote" : "local"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5660 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
| 5661 | /* Update the remote cached instance and return */ |
| 5662 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, |
| 5663 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, |
| 5664 | &hw->remote_dcbx_config); |
| 5665 | goto exit; |
| 5666 | } |
| 5667 | |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5668 | /* Store the old configuration */ |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5669 | tmp_dcbx_cfg = hw->local_dcbx_config; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5670 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5671 | /* Reset the old DCBx configuration data */ |
| 5672 | memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config)); |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5673 | /* Get updated DCBX data from firmware */ |
| 5674 | ret = i40e_get_dcb_config(&pf->hw); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5675 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 5676 | dev_info(&pf->pdev->dev, |
| 5677 | "Failed querying DCB configuration data from firmware, err %s aq_err %s\n", |
| 5678 | i40e_stat_str(&pf->hw, ret), |
| 5679 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5680 | goto exit; |
| 5681 | } |
| 5682 | |
| 5683 | /* No change detected in DCBX configs */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5684 | if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config, |
| 5685 | sizeof(tmp_dcbx_cfg))) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5686 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5687 | goto exit; |
| 5688 | } |
| 5689 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5690 | need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg, |
| 5691 | &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5692 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5693 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5694 | |
| 5695 | if (!need_reconfig) |
| 5696 | goto exit; |
| 5697 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5698 | /* Enable DCB tagging only when more than one TC */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5699 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5700 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
| 5701 | else |
| 5702 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 5703 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5704 | set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5705 | /* Reconfiguration needed quiesce all VSIs */ |
| 5706 | i40e_pf_quiesce_all_vsi(pf); |
| 5707 | |
| 5708 | /* Changes in configuration update VEB/VSI */ |
| 5709 | i40e_dcb_reconfigure(pf); |
| 5710 | |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5711 | ret = i40e_resume_port_tx(pf); |
| 5712 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5713 | clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5714 | /* In case of error no point in resuming VSIs */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5715 | if (ret) |
| 5716 | goto exit; |
| 5717 | |
| 5718 | /* Wait for the PF's Tx queues to be disabled */ |
| 5719 | ret = i40e_pf_wait_txq_disabled(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5720 | if (ret) { |
| 5721 | /* Schedule PF reset to recover */ |
| 5722 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5723 | i40e_service_event_schedule(pf); |
| 5724 | } else { |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5725 | i40e_pf_unquiesce_all_vsi(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5726 | } |
| 5727 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5728 | exit: |
| 5729 | return ret; |
| 5730 | } |
| 5731 | #endif /* CONFIG_I40E_DCB */ |
| 5732 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5733 | /** |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5734 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 5735 | * @pf: board private structure |
| 5736 | * @reset_flags: which reset is requested |
| 5737 | * |
| 5738 | **/ |
| 5739 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 5740 | { |
| 5741 | rtnl_lock(); |
| 5742 | i40e_do_reset(pf, reset_flags); |
| 5743 | rtnl_unlock(); |
| 5744 | } |
| 5745 | |
| 5746 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5747 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 5748 | * @pf: board private structure |
| 5749 | * @e: event info posted on ARQ |
| 5750 | * |
| 5751 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 5752 | * and VF queues |
| 5753 | **/ |
| 5754 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 5755 | struct i40e_arq_event_info *e) |
| 5756 | { |
| 5757 | struct i40e_aqc_lan_overflow *data = |
| 5758 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 5759 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 5760 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 5761 | struct i40e_hw *hw = &pf->hw; |
| 5762 | struct i40e_vf *vf; |
| 5763 | u16 vf_id; |
| 5764 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5765 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 5766 | queue, qtx_ctl); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5767 | |
| 5768 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 5769 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 5770 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 5771 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 5772 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 5773 | vf_id -= hw->func_caps.vf_base_id; |
| 5774 | vf = &pf->vf[vf_id]; |
| 5775 | i40e_vc_notify_vf_reset(vf); |
| 5776 | /* Allow VF to process pending reset notification */ |
| 5777 | msleep(20); |
| 5778 | i40e_reset_vf(vf, false); |
| 5779 | } |
| 5780 | } |
| 5781 | |
| 5782 | /** |
| 5783 | * i40e_service_event_complete - Finish up the service event |
| 5784 | * @pf: board private structure |
| 5785 | **/ |
| 5786 | static void i40e_service_event_complete(struct i40e_pf *pf) |
| 5787 | { |
Shannon Nelson | b875f99 | 2015-10-21 19:47:03 -0400 | [diff] [blame] | 5788 | WARN_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5789 | |
| 5790 | /* flush memory to make sure state is correct before next watchog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5791 | smp_mb__before_atomic(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5792 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 5793 | } |
| 5794 | |
| 5795 | /** |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5796 | * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters |
| 5797 | * @pf: board private structure |
| 5798 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5799 | u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5800 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5801 | u32 val, fcnt_prog; |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5802 | |
| 5803 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5804 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK); |
| 5805 | return fcnt_prog; |
| 5806 | } |
| 5807 | |
| 5808 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5809 | * 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] | 5810 | * @pf: board private structure |
| 5811 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5812 | u32 i40e_get_current_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5813 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5814 | u32 val, fcnt_prog; |
| 5815 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5816 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5817 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + |
| 5818 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> |
| 5819 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); |
| 5820 | return fcnt_prog; |
| 5821 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5822 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5823 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5824 | * i40e_get_global_fd_count - Get total FD filters programmed on device |
| 5825 | * @pf: board private structure |
| 5826 | **/ |
| 5827 | u32 i40e_get_global_fd_count(struct i40e_pf *pf) |
| 5828 | { |
| 5829 | u32 val, fcnt_prog; |
| 5830 | |
| 5831 | val = rd32(&pf->hw, I40E_GLQF_FDCNT_0); |
| 5832 | fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) + |
| 5833 | ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >> |
| 5834 | I40E_GLQF_FDCNT_0_BESTCNT_SHIFT); |
| 5835 | return fcnt_prog; |
| 5836 | } |
| 5837 | |
| 5838 | /** |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5839 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled |
| 5840 | * @pf: board private structure |
| 5841 | **/ |
| 5842 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) |
| 5843 | { |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5844 | struct i40e_fdir_filter *filter; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5845 | u32 fcnt_prog, fcnt_avail; |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5846 | struct hlist_node *node; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5847 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5848 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 5849 | return; |
| 5850 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5851 | /* Check if, FD SB or ATR was auto disabled and if there is enough room |
| 5852 | * to re-enable |
| 5853 | */ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5854 | fcnt_prog = i40e_get_global_fd_count(pf); |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5855 | fcnt_avail = pf->fdir_pf_filter_count; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5856 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) || |
| 5857 | (pf->fd_add_err == 0) || |
| 5858 | (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5859 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 5860 | (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) { |
| 5861 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5862 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5863 | 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] | 5864 | } |
| 5865 | } |
| 5866 | /* Wait for some more space to be available to turn on ATR */ |
| 5867 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) { |
| 5868 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 5869 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) { |
| 5870 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5871 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5872 | dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table now\n"); |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5873 | } |
| 5874 | } |
Carolyn Wyborny | 3487b6c | 2015-08-27 11:42:38 -0400 | [diff] [blame] | 5875 | |
| 5876 | /* if hw had a problem adding a filter, delete it */ |
| 5877 | if (pf->fd_inv > 0) { |
| 5878 | hlist_for_each_entry_safe(filter, node, |
| 5879 | &pf->fdir_filter_list, fdir_node) { |
| 5880 | if (filter->fd_id == pf->fd_inv) { |
| 5881 | hlist_del(&filter->fdir_node); |
| 5882 | kfree(filter); |
| 5883 | pf->fdir_pf_active_filters--; |
| 5884 | } |
| 5885 | } |
| 5886 | } |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5887 | } |
| 5888 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5889 | #define I40E_MIN_FD_FLUSH_INTERVAL 10 |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5890 | #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30 |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5891 | /** |
| 5892 | * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB |
| 5893 | * @pf: board private structure |
| 5894 | **/ |
| 5895 | static void i40e_fdir_flush_and_replay(struct i40e_pf *pf) |
| 5896 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5897 | unsigned long min_flush_time; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5898 | int flush_wait_retry = 50; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5899 | bool disable_atr = false; |
| 5900 | int fd_room; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5901 | int reg; |
| 5902 | |
Akeem G Abodunrin | 1790ed0 | 2014-10-17 03:14:41 +0000 | [diff] [blame] | 5903 | if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))) |
| 5904 | return; |
| 5905 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5906 | if (!time_after(jiffies, pf->fd_flush_timestamp + |
| 5907 | (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) |
| 5908 | return; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5909 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5910 | /* If the flush is happening too quick and we have mostly SB rules we |
| 5911 | * should not re-enable ATR for some time. |
| 5912 | */ |
| 5913 | min_flush_time = pf->fd_flush_timestamp + |
| 5914 | (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ); |
| 5915 | 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] | 5916 | |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5917 | if (!(time_after(jiffies, min_flush_time)) && |
| 5918 | (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) { |
| 5919 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5920 | dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n"); |
| 5921 | disable_atr = true; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5922 | } |
Jesse Brandeburg | a5fdaf3 | 2015-08-28 17:55:56 -0400 | [diff] [blame] | 5923 | |
| 5924 | pf->fd_flush_timestamp = jiffies; |
| 5925 | pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
| 5926 | /* flush all filters */ |
| 5927 | wr32(&pf->hw, I40E_PFQF_CTL_1, |
| 5928 | I40E_PFQF_CTL_1_CLEARFDTABLE_MASK); |
| 5929 | i40e_flush(&pf->hw); |
| 5930 | pf->fd_flush_cnt++; |
| 5931 | pf->fd_add_err = 0; |
| 5932 | do { |
| 5933 | /* Check FD flush status every 5-6msec */ |
| 5934 | usleep_range(5000, 6000); |
| 5935 | reg = rd32(&pf->hw, I40E_PFQF_CTL_1); |
| 5936 | if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK)) |
| 5937 | break; |
| 5938 | } while (flush_wait_retry--); |
| 5939 | if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) { |
| 5940 | dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n"); |
| 5941 | } else { |
| 5942 | /* replay sideband filters */ |
| 5943 | i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]); |
| 5944 | if (!disable_atr) |
| 5945 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 5946 | clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state); |
| 5947 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5948 | dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n"); |
| 5949 | } |
| 5950 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5951 | } |
| 5952 | |
| 5953 | /** |
| 5954 | * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed |
| 5955 | * @pf: board private structure |
| 5956 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5957 | u32 i40e_get_current_atr_cnt(struct i40e_pf *pf) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5958 | { |
| 5959 | return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters; |
| 5960 | } |
| 5961 | |
| 5962 | /* We can see up to 256 filter programming desc in transit if the filters are |
| 5963 | * being applied really fast; before we see the first |
| 5964 | * filter miss error on Rx queue 0. Accumulating enough error messages before |
| 5965 | * reacting will make sure we don't cause flush too often. |
| 5966 | */ |
| 5967 | #define I40E_MAX_FD_PROGRAM_ERROR 256 |
| 5968 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5969 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5970 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 5971 | * @pf: board private structure |
| 5972 | **/ |
| 5973 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 5974 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5975 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5976 | /* if interface is down do nothing */ |
| 5977 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 5978 | return; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5979 | |
Akeem G Abodunrin | 1790ed0 | 2014-10-17 03:14:41 +0000 | [diff] [blame] | 5980 | if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))) |
| 5981 | return; |
| 5982 | |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5983 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5984 | i40e_fdir_flush_and_replay(pf); |
| 5985 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5986 | i40e_fdir_check_and_reenable(pf); |
| 5987 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5988 | } |
| 5989 | |
| 5990 | /** |
| 5991 | * i40e_vsi_link_event - notify VSI of a link event |
| 5992 | * @vsi: vsi to be notified |
| 5993 | * @link_up: link up or down |
| 5994 | **/ |
| 5995 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 5996 | { |
Jesse Brandeburg | 32b5b81 | 2014-08-12 06:33:14 +0000 | [diff] [blame] | 5997 | if (!vsi || test_bit(__I40E_DOWN, &vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5998 | return; |
| 5999 | |
| 6000 | switch (vsi->type) { |
| 6001 | case I40E_VSI_MAIN: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6002 | #ifdef I40E_FCOE |
| 6003 | case I40E_VSI_FCOE: |
| 6004 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6005 | if (!vsi->netdev || !vsi->netdev_registered) |
| 6006 | break; |
| 6007 | |
| 6008 | if (link_up) { |
| 6009 | netif_carrier_on(vsi->netdev); |
| 6010 | netif_tx_wake_all_queues(vsi->netdev); |
| 6011 | } else { |
| 6012 | netif_carrier_off(vsi->netdev); |
| 6013 | netif_tx_stop_all_queues(vsi->netdev); |
| 6014 | } |
| 6015 | break; |
| 6016 | |
| 6017 | case I40E_VSI_SRIOV: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6018 | case I40E_VSI_VMDQ2: |
| 6019 | case I40E_VSI_CTRL: |
| 6020 | case I40E_VSI_MIRROR: |
| 6021 | default: |
| 6022 | /* there is no notification for other VSIs */ |
| 6023 | break; |
| 6024 | } |
| 6025 | } |
| 6026 | |
| 6027 | /** |
| 6028 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 6029 | * @veb: veb to be notified |
| 6030 | * @link_up: link up or down |
| 6031 | **/ |
| 6032 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 6033 | { |
| 6034 | struct i40e_pf *pf; |
| 6035 | int i; |
| 6036 | |
| 6037 | if (!veb || !veb->pf) |
| 6038 | return; |
| 6039 | pf = veb->pf; |
| 6040 | |
| 6041 | /* depth first... */ |
| 6042 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6043 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 6044 | i40e_veb_link_event(pf->veb[i], link_up); |
| 6045 | |
| 6046 | /* ... now the local VSIs */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6047 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6048 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 6049 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 6050 | } |
| 6051 | |
| 6052 | /** |
| 6053 | * i40e_link_event - Update netif_carrier status |
| 6054 | * @pf: board private structure |
| 6055 | **/ |
| 6056 | static void i40e_link_event(struct i40e_pf *pf) |
| 6057 | { |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6058 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6059 | u8 new_link_speed, old_link_speed; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 6060 | i40e_status status; |
| 6061 | bool new_link, old_link; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6062 | |
Catherine Sullivan | 1f9610e | 2015-10-21 19:47:09 -0400 | [diff] [blame] | 6063 | /* save off old link status information */ |
| 6064 | pf->hw.phy.link_info_old = pf->hw.phy.link_info; |
| 6065 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6066 | /* set this to force the get_link_status call to refresh state */ |
| 6067 | pf->hw.phy.get_link_info = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6068 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6069 | 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] | 6070 | |
| 6071 | status = i40e_get_link_status(&pf->hw, &new_link); |
| 6072 | if (status) { |
| 6073 | dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n", |
| 6074 | status); |
| 6075 | return; |
| 6076 | } |
| 6077 | |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6078 | old_link_speed = pf->hw.phy.link_info_old.link_speed; |
| 6079 | new_link_speed = pf->hw.phy.link_info.link_speed; |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6080 | |
| 6081 | if (new_link == old_link && |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 6082 | new_link_speed == old_link_speed && |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6083 | (test_bit(__I40E_DOWN, &vsi->state) || |
| 6084 | new_link == netif_carrier_ok(vsi->netdev))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6085 | return; |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6086 | |
| 6087 | if (!test_bit(__I40E_DOWN, &vsi->state)) |
| 6088 | i40e_print_link_message(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6089 | |
| 6090 | /* Notify the base of the switch tree connected to |
| 6091 | * the link. Floating VEBs are not notified. |
| 6092 | */ |
| 6093 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 6094 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 6095 | else |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 6096 | i40e_vsi_link_event(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6097 | |
| 6098 | if (pf->vf) |
| 6099 | i40e_vc_notify_link_state(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6100 | |
| 6101 | if (pf->flags & I40E_FLAG_PTP) |
| 6102 | i40e_ptp_set_increment(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6103 | } |
| 6104 | |
| 6105 | /** |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6106 | * i40e_watchdog_subtask - periodic checks not using event driven response |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6107 | * @pf: board private structure |
| 6108 | **/ |
| 6109 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 6110 | { |
| 6111 | int i; |
| 6112 | |
| 6113 | /* if interface is down do nothing */ |
| 6114 | if (test_bit(__I40E_DOWN, &pf->state) || |
| 6115 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6116 | return; |
| 6117 | |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6118 | /* make sure we don't do these things too often */ |
| 6119 | if (time_before(jiffies, (pf->service_timer_previous + |
| 6120 | pf->service_timer_period))) |
| 6121 | return; |
| 6122 | pf->service_timer_previous = jiffies; |
| 6123 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 6124 | if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) |
| 6125 | i40e_link_event(pf); |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 6126 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6127 | /* Update the stats for active netdevs so the network stack |
| 6128 | * can look at updated numbers whenever it cares to |
| 6129 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6130 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6131 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 6132 | i40e_update_stats(pf->vsi[i]); |
| 6133 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 6134 | if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) { |
| 6135 | /* Update the stats for the active switching components */ |
| 6136 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 6137 | if (pf->veb[i]) |
| 6138 | i40e_update_veb_stats(pf->veb[i]); |
| 6139 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6140 | |
| 6141 | i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6142 | } |
| 6143 | |
| 6144 | /** |
| 6145 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 6146 | * @pf: board private structure |
| 6147 | **/ |
| 6148 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 6149 | { |
| 6150 | u32 reset_flags = 0; |
| 6151 | |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6152 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6153 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6154 | reset_flags |= BIT(__I40E_REINIT_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6155 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 6156 | } |
| 6157 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6158 | reset_flags |= BIT(__I40E_PF_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6159 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 6160 | } |
| 6161 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6162 | reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6163 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 6164 | } |
| 6165 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6166 | reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6167 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 6168 | } |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6169 | if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) { |
Jesse Brandeburg | 75f5cea | 2015-11-19 11:34:14 -0800 | [diff] [blame] | 6170 | reset_flags |= BIT(__I40E_DOWN_REQUESTED); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 6171 | clear_bit(__I40E_DOWN_REQUESTED, &pf->state); |
| 6172 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6173 | |
| 6174 | /* If there's a recovery already waiting, it takes |
| 6175 | * precedence before starting a new reset sequence. |
| 6176 | */ |
| 6177 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { |
| 6178 | i40e_handle_reset_warning(pf); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6179 | goto unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6180 | } |
| 6181 | |
| 6182 | /* If we're already down or resetting, just bail */ |
| 6183 | if (reset_flags && |
| 6184 | !test_bit(__I40E_DOWN, &pf->state) && |
| 6185 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 6186 | i40e_do_reset(pf, reset_flags); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 6187 | |
| 6188 | unlock: |
| 6189 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6190 | } |
| 6191 | |
| 6192 | /** |
| 6193 | * i40e_handle_link_event - Handle link event |
| 6194 | * @pf: board private structure |
| 6195 | * @e: event info posted on ARQ |
| 6196 | **/ |
| 6197 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 6198 | struct i40e_arq_event_info *e) |
| 6199 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6200 | struct i40e_aqc_get_link_status *status = |
| 6201 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6202 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 6203 | /* Do a new status request to re-enable LSE reporting |
| 6204 | * and load new status information into the hw struct |
| 6205 | * This completely ignores any state information |
| 6206 | * in the ARQ event info, instead choosing to always |
| 6207 | * issue the AQ update link status command. |
| 6208 | */ |
| 6209 | i40e_link_event(pf); |
| 6210 | |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 6211 | /* check for unqualified module, if link is down */ |
| 6212 | if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && |
| 6213 | (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && |
| 6214 | (!(status->link_info & I40E_AQ_LINK_UP))) |
| 6215 | dev_err(&pf->pdev->dev, |
| 6216 | "The driver failed to link because an unqualified module was detected.\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6217 | } |
| 6218 | |
| 6219 | /** |
| 6220 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 6221 | * @pf: board private structure |
| 6222 | **/ |
| 6223 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 6224 | { |
| 6225 | struct i40e_arq_event_info event; |
| 6226 | struct i40e_hw *hw = &pf->hw; |
| 6227 | u16 pending, i = 0; |
| 6228 | i40e_status ret; |
| 6229 | u16 opcode; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6230 | u32 oldval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6231 | u32 val; |
| 6232 | |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6233 | /* Do not run clean AQ when PF reset fails */ |
| 6234 | if (test_bit(__I40E_RESET_FAILED, &pf->state)) |
| 6235 | return; |
| 6236 | |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6237 | /* check for error indications */ |
| 6238 | val = rd32(&pf->hw, pf->hw.aq.arq.len); |
| 6239 | oldval = val; |
| 6240 | if (val & I40E_PF_ARQLEN_ARQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6241 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6242 | dev_info(&pf->pdev->dev, "ARQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6243 | val &= ~I40E_PF_ARQLEN_ARQVFE_MASK; |
| 6244 | } |
| 6245 | if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6246 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6247 | dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6248 | val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK; |
| 6249 | } |
| 6250 | if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6251 | if (hw->debug_mask & I40E_DEBUG_AQ) |
| 6252 | dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6253 | val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK; |
| 6254 | } |
| 6255 | if (oldval != val) |
| 6256 | wr32(&pf->hw, pf->hw.aq.arq.len, val); |
| 6257 | |
| 6258 | val = rd32(&pf->hw, pf->hw.aq.asq.len); |
| 6259 | oldval = val; |
| 6260 | if (val & I40E_PF_ATQLEN_ATQVFE_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6261 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6262 | dev_info(&pf->pdev->dev, "ASQ VF Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6263 | val &= ~I40E_PF_ATQLEN_ATQVFE_MASK; |
| 6264 | } |
| 6265 | if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6266 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6267 | dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6268 | val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK; |
| 6269 | } |
| 6270 | if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) { |
Mitch Williams | 75eb73c | 2015-11-19 11:34:21 -0800 | [diff] [blame] | 6271 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
| 6272 | dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n"); |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 6273 | val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK; |
| 6274 | } |
| 6275 | if (oldval != val) |
| 6276 | wr32(&pf->hw, pf->hw.aq.asq.len, val); |
| 6277 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6278 | event.buf_len = I40E_MAX_AQ_BUF_SIZE; |
| 6279 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6280 | if (!event.msg_buf) |
| 6281 | return; |
| 6282 | |
| 6283 | do { |
| 6284 | ret = i40e_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6285 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6286 | break; |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 6287 | else if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6288 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 6289 | break; |
| 6290 | } |
| 6291 | |
| 6292 | opcode = le16_to_cpu(event.desc.opcode); |
| 6293 | switch (opcode) { |
| 6294 | |
| 6295 | case i40e_aqc_opc_get_link_status: |
| 6296 | i40e_handle_link_event(pf, &event); |
| 6297 | break; |
| 6298 | case i40e_aqc_opc_send_msg_to_pf: |
| 6299 | ret = i40e_vc_process_vf_msg(pf, |
| 6300 | le16_to_cpu(event.desc.retval), |
| 6301 | le32_to_cpu(event.desc.cookie_high), |
| 6302 | le32_to_cpu(event.desc.cookie_low), |
| 6303 | event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 6304 | event.msg_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6305 | break; |
| 6306 | case i40e_aqc_opc_lldp_update_mib: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6307 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6308 | #ifdef CONFIG_I40E_DCB |
| 6309 | rtnl_lock(); |
| 6310 | ret = i40e_handle_lldp_event(pf, &event); |
| 6311 | rtnl_unlock(); |
| 6312 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6313 | break; |
| 6314 | case i40e_aqc_opc_event_lan_overflow: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6315 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6316 | i40e_handle_lan_overflow_event(pf, &event); |
| 6317 | break; |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6318 | case i40e_aqc_opc_send_msg_to_peer: |
| 6319 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); |
| 6320 | break; |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6321 | case i40e_aqc_opc_nvm_erase: |
| 6322 | case i40e_aqc_opc_nvm_update: |
Michal Kosiarz | 00ada50 | 2015-11-19 11:34:20 -0800 | [diff] [blame] | 6323 | case i40e_aqc_opc_oem_post_update: |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 6324 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, "ARQ NVM operation completed\n"); |
| 6325 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6326 | default: |
| 6327 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 6328 | "ARQ Error: Unknown event 0x%04x received\n", |
| 6329 | opcode); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6330 | break; |
| 6331 | } |
| 6332 | } while (pending && (i++ < pf->adminq_work_limit)); |
| 6333 | |
| 6334 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 6335 | /* re-enable Admin queue interrupt cause */ |
| 6336 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 6337 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 6338 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 6339 | i40e_flush(hw); |
| 6340 | |
| 6341 | kfree(event.msg_buf); |
| 6342 | } |
| 6343 | |
| 6344 | /** |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6345 | * i40e_verify_eeprom - make sure eeprom is good to use |
| 6346 | * @pf: board private structure |
| 6347 | **/ |
| 6348 | static void i40e_verify_eeprom(struct i40e_pf *pf) |
| 6349 | { |
| 6350 | int err; |
| 6351 | |
| 6352 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6353 | if (err) { |
| 6354 | /* retry in case of garbage read */ |
| 6355 | err = i40e_diag_eeprom_test(&pf->hw); |
| 6356 | if (err) { |
| 6357 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", |
| 6358 | err); |
| 6359 | set_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6360 | } |
| 6361 | } |
| 6362 | |
| 6363 | if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 6364 | dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n"); |
| 6365 | clear_bit(__I40E_BAD_EEPROM, &pf->state); |
| 6366 | } |
| 6367 | } |
| 6368 | |
| 6369 | /** |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6370 | * i40e_enable_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 | * enable switch loop back or die - no point in a return value |
| 6374 | **/ |
| 6375 | static void i40e_enable_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 | /** |
| 6406 | * i40e_disable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6407 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6408 | * |
| 6409 | * disable switch loop back or die - no point in a return value |
| 6410 | **/ |
| 6411 | static void i40e_disable_pf_switch_lb(struct i40e_pf *pf) |
| 6412 | { |
| 6413 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6414 | struct i40e_vsi_context ctxt; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6415 | int ret; |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6416 | |
| 6417 | ctxt.seid = pf->main_vsi_seid; |
| 6418 | ctxt.pf_num = pf->hw.pf_id; |
| 6419 | ctxt.vf_num = 0; |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6420 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6421 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6422 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6423 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 6424 | i40e_stat_str(&pf->hw, ret), |
| 6425 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6426 | return; |
| 6427 | } |
| 6428 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6429 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6430 | ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6431 | |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6432 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6433 | if (ret) { |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6434 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6435 | "update vsi switch failed, err %s aq_err %s\n", |
| 6436 | i40e_stat_str(&pf->hw, ret), |
| 6437 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6438 | } |
| 6439 | } |
| 6440 | |
| 6441 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6442 | * i40e_config_bridge_mode - Configure the HW bridge mode |
| 6443 | * @veb: pointer to the bridge instance |
| 6444 | * |
| 6445 | * Configure the loop back mode for the LAN VSI that is downlink to the |
| 6446 | * specified HW bridge instance. It is expected this function is called |
| 6447 | * when a new HW bridge is instantiated. |
| 6448 | **/ |
| 6449 | static void i40e_config_bridge_mode(struct i40e_veb *veb) |
| 6450 | { |
| 6451 | struct i40e_pf *pf = veb->pf; |
| 6452 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 6453 | if (pf->hw.debug_mask & I40E_DEBUG_LAN) |
| 6454 | dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n", |
| 6455 | veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6456 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) |
| 6457 | i40e_disable_pf_switch_lb(pf); |
| 6458 | else |
| 6459 | i40e_enable_pf_switch_lb(pf); |
| 6460 | } |
| 6461 | |
| 6462 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6463 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 6464 | * @veb: pointer to the VEB instance |
| 6465 | * |
| 6466 | * This is a recursive function that first builds the attached VSIs then |
| 6467 | * recurses in to build the next layer of VEB. We track the connections |
| 6468 | * through our own index numbers because the seid's from the HW could |
| 6469 | * change across the reset. |
| 6470 | **/ |
| 6471 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 6472 | { |
| 6473 | struct i40e_vsi *ctl_vsi = NULL; |
| 6474 | struct i40e_pf *pf = veb->pf; |
| 6475 | int v, veb_idx; |
| 6476 | int ret; |
| 6477 | |
| 6478 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6479 | for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6480 | if (pf->vsi[v] && |
| 6481 | pf->vsi[v]->veb_idx == veb->idx && |
| 6482 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 6483 | ctl_vsi = pf->vsi[v]; |
| 6484 | break; |
| 6485 | } |
| 6486 | } |
| 6487 | if (!ctl_vsi) { |
| 6488 | dev_info(&pf->pdev->dev, |
| 6489 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 6490 | ret = -ENOENT; |
| 6491 | goto end_reconstitute; |
| 6492 | } |
| 6493 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 6494 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 6495 | ret = i40e_add_vsi(ctl_vsi); |
| 6496 | if (ret) { |
| 6497 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6498 | "rebuild of veb_idx %d owner VSI failed: %d\n", |
| 6499 | veb->idx, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6500 | goto end_reconstitute; |
| 6501 | } |
| 6502 | i40e_vsi_reset_stats(ctl_vsi); |
| 6503 | |
| 6504 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 6505 | ret = i40e_add_veb(veb, ctl_vsi); |
| 6506 | if (ret) |
| 6507 | goto end_reconstitute; |
| 6508 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 6509 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
| 6510 | veb->bridge_mode = BRIDGE_MODE_VEB; |
| 6511 | else |
| 6512 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6513 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | b64ba08 | 2014-11-13 03:06:15 +0000 | [diff] [blame] | 6514 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6515 | /* create the remaining VSIs attached to this VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6516 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6517 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 6518 | continue; |
| 6519 | |
| 6520 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 6521 | struct i40e_vsi *vsi = pf->vsi[v]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 6522 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6523 | vsi->uplink_seid = veb->seid; |
| 6524 | ret = i40e_add_vsi(vsi); |
| 6525 | if (ret) { |
| 6526 | dev_info(&pf->pdev->dev, |
| 6527 | "rebuild of vsi_idx %d failed: %d\n", |
| 6528 | v, ret); |
| 6529 | goto end_reconstitute; |
| 6530 | } |
| 6531 | i40e_vsi_reset_stats(vsi); |
| 6532 | } |
| 6533 | } |
| 6534 | |
| 6535 | /* create any VEBs attached to this VEB - RECURSION */ |
| 6536 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 6537 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 6538 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 6539 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 6540 | if (ret) |
| 6541 | break; |
| 6542 | } |
| 6543 | } |
| 6544 | |
| 6545 | end_reconstitute: |
| 6546 | return ret; |
| 6547 | } |
| 6548 | |
| 6549 | /** |
| 6550 | * i40e_get_capabilities - get info about the HW |
| 6551 | * @pf: the PF struct |
| 6552 | **/ |
| 6553 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 6554 | { |
| 6555 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 6556 | u16 data_size; |
| 6557 | int buf_len; |
| 6558 | int err; |
| 6559 | |
| 6560 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 6561 | do { |
| 6562 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 6563 | if (!cap_buf) |
| 6564 | return -ENOMEM; |
| 6565 | |
| 6566 | /* this loads the data into the hw struct for us */ |
| 6567 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 6568 | &data_size, |
| 6569 | i40e_aqc_opc_list_func_capabilities, |
| 6570 | NULL); |
| 6571 | /* data loaded, buffer no longer needed */ |
| 6572 | kfree(cap_buf); |
| 6573 | |
| 6574 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 6575 | /* retry with a larger buffer */ |
| 6576 | buf_len = data_size; |
| 6577 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 6578 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6579 | "capability discovery failed, err %s aq_err %s\n", |
| 6580 | i40e_stat_str(&pf->hw, err), |
| 6581 | i40e_aq_str(&pf->hw, |
| 6582 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6583 | return -ENODEV; |
| 6584 | } |
| 6585 | } while (err); |
| 6586 | |
| 6587 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 6588 | dev_info(&pf->pdev->dev, |
| 6589 | "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", |
| 6590 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 6591 | pf->hw.func_caps.num_msix_vectors, |
| 6592 | pf->hw.func_caps.num_msix_vectors_vf, |
| 6593 | pf->hw.func_caps.fd_filters_guaranteed, |
| 6594 | pf->hw.func_caps.fd_filters_best_effort, |
| 6595 | pf->hw.func_caps.num_tx_qp, |
| 6596 | pf->hw.func_caps.num_vsis); |
| 6597 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 6598 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 6599 | + pf->hw.func_caps.num_vfs) |
| 6600 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 6601 | dev_info(&pf->pdev->dev, |
| 6602 | "got num_vsis %d, setting num_vsis to %d\n", |
| 6603 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 6604 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 6605 | } |
| 6606 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6607 | return 0; |
| 6608 | } |
| 6609 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6610 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
| 6611 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6612 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6613 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6614 | * @pf: board private structure |
| 6615 | **/ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6616 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6617 | { |
| 6618 | struct i40e_vsi *vsi; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6619 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6620 | |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6621 | /* quick workaround for an NVM issue that leaves a critical register |
| 6622 | * uninitialized |
| 6623 | */ |
| 6624 | if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) { |
| 6625 | static const u32 hkey[] = { |
| 6626 | 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36, |
| 6627 | 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb, |
| 6628 | 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21, |
| 6629 | 0x95b3a76d}; |
| 6630 | |
| 6631 | for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++) |
| 6632 | wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]); |
| 6633 | } |
| 6634 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6635 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6636 | return; |
| 6637 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6638 | /* find existing VSI and see if it needs configuring */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6639 | vsi = NULL; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6640 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6641 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6642 | vsi = pf->vsi[i]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6643 | break; |
| 6644 | } |
| 6645 | } |
| 6646 | |
| 6647 | /* create a new VSI if none exists */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6648 | if (!vsi) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6649 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
| 6650 | pf->vsi[pf->lan_vsi]->seid, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6651 | if (!vsi) { |
| 6652 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6653 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 6654 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6655 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6656 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6657 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6658 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6659 | } |
| 6660 | |
| 6661 | /** |
| 6662 | * i40e_fdir_teardown - release the Flow Director resources |
| 6663 | * @pf: board private structure |
| 6664 | **/ |
| 6665 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 6666 | { |
| 6667 | int i; |
| 6668 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6669 | i40e_fdir_filter_exit(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6670 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6671 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 6672 | i40e_vsi_release(pf->vsi[i]); |
| 6673 | break; |
| 6674 | } |
| 6675 | } |
| 6676 | } |
| 6677 | |
| 6678 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6679 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6680 | * @pf: board private structure |
| 6681 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6682 | * 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] | 6683 | **/ |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6684 | static void i40e_prep_for_reset(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6685 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6686 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6687 | i40e_status ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6688 | u32 v; |
| 6689 | |
| 6690 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 6691 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6692 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6693 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6694 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6695 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6696 | /* quiesce the VSIs and their queues that are not already DOWN */ |
| 6697 | i40e_pf_quiesce_all_vsi(pf); |
| 6698 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6699 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6700 | if (pf->vsi[v]) |
| 6701 | pf->vsi[v]->seid = 0; |
| 6702 | } |
| 6703 | |
| 6704 | i40e_shutdown_adminq(&pf->hw); |
| 6705 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6706 | /* call shutdown HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6707 | if (hw->hmc.hmc_obj) { |
| 6708 | ret = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6709 | if (ret) |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6710 | dev_warn(&pf->pdev->dev, |
| 6711 | "shutdown_lan_hmc failed: %d\n", ret); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6712 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6713 | } |
| 6714 | |
| 6715 | /** |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6716 | * i40e_send_version - update firmware with driver version |
| 6717 | * @pf: PF struct |
| 6718 | */ |
| 6719 | static void i40e_send_version(struct i40e_pf *pf) |
| 6720 | { |
| 6721 | struct i40e_driver_version dv; |
| 6722 | |
| 6723 | dv.major_version = DRV_VERSION_MAJOR; |
| 6724 | dv.minor_version = DRV_VERSION_MINOR; |
| 6725 | dv.build_version = DRV_VERSION_BUILD; |
| 6726 | dv.subbuild_version = 0; |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 6727 | strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6728 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 6729 | } |
| 6730 | |
| 6731 | /** |
Jesse Brandeburg | 4dda12e | 2013-12-18 13:46:01 +0000 | [diff] [blame] | 6732 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6733 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6734 | * @reinit: if the Main VSI needs to re-initialized. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6735 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6736 | 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] | 6737 | { |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6738 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6739 | u8 set_fc_aq_fail = 0; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6740 | i40e_status ret; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6741 | u32 val; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6742 | u32 v; |
| 6743 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6744 | /* Now we wait for GRST to settle out. |
| 6745 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 6746 | * because the reset will make them disappear. |
| 6747 | */ |
| 6748 | ret = i40e_pf_reset(hw); |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6749 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6750 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6751 | set_bit(__I40E_RESET_FAILED, &pf->state); |
| 6752 | goto clear_recovery; |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6753 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6754 | pf->pfr_count++; |
| 6755 | |
| 6756 | if (test_bit(__I40E_DOWN, &pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6757 | goto clear_recovery; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6758 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6759 | |
| 6760 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 6761 | ret = i40e_init_adminq(&pf->hw); |
| 6762 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6763 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n", |
| 6764 | i40e_stat_str(&pf->hw, ret), |
| 6765 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6766 | goto clear_recovery; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6767 | } |
| 6768 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6769 | /* re-verify the eeprom if we just had an EMP reset */ |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 6770 | if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state)) |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6771 | i40e_verify_eeprom(pf); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6772 | |
Shannon Nelson | e78ac4bf | 2014-05-10 04:49:09 +0000 | [diff] [blame] | 6773 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6774 | ret = i40e_get_capabilities(pf); |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6775 | if (ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6776 | goto end_core_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6777 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6778 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 6779 | hw->func_caps.num_rx_qp, |
| 6780 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 6781 | if (ret) { |
| 6782 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 6783 | goto end_core_reset; |
| 6784 | } |
| 6785 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 6786 | if (ret) { |
| 6787 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 6788 | goto end_core_reset; |
| 6789 | } |
| 6790 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6791 | #ifdef CONFIG_I40E_DCB |
| 6792 | ret = i40e_init_pf_dcb(pf); |
| 6793 | if (ret) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 6794 | dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret); |
| 6795 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
| 6796 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6797 | } |
| 6798 | #endif /* CONFIG_I40E_DCB */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6799 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 6800 | i40e_init_pf_fcoe(pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6801 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6802 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6803 | /* do basic switch setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6804 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6805 | if (ret) |
| 6806 | goto end_core_reset; |
| 6807 | |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6808 | /* driver is only interested in link up/down and module qualification |
| 6809 | * reports from firmware |
| 6810 | */ |
| 6811 | ret = i40e_aq_set_phy_int_mask(&pf->hw, |
| 6812 | I40E_AQ_EVENT_LINK_UPDOWN | |
| 6813 | I40E_AQ_EVENT_MODULE_QUAL_FAIL, NULL); |
| 6814 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6815 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 6816 | i40e_stat_str(&pf->hw, ret), |
| 6817 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6818 | |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6819 | /* make sure our flow control settings are restored */ |
| 6820 | ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true); |
| 6821 | if (ret) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 6822 | dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n", |
| 6823 | i40e_stat_str(&pf->hw, ret), |
| 6824 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6825 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6826 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 6827 | * They are still in our local switch element arrays, so only |
| 6828 | * need to rebuild the switch model in the HW. |
| 6829 | * |
| 6830 | * If there were VEBs but the reconstitution failed, we'll try |
| 6831 | * try to recover minimal use by getting the basic PF VSI working. |
| 6832 | */ |
| 6833 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6834 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6835 | /* find the one VEB connected to the MAC, and find orphans */ |
| 6836 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 6837 | if (!pf->veb[v]) |
| 6838 | continue; |
| 6839 | |
| 6840 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 6841 | pf->veb[v]->uplink_seid == 0) { |
| 6842 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 6843 | |
| 6844 | if (!ret) |
| 6845 | continue; |
| 6846 | |
| 6847 | /* If Main VEB failed, we're in deep doodoo, |
| 6848 | * so give up rebuilding the switch and set up |
| 6849 | * for minimal rebuild of PF VSI. |
| 6850 | * If orphan failed, we'll report the error |
| 6851 | * but try to keep going. |
| 6852 | */ |
| 6853 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 6854 | dev_info(&pf->pdev->dev, |
| 6855 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 6856 | ret); |
| 6857 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 6858 | = pf->mac_seid; |
| 6859 | break; |
| 6860 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 6861 | dev_info(&pf->pdev->dev, |
| 6862 | "rebuild of orphan VEB failed: %d\n", |
| 6863 | ret); |
| 6864 | } |
| 6865 | } |
| 6866 | } |
| 6867 | } |
| 6868 | |
| 6869 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
Shannon Nelson | cde4cbc | 2014-06-04 01:23:17 +0000 | [diff] [blame] | 6870 | dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6871 | /* no VEB, so rebuild only the Main VSI */ |
| 6872 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 6873 | if (ret) { |
| 6874 | dev_info(&pf->pdev->dev, |
| 6875 | "rebuild of Main VSI failed: %d\n", ret); |
| 6876 | goto end_core_reset; |
| 6877 | } |
| 6878 | } |
| 6879 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 6880 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 6881 | * of TSO, so that we avoid the MDD being fired and causing |
| 6882 | * a reset in the case of small MSS+TSO. |
| 6883 | */ |
| 6884 | #define I40E_REG_MSS 0x000E64DC |
| 6885 | #define I40E_REG_MSS_MIN_MASK 0x3FF0000 |
| 6886 | #define I40E_64BYTE_MSS 0x400000 |
| 6887 | val = rd32(hw, I40E_REG_MSS); |
| 6888 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 6889 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 6890 | val |= I40E_64BYTE_MSS; |
| 6891 | wr32(hw, I40E_REG_MSS, val); |
| 6892 | } |
| 6893 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 6894 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 6895 | msleep(75); |
| 6896 | ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 6897 | if (ret) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 6898 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 6899 | i40e_stat_str(&pf->hw, ret), |
| 6900 | i40e_aq_str(&pf->hw, |
| 6901 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6902 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6903 | /* reinit the misc interrupt */ |
| 6904 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 6905 | ret = i40e_setup_misc_vector(pf); |
| 6906 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 6907 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 6908 | * transmitted. By doing so we stop a malicious VF from sending out |
| 6909 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 6910 | * PF/VF VSIs. |
| 6911 | * The FW can still send Flow control frames if enabled. |
| 6912 | */ |
| 6913 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 6914 | pf->main_vsi_seid); |
| 6915 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6916 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 6917 | i40e_pf_unquiesce_all_vsi(pf); |
| 6918 | |
Mitch Williams | 69f64b2 | 2014-02-13 03:48:46 -0800 | [diff] [blame] | 6919 | if (pf->num_alloc_vfs) { |
| 6920 | for (v = 0; v < pf->num_alloc_vfs; v++) |
| 6921 | i40e_reset_vf(&pf->vf[v], true); |
| 6922 | } |
| 6923 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6924 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6925 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6926 | |
| 6927 | end_core_reset: |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6928 | clear_bit(__I40E_RESET_FAILED, &pf->state); |
| 6929 | clear_recovery: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6930 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 6931 | } |
| 6932 | |
| 6933 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6934 | * 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] | 6935 | * @pf: board private structure |
| 6936 | * |
| 6937 | * Close up the VFs and other things in prep for a Core Reset, |
| 6938 | * then get ready to rebuild the world. |
| 6939 | **/ |
| 6940 | static void i40e_handle_reset_warning(struct i40e_pf *pf) |
| 6941 | { |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6942 | i40e_prep_for_reset(pf); |
| 6943 | i40e_reset_and_rebuild(pf, false); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6944 | } |
| 6945 | |
| 6946 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6947 | * i40e_handle_mdd_event |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6948 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6949 | * |
| 6950 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 6951 | **/ |
| 6952 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 6953 | { |
| 6954 | struct i40e_hw *hw = &pf->hw; |
| 6955 | bool mdd_detected = false; |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 6956 | bool pf_mdd_detected = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6957 | struct i40e_vf *vf; |
| 6958 | u32 reg; |
| 6959 | int i; |
| 6960 | |
| 6961 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) |
| 6962 | return; |
| 6963 | |
| 6964 | /* find what triggered the MDD event */ |
| 6965 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 6966 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6967 | u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> |
| 6968 | I40E_GL_MDET_TX_PF_NUM_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 6969 | u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6970 | I40E_GL_MDET_TX_VF_NUM_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 6971 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6972 | I40E_GL_MDET_TX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 6973 | u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >> |
| 6974 | I40E_GL_MDET_TX_QUEUE_SHIFT) - |
| 6975 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 6976 | if (netif_msg_tx_err(pf)) |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6977 | 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] | 6978 | event, queue, pf_num, vf_num); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6979 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 6980 | mdd_detected = true; |
| 6981 | } |
| 6982 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 6983 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6984 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> |
| 6985 | I40E_GL_MDET_RX_FUNCTION_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 6986 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6987 | I40E_GL_MDET_RX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 6988 | u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >> |
| 6989 | I40E_GL_MDET_RX_QUEUE_SHIFT) - |
| 6990 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 6991 | if (netif_msg_rx_err(pf)) |
| 6992 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
| 6993 | event, queue, func); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6994 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 6995 | mdd_detected = true; |
| 6996 | } |
| 6997 | |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 6998 | if (mdd_detected) { |
| 6999 | reg = rd32(hw, I40E_PF_MDET_TX); |
| 7000 | if (reg & I40E_PF_MDET_TX_VALID_MASK) { |
| 7001 | wr32(hw, I40E_PF_MDET_TX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7002 | 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] | 7003 | pf_mdd_detected = true; |
| 7004 | } |
| 7005 | reg = rd32(hw, I40E_PF_MDET_RX); |
| 7006 | if (reg & I40E_PF_MDET_RX_VALID_MASK) { |
| 7007 | wr32(hw, I40E_PF_MDET_RX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7008 | 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] | 7009 | pf_mdd_detected = true; |
| 7010 | } |
| 7011 | /* Queue belongs to the PF, initiate a reset */ |
| 7012 | if (pf_mdd_detected) { |
| 7013 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 7014 | i40e_service_event_schedule(pf); |
| 7015 | } |
| 7016 | } |
| 7017 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7018 | /* see if one of the VFs needs its hand slapped */ |
| 7019 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 7020 | vf = &(pf->vf[i]); |
| 7021 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 7022 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 7023 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 7024 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7025 | dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n", |
| 7026 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7027 | } |
| 7028 | |
| 7029 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 7030 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 7031 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 7032 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 7033 | dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n", |
| 7034 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7035 | } |
| 7036 | |
| 7037 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 7038 | dev_info(&pf->pdev->dev, |
| 7039 | "Too many MDD events on VF %d, disabled\n", i); |
| 7040 | dev_info(&pf->pdev->dev, |
| 7041 | "Use PF Control I/F to re-enable the VF\n"); |
| 7042 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 7043 | } |
| 7044 | } |
| 7045 | |
| 7046 | /* re-enable mdd interrupt cause */ |
| 7047 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 7048 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 7049 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 7050 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 7051 | i40e_flush(hw); |
| 7052 | } |
| 7053 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7054 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7055 | * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7056 | * @pf: board private structure |
| 7057 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7058 | static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7059 | { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7060 | #if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7061 | struct i40e_hw *hw = &pf->hw; |
| 7062 | i40e_status ret; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7063 | __be16 port; |
| 7064 | int i; |
| 7065 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7066 | if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC)) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7067 | return; |
| 7068 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7069 | pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7070 | |
| 7071 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7072 | if (pf->pending_udp_bitmap & BIT_ULL(i)) { |
| 7073 | pf->pending_udp_bitmap &= ~BIT_ULL(i); |
| 7074 | port = pf->udp_ports[i].index; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7075 | if (port) |
| 7076 | ret = i40e_aq_add_udp_tunnel(hw, ntohs(port), |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7077 | pf->udp_ports[i].type, |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7078 | NULL, NULL); |
| 7079 | else |
| 7080 | ret = i40e_aq_del_udp_tunnel(hw, i, NULL); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7081 | |
| 7082 | if (ret) { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7083 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7084 | "%s vxlan port %d, index %d failed, err %s aq_err %s\n", |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7085 | port ? "add" : "delete", |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 7086 | ntohs(port), i, |
| 7087 | i40e_stat_str(&pf->hw, ret), |
| 7088 | i40e_aq_str(&pf->hw, |
| 7089 | pf->hw.aq.asq_last_status)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7090 | pf->udp_ports[i].index = 0; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7091 | } |
| 7092 | } |
| 7093 | } |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7094 | #endif |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7095 | } |
| 7096 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7097 | /** |
| 7098 | * i40e_service_task - Run the driver's async subtasks |
| 7099 | * @work: pointer to work_struct containing our data |
| 7100 | **/ |
| 7101 | static void i40e_service_task(struct work_struct *work) |
| 7102 | { |
| 7103 | struct i40e_pf *pf = container_of(work, |
| 7104 | struct i40e_pf, |
| 7105 | service_task); |
| 7106 | unsigned long start_time = jiffies; |
| 7107 | |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 7108 | /* don't bother with service tasks if a reset is in progress */ |
| 7109 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7110 | i40e_service_event_complete(pf); |
| 7111 | return; |
| 7112 | } |
| 7113 | |
Kiran Patil | b03a8c1 | 2015-09-24 18:13:15 -0400 | [diff] [blame] | 7114 | i40e_detect_recover_hung(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7115 | i40e_reset_subtask(pf); |
| 7116 | i40e_handle_mdd_event(pf); |
| 7117 | i40e_vc_process_vflr_event(pf); |
| 7118 | i40e_watchdog_subtask(pf); |
| 7119 | i40e_fdir_reinit_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7120 | i40e_sync_filters_subtask(pf); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 7121 | i40e_sync_udp_filters_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7122 | i40e_clean_adminq_subtask(pf); |
| 7123 | |
| 7124 | i40e_service_event_complete(pf); |
| 7125 | |
| 7126 | /* If the tasks have taken longer than one timer cycle or there |
| 7127 | * is more work to be done, reschedule the service task now |
| 7128 | * rather than wait for the timer to tick again. |
| 7129 | */ |
| 7130 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
| 7131 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || |
| 7132 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || |
| 7133 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 7134 | i40e_service_event_schedule(pf); |
| 7135 | } |
| 7136 | |
| 7137 | /** |
| 7138 | * i40e_service_timer - timer callback |
| 7139 | * @data: pointer to PF struct |
| 7140 | **/ |
| 7141 | static void i40e_service_timer(unsigned long data) |
| 7142 | { |
| 7143 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 7144 | |
| 7145 | mod_timer(&pf->service_timer, |
| 7146 | round_jiffies(jiffies + pf->service_timer_period)); |
| 7147 | i40e_service_event_schedule(pf); |
| 7148 | } |
| 7149 | |
| 7150 | /** |
| 7151 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 7152 | * @vsi: the VSI being configured |
| 7153 | **/ |
| 7154 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 7155 | { |
| 7156 | struct i40e_pf *pf = vsi->back; |
| 7157 | |
| 7158 | switch (vsi->type) { |
| 7159 | case I40E_VSI_MAIN: |
| 7160 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 7161 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7162 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7163 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7164 | vsi->num_q_vectors = pf->num_lan_msix; |
| 7165 | else |
| 7166 | vsi->num_q_vectors = 1; |
| 7167 | |
| 7168 | break; |
| 7169 | |
| 7170 | case I40E_VSI_FDIR: |
| 7171 | vsi->alloc_queue_pairs = 1; |
| 7172 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 7173 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7174 | vsi->num_q_vectors = 1; |
| 7175 | break; |
| 7176 | |
| 7177 | case I40E_VSI_VMDQ2: |
| 7178 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 7179 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7180 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7181 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 7182 | break; |
| 7183 | |
| 7184 | case I40E_VSI_SRIOV: |
| 7185 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 7186 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7187 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7188 | break; |
| 7189 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7190 | #ifdef I40E_FCOE |
| 7191 | case I40E_VSI_FCOE: |
| 7192 | vsi->alloc_queue_pairs = pf->num_fcoe_qps; |
| 7193 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 7194 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 7195 | vsi->num_q_vectors = pf->num_fcoe_msix; |
| 7196 | break; |
| 7197 | |
| 7198 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7199 | default: |
| 7200 | WARN_ON(1); |
| 7201 | return -ENODATA; |
| 7202 | } |
| 7203 | |
| 7204 | return 0; |
| 7205 | } |
| 7206 | |
| 7207 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7208 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 7209 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7210 | * @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] | 7211 | * |
| 7212 | * On error: returns error code (negative) |
| 7213 | * On success: returns 0 |
| 7214 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7215 | 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] | 7216 | { |
| 7217 | int size; |
| 7218 | int ret = 0; |
| 7219 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7220 | /* allocate memory for both Tx and Rx ring pointers */ |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7221 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
| 7222 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 7223 | if (!vsi->tx_rings) |
| 7224 | return -ENOMEM; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7225 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
| 7226 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7227 | if (alloc_qvectors) { |
| 7228 | /* allocate memory for q_vector pointers */ |
Julia Lawall | f57e4fb | 2014-07-30 03:11:09 +0000 | [diff] [blame] | 7229 | size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7230 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 7231 | if (!vsi->q_vectors) { |
| 7232 | ret = -ENOMEM; |
| 7233 | goto err_vectors; |
| 7234 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7235 | } |
| 7236 | return ret; |
| 7237 | |
| 7238 | err_vectors: |
| 7239 | kfree(vsi->tx_rings); |
| 7240 | return ret; |
| 7241 | } |
| 7242 | |
| 7243 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7244 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 7245 | * @pf: board private structure |
| 7246 | * @type: type of VSI |
| 7247 | * |
| 7248 | * On error: returns error code (negative) |
| 7249 | * On success: returns vsi index in PF (positive) |
| 7250 | **/ |
| 7251 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 7252 | { |
| 7253 | int ret = -ENODEV; |
| 7254 | struct i40e_vsi *vsi; |
| 7255 | int vsi_idx; |
| 7256 | int i; |
| 7257 | |
| 7258 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 7259 | mutex_lock(&pf->switch_mutex); |
| 7260 | |
| 7261 | /* VSI list may be fragmented if VSI creation/destruction has |
| 7262 | * been happening. We can afford to do a quick scan to look |
| 7263 | * for any free VSIs in the list. |
| 7264 | * |
| 7265 | * find next empty vsi slot, looping back around if necessary |
| 7266 | */ |
| 7267 | i = pf->next_vsi; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7268 | while (i < pf->num_alloc_vsi && pf->vsi[i]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7269 | i++; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7270 | if (i >= pf->num_alloc_vsi) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7271 | i = 0; |
| 7272 | while (i < pf->next_vsi && pf->vsi[i]) |
| 7273 | i++; |
| 7274 | } |
| 7275 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 7276 | if (i < pf->num_alloc_vsi && !pf->vsi[i]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7277 | vsi_idx = i; /* Found one! */ |
| 7278 | } else { |
| 7279 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7280 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7281 | } |
| 7282 | pf->next_vsi = ++i; |
| 7283 | |
| 7284 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 7285 | if (!vsi) { |
| 7286 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7287 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7288 | } |
| 7289 | vsi->type = type; |
| 7290 | vsi->back = pf; |
| 7291 | set_bit(__I40E_DOWN, &vsi->state); |
| 7292 | vsi->flags = 0; |
| 7293 | vsi->idx = vsi_idx; |
| 7294 | vsi->rx_itr_setting = pf->rx_itr_default; |
| 7295 | vsi->tx_itr_setting = pf->tx_itr_default; |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 7296 | vsi->int_rate_limit = 0; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 7297 | vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ? |
| 7298 | pf->rss_table_size : 64; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7299 | vsi->netdev_registered = false; |
| 7300 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
| 7301 | INIT_LIST_HEAD(&vsi->mac_filter_list); |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 7302 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7303 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7304 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 7305 | if (ret) |
| 7306 | goto err_rings; |
| 7307 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7308 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7309 | if (ret) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7310 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7311 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7312 | /* Setup default MSIX irq handler for VSI */ |
| 7313 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 7314 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 7315 | /* Initialize VSI lock */ |
| 7316 | spin_lock_init(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7317 | pf->vsi[vsi_idx] = vsi; |
| 7318 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7319 | goto unlock_pf; |
| 7320 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7321 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7322 | pf->next_vsi = i - 1; |
| 7323 | kfree(vsi); |
| 7324 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7325 | mutex_unlock(&pf->switch_mutex); |
| 7326 | return ret; |
| 7327 | } |
| 7328 | |
| 7329 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7330 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 7331 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7332 | * @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] | 7333 | * |
| 7334 | * On error: returns error code (negative) |
| 7335 | * On success: returns 0 |
| 7336 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7337 | 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] | 7338 | { |
| 7339 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7340 | if (free_qvectors) { |
| 7341 | kfree(vsi->q_vectors); |
| 7342 | vsi->q_vectors = NULL; |
| 7343 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 7344 | kfree(vsi->tx_rings); |
| 7345 | vsi->tx_rings = NULL; |
| 7346 | vsi->rx_rings = NULL; |
| 7347 | } |
| 7348 | |
| 7349 | /** |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7350 | * i40e_clear_rss_config_user - clear the user configured RSS hash keys |
| 7351 | * and lookup table |
| 7352 | * @vsi: Pointer to VSI structure |
| 7353 | */ |
| 7354 | static void i40e_clear_rss_config_user(struct i40e_vsi *vsi) |
| 7355 | { |
| 7356 | if (!vsi) |
| 7357 | return; |
| 7358 | |
| 7359 | kfree(vsi->rss_hkey_user); |
| 7360 | vsi->rss_hkey_user = NULL; |
| 7361 | |
| 7362 | kfree(vsi->rss_lut_user); |
| 7363 | vsi->rss_lut_user = NULL; |
| 7364 | } |
| 7365 | |
| 7366 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7367 | * i40e_vsi_clear - Deallocate the VSI provided |
| 7368 | * @vsi: the VSI being un-configured |
| 7369 | **/ |
| 7370 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 7371 | { |
| 7372 | struct i40e_pf *pf; |
| 7373 | |
| 7374 | if (!vsi) |
| 7375 | return 0; |
| 7376 | |
| 7377 | if (!vsi->back) |
| 7378 | goto free_vsi; |
| 7379 | pf = vsi->back; |
| 7380 | |
| 7381 | mutex_lock(&pf->switch_mutex); |
| 7382 | if (!pf->vsi[vsi->idx]) { |
| 7383 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 7384 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 7385 | goto unlock_vsi; |
| 7386 | } |
| 7387 | |
| 7388 | if (pf->vsi[vsi->idx] != vsi) { |
| 7389 | dev_err(&pf->pdev->dev, |
| 7390 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 7391 | pf->vsi[vsi->idx]->idx, |
| 7392 | pf->vsi[vsi->idx], |
| 7393 | pf->vsi[vsi->idx]->type, |
| 7394 | vsi->idx, vsi, vsi->type); |
| 7395 | goto unlock_vsi; |
| 7396 | } |
| 7397 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7398 | /* updates the PF for this cleared vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7399 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 7400 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 7401 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7402 | i40e_vsi_free_arrays(vsi, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 7403 | i40e_clear_rss_config_user(vsi); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7404 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7405 | pf->vsi[vsi->idx] = NULL; |
| 7406 | if (vsi->idx < pf->next_vsi) |
| 7407 | pf->next_vsi = vsi->idx; |
| 7408 | |
| 7409 | unlock_vsi: |
| 7410 | mutex_unlock(&pf->switch_mutex); |
| 7411 | free_vsi: |
| 7412 | kfree(vsi); |
| 7413 | |
| 7414 | return 0; |
| 7415 | } |
| 7416 | |
| 7417 | /** |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7418 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 7419 | * @vsi: the VSI being cleaned |
| 7420 | **/ |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7421 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7422 | { |
| 7423 | int i; |
| 7424 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 7425 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7426 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 7427 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 7428 | vsi->tx_rings[i] = NULL; |
| 7429 | vsi->rx_rings[i] = NULL; |
| 7430 | } |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 7431 | } |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7432 | } |
| 7433 | |
| 7434 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7435 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 7436 | * @vsi: the VSI being configured |
| 7437 | **/ |
| 7438 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 7439 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 7440 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7441 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7442 | int i; |
| 7443 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7444 | /* Set basic values in the rings to be used later during open() */ |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7445 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7446 | /* allocate space for both Tx and Rx in one shot */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7447 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
| 7448 | if (!tx_ring) |
| 7449 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7450 | |
| 7451 | tx_ring->queue_index = i; |
| 7452 | tx_ring->reg_idx = vsi->base_queue + i; |
| 7453 | tx_ring->ring_active = false; |
| 7454 | tx_ring->vsi = vsi; |
| 7455 | tx_ring->netdev = vsi->netdev; |
| 7456 | tx_ring->dev = &pf->pdev->dev; |
| 7457 | tx_ring->count = vsi->num_desc; |
| 7458 | tx_ring->size = 0; |
| 7459 | tx_ring->dcb_tc = 0; |
Anjali Singhai Jain | 8e0764b | 2015-06-05 12:20:30 -0400 | [diff] [blame] | 7460 | if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) |
| 7461 | tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; |
Anjali Singhai Jain | 527274c | 2015-06-05 12:20:31 -0400 | [diff] [blame] | 7462 | if (vsi->back->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE) |
| 7463 | tx_ring->flags |= I40E_TXR_FLAGS_OUTER_UDP_CSUM; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7464 | vsi->tx_rings[i] = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7465 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7466 | rx_ring = &tx_ring[1]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7467 | rx_ring->queue_index = i; |
| 7468 | rx_ring->reg_idx = vsi->base_queue + i; |
| 7469 | rx_ring->ring_active = false; |
| 7470 | rx_ring->vsi = vsi; |
| 7471 | rx_ring->netdev = vsi->netdev; |
| 7472 | rx_ring->dev = &pf->pdev->dev; |
| 7473 | rx_ring->count = vsi->num_desc; |
| 7474 | rx_ring->size = 0; |
| 7475 | rx_ring->dcb_tc = 0; |
| 7476 | if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) |
| 7477 | set_ring_16byte_desc_enabled(rx_ring); |
| 7478 | else |
| 7479 | clear_ring_16byte_desc_enabled(rx_ring); |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7480 | vsi->rx_rings[i] = rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7481 | } |
| 7482 | |
| 7483 | return 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7484 | |
| 7485 | err_out: |
| 7486 | i40e_vsi_clear_rings(vsi); |
| 7487 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7488 | } |
| 7489 | |
| 7490 | /** |
| 7491 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 7492 | * @pf: board private structure |
| 7493 | * @vectors: the number of MSI-X vectors to request |
| 7494 | * |
| 7495 | * Returns the number of vectors reserved, or error |
| 7496 | **/ |
| 7497 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 7498 | { |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7499 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
| 7500 | I40E_MIN_MSIX, vectors); |
| 7501 | if (vectors < 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7502 | dev_info(&pf->pdev->dev, |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7503 | "MSI-X vector reservation failed: %d\n", vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7504 | vectors = 0; |
| 7505 | } |
| 7506 | |
| 7507 | return vectors; |
| 7508 | } |
| 7509 | |
| 7510 | /** |
| 7511 | * i40e_init_msix - Setup the MSIX capability |
| 7512 | * @pf: board private structure |
| 7513 | * |
| 7514 | * Work with the OS to set up the MSIX vectors needed. |
| 7515 | * |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7516 | * Returns the number of vectors reserved or negative on failure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7517 | **/ |
| 7518 | static int i40e_init_msix(struct i40e_pf *pf) |
| 7519 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7520 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7521 | int vectors_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7522 | int v_budget, i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7523 | int v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7524 | |
| 7525 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 7526 | return -ENODEV; |
| 7527 | |
| 7528 | /* The number of vectors we'll request will be comprised of: |
| 7529 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 7530 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7531 | * - Queues being used for RSS. |
| 7532 | * We don't need as many as max_rss_size vectors. |
| 7533 | * use rss_size instead in the calculation since that |
| 7534 | * is governed by number of cpus in the system. |
| 7535 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7536 | * - The number of VMDq pairs |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7537 | #ifdef I40E_FCOE |
| 7538 | * - The number of FCOE qps. |
| 7539 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7540 | * Once we count this up, try the request. |
| 7541 | * |
| 7542 | * If we can't get what we want, we'll simplify to nearly nothing |
| 7543 | * and try again. If that still fails, we punt. |
| 7544 | */ |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7545 | vectors_left = hw->func_caps.num_msix_vectors; |
| 7546 | v_budget = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7547 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7548 | /* reserve one vector for miscellaneous handler */ |
| 7549 | if (vectors_left) { |
| 7550 | v_budget++; |
| 7551 | vectors_left--; |
| 7552 | } |
| 7553 | |
| 7554 | /* reserve vectors for the main PF traffic queues */ |
| 7555 | pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left); |
| 7556 | vectors_left -= pf->num_lan_msix; |
| 7557 | v_budget += pf->num_lan_msix; |
| 7558 | |
| 7559 | /* reserve one vector for sideband flow director */ |
| 7560 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7561 | if (vectors_left) { |
| 7562 | v_budget++; |
| 7563 | vectors_left--; |
| 7564 | } else { |
| 7565 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 7566 | } |
| 7567 | } |
John W Linville | 83840e4 | 2015-01-14 03:06:28 +0000 | [diff] [blame] | 7568 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7569 | #ifdef I40E_FCOE |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7570 | /* can we reserve enough for FCoE? */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7571 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7572 | if (!vectors_left) |
| 7573 | pf->num_fcoe_msix = 0; |
| 7574 | else if (vectors_left >= pf->num_fcoe_qps) |
| 7575 | pf->num_fcoe_msix = pf->num_fcoe_qps; |
| 7576 | else |
| 7577 | pf->num_fcoe_msix = 1; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7578 | v_budget += pf->num_fcoe_msix; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7579 | vectors_left -= pf->num_fcoe_msix; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7580 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7581 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7582 | #endif |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7583 | /* any vectors left over go for VMDq support */ |
| 7584 | if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { |
| 7585 | int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; |
| 7586 | int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted); |
| 7587 | |
| 7588 | /* if we're short on vectors for what's desired, we limit |
| 7589 | * the queues per vmdq. If this is still more than are |
| 7590 | * available, the user will need to change the number of |
| 7591 | * queues/vectors used by the PF later with the ethtool |
| 7592 | * channels command |
| 7593 | */ |
| 7594 | if (vmdq_vecs < vmdq_vecs_wanted) |
| 7595 | pf->num_vmdq_qps = 1; |
| 7596 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
| 7597 | |
| 7598 | v_budget += vmdq_vecs; |
| 7599 | vectors_left -= vmdq_vecs; |
| 7600 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7601 | |
| 7602 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 7603 | GFP_KERNEL); |
| 7604 | if (!pf->msix_entries) |
| 7605 | return -ENOMEM; |
| 7606 | |
| 7607 | for (i = 0; i < v_budget; i++) |
| 7608 | pf->msix_entries[i].entry = i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7609 | v_actual = i40e_reserve_msix_vectors(pf, v_budget); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7610 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7611 | if (v_actual != v_budget) { |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7612 | /* If we have limited resources, we will start with no vectors |
| 7613 | * for the special features and then allocate vectors to some |
| 7614 | * of these features based on the policy and at the end disable |
| 7615 | * the features that did not get any vectors. |
| 7616 | */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7617 | #ifdef I40E_FCOE |
| 7618 | pf->num_fcoe_qps = 0; |
| 7619 | pf->num_fcoe_msix = 0; |
| 7620 | #endif |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7621 | pf->num_vmdq_msix = 0; |
| 7622 | } |
| 7623 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7624 | if (v_actual < I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7625 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 7626 | kfree(pf->msix_entries); |
| 7627 | pf->msix_entries = NULL; |
| 7628 | return -ENODEV; |
| 7629 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7630 | } else if (v_actual == I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7631 | /* Adjust for minimal MSIX use */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7632 | pf->num_vmdq_vsis = 0; |
| 7633 | pf->num_vmdq_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7634 | pf->num_lan_qps = 1; |
| 7635 | pf->num_lan_msix = 1; |
| 7636 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7637 | } else if (v_actual != v_budget) { |
| 7638 | int vec; |
| 7639 | |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7640 | /* reserve the misc vector */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7641 | vec = v_actual - 1; |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7642 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7643 | /* Scale vector usage down */ |
| 7644 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7645 | pf->num_vmdq_vsis = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7646 | pf->num_vmdq_qps = 1; |
| 7647 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7648 | |
| 7649 | /* partition out the remaining vectors */ |
| 7650 | switch (vec) { |
| 7651 | case 2: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7652 | pf->num_lan_msix = 1; |
| 7653 | break; |
| 7654 | case 3: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7655 | #ifdef I40E_FCOE |
| 7656 | /* give one vector to FCoE */ |
| 7657 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7658 | pf->num_lan_msix = 1; |
| 7659 | pf->num_fcoe_msix = 1; |
| 7660 | } |
| 7661 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7662 | pf->num_lan_msix = 2; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7663 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7664 | break; |
| 7665 | default: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7666 | #ifdef I40E_FCOE |
| 7667 | /* give one vector to FCoE */ |
| 7668 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7669 | pf->num_fcoe_msix = 1; |
| 7670 | vec--; |
| 7671 | } |
| 7672 | #endif |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7673 | /* give the rest to the PF */ |
| 7674 | pf->num_lan_msix = min_t(int, vec, pf->num_lan_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7675 | break; |
| 7676 | } |
| 7677 | } |
| 7678 | |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7679 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 7680 | (pf->num_vmdq_msix == 0)) { |
| 7681 | dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); |
| 7682 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 7683 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7684 | #ifdef I40E_FCOE |
| 7685 | |
| 7686 | if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) { |
| 7687 | dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n"); |
| 7688 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 7689 | } |
| 7690 | #endif |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7691 | return v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7692 | } |
| 7693 | |
| 7694 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7695 | * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7696 | * @vsi: the VSI being configured |
| 7697 | * @v_idx: index of the vector in the vsi struct |
| 7698 | * |
| 7699 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 7700 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7701 | static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7702 | { |
| 7703 | struct i40e_q_vector *q_vector; |
| 7704 | |
| 7705 | /* allocate q_vector */ |
| 7706 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 7707 | if (!q_vector) |
| 7708 | return -ENOMEM; |
| 7709 | |
| 7710 | q_vector->vsi = vsi; |
| 7711 | q_vector->v_idx = v_idx; |
| 7712 | cpumask_set_cpu(v_idx, &q_vector->affinity_mask); |
| 7713 | if (vsi->netdev) |
| 7714 | netif_napi_add(vsi->netdev, &q_vector->napi, |
Jesse Brandeburg | eefeace | 2014-05-10 04:49:13 +0000 | [diff] [blame] | 7715 | i40e_napi_poll, NAPI_POLL_WEIGHT); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7716 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 7717 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 7718 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 7719 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7720 | /* tie q_vector and vsi together */ |
| 7721 | vsi->q_vectors[v_idx] = q_vector; |
| 7722 | |
| 7723 | return 0; |
| 7724 | } |
| 7725 | |
| 7726 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7727 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7728 | * @vsi: the VSI being configured |
| 7729 | * |
| 7730 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 7731 | * return -ENOMEM. |
| 7732 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7733 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7734 | { |
| 7735 | struct i40e_pf *pf = vsi->back; |
| 7736 | int v_idx, num_q_vectors; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7737 | int err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7738 | |
| 7739 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 7740 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7741 | num_q_vectors = vsi->num_q_vectors; |
| 7742 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 7743 | num_q_vectors = 1; |
| 7744 | else |
| 7745 | return -EINVAL; |
| 7746 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7747 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7748 | err = i40e_vsi_alloc_q_vector(vsi, v_idx); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7749 | if (err) |
| 7750 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7751 | } |
| 7752 | |
| 7753 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7754 | |
| 7755 | err_out: |
| 7756 | while (v_idx--) |
| 7757 | i40e_free_q_vector(vsi, v_idx); |
| 7758 | |
| 7759 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7760 | } |
| 7761 | |
| 7762 | /** |
| 7763 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 7764 | * @pf: board private structure to initialize |
| 7765 | **/ |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7766 | static int i40e_init_interrupt_scheme(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7767 | { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7768 | int vectors = 0; |
| 7769 | ssize_t size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7770 | |
| 7771 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7772 | vectors = i40e_init_msix(pf); |
| 7773 | if (vectors < 0) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7774 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7775 | #ifdef I40E_FCOE |
| 7776 | I40E_FLAG_FCOE_ENABLED | |
| 7777 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7778 | I40E_FLAG_RSS_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 7779 | I40E_FLAG_DCB_CAPABLE | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7780 | I40E_FLAG_SRIOV_ENABLED | |
| 7781 | I40E_FLAG_FD_SB_ENABLED | |
| 7782 | I40E_FLAG_FD_ATR_ENABLED | |
| 7783 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7784 | |
| 7785 | /* rework the queue expectations without MSIX */ |
| 7786 | i40e_determine_queue_usage(pf); |
| 7787 | } |
| 7788 | } |
| 7789 | |
| 7790 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 7791 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7792 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7793 | vectors = pci_enable_msi(pf->pdev); |
| 7794 | if (vectors < 0) { |
| 7795 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", |
| 7796 | vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7797 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 7798 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7799 | vectors = 1; /* one MSI or Legacy vector */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7800 | } |
| 7801 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 7802 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7803 | 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] | 7804 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7805 | /* set up vector assignment tracking */ |
| 7806 | size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors); |
| 7807 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7808 | if (!pf->irq_pile) { |
| 7809 | dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n"); |
| 7810 | return -ENOMEM; |
| 7811 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7812 | pf->irq_pile->num_entries = vectors; |
| 7813 | pf->irq_pile->search_hint = 0; |
| 7814 | |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7815 | /* track first vector for misc interrupts, ignore return */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7816 | (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] | 7817 | |
| 7818 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7819 | } |
| 7820 | |
| 7821 | /** |
| 7822 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 7823 | * @pf: board private structure |
| 7824 | * |
| 7825 | * This sets up the handler for MSIX 0, which is used to manage the |
| 7826 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 7827 | * when in MSI or Legacy interrupt mode. |
| 7828 | **/ |
| 7829 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 7830 | { |
| 7831 | struct i40e_hw *hw = &pf->hw; |
| 7832 | int err = 0; |
| 7833 | |
| 7834 | /* Only request the irq if this is the first time through, and |
| 7835 | * not when we're rebuilding after a Reset |
| 7836 | */ |
| 7837 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7838 | err = request_irq(pf->msix_entries[0].vector, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 7839 | i40e_intr, 0, pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7840 | if (err) { |
| 7841 | dev_info(&pf->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7842 | "request_irq for %s failed: %d\n", |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 7843 | pf->int_name, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7844 | return -EFAULT; |
| 7845 | } |
| 7846 | } |
| 7847 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 7848 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7849 | |
| 7850 | /* associate no queues to the misc vector */ |
| 7851 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 7852 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 7853 | |
| 7854 | i40e_flush(hw); |
| 7855 | |
| 7856 | i40e_irq_dynamic_enable_icr0(pf); |
| 7857 | |
| 7858 | return err; |
| 7859 | } |
| 7860 | |
| 7861 | /** |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7862 | * i40e_config_rss_aq - Prepare for RSS using AQ commands |
| 7863 | * @vsi: vsi structure |
| 7864 | * @seed: RSS hash seed |
| 7865 | **/ |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7866 | static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 7867 | u8 *lut, u16 lut_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7868 | { |
| 7869 | struct i40e_aqc_get_set_rss_key_data rss_key; |
| 7870 | struct i40e_pf *pf = vsi->back; |
| 7871 | struct i40e_hw *hw = &pf->hw; |
| 7872 | bool pf_lut = false; |
| 7873 | u8 *rss_lut; |
| 7874 | int ret, i; |
| 7875 | |
| 7876 | memset(&rss_key, 0, sizeof(rss_key)); |
| 7877 | memcpy(&rss_key, seed, sizeof(rss_key)); |
| 7878 | |
| 7879 | rss_lut = kzalloc(pf->rss_table_size, GFP_KERNEL); |
| 7880 | if (!rss_lut) |
| 7881 | return -ENOMEM; |
| 7882 | |
| 7883 | /* Populate the LUT with max no. of queues in round robin fashion */ |
| 7884 | for (i = 0; i < vsi->rss_table_size; i++) |
| 7885 | rss_lut[i] = i % vsi->rss_size; |
| 7886 | |
| 7887 | ret = i40e_aq_set_rss_key(hw, vsi->id, &rss_key); |
| 7888 | if (ret) { |
| 7889 | dev_info(&pf->pdev->dev, |
| 7890 | "Cannot set RSS key, err %s aq_err %s\n", |
| 7891 | i40e_stat_str(&pf->hw, ret), |
| 7892 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Anjali Singhai | 126b63d | 2015-08-24 13:26:53 -0700 | [diff] [blame] | 7893 | goto config_rss_aq_out; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7894 | } |
| 7895 | |
| 7896 | if (vsi->type == I40E_VSI_MAIN) |
| 7897 | pf_lut = true; |
| 7898 | |
| 7899 | ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, rss_lut, |
| 7900 | vsi->rss_table_size); |
| 7901 | if (ret) |
| 7902 | dev_info(&pf->pdev->dev, |
| 7903 | "Cannot set RSS lut, err %s aq_err %s\n", |
| 7904 | i40e_stat_str(&pf->hw, ret), |
| 7905 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 7906 | |
Anjali Singhai | 126b63d | 2015-08-24 13:26:53 -0700 | [diff] [blame] | 7907 | config_rss_aq_out: |
| 7908 | kfree(rss_lut); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7909 | return ret; |
| 7910 | } |
| 7911 | |
| 7912 | /** |
| 7913 | * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used |
| 7914 | * @vsi: VSI structure |
| 7915 | **/ |
| 7916 | static int i40e_vsi_config_rss(struct i40e_vsi *vsi) |
| 7917 | { |
| 7918 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
| 7919 | struct i40e_pf *pf = vsi->back; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7920 | u8 *lut; |
| 7921 | int ret; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7922 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7923 | if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)) |
| 7924 | return 0; |
| 7925 | |
| 7926 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 7927 | if (!lut) |
| 7928 | return -ENOMEM; |
| 7929 | |
| 7930 | i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7931 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 7932 | vsi->rss_size = min_t(int, pf->alloc_rss_size, vsi->num_queue_pairs); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7933 | ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size); |
| 7934 | kfree(lut); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 7935 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7936 | return ret; |
| 7937 | } |
| 7938 | |
| 7939 | /** |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 7940 | * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands |
| 7941 | * @vsi: Pointer to vsi structure |
| 7942 | * @seed: Buffter to store the hash keys |
| 7943 | * @lut: Buffer to store the lookup table entries |
| 7944 | * @lut_size: Size of buffer to store the lookup table entries |
| 7945 | * |
| 7946 | * Return 0 on success, negative on failure |
| 7947 | */ |
| 7948 | static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
| 7949 | u8 *lut, u16 lut_size) |
| 7950 | { |
| 7951 | struct i40e_pf *pf = vsi->back; |
| 7952 | struct i40e_hw *hw = &pf->hw; |
| 7953 | int ret = 0; |
| 7954 | |
| 7955 | if (seed) { |
| 7956 | ret = i40e_aq_get_rss_key(hw, vsi->id, |
| 7957 | (struct i40e_aqc_get_set_rss_key_data *)seed); |
| 7958 | if (ret) { |
| 7959 | dev_info(&pf->pdev->dev, |
| 7960 | "Cannot get RSS key, 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 | if (lut) { |
| 7969 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; |
| 7970 | |
| 7971 | ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
| 7972 | if (ret) { |
| 7973 | dev_info(&pf->pdev->dev, |
| 7974 | "Cannot get RSS lut, err %s aq_err %s\n", |
| 7975 | i40e_stat_str(&pf->hw, ret), |
| 7976 | i40e_aq_str(&pf->hw, |
| 7977 | pf->hw.aq.asq_last_status)); |
| 7978 | return ret; |
| 7979 | } |
| 7980 | } |
| 7981 | |
| 7982 | return ret; |
| 7983 | } |
| 7984 | |
| 7985 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 7986 | * i40e_config_rss_reg - Configure RSS keys and lut by writing registers |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 7987 | * @vsi: Pointer to vsi structure |
| 7988 | * @seed: RSS hash seed |
| 7989 | * @lut: Lookup table |
| 7990 | * @lut_size: Lookup table size |
| 7991 | * |
| 7992 | * Returns 0 on success, negative on failure |
| 7993 | **/ |
| 7994 | static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed, |
| 7995 | const u8 *lut, u16 lut_size) |
| 7996 | { |
| 7997 | struct i40e_pf *pf = vsi->back; |
| 7998 | struct i40e_hw *hw = &pf->hw; |
| 7999 | u8 i; |
| 8000 | |
| 8001 | /* Fill out hash function seed */ |
| 8002 | if (seed) { |
| 8003 | u32 *seed_dw = (u32 *)seed; |
| 8004 | |
| 8005 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
| 8006 | wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]); |
| 8007 | } |
| 8008 | |
| 8009 | if (lut) { |
| 8010 | u32 *lut_dw = (u32 *)lut; |
| 8011 | |
| 8012 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8013 | return -EINVAL; |
| 8014 | |
| 8015 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8016 | wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]); |
| 8017 | } |
| 8018 | i40e_flush(hw); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8019 | |
| 8020 | return 0; |
| 8021 | } |
| 8022 | |
| 8023 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8024 | * i40e_get_rss_reg - Get the RSS keys and lut by reading registers |
| 8025 | * @vsi: Pointer to VSI structure |
| 8026 | * @seed: Buffer to store the keys |
| 8027 | * @lut: Buffer to store the lookup table entries |
| 8028 | * @lut_size: Size of buffer to store the lookup table entries |
| 8029 | * |
| 8030 | * Returns 0 on success, negative on failure |
| 8031 | */ |
| 8032 | static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed, |
| 8033 | u8 *lut, u16 lut_size) |
| 8034 | { |
| 8035 | struct i40e_pf *pf = vsi->back; |
| 8036 | struct i40e_hw *hw = &pf->hw; |
| 8037 | u16 i; |
| 8038 | |
| 8039 | if (seed) { |
| 8040 | u32 *seed_dw = (u32 *)seed; |
| 8041 | |
| 8042 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
| 8043 | seed_dw[i] = rd32(hw, I40E_PFQF_HKEY(i)); |
| 8044 | } |
| 8045 | if (lut) { |
| 8046 | u32 *lut_dw = (u32 *)lut; |
| 8047 | |
| 8048 | if (lut_size != I40E_HLUT_ARRAY_SIZE) |
| 8049 | return -EINVAL; |
| 8050 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) |
| 8051 | lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i)); |
| 8052 | } |
| 8053 | |
| 8054 | return 0; |
| 8055 | } |
| 8056 | |
| 8057 | /** |
| 8058 | * i40e_config_rss - Configure RSS keys and lut |
| 8059 | * @vsi: Pointer to VSI structure |
| 8060 | * @seed: RSS hash seed |
| 8061 | * @lut: Lookup table |
| 8062 | * @lut_size: Lookup table size |
| 8063 | * |
| 8064 | * Returns 0 on success, negative on failure |
| 8065 | */ |
| 8066 | int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8067 | { |
| 8068 | struct i40e_pf *pf = vsi->back; |
| 8069 | |
| 8070 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8071 | return i40e_config_rss_aq(vsi, seed, lut, lut_size); |
| 8072 | else |
| 8073 | return i40e_config_rss_reg(vsi, seed, lut, lut_size); |
| 8074 | } |
| 8075 | |
| 8076 | /** |
| 8077 | * i40e_get_rss - Get RSS keys and lut |
| 8078 | * @vsi: Pointer to VSI structure |
| 8079 | * @seed: Buffer to store the keys |
| 8080 | * @lut: Buffer to store the lookup table entries |
| 8081 | * lut_size: Size of buffer to store the lookup table entries |
| 8082 | * |
| 8083 | * Returns 0 on success, negative on failure |
| 8084 | */ |
| 8085 | int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) |
| 8086 | { |
Anjali Singhai Jain | 95a7378 | 2015-12-22 14:25:04 -0800 | [diff] [blame] | 8087 | struct i40e_pf *pf = vsi->back; |
| 8088 | |
| 8089 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) |
| 8090 | return i40e_get_rss_aq(vsi, seed, lut, lut_size); |
| 8091 | else |
| 8092 | return i40e_get_rss_reg(vsi, seed, lut, lut_size); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8093 | } |
| 8094 | |
| 8095 | /** |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8096 | * i40e_fill_rss_lut - Fill the RSS lookup table with default values |
| 8097 | * @pf: Pointer to board private structure |
| 8098 | * @lut: Lookup table |
| 8099 | * @rss_table_size: Lookup table size |
| 8100 | * @rss_size: Range of queue number for hashing |
| 8101 | */ |
| 8102 | static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
| 8103 | u16 rss_table_size, u16 rss_size) |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8104 | { |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8105 | u16 i; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8106 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8107 | for (i = 0; i < rss_table_size; i++) |
| 8108 | lut[i] = i % rss_size; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8109 | } |
| 8110 | |
| 8111 | /** |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8112 | * i40e_pf_config_rss - Prepare for RSS if used |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8113 | * @pf: board private structure |
| 8114 | **/ |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8115 | static int i40e_pf_config_rss(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8116 | { |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 8117 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8118 | u8 seed[I40E_HKEY_ARRAY_SIZE]; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8119 | u8 *lut; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 8120 | struct i40e_hw *hw = &pf->hw; |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8121 | u32 reg_val; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8122 | u64 hena; |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8123 | int ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8124 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8125 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
| 8126 | hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) | |
| 8127 | ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8128 | hena |= i40e_pf_get_default_rss_hena(pf); |
| 8129 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8130 | wr32(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 8131 | wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
| 8132 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8133 | /* Determine the RSS table size based on the hardware capabilities */ |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8134 | reg_val = rd32(hw, I40E_PFQF_CTL_0); |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8135 | reg_val = (pf->rss_table_size == 512) ? |
| 8136 | (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) : |
| 8137 | (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512); |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 8138 | wr32(hw, I40E_PFQF_CTL_0, reg_val); |
| 8139 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8140 | /* Determine the RSS size of the VSI */ |
| 8141 | if (!vsi->rss_size) |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8142 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8143 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8144 | |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8145 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
| 8146 | if (!lut) |
| 8147 | return -ENOMEM; |
| 8148 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8149 | /* Use user configured lut if there is one, otherwise use default */ |
| 8150 | if (vsi->rss_lut_user) |
| 8151 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); |
| 8152 | else |
| 8153 | 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] | 8154 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8155 | /* Use user configured hash key if there is one, otherwise |
| 8156 | * use default. |
| 8157 | */ |
| 8158 | if (vsi->rss_hkey_user) |
| 8159 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); |
| 8160 | else |
| 8161 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8162 | ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size); |
Helin Zhang | e69ff81 | 2015-10-21 19:56:22 -0400 | [diff] [blame] | 8163 | kfree(lut); |
| 8164 | |
| 8165 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8166 | } |
| 8167 | |
| 8168 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8169 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 8170 | * @pf: board private structure |
| 8171 | * @queue_count: the requested queue count for rss. |
| 8172 | * |
| 8173 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 8174 | * count which may be different from the requested queue count. |
| 8175 | **/ |
| 8176 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 8177 | { |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8178 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 8179 | int new_rss_size; |
| 8180 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8181 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 8182 | return 0; |
| 8183 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8184 | 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] | 8185 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 8186 | if (queue_count != vsi->num_queue_pairs) { |
| 8187 | vsi->req_queue_pairs = queue_count; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8188 | i40e_prep_for_reset(pf); |
| 8189 | |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8190 | pf->alloc_rss_size = new_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8191 | |
| 8192 | i40e_reset_and_rebuild(pf, true); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8193 | |
| 8194 | /* Discard the user configured hash keys and lut, if less |
| 8195 | * queues are enabled. |
| 8196 | */ |
| 8197 | if (queue_count < vsi->rss_size) { |
| 8198 | i40e_clear_rss_config_user(vsi); |
| 8199 | dev_dbg(&pf->pdev->dev, |
| 8200 | "discard user configured hash keys and lut\n"); |
| 8201 | } |
| 8202 | |
| 8203 | /* Reset vsi->rss_size, as number of enabled queues changed */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8204 | vsi->rss_size = min_t(int, pf->alloc_rss_size, |
| 8205 | vsi->num_queue_pairs); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 8206 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 8207 | i40e_pf_config_rss(pf); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8208 | } |
Helin Zhang | e36b0b1 | 2015-10-26 19:44:36 -0400 | [diff] [blame] | 8209 | dev_info(&pf->pdev->dev, "RSS count/HW max RSS count: %d/%d\n", |
| 8210 | pf->alloc_rss_size, pf->rss_size_max); |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8211 | return pf->alloc_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8212 | } |
| 8213 | |
| 8214 | /** |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8215 | * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition |
| 8216 | * @pf: board private structure |
| 8217 | **/ |
| 8218 | i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf) |
| 8219 | { |
| 8220 | i40e_status status; |
| 8221 | bool min_valid, max_valid; |
| 8222 | u32 max_bw, min_bw; |
| 8223 | |
| 8224 | status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw, |
| 8225 | &min_valid, &max_valid); |
| 8226 | |
| 8227 | if (!status) { |
| 8228 | if (min_valid) |
| 8229 | pf->npar_min_bw = min_bw; |
| 8230 | if (max_valid) |
| 8231 | pf->npar_max_bw = max_bw; |
| 8232 | } |
| 8233 | |
| 8234 | return status; |
| 8235 | } |
| 8236 | |
| 8237 | /** |
| 8238 | * i40e_set_npar_bw_setting - Set BW settings for this PF partition |
| 8239 | * @pf: board private structure |
| 8240 | **/ |
| 8241 | i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf) |
| 8242 | { |
| 8243 | struct i40e_aqc_configure_partition_bw_data bw_data; |
| 8244 | i40e_status status; |
| 8245 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8246 | /* Set the valid bit for this PF */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8247 | 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] | 8248 | bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK; |
| 8249 | bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK; |
| 8250 | |
| 8251 | /* Set the new bandwidths */ |
| 8252 | status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL); |
| 8253 | |
| 8254 | return status; |
| 8255 | } |
| 8256 | |
| 8257 | /** |
| 8258 | * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition |
| 8259 | * @pf: board private structure |
| 8260 | **/ |
| 8261 | i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf) |
| 8262 | { |
| 8263 | /* Commit temporary BW setting to permanent NVM image */ |
| 8264 | enum i40e_admin_queue_err last_aq_status; |
| 8265 | i40e_status ret; |
| 8266 | u16 nvm_word; |
| 8267 | |
| 8268 | if (pf->hw.partition_id != 1) { |
| 8269 | dev_info(&pf->pdev->dev, |
| 8270 | "Commit BW only works on partition 1! This is partition %d", |
| 8271 | pf->hw.partition_id); |
| 8272 | ret = I40E_NOT_SUPPORTED; |
| 8273 | goto bw_commit_out; |
| 8274 | } |
| 8275 | |
| 8276 | /* Acquire NVM for read access */ |
| 8277 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); |
| 8278 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8279 | if (ret) { |
| 8280 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8281 | "Cannot acquire NVM for read access, err %s aq_err %s\n", |
| 8282 | i40e_stat_str(&pf->hw, ret), |
| 8283 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8284 | goto bw_commit_out; |
| 8285 | } |
| 8286 | |
| 8287 | /* Read word 0x10 of NVM - SW compatibility word 1 */ |
| 8288 | ret = i40e_aq_read_nvm(&pf->hw, |
| 8289 | I40E_SR_NVM_CONTROL_WORD, |
| 8290 | 0x10, sizeof(nvm_word), &nvm_word, |
| 8291 | false, NULL); |
| 8292 | /* Save off last admin queue command status before releasing |
| 8293 | * the NVM |
| 8294 | */ |
| 8295 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8296 | i40e_release_nvm(&pf->hw); |
| 8297 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8298 | dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n", |
| 8299 | i40e_stat_str(&pf->hw, ret), |
| 8300 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8301 | goto bw_commit_out; |
| 8302 | } |
| 8303 | |
| 8304 | /* Wait a bit for NVM release to complete */ |
| 8305 | msleep(50); |
| 8306 | |
| 8307 | /* Acquire NVM for write access */ |
| 8308 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE); |
| 8309 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8310 | if (ret) { |
| 8311 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8312 | "Cannot acquire NVM for write access, err %s aq_err %s\n", |
| 8313 | i40e_stat_str(&pf->hw, ret), |
| 8314 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8315 | goto bw_commit_out; |
| 8316 | } |
| 8317 | /* Write it back out unchanged to initiate update NVM, |
| 8318 | * which will force a write of the shadow (alt) RAM to |
| 8319 | * the NVM - thus storing the bandwidth values permanently. |
| 8320 | */ |
| 8321 | ret = i40e_aq_update_nvm(&pf->hw, |
| 8322 | I40E_SR_NVM_CONTROL_WORD, |
| 8323 | 0x10, sizeof(nvm_word), |
| 8324 | &nvm_word, true, NULL); |
| 8325 | /* Save off last admin queue command status before releasing |
| 8326 | * the NVM |
| 8327 | */ |
| 8328 | last_aq_status = pf->hw.aq.asq_last_status; |
| 8329 | i40e_release_nvm(&pf->hw); |
| 8330 | if (ret) |
| 8331 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 8332 | "BW settings NOT SAVED, err %s aq_err %s\n", |
| 8333 | i40e_stat_str(&pf->hw, ret), |
| 8334 | i40e_aq_str(&pf->hw, last_aq_status)); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8335 | bw_commit_out: |
| 8336 | |
| 8337 | return ret; |
| 8338 | } |
| 8339 | |
| 8340 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8341 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 8342 | * @pf: board private structure to initialize |
| 8343 | * |
| 8344 | * i40e_sw_init initializes the Adapter private data structure. |
| 8345 | * Fields are initialized based on PCI device information and |
| 8346 | * OS network device settings (MTU size). |
| 8347 | **/ |
| 8348 | static int i40e_sw_init(struct i40e_pf *pf) |
| 8349 | { |
| 8350 | int err = 0; |
| 8351 | int size; |
| 8352 | |
| 8353 | pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE, |
| 8354 | (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)); |
Shannon Nelson | 2759997 | 2013-11-16 10:00:43 +0000 | [diff] [blame] | 8355 | pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8356 | if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) { |
| 8357 | if (I40E_DEBUG_USER & debug) |
| 8358 | pf->hw.debug_mask = debug; |
| 8359 | pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER), |
| 8360 | I40E_DEFAULT_MSG_ENABLE); |
| 8361 | } |
| 8362 | |
| 8363 | /* Set default capability flags */ |
| 8364 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 8365 | I40E_FLAG_MSI_ENABLED | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 8366 | I40E_FLAG_LINK_POLLING_ENABLED | |
Mitch Williams | 2bc7ee8 | 2015-02-06 08:52:11 +0000 | [diff] [blame] | 8367 | I40E_FLAG_MSIX_ENABLED; |
| 8368 | |
| 8369 | if (iommu_present(&pci_bus_type)) |
| 8370 | pf->flags |= I40E_FLAG_RX_PS_ENABLED; |
| 8371 | else |
| 8372 | pf->flags |= I40E_FLAG_RX_1BUF_ENABLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8373 | |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 8374 | /* Set default ITR */ |
| 8375 | pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF; |
| 8376 | pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF; |
| 8377 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8378 | /* Depending on PF configurations, it is possible that the RSS |
| 8379 | * maximum might end up larger than the available queues |
| 8380 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8381 | 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] | 8382 | pf->alloc_rss_size = 1; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 8383 | pf->rss_table_size = pf->hw.func_caps.rss_table_size; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8384 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 8385 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8386 | if (pf->hw.func_caps.rss) { |
| 8387 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 8388 | pf->alloc_rss_size = min_t(int, pf->rss_size_max, |
| 8389 | num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8390 | } |
| 8391 | |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8392 | /* MFP mode enabled */ |
Pawel Orlowski | c78b953 | 2015-04-22 19:34:06 -0400 | [diff] [blame] | 8393 | 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] | 8394 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 8395 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 8396 | if (i40e_get_npar_bw_setting(pf)) |
| 8397 | dev_warn(&pf->pdev->dev, |
| 8398 | "Could not get NPAR bw settings\n"); |
| 8399 | else |
| 8400 | dev_info(&pf->pdev->dev, |
| 8401 | "Min BW = %8.8x, Max BW = %8.8x\n", |
| 8402 | pf->npar_min_bw, pf->npar_max_bw); |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 8403 | } |
| 8404 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8405 | /* FW/NVM is not yet fixed in this regard */ |
| 8406 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 8407 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 8408 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 8409 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8410 | if (pf->flags & I40E_FLAG_MFP_ENABLED && |
| 8411 | pf->hw.num_partitions > 1) |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8412 | dev_info(&pf->pdev->dev, |
Anjali Singhai Jain | 0b67584 | 2014-03-06 08:59:51 +0000 | [diff] [blame] | 8413 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
Shannon Nelson | 6eae9c6 | 2015-09-03 17:18:55 -0400 | [diff] [blame] | 8414 | else |
| 8415 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8416 | pf->fdir_pf_filter_count = |
| 8417 | pf->hw.func_caps.fd_filters_guaranteed; |
| 8418 | pf->hw.fdir_shared_filter_count = |
| 8419 | pf->hw.func_caps.fd_filters_best_effort; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8420 | } |
| 8421 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 8422 | if (((pf->hw.mac.type == I40E_MAC_X710) || |
| 8423 | (pf->hw.mac.type == I40E_MAC_XL710)) && |
| 8424 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) || |
| 8425 | (pf->hw.aq.fw_maj_ver < 4))) |
| 8426 | pf->flags |= I40E_FLAG_RESTART_AUTONEG; |
| 8427 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8428 | if (pf->hw.func_caps.vmdq) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8429 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 8430 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
Jesse Brandeburg | e9e5366 | 2015-10-02 17:57:21 -0700 | [diff] [blame] | 8431 | pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8432 | } |
| 8433 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8434 | #ifdef I40E_FCOE |
Shannon Nelson | 21364bc | 2015-08-26 15:14:13 -0400 | [diff] [blame] | 8435 | i40e_init_pf_fcoe(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8436 | |
| 8437 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8438 | #ifdef CONFIG_PCI_IOV |
Shannon Nelson | ba252f13 | 2014-12-11 07:06:34 +0000 | [diff] [blame] | 8439 | if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8440 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 8441 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 8442 | pf->num_req_vfs = min_t(int, |
| 8443 | pf->hw.func_caps.num_vfs, |
| 8444 | I40E_MAX_VF_COUNT); |
| 8445 | } |
| 8446 | #endif /* CONFIG_PCI_IOV */ |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8447 | if (pf->hw.mac.type == I40E_MAC_X722) { |
| 8448 | pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE | |
| 8449 | I40E_FLAG_128_QP_RSS_CAPABLE | |
| 8450 | I40E_FLAG_HW_ATR_EVICT_CAPABLE | |
| 8451 | I40E_FLAG_OUTER_UDP_CSUM_CAPABLE | |
| 8452 | I40E_FLAG_WB_ON_ITR_CAPABLE | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8453 | I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE | |
| 8454 | I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Anjali Singhai Jain | d502ce0 | 2015-06-05 12:20:26 -0400 | [diff] [blame] | 8455 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8456 | pf->eeprom_version = 0xDEAD; |
| 8457 | pf->lan_veb = I40E_NO_VEB; |
| 8458 | pf->lan_vsi = I40E_NO_VSI; |
| 8459 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 8460 | /* By default FW has this off for performance reasons */ |
| 8461 | pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; |
| 8462 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8463 | /* set up queue assignment tracking */ |
| 8464 | size = sizeof(struct i40e_lump_tracking) |
| 8465 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 8466 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 8467 | if (!pf->qp_pile) { |
| 8468 | err = -ENOMEM; |
| 8469 | goto sw_init_done; |
| 8470 | } |
| 8471 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 8472 | pf->qp_pile->search_hint = 0; |
| 8473 | |
Anjali Singhai Jain | 327fe04 | 2014-06-04 01:23:26 +0000 | [diff] [blame] | 8474 | pf->tx_timeout_recovery_level = 1; |
| 8475 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8476 | mutex_init(&pf->switch_mutex); |
| 8477 | |
Greg Rose | c668a12 | 2015-02-26 16:10:39 +0000 | [diff] [blame] | 8478 | /* If NPAR is enabled nudge the Tx scheduler */ |
| 8479 | if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf))) |
| 8480 | i40e_set_npar_bw_setting(pf); |
| 8481 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8482 | sw_init_done: |
| 8483 | return err; |
| 8484 | } |
| 8485 | |
| 8486 | /** |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8487 | * i40e_set_ntuple - set the ntuple feature flag and take action |
| 8488 | * @pf: board private structure to initialize |
| 8489 | * @features: the feature set that the stack is suggesting |
| 8490 | * |
| 8491 | * returns a bool to indicate if reset needs to happen |
| 8492 | **/ |
| 8493 | bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features) |
| 8494 | { |
| 8495 | bool need_reset = false; |
| 8496 | |
| 8497 | /* Check if Flow Director n-tuple support was enabled or disabled. If |
| 8498 | * the state changed, we need to reset. |
| 8499 | */ |
| 8500 | if (features & NETIF_F_NTUPLE) { |
| 8501 | /* Enable filters and mark for reset */ |
| 8502 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 8503 | need_reset = true; |
| 8504 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
| 8505 | } else { |
| 8506 | /* turn off filters, mark for reset and clear SW filter list */ |
| 8507 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 8508 | need_reset = true; |
| 8509 | i40e_fdir_filter_exit(pf); |
| 8510 | } |
| 8511 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8512 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 8513 | /* reset fd counters */ |
| 8514 | pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0; |
| 8515 | pf->fdir_pf_active_filters = 0; |
| 8516 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 8517 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 8518 | dev_info(&pf->pdev->dev, "ATR re-enabled.\n"); |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 8519 | /* if ATR was auto disabled it can be re-enabled. */ |
| 8520 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 8521 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 8522 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8523 | } |
| 8524 | return need_reset; |
| 8525 | } |
| 8526 | |
| 8527 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8528 | * i40e_set_features - set the netdev feature flags |
| 8529 | * @netdev: ptr to the netdev being adjusted |
| 8530 | * @features: the feature set that the stack is suggesting |
| 8531 | **/ |
| 8532 | static int i40e_set_features(struct net_device *netdev, |
| 8533 | netdev_features_t features) |
| 8534 | { |
| 8535 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8536 | struct i40e_vsi *vsi = np->vsi; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8537 | struct i40e_pf *pf = vsi->back; |
| 8538 | bool need_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8539 | |
| 8540 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 8541 | i40e_vlan_stripping_enable(vsi); |
| 8542 | else |
| 8543 | i40e_vlan_stripping_disable(vsi); |
| 8544 | |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8545 | need_reset = i40e_set_ntuple(pf, features); |
| 8546 | |
| 8547 | if (need_reset) |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 8548 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 8549 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8550 | return 0; |
| 8551 | } |
| 8552 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8553 | #if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8554 | /** |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8555 | * 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] | 8556 | * @pf: board private structure |
| 8557 | * @port: The UDP port to look up |
| 8558 | * |
| 8559 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found |
| 8560 | **/ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8561 | 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] | 8562 | { |
| 8563 | u8 i; |
| 8564 | |
| 8565 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8566 | if (pf->udp_ports[i].index == port) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8567 | return i; |
| 8568 | } |
| 8569 | |
| 8570 | return i; |
| 8571 | } |
| 8572 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8573 | #endif |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8574 | |
| 8575 | #if IS_ENABLED(CONFIG_VXLAN) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8576 | /** |
| 8577 | * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up |
| 8578 | * @netdev: This physical port's netdev |
| 8579 | * @sa_family: Socket Family that VXLAN is notifying us about |
| 8580 | * @port: New UDP port number that VXLAN started listening to |
| 8581 | **/ |
| 8582 | static void i40e_add_vxlan_port(struct net_device *netdev, |
| 8583 | sa_family_t sa_family, __be16 port) |
| 8584 | { |
| 8585 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8586 | struct i40e_vsi *vsi = np->vsi; |
| 8587 | struct i40e_pf *pf = vsi->back; |
| 8588 | u8 next_idx; |
| 8589 | u8 idx; |
| 8590 | |
| 8591 | if (sa_family == AF_INET6) |
| 8592 | return; |
| 8593 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8594 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8595 | |
| 8596 | /* Check if port already exists */ |
| 8597 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8598 | netdev_info(netdev, "vxlan port %d already offloaded\n", |
| 8599 | ntohs(port)); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8600 | return; |
| 8601 | } |
| 8602 | |
| 8603 | /* Now check if there is space to add the new port */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8604 | next_idx = i40e_get_udp_port_idx(pf, 0); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8605 | |
| 8606 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8607 | netdev_info(netdev, "maximum number of vxlan UDP ports reached, not adding port %d\n", |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8608 | ntohs(port)); |
| 8609 | return; |
| 8610 | } |
| 8611 | |
| 8612 | /* New port: add it and mark its index in the bitmap */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8613 | pf->udp_ports[next_idx].index = port; |
| 8614 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN; |
| 8615 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 8616 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8617 | } |
| 8618 | |
| 8619 | /** |
| 8620 | * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away |
| 8621 | * @netdev: This physical port's netdev |
| 8622 | * @sa_family: Socket Family that VXLAN is notifying us about |
| 8623 | * @port: UDP port number that VXLAN stopped listening to |
| 8624 | **/ |
| 8625 | static void i40e_del_vxlan_port(struct net_device *netdev, |
| 8626 | sa_family_t sa_family, __be16 port) |
| 8627 | { |
| 8628 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8629 | struct i40e_vsi *vsi = np->vsi; |
| 8630 | struct i40e_pf *pf = vsi->back; |
| 8631 | u8 idx; |
| 8632 | |
| 8633 | if (sa_family == AF_INET6) |
| 8634 | return; |
| 8635 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8636 | idx = i40e_get_udp_port_idx(pf, port); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8637 | |
| 8638 | /* Check if port already exists */ |
| 8639 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8640 | /* if port exists, set it to 0 (mark for deletion) |
| 8641 | * and make it pending |
| 8642 | */ |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8643 | pf->udp_ports[idx].index = 0; |
| 8644 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
| 8645 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8646 | } else { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 8647 | netdev_warn(netdev, "vxlan port %d was not found, not deleting\n", |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8648 | ntohs(port)); |
| 8649 | } |
| 8650 | } |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8651 | #endif |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8652 | |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8653 | #if IS_ENABLED(CONFIG_GENEVE) |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8654 | /** |
| 8655 | * i40e_add_geneve_port - Get notifications about GENEVE ports that come up |
| 8656 | * @netdev: This physical port's netdev |
| 8657 | * @sa_family: Socket Family that GENEVE is notifying us about |
| 8658 | * @port: New UDP port number that GENEVE started listening to |
| 8659 | **/ |
| 8660 | static void i40e_add_geneve_port(struct net_device *netdev, |
| 8661 | sa_family_t sa_family, __be16 port) |
| 8662 | { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8663 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8664 | struct i40e_vsi *vsi = np->vsi; |
| 8665 | struct i40e_pf *pf = vsi->back; |
| 8666 | u8 next_idx; |
| 8667 | u8 idx; |
| 8668 | |
| 8669 | if (sa_family == AF_INET6) |
| 8670 | return; |
| 8671 | |
| 8672 | idx = i40e_get_udp_port_idx(pf, port); |
| 8673 | |
| 8674 | /* Check if port already exists */ |
| 8675 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8676 | netdev_info(netdev, "udp port %d already offloaded\n", |
| 8677 | ntohs(port)); |
| 8678 | return; |
| 8679 | } |
| 8680 | |
| 8681 | /* Now check if there is space to add the new port */ |
| 8682 | next_idx = i40e_get_udp_port_idx(pf, 0); |
| 8683 | |
| 8684 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8685 | netdev_info(netdev, "maximum number of UDP ports reached, not adding port %d\n", |
| 8686 | ntohs(port)); |
| 8687 | return; |
| 8688 | } |
| 8689 | |
| 8690 | /* New port: add it and mark its index in the bitmap */ |
| 8691 | pf->udp_ports[next_idx].index = port; |
| 8692 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE; |
| 8693 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
| 8694 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 8695 | |
| 8696 | dev_info(&pf->pdev->dev, "adding geneve port %d\n", ntohs(port)); |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8697 | } |
| 8698 | |
| 8699 | /** |
| 8700 | * i40e_del_geneve_port - Get notifications about GENEVE ports that go away |
| 8701 | * @netdev: This physical port's netdev |
| 8702 | * @sa_family: Socket Family that GENEVE is notifying us about |
| 8703 | * @port: UDP port number that GENEVE stopped listening to |
| 8704 | **/ |
| 8705 | static void i40e_del_geneve_port(struct net_device *netdev, |
| 8706 | sa_family_t sa_family, __be16 port) |
| 8707 | { |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8708 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8709 | struct i40e_vsi *vsi = np->vsi; |
| 8710 | struct i40e_pf *pf = vsi->back; |
| 8711 | u8 idx; |
| 8712 | |
| 8713 | if (sa_family == AF_INET6) |
| 8714 | return; |
| 8715 | |
| 8716 | idx = i40e_get_udp_port_idx(pf, port); |
| 8717 | |
| 8718 | /* Check if port already exists */ |
| 8719 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 8720 | /* if port exists, set it to 0 (mark for deletion) |
| 8721 | * and make it pending |
| 8722 | */ |
| 8723 | pf->udp_ports[idx].index = 0; |
| 8724 | pf->pending_udp_bitmap |= BIT_ULL(idx); |
| 8725 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; |
| 8726 | |
| 8727 | dev_info(&pf->pdev->dev, "deleting geneve port %d\n", |
| 8728 | ntohs(port)); |
| 8729 | } else { |
| 8730 | netdev_warn(netdev, "geneve port %d was not found, not deleting\n", |
| 8731 | ntohs(port)); |
| 8732 | } |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8733 | } |
Eric Dumazet | 5cae761 | 2016-01-20 19:53:02 -0800 | [diff] [blame] | 8734 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8735 | |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8736 | static int i40e_get_phys_port_id(struct net_device *netdev, |
Jiri Pirko | 02637fc | 2014-11-28 14:34:16 +0100 | [diff] [blame] | 8737 | struct netdev_phys_item_id *ppid) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8738 | { |
| 8739 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 8740 | struct i40e_pf *pf = np->vsi->back; |
| 8741 | struct i40e_hw *hw = &pf->hw; |
| 8742 | |
| 8743 | if (!(pf->flags & I40E_FLAG_PORT_ID_VALID)) |
| 8744 | return -EOPNOTSUPP; |
| 8745 | |
| 8746 | ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id)); |
| 8747 | memcpy(ppid->id, hw->mac.port_addr, ppid->id_len); |
| 8748 | |
| 8749 | return 0; |
| 8750 | } |
| 8751 | |
Jesse Brandeburg | 2f90ade | 2014-11-20 16:30:02 -0800 | [diff] [blame] | 8752 | /** |
| 8753 | * i40e_ndo_fdb_add - add an entry to the hardware database |
| 8754 | * @ndm: the input from the stack |
| 8755 | * @tb: pointer to array of nladdr (unused) |
| 8756 | * @dev: the net device pointer |
| 8757 | * @addr: the MAC address entry being added |
| 8758 | * @flags: instructions from stack about fdb operation |
| 8759 | */ |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8760 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 8761 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 8762 | const unsigned char *addr, u16 vid, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8763 | u16 flags) |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8764 | { |
| 8765 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8766 | struct i40e_pf *pf = np->vsi->back; |
| 8767 | int err = 0; |
| 8768 | |
| 8769 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) |
| 8770 | return -EOPNOTSUPP; |
| 8771 | |
Or Gerlitz | 65891fe | 2014-12-14 18:19:05 +0200 | [diff] [blame] | 8772 | if (vid) { |
| 8773 | pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name); |
| 8774 | return -EINVAL; |
| 8775 | } |
| 8776 | |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8777 | /* Hardware does not support aging addresses so if a |
| 8778 | * ndm_state is given only allow permanent addresses |
| 8779 | */ |
| 8780 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
| 8781 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 8782 | return -EINVAL; |
| 8783 | } |
| 8784 | |
| 8785 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) |
| 8786 | err = dev_uc_add_excl(dev, addr); |
| 8787 | else if (is_multicast_ether_addr(addr)) |
| 8788 | err = dev_mc_add_excl(dev, addr); |
| 8789 | else |
| 8790 | err = -EINVAL; |
| 8791 | |
| 8792 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 8793 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 8794 | err = 0; |
| 8795 | |
| 8796 | return err; |
| 8797 | } |
| 8798 | |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8799 | /** |
| 8800 | * i40e_ndo_bridge_setlink - Set the hardware bridge mode |
| 8801 | * @dev: the netdev being configured |
| 8802 | * @nlh: RTNL message |
| 8803 | * |
| 8804 | * Inserts a new hardware bridge if not already created and |
| 8805 | * enables the bridging mode requested (VEB or VEPA). If the |
| 8806 | * hardware bridge has already been inserted and the request |
| 8807 | * is to change the mode then that requires a PF reset to |
| 8808 | * allow rebuild of the components with required hardware |
| 8809 | * bridge mode enabled. |
| 8810 | **/ |
| 8811 | static int i40e_ndo_bridge_setlink(struct net_device *dev, |
Carolyn Wyborny | 9df70b6 | 2015-04-27 14:57:11 -0400 | [diff] [blame] | 8812 | struct nlmsghdr *nlh, |
| 8813 | u16 flags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8814 | { |
| 8815 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8816 | struct i40e_vsi *vsi = np->vsi; |
| 8817 | struct i40e_pf *pf = vsi->back; |
| 8818 | struct i40e_veb *veb = NULL; |
| 8819 | struct nlattr *attr, *br_spec; |
| 8820 | int i, rem; |
| 8821 | |
| 8822 | /* Only for PF VSI for now */ |
| 8823 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 8824 | return -EOPNOTSUPP; |
| 8825 | |
| 8826 | /* Find the HW bridge for PF VSI */ |
| 8827 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 8828 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 8829 | veb = pf->veb[i]; |
| 8830 | } |
| 8831 | |
| 8832 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 8833 | |
| 8834 | nla_for_each_nested(attr, br_spec, rem) { |
| 8835 | __u16 mode; |
| 8836 | |
| 8837 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 8838 | continue; |
| 8839 | |
| 8840 | mode = nla_get_u16(attr); |
| 8841 | if ((mode != BRIDGE_MODE_VEPA) && |
| 8842 | (mode != BRIDGE_MODE_VEB)) |
| 8843 | return -EINVAL; |
| 8844 | |
| 8845 | /* Insert a new HW bridge */ |
| 8846 | if (!veb) { |
| 8847 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 8848 | vsi->tc_config.enabled_tc); |
| 8849 | if (veb) { |
| 8850 | veb->bridge_mode = mode; |
| 8851 | i40e_config_bridge_mode(veb); |
| 8852 | } else { |
| 8853 | /* No Bridge HW offload available */ |
| 8854 | return -ENOENT; |
| 8855 | } |
| 8856 | break; |
| 8857 | } else if (mode != veb->bridge_mode) { |
| 8858 | /* Existing HW bridge but different mode needs reset */ |
| 8859 | veb->bridge_mode = mode; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 8860 | /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */ |
| 8861 | if (mode == BRIDGE_MODE_VEB) |
| 8862 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 8863 | else |
| 8864 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 8865 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8866 | break; |
| 8867 | } |
| 8868 | } |
| 8869 | |
| 8870 | return 0; |
| 8871 | } |
| 8872 | |
| 8873 | /** |
| 8874 | * i40e_ndo_bridge_getlink - Get the hardware bridge mode |
| 8875 | * @skb: skb buff |
| 8876 | * @pid: process id |
| 8877 | * @seq: RTNL message seq # |
| 8878 | * @dev: the netdev being configured |
| 8879 | * @filter_mask: unused |
Jesse Brandeburg | d4b2f9f | 2015-09-03 17:18:48 -0400 | [diff] [blame] | 8880 | * @nlflags: netlink flags passed in |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8881 | * |
| 8882 | * Return the mode in which the hardware bridge is operating in |
| 8883 | * i.e VEB or VEPA. |
| 8884 | **/ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8885 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 8886 | struct net_device *dev, |
Carolyn Wyborny | 9f4ffc4 | 2015-08-31 19:54:42 -0400 | [diff] [blame] | 8887 | u32 __always_unused filter_mask, |
| 8888 | int nlflags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8889 | { |
| 8890 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8891 | struct i40e_vsi *vsi = np->vsi; |
| 8892 | struct i40e_pf *pf = vsi->back; |
| 8893 | struct i40e_veb *veb = NULL; |
| 8894 | int i; |
| 8895 | |
| 8896 | /* Only for PF VSI for now */ |
| 8897 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 8898 | return -EOPNOTSUPP; |
| 8899 | |
| 8900 | /* Find the HW bridge for the PF VSI */ |
| 8901 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 8902 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 8903 | veb = pf->veb[i]; |
| 8904 | } |
| 8905 | |
| 8906 | if (!veb) |
| 8907 | return 0; |
| 8908 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 8909 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, |
Scott Feldman | 7d4f8d8 | 2015-06-22 00:27:17 -0700 | [diff] [blame] | 8910 | nlflags, 0, 0, filter_mask, NULL); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8911 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8912 | |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8913 | /* Hardware supports L4 tunnel length of 128B (=2^7) which includes |
| 8914 | * inner mac plus all inner ethertypes. |
| 8915 | */ |
| 8916 | #define I40E_MAX_TUNNEL_HDR_LEN 128 |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8917 | /** |
| 8918 | * i40e_features_check - Validate encapsulated packet conforms to limits |
| 8919 | * @skb: skb buff |
Jean Sacren | 2bc11c6 | 2015-09-19 05:08:43 -0600 | [diff] [blame] | 8920 | * @dev: This physical port's netdev |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8921 | * @features: Offload features that the stack believes apply |
| 8922 | **/ |
| 8923 | static netdev_features_t i40e_features_check(struct sk_buff *skb, |
| 8924 | struct net_device *dev, |
| 8925 | netdev_features_t features) |
| 8926 | { |
| 8927 | if (skb->encapsulation && |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8928 | ((skb_inner_network_header(skb) - skb_transport_header(skb)) > |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8929 | I40E_MAX_TUNNEL_HDR_LEN)) |
Tom Herbert | a188222 | 2015-12-14 11:19:43 -0800 | [diff] [blame] | 8930 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8931 | |
| 8932 | return features; |
| 8933 | } |
| 8934 | |
Shannon Nelson | 37a2973 | 2015-02-27 09:15:19 +0000 | [diff] [blame] | 8935 | static const struct net_device_ops i40e_netdev_ops = { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8936 | .ndo_open = i40e_open, |
| 8937 | .ndo_stop = i40e_close, |
| 8938 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 8939 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 8940 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 8941 | .ndo_validate_addr = eth_validate_addr, |
| 8942 | .ndo_set_mac_address = i40e_set_mac, |
| 8943 | .ndo_change_mtu = i40e_change_mtu, |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 8944 | .ndo_do_ioctl = i40e_ioctl, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8945 | .ndo_tx_timeout = i40e_tx_timeout, |
| 8946 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 8947 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 8948 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 8949 | .ndo_poll_controller = i40e_netpoll, |
| 8950 | #endif |
| 8951 | .ndo_setup_tc = i40e_setup_tc, |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8952 | #ifdef I40E_FCOE |
| 8953 | .ndo_fcoe_enable = i40e_fcoe_enable, |
| 8954 | .ndo_fcoe_disable = i40e_fcoe_disable, |
| 8955 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8956 | .ndo_set_features = i40e_set_features, |
| 8957 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 8958 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 8959 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8960 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 8961 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 8962 | .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk, |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8963 | #if IS_ENABLED(CONFIG_VXLAN) |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8964 | .ndo_add_vxlan_port = i40e_add_vxlan_port, |
| 8965 | .ndo_del_vxlan_port = i40e_del_vxlan_port, |
| 8966 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 8967 | #if IS_ENABLED(CONFIG_GENEVE) |
| 8968 | .ndo_add_geneve_port = i40e_add_geneve_port, |
| 8969 | .ndo_del_geneve_port = i40e_del_geneve_port, |
| 8970 | #endif |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8971 | .ndo_get_phys_port_id = i40e_get_phys_port_id, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8972 | .ndo_fdb_add = i40e_ndo_fdb_add, |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8973 | .ndo_features_check = i40e_features_check, |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8974 | .ndo_bridge_getlink = i40e_ndo_bridge_getlink, |
| 8975 | .ndo_bridge_setlink = i40e_ndo_bridge_setlink, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8976 | }; |
| 8977 | |
| 8978 | /** |
| 8979 | * i40e_config_netdev - Setup the netdev flags |
| 8980 | * @vsi: the VSI being configured |
| 8981 | * |
| 8982 | * Returns 0 on success, negative value on failure |
| 8983 | **/ |
| 8984 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 8985 | { |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 8986 | u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8987 | struct i40e_pf *pf = vsi->back; |
| 8988 | struct i40e_hw *hw = &pf->hw; |
| 8989 | struct i40e_netdev_priv *np; |
| 8990 | struct net_device *netdev; |
| 8991 | u8 mac_addr[ETH_ALEN]; |
| 8992 | int etherdev_size; |
| 8993 | |
| 8994 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8995 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8996 | if (!netdev) |
| 8997 | return -ENOMEM; |
| 8998 | |
| 8999 | vsi->netdev = netdev; |
| 9000 | np = netdev_priv(netdev); |
| 9001 | np->vsi = vsi; |
| 9002 | |
Jesse Brandeburg | 5afdaaa | 2015-12-10 11:38:50 -0800 | [diff] [blame] | 9003 | netdev->hw_enc_features |= NETIF_F_IP_CSUM | |
| 9004 | NETIF_F_GSO_UDP_TUNNEL | |
| 9005 | NETIF_F_GSO_GRE | |
| 9006 | NETIF_F_TSO | |
| 9007 | 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9008 | |
| 9009 | netdev->features = NETIF_F_SG | |
| 9010 | NETIF_F_IP_CSUM | |
Tom Herbert | 53692b1 | 2015-12-14 11:19:41 -0800 | [diff] [blame] | 9011 | NETIF_F_SCTP_CRC | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9012 | NETIF_F_HIGHDMA | |
| 9013 | NETIF_F_GSO_UDP_TUNNEL | |
Jesse Brandeburg | fec31ff | 2015-10-01 18:25:42 -0700 | [diff] [blame] | 9014 | NETIF_F_GSO_GRE | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9015 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9016 | NETIF_F_HW_VLAN_CTAG_RX | |
| 9017 | NETIF_F_HW_VLAN_CTAG_FILTER | |
| 9018 | NETIF_F_IPV6_CSUM | |
| 9019 | NETIF_F_TSO | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 9020 | NETIF_F_TSO_ECN | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9021 | NETIF_F_TSO6 | |
| 9022 | NETIF_F_RXCSUM | |
| 9023 | NETIF_F_RXHASH | |
| 9024 | 0; |
| 9025 | |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 9026 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 9027 | netdev->features |= NETIF_F_NTUPLE; |
| 9028 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9029 | /* copy netdev features into list of user selectable features */ |
| 9030 | netdev->hw_features |= netdev->features; |
| 9031 | |
| 9032 | if (vsi->type == I40E_VSI_MAIN) { |
| 9033 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9034 | ether_addr_copy(mac_addr, hw->mac.perm_addr); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 9035 | /* The following steps are necessary to prevent reception |
| 9036 | * of tagged packets - some older NVM configurations load a |
| 9037 | * default a MAC-VLAN filter that accepts any tagged packet |
| 9038 | * which must be replaced by a normal filter. |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 9039 | */ |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9040 | if (!i40e_rm_default_mac_filter(vsi, mac_addr)) { |
| 9041 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 9042 | i40e_add_filter(vsi, mac_addr, |
| 9043 | I40E_VLAN_ANY, false, true); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9044 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9045 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9046 | } else { |
| 9047 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ |
| 9048 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", |
| 9049 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 9050 | random_ether_addr(mac_addr); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9051 | |
| 9052 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9053 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9054 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9055 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9056 | |
| 9057 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 9058 | i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9059 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9060 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9061 | ether_addr_copy(netdev->dev_addr, mac_addr); |
| 9062 | ether_addr_copy(netdev->perm_addr, mac_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9063 | /* vlan gets same features (except vlan offload) |
| 9064 | * after any tweaks for specific VSI types |
| 9065 | */ |
| 9066 | netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX | |
| 9067 | NETIF_F_HW_VLAN_CTAG_RX | |
| 9068 | NETIF_F_HW_VLAN_CTAG_FILTER); |
| 9069 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 9070 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 9071 | /* Setup netdev TC information */ |
| 9072 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 9073 | |
| 9074 | netdev->netdev_ops = &i40e_netdev_ops; |
| 9075 | netdev->watchdog_timeo = 5 * HZ; |
| 9076 | i40e_set_ethtool_ops(netdev); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9077 | #ifdef I40E_FCOE |
| 9078 | i40e_fcoe_config_netdev(netdev, vsi); |
| 9079 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9080 | |
| 9081 | return 0; |
| 9082 | } |
| 9083 | |
| 9084 | /** |
| 9085 | * i40e_vsi_delete - Delete a VSI from the switch |
| 9086 | * @vsi: the VSI being removed |
| 9087 | * |
| 9088 | * Returns 0 on success, negative value on failure |
| 9089 | **/ |
| 9090 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 9091 | { |
| 9092 | /* remove default VSI is not allowed */ |
| 9093 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 9094 | return; |
| 9095 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9096 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9097 | } |
| 9098 | |
| 9099 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9100 | * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB |
| 9101 | * @vsi: the VSI being queried |
| 9102 | * |
| 9103 | * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode |
| 9104 | **/ |
| 9105 | int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi) |
| 9106 | { |
| 9107 | struct i40e_veb *veb; |
| 9108 | struct i40e_pf *pf = vsi->back; |
| 9109 | |
| 9110 | /* Uplink is not a bridge so default to VEB */ |
| 9111 | if (vsi->veb_idx == I40E_NO_VEB) |
| 9112 | return 1; |
| 9113 | |
| 9114 | veb = pf->veb[vsi->veb_idx]; |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9115 | if (!veb) { |
| 9116 | dev_info(&pf->pdev->dev, |
| 9117 | "There is no veb associated with the bridge\n"); |
| 9118 | return -ENOENT; |
| 9119 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9120 | |
Akeem G Abodunrin | 09603ea | 2015-10-01 14:37:36 -0400 | [diff] [blame] | 9121 | /* Uplink is a bridge in VEPA mode */ |
| 9122 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) { |
| 9123 | return 0; |
| 9124 | } else { |
| 9125 | /* Uplink is a bridge in VEB mode */ |
| 9126 | return 1; |
| 9127 | } |
| 9128 | |
| 9129 | /* VEPA is now default bridge, so return 0 */ |
| 9130 | return 0; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9131 | } |
| 9132 | |
| 9133 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9134 | * i40e_add_vsi - Add a VSI to the switch |
| 9135 | * @vsi: the VSI being configured |
| 9136 | * |
| 9137 | * This initializes a VSI context depending on the VSI type to be added and |
| 9138 | * passes it down to the add_vsi aq command. |
| 9139 | **/ |
| 9140 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 9141 | { |
| 9142 | int ret = -ENODEV; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9143 | u8 laa_macaddr[ETH_ALEN]; |
| 9144 | bool found_laa_mac_filter = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9145 | struct i40e_pf *pf = vsi->back; |
| 9146 | struct i40e_hw *hw = &pf->hw; |
| 9147 | struct i40e_vsi_context ctxt; |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9148 | struct i40e_mac_filter *f, *ftmp; |
| 9149 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9150 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 9151 | int f_count = 0; |
| 9152 | |
| 9153 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9154 | switch (vsi->type) { |
| 9155 | case I40E_VSI_MAIN: |
| 9156 | /* The PF's main VSI is already setup as part of the |
| 9157 | * device initialization, so we'll not bother with |
| 9158 | * the add_vsi call, but we will retrieve the current |
| 9159 | * VSI context. |
| 9160 | */ |
| 9161 | ctxt.seid = pf->main_vsi_seid; |
| 9162 | ctxt.pf_num = pf->hw.pf_id; |
| 9163 | ctxt.vf_num = 0; |
| 9164 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 9165 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 9166 | if (ret) { |
| 9167 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9168 | "couldn't get PF vsi config, err %s aq_err %s\n", |
| 9169 | i40e_stat_str(&pf->hw, ret), |
| 9170 | i40e_aq_str(&pf->hw, |
| 9171 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9172 | return -ENOENT; |
| 9173 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9174 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9175 | vsi->info.valid_sections = 0; |
| 9176 | |
| 9177 | vsi->seid = ctxt.seid; |
| 9178 | vsi->id = ctxt.vsi_number; |
| 9179 | |
| 9180 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 9181 | |
| 9182 | /* MFP mode setup queue map and update VSI */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9183 | if ((pf->flags & I40E_FLAG_MFP_ENABLED) && |
| 9184 | !(pf->hw.func_caps.iscsi)) { /* NIC type PF */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9185 | memset(&ctxt, 0, sizeof(ctxt)); |
| 9186 | ctxt.seid = pf->main_vsi_seid; |
| 9187 | ctxt.pf_num = pf->hw.pf_id; |
| 9188 | ctxt.vf_num = 0; |
| 9189 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 9190 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 9191 | if (ret) { |
| 9192 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9193 | "update vsi failed, err %s aq_err %s\n", |
| 9194 | i40e_stat_str(&pf->hw, ret), |
| 9195 | i40e_aq_str(&pf->hw, |
| 9196 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9197 | ret = -ENOENT; |
| 9198 | goto err; |
| 9199 | } |
| 9200 | /* update the local VSI info queue map */ |
| 9201 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 9202 | vsi->info.valid_sections = 0; |
| 9203 | } else { |
| 9204 | /* Default/Main VSI is only enabled for TC0 |
| 9205 | * reconfigure it to enable all TCs that are |
| 9206 | * available on the port in SFP mode. |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 9207 | * For MFP case the iSCSI PF would use this |
| 9208 | * flow to enable LAN+iSCSI TC. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9209 | */ |
| 9210 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 9211 | if (ret) { |
| 9212 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9213 | "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n", |
| 9214 | enabled_tc, |
| 9215 | i40e_stat_str(&pf->hw, ret), |
| 9216 | i40e_aq_str(&pf->hw, |
| 9217 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9218 | ret = -ENOENT; |
| 9219 | } |
| 9220 | } |
| 9221 | break; |
| 9222 | |
| 9223 | case I40E_VSI_FDIR: |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9224 | ctxt.pf_num = hw->pf_id; |
| 9225 | ctxt.vf_num = 0; |
| 9226 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9227 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9228 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9229 | if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) && |
| 9230 | (i40e_is_vsi_uplink_mode_veb(vsi))) { |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9231 | ctxt.info.valid_sections |= |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9232 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9233 | ctxt.info.switch_id = |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 9234 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9235 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9236 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9237 | break; |
| 9238 | |
| 9239 | case I40E_VSI_VMDQ2: |
| 9240 | ctxt.pf_num = hw->pf_id; |
| 9241 | ctxt.vf_num = 0; |
| 9242 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9243 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9244 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 9245 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9246 | /* This VSI is connected to VEB so the switch_id |
| 9247 | * should be set to zero by default. |
| 9248 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9249 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9250 | ctxt.info.valid_sections |= |
| 9251 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9252 | ctxt.info.switch_id = |
| 9253 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9254 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9255 | |
| 9256 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9257 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9258 | break; |
| 9259 | |
| 9260 | case I40E_VSI_SRIOV: |
| 9261 | ctxt.pf_num = hw->pf_id; |
| 9262 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 9263 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 9264 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9265 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 9266 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9267 | /* This VSI is connected to VEB so the switch_id |
| 9268 | * should be set to zero by default. |
| 9269 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9270 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 9271 | ctxt.info.valid_sections |= |
| 9272 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 9273 | ctxt.info.switch_id = |
| 9274 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 9275 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9276 | |
| 9277 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 9278 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 9279 | if (pf->vf[vsi->vf_id].spoofchk) { |
| 9280 | ctxt.info.valid_sections |= |
| 9281 | cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 9282 | ctxt.info.sec_flags |= |
| 9283 | (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 9284 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
| 9285 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9286 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 9287 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 9288 | break; |
| 9289 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9290 | #ifdef I40E_FCOE |
| 9291 | case I40E_VSI_FCOE: |
| 9292 | ret = i40e_fcoe_vsi_init(vsi, &ctxt); |
| 9293 | if (ret) { |
| 9294 | dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n"); |
| 9295 | return ret; |
| 9296 | } |
| 9297 | break; |
| 9298 | |
| 9299 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9300 | default: |
| 9301 | return -ENODEV; |
| 9302 | } |
| 9303 | |
| 9304 | if (vsi->type != I40E_VSI_MAIN) { |
| 9305 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 9306 | if (ret) { |
| 9307 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9308 | "add vsi failed, err %s aq_err %s\n", |
| 9309 | i40e_stat_str(&pf->hw, ret), |
| 9310 | i40e_aq_str(&pf->hw, |
| 9311 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9312 | ret = -ENOENT; |
| 9313 | goto err; |
| 9314 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 9315 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9316 | vsi->info.valid_sections = 0; |
| 9317 | vsi->seid = ctxt.seid; |
| 9318 | vsi->id = ctxt.vsi_number; |
| 9319 | } |
| 9320 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9321 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9322 | /* If macvlan filters already exist, force them to get loaded */ |
| 9323 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 9324 | f->changed = true; |
| 9325 | f_count++; |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 9326 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9327 | /* Expected to have only one MAC filter entry for LAA in list */ |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 9328 | if (f->is_laa && vsi->type == I40E_VSI_MAIN) { |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9329 | ether_addr_copy(laa_macaddr, f->macaddr); |
| 9330 | found_laa_mac_filter = true; |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 9331 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9332 | } |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9333 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9334 | |
| 9335 | if (found_laa_mac_filter) { |
| 9336 | struct i40e_aqc_remove_macvlan_element_data element; |
| 9337 | |
| 9338 | memset(&element, 0, sizeof(element)); |
| 9339 | ether_addr_copy(element.mac_addr, laa_macaddr); |
| 9340 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 9341 | ret = i40e_aq_remove_macvlan(hw, vsi->seid, |
| 9342 | &element, 1, NULL); |
| 9343 | if (ret) { |
| 9344 | /* some older FW has a different default */ |
| 9345 | element.flags |= |
| 9346 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
| 9347 | i40e_aq_remove_macvlan(hw, vsi->seid, |
| 9348 | &element, 1, NULL); |
| 9349 | } |
| 9350 | |
| 9351 | i40e_aq_mac_address_write(hw, |
| 9352 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 9353 | laa_macaddr, NULL); |
| 9354 | } |
| 9355 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9356 | if (f_count) { |
| 9357 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 9358 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 9359 | } |
| 9360 | |
| 9361 | /* Update VSI BW information */ |
| 9362 | ret = i40e_vsi_get_bw_info(vsi); |
| 9363 | if (ret) { |
| 9364 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9365 | "couldn't get vsi bw info, err %s aq_err %s\n", |
| 9366 | i40e_stat_str(&pf->hw, ret), |
| 9367 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9368 | /* VSI is already added so not tearing that up */ |
| 9369 | ret = 0; |
| 9370 | } |
| 9371 | |
| 9372 | err: |
| 9373 | return ret; |
| 9374 | } |
| 9375 | |
| 9376 | /** |
| 9377 | * i40e_vsi_release - Delete a VSI and free its resources |
| 9378 | * @vsi: the VSI being removed |
| 9379 | * |
| 9380 | * Returns 0 on success or < 0 on error |
| 9381 | **/ |
| 9382 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 9383 | { |
| 9384 | struct i40e_mac_filter *f, *ftmp; |
| 9385 | struct i40e_veb *veb = NULL; |
| 9386 | struct i40e_pf *pf; |
| 9387 | u16 uplink_seid; |
| 9388 | int i, n; |
| 9389 | |
| 9390 | pf = vsi->back; |
| 9391 | |
| 9392 | /* release of a VEB-owner or last VSI is not allowed */ |
| 9393 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 9394 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 9395 | vsi->seid, vsi->uplink_seid); |
| 9396 | return -ENODEV; |
| 9397 | } |
| 9398 | if (vsi == pf->vsi[pf->lan_vsi] && |
| 9399 | !test_bit(__I40E_DOWN, &pf->state)) { |
| 9400 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 9401 | return -ENODEV; |
| 9402 | } |
| 9403 | |
| 9404 | uplink_seid = vsi->uplink_seid; |
| 9405 | if (vsi->type != I40E_VSI_SRIOV) { |
| 9406 | if (vsi->netdev_registered) { |
| 9407 | vsi->netdev_registered = false; |
| 9408 | if (vsi->netdev) { |
| 9409 | /* results in a call to i40e_close() */ |
| 9410 | unregister_netdev(vsi->netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9411 | } |
| 9412 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 9413 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9414 | } |
| 9415 | i40e_vsi_disable_irq(vsi); |
| 9416 | } |
| 9417 | |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9418 | spin_lock_bh(&vsi->mac_filter_list_lock); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9419 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) |
| 9420 | i40e_del_filter(vsi, f->macaddr, f->vlan, |
| 9421 | f->is_vf, f->is_netdev); |
Kiran Patil | 2165903 | 2015-09-30 14:09:03 -0400 | [diff] [blame] | 9422 | spin_unlock_bh(&vsi->mac_filter_list_lock); |
| 9423 | |
Jesse Brandeburg | 17652c6 | 2015-11-05 17:01:02 -0800 | [diff] [blame] | 9424 | i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9425 | |
| 9426 | i40e_vsi_delete(vsi); |
| 9427 | i40e_vsi_free_q_vectors(vsi); |
Shannon Nelson | a486659 | 2014-02-11 08:24:07 +0000 | [diff] [blame] | 9428 | if (vsi->netdev) { |
| 9429 | free_netdev(vsi->netdev); |
| 9430 | vsi->netdev = NULL; |
| 9431 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9432 | i40e_vsi_clear_rings(vsi); |
| 9433 | i40e_vsi_clear(vsi); |
| 9434 | |
| 9435 | /* If this was the last thing on the VEB, except for the |
| 9436 | * controlling VSI, remove the VEB, which puts the controlling |
| 9437 | * VSI onto the next level down in the switch. |
| 9438 | * |
| 9439 | * Well, okay, there's one more exception here: don't remove |
| 9440 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 9441 | * from up the network stack. |
| 9442 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9443 | for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9444 | if (pf->vsi[i] && |
| 9445 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 9446 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 9447 | n++; /* count the VSIs */ |
| 9448 | } |
| 9449 | } |
| 9450 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9451 | if (!pf->veb[i]) |
| 9452 | continue; |
| 9453 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 9454 | n++; /* count the VEBs */ |
| 9455 | if (pf->veb[i]->seid == uplink_seid) |
| 9456 | veb = pf->veb[i]; |
| 9457 | } |
| 9458 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 9459 | i40e_veb_release(veb); |
| 9460 | |
| 9461 | return 0; |
| 9462 | } |
| 9463 | |
| 9464 | /** |
| 9465 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 9466 | * @vsi: ptr to the VSI |
| 9467 | * |
| 9468 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 9469 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 9470 | * newly allocated VSI. |
| 9471 | * |
| 9472 | * Returns 0 on success or negative on failure |
| 9473 | **/ |
| 9474 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 9475 | { |
| 9476 | int ret = -ENOENT; |
| 9477 | struct i40e_pf *pf = vsi->back; |
| 9478 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 9479 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9480 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 9481 | vsi->seid); |
| 9482 | return -EEXIST; |
| 9483 | } |
| 9484 | |
| 9485 | if (vsi->base_vector) { |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 9486 | 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] | 9487 | vsi->seid, vsi->base_vector); |
| 9488 | return -EEXIST; |
| 9489 | } |
| 9490 | |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 9491 | ret = i40e_vsi_alloc_q_vectors(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9492 | if (ret) { |
| 9493 | dev_info(&pf->pdev->dev, |
| 9494 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 9495 | vsi->num_q_vectors, vsi->seid, ret); |
| 9496 | vsi->num_q_vectors = 0; |
| 9497 | goto vector_setup_out; |
| 9498 | } |
| 9499 | |
Anjali Singhai Jain | 26cdc44 | 2015-07-10 19:36:00 -0400 | [diff] [blame] | 9500 | /* In Legacy mode, we do not have to get any other vector since we |
| 9501 | * piggyback on the misc/ICR0 for queue interrupts. |
| 9502 | */ |
| 9503 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 9504 | return ret; |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 9505 | if (vsi->num_q_vectors) |
| 9506 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 9507 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9508 | if (vsi->base_vector < 0) { |
| 9509 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9510 | "failed to get tracking for %d vectors for VSI %d, err=%d\n", |
| 9511 | vsi->num_q_vectors, vsi->seid, vsi->base_vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9512 | i40e_vsi_free_q_vectors(vsi); |
| 9513 | ret = -ENOENT; |
| 9514 | goto vector_setup_out; |
| 9515 | } |
| 9516 | |
| 9517 | vector_setup_out: |
| 9518 | return ret; |
| 9519 | } |
| 9520 | |
| 9521 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9522 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 9523 | * @vsi: pointer to the vsi. |
| 9524 | * |
| 9525 | * This re-allocates a vsi's queue resources. |
| 9526 | * |
| 9527 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 9528 | * on success, otherwise returns NULL on failure. |
| 9529 | **/ |
| 9530 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 9531 | { |
| 9532 | struct i40e_pf *pf = vsi->back; |
| 9533 | u8 enabled_tc; |
| 9534 | int ret; |
| 9535 | |
| 9536 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 9537 | i40e_vsi_clear_rings(vsi); |
| 9538 | |
| 9539 | i40e_vsi_free_arrays(vsi, false); |
| 9540 | i40e_set_num_rings_in_vsi(vsi); |
| 9541 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 9542 | if (ret) |
| 9543 | goto err_vsi; |
| 9544 | |
| 9545 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 9546 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9547 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9548 | "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] | 9549 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9550 | goto err_vsi; |
| 9551 | } |
| 9552 | vsi->base_queue = ret; |
| 9553 | |
| 9554 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 9555 | * layout configurations. |
| 9556 | */ |
| 9557 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 9558 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 9559 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 9560 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 9561 | |
| 9562 | /* assign it some queues */ |
| 9563 | ret = i40e_alloc_rings(vsi); |
| 9564 | if (ret) |
| 9565 | goto err_rings; |
| 9566 | |
| 9567 | /* map all of the rings to the q_vectors */ |
| 9568 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9569 | return vsi; |
| 9570 | |
| 9571 | err_rings: |
| 9572 | i40e_vsi_free_q_vectors(vsi); |
| 9573 | if (vsi->netdev_registered) { |
| 9574 | vsi->netdev_registered = false; |
| 9575 | unregister_netdev(vsi->netdev); |
| 9576 | free_netdev(vsi->netdev); |
| 9577 | vsi->netdev = NULL; |
| 9578 | } |
| 9579 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9580 | err_vsi: |
| 9581 | i40e_vsi_clear(vsi); |
| 9582 | return NULL; |
| 9583 | } |
| 9584 | |
| 9585 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 9586 | * i40e_macaddr_init - explicitly write the mac address filters. |
| 9587 | * |
| 9588 | * @vsi: pointer to the vsi. |
| 9589 | * @macaddr: the MAC address |
| 9590 | * |
| 9591 | * This is needed when the macaddr has been obtained by other |
| 9592 | * means than the default, e.g., from Open Firmware or IDPROM. |
| 9593 | * Returns 0 on success, negative on failure |
| 9594 | **/ |
| 9595 | static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr) |
| 9596 | { |
| 9597 | int ret; |
| 9598 | struct i40e_aqc_add_macvlan_element_data element; |
| 9599 | |
| 9600 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
| 9601 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 9602 | macaddr, NULL); |
| 9603 | if (ret) { |
| 9604 | dev_info(&vsi->back->pdev->dev, |
| 9605 | "Addr change for VSI failed: %d\n", ret); |
| 9606 | return -EADDRNOTAVAIL; |
| 9607 | } |
| 9608 | |
| 9609 | memset(&element, 0, sizeof(element)); |
| 9610 | ether_addr_copy(element.mac_addr, macaddr); |
| 9611 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 9612 | ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL); |
| 9613 | if (ret) { |
| 9614 | dev_info(&vsi->back->pdev->dev, |
| 9615 | "add filter failed err %s aq_err %s\n", |
| 9616 | i40e_stat_str(&vsi->back->hw, ret), |
| 9617 | i40e_aq_str(&vsi->back->hw, |
| 9618 | vsi->back->hw.aq.asq_last_status)); |
| 9619 | } |
| 9620 | return ret; |
| 9621 | } |
| 9622 | |
| 9623 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9624 | * i40e_vsi_setup - Set up a VSI by a given type |
| 9625 | * @pf: board private structure |
| 9626 | * @type: VSI type |
| 9627 | * @uplink_seid: the switch element to link to |
| 9628 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 9629 | * |
| 9630 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 9631 | * to the identified VEB. |
| 9632 | * |
| 9633 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 9634 | * success, otherwise returns NULL on failure. |
| 9635 | **/ |
| 9636 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 9637 | u16 uplink_seid, u32 param1) |
| 9638 | { |
| 9639 | struct i40e_vsi *vsi = NULL; |
| 9640 | struct i40e_veb *veb = NULL; |
| 9641 | int ret, i; |
| 9642 | int v_idx; |
| 9643 | |
| 9644 | /* The requested uplink_seid must be either |
| 9645 | * - the PF's port seid |
| 9646 | * no VEB is needed because this is the PF |
| 9647 | * or this is a Flow Director special case VSI |
| 9648 | * - seid of an existing VEB |
| 9649 | * - seid of a VSI that owns an existing VEB |
| 9650 | * - seid of a VSI that doesn't own a VEB |
| 9651 | * a new VEB is created and the VSI becomes the owner |
| 9652 | * - seid of the PF VSI, which is what creates the first VEB |
| 9653 | * this is a special case of the previous |
| 9654 | * |
| 9655 | * Find which uplink_seid we were given and create a new VEB if needed |
| 9656 | */ |
| 9657 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9658 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 9659 | veb = pf->veb[i]; |
| 9660 | break; |
| 9661 | } |
| 9662 | } |
| 9663 | |
| 9664 | if (!veb && uplink_seid != pf->mac_seid) { |
| 9665 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9666 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9667 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 9668 | vsi = pf->vsi[i]; |
| 9669 | break; |
| 9670 | } |
| 9671 | } |
| 9672 | if (!vsi) { |
| 9673 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 9674 | uplink_seid); |
| 9675 | return NULL; |
| 9676 | } |
| 9677 | |
| 9678 | if (vsi->uplink_seid == pf->mac_seid) |
| 9679 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 9680 | vsi->tc_config.enabled_tc); |
| 9681 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 9682 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 9683 | vsi->tc_config.enabled_tc); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9684 | if (veb) { |
| 9685 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) { |
| 9686 | dev_info(&vsi->back->pdev->dev, |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 9687 | "New VSI creation error, uplink seid of LAN VSI expected.\n"); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9688 | return NULL; |
| 9689 | } |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 9690 | /* We come up by default in VEPA mode if SRIOV is not |
| 9691 | * already enabled, in which case we can't force VEPA |
| 9692 | * mode. |
| 9693 | */ |
| 9694 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 9695 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
| 9696 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 9697 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 9698 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 9699 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9700 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 9701 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 9702 | veb = pf->veb[i]; |
| 9703 | } |
| 9704 | if (!veb) { |
| 9705 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 9706 | return NULL; |
| 9707 | } |
| 9708 | |
| 9709 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 9710 | uplink_seid = veb->seid; |
| 9711 | } |
| 9712 | |
| 9713 | /* get vsi sw struct */ |
| 9714 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 9715 | if (v_idx < 0) |
| 9716 | goto err_alloc; |
| 9717 | vsi = pf->vsi[v_idx]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9718 | if (!vsi) |
| 9719 | goto err_alloc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9720 | vsi->type = type; |
| 9721 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 9722 | |
| 9723 | if (type == I40E_VSI_MAIN) |
| 9724 | pf->lan_vsi = v_idx; |
| 9725 | else if (type == I40E_VSI_SRIOV) |
| 9726 | vsi->vf_id = param1; |
| 9727 | /* assign it some queues */ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9728 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, |
| 9729 | vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9730 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 9731 | dev_info(&pf->pdev->dev, |
| 9732 | "failed to get tracking for %d queues for VSI %d err=%d\n", |
| 9733 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9734 | goto err_vsi; |
| 9735 | } |
| 9736 | vsi->base_queue = ret; |
| 9737 | |
| 9738 | /* get a VSI from the hardware */ |
| 9739 | vsi->uplink_seid = uplink_seid; |
| 9740 | ret = i40e_add_vsi(vsi); |
| 9741 | if (ret) |
| 9742 | goto err_vsi; |
| 9743 | |
| 9744 | switch (vsi->type) { |
| 9745 | /* setup the netdev if needed */ |
| 9746 | case I40E_VSI_MAIN: |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 9747 | /* Apply relevant filters if a platform-specific mac |
| 9748 | * address was selected. |
| 9749 | */ |
| 9750 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { |
| 9751 | ret = i40e_macaddr_init(vsi, pf->hw.mac.addr); |
| 9752 | if (ret) { |
| 9753 | dev_warn(&pf->pdev->dev, |
| 9754 | "could not set up macaddr; err %d\n", |
| 9755 | ret); |
| 9756 | } |
| 9757 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9758 | case I40E_VSI_VMDQ2: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9759 | case I40E_VSI_FCOE: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9760 | ret = i40e_config_netdev(vsi); |
| 9761 | if (ret) |
| 9762 | goto err_netdev; |
| 9763 | ret = register_netdev(vsi->netdev); |
| 9764 | if (ret) |
| 9765 | goto err_netdev; |
| 9766 | vsi->netdev_registered = true; |
| 9767 | netif_carrier_off(vsi->netdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 9768 | #ifdef CONFIG_I40E_DCB |
| 9769 | /* Setup DCB netlink interface */ |
| 9770 | i40e_dcbnl_setup(vsi); |
| 9771 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9772 | /* fall through */ |
| 9773 | |
| 9774 | case I40E_VSI_FDIR: |
| 9775 | /* set up vectors and rings if needed */ |
| 9776 | ret = i40e_vsi_setup_vectors(vsi); |
| 9777 | if (ret) |
| 9778 | goto err_msix; |
| 9779 | |
| 9780 | ret = i40e_alloc_rings(vsi); |
| 9781 | if (ret) |
| 9782 | goto err_rings; |
| 9783 | |
| 9784 | /* map all of the rings to the q_vectors */ |
| 9785 | i40e_vsi_map_rings_to_vectors(vsi); |
| 9786 | |
| 9787 | i40e_vsi_reset_stats(vsi); |
| 9788 | break; |
| 9789 | |
| 9790 | default: |
| 9791 | /* no netdev or rings for the other VSI types */ |
| 9792 | break; |
| 9793 | } |
| 9794 | |
Anjali Singhai Jain | e25d00b | 2015-06-23 19:00:04 -0400 | [diff] [blame] | 9795 | if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) && |
| 9796 | (vsi->type == I40E_VSI_VMDQ2)) { |
| 9797 | ret = i40e_vsi_config_rss(vsi); |
| 9798 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9799 | return vsi; |
| 9800 | |
| 9801 | err_rings: |
| 9802 | i40e_vsi_free_q_vectors(vsi); |
| 9803 | err_msix: |
| 9804 | if (vsi->netdev_registered) { |
| 9805 | vsi->netdev_registered = false; |
| 9806 | unregister_netdev(vsi->netdev); |
| 9807 | free_netdev(vsi->netdev); |
| 9808 | vsi->netdev = NULL; |
| 9809 | } |
| 9810 | err_netdev: |
| 9811 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 9812 | err_vsi: |
| 9813 | i40e_vsi_clear(vsi); |
| 9814 | err_alloc: |
| 9815 | return NULL; |
| 9816 | } |
| 9817 | |
| 9818 | /** |
| 9819 | * i40e_veb_get_bw_info - Query VEB BW information |
| 9820 | * @veb: the veb to query |
| 9821 | * |
| 9822 | * Query the Tx scheduler BW configuration data for given VEB |
| 9823 | **/ |
| 9824 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 9825 | { |
| 9826 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 9827 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 9828 | struct i40e_pf *pf = veb->pf; |
| 9829 | struct i40e_hw *hw = &pf->hw; |
| 9830 | u32 tc_bw_max; |
| 9831 | int ret = 0; |
| 9832 | int i; |
| 9833 | |
| 9834 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 9835 | &bw_data, NULL); |
| 9836 | if (ret) { |
| 9837 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9838 | "query veb bw config failed, err %s aq_err %s\n", |
| 9839 | i40e_stat_str(&pf->hw, ret), |
| 9840 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9841 | goto out; |
| 9842 | } |
| 9843 | |
| 9844 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 9845 | &ets_data, NULL); |
| 9846 | if (ret) { |
| 9847 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 9848 | "query veb bw ets config failed, err %s aq_err %s\n", |
| 9849 | i40e_stat_str(&pf->hw, ret), |
| 9850 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9851 | goto out; |
| 9852 | } |
| 9853 | |
| 9854 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 9855 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 9856 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
Neerav Parikh | 23cd1f0 | 2014-11-12 00:18:41 +0000 | [diff] [blame] | 9857 | veb->enabled_tc = ets_data.tc_valid_bits; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9858 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 9859 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 9860 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 9861 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 9862 | veb->bw_tc_limit_credits[i] = |
| 9863 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 9864 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 9865 | } |
| 9866 | |
| 9867 | out: |
| 9868 | return ret; |
| 9869 | } |
| 9870 | |
| 9871 | /** |
| 9872 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 9873 | * @pf: board private structure |
| 9874 | * |
| 9875 | * On error: returns error code (negative) |
| 9876 | * On success: returns vsi index in PF (positive) |
| 9877 | **/ |
| 9878 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 9879 | { |
| 9880 | int ret = -ENOENT; |
| 9881 | struct i40e_veb *veb; |
| 9882 | int i; |
| 9883 | |
| 9884 | /* Need to protect the allocation of switch elements at the PF level */ |
| 9885 | mutex_lock(&pf->switch_mutex); |
| 9886 | |
| 9887 | /* VEB list may be fragmented if VEB creation/destruction has |
| 9888 | * been happening. We can afford to do a quick scan to look |
| 9889 | * for any free slots in the list. |
| 9890 | * |
| 9891 | * find next empty veb slot, looping back around if necessary |
| 9892 | */ |
| 9893 | i = 0; |
| 9894 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 9895 | i++; |
| 9896 | if (i >= I40E_MAX_VEB) { |
| 9897 | ret = -ENOMEM; |
| 9898 | goto err_alloc_veb; /* out of VEB slots! */ |
| 9899 | } |
| 9900 | |
| 9901 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 9902 | if (!veb) { |
| 9903 | ret = -ENOMEM; |
| 9904 | goto err_alloc_veb; |
| 9905 | } |
| 9906 | veb->pf = pf; |
| 9907 | veb->idx = i; |
| 9908 | veb->enabled_tc = 1; |
| 9909 | |
| 9910 | pf->veb[i] = veb; |
| 9911 | ret = i; |
| 9912 | err_alloc_veb: |
| 9913 | mutex_unlock(&pf->switch_mutex); |
| 9914 | return ret; |
| 9915 | } |
| 9916 | |
| 9917 | /** |
| 9918 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 9919 | * @branch: where to start deleting |
| 9920 | * |
| 9921 | * This uses recursion to find the tips of the branch to be |
| 9922 | * removed, deleting until we get back to and can delete this VEB. |
| 9923 | **/ |
| 9924 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 9925 | { |
| 9926 | struct i40e_pf *pf = branch->pf; |
| 9927 | u16 branch_seid = branch->seid; |
| 9928 | u16 veb_idx = branch->idx; |
| 9929 | int i; |
| 9930 | |
| 9931 | /* release any VEBs on this VEB - RECURSION */ |
| 9932 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9933 | if (!pf->veb[i]) |
| 9934 | continue; |
| 9935 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 9936 | i40e_switch_branch_release(pf->veb[i]); |
| 9937 | } |
| 9938 | |
| 9939 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 9940 | * |
| 9941 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 9942 | * the VEB itself, so don't use (*branch) after this loop. |
| 9943 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9944 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9945 | if (!pf->vsi[i]) |
| 9946 | continue; |
| 9947 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 9948 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 9949 | i40e_vsi_release(pf->vsi[i]); |
| 9950 | } |
| 9951 | } |
| 9952 | |
| 9953 | /* There's one corner case where the VEB might not have been |
| 9954 | * removed, so double check it here and remove it if needed. |
| 9955 | * This case happens if the veb was created from the debugfs |
| 9956 | * commands and no VSIs were added to it. |
| 9957 | */ |
| 9958 | if (pf->veb[veb_idx]) |
| 9959 | i40e_veb_release(pf->veb[veb_idx]); |
| 9960 | } |
| 9961 | |
| 9962 | /** |
| 9963 | * i40e_veb_clear - remove veb struct |
| 9964 | * @veb: the veb to remove |
| 9965 | **/ |
| 9966 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 9967 | { |
| 9968 | if (!veb) |
| 9969 | return; |
| 9970 | |
| 9971 | if (veb->pf) { |
| 9972 | struct i40e_pf *pf = veb->pf; |
| 9973 | |
| 9974 | mutex_lock(&pf->switch_mutex); |
| 9975 | if (pf->veb[veb->idx] == veb) |
| 9976 | pf->veb[veb->idx] = NULL; |
| 9977 | mutex_unlock(&pf->switch_mutex); |
| 9978 | } |
| 9979 | |
| 9980 | kfree(veb); |
| 9981 | } |
| 9982 | |
| 9983 | /** |
| 9984 | * i40e_veb_release - Delete a VEB and free its resources |
| 9985 | * @veb: the VEB being removed |
| 9986 | **/ |
| 9987 | void i40e_veb_release(struct i40e_veb *veb) |
| 9988 | { |
| 9989 | struct i40e_vsi *vsi = NULL; |
| 9990 | struct i40e_pf *pf; |
| 9991 | int i, n = 0; |
| 9992 | |
| 9993 | pf = veb->pf; |
| 9994 | |
| 9995 | /* find the remaining VSI and check for extras */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9996 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9997 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 9998 | n++; |
| 9999 | vsi = pf->vsi[i]; |
| 10000 | } |
| 10001 | } |
| 10002 | if (n != 1) { |
| 10003 | dev_info(&pf->pdev->dev, |
| 10004 | "can't remove VEB %d with %d VSIs left\n", |
| 10005 | veb->seid, n); |
| 10006 | return; |
| 10007 | } |
| 10008 | |
| 10009 | /* move the remaining VSI to uplink veb */ |
| 10010 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 10011 | if (veb->uplink_seid) { |
| 10012 | vsi->uplink_seid = veb->uplink_seid; |
| 10013 | if (veb->uplink_seid == pf->mac_seid) |
| 10014 | vsi->veb_idx = I40E_NO_VEB; |
| 10015 | else |
| 10016 | vsi->veb_idx = veb->veb_idx; |
| 10017 | } else { |
| 10018 | /* floating VEB */ |
| 10019 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 10020 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 10021 | } |
| 10022 | |
| 10023 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 10024 | i40e_veb_clear(veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10025 | } |
| 10026 | |
| 10027 | /** |
| 10028 | * i40e_add_veb - create the VEB in the switch |
| 10029 | * @veb: the VEB to be instantiated |
| 10030 | * @vsi: the controlling VSI |
| 10031 | **/ |
| 10032 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 10033 | { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10034 | struct i40e_pf *pf = veb->pf; |
Anjali Singhai Jain | 92faef8 | 2015-07-28 13:02:00 -0400 | [diff] [blame] | 10035 | bool is_default = veb->pf->cur_promisc; |
Kevin Scott | e1c51b95 | 2013-11-20 10:02:51 +0000 | [diff] [blame] | 10036 | bool is_cloud = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10037 | int ret; |
| 10038 | |
| 10039 | /* get a VEB from the hardware */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10040 | ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid, |
Kevin Scott | e1c51b95 | 2013-11-20 10:02:51 +0000 | [diff] [blame] | 10041 | veb->enabled_tc, is_default, |
| 10042 | is_cloud, &veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10043 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10044 | dev_info(&pf->pdev->dev, |
| 10045 | "couldn't add VEB, err %s aq_err %s\n", |
| 10046 | i40e_stat_str(&pf->hw, ret), |
| 10047 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10048 | return -EPERM; |
| 10049 | } |
| 10050 | |
| 10051 | /* get statistics counter */ |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10052 | ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10053 | &veb->stats_idx, NULL, NULL, NULL); |
| 10054 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10055 | dev_info(&pf->pdev->dev, |
| 10056 | "couldn't get VEB statistics idx, err %s aq_err %s\n", |
| 10057 | i40e_stat_str(&pf->hw, ret), |
| 10058 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10059 | return -EPERM; |
| 10060 | } |
| 10061 | ret = i40e_veb_get_bw_info(veb); |
| 10062 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10063 | dev_info(&pf->pdev->dev, |
| 10064 | "couldn't get VEB bw info, err %s aq_err %s\n", |
| 10065 | i40e_stat_str(&pf->hw, ret), |
| 10066 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 10067 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10068 | return -ENOENT; |
| 10069 | } |
| 10070 | |
| 10071 | vsi->uplink_seid = veb->seid; |
| 10072 | vsi->veb_idx = veb->idx; |
| 10073 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 10074 | |
| 10075 | return 0; |
| 10076 | } |
| 10077 | |
| 10078 | /** |
| 10079 | * i40e_veb_setup - Set up a VEB |
| 10080 | * @pf: board private structure |
| 10081 | * @flags: VEB setup flags |
| 10082 | * @uplink_seid: the switch element to link to |
| 10083 | * @vsi_seid: the initial VSI seid |
| 10084 | * @enabled_tc: Enabled TC bit-map |
| 10085 | * |
| 10086 | * This allocates the sw VEB structure and links it into the switch |
| 10087 | * It is possible and legal for this to be a duplicate of an already |
| 10088 | * existing VEB. It is also possible for both uplink and vsi seids |
| 10089 | * to be zero, in order to create a floating VEB. |
| 10090 | * |
| 10091 | * Returns pointer to the successfully allocated VEB sw struct on |
| 10092 | * success, otherwise returns NULL on failure. |
| 10093 | **/ |
| 10094 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 10095 | u16 uplink_seid, u16 vsi_seid, |
| 10096 | u8 enabled_tc) |
| 10097 | { |
| 10098 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 10099 | int vsi_idx, veb_idx; |
| 10100 | int ret; |
| 10101 | |
| 10102 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 10103 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 10104 | (uplink_seid + vsi_seid != 0)) { |
| 10105 | dev_info(&pf->pdev->dev, |
| 10106 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 10107 | uplink_seid, vsi_seid); |
| 10108 | return NULL; |
| 10109 | } |
| 10110 | |
| 10111 | /* make sure there is such a vsi and uplink */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10112 | for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10113 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 10114 | break; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10115 | if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10116 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 10117 | vsi_seid); |
| 10118 | return NULL; |
| 10119 | } |
| 10120 | |
| 10121 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 10122 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 10123 | if (pf->veb[veb_idx] && |
| 10124 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 10125 | uplink_veb = pf->veb[veb_idx]; |
| 10126 | break; |
| 10127 | } |
| 10128 | } |
| 10129 | if (!uplink_veb) { |
| 10130 | dev_info(&pf->pdev->dev, |
| 10131 | "uplink seid %d not found\n", uplink_seid); |
| 10132 | return NULL; |
| 10133 | } |
| 10134 | } |
| 10135 | |
| 10136 | /* get veb sw struct */ |
| 10137 | veb_idx = i40e_veb_mem_alloc(pf); |
| 10138 | if (veb_idx < 0) |
| 10139 | goto err_alloc; |
| 10140 | veb = pf->veb[veb_idx]; |
| 10141 | veb->flags = flags; |
| 10142 | veb->uplink_seid = uplink_seid; |
| 10143 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 10144 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 10145 | |
| 10146 | /* create the VEB in the switch */ |
| 10147 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 10148 | if (ret) |
| 10149 | goto err_veb; |
Shannon Nelson | 1bb8b93 | 2014-04-23 04:49:54 +0000 | [diff] [blame] | 10150 | if (vsi_idx == pf->lan_vsi) |
| 10151 | pf->lan_veb = veb->idx; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10152 | |
| 10153 | return veb; |
| 10154 | |
| 10155 | err_veb: |
| 10156 | i40e_veb_clear(veb); |
| 10157 | err_alloc: |
| 10158 | return NULL; |
| 10159 | } |
| 10160 | |
| 10161 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10162 | * i40e_setup_pf_switch_element - set PF vars based on switch type |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10163 | * @pf: board private structure |
| 10164 | * @ele: element we are building info from |
| 10165 | * @num_reported: total number of elements |
| 10166 | * @printconfig: should we print the contents |
| 10167 | * |
| 10168 | * helper function to assist in extracting a few useful SEID values. |
| 10169 | **/ |
| 10170 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 10171 | struct i40e_aqc_switch_config_element_resp *ele, |
| 10172 | u16 num_reported, bool printconfig) |
| 10173 | { |
| 10174 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 10175 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 10176 | u8 element_type = ele->element_type; |
| 10177 | u16 seid = le16_to_cpu(ele->seid); |
| 10178 | |
| 10179 | if (printconfig) |
| 10180 | dev_info(&pf->pdev->dev, |
| 10181 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 10182 | element_type, seid, uplink_seid, downlink_seid); |
| 10183 | |
| 10184 | switch (element_type) { |
| 10185 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 10186 | pf->mac_seid = seid; |
| 10187 | break; |
| 10188 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 10189 | /* Main VEB? */ |
| 10190 | if (uplink_seid != pf->mac_seid) |
| 10191 | break; |
| 10192 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10193 | int v; |
| 10194 | |
| 10195 | /* find existing or else empty VEB */ |
| 10196 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 10197 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 10198 | pf->lan_veb = v; |
| 10199 | break; |
| 10200 | } |
| 10201 | } |
| 10202 | if (pf->lan_veb == I40E_NO_VEB) { |
| 10203 | v = i40e_veb_mem_alloc(pf); |
| 10204 | if (v < 0) |
| 10205 | break; |
| 10206 | pf->lan_veb = v; |
| 10207 | } |
| 10208 | } |
| 10209 | |
| 10210 | pf->veb[pf->lan_veb]->seid = seid; |
| 10211 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 10212 | pf->veb[pf->lan_veb]->pf = pf; |
| 10213 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 10214 | break; |
| 10215 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 10216 | if (num_reported != 1) |
| 10217 | break; |
| 10218 | /* This is immediately after a reset so we can assume this is |
| 10219 | * the PF's VSI |
| 10220 | */ |
| 10221 | pf->mac_seid = uplink_seid; |
| 10222 | pf->pf_seid = downlink_seid; |
| 10223 | pf->main_vsi_seid = seid; |
| 10224 | if (printconfig) |
| 10225 | dev_info(&pf->pdev->dev, |
| 10226 | "pf_seid=%d main_vsi_seid=%d\n", |
| 10227 | pf->pf_seid, pf->main_vsi_seid); |
| 10228 | break; |
| 10229 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 10230 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 10231 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 10232 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 10233 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 10234 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 10235 | /* ignore these for now */ |
| 10236 | break; |
| 10237 | default: |
| 10238 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 10239 | element_type, seid); |
| 10240 | break; |
| 10241 | } |
| 10242 | } |
| 10243 | |
| 10244 | /** |
| 10245 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 10246 | * @pf: board private structure |
| 10247 | * @printconfig: should we print the contents |
| 10248 | * |
| 10249 | * Get the current switch configuration from the device and |
| 10250 | * extract a few useful SEID values. |
| 10251 | **/ |
| 10252 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 10253 | { |
| 10254 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 10255 | u16 next_seid = 0; |
| 10256 | int ret = 0; |
| 10257 | u8 *aq_buf; |
| 10258 | int i; |
| 10259 | |
| 10260 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 10261 | if (!aq_buf) |
| 10262 | return -ENOMEM; |
| 10263 | |
| 10264 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 10265 | do { |
| 10266 | u16 num_reported, num_total; |
| 10267 | |
| 10268 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 10269 | I40E_AQ_LARGE_BUF, |
| 10270 | &next_seid, NULL); |
| 10271 | if (ret) { |
| 10272 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10273 | "get switch config failed err %s aq_err %s\n", |
| 10274 | i40e_stat_str(&pf->hw, ret), |
| 10275 | i40e_aq_str(&pf->hw, |
| 10276 | pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10277 | kfree(aq_buf); |
| 10278 | return -ENOENT; |
| 10279 | } |
| 10280 | |
| 10281 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 10282 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 10283 | |
| 10284 | if (printconfig) |
| 10285 | dev_info(&pf->pdev->dev, |
| 10286 | "header: %d reported %d total\n", |
| 10287 | num_reported, num_total); |
| 10288 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10289 | for (i = 0; i < num_reported; i++) { |
| 10290 | struct i40e_aqc_switch_config_element_resp *ele = |
| 10291 | &sw_config->element[i]; |
| 10292 | |
| 10293 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 10294 | printconfig); |
| 10295 | } |
| 10296 | } while (next_seid != 0); |
| 10297 | |
| 10298 | kfree(aq_buf); |
| 10299 | return ret; |
| 10300 | } |
| 10301 | |
| 10302 | /** |
| 10303 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 10304 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10305 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10306 | * |
| 10307 | * Returns 0 on success, negative value on failure |
| 10308 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10309 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10310 | { |
| 10311 | int ret; |
| 10312 | |
| 10313 | /* find out what's out there already */ |
| 10314 | ret = i40e_fetch_switch_configuration(pf, false); |
| 10315 | if (ret) { |
| 10316 | dev_info(&pf->pdev->dev, |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10317 | "couldn't fetch switch config, err %s aq_err %s\n", |
| 10318 | i40e_stat_str(&pf->hw, ret), |
| 10319 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10320 | return ret; |
| 10321 | } |
| 10322 | i40e_pf_reset_stats(pf); |
| 10323 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10324 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10325 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10326 | struct i40e_vsi *vsi = NULL; |
| 10327 | u16 uplink_seid; |
| 10328 | |
| 10329 | /* Set up the PF VSI associated with the PF's main VSI |
| 10330 | * that is already in the HW switch |
| 10331 | */ |
| 10332 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 10333 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 10334 | else |
| 10335 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10336 | if (pf->lan_vsi == I40E_NO_VSI) |
| 10337 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 10338 | else if (reinit) |
| 10339 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10340 | if (!vsi) { |
| 10341 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 10342 | i40e_fdir_teardown(pf); |
| 10343 | return -EAGAIN; |
| 10344 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10345 | } else { |
| 10346 | /* force a reset of TC and queue layout configurations */ |
| 10347 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 10348 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10349 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 10350 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 10351 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 10352 | } |
| 10353 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 10354 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10355 | i40e_fdir_sb_setup(pf); |
| 10356 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10357 | /* Setup static PF queue filter control settings */ |
| 10358 | ret = i40e_setup_pf_filter_control(pf); |
| 10359 | if (ret) { |
| 10360 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 10361 | ret); |
| 10362 | /* Failure here should not stop continuing other steps */ |
| 10363 | } |
| 10364 | |
| 10365 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 10366 | * the hash |
| 10367 | */ |
| 10368 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 10369 | i40e_pf_config_rss(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10370 | |
| 10371 | /* fill in link information and enable LSE reporting */ |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 10372 | i40e_update_link_info(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10373 | i40e_link_event(pf); |
| 10374 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10375 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10376 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 10377 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10378 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 10379 | i40e_ptp_init(pf); |
| 10380 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10381 | return ret; |
| 10382 | } |
| 10383 | |
| 10384 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10385 | * i40e_determine_queue_usage - Work out queue distribution |
| 10386 | * @pf: board private structure |
| 10387 | **/ |
| 10388 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 10389 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10390 | int queues_left; |
| 10391 | |
| 10392 | pf->num_lan_qps = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10393 | #ifdef I40E_FCOE |
| 10394 | pf->num_fcoe_qps = 0; |
| 10395 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10396 | |
| 10397 | /* Find the max queues to be put into basic use. We'll always be |
| 10398 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 10399 | * big RSS set. |
| 10400 | */ |
| 10401 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 10402 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10403 | if ((queues_left == 1) || |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10404 | !(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10405 | /* one qp for PF, no queues for anything else */ |
| 10406 | queues_left = 0; |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10407 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10408 | |
| 10409 | /* make sure all the fancies are disabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10410 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10411 | #ifdef I40E_FCOE |
| 10412 | I40E_FLAG_FCOE_ENABLED | |
| 10413 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10414 | I40E_FLAG_FD_SB_ENABLED | |
| 10415 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10416 | I40E_FLAG_DCB_CAPABLE | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10417 | I40E_FLAG_SRIOV_ENABLED | |
| 10418 | I40E_FLAG_VMDQ_ENABLED); |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10419 | } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 10420 | I40E_FLAG_FD_SB_ENABLED | |
Anjali Singhai Jain | bbe7d0e | 2014-05-20 08:01:44 +0000 | [diff] [blame] | 10421 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10422 | I40E_FLAG_DCB_CAPABLE))) { |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10423 | /* one qp for PF */ |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10424 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10425 | queues_left -= pf->num_lan_qps; |
| 10426 | |
| 10427 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10428 | #ifdef I40E_FCOE |
| 10429 | I40E_FLAG_FCOE_ENABLED | |
| 10430 | #endif |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 10431 | I40E_FLAG_FD_SB_ENABLED | |
| 10432 | I40E_FLAG_FD_ATR_ENABLED | |
| 10433 | I40E_FLAG_DCB_ENABLED | |
| 10434 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10435 | } else { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10436 | /* Not enough queues for all TCs */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10437 | if ((pf->flags & I40E_FLAG_DCB_CAPABLE) && |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10438 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10439 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10440 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
| 10441 | } |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 10442 | pf->num_lan_qps = max_t(int, pf->rss_size_max, |
| 10443 | num_online_cpus()); |
| 10444 | pf->num_lan_qps = min_t(int, pf->num_lan_qps, |
| 10445 | pf->hw.func_caps.num_tx_qp); |
| 10446 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10447 | queues_left -= pf->num_lan_qps; |
| 10448 | } |
| 10449 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10450 | #ifdef I40E_FCOE |
| 10451 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 10452 | if (I40E_DEFAULT_FCOE <= queues_left) { |
| 10453 | pf->num_fcoe_qps = I40E_DEFAULT_FCOE; |
| 10454 | } else if (I40E_MINIMUM_FCOE <= queues_left) { |
| 10455 | pf->num_fcoe_qps = I40E_MINIMUM_FCOE; |
| 10456 | } else { |
| 10457 | pf->num_fcoe_qps = 0; |
| 10458 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 10459 | dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n"); |
| 10460 | } |
| 10461 | |
| 10462 | queues_left -= pf->num_fcoe_qps; |
| 10463 | } |
| 10464 | |
| 10465 | #endif |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10466 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 10467 | if (queues_left > 1) { |
| 10468 | queues_left -= 1; /* save 1 queue for FD */ |
| 10469 | } else { |
| 10470 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 10471 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); |
| 10472 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10473 | } |
| 10474 | |
| 10475 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 10476 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 10477 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
| 10478 | (queues_left / pf->num_vf_qps)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10479 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 10480 | } |
| 10481 | |
| 10482 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 10483 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 10484 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 10485 | (queues_left / pf->num_vmdq_qps)); |
| 10486 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 10487 | } |
| 10488 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 10489 | pf->queues_left = queues_left; |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10490 | dev_dbg(&pf->pdev->dev, |
| 10491 | "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n", |
| 10492 | pf->hw.func_caps.num_tx_qp, |
| 10493 | !!(pf->flags & I40E_FLAG_FD_SB_ENABLED), |
Helin Zhang | acd6544 | 2015-10-26 19:44:28 -0400 | [diff] [blame] | 10494 | pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs, |
| 10495 | pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps, |
| 10496 | queues_left); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10497 | #ifdef I40E_FCOE |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 10498 | 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] | 10499 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10500 | } |
| 10501 | |
| 10502 | /** |
| 10503 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 10504 | * @pf: PF to be setup |
| 10505 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10506 | * 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] | 10507 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 10508 | * based filter sizes required for them. It also enables Flow director, |
| 10509 | * ethertype and macvlan type filter settings for the pf. |
| 10510 | * |
| 10511 | * Returns 0 on success, negative on failure |
| 10512 | **/ |
| 10513 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 10514 | { |
| 10515 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 10516 | |
| 10517 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 10518 | |
| 10519 | /* Flow Director is enabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 10520 | 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] | 10521 | settings->enable_fdir = true; |
| 10522 | |
| 10523 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 10524 | settings->enable_ethtype = true; |
| 10525 | settings->enable_macvlan = true; |
| 10526 | |
| 10527 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 10528 | return -ENOENT; |
| 10529 | |
| 10530 | return 0; |
| 10531 | } |
| 10532 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10533 | #define INFO_STRING_LEN 255 |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10534 | #define REMAIN(__x) (INFO_STRING_LEN - (__x)) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10535 | static void i40e_print_features(struct i40e_pf *pf) |
| 10536 | { |
| 10537 | struct i40e_hw *hw = &pf->hw; |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10538 | char *buf; |
| 10539 | int i; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10540 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10541 | buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL); |
| 10542 | if (!buf) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10543 | return; |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10544 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10545 | 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] | 10546 | #ifdef CONFIG_PCI_IOV |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10547 | i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10548 | #endif |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10549 | i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d RX: %s", |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10550 | pf->hw.func_caps.num_vsis, |
| 10551 | pf->vsi[pf->lan_vsi]->num_queue_pairs, |
| 10552 | pf->flags & I40E_FLAG_RX_PS_ENABLED ? "PS" : "1BUF"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10553 | |
| 10554 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10555 | i += snprintf(&buf[i], REMAIN(i), " RSS"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10556 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10557 | i += snprintf(&buf[i], REMAIN(i), " FD_ATR"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10558 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10559 | i += snprintf(&buf[i], REMAIN(i), " FD_SB"); |
| 10560 | i += snprintf(&buf[i], REMAIN(i), " NTUPLE"); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 10561 | } |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10562 | if (pf->flags & I40E_FLAG_DCB_CAPABLE) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10563 | i += snprintf(&buf[i], REMAIN(i), " DCB"); |
Jesse Brandeburg | ce6fcb3 | 2015-08-28 17:55:59 -0400 | [diff] [blame] | 10564 | #if IS_ENABLED(CONFIG_VXLAN) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10565 | i += snprintf(&buf[i], REMAIN(i), " VxLAN"); |
Jesse Brandeburg | ce6fcb3 | 2015-08-28 17:55:59 -0400 | [diff] [blame] | 10566 | #endif |
Singhai, Anjali | 6a89902 | 2015-12-14 12:21:18 -0800 | [diff] [blame] | 10567 | #if IS_ENABLED(CONFIG_GENEVE) |
| 10568 | i += snprintf(&buf[i], REMAIN(i), " Geneve"); |
| 10569 | #endif |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10570 | if (pf->flags & I40E_FLAG_PTP) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10571 | i += snprintf(&buf[i], REMAIN(i), " PTP"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10572 | #ifdef I40E_FCOE |
| 10573 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10574 | i += snprintf(&buf[i], REMAIN(i), " FCOE"); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10575 | #endif |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10576 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10577 | i += snprintf(&buf[i], REMAIN(i), " VEB"); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10578 | else |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10579 | i += snprintf(&buf[i], REMAIN(i), " VEPA"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10580 | |
Joe Perches | 3b19584 | 2015-12-03 04:20:57 -0800 | [diff] [blame] | 10581 | dev_info(&pf->pdev->dev, "%s\n", buf); |
| 10582 | kfree(buf); |
Shannon Nelson | 7fd8954 | 2015-10-21 19:47:04 -0400 | [diff] [blame] | 10583 | WARN_ON(i > INFO_STRING_LEN); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10584 | } |
| 10585 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10586 | /** |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10587 | * i40e_get_platform_mac_addr - get platform-specific MAC address |
| 10588 | * |
| 10589 | * @pdev: PCI device information struct |
| 10590 | * @pf: board private structure |
| 10591 | * |
| 10592 | * Look up the MAC address in Open Firmware on systems that support it, |
| 10593 | * and use IDPROM on SPARC if no OF address is found. On return, the |
| 10594 | * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value |
| 10595 | * has been selected. |
| 10596 | **/ |
| 10597 | static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf) |
| 10598 | { |
| 10599 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 10600 | const unsigned char *addr; |
| 10601 | u8 *mac_addr = pf->hw.mac.addr; |
| 10602 | |
| 10603 | pf->flags &= ~I40E_FLAG_PF_MAC; |
| 10604 | addr = of_get_mac_address(dp); |
| 10605 | if (addr) { |
| 10606 | ether_addr_copy(mac_addr, addr); |
| 10607 | pf->flags |= I40E_FLAG_PF_MAC; |
| 10608 | #ifdef CONFIG_SPARC |
| 10609 | } else { |
| 10610 | ether_addr_copy(mac_addr, idprom->id_ethaddr); |
| 10611 | pf->flags |= I40E_FLAG_PF_MAC; |
| 10612 | #endif /* CONFIG_SPARC */ |
| 10613 | } |
| 10614 | } |
| 10615 | |
| 10616 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10617 | * i40e_probe - Device initialization routine |
| 10618 | * @pdev: PCI device information struct |
| 10619 | * @ent: entry in i40e_pci_tbl |
| 10620 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 10621 | * i40e_probe initializes a PF identified by a pci_dev structure. |
| 10622 | * The OS initialization, configuring of the PF private structure, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10623 | * and a hardware reset occur. |
| 10624 | * |
| 10625 | * Returns 0 on success, negative on failure |
| 10626 | **/ |
| 10627 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 10628 | { |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 10629 | struct i40e_aq_get_phy_abilities_resp abilities; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10630 | struct i40e_pf *pf; |
| 10631 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10632 | static u16 pfs_found; |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10633 | u16 wol_nvm_bits; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 10634 | u16 link_status; |
Jean Sacren | 6f66a48 | 2015-09-19 05:08:45 -0600 | [diff] [blame] | 10635 | int err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10636 | u32 len; |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 10637 | u32 val; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10638 | u32 i; |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 10639 | u8 set_fc_aq_fail; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10640 | |
| 10641 | err = pci_enable_device_mem(pdev); |
| 10642 | if (err) |
| 10643 | return err; |
| 10644 | |
| 10645 | /* set up for high or low dma */ |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10646 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 10647 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 10648 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10649 | if (err) { |
| 10650 | dev_err(&pdev->dev, |
| 10651 | "DMA configuration failed: 0x%x\n", err); |
| 10652 | goto err_dma; |
| 10653 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10654 | } |
| 10655 | |
| 10656 | /* set up pci connections */ |
| 10657 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 10658 | IORESOURCE_MEM), i40e_driver_name); |
| 10659 | if (err) { |
| 10660 | dev_info(&pdev->dev, |
| 10661 | "pci_request_selected_regions failed %d\n", err); |
| 10662 | goto err_pci_reg; |
| 10663 | } |
| 10664 | |
| 10665 | pci_enable_pcie_error_reporting(pdev); |
| 10666 | pci_set_master(pdev); |
| 10667 | |
| 10668 | /* Now that we have a PCI connection, we need to do the |
| 10669 | * low level device setup. This is primarily setting up |
| 10670 | * the Admin Queue structures and then querying for the |
| 10671 | * device's current profile information. |
| 10672 | */ |
| 10673 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 10674 | if (!pf) { |
| 10675 | err = -ENOMEM; |
| 10676 | goto err_pf_alloc; |
| 10677 | } |
| 10678 | pf->next_vsi = 0; |
| 10679 | pf->pdev = pdev; |
| 10680 | set_bit(__I40E_DOWN, &pf->state); |
| 10681 | |
| 10682 | hw = &pf->hw; |
| 10683 | hw->back = pf; |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10684 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10685 | pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0), |
| 10686 | I40E_MAX_CSR_SPACE); |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 10687 | |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10688 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10689 | if (!hw->hw_addr) { |
| 10690 | err = -EIO; |
| 10691 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 10692 | (unsigned int)pci_resource_start(pdev, 0), |
Shannon Nelson | 2ac8b67 | 2015-07-23 16:54:37 -0400 | [diff] [blame] | 10693 | pf->ioremap_len, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10694 | goto err_ioremap; |
| 10695 | } |
| 10696 | hw->vendor_id = pdev->vendor; |
| 10697 | hw->device_id = pdev->device; |
| 10698 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 10699 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 10700 | hw->subsystem_device_id = pdev->subsystem_device; |
| 10701 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 10702 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10703 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10704 | |
Shannon Nelson | 5b5faa4 | 2014-10-17 03:14:51 +0000 | [diff] [blame] | 10705 | if (debug != -1) { |
| 10706 | pf->msg_enable = pf->hw.debug_mask; |
| 10707 | pf->msg_enable = debug; |
| 10708 | } |
| 10709 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 10710 | /* do a special CORER for clearing PXE mode once at init */ |
| 10711 | if (hw->revision_id == 0 && |
| 10712 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 10713 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 10714 | i40e_flush(hw); |
| 10715 | msleep(200); |
| 10716 | pf->corer_count++; |
| 10717 | |
| 10718 | i40e_clear_pxe_mode(hw); |
| 10719 | } |
| 10720 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10721 | /* 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] | 10722 | i40e_clear_hw(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10723 | err = i40e_pf_reset(hw); |
| 10724 | if (err) { |
| 10725 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 10726 | goto err_pf_reset; |
| 10727 | } |
| 10728 | pf->pfr_count++; |
| 10729 | |
| 10730 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 10731 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 10732 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10733 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 10734 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10735 | |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 10736 | snprintf(pf->int_name, sizeof(pf->int_name) - 1, |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 10737 | "%s-%s:misc", |
| 10738 | dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10739 | |
| 10740 | err = i40e_init_shared_code(hw); |
| 10741 | if (err) { |
Anjali Singhai Jain | b2a75c5 | 2015-04-27 14:57:20 -0400 | [diff] [blame] | 10742 | dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n", |
| 10743 | err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10744 | goto err_pf_reset; |
| 10745 | } |
| 10746 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 10747 | /* set up a default setting for link flow control */ |
| 10748 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 10749 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 10750 | /* set up the locks for the AQ, do this only once in probe |
| 10751 | * and destroy them only once in remove |
| 10752 | */ |
| 10753 | mutex_init(&hw->aq.asq_mutex); |
| 10754 | mutex_init(&hw->aq.arq_mutex); |
| 10755 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10756 | err = i40e_init_adminq(hw); |
Carolyn Wyborny | 2b2426a76 | 2015-10-26 19:44:35 -0400 | [diff] [blame] | 10757 | if (err) { |
| 10758 | if (err == I40E_ERR_FIRMWARE_API_VERSION) |
| 10759 | dev_info(&pdev->dev, |
| 10760 | "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"); |
| 10761 | else |
| 10762 | dev_info(&pdev->dev, |
| 10763 | "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n"); |
| 10764 | |
| 10765 | goto err_pf_reset; |
| 10766 | } |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10767 | |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 10768 | /* provide nvm, fw, api versions */ |
| 10769 | dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n", |
| 10770 | hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build, |
| 10771 | hw->aq.api_maj_ver, hw->aq.api_min_ver, |
| 10772 | i40e_nvm_version_str(hw)); |
Carolyn Wyborny | f0b4444 | 2015-08-31 19:54:49 -0400 | [diff] [blame] | 10773 | |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10774 | if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && |
| 10775 | hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10776 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10777 | "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"); |
| 10778 | else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR || |
| 10779 | hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1)) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 10780 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 10781 | "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] | 10782 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 10783 | i40e_verify_eeprom(pf); |
| 10784 | |
Jesse Brandeburg | 2c5fe33 | 2014-04-23 04:49:57 +0000 | [diff] [blame] | 10785 | /* Rev 0 hardware was never productized */ |
| 10786 | if (hw->revision_id < 1) |
| 10787 | 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"); |
| 10788 | |
Shannon Nelson | 6ff4ef8 | 2013-12-21 05:44:49 +0000 | [diff] [blame] | 10789 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10790 | err = i40e_get_capabilities(pf); |
| 10791 | if (err) |
| 10792 | goto err_adminq_setup; |
| 10793 | |
| 10794 | err = i40e_sw_init(pf); |
| 10795 | if (err) { |
| 10796 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 10797 | goto err_sw_init; |
| 10798 | } |
| 10799 | |
| 10800 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 10801 | hw->func_caps.num_rx_qp, |
| 10802 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 10803 | if (err) { |
| 10804 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 10805 | goto err_init_lan_hmc; |
| 10806 | } |
| 10807 | |
| 10808 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 10809 | if (err) { |
| 10810 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 10811 | err = -ENOENT; |
| 10812 | goto err_configure_lan_hmc; |
| 10813 | } |
| 10814 | |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 10815 | /* Disable LLDP for NICs that have firmware versions lower than v4.3. |
| 10816 | * Ignore error return codes because if it was already disabled via |
| 10817 | * hardware settings this will fail |
| 10818 | */ |
| 10819 | if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || |
| 10820 | (pf->hw.aq.fw_maj_ver < 4)) { |
| 10821 | dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n"); |
| 10822 | i40e_aq_stop_lldp(hw, true, NULL); |
| 10823 | } |
| 10824 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10825 | i40e_get_mac_addr(hw, hw->mac.addr); |
Sowmini Varadhan | b499ffb | 2015-12-07 15:06:34 -0500 | [diff] [blame] | 10826 | /* allow a platform config to override the HW addr */ |
| 10827 | i40e_get_platform_mac_addr(pdev, pf); |
Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 10828 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10829 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 10830 | err = -EIO; |
| 10831 | goto err_mac_addr; |
| 10832 | } |
| 10833 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 10834 | ether_addr_copy(hw->mac.perm_addr, hw->mac.addr); |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 10835 | i40e_get_port_mac_addr(hw, hw->mac.port_addr); |
| 10836 | if (is_valid_ether_addr(hw->mac.port_addr)) |
| 10837 | pf->flags |= I40E_FLAG_PORT_ID_VALID; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10838 | #ifdef I40E_FCOE |
| 10839 | err = i40e_get_san_mac_addr(hw, hw->mac.san_addr); |
| 10840 | if (err) |
| 10841 | dev_info(&pdev->dev, |
| 10842 | "(non-fatal) SAN MAC retrieval failed: %d\n", err); |
| 10843 | if (!is_valid_ether_addr(hw->mac.san_addr)) { |
| 10844 | dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n", |
| 10845 | hw->mac.san_addr); |
| 10846 | ether_addr_copy(hw->mac.san_addr, hw->mac.addr); |
| 10847 | } |
| 10848 | dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr); |
| 10849 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10850 | |
| 10851 | pci_set_drvdata(pdev, pf); |
| 10852 | pci_save_state(pdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10853 | #ifdef CONFIG_I40E_DCB |
| 10854 | err = i40e_init_pf_dcb(pf); |
| 10855 | if (err) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 10856 | dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err); |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 10857 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 10858 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 10859 | } |
| 10860 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10861 | |
| 10862 | /* set up periodic task facility */ |
| 10863 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 10864 | pf->service_timer_period = HZ; |
| 10865 | |
| 10866 | INIT_WORK(&pf->service_task, i40e_service_task); |
| 10867 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 10868 | pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10869 | |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10870 | /* NVM bit on means WoL disabled for the port */ |
| 10871 | 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] | 10872 | if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1) |
Shannon Nelson | 1d5109d | 2015-08-26 15:14:08 -0400 | [diff] [blame] | 10873 | pf->wol_en = false; |
| 10874 | else |
| 10875 | pf->wol_en = true; |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 10876 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 10877 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10878 | /* set up the main switch operations */ |
| 10879 | i40e_determine_queue_usage(pf); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 10880 | err = i40e_init_interrupt_scheme(pf); |
| 10881 | if (err) |
| 10882 | goto err_switch_setup; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10883 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10884 | /* The number of VSIs reported by the FW is the minimum guaranteed |
| 10885 | * to us; HW supports far more and we share the remaining pool with |
| 10886 | * the other PFs. We allocate space for more than the guarantee with |
| 10887 | * the understanding that we might not get them all later. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10888 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10889 | if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC) |
| 10890 | pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC; |
| 10891 | else |
| 10892 | pf->num_alloc_vsi = pf->hw.func_caps.num_vsis; |
| 10893 | |
| 10894 | /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */ |
| 10895 | len = sizeof(struct i40e_vsi *) * pf->num_alloc_vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10896 | pf->vsi = kzalloc(len, GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 10897 | if (!pf->vsi) { |
| 10898 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10899 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 10900 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10901 | |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 10902 | #ifdef CONFIG_PCI_IOV |
| 10903 | /* prep for VF support */ |
| 10904 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 10905 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 10906 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 10907 | if (pci_num_vf(pdev)) |
| 10908 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 10909 | } |
| 10910 | #endif |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 10911 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10912 | if (err) { |
| 10913 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 10914 | goto err_vsis; |
| 10915 | } |
Helin Zhang | 58fc326 | 2015-10-01 14:37:38 -0400 | [diff] [blame] | 10916 | |
| 10917 | /* Make sure flow control is set according to current settings */ |
| 10918 | err = i40e_set_fc(hw, &set_fc_aq_fail, true); |
| 10919 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET) |
| 10920 | dev_dbg(&pf->pdev->dev, |
| 10921 | "Set fc with err %s aq_err %s on get_phy_cap\n", |
| 10922 | i40e_stat_str(hw, err), |
| 10923 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 10924 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET) |
| 10925 | dev_dbg(&pf->pdev->dev, |
| 10926 | "Set fc with err %s aq_err %s on set_phy_config\n", |
| 10927 | i40e_stat_str(hw, err), |
| 10928 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 10929 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE) |
| 10930 | dev_dbg(&pf->pdev->dev, |
| 10931 | "Set fc with err %s aq_err %s on get_link_info\n", |
| 10932 | i40e_stat_str(hw, err), |
| 10933 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
| 10934 | |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10935 | /* if FDIR VSI was set up, start it now */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10936 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 10937 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 10938 | i40e_vsi_open(pf->vsi[i]); |
| 10939 | break; |
| 10940 | } |
| 10941 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10942 | |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 10943 | /* driver is only interested in link up/down and module qualification |
| 10944 | * reports from firmware |
| 10945 | */ |
| 10946 | err = i40e_aq_set_phy_int_mask(&pf->hw, |
| 10947 | I40E_AQ_EVENT_LINK_UPDOWN | |
| 10948 | I40E_AQ_EVENT_MODULE_QUAL_FAIL, NULL); |
| 10949 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10950 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
| 10951 | i40e_stat_str(&pf->hw, err), |
| 10952 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 10953 | |
Anjali Singhai Jain | 4f2f017c | 2015-10-21 19:47:07 -0400 | [diff] [blame] | 10954 | /* Reconfigure hardware for allowing smaller MSS in the case |
| 10955 | * of TSO, so that we avoid the MDD being fired and causing |
| 10956 | * a reset in the case of small MSS+TSO. |
| 10957 | */ |
| 10958 | val = rd32(hw, I40E_REG_MSS); |
| 10959 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { |
| 10960 | val &= ~I40E_REG_MSS_MIN_MASK; |
| 10961 | val |= I40E_64BYTE_MSS; |
| 10962 | wr32(hw, I40E_REG_MSS, val); |
| 10963 | } |
| 10964 | |
Anjali Singhai Jain | 8eed76f | 2015-12-09 15:50:31 -0800 | [diff] [blame] | 10965 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 10966 | msleep(75); |
| 10967 | err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 10968 | if (err) |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 10969 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
| 10970 | i40e_stat_str(&pf->hw, err), |
| 10971 | i40e_aq_str(&pf->hw, |
| 10972 | pf->hw.aq.asq_last_status)); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 10973 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10974 | /* The main driver is (mostly) up and happy. We need to set this state |
| 10975 | * before setting up the misc vector or we get a race and the vector |
| 10976 | * ends up disabled forever. |
| 10977 | */ |
| 10978 | clear_bit(__I40E_DOWN, &pf->state); |
| 10979 | |
| 10980 | /* In case of MSIX we are going to setup the misc vector right here |
| 10981 | * to handle admin queue events etc. In case of legacy and MSI |
| 10982 | * the misc functionality and queue processing is combined in |
| 10983 | * the same vector and that gets setup at open. |
| 10984 | */ |
| 10985 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 10986 | err = i40e_setup_misc_vector(pf); |
| 10987 | if (err) { |
| 10988 | dev_info(&pdev->dev, |
| 10989 | "setup of misc vector failed: %d\n", err); |
| 10990 | goto err_vsis; |
| 10991 | } |
| 10992 | } |
| 10993 | |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 10994 | #ifdef CONFIG_PCI_IOV |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10995 | /* prep for VF support */ |
| 10996 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 10997 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 10998 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10999 | u32 val; |
| 11000 | |
| 11001 | /* disable link interrupts for VFs */ |
| 11002 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 11003 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 11004 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 11005 | i40e_flush(hw); |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 11006 | |
| 11007 | if (pci_num_vf(pdev)) { |
| 11008 | dev_info(&pdev->dev, |
| 11009 | "Active VFs found, allocating resources.\n"); |
| 11010 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); |
| 11011 | if (err) |
| 11012 | dev_info(&pdev->dev, |
| 11013 | "Error %d allocating resources for existing VFs\n", |
| 11014 | err); |
| 11015 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11016 | } |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 11017 | #endif /* CONFIG_PCI_IOV */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11018 | |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 11019 | pfs_found++; |
| 11020 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11021 | i40e_dbg_pf_init(pf); |
| 11022 | |
| 11023 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 11024 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11025 | |
| 11026 | /* since everything's happy, start the service_task timer */ |
| 11027 | mod_timer(&pf->service_timer, |
| 11028 | round_jiffies(jiffies + pf->service_timer_period)); |
| 11029 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 11030 | #ifdef I40E_FCOE |
| 11031 | /* create FCoE interface */ |
| 11032 | i40e_fcoe_vsi_setup(pf); |
| 11033 | |
| 11034 | #endif |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11035 | #define PCI_SPEED_SIZE 8 |
| 11036 | #define PCI_WIDTH_SIZE 8 |
| 11037 | /* Devices on the IOSF bus do not have this information |
| 11038 | * and will report PCI Gen 1 x 1 by default so don't bother |
| 11039 | * checking them. |
| 11040 | */ |
| 11041 | if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) { |
| 11042 | char speed[PCI_SPEED_SIZE] = "Unknown"; |
| 11043 | char width[PCI_WIDTH_SIZE] = "Unknown"; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11044 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11045 | /* Get the negotiated link width and speed from PCI config |
| 11046 | * space |
| 11047 | */ |
| 11048 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, |
| 11049 | &link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11050 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11051 | i40e_set_pci_config_data(hw, link_status); |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11052 | |
Anjali Singhai Jain | 3fced53 | 2015-09-03 17:18:59 -0400 | [diff] [blame] | 11053 | switch (hw->bus.speed) { |
| 11054 | case i40e_bus_speed_8000: |
| 11055 | strncpy(speed, "8.0", PCI_SPEED_SIZE); break; |
| 11056 | case i40e_bus_speed_5000: |
| 11057 | strncpy(speed, "5.0", PCI_SPEED_SIZE); break; |
| 11058 | case i40e_bus_speed_2500: |
| 11059 | strncpy(speed, "2.5", PCI_SPEED_SIZE); break; |
| 11060 | default: |
| 11061 | break; |
| 11062 | } |
| 11063 | switch (hw->bus.width) { |
| 11064 | case i40e_bus_width_pcie_x8: |
| 11065 | strncpy(width, "8", PCI_WIDTH_SIZE); break; |
| 11066 | case i40e_bus_width_pcie_x4: |
| 11067 | strncpy(width, "4", PCI_WIDTH_SIZE); break; |
| 11068 | case i40e_bus_width_pcie_x2: |
| 11069 | strncpy(width, "2", PCI_WIDTH_SIZE); break; |
| 11070 | case i40e_bus_width_pcie_x1: |
| 11071 | strncpy(width, "1", PCI_WIDTH_SIZE); break; |
| 11072 | default: |
| 11073 | break; |
| 11074 | } |
| 11075 | |
| 11076 | dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n", |
| 11077 | speed, width); |
| 11078 | |
| 11079 | if (hw->bus.width < i40e_bus_width_pcie_x8 || |
| 11080 | hw->bus.speed < i40e_bus_speed_8000) { |
| 11081 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); |
| 11082 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); |
| 11083 | } |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 11084 | } |
| 11085 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11086 | /* get the requested speeds from the fw */ |
| 11087 | err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL); |
| 11088 | if (err) |
Neerav Parikh | 8279e49 | 2015-09-03 17:18:50 -0400 | [diff] [blame] | 11089 | dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n", |
| 11090 | i40e_stat_str(&pf->hw, err), |
| 11091 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 11092 | pf->hw.phy.link_info.requested_speeds = abilities.link_speed; |
| 11093 | |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 11094 | /* get the supported phy types from the fw */ |
| 11095 | err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL); |
| 11096 | if (err) |
| 11097 | dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n", |
| 11098 | i40e_stat_str(&pf->hw, err), |
| 11099 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); |
| 11100 | pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type); |
| 11101 | |
Anjali Singhai Jain | e7358f5 | 2015-10-01 14:37:34 -0400 | [diff] [blame] | 11102 | /* Add a filter to drop all Flow control frames from any VSI from being |
| 11103 | * transmitted. By doing so we stop a malicious VF from sending out |
| 11104 | * PAUSE or PFC frames and potentially controlling traffic for other |
| 11105 | * PF/VF VSIs. |
| 11106 | * The FW can still send Flow control frames if enabled. |
| 11107 | */ |
| 11108 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, |
| 11109 | pf->main_vsi_seid); |
| 11110 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 11111 | /* print a string summarizing features */ |
| 11112 | i40e_print_features(pf); |
| 11113 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11114 | return 0; |
| 11115 | |
| 11116 | /* Unwind what we've done if something failed in the setup */ |
| 11117 | err_vsis: |
| 11118 | set_bit(__I40E_DOWN, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11119 | i40e_clear_interrupt_scheme(pf); |
| 11120 | kfree(pf->vsi); |
Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 11121 | err_switch_setup: |
| 11122 | i40e_reset_interrupt_capability(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11123 | del_timer_sync(&pf->service_timer); |
| 11124 | err_mac_addr: |
| 11125 | err_configure_lan_hmc: |
| 11126 | (void)i40e_shutdown_lan_hmc(hw); |
| 11127 | err_init_lan_hmc: |
| 11128 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11129 | err_sw_init: |
| 11130 | err_adminq_setup: |
| 11131 | (void)i40e_shutdown_adminq(hw); |
| 11132 | err_pf_reset: |
| 11133 | iounmap(hw->hw_addr); |
| 11134 | err_ioremap: |
| 11135 | kfree(pf); |
| 11136 | err_pf_alloc: |
| 11137 | pci_disable_pcie_error_reporting(pdev); |
| 11138 | pci_release_selected_regions(pdev, |
| 11139 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 11140 | err_pci_reg: |
| 11141 | err_dma: |
| 11142 | pci_disable_device(pdev); |
| 11143 | return err; |
| 11144 | } |
| 11145 | |
| 11146 | /** |
| 11147 | * i40e_remove - Device removal routine |
| 11148 | * @pdev: PCI device information struct |
| 11149 | * |
| 11150 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 11151 | * that is should release a PCI device. This could be caused by a |
| 11152 | * Hot-Plug event, or because the driver is going to be removed from |
| 11153 | * memory. |
| 11154 | **/ |
| 11155 | static void i40e_remove(struct pci_dev *pdev) |
| 11156 | { |
| 11157 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11158 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11159 | i40e_status ret_code; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11160 | int i; |
| 11161 | |
| 11162 | i40e_dbg_pf_exit(pf); |
| 11163 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 11164 | i40e_ptp_stop(pf); |
| 11165 | |
Carolyn Wyborny | bcab2db | 2015-09-28 14:16:55 -0400 | [diff] [blame] | 11166 | /* Disable RSS in hw */ |
| 11167 | wr32(hw, I40E_PFQF_HENA(0), 0); |
| 11168 | wr32(hw, I40E_PFQF_HENA(1), 0); |
| 11169 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11170 | /* no more scheduling of any task */ |
| 11171 | set_bit(__I40E_DOWN, &pf->state); |
| 11172 | del_timer_sync(&pf->service_timer); |
| 11173 | cancel_work_sync(&pf->service_task); |
| 11174 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 11175 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 11176 | i40e_free_vfs(pf); |
| 11177 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 11178 | } |
| 11179 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11180 | i40e_fdir_teardown(pf); |
| 11181 | |
| 11182 | /* If there is a switch structure or any orphans, remove them. |
| 11183 | * This will leave only the PF's VSI remaining. |
| 11184 | */ |
| 11185 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11186 | if (!pf->veb[i]) |
| 11187 | continue; |
| 11188 | |
| 11189 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 11190 | pf->veb[i]->uplink_seid == 0) |
| 11191 | i40e_switch_branch_release(pf->veb[i]); |
| 11192 | } |
| 11193 | |
| 11194 | /* Now we can shutdown the PF's VSI, just before we kill |
| 11195 | * adminq and hmc. |
| 11196 | */ |
| 11197 | if (pf->vsi[pf->lan_vsi]) |
| 11198 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 11199 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11200 | /* shutdown and destroy the HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 11201 | if (pf->hw.hmc.hmc_obj) { |
| 11202 | ret_code = i40e_shutdown_lan_hmc(&pf->hw); |
| 11203 | if (ret_code) |
| 11204 | dev_warn(&pdev->dev, |
| 11205 | "Failed to destroy the HMC resources: %d\n", |
| 11206 | ret_code); |
| 11207 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11208 | |
| 11209 | /* shutdown the adminq */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11210 | ret_code = i40e_shutdown_adminq(&pf->hw); |
| 11211 | if (ret_code) |
| 11212 | dev_warn(&pdev->dev, |
| 11213 | "Failed to destroy the Admin Queue resources: %d\n", |
| 11214 | ret_code); |
| 11215 | |
Jesse Brandeburg | 8ddb332 | 2015-11-18 15:47:06 -0800 | [diff] [blame] | 11216 | /* destroy the locks only once, here */ |
| 11217 | mutex_destroy(&hw->aq.arq_mutex); |
| 11218 | mutex_destroy(&hw->aq.asq_mutex); |
| 11219 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11220 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 11221 | i40e_clear_interrupt_scheme(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 11222 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11223 | if (pf->vsi[i]) { |
| 11224 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 11225 | i40e_vsi_clear(pf->vsi[i]); |
| 11226 | pf->vsi[i] = NULL; |
| 11227 | } |
| 11228 | } |
| 11229 | |
| 11230 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 11231 | kfree(pf->veb[i]); |
| 11232 | pf->veb[i] = NULL; |
| 11233 | } |
| 11234 | |
| 11235 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11236 | kfree(pf->vsi); |
| 11237 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11238 | iounmap(pf->hw.hw_addr); |
| 11239 | kfree(pf); |
| 11240 | pci_release_selected_regions(pdev, |
| 11241 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 11242 | |
| 11243 | pci_disable_pcie_error_reporting(pdev); |
| 11244 | pci_disable_device(pdev); |
| 11245 | } |
| 11246 | |
| 11247 | /** |
| 11248 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 11249 | * @pdev: PCI device information struct |
| 11250 | * |
| 11251 | * Called to warn that something happened and the error handling steps |
| 11252 | * are in progress. Allows the driver to quiesce things, be ready for |
| 11253 | * remediation. |
| 11254 | **/ |
| 11255 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 11256 | enum pci_channel_state error) |
| 11257 | { |
| 11258 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11259 | |
| 11260 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 11261 | |
| 11262 | /* shutdown all operations */ |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11263 | if (!test_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11264 | rtnl_lock(); |
| 11265 | i40e_prep_for_reset(pf); |
| 11266 | rtnl_unlock(); |
| 11267 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11268 | |
| 11269 | /* Request a slot reset */ |
| 11270 | return PCI_ERS_RESULT_NEED_RESET; |
| 11271 | } |
| 11272 | |
| 11273 | /** |
| 11274 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 11275 | * @pdev: PCI device information struct |
| 11276 | * |
| 11277 | * Called to find if the driver can work with the device now that |
| 11278 | * the pci slot has been reset. If a basic connection seems good |
| 11279 | * (registers are readable and have sane content) then return a |
| 11280 | * happy little PCI_ERS_RESULT_xxx. |
| 11281 | **/ |
| 11282 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 11283 | { |
| 11284 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11285 | pci_ers_result_t result; |
| 11286 | int err; |
| 11287 | u32 reg; |
| 11288 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11289 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11290 | if (pci_enable_device_mem(pdev)) { |
| 11291 | dev_info(&pdev->dev, |
| 11292 | "Cannot re-enable PCI device after reset.\n"); |
| 11293 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11294 | } else { |
| 11295 | pci_set_master(pdev); |
| 11296 | pci_restore_state(pdev); |
| 11297 | pci_save_state(pdev); |
| 11298 | pci_wake_from_d3(pdev, false); |
| 11299 | |
| 11300 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 11301 | if (reg == 0) |
| 11302 | result = PCI_ERS_RESULT_RECOVERED; |
| 11303 | else |
| 11304 | result = PCI_ERS_RESULT_DISCONNECT; |
| 11305 | } |
| 11306 | |
| 11307 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 11308 | if (err) { |
| 11309 | dev_info(&pdev->dev, |
| 11310 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 11311 | err); |
| 11312 | /* non-fatal, continue */ |
| 11313 | } |
| 11314 | |
| 11315 | return result; |
| 11316 | } |
| 11317 | |
| 11318 | /** |
| 11319 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 11320 | * @pdev: PCI device information struct |
| 11321 | * |
| 11322 | * Called to allow the driver to bring things back up after PCI error |
| 11323 | * and/or reset recovery has finished. |
| 11324 | **/ |
| 11325 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 11326 | { |
| 11327 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11328 | |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11329 | dev_dbg(&pdev->dev, "%s\n", __func__); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11330 | if (test_bit(__I40E_SUSPENDED, &pf->state)) |
| 11331 | return; |
| 11332 | |
| 11333 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11334 | i40e_handle_reset_warning(pf); |
Vasily Averin | 4c4935a | 2015-07-08 15:04:26 +0300 | [diff] [blame] | 11335 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11336 | } |
| 11337 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11338 | /** |
| 11339 | * i40e_shutdown - PCI callback for shutting down |
| 11340 | * @pdev: PCI device information struct |
| 11341 | **/ |
| 11342 | static void i40e_shutdown(struct pci_dev *pdev) |
| 11343 | { |
| 11344 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11345 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11346 | |
| 11347 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11348 | set_bit(__I40E_DOWN, &pf->state); |
| 11349 | rtnl_lock(); |
| 11350 | i40e_prep_for_reset(pf); |
| 11351 | rtnl_unlock(); |
| 11352 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11353 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11354 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11355 | |
Catherine Sullivan | 02b4249 | 2015-07-10 19:35:59 -0400 | [diff] [blame] | 11356 | del_timer_sync(&pf->service_timer); |
| 11357 | cancel_work_sync(&pf->service_task); |
| 11358 | i40e_fdir_teardown(pf); |
| 11359 | |
| 11360 | rtnl_lock(); |
| 11361 | i40e_prep_for_reset(pf); |
| 11362 | rtnl_unlock(); |
| 11363 | |
| 11364 | wr32(hw, I40E_PFPM_APM, |
| 11365 | (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11366 | wr32(hw, I40E_PFPM_WUFC, |
| 11367 | (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11368 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 11369 | i40e_clear_interrupt_scheme(pf); |
| 11370 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11371 | if (system_state == SYSTEM_POWER_OFF) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11372 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11373 | pci_set_power_state(pdev, PCI_D3hot); |
| 11374 | } |
| 11375 | } |
| 11376 | |
| 11377 | #ifdef CONFIG_PM |
| 11378 | /** |
| 11379 | * i40e_suspend - PCI callback for moving to D3 |
| 11380 | * @pdev: PCI device information struct |
| 11381 | **/ |
| 11382 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) |
| 11383 | { |
| 11384 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11385 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11386 | |
| 11387 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 11388 | set_bit(__I40E_DOWN, &pf->state); |
Mitch Williams | 3932dbf | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 11389 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11390 | rtnl_lock(); |
| 11391 | i40e_prep_for_reset(pf); |
| 11392 | rtnl_unlock(); |
| 11393 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 11394 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 11395 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 11396 | |
| 11397 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11398 | pci_set_power_state(pdev, PCI_D3hot); |
| 11399 | |
| 11400 | return 0; |
| 11401 | } |
| 11402 | |
| 11403 | /** |
| 11404 | * i40e_resume - PCI callback for waking up from D3 |
| 11405 | * @pdev: PCI device information struct |
| 11406 | **/ |
| 11407 | static int i40e_resume(struct pci_dev *pdev) |
| 11408 | { |
| 11409 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 11410 | u32 err; |
| 11411 | |
| 11412 | pci_set_power_state(pdev, PCI_D0); |
| 11413 | pci_restore_state(pdev); |
| 11414 | /* pci_restore_state() clears dev->state_saves, so |
| 11415 | * call pci_save_state() again to restore it. |
| 11416 | */ |
| 11417 | pci_save_state(pdev); |
| 11418 | |
| 11419 | err = pci_enable_device_mem(pdev); |
| 11420 | if (err) { |
Shannon Nelson | fb43201f | 2015-08-26 15:14:17 -0400 | [diff] [blame] | 11421 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n"); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11422 | return err; |
| 11423 | } |
| 11424 | pci_set_master(pdev); |
| 11425 | |
| 11426 | /* no wakeup events while running */ |
| 11427 | pci_wake_from_d3(pdev, false); |
| 11428 | |
| 11429 | /* handling the reset will rebuild the device state */ |
| 11430 | if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) { |
| 11431 | clear_bit(__I40E_DOWN, &pf->state); |
| 11432 | rtnl_lock(); |
| 11433 | i40e_reset_and_rebuild(pf, false); |
| 11434 | rtnl_unlock(); |
| 11435 | } |
| 11436 | |
| 11437 | return 0; |
| 11438 | } |
| 11439 | |
| 11440 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11441 | static const struct pci_error_handlers i40e_err_handler = { |
| 11442 | .error_detected = i40e_pci_error_detected, |
| 11443 | .slot_reset = i40e_pci_error_slot_reset, |
| 11444 | .resume = i40e_pci_error_resume, |
| 11445 | }; |
| 11446 | |
| 11447 | static struct pci_driver i40e_driver = { |
| 11448 | .name = i40e_driver_name, |
| 11449 | .id_table = i40e_pci_tbl, |
| 11450 | .probe = i40e_probe, |
| 11451 | .remove = i40e_remove, |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 11452 | #ifdef CONFIG_PM |
| 11453 | .suspend = i40e_suspend, |
| 11454 | .resume = i40e_resume, |
| 11455 | #endif |
| 11456 | .shutdown = i40e_shutdown, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11457 | .err_handler = &i40e_err_handler, |
| 11458 | .sriov_configure = i40e_pci_sriov_configure, |
| 11459 | }; |
| 11460 | |
| 11461 | /** |
| 11462 | * i40e_init_module - Driver registration routine |
| 11463 | * |
| 11464 | * i40e_init_module is the first routine called when the driver is |
| 11465 | * loaded. All it does is register with the PCI subsystem. |
| 11466 | **/ |
| 11467 | static int __init i40e_init_module(void) |
| 11468 | { |
| 11469 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 11470 | i40e_driver_string, i40e_driver_version_str); |
| 11471 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
Greg Rose | 9666448 | 2015-02-06 08:52:13 +0000 | [diff] [blame] | 11472 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11473 | i40e_dbg_init(); |
| 11474 | return pci_register_driver(&i40e_driver); |
| 11475 | } |
| 11476 | module_init(i40e_init_module); |
| 11477 | |
| 11478 | /** |
| 11479 | * i40e_exit_module - Driver exit cleanup routine |
| 11480 | * |
| 11481 | * i40e_exit_module is called just before the driver is removed |
| 11482 | * from memory. |
| 11483 | **/ |
| 11484 | static void __exit i40e_exit_module(void) |
| 11485 | { |
| 11486 | pci_unregister_driver(&i40e_driver); |
| 11487 | i40e_dbg_exit(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 11488 | } |
| 11489 | module_exit(i40e_exit_module); |