From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3817FA0543; Fri, 12 Aug 2022 11:55:06 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1CE4B42C15; Fri, 12 Aug 2022 11:54:53 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mails.dpdk.org (Postfix) with ESMTP id DABC7410E7 for ; Fri, 12 Aug 2022 11:54:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660298091; x=1691834091; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cE8rODZCkPv1vlpC/wQGWIJa6ugz/lPWmiZo79mP12c=; b=eUubNfNsIbeXmUIQvFFTj0B/DM3lAsLPwdb+r/Ajeux5ucxn3NNeFNFj u6adJYjtIk3K9ssO10Blmr22Xqu0YsZOfScXet6OUI8oTCE5+rszaADBj 9RQKybIGMw2csxRxZBj4DZicHjvQs+dHkgkYX9fPYQJrLNB3EulBkpkQr SGNPj24agfem525hlv0eSfu0C66QnEA8il1188pRXgAbzXTv0lxi3SKUq 2u3TZhoKi8OYjyb8YJRtP/mft5e7D2bGc0jYmgwYS5S6E7KsH/dbgEc1v 2rQX/UlnmwtCI4QqFyCCKACYZTEiGd4w6kVELUhguuju951Y29ClCEYMx A==; X-IronPort-AV: E=McAfee;i="6400,9594,10436"; a="289135020" X-IronPort-AV: E=Sophos;i="5.93,231,1654585200"; d="scan'208";a="289135020" 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:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,231,1654585200"; d="scan'208";a="634589094" 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:49 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Cc: Harshad Suresh Narayane Subject: [PATCH 3/4] pipeline: support large default action arguments Date: Fri, 12 Aug 2022 09:54:44 +0000 Message-Id: <20220812095445.1253138-4-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 Content-Transfer-Encoding: 8bit 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 structure fields bigger than 64 bits as default action arguments. Signed-off-by: Cristian Dumitrescu Signed-off-by: Harshad Suresh Narayane --- lib/pipeline/rte_swx_pipeline.c | 89 +++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 11 deletions(-) diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c index 15c840b352..48b9df0fef 100644 --- a/lib/pipeline/rte_swx_pipeline.c +++ b/lib/pipeline/rte_swx_pipeline.c @@ -7576,6 +7576,65 @@ action_arg_src_mov_count(struct action *a, return n_users; } +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; +} + #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN #define field_ntoh(val, n_bits) (ntoh64((val) << (64 - n_bits))) #define field_hton(val, n_bits) (hton64((val) << (64 - n_bits))) @@ -7634,25 +7693,33 @@ action_args_parse(struct action *a, const char *args, uint8_t *data) struct field *f = &a->st->fields[i]; char *arg_name = tokens[i * 2]; char *arg_val = tokens[i * 2 + 1]; - uint64_t val; if (strcmp(arg_name, f->name)) { status = -EINVAL; goto error; } - val = strtoull(arg_val, &arg_val, 0); - if (arg_val[0]) { - status = -EINVAL; - goto error; - } + if (f->n_bits <= 64) { + uint64_t val; - /* Endianness conversion. */ - if (a->args_endianness[i]) - val = field_hton(val, f->n_bits); + val = strtoull(arg_val, &arg_val, 0); + if (arg_val[0]) { + status = -EINVAL; + goto error; + } + + /* Endianness conversion. */ + if (a->args_endianness[i]) + val = field_hton(val, f->n_bits); + + /* Copy to entry. */ + memcpy(&data[offset], (uint8_t *)&val, f->n_bits / 8); + } else { + status = hex_string_parse(arg_val, &data[offset], f->n_bits / 8); + if (status) + goto error; + } - /* Copy to entry. */ - memcpy(&data[offset], (uint8_t *)&val, f->n_bits / 8); offset += f->n_bits / 8; } -- 2.34.1