From efad24a84d35458e2c672b94027e54923a42fd25 Mon Sep 17 00:00:00 2001 From: Xinyao Cai Date: Wed, 12 Apr 2023 18:35:23 +0800 Subject: dpdk: code preparation for bumping to DPDK 22.11 This patch prepares code for bumping DPDK version to 22.11, but the DPDK version of this patch keeps at 22.07 for compatibility. the "no-dsa" parameter in DPDK configuration is removed, the "blacklist" parameter can be used to block the related DSA devices. Type: feature Signed-off-by: Xinyao Cai Change-Id: I08787c6584bba66383fc0a784963f33171196910 --- src/plugins/dpdk/cryptodev/cryptodev.c | 86 +++++++++++++++++++--- src/plugins/dpdk/cryptodev/cryptodev.h | 15 +++- .../dpdk/cryptodev/cryptodev_op_data_path.c | 13 +++- .../dpdk/cryptodev/cryptodev_raw_data_path.c | 9 ++- src/plugins/dpdk/device/common.c | 13 ++-- src/plugins/dpdk/device/dpdk.h | 9 +++ src/plugins/dpdk/device/dpdk_priv.h | 1 + src/plugins/dpdk/device/format.c | 17 +++++ src/plugins/dpdk/device/init.c | 18 ++--- 9 files changed, 147 insertions(+), 34 deletions(-) (limited to 'src/plugins/dpdk') diff --git a/src/plugins/dpdk/cryptodev/cryptodev.c b/src/plugins/dpdk/cryptodev/cryptodev.c index adb437e3465..84a307d02ce 100644 --- a/src/plugins/dpdk/cryptodev/cryptodev.c +++ b/src/plugins/dpdk/cryptodev/cryptodev.c @@ -141,7 +141,7 @@ prepare_linked_xform (struct rte_crypto_sym_xform *xforms, } static_always_inline void -cryptodev_session_del (struct rte_cryptodev_sym_session *sess) +cryptodev_session_del (cryptodev_session_t *sess) { u32 n_devs, i; @@ -151,9 +151,14 @@ cryptodev_session_del (struct rte_cryptodev_sym_session *sess) n_devs = rte_cryptodev_count (); for (i = 0; i < n_devs; i++) +#if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) + if (rte_cryptodev_sym_session_free (i, sess) == 0) + break; +#else rte_cryptodev_sym_session_clear (i, sess); rte_cryptodev_sym_session_free (sess); +#endif } static int @@ -337,8 +342,13 @@ allocate_session_pools (u32 numa_node, clib_error_t *error = NULL; name = format (0, "vcrypto_sess_pool_%u_%04x%c", numa_node, len, 0); +#if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) + sess_pools_elt->sess_pool = rte_cryptodev_sym_session_pool_create ( + (char *) name, CRYPTODEV_NB_SESSION, cmt->sess_sz, 0, 0, numa_node); +#else sess_pools_elt->sess_pool = rte_cryptodev_sym_session_pool_create ( (char *) name, CRYPTODEV_NB_SESSION, 0, 0, 0, numa_node); +#endif if (!sess_pools_elt->sess_pool) { @@ -347,6 +357,7 @@ allocate_session_pools (u32 numa_node, } vec_free (name); +#if RTE_VERSION < RTE_VERSION_NUM(22, 11, 0, 0) name = format (0, "crypto_sess_pool_%u_%04x%c", numa_node, len, 0); sess_pools_elt->sess_priv_pool = rte_mempool_create ( (char *) name, CRYPTODEV_NB_SESSION * (cmt->drivers_cnt), cmt->sess_sz, 0, @@ -358,6 +369,7 @@ allocate_session_pools (u32 numa_node, goto clear_mempools; } vec_free (name); +#endif clear_mempools: if (error) @@ -365,8 +377,10 @@ clear_mempools: vec_free (name); if (sess_pools_elt->sess_pool) rte_mempool_free (sess_pools_elt->sess_pool); +#if RTE_VERSION < RTE_VERSION_NUM(22, 11, 0, 0) if (sess_pools_elt->sess_priv_pool) rte_mempool_free (sess_pools_elt->sess_priv_pool); +#endif return error; } return 0; @@ -380,13 +394,16 @@ cryptodev_session_create (vlib_main_t *vm, vnet_crypto_key_index_t idx, cryptodev_numa_data_t *numa_data; cryptodev_inst_t *dev_inst; vnet_crypto_key_t *key = vnet_crypto_get_key (idx); - struct rte_mempool *sess_pool, *sess_priv_pool; + struct rte_mempool *sess_pool; cryptodev_session_pool_t *sess_pools_elt; cryptodev_key_t *ckey = vec_elt_at_index (cmt->keys, idx); struct rte_crypto_sym_xform xforms_enc[2] = { { 0 } }; struct rte_crypto_sym_xform xforms_dec[2] = { { 0 } }; - struct rte_cryptodev_sym_session *sessions[CRYPTODEV_N_OP_TYPES] = { 0 }; + cryptodev_session_t *sessions[CRYPTODEV_N_OP_TYPES] = { 0 }; +#if RTE_VERSION < RTE_VERSION_NUM(22, 11, 0, 0) + struct rte_mempool *sess_priv_pool; struct rte_cryptodev_info dev_info; +#endif u32 numa_node = vm->numa_node; clib_error_t *error; int ret = 0; @@ -427,6 +444,7 @@ cryptodev_session_create (vlib_main_t *vm, vnet_crypto_key_index_t idx, } sess_pool = sess_pools_elt->sess_pool; +#if RTE_VERSION < RTE_VERSION_NUM(22, 11, 0, 0) sess_priv_pool = sess_pools_elt->sess_priv_pool; sessions[CRYPTODEV_OP_TYPE_ENCRYPT] = @@ -434,6 +452,7 @@ cryptodev_session_create (vlib_main_t *vm, vnet_crypto_key_index_t idx, sessions[CRYPTODEV_OP_TYPE_DECRYPT] = rte_cryptodev_sym_session_create (sess_pool); +#endif if (key->type == VNET_CRYPTO_KEY_TYPE_LINK) ret = prepare_linked_xform (xforms_enc, CRYPTODEV_OP_TYPE_ENCRYPT, key); @@ -451,6 +470,25 @@ cryptodev_session_create (vlib_main_t *vm, vnet_crypto_key_index_t idx, else prepare_aead_xform (xforms_dec, CRYPTODEV_OP_TYPE_DECRYPT, key, aad_len); +#if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) + dev_inst = vec_elt_at_index (cmt->cryptodev_inst, 0); + u32 dev_id = dev_inst->dev_id; + sessions[CRYPTODEV_OP_TYPE_ENCRYPT] = + rte_cryptodev_sym_session_create (dev_id, xforms_enc, sess_pool); + sessions[CRYPTODEV_OP_TYPE_DECRYPT] = + rte_cryptodev_sym_session_create (dev_id, xforms_dec, sess_pool); + if (!sessions[CRYPTODEV_OP_TYPE_ENCRYPT] || + !sessions[CRYPTODEV_OP_TYPE_DECRYPT]) + { + ret = -1; + goto clear_key; + } + + rte_cryptodev_sym_session_opaque_data_set ( + sessions[CRYPTODEV_OP_TYPE_ENCRYPT], aad_len); + rte_cryptodev_sym_session_opaque_data_set ( + sessions[CRYPTODEV_OP_TYPE_DECRYPT], aad_len); +#else vec_foreach (dev_inst, cmt->cryptodev_inst) { u32 dev_id = dev_inst->dev_id; @@ -475,6 +513,7 @@ cryptodev_session_create (vlib_main_t *vm, vnet_crypto_key_index_t idx, sessions[CRYPTODEV_OP_TYPE_ENCRYPT]->opaque_data = aad_len; sessions[CRYPTODEV_OP_TYPE_DECRYPT]->opaque_data = aad_len; +#endif CLIB_MEMORY_STORE_BARRIER (); ckey->keys[numa_node][CRYPTODEV_OP_TYPE_ENCRYPT] = @@ -724,6 +763,15 @@ cryptodev_configure (vlib_main_t *vm, u32 cryptodev_id) rte_cryptodev_info_get (cryptodev_id, &info); + /* Starting from DPDK 22.11, VPP does not allow heterogeneous crypto devices + anymore. Only devices that have the same driver type as the first + initialized device can be initialized. + */ +#if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) + if (cmt->drivers_cnt == 1 && cmt->driver_id != info.driver_id) + return -1; +#endif + if (!(info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) return -1; @@ -737,7 +785,9 @@ cryptodev_configure (vlib_main_t *vm, u32 cryptodev_id) struct rte_cryptodev_qp_conf qp_cfg; qp_cfg.mp_session = 0; +#if RTE_VERSION < RTE_VERSION_NUM(22, 11, 0, 0) qp_cfg.mp_session_private = 0; +#endif qp_cfg.nb_descriptors = CRYPTODEV_NB_CRYPTO_OPS; ret = rte_cryptodev_queue_pair_setup (cryptodev_id, i, &qp_cfg, @@ -756,16 +806,30 @@ cryptodev_configure (vlib_main_t *vm, u32 cryptodev_id) /* start the device */ rte_cryptodev_start (cryptodev_id); +#if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) + if (cmt->drivers_cnt == 0) + { + cmt->drivers_cnt = 1; + cmt->driver_id = info.driver_id; + cmt->sess_sz = rte_cryptodev_sym_get_private_session_size (cryptodev_id); + } +#endif + for (i = 0; i < info.max_nb_queue_pairs; i++) { cryptodev_inst_t *cdev_inst; +#if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) + const char *dev_name = rte_dev_name (info.device); +#else + const char *dev_name = info.device->name; +#endif vec_add2(cmt->cryptodev_inst, cdev_inst, 1); - cdev_inst->desc = vec_new (char, strlen (info.device->name) + 10); + cdev_inst->desc = vec_new (char, strlen (dev_name) + 10); cdev_inst->dev_id = cryptodev_id; cdev_inst->q_id = i; - snprintf (cdev_inst->desc, strlen (info.device->name) + 9, - "%s_q%u", info.device->name, i); + snprintf (cdev_inst->desc, strlen (dev_name) + 9, "%s_q%u", + info.device->name, i); } return 0; @@ -1097,6 +1161,7 @@ cryptodev_probe (vlib_main_t *vm, u32 n_workers) return 0; } +#if RTE_VERSION < RTE_VERSION_NUM(22, 11, 0, 0) static void is_drv_unique (u32 driver_id, u32 **unique_drivers) { @@ -1115,6 +1180,7 @@ is_drv_unique (u32 driver_id, u32 **unique_drivers) if (!found) vec_add1 (*unique_drivers, driver_id); } +#endif clib_error_t * dpdk_cryptodev_init (vlib_main_t * vm) @@ -1123,15 +1189,12 @@ dpdk_cryptodev_init (vlib_main_t * vm) vlib_thread_main_t *tm = vlib_get_thread_main (); cryptodev_engine_thread_t *cet; cryptodev_numa_data_t *numa_data; - cryptodev_inst_t *dev_inst; - struct rte_cryptodev_info dev_info; u32 node; u8 nodes = 0; u32 skip_master = vlib_num_workers () > 0; u32 n_workers = tm->n_vlib_mains - skip_master; u32 eidx; u32 i; - u32 *unique_drivers = 0; clib_error_t *error; cmt->iova_mode = rte_eal_iova_mode (); @@ -1152,6 +1215,10 @@ dpdk_cryptodev_init (vlib_main_t * vm) if (cryptodev_probe (vm, n_workers) < 0) return 0; +#if RTE_VERSION < RTE_VERSION_NUM(22, 11, 0, 0) + struct rte_cryptodev_info dev_info; + cryptodev_inst_t *dev_inst; + u32 *unique_drivers = 0; vec_foreach (dev_inst, cmt->cryptodev_inst) { u32 dev_id = dev_inst->dev_id; @@ -1166,6 +1233,7 @@ dpdk_cryptodev_init (vlib_main_t * vm) cmt->drivers_cnt = vec_len (unique_drivers); vec_free (unique_drivers); +#endif clib_bitmap_vec_validate (cmt->active_cdev_inst_mask, tm->n_vlib_mains); clib_spinlock_init (&cmt->tlock); diff --git a/src/plugins/dpdk/cryptodev/cryptodev.h b/src/plugins/dpdk/cryptodev/cryptodev.h index 53a0462ea43..cf68e1da083 100644 --- a/src/plugins/dpdk/cryptodev/cryptodev.h +++ b/src/plugins/dpdk/cryptodev/cryptodev.h @@ -81,10 +81,16 @@ typedef enum CRYPTODEV_N_OP_TYPES, } cryptodev_op_type_t; +#if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) +typedef void cryptodev_session_t; +#else +typedef struct rte_cryptodev_sym_session cryptodev_session_t; +#endif + /* Cryptodev session data, one data per direction per numa */ typedef struct { - struct rte_cryptodev_sym_session ***keys; + cryptodev_session_t ***keys; } cryptodev_key_t; /* Replicate DPDK rte_cryptodev_sym_capability structure with key size ranges @@ -125,7 +131,9 @@ typedef struct typedef struct { struct rte_mempool *sess_pool; +#if RTE_VERSION < RTE_VERSION_NUM(22, 11, 0, 0) struct rte_mempool *sess_priv_pool; +#endif } cryptodev_session_pool_t; typedef struct @@ -163,7 +171,7 @@ typedef struct u16 aad_index; u8 *aad_buf; u64 aad_phy_addr; - struct rte_cryptodev_sym_session *reset_sess; + cryptodev_session_t *reset_sess; }; }; u16 cryptodev_id; @@ -184,6 +192,9 @@ typedef struct u32 sess_sz; u32 drivers_cnt; u8 is_raw_api; +#if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) + u8 driver_id; +#endif } cryptodev_main_t; extern cryptodev_main_t cryptodev_main; diff --git a/src/plugins/dpdk/cryptodev/cryptodev_op_data_path.c b/src/plugins/dpdk/cryptodev/cryptodev_op_data_path.c index 55be79c5dc5..66c0c168234 100644 --- a/src/plugins/dpdk/cryptodev/cryptodev_op_data_path.c +++ b/src/plugins/dpdk/cryptodev/cryptodev_op_data_path.c @@ -127,7 +127,7 @@ cryptodev_frame_linked_algs_enqueue (vlib_main_t *vm, clib_pmalloc_main_t *pm = vm->physmem_main.pmalloc_main; cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index; vnet_crypto_async_frame_elt_t *fe; - struct rte_cryptodev_sym_session *sess = 0; + cryptodev_session_t *sess = 0; cryptodev_op_t **cop; u32 *bi; u32 n_enqueue, n_elts; @@ -246,7 +246,7 @@ cryptodev_frame_aead_enqueue (vlib_main_t *vm, clib_pmalloc_main_t *pm = vm->physmem_main.pmalloc_main; cryptodev_engine_thread_t *cet = cmt->per_thread_data + vm->thread_index; vnet_crypto_async_frame_elt_t *fe; - struct rte_cryptodev_sym_session *sess = 0; + cryptodev_session_t *sess = 0; cryptodev_op_t **cop; u32 *bi; u32 n_enqueue = 0, n_elts; @@ -306,8 +306,13 @@ cryptodev_frame_aead_enqueue (vlib_main_t *vm, } } else if (PREDICT_FALSE ( - key->keys[vm->numa_node][op_type]->opaque_data != - aad_len)) +#if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) + rte_cryptodev_sym_session_opaque_data_get ( + key->keys[vm->numa_node][op_type]) != (u64) aad_len +#else + key->keys[vm->numa_node][op_type]->opaque_data != aad_len +#endif + )) { cryptodev_sess_handler (vm, VNET_CRYPTO_KEY_OP_DEL, fe->key_index, aad_len); diff --git a/src/plugins/dpdk/cryptodev/cryptodev_raw_data_path.c b/src/plugins/dpdk/cryptodev/cryptodev_raw_data_path.c index c096e34fba4..a8265b82c82 100644 --- a/src/plugins/dpdk/cryptodev/cryptodev_raw_data_path.c +++ b/src/plugins/dpdk/cryptodev/cryptodev_raw_data_path.c @@ -292,8 +292,13 @@ cryptodev_raw_aead_enqueue (vlib_main_t *vm, vnet_crypto_async_frame_t *frame, } if (PREDICT_FALSE ( - (u8) key->keys[vm->numa_node][op_type]->opaque_data != - aad_len)) +#if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) + rte_cryptodev_sym_session_opaque_data_get ( + key->keys[vm->numa_node][op_type]) != (u64) aad_len +#else + (u8) key->keys[vm->numa_node][op_type]->opaque_data != aad_len +#endif + )) { cryptodev_sess_handler (vm, VNET_CRYPTO_KEY_OP_DEL, fe->key_index, aad_len); diff --git a/src/plugins/dpdk/device/common.c b/src/plugins/dpdk/device/common.c index b8c6eddd34b..e4a79e88286 100644 --- a/src/plugins/dpdk/device/common.c +++ b/src/plugins/dpdk/device/common.c @@ -134,11 +134,6 @@ dpdk_device_setup (dpdk_device_t * xd) dpdk_log_debug ("[%u] Configured TX offloads: %U", xd->port_id, format_dpdk_tx_offload_caps, txo); - /* Enable flow director when flows exist */ - if (xd->supported_flow_actions && - (xd->flags & DPDK_DEVICE_FLAG_RX_FLOW_OFFLOAD) != 0) - conf.fdir_conf.mode = RTE_FDIR_MODE_PERFECT; - /* finalize configuration */ conf.rxmode.offloads = rxo; conf.txmode.offloads = txo; @@ -487,7 +482,11 @@ dpdk_get_pci_device (const struct rte_eth_dev_info *info) const struct rte_bus *bus; bus = rte_bus_find_by_device (info->device); +#if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) + if (bus && !strcmp (rte_bus_name (bus), "pci")) +#else if (bus && !strcmp (bus->name, "pci")) +#endif return RTE_DEV_TO_PCI (info->device); else return NULL; @@ -500,7 +499,11 @@ dpdk_get_vmbus_device (const struct rte_eth_dev_info *info) const struct rte_bus *bus; bus = rte_bus_find_by_device (info->device); +#if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) + if (bus && !strcmp (rte_bus_name (bus), "vmbus")) +#else if (bus && !strcmp (bus->name, "vmbus")) +#endif return container_of (info->device, struct rte_vmbus_device, device); else return NULL; diff --git a/src/plugins/dpdk/device/dpdk.h b/src/plugins/dpdk/device/dpdk.h index 7238ecf5515..3f02f20237f 100644 --- a/src/plugins/dpdk/device/dpdk.h +++ b/src/plugins/dpdk/device/dpdk.h @@ -28,6 +28,15 @@ #include #include #include +#if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) +#include +#include +#include + +#include +#include +#include +#endif #include diff --git a/src/plugins/dpdk/device/dpdk_priv.h b/src/plugins/dpdk/device/dpdk_priv.h index 013ab41637e..d1a44fd28a1 100644 --- a/src/plugins/dpdk/device/dpdk_priv.h +++ b/src/plugins/dpdk/device/dpdk_priv.h @@ -36,6 +36,7 @@ _(proc-type) \ _(file-prefix) \ _(vdev) \ _(log-level) \ +_(block) \ _(iova-mode) \ _(base-virtaddr) /* clang-format on */ diff --git a/src/plugins/dpdk/device/format.c b/src/plugins/dpdk/device/format.c index ab14231d5f7..d3234d16f00 100644 --- a/src/plugins/dpdk/device/format.c +++ b/src/plugins/dpdk/device/format.c @@ -384,6 +384,16 @@ format_dpdk_rte_device (u8 *s, va_list *args) if (!d) return format (s, "not available"); +#if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) + s = + format (s, "name: %s, numa: %d", rte_dev_name (d), rte_dev_numa_node (d)); + + if (rte_dev_driver (d)) + s = format (s, ", driver: %s", rte_driver_name (rte_dev_driver (d))); + + if (rte_dev_bus (d)) + s = format (s, ", bus: %s", rte_bus_name (rte_dev_bus (d))); +#else s = format (s, "name: %s, numa: %d", d->name, d->numa_node); if (d->driver) @@ -391,6 +401,7 @@ format_dpdk_rte_device (u8 *s, va_list *args) if (d->bus) s = format (s, ", bus: %s", d->bus->name); +#endif return s; } @@ -421,9 +432,15 @@ format_dpdk_device (u8 * s, va_list * args) format_white_space, indent + 2, format_dpdk_link_status, xd); s = format (s, "%Uflags: %U\n", format_white_space, indent + 2, format_dpdk_device_flags, xd); +#if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) + if (rte_dev_devargs (di.device) && rte_dev_devargs (di.device)->args) + s = format (s, "%UDevargs: %s\n", format_white_space, indent + 2, + rte_dev_devargs (di.device)->args); +#else if (di.device->devargs && di.device->devargs->args) s = format (s, "%UDevargs: %s\n", format_white_space, indent + 2, di.device->devargs->args); +#endif s = format (s, "%Urx: queues %d (max %d), desc %d " "(min %d max %d align %d)\n", diff --git a/src/plugins/dpdk/device/init.c b/src/plugins/dpdk/device/init.c index 847affea243..3eb1da55919 100644 --- a/src/plugins/dpdk/device/init.c +++ b/src/plugins/dpdk/device/init.c @@ -205,8 +205,12 @@ dpdk_find_startup_config (struct rte_eth_dev_info *di) if ((vmbus_dev = dpdk_get_vmbus_device (di))) { unformat_input_t input_vmbus; - unformat_init_string (&input_vmbus, di->device->name, - strlen (di->device->name)); +#if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) + const char *dev_name = rte_dev_name (di->device); +#else + const char *dev_name = di->device->name; +#endif + unformat_init_string (&input_vmbus, dev_name, strlen (dev_name)); if (unformat (&input_vmbus, "%U", unformat_vlib_vmbus_addr, &vmbus_addr)) p = mhash_get (&dm->conf->device_config_index_by_vmbus_addr, &vmbus_addr); @@ -997,7 +1001,6 @@ dpdk_config (vlib_main_t * vm, unformat_input_t * input) int eal_no_hugetlb = 0; u8 no_pci = 0; u8 no_vmbus = 0; - u8 no_dsa = 0; u8 file_prefix = 0; u8 *socket_mem = 0; u8 *huge_dir_path = 0; @@ -1108,8 +1111,6 @@ dpdk_config (vlib_main_t * vm, unformat_input_t * input) tmp = format (0, "--no-pci%c", 0); vec_add1 (conf->eal_init_args, tmp); } - else if (unformat (input, "no-dsa")) - no_dsa = 1; else if (unformat (input, "blacklist %U", unformat_vlib_vmbus_addr, &vmbus_addr)) { @@ -1319,13 +1320,6 @@ dpdk_config (vlib_main_t * vm, unformat_input_t * input) vm = vlib_get_main (); - if (no_dsa) - { - struct rte_bus *bus; - bus = rte_bus_find_by_name ("dsa"); - if (bus) - rte_bus_unregister (bus); - } /* make copy of args as rte_eal_init tends to mess up with arg array */ for (i = 1; i < vec_len (conf->eal_init_args); i++) conf->eal_init_args_str = format (conf->eal_init_args_str, "%s ", -- cgit 1.2.3-korg