Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright (c) 2022 Marvell. 3 : : */ 4 : : 5 : : #include <dev_driver.h> 6 : : #include <eal_export.h> 7 : : #include <rte_eal.h> 8 : : #include <rte_malloc.h> 9 : : 10 : : #include "rte_mldev_pmd.h" 11 : : 12 : : RTE_EXPORT_INTERNAL_SYMBOL(rte_ml_dev_pmd_create) 13 : : struct rte_ml_dev * 14 : 0 : rte_ml_dev_pmd_create(const char *name, struct rte_device *device, 15 : : struct rte_ml_dev_pmd_init_params *params) 16 : : { 17 : : struct rte_ml_dev *dev; 18 : : 19 : 0 : RTE_MLDEV_LOG(INFO, "ML device initialisation - name: %s, socket_id: %u", name, 20 : : params->socket_id); 21 : : 22 : : /* Allocate device structure */ 23 : 0 : dev = rte_ml_dev_pmd_allocate(name, params->socket_id); 24 [ # # ]: 0 : if (dev == NULL) { 25 : 0 : RTE_MLDEV_LOG(ERR, "Failed to allocate ML device for %s", name); 26 : 0 : return NULL; 27 : : } 28 : : 29 : : /* Allocate private device structure */ 30 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY) { 31 : 0 : dev->data->dev_private = 32 : 0 : rte_zmalloc_socket("ml_dev_private", params->private_data_size, 33 : 0 : RTE_CACHE_LINE_SIZE, params->socket_id); 34 : : 35 [ # # ]: 0 : if (dev->data->dev_private == NULL) { 36 : 0 : RTE_MLDEV_LOG(ERR, "Cannot allocate memory for mldev %s private data", 37 : : name); 38 : 0 : rte_ml_dev_pmd_release(dev); 39 : 0 : return NULL; 40 : : } 41 : : } 42 : 0 : dev->device = device; 43 : : 44 : 0 : return dev; 45 : : } 46 : : 47 : : RTE_EXPORT_INTERNAL_SYMBOL(rte_ml_dev_pmd_destroy) 48 : : int 49 : 0 : rte_ml_dev_pmd_destroy(struct rte_ml_dev *dev) 50 : : { 51 : : int ret; 52 : : 53 : 0 : RTE_MLDEV_LOG(INFO, "Releasing ML device - name: %s", dev->device->name); 54 : 0 : ret = rte_ml_dev_pmd_release(dev); 55 [ # # ]: 0 : if (ret) 56 : : return ret; 57 : : 58 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY) 59 : 0 : rte_free(dev->data->dev_private); 60 : : 61 : 0 : dev->data = NULL; 62 : 0 : dev->device = NULL; 63 : : 64 : 0 : return 0; 65 : : }