1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2018 Intel Corporation 3 */ 4 5 #include <stdlib.h> 6 #include <string.h> 7 8 #include <rte_string_fns.h> 9 10 #include "swq.h" 11 12 static struct swq_list swq_list; 13 14 int 15 swq_init(void) 16 { 17 TAILQ_INIT(&swq_list); 18 19 return 0; 20 } 21 22 struct swq * 23 swq_find(const char *name) 24 { 25 struct swq *swq; 26 27 if (name == NULL) 28 return NULL; 29 30 TAILQ_FOREACH(swq, &swq_list, node) 31 if (strcmp(swq->name, name) == 0) 32 return swq; 33 34 return NULL; 35 } 36 37 struct swq * 38 swq_create(const char *name, struct swq_params *params) 39 { 40 struct swq *swq; 41 struct rte_ring *r; 42 unsigned int flags = RING_F_SP_ENQ | RING_F_SC_DEQ; 43 44 /* Check input params */ 45 if ((name == NULL) || 46 swq_find(name) || 47 (params == NULL) || 48 (params->size == 0)) 49 return NULL; 50 51 /* Resource create */ 52 r = rte_ring_create( 53 name, 54 params->size, 55 params->cpu_id, 56 flags); 57 58 if (r == NULL) 59 return NULL; 60 61 /* Node allocation */ 62 swq = calloc(1, sizeof(struct swq)); 63 if (swq == NULL) { 64 rte_ring_free(r); 65 return NULL; 66 } 67 68 /* Node fill in */ 69 strlcpy(swq->name, name, sizeof(swq->name)); 70 swq->r = r; 71 72 /* Node add to list */ 73 TAILQ_INSERT_TAIL(&swq_list, swq, node); 74 75 return swq; 76 } 77