From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wj0-f177.google.com (mail-wj0-f177.google.com [209.85.210.177]) by dpdk.org (Postfix) with ESMTP id 305CCFA52 for ; Mon, 19 Dec 2016 18:50:04 +0100 (CET) Received: by mail-wj0-f177.google.com with SMTP id v7so156357560wjy.2 for ; Mon, 19 Dec 2016 09:50:04 -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=P9+hjXFrz981xjo5H5dqxZtfoZs7lCKIOR5RrPfOpfc=; b=WuGtrdAkPghgn3xi4IYFGWfX+SeH8bVF1XcQUjIpqcLmu64vkfK6WWeOBWkBE5mTFa p68a8RdGZfMNYfMikHugcebkusGDpymhFkBLU8HgPuuIhl8V+0jC+17Qs9sIZln18FCC fDO4dxyEkw6dwjrDEqGzt1vgYL0VytTNjNoGtYnbkyjdyF7m+7PKSfYqJ9sVkGsioPeY PyexkZpJQwRV7wxFJz9fcfwYEZ0j8TTdt1Q+i1BEjkyq3q6YiT7E6u02Jr/vu512u7XO /7863g9H8XKiTTkeyVQw4AvUVUMhtdtS6yzItbakBMxqz9p4bk6R5W4hKVO8I6n1ZYxY n9og== 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=P9+hjXFrz981xjo5H5dqxZtfoZs7lCKIOR5RrPfOpfc=; b=YCJ1EFCg6brPHd9CRuBcNELwd10hlFxf9f1DDzLgC+Cl98YgtsMFIi/G+NfOLalND9 byap82G8JR3GuLMh/tfKeaf1wBGQqTGgZtXApj3SFTWbbU0UDBJ9p5KCJdJx4+lN5zRw biz4tqTvsUyd+g6q52ipvySzUFPSOLfPVMXi71CS36FwA3Mi4zLev1FLyqDGFFivst+l 7cFSJ2KpwspAqy2qaD5aIHCk86PiDkvp58qhXwufKqN1Js4dmuRuWBwJQBZIvXBY8Y2n yRRnDWF7GEjJGoHwaUry+xb87r8LFTaP+yVSSS0gQuM7kQTHVCbLi7bAaoy5fXpf3/lj Y9Rg== X-Gm-Message-State: AIkVDXII4y53RnEVg3lLnsgtZq0wp5yc+JSQW4Tt6TdmQ1EV3Fq8OaDJLFKZf2fbFpTQUBrE X-Received: by 10.194.14.196 with SMTP id r4mr18098248wjc.54.1482169803722; Mon, 19 Dec 2016 09:50:03 -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 vr9sm21656053wjc.35.2016.12.19.09.50.02 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 19 Dec 2016 09:50:02 -0800 (PST) From: Adrien Mazarguil To: dev@dpdk.org Date: Mon, 19 Dec 2016 18:49:06 +0100 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v3 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: Mon, 19 Dec 2016 17:50:04 -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 07f895e..69887fc 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