1b77f6600SCristian Dumitrescu /* SPDX-License-Identifier: BSD-3-Clause 2b77f6600SCristian Dumitrescu * Copyright(c) 2020 Intel Corporation 3b77f6600SCristian Dumitrescu */ 4b77f6600SCristian Dumitrescu 5b77f6600SCristian Dumitrescu #include <stdlib.h> 6b77f6600SCristian Dumitrescu #include <string.h> 7b77f6600SCristian Dumitrescu 8b77f6600SCristian Dumitrescu #include <rte_mempool.h> 9b77f6600SCristian Dumitrescu #include <rte_mbuf.h> 10b77f6600SCristian Dumitrescu #include <rte_ethdev.h> 11b77f6600SCristian Dumitrescu #include <rte_swx_port_ethdev.h> 12*77a41301SCristian Dumitrescu #include <rte_swx_port_ring.h> 13b77f6600SCristian Dumitrescu #include <rte_swx_port_source_sink.h> 14b77f6600SCristian Dumitrescu #include <rte_swx_table_em.h> 15b77f6600SCristian Dumitrescu #include <rte_swx_pipeline.h> 16b77f6600SCristian Dumitrescu #include <rte_swx_ctl.h> 17b77f6600SCristian Dumitrescu 18b77f6600SCristian Dumitrescu #include "obj.h" 19b77f6600SCristian Dumitrescu 20b77f6600SCristian Dumitrescu /* 21b77f6600SCristian Dumitrescu * mempool 22b77f6600SCristian Dumitrescu */ 23b77f6600SCristian Dumitrescu TAILQ_HEAD(mempool_list, mempool); 24b77f6600SCristian Dumitrescu 25b77f6600SCristian Dumitrescu /* 26b77f6600SCristian Dumitrescu * link 27b77f6600SCristian Dumitrescu */ 28b77f6600SCristian Dumitrescu TAILQ_HEAD(link_list, link); 29b77f6600SCristian Dumitrescu 30b77f6600SCristian Dumitrescu /* 31*77a41301SCristian Dumitrescu * ring 32*77a41301SCristian Dumitrescu */ 33*77a41301SCristian Dumitrescu TAILQ_HEAD(ring_list, ring); 34*77a41301SCristian Dumitrescu 35*77a41301SCristian Dumitrescu /* 36b77f6600SCristian Dumitrescu * pipeline 37b77f6600SCristian Dumitrescu */ 38b77f6600SCristian Dumitrescu TAILQ_HEAD(pipeline_list, pipeline); 39b77f6600SCristian Dumitrescu 40b77f6600SCristian Dumitrescu /* 41b77f6600SCristian Dumitrescu * obj 42b77f6600SCristian Dumitrescu */ 43b77f6600SCristian Dumitrescu struct obj { 44b77f6600SCristian Dumitrescu struct mempool_list mempool_list; 45b77f6600SCristian Dumitrescu struct link_list link_list; 46*77a41301SCristian Dumitrescu struct ring_list ring_list; 47b77f6600SCristian Dumitrescu struct pipeline_list pipeline_list; 48b77f6600SCristian Dumitrescu }; 49b77f6600SCristian Dumitrescu 50b77f6600SCristian Dumitrescu /* 51b77f6600SCristian Dumitrescu * mempool 52b77f6600SCristian Dumitrescu */ 53b77f6600SCristian Dumitrescu #define BUFFER_SIZE_MIN (sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM) 54b77f6600SCristian Dumitrescu 55b77f6600SCristian Dumitrescu struct mempool * 56b77f6600SCristian Dumitrescu mempool_create(struct obj *obj, const char *name, struct mempool_params *params) 57b77f6600SCristian Dumitrescu { 58b77f6600SCristian Dumitrescu struct mempool *mempool; 59b77f6600SCristian Dumitrescu struct rte_mempool *m; 60b77f6600SCristian Dumitrescu 61b77f6600SCristian Dumitrescu /* Check input params */ 62b77f6600SCristian Dumitrescu if ((name == NULL) || 63b77f6600SCristian Dumitrescu mempool_find(obj, name) || 64b77f6600SCristian Dumitrescu (params == NULL) || 65b77f6600SCristian Dumitrescu (params->buffer_size < BUFFER_SIZE_MIN) || 66b77f6600SCristian Dumitrescu (params->pool_size == 0)) 67b77f6600SCristian Dumitrescu return NULL; 68b77f6600SCristian Dumitrescu 69b77f6600SCristian Dumitrescu /* Resource create */ 70b77f6600SCristian Dumitrescu m = rte_pktmbuf_pool_create( 71b77f6600SCristian Dumitrescu name, 72b77f6600SCristian Dumitrescu params->pool_size, 73b77f6600SCristian Dumitrescu params->cache_size, 74b77f6600SCristian Dumitrescu 0, 75b77f6600SCristian Dumitrescu params->buffer_size - sizeof(struct rte_mbuf), 76b77f6600SCristian Dumitrescu params->cpu_id); 77b77f6600SCristian Dumitrescu 78b77f6600SCristian Dumitrescu if (m == NULL) 79b77f6600SCristian Dumitrescu return NULL; 80b77f6600SCristian Dumitrescu 81b77f6600SCristian Dumitrescu /* Node allocation */ 82b77f6600SCristian Dumitrescu mempool = calloc(1, sizeof(struct mempool)); 83b77f6600SCristian Dumitrescu if (mempool == NULL) { 84b77f6600SCristian Dumitrescu rte_mempool_free(m); 85b77f6600SCristian Dumitrescu return NULL; 86b77f6600SCristian Dumitrescu } 87b77f6600SCristian Dumitrescu 88b77f6600SCristian Dumitrescu /* Node fill in */ 89b77f6600SCristian Dumitrescu strlcpy(mempool->name, name, sizeof(mempool->name)); 90b77f6600SCristian Dumitrescu mempool->m = m; 91b77f6600SCristian Dumitrescu mempool->buffer_size = params->buffer_size; 92b77f6600SCristian Dumitrescu 93b77f6600SCristian Dumitrescu /* Node add to list */ 94b77f6600SCristian Dumitrescu TAILQ_INSERT_TAIL(&obj->mempool_list, mempool, node); 95b77f6600SCristian Dumitrescu 96b77f6600SCristian Dumitrescu return mempool; 97b77f6600SCristian Dumitrescu } 98b77f6600SCristian Dumitrescu 99b77f6600SCristian Dumitrescu struct mempool * 100b77f6600SCristian Dumitrescu mempool_find(struct obj *obj, const char *name) 101b77f6600SCristian Dumitrescu { 102b77f6600SCristian Dumitrescu struct mempool *mempool; 103b77f6600SCristian Dumitrescu 104b77f6600SCristian Dumitrescu if (!obj || !name) 105b77f6600SCristian Dumitrescu return NULL; 106b77f6600SCristian Dumitrescu 107b77f6600SCristian Dumitrescu TAILQ_FOREACH(mempool, &obj->mempool_list, node) 108b77f6600SCristian Dumitrescu if (strcmp(mempool->name, name) == 0) 109b77f6600SCristian Dumitrescu return mempool; 110b77f6600SCristian Dumitrescu 111b77f6600SCristian Dumitrescu return NULL; 112b77f6600SCristian Dumitrescu } 113b77f6600SCristian Dumitrescu 114b77f6600SCristian Dumitrescu /* 115b77f6600SCristian Dumitrescu * link 116b77f6600SCristian Dumitrescu */ 117b77f6600SCristian Dumitrescu static struct rte_eth_conf port_conf_default = { 118b77f6600SCristian Dumitrescu .link_speeds = 0, 119b77f6600SCristian Dumitrescu .rxmode = { 120b77f6600SCristian Dumitrescu .mq_mode = ETH_MQ_RX_NONE, 121b77f6600SCristian Dumitrescu .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */ 122b77f6600SCristian Dumitrescu .split_hdr_size = 0, /* Header split buffer size */ 123b77f6600SCristian Dumitrescu }, 124b77f6600SCristian Dumitrescu .rx_adv_conf = { 125b77f6600SCristian Dumitrescu .rss_conf = { 126b77f6600SCristian Dumitrescu .rss_key = NULL, 127b77f6600SCristian Dumitrescu .rss_key_len = 40, 128b77f6600SCristian Dumitrescu .rss_hf = 0, 129b77f6600SCristian Dumitrescu }, 130b77f6600SCristian Dumitrescu }, 131b77f6600SCristian Dumitrescu .txmode = { 132b77f6600SCristian Dumitrescu .mq_mode = ETH_MQ_TX_NONE, 133b77f6600SCristian Dumitrescu }, 134b77f6600SCristian Dumitrescu .lpbk_mode = 0, 135b77f6600SCristian Dumitrescu }; 136b77f6600SCristian Dumitrescu 137b77f6600SCristian Dumitrescu #define RETA_CONF_SIZE (ETH_RSS_RETA_SIZE_512 / RTE_RETA_GROUP_SIZE) 138b77f6600SCristian Dumitrescu 139b77f6600SCristian Dumitrescu static int 140b77f6600SCristian Dumitrescu rss_setup(uint16_t port_id, 141b77f6600SCristian Dumitrescu uint16_t reta_size, 142b77f6600SCristian Dumitrescu struct link_params_rss *rss) 143b77f6600SCristian Dumitrescu { 144b77f6600SCristian Dumitrescu struct rte_eth_rss_reta_entry64 reta_conf[RETA_CONF_SIZE]; 145b77f6600SCristian Dumitrescu uint32_t i; 146b77f6600SCristian Dumitrescu int status; 147b77f6600SCristian Dumitrescu 148b77f6600SCristian Dumitrescu /* RETA setting */ 149b77f6600SCristian Dumitrescu memset(reta_conf, 0, sizeof(reta_conf)); 150b77f6600SCristian Dumitrescu 151b77f6600SCristian Dumitrescu for (i = 0; i < reta_size; i++) 152b77f6600SCristian Dumitrescu reta_conf[i / RTE_RETA_GROUP_SIZE].mask = UINT64_MAX; 153b77f6600SCristian Dumitrescu 154b77f6600SCristian Dumitrescu for (i = 0; i < reta_size; i++) { 155b77f6600SCristian Dumitrescu uint32_t reta_id = i / RTE_RETA_GROUP_SIZE; 156b77f6600SCristian Dumitrescu uint32_t reta_pos = i % RTE_RETA_GROUP_SIZE; 157b77f6600SCristian Dumitrescu uint32_t rss_qs_pos = i % rss->n_queues; 158b77f6600SCristian Dumitrescu 159b77f6600SCristian Dumitrescu reta_conf[reta_id].reta[reta_pos] = 160b77f6600SCristian Dumitrescu (uint16_t) rss->queue_id[rss_qs_pos]; 161b77f6600SCristian Dumitrescu } 162b77f6600SCristian Dumitrescu 163b77f6600SCristian Dumitrescu /* RETA update */ 164b77f6600SCristian Dumitrescu status = rte_eth_dev_rss_reta_update(port_id, 165b77f6600SCristian Dumitrescu reta_conf, 166b77f6600SCristian Dumitrescu reta_size); 167b77f6600SCristian Dumitrescu 168b77f6600SCristian Dumitrescu return status; 169b77f6600SCristian Dumitrescu } 170b77f6600SCristian Dumitrescu 171b77f6600SCristian Dumitrescu struct link * 172b77f6600SCristian Dumitrescu link_create(struct obj *obj, const char *name, struct link_params *params) 173b77f6600SCristian Dumitrescu { 174b77f6600SCristian Dumitrescu struct rte_eth_dev_info port_info; 175b77f6600SCristian Dumitrescu struct rte_eth_conf port_conf; 176b77f6600SCristian Dumitrescu struct link *link; 177b77f6600SCristian Dumitrescu struct link_params_rss *rss; 178b77f6600SCristian Dumitrescu struct mempool *mempool; 179b77f6600SCristian Dumitrescu uint32_t cpu_id, i; 180b77f6600SCristian Dumitrescu int status; 181b77f6600SCristian Dumitrescu uint16_t port_id; 182b77f6600SCristian Dumitrescu 183b77f6600SCristian Dumitrescu /* Check input params */ 184b77f6600SCristian Dumitrescu if ((name == NULL) || 185b77f6600SCristian Dumitrescu link_find(obj, name) || 186b77f6600SCristian Dumitrescu (params == NULL) || 187b77f6600SCristian Dumitrescu (params->rx.n_queues == 0) || 188b77f6600SCristian Dumitrescu (params->rx.queue_size == 0) || 189b77f6600SCristian Dumitrescu (params->tx.n_queues == 0) || 190b77f6600SCristian Dumitrescu (params->tx.queue_size == 0)) 191b77f6600SCristian Dumitrescu return NULL; 192b77f6600SCristian Dumitrescu 193b77f6600SCristian Dumitrescu port_id = params->port_id; 194b77f6600SCristian Dumitrescu if (params->dev_name) { 195b77f6600SCristian Dumitrescu status = rte_eth_dev_get_port_by_name(params->dev_name, 196b77f6600SCristian Dumitrescu &port_id); 197b77f6600SCristian Dumitrescu 198b77f6600SCristian Dumitrescu if (status) 199b77f6600SCristian Dumitrescu return NULL; 200b77f6600SCristian Dumitrescu } else 201b77f6600SCristian Dumitrescu if (!rte_eth_dev_is_valid_port(port_id)) 202b77f6600SCristian Dumitrescu return NULL; 203b77f6600SCristian Dumitrescu 204b77f6600SCristian Dumitrescu if (rte_eth_dev_info_get(port_id, &port_info) != 0) 205b77f6600SCristian Dumitrescu return NULL; 206b77f6600SCristian Dumitrescu 207b77f6600SCristian Dumitrescu mempool = mempool_find(obj, params->rx.mempool_name); 208b77f6600SCristian Dumitrescu if (mempool == NULL) 209b77f6600SCristian Dumitrescu return NULL; 210b77f6600SCristian Dumitrescu 211b77f6600SCristian Dumitrescu rss = params->rx.rss; 212b77f6600SCristian Dumitrescu if (rss) { 213b77f6600SCristian Dumitrescu if ((port_info.reta_size == 0) || 214b77f6600SCristian Dumitrescu (port_info.reta_size > ETH_RSS_RETA_SIZE_512)) 215b77f6600SCristian Dumitrescu return NULL; 216b77f6600SCristian Dumitrescu 217b77f6600SCristian Dumitrescu if ((rss->n_queues == 0) || 218b77f6600SCristian Dumitrescu (rss->n_queues >= LINK_RXQ_RSS_MAX)) 219b77f6600SCristian Dumitrescu return NULL; 220b77f6600SCristian Dumitrescu 221b77f6600SCristian Dumitrescu for (i = 0; i < rss->n_queues; i++) 222b77f6600SCristian Dumitrescu if (rss->queue_id[i] >= port_info.max_rx_queues) 223b77f6600SCristian Dumitrescu return NULL; 224b77f6600SCristian Dumitrescu } 225b77f6600SCristian Dumitrescu 226b77f6600SCristian Dumitrescu /** 227b77f6600SCristian Dumitrescu * Resource create 228b77f6600SCristian Dumitrescu */ 229b77f6600SCristian Dumitrescu /* Port */ 230b77f6600SCristian Dumitrescu memcpy(&port_conf, &port_conf_default, sizeof(port_conf)); 231b77f6600SCristian Dumitrescu if (rss) { 232b77f6600SCristian Dumitrescu port_conf.rxmode.mq_mode = ETH_MQ_RX_RSS; 233b77f6600SCristian Dumitrescu port_conf.rx_adv_conf.rss_conf.rss_hf = 234b77f6600SCristian Dumitrescu (ETH_RSS_IP | ETH_RSS_TCP | ETH_RSS_UDP) & 235b77f6600SCristian Dumitrescu port_info.flow_type_rss_offloads; 236b77f6600SCristian Dumitrescu } 237b77f6600SCristian Dumitrescu 238b77f6600SCristian Dumitrescu cpu_id = (uint32_t) rte_eth_dev_socket_id(port_id); 239b77f6600SCristian Dumitrescu if (cpu_id == (uint32_t) SOCKET_ID_ANY) 240b77f6600SCristian Dumitrescu cpu_id = 0; 241b77f6600SCristian Dumitrescu 242b77f6600SCristian Dumitrescu status = rte_eth_dev_configure( 243b77f6600SCristian Dumitrescu port_id, 244b77f6600SCristian Dumitrescu params->rx.n_queues, 245b77f6600SCristian Dumitrescu params->tx.n_queues, 246b77f6600SCristian Dumitrescu &port_conf); 247b77f6600SCristian Dumitrescu 248b77f6600SCristian Dumitrescu if (status < 0) 249b77f6600SCristian Dumitrescu return NULL; 250b77f6600SCristian Dumitrescu 251b77f6600SCristian Dumitrescu if (params->promiscuous) { 252b77f6600SCristian Dumitrescu status = rte_eth_promiscuous_enable(port_id); 253b77f6600SCristian Dumitrescu if (status != 0) 254b77f6600SCristian Dumitrescu return NULL; 255b77f6600SCristian Dumitrescu } 256b77f6600SCristian Dumitrescu 257b77f6600SCristian Dumitrescu /* Port RX */ 258b77f6600SCristian Dumitrescu for (i = 0; i < params->rx.n_queues; i++) { 259b77f6600SCristian Dumitrescu status = rte_eth_rx_queue_setup( 260b77f6600SCristian Dumitrescu port_id, 261b77f6600SCristian Dumitrescu i, 262b77f6600SCristian Dumitrescu params->rx.queue_size, 263b77f6600SCristian Dumitrescu cpu_id, 264b77f6600SCristian Dumitrescu NULL, 265b77f6600SCristian Dumitrescu mempool->m); 266b77f6600SCristian Dumitrescu 267b77f6600SCristian Dumitrescu if (status < 0) 268b77f6600SCristian Dumitrescu return NULL; 269b77f6600SCristian Dumitrescu } 270b77f6600SCristian Dumitrescu 271b77f6600SCristian Dumitrescu /* Port TX */ 272b77f6600SCristian Dumitrescu for (i = 0; i < params->tx.n_queues; i++) { 273b77f6600SCristian Dumitrescu status = rte_eth_tx_queue_setup( 274b77f6600SCristian Dumitrescu port_id, 275b77f6600SCristian Dumitrescu i, 276b77f6600SCristian Dumitrescu params->tx.queue_size, 277b77f6600SCristian Dumitrescu cpu_id, 278b77f6600SCristian Dumitrescu NULL); 279b77f6600SCristian Dumitrescu 280b77f6600SCristian Dumitrescu if (status < 0) 281b77f6600SCristian Dumitrescu return NULL; 282b77f6600SCristian Dumitrescu } 283b77f6600SCristian Dumitrescu 284b77f6600SCristian Dumitrescu /* Port start */ 285b77f6600SCristian Dumitrescu status = rte_eth_dev_start(port_id); 286b77f6600SCristian Dumitrescu if (status < 0) 287b77f6600SCristian Dumitrescu return NULL; 288b77f6600SCristian Dumitrescu 289b77f6600SCristian Dumitrescu if (rss) { 290b77f6600SCristian Dumitrescu status = rss_setup(port_id, port_info.reta_size, rss); 291b77f6600SCristian Dumitrescu 292b77f6600SCristian Dumitrescu if (status) { 293b77f6600SCristian Dumitrescu rte_eth_dev_stop(port_id); 294b77f6600SCristian Dumitrescu return NULL; 295b77f6600SCristian Dumitrescu } 296b77f6600SCristian Dumitrescu } 297b77f6600SCristian Dumitrescu 298b77f6600SCristian Dumitrescu /* Port link up */ 299b77f6600SCristian Dumitrescu status = rte_eth_dev_set_link_up(port_id); 300b77f6600SCristian Dumitrescu if ((status < 0) && (status != -ENOTSUP)) { 301b77f6600SCristian Dumitrescu rte_eth_dev_stop(port_id); 302b77f6600SCristian Dumitrescu return NULL; 303b77f6600SCristian Dumitrescu } 304b77f6600SCristian Dumitrescu 305b77f6600SCristian Dumitrescu /* Node allocation */ 306b77f6600SCristian Dumitrescu link = calloc(1, sizeof(struct link)); 307b77f6600SCristian Dumitrescu if (link == NULL) { 308b77f6600SCristian Dumitrescu rte_eth_dev_stop(port_id); 309b77f6600SCristian Dumitrescu return NULL; 310b77f6600SCristian Dumitrescu } 311b77f6600SCristian Dumitrescu 312b77f6600SCristian Dumitrescu /* Node fill in */ 313b77f6600SCristian Dumitrescu strlcpy(link->name, name, sizeof(link->name)); 314b77f6600SCristian Dumitrescu link->port_id = port_id; 315b77f6600SCristian Dumitrescu rte_eth_dev_get_name_by_port(port_id, link->dev_name); 316b77f6600SCristian Dumitrescu link->n_rxq = params->rx.n_queues; 317b77f6600SCristian Dumitrescu link->n_txq = params->tx.n_queues; 318b77f6600SCristian Dumitrescu 319b77f6600SCristian Dumitrescu /* Node add to list */ 320b77f6600SCristian Dumitrescu TAILQ_INSERT_TAIL(&obj->link_list, link, node); 321b77f6600SCristian Dumitrescu 322b77f6600SCristian Dumitrescu return link; 323b77f6600SCristian Dumitrescu } 324b77f6600SCristian Dumitrescu 325b77f6600SCristian Dumitrescu int 326b77f6600SCristian Dumitrescu link_is_up(struct obj *obj, const char *name) 327b77f6600SCristian Dumitrescu { 328b77f6600SCristian Dumitrescu struct rte_eth_link link_params; 329b77f6600SCristian Dumitrescu struct link *link; 330b77f6600SCristian Dumitrescu 331b77f6600SCristian Dumitrescu /* Check input params */ 332b77f6600SCristian Dumitrescu if (!obj || !name) 333b77f6600SCristian Dumitrescu return 0; 334b77f6600SCristian Dumitrescu 335b77f6600SCristian Dumitrescu link = link_find(obj, name); 336b77f6600SCristian Dumitrescu if (link == NULL) 337b77f6600SCristian Dumitrescu return 0; 338b77f6600SCristian Dumitrescu 339b77f6600SCristian Dumitrescu /* Resource */ 340b77f6600SCristian Dumitrescu if (rte_eth_link_get(link->port_id, &link_params) < 0) 341b77f6600SCristian Dumitrescu return 0; 342b77f6600SCristian Dumitrescu 343b77f6600SCristian Dumitrescu return (link_params.link_status == ETH_LINK_DOWN) ? 0 : 1; 344b77f6600SCristian Dumitrescu } 345b77f6600SCristian Dumitrescu 346b77f6600SCristian Dumitrescu struct link * 347b77f6600SCristian Dumitrescu link_find(struct obj *obj, const char *name) 348b77f6600SCristian Dumitrescu { 349b77f6600SCristian Dumitrescu struct link *link; 350b77f6600SCristian Dumitrescu 351b77f6600SCristian Dumitrescu if (!obj || !name) 352b77f6600SCristian Dumitrescu return NULL; 353b77f6600SCristian Dumitrescu 354b77f6600SCristian Dumitrescu TAILQ_FOREACH(link, &obj->link_list, node) 355b77f6600SCristian Dumitrescu if (strcmp(link->name, name) == 0) 356b77f6600SCristian Dumitrescu return link; 357b77f6600SCristian Dumitrescu 358b77f6600SCristian Dumitrescu return NULL; 359b77f6600SCristian Dumitrescu } 360b77f6600SCristian Dumitrescu 361b77f6600SCristian Dumitrescu struct link * 362b77f6600SCristian Dumitrescu link_next(struct obj *obj, struct link *link) 363b77f6600SCristian Dumitrescu { 364b77f6600SCristian Dumitrescu return (link == NULL) ? 365b77f6600SCristian Dumitrescu TAILQ_FIRST(&obj->link_list) : TAILQ_NEXT(link, node); 366b77f6600SCristian Dumitrescu } 367b77f6600SCristian Dumitrescu 368b77f6600SCristian Dumitrescu /* 369*77a41301SCristian Dumitrescu * ring 370*77a41301SCristian Dumitrescu */ 371*77a41301SCristian Dumitrescu struct ring * 372*77a41301SCristian Dumitrescu ring_create(struct obj *obj, const char *name, struct ring_params *params) 373*77a41301SCristian Dumitrescu { 374*77a41301SCristian Dumitrescu struct ring *ring; 375*77a41301SCristian Dumitrescu struct rte_ring *r; 376*77a41301SCristian Dumitrescu unsigned int flags = RING_F_SP_ENQ | RING_F_SC_DEQ; 377*77a41301SCristian Dumitrescu 378*77a41301SCristian Dumitrescu /* Check input params */ 379*77a41301SCristian Dumitrescu if (!name || ring_find(obj, name) || !params || !params->size) 380*77a41301SCristian Dumitrescu return NULL; 381*77a41301SCristian Dumitrescu 382*77a41301SCristian Dumitrescu /** 383*77a41301SCristian Dumitrescu * Resource create 384*77a41301SCristian Dumitrescu */ 385*77a41301SCristian Dumitrescu r = rte_ring_create( 386*77a41301SCristian Dumitrescu name, 387*77a41301SCristian Dumitrescu params->size, 388*77a41301SCristian Dumitrescu params->numa_node, 389*77a41301SCristian Dumitrescu flags); 390*77a41301SCristian Dumitrescu if (!r) 391*77a41301SCristian Dumitrescu return NULL; 392*77a41301SCristian Dumitrescu 393*77a41301SCristian Dumitrescu /* Node allocation */ 394*77a41301SCristian Dumitrescu ring = calloc(1, sizeof(struct ring)); 395*77a41301SCristian Dumitrescu if (!ring) { 396*77a41301SCristian Dumitrescu rte_ring_free(r); 397*77a41301SCristian Dumitrescu return NULL; 398*77a41301SCristian Dumitrescu } 399*77a41301SCristian Dumitrescu 400*77a41301SCristian Dumitrescu /* Node fill in */ 401*77a41301SCristian Dumitrescu strlcpy(ring->name, name, sizeof(ring->name)); 402*77a41301SCristian Dumitrescu 403*77a41301SCristian Dumitrescu /* Node add to list */ 404*77a41301SCristian Dumitrescu TAILQ_INSERT_TAIL(&obj->ring_list, ring, node); 405*77a41301SCristian Dumitrescu 406*77a41301SCristian Dumitrescu return ring; 407*77a41301SCristian Dumitrescu } 408*77a41301SCristian Dumitrescu 409*77a41301SCristian Dumitrescu struct ring * 410*77a41301SCristian Dumitrescu ring_find(struct obj *obj, const char *name) 411*77a41301SCristian Dumitrescu { 412*77a41301SCristian Dumitrescu struct ring *ring; 413*77a41301SCristian Dumitrescu 414*77a41301SCristian Dumitrescu if (!obj || !name) 415*77a41301SCristian Dumitrescu return NULL; 416*77a41301SCristian Dumitrescu 417*77a41301SCristian Dumitrescu TAILQ_FOREACH(ring, &obj->ring_list, node) 418*77a41301SCristian Dumitrescu if (strcmp(ring->name, name) == 0) 419*77a41301SCristian Dumitrescu return ring; 420*77a41301SCristian Dumitrescu 421*77a41301SCristian Dumitrescu return NULL; 422*77a41301SCristian Dumitrescu } 423*77a41301SCristian Dumitrescu 424*77a41301SCristian Dumitrescu /* 425b77f6600SCristian Dumitrescu * pipeline 426b77f6600SCristian Dumitrescu */ 427b77f6600SCristian Dumitrescu #ifndef PIPELINE_MSGQ_SIZE 428b77f6600SCristian Dumitrescu #define PIPELINE_MSGQ_SIZE 64 429b77f6600SCristian Dumitrescu #endif 430b77f6600SCristian Dumitrescu 431b77f6600SCristian Dumitrescu struct pipeline * 432b77f6600SCristian Dumitrescu pipeline_create(struct obj *obj, const char *name, int numa_node) 433b77f6600SCristian Dumitrescu { 434b77f6600SCristian Dumitrescu struct pipeline *pipeline; 435b77f6600SCristian Dumitrescu struct rte_swx_pipeline *p = NULL; 436b77f6600SCristian Dumitrescu int status; 437b77f6600SCristian Dumitrescu 438b77f6600SCristian Dumitrescu /* Check input params */ 439b77f6600SCristian Dumitrescu if ((name == NULL) || 440b77f6600SCristian Dumitrescu pipeline_find(obj, name)) 441b77f6600SCristian Dumitrescu return NULL; 442b77f6600SCristian Dumitrescu 443b77f6600SCristian Dumitrescu /* Resource create */ 444b77f6600SCristian Dumitrescu status = rte_swx_pipeline_config(&p, numa_node); 445b77f6600SCristian Dumitrescu if (status) 446b77f6600SCristian Dumitrescu goto error; 447b77f6600SCristian Dumitrescu 448b77f6600SCristian Dumitrescu status = rte_swx_pipeline_port_in_type_register(p, 449b77f6600SCristian Dumitrescu "ethdev", 450b77f6600SCristian Dumitrescu &rte_swx_port_ethdev_reader_ops); 451b77f6600SCristian Dumitrescu if (status) 452b77f6600SCristian Dumitrescu goto error; 453b77f6600SCristian Dumitrescu 454b77f6600SCristian Dumitrescu status = rte_swx_pipeline_port_out_type_register(p, 455b77f6600SCristian Dumitrescu "ethdev", 456b77f6600SCristian Dumitrescu &rte_swx_port_ethdev_writer_ops); 457b77f6600SCristian Dumitrescu if (status) 458b77f6600SCristian Dumitrescu goto error; 459b77f6600SCristian Dumitrescu 460*77a41301SCristian Dumitrescu status = rte_swx_pipeline_port_in_type_register(p, 461*77a41301SCristian Dumitrescu "ring", 462*77a41301SCristian Dumitrescu &rte_swx_port_ring_reader_ops); 463*77a41301SCristian Dumitrescu if (status) 464*77a41301SCristian Dumitrescu goto error; 465*77a41301SCristian Dumitrescu 466*77a41301SCristian Dumitrescu status = rte_swx_pipeline_port_out_type_register(p, 467*77a41301SCristian Dumitrescu "ring", 468*77a41301SCristian Dumitrescu &rte_swx_port_ring_writer_ops); 469*77a41301SCristian Dumitrescu if (status) 470*77a41301SCristian Dumitrescu goto error; 471*77a41301SCristian Dumitrescu 472b77f6600SCristian Dumitrescu #ifdef RTE_PORT_PCAP 473b77f6600SCristian Dumitrescu status = rte_swx_pipeline_port_in_type_register(p, 474b77f6600SCristian Dumitrescu "source", 475b77f6600SCristian Dumitrescu &rte_swx_port_source_ops); 476b77f6600SCristian Dumitrescu if (status) 477b77f6600SCristian Dumitrescu goto error; 478b77f6600SCristian Dumitrescu #endif 479b77f6600SCristian Dumitrescu 480b77f6600SCristian Dumitrescu status = rte_swx_pipeline_port_out_type_register(p, 481b77f6600SCristian Dumitrescu "sink", 482b77f6600SCristian Dumitrescu &rte_swx_port_sink_ops); 483b77f6600SCristian Dumitrescu if (status) 484b77f6600SCristian Dumitrescu goto error; 485b77f6600SCristian Dumitrescu 486b77f6600SCristian Dumitrescu status = rte_swx_pipeline_table_type_register(p, 487b77f6600SCristian Dumitrescu "exact", 488b77f6600SCristian Dumitrescu RTE_SWX_TABLE_MATCH_EXACT, 489b77f6600SCristian Dumitrescu &rte_swx_table_exact_match_ops); 490b77f6600SCristian Dumitrescu if (status) 491b77f6600SCristian Dumitrescu goto error; 492b77f6600SCristian Dumitrescu 493b77f6600SCristian Dumitrescu /* Node allocation */ 494b77f6600SCristian Dumitrescu pipeline = calloc(1, sizeof(struct pipeline)); 495b77f6600SCristian Dumitrescu if (pipeline == NULL) 496b77f6600SCristian Dumitrescu goto error; 497b77f6600SCristian Dumitrescu 498b77f6600SCristian Dumitrescu /* Node fill in */ 499b77f6600SCristian Dumitrescu strlcpy(pipeline->name, name, sizeof(pipeline->name)); 500b77f6600SCristian Dumitrescu pipeline->p = p; 501b77f6600SCristian Dumitrescu pipeline->timer_period_ms = 10; 502b77f6600SCristian Dumitrescu 503b77f6600SCristian Dumitrescu /* Node add to list */ 504b77f6600SCristian Dumitrescu TAILQ_INSERT_TAIL(&obj->pipeline_list, pipeline, node); 505b77f6600SCristian Dumitrescu 506b77f6600SCristian Dumitrescu return pipeline; 507b77f6600SCristian Dumitrescu 508b77f6600SCristian Dumitrescu error: 509b77f6600SCristian Dumitrescu rte_swx_pipeline_free(p); 510b77f6600SCristian Dumitrescu return NULL; 511b77f6600SCristian Dumitrescu } 512b77f6600SCristian Dumitrescu 513b77f6600SCristian Dumitrescu struct pipeline * 514b77f6600SCristian Dumitrescu pipeline_find(struct obj *obj, const char *name) 515b77f6600SCristian Dumitrescu { 516b77f6600SCristian Dumitrescu struct pipeline *pipeline; 517b77f6600SCristian Dumitrescu 518b77f6600SCristian Dumitrescu if (!obj || !name) 519b77f6600SCristian Dumitrescu return NULL; 520b77f6600SCristian Dumitrescu 521b77f6600SCristian Dumitrescu TAILQ_FOREACH(pipeline, &obj->pipeline_list, node) 522b77f6600SCristian Dumitrescu if (strcmp(name, pipeline->name) == 0) 523b77f6600SCristian Dumitrescu return pipeline; 524b77f6600SCristian Dumitrescu 525b77f6600SCristian Dumitrescu return NULL; 526b77f6600SCristian Dumitrescu } 527b77f6600SCristian Dumitrescu 528b77f6600SCristian Dumitrescu /* 529b77f6600SCristian Dumitrescu * obj 530b77f6600SCristian Dumitrescu */ 531b77f6600SCristian Dumitrescu struct obj * 532b77f6600SCristian Dumitrescu obj_init(void) 533b77f6600SCristian Dumitrescu { 534b77f6600SCristian Dumitrescu struct obj *obj; 535b77f6600SCristian Dumitrescu 536b77f6600SCristian Dumitrescu obj = calloc(1, sizeof(struct obj)); 537b77f6600SCristian Dumitrescu if (!obj) 538b77f6600SCristian Dumitrescu return NULL; 539b77f6600SCristian Dumitrescu 540b77f6600SCristian Dumitrescu TAILQ_INIT(&obj->mempool_list); 541b77f6600SCristian Dumitrescu TAILQ_INIT(&obj->link_list); 542*77a41301SCristian Dumitrescu TAILQ_INIT(&obj->ring_list); 543b77f6600SCristian Dumitrescu TAILQ_INIT(&obj->pipeline_list); 544b77f6600SCristian Dumitrescu 545b77f6600SCristian Dumitrescu return obj; 546b77f6600SCristian Dumitrescu } 547