Line data Source code
1 : /* SPDX-License-Identifier: Apache-2.0 2 : * Copyright (c) 2022 Cisco Systems, Inc. 3 : */ 4 : 5 : #include <vlib/vlib.h> 6 : #include <vlib/log.h> 7 : #include <vlib/dma/dma.h> 8 : 9 575 : VLIB_REGISTER_LOG_CLASS (dma_log) = { 10 : .class_name = "dma", 11 : }; 12 : 13 : vlib_dma_main_t vlib_dma_main = {}; 14 : 15 : clib_error_t * 16 575 : vlib_dma_register_backend (vlib_main_t *vm, vlib_dma_backend_t *b) 17 : { 18 575 : vlib_dma_main_t *dm = &vlib_dma_main; 19 575 : vec_add1 (dm->backends, *b); 20 575 : dma_log_info ("backend '%s' registered", b->name); 21 575 : return 0; 22 : } 23 : 24 : int 25 0 : vlib_dma_config_add (vlib_main_t *vm, vlib_dma_config_t *c) 26 : { 27 0 : vlib_dma_main_t *dm = &vlib_dma_main; 28 : vlib_dma_backend_t *b; 29 : vlib_dma_config_data_t *cd; 30 : 31 0 : pool_get_zero (dm->configs, cd); 32 0 : cd->config_index = cd - dm->configs; 33 : 34 0 : clib_memcpy (&cd->cfg, c, sizeof (vlib_dma_config_t)); 35 : 36 0 : vec_foreach (b, dm->backends) 37 : { 38 0 : dma_log_info ("calling '%s' config_add_fn", b->name); 39 0 : if (b->config_add_fn (vm, cd)) 40 : { 41 0 : dma_log_info ("config %u added into backend %s", cd - dm->configs, 42 : b->name); 43 0 : cd->backend_index = b - dm->backends; 44 0 : return cd - dm->configs; 45 : } 46 : } 47 : 48 0 : pool_put (dm->configs, cd); 49 0 : return -1; 50 : } 51 : 52 : void 53 0 : vlib_dma_config_del (vlib_main_t *vm, u32 config_index) 54 : { 55 0 : vlib_dma_main_t *dm = &vlib_dma_main; 56 0 : vlib_dma_config_data_t *cd = pool_elt_at_index (dm->configs, config_index); 57 0 : vlib_dma_backend_t *b = vec_elt_at_index (dm->backends, cd->backend_index); 58 : 59 0 : if (b->config_del_fn) 60 0 : b->config_del_fn (vm, cd); 61 : 62 0 : pool_put (dm->configs, cd); 63 0 : dma_log_info ("config %u deleted from backend %s", config_index, b->name); 64 0 : } 65 : 66 : u8 * 67 0 : vlib_dma_config_info (u8 *s, va_list *args) 68 : { 69 0 : vlib_dma_main_t *dm = &vlib_dma_main; 70 0 : int config_index = va_arg (*args, int); 71 0 : u32 len = pool_elts (dm->configs); 72 0 : if (config_index >= len) 73 0 : return format (s, "%s", "not found"); 74 0 : vlib_dma_config_data_t *cd = pool_elt_at_index (dm->configs, config_index); 75 : 76 0 : vlib_dma_backend_t *b = vec_elt_at_index (dm->backends, cd->backend_index); 77 : 78 0 : if (b->info_fn) 79 0 : return b->info_fn (s, args); 80 : 81 0 : return 0; 82 : }