From patchwork Fri Aug 12 09:54:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 114885 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B0027A0543; Fri, 12 Aug 2022 11:54:59 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F104042C04; Fri, 12 Aug 2022 11:54:50 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mails.dpdk.org (Postfix) with ESMTP id C2A8C410E7 for ; Fri, 12 Aug 2022 11:54:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660298089; x=1691834089; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EvnaB5jnOVA2lUTYDU1Sf47PjzYptVLmCUNFa2tLbCQ=; b=n5sz6BaZSn/3PPovdaJA8m9AjmraxzLjm3iwnammvKXMQZfiEg0N37ol JQfjO2BuGr0Wi9pn7zS0oYvMxBl08tzNAJ1jPr74WRfRJOelc3vvutExv Btyj/YI0mGfGQ9gWT4SALwHyDvoa6zr6YsL8Q70SJQ3mo1ZDyemsmxWRZ yeAiy5VJOUzbXHGihOl8AWcB9liZvh7ZoHnlCPEz2cx9v1tJIYDA0AmDP u9Fwq997n8p+Jrkf7wByxHTUv5LsikSBho2r5XezAwL+EMwWpci+ng/Ap I1z0MC6cHbOnERgvYUVVrQ8Y+BcN9H6Sjjb2ceBpGyi1+m7fkA7WPoMJQ Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10436"; a="289135016" X-IronPort-AV: E=Sophos;i="5.93,231,1654585200"; d="scan'208";a="289135016" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Aug 2022 02:54:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,231,1654585200"; d="scan'208";a="634589086" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by orsmga008.jf.intel.com with ESMTP; 12 Aug 2022 02:54:48 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Cc: Harshad Suresh Narayane Subject: [PATCH 2/4] pipeline: read large structure fields on the control path Date: Fri, 12 Aug 2022 09:54:43 +0000 Message-Id: <20220812095445.1253138-3-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220812095445.1253138-1-cristian.dumitrescu@intel.com> References: <20220812095445.1253138-1-cristian.dumitrescu@intel.com> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Support reading structure fields that are bigger than 64 bits on the control path for the table update operations. Signed-off-by: Cristian Dumitrescu Signed-off-by: Harshad Suresh Narayane --- lib/pipeline/rte_swx_ctl.c | 357 +++++++++++++++++++++++++++++++------ 1 file changed, 298 insertions(+), 59 deletions(-) diff --git a/lib/pipeline/rte_swx_ctl.c b/lib/pipeline/rte_swx_ctl.c index 1b776fc543..bdbcd8f50a 100644 --- a/lib/pipeline/rte_swx_ctl.c +++ b/lib/pipeline/rte_swx_ctl.c @@ -2694,6 +2694,270 @@ mask_to_prefix(uint64_t mask, uint32_t mask_length, uint32_t *prefix_length) return 0; } +static int +large_mask_to_prefix(uint8_t *mask, uint32_t n_mask_bytes, uint32_t *prefix_length) +{ + uint32_t pl, i; + + /* Check input arguments. */ + if (!mask || !n_mask_bytes || !prefix_length) + return -EINVAL; + + /* Count leading bits of one. */ + for (i = 0; i < n_mask_bytes * 8; i++) { + uint32_t byte_id = i / 8; + uint32_t bit_id = i & 7; + + uint32_t byte = mask[byte_id]; + uint32_t bit = byte & (1 << (7 - bit_id)); + + if (!bit) + break; + } + + /* Save the potential prefix length. */ + pl = i; + + /* Check that all remaining bits are zeros. */ + for ( ; i < n_mask_bytes * 8; i++) { + uint32_t byte_id = i / 8; + uint32_t bit_id = i & 7; + + uint32_t byte = mask[byte_id]; + uint32_t bit = byte & (1 << (7 - bit_id)); + + if (bit) + break; + } + + if (i < n_mask_bytes * 8) + return -EINVAL; + + *prefix_length = pl; + return 0; +} + +static int +char_to_hex(char c, uint8_t *val) +{ + if (c >= '0' && c <= '9') { + *val = c - '0'; + return 0; + } + + if (c >= 'A' && c <= 'F') { + *val = c - 'A' + 10; + return 0; + } + + if (c >= 'a' && c <= 'f') { + *val = c - 'a' + 10; + return 0; + } + + return -EINVAL; +} + +static int +hex_string_parse(char *src, uint8_t *dst, uint32_t n_dst_bytes) +{ + uint32_t i; + + /* Check input arguments. */ + if (!src || !src[0] || !dst || !n_dst_bytes) + return -EINVAL; + + /* Skip any leading "0x" or "0X" in the src string. */ + if ((src[0] == '0') && (src[1] == 'x' || src[1] == 'X')) + src += 2; + + /* Convert each group of two hex characters in the src string to one byte in dst array. */ + for (i = 0; i < n_dst_bytes; i++) { + uint8_t a, b; + int status; + + status = char_to_hex(*src, &a); + if (status) + return status; + src++; + + status = char_to_hex(*src, &b); + if (status) + return status; + src++; + + dst[i] = a * 16 + b; + } + + /* Check for the end of the src string. */ + if (*src) + return -EINVAL; + + return 0; +} + +static int +table_entry_match_field_read(struct table *table, + struct rte_swx_table_entry *entry, + uint32_t mf_id, + char *mf_val, + char *mf_mask, + int *lpm, + uint32_t *lpm_prefix_length_max, + uint32_t *lpm_prefix_length) +{ + struct rte_swx_ctl_table_match_field_info *mf = &table->mf[mf_id]; + uint64_t val, mask = UINT64_MAX; + uint32_t offset = (mf->offset - table->mf_first->offset) / 8; + + /* + * Mask. + */ + if (mf_mask) { + /* Parse. */ + mask = strtoull(mf_mask, &mf_mask, 0); + if (mf_mask[0]) + return -EINVAL; + + /* LPM. */ + if (mf->match_type == RTE_SWX_TABLE_MATCH_LPM) { + int status; + + *lpm = 1; + + *lpm_prefix_length_max = mf->n_bits; + + status = mask_to_prefix(mask, mf->n_bits, lpm_prefix_length); + if (status) + return status; + } + + /* Endianness conversion. */ + if (mf->is_header) + mask = field_hton(mask, mf->n_bits); + } + + /* Copy to entry. */ + if (entry->key_mask) + memcpy(&entry->key_mask[offset], (uint8_t *)&mask, mf->n_bits / 8); + + /* + * Value. + */ + /* Parse. */ + val = strtoull(mf_val, &mf_val, 0); + if (mf_val[0]) + return -EINVAL; + + /* Endianness conversion. */ + if (mf->is_header) + val = field_hton(val, mf->n_bits); + + /* Copy to entry. */ + memcpy(&entry->key[offset], (uint8_t *)&val, mf->n_bits / 8); + + return 0; +} + +static int +table_entry_action_argument_read(struct action *action, + struct rte_swx_table_entry *entry, + uint32_t arg_id, + uint32_t arg_offset, + char *arg_val) +{ + struct rte_swx_ctl_action_arg_info *arg = &action->args[arg_id]; + uint64_t val; + + val = strtoull(arg_val, &arg_val, 0); + if (arg_val[0]) + return -EINVAL; + + /* Endianness conversion. */ + if (arg->is_network_byte_order) + val = field_hton(val, arg->n_bits); + + /* Copy to entry. */ + memcpy(&entry->action_data[arg_offset], + (uint8_t *)&val, + arg->n_bits / 8); + + return 0; +} + +static int +table_entry_large_match_field_read(struct table *table, + struct rte_swx_table_entry *entry, + uint32_t mf_id, + char *mf_val, + char *mf_mask, + int *lpm, + uint32_t *lpm_prefix_length_max, + uint32_t *lpm_prefix_length) +{ + struct rte_swx_ctl_table_match_field_info *mf = &table->mf[mf_id]; + uint32_t offset = (mf->offset - table->mf_first->offset) / 8; + int status; + + /* + * Mask. + */ + if (!entry->key_mask) + goto value; + + if (!mf_mask) { + /* Set mask to all-ones. */ + memset(&entry->key_mask[offset], 0xFF, mf->n_bits / 8); + goto value; + } + + /* Parse. */ + status = hex_string_parse(mf_mask, &entry->key_mask[offset], mf->n_bits / 8); + if (status) + return -EINVAL; + + /* LPM. */ + if (mf->match_type == RTE_SWX_TABLE_MATCH_LPM) { + *lpm = 1; + + *lpm_prefix_length_max = mf->n_bits; + + status = large_mask_to_prefix(&entry->key_mask[offset], + mf->n_bits / 8, + lpm_prefix_length); + if (status) + return status; + } + + /* + * Value. + */ +value: + /* Parse. */ + status = hex_string_parse(mf_val, &entry->key[offset], mf->n_bits / 8); + if (status) + return -EINVAL; + + return 0; +} + +static int +table_entry_large_action_argument_read(struct action *action, + struct rte_swx_table_entry *entry, + uint32_t arg_id, + uint32_t arg_offset, + char *arg_val) +{ + struct rte_swx_ctl_action_arg_info *arg = &action->args[arg_id]; + int status; + + status = hex_string_parse(arg_val, &entry->action_data[arg_offset], arg->n_bits / 8); + if (status) + return -EINVAL; + + return 0; +} + static int token_is_comment(const char *token) { @@ -2778,62 +3042,35 @@ rte_swx_ctl_pipeline_table_entry_read(struct rte_swx_ctl_pipeline *ctl, for (i = 0; i < table->info.n_match_fields; i++) { struct rte_swx_ctl_table_match_field_info *mf = &table->mf[i]; char *mf_val = tokens[1 + i], *mf_mask = NULL; - uint64_t val, mask = UINT64_MAX; - uint32_t offset = (mf->offset - table->mf_first->offset) / 8; + int status; - /* - * Mask. - */ mf_mask = strchr(mf_val, '/'); if (mf_mask) { *mf_mask = 0; mf_mask++; - - /* Parse. */ - mask = strtoull(mf_mask, &mf_mask, 0); - if (mf_mask[0]) - goto error; - - /* LPM. */ - if (mf->match_type == RTE_SWX_TABLE_MATCH_LPM) { - int status; - - lpm = 1; - - lpm_prefix_length_max = mf->n_bits; - - status = mask_to_prefix(mask, mf->n_bits, &lpm_prefix_length); - if (status) - goto error; - } - - /* Endianness conversion. */ - if (mf->is_header) - mask = field_hton(mask, mf->n_bits); } - /* Copy to entry. */ - if (entry->key_mask) - memcpy(&entry->key_mask[offset], - (uint8_t *)&mask, - mf->n_bits / 8); - - /* - * Value. - */ - /* Parse. */ - val = strtoull(mf_val, &mf_val, 0); - if (mf_val[0]) + if (mf->n_bits <= 64) + status = table_entry_match_field_read(table, + entry, + i, + mf_val, + mf_mask, + &lpm, + &lpm_prefix_length_max, + &lpm_prefix_length); + else + status = table_entry_large_match_field_read(table, + entry, + i, + mf_val, + mf_mask, + &lpm, + &lpm_prefix_length_max, + &lpm_prefix_length); + if (status) goto error; - /* Endianness conversion. */ - if (mf->is_header) - val = field_hton(val, mf->n_bits); - - /* Copy to entry. */ - memcpy(&entry->key[offset], - (uint8_t *)&val, - mf->n_bits / 8); } tokens += 1 + table->info.n_match_fields; @@ -2889,7 +3126,7 @@ rte_swx_ctl_pipeline_table_entry_read(struct rte_swx_ctl_pipeline *ctl, for (i = 0; i < action->info.n_args; i++) { struct rte_swx_ctl_action_arg_info *arg = &action->args[i]; char *arg_name, *arg_val; - uint64_t val; + int status; arg_name = tokens[2 + i * 2]; arg_val = tokens[2 + i * 2 + 1]; @@ -2897,19 +3134,21 @@ rte_swx_ctl_pipeline_table_entry_read(struct rte_swx_ctl_pipeline *ctl, if (strcmp(arg_name, arg->name)) goto error; - val = strtoull(arg_val, &arg_val, 0); - if (arg_val[0]) + if (arg->n_bits <= 64) + status = table_entry_action_argument_read(action, + entry, + i, + arg_offset, + arg_val); + else + status = table_entry_large_action_argument_read(action, + entry, + i, + arg_offset, + arg_val); + if (status) goto error; - /* Endianness conversion. */ - if (arg->is_network_byte_order) - val = field_hton(val, arg->n_bits); - - /* Copy to entry. */ - memcpy(&entry->action_data[arg_offset], - (uint8_t *)&val, - arg->n_bits / 8); - arg_offset += arg->n_bits / 8; }