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