From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by dpdk.org (Postfix) with ESMTP id 3F3DDF938 for ; Fri, 16 Dec 2016 17:26:09 +0100 (CET) Received: by mail-wm0-f48.google.com with SMTP id f82so40865356wmf.1 for ; Fri, 16 Dec 2016 08:26:09 -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=hL0wCss5N794uft/VZAufFLIEwtArKN6+L6fj7x4PDk=; b=fYiVsfQLzbCNYbjaYfBhBAh//slqFij5oOBl7Anxx5JLa2fKsudYfP/QGQ1zMWZhPk 5eN4spOLfPbQRGFNUv0s8K9jNdatz0rbFvOHKutD43nrKII9akZXF/pO/kukMdb9mc2q zA5vL0eWUnGlv4QieTDyQJOzMGP5CxX/UP44K/G003vHIeY+oMIRC/2ruqLKcYQQW8J1 iOzwdz2ks1zADN1C9Pvfcwwhje7iIJx6bPBuwWMqeeKNRXbiBnG812Q0bCgpWlprGmP0 uvLORPiJjuv/HfrJgBqTYO97nUXNajXh6mH0Y78X9E4RIgMVEoTOvY7JtK1gfyZql0Y/ /naQ== 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=hL0wCss5N794uft/VZAufFLIEwtArKN6+L6fj7x4PDk=; b=d9g8cq8/BN8BVLfhj57dZqTPzMiHwE9ZhVxoMGWS+FtV9Wx7ieJfv+pZL1jNkrZbNb rZCfkTpO1iFWHTa95UjMXHD2mEnxCwY3X70CTZpsS8qsyuHm2/6W1y9Z27c6aCWqvQLz dIfJ7CLjnSrz2ky6GE0wAFC7k3EtvU+kezAd1OMmCh8qzZMKDe6u9UG8TgMsVTiJwmR+ g5251AimBYZcykBetemcexYpxwJMrdVg0bg61nzO//P80BJd8UGlyneg7Evjx7iiZW0P NvdqBPxk11ZYREsrmxWCGY0CY4UDgLApzZYVm16TOu0Kz2F8DTGl1wUvSpyvW4PfT9In 814Q== X-Gm-Message-State: AIkVDXJYfXeHLwGOJ+PnR6NMUfuQdNePdsrC3JqJOV1Pjdpg2SxlOlVrn7pfxz9h8+OOkOM+ X-Received: by 10.194.23.67 with SMTP id k3mr3564014wjf.103.1481905568771; Fri, 16 Dec 2016 08:26:08 -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 f76sm4023649wmd.15.2016.12.16.08.26.07 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 16 Dec 2016 08:26:08 -0800 (PST) From: Adrien Mazarguil To: dev@dpdk.org Date: Fri, 16 Dec 2016 17:25:13 +0100 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2 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: Fri, 16 Dec 2016 16:26:09 -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 --- 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