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 | |
| 27 | /* Local includes */ |
| 28 | #include "i40e.h" |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 29 | #include "i40e_diag.h" |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 30 | #ifdef CONFIG_I40E_VXLAN |
| 31 | #include <net/vxlan.h> |
| 32 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 33 | |
| 34 | const char i40e_driver_name[] = "i40e"; |
| 35 | static const char i40e_driver_string[] = |
| 36 | "Intel(R) Ethernet Connection XL710 Network Driver"; |
| 37 | |
| 38 | #define DRV_KERN "-k" |
| 39 | |
Catherine Sullivan | e8e724d | 2014-07-10 07:58:26 +0000 | [diff] [blame] | 40 | #define DRV_VERSION_MAJOR 1 |
Catherine Sullivan | 42d255c | 2015-03-31 00:45:06 -0700 | [diff] [blame] | 41 | #define DRV_VERSION_MINOR 3 |
Catherine Sullivan | f029094 | 2015-04-16 20:06:12 -0400 | [diff] [blame] | 42 | #define DRV_VERSION_BUILD 4 |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 43 | #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ |
| 44 | __stringify(DRV_VERSION_MINOR) "." \ |
| 45 | __stringify(DRV_VERSION_BUILD) DRV_KERN |
| 46 | const char i40e_driver_version_str[] = DRV_VERSION; |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 47 | static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation."; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 48 | |
| 49 | /* a bit of forward declarations */ |
| 50 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi); |
| 51 | static void i40e_handle_reset_warning(struct i40e_pf *pf); |
| 52 | static int i40e_add_vsi(struct i40e_vsi *vsi); |
| 53 | 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] | 54 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 55 | static int i40e_setup_misc_vector(struct i40e_pf *pf); |
| 56 | static void i40e_determine_queue_usage(struct i40e_pf *pf); |
| 57 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 58 | static void i40e_fdir_sb_setup(struct i40e_pf *pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 59 | static int i40e_veb_get_bw_info(struct i40e_veb *veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 60 | |
| 61 | /* i40e_pci_tbl - PCI Device ID Table |
| 62 | * |
| 63 | * Last entry must be all 0s |
| 64 | * |
| 65 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 66 | * Class, Class Mask, private data (not used) } |
| 67 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 68 | static const struct pci_device_id i40e_pci_tbl[] = { |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 69 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 70 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0}, |
| 71 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_A), 0}, |
| 72 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0}, |
| 73 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0}, |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 74 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0}, |
| 75 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0}, |
| 76 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0}, |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 77 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0}, |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 78 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 79 | /* required last entry */ |
| 80 | {0, } |
| 81 | }; |
| 82 | MODULE_DEVICE_TABLE(pci, i40e_pci_tbl); |
| 83 | |
| 84 | #define I40E_MAX_VF_COUNT 128 |
| 85 | static int debug = -1; |
| 86 | module_param(debug, int, 0); |
| 87 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 88 | |
| 89 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); |
| 90 | MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver"); |
| 91 | MODULE_LICENSE("GPL"); |
| 92 | MODULE_VERSION(DRV_VERSION); |
| 93 | |
| 94 | /** |
| 95 | * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code |
| 96 | * @hw: pointer to the HW structure |
| 97 | * @mem: ptr to mem struct to fill out |
| 98 | * @size: size of memory requested |
| 99 | * @alignment: what to align the allocation to |
| 100 | **/ |
| 101 | int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem, |
| 102 | u64 size, u32 alignment) |
| 103 | { |
| 104 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 105 | |
| 106 | mem->size = ALIGN(size, alignment); |
| 107 | mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size, |
| 108 | &mem->pa, GFP_KERNEL); |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 109 | if (!mem->va) |
| 110 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 111 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 112 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /** |
| 116 | * i40e_free_dma_mem_d - OS specific memory free for shared code |
| 117 | * @hw: pointer to the HW structure |
| 118 | * @mem: ptr to mem struct to free |
| 119 | **/ |
| 120 | int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) |
| 121 | { |
| 122 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 123 | |
| 124 | dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa); |
| 125 | mem->va = NULL; |
| 126 | mem->pa = 0; |
| 127 | mem->size = 0; |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code |
| 134 | * @hw: pointer to the HW structure |
| 135 | * @mem: ptr to mem struct to fill out |
| 136 | * @size: size of memory requested |
| 137 | **/ |
| 138 | int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem, |
| 139 | u32 size) |
| 140 | { |
| 141 | mem->size = size; |
| 142 | mem->va = kzalloc(size, GFP_KERNEL); |
| 143 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 144 | if (!mem->va) |
| 145 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 146 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 147 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /** |
| 151 | * i40e_free_virt_mem_d - OS specific memory free for shared code |
| 152 | * @hw: pointer to the HW structure |
| 153 | * @mem: ptr to mem struct to free |
| 154 | **/ |
| 155 | int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem) |
| 156 | { |
| 157 | /* it's ok to kfree a NULL pointer */ |
| 158 | kfree(mem->va); |
| 159 | mem->va = NULL; |
| 160 | mem->size = 0; |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * i40e_get_lump - find a lump of free generic resource |
| 167 | * @pf: board private structure |
| 168 | * @pile: the pile of resource to search |
| 169 | * @needed: the number of items needed |
| 170 | * @id: an owner id to stick on the items assigned |
| 171 | * |
| 172 | * Returns the base item index of the lump, or negative for error |
| 173 | * |
| 174 | * The search_hint trick and lack of advanced fit-finding only work |
| 175 | * because we're highly likely to have all the same size lump requests. |
| 176 | * Linear search time and any fragmentation should be minimal. |
| 177 | **/ |
| 178 | static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile, |
| 179 | u16 needed, u16 id) |
| 180 | { |
| 181 | int ret = -ENOMEM; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 182 | int i, j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 183 | |
| 184 | if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) { |
| 185 | dev_info(&pf->pdev->dev, |
| 186 | "param err: pile=%p needed=%d id=0x%04x\n", |
| 187 | pile, needed, id); |
| 188 | return -EINVAL; |
| 189 | } |
| 190 | |
| 191 | /* start the linear search with an imperfect hint */ |
| 192 | i = pile->search_hint; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 193 | while (i < pile->num_entries) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 194 | /* skip already allocated entries */ |
| 195 | if (pile->list[i] & I40E_PILE_VALID_BIT) { |
| 196 | i++; |
| 197 | continue; |
| 198 | } |
| 199 | |
| 200 | /* do we have enough in this lump? */ |
| 201 | for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) { |
| 202 | if (pile->list[i+j] & I40E_PILE_VALID_BIT) |
| 203 | break; |
| 204 | } |
| 205 | |
| 206 | if (j == needed) { |
| 207 | /* there was enough, so assign it to the requestor */ |
| 208 | for (j = 0; j < needed; j++) |
| 209 | pile->list[i+j] = id | I40E_PILE_VALID_BIT; |
| 210 | ret = i; |
| 211 | pile->search_hint = i + j; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 212 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 213 | } else { |
| 214 | /* not enough, so skip over it and continue looking */ |
| 215 | i += j; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | return ret; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * i40e_put_lump - return a lump of generic resource |
| 224 | * @pile: the pile of resource to search |
| 225 | * @index: the base item index |
| 226 | * @id: the owner id of the items assigned |
| 227 | * |
| 228 | * Returns the count of items in the lump |
| 229 | **/ |
| 230 | static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id) |
| 231 | { |
| 232 | int valid_id = (id | I40E_PILE_VALID_BIT); |
| 233 | int count = 0; |
| 234 | int i; |
| 235 | |
| 236 | if (!pile || index >= pile->num_entries) |
| 237 | return -EINVAL; |
| 238 | |
| 239 | for (i = index; |
| 240 | i < pile->num_entries && pile->list[i] == valid_id; |
| 241 | i++) { |
| 242 | pile->list[i] = 0; |
| 243 | count++; |
| 244 | } |
| 245 | |
| 246 | if (count && index < pile->search_hint) |
| 247 | pile->search_hint = index; |
| 248 | |
| 249 | return count; |
| 250 | } |
| 251 | |
| 252 | /** |
Anjali Singhai Jain | fdf0e0b | 2015-03-31 00:45:05 -0700 | [diff] [blame] | 253 | * i40e_find_vsi_from_id - searches for the vsi with the given id |
| 254 | * @pf - the pf structure to search for the vsi |
| 255 | * @id - id of the vsi it is searching for |
| 256 | **/ |
| 257 | struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id) |
| 258 | { |
| 259 | int i; |
| 260 | |
| 261 | for (i = 0; i < pf->num_alloc_vsi; i++) |
| 262 | if (pf->vsi[i] && (pf->vsi[i]->id == id)) |
| 263 | return pf->vsi[i]; |
| 264 | |
| 265 | return NULL; |
| 266 | } |
| 267 | |
| 268 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 269 | * i40e_service_event_schedule - Schedule the service task to wake up |
| 270 | * @pf: board private structure |
| 271 | * |
| 272 | * If not already scheduled, this puts the task into the work queue |
| 273 | **/ |
| 274 | static void i40e_service_event_schedule(struct i40e_pf *pf) |
| 275 | { |
| 276 | if (!test_bit(__I40E_DOWN, &pf->state) && |
| 277 | !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) && |
| 278 | !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state)) |
| 279 | schedule_work(&pf->service_task); |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * i40e_tx_timeout - Respond to a Tx Hang |
| 284 | * @netdev: network interface device structure |
| 285 | * |
| 286 | * If any port has noticed a Tx timeout, it is likely that the whole |
| 287 | * device is munged, not just the one netdev port, so go for the full |
| 288 | * reset. |
| 289 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 290 | #ifdef I40E_FCOE |
| 291 | void i40e_tx_timeout(struct net_device *netdev) |
| 292 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 293 | static void i40e_tx_timeout(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 294 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 295 | { |
| 296 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 297 | struct i40e_vsi *vsi = np->vsi; |
| 298 | struct i40e_pf *pf = vsi->back; |
| 299 | |
| 300 | pf->tx_timeout_count++; |
| 301 | |
| 302 | if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20))) |
Anjali Singhai Jain | 327fe04 | 2014-06-04 01:23:26 +0000 | [diff] [blame] | 303 | pf->tx_timeout_recovery_level = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 304 | pf->tx_timeout_last_recovery = jiffies; |
| 305 | netdev_info(netdev, "tx_timeout recovery level %d\n", |
| 306 | pf->tx_timeout_recovery_level); |
| 307 | |
| 308 | switch (pf->tx_timeout_recovery_level) { |
| 309 | case 0: |
| 310 | /* disable and re-enable queues for the VSI */ |
| 311 | if (in_interrupt()) { |
| 312 | set_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 313 | set_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 314 | } else { |
| 315 | i40e_vsi_reinit_locked(vsi); |
| 316 | } |
| 317 | break; |
| 318 | case 1: |
| 319 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 320 | break; |
| 321 | case 2: |
| 322 | set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 323 | break; |
| 324 | case 3: |
| 325 | set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 326 | break; |
| 327 | default: |
| 328 | netdev_err(netdev, "tx_timeout recovery unsuccessful\n"); |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 329 | set_bit(__I40E_DOWN_REQUESTED, &pf->state); |
| 330 | set_bit(__I40E_DOWN_REQUESTED, &vsi->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 331 | break; |
| 332 | } |
| 333 | i40e_service_event_schedule(pf); |
| 334 | pf->tx_timeout_recovery_level++; |
| 335 | } |
| 336 | |
| 337 | /** |
| 338 | * i40e_release_rx_desc - Store the new tail and head values |
| 339 | * @rx_ring: ring to bump |
| 340 | * @val: new head index |
| 341 | **/ |
| 342 | static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val) |
| 343 | { |
| 344 | rx_ring->next_to_use = val; |
| 345 | |
| 346 | /* Force memory writes to complete before letting h/w |
| 347 | * know there are new descriptors to fetch. (Only |
| 348 | * applicable for weak-ordered memory model archs, |
| 349 | * such as IA-64). |
| 350 | */ |
| 351 | wmb(); |
| 352 | writel(val, rx_ring->tail); |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * i40e_get_vsi_stats_struct - Get System Network Statistics |
| 357 | * @vsi: the VSI we care about |
| 358 | * |
| 359 | * Returns the address of the device statistics structure. |
| 360 | * The statistics are actually updated from the service task. |
| 361 | **/ |
| 362 | struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi) |
| 363 | { |
| 364 | return &vsi->net_stats; |
| 365 | } |
| 366 | |
| 367 | /** |
| 368 | * i40e_get_netdev_stats_struct - Get statistics for netdev interface |
| 369 | * @netdev: network interface device structure |
| 370 | * |
| 371 | * Returns the address of the device statistics structure. |
| 372 | * The statistics are actually updated from the service task. |
| 373 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 374 | #ifdef I40E_FCOE |
| 375 | struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 376 | struct net_device *netdev, |
| 377 | struct rtnl_link_stats64 *stats) |
| 378 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 379 | static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 380 | struct net_device *netdev, |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 381 | struct rtnl_link_stats64 *stats) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 382 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 383 | { |
| 384 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 385 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 386 | struct i40e_vsi *vsi = np->vsi; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 387 | struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi); |
| 388 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 389 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 390 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 391 | return stats; |
| 392 | |
Jesse Brandeburg | 3c325ce | 2013-12-14 03:26:45 -0800 | [diff] [blame] | 393 | if (!vsi->tx_rings) |
| 394 | return stats; |
| 395 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 396 | rcu_read_lock(); |
| 397 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 398 | u64 bytes, packets; |
| 399 | unsigned int start; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 400 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 401 | tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); |
| 402 | if (!tx_ring) |
| 403 | continue; |
| 404 | |
| 405 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 406 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 407 | packets = tx_ring->stats.packets; |
| 408 | bytes = tx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 409 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 410 | |
| 411 | stats->tx_packets += packets; |
| 412 | stats->tx_bytes += bytes; |
| 413 | rx_ring = &tx_ring[1]; |
| 414 | |
| 415 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 416 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 417 | packets = rx_ring->stats.packets; |
| 418 | bytes = rx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 419 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 420 | |
| 421 | stats->rx_packets += packets; |
| 422 | stats->rx_bytes += bytes; |
| 423 | } |
| 424 | rcu_read_unlock(); |
| 425 | |
Akeem G Abodunrin | a5282f4 | 2014-05-10 04:49:03 +0000 | [diff] [blame] | 426 | /* following stats updated by i40e_watchdog_subtask() */ |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 427 | stats->multicast = vsi_stats->multicast; |
| 428 | stats->tx_errors = vsi_stats->tx_errors; |
| 429 | stats->tx_dropped = vsi_stats->tx_dropped; |
| 430 | stats->rx_errors = vsi_stats->rx_errors; |
| 431 | stats->rx_crc_errors = vsi_stats->rx_crc_errors; |
| 432 | stats->rx_length_errors = vsi_stats->rx_length_errors; |
| 433 | |
| 434 | return stats; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | /** |
| 438 | * i40e_vsi_reset_stats - Resets all stats of the given vsi |
| 439 | * @vsi: the VSI to have its stats reset |
| 440 | **/ |
| 441 | void i40e_vsi_reset_stats(struct i40e_vsi *vsi) |
| 442 | { |
| 443 | struct rtnl_link_stats64 *ns; |
| 444 | int i; |
| 445 | |
| 446 | if (!vsi) |
| 447 | return; |
| 448 | |
| 449 | ns = i40e_get_vsi_stats_struct(vsi); |
| 450 | memset(ns, 0, sizeof(*ns)); |
| 451 | memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets)); |
| 452 | memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats)); |
| 453 | memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets)); |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 454 | if (vsi->rx_rings && vsi->rx_rings[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 455 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 456 | memset(&vsi->rx_rings[i]->stats, 0 , |
| 457 | sizeof(vsi->rx_rings[i]->stats)); |
| 458 | memset(&vsi->rx_rings[i]->rx_stats, 0 , |
| 459 | sizeof(vsi->rx_rings[i]->rx_stats)); |
| 460 | memset(&vsi->tx_rings[i]->stats, 0 , |
| 461 | sizeof(vsi->tx_rings[i]->stats)); |
| 462 | memset(&vsi->tx_rings[i]->tx_stats, 0, |
| 463 | sizeof(vsi->tx_rings[i]->tx_stats)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 464 | } |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 465 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 466 | vsi->stat_offsets_loaded = false; |
| 467 | } |
| 468 | |
| 469 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 470 | * 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] | 471 | * @pf: the PF to be reset |
| 472 | **/ |
| 473 | void i40e_pf_reset_stats(struct i40e_pf *pf) |
| 474 | { |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 475 | int i; |
| 476 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 477 | memset(&pf->stats, 0, sizeof(pf->stats)); |
| 478 | memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); |
| 479 | pf->stat_offsets_loaded = false; |
Shannon Nelson | e91fdf7 | 2014-06-03 23:50:18 +0000 | [diff] [blame] | 480 | |
| 481 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 482 | if (pf->veb[i]) { |
| 483 | memset(&pf->veb[i]->stats, 0, |
| 484 | sizeof(pf->veb[i]->stats)); |
| 485 | memset(&pf->veb[i]->stats_offsets, 0, |
| 486 | sizeof(pf->veb[i]->stats_offsets)); |
| 487 | pf->veb[i]->stat_offsets_loaded = false; |
| 488 | } |
| 489 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | /** |
| 493 | * i40e_stat_update48 - read and update a 48 bit stat from the chip |
| 494 | * @hw: ptr to the hardware info |
| 495 | * @hireg: the high 32 bit reg to read |
| 496 | * @loreg: the low 32 bit reg to read |
| 497 | * @offset_loaded: has the initial offset been loaded yet |
| 498 | * @offset: ptr to current offset value |
| 499 | * @stat: ptr to the stat |
| 500 | * |
| 501 | * Since the device stats are not reset at PFReset, they likely will not |
| 502 | * be zeroed when the driver starts. We'll save the first values read |
| 503 | * and use them as offsets to be subtracted from the raw values in order |
| 504 | * to report stats that count from zero. In the process, we also manage |
| 505 | * the potential roll-over. |
| 506 | **/ |
| 507 | static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, |
| 508 | bool offset_loaded, u64 *offset, u64 *stat) |
| 509 | { |
| 510 | u64 new_data; |
| 511 | |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 512 | if (hw->device_id == I40E_DEV_ID_QEMU) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 513 | new_data = rd32(hw, loreg); |
| 514 | new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; |
| 515 | } else { |
| 516 | new_data = rd64(hw, loreg); |
| 517 | } |
| 518 | if (!offset_loaded) |
| 519 | *offset = new_data; |
| 520 | if (likely(new_data >= *offset)) |
| 521 | *stat = new_data - *offset; |
| 522 | else |
| 523 | *stat = (new_data + ((u64)1 << 48)) - *offset; |
| 524 | *stat &= 0xFFFFFFFFFFFFULL; |
| 525 | } |
| 526 | |
| 527 | /** |
| 528 | * i40e_stat_update32 - read and update a 32 bit stat from the chip |
| 529 | * @hw: ptr to the hardware info |
| 530 | * @reg: the hw reg to read |
| 531 | * @offset_loaded: has the initial offset been loaded yet |
| 532 | * @offset: ptr to current offset value |
| 533 | * @stat: ptr to the stat |
| 534 | **/ |
| 535 | static void i40e_stat_update32(struct i40e_hw *hw, u32 reg, |
| 536 | bool offset_loaded, u64 *offset, u64 *stat) |
| 537 | { |
| 538 | u32 new_data; |
| 539 | |
| 540 | new_data = rd32(hw, reg); |
| 541 | if (!offset_loaded) |
| 542 | *offset = new_data; |
| 543 | if (likely(new_data >= *offset)) |
| 544 | *stat = (u32)(new_data - *offset); |
| 545 | else |
| 546 | *stat = (u32)((new_data + ((u64)1 << 32)) - *offset); |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. |
| 551 | * @vsi: the VSI to be updated |
| 552 | **/ |
| 553 | void i40e_update_eth_stats(struct i40e_vsi *vsi) |
| 554 | { |
| 555 | int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); |
| 556 | struct i40e_pf *pf = vsi->back; |
| 557 | struct i40e_hw *hw = &pf->hw; |
| 558 | struct i40e_eth_stats *oes; |
| 559 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 560 | |
| 561 | es = &vsi->eth_stats; |
| 562 | oes = &vsi->eth_stats_offsets; |
| 563 | |
| 564 | /* Gather up the stats that the hw collects */ |
| 565 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 566 | vsi->stat_offsets_loaded, |
| 567 | &oes->tx_errors, &es->tx_errors); |
| 568 | i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), |
| 569 | vsi->stat_offsets_loaded, |
| 570 | &oes->rx_discards, &es->rx_discards); |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 571 | i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx), |
| 572 | vsi->stat_offsets_loaded, |
| 573 | &oes->rx_unknown_protocol, &es->rx_unknown_protocol); |
| 574 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 575 | vsi->stat_offsets_loaded, |
| 576 | &oes->tx_errors, &es->tx_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 577 | |
| 578 | i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), |
| 579 | I40E_GLV_GORCL(stat_idx), |
| 580 | vsi->stat_offsets_loaded, |
| 581 | &oes->rx_bytes, &es->rx_bytes); |
| 582 | i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), |
| 583 | I40E_GLV_UPRCL(stat_idx), |
| 584 | vsi->stat_offsets_loaded, |
| 585 | &oes->rx_unicast, &es->rx_unicast); |
| 586 | i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), |
| 587 | I40E_GLV_MPRCL(stat_idx), |
| 588 | vsi->stat_offsets_loaded, |
| 589 | &oes->rx_multicast, &es->rx_multicast); |
| 590 | i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), |
| 591 | I40E_GLV_BPRCL(stat_idx), |
| 592 | vsi->stat_offsets_loaded, |
| 593 | &oes->rx_broadcast, &es->rx_broadcast); |
| 594 | |
| 595 | i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), |
| 596 | I40E_GLV_GOTCL(stat_idx), |
| 597 | vsi->stat_offsets_loaded, |
| 598 | &oes->tx_bytes, &es->tx_bytes); |
| 599 | i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), |
| 600 | I40E_GLV_UPTCL(stat_idx), |
| 601 | vsi->stat_offsets_loaded, |
| 602 | &oes->tx_unicast, &es->tx_unicast); |
| 603 | i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), |
| 604 | I40E_GLV_MPTCL(stat_idx), |
| 605 | vsi->stat_offsets_loaded, |
| 606 | &oes->tx_multicast, &es->tx_multicast); |
| 607 | i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), |
| 608 | I40E_GLV_BPTCL(stat_idx), |
| 609 | vsi->stat_offsets_loaded, |
| 610 | &oes->tx_broadcast, &es->tx_broadcast); |
| 611 | vsi->stat_offsets_loaded = true; |
| 612 | } |
| 613 | |
| 614 | /** |
| 615 | * i40e_update_veb_stats - Update Switch component statistics |
| 616 | * @veb: the VEB being updated |
| 617 | **/ |
| 618 | static void i40e_update_veb_stats(struct i40e_veb *veb) |
| 619 | { |
| 620 | struct i40e_pf *pf = veb->pf; |
| 621 | struct i40e_hw *hw = &pf->hw; |
| 622 | struct i40e_eth_stats *oes; |
| 623 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 624 | int idx = 0; |
| 625 | |
| 626 | idx = veb->stats_idx; |
| 627 | es = &veb->stats; |
| 628 | oes = &veb->stats_offsets; |
| 629 | |
| 630 | /* Gather up the stats that the hw collects */ |
| 631 | i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), |
| 632 | veb->stat_offsets_loaded, |
| 633 | &oes->tx_discards, &es->tx_discards); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 634 | if (hw->revision_id > 0) |
| 635 | i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), |
| 636 | veb->stat_offsets_loaded, |
| 637 | &oes->rx_unknown_protocol, |
| 638 | &es->rx_unknown_protocol); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 639 | i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), |
| 640 | veb->stat_offsets_loaded, |
| 641 | &oes->rx_bytes, &es->rx_bytes); |
| 642 | i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), |
| 643 | veb->stat_offsets_loaded, |
| 644 | &oes->rx_unicast, &es->rx_unicast); |
| 645 | i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), |
| 646 | veb->stat_offsets_loaded, |
| 647 | &oes->rx_multicast, &es->rx_multicast); |
| 648 | i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), |
| 649 | veb->stat_offsets_loaded, |
| 650 | &oes->rx_broadcast, &es->rx_broadcast); |
| 651 | |
| 652 | i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), |
| 653 | veb->stat_offsets_loaded, |
| 654 | &oes->tx_bytes, &es->tx_bytes); |
| 655 | i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), |
| 656 | veb->stat_offsets_loaded, |
| 657 | &oes->tx_unicast, &es->tx_unicast); |
| 658 | i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), |
| 659 | veb->stat_offsets_loaded, |
| 660 | &oes->tx_multicast, &es->tx_multicast); |
| 661 | i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), |
| 662 | veb->stat_offsets_loaded, |
| 663 | &oes->tx_broadcast, &es->tx_broadcast); |
| 664 | veb->stat_offsets_loaded = true; |
| 665 | } |
| 666 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 667 | #ifdef I40E_FCOE |
| 668 | /** |
| 669 | * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters. |
| 670 | * @vsi: the VSI that is capable of doing FCoE |
| 671 | **/ |
| 672 | static void i40e_update_fcoe_stats(struct i40e_vsi *vsi) |
| 673 | { |
| 674 | struct i40e_pf *pf = vsi->back; |
| 675 | struct i40e_hw *hw = &pf->hw; |
| 676 | struct i40e_fcoe_stats *ofs; |
| 677 | struct i40e_fcoe_stats *fs; /* device's eth stats */ |
| 678 | int idx; |
| 679 | |
| 680 | if (vsi->type != I40E_VSI_FCOE) |
| 681 | return; |
| 682 | |
| 683 | idx = (pf->pf_seid - I40E_BASE_PF_SEID) + I40E_FCOE_PF_STAT_OFFSET; |
| 684 | fs = &vsi->fcoe_stats; |
| 685 | ofs = &vsi->fcoe_stats_offsets; |
| 686 | |
| 687 | i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx), |
| 688 | vsi->fcoe_stat_offsets_loaded, |
| 689 | &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets); |
| 690 | i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx), |
| 691 | vsi->fcoe_stat_offsets_loaded, |
| 692 | &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords); |
| 693 | i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx), |
| 694 | vsi->fcoe_stat_offsets_loaded, |
| 695 | &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped); |
| 696 | i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx), |
| 697 | vsi->fcoe_stat_offsets_loaded, |
| 698 | &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets); |
| 699 | i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx), |
| 700 | vsi->fcoe_stat_offsets_loaded, |
| 701 | &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords); |
| 702 | i40e_stat_update32(hw, I40E_GL_FCOECRC(idx), |
| 703 | vsi->fcoe_stat_offsets_loaded, |
| 704 | &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc); |
| 705 | i40e_stat_update32(hw, I40E_GL_FCOELAST(idx), |
| 706 | vsi->fcoe_stat_offsets_loaded, |
| 707 | &ofs->fcoe_last_error, &fs->fcoe_last_error); |
| 708 | i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx), |
| 709 | vsi->fcoe_stat_offsets_loaded, |
| 710 | &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count); |
| 711 | |
| 712 | vsi->fcoe_stat_offsets_loaded = true; |
| 713 | } |
| 714 | |
| 715 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 716 | /** |
| 717 | * i40e_update_link_xoff_rx - Update XOFF received in link flow control mode |
| 718 | * @pf: the corresponding PF |
| 719 | * |
| 720 | * Update the Rx XOFF counter (PAUSE frames) in link flow control mode |
| 721 | **/ |
| 722 | static void i40e_update_link_xoff_rx(struct i40e_pf *pf) |
| 723 | { |
| 724 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 725 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 726 | struct i40e_hw *hw = &pf->hw; |
| 727 | u64 xoff = 0; |
| 728 | u16 i, v; |
| 729 | |
| 730 | if ((hw->fc.current_mode != I40E_FC_FULL) && |
| 731 | (hw->fc.current_mode != I40E_FC_RX_PAUSE)) |
| 732 | return; |
| 733 | |
| 734 | xoff = nsd->link_xoff_rx; |
| 735 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), |
| 736 | pf->stat_offsets_loaded, |
| 737 | &osd->link_xoff_rx, &nsd->link_xoff_rx); |
| 738 | |
| 739 | /* No new LFC xoff rx */ |
| 740 | if (!(nsd->link_xoff_rx - xoff)) |
| 741 | return; |
| 742 | |
| 743 | /* Clear the __I40E_HANG_CHECK_ARMED bit for all Tx rings */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 744 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 745 | struct i40e_vsi *vsi = pf->vsi[v]; |
| 746 | |
Mitch Williams | ddfda80 | 2014-05-10 04:49:10 +0000 | [diff] [blame] | 747 | if (!vsi || !vsi->tx_rings[0]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 748 | continue; |
| 749 | |
| 750 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 751 | struct i40e_ring *ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 752 | clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state); |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | /** |
| 758 | * i40e_update_prio_xoff_rx - Update XOFF received in PFC mode |
| 759 | * @pf: the corresponding PF |
| 760 | * |
| 761 | * Update the Rx XOFF counter (PAUSE frames) in PFC mode |
| 762 | **/ |
| 763 | static void i40e_update_prio_xoff_rx(struct i40e_pf *pf) |
| 764 | { |
| 765 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 766 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 767 | bool xoff[I40E_MAX_TRAFFIC_CLASS] = {false}; |
| 768 | struct i40e_dcbx_config *dcb_cfg; |
| 769 | struct i40e_hw *hw = &pf->hw; |
| 770 | u16 i, v; |
| 771 | u8 tc; |
| 772 | |
| 773 | dcb_cfg = &hw->local_dcbx_config; |
| 774 | |
Neerav Parikh | e120814 | 2015-04-16 20:05:58 -0400 | [diff] [blame] | 775 | /* Collect Link XOFF stats when PFC is disabled */ |
| 776 | if (!dcb_cfg->pfc.pfcenable) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 777 | i40e_update_link_xoff_rx(pf); |
| 778 | return; |
| 779 | } |
| 780 | |
| 781 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 782 | u64 prio_xoff = nsd->priority_xoff_rx[i]; |
| 783 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), |
| 784 | pf->stat_offsets_loaded, |
| 785 | &osd->priority_xoff_rx[i], |
| 786 | &nsd->priority_xoff_rx[i]); |
| 787 | |
| 788 | /* No new PFC xoff rx */ |
| 789 | if (!(nsd->priority_xoff_rx[i] - prio_xoff)) |
| 790 | continue; |
| 791 | /* Get the TC for given priority */ |
| 792 | tc = dcb_cfg->etscfg.prioritytable[i]; |
| 793 | xoff[tc] = true; |
| 794 | } |
| 795 | |
| 796 | /* Clear the __I40E_HANG_CHECK_ARMED bit for Tx rings */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 797 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 798 | struct i40e_vsi *vsi = pf->vsi[v]; |
| 799 | |
Mitch Williams | ddfda80 | 2014-05-10 04:49:10 +0000 | [diff] [blame] | 800 | if (!vsi || !vsi->tx_rings[0]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 801 | continue; |
| 802 | |
| 803 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 804 | struct i40e_ring *ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 805 | |
| 806 | tc = ring->dcb_tc; |
| 807 | if (xoff[tc]) |
| 808 | clear_bit(__I40E_HANG_CHECK_ARMED, |
| 809 | &ring->state); |
| 810 | } |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 815 | * i40e_update_vsi_stats - Update the vsi statistics counters. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 816 | * @vsi: the VSI to be updated |
| 817 | * |
| 818 | * There are a few instances where we store the same stat in a |
| 819 | * couple of different structs. This is partly because we have |
| 820 | * the netdev stats that need to be filled out, which is slightly |
| 821 | * different from the "eth_stats" defined by the chip and used in |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 822 | * VF communications. We sort it out here. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 823 | **/ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 824 | static void i40e_update_vsi_stats(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 825 | { |
| 826 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 827 | struct rtnl_link_stats64 *ons; |
| 828 | struct rtnl_link_stats64 *ns; /* netdev stats */ |
| 829 | struct i40e_eth_stats *oes; |
| 830 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 831 | u32 tx_restart, tx_busy; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 832 | struct i40e_ring *p; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 833 | u32 rx_page, rx_buf; |
Akeem G Abodunrin | bf00b37 | 2014-10-17 03:14:39 +0000 | [diff] [blame] | 834 | u64 bytes, packets; |
| 835 | unsigned int start; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 836 | u64 rx_p, rx_b; |
| 837 | u64 tx_p, tx_b; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 838 | u16 q; |
| 839 | |
| 840 | if (test_bit(__I40E_DOWN, &vsi->state) || |
| 841 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 842 | return; |
| 843 | |
| 844 | ns = i40e_get_vsi_stats_struct(vsi); |
| 845 | ons = &vsi->net_stats_offsets; |
| 846 | es = &vsi->eth_stats; |
| 847 | oes = &vsi->eth_stats_offsets; |
| 848 | |
| 849 | /* Gather up the netdev and vsi stats that the driver collects |
| 850 | * on the fly during packet processing |
| 851 | */ |
| 852 | rx_b = rx_p = 0; |
| 853 | tx_b = tx_p = 0; |
| 854 | tx_restart = tx_busy = 0; |
| 855 | rx_page = 0; |
| 856 | rx_buf = 0; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 857 | rcu_read_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 858 | for (q = 0; q < vsi->num_queue_pairs; q++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 859 | /* locate Tx ring */ |
| 860 | p = ACCESS_ONCE(vsi->tx_rings[q]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 861 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 862 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 863 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 864 | packets = p->stats.packets; |
| 865 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 866 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 867 | tx_b += bytes; |
| 868 | tx_p += packets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 869 | tx_restart += p->tx_stats.restart_queue; |
| 870 | tx_busy += p->tx_stats.tx_busy; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 871 | |
| 872 | /* Rx queue is part of the same block as Tx queue */ |
| 873 | p = &p[1]; |
| 874 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 875 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 876 | packets = p->stats.packets; |
| 877 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 878 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 879 | rx_b += bytes; |
| 880 | rx_p += packets; |
Mitch Williams | 420136c | 2013-12-18 13:45:59 +0000 | [diff] [blame] | 881 | rx_buf += p->rx_stats.alloc_buff_failed; |
| 882 | rx_page += p->rx_stats.alloc_page_failed; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 883 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 884 | rcu_read_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 885 | vsi->tx_restart = tx_restart; |
| 886 | vsi->tx_busy = tx_busy; |
| 887 | vsi->rx_page_failed = rx_page; |
| 888 | vsi->rx_buf_failed = rx_buf; |
| 889 | |
| 890 | ns->rx_packets = rx_p; |
| 891 | ns->rx_bytes = rx_b; |
| 892 | ns->tx_packets = tx_p; |
| 893 | ns->tx_bytes = tx_b; |
| 894 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 895 | /* update netdev stats from eth stats */ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 896 | i40e_update_eth_stats(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 897 | ons->tx_errors = oes->tx_errors; |
| 898 | ns->tx_errors = es->tx_errors; |
| 899 | ons->multicast = oes->rx_multicast; |
| 900 | ns->multicast = es->rx_multicast; |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 901 | ons->rx_dropped = oes->rx_discards; |
| 902 | ns->rx_dropped = es->rx_discards; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 903 | ons->tx_dropped = oes->tx_discards; |
| 904 | ns->tx_dropped = es->tx_discards; |
| 905 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 906 | /* pull in a couple PF stats if this is the main vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 907 | if (vsi == pf->vsi[pf->lan_vsi]) { |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 908 | ns->rx_crc_errors = pf->stats.crc_errors; |
| 909 | ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes; |
| 910 | ns->rx_length_errors = pf->stats.rx_length_errors; |
| 911 | } |
| 912 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 913 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 914 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 915 | * i40e_update_pf_stats - Update the PF statistics counters. |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 916 | * @pf: the PF to be updated |
| 917 | **/ |
| 918 | static void i40e_update_pf_stats(struct i40e_pf *pf) |
| 919 | { |
| 920 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 921 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 922 | struct i40e_hw *hw = &pf->hw; |
| 923 | u32 val; |
| 924 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 925 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 926 | i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), |
| 927 | I40E_GLPRT_GORCL(hw->port), |
| 928 | pf->stat_offsets_loaded, |
| 929 | &osd->eth.rx_bytes, &nsd->eth.rx_bytes); |
| 930 | i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), |
| 931 | I40E_GLPRT_GOTCL(hw->port), |
| 932 | pf->stat_offsets_loaded, |
| 933 | &osd->eth.tx_bytes, &nsd->eth.tx_bytes); |
| 934 | i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), |
| 935 | pf->stat_offsets_loaded, |
| 936 | &osd->eth.rx_discards, |
| 937 | &nsd->eth.rx_discards); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 938 | i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port), |
| 939 | I40E_GLPRT_UPRCL(hw->port), |
| 940 | pf->stat_offsets_loaded, |
| 941 | &osd->eth.rx_unicast, |
| 942 | &nsd->eth.rx_unicast); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 943 | i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), |
| 944 | I40E_GLPRT_MPRCL(hw->port), |
| 945 | pf->stat_offsets_loaded, |
| 946 | &osd->eth.rx_multicast, |
| 947 | &nsd->eth.rx_multicast); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 948 | i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port), |
| 949 | I40E_GLPRT_BPRCL(hw->port), |
| 950 | pf->stat_offsets_loaded, |
| 951 | &osd->eth.rx_broadcast, |
| 952 | &nsd->eth.rx_broadcast); |
| 953 | i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port), |
| 954 | I40E_GLPRT_UPTCL(hw->port), |
| 955 | pf->stat_offsets_loaded, |
| 956 | &osd->eth.tx_unicast, |
| 957 | &nsd->eth.tx_unicast); |
| 958 | i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port), |
| 959 | I40E_GLPRT_MPTCL(hw->port), |
| 960 | pf->stat_offsets_loaded, |
| 961 | &osd->eth.tx_multicast, |
| 962 | &nsd->eth.tx_multicast); |
| 963 | i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port), |
| 964 | I40E_GLPRT_BPTCL(hw->port), |
| 965 | pf->stat_offsets_loaded, |
| 966 | &osd->eth.tx_broadcast, |
| 967 | &nsd->eth.tx_broadcast); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 968 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 969 | i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), |
| 970 | pf->stat_offsets_loaded, |
| 971 | &osd->tx_dropped_link_down, |
| 972 | &nsd->tx_dropped_link_down); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 973 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 974 | i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), |
| 975 | pf->stat_offsets_loaded, |
| 976 | &osd->crc_errors, &nsd->crc_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 977 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 978 | i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), |
| 979 | pf->stat_offsets_loaded, |
| 980 | &osd->illegal_bytes, &nsd->illegal_bytes); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 981 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 982 | i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), |
| 983 | pf->stat_offsets_loaded, |
| 984 | &osd->mac_local_faults, |
| 985 | &nsd->mac_local_faults); |
| 986 | i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), |
| 987 | pf->stat_offsets_loaded, |
| 988 | &osd->mac_remote_faults, |
| 989 | &nsd->mac_remote_faults); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 990 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 991 | i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), |
| 992 | pf->stat_offsets_loaded, |
| 993 | &osd->rx_length_errors, |
| 994 | &nsd->rx_length_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 995 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 996 | i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), |
| 997 | pf->stat_offsets_loaded, |
| 998 | &osd->link_xon_rx, &nsd->link_xon_rx); |
| 999 | i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), |
| 1000 | pf->stat_offsets_loaded, |
| 1001 | &osd->link_xon_tx, &nsd->link_xon_tx); |
| 1002 | i40e_update_prio_xoff_rx(pf); /* handles I40E_GLPRT_LXOFFRXC */ |
| 1003 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), |
| 1004 | pf->stat_offsets_loaded, |
| 1005 | &osd->link_xoff_tx, &nsd->link_xoff_tx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1006 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1007 | for (i = 0; i < 8; i++) { |
| 1008 | i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1009 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1010 | &osd->priority_xon_rx[i], |
| 1011 | &nsd->priority_xon_rx[i]); |
| 1012 | i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1013 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1014 | &osd->priority_xon_tx[i], |
| 1015 | &nsd->priority_xon_tx[i]); |
| 1016 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1017 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1018 | &osd->priority_xoff_tx[i], |
| 1019 | &nsd->priority_xoff_tx[i]); |
| 1020 | i40e_stat_update32(hw, |
| 1021 | I40E_GLPRT_RXON2OFFCNT(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_xon_2_xoff[i], |
| 1024 | &nsd->priority_xon_2_xoff[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1027 | i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), |
| 1028 | I40E_GLPRT_PRC64L(hw->port), |
| 1029 | pf->stat_offsets_loaded, |
| 1030 | &osd->rx_size_64, &nsd->rx_size_64); |
| 1031 | i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), |
| 1032 | I40E_GLPRT_PRC127L(hw->port), |
| 1033 | pf->stat_offsets_loaded, |
| 1034 | &osd->rx_size_127, &nsd->rx_size_127); |
| 1035 | i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), |
| 1036 | I40E_GLPRT_PRC255L(hw->port), |
| 1037 | pf->stat_offsets_loaded, |
| 1038 | &osd->rx_size_255, &nsd->rx_size_255); |
| 1039 | i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), |
| 1040 | I40E_GLPRT_PRC511L(hw->port), |
| 1041 | pf->stat_offsets_loaded, |
| 1042 | &osd->rx_size_511, &nsd->rx_size_511); |
| 1043 | i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), |
| 1044 | I40E_GLPRT_PRC1023L(hw->port), |
| 1045 | pf->stat_offsets_loaded, |
| 1046 | &osd->rx_size_1023, &nsd->rx_size_1023); |
| 1047 | i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), |
| 1048 | I40E_GLPRT_PRC1522L(hw->port), |
| 1049 | pf->stat_offsets_loaded, |
| 1050 | &osd->rx_size_1522, &nsd->rx_size_1522); |
| 1051 | i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), |
| 1052 | I40E_GLPRT_PRC9522L(hw->port), |
| 1053 | pf->stat_offsets_loaded, |
| 1054 | &osd->rx_size_big, &nsd->rx_size_big); |
| 1055 | |
| 1056 | i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), |
| 1057 | I40E_GLPRT_PTC64L(hw->port), |
| 1058 | pf->stat_offsets_loaded, |
| 1059 | &osd->tx_size_64, &nsd->tx_size_64); |
| 1060 | i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), |
| 1061 | I40E_GLPRT_PTC127L(hw->port), |
| 1062 | pf->stat_offsets_loaded, |
| 1063 | &osd->tx_size_127, &nsd->tx_size_127); |
| 1064 | i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), |
| 1065 | I40E_GLPRT_PTC255L(hw->port), |
| 1066 | pf->stat_offsets_loaded, |
| 1067 | &osd->tx_size_255, &nsd->tx_size_255); |
| 1068 | i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), |
| 1069 | I40E_GLPRT_PTC511L(hw->port), |
| 1070 | pf->stat_offsets_loaded, |
| 1071 | &osd->tx_size_511, &nsd->tx_size_511); |
| 1072 | i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), |
| 1073 | I40E_GLPRT_PTC1023L(hw->port), |
| 1074 | pf->stat_offsets_loaded, |
| 1075 | &osd->tx_size_1023, &nsd->tx_size_1023); |
| 1076 | i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), |
| 1077 | I40E_GLPRT_PTC1522L(hw->port), |
| 1078 | pf->stat_offsets_loaded, |
| 1079 | &osd->tx_size_1522, &nsd->tx_size_1522); |
| 1080 | i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), |
| 1081 | I40E_GLPRT_PTC9522L(hw->port), |
| 1082 | pf->stat_offsets_loaded, |
| 1083 | &osd->tx_size_big, &nsd->tx_size_big); |
| 1084 | |
| 1085 | i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), |
| 1086 | pf->stat_offsets_loaded, |
| 1087 | &osd->rx_undersize, &nsd->rx_undersize); |
| 1088 | i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), |
| 1089 | pf->stat_offsets_loaded, |
| 1090 | &osd->rx_fragments, &nsd->rx_fragments); |
| 1091 | i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), |
| 1092 | pf->stat_offsets_loaded, |
| 1093 | &osd->rx_oversize, &nsd->rx_oversize); |
| 1094 | i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), |
| 1095 | pf->stat_offsets_loaded, |
| 1096 | &osd->rx_jabber, &nsd->rx_jabber); |
| 1097 | |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1098 | /* FDIR stats */ |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1099 | i40e_stat_update32(hw, |
| 1100 | 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] | 1101 | pf->stat_offsets_loaded, |
| 1102 | &osd->fd_atr_match, &nsd->fd_atr_match); |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 1103 | i40e_stat_update32(hw, |
| 1104 | 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] | 1105 | pf->stat_offsets_loaded, |
| 1106 | &osd->fd_sb_match, &nsd->fd_sb_match); |
Anjali Singhai Jain | 60ccd45 | 2015-04-16 20:06:01 -0400 | [diff] [blame] | 1107 | i40e_stat_update32(hw, |
| 1108 | I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)), |
| 1109 | pf->stat_offsets_loaded, |
| 1110 | &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match); |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1111 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1112 | val = rd32(hw, I40E_PRTPM_EEE_STAT); |
| 1113 | nsd->tx_lpi_status = |
| 1114 | (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >> |
| 1115 | I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT; |
| 1116 | nsd->rx_lpi_status = |
| 1117 | (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >> |
| 1118 | I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT; |
| 1119 | i40e_stat_update32(hw, I40E_PRTPM_TLPIC, |
| 1120 | pf->stat_offsets_loaded, |
| 1121 | &osd->tx_lpi_count, &nsd->tx_lpi_count); |
| 1122 | i40e_stat_update32(hw, I40E_PRTPM_RLPIC, |
| 1123 | pf->stat_offsets_loaded, |
| 1124 | &osd->rx_lpi_count, &nsd->rx_lpi_count); |
| 1125 | |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame^] | 1126 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED && |
| 1127 | !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) |
| 1128 | nsd->fd_sb_status = true; |
| 1129 | else |
| 1130 | nsd->fd_sb_status = false; |
| 1131 | |
| 1132 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED && |
| 1133 | !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 1134 | nsd->fd_atr_status = true; |
| 1135 | else |
| 1136 | nsd->fd_atr_status = false; |
| 1137 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1138 | pf->stat_offsets_loaded = true; |
| 1139 | } |
| 1140 | |
| 1141 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1142 | * i40e_update_stats - Update the various statistics counters. |
| 1143 | * @vsi: the VSI to be updated |
| 1144 | * |
| 1145 | * Update the various stats for this VSI and its related entities. |
| 1146 | **/ |
| 1147 | void i40e_update_stats(struct i40e_vsi *vsi) |
| 1148 | { |
| 1149 | struct i40e_pf *pf = vsi->back; |
| 1150 | |
| 1151 | if (vsi == pf->vsi[pf->lan_vsi]) |
| 1152 | i40e_update_pf_stats(pf); |
| 1153 | |
| 1154 | i40e_update_vsi_stats(vsi); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1155 | #ifdef I40E_FCOE |
| 1156 | i40e_update_fcoe_stats(vsi); |
| 1157 | #endif |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1161 | * i40e_find_filter - Search VSI filter list for specific mac/vlan filter |
| 1162 | * @vsi: the VSI to be searched |
| 1163 | * @macaddr: the MAC address |
| 1164 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1165 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1166 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1167 | * |
| 1168 | * Returns ptr to the filter object or NULL |
| 1169 | **/ |
| 1170 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, |
| 1171 | u8 *macaddr, s16 vlan, |
| 1172 | bool is_vf, bool is_netdev) |
| 1173 | { |
| 1174 | struct i40e_mac_filter *f; |
| 1175 | |
| 1176 | if (!vsi || !macaddr) |
| 1177 | return NULL; |
| 1178 | |
| 1179 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1180 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1181 | (vlan == f->vlan) && |
| 1182 | (!is_vf || f->is_vf) && |
| 1183 | (!is_netdev || f->is_netdev)) |
| 1184 | return f; |
| 1185 | } |
| 1186 | return NULL; |
| 1187 | } |
| 1188 | |
| 1189 | /** |
| 1190 | * i40e_find_mac - Find a mac addr in the macvlan filters list |
| 1191 | * @vsi: the VSI to be searched |
| 1192 | * @macaddr: the MAC address we are searching for |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1193 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1194 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1195 | * |
| 1196 | * Returns the first filter with the provided MAC address or NULL if |
| 1197 | * MAC address was not found |
| 1198 | **/ |
| 1199 | struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr, |
| 1200 | bool is_vf, bool is_netdev) |
| 1201 | { |
| 1202 | struct i40e_mac_filter *f; |
| 1203 | |
| 1204 | if (!vsi || !macaddr) |
| 1205 | return NULL; |
| 1206 | |
| 1207 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1208 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1209 | (!is_vf || f->is_vf) && |
| 1210 | (!is_netdev || f->is_netdev)) |
| 1211 | return f; |
| 1212 | } |
| 1213 | return NULL; |
| 1214 | } |
| 1215 | |
| 1216 | /** |
| 1217 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode |
| 1218 | * @vsi: the VSI to be searched |
| 1219 | * |
| 1220 | * Returns true if VSI is in vlan mode or false otherwise |
| 1221 | **/ |
| 1222 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) |
| 1223 | { |
| 1224 | struct i40e_mac_filter *f; |
| 1225 | |
| 1226 | /* Only -1 for all the filters denotes not in vlan mode |
| 1227 | * so we have to go through all the list in order to make sure |
| 1228 | */ |
| 1229 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1230 | if (f->vlan >= 0) |
| 1231 | return true; |
| 1232 | } |
| 1233 | |
| 1234 | return false; |
| 1235 | } |
| 1236 | |
| 1237 | /** |
| 1238 | * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans |
| 1239 | * @vsi: the VSI to be searched |
| 1240 | * @macaddr: the mac address to be filtered |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1241 | * @is_vf: true if it is a VF |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1242 | * @is_netdev: true if it is a netdev |
| 1243 | * |
| 1244 | * Goes through all the macvlan filters and adds a |
| 1245 | * macvlan filter for each unique vlan that already exists |
| 1246 | * |
| 1247 | * Returns first filter found on success, else NULL |
| 1248 | **/ |
| 1249 | struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1250 | bool is_vf, bool is_netdev) |
| 1251 | { |
| 1252 | struct i40e_mac_filter *f; |
| 1253 | |
| 1254 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1255 | if (!i40e_find_filter(vsi, macaddr, f->vlan, |
| 1256 | is_vf, is_netdev)) { |
| 1257 | if (!i40e_add_filter(vsi, macaddr, f->vlan, |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 1258 | is_vf, is_netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1259 | return NULL; |
| 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | return list_first_entry_or_null(&vsi->mac_filter_list, |
| 1264 | struct i40e_mac_filter, list); |
| 1265 | } |
| 1266 | |
| 1267 | /** |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1268 | * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM |
| 1269 | * @vsi: the PF Main VSI - inappropriate for any other VSI |
| 1270 | * @macaddr: the MAC address |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1271 | * |
| 1272 | * Some older firmware configurations set up a default promiscuous VLAN |
| 1273 | * filter that needs to be removed. |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1274 | **/ |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1275 | 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] | 1276 | { |
| 1277 | struct i40e_aqc_remove_macvlan_element_data element; |
| 1278 | struct i40e_pf *pf = vsi->back; |
| 1279 | i40e_status aq_ret; |
| 1280 | |
| 1281 | /* Only appropriate for the PF main VSI */ |
| 1282 | if (vsi->type != I40E_VSI_MAIN) |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1283 | return -EINVAL; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1284 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1285 | memset(&element, 0, sizeof(element)); |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1286 | ether_addr_copy(element.mac_addr, macaddr); |
| 1287 | element.vlan_tag = 0; |
| 1288 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH | |
| 1289 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
| 1290 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1291 | if (aq_ret) |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1292 | return -ENOENT; |
| 1293 | |
| 1294 | return 0; |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1298 | * i40e_add_filter - Add a mac/vlan filter to the VSI |
| 1299 | * @vsi: the VSI to be searched |
| 1300 | * @macaddr: the MAC address |
| 1301 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1302 | * @is_vf: make sure its a VF filter, else doesn't matter |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1303 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1304 | * |
| 1305 | * Returns ptr to the filter object or NULL when no memory available. |
| 1306 | **/ |
| 1307 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, |
| 1308 | u8 *macaddr, s16 vlan, |
| 1309 | bool is_vf, bool is_netdev) |
| 1310 | { |
| 1311 | struct i40e_mac_filter *f; |
| 1312 | |
| 1313 | if (!vsi || !macaddr) |
| 1314 | return NULL; |
| 1315 | |
| 1316 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1317 | if (!f) { |
| 1318 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1319 | if (!f) |
| 1320 | goto add_filter_out; |
| 1321 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1322 | ether_addr_copy(f->macaddr, macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1323 | f->vlan = vlan; |
| 1324 | f->changed = true; |
| 1325 | |
| 1326 | INIT_LIST_HEAD(&f->list); |
| 1327 | list_add(&f->list, &vsi->mac_filter_list); |
| 1328 | } |
| 1329 | |
| 1330 | /* increment counter and add a new flag if needed */ |
| 1331 | if (is_vf) { |
| 1332 | if (!f->is_vf) { |
| 1333 | f->is_vf = true; |
| 1334 | f->counter++; |
| 1335 | } |
| 1336 | } else if (is_netdev) { |
| 1337 | if (!f->is_netdev) { |
| 1338 | f->is_netdev = true; |
| 1339 | f->counter++; |
| 1340 | } |
| 1341 | } else { |
| 1342 | f->counter++; |
| 1343 | } |
| 1344 | |
| 1345 | /* changed tells sync_filters_subtask to |
| 1346 | * push the filter down to the firmware |
| 1347 | */ |
| 1348 | if (f->changed) { |
| 1349 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1350 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1351 | } |
| 1352 | |
| 1353 | add_filter_out: |
| 1354 | return f; |
| 1355 | } |
| 1356 | |
| 1357 | /** |
| 1358 | * i40e_del_filter - Remove a mac/vlan filter from the VSI |
| 1359 | * @vsi: the VSI to be searched |
| 1360 | * @macaddr: the MAC address |
| 1361 | * @vlan: the vlan |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1362 | * @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] | 1363 | * @is_netdev: make sure it's a netdev filter, else doesn't matter |
| 1364 | **/ |
| 1365 | void i40e_del_filter(struct i40e_vsi *vsi, |
| 1366 | u8 *macaddr, s16 vlan, |
| 1367 | bool is_vf, bool is_netdev) |
| 1368 | { |
| 1369 | struct i40e_mac_filter *f; |
| 1370 | |
| 1371 | if (!vsi || !macaddr) |
| 1372 | return; |
| 1373 | |
| 1374 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1375 | if (!f || f->counter == 0) |
| 1376 | return; |
| 1377 | |
| 1378 | if (is_vf) { |
| 1379 | if (f->is_vf) { |
| 1380 | f->is_vf = false; |
| 1381 | f->counter--; |
| 1382 | } |
| 1383 | } else if (is_netdev) { |
| 1384 | if (f->is_netdev) { |
| 1385 | f->is_netdev = false; |
| 1386 | f->counter--; |
| 1387 | } |
| 1388 | } else { |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 1389 | /* 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] | 1390 | int min_f = 0; |
| 1391 | min_f += (f->is_vf ? 1 : 0); |
| 1392 | min_f += (f->is_netdev ? 1 : 0); |
| 1393 | |
| 1394 | if (f->counter > min_f) |
| 1395 | f->counter--; |
| 1396 | } |
| 1397 | |
| 1398 | /* counter == 0 tells sync_filters_subtask to |
| 1399 | * remove the filter from the firmware's list |
| 1400 | */ |
| 1401 | if (f->counter == 0) { |
| 1402 | f->changed = true; |
| 1403 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1404 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | /** |
| 1409 | * i40e_set_mac - NDO callback to set mac address |
| 1410 | * @netdev: network interface device structure |
| 1411 | * @p: pointer to an address structure |
| 1412 | * |
| 1413 | * Returns 0 on success, negative on failure |
| 1414 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1415 | #ifdef I40E_FCOE |
| 1416 | int i40e_set_mac(struct net_device *netdev, void *p) |
| 1417 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1418 | static int i40e_set_mac(struct net_device *netdev, void *p) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1419 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1420 | { |
| 1421 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1422 | struct i40e_vsi *vsi = np->vsi; |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1423 | struct i40e_pf *pf = vsi->back; |
| 1424 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1425 | struct sockaddr *addr = p; |
| 1426 | struct i40e_mac_filter *f; |
| 1427 | |
| 1428 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1429 | return -EADDRNOTAVAIL; |
| 1430 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1431 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) { |
| 1432 | netdev_info(netdev, "already using mac address %pM\n", |
| 1433 | addr->sa_data); |
| 1434 | return 0; |
| 1435 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1436 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1437 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 1438 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 1439 | return -EADDRNOTAVAIL; |
| 1440 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1441 | if (ether_addr_equal(hw->mac.addr, addr->sa_data)) |
| 1442 | netdev_info(netdev, "returning to hw mac address %pM\n", |
| 1443 | hw->mac.addr); |
| 1444 | else |
| 1445 | netdev_info(netdev, "set new mac address %pM\n", addr->sa_data); |
| 1446 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1447 | if (vsi->type == I40E_VSI_MAIN) { |
| 1448 | i40e_status ret; |
| 1449 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
Shannon Nelson | cc41222 | 2014-06-04 01:23:21 +0000 | [diff] [blame] | 1450 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1451 | addr->sa_data, NULL); |
| 1452 | if (ret) { |
| 1453 | netdev_info(netdev, |
| 1454 | "Addr change for Main VSI failed: %d\n", |
| 1455 | ret); |
| 1456 | return -EADDRNOTAVAIL; |
| 1457 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1460 | if (ether_addr_equal(netdev->dev_addr, hw->mac.addr)) { |
| 1461 | struct i40e_aqc_remove_macvlan_element_data element; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1462 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1463 | memset(&element, 0, sizeof(element)); |
| 1464 | ether_addr_copy(element.mac_addr, netdev->dev_addr); |
| 1465 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1466 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1467 | } else { |
Shannon Nelson | 6c8ad1b | 2014-06-04 01:23:22 +0000 | [diff] [blame] | 1468 | i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, |
| 1469 | false, false); |
Shannon Nelson | 6c8ad1b | 2014-06-04 01:23:22 +0000 | [diff] [blame] | 1470 | } |
| 1471 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1472 | if (ether_addr_equal(addr->sa_data, hw->mac.addr)) { |
| 1473 | struct i40e_aqc_add_macvlan_element_data element; |
| 1474 | |
| 1475 | memset(&element, 0, sizeof(element)); |
| 1476 | ether_addr_copy(element.mac_addr, hw->mac.addr); |
| 1477 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); |
| 1478 | i40e_aq_add_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); |
| 1479 | } else { |
| 1480 | f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY, |
| 1481 | false, false); |
| 1482 | if (f) |
| 1483 | f->is_laa = true; |
| 1484 | } |
| 1485 | |
| 1486 | i40e_sync_vsi_filters(vsi); |
| 1487 | ether_addr_copy(netdev->dev_addr, addr->sa_data); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1488 | |
| 1489 | return 0; |
| 1490 | } |
| 1491 | |
| 1492 | /** |
| 1493 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1494 | * @vsi: the VSI being setup |
| 1495 | * @ctxt: VSI context structure |
| 1496 | * @enabled_tc: Enabled TCs bitmap |
| 1497 | * @is_add: True if called before Add VSI |
| 1498 | * |
| 1499 | * Setup VSI queue mapping for enabled traffic classes. |
| 1500 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1501 | #ifdef I40E_FCOE |
| 1502 | void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1503 | struct i40e_vsi_context *ctxt, |
| 1504 | u8 enabled_tc, |
| 1505 | bool is_add) |
| 1506 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1507 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1508 | struct i40e_vsi_context *ctxt, |
| 1509 | u8 enabled_tc, |
| 1510 | bool is_add) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1511 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1512 | { |
| 1513 | struct i40e_pf *pf = vsi->back; |
| 1514 | u16 sections = 0; |
| 1515 | u8 netdev_tc = 0; |
| 1516 | u16 numtc = 0; |
| 1517 | u16 qcount; |
| 1518 | u8 offset; |
| 1519 | u16 qmap; |
| 1520 | int i; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1521 | u16 num_tc_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1522 | |
| 1523 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1524 | offset = 0; |
| 1525 | |
| 1526 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1527 | /* Find numtc from enabled TC bitmap */ |
| 1528 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1529 | if (enabled_tc & (1 << i)) /* TC is enabled */ |
| 1530 | numtc++; |
| 1531 | } |
| 1532 | if (!numtc) { |
| 1533 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1534 | numtc = 1; |
| 1535 | } |
| 1536 | } else { |
| 1537 | /* At least TC0 is enabled in case of non-DCB case */ |
| 1538 | numtc = 1; |
| 1539 | } |
| 1540 | |
| 1541 | vsi->tc_config.numtc = numtc; |
| 1542 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1543 | /* Number of queues per enabled TC */ |
Anjali Singhai | 7f9ff47 | 2015-02-21 06:43:19 +0000 | [diff] [blame] | 1544 | /* In MFP case we can have a much lower count of MSIx |
| 1545 | * vectors available and so we need to lower the used |
| 1546 | * q count. |
| 1547 | */ |
| 1548 | qcount = min_t(int, vsi->alloc_queue_pairs, pf->num_lan_msix); |
| 1549 | num_tc_qps = qcount / numtc; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1550 | num_tc_qps = min_t(int, num_tc_qps, I40E_MAX_QUEUES_PER_TC); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1551 | |
| 1552 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1553 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1554 | /* See if the given TC is enabled for the given VSI */ |
| 1555 | if (vsi->tc_config.enabled_tc & (1 << i)) { /* TC is enabled */ |
| 1556 | int pow, num_qps; |
| 1557 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1558 | switch (vsi->type) { |
| 1559 | case I40E_VSI_MAIN: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1560 | qcount = min_t(int, pf->rss_size, num_tc_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1561 | break; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1562 | #ifdef I40E_FCOE |
| 1563 | case I40E_VSI_FCOE: |
| 1564 | qcount = num_tc_qps; |
| 1565 | break; |
| 1566 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1567 | case I40E_VSI_FDIR: |
| 1568 | case I40E_VSI_SRIOV: |
| 1569 | case I40E_VSI_VMDQ2: |
| 1570 | default: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1571 | qcount = num_tc_qps; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1572 | WARN_ON(i != 0); |
| 1573 | break; |
| 1574 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1575 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1576 | vsi->tc_config.tc_info[i].qcount = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1577 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 1578 | /* find the next higher power-of-2 of num queue pairs */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1579 | num_qps = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1580 | pow = 0; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1581 | while (num_qps && ((1 << pow) < qcount)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1582 | pow++; |
| 1583 | num_qps >>= 1; |
| 1584 | } |
| 1585 | |
| 1586 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1587 | qmap = |
| 1588 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1589 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1590 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1591 | offset += qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1592 | } else { |
| 1593 | /* TC is not enabled so set the offset to |
| 1594 | * default queue and allocate one queue |
| 1595 | * for the given TC. |
| 1596 | */ |
| 1597 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1598 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1599 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1600 | |
| 1601 | qmap = 0; |
| 1602 | } |
| 1603 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1604 | } |
| 1605 | |
| 1606 | /* Set actual Tx/Rx queue pairs */ |
| 1607 | vsi->num_queue_pairs = offset; |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 1608 | if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) { |
| 1609 | if (vsi->req_queue_pairs > 0) |
| 1610 | vsi->num_queue_pairs = vsi->req_queue_pairs; |
| 1611 | else |
| 1612 | vsi->num_queue_pairs = pf->num_lan_msix; |
| 1613 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1614 | |
| 1615 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1616 | if (is_add) { |
| 1617 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1618 | |
| 1619 | ctxt->info.up_enable_bits = enabled_tc; |
| 1620 | } |
| 1621 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1622 | ctxt->info.mapping_flags |= |
| 1623 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1624 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1625 | ctxt->info.queue_mapping[i] = |
| 1626 | cpu_to_le16(vsi->base_queue + i); |
| 1627 | } else { |
| 1628 | ctxt->info.mapping_flags |= |
| 1629 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1630 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1631 | } |
| 1632 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1633 | } |
| 1634 | |
| 1635 | /** |
| 1636 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1637 | * @netdev: network interface device structure |
| 1638 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1639 | #ifdef I40E_FCOE |
| 1640 | void i40e_set_rx_mode(struct net_device *netdev) |
| 1641 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1642 | static void i40e_set_rx_mode(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1643 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1644 | { |
| 1645 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1646 | struct i40e_mac_filter *f, *ftmp; |
| 1647 | struct i40e_vsi *vsi = np->vsi; |
| 1648 | struct netdev_hw_addr *uca; |
| 1649 | struct netdev_hw_addr *mca; |
| 1650 | struct netdev_hw_addr *ha; |
| 1651 | |
| 1652 | /* add addr if not already in the filter list */ |
| 1653 | netdev_for_each_uc_addr(uca, netdev) { |
| 1654 | if (!i40e_find_mac(vsi, uca->addr, false, true)) { |
| 1655 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1656 | i40e_put_mac_in_vlan(vsi, uca->addr, |
| 1657 | false, true); |
| 1658 | else |
| 1659 | i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY, |
| 1660 | false, true); |
| 1661 | } |
| 1662 | } |
| 1663 | |
| 1664 | netdev_for_each_mc_addr(mca, netdev) { |
| 1665 | if (!i40e_find_mac(vsi, mca->addr, false, true)) { |
| 1666 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1667 | i40e_put_mac_in_vlan(vsi, mca->addr, |
| 1668 | false, true); |
| 1669 | else |
| 1670 | i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY, |
| 1671 | false, true); |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | /* remove filter if not in netdev list */ |
| 1676 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1677 | bool found = false; |
| 1678 | |
| 1679 | if (!f->is_netdev) |
| 1680 | continue; |
| 1681 | |
| 1682 | if (is_multicast_ether_addr(f->macaddr)) { |
| 1683 | netdev_for_each_mc_addr(mca, netdev) { |
| 1684 | if (ether_addr_equal(mca->addr, f->macaddr)) { |
| 1685 | found = true; |
| 1686 | break; |
| 1687 | } |
| 1688 | } |
| 1689 | } else { |
| 1690 | netdev_for_each_uc_addr(uca, netdev) { |
| 1691 | if (ether_addr_equal(uca->addr, f->macaddr)) { |
| 1692 | found = true; |
| 1693 | break; |
| 1694 | } |
| 1695 | } |
| 1696 | |
| 1697 | for_each_dev_addr(netdev, ha) { |
| 1698 | if (ether_addr_equal(ha->addr, f->macaddr)) { |
| 1699 | found = true; |
| 1700 | break; |
| 1701 | } |
| 1702 | } |
| 1703 | } |
| 1704 | if (!found) |
| 1705 | i40e_del_filter( |
| 1706 | vsi, f->macaddr, I40E_VLAN_ANY, false, true); |
| 1707 | } |
| 1708 | |
| 1709 | /* check for other flag changes */ |
| 1710 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1711 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1712 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1713 | } |
| 1714 | } |
| 1715 | |
| 1716 | /** |
| 1717 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 1718 | * @vsi: ptr to the VSI |
| 1719 | * |
| 1720 | * Push any outstanding VSI filter changes through the AdminQ. |
| 1721 | * |
| 1722 | * Returns 0 or error value |
| 1723 | **/ |
| 1724 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
| 1725 | { |
| 1726 | struct i40e_mac_filter *f, *ftmp; |
| 1727 | bool promisc_forced_on = false; |
| 1728 | bool add_happened = false; |
| 1729 | int filter_list_len = 0; |
| 1730 | u32 changed_flags = 0; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1731 | i40e_status aq_ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1732 | struct i40e_pf *pf; |
| 1733 | int num_add = 0; |
| 1734 | int num_del = 0; |
| 1735 | u16 cmd_flags; |
| 1736 | |
| 1737 | /* empty array typed pointers, kcalloc later */ |
| 1738 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 1739 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 1740 | |
| 1741 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 1742 | usleep_range(1000, 2000); |
| 1743 | pf = vsi->back; |
| 1744 | |
| 1745 | if (vsi->netdev) { |
| 1746 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 1747 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 1748 | } |
| 1749 | |
| 1750 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 1751 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 1752 | |
| 1753 | filter_list_len = pf->hw.aq.asq_buf_size / |
| 1754 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
| 1755 | del_list = kcalloc(filter_list_len, |
| 1756 | sizeof(struct i40e_aqc_remove_macvlan_element_data), |
| 1757 | GFP_KERNEL); |
| 1758 | if (!del_list) |
| 1759 | return -ENOMEM; |
| 1760 | |
| 1761 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1762 | if (!f->changed) |
| 1763 | continue; |
| 1764 | |
| 1765 | if (f->counter != 0) |
| 1766 | continue; |
| 1767 | f->changed = false; |
| 1768 | cmd_flags = 0; |
| 1769 | |
| 1770 | /* add to delete list */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1771 | ether_addr_copy(del_list[num_del].mac_addr, f->macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1772 | del_list[num_del].vlan_tag = |
| 1773 | cpu_to_le16((u16)(f->vlan == |
| 1774 | I40E_VLAN_ANY ? 0 : f->vlan)); |
| 1775 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1776 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1777 | del_list[num_del].flags = cmd_flags; |
| 1778 | num_del++; |
| 1779 | |
| 1780 | /* unlink from filter list */ |
| 1781 | list_del(&f->list); |
| 1782 | kfree(f); |
| 1783 | |
| 1784 | /* flush a full buffer */ |
| 1785 | if (num_del == filter_list_len) { |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1786 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1787 | vsi->seid, del_list, num_del, |
| 1788 | NULL); |
| 1789 | num_del = 0; |
| 1790 | memset(del_list, 0, sizeof(*del_list)); |
| 1791 | |
Shannon Nelson | fdfe9cb | 2014-05-20 08:01:39 +0000 | [diff] [blame] | 1792 | if (aq_ret && |
| 1793 | pf->hw.aq.asq_last_status != |
| 1794 | I40E_AQ_RC_ENOENT) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1795 | dev_info(&pf->pdev->dev, |
| 1796 | "ignoring delete macvlan error, err %d, aq_err %d while flushing a full buffer\n", |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1797 | aq_ret, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1798 | pf->hw.aq.asq_last_status); |
| 1799 | } |
| 1800 | } |
| 1801 | if (num_del) { |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1802 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1803 | del_list, num_del, NULL); |
| 1804 | num_del = 0; |
| 1805 | |
Shannon Nelson | fdfe9cb | 2014-05-20 08:01:39 +0000 | [diff] [blame] | 1806 | if (aq_ret && |
| 1807 | pf->hw.aq.asq_last_status != I40E_AQ_RC_ENOENT) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1808 | dev_info(&pf->pdev->dev, |
| 1809 | "ignoring delete macvlan error, err %d, aq_err %d\n", |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1810 | aq_ret, pf->hw.aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | kfree(del_list); |
| 1814 | del_list = NULL; |
| 1815 | |
| 1816 | /* do all the adds now */ |
| 1817 | filter_list_len = pf->hw.aq.asq_buf_size / |
| 1818 | sizeof(struct i40e_aqc_add_macvlan_element_data), |
| 1819 | add_list = kcalloc(filter_list_len, |
| 1820 | sizeof(struct i40e_aqc_add_macvlan_element_data), |
| 1821 | GFP_KERNEL); |
| 1822 | if (!add_list) |
| 1823 | return -ENOMEM; |
| 1824 | |
| 1825 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1826 | if (!f->changed) |
| 1827 | continue; |
| 1828 | |
| 1829 | if (f->counter == 0) |
| 1830 | continue; |
| 1831 | f->changed = false; |
| 1832 | add_happened = true; |
| 1833 | cmd_flags = 0; |
| 1834 | |
| 1835 | /* add to add array */ |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 1836 | ether_addr_copy(add_list[num_add].mac_addr, f->macaddr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1837 | add_list[num_add].vlan_tag = |
| 1838 | cpu_to_le16( |
| 1839 | (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan)); |
| 1840 | add_list[num_add].queue_number = 0; |
| 1841 | |
| 1842 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1843 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 1844 | num_add++; |
| 1845 | |
| 1846 | /* flush a full buffer */ |
| 1847 | if (num_add == filter_list_len) { |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1848 | aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, |
| 1849 | add_list, num_add, |
| 1850 | NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1851 | num_add = 0; |
| 1852 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1853 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1854 | break; |
| 1855 | memset(add_list, 0, sizeof(*add_list)); |
| 1856 | } |
| 1857 | } |
| 1858 | if (num_add) { |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1859 | aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, |
| 1860 | add_list, num_add, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1861 | num_add = 0; |
| 1862 | } |
| 1863 | kfree(add_list); |
| 1864 | add_list = NULL; |
| 1865 | |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 1866 | if (add_happened && aq_ret && |
| 1867 | pf->hw.aq.asq_last_status != I40E_AQ_RC_EINVAL) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1868 | dev_info(&pf->pdev->dev, |
| 1869 | "add filter failed, err %d, aq_err %d\n", |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1870 | aq_ret, pf->hw.aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1871 | if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) && |
| 1872 | !test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 1873 | &vsi->state)) { |
| 1874 | promisc_forced_on = true; |
| 1875 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 1876 | &vsi->state); |
| 1877 | dev_info(&pf->pdev->dev, "promiscuous mode forced on\n"); |
| 1878 | } |
| 1879 | } |
| 1880 | } |
| 1881 | |
| 1882 | /* check for changes in promiscuous modes */ |
| 1883 | if (changed_flags & IFF_ALLMULTI) { |
| 1884 | bool cur_multipromisc; |
| 1885 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1886 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 1887 | vsi->seid, |
| 1888 | cur_multipromisc, |
| 1889 | NULL); |
| 1890 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1891 | dev_info(&pf->pdev->dev, |
| 1892 | "set multi promisc failed, err %d, aq_err %d\n", |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1893 | aq_ret, pf->hw.aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1894 | } |
| 1895 | if ((changed_flags & IFF_PROMISC) || promisc_forced_on) { |
| 1896 | bool cur_promisc; |
| 1897 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
| 1898 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 1899 | &vsi->state)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1900 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous(&vsi->back->hw, |
| 1901 | vsi->seid, |
| 1902 | cur_promisc, NULL); |
| 1903 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1904 | dev_info(&pf->pdev->dev, |
| 1905 | "set uni promisc failed, err %d, aq_err %d\n", |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1906 | aq_ret, pf->hw.aq.asq_last_status); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 1907 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
| 1908 | vsi->seid, |
| 1909 | cur_promisc, NULL); |
| 1910 | if (aq_ret) |
| 1911 | dev_info(&pf->pdev->dev, |
| 1912 | "set brdcast promisc failed, err %d, aq_err %d\n", |
| 1913 | aq_ret, pf->hw.aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
| 1917 | return 0; |
| 1918 | } |
| 1919 | |
| 1920 | /** |
| 1921 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 1922 | * @pf: board private structure |
| 1923 | **/ |
| 1924 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 1925 | { |
| 1926 | int v; |
| 1927 | |
| 1928 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 1929 | return; |
| 1930 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 1931 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 1932 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1933 | if (pf->vsi[v] && |
| 1934 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) |
| 1935 | i40e_sync_vsi_filters(pf->vsi[v]); |
| 1936 | } |
| 1937 | } |
| 1938 | |
| 1939 | /** |
| 1940 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 1941 | * @netdev: network interface device structure |
| 1942 | * @new_mtu: new value for maximum frame size |
| 1943 | * |
| 1944 | * Returns 0 on success, negative on failure |
| 1945 | **/ |
| 1946 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 1947 | { |
| 1948 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 61a46a4 | 2014-04-23 04:50:05 +0000 | [diff] [blame] | 1949 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1950 | struct i40e_vsi *vsi = np->vsi; |
| 1951 | |
| 1952 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 1953 | if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER)) |
| 1954 | return -EINVAL; |
| 1955 | |
| 1956 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 1957 | netdev->mtu, new_mtu); |
| 1958 | netdev->mtu = new_mtu; |
| 1959 | if (netif_running(netdev)) |
| 1960 | i40e_vsi_reinit_locked(vsi); |
| 1961 | |
| 1962 | return 0; |
| 1963 | } |
| 1964 | |
| 1965 | /** |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 1966 | * i40e_ioctl - Access the hwtstamp interface |
| 1967 | * @netdev: network interface device structure |
| 1968 | * @ifr: interface request data |
| 1969 | * @cmd: ioctl command |
| 1970 | **/ |
| 1971 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 1972 | { |
| 1973 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1974 | struct i40e_pf *pf = np->vsi->back; |
| 1975 | |
| 1976 | switch (cmd) { |
| 1977 | case SIOCGHWTSTAMP: |
| 1978 | return i40e_ptp_get_ts_config(pf, ifr); |
| 1979 | case SIOCSHWTSTAMP: |
| 1980 | return i40e_ptp_set_ts_config(pf, ifr); |
| 1981 | default: |
| 1982 | return -EOPNOTSUPP; |
| 1983 | } |
| 1984 | } |
| 1985 | |
| 1986 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1987 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 1988 | * @vsi: the vsi being adjusted |
| 1989 | **/ |
| 1990 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 1991 | { |
| 1992 | struct i40e_vsi_context ctxt; |
| 1993 | i40e_status ret; |
| 1994 | |
| 1995 | if ((vsi->info.valid_sections & |
| 1996 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 1997 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 1998 | return; /* already enabled */ |
| 1999 | |
| 2000 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2001 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2002 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 2003 | |
| 2004 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2005 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2006 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2007 | if (ret) { |
| 2008 | dev_info(&vsi->back->pdev->dev, |
| 2009 | "%s: update vsi failed, aq_err=%d\n", |
| 2010 | __func__, vsi->back->hw.aq.asq_last_status); |
| 2011 | } |
| 2012 | } |
| 2013 | |
| 2014 | /** |
| 2015 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 2016 | * @vsi: the vsi being adjusted |
| 2017 | **/ |
| 2018 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 2019 | { |
| 2020 | struct i40e_vsi_context ctxt; |
| 2021 | i40e_status ret; |
| 2022 | |
| 2023 | if ((vsi->info.valid_sections & |
| 2024 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 2025 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 2026 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 2027 | return; /* already disabled */ |
| 2028 | |
| 2029 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2030 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 2031 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 2032 | |
| 2033 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2034 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2035 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2036 | if (ret) { |
| 2037 | dev_info(&vsi->back->pdev->dev, |
| 2038 | "%s: update vsi failed, aq_err=%d\n", |
| 2039 | __func__, vsi->back->hw.aq.asq_last_status); |
| 2040 | } |
| 2041 | } |
| 2042 | |
| 2043 | /** |
| 2044 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 2045 | * @netdev: network interface to be adjusted |
| 2046 | * @features: netdev features to test if VLAN offload is enabled or not |
| 2047 | **/ |
| 2048 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 2049 | { |
| 2050 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2051 | struct i40e_vsi *vsi = np->vsi; |
| 2052 | |
| 2053 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2054 | i40e_vlan_stripping_enable(vsi); |
| 2055 | else |
| 2056 | i40e_vlan_stripping_disable(vsi); |
| 2057 | } |
| 2058 | |
| 2059 | /** |
| 2060 | * i40e_vsi_add_vlan - Add vsi membership for given vlan |
| 2061 | * @vsi: the vsi being configured |
| 2062 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
| 2063 | **/ |
| 2064 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2065 | { |
| 2066 | struct i40e_mac_filter *f, *add_f; |
| 2067 | bool is_netdev, is_vf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2068 | |
| 2069 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 2070 | is_netdev = !!(vsi->netdev); |
| 2071 | |
| 2072 | if (is_netdev) { |
| 2073 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid, |
| 2074 | is_vf, is_netdev); |
| 2075 | if (!add_f) { |
| 2076 | dev_info(&vsi->back->pdev->dev, |
| 2077 | "Could not add vlan filter %d for %pM\n", |
| 2078 | vid, vsi->netdev->dev_addr); |
| 2079 | return -ENOMEM; |
| 2080 | } |
| 2081 | } |
| 2082 | |
| 2083 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2084 | add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 2085 | if (!add_f) { |
| 2086 | dev_info(&vsi->back->pdev->dev, |
| 2087 | "Could not add vlan filter %d for %pM\n", |
| 2088 | vid, f->macaddr); |
| 2089 | return -ENOMEM; |
| 2090 | } |
| 2091 | } |
| 2092 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2093 | /* Now if we add a vlan tag, make sure to check if it is the first |
| 2094 | * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag" |
| 2095 | * with 0, so we now accept untagged and specified tagged traffic |
| 2096 | * (and not any taged and untagged) |
| 2097 | */ |
| 2098 | if (vid > 0) { |
| 2099 | if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr, |
| 2100 | I40E_VLAN_ANY, |
| 2101 | is_vf, is_netdev)) { |
| 2102 | i40e_del_filter(vsi, vsi->netdev->dev_addr, |
| 2103 | I40E_VLAN_ANY, is_vf, is_netdev); |
| 2104 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0, |
| 2105 | is_vf, is_netdev); |
| 2106 | if (!add_f) { |
| 2107 | dev_info(&vsi->back->pdev->dev, |
| 2108 | "Could not add filter 0 for %pM\n", |
| 2109 | vsi->netdev->dev_addr); |
| 2110 | return -ENOMEM; |
| 2111 | } |
| 2112 | } |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2113 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2114 | |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 2115 | /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */ |
| 2116 | if (vid > 0 && !vsi->info.pvid) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2117 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2118 | if (i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2119 | is_vf, is_netdev)) { |
| 2120 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2121 | is_vf, is_netdev); |
| 2122 | add_f = i40e_add_filter(vsi, f->macaddr, |
| 2123 | 0, is_vf, is_netdev); |
| 2124 | if (!add_f) { |
| 2125 | dev_info(&vsi->back->pdev->dev, |
| 2126 | "Could not add filter 0 for %pM\n", |
| 2127 | f->macaddr); |
| 2128 | return -ENOMEM; |
| 2129 | } |
| 2130 | } |
| 2131 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2132 | } |
| 2133 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 2134 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 2135 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 2136 | return 0; |
| 2137 | |
| 2138 | return i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | /** |
| 2142 | * i40e_vsi_kill_vlan - Remove vsi membership for given vlan |
| 2143 | * @vsi: the vsi being configured |
| 2144 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2145 | * |
| 2146 | * Return: 0 on success or negative otherwise |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2147 | **/ |
| 2148 | int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid) |
| 2149 | { |
| 2150 | struct net_device *netdev = vsi->netdev; |
| 2151 | struct i40e_mac_filter *f, *add_f; |
| 2152 | bool is_vf, is_netdev; |
| 2153 | int filter_count = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2154 | |
| 2155 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 2156 | is_netdev = !!(netdev); |
| 2157 | |
| 2158 | if (is_netdev) |
| 2159 | i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev); |
| 2160 | |
| 2161 | list_for_each_entry(f, &vsi->mac_filter_list, list) |
| 2162 | i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 2163 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2164 | /* go through all the filters for this VSI and if there is only |
| 2165 | * vid == 0 it means there are no other filters, so vid 0 must |
| 2166 | * be replaced with -1. This signifies that we should from now |
| 2167 | * on accept any traffic (with any tag present, or untagged) |
| 2168 | */ |
| 2169 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2170 | if (is_netdev) { |
| 2171 | if (f->vlan && |
| 2172 | ether_addr_equal(netdev->dev_addr, f->macaddr)) |
| 2173 | filter_count++; |
| 2174 | } |
| 2175 | |
| 2176 | if (f->vlan) |
| 2177 | filter_count++; |
| 2178 | } |
| 2179 | |
| 2180 | if (!filter_count && is_netdev) { |
| 2181 | i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev); |
| 2182 | f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, |
| 2183 | is_vf, is_netdev); |
| 2184 | if (!f) { |
| 2185 | dev_info(&vsi->back->pdev->dev, |
| 2186 | "Could not add filter %d for %pM\n", |
| 2187 | I40E_VLAN_ANY, netdev->dev_addr); |
| 2188 | return -ENOMEM; |
| 2189 | } |
| 2190 | } |
| 2191 | |
| 2192 | if (!filter_count) { |
| 2193 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2194 | i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev); |
| 2195 | add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2196 | is_vf, is_netdev); |
| 2197 | if (!add_f) { |
| 2198 | dev_info(&vsi->back->pdev->dev, |
| 2199 | "Could not add filter %d for %pM\n", |
| 2200 | I40E_VLAN_ANY, f->macaddr); |
| 2201 | return -ENOMEM; |
| 2202 | } |
| 2203 | } |
| 2204 | } |
| 2205 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 2206 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 2207 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 2208 | return 0; |
| 2209 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2210 | return i40e_sync_vsi_filters(vsi); |
| 2211 | } |
| 2212 | |
| 2213 | /** |
| 2214 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 2215 | * @netdev: network interface to be adjusted |
| 2216 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2217 | * |
| 2218 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2219 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2220 | #ifdef I40E_FCOE |
| 2221 | int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2222 | __always_unused __be16 proto, u16 vid) |
| 2223 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2224 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2225 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2226 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2227 | { |
| 2228 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2229 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2230 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2231 | |
| 2232 | if (vid > 4095) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2233 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2234 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2235 | netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid); |
| 2236 | |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2237 | /* If the network stack called us with vid = 0 then |
| 2238 | * it is asking to receive priority tagged packets with |
| 2239 | * vlan id 0. Our HW receives them by default when configured |
| 2240 | * to receive untagged packets so there is no need to add an |
| 2241 | * extra filter for vlan 0 tagged packets. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2242 | */ |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2243 | if (vid) |
| 2244 | ret = i40e_vsi_add_vlan(vsi, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2245 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2246 | if (!ret && (vid < VLAN_N_VID)) |
| 2247 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2248 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2249 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2250 | } |
| 2251 | |
| 2252 | /** |
| 2253 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 2254 | * @netdev: network interface to be adjusted |
| 2255 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2256 | * |
Akeem G Abodunrin | fdfd943 | 2014-02-11 08:24:15 +0000 | [diff] [blame] | 2257 | * net_device_ops implementation for removing vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2258 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2259 | #ifdef I40E_FCOE |
| 2260 | int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2261 | __always_unused __be16 proto, u16 vid) |
| 2262 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2263 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2264 | __always_unused __be16 proto, u16 vid) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2265 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2266 | { |
| 2267 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2268 | struct i40e_vsi *vsi = np->vsi; |
| 2269 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2270 | netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid); |
| 2271 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2272 | /* return code is ignored as there is nothing a user |
| 2273 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2274 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2275 | */ |
| 2276 | i40e_vsi_kill_vlan(vsi, vid); |
| 2277 | |
| 2278 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2279 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2280 | return 0; |
| 2281 | } |
| 2282 | |
| 2283 | /** |
| 2284 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 2285 | * @vsi: the vsi being brought back up |
| 2286 | **/ |
| 2287 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 2288 | { |
| 2289 | u16 vid; |
| 2290 | |
| 2291 | if (!vsi->netdev) |
| 2292 | return; |
| 2293 | |
| 2294 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2295 | |
| 2296 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 2297 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 2298 | vid); |
| 2299 | } |
| 2300 | |
| 2301 | /** |
| 2302 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2303 | * @vsi: the vsi being adjusted |
| 2304 | * @vid: the vlan id to set as a PVID |
| 2305 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2306 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2307 | { |
| 2308 | struct i40e_vsi_context ctxt; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2309 | i40e_status aq_ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2310 | |
| 2311 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2312 | vsi->info.pvid = cpu_to_le16(vid); |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2313 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
| 2314 | I40E_AQ_VSI_PVLAN_INSERT_PVID | |
Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2315 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2316 | |
| 2317 | ctxt.seid = vsi->seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 2318 | ctxt.info = vsi->info; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2319 | aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2320 | if (aq_ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2321 | dev_info(&vsi->back->pdev->dev, |
| 2322 | "%s: update vsi failed, aq_err=%d\n", |
| 2323 | __func__, vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2324 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2325 | } |
| 2326 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2327 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | /** |
| 2331 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2332 | * @vsi: the vsi being adjusted |
| 2333 | * |
| 2334 | * Just use the vlan_rx_register() service to put it back to normal |
| 2335 | **/ |
| 2336 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2337 | { |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2338 | i40e_vlan_stripping_disable(vsi); |
| 2339 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2340 | vsi->info.pvid = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | /** |
| 2344 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2345 | * @vsi: ptr to the VSI |
| 2346 | * |
| 2347 | * If this function returns with an error, then it's possible one or |
| 2348 | * more of the rings is populated (while the rest are not). It is the |
| 2349 | * callers duty to clean those orphaned rings. |
| 2350 | * |
| 2351 | * Return 0 on success, negative on failure |
| 2352 | **/ |
| 2353 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2354 | { |
| 2355 | int i, err = 0; |
| 2356 | |
| 2357 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2358 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2359 | |
| 2360 | return err; |
| 2361 | } |
| 2362 | |
| 2363 | /** |
| 2364 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2365 | * @vsi: ptr to the VSI |
| 2366 | * |
| 2367 | * Free VSI's transmit software resources |
| 2368 | **/ |
| 2369 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2370 | { |
| 2371 | int i; |
| 2372 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2373 | if (!vsi->tx_rings) |
| 2374 | return; |
| 2375 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2376 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2377 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2378 | i40e_free_tx_resources(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | /** |
| 2382 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 2383 | * @vsi: ptr to the VSI |
| 2384 | * |
| 2385 | * If this function returns with an error, then it's possible one or |
| 2386 | * more of the rings is populated (while the rest are not). It is the |
| 2387 | * callers duty to clean those orphaned rings. |
| 2388 | * |
| 2389 | * Return 0 on success, negative on failure |
| 2390 | **/ |
| 2391 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 2392 | { |
| 2393 | int i, err = 0; |
| 2394 | |
| 2395 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2396 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2397 | #ifdef I40E_FCOE |
| 2398 | i40e_fcoe_setup_ddp_resources(vsi); |
| 2399 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2400 | return err; |
| 2401 | } |
| 2402 | |
| 2403 | /** |
| 2404 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 2405 | * @vsi: ptr to the VSI |
| 2406 | * |
| 2407 | * Free all receive software resources |
| 2408 | **/ |
| 2409 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 2410 | { |
| 2411 | int i; |
| 2412 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2413 | if (!vsi->rx_rings) |
| 2414 | return; |
| 2415 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2416 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2417 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2418 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2419 | #ifdef I40E_FCOE |
| 2420 | i40e_fcoe_free_ddp_resources(vsi); |
| 2421 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2422 | } |
| 2423 | |
| 2424 | /** |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2425 | * i40e_config_xps_tx_ring - Configure XPS for a Tx ring |
| 2426 | * @ring: The Tx ring to configure |
| 2427 | * |
| 2428 | * This enables/disables XPS for a given Tx descriptor ring |
| 2429 | * based on the TCs enabled for the VSI that ring belongs to. |
| 2430 | **/ |
| 2431 | static void i40e_config_xps_tx_ring(struct i40e_ring *ring) |
| 2432 | { |
| 2433 | struct i40e_vsi *vsi = ring->vsi; |
| 2434 | cpumask_var_t mask; |
| 2435 | |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2436 | if (!ring->q_vector || !ring->netdev) |
| 2437 | return; |
| 2438 | |
| 2439 | /* Single TC mode enable XPS */ |
| 2440 | if (vsi->tc_config.numtc <= 1) { |
| 2441 | if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2442 | netif_set_xps_queue(ring->netdev, |
| 2443 | &ring->q_vector->affinity_mask, |
| 2444 | ring->queue_index); |
Jesse Brandeburg | 9a660ee | 2015-02-26 16:13:22 +0000 | [diff] [blame] | 2445 | } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) { |
| 2446 | /* Disable XPS to allow selection based on TC */ |
| 2447 | bitmap_zero(cpumask_bits(mask), nr_cpumask_bits); |
| 2448 | netif_set_xps_queue(ring->netdev, mask, ring->queue_index); |
| 2449 | free_cpumask_var(mask); |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2450 | } |
| 2451 | } |
| 2452 | |
| 2453 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2454 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 2455 | * @ring: The Tx ring to configure |
| 2456 | * |
| 2457 | * Configure the Tx descriptor ring in the HMC context. |
| 2458 | **/ |
| 2459 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 2460 | { |
| 2461 | struct i40e_vsi *vsi = ring->vsi; |
| 2462 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2463 | struct i40e_hw *hw = &vsi->back->hw; |
| 2464 | struct i40e_hmc_obj_txq tx_ctx; |
| 2465 | i40e_status err = 0; |
| 2466 | u32 qtx_ctl = 0; |
| 2467 | |
| 2468 | /* some ATR related tx ring init */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2469 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2470 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 2471 | ring->atr_count = 0; |
| 2472 | } else { |
| 2473 | ring->atr_sample_rate = 0; |
| 2474 | } |
| 2475 | |
Neerav Parikh | 3ffa037 | 2014-11-12 00:19:02 +0000 | [diff] [blame] | 2476 | /* configure XPS */ |
| 2477 | i40e_config_xps_tx_ring(ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2478 | |
| 2479 | /* clear the context structure first */ |
| 2480 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 2481 | |
| 2482 | tx_ctx.new_context = 1; |
| 2483 | tx_ctx.base = (ring->dma / 128); |
| 2484 | tx_ctx.qlen = ring->count; |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2485 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
| 2486 | I40E_FLAG_FD_ATR_ENABLED)); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2487 | #ifdef I40E_FCOE |
| 2488 | tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2489 | #endif |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2490 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 2491 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
| 2492 | if (vsi->type != I40E_VSI_FDIR) |
| 2493 | tx_ctx.head_wb_ena = 1; |
| 2494 | tx_ctx.head_wb_addr = ring->dma + |
| 2495 | (ring->count * sizeof(struct i40e_tx_desc)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2496 | |
| 2497 | /* As part of VSI creation/update, FW allocates certain |
| 2498 | * Tx arbitration queue sets for each TC enabled for |
| 2499 | * the VSI. The FW returns the handles to these queue |
| 2500 | * sets as part of the response buffer to Add VSI, |
| 2501 | * Update VSI, etc. AQ commands. It is expected that |
| 2502 | * these queue set handles be associated with the Tx |
| 2503 | * queues by the driver as part of the TX queue context |
| 2504 | * initialization. This has to be done regardless of |
| 2505 | * DCB as by default everything is mapped to TC0. |
| 2506 | */ |
| 2507 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 2508 | tx_ctx.rdylist_act = 0; |
| 2509 | |
| 2510 | /* clear the context in the HMC */ |
| 2511 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 2512 | if (err) { |
| 2513 | dev_info(&vsi->back->pdev->dev, |
| 2514 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 2515 | ring->queue_index, pf_q, err); |
| 2516 | return -ENOMEM; |
| 2517 | } |
| 2518 | |
| 2519 | /* set the context in the HMC */ |
| 2520 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 2521 | if (err) { |
| 2522 | dev_info(&vsi->back->pdev->dev, |
| 2523 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 2524 | ring->queue_index, pf_q, err); |
| 2525 | return -ENOMEM; |
| 2526 | } |
| 2527 | |
| 2528 | /* Now associate this queue with this PCI function */ |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2529 | if (vsi->type == I40E_VSI_VMDQ2) { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2530 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2531 | qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
| 2532 | I40E_QTX_CTL_VFVM_INDX_MASK; |
| 2533 | } else { |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2534 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
Mitch Williams | 7a28d88 | 2014-10-17 03:14:52 +0000 | [diff] [blame] | 2535 | } |
| 2536 | |
Shannon Nelson | 13fd977 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 2537 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 2538 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2539 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 2540 | i40e_flush(hw); |
| 2541 | |
| 2542 | clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state); |
| 2543 | |
| 2544 | /* cache tail off for easier writes later */ |
| 2545 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 2546 | |
| 2547 | return 0; |
| 2548 | } |
| 2549 | |
| 2550 | /** |
| 2551 | * i40e_configure_rx_ring - Configure a receive ring context |
| 2552 | * @ring: The Rx ring to configure |
| 2553 | * |
| 2554 | * Configure the Rx descriptor ring in the HMC context. |
| 2555 | **/ |
| 2556 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 2557 | { |
| 2558 | struct i40e_vsi *vsi = ring->vsi; |
| 2559 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 2560 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2561 | struct i40e_hw *hw = &vsi->back->hw; |
| 2562 | struct i40e_hmc_obj_rxq rx_ctx; |
| 2563 | i40e_status err = 0; |
| 2564 | |
| 2565 | ring->state = 0; |
| 2566 | |
| 2567 | /* clear the context structure first */ |
| 2568 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 2569 | |
| 2570 | ring->rx_buf_len = vsi->rx_buf_len; |
| 2571 | ring->rx_hdr_len = vsi->rx_hdr_len; |
| 2572 | |
| 2573 | rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT; |
| 2574 | rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT; |
| 2575 | |
| 2576 | rx_ctx.base = (ring->dma / 128); |
| 2577 | rx_ctx.qlen = ring->count; |
| 2578 | |
| 2579 | if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) { |
| 2580 | set_ring_16byte_desc_enabled(ring); |
| 2581 | rx_ctx.dsize = 0; |
| 2582 | } else { |
| 2583 | rx_ctx.dsize = 1; |
| 2584 | } |
| 2585 | |
| 2586 | rx_ctx.dtype = vsi->dtype; |
| 2587 | if (vsi->dtype) { |
| 2588 | set_ring_ps_enabled(ring); |
| 2589 | rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 | |
| 2590 | I40E_RX_SPLIT_IP | |
| 2591 | I40E_RX_SPLIT_TCP_UDP | |
| 2592 | I40E_RX_SPLIT_SCTP; |
| 2593 | } else { |
| 2594 | rx_ctx.hsplit_0 = 0; |
| 2595 | } |
| 2596 | |
| 2597 | rx_ctx.rxmax = min_t(u16, vsi->max_frame, |
| 2598 | (chain_len * ring->rx_buf_len)); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 2599 | if (hw->revision_id == 0) |
| 2600 | rx_ctx.lrxqthresh = 0; |
| 2601 | else |
| 2602 | rx_ctx.lrxqthresh = 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2603 | rx_ctx.crcstrip = 1; |
| 2604 | rx_ctx.l2tsel = 1; |
| 2605 | rx_ctx.showiv = 1; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2606 | #ifdef I40E_FCOE |
| 2607 | rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE); |
| 2608 | #endif |
Catherine Sullivan | acb3676 | 2014-03-06 09:02:30 +0000 | [diff] [blame] | 2609 | /* set the prefena field to 1 because the manual says to */ |
| 2610 | rx_ctx.prefena = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2611 | |
| 2612 | /* clear the context in the HMC */ |
| 2613 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 2614 | if (err) { |
| 2615 | dev_info(&vsi->back->pdev->dev, |
| 2616 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2617 | ring->queue_index, pf_q, err); |
| 2618 | return -ENOMEM; |
| 2619 | } |
| 2620 | |
| 2621 | /* set the context in the HMC */ |
| 2622 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 2623 | if (err) { |
| 2624 | dev_info(&vsi->back->pdev->dev, |
| 2625 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2626 | ring->queue_index, pf_q, err); |
| 2627 | return -ENOMEM; |
| 2628 | } |
| 2629 | |
| 2630 | /* cache tail for quicker writes, and clear the reg before use */ |
| 2631 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 2632 | writel(0, ring->tail); |
| 2633 | |
Mitch Williams | a132af2 | 2015-01-24 09:58:35 +0000 | [diff] [blame] | 2634 | if (ring_is_ps_enabled(ring)) { |
| 2635 | i40e_alloc_rx_headers(ring); |
| 2636 | i40e_alloc_rx_buffers_ps(ring, I40E_DESC_UNUSED(ring)); |
| 2637 | } else { |
| 2638 | i40e_alloc_rx_buffers_1buf(ring, I40E_DESC_UNUSED(ring)); |
| 2639 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2640 | |
| 2641 | return 0; |
| 2642 | } |
| 2643 | |
| 2644 | /** |
| 2645 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 2646 | * @vsi: VSI structure describing this set of rings and resources |
| 2647 | * |
| 2648 | * Configure the Tx VSI for operation. |
| 2649 | **/ |
| 2650 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 2651 | { |
| 2652 | int err = 0; |
| 2653 | u16 i; |
| 2654 | |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2655 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 2656 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2657 | |
| 2658 | return err; |
| 2659 | } |
| 2660 | |
| 2661 | /** |
| 2662 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 2663 | * @vsi: the VSI being configured |
| 2664 | * |
| 2665 | * Configure the Rx VSI for operation. |
| 2666 | **/ |
| 2667 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 2668 | { |
| 2669 | int err = 0; |
| 2670 | u16 i; |
| 2671 | |
| 2672 | if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN)) |
| 2673 | vsi->max_frame = vsi->netdev->mtu + ETH_HLEN |
| 2674 | + ETH_FCS_LEN + VLAN_HLEN; |
| 2675 | else |
| 2676 | vsi->max_frame = I40E_RXBUFFER_2048; |
| 2677 | |
| 2678 | /* figure out correct receive buffer length */ |
| 2679 | switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED | |
| 2680 | I40E_FLAG_RX_PS_ENABLED)) { |
| 2681 | case I40E_FLAG_RX_1BUF_ENABLED: |
| 2682 | vsi->rx_hdr_len = 0; |
| 2683 | vsi->rx_buf_len = vsi->max_frame; |
| 2684 | vsi->dtype = I40E_RX_DTYPE_NO_SPLIT; |
| 2685 | break; |
| 2686 | case I40E_FLAG_RX_PS_ENABLED: |
| 2687 | vsi->rx_hdr_len = I40E_RX_HDR_SIZE; |
| 2688 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 2689 | vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT; |
| 2690 | break; |
| 2691 | default: |
| 2692 | vsi->rx_hdr_len = I40E_RX_HDR_SIZE; |
| 2693 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 2694 | vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS; |
| 2695 | break; |
| 2696 | } |
| 2697 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 2698 | #ifdef I40E_FCOE |
| 2699 | /* setup rx buffer for FCoE */ |
| 2700 | if ((vsi->type == I40E_VSI_FCOE) && |
| 2701 | (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) { |
| 2702 | vsi->rx_hdr_len = 0; |
| 2703 | vsi->rx_buf_len = I40E_RXBUFFER_3072; |
| 2704 | vsi->max_frame = I40E_RXBUFFER_3072; |
| 2705 | vsi->dtype = I40E_RX_DTYPE_NO_SPLIT; |
| 2706 | } |
| 2707 | |
| 2708 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2709 | /* round up for the chip's needs */ |
| 2710 | vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len, |
| 2711 | (1 << I40E_RXQ_CTX_HBUFF_SHIFT)); |
| 2712 | vsi->rx_buf_len = ALIGN(vsi->rx_buf_len, |
| 2713 | (1 << I40E_RXQ_CTX_DBUFF_SHIFT)); |
| 2714 | |
| 2715 | /* set up individual rings */ |
| 2716 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2717 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2718 | |
| 2719 | return err; |
| 2720 | } |
| 2721 | |
| 2722 | /** |
| 2723 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 2724 | * @vsi: ptr to the VSI |
| 2725 | **/ |
| 2726 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 2727 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 2728 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2729 | u16 qoffset, qcount; |
| 2730 | int i, n; |
| 2731 | |
Parikh, Neerav | cd238a3 | 2015-02-21 06:43:37 +0000 | [diff] [blame] | 2732 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 2733 | /* Reset the TC information */ |
| 2734 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 2735 | rx_ring = vsi->rx_rings[i]; |
| 2736 | tx_ring = vsi->tx_rings[i]; |
| 2737 | rx_ring->dcb_tc = 0; |
| 2738 | tx_ring->dcb_tc = 0; |
| 2739 | } |
| 2740 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2741 | |
| 2742 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
| 2743 | if (!(vsi->tc_config.enabled_tc & (1 << n))) |
| 2744 | continue; |
| 2745 | |
| 2746 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 2747 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 2748 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 2749 | rx_ring = vsi->rx_rings[i]; |
| 2750 | tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2751 | rx_ring->dcb_tc = n; |
| 2752 | tx_ring->dcb_tc = n; |
| 2753 | } |
| 2754 | } |
| 2755 | } |
| 2756 | |
| 2757 | /** |
| 2758 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 2759 | * @vsi: ptr to the VSI |
| 2760 | **/ |
| 2761 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 2762 | { |
| 2763 | if (vsi->netdev) |
| 2764 | i40e_set_rx_mode(vsi->netdev); |
| 2765 | } |
| 2766 | |
| 2767 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2768 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters |
| 2769 | * @vsi: Pointer to the targeted VSI |
| 2770 | * |
| 2771 | * This function replays the hlist on the hw where all the SB Flow Director |
| 2772 | * filters were saved. |
| 2773 | **/ |
| 2774 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) |
| 2775 | { |
| 2776 | struct i40e_fdir_filter *filter; |
| 2777 | struct i40e_pf *pf = vsi->back; |
| 2778 | struct hlist_node *node; |
| 2779 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 2780 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 2781 | return; |
| 2782 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2783 | hlist_for_each_entry_safe(filter, node, |
| 2784 | &pf->fdir_filter_list, fdir_node) { |
| 2785 | i40e_add_del_fdir(vsi, filter, true); |
| 2786 | } |
| 2787 | } |
| 2788 | |
| 2789 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2790 | * i40e_vsi_configure - Set up the VSI for action |
| 2791 | * @vsi: the VSI being configured |
| 2792 | **/ |
| 2793 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 2794 | { |
| 2795 | int err; |
| 2796 | |
| 2797 | i40e_set_vsi_rx_mode(vsi); |
| 2798 | i40e_restore_vlan(vsi); |
| 2799 | i40e_vsi_config_dcb_rings(vsi); |
| 2800 | err = i40e_vsi_configure_tx(vsi); |
| 2801 | if (!err) |
| 2802 | err = i40e_vsi_configure_rx(vsi); |
| 2803 | |
| 2804 | return err; |
| 2805 | } |
| 2806 | |
| 2807 | /** |
| 2808 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 2809 | * @vsi: the VSI being configured |
| 2810 | **/ |
| 2811 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 2812 | { |
| 2813 | struct i40e_pf *pf = vsi->back; |
| 2814 | struct i40e_q_vector *q_vector; |
| 2815 | struct i40e_hw *hw = &pf->hw; |
| 2816 | u16 vector; |
| 2817 | int i, q; |
| 2818 | u32 val; |
| 2819 | u32 qp; |
| 2820 | |
| 2821 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 2822 | * and PFINT_LNKLSTn registers, e.g.: |
| 2823 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 2824 | */ |
| 2825 | qp = vsi->base_queue; |
| 2826 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 2827 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
| 2828 | q_vector = vsi->q_vectors[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2829 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting); |
| 2830 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 2831 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 2832 | q_vector->rx.itr); |
| 2833 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting); |
| 2834 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 2835 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 2836 | q_vector->tx.itr); |
| 2837 | |
| 2838 | /* Linked list for the queuepairs assigned to this vector */ |
| 2839 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 2840 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
| 2841 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 2842 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 2843 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 2844 | (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
| 2845 | (I40E_QUEUE_TYPE_TX |
| 2846 | << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
| 2847 | |
| 2848 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 2849 | |
| 2850 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 2851 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 2852 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 2853 | ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| |
| 2854 | (I40E_QUEUE_TYPE_RX |
| 2855 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 2856 | |
| 2857 | /* Terminate the linked list */ |
| 2858 | if (q == (q_vector->num_ringpairs - 1)) |
| 2859 | val |= (I40E_QUEUE_END_OF_LIST |
| 2860 | << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 2861 | |
| 2862 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 2863 | qp++; |
| 2864 | } |
| 2865 | } |
| 2866 | |
| 2867 | i40e_flush(hw); |
| 2868 | } |
| 2869 | |
| 2870 | /** |
| 2871 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 2872 | * @hw: ptr to the hardware info |
| 2873 | **/ |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 2874 | static void i40e_enable_misc_int_causes(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2875 | { |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 2876 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2877 | u32 val; |
| 2878 | |
| 2879 | /* clear things first */ |
| 2880 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 2881 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 2882 | |
| 2883 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 2884 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 2885 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 2886 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 2887 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2888 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 2889 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 2890 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 2891 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 2892 | if (pf->flags & I40E_FLAG_PTP) |
| 2893 | val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
| 2894 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2895 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 2896 | |
| 2897 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 2898 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
| 2899 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2900 | |
| 2901 | /* OTHER_ITR_IDX = 0 */ |
| 2902 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 2903 | } |
| 2904 | |
| 2905 | /** |
| 2906 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 2907 | * @vsi: the VSI being configured |
| 2908 | **/ |
| 2909 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 2910 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 2911 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2912 | struct i40e_pf *pf = vsi->back; |
| 2913 | struct i40e_hw *hw = &pf->hw; |
| 2914 | u32 val; |
| 2915 | |
| 2916 | /* set the ITR configuration */ |
| 2917 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting); |
| 2918 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 2919 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
| 2920 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting); |
| 2921 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 2922 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 2923 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 2924 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2925 | |
| 2926 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 2927 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 2928 | |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 2929 | /* Associate the queue pair to the vector and enable the queue int */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2930 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 2931 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 2932 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 2933 | |
| 2934 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 2935 | |
| 2936 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 2937 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 2938 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 2939 | |
| 2940 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 2941 | i40e_flush(hw); |
| 2942 | } |
| 2943 | |
| 2944 | /** |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 2945 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 |
| 2946 | * @pf: board private structure |
| 2947 | **/ |
| 2948 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) |
| 2949 | { |
| 2950 | struct i40e_hw *hw = &pf->hw; |
| 2951 | |
| 2952 | wr32(hw, I40E_PFINT_DYN_CTL0, |
| 2953 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 2954 | i40e_flush(hw); |
| 2955 | } |
| 2956 | |
| 2957 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2958 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 2959 | * @pf: board private structure |
| 2960 | **/ |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 2961 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2962 | { |
| 2963 | struct i40e_hw *hw = &pf->hw; |
| 2964 | u32 val; |
| 2965 | |
| 2966 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
| 2967 | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK | |
| 2968 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 2969 | |
| 2970 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 2971 | i40e_flush(hw); |
| 2972 | } |
| 2973 | |
| 2974 | /** |
| 2975 | * i40e_irq_dynamic_enable - Enable default interrupt generation settings |
| 2976 | * @vsi: pointer to a vsi |
| 2977 | * @vector: enable a particular Hw Interrupt vector |
| 2978 | **/ |
| 2979 | void i40e_irq_dynamic_enable(struct i40e_vsi *vsi, int vector) |
| 2980 | { |
| 2981 | struct i40e_pf *pf = vsi->back; |
| 2982 | struct i40e_hw *hw = &pf->hw; |
| 2983 | u32 val; |
| 2984 | |
| 2985 | val = I40E_PFINT_DYN_CTLN_INTENA_MASK | |
| 2986 | I40E_PFINT_DYN_CTLN_CLEARPBA_MASK | |
| 2987 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 2988 | wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val); |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 2989 | /* skip the flush */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2990 | } |
| 2991 | |
| 2992 | /** |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 2993 | * i40e_irq_dynamic_disable - Disable default interrupt generation settings |
| 2994 | * @vsi: pointer to a vsi |
Greg Rose | 0314777 | 2015-01-24 09:58:29 +0000 | [diff] [blame] | 2995 | * @vector: disable a particular Hw Interrupt vector |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 2996 | **/ |
| 2997 | void i40e_irq_dynamic_disable(struct i40e_vsi *vsi, int vector) |
| 2998 | { |
| 2999 | struct i40e_pf *pf = vsi->back; |
| 3000 | struct i40e_hw *hw = &pf->hw; |
| 3001 | u32 val; |
| 3002 | |
| 3003 | val = I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT; |
| 3004 | wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val); |
| 3005 | i40e_flush(hw); |
| 3006 | } |
| 3007 | |
| 3008 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3009 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 3010 | * @irq: interrupt number |
| 3011 | * @data: pointer to a q_vector |
| 3012 | **/ |
| 3013 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 3014 | { |
| 3015 | struct i40e_q_vector *q_vector = data; |
| 3016 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3017 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3018 | return IRQ_HANDLED; |
| 3019 | |
| 3020 | napi_schedule(&q_vector->napi); |
| 3021 | |
| 3022 | return IRQ_HANDLED; |
| 3023 | } |
| 3024 | |
| 3025 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3026 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 3027 | * @vsi: the VSI being configured |
| 3028 | * @basename: name for the vector |
| 3029 | * |
| 3030 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 3031 | **/ |
| 3032 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 3033 | { |
| 3034 | int q_vectors = vsi->num_q_vectors; |
| 3035 | struct i40e_pf *pf = vsi->back; |
| 3036 | int base = vsi->base_vector; |
| 3037 | int rx_int_idx = 0; |
| 3038 | int tx_int_idx = 0; |
| 3039 | int vector, err; |
| 3040 | |
| 3041 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3042 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3043 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3044 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3045 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3046 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 3047 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3048 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3049 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3050 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3051 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3052 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 3053 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 3054 | } else { |
| 3055 | /* skip this unused q_vector */ |
| 3056 | continue; |
| 3057 | } |
| 3058 | err = request_irq(pf->msix_entries[base + vector].vector, |
| 3059 | vsi->irq_handler, |
| 3060 | 0, |
| 3061 | q_vector->name, |
| 3062 | q_vector); |
| 3063 | if (err) { |
| 3064 | dev_info(&pf->pdev->dev, |
| 3065 | "%s: request_irq failed, error: %d\n", |
| 3066 | __func__, err); |
| 3067 | goto free_queue_irqs; |
| 3068 | } |
| 3069 | /* assign the mask for this irq */ |
| 3070 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 3071 | &q_vector->affinity_mask); |
| 3072 | } |
| 3073 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3074 | vsi->irqs_ready = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3075 | return 0; |
| 3076 | |
| 3077 | free_queue_irqs: |
| 3078 | while (vector) { |
| 3079 | vector--; |
| 3080 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 3081 | NULL); |
| 3082 | free_irq(pf->msix_entries[base + vector].vector, |
| 3083 | &(vsi->q_vectors[vector])); |
| 3084 | } |
| 3085 | return err; |
| 3086 | } |
| 3087 | |
| 3088 | /** |
| 3089 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 3090 | * @vsi: the VSI being un-configured |
| 3091 | **/ |
| 3092 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 3093 | { |
| 3094 | struct i40e_pf *pf = vsi->back; |
| 3095 | struct i40e_hw *hw = &pf->hw; |
| 3096 | int base = vsi->base_vector; |
| 3097 | int i; |
| 3098 | |
| 3099 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3100 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); |
| 3101 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3102 | } |
| 3103 | |
| 3104 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3105 | for (i = vsi->base_vector; |
| 3106 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 3107 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 3108 | |
| 3109 | i40e_flush(hw); |
| 3110 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 3111 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 3112 | } else { |
| 3113 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 3114 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 3115 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 3116 | i40e_flush(hw); |
| 3117 | synchronize_irq(pf->pdev->irq); |
| 3118 | } |
| 3119 | } |
| 3120 | |
| 3121 | /** |
| 3122 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 3123 | * @vsi: the VSI being configured |
| 3124 | **/ |
| 3125 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 3126 | { |
| 3127 | struct i40e_pf *pf = vsi->back; |
| 3128 | int i; |
| 3129 | |
| 3130 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3131 | for (i = vsi->base_vector; |
| 3132 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 3133 | i40e_irq_dynamic_enable(vsi, i); |
| 3134 | } else { |
| 3135 | i40e_irq_dynamic_enable_icr0(pf); |
| 3136 | } |
| 3137 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 3138 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3139 | return 0; |
| 3140 | } |
| 3141 | |
| 3142 | /** |
| 3143 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events |
| 3144 | * @pf: board private structure |
| 3145 | **/ |
| 3146 | static void i40e_stop_misc_vector(struct i40e_pf *pf) |
| 3147 | { |
| 3148 | /* Disable ICR 0 */ |
| 3149 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 3150 | i40e_flush(&pf->hw); |
| 3151 | } |
| 3152 | |
| 3153 | /** |
| 3154 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 3155 | * @irq: interrupt number |
| 3156 | * @data: pointer to a q_vector |
| 3157 | * |
| 3158 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 3159 | * with both queue and non-queue interrupts. This is also used in |
| 3160 | * MSIX mode to handle the non-queue interrupts. |
| 3161 | **/ |
| 3162 | static irqreturn_t i40e_intr(int irq, void *data) |
| 3163 | { |
| 3164 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 3165 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3166 | irqreturn_t ret = IRQ_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3167 | u32 icr0, icr0_remaining; |
| 3168 | u32 val, ena_mask; |
| 3169 | |
| 3170 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3171 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3172 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 3173 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 3174 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3175 | goto enable_intr; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3176 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 3177 | /* if interrupt but no bits showing, must be SWINT */ |
| 3178 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 3179 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 3180 | pf->sw_int_count++; |
| 3181 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3182 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 3183 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
| 3184 | |
| 3185 | /* temporarily disable queue cause for NAPI processing */ |
| 3186 | u32 qval = rd32(hw, I40E_QINT_RQCTL(0)); |
| 3187 | qval &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK; |
| 3188 | wr32(hw, I40E_QINT_RQCTL(0), qval); |
| 3189 | |
| 3190 | qval = rd32(hw, I40E_QINT_TQCTL(0)); |
| 3191 | qval &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK; |
| 3192 | wr32(hw, I40E_QINT_TQCTL(0), qval); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3193 | |
| 3194 | if (!test_bit(__I40E_DOWN, &pf->state)) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3195 | napi_schedule(&pf->vsi[pf->lan_vsi]->q_vectors[0]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3196 | } |
| 3197 | |
| 3198 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 3199 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 3200 | set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 3201 | } |
| 3202 | |
| 3203 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 3204 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 3205 | set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 3206 | } |
| 3207 | |
| 3208 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 3209 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
| 3210 | set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
| 3211 | } |
| 3212 | |
| 3213 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
| 3214 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
| 3215 | set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 3216 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 3217 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 3218 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 3219 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3220 | if (val == I40E_RESET_CORER) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3221 | pf->corer_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3222 | } else if (val == I40E_RESET_GLOBR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3223 | pf->globr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3224 | } else if (val == I40E_RESET_EMPR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3225 | pf->empr_count++; |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 3226 | set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 3227 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3228 | } |
| 3229 | |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3230 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 3231 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; |
| 3232 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
Anjali Singhai Jain | 25fc0e6 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 3233 | dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n", |
| 3234 | rd32(hw, I40E_PFHMC_ERRORINFO), |
| 3235 | rd32(hw, I40E_PFHMC_ERRORDATA)); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3236 | } |
| 3237 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3238 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
| 3239 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); |
| 3240 | |
| 3241 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { |
Jacob Keller | cafa1fc | 2014-04-24 18:05:03 -0700 | [diff] [blame] | 3242 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3243 | i40e_ptp_tx_hwtstamp(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3244 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 3245 | } |
| 3246 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3247 | /* If a critical error is pending we have no choice but to reset the |
| 3248 | * device. |
| 3249 | * Report and mask out any remaining unexpected interrupts. |
| 3250 | */ |
| 3251 | icr0_remaining = icr0 & ena_mask; |
| 3252 | if (icr0_remaining) { |
| 3253 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 3254 | icr0_remaining); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3255 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3256 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
Anjali Singhai Jain | c0c2897 | 2014-02-12 01:45:34 +0000 | [diff] [blame] | 3257 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 3258 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
| 3259 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 3260 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3261 | } |
| 3262 | ena_mask &= ~icr0_remaining; |
| 3263 | } |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3264 | ret = IRQ_HANDLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3265 | |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3266 | enable_intr: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3267 | /* re-enable interrupt causes */ |
| 3268 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3269 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 3270 | i40e_service_event_schedule(pf); |
| 3271 | i40e_irq_dynamic_enable_icr0(pf); |
| 3272 | } |
| 3273 | |
Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 3274 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3275 | } |
| 3276 | |
| 3277 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3278 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes |
| 3279 | * @tx_ring: tx ring to clean |
| 3280 | * @budget: how many cleans we're allowed |
| 3281 | * |
| 3282 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 3283 | **/ |
| 3284 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) |
| 3285 | { |
| 3286 | struct i40e_vsi *vsi = tx_ring->vsi; |
| 3287 | u16 i = tx_ring->next_to_clean; |
| 3288 | struct i40e_tx_buffer *tx_buf; |
| 3289 | struct i40e_tx_desc *tx_desc; |
| 3290 | |
| 3291 | tx_buf = &tx_ring->tx_bi[i]; |
| 3292 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 3293 | i -= tx_ring->count; |
| 3294 | |
| 3295 | do { |
| 3296 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 3297 | |
| 3298 | /* if next_to_watch is not set then there is no work pending */ |
| 3299 | if (!eop_desc) |
| 3300 | break; |
| 3301 | |
| 3302 | /* prevent any other reads prior to eop_desc */ |
| 3303 | read_barrier_depends(); |
| 3304 | |
| 3305 | /* if the descriptor isn't done, no work yet to do */ |
| 3306 | if (!(eop_desc->cmd_type_offset_bsz & |
| 3307 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
| 3308 | break; |
| 3309 | |
| 3310 | /* clear next_to_watch to prevent false hangs */ |
| 3311 | tx_buf->next_to_watch = NULL; |
| 3312 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3313 | tx_desc->buffer_addr = 0; |
| 3314 | tx_desc->cmd_type_offset_bsz = 0; |
| 3315 | /* move past filter desc */ |
| 3316 | tx_buf++; |
| 3317 | tx_desc++; |
| 3318 | i++; |
| 3319 | if (unlikely(!i)) { |
| 3320 | i -= tx_ring->count; |
| 3321 | tx_buf = tx_ring->tx_bi; |
| 3322 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3323 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3324 | /* unmap skb header data */ |
| 3325 | dma_unmap_single(tx_ring->dev, |
| 3326 | dma_unmap_addr(tx_buf, dma), |
| 3327 | dma_unmap_len(tx_buf, len), |
| 3328 | DMA_TO_DEVICE); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3329 | if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB) |
| 3330 | kfree(tx_buf->raw_buf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3331 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3332 | tx_buf->raw_buf = NULL; |
| 3333 | tx_buf->tx_flags = 0; |
| 3334 | tx_buf->next_to_watch = NULL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3335 | dma_unmap_len_set(tx_buf, len, 0); |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3336 | tx_desc->buffer_addr = 0; |
| 3337 | tx_desc->cmd_type_offset_bsz = 0; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 3338 | |
Anjali Singhai Jain | 49d7d93 | 2014-06-04 08:45:15 +0000 | [diff] [blame] | 3339 | /* 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] | 3340 | tx_buf++; |
| 3341 | tx_desc++; |
| 3342 | i++; |
| 3343 | if (unlikely(!i)) { |
| 3344 | i -= tx_ring->count; |
| 3345 | tx_buf = tx_ring->tx_bi; |
| 3346 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3347 | } |
| 3348 | |
| 3349 | /* update budget accounting */ |
| 3350 | budget--; |
| 3351 | } while (likely(budget)); |
| 3352 | |
| 3353 | i += tx_ring->count; |
| 3354 | tx_ring->next_to_clean = i; |
| 3355 | |
| 3356 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3357 | i40e_irq_dynamic_enable(vsi, |
| 3358 | tx_ring->q_vector->v_idx + vsi->base_vector); |
| 3359 | } |
| 3360 | return budget > 0; |
| 3361 | } |
| 3362 | |
| 3363 | /** |
| 3364 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring |
| 3365 | * @irq: interrupt number |
| 3366 | * @data: pointer to a q_vector |
| 3367 | **/ |
| 3368 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) |
| 3369 | { |
| 3370 | struct i40e_q_vector *q_vector = data; |
| 3371 | struct i40e_vsi *vsi; |
| 3372 | |
| 3373 | if (!q_vector->tx.ring) |
| 3374 | return IRQ_HANDLED; |
| 3375 | |
| 3376 | vsi = q_vector->tx.ring->vsi; |
| 3377 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); |
| 3378 | |
| 3379 | return IRQ_HANDLED; |
| 3380 | } |
| 3381 | |
| 3382 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3383 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3384 | * @vsi: the VSI being configured |
| 3385 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3386 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3387 | **/ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3388 | static void 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] | 3389 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3390 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3391 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 3392 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3393 | |
| 3394 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3395 | tx_ring->next = q_vector->tx.ring; |
| 3396 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3397 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3398 | |
| 3399 | rx_ring->q_vector = q_vector; |
| 3400 | rx_ring->next = q_vector->rx.ring; |
| 3401 | q_vector->rx.ring = rx_ring; |
| 3402 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3403 | } |
| 3404 | |
| 3405 | /** |
| 3406 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 3407 | * @vsi: the VSI being configured |
| 3408 | * |
| 3409 | * This function maps descriptor rings to the queue-specific vectors |
| 3410 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 3411 | * one vector per queue pair, but on a constrained vector budget, we |
| 3412 | * group the queue pairs as "efficiently" as possible. |
| 3413 | **/ |
| 3414 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 3415 | { |
| 3416 | int qp_remaining = vsi->num_queue_pairs; |
| 3417 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3418 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3419 | int v_start = 0; |
| 3420 | int qp_idx = 0; |
| 3421 | |
| 3422 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 3423 | * group them so there are multiple queues per vector. |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3424 | * It is also important to go through all the vectors available to be |
| 3425 | * sure that if we don't use all the vectors, that the remaining vectors |
| 3426 | * are cleared. This is especially important when decreasing the |
| 3427 | * number of queues in use. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3428 | */ |
Anjali Singhai Jain | 70114ec | 2014-06-03 23:50:14 +0000 | [diff] [blame] | 3429 | for (; v_start < q_vectors; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3430 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 3431 | |
| 3432 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 3433 | |
| 3434 | q_vector->num_ringpairs = num_ringpairs; |
| 3435 | |
| 3436 | q_vector->rx.count = 0; |
| 3437 | q_vector->tx.count = 0; |
| 3438 | q_vector->rx.ring = NULL; |
| 3439 | q_vector->tx.ring = NULL; |
| 3440 | |
| 3441 | while (num_ringpairs--) { |
| 3442 | map_vector_to_qp(vsi, v_start, qp_idx); |
| 3443 | qp_idx++; |
| 3444 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3445 | } |
| 3446 | } |
| 3447 | } |
| 3448 | |
| 3449 | /** |
| 3450 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 3451 | * @vsi: the VSI being configured |
| 3452 | * @basename: name for the vector |
| 3453 | **/ |
| 3454 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 3455 | { |
| 3456 | struct i40e_pf *pf = vsi->back; |
| 3457 | int err; |
| 3458 | |
| 3459 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 3460 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 3461 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 3462 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3463 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3464 | else |
| 3465 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 3466 | pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3467 | |
| 3468 | if (err) |
| 3469 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 3470 | |
| 3471 | return err; |
| 3472 | } |
| 3473 | |
| 3474 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3475 | /** |
| 3476 | * i40e_netpoll - A Polling 'interrupt'handler |
| 3477 | * @netdev: network interface device structure |
| 3478 | * |
| 3479 | * This is used by netconsole to send skbs without having to re-enable |
| 3480 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 3481 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3482 | #ifdef I40E_FCOE |
| 3483 | void i40e_netpoll(struct net_device *netdev) |
| 3484 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3485 | static void i40e_netpoll(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 3486 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3487 | { |
| 3488 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3489 | struct i40e_vsi *vsi = np->vsi; |
| 3490 | struct i40e_pf *pf = vsi->back; |
| 3491 | int i; |
| 3492 | |
| 3493 | /* if interface is down do nothing */ |
| 3494 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 3495 | return; |
| 3496 | |
| 3497 | pf->flags |= I40E_FLAG_IN_NETPOLL; |
| 3498 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3499 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3500 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3501 | } else { |
| 3502 | i40e_intr(pf->pdev->irq, netdev); |
| 3503 | } |
| 3504 | pf->flags &= ~I40E_FLAG_IN_NETPOLL; |
| 3505 | } |
| 3506 | #endif |
| 3507 | |
| 3508 | /** |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3509 | * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled |
| 3510 | * @pf: the PF being configured |
| 3511 | * @pf_q: the PF queue |
| 3512 | * @enable: enable or disable state of the queue |
| 3513 | * |
| 3514 | * This routine will wait for the given Tx queue of the PF to reach the |
| 3515 | * enabled or disabled state. |
| 3516 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3517 | * multiple retries; else will return 0 in case of success. |
| 3518 | **/ |
| 3519 | static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3520 | { |
| 3521 | int i; |
| 3522 | u32 tx_reg; |
| 3523 | |
| 3524 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3525 | tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q)); |
| 3526 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 3527 | break; |
| 3528 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3529 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3530 | } |
| 3531 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3532 | return -ETIMEDOUT; |
| 3533 | |
| 3534 | return 0; |
| 3535 | } |
| 3536 | |
| 3537 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3538 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 3539 | * @vsi: the VSI being configured |
| 3540 | * @enable: start or stop the rings |
| 3541 | **/ |
| 3542 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 3543 | { |
| 3544 | struct i40e_pf *pf = vsi->back; |
| 3545 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3546 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3547 | u32 tx_reg; |
| 3548 | |
| 3549 | pf_q = vsi->base_queue; |
| 3550 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Matt Jared | 351499a | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3551 | |
| 3552 | /* warn the TX unit of coming changes */ |
| 3553 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); |
| 3554 | if (!enable) |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3555 | usleep_range(10, 20); |
Matt Jared | 351499a | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3556 | |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3557 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3558 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3559 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3560 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3561 | break; |
| 3562 | usleep_range(1000, 2000); |
| 3563 | } |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3564 | /* Skip if the queue is already in the requested state */ |
Catherine Sullivan | 7c12200 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3565 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3566 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3567 | |
| 3568 | /* turn on/off the queue */ |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3569 | if (enable) { |
| 3570 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3571 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3572 | } else { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3573 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3574 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3575 | |
| 3576 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 3577 | /* No waiting for the Tx queue to disable */ |
| 3578 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
| 3579 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3580 | |
| 3581 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3582 | ret = i40e_pf_txq_wait(pf, pf_q, enable); |
| 3583 | if (ret) { |
| 3584 | dev_info(&pf->pdev->dev, |
| 3585 | "%s: VSI seid %d Tx ring %d %sable timeout\n", |
| 3586 | __func__, vsi->seid, pf_q, |
| 3587 | (enable ? "en" : "dis")); |
| 3588 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3589 | } |
| 3590 | } |
| 3591 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3592 | if (hw->revision_id == 0) |
| 3593 | mdelay(50); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3594 | return ret; |
| 3595 | } |
| 3596 | |
| 3597 | /** |
| 3598 | * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled |
| 3599 | * @pf: the PF being configured |
| 3600 | * @pf_q: the PF queue |
| 3601 | * @enable: enable or disable state of the queue |
| 3602 | * |
| 3603 | * This routine will wait for the given Rx queue of the PF to reach the |
| 3604 | * enabled or disabled state. |
| 3605 | * Returns -ETIMEDOUT in case of failing to reach the requested state after |
| 3606 | * multiple retries; else will return 0 in case of success. |
| 3607 | **/ |
| 3608 | static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable) |
| 3609 | { |
| 3610 | int i; |
| 3611 | u32 rx_reg; |
| 3612 | |
| 3613 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { |
| 3614 | rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q)); |
| 3615 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3616 | break; |
| 3617 | |
Neerav Parikh | f98a200 | 2014-09-13 07:40:44 +0000 | [diff] [blame] | 3618 | usleep_range(10, 20); |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3619 | } |
| 3620 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) |
| 3621 | return -ETIMEDOUT; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3622 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3623 | return 0; |
| 3624 | } |
| 3625 | |
| 3626 | /** |
| 3627 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 3628 | * @vsi: the VSI being configured |
| 3629 | * @enable: start or stop the rings |
| 3630 | **/ |
| 3631 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 3632 | { |
| 3633 | struct i40e_pf *pf = vsi->back; |
| 3634 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3635 | int i, j, pf_q, ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3636 | u32 rx_reg; |
| 3637 | |
| 3638 | pf_q = vsi->base_queue; |
| 3639 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3640 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3641 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3642 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3643 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3644 | break; |
| 3645 | usleep_range(1000, 2000); |
| 3646 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3647 | |
Catherine Sullivan | 7c12200 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3648 | /* Skip if the queue is already in the requested state */ |
| 3649 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3650 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3651 | |
| 3652 | /* turn on/off the queue */ |
| 3653 | if (enable) |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3654 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3655 | else |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3656 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3657 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
| 3658 | |
| 3659 | /* wait for the change to finish */ |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3660 | ret = i40e_pf_rxq_wait(pf, pf_q, enable); |
| 3661 | if (ret) { |
| 3662 | dev_info(&pf->pdev->dev, |
| 3663 | "%s: VSI seid %d Rx ring %d %sable timeout\n", |
| 3664 | __func__, vsi->seid, pf_q, |
| 3665 | (enable ? "en" : "dis")); |
| 3666 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3667 | } |
| 3668 | } |
| 3669 | |
Neerav Parikh | 2352730 | 2014-06-03 23:50:15 +0000 | [diff] [blame] | 3670 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3671 | } |
| 3672 | |
| 3673 | /** |
| 3674 | * i40e_vsi_control_rings - Start or stop a VSI's rings |
| 3675 | * @vsi: the VSI being configured |
| 3676 | * @enable: start or stop the rings |
| 3677 | **/ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 3678 | int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3679 | { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3680 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3681 | |
| 3682 | /* do rx first for enable and last for disable */ |
| 3683 | if (request) { |
| 3684 | ret = i40e_vsi_control_rx(vsi, request); |
| 3685 | if (ret) |
| 3686 | return ret; |
| 3687 | ret = i40e_vsi_control_tx(vsi, request); |
| 3688 | } else { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3689 | /* Ignore return value, we need to shutdown whatever we can */ |
| 3690 | i40e_vsi_control_tx(vsi, request); |
| 3691 | i40e_vsi_control_rx(vsi, request); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3692 | } |
| 3693 | |
| 3694 | return ret; |
| 3695 | } |
| 3696 | |
| 3697 | /** |
| 3698 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 3699 | * @vsi: the VSI being configured |
| 3700 | **/ |
| 3701 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 3702 | { |
| 3703 | struct i40e_pf *pf = vsi->back; |
| 3704 | struct i40e_hw *hw = &pf->hw; |
| 3705 | int base = vsi->base_vector; |
| 3706 | u32 val, qp; |
| 3707 | int i; |
| 3708 | |
| 3709 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3710 | if (!vsi->q_vectors) |
| 3711 | return; |
| 3712 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 3713 | if (!vsi->irqs_ready) |
| 3714 | return; |
| 3715 | |
| 3716 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3717 | for (i = 0; i < vsi->num_q_vectors; i++) { |
| 3718 | u16 vector = i + base; |
| 3719 | |
| 3720 | /* free only the irqs that were actually requested */ |
Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 3721 | if (!vsi->q_vectors[i] || |
| 3722 | !vsi->q_vectors[i]->num_ringpairs) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3723 | continue; |
| 3724 | |
| 3725 | /* clear the affinity_mask in the IRQ descriptor */ |
| 3726 | irq_set_affinity_hint(pf->msix_entries[vector].vector, |
| 3727 | NULL); |
| 3728 | free_irq(pf->msix_entries[vector].vector, |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3729 | vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3730 | |
| 3731 | /* Tear down the interrupt queue link list |
| 3732 | * |
| 3733 | * We know that they come in pairs and always |
| 3734 | * the Rx first, then the Tx. To clear the |
| 3735 | * link list, stick the EOL value into the |
| 3736 | * next_q field of the registers. |
| 3737 | */ |
| 3738 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 3739 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 3740 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 3741 | val |= I40E_QUEUE_END_OF_LIST |
| 3742 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 3743 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 3744 | |
| 3745 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 3746 | u32 next; |
| 3747 | |
| 3748 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 3749 | |
| 3750 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 3751 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 3752 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3753 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 3754 | |
| 3755 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 3756 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 3757 | |
| 3758 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3759 | |
| 3760 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 3761 | |
| 3762 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 3763 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 3764 | |
| 3765 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 3766 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 3767 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3768 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 3769 | |
| 3770 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 3771 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 3772 | |
| 3773 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3774 | qp = next; |
| 3775 | } |
| 3776 | } |
| 3777 | } else { |
| 3778 | free_irq(pf->pdev->irq, pf); |
| 3779 | |
| 3780 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 3781 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 3782 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 3783 | val |= I40E_QUEUE_END_OF_LIST |
| 3784 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 3785 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 3786 | |
| 3787 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 3788 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 3789 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 3790 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3791 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 3792 | |
| 3793 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 3794 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 3795 | |
| 3796 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3797 | |
| 3798 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 3799 | |
| 3800 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 3801 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 3802 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3803 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 3804 | |
| 3805 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 3806 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 3807 | |
| 3808 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3809 | } |
| 3810 | } |
| 3811 | |
| 3812 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3813 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 3814 | * @vsi: the VSI being configured |
| 3815 | * @v_idx: Index of vector to be freed |
| 3816 | * |
| 3817 | * This function frees the memory allocated to the q_vector. In addition if |
| 3818 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 3819 | * to freeing the q_vector. |
| 3820 | **/ |
| 3821 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 3822 | { |
| 3823 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3824 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3825 | |
| 3826 | if (!q_vector) |
| 3827 | return; |
| 3828 | |
| 3829 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3830 | i40e_for_each_ring(ring, q_vector->tx) |
| 3831 | ring->q_vector = NULL; |
| 3832 | |
| 3833 | i40e_for_each_ring(ring, q_vector->rx) |
| 3834 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3835 | |
| 3836 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 3837 | if (vsi->netdev) |
| 3838 | netif_napi_del(&q_vector->napi); |
| 3839 | |
| 3840 | vsi->q_vectors[v_idx] = NULL; |
| 3841 | |
| 3842 | kfree_rcu(q_vector, rcu); |
| 3843 | } |
| 3844 | |
| 3845 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3846 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 3847 | * @vsi: the VSI being un-configured |
| 3848 | * |
| 3849 | * This frees the memory allocated to the q_vectors and |
| 3850 | * deletes references to the NAPI struct. |
| 3851 | **/ |
| 3852 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 3853 | { |
| 3854 | int v_idx; |
| 3855 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3856 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 3857 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3858 | } |
| 3859 | |
| 3860 | /** |
| 3861 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 3862 | * @pf: board private structure |
| 3863 | **/ |
| 3864 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 3865 | { |
| 3866 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 3867 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3868 | pci_disable_msix(pf->pdev); |
| 3869 | kfree(pf->msix_entries); |
| 3870 | pf->msix_entries = NULL; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 3871 | kfree(pf->irq_pile); |
| 3872 | pf->irq_pile = NULL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3873 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 3874 | pci_disable_msi(pf->pdev); |
| 3875 | } |
| 3876 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 3877 | } |
| 3878 | |
| 3879 | /** |
| 3880 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 3881 | * @pf: board private structure |
| 3882 | * |
| 3883 | * We go through and clear interrupt specific resources and reset the structure |
| 3884 | * to pre-load conditions |
| 3885 | **/ |
| 3886 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 3887 | { |
| 3888 | int i; |
| 3889 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 3890 | i40e_stop_misc_vector(pf); |
| 3891 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3892 | synchronize_irq(pf->msix_entries[0].vector); |
| 3893 | free_irq(pf->msix_entries[0].vector, pf); |
| 3894 | } |
| 3895 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3896 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 3897 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3898 | if (pf->vsi[i]) |
| 3899 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 3900 | i40e_reset_interrupt_capability(pf); |
| 3901 | } |
| 3902 | |
| 3903 | /** |
| 3904 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 3905 | * @vsi: the VSI being configured |
| 3906 | **/ |
| 3907 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 3908 | { |
| 3909 | int q_idx; |
| 3910 | |
| 3911 | if (!vsi->netdev) |
| 3912 | return; |
| 3913 | |
| 3914 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3915 | napi_enable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3916 | } |
| 3917 | |
| 3918 | /** |
| 3919 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 3920 | * @vsi: the VSI being configured |
| 3921 | **/ |
| 3922 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 3923 | { |
| 3924 | int q_idx; |
| 3925 | |
| 3926 | if (!vsi->netdev) |
| 3927 | return; |
| 3928 | |
| 3929 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3930 | napi_disable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3931 | } |
| 3932 | |
| 3933 | /** |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 3934 | * i40e_vsi_close - Shut down a VSI |
| 3935 | * @vsi: the vsi to be quelled |
| 3936 | **/ |
| 3937 | static void i40e_vsi_close(struct i40e_vsi *vsi) |
| 3938 | { |
| 3939 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) |
| 3940 | i40e_down(vsi); |
| 3941 | i40e_vsi_free_irq(vsi); |
| 3942 | i40e_vsi_free_tx_resources(vsi); |
| 3943 | i40e_vsi_free_rx_resources(vsi); |
| 3944 | } |
| 3945 | |
| 3946 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3947 | * i40e_quiesce_vsi - Pause a given VSI |
| 3948 | * @vsi: the VSI being paused |
| 3949 | **/ |
| 3950 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 3951 | { |
| 3952 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 3953 | return; |
| 3954 | |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 3955 | /* No need to disable FCoE VSI when Tx suspended */ |
| 3956 | if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) && |
| 3957 | vsi->type == I40E_VSI_FCOE) { |
| 3958 | dev_dbg(&vsi->back->pdev->dev, |
| 3959 | "%s: VSI seid %d skipping FCoE VSI disable\n", |
| 3960 | __func__, vsi->seid); |
| 3961 | return; |
| 3962 | } |
| 3963 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3964 | set_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 3965 | if (vsi->netdev && netif_running(vsi->netdev)) { |
| 3966 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
| 3967 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 3968 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3969 | } |
| 3970 | } |
| 3971 | |
| 3972 | /** |
| 3973 | * i40e_unquiesce_vsi - Resume a given VSI |
| 3974 | * @vsi: the VSI being resumed |
| 3975 | **/ |
| 3976 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 3977 | { |
| 3978 | if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) |
| 3979 | return; |
| 3980 | |
| 3981 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 3982 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 3983 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 3984 | else |
Shannon Nelson | 8276f75 | 2014-03-14 07:32:27 +0000 | [diff] [blame] | 3985 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3986 | } |
| 3987 | |
| 3988 | /** |
| 3989 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 3990 | * @pf: the PF |
| 3991 | **/ |
| 3992 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 3993 | { |
| 3994 | int v; |
| 3995 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 3996 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3997 | if (pf->vsi[v]) |
| 3998 | i40e_quiesce_vsi(pf->vsi[v]); |
| 3999 | } |
| 4000 | } |
| 4001 | |
| 4002 | /** |
| 4003 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 4004 | * @pf: the PF |
| 4005 | **/ |
| 4006 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 4007 | { |
| 4008 | int v; |
| 4009 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4010 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4011 | if (pf->vsi[v]) |
| 4012 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 4013 | } |
| 4014 | } |
| 4015 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4016 | #ifdef CONFIG_I40E_DCB |
| 4017 | /** |
| 4018 | * i40e_vsi_wait_txq_disabled - Wait for VSI's queues to be disabled |
| 4019 | * @vsi: the VSI being configured |
| 4020 | * |
| 4021 | * This function waits for the given VSI's Tx queues to be disabled. |
| 4022 | **/ |
| 4023 | static int i40e_vsi_wait_txq_disabled(struct i40e_vsi *vsi) |
| 4024 | { |
| 4025 | struct i40e_pf *pf = vsi->back; |
| 4026 | int i, pf_q, ret; |
| 4027 | |
| 4028 | pf_q = vsi->base_queue; |
| 4029 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 4030 | /* Check and wait for the disable status of the queue */ |
| 4031 | ret = i40e_pf_txq_wait(pf, pf_q, false); |
| 4032 | if (ret) { |
| 4033 | dev_info(&pf->pdev->dev, |
| 4034 | "%s: VSI seid %d Tx ring %d disable timeout\n", |
| 4035 | __func__, vsi->seid, pf_q); |
| 4036 | return ret; |
| 4037 | } |
| 4038 | } |
| 4039 | |
| 4040 | return 0; |
| 4041 | } |
| 4042 | |
| 4043 | /** |
| 4044 | * i40e_pf_wait_txq_disabled - Wait for all queues of PF VSIs to be disabled |
| 4045 | * @pf: the PF |
| 4046 | * |
| 4047 | * This function waits for the Tx queues to be in disabled state for all the |
| 4048 | * VSIs that are managed by this PF. |
| 4049 | **/ |
| 4050 | static int i40e_pf_wait_txq_disabled(struct i40e_pf *pf) |
| 4051 | { |
| 4052 | int v, ret = 0; |
| 4053 | |
| 4054 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
Neerav Parikh | d341b7a | 2014-11-12 00:18:51 +0000 | [diff] [blame] | 4055 | /* No need to wait for FCoE VSI queues */ |
| 4056 | if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) { |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 4057 | ret = i40e_vsi_wait_txq_disabled(pf->vsi[v]); |
| 4058 | if (ret) |
| 4059 | break; |
| 4060 | } |
| 4061 | } |
| 4062 | |
| 4063 | return ret; |
| 4064 | } |
| 4065 | |
| 4066 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4067 | /** |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4068 | * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4069 | * @pf: pointer to PF |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4070 | * |
| 4071 | * Get TC map for ISCSI PF type that will include iSCSI TC |
| 4072 | * and LAN TC. |
| 4073 | **/ |
| 4074 | static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf) |
| 4075 | { |
| 4076 | struct i40e_dcb_app_priority_table app; |
| 4077 | struct i40e_hw *hw = &pf->hw; |
| 4078 | u8 enabled_tc = 1; /* TC0 is always enabled */ |
| 4079 | u8 tc, i; |
| 4080 | /* Get the iSCSI APP TLV */ |
| 4081 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4082 | |
| 4083 | for (i = 0; i < dcbcfg->numapps; i++) { |
| 4084 | app = dcbcfg->app[i]; |
| 4085 | if (app.selector == I40E_APP_SEL_TCPIP && |
| 4086 | app.protocolid == I40E_APP_PROTOID_ISCSI) { |
| 4087 | tc = dcbcfg->etscfg.prioritytable[app.priority]; |
| 4088 | enabled_tc |= (1 << tc); |
| 4089 | break; |
| 4090 | } |
| 4091 | } |
| 4092 | |
| 4093 | return enabled_tc; |
| 4094 | } |
| 4095 | |
| 4096 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4097 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 4098 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4099 | * |
| 4100 | * Return the number of TCs from given DCBx configuration |
| 4101 | **/ |
| 4102 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 4103 | { |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4104 | u8 num_tc = 0; |
| 4105 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4106 | |
| 4107 | /* Scan the ETS Config Priority Table to find |
| 4108 | * traffic class enabled for a given priority |
| 4109 | * and use the traffic class index to get the |
| 4110 | * number of traffic classes enabled |
| 4111 | */ |
| 4112 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4113 | if (dcbcfg->etscfg.prioritytable[i] > num_tc) |
| 4114 | num_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4115 | } |
| 4116 | |
| 4117 | /* Traffic class index starts from zero so |
| 4118 | * increment to return the actual count |
| 4119 | */ |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4120 | return num_tc + 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4121 | } |
| 4122 | |
| 4123 | /** |
| 4124 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 4125 | * @dcbcfg: the corresponding DCBx configuration structure |
| 4126 | * |
| 4127 | * Query the current DCB configuration and return the number of |
| 4128 | * traffic classes enabled from the given DCBX config |
| 4129 | **/ |
| 4130 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 4131 | { |
| 4132 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 4133 | u8 enabled_tc = 1; |
| 4134 | u8 i; |
| 4135 | |
| 4136 | for (i = 0; i < num_tc; i++) |
| 4137 | enabled_tc |= 1 << i; |
| 4138 | |
| 4139 | return enabled_tc; |
| 4140 | } |
| 4141 | |
| 4142 | /** |
| 4143 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 4144 | * @pf: PF being queried |
| 4145 | * |
| 4146 | * Return number of traffic classes enabled for the given PF |
| 4147 | **/ |
| 4148 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 4149 | { |
| 4150 | struct i40e_hw *hw = &pf->hw; |
| 4151 | u8 i, enabled_tc; |
| 4152 | u8 num_tc = 0; |
| 4153 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4154 | |
| 4155 | /* If DCB is not enabled then always in single TC */ |
| 4156 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4157 | return 1; |
| 4158 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4159 | /* SFP mode will be enabled for all TCs on port */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4160 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4161 | return i40e_dcb_get_num_tc(dcbcfg); |
| 4162 | |
| 4163 | /* MFP mode return count of enabled TCs for this PF */ |
| 4164 | if (pf->hw.func_caps.iscsi) |
| 4165 | enabled_tc = i40e_get_iscsi_tc_map(pf); |
| 4166 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4167 | return 1; /* Only TC0 */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4168 | |
| 4169 | /* At least have TC0 */ |
| 4170 | enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 4171 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4172 | if (enabled_tc & (1 << i)) |
| 4173 | num_tc++; |
| 4174 | } |
| 4175 | return num_tc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4176 | } |
| 4177 | |
| 4178 | /** |
| 4179 | * i40e_pf_get_default_tc - Get bitmap for first enabled TC |
| 4180 | * @pf: PF being queried |
| 4181 | * |
| 4182 | * Return a bitmap for first enabled traffic class for this PF. |
| 4183 | **/ |
| 4184 | static u8 i40e_pf_get_default_tc(struct i40e_pf *pf) |
| 4185 | { |
| 4186 | u8 enabled_tc = pf->hw.func_caps.enabled_tcmap; |
| 4187 | u8 i = 0; |
| 4188 | |
| 4189 | if (!enabled_tc) |
| 4190 | return 0x1; /* TC0 */ |
| 4191 | |
| 4192 | /* Find the first enabled TC */ |
| 4193 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4194 | if (enabled_tc & (1 << i)) |
| 4195 | break; |
| 4196 | } |
| 4197 | |
| 4198 | return 1 << i; |
| 4199 | } |
| 4200 | |
| 4201 | /** |
| 4202 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 4203 | * @pf: PF being queried |
| 4204 | * |
| 4205 | * Return a bitmap for enabled traffic classes for this PF. |
| 4206 | **/ |
| 4207 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 4208 | { |
| 4209 | /* If DCB is not enabled for this PF then just return default TC */ |
| 4210 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 4211 | return i40e_pf_get_default_tc(pf); |
| 4212 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4213 | /* SFP mode we want PF to be enabled for all TCs */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4214 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 4215 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); |
| 4216 | |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4217 | /* MFP enabled and iSCSI PF type */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 4218 | if (pf->hw.func_caps.iscsi) |
| 4219 | return i40e_get_iscsi_tc_map(pf); |
| 4220 | else |
Neerav Parikh | fc51de9 | 2015-02-24 06:58:53 +0000 | [diff] [blame] | 4221 | return i40e_pf_get_default_tc(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4222 | } |
| 4223 | |
| 4224 | /** |
| 4225 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 4226 | * @vsi: the VSI being queried |
| 4227 | * |
| 4228 | * Returns 0 on success, negative value on failure |
| 4229 | **/ |
| 4230 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 4231 | { |
| 4232 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 4233 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 4234 | struct i40e_pf *pf = vsi->back; |
| 4235 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4236 | i40e_status aq_ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4237 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4238 | int i; |
| 4239 | |
| 4240 | /* Get the VSI level BW configuration */ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4241 | aq_ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
| 4242 | if (aq_ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4243 | dev_info(&pf->pdev->dev, |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4244 | "couldn't get PF vsi bw config, err %d, aq_err %d\n", |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4245 | aq_ret, pf->hw.aq.asq_last_status); |
| 4246 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4247 | } |
| 4248 | |
| 4249 | /* Get the VSI level BW configuration per TC */ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4250 | aq_ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
Jesse Brandeburg | 6838b53 | 2014-01-14 00:49:52 -0800 | [diff] [blame] | 4251 | NULL); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4252 | if (aq_ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4253 | dev_info(&pf->pdev->dev, |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 4254 | "couldn't get PF vsi ets bw config, err %d, aq_err %d\n", |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4255 | aq_ret, pf->hw.aq.asq_last_status); |
| 4256 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4257 | } |
| 4258 | |
| 4259 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 4260 | dev_info(&pf->pdev->dev, |
| 4261 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 4262 | bw_config.tc_valid_bits, |
| 4263 | bw_ets_config.tc_valid_bits); |
| 4264 | /* Still continuing */ |
| 4265 | } |
| 4266 | |
| 4267 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 4268 | vsi->bw_max_quanta = bw_config.max_bw; |
| 4269 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 4270 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 4271 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4272 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 4273 | vsi->bw_ets_limit_credits[i] = |
| 4274 | le16_to_cpu(bw_ets_config.credits[i]); |
| 4275 | /* 3 bits out of 4 for each TC */ |
| 4276 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 4277 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 4278 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4279 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4280 | } |
| 4281 | |
| 4282 | /** |
| 4283 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 4284 | * @vsi: the VSI being configured |
| 4285 | * @enabled_tc: TC bitmap |
| 4286 | * @bw_credits: BW shared credits per TC |
| 4287 | * |
| 4288 | * Returns 0 on success, negative value on failure |
| 4289 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4290 | 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] | 4291 | u8 *bw_share) |
| 4292 | { |
| 4293 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4294 | i40e_status aq_ret; |
| 4295 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4296 | |
| 4297 | bw_data.tc_valid_bits = enabled_tc; |
| 4298 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4299 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 4300 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4301 | aq_ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 4302 | NULL); |
| 4303 | if (aq_ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4304 | dev_info(&vsi->back->pdev->dev, |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4305 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
| 4306 | vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4307 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4308 | } |
| 4309 | |
| 4310 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 4311 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 4312 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 4313 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4314 | } |
| 4315 | |
| 4316 | /** |
| 4317 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 4318 | * @vsi: the VSI being configured |
| 4319 | * @enabled_tc: TC map to be enabled |
| 4320 | * |
| 4321 | **/ |
| 4322 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4323 | { |
| 4324 | struct net_device *netdev = vsi->netdev; |
| 4325 | struct i40e_pf *pf = vsi->back; |
| 4326 | struct i40e_hw *hw = &pf->hw; |
| 4327 | u8 netdev_tc = 0; |
| 4328 | int i; |
| 4329 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 4330 | |
| 4331 | if (!netdev) |
| 4332 | return; |
| 4333 | |
| 4334 | if (!enabled_tc) { |
| 4335 | netdev_reset_tc(netdev); |
| 4336 | return; |
| 4337 | } |
| 4338 | |
| 4339 | /* Set up actual enabled TCs on the VSI */ |
| 4340 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 4341 | return; |
| 4342 | |
| 4343 | /* set per TC queues for the VSI */ |
| 4344 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4345 | /* Only set TC queues for enabled tcs |
| 4346 | * |
| 4347 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 4348 | * enabled_tc bitmap would be 0x00001001; the driver |
| 4349 | * will set the numtc for netdev as 2 that will be |
| 4350 | * referenced by the netdev layer as TC 0 and 1. |
| 4351 | */ |
| 4352 | if (vsi->tc_config.enabled_tc & (1 << i)) |
| 4353 | netdev_set_tc_queue(netdev, |
| 4354 | vsi->tc_config.tc_info[i].netdev_tc, |
| 4355 | vsi->tc_config.tc_info[i].qcount, |
| 4356 | vsi->tc_config.tc_info[i].qoffset); |
| 4357 | } |
| 4358 | |
| 4359 | /* Assign UP2TC map for the VSI */ |
| 4360 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 4361 | /* Get the actual TC# for the UP */ |
| 4362 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 4363 | /* Get the mapped netdev TC# for the UP */ |
| 4364 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 4365 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 4366 | } |
| 4367 | } |
| 4368 | |
| 4369 | /** |
| 4370 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 4371 | * @vsi: the VSI being configured |
| 4372 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 4373 | **/ |
| 4374 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 4375 | struct i40e_vsi_context *ctxt) |
| 4376 | { |
| 4377 | /* copy just the sections touched not the entire info |
| 4378 | * since not all sections are valid as returned by |
| 4379 | * update vsi params |
| 4380 | */ |
| 4381 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 4382 | memcpy(&vsi->info.queue_mapping, |
| 4383 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 4384 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 4385 | sizeof(vsi->info.tc_mapping)); |
| 4386 | } |
| 4387 | |
| 4388 | /** |
| 4389 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 4390 | * @vsi: VSI to be configured |
| 4391 | * @enabled_tc: TC bitmap |
| 4392 | * |
| 4393 | * This configures a particular VSI for TCs that are mapped to the |
| 4394 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 4395 | * VSIs to configure TC for a particular VSI. |
| 4396 | * |
| 4397 | * NOTE: |
| 4398 | * It is expected that the VSI queues have been quisced before calling |
| 4399 | * this function. |
| 4400 | **/ |
| 4401 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 4402 | { |
| 4403 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 4404 | struct i40e_vsi_context ctxt; |
| 4405 | int ret = 0; |
| 4406 | int i; |
| 4407 | |
| 4408 | /* Check if enabled_tc is same as existing or new TCs */ |
| 4409 | if (vsi->tc_config.enabled_tc == enabled_tc) |
| 4410 | return ret; |
| 4411 | |
| 4412 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 4413 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4414 | if (enabled_tc & (1 << i)) |
| 4415 | bw_share[i] = 1; |
| 4416 | } |
| 4417 | |
| 4418 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 4419 | if (ret) { |
| 4420 | dev_info(&vsi->back->pdev->dev, |
| 4421 | "Failed configuring TC map %d for VSI %d\n", |
| 4422 | enabled_tc, vsi->seid); |
| 4423 | goto out; |
| 4424 | } |
| 4425 | |
| 4426 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 4427 | ctxt.seid = vsi->seid; |
| 4428 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 4429 | ctxt.vf_num = 0; |
| 4430 | ctxt.uplink_seid = vsi->uplink_seid; |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 4431 | ctxt.info = vsi->info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4432 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 4433 | |
| 4434 | /* Update the VSI after updating the VSI queue-mapping information */ |
| 4435 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 4436 | if (ret) { |
| 4437 | dev_info(&vsi->back->pdev->dev, |
| 4438 | "update vsi failed, aq_err=%d\n", |
| 4439 | vsi->back->hw.aq.asq_last_status); |
| 4440 | goto out; |
| 4441 | } |
| 4442 | /* update the local VSI info with updated queue map */ |
| 4443 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 4444 | vsi->info.valid_sections = 0; |
| 4445 | |
| 4446 | /* Update current VSI BW information */ |
| 4447 | ret = i40e_vsi_get_bw_info(vsi); |
| 4448 | if (ret) { |
| 4449 | dev_info(&vsi->back->pdev->dev, |
| 4450 | "Failed updating vsi bw info, aq_err=%d\n", |
| 4451 | vsi->back->hw.aq.asq_last_status); |
| 4452 | goto out; |
| 4453 | } |
| 4454 | |
| 4455 | /* Update the netdev TC setup */ |
| 4456 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 4457 | out: |
| 4458 | return ret; |
| 4459 | } |
| 4460 | |
| 4461 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4462 | * i40e_veb_config_tc - Configure TCs for given VEB |
| 4463 | * @veb: given VEB |
| 4464 | * @enabled_tc: TC bitmap |
| 4465 | * |
| 4466 | * Configures given TC bitmap for VEB (switching) element |
| 4467 | **/ |
| 4468 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) |
| 4469 | { |
| 4470 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; |
| 4471 | struct i40e_pf *pf = veb->pf; |
| 4472 | int ret = 0; |
| 4473 | int i; |
| 4474 | |
| 4475 | /* No TCs or already enabled TCs just return */ |
| 4476 | if (!enabled_tc || veb->enabled_tc == enabled_tc) |
| 4477 | return ret; |
| 4478 | |
| 4479 | bw_data.tc_valid_bits = enabled_tc; |
| 4480 | /* bw_data.absolute_credits is not set (relative) */ |
| 4481 | |
| 4482 | /* Enable ETS TCs with equal BW Share for now */ |
| 4483 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4484 | if (enabled_tc & (1 << i)) |
| 4485 | bw_data.tc_bw_share_credits[i] = 1; |
| 4486 | } |
| 4487 | |
| 4488 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, |
| 4489 | &bw_data, NULL); |
| 4490 | if (ret) { |
| 4491 | dev_info(&pf->pdev->dev, |
| 4492 | "veb bw config failed, aq_err=%d\n", |
| 4493 | pf->hw.aq.asq_last_status); |
| 4494 | goto out; |
| 4495 | } |
| 4496 | |
| 4497 | /* Update the BW information */ |
| 4498 | ret = i40e_veb_get_bw_info(veb); |
| 4499 | if (ret) { |
| 4500 | dev_info(&pf->pdev->dev, |
| 4501 | "Failed getting veb bw config, aq_err=%d\n", |
| 4502 | pf->hw.aq.asq_last_status); |
| 4503 | } |
| 4504 | |
| 4505 | out: |
| 4506 | return ret; |
| 4507 | } |
| 4508 | |
| 4509 | #ifdef CONFIG_I40E_DCB |
| 4510 | /** |
| 4511 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs |
| 4512 | * @pf: PF struct |
| 4513 | * |
| 4514 | * Reconfigure VEB/VSIs on a given PF; it is assumed that |
| 4515 | * the caller would've quiesce all the VSIs before calling |
| 4516 | * this function |
| 4517 | **/ |
| 4518 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) |
| 4519 | { |
| 4520 | u8 tc_map = 0; |
| 4521 | int ret; |
| 4522 | u8 v; |
| 4523 | |
| 4524 | /* Enable the TCs available on PF to all VEBs */ |
| 4525 | tc_map = i40e_pf_get_tc_map(pf); |
| 4526 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 4527 | if (!pf->veb[v]) |
| 4528 | continue; |
| 4529 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); |
| 4530 | if (ret) { |
| 4531 | dev_info(&pf->pdev->dev, |
| 4532 | "Failed configuring TC for VEB seid=%d\n", |
| 4533 | pf->veb[v]->seid); |
| 4534 | /* Will try to configure as many components */ |
| 4535 | } |
| 4536 | } |
| 4537 | |
| 4538 | /* Update each VSI */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 4539 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4540 | if (!pf->vsi[v]) |
| 4541 | continue; |
| 4542 | |
| 4543 | /* - Enable all TCs for the LAN VSI |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4544 | #ifdef I40E_FCOE |
| 4545 | * - For FCoE VSI only enable the TC configured |
| 4546 | * as per the APP TLV |
| 4547 | #endif |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4548 | * - For all others keep them at TC0 for now |
| 4549 | */ |
| 4550 | if (v == pf->lan_vsi) |
| 4551 | tc_map = i40e_pf_get_tc_map(pf); |
| 4552 | else |
| 4553 | tc_map = i40e_pf_get_default_tc(pf); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4554 | #ifdef I40E_FCOE |
| 4555 | if (pf->vsi[v]->type == I40E_VSI_FCOE) |
| 4556 | tc_map = i40e_get_fcoe_tc_map(pf); |
| 4557 | #endif /* #ifdef I40E_FCOE */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4558 | |
| 4559 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); |
| 4560 | if (ret) { |
| 4561 | dev_info(&pf->pdev->dev, |
| 4562 | "Failed configuring TC for VSI seid=%d\n", |
| 4563 | pf->vsi[v]->seid); |
| 4564 | /* Will try to configure as many components */ |
| 4565 | } else { |
Neerav Parikh | 0672a09 | 2014-04-01 07:11:47 +0000 | [diff] [blame] | 4566 | /* Re-configure VSI vectors based on updated TC map */ |
| 4567 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4568 | if (pf->vsi[v]->netdev) |
| 4569 | i40e_dcbnl_set_all(pf->vsi[v]); |
| 4570 | } |
| 4571 | } |
| 4572 | } |
| 4573 | |
| 4574 | /** |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 4575 | * i40e_resume_port_tx - Resume port Tx |
| 4576 | * @pf: PF struct |
| 4577 | * |
| 4578 | * Resume a port's Tx and issue a PF reset in case of failure to |
| 4579 | * resume. |
| 4580 | **/ |
| 4581 | static int i40e_resume_port_tx(struct i40e_pf *pf) |
| 4582 | { |
| 4583 | struct i40e_hw *hw = &pf->hw; |
| 4584 | int ret; |
| 4585 | |
| 4586 | ret = i40e_aq_resume_port_tx(hw, NULL); |
| 4587 | if (ret) { |
| 4588 | dev_info(&pf->pdev->dev, |
| 4589 | "AQ command Resume Port Tx failed = %d\n", |
| 4590 | pf->hw.aq.asq_last_status); |
| 4591 | /* Schedule PF reset to recover */ |
| 4592 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 4593 | i40e_service_event_schedule(pf); |
| 4594 | } |
| 4595 | |
| 4596 | return ret; |
| 4597 | } |
| 4598 | |
| 4599 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4600 | * i40e_init_pf_dcb - Initialize DCB configuration |
| 4601 | * @pf: PF being configured |
| 4602 | * |
| 4603 | * Query the current DCB configuration and cache it |
| 4604 | * in the hardware structure |
| 4605 | **/ |
| 4606 | static int i40e_init_pf_dcb(struct i40e_pf *pf) |
| 4607 | { |
| 4608 | struct i40e_hw *hw = &pf->hw; |
| 4609 | int err = 0; |
| 4610 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 4611 | /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */ |
| 4612 | if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) || |
| 4613 | (pf->hw.aq.fw_maj_ver < 4)) |
| 4614 | goto out; |
| 4615 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4616 | /* Get the initial DCB configuration */ |
| 4617 | err = i40e_init_dcb(hw); |
| 4618 | if (!err) { |
| 4619 | /* Device/Function is not DCBX capable */ |
| 4620 | if ((!hw->func_caps.dcb) || |
| 4621 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { |
| 4622 | dev_info(&pf->pdev->dev, |
| 4623 | "DCBX offload is not supported or is disabled for this PF.\n"); |
| 4624 | |
| 4625 | if (pf->flags & I40E_FLAG_MFP_ENABLED) |
| 4626 | goto out; |
| 4627 | |
| 4628 | } else { |
| 4629 | /* When status is not DISABLED then DCBX in FW */ |
| 4630 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | |
| 4631 | DCB_CAP_DCBX_VER_IEEE; |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 4632 | |
| 4633 | pf->flags |= I40E_FLAG_DCB_CAPABLE; |
| 4634 | /* Enable DCB tagging only when more than one TC */ |
| 4635 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
| 4636 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 4637 | dev_dbg(&pf->pdev->dev, |
| 4638 | "DCBX offload is supported for this PF.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4639 | } |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 4640 | } else { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 4641 | dev_info(&pf->pdev->dev, |
| 4642 | "AQ Querying DCB configuration failed: aq_err %d\n", |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 4643 | pf->hw.aq.asq_last_status); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4644 | } |
| 4645 | |
| 4646 | out: |
| 4647 | return err; |
| 4648 | } |
| 4649 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 4650 | #define SPEED_SIZE 14 |
| 4651 | #define FC_SIZE 8 |
| 4652 | /** |
| 4653 | * i40e_print_link_message - print link up or down |
| 4654 | * @vsi: the VSI for which link needs a message |
| 4655 | */ |
| 4656 | static void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
| 4657 | { |
| 4658 | char speed[SPEED_SIZE] = "Unknown"; |
| 4659 | char fc[FC_SIZE] = "RX/TX"; |
| 4660 | |
| 4661 | if (!isup) { |
| 4662 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| 4663 | return; |
| 4664 | } |
| 4665 | |
Greg Rose | 148c2d8 | 2014-12-11 07:06:27 +0000 | [diff] [blame] | 4666 | /* Warn user if link speed on NPAR enabled partition is not at |
| 4667 | * least 10GB |
| 4668 | */ |
| 4669 | if (vsi->back->hw.func_caps.npar_enable && |
| 4670 | (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB || |
| 4671 | vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB)) |
| 4672 | netdev_warn(vsi->netdev, |
| 4673 | "The partition detected link speed that is less than 10Gbps\n"); |
| 4674 | |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 4675 | switch (vsi->back->hw.phy.link_info.link_speed) { |
| 4676 | case I40E_LINK_SPEED_40GB: |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 4677 | strlcpy(speed, "40 Gbps", SPEED_SIZE); |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 4678 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 4679 | case I40E_LINK_SPEED_20GB: |
| 4680 | strncpy(speed, "20 Gbps", SPEED_SIZE); |
| 4681 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 4682 | case I40E_LINK_SPEED_10GB: |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 4683 | strlcpy(speed, "10 Gbps", SPEED_SIZE); |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 4684 | break; |
| 4685 | case I40E_LINK_SPEED_1GB: |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 4686 | strlcpy(speed, "1000 Mbps", SPEED_SIZE); |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 4687 | break; |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 4688 | case I40E_LINK_SPEED_100MB: |
| 4689 | strncpy(speed, "100 Mbps", SPEED_SIZE); |
| 4690 | break; |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 4691 | default: |
| 4692 | break; |
| 4693 | } |
| 4694 | |
| 4695 | switch (vsi->back->hw.fc.current_mode) { |
| 4696 | case I40E_FC_FULL: |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 4697 | strlcpy(fc, "RX/TX", FC_SIZE); |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 4698 | break; |
| 4699 | case I40E_FC_TX_PAUSE: |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 4700 | strlcpy(fc, "TX", FC_SIZE); |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 4701 | break; |
| 4702 | case I40E_FC_RX_PAUSE: |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 4703 | strlcpy(fc, "RX", FC_SIZE); |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 4704 | break; |
| 4705 | default: |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 4706 | strlcpy(fc, "None", FC_SIZE); |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 4707 | break; |
| 4708 | } |
| 4709 | |
| 4710 | netdev_info(vsi->netdev, "NIC Link is Up %s Full Duplex, Flow Control: %s\n", |
| 4711 | speed, fc); |
| 4712 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4713 | |
| 4714 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4715 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 4716 | * @vsi: the VSI being configured |
| 4717 | **/ |
| 4718 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 4719 | { |
| 4720 | struct i40e_pf *pf = vsi->back; |
| 4721 | int err; |
| 4722 | |
| 4723 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4724 | i40e_vsi_configure_msix(vsi); |
| 4725 | else |
| 4726 | i40e_configure_msi_and_legacy(vsi); |
| 4727 | |
| 4728 | /* start rings */ |
| 4729 | err = i40e_vsi_control_rings(vsi, true); |
| 4730 | if (err) |
| 4731 | return err; |
| 4732 | |
| 4733 | clear_bit(__I40E_DOWN, &vsi->state); |
| 4734 | i40e_napi_enable_all(vsi); |
| 4735 | i40e_vsi_enable_irq(vsi); |
| 4736 | |
| 4737 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 4738 | (vsi->netdev)) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 4739 | i40e_print_link_message(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4740 | netif_tx_start_all_queues(vsi->netdev); |
| 4741 | netif_carrier_on(vsi->netdev); |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 4742 | } else if (vsi->netdev) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 4743 | i40e_print_link_message(vsi, false); |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 4744 | /* need to check for qualified module here*/ |
| 4745 | if ((pf->hw.phy.link_info.link_info & |
| 4746 | I40E_AQ_MEDIA_AVAILABLE) && |
| 4747 | (!(pf->hw.phy.link_info.an_info & |
| 4748 | I40E_AQ_QUALIFIED_MODULE))) |
| 4749 | netdev_err(vsi->netdev, |
| 4750 | "the driver failed to link because an unqualified module was detected."); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4751 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 4752 | |
| 4753 | /* replay FDIR SB filters */ |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 4754 | if (vsi->type == I40E_VSI_FDIR) { |
| 4755 | /* reset fd counters */ |
| 4756 | pf->fd_add_err = pf->fd_atr_cnt = 0; |
| 4757 | if (pf->fd_tcp_rule > 0) { |
| 4758 | pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 4759 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 4760 | 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] | 4761 | pf->fd_tcp_rule = 0; |
| 4762 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 4763 | i40e_fdir_filter_restore(vsi); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 4764 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4765 | i40e_service_event_schedule(pf); |
| 4766 | |
| 4767 | return 0; |
| 4768 | } |
| 4769 | |
| 4770 | /** |
| 4771 | * i40e_vsi_reinit_locked - Reset the VSI |
| 4772 | * @vsi: the VSI being configured |
| 4773 | * |
| 4774 | * Rebuild the ring structs after some configuration |
| 4775 | * has changed, e.g. MTU size. |
| 4776 | **/ |
| 4777 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 4778 | { |
| 4779 | struct i40e_pf *pf = vsi->back; |
| 4780 | |
| 4781 | WARN_ON(in_interrupt()); |
| 4782 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 4783 | usleep_range(1000, 2000); |
| 4784 | i40e_down(vsi); |
| 4785 | |
| 4786 | /* Give a VF some time to respond to the reset. The |
| 4787 | * two second wait is based upon the watchdog cycle in |
| 4788 | * the VF driver. |
| 4789 | */ |
| 4790 | if (vsi->type == I40E_VSI_SRIOV) |
| 4791 | msleep(2000); |
| 4792 | i40e_up(vsi); |
| 4793 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 4794 | } |
| 4795 | |
| 4796 | /** |
| 4797 | * i40e_up - Bring the connection back up after being down |
| 4798 | * @vsi: the VSI being configured |
| 4799 | **/ |
| 4800 | int i40e_up(struct i40e_vsi *vsi) |
| 4801 | { |
| 4802 | int err; |
| 4803 | |
| 4804 | err = i40e_vsi_configure(vsi); |
| 4805 | if (!err) |
| 4806 | err = i40e_up_complete(vsi); |
| 4807 | |
| 4808 | return err; |
| 4809 | } |
| 4810 | |
| 4811 | /** |
| 4812 | * i40e_down - Shutdown the connection processing |
| 4813 | * @vsi: the VSI being stopped |
| 4814 | **/ |
| 4815 | void i40e_down(struct i40e_vsi *vsi) |
| 4816 | { |
| 4817 | int i; |
| 4818 | |
| 4819 | /* It is assumed that the caller of this function |
| 4820 | * sets the vsi->state __I40E_DOWN bit. |
| 4821 | */ |
| 4822 | if (vsi->netdev) { |
| 4823 | netif_carrier_off(vsi->netdev); |
| 4824 | netif_tx_disable(vsi->netdev); |
| 4825 | } |
| 4826 | i40e_vsi_disable_irq(vsi); |
| 4827 | i40e_vsi_control_rings(vsi, false); |
| 4828 | i40e_napi_disable_all(vsi); |
| 4829 | |
| 4830 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 4831 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
| 4832 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4833 | } |
| 4834 | } |
| 4835 | |
| 4836 | /** |
| 4837 | * i40e_setup_tc - configure multiple traffic classes |
| 4838 | * @netdev: net device to configure |
| 4839 | * @tc: number of traffic classes to enable |
| 4840 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4841 | #ifdef I40E_FCOE |
| 4842 | int i40e_setup_tc(struct net_device *netdev, u8 tc) |
| 4843 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4844 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4845 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4846 | { |
| 4847 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 4848 | struct i40e_vsi *vsi = np->vsi; |
| 4849 | struct i40e_pf *pf = vsi->back; |
| 4850 | u8 enabled_tc = 0; |
| 4851 | int ret = -EINVAL; |
| 4852 | int i; |
| 4853 | |
| 4854 | /* Check if DCB enabled to continue */ |
| 4855 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 4856 | netdev_info(netdev, "DCB is not enabled for adapter\n"); |
| 4857 | goto exit; |
| 4858 | } |
| 4859 | |
| 4860 | /* Check if MFP enabled */ |
| 4861 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 4862 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); |
| 4863 | goto exit; |
| 4864 | } |
| 4865 | |
| 4866 | /* Check whether tc count is within enabled limit */ |
| 4867 | if (tc > i40e_pf_get_num_tc(pf)) { |
| 4868 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); |
| 4869 | goto exit; |
| 4870 | } |
| 4871 | |
| 4872 | /* Generate TC map for number of tc requested */ |
| 4873 | for (i = 0; i < tc; i++) |
| 4874 | enabled_tc |= (1 << i); |
| 4875 | |
| 4876 | /* Requesting same TC configuration as already enabled */ |
| 4877 | if (enabled_tc == vsi->tc_config.enabled_tc) |
| 4878 | return 0; |
| 4879 | |
| 4880 | /* Quiesce VSI queues */ |
| 4881 | i40e_quiesce_vsi(vsi); |
| 4882 | |
| 4883 | /* Configure VSI for enabled TCs */ |
| 4884 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 4885 | if (ret) { |
| 4886 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 4887 | vsi->seid); |
| 4888 | goto exit; |
| 4889 | } |
| 4890 | |
| 4891 | /* Unquiesce VSI */ |
| 4892 | i40e_unquiesce_vsi(vsi); |
| 4893 | |
| 4894 | exit: |
| 4895 | return ret; |
| 4896 | } |
| 4897 | |
| 4898 | /** |
| 4899 | * i40e_open - Called when a network interface is made active |
| 4900 | * @netdev: network interface device structure |
| 4901 | * |
| 4902 | * The open entry point is called when a network interface is made |
| 4903 | * active by the system (IFF_UP). At this point all resources needed |
| 4904 | * for transmit and receive operations are allocated, the interrupt |
| 4905 | * handler is registered with the OS, the netdev watchdog subtask is |
| 4906 | * enabled, and the stack is notified that the interface is ready. |
| 4907 | * |
| 4908 | * Returns 0 on success, negative value on failure |
| 4909 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 4910 | int i40e_open(struct net_device *netdev) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4911 | { |
| 4912 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 4913 | struct i40e_vsi *vsi = np->vsi; |
| 4914 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4915 | int err; |
| 4916 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 4917 | /* disallow open during test or if eeprom is broken */ |
| 4918 | if (test_bit(__I40E_TESTING, &pf->state) || |
| 4919 | test_bit(__I40E_BAD_EEPROM, &pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4920 | return -EBUSY; |
| 4921 | |
| 4922 | netif_carrier_off(netdev); |
| 4923 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 4924 | err = i40e_vsi_open(vsi); |
| 4925 | if (err) |
| 4926 | return err; |
| 4927 | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 4928 | /* configure global TSO hardware offload settings */ |
| 4929 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | |
| 4930 | TCP_FLAG_FIN) >> 16); |
| 4931 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | |
| 4932 | TCP_FLAG_FIN | |
| 4933 | TCP_FLAG_CWR) >> 16); |
| 4934 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); |
| 4935 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 4936 | #ifdef CONFIG_I40E_VXLAN |
| 4937 | vxlan_get_rx_port(netdev); |
| 4938 | #endif |
| 4939 | |
| 4940 | return 0; |
| 4941 | } |
| 4942 | |
| 4943 | /** |
| 4944 | * i40e_vsi_open - |
| 4945 | * @vsi: the VSI to open |
| 4946 | * |
| 4947 | * Finish initialization of the VSI. |
| 4948 | * |
| 4949 | * Returns 0 on success, negative value on failure |
| 4950 | **/ |
| 4951 | int i40e_vsi_open(struct i40e_vsi *vsi) |
| 4952 | { |
| 4953 | struct i40e_pf *pf = vsi->back; |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 4954 | char int_name[I40E_INT_NAME_STR_LEN]; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 4955 | int err; |
| 4956 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4957 | /* allocate descriptors */ |
| 4958 | err = i40e_vsi_setup_tx_resources(vsi); |
| 4959 | if (err) |
| 4960 | goto err_setup_tx; |
| 4961 | err = i40e_vsi_setup_rx_resources(vsi); |
| 4962 | if (err) |
| 4963 | goto err_setup_rx; |
| 4964 | |
| 4965 | err = i40e_vsi_configure(vsi); |
| 4966 | if (err) |
| 4967 | goto err_setup_rx; |
| 4968 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 4969 | if (vsi->netdev) { |
| 4970 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 4971 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); |
| 4972 | err = i40e_vsi_request_irq(vsi, int_name); |
| 4973 | if (err) |
| 4974 | goto err_setup_rx; |
| 4975 | |
| 4976 | /* Notify the stack of the actual queue counts. */ |
| 4977 | err = netif_set_real_num_tx_queues(vsi->netdev, |
| 4978 | vsi->num_queue_pairs); |
| 4979 | if (err) |
| 4980 | goto err_set_queues; |
| 4981 | |
| 4982 | err = netif_set_real_num_rx_queues(vsi->netdev, |
| 4983 | vsi->num_queue_pairs); |
| 4984 | if (err) |
| 4985 | goto err_set_queues; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 4986 | |
| 4987 | } else if (vsi->type == I40E_VSI_FDIR) { |
Carolyn Wyborny | e240f67 | 2014-12-11 07:06:37 +0000 | [diff] [blame] | 4988 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir", |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 4989 | dev_driver_string(&pf->pdev->dev), |
| 4990 | dev_name(&pf->pdev->dev)); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 4991 | err = i40e_vsi_request_irq(vsi, int_name); |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 4992 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 4993 | } else { |
Jean Sacren | ce9ccb1 | 2014-05-01 14:31:18 +0000 | [diff] [blame] | 4994 | err = -EINVAL; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 4995 | goto err_setup_rx; |
| 4996 | } |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 4997 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4998 | err = i40e_up_complete(vsi); |
| 4999 | if (err) |
| 5000 | goto err_up_complete; |
| 5001 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5002 | return 0; |
| 5003 | |
| 5004 | err_up_complete: |
| 5005 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 5006 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5007 | i40e_vsi_free_irq(vsi); |
| 5008 | err_setup_rx: |
| 5009 | i40e_vsi_free_rx_resources(vsi); |
| 5010 | err_setup_tx: |
| 5011 | i40e_vsi_free_tx_resources(vsi); |
| 5012 | if (vsi == pf->vsi[pf->lan_vsi]) |
| 5013 | i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED)); |
| 5014 | |
| 5015 | return err; |
| 5016 | } |
| 5017 | |
| 5018 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5019 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 5020 | * @pf: Pointer to PF |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5021 | * |
| 5022 | * This function destroys the hlist where all the Flow Director |
| 5023 | * filters were saved. |
| 5024 | **/ |
| 5025 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) |
| 5026 | { |
| 5027 | struct i40e_fdir_filter *filter; |
| 5028 | struct hlist_node *node2; |
| 5029 | |
| 5030 | hlist_for_each_entry_safe(filter, node2, |
| 5031 | &pf->fdir_filter_list, fdir_node) { |
| 5032 | hlist_del(&filter->fdir_node); |
| 5033 | kfree(filter); |
| 5034 | } |
| 5035 | pf->fdir_pf_active_filters = 0; |
| 5036 | } |
| 5037 | |
| 5038 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5039 | * i40e_close - Disables a network interface |
| 5040 | * @netdev: network interface device structure |
| 5041 | * |
| 5042 | * The close entry point is called when an interface is de-activated |
| 5043 | * by the OS. The hardware is still under the driver's control, but |
| 5044 | * this netdev interface is disabled. |
| 5045 | * |
| 5046 | * Returns 0, this is not allowed to fail |
| 5047 | **/ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5048 | #ifdef I40E_FCOE |
| 5049 | int i40e_close(struct net_device *netdev) |
| 5050 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5051 | static int i40e_close(struct net_device *netdev) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5052 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5053 | { |
| 5054 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5055 | struct i40e_vsi *vsi = np->vsi; |
| 5056 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 5057 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5058 | |
| 5059 | return 0; |
| 5060 | } |
| 5061 | |
| 5062 | /** |
| 5063 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 5064 | * @pf: board private structure |
| 5065 | * @reset_flags: which reset is requested |
| 5066 | * |
| 5067 | * The essential difference in resets is that the PF Reset |
| 5068 | * doesn't clear the packet buffers, doesn't reset the PE |
| 5069 | * firmware, and doesn't bother the other PFs on the chip. |
| 5070 | **/ |
| 5071 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags) |
| 5072 | { |
| 5073 | u32 val; |
| 5074 | |
| 5075 | WARN_ON(in_interrupt()); |
| 5076 | |
Mitch Williams | 263fc48 | 2014-04-23 04:50:11 +0000 | [diff] [blame] | 5077 | if (i40e_check_asq_alive(&pf->hw)) |
| 5078 | i40e_vc_notify_reset(pf); |
| 5079 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5080 | /* do the biggest reset indicated */ |
| 5081 | if (reset_flags & (1 << __I40E_GLOBAL_RESET_REQUESTED)) { |
| 5082 | |
| 5083 | /* Request a Global Reset |
| 5084 | * |
| 5085 | * This will start the chip's countdown to the actual full |
| 5086 | * chip reset event, and a warning interrupt to be sent |
| 5087 | * to all PFs, including the requestor. Our handler |
| 5088 | * for the warning interrupt will deal with the shutdown |
| 5089 | * and recovery of the switch setup. |
| 5090 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5091 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5092 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5093 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; |
| 5094 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5095 | |
| 5096 | } else if (reset_flags & (1 << __I40E_CORE_RESET_REQUESTED)) { |
| 5097 | |
| 5098 | /* Request a Core Reset |
| 5099 | * |
| 5100 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 5101 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5102 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5103 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 5104 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 5105 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 5106 | i40e_flush(&pf->hw); |
| 5107 | |
| 5108 | } else if (reset_flags & (1 << __I40E_PF_RESET_REQUESTED)) { |
| 5109 | |
| 5110 | /* Request a PF Reset |
| 5111 | * |
| 5112 | * Resets only the PF-specific registers |
| 5113 | * |
| 5114 | * This goes directly to the tear-down and rebuild of |
| 5115 | * the switch, since we need to do all the recovery as |
| 5116 | * for the Core Reset. |
| 5117 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5118 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5119 | i40e_handle_reset_warning(pf); |
| 5120 | |
| 5121 | } else if (reset_flags & (1 << __I40E_REINIT_REQUESTED)) { |
| 5122 | int v; |
| 5123 | |
| 5124 | /* Find the VSI(s) that requested a re-init */ |
| 5125 | dev_info(&pf->pdev->dev, |
| 5126 | "VSI reinit requested\n"); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5127 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5128 | struct i40e_vsi *vsi = pf->vsi[v]; |
| 5129 | if (vsi != NULL && |
| 5130 | test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { |
| 5131 | i40e_vsi_reinit_locked(pf->vsi[v]); |
| 5132 | clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 5133 | } |
| 5134 | } |
| 5135 | |
| 5136 | /* no further action needed, so return now */ |
| 5137 | return; |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5138 | } else if (reset_flags & (1 << __I40E_DOWN_REQUESTED)) { |
| 5139 | int v; |
| 5140 | |
| 5141 | /* Find the VSI(s) that needs to be brought down */ |
| 5142 | dev_info(&pf->pdev->dev, "VSI down requested\n"); |
| 5143 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
| 5144 | struct i40e_vsi *vsi = pf->vsi[v]; |
| 5145 | if (vsi != NULL && |
| 5146 | test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) { |
| 5147 | set_bit(__I40E_DOWN, &vsi->state); |
| 5148 | i40e_down(vsi); |
| 5149 | clear_bit(__I40E_DOWN_REQUESTED, &vsi->state); |
| 5150 | } |
| 5151 | } |
| 5152 | |
| 5153 | /* no further action needed, so return now */ |
| 5154 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5155 | } else { |
| 5156 | dev_info(&pf->pdev->dev, |
| 5157 | "bad reset request 0x%08x\n", reset_flags); |
| 5158 | return; |
| 5159 | } |
| 5160 | } |
| 5161 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5162 | #ifdef CONFIG_I40E_DCB |
| 5163 | /** |
| 5164 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig |
| 5165 | * @pf: board private structure |
| 5166 | * @old_cfg: current DCB config |
| 5167 | * @new_cfg: new DCB config |
| 5168 | **/ |
| 5169 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, |
| 5170 | struct i40e_dcbx_config *old_cfg, |
| 5171 | struct i40e_dcbx_config *new_cfg) |
| 5172 | { |
| 5173 | bool need_reconfig = false; |
| 5174 | |
| 5175 | /* Check if ETS configuration has changed */ |
| 5176 | if (memcmp(&new_cfg->etscfg, |
| 5177 | &old_cfg->etscfg, |
| 5178 | sizeof(new_cfg->etscfg))) { |
| 5179 | /* If Priority Table has changed reconfig is needed */ |
| 5180 | if (memcmp(&new_cfg->etscfg.prioritytable, |
| 5181 | &old_cfg->etscfg.prioritytable, |
| 5182 | sizeof(new_cfg->etscfg.prioritytable))) { |
| 5183 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5184 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5185 | } |
| 5186 | |
| 5187 | if (memcmp(&new_cfg->etscfg.tcbwtable, |
| 5188 | &old_cfg->etscfg.tcbwtable, |
| 5189 | sizeof(new_cfg->etscfg.tcbwtable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5190 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5191 | |
| 5192 | if (memcmp(&new_cfg->etscfg.tsatable, |
| 5193 | &old_cfg->etscfg.tsatable, |
| 5194 | sizeof(new_cfg->etscfg.tsatable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5195 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5196 | } |
| 5197 | |
| 5198 | /* Check if PFC configuration has changed */ |
| 5199 | if (memcmp(&new_cfg->pfc, |
| 5200 | &old_cfg->pfc, |
| 5201 | sizeof(new_cfg->pfc))) { |
| 5202 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5203 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5204 | } |
| 5205 | |
| 5206 | /* Check if APP Table has changed */ |
| 5207 | if (memcmp(&new_cfg->app, |
| 5208 | &old_cfg->app, |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5209 | sizeof(new_cfg->app))) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5210 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5211 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 5212 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5213 | |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5214 | dev_dbg(&pf->pdev->dev, "%s: need_reconfig=%d\n", __func__, |
| 5215 | need_reconfig); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5216 | return need_reconfig; |
| 5217 | } |
| 5218 | |
| 5219 | /** |
| 5220 | * i40e_handle_lldp_event - Handle LLDP Change MIB event |
| 5221 | * @pf: board private structure |
| 5222 | * @e: event info posted on ARQ |
| 5223 | **/ |
| 5224 | static int i40e_handle_lldp_event(struct i40e_pf *pf, |
| 5225 | struct i40e_arq_event_info *e) |
| 5226 | { |
| 5227 | struct i40e_aqc_lldp_get_mib *mib = |
| 5228 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; |
| 5229 | struct i40e_hw *hw = &pf->hw; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5230 | struct i40e_dcbx_config tmp_dcbx_cfg; |
| 5231 | bool need_reconfig = false; |
| 5232 | int ret = 0; |
| 5233 | u8 type; |
| 5234 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5235 | /* Not DCB capable or capability disabled */ |
| 5236 | if (!(pf->flags & I40E_FLAG_DCB_CAPABLE)) |
| 5237 | return ret; |
| 5238 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5239 | /* Ignore if event is not for Nearest Bridge */ |
| 5240 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) |
| 5241 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5242 | dev_dbg(&pf->pdev->dev, |
| 5243 | "%s: LLDP event mib bridge type 0x%x\n", __func__, type); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5244 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
| 5245 | return ret; |
| 5246 | |
| 5247 | /* Check MIB Type and return if event for Remote MIB update */ |
| 5248 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5249 | dev_dbg(&pf->pdev->dev, |
| 5250 | "%s: LLDP event mib type %s\n", __func__, |
| 5251 | type ? "remote" : "local"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5252 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
| 5253 | /* Update the remote cached instance and return */ |
| 5254 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, |
| 5255 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, |
| 5256 | &hw->remote_dcbx_config); |
| 5257 | goto exit; |
| 5258 | } |
| 5259 | |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5260 | /* Store the old configuration */ |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5261 | tmp_dcbx_cfg = hw->local_dcbx_config; |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5262 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5263 | /* Reset the old DCBx configuration data */ |
| 5264 | memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config)); |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5265 | /* Get updated DCBX data from firmware */ |
| 5266 | ret = i40e_get_dcb_config(&pf->hw); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5267 | if (ret) { |
Neerav Parikh | 9fa61dd | 2014-11-12 00:18:25 +0000 | [diff] [blame] | 5268 | dev_info(&pf->pdev->dev, "Failed querying DCB configuration data from firmware.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5269 | goto exit; |
| 5270 | } |
| 5271 | |
| 5272 | /* No change detected in DCBX configs */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5273 | if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config, |
| 5274 | sizeof(tmp_dcbx_cfg))) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5275 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5276 | goto exit; |
| 5277 | } |
| 5278 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5279 | need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg, |
| 5280 | &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5281 | |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5282 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5283 | |
| 5284 | if (!need_reconfig) |
| 5285 | goto exit; |
| 5286 | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5287 | /* Enable DCB tagging only when more than one TC */ |
Neerav Parikh | 750fcbc | 2015-02-24 06:58:47 +0000 | [diff] [blame] | 5288 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 5289 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
| 5290 | else |
| 5291 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 5292 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5293 | set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5294 | /* Reconfiguration needed quiesce all VSIs */ |
| 5295 | i40e_pf_quiesce_all_vsi(pf); |
| 5296 | |
| 5297 | /* Changes in configuration update VEB/VSI */ |
| 5298 | i40e_dcb_reconfigure(pf); |
| 5299 | |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5300 | ret = i40e_resume_port_tx(pf); |
| 5301 | |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5302 | clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5303 | /* In case of error no point in resuming VSIs */ |
Neerav Parikh | 69129dc | 2014-11-12 00:18:46 +0000 | [diff] [blame] | 5304 | if (ret) |
| 5305 | goto exit; |
| 5306 | |
| 5307 | /* Wait for the PF's Tx queues to be disabled */ |
| 5308 | ret = i40e_pf_wait_txq_disabled(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5309 | if (ret) { |
| 5310 | /* Schedule PF reset to recover */ |
| 5311 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5312 | i40e_service_event_schedule(pf); |
| 5313 | } else { |
Neerav Parikh | 2fd75f3 | 2014-11-12 00:18:20 +0000 | [diff] [blame] | 5314 | i40e_pf_unquiesce_all_vsi(pf); |
Parikh, Neerav | 11e4770 | 2015-02-21 06:43:55 +0000 | [diff] [blame] | 5315 | } |
| 5316 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5317 | exit: |
| 5318 | return ret; |
| 5319 | } |
| 5320 | #endif /* CONFIG_I40E_DCB */ |
| 5321 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5322 | /** |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5323 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 5324 | * @pf: board private structure |
| 5325 | * @reset_flags: which reset is requested |
| 5326 | * |
| 5327 | **/ |
| 5328 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 5329 | { |
| 5330 | rtnl_lock(); |
| 5331 | i40e_do_reset(pf, reset_flags); |
| 5332 | rtnl_unlock(); |
| 5333 | } |
| 5334 | |
| 5335 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5336 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 5337 | * @pf: board private structure |
| 5338 | * @e: event info posted on ARQ |
| 5339 | * |
| 5340 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 5341 | * and VF queues |
| 5342 | **/ |
| 5343 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 5344 | struct i40e_arq_event_info *e) |
| 5345 | { |
| 5346 | struct i40e_aqc_lan_overflow *data = |
| 5347 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 5348 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 5349 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 5350 | struct i40e_hw *hw = &pf->hw; |
| 5351 | struct i40e_vf *vf; |
| 5352 | u16 vf_id; |
| 5353 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5354 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 5355 | queue, qtx_ctl); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5356 | |
| 5357 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 5358 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 5359 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 5360 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 5361 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 5362 | vf_id -= hw->func_caps.vf_base_id; |
| 5363 | vf = &pf->vf[vf_id]; |
| 5364 | i40e_vc_notify_vf_reset(vf); |
| 5365 | /* Allow VF to process pending reset notification */ |
| 5366 | msleep(20); |
| 5367 | i40e_reset_vf(vf, false); |
| 5368 | } |
| 5369 | } |
| 5370 | |
| 5371 | /** |
| 5372 | * i40e_service_event_complete - Finish up the service event |
| 5373 | * @pf: board private structure |
| 5374 | **/ |
| 5375 | static void i40e_service_event_complete(struct i40e_pf *pf) |
| 5376 | { |
| 5377 | BUG_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state)); |
| 5378 | |
| 5379 | /* flush memory to make sure state is correct before next watchog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5380 | smp_mb__before_atomic(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5381 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 5382 | } |
| 5383 | |
| 5384 | /** |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5385 | * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters |
| 5386 | * @pf: board private structure |
| 5387 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5388 | u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5389 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5390 | u32 val, fcnt_prog; |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5391 | |
| 5392 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5393 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK); |
| 5394 | return fcnt_prog; |
| 5395 | } |
| 5396 | |
| 5397 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5398 | * 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] | 5399 | * @pf: board private structure |
| 5400 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5401 | u32 i40e_get_current_fd_count(struct i40e_pf *pf) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5402 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5403 | u32 val, fcnt_prog; |
| 5404 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5405 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 5406 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + |
| 5407 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> |
| 5408 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); |
| 5409 | return fcnt_prog; |
| 5410 | } |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5411 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5412 | /** |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5413 | * i40e_get_global_fd_count - Get total FD filters programmed on device |
| 5414 | * @pf: board private structure |
| 5415 | **/ |
| 5416 | u32 i40e_get_global_fd_count(struct i40e_pf *pf) |
| 5417 | { |
| 5418 | u32 val, fcnt_prog; |
| 5419 | |
| 5420 | val = rd32(&pf->hw, I40E_GLQF_FDCNT_0); |
| 5421 | fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) + |
| 5422 | ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >> |
| 5423 | I40E_GLQF_FDCNT_0_BESTCNT_SHIFT); |
| 5424 | return fcnt_prog; |
| 5425 | } |
| 5426 | |
| 5427 | /** |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5428 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled |
| 5429 | * @pf: board private structure |
| 5430 | **/ |
| 5431 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) |
| 5432 | { |
| 5433 | u32 fcnt_prog, fcnt_avail; |
| 5434 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5435 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 5436 | return; |
| 5437 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5438 | /* Check if, FD SB or ATR was auto disabled and if there is enough room |
| 5439 | * to re-enable |
| 5440 | */ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5441 | fcnt_prog = i40e_get_global_fd_count(pf); |
Anjali Singhai Jain | 1295738 | 2014-06-04 04:22:47 +0000 | [diff] [blame] | 5442 | fcnt_avail = pf->fdir_pf_filter_count; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5443 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) || |
| 5444 | (pf->fd_add_err == 0) || |
| 5445 | (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) { |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5446 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 5447 | (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) { |
| 5448 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5449 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5450 | 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] | 5451 | } |
| 5452 | } |
| 5453 | /* Wait for some more space to be available to turn on ATR */ |
| 5454 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) { |
| 5455 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 5456 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) { |
| 5457 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5458 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5459 | 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] | 5460 | } |
| 5461 | } |
| 5462 | } |
| 5463 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5464 | #define I40E_MIN_FD_FLUSH_INTERVAL 10 |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5465 | #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30 |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5466 | /** |
| 5467 | * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB |
| 5468 | * @pf: board private structure |
| 5469 | **/ |
| 5470 | static void i40e_fdir_flush_and_replay(struct i40e_pf *pf) |
| 5471 | { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5472 | unsigned long min_flush_time; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5473 | int flush_wait_retry = 50; |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5474 | bool disable_atr = false; |
| 5475 | int fd_room; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5476 | int reg; |
| 5477 | |
Akeem G Abodunrin | 1790ed0 | 2014-10-17 03:14:41 +0000 | [diff] [blame] | 5478 | if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))) |
| 5479 | return; |
| 5480 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5481 | if (time_after(jiffies, pf->fd_flush_timestamp + |
| 5482 | (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) { |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5483 | /* If the flush is happening too quick and we have mostly |
| 5484 | * SB rules we should not re-enable ATR for some time. |
| 5485 | */ |
| 5486 | min_flush_time = pf->fd_flush_timestamp |
| 5487 | + (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ); |
| 5488 | fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters; |
| 5489 | |
| 5490 | if (!(time_after(jiffies, min_flush_time)) && |
| 5491 | (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) { |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5492 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5493 | dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n"); |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5494 | disable_atr = true; |
| 5495 | } |
| 5496 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5497 | pf->fd_flush_timestamp = jiffies; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5498 | pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
| 5499 | /* flush all filters */ |
| 5500 | wr32(&pf->hw, I40E_PFQF_CTL_1, |
| 5501 | I40E_PFQF_CTL_1_CLEARFDTABLE_MASK); |
| 5502 | i40e_flush(&pf->hw); |
Anjali Singhai Jain | 60793f4 | 2014-07-09 07:46:23 +0000 | [diff] [blame] | 5503 | pf->fd_flush_cnt++; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5504 | pf->fd_add_err = 0; |
| 5505 | do { |
| 5506 | /* Check FD flush status every 5-6msec */ |
| 5507 | usleep_range(5000, 6000); |
| 5508 | reg = rd32(&pf->hw, I40E_PFQF_CTL_1); |
| 5509 | if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK)) |
| 5510 | break; |
| 5511 | } while (flush_wait_retry--); |
| 5512 | if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) { |
| 5513 | dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n"); |
| 5514 | } else { |
| 5515 | /* replay sideband filters */ |
| 5516 | i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]); |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5517 | if (!disable_atr) |
| 5518 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5519 | clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state); |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 5520 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 5521 | dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n"); |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5522 | } |
| 5523 | } |
| 5524 | } |
| 5525 | |
| 5526 | /** |
| 5527 | * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed |
| 5528 | * @pf: board private structure |
| 5529 | **/ |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5530 | u32 i40e_get_current_atr_cnt(struct i40e_pf *pf) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5531 | { |
| 5532 | return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters; |
| 5533 | } |
| 5534 | |
| 5535 | /* We can see up to 256 filter programming desc in transit if the filters are |
| 5536 | * being applied really fast; before we see the first |
| 5537 | * filter miss error on Rx queue 0. Accumulating enough error messages before |
| 5538 | * reacting will make sure we don't cause flush too often. |
| 5539 | */ |
| 5540 | #define I40E_MAX_FD_PROGRAM_ERROR 256 |
| 5541 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5542 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5543 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 5544 | * @pf: board private structure |
| 5545 | **/ |
| 5546 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 5547 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5548 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5549 | /* if interface is down do nothing */ |
| 5550 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 5551 | return; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5552 | |
Akeem G Abodunrin | 1790ed0 | 2014-10-17 03:14:41 +0000 | [diff] [blame] | 5553 | if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))) |
| 5554 | return; |
| 5555 | |
Anjali Singhai Jain | 04294e3 | 2015-02-27 09:15:28 +0000 | [diff] [blame] | 5556 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 5557 | i40e_fdir_flush_and_replay(pf); |
| 5558 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 5559 | i40e_fdir_check_and_reenable(pf); |
| 5560 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5561 | } |
| 5562 | |
| 5563 | /** |
| 5564 | * i40e_vsi_link_event - notify VSI of a link event |
| 5565 | * @vsi: vsi to be notified |
| 5566 | * @link_up: link up or down |
| 5567 | **/ |
| 5568 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 5569 | { |
Jesse Brandeburg | 32b5b81 | 2014-08-12 06:33:14 +0000 | [diff] [blame] | 5570 | if (!vsi || test_bit(__I40E_DOWN, &vsi->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5571 | return; |
| 5572 | |
| 5573 | switch (vsi->type) { |
| 5574 | case I40E_VSI_MAIN: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 5575 | #ifdef I40E_FCOE |
| 5576 | case I40E_VSI_FCOE: |
| 5577 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5578 | if (!vsi->netdev || !vsi->netdev_registered) |
| 5579 | break; |
| 5580 | |
| 5581 | if (link_up) { |
| 5582 | netif_carrier_on(vsi->netdev); |
| 5583 | netif_tx_wake_all_queues(vsi->netdev); |
| 5584 | } else { |
| 5585 | netif_carrier_off(vsi->netdev); |
| 5586 | netif_tx_stop_all_queues(vsi->netdev); |
| 5587 | } |
| 5588 | break; |
| 5589 | |
| 5590 | case I40E_VSI_SRIOV: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5591 | case I40E_VSI_VMDQ2: |
| 5592 | case I40E_VSI_CTRL: |
| 5593 | case I40E_VSI_MIRROR: |
| 5594 | default: |
| 5595 | /* there is no notification for other VSIs */ |
| 5596 | break; |
| 5597 | } |
| 5598 | } |
| 5599 | |
| 5600 | /** |
| 5601 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 5602 | * @veb: veb to be notified |
| 5603 | * @link_up: link up or down |
| 5604 | **/ |
| 5605 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 5606 | { |
| 5607 | struct i40e_pf *pf; |
| 5608 | int i; |
| 5609 | |
| 5610 | if (!veb || !veb->pf) |
| 5611 | return; |
| 5612 | pf = veb->pf; |
| 5613 | |
| 5614 | /* depth first... */ |
| 5615 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 5616 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 5617 | i40e_veb_link_event(pf->veb[i], link_up); |
| 5618 | |
| 5619 | /* ... now the local VSIs */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5620 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5621 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 5622 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 5623 | } |
| 5624 | |
| 5625 | /** |
| 5626 | * i40e_link_event - Update netif_carrier status |
| 5627 | * @pf: board private structure |
| 5628 | **/ |
| 5629 | static void i40e_link_event(struct i40e_pf *pf) |
| 5630 | { |
| 5631 | bool new_link, old_link; |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 5632 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 5633 | u8 new_link_speed, old_link_speed; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5634 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 5635 | /* set this to force the get_link_status call to refresh state */ |
| 5636 | pf->hw.phy.get_link_info = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5637 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 5638 | old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP); |
| 5639 | new_link = i40e_get_link_status(&pf->hw); |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 5640 | old_link_speed = pf->hw.phy.link_info_old.link_speed; |
| 5641 | new_link_speed = pf->hw.phy.link_info.link_speed; |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 5642 | |
| 5643 | if (new_link == old_link && |
Catherine Sullivan | fef59dd | 2014-12-11 07:06:33 +0000 | [diff] [blame] | 5644 | new_link_speed == old_link_speed && |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 5645 | (test_bit(__I40E_DOWN, &vsi->state) || |
| 5646 | new_link == netif_carrier_ok(vsi->netdev))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5647 | return; |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 5648 | |
| 5649 | if (!test_bit(__I40E_DOWN, &vsi->state)) |
| 5650 | i40e_print_link_message(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5651 | |
| 5652 | /* Notify the base of the switch tree connected to |
| 5653 | * the link. Floating VEBs are not notified. |
| 5654 | */ |
| 5655 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 5656 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 5657 | else |
Mitch Williams | 320684c | 2014-10-17 03:14:43 +0000 | [diff] [blame] | 5658 | i40e_vsi_link_event(vsi, new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5659 | |
| 5660 | if (pf->vf) |
| 5661 | i40e_vc_notify_link_state(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 5662 | |
| 5663 | if (pf->flags & I40E_FLAG_PTP) |
| 5664 | i40e_ptp_set_increment(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5665 | } |
| 5666 | |
| 5667 | /** |
| 5668 | * i40e_check_hang_subtask - Check for hung queues and dropped interrupts |
| 5669 | * @pf: board private structure |
| 5670 | * |
| 5671 | * Set the per-queue flags to request a check for stuck queues in the irq |
| 5672 | * clean functions, then force interrupts to be sure the irq clean is called. |
| 5673 | **/ |
| 5674 | static void i40e_check_hang_subtask(struct i40e_pf *pf) |
| 5675 | { |
| 5676 | int i, v; |
| 5677 | |
| 5678 | /* If we're down or resetting, just bail */ |
Akeem G Abodunrin | b67a033 | 2015-02-21 06:42:15 +0000 | [diff] [blame] | 5679 | if (test_bit(__I40E_DOWN, &pf->state) || |
| 5680 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5681 | return; |
| 5682 | |
| 5683 | /* for each VSI/netdev |
| 5684 | * for each Tx queue |
| 5685 | * set the check flag |
| 5686 | * for each q_vector |
| 5687 | * force an interrupt |
| 5688 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5689 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5690 | struct i40e_vsi *vsi = pf->vsi[v]; |
| 5691 | int armed = 0; |
| 5692 | |
| 5693 | if (!pf->vsi[v] || |
| 5694 | test_bit(__I40E_DOWN, &vsi->state) || |
| 5695 | (vsi->netdev && !netif_carrier_ok(vsi->netdev))) |
| 5696 | continue; |
| 5697 | |
| 5698 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5699 | set_check_for_tx_hang(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5700 | if (test_bit(__I40E_HANG_CHECK_ARMED, |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5701 | &vsi->tx_rings[i]->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5702 | armed++; |
| 5703 | } |
| 5704 | |
| 5705 | if (armed) { |
| 5706 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
| 5707 | wr32(&vsi->back->hw, I40E_PFINT_DYN_CTL0, |
| 5708 | (I40E_PFINT_DYN_CTL0_INTENA_MASK | |
Shannon Nelson | 5d1ff106 | 2014-11-11 20:04:35 +0000 | [diff] [blame] | 5709 | I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK | |
| 5710 | I40E_PFINT_DYN_CTL0_ITR_INDX_MASK | |
| 5711 | I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK | |
| 5712 | I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5713 | } else { |
| 5714 | u16 vec = vsi->base_vector - 1; |
| 5715 | u32 val = (I40E_PFINT_DYN_CTLN_INTENA_MASK | |
Shannon Nelson | 5d1ff106 | 2014-11-11 20:04:35 +0000 | [diff] [blame] | 5716 | I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK | |
| 5717 | I40E_PFINT_DYN_CTLN_ITR_INDX_MASK | |
| 5718 | I40E_PFINT_DYN_CTLN_SW_ITR_INDX_ENA_MASK | |
| 5719 | I40E_PFINT_DYN_CTLN_SW_ITR_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5720 | for (i = 0; i < vsi->num_q_vectors; i++, vec++) |
| 5721 | wr32(&vsi->back->hw, |
| 5722 | I40E_PFINT_DYN_CTLN(vec), val); |
| 5723 | } |
| 5724 | i40e_flush(&vsi->back->hw); |
| 5725 | } |
| 5726 | } |
| 5727 | } |
| 5728 | |
| 5729 | /** |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 5730 | * i40e_watchdog_subtask - periodic checks not using event driven response |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5731 | * @pf: board private structure |
| 5732 | **/ |
| 5733 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 5734 | { |
| 5735 | int i; |
| 5736 | |
| 5737 | /* if interface is down do nothing */ |
| 5738 | if (test_bit(__I40E_DOWN, &pf->state) || |
| 5739 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 5740 | return; |
| 5741 | |
Shannon Nelson | 2153671 | 2014-10-25 10:35:25 +0000 | [diff] [blame] | 5742 | /* make sure we don't do these things too often */ |
| 5743 | if (time_before(jiffies, (pf->service_timer_previous + |
| 5744 | pf->service_timer_period))) |
| 5745 | return; |
| 5746 | pf->service_timer_previous = jiffies; |
| 5747 | |
| 5748 | i40e_check_hang_subtask(pf); |
| 5749 | i40e_link_event(pf); |
| 5750 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5751 | /* Update the stats for active netdevs so the network stack |
| 5752 | * can look at updated numbers whenever it cares to |
| 5753 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 5754 | for (i = 0; i < pf->num_alloc_vsi; i++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5755 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 5756 | i40e_update_stats(pf->vsi[i]); |
| 5757 | |
| 5758 | /* Update the stats for the active switching components */ |
| 5759 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 5760 | if (pf->veb[i]) |
| 5761 | i40e_update_veb_stats(pf->veb[i]); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 5762 | |
| 5763 | i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5764 | } |
| 5765 | |
| 5766 | /** |
| 5767 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 5768 | * @pf: board private structure |
| 5769 | **/ |
| 5770 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 5771 | { |
| 5772 | u32 reset_flags = 0; |
| 5773 | |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5774 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5775 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { |
| 5776 | reset_flags |= (1 << __I40E_REINIT_REQUESTED); |
| 5777 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 5778 | } |
| 5779 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { |
| 5780 | reset_flags |= (1 << __I40E_PF_RESET_REQUESTED); |
| 5781 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5782 | } |
| 5783 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { |
| 5784 | reset_flags |= (1 << __I40E_CORE_RESET_REQUESTED); |
| 5785 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 5786 | } |
| 5787 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { |
| 5788 | reset_flags |= (1 << __I40E_GLOBAL_RESET_REQUESTED); |
| 5789 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 5790 | } |
Neerav Parikh | b5d06f0 | 2014-06-03 23:50:17 +0000 | [diff] [blame] | 5791 | if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) { |
| 5792 | reset_flags |= (1 << __I40E_DOWN_REQUESTED); |
| 5793 | clear_bit(__I40E_DOWN_REQUESTED, &pf->state); |
| 5794 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5795 | |
| 5796 | /* If there's a recovery already waiting, it takes |
| 5797 | * precedence before starting a new reset sequence. |
| 5798 | */ |
| 5799 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { |
| 5800 | i40e_handle_reset_warning(pf); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5801 | goto unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5802 | } |
| 5803 | |
| 5804 | /* If we're already down or resetting, just bail */ |
| 5805 | if (reset_flags && |
| 5806 | !test_bit(__I40E_DOWN, &pf->state) && |
| 5807 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 5808 | i40e_do_reset(pf, reset_flags); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5809 | |
| 5810 | unlock: |
| 5811 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5812 | } |
| 5813 | |
| 5814 | /** |
| 5815 | * i40e_handle_link_event - Handle link event |
| 5816 | * @pf: board private structure |
| 5817 | * @e: event info posted on ARQ |
| 5818 | **/ |
| 5819 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 5820 | struct i40e_arq_event_info *e) |
| 5821 | { |
| 5822 | struct i40e_hw *hw = &pf->hw; |
| 5823 | struct i40e_aqc_get_link_status *status = |
| 5824 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5825 | |
| 5826 | /* save off old link status information */ |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 5827 | hw->phy.link_info_old = hw->phy.link_info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5828 | |
Jesse Brandeburg | 1e701e0 | 2014-09-13 07:40:42 +0000 | [diff] [blame] | 5829 | /* Do a new status request to re-enable LSE reporting |
| 5830 | * and load new status information into the hw struct |
| 5831 | * This completely ignores any state information |
| 5832 | * in the ARQ event info, instead choosing to always |
| 5833 | * issue the AQ update link status command. |
| 5834 | */ |
| 5835 | i40e_link_event(pf); |
| 5836 | |
Carolyn Wyborny | 7b592f6 | 2014-07-10 07:58:19 +0000 | [diff] [blame] | 5837 | /* check for unqualified module, if link is down */ |
| 5838 | if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && |
| 5839 | (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && |
| 5840 | (!(status->link_info & I40E_AQ_LINK_UP))) |
| 5841 | dev_err(&pf->pdev->dev, |
| 5842 | "The driver failed to link because an unqualified module was detected.\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5843 | } |
| 5844 | |
| 5845 | /** |
| 5846 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 5847 | * @pf: board private structure |
| 5848 | **/ |
| 5849 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 5850 | { |
| 5851 | struct i40e_arq_event_info event; |
| 5852 | struct i40e_hw *hw = &pf->hw; |
| 5853 | u16 pending, i = 0; |
| 5854 | i40e_status ret; |
| 5855 | u16 opcode; |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 5856 | u32 oldval; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5857 | u32 val; |
| 5858 | |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 5859 | /* Do not run clean AQ when PF reset fails */ |
| 5860 | if (test_bit(__I40E_RESET_FAILED, &pf->state)) |
| 5861 | return; |
| 5862 | |
Shannon Nelson | 86df242 | 2014-05-20 08:01:35 +0000 | [diff] [blame] | 5863 | /* check for error indications */ |
| 5864 | val = rd32(&pf->hw, pf->hw.aq.arq.len); |
| 5865 | oldval = val; |
| 5866 | if (val & I40E_PF_ARQLEN_ARQVFE_MASK) { |
| 5867 | dev_info(&pf->pdev->dev, "ARQ VF Error detected\n"); |
| 5868 | val &= ~I40E_PF_ARQLEN_ARQVFE_MASK; |
| 5869 | } |
| 5870 | if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) { |
| 5871 | dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n"); |
| 5872 | val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK; |
| 5873 | } |
| 5874 | if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) { |
| 5875 | dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n"); |
| 5876 | val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK; |
| 5877 | } |
| 5878 | if (oldval != val) |
| 5879 | wr32(&pf->hw, pf->hw.aq.arq.len, val); |
| 5880 | |
| 5881 | val = rd32(&pf->hw, pf->hw.aq.asq.len); |
| 5882 | oldval = val; |
| 5883 | if (val & I40E_PF_ATQLEN_ATQVFE_MASK) { |
| 5884 | dev_info(&pf->pdev->dev, "ASQ VF Error detected\n"); |
| 5885 | val &= ~I40E_PF_ATQLEN_ATQVFE_MASK; |
| 5886 | } |
| 5887 | if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) { |
| 5888 | dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n"); |
| 5889 | val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK; |
| 5890 | } |
| 5891 | if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) { |
| 5892 | dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n"); |
| 5893 | val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK; |
| 5894 | } |
| 5895 | if (oldval != val) |
| 5896 | wr32(&pf->hw, pf->hw.aq.asq.len, val); |
| 5897 | |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 5898 | event.buf_len = I40E_MAX_AQ_BUF_SIZE; |
| 5899 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5900 | if (!event.msg_buf) |
| 5901 | return; |
| 5902 | |
| 5903 | do { |
| 5904 | ret = i40e_clean_arq_element(hw, &event, &pending); |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 5905 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5906 | break; |
Mitch Williams | 5649797 | 2014-06-04 08:45:18 +0000 | [diff] [blame] | 5907 | else if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5908 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 5909 | break; |
| 5910 | } |
| 5911 | |
| 5912 | opcode = le16_to_cpu(event.desc.opcode); |
| 5913 | switch (opcode) { |
| 5914 | |
| 5915 | case i40e_aqc_opc_get_link_status: |
| 5916 | i40e_handle_link_event(pf, &event); |
| 5917 | break; |
| 5918 | case i40e_aqc_opc_send_msg_to_pf: |
| 5919 | ret = i40e_vc_process_vf_msg(pf, |
| 5920 | le16_to_cpu(event.desc.retval), |
| 5921 | le32_to_cpu(event.desc.cookie_high), |
| 5922 | le32_to_cpu(event.desc.cookie_low), |
| 5923 | event.msg_buf, |
Mitch Williams | 1001dc3 | 2014-11-11 20:02:19 +0000 | [diff] [blame] | 5924 | event.msg_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5925 | break; |
| 5926 | case i40e_aqc_opc_lldp_update_mib: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5927 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5928 | #ifdef CONFIG_I40E_DCB |
| 5929 | rtnl_lock(); |
| 5930 | ret = i40e_handle_lldp_event(pf, &event); |
| 5931 | rtnl_unlock(); |
| 5932 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5933 | break; |
| 5934 | case i40e_aqc_opc_event_lan_overflow: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5935 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5936 | i40e_handle_lan_overflow_event(pf, &event); |
| 5937 | break; |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 5938 | case i40e_aqc_opc_send_msg_to_peer: |
| 5939 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); |
| 5940 | break; |
Shannon Nelson | 91a0f93 | 2015-03-19 14:32:01 -0700 | [diff] [blame] | 5941 | case i40e_aqc_opc_nvm_erase: |
| 5942 | case i40e_aqc_opc_nvm_update: |
| 5943 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, "ARQ NVM operation completed\n"); |
| 5944 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5945 | default: |
| 5946 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 5947 | "ARQ Error: Unknown event 0x%04x received\n", |
| 5948 | opcode); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5949 | break; |
| 5950 | } |
| 5951 | } while (pending && (i++ < pf->adminq_work_limit)); |
| 5952 | |
| 5953 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 5954 | /* re-enable Admin queue interrupt cause */ |
| 5955 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 5956 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 5957 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 5958 | i40e_flush(hw); |
| 5959 | |
| 5960 | kfree(event.msg_buf); |
| 5961 | } |
| 5962 | |
| 5963 | /** |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 5964 | * i40e_verify_eeprom - make sure eeprom is good to use |
| 5965 | * @pf: board private structure |
| 5966 | **/ |
| 5967 | static void i40e_verify_eeprom(struct i40e_pf *pf) |
| 5968 | { |
| 5969 | int err; |
| 5970 | |
| 5971 | err = i40e_diag_eeprom_test(&pf->hw); |
| 5972 | if (err) { |
| 5973 | /* retry in case of garbage read */ |
| 5974 | err = i40e_diag_eeprom_test(&pf->hw); |
| 5975 | if (err) { |
| 5976 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", |
| 5977 | err); |
| 5978 | set_bit(__I40E_BAD_EEPROM, &pf->state); |
| 5979 | } |
| 5980 | } |
| 5981 | |
| 5982 | if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 5983 | dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n"); |
| 5984 | clear_bit(__I40E_BAD_EEPROM, &pf->state); |
| 5985 | } |
| 5986 | } |
| 5987 | |
| 5988 | /** |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 5989 | * i40e_enable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 5990 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 5991 | * |
| 5992 | * enable switch loop back or die - no point in a return value |
| 5993 | **/ |
| 5994 | static void i40e_enable_pf_switch_lb(struct i40e_pf *pf) |
| 5995 | { |
| 5996 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 5997 | struct i40e_vsi_context ctxt; |
| 5998 | int aq_ret; |
| 5999 | |
| 6000 | ctxt.seid = pf->main_vsi_seid; |
| 6001 | ctxt.pf_num = pf->hw.pf_id; |
| 6002 | ctxt.vf_num = 0; |
| 6003 | aq_ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6004 | if (aq_ret) { |
| 6005 | dev_info(&pf->pdev->dev, |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6006 | "%s couldn't get PF vsi config, err %d, aq_err %d\n", |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6007 | __func__, aq_ret, pf->hw.aq.asq_last_status); |
| 6008 | return; |
| 6009 | } |
| 6010 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6011 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6012 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6013 | |
| 6014 | aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6015 | if (aq_ret) { |
| 6016 | dev_info(&pf->pdev->dev, |
| 6017 | "%s: update vsi switch failed, aq_err=%d\n", |
| 6018 | __func__, vsi->back->hw.aq.asq_last_status); |
| 6019 | } |
| 6020 | } |
| 6021 | |
| 6022 | /** |
| 6023 | * i40e_disable_pf_switch_lb |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6024 | * @pf: pointer to the PF structure |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6025 | * |
| 6026 | * disable switch loop back or die - no point in a return value |
| 6027 | **/ |
| 6028 | static void i40e_disable_pf_switch_lb(struct i40e_pf *pf) |
| 6029 | { |
| 6030 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 6031 | struct i40e_vsi_context ctxt; |
| 6032 | int aq_ret; |
| 6033 | |
| 6034 | ctxt.seid = pf->main_vsi_seid; |
| 6035 | ctxt.pf_num = pf->hw.pf_id; |
| 6036 | ctxt.vf_num = 0; |
| 6037 | aq_ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6038 | if (aq_ret) { |
| 6039 | dev_info(&pf->pdev->dev, |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6040 | "%s couldn't get PF vsi config, err %d, aq_err %d\n", |
Akeem G Abodunrin | 386a0af | 2015-02-27 09:15:25 +0000 | [diff] [blame] | 6041 | __func__, aq_ret, pf->hw.aq.asq_last_status); |
| 6042 | return; |
| 6043 | } |
| 6044 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6045 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6046 | ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6047 | |
| 6048 | aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 6049 | if (aq_ret) { |
| 6050 | dev_info(&pf->pdev->dev, |
| 6051 | "%s: update vsi switch failed, aq_err=%d\n", |
| 6052 | __func__, vsi->back->hw.aq.asq_last_status); |
| 6053 | } |
| 6054 | } |
| 6055 | |
| 6056 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6057 | * i40e_config_bridge_mode - Configure the HW bridge mode |
| 6058 | * @veb: pointer to the bridge instance |
| 6059 | * |
| 6060 | * Configure the loop back mode for the LAN VSI that is downlink to the |
| 6061 | * specified HW bridge instance. It is expected this function is called |
| 6062 | * when a new HW bridge is instantiated. |
| 6063 | **/ |
| 6064 | static void i40e_config_bridge_mode(struct i40e_veb *veb) |
| 6065 | { |
| 6066 | struct i40e_pf *pf = veb->pf; |
| 6067 | |
| 6068 | dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n", |
| 6069 | veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 6070 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) |
| 6071 | i40e_disable_pf_switch_lb(pf); |
| 6072 | else |
| 6073 | i40e_enable_pf_switch_lb(pf); |
| 6074 | } |
| 6075 | |
| 6076 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6077 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 6078 | * @veb: pointer to the VEB instance |
| 6079 | * |
| 6080 | * This is a recursive function that first builds the attached VSIs then |
| 6081 | * recurses in to build the next layer of VEB. We track the connections |
| 6082 | * through our own index numbers because the seid's from the HW could |
| 6083 | * change across the reset. |
| 6084 | **/ |
| 6085 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 6086 | { |
| 6087 | struct i40e_vsi *ctl_vsi = NULL; |
| 6088 | struct i40e_pf *pf = veb->pf; |
| 6089 | int v, veb_idx; |
| 6090 | int ret; |
| 6091 | |
| 6092 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6093 | for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6094 | if (pf->vsi[v] && |
| 6095 | pf->vsi[v]->veb_idx == veb->idx && |
| 6096 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 6097 | ctl_vsi = pf->vsi[v]; |
| 6098 | break; |
| 6099 | } |
| 6100 | } |
| 6101 | if (!ctl_vsi) { |
| 6102 | dev_info(&pf->pdev->dev, |
| 6103 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 6104 | ret = -ENOENT; |
| 6105 | goto end_reconstitute; |
| 6106 | } |
| 6107 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 6108 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 6109 | ret = i40e_add_vsi(ctl_vsi); |
| 6110 | if (ret) { |
| 6111 | dev_info(&pf->pdev->dev, |
| 6112 | "rebuild of owner VSI failed: %d\n", ret); |
| 6113 | goto end_reconstitute; |
| 6114 | } |
| 6115 | i40e_vsi_reset_stats(ctl_vsi); |
| 6116 | |
| 6117 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 6118 | ret = i40e_add_veb(veb, ctl_vsi); |
| 6119 | if (ret) |
| 6120 | goto end_reconstitute; |
| 6121 | |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 6122 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
| 6123 | veb->bridge_mode = BRIDGE_MODE_VEB; |
| 6124 | else |
| 6125 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 6126 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | b64ba08 | 2014-11-13 03:06:15 +0000 | [diff] [blame] | 6127 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6128 | /* create the remaining VSIs attached to this VEB */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6129 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6130 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 6131 | continue; |
| 6132 | |
| 6133 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 6134 | struct i40e_vsi *vsi = pf->vsi[v]; |
| 6135 | vsi->uplink_seid = veb->seid; |
| 6136 | ret = i40e_add_vsi(vsi); |
| 6137 | if (ret) { |
| 6138 | dev_info(&pf->pdev->dev, |
| 6139 | "rebuild of vsi_idx %d failed: %d\n", |
| 6140 | v, ret); |
| 6141 | goto end_reconstitute; |
| 6142 | } |
| 6143 | i40e_vsi_reset_stats(vsi); |
| 6144 | } |
| 6145 | } |
| 6146 | |
| 6147 | /* create any VEBs attached to this VEB - RECURSION */ |
| 6148 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 6149 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 6150 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 6151 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 6152 | if (ret) |
| 6153 | break; |
| 6154 | } |
| 6155 | } |
| 6156 | |
| 6157 | end_reconstitute: |
| 6158 | return ret; |
| 6159 | } |
| 6160 | |
| 6161 | /** |
| 6162 | * i40e_get_capabilities - get info about the HW |
| 6163 | * @pf: the PF struct |
| 6164 | **/ |
| 6165 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 6166 | { |
| 6167 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 6168 | u16 data_size; |
| 6169 | int buf_len; |
| 6170 | int err; |
| 6171 | |
| 6172 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 6173 | do { |
| 6174 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 6175 | if (!cap_buf) |
| 6176 | return -ENOMEM; |
| 6177 | |
| 6178 | /* this loads the data into the hw struct for us */ |
| 6179 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 6180 | &data_size, |
| 6181 | i40e_aqc_opc_list_func_capabilities, |
| 6182 | NULL); |
| 6183 | /* data loaded, buffer no longer needed */ |
| 6184 | kfree(cap_buf); |
| 6185 | |
| 6186 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 6187 | /* retry with a larger buffer */ |
| 6188 | buf_len = data_size; |
| 6189 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 6190 | dev_info(&pf->pdev->dev, |
| 6191 | "capability discovery failed: aq=%d\n", |
| 6192 | pf->hw.aq.asq_last_status); |
| 6193 | return -ENODEV; |
| 6194 | } |
| 6195 | } while (err); |
| 6196 | |
Anjali Singhai Jain | ac71b7b | 2014-02-06 05:51:08 +0000 | [diff] [blame] | 6197 | if (((pf->hw.aq.fw_maj_ver == 2) && (pf->hw.aq.fw_min_ver < 22)) || |
| 6198 | (pf->hw.aq.fw_maj_ver < 2)) { |
| 6199 | pf->hw.func_caps.num_msix_vectors++; |
| 6200 | pf->hw.func_caps.num_msix_vectors_vf++; |
| 6201 | } |
| 6202 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6203 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 6204 | dev_info(&pf->pdev->dev, |
| 6205 | "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", |
| 6206 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 6207 | pf->hw.func_caps.num_msix_vectors, |
| 6208 | pf->hw.func_caps.num_msix_vectors_vf, |
| 6209 | pf->hw.func_caps.fd_filters_guaranteed, |
| 6210 | pf->hw.func_caps.fd_filters_best_effort, |
| 6211 | pf->hw.func_caps.num_tx_qp, |
| 6212 | pf->hw.func_caps.num_vsis); |
| 6213 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 6214 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 6215 | + pf->hw.func_caps.num_vfs) |
| 6216 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 6217 | dev_info(&pf->pdev->dev, |
| 6218 | "got num_vsis %d, setting num_vsis to %d\n", |
| 6219 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 6220 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 6221 | } |
| 6222 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6223 | return 0; |
| 6224 | } |
| 6225 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6226 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
| 6227 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6228 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6229 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6230 | * @pf: board private structure |
| 6231 | **/ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6232 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6233 | { |
| 6234 | struct i40e_vsi *vsi; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6235 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6236 | |
Jesse Brandeburg | 407e063 | 2014-06-03 23:50:12 +0000 | [diff] [blame] | 6237 | /* quick workaround for an NVM issue that leaves a critical register |
| 6238 | * uninitialized |
| 6239 | */ |
| 6240 | if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) { |
| 6241 | static const u32 hkey[] = { |
| 6242 | 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36, |
| 6243 | 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb, |
| 6244 | 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21, |
| 6245 | 0x95b3a76d}; |
| 6246 | |
| 6247 | for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++) |
| 6248 | wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]); |
| 6249 | } |
| 6250 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6251 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6252 | return; |
| 6253 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6254 | /* find existing VSI and see if it needs configuring */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6255 | vsi = NULL; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6256 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6257 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6258 | vsi = pf->vsi[i]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6259 | break; |
| 6260 | } |
| 6261 | } |
| 6262 | |
| 6263 | /* create a new VSI if none exists */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6264 | if (!vsi) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6265 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
| 6266 | pf->vsi[pf->lan_vsi]->seid, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6267 | if (!vsi) { |
| 6268 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6269 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 6270 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6271 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6272 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 6273 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6274 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6275 | } |
| 6276 | |
| 6277 | /** |
| 6278 | * i40e_fdir_teardown - release the Flow Director resources |
| 6279 | * @pf: board private structure |
| 6280 | **/ |
| 6281 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 6282 | { |
| 6283 | int i; |
| 6284 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 6285 | i40e_fdir_filter_exit(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6286 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6287 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 6288 | i40e_vsi_release(pf->vsi[i]); |
| 6289 | break; |
| 6290 | } |
| 6291 | } |
| 6292 | } |
| 6293 | |
| 6294 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6295 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6296 | * @pf: board private structure |
| 6297 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6298 | * 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] | 6299 | **/ |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6300 | static void i40e_prep_for_reset(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6301 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6302 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6303 | i40e_status ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6304 | u32 v; |
| 6305 | |
| 6306 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 6307 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6308 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6309 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6310 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6311 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6312 | /* quiesce the VSIs and their queues that are not already DOWN */ |
| 6313 | i40e_pf_quiesce_all_vsi(pf); |
| 6314 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6315 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6316 | if (pf->vsi[v]) |
| 6317 | pf->vsi[v]->seid = 0; |
| 6318 | } |
| 6319 | |
| 6320 | i40e_shutdown_adminq(&pf->hw); |
| 6321 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6322 | /* call shutdown HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6323 | if (hw->hmc.hmc_obj) { |
| 6324 | ret = i40e_shutdown_lan_hmc(hw); |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6325 | if (ret) |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 6326 | dev_warn(&pf->pdev->dev, |
| 6327 | "shutdown_lan_hmc failed: %d\n", ret); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6328 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6329 | } |
| 6330 | |
| 6331 | /** |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6332 | * i40e_send_version - update firmware with driver version |
| 6333 | * @pf: PF struct |
| 6334 | */ |
| 6335 | static void i40e_send_version(struct i40e_pf *pf) |
| 6336 | { |
| 6337 | struct i40e_driver_version dv; |
| 6338 | |
| 6339 | dv.major_version = DRV_VERSION_MAJOR; |
| 6340 | dv.minor_version = DRV_VERSION_MINOR; |
| 6341 | dv.build_version = DRV_VERSION_BUILD; |
| 6342 | dv.subbuild_version = 0; |
Rickard Strandqvist | 35a7d80 | 2014-07-29 09:26:25 +0000 | [diff] [blame] | 6343 | strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6344 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 6345 | } |
| 6346 | |
| 6347 | /** |
Jesse Brandeburg | 4dda12e | 2013-12-18 13:46:01 +0000 | [diff] [blame] | 6348 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6349 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6350 | * @reinit: if the Main VSI needs to re-initialized. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6351 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6352 | 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] | 6353 | { |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6354 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6355 | u8 set_fc_aq_fail = 0; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6356 | i40e_status ret; |
| 6357 | u32 v; |
| 6358 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6359 | /* Now we wait for GRST to settle out. |
| 6360 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 6361 | * because the reset will make them disappear. |
| 6362 | */ |
| 6363 | ret = i40e_pf_reset(hw); |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6364 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6365 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6366 | set_bit(__I40E_RESET_FAILED, &pf->state); |
| 6367 | goto clear_recovery; |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 6368 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6369 | pf->pfr_count++; |
| 6370 | |
| 6371 | if (test_bit(__I40E_DOWN, &pf->state)) |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6372 | goto clear_recovery; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6373 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6374 | |
| 6375 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 6376 | ret = i40e_init_adminq(&pf->hw); |
| 6377 | if (ret) { |
| 6378 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, %d\n", ret); |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6379 | goto clear_recovery; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6380 | } |
| 6381 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6382 | /* re-verify the eeprom if we just had an EMP reset */ |
Anjali Singhai Jain | 9df42d1 | 2015-01-24 09:58:40 +0000 | [diff] [blame] | 6383 | if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state)) |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6384 | i40e_verify_eeprom(pf); |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 6385 | |
Shannon Nelson | e78ac4bf | 2014-05-10 04:49:09 +0000 | [diff] [blame] | 6386 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6387 | ret = i40e_get_capabilities(pf); |
| 6388 | if (ret) { |
| 6389 | dev_info(&pf->pdev->dev, "i40e_get_capabilities failed, %d\n", |
| 6390 | ret); |
| 6391 | goto end_core_reset; |
| 6392 | } |
| 6393 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6394 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 6395 | hw->func_caps.num_rx_qp, |
| 6396 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 6397 | if (ret) { |
| 6398 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 6399 | goto end_core_reset; |
| 6400 | } |
| 6401 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 6402 | if (ret) { |
| 6403 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 6404 | goto end_core_reset; |
| 6405 | } |
| 6406 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6407 | #ifdef CONFIG_I40E_DCB |
| 6408 | ret = i40e_init_pf_dcb(pf); |
| 6409 | if (ret) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 6410 | dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret); |
| 6411 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
| 6412 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6413 | } |
| 6414 | #endif /* CONFIG_I40E_DCB */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6415 | #ifdef I40E_FCOE |
| 6416 | ret = i40e_init_pf_fcoe(pf); |
| 6417 | if (ret) |
| 6418 | dev_info(&pf->pdev->dev, "init_pf_fcoe failed: %d\n", ret); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 6419 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6420 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6421 | /* do basic switch setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6422 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6423 | if (ret) |
| 6424 | goto end_core_reset; |
| 6425 | |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 6426 | /* driver is only interested in link up/down and module qualification |
| 6427 | * reports from firmware |
| 6428 | */ |
| 6429 | ret = i40e_aq_set_phy_int_mask(&pf->hw, |
| 6430 | I40E_AQ_EVENT_LINK_UPDOWN | |
| 6431 | I40E_AQ_EVENT_MODULE_QUAL_FAIL, NULL); |
| 6432 | if (ret) |
| 6433 | dev_info(&pf->pdev->dev, "set phy mask fail, aq_err %d\n", ret); |
| 6434 | |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6435 | /* make sure our flow control settings are restored */ |
| 6436 | ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true); |
| 6437 | if (ret) |
| 6438 | dev_info(&pf->pdev->dev, "set fc fail, aq_err %d\n", ret); |
| 6439 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6440 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 6441 | * They are still in our local switch element arrays, so only |
| 6442 | * need to rebuild the switch model in the HW. |
| 6443 | * |
| 6444 | * If there were VEBs but the reconstitution failed, we'll try |
| 6445 | * try to recover minimal use by getting the basic PF VSI working. |
| 6446 | */ |
| 6447 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 6448 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6449 | /* find the one VEB connected to the MAC, and find orphans */ |
| 6450 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 6451 | if (!pf->veb[v]) |
| 6452 | continue; |
| 6453 | |
| 6454 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 6455 | pf->veb[v]->uplink_seid == 0) { |
| 6456 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 6457 | |
| 6458 | if (!ret) |
| 6459 | continue; |
| 6460 | |
| 6461 | /* If Main VEB failed, we're in deep doodoo, |
| 6462 | * so give up rebuilding the switch and set up |
| 6463 | * for minimal rebuild of PF VSI. |
| 6464 | * If orphan failed, we'll report the error |
| 6465 | * but try to keep going. |
| 6466 | */ |
| 6467 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 6468 | dev_info(&pf->pdev->dev, |
| 6469 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 6470 | ret); |
| 6471 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 6472 | = pf->mac_seid; |
| 6473 | break; |
| 6474 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 6475 | dev_info(&pf->pdev->dev, |
| 6476 | "rebuild of orphan VEB failed: %d\n", |
| 6477 | ret); |
| 6478 | } |
| 6479 | } |
| 6480 | } |
| 6481 | } |
| 6482 | |
| 6483 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
Shannon Nelson | cde4cbc | 2014-06-04 01:23:17 +0000 | [diff] [blame] | 6484 | dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6485 | /* no VEB, so rebuild only the Main VSI */ |
| 6486 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 6487 | if (ret) { |
| 6488 | dev_info(&pf->pdev->dev, |
| 6489 | "rebuild of Main VSI failed: %d\n", ret); |
| 6490 | goto end_core_reset; |
| 6491 | } |
| 6492 | } |
| 6493 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 6494 | if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) || |
| 6495 | (pf->hw.aq.fw_maj_ver < 4)) { |
| 6496 | msleep(75); |
| 6497 | ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 6498 | if (ret) |
| 6499 | dev_info(&pf->pdev->dev, "link restart failed, aq_err=%d\n", |
| 6500 | pf->hw.aq.asq_last_status); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 6501 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6502 | /* reinit the misc interrupt */ |
| 6503 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 6504 | ret = i40e_setup_misc_vector(pf); |
| 6505 | |
| 6506 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 6507 | i40e_pf_unquiesce_all_vsi(pf); |
| 6508 | |
Mitch Williams | 69f64b2 | 2014-02-13 03:48:46 -0800 | [diff] [blame] | 6509 | if (pf->num_alloc_vfs) { |
| 6510 | for (v = 0; v < pf->num_alloc_vfs; v++) |
| 6511 | i40e_reset_vf(&pf->vf[v], true); |
| 6512 | } |
| 6513 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6514 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 6515 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6516 | |
| 6517 | end_core_reset: |
Anjali Singhai Jain | a316f65 | 2014-07-12 07:28:25 +0000 | [diff] [blame] | 6518 | clear_bit(__I40E_RESET_FAILED, &pf->state); |
| 6519 | clear_recovery: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6520 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 6521 | } |
| 6522 | |
| 6523 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6524 | * 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] | 6525 | * @pf: board private structure |
| 6526 | * |
| 6527 | * Close up the VFs and other things in prep for a Core Reset, |
| 6528 | * then get ready to rebuild the world. |
| 6529 | **/ |
| 6530 | static void i40e_handle_reset_warning(struct i40e_pf *pf) |
| 6531 | { |
Shannon Nelson | 23cfbe0 | 2014-06-04 01:23:14 +0000 | [diff] [blame] | 6532 | i40e_prep_for_reset(pf); |
| 6533 | i40e_reset_and_rebuild(pf, false); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6534 | } |
| 6535 | |
| 6536 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6537 | * i40e_handle_mdd_event |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6538 | * @pf: pointer to the PF structure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6539 | * |
| 6540 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 6541 | **/ |
| 6542 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 6543 | { |
| 6544 | struct i40e_hw *hw = &pf->hw; |
| 6545 | bool mdd_detected = false; |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 6546 | bool pf_mdd_detected = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6547 | struct i40e_vf *vf; |
| 6548 | u32 reg; |
| 6549 | int i; |
| 6550 | |
| 6551 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) |
| 6552 | return; |
| 6553 | |
| 6554 | /* find what triggered the MDD event */ |
| 6555 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 6556 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6557 | u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> |
| 6558 | I40E_GL_MDET_TX_PF_NUM_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 6559 | u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6560 | I40E_GL_MDET_TX_VF_NUM_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 6561 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6562 | I40E_GL_MDET_TX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 6563 | u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >> |
| 6564 | I40E_GL_MDET_TX_QUEUE_SHIFT) - |
| 6565 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 6566 | if (netif_msg_tx_err(pf)) |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6567 | 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] | 6568 | event, queue, pf_num, vf_num); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6569 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 6570 | mdd_detected = true; |
| 6571 | } |
| 6572 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 6573 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6574 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> |
| 6575 | I40E_GL_MDET_RX_FUNCTION_SHIFT; |
Dan Carpenter | 013f657 | 2014-10-22 20:06:29 -0700 | [diff] [blame] | 6576 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> |
Anjali Singhai Jain | 4c33f83 | 2014-06-05 00:18:21 +0000 | [diff] [blame] | 6577 | I40E_GL_MDET_RX_EVENT_SHIFT; |
Mitch Williams | 2089ad0 | 2014-10-17 03:14:53 +0000 | [diff] [blame] | 6578 | u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >> |
| 6579 | I40E_GL_MDET_RX_QUEUE_SHIFT) - |
| 6580 | pf->hw.func_caps.base_queue; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 6581 | if (netif_msg_rx_err(pf)) |
| 6582 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
| 6583 | event, queue, func); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6584 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 6585 | mdd_detected = true; |
| 6586 | } |
| 6587 | |
Neerav Parikh | df430b1 | 2014-06-04 01:23:15 +0000 | [diff] [blame] | 6588 | if (mdd_detected) { |
| 6589 | reg = rd32(hw, I40E_PF_MDET_TX); |
| 6590 | if (reg & I40E_PF_MDET_TX_VALID_MASK) { |
| 6591 | wr32(hw, I40E_PF_MDET_TX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 6592 | 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] | 6593 | pf_mdd_detected = true; |
| 6594 | } |
| 6595 | reg = rd32(hw, I40E_PF_MDET_RX); |
| 6596 | if (reg & I40E_PF_MDET_RX_VALID_MASK) { |
| 6597 | wr32(hw, I40E_PF_MDET_RX, 0xFFFF); |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 6598 | 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] | 6599 | pf_mdd_detected = true; |
| 6600 | } |
| 6601 | /* Queue belongs to the PF, initiate a reset */ |
| 6602 | if (pf_mdd_detected) { |
| 6603 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 6604 | i40e_service_event_schedule(pf); |
| 6605 | } |
| 6606 | } |
| 6607 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6608 | /* see if one of the VFs needs its hand slapped */ |
| 6609 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 6610 | vf = &(pf->vf[i]); |
| 6611 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 6612 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 6613 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 6614 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 6615 | dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n", |
| 6616 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6617 | } |
| 6618 | |
| 6619 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 6620 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 6621 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 6622 | vf->num_mdd_events++; |
Jesse Brandeburg | faf3297 | 2014-07-12 07:28:21 +0000 | [diff] [blame] | 6623 | dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n", |
| 6624 | i); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6625 | } |
| 6626 | |
| 6627 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 6628 | dev_info(&pf->pdev->dev, |
| 6629 | "Too many MDD events on VF %d, disabled\n", i); |
| 6630 | dev_info(&pf->pdev->dev, |
| 6631 | "Use PF Control I/F to re-enable the VF\n"); |
| 6632 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 6633 | } |
| 6634 | } |
| 6635 | |
| 6636 | /* re-enable mdd interrupt cause */ |
| 6637 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 6638 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 6639 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 6640 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 6641 | i40e_flush(hw); |
| 6642 | } |
| 6643 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 6644 | #ifdef CONFIG_I40E_VXLAN |
| 6645 | /** |
| 6646 | * i40e_sync_vxlan_filters_subtask - Sync the VSI filter list with HW |
| 6647 | * @pf: board private structure |
| 6648 | **/ |
| 6649 | static void i40e_sync_vxlan_filters_subtask(struct i40e_pf *pf) |
| 6650 | { |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 6651 | struct i40e_hw *hw = &pf->hw; |
| 6652 | i40e_status ret; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 6653 | __be16 port; |
| 6654 | int i; |
| 6655 | |
| 6656 | if (!(pf->flags & I40E_FLAG_VXLAN_FILTER_SYNC)) |
| 6657 | return; |
| 6658 | |
| 6659 | pf->flags &= ~I40E_FLAG_VXLAN_FILTER_SYNC; |
| 6660 | |
| 6661 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
| 6662 | if (pf->pending_vxlan_bitmap & (1 << i)) { |
| 6663 | pf->pending_vxlan_bitmap &= ~(1 << i); |
| 6664 | port = pf->vxlan_ports[i]; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 6665 | if (port) |
| 6666 | ret = i40e_aq_add_udp_tunnel(hw, ntohs(port), |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 6667 | I40E_AQC_TUNNEL_TYPE_VXLAN, |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 6668 | NULL, NULL); |
| 6669 | else |
| 6670 | ret = i40e_aq_del_udp_tunnel(hw, i, NULL); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 6671 | |
| 6672 | if (ret) { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 6673 | dev_info(&pf->pdev->dev, |
| 6674 | "%s vxlan port %d, index %d failed, err %d, aq_err %d\n", |
| 6675 | port ? "add" : "delete", |
| 6676 | ntohs(port), i, ret, |
| 6677 | pf->hw.aq.asq_last_status); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 6678 | pf->vxlan_ports[i] = 0; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 6679 | } |
| 6680 | } |
| 6681 | } |
| 6682 | } |
| 6683 | |
| 6684 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6685 | /** |
| 6686 | * i40e_service_task - Run the driver's async subtasks |
| 6687 | * @work: pointer to work_struct containing our data |
| 6688 | **/ |
| 6689 | static void i40e_service_task(struct work_struct *work) |
| 6690 | { |
| 6691 | struct i40e_pf *pf = container_of(work, |
| 6692 | struct i40e_pf, |
| 6693 | service_task); |
| 6694 | unsigned long start_time = jiffies; |
| 6695 | |
Shannon Nelson | e57a2fe | 2014-06-03 23:50:19 +0000 | [diff] [blame] | 6696 | /* don't bother with service tasks if a reset is in progress */ |
| 6697 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 6698 | i40e_service_event_complete(pf); |
| 6699 | return; |
| 6700 | } |
| 6701 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6702 | i40e_reset_subtask(pf); |
| 6703 | i40e_handle_mdd_event(pf); |
| 6704 | i40e_vc_process_vflr_event(pf); |
| 6705 | i40e_watchdog_subtask(pf); |
| 6706 | i40e_fdir_reinit_subtask(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6707 | i40e_sync_filters_subtask(pf); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 6708 | #ifdef CONFIG_I40E_VXLAN |
| 6709 | i40e_sync_vxlan_filters_subtask(pf); |
| 6710 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6711 | i40e_clean_adminq_subtask(pf); |
| 6712 | |
| 6713 | i40e_service_event_complete(pf); |
| 6714 | |
| 6715 | /* If the tasks have taken longer than one timer cycle or there |
| 6716 | * is more work to be done, reschedule the service task now |
| 6717 | * rather than wait for the timer to tick again. |
| 6718 | */ |
| 6719 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
| 6720 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || |
| 6721 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || |
| 6722 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 6723 | i40e_service_event_schedule(pf); |
| 6724 | } |
| 6725 | |
| 6726 | /** |
| 6727 | * i40e_service_timer - timer callback |
| 6728 | * @data: pointer to PF struct |
| 6729 | **/ |
| 6730 | static void i40e_service_timer(unsigned long data) |
| 6731 | { |
| 6732 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 6733 | |
| 6734 | mod_timer(&pf->service_timer, |
| 6735 | round_jiffies(jiffies + pf->service_timer_period)); |
| 6736 | i40e_service_event_schedule(pf); |
| 6737 | } |
| 6738 | |
| 6739 | /** |
| 6740 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 6741 | * @vsi: the VSI being configured |
| 6742 | **/ |
| 6743 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 6744 | { |
| 6745 | struct i40e_pf *pf = vsi->back; |
| 6746 | |
| 6747 | switch (vsi->type) { |
| 6748 | case I40E_VSI_MAIN: |
| 6749 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 6750 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 6751 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 6752 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 6753 | vsi->num_q_vectors = pf->num_lan_msix; |
| 6754 | else |
| 6755 | vsi->num_q_vectors = 1; |
| 6756 | |
| 6757 | break; |
| 6758 | |
| 6759 | case I40E_VSI_FDIR: |
| 6760 | vsi->alloc_queue_pairs = 1; |
| 6761 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 6762 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 6763 | vsi->num_q_vectors = 1; |
| 6764 | break; |
| 6765 | |
| 6766 | case I40E_VSI_VMDQ2: |
| 6767 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 6768 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 6769 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 6770 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 6771 | break; |
| 6772 | |
| 6773 | case I40E_VSI_SRIOV: |
| 6774 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 6775 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 6776 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 6777 | break; |
| 6778 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 6779 | #ifdef I40E_FCOE |
| 6780 | case I40E_VSI_FCOE: |
| 6781 | vsi->alloc_queue_pairs = pf->num_fcoe_qps; |
| 6782 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 6783 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 6784 | vsi->num_q_vectors = pf->num_fcoe_msix; |
| 6785 | break; |
| 6786 | |
| 6787 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6788 | default: |
| 6789 | WARN_ON(1); |
| 6790 | return -ENODATA; |
| 6791 | } |
| 6792 | |
| 6793 | return 0; |
| 6794 | } |
| 6795 | |
| 6796 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6797 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 6798 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6799 | * @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] | 6800 | * |
| 6801 | * On error: returns error code (negative) |
| 6802 | * On success: returns 0 |
| 6803 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6804 | 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] | 6805 | { |
| 6806 | int size; |
| 6807 | int ret = 0; |
| 6808 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 6809 | /* allocate memory for both Tx and Rx ring pointers */ |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6810 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
| 6811 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 6812 | if (!vsi->tx_rings) |
| 6813 | return -ENOMEM; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6814 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
| 6815 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6816 | if (alloc_qvectors) { |
| 6817 | /* allocate memory for q_vector pointers */ |
Julia Lawall | f57e4fb | 2014-07-30 03:11:09 +0000 | [diff] [blame] | 6818 | size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6819 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 6820 | if (!vsi->q_vectors) { |
| 6821 | ret = -ENOMEM; |
| 6822 | goto err_vectors; |
| 6823 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6824 | } |
| 6825 | return ret; |
| 6826 | |
| 6827 | err_vectors: |
| 6828 | kfree(vsi->tx_rings); |
| 6829 | return ret; |
| 6830 | } |
| 6831 | |
| 6832 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6833 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 6834 | * @pf: board private structure |
| 6835 | * @type: type of VSI |
| 6836 | * |
| 6837 | * On error: returns error code (negative) |
| 6838 | * On success: returns vsi index in PF (positive) |
| 6839 | **/ |
| 6840 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 6841 | { |
| 6842 | int ret = -ENODEV; |
| 6843 | struct i40e_vsi *vsi; |
| 6844 | int vsi_idx; |
| 6845 | int i; |
| 6846 | |
| 6847 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 6848 | mutex_lock(&pf->switch_mutex); |
| 6849 | |
| 6850 | /* VSI list may be fragmented if VSI creation/destruction has |
| 6851 | * been happening. We can afford to do a quick scan to look |
| 6852 | * for any free VSIs in the list. |
| 6853 | * |
| 6854 | * find next empty vsi slot, looping back around if necessary |
| 6855 | */ |
| 6856 | i = pf->next_vsi; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6857 | while (i < pf->num_alloc_vsi && pf->vsi[i]) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6858 | i++; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6859 | if (i >= pf->num_alloc_vsi) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6860 | i = 0; |
| 6861 | while (i < pf->next_vsi && pf->vsi[i]) |
| 6862 | i++; |
| 6863 | } |
| 6864 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 6865 | if (i < pf->num_alloc_vsi && !pf->vsi[i]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6866 | vsi_idx = i; /* Found one! */ |
| 6867 | } else { |
| 6868 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 6869 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6870 | } |
| 6871 | pf->next_vsi = ++i; |
| 6872 | |
| 6873 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 6874 | if (!vsi) { |
| 6875 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 6876 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6877 | } |
| 6878 | vsi->type = type; |
| 6879 | vsi->back = pf; |
| 6880 | set_bit(__I40E_DOWN, &vsi->state); |
| 6881 | vsi->flags = 0; |
| 6882 | vsi->idx = vsi_idx; |
| 6883 | vsi->rx_itr_setting = pf->rx_itr_default; |
| 6884 | vsi->tx_itr_setting = pf->tx_itr_default; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 6885 | vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ? |
| 6886 | pf->rss_table_size : 64; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6887 | vsi->netdev_registered = false; |
| 6888 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
| 6889 | INIT_LIST_HEAD(&vsi->mac_filter_list); |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame] | 6890 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6891 | |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 6892 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 6893 | if (ret) |
| 6894 | goto err_rings; |
| 6895 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6896 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6897 | if (ret) |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 6898 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 6899 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6900 | /* Setup default MSIX irq handler for VSI */ |
| 6901 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 6902 | |
| 6903 | pf->vsi[vsi_idx] = vsi; |
| 6904 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 6905 | goto unlock_pf; |
| 6906 | |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 6907 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 6908 | pf->next_vsi = i - 1; |
| 6909 | kfree(vsi); |
| 6910 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6911 | mutex_unlock(&pf->switch_mutex); |
| 6912 | return ret; |
| 6913 | } |
| 6914 | |
| 6915 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6916 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 6917 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6918 | * @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] | 6919 | * |
| 6920 | * On error: returns error code (negative) |
| 6921 | * On success: returns 0 |
| 6922 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6923 | 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] | 6924 | { |
| 6925 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6926 | if (free_qvectors) { |
| 6927 | kfree(vsi->q_vectors); |
| 6928 | vsi->q_vectors = NULL; |
| 6929 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6930 | kfree(vsi->tx_rings); |
| 6931 | vsi->tx_rings = NULL; |
| 6932 | vsi->rx_rings = NULL; |
| 6933 | } |
| 6934 | |
| 6935 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6936 | * i40e_vsi_clear - Deallocate the VSI provided |
| 6937 | * @vsi: the VSI being un-configured |
| 6938 | **/ |
| 6939 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 6940 | { |
| 6941 | struct i40e_pf *pf; |
| 6942 | |
| 6943 | if (!vsi) |
| 6944 | return 0; |
| 6945 | |
| 6946 | if (!vsi->back) |
| 6947 | goto free_vsi; |
| 6948 | pf = vsi->back; |
| 6949 | |
| 6950 | mutex_lock(&pf->switch_mutex); |
| 6951 | if (!pf->vsi[vsi->idx]) { |
| 6952 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 6953 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 6954 | goto unlock_vsi; |
| 6955 | } |
| 6956 | |
| 6957 | if (pf->vsi[vsi->idx] != vsi) { |
| 6958 | dev_err(&pf->pdev->dev, |
| 6959 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 6960 | pf->vsi[vsi->idx]->idx, |
| 6961 | pf->vsi[vsi->idx], |
| 6962 | pf->vsi[vsi->idx]->type, |
| 6963 | vsi->idx, vsi, vsi->type); |
| 6964 | goto unlock_vsi; |
| 6965 | } |
| 6966 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 6967 | /* updates the PF for this cleared vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6968 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 6969 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 6970 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6971 | i40e_vsi_free_arrays(vsi, true); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 6972 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6973 | pf->vsi[vsi->idx] = NULL; |
| 6974 | if (vsi->idx < pf->next_vsi) |
| 6975 | pf->next_vsi = vsi->idx; |
| 6976 | |
| 6977 | unlock_vsi: |
| 6978 | mutex_unlock(&pf->switch_mutex); |
| 6979 | free_vsi: |
| 6980 | kfree(vsi); |
| 6981 | |
| 6982 | return 0; |
| 6983 | } |
| 6984 | |
| 6985 | /** |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 6986 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 6987 | * @vsi: the VSI being cleaned |
| 6988 | **/ |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 6989 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 6990 | { |
| 6991 | int i; |
| 6992 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 6993 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 6994 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 6995 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 6996 | vsi->tx_rings[i] = NULL; |
| 6997 | vsi->rx_rings[i] = NULL; |
| 6998 | } |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 6999 | } |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7000 | } |
| 7001 | |
| 7002 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7003 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 7004 | * @vsi: the VSI being configured |
| 7005 | **/ |
| 7006 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 7007 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 7008 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7009 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7010 | int i; |
| 7011 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7012 | /* Set basic values in the rings to be used later during open() */ |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7013 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7014 | /* allocate space for both Tx and Rx in one shot */ |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7015 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
| 7016 | if (!tx_ring) |
| 7017 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7018 | |
| 7019 | tx_ring->queue_index = i; |
| 7020 | tx_ring->reg_idx = vsi->base_queue + i; |
| 7021 | tx_ring->ring_active = false; |
| 7022 | tx_ring->vsi = vsi; |
| 7023 | tx_ring->netdev = vsi->netdev; |
| 7024 | tx_ring->dev = &pf->pdev->dev; |
| 7025 | tx_ring->count = vsi->num_desc; |
| 7026 | tx_ring->size = 0; |
| 7027 | tx_ring->dcb_tc = 0; |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7028 | vsi->tx_rings[i] = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7029 | |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7030 | rx_ring = &tx_ring[1]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7031 | rx_ring->queue_index = i; |
| 7032 | rx_ring->reg_idx = vsi->base_queue + i; |
| 7033 | rx_ring->ring_active = false; |
| 7034 | rx_ring->vsi = vsi; |
| 7035 | rx_ring->netdev = vsi->netdev; |
| 7036 | rx_ring->dev = &pf->pdev->dev; |
| 7037 | rx_ring->count = vsi->num_desc; |
| 7038 | rx_ring->size = 0; |
| 7039 | rx_ring->dcb_tc = 0; |
| 7040 | if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) |
| 7041 | set_ring_16byte_desc_enabled(rx_ring); |
| 7042 | else |
| 7043 | clear_ring_16byte_desc_enabled(rx_ring); |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7044 | vsi->rx_rings[i] = rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7045 | } |
| 7046 | |
| 7047 | return 0; |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 7048 | |
| 7049 | err_out: |
| 7050 | i40e_vsi_clear_rings(vsi); |
| 7051 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7052 | } |
| 7053 | |
| 7054 | /** |
| 7055 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 7056 | * @pf: board private structure |
| 7057 | * @vectors: the number of MSI-X vectors to request |
| 7058 | * |
| 7059 | * Returns the number of vectors reserved, or error |
| 7060 | **/ |
| 7061 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 7062 | { |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7063 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
| 7064 | I40E_MIN_MSIX, vectors); |
| 7065 | if (vectors < 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7066 | dev_info(&pf->pdev->dev, |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 7067 | "MSI-X vector reservation failed: %d\n", vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7068 | vectors = 0; |
| 7069 | } |
| 7070 | |
| 7071 | return vectors; |
| 7072 | } |
| 7073 | |
| 7074 | /** |
| 7075 | * i40e_init_msix - Setup the MSIX capability |
| 7076 | * @pf: board private structure |
| 7077 | * |
| 7078 | * Work with the OS to set up the MSIX vectors needed. |
| 7079 | * |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7080 | * Returns the number of vectors reserved or negative on failure |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7081 | **/ |
| 7082 | static int i40e_init_msix(struct i40e_pf *pf) |
| 7083 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7084 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7085 | int vectors_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7086 | int v_budget, i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7087 | int v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7088 | |
| 7089 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 7090 | return -ENODEV; |
| 7091 | |
| 7092 | /* The number of vectors we'll request will be comprised of: |
| 7093 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 7094 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7095 | * - Queues being used for RSS. |
| 7096 | * We don't need as many as max_rss_size vectors. |
| 7097 | * use rss_size instead in the calculation since that |
| 7098 | * is governed by number of cpus in the system. |
| 7099 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7100 | * - The number of VMDq pairs |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7101 | #ifdef I40E_FCOE |
| 7102 | * - The number of FCOE qps. |
| 7103 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7104 | * Once we count this up, try the request. |
| 7105 | * |
| 7106 | * If we can't get what we want, we'll simplify to nearly nothing |
| 7107 | * and try again. If that still fails, we punt. |
| 7108 | */ |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7109 | vectors_left = hw->func_caps.num_msix_vectors; |
| 7110 | v_budget = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7111 | |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7112 | /* reserve one vector for miscellaneous handler */ |
| 7113 | if (vectors_left) { |
| 7114 | v_budget++; |
| 7115 | vectors_left--; |
| 7116 | } |
| 7117 | |
| 7118 | /* reserve vectors for the main PF traffic queues */ |
| 7119 | pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left); |
| 7120 | vectors_left -= pf->num_lan_msix; |
| 7121 | v_budget += pf->num_lan_msix; |
| 7122 | |
| 7123 | /* reserve one vector for sideband flow director */ |
| 7124 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7125 | if (vectors_left) { |
| 7126 | v_budget++; |
| 7127 | vectors_left--; |
| 7128 | } else { |
| 7129 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 7130 | } |
| 7131 | } |
John W Linville | 83840e4 | 2015-01-14 03:06:28 +0000 | [diff] [blame] | 7132 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7133 | #ifdef I40E_FCOE |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7134 | /* can we reserve enough for FCoE? */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7135 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7136 | if (!vectors_left) |
| 7137 | pf->num_fcoe_msix = 0; |
| 7138 | else if (vectors_left >= pf->num_fcoe_qps) |
| 7139 | pf->num_fcoe_msix = pf->num_fcoe_qps; |
| 7140 | else |
| 7141 | pf->num_fcoe_msix = 1; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7142 | v_budget += pf->num_fcoe_msix; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7143 | vectors_left -= pf->num_fcoe_msix; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7144 | } |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7145 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7146 | #endif |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7147 | /* any vectors left over go for VMDq support */ |
| 7148 | if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { |
| 7149 | int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; |
| 7150 | int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted); |
| 7151 | |
| 7152 | /* if we're short on vectors for what's desired, we limit |
| 7153 | * the queues per vmdq. If this is still more than are |
| 7154 | * available, the user will need to change the number of |
| 7155 | * queues/vectors used by the PF later with the ethtool |
| 7156 | * channels command |
| 7157 | */ |
| 7158 | if (vmdq_vecs < vmdq_vecs_wanted) |
| 7159 | pf->num_vmdq_qps = 1; |
| 7160 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
| 7161 | |
| 7162 | v_budget += vmdq_vecs; |
| 7163 | vectors_left -= vmdq_vecs; |
| 7164 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7165 | |
| 7166 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 7167 | GFP_KERNEL); |
| 7168 | if (!pf->msix_entries) |
| 7169 | return -ENOMEM; |
| 7170 | |
| 7171 | for (i = 0; i < v_budget; i++) |
| 7172 | pf->msix_entries[i].entry = i; |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7173 | v_actual = i40e_reserve_msix_vectors(pf, v_budget); |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7174 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7175 | if (v_actual != v_budget) { |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7176 | /* If we have limited resources, we will start with no vectors |
| 7177 | * for the special features and then allocate vectors to some |
| 7178 | * of these features based on the policy and at the end disable |
| 7179 | * the features that did not get any vectors. |
| 7180 | */ |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7181 | #ifdef I40E_FCOE |
| 7182 | pf->num_fcoe_qps = 0; |
| 7183 | pf->num_fcoe_msix = 0; |
| 7184 | #endif |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7185 | pf->num_vmdq_msix = 0; |
| 7186 | } |
| 7187 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7188 | if (v_actual < I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7189 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 7190 | kfree(pf->msix_entries); |
| 7191 | pf->msix_entries = NULL; |
| 7192 | return -ENODEV; |
| 7193 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7194 | } else if (v_actual == I40E_MIN_MSIX) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7195 | /* Adjust for minimal MSIX use */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7196 | pf->num_vmdq_vsis = 0; |
| 7197 | pf->num_vmdq_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7198 | pf->num_lan_qps = 1; |
| 7199 | pf->num_lan_msix = 1; |
| 7200 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7201 | } else if (v_actual != v_budget) { |
| 7202 | int vec; |
| 7203 | |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7204 | /* reserve the misc vector */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7205 | vec = v_actual - 1; |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7206 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7207 | /* Scale vector usage down */ |
| 7208 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7209 | pf->num_vmdq_vsis = 1; |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7210 | pf->num_vmdq_qps = 1; |
| 7211 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7212 | |
| 7213 | /* partition out the remaining vectors */ |
| 7214 | switch (vec) { |
| 7215 | case 2: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7216 | pf->num_lan_msix = 1; |
| 7217 | break; |
| 7218 | case 3: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7219 | #ifdef I40E_FCOE |
| 7220 | /* give one vector to FCoE */ |
| 7221 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7222 | pf->num_lan_msix = 1; |
| 7223 | pf->num_fcoe_msix = 1; |
| 7224 | } |
| 7225 | #else |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7226 | pf->num_lan_msix = 2; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7227 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7228 | break; |
| 7229 | default: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7230 | #ifdef I40E_FCOE |
| 7231 | /* give one vector to FCoE */ |
| 7232 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 7233 | pf->num_fcoe_msix = 1; |
| 7234 | vec--; |
| 7235 | } |
| 7236 | #endif |
Shannon Nelson | 1e200e4 | 2015-02-27 09:15:24 +0000 | [diff] [blame] | 7237 | /* give the rest to the PF */ |
| 7238 | pf->num_lan_msix = min_t(int, vec, pf->num_lan_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7239 | break; |
| 7240 | } |
| 7241 | } |
| 7242 | |
Anjali Singhai Jain | a34977b | 2014-05-21 23:32:43 +0000 | [diff] [blame] | 7243 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 7244 | (pf->num_vmdq_msix == 0)) { |
| 7245 | dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); |
| 7246 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 7247 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7248 | #ifdef I40E_FCOE |
| 7249 | |
| 7250 | if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) { |
| 7251 | dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n"); |
| 7252 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 7253 | } |
| 7254 | #endif |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7255 | return v_actual; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7256 | } |
| 7257 | |
| 7258 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7259 | * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7260 | * @vsi: the VSI being configured |
| 7261 | * @v_idx: index of the vector in the vsi struct |
| 7262 | * |
| 7263 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 7264 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7265 | 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] | 7266 | { |
| 7267 | struct i40e_q_vector *q_vector; |
| 7268 | |
| 7269 | /* allocate q_vector */ |
| 7270 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 7271 | if (!q_vector) |
| 7272 | return -ENOMEM; |
| 7273 | |
| 7274 | q_vector->vsi = vsi; |
| 7275 | q_vector->v_idx = v_idx; |
| 7276 | cpumask_set_cpu(v_idx, &q_vector->affinity_mask); |
| 7277 | if (vsi->netdev) |
| 7278 | netif_napi_add(vsi->netdev, &q_vector->napi, |
Jesse Brandeburg | eefeace | 2014-05-10 04:49:13 +0000 | [diff] [blame] | 7279 | i40e_napi_poll, NAPI_POLL_WEIGHT); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7280 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 7281 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 7282 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 7283 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7284 | /* tie q_vector and vsi together */ |
| 7285 | vsi->q_vectors[v_idx] = q_vector; |
| 7286 | |
| 7287 | return 0; |
| 7288 | } |
| 7289 | |
| 7290 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7291 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7292 | * @vsi: the VSI being configured |
| 7293 | * |
| 7294 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 7295 | * return -ENOMEM. |
| 7296 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7297 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7298 | { |
| 7299 | struct i40e_pf *pf = vsi->back; |
| 7300 | int v_idx, num_q_vectors; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7301 | int err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7302 | |
| 7303 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 7304 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 7305 | num_q_vectors = vsi->num_q_vectors; |
| 7306 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 7307 | num_q_vectors = 1; |
| 7308 | else |
| 7309 | return -EINVAL; |
| 7310 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7311 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7312 | err = i40e_vsi_alloc_q_vector(vsi, v_idx); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7313 | if (err) |
| 7314 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7315 | } |
| 7316 | |
| 7317 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7318 | |
| 7319 | err_out: |
| 7320 | while (v_idx--) |
| 7321 | i40e_free_q_vector(vsi, v_idx); |
| 7322 | |
| 7323 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7324 | } |
| 7325 | |
| 7326 | /** |
| 7327 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 7328 | * @pf: board private structure to initialize |
| 7329 | **/ |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7330 | static int i40e_init_interrupt_scheme(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7331 | { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7332 | int vectors = 0; |
| 7333 | ssize_t size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7334 | |
| 7335 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7336 | vectors = i40e_init_msix(pf); |
| 7337 | if (vectors < 0) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7338 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7339 | #ifdef I40E_FCOE |
| 7340 | I40E_FLAG_FCOE_ENABLED | |
| 7341 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7342 | I40E_FLAG_RSS_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 7343 | I40E_FLAG_DCB_CAPABLE | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7344 | I40E_FLAG_SRIOV_ENABLED | |
| 7345 | I40E_FLAG_FD_SB_ENABLED | |
| 7346 | I40E_FLAG_FD_ATR_ENABLED | |
| 7347 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7348 | |
| 7349 | /* rework the queue expectations without MSIX */ |
| 7350 | i40e_determine_queue_usage(pf); |
| 7351 | } |
| 7352 | } |
| 7353 | |
| 7354 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 7355 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7356 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7357 | vectors = pci_enable_msi(pf->pdev); |
| 7358 | if (vectors < 0) { |
| 7359 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", |
| 7360 | vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7361 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 7362 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7363 | vectors = 1; /* one MSI or Legacy vector */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7364 | } |
| 7365 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 7366 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7367 | 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] | 7368 | |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7369 | /* set up vector assignment tracking */ |
| 7370 | size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors); |
| 7371 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7372 | if (!pf->irq_pile) { |
| 7373 | dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n"); |
| 7374 | return -ENOMEM; |
| 7375 | } |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7376 | pf->irq_pile->num_entries = vectors; |
| 7377 | pf->irq_pile->search_hint = 0; |
| 7378 | |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 7379 | /* track first vector for misc interrupts, ignore return */ |
Shannon Nelson | 3b44439 | 2015-02-26 16:15:57 +0000 | [diff] [blame] | 7380 | (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] | 7381 | |
| 7382 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7383 | } |
| 7384 | |
| 7385 | /** |
| 7386 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 7387 | * @pf: board private structure |
| 7388 | * |
| 7389 | * This sets up the handler for MSIX 0, which is used to manage the |
| 7390 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 7391 | * when in MSI or Legacy interrupt mode. |
| 7392 | **/ |
| 7393 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 7394 | { |
| 7395 | struct i40e_hw *hw = &pf->hw; |
| 7396 | int err = 0; |
| 7397 | |
| 7398 | /* Only request the irq if this is the first time through, and |
| 7399 | * not when we're rebuilding after a Reset |
| 7400 | */ |
| 7401 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 7402 | err = request_irq(pf->msix_entries[0].vector, |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 7403 | i40e_intr, 0, pf->int_name, pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7404 | if (err) { |
| 7405 | dev_info(&pf->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 7406 | "request_irq for %s failed: %d\n", |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 7407 | pf->int_name, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7408 | return -EFAULT; |
| 7409 | } |
| 7410 | } |
| 7411 | |
Jacob Keller | ab437b5 | 2014-12-14 01:55:08 +0000 | [diff] [blame] | 7412 | i40e_enable_misc_int_causes(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7413 | |
| 7414 | /* associate no queues to the misc vector */ |
| 7415 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 7416 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 7417 | |
| 7418 | i40e_flush(hw); |
| 7419 | |
| 7420 | i40e_irq_dynamic_enable_icr0(pf); |
| 7421 | |
| 7422 | return err; |
| 7423 | } |
| 7424 | |
| 7425 | /** |
| 7426 | * i40e_config_rss - Prepare for RSS if used |
| 7427 | * @pf: board private structure |
| 7428 | **/ |
| 7429 | static int i40e_config_rss(struct i40e_pf *pf) |
| 7430 | { |
Eric Dumazet | 22f258a | 2014-11-16 06:23:13 -0800 | [diff] [blame] | 7431 | u32 rss_key[I40E_PFQF_HKEY_MAX_INDEX + 1]; |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 7432 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 7433 | struct i40e_hw *hw = &pf->hw; |
| 7434 | u32 lut = 0; |
| 7435 | int i, j; |
| 7436 | u64 hena; |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 7437 | u32 reg_val; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7438 | |
Eric Dumazet | 22f258a | 2014-11-16 06:23:13 -0800 | [diff] [blame] | 7439 | netdev_rss_key_fill(rss_key, sizeof(rss_key)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7440 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
Eric Dumazet | 22f258a | 2014-11-16 06:23:13 -0800 | [diff] [blame] | 7441 | wr32(hw, I40E_PFQF_HKEY(i), rss_key[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7442 | |
| 7443 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
| 7444 | hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) | |
| 7445 | ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32); |
Mitch Williams | 12dc4fe | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 7446 | hena |= I40E_DEFAULT_RSS_HENA; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7447 | wr32(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 7448 | wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
| 7449 | |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 7450 | vsi->rss_size = min_t(int, pf->rss_size, vsi->num_queue_pairs); |
| 7451 | |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 7452 | /* Check capability and Set table size and register per hw expectation*/ |
| 7453 | reg_val = rd32(hw, I40E_PFQF_CTL_0); |
Anjali Singhai Jain | d9e894e | 2015-02-27 09:15:30 +0000 | [diff] [blame] | 7454 | if (pf->rss_table_size == 512) |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 7455 | reg_val |= I40E_PFQF_CTL_0_HASHLUTSIZE_512; |
Anjali Singhai Jain | d9e894e | 2015-02-27 09:15:30 +0000 | [diff] [blame] | 7456 | else |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 7457 | reg_val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_512; |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 7458 | wr32(hw, I40E_PFQF_CTL_0, reg_val); |
| 7459 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7460 | /* Populate the LUT with max no. of queues in round robin fashion */ |
Carolyn Wyborny | e157ea3 | 2014-06-03 23:50:22 +0000 | [diff] [blame] | 7461 | for (i = 0, j = 0; i < pf->rss_table_size; i++, j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7462 | |
| 7463 | /* The assumption is that lan qp count will be the highest |
| 7464 | * qp count for any PF VSI that needs RSS. |
| 7465 | * If multiple VSIs need RSS support, all the qp counts |
| 7466 | * for those VSIs should be a power of 2 for RSS to work. |
| 7467 | * If LAN VSI is the only consumer for RSS then this requirement |
| 7468 | * is not necessary. |
| 7469 | */ |
Anjali Singhai Jain | 66ddcff | 2015-02-24 06:58:50 +0000 | [diff] [blame] | 7470 | if (j == vsi->rss_size) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7471 | j = 0; |
| 7472 | /* lut = 4-byte sliding window of 4 lut entries */ |
| 7473 | lut = (lut << 8) | (j & |
| 7474 | ((0x1 << pf->hw.func_caps.rss_table_entry_width) - 1)); |
| 7475 | /* On i = 3, we have 4 entries in lut; write to the register */ |
| 7476 | if ((i & 3) == 3) |
| 7477 | wr32(hw, I40E_PFQF_HLUT(i >> 2), lut); |
| 7478 | } |
| 7479 | i40e_flush(hw); |
| 7480 | |
| 7481 | return 0; |
| 7482 | } |
| 7483 | |
| 7484 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7485 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 7486 | * @pf: board private structure |
| 7487 | * @queue_count: the requested queue count for rss. |
| 7488 | * |
| 7489 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 7490 | * count which may be different from the requested queue count. |
| 7491 | **/ |
| 7492 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 7493 | { |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 7494 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 7495 | int new_rss_size; |
| 7496 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7497 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 7498 | return 0; |
| 7499 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 7500 | 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] | 7501 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 7502 | if (queue_count != vsi->num_queue_pairs) { |
| 7503 | vsi->req_queue_pairs = queue_count; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7504 | i40e_prep_for_reset(pf); |
| 7505 | |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 7506 | pf->rss_size = new_rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7507 | |
| 7508 | i40e_reset_and_rebuild(pf, true); |
| 7509 | i40e_config_rss(pf); |
| 7510 | } |
| 7511 | dev_info(&pf->pdev->dev, "RSS count: %d\n", pf->rss_size); |
| 7512 | return pf->rss_size; |
| 7513 | } |
| 7514 | |
| 7515 | /** |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 7516 | * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition |
| 7517 | * @pf: board private structure |
| 7518 | **/ |
| 7519 | i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf) |
| 7520 | { |
| 7521 | i40e_status status; |
| 7522 | bool min_valid, max_valid; |
| 7523 | u32 max_bw, min_bw; |
| 7524 | |
| 7525 | status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw, |
| 7526 | &min_valid, &max_valid); |
| 7527 | |
| 7528 | if (!status) { |
| 7529 | if (min_valid) |
| 7530 | pf->npar_min_bw = min_bw; |
| 7531 | if (max_valid) |
| 7532 | pf->npar_max_bw = max_bw; |
| 7533 | } |
| 7534 | |
| 7535 | return status; |
| 7536 | } |
| 7537 | |
| 7538 | /** |
| 7539 | * i40e_set_npar_bw_setting - Set BW settings for this PF partition |
| 7540 | * @pf: board private structure |
| 7541 | **/ |
| 7542 | i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf) |
| 7543 | { |
| 7544 | struct i40e_aqc_configure_partition_bw_data bw_data; |
| 7545 | i40e_status status; |
| 7546 | |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 7547 | /* Set the valid bit for this PF */ |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 7548 | bw_data.pf_valid_bits = cpu_to_le16(1 << pf->hw.pf_id); |
| 7549 | bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK; |
| 7550 | bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK; |
| 7551 | |
| 7552 | /* Set the new bandwidths */ |
| 7553 | status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL); |
| 7554 | |
| 7555 | return status; |
| 7556 | } |
| 7557 | |
| 7558 | /** |
| 7559 | * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition |
| 7560 | * @pf: board private structure |
| 7561 | **/ |
| 7562 | i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf) |
| 7563 | { |
| 7564 | /* Commit temporary BW setting to permanent NVM image */ |
| 7565 | enum i40e_admin_queue_err last_aq_status; |
| 7566 | i40e_status ret; |
| 7567 | u16 nvm_word; |
| 7568 | |
| 7569 | if (pf->hw.partition_id != 1) { |
| 7570 | dev_info(&pf->pdev->dev, |
| 7571 | "Commit BW only works on partition 1! This is partition %d", |
| 7572 | pf->hw.partition_id); |
| 7573 | ret = I40E_NOT_SUPPORTED; |
| 7574 | goto bw_commit_out; |
| 7575 | } |
| 7576 | |
| 7577 | /* Acquire NVM for read access */ |
| 7578 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); |
| 7579 | last_aq_status = pf->hw.aq.asq_last_status; |
| 7580 | if (ret) { |
| 7581 | dev_info(&pf->pdev->dev, |
| 7582 | "Cannot acquire NVM for read access, err %d: aq_err %d\n", |
| 7583 | ret, last_aq_status); |
| 7584 | goto bw_commit_out; |
| 7585 | } |
| 7586 | |
| 7587 | /* Read word 0x10 of NVM - SW compatibility word 1 */ |
| 7588 | ret = i40e_aq_read_nvm(&pf->hw, |
| 7589 | I40E_SR_NVM_CONTROL_WORD, |
| 7590 | 0x10, sizeof(nvm_word), &nvm_word, |
| 7591 | false, NULL); |
| 7592 | /* Save off last admin queue command status before releasing |
| 7593 | * the NVM |
| 7594 | */ |
| 7595 | last_aq_status = pf->hw.aq.asq_last_status; |
| 7596 | i40e_release_nvm(&pf->hw); |
| 7597 | if (ret) { |
| 7598 | dev_info(&pf->pdev->dev, "NVM read error, err %d aq_err %d\n", |
| 7599 | ret, last_aq_status); |
| 7600 | goto bw_commit_out; |
| 7601 | } |
| 7602 | |
| 7603 | /* Wait a bit for NVM release to complete */ |
| 7604 | msleep(50); |
| 7605 | |
| 7606 | /* Acquire NVM for write access */ |
| 7607 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE); |
| 7608 | last_aq_status = pf->hw.aq.asq_last_status; |
| 7609 | if (ret) { |
| 7610 | dev_info(&pf->pdev->dev, |
| 7611 | "Cannot acquire NVM for write access, err %d: aq_err %d\n", |
| 7612 | ret, last_aq_status); |
| 7613 | goto bw_commit_out; |
| 7614 | } |
| 7615 | /* Write it back out unchanged to initiate update NVM, |
| 7616 | * which will force a write of the shadow (alt) RAM to |
| 7617 | * the NVM - thus storing the bandwidth values permanently. |
| 7618 | */ |
| 7619 | ret = i40e_aq_update_nvm(&pf->hw, |
| 7620 | I40E_SR_NVM_CONTROL_WORD, |
| 7621 | 0x10, sizeof(nvm_word), |
| 7622 | &nvm_word, true, NULL); |
| 7623 | /* Save off last admin queue command status before releasing |
| 7624 | * the NVM |
| 7625 | */ |
| 7626 | last_aq_status = pf->hw.aq.asq_last_status; |
| 7627 | i40e_release_nvm(&pf->hw); |
| 7628 | if (ret) |
| 7629 | dev_info(&pf->pdev->dev, |
| 7630 | "BW settings NOT SAVED, err %d aq_err %d\n", |
| 7631 | ret, last_aq_status); |
| 7632 | bw_commit_out: |
| 7633 | |
| 7634 | return ret; |
| 7635 | } |
| 7636 | |
| 7637 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7638 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 7639 | * @pf: board private structure to initialize |
| 7640 | * |
| 7641 | * i40e_sw_init initializes the Adapter private data structure. |
| 7642 | * Fields are initialized based on PCI device information and |
| 7643 | * OS network device settings (MTU size). |
| 7644 | **/ |
| 7645 | static int i40e_sw_init(struct i40e_pf *pf) |
| 7646 | { |
| 7647 | int err = 0; |
| 7648 | int size; |
| 7649 | |
| 7650 | pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE, |
| 7651 | (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)); |
Shannon Nelson | 2759997 | 2013-11-16 10:00:43 +0000 | [diff] [blame] | 7652 | pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7653 | if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) { |
| 7654 | if (I40E_DEBUG_USER & debug) |
| 7655 | pf->hw.debug_mask = debug; |
| 7656 | pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER), |
| 7657 | I40E_DEFAULT_MSG_ENABLE); |
| 7658 | } |
| 7659 | |
| 7660 | /* Set default capability flags */ |
| 7661 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 7662 | I40E_FLAG_MSI_ENABLED | |
Mitch Williams | 2bc7ee8 | 2015-02-06 08:52:11 +0000 | [diff] [blame] | 7663 | I40E_FLAG_MSIX_ENABLED; |
| 7664 | |
| 7665 | if (iommu_present(&pci_bus_type)) |
| 7666 | pf->flags |= I40E_FLAG_RX_PS_ENABLED; |
| 7667 | else |
| 7668 | pf->flags |= I40E_FLAG_RX_1BUF_ENABLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7669 | |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 7670 | /* Set default ITR */ |
| 7671 | pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF; |
| 7672 | pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF; |
| 7673 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 7674 | /* Depending on PF configurations, it is possible that the RSS |
| 7675 | * maximum might end up larger than the available queues |
| 7676 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7677 | pf->rss_size_max = 0x1 << pf->hw.func_caps.rss_table_entry_width; |
Paul M Stillwell Jr | ec9a7db | 2014-07-09 07:46:10 +0000 | [diff] [blame] | 7678 | pf->rss_size = 1; |
Anjali Singhai Jain | 5db4cb5 | 2015-02-24 06:58:49 +0000 | [diff] [blame] | 7679 | pf->rss_table_size = pf->hw.func_caps.rss_table_size; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 7680 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 7681 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7682 | if (pf->hw.func_caps.rss) { |
| 7683 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Jesse Brandeburg | bf051a3 | 2013-11-26 10:49:17 +0000 | [diff] [blame] | 7684 | pf->rss_size = min_t(int, pf->rss_size_max, num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7685 | } |
| 7686 | |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 7687 | /* MFP mode enabled */ |
| 7688 | if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.mfp_mode_1) { |
| 7689 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 7690 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
Greg Rose | f4492db | 2015-02-06 08:52:12 +0000 | [diff] [blame] | 7691 | if (i40e_get_npar_bw_setting(pf)) |
| 7692 | dev_warn(&pf->pdev->dev, |
| 7693 | "Could not get NPAR bw settings\n"); |
| 7694 | else |
| 7695 | dev_info(&pf->pdev->dev, |
| 7696 | "Min BW = %8.8x, Max BW = %8.8x\n", |
| 7697 | pf->npar_min_bw, pf->npar_max_bw); |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 7698 | } |
| 7699 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 7700 | /* FW/NVM is not yet fixed in this regard */ |
| 7701 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 7702 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 7703 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 7704 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 7705 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 7706 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 7707 | } else { |
| 7708 | dev_info(&pf->pdev->dev, |
Anjali Singhai Jain | 0b67584 | 2014-03-06 08:59:51 +0000 | [diff] [blame] | 7709 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7710 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 7711 | pf->fdir_pf_filter_count = |
| 7712 | pf->hw.func_caps.fd_filters_guaranteed; |
| 7713 | pf->hw.fdir_shared_filter_count = |
| 7714 | pf->hw.func_caps.fd_filters_best_effort; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7715 | } |
| 7716 | |
| 7717 | if (pf->hw.func_caps.vmdq) { |
| 7718 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
| 7719 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
| 7720 | pf->num_vmdq_qps = I40E_DEFAULT_QUEUES_PER_VMDQ; |
| 7721 | } |
| 7722 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 7723 | #ifdef I40E_FCOE |
| 7724 | err = i40e_init_pf_fcoe(pf); |
| 7725 | if (err) |
| 7726 | dev_info(&pf->pdev->dev, "init_pf_fcoe failed: %d\n", err); |
| 7727 | |
| 7728 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7729 | #ifdef CONFIG_PCI_IOV |
Shannon Nelson | ba252f1 | 2014-12-11 07:06:34 +0000 | [diff] [blame] | 7730 | if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7731 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 7732 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 7733 | pf->num_req_vfs = min_t(int, |
| 7734 | pf->hw.func_caps.num_vfs, |
| 7735 | I40E_MAX_VF_COUNT); |
| 7736 | } |
| 7737 | #endif /* CONFIG_PCI_IOV */ |
| 7738 | pf->eeprom_version = 0xDEAD; |
| 7739 | pf->lan_veb = I40E_NO_VEB; |
| 7740 | pf->lan_vsi = I40E_NO_VSI; |
| 7741 | |
| 7742 | /* set up queue assignment tracking */ |
| 7743 | size = sizeof(struct i40e_lump_tracking) |
| 7744 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 7745 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 7746 | if (!pf->qp_pile) { |
| 7747 | err = -ENOMEM; |
| 7748 | goto sw_init_done; |
| 7749 | } |
| 7750 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 7751 | pf->qp_pile->search_hint = 0; |
| 7752 | |
Anjali Singhai Jain | 327fe04 | 2014-06-04 01:23:26 +0000 | [diff] [blame] | 7753 | pf->tx_timeout_recovery_level = 1; |
| 7754 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7755 | mutex_init(&pf->switch_mutex); |
| 7756 | |
Greg Rose | c668a12 | 2015-02-26 16:10:39 +0000 | [diff] [blame] | 7757 | /* If NPAR is enabled nudge the Tx scheduler */ |
| 7758 | if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf))) |
| 7759 | i40e_set_npar_bw_setting(pf); |
| 7760 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7761 | sw_init_done: |
| 7762 | return err; |
| 7763 | } |
| 7764 | |
| 7765 | /** |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 7766 | * i40e_set_ntuple - set the ntuple feature flag and take action |
| 7767 | * @pf: board private structure to initialize |
| 7768 | * @features: the feature set that the stack is suggesting |
| 7769 | * |
| 7770 | * returns a bool to indicate if reset needs to happen |
| 7771 | **/ |
| 7772 | bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features) |
| 7773 | { |
| 7774 | bool need_reset = false; |
| 7775 | |
| 7776 | /* Check if Flow Director n-tuple support was enabled or disabled. If |
| 7777 | * the state changed, we need to reset. |
| 7778 | */ |
| 7779 | if (features & NETIF_F_NTUPLE) { |
| 7780 | /* Enable filters and mark for reset */ |
| 7781 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 7782 | need_reset = true; |
| 7783 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
| 7784 | } else { |
| 7785 | /* turn off filters, mark for reset and clear SW filter list */ |
| 7786 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 7787 | need_reset = true; |
| 7788 | i40e_fdir_filter_exit(pf); |
| 7789 | } |
| 7790 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 7791 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 7792 | /* reset fd counters */ |
| 7793 | pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0; |
| 7794 | pf->fdir_pf_active_filters = 0; |
| 7795 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 2e4875e | 2015-04-16 20:06:06 -0400 | [diff] [blame] | 7796 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
| 7797 | dev_info(&pf->pdev->dev, "ATR re-enabled.\n"); |
Anjali Singhai Jain | 8a4f34f | 2014-06-04 08:45:20 +0000 | [diff] [blame] | 7798 | /* if ATR was auto disabled it can be re-enabled. */ |
| 7799 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 7800 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 7801 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 7802 | } |
| 7803 | return need_reset; |
| 7804 | } |
| 7805 | |
| 7806 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7807 | * i40e_set_features - set the netdev feature flags |
| 7808 | * @netdev: ptr to the netdev being adjusted |
| 7809 | * @features: the feature set that the stack is suggesting |
| 7810 | **/ |
| 7811 | static int i40e_set_features(struct net_device *netdev, |
| 7812 | netdev_features_t features) |
| 7813 | { |
| 7814 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 7815 | struct i40e_vsi *vsi = np->vsi; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 7816 | struct i40e_pf *pf = vsi->back; |
| 7817 | bool need_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7818 | |
| 7819 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 7820 | i40e_vlan_stripping_enable(vsi); |
| 7821 | else |
| 7822 | i40e_vlan_stripping_disable(vsi); |
| 7823 | |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 7824 | need_reset = i40e_set_ntuple(pf, features); |
| 7825 | |
| 7826 | if (need_reset) |
| 7827 | i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED)); |
| 7828 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7829 | return 0; |
| 7830 | } |
| 7831 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7832 | #ifdef CONFIG_I40E_VXLAN |
| 7833 | /** |
| 7834 | * i40e_get_vxlan_port_idx - Lookup a possibly offloaded for Rx UDP port |
| 7835 | * @pf: board private structure |
| 7836 | * @port: The UDP port to look up |
| 7837 | * |
| 7838 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found |
| 7839 | **/ |
| 7840 | static u8 i40e_get_vxlan_port_idx(struct i40e_pf *pf, __be16 port) |
| 7841 | { |
| 7842 | u8 i; |
| 7843 | |
| 7844 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
| 7845 | if (pf->vxlan_ports[i] == port) |
| 7846 | return i; |
| 7847 | } |
| 7848 | |
| 7849 | return i; |
| 7850 | } |
| 7851 | |
| 7852 | /** |
| 7853 | * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up |
| 7854 | * @netdev: This physical port's netdev |
| 7855 | * @sa_family: Socket Family that VXLAN is notifying us about |
| 7856 | * @port: New UDP port number that VXLAN started listening to |
| 7857 | **/ |
| 7858 | static void i40e_add_vxlan_port(struct net_device *netdev, |
| 7859 | sa_family_t sa_family, __be16 port) |
| 7860 | { |
| 7861 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 7862 | struct i40e_vsi *vsi = np->vsi; |
| 7863 | struct i40e_pf *pf = vsi->back; |
| 7864 | u8 next_idx; |
| 7865 | u8 idx; |
| 7866 | |
| 7867 | if (sa_family == AF_INET6) |
| 7868 | return; |
| 7869 | |
| 7870 | idx = i40e_get_vxlan_port_idx(pf, port); |
| 7871 | |
| 7872 | /* Check if port already exists */ |
| 7873 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7874 | netdev_info(netdev, "vxlan port %d already offloaded\n", |
| 7875 | ntohs(port)); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7876 | return; |
| 7877 | } |
| 7878 | |
| 7879 | /* Now check if there is space to add the new port */ |
| 7880 | next_idx = i40e_get_vxlan_port_idx(pf, 0); |
| 7881 | |
| 7882 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7883 | 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] | 7884 | ntohs(port)); |
| 7885 | return; |
| 7886 | } |
| 7887 | |
| 7888 | /* New port: add it and mark its index in the bitmap */ |
| 7889 | pf->vxlan_ports[next_idx] = port; |
| 7890 | pf->pending_vxlan_bitmap |= (1 << next_idx); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7891 | pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7892 | |
| 7893 | dev_info(&pf->pdev->dev, "adding vxlan port %d\n", ntohs(port)); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7894 | } |
| 7895 | |
| 7896 | /** |
| 7897 | * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away |
| 7898 | * @netdev: This physical port's netdev |
| 7899 | * @sa_family: Socket Family that VXLAN is notifying us about |
| 7900 | * @port: UDP port number that VXLAN stopped listening to |
| 7901 | **/ |
| 7902 | static void i40e_del_vxlan_port(struct net_device *netdev, |
| 7903 | sa_family_t sa_family, __be16 port) |
| 7904 | { |
| 7905 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 7906 | struct i40e_vsi *vsi = np->vsi; |
| 7907 | struct i40e_pf *pf = vsi->back; |
| 7908 | u8 idx; |
| 7909 | |
| 7910 | if (sa_family == AF_INET6) |
| 7911 | return; |
| 7912 | |
| 7913 | idx = i40e_get_vxlan_port_idx(pf, port); |
| 7914 | |
| 7915 | /* Check if port already exists */ |
| 7916 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 7917 | /* if port exists, set it to 0 (mark for deletion) |
| 7918 | * and make it pending |
| 7919 | */ |
| 7920 | pf->vxlan_ports[idx] = 0; |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7921 | pf->pending_vxlan_bitmap |= (1 << idx); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7922 | pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC; |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7923 | |
| 7924 | dev_info(&pf->pdev->dev, "deleting vxlan port %d\n", |
| 7925 | ntohs(port)); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7926 | } else { |
Shannon Nelson | c22c06c | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 7927 | netdev_warn(netdev, "vxlan port %d was not found, not deleting\n", |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 7928 | ntohs(port)); |
| 7929 | } |
| 7930 | } |
| 7931 | |
| 7932 | #endif |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 7933 | static int i40e_get_phys_port_id(struct net_device *netdev, |
Jiri Pirko | 02637fc | 2014-11-28 14:34:16 +0100 | [diff] [blame] | 7934 | struct netdev_phys_item_id *ppid) |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 7935 | { |
| 7936 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 7937 | struct i40e_pf *pf = np->vsi->back; |
| 7938 | struct i40e_hw *hw = &pf->hw; |
| 7939 | |
| 7940 | if (!(pf->flags & I40E_FLAG_PORT_ID_VALID)) |
| 7941 | return -EOPNOTSUPP; |
| 7942 | |
| 7943 | ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id)); |
| 7944 | memcpy(ppid->id, hw->mac.port_addr, ppid->id_len); |
| 7945 | |
| 7946 | return 0; |
| 7947 | } |
| 7948 | |
Jesse Brandeburg | 2f90ade | 2014-11-20 16:30:02 -0800 | [diff] [blame] | 7949 | /** |
| 7950 | * i40e_ndo_fdb_add - add an entry to the hardware database |
| 7951 | * @ndm: the input from the stack |
| 7952 | * @tb: pointer to array of nladdr (unused) |
| 7953 | * @dev: the net device pointer |
| 7954 | * @addr: the MAC address entry being added |
| 7955 | * @flags: instructions from stack about fdb operation |
| 7956 | */ |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 7957 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 7958 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 7959 | const unsigned char *addr, u16 vid, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 7960 | u16 flags) |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 7961 | { |
| 7962 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 7963 | struct i40e_pf *pf = np->vsi->back; |
| 7964 | int err = 0; |
| 7965 | |
| 7966 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) |
| 7967 | return -EOPNOTSUPP; |
| 7968 | |
Or Gerlitz | 65891fe | 2014-12-14 18:19:05 +0200 | [diff] [blame] | 7969 | if (vid) { |
| 7970 | pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name); |
| 7971 | return -EINVAL; |
| 7972 | } |
| 7973 | |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 7974 | /* Hardware does not support aging addresses so if a |
| 7975 | * ndm_state is given only allow permanent addresses |
| 7976 | */ |
| 7977 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
| 7978 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 7979 | return -EINVAL; |
| 7980 | } |
| 7981 | |
| 7982 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) |
| 7983 | err = dev_uc_add_excl(dev, addr); |
| 7984 | else if (is_multicast_ether_addr(addr)) |
| 7985 | err = dev_mc_add_excl(dev, addr); |
| 7986 | else |
| 7987 | err = -EINVAL; |
| 7988 | |
| 7989 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 7990 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 7991 | err = 0; |
| 7992 | |
| 7993 | return err; |
| 7994 | } |
| 7995 | |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 7996 | #ifdef HAVE_BRIDGE_ATTRIBS |
| 7997 | /** |
| 7998 | * i40e_ndo_bridge_setlink - Set the hardware bridge mode |
| 7999 | * @dev: the netdev being configured |
| 8000 | * @nlh: RTNL message |
| 8001 | * |
| 8002 | * Inserts a new hardware bridge if not already created and |
| 8003 | * enables the bridging mode requested (VEB or VEPA). If the |
| 8004 | * hardware bridge has already been inserted and the request |
| 8005 | * is to change the mode then that requires a PF reset to |
| 8006 | * allow rebuild of the components with required hardware |
| 8007 | * bridge mode enabled. |
| 8008 | **/ |
| 8009 | static int i40e_ndo_bridge_setlink(struct net_device *dev, |
| 8010 | struct nlmsghdr *nlh) |
| 8011 | { |
| 8012 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8013 | struct i40e_vsi *vsi = np->vsi; |
| 8014 | struct i40e_pf *pf = vsi->back; |
| 8015 | struct i40e_veb *veb = NULL; |
| 8016 | struct nlattr *attr, *br_spec; |
| 8017 | int i, rem; |
| 8018 | |
| 8019 | /* Only for PF VSI for now */ |
| 8020 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 8021 | return -EOPNOTSUPP; |
| 8022 | |
| 8023 | /* Find the HW bridge for PF VSI */ |
| 8024 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 8025 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 8026 | veb = pf->veb[i]; |
| 8027 | } |
| 8028 | |
| 8029 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 8030 | |
| 8031 | nla_for_each_nested(attr, br_spec, rem) { |
| 8032 | __u16 mode; |
| 8033 | |
| 8034 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 8035 | continue; |
| 8036 | |
| 8037 | mode = nla_get_u16(attr); |
| 8038 | if ((mode != BRIDGE_MODE_VEPA) && |
| 8039 | (mode != BRIDGE_MODE_VEB)) |
| 8040 | return -EINVAL; |
| 8041 | |
| 8042 | /* Insert a new HW bridge */ |
| 8043 | if (!veb) { |
| 8044 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 8045 | vsi->tc_config.enabled_tc); |
| 8046 | if (veb) { |
| 8047 | veb->bridge_mode = mode; |
| 8048 | i40e_config_bridge_mode(veb); |
| 8049 | } else { |
| 8050 | /* No Bridge HW offload available */ |
| 8051 | return -ENOENT; |
| 8052 | } |
| 8053 | break; |
| 8054 | } else if (mode != veb->bridge_mode) { |
| 8055 | /* Existing HW bridge but different mode needs reset */ |
| 8056 | veb->bridge_mode = mode; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 8057 | /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */ |
| 8058 | if (mode == BRIDGE_MODE_VEB) |
| 8059 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 8060 | else |
| 8061 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 8062 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED)); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8063 | break; |
| 8064 | } |
| 8065 | } |
| 8066 | |
| 8067 | return 0; |
| 8068 | } |
| 8069 | |
| 8070 | /** |
| 8071 | * i40e_ndo_bridge_getlink - Get the hardware bridge mode |
| 8072 | * @skb: skb buff |
| 8073 | * @pid: process id |
| 8074 | * @seq: RTNL message seq # |
| 8075 | * @dev: the netdev being configured |
| 8076 | * @filter_mask: unused |
| 8077 | * |
| 8078 | * Return the mode in which the hardware bridge is operating in |
| 8079 | * i.e VEB or VEPA. |
| 8080 | **/ |
| 8081 | #ifdef HAVE_BRIDGE_FILTER |
| 8082 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 8083 | struct net_device *dev, |
Scott Feldman | 7d4f8d8 | 2015-06-22 00:27:17 -0700 | [diff] [blame] | 8084 | u32 filter_mask, int nlflags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8085 | #else |
| 8086 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 8087 | struct net_device *dev, int nlflags) |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8088 | #endif /* HAVE_BRIDGE_FILTER */ |
| 8089 | { |
| 8090 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 8091 | struct i40e_vsi *vsi = np->vsi; |
| 8092 | struct i40e_pf *pf = vsi->back; |
| 8093 | struct i40e_veb *veb = NULL; |
| 8094 | int i; |
| 8095 | |
| 8096 | /* Only for PF VSI for now */ |
| 8097 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) |
| 8098 | return -EOPNOTSUPP; |
| 8099 | |
| 8100 | /* Find the HW bridge for the PF VSI */ |
| 8101 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 8102 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 8103 | veb = pf->veb[i]; |
| 8104 | } |
| 8105 | |
| 8106 | if (!veb) |
| 8107 | return 0; |
| 8108 | |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 8109 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, |
Scott Feldman | 7d4f8d8 | 2015-06-22 00:27:17 -0700 | [diff] [blame] | 8110 | nlflags, 0, 0, filter_mask, NULL); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8111 | } |
| 8112 | #endif /* HAVE_BRIDGE_ATTRIBS */ |
| 8113 | |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8114 | #define I40E_MAX_TUNNEL_HDR_LEN 80 |
| 8115 | /** |
| 8116 | * i40e_features_check - Validate encapsulated packet conforms to limits |
| 8117 | * @skb: skb buff |
| 8118 | * @netdev: This physical port's netdev |
| 8119 | * @features: Offload features that the stack believes apply |
| 8120 | **/ |
| 8121 | static netdev_features_t i40e_features_check(struct sk_buff *skb, |
| 8122 | struct net_device *dev, |
| 8123 | netdev_features_t features) |
| 8124 | { |
| 8125 | if (skb->encapsulation && |
| 8126 | (skb_inner_mac_header(skb) - skb_transport_header(skb) > |
| 8127 | I40E_MAX_TUNNEL_HDR_LEN)) |
| 8128 | return features & ~(NETIF_F_ALL_CSUM | NETIF_F_GSO_MASK); |
| 8129 | |
| 8130 | return features; |
| 8131 | } |
| 8132 | |
Shannon Nelson | 37a2973 | 2015-02-27 09:15:19 +0000 | [diff] [blame] | 8133 | static const struct net_device_ops i40e_netdev_ops = { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8134 | .ndo_open = i40e_open, |
| 8135 | .ndo_stop = i40e_close, |
| 8136 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 8137 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 8138 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 8139 | .ndo_validate_addr = eth_validate_addr, |
| 8140 | .ndo_set_mac_address = i40e_set_mac, |
| 8141 | .ndo_change_mtu = i40e_change_mtu, |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 8142 | .ndo_do_ioctl = i40e_ioctl, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8143 | .ndo_tx_timeout = i40e_tx_timeout, |
| 8144 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 8145 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 8146 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 8147 | .ndo_poll_controller = i40e_netpoll, |
| 8148 | #endif |
| 8149 | .ndo_setup_tc = i40e_setup_tc, |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8150 | #ifdef I40E_FCOE |
| 8151 | .ndo_fcoe_enable = i40e_fcoe_enable, |
| 8152 | .ndo_fcoe_disable = i40e_fcoe_disable, |
| 8153 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8154 | .ndo_set_features = i40e_set_features, |
| 8155 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 8156 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 8157 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8158 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 8159 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
Serey Kong | e6d9004 | 2014-07-12 07:28:14 +0000 | [diff] [blame] | 8160 | .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk, |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 8161 | #ifdef CONFIG_I40E_VXLAN |
| 8162 | .ndo_add_vxlan_port = i40e_add_vxlan_port, |
| 8163 | .ndo_del_vxlan_port = i40e_del_vxlan_port, |
| 8164 | #endif |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 8165 | .ndo_get_phys_port_id = i40e_get_phys_port_id, |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 8166 | .ndo_fdb_add = i40e_ndo_fdb_add, |
Joe Stringer | f44a75e | 2015-04-14 17:09:14 -0700 | [diff] [blame] | 8167 | .ndo_features_check = i40e_features_check, |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8168 | #ifdef HAVE_BRIDGE_ATTRIBS |
| 8169 | .ndo_bridge_getlink = i40e_ndo_bridge_getlink, |
| 8170 | .ndo_bridge_setlink = i40e_ndo_bridge_setlink, |
| 8171 | #endif /* HAVE_BRIDGE_ATTRIBS */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8172 | }; |
| 8173 | |
| 8174 | /** |
| 8175 | * i40e_config_netdev - Setup the netdev flags |
| 8176 | * @vsi: the VSI being configured |
| 8177 | * |
| 8178 | * Returns 0 on success, negative value on failure |
| 8179 | **/ |
| 8180 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 8181 | { |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 8182 | u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8183 | struct i40e_pf *pf = vsi->back; |
| 8184 | struct i40e_hw *hw = &pf->hw; |
| 8185 | struct i40e_netdev_priv *np; |
| 8186 | struct net_device *netdev; |
| 8187 | u8 mac_addr[ETH_ALEN]; |
| 8188 | int etherdev_size; |
| 8189 | |
| 8190 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8191 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8192 | if (!netdev) |
| 8193 | return -ENOMEM; |
| 8194 | |
| 8195 | vsi->netdev = netdev; |
| 8196 | np = netdev_priv(netdev); |
| 8197 | np->vsi = vsi; |
| 8198 | |
Or Gerlitz | d70e941 | 2014-03-18 10:36:45 +0200 | [diff] [blame] | 8199 | netdev->hw_enc_features |= NETIF_F_IP_CSUM | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8200 | NETIF_F_GSO_UDP_TUNNEL | |
Or Gerlitz | d70e941 | 2014-03-18 10:36:45 +0200 | [diff] [blame] | 8201 | NETIF_F_TSO; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8202 | |
| 8203 | netdev->features = NETIF_F_SG | |
| 8204 | NETIF_F_IP_CSUM | |
| 8205 | NETIF_F_SCTP_CSUM | |
| 8206 | NETIF_F_HIGHDMA | |
| 8207 | NETIF_F_GSO_UDP_TUNNEL | |
| 8208 | NETIF_F_HW_VLAN_CTAG_TX | |
| 8209 | NETIF_F_HW_VLAN_CTAG_RX | |
| 8210 | NETIF_F_HW_VLAN_CTAG_FILTER | |
| 8211 | NETIF_F_IPV6_CSUM | |
| 8212 | NETIF_F_TSO | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 8213 | NETIF_F_TSO_ECN | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8214 | NETIF_F_TSO6 | |
| 8215 | NETIF_F_RXCSUM | |
| 8216 | NETIF_F_RXHASH | |
| 8217 | 0; |
| 8218 | |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 8219 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 8220 | netdev->features |= NETIF_F_NTUPLE; |
| 8221 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8222 | /* copy netdev features into list of user selectable features */ |
| 8223 | netdev->hw_features |= netdev->features; |
| 8224 | |
| 8225 | if (vsi->type == I40E_VSI_MAIN) { |
| 8226 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 8227 | ether_addr_copy(mac_addr, hw->mac.perm_addr); |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 8228 | /* The following steps are necessary to prevent reception |
| 8229 | * of tagged packets - some older NVM configurations load a |
| 8230 | * default a MAC-VLAN filter that accepts any tagged packet |
| 8231 | * which must be replaced by a normal filter. |
Greg Rose | 8c27d42 | 2014-05-22 06:31:56 +0000 | [diff] [blame] | 8232 | */ |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 8233 | if (!i40e_rm_default_mac_filter(vsi, mac_addr)) |
| 8234 | i40e_add_filter(vsi, mac_addr, |
| 8235 | I40E_VLAN_ANY, false, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8236 | } else { |
| 8237 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ |
| 8238 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", |
| 8239 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 8240 | random_ether_addr(mac_addr); |
| 8241 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false); |
| 8242 | } |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 8243 | i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8244 | |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 8245 | ether_addr_copy(netdev->dev_addr, mac_addr); |
| 8246 | ether_addr_copy(netdev->perm_addr, mac_addr); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8247 | /* vlan gets same features (except vlan offload) |
| 8248 | * after any tweaks for specific VSI types |
| 8249 | */ |
| 8250 | netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX | |
| 8251 | NETIF_F_HW_VLAN_CTAG_RX | |
| 8252 | NETIF_F_HW_VLAN_CTAG_FILTER); |
| 8253 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 8254 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 8255 | /* Setup netdev TC information */ |
| 8256 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 8257 | |
| 8258 | netdev->netdev_ops = &i40e_netdev_ops; |
| 8259 | netdev->watchdog_timeo = 5 * HZ; |
| 8260 | i40e_set_ethtool_ops(netdev); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8261 | #ifdef I40E_FCOE |
| 8262 | i40e_fcoe_config_netdev(netdev, vsi); |
| 8263 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8264 | |
| 8265 | return 0; |
| 8266 | } |
| 8267 | |
| 8268 | /** |
| 8269 | * i40e_vsi_delete - Delete a VSI from the switch |
| 8270 | * @vsi: the VSI being removed |
| 8271 | * |
| 8272 | * Returns 0 on success, negative value on failure |
| 8273 | **/ |
| 8274 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 8275 | { |
| 8276 | /* remove default VSI is not allowed */ |
| 8277 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 8278 | return; |
| 8279 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8280 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8281 | } |
| 8282 | |
| 8283 | /** |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8284 | * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB |
| 8285 | * @vsi: the VSI being queried |
| 8286 | * |
| 8287 | * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode |
| 8288 | **/ |
| 8289 | int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi) |
| 8290 | { |
| 8291 | struct i40e_veb *veb; |
| 8292 | struct i40e_pf *pf = vsi->back; |
| 8293 | |
| 8294 | /* Uplink is not a bridge so default to VEB */ |
| 8295 | if (vsi->veb_idx == I40E_NO_VEB) |
| 8296 | return 1; |
| 8297 | |
| 8298 | veb = pf->veb[vsi->veb_idx]; |
| 8299 | /* Uplink is a bridge in VEPA mode */ |
| 8300 | if (veb && (veb->bridge_mode & BRIDGE_MODE_VEPA)) |
| 8301 | return 0; |
| 8302 | |
| 8303 | /* Uplink is a bridge in VEB mode */ |
| 8304 | return 1; |
| 8305 | } |
| 8306 | |
| 8307 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8308 | * i40e_add_vsi - Add a VSI to the switch |
| 8309 | * @vsi: the VSI being configured |
| 8310 | * |
| 8311 | * This initializes a VSI context depending on the VSI type to be added and |
| 8312 | * passes it down to the add_vsi aq command. |
| 8313 | **/ |
| 8314 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 8315 | { |
| 8316 | int ret = -ENODEV; |
| 8317 | struct i40e_mac_filter *f, *ftmp; |
| 8318 | struct i40e_pf *pf = vsi->back; |
| 8319 | struct i40e_hw *hw = &pf->hw; |
| 8320 | struct i40e_vsi_context ctxt; |
| 8321 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 8322 | int f_count = 0; |
| 8323 | |
| 8324 | memset(&ctxt, 0, sizeof(ctxt)); |
| 8325 | switch (vsi->type) { |
| 8326 | case I40E_VSI_MAIN: |
| 8327 | /* The PF's main VSI is already setup as part of the |
| 8328 | * device initialization, so we'll not bother with |
| 8329 | * the add_vsi call, but we will retrieve the current |
| 8330 | * VSI context. |
| 8331 | */ |
| 8332 | ctxt.seid = pf->main_vsi_seid; |
| 8333 | ctxt.pf_num = pf->hw.pf_id; |
| 8334 | ctxt.vf_num = 0; |
| 8335 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 8336 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 8337 | if (ret) { |
| 8338 | dev_info(&pf->pdev->dev, |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 8339 | "couldn't get PF vsi config, err %d, aq_err %d\n", |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8340 | ret, pf->hw.aq.asq_last_status); |
| 8341 | return -ENOENT; |
| 8342 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 8343 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8344 | vsi->info.valid_sections = 0; |
| 8345 | |
| 8346 | vsi->seid = ctxt.seid; |
| 8347 | vsi->id = ctxt.vsi_number; |
| 8348 | |
| 8349 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 8350 | |
| 8351 | /* MFP mode setup queue map and update VSI */ |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 8352 | if ((pf->flags & I40E_FLAG_MFP_ENABLED) && |
| 8353 | !(pf->hw.func_caps.iscsi)) { /* NIC type PF */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8354 | memset(&ctxt, 0, sizeof(ctxt)); |
| 8355 | ctxt.seid = pf->main_vsi_seid; |
| 8356 | ctxt.pf_num = pf->hw.pf_id; |
| 8357 | ctxt.vf_num = 0; |
| 8358 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 8359 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 8360 | if (ret) { |
| 8361 | dev_info(&pf->pdev->dev, |
| 8362 | "update vsi failed, aq_err=%d\n", |
| 8363 | pf->hw.aq.asq_last_status); |
| 8364 | ret = -ENOENT; |
| 8365 | goto err; |
| 8366 | } |
| 8367 | /* update the local VSI info queue map */ |
| 8368 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 8369 | vsi->info.valid_sections = 0; |
| 8370 | } else { |
| 8371 | /* Default/Main VSI is only enabled for TC0 |
| 8372 | * reconfigure it to enable all TCs that are |
| 8373 | * available on the port in SFP mode. |
Neerav Parikh | 63d7e5a | 2014-12-14 01:55:16 +0000 | [diff] [blame] | 8374 | * For MFP case the iSCSI PF would use this |
| 8375 | * flow to enable LAN+iSCSI TC. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8376 | */ |
| 8377 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 8378 | if (ret) { |
| 8379 | dev_info(&pf->pdev->dev, |
| 8380 | "failed to configure TCs for main VSI tc_map 0x%08x, err %d, aq_err %d\n", |
| 8381 | enabled_tc, ret, |
| 8382 | pf->hw.aq.asq_last_status); |
| 8383 | ret = -ENOENT; |
| 8384 | } |
| 8385 | } |
| 8386 | break; |
| 8387 | |
| 8388 | case I40E_VSI_FDIR: |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8389 | ctxt.pf_num = hw->pf_id; |
| 8390 | ctxt.vf_num = 0; |
| 8391 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 8392 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8393 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 8394 | if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) && |
| 8395 | (i40e_is_vsi_uplink_mode_veb(vsi))) { |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8396 | ctxt.info.valid_sections |= |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 8397 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8398 | ctxt.info.switch_id = |
Anjali Singhai Jain | fc60861 | 2015-05-08 15:35:57 -0700 | [diff] [blame] | 8399 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8400 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8401 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8402 | break; |
| 8403 | |
| 8404 | case I40E_VSI_VMDQ2: |
| 8405 | ctxt.pf_num = hw->pf_id; |
| 8406 | ctxt.vf_num = 0; |
| 8407 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 8408 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8409 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 8410 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8411 | /* This VSI is connected to VEB so the switch_id |
| 8412 | * should be set to zero by default. |
| 8413 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8414 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 8415 | ctxt.info.valid_sections |= |
| 8416 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 8417 | ctxt.info.switch_id = |
| 8418 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 8419 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8420 | |
| 8421 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 8422 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 8423 | break; |
| 8424 | |
| 8425 | case I40E_VSI_SRIOV: |
| 8426 | ctxt.pf_num = hw->pf_id; |
| 8427 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 8428 | ctxt.uplink_seid = vsi->uplink_seid; |
Neerav Parikh | 2b18e59 | 2015-01-24 09:58:38 +0000 | [diff] [blame] | 8429 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8430 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 8431 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8432 | /* This VSI is connected to VEB so the switch_id |
| 8433 | * should be set to zero by default. |
| 8434 | */ |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8435 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
| 8436 | ctxt.info.valid_sections |= |
| 8437 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 8438 | ctxt.info.switch_id = |
| 8439 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 8440 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8441 | |
| 8442 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 8443 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
Mitch Williams | c674d12 | 2014-05-20 08:01:40 +0000 | [diff] [blame] | 8444 | if (pf->vf[vsi->vf_id].spoofchk) { |
| 8445 | ctxt.info.valid_sections |= |
| 8446 | cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); |
| 8447 | ctxt.info.sec_flags |= |
| 8448 | (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | |
| 8449 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); |
| 8450 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8451 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 8452 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 8453 | break; |
| 8454 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8455 | #ifdef I40E_FCOE |
| 8456 | case I40E_VSI_FCOE: |
| 8457 | ret = i40e_fcoe_vsi_init(vsi, &ctxt); |
| 8458 | if (ret) { |
| 8459 | dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n"); |
| 8460 | return ret; |
| 8461 | } |
| 8462 | break; |
| 8463 | |
| 8464 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8465 | default: |
| 8466 | return -ENODEV; |
| 8467 | } |
| 8468 | |
| 8469 | if (vsi->type != I40E_VSI_MAIN) { |
| 8470 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 8471 | if (ret) { |
| 8472 | dev_info(&vsi->back->pdev->dev, |
| 8473 | "add vsi failed, aq_err=%d\n", |
| 8474 | vsi->back->hw.aq.asq_last_status); |
| 8475 | ret = -ENOENT; |
| 8476 | goto err; |
| 8477 | } |
Jesse Brandeburg | 1a2f624 | 2015-03-31 00:45:01 -0700 | [diff] [blame] | 8478 | vsi->info = ctxt.info; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8479 | vsi->info.valid_sections = 0; |
| 8480 | vsi->seid = ctxt.seid; |
| 8481 | vsi->id = ctxt.vsi_number; |
| 8482 | } |
| 8483 | |
| 8484 | /* If macvlan filters already exist, force them to get loaded */ |
| 8485 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 8486 | f->changed = true; |
| 8487 | f_count++; |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 8488 | |
| 8489 | if (f->is_laa && vsi->type == I40E_VSI_MAIN) { |
Shannon Nelson | 30650cc | 2014-07-29 04:01:50 +0000 | [diff] [blame] | 8490 | struct i40e_aqc_remove_macvlan_element_data element; |
| 8491 | |
| 8492 | memset(&element, 0, sizeof(element)); |
| 8493 | ether_addr_copy(element.mac_addr, f->macaddr); |
| 8494 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 8495 | ret = i40e_aq_remove_macvlan(hw, vsi->seid, |
| 8496 | &element, 1, NULL); |
| 8497 | if (ret) { |
| 8498 | /* some older FW has a different default */ |
| 8499 | element.flags |= |
| 8500 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
| 8501 | i40e_aq_remove_macvlan(hw, vsi->seid, |
| 8502 | &element, 1, NULL); |
| 8503 | } |
| 8504 | |
| 8505 | i40e_aq_mac_address_write(hw, |
Shannon Nelson | 6252c7e | 2014-06-04 01:23:23 +0000 | [diff] [blame] | 8506 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
| 8507 | f->macaddr, NULL); |
| 8508 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8509 | } |
| 8510 | if (f_count) { |
| 8511 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 8512 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 8513 | } |
| 8514 | |
| 8515 | /* Update VSI BW information */ |
| 8516 | ret = i40e_vsi_get_bw_info(vsi); |
| 8517 | if (ret) { |
| 8518 | dev_info(&pf->pdev->dev, |
| 8519 | "couldn't get vsi bw info, err %d, aq_err %d\n", |
| 8520 | ret, pf->hw.aq.asq_last_status); |
| 8521 | /* VSI is already added so not tearing that up */ |
| 8522 | ret = 0; |
| 8523 | } |
| 8524 | |
| 8525 | err: |
| 8526 | return ret; |
| 8527 | } |
| 8528 | |
| 8529 | /** |
| 8530 | * i40e_vsi_release - Delete a VSI and free its resources |
| 8531 | * @vsi: the VSI being removed |
| 8532 | * |
| 8533 | * Returns 0 on success or < 0 on error |
| 8534 | **/ |
| 8535 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 8536 | { |
| 8537 | struct i40e_mac_filter *f, *ftmp; |
| 8538 | struct i40e_veb *veb = NULL; |
| 8539 | struct i40e_pf *pf; |
| 8540 | u16 uplink_seid; |
| 8541 | int i, n; |
| 8542 | |
| 8543 | pf = vsi->back; |
| 8544 | |
| 8545 | /* release of a VEB-owner or last VSI is not allowed */ |
| 8546 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 8547 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 8548 | vsi->seid, vsi->uplink_seid); |
| 8549 | return -ENODEV; |
| 8550 | } |
| 8551 | if (vsi == pf->vsi[pf->lan_vsi] && |
| 8552 | !test_bit(__I40E_DOWN, &pf->state)) { |
| 8553 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 8554 | return -ENODEV; |
| 8555 | } |
| 8556 | |
| 8557 | uplink_seid = vsi->uplink_seid; |
| 8558 | if (vsi->type != I40E_VSI_SRIOV) { |
| 8559 | if (vsi->netdev_registered) { |
| 8560 | vsi->netdev_registered = false; |
| 8561 | if (vsi->netdev) { |
| 8562 | /* results in a call to i40e_close() */ |
| 8563 | unregister_netdev(vsi->netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8564 | } |
| 8565 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 8566 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8567 | } |
| 8568 | i40e_vsi_disable_irq(vsi); |
| 8569 | } |
| 8570 | |
| 8571 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) |
| 8572 | i40e_del_filter(vsi, f->macaddr, f->vlan, |
| 8573 | f->is_vf, f->is_netdev); |
| 8574 | i40e_sync_vsi_filters(vsi); |
| 8575 | |
| 8576 | i40e_vsi_delete(vsi); |
| 8577 | i40e_vsi_free_q_vectors(vsi); |
Shannon Nelson | a486659 | 2014-02-11 08:24:07 +0000 | [diff] [blame] | 8578 | if (vsi->netdev) { |
| 8579 | free_netdev(vsi->netdev); |
| 8580 | vsi->netdev = NULL; |
| 8581 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8582 | i40e_vsi_clear_rings(vsi); |
| 8583 | i40e_vsi_clear(vsi); |
| 8584 | |
| 8585 | /* If this was the last thing on the VEB, except for the |
| 8586 | * controlling VSI, remove the VEB, which puts the controlling |
| 8587 | * VSI onto the next level down in the switch. |
| 8588 | * |
| 8589 | * Well, okay, there's one more exception here: don't remove |
| 8590 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 8591 | * from up the network stack. |
| 8592 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 8593 | for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8594 | if (pf->vsi[i] && |
| 8595 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 8596 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 8597 | n++; /* count the VSIs */ |
| 8598 | } |
| 8599 | } |
| 8600 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 8601 | if (!pf->veb[i]) |
| 8602 | continue; |
| 8603 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 8604 | n++; /* count the VEBs */ |
| 8605 | if (pf->veb[i]->seid == uplink_seid) |
| 8606 | veb = pf->veb[i]; |
| 8607 | } |
| 8608 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 8609 | i40e_veb_release(veb); |
| 8610 | |
| 8611 | return 0; |
| 8612 | } |
| 8613 | |
| 8614 | /** |
| 8615 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 8616 | * @vsi: ptr to the VSI |
| 8617 | * |
| 8618 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 8619 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 8620 | * newly allocated VSI. |
| 8621 | * |
| 8622 | * Returns 0 on success or negative on failure |
| 8623 | **/ |
| 8624 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 8625 | { |
| 8626 | int ret = -ENOENT; |
| 8627 | struct i40e_pf *pf = vsi->back; |
| 8628 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 8629 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8630 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 8631 | vsi->seid); |
| 8632 | return -EEXIST; |
| 8633 | } |
| 8634 | |
| 8635 | if (vsi->base_vector) { |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 8636 | 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] | 8637 | vsi->seid, vsi->base_vector); |
| 8638 | return -EEXIST; |
| 8639 | } |
| 8640 | |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 8641 | ret = i40e_vsi_alloc_q_vectors(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8642 | if (ret) { |
| 8643 | dev_info(&pf->pdev->dev, |
| 8644 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 8645 | vsi->num_q_vectors, vsi->seid, ret); |
| 8646 | vsi->num_q_vectors = 0; |
| 8647 | goto vector_setup_out; |
| 8648 | } |
| 8649 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 8650 | if (vsi->num_q_vectors) |
| 8651 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 8652 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8653 | if (vsi->base_vector < 0) { |
| 8654 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 8655 | "failed to get tracking for %d vectors for VSI %d, err=%d\n", |
| 8656 | vsi->num_q_vectors, vsi->seid, vsi->base_vector); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8657 | i40e_vsi_free_q_vectors(vsi); |
| 8658 | ret = -ENOENT; |
| 8659 | goto vector_setup_out; |
| 8660 | } |
| 8661 | |
| 8662 | vector_setup_out: |
| 8663 | return ret; |
| 8664 | } |
| 8665 | |
| 8666 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 8667 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 8668 | * @vsi: pointer to the vsi. |
| 8669 | * |
| 8670 | * This re-allocates a vsi's queue resources. |
| 8671 | * |
| 8672 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 8673 | * on success, otherwise returns NULL on failure. |
| 8674 | **/ |
| 8675 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 8676 | { |
| 8677 | struct i40e_pf *pf = vsi->back; |
| 8678 | u8 enabled_tc; |
| 8679 | int ret; |
| 8680 | |
| 8681 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 8682 | i40e_vsi_clear_rings(vsi); |
| 8683 | |
| 8684 | i40e_vsi_free_arrays(vsi, false); |
| 8685 | i40e_set_num_rings_in_vsi(vsi); |
| 8686 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 8687 | if (ret) |
| 8688 | goto err_vsi; |
| 8689 | |
| 8690 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 8691 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 8692 | dev_info(&pf->pdev->dev, |
| 8693 | "failed to get tracking for %d queues for VSI %d err=%d\n", |
| 8694 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 8695 | goto err_vsi; |
| 8696 | } |
| 8697 | vsi->base_queue = ret; |
| 8698 | |
| 8699 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 8700 | * layout configurations. |
| 8701 | */ |
| 8702 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 8703 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 8704 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 8705 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 8706 | |
| 8707 | /* assign it some queues */ |
| 8708 | ret = i40e_alloc_rings(vsi); |
| 8709 | if (ret) |
| 8710 | goto err_rings; |
| 8711 | |
| 8712 | /* map all of the rings to the q_vectors */ |
| 8713 | i40e_vsi_map_rings_to_vectors(vsi); |
| 8714 | return vsi; |
| 8715 | |
| 8716 | err_rings: |
| 8717 | i40e_vsi_free_q_vectors(vsi); |
| 8718 | if (vsi->netdev_registered) { |
| 8719 | vsi->netdev_registered = false; |
| 8720 | unregister_netdev(vsi->netdev); |
| 8721 | free_netdev(vsi->netdev); |
| 8722 | vsi->netdev = NULL; |
| 8723 | } |
| 8724 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 8725 | err_vsi: |
| 8726 | i40e_vsi_clear(vsi); |
| 8727 | return NULL; |
| 8728 | } |
| 8729 | |
| 8730 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8731 | * i40e_vsi_setup - Set up a VSI by a given type |
| 8732 | * @pf: board private structure |
| 8733 | * @type: VSI type |
| 8734 | * @uplink_seid: the switch element to link to |
| 8735 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 8736 | * |
| 8737 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 8738 | * to the identified VEB. |
| 8739 | * |
| 8740 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 8741 | * success, otherwise returns NULL on failure. |
| 8742 | **/ |
| 8743 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 8744 | u16 uplink_seid, u32 param1) |
| 8745 | { |
| 8746 | struct i40e_vsi *vsi = NULL; |
| 8747 | struct i40e_veb *veb = NULL; |
| 8748 | int ret, i; |
| 8749 | int v_idx; |
| 8750 | |
| 8751 | /* The requested uplink_seid must be either |
| 8752 | * - the PF's port seid |
| 8753 | * no VEB is needed because this is the PF |
| 8754 | * or this is a Flow Director special case VSI |
| 8755 | * - seid of an existing VEB |
| 8756 | * - seid of a VSI that owns an existing VEB |
| 8757 | * - seid of a VSI that doesn't own a VEB |
| 8758 | * a new VEB is created and the VSI becomes the owner |
| 8759 | * - seid of the PF VSI, which is what creates the first VEB |
| 8760 | * this is a special case of the previous |
| 8761 | * |
| 8762 | * Find which uplink_seid we were given and create a new VEB if needed |
| 8763 | */ |
| 8764 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 8765 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 8766 | veb = pf->veb[i]; |
| 8767 | break; |
| 8768 | } |
| 8769 | } |
| 8770 | |
| 8771 | if (!veb && uplink_seid != pf->mac_seid) { |
| 8772 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 8773 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8774 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 8775 | vsi = pf->vsi[i]; |
| 8776 | break; |
| 8777 | } |
| 8778 | } |
| 8779 | if (!vsi) { |
| 8780 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 8781 | uplink_seid); |
| 8782 | return NULL; |
| 8783 | } |
| 8784 | |
| 8785 | if (vsi->uplink_seid == pf->mac_seid) |
| 8786 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 8787 | vsi->tc_config.enabled_tc); |
| 8788 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 8789 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 8790 | vsi->tc_config.enabled_tc); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 8791 | if (veb) { |
| 8792 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) { |
| 8793 | dev_info(&vsi->back->pdev->dev, |
| 8794 | "%s: New VSI creation error, uplink seid of LAN VSI expected.\n", |
| 8795 | __func__); |
| 8796 | return NULL; |
| 8797 | } |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 8798 | /* We come up by default in VEPA mode if SRIOV is not |
| 8799 | * already enabled, in which case we can't force VEPA |
| 8800 | * mode. |
| 8801 | */ |
| 8802 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { |
| 8803 | veb->bridge_mode = BRIDGE_MODE_VEPA; |
| 8804 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; |
| 8805 | } |
Neerav Parikh | 5161601 | 2015-02-06 08:52:14 +0000 | [diff] [blame] | 8806 | i40e_config_bridge_mode(veb); |
Anjali Singhai Jain | 79c21a8 | 2014-11-13 03:06:14 +0000 | [diff] [blame] | 8807 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8808 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 8809 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 8810 | veb = pf->veb[i]; |
| 8811 | } |
| 8812 | if (!veb) { |
| 8813 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 8814 | return NULL; |
| 8815 | } |
| 8816 | |
| 8817 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 8818 | uplink_seid = veb->seid; |
| 8819 | } |
| 8820 | |
| 8821 | /* get vsi sw struct */ |
| 8822 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 8823 | if (v_idx < 0) |
| 8824 | goto err_alloc; |
| 8825 | vsi = pf->vsi[v_idx]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8826 | if (!vsi) |
| 8827 | goto err_alloc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8828 | vsi->type = type; |
| 8829 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 8830 | |
| 8831 | if (type == I40E_VSI_MAIN) |
| 8832 | pf->lan_vsi = v_idx; |
| 8833 | else if (type == I40E_VSI_SRIOV) |
| 8834 | vsi->vf_id = param1; |
| 8835 | /* assign it some queues */ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8836 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, |
| 8837 | vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8838 | if (ret < 0) { |
Shannon Nelson | 049a2be | 2014-10-17 03:14:50 +0000 | [diff] [blame] | 8839 | dev_info(&pf->pdev->dev, |
| 8840 | "failed to get tracking for %d queues for VSI %d err=%d\n", |
| 8841 | vsi->alloc_queue_pairs, vsi->seid, ret); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8842 | goto err_vsi; |
| 8843 | } |
| 8844 | vsi->base_queue = ret; |
| 8845 | |
| 8846 | /* get a VSI from the hardware */ |
| 8847 | vsi->uplink_seid = uplink_seid; |
| 8848 | ret = i40e_add_vsi(vsi); |
| 8849 | if (ret) |
| 8850 | goto err_vsi; |
| 8851 | |
| 8852 | switch (vsi->type) { |
| 8853 | /* setup the netdev if needed */ |
| 8854 | case I40E_VSI_MAIN: |
| 8855 | case I40E_VSI_VMDQ2: |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 8856 | case I40E_VSI_FCOE: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8857 | ret = i40e_config_netdev(vsi); |
| 8858 | if (ret) |
| 8859 | goto err_netdev; |
| 8860 | ret = register_netdev(vsi->netdev); |
| 8861 | if (ret) |
| 8862 | goto err_netdev; |
| 8863 | vsi->netdev_registered = true; |
| 8864 | netif_carrier_off(vsi->netdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 8865 | #ifdef CONFIG_I40E_DCB |
| 8866 | /* Setup DCB netlink interface */ |
| 8867 | i40e_dcbnl_setup(vsi); |
| 8868 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8869 | /* fall through */ |
| 8870 | |
| 8871 | case I40E_VSI_FDIR: |
| 8872 | /* set up vectors and rings if needed */ |
| 8873 | ret = i40e_vsi_setup_vectors(vsi); |
| 8874 | if (ret) |
| 8875 | goto err_msix; |
| 8876 | |
| 8877 | ret = i40e_alloc_rings(vsi); |
| 8878 | if (ret) |
| 8879 | goto err_rings; |
| 8880 | |
| 8881 | /* map all of the rings to the q_vectors */ |
| 8882 | i40e_vsi_map_rings_to_vectors(vsi); |
| 8883 | |
| 8884 | i40e_vsi_reset_stats(vsi); |
| 8885 | break; |
| 8886 | |
| 8887 | default: |
| 8888 | /* no netdev or rings for the other VSI types */ |
| 8889 | break; |
| 8890 | } |
| 8891 | |
| 8892 | return vsi; |
| 8893 | |
| 8894 | err_rings: |
| 8895 | i40e_vsi_free_q_vectors(vsi); |
| 8896 | err_msix: |
| 8897 | if (vsi->netdev_registered) { |
| 8898 | vsi->netdev_registered = false; |
| 8899 | unregister_netdev(vsi->netdev); |
| 8900 | free_netdev(vsi->netdev); |
| 8901 | vsi->netdev = NULL; |
| 8902 | } |
| 8903 | err_netdev: |
| 8904 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 8905 | err_vsi: |
| 8906 | i40e_vsi_clear(vsi); |
| 8907 | err_alloc: |
| 8908 | return NULL; |
| 8909 | } |
| 8910 | |
| 8911 | /** |
| 8912 | * i40e_veb_get_bw_info - Query VEB BW information |
| 8913 | * @veb: the veb to query |
| 8914 | * |
| 8915 | * Query the Tx scheduler BW configuration data for given VEB |
| 8916 | **/ |
| 8917 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 8918 | { |
| 8919 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 8920 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 8921 | struct i40e_pf *pf = veb->pf; |
| 8922 | struct i40e_hw *hw = &pf->hw; |
| 8923 | u32 tc_bw_max; |
| 8924 | int ret = 0; |
| 8925 | int i; |
| 8926 | |
| 8927 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 8928 | &bw_data, NULL); |
| 8929 | if (ret) { |
| 8930 | dev_info(&pf->pdev->dev, |
| 8931 | "query veb bw config failed, aq_err=%d\n", |
| 8932 | hw->aq.asq_last_status); |
| 8933 | goto out; |
| 8934 | } |
| 8935 | |
| 8936 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 8937 | &ets_data, NULL); |
| 8938 | if (ret) { |
| 8939 | dev_info(&pf->pdev->dev, |
| 8940 | "query veb bw ets config failed, aq_err=%d\n", |
| 8941 | hw->aq.asq_last_status); |
| 8942 | goto out; |
| 8943 | } |
| 8944 | |
| 8945 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 8946 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 8947 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
Neerav Parikh | 23cd1f0 | 2014-11-12 00:18:41 +0000 | [diff] [blame] | 8948 | veb->enabled_tc = ets_data.tc_valid_bits; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8949 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 8950 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 8951 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 8952 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 8953 | veb->bw_tc_limit_credits[i] = |
| 8954 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 8955 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 8956 | } |
| 8957 | |
| 8958 | out: |
| 8959 | return ret; |
| 8960 | } |
| 8961 | |
| 8962 | /** |
| 8963 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 8964 | * @pf: board private structure |
| 8965 | * |
| 8966 | * On error: returns error code (negative) |
| 8967 | * On success: returns vsi index in PF (positive) |
| 8968 | **/ |
| 8969 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 8970 | { |
| 8971 | int ret = -ENOENT; |
| 8972 | struct i40e_veb *veb; |
| 8973 | int i; |
| 8974 | |
| 8975 | /* Need to protect the allocation of switch elements at the PF level */ |
| 8976 | mutex_lock(&pf->switch_mutex); |
| 8977 | |
| 8978 | /* VEB list may be fragmented if VEB creation/destruction has |
| 8979 | * been happening. We can afford to do a quick scan to look |
| 8980 | * for any free slots in the list. |
| 8981 | * |
| 8982 | * find next empty veb slot, looping back around if necessary |
| 8983 | */ |
| 8984 | i = 0; |
| 8985 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 8986 | i++; |
| 8987 | if (i >= I40E_MAX_VEB) { |
| 8988 | ret = -ENOMEM; |
| 8989 | goto err_alloc_veb; /* out of VEB slots! */ |
| 8990 | } |
| 8991 | |
| 8992 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 8993 | if (!veb) { |
| 8994 | ret = -ENOMEM; |
| 8995 | goto err_alloc_veb; |
| 8996 | } |
| 8997 | veb->pf = pf; |
| 8998 | veb->idx = i; |
| 8999 | veb->enabled_tc = 1; |
| 9000 | |
| 9001 | pf->veb[i] = veb; |
| 9002 | ret = i; |
| 9003 | err_alloc_veb: |
| 9004 | mutex_unlock(&pf->switch_mutex); |
| 9005 | return ret; |
| 9006 | } |
| 9007 | |
| 9008 | /** |
| 9009 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 9010 | * @branch: where to start deleting |
| 9011 | * |
| 9012 | * This uses recursion to find the tips of the branch to be |
| 9013 | * removed, deleting until we get back to and can delete this VEB. |
| 9014 | **/ |
| 9015 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 9016 | { |
| 9017 | struct i40e_pf *pf = branch->pf; |
| 9018 | u16 branch_seid = branch->seid; |
| 9019 | u16 veb_idx = branch->idx; |
| 9020 | int i; |
| 9021 | |
| 9022 | /* release any VEBs on this VEB - RECURSION */ |
| 9023 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 9024 | if (!pf->veb[i]) |
| 9025 | continue; |
| 9026 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 9027 | i40e_switch_branch_release(pf->veb[i]); |
| 9028 | } |
| 9029 | |
| 9030 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 9031 | * |
| 9032 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 9033 | * the VEB itself, so don't use (*branch) after this loop. |
| 9034 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9035 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9036 | if (!pf->vsi[i]) |
| 9037 | continue; |
| 9038 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 9039 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 9040 | i40e_vsi_release(pf->vsi[i]); |
| 9041 | } |
| 9042 | } |
| 9043 | |
| 9044 | /* There's one corner case where the VEB might not have been |
| 9045 | * removed, so double check it here and remove it if needed. |
| 9046 | * This case happens if the veb was created from the debugfs |
| 9047 | * commands and no VSIs were added to it. |
| 9048 | */ |
| 9049 | if (pf->veb[veb_idx]) |
| 9050 | i40e_veb_release(pf->veb[veb_idx]); |
| 9051 | } |
| 9052 | |
| 9053 | /** |
| 9054 | * i40e_veb_clear - remove veb struct |
| 9055 | * @veb: the veb to remove |
| 9056 | **/ |
| 9057 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 9058 | { |
| 9059 | if (!veb) |
| 9060 | return; |
| 9061 | |
| 9062 | if (veb->pf) { |
| 9063 | struct i40e_pf *pf = veb->pf; |
| 9064 | |
| 9065 | mutex_lock(&pf->switch_mutex); |
| 9066 | if (pf->veb[veb->idx] == veb) |
| 9067 | pf->veb[veb->idx] = NULL; |
| 9068 | mutex_unlock(&pf->switch_mutex); |
| 9069 | } |
| 9070 | |
| 9071 | kfree(veb); |
| 9072 | } |
| 9073 | |
| 9074 | /** |
| 9075 | * i40e_veb_release - Delete a VEB and free its resources |
| 9076 | * @veb: the VEB being removed |
| 9077 | **/ |
| 9078 | void i40e_veb_release(struct i40e_veb *veb) |
| 9079 | { |
| 9080 | struct i40e_vsi *vsi = NULL; |
| 9081 | struct i40e_pf *pf; |
| 9082 | int i, n = 0; |
| 9083 | |
| 9084 | pf = veb->pf; |
| 9085 | |
| 9086 | /* find the remaining VSI and check for extras */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9087 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9088 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 9089 | n++; |
| 9090 | vsi = pf->vsi[i]; |
| 9091 | } |
| 9092 | } |
| 9093 | if (n != 1) { |
| 9094 | dev_info(&pf->pdev->dev, |
| 9095 | "can't remove VEB %d with %d VSIs left\n", |
| 9096 | veb->seid, n); |
| 9097 | return; |
| 9098 | } |
| 9099 | |
| 9100 | /* move the remaining VSI to uplink veb */ |
| 9101 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 9102 | if (veb->uplink_seid) { |
| 9103 | vsi->uplink_seid = veb->uplink_seid; |
| 9104 | if (veb->uplink_seid == pf->mac_seid) |
| 9105 | vsi->veb_idx = I40E_NO_VEB; |
| 9106 | else |
| 9107 | vsi->veb_idx = veb->veb_idx; |
| 9108 | } else { |
| 9109 | /* floating VEB */ |
| 9110 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 9111 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 9112 | } |
| 9113 | |
| 9114 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 9115 | i40e_veb_clear(veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9116 | } |
| 9117 | |
| 9118 | /** |
| 9119 | * i40e_add_veb - create the VEB in the switch |
| 9120 | * @veb: the VEB to be instantiated |
| 9121 | * @vsi: the controlling VSI |
| 9122 | **/ |
| 9123 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 9124 | { |
Greg Rose | 5674726 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 9125 | bool is_default = false; |
Kevin Scott | e1c51b95 | 2013-11-20 10:02:51 +0000 | [diff] [blame] | 9126 | bool is_cloud = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9127 | int ret; |
| 9128 | |
| 9129 | /* get a VEB from the hardware */ |
| 9130 | ret = i40e_aq_add_veb(&veb->pf->hw, veb->uplink_seid, vsi->seid, |
Kevin Scott | e1c51b95 | 2013-11-20 10:02:51 +0000 | [diff] [blame] | 9131 | veb->enabled_tc, is_default, |
| 9132 | is_cloud, &veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9133 | if (ret) { |
| 9134 | dev_info(&veb->pf->pdev->dev, |
| 9135 | "couldn't add VEB, err %d, aq_err %d\n", |
| 9136 | ret, veb->pf->hw.aq.asq_last_status); |
| 9137 | return -EPERM; |
| 9138 | } |
| 9139 | |
| 9140 | /* get statistics counter */ |
| 9141 | ret = i40e_aq_get_veb_parameters(&veb->pf->hw, veb->seid, NULL, NULL, |
| 9142 | &veb->stats_idx, NULL, NULL, NULL); |
| 9143 | if (ret) { |
| 9144 | dev_info(&veb->pf->pdev->dev, |
| 9145 | "couldn't get VEB statistics idx, err %d, aq_err %d\n", |
| 9146 | ret, veb->pf->hw.aq.asq_last_status); |
| 9147 | return -EPERM; |
| 9148 | } |
| 9149 | ret = i40e_veb_get_bw_info(veb); |
| 9150 | if (ret) { |
| 9151 | dev_info(&veb->pf->pdev->dev, |
| 9152 | "couldn't get VEB bw info, err %d, aq_err %d\n", |
| 9153 | ret, veb->pf->hw.aq.asq_last_status); |
| 9154 | i40e_aq_delete_element(&veb->pf->hw, veb->seid, NULL); |
| 9155 | return -ENOENT; |
| 9156 | } |
| 9157 | |
| 9158 | vsi->uplink_seid = veb->seid; |
| 9159 | vsi->veb_idx = veb->idx; |
| 9160 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 9161 | |
| 9162 | return 0; |
| 9163 | } |
| 9164 | |
| 9165 | /** |
| 9166 | * i40e_veb_setup - Set up a VEB |
| 9167 | * @pf: board private structure |
| 9168 | * @flags: VEB setup flags |
| 9169 | * @uplink_seid: the switch element to link to |
| 9170 | * @vsi_seid: the initial VSI seid |
| 9171 | * @enabled_tc: Enabled TC bit-map |
| 9172 | * |
| 9173 | * This allocates the sw VEB structure and links it into the switch |
| 9174 | * It is possible and legal for this to be a duplicate of an already |
| 9175 | * existing VEB. It is also possible for both uplink and vsi seids |
| 9176 | * to be zero, in order to create a floating VEB. |
| 9177 | * |
| 9178 | * Returns pointer to the successfully allocated VEB sw struct on |
| 9179 | * success, otherwise returns NULL on failure. |
| 9180 | **/ |
| 9181 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 9182 | u16 uplink_seid, u16 vsi_seid, |
| 9183 | u8 enabled_tc) |
| 9184 | { |
| 9185 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 9186 | int vsi_idx, veb_idx; |
| 9187 | int ret; |
| 9188 | |
| 9189 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 9190 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 9191 | (uplink_seid + vsi_seid != 0)) { |
| 9192 | dev_info(&pf->pdev->dev, |
| 9193 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 9194 | uplink_seid, vsi_seid); |
| 9195 | return NULL; |
| 9196 | } |
| 9197 | |
| 9198 | /* make sure there is such a vsi and uplink */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9199 | for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9200 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 9201 | break; |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9202 | if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9203 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 9204 | vsi_seid); |
| 9205 | return NULL; |
| 9206 | } |
| 9207 | |
| 9208 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 9209 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 9210 | if (pf->veb[veb_idx] && |
| 9211 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 9212 | uplink_veb = pf->veb[veb_idx]; |
| 9213 | break; |
| 9214 | } |
| 9215 | } |
| 9216 | if (!uplink_veb) { |
| 9217 | dev_info(&pf->pdev->dev, |
| 9218 | "uplink seid %d not found\n", uplink_seid); |
| 9219 | return NULL; |
| 9220 | } |
| 9221 | } |
| 9222 | |
| 9223 | /* get veb sw struct */ |
| 9224 | veb_idx = i40e_veb_mem_alloc(pf); |
| 9225 | if (veb_idx < 0) |
| 9226 | goto err_alloc; |
| 9227 | veb = pf->veb[veb_idx]; |
| 9228 | veb->flags = flags; |
| 9229 | veb->uplink_seid = uplink_seid; |
| 9230 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 9231 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 9232 | |
| 9233 | /* create the VEB in the switch */ |
| 9234 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 9235 | if (ret) |
| 9236 | goto err_veb; |
Shannon Nelson | 1bb8b93 | 2014-04-23 04:49:54 +0000 | [diff] [blame] | 9237 | if (vsi_idx == pf->lan_vsi) |
| 9238 | pf->lan_veb = veb->idx; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9239 | |
| 9240 | return veb; |
| 9241 | |
| 9242 | err_veb: |
| 9243 | i40e_veb_clear(veb); |
| 9244 | err_alloc: |
| 9245 | return NULL; |
| 9246 | } |
| 9247 | |
| 9248 | /** |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 9249 | * i40e_setup_pf_switch_element - set PF vars based on switch type |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9250 | * @pf: board private structure |
| 9251 | * @ele: element we are building info from |
| 9252 | * @num_reported: total number of elements |
| 9253 | * @printconfig: should we print the contents |
| 9254 | * |
| 9255 | * helper function to assist in extracting a few useful SEID values. |
| 9256 | **/ |
| 9257 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 9258 | struct i40e_aqc_switch_config_element_resp *ele, |
| 9259 | u16 num_reported, bool printconfig) |
| 9260 | { |
| 9261 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 9262 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 9263 | u8 element_type = ele->element_type; |
| 9264 | u16 seid = le16_to_cpu(ele->seid); |
| 9265 | |
| 9266 | if (printconfig) |
| 9267 | dev_info(&pf->pdev->dev, |
| 9268 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 9269 | element_type, seid, uplink_seid, downlink_seid); |
| 9270 | |
| 9271 | switch (element_type) { |
| 9272 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 9273 | pf->mac_seid = seid; |
| 9274 | break; |
| 9275 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 9276 | /* Main VEB? */ |
| 9277 | if (uplink_seid != pf->mac_seid) |
| 9278 | break; |
| 9279 | if (pf->lan_veb == I40E_NO_VEB) { |
| 9280 | int v; |
| 9281 | |
| 9282 | /* find existing or else empty VEB */ |
| 9283 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 9284 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 9285 | pf->lan_veb = v; |
| 9286 | break; |
| 9287 | } |
| 9288 | } |
| 9289 | if (pf->lan_veb == I40E_NO_VEB) { |
| 9290 | v = i40e_veb_mem_alloc(pf); |
| 9291 | if (v < 0) |
| 9292 | break; |
| 9293 | pf->lan_veb = v; |
| 9294 | } |
| 9295 | } |
| 9296 | |
| 9297 | pf->veb[pf->lan_veb]->seid = seid; |
| 9298 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 9299 | pf->veb[pf->lan_veb]->pf = pf; |
| 9300 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 9301 | break; |
| 9302 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 9303 | if (num_reported != 1) |
| 9304 | break; |
| 9305 | /* This is immediately after a reset so we can assume this is |
| 9306 | * the PF's VSI |
| 9307 | */ |
| 9308 | pf->mac_seid = uplink_seid; |
| 9309 | pf->pf_seid = downlink_seid; |
| 9310 | pf->main_vsi_seid = seid; |
| 9311 | if (printconfig) |
| 9312 | dev_info(&pf->pdev->dev, |
| 9313 | "pf_seid=%d main_vsi_seid=%d\n", |
| 9314 | pf->pf_seid, pf->main_vsi_seid); |
| 9315 | break; |
| 9316 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 9317 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 9318 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 9319 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 9320 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 9321 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 9322 | /* ignore these for now */ |
| 9323 | break; |
| 9324 | default: |
| 9325 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 9326 | element_type, seid); |
| 9327 | break; |
| 9328 | } |
| 9329 | } |
| 9330 | |
| 9331 | /** |
| 9332 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 9333 | * @pf: board private structure |
| 9334 | * @printconfig: should we print the contents |
| 9335 | * |
| 9336 | * Get the current switch configuration from the device and |
| 9337 | * extract a few useful SEID values. |
| 9338 | **/ |
| 9339 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 9340 | { |
| 9341 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 9342 | u16 next_seid = 0; |
| 9343 | int ret = 0; |
| 9344 | u8 *aq_buf; |
| 9345 | int i; |
| 9346 | |
| 9347 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 9348 | if (!aq_buf) |
| 9349 | return -ENOMEM; |
| 9350 | |
| 9351 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 9352 | do { |
| 9353 | u16 num_reported, num_total; |
| 9354 | |
| 9355 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 9356 | I40E_AQ_LARGE_BUF, |
| 9357 | &next_seid, NULL); |
| 9358 | if (ret) { |
| 9359 | dev_info(&pf->pdev->dev, |
| 9360 | "get switch config failed %d aq_err=%x\n", |
| 9361 | ret, pf->hw.aq.asq_last_status); |
| 9362 | kfree(aq_buf); |
| 9363 | return -ENOENT; |
| 9364 | } |
| 9365 | |
| 9366 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 9367 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 9368 | |
| 9369 | if (printconfig) |
| 9370 | dev_info(&pf->pdev->dev, |
| 9371 | "header: %d reported %d total\n", |
| 9372 | num_reported, num_total); |
| 9373 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9374 | for (i = 0; i < num_reported; i++) { |
| 9375 | struct i40e_aqc_switch_config_element_resp *ele = |
| 9376 | &sw_config->element[i]; |
| 9377 | |
| 9378 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 9379 | printconfig); |
| 9380 | } |
| 9381 | } while (next_seid != 0); |
| 9382 | |
| 9383 | kfree(aq_buf); |
| 9384 | return ret; |
| 9385 | } |
| 9386 | |
| 9387 | /** |
| 9388 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 9389 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9390 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9391 | * |
| 9392 | * Returns 0 on success, negative value on failure |
| 9393 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9394 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9395 | { |
| 9396 | int ret; |
| 9397 | |
| 9398 | /* find out what's out there already */ |
| 9399 | ret = i40e_fetch_switch_configuration(pf, false); |
| 9400 | if (ret) { |
| 9401 | dev_info(&pf->pdev->dev, |
| 9402 | "couldn't fetch switch config, err %d, aq_err %d\n", |
| 9403 | ret, pf->hw.aq.asq_last_status); |
| 9404 | return ret; |
| 9405 | } |
| 9406 | i40e_pf_reset_stats(pf); |
| 9407 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9408 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9409 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9410 | struct i40e_vsi *vsi = NULL; |
| 9411 | u16 uplink_seid; |
| 9412 | |
| 9413 | /* Set up the PF VSI associated with the PF's main VSI |
| 9414 | * that is already in the HW switch |
| 9415 | */ |
| 9416 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 9417 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 9418 | else |
| 9419 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9420 | if (pf->lan_vsi == I40E_NO_VSI) |
| 9421 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 9422 | else if (reinit) |
| 9423 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9424 | if (!vsi) { |
| 9425 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 9426 | i40e_fdir_teardown(pf); |
| 9427 | return -EAGAIN; |
| 9428 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9429 | } else { |
| 9430 | /* force a reset of TC and queue layout configurations */ |
| 9431 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 9432 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 9433 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 9434 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 9435 | } |
| 9436 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 9437 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9438 | i40e_fdir_sb_setup(pf); |
| 9439 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9440 | /* Setup static PF queue filter control settings */ |
| 9441 | ret = i40e_setup_pf_filter_control(pf); |
| 9442 | if (ret) { |
| 9443 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 9444 | ret); |
| 9445 | /* Failure here should not stop continuing other steps */ |
| 9446 | } |
| 9447 | |
| 9448 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 9449 | * the hash |
| 9450 | */ |
| 9451 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 9452 | i40e_config_rss(pf); |
| 9453 | |
| 9454 | /* fill in link information and enable LSE reporting */ |
Catherine Sullivan | 21af70f | 2015-01-24 09:58:41 +0000 | [diff] [blame] | 9455 | i40e_aq_get_link_info(&pf->hw, true, NULL, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9456 | i40e_link_event(pf); |
| 9457 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 9458 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9459 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 9460 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 9461 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 9462 | i40e_ptp_init(pf); |
| 9463 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9464 | return ret; |
| 9465 | } |
| 9466 | |
| 9467 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9468 | * i40e_determine_queue_usage - Work out queue distribution |
| 9469 | * @pf: board private structure |
| 9470 | **/ |
| 9471 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 9472 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9473 | int queues_left; |
| 9474 | |
| 9475 | pf->num_lan_qps = 0; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9476 | #ifdef I40E_FCOE |
| 9477 | pf->num_fcoe_qps = 0; |
| 9478 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9479 | |
| 9480 | /* Find the max queues to be put into basic use. We'll always be |
| 9481 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 9482 | * big RSS set. |
| 9483 | */ |
| 9484 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 9485 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9486 | if ((queues_left == 1) || |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 9487 | !(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9488 | /* one qp for PF, no queues for anything else */ |
| 9489 | queues_left = 0; |
| 9490 | pf->rss_size = pf->num_lan_qps = 1; |
| 9491 | |
| 9492 | /* make sure all the fancies are disabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 9493 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9494 | #ifdef I40E_FCOE |
| 9495 | I40E_FLAG_FCOE_ENABLED | |
| 9496 | #endif |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 9497 | I40E_FLAG_FD_SB_ENABLED | |
| 9498 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 9499 | I40E_FLAG_DCB_CAPABLE | |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 9500 | I40E_FLAG_SRIOV_ENABLED | |
| 9501 | I40E_FLAG_VMDQ_ENABLED); |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 9502 | } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 9503 | I40E_FLAG_FD_SB_ENABLED | |
Anjali Singhai Jain | bbe7d0e | 2014-05-20 08:01:44 +0000 | [diff] [blame] | 9504 | I40E_FLAG_FD_ATR_ENABLED | |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 9505 | I40E_FLAG_DCB_CAPABLE))) { |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 9506 | /* one qp for PF */ |
| 9507 | pf->rss_size = pf->num_lan_qps = 1; |
| 9508 | queues_left -= pf->num_lan_qps; |
| 9509 | |
| 9510 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9511 | #ifdef I40E_FCOE |
| 9512 | I40E_FLAG_FCOE_ENABLED | |
| 9513 | #endif |
Frank Zhang | 9aa7e93 | 2014-05-20 08:01:42 +0000 | [diff] [blame] | 9514 | I40E_FLAG_FD_SB_ENABLED | |
| 9515 | I40E_FLAG_FD_ATR_ENABLED | |
| 9516 | I40E_FLAG_DCB_ENABLED | |
| 9517 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9518 | } else { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9519 | /* Not enough queues for all TCs */ |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 9520 | if ((pf->flags & I40E_FLAG_DCB_CAPABLE) && |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9521 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 9522 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9523 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
| 9524 | } |
Anjali Singhai Jain | 9a3bd2f | 2015-02-24 06:58:44 +0000 | [diff] [blame] | 9525 | pf->num_lan_qps = max_t(int, pf->rss_size_max, |
| 9526 | num_online_cpus()); |
| 9527 | pf->num_lan_qps = min_t(int, pf->num_lan_qps, |
| 9528 | pf->hw.func_caps.num_tx_qp); |
| 9529 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9530 | queues_left -= pf->num_lan_qps; |
| 9531 | } |
| 9532 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9533 | #ifdef I40E_FCOE |
| 9534 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) { |
| 9535 | if (I40E_DEFAULT_FCOE <= queues_left) { |
| 9536 | pf->num_fcoe_qps = I40E_DEFAULT_FCOE; |
| 9537 | } else if (I40E_MINIMUM_FCOE <= queues_left) { |
| 9538 | pf->num_fcoe_qps = I40E_MINIMUM_FCOE; |
| 9539 | } else { |
| 9540 | pf->num_fcoe_qps = 0; |
| 9541 | pf->flags &= ~I40E_FLAG_FCOE_ENABLED; |
| 9542 | dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n"); |
| 9543 | } |
| 9544 | |
| 9545 | queues_left -= pf->num_fcoe_qps; |
| 9546 | } |
| 9547 | |
| 9548 | #endif |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9549 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 9550 | if (queues_left > 1) { |
| 9551 | queues_left -= 1; /* save 1 queue for FD */ |
| 9552 | } else { |
| 9553 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 9554 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); |
| 9555 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9556 | } |
| 9557 | |
| 9558 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 9559 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 9560 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
| 9561 | (queues_left / pf->num_vf_qps)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9562 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 9563 | } |
| 9564 | |
| 9565 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 9566 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 9567 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 9568 | (queues_left / pf->num_vmdq_qps)); |
| 9569 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 9570 | } |
| 9571 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 9572 | pf->queues_left = queues_left; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9573 | #ifdef I40E_FCOE |
| 9574 | dev_info(&pf->pdev->dev, "fcoe queues = %d\n", pf->num_fcoe_qps); |
| 9575 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9576 | } |
| 9577 | |
| 9578 | /** |
| 9579 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 9580 | * @pf: PF to be setup |
| 9581 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 9582 | * 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] | 9583 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 9584 | * based filter sizes required for them. It also enables Flow director, |
| 9585 | * ethertype and macvlan type filter settings for the pf. |
| 9586 | * |
| 9587 | * Returns 0 on success, negative on failure |
| 9588 | **/ |
| 9589 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 9590 | { |
| 9591 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 9592 | |
| 9593 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 9594 | |
| 9595 | /* Flow Director is enabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 9596 | 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] | 9597 | settings->enable_fdir = true; |
| 9598 | |
| 9599 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 9600 | settings->enable_ethtype = true; |
| 9601 | settings->enable_macvlan = true; |
| 9602 | |
| 9603 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 9604 | return -ENOENT; |
| 9605 | |
| 9606 | return 0; |
| 9607 | } |
| 9608 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 9609 | #define INFO_STRING_LEN 255 |
| 9610 | static void i40e_print_features(struct i40e_pf *pf) |
| 9611 | { |
| 9612 | struct i40e_hw *hw = &pf->hw; |
| 9613 | char *buf, *string; |
| 9614 | |
| 9615 | string = kzalloc(INFO_STRING_LEN, GFP_KERNEL); |
| 9616 | if (!string) { |
| 9617 | dev_err(&pf->pdev->dev, "Features string allocation failed\n"); |
| 9618 | return; |
| 9619 | } |
| 9620 | |
| 9621 | buf = string; |
| 9622 | |
| 9623 | buf += sprintf(string, "Features: PF-id[%d] ", hw->pf_id); |
| 9624 | #ifdef CONFIG_PCI_IOV |
| 9625 | buf += sprintf(buf, "VFs: %d ", pf->num_req_vfs); |
| 9626 | #endif |
Mitch Williams | aba237d | 2015-02-06 08:52:17 +0000 | [diff] [blame] | 9627 | buf += sprintf(buf, "VSIs: %d QP: %d RX: %s ", |
| 9628 | pf->hw.func_caps.num_vsis, |
| 9629 | pf->vsi[pf->lan_vsi]->num_queue_pairs, |
| 9630 | pf->flags & I40E_FLAG_RX_PS_ENABLED ? "PS" : "1BUF"); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 9631 | |
| 9632 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
| 9633 | buf += sprintf(buf, "RSS "); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 9634 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 9635 | buf += sprintf(buf, "FD_ATR "); |
| 9636 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 9637 | buf += sprintf(buf, "FD_SB "); |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 9638 | buf += sprintf(buf, "NTUPLE "); |
Akeem G Abodunrin | c6423ff | 2014-05-10 04:49:08 +0000 | [diff] [blame] | 9639 | } |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 9640 | if (pf->flags & I40E_FLAG_DCB_CAPABLE) |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 9641 | buf += sprintf(buf, "DCB "); |
| 9642 | if (pf->flags & I40E_FLAG_PTP) |
| 9643 | buf += sprintf(buf, "PTP "); |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9644 | #ifdef I40E_FCOE |
| 9645 | if (pf->flags & I40E_FLAG_FCOE_ENABLED) |
| 9646 | buf += sprintf(buf, "FCOE "); |
| 9647 | #endif |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 9648 | |
| 9649 | BUG_ON(buf > (string + INFO_STRING_LEN)); |
| 9650 | dev_info(&pf->pdev->dev, "%s\n", string); |
| 9651 | kfree(string); |
| 9652 | } |
| 9653 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9654 | /** |
| 9655 | * i40e_probe - Device initialization routine |
| 9656 | * @pdev: PCI device information struct |
| 9657 | * @ent: entry in i40e_pci_tbl |
| 9658 | * |
Jeff Kirsher | b40c82e | 2015-02-27 09:18:34 +0000 | [diff] [blame] | 9659 | * i40e_probe initializes a PF identified by a pci_dev structure. |
| 9660 | * The OS initialization, configuring of the PF private structure, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9661 | * and a hardware reset occur. |
| 9662 | * |
| 9663 | * Returns 0 on success, negative on failure |
| 9664 | **/ |
| 9665 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 9666 | { |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 9667 | struct i40e_aq_get_phy_abilities_resp abilities; |
Jeff Kirsher | e815665 | 2015-03-05 19:02:35 -0800 | [diff] [blame] | 9668 | unsigned long ioremap_len; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9669 | struct i40e_pf *pf; |
| 9670 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 9671 | static u16 pfs_found; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 9672 | u16 link_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9673 | int err = 0; |
| 9674 | u32 len; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 9675 | u32 i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9676 | |
| 9677 | err = pci_enable_device_mem(pdev); |
| 9678 | if (err) |
| 9679 | return err; |
| 9680 | |
| 9681 | /* set up for high or low dma */ |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 9682 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 9683 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 9684 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 9685 | if (err) { |
| 9686 | dev_err(&pdev->dev, |
| 9687 | "DMA configuration failed: 0x%x\n", err); |
| 9688 | goto err_dma; |
| 9689 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9690 | } |
| 9691 | |
| 9692 | /* set up pci connections */ |
| 9693 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 9694 | IORESOURCE_MEM), i40e_driver_name); |
| 9695 | if (err) { |
| 9696 | dev_info(&pdev->dev, |
| 9697 | "pci_request_selected_regions failed %d\n", err); |
| 9698 | goto err_pci_reg; |
| 9699 | } |
| 9700 | |
| 9701 | pci_enable_pcie_error_reporting(pdev); |
| 9702 | pci_set_master(pdev); |
| 9703 | |
| 9704 | /* Now that we have a PCI connection, we need to do the |
| 9705 | * low level device setup. This is primarily setting up |
| 9706 | * the Admin Queue structures and then querying for the |
| 9707 | * device's current profile information. |
| 9708 | */ |
| 9709 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 9710 | if (!pf) { |
| 9711 | err = -ENOMEM; |
| 9712 | goto err_pf_alloc; |
| 9713 | } |
| 9714 | pf->next_vsi = 0; |
| 9715 | pf->pdev = pdev; |
| 9716 | set_bit(__I40E_DOWN, &pf->state); |
| 9717 | |
| 9718 | hw = &pf->hw; |
| 9719 | hw->back = pf; |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 9720 | |
Jeff Kirsher | e815665 | 2015-03-05 19:02:35 -0800 | [diff] [blame] | 9721 | ioremap_len = min_t(unsigned long, pci_resource_len(pdev, 0), |
Anjali Singhai | 232f470 | 2015-02-26 16:15:39 +0000 | [diff] [blame] | 9722 | I40E_MAX_CSR_SPACE); |
| 9723 | |
| 9724 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), ioremap_len); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9725 | if (!hw->hw_addr) { |
| 9726 | err = -EIO; |
| 9727 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 9728 | (unsigned int)pci_resource_start(pdev, 0), |
| 9729 | (unsigned int)pci_resource_len(pdev, 0), err); |
| 9730 | goto err_ioremap; |
| 9731 | } |
| 9732 | hw->vendor_id = pdev->vendor; |
| 9733 | hw->device_id = pdev->device; |
| 9734 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 9735 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 9736 | hw->subsystem_device_id = pdev->subsystem_device; |
| 9737 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 9738 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 9739 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9740 | |
Shannon Nelson | 5b5faa4 | 2014-10-17 03:14:51 +0000 | [diff] [blame] | 9741 | if (debug != -1) { |
| 9742 | pf->msg_enable = pf->hw.debug_mask; |
| 9743 | pf->msg_enable = debug; |
| 9744 | } |
| 9745 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 9746 | /* do a special CORER for clearing PXE mode once at init */ |
| 9747 | if (hw->revision_id == 0 && |
| 9748 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 9749 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 9750 | i40e_flush(hw); |
| 9751 | msleep(200); |
| 9752 | pf->corer_count++; |
| 9753 | |
| 9754 | i40e_clear_pxe_mode(hw); |
| 9755 | } |
| 9756 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9757 | /* 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] | 9758 | i40e_clear_hw(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9759 | err = i40e_pf_reset(hw); |
| 9760 | if (err) { |
| 9761 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 9762 | goto err_pf_reset; |
| 9763 | } |
| 9764 | pf->pfr_count++; |
| 9765 | |
| 9766 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 9767 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 9768 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 9769 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 9770 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 9771 | |
Carolyn Wyborny | b294ac7 | 2014-12-11 07:06:39 +0000 | [diff] [blame] | 9772 | snprintf(pf->int_name, sizeof(pf->int_name) - 1, |
Carolyn Wyborny | b2008cb | 2014-11-11 20:05:26 +0000 | [diff] [blame] | 9773 | "%s-%s:misc", |
| 9774 | dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9775 | |
| 9776 | err = i40e_init_shared_code(hw); |
| 9777 | if (err) { |
| 9778 | dev_info(&pdev->dev, "init_shared_code failed: %d\n", err); |
| 9779 | goto err_pf_reset; |
| 9780 | } |
| 9781 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 9782 | /* set up a default setting for link flow control */ |
| 9783 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 9784 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9785 | err = i40e_init_adminq(hw); |
| 9786 | dev_info(&pdev->dev, "%s\n", i40e_fw_version_str(hw)); |
| 9787 | if (err) { |
| 9788 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 9789 | "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"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9790 | goto err_pf_reset; |
| 9791 | } |
| 9792 | |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 9793 | if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && |
| 9794 | hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 9795 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 9796 | "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"); |
| 9797 | else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR || |
| 9798 | hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1)) |
Shannon Nelson | 278b6f6 | 2014-06-04 01:41:03 +0000 | [diff] [blame] | 9799 | dev_info(&pdev->dev, |
Catherine Sullivan | 7aa6761 | 2014-07-09 07:46:17 +0000 | [diff] [blame] | 9800 | "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] | 9801 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 9802 | i40e_verify_eeprom(pf); |
| 9803 | |
Jesse Brandeburg | 2c5fe33 | 2014-04-23 04:49:57 +0000 | [diff] [blame] | 9804 | /* Rev 0 hardware was never productized */ |
| 9805 | if (hw->revision_id < 1) |
| 9806 | 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"); |
| 9807 | |
Shannon Nelson | 6ff4ef8 | 2013-12-21 05:44:49 +0000 | [diff] [blame] | 9808 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9809 | err = i40e_get_capabilities(pf); |
| 9810 | if (err) |
| 9811 | goto err_adminq_setup; |
| 9812 | |
| 9813 | err = i40e_sw_init(pf); |
| 9814 | if (err) { |
| 9815 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 9816 | goto err_sw_init; |
| 9817 | } |
| 9818 | |
| 9819 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 9820 | hw->func_caps.num_rx_qp, |
| 9821 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 9822 | if (err) { |
| 9823 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 9824 | goto err_init_lan_hmc; |
| 9825 | } |
| 9826 | |
| 9827 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 9828 | if (err) { |
| 9829 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 9830 | err = -ENOENT; |
| 9831 | goto err_configure_lan_hmc; |
| 9832 | } |
| 9833 | |
Neerav Parikh | b686ece | 2014-12-14 01:55:11 +0000 | [diff] [blame] | 9834 | /* Disable LLDP for NICs that have firmware versions lower than v4.3. |
| 9835 | * Ignore error return codes because if it was already disabled via |
| 9836 | * hardware settings this will fail |
| 9837 | */ |
| 9838 | if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || |
| 9839 | (pf->hw.aq.fw_maj_ver < 4)) { |
| 9840 | dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n"); |
| 9841 | i40e_aq_stop_lldp(hw, true, NULL); |
| 9842 | } |
| 9843 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9844 | i40e_get_mac_addr(hw, hw->mac.addr); |
Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 9845 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9846 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 9847 | err = -EIO; |
| 9848 | goto err_mac_addr; |
| 9849 | } |
| 9850 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
Greg Rose | 9a17390 | 2014-05-22 06:32:02 +0000 | [diff] [blame] | 9851 | ether_addr_copy(hw->mac.perm_addr, hw->mac.addr); |
Neerav Parikh | 1f224ad | 2014-02-12 01:45:31 +0000 | [diff] [blame] | 9852 | i40e_get_port_mac_addr(hw, hw->mac.port_addr); |
| 9853 | if (is_valid_ether_addr(hw->mac.port_addr)) |
| 9854 | pf->flags |= I40E_FLAG_PORT_ID_VALID; |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 9855 | #ifdef I40E_FCOE |
| 9856 | err = i40e_get_san_mac_addr(hw, hw->mac.san_addr); |
| 9857 | if (err) |
| 9858 | dev_info(&pdev->dev, |
| 9859 | "(non-fatal) SAN MAC retrieval failed: %d\n", err); |
| 9860 | if (!is_valid_ether_addr(hw->mac.san_addr)) { |
| 9861 | dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n", |
| 9862 | hw->mac.san_addr); |
| 9863 | ether_addr_copy(hw->mac.san_addr, hw->mac.addr); |
| 9864 | } |
| 9865 | dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr); |
| 9866 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9867 | |
| 9868 | pci_set_drvdata(pdev, pf); |
| 9869 | pci_save_state(pdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 9870 | #ifdef CONFIG_I40E_DCB |
| 9871 | err = i40e_init_pf_dcb(pf); |
| 9872 | if (err) { |
Shannon Nelson | aebfc81 | 2014-12-11 07:06:38 +0000 | [diff] [blame] | 9873 | dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err); |
Neerav Parikh | 4d9b604 | 2014-05-22 06:31:51 +0000 | [diff] [blame] | 9874 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 9875 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 9876 | } |
| 9877 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9878 | |
| 9879 | /* set up periodic task facility */ |
| 9880 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 9881 | pf->service_timer_period = HZ; |
| 9882 | |
| 9883 | INIT_WORK(&pf->service_task, i40e_service_task); |
| 9884 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 9885 | pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; |
| 9886 | pf->link_check_timeout = jiffies; |
| 9887 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 9888 | /* WoL defaults to disabled */ |
| 9889 | pf->wol_en = false; |
| 9890 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 9891 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9892 | /* set up the main switch operations */ |
| 9893 | i40e_determine_queue_usage(pf); |
Jesse Brandeburg | c1147280 | 2015-04-07 19:45:39 -0400 | [diff] [blame] | 9894 | err = i40e_init_interrupt_scheme(pf); |
| 9895 | if (err) |
| 9896 | goto err_switch_setup; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9897 | |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9898 | /* The number of VSIs reported by the FW is the minimum guaranteed |
| 9899 | * to us; HW supports far more and we share the remaining pool with |
| 9900 | * the other PFs. We allocate space for more than the guarantee with |
| 9901 | * the understanding that we might not get them all later. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9902 | */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9903 | if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC) |
| 9904 | pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC; |
| 9905 | else |
| 9906 | pf->num_alloc_vsi = pf->hw.func_caps.num_vsis; |
| 9907 | |
| 9908 | /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */ |
| 9909 | len = sizeof(struct i40e_vsi *) * pf->num_alloc_vsi; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9910 | pf->vsi = kzalloc(len, GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 9911 | if (!pf->vsi) { |
| 9912 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9913 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 9914 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9915 | |
Anjali Singhai Jain | fa11cb3 | 2015-05-27 12:06:14 -0400 | [diff] [blame] | 9916 | #ifdef CONFIG_PCI_IOV |
| 9917 | /* prep for VF support */ |
| 9918 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 9919 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 9920 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 9921 | if (pci_num_vf(pdev)) |
| 9922 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; |
| 9923 | } |
| 9924 | #endif |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 9925 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9926 | if (err) { |
| 9927 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 9928 | goto err_vsis; |
| 9929 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 9930 | /* if FDIR VSI was set up, start it now */ |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 9931 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 9932 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 9933 | i40e_vsi_open(pf->vsi[i]); |
| 9934 | break; |
| 9935 | } |
| 9936 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9937 | |
Jesse Brandeburg | 7e2453f | 2014-09-13 07:40:41 +0000 | [diff] [blame] | 9938 | /* driver is only interested in link up/down and module qualification |
| 9939 | * reports from firmware |
| 9940 | */ |
| 9941 | err = i40e_aq_set_phy_int_mask(&pf->hw, |
| 9942 | I40E_AQ_EVENT_LINK_UPDOWN | |
| 9943 | I40E_AQ_EVENT_MODULE_QUAL_FAIL, NULL); |
| 9944 | if (err) |
| 9945 | dev_info(&pf->pdev->dev, "set phy mask fail, aq_err %d\n", err); |
| 9946 | |
Anjali Singhai Jain | 025b4a5 | 2015-02-24 06:58:46 +0000 | [diff] [blame] | 9947 | if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) || |
| 9948 | (pf->hw.aq.fw_maj_ver < 4)) { |
| 9949 | msleep(75); |
| 9950 | err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); |
| 9951 | if (err) |
| 9952 | dev_info(&pf->pdev->dev, "link restart failed, aq_err=%d\n", |
| 9953 | pf->hw.aq.asq_last_status); |
Anjali Singhai Jain | cafa2ee | 2014-09-13 07:40:45 +0000 | [diff] [blame] | 9954 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9955 | /* The main driver is (mostly) up and happy. We need to set this state |
| 9956 | * before setting up the misc vector or we get a race and the vector |
| 9957 | * ends up disabled forever. |
| 9958 | */ |
| 9959 | clear_bit(__I40E_DOWN, &pf->state); |
| 9960 | |
| 9961 | /* In case of MSIX we are going to setup the misc vector right here |
| 9962 | * to handle admin queue events etc. In case of legacy and MSI |
| 9963 | * the misc functionality and queue processing is combined in |
| 9964 | * the same vector and that gets setup at open. |
| 9965 | */ |
| 9966 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 9967 | err = i40e_setup_misc_vector(pf); |
| 9968 | if (err) { |
| 9969 | dev_info(&pdev->dev, |
| 9970 | "setup of misc vector failed: %d\n", err); |
| 9971 | goto err_vsis; |
| 9972 | } |
| 9973 | } |
| 9974 | |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 9975 | #ifdef CONFIG_PCI_IOV |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9976 | /* prep for VF support */ |
| 9977 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 9978 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 9979 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9980 | u32 val; |
| 9981 | |
| 9982 | /* disable link interrupts for VFs */ |
| 9983 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 9984 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 9985 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 9986 | i40e_flush(hw); |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 9987 | |
| 9988 | if (pci_num_vf(pdev)) { |
| 9989 | dev_info(&pdev->dev, |
| 9990 | "Active VFs found, allocating resources.\n"); |
| 9991 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); |
| 9992 | if (err) |
| 9993 | dev_info(&pdev->dev, |
| 9994 | "Error %d allocating resources for existing VFs\n", |
| 9995 | err); |
| 9996 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9997 | } |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 9998 | #endif /* CONFIG_PCI_IOV */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 9999 | |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 10000 | pfs_found++; |
| 10001 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10002 | i40e_dbg_pf_init(pf); |
| 10003 | |
| 10004 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 10005 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10006 | |
| 10007 | /* since everything's happy, start the service_task timer */ |
| 10008 | mod_timer(&pf->service_timer, |
| 10009 | round_jiffies(jiffies + pf->service_timer_period)); |
| 10010 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 10011 | #ifdef I40E_FCOE |
| 10012 | /* create FCoE interface */ |
| 10013 | i40e_fcoe_vsi_setup(pf); |
| 10014 | |
| 10015 | #endif |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 10016 | /* Get the negotiated link width and speed from PCI config space */ |
| 10017 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, &link_status); |
| 10018 | |
| 10019 | i40e_set_pci_config_data(hw, link_status); |
| 10020 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 10021 | dev_info(&pdev->dev, "PCI-Express: %s %s\n", |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 10022 | (hw->bus.speed == i40e_bus_speed_8000 ? "Speed 8.0GT/s" : |
| 10023 | hw->bus.speed == i40e_bus_speed_5000 ? "Speed 5.0GT/s" : |
| 10024 | hw->bus.speed == i40e_bus_speed_2500 ? "Speed 2.5GT/s" : |
| 10025 | "Unknown"), |
| 10026 | (hw->bus.width == i40e_bus_width_pcie_x8 ? "Width x8" : |
| 10027 | hw->bus.width == i40e_bus_width_pcie_x4 ? "Width x4" : |
| 10028 | hw->bus.width == i40e_bus_width_pcie_x2 ? "Width x2" : |
| 10029 | hw->bus.width == i40e_bus_width_pcie_x1 ? "Width x1" : |
| 10030 | "Unknown")); |
| 10031 | |
| 10032 | if (hw->bus.width < i40e_bus_width_pcie_x8 || |
| 10033 | hw->bus.speed < i40e_bus_speed_8000) { |
| 10034 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); |
| 10035 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); |
| 10036 | } |
| 10037 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 10038 | /* get the requested speeds from the fw */ |
| 10039 | err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL); |
| 10040 | if (err) |
| 10041 | dev_info(&pf->pdev->dev, "get phy abilities failed, aq_err %d, advertised speed settings may not be correct\n", |
| 10042 | err); |
| 10043 | pf->hw.phy.link_info.requested_speeds = abilities.link_speed; |
| 10044 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 10045 | /* print a string summarizing features */ |
| 10046 | i40e_print_features(pf); |
| 10047 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10048 | return 0; |
| 10049 | |
| 10050 | /* Unwind what we've done if something failed in the setup */ |
| 10051 | err_vsis: |
| 10052 | set_bit(__I40E_DOWN, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10053 | i40e_clear_interrupt_scheme(pf); |
| 10054 | kfree(pf->vsi); |
Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 10055 | err_switch_setup: |
| 10056 | i40e_reset_interrupt_capability(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10057 | del_timer_sync(&pf->service_timer); |
| 10058 | err_mac_addr: |
| 10059 | err_configure_lan_hmc: |
| 10060 | (void)i40e_shutdown_lan_hmc(hw); |
| 10061 | err_init_lan_hmc: |
| 10062 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10063 | err_sw_init: |
| 10064 | err_adminq_setup: |
| 10065 | (void)i40e_shutdown_adminq(hw); |
| 10066 | err_pf_reset: |
| 10067 | iounmap(hw->hw_addr); |
| 10068 | err_ioremap: |
| 10069 | kfree(pf); |
| 10070 | err_pf_alloc: |
| 10071 | pci_disable_pcie_error_reporting(pdev); |
| 10072 | pci_release_selected_regions(pdev, |
| 10073 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 10074 | err_pci_reg: |
| 10075 | err_dma: |
| 10076 | pci_disable_device(pdev); |
| 10077 | return err; |
| 10078 | } |
| 10079 | |
| 10080 | /** |
| 10081 | * i40e_remove - Device removal routine |
| 10082 | * @pdev: PCI device information struct |
| 10083 | * |
| 10084 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 10085 | * that is should release a PCI device. This could be caused by a |
| 10086 | * Hot-Plug event, or because the driver is going to be removed from |
| 10087 | * memory. |
| 10088 | **/ |
| 10089 | static void i40e_remove(struct pci_dev *pdev) |
| 10090 | { |
| 10091 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 10092 | i40e_status ret_code; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10093 | int i; |
| 10094 | |
| 10095 | i40e_dbg_pf_exit(pf); |
| 10096 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 10097 | i40e_ptp_stop(pf); |
| 10098 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10099 | /* no more scheduling of any task */ |
| 10100 | set_bit(__I40E_DOWN, &pf->state); |
| 10101 | del_timer_sync(&pf->service_timer); |
| 10102 | cancel_work_sync(&pf->service_task); |
Mitch A Williams | 33c62b3 | 2015-02-21 06:44:51 +0000 | [diff] [blame] | 10103 | i40e_fdir_teardown(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10104 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 10105 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 10106 | i40e_free_vfs(pf); |
| 10107 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 10108 | } |
| 10109 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10110 | i40e_fdir_teardown(pf); |
| 10111 | |
| 10112 | /* If there is a switch structure or any orphans, remove them. |
| 10113 | * This will leave only the PF's VSI remaining. |
| 10114 | */ |
| 10115 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 10116 | if (!pf->veb[i]) |
| 10117 | continue; |
| 10118 | |
| 10119 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 10120 | pf->veb[i]->uplink_seid == 0) |
| 10121 | i40e_switch_branch_release(pf->veb[i]); |
| 10122 | } |
| 10123 | |
| 10124 | /* Now we can shutdown the PF's VSI, just before we kill |
| 10125 | * adminq and hmc. |
| 10126 | */ |
| 10127 | if (pf->vsi[pf->lan_vsi]) |
| 10128 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 10129 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10130 | /* shutdown and destroy the HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 10131 | if (pf->hw.hmc.hmc_obj) { |
| 10132 | ret_code = i40e_shutdown_lan_hmc(&pf->hw); |
| 10133 | if (ret_code) |
| 10134 | dev_warn(&pdev->dev, |
| 10135 | "Failed to destroy the HMC resources: %d\n", |
| 10136 | ret_code); |
| 10137 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10138 | |
| 10139 | /* shutdown the adminq */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10140 | ret_code = i40e_shutdown_adminq(&pf->hw); |
| 10141 | if (ret_code) |
| 10142 | dev_warn(&pdev->dev, |
| 10143 | "Failed to destroy the Admin Queue resources: %d\n", |
| 10144 | ret_code); |
| 10145 | |
| 10146 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 10147 | i40e_clear_interrupt_scheme(pf); |
Mitch Williams | 505682c | 2014-05-20 08:01:37 +0000 | [diff] [blame] | 10148 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10149 | if (pf->vsi[i]) { |
| 10150 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 10151 | i40e_vsi_clear(pf->vsi[i]); |
| 10152 | pf->vsi[i] = NULL; |
| 10153 | } |
| 10154 | } |
| 10155 | |
| 10156 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 10157 | kfree(pf->veb[i]); |
| 10158 | pf->veb[i] = NULL; |
| 10159 | } |
| 10160 | |
| 10161 | kfree(pf->qp_pile); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10162 | kfree(pf->vsi); |
| 10163 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10164 | iounmap(pf->hw.hw_addr); |
| 10165 | kfree(pf); |
| 10166 | pci_release_selected_regions(pdev, |
| 10167 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 10168 | |
| 10169 | pci_disable_pcie_error_reporting(pdev); |
| 10170 | pci_disable_device(pdev); |
| 10171 | } |
| 10172 | |
| 10173 | /** |
| 10174 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 10175 | * @pdev: PCI device information struct |
| 10176 | * |
| 10177 | * Called to warn that something happened and the error handling steps |
| 10178 | * are in progress. Allows the driver to quiesce things, be ready for |
| 10179 | * remediation. |
| 10180 | **/ |
| 10181 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 10182 | enum pci_channel_state error) |
| 10183 | { |
| 10184 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 10185 | |
| 10186 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 10187 | |
| 10188 | /* shutdown all operations */ |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 10189 | if (!test_bit(__I40E_SUSPENDED, &pf->state)) { |
| 10190 | rtnl_lock(); |
| 10191 | i40e_prep_for_reset(pf); |
| 10192 | rtnl_unlock(); |
| 10193 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10194 | |
| 10195 | /* Request a slot reset */ |
| 10196 | return PCI_ERS_RESULT_NEED_RESET; |
| 10197 | } |
| 10198 | |
| 10199 | /** |
| 10200 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 10201 | * @pdev: PCI device information struct |
| 10202 | * |
| 10203 | * Called to find if the driver can work with the device now that |
| 10204 | * the pci slot has been reset. If a basic connection seems good |
| 10205 | * (registers are readable and have sane content) then return a |
| 10206 | * happy little PCI_ERS_RESULT_xxx. |
| 10207 | **/ |
| 10208 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 10209 | { |
| 10210 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 10211 | pci_ers_result_t result; |
| 10212 | int err; |
| 10213 | u32 reg; |
| 10214 | |
| 10215 | dev_info(&pdev->dev, "%s\n", __func__); |
| 10216 | if (pci_enable_device_mem(pdev)) { |
| 10217 | dev_info(&pdev->dev, |
| 10218 | "Cannot re-enable PCI device after reset.\n"); |
| 10219 | result = PCI_ERS_RESULT_DISCONNECT; |
| 10220 | } else { |
| 10221 | pci_set_master(pdev); |
| 10222 | pci_restore_state(pdev); |
| 10223 | pci_save_state(pdev); |
| 10224 | pci_wake_from_d3(pdev, false); |
| 10225 | |
| 10226 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 10227 | if (reg == 0) |
| 10228 | result = PCI_ERS_RESULT_RECOVERED; |
| 10229 | else |
| 10230 | result = PCI_ERS_RESULT_DISCONNECT; |
| 10231 | } |
| 10232 | |
| 10233 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 10234 | if (err) { |
| 10235 | dev_info(&pdev->dev, |
| 10236 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 10237 | err); |
| 10238 | /* non-fatal, continue */ |
| 10239 | } |
| 10240 | |
| 10241 | return result; |
| 10242 | } |
| 10243 | |
| 10244 | /** |
| 10245 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 10246 | * @pdev: PCI device information struct |
| 10247 | * |
| 10248 | * Called to allow the driver to bring things back up after PCI error |
| 10249 | * and/or reset recovery has finished. |
| 10250 | **/ |
| 10251 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 10252 | { |
| 10253 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 10254 | |
| 10255 | dev_info(&pdev->dev, "%s\n", __func__); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 10256 | if (test_bit(__I40E_SUSPENDED, &pf->state)) |
| 10257 | return; |
| 10258 | |
| 10259 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10260 | i40e_handle_reset_warning(pf); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 10261 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10262 | } |
| 10263 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 10264 | /** |
| 10265 | * i40e_shutdown - PCI callback for shutting down |
| 10266 | * @pdev: PCI device information struct |
| 10267 | **/ |
| 10268 | static void i40e_shutdown(struct pci_dev *pdev) |
| 10269 | { |
| 10270 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 10271 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 10272 | |
| 10273 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 10274 | set_bit(__I40E_DOWN, &pf->state); |
| 10275 | rtnl_lock(); |
| 10276 | i40e_prep_for_reset(pf); |
| 10277 | rtnl_unlock(); |
| 10278 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 10279 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 10280 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 10281 | |
Shannon Nelson | e147758 | 2015-02-21 06:44:33 +0000 | [diff] [blame] | 10282 | i40e_clear_interrupt_scheme(pf); |
| 10283 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 10284 | if (system_state == SYSTEM_POWER_OFF) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 10285 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 10286 | pci_set_power_state(pdev, PCI_D3hot); |
| 10287 | } |
| 10288 | } |
| 10289 | |
| 10290 | #ifdef CONFIG_PM |
| 10291 | /** |
| 10292 | * i40e_suspend - PCI callback for moving to D3 |
| 10293 | * @pdev: PCI device information struct |
| 10294 | **/ |
| 10295 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) |
| 10296 | { |
| 10297 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 10298 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 10299 | |
| 10300 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 10301 | set_bit(__I40E_DOWN, &pf->state); |
Mitch Williams | 88086e5d | 2015-01-09 11:18:19 +0000 | [diff] [blame] | 10302 | del_timer_sync(&pf->service_timer); |
| 10303 | cancel_work_sync(&pf->service_task); |
Mitch Williams | 3932dbf | 2015-03-31 00:45:04 -0700 | [diff] [blame] | 10304 | i40e_fdir_teardown(pf); |
| 10305 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 10306 | rtnl_lock(); |
| 10307 | i40e_prep_for_reset(pf); |
| 10308 | rtnl_unlock(); |
| 10309 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 10310 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 10311 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 10312 | |
| 10313 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 10314 | pci_set_power_state(pdev, PCI_D3hot); |
| 10315 | |
| 10316 | return 0; |
| 10317 | } |
| 10318 | |
| 10319 | /** |
| 10320 | * i40e_resume - PCI callback for waking up from D3 |
| 10321 | * @pdev: PCI device information struct |
| 10322 | **/ |
| 10323 | static int i40e_resume(struct pci_dev *pdev) |
| 10324 | { |
| 10325 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 10326 | u32 err; |
| 10327 | |
| 10328 | pci_set_power_state(pdev, PCI_D0); |
| 10329 | pci_restore_state(pdev); |
| 10330 | /* pci_restore_state() clears dev->state_saves, so |
| 10331 | * call pci_save_state() again to restore it. |
| 10332 | */ |
| 10333 | pci_save_state(pdev); |
| 10334 | |
| 10335 | err = pci_enable_device_mem(pdev); |
| 10336 | if (err) { |
| 10337 | dev_err(&pdev->dev, |
| 10338 | "%s: Cannot enable PCI device from suspend\n", |
| 10339 | __func__); |
| 10340 | return err; |
| 10341 | } |
| 10342 | pci_set_master(pdev); |
| 10343 | |
| 10344 | /* no wakeup events while running */ |
| 10345 | pci_wake_from_d3(pdev, false); |
| 10346 | |
| 10347 | /* handling the reset will rebuild the device state */ |
| 10348 | if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) { |
| 10349 | clear_bit(__I40E_DOWN, &pf->state); |
| 10350 | rtnl_lock(); |
| 10351 | i40e_reset_and_rebuild(pf, false); |
| 10352 | rtnl_unlock(); |
| 10353 | } |
| 10354 | |
| 10355 | return 0; |
| 10356 | } |
| 10357 | |
| 10358 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10359 | static const struct pci_error_handlers i40e_err_handler = { |
| 10360 | .error_detected = i40e_pci_error_detected, |
| 10361 | .slot_reset = i40e_pci_error_slot_reset, |
| 10362 | .resume = i40e_pci_error_resume, |
| 10363 | }; |
| 10364 | |
| 10365 | static struct pci_driver i40e_driver = { |
| 10366 | .name = i40e_driver_name, |
| 10367 | .id_table = i40e_pci_tbl, |
| 10368 | .probe = i40e_probe, |
| 10369 | .remove = i40e_remove, |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 10370 | #ifdef CONFIG_PM |
| 10371 | .suspend = i40e_suspend, |
| 10372 | .resume = i40e_resume, |
| 10373 | #endif |
| 10374 | .shutdown = i40e_shutdown, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10375 | .err_handler = &i40e_err_handler, |
| 10376 | .sriov_configure = i40e_pci_sriov_configure, |
| 10377 | }; |
| 10378 | |
| 10379 | /** |
| 10380 | * i40e_init_module - Driver registration routine |
| 10381 | * |
| 10382 | * i40e_init_module is the first routine called when the driver is |
| 10383 | * loaded. All it does is register with the PCI subsystem. |
| 10384 | **/ |
| 10385 | static int __init i40e_init_module(void) |
| 10386 | { |
| 10387 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 10388 | i40e_driver_string, i40e_driver_version_str); |
| 10389 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
Greg Rose | 9666448 | 2015-02-06 08:52:13 +0000 | [diff] [blame] | 10390 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10391 | i40e_dbg_init(); |
| 10392 | return pci_register_driver(&i40e_driver); |
| 10393 | } |
| 10394 | module_init(i40e_init_module); |
| 10395 | |
| 10396 | /** |
| 10397 | * i40e_exit_module - Driver exit cleanup routine |
| 10398 | * |
| 10399 | * i40e_exit_module is called just before the driver is removed |
| 10400 | * from memory. |
| 10401 | **/ |
| 10402 | static void __exit i40e_exit_module(void) |
| 10403 | { |
| 10404 | pci_unregister_driver(&i40e_driver); |
| 10405 | i40e_dbg_exit(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 10406 | } |
| 10407 | module_exit(i40e_exit_module); |