1*99a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 2*99a2dd95SBruce Richardson * Copyright(C) 2019 Marvell International Ltd. 3*99a2dd95SBruce Richardson * Copyright 2020 Mellanox Technologies, Ltd 4*99a2dd95SBruce Richardson */ 5*99a2dd95SBruce Richardson 6*99a2dd95SBruce Richardson #include <string.h> 7*99a2dd95SBruce Richardson 8*99a2dd95SBruce Richardson #include <rte_memory.h> 9*99a2dd95SBruce Richardson #include <rte_memcpy.h> 10*99a2dd95SBruce Richardson #include <rte_memzone.h> 11*99a2dd95SBruce Richardson #include <rte_string_fns.h> 12*99a2dd95SBruce Richardson 13*99a2dd95SBruce Richardson #include "rte_regexdev.h" 14*99a2dd95SBruce Richardson #include "rte_regexdev_core.h" 15*99a2dd95SBruce Richardson #include "rte_regexdev_driver.h" 16*99a2dd95SBruce Richardson 17*99a2dd95SBruce Richardson static const char *MZ_RTE_REGEXDEV_DATA = "rte_regexdev_data"; 18*99a2dd95SBruce Richardson struct rte_regexdev rte_regex_devices[RTE_MAX_REGEXDEV_DEVS]; 19*99a2dd95SBruce Richardson /* Shared memory between primary and secondary processes. */ 20*99a2dd95SBruce Richardson static struct { 21*99a2dd95SBruce Richardson struct rte_regexdev_data data[RTE_MAX_REGEXDEV_DEVS]; 22*99a2dd95SBruce Richardson } *rte_regexdev_shared_data; 23*99a2dd95SBruce Richardson 24*99a2dd95SBruce Richardson int rte_regexdev_logtype; 25*99a2dd95SBruce Richardson 26*99a2dd95SBruce Richardson static uint16_t 27*99a2dd95SBruce Richardson regexdev_find_free_dev(void) 28*99a2dd95SBruce Richardson { 29*99a2dd95SBruce Richardson uint16_t i; 30*99a2dd95SBruce Richardson 31*99a2dd95SBruce Richardson for (i = 0; i < RTE_MAX_REGEXDEV_DEVS; i++) { 32*99a2dd95SBruce Richardson if (rte_regex_devices[i].state == RTE_REGEXDEV_UNUSED) 33*99a2dd95SBruce Richardson return i; 34*99a2dd95SBruce Richardson } 35*99a2dd95SBruce Richardson return RTE_MAX_REGEXDEV_DEVS; 36*99a2dd95SBruce Richardson } 37*99a2dd95SBruce Richardson 38*99a2dd95SBruce Richardson static struct rte_regexdev* 39*99a2dd95SBruce Richardson regexdev_allocated(const char *name) 40*99a2dd95SBruce Richardson { 41*99a2dd95SBruce Richardson uint16_t i; 42*99a2dd95SBruce Richardson 43*99a2dd95SBruce Richardson for (i = 0; i < RTE_MAX_REGEXDEV_DEVS; i++) { 44*99a2dd95SBruce Richardson if (rte_regex_devices[i].state != RTE_REGEXDEV_UNUSED) 45*99a2dd95SBruce Richardson if (!strcmp(name, rte_regex_devices[i].data->dev_name)) 46*99a2dd95SBruce Richardson return &rte_regex_devices[i]; 47*99a2dd95SBruce Richardson } 48*99a2dd95SBruce Richardson return NULL; 49*99a2dd95SBruce Richardson } 50*99a2dd95SBruce Richardson 51*99a2dd95SBruce Richardson static int 52*99a2dd95SBruce Richardson regexdev_shared_data_prepare(void) 53*99a2dd95SBruce Richardson { 54*99a2dd95SBruce Richardson const unsigned int flags = 0; 55*99a2dd95SBruce Richardson const struct rte_memzone *mz; 56*99a2dd95SBruce Richardson 57*99a2dd95SBruce Richardson if (rte_regexdev_shared_data == NULL) { 58*99a2dd95SBruce Richardson /* Allocate port data and ownership shared memory. */ 59*99a2dd95SBruce Richardson mz = rte_memzone_reserve(MZ_RTE_REGEXDEV_DATA, 60*99a2dd95SBruce Richardson sizeof(*rte_regexdev_shared_data), 61*99a2dd95SBruce Richardson rte_socket_id(), flags); 62*99a2dd95SBruce Richardson if (mz == NULL) 63*99a2dd95SBruce Richardson return -ENOMEM; 64*99a2dd95SBruce Richardson 65*99a2dd95SBruce Richardson rte_regexdev_shared_data = mz->addr; 66*99a2dd95SBruce Richardson memset(rte_regexdev_shared_data->data, 0, 67*99a2dd95SBruce Richardson sizeof(rte_regexdev_shared_data->data)); 68*99a2dd95SBruce Richardson } 69*99a2dd95SBruce Richardson return 0; 70*99a2dd95SBruce Richardson } 71*99a2dd95SBruce Richardson 72*99a2dd95SBruce Richardson static int 73*99a2dd95SBruce Richardson regexdev_check_name(const char *name) 74*99a2dd95SBruce Richardson { 75*99a2dd95SBruce Richardson size_t name_len; 76*99a2dd95SBruce Richardson 77*99a2dd95SBruce Richardson if (name == NULL) { 78*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Name can't be NULL\n"); 79*99a2dd95SBruce Richardson return -EINVAL; 80*99a2dd95SBruce Richardson } 81*99a2dd95SBruce Richardson name_len = strnlen(name, RTE_REGEXDEV_NAME_MAX_LEN); 82*99a2dd95SBruce Richardson if (name_len == 0) { 83*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Zero length RegEx device name\n"); 84*99a2dd95SBruce Richardson return -EINVAL; 85*99a2dd95SBruce Richardson } 86*99a2dd95SBruce Richardson if (name_len >= RTE_REGEXDEV_NAME_MAX_LEN) { 87*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "RegEx device name is too long\n"); 88*99a2dd95SBruce Richardson return -EINVAL; 89*99a2dd95SBruce Richardson } 90*99a2dd95SBruce Richardson return (int)name_len; 91*99a2dd95SBruce Richardson 92*99a2dd95SBruce Richardson } 93*99a2dd95SBruce Richardson 94*99a2dd95SBruce Richardson struct rte_regexdev * 95*99a2dd95SBruce Richardson rte_regexdev_register(const char *name) 96*99a2dd95SBruce Richardson { 97*99a2dd95SBruce Richardson uint16_t dev_id; 98*99a2dd95SBruce Richardson int name_len; 99*99a2dd95SBruce Richardson struct rte_regexdev *dev; 100*99a2dd95SBruce Richardson 101*99a2dd95SBruce Richardson name_len = regexdev_check_name(name); 102*99a2dd95SBruce Richardson if (name_len < 0) 103*99a2dd95SBruce Richardson return NULL; 104*99a2dd95SBruce Richardson dev = regexdev_allocated(name); 105*99a2dd95SBruce Richardson if (dev != NULL) { 106*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "RegEx device already allocated\n"); 107*99a2dd95SBruce Richardson return NULL; 108*99a2dd95SBruce Richardson } 109*99a2dd95SBruce Richardson dev_id = regexdev_find_free_dev(); 110*99a2dd95SBruce Richardson if (dev_id == RTE_MAX_REGEXDEV_DEVS) { 111*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG 112*99a2dd95SBruce Richardson (ERR, "Reached maximum number of RegEx devices\n"); 113*99a2dd95SBruce Richardson return NULL; 114*99a2dd95SBruce Richardson } 115*99a2dd95SBruce Richardson if (regexdev_shared_data_prepare() < 0) { 116*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Cannot allocate RegEx shared data\n"); 117*99a2dd95SBruce Richardson return NULL; 118*99a2dd95SBruce Richardson } 119*99a2dd95SBruce Richardson 120*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 121*99a2dd95SBruce Richardson dev->state = RTE_REGEXDEV_REGISTERED; 122*99a2dd95SBruce Richardson if (dev->data == NULL) 123*99a2dd95SBruce Richardson dev->data = &rte_regexdev_shared_data->data[dev_id]; 124*99a2dd95SBruce Richardson else 125*99a2dd95SBruce Richardson memset(dev->data, 1, sizeof(*dev->data)); 126*99a2dd95SBruce Richardson dev->data->dev_id = dev_id; 127*99a2dd95SBruce Richardson strlcpy(dev->data->dev_name, name, sizeof(dev->data->dev_name)); 128*99a2dd95SBruce Richardson return dev; 129*99a2dd95SBruce Richardson } 130*99a2dd95SBruce Richardson 131*99a2dd95SBruce Richardson void 132*99a2dd95SBruce Richardson rte_regexdev_unregister(struct rte_regexdev *dev) 133*99a2dd95SBruce Richardson { 134*99a2dd95SBruce Richardson dev->state = RTE_REGEXDEV_UNUSED; 135*99a2dd95SBruce Richardson } 136*99a2dd95SBruce Richardson 137*99a2dd95SBruce Richardson struct rte_regexdev * 138*99a2dd95SBruce Richardson rte_regexdev_get_device_by_name(const char *name) 139*99a2dd95SBruce Richardson { 140*99a2dd95SBruce Richardson if (regexdev_check_name(name) < 0) 141*99a2dd95SBruce Richardson return NULL; 142*99a2dd95SBruce Richardson return regexdev_allocated(name); 143*99a2dd95SBruce Richardson } 144*99a2dd95SBruce Richardson 145*99a2dd95SBruce Richardson uint8_t 146*99a2dd95SBruce Richardson rte_regexdev_count(void) 147*99a2dd95SBruce Richardson { 148*99a2dd95SBruce Richardson int i; 149*99a2dd95SBruce Richardson int count = 0; 150*99a2dd95SBruce Richardson 151*99a2dd95SBruce Richardson for (i = 0; i < RTE_MAX_REGEXDEV_DEVS; i++) { 152*99a2dd95SBruce Richardson if (rte_regex_devices[i].state != RTE_REGEXDEV_UNUSED) 153*99a2dd95SBruce Richardson count++; 154*99a2dd95SBruce Richardson } 155*99a2dd95SBruce Richardson return count; 156*99a2dd95SBruce Richardson } 157*99a2dd95SBruce Richardson 158*99a2dd95SBruce Richardson int 159*99a2dd95SBruce Richardson rte_regexdev_get_dev_id(const char *name) 160*99a2dd95SBruce Richardson { 161*99a2dd95SBruce Richardson int i; 162*99a2dd95SBruce Richardson int id = -EINVAL; 163*99a2dd95SBruce Richardson 164*99a2dd95SBruce Richardson if (name == NULL) 165*99a2dd95SBruce Richardson return -EINVAL; 166*99a2dd95SBruce Richardson for (i = 0; i < RTE_MAX_REGEXDEV_DEVS; i++) { 167*99a2dd95SBruce Richardson if (rte_regex_devices[i].state != RTE_REGEXDEV_UNUSED) 168*99a2dd95SBruce Richardson if (strcmp(name, rte_regex_devices[i].data->dev_name)) { 169*99a2dd95SBruce Richardson id = rte_regex_devices[i].data->dev_id; 170*99a2dd95SBruce Richardson break; 171*99a2dd95SBruce Richardson } 172*99a2dd95SBruce Richardson } 173*99a2dd95SBruce Richardson return id; 174*99a2dd95SBruce Richardson } 175*99a2dd95SBruce Richardson 176*99a2dd95SBruce Richardson int 177*99a2dd95SBruce Richardson rte_regexdev_is_valid_dev(uint16_t dev_id) 178*99a2dd95SBruce Richardson { 179*99a2dd95SBruce Richardson if (dev_id >= RTE_MAX_REGEXDEV_DEVS || 180*99a2dd95SBruce Richardson rte_regex_devices[dev_id].state != RTE_REGEXDEV_READY) 181*99a2dd95SBruce Richardson return 0; 182*99a2dd95SBruce Richardson return 1; 183*99a2dd95SBruce Richardson } 184*99a2dd95SBruce Richardson 185*99a2dd95SBruce Richardson static int 186*99a2dd95SBruce Richardson regexdev_info_get(uint8_t dev_id, struct rte_regexdev_info *dev_info) 187*99a2dd95SBruce Richardson { 188*99a2dd95SBruce Richardson struct rte_regexdev *dev; 189*99a2dd95SBruce Richardson 190*99a2dd95SBruce Richardson RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 191*99a2dd95SBruce Richardson if (dev_info == NULL) 192*99a2dd95SBruce Richardson return -EINVAL; 193*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 194*99a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_info_get, -ENOTSUP); 195*99a2dd95SBruce Richardson return (*dev->dev_ops->dev_info_get)(dev, dev_info); 196*99a2dd95SBruce Richardson 197*99a2dd95SBruce Richardson } 198*99a2dd95SBruce Richardson 199*99a2dd95SBruce Richardson int 200*99a2dd95SBruce Richardson rte_regexdev_info_get(uint8_t dev_id, struct rte_regexdev_info *dev_info) 201*99a2dd95SBruce Richardson { 202*99a2dd95SBruce Richardson return regexdev_info_get(dev_id, dev_info); 203*99a2dd95SBruce Richardson } 204*99a2dd95SBruce Richardson 205*99a2dd95SBruce Richardson int 206*99a2dd95SBruce Richardson rte_regexdev_configure(uint8_t dev_id, const struct rte_regexdev_config *cfg) 207*99a2dd95SBruce Richardson { 208*99a2dd95SBruce Richardson struct rte_regexdev *dev; 209*99a2dd95SBruce Richardson struct rte_regexdev_info dev_info; 210*99a2dd95SBruce Richardson int ret; 211*99a2dd95SBruce Richardson 212*99a2dd95SBruce Richardson RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 213*99a2dd95SBruce Richardson if (cfg == NULL) 214*99a2dd95SBruce Richardson return -EINVAL; 215*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 216*99a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP); 217*99a2dd95SBruce Richardson if (dev->data->dev_started) { 218*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG 219*99a2dd95SBruce Richardson (ERR, "Dev %u must be stopped to allow configuration\n", 220*99a2dd95SBruce Richardson dev_id); 221*99a2dd95SBruce Richardson return -EBUSY; 222*99a2dd95SBruce Richardson } 223*99a2dd95SBruce Richardson ret = regexdev_info_get(dev_id, &dev_info); 224*99a2dd95SBruce Richardson if (ret < 0) 225*99a2dd95SBruce Richardson return ret; 226*99a2dd95SBruce Richardson if ((cfg->dev_cfg_flags & RTE_REGEXDEV_CFG_CROSS_BUFFER_SCAN_F) && 227*99a2dd95SBruce Richardson !(dev_info.regexdev_capa & RTE_REGEXDEV_SUPP_CROSS_BUFFER_F)) { 228*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, 229*99a2dd95SBruce Richardson "Dev %u doesn't support cross buffer scan\n", 230*99a2dd95SBruce Richardson dev_id); 231*99a2dd95SBruce Richardson return -EINVAL; 232*99a2dd95SBruce Richardson } 233*99a2dd95SBruce Richardson if ((cfg->dev_cfg_flags & RTE_REGEXDEV_CFG_MATCH_AS_END_F) && 234*99a2dd95SBruce Richardson !(dev_info.regexdev_capa & RTE_REGEXDEV_SUPP_MATCH_AS_END_F)) { 235*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, 236*99a2dd95SBruce Richardson "Dev %u doesn't support match as end\n", 237*99a2dd95SBruce Richardson dev_id); 238*99a2dd95SBruce Richardson return -EINVAL; 239*99a2dd95SBruce Richardson } 240*99a2dd95SBruce Richardson if ((cfg->dev_cfg_flags & RTE_REGEXDEV_CFG_MATCH_ALL_F) && 241*99a2dd95SBruce Richardson !(dev_info.regexdev_capa & RTE_REGEXDEV_SUPP_MATCH_ALL_F)) { 242*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, 243*99a2dd95SBruce Richardson "Dev %u doesn't support match all\n", 244*99a2dd95SBruce Richardson dev_id); 245*99a2dd95SBruce Richardson return -EINVAL; 246*99a2dd95SBruce Richardson } 247*99a2dd95SBruce Richardson if (cfg->nb_groups == 0) { 248*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Dev %u num of groups must be > 0\n", 249*99a2dd95SBruce Richardson dev_id); 250*99a2dd95SBruce Richardson return -EINVAL; 251*99a2dd95SBruce Richardson } 252*99a2dd95SBruce Richardson if (cfg->nb_groups > dev_info.max_groups) { 253*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Dev %u num of groups %d > %d\n", 254*99a2dd95SBruce Richardson dev_id, cfg->nb_groups, dev_info.max_groups); 255*99a2dd95SBruce Richardson return -EINVAL; 256*99a2dd95SBruce Richardson } 257*99a2dd95SBruce Richardson if (cfg->nb_max_matches == 0) { 258*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Dev %u num of matches must be > 0\n", 259*99a2dd95SBruce Richardson dev_id); 260*99a2dd95SBruce Richardson return -EINVAL; 261*99a2dd95SBruce Richardson } 262*99a2dd95SBruce Richardson if (cfg->nb_max_matches > dev_info.max_matches) { 263*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Dev %u num of matches %d > %d\n", 264*99a2dd95SBruce Richardson dev_id, cfg->nb_max_matches, 265*99a2dd95SBruce Richardson dev_info.max_matches); 266*99a2dd95SBruce Richardson return -EINVAL; 267*99a2dd95SBruce Richardson } 268*99a2dd95SBruce Richardson if (cfg->nb_queue_pairs == 0) { 269*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Dev %u num of queues must be > 0\n", 270*99a2dd95SBruce Richardson dev_id); 271*99a2dd95SBruce Richardson return -EINVAL; 272*99a2dd95SBruce Richardson } 273*99a2dd95SBruce Richardson if (cfg->nb_queue_pairs > dev_info.max_queue_pairs) { 274*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Dev %u num of queues %d > %d\n", 275*99a2dd95SBruce Richardson dev_id, cfg->nb_queue_pairs, 276*99a2dd95SBruce Richardson dev_info.max_queue_pairs); 277*99a2dd95SBruce Richardson return -EINVAL; 278*99a2dd95SBruce Richardson } 279*99a2dd95SBruce Richardson if (cfg->nb_rules_per_group == 0) { 280*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, 281*99a2dd95SBruce Richardson "Dev %u num of rules per group must be > 0\n", 282*99a2dd95SBruce Richardson dev_id); 283*99a2dd95SBruce Richardson return -EINVAL; 284*99a2dd95SBruce Richardson } 285*99a2dd95SBruce Richardson if (cfg->nb_rules_per_group > dev_info.max_rules_per_group) { 286*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, 287*99a2dd95SBruce Richardson "Dev %u num of rules per group %d > %d\n", 288*99a2dd95SBruce Richardson dev_id, cfg->nb_rules_per_group, 289*99a2dd95SBruce Richardson dev_info.max_rules_per_group); 290*99a2dd95SBruce Richardson return -EINVAL; 291*99a2dd95SBruce Richardson } 292*99a2dd95SBruce Richardson ret = (*dev->dev_ops->dev_configure)(dev, cfg); 293*99a2dd95SBruce Richardson if (ret == 0) 294*99a2dd95SBruce Richardson dev->data->dev_conf = *cfg; 295*99a2dd95SBruce Richardson return ret; 296*99a2dd95SBruce Richardson } 297*99a2dd95SBruce Richardson 298*99a2dd95SBruce Richardson int 299*99a2dd95SBruce Richardson rte_regexdev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id, 300*99a2dd95SBruce Richardson const struct rte_regexdev_qp_conf *qp_conf) 301*99a2dd95SBruce Richardson { 302*99a2dd95SBruce Richardson struct rte_regexdev *dev; 303*99a2dd95SBruce Richardson 304*99a2dd95SBruce Richardson RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 305*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 306*99a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_qp_setup, -ENOTSUP); 307*99a2dd95SBruce Richardson if (dev->data->dev_started) { 308*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG 309*99a2dd95SBruce Richardson (ERR, "Dev %u must be stopped to allow configuration\n", 310*99a2dd95SBruce Richardson dev_id); 311*99a2dd95SBruce Richardson return -EBUSY; 312*99a2dd95SBruce Richardson } 313*99a2dd95SBruce Richardson if (queue_pair_id >= dev->data->dev_conf.nb_queue_pairs) { 314*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, 315*99a2dd95SBruce Richardson "Dev %u invalid queue %d > %d\n", 316*99a2dd95SBruce Richardson dev_id, queue_pair_id, 317*99a2dd95SBruce Richardson dev->data->dev_conf.nb_queue_pairs); 318*99a2dd95SBruce Richardson return -EINVAL; 319*99a2dd95SBruce Richardson } 320*99a2dd95SBruce Richardson if (dev->data->dev_started) { 321*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG 322*99a2dd95SBruce Richardson (ERR, "Dev %u must be stopped to allow configuration\n", 323*99a2dd95SBruce Richardson dev_id); 324*99a2dd95SBruce Richardson return -EBUSY; 325*99a2dd95SBruce Richardson } 326*99a2dd95SBruce Richardson return (*dev->dev_ops->dev_qp_setup)(dev, queue_pair_id, qp_conf); 327*99a2dd95SBruce Richardson } 328*99a2dd95SBruce Richardson 329*99a2dd95SBruce Richardson int 330*99a2dd95SBruce Richardson rte_regexdev_start(uint8_t dev_id) 331*99a2dd95SBruce Richardson { 332*99a2dd95SBruce Richardson struct rte_regexdev *dev; 333*99a2dd95SBruce Richardson int ret; 334*99a2dd95SBruce Richardson 335*99a2dd95SBruce Richardson RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 336*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 337*99a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP); 338*99a2dd95SBruce Richardson ret = (*dev->dev_ops->dev_start)(dev); 339*99a2dd95SBruce Richardson if (ret == 0) 340*99a2dd95SBruce Richardson dev->data->dev_started = 1; 341*99a2dd95SBruce Richardson return ret; 342*99a2dd95SBruce Richardson } 343*99a2dd95SBruce Richardson 344*99a2dd95SBruce Richardson int 345*99a2dd95SBruce Richardson rte_regexdev_stop(uint8_t dev_id) 346*99a2dd95SBruce Richardson { 347*99a2dd95SBruce Richardson struct rte_regexdev *dev; 348*99a2dd95SBruce Richardson 349*99a2dd95SBruce Richardson RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 350*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 351*99a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_stop, -ENOTSUP); 352*99a2dd95SBruce Richardson (*dev->dev_ops->dev_stop)(dev); 353*99a2dd95SBruce Richardson dev->data->dev_started = 0; 354*99a2dd95SBruce Richardson return 0; 355*99a2dd95SBruce Richardson } 356*99a2dd95SBruce Richardson 357*99a2dd95SBruce Richardson int 358*99a2dd95SBruce Richardson rte_regexdev_close(uint8_t dev_id) 359*99a2dd95SBruce Richardson { 360*99a2dd95SBruce Richardson struct rte_regexdev *dev; 361*99a2dd95SBruce Richardson 362*99a2dd95SBruce Richardson RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 363*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 364*99a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_close, -ENOTSUP); 365*99a2dd95SBruce Richardson (*dev->dev_ops->dev_close)(dev); 366*99a2dd95SBruce Richardson dev->data->dev_started = 0; 367*99a2dd95SBruce Richardson dev->state = RTE_REGEXDEV_UNUSED; 368*99a2dd95SBruce Richardson return 0; 369*99a2dd95SBruce Richardson } 370*99a2dd95SBruce Richardson 371*99a2dd95SBruce Richardson int 372*99a2dd95SBruce Richardson rte_regexdev_attr_get(uint8_t dev_id, enum rte_regexdev_attr_id attr_id, 373*99a2dd95SBruce Richardson void *attr_value) 374*99a2dd95SBruce Richardson { 375*99a2dd95SBruce Richardson struct rte_regexdev *dev; 376*99a2dd95SBruce Richardson 377*99a2dd95SBruce Richardson RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 378*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 379*99a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_attr_get, -ENOTSUP); 380*99a2dd95SBruce Richardson if (attr_value == NULL) { 381*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Dev %d attribute value can't be NULL\n", 382*99a2dd95SBruce Richardson dev_id); 383*99a2dd95SBruce Richardson return -EINVAL; 384*99a2dd95SBruce Richardson } 385*99a2dd95SBruce Richardson return (*dev->dev_ops->dev_attr_get)(dev, attr_id, attr_value); 386*99a2dd95SBruce Richardson } 387*99a2dd95SBruce Richardson 388*99a2dd95SBruce Richardson int 389*99a2dd95SBruce Richardson rte_regexdev_attr_set(uint8_t dev_id, enum rte_regexdev_attr_id attr_id, 390*99a2dd95SBruce Richardson const void *attr_value) 391*99a2dd95SBruce Richardson { 392*99a2dd95SBruce Richardson struct rte_regexdev *dev; 393*99a2dd95SBruce Richardson 394*99a2dd95SBruce Richardson RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 395*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 396*99a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_attr_set, -ENOTSUP); 397*99a2dd95SBruce Richardson if (attr_value == NULL) { 398*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Dev %d attribute value can't be NULL\n", 399*99a2dd95SBruce Richardson dev_id); 400*99a2dd95SBruce Richardson return -EINVAL; 401*99a2dd95SBruce Richardson } 402*99a2dd95SBruce Richardson return (*dev->dev_ops->dev_attr_set)(dev, attr_id, attr_value); 403*99a2dd95SBruce Richardson } 404*99a2dd95SBruce Richardson 405*99a2dd95SBruce Richardson int 406*99a2dd95SBruce Richardson rte_regexdev_rule_db_update(uint8_t dev_id, 407*99a2dd95SBruce Richardson const struct rte_regexdev_rule *rules, 408*99a2dd95SBruce Richardson uint32_t nb_rules) 409*99a2dd95SBruce Richardson { 410*99a2dd95SBruce Richardson struct rte_regexdev *dev; 411*99a2dd95SBruce Richardson 412*99a2dd95SBruce Richardson RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 413*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 414*99a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_rule_db_update, -ENOTSUP); 415*99a2dd95SBruce Richardson if (rules == NULL) { 416*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Dev %d rules can't be NULL\n", 417*99a2dd95SBruce Richardson dev_id); 418*99a2dd95SBruce Richardson return -EINVAL; 419*99a2dd95SBruce Richardson } 420*99a2dd95SBruce Richardson return (*dev->dev_ops->dev_rule_db_update)(dev, rules, nb_rules); 421*99a2dd95SBruce Richardson } 422*99a2dd95SBruce Richardson 423*99a2dd95SBruce Richardson int 424*99a2dd95SBruce Richardson rte_regexdev_rule_db_compile_activate(uint8_t dev_id) 425*99a2dd95SBruce Richardson { 426*99a2dd95SBruce Richardson struct rte_regexdev *dev; 427*99a2dd95SBruce Richardson 428*99a2dd95SBruce Richardson RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 429*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 430*99a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_rule_db_compile_activate, 431*99a2dd95SBruce Richardson -ENOTSUP); 432*99a2dd95SBruce Richardson return (*dev->dev_ops->dev_rule_db_compile_activate)(dev); 433*99a2dd95SBruce Richardson } 434*99a2dd95SBruce Richardson 435*99a2dd95SBruce Richardson int 436*99a2dd95SBruce Richardson rte_regexdev_rule_db_import(uint8_t dev_id, const char *rule_db, 437*99a2dd95SBruce Richardson uint32_t rule_db_len) 438*99a2dd95SBruce Richardson { 439*99a2dd95SBruce Richardson struct rte_regexdev *dev; 440*99a2dd95SBruce Richardson 441*99a2dd95SBruce Richardson RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 442*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 443*99a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_db_import, 444*99a2dd95SBruce Richardson -ENOTSUP); 445*99a2dd95SBruce Richardson if (rule_db == NULL) { 446*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Dev %d rules can't be NULL\n", 447*99a2dd95SBruce Richardson dev_id); 448*99a2dd95SBruce Richardson return -EINVAL; 449*99a2dd95SBruce Richardson } 450*99a2dd95SBruce Richardson return (*dev->dev_ops->dev_db_import)(dev, rule_db, rule_db_len); 451*99a2dd95SBruce Richardson } 452*99a2dd95SBruce Richardson 453*99a2dd95SBruce Richardson int 454*99a2dd95SBruce Richardson rte_regexdev_rule_db_export(uint8_t dev_id, char *rule_db) 455*99a2dd95SBruce Richardson { 456*99a2dd95SBruce Richardson struct rte_regexdev *dev; 457*99a2dd95SBruce Richardson 458*99a2dd95SBruce Richardson RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 459*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 460*99a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_db_export, 461*99a2dd95SBruce Richardson -ENOTSUP); 462*99a2dd95SBruce Richardson return (*dev->dev_ops->dev_db_export)(dev, rule_db); 463*99a2dd95SBruce Richardson } 464*99a2dd95SBruce Richardson 465*99a2dd95SBruce Richardson int 466*99a2dd95SBruce Richardson rte_regexdev_xstats_names_get(uint8_t dev_id, 467*99a2dd95SBruce Richardson struct rte_regexdev_xstats_map *xstats_map) 468*99a2dd95SBruce Richardson { 469*99a2dd95SBruce Richardson struct rte_regexdev *dev; 470*99a2dd95SBruce Richardson 471*99a2dd95SBruce Richardson RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 472*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 473*99a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_xstats_names_get, 474*99a2dd95SBruce Richardson -ENOTSUP); 475*99a2dd95SBruce Richardson if (xstats_map == NULL) { 476*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Dev %d xstats map can't be NULL\n", 477*99a2dd95SBruce Richardson dev_id); 478*99a2dd95SBruce Richardson return -EINVAL; 479*99a2dd95SBruce Richardson } 480*99a2dd95SBruce Richardson return (*dev->dev_ops->dev_xstats_names_get)(dev, xstats_map); 481*99a2dd95SBruce Richardson } 482*99a2dd95SBruce Richardson 483*99a2dd95SBruce Richardson int 484*99a2dd95SBruce Richardson rte_regexdev_xstats_get(uint8_t dev_id, const uint16_t *ids, 485*99a2dd95SBruce Richardson uint64_t *values, uint16_t n) 486*99a2dd95SBruce Richardson { 487*99a2dd95SBruce Richardson struct rte_regexdev *dev; 488*99a2dd95SBruce Richardson 489*99a2dd95SBruce Richardson RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 490*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 491*99a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_xstats_get, -ENOTSUP); 492*99a2dd95SBruce Richardson if (ids == NULL) { 493*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Dev %d ids can't be NULL\n", dev_id); 494*99a2dd95SBruce Richardson return -EINVAL; 495*99a2dd95SBruce Richardson } 496*99a2dd95SBruce Richardson if (values == NULL) { 497*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Dev %d values can't be NULL\n", dev_id); 498*99a2dd95SBruce Richardson return -EINVAL; 499*99a2dd95SBruce Richardson } 500*99a2dd95SBruce Richardson return (*dev->dev_ops->dev_xstats_get)(dev, ids, values, n); 501*99a2dd95SBruce Richardson } 502*99a2dd95SBruce Richardson 503*99a2dd95SBruce Richardson int 504*99a2dd95SBruce Richardson rte_regexdev_xstats_by_name_get(uint8_t dev_id, const char *name, 505*99a2dd95SBruce Richardson uint16_t *id, uint64_t *value) 506*99a2dd95SBruce Richardson { 507*99a2dd95SBruce Richardson struct rte_regexdev *dev; 508*99a2dd95SBruce Richardson 509*99a2dd95SBruce Richardson RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 510*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 511*99a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_xstats_by_name_get, 512*99a2dd95SBruce Richardson -ENOTSUP); 513*99a2dd95SBruce Richardson if (name == NULL) { 514*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Dev %d name can't be NULL\n", dev_id); 515*99a2dd95SBruce Richardson return -EINVAL; 516*99a2dd95SBruce Richardson } 517*99a2dd95SBruce Richardson if (id == NULL) { 518*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Dev %d id can't be NULL\n", dev_id); 519*99a2dd95SBruce Richardson return -EINVAL; 520*99a2dd95SBruce Richardson } 521*99a2dd95SBruce Richardson if (value == NULL) { 522*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Dev %d value can't be NULL\n", dev_id); 523*99a2dd95SBruce Richardson return -EINVAL; 524*99a2dd95SBruce Richardson } 525*99a2dd95SBruce Richardson return (*dev->dev_ops->dev_xstats_by_name_get)(dev, name, id, value); 526*99a2dd95SBruce Richardson } 527*99a2dd95SBruce Richardson 528*99a2dd95SBruce Richardson int 529*99a2dd95SBruce Richardson rte_regexdev_xstats_reset(uint8_t dev_id, const uint16_t *ids, 530*99a2dd95SBruce Richardson uint16_t nb_ids) 531*99a2dd95SBruce Richardson { 532*99a2dd95SBruce Richardson struct rte_regexdev *dev; 533*99a2dd95SBruce Richardson 534*99a2dd95SBruce Richardson RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 535*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 536*99a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_xstats_reset, -ENOTSUP); 537*99a2dd95SBruce Richardson if (ids == NULL) { 538*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Dev %d ids can't be NULL\n", dev_id); 539*99a2dd95SBruce Richardson return -EINVAL; 540*99a2dd95SBruce Richardson } 541*99a2dd95SBruce Richardson return (*dev->dev_ops->dev_xstats_reset)(dev, ids, nb_ids); 542*99a2dd95SBruce Richardson } 543*99a2dd95SBruce Richardson 544*99a2dd95SBruce Richardson int 545*99a2dd95SBruce Richardson rte_regexdev_selftest(uint8_t dev_id) 546*99a2dd95SBruce Richardson { 547*99a2dd95SBruce Richardson struct rte_regexdev *dev; 548*99a2dd95SBruce Richardson 549*99a2dd95SBruce Richardson RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 550*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 551*99a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_selftest, -ENOTSUP); 552*99a2dd95SBruce Richardson return (*dev->dev_ops->dev_selftest)(dev); 553*99a2dd95SBruce Richardson } 554*99a2dd95SBruce Richardson 555*99a2dd95SBruce Richardson int 556*99a2dd95SBruce Richardson rte_regexdev_dump(uint8_t dev_id, FILE *f) 557*99a2dd95SBruce Richardson { 558*99a2dd95SBruce Richardson struct rte_regexdev *dev; 559*99a2dd95SBruce Richardson 560*99a2dd95SBruce Richardson RTE_REGEXDEV_VALID_DEV_ID_OR_ERR_RET(dev_id, -EINVAL); 561*99a2dd95SBruce Richardson dev = &rte_regex_devices[dev_id]; 562*99a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_dump, -ENOTSUP); 563*99a2dd95SBruce Richardson if (f == NULL) { 564*99a2dd95SBruce Richardson RTE_REGEXDEV_LOG(ERR, "Dev %d file can't be NULL\n", dev_id); 565*99a2dd95SBruce Richardson return -EINVAL; 566*99a2dd95SBruce Richardson } 567*99a2dd95SBruce Richardson return (*dev->dev_ops->dev_dump)(dev, f); 568*99a2dd95SBruce Richardson } 569