18245472cSJasvinder Singh /* SPDX-License-Identifier: BSD-3-Clause
28245472cSJasvinder Singh * Copyright(c) 2010-2018 Intel Corporation
38245472cSJasvinder Singh */
48245472cSJasvinder Singh
58245472cSJasvinder Singh #include <stdlib.h>
68245472cSJasvinder Singh #include <string.h>
78245472cSJasvinder Singh
8*7959831bSJasvinder Singh #include <rte_string_fns.h>
9*7959831bSJasvinder Singh
108245472cSJasvinder Singh #include "swq.h"
118245472cSJasvinder Singh
128245472cSJasvinder Singh static struct swq_list swq_list;
138245472cSJasvinder Singh
148245472cSJasvinder Singh int
swq_init(void)158245472cSJasvinder Singh swq_init(void)
168245472cSJasvinder Singh {
178245472cSJasvinder Singh TAILQ_INIT(&swq_list);
188245472cSJasvinder Singh
198245472cSJasvinder Singh return 0;
208245472cSJasvinder Singh }
218245472cSJasvinder Singh
228245472cSJasvinder Singh struct swq *
swq_find(const char * name)238245472cSJasvinder Singh swq_find(const char *name)
248245472cSJasvinder Singh {
258245472cSJasvinder Singh struct swq *swq;
268245472cSJasvinder Singh
278245472cSJasvinder Singh if (name == NULL)
288245472cSJasvinder Singh return NULL;
298245472cSJasvinder Singh
308245472cSJasvinder Singh TAILQ_FOREACH(swq, &swq_list, node)
318245472cSJasvinder Singh if (strcmp(swq->name, name) == 0)
328245472cSJasvinder Singh return swq;
338245472cSJasvinder Singh
348245472cSJasvinder Singh return NULL;
358245472cSJasvinder Singh }
368245472cSJasvinder Singh
378245472cSJasvinder Singh struct swq *
swq_create(const char * name,struct swq_params * params)388245472cSJasvinder Singh swq_create(const char *name, struct swq_params *params)
398245472cSJasvinder Singh {
408245472cSJasvinder Singh struct swq *swq;
418245472cSJasvinder Singh struct rte_ring *r;
428245472cSJasvinder Singh unsigned int flags = RING_F_SP_ENQ | RING_F_SC_DEQ;
438245472cSJasvinder Singh
448245472cSJasvinder Singh /* Check input params */
458245472cSJasvinder Singh if ((name == NULL) ||
468245472cSJasvinder Singh swq_find(name) ||
478245472cSJasvinder Singh (params == NULL) ||
488245472cSJasvinder Singh (params->size == 0))
498245472cSJasvinder Singh return NULL;
508245472cSJasvinder Singh
518245472cSJasvinder Singh /* Resource create */
528245472cSJasvinder Singh r = rte_ring_create(
538245472cSJasvinder Singh name,
548245472cSJasvinder Singh params->size,
558245472cSJasvinder Singh params->cpu_id,
568245472cSJasvinder Singh flags);
578245472cSJasvinder Singh
588245472cSJasvinder Singh if (r == NULL)
598245472cSJasvinder Singh return NULL;
608245472cSJasvinder Singh
618245472cSJasvinder Singh /* Node allocation */
628245472cSJasvinder Singh swq = calloc(1, sizeof(struct swq));
638245472cSJasvinder Singh if (swq == NULL) {
648245472cSJasvinder Singh rte_ring_free(r);
658245472cSJasvinder Singh return NULL;
668245472cSJasvinder Singh }
678245472cSJasvinder Singh
688245472cSJasvinder Singh /* Node fill in */
69*7959831bSJasvinder Singh strlcpy(swq->name, name, sizeof(swq->name));
708245472cSJasvinder Singh swq->r = r;
718245472cSJasvinder Singh
728245472cSJasvinder Singh /* Node add to list */
738245472cSJasvinder Singh TAILQ_INSERT_TAIL(&swq_list, swq, node);
748245472cSJasvinder Singh
758245472cSJasvinder Singh return swq;
768245472cSJasvinder Singh }
77