DPDK patches and discussions
 help / color / mirror / Atom feed
From: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
To: dev@dpdk.org
Cc: Harshad Suresh Narayane <harshad.suresh.narayane@intel.com>
Subject: [PATCH 3/4] pipeline: support large default action arguments
Date: Fri, 12 Aug 2022 09:54:44 +0000	[thread overview]
Message-ID: <20220812095445.1253138-4-cristian.dumitrescu@intel.com> (raw)
In-Reply-To: <20220812095445.1253138-1-cristian.dumitrescu@intel.com>

Support structure fields bigger than 64 bits as default action
arguments.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Signed-off-by: Harshad Suresh Narayane <harshad.suresh.narayane@intel.com>
---
 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


  parent reply	other threads:[~2022-08-12  9:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-12  9:54 [PATCH 0/4] pipeline: support large structure fields Cristian Dumitrescu
2022-08-12  9:54 ` [PATCH 1/4] pipeline: remove the 64-bit limit for " Cristian Dumitrescu
2022-08-12  9:54 ` [PATCH 2/4] pipeline: read large structure fields on the control path Cristian Dumitrescu
2022-08-12  9:54 ` Cristian Dumitrescu [this message]
2022-08-12  9:54 ` [PATCH 4/4] pipeline: add instruction support for moving large structure fields Cristian Dumitrescu
2022-09-23 11:56 ` [PATCH 0/4] pipeline: support " Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220812095445.1253138-4-cristian.dumitrescu@intel.com \
    --to=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    --cc=harshad.suresh.narayane@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).