15433956dSTimothy McDaniel /* SPDX-License-Identifier: BSD-3-Clause 25433956dSTimothy McDaniel * Copyright(c) 2016-2020 Intel Corporation 35433956dSTimothy McDaniel */ 45433956dSTimothy McDaniel 55433956dSTimothy McDaniel #include <stdint.h> 65433956dSTimothy McDaniel #include <stdbool.h> 75433956dSTimothy McDaniel #include <stdio.h> 85433956dSTimothy McDaniel #include <sys/mman.h> 929420808SThomas Monjalon #include <fcntl.h> 105433956dSTimothy McDaniel #include <sys/time.h> 115433956dSTimothy McDaniel #include <errno.h> 125433956dSTimothy McDaniel #include <assert.h> 135433956dSTimothy McDaniel #include <unistd.h> 145433956dSTimothy McDaniel #include <string.h> 1529420808SThomas Monjalon 165433956dSTimothy McDaniel #include <rte_debug.h> 175433956dSTimothy McDaniel #include <rte_log.h> 181acb7f54SDavid Marchand #include <dev_driver.h> 195433956dSTimothy McDaniel #include <rte_devargs.h> 205433956dSTimothy McDaniel #include <rte_mbuf.h> 215433956dSTimothy McDaniel #include <rte_ring.h> 225433956dSTimothy McDaniel #include <rte_errno.h> 235433956dSTimothy McDaniel #include <rte_kvargs.h> 245433956dSTimothy McDaniel #include <rte_malloc.h> 255433956dSTimothy McDaniel #include <rte_cycles.h> 265433956dSTimothy McDaniel #include <rte_io.h> 275433956dSTimothy McDaniel #include <rte_pci.h> 281f37cb2bSDavid Marchand #include <bus_pci_driver.h> 295433956dSTimothy McDaniel #include <rte_eventdev.h> 3025187042SBruce Richardson #include <eventdev_pmd.h> 3125187042SBruce Richardson #include <eventdev_pmd_pci.h> 325433956dSTimothy McDaniel #include <rte_memory.h> 335433956dSTimothy McDaniel #include <rte_string_fns.h> 345433956dSTimothy McDaniel 355433956dSTimothy McDaniel #include "../dlb2_priv.h" 36e7c9971aSTimothy McDaniel #include "../dlb2_iface.h" 375433956dSTimothy McDaniel #include "../dlb2_inline_fns.h" 385433956dSTimothy McDaniel #include "dlb2_main.h" 39037a6167STimothy McDaniel #include "base/dlb2_hw_types.h" 405433956dSTimothy McDaniel #include "base/dlb2_osdep.h" 41dfdd11a8STimothy McDaniel #include "base/dlb2_resource.h" 425433956dSTimothy McDaniel 435433956dSTimothy McDaniel static const char *event_dlb2_pf_name = RTE_STR(EVDEV_DLB2_NAME_PMD); 44ffa46fc4STimothy McDaniel static unsigned int dlb2_qe_sa_pct = 1; 45ffa46fc4STimothy McDaniel static unsigned int dlb2_qid_sa_pct; 465433956dSTimothy McDaniel 47e7c9971aSTimothy McDaniel static void 48e7c9971aSTimothy McDaniel dlb2_pf_low_level_io_init(void) 495433956dSTimothy McDaniel { 50e7c9971aSTimothy McDaniel int i; 51e7c9971aSTimothy McDaniel /* Addresses will be initialized at port create */ 52b66a418dSTimothy McDaniel for (i = 0; i < DLB2_MAX_NUM_PORTS(DLB2_HW_V2_5); i++) { 53e7c9971aSTimothy McDaniel /* First directed ports */ 54e7c9971aSTimothy McDaniel dlb2_port[i][DLB2_DIR_PORT].pp_addr = NULL; 55e7c9971aSTimothy McDaniel dlb2_port[i][DLB2_DIR_PORT].cq_base = NULL; 56e7c9971aSTimothy McDaniel dlb2_port[i][DLB2_DIR_PORT].mmaped = true; 57e7c9971aSTimothy McDaniel 58e7c9971aSTimothy McDaniel /* Now load balanced ports */ 59e7c9971aSTimothy McDaniel dlb2_port[i][DLB2_LDB_PORT].pp_addr = NULL; 60e7c9971aSTimothy McDaniel dlb2_port[i][DLB2_LDB_PORT].cq_base = NULL; 61e7c9971aSTimothy McDaniel dlb2_port[i][DLB2_LDB_PORT].mmaped = true; 62e7c9971aSTimothy McDaniel } 63e7c9971aSTimothy McDaniel } 64e7c9971aSTimothy McDaniel 65e7c9971aSTimothy McDaniel static int 66e7c9971aSTimothy McDaniel dlb2_pf_open(struct dlb2_hw_dev *handle, const char *name) 67e7c9971aSTimothy McDaniel { 68e7c9971aSTimothy McDaniel RTE_SET_USED(handle); 69e7c9971aSTimothy McDaniel RTE_SET_USED(name); 705433956dSTimothy McDaniel 715433956dSTimothy McDaniel return 0; 725433956dSTimothy McDaniel } 735433956dSTimothy McDaniel 74e7c9971aSTimothy McDaniel static int 75e7c9971aSTimothy McDaniel dlb2_pf_get_device_version(struct dlb2_hw_dev *handle, 76e7c9971aSTimothy McDaniel uint8_t *revision) 775433956dSTimothy McDaniel { 78e7c9971aSTimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 79e7c9971aSTimothy McDaniel 80e7c9971aSTimothy McDaniel *revision = dlb2_dev->revision; 81e7c9971aSTimothy McDaniel 82e7c9971aSTimothy McDaniel return 0; 835433956dSTimothy McDaniel } 845433956dSTimothy McDaniel 85ffa46fc4STimothy McDaniel static void dlb2_pf_calc_arbiter_weights(u8 *weight, 86ffa46fc4STimothy McDaniel unsigned int pct) 87ffa46fc4STimothy McDaniel { 88ffa46fc4STimothy McDaniel int val, i; 89ffa46fc4STimothy McDaniel 90ffa46fc4STimothy McDaniel /* Largest possible weight (100% SA case): 32 */ 91ffa46fc4STimothy McDaniel val = (DLB2_MAX_WEIGHT + 1) / DLB2_NUM_ARB_WEIGHTS; 92ffa46fc4STimothy McDaniel 93ffa46fc4STimothy McDaniel /* Scale val according to the starvation avoidance percentage */ 94ffa46fc4STimothy McDaniel val = (val * pct) / 100; 95ffa46fc4STimothy McDaniel if (val == 0 && pct != 0) 96ffa46fc4STimothy McDaniel val = 1; 97ffa46fc4STimothy McDaniel 98ffa46fc4STimothy McDaniel /* Prio 7 always has weight 0xff */ 99ffa46fc4STimothy McDaniel weight[DLB2_NUM_ARB_WEIGHTS - 1] = DLB2_MAX_WEIGHT; 100ffa46fc4STimothy McDaniel 101ffa46fc4STimothy McDaniel for (i = DLB2_NUM_ARB_WEIGHTS - 2; i >= 0; i--) 102ffa46fc4STimothy McDaniel weight[i] = weight[i + 1] - val; 103ffa46fc4STimothy McDaniel } 104ffa46fc4STimothy McDaniel 105ffa46fc4STimothy McDaniel 106e7c9971aSTimothy McDaniel static void 107e7c9971aSTimothy McDaniel dlb2_pf_hardware_init(struct dlb2_hw_dev *handle) 1085433956dSTimothy McDaniel { 109e7c9971aSTimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 110e7c9971aSTimothy McDaniel 111e7c9971aSTimothy McDaniel dlb2_hw_enable_sparse_ldb_cq_mode(&dlb2_dev->hw); 112e7c9971aSTimothy McDaniel dlb2_hw_enable_sparse_dir_cq_mode(&dlb2_dev->hw); 113ffa46fc4STimothy McDaniel 114ffa46fc4STimothy McDaniel /* Configure arbitration weights for QE selection */ 115ffa46fc4STimothy McDaniel if (dlb2_qe_sa_pct <= 100) { 116ffa46fc4STimothy McDaniel u8 weight[DLB2_NUM_ARB_WEIGHTS]; 117ffa46fc4STimothy McDaniel 118ffa46fc4STimothy McDaniel dlb2_pf_calc_arbiter_weights(weight, 119ffa46fc4STimothy McDaniel dlb2_qe_sa_pct); 120ffa46fc4STimothy McDaniel 121ffa46fc4STimothy McDaniel dlb2_hw_set_qe_arbiter_weights(&dlb2_dev->hw, weight); 122ffa46fc4STimothy McDaniel } 123ffa46fc4STimothy McDaniel 124ffa46fc4STimothy McDaniel /* Configure arbitration weights for QID selection */ 125ffa46fc4STimothy McDaniel if (dlb2_qid_sa_pct <= 100) { 126ffa46fc4STimothy McDaniel u8 weight[DLB2_NUM_ARB_WEIGHTS]; 127ffa46fc4STimothy McDaniel 128ffa46fc4STimothy McDaniel dlb2_pf_calc_arbiter_weights(weight, 129ffa46fc4STimothy McDaniel dlb2_qid_sa_pct); 130ffa46fc4STimothy McDaniel 131ffa46fc4STimothy McDaniel dlb2_hw_set_qid_arbiter_weights(&dlb2_dev->hw, weight); 132ffa46fc4STimothy McDaniel } 133ffa46fc4STimothy McDaniel 1345433956dSTimothy McDaniel } 135e7c9971aSTimothy McDaniel 136e7c9971aSTimothy McDaniel static int 137e7c9971aSTimothy McDaniel dlb2_pf_get_num_resources(struct dlb2_hw_dev *handle, 138e7c9971aSTimothy McDaniel struct dlb2_get_num_resources_args *rsrcs) 139e7c9971aSTimothy McDaniel { 140e7c9971aSTimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 141e7c9971aSTimothy McDaniel 142e7c9971aSTimothy McDaniel return dlb2_hw_get_num_resources(&dlb2_dev->hw, rsrcs, false, 0); 143e7c9971aSTimothy McDaniel } 144e7c9971aSTimothy McDaniel 145e7c9971aSTimothy McDaniel static int 146e7c9971aSTimothy McDaniel dlb2_pf_get_cq_poll_mode(struct dlb2_hw_dev *handle, 147e7c9971aSTimothy McDaniel enum dlb2_cq_poll_modes *mode) 148e7c9971aSTimothy McDaniel { 149e7c9971aSTimothy McDaniel RTE_SET_USED(handle); 150e7c9971aSTimothy McDaniel 151e7c9971aSTimothy McDaniel *mode = DLB2_CQ_POLL_MODE_SPARSE; 152e7c9971aSTimothy McDaniel 153e7c9971aSTimothy McDaniel return 0; 154e7c9971aSTimothy McDaniel } 1555433956dSTimothy McDaniel 156f3cad285STimothy McDaniel static int 157f3cad285STimothy McDaniel dlb2_pf_sched_domain_create(struct dlb2_hw_dev *handle, 158f3cad285STimothy McDaniel struct dlb2_create_sched_domain_args *arg) 159f3cad285STimothy McDaniel { 160f3cad285STimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 161f3cad285STimothy McDaniel struct dlb2_cmd_response response = {0}; 162f3cad285STimothy McDaniel int ret; 163f3cad285STimothy McDaniel 164f3cad285STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Entering %s()\n", __func__); 165f3cad285STimothy McDaniel 166f3cad285STimothy McDaniel if (dlb2_dev->domain_reset_failed) { 167f3cad285STimothy McDaniel response.status = DLB2_ST_DOMAIN_RESET_FAILED; 168f3cad285STimothy McDaniel ret = -EINVAL; 169f3cad285STimothy McDaniel goto done; 170f3cad285STimothy McDaniel } 171f3cad285STimothy McDaniel 172f3cad285STimothy McDaniel ret = dlb2_pf_create_sched_domain(&dlb2_dev->hw, arg, &response); 173f3cad285STimothy McDaniel if (ret) 174f3cad285STimothy McDaniel goto done; 175f3cad285STimothy McDaniel 176f3cad285STimothy McDaniel done: 177f3cad285STimothy McDaniel 178f3cad285STimothy McDaniel arg->response = response; 179f3cad285STimothy McDaniel 180f3cad285STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Exiting %s() with ret=%d\n", 181f3cad285STimothy McDaniel __func__, ret); 182f3cad285STimothy McDaniel 183f3cad285STimothy McDaniel return ret; 184f3cad285STimothy McDaniel } 185f3cad285STimothy McDaniel 186f3cad285STimothy McDaniel static void 187f3cad285STimothy McDaniel dlb2_pf_domain_reset(struct dlb2_eventdev *dlb2) 188f3cad285STimothy McDaniel { 189f3cad285STimothy McDaniel struct dlb2_dev *dlb2_dev; 190f3cad285STimothy McDaniel int ret; 191f3cad285STimothy McDaniel 192f3cad285STimothy McDaniel dlb2_dev = (struct dlb2_dev *)dlb2->qm_instance.pf_dev; 193f3cad285STimothy McDaniel ret = dlb2_pf_reset_domain(&dlb2_dev->hw, dlb2->qm_instance.domain_id); 194f3cad285STimothy McDaniel if (ret) 195f3cad285STimothy McDaniel DLB2_LOG_ERR("dlb2_pf_reset_domain err %d", ret); 196f3cad285STimothy McDaniel } 197f3cad285STimothy McDaniel 1987e668e57STimothy McDaniel static int 1997e668e57STimothy McDaniel dlb2_pf_ldb_queue_create(struct dlb2_hw_dev *handle, 2007e668e57STimothy McDaniel struct dlb2_create_ldb_queue_args *cfg) 2017e668e57STimothy McDaniel { 2027e668e57STimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 2037e668e57STimothy McDaniel struct dlb2_cmd_response response = {0}; 2047e668e57STimothy McDaniel int ret; 2057e668e57STimothy McDaniel 2067e668e57STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Entering %s()\n", __func__); 2077e668e57STimothy McDaniel 2087e668e57STimothy McDaniel ret = dlb2_pf_create_ldb_queue(&dlb2_dev->hw, 2097e668e57STimothy McDaniel handle->domain_id, 2107e668e57STimothy McDaniel cfg, 2117e668e57STimothy McDaniel &response); 2127e668e57STimothy McDaniel 2137e668e57STimothy McDaniel cfg->response = response; 2147e668e57STimothy McDaniel 2157e668e57STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Exiting %s() with ret=%d\n", 2167e668e57STimothy McDaniel __func__, ret); 2177e668e57STimothy McDaniel 2187e668e57STimothy McDaniel return ret; 2197e668e57STimothy McDaniel } 2207e668e57STimothy McDaniel 2217e668e57STimothy McDaniel static int 2227e668e57STimothy McDaniel dlb2_pf_get_sn_occupancy(struct dlb2_hw_dev *handle, 2237e668e57STimothy McDaniel struct dlb2_get_sn_occupancy_args *args) 2247e668e57STimothy McDaniel { 2257e668e57STimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 2267e668e57STimothy McDaniel struct dlb2_cmd_response response = {0}; 2277e668e57STimothy McDaniel int ret; 2287e668e57STimothy McDaniel 2297e668e57STimothy McDaniel ret = dlb2_get_group_sequence_number_occupancy(&dlb2_dev->hw, 2307e668e57STimothy McDaniel args->group); 2317e668e57STimothy McDaniel 2327e668e57STimothy McDaniel response.id = ret; 2337e668e57STimothy McDaniel response.status = 0; 2347e668e57STimothy McDaniel 2357e668e57STimothy McDaniel args->response = response; 2367e668e57STimothy McDaniel 2377e668e57STimothy McDaniel return ret; 2387e668e57STimothy McDaniel } 2397e668e57STimothy McDaniel 2407e668e57STimothy McDaniel static int 2417e668e57STimothy McDaniel dlb2_pf_get_sn_allocation(struct dlb2_hw_dev *handle, 2427e668e57STimothy McDaniel struct dlb2_get_sn_allocation_args *args) 2437e668e57STimothy McDaniel { 2447e668e57STimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 2457e668e57STimothy McDaniel struct dlb2_cmd_response response = {0}; 2467e668e57STimothy McDaniel int ret; 2477e668e57STimothy McDaniel 2487e668e57STimothy McDaniel ret = dlb2_get_group_sequence_numbers(&dlb2_dev->hw, args->group); 2497e668e57STimothy McDaniel 2507e668e57STimothy McDaniel response.id = ret; 2517e668e57STimothy McDaniel response.status = 0; 2527e668e57STimothy McDaniel 2537e668e57STimothy McDaniel args->response = response; 2547e668e57STimothy McDaniel 2557e668e57STimothy McDaniel return ret; 2567e668e57STimothy McDaniel } 2577e668e57STimothy McDaniel 2587e668e57STimothy McDaniel static int 2597e668e57STimothy McDaniel dlb2_pf_set_sn_allocation(struct dlb2_hw_dev *handle, 2607e668e57STimothy McDaniel struct dlb2_set_sn_allocation_args *args) 2617e668e57STimothy McDaniel { 2627e668e57STimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 2637e668e57STimothy McDaniel struct dlb2_cmd_response response = {0}; 2647e668e57STimothy McDaniel int ret; 2657e668e57STimothy McDaniel 2667e668e57STimothy McDaniel ret = dlb2_set_group_sequence_numbers(&dlb2_dev->hw, args->group, 2677e668e57STimothy McDaniel args->num); 2687e668e57STimothy McDaniel 2697e668e57STimothy McDaniel response.status = 0; 2707e668e57STimothy McDaniel 2717e668e57STimothy McDaniel args->response = response; 2727e668e57STimothy McDaniel 2737e668e57STimothy McDaniel return ret; 2747e668e57STimothy McDaniel } 2757e668e57STimothy McDaniel 2763a6d0c04STimothy McDaniel static void * 2773a6d0c04STimothy McDaniel dlb2_alloc_coherent_aligned(const struct rte_memzone **mz, uintptr_t *phys, 2783a6d0c04STimothy McDaniel size_t size, int align) 2793a6d0c04STimothy McDaniel { 2803a6d0c04STimothy McDaniel char mz_name[RTE_MEMZONE_NAMESIZE]; 2813a6d0c04STimothy McDaniel uint32_t core_id = rte_lcore_id(); 2823a6d0c04STimothy McDaniel unsigned int socket_id; 2833a6d0c04STimothy McDaniel 2843a6d0c04STimothy McDaniel snprintf(mz_name, sizeof(mz_name) - 1, "event_dlb2_pf_%lx", 2853a6d0c04STimothy McDaniel (unsigned long)rte_get_timer_cycles()); 2863a6d0c04STimothy McDaniel if (core_id == (unsigned int)LCORE_ID_ANY) 2873a6d0c04STimothy McDaniel core_id = rte_get_main_lcore(); 2883a6d0c04STimothy McDaniel socket_id = rte_lcore_to_socket_id(core_id); 2893a6d0c04STimothy McDaniel *mz = rte_memzone_reserve_aligned(mz_name, size, socket_id, 2903a6d0c04STimothy McDaniel RTE_MEMZONE_IOVA_CONTIG, align); 2913a6d0c04STimothy McDaniel if (*mz == NULL) { 292e99981afSDavid Marchand DLB2_LOG_LINE_DBG("Unable to allocate DMA memory of size %zu bytes - %s", 2933a6d0c04STimothy McDaniel size, rte_strerror(rte_errno)); 2943a6d0c04STimothy McDaniel *phys = 0; 2953a6d0c04STimothy McDaniel return NULL; 2963a6d0c04STimothy McDaniel } 2973a6d0c04STimothy McDaniel *phys = (*mz)->iova; 2983a6d0c04STimothy McDaniel return (*mz)->addr; 2993a6d0c04STimothy McDaniel } 3003a6d0c04STimothy McDaniel 3013a6d0c04STimothy McDaniel static int 3023a6d0c04STimothy McDaniel dlb2_pf_ldb_port_create(struct dlb2_hw_dev *handle, 3033a6d0c04STimothy McDaniel struct dlb2_create_ldb_port_args *cfg, 3043a6d0c04STimothy McDaniel enum dlb2_cq_poll_modes poll_mode) 3053a6d0c04STimothy McDaniel { 3063a6d0c04STimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 3073a6d0c04STimothy McDaniel struct dlb2_cmd_response response = {0}; 3083a6d0c04STimothy McDaniel struct dlb2_port_memory port_memory; 3093a6d0c04STimothy McDaniel int ret, cq_alloc_depth; 3103a6d0c04STimothy McDaniel uint8_t *port_base; 3113a6d0c04STimothy McDaniel const struct rte_memzone *mz; 3123a6d0c04STimothy McDaniel int alloc_sz, qe_sz; 3133a6d0c04STimothy McDaniel phys_addr_t cq_base; 3143a6d0c04STimothy McDaniel phys_addr_t pp_base; 3153a6d0c04STimothy McDaniel int is_dir = false; 3163a6d0c04STimothy McDaniel 3173a6d0c04STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Entering %s()\n", __func__); 3183a6d0c04STimothy McDaniel 3193a6d0c04STimothy McDaniel if (poll_mode == DLB2_CQ_POLL_MODE_STD) 3203a6d0c04STimothy McDaniel qe_sz = sizeof(struct dlb2_dequeue_qe); 3213a6d0c04STimothy McDaniel else 3223a6d0c04STimothy McDaniel qe_sz = RTE_CACHE_LINE_SIZE; 3233a6d0c04STimothy McDaniel 3243a6d0c04STimothy McDaniel /* Calculate the port memory required, and round up to the nearest 3253a6d0c04STimothy McDaniel * cache line. 3263a6d0c04STimothy McDaniel */ 3273a6d0c04STimothy McDaniel cq_alloc_depth = RTE_MAX(cfg->cq_depth, DLB2_MIN_HARDWARE_CQ_DEPTH); 3283a6d0c04STimothy McDaniel alloc_sz = cq_alloc_depth * qe_sz; 3293a6d0c04STimothy McDaniel alloc_sz = RTE_CACHE_LINE_ROUNDUP(alloc_sz); 3303a6d0c04STimothy McDaniel 3313a6d0c04STimothy McDaniel port_base = dlb2_alloc_coherent_aligned(&mz, &cq_base, alloc_sz, 332924e6b76SThomas Monjalon rte_mem_page_size()); 3333a6d0c04STimothy McDaniel if (port_base == NULL) 3343a6d0c04STimothy McDaniel return -ENOMEM; 3353a6d0c04STimothy McDaniel 3363a6d0c04STimothy McDaniel /* Lock the page in memory */ 3373a6d0c04STimothy McDaniel ret = rte_mem_lock_page(port_base); 3383a6d0c04STimothy McDaniel if (ret < 0) { 339*f665790aSDavid Marchand DLB2_LOG_ERR("dlb2 pf pmd could not lock page for device i/o"); 3403a6d0c04STimothy McDaniel goto create_port_err; 3413a6d0c04STimothy McDaniel } 3423a6d0c04STimothy McDaniel 3433a6d0c04STimothy McDaniel memset(port_base, 0, alloc_sz); 3443a6d0c04STimothy McDaniel 3453a6d0c04STimothy McDaniel ret = dlb2_pf_create_ldb_port(&dlb2_dev->hw, 3463a6d0c04STimothy McDaniel handle->domain_id, 3473a6d0c04STimothy McDaniel cfg, 3483a6d0c04STimothy McDaniel cq_base, 3493a6d0c04STimothy McDaniel &response); 3503a6d0c04STimothy McDaniel if (ret) 3513a6d0c04STimothy McDaniel goto create_port_err; 3523a6d0c04STimothy McDaniel 3533a6d0c04STimothy McDaniel pp_base = (uintptr_t)dlb2_dev->hw.func_kva + PP_BASE(is_dir); 3543a6d0c04STimothy McDaniel dlb2_port[response.id][DLB2_LDB_PORT].pp_addr = 355924e6b76SThomas Monjalon (void *)(pp_base + (rte_mem_page_size() * response.id)); 3563a6d0c04STimothy McDaniel 3573a6d0c04STimothy McDaniel dlb2_port[response.id][DLB2_LDB_PORT].cq_base = (void *)(port_base); 3583a6d0c04STimothy McDaniel memset(&port_memory, 0, sizeof(port_memory)); 3593a6d0c04STimothy McDaniel 3603a6d0c04STimothy McDaniel dlb2_port[response.id][DLB2_LDB_PORT].mz = mz; 3613a6d0c04STimothy McDaniel 3623a6d0c04STimothy McDaniel dlb2_list_init_head(&port_memory.list); 3633a6d0c04STimothy McDaniel 3643a6d0c04STimothy McDaniel cfg->response = response; 3653a6d0c04STimothy McDaniel 3663a6d0c04STimothy McDaniel return 0; 3673a6d0c04STimothy McDaniel 3683a6d0c04STimothy McDaniel create_port_err: 3693a6d0c04STimothy McDaniel 3703a6d0c04STimothy McDaniel rte_memzone_free(mz); 3713a6d0c04STimothy McDaniel 3723a6d0c04STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Exiting %s() with ret=%d\n", 3733a6d0c04STimothy McDaniel __func__, ret); 3743a6d0c04STimothy McDaniel return ret; 3753a6d0c04STimothy McDaniel } 3763a6d0c04STimothy McDaniel 3773a6d0c04STimothy McDaniel static int 3783a6d0c04STimothy McDaniel dlb2_pf_dir_port_create(struct dlb2_hw_dev *handle, 3793a6d0c04STimothy McDaniel struct dlb2_create_dir_port_args *cfg, 3803a6d0c04STimothy McDaniel enum dlb2_cq_poll_modes poll_mode) 3813a6d0c04STimothy McDaniel { 3823a6d0c04STimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 3833a6d0c04STimothy McDaniel struct dlb2_cmd_response response = {0}; 3843a6d0c04STimothy McDaniel struct dlb2_port_memory port_memory; 3853a6d0c04STimothy McDaniel int ret; 3863a6d0c04STimothy McDaniel uint8_t *port_base; 3873a6d0c04STimothy McDaniel const struct rte_memzone *mz; 3883a6d0c04STimothy McDaniel int alloc_sz, qe_sz; 3893a6d0c04STimothy McDaniel phys_addr_t cq_base; 3903a6d0c04STimothy McDaniel phys_addr_t pp_base; 3913a6d0c04STimothy McDaniel int is_dir = true; 3923a6d0c04STimothy McDaniel 3933a6d0c04STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Entering %s()\n", __func__); 3943a6d0c04STimothy McDaniel 3953a6d0c04STimothy McDaniel if (poll_mode == DLB2_CQ_POLL_MODE_STD) 3963a6d0c04STimothy McDaniel qe_sz = sizeof(struct dlb2_dequeue_qe); 3973a6d0c04STimothy McDaniel else 3983a6d0c04STimothy McDaniel qe_sz = RTE_CACHE_LINE_SIZE; 3993a6d0c04STimothy McDaniel 4003a6d0c04STimothy McDaniel /* Calculate the port memory required, and round up to the nearest 4013a6d0c04STimothy McDaniel * cache line. 4023a6d0c04STimothy McDaniel */ 4033a6d0c04STimothy McDaniel alloc_sz = cfg->cq_depth * qe_sz; 4043a6d0c04STimothy McDaniel alloc_sz = RTE_CACHE_LINE_ROUNDUP(alloc_sz); 4053a6d0c04STimothy McDaniel 4063a6d0c04STimothy McDaniel port_base = dlb2_alloc_coherent_aligned(&mz, &cq_base, alloc_sz, 407924e6b76SThomas Monjalon rte_mem_page_size()); 4083a6d0c04STimothy McDaniel if (port_base == NULL) 4093a6d0c04STimothy McDaniel return -ENOMEM; 4103a6d0c04STimothy McDaniel 4113a6d0c04STimothy McDaniel /* Lock the page in memory */ 4123a6d0c04STimothy McDaniel ret = rte_mem_lock_page(port_base); 4133a6d0c04STimothy McDaniel if (ret < 0) { 414*f665790aSDavid Marchand DLB2_LOG_ERR("dlb2 pf pmd could not lock page for device i/o"); 4153a6d0c04STimothy McDaniel goto create_port_err; 4163a6d0c04STimothy McDaniel } 4173a6d0c04STimothy McDaniel 4183a6d0c04STimothy McDaniel memset(port_base, 0, alloc_sz); 4193a6d0c04STimothy McDaniel 4203a6d0c04STimothy McDaniel ret = dlb2_pf_create_dir_port(&dlb2_dev->hw, 4213a6d0c04STimothy McDaniel handle->domain_id, 4223a6d0c04STimothy McDaniel cfg, 4233a6d0c04STimothy McDaniel cq_base, 4243a6d0c04STimothy McDaniel &response); 4253a6d0c04STimothy McDaniel if (ret) 4263a6d0c04STimothy McDaniel goto create_port_err; 4273a6d0c04STimothy McDaniel 4283a6d0c04STimothy McDaniel pp_base = (uintptr_t)dlb2_dev->hw.func_kva + PP_BASE(is_dir); 4293a6d0c04STimothy McDaniel dlb2_port[response.id][DLB2_DIR_PORT].pp_addr = 430924e6b76SThomas Monjalon (void *)(pp_base + (rte_mem_page_size() * response.id)); 4313a6d0c04STimothy McDaniel 4323a6d0c04STimothy McDaniel dlb2_port[response.id][DLB2_DIR_PORT].cq_base = 4333a6d0c04STimothy McDaniel (void *)(port_base); 4343a6d0c04STimothy McDaniel memset(&port_memory, 0, sizeof(port_memory)); 4353a6d0c04STimothy McDaniel 4363a6d0c04STimothy McDaniel dlb2_port[response.id][DLB2_DIR_PORT].mz = mz; 4373a6d0c04STimothy McDaniel 4383a6d0c04STimothy McDaniel dlb2_list_init_head(&port_memory.list); 4393a6d0c04STimothy McDaniel 4403a6d0c04STimothy McDaniel cfg->response = response; 4413a6d0c04STimothy McDaniel 4423a6d0c04STimothy McDaniel return 0; 4433a6d0c04STimothy McDaniel 4443a6d0c04STimothy McDaniel create_port_err: 4453a6d0c04STimothy McDaniel 4463a6d0c04STimothy McDaniel rte_memzone_free(mz); 4473a6d0c04STimothy McDaniel 4483a6d0c04STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Exiting %s() with ret=%d\n", 4493a6d0c04STimothy McDaniel __func__, ret); 4503a6d0c04STimothy McDaniel 4513a6d0c04STimothy McDaniel return ret; 4523a6d0c04STimothy McDaniel } 4533a6d0c04STimothy McDaniel 4541acd82c0STimothy McDaniel static int 4551acd82c0STimothy McDaniel dlb2_pf_dir_queue_create(struct dlb2_hw_dev *handle, 4561acd82c0STimothy McDaniel struct dlb2_create_dir_queue_args *cfg) 4571acd82c0STimothy McDaniel { 4581acd82c0STimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 4591acd82c0STimothy McDaniel struct dlb2_cmd_response response = {0}; 4601acd82c0STimothy McDaniel int ret; 4611acd82c0STimothy McDaniel 4621acd82c0STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Entering %s()\n", __func__); 4631acd82c0STimothy McDaniel 4641acd82c0STimothy McDaniel ret = dlb2_pf_create_dir_queue(&dlb2_dev->hw, 4651acd82c0STimothy McDaniel handle->domain_id, 4661acd82c0STimothy McDaniel cfg, 4671acd82c0STimothy McDaniel &response); 4681acd82c0STimothy McDaniel 4691acd82c0STimothy McDaniel cfg->response = response; 4701acd82c0STimothy McDaniel 4711acd82c0STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Exiting %s() with ret=%d\n", 4721acd82c0STimothy McDaniel __func__, ret); 4731acd82c0STimothy McDaniel 4741acd82c0STimothy McDaniel return ret; 4751acd82c0STimothy McDaniel } 4761acd82c0STimothy McDaniel 4771acd82c0STimothy McDaniel static int 4781acd82c0STimothy McDaniel dlb2_pf_map_qid(struct dlb2_hw_dev *handle, 4791acd82c0STimothy McDaniel struct dlb2_map_qid_args *cfg) 4801acd82c0STimothy McDaniel { 4811acd82c0STimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 4821acd82c0STimothy McDaniel struct dlb2_cmd_response response = {0}; 4831acd82c0STimothy McDaniel int ret; 4841acd82c0STimothy McDaniel 4851acd82c0STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Entering %s()\n", __func__); 4861acd82c0STimothy McDaniel 4871acd82c0STimothy McDaniel ret = dlb2_hw_map_qid(&dlb2_dev->hw, 4881acd82c0STimothy McDaniel handle->domain_id, 4891acd82c0STimothy McDaniel cfg, 4901acd82c0STimothy McDaniel &response, 4911acd82c0STimothy McDaniel false, 4921acd82c0STimothy McDaniel 0); 4931acd82c0STimothy McDaniel 4941acd82c0STimothy McDaniel cfg->response = response; 4951acd82c0STimothy McDaniel 4961acd82c0STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Exiting %s() with ret=%d\n", 4971acd82c0STimothy McDaniel __func__, ret); 4981acd82c0STimothy McDaniel 4991acd82c0STimothy McDaniel return ret; 5001acd82c0STimothy McDaniel } 5011acd82c0STimothy McDaniel 502a29248b5STimothy McDaniel static int 503a29248b5STimothy McDaniel dlb2_pf_unmap_qid(struct dlb2_hw_dev *handle, 504a29248b5STimothy McDaniel struct dlb2_unmap_qid_args *cfg) 505a29248b5STimothy McDaniel { 506a29248b5STimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 507a29248b5STimothy McDaniel struct dlb2_cmd_response response = {0}; 508a29248b5STimothy McDaniel int ret; 509a29248b5STimothy McDaniel 510a29248b5STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Entering %s()\n", __func__); 511a29248b5STimothy McDaniel 512a29248b5STimothy McDaniel ret = dlb2_hw_unmap_qid(&dlb2_dev->hw, 513a29248b5STimothy McDaniel handle->domain_id, 514a29248b5STimothy McDaniel cfg, 515a29248b5STimothy McDaniel &response, 516a29248b5STimothy McDaniel false, 517a29248b5STimothy McDaniel 0); 518a29248b5STimothy McDaniel 519a29248b5STimothy McDaniel cfg->response = response; 520a29248b5STimothy McDaniel 521a29248b5STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Exiting %s() with ret=%d\n", 522a29248b5STimothy McDaniel __func__, ret); 523a29248b5STimothy McDaniel 524a29248b5STimothy McDaniel return ret; 525a29248b5STimothy McDaniel } 526a29248b5STimothy McDaniel 527a29248b5STimothy McDaniel static int 528a29248b5STimothy McDaniel dlb2_pf_pending_port_unmaps(struct dlb2_hw_dev *handle, 529a29248b5STimothy McDaniel struct dlb2_pending_port_unmaps_args *args) 530a29248b5STimothy McDaniel { 531a29248b5STimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 532a29248b5STimothy McDaniel struct dlb2_cmd_response response = {0}; 533a29248b5STimothy McDaniel int ret; 534a29248b5STimothy McDaniel 535a29248b5STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Entering %s()\n", __func__); 536a29248b5STimothy McDaniel 537a29248b5STimothy McDaniel ret = dlb2_hw_pending_port_unmaps(&dlb2_dev->hw, 538a29248b5STimothy McDaniel handle->domain_id, 539a29248b5STimothy McDaniel args, 540a29248b5STimothy McDaniel &response, 541a29248b5STimothy McDaniel false, 542a29248b5STimothy McDaniel 0); 543a29248b5STimothy McDaniel 544a29248b5STimothy McDaniel args->response = response; 545a29248b5STimothy McDaniel 546a29248b5STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Exiting %s() with ret=%d\n", 547a29248b5STimothy McDaniel __func__, ret); 548a29248b5STimothy McDaniel 549a29248b5STimothy McDaniel return ret; 550a29248b5STimothy McDaniel } 55159e1a966STimothy McDaniel 55259e1a966STimothy McDaniel static int 55359e1a966STimothy McDaniel dlb2_pf_sched_domain_start(struct dlb2_hw_dev *handle, 55459e1a966STimothy McDaniel struct dlb2_start_domain_args *cfg) 55559e1a966STimothy McDaniel { 55659e1a966STimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 55759e1a966STimothy McDaniel struct dlb2_cmd_response response = {0}; 55859e1a966STimothy McDaniel int ret; 55959e1a966STimothy McDaniel 56059e1a966STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Entering %s()\n", __func__); 56159e1a966STimothy McDaniel 56259e1a966STimothy McDaniel ret = dlb2_pf_start_domain(&dlb2_dev->hw, 56359e1a966STimothy McDaniel handle->domain_id, 56459e1a966STimothy McDaniel cfg, 56559e1a966STimothy McDaniel &response); 56659e1a966STimothy McDaniel 56759e1a966STimothy McDaniel cfg->response = response; 56859e1a966STimothy McDaniel 56959e1a966STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Exiting %s() with ret=%d\n", 57059e1a966STimothy McDaniel __func__, ret); 57159e1a966STimothy McDaniel 57259e1a966STimothy McDaniel return ret; 57359e1a966STimothy McDaniel } 57459e1a966STimothy McDaniel 57518991548STimothy McDaniel static int 57618991548STimothy McDaniel dlb2_pf_get_ldb_queue_depth(struct dlb2_hw_dev *handle, 57718991548STimothy McDaniel struct dlb2_get_ldb_queue_depth_args *args) 57818991548STimothy McDaniel { 57918991548STimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 58018991548STimothy McDaniel struct dlb2_cmd_response response = {0}; 58118991548STimothy McDaniel int ret; 58218991548STimothy McDaniel 58318991548STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Entering %s()\n", __func__); 58418991548STimothy McDaniel 58518991548STimothy McDaniel ret = dlb2_hw_get_ldb_queue_depth(&dlb2_dev->hw, 58618991548STimothy McDaniel handle->domain_id, 58718991548STimothy McDaniel args, 58818991548STimothy McDaniel &response, 58918991548STimothy McDaniel false, 59018991548STimothy McDaniel 0); 59118991548STimothy McDaniel 59218991548STimothy McDaniel args->response = response; 59318991548STimothy McDaniel 59418991548STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Exiting %s() with ret=%d\n", 59518991548STimothy McDaniel __func__, ret); 59618991548STimothy McDaniel 59718991548STimothy McDaniel return ret; 59818991548STimothy McDaniel } 59918991548STimothy McDaniel 60018991548STimothy McDaniel static int 60118991548STimothy McDaniel dlb2_pf_get_dir_queue_depth(struct dlb2_hw_dev *handle, 60218991548STimothy McDaniel struct dlb2_get_dir_queue_depth_args *args) 60318991548STimothy McDaniel { 60418991548STimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 60518991548STimothy McDaniel struct dlb2_cmd_response response = {0}; 60618991548STimothy McDaniel int ret = 0; 60718991548STimothy McDaniel 60818991548STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Entering %s()\n", __func__); 60918991548STimothy McDaniel 61018991548STimothy McDaniel ret = dlb2_hw_get_dir_queue_depth(&dlb2_dev->hw, 61118991548STimothy McDaniel handle->domain_id, 61218991548STimothy McDaniel args, 61318991548STimothy McDaniel &response, 61418991548STimothy McDaniel false, 61518991548STimothy McDaniel 0); 61618991548STimothy McDaniel 61718991548STimothy McDaniel args->response = response; 61818991548STimothy McDaniel 61918991548STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Exiting %s() with ret=%d\n", 62018991548STimothy McDaniel __func__, ret); 62118991548STimothy McDaniel 62218991548STimothy McDaniel return ret; 62318991548STimothy McDaniel } 62418991548STimothy McDaniel 625ffa46fc4STimothy McDaniel static int 626ffa46fc4STimothy McDaniel dlb2_pf_enable_cq_weight(struct dlb2_hw_dev *handle, 627ffa46fc4STimothy McDaniel struct dlb2_enable_cq_weight_args *args) 628ffa46fc4STimothy McDaniel { 629ffa46fc4STimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 630ffa46fc4STimothy McDaniel struct dlb2_cmd_response response = {0}; 631ffa46fc4STimothy McDaniel int ret = 0; 632ffa46fc4STimothy McDaniel 633ffa46fc4STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Entering %s()\n", __func__); 634ffa46fc4STimothy McDaniel 635ffa46fc4STimothy McDaniel ret = dlb2_hw_enable_cq_weight(&dlb2_dev->hw, 636ffa46fc4STimothy McDaniel handle->domain_id, 637ffa46fc4STimothy McDaniel args, 638ffa46fc4STimothy McDaniel &response, 639ffa46fc4STimothy McDaniel false, 640ffa46fc4STimothy McDaniel 0); 641ffa46fc4STimothy McDaniel args->response = response; 642ffa46fc4STimothy McDaniel 643ffa46fc4STimothy McDaniel DLB2_INFO(dev->dlb2_device, "Exiting %s() with ret=%d\n", 644ffa46fc4STimothy McDaniel __func__, ret); 645ffa46fc4STimothy McDaniel 646ffa46fc4STimothy McDaniel return ret; 647ffa46fc4STimothy McDaniel } 648ffa46fc4STimothy McDaniel 649bec8901bSTimothy McDaniel static int 650bec8901bSTimothy McDaniel dlb2_pf_set_cos_bandwidth(struct dlb2_hw_dev *handle, 651bec8901bSTimothy McDaniel struct dlb2_set_cos_bw_args *args) 652bec8901bSTimothy McDaniel { 653bec8901bSTimothy McDaniel struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)handle->pf_dev; 654bec8901bSTimothy McDaniel int ret = 0; 655bec8901bSTimothy McDaniel 656bec8901bSTimothy McDaniel DLB2_INFO(dev->dlb2_device, "Entering %s()\n", __func__); 657bec8901bSTimothy McDaniel 658bec8901bSTimothy McDaniel ret = dlb2_hw_set_cos_bandwidth(&dlb2_dev->hw, 659bec8901bSTimothy McDaniel args->cos_id, 660bec8901bSTimothy McDaniel args->bandwidth); 661bec8901bSTimothy McDaniel 662bec8901bSTimothy McDaniel DLB2_INFO(dev->dlb2_device, "Exiting %s() with ret=%d\n", 663bec8901bSTimothy McDaniel __func__, ret); 664bec8901bSTimothy McDaniel 665bec8901bSTimothy McDaniel return ret; 666bec8901bSTimothy McDaniel } 667bec8901bSTimothy McDaniel 6685433956dSTimothy McDaniel static void 6695433956dSTimothy McDaniel dlb2_pf_iface_fn_ptrs_init(void) 6705433956dSTimothy McDaniel { 671e7c9971aSTimothy McDaniel dlb2_iface_low_level_io_init = dlb2_pf_low_level_io_init; 672e7c9971aSTimothy McDaniel dlb2_iface_open = dlb2_pf_open; 673f3cad285STimothy McDaniel dlb2_iface_domain_reset = dlb2_pf_domain_reset; 674e7c9971aSTimothy McDaniel dlb2_iface_get_device_version = dlb2_pf_get_device_version; 675e7c9971aSTimothy McDaniel dlb2_iface_hardware_init = dlb2_pf_hardware_init; 676e7c9971aSTimothy McDaniel dlb2_iface_get_num_resources = dlb2_pf_get_num_resources; 677e7c9971aSTimothy McDaniel dlb2_iface_get_cq_poll_mode = dlb2_pf_get_cq_poll_mode; 678f3cad285STimothy McDaniel dlb2_iface_sched_domain_create = dlb2_pf_sched_domain_create; 6797e668e57STimothy McDaniel dlb2_iface_ldb_queue_create = dlb2_pf_ldb_queue_create; 6803a6d0c04STimothy McDaniel dlb2_iface_ldb_port_create = dlb2_pf_ldb_port_create; 6811acd82c0STimothy McDaniel dlb2_iface_dir_queue_create = dlb2_pf_dir_queue_create; 6823a6d0c04STimothy McDaniel dlb2_iface_dir_port_create = dlb2_pf_dir_port_create; 6831acd82c0STimothy McDaniel dlb2_iface_map_qid = dlb2_pf_map_qid; 684a29248b5STimothy McDaniel dlb2_iface_unmap_qid = dlb2_pf_unmap_qid; 68518991548STimothy McDaniel dlb2_iface_get_ldb_queue_depth = dlb2_pf_get_ldb_queue_depth; 68618991548STimothy McDaniel dlb2_iface_get_dir_queue_depth = dlb2_pf_get_dir_queue_depth; 68759e1a966STimothy McDaniel dlb2_iface_sched_domain_start = dlb2_pf_sched_domain_start; 688a29248b5STimothy McDaniel dlb2_iface_pending_port_unmaps = dlb2_pf_pending_port_unmaps; 6897e668e57STimothy McDaniel dlb2_iface_get_sn_allocation = dlb2_pf_get_sn_allocation; 6907e668e57STimothy McDaniel dlb2_iface_set_sn_allocation = dlb2_pf_set_sn_allocation; 6917e668e57STimothy McDaniel dlb2_iface_get_sn_occupancy = dlb2_pf_get_sn_occupancy; 692ffa46fc4STimothy McDaniel dlb2_iface_enable_cq_weight = dlb2_pf_enable_cq_weight; 693bec8901bSTimothy McDaniel dlb2_iface_set_cos_bw = dlb2_pf_set_cos_bandwidth; 6945433956dSTimothy McDaniel } 6955433956dSTimothy McDaniel 6965433956dSTimothy McDaniel /* PCI DEV HOOKS */ 6975433956dSTimothy McDaniel static int 6985433956dSTimothy McDaniel dlb2_eventdev_pci_init(struct rte_eventdev *eventdev) 6995433956dSTimothy McDaniel { 7005433956dSTimothy McDaniel int ret = 0; 7015433956dSTimothy McDaniel struct rte_pci_device *pci_dev; 7025433956dSTimothy McDaniel struct dlb2_devargs dlb2_args = { 7035433956dSTimothy McDaniel .socket_id = rte_socket_id(), 7045433956dSTimothy McDaniel .max_num_events = DLB2_MAX_NUM_LDB_CREDITS, 7058d1d9070SAbdullah Sevincer .producer_coremask = NULL, 7065433956dSTimothy McDaniel .num_dir_credits_override = -1, 7075433956dSTimothy McDaniel .qid_depth_thresholds = { {0} }, 7087be66a3bSTimothy McDaniel .poll_interval = DLB2_POLL_INTERVAL_DEFAULT, 7097be66a3bSTimothy McDaniel .sw_credit_quanta = DLB2_SW_CREDIT_QUANTA_DEFAULT, 710e4869c0bSPravin Pathak .hw_credit_quanta = DLB2_SW_CREDIT_BATCH_SZ, 71186fe66d4STimothy McDaniel .default_depth_thresh = DLB2_DEPTH_THRESH_DEFAULT, 7120fc71ad8STimothy McDaniel .max_cq_depth = DLB2_DEFAULT_CQ_DEPTH, 7130fc71ad8STimothy McDaniel .max_enq_depth = DLB2_MAX_ENQUEUE_DEPTH 7145433956dSTimothy McDaniel }; 7155433956dSTimothy McDaniel struct dlb2_eventdev *dlb2; 71654089151STimothy McDaniel int q; 7178d1d9070SAbdullah Sevincer const void *probe_args = NULL; 7185433956dSTimothy McDaniel 719e99981afSDavid Marchand DLB2_LOG_LINE_DBG("Enter with dev_id=%d socket_id=%d", 7205433956dSTimothy McDaniel eventdev->data->dev_id, eventdev->data->socket_id); 7215433956dSTimothy McDaniel 72254089151STimothy McDaniel for (q = 0; q < DLB2_MAX_NUM_PORTS_ALL; q++) 72354089151STimothy McDaniel dlb2_args.port_cos.cos_id[q] = DLB2_COS_DEFAULT; 72454089151STimothy McDaniel 7255433956dSTimothy McDaniel dlb2_pf_iface_fn_ptrs_init(); 7265433956dSTimothy McDaniel 7275433956dSTimothy McDaniel pci_dev = RTE_DEV_TO_PCI(eventdev->dev); 7285433956dSTimothy McDaniel 7295433956dSTimothy McDaniel if (rte_eal_process_type() == RTE_PROC_PRIMARY) { 7305433956dSTimothy McDaniel dlb2 = dlb2_pmd_priv(eventdev); /* rte_zmalloc_socket mem */ 731b66a418dSTimothy McDaniel dlb2->version = DLB2_HW_DEVICE_FROM_PCI_ID(pci_dev); 7325433956dSTimothy McDaniel 7335433956dSTimothy McDaniel /* Were we invoked with runtime parameters? */ 7345433956dSTimothy McDaniel if (pci_dev->device.devargs) { 7355433956dSTimothy McDaniel ret = dlb2_parse_params(pci_dev->device.devargs->args, 7365433956dSTimothy McDaniel pci_dev->device.devargs->name, 737b66a418dSTimothy McDaniel &dlb2_args, 738b66a418dSTimothy McDaniel dlb2->version); 7395433956dSTimothy McDaniel if (ret) { 740*f665790aSDavid Marchand DLB2_LOG_ERR("PFPMD failed to parse args ret=%d, errno=%d", 7415433956dSTimothy McDaniel ret, rte_errno); 7425433956dSTimothy McDaniel goto dlb2_probe_failed; 7435433956dSTimothy McDaniel } 7448d1d9070SAbdullah Sevincer probe_args = &dlb2_args; 7458d1d9070SAbdullah Sevincer } 7468d1d9070SAbdullah Sevincer 7478d1d9070SAbdullah Sevincer /* Probe the DLB2 PF layer */ 7488d1d9070SAbdullah Sevincer dlb2->qm_instance.pf_dev = dlb2_probe(pci_dev, probe_args); 7498d1d9070SAbdullah Sevincer 7508d1d9070SAbdullah Sevincer if (dlb2->qm_instance.pf_dev == NULL) { 751*f665790aSDavid Marchand DLB2_LOG_ERR("DLB2 PF Probe failed with error %d", 7528d1d9070SAbdullah Sevincer rte_errno); 7538d1d9070SAbdullah Sevincer ret = -rte_errno; 7548d1d9070SAbdullah Sevincer goto dlb2_probe_failed; 7555433956dSTimothy McDaniel } 7565433956dSTimothy McDaniel 7575433956dSTimothy McDaniel ret = dlb2_primary_eventdev_probe(eventdev, 7585433956dSTimothy McDaniel event_dlb2_pf_name, 7595433956dSTimothy McDaniel &dlb2_args); 7605433956dSTimothy McDaniel } else { 761b66a418dSTimothy McDaniel dlb2 = dlb2_pmd_priv(eventdev); 762b66a418dSTimothy McDaniel dlb2->version = DLB2_HW_DEVICE_FROM_PCI_ID(pci_dev); 7635433956dSTimothy McDaniel ret = dlb2_secondary_eventdev_probe(eventdev, 7645433956dSTimothy McDaniel event_dlb2_pf_name); 7655433956dSTimothy McDaniel } 7665433956dSTimothy McDaniel if (ret) 7675433956dSTimothy McDaniel goto dlb2_probe_failed; 7685433956dSTimothy McDaniel 769*f665790aSDavid Marchand DLB2_LOG_INFO("DLB2 PF Probe success"); 7705433956dSTimothy McDaniel 7715433956dSTimothy McDaniel return 0; 7725433956dSTimothy McDaniel 7735433956dSTimothy McDaniel dlb2_probe_failed: 7745433956dSTimothy McDaniel 775*f665790aSDavid Marchand DLB2_LOG_INFO("DLB2 PF Probe failed, ret=%d", ret); 7765433956dSTimothy McDaniel 7775433956dSTimothy McDaniel return ret; 7785433956dSTimothy McDaniel } 7795433956dSTimothy McDaniel 7805433956dSTimothy McDaniel #define EVENTDEV_INTEL_VENDOR_ID 0x8086 7815433956dSTimothy McDaniel 7825433956dSTimothy McDaniel static const struct rte_pci_id pci_id_dlb2_map[] = { 7835433956dSTimothy McDaniel { 7845433956dSTimothy McDaniel RTE_PCI_DEVICE(EVENTDEV_INTEL_VENDOR_ID, 7855433956dSTimothy McDaniel PCI_DEVICE_ID_INTEL_DLB2_PF) 7865433956dSTimothy McDaniel }, 7875433956dSTimothy McDaniel { 7885433956dSTimothy McDaniel .vendor_id = 0, 7895433956dSTimothy McDaniel }, 7905433956dSTimothy McDaniel }; 7915433956dSTimothy McDaniel 792b66a418dSTimothy McDaniel static const struct rte_pci_id pci_id_dlb2_5_map[] = { 793b66a418dSTimothy McDaniel { 794b66a418dSTimothy McDaniel RTE_PCI_DEVICE(EVENTDEV_INTEL_VENDOR_ID, 795b66a418dSTimothy McDaniel PCI_DEVICE_ID_INTEL_DLB2_5_PF) 796b66a418dSTimothy McDaniel }, 797b66a418dSTimothy McDaniel { 798b66a418dSTimothy McDaniel .vendor_id = 0, 799b66a418dSTimothy McDaniel }, 800b66a418dSTimothy McDaniel }; 801b66a418dSTimothy McDaniel 8025433956dSTimothy McDaniel static int 8035433956dSTimothy McDaniel event_dlb2_pci_probe(struct rte_pci_driver *pci_drv, 8045433956dSTimothy McDaniel struct rte_pci_device *pci_dev) 8055433956dSTimothy McDaniel { 8065433956dSTimothy McDaniel int ret; 8075433956dSTimothy McDaniel 8085433956dSTimothy McDaniel ret = rte_event_pmd_pci_probe_named(pci_drv, pci_dev, 8095433956dSTimothy McDaniel sizeof(struct dlb2_eventdev), 8105433956dSTimothy McDaniel dlb2_eventdev_pci_init, 8115433956dSTimothy McDaniel event_dlb2_pf_name); 8125433956dSTimothy McDaniel if (ret) { 8135433956dSTimothy McDaniel DLB2_LOG_INFO("rte_event_pmd_pci_probe_named() failed, " 814*f665790aSDavid Marchand "ret=%d", ret); 8155433956dSTimothy McDaniel } 8165433956dSTimothy McDaniel 8175433956dSTimothy McDaniel return ret; 8185433956dSTimothy McDaniel } 8195433956dSTimothy McDaniel 8205433956dSTimothy McDaniel static int 8215433956dSTimothy McDaniel event_dlb2_pci_remove(struct rte_pci_device *pci_dev) 8225433956dSTimothy McDaniel { 8235433956dSTimothy McDaniel int ret; 8245433956dSTimothy McDaniel 8255433956dSTimothy McDaniel ret = rte_event_pmd_pci_remove(pci_dev, NULL); 8265433956dSTimothy McDaniel 8275433956dSTimothy McDaniel if (ret) { 8285433956dSTimothy McDaniel DLB2_LOG_INFO("rte_event_pmd_pci_remove() failed, " 829*f665790aSDavid Marchand "ret=%d", ret); 8305433956dSTimothy McDaniel } 8315433956dSTimothy McDaniel 8325433956dSTimothy McDaniel return ret; 8335433956dSTimothy McDaniel 8345433956dSTimothy McDaniel } 8355433956dSTimothy McDaniel 836b66a418dSTimothy McDaniel static int 837b66a418dSTimothy McDaniel event_dlb2_5_pci_probe(struct rte_pci_driver *pci_drv, 838b66a418dSTimothy McDaniel struct rte_pci_device *pci_dev) 839b66a418dSTimothy McDaniel { 840b66a418dSTimothy McDaniel int ret; 841b66a418dSTimothy McDaniel 842b66a418dSTimothy McDaniel ret = rte_event_pmd_pci_probe_named(pci_drv, pci_dev, 843b66a418dSTimothy McDaniel sizeof(struct dlb2_eventdev), 844b66a418dSTimothy McDaniel dlb2_eventdev_pci_init, 845b66a418dSTimothy McDaniel event_dlb2_pf_name); 846b66a418dSTimothy McDaniel if (ret) { 847b66a418dSTimothy McDaniel DLB2_LOG_INFO("rte_event_pmd_pci_probe_named() failed, " 848*f665790aSDavid Marchand "ret=%d", ret); 849b66a418dSTimothy McDaniel } 850b66a418dSTimothy McDaniel 851b66a418dSTimothy McDaniel return ret; 852b66a418dSTimothy McDaniel } 853b66a418dSTimothy McDaniel 854b66a418dSTimothy McDaniel static int 855b66a418dSTimothy McDaniel event_dlb2_5_pci_remove(struct rte_pci_device *pci_dev) 856b66a418dSTimothy McDaniel { 857b66a418dSTimothy McDaniel int ret; 858b66a418dSTimothy McDaniel 859b66a418dSTimothy McDaniel ret = rte_event_pmd_pci_remove(pci_dev, NULL); 860b66a418dSTimothy McDaniel 861b66a418dSTimothy McDaniel if (ret) { 862b66a418dSTimothy McDaniel DLB2_LOG_INFO("rte_event_pmd_pci_remove() failed, " 863*f665790aSDavid Marchand "ret=%d", ret); 864b66a418dSTimothy McDaniel } 865b66a418dSTimothy McDaniel 866b66a418dSTimothy McDaniel return ret; 867b66a418dSTimothy McDaniel 868b66a418dSTimothy McDaniel } 869b66a418dSTimothy McDaniel 8705433956dSTimothy McDaniel static struct rte_pci_driver pci_eventdev_dlb2_pmd = { 8715433956dSTimothy McDaniel .id_table = pci_id_dlb2_map, 8725433956dSTimothy McDaniel .drv_flags = RTE_PCI_DRV_NEED_MAPPING, 8735433956dSTimothy McDaniel .probe = event_dlb2_pci_probe, 8745433956dSTimothy McDaniel .remove = event_dlb2_pci_remove, 8755433956dSTimothy McDaniel }; 8765433956dSTimothy McDaniel 877b66a418dSTimothy McDaniel static struct rte_pci_driver pci_eventdev_dlb2_5_pmd = { 878b66a418dSTimothy McDaniel .id_table = pci_id_dlb2_5_map, 879b66a418dSTimothy McDaniel .drv_flags = RTE_PCI_DRV_NEED_MAPPING, 880b66a418dSTimothy McDaniel .probe = event_dlb2_5_pci_probe, 881b66a418dSTimothy McDaniel .remove = event_dlb2_5_pci_remove, 882b66a418dSTimothy McDaniel }; 883b66a418dSTimothy McDaniel 8845433956dSTimothy McDaniel RTE_PMD_REGISTER_PCI(event_dlb2_pf, pci_eventdev_dlb2_pmd); 8855433956dSTimothy McDaniel RTE_PMD_REGISTER_PCI_TABLE(event_dlb2_pf, pci_id_dlb2_map); 886b66a418dSTimothy McDaniel 887b66a418dSTimothy McDaniel RTE_PMD_REGISTER_PCI(event_dlb2_5_pf, pci_eventdev_dlb2_5_pmd); 888b66a418dSTimothy McDaniel RTE_PMD_REGISTER_PCI_TABLE(event_dlb2_5_pf, pci_id_dlb2_5_map); 889