From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by dpdk.org (Postfix) with ESMTP id EDBEE1B466 for ; Wed, 11 Jul 2018 09:23:24 +0200 (CEST) Received: by mail-wm0-f65.google.com with SMTP id s12-v6so1361034wmc.1 for ; Wed, 11 Jul 2018 00:23:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mfbxs3WLJSYeG5D0sppAmHzD3jTOo1M2C+Io/1hQgSQ=; b=ynfroQIhMlemc//Puo1dXDt9YQOAd9xNE5EkHAzbstIL7gNKcOTmMQpNMBrdOIdxNs RH5pm/rlpgStoTapkAEO9FH9e7QFWCkMvelw9nKSkvHE1ufkNH2nIqrVh+QtYGjAHNDB B+xWlzyY87VHMyc13TaSsAKWQ7C1xyq6tRLYRdfB7i0DiiwF78jeFiwbVrAEYD/x0H+U yGlhW10lXouIrcIh6LeVwRR//b5aq90q2d/312zTHFkgqIAcv9ep61tCkSpPmpxWc2d+ MIQpZp+ydP9EPe96KaAy6EtXZ7HW3e2aE1VR/jIExnCRhVH7Pguf67DmGumvLKrAsQAD zc4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mfbxs3WLJSYeG5D0sppAmHzD3jTOo1M2C+Io/1hQgSQ=; b=pLlsLj8A7oO9iNja55x2LEWSsRkrvJj2gBp/OOSGmqUk2uCahQqUL5eTQaAB3NOtuF FsbSuJrulPidGVCtx1XarZcx9mv4G3eKm1rcWQX+8R57WG4HJGsMsK+YUUdTZ6+z+pPq 1YX4A6N/aylxE9Dl7JNbPICsW2lY8AG9Ln7Fqzo7v3ftL5u9UDHawIOgvEa2LDhszYSL LYl+C8+BdXwp2clAOAQg0jo98HgCLfjqnlfHe+0P8aK9ZVJmkdff/xJAj3dR8KBnzXnv fWZ5vvbsiQF3ha3hEU9O1eLcaLO87/fWDUElSNR7DTs1BK+X7CWZ1ZANhLWfjzr4imn0 z0Ig== X-Gm-Message-State: APt69E3RwMf34KdwZgeu268e1BXfxL86uWYNCOgVcnkb13Hjt8Oz/Qh3 6IoJVEeGyJye4Y2pvZY033JHrGDjMw== X-Google-Smtp-Source: AAOMgpeOlI3YLUZxn8vLAfl0oaVrzGz0AopIQSgltCiAjWW+ztMBleIIKjmWBM81CU2n27CG2R3GXA== X-Received: by 2002:a1c:b788:: with SMTP id h130-v6mr17892193wmf.27.1531293804488; Wed, 11 Jul 2018 00:23:24 -0700 (PDT) Received: from laranjeiro-vm.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id t10-v6sm31314212wre.95.2018.07.11.00.23.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:23:23 -0700 (PDT) From: Nelio Laranjeiro To: dev@dpdk.org, Yongseok Koh Cc: Adrien Mazarguil Date: Wed, 11 Jul 2018 09:22:41 +0200 Message-Id: <9d8fa5593b1874380094bfae87bd9aefd017b30c.1531293415.git.nelio.laranjeiro@6wind.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v3 08/21] net/mlx5: add flow IPv4 item 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: Wed, 11 Jul 2018 07:23:25 -0000 Signed-off-by: Nelio Laranjeiro --- drivers/net/mlx5/mlx5_flow.c | 90 ++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 659979283..c05b8498d 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -506,6 +506,93 @@ mlx5_flow_item_vlan(const struct rte_flow_item *item, struct rte_flow *flow, return size; } +/** + * Convert the @p item into a Verbs specification after ensuring the NIC + * will understand and process it correctly. + * If the necessary size for the conversion is greater than the @p flow_size, + * nothing is written in @p flow, the validation is still performed. + * + * @param[in] item + * Item specification. + * @param[in, out] flow + * Pointer to flow structure. + * @param[in] flow_size + * Size in bytes of the available space in @p flow, if too small, nothing is + * written. + * @param[out] error + * Pointer to error structure. + * + * @return + * On success the number of bytes consumed/necessary, if the returned value + * is lesser or equal to @p flow_size, the @p item has fully been converted, + * otherwise another call with this returned memory size should be done. + * On error, a negative errno value is returned and rte_errno is set. + */ +static int +mlx5_flow_item_ipv4(const struct rte_flow_item *item, struct rte_flow *flow, + const size_t flow_size, struct rte_flow_error *error) +{ + const struct rte_flow_item_ipv4 *spec = item->spec; + const struct rte_flow_item_ipv4 *mask = item->mask; + const struct rte_flow_item_ipv4 nic_mask = { + .hdr = { + .src_addr = RTE_BE32(0xffffffff), + .dst_addr = RTE_BE32(0xffffffff), + .type_of_service = 0xff, + .next_proto_id = 0xff, + }, + }; + unsigned int size = sizeof(struct ibv_flow_spec_ipv4_ext); + struct ibv_flow_spec_ipv4_ext ipv4 = { + .type = IBV_FLOW_SPEC_IPV4_EXT, + .size = size, + }; + int ret; + + if (flow->layers & MLX5_FLOW_LAYER_OUTER_L3) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ITEM, + item, + "multiple L3 layers not supported"); + else if (flow->layers & MLX5_FLOW_LAYER_OUTER_L4) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ITEM, + item, + "L3 cannot follow an L4 layer."); + if (!mask) + mask = &rte_flow_item_ipv4_mask; + ret = mlx5_flow_item_acceptable + (item, (const uint8_t *)mask, + (const uint8_t *)&nic_mask, + sizeof(struct rte_flow_item_ipv4), error); + if (ret < 0) + return ret; + flow->layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4; + if (size > flow_size) + return size; + if (spec) { + ipv4.val = (struct ibv_flow_ipv4_ext_filter){ + .src_ip = spec->hdr.src_addr, + .dst_ip = spec->hdr.dst_addr, + .proto = spec->hdr.next_proto_id, + .tos = spec->hdr.type_of_service, + }; + ipv4.mask = (struct ibv_flow_ipv4_ext_filter){ + .src_ip = mask->hdr.src_addr, + .dst_ip = mask->hdr.dst_addr, + .proto = mask->hdr.next_proto_id, + .tos = mask->hdr.type_of_service, + }; + /* Remove unwanted bits from values. */ + ipv4.val.src_ip &= ipv4.mask.src_ip; + ipv4.val.dst_ip &= ipv4.mask.dst_ip; + ipv4.val.proto &= ipv4.mask.proto; + ipv4.val.tos &= ipv4.mask.tos; + } + mlx5_flow_spec_verbs_add(flow, &ipv4, size); + return size; +} + /** * Convert the @p pattern into a Verbs specifications after ensuring the NIC * will understand and process it correctly. @@ -551,6 +638,9 @@ mlx5_flow_items(const struct rte_flow_item pattern[], case RTE_FLOW_ITEM_TYPE_VLAN: ret = mlx5_flow_item_vlan(pattern, flow, remain, error); break; + case RTE_FLOW_ITEM_TYPE_IPV4: + ret = mlx5_flow_item_ipv4(pattern, flow, remain, error); + break; default: return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, -- 2.18.0