Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Driver |
| 4 | * Copyright(c) 2013 Intel Corporation. |
| 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 | * |
| 15 | * You should have received a copy of the GNU General Public License along with |
| 16 | * this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * The full GNU General Public License is included in this distribution in |
| 20 | * the file called "COPYING". |
| 21 | * |
| 22 | * Contact Information: |
| 23 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 24 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 25 | * |
| 26 | ******************************************************************************/ |
| 27 | |
| 28 | /* Local includes */ |
| 29 | #include "i40e.h" |
| 30 | |
| 31 | const char i40e_driver_name[] = "i40e"; |
| 32 | static const char i40e_driver_string[] = |
| 33 | "Intel(R) Ethernet Connection XL710 Network Driver"; |
| 34 | |
| 35 | #define DRV_KERN "-k" |
| 36 | |
| 37 | #define DRV_VERSION_MAJOR 0 |
| 38 | #define DRV_VERSION_MINOR 3 |
Catherine Sullivan | 893238a | 2013-11-20 10:03:10 +0000 | [diff] [blame] | 39 | #define DRV_VERSION_BUILD 13 |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 40 | #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ |
| 41 | __stringify(DRV_VERSION_MINOR) "." \ |
| 42 | __stringify(DRV_VERSION_BUILD) DRV_KERN |
| 43 | const char i40e_driver_version_str[] = DRV_VERSION; |
| 44 | static const char i40e_copyright[] = "Copyright (c) 2013 Intel Corporation."; |
| 45 | |
| 46 | /* a bit of forward declarations */ |
| 47 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi); |
| 48 | static void i40e_handle_reset_warning(struct i40e_pf *pf); |
| 49 | static int i40e_add_vsi(struct i40e_vsi *vsi); |
| 50 | 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^] | 51 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 52 | static int i40e_setup_misc_vector(struct i40e_pf *pf); |
| 53 | static void i40e_determine_queue_usage(struct i40e_pf *pf); |
| 54 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf); |
| 55 | |
| 56 | /* i40e_pci_tbl - PCI Device ID Table |
| 57 | * |
| 58 | * Last entry must be all 0s |
| 59 | * |
| 60 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 61 | * Class, Class Mask, private data (not used) } |
| 62 | */ |
| 63 | static DEFINE_PCI_DEVICE_TABLE(i40e_pci_tbl) = { |
| 64 | {PCI_VDEVICE(INTEL, I40E_SFP_XL710_DEVICE_ID), 0}, |
| 65 | {PCI_VDEVICE(INTEL, I40E_SFP_X710_DEVICE_ID), 0}, |
| 66 | {PCI_VDEVICE(INTEL, I40E_QEMU_DEVICE_ID), 0}, |
| 67 | {PCI_VDEVICE(INTEL, I40E_KX_A_DEVICE_ID), 0}, |
| 68 | {PCI_VDEVICE(INTEL, I40E_KX_B_DEVICE_ID), 0}, |
| 69 | {PCI_VDEVICE(INTEL, I40E_KX_C_DEVICE_ID), 0}, |
| 70 | {PCI_VDEVICE(INTEL, I40E_KX_D_DEVICE_ID), 0}, |
| 71 | {PCI_VDEVICE(INTEL, I40E_QSFP_A_DEVICE_ID), 0}, |
| 72 | {PCI_VDEVICE(INTEL, I40E_QSFP_B_DEVICE_ID), 0}, |
| 73 | {PCI_VDEVICE(INTEL, I40E_QSFP_C_DEVICE_ID), 0}, |
| 74 | /* required last entry */ |
| 75 | {0, } |
| 76 | }; |
| 77 | MODULE_DEVICE_TABLE(pci, i40e_pci_tbl); |
| 78 | |
| 79 | #define I40E_MAX_VF_COUNT 128 |
| 80 | static int debug = -1; |
| 81 | module_param(debug, int, 0); |
| 82 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 83 | |
| 84 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); |
| 85 | MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver"); |
| 86 | MODULE_LICENSE("GPL"); |
| 87 | MODULE_VERSION(DRV_VERSION); |
| 88 | |
| 89 | /** |
| 90 | * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code |
| 91 | * @hw: pointer to the HW structure |
| 92 | * @mem: ptr to mem struct to fill out |
| 93 | * @size: size of memory requested |
| 94 | * @alignment: what to align the allocation to |
| 95 | **/ |
| 96 | int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem, |
| 97 | u64 size, u32 alignment) |
| 98 | { |
| 99 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 100 | |
| 101 | mem->size = ALIGN(size, alignment); |
| 102 | mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size, |
| 103 | &mem->pa, GFP_KERNEL); |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 104 | if (!mem->va) |
| 105 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 106 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 107 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /** |
| 111 | * i40e_free_dma_mem_d - OS specific memory free for shared code |
| 112 | * @hw: pointer to the HW structure |
| 113 | * @mem: ptr to mem struct to free |
| 114 | **/ |
| 115 | int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) |
| 116 | { |
| 117 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 118 | |
| 119 | dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa); |
| 120 | mem->va = NULL; |
| 121 | mem->pa = 0; |
| 122 | mem->size = 0; |
| 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code |
| 129 | * @hw: pointer to the HW structure |
| 130 | * @mem: ptr to mem struct to fill out |
| 131 | * @size: size of memory requested |
| 132 | **/ |
| 133 | int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem, |
| 134 | u32 size) |
| 135 | { |
| 136 | mem->size = size; |
| 137 | mem->va = kzalloc(size, GFP_KERNEL); |
| 138 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 139 | if (!mem->va) |
| 140 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 141 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 142 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /** |
| 146 | * i40e_free_virt_mem_d - OS specific memory free for shared code |
| 147 | * @hw: pointer to the HW structure |
| 148 | * @mem: ptr to mem struct to free |
| 149 | **/ |
| 150 | int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem) |
| 151 | { |
| 152 | /* it's ok to kfree a NULL pointer */ |
| 153 | kfree(mem->va); |
| 154 | mem->va = NULL; |
| 155 | mem->size = 0; |
| 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * i40e_get_lump - find a lump of free generic resource |
| 162 | * @pf: board private structure |
| 163 | * @pile: the pile of resource to search |
| 164 | * @needed: the number of items needed |
| 165 | * @id: an owner id to stick on the items assigned |
| 166 | * |
| 167 | * Returns the base item index of the lump, or negative for error |
| 168 | * |
| 169 | * The search_hint trick and lack of advanced fit-finding only work |
| 170 | * because we're highly likely to have all the same size lump requests. |
| 171 | * Linear search time and any fragmentation should be minimal. |
| 172 | **/ |
| 173 | static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile, |
| 174 | u16 needed, u16 id) |
| 175 | { |
| 176 | int ret = -ENOMEM; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 177 | int i, j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 178 | |
| 179 | if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) { |
| 180 | dev_info(&pf->pdev->dev, |
| 181 | "param err: pile=%p needed=%d id=0x%04x\n", |
| 182 | pile, needed, id); |
| 183 | return -EINVAL; |
| 184 | } |
| 185 | |
| 186 | /* start the linear search with an imperfect hint */ |
| 187 | i = pile->search_hint; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 188 | while (i < pile->num_entries) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 189 | /* skip already allocated entries */ |
| 190 | if (pile->list[i] & I40E_PILE_VALID_BIT) { |
| 191 | i++; |
| 192 | continue; |
| 193 | } |
| 194 | |
| 195 | /* do we have enough in this lump? */ |
| 196 | for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) { |
| 197 | if (pile->list[i+j] & I40E_PILE_VALID_BIT) |
| 198 | break; |
| 199 | } |
| 200 | |
| 201 | if (j == needed) { |
| 202 | /* there was enough, so assign it to the requestor */ |
| 203 | for (j = 0; j < needed; j++) |
| 204 | pile->list[i+j] = id | I40E_PILE_VALID_BIT; |
| 205 | ret = i; |
| 206 | pile->search_hint = i + j; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 207 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 208 | } else { |
| 209 | /* not enough, so skip over it and continue looking */ |
| 210 | i += j; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | return ret; |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * i40e_put_lump - return a lump of generic resource |
| 219 | * @pile: the pile of resource to search |
| 220 | * @index: the base item index |
| 221 | * @id: the owner id of the items assigned |
| 222 | * |
| 223 | * Returns the count of items in the lump |
| 224 | **/ |
| 225 | static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id) |
| 226 | { |
| 227 | int valid_id = (id | I40E_PILE_VALID_BIT); |
| 228 | int count = 0; |
| 229 | int i; |
| 230 | |
| 231 | if (!pile || index >= pile->num_entries) |
| 232 | return -EINVAL; |
| 233 | |
| 234 | for (i = index; |
| 235 | i < pile->num_entries && pile->list[i] == valid_id; |
| 236 | i++) { |
| 237 | pile->list[i] = 0; |
| 238 | count++; |
| 239 | } |
| 240 | |
| 241 | if (count && index < pile->search_hint) |
| 242 | pile->search_hint = index; |
| 243 | |
| 244 | return count; |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * i40e_service_event_schedule - Schedule the service task to wake up |
| 249 | * @pf: board private structure |
| 250 | * |
| 251 | * If not already scheduled, this puts the task into the work queue |
| 252 | **/ |
| 253 | static void i40e_service_event_schedule(struct i40e_pf *pf) |
| 254 | { |
| 255 | if (!test_bit(__I40E_DOWN, &pf->state) && |
| 256 | !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) && |
| 257 | !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state)) |
| 258 | schedule_work(&pf->service_task); |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * i40e_tx_timeout - Respond to a Tx Hang |
| 263 | * @netdev: network interface device structure |
| 264 | * |
| 265 | * If any port has noticed a Tx timeout, it is likely that the whole |
| 266 | * device is munged, not just the one netdev port, so go for the full |
| 267 | * reset. |
| 268 | **/ |
| 269 | static void i40e_tx_timeout(struct net_device *netdev) |
| 270 | { |
| 271 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 272 | struct i40e_vsi *vsi = np->vsi; |
| 273 | struct i40e_pf *pf = vsi->back; |
| 274 | |
| 275 | pf->tx_timeout_count++; |
| 276 | |
| 277 | if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20))) |
| 278 | pf->tx_timeout_recovery_level = 0; |
| 279 | pf->tx_timeout_last_recovery = jiffies; |
| 280 | netdev_info(netdev, "tx_timeout recovery level %d\n", |
| 281 | pf->tx_timeout_recovery_level); |
| 282 | |
| 283 | switch (pf->tx_timeout_recovery_level) { |
| 284 | case 0: |
| 285 | /* disable and re-enable queues for the VSI */ |
| 286 | if (in_interrupt()) { |
| 287 | set_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 288 | set_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 289 | } else { |
| 290 | i40e_vsi_reinit_locked(vsi); |
| 291 | } |
| 292 | break; |
| 293 | case 1: |
| 294 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 295 | break; |
| 296 | case 2: |
| 297 | set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 298 | break; |
| 299 | case 3: |
| 300 | set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 301 | break; |
| 302 | default: |
| 303 | netdev_err(netdev, "tx_timeout recovery unsuccessful\n"); |
| 304 | i40e_down(vsi); |
| 305 | break; |
| 306 | } |
| 307 | i40e_service_event_schedule(pf); |
| 308 | pf->tx_timeout_recovery_level++; |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * i40e_release_rx_desc - Store the new tail and head values |
| 313 | * @rx_ring: ring to bump |
| 314 | * @val: new head index |
| 315 | **/ |
| 316 | static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val) |
| 317 | { |
| 318 | rx_ring->next_to_use = val; |
| 319 | |
| 320 | /* Force memory writes to complete before letting h/w |
| 321 | * know there are new descriptors to fetch. (Only |
| 322 | * applicable for weak-ordered memory model archs, |
| 323 | * such as IA-64). |
| 324 | */ |
| 325 | wmb(); |
| 326 | writel(val, rx_ring->tail); |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * i40e_get_vsi_stats_struct - Get System Network Statistics |
| 331 | * @vsi: the VSI we care about |
| 332 | * |
| 333 | * Returns the address of the device statistics structure. |
| 334 | * The statistics are actually updated from the service task. |
| 335 | **/ |
| 336 | struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi) |
| 337 | { |
| 338 | return &vsi->net_stats; |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * i40e_get_netdev_stats_struct - Get statistics for netdev interface |
| 343 | * @netdev: network interface device structure |
| 344 | * |
| 345 | * Returns the address of the device statistics structure. |
| 346 | * The statistics are actually updated from the service task. |
| 347 | **/ |
| 348 | static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 349 | struct net_device *netdev, |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 350 | struct rtnl_link_stats64 *stats) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 351 | { |
| 352 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 353 | struct i40e_vsi *vsi = np->vsi; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 354 | struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi); |
| 355 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 356 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 357 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 358 | return stats; |
| 359 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 360 | rcu_read_lock(); |
| 361 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 362 | struct i40e_ring *tx_ring, *rx_ring; |
| 363 | u64 bytes, packets; |
| 364 | unsigned int start; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 365 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 366 | tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); |
| 367 | if (!tx_ring) |
| 368 | continue; |
| 369 | |
| 370 | do { |
| 371 | start = u64_stats_fetch_begin_bh(&tx_ring->syncp); |
| 372 | packets = tx_ring->stats.packets; |
| 373 | bytes = tx_ring->stats.bytes; |
| 374 | } while (u64_stats_fetch_retry_bh(&tx_ring->syncp, start)); |
| 375 | |
| 376 | stats->tx_packets += packets; |
| 377 | stats->tx_bytes += bytes; |
| 378 | rx_ring = &tx_ring[1]; |
| 379 | |
| 380 | do { |
| 381 | start = u64_stats_fetch_begin_bh(&rx_ring->syncp); |
| 382 | packets = rx_ring->stats.packets; |
| 383 | bytes = rx_ring->stats.bytes; |
| 384 | } while (u64_stats_fetch_retry_bh(&rx_ring->syncp, start)); |
| 385 | |
| 386 | stats->rx_packets += packets; |
| 387 | stats->rx_bytes += bytes; |
| 388 | } |
| 389 | rcu_read_unlock(); |
| 390 | |
| 391 | /* following stats updated by ixgbe_watchdog_task() */ |
| 392 | stats->multicast = vsi_stats->multicast; |
| 393 | stats->tx_errors = vsi_stats->tx_errors; |
| 394 | stats->tx_dropped = vsi_stats->tx_dropped; |
| 395 | stats->rx_errors = vsi_stats->rx_errors; |
| 396 | stats->rx_crc_errors = vsi_stats->rx_crc_errors; |
| 397 | stats->rx_length_errors = vsi_stats->rx_length_errors; |
| 398 | |
| 399 | return stats; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /** |
| 403 | * i40e_vsi_reset_stats - Resets all stats of the given vsi |
| 404 | * @vsi: the VSI to have its stats reset |
| 405 | **/ |
| 406 | void i40e_vsi_reset_stats(struct i40e_vsi *vsi) |
| 407 | { |
| 408 | struct rtnl_link_stats64 *ns; |
| 409 | int i; |
| 410 | |
| 411 | if (!vsi) |
| 412 | return; |
| 413 | |
| 414 | ns = i40e_get_vsi_stats_struct(vsi); |
| 415 | memset(ns, 0, sizeof(*ns)); |
| 416 | memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets)); |
| 417 | memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats)); |
| 418 | memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets)); |
| 419 | if (vsi->rx_rings) |
| 420 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 421 | memset(&vsi->rx_rings[i]->stats, 0 , |
| 422 | sizeof(vsi->rx_rings[i]->stats)); |
| 423 | memset(&vsi->rx_rings[i]->rx_stats, 0 , |
| 424 | sizeof(vsi->rx_rings[i]->rx_stats)); |
| 425 | memset(&vsi->tx_rings[i]->stats, 0 , |
| 426 | sizeof(vsi->tx_rings[i]->stats)); |
| 427 | memset(&vsi->tx_rings[i]->tx_stats, 0, |
| 428 | sizeof(vsi->tx_rings[i]->tx_stats)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 429 | } |
| 430 | vsi->stat_offsets_loaded = false; |
| 431 | } |
| 432 | |
| 433 | /** |
| 434 | * i40e_pf_reset_stats - Reset all of the stats for the given pf |
| 435 | * @pf: the PF to be reset |
| 436 | **/ |
| 437 | void i40e_pf_reset_stats(struct i40e_pf *pf) |
| 438 | { |
| 439 | memset(&pf->stats, 0, sizeof(pf->stats)); |
| 440 | memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); |
| 441 | pf->stat_offsets_loaded = false; |
| 442 | } |
| 443 | |
| 444 | /** |
| 445 | * i40e_stat_update48 - read and update a 48 bit stat from the chip |
| 446 | * @hw: ptr to the hardware info |
| 447 | * @hireg: the high 32 bit reg to read |
| 448 | * @loreg: the low 32 bit reg to read |
| 449 | * @offset_loaded: has the initial offset been loaded yet |
| 450 | * @offset: ptr to current offset value |
| 451 | * @stat: ptr to the stat |
| 452 | * |
| 453 | * Since the device stats are not reset at PFReset, they likely will not |
| 454 | * be zeroed when the driver starts. We'll save the first values read |
| 455 | * and use them as offsets to be subtracted from the raw values in order |
| 456 | * to report stats that count from zero. In the process, we also manage |
| 457 | * the potential roll-over. |
| 458 | **/ |
| 459 | static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, |
| 460 | bool offset_loaded, u64 *offset, u64 *stat) |
| 461 | { |
| 462 | u64 new_data; |
| 463 | |
| 464 | if (hw->device_id == I40E_QEMU_DEVICE_ID) { |
| 465 | new_data = rd32(hw, loreg); |
| 466 | new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; |
| 467 | } else { |
| 468 | new_data = rd64(hw, loreg); |
| 469 | } |
| 470 | if (!offset_loaded) |
| 471 | *offset = new_data; |
| 472 | if (likely(new_data >= *offset)) |
| 473 | *stat = new_data - *offset; |
| 474 | else |
| 475 | *stat = (new_data + ((u64)1 << 48)) - *offset; |
| 476 | *stat &= 0xFFFFFFFFFFFFULL; |
| 477 | } |
| 478 | |
| 479 | /** |
| 480 | * i40e_stat_update32 - read and update a 32 bit stat from the chip |
| 481 | * @hw: ptr to the hardware info |
| 482 | * @reg: the hw reg to read |
| 483 | * @offset_loaded: has the initial offset been loaded yet |
| 484 | * @offset: ptr to current offset value |
| 485 | * @stat: ptr to the stat |
| 486 | **/ |
| 487 | static void i40e_stat_update32(struct i40e_hw *hw, u32 reg, |
| 488 | bool offset_loaded, u64 *offset, u64 *stat) |
| 489 | { |
| 490 | u32 new_data; |
| 491 | |
| 492 | new_data = rd32(hw, reg); |
| 493 | if (!offset_loaded) |
| 494 | *offset = new_data; |
| 495 | if (likely(new_data >= *offset)) |
| 496 | *stat = (u32)(new_data - *offset); |
| 497 | else |
| 498 | *stat = (u32)((new_data + ((u64)1 << 32)) - *offset); |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. |
| 503 | * @vsi: the VSI to be updated |
| 504 | **/ |
| 505 | void i40e_update_eth_stats(struct i40e_vsi *vsi) |
| 506 | { |
| 507 | int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); |
| 508 | struct i40e_pf *pf = vsi->back; |
| 509 | struct i40e_hw *hw = &pf->hw; |
| 510 | struct i40e_eth_stats *oes; |
| 511 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 512 | |
| 513 | es = &vsi->eth_stats; |
| 514 | oes = &vsi->eth_stats_offsets; |
| 515 | |
| 516 | /* Gather up the stats that the hw collects */ |
| 517 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 518 | vsi->stat_offsets_loaded, |
| 519 | &oes->tx_errors, &es->tx_errors); |
| 520 | i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), |
| 521 | vsi->stat_offsets_loaded, |
| 522 | &oes->rx_discards, &es->rx_discards); |
| 523 | |
| 524 | i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), |
| 525 | I40E_GLV_GORCL(stat_idx), |
| 526 | vsi->stat_offsets_loaded, |
| 527 | &oes->rx_bytes, &es->rx_bytes); |
| 528 | i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), |
| 529 | I40E_GLV_UPRCL(stat_idx), |
| 530 | vsi->stat_offsets_loaded, |
| 531 | &oes->rx_unicast, &es->rx_unicast); |
| 532 | i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), |
| 533 | I40E_GLV_MPRCL(stat_idx), |
| 534 | vsi->stat_offsets_loaded, |
| 535 | &oes->rx_multicast, &es->rx_multicast); |
| 536 | i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), |
| 537 | I40E_GLV_BPRCL(stat_idx), |
| 538 | vsi->stat_offsets_loaded, |
| 539 | &oes->rx_broadcast, &es->rx_broadcast); |
| 540 | |
| 541 | i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), |
| 542 | I40E_GLV_GOTCL(stat_idx), |
| 543 | vsi->stat_offsets_loaded, |
| 544 | &oes->tx_bytes, &es->tx_bytes); |
| 545 | i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), |
| 546 | I40E_GLV_UPTCL(stat_idx), |
| 547 | vsi->stat_offsets_loaded, |
| 548 | &oes->tx_unicast, &es->tx_unicast); |
| 549 | i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), |
| 550 | I40E_GLV_MPTCL(stat_idx), |
| 551 | vsi->stat_offsets_loaded, |
| 552 | &oes->tx_multicast, &es->tx_multicast); |
| 553 | i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), |
| 554 | I40E_GLV_BPTCL(stat_idx), |
| 555 | vsi->stat_offsets_loaded, |
| 556 | &oes->tx_broadcast, &es->tx_broadcast); |
| 557 | vsi->stat_offsets_loaded = true; |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * i40e_update_veb_stats - Update Switch component statistics |
| 562 | * @veb: the VEB being updated |
| 563 | **/ |
| 564 | static void i40e_update_veb_stats(struct i40e_veb *veb) |
| 565 | { |
| 566 | struct i40e_pf *pf = veb->pf; |
| 567 | struct i40e_hw *hw = &pf->hw; |
| 568 | struct i40e_eth_stats *oes; |
| 569 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 570 | int idx = 0; |
| 571 | |
| 572 | idx = veb->stats_idx; |
| 573 | es = &veb->stats; |
| 574 | oes = &veb->stats_offsets; |
| 575 | |
| 576 | /* Gather up the stats that the hw collects */ |
| 577 | i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), |
| 578 | veb->stat_offsets_loaded, |
| 579 | &oes->tx_discards, &es->tx_discards); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 580 | if (hw->revision_id > 0) |
| 581 | i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), |
| 582 | veb->stat_offsets_loaded, |
| 583 | &oes->rx_unknown_protocol, |
| 584 | &es->rx_unknown_protocol); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 585 | i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), |
| 586 | veb->stat_offsets_loaded, |
| 587 | &oes->rx_bytes, &es->rx_bytes); |
| 588 | i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), |
| 589 | veb->stat_offsets_loaded, |
| 590 | &oes->rx_unicast, &es->rx_unicast); |
| 591 | i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), |
| 592 | veb->stat_offsets_loaded, |
| 593 | &oes->rx_multicast, &es->rx_multicast); |
| 594 | i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), |
| 595 | veb->stat_offsets_loaded, |
| 596 | &oes->rx_broadcast, &es->rx_broadcast); |
| 597 | |
| 598 | i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), |
| 599 | veb->stat_offsets_loaded, |
| 600 | &oes->tx_bytes, &es->tx_bytes); |
| 601 | i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), |
| 602 | veb->stat_offsets_loaded, |
| 603 | &oes->tx_unicast, &es->tx_unicast); |
| 604 | i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), |
| 605 | veb->stat_offsets_loaded, |
| 606 | &oes->tx_multicast, &es->tx_multicast); |
| 607 | i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), |
| 608 | veb->stat_offsets_loaded, |
| 609 | &oes->tx_broadcast, &es->tx_broadcast); |
| 610 | veb->stat_offsets_loaded = true; |
| 611 | } |
| 612 | |
| 613 | /** |
| 614 | * i40e_update_link_xoff_rx - Update XOFF received in link flow control mode |
| 615 | * @pf: the corresponding PF |
| 616 | * |
| 617 | * Update the Rx XOFF counter (PAUSE frames) in link flow control mode |
| 618 | **/ |
| 619 | static void i40e_update_link_xoff_rx(struct i40e_pf *pf) |
| 620 | { |
| 621 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 622 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 623 | struct i40e_hw *hw = &pf->hw; |
| 624 | u64 xoff = 0; |
| 625 | u16 i, v; |
| 626 | |
| 627 | if ((hw->fc.current_mode != I40E_FC_FULL) && |
| 628 | (hw->fc.current_mode != I40E_FC_RX_PAUSE)) |
| 629 | return; |
| 630 | |
| 631 | xoff = nsd->link_xoff_rx; |
| 632 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), |
| 633 | pf->stat_offsets_loaded, |
| 634 | &osd->link_xoff_rx, &nsd->link_xoff_rx); |
| 635 | |
| 636 | /* No new LFC xoff rx */ |
| 637 | if (!(nsd->link_xoff_rx - xoff)) |
| 638 | return; |
| 639 | |
| 640 | /* Clear the __I40E_HANG_CHECK_ARMED bit for all Tx rings */ |
| 641 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 642 | struct i40e_vsi *vsi = pf->vsi[v]; |
| 643 | |
| 644 | if (!vsi) |
| 645 | continue; |
| 646 | |
| 647 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 648 | struct i40e_ring *ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 649 | clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state); |
| 650 | } |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | /** |
| 655 | * i40e_update_prio_xoff_rx - Update XOFF received in PFC mode |
| 656 | * @pf: the corresponding PF |
| 657 | * |
| 658 | * Update the Rx XOFF counter (PAUSE frames) in PFC mode |
| 659 | **/ |
| 660 | static void i40e_update_prio_xoff_rx(struct i40e_pf *pf) |
| 661 | { |
| 662 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 663 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 664 | bool xoff[I40E_MAX_TRAFFIC_CLASS] = {false}; |
| 665 | struct i40e_dcbx_config *dcb_cfg; |
| 666 | struct i40e_hw *hw = &pf->hw; |
| 667 | u16 i, v; |
| 668 | u8 tc; |
| 669 | |
| 670 | dcb_cfg = &hw->local_dcbx_config; |
| 671 | |
| 672 | /* See if DCB enabled with PFC TC */ |
| 673 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED) || |
| 674 | !(dcb_cfg->pfc.pfcenable)) { |
| 675 | i40e_update_link_xoff_rx(pf); |
| 676 | return; |
| 677 | } |
| 678 | |
| 679 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 680 | u64 prio_xoff = nsd->priority_xoff_rx[i]; |
| 681 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), |
| 682 | pf->stat_offsets_loaded, |
| 683 | &osd->priority_xoff_rx[i], |
| 684 | &nsd->priority_xoff_rx[i]); |
| 685 | |
| 686 | /* No new PFC xoff rx */ |
| 687 | if (!(nsd->priority_xoff_rx[i] - prio_xoff)) |
| 688 | continue; |
| 689 | /* Get the TC for given priority */ |
| 690 | tc = dcb_cfg->etscfg.prioritytable[i]; |
| 691 | xoff[tc] = true; |
| 692 | } |
| 693 | |
| 694 | /* Clear the __I40E_HANG_CHECK_ARMED bit for Tx rings */ |
| 695 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 696 | struct i40e_vsi *vsi = pf->vsi[v]; |
| 697 | |
| 698 | if (!vsi) |
| 699 | continue; |
| 700 | |
| 701 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 702 | struct i40e_ring *ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 703 | |
| 704 | tc = ring->dcb_tc; |
| 705 | if (xoff[tc]) |
| 706 | clear_bit(__I40E_HANG_CHECK_ARMED, |
| 707 | &ring->state); |
| 708 | } |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | /** |
| 713 | * i40e_update_stats - Update the board statistics counters. |
| 714 | * @vsi: the VSI to be updated |
| 715 | * |
| 716 | * There are a few instances where we store the same stat in a |
| 717 | * couple of different structs. This is partly because we have |
| 718 | * the netdev stats that need to be filled out, which is slightly |
| 719 | * different from the "eth_stats" defined by the chip and used in |
| 720 | * VF communications. We sort it all out here in a central place. |
| 721 | **/ |
| 722 | void i40e_update_stats(struct i40e_vsi *vsi) |
| 723 | { |
| 724 | struct i40e_pf *pf = vsi->back; |
| 725 | struct i40e_hw *hw = &pf->hw; |
| 726 | struct rtnl_link_stats64 *ons; |
| 727 | struct rtnl_link_stats64 *ns; /* netdev stats */ |
| 728 | struct i40e_eth_stats *oes; |
| 729 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 730 | u32 tx_restart, tx_busy; |
| 731 | u32 rx_page, rx_buf; |
| 732 | u64 rx_p, rx_b; |
| 733 | u64 tx_p, tx_b; |
| 734 | int i; |
| 735 | u16 q; |
| 736 | |
| 737 | if (test_bit(__I40E_DOWN, &vsi->state) || |
| 738 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 739 | return; |
| 740 | |
| 741 | ns = i40e_get_vsi_stats_struct(vsi); |
| 742 | ons = &vsi->net_stats_offsets; |
| 743 | es = &vsi->eth_stats; |
| 744 | oes = &vsi->eth_stats_offsets; |
| 745 | |
| 746 | /* Gather up the netdev and vsi stats that the driver collects |
| 747 | * on the fly during packet processing |
| 748 | */ |
| 749 | rx_b = rx_p = 0; |
| 750 | tx_b = tx_p = 0; |
| 751 | tx_restart = tx_busy = 0; |
| 752 | rx_page = 0; |
| 753 | rx_buf = 0; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 754 | rcu_read_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 755 | for (q = 0; q < vsi->num_queue_pairs; q++) { |
| 756 | struct i40e_ring *p; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 757 | u64 bytes, packets; |
| 758 | unsigned int start; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 759 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 760 | /* locate Tx ring */ |
| 761 | p = ACCESS_ONCE(vsi->tx_rings[q]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 762 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 763 | do { |
| 764 | start = u64_stats_fetch_begin_bh(&p->syncp); |
| 765 | packets = p->stats.packets; |
| 766 | bytes = p->stats.bytes; |
| 767 | } while (u64_stats_fetch_retry_bh(&p->syncp, start)); |
| 768 | tx_b += bytes; |
| 769 | tx_p += packets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 770 | tx_restart += p->tx_stats.restart_queue; |
| 771 | tx_busy += p->tx_stats.tx_busy; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 772 | |
| 773 | /* Rx queue is part of the same block as Tx queue */ |
| 774 | p = &p[1]; |
| 775 | do { |
| 776 | start = u64_stats_fetch_begin_bh(&p->syncp); |
| 777 | packets = p->stats.packets; |
| 778 | bytes = p->stats.bytes; |
| 779 | } while (u64_stats_fetch_retry_bh(&p->syncp, start)); |
| 780 | rx_b += bytes; |
| 781 | rx_p += packets; |
| 782 | rx_buf += p->rx_stats.alloc_rx_buff_failed; |
| 783 | rx_page += p->rx_stats.alloc_rx_page_failed; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 784 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 785 | rcu_read_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 786 | vsi->tx_restart = tx_restart; |
| 787 | vsi->tx_busy = tx_busy; |
| 788 | vsi->rx_page_failed = rx_page; |
| 789 | vsi->rx_buf_failed = rx_buf; |
| 790 | |
| 791 | ns->rx_packets = rx_p; |
| 792 | ns->rx_bytes = rx_b; |
| 793 | ns->tx_packets = tx_p; |
| 794 | ns->tx_bytes = tx_b; |
| 795 | |
| 796 | i40e_update_eth_stats(vsi); |
| 797 | /* update netdev stats from eth stats */ |
| 798 | ons->rx_errors = oes->rx_errors; |
| 799 | ns->rx_errors = es->rx_errors; |
| 800 | ons->tx_errors = oes->tx_errors; |
| 801 | ns->tx_errors = es->tx_errors; |
| 802 | ons->multicast = oes->rx_multicast; |
| 803 | ns->multicast = es->rx_multicast; |
| 804 | ons->tx_dropped = oes->tx_discards; |
| 805 | ns->tx_dropped = es->tx_discards; |
| 806 | |
| 807 | /* Get the port data only if this is the main PF VSI */ |
| 808 | if (vsi == pf->vsi[pf->lan_vsi]) { |
| 809 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 810 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 811 | |
| 812 | i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), |
| 813 | I40E_GLPRT_GORCL(hw->port), |
| 814 | pf->stat_offsets_loaded, |
| 815 | &osd->eth.rx_bytes, &nsd->eth.rx_bytes); |
| 816 | i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), |
| 817 | I40E_GLPRT_GOTCL(hw->port), |
| 818 | pf->stat_offsets_loaded, |
| 819 | &osd->eth.tx_bytes, &nsd->eth.tx_bytes); |
| 820 | i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), |
| 821 | pf->stat_offsets_loaded, |
| 822 | &osd->eth.rx_discards, |
| 823 | &nsd->eth.rx_discards); |
| 824 | i40e_stat_update32(hw, I40E_GLPRT_TDPC(hw->port), |
| 825 | pf->stat_offsets_loaded, |
| 826 | &osd->eth.tx_discards, |
| 827 | &nsd->eth.tx_discards); |
| 828 | i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), |
| 829 | I40E_GLPRT_MPRCL(hw->port), |
| 830 | pf->stat_offsets_loaded, |
| 831 | &osd->eth.rx_multicast, |
| 832 | &nsd->eth.rx_multicast); |
| 833 | |
| 834 | i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), |
| 835 | pf->stat_offsets_loaded, |
| 836 | &osd->tx_dropped_link_down, |
| 837 | &nsd->tx_dropped_link_down); |
| 838 | |
| 839 | i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), |
| 840 | pf->stat_offsets_loaded, |
| 841 | &osd->crc_errors, &nsd->crc_errors); |
| 842 | ns->rx_crc_errors = nsd->crc_errors; |
| 843 | |
| 844 | i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), |
| 845 | pf->stat_offsets_loaded, |
| 846 | &osd->illegal_bytes, &nsd->illegal_bytes); |
| 847 | ns->rx_errors = nsd->crc_errors |
| 848 | + nsd->illegal_bytes; |
| 849 | |
| 850 | i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), |
| 851 | pf->stat_offsets_loaded, |
| 852 | &osd->mac_local_faults, |
| 853 | &nsd->mac_local_faults); |
| 854 | i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), |
| 855 | pf->stat_offsets_loaded, |
| 856 | &osd->mac_remote_faults, |
| 857 | &nsd->mac_remote_faults); |
| 858 | |
| 859 | i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), |
| 860 | pf->stat_offsets_loaded, |
| 861 | &osd->rx_length_errors, |
| 862 | &nsd->rx_length_errors); |
| 863 | ns->rx_length_errors = nsd->rx_length_errors; |
| 864 | |
| 865 | i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), |
| 866 | pf->stat_offsets_loaded, |
| 867 | &osd->link_xon_rx, &nsd->link_xon_rx); |
| 868 | i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), |
| 869 | pf->stat_offsets_loaded, |
| 870 | &osd->link_xon_tx, &nsd->link_xon_tx); |
| 871 | i40e_update_prio_xoff_rx(pf); /* handles I40E_GLPRT_LXOFFRXC */ |
| 872 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), |
| 873 | pf->stat_offsets_loaded, |
| 874 | &osd->link_xoff_tx, &nsd->link_xoff_tx); |
| 875 | |
| 876 | for (i = 0; i < 8; i++) { |
| 877 | i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), |
| 878 | pf->stat_offsets_loaded, |
| 879 | &osd->priority_xon_rx[i], |
| 880 | &nsd->priority_xon_rx[i]); |
| 881 | i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), |
| 882 | pf->stat_offsets_loaded, |
| 883 | &osd->priority_xon_tx[i], |
| 884 | &nsd->priority_xon_tx[i]); |
| 885 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), |
| 886 | pf->stat_offsets_loaded, |
| 887 | &osd->priority_xoff_tx[i], |
| 888 | &nsd->priority_xoff_tx[i]); |
| 889 | i40e_stat_update32(hw, |
| 890 | I40E_GLPRT_RXON2OFFCNT(hw->port, i), |
| 891 | pf->stat_offsets_loaded, |
| 892 | &osd->priority_xon_2_xoff[i], |
| 893 | &nsd->priority_xon_2_xoff[i]); |
| 894 | } |
| 895 | |
| 896 | i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), |
| 897 | I40E_GLPRT_PRC64L(hw->port), |
| 898 | pf->stat_offsets_loaded, |
| 899 | &osd->rx_size_64, &nsd->rx_size_64); |
| 900 | i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), |
| 901 | I40E_GLPRT_PRC127L(hw->port), |
| 902 | pf->stat_offsets_loaded, |
| 903 | &osd->rx_size_127, &nsd->rx_size_127); |
| 904 | i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), |
| 905 | I40E_GLPRT_PRC255L(hw->port), |
| 906 | pf->stat_offsets_loaded, |
| 907 | &osd->rx_size_255, &nsd->rx_size_255); |
| 908 | i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), |
| 909 | I40E_GLPRT_PRC511L(hw->port), |
| 910 | pf->stat_offsets_loaded, |
| 911 | &osd->rx_size_511, &nsd->rx_size_511); |
| 912 | i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), |
| 913 | I40E_GLPRT_PRC1023L(hw->port), |
| 914 | pf->stat_offsets_loaded, |
| 915 | &osd->rx_size_1023, &nsd->rx_size_1023); |
| 916 | i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), |
| 917 | I40E_GLPRT_PRC1522L(hw->port), |
| 918 | pf->stat_offsets_loaded, |
| 919 | &osd->rx_size_1522, &nsd->rx_size_1522); |
| 920 | i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), |
| 921 | I40E_GLPRT_PRC9522L(hw->port), |
| 922 | pf->stat_offsets_loaded, |
| 923 | &osd->rx_size_big, &nsd->rx_size_big); |
| 924 | |
| 925 | i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), |
| 926 | I40E_GLPRT_PTC64L(hw->port), |
| 927 | pf->stat_offsets_loaded, |
| 928 | &osd->tx_size_64, &nsd->tx_size_64); |
| 929 | i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), |
| 930 | I40E_GLPRT_PTC127L(hw->port), |
| 931 | pf->stat_offsets_loaded, |
| 932 | &osd->tx_size_127, &nsd->tx_size_127); |
| 933 | i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), |
| 934 | I40E_GLPRT_PTC255L(hw->port), |
| 935 | pf->stat_offsets_loaded, |
| 936 | &osd->tx_size_255, &nsd->tx_size_255); |
| 937 | i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), |
| 938 | I40E_GLPRT_PTC511L(hw->port), |
| 939 | pf->stat_offsets_loaded, |
| 940 | &osd->tx_size_511, &nsd->tx_size_511); |
| 941 | i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), |
| 942 | I40E_GLPRT_PTC1023L(hw->port), |
| 943 | pf->stat_offsets_loaded, |
| 944 | &osd->tx_size_1023, &nsd->tx_size_1023); |
| 945 | i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), |
| 946 | I40E_GLPRT_PTC1522L(hw->port), |
| 947 | pf->stat_offsets_loaded, |
| 948 | &osd->tx_size_1522, &nsd->tx_size_1522); |
| 949 | i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), |
| 950 | I40E_GLPRT_PTC9522L(hw->port), |
| 951 | pf->stat_offsets_loaded, |
| 952 | &osd->tx_size_big, &nsd->tx_size_big); |
| 953 | |
| 954 | i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), |
| 955 | pf->stat_offsets_loaded, |
| 956 | &osd->rx_undersize, &nsd->rx_undersize); |
| 957 | i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), |
| 958 | pf->stat_offsets_loaded, |
| 959 | &osd->rx_fragments, &nsd->rx_fragments); |
| 960 | i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), |
| 961 | pf->stat_offsets_loaded, |
| 962 | &osd->rx_oversize, &nsd->rx_oversize); |
| 963 | i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), |
| 964 | pf->stat_offsets_loaded, |
| 965 | &osd->rx_jabber, &nsd->rx_jabber); |
| 966 | } |
| 967 | |
| 968 | pf->stat_offsets_loaded = true; |
| 969 | } |
| 970 | |
| 971 | /** |
| 972 | * i40e_find_filter - Search VSI filter list for specific mac/vlan filter |
| 973 | * @vsi: the VSI to be searched |
| 974 | * @macaddr: the MAC address |
| 975 | * @vlan: the vlan |
| 976 | * @is_vf: make sure its a vf filter, else doesn't matter |
| 977 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 978 | * |
| 979 | * Returns ptr to the filter object or NULL |
| 980 | **/ |
| 981 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, |
| 982 | u8 *macaddr, s16 vlan, |
| 983 | bool is_vf, bool is_netdev) |
| 984 | { |
| 985 | struct i40e_mac_filter *f; |
| 986 | |
| 987 | if (!vsi || !macaddr) |
| 988 | return NULL; |
| 989 | |
| 990 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 991 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 992 | (vlan == f->vlan) && |
| 993 | (!is_vf || f->is_vf) && |
| 994 | (!is_netdev || f->is_netdev)) |
| 995 | return f; |
| 996 | } |
| 997 | return NULL; |
| 998 | } |
| 999 | |
| 1000 | /** |
| 1001 | * i40e_find_mac - Find a mac addr in the macvlan filters list |
| 1002 | * @vsi: the VSI to be searched |
| 1003 | * @macaddr: the MAC address we are searching for |
| 1004 | * @is_vf: make sure its a vf filter, else doesn't matter |
| 1005 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1006 | * |
| 1007 | * Returns the first filter with the provided MAC address or NULL if |
| 1008 | * MAC address was not found |
| 1009 | **/ |
| 1010 | struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr, |
| 1011 | bool is_vf, bool is_netdev) |
| 1012 | { |
| 1013 | struct i40e_mac_filter *f; |
| 1014 | |
| 1015 | if (!vsi || !macaddr) |
| 1016 | return NULL; |
| 1017 | |
| 1018 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1019 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1020 | (!is_vf || f->is_vf) && |
| 1021 | (!is_netdev || f->is_netdev)) |
| 1022 | return f; |
| 1023 | } |
| 1024 | return NULL; |
| 1025 | } |
| 1026 | |
| 1027 | /** |
| 1028 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode |
| 1029 | * @vsi: the VSI to be searched |
| 1030 | * |
| 1031 | * Returns true if VSI is in vlan mode or false otherwise |
| 1032 | **/ |
| 1033 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) |
| 1034 | { |
| 1035 | struct i40e_mac_filter *f; |
| 1036 | |
| 1037 | /* Only -1 for all the filters denotes not in vlan mode |
| 1038 | * so we have to go through all the list in order to make sure |
| 1039 | */ |
| 1040 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1041 | if (f->vlan >= 0) |
| 1042 | return true; |
| 1043 | } |
| 1044 | |
| 1045 | return false; |
| 1046 | } |
| 1047 | |
| 1048 | /** |
| 1049 | * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans |
| 1050 | * @vsi: the VSI to be searched |
| 1051 | * @macaddr: the mac address to be filtered |
| 1052 | * @is_vf: true if it is a vf |
| 1053 | * @is_netdev: true if it is a netdev |
| 1054 | * |
| 1055 | * Goes through all the macvlan filters and adds a |
| 1056 | * macvlan filter for each unique vlan that already exists |
| 1057 | * |
| 1058 | * Returns first filter found on success, else NULL |
| 1059 | **/ |
| 1060 | struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1061 | bool is_vf, bool is_netdev) |
| 1062 | { |
| 1063 | struct i40e_mac_filter *f; |
| 1064 | |
| 1065 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1066 | if (!i40e_find_filter(vsi, macaddr, f->vlan, |
| 1067 | is_vf, is_netdev)) { |
| 1068 | if (!i40e_add_filter(vsi, macaddr, f->vlan, |
| 1069 | is_vf, is_netdev)) |
| 1070 | return NULL; |
| 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | return list_first_entry_or_null(&vsi->mac_filter_list, |
| 1075 | struct i40e_mac_filter, list); |
| 1076 | } |
| 1077 | |
| 1078 | /** |
| 1079 | * i40e_add_filter - Add a mac/vlan filter to the VSI |
| 1080 | * @vsi: the VSI to be searched |
| 1081 | * @macaddr: the MAC address |
| 1082 | * @vlan: the vlan |
| 1083 | * @is_vf: make sure its a vf filter, else doesn't matter |
| 1084 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1085 | * |
| 1086 | * Returns ptr to the filter object or NULL when no memory available. |
| 1087 | **/ |
| 1088 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, |
| 1089 | u8 *macaddr, s16 vlan, |
| 1090 | bool is_vf, bool is_netdev) |
| 1091 | { |
| 1092 | struct i40e_mac_filter *f; |
| 1093 | |
| 1094 | if (!vsi || !macaddr) |
| 1095 | return NULL; |
| 1096 | |
| 1097 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1098 | if (!f) { |
| 1099 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1100 | if (!f) |
| 1101 | goto add_filter_out; |
| 1102 | |
| 1103 | memcpy(f->macaddr, macaddr, ETH_ALEN); |
| 1104 | f->vlan = vlan; |
| 1105 | f->changed = true; |
| 1106 | |
| 1107 | INIT_LIST_HEAD(&f->list); |
| 1108 | list_add(&f->list, &vsi->mac_filter_list); |
| 1109 | } |
| 1110 | |
| 1111 | /* increment counter and add a new flag if needed */ |
| 1112 | if (is_vf) { |
| 1113 | if (!f->is_vf) { |
| 1114 | f->is_vf = true; |
| 1115 | f->counter++; |
| 1116 | } |
| 1117 | } else if (is_netdev) { |
| 1118 | if (!f->is_netdev) { |
| 1119 | f->is_netdev = true; |
| 1120 | f->counter++; |
| 1121 | } |
| 1122 | } else { |
| 1123 | f->counter++; |
| 1124 | } |
| 1125 | |
| 1126 | /* changed tells sync_filters_subtask to |
| 1127 | * push the filter down to the firmware |
| 1128 | */ |
| 1129 | if (f->changed) { |
| 1130 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1131 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1132 | } |
| 1133 | |
| 1134 | add_filter_out: |
| 1135 | return f; |
| 1136 | } |
| 1137 | |
| 1138 | /** |
| 1139 | * i40e_del_filter - Remove a mac/vlan filter from the VSI |
| 1140 | * @vsi: the VSI to be searched |
| 1141 | * @macaddr: the MAC address |
| 1142 | * @vlan: the vlan |
| 1143 | * @is_vf: make sure it's a vf filter, else doesn't matter |
| 1144 | * @is_netdev: make sure it's a netdev filter, else doesn't matter |
| 1145 | **/ |
| 1146 | void i40e_del_filter(struct i40e_vsi *vsi, |
| 1147 | u8 *macaddr, s16 vlan, |
| 1148 | bool is_vf, bool is_netdev) |
| 1149 | { |
| 1150 | struct i40e_mac_filter *f; |
| 1151 | |
| 1152 | if (!vsi || !macaddr) |
| 1153 | return; |
| 1154 | |
| 1155 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1156 | if (!f || f->counter == 0) |
| 1157 | return; |
| 1158 | |
| 1159 | if (is_vf) { |
| 1160 | if (f->is_vf) { |
| 1161 | f->is_vf = false; |
| 1162 | f->counter--; |
| 1163 | } |
| 1164 | } else if (is_netdev) { |
| 1165 | if (f->is_netdev) { |
| 1166 | f->is_netdev = false; |
| 1167 | f->counter--; |
| 1168 | } |
| 1169 | } else { |
| 1170 | /* make sure we don't remove a filter in use by vf or netdev */ |
| 1171 | int min_f = 0; |
| 1172 | min_f += (f->is_vf ? 1 : 0); |
| 1173 | min_f += (f->is_netdev ? 1 : 0); |
| 1174 | |
| 1175 | if (f->counter > min_f) |
| 1176 | f->counter--; |
| 1177 | } |
| 1178 | |
| 1179 | /* counter == 0 tells sync_filters_subtask to |
| 1180 | * remove the filter from the firmware's list |
| 1181 | */ |
| 1182 | if (f->counter == 0) { |
| 1183 | f->changed = true; |
| 1184 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1185 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | /** |
| 1190 | * i40e_set_mac - NDO callback to set mac address |
| 1191 | * @netdev: network interface device structure |
| 1192 | * @p: pointer to an address structure |
| 1193 | * |
| 1194 | * Returns 0 on success, negative on failure |
| 1195 | **/ |
| 1196 | static int i40e_set_mac(struct net_device *netdev, void *p) |
| 1197 | { |
| 1198 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1199 | struct i40e_vsi *vsi = np->vsi; |
| 1200 | struct sockaddr *addr = p; |
| 1201 | struct i40e_mac_filter *f; |
| 1202 | |
| 1203 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1204 | return -EADDRNOTAVAIL; |
| 1205 | |
| 1206 | netdev_info(netdev, "set mac address=%pM\n", addr->sa_data); |
| 1207 | |
| 1208 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) |
| 1209 | return 0; |
| 1210 | |
| 1211 | if (vsi->type == I40E_VSI_MAIN) { |
| 1212 | i40e_status ret; |
| 1213 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
| 1214 | I40E_AQC_WRITE_TYPE_LAA_ONLY, |
| 1215 | addr->sa_data, NULL); |
| 1216 | if (ret) { |
| 1217 | netdev_info(netdev, |
| 1218 | "Addr change for Main VSI failed: %d\n", |
| 1219 | ret); |
| 1220 | return -EADDRNOTAVAIL; |
| 1221 | } |
| 1222 | |
| 1223 | memcpy(vsi->back->hw.mac.addr, addr->sa_data, netdev->addr_len); |
| 1224 | } |
| 1225 | |
| 1226 | /* In order to be sure to not drop any packets, add the new address |
| 1227 | * then delete the old one. |
| 1228 | */ |
| 1229 | f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY, false, false); |
| 1230 | if (!f) |
| 1231 | return -ENOMEM; |
| 1232 | |
| 1233 | i40e_sync_vsi_filters(vsi); |
| 1234 | i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, false, false); |
| 1235 | i40e_sync_vsi_filters(vsi); |
| 1236 | |
| 1237 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 1238 | |
| 1239 | return 0; |
| 1240 | } |
| 1241 | |
| 1242 | /** |
| 1243 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1244 | * @vsi: the VSI being setup |
| 1245 | * @ctxt: VSI context structure |
| 1246 | * @enabled_tc: Enabled TCs bitmap |
| 1247 | * @is_add: True if called before Add VSI |
| 1248 | * |
| 1249 | * Setup VSI queue mapping for enabled traffic classes. |
| 1250 | **/ |
| 1251 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1252 | struct i40e_vsi_context *ctxt, |
| 1253 | u8 enabled_tc, |
| 1254 | bool is_add) |
| 1255 | { |
| 1256 | struct i40e_pf *pf = vsi->back; |
| 1257 | u16 sections = 0; |
| 1258 | u8 netdev_tc = 0; |
| 1259 | u16 numtc = 0; |
| 1260 | u16 qcount; |
| 1261 | u8 offset; |
| 1262 | u16 qmap; |
| 1263 | int i; |
| 1264 | |
| 1265 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1266 | offset = 0; |
| 1267 | |
| 1268 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1269 | /* Find numtc from enabled TC bitmap */ |
| 1270 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1271 | if (enabled_tc & (1 << i)) /* TC is enabled */ |
| 1272 | numtc++; |
| 1273 | } |
| 1274 | if (!numtc) { |
| 1275 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1276 | numtc = 1; |
| 1277 | } |
| 1278 | } else { |
| 1279 | /* At least TC0 is enabled in case of non-DCB case */ |
| 1280 | numtc = 1; |
| 1281 | } |
| 1282 | |
| 1283 | vsi->tc_config.numtc = numtc; |
| 1284 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
| 1285 | |
| 1286 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1287 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1288 | /* See if the given TC is enabled for the given VSI */ |
| 1289 | if (vsi->tc_config.enabled_tc & (1 << i)) { /* TC is enabled */ |
| 1290 | int pow, num_qps; |
| 1291 | |
| 1292 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1293 | switch (vsi->type) { |
| 1294 | case I40E_VSI_MAIN: |
| 1295 | if (i == 0) |
| 1296 | qcount = pf->rss_size; |
| 1297 | else |
| 1298 | qcount = pf->num_tc_qps; |
| 1299 | vsi->tc_config.tc_info[i].qcount = qcount; |
| 1300 | break; |
| 1301 | case I40E_VSI_FDIR: |
| 1302 | case I40E_VSI_SRIOV: |
| 1303 | case I40E_VSI_VMDQ2: |
| 1304 | default: |
| 1305 | qcount = vsi->alloc_queue_pairs; |
| 1306 | vsi->tc_config.tc_info[i].qcount = qcount; |
| 1307 | WARN_ON(i != 0); |
| 1308 | break; |
| 1309 | } |
| 1310 | |
| 1311 | /* find the power-of-2 of the number of queue pairs */ |
| 1312 | num_qps = vsi->tc_config.tc_info[i].qcount; |
| 1313 | pow = 0; |
| 1314 | while (num_qps && |
| 1315 | ((1 << pow) < vsi->tc_config.tc_info[i].qcount)) { |
| 1316 | pow++; |
| 1317 | num_qps >>= 1; |
| 1318 | } |
| 1319 | |
| 1320 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1321 | qmap = |
| 1322 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1323 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1324 | |
| 1325 | offset += vsi->tc_config.tc_info[i].qcount; |
| 1326 | } else { |
| 1327 | /* TC is not enabled so set the offset to |
| 1328 | * default queue and allocate one queue |
| 1329 | * for the given TC. |
| 1330 | */ |
| 1331 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1332 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1333 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1334 | |
| 1335 | qmap = 0; |
| 1336 | } |
| 1337 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1338 | } |
| 1339 | |
| 1340 | /* Set actual Tx/Rx queue pairs */ |
| 1341 | vsi->num_queue_pairs = offset; |
| 1342 | |
| 1343 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1344 | if (is_add) { |
| 1345 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1346 | |
| 1347 | ctxt->info.up_enable_bits = enabled_tc; |
| 1348 | } |
| 1349 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1350 | ctxt->info.mapping_flags |= |
| 1351 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1352 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1353 | ctxt->info.queue_mapping[i] = |
| 1354 | cpu_to_le16(vsi->base_queue + i); |
| 1355 | } else { |
| 1356 | ctxt->info.mapping_flags |= |
| 1357 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1358 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1359 | } |
| 1360 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1361 | } |
| 1362 | |
| 1363 | /** |
| 1364 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1365 | * @netdev: network interface device structure |
| 1366 | **/ |
| 1367 | static void i40e_set_rx_mode(struct net_device *netdev) |
| 1368 | { |
| 1369 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1370 | struct i40e_mac_filter *f, *ftmp; |
| 1371 | struct i40e_vsi *vsi = np->vsi; |
| 1372 | struct netdev_hw_addr *uca; |
| 1373 | struct netdev_hw_addr *mca; |
| 1374 | struct netdev_hw_addr *ha; |
| 1375 | |
| 1376 | /* add addr if not already in the filter list */ |
| 1377 | netdev_for_each_uc_addr(uca, netdev) { |
| 1378 | if (!i40e_find_mac(vsi, uca->addr, false, true)) { |
| 1379 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1380 | i40e_put_mac_in_vlan(vsi, uca->addr, |
| 1381 | false, true); |
| 1382 | else |
| 1383 | i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY, |
| 1384 | false, true); |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | netdev_for_each_mc_addr(mca, netdev) { |
| 1389 | if (!i40e_find_mac(vsi, mca->addr, false, true)) { |
| 1390 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1391 | i40e_put_mac_in_vlan(vsi, mca->addr, |
| 1392 | false, true); |
| 1393 | else |
| 1394 | i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY, |
| 1395 | false, true); |
| 1396 | } |
| 1397 | } |
| 1398 | |
| 1399 | /* remove filter if not in netdev list */ |
| 1400 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1401 | bool found = false; |
| 1402 | |
| 1403 | if (!f->is_netdev) |
| 1404 | continue; |
| 1405 | |
| 1406 | if (is_multicast_ether_addr(f->macaddr)) { |
| 1407 | netdev_for_each_mc_addr(mca, netdev) { |
| 1408 | if (ether_addr_equal(mca->addr, f->macaddr)) { |
| 1409 | found = true; |
| 1410 | break; |
| 1411 | } |
| 1412 | } |
| 1413 | } else { |
| 1414 | netdev_for_each_uc_addr(uca, netdev) { |
| 1415 | if (ether_addr_equal(uca->addr, f->macaddr)) { |
| 1416 | found = true; |
| 1417 | break; |
| 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | for_each_dev_addr(netdev, ha) { |
| 1422 | if (ether_addr_equal(ha->addr, f->macaddr)) { |
| 1423 | found = true; |
| 1424 | break; |
| 1425 | } |
| 1426 | } |
| 1427 | } |
| 1428 | if (!found) |
| 1429 | i40e_del_filter( |
| 1430 | vsi, f->macaddr, I40E_VLAN_ANY, false, true); |
| 1431 | } |
| 1432 | |
| 1433 | /* check for other flag changes */ |
| 1434 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1435 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1436 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | /** |
| 1441 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 1442 | * @vsi: ptr to the VSI |
| 1443 | * |
| 1444 | * Push any outstanding VSI filter changes through the AdminQ. |
| 1445 | * |
| 1446 | * Returns 0 or error value |
| 1447 | **/ |
| 1448 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
| 1449 | { |
| 1450 | struct i40e_mac_filter *f, *ftmp; |
| 1451 | bool promisc_forced_on = false; |
| 1452 | bool add_happened = false; |
| 1453 | int filter_list_len = 0; |
| 1454 | u32 changed_flags = 0; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1455 | i40e_status aq_ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1456 | struct i40e_pf *pf; |
| 1457 | int num_add = 0; |
| 1458 | int num_del = 0; |
| 1459 | u16 cmd_flags; |
| 1460 | |
| 1461 | /* empty array typed pointers, kcalloc later */ |
| 1462 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 1463 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 1464 | |
| 1465 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 1466 | usleep_range(1000, 2000); |
| 1467 | pf = vsi->back; |
| 1468 | |
| 1469 | if (vsi->netdev) { |
| 1470 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 1471 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 1472 | } |
| 1473 | |
| 1474 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 1475 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 1476 | |
| 1477 | filter_list_len = pf->hw.aq.asq_buf_size / |
| 1478 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
| 1479 | del_list = kcalloc(filter_list_len, |
| 1480 | sizeof(struct i40e_aqc_remove_macvlan_element_data), |
| 1481 | GFP_KERNEL); |
| 1482 | if (!del_list) |
| 1483 | return -ENOMEM; |
| 1484 | |
| 1485 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1486 | if (!f->changed) |
| 1487 | continue; |
| 1488 | |
| 1489 | if (f->counter != 0) |
| 1490 | continue; |
| 1491 | f->changed = false; |
| 1492 | cmd_flags = 0; |
| 1493 | |
| 1494 | /* add to delete list */ |
| 1495 | memcpy(del_list[num_del].mac_addr, |
| 1496 | f->macaddr, ETH_ALEN); |
| 1497 | del_list[num_del].vlan_tag = |
| 1498 | cpu_to_le16((u16)(f->vlan == |
| 1499 | I40E_VLAN_ANY ? 0 : f->vlan)); |
| 1500 | |
| 1501 | /* vlan0 as wild card to allow packets from all vlans */ |
| 1502 | if (f->vlan == I40E_VLAN_ANY || |
| 1503 | (vsi->netdev && !(vsi->netdev->features & |
| 1504 | NETIF_F_HW_VLAN_CTAG_FILTER))) |
| 1505 | cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
| 1506 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1507 | del_list[num_del].flags = cmd_flags; |
| 1508 | num_del++; |
| 1509 | |
| 1510 | /* unlink from filter list */ |
| 1511 | list_del(&f->list); |
| 1512 | kfree(f); |
| 1513 | |
| 1514 | /* flush a full buffer */ |
| 1515 | if (num_del == filter_list_len) { |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1516 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1517 | vsi->seid, del_list, num_del, |
| 1518 | NULL); |
| 1519 | num_del = 0; |
| 1520 | memset(del_list, 0, sizeof(*del_list)); |
| 1521 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1522 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1523 | dev_info(&pf->pdev->dev, |
| 1524 | "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] | 1525 | aq_ret, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1526 | pf->hw.aq.asq_last_status); |
| 1527 | } |
| 1528 | } |
| 1529 | if (num_del) { |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1530 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1531 | del_list, num_del, NULL); |
| 1532 | num_del = 0; |
| 1533 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1534 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1535 | dev_info(&pf->pdev->dev, |
| 1536 | "ignoring delete macvlan error, err %d, aq_err %d\n", |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1537 | aq_ret, pf->hw.aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | kfree(del_list); |
| 1541 | del_list = NULL; |
| 1542 | |
| 1543 | /* do all the adds now */ |
| 1544 | filter_list_len = pf->hw.aq.asq_buf_size / |
| 1545 | sizeof(struct i40e_aqc_add_macvlan_element_data), |
| 1546 | add_list = kcalloc(filter_list_len, |
| 1547 | sizeof(struct i40e_aqc_add_macvlan_element_data), |
| 1548 | GFP_KERNEL); |
| 1549 | if (!add_list) |
| 1550 | return -ENOMEM; |
| 1551 | |
| 1552 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1553 | if (!f->changed) |
| 1554 | continue; |
| 1555 | |
| 1556 | if (f->counter == 0) |
| 1557 | continue; |
| 1558 | f->changed = false; |
| 1559 | add_happened = true; |
| 1560 | cmd_flags = 0; |
| 1561 | |
| 1562 | /* add to add array */ |
| 1563 | memcpy(add_list[num_add].mac_addr, |
| 1564 | f->macaddr, ETH_ALEN); |
| 1565 | add_list[num_add].vlan_tag = |
| 1566 | cpu_to_le16( |
| 1567 | (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan)); |
| 1568 | add_list[num_add].queue_number = 0; |
| 1569 | |
| 1570 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
| 1571 | |
| 1572 | /* vlan0 as wild card to allow packets from all vlans */ |
| 1573 | if (f->vlan == I40E_VLAN_ANY || (vsi->netdev && |
| 1574 | !(vsi->netdev->features & |
| 1575 | NETIF_F_HW_VLAN_CTAG_FILTER))) |
| 1576 | cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN; |
| 1577 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 1578 | num_add++; |
| 1579 | |
| 1580 | /* flush a full buffer */ |
| 1581 | if (num_add == filter_list_len) { |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1582 | aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, |
| 1583 | add_list, num_add, |
| 1584 | NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1585 | num_add = 0; |
| 1586 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1587 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1588 | break; |
| 1589 | memset(add_list, 0, sizeof(*add_list)); |
| 1590 | } |
| 1591 | } |
| 1592 | if (num_add) { |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1593 | aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, |
| 1594 | add_list, num_add, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1595 | num_add = 0; |
| 1596 | } |
| 1597 | kfree(add_list); |
| 1598 | add_list = NULL; |
| 1599 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1600 | if (add_happened && (!aq_ret)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1601 | /* do nothing */; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1602 | } else if (add_happened && (aq_ret)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1603 | dev_info(&pf->pdev->dev, |
| 1604 | "add filter failed, err %d, aq_err %d\n", |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1605 | aq_ret, pf->hw.aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1606 | if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) && |
| 1607 | !test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 1608 | &vsi->state)) { |
| 1609 | promisc_forced_on = true; |
| 1610 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 1611 | &vsi->state); |
| 1612 | dev_info(&pf->pdev->dev, "promiscuous mode forced on\n"); |
| 1613 | } |
| 1614 | } |
| 1615 | } |
| 1616 | |
| 1617 | /* check for changes in promiscuous modes */ |
| 1618 | if (changed_flags & IFF_ALLMULTI) { |
| 1619 | bool cur_multipromisc; |
| 1620 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1621 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 1622 | vsi->seid, |
| 1623 | cur_multipromisc, |
| 1624 | NULL); |
| 1625 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1626 | dev_info(&pf->pdev->dev, |
| 1627 | "set multi promisc failed, err %d, aq_err %d\n", |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1628 | aq_ret, pf->hw.aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1629 | } |
| 1630 | if ((changed_flags & IFF_PROMISC) || promisc_forced_on) { |
| 1631 | bool cur_promisc; |
| 1632 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
| 1633 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 1634 | &vsi->state)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1635 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous(&vsi->back->hw, |
| 1636 | vsi->seid, |
| 1637 | cur_promisc, NULL); |
| 1638 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1639 | dev_info(&pf->pdev->dev, |
| 1640 | "set uni promisc failed, err %d, aq_err %d\n", |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1641 | aq_ret, pf->hw.aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
| 1645 | return 0; |
| 1646 | } |
| 1647 | |
| 1648 | /** |
| 1649 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 1650 | * @pf: board private structure |
| 1651 | **/ |
| 1652 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 1653 | { |
| 1654 | int v; |
| 1655 | |
| 1656 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 1657 | return; |
| 1658 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 1659 | |
| 1660 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 1661 | if (pf->vsi[v] && |
| 1662 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) |
| 1663 | i40e_sync_vsi_filters(pf->vsi[v]); |
| 1664 | } |
| 1665 | } |
| 1666 | |
| 1667 | /** |
| 1668 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 1669 | * @netdev: network interface device structure |
| 1670 | * @new_mtu: new value for maximum frame size |
| 1671 | * |
| 1672 | * Returns 0 on success, negative on failure |
| 1673 | **/ |
| 1674 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 1675 | { |
| 1676 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1677 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 1678 | struct i40e_vsi *vsi = np->vsi; |
| 1679 | |
| 1680 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 1681 | if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER)) |
| 1682 | return -EINVAL; |
| 1683 | |
| 1684 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 1685 | netdev->mtu, new_mtu); |
| 1686 | netdev->mtu = new_mtu; |
| 1687 | if (netif_running(netdev)) |
| 1688 | i40e_vsi_reinit_locked(vsi); |
| 1689 | |
| 1690 | return 0; |
| 1691 | } |
| 1692 | |
| 1693 | /** |
| 1694 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 1695 | * @vsi: the vsi being adjusted |
| 1696 | **/ |
| 1697 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 1698 | { |
| 1699 | struct i40e_vsi_context ctxt; |
| 1700 | i40e_status ret; |
| 1701 | |
| 1702 | if ((vsi->info.valid_sections & |
| 1703 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 1704 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 1705 | return; /* already enabled */ |
| 1706 | |
| 1707 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 1708 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 1709 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 1710 | |
| 1711 | ctxt.seid = vsi->seid; |
| 1712 | memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info)); |
| 1713 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 1714 | if (ret) { |
| 1715 | dev_info(&vsi->back->pdev->dev, |
| 1716 | "%s: update vsi failed, aq_err=%d\n", |
| 1717 | __func__, vsi->back->hw.aq.asq_last_status); |
| 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | /** |
| 1722 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 1723 | * @vsi: the vsi being adjusted |
| 1724 | **/ |
| 1725 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 1726 | { |
| 1727 | struct i40e_vsi_context ctxt; |
| 1728 | i40e_status ret; |
| 1729 | |
| 1730 | if ((vsi->info.valid_sections & |
| 1731 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 1732 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 1733 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 1734 | return; /* already disabled */ |
| 1735 | |
| 1736 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 1737 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 1738 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 1739 | |
| 1740 | ctxt.seid = vsi->seid; |
| 1741 | memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info)); |
| 1742 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 1743 | if (ret) { |
| 1744 | dev_info(&vsi->back->pdev->dev, |
| 1745 | "%s: update vsi failed, aq_err=%d\n", |
| 1746 | __func__, vsi->back->hw.aq.asq_last_status); |
| 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | /** |
| 1751 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 1752 | * @netdev: network interface to be adjusted |
| 1753 | * @features: netdev features to test if VLAN offload is enabled or not |
| 1754 | **/ |
| 1755 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 1756 | { |
| 1757 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1758 | struct i40e_vsi *vsi = np->vsi; |
| 1759 | |
| 1760 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 1761 | i40e_vlan_stripping_enable(vsi); |
| 1762 | else |
| 1763 | i40e_vlan_stripping_disable(vsi); |
| 1764 | } |
| 1765 | |
| 1766 | /** |
| 1767 | * i40e_vsi_add_vlan - Add vsi membership for given vlan |
| 1768 | * @vsi: the vsi being configured |
| 1769 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
| 1770 | **/ |
| 1771 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid) |
| 1772 | { |
| 1773 | struct i40e_mac_filter *f, *add_f; |
| 1774 | bool is_netdev, is_vf; |
| 1775 | int ret; |
| 1776 | |
| 1777 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 1778 | is_netdev = !!(vsi->netdev); |
| 1779 | |
| 1780 | if (is_netdev) { |
| 1781 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid, |
| 1782 | is_vf, is_netdev); |
| 1783 | if (!add_f) { |
| 1784 | dev_info(&vsi->back->pdev->dev, |
| 1785 | "Could not add vlan filter %d for %pM\n", |
| 1786 | vid, vsi->netdev->dev_addr); |
| 1787 | return -ENOMEM; |
| 1788 | } |
| 1789 | } |
| 1790 | |
| 1791 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1792 | add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 1793 | if (!add_f) { |
| 1794 | dev_info(&vsi->back->pdev->dev, |
| 1795 | "Could not add vlan filter %d for %pM\n", |
| 1796 | vid, f->macaddr); |
| 1797 | return -ENOMEM; |
| 1798 | } |
| 1799 | } |
| 1800 | |
| 1801 | ret = i40e_sync_vsi_filters(vsi); |
| 1802 | if (ret) { |
| 1803 | dev_info(&vsi->back->pdev->dev, |
| 1804 | "Could not sync filters for vid %d\n", vid); |
| 1805 | return ret; |
| 1806 | } |
| 1807 | |
| 1808 | /* Now if we add a vlan tag, make sure to check if it is the first |
| 1809 | * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag" |
| 1810 | * with 0, so we now accept untagged and specified tagged traffic |
| 1811 | * (and not any taged and untagged) |
| 1812 | */ |
| 1813 | if (vid > 0) { |
| 1814 | if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr, |
| 1815 | I40E_VLAN_ANY, |
| 1816 | is_vf, is_netdev)) { |
| 1817 | i40e_del_filter(vsi, vsi->netdev->dev_addr, |
| 1818 | I40E_VLAN_ANY, is_vf, is_netdev); |
| 1819 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0, |
| 1820 | is_vf, is_netdev); |
| 1821 | if (!add_f) { |
| 1822 | dev_info(&vsi->back->pdev->dev, |
| 1823 | "Could not add filter 0 for %pM\n", |
| 1824 | vsi->netdev->dev_addr); |
| 1825 | return -ENOMEM; |
| 1826 | } |
| 1827 | } |
| 1828 | |
| 1829 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1830 | if (i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 1831 | is_vf, is_netdev)) { |
| 1832 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 1833 | is_vf, is_netdev); |
| 1834 | add_f = i40e_add_filter(vsi, f->macaddr, |
| 1835 | 0, is_vf, is_netdev); |
| 1836 | if (!add_f) { |
| 1837 | dev_info(&vsi->back->pdev->dev, |
| 1838 | "Could not add filter 0 for %pM\n", |
| 1839 | f->macaddr); |
| 1840 | return -ENOMEM; |
| 1841 | } |
| 1842 | } |
| 1843 | } |
| 1844 | ret = i40e_sync_vsi_filters(vsi); |
| 1845 | } |
| 1846 | |
| 1847 | return ret; |
| 1848 | } |
| 1849 | |
| 1850 | /** |
| 1851 | * i40e_vsi_kill_vlan - Remove vsi membership for given vlan |
| 1852 | * @vsi: the vsi being configured |
| 1853 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1854 | * |
| 1855 | * Return: 0 on success or negative otherwise |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1856 | **/ |
| 1857 | int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid) |
| 1858 | { |
| 1859 | struct net_device *netdev = vsi->netdev; |
| 1860 | struct i40e_mac_filter *f, *add_f; |
| 1861 | bool is_vf, is_netdev; |
| 1862 | int filter_count = 0; |
| 1863 | int ret; |
| 1864 | |
| 1865 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 1866 | is_netdev = !!(netdev); |
| 1867 | |
| 1868 | if (is_netdev) |
| 1869 | i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev); |
| 1870 | |
| 1871 | list_for_each_entry(f, &vsi->mac_filter_list, list) |
| 1872 | i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 1873 | |
| 1874 | ret = i40e_sync_vsi_filters(vsi); |
| 1875 | if (ret) { |
| 1876 | dev_info(&vsi->back->pdev->dev, "Could not sync filters\n"); |
| 1877 | return ret; |
| 1878 | } |
| 1879 | |
| 1880 | /* go through all the filters for this VSI and if there is only |
| 1881 | * vid == 0 it means there are no other filters, so vid 0 must |
| 1882 | * be replaced with -1. This signifies that we should from now |
| 1883 | * on accept any traffic (with any tag present, or untagged) |
| 1884 | */ |
| 1885 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1886 | if (is_netdev) { |
| 1887 | if (f->vlan && |
| 1888 | ether_addr_equal(netdev->dev_addr, f->macaddr)) |
| 1889 | filter_count++; |
| 1890 | } |
| 1891 | |
| 1892 | if (f->vlan) |
| 1893 | filter_count++; |
| 1894 | } |
| 1895 | |
| 1896 | if (!filter_count && is_netdev) { |
| 1897 | i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev); |
| 1898 | f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, |
| 1899 | is_vf, is_netdev); |
| 1900 | if (!f) { |
| 1901 | dev_info(&vsi->back->pdev->dev, |
| 1902 | "Could not add filter %d for %pM\n", |
| 1903 | I40E_VLAN_ANY, netdev->dev_addr); |
| 1904 | return -ENOMEM; |
| 1905 | } |
| 1906 | } |
| 1907 | |
| 1908 | if (!filter_count) { |
| 1909 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1910 | i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev); |
| 1911 | add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 1912 | is_vf, is_netdev); |
| 1913 | if (!add_f) { |
| 1914 | dev_info(&vsi->back->pdev->dev, |
| 1915 | "Could not add filter %d for %pM\n", |
| 1916 | I40E_VLAN_ANY, f->macaddr); |
| 1917 | return -ENOMEM; |
| 1918 | } |
| 1919 | } |
| 1920 | } |
| 1921 | |
| 1922 | return i40e_sync_vsi_filters(vsi); |
| 1923 | } |
| 1924 | |
| 1925 | /** |
| 1926 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 1927 | * @netdev: network interface to be adjusted |
| 1928 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1929 | * |
| 1930 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1931 | **/ |
| 1932 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 1933 | __always_unused __be16 proto, u16 vid) |
| 1934 | { |
| 1935 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1936 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1937 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1938 | |
| 1939 | if (vid > 4095) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1940 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1941 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1942 | netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid); |
| 1943 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1944 | /* If the network stack called us with vid = 0, we should |
| 1945 | * indicate to i40e_vsi_add_vlan() that we want to receive |
| 1946 | * any traffic (i.e. with any vlan tag, or untagged) |
| 1947 | */ |
| 1948 | ret = i40e_vsi_add_vlan(vsi, vid ? vid : I40E_VLAN_ANY); |
| 1949 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1950 | if (!ret && (vid < VLAN_N_VID)) |
| 1951 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1952 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1953 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | /** |
| 1957 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 1958 | * @netdev: network interface to be adjusted |
| 1959 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1960 | * |
| 1961 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1962 | **/ |
| 1963 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 1964 | __always_unused __be16 proto, u16 vid) |
| 1965 | { |
| 1966 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1967 | struct i40e_vsi *vsi = np->vsi; |
| 1968 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1969 | netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid); |
| 1970 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1971 | /* return code is ignored as there is nothing a user |
| 1972 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1973 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1974 | */ |
| 1975 | i40e_vsi_kill_vlan(vsi, vid); |
| 1976 | |
| 1977 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1978 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1979 | return 0; |
| 1980 | } |
| 1981 | |
| 1982 | /** |
| 1983 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 1984 | * @vsi: the vsi being brought back up |
| 1985 | **/ |
| 1986 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 1987 | { |
| 1988 | u16 vid; |
| 1989 | |
| 1990 | if (!vsi->netdev) |
| 1991 | return; |
| 1992 | |
| 1993 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 1994 | |
| 1995 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 1996 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 1997 | vid); |
| 1998 | } |
| 1999 | |
| 2000 | /** |
| 2001 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2002 | * @vsi: the vsi being adjusted |
| 2003 | * @vid: the vlan id to set as a PVID |
| 2004 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2005 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2006 | { |
| 2007 | struct i40e_vsi_context ctxt; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2008 | i40e_status aq_ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2009 | |
| 2010 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2011 | vsi->info.pvid = cpu_to_le16(vid); |
| 2012 | vsi->info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID; |
| 2013 | vsi->info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED; |
| 2014 | |
| 2015 | ctxt.seid = vsi->seid; |
| 2016 | memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2017 | aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2018 | if (aq_ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2019 | dev_info(&vsi->back->pdev->dev, |
| 2020 | "%s: update vsi failed, aq_err=%d\n", |
| 2021 | __func__, vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2022 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2023 | } |
| 2024 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2025 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | /** |
| 2029 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2030 | * @vsi: the vsi being adjusted |
| 2031 | * |
| 2032 | * Just use the vlan_rx_register() service to put it back to normal |
| 2033 | **/ |
| 2034 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2035 | { |
| 2036 | vsi->info.pvid = 0; |
| 2037 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2038 | } |
| 2039 | |
| 2040 | /** |
| 2041 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2042 | * @vsi: ptr to the VSI |
| 2043 | * |
| 2044 | * If this function returns with an error, then it's possible one or |
| 2045 | * more of the rings is populated (while the rest are not). It is the |
| 2046 | * callers duty to clean those orphaned rings. |
| 2047 | * |
| 2048 | * Return 0 on success, negative on failure |
| 2049 | **/ |
| 2050 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2051 | { |
| 2052 | int i, err = 0; |
| 2053 | |
| 2054 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2055 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2056 | |
| 2057 | return err; |
| 2058 | } |
| 2059 | |
| 2060 | /** |
| 2061 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2062 | * @vsi: ptr to the VSI |
| 2063 | * |
| 2064 | * Free VSI's transmit software resources |
| 2065 | **/ |
| 2066 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2067 | { |
| 2068 | int i; |
| 2069 | |
| 2070 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2071 | if (vsi->tx_rings[i]->desc) |
| 2072 | i40e_free_tx_resources(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | /** |
| 2076 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 2077 | * @vsi: ptr to the VSI |
| 2078 | * |
| 2079 | * If this function returns with an error, then it's possible one or |
| 2080 | * more of the rings is populated (while the rest are not). It is the |
| 2081 | * callers duty to clean those orphaned rings. |
| 2082 | * |
| 2083 | * Return 0 on success, negative on failure |
| 2084 | **/ |
| 2085 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 2086 | { |
| 2087 | int i, err = 0; |
| 2088 | |
| 2089 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2090 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2091 | return err; |
| 2092 | } |
| 2093 | |
| 2094 | /** |
| 2095 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 2096 | * @vsi: ptr to the VSI |
| 2097 | * |
| 2098 | * Free all receive software resources |
| 2099 | **/ |
| 2100 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 2101 | { |
| 2102 | int i; |
| 2103 | |
| 2104 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2105 | if (vsi->rx_rings[i]->desc) |
| 2106 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | /** |
| 2110 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 2111 | * @ring: The Tx ring to configure |
| 2112 | * |
| 2113 | * Configure the Tx descriptor ring in the HMC context. |
| 2114 | **/ |
| 2115 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 2116 | { |
| 2117 | struct i40e_vsi *vsi = ring->vsi; |
| 2118 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2119 | struct i40e_hw *hw = &vsi->back->hw; |
| 2120 | struct i40e_hmc_obj_txq tx_ctx; |
| 2121 | i40e_status err = 0; |
| 2122 | u32 qtx_ctl = 0; |
| 2123 | |
| 2124 | /* some ATR related tx ring init */ |
| 2125 | if (vsi->back->flags & I40E_FLAG_FDIR_ATR_ENABLED) { |
| 2126 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 2127 | ring->atr_count = 0; |
| 2128 | } else { |
| 2129 | ring->atr_sample_rate = 0; |
| 2130 | } |
| 2131 | |
| 2132 | /* initialize XPS */ |
| 2133 | if (ring->q_vector && ring->netdev && |
| 2134 | !test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) |
| 2135 | netif_set_xps_queue(ring->netdev, |
| 2136 | &ring->q_vector->affinity_mask, |
| 2137 | ring->queue_index); |
| 2138 | |
| 2139 | /* clear the context structure first */ |
| 2140 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 2141 | |
| 2142 | tx_ctx.new_context = 1; |
| 2143 | tx_ctx.base = (ring->dma / 128); |
| 2144 | tx_ctx.qlen = ring->count; |
| 2145 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FDIR_ENABLED | |
| 2146 | I40E_FLAG_FDIR_ATR_ENABLED)); |
| 2147 | |
| 2148 | /* As part of VSI creation/update, FW allocates certain |
| 2149 | * Tx arbitration queue sets for each TC enabled for |
| 2150 | * the VSI. The FW returns the handles to these queue |
| 2151 | * sets as part of the response buffer to Add VSI, |
| 2152 | * Update VSI, etc. AQ commands. It is expected that |
| 2153 | * these queue set handles be associated with the Tx |
| 2154 | * queues by the driver as part of the TX queue context |
| 2155 | * initialization. This has to be done regardless of |
| 2156 | * DCB as by default everything is mapped to TC0. |
| 2157 | */ |
| 2158 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 2159 | tx_ctx.rdylist_act = 0; |
| 2160 | |
| 2161 | /* clear the context in the HMC */ |
| 2162 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 2163 | if (err) { |
| 2164 | dev_info(&vsi->back->pdev->dev, |
| 2165 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 2166 | ring->queue_index, pf_q, err); |
| 2167 | return -ENOMEM; |
| 2168 | } |
| 2169 | |
| 2170 | /* set the context in the HMC */ |
| 2171 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 2172 | if (err) { |
| 2173 | dev_info(&vsi->back->pdev->dev, |
| 2174 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 2175 | ring->queue_index, pf_q, err); |
| 2176 | return -ENOMEM; |
| 2177 | } |
| 2178 | |
| 2179 | /* Now associate this queue with this PCI function */ |
| 2180 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
Shannon Nelson | 13fd97749 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 2181 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 2182 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2183 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 2184 | i40e_flush(hw); |
| 2185 | |
| 2186 | clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state); |
| 2187 | |
| 2188 | /* cache tail off for easier writes later */ |
| 2189 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 2190 | |
| 2191 | return 0; |
| 2192 | } |
| 2193 | |
| 2194 | /** |
| 2195 | * i40e_configure_rx_ring - Configure a receive ring context |
| 2196 | * @ring: The Rx ring to configure |
| 2197 | * |
| 2198 | * Configure the Rx descriptor ring in the HMC context. |
| 2199 | **/ |
| 2200 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 2201 | { |
| 2202 | struct i40e_vsi *vsi = ring->vsi; |
| 2203 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 2204 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2205 | struct i40e_hw *hw = &vsi->back->hw; |
| 2206 | struct i40e_hmc_obj_rxq rx_ctx; |
| 2207 | i40e_status err = 0; |
| 2208 | |
| 2209 | ring->state = 0; |
| 2210 | |
| 2211 | /* clear the context structure first */ |
| 2212 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 2213 | |
| 2214 | ring->rx_buf_len = vsi->rx_buf_len; |
| 2215 | ring->rx_hdr_len = vsi->rx_hdr_len; |
| 2216 | |
| 2217 | rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT; |
| 2218 | rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT; |
| 2219 | |
| 2220 | rx_ctx.base = (ring->dma / 128); |
| 2221 | rx_ctx.qlen = ring->count; |
| 2222 | |
| 2223 | if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) { |
| 2224 | set_ring_16byte_desc_enabled(ring); |
| 2225 | rx_ctx.dsize = 0; |
| 2226 | } else { |
| 2227 | rx_ctx.dsize = 1; |
| 2228 | } |
| 2229 | |
| 2230 | rx_ctx.dtype = vsi->dtype; |
| 2231 | if (vsi->dtype) { |
| 2232 | set_ring_ps_enabled(ring); |
| 2233 | rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 | |
| 2234 | I40E_RX_SPLIT_IP | |
| 2235 | I40E_RX_SPLIT_TCP_UDP | |
| 2236 | I40E_RX_SPLIT_SCTP; |
| 2237 | } else { |
| 2238 | rx_ctx.hsplit_0 = 0; |
| 2239 | } |
| 2240 | |
| 2241 | rx_ctx.rxmax = min_t(u16, vsi->max_frame, |
| 2242 | (chain_len * ring->rx_buf_len)); |
| 2243 | rx_ctx.tphrdesc_ena = 1; |
| 2244 | rx_ctx.tphwdesc_ena = 1; |
| 2245 | rx_ctx.tphdata_ena = 1; |
| 2246 | rx_ctx.tphhead_ena = 1; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 2247 | if (hw->revision_id == 0) |
| 2248 | rx_ctx.lrxqthresh = 0; |
| 2249 | else |
| 2250 | rx_ctx.lrxqthresh = 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2251 | rx_ctx.crcstrip = 1; |
| 2252 | rx_ctx.l2tsel = 1; |
| 2253 | rx_ctx.showiv = 1; |
| 2254 | |
| 2255 | /* clear the context in the HMC */ |
| 2256 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 2257 | if (err) { |
| 2258 | dev_info(&vsi->back->pdev->dev, |
| 2259 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2260 | ring->queue_index, pf_q, err); |
| 2261 | return -ENOMEM; |
| 2262 | } |
| 2263 | |
| 2264 | /* set the context in the HMC */ |
| 2265 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 2266 | if (err) { |
| 2267 | dev_info(&vsi->back->pdev->dev, |
| 2268 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2269 | ring->queue_index, pf_q, err); |
| 2270 | return -ENOMEM; |
| 2271 | } |
| 2272 | |
| 2273 | /* cache tail for quicker writes, and clear the reg before use */ |
| 2274 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 2275 | writel(0, ring->tail); |
| 2276 | |
| 2277 | i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); |
| 2278 | |
| 2279 | return 0; |
| 2280 | } |
| 2281 | |
| 2282 | /** |
| 2283 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 2284 | * @vsi: VSI structure describing this set of rings and resources |
| 2285 | * |
| 2286 | * Configure the Tx VSI for operation. |
| 2287 | **/ |
| 2288 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 2289 | { |
| 2290 | int err = 0; |
| 2291 | u16 i; |
| 2292 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2293 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 2294 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2295 | |
| 2296 | return err; |
| 2297 | } |
| 2298 | |
| 2299 | /** |
| 2300 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 2301 | * @vsi: the VSI being configured |
| 2302 | * |
| 2303 | * Configure the Rx VSI for operation. |
| 2304 | **/ |
| 2305 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 2306 | { |
| 2307 | int err = 0; |
| 2308 | u16 i; |
| 2309 | |
| 2310 | if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN)) |
| 2311 | vsi->max_frame = vsi->netdev->mtu + ETH_HLEN |
| 2312 | + ETH_FCS_LEN + VLAN_HLEN; |
| 2313 | else |
| 2314 | vsi->max_frame = I40E_RXBUFFER_2048; |
| 2315 | |
| 2316 | /* figure out correct receive buffer length */ |
| 2317 | switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED | |
| 2318 | I40E_FLAG_RX_PS_ENABLED)) { |
| 2319 | case I40E_FLAG_RX_1BUF_ENABLED: |
| 2320 | vsi->rx_hdr_len = 0; |
| 2321 | vsi->rx_buf_len = vsi->max_frame; |
| 2322 | vsi->dtype = I40E_RX_DTYPE_NO_SPLIT; |
| 2323 | break; |
| 2324 | case I40E_FLAG_RX_PS_ENABLED: |
| 2325 | vsi->rx_hdr_len = I40E_RX_HDR_SIZE; |
| 2326 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 2327 | vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT; |
| 2328 | break; |
| 2329 | default: |
| 2330 | vsi->rx_hdr_len = I40E_RX_HDR_SIZE; |
| 2331 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 2332 | vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS; |
| 2333 | break; |
| 2334 | } |
| 2335 | |
| 2336 | /* round up for the chip's needs */ |
| 2337 | vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len, |
| 2338 | (1 << I40E_RXQ_CTX_HBUFF_SHIFT)); |
| 2339 | vsi->rx_buf_len = ALIGN(vsi->rx_buf_len, |
| 2340 | (1 << I40E_RXQ_CTX_DBUFF_SHIFT)); |
| 2341 | |
| 2342 | /* set up individual rings */ |
| 2343 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2344 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2345 | |
| 2346 | return err; |
| 2347 | } |
| 2348 | |
| 2349 | /** |
| 2350 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 2351 | * @vsi: ptr to the VSI |
| 2352 | **/ |
| 2353 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 2354 | { |
| 2355 | u16 qoffset, qcount; |
| 2356 | int i, n; |
| 2357 | |
| 2358 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) |
| 2359 | return; |
| 2360 | |
| 2361 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
| 2362 | if (!(vsi->tc_config.enabled_tc & (1 << n))) |
| 2363 | continue; |
| 2364 | |
| 2365 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 2366 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 2367 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2368 | struct i40e_ring *rx_ring = vsi->rx_rings[i]; |
| 2369 | struct i40e_ring *tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2370 | rx_ring->dcb_tc = n; |
| 2371 | tx_ring->dcb_tc = n; |
| 2372 | } |
| 2373 | } |
| 2374 | } |
| 2375 | |
| 2376 | /** |
| 2377 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 2378 | * @vsi: ptr to the VSI |
| 2379 | **/ |
| 2380 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 2381 | { |
| 2382 | if (vsi->netdev) |
| 2383 | i40e_set_rx_mode(vsi->netdev); |
| 2384 | } |
| 2385 | |
| 2386 | /** |
| 2387 | * i40e_vsi_configure - Set up the VSI for action |
| 2388 | * @vsi: the VSI being configured |
| 2389 | **/ |
| 2390 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 2391 | { |
| 2392 | int err; |
| 2393 | |
| 2394 | i40e_set_vsi_rx_mode(vsi); |
| 2395 | i40e_restore_vlan(vsi); |
| 2396 | i40e_vsi_config_dcb_rings(vsi); |
| 2397 | err = i40e_vsi_configure_tx(vsi); |
| 2398 | if (!err) |
| 2399 | err = i40e_vsi_configure_rx(vsi); |
| 2400 | |
| 2401 | return err; |
| 2402 | } |
| 2403 | |
| 2404 | /** |
| 2405 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 2406 | * @vsi: the VSI being configured |
| 2407 | **/ |
| 2408 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 2409 | { |
| 2410 | struct i40e_pf *pf = vsi->back; |
| 2411 | struct i40e_q_vector *q_vector; |
| 2412 | struct i40e_hw *hw = &pf->hw; |
| 2413 | u16 vector; |
| 2414 | int i, q; |
| 2415 | u32 val; |
| 2416 | u32 qp; |
| 2417 | |
| 2418 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 2419 | * and PFINT_LNKLSTn registers, e.g.: |
| 2420 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 2421 | */ |
| 2422 | qp = vsi->base_queue; |
| 2423 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 2424 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
| 2425 | q_vector = vsi->q_vectors[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2426 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting); |
| 2427 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 2428 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 2429 | q_vector->rx.itr); |
| 2430 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting); |
| 2431 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 2432 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 2433 | q_vector->tx.itr); |
| 2434 | |
| 2435 | /* Linked list for the queuepairs assigned to this vector */ |
| 2436 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 2437 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
| 2438 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 2439 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 2440 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 2441 | (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
| 2442 | (I40E_QUEUE_TYPE_TX |
| 2443 | << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
| 2444 | |
| 2445 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 2446 | |
| 2447 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 2448 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 2449 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 2450 | ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| |
| 2451 | (I40E_QUEUE_TYPE_RX |
| 2452 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 2453 | |
| 2454 | /* Terminate the linked list */ |
| 2455 | if (q == (q_vector->num_ringpairs - 1)) |
| 2456 | val |= (I40E_QUEUE_END_OF_LIST |
| 2457 | << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 2458 | |
| 2459 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 2460 | qp++; |
| 2461 | } |
| 2462 | } |
| 2463 | |
| 2464 | i40e_flush(hw); |
| 2465 | } |
| 2466 | |
| 2467 | /** |
| 2468 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 2469 | * @hw: ptr to the hardware info |
| 2470 | **/ |
| 2471 | static void i40e_enable_misc_int_causes(struct i40e_hw *hw) |
| 2472 | { |
| 2473 | u32 val; |
| 2474 | |
| 2475 | /* clear things first */ |
| 2476 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 2477 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 2478 | |
| 2479 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 2480 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 2481 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 2482 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 2483 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
| 2484 | I40E_PFINT_ICR0_ENA_STORM_DETECT_MASK | |
| 2485 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 2486 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 2487 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 2488 | |
| 2489 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 2490 | |
| 2491 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
| 2492 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTLN_SW_ITR_INDX_MASK | |
| 2493 | I40E_PFINT_DYN_CTLN_INTENA_MSK_MASK); |
| 2494 | |
| 2495 | /* OTHER_ITR_IDX = 0 */ |
| 2496 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 2497 | } |
| 2498 | |
| 2499 | /** |
| 2500 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 2501 | * @vsi: the VSI being configured |
| 2502 | **/ |
| 2503 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 2504 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 2505 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2506 | struct i40e_pf *pf = vsi->back; |
| 2507 | struct i40e_hw *hw = &pf->hw; |
| 2508 | u32 val; |
| 2509 | |
| 2510 | /* set the ITR configuration */ |
| 2511 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting); |
| 2512 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 2513 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
| 2514 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting); |
| 2515 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 2516 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 2517 | |
| 2518 | i40e_enable_misc_int_causes(hw); |
| 2519 | |
| 2520 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 2521 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 2522 | |
| 2523 | /* Associate the queue pair to the vector and enable the q int */ |
| 2524 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 2525 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 2526 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 2527 | |
| 2528 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 2529 | |
| 2530 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 2531 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 2532 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 2533 | |
| 2534 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 2535 | i40e_flush(hw); |
| 2536 | } |
| 2537 | |
| 2538 | /** |
| 2539 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 2540 | * @pf: board private structure |
| 2541 | **/ |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 2542 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2543 | { |
| 2544 | struct i40e_hw *hw = &pf->hw; |
| 2545 | u32 val; |
| 2546 | |
| 2547 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
| 2548 | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK | |
| 2549 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 2550 | |
| 2551 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 2552 | i40e_flush(hw); |
| 2553 | } |
| 2554 | |
| 2555 | /** |
| 2556 | * i40e_irq_dynamic_enable - Enable default interrupt generation settings |
| 2557 | * @vsi: pointer to a vsi |
| 2558 | * @vector: enable a particular Hw Interrupt vector |
| 2559 | **/ |
| 2560 | void i40e_irq_dynamic_enable(struct i40e_vsi *vsi, int vector) |
| 2561 | { |
| 2562 | struct i40e_pf *pf = vsi->back; |
| 2563 | struct i40e_hw *hw = &pf->hw; |
| 2564 | u32 val; |
| 2565 | |
| 2566 | val = I40E_PFINT_DYN_CTLN_INTENA_MASK | |
| 2567 | I40E_PFINT_DYN_CTLN_CLEARPBA_MASK | |
| 2568 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 2569 | wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val); |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 2570 | /* skip the flush */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2571 | } |
| 2572 | |
| 2573 | /** |
| 2574 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 2575 | * @irq: interrupt number |
| 2576 | * @data: pointer to a q_vector |
| 2577 | **/ |
| 2578 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 2579 | { |
| 2580 | struct i40e_q_vector *q_vector = data; |
| 2581 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2582 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2583 | return IRQ_HANDLED; |
| 2584 | |
| 2585 | napi_schedule(&q_vector->napi); |
| 2586 | |
| 2587 | return IRQ_HANDLED; |
| 2588 | } |
| 2589 | |
| 2590 | /** |
| 2591 | * i40e_fdir_clean_rings - Interrupt Handler for FDIR rings |
| 2592 | * @irq: interrupt number |
| 2593 | * @data: pointer to a q_vector |
| 2594 | **/ |
| 2595 | static irqreturn_t i40e_fdir_clean_rings(int irq, void *data) |
| 2596 | { |
| 2597 | struct i40e_q_vector *q_vector = data; |
| 2598 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2599 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2600 | return IRQ_HANDLED; |
| 2601 | |
| 2602 | pr_info("fdir ring cleaning needed\n"); |
| 2603 | |
| 2604 | return IRQ_HANDLED; |
| 2605 | } |
| 2606 | |
| 2607 | /** |
| 2608 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 2609 | * @vsi: the VSI being configured |
| 2610 | * @basename: name for the vector |
| 2611 | * |
| 2612 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 2613 | **/ |
| 2614 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 2615 | { |
| 2616 | int q_vectors = vsi->num_q_vectors; |
| 2617 | struct i40e_pf *pf = vsi->back; |
| 2618 | int base = vsi->base_vector; |
| 2619 | int rx_int_idx = 0; |
| 2620 | int tx_int_idx = 0; |
| 2621 | int vector, err; |
| 2622 | |
| 2623 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 2624 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2625 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2626 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2627 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2628 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 2629 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2630 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2631 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2632 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2633 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2634 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2635 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 2636 | } else { |
| 2637 | /* skip this unused q_vector */ |
| 2638 | continue; |
| 2639 | } |
| 2640 | err = request_irq(pf->msix_entries[base + vector].vector, |
| 2641 | vsi->irq_handler, |
| 2642 | 0, |
| 2643 | q_vector->name, |
| 2644 | q_vector); |
| 2645 | if (err) { |
| 2646 | dev_info(&pf->pdev->dev, |
| 2647 | "%s: request_irq failed, error: %d\n", |
| 2648 | __func__, err); |
| 2649 | goto free_queue_irqs; |
| 2650 | } |
| 2651 | /* assign the mask for this irq */ |
| 2652 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 2653 | &q_vector->affinity_mask); |
| 2654 | } |
| 2655 | |
| 2656 | return 0; |
| 2657 | |
| 2658 | free_queue_irqs: |
| 2659 | while (vector) { |
| 2660 | vector--; |
| 2661 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 2662 | NULL); |
| 2663 | free_irq(pf->msix_entries[base + vector].vector, |
| 2664 | &(vsi->q_vectors[vector])); |
| 2665 | } |
| 2666 | return err; |
| 2667 | } |
| 2668 | |
| 2669 | /** |
| 2670 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 2671 | * @vsi: the VSI being un-configured |
| 2672 | **/ |
| 2673 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 2674 | { |
| 2675 | struct i40e_pf *pf = vsi->back; |
| 2676 | struct i40e_hw *hw = &pf->hw; |
| 2677 | int base = vsi->base_vector; |
| 2678 | int i; |
| 2679 | |
| 2680 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2681 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); |
| 2682 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2683 | } |
| 2684 | |
| 2685 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 2686 | for (i = vsi->base_vector; |
| 2687 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 2688 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 2689 | |
| 2690 | i40e_flush(hw); |
| 2691 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 2692 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 2693 | } else { |
| 2694 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 2695 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 2696 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 2697 | i40e_flush(hw); |
| 2698 | synchronize_irq(pf->pdev->irq); |
| 2699 | } |
| 2700 | } |
| 2701 | |
| 2702 | /** |
| 2703 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 2704 | * @vsi: the VSI being configured |
| 2705 | **/ |
| 2706 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 2707 | { |
| 2708 | struct i40e_pf *pf = vsi->back; |
| 2709 | int i; |
| 2710 | |
| 2711 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 2712 | for (i = vsi->base_vector; |
| 2713 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 2714 | i40e_irq_dynamic_enable(vsi, i); |
| 2715 | } else { |
| 2716 | i40e_irq_dynamic_enable_icr0(pf); |
| 2717 | } |
| 2718 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 2719 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2720 | return 0; |
| 2721 | } |
| 2722 | |
| 2723 | /** |
| 2724 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events |
| 2725 | * @pf: board private structure |
| 2726 | **/ |
| 2727 | static void i40e_stop_misc_vector(struct i40e_pf *pf) |
| 2728 | { |
| 2729 | /* Disable ICR 0 */ |
| 2730 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 2731 | i40e_flush(&pf->hw); |
| 2732 | } |
| 2733 | |
| 2734 | /** |
| 2735 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 2736 | * @irq: interrupt number |
| 2737 | * @data: pointer to a q_vector |
| 2738 | * |
| 2739 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 2740 | * with both queue and non-queue interrupts. This is also used in |
| 2741 | * MSIX mode to handle the non-queue interrupts. |
| 2742 | **/ |
| 2743 | static irqreturn_t i40e_intr(int irq, void *data) |
| 2744 | { |
| 2745 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 2746 | struct i40e_hw *hw = &pf->hw; |
| 2747 | u32 icr0, icr0_remaining; |
| 2748 | u32 val, ena_mask; |
| 2749 | |
| 2750 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
| 2751 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2752 | val = rd32(hw, I40E_PFINT_DYN_CTL0); |
| 2753 | val = val | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK; |
| 2754 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 2755 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 2756 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 2757 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
| 2758 | return IRQ_NONE; |
| 2759 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2760 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 2761 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 2762 | /* if interrupt but no bits showing, must be SWINT */ |
| 2763 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 2764 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 2765 | pf->sw_int_count++; |
| 2766 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2767 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 2768 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
| 2769 | |
| 2770 | /* temporarily disable queue cause for NAPI processing */ |
| 2771 | u32 qval = rd32(hw, I40E_QINT_RQCTL(0)); |
| 2772 | qval &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK; |
| 2773 | wr32(hw, I40E_QINT_RQCTL(0), qval); |
| 2774 | |
| 2775 | qval = rd32(hw, I40E_QINT_TQCTL(0)); |
| 2776 | qval &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK; |
| 2777 | wr32(hw, I40E_QINT_TQCTL(0), qval); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2778 | |
| 2779 | if (!test_bit(__I40E_DOWN, &pf->state)) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 2780 | napi_schedule(&pf->vsi[pf->lan_vsi]->q_vectors[0]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2781 | } |
| 2782 | |
| 2783 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 2784 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 2785 | set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 2786 | } |
| 2787 | |
| 2788 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 2789 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 2790 | set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 2791 | } |
| 2792 | |
| 2793 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 2794 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
| 2795 | set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
| 2796 | } |
| 2797 | |
| 2798 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
| 2799 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
| 2800 | set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 2801 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 2802 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 2803 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 2804 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | d52cf0a | 2013-11-16 10:00:39 +0000 | [diff] [blame] | 2805 | if (val == I40E_RESET_CORER) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2806 | pf->corer_count++; |
Shannon Nelson | d52cf0a | 2013-11-16 10:00:39 +0000 | [diff] [blame] | 2807 | else if (val == I40E_RESET_GLOBR) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2808 | pf->globr_count++; |
Shannon Nelson | d52cf0a | 2013-11-16 10:00:39 +0000 | [diff] [blame] | 2809 | else if (val == I40E_RESET_EMPR) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2810 | pf->empr_count++; |
| 2811 | } |
| 2812 | |
| 2813 | /* If a critical error is pending we have no choice but to reset the |
| 2814 | * device. |
| 2815 | * Report and mask out any remaining unexpected interrupts. |
| 2816 | */ |
| 2817 | icr0_remaining = icr0 & ena_mask; |
| 2818 | if (icr0_remaining) { |
| 2819 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 2820 | icr0_remaining); |
| 2821 | if ((icr0_remaining & I40E_PFINT_ICR0_HMC_ERR_MASK) || |
| 2822 | (icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
| 2823 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
| 2824 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK) || |
| 2825 | (icr0_remaining & I40E_PFINT_ICR0_MAL_DETECT_MASK)) { |
| 2826 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 2827 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
| 2828 | } else { |
| 2829 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
| 2830 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 2831 | i40e_service_event_schedule(pf); |
| 2832 | } |
| 2833 | } |
| 2834 | ena_mask &= ~icr0_remaining; |
| 2835 | } |
| 2836 | |
| 2837 | /* re-enable interrupt causes */ |
| 2838 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2839 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 2840 | i40e_service_event_schedule(pf); |
| 2841 | i40e_irq_dynamic_enable_icr0(pf); |
| 2842 | } |
| 2843 | |
| 2844 | return IRQ_HANDLED; |
| 2845 | } |
| 2846 | |
| 2847 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2848 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2849 | * @vsi: the VSI being configured |
| 2850 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2851 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2852 | **/ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2853 | 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] | 2854 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 2855 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2856 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 2857 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2858 | |
| 2859 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2860 | tx_ring->next = q_vector->tx.ring; |
| 2861 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2862 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2863 | |
| 2864 | rx_ring->q_vector = q_vector; |
| 2865 | rx_ring->next = q_vector->rx.ring; |
| 2866 | q_vector->rx.ring = rx_ring; |
| 2867 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2868 | } |
| 2869 | |
| 2870 | /** |
| 2871 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 2872 | * @vsi: the VSI being configured |
| 2873 | * |
| 2874 | * This function maps descriptor rings to the queue-specific vectors |
| 2875 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 2876 | * one vector per queue pair, but on a constrained vector budget, we |
| 2877 | * group the queue pairs as "efficiently" as possible. |
| 2878 | **/ |
| 2879 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 2880 | { |
| 2881 | int qp_remaining = vsi->num_queue_pairs; |
| 2882 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2883 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2884 | int v_start = 0; |
| 2885 | int qp_idx = 0; |
| 2886 | |
| 2887 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 2888 | * group them so there are multiple queues per vector. |
| 2889 | */ |
| 2890 | for (; v_start < q_vectors && qp_remaining; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2891 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 2892 | |
| 2893 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 2894 | |
| 2895 | q_vector->num_ringpairs = num_ringpairs; |
| 2896 | |
| 2897 | q_vector->rx.count = 0; |
| 2898 | q_vector->tx.count = 0; |
| 2899 | q_vector->rx.ring = NULL; |
| 2900 | q_vector->tx.ring = NULL; |
| 2901 | |
| 2902 | while (num_ringpairs--) { |
| 2903 | map_vector_to_qp(vsi, v_start, qp_idx); |
| 2904 | qp_idx++; |
| 2905 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2906 | } |
| 2907 | } |
| 2908 | } |
| 2909 | |
| 2910 | /** |
| 2911 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 2912 | * @vsi: the VSI being configured |
| 2913 | * @basename: name for the vector |
| 2914 | **/ |
| 2915 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 2916 | { |
| 2917 | struct i40e_pf *pf = vsi->back; |
| 2918 | int err; |
| 2919 | |
| 2920 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 2921 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 2922 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 2923 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
| 2924 | pf->misc_int_name, pf); |
| 2925 | else |
| 2926 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
| 2927 | pf->misc_int_name, pf); |
| 2928 | |
| 2929 | if (err) |
| 2930 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 2931 | |
| 2932 | return err; |
| 2933 | } |
| 2934 | |
| 2935 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2936 | /** |
| 2937 | * i40e_netpoll - A Polling 'interrupt'handler |
| 2938 | * @netdev: network interface device structure |
| 2939 | * |
| 2940 | * This is used by netconsole to send skbs without having to re-enable |
| 2941 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 2942 | **/ |
| 2943 | static void i40e_netpoll(struct net_device *netdev) |
| 2944 | { |
| 2945 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2946 | struct i40e_vsi *vsi = np->vsi; |
| 2947 | struct i40e_pf *pf = vsi->back; |
| 2948 | int i; |
| 2949 | |
| 2950 | /* if interface is down do nothing */ |
| 2951 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 2952 | return; |
| 2953 | |
| 2954 | pf->flags |= I40E_FLAG_IN_NETPOLL; |
| 2955 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 2956 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 2957 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2958 | } else { |
| 2959 | i40e_intr(pf->pdev->irq, netdev); |
| 2960 | } |
| 2961 | pf->flags &= ~I40E_FLAG_IN_NETPOLL; |
| 2962 | } |
| 2963 | #endif |
| 2964 | |
| 2965 | /** |
| 2966 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 2967 | * @vsi: the VSI being configured |
| 2968 | * @enable: start or stop the rings |
| 2969 | **/ |
| 2970 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 2971 | { |
| 2972 | struct i40e_pf *pf = vsi->back; |
| 2973 | struct i40e_hw *hw = &pf->hw; |
| 2974 | int i, j, pf_q; |
| 2975 | u32 tx_reg; |
| 2976 | |
| 2977 | pf_q = vsi->base_queue; |
| 2978 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 2979 | j = 1000; |
| 2980 | do { |
| 2981 | usleep_range(1000, 2000); |
| 2982 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
| 2983 | } while (j-- && ((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) |
| 2984 | ^ (tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT)) & 1); |
| 2985 | |
| 2986 | if (enable) { |
| 2987 | /* is STAT set ? */ |
| 2988 | if ((tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) { |
| 2989 | dev_info(&pf->pdev->dev, |
| 2990 | "Tx %d already enabled\n", i); |
| 2991 | continue; |
| 2992 | } |
| 2993 | } else { |
| 2994 | /* is !STAT set ? */ |
| 2995 | if (!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) { |
| 2996 | dev_info(&pf->pdev->dev, |
| 2997 | "Tx %d already disabled\n", i); |
| 2998 | continue; |
| 2999 | } |
| 3000 | } |
| 3001 | |
| 3002 | /* turn on/off the queue */ |
| 3003 | if (enable) |
| 3004 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK | |
| 3005 | I40E_QTX_ENA_QENA_STAT_MASK; |
| 3006 | else |
| 3007 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
| 3008 | |
| 3009 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
| 3010 | |
| 3011 | /* wait for the change to finish */ |
| 3012 | for (j = 0; j < 10; j++) { |
| 3013 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
| 3014 | if (enable) { |
| 3015 | if ((tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 3016 | break; |
| 3017 | } else { |
| 3018 | if (!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 3019 | break; |
| 3020 | } |
| 3021 | |
| 3022 | udelay(10); |
| 3023 | } |
| 3024 | if (j >= 10) { |
| 3025 | dev_info(&pf->pdev->dev, "Tx ring %d %sable timeout\n", |
| 3026 | pf_q, (enable ? "en" : "dis")); |
| 3027 | return -ETIMEDOUT; |
| 3028 | } |
| 3029 | } |
| 3030 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3031 | if (hw->revision_id == 0) |
| 3032 | mdelay(50); |
| 3033 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3034 | return 0; |
| 3035 | } |
| 3036 | |
| 3037 | /** |
| 3038 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 3039 | * @vsi: the VSI being configured |
| 3040 | * @enable: start or stop the rings |
| 3041 | **/ |
| 3042 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 3043 | { |
| 3044 | struct i40e_pf *pf = vsi->back; |
| 3045 | struct i40e_hw *hw = &pf->hw; |
| 3046 | int i, j, pf_q; |
| 3047 | u32 rx_reg; |
| 3048 | |
| 3049 | pf_q = vsi->base_queue; |
| 3050 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
| 3051 | j = 1000; |
| 3052 | do { |
| 3053 | usleep_range(1000, 2000); |
| 3054 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
| 3055 | } while (j-- && ((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) |
| 3056 | ^ (rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT)) & 1); |
| 3057 | |
| 3058 | if (enable) { |
| 3059 | /* is STAT set ? */ |
| 3060 | if ((rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3061 | continue; |
| 3062 | } else { |
| 3063 | /* is !STAT set ? */ |
| 3064 | if (!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3065 | continue; |
| 3066 | } |
| 3067 | |
| 3068 | /* turn on/off the queue */ |
| 3069 | if (enable) |
| 3070 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK | |
| 3071 | I40E_QRX_ENA_QENA_STAT_MASK; |
| 3072 | else |
| 3073 | rx_reg &= ~(I40E_QRX_ENA_QENA_REQ_MASK | |
| 3074 | I40E_QRX_ENA_QENA_STAT_MASK); |
| 3075 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
| 3076 | |
| 3077 | /* wait for the change to finish */ |
| 3078 | for (j = 0; j < 10; j++) { |
| 3079 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
| 3080 | |
| 3081 | if (enable) { |
| 3082 | if ((rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3083 | break; |
| 3084 | } else { |
| 3085 | if (!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3086 | break; |
| 3087 | } |
| 3088 | |
| 3089 | udelay(10); |
| 3090 | } |
| 3091 | if (j >= 10) { |
| 3092 | dev_info(&pf->pdev->dev, "Rx ring %d %sable timeout\n", |
| 3093 | pf_q, (enable ? "en" : "dis")); |
| 3094 | return -ETIMEDOUT; |
| 3095 | } |
| 3096 | } |
| 3097 | |
| 3098 | return 0; |
| 3099 | } |
| 3100 | |
| 3101 | /** |
| 3102 | * i40e_vsi_control_rings - Start or stop a VSI's rings |
| 3103 | * @vsi: the VSI being configured |
| 3104 | * @enable: start or stop the rings |
| 3105 | **/ |
| 3106 | static int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request) |
| 3107 | { |
| 3108 | int ret; |
| 3109 | |
| 3110 | /* do rx first for enable and last for disable */ |
| 3111 | if (request) { |
| 3112 | ret = i40e_vsi_control_rx(vsi, request); |
| 3113 | if (ret) |
| 3114 | return ret; |
| 3115 | ret = i40e_vsi_control_tx(vsi, request); |
| 3116 | } else { |
| 3117 | ret = i40e_vsi_control_tx(vsi, request); |
| 3118 | if (ret) |
| 3119 | return ret; |
| 3120 | ret = i40e_vsi_control_rx(vsi, request); |
| 3121 | } |
| 3122 | |
| 3123 | return ret; |
| 3124 | } |
| 3125 | |
| 3126 | /** |
| 3127 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 3128 | * @vsi: the VSI being configured |
| 3129 | **/ |
| 3130 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 3131 | { |
| 3132 | struct i40e_pf *pf = vsi->back; |
| 3133 | struct i40e_hw *hw = &pf->hw; |
| 3134 | int base = vsi->base_vector; |
| 3135 | u32 val, qp; |
| 3136 | int i; |
| 3137 | |
| 3138 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3139 | if (!vsi->q_vectors) |
| 3140 | return; |
| 3141 | |
| 3142 | for (i = 0; i < vsi->num_q_vectors; i++) { |
| 3143 | u16 vector = i + base; |
| 3144 | |
| 3145 | /* free only the irqs that were actually requested */ |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3146 | if (vsi->q_vectors[i]->num_ringpairs == 0) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3147 | continue; |
| 3148 | |
| 3149 | /* clear the affinity_mask in the IRQ descriptor */ |
| 3150 | irq_set_affinity_hint(pf->msix_entries[vector].vector, |
| 3151 | NULL); |
| 3152 | free_irq(pf->msix_entries[vector].vector, |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3153 | vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3154 | |
| 3155 | /* Tear down the interrupt queue link list |
| 3156 | * |
| 3157 | * We know that they come in pairs and always |
| 3158 | * the Rx first, then the Tx. To clear the |
| 3159 | * link list, stick the EOL value into the |
| 3160 | * next_q field of the registers. |
| 3161 | */ |
| 3162 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 3163 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 3164 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 3165 | val |= I40E_QUEUE_END_OF_LIST |
| 3166 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 3167 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 3168 | |
| 3169 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 3170 | u32 next; |
| 3171 | |
| 3172 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 3173 | |
| 3174 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 3175 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 3176 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3177 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 3178 | |
| 3179 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 3180 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 3181 | |
| 3182 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3183 | |
| 3184 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 3185 | |
| 3186 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 3187 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 3188 | |
| 3189 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 3190 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 3191 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3192 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 3193 | |
| 3194 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 3195 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 3196 | |
| 3197 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3198 | qp = next; |
| 3199 | } |
| 3200 | } |
| 3201 | } else { |
| 3202 | free_irq(pf->pdev->irq, pf); |
| 3203 | |
| 3204 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 3205 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 3206 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 3207 | val |= I40E_QUEUE_END_OF_LIST |
| 3208 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 3209 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 3210 | |
| 3211 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 3212 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 3213 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 3214 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3215 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 3216 | |
| 3217 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 3218 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 3219 | |
| 3220 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3221 | |
| 3222 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 3223 | |
| 3224 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 3225 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 3226 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3227 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 3228 | |
| 3229 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 3230 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 3231 | |
| 3232 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3233 | } |
| 3234 | } |
| 3235 | |
| 3236 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3237 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 3238 | * @vsi: the VSI being configured |
| 3239 | * @v_idx: Index of vector to be freed |
| 3240 | * |
| 3241 | * This function frees the memory allocated to the q_vector. In addition if |
| 3242 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 3243 | * to freeing the q_vector. |
| 3244 | **/ |
| 3245 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 3246 | { |
| 3247 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3248 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3249 | |
| 3250 | if (!q_vector) |
| 3251 | return; |
| 3252 | |
| 3253 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3254 | i40e_for_each_ring(ring, q_vector->tx) |
| 3255 | ring->q_vector = NULL; |
| 3256 | |
| 3257 | i40e_for_each_ring(ring, q_vector->rx) |
| 3258 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3259 | |
| 3260 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 3261 | if (vsi->netdev) |
| 3262 | netif_napi_del(&q_vector->napi); |
| 3263 | |
| 3264 | vsi->q_vectors[v_idx] = NULL; |
| 3265 | |
| 3266 | kfree_rcu(q_vector, rcu); |
| 3267 | } |
| 3268 | |
| 3269 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3270 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 3271 | * @vsi: the VSI being un-configured |
| 3272 | * |
| 3273 | * This frees the memory allocated to the q_vectors and |
| 3274 | * deletes references to the NAPI struct. |
| 3275 | **/ |
| 3276 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 3277 | { |
| 3278 | int v_idx; |
| 3279 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3280 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 3281 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | /** |
| 3285 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 3286 | * @pf: board private structure |
| 3287 | **/ |
| 3288 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 3289 | { |
| 3290 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 3291 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3292 | pci_disable_msix(pf->pdev); |
| 3293 | kfree(pf->msix_entries); |
| 3294 | pf->msix_entries = NULL; |
| 3295 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 3296 | pci_disable_msi(pf->pdev); |
| 3297 | } |
| 3298 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 3299 | } |
| 3300 | |
| 3301 | /** |
| 3302 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 3303 | * @pf: board private structure |
| 3304 | * |
| 3305 | * We go through and clear interrupt specific resources and reset the structure |
| 3306 | * to pre-load conditions |
| 3307 | **/ |
| 3308 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 3309 | { |
| 3310 | int i; |
| 3311 | |
| 3312 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
| 3313 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) |
| 3314 | if (pf->vsi[i]) |
| 3315 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 3316 | i40e_reset_interrupt_capability(pf); |
| 3317 | } |
| 3318 | |
| 3319 | /** |
| 3320 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 3321 | * @vsi: the VSI being configured |
| 3322 | **/ |
| 3323 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 3324 | { |
| 3325 | int q_idx; |
| 3326 | |
| 3327 | if (!vsi->netdev) |
| 3328 | return; |
| 3329 | |
| 3330 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3331 | napi_enable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | /** |
| 3335 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 3336 | * @vsi: the VSI being configured |
| 3337 | **/ |
| 3338 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 3339 | { |
| 3340 | int q_idx; |
| 3341 | |
| 3342 | if (!vsi->netdev) |
| 3343 | return; |
| 3344 | |
| 3345 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3346 | napi_disable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3347 | } |
| 3348 | |
| 3349 | /** |
| 3350 | * i40e_quiesce_vsi - Pause a given VSI |
| 3351 | * @vsi: the VSI being paused |
| 3352 | **/ |
| 3353 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 3354 | { |
| 3355 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 3356 | return; |
| 3357 | |
| 3358 | set_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 3359 | if (vsi->netdev && netif_running(vsi->netdev)) { |
| 3360 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
| 3361 | } else { |
| 3362 | set_bit(__I40E_DOWN, &vsi->state); |
| 3363 | i40e_down(vsi); |
| 3364 | } |
| 3365 | } |
| 3366 | |
| 3367 | /** |
| 3368 | * i40e_unquiesce_vsi - Resume a given VSI |
| 3369 | * @vsi: the VSI being resumed |
| 3370 | **/ |
| 3371 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 3372 | { |
| 3373 | if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) |
| 3374 | return; |
| 3375 | |
| 3376 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 3377 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 3378 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 3379 | else |
| 3380 | i40e_up(vsi); /* this clears the DOWN bit */ |
| 3381 | } |
| 3382 | |
| 3383 | /** |
| 3384 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 3385 | * @pf: the PF |
| 3386 | **/ |
| 3387 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 3388 | { |
| 3389 | int v; |
| 3390 | |
| 3391 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 3392 | if (pf->vsi[v]) |
| 3393 | i40e_quiesce_vsi(pf->vsi[v]); |
| 3394 | } |
| 3395 | } |
| 3396 | |
| 3397 | /** |
| 3398 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 3399 | * @pf: the PF |
| 3400 | **/ |
| 3401 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 3402 | { |
| 3403 | int v; |
| 3404 | |
| 3405 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 3406 | if (pf->vsi[v]) |
| 3407 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 3408 | } |
| 3409 | } |
| 3410 | |
| 3411 | /** |
| 3412 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 3413 | * @dcbcfg: the corresponding DCBx configuration structure |
| 3414 | * |
| 3415 | * Return the number of TCs from given DCBx configuration |
| 3416 | **/ |
| 3417 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 3418 | { |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 3419 | u8 num_tc = 0; |
| 3420 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3421 | |
| 3422 | /* Scan the ETS Config Priority Table to find |
| 3423 | * traffic class enabled for a given priority |
| 3424 | * and use the traffic class index to get the |
| 3425 | * number of traffic classes enabled |
| 3426 | */ |
| 3427 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 3428 | if (dcbcfg->etscfg.prioritytable[i] > num_tc) |
| 3429 | num_tc = dcbcfg->etscfg.prioritytable[i]; |
| 3430 | } |
| 3431 | |
| 3432 | /* Traffic class index starts from zero so |
| 3433 | * increment to return the actual count |
| 3434 | */ |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 3435 | return num_tc + 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3436 | } |
| 3437 | |
| 3438 | /** |
| 3439 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 3440 | * @dcbcfg: the corresponding DCBx configuration structure |
| 3441 | * |
| 3442 | * Query the current DCB configuration and return the number of |
| 3443 | * traffic classes enabled from the given DCBX config |
| 3444 | **/ |
| 3445 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 3446 | { |
| 3447 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 3448 | u8 enabled_tc = 1; |
| 3449 | u8 i; |
| 3450 | |
| 3451 | for (i = 0; i < num_tc; i++) |
| 3452 | enabled_tc |= 1 << i; |
| 3453 | |
| 3454 | return enabled_tc; |
| 3455 | } |
| 3456 | |
| 3457 | /** |
| 3458 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 3459 | * @pf: PF being queried |
| 3460 | * |
| 3461 | * Return number of traffic classes enabled for the given PF |
| 3462 | **/ |
| 3463 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 3464 | { |
| 3465 | struct i40e_hw *hw = &pf->hw; |
| 3466 | u8 i, enabled_tc; |
| 3467 | u8 num_tc = 0; |
| 3468 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 3469 | |
| 3470 | /* If DCB is not enabled then always in single TC */ |
| 3471 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 3472 | return 1; |
| 3473 | |
| 3474 | /* MFP mode return count of enabled TCs for this PF */ |
| 3475 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 3476 | enabled_tc = pf->hw.func_caps.enabled_tcmap; |
| 3477 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 3478 | if (enabled_tc & (1 << i)) |
| 3479 | num_tc++; |
| 3480 | } |
| 3481 | return num_tc; |
| 3482 | } |
| 3483 | |
| 3484 | /* SFP mode will be enabled for all TCs on port */ |
| 3485 | return i40e_dcb_get_num_tc(dcbcfg); |
| 3486 | } |
| 3487 | |
| 3488 | /** |
| 3489 | * i40e_pf_get_default_tc - Get bitmap for first enabled TC |
| 3490 | * @pf: PF being queried |
| 3491 | * |
| 3492 | * Return a bitmap for first enabled traffic class for this PF. |
| 3493 | **/ |
| 3494 | static u8 i40e_pf_get_default_tc(struct i40e_pf *pf) |
| 3495 | { |
| 3496 | u8 enabled_tc = pf->hw.func_caps.enabled_tcmap; |
| 3497 | u8 i = 0; |
| 3498 | |
| 3499 | if (!enabled_tc) |
| 3500 | return 0x1; /* TC0 */ |
| 3501 | |
| 3502 | /* Find the first enabled TC */ |
| 3503 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 3504 | if (enabled_tc & (1 << i)) |
| 3505 | break; |
| 3506 | } |
| 3507 | |
| 3508 | return 1 << i; |
| 3509 | } |
| 3510 | |
| 3511 | /** |
| 3512 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 3513 | * @pf: PF being queried |
| 3514 | * |
| 3515 | * Return a bitmap for enabled traffic classes for this PF. |
| 3516 | **/ |
| 3517 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 3518 | { |
| 3519 | /* If DCB is not enabled for this PF then just return default TC */ |
| 3520 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 3521 | return i40e_pf_get_default_tc(pf); |
| 3522 | |
| 3523 | /* MFP mode will have enabled TCs set by FW */ |
| 3524 | if (pf->flags & I40E_FLAG_MFP_ENABLED) |
| 3525 | return pf->hw.func_caps.enabled_tcmap; |
| 3526 | |
| 3527 | /* SFP mode we want PF to be enabled for all TCs */ |
| 3528 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); |
| 3529 | } |
| 3530 | |
| 3531 | /** |
| 3532 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 3533 | * @vsi: the VSI being queried |
| 3534 | * |
| 3535 | * Returns 0 on success, negative value on failure |
| 3536 | **/ |
| 3537 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 3538 | { |
| 3539 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 3540 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 3541 | struct i40e_pf *pf = vsi->back; |
| 3542 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3543 | i40e_status aq_ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3544 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3545 | int i; |
| 3546 | |
| 3547 | /* Get the VSI level BW configuration */ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3548 | aq_ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
| 3549 | if (aq_ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3550 | dev_info(&pf->pdev->dev, |
| 3551 | "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] | 3552 | aq_ret, pf->hw.aq.asq_last_status); |
| 3553 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3554 | } |
| 3555 | |
| 3556 | /* Get the VSI level BW configuration per TC */ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3557 | aq_ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
| 3558 | NULL); |
| 3559 | if (aq_ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3560 | dev_info(&pf->pdev->dev, |
| 3561 | "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] | 3562 | aq_ret, pf->hw.aq.asq_last_status); |
| 3563 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 3567 | dev_info(&pf->pdev->dev, |
| 3568 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 3569 | bw_config.tc_valid_bits, |
| 3570 | bw_ets_config.tc_valid_bits); |
| 3571 | /* Still continuing */ |
| 3572 | } |
| 3573 | |
| 3574 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 3575 | vsi->bw_max_quanta = bw_config.max_bw; |
| 3576 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 3577 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 3578 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 3579 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 3580 | vsi->bw_ets_limit_credits[i] = |
| 3581 | le16_to_cpu(bw_ets_config.credits[i]); |
| 3582 | /* 3 bits out of 4 for each TC */ |
| 3583 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 3584 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 3585 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3586 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3587 | } |
| 3588 | |
| 3589 | /** |
| 3590 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 3591 | * @vsi: the VSI being configured |
| 3592 | * @enabled_tc: TC bitmap |
| 3593 | * @bw_credits: BW shared credits per TC |
| 3594 | * |
| 3595 | * Returns 0 on success, negative value on failure |
| 3596 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3597 | 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] | 3598 | u8 *bw_share) |
| 3599 | { |
| 3600 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3601 | i40e_status aq_ret; |
| 3602 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3603 | |
| 3604 | bw_data.tc_valid_bits = enabled_tc; |
| 3605 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 3606 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 3607 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3608 | aq_ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 3609 | NULL); |
| 3610 | if (aq_ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3611 | dev_info(&vsi->back->pdev->dev, |
| 3612 | "%s: AQ command Config VSI BW allocation per TC failed = %d\n", |
| 3613 | __func__, vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3614 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3615 | } |
| 3616 | |
| 3617 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 3618 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 3619 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3620 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3621 | } |
| 3622 | |
| 3623 | /** |
| 3624 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 3625 | * @vsi: the VSI being configured |
| 3626 | * @enabled_tc: TC map to be enabled |
| 3627 | * |
| 3628 | **/ |
| 3629 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 3630 | { |
| 3631 | struct net_device *netdev = vsi->netdev; |
| 3632 | struct i40e_pf *pf = vsi->back; |
| 3633 | struct i40e_hw *hw = &pf->hw; |
| 3634 | u8 netdev_tc = 0; |
| 3635 | int i; |
| 3636 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 3637 | |
| 3638 | if (!netdev) |
| 3639 | return; |
| 3640 | |
| 3641 | if (!enabled_tc) { |
| 3642 | netdev_reset_tc(netdev); |
| 3643 | return; |
| 3644 | } |
| 3645 | |
| 3646 | /* Set up actual enabled TCs on the VSI */ |
| 3647 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 3648 | return; |
| 3649 | |
| 3650 | /* set per TC queues for the VSI */ |
| 3651 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 3652 | /* Only set TC queues for enabled tcs |
| 3653 | * |
| 3654 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 3655 | * enabled_tc bitmap would be 0x00001001; the driver |
| 3656 | * will set the numtc for netdev as 2 that will be |
| 3657 | * referenced by the netdev layer as TC 0 and 1. |
| 3658 | */ |
| 3659 | if (vsi->tc_config.enabled_tc & (1 << i)) |
| 3660 | netdev_set_tc_queue(netdev, |
| 3661 | vsi->tc_config.tc_info[i].netdev_tc, |
| 3662 | vsi->tc_config.tc_info[i].qcount, |
| 3663 | vsi->tc_config.tc_info[i].qoffset); |
| 3664 | } |
| 3665 | |
| 3666 | /* Assign UP2TC map for the VSI */ |
| 3667 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 3668 | /* Get the actual TC# for the UP */ |
| 3669 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 3670 | /* Get the mapped netdev TC# for the UP */ |
| 3671 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 3672 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 3673 | } |
| 3674 | } |
| 3675 | |
| 3676 | /** |
| 3677 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 3678 | * @vsi: the VSI being configured |
| 3679 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 3680 | **/ |
| 3681 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 3682 | struct i40e_vsi_context *ctxt) |
| 3683 | { |
| 3684 | /* copy just the sections touched not the entire info |
| 3685 | * since not all sections are valid as returned by |
| 3686 | * update vsi params |
| 3687 | */ |
| 3688 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 3689 | memcpy(&vsi->info.queue_mapping, |
| 3690 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 3691 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 3692 | sizeof(vsi->info.tc_mapping)); |
| 3693 | } |
| 3694 | |
| 3695 | /** |
| 3696 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 3697 | * @vsi: VSI to be configured |
| 3698 | * @enabled_tc: TC bitmap |
| 3699 | * |
| 3700 | * This configures a particular VSI for TCs that are mapped to the |
| 3701 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 3702 | * VSIs to configure TC for a particular VSI. |
| 3703 | * |
| 3704 | * NOTE: |
| 3705 | * It is expected that the VSI queues have been quisced before calling |
| 3706 | * this function. |
| 3707 | **/ |
| 3708 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 3709 | { |
| 3710 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 3711 | struct i40e_vsi_context ctxt; |
| 3712 | int ret = 0; |
| 3713 | int i; |
| 3714 | |
| 3715 | /* Check if enabled_tc is same as existing or new TCs */ |
| 3716 | if (vsi->tc_config.enabled_tc == enabled_tc) |
| 3717 | return ret; |
| 3718 | |
| 3719 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 3720 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 3721 | if (enabled_tc & (1 << i)) |
| 3722 | bw_share[i] = 1; |
| 3723 | } |
| 3724 | |
| 3725 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 3726 | if (ret) { |
| 3727 | dev_info(&vsi->back->pdev->dev, |
| 3728 | "Failed configuring TC map %d for VSI %d\n", |
| 3729 | enabled_tc, vsi->seid); |
| 3730 | goto out; |
| 3731 | } |
| 3732 | |
| 3733 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 3734 | ctxt.seid = vsi->seid; |
| 3735 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 3736 | ctxt.vf_num = 0; |
| 3737 | ctxt.uplink_seid = vsi->uplink_seid; |
| 3738 | memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info)); |
| 3739 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 3740 | |
| 3741 | /* Update the VSI after updating the VSI queue-mapping information */ |
| 3742 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 3743 | if (ret) { |
| 3744 | dev_info(&vsi->back->pdev->dev, |
| 3745 | "update vsi failed, aq_err=%d\n", |
| 3746 | vsi->back->hw.aq.asq_last_status); |
| 3747 | goto out; |
| 3748 | } |
| 3749 | /* update the local VSI info with updated queue map */ |
| 3750 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 3751 | vsi->info.valid_sections = 0; |
| 3752 | |
| 3753 | /* Update current VSI BW information */ |
| 3754 | ret = i40e_vsi_get_bw_info(vsi); |
| 3755 | if (ret) { |
| 3756 | dev_info(&vsi->back->pdev->dev, |
| 3757 | "Failed updating vsi bw info, aq_err=%d\n", |
| 3758 | vsi->back->hw.aq.asq_last_status); |
| 3759 | goto out; |
| 3760 | } |
| 3761 | |
| 3762 | /* Update the netdev TC setup */ |
| 3763 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 3764 | out: |
| 3765 | return ret; |
| 3766 | } |
| 3767 | |
| 3768 | /** |
| 3769 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 3770 | * @vsi: the VSI being configured |
| 3771 | **/ |
| 3772 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 3773 | { |
| 3774 | struct i40e_pf *pf = vsi->back; |
| 3775 | int err; |
| 3776 | |
| 3777 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 3778 | i40e_vsi_configure_msix(vsi); |
| 3779 | else |
| 3780 | i40e_configure_msi_and_legacy(vsi); |
| 3781 | |
| 3782 | /* start rings */ |
| 3783 | err = i40e_vsi_control_rings(vsi, true); |
| 3784 | if (err) |
| 3785 | return err; |
| 3786 | |
| 3787 | clear_bit(__I40E_DOWN, &vsi->state); |
| 3788 | i40e_napi_enable_all(vsi); |
| 3789 | i40e_vsi_enable_irq(vsi); |
| 3790 | |
| 3791 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 3792 | (vsi->netdev)) { |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 3793 | netdev_info(vsi->netdev, "NIC Link is Up\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3794 | netif_tx_start_all_queues(vsi->netdev); |
| 3795 | netif_carrier_on(vsi->netdev); |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 3796 | } else if (vsi->netdev) { |
| 3797 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3798 | } |
| 3799 | i40e_service_event_schedule(pf); |
| 3800 | |
| 3801 | return 0; |
| 3802 | } |
| 3803 | |
| 3804 | /** |
| 3805 | * i40e_vsi_reinit_locked - Reset the VSI |
| 3806 | * @vsi: the VSI being configured |
| 3807 | * |
| 3808 | * Rebuild the ring structs after some configuration |
| 3809 | * has changed, e.g. MTU size. |
| 3810 | **/ |
| 3811 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 3812 | { |
| 3813 | struct i40e_pf *pf = vsi->back; |
| 3814 | |
| 3815 | WARN_ON(in_interrupt()); |
| 3816 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 3817 | usleep_range(1000, 2000); |
| 3818 | i40e_down(vsi); |
| 3819 | |
| 3820 | /* Give a VF some time to respond to the reset. The |
| 3821 | * two second wait is based upon the watchdog cycle in |
| 3822 | * the VF driver. |
| 3823 | */ |
| 3824 | if (vsi->type == I40E_VSI_SRIOV) |
| 3825 | msleep(2000); |
| 3826 | i40e_up(vsi); |
| 3827 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 3828 | } |
| 3829 | |
| 3830 | /** |
| 3831 | * i40e_up - Bring the connection back up after being down |
| 3832 | * @vsi: the VSI being configured |
| 3833 | **/ |
| 3834 | int i40e_up(struct i40e_vsi *vsi) |
| 3835 | { |
| 3836 | int err; |
| 3837 | |
| 3838 | err = i40e_vsi_configure(vsi); |
| 3839 | if (!err) |
| 3840 | err = i40e_up_complete(vsi); |
| 3841 | |
| 3842 | return err; |
| 3843 | } |
| 3844 | |
| 3845 | /** |
| 3846 | * i40e_down - Shutdown the connection processing |
| 3847 | * @vsi: the VSI being stopped |
| 3848 | **/ |
| 3849 | void i40e_down(struct i40e_vsi *vsi) |
| 3850 | { |
| 3851 | int i; |
| 3852 | |
| 3853 | /* It is assumed that the caller of this function |
| 3854 | * sets the vsi->state __I40E_DOWN bit. |
| 3855 | */ |
| 3856 | if (vsi->netdev) { |
| 3857 | netif_carrier_off(vsi->netdev); |
| 3858 | netif_tx_disable(vsi->netdev); |
| 3859 | } |
| 3860 | i40e_vsi_disable_irq(vsi); |
| 3861 | i40e_vsi_control_rings(vsi, false); |
| 3862 | i40e_napi_disable_all(vsi); |
| 3863 | |
| 3864 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3865 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
| 3866 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3867 | } |
| 3868 | } |
| 3869 | |
| 3870 | /** |
| 3871 | * i40e_setup_tc - configure multiple traffic classes |
| 3872 | * @netdev: net device to configure |
| 3873 | * @tc: number of traffic classes to enable |
| 3874 | **/ |
| 3875 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) |
| 3876 | { |
| 3877 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3878 | struct i40e_vsi *vsi = np->vsi; |
| 3879 | struct i40e_pf *pf = vsi->back; |
| 3880 | u8 enabled_tc = 0; |
| 3881 | int ret = -EINVAL; |
| 3882 | int i; |
| 3883 | |
| 3884 | /* Check if DCB enabled to continue */ |
| 3885 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 3886 | netdev_info(netdev, "DCB is not enabled for adapter\n"); |
| 3887 | goto exit; |
| 3888 | } |
| 3889 | |
| 3890 | /* Check if MFP enabled */ |
| 3891 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 3892 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); |
| 3893 | goto exit; |
| 3894 | } |
| 3895 | |
| 3896 | /* Check whether tc count is within enabled limit */ |
| 3897 | if (tc > i40e_pf_get_num_tc(pf)) { |
| 3898 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); |
| 3899 | goto exit; |
| 3900 | } |
| 3901 | |
| 3902 | /* Generate TC map for number of tc requested */ |
| 3903 | for (i = 0; i < tc; i++) |
| 3904 | enabled_tc |= (1 << i); |
| 3905 | |
| 3906 | /* Requesting same TC configuration as already enabled */ |
| 3907 | if (enabled_tc == vsi->tc_config.enabled_tc) |
| 3908 | return 0; |
| 3909 | |
| 3910 | /* Quiesce VSI queues */ |
| 3911 | i40e_quiesce_vsi(vsi); |
| 3912 | |
| 3913 | /* Configure VSI for enabled TCs */ |
| 3914 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 3915 | if (ret) { |
| 3916 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 3917 | vsi->seid); |
| 3918 | goto exit; |
| 3919 | } |
| 3920 | |
| 3921 | /* Unquiesce VSI */ |
| 3922 | i40e_unquiesce_vsi(vsi); |
| 3923 | |
| 3924 | exit: |
| 3925 | return ret; |
| 3926 | } |
| 3927 | |
| 3928 | /** |
| 3929 | * i40e_open - Called when a network interface is made active |
| 3930 | * @netdev: network interface device structure |
| 3931 | * |
| 3932 | * The open entry point is called when a network interface is made |
| 3933 | * active by the system (IFF_UP). At this point all resources needed |
| 3934 | * for transmit and receive operations are allocated, the interrupt |
| 3935 | * handler is registered with the OS, the netdev watchdog subtask is |
| 3936 | * enabled, and the stack is notified that the interface is ready. |
| 3937 | * |
| 3938 | * Returns 0 on success, negative value on failure |
| 3939 | **/ |
| 3940 | static int i40e_open(struct net_device *netdev) |
| 3941 | { |
| 3942 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3943 | struct i40e_vsi *vsi = np->vsi; |
| 3944 | struct i40e_pf *pf = vsi->back; |
| 3945 | char int_name[IFNAMSIZ]; |
| 3946 | int err; |
| 3947 | |
| 3948 | /* disallow open during test */ |
| 3949 | if (test_bit(__I40E_TESTING, &pf->state)) |
| 3950 | return -EBUSY; |
| 3951 | |
| 3952 | netif_carrier_off(netdev); |
| 3953 | |
| 3954 | /* allocate descriptors */ |
| 3955 | err = i40e_vsi_setup_tx_resources(vsi); |
| 3956 | if (err) |
| 3957 | goto err_setup_tx; |
| 3958 | err = i40e_vsi_setup_rx_resources(vsi); |
| 3959 | if (err) |
| 3960 | goto err_setup_rx; |
| 3961 | |
| 3962 | err = i40e_vsi_configure(vsi); |
| 3963 | if (err) |
| 3964 | goto err_setup_rx; |
| 3965 | |
| 3966 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 3967 | dev_driver_string(&pf->pdev->dev), netdev->name); |
| 3968 | err = i40e_vsi_request_irq(vsi, int_name); |
| 3969 | if (err) |
| 3970 | goto err_setup_rx; |
| 3971 | |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 3972 | /* Notify the stack of the actual queue counts. */ |
| 3973 | err = netif_set_real_num_tx_queues(netdev, pf->num_tx_queues); |
| 3974 | if (err) |
| 3975 | goto err_set_queues; |
| 3976 | |
| 3977 | err = netif_set_real_num_rx_queues(netdev, pf->num_rx_queues); |
| 3978 | if (err) |
| 3979 | goto err_set_queues; |
| 3980 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3981 | err = i40e_up_complete(vsi); |
| 3982 | if (err) |
| 3983 | goto err_up_complete; |
| 3984 | |
| 3985 | if ((vsi->type == I40E_VSI_MAIN) || (vsi->type == I40E_VSI_VMDQ2)) { |
| 3986 | err = i40e_aq_set_vsi_broadcast(&pf->hw, vsi->seid, true, NULL); |
| 3987 | if (err) |
| 3988 | netdev_info(netdev, |
| 3989 | "couldn't set broadcast err %d aq_err %d\n", |
| 3990 | err, pf->hw.aq.asq_last_status); |
| 3991 | } |
| 3992 | |
| 3993 | return 0; |
| 3994 | |
| 3995 | err_up_complete: |
| 3996 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 3997 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3998 | i40e_vsi_free_irq(vsi); |
| 3999 | err_setup_rx: |
| 4000 | i40e_vsi_free_rx_resources(vsi); |
| 4001 | err_setup_tx: |
| 4002 | i40e_vsi_free_tx_resources(vsi); |
| 4003 | if (vsi == pf->vsi[pf->lan_vsi]) |
| 4004 | i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED)); |
| 4005 | |
| 4006 | return err; |
| 4007 | } |
| 4008 | |
| 4009 | /** |
| 4010 | * i40e_close - Disables a network interface |
| 4011 | * @netdev: network interface device structure |
| 4012 | * |
| 4013 | * The close entry point is called when an interface is de-activated |
| 4014 | * by the OS. The hardware is still under the driver's control, but |
| 4015 | * this netdev interface is disabled. |
| 4016 | * |
| 4017 | * Returns 0, this is not allowed to fail |
| 4018 | **/ |
| 4019 | static int i40e_close(struct net_device *netdev) |
| 4020 | { |
| 4021 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 4022 | struct i40e_vsi *vsi = np->vsi; |
| 4023 | |
| 4024 | if (test_and_set_bit(__I40E_DOWN, &vsi->state)) |
| 4025 | return 0; |
| 4026 | |
| 4027 | i40e_down(vsi); |
| 4028 | i40e_vsi_free_irq(vsi); |
| 4029 | |
| 4030 | i40e_vsi_free_tx_resources(vsi); |
| 4031 | i40e_vsi_free_rx_resources(vsi); |
| 4032 | |
| 4033 | return 0; |
| 4034 | } |
| 4035 | |
| 4036 | /** |
| 4037 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 4038 | * @pf: board private structure |
| 4039 | * @reset_flags: which reset is requested |
| 4040 | * |
| 4041 | * The essential difference in resets is that the PF Reset |
| 4042 | * doesn't clear the packet buffers, doesn't reset the PE |
| 4043 | * firmware, and doesn't bother the other PFs on the chip. |
| 4044 | **/ |
| 4045 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags) |
| 4046 | { |
| 4047 | u32 val; |
| 4048 | |
| 4049 | WARN_ON(in_interrupt()); |
| 4050 | |
| 4051 | /* do the biggest reset indicated */ |
| 4052 | if (reset_flags & (1 << __I40E_GLOBAL_RESET_REQUESTED)) { |
| 4053 | |
| 4054 | /* Request a Global Reset |
| 4055 | * |
| 4056 | * This will start the chip's countdown to the actual full |
| 4057 | * chip reset event, and a warning interrupt to be sent |
| 4058 | * to all PFs, including the requestor. Our handler |
| 4059 | * for the warning interrupt will deal with the shutdown |
| 4060 | * and recovery of the switch setup. |
| 4061 | */ |
| 4062 | dev_info(&pf->pdev->dev, "GlobalR requested\n"); |
| 4063 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 4064 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; |
| 4065 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 4066 | |
| 4067 | } else if (reset_flags & (1 << __I40E_CORE_RESET_REQUESTED)) { |
| 4068 | |
| 4069 | /* Request a Core Reset |
| 4070 | * |
| 4071 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 4072 | */ |
| 4073 | dev_info(&pf->pdev->dev, "CoreR requested\n"); |
| 4074 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 4075 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 4076 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 4077 | i40e_flush(&pf->hw); |
| 4078 | |
Shannon Nelson | 7823fe3 | 2013-11-16 10:00:45 +0000 | [diff] [blame] | 4079 | } else if (reset_flags & (1 << __I40E_EMP_RESET_REQUESTED)) { |
| 4080 | |
| 4081 | /* Request a Firmware Reset |
| 4082 | * |
| 4083 | * Same as Global reset, plus restarting the |
| 4084 | * embedded firmware engine. |
| 4085 | */ |
| 4086 | /* enable EMP Reset */ |
| 4087 | val = rd32(&pf->hw, I40E_GLGEN_RSTENA_EMP); |
| 4088 | val |= I40E_GLGEN_RSTENA_EMP_EMP_RST_ENA_MASK; |
| 4089 | wr32(&pf->hw, I40E_GLGEN_RSTENA_EMP, val); |
| 4090 | |
| 4091 | /* force the reset */ |
| 4092 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 4093 | val |= I40E_GLGEN_RTRIG_EMPFWR_MASK; |
| 4094 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 4095 | i40e_flush(&pf->hw); |
| 4096 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4097 | } else if (reset_flags & (1 << __I40E_PF_RESET_REQUESTED)) { |
| 4098 | |
| 4099 | /* Request a PF Reset |
| 4100 | * |
| 4101 | * Resets only the PF-specific registers |
| 4102 | * |
| 4103 | * This goes directly to the tear-down and rebuild of |
| 4104 | * the switch, since we need to do all the recovery as |
| 4105 | * for the Core Reset. |
| 4106 | */ |
| 4107 | dev_info(&pf->pdev->dev, "PFR requested\n"); |
| 4108 | i40e_handle_reset_warning(pf); |
| 4109 | |
| 4110 | } else if (reset_flags & (1 << __I40E_REINIT_REQUESTED)) { |
| 4111 | int v; |
| 4112 | |
| 4113 | /* Find the VSI(s) that requested a re-init */ |
| 4114 | dev_info(&pf->pdev->dev, |
| 4115 | "VSI reinit requested\n"); |
| 4116 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 4117 | struct i40e_vsi *vsi = pf->vsi[v]; |
| 4118 | if (vsi != NULL && |
| 4119 | test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { |
| 4120 | i40e_vsi_reinit_locked(pf->vsi[v]); |
| 4121 | clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 4122 | } |
| 4123 | } |
| 4124 | |
| 4125 | /* no further action needed, so return now */ |
| 4126 | return; |
| 4127 | } else { |
| 4128 | dev_info(&pf->pdev->dev, |
| 4129 | "bad reset request 0x%08x\n", reset_flags); |
| 4130 | return; |
| 4131 | } |
| 4132 | } |
| 4133 | |
| 4134 | /** |
| 4135 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 4136 | * @pf: board private structure |
| 4137 | * @e: event info posted on ARQ |
| 4138 | * |
| 4139 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 4140 | * and VF queues |
| 4141 | **/ |
| 4142 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 4143 | struct i40e_arq_event_info *e) |
| 4144 | { |
| 4145 | struct i40e_aqc_lan_overflow *data = |
| 4146 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 4147 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 4148 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 4149 | struct i40e_hw *hw = &pf->hw; |
| 4150 | struct i40e_vf *vf; |
| 4151 | u16 vf_id; |
| 4152 | |
| 4153 | dev_info(&pf->pdev->dev, "%s: Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 4154 | __func__, queue, qtx_ctl); |
| 4155 | |
| 4156 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 4157 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 4158 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 4159 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 4160 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 4161 | vf_id -= hw->func_caps.vf_base_id; |
| 4162 | vf = &pf->vf[vf_id]; |
| 4163 | i40e_vc_notify_vf_reset(vf); |
| 4164 | /* Allow VF to process pending reset notification */ |
| 4165 | msleep(20); |
| 4166 | i40e_reset_vf(vf, false); |
| 4167 | } |
| 4168 | } |
| 4169 | |
| 4170 | /** |
| 4171 | * i40e_service_event_complete - Finish up the service event |
| 4172 | * @pf: board private structure |
| 4173 | **/ |
| 4174 | static void i40e_service_event_complete(struct i40e_pf *pf) |
| 4175 | { |
| 4176 | BUG_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state)); |
| 4177 | |
| 4178 | /* flush memory to make sure state is correct before next watchog */ |
| 4179 | smp_mb__before_clear_bit(); |
| 4180 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 4181 | } |
| 4182 | |
| 4183 | /** |
| 4184 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 4185 | * @pf: board private structure |
| 4186 | **/ |
| 4187 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 4188 | { |
| 4189 | if (!(pf->flags & I40E_FLAG_FDIR_REQUIRES_REINIT)) |
| 4190 | return; |
| 4191 | |
| 4192 | pf->flags &= ~I40E_FLAG_FDIR_REQUIRES_REINIT; |
| 4193 | |
| 4194 | /* if interface is down do nothing */ |
| 4195 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 4196 | return; |
| 4197 | } |
| 4198 | |
| 4199 | /** |
| 4200 | * i40e_vsi_link_event - notify VSI of a link event |
| 4201 | * @vsi: vsi to be notified |
| 4202 | * @link_up: link up or down |
| 4203 | **/ |
| 4204 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 4205 | { |
| 4206 | if (!vsi) |
| 4207 | return; |
| 4208 | |
| 4209 | switch (vsi->type) { |
| 4210 | case I40E_VSI_MAIN: |
| 4211 | if (!vsi->netdev || !vsi->netdev_registered) |
| 4212 | break; |
| 4213 | |
| 4214 | if (link_up) { |
| 4215 | netif_carrier_on(vsi->netdev); |
| 4216 | netif_tx_wake_all_queues(vsi->netdev); |
| 4217 | } else { |
| 4218 | netif_carrier_off(vsi->netdev); |
| 4219 | netif_tx_stop_all_queues(vsi->netdev); |
| 4220 | } |
| 4221 | break; |
| 4222 | |
| 4223 | case I40E_VSI_SRIOV: |
| 4224 | break; |
| 4225 | |
| 4226 | case I40E_VSI_VMDQ2: |
| 4227 | case I40E_VSI_CTRL: |
| 4228 | case I40E_VSI_MIRROR: |
| 4229 | default: |
| 4230 | /* there is no notification for other VSIs */ |
| 4231 | break; |
| 4232 | } |
| 4233 | } |
| 4234 | |
| 4235 | /** |
| 4236 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 4237 | * @veb: veb to be notified |
| 4238 | * @link_up: link up or down |
| 4239 | **/ |
| 4240 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 4241 | { |
| 4242 | struct i40e_pf *pf; |
| 4243 | int i; |
| 4244 | |
| 4245 | if (!veb || !veb->pf) |
| 4246 | return; |
| 4247 | pf = veb->pf; |
| 4248 | |
| 4249 | /* depth first... */ |
| 4250 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 4251 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 4252 | i40e_veb_link_event(pf->veb[i], link_up); |
| 4253 | |
| 4254 | /* ... now the local VSIs */ |
| 4255 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) |
| 4256 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 4257 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 4258 | } |
| 4259 | |
| 4260 | /** |
| 4261 | * i40e_link_event - Update netif_carrier status |
| 4262 | * @pf: board private structure |
| 4263 | **/ |
| 4264 | static void i40e_link_event(struct i40e_pf *pf) |
| 4265 | { |
| 4266 | bool new_link, old_link; |
| 4267 | |
| 4268 | new_link = (pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP); |
| 4269 | old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP); |
| 4270 | |
| 4271 | if (new_link == old_link) |
| 4272 | return; |
| 4273 | |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 4274 | if (!test_bit(__I40E_DOWN, &pf->vsi[pf->lan_vsi]->state)) |
| 4275 | netdev_info(pf->vsi[pf->lan_vsi]->netdev, |
| 4276 | "NIC Link is %s\n", (new_link ? "Up" : "Down")); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4277 | |
| 4278 | /* Notify the base of the switch tree connected to |
| 4279 | * the link. Floating VEBs are not notified. |
| 4280 | */ |
| 4281 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 4282 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 4283 | else |
| 4284 | i40e_vsi_link_event(pf->vsi[pf->lan_vsi], new_link); |
| 4285 | |
| 4286 | if (pf->vf) |
| 4287 | i40e_vc_notify_link_state(pf); |
| 4288 | } |
| 4289 | |
| 4290 | /** |
| 4291 | * i40e_check_hang_subtask - Check for hung queues and dropped interrupts |
| 4292 | * @pf: board private structure |
| 4293 | * |
| 4294 | * Set the per-queue flags to request a check for stuck queues in the irq |
| 4295 | * clean functions, then force interrupts to be sure the irq clean is called. |
| 4296 | **/ |
| 4297 | static void i40e_check_hang_subtask(struct i40e_pf *pf) |
| 4298 | { |
| 4299 | int i, v; |
| 4300 | |
| 4301 | /* If we're down or resetting, just bail */ |
| 4302 | if (test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 4303 | return; |
| 4304 | |
| 4305 | /* for each VSI/netdev |
| 4306 | * for each Tx queue |
| 4307 | * set the check flag |
| 4308 | * for each q_vector |
| 4309 | * force an interrupt |
| 4310 | */ |
| 4311 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 4312 | struct i40e_vsi *vsi = pf->vsi[v]; |
| 4313 | int armed = 0; |
| 4314 | |
| 4315 | if (!pf->vsi[v] || |
| 4316 | test_bit(__I40E_DOWN, &vsi->state) || |
| 4317 | (vsi->netdev && !netif_carrier_ok(vsi->netdev))) |
| 4318 | continue; |
| 4319 | |
| 4320 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 4321 | set_check_for_tx_hang(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4322 | if (test_bit(__I40E_HANG_CHECK_ARMED, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 4323 | &vsi->tx_rings[i]->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4324 | armed++; |
| 4325 | } |
| 4326 | |
| 4327 | if (armed) { |
| 4328 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
| 4329 | wr32(&vsi->back->hw, I40E_PFINT_DYN_CTL0, |
| 4330 | (I40E_PFINT_DYN_CTL0_INTENA_MASK | |
| 4331 | I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK)); |
| 4332 | } else { |
| 4333 | u16 vec = vsi->base_vector - 1; |
| 4334 | u32 val = (I40E_PFINT_DYN_CTLN_INTENA_MASK | |
| 4335 | I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK); |
| 4336 | for (i = 0; i < vsi->num_q_vectors; i++, vec++) |
| 4337 | wr32(&vsi->back->hw, |
| 4338 | I40E_PFINT_DYN_CTLN(vec), val); |
| 4339 | } |
| 4340 | i40e_flush(&vsi->back->hw); |
| 4341 | } |
| 4342 | } |
| 4343 | } |
| 4344 | |
| 4345 | /** |
| 4346 | * i40e_watchdog_subtask - Check and bring link up |
| 4347 | * @pf: board private structure |
| 4348 | **/ |
| 4349 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 4350 | { |
| 4351 | int i; |
| 4352 | |
| 4353 | /* if interface is down do nothing */ |
| 4354 | if (test_bit(__I40E_DOWN, &pf->state) || |
| 4355 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 4356 | return; |
| 4357 | |
| 4358 | /* Update the stats for active netdevs so the network stack |
| 4359 | * can look at updated numbers whenever it cares to |
| 4360 | */ |
| 4361 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) |
| 4362 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 4363 | i40e_update_stats(pf->vsi[i]); |
| 4364 | |
| 4365 | /* Update the stats for the active switching components */ |
| 4366 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 4367 | if (pf->veb[i]) |
| 4368 | i40e_update_veb_stats(pf->veb[i]); |
| 4369 | } |
| 4370 | |
| 4371 | /** |
| 4372 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 4373 | * @pf: board private structure |
| 4374 | **/ |
| 4375 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 4376 | { |
| 4377 | u32 reset_flags = 0; |
| 4378 | |
| 4379 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { |
| 4380 | reset_flags |= (1 << __I40E_REINIT_REQUESTED); |
| 4381 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 4382 | } |
| 4383 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { |
| 4384 | reset_flags |= (1 << __I40E_PF_RESET_REQUESTED); |
| 4385 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 4386 | } |
| 4387 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { |
| 4388 | reset_flags |= (1 << __I40E_CORE_RESET_REQUESTED); |
| 4389 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 4390 | } |
| 4391 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { |
| 4392 | reset_flags |= (1 << __I40E_GLOBAL_RESET_REQUESTED); |
| 4393 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 4394 | } |
| 4395 | |
| 4396 | /* If there's a recovery already waiting, it takes |
| 4397 | * precedence before starting a new reset sequence. |
| 4398 | */ |
| 4399 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { |
| 4400 | i40e_handle_reset_warning(pf); |
| 4401 | return; |
| 4402 | } |
| 4403 | |
| 4404 | /* If we're already down or resetting, just bail */ |
| 4405 | if (reset_flags && |
| 4406 | !test_bit(__I40E_DOWN, &pf->state) && |
| 4407 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 4408 | i40e_do_reset(pf, reset_flags); |
| 4409 | } |
| 4410 | |
| 4411 | /** |
| 4412 | * i40e_handle_link_event - Handle link event |
| 4413 | * @pf: board private structure |
| 4414 | * @e: event info posted on ARQ |
| 4415 | **/ |
| 4416 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 4417 | struct i40e_arq_event_info *e) |
| 4418 | { |
| 4419 | struct i40e_hw *hw = &pf->hw; |
| 4420 | struct i40e_aqc_get_link_status *status = |
| 4421 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
| 4422 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; |
| 4423 | |
| 4424 | /* save off old link status information */ |
| 4425 | memcpy(&pf->hw.phy.link_info_old, hw_link_info, |
| 4426 | sizeof(pf->hw.phy.link_info_old)); |
| 4427 | |
| 4428 | /* update link status */ |
| 4429 | hw_link_info->phy_type = (enum i40e_aq_phy_type)status->phy_type; |
| 4430 | hw_link_info->link_speed = (enum i40e_aq_link_speed)status->link_speed; |
| 4431 | hw_link_info->link_info = status->link_info; |
| 4432 | hw_link_info->an_info = status->an_info; |
| 4433 | hw_link_info->ext_info = status->ext_info; |
| 4434 | hw_link_info->lse_enable = |
| 4435 | le16_to_cpu(status->command_flags) & |
| 4436 | I40E_AQ_LSE_ENABLE; |
| 4437 | |
| 4438 | /* process the event */ |
| 4439 | i40e_link_event(pf); |
| 4440 | |
| 4441 | /* Do a new status request to re-enable LSE reporting |
| 4442 | * and load new status information into the hw struct, |
| 4443 | * then see if the status changed while processing the |
| 4444 | * initial event. |
| 4445 | */ |
| 4446 | i40e_aq_get_link_info(&pf->hw, true, NULL, NULL); |
| 4447 | i40e_link_event(pf); |
| 4448 | } |
| 4449 | |
| 4450 | /** |
| 4451 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 4452 | * @pf: board private structure |
| 4453 | **/ |
| 4454 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 4455 | { |
| 4456 | struct i40e_arq_event_info event; |
| 4457 | struct i40e_hw *hw = &pf->hw; |
| 4458 | u16 pending, i = 0; |
| 4459 | i40e_status ret; |
| 4460 | u16 opcode; |
| 4461 | u32 val; |
| 4462 | |
| 4463 | if (!test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state)) |
| 4464 | return; |
| 4465 | |
| 4466 | event.msg_size = I40E_MAX_AQ_BUF_SIZE; |
| 4467 | event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL); |
| 4468 | if (!event.msg_buf) |
| 4469 | return; |
| 4470 | |
| 4471 | do { |
| 4472 | ret = i40e_clean_arq_element(hw, &event, &pending); |
| 4473 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) { |
| 4474 | dev_info(&pf->pdev->dev, "No ARQ event found\n"); |
| 4475 | break; |
| 4476 | } else if (ret) { |
| 4477 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 4478 | break; |
| 4479 | } |
| 4480 | |
| 4481 | opcode = le16_to_cpu(event.desc.opcode); |
| 4482 | switch (opcode) { |
| 4483 | |
| 4484 | case i40e_aqc_opc_get_link_status: |
| 4485 | i40e_handle_link_event(pf, &event); |
| 4486 | break; |
| 4487 | case i40e_aqc_opc_send_msg_to_pf: |
| 4488 | ret = i40e_vc_process_vf_msg(pf, |
| 4489 | le16_to_cpu(event.desc.retval), |
| 4490 | le32_to_cpu(event.desc.cookie_high), |
| 4491 | le32_to_cpu(event.desc.cookie_low), |
| 4492 | event.msg_buf, |
| 4493 | event.msg_size); |
| 4494 | break; |
| 4495 | case i40e_aqc_opc_lldp_update_mib: |
| 4496 | dev_info(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
| 4497 | break; |
| 4498 | case i40e_aqc_opc_event_lan_overflow: |
| 4499 | dev_info(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
| 4500 | i40e_handle_lan_overflow_event(pf, &event); |
| 4501 | break; |
| 4502 | default: |
| 4503 | dev_info(&pf->pdev->dev, |
| 4504 | "ARQ Error: Unknown event %d received\n", |
| 4505 | event.desc.opcode); |
| 4506 | break; |
| 4507 | } |
| 4508 | } while (pending && (i++ < pf->adminq_work_limit)); |
| 4509 | |
| 4510 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 4511 | /* re-enable Admin queue interrupt cause */ |
| 4512 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 4513 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 4514 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 4515 | i40e_flush(hw); |
| 4516 | |
| 4517 | kfree(event.msg_buf); |
| 4518 | } |
| 4519 | |
| 4520 | /** |
| 4521 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 4522 | * @veb: pointer to the VEB instance |
| 4523 | * |
| 4524 | * This is a recursive function that first builds the attached VSIs then |
| 4525 | * recurses in to build the next layer of VEB. We track the connections |
| 4526 | * through our own index numbers because the seid's from the HW could |
| 4527 | * change across the reset. |
| 4528 | **/ |
| 4529 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 4530 | { |
| 4531 | struct i40e_vsi *ctl_vsi = NULL; |
| 4532 | struct i40e_pf *pf = veb->pf; |
| 4533 | int v, veb_idx; |
| 4534 | int ret; |
| 4535 | |
| 4536 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
| 4537 | for (v = 0; v < pf->hw.func_caps.num_vsis && !ctl_vsi; v++) { |
| 4538 | if (pf->vsi[v] && |
| 4539 | pf->vsi[v]->veb_idx == veb->idx && |
| 4540 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 4541 | ctl_vsi = pf->vsi[v]; |
| 4542 | break; |
| 4543 | } |
| 4544 | } |
| 4545 | if (!ctl_vsi) { |
| 4546 | dev_info(&pf->pdev->dev, |
| 4547 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 4548 | ret = -ENOENT; |
| 4549 | goto end_reconstitute; |
| 4550 | } |
| 4551 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 4552 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 4553 | ret = i40e_add_vsi(ctl_vsi); |
| 4554 | if (ret) { |
| 4555 | dev_info(&pf->pdev->dev, |
| 4556 | "rebuild of owner VSI failed: %d\n", ret); |
| 4557 | goto end_reconstitute; |
| 4558 | } |
| 4559 | i40e_vsi_reset_stats(ctl_vsi); |
| 4560 | |
| 4561 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 4562 | ret = i40e_add_veb(veb, ctl_vsi); |
| 4563 | if (ret) |
| 4564 | goto end_reconstitute; |
| 4565 | |
| 4566 | /* create the remaining VSIs attached to this VEB */ |
| 4567 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 4568 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 4569 | continue; |
| 4570 | |
| 4571 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 4572 | struct i40e_vsi *vsi = pf->vsi[v]; |
| 4573 | vsi->uplink_seid = veb->seid; |
| 4574 | ret = i40e_add_vsi(vsi); |
| 4575 | if (ret) { |
| 4576 | dev_info(&pf->pdev->dev, |
| 4577 | "rebuild of vsi_idx %d failed: %d\n", |
| 4578 | v, ret); |
| 4579 | goto end_reconstitute; |
| 4580 | } |
| 4581 | i40e_vsi_reset_stats(vsi); |
| 4582 | } |
| 4583 | } |
| 4584 | |
| 4585 | /* create any VEBs attached to this VEB - RECURSION */ |
| 4586 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 4587 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 4588 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 4589 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 4590 | if (ret) |
| 4591 | break; |
| 4592 | } |
| 4593 | } |
| 4594 | |
| 4595 | end_reconstitute: |
| 4596 | return ret; |
| 4597 | } |
| 4598 | |
| 4599 | /** |
| 4600 | * i40e_get_capabilities - get info about the HW |
| 4601 | * @pf: the PF struct |
| 4602 | **/ |
| 4603 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 4604 | { |
| 4605 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 4606 | u16 data_size; |
| 4607 | int buf_len; |
| 4608 | int err; |
| 4609 | |
| 4610 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 4611 | do { |
| 4612 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 4613 | if (!cap_buf) |
| 4614 | return -ENOMEM; |
| 4615 | |
| 4616 | /* this loads the data into the hw struct for us */ |
| 4617 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 4618 | &data_size, |
| 4619 | i40e_aqc_opc_list_func_capabilities, |
| 4620 | NULL); |
| 4621 | /* data loaded, buffer no longer needed */ |
| 4622 | kfree(cap_buf); |
| 4623 | |
| 4624 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 4625 | /* retry with a larger buffer */ |
| 4626 | buf_len = data_size; |
| 4627 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 4628 | dev_info(&pf->pdev->dev, |
| 4629 | "capability discovery failed: aq=%d\n", |
| 4630 | pf->hw.aq.asq_last_status); |
| 4631 | return -ENODEV; |
| 4632 | } |
| 4633 | } while (err); |
| 4634 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 4635 | if (pf->hw.revision_id == 0 && pf->hw.func_caps.npar_enable) { |
| 4636 | pf->hw.func_caps.num_msix_vectors += 1; |
| 4637 | pf->hw.func_caps.num_tx_qp = |
| 4638 | min_t(int, pf->hw.func_caps.num_tx_qp, |
| 4639 | I40E_MAX_NPAR_QPS); |
| 4640 | } |
| 4641 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4642 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 4643 | dev_info(&pf->pdev->dev, |
| 4644 | "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", |
| 4645 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 4646 | pf->hw.func_caps.num_msix_vectors, |
| 4647 | pf->hw.func_caps.num_msix_vectors_vf, |
| 4648 | pf->hw.func_caps.fd_filters_guaranteed, |
| 4649 | pf->hw.func_caps.fd_filters_best_effort, |
| 4650 | pf->hw.func_caps.num_tx_qp, |
| 4651 | pf->hw.func_caps.num_vsis); |
| 4652 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 4653 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 4654 | + pf->hw.func_caps.num_vfs) |
| 4655 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 4656 | dev_info(&pf->pdev->dev, |
| 4657 | "got num_vsis %d, setting num_vsis to %d\n", |
| 4658 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 4659 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 4660 | } |
| 4661 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4662 | return 0; |
| 4663 | } |
| 4664 | |
| 4665 | /** |
| 4666 | * i40e_fdir_setup - initialize the Flow Director resources |
| 4667 | * @pf: board private structure |
| 4668 | **/ |
| 4669 | static void i40e_fdir_setup(struct i40e_pf *pf) |
| 4670 | { |
| 4671 | struct i40e_vsi *vsi; |
| 4672 | bool new_vsi = false; |
| 4673 | int err, i; |
| 4674 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 4675 | if (!(pf->flags & (I40E_FLAG_FDIR_ENABLED | |
| 4676 | I40E_FLAG_FDIR_ATR_ENABLED))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4677 | return; |
| 4678 | |
| 4679 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
| 4680 | |
| 4681 | /* find existing or make new FDIR VSI */ |
| 4682 | vsi = NULL; |
| 4683 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) |
| 4684 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) |
| 4685 | vsi = pf->vsi[i]; |
| 4686 | if (!vsi) { |
| 4687 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, pf->mac_seid, 0); |
| 4688 | if (!vsi) { |
| 4689 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
| 4690 | pf->flags &= ~I40E_FLAG_FDIR_ENABLED; |
| 4691 | return; |
| 4692 | } |
| 4693 | new_vsi = true; |
| 4694 | } |
| 4695 | WARN_ON(vsi->base_queue != I40E_FDIR_RING); |
| 4696 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_rings); |
| 4697 | |
| 4698 | err = i40e_vsi_setup_tx_resources(vsi); |
| 4699 | if (!err) |
| 4700 | err = i40e_vsi_setup_rx_resources(vsi); |
| 4701 | if (!err) |
| 4702 | err = i40e_vsi_configure(vsi); |
| 4703 | if (!err && new_vsi) { |
| 4704 | char int_name[IFNAMSIZ + 9]; |
| 4705 | snprintf(int_name, sizeof(int_name) - 1, "%s-fdir", |
| 4706 | dev_driver_string(&pf->pdev->dev)); |
| 4707 | err = i40e_vsi_request_irq(vsi, int_name); |
| 4708 | } |
| 4709 | if (!err) |
| 4710 | err = i40e_up_complete(vsi); |
| 4711 | |
| 4712 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 4713 | } |
| 4714 | |
| 4715 | /** |
| 4716 | * i40e_fdir_teardown - release the Flow Director resources |
| 4717 | * @pf: board private structure |
| 4718 | **/ |
| 4719 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 4720 | { |
| 4721 | int i; |
| 4722 | |
| 4723 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 4724 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 4725 | i40e_vsi_release(pf->vsi[i]); |
| 4726 | break; |
| 4727 | } |
| 4728 | } |
| 4729 | } |
| 4730 | |
| 4731 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4732 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4733 | * @pf: board private structure |
| 4734 | * |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4735 | * Close up the VFs and other things in prep for pf Reset. |
| 4736 | **/ |
| 4737 | static int i40e_prep_for_reset(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4738 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4739 | struct i40e_hw *hw = &pf->hw; |
| 4740 | i40e_status ret; |
| 4741 | u32 v; |
| 4742 | |
| 4743 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 4744 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4745 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4746 | |
| 4747 | dev_info(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
| 4748 | |
| 4749 | i40e_vc_notify_reset(pf); |
| 4750 | |
| 4751 | /* quiesce the VSIs and their queues that are not already DOWN */ |
| 4752 | i40e_pf_quiesce_all_vsi(pf); |
| 4753 | |
| 4754 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 4755 | if (pf->vsi[v]) |
| 4756 | pf->vsi[v]->seid = 0; |
| 4757 | } |
| 4758 | |
| 4759 | i40e_shutdown_adminq(&pf->hw); |
| 4760 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4761 | /* call shutdown HMC */ |
| 4762 | ret = i40e_shutdown_lan_hmc(hw); |
| 4763 | if (ret) { |
| 4764 | dev_info(&pf->pdev->dev, "shutdown_lan_hmc failed: %d\n", ret); |
| 4765 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 4766 | } |
| 4767 | return ret; |
| 4768 | } |
| 4769 | |
| 4770 | /** |
| 4771 | * i40e_reset_and_rebuild - reset and rebuid using a saved config |
| 4772 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 4773 | * @reinit: if the Main VSI needs to re-initialized. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4774 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 4775 | 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] | 4776 | { |
| 4777 | struct i40e_driver_version dv; |
| 4778 | struct i40e_hw *hw = &pf->hw; |
| 4779 | i40e_status ret; |
| 4780 | u32 v; |
| 4781 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4782 | /* Now we wait for GRST to settle out. |
| 4783 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 4784 | * because the reset will make them disappear. |
| 4785 | */ |
| 4786 | ret = i40e_pf_reset(hw); |
| 4787 | if (ret) |
| 4788 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
| 4789 | pf->pfr_count++; |
| 4790 | |
| 4791 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 4792 | goto end_core_reset; |
| 4793 | dev_info(&pf->pdev->dev, "Rebuilding internal switch\n"); |
| 4794 | |
| 4795 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 4796 | ret = i40e_init_adminq(&pf->hw); |
| 4797 | if (ret) { |
| 4798 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, %d\n", ret); |
| 4799 | goto end_core_reset; |
| 4800 | } |
| 4801 | |
| 4802 | ret = i40e_get_capabilities(pf); |
| 4803 | if (ret) { |
| 4804 | dev_info(&pf->pdev->dev, "i40e_get_capabilities failed, %d\n", |
| 4805 | ret); |
| 4806 | goto end_core_reset; |
| 4807 | } |
| 4808 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4809 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 4810 | hw->func_caps.num_rx_qp, |
| 4811 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 4812 | if (ret) { |
| 4813 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 4814 | goto end_core_reset; |
| 4815 | } |
| 4816 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 4817 | if (ret) { |
| 4818 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 4819 | goto end_core_reset; |
| 4820 | } |
| 4821 | |
| 4822 | /* do basic switch setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 4823 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4824 | if (ret) |
| 4825 | goto end_core_reset; |
| 4826 | |
| 4827 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 4828 | * They are still in our local switch element arrays, so only |
| 4829 | * need to rebuild the switch model in the HW. |
| 4830 | * |
| 4831 | * If there were VEBs but the reconstitution failed, we'll try |
| 4832 | * try to recover minimal use by getting the basic PF VSI working. |
| 4833 | */ |
| 4834 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
| 4835 | dev_info(&pf->pdev->dev, "attempting to rebuild switch\n"); |
| 4836 | /* find the one VEB connected to the MAC, and find orphans */ |
| 4837 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 4838 | if (!pf->veb[v]) |
| 4839 | continue; |
| 4840 | |
| 4841 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 4842 | pf->veb[v]->uplink_seid == 0) { |
| 4843 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 4844 | |
| 4845 | if (!ret) |
| 4846 | continue; |
| 4847 | |
| 4848 | /* If Main VEB failed, we're in deep doodoo, |
| 4849 | * so give up rebuilding the switch and set up |
| 4850 | * for minimal rebuild of PF VSI. |
| 4851 | * If orphan failed, we'll report the error |
| 4852 | * but try to keep going. |
| 4853 | */ |
| 4854 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 4855 | dev_info(&pf->pdev->dev, |
| 4856 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 4857 | ret); |
| 4858 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 4859 | = pf->mac_seid; |
| 4860 | break; |
| 4861 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 4862 | dev_info(&pf->pdev->dev, |
| 4863 | "rebuild of orphan VEB failed: %d\n", |
| 4864 | ret); |
| 4865 | } |
| 4866 | } |
| 4867 | } |
| 4868 | } |
| 4869 | |
| 4870 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
| 4871 | dev_info(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
| 4872 | /* no VEB, so rebuild only the Main VSI */ |
| 4873 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 4874 | if (ret) { |
| 4875 | dev_info(&pf->pdev->dev, |
| 4876 | "rebuild of Main VSI failed: %d\n", ret); |
| 4877 | goto end_core_reset; |
| 4878 | } |
| 4879 | } |
| 4880 | |
| 4881 | /* reinit the misc interrupt */ |
| 4882 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4883 | ret = i40e_setup_misc_vector(pf); |
| 4884 | |
| 4885 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 4886 | i40e_pf_unquiesce_all_vsi(pf); |
| 4887 | |
| 4888 | /* tell the firmware that we're starting */ |
| 4889 | dv.major_version = DRV_VERSION_MAJOR; |
| 4890 | dv.minor_version = DRV_VERSION_MINOR; |
| 4891 | dv.build_version = DRV_VERSION_BUILD; |
| 4892 | dv.subbuild_version = 0; |
| 4893 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 4894 | |
| 4895 | dev_info(&pf->pdev->dev, "PF reset done\n"); |
| 4896 | |
| 4897 | end_core_reset: |
| 4898 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 4899 | } |
| 4900 | |
| 4901 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4902 | * i40e_handle_reset_warning - prep for the pf to reset, reset and rebuild |
| 4903 | * @pf: board private structure |
| 4904 | * |
| 4905 | * Close up the VFs and other things in prep for a Core Reset, |
| 4906 | * then get ready to rebuild the world. |
| 4907 | **/ |
| 4908 | static void i40e_handle_reset_warning(struct i40e_pf *pf) |
| 4909 | { |
| 4910 | i40e_status ret; |
| 4911 | |
| 4912 | ret = i40e_prep_for_reset(pf); |
| 4913 | if (!ret) |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 4914 | i40e_reset_and_rebuild(pf, false); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4915 | } |
| 4916 | |
| 4917 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4918 | * i40e_handle_mdd_event |
| 4919 | * @pf: pointer to the pf structure |
| 4920 | * |
| 4921 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 4922 | **/ |
| 4923 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 4924 | { |
| 4925 | struct i40e_hw *hw = &pf->hw; |
| 4926 | bool mdd_detected = false; |
| 4927 | struct i40e_vf *vf; |
| 4928 | u32 reg; |
| 4929 | int i; |
| 4930 | |
| 4931 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) |
| 4932 | return; |
| 4933 | |
| 4934 | /* find what triggered the MDD event */ |
| 4935 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 4936 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
| 4937 | u8 func = (reg & I40E_GL_MDET_TX_FUNCTION_MASK) |
| 4938 | >> I40E_GL_MDET_TX_FUNCTION_SHIFT; |
| 4939 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_SHIFT) |
| 4940 | >> I40E_GL_MDET_TX_EVENT_SHIFT; |
| 4941 | u8 queue = (reg & I40E_GL_MDET_TX_QUEUE_MASK) |
| 4942 | >> I40E_GL_MDET_TX_QUEUE_SHIFT; |
| 4943 | dev_info(&pf->pdev->dev, |
| 4944 | "Malicious Driver Detection TX event 0x%02x on q %d of function 0x%02x\n", |
| 4945 | event, queue, func); |
| 4946 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 4947 | mdd_detected = true; |
| 4948 | } |
| 4949 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 4950 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
| 4951 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) |
| 4952 | >> I40E_GL_MDET_RX_FUNCTION_SHIFT; |
| 4953 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_SHIFT) |
| 4954 | >> I40E_GL_MDET_RX_EVENT_SHIFT; |
| 4955 | u8 queue = (reg & I40E_GL_MDET_RX_QUEUE_MASK) |
| 4956 | >> I40E_GL_MDET_RX_QUEUE_SHIFT; |
| 4957 | dev_info(&pf->pdev->dev, |
| 4958 | "Malicious Driver Detection RX event 0x%02x on q %d of function 0x%02x\n", |
| 4959 | event, queue, func); |
| 4960 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 4961 | mdd_detected = true; |
| 4962 | } |
| 4963 | |
| 4964 | /* see if one of the VFs needs its hand slapped */ |
| 4965 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 4966 | vf = &(pf->vf[i]); |
| 4967 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 4968 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 4969 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 4970 | vf->num_mdd_events++; |
| 4971 | dev_info(&pf->pdev->dev, "MDD TX event on VF %d\n", i); |
| 4972 | } |
| 4973 | |
| 4974 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 4975 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 4976 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 4977 | vf->num_mdd_events++; |
| 4978 | dev_info(&pf->pdev->dev, "MDD RX event on VF %d\n", i); |
| 4979 | } |
| 4980 | |
| 4981 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 4982 | dev_info(&pf->pdev->dev, |
| 4983 | "Too many MDD events on VF %d, disabled\n", i); |
| 4984 | dev_info(&pf->pdev->dev, |
| 4985 | "Use PF Control I/F to re-enable the VF\n"); |
| 4986 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 4987 | } |
| 4988 | } |
| 4989 | |
| 4990 | /* re-enable mdd interrupt cause */ |
| 4991 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 4992 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 4993 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 4994 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 4995 | i40e_flush(hw); |
| 4996 | } |
| 4997 | |
| 4998 | /** |
| 4999 | * i40e_service_task - Run the driver's async subtasks |
| 5000 | * @work: pointer to work_struct containing our data |
| 5001 | **/ |
| 5002 | static void i40e_service_task(struct work_struct *work) |
| 5003 | { |
| 5004 | struct i40e_pf *pf = container_of(work, |
| 5005 | struct i40e_pf, |
| 5006 | service_task); |
| 5007 | unsigned long start_time = jiffies; |
| 5008 | |
| 5009 | i40e_reset_subtask(pf); |
| 5010 | i40e_handle_mdd_event(pf); |
| 5011 | i40e_vc_process_vflr_event(pf); |
| 5012 | i40e_watchdog_subtask(pf); |
| 5013 | i40e_fdir_reinit_subtask(pf); |
| 5014 | i40e_check_hang_subtask(pf); |
| 5015 | i40e_sync_filters_subtask(pf); |
| 5016 | i40e_clean_adminq_subtask(pf); |
| 5017 | |
| 5018 | i40e_service_event_complete(pf); |
| 5019 | |
| 5020 | /* If the tasks have taken longer than one timer cycle or there |
| 5021 | * is more work to be done, reschedule the service task now |
| 5022 | * rather than wait for the timer to tick again. |
| 5023 | */ |
| 5024 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
| 5025 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || |
| 5026 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || |
| 5027 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 5028 | i40e_service_event_schedule(pf); |
| 5029 | } |
| 5030 | |
| 5031 | /** |
| 5032 | * i40e_service_timer - timer callback |
| 5033 | * @data: pointer to PF struct |
| 5034 | **/ |
| 5035 | static void i40e_service_timer(unsigned long data) |
| 5036 | { |
| 5037 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 5038 | |
| 5039 | mod_timer(&pf->service_timer, |
| 5040 | round_jiffies(jiffies + pf->service_timer_period)); |
| 5041 | i40e_service_event_schedule(pf); |
| 5042 | } |
| 5043 | |
| 5044 | /** |
| 5045 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 5046 | * @vsi: the VSI being configured |
| 5047 | **/ |
| 5048 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 5049 | { |
| 5050 | struct i40e_pf *pf = vsi->back; |
| 5051 | |
| 5052 | switch (vsi->type) { |
| 5053 | case I40E_VSI_MAIN: |
| 5054 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 5055 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 5056 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 5057 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5058 | vsi->num_q_vectors = pf->num_lan_msix; |
| 5059 | else |
| 5060 | vsi->num_q_vectors = 1; |
| 5061 | |
| 5062 | break; |
| 5063 | |
| 5064 | case I40E_VSI_FDIR: |
| 5065 | vsi->alloc_queue_pairs = 1; |
| 5066 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 5067 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 5068 | vsi->num_q_vectors = 1; |
| 5069 | break; |
| 5070 | |
| 5071 | case I40E_VSI_VMDQ2: |
| 5072 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 5073 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 5074 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 5075 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 5076 | break; |
| 5077 | |
| 5078 | case I40E_VSI_SRIOV: |
| 5079 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 5080 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 5081 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 5082 | break; |
| 5083 | |
| 5084 | default: |
| 5085 | WARN_ON(1); |
| 5086 | return -ENODATA; |
| 5087 | } |
| 5088 | |
| 5089 | return 0; |
| 5090 | } |
| 5091 | |
| 5092 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5093 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 5094 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 5095 | * @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] | 5096 | * |
| 5097 | * On error: returns error code (negative) |
| 5098 | * On success: returns 0 |
| 5099 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 5100 | 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] | 5101 | { |
| 5102 | int size; |
| 5103 | int ret = 0; |
| 5104 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 5105 | /* allocate memory for both Tx and Rx ring pointers */ |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5106 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
| 5107 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 5108 | if (!vsi->tx_rings) |
| 5109 | return -ENOMEM; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5110 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
| 5111 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 5112 | if (alloc_qvectors) { |
| 5113 | /* allocate memory for q_vector pointers */ |
| 5114 | size = sizeof(struct i40e_q_vectors *) * vsi->num_q_vectors; |
| 5115 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 5116 | if (!vsi->q_vectors) { |
| 5117 | ret = -ENOMEM; |
| 5118 | goto err_vectors; |
| 5119 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5120 | } |
| 5121 | return ret; |
| 5122 | |
| 5123 | err_vectors: |
| 5124 | kfree(vsi->tx_rings); |
| 5125 | return ret; |
| 5126 | } |
| 5127 | |
| 5128 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5129 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 5130 | * @pf: board private structure |
| 5131 | * @type: type of VSI |
| 5132 | * |
| 5133 | * On error: returns error code (negative) |
| 5134 | * On success: returns vsi index in PF (positive) |
| 5135 | **/ |
| 5136 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 5137 | { |
| 5138 | int ret = -ENODEV; |
| 5139 | struct i40e_vsi *vsi; |
| 5140 | int vsi_idx; |
| 5141 | int i; |
| 5142 | |
| 5143 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 5144 | mutex_lock(&pf->switch_mutex); |
| 5145 | |
| 5146 | /* VSI list may be fragmented if VSI creation/destruction has |
| 5147 | * been happening. We can afford to do a quick scan to look |
| 5148 | * for any free VSIs in the list. |
| 5149 | * |
| 5150 | * find next empty vsi slot, looping back around if necessary |
| 5151 | */ |
| 5152 | i = pf->next_vsi; |
| 5153 | while (i < pf->hw.func_caps.num_vsis && pf->vsi[i]) |
| 5154 | i++; |
| 5155 | if (i >= pf->hw.func_caps.num_vsis) { |
| 5156 | i = 0; |
| 5157 | while (i < pf->next_vsi && pf->vsi[i]) |
| 5158 | i++; |
| 5159 | } |
| 5160 | |
| 5161 | if (i < pf->hw.func_caps.num_vsis && !pf->vsi[i]) { |
| 5162 | vsi_idx = i; /* Found one! */ |
| 5163 | } else { |
| 5164 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5165 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5166 | } |
| 5167 | pf->next_vsi = ++i; |
| 5168 | |
| 5169 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 5170 | if (!vsi) { |
| 5171 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5172 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5173 | } |
| 5174 | vsi->type = type; |
| 5175 | vsi->back = pf; |
| 5176 | set_bit(__I40E_DOWN, &vsi->state); |
| 5177 | vsi->flags = 0; |
| 5178 | vsi->idx = vsi_idx; |
| 5179 | vsi->rx_itr_setting = pf->rx_itr_default; |
| 5180 | vsi->tx_itr_setting = pf->tx_itr_default; |
| 5181 | vsi->netdev_registered = false; |
| 5182 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
| 5183 | INIT_LIST_HEAD(&vsi->mac_filter_list); |
| 5184 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5185 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 5186 | if (ret) |
| 5187 | goto err_rings; |
| 5188 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 5189 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5190 | if (ret) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5191 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5192 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5193 | /* Setup default MSIX irq handler for VSI */ |
| 5194 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 5195 | |
| 5196 | pf->vsi[vsi_idx] = vsi; |
| 5197 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5198 | goto unlock_pf; |
| 5199 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5200 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5201 | pf->next_vsi = i - 1; |
| 5202 | kfree(vsi); |
| 5203 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5204 | mutex_unlock(&pf->switch_mutex); |
| 5205 | return ret; |
| 5206 | } |
| 5207 | |
| 5208 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5209 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 5210 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 5211 | * @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] | 5212 | * |
| 5213 | * On error: returns error code (negative) |
| 5214 | * On success: returns 0 |
| 5215 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 5216 | 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] | 5217 | { |
| 5218 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 5219 | if (free_qvectors) { |
| 5220 | kfree(vsi->q_vectors); |
| 5221 | vsi->q_vectors = NULL; |
| 5222 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5223 | kfree(vsi->tx_rings); |
| 5224 | vsi->tx_rings = NULL; |
| 5225 | vsi->rx_rings = NULL; |
| 5226 | } |
| 5227 | |
| 5228 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5229 | * i40e_vsi_clear - Deallocate the VSI provided |
| 5230 | * @vsi: the VSI being un-configured |
| 5231 | **/ |
| 5232 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 5233 | { |
| 5234 | struct i40e_pf *pf; |
| 5235 | |
| 5236 | if (!vsi) |
| 5237 | return 0; |
| 5238 | |
| 5239 | if (!vsi->back) |
| 5240 | goto free_vsi; |
| 5241 | pf = vsi->back; |
| 5242 | |
| 5243 | mutex_lock(&pf->switch_mutex); |
| 5244 | if (!pf->vsi[vsi->idx]) { |
| 5245 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 5246 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 5247 | goto unlock_vsi; |
| 5248 | } |
| 5249 | |
| 5250 | if (pf->vsi[vsi->idx] != vsi) { |
| 5251 | dev_err(&pf->pdev->dev, |
| 5252 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 5253 | pf->vsi[vsi->idx]->idx, |
| 5254 | pf->vsi[vsi->idx], |
| 5255 | pf->vsi[vsi->idx]->type, |
| 5256 | vsi->idx, vsi, vsi->type); |
| 5257 | goto unlock_vsi; |
| 5258 | } |
| 5259 | |
| 5260 | /* updates the pf for this cleared vsi */ |
| 5261 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 5262 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 5263 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 5264 | i40e_vsi_free_arrays(vsi, true); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5265 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5266 | pf->vsi[vsi->idx] = NULL; |
| 5267 | if (vsi->idx < pf->next_vsi) |
| 5268 | pf->next_vsi = vsi->idx; |
| 5269 | |
| 5270 | unlock_vsi: |
| 5271 | mutex_unlock(&pf->switch_mutex); |
| 5272 | free_vsi: |
| 5273 | kfree(vsi); |
| 5274 | |
| 5275 | return 0; |
| 5276 | } |
| 5277 | |
| 5278 | /** |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5279 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 5280 | * @vsi: the VSI being cleaned |
| 5281 | **/ |
| 5282 | static s32 i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
| 5283 | { |
| 5284 | int i; |
| 5285 | |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 5286 | if (vsi->tx_rings[0]) |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 5287 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 5288 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 5289 | vsi->tx_rings[i] = NULL; |
| 5290 | vsi->rx_rings[i] = NULL; |
| 5291 | } |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5292 | |
| 5293 | return 0; |
| 5294 | } |
| 5295 | |
| 5296 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5297 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 5298 | * @vsi: the VSI being configured |
| 5299 | **/ |
| 5300 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 5301 | { |
| 5302 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5303 | int i; |
| 5304 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5305 | /* Set basic values in the rings to be used later during open() */ |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 5306 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5307 | struct i40e_ring *tx_ring; |
| 5308 | struct i40e_ring *rx_ring; |
| 5309 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 5310 | /* allocate space for both Tx and Rx in one shot */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5311 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
| 5312 | if (!tx_ring) |
| 5313 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5314 | |
| 5315 | tx_ring->queue_index = i; |
| 5316 | tx_ring->reg_idx = vsi->base_queue + i; |
| 5317 | tx_ring->ring_active = false; |
| 5318 | tx_ring->vsi = vsi; |
| 5319 | tx_ring->netdev = vsi->netdev; |
| 5320 | tx_ring->dev = &pf->pdev->dev; |
| 5321 | tx_ring->count = vsi->num_desc; |
| 5322 | tx_ring->size = 0; |
| 5323 | tx_ring->dcb_tc = 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5324 | vsi->tx_rings[i] = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5325 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5326 | rx_ring = &tx_ring[1]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5327 | rx_ring->queue_index = i; |
| 5328 | rx_ring->reg_idx = vsi->base_queue + i; |
| 5329 | rx_ring->ring_active = false; |
| 5330 | rx_ring->vsi = vsi; |
| 5331 | rx_ring->netdev = vsi->netdev; |
| 5332 | rx_ring->dev = &pf->pdev->dev; |
| 5333 | rx_ring->count = vsi->num_desc; |
| 5334 | rx_ring->size = 0; |
| 5335 | rx_ring->dcb_tc = 0; |
| 5336 | if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) |
| 5337 | set_ring_16byte_desc_enabled(rx_ring); |
| 5338 | else |
| 5339 | clear_ring_16byte_desc_enabled(rx_ring); |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5340 | vsi->rx_rings[i] = rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5341 | } |
| 5342 | |
| 5343 | return 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5344 | |
| 5345 | err_out: |
| 5346 | i40e_vsi_clear_rings(vsi); |
| 5347 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | /** |
| 5351 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 5352 | * @pf: board private structure |
| 5353 | * @vectors: the number of MSI-X vectors to request |
| 5354 | * |
| 5355 | * Returns the number of vectors reserved, or error |
| 5356 | **/ |
| 5357 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 5358 | { |
| 5359 | int err = 0; |
| 5360 | |
| 5361 | pf->num_msix_entries = 0; |
| 5362 | while (vectors >= I40E_MIN_MSIX) { |
| 5363 | err = pci_enable_msix(pf->pdev, pf->msix_entries, vectors); |
| 5364 | if (err == 0) { |
| 5365 | /* good to go */ |
| 5366 | pf->num_msix_entries = vectors; |
| 5367 | break; |
| 5368 | } else if (err < 0) { |
| 5369 | /* total failure */ |
| 5370 | dev_info(&pf->pdev->dev, |
| 5371 | "MSI-X vector reservation failed: %d\n", err); |
| 5372 | vectors = 0; |
| 5373 | break; |
| 5374 | } else { |
| 5375 | /* err > 0 is the hint for retry */ |
| 5376 | dev_info(&pf->pdev->dev, |
| 5377 | "MSI-X vectors wanted %d, retrying with %d\n", |
| 5378 | vectors, err); |
| 5379 | vectors = err; |
| 5380 | } |
| 5381 | } |
| 5382 | |
| 5383 | if (vectors > 0 && vectors < I40E_MIN_MSIX) { |
| 5384 | dev_info(&pf->pdev->dev, |
| 5385 | "Couldn't get enough vectors, only %d available\n", |
| 5386 | vectors); |
| 5387 | vectors = 0; |
| 5388 | } |
| 5389 | |
| 5390 | return vectors; |
| 5391 | } |
| 5392 | |
| 5393 | /** |
| 5394 | * i40e_init_msix - Setup the MSIX capability |
| 5395 | * @pf: board private structure |
| 5396 | * |
| 5397 | * Work with the OS to set up the MSIX vectors needed. |
| 5398 | * |
| 5399 | * Returns 0 on success, negative on failure |
| 5400 | **/ |
| 5401 | static int i40e_init_msix(struct i40e_pf *pf) |
| 5402 | { |
| 5403 | i40e_status err = 0; |
| 5404 | struct i40e_hw *hw = &pf->hw; |
| 5405 | int v_budget, i; |
| 5406 | int vec; |
| 5407 | |
| 5408 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 5409 | return -ENODEV; |
| 5410 | |
| 5411 | /* The number of vectors we'll request will be comprised of: |
| 5412 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 5413 | * - The number of LAN queue pairs |
Jesse Brandeburg | bf051a3 | 2013-11-26 10:49:17 +0000 | [diff] [blame] | 5414 | * already adjusted for the number of cpus in the system |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5415 | * assumes symmetric Tx/Rx pairing |
| 5416 | * - The number of VMDq pairs |
| 5417 | * Once we count this up, try the request. |
| 5418 | * |
| 5419 | * If we can't get what we want, we'll simplify to nearly nothing |
| 5420 | * and try again. If that still fails, we punt. |
| 5421 | */ |
| 5422 | pf->num_lan_msix = pf->num_lan_qps; |
| 5423 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
| 5424 | v_budget = 1 + pf->num_lan_msix; |
| 5425 | v_budget += (pf->num_vmdq_vsis * pf->num_vmdq_msix); |
| 5426 | if (pf->flags & I40E_FLAG_FDIR_ENABLED) |
| 5427 | v_budget++; |
| 5428 | |
| 5429 | /* Scale down if necessary, and the rings will share vectors */ |
| 5430 | v_budget = min_t(int, v_budget, hw->func_caps.num_msix_vectors); |
| 5431 | |
| 5432 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 5433 | GFP_KERNEL); |
| 5434 | if (!pf->msix_entries) |
| 5435 | return -ENOMEM; |
| 5436 | |
| 5437 | for (i = 0; i < v_budget; i++) |
| 5438 | pf->msix_entries[i].entry = i; |
| 5439 | vec = i40e_reserve_msix_vectors(pf, v_budget); |
| 5440 | if (vec < I40E_MIN_MSIX) { |
| 5441 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 5442 | kfree(pf->msix_entries); |
| 5443 | pf->msix_entries = NULL; |
| 5444 | return -ENODEV; |
| 5445 | |
| 5446 | } else if (vec == I40E_MIN_MSIX) { |
| 5447 | /* Adjust for minimal MSIX use */ |
| 5448 | dev_info(&pf->pdev->dev, "Features disabled, not enough MSIX vectors\n"); |
| 5449 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 5450 | pf->num_vmdq_vsis = 0; |
| 5451 | pf->num_vmdq_qps = 0; |
| 5452 | pf->num_vmdq_msix = 0; |
| 5453 | pf->num_lan_qps = 1; |
| 5454 | pf->num_lan_msix = 1; |
| 5455 | |
| 5456 | } else if (vec != v_budget) { |
| 5457 | /* Scale vector usage down */ |
| 5458 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
| 5459 | vec--; /* reserve the misc vector */ |
| 5460 | |
| 5461 | /* partition out the remaining vectors */ |
| 5462 | switch (vec) { |
| 5463 | case 2: |
| 5464 | pf->num_vmdq_vsis = 1; |
| 5465 | pf->num_lan_msix = 1; |
| 5466 | break; |
| 5467 | case 3: |
| 5468 | pf->num_vmdq_vsis = 1; |
| 5469 | pf->num_lan_msix = 2; |
| 5470 | break; |
| 5471 | default: |
| 5472 | pf->num_lan_msix = min_t(int, (vec / 2), |
| 5473 | pf->num_lan_qps); |
| 5474 | pf->num_vmdq_vsis = min_t(int, (vec - pf->num_lan_msix), |
| 5475 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 5476 | break; |
| 5477 | } |
| 5478 | } |
| 5479 | |
| 5480 | return err; |
| 5481 | } |
| 5482 | |
| 5483 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5484 | * i40e_alloc_q_vector - Allocate memory for a single interrupt vector |
| 5485 | * @vsi: the VSI being configured |
| 5486 | * @v_idx: index of the vector in the vsi struct |
| 5487 | * |
| 5488 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 5489 | **/ |
| 5490 | static int i40e_alloc_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 5491 | { |
| 5492 | struct i40e_q_vector *q_vector; |
| 5493 | |
| 5494 | /* allocate q_vector */ |
| 5495 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 5496 | if (!q_vector) |
| 5497 | return -ENOMEM; |
| 5498 | |
| 5499 | q_vector->vsi = vsi; |
| 5500 | q_vector->v_idx = v_idx; |
| 5501 | cpumask_set_cpu(v_idx, &q_vector->affinity_mask); |
| 5502 | if (vsi->netdev) |
| 5503 | netif_napi_add(vsi->netdev, &q_vector->napi, |
| 5504 | i40e_napi_poll, vsi->work_limit); |
| 5505 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 5506 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 5507 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 5508 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5509 | /* tie q_vector and vsi together */ |
| 5510 | vsi->q_vectors[v_idx] = q_vector; |
| 5511 | |
| 5512 | return 0; |
| 5513 | } |
| 5514 | |
| 5515 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5516 | * i40e_alloc_q_vectors - Allocate memory for interrupt vectors |
| 5517 | * @vsi: the VSI being configured |
| 5518 | * |
| 5519 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 5520 | * return -ENOMEM. |
| 5521 | **/ |
| 5522 | static int i40e_alloc_q_vectors(struct i40e_vsi *vsi) |
| 5523 | { |
| 5524 | struct i40e_pf *pf = vsi->back; |
| 5525 | int v_idx, num_q_vectors; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5526 | int err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5527 | |
| 5528 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 5529 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5530 | num_q_vectors = vsi->num_q_vectors; |
| 5531 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 5532 | num_q_vectors = 1; |
| 5533 | else |
| 5534 | return -EINVAL; |
| 5535 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5536 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5537 | err = i40e_alloc_q_vector(vsi, v_idx); |
| 5538 | if (err) |
| 5539 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5540 | } |
| 5541 | |
| 5542 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5543 | |
| 5544 | err_out: |
| 5545 | while (v_idx--) |
| 5546 | i40e_free_q_vector(vsi, v_idx); |
| 5547 | |
| 5548 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5549 | } |
| 5550 | |
| 5551 | /** |
| 5552 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 5553 | * @pf: board private structure to initialize |
| 5554 | **/ |
| 5555 | static void i40e_init_interrupt_scheme(struct i40e_pf *pf) |
| 5556 | { |
| 5557 | int err = 0; |
| 5558 | |
| 5559 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 5560 | err = i40e_init_msix(pf); |
| 5561 | if (err) { |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 5562 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
| 5563 | I40E_FLAG_RSS_ENABLED | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5564 | I40E_FLAG_MQ_ENABLED | |
| 5565 | I40E_FLAG_DCB_ENABLED | |
| 5566 | I40E_FLAG_SRIOV_ENABLED | |
| 5567 | I40E_FLAG_FDIR_ENABLED | |
| 5568 | I40E_FLAG_FDIR_ATR_ENABLED | |
| 5569 | I40E_FLAG_VMDQ_ENABLED); |
| 5570 | |
| 5571 | /* rework the queue expectations without MSIX */ |
| 5572 | i40e_determine_queue_usage(pf); |
| 5573 | } |
| 5574 | } |
| 5575 | |
| 5576 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 5577 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 5578 | dev_info(&pf->pdev->dev, "MSIX not available, trying MSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5579 | err = pci_enable_msi(pf->pdev); |
| 5580 | if (err) { |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 5581 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5582 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 5583 | } |
| 5584 | } |
| 5585 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 5586 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
| 5587 | dev_info(&pf->pdev->dev, "MSIX and MSI not available, falling back to Legacy IRQ\n"); |
| 5588 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5589 | /* track first vector for misc interrupts */ |
| 5590 | err = i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT-1); |
| 5591 | } |
| 5592 | |
| 5593 | /** |
| 5594 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 5595 | * @pf: board private structure |
| 5596 | * |
| 5597 | * This sets up the handler for MSIX 0, which is used to manage the |
| 5598 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 5599 | * when in MSI or Legacy interrupt mode. |
| 5600 | **/ |
| 5601 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 5602 | { |
| 5603 | struct i40e_hw *hw = &pf->hw; |
| 5604 | int err = 0; |
| 5605 | |
| 5606 | /* Only request the irq if this is the first time through, and |
| 5607 | * not when we're rebuilding after a Reset |
| 5608 | */ |
| 5609 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 5610 | err = request_irq(pf->msix_entries[0].vector, |
| 5611 | i40e_intr, 0, pf->misc_int_name, pf); |
| 5612 | if (err) { |
| 5613 | dev_info(&pf->pdev->dev, |
| 5614 | "request_irq for msix_misc failed: %d\n", err); |
| 5615 | return -EFAULT; |
| 5616 | } |
| 5617 | } |
| 5618 | |
| 5619 | i40e_enable_misc_int_causes(hw); |
| 5620 | |
| 5621 | /* associate no queues to the misc vector */ |
| 5622 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 5623 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 5624 | |
| 5625 | i40e_flush(hw); |
| 5626 | |
| 5627 | i40e_irq_dynamic_enable_icr0(pf); |
| 5628 | |
| 5629 | return err; |
| 5630 | } |
| 5631 | |
| 5632 | /** |
| 5633 | * i40e_config_rss - Prepare for RSS if used |
| 5634 | * @pf: board private structure |
| 5635 | **/ |
| 5636 | static int i40e_config_rss(struct i40e_pf *pf) |
| 5637 | { |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 5638 | const u64 default_hena = |
| 5639 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) | |
| 5640 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) | |
| 5641 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) | |
| 5642 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP) | |
| 5643 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN) | |
| 5644 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP) | |
| 5645 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | |
| 5646 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4) | |
| 5647 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) | |
| 5648 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) | |
| 5649 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) | |
| 5650 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN) | |
| 5651 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP) | |
| 5652 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP) | |
| 5653 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | |
| 5654 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6) | |
| 5655 | ((u64)1 << I40E_FILTER_PCTYPE_L2_PAYLOAD); |
| 5656 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5657 | /* Set of random keys generated using kernel random number generator */ |
| 5658 | static const u32 seed[I40E_PFQF_HKEY_MAX_INDEX + 1] = {0x41b01687, |
| 5659 | 0x183cfd8c, 0xce880440, 0x580cbc3c, 0x35897377, |
| 5660 | 0x328b25e1, 0x4fa98922, 0xb7d90c14, 0xd5bad70d, |
| 5661 | 0xcd15a2c1, 0xe8580225, 0x4a1e9d11, 0xfe5731be}; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 5662 | struct i40e_hw *hw = &pf->hw; |
| 5663 | u32 lut = 0; |
| 5664 | int i, j; |
| 5665 | u64 hena; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5666 | |
| 5667 | /* Fill out hash function seed */ |
| 5668 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
| 5669 | wr32(hw, I40E_PFQF_HKEY(i), seed[i]); |
| 5670 | |
| 5671 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
| 5672 | hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) | |
| 5673 | ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32); |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 5674 | hena |= default_hena; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5675 | wr32(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 5676 | wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
| 5677 | |
| 5678 | /* Populate the LUT with max no. of queues in round robin fashion */ |
| 5679 | for (i = 0, j = 0; i < pf->hw.func_caps.rss_table_size; i++, j++) { |
| 5680 | |
| 5681 | /* The assumption is that lan qp count will be the highest |
| 5682 | * qp count for any PF VSI that needs RSS. |
| 5683 | * If multiple VSIs need RSS support, all the qp counts |
| 5684 | * for those VSIs should be a power of 2 for RSS to work. |
| 5685 | * If LAN VSI is the only consumer for RSS then this requirement |
| 5686 | * is not necessary. |
| 5687 | */ |
| 5688 | if (j == pf->rss_size) |
| 5689 | j = 0; |
| 5690 | /* lut = 4-byte sliding window of 4 lut entries */ |
| 5691 | lut = (lut << 8) | (j & |
| 5692 | ((0x1 << pf->hw.func_caps.rss_table_entry_width) - 1)); |
| 5693 | /* On i = 3, we have 4 entries in lut; write to the register */ |
| 5694 | if ((i & 3) == 3) |
| 5695 | wr32(hw, I40E_PFQF_HLUT(i >> 2), lut); |
| 5696 | } |
| 5697 | i40e_flush(hw); |
| 5698 | |
| 5699 | return 0; |
| 5700 | } |
| 5701 | |
| 5702 | /** |
| 5703 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 5704 | * @pf: board private structure to initialize |
| 5705 | * |
| 5706 | * i40e_sw_init initializes the Adapter private data structure. |
| 5707 | * Fields are initialized based on PCI device information and |
| 5708 | * OS network device settings (MTU size). |
| 5709 | **/ |
| 5710 | static int i40e_sw_init(struct i40e_pf *pf) |
| 5711 | { |
| 5712 | int err = 0; |
| 5713 | int size; |
| 5714 | |
| 5715 | pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE, |
| 5716 | (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)); |
Shannon Nelson | 2759997 | 2013-11-16 10:00:43 +0000 | [diff] [blame] | 5717 | pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5718 | if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) { |
| 5719 | if (I40E_DEBUG_USER & debug) |
| 5720 | pf->hw.debug_mask = debug; |
| 5721 | pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER), |
| 5722 | I40E_DEFAULT_MSG_ENABLE); |
| 5723 | } |
| 5724 | |
| 5725 | /* Set default capability flags */ |
| 5726 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 5727 | I40E_FLAG_MSI_ENABLED | |
| 5728 | I40E_FLAG_MSIX_ENABLED | |
| 5729 | I40E_FLAG_RX_PS_ENABLED | |
| 5730 | I40E_FLAG_MQ_ENABLED | |
| 5731 | I40E_FLAG_RX_1BUF_ENABLED; |
| 5732 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 5733 | /* Depending on PF configurations, it is possible that the RSS |
| 5734 | * maximum might end up larger than the available queues |
| 5735 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5736 | pf->rss_size_max = 0x1 << pf->hw.func_caps.rss_table_entry_width; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 5737 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 5738 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5739 | if (pf->hw.func_caps.rss) { |
| 5740 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Jesse Brandeburg | bf051a3 | 2013-11-26 10:49:17 +0000 | [diff] [blame] | 5741 | 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] | 5742 | } else { |
| 5743 | pf->rss_size = 1; |
| 5744 | } |
| 5745 | |
| 5746 | if (pf->hw.func_caps.dcb) |
| 5747 | pf->num_tc_qps = I40E_DEFAULT_QUEUES_PER_TC; |
| 5748 | else |
| 5749 | pf->num_tc_qps = 0; |
| 5750 | |
| 5751 | if (pf->hw.func_caps.fd) { |
| 5752 | /* FW/NVM is not yet fixed in this regard */ |
| 5753 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 5754 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 5755 | pf->flags |= I40E_FLAG_FDIR_ATR_ENABLED; |
| 5756 | dev_info(&pf->pdev->dev, |
| 5757 | "Flow Director ATR mode Enabled\n"); |
| 5758 | pf->flags |= I40E_FLAG_FDIR_ENABLED; |
| 5759 | dev_info(&pf->pdev->dev, |
| 5760 | "Flow Director Side Band mode Enabled\n"); |
| 5761 | pf->fdir_pf_filter_count = |
| 5762 | pf->hw.func_caps.fd_filters_guaranteed; |
| 5763 | } |
| 5764 | } else { |
| 5765 | pf->fdir_pf_filter_count = 0; |
| 5766 | } |
| 5767 | |
| 5768 | if (pf->hw.func_caps.vmdq) { |
| 5769 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
| 5770 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
| 5771 | pf->num_vmdq_qps = I40E_DEFAULT_QUEUES_PER_VMDQ; |
| 5772 | } |
| 5773 | |
| 5774 | /* MFP mode enabled */ |
| 5775 | if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.mfp_mode_1) { |
| 5776 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 5777 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
| 5778 | } |
| 5779 | |
| 5780 | #ifdef CONFIG_PCI_IOV |
| 5781 | if (pf->hw.func_caps.num_vfs) { |
| 5782 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 5783 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 5784 | pf->num_req_vfs = min_t(int, |
| 5785 | pf->hw.func_caps.num_vfs, |
| 5786 | I40E_MAX_VF_COUNT); |
Anjali Singhai Jain | 4a38d09 | 2013-11-20 10:03:00 +0000 | [diff] [blame] | 5787 | dev_info(&pf->pdev->dev, |
| 5788 | "Number of VFs being requested for PF[%d] = %d\n", |
| 5789 | pf->hw.pf_id, pf->num_req_vfs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5790 | } |
| 5791 | #endif /* CONFIG_PCI_IOV */ |
| 5792 | pf->eeprom_version = 0xDEAD; |
| 5793 | pf->lan_veb = I40E_NO_VEB; |
| 5794 | pf->lan_vsi = I40E_NO_VSI; |
| 5795 | |
| 5796 | /* set up queue assignment tracking */ |
| 5797 | size = sizeof(struct i40e_lump_tracking) |
| 5798 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 5799 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 5800 | if (!pf->qp_pile) { |
| 5801 | err = -ENOMEM; |
| 5802 | goto sw_init_done; |
| 5803 | } |
| 5804 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 5805 | pf->qp_pile->search_hint = 0; |
| 5806 | |
| 5807 | /* set up vector assignment tracking */ |
| 5808 | size = sizeof(struct i40e_lump_tracking) |
| 5809 | + (sizeof(u16) * pf->hw.func_caps.num_msix_vectors); |
| 5810 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
| 5811 | if (!pf->irq_pile) { |
| 5812 | kfree(pf->qp_pile); |
| 5813 | err = -ENOMEM; |
| 5814 | goto sw_init_done; |
| 5815 | } |
| 5816 | pf->irq_pile->num_entries = pf->hw.func_caps.num_msix_vectors; |
| 5817 | pf->irq_pile->search_hint = 0; |
| 5818 | |
| 5819 | mutex_init(&pf->switch_mutex); |
| 5820 | |
| 5821 | sw_init_done: |
| 5822 | return err; |
| 5823 | } |
| 5824 | |
| 5825 | /** |
| 5826 | * i40e_set_features - set the netdev feature flags |
| 5827 | * @netdev: ptr to the netdev being adjusted |
| 5828 | * @features: the feature set that the stack is suggesting |
| 5829 | **/ |
| 5830 | static int i40e_set_features(struct net_device *netdev, |
| 5831 | netdev_features_t features) |
| 5832 | { |
| 5833 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5834 | struct i40e_vsi *vsi = np->vsi; |
| 5835 | |
| 5836 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 5837 | i40e_vlan_stripping_enable(vsi); |
| 5838 | else |
| 5839 | i40e_vlan_stripping_disable(vsi); |
| 5840 | |
| 5841 | return 0; |
| 5842 | } |
| 5843 | |
| 5844 | static const struct net_device_ops i40e_netdev_ops = { |
| 5845 | .ndo_open = i40e_open, |
| 5846 | .ndo_stop = i40e_close, |
| 5847 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 5848 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 5849 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 5850 | .ndo_validate_addr = eth_validate_addr, |
| 5851 | .ndo_set_mac_address = i40e_set_mac, |
| 5852 | .ndo_change_mtu = i40e_change_mtu, |
| 5853 | .ndo_tx_timeout = i40e_tx_timeout, |
| 5854 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 5855 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 5856 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5857 | .ndo_poll_controller = i40e_netpoll, |
| 5858 | #endif |
| 5859 | .ndo_setup_tc = i40e_setup_tc, |
| 5860 | .ndo_set_features = i40e_set_features, |
| 5861 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 5862 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
| 5863 | .ndo_set_vf_tx_rate = i40e_ndo_set_vf_bw, |
| 5864 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
| 5865 | }; |
| 5866 | |
| 5867 | /** |
| 5868 | * i40e_config_netdev - Setup the netdev flags |
| 5869 | * @vsi: the VSI being configured |
| 5870 | * |
| 5871 | * Returns 0 on success, negative value on failure |
| 5872 | **/ |
| 5873 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 5874 | { |
| 5875 | struct i40e_pf *pf = vsi->back; |
| 5876 | struct i40e_hw *hw = &pf->hw; |
| 5877 | struct i40e_netdev_priv *np; |
| 5878 | struct net_device *netdev; |
| 5879 | u8 mac_addr[ETH_ALEN]; |
| 5880 | int etherdev_size; |
| 5881 | |
| 5882 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 5883 | netdev = alloc_etherdev_mq(etherdev_size, vsi->num_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5884 | if (!netdev) |
| 5885 | return -ENOMEM; |
| 5886 | |
| 5887 | vsi->netdev = netdev; |
| 5888 | np = netdev_priv(netdev); |
| 5889 | np->vsi = vsi; |
| 5890 | |
| 5891 | netdev->hw_enc_features = NETIF_F_IP_CSUM | |
| 5892 | NETIF_F_GSO_UDP_TUNNEL | |
| 5893 | NETIF_F_TSO | |
| 5894 | NETIF_F_SG; |
| 5895 | |
| 5896 | netdev->features = NETIF_F_SG | |
| 5897 | NETIF_F_IP_CSUM | |
| 5898 | NETIF_F_SCTP_CSUM | |
| 5899 | NETIF_F_HIGHDMA | |
| 5900 | NETIF_F_GSO_UDP_TUNNEL | |
| 5901 | NETIF_F_HW_VLAN_CTAG_TX | |
| 5902 | NETIF_F_HW_VLAN_CTAG_RX | |
| 5903 | NETIF_F_HW_VLAN_CTAG_FILTER | |
| 5904 | NETIF_F_IPV6_CSUM | |
| 5905 | NETIF_F_TSO | |
| 5906 | NETIF_F_TSO6 | |
| 5907 | NETIF_F_RXCSUM | |
| 5908 | NETIF_F_RXHASH | |
| 5909 | 0; |
| 5910 | |
| 5911 | /* copy netdev features into list of user selectable features */ |
| 5912 | netdev->hw_features |= netdev->features; |
| 5913 | |
| 5914 | if (vsi->type == I40E_VSI_MAIN) { |
| 5915 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
| 5916 | memcpy(mac_addr, hw->mac.perm_addr, ETH_ALEN); |
| 5917 | } else { |
| 5918 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ |
| 5919 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", |
| 5920 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 5921 | random_ether_addr(mac_addr); |
| 5922 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false); |
| 5923 | } |
| 5924 | |
| 5925 | memcpy(netdev->dev_addr, mac_addr, ETH_ALEN); |
| 5926 | memcpy(netdev->perm_addr, mac_addr, ETH_ALEN); |
| 5927 | /* vlan gets same features (except vlan offload) |
| 5928 | * after any tweaks for specific VSI types |
| 5929 | */ |
| 5930 | netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX | |
| 5931 | NETIF_F_HW_VLAN_CTAG_RX | |
| 5932 | NETIF_F_HW_VLAN_CTAG_FILTER); |
| 5933 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 5934 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 5935 | /* Setup netdev TC information */ |
| 5936 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 5937 | |
| 5938 | netdev->netdev_ops = &i40e_netdev_ops; |
| 5939 | netdev->watchdog_timeo = 5 * HZ; |
| 5940 | i40e_set_ethtool_ops(netdev); |
| 5941 | |
| 5942 | return 0; |
| 5943 | } |
| 5944 | |
| 5945 | /** |
| 5946 | * i40e_vsi_delete - Delete a VSI from the switch |
| 5947 | * @vsi: the VSI being removed |
| 5948 | * |
| 5949 | * Returns 0 on success, negative value on failure |
| 5950 | **/ |
| 5951 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 5952 | { |
| 5953 | /* remove default VSI is not allowed */ |
| 5954 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 5955 | return; |
| 5956 | |
| 5957 | /* there is no HW VSI for FDIR */ |
| 5958 | if (vsi->type == I40E_VSI_FDIR) |
| 5959 | return; |
| 5960 | |
| 5961 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
| 5962 | return; |
| 5963 | } |
| 5964 | |
| 5965 | /** |
| 5966 | * i40e_add_vsi - Add a VSI to the switch |
| 5967 | * @vsi: the VSI being configured |
| 5968 | * |
| 5969 | * This initializes a VSI context depending on the VSI type to be added and |
| 5970 | * passes it down to the add_vsi aq command. |
| 5971 | **/ |
| 5972 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 5973 | { |
| 5974 | int ret = -ENODEV; |
| 5975 | struct i40e_mac_filter *f, *ftmp; |
| 5976 | struct i40e_pf *pf = vsi->back; |
| 5977 | struct i40e_hw *hw = &pf->hw; |
| 5978 | struct i40e_vsi_context ctxt; |
| 5979 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 5980 | int f_count = 0; |
| 5981 | |
| 5982 | memset(&ctxt, 0, sizeof(ctxt)); |
| 5983 | switch (vsi->type) { |
| 5984 | case I40E_VSI_MAIN: |
| 5985 | /* The PF's main VSI is already setup as part of the |
| 5986 | * device initialization, so we'll not bother with |
| 5987 | * the add_vsi call, but we will retrieve the current |
| 5988 | * VSI context. |
| 5989 | */ |
| 5990 | ctxt.seid = pf->main_vsi_seid; |
| 5991 | ctxt.pf_num = pf->hw.pf_id; |
| 5992 | ctxt.vf_num = 0; |
| 5993 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 5994 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 5995 | if (ret) { |
| 5996 | dev_info(&pf->pdev->dev, |
| 5997 | "couldn't get pf vsi config, err %d, aq_err %d\n", |
| 5998 | ret, pf->hw.aq.asq_last_status); |
| 5999 | return -ENOENT; |
| 6000 | } |
| 6001 | memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info)); |
| 6002 | vsi->info.valid_sections = 0; |
| 6003 | |
| 6004 | vsi->seid = ctxt.seid; |
| 6005 | vsi->id = ctxt.vsi_number; |
| 6006 | |
| 6007 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 6008 | |
| 6009 | /* MFP mode setup queue map and update VSI */ |
| 6010 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 6011 | memset(&ctxt, 0, sizeof(ctxt)); |
| 6012 | ctxt.seid = pf->main_vsi_seid; |
| 6013 | ctxt.pf_num = pf->hw.pf_id; |
| 6014 | ctxt.vf_num = 0; |
| 6015 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 6016 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 6017 | if (ret) { |
| 6018 | dev_info(&pf->pdev->dev, |
| 6019 | "update vsi failed, aq_err=%d\n", |
| 6020 | pf->hw.aq.asq_last_status); |
| 6021 | ret = -ENOENT; |
| 6022 | goto err; |
| 6023 | } |
| 6024 | /* update the local VSI info queue map */ |
| 6025 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 6026 | vsi->info.valid_sections = 0; |
| 6027 | } else { |
| 6028 | /* Default/Main VSI is only enabled for TC0 |
| 6029 | * reconfigure it to enable all TCs that are |
| 6030 | * available on the port in SFP mode. |
| 6031 | */ |
| 6032 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 6033 | if (ret) { |
| 6034 | dev_info(&pf->pdev->dev, |
| 6035 | "failed to configure TCs for main VSI tc_map 0x%08x, err %d, aq_err %d\n", |
| 6036 | enabled_tc, ret, |
| 6037 | pf->hw.aq.asq_last_status); |
| 6038 | ret = -ENOENT; |
| 6039 | } |
| 6040 | } |
| 6041 | break; |
| 6042 | |
| 6043 | case I40E_VSI_FDIR: |
| 6044 | /* no queue mapping or actual HW VSI needed */ |
| 6045 | vsi->info.valid_sections = 0; |
| 6046 | vsi->seid = 0; |
| 6047 | vsi->id = 0; |
| 6048 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 6049 | return 0; |
| 6050 | break; |
| 6051 | |
| 6052 | case I40E_VSI_VMDQ2: |
| 6053 | ctxt.pf_num = hw->pf_id; |
| 6054 | ctxt.vf_num = 0; |
| 6055 | ctxt.uplink_seid = vsi->uplink_seid; |
| 6056 | ctxt.connection_type = 0x1; /* regular data port */ |
| 6057 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 6058 | |
| 6059 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6060 | |
| 6061 | /* This VSI is connected to VEB so the switch_id |
| 6062 | * should be set to zero by default. |
| 6063 | */ |
| 6064 | ctxt.info.switch_id = 0; |
| 6065 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB); |
| 6066 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6067 | |
| 6068 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 6069 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 6070 | break; |
| 6071 | |
| 6072 | case I40E_VSI_SRIOV: |
| 6073 | ctxt.pf_num = hw->pf_id; |
| 6074 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 6075 | ctxt.uplink_seid = vsi->uplink_seid; |
| 6076 | ctxt.connection_type = 0x1; /* regular data port */ |
| 6077 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 6078 | |
| 6079 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6080 | |
| 6081 | /* This VSI is connected to VEB so the switch_id |
| 6082 | * should be set to zero by default. |
| 6083 | */ |
| 6084 | ctxt.info.switch_id = cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6085 | |
| 6086 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 6087 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
| 6088 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 6089 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 6090 | break; |
| 6091 | |
| 6092 | default: |
| 6093 | return -ENODEV; |
| 6094 | } |
| 6095 | |
| 6096 | if (vsi->type != I40E_VSI_MAIN) { |
| 6097 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 6098 | if (ret) { |
| 6099 | dev_info(&vsi->back->pdev->dev, |
| 6100 | "add vsi failed, aq_err=%d\n", |
| 6101 | vsi->back->hw.aq.asq_last_status); |
| 6102 | ret = -ENOENT; |
| 6103 | goto err; |
| 6104 | } |
| 6105 | memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info)); |
| 6106 | vsi->info.valid_sections = 0; |
| 6107 | vsi->seid = ctxt.seid; |
| 6108 | vsi->id = ctxt.vsi_number; |
| 6109 | } |
| 6110 | |
| 6111 | /* If macvlan filters already exist, force them to get loaded */ |
| 6112 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 6113 | f->changed = true; |
| 6114 | f_count++; |
| 6115 | } |
| 6116 | if (f_count) { |
| 6117 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 6118 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 6119 | } |
| 6120 | |
| 6121 | /* Update VSI BW information */ |
| 6122 | ret = i40e_vsi_get_bw_info(vsi); |
| 6123 | if (ret) { |
| 6124 | dev_info(&pf->pdev->dev, |
| 6125 | "couldn't get vsi bw info, err %d, aq_err %d\n", |
| 6126 | ret, pf->hw.aq.asq_last_status); |
| 6127 | /* VSI is already added so not tearing that up */ |
| 6128 | ret = 0; |
| 6129 | } |
| 6130 | |
| 6131 | err: |
| 6132 | return ret; |
| 6133 | } |
| 6134 | |
| 6135 | /** |
| 6136 | * i40e_vsi_release - Delete a VSI and free its resources |
| 6137 | * @vsi: the VSI being removed |
| 6138 | * |
| 6139 | * Returns 0 on success or < 0 on error |
| 6140 | **/ |
| 6141 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 6142 | { |
| 6143 | struct i40e_mac_filter *f, *ftmp; |
| 6144 | struct i40e_veb *veb = NULL; |
| 6145 | struct i40e_pf *pf; |
| 6146 | u16 uplink_seid; |
| 6147 | int i, n; |
| 6148 | |
| 6149 | pf = vsi->back; |
| 6150 | |
| 6151 | /* release of a VEB-owner or last VSI is not allowed */ |
| 6152 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 6153 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 6154 | vsi->seid, vsi->uplink_seid); |
| 6155 | return -ENODEV; |
| 6156 | } |
| 6157 | if (vsi == pf->vsi[pf->lan_vsi] && |
| 6158 | !test_bit(__I40E_DOWN, &pf->state)) { |
| 6159 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 6160 | return -ENODEV; |
| 6161 | } |
| 6162 | |
| 6163 | uplink_seid = vsi->uplink_seid; |
| 6164 | if (vsi->type != I40E_VSI_SRIOV) { |
| 6165 | if (vsi->netdev_registered) { |
| 6166 | vsi->netdev_registered = false; |
| 6167 | if (vsi->netdev) { |
| 6168 | /* results in a call to i40e_close() */ |
| 6169 | unregister_netdev(vsi->netdev); |
| 6170 | free_netdev(vsi->netdev); |
| 6171 | vsi->netdev = NULL; |
| 6172 | } |
| 6173 | } else { |
| 6174 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) |
| 6175 | i40e_down(vsi); |
| 6176 | i40e_vsi_free_irq(vsi); |
| 6177 | i40e_vsi_free_tx_resources(vsi); |
| 6178 | i40e_vsi_free_rx_resources(vsi); |
| 6179 | } |
| 6180 | i40e_vsi_disable_irq(vsi); |
| 6181 | } |
| 6182 | |
| 6183 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) |
| 6184 | i40e_del_filter(vsi, f->macaddr, f->vlan, |
| 6185 | f->is_vf, f->is_netdev); |
| 6186 | i40e_sync_vsi_filters(vsi); |
| 6187 | |
| 6188 | i40e_vsi_delete(vsi); |
| 6189 | i40e_vsi_free_q_vectors(vsi); |
| 6190 | i40e_vsi_clear_rings(vsi); |
| 6191 | i40e_vsi_clear(vsi); |
| 6192 | |
| 6193 | /* If this was the last thing on the VEB, except for the |
| 6194 | * controlling VSI, remove the VEB, which puts the controlling |
| 6195 | * VSI onto the next level down in the switch. |
| 6196 | * |
| 6197 | * Well, okay, there's one more exception here: don't remove |
| 6198 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 6199 | * from up the network stack. |
| 6200 | */ |
| 6201 | for (n = 0, i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 6202 | if (pf->vsi[i] && |
| 6203 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 6204 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 6205 | n++; /* count the VSIs */ |
| 6206 | } |
| 6207 | } |
| 6208 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 6209 | if (!pf->veb[i]) |
| 6210 | continue; |
| 6211 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 6212 | n++; /* count the VEBs */ |
| 6213 | if (pf->veb[i]->seid == uplink_seid) |
| 6214 | veb = pf->veb[i]; |
| 6215 | } |
| 6216 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 6217 | i40e_veb_release(veb); |
| 6218 | |
| 6219 | return 0; |
| 6220 | } |
| 6221 | |
| 6222 | /** |
| 6223 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 6224 | * @vsi: ptr to the VSI |
| 6225 | * |
| 6226 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 6227 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 6228 | * newly allocated VSI. |
| 6229 | * |
| 6230 | * Returns 0 on success or negative on failure |
| 6231 | **/ |
| 6232 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 6233 | { |
| 6234 | int ret = -ENOENT; |
| 6235 | struct i40e_pf *pf = vsi->back; |
| 6236 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 6237 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6238 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 6239 | vsi->seid); |
| 6240 | return -EEXIST; |
| 6241 | } |
| 6242 | |
| 6243 | if (vsi->base_vector) { |
| 6244 | dev_info(&pf->pdev->dev, |
| 6245 | "VSI %d has non-zero base vector %d\n", |
| 6246 | vsi->seid, vsi->base_vector); |
| 6247 | return -EEXIST; |
| 6248 | } |
| 6249 | |
| 6250 | ret = i40e_alloc_q_vectors(vsi); |
| 6251 | if (ret) { |
| 6252 | dev_info(&pf->pdev->dev, |
| 6253 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 6254 | vsi->num_q_vectors, vsi->seid, ret); |
| 6255 | vsi->num_q_vectors = 0; |
| 6256 | goto vector_setup_out; |
| 6257 | } |
| 6258 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 6259 | if (vsi->num_q_vectors) |
| 6260 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 6261 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6262 | if (vsi->base_vector < 0) { |
| 6263 | dev_info(&pf->pdev->dev, |
| 6264 | "failed to get q tracking for VSI %d, err=%d\n", |
| 6265 | vsi->seid, vsi->base_vector); |
| 6266 | i40e_vsi_free_q_vectors(vsi); |
| 6267 | ret = -ENOENT; |
| 6268 | goto vector_setup_out; |
| 6269 | } |
| 6270 | |
| 6271 | vector_setup_out: |
| 6272 | return ret; |
| 6273 | } |
| 6274 | |
| 6275 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 6276 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 6277 | * @vsi: pointer to the vsi. |
| 6278 | * |
| 6279 | * This re-allocates a vsi's queue resources. |
| 6280 | * |
| 6281 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 6282 | * on success, otherwise returns NULL on failure. |
| 6283 | **/ |
| 6284 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 6285 | { |
| 6286 | struct i40e_pf *pf = vsi->back; |
| 6287 | u8 enabled_tc; |
| 6288 | int ret; |
| 6289 | |
| 6290 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 6291 | i40e_vsi_clear_rings(vsi); |
| 6292 | |
| 6293 | i40e_vsi_free_arrays(vsi, false); |
| 6294 | i40e_set_num_rings_in_vsi(vsi); |
| 6295 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 6296 | if (ret) |
| 6297 | goto err_vsi; |
| 6298 | |
| 6299 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 6300 | if (ret < 0) { |
| 6301 | dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n", |
| 6302 | vsi->seid, ret); |
| 6303 | goto err_vsi; |
| 6304 | } |
| 6305 | vsi->base_queue = ret; |
| 6306 | |
| 6307 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 6308 | * layout configurations. |
| 6309 | */ |
| 6310 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 6311 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 6312 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 6313 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 6314 | |
| 6315 | /* assign it some queues */ |
| 6316 | ret = i40e_alloc_rings(vsi); |
| 6317 | if (ret) |
| 6318 | goto err_rings; |
| 6319 | |
| 6320 | /* map all of the rings to the q_vectors */ |
| 6321 | i40e_vsi_map_rings_to_vectors(vsi); |
| 6322 | return vsi; |
| 6323 | |
| 6324 | err_rings: |
| 6325 | i40e_vsi_free_q_vectors(vsi); |
| 6326 | if (vsi->netdev_registered) { |
| 6327 | vsi->netdev_registered = false; |
| 6328 | unregister_netdev(vsi->netdev); |
| 6329 | free_netdev(vsi->netdev); |
| 6330 | vsi->netdev = NULL; |
| 6331 | } |
| 6332 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 6333 | err_vsi: |
| 6334 | i40e_vsi_clear(vsi); |
| 6335 | return NULL; |
| 6336 | } |
| 6337 | |
| 6338 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6339 | * i40e_vsi_setup - Set up a VSI by a given type |
| 6340 | * @pf: board private structure |
| 6341 | * @type: VSI type |
| 6342 | * @uplink_seid: the switch element to link to |
| 6343 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 6344 | * |
| 6345 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 6346 | * to the identified VEB. |
| 6347 | * |
| 6348 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 6349 | * success, otherwise returns NULL on failure. |
| 6350 | **/ |
| 6351 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 6352 | u16 uplink_seid, u32 param1) |
| 6353 | { |
| 6354 | struct i40e_vsi *vsi = NULL; |
| 6355 | struct i40e_veb *veb = NULL; |
| 6356 | int ret, i; |
| 6357 | int v_idx; |
| 6358 | |
| 6359 | /* The requested uplink_seid must be either |
| 6360 | * - the PF's port seid |
| 6361 | * no VEB is needed because this is the PF |
| 6362 | * or this is a Flow Director special case VSI |
| 6363 | * - seid of an existing VEB |
| 6364 | * - seid of a VSI that owns an existing VEB |
| 6365 | * - seid of a VSI that doesn't own a VEB |
| 6366 | * a new VEB is created and the VSI becomes the owner |
| 6367 | * - seid of the PF VSI, which is what creates the first VEB |
| 6368 | * this is a special case of the previous |
| 6369 | * |
| 6370 | * Find which uplink_seid we were given and create a new VEB if needed |
| 6371 | */ |
| 6372 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 6373 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 6374 | veb = pf->veb[i]; |
| 6375 | break; |
| 6376 | } |
| 6377 | } |
| 6378 | |
| 6379 | if (!veb && uplink_seid != pf->mac_seid) { |
| 6380 | |
| 6381 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 6382 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 6383 | vsi = pf->vsi[i]; |
| 6384 | break; |
| 6385 | } |
| 6386 | } |
| 6387 | if (!vsi) { |
| 6388 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 6389 | uplink_seid); |
| 6390 | return NULL; |
| 6391 | } |
| 6392 | |
| 6393 | if (vsi->uplink_seid == pf->mac_seid) |
| 6394 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 6395 | vsi->tc_config.enabled_tc); |
| 6396 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 6397 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 6398 | vsi->tc_config.enabled_tc); |
| 6399 | |
| 6400 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 6401 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 6402 | veb = pf->veb[i]; |
| 6403 | } |
| 6404 | if (!veb) { |
| 6405 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 6406 | return NULL; |
| 6407 | } |
| 6408 | |
| 6409 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 6410 | uplink_seid = veb->seid; |
| 6411 | } |
| 6412 | |
| 6413 | /* get vsi sw struct */ |
| 6414 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 6415 | if (v_idx < 0) |
| 6416 | goto err_alloc; |
| 6417 | vsi = pf->vsi[v_idx]; |
| 6418 | vsi->type = type; |
| 6419 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 6420 | |
| 6421 | if (type == I40E_VSI_MAIN) |
| 6422 | pf->lan_vsi = v_idx; |
| 6423 | else if (type == I40E_VSI_SRIOV) |
| 6424 | vsi->vf_id = param1; |
| 6425 | /* assign it some queues */ |
| 6426 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 6427 | if (ret < 0) { |
| 6428 | dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n", |
| 6429 | vsi->seid, ret); |
| 6430 | goto err_vsi; |
| 6431 | } |
| 6432 | vsi->base_queue = ret; |
| 6433 | |
| 6434 | /* get a VSI from the hardware */ |
| 6435 | vsi->uplink_seid = uplink_seid; |
| 6436 | ret = i40e_add_vsi(vsi); |
| 6437 | if (ret) |
| 6438 | goto err_vsi; |
| 6439 | |
| 6440 | switch (vsi->type) { |
| 6441 | /* setup the netdev if needed */ |
| 6442 | case I40E_VSI_MAIN: |
| 6443 | case I40E_VSI_VMDQ2: |
| 6444 | ret = i40e_config_netdev(vsi); |
| 6445 | if (ret) |
| 6446 | goto err_netdev; |
| 6447 | ret = register_netdev(vsi->netdev); |
| 6448 | if (ret) |
| 6449 | goto err_netdev; |
| 6450 | vsi->netdev_registered = true; |
| 6451 | netif_carrier_off(vsi->netdev); |
| 6452 | /* fall through */ |
| 6453 | |
| 6454 | case I40E_VSI_FDIR: |
| 6455 | /* set up vectors and rings if needed */ |
| 6456 | ret = i40e_vsi_setup_vectors(vsi); |
| 6457 | if (ret) |
| 6458 | goto err_msix; |
| 6459 | |
| 6460 | ret = i40e_alloc_rings(vsi); |
| 6461 | if (ret) |
| 6462 | goto err_rings; |
| 6463 | |
| 6464 | /* map all of the rings to the q_vectors */ |
| 6465 | i40e_vsi_map_rings_to_vectors(vsi); |
| 6466 | |
| 6467 | i40e_vsi_reset_stats(vsi); |
| 6468 | break; |
| 6469 | |
| 6470 | default: |
| 6471 | /* no netdev or rings for the other VSI types */ |
| 6472 | break; |
| 6473 | } |
| 6474 | |
| 6475 | return vsi; |
| 6476 | |
| 6477 | err_rings: |
| 6478 | i40e_vsi_free_q_vectors(vsi); |
| 6479 | err_msix: |
| 6480 | if (vsi->netdev_registered) { |
| 6481 | vsi->netdev_registered = false; |
| 6482 | unregister_netdev(vsi->netdev); |
| 6483 | free_netdev(vsi->netdev); |
| 6484 | vsi->netdev = NULL; |
| 6485 | } |
| 6486 | err_netdev: |
| 6487 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 6488 | err_vsi: |
| 6489 | i40e_vsi_clear(vsi); |
| 6490 | err_alloc: |
| 6491 | return NULL; |
| 6492 | } |
| 6493 | |
| 6494 | /** |
| 6495 | * i40e_veb_get_bw_info - Query VEB BW information |
| 6496 | * @veb: the veb to query |
| 6497 | * |
| 6498 | * Query the Tx scheduler BW configuration data for given VEB |
| 6499 | **/ |
| 6500 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 6501 | { |
| 6502 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 6503 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 6504 | struct i40e_pf *pf = veb->pf; |
| 6505 | struct i40e_hw *hw = &pf->hw; |
| 6506 | u32 tc_bw_max; |
| 6507 | int ret = 0; |
| 6508 | int i; |
| 6509 | |
| 6510 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 6511 | &bw_data, NULL); |
| 6512 | if (ret) { |
| 6513 | dev_info(&pf->pdev->dev, |
| 6514 | "query veb bw config failed, aq_err=%d\n", |
| 6515 | hw->aq.asq_last_status); |
| 6516 | goto out; |
| 6517 | } |
| 6518 | |
| 6519 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 6520 | &ets_data, NULL); |
| 6521 | if (ret) { |
| 6522 | dev_info(&pf->pdev->dev, |
| 6523 | "query veb bw ets config failed, aq_err=%d\n", |
| 6524 | hw->aq.asq_last_status); |
| 6525 | goto out; |
| 6526 | } |
| 6527 | |
| 6528 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 6529 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 6530 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
| 6531 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 6532 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 6533 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 6534 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 6535 | veb->bw_tc_limit_credits[i] = |
| 6536 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 6537 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 6538 | } |
| 6539 | |
| 6540 | out: |
| 6541 | return ret; |
| 6542 | } |
| 6543 | |
| 6544 | /** |
| 6545 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 6546 | * @pf: board private structure |
| 6547 | * |
| 6548 | * On error: returns error code (negative) |
| 6549 | * On success: returns vsi index in PF (positive) |
| 6550 | **/ |
| 6551 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 6552 | { |
| 6553 | int ret = -ENOENT; |
| 6554 | struct i40e_veb *veb; |
| 6555 | int i; |
| 6556 | |
| 6557 | /* Need to protect the allocation of switch elements at the PF level */ |
| 6558 | mutex_lock(&pf->switch_mutex); |
| 6559 | |
| 6560 | /* VEB list may be fragmented if VEB creation/destruction has |
| 6561 | * been happening. We can afford to do a quick scan to look |
| 6562 | * for any free slots in the list. |
| 6563 | * |
| 6564 | * find next empty veb slot, looping back around if necessary |
| 6565 | */ |
| 6566 | i = 0; |
| 6567 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 6568 | i++; |
| 6569 | if (i >= I40E_MAX_VEB) { |
| 6570 | ret = -ENOMEM; |
| 6571 | goto err_alloc_veb; /* out of VEB slots! */ |
| 6572 | } |
| 6573 | |
| 6574 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 6575 | if (!veb) { |
| 6576 | ret = -ENOMEM; |
| 6577 | goto err_alloc_veb; |
| 6578 | } |
| 6579 | veb->pf = pf; |
| 6580 | veb->idx = i; |
| 6581 | veb->enabled_tc = 1; |
| 6582 | |
| 6583 | pf->veb[i] = veb; |
| 6584 | ret = i; |
| 6585 | err_alloc_veb: |
| 6586 | mutex_unlock(&pf->switch_mutex); |
| 6587 | return ret; |
| 6588 | } |
| 6589 | |
| 6590 | /** |
| 6591 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 6592 | * @branch: where to start deleting |
| 6593 | * |
| 6594 | * This uses recursion to find the tips of the branch to be |
| 6595 | * removed, deleting until we get back to and can delete this VEB. |
| 6596 | **/ |
| 6597 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 6598 | { |
| 6599 | struct i40e_pf *pf = branch->pf; |
| 6600 | u16 branch_seid = branch->seid; |
| 6601 | u16 veb_idx = branch->idx; |
| 6602 | int i; |
| 6603 | |
| 6604 | /* release any VEBs on this VEB - RECURSION */ |
| 6605 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 6606 | if (!pf->veb[i]) |
| 6607 | continue; |
| 6608 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 6609 | i40e_switch_branch_release(pf->veb[i]); |
| 6610 | } |
| 6611 | |
| 6612 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 6613 | * |
| 6614 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 6615 | * the VEB itself, so don't use (*branch) after this loop. |
| 6616 | */ |
| 6617 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 6618 | if (!pf->vsi[i]) |
| 6619 | continue; |
| 6620 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 6621 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 6622 | i40e_vsi_release(pf->vsi[i]); |
| 6623 | } |
| 6624 | } |
| 6625 | |
| 6626 | /* There's one corner case where the VEB might not have been |
| 6627 | * removed, so double check it here and remove it if needed. |
| 6628 | * This case happens if the veb was created from the debugfs |
| 6629 | * commands and no VSIs were added to it. |
| 6630 | */ |
| 6631 | if (pf->veb[veb_idx]) |
| 6632 | i40e_veb_release(pf->veb[veb_idx]); |
| 6633 | } |
| 6634 | |
| 6635 | /** |
| 6636 | * i40e_veb_clear - remove veb struct |
| 6637 | * @veb: the veb to remove |
| 6638 | **/ |
| 6639 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 6640 | { |
| 6641 | if (!veb) |
| 6642 | return; |
| 6643 | |
| 6644 | if (veb->pf) { |
| 6645 | struct i40e_pf *pf = veb->pf; |
| 6646 | |
| 6647 | mutex_lock(&pf->switch_mutex); |
| 6648 | if (pf->veb[veb->idx] == veb) |
| 6649 | pf->veb[veb->idx] = NULL; |
| 6650 | mutex_unlock(&pf->switch_mutex); |
| 6651 | } |
| 6652 | |
| 6653 | kfree(veb); |
| 6654 | } |
| 6655 | |
| 6656 | /** |
| 6657 | * i40e_veb_release - Delete a VEB and free its resources |
| 6658 | * @veb: the VEB being removed |
| 6659 | **/ |
| 6660 | void i40e_veb_release(struct i40e_veb *veb) |
| 6661 | { |
| 6662 | struct i40e_vsi *vsi = NULL; |
| 6663 | struct i40e_pf *pf; |
| 6664 | int i, n = 0; |
| 6665 | |
| 6666 | pf = veb->pf; |
| 6667 | |
| 6668 | /* find the remaining VSI and check for extras */ |
| 6669 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 6670 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 6671 | n++; |
| 6672 | vsi = pf->vsi[i]; |
| 6673 | } |
| 6674 | } |
| 6675 | if (n != 1) { |
| 6676 | dev_info(&pf->pdev->dev, |
| 6677 | "can't remove VEB %d with %d VSIs left\n", |
| 6678 | veb->seid, n); |
| 6679 | return; |
| 6680 | } |
| 6681 | |
| 6682 | /* move the remaining VSI to uplink veb */ |
| 6683 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 6684 | if (veb->uplink_seid) { |
| 6685 | vsi->uplink_seid = veb->uplink_seid; |
| 6686 | if (veb->uplink_seid == pf->mac_seid) |
| 6687 | vsi->veb_idx = I40E_NO_VEB; |
| 6688 | else |
| 6689 | vsi->veb_idx = veb->veb_idx; |
| 6690 | } else { |
| 6691 | /* floating VEB */ |
| 6692 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 6693 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 6694 | } |
| 6695 | |
| 6696 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 6697 | i40e_veb_clear(veb); |
| 6698 | |
| 6699 | return; |
| 6700 | } |
| 6701 | |
| 6702 | /** |
| 6703 | * i40e_add_veb - create the VEB in the switch |
| 6704 | * @veb: the VEB to be instantiated |
| 6705 | * @vsi: the controlling VSI |
| 6706 | **/ |
| 6707 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 6708 | { |
| 6709 | bool is_default = (vsi->idx == vsi->back->lan_vsi); |
Kevin Scott | e1c51b95 | 2013-11-20 10:02:51 +0000 | [diff] [blame] | 6710 | bool is_cloud = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6711 | int ret; |
| 6712 | |
| 6713 | /* get a VEB from the hardware */ |
| 6714 | 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] | 6715 | veb->enabled_tc, is_default, |
| 6716 | is_cloud, &veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6717 | if (ret) { |
| 6718 | dev_info(&veb->pf->pdev->dev, |
| 6719 | "couldn't add VEB, err %d, aq_err %d\n", |
| 6720 | ret, veb->pf->hw.aq.asq_last_status); |
| 6721 | return -EPERM; |
| 6722 | } |
| 6723 | |
| 6724 | /* get statistics counter */ |
| 6725 | ret = i40e_aq_get_veb_parameters(&veb->pf->hw, veb->seid, NULL, NULL, |
| 6726 | &veb->stats_idx, NULL, NULL, NULL); |
| 6727 | if (ret) { |
| 6728 | dev_info(&veb->pf->pdev->dev, |
| 6729 | "couldn't get VEB statistics idx, err %d, aq_err %d\n", |
| 6730 | ret, veb->pf->hw.aq.asq_last_status); |
| 6731 | return -EPERM; |
| 6732 | } |
| 6733 | ret = i40e_veb_get_bw_info(veb); |
| 6734 | if (ret) { |
| 6735 | dev_info(&veb->pf->pdev->dev, |
| 6736 | "couldn't get VEB bw info, err %d, aq_err %d\n", |
| 6737 | ret, veb->pf->hw.aq.asq_last_status); |
| 6738 | i40e_aq_delete_element(&veb->pf->hw, veb->seid, NULL); |
| 6739 | return -ENOENT; |
| 6740 | } |
| 6741 | |
| 6742 | vsi->uplink_seid = veb->seid; |
| 6743 | vsi->veb_idx = veb->idx; |
| 6744 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 6745 | |
| 6746 | return 0; |
| 6747 | } |
| 6748 | |
| 6749 | /** |
| 6750 | * i40e_veb_setup - Set up a VEB |
| 6751 | * @pf: board private structure |
| 6752 | * @flags: VEB setup flags |
| 6753 | * @uplink_seid: the switch element to link to |
| 6754 | * @vsi_seid: the initial VSI seid |
| 6755 | * @enabled_tc: Enabled TC bit-map |
| 6756 | * |
| 6757 | * This allocates the sw VEB structure and links it into the switch |
| 6758 | * It is possible and legal for this to be a duplicate of an already |
| 6759 | * existing VEB. It is also possible for both uplink and vsi seids |
| 6760 | * to be zero, in order to create a floating VEB. |
| 6761 | * |
| 6762 | * Returns pointer to the successfully allocated VEB sw struct on |
| 6763 | * success, otherwise returns NULL on failure. |
| 6764 | **/ |
| 6765 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 6766 | u16 uplink_seid, u16 vsi_seid, |
| 6767 | u8 enabled_tc) |
| 6768 | { |
| 6769 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 6770 | int vsi_idx, veb_idx; |
| 6771 | int ret; |
| 6772 | |
| 6773 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 6774 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 6775 | (uplink_seid + vsi_seid != 0)) { |
| 6776 | dev_info(&pf->pdev->dev, |
| 6777 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 6778 | uplink_seid, vsi_seid); |
| 6779 | return NULL; |
| 6780 | } |
| 6781 | |
| 6782 | /* make sure there is such a vsi and uplink */ |
| 6783 | for (vsi_idx = 0; vsi_idx < pf->hw.func_caps.num_vsis; vsi_idx++) |
| 6784 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 6785 | break; |
| 6786 | if (vsi_idx >= pf->hw.func_caps.num_vsis && vsi_seid != 0) { |
| 6787 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 6788 | vsi_seid); |
| 6789 | return NULL; |
| 6790 | } |
| 6791 | |
| 6792 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 6793 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 6794 | if (pf->veb[veb_idx] && |
| 6795 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 6796 | uplink_veb = pf->veb[veb_idx]; |
| 6797 | break; |
| 6798 | } |
| 6799 | } |
| 6800 | if (!uplink_veb) { |
| 6801 | dev_info(&pf->pdev->dev, |
| 6802 | "uplink seid %d not found\n", uplink_seid); |
| 6803 | return NULL; |
| 6804 | } |
| 6805 | } |
| 6806 | |
| 6807 | /* get veb sw struct */ |
| 6808 | veb_idx = i40e_veb_mem_alloc(pf); |
| 6809 | if (veb_idx < 0) |
| 6810 | goto err_alloc; |
| 6811 | veb = pf->veb[veb_idx]; |
| 6812 | veb->flags = flags; |
| 6813 | veb->uplink_seid = uplink_seid; |
| 6814 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 6815 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 6816 | |
| 6817 | /* create the VEB in the switch */ |
| 6818 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 6819 | if (ret) |
| 6820 | goto err_veb; |
| 6821 | |
| 6822 | return veb; |
| 6823 | |
| 6824 | err_veb: |
| 6825 | i40e_veb_clear(veb); |
| 6826 | err_alloc: |
| 6827 | return NULL; |
| 6828 | } |
| 6829 | |
| 6830 | /** |
| 6831 | * i40e_setup_pf_switch_element - set pf vars based on switch type |
| 6832 | * @pf: board private structure |
| 6833 | * @ele: element we are building info from |
| 6834 | * @num_reported: total number of elements |
| 6835 | * @printconfig: should we print the contents |
| 6836 | * |
| 6837 | * helper function to assist in extracting a few useful SEID values. |
| 6838 | **/ |
| 6839 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 6840 | struct i40e_aqc_switch_config_element_resp *ele, |
| 6841 | u16 num_reported, bool printconfig) |
| 6842 | { |
| 6843 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 6844 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 6845 | u8 element_type = ele->element_type; |
| 6846 | u16 seid = le16_to_cpu(ele->seid); |
| 6847 | |
| 6848 | if (printconfig) |
| 6849 | dev_info(&pf->pdev->dev, |
| 6850 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 6851 | element_type, seid, uplink_seid, downlink_seid); |
| 6852 | |
| 6853 | switch (element_type) { |
| 6854 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 6855 | pf->mac_seid = seid; |
| 6856 | break; |
| 6857 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 6858 | /* Main VEB? */ |
| 6859 | if (uplink_seid != pf->mac_seid) |
| 6860 | break; |
| 6861 | if (pf->lan_veb == I40E_NO_VEB) { |
| 6862 | int v; |
| 6863 | |
| 6864 | /* find existing or else empty VEB */ |
| 6865 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 6866 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 6867 | pf->lan_veb = v; |
| 6868 | break; |
| 6869 | } |
| 6870 | } |
| 6871 | if (pf->lan_veb == I40E_NO_VEB) { |
| 6872 | v = i40e_veb_mem_alloc(pf); |
| 6873 | if (v < 0) |
| 6874 | break; |
| 6875 | pf->lan_veb = v; |
| 6876 | } |
| 6877 | } |
| 6878 | |
| 6879 | pf->veb[pf->lan_veb]->seid = seid; |
| 6880 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 6881 | pf->veb[pf->lan_veb]->pf = pf; |
| 6882 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 6883 | break; |
| 6884 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 6885 | if (num_reported != 1) |
| 6886 | break; |
| 6887 | /* This is immediately after a reset so we can assume this is |
| 6888 | * the PF's VSI |
| 6889 | */ |
| 6890 | pf->mac_seid = uplink_seid; |
| 6891 | pf->pf_seid = downlink_seid; |
| 6892 | pf->main_vsi_seid = seid; |
| 6893 | if (printconfig) |
| 6894 | dev_info(&pf->pdev->dev, |
| 6895 | "pf_seid=%d main_vsi_seid=%d\n", |
| 6896 | pf->pf_seid, pf->main_vsi_seid); |
| 6897 | break; |
| 6898 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 6899 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 6900 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 6901 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 6902 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 6903 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 6904 | /* ignore these for now */ |
| 6905 | break; |
| 6906 | default: |
| 6907 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 6908 | element_type, seid); |
| 6909 | break; |
| 6910 | } |
| 6911 | } |
| 6912 | |
| 6913 | /** |
| 6914 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 6915 | * @pf: board private structure |
| 6916 | * @printconfig: should we print the contents |
| 6917 | * |
| 6918 | * Get the current switch configuration from the device and |
| 6919 | * extract a few useful SEID values. |
| 6920 | **/ |
| 6921 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 6922 | { |
| 6923 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 6924 | u16 next_seid = 0; |
| 6925 | int ret = 0; |
| 6926 | u8 *aq_buf; |
| 6927 | int i; |
| 6928 | |
| 6929 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 6930 | if (!aq_buf) |
| 6931 | return -ENOMEM; |
| 6932 | |
| 6933 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 6934 | do { |
| 6935 | u16 num_reported, num_total; |
| 6936 | |
| 6937 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 6938 | I40E_AQ_LARGE_BUF, |
| 6939 | &next_seid, NULL); |
| 6940 | if (ret) { |
| 6941 | dev_info(&pf->pdev->dev, |
| 6942 | "get switch config failed %d aq_err=%x\n", |
| 6943 | ret, pf->hw.aq.asq_last_status); |
| 6944 | kfree(aq_buf); |
| 6945 | return -ENOENT; |
| 6946 | } |
| 6947 | |
| 6948 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 6949 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 6950 | |
| 6951 | if (printconfig) |
| 6952 | dev_info(&pf->pdev->dev, |
| 6953 | "header: %d reported %d total\n", |
| 6954 | num_reported, num_total); |
| 6955 | |
| 6956 | if (num_reported) { |
| 6957 | int sz = sizeof(*sw_config) * num_reported; |
| 6958 | |
| 6959 | kfree(pf->sw_config); |
| 6960 | pf->sw_config = kzalloc(sz, GFP_KERNEL); |
| 6961 | if (pf->sw_config) |
| 6962 | memcpy(pf->sw_config, sw_config, sz); |
| 6963 | } |
| 6964 | |
| 6965 | for (i = 0; i < num_reported; i++) { |
| 6966 | struct i40e_aqc_switch_config_element_resp *ele = |
| 6967 | &sw_config->element[i]; |
| 6968 | |
| 6969 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 6970 | printconfig); |
| 6971 | } |
| 6972 | } while (next_seid != 0); |
| 6973 | |
| 6974 | kfree(aq_buf); |
| 6975 | return ret; |
| 6976 | } |
| 6977 | |
| 6978 | /** |
| 6979 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 6980 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 6981 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6982 | * |
| 6983 | * Returns 0 on success, negative value on failure |
| 6984 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 6985 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6986 | { |
Jesse Brandeburg | 895106a | 2013-11-26 10:49:16 +0000 | [diff] [blame] | 6987 | u32 rxfc = 0, txfc = 0, rxfc_reg; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6988 | int ret; |
| 6989 | |
| 6990 | /* find out what's out there already */ |
| 6991 | ret = i40e_fetch_switch_configuration(pf, false); |
| 6992 | if (ret) { |
| 6993 | dev_info(&pf->pdev->dev, |
| 6994 | "couldn't fetch switch config, err %d, aq_err %d\n", |
| 6995 | ret, pf->hw.aq.asq_last_status); |
| 6996 | return ret; |
| 6997 | } |
| 6998 | i40e_pf_reset_stats(pf); |
| 6999 | |
| 7000 | /* fdir VSI must happen first to be sure it gets queue 0, but only |
| 7001 | * if there is enough room for the fdir VSI |
| 7002 | */ |
| 7003 | if (pf->num_lan_qps > 1) |
| 7004 | i40e_fdir_setup(pf); |
| 7005 | |
| 7006 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 7007 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7008 | struct i40e_vsi *vsi = NULL; |
| 7009 | u16 uplink_seid; |
| 7010 | |
| 7011 | /* Set up the PF VSI associated with the PF's main VSI |
| 7012 | * that is already in the HW switch |
| 7013 | */ |
| 7014 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 7015 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 7016 | else |
| 7017 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 7018 | if (pf->lan_vsi == I40E_NO_VSI) |
| 7019 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 7020 | else if (reinit) |
| 7021 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7022 | if (!vsi) { |
| 7023 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 7024 | i40e_fdir_teardown(pf); |
| 7025 | return -EAGAIN; |
| 7026 | } |
| 7027 | /* accommodate kcompat by copying the main VSI queue count |
| 7028 | * into the pf, since this newer code pushes the pf queue |
| 7029 | * info down a level into a VSI |
| 7030 | */ |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7031 | pf->num_rx_queues = vsi->num_queue_pairs; |
| 7032 | pf->num_tx_queues = vsi->num_queue_pairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7033 | } else { |
| 7034 | /* force a reset of TC and queue layout configurations */ |
| 7035 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 7036 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 7037 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 7038 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 7039 | } |
| 7040 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 7041 | |
| 7042 | /* Setup static PF queue filter control settings */ |
| 7043 | ret = i40e_setup_pf_filter_control(pf); |
| 7044 | if (ret) { |
| 7045 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 7046 | ret); |
| 7047 | /* Failure here should not stop continuing other steps */ |
| 7048 | } |
| 7049 | |
| 7050 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 7051 | * the hash |
| 7052 | */ |
| 7053 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 7054 | i40e_config_rss(pf); |
| 7055 | |
| 7056 | /* fill in link information and enable LSE reporting */ |
| 7057 | i40e_aq_get_link_info(&pf->hw, true, NULL, NULL); |
| 7058 | i40e_link_event(pf); |
| 7059 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 7060 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7061 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 7062 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 7063 | /* requested_mode is set in probe or by ethtool */ |
| 7064 | if (!pf->fc_autoneg_status) |
| 7065 | goto no_autoneg; |
| 7066 | |
| 7067 | if ((pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) && |
| 7068 | (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7069 | pf->hw.fc.current_mode = I40E_FC_FULL; |
| 7070 | else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) |
| 7071 | pf->hw.fc.current_mode = I40E_FC_TX_PAUSE; |
| 7072 | else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX) |
| 7073 | pf->hw.fc.current_mode = I40E_FC_RX_PAUSE; |
| 7074 | else |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 7075 | pf->hw.fc.current_mode = I40E_FC_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7076 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 7077 | /* sync the flow control settings with the auto-neg values */ |
| 7078 | switch (pf->hw.fc.current_mode) { |
| 7079 | case I40E_FC_FULL: |
| 7080 | txfc = 1; |
| 7081 | rxfc = 1; |
| 7082 | break; |
| 7083 | case I40E_FC_TX_PAUSE: |
| 7084 | txfc = 1; |
| 7085 | rxfc = 0; |
| 7086 | break; |
| 7087 | case I40E_FC_RX_PAUSE: |
| 7088 | txfc = 0; |
| 7089 | rxfc = 1; |
| 7090 | break; |
| 7091 | case I40E_FC_NONE: |
| 7092 | case I40E_FC_DEFAULT: |
| 7093 | txfc = 0; |
| 7094 | rxfc = 0; |
| 7095 | break; |
| 7096 | case I40E_FC_PFC: |
| 7097 | /* TBD */ |
| 7098 | break; |
| 7099 | /* no default case, we have to handle all possibilities here */ |
| 7100 | } |
| 7101 | |
| 7102 | wr32(&pf->hw, I40E_PRTDCB_FCCFG, txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT); |
| 7103 | |
| 7104 | rxfc_reg = rd32(&pf->hw, I40E_PRTDCB_MFLCN) & |
| 7105 | ~I40E_PRTDCB_MFLCN_RFCE_MASK; |
| 7106 | rxfc_reg |= (rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT); |
| 7107 | |
| 7108 | wr32(&pf->hw, I40E_PRTDCB_MFLCN, rxfc_reg); |
| 7109 | |
| 7110 | goto fc_complete; |
| 7111 | |
| 7112 | no_autoneg: |
| 7113 | /* disable L2 flow control, user can turn it on if they wish */ |
| 7114 | wr32(&pf->hw, I40E_PRTDCB_FCCFG, 0); |
| 7115 | wr32(&pf->hw, I40E_PRTDCB_MFLCN, rd32(&pf->hw, I40E_PRTDCB_MFLCN) & |
| 7116 | ~I40E_PRTDCB_MFLCN_RFCE_MASK); |
| 7117 | |
| 7118 | fc_complete: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7119 | return ret; |
| 7120 | } |
| 7121 | |
| 7122 | /** |
| 7123 | * i40e_set_rss_size - helper to set rss_size |
| 7124 | * @pf: board private structure |
| 7125 | * @queues_left: how many queues |
| 7126 | */ |
| 7127 | static u16 i40e_set_rss_size(struct i40e_pf *pf, int queues_left) |
| 7128 | { |
| 7129 | int num_tc0; |
| 7130 | |
| 7131 | num_tc0 = min_t(int, queues_left, pf->rss_size_max); |
Jesse Brandeburg | bf051a3 | 2013-11-26 10:49:17 +0000 | [diff] [blame] | 7132 | num_tc0 = min_t(int, num_tc0, num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7133 | num_tc0 = rounddown_pow_of_two(num_tc0); |
| 7134 | |
| 7135 | return num_tc0; |
| 7136 | } |
| 7137 | |
| 7138 | /** |
| 7139 | * i40e_determine_queue_usage - Work out queue distribution |
| 7140 | * @pf: board private structure |
| 7141 | **/ |
| 7142 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 7143 | { |
| 7144 | int accum_tc_size; |
| 7145 | int queues_left; |
| 7146 | |
| 7147 | pf->num_lan_qps = 0; |
| 7148 | pf->num_tc_qps = rounddown_pow_of_two(pf->num_tc_qps); |
| 7149 | accum_tc_size = (I40E_MAX_TRAFFIC_CLASS - 1) * pf->num_tc_qps; |
| 7150 | |
| 7151 | /* Find the max queues to be put into basic use. We'll always be |
| 7152 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 7153 | * big RSS set. |
| 7154 | */ |
| 7155 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 7156 | |
| 7157 | if (!((pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 7158 | (pf->flags & I40E_FLAG_MQ_ENABLED)) || |
| 7159 | !(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 7160 | I40E_FLAG_FDIR_ENABLED | I40E_FLAG_DCB_ENABLED)) || |
| 7161 | (queues_left == 1)) { |
| 7162 | |
| 7163 | /* one qp for PF, no queues for anything else */ |
| 7164 | queues_left = 0; |
| 7165 | pf->rss_size = pf->num_lan_qps = 1; |
| 7166 | |
| 7167 | /* make sure all the fancies are disabled */ |
| 7168 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
| 7169 | I40E_FLAG_MQ_ENABLED | |
| 7170 | I40E_FLAG_FDIR_ENABLED | |
| 7171 | I40E_FLAG_FDIR_ATR_ENABLED | |
| 7172 | I40E_FLAG_DCB_ENABLED | |
| 7173 | I40E_FLAG_SRIOV_ENABLED | |
| 7174 | I40E_FLAG_VMDQ_ENABLED); |
| 7175 | |
| 7176 | } else if (pf->flags & I40E_FLAG_RSS_ENABLED && |
| 7177 | !(pf->flags & I40E_FLAG_FDIR_ENABLED) && |
| 7178 | !(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 7179 | |
| 7180 | pf->rss_size = i40e_set_rss_size(pf, queues_left); |
| 7181 | |
| 7182 | queues_left -= pf->rss_size; |
| 7183 | pf->num_lan_qps = pf->rss_size; |
| 7184 | |
| 7185 | } else if (pf->flags & I40E_FLAG_RSS_ENABLED && |
| 7186 | !(pf->flags & I40E_FLAG_FDIR_ENABLED) && |
| 7187 | (pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 7188 | |
| 7189 | /* save num_tc_qps queues for TCs 1 thru 7 and the rest |
| 7190 | * are set up for RSS in TC0 |
| 7191 | */ |
| 7192 | queues_left -= accum_tc_size; |
| 7193 | |
| 7194 | pf->rss_size = i40e_set_rss_size(pf, queues_left); |
| 7195 | |
| 7196 | queues_left -= pf->rss_size; |
| 7197 | if (queues_left < 0) { |
| 7198 | dev_info(&pf->pdev->dev, "not enough queues for DCB\n"); |
| 7199 | return; |
| 7200 | } |
| 7201 | |
| 7202 | pf->num_lan_qps = pf->rss_size + accum_tc_size; |
| 7203 | |
| 7204 | } else if (pf->flags & I40E_FLAG_RSS_ENABLED && |
| 7205 | (pf->flags & I40E_FLAG_FDIR_ENABLED) && |
| 7206 | !(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 7207 | |
| 7208 | queues_left -= 1; /* save 1 queue for FD */ |
| 7209 | |
| 7210 | pf->rss_size = i40e_set_rss_size(pf, queues_left); |
| 7211 | |
| 7212 | queues_left -= pf->rss_size; |
| 7213 | if (queues_left < 0) { |
| 7214 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director\n"); |
| 7215 | return; |
| 7216 | } |
| 7217 | |
| 7218 | pf->num_lan_qps = pf->rss_size; |
| 7219 | |
| 7220 | } else if (pf->flags & I40E_FLAG_RSS_ENABLED && |
| 7221 | (pf->flags & I40E_FLAG_FDIR_ENABLED) && |
| 7222 | (pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 7223 | |
| 7224 | /* save 1 queue for TCs 1 thru 7, |
| 7225 | * 1 queue for flow director, |
| 7226 | * and the rest are set up for RSS in TC0 |
| 7227 | */ |
| 7228 | queues_left -= 1; |
| 7229 | queues_left -= accum_tc_size; |
| 7230 | |
| 7231 | pf->rss_size = i40e_set_rss_size(pf, queues_left); |
| 7232 | queues_left -= pf->rss_size; |
| 7233 | if (queues_left < 0) { |
| 7234 | dev_info(&pf->pdev->dev, "not enough queues for DCB and Flow Director\n"); |
| 7235 | return; |
| 7236 | } |
| 7237 | |
| 7238 | pf->num_lan_qps = pf->rss_size + accum_tc_size; |
| 7239 | |
| 7240 | } else { |
| 7241 | dev_info(&pf->pdev->dev, |
| 7242 | "Invalid configuration, flags=0x%08llx\n", pf->flags); |
| 7243 | return; |
| 7244 | } |
| 7245 | |
| 7246 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 7247 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
| 7248 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, (queues_left / |
| 7249 | pf->num_vf_qps)); |
| 7250 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 7251 | } |
| 7252 | |
| 7253 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 7254 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 7255 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 7256 | (queues_left / pf->num_vmdq_qps)); |
| 7257 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 7258 | } |
| 7259 | |
| 7260 | return; |
| 7261 | } |
| 7262 | |
| 7263 | /** |
| 7264 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 7265 | * @pf: PF to be setup |
| 7266 | * |
| 7267 | * i40e_setup_pf_filter_control sets up a pf's initial filter control |
| 7268 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 7269 | * based filter sizes required for them. It also enables Flow director, |
| 7270 | * ethertype and macvlan type filter settings for the pf. |
| 7271 | * |
| 7272 | * Returns 0 on success, negative on failure |
| 7273 | **/ |
| 7274 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 7275 | { |
| 7276 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 7277 | |
| 7278 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 7279 | |
| 7280 | /* Flow Director is enabled */ |
| 7281 | if (pf->flags & (I40E_FLAG_FDIR_ENABLED | I40E_FLAG_FDIR_ATR_ENABLED)) |
| 7282 | settings->enable_fdir = true; |
| 7283 | |
| 7284 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 7285 | settings->enable_ethtype = true; |
| 7286 | settings->enable_macvlan = true; |
| 7287 | |
| 7288 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 7289 | return -ENOENT; |
| 7290 | |
| 7291 | return 0; |
| 7292 | } |
| 7293 | |
| 7294 | /** |
| 7295 | * i40e_probe - Device initialization routine |
| 7296 | * @pdev: PCI device information struct |
| 7297 | * @ent: entry in i40e_pci_tbl |
| 7298 | * |
| 7299 | * i40e_probe initializes a pf identified by a pci_dev structure. |
| 7300 | * The OS initialization, configuring of the pf private structure, |
| 7301 | * and a hardware reset occur. |
| 7302 | * |
| 7303 | * Returns 0 on success, negative on failure |
| 7304 | **/ |
| 7305 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 7306 | { |
| 7307 | struct i40e_driver_version dv; |
| 7308 | struct i40e_pf *pf; |
| 7309 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 7310 | static u16 pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7311 | int err = 0; |
| 7312 | u32 len; |
| 7313 | |
| 7314 | err = pci_enable_device_mem(pdev); |
| 7315 | if (err) |
| 7316 | return err; |
| 7317 | |
| 7318 | /* set up for high or low dma */ |
| 7319 | if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) { |
| 7320 | /* coherent mask for the same size will always succeed if |
| 7321 | * dma_set_mask does |
| 7322 | */ |
| 7323 | dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); |
| 7324 | } else if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) { |
| 7325 | dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); |
| 7326 | } else { |
| 7327 | dev_err(&pdev->dev, "DMA configuration failed: %d\n", err); |
| 7328 | err = -EIO; |
| 7329 | goto err_dma; |
| 7330 | } |
| 7331 | |
| 7332 | /* set up pci connections */ |
| 7333 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 7334 | IORESOURCE_MEM), i40e_driver_name); |
| 7335 | if (err) { |
| 7336 | dev_info(&pdev->dev, |
| 7337 | "pci_request_selected_regions failed %d\n", err); |
| 7338 | goto err_pci_reg; |
| 7339 | } |
| 7340 | |
| 7341 | pci_enable_pcie_error_reporting(pdev); |
| 7342 | pci_set_master(pdev); |
| 7343 | |
| 7344 | /* Now that we have a PCI connection, we need to do the |
| 7345 | * low level device setup. This is primarily setting up |
| 7346 | * the Admin Queue structures and then querying for the |
| 7347 | * device's current profile information. |
| 7348 | */ |
| 7349 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 7350 | if (!pf) { |
| 7351 | err = -ENOMEM; |
| 7352 | goto err_pf_alloc; |
| 7353 | } |
| 7354 | pf->next_vsi = 0; |
| 7355 | pf->pdev = pdev; |
| 7356 | set_bit(__I40E_DOWN, &pf->state); |
| 7357 | |
| 7358 | hw = &pf->hw; |
| 7359 | hw->back = pf; |
| 7360 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
| 7361 | pci_resource_len(pdev, 0)); |
| 7362 | if (!hw->hw_addr) { |
| 7363 | err = -EIO; |
| 7364 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 7365 | (unsigned int)pci_resource_start(pdev, 0), |
| 7366 | (unsigned int)pci_resource_len(pdev, 0), err); |
| 7367 | goto err_ioremap; |
| 7368 | } |
| 7369 | hw->vendor_id = pdev->vendor; |
| 7370 | hw->device_id = pdev->device; |
| 7371 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 7372 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 7373 | hw->subsystem_device_id = pdev->subsystem_device; |
| 7374 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 7375 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 7376 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7377 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 7378 | /* do a special CORER for clearing PXE mode once at init */ |
| 7379 | if (hw->revision_id == 0 && |
| 7380 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 7381 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 7382 | i40e_flush(hw); |
| 7383 | msleep(200); |
| 7384 | pf->corer_count++; |
| 7385 | |
| 7386 | i40e_clear_pxe_mode(hw); |
| 7387 | } |
| 7388 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7389 | /* Reset here to make sure all is clean and to define PF 'n' */ |
| 7390 | err = i40e_pf_reset(hw); |
| 7391 | if (err) { |
| 7392 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 7393 | goto err_pf_reset; |
| 7394 | } |
| 7395 | pf->pfr_count++; |
| 7396 | |
| 7397 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 7398 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 7399 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 7400 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 7401 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
| 7402 | snprintf(pf->misc_int_name, sizeof(pf->misc_int_name) - 1, |
| 7403 | "%s-pf%d:misc", |
| 7404 | dev_driver_string(&pf->pdev->dev), pf->hw.pf_id); |
| 7405 | |
| 7406 | err = i40e_init_shared_code(hw); |
| 7407 | if (err) { |
| 7408 | dev_info(&pdev->dev, "init_shared_code failed: %d\n", err); |
| 7409 | goto err_pf_reset; |
| 7410 | } |
| 7411 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 7412 | /* set up a default setting for link flow control */ |
| 7413 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 7414 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7415 | err = i40e_init_adminq(hw); |
| 7416 | dev_info(&pdev->dev, "%s\n", i40e_fw_version_str(hw)); |
Anjali Singhai jain | fe31070 | 2013-11-16 10:00:37 +0000 | [diff] [blame] | 7417 | if (((hw->nvm.version & I40E_NVM_VERSION_HI_MASK) |
| 7418 | >> I40E_NVM_VERSION_HI_SHIFT) != I40E_CURRENT_NVM_VERSION_HI) { |
| 7419 | dev_info(&pdev->dev, |
| 7420 | "warning: NVM version not supported, supported version: %02x.%02x\n", |
| 7421 | I40E_CURRENT_NVM_VERSION_HI, |
| 7422 | I40E_CURRENT_NVM_VERSION_LO); |
| 7423 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7424 | if (err) { |
| 7425 | dev_info(&pdev->dev, |
| 7426 | "init_adminq failed: %d expecting API %02x.%02x\n", |
| 7427 | err, |
| 7428 | I40E_FW_API_VERSION_MAJOR, I40E_FW_API_VERSION_MINOR); |
| 7429 | goto err_pf_reset; |
| 7430 | } |
| 7431 | |
| 7432 | err = i40e_get_capabilities(pf); |
| 7433 | if (err) |
| 7434 | goto err_adminq_setup; |
| 7435 | |
| 7436 | err = i40e_sw_init(pf); |
| 7437 | if (err) { |
| 7438 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 7439 | goto err_sw_init; |
| 7440 | } |
| 7441 | |
| 7442 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 7443 | hw->func_caps.num_rx_qp, |
| 7444 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 7445 | if (err) { |
| 7446 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 7447 | goto err_init_lan_hmc; |
| 7448 | } |
| 7449 | |
| 7450 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 7451 | if (err) { |
| 7452 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 7453 | err = -ENOENT; |
| 7454 | goto err_configure_lan_hmc; |
| 7455 | } |
| 7456 | |
| 7457 | i40e_get_mac_addr(hw, hw->mac.addr); |
| 7458 | if (i40e_validate_mac_addr(hw->mac.addr)) { |
| 7459 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 7460 | err = -EIO; |
| 7461 | goto err_mac_addr; |
| 7462 | } |
| 7463 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
| 7464 | memcpy(hw->mac.perm_addr, hw->mac.addr, ETH_ALEN); |
| 7465 | |
| 7466 | pci_set_drvdata(pdev, pf); |
| 7467 | pci_save_state(pdev); |
| 7468 | |
| 7469 | /* set up periodic task facility */ |
| 7470 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 7471 | pf->service_timer_period = HZ; |
| 7472 | |
| 7473 | INIT_WORK(&pf->service_task, i40e_service_task); |
| 7474 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 7475 | pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; |
| 7476 | pf->link_check_timeout = jiffies; |
| 7477 | |
| 7478 | /* set up the main switch operations */ |
| 7479 | i40e_determine_queue_usage(pf); |
| 7480 | i40e_init_interrupt_scheme(pf); |
| 7481 | |
| 7482 | /* Set up the *vsi struct based on the number of VSIs in the HW, |
| 7483 | * and set up our local tracking of the MAIN PF vsi. |
| 7484 | */ |
| 7485 | len = sizeof(struct i40e_vsi *) * pf->hw.func_caps.num_vsis; |
| 7486 | pf->vsi = kzalloc(len, GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 7487 | if (!pf->vsi) { |
| 7488 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7489 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 7490 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7491 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame^] | 7492 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7493 | if (err) { |
| 7494 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 7495 | goto err_vsis; |
| 7496 | } |
| 7497 | |
| 7498 | /* The main driver is (mostly) up and happy. We need to set this state |
| 7499 | * before setting up the misc vector or we get a race and the vector |
| 7500 | * ends up disabled forever. |
| 7501 | */ |
| 7502 | clear_bit(__I40E_DOWN, &pf->state); |
| 7503 | |
| 7504 | /* In case of MSIX we are going to setup the misc vector right here |
| 7505 | * to handle admin queue events etc. In case of legacy and MSI |
| 7506 | * the misc functionality and queue processing is combined in |
| 7507 | * the same vector and that gets setup at open. |
| 7508 | */ |
| 7509 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 7510 | err = i40e_setup_misc_vector(pf); |
| 7511 | if (err) { |
| 7512 | dev_info(&pdev->dev, |
| 7513 | "setup of misc vector failed: %d\n", err); |
| 7514 | goto err_vsis; |
| 7515 | } |
| 7516 | } |
| 7517 | |
| 7518 | /* prep for VF support */ |
| 7519 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 7520 | (pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
| 7521 | u32 val; |
| 7522 | |
| 7523 | /* disable link interrupts for VFs */ |
| 7524 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 7525 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 7526 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 7527 | i40e_flush(hw); |
| 7528 | } |
| 7529 | |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 7530 | pfs_found++; |
| 7531 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7532 | i40e_dbg_pf_init(pf); |
| 7533 | |
| 7534 | /* tell the firmware that we're starting */ |
| 7535 | dv.major_version = DRV_VERSION_MAJOR; |
| 7536 | dv.minor_version = DRV_VERSION_MINOR; |
| 7537 | dv.build_version = DRV_VERSION_BUILD; |
| 7538 | dv.subbuild_version = 0; |
| 7539 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 7540 | |
| 7541 | /* since everything's happy, start the service_task timer */ |
| 7542 | mod_timer(&pf->service_timer, |
| 7543 | round_jiffies(jiffies + pf->service_timer_period)); |
| 7544 | |
| 7545 | return 0; |
| 7546 | |
| 7547 | /* Unwind what we've done if something failed in the setup */ |
| 7548 | err_vsis: |
| 7549 | set_bit(__I40E_DOWN, &pf->state); |
| 7550 | err_switch_setup: |
| 7551 | i40e_clear_interrupt_scheme(pf); |
| 7552 | kfree(pf->vsi); |
| 7553 | del_timer_sync(&pf->service_timer); |
| 7554 | err_mac_addr: |
| 7555 | err_configure_lan_hmc: |
| 7556 | (void)i40e_shutdown_lan_hmc(hw); |
| 7557 | err_init_lan_hmc: |
| 7558 | kfree(pf->qp_pile); |
| 7559 | kfree(pf->irq_pile); |
| 7560 | err_sw_init: |
| 7561 | err_adminq_setup: |
| 7562 | (void)i40e_shutdown_adminq(hw); |
| 7563 | err_pf_reset: |
| 7564 | iounmap(hw->hw_addr); |
| 7565 | err_ioremap: |
| 7566 | kfree(pf); |
| 7567 | err_pf_alloc: |
| 7568 | pci_disable_pcie_error_reporting(pdev); |
| 7569 | pci_release_selected_regions(pdev, |
| 7570 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 7571 | err_pci_reg: |
| 7572 | err_dma: |
| 7573 | pci_disable_device(pdev); |
| 7574 | return err; |
| 7575 | } |
| 7576 | |
| 7577 | /** |
| 7578 | * i40e_remove - Device removal routine |
| 7579 | * @pdev: PCI device information struct |
| 7580 | * |
| 7581 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 7582 | * that is should release a PCI device. This could be caused by a |
| 7583 | * Hot-Plug event, or because the driver is going to be removed from |
| 7584 | * memory. |
| 7585 | **/ |
| 7586 | static void i40e_remove(struct pci_dev *pdev) |
| 7587 | { |
| 7588 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 7589 | i40e_status ret_code; |
| 7590 | u32 reg; |
| 7591 | int i; |
| 7592 | |
| 7593 | i40e_dbg_pf_exit(pf); |
| 7594 | |
| 7595 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 7596 | i40e_free_vfs(pf); |
| 7597 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 7598 | } |
| 7599 | |
| 7600 | /* no more scheduling of any task */ |
| 7601 | set_bit(__I40E_DOWN, &pf->state); |
| 7602 | del_timer_sync(&pf->service_timer); |
| 7603 | cancel_work_sync(&pf->service_task); |
| 7604 | |
| 7605 | i40e_fdir_teardown(pf); |
| 7606 | |
| 7607 | /* If there is a switch structure or any orphans, remove them. |
| 7608 | * This will leave only the PF's VSI remaining. |
| 7609 | */ |
| 7610 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 7611 | if (!pf->veb[i]) |
| 7612 | continue; |
| 7613 | |
| 7614 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 7615 | pf->veb[i]->uplink_seid == 0) |
| 7616 | i40e_switch_branch_release(pf->veb[i]); |
| 7617 | } |
| 7618 | |
| 7619 | /* Now we can shutdown the PF's VSI, just before we kill |
| 7620 | * adminq and hmc. |
| 7621 | */ |
| 7622 | if (pf->vsi[pf->lan_vsi]) |
| 7623 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 7624 | |
| 7625 | i40e_stop_misc_vector(pf); |
| 7626 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 7627 | synchronize_irq(pf->msix_entries[0].vector); |
| 7628 | free_irq(pf->msix_entries[0].vector, pf); |
| 7629 | } |
| 7630 | |
| 7631 | /* shutdown and destroy the HMC */ |
| 7632 | ret_code = i40e_shutdown_lan_hmc(&pf->hw); |
| 7633 | if (ret_code) |
| 7634 | dev_warn(&pdev->dev, |
| 7635 | "Failed to destroy the HMC resources: %d\n", ret_code); |
| 7636 | |
| 7637 | /* shutdown the adminq */ |
| 7638 | i40e_aq_queue_shutdown(&pf->hw, true); |
| 7639 | ret_code = i40e_shutdown_adminq(&pf->hw); |
| 7640 | if (ret_code) |
| 7641 | dev_warn(&pdev->dev, |
| 7642 | "Failed to destroy the Admin Queue resources: %d\n", |
| 7643 | ret_code); |
| 7644 | |
| 7645 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 7646 | i40e_clear_interrupt_scheme(pf); |
| 7647 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 7648 | if (pf->vsi[i]) { |
| 7649 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 7650 | i40e_vsi_clear(pf->vsi[i]); |
| 7651 | pf->vsi[i] = NULL; |
| 7652 | } |
| 7653 | } |
| 7654 | |
| 7655 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 7656 | kfree(pf->veb[i]); |
| 7657 | pf->veb[i] = NULL; |
| 7658 | } |
| 7659 | |
| 7660 | kfree(pf->qp_pile); |
| 7661 | kfree(pf->irq_pile); |
| 7662 | kfree(pf->sw_config); |
| 7663 | kfree(pf->vsi); |
| 7664 | |
| 7665 | /* force a PF reset to clean anything leftover */ |
| 7666 | reg = rd32(&pf->hw, I40E_PFGEN_CTRL); |
| 7667 | wr32(&pf->hw, I40E_PFGEN_CTRL, (reg | I40E_PFGEN_CTRL_PFSWR_MASK)); |
| 7668 | i40e_flush(&pf->hw); |
| 7669 | |
| 7670 | iounmap(pf->hw.hw_addr); |
| 7671 | kfree(pf); |
| 7672 | pci_release_selected_regions(pdev, |
| 7673 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 7674 | |
| 7675 | pci_disable_pcie_error_reporting(pdev); |
| 7676 | pci_disable_device(pdev); |
| 7677 | } |
| 7678 | |
| 7679 | /** |
| 7680 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 7681 | * @pdev: PCI device information struct |
| 7682 | * |
| 7683 | * Called to warn that something happened and the error handling steps |
| 7684 | * are in progress. Allows the driver to quiesce things, be ready for |
| 7685 | * remediation. |
| 7686 | **/ |
| 7687 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 7688 | enum pci_channel_state error) |
| 7689 | { |
| 7690 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 7691 | |
| 7692 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 7693 | |
| 7694 | /* shutdown all operations */ |
| 7695 | i40e_pf_quiesce_all_vsi(pf); |
| 7696 | |
| 7697 | /* Request a slot reset */ |
| 7698 | return PCI_ERS_RESULT_NEED_RESET; |
| 7699 | } |
| 7700 | |
| 7701 | /** |
| 7702 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 7703 | * @pdev: PCI device information struct |
| 7704 | * |
| 7705 | * Called to find if the driver can work with the device now that |
| 7706 | * the pci slot has been reset. If a basic connection seems good |
| 7707 | * (registers are readable and have sane content) then return a |
| 7708 | * happy little PCI_ERS_RESULT_xxx. |
| 7709 | **/ |
| 7710 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 7711 | { |
| 7712 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 7713 | pci_ers_result_t result; |
| 7714 | int err; |
| 7715 | u32 reg; |
| 7716 | |
| 7717 | dev_info(&pdev->dev, "%s\n", __func__); |
| 7718 | if (pci_enable_device_mem(pdev)) { |
| 7719 | dev_info(&pdev->dev, |
| 7720 | "Cannot re-enable PCI device after reset.\n"); |
| 7721 | result = PCI_ERS_RESULT_DISCONNECT; |
| 7722 | } else { |
| 7723 | pci_set_master(pdev); |
| 7724 | pci_restore_state(pdev); |
| 7725 | pci_save_state(pdev); |
| 7726 | pci_wake_from_d3(pdev, false); |
| 7727 | |
| 7728 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 7729 | if (reg == 0) |
| 7730 | result = PCI_ERS_RESULT_RECOVERED; |
| 7731 | else |
| 7732 | result = PCI_ERS_RESULT_DISCONNECT; |
| 7733 | } |
| 7734 | |
| 7735 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 7736 | if (err) { |
| 7737 | dev_info(&pdev->dev, |
| 7738 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 7739 | err); |
| 7740 | /* non-fatal, continue */ |
| 7741 | } |
| 7742 | |
| 7743 | return result; |
| 7744 | } |
| 7745 | |
| 7746 | /** |
| 7747 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 7748 | * @pdev: PCI device information struct |
| 7749 | * |
| 7750 | * Called to allow the driver to bring things back up after PCI error |
| 7751 | * and/or reset recovery has finished. |
| 7752 | **/ |
| 7753 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 7754 | { |
| 7755 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 7756 | |
| 7757 | dev_info(&pdev->dev, "%s\n", __func__); |
| 7758 | i40e_handle_reset_warning(pf); |
| 7759 | } |
| 7760 | |
| 7761 | static const struct pci_error_handlers i40e_err_handler = { |
| 7762 | .error_detected = i40e_pci_error_detected, |
| 7763 | .slot_reset = i40e_pci_error_slot_reset, |
| 7764 | .resume = i40e_pci_error_resume, |
| 7765 | }; |
| 7766 | |
| 7767 | static struct pci_driver i40e_driver = { |
| 7768 | .name = i40e_driver_name, |
| 7769 | .id_table = i40e_pci_tbl, |
| 7770 | .probe = i40e_probe, |
| 7771 | .remove = i40e_remove, |
| 7772 | .err_handler = &i40e_err_handler, |
| 7773 | .sriov_configure = i40e_pci_sriov_configure, |
| 7774 | }; |
| 7775 | |
| 7776 | /** |
| 7777 | * i40e_init_module - Driver registration routine |
| 7778 | * |
| 7779 | * i40e_init_module is the first routine called when the driver is |
| 7780 | * loaded. All it does is register with the PCI subsystem. |
| 7781 | **/ |
| 7782 | static int __init i40e_init_module(void) |
| 7783 | { |
| 7784 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 7785 | i40e_driver_string, i40e_driver_version_str); |
| 7786 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
| 7787 | i40e_dbg_init(); |
| 7788 | return pci_register_driver(&i40e_driver); |
| 7789 | } |
| 7790 | module_init(i40e_init_module); |
| 7791 | |
| 7792 | /** |
| 7793 | * i40e_exit_module - Driver exit cleanup routine |
| 7794 | * |
| 7795 | * i40e_exit_module is called just before the driver is removed |
| 7796 | * from memory. |
| 7797 | **/ |
| 7798 | static void __exit i40e_exit_module(void) |
| 7799 | { |
| 7800 | pci_unregister_driver(&i40e_driver); |
| 7801 | i40e_dbg_exit(); |
| 7802 | } |
| 7803 | module_exit(i40e_exit_module); |