ena.c (21823546222b3f7da1dc2cfe47576ed3cce5f214) ena.c (e2735b095b7e31a6e07b8639ed151456a610bc07)
1/*-
2 * BSD LICENSE
3 *
4 * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 1548 unchanged lines hidden (view full) ---

1557 "Not enough number of MSI-x allocated: %d\n",
1558 msix_vecs);
1559 pci_release_msi(dev);
1560 rc = ENOSPC;
1561 goto err_msix_free;
1562 }
1563 device_printf(dev, "Enable only %d MSI-x (out of %d), reduce "
1564 "the number of queues\n", msix_vecs, msix_req);
1/*-
2 * BSD LICENSE
3 *
4 * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 1548 unchanged lines hidden (view full) ---

1557 "Not enough number of MSI-x allocated: %d\n",
1558 msix_vecs);
1559 pci_release_msi(dev);
1560 rc = ENOSPC;
1561 goto err_msix_free;
1562 }
1563 device_printf(dev, "Enable only %d MSI-x (out of %d), reduce "
1564 "the number of queues\n", msix_vecs, msix_req);
1565 adapter->num_io_queues = msix_vecs - ENA_ADMIN_MSIX_VEC;
1566 }
1567
1568 adapter->msix_vecs = msix_vecs;
1569 ENA_FLAG_SET_ATOMIC(ENA_FLAG_MSIX_ENABLED, adapter);
1570
1571 return (0);
1572
1573err_msix_free:

--- 1537 unchanged lines hidden (view full) ---

3111 */
3112 if (!(ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter) && dev_up))
3113 ena_com_dev_reset(adapter->ena_dev, adapter->reset_reason);
3114
3115 ena_free_mgmnt_irq(adapter);
3116
3117 ena_disable_msix(adapter);
3118
1565 }
1566
1567 adapter->msix_vecs = msix_vecs;
1568 ENA_FLAG_SET_ATOMIC(ENA_FLAG_MSIX_ENABLED, adapter);
1569
1570 return (0);
1571
1572err_msix_free:

--- 1537 unchanged lines hidden (view full) ---

3110 */
3111 if (!(ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter) && dev_up))
3112 ena_com_dev_reset(adapter->ena_dev, adapter->reset_reason);
3113
3114 ena_free_mgmnt_irq(adapter);
3115
3116 ena_disable_msix(adapter);
3117
3118 /*
3119 * IO rings resources should be freed because `ena_restore_device()`
3120 * calls (not directly) `ena_enable_msix()`, which re-allocates MSIX
3121 * vectors. The amount of MSIX vectors after destroy-restore may be
3122 * different than before. Therefore, IO rings resources should be
3123 * established from scratch each time.
3124 */
3125 ena_free_all_io_rings_resources(adapter);
3126
3119 ena_com_abort_admin_commands(ena_dev);
3120
3121 ena_com_wait_for_abort_completion(ena_dev);
3122
3123 ena_com_admin_destroy(ena_dev);
3124
3125 ena_com_mmio_reg_read_request_destroy(ena_dev);
3126

--- 60 unchanged lines hidden (view full) ---

3187 if_link_state_change(ifp, LINK_STATE_UP);
3188
3189 rc = ena_enable_msix_and_set_admin_interrupts(adapter);
3190 if (rc != 0) {
3191 device_printf(dev, "Enable MSI-X failed\n");
3192 goto err_device_destroy;
3193 }
3194
3127 ena_com_abort_admin_commands(ena_dev);
3128
3129 ena_com_wait_for_abort_completion(ena_dev);
3130
3131 ena_com_admin_destroy(ena_dev);
3132
3133 ena_com_mmio_reg_read_request_destroy(ena_dev);
3134

--- 60 unchanged lines hidden (view full) ---

3195 if_link_state_change(ifp, LINK_STATE_UP);
3196
3197 rc = ena_enable_msix_and_set_admin_interrupts(adapter);
3198 if (rc != 0) {
3199 device_printf(dev, "Enable MSI-X failed\n");
3200 goto err_device_destroy;
3201 }
3202
3203 /*
3204 * Effective value of used MSIX vectors should be the same as before
3205 * `ena_destroy_device()`, if possible, or closest to it if less vectors
3206 * are available.
3207 */
3208 if ((adapter->msix_vecs - ENA_ADMIN_MSIX_VEC) < adapter->num_io_queues)
3209 adapter->num_io_queues =
3210 adapter->msix_vecs - ENA_ADMIN_MSIX_VEC;
3211
3212 /* Re-initialize rings basic information */
3213 ena_init_io_rings(adapter);
3214
3195 /* If the interface was up before the reset bring it up */
3196 if (ENA_FLAG_ISSET(ENA_FLAG_DEV_UP_BEFORE_RESET, adapter)) {
3197 rc = ena_up(adapter);
3198 if (rc != 0) {
3199 device_printf(dev, "Failed to create I/O queues\n");
3200 goto err_disable_msix;
3201 }
3202 }

--- 171 unchanged lines hidden (view full) ---

3374 adapter->tx_ring_size = calc_queue_ctx.tx_queue_size;
3375 adapter->rx_ring_size = calc_queue_ctx.rx_queue_size;
3376 adapter->max_tx_ring_size = calc_queue_ctx.max_tx_queue_size;
3377 adapter->max_rx_ring_size = calc_queue_ctx.max_rx_queue_size;
3378 adapter->max_tx_sgl_size = calc_queue_ctx.max_tx_sgl_size;
3379 adapter->max_rx_sgl_size = calc_queue_ctx.max_rx_sgl_size;
3380
3381 adapter->max_num_io_queues = max_num_io_queues;
3215 /* If the interface was up before the reset bring it up */
3216 if (ENA_FLAG_ISSET(ENA_FLAG_DEV_UP_BEFORE_RESET, adapter)) {
3217 rc = ena_up(adapter);
3218 if (rc != 0) {
3219 device_printf(dev, "Failed to create I/O queues\n");
3220 goto err_disable_msix;
3221 }
3222 }

--- 171 unchanged lines hidden (view full) ---

3394 adapter->tx_ring_size = calc_queue_ctx.tx_queue_size;
3395 adapter->rx_ring_size = calc_queue_ctx.rx_queue_size;
3396 adapter->max_tx_ring_size = calc_queue_ctx.max_tx_queue_size;
3397 adapter->max_rx_ring_size = calc_queue_ctx.max_rx_queue_size;
3398 adapter->max_tx_sgl_size = calc_queue_ctx.max_tx_sgl_size;
3399 adapter->max_rx_sgl_size = calc_queue_ctx.max_rx_sgl_size;
3400
3401 adapter->max_num_io_queues = max_num_io_queues;
3382 adapter->num_io_queues = max_num_io_queues;
3383
3384 adapter->buf_ring_size = ENA_DEFAULT_BUF_RING_SIZE;
3385
3386 adapter->max_mtu = get_feat_ctx.dev_attr.max_mtu;
3387
3388 adapter->reset_reason = ENA_REGS_RESET_NORMAL;
3389
3390 /* set up dma tags for rx and tx buffers */

--- 4 unchanged lines hidden (view full) ---

3395 }
3396
3397 rc = ena_setup_rx_dma_tag(adapter);
3398 if (unlikely(rc != 0)) {
3399 device_printf(pdev, "Failed to create RX DMA tag\n");
3400 goto err_tx_tag_free;
3401 }
3402
3402
3403 adapter->buf_ring_size = ENA_DEFAULT_BUF_RING_SIZE;
3404
3405 adapter->max_mtu = get_feat_ctx.dev_attr.max_mtu;
3406
3407 adapter->reset_reason = ENA_REGS_RESET_NORMAL;
3408
3409 /* set up dma tags for rx and tx buffers */

--- 4 unchanged lines hidden (view full) ---

3414 }
3415
3416 rc = ena_setup_rx_dma_tag(adapter);
3417 if (unlikely(rc != 0)) {
3418 device_printf(pdev, "Failed to create RX DMA tag\n");
3419 goto err_tx_tag_free;
3420 }
3421
3403 /* initialize rings basic information */
3404 ena_init_io_rings(adapter);
3405
3422 /*
3423 * The amount of requested MSIX vectors is equal to
3424 * adapter::max_num_io_queues (see `ena_enable_msix()`), plus a constant
3425 * number of admin queue interrupts. The former is initially determined
3426 * by HW capabilities (see `ena_calc_max_io_queue_num())` but may not be
3427 * achieved if there are not enough system resources. By default, the
3428 * number of effectively used IO queues is the same but later on it can
3429 * be limited by the user using sysctl interface.
3430 */
3406 rc = ena_enable_msix_and_set_admin_interrupts(adapter);
3407 if (unlikely(rc != 0)) {
3408 device_printf(pdev,
3409 "Failed to enable and set the admin interrupts\n");
3410 goto err_io_free;
3411 }
3431 rc = ena_enable_msix_and_set_admin_interrupts(adapter);
3432 if (unlikely(rc != 0)) {
3433 device_printf(pdev,
3434 "Failed to enable and set the admin interrupts\n");
3435 goto err_io_free;
3436 }
3437 /* By default all of allocated MSIX vectors are actively used */
3438 adapter->num_io_queues = adapter->msix_vecs - ENA_ADMIN_MSIX_VEC;
3412
3439
3440 /* initialize rings basic information */
3441 ena_init_io_rings(adapter);
3442
3413 /* setup network interface */
3414 rc = ena_setup_ifnet(pdev, adapter, &get_feat_ctx);
3415 if (unlikely(rc != 0)) {
3416 device_printf(pdev, "Error with network interface setup\n");
3417 goto err_msix_free;
3418 }
3419
3420 /* Initialize reset task queue */

--- 238 unchanged lines hidden ---
3443 /* setup network interface */
3444 rc = ena_setup_ifnet(pdev, adapter, &get_feat_ctx);
3445 if (unlikely(rc != 0)) {
3446 device_printf(pdev, "Error with network interface setup\n");
3447 goto err_msix_free;
3448 }
3449
3450 /* Initialize reset task queue */

--- 238 unchanged lines hidden ---