From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by dpdk.org (Postfix) with ESMTP id E29A2FBEA for ; Tue, 20 Dec 2016 19:43:28 +0100 (CET) Received: by mail-wm0-f42.google.com with SMTP id t79so138534066wmt.0 for ; Tue, 20 Dec 2016 10:43:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=8SIOjLvMXFLw7IcLx9Ycj059yI8l9oPiJMnltwNP0IQ=; b=Y+1Wfp8O0qqGls+wGxnJEkrLrLHgL8+5xSw7MEWBkr1EQW/nWb4l+dOOaI7Gnn7S94 V6IRJfAMRtDsr93/LTv8kemZZsXG8L6jVvGlheKmx0bxh9DAwhFndVZ/t1tnln4U/rEJ 3xDkb9Ju1zcWPUWNiKn17g3OsXMP715g8T2Frf0quiAv/YJzGS5bSbmqCvDSHtt6qsYd xswDy/sajAGnB7w5+MVQ6VJY4P8M0izgE3oLyhx+lRheEV8tCwx9n4p1QJ8KkLec7Gnq H+1zkduQz057xyI0Xh6l+BVZm5xZonbn884TK0j/aMSD4JGuGtegTT/CKxxOfQQ/9fI+ CJiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=8SIOjLvMXFLw7IcLx9Ycj059yI8l9oPiJMnltwNP0IQ=; b=mA0eHOi0jvQ+XbfwaxQcp2mmoFFF16K11sUSuEwXDeLN3d2Ec+qalChnosSMkgRPzv 946CkgNMpUScPHTFRHr0D8xjPjP4+/s5Wfqqxsh76B6C+MFufzhZI9YuB/Xdq/1Zsi+9 Yww5oeLouwztTFjTl1xm64QYHVN2/teMJFgFFrnLOLBbRvpQs8HSMJvwBCs71WKb/ygX HD+m3mpTvQSahdrNkd5Wro2qnYL39ZxRnkhbg8hxq7plX6uerBYqq4E44eJLmWFIG9ul gmZ/8288BX9VVkxFOLu4JHiuy4Lo98TpRxug/16cinmPSPJghfmTWrfSOe+wGb0EHeVK jAuQ== X-Gm-Message-State: AIkVDXItQ8lyg6IgZz//ZDYHj7kYU7jJ+HuHaKt3nOeRMDdR2IFtipFWoUVqKkl1l1qv+c07 X-Received: by 10.28.154.140 with SMTP id c134mr1195570wme.25.1482259408412; Tue, 20 Dec 2016 10:43:28 -0800 (PST) Received: from 6wind.com (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by smtp.gmail.com with ESMTPSA id e6sm26815031wjw.33.2016.12.20.10.43.27 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 20 Dec 2016 10:43:27 -0800 (PST) From: Adrien Mazarguil To: dev@dpdk.org Date: Tue, 20 Dec 2016 19:42:33 +0100 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v4 16/25] app/testpmd: add rte_flow bit-field support X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Dec 2016 18:43:29 -0000 Several rte_flow structures expose bit-fields that cannot be set in a generic fashion at byte level. Add bit-mask support to handle them. Signed-off-by: Adrien Mazarguil Acked-by: Olga Shern --- app/test-pmd/cmdline_flow.c | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index 9a6f37d..72b5297 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -136,6 +136,7 @@ struct arg { uint32_t sign:1; /**< Value is signed. */ uint32_t offset; /**< Relative offset from ctx->object. */ uint32_t size; /**< Field size. */ + const uint8_t *mask; /**< Bit-mask to use instead of offset/size. */ }; /** Parser token definition. */ @@ -195,6 +196,13 @@ struct token { .size = sizeof(((s *)0)->f), \ }) +/** Static initializer for ARGS() to target a bit-field. */ +#define ARGS_ENTRY_BF(s, f, b) \ + (&(const struct arg){ \ + .size = sizeof(s), \ + .mask = (const void *)&(const s){ .f = (1 << (b)) - 1 }, \ + }) + /** Static initializer for ARGS() to target a pointer. */ #define ARGS_ENTRY_PTR(s, f) \ (&(const struct arg){ \ @@ -623,6 +631,34 @@ push_args(struct context *ctx, const struct arg *arg) return 0; } +/** Spread value into buffer according to bit-mask. */ +static size_t +arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg) +{ + uint32_t i; + size_t len = 0; + + /* Endian conversion is not supported on bit-fields. */ + if (!arg->mask || arg->hton) + return 0; + for (i = 0; i != arg->size; ++i) { + unsigned int shift = 0; + uint8_t *buf = (uint8_t *)dst + i; + + for (shift = 0; arg->mask[i] >> shift; ++shift) { + if (!(arg->mask[i] & (1 << shift))) + continue; + ++len; + if (!dst) + continue; + *buf &= ~(1 << shift); + *buf |= (val & 1) << shift; + val >>= 1; + } + } + return len; +} + /** * Parse a prefix length and generate a bit-mask. * @@ -649,6 +685,23 @@ parse_prefix(struct context *ctx, const struct token *token, u = strtoumax(str, &end, 0); if (errno || (size_t)(end - str) != len) goto error; + if (arg->mask) { + uintmax_t v = 0; + + extra = arg_entry_bf_fill(NULL, 0, arg); + if (u > extra) + goto error; + if (!ctx->object) + return len; + extra -= u; + while (u--) + (v <<= 1, v |= 1); + v <<= extra; + if (!arg_entry_bf_fill(ctx->object, v, arg) || + !arg_entry_bf_fill(ctx->objmask, -1, arg)) + goto error; + return len; + } bytes = u / 8; extra = u % 8; size = arg->size; @@ -1072,6 +1125,12 @@ parse_int(struct context *ctx, const struct token *token, goto error; if (!ctx->object) return len; + if (arg->mask) { + if (!arg_entry_bf_fill(ctx->object, u, arg) || + !arg_entry_bf_fill(ctx->objmask, -1, arg)) + goto error; + return len; + } buf = (uint8_t *)ctx->object + arg->offset; size = arg->size; objmask: -- 2.1.4