ena.c (0ac122c388d9a5e189e60378f1950b82a22bbdd1) | ena.c (b899a02ad7330cae3c9bb08ad7975601dc3b9551) |
---|---|
1/*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2015-2021 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 --- 2090 unchanged lines hidden (view full) --- 2099 return (ENXIO); 2100 } 2101 2102 if (ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter)) 2103 return (0); 2104 2105 ena_log(adapter->pdev, INFO, "device is going UP\n"); 2106 | 1/*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2015-2021 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 --- 2090 unchanged lines hidden (view full) --- 2099 return (ENXIO); 2100 } 2101 2102 if (ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter)) 2103 return (0); 2104 2105 ena_log(adapter->pdev, INFO, "device is going UP\n"); 2106 |
2107 /* 2108 * ena_timer_service can use functions, which write to the admin queue. 2109 * Those calls are not protected by ENA_LOCK, and because of that, the 2110 * timer should be stopped when bringing the device up or down. 2111 */ 2112 ENA_TIMER_DRAIN(adapter); 2113 | |
2114 /* setup interrupts for IO queues */ 2115 rc = ena_setup_io_intr(adapter); 2116 if (unlikely(rc != 0)) { 2117 ena_log(adapter->pdev, ERR, "error setting up IO interrupt\n"); 2118 goto error; 2119 } 2120 rc = ena_request_io_irq(adapter); 2121 if (unlikely(rc != 0)) { --- 30 unchanged lines hidden (view full) --- 2152 2153 if_setdrvflagbits(adapter->ifp, IFF_DRV_RUNNING, 2154 IFF_DRV_OACTIVE); 2155 2156 ENA_FLAG_SET_ATOMIC(ENA_FLAG_DEV_UP, adapter); 2157 2158 ena_unmask_all_io_irqs(adapter); 2159 | 2107 /* setup interrupts for IO queues */ 2108 rc = ena_setup_io_intr(adapter); 2109 if (unlikely(rc != 0)) { 2110 ena_log(adapter->pdev, ERR, "error setting up IO interrupt\n"); 2111 goto error; 2112 } 2113 rc = ena_request_io_irq(adapter); 2114 if (unlikely(rc != 0)) { --- 30 unchanged lines hidden (view full) --- 2145 2146 if_setdrvflagbits(adapter->ifp, IFF_DRV_RUNNING, 2147 IFF_DRV_OACTIVE); 2148 2149 ENA_FLAG_SET_ATOMIC(ENA_FLAG_DEV_UP, adapter); 2150 2151 ena_unmask_all_io_irqs(adapter); 2152 |
2160 ENA_TIMER_RESET(adapter); 2161 | |
2162 return (0); 2163 2164err_up_complete: 2165 ena_destroy_all_io_queues(adapter); 2166 ena_free_all_rx_resources(adapter); 2167 ena_free_all_tx_resources(adapter); 2168err_create_queues_with_backoff: 2169 ena_free_io_irq(adapter); 2170error: | 2153 return (0); 2154 2155err_up_complete: 2156 ena_destroy_all_io_queues(adapter); 2157 ena_free_all_rx_resources(adapter); 2158 ena_free_all_tx_resources(adapter); 2159err_create_queues_with_backoff: 2160 ena_free_io_irq(adapter); 2161error: |
2171 ENA_TIMER_RESET(adapter); 2172 | |
2173 return (rc); 2174} 2175 2176static uint64_t 2177ena_get_counter(if_t ifp, ift_counter cnt) 2178{ 2179 struct ena_adapter *adapter; 2180 struct ena_hw_stats *stats; --- 288 unchanged lines hidden (view full) --- 2469{ 2470 int rc; 2471 2472 ENA_LOCK_ASSERT(); 2473 2474 if (!ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter)) 2475 return; 2476 | 2162 return (rc); 2163} 2164 2165static uint64_t 2166ena_get_counter(if_t ifp, ift_counter cnt) 2167{ 2168 struct ena_adapter *adapter; 2169 struct ena_hw_stats *stats; --- 288 unchanged lines hidden (view full) --- 2458{ 2459 int rc; 2460 2461 ENA_LOCK_ASSERT(); 2462 2463 if (!ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter)) 2464 return; 2465 |
2477 /* Drain timer service to avoid admin queue race condition. */ 2478 ENA_TIMER_DRAIN(adapter); 2479 | |
2480 ena_log(adapter->pdev, INFO, "device is going DOWN\n"); 2481 2482 ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_DEV_UP, adapter); 2483 if_setdrvflagbits(adapter->ifp, IFF_DRV_OACTIVE, 2484 IFF_DRV_RUNNING); 2485 2486 ena_free_io_irq(adapter); 2487 --- 8 unchanged lines hidden (view full) --- 2496 ena_destroy_all_io_queues(adapter); 2497 2498 ena_free_all_tx_bufs(adapter); 2499 ena_free_all_rx_bufs(adapter); 2500 ena_free_all_tx_resources(adapter); 2501 ena_free_all_rx_resources(adapter); 2502 2503 counter_u64_add(adapter->dev_stats.interface_down, 1); | 2466 ena_log(adapter->pdev, INFO, "device is going DOWN\n"); 2467 2468 ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_DEV_UP, adapter); 2469 if_setdrvflagbits(adapter->ifp, IFF_DRV_OACTIVE, 2470 IFF_DRV_RUNNING); 2471 2472 ena_free_io_irq(adapter); 2473 --- 8 unchanged lines hidden (view full) --- 2482 ena_destroy_all_io_queues(adapter); 2483 2484 ena_free_all_tx_bufs(adapter); 2485 ena_free_all_rx_bufs(adapter); 2486 ena_free_all_tx_resources(adapter); 2487 ena_free_all_rx_resources(adapter); 2488 2489 counter_u64_add(adapter->dev_stats.interface_down, 1); |
2504 2505 ENA_TIMER_RESET(adapter); | |
2506} 2507 2508static uint32_t 2509ena_calc_max_io_queue_num(device_t pdev, struct ena_com_dev *ena_dev, 2510 struct ena_com_dev_get_features_ctx *get_feat_ctx) 2511{ 2512 uint32_t io_tx_sq_num, io_tx_cq_num, io_rx_num, max_num_io_queues; 2513 --- 756 unchanged lines hidden (view full) --- 3270 * Otherwise, wait 'eni_metrics_sample_interval' seconds, before 3271 * updating stats. 3272 * As timer service is executed every second, it's enough to increment 3273 * appropriate counter each time the timer service is executed. 3274 */ 3275 if ((adapter->eni_metrics_sample_interval != 0) && 3276 (++adapter->eni_metrics_sample_interval_cnt >= 3277 adapter->eni_metrics_sample_interval)) { | 2490} 2491 2492static uint32_t 2493ena_calc_max_io_queue_num(device_t pdev, struct ena_com_dev *ena_dev, 2494 struct ena_com_dev_get_features_ctx *get_feat_ctx) 2495{ 2496 uint32_t io_tx_sq_num, io_tx_cq_num, io_rx_num, max_num_io_queues; 2497 --- 756 unchanged lines hidden (view full) --- 3254 * Otherwise, wait 'eni_metrics_sample_interval' seconds, before 3255 * updating stats. 3256 * As timer service is executed every second, it's enough to increment 3257 * appropriate counter each time the timer service is executed. 3258 */ 3259 if ((adapter->eni_metrics_sample_interval != 0) && 3260 (++adapter->eni_metrics_sample_interval_cnt >= 3261 adapter->eni_metrics_sample_interval)) { |
3278 /* 3279 * There is no race with other admin queue calls, as: 3280 * - Timer service runs after attach function ends, so all 3281 * configuration calls to the admin queue are finished. 3282 * - Timer service is temporarily stopped when bringing 3283 * the interface up or down. 3284 * - After interface is up, the driver doesn't use (at least 3285 * for now) other functions writing to the admin queue. 3286 * 3287 * It may change in the future, so in that situation, the lock 3288 * will be needed. ENA_LOCK_*() cannot be used for that purpose, 3289 * as callout ena_timer_service is protected by them. It could 3290 * lead to the deadlock if callout_drain() would hold the lock 3291 * before ena_copy_eni_metrics() was executed. It's advised to 3292 * use separate lock in that situation which will be used only 3293 * for the admin queue. 3294 */ 3295 (void)ena_copy_eni_metrics(adapter); | 3262 taskqueue_enqueue(adapter->metrics_tq, &adapter->metrics_task); |
3296 adapter->eni_metrics_sample_interval_cnt = 0; 3297 } 3298 3299 3300 if (host_info != NULL) 3301 ena_update_host_info(host_info, adapter->ifp); 3302 3303 if (unlikely(ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) { --- 191 unchanged lines hidden (view full) --- 3495 ena_log(dev, ERR, "Reset attempt failed. Can not reset the device\n"); 3496 3497 ENA_TIMER_RESET(adapter); 3498 3499 return (rc); 3500} 3501 3502static void | 3263 adapter->eni_metrics_sample_interval_cnt = 0; 3264 } 3265 3266 3267 if (host_info != NULL) 3268 ena_update_host_info(host_info, adapter->ifp); 3269 3270 if (unlikely(ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) { --- 191 unchanged lines hidden (view full) --- 3462 ena_log(dev, ERR, "Reset attempt failed. Can not reset the device\n"); 3463 3464 ENA_TIMER_RESET(adapter); 3465 3466 return (rc); 3467} 3468 3469static void |
3470ena_metrics_task(void *arg, int pending) 3471{ 3472 struct ena_adapter *adapter = (struct ena_adapter *)arg; 3473 3474 ENA_LOCK_LOCK(); 3475 (void)ena_copy_eni_metrics(adapter); 3476 ENA_LOCK_UNLOCK(); 3477} 3478 3479static void |
|
3503ena_reset_task(void *arg, int pending) 3504{ 3505 struct ena_adapter *adapter = (struct ena_adapter *)arg; 3506 3507 ENA_LOCK_LOCK(); 3508 if (likely(ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) { 3509 ena_destroy_device(adapter, false); 3510 ena_restore_device(adapter); --- 203 unchanged lines hidden (view full) --- 3714 3715 /* Initialize reset task queue */ 3716 TASK_INIT(&adapter->reset_task, 0, ena_reset_task, adapter); 3717 adapter->reset_tq = taskqueue_create("ena_reset_enqueue", 3718 M_WAITOK | M_ZERO, taskqueue_thread_enqueue, &adapter->reset_tq); 3719 taskqueue_start_threads(&adapter->reset_tq, 1, PI_NET, 3720 "%s rstq", device_get_nameunit(adapter->pdev)); 3721 | 3480ena_reset_task(void *arg, int pending) 3481{ 3482 struct ena_adapter *adapter = (struct ena_adapter *)arg; 3483 3484 ENA_LOCK_LOCK(); 3485 if (likely(ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) { 3486 ena_destroy_device(adapter, false); 3487 ena_restore_device(adapter); --- 203 unchanged lines hidden (view full) --- 3691 3692 /* Initialize reset task queue */ 3693 TASK_INIT(&adapter->reset_task, 0, ena_reset_task, adapter); 3694 adapter->reset_tq = taskqueue_create("ena_reset_enqueue", 3695 M_WAITOK | M_ZERO, taskqueue_thread_enqueue, &adapter->reset_tq); 3696 taskqueue_start_threads(&adapter->reset_tq, 1, PI_NET, 3697 "%s rstq", device_get_nameunit(adapter->pdev)); 3698 |
3699 /* Initialize metrics task queue */ 3700 TASK_INIT(&adapter->metrics_task, 0, ena_metrics_task, adapter); 3701 adapter->metrics_tq = taskqueue_create("ena_metrics_enqueue", 3702 M_WAITOK | M_ZERO, taskqueue_thread_enqueue, &adapter->metrics_tq); 3703 taskqueue_start_threads(&adapter->metrics_tq, 1, PI_NET, 3704 "%s metricsq", device_get_nameunit(adapter->pdev)); 3705 |
|
3722 /* Initialize statistics */ 3723 ena_alloc_counters((counter_u64_t *)&adapter->dev_stats, 3724 sizeof(struct ena_stats_dev)); 3725 ena_alloc_counters((counter_u64_t *)&adapter->hw_stats, 3726 sizeof(struct ena_hw_stats)); 3727 ena_sysctl_add_nodes(adapter); 3728 3729#ifdef DEV_NETMAP --- 62 unchanged lines hidden (view full) --- 3792 3793 ether_ifdetach(adapter->ifp); 3794 3795 /* Stop timer service */ 3796 ENA_LOCK_LOCK(); 3797 ENA_TIMER_DRAIN(adapter); 3798 ENA_LOCK_UNLOCK(); 3799 | 3706 /* Initialize statistics */ 3707 ena_alloc_counters((counter_u64_t *)&adapter->dev_stats, 3708 sizeof(struct ena_stats_dev)); 3709 ena_alloc_counters((counter_u64_t *)&adapter->hw_stats, 3710 sizeof(struct ena_hw_stats)); 3711 ena_sysctl_add_nodes(adapter); 3712 3713#ifdef DEV_NETMAP --- 62 unchanged lines hidden (view full) --- 3776 3777 ether_ifdetach(adapter->ifp); 3778 3779 /* Stop timer service */ 3780 ENA_LOCK_LOCK(); 3781 ENA_TIMER_DRAIN(adapter); 3782 ENA_LOCK_UNLOCK(); 3783 |
3784 /* Release metrics task */ 3785 while (taskqueue_cancel(adapter->metrics_tq, &adapter->metrics_task, NULL)) 3786 taskqueue_drain(adapter->metrics_tq, &adapter->metrics_task); 3787 taskqueue_free(adapter->metrics_tq); 3788 |
|
3800 /* Release reset task */ 3801 while (taskqueue_cancel(adapter->reset_tq, &adapter->reset_task, NULL)) 3802 taskqueue_drain(adapter->reset_tq, &adapter->reset_task); 3803 taskqueue_free(adapter->reset_tq); 3804 3805 ENA_LOCK_LOCK(); 3806 ena_down(adapter); 3807 ena_destroy_device(adapter, true); --- 164 unchanged lines hidden --- | 3789 /* Release reset task */ 3790 while (taskqueue_cancel(adapter->reset_tq, &adapter->reset_task, NULL)) 3791 taskqueue_drain(adapter->reset_tq, &adapter->reset_task); 3792 taskqueue_free(adapter->reset_tq); 3793 3794 ENA_LOCK_LOCK(); 3795 ena_down(adapter); 3796 ena_destroy_device(adapter, true); --- 164 unchanged lines hidden --- |