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 | 9f65e15b | 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 | 9f65e15b | 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 | 9f65e15b | 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 | 9f65e15b | 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 | 9f65e15b | 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 | 9f65e15b | 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 | 9f65e15b | 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 | 13fd977 | 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 | 9f65e15b | 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 | 9f65e15b | 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 | 9f65e15b | 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 | 9f65e15b | 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 | 9f65e15b | 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 | 9f65e15b | 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 | /** |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame^] | 4135 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 4136 | * @pf: board private structure |
| 4137 | * @reset_flags: which reset is requested |
| 4138 | * |
| 4139 | **/ |
| 4140 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 4141 | { |
| 4142 | rtnl_lock(); |
| 4143 | i40e_do_reset(pf, reset_flags); |
| 4144 | rtnl_unlock(); |
| 4145 | } |
| 4146 | |
| 4147 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4148 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 4149 | * @pf: board private structure |
| 4150 | * @e: event info posted on ARQ |
| 4151 | * |
| 4152 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 4153 | * and VF queues |
| 4154 | **/ |
| 4155 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 4156 | struct i40e_arq_event_info *e) |
| 4157 | { |
| 4158 | struct i40e_aqc_lan_overflow *data = |
| 4159 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 4160 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 4161 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 4162 | struct i40e_hw *hw = &pf->hw; |
| 4163 | struct i40e_vf *vf; |
| 4164 | u16 vf_id; |
| 4165 | |
| 4166 | dev_info(&pf->pdev->dev, "%s: Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 4167 | __func__, queue, qtx_ctl); |
| 4168 | |
| 4169 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 4170 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 4171 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 4172 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 4173 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 4174 | vf_id -= hw->func_caps.vf_base_id; |
| 4175 | vf = &pf->vf[vf_id]; |
| 4176 | i40e_vc_notify_vf_reset(vf); |
| 4177 | /* Allow VF to process pending reset notification */ |
| 4178 | msleep(20); |
| 4179 | i40e_reset_vf(vf, false); |
| 4180 | } |
| 4181 | } |
| 4182 | |
| 4183 | /** |
| 4184 | * i40e_service_event_complete - Finish up the service event |
| 4185 | * @pf: board private structure |
| 4186 | **/ |
| 4187 | static void i40e_service_event_complete(struct i40e_pf *pf) |
| 4188 | { |
| 4189 | BUG_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state)); |
| 4190 | |
| 4191 | /* flush memory to make sure state is correct before next watchog */ |
| 4192 | smp_mb__before_clear_bit(); |
| 4193 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 4194 | } |
| 4195 | |
| 4196 | /** |
| 4197 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 4198 | * @pf: board private structure |
| 4199 | **/ |
| 4200 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 4201 | { |
| 4202 | if (!(pf->flags & I40E_FLAG_FDIR_REQUIRES_REINIT)) |
| 4203 | return; |
| 4204 | |
| 4205 | pf->flags &= ~I40E_FLAG_FDIR_REQUIRES_REINIT; |
| 4206 | |
| 4207 | /* if interface is down do nothing */ |
| 4208 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 4209 | return; |
| 4210 | } |
| 4211 | |
| 4212 | /** |
| 4213 | * i40e_vsi_link_event - notify VSI of a link event |
| 4214 | * @vsi: vsi to be notified |
| 4215 | * @link_up: link up or down |
| 4216 | **/ |
| 4217 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 4218 | { |
| 4219 | if (!vsi) |
| 4220 | return; |
| 4221 | |
| 4222 | switch (vsi->type) { |
| 4223 | case I40E_VSI_MAIN: |
| 4224 | if (!vsi->netdev || !vsi->netdev_registered) |
| 4225 | break; |
| 4226 | |
| 4227 | if (link_up) { |
| 4228 | netif_carrier_on(vsi->netdev); |
| 4229 | netif_tx_wake_all_queues(vsi->netdev); |
| 4230 | } else { |
| 4231 | netif_carrier_off(vsi->netdev); |
| 4232 | netif_tx_stop_all_queues(vsi->netdev); |
| 4233 | } |
| 4234 | break; |
| 4235 | |
| 4236 | case I40E_VSI_SRIOV: |
| 4237 | break; |
| 4238 | |
| 4239 | case I40E_VSI_VMDQ2: |
| 4240 | case I40E_VSI_CTRL: |
| 4241 | case I40E_VSI_MIRROR: |
| 4242 | default: |
| 4243 | /* there is no notification for other VSIs */ |
| 4244 | break; |
| 4245 | } |
| 4246 | } |
| 4247 | |
| 4248 | /** |
| 4249 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 4250 | * @veb: veb to be notified |
| 4251 | * @link_up: link up or down |
| 4252 | **/ |
| 4253 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 4254 | { |
| 4255 | struct i40e_pf *pf; |
| 4256 | int i; |
| 4257 | |
| 4258 | if (!veb || !veb->pf) |
| 4259 | return; |
| 4260 | pf = veb->pf; |
| 4261 | |
| 4262 | /* depth first... */ |
| 4263 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 4264 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 4265 | i40e_veb_link_event(pf->veb[i], link_up); |
| 4266 | |
| 4267 | /* ... now the local VSIs */ |
| 4268 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) |
| 4269 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 4270 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 4271 | } |
| 4272 | |
| 4273 | /** |
| 4274 | * i40e_link_event - Update netif_carrier status |
| 4275 | * @pf: board private structure |
| 4276 | **/ |
| 4277 | static void i40e_link_event(struct i40e_pf *pf) |
| 4278 | { |
| 4279 | bool new_link, old_link; |
| 4280 | |
| 4281 | new_link = (pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP); |
| 4282 | old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP); |
| 4283 | |
| 4284 | if (new_link == old_link) |
| 4285 | return; |
| 4286 | |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 4287 | if (!test_bit(__I40E_DOWN, &pf->vsi[pf->lan_vsi]->state)) |
| 4288 | netdev_info(pf->vsi[pf->lan_vsi]->netdev, |
| 4289 | "NIC Link is %s\n", (new_link ? "Up" : "Down")); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4290 | |
| 4291 | /* Notify the base of the switch tree connected to |
| 4292 | * the link. Floating VEBs are not notified. |
| 4293 | */ |
| 4294 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 4295 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 4296 | else |
| 4297 | i40e_vsi_link_event(pf->vsi[pf->lan_vsi], new_link); |
| 4298 | |
| 4299 | if (pf->vf) |
| 4300 | i40e_vc_notify_link_state(pf); |
| 4301 | } |
| 4302 | |
| 4303 | /** |
| 4304 | * i40e_check_hang_subtask - Check for hung queues and dropped interrupts |
| 4305 | * @pf: board private structure |
| 4306 | * |
| 4307 | * Set the per-queue flags to request a check for stuck queues in the irq |
| 4308 | * clean functions, then force interrupts to be sure the irq clean is called. |
| 4309 | **/ |
| 4310 | static void i40e_check_hang_subtask(struct i40e_pf *pf) |
| 4311 | { |
| 4312 | int i, v; |
| 4313 | |
| 4314 | /* If we're down or resetting, just bail */ |
| 4315 | if (test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 4316 | return; |
| 4317 | |
| 4318 | /* for each VSI/netdev |
| 4319 | * for each Tx queue |
| 4320 | * set the check flag |
| 4321 | * for each q_vector |
| 4322 | * force an interrupt |
| 4323 | */ |
| 4324 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 4325 | struct i40e_vsi *vsi = pf->vsi[v]; |
| 4326 | int armed = 0; |
| 4327 | |
| 4328 | if (!pf->vsi[v] || |
| 4329 | test_bit(__I40E_DOWN, &vsi->state) || |
| 4330 | (vsi->netdev && !netif_carrier_ok(vsi->netdev))) |
| 4331 | continue; |
| 4332 | |
| 4333 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 4334 | set_check_for_tx_hang(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4335 | if (test_bit(__I40E_HANG_CHECK_ARMED, |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 4336 | &vsi->tx_rings[i]->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4337 | armed++; |
| 4338 | } |
| 4339 | |
| 4340 | if (armed) { |
| 4341 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
| 4342 | wr32(&vsi->back->hw, I40E_PFINT_DYN_CTL0, |
| 4343 | (I40E_PFINT_DYN_CTL0_INTENA_MASK | |
| 4344 | I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK)); |
| 4345 | } else { |
| 4346 | u16 vec = vsi->base_vector - 1; |
| 4347 | u32 val = (I40E_PFINT_DYN_CTLN_INTENA_MASK | |
| 4348 | I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK); |
| 4349 | for (i = 0; i < vsi->num_q_vectors; i++, vec++) |
| 4350 | wr32(&vsi->back->hw, |
| 4351 | I40E_PFINT_DYN_CTLN(vec), val); |
| 4352 | } |
| 4353 | i40e_flush(&vsi->back->hw); |
| 4354 | } |
| 4355 | } |
| 4356 | } |
| 4357 | |
| 4358 | /** |
| 4359 | * i40e_watchdog_subtask - Check and bring link up |
| 4360 | * @pf: board private structure |
| 4361 | **/ |
| 4362 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 4363 | { |
| 4364 | int i; |
| 4365 | |
| 4366 | /* if interface is down do nothing */ |
| 4367 | if (test_bit(__I40E_DOWN, &pf->state) || |
| 4368 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 4369 | return; |
| 4370 | |
| 4371 | /* Update the stats for active netdevs so the network stack |
| 4372 | * can look at updated numbers whenever it cares to |
| 4373 | */ |
| 4374 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) |
| 4375 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 4376 | i40e_update_stats(pf->vsi[i]); |
| 4377 | |
| 4378 | /* Update the stats for the active switching components */ |
| 4379 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 4380 | if (pf->veb[i]) |
| 4381 | i40e_update_veb_stats(pf->veb[i]); |
| 4382 | } |
| 4383 | |
| 4384 | /** |
| 4385 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 4386 | * @pf: board private structure |
| 4387 | **/ |
| 4388 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 4389 | { |
| 4390 | u32 reset_flags = 0; |
| 4391 | |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame^] | 4392 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4393 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { |
| 4394 | reset_flags |= (1 << __I40E_REINIT_REQUESTED); |
| 4395 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 4396 | } |
| 4397 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { |
| 4398 | reset_flags |= (1 << __I40E_PF_RESET_REQUESTED); |
| 4399 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 4400 | } |
| 4401 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { |
| 4402 | reset_flags |= (1 << __I40E_CORE_RESET_REQUESTED); |
| 4403 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 4404 | } |
| 4405 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { |
| 4406 | reset_flags |= (1 << __I40E_GLOBAL_RESET_REQUESTED); |
| 4407 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 4408 | } |
| 4409 | |
| 4410 | /* If there's a recovery already waiting, it takes |
| 4411 | * precedence before starting a new reset sequence. |
| 4412 | */ |
| 4413 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { |
| 4414 | i40e_handle_reset_warning(pf); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame^] | 4415 | goto unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4416 | } |
| 4417 | |
| 4418 | /* If we're already down or resetting, just bail */ |
| 4419 | if (reset_flags && |
| 4420 | !test_bit(__I40E_DOWN, &pf->state) && |
| 4421 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 4422 | i40e_do_reset(pf, reset_flags); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame^] | 4423 | |
| 4424 | unlock: |
| 4425 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4426 | } |
| 4427 | |
| 4428 | /** |
| 4429 | * i40e_handle_link_event - Handle link event |
| 4430 | * @pf: board private structure |
| 4431 | * @e: event info posted on ARQ |
| 4432 | **/ |
| 4433 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 4434 | struct i40e_arq_event_info *e) |
| 4435 | { |
| 4436 | struct i40e_hw *hw = &pf->hw; |
| 4437 | struct i40e_aqc_get_link_status *status = |
| 4438 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
| 4439 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; |
| 4440 | |
| 4441 | /* save off old link status information */ |
| 4442 | memcpy(&pf->hw.phy.link_info_old, hw_link_info, |
| 4443 | sizeof(pf->hw.phy.link_info_old)); |
| 4444 | |
| 4445 | /* update link status */ |
| 4446 | hw_link_info->phy_type = (enum i40e_aq_phy_type)status->phy_type; |
| 4447 | hw_link_info->link_speed = (enum i40e_aq_link_speed)status->link_speed; |
| 4448 | hw_link_info->link_info = status->link_info; |
| 4449 | hw_link_info->an_info = status->an_info; |
| 4450 | hw_link_info->ext_info = status->ext_info; |
| 4451 | hw_link_info->lse_enable = |
| 4452 | le16_to_cpu(status->command_flags) & |
| 4453 | I40E_AQ_LSE_ENABLE; |
| 4454 | |
| 4455 | /* process the event */ |
| 4456 | i40e_link_event(pf); |
| 4457 | |
| 4458 | /* Do a new status request to re-enable LSE reporting |
| 4459 | * and load new status information into the hw struct, |
| 4460 | * then see if the status changed while processing the |
| 4461 | * initial event. |
| 4462 | */ |
| 4463 | i40e_aq_get_link_info(&pf->hw, true, NULL, NULL); |
| 4464 | i40e_link_event(pf); |
| 4465 | } |
| 4466 | |
| 4467 | /** |
| 4468 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 4469 | * @pf: board private structure |
| 4470 | **/ |
| 4471 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 4472 | { |
| 4473 | struct i40e_arq_event_info event; |
| 4474 | struct i40e_hw *hw = &pf->hw; |
| 4475 | u16 pending, i = 0; |
| 4476 | i40e_status ret; |
| 4477 | u16 opcode; |
| 4478 | u32 val; |
| 4479 | |
| 4480 | if (!test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state)) |
| 4481 | return; |
| 4482 | |
| 4483 | event.msg_size = I40E_MAX_AQ_BUF_SIZE; |
| 4484 | event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL); |
| 4485 | if (!event.msg_buf) |
| 4486 | return; |
| 4487 | |
| 4488 | do { |
| 4489 | ret = i40e_clean_arq_element(hw, &event, &pending); |
| 4490 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) { |
| 4491 | dev_info(&pf->pdev->dev, "No ARQ event found\n"); |
| 4492 | break; |
| 4493 | } else if (ret) { |
| 4494 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 4495 | break; |
| 4496 | } |
| 4497 | |
| 4498 | opcode = le16_to_cpu(event.desc.opcode); |
| 4499 | switch (opcode) { |
| 4500 | |
| 4501 | case i40e_aqc_opc_get_link_status: |
| 4502 | i40e_handle_link_event(pf, &event); |
| 4503 | break; |
| 4504 | case i40e_aqc_opc_send_msg_to_pf: |
| 4505 | ret = i40e_vc_process_vf_msg(pf, |
| 4506 | le16_to_cpu(event.desc.retval), |
| 4507 | le32_to_cpu(event.desc.cookie_high), |
| 4508 | le32_to_cpu(event.desc.cookie_low), |
| 4509 | event.msg_buf, |
| 4510 | event.msg_size); |
| 4511 | break; |
| 4512 | case i40e_aqc_opc_lldp_update_mib: |
| 4513 | dev_info(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
| 4514 | break; |
| 4515 | case i40e_aqc_opc_event_lan_overflow: |
| 4516 | dev_info(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
| 4517 | i40e_handle_lan_overflow_event(pf, &event); |
| 4518 | break; |
| 4519 | default: |
| 4520 | dev_info(&pf->pdev->dev, |
| 4521 | "ARQ Error: Unknown event %d received\n", |
| 4522 | event.desc.opcode); |
| 4523 | break; |
| 4524 | } |
| 4525 | } while (pending && (i++ < pf->adminq_work_limit)); |
| 4526 | |
| 4527 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 4528 | /* re-enable Admin queue interrupt cause */ |
| 4529 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 4530 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 4531 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 4532 | i40e_flush(hw); |
| 4533 | |
| 4534 | kfree(event.msg_buf); |
| 4535 | } |
| 4536 | |
| 4537 | /** |
| 4538 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 4539 | * @veb: pointer to the VEB instance |
| 4540 | * |
| 4541 | * This is a recursive function that first builds the attached VSIs then |
| 4542 | * recurses in to build the next layer of VEB. We track the connections |
| 4543 | * through our own index numbers because the seid's from the HW could |
| 4544 | * change across the reset. |
| 4545 | **/ |
| 4546 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 4547 | { |
| 4548 | struct i40e_vsi *ctl_vsi = NULL; |
| 4549 | struct i40e_pf *pf = veb->pf; |
| 4550 | int v, veb_idx; |
| 4551 | int ret; |
| 4552 | |
| 4553 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
| 4554 | for (v = 0; v < pf->hw.func_caps.num_vsis && !ctl_vsi; v++) { |
| 4555 | if (pf->vsi[v] && |
| 4556 | pf->vsi[v]->veb_idx == veb->idx && |
| 4557 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 4558 | ctl_vsi = pf->vsi[v]; |
| 4559 | break; |
| 4560 | } |
| 4561 | } |
| 4562 | if (!ctl_vsi) { |
| 4563 | dev_info(&pf->pdev->dev, |
| 4564 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 4565 | ret = -ENOENT; |
| 4566 | goto end_reconstitute; |
| 4567 | } |
| 4568 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 4569 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 4570 | ret = i40e_add_vsi(ctl_vsi); |
| 4571 | if (ret) { |
| 4572 | dev_info(&pf->pdev->dev, |
| 4573 | "rebuild of owner VSI failed: %d\n", ret); |
| 4574 | goto end_reconstitute; |
| 4575 | } |
| 4576 | i40e_vsi_reset_stats(ctl_vsi); |
| 4577 | |
| 4578 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 4579 | ret = i40e_add_veb(veb, ctl_vsi); |
| 4580 | if (ret) |
| 4581 | goto end_reconstitute; |
| 4582 | |
| 4583 | /* create the remaining VSIs attached to this VEB */ |
| 4584 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 4585 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 4586 | continue; |
| 4587 | |
| 4588 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 4589 | struct i40e_vsi *vsi = pf->vsi[v]; |
| 4590 | vsi->uplink_seid = veb->seid; |
| 4591 | ret = i40e_add_vsi(vsi); |
| 4592 | if (ret) { |
| 4593 | dev_info(&pf->pdev->dev, |
| 4594 | "rebuild of vsi_idx %d failed: %d\n", |
| 4595 | v, ret); |
| 4596 | goto end_reconstitute; |
| 4597 | } |
| 4598 | i40e_vsi_reset_stats(vsi); |
| 4599 | } |
| 4600 | } |
| 4601 | |
| 4602 | /* create any VEBs attached to this VEB - RECURSION */ |
| 4603 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 4604 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 4605 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 4606 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 4607 | if (ret) |
| 4608 | break; |
| 4609 | } |
| 4610 | } |
| 4611 | |
| 4612 | end_reconstitute: |
| 4613 | return ret; |
| 4614 | } |
| 4615 | |
| 4616 | /** |
| 4617 | * i40e_get_capabilities - get info about the HW |
| 4618 | * @pf: the PF struct |
| 4619 | **/ |
| 4620 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 4621 | { |
| 4622 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 4623 | u16 data_size; |
| 4624 | int buf_len; |
| 4625 | int err; |
| 4626 | |
| 4627 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 4628 | do { |
| 4629 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 4630 | if (!cap_buf) |
| 4631 | return -ENOMEM; |
| 4632 | |
| 4633 | /* this loads the data into the hw struct for us */ |
| 4634 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 4635 | &data_size, |
| 4636 | i40e_aqc_opc_list_func_capabilities, |
| 4637 | NULL); |
| 4638 | /* data loaded, buffer no longer needed */ |
| 4639 | kfree(cap_buf); |
| 4640 | |
| 4641 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 4642 | /* retry with a larger buffer */ |
| 4643 | buf_len = data_size; |
| 4644 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 4645 | dev_info(&pf->pdev->dev, |
| 4646 | "capability discovery failed: aq=%d\n", |
| 4647 | pf->hw.aq.asq_last_status); |
| 4648 | return -ENODEV; |
| 4649 | } |
| 4650 | } while (err); |
| 4651 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 4652 | if (pf->hw.revision_id == 0 && pf->hw.func_caps.npar_enable) { |
| 4653 | pf->hw.func_caps.num_msix_vectors += 1; |
| 4654 | pf->hw.func_caps.num_tx_qp = |
| 4655 | min_t(int, pf->hw.func_caps.num_tx_qp, |
| 4656 | I40E_MAX_NPAR_QPS); |
| 4657 | } |
| 4658 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4659 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 4660 | dev_info(&pf->pdev->dev, |
| 4661 | "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", |
| 4662 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 4663 | pf->hw.func_caps.num_msix_vectors, |
| 4664 | pf->hw.func_caps.num_msix_vectors_vf, |
| 4665 | pf->hw.func_caps.fd_filters_guaranteed, |
| 4666 | pf->hw.func_caps.fd_filters_best_effort, |
| 4667 | pf->hw.func_caps.num_tx_qp, |
| 4668 | pf->hw.func_caps.num_vsis); |
| 4669 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 4670 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 4671 | + pf->hw.func_caps.num_vfs) |
| 4672 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 4673 | dev_info(&pf->pdev->dev, |
| 4674 | "got num_vsis %d, setting num_vsis to %d\n", |
| 4675 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 4676 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 4677 | } |
| 4678 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4679 | return 0; |
| 4680 | } |
| 4681 | |
| 4682 | /** |
| 4683 | * i40e_fdir_setup - initialize the Flow Director resources |
| 4684 | * @pf: board private structure |
| 4685 | **/ |
| 4686 | static void i40e_fdir_setup(struct i40e_pf *pf) |
| 4687 | { |
| 4688 | struct i40e_vsi *vsi; |
| 4689 | bool new_vsi = false; |
| 4690 | int err, i; |
| 4691 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 4692 | if (!(pf->flags & (I40E_FLAG_FDIR_ENABLED | |
| 4693 | I40E_FLAG_FDIR_ATR_ENABLED))) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4694 | return; |
| 4695 | |
| 4696 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
| 4697 | |
| 4698 | /* find existing or make new FDIR VSI */ |
| 4699 | vsi = NULL; |
| 4700 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) |
| 4701 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) |
| 4702 | vsi = pf->vsi[i]; |
| 4703 | if (!vsi) { |
| 4704 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, pf->mac_seid, 0); |
| 4705 | if (!vsi) { |
| 4706 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
| 4707 | pf->flags &= ~I40E_FLAG_FDIR_ENABLED; |
| 4708 | return; |
| 4709 | } |
| 4710 | new_vsi = true; |
| 4711 | } |
| 4712 | WARN_ON(vsi->base_queue != I40E_FDIR_RING); |
| 4713 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_rings); |
| 4714 | |
| 4715 | err = i40e_vsi_setup_tx_resources(vsi); |
| 4716 | if (!err) |
| 4717 | err = i40e_vsi_setup_rx_resources(vsi); |
| 4718 | if (!err) |
| 4719 | err = i40e_vsi_configure(vsi); |
| 4720 | if (!err && new_vsi) { |
| 4721 | char int_name[IFNAMSIZ + 9]; |
| 4722 | snprintf(int_name, sizeof(int_name) - 1, "%s-fdir", |
| 4723 | dev_driver_string(&pf->pdev->dev)); |
| 4724 | err = i40e_vsi_request_irq(vsi, int_name); |
| 4725 | } |
| 4726 | if (!err) |
| 4727 | err = i40e_up_complete(vsi); |
| 4728 | |
| 4729 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 4730 | } |
| 4731 | |
| 4732 | /** |
| 4733 | * i40e_fdir_teardown - release the Flow Director resources |
| 4734 | * @pf: board private structure |
| 4735 | **/ |
| 4736 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 4737 | { |
| 4738 | int i; |
| 4739 | |
| 4740 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 4741 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 4742 | i40e_vsi_release(pf->vsi[i]); |
| 4743 | break; |
| 4744 | } |
| 4745 | } |
| 4746 | } |
| 4747 | |
| 4748 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4749 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4750 | * @pf: board private structure |
| 4751 | * |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4752 | * Close up the VFs and other things in prep for pf Reset. |
| 4753 | **/ |
| 4754 | static int i40e_prep_for_reset(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4755 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4756 | struct i40e_hw *hw = &pf->hw; |
| 4757 | i40e_status ret; |
| 4758 | u32 v; |
| 4759 | |
| 4760 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 4761 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4762 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4763 | |
| 4764 | dev_info(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
| 4765 | |
| 4766 | i40e_vc_notify_reset(pf); |
| 4767 | |
| 4768 | /* quiesce the VSIs and their queues that are not already DOWN */ |
| 4769 | i40e_pf_quiesce_all_vsi(pf); |
| 4770 | |
| 4771 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 4772 | if (pf->vsi[v]) |
| 4773 | pf->vsi[v]->seid = 0; |
| 4774 | } |
| 4775 | |
| 4776 | i40e_shutdown_adminq(&pf->hw); |
| 4777 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4778 | /* call shutdown HMC */ |
| 4779 | ret = i40e_shutdown_lan_hmc(hw); |
| 4780 | if (ret) { |
| 4781 | dev_info(&pf->pdev->dev, "shutdown_lan_hmc failed: %d\n", ret); |
| 4782 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 4783 | } |
| 4784 | return ret; |
| 4785 | } |
| 4786 | |
| 4787 | /** |
| 4788 | * i40e_reset_and_rebuild - reset and rebuid using a saved config |
| 4789 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 4790 | * @reinit: if the Main VSI needs to re-initialized. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4791 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 4792 | 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] | 4793 | { |
| 4794 | struct i40e_driver_version dv; |
| 4795 | struct i40e_hw *hw = &pf->hw; |
| 4796 | i40e_status ret; |
| 4797 | u32 v; |
| 4798 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4799 | /* Now we wait for GRST to settle out. |
| 4800 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 4801 | * because the reset will make them disappear. |
| 4802 | */ |
| 4803 | ret = i40e_pf_reset(hw); |
| 4804 | if (ret) |
| 4805 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
| 4806 | pf->pfr_count++; |
| 4807 | |
| 4808 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 4809 | goto end_core_reset; |
| 4810 | dev_info(&pf->pdev->dev, "Rebuilding internal switch\n"); |
| 4811 | |
| 4812 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 4813 | ret = i40e_init_adminq(&pf->hw); |
| 4814 | if (ret) { |
| 4815 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, %d\n", ret); |
| 4816 | goto end_core_reset; |
| 4817 | } |
| 4818 | |
| 4819 | ret = i40e_get_capabilities(pf); |
| 4820 | if (ret) { |
| 4821 | dev_info(&pf->pdev->dev, "i40e_get_capabilities failed, %d\n", |
| 4822 | ret); |
| 4823 | goto end_core_reset; |
| 4824 | } |
| 4825 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4826 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 4827 | hw->func_caps.num_rx_qp, |
| 4828 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 4829 | if (ret) { |
| 4830 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 4831 | goto end_core_reset; |
| 4832 | } |
| 4833 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 4834 | if (ret) { |
| 4835 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 4836 | goto end_core_reset; |
| 4837 | } |
| 4838 | |
| 4839 | /* do basic switch setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 4840 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4841 | if (ret) |
| 4842 | goto end_core_reset; |
| 4843 | |
| 4844 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 4845 | * They are still in our local switch element arrays, so only |
| 4846 | * need to rebuild the switch model in the HW. |
| 4847 | * |
| 4848 | * If there were VEBs but the reconstitution failed, we'll try |
| 4849 | * try to recover minimal use by getting the basic PF VSI working. |
| 4850 | */ |
| 4851 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
| 4852 | dev_info(&pf->pdev->dev, "attempting to rebuild switch\n"); |
| 4853 | /* find the one VEB connected to the MAC, and find orphans */ |
| 4854 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 4855 | if (!pf->veb[v]) |
| 4856 | continue; |
| 4857 | |
| 4858 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 4859 | pf->veb[v]->uplink_seid == 0) { |
| 4860 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 4861 | |
| 4862 | if (!ret) |
| 4863 | continue; |
| 4864 | |
| 4865 | /* If Main VEB failed, we're in deep doodoo, |
| 4866 | * so give up rebuilding the switch and set up |
| 4867 | * for minimal rebuild of PF VSI. |
| 4868 | * If orphan failed, we'll report the error |
| 4869 | * but try to keep going. |
| 4870 | */ |
| 4871 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 4872 | dev_info(&pf->pdev->dev, |
| 4873 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 4874 | ret); |
| 4875 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 4876 | = pf->mac_seid; |
| 4877 | break; |
| 4878 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 4879 | dev_info(&pf->pdev->dev, |
| 4880 | "rebuild of orphan VEB failed: %d\n", |
| 4881 | ret); |
| 4882 | } |
| 4883 | } |
| 4884 | } |
| 4885 | } |
| 4886 | |
| 4887 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
| 4888 | dev_info(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
| 4889 | /* no VEB, so rebuild only the Main VSI */ |
| 4890 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 4891 | if (ret) { |
| 4892 | dev_info(&pf->pdev->dev, |
| 4893 | "rebuild of Main VSI failed: %d\n", ret); |
| 4894 | goto end_core_reset; |
| 4895 | } |
| 4896 | } |
| 4897 | |
| 4898 | /* reinit the misc interrupt */ |
| 4899 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4900 | ret = i40e_setup_misc_vector(pf); |
| 4901 | |
| 4902 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 4903 | i40e_pf_unquiesce_all_vsi(pf); |
| 4904 | |
| 4905 | /* tell the firmware that we're starting */ |
| 4906 | dv.major_version = DRV_VERSION_MAJOR; |
| 4907 | dv.minor_version = DRV_VERSION_MINOR; |
| 4908 | dv.build_version = DRV_VERSION_BUILD; |
| 4909 | dv.subbuild_version = 0; |
| 4910 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 4911 | |
| 4912 | dev_info(&pf->pdev->dev, "PF reset done\n"); |
| 4913 | |
| 4914 | end_core_reset: |
| 4915 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 4916 | } |
| 4917 | |
| 4918 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4919 | * i40e_handle_reset_warning - prep for the pf to reset, reset and rebuild |
| 4920 | * @pf: board private structure |
| 4921 | * |
| 4922 | * Close up the VFs and other things in prep for a Core Reset, |
| 4923 | * then get ready to rebuild the world. |
| 4924 | **/ |
| 4925 | static void i40e_handle_reset_warning(struct i40e_pf *pf) |
| 4926 | { |
| 4927 | i40e_status ret; |
| 4928 | |
| 4929 | ret = i40e_prep_for_reset(pf); |
| 4930 | if (!ret) |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 4931 | i40e_reset_and_rebuild(pf, false); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4932 | } |
| 4933 | |
| 4934 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4935 | * i40e_handle_mdd_event |
| 4936 | * @pf: pointer to the pf structure |
| 4937 | * |
| 4938 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 4939 | **/ |
| 4940 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 4941 | { |
| 4942 | struct i40e_hw *hw = &pf->hw; |
| 4943 | bool mdd_detected = false; |
| 4944 | struct i40e_vf *vf; |
| 4945 | u32 reg; |
| 4946 | int i; |
| 4947 | |
| 4948 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) |
| 4949 | return; |
| 4950 | |
| 4951 | /* find what triggered the MDD event */ |
| 4952 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 4953 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
| 4954 | u8 func = (reg & I40E_GL_MDET_TX_FUNCTION_MASK) |
| 4955 | >> I40E_GL_MDET_TX_FUNCTION_SHIFT; |
| 4956 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_SHIFT) |
| 4957 | >> I40E_GL_MDET_TX_EVENT_SHIFT; |
| 4958 | u8 queue = (reg & I40E_GL_MDET_TX_QUEUE_MASK) |
| 4959 | >> I40E_GL_MDET_TX_QUEUE_SHIFT; |
| 4960 | dev_info(&pf->pdev->dev, |
| 4961 | "Malicious Driver Detection TX event 0x%02x on q %d of function 0x%02x\n", |
| 4962 | event, queue, func); |
| 4963 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 4964 | mdd_detected = true; |
| 4965 | } |
| 4966 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 4967 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
| 4968 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) |
| 4969 | >> I40E_GL_MDET_RX_FUNCTION_SHIFT; |
| 4970 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_SHIFT) |
| 4971 | >> I40E_GL_MDET_RX_EVENT_SHIFT; |
| 4972 | u8 queue = (reg & I40E_GL_MDET_RX_QUEUE_MASK) |
| 4973 | >> I40E_GL_MDET_RX_QUEUE_SHIFT; |
| 4974 | dev_info(&pf->pdev->dev, |
| 4975 | "Malicious Driver Detection RX event 0x%02x on q %d of function 0x%02x\n", |
| 4976 | event, queue, func); |
| 4977 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 4978 | mdd_detected = true; |
| 4979 | } |
| 4980 | |
| 4981 | /* see if one of the VFs needs its hand slapped */ |
| 4982 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 4983 | vf = &(pf->vf[i]); |
| 4984 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 4985 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 4986 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 4987 | vf->num_mdd_events++; |
| 4988 | dev_info(&pf->pdev->dev, "MDD TX event on VF %d\n", i); |
| 4989 | } |
| 4990 | |
| 4991 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 4992 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 4993 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 4994 | vf->num_mdd_events++; |
| 4995 | dev_info(&pf->pdev->dev, "MDD RX event on VF %d\n", i); |
| 4996 | } |
| 4997 | |
| 4998 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 4999 | dev_info(&pf->pdev->dev, |
| 5000 | "Too many MDD events on VF %d, disabled\n", i); |
| 5001 | dev_info(&pf->pdev->dev, |
| 5002 | "Use PF Control I/F to re-enable the VF\n"); |
| 5003 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 5004 | } |
| 5005 | } |
| 5006 | |
| 5007 | /* re-enable mdd interrupt cause */ |
| 5008 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 5009 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 5010 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 5011 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 5012 | i40e_flush(hw); |
| 5013 | } |
| 5014 | |
| 5015 | /** |
| 5016 | * i40e_service_task - Run the driver's async subtasks |
| 5017 | * @work: pointer to work_struct containing our data |
| 5018 | **/ |
| 5019 | static void i40e_service_task(struct work_struct *work) |
| 5020 | { |
| 5021 | struct i40e_pf *pf = container_of(work, |
| 5022 | struct i40e_pf, |
| 5023 | service_task); |
| 5024 | unsigned long start_time = jiffies; |
| 5025 | |
| 5026 | i40e_reset_subtask(pf); |
| 5027 | i40e_handle_mdd_event(pf); |
| 5028 | i40e_vc_process_vflr_event(pf); |
| 5029 | i40e_watchdog_subtask(pf); |
| 5030 | i40e_fdir_reinit_subtask(pf); |
| 5031 | i40e_check_hang_subtask(pf); |
| 5032 | i40e_sync_filters_subtask(pf); |
| 5033 | i40e_clean_adminq_subtask(pf); |
| 5034 | |
| 5035 | i40e_service_event_complete(pf); |
| 5036 | |
| 5037 | /* If the tasks have taken longer than one timer cycle or there |
| 5038 | * is more work to be done, reschedule the service task now |
| 5039 | * rather than wait for the timer to tick again. |
| 5040 | */ |
| 5041 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
| 5042 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || |
| 5043 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || |
| 5044 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 5045 | i40e_service_event_schedule(pf); |
| 5046 | } |
| 5047 | |
| 5048 | /** |
| 5049 | * i40e_service_timer - timer callback |
| 5050 | * @data: pointer to PF struct |
| 5051 | **/ |
| 5052 | static void i40e_service_timer(unsigned long data) |
| 5053 | { |
| 5054 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 5055 | |
| 5056 | mod_timer(&pf->service_timer, |
| 5057 | round_jiffies(jiffies + pf->service_timer_period)); |
| 5058 | i40e_service_event_schedule(pf); |
| 5059 | } |
| 5060 | |
| 5061 | /** |
| 5062 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 5063 | * @vsi: the VSI being configured |
| 5064 | **/ |
| 5065 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 5066 | { |
| 5067 | struct i40e_pf *pf = vsi->back; |
| 5068 | |
| 5069 | switch (vsi->type) { |
| 5070 | case I40E_VSI_MAIN: |
| 5071 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 5072 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 5073 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 5074 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5075 | vsi->num_q_vectors = pf->num_lan_msix; |
| 5076 | else |
| 5077 | vsi->num_q_vectors = 1; |
| 5078 | |
| 5079 | break; |
| 5080 | |
| 5081 | case I40E_VSI_FDIR: |
| 5082 | vsi->alloc_queue_pairs = 1; |
| 5083 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 5084 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 5085 | vsi->num_q_vectors = 1; |
| 5086 | break; |
| 5087 | |
| 5088 | case I40E_VSI_VMDQ2: |
| 5089 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 5090 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 5091 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 5092 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 5093 | break; |
| 5094 | |
| 5095 | case I40E_VSI_SRIOV: |
| 5096 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 5097 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 5098 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 5099 | break; |
| 5100 | |
| 5101 | default: |
| 5102 | WARN_ON(1); |
| 5103 | return -ENODATA; |
| 5104 | } |
| 5105 | |
| 5106 | return 0; |
| 5107 | } |
| 5108 | |
| 5109 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5110 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 5111 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5112 | * @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] | 5113 | * |
| 5114 | * On error: returns error code (negative) |
| 5115 | * On success: returns 0 |
| 5116 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5117 | 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] | 5118 | { |
| 5119 | int size; |
| 5120 | int ret = 0; |
| 5121 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 5122 | /* allocate memory for both Tx and Rx ring pointers */ |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5123 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
| 5124 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 5125 | if (!vsi->tx_rings) |
| 5126 | return -ENOMEM; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5127 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
| 5128 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5129 | if (alloc_qvectors) { |
| 5130 | /* allocate memory for q_vector pointers */ |
| 5131 | size = sizeof(struct i40e_q_vectors *) * vsi->num_q_vectors; |
| 5132 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 5133 | if (!vsi->q_vectors) { |
| 5134 | ret = -ENOMEM; |
| 5135 | goto err_vectors; |
| 5136 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5137 | } |
| 5138 | return ret; |
| 5139 | |
| 5140 | err_vectors: |
| 5141 | kfree(vsi->tx_rings); |
| 5142 | return ret; |
| 5143 | } |
| 5144 | |
| 5145 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5146 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 5147 | * @pf: board private structure |
| 5148 | * @type: type of VSI |
| 5149 | * |
| 5150 | * On error: returns error code (negative) |
| 5151 | * On success: returns vsi index in PF (positive) |
| 5152 | **/ |
| 5153 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 5154 | { |
| 5155 | int ret = -ENODEV; |
| 5156 | struct i40e_vsi *vsi; |
| 5157 | int vsi_idx; |
| 5158 | int i; |
| 5159 | |
| 5160 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 5161 | mutex_lock(&pf->switch_mutex); |
| 5162 | |
| 5163 | /* VSI list may be fragmented if VSI creation/destruction has |
| 5164 | * been happening. We can afford to do a quick scan to look |
| 5165 | * for any free VSIs in the list. |
| 5166 | * |
| 5167 | * find next empty vsi slot, looping back around if necessary |
| 5168 | */ |
| 5169 | i = pf->next_vsi; |
| 5170 | while (i < pf->hw.func_caps.num_vsis && pf->vsi[i]) |
| 5171 | i++; |
| 5172 | if (i >= pf->hw.func_caps.num_vsis) { |
| 5173 | i = 0; |
| 5174 | while (i < pf->next_vsi && pf->vsi[i]) |
| 5175 | i++; |
| 5176 | } |
| 5177 | |
| 5178 | if (i < pf->hw.func_caps.num_vsis && !pf->vsi[i]) { |
| 5179 | vsi_idx = i; /* Found one! */ |
| 5180 | } else { |
| 5181 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5182 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5183 | } |
| 5184 | pf->next_vsi = ++i; |
| 5185 | |
| 5186 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 5187 | if (!vsi) { |
| 5188 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5189 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5190 | } |
| 5191 | vsi->type = type; |
| 5192 | vsi->back = pf; |
| 5193 | set_bit(__I40E_DOWN, &vsi->state); |
| 5194 | vsi->flags = 0; |
| 5195 | vsi->idx = vsi_idx; |
| 5196 | vsi->rx_itr_setting = pf->rx_itr_default; |
| 5197 | vsi->tx_itr_setting = pf->tx_itr_default; |
| 5198 | vsi->netdev_registered = false; |
| 5199 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
| 5200 | INIT_LIST_HEAD(&vsi->mac_filter_list); |
| 5201 | |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5202 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 5203 | if (ret) |
| 5204 | goto err_rings; |
| 5205 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5206 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5207 | if (ret) |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5208 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5209 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5210 | /* Setup default MSIX irq handler for VSI */ |
| 5211 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 5212 | |
| 5213 | pf->vsi[vsi_idx] = vsi; |
| 5214 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5215 | goto unlock_pf; |
| 5216 | |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5217 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5218 | pf->next_vsi = i - 1; |
| 5219 | kfree(vsi); |
| 5220 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5221 | mutex_unlock(&pf->switch_mutex); |
| 5222 | return ret; |
| 5223 | } |
| 5224 | |
| 5225 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5226 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 5227 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5228 | * @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] | 5229 | * |
| 5230 | * On error: returns error code (negative) |
| 5231 | * On success: returns 0 |
| 5232 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5233 | 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] | 5234 | { |
| 5235 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5236 | if (free_qvectors) { |
| 5237 | kfree(vsi->q_vectors); |
| 5238 | vsi->q_vectors = NULL; |
| 5239 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5240 | kfree(vsi->tx_rings); |
| 5241 | vsi->tx_rings = NULL; |
| 5242 | vsi->rx_rings = NULL; |
| 5243 | } |
| 5244 | |
| 5245 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5246 | * i40e_vsi_clear - Deallocate the VSI provided |
| 5247 | * @vsi: the VSI being un-configured |
| 5248 | **/ |
| 5249 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 5250 | { |
| 5251 | struct i40e_pf *pf; |
| 5252 | |
| 5253 | if (!vsi) |
| 5254 | return 0; |
| 5255 | |
| 5256 | if (!vsi->back) |
| 5257 | goto free_vsi; |
| 5258 | pf = vsi->back; |
| 5259 | |
| 5260 | mutex_lock(&pf->switch_mutex); |
| 5261 | if (!pf->vsi[vsi->idx]) { |
| 5262 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 5263 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 5264 | goto unlock_vsi; |
| 5265 | } |
| 5266 | |
| 5267 | if (pf->vsi[vsi->idx] != vsi) { |
| 5268 | dev_err(&pf->pdev->dev, |
| 5269 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 5270 | pf->vsi[vsi->idx]->idx, |
| 5271 | pf->vsi[vsi->idx], |
| 5272 | pf->vsi[vsi->idx]->type, |
| 5273 | vsi->idx, vsi, vsi->type); |
| 5274 | goto unlock_vsi; |
| 5275 | } |
| 5276 | |
| 5277 | /* updates the pf for this cleared vsi */ |
| 5278 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 5279 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 5280 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5281 | i40e_vsi_free_arrays(vsi, true); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5282 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5283 | pf->vsi[vsi->idx] = NULL; |
| 5284 | if (vsi->idx < pf->next_vsi) |
| 5285 | pf->next_vsi = vsi->idx; |
| 5286 | |
| 5287 | unlock_vsi: |
| 5288 | mutex_unlock(&pf->switch_mutex); |
| 5289 | free_vsi: |
| 5290 | kfree(vsi); |
| 5291 | |
| 5292 | return 0; |
| 5293 | } |
| 5294 | |
| 5295 | /** |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5296 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 5297 | * @vsi: the VSI being cleaned |
| 5298 | **/ |
| 5299 | static s32 i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
| 5300 | { |
| 5301 | int i; |
| 5302 | |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 5303 | if (vsi->tx_rings[0]) |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 5304 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 5305 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 5306 | vsi->tx_rings[i] = NULL; |
| 5307 | vsi->rx_rings[i] = NULL; |
| 5308 | } |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5309 | |
| 5310 | return 0; |
| 5311 | } |
| 5312 | |
| 5313 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5314 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 5315 | * @vsi: the VSI being configured |
| 5316 | **/ |
| 5317 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 5318 | { |
| 5319 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5320 | int i; |
| 5321 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5322 | /* Set basic values in the rings to be used later during open() */ |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 5323 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5324 | struct i40e_ring *tx_ring; |
| 5325 | struct i40e_ring *rx_ring; |
| 5326 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 5327 | /* allocate space for both Tx and Rx in one shot */ |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5328 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
| 5329 | if (!tx_ring) |
| 5330 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5331 | |
| 5332 | tx_ring->queue_index = i; |
| 5333 | tx_ring->reg_idx = vsi->base_queue + i; |
| 5334 | tx_ring->ring_active = false; |
| 5335 | tx_ring->vsi = vsi; |
| 5336 | tx_ring->netdev = vsi->netdev; |
| 5337 | tx_ring->dev = &pf->pdev->dev; |
| 5338 | tx_ring->count = vsi->num_desc; |
| 5339 | tx_ring->size = 0; |
| 5340 | tx_ring->dcb_tc = 0; |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5341 | vsi->tx_rings[i] = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5342 | |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5343 | rx_ring = &tx_ring[1]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5344 | rx_ring->queue_index = i; |
| 5345 | rx_ring->reg_idx = vsi->base_queue + i; |
| 5346 | rx_ring->ring_active = false; |
| 5347 | rx_ring->vsi = vsi; |
| 5348 | rx_ring->netdev = vsi->netdev; |
| 5349 | rx_ring->dev = &pf->pdev->dev; |
| 5350 | rx_ring->count = vsi->num_desc; |
| 5351 | rx_ring->size = 0; |
| 5352 | rx_ring->dcb_tc = 0; |
| 5353 | if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) |
| 5354 | set_ring_16byte_desc_enabled(rx_ring); |
| 5355 | else |
| 5356 | clear_ring_16byte_desc_enabled(rx_ring); |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5357 | vsi->rx_rings[i] = rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5358 | } |
| 5359 | |
| 5360 | return 0; |
Alexander Duyck | 9f65e15b | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5361 | |
| 5362 | err_out: |
| 5363 | i40e_vsi_clear_rings(vsi); |
| 5364 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5365 | } |
| 5366 | |
| 5367 | /** |
| 5368 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 5369 | * @pf: board private structure |
| 5370 | * @vectors: the number of MSI-X vectors to request |
| 5371 | * |
| 5372 | * Returns the number of vectors reserved, or error |
| 5373 | **/ |
| 5374 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 5375 | { |
| 5376 | int err = 0; |
| 5377 | |
| 5378 | pf->num_msix_entries = 0; |
| 5379 | while (vectors >= I40E_MIN_MSIX) { |
| 5380 | err = pci_enable_msix(pf->pdev, pf->msix_entries, vectors); |
| 5381 | if (err == 0) { |
| 5382 | /* good to go */ |
| 5383 | pf->num_msix_entries = vectors; |
| 5384 | break; |
| 5385 | } else if (err < 0) { |
| 5386 | /* total failure */ |
| 5387 | dev_info(&pf->pdev->dev, |
| 5388 | "MSI-X vector reservation failed: %d\n", err); |
| 5389 | vectors = 0; |
| 5390 | break; |
| 5391 | } else { |
| 5392 | /* err > 0 is the hint for retry */ |
| 5393 | dev_info(&pf->pdev->dev, |
| 5394 | "MSI-X vectors wanted %d, retrying with %d\n", |
| 5395 | vectors, err); |
| 5396 | vectors = err; |
| 5397 | } |
| 5398 | } |
| 5399 | |
| 5400 | if (vectors > 0 && vectors < I40E_MIN_MSIX) { |
| 5401 | dev_info(&pf->pdev->dev, |
| 5402 | "Couldn't get enough vectors, only %d available\n", |
| 5403 | vectors); |
| 5404 | vectors = 0; |
| 5405 | } |
| 5406 | |
| 5407 | return vectors; |
| 5408 | } |
| 5409 | |
| 5410 | /** |
| 5411 | * i40e_init_msix - Setup the MSIX capability |
| 5412 | * @pf: board private structure |
| 5413 | * |
| 5414 | * Work with the OS to set up the MSIX vectors needed. |
| 5415 | * |
| 5416 | * Returns 0 on success, negative on failure |
| 5417 | **/ |
| 5418 | static int i40e_init_msix(struct i40e_pf *pf) |
| 5419 | { |
| 5420 | i40e_status err = 0; |
| 5421 | struct i40e_hw *hw = &pf->hw; |
| 5422 | int v_budget, i; |
| 5423 | int vec; |
| 5424 | |
| 5425 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 5426 | return -ENODEV; |
| 5427 | |
| 5428 | /* The number of vectors we'll request will be comprised of: |
| 5429 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 5430 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 5431 | * - Queues being used for RSS. |
| 5432 | * We don't need as many as max_rss_size vectors. |
| 5433 | * use rss_size instead in the calculation since that |
| 5434 | * is governed by number of cpus in the system. |
| 5435 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5436 | * - The number of VMDq pairs |
| 5437 | * Once we count this up, try the request. |
| 5438 | * |
| 5439 | * If we can't get what we want, we'll simplify to nearly nothing |
| 5440 | * and try again. If that still fails, we punt. |
| 5441 | */ |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 5442 | pf->num_lan_msix = pf->num_lan_qps - (pf->rss_size_max - pf->rss_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5443 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
| 5444 | v_budget = 1 + pf->num_lan_msix; |
| 5445 | v_budget += (pf->num_vmdq_vsis * pf->num_vmdq_msix); |
| 5446 | if (pf->flags & I40E_FLAG_FDIR_ENABLED) |
| 5447 | v_budget++; |
| 5448 | |
| 5449 | /* Scale down if necessary, and the rings will share vectors */ |
| 5450 | v_budget = min_t(int, v_budget, hw->func_caps.num_msix_vectors); |
| 5451 | |
| 5452 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 5453 | GFP_KERNEL); |
| 5454 | if (!pf->msix_entries) |
| 5455 | return -ENOMEM; |
| 5456 | |
| 5457 | for (i = 0; i < v_budget; i++) |
| 5458 | pf->msix_entries[i].entry = i; |
| 5459 | vec = i40e_reserve_msix_vectors(pf, v_budget); |
| 5460 | if (vec < I40E_MIN_MSIX) { |
| 5461 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 5462 | kfree(pf->msix_entries); |
| 5463 | pf->msix_entries = NULL; |
| 5464 | return -ENODEV; |
| 5465 | |
| 5466 | } else if (vec == I40E_MIN_MSIX) { |
| 5467 | /* Adjust for minimal MSIX use */ |
| 5468 | dev_info(&pf->pdev->dev, "Features disabled, not enough MSIX vectors\n"); |
| 5469 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 5470 | pf->num_vmdq_vsis = 0; |
| 5471 | pf->num_vmdq_qps = 0; |
| 5472 | pf->num_vmdq_msix = 0; |
| 5473 | pf->num_lan_qps = 1; |
| 5474 | pf->num_lan_msix = 1; |
| 5475 | |
| 5476 | } else if (vec != v_budget) { |
| 5477 | /* Scale vector usage down */ |
| 5478 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
| 5479 | vec--; /* reserve the misc vector */ |
| 5480 | |
| 5481 | /* partition out the remaining vectors */ |
| 5482 | switch (vec) { |
| 5483 | case 2: |
| 5484 | pf->num_vmdq_vsis = 1; |
| 5485 | pf->num_lan_msix = 1; |
| 5486 | break; |
| 5487 | case 3: |
| 5488 | pf->num_vmdq_vsis = 1; |
| 5489 | pf->num_lan_msix = 2; |
| 5490 | break; |
| 5491 | default: |
| 5492 | pf->num_lan_msix = min_t(int, (vec / 2), |
| 5493 | pf->num_lan_qps); |
| 5494 | pf->num_vmdq_vsis = min_t(int, (vec - pf->num_lan_msix), |
| 5495 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 5496 | break; |
| 5497 | } |
| 5498 | } |
| 5499 | |
| 5500 | return err; |
| 5501 | } |
| 5502 | |
| 5503 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5504 | * i40e_alloc_q_vector - Allocate memory for a single interrupt vector |
| 5505 | * @vsi: the VSI being configured |
| 5506 | * @v_idx: index of the vector in the vsi struct |
| 5507 | * |
| 5508 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 5509 | **/ |
| 5510 | static int i40e_alloc_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 5511 | { |
| 5512 | struct i40e_q_vector *q_vector; |
| 5513 | |
| 5514 | /* allocate q_vector */ |
| 5515 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 5516 | if (!q_vector) |
| 5517 | return -ENOMEM; |
| 5518 | |
| 5519 | q_vector->vsi = vsi; |
| 5520 | q_vector->v_idx = v_idx; |
| 5521 | cpumask_set_cpu(v_idx, &q_vector->affinity_mask); |
| 5522 | if (vsi->netdev) |
| 5523 | netif_napi_add(vsi->netdev, &q_vector->napi, |
| 5524 | i40e_napi_poll, vsi->work_limit); |
| 5525 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 5526 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 5527 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 5528 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5529 | /* tie q_vector and vsi together */ |
| 5530 | vsi->q_vectors[v_idx] = q_vector; |
| 5531 | |
| 5532 | return 0; |
| 5533 | } |
| 5534 | |
| 5535 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5536 | * i40e_alloc_q_vectors - Allocate memory for interrupt vectors |
| 5537 | * @vsi: the VSI being configured |
| 5538 | * |
| 5539 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 5540 | * return -ENOMEM. |
| 5541 | **/ |
| 5542 | static int i40e_alloc_q_vectors(struct i40e_vsi *vsi) |
| 5543 | { |
| 5544 | struct i40e_pf *pf = vsi->back; |
| 5545 | int v_idx, num_q_vectors; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5546 | int err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5547 | |
| 5548 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 5549 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5550 | num_q_vectors = vsi->num_q_vectors; |
| 5551 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 5552 | num_q_vectors = 1; |
| 5553 | else |
| 5554 | return -EINVAL; |
| 5555 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5556 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5557 | err = i40e_alloc_q_vector(vsi, v_idx); |
| 5558 | if (err) |
| 5559 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5560 | } |
| 5561 | |
| 5562 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5563 | |
| 5564 | err_out: |
| 5565 | while (v_idx--) |
| 5566 | i40e_free_q_vector(vsi, v_idx); |
| 5567 | |
| 5568 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5569 | } |
| 5570 | |
| 5571 | /** |
| 5572 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 5573 | * @pf: board private structure to initialize |
| 5574 | **/ |
| 5575 | static void i40e_init_interrupt_scheme(struct i40e_pf *pf) |
| 5576 | { |
| 5577 | int err = 0; |
| 5578 | |
| 5579 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 5580 | err = i40e_init_msix(pf); |
| 5581 | if (err) { |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 5582 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
| 5583 | I40E_FLAG_RSS_ENABLED | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5584 | I40E_FLAG_MQ_ENABLED | |
| 5585 | I40E_FLAG_DCB_ENABLED | |
| 5586 | I40E_FLAG_SRIOV_ENABLED | |
| 5587 | I40E_FLAG_FDIR_ENABLED | |
| 5588 | I40E_FLAG_FDIR_ATR_ENABLED | |
| 5589 | I40E_FLAG_VMDQ_ENABLED); |
| 5590 | |
| 5591 | /* rework the queue expectations without MSIX */ |
| 5592 | i40e_determine_queue_usage(pf); |
| 5593 | } |
| 5594 | } |
| 5595 | |
| 5596 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 5597 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 5598 | dev_info(&pf->pdev->dev, "MSIX not available, trying MSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5599 | err = pci_enable_msi(pf->pdev); |
| 5600 | if (err) { |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 5601 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5602 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 5603 | } |
| 5604 | } |
| 5605 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 5606 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
| 5607 | dev_info(&pf->pdev->dev, "MSIX and MSI not available, falling back to Legacy IRQ\n"); |
| 5608 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5609 | /* track first vector for misc interrupts */ |
| 5610 | err = i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT-1); |
| 5611 | } |
| 5612 | |
| 5613 | /** |
| 5614 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 5615 | * @pf: board private structure |
| 5616 | * |
| 5617 | * This sets up the handler for MSIX 0, which is used to manage the |
| 5618 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 5619 | * when in MSI or Legacy interrupt mode. |
| 5620 | **/ |
| 5621 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 5622 | { |
| 5623 | struct i40e_hw *hw = &pf->hw; |
| 5624 | int err = 0; |
| 5625 | |
| 5626 | /* Only request the irq if this is the first time through, and |
| 5627 | * not when we're rebuilding after a Reset |
| 5628 | */ |
| 5629 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 5630 | err = request_irq(pf->msix_entries[0].vector, |
| 5631 | i40e_intr, 0, pf->misc_int_name, pf); |
| 5632 | if (err) { |
| 5633 | dev_info(&pf->pdev->dev, |
| 5634 | "request_irq for msix_misc failed: %d\n", err); |
| 5635 | return -EFAULT; |
| 5636 | } |
| 5637 | } |
| 5638 | |
| 5639 | i40e_enable_misc_int_causes(hw); |
| 5640 | |
| 5641 | /* associate no queues to the misc vector */ |
| 5642 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 5643 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 5644 | |
| 5645 | i40e_flush(hw); |
| 5646 | |
| 5647 | i40e_irq_dynamic_enable_icr0(pf); |
| 5648 | |
| 5649 | return err; |
| 5650 | } |
| 5651 | |
| 5652 | /** |
| 5653 | * i40e_config_rss - Prepare for RSS if used |
| 5654 | * @pf: board private structure |
| 5655 | **/ |
| 5656 | static int i40e_config_rss(struct i40e_pf *pf) |
| 5657 | { |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 5658 | const u64 default_hena = |
| 5659 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) | |
| 5660 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) | |
| 5661 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) | |
| 5662 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP) | |
| 5663 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN) | |
| 5664 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP) | |
| 5665 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | |
| 5666 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4) | |
| 5667 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) | |
| 5668 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) | |
| 5669 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) | |
| 5670 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN) | |
| 5671 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP) | |
| 5672 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP) | |
| 5673 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | |
| 5674 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6) | |
| 5675 | ((u64)1 << I40E_FILTER_PCTYPE_L2_PAYLOAD); |
| 5676 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5677 | /* Set of random keys generated using kernel random number generator */ |
| 5678 | static const u32 seed[I40E_PFQF_HKEY_MAX_INDEX + 1] = {0x41b01687, |
| 5679 | 0x183cfd8c, 0xce880440, 0x580cbc3c, 0x35897377, |
| 5680 | 0x328b25e1, 0x4fa98922, 0xb7d90c14, 0xd5bad70d, |
| 5681 | 0xcd15a2c1, 0xe8580225, 0x4a1e9d11, 0xfe5731be}; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 5682 | struct i40e_hw *hw = &pf->hw; |
| 5683 | u32 lut = 0; |
| 5684 | int i, j; |
| 5685 | u64 hena; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5686 | |
| 5687 | /* Fill out hash function seed */ |
| 5688 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
| 5689 | wr32(hw, I40E_PFQF_HKEY(i), seed[i]); |
| 5690 | |
| 5691 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
| 5692 | hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) | |
| 5693 | ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32); |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 5694 | hena |= default_hena; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5695 | wr32(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 5696 | wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
| 5697 | |
| 5698 | /* Populate the LUT with max no. of queues in round robin fashion */ |
| 5699 | for (i = 0, j = 0; i < pf->hw.func_caps.rss_table_size; i++, j++) { |
| 5700 | |
| 5701 | /* The assumption is that lan qp count will be the highest |
| 5702 | * qp count for any PF VSI that needs RSS. |
| 5703 | * If multiple VSIs need RSS support, all the qp counts |
| 5704 | * for those VSIs should be a power of 2 for RSS to work. |
| 5705 | * If LAN VSI is the only consumer for RSS then this requirement |
| 5706 | * is not necessary. |
| 5707 | */ |
| 5708 | if (j == pf->rss_size) |
| 5709 | j = 0; |
| 5710 | /* lut = 4-byte sliding window of 4 lut entries */ |
| 5711 | lut = (lut << 8) | (j & |
| 5712 | ((0x1 << pf->hw.func_caps.rss_table_entry_width) - 1)); |
| 5713 | /* On i = 3, we have 4 entries in lut; write to the register */ |
| 5714 | if ((i & 3) == 3) |
| 5715 | wr32(hw, I40E_PFQF_HLUT(i >> 2), lut); |
| 5716 | } |
| 5717 | i40e_flush(hw); |
| 5718 | |
| 5719 | return 0; |
| 5720 | } |
| 5721 | |
| 5722 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 5723 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 5724 | * @pf: board private structure |
| 5725 | * @queue_count: the requested queue count for rss. |
| 5726 | * |
| 5727 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 5728 | * count which may be different from the requested queue count. |
| 5729 | **/ |
| 5730 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 5731 | { |
| 5732 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 5733 | return 0; |
| 5734 | |
| 5735 | queue_count = min_t(int, queue_count, pf->rss_size_max); |
| 5736 | queue_count = rounddown_pow_of_two(queue_count); |
| 5737 | |
| 5738 | if (queue_count != pf->rss_size) { |
| 5739 | if (pf->queues_left < (queue_count - pf->rss_size)) { |
| 5740 | dev_info(&pf->pdev->dev, |
| 5741 | "Not enough queues to do RSS on %d queues: remaining queues %d\n", |
| 5742 | queue_count, pf->queues_left); |
| 5743 | return pf->rss_size; |
| 5744 | } |
| 5745 | i40e_prep_for_reset(pf); |
| 5746 | |
| 5747 | pf->num_lan_qps += (queue_count - pf->rss_size); |
| 5748 | pf->queues_left -= (queue_count - pf->rss_size); |
| 5749 | pf->rss_size = queue_count; |
| 5750 | |
| 5751 | i40e_reset_and_rebuild(pf, true); |
| 5752 | i40e_config_rss(pf); |
| 5753 | } |
| 5754 | dev_info(&pf->pdev->dev, "RSS count: %d\n", pf->rss_size); |
| 5755 | return pf->rss_size; |
| 5756 | } |
| 5757 | |
| 5758 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5759 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 5760 | * @pf: board private structure to initialize |
| 5761 | * |
| 5762 | * i40e_sw_init initializes the Adapter private data structure. |
| 5763 | * Fields are initialized based on PCI device information and |
| 5764 | * OS network device settings (MTU size). |
| 5765 | **/ |
| 5766 | static int i40e_sw_init(struct i40e_pf *pf) |
| 5767 | { |
| 5768 | int err = 0; |
| 5769 | int size; |
| 5770 | |
| 5771 | pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE, |
| 5772 | (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)); |
Shannon Nelson | 2759997 | 2013-11-16 10:00:43 +0000 | [diff] [blame] | 5773 | pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5774 | if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) { |
| 5775 | if (I40E_DEBUG_USER & debug) |
| 5776 | pf->hw.debug_mask = debug; |
| 5777 | pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER), |
| 5778 | I40E_DEFAULT_MSG_ENABLE); |
| 5779 | } |
| 5780 | |
| 5781 | /* Set default capability flags */ |
| 5782 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 5783 | I40E_FLAG_MSI_ENABLED | |
| 5784 | I40E_FLAG_MSIX_ENABLED | |
| 5785 | I40E_FLAG_RX_PS_ENABLED | |
| 5786 | I40E_FLAG_MQ_ENABLED | |
| 5787 | I40E_FLAG_RX_1BUF_ENABLED; |
| 5788 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 5789 | /* Depending on PF configurations, it is possible that the RSS |
| 5790 | * maximum might end up larger than the available queues |
| 5791 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5792 | 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] | 5793 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 5794 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5795 | if (pf->hw.func_caps.rss) { |
| 5796 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Jesse Brandeburg | bf051a3 | 2013-11-26 10:49:17 +0000 | [diff] [blame] | 5797 | 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] | 5798 | } else { |
| 5799 | pf->rss_size = 1; |
| 5800 | } |
| 5801 | |
| 5802 | if (pf->hw.func_caps.dcb) |
| 5803 | pf->num_tc_qps = I40E_DEFAULT_QUEUES_PER_TC; |
| 5804 | else |
| 5805 | pf->num_tc_qps = 0; |
| 5806 | |
| 5807 | if (pf->hw.func_caps.fd) { |
| 5808 | /* FW/NVM is not yet fixed in this regard */ |
| 5809 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 5810 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 5811 | pf->flags |= I40E_FLAG_FDIR_ATR_ENABLED; |
| 5812 | dev_info(&pf->pdev->dev, |
| 5813 | "Flow Director ATR mode Enabled\n"); |
| 5814 | pf->flags |= I40E_FLAG_FDIR_ENABLED; |
| 5815 | dev_info(&pf->pdev->dev, |
| 5816 | "Flow Director Side Band mode Enabled\n"); |
| 5817 | pf->fdir_pf_filter_count = |
| 5818 | pf->hw.func_caps.fd_filters_guaranteed; |
| 5819 | } |
| 5820 | } else { |
| 5821 | pf->fdir_pf_filter_count = 0; |
| 5822 | } |
| 5823 | |
| 5824 | if (pf->hw.func_caps.vmdq) { |
| 5825 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
| 5826 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
| 5827 | pf->num_vmdq_qps = I40E_DEFAULT_QUEUES_PER_VMDQ; |
| 5828 | } |
| 5829 | |
| 5830 | /* MFP mode enabled */ |
| 5831 | if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.mfp_mode_1) { |
| 5832 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 5833 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
| 5834 | } |
| 5835 | |
| 5836 | #ifdef CONFIG_PCI_IOV |
| 5837 | if (pf->hw.func_caps.num_vfs) { |
| 5838 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 5839 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 5840 | pf->num_req_vfs = min_t(int, |
| 5841 | pf->hw.func_caps.num_vfs, |
| 5842 | I40E_MAX_VF_COUNT); |
Anjali Singhai Jain | 4a38d09 | 2013-11-20 10:03:00 +0000 | [diff] [blame] | 5843 | dev_info(&pf->pdev->dev, |
| 5844 | "Number of VFs being requested for PF[%d] = %d\n", |
| 5845 | pf->hw.pf_id, pf->num_req_vfs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5846 | } |
| 5847 | #endif /* CONFIG_PCI_IOV */ |
| 5848 | pf->eeprom_version = 0xDEAD; |
| 5849 | pf->lan_veb = I40E_NO_VEB; |
| 5850 | pf->lan_vsi = I40E_NO_VSI; |
| 5851 | |
| 5852 | /* set up queue assignment tracking */ |
| 5853 | size = sizeof(struct i40e_lump_tracking) |
| 5854 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 5855 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 5856 | if (!pf->qp_pile) { |
| 5857 | err = -ENOMEM; |
| 5858 | goto sw_init_done; |
| 5859 | } |
| 5860 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 5861 | pf->qp_pile->search_hint = 0; |
| 5862 | |
| 5863 | /* set up vector assignment tracking */ |
| 5864 | size = sizeof(struct i40e_lump_tracking) |
| 5865 | + (sizeof(u16) * pf->hw.func_caps.num_msix_vectors); |
| 5866 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
| 5867 | if (!pf->irq_pile) { |
| 5868 | kfree(pf->qp_pile); |
| 5869 | err = -ENOMEM; |
| 5870 | goto sw_init_done; |
| 5871 | } |
| 5872 | pf->irq_pile->num_entries = pf->hw.func_caps.num_msix_vectors; |
| 5873 | pf->irq_pile->search_hint = 0; |
| 5874 | |
| 5875 | mutex_init(&pf->switch_mutex); |
| 5876 | |
| 5877 | sw_init_done: |
| 5878 | return err; |
| 5879 | } |
| 5880 | |
| 5881 | /** |
| 5882 | * i40e_set_features - set the netdev feature flags |
| 5883 | * @netdev: ptr to the netdev being adjusted |
| 5884 | * @features: the feature set that the stack is suggesting |
| 5885 | **/ |
| 5886 | static int i40e_set_features(struct net_device *netdev, |
| 5887 | netdev_features_t features) |
| 5888 | { |
| 5889 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 5890 | struct i40e_vsi *vsi = np->vsi; |
| 5891 | |
| 5892 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 5893 | i40e_vlan_stripping_enable(vsi); |
| 5894 | else |
| 5895 | i40e_vlan_stripping_disable(vsi); |
| 5896 | |
| 5897 | return 0; |
| 5898 | } |
| 5899 | |
| 5900 | static const struct net_device_ops i40e_netdev_ops = { |
| 5901 | .ndo_open = i40e_open, |
| 5902 | .ndo_stop = i40e_close, |
| 5903 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 5904 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 5905 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 5906 | .ndo_validate_addr = eth_validate_addr, |
| 5907 | .ndo_set_mac_address = i40e_set_mac, |
| 5908 | .ndo_change_mtu = i40e_change_mtu, |
| 5909 | .ndo_tx_timeout = i40e_tx_timeout, |
| 5910 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 5911 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 5912 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5913 | .ndo_poll_controller = i40e_netpoll, |
| 5914 | #endif |
| 5915 | .ndo_setup_tc = i40e_setup_tc, |
| 5916 | .ndo_set_features = i40e_set_features, |
| 5917 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 5918 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
| 5919 | .ndo_set_vf_tx_rate = i40e_ndo_set_vf_bw, |
| 5920 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
| 5921 | }; |
| 5922 | |
| 5923 | /** |
| 5924 | * i40e_config_netdev - Setup the netdev flags |
| 5925 | * @vsi: the VSI being configured |
| 5926 | * |
| 5927 | * Returns 0 on success, negative value on failure |
| 5928 | **/ |
| 5929 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 5930 | { |
| 5931 | struct i40e_pf *pf = vsi->back; |
| 5932 | struct i40e_hw *hw = &pf->hw; |
| 5933 | struct i40e_netdev_priv *np; |
| 5934 | struct net_device *netdev; |
| 5935 | u8 mac_addr[ETH_ALEN]; |
| 5936 | int etherdev_size; |
| 5937 | |
| 5938 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 5939 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5940 | if (!netdev) |
| 5941 | return -ENOMEM; |
| 5942 | |
| 5943 | vsi->netdev = netdev; |
| 5944 | np = netdev_priv(netdev); |
| 5945 | np->vsi = vsi; |
| 5946 | |
| 5947 | netdev->hw_enc_features = NETIF_F_IP_CSUM | |
| 5948 | NETIF_F_GSO_UDP_TUNNEL | |
| 5949 | NETIF_F_TSO | |
| 5950 | NETIF_F_SG; |
| 5951 | |
| 5952 | netdev->features = NETIF_F_SG | |
| 5953 | NETIF_F_IP_CSUM | |
| 5954 | NETIF_F_SCTP_CSUM | |
| 5955 | NETIF_F_HIGHDMA | |
| 5956 | NETIF_F_GSO_UDP_TUNNEL | |
| 5957 | NETIF_F_HW_VLAN_CTAG_TX | |
| 5958 | NETIF_F_HW_VLAN_CTAG_RX | |
| 5959 | NETIF_F_HW_VLAN_CTAG_FILTER | |
| 5960 | NETIF_F_IPV6_CSUM | |
| 5961 | NETIF_F_TSO | |
| 5962 | NETIF_F_TSO6 | |
| 5963 | NETIF_F_RXCSUM | |
| 5964 | NETIF_F_RXHASH | |
| 5965 | 0; |
| 5966 | |
| 5967 | /* copy netdev features into list of user selectable features */ |
| 5968 | netdev->hw_features |= netdev->features; |
| 5969 | |
| 5970 | if (vsi->type == I40E_VSI_MAIN) { |
| 5971 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
| 5972 | memcpy(mac_addr, hw->mac.perm_addr, ETH_ALEN); |
| 5973 | } else { |
| 5974 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ |
| 5975 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", |
| 5976 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 5977 | random_ether_addr(mac_addr); |
| 5978 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false); |
| 5979 | } |
| 5980 | |
| 5981 | memcpy(netdev->dev_addr, mac_addr, ETH_ALEN); |
| 5982 | memcpy(netdev->perm_addr, mac_addr, ETH_ALEN); |
| 5983 | /* vlan gets same features (except vlan offload) |
| 5984 | * after any tweaks for specific VSI types |
| 5985 | */ |
| 5986 | netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX | |
| 5987 | NETIF_F_HW_VLAN_CTAG_RX | |
| 5988 | NETIF_F_HW_VLAN_CTAG_FILTER); |
| 5989 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 5990 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 5991 | /* Setup netdev TC information */ |
| 5992 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 5993 | |
| 5994 | netdev->netdev_ops = &i40e_netdev_ops; |
| 5995 | netdev->watchdog_timeo = 5 * HZ; |
| 5996 | i40e_set_ethtool_ops(netdev); |
| 5997 | |
| 5998 | return 0; |
| 5999 | } |
| 6000 | |
| 6001 | /** |
| 6002 | * i40e_vsi_delete - Delete a VSI from the switch |
| 6003 | * @vsi: the VSI being removed |
| 6004 | * |
| 6005 | * Returns 0 on success, negative value on failure |
| 6006 | **/ |
| 6007 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 6008 | { |
| 6009 | /* remove default VSI is not allowed */ |
| 6010 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 6011 | return; |
| 6012 | |
| 6013 | /* there is no HW VSI for FDIR */ |
| 6014 | if (vsi->type == I40E_VSI_FDIR) |
| 6015 | return; |
| 6016 | |
| 6017 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
| 6018 | return; |
| 6019 | } |
| 6020 | |
| 6021 | /** |
| 6022 | * i40e_add_vsi - Add a VSI to the switch |
| 6023 | * @vsi: the VSI being configured |
| 6024 | * |
| 6025 | * This initializes a VSI context depending on the VSI type to be added and |
| 6026 | * passes it down to the add_vsi aq command. |
| 6027 | **/ |
| 6028 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 6029 | { |
| 6030 | int ret = -ENODEV; |
| 6031 | struct i40e_mac_filter *f, *ftmp; |
| 6032 | struct i40e_pf *pf = vsi->back; |
| 6033 | struct i40e_hw *hw = &pf->hw; |
| 6034 | struct i40e_vsi_context ctxt; |
| 6035 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 6036 | int f_count = 0; |
| 6037 | |
| 6038 | memset(&ctxt, 0, sizeof(ctxt)); |
| 6039 | switch (vsi->type) { |
| 6040 | case I40E_VSI_MAIN: |
| 6041 | /* The PF's main VSI is already setup as part of the |
| 6042 | * device initialization, so we'll not bother with |
| 6043 | * the add_vsi call, but we will retrieve the current |
| 6044 | * VSI context. |
| 6045 | */ |
| 6046 | ctxt.seid = pf->main_vsi_seid; |
| 6047 | ctxt.pf_num = pf->hw.pf_id; |
| 6048 | ctxt.vf_num = 0; |
| 6049 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6050 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6051 | if (ret) { |
| 6052 | dev_info(&pf->pdev->dev, |
| 6053 | "couldn't get pf vsi config, err %d, aq_err %d\n", |
| 6054 | ret, pf->hw.aq.asq_last_status); |
| 6055 | return -ENOENT; |
| 6056 | } |
| 6057 | memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info)); |
| 6058 | vsi->info.valid_sections = 0; |
| 6059 | |
| 6060 | vsi->seid = ctxt.seid; |
| 6061 | vsi->id = ctxt.vsi_number; |
| 6062 | |
| 6063 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 6064 | |
| 6065 | /* MFP mode setup queue map and update VSI */ |
| 6066 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 6067 | memset(&ctxt, 0, sizeof(ctxt)); |
| 6068 | ctxt.seid = pf->main_vsi_seid; |
| 6069 | ctxt.pf_num = pf->hw.pf_id; |
| 6070 | ctxt.vf_num = 0; |
| 6071 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 6072 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 6073 | if (ret) { |
| 6074 | dev_info(&pf->pdev->dev, |
| 6075 | "update vsi failed, aq_err=%d\n", |
| 6076 | pf->hw.aq.asq_last_status); |
| 6077 | ret = -ENOENT; |
| 6078 | goto err; |
| 6079 | } |
| 6080 | /* update the local VSI info queue map */ |
| 6081 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 6082 | vsi->info.valid_sections = 0; |
| 6083 | } else { |
| 6084 | /* Default/Main VSI is only enabled for TC0 |
| 6085 | * reconfigure it to enable all TCs that are |
| 6086 | * available on the port in SFP mode. |
| 6087 | */ |
| 6088 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 6089 | if (ret) { |
| 6090 | dev_info(&pf->pdev->dev, |
| 6091 | "failed to configure TCs for main VSI tc_map 0x%08x, err %d, aq_err %d\n", |
| 6092 | enabled_tc, ret, |
| 6093 | pf->hw.aq.asq_last_status); |
| 6094 | ret = -ENOENT; |
| 6095 | } |
| 6096 | } |
| 6097 | break; |
| 6098 | |
| 6099 | case I40E_VSI_FDIR: |
| 6100 | /* no queue mapping or actual HW VSI needed */ |
| 6101 | vsi->info.valid_sections = 0; |
| 6102 | vsi->seid = 0; |
| 6103 | vsi->id = 0; |
| 6104 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 6105 | return 0; |
| 6106 | break; |
| 6107 | |
| 6108 | case I40E_VSI_VMDQ2: |
| 6109 | ctxt.pf_num = hw->pf_id; |
| 6110 | ctxt.vf_num = 0; |
| 6111 | ctxt.uplink_seid = vsi->uplink_seid; |
| 6112 | ctxt.connection_type = 0x1; /* regular data port */ |
| 6113 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 6114 | |
| 6115 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6116 | |
| 6117 | /* This VSI is connected to VEB so the switch_id |
| 6118 | * should be set to zero by default. |
| 6119 | */ |
| 6120 | ctxt.info.switch_id = 0; |
| 6121 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB); |
| 6122 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6123 | |
| 6124 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 6125 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 6126 | break; |
| 6127 | |
| 6128 | case I40E_VSI_SRIOV: |
| 6129 | ctxt.pf_num = hw->pf_id; |
| 6130 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 6131 | ctxt.uplink_seid = vsi->uplink_seid; |
| 6132 | ctxt.connection_type = 0x1; /* regular data port */ |
| 6133 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 6134 | |
| 6135 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 6136 | |
| 6137 | /* This VSI is connected to VEB so the switch_id |
| 6138 | * should be set to zero by default. |
| 6139 | */ |
| 6140 | ctxt.info.switch_id = cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 6141 | |
| 6142 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 6143 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
| 6144 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 6145 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 6146 | break; |
| 6147 | |
| 6148 | default: |
| 6149 | return -ENODEV; |
| 6150 | } |
| 6151 | |
| 6152 | if (vsi->type != I40E_VSI_MAIN) { |
| 6153 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 6154 | if (ret) { |
| 6155 | dev_info(&vsi->back->pdev->dev, |
| 6156 | "add vsi failed, aq_err=%d\n", |
| 6157 | vsi->back->hw.aq.asq_last_status); |
| 6158 | ret = -ENOENT; |
| 6159 | goto err; |
| 6160 | } |
| 6161 | memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info)); |
| 6162 | vsi->info.valid_sections = 0; |
| 6163 | vsi->seid = ctxt.seid; |
| 6164 | vsi->id = ctxt.vsi_number; |
| 6165 | } |
| 6166 | |
| 6167 | /* If macvlan filters already exist, force them to get loaded */ |
| 6168 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 6169 | f->changed = true; |
| 6170 | f_count++; |
| 6171 | } |
| 6172 | if (f_count) { |
| 6173 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 6174 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 6175 | } |
| 6176 | |
| 6177 | /* Update VSI BW information */ |
| 6178 | ret = i40e_vsi_get_bw_info(vsi); |
| 6179 | if (ret) { |
| 6180 | dev_info(&pf->pdev->dev, |
| 6181 | "couldn't get vsi bw info, err %d, aq_err %d\n", |
| 6182 | ret, pf->hw.aq.asq_last_status); |
| 6183 | /* VSI is already added so not tearing that up */ |
| 6184 | ret = 0; |
| 6185 | } |
| 6186 | |
| 6187 | err: |
| 6188 | return ret; |
| 6189 | } |
| 6190 | |
| 6191 | /** |
| 6192 | * i40e_vsi_release - Delete a VSI and free its resources |
| 6193 | * @vsi: the VSI being removed |
| 6194 | * |
| 6195 | * Returns 0 on success or < 0 on error |
| 6196 | **/ |
| 6197 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 6198 | { |
| 6199 | struct i40e_mac_filter *f, *ftmp; |
| 6200 | struct i40e_veb *veb = NULL; |
| 6201 | struct i40e_pf *pf; |
| 6202 | u16 uplink_seid; |
| 6203 | int i, n; |
| 6204 | |
| 6205 | pf = vsi->back; |
| 6206 | |
| 6207 | /* release of a VEB-owner or last VSI is not allowed */ |
| 6208 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 6209 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 6210 | vsi->seid, vsi->uplink_seid); |
| 6211 | return -ENODEV; |
| 6212 | } |
| 6213 | if (vsi == pf->vsi[pf->lan_vsi] && |
| 6214 | !test_bit(__I40E_DOWN, &pf->state)) { |
| 6215 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 6216 | return -ENODEV; |
| 6217 | } |
| 6218 | |
| 6219 | uplink_seid = vsi->uplink_seid; |
| 6220 | if (vsi->type != I40E_VSI_SRIOV) { |
| 6221 | if (vsi->netdev_registered) { |
| 6222 | vsi->netdev_registered = false; |
| 6223 | if (vsi->netdev) { |
| 6224 | /* results in a call to i40e_close() */ |
| 6225 | unregister_netdev(vsi->netdev); |
| 6226 | free_netdev(vsi->netdev); |
| 6227 | vsi->netdev = NULL; |
| 6228 | } |
| 6229 | } else { |
| 6230 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) |
| 6231 | i40e_down(vsi); |
| 6232 | i40e_vsi_free_irq(vsi); |
| 6233 | i40e_vsi_free_tx_resources(vsi); |
| 6234 | i40e_vsi_free_rx_resources(vsi); |
| 6235 | } |
| 6236 | i40e_vsi_disable_irq(vsi); |
| 6237 | } |
| 6238 | |
| 6239 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) |
| 6240 | i40e_del_filter(vsi, f->macaddr, f->vlan, |
| 6241 | f->is_vf, f->is_netdev); |
| 6242 | i40e_sync_vsi_filters(vsi); |
| 6243 | |
| 6244 | i40e_vsi_delete(vsi); |
| 6245 | i40e_vsi_free_q_vectors(vsi); |
| 6246 | i40e_vsi_clear_rings(vsi); |
| 6247 | i40e_vsi_clear(vsi); |
| 6248 | |
| 6249 | /* If this was the last thing on the VEB, except for the |
| 6250 | * controlling VSI, remove the VEB, which puts the controlling |
| 6251 | * VSI onto the next level down in the switch. |
| 6252 | * |
| 6253 | * Well, okay, there's one more exception here: don't remove |
| 6254 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 6255 | * from up the network stack. |
| 6256 | */ |
| 6257 | for (n = 0, i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 6258 | if (pf->vsi[i] && |
| 6259 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 6260 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 6261 | n++; /* count the VSIs */ |
| 6262 | } |
| 6263 | } |
| 6264 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 6265 | if (!pf->veb[i]) |
| 6266 | continue; |
| 6267 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 6268 | n++; /* count the VEBs */ |
| 6269 | if (pf->veb[i]->seid == uplink_seid) |
| 6270 | veb = pf->veb[i]; |
| 6271 | } |
| 6272 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 6273 | i40e_veb_release(veb); |
| 6274 | |
| 6275 | return 0; |
| 6276 | } |
| 6277 | |
| 6278 | /** |
| 6279 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 6280 | * @vsi: ptr to the VSI |
| 6281 | * |
| 6282 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 6283 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 6284 | * newly allocated VSI. |
| 6285 | * |
| 6286 | * Returns 0 on success or negative on failure |
| 6287 | **/ |
| 6288 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 6289 | { |
| 6290 | int ret = -ENOENT; |
| 6291 | struct i40e_pf *pf = vsi->back; |
| 6292 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 6293 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6294 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 6295 | vsi->seid); |
| 6296 | return -EEXIST; |
| 6297 | } |
| 6298 | |
| 6299 | if (vsi->base_vector) { |
| 6300 | dev_info(&pf->pdev->dev, |
| 6301 | "VSI %d has non-zero base vector %d\n", |
| 6302 | vsi->seid, vsi->base_vector); |
| 6303 | return -EEXIST; |
| 6304 | } |
| 6305 | |
| 6306 | ret = i40e_alloc_q_vectors(vsi); |
| 6307 | if (ret) { |
| 6308 | dev_info(&pf->pdev->dev, |
| 6309 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 6310 | vsi->num_q_vectors, vsi->seid, ret); |
| 6311 | vsi->num_q_vectors = 0; |
| 6312 | goto vector_setup_out; |
| 6313 | } |
| 6314 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 6315 | if (vsi->num_q_vectors) |
| 6316 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 6317 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6318 | if (vsi->base_vector < 0) { |
| 6319 | dev_info(&pf->pdev->dev, |
| 6320 | "failed to get q tracking for VSI %d, err=%d\n", |
| 6321 | vsi->seid, vsi->base_vector); |
| 6322 | i40e_vsi_free_q_vectors(vsi); |
| 6323 | ret = -ENOENT; |
| 6324 | goto vector_setup_out; |
| 6325 | } |
| 6326 | |
| 6327 | vector_setup_out: |
| 6328 | return ret; |
| 6329 | } |
| 6330 | |
| 6331 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6332 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 6333 | * @vsi: pointer to the vsi. |
| 6334 | * |
| 6335 | * This re-allocates a vsi's queue resources. |
| 6336 | * |
| 6337 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 6338 | * on success, otherwise returns NULL on failure. |
| 6339 | **/ |
| 6340 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 6341 | { |
| 6342 | struct i40e_pf *pf = vsi->back; |
| 6343 | u8 enabled_tc; |
| 6344 | int ret; |
| 6345 | |
| 6346 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 6347 | i40e_vsi_clear_rings(vsi); |
| 6348 | |
| 6349 | i40e_vsi_free_arrays(vsi, false); |
| 6350 | i40e_set_num_rings_in_vsi(vsi); |
| 6351 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 6352 | if (ret) |
| 6353 | goto err_vsi; |
| 6354 | |
| 6355 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 6356 | if (ret < 0) { |
| 6357 | dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n", |
| 6358 | vsi->seid, ret); |
| 6359 | goto err_vsi; |
| 6360 | } |
| 6361 | vsi->base_queue = ret; |
| 6362 | |
| 6363 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 6364 | * layout configurations. |
| 6365 | */ |
| 6366 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 6367 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 6368 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 6369 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 6370 | |
| 6371 | /* assign it some queues */ |
| 6372 | ret = i40e_alloc_rings(vsi); |
| 6373 | if (ret) |
| 6374 | goto err_rings; |
| 6375 | |
| 6376 | /* map all of the rings to the q_vectors */ |
| 6377 | i40e_vsi_map_rings_to_vectors(vsi); |
| 6378 | return vsi; |
| 6379 | |
| 6380 | err_rings: |
| 6381 | i40e_vsi_free_q_vectors(vsi); |
| 6382 | if (vsi->netdev_registered) { |
| 6383 | vsi->netdev_registered = false; |
| 6384 | unregister_netdev(vsi->netdev); |
| 6385 | free_netdev(vsi->netdev); |
| 6386 | vsi->netdev = NULL; |
| 6387 | } |
| 6388 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 6389 | err_vsi: |
| 6390 | i40e_vsi_clear(vsi); |
| 6391 | return NULL; |
| 6392 | } |
| 6393 | |
| 6394 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6395 | * i40e_vsi_setup - Set up a VSI by a given type |
| 6396 | * @pf: board private structure |
| 6397 | * @type: VSI type |
| 6398 | * @uplink_seid: the switch element to link to |
| 6399 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 6400 | * |
| 6401 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 6402 | * to the identified VEB. |
| 6403 | * |
| 6404 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 6405 | * success, otherwise returns NULL on failure. |
| 6406 | **/ |
| 6407 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 6408 | u16 uplink_seid, u32 param1) |
| 6409 | { |
| 6410 | struct i40e_vsi *vsi = NULL; |
| 6411 | struct i40e_veb *veb = NULL; |
| 6412 | int ret, i; |
| 6413 | int v_idx; |
| 6414 | |
| 6415 | /* The requested uplink_seid must be either |
| 6416 | * - the PF's port seid |
| 6417 | * no VEB is needed because this is the PF |
| 6418 | * or this is a Flow Director special case VSI |
| 6419 | * - seid of an existing VEB |
| 6420 | * - seid of a VSI that owns an existing VEB |
| 6421 | * - seid of a VSI that doesn't own a VEB |
| 6422 | * a new VEB is created and the VSI becomes the owner |
| 6423 | * - seid of the PF VSI, which is what creates the first VEB |
| 6424 | * this is a special case of the previous |
| 6425 | * |
| 6426 | * Find which uplink_seid we were given and create a new VEB if needed |
| 6427 | */ |
| 6428 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 6429 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 6430 | veb = pf->veb[i]; |
| 6431 | break; |
| 6432 | } |
| 6433 | } |
| 6434 | |
| 6435 | if (!veb && uplink_seid != pf->mac_seid) { |
| 6436 | |
| 6437 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 6438 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 6439 | vsi = pf->vsi[i]; |
| 6440 | break; |
| 6441 | } |
| 6442 | } |
| 6443 | if (!vsi) { |
| 6444 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 6445 | uplink_seid); |
| 6446 | return NULL; |
| 6447 | } |
| 6448 | |
| 6449 | if (vsi->uplink_seid == pf->mac_seid) |
| 6450 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 6451 | vsi->tc_config.enabled_tc); |
| 6452 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 6453 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 6454 | vsi->tc_config.enabled_tc); |
| 6455 | |
| 6456 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 6457 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 6458 | veb = pf->veb[i]; |
| 6459 | } |
| 6460 | if (!veb) { |
| 6461 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 6462 | return NULL; |
| 6463 | } |
| 6464 | |
| 6465 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 6466 | uplink_seid = veb->seid; |
| 6467 | } |
| 6468 | |
| 6469 | /* get vsi sw struct */ |
| 6470 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 6471 | if (v_idx < 0) |
| 6472 | goto err_alloc; |
| 6473 | vsi = pf->vsi[v_idx]; |
| 6474 | vsi->type = type; |
| 6475 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 6476 | |
| 6477 | if (type == I40E_VSI_MAIN) |
| 6478 | pf->lan_vsi = v_idx; |
| 6479 | else if (type == I40E_VSI_SRIOV) |
| 6480 | vsi->vf_id = param1; |
| 6481 | /* assign it some queues */ |
| 6482 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 6483 | if (ret < 0) { |
| 6484 | dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n", |
| 6485 | vsi->seid, ret); |
| 6486 | goto err_vsi; |
| 6487 | } |
| 6488 | vsi->base_queue = ret; |
| 6489 | |
| 6490 | /* get a VSI from the hardware */ |
| 6491 | vsi->uplink_seid = uplink_seid; |
| 6492 | ret = i40e_add_vsi(vsi); |
| 6493 | if (ret) |
| 6494 | goto err_vsi; |
| 6495 | |
| 6496 | switch (vsi->type) { |
| 6497 | /* setup the netdev if needed */ |
| 6498 | case I40E_VSI_MAIN: |
| 6499 | case I40E_VSI_VMDQ2: |
| 6500 | ret = i40e_config_netdev(vsi); |
| 6501 | if (ret) |
| 6502 | goto err_netdev; |
| 6503 | ret = register_netdev(vsi->netdev); |
| 6504 | if (ret) |
| 6505 | goto err_netdev; |
| 6506 | vsi->netdev_registered = true; |
| 6507 | netif_carrier_off(vsi->netdev); |
| 6508 | /* fall through */ |
| 6509 | |
| 6510 | case I40E_VSI_FDIR: |
| 6511 | /* set up vectors and rings if needed */ |
| 6512 | ret = i40e_vsi_setup_vectors(vsi); |
| 6513 | if (ret) |
| 6514 | goto err_msix; |
| 6515 | |
| 6516 | ret = i40e_alloc_rings(vsi); |
| 6517 | if (ret) |
| 6518 | goto err_rings; |
| 6519 | |
| 6520 | /* map all of the rings to the q_vectors */ |
| 6521 | i40e_vsi_map_rings_to_vectors(vsi); |
| 6522 | |
| 6523 | i40e_vsi_reset_stats(vsi); |
| 6524 | break; |
| 6525 | |
| 6526 | default: |
| 6527 | /* no netdev or rings for the other VSI types */ |
| 6528 | break; |
| 6529 | } |
| 6530 | |
| 6531 | return vsi; |
| 6532 | |
| 6533 | err_rings: |
| 6534 | i40e_vsi_free_q_vectors(vsi); |
| 6535 | err_msix: |
| 6536 | if (vsi->netdev_registered) { |
| 6537 | vsi->netdev_registered = false; |
| 6538 | unregister_netdev(vsi->netdev); |
| 6539 | free_netdev(vsi->netdev); |
| 6540 | vsi->netdev = NULL; |
| 6541 | } |
| 6542 | err_netdev: |
| 6543 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 6544 | err_vsi: |
| 6545 | i40e_vsi_clear(vsi); |
| 6546 | err_alloc: |
| 6547 | return NULL; |
| 6548 | } |
| 6549 | |
| 6550 | /** |
| 6551 | * i40e_veb_get_bw_info - Query VEB BW information |
| 6552 | * @veb: the veb to query |
| 6553 | * |
| 6554 | * Query the Tx scheduler BW configuration data for given VEB |
| 6555 | **/ |
| 6556 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 6557 | { |
| 6558 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 6559 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 6560 | struct i40e_pf *pf = veb->pf; |
| 6561 | struct i40e_hw *hw = &pf->hw; |
| 6562 | u32 tc_bw_max; |
| 6563 | int ret = 0; |
| 6564 | int i; |
| 6565 | |
| 6566 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 6567 | &bw_data, NULL); |
| 6568 | if (ret) { |
| 6569 | dev_info(&pf->pdev->dev, |
| 6570 | "query veb bw config failed, aq_err=%d\n", |
| 6571 | hw->aq.asq_last_status); |
| 6572 | goto out; |
| 6573 | } |
| 6574 | |
| 6575 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 6576 | &ets_data, NULL); |
| 6577 | if (ret) { |
| 6578 | dev_info(&pf->pdev->dev, |
| 6579 | "query veb bw ets config failed, aq_err=%d\n", |
| 6580 | hw->aq.asq_last_status); |
| 6581 | goto out; |
| 6582 | } |
| 6583 | |
| 6584 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 6585 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 6586 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
| 6587 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 6588 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 6589 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 6590 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 6591 | veb->bw_tc_limit_credits[i] = |
| 6592 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 6593 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 6594 | } |
| 6595 | |
| 6596 | out: |
| 6597 | return ret; |
| 6598 | } |
| 6599 | |
| 6600 | /** |
| 6601 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 6602 | * @pf: board private structure |
| 6603 | * |
| 6604 | * On error: returns error code (negative) |
| 6605 | * On success: returns vsi index in PF (positive) |
| 6606 | **/ |
| 6607 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 6608 | { |
| 6609 | int ret = -ENOENT; |
| 6610 | struct i40e_veb *veb; |
| 6611 | int i; |
| 6612 | |
| 6613 | /* Need to protect the allocation of switch elements at the PF level */ |
| 6614 | mutex_lock(&pf->switch_mutex); |
| 6615 | |
| 6616 | /* VEB list may be fragmented if VEB creation/destruction has |
| 6617 | * been happening. We can afford to do a quick scan to look |
| 6618 | * for any free slots in the list. |
| 6619 | * |
| 6620 | * find next empty veb slot, looping back around if necessary |
| 6621 | */ |
| 6622 | i = 0; |
| 6623 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 6624 | i++; |
| 6625 | if (i >= I40E_MAX_VEB) { |
| 6626 | ret = -ENOMEM; |
| 6627 | goto err_alloc_veb; /* out of VEB slots! */ |
| 6628 | } |
| 6629 | |
| 6630 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 6631 | if (!veb) { |
| 6632 | ret = -ENOMEM; |
| 6633 | goto err_alloc_veb; |
| 6634 | } |
| 6635 | veb->pf = pf; |
| 6636 | veb->idx = i; |
| 6637 | veb->enabled_tc = 1; |
| 6638 | |
| 6639 | pf->veb[i] = veb; |
| 6640 | ret = i; |
| 6641 | err_alloc_veb: |
| 6642 | mutex_unlock(&pf->switch_mutex); |
| 6643 | return ret; |
| 6644 | } |
| 6645 | |
| 6646 | /** |
| 6647 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 6648 | * @branch: where to start deleting |
| 6649 | * |
| 6650 | * This uses recursion to find the tips of the branch to be |
| 6651 | * removed, deleting until we get back to and can delete this VEB. |
| 6652 | **/ |
| 6653 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 6654 | { |
| 6655 | struct i40e_pf *pf = branch->pf; |
| 6656 | u16 branch_seid = branch->seid; |
| 6657 | u16 veb_idx = branch->idx; |
| 6658 | int i; |
| 6659 | |
| 6660 | /* release any VEBs on this VEB - RECURSION */ |
| 6661 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 6662 | if (!pf->veb[i]) |
| 6663 | continue; |
| 6664 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 6665 | i40e_switch_branch_release(pf->veb[i]); |
| 6666 | } |
| 6667 | |
| 6668 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 6669 | * |
| 6670 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 6671 | * the VEB itself, so don't use (*branch) after this loop. |
| 6672 | */ |
| 6673 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 6674 | if (!pf->vsi[i]) |
| 6675 | continue; |
| 6676 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 6677 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 6678 | i40e_vsi_release(pf->vsi[i]); |
| 6679 | } |
| 6680 | } |
| 6681 | |
| 6682 | /* There's one corner case where the VEB might not have been |
| 6683 | * removed, so double check it here and remove it if needed. |
| 6684 | * This case happens if the veb was created from the debugfs |
| 6685 | * commands and no VSIs were added to it. |
| 6686 | */ |
| 6687 | if (pf->veb[veb_idx]) |
| 6688 | i40e_veb_release(pf->veb[veb_idx]); |
| 6689 | } |
| 6690 | |
| 6691 | /** |
| 6692 | * i40e_veb_clear - remove veb struct |
| 6693 | * @veb: the veb to remove |
| 6694 | **/ |
| 6695 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 6696 | { |
| 6697 | if (!veb) |
| 6698 | return; |
| 6699 | |
| 6700 | if (veb->pf) { |
| 6701 | struct i40e_pf *pf = veb->pf; |
| 6702 | |
| 6703 | mutex_lock(&pf->switch_mutex); |
| 6704 | if (pf->veb[veb->idx] == veb) |
| 6705 | pf->veb[veb->idx] = NULL; |
| 6706 | mutex_unlock(&pf->switch_mutex); |
| 6707 | } |
| 6708 | |
| 6709 | kfree(veb); |
| 6710 | } |
| 6711 | |
| 6712 | /** |
| 6713 | * i40e_veb_release - Delete a VEB and free its resources |
| 6714 | * @veb: the VEB being removed |
| 6715 | **/ |
| 6716 | void i40e_veb_release(struct i40e_veb *veb) |
| 6717 | { |
| 6718 | struct i40e_vsi *vsi = NULL; |
| 6719 | struct i40e_pf *pf; |
| 6720 | int i, n = 0; |
| 6721 | |
| 6722 | pf = veb->pf; |
| 6723 | |
| 6724 | /* find the remaining VSI and check for extras */ |
| 6725 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 6726 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 6727 | n++; |
| 6728 | vsi = pf->vsi[i]; |
| 6729 | } |
| 6730 | } |
| 6731 | if (n != 1) { |
| 6732 | dev_info(&pf->pdev->dev, |
| 6733 | "can't remove VEB %d with %d VSIs left\n", |
| 6734 | veb->seid, n); |
| 6735 | return; |
| 6736 | } |
| 6737 | |
| 6738 | /* move the remaining VSI to uplink veb */ |
| 6739 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 6740 | if (veb->uplink_seid) { |
| 6741 | vsi->uplink_seid = veb->uplink_seid; |
| 6742 | if (veb->uplink_seid == pf->mac_seid) |
| 6743 | vsi->veb_idx = I40E_NO_VEB; |
| 6744 | else |
| 6745 | vsi->veb_idx = veb->veb_idx; |
| 6746 | } else { |
| 6747 | /* floating VEB */ |
| 6748 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 6749 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 6750 | } |
| 6751 | |
| 6752 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 6753 | i40e_veb_clear(veb); |
| 6754 | |
| 6755 | return; |
| 6756 | } |
| 6757 | |
| 6758 | /** |
| 6759 | * i40e_add_veb - create the VEB in the switch |
| 6760 | * @veb: the VEB to be instantiated |
| 6761 | * @vsi: the controlling VSI |
| 6762 | **/ |
| 6763 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 6764 | { |
| 6765 | bool is_default = (vsi->idx == vsi->back->lan_vsi); |
Kevin Scott | e1c51b95 | 2013-11-20 10:02:51 +0000 | [diff] [blame] | 6766 | bool is_cloud = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6767 | int ret; |
| 6768 | |
| 6769 | /* get a VEB from the hardware */ |
| 6770 | 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] | 6771 | veb->enabled_tc, is_default, |
| 6772 | is_cloud, &veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6773 | if (ret) { |
| 6774 | dev_info(&veb->pf->pdev->dev, |
| 6775 | "couldn't add VEB, err %d, aq_err %d\n", |
| 6776 | ret, veb->pf->hw.aq.asq_last_status); |
| 6777 | return -EPERM; |
| 6778 | } |
| 6779 | |
| 6780 | /* get statistics counter */ |
| 6781 | ret = i40e_aq_get_veb_parameters(&veb->pf->hw, veb->seid, NULL, NULL, |
| 6782 | &veb->stats_idx, NULL, NULL, NULL); |
| 6783 | if (ret) { |
| 6784 | dev_info(&veb->pf->pdev->dev, |
| 6785 | "couldn't get VEB statistics idx, err %d, aq_err %d\n", |
| 6786 | ret, veb->pf->hw.aq.asq_last_status); |
| 6787 | return -EPERM; |
| 6788 | } |
| 6789 | ret = i40e_veb_get_bw_info(veb); |
| 6790 | if (ret) { |
| 6791 | dev_info(&veb->pf->pdev->dev, |
| 6792 | "couldn't get VEB bw info, err %d, aq_err %d\n", |
| 6793 | ret, veb->pf->hw.aq.asq_last_status); |
| 6794 | i40e_aq_delete_element(&veb->pf->hw, veb->seid, NULL); |
| 6795 | return -ENOENT; |
| 6796 | } |
| 6797 | |
| 6798 | vsi->uplink_seid = veb->seid; |
| 6799 | vsi->veb_idx = veb->idx; |
| 6800 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 6801 | |
| 6802 | return 0; |
| 6803 | } |
| 6804 | |
| 6805 | /** |
| 6806 | * i40e_veb_setup - Set up a VEB |
| 6807 | * @pf: board private structure |
| 6808 | * @flags: VEB setup flags |
| 6809 | * @uplink_seid: the switch element to link to |
| 6810 | * @vsi_seid: the initial VSI seid |
| 6811 | * @enabled_tc: Enabled TC bit-map |
| 6812 | * |
| 6813 | * This allocates the sw VEB structure and links it into the switch |
| 6814 | * It is possible and legal for this to be a duplicate of an already |
| 6815 | * existing VEB. It is also possible for both uplink and vsi seids |
| 6816 | * to be zero, in order to create a floating VEB. |
| 6817 | * |
| 6818 | * Returns pointer to the successfully allocated VEB sw struct on |
| 6819 | * success, otherwise returns NULL on failure. |
| 6820 | **/ |
| 6821 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 6822 | u16 uplink_seid, u16 vsi_seid, |
| 6823 | u8 enabled_tc) |
| 6824 | { |
| 6825 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 6826 | int vsi_idx, veb_idx; |
| 6827 | int ret; |
| 6828 | |
| 6829 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 6830 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 6831 | (uplink_seid + vsi_seid != 0)) { |
| 6832 | dev_info(&pf->pdev->dev, |
| 6833 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 6834 | uplink_seid, vsi_seid); |
| 6835 | return NULL; |
| 6836 | } |
| 6837 | |
| 6838 | /* make sure there is such a vsi and uplink */ |
| 6839 | for (vsi_idx = 0; vsi_idx < pf->hw.func_caps.num_vsis; vsi_idx++) |
| 6840 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 6841 | break; |
| 6842 | if (vsi_idx >= pf->hw.func_caps.num_vsis && vsi_seid != 0) { |
| 6843 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 6844 | vsi_seid); |
| 6845 | return NULL; |
| 6846 | } |
| 6847 | |
| 6848 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 6849 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 6850 | if (pf->veb[veb_idx] && |
| 6851 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 6852 | uplink_veb = pf->veb[veb_idx]; |
| 6853 | break; |
| 6854 | } |
| 6855 | } |
| 6856 | if (!uplink_veb) { |
| 6857 | dev_info(&pf->pdev->dev, |
| 6858 | "uplink seid %d not found\n", uplink_seid); |
| 6859 | return NULL; |
| 6860 | } |
| 6861 | } |
| 6862 | |
| 6863 | /* get veb sw struct */ |
| 6864 | veb_idx = i40e_veb_mem_alloc(pf); |
| 6865 | if (veb_idx < 0) |
| 6866 | goto err_alloc; |
| 6867 | veb = pf->veb[veb_idx]; |
| 6868 | veb->flags = flags; |
| 6869 | veb->uplink_seid = uplink_seid; |
| 6870 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 6871 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 6872 | |
| 6873 | /* create the VEB in the switch */ |
| 6874 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 6875 | if (ret) |
| 6876 | goto err_veb; |
| 6877 | |
| 6878 | return veb; |
| 6879 | |
| 6880 | err_veb: |
| 6881 | i40e_veb_clear(veb); |
| 6882 | err_alloc: |
| 6883 | return NULL; |
| 6884 | } |
| 6885 | |
| 6886 | /** |
| 6887 | * i40e_setup_pf_switch_element - set pf vars based on switch type |
| 6888 | * @pf: board private structure |
| 6889 | * @ele: element we are building info from |
| 6890 | * @num_reported: total number of elements |
| 6891 | * @printconfig: should we print the contents |
| 6892 | * |
| 6893 | * helper function to assist in extracting a few useful SEID values. |
| 6894 | **/ |
| 6895 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 6896 | struct i40e_aqc_switch_config_element_resp *ele, |
| 6897 | u16 num_reported, bool printconfig) |
| 6898 | { |
| 6899 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 6900 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 6901 | u8 element_type = ele->element_type; |
| 6902 | u16 seid = le16_to_cpu(ele->seid); |
| 6903 | |
| 6904 | if (printconfig) |
| 6905 | dev_info(&pf->pdev->dev, |
| 6906 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 6907 | element_type, seid, uplink_seid, downlink_seid); |
| 6908 | |
| 6909 | switch (element_type) { |
| 6910 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 6911 | pf->mac_seid = seid; |
| 6912 | break; |
| 6913 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 6914 | /* Main VEB? */ |
| 6915 | if (uplink_seid != pf->mac_seid) |
| 6916 | break; |
| 6917 | if (pf->lan_veb == I40E_NO_VEB) { |
| 6918 | int v; |
| 6919 | |
| 6920 | /* find existing or else empty VEB */ |
| 6921 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 6922 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 6923 | pf->lan_veb = v; |
| 6924 | break; |
| 6925 | } |
| 6926 | } |
| 6927 | if (pf->lan_veb == I40E_NO_VEB) { |
| 6928 | v = i40e_veb_mem_alloc(pf); |
| 6929 | if (v < 0) |
| 6930 | break; |
| 6931 | pf->lan_veb = v; |
| 6932 | } |
| 6933 | } |
| 6934 | |
| 6935 | pf->veb[pf->lan_veb]->seid = seid; |
| 6936 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 6937 | pf->veb[pf->lan_veb]->pf = pf; |
| 6938 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 6939 | break; |
| 6940 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 6941 | if (num_reported != 1) |
| 6942 | break; |
| 6943 | /* This is immediately after a reset so we can assume this is |
| 6944 | * the PF's VSI |
| 6945 | */ |
| 6946 | pf->mac_seid = uplink_seid; |
| 6947 | pf->pf_seid = downlink_seid; |
| 6948 | pf->main_vsi_seid = seid; |
| 6949 | if (printconfig) |
| 6950 | dev_info(&pf->pdev->dev, |
| 6951 | "pf_seid=%d main_vsi_seid=%d\n", |
| 6952 | pf->pf_seid, pf->main_vsi_seid); |
| 6953 | break; |
| 6954 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 6955 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 6956 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 6957 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 6958 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 6959 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 6960 | /* ignore these for now */ |
| 6961 | break; |
| 6962 | default: |
| 6963 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 6964 | element_type, seid); |
| 6965 | break; |
| 6966 | } |
| 6967 | } |
| 6968 | |
| 6969 | /** |
| 6970 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 6971 | * @pf: board private structure |
| 6972 | * @printconfig: should we print the contents |
| 6973 | * |
| 6974 | * Get the current switch configuration from the device and |
| 6975 | * extract a few useful SEID values. |
| 6976 | **/ |
| 6977 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 6978 | { |
| 6979 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 6980 | u16 next_seid = 0; |
| 6981 | int ret = 0; |
| 6982 | u8 *aq_buf; |
| 6983 | int i; |
| 6984 | |
| 6985 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 6986 | if (!aq_buf) |
| 6987 | return -ENOMEM; |
| 6988 | |
| 6989 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 6990 | do { |
| 6991 | u16 num_reported, num_total; |
| 6992 | |
| 6993 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 6994 | I40E_AQ_LARGE_BUF, |
| 6995 | &next_seid, NULL); |
| 6996 | if (ret) { |
| 6997 | dev_info(&pf->pdev->dev, |
| 6998 | "get switch config failed %d aq_err=%x\n", |
| 6999 | ret, pf->hw.aq.asq_last_status); |
| 7000 | kfree(aq_buf); |
| 7001 | return -ENOENT; |
| 7002 | } |
| 7003 | |
| 7004 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 7005 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 7006 | |
| 7007 | if (printconfig) |
| 7008 | dev_info(&pf->pdev->dev, |
| 7009 | "header: %d reported %d total\n", |
| 7010 | num_reported, num_total); |
| 7011 | |
| 7012 | if (num_reported) { |
| 7013 | int sz = sizeof(*sw_config) * num_reported; |
| 7014 | |
| 7015 | kfree(pf->sw_config); |
| 7016 | pf->sw_config = kzalloc(sz, GFP_KERNEL); |
| 7017 | if (pf->sw_config) |
| 7018 | memcpy(pf->sw_config, sw_config, sz); |
| 7019 | } |
| 7020 | |
| 7021 | for (i = 0; i < num_reported; i++) { |
| 7022 | struct i40e_aqc_switch_config_element_resp *ele = |
| 7023 | &sw_config->element[i]; |
| 7024 | |
| 7025 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 7026 | printconfig); |
| 7027 | } |
| 7028 | } while (next_seid != 0); |
| 7029 | |
| 7030 | kfree(aq_buf); |
| 7031 | return ret; |
| 7032 | } |
| 7033 | |
| 7034 | /** |
| 7035 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 7036 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7037 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7038 | * |
| 7039 | * Returns 0 on success, negative value on failure |
| 7040 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7041 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7042 | { |
Jesse Brandeburg | 895106a | 2013-11-26 10:49:16 +0000 | [diff] [blame] | 7043 | u32 rxfc = 0, txfc = 0, rxfc_reg; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7044 | int ret; |
| 7045 | |
| 7046 | /* find out what's out there already */ |
| 7047 | ret = i40e_fetch_switch_configuration(pf, false); |
| 7048 | if (ret) { |
| 7049 | dev_info(&pf->pdev->dev, |
| 7050 | "couldn't fetch switch config, err %d, aq_err %d\n", |
| 7051 | ret, pf->hw.aq.asq_last_status); |
| 7052 | return ret; |
| 7053 | } |
| 7054 | i40e_pf_reset_stats(pf); |
| 7055 | |
| 7056 | /* fdir VSI must happen first to be sure it gets queue 0, but only |
| 7057 | * if there is enough room for the fdir VSI |
| 7058 | */ |
| 7059 | if (pf->num_lan_qps > 1) |
| 7060 | i40e_fdir_setup(pf); |
| 7061 | |
| 7062 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7063 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7064 | struct i40e_vsi *vsi = NULL; |
| 7065 | u16 uplink_seid; |
| 7066 | |
| 7067 | /* Set up the PF VSI associated with the PF's main VSI |
| 7068 | * that is already in the HW switch |
| 7069 | */ |
| 7070 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 7071 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 7072 | else |
| 7073 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7074 | if (pf->lan_vsi == I40E_NO_VSI) |
| 7075 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 7076 | else if (reinit) |
| 7077 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7078 | if (!vsi) { |
| 7079 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 7080 | i40e_fdir_teardown(pf); |
| 7081 | return -EAGAIN; |
| 7082 | } |
| 7083 | /* accommodate kcompat by copying the main VSI queue count |
| 7084 | * into the pf, since this newer code pushes the pf queue |
| 7085 | * info down a level into a VSI |
| 7086 | */ |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 7087 | pf->num_rx_queues = vsi->num_queue_pairs; |
| 7088 | pf->num_tx_queues = vsi->num_queue_pairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7089 | } else { |
| 7090 | /* force a reset of TC and queue layout configurations */ |
| 7091 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 7092 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 7093 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 7094 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 7095 | } |
| 7096 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 7097 | |
| 7098 | /* Setup static PF queue filter control settings */ |
| 7099 | ret = i40e_setup_pf_filter_control(pf); |
| 7100 | if (ret) { |
| 7101 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 7102 | ret); |
| 7103 | /* Failure here should not stop continuing other steps */ |
| 7104 | } |
| 7105 | |
| 7106 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 7107 | * the hash |
| 7108 | */ |
| 7109 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 7110 | i40e_config_rss(pf); |
| 7111 | |
| 7112 | /* fill in link information and enable LSE reporting */ |
| 7113 | i40e_aq_get_link_info(&pf->hw, true, NULL, NULL); |
| 7114 | i40e_link_event(pf); |
| 7115 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 7116 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7117 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 7118 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 7119 | /* requested_mode is set in probe or by ethtool */ |
| 7120 | if (!pf->fc_autoneg_status) |
| 7121 | goto no_autoneg; |
| 7122 | |
| 7123 | if ((pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) && |
| 7124 | (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7125 | pf->hw.fc.current_mode = I40E_FC_FULL; |
| 7126 | else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) |
| 7127 | pf->hw.fc.current_mode = I40E_FC_TX_PAUSE; |
| 7128 | else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX) |
| 7129 | pf->hw.fc.current_mode = I40E_FC_RX_PAUSE; |
| 7130 | else |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 7131 | pf->hw.fc.current_mode = I40E_FC_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7132 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 7133 | /* sync the flow control settings with the auto-neg values */ |
| 7134 | switch (pf->hw.fc.current_mode) { |
| 7135 | case I40E_FC_FULL: |
| 7136 | txfc = 1; |
| 7137 | rxfc = 1; |
| 7138 | break; |
| 7139 | case I40E_FC_TX_PAUSE: |
| 7140 | txfc = 1; |
| 7141 | rxfc = 0; |
| 7142 | break; |
| 7143 | case I40E_FC_RX_PAUSE: |
| 7144 | txfc = 0; |
| 7145 | rxfc = 1; |
| 7146 | break; |
| 7147 | case I40E_FC_NONE: |
| 7148 | case I40E_FC_DEFAULT: |
| 7149 | txfc = 0; |
| 7150 | rxfc = 0; |
| 7151 | break; |
| 7152 | case I40E_FC_PFC: |
| 7153 | /* TBD */ |
| 7154 | break; |
| 7155 | /* no default case, we have to handle all possibilities here */ |
| 7156 | } |
| 7157 | |
| 7158 | wr32(&pf->hw, I40E_PRTDCB_FCCFG, txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT); |
| 7159 | |
| 7160 | rxfc_reg = rd32(&pf->hw, I40E_PRTDCB_MFLCN) & |
| 7161 | ~I40E_PRTDCB_MFLCN_RFCE_MASK; |
| 7162 | rxfc_reg |= (rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT); |
| 7163 | |
| 7164 | wr32(&pf->hw, I40E_PRTDCB_MFLCN, rxfc_reg); |
| 7165 | |
| 7166 | goto fc_complete; |
| 7167 | |
| 7168 | no_autoneg: |
| 7169 | /* disable L2 flow control, user can turn it on if they wish */ |
| 7170 | wr32(&pf->hw, I40E_PRTDCB_FCCFG, 0); |
| 7171 | wr32(&pf->hw, I40E_PRTDCB_MFLCN, rd32(&pf->hw, I40E_PRTDCB_MFLCN) & |
| 7172 | ~I40E_PRTDCB_MFLCN_RFCE_MASK); |
| 7173 | |
| 7174 | fc_complete: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7175 | return ret; |
| 7176 | } |
| 7177 | |
| 7178 | /** |
| 7179 | * i40e_set_rss_size - helper to set rss_size |
| 7180 | * @pf: board private structure |
| 7181 | * @queues_left: how many queues |
| 7182 | */ |
| 7183 | static u16 i40e_set_rss_size(struct i40e_pf *pf, int queues_left) |
| 7184 | { |
| 7185 | int num_tc0; |
| 7186 | |
| 7187 | num_tc0 = min_t(int, queues_left, pf->rss_size_max); |
Jesse Brandeburg | bf051a3 | 2013-11-26 10:49:17 +0000 | [diff] [blame] | 7188 | num_tc0 = min_t(int, num_tc0, num_online_cpus()); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7189 | num_tc0 = rounddown_pow_of_two(num_tc0); |
| 7190 | |
| 7191 | return num_tc0; |
| 7192 | } |
| 7193 | |
| 7194 | /** |
| 7195 | * i40e_determine_queue_usage - Work out queue distribution |
| 7196 | * @pf: board private structure |
| 7197 | **/ |
| 7198 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 7199 | { |
| 7200 | int accum_tc_size; |
| 7201 | int queues_left; |
| 7202 | |
| 7203 | pf->num_lan_qps = 0; |
| 7204 | pf->num_tc_qps = rounddown_pow_of_two(pf->num_tc_qps); |
| 7205 | accum_tc_size = (I40E_MAX_TRAFFIC_CLASS - 1) * pf->num_tc_qps; |
| 7206 | |
| 7207 | /* Find the max queues to be put into basic use. We'll always be |
| 7208 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 7209 | * big RSS set. |
| 7210 | */ |
| 7211 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 7212 | |
| 7213 | if (!((pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 7214 | (pf->flags & I40E_FLAG_MQ_ENABLED)) || |
| 7215 | !(pf->flags & (I40E_FLAG_RSS_ENABLED | |
| 7216 | I40E_FLAG_FDIR_ENABLED | I40E_FLAG_DCB_ENABLED)) || |
| 7217 | (queues_left == 1)) { |
| 7218 | |
| 7219 | /* one qp for PF, no queues for anything else */ |
| 7220 | queues_left = 0; |
| 7221 | pf->rss_size = pf->num_lan_qps = 1; |
| 7222 | |
| 7223 | /* make sure all the fancies are disabled */ |
| 7224 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
| 7225 | I40E_FLAG_MQ_ENABLED | |
| 7226 | I40E_FLAG_FDIR_ENABLED | |
| 7227 | I40E_FLAG_FDIR_ATR_ENABLED | |
| 7228 | I40E_FLAG_DCB_ENABLED | |
| 7229 | I40E_FLAG_SRIOV_ENABLED | |
| 7230 | I40E_FLAG_VMDQ_ENABLED); |
| 7231 | |
| 7232 | } else if (pf->flags & I40E_FLAG_RSS_ENABLED && |
| 7233 | !(pf->flags & I40E_FLAG_FDIR_ENABLED) && |
| 7234 | !(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 7235 | |
| 7236 | pf->rss_size = i40e_set_rss_size(pf, queues_left); |
| 7237 | |
| 7238 | queues_left -= pf->rss_size; |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7239 | pf->num_lan_qps = pf->rss_size_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7240 | |
| 7241 | } else if (pf->flags & I40E_FLAG_RSS_ENABLED && |
| 7242 | !(pf->flags & I40E_FLAG_FDIR_ENABLED) && |
| 7243 | (pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 7244 | |
| 7245 | /* save num_tc_qps queues for TCs 1 thru 7 and the rest |
| 7246 | * are set up for RSS in TC0 |
| 7247 | */ |
| 7248 | queues_left -= accum_tc_size; |
| 7249 | |
| 7250 | pf->rss_size = i40e_set_rss_size(pf, queues_left); |
| 7251 | |
| 7252 | queues_left -= pf->rss_size; |
| 7253 | if (queues_left < 0) { |
| 7254 | dev_info(&pf->pdev->dev, "not enough queues for DCB\n"); |
| 7255 | return; |
| 7256 | } |
| 7257 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7258 | pf->num_lan_qps = pf->rss_size_max + accum_tc_size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7259 | |
| 7260 | } else if (pf->flags & I40E_FLAG_RSS_ENABLED && |
| 7261 | (pf->flags & I40E_FLAG_FDIR_ENABLED) && |
| 7262 | !(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 7263 | |
| 7264 | queues_left -= 1; /* save 1 queue for FD */ |
| 7265 | |
| 7266 | pf->rss_size = i40e_set_rss_size(pf, queues_left); |
| 7267 | |
| 7268 | queues_left -= pf->rss_size; |
| 7269 | if (queues_left < 0) { |
| 7270 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director\n"); |
| 7271 | return; |
| 7272 | } |
| 7273 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7274 | pf->num_lan_qps = pf->rss_size_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7275 | |
| 7276 | } else if (pf->flags & I40E_FLAG_RSS_ENABLED && |
| 7277 | (pf->flags & I40E_FLAG_FDIR_ENABLED) && |
| 7278 | (pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 7279 | |
| 7280 | /* save 1 queue for TCs 1 thru 7, |
| 7281 | * 1 queue for flow director, |
| 7282 | * and the rest are set up for RSS in TC0 |
| 7283 | */ |
| 7284 | queues_left -= 1; |
| 7285 | queues_left -= accum_tc_size; |
| 7286 | |
| 7287 | pf->rss_size = i40e_set_rss_size(pf, queues_left); |
| 7288 | queues_left -= pf->rss_size; |
| 7289 | if (queues_left < 0) { |
| 7290 | dev_info(&pf->pdev->dev, "not enough queues for DCB and Flow Director\n"); |
| 7291 | return; |
| 7292 | } |
| 7293 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7294 | pf->num_lan_qps = pf->rss_size_max + accum_tc_size; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7295 | |
| 7296 | } else { |
| 7297 | dev_info(&pf->pdev->dev, |
| 7298 | "Invalid configuration, flags=0x%08llx\n", pf->flags); |
| 7299 | return; |
| 7300 | } |
| 7301 | |
| 7302 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 7303 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
| 7304 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, (queues_left / |
| 7305 | pf->num_vf_qps)); |
| 7306 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 7307 | } |
| 7308 | |
| 7309 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 7310 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 7311 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 7312 | (queues_left / pf->num_vmdq_qps)); |
| 7313 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 7314 | } |
| 7315 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7316 | pf->queues_left = queues_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7317 | return; |
| 7318 | } |
| 7319 | |
| 7320 | /** |
| 7321 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 7322 | * @pf: PF to be setup |
| 7323 | * |
| 7324 | * i40e_setup_pf_filter_control sets up a pf's initial filter control |
| 7325 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 7326 | * based filter sizes required for them. It also enables Flow director, |
| 7327 | * ethertype and macvlan type filter settings for the pf. |
| 7328 | * |
| 7329 | * Returns 0 on success, negative on failure |
| 7330 | **/ |
| 7331 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 7332 | { |
| 7333 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 7334 | |
| 7335 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 7336 | |
| 7337 | /* Flow Director is enabled */ |
| 7338 | if (pf->flags & (I40E_FLAG_FDIR_ENABLED | I40E_FLAG_FDIR_ATR_ENABLED)) |
| 7339 | settings->enable_fdir = true; |
| 7340 | |
| 7341 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 7342 | settings->enable_ethtype = true; |
| 7343 | settings->enable_macvlan = true; |
| 7344 | |
| 7345 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 7346 | return -ENOENT; |
| 7347 | |
| 7348 | return 0; |
| 7349 | } |
| 7350 | |
| 7351 | /** |
| 7352 | * i40e_probe - Device initialization routine |
| 7353 | * @pdev: PCI device information struct |
| 7354 | * @ent: entry in i40e_pci_tbl |
| 7355 | * |
| 7356 | * i40e_probe initializes a pf identified by a pci_dev structure. |
| 7357 | * The OS initialization, configuring of the pf private structure, |
| 7358 | * and a hardware reset occur. |
| 7359 | * |
| 7360 | * Returns 0 on success, negative on failure |
| 7361 | **/ |
| 7362 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 7363 | { |
| 7364 | struct i40e_driver_version dv; |
| 7365 | struct i40e_pf *pf; |
| 7366 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 7367 | static u16 pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7368 | int err = 0; |
| 7369 | u32 len; |
| 7370 | |
| 7371 | err = pci_enable_device_mem(pdev); |
| 7372 | if (err) |
| 7373 | return err; |
| 7374 | |
| 7375 | /* set up for high or low dma */ |
| 7376 | if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) { |
| 7377 | /* coherent mask for the same size will always succeed if |
| 7378 | * dma_set_mask does |
| 7379 | */ |
| 7380 | dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); |
| 7381 | } else if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) { |
| 7382 | dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); |
| 7383 | } else { |
| 7384 | dev_err(&pdev->dev, "DMA configuration failed: %d\n", err); |
| 7385 | err = -EIO; |
| 7386 | goto err_dma; |
| 7387 | } |
| 7388 | |
| 7389 | /* set up pci connections */ |
| 7390 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 7391 | IORESOURCE_MEM), i40e_driver_name); |
| 7392 | if (err) { |
| 7393 | dev_info(&pdev->dev, |
| 7394 | "pci_request_selected_regions failed %d\n", err); |
| 7395 | goto err_pci_reg; |
| 7396 | } |
| 7397 | |
| 7398 | pci_enable_pcie_error_reporting(pdev); |
| 7399 | pci_set_master(pdev); |
| 7400 | |
| 7401 | /* Now that we have a PCI connection, we need to do the |
| 7402 | * low level device setup. This is primarily setting up |
| 7403 | * the Admin Queue structures and then querying for the |
| 7404 | * device's current profile information. |
| 7405 | */ |
| 7406 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 7407 | if (!pf) { |
| 7408 | err = -ENOMEM; |
| 7409 | goto err_pf_alloc; |
| 7410 | } |
| 7411 | pf->next_vsi = 0; |
| 7412 | pf->pdev = pdev; |
| 7413 | set_bit(__I40E_DOWN, &pf->state); |
| 7414 | |
| 7415 | hw = &pf->hw; |
| 7416 | hw->back = pf; |
| 7417 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
| 7418 | pci_resource_len(pdev, 0)); |
| 7419 | if (!hw->hw_addr) { |
| 7420 | err = -EIO; |
| 7421 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 7422 | (unsigned int)pci_resource_start(pdev, 0), |
| 7423 | (unsigned int)pci_resource_len(pdev, 0), err); |
| 7424 | goto err_ioremap; |
| 7425 | } |
| 7426 | hw->vendor_id = pdev->vendor; |
| 7427 | hw->device_id = pdev->device; |
| 7428 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 7429 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 7430 | hw->subsystem_device_id = pdev->subsystem_device; |
| 7431 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 7432 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 7433 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7434 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 7435 | /* do a special CORER for clearing PXE mode once at init */ |
| 7436 | if (hw->revision_id == 0 && |
| 7437 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 7438 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 7439 | i40e_flush(hw); |
| 7440 | msleep(200); |
| 7441 | pf->corer_count++; |
| 7442 | |
| 7443 | i40e_clear_pxe_mode(hw); |
| 7444 | } |
| 7445 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7446 | /* Reset here to make sure all is clean and to define PF 'n' */ |
| 7447 | err = i40e_pf_reset(hw); |
| 7448 | if (err) { |
| 7449 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 7450 | goto err_pf_reset; |
| 7451 | } |
| 7452 | pf->pfr_count++; |
| 7453 | |
| 7454 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 7455 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 7456 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 7457 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 7458 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
| 7459 | snprintf(pf->misc_int_name, sizeof(pf->misc_int_name) - 1, |
| 7460 | "%s-pf%d:misc", |
| 7461 | dev_driver_string(&pf->pdev->dev), pf->hw.pf_id); |
| 7462 | |
| 7463 | err = i40e_init_shared_code(hw); |
| 7464 | if (err) { |
| 7465 | dev_info(&pdev->dev, "init_shared_code failed: %d\n", err); |
| 7466 | goto err_pf_reset; |
| 7467 | } |
| 7468 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 7469 | /* set up a default setting for link flow control */ |
| 7470 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 7471 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7472 | err = i40e_init_adminq(hw); |
| 7473 | dev_info(&pdev->dev, "%s\n", i40e_fw_version_str(hw)); |
Anjali Singhai jain | fe31070 | 2013-11-16 10:00:37 +0000 | [diff] [blame] | 7474 | if (((hw->nvm.version & I40E_NVM_VERSION_HI_MASK) |
| 7475 | >> I40E_NVM_VERSION_HI_SHIFT) != I40E_CURRENT_NVM_VERSION_HI) { |
| 7476 | dev_info(&pdev->dev, |
| 7477 | "warning: NVM version not supported, supported version: %02x.%02x\n", |
| 7478 | I40E_CURRENT_NVM_VERSION_HI, |
| 7479 | I40E_CURRENT_NVM_VERSION_LO); |
| 7480 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7481 | if (err) { |
| 7482 | dev_info(&pdev->dev, |
| 7483 | "init_adminq failed: %d expecting API %02x.%02x\n", |
| 7484 | err, |
| 7485 | I40E_FW_API_VERSION_MAJOR, I40E_FW_API_VERSION_MINOR); |
| 7486 | goto err_pf_reset; |
| 7487 | } |
| 7488 | |
| 7489 | err = i40e_get_capabilities(pf); |
| 7490 | if (err) |
| 7491 | goto err_adminq_setup; |
| 7492 | |
| 7493 | err = i40e_sw_init(pf); |
| 7494 | if (err) { |
| 7495 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 7496 | goto err_sw_init; |
| 7497 | } |
| 7498 | |
| 7499 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 7500 | hw->func_caps.num_rx_qp, |
| 7501 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 7502 | if (err) { |
| 7503 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 7504 | goto err_init_lan_hmc; |
| 7505 | } |
| 7506 | |
| 7507 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 7508 | if (err) { |
| 7509 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 7510 | err = -ENOENT; |
| 7511 | goto err_configure_lan_hmc; |
| 7512 | } |
| 7513 | |
| 7514 | i40e_get_mac_addr(hw, hw->mac.addr); |
| 7515 | if (i40e_validate_mac_addr(hw->mac.addr)) { |
| 7516 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 7517 | err = -EIO; |
| 7518 | goto err_mac_addr; |
| 7519 | } |
| 7520 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
| 7521 | memcpy(hw->mac.perm_addr, hw->mac.addr, ETH_ALEN); |
| 7522 | |
| 7523 | pci_set_drvdata(pdev, pf); |
| 7524 | pci_save_state(pdev); |
| 7525 | |
| 7526 | /* set up periodic task facility */ |
| 7527 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 7528 | pf->service_timer_period = HZ; |
| 7529 | |
| 7530 | INIT_WORK(&pf->service_task, i40e_service_task); |
| 7531 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 7532 | pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; |
| 7533 | pf->link_check_timeout = jiffies; |
| 7534 | |
| 7535 | /* set up the main switch operations */ |
| 7536 | i40e_determine_queue_usage(pf); |
| 7537 | i40e_init_interrupt_scheme(pf); |
| 7538 | |
| 7539 | /* Set up the *vsi struct based on the number of VSIs in the HW, |
| 7540 | * and set up our local tracking of the MAIN PF vsi. |
| 7541 | */ |
| 7542 | len = sizeof(struct i40e_vsi *) * pf->hw.func_caps.num_vsis; |
| 7543 | pf->vsi = kzalloc(len, GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 7544 | if (!pf->vsi) { |
| 7545 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7546 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 7547 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7548 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7549 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7550 | if (err) { |
| 7551 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 7552 | goto err_vsis; |
| 7553 | } |
| 7554 | |
| 7555 | /* The main driver is (mostly) up and happy. We need to set this state |
| 7556 | * before setting up the misc vector or we get a race and the vector |
| 7557 | * ends up disabled forever. |
| 7558 | */ |
| 7559 | clear_bit(__I40E_DOWN, &pf->state); |
| 7560 | |
| 7561 | /* In case of MSIX we are going to setup the misc vector right here |
| 7562 | * to handle admin queue events etc. In case of legacy and MSI |
| 7563 | * the misc functionality and queue processing is combined in |
| 7564 | * the same vector and that gets setup at open. |
| 7565 | */ |
| 7566 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 7567 | err = i40e_setup_misc_vector(pf); |
| 7568 | if (err) { |
| 7569 | dev_info(&pdev->dev, |
| 7570 | "setup of misc vector failed: %d\n", err); |
| 7571 | goto err_vsis; |
| 7572 | } |
| 7573 | } |
| 7574 | |
| 7575 | /* prep for VF support */ |
| 7576 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 7577 | (pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
| 7578 | u32 val; |
| 7579 | |
| 7580 | /* disable link interrupts for VFs */ |
| 7581 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 7582 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 7583 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 7584 | i40e_flush(hw); |
| 7585 | } |
| 7586 | |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 7587 | pfs_found++; |
| 7588 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7589 | i40e_dbg_pf_init(pf); |
| 7590 | |
| 7591 | /* tell the firmware that we're starting */ |
| 7592 | dv.major_version = DRV_VERSION_MAJOR; |
| 7593 | dv.minor_version = DRV_VERSION_MINOR; |
| 7594 | dv.build_version = DRV_VERSION_BUILD; |
| 7595 | dv.subbuild_version = 0; |
| 7596 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 7597 | |
| 7598 | /* since everything's happy, start the service_task timer */ |
| 7599 | mod_timer(&pf->service_timer, |
| 7600 | round_jiffies(jiffies + pf->service_timer_period)); |
| 7601 | |
| 7602 | return 0; |
| 7603 | |
| 7604 | /* Unwind what we've done if something failed in the setup */ |
| 7605 | err_vsis: |
| 7606 | set_bit(__I40E_DOWN, &pf->state); |
| 7607 | err_switch_setup: |
| 7608 | i40e_clear_interrupt_scheme(pf); |
| 7609 | kfree(pf->vsi); |
| 7610 | del_timer_sync(&pf->service_timer); |
| 7611 | err_mac_addr: |
| 7612 | err_configure_lan_hmc: |
| 7613 | (void)i40e_shutdown_lan_hmc(hw); |
| 7614 | err_init_lan_hmc: |
| 7615 | kfree(pf->qp_pile); |
| 7616 | kfree(pf->irq_pile); |
| 7617 | err_sw_init: |
| 7618 | err_adminq_setup: |
| 7619 | (void)i40e_shutdown_adminq(hw); |
| 7620 | err_pf_reset: |
| 7621 | iounmap(hw->hw_addr); |
| 7622 | err_ioremap: |
| 7623 | kfree(pf); |
| 7624 | err_pf_alloc: |
| 7625 | pci_disable_pcie_error_reporting(pdev); |
| 7626 | pci_release_selected_regions(pdev, |
| 7627 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 7628 | err_pci_reg: |
| 7629 | err_dma: |
| 7630 | pci_disable_device(pdev); |
| 7631 | return err; |
| 7632 | } |
| 7633 | |
| 7634 | /** |
| 7635 | * i40e_remove - Device removal routine |
| 7636 | * @pdev: PCI device information struct |
| 7637 | * |
| 7638 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 7639 | * that is should release a PCI device. This could be caused by a |
| 7640 | * Hot-Plug event, or because the driver is going to be removed from |
| 7641 | * memory. |
| 7642 | **/ |
| 7643 | static void i40e_remove(struct pci_dev *pdev) |
| 7644 | { |
| 7645 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 7646 | i40e_status ret_code; |
| 7647 | u32 reg; |
| 7648 | int i; |
| 7649 | |
| 7650 | i40e_dbg_pf_exit(pf); |
| 7651 | |
| 7652 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 7653 | i40e_free_vfs(pf); |
| 7654 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 7655 | } |
| 7656 | |
| 7657 | /* no more scheduling of any task */ |
| 7658 | set_bit(__I40E_DOWN, &pf->state); |
| 7659 | del_timer_sync(&pf->service_timer); |
| 7660 | cancel_work_sync(&pf->service_task); |
| 7661 | |
| 7662 | i40e_fdir_teardown(pf); |
| 7663 | |
| 7664 | /* If there is a switch structure or any orphans, remove them. |
| 7665 | * This will leave only the PF's VSI remaining. |
| 7666 | */ |
| 7667 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 7668 | if (!pf->veb[i]) |
| 7669 | continue; |
| 7670 | |
| 7671 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 7672 | pf->veb[i]->uplink_seid == 0) |
| 7673 | i40e_switch_branch_release(pf->veb[i]); |
| 7674 | } |
| 7675 | |
| 7676 | /* Now we can shutdown the PF's VSI, just before we kill |
| 7677 | * adminq and hmc. |
| 7678 | */ |
| 7679 | if (pf->vsi[pf->lan_vsi]) |
| 7680 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 7681 | |
| 7682 | i40e_stop_misc_vector(pf); |
| 7683 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 7684 | synchronize_irq(pf->msix_entries[0].vector); |
| 7685 | free_irq(pf->msix_entries[0].vector, pf); |
| 7686 | } |
| 7687 | |
| 7688 | /* shutdown and destroy the HMC */ |
| 7689 | ret_code = i40e_shutdown_lan_hmc(&pf->hw); |
| 7690 | if (ret_code) |
| 7691 | dev_warn(&pdev->dev, |
| 7692 | "Failed to destroy the HMC resources: %d\n", ret_code); |
| 7693 | |
| 7694 | /* shutdown the adminq */ |
| 7695 | i40e_aq_queue_shutdown(&pf->hw, true); |
| 7696 | ret_code = i40e_shutdown_adminq(&pf->hw); |
| 7697 | if (ret_code) |
| 7698 | dev_warn(&pdev->dev, |
| 7699 | "Failed to destroy the Admin Queue resources: %d\n", |
| 7700 | ret_code); |
| 7701 | |
| 7702 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 7703 | i40e_clear_interrupt_scheme(pf); |
| 7704 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 7705 | if (pf->vsi[i]) { |
| 7706 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 7707 | i40e_vsi_clear(pf->vsi[i]); |
| 7708 | pf->vsi[i] = NULL; |
| 7709 | } |
| 7710 | } |
| 7711 | |
| 7712 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 7713 | kfree(pf->veb[i]); |
| 7714 | pf->veb[i] = NULL; |
| 7715 | } |
| 7716 | |
| 7717 | kfree(pf->qp_pile); |
| 7718 | kfree(pf->irq_pile); |
| 7719 | kfree(pf->sw_config); |
| 7720 | kfree(pf->vsi); |
| 7721 | |
| 7722 | /* force a PF reset to clean anything leftover */ |
| 7723 | reg = rd32(&pf->hw, I40E_PFGEN_CTRL); |
| 7724 | wr32(&pf->hw, I40E_PFGEN_CTRL, (reg | I40E_PFGEN_CTRL_PFSWR_MASK)); |
| 7725 | i40e_flush(&pf->hw); |
| 7726 | |
| 7727 | iounmap(pf->hw.hw_addr); |
| 7728 | kfree(pf); |
| 7729 | pci_release_selected_regions(pdev, |
| 7730 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 7731 | |
| 7732 | pci_disable_pcie_error_reporting(pdev); |
| 7733 | pci_disable_device(pdev); |
| 7734 | } |
| 7735 | |
| 7736 | /** |
| 7737 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 7738 | * @pdev: PCI device information struct |
| 7739 | * |
| 7740 | * Called to warn that something happened and the error handling steps |
| 7741 | * are in progress. Allows the driver to quiesce things, be ready for |
| 7742 | * remediation. |
| 7743 | **/ |
| 7744 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 7745 | enum pci_channel_state error) |
| 7746 | { |
| 7747 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 7748 | |
| 7749 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 7750 | |
| 7751 | /* shutdown all operations */ |
| 7752 | i40e_pf_quiesce_all_vsi(pf); |
| 7753 | |
| 7754 | /* Request a slot reset */ |
| 7755 | return PCI_ERS_RESULT_NEED_RESET; |
| 7756 | } |
| 7757 | |
| 7758 | /** |
| 7759 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 7760 | * @pdev: PCI device information struct |
| 7761 | * |
| 7762 | * Called to find if the driver can work with the device now that |
| 7763 | * the pci slot has been reset. If a basic connection seems good |
| 7764 | * (registers are readable and have sane content) then return a |
| 7765 | * happy little PCI_ERS_RESULT_xxx. |
| 7766 | **/ |
| 7767 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 7768 | { |
| 7769 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 7770 | pci_ers_result_t result; |
| 7771 | int err; |
| 7772 | u32 reg; |
| 7773 | |
| 7774 | dev_info(&pdev->dev, "%s\n", __func__); |
| 7775 | if (pci_enable_device_mem(pdev)) { |
| 7776 | dev_info(&pdev->dev, |
| 7777 | "Cannot re-enable PCI device after reset.\n"); |
| 7778 | result = PCI_ERS_RESULT_DISCONNECT; |
| 7779 | } else { |
| 7780 | pci_set_master(pdev); |
| 7781 | pci_restore_state(pdev); |
| 7782 | pci_save_state(pdev); |
| 7783 | pci_wake_from_d3(pdev, false); |
| 7784 | |
| 7785 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 7786 | if (reg == 0) |
| 7787 | result = PCI_ERS_RESULT_RECOVERED; |
| 7788 | else |
| 7789 | result = PCI_ERS_RESULT_DISCONNECT; |
| 7790 | } |
| 7791 | |
| 7792 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 7793 | if (err) { |
| 7794 | dev_info(&pdev->dev, |
| 7795 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 7796 | err); |
| 7797 | /* non-fatal, continue */ |
| 7798 | } |
| 7799 | |
| 7800 | return result; |
| 7801 | } |
| 7802 | |
| 7803 | /** |
| 7804 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 7805 | * @pdev: PCI device information struct |
| 7806 | * |
| 7807 | * Called to allow the driver to bring things back up after PCI error |
| 7808 | * and/or reset recovery has finished. |
| 7809 | **/ |
| 7810 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 7811 | { |
| 7812 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 7813 | |
| 7814 | dev_info(&pdev->dev, "%s\n", __func__); |
| 7815 | i40e_handle_reset_warning(pf); |
| 7816 | } |
| 7817 | |
| 7818 | static const struct pci_error_handlers i40e_err_handler = { |
| 7819 | .error_detected = i40e_pci_error_detected, |
| 7820 | .slot_reset = i40e_pci_error_slot_reset, |
| 7821 | .resume = i40e_pci_error_resume, |
| 7822 | }; |
| 7823 | |
| 7824 | static struct pci_driver i40e_driver = { |
| 7825 | .name = i40e_driver_name, |
| 7826 | .id_table = i40e_pci_tbl, |
| 7827 | .probe = i40e_probe, |
| 7828 | .remove = i40e_remove, |
| 7829 | .err_handler = &i40e_err_handler, |
| 7830 | .sriov_configure = i40e_pci_sriov_configure, |
| 7831 | }; |
| 7832 | |
| 7833 | /** |
| 7834 | * i40e_init_module - Driver registration routine |
| 7835 | * |
| 7836 | * i40e_init_module is the first routine called when the driver is |
| 7837 | * loaded. All it does is register with the PCI subsystem. |
| 7838 | **/ |
| 7839 | static int __init i40e_init_module(void) |
| 7840 | { |
| 7841 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 7842 | i40e_driver_string, i40e_driver_version_str); |
| 7843 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
| 7844 | i40e_dbg_init(); |
| 7845 | return pci_register_driver(&i40e_driver); |
| 7846 | } |
| 7847 | module_init(i40e_init_module); |
| 7848 | |
| 7849 | /** |
| 7850 | * i40e_exit_module - Driver exit cleanup routine |
| 7851 | * |
| 7852 | * i40e_exit_module is called just before the driver is removed |
| 7853 | * from memory. |
| 7854 | **/ |
| 7855 | static void __exit i40e_exit_module(void) |
| 7856 | { |
| 7857 | pci_unregister_driver(&i40e_driver); |
| 7858 | i40e_dbg_exit(); |
| 7859 | } |
| 7860 | module_exit(i40e_exit_module); |