From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by dpdk.org (Postfix) with ESMTP id 108B744C7 for ; Mon, 28 May 2018 13:21:49 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id r15-v6so3675510wmc.1 for ; Mon, 28 May 2018 04:21:49 -0700 (PDT) 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:in-reply-to :references; bh=TSBsccd1foM9mNkdvQexgsgIUNbcqRCAY1G31PgslSk=; b=srlbS+IPOeu6kCaG/KUShuf7MvKzp34tIh2IV0nypyPW9sILwrUNSHTZ9fWXxZLYfa NiwpEF6EyZ/MlFapQeLDmJCoxv4Cw+lsB5H5Q0OejjUmTEK2wu55auXa6eAXYkBXbcM0 5VrvgRRuRQdd0GGD4oy67g2bA8PkwPncjBUCAIeNPW2RQ3rwUFdrmKwsbsFe7ez2nOO1 inZw6uJSrM3u5py8gS5/bwssCeXol4Bi/Km7MuWR4kt9Za2NOMzbMNLKmCSVhLL66xeJ ZNtrI2JQiXFhAmYCYyjRMp3uEBrH7ZvQtVjlyh+GlQZz5KmU9JupL9dCz1lK1/jy6xhk m0MA== 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:in-reply-to:references; bh=TSBsccd1foM9mNkdvQexgsgIUNbcqRCAY1G31PgslSk=; b=Kthw48CyPoaKgf6LTodJp0ktZl/uFex3h0uVM7JNcHBVK/Uve4d5ICGRh+/L/qzF3j oT5oS2Uqxo9IFt0IMvwcaksTW/EJqluWqqQf/kD4fx0RCbf0OOMxG0edZkbQMilP8Plh M9r+vrhjGratE2D75PGA1h9zuu1ejkftZp170eQvOCuzS5hiVbOsR936UgKeXKCfBnPw UkPY2otHjcy0miR8yTBreXNPtbeIt0FviiKS7leoaf6uqovbVYb7GzdR/8vKmcBVFTMO icYFl9eXsskl5wn78cu8dIeMO8hJQI9EMeC13WpxH+pYO9kexN8DIRqBZKPD/nK4Ud0t N1Gw== X-Gm-Message-State: ALKqPwc6A/MvScVEWjL8f9pbIYHZxEuj3QFre+IjO3hmzVXllGWkEp6n LeSwhptw4pMw2m5tOwgqEW9ZrU8eew== X-Google-Smtp-Source: ADUXVKJs2N0H9uqO3XX16zZJDO2+uvSWGBxDGEaWMLhhhQhiwyFWSe8jpDG34iX5gb8i9v0B38W4qg== X-Received: by 2002:a1c:800e:: with SMTP id b14-v6mr8062018wmd.83.1527506508522; Mon, 28 May 2018 04:21:48 -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 q81-v6sm20755444wmd.14.2018.05.28.04.21.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 May 2018 04:21:47 -0700 (PDT) From: Nelio Laranjeiro To: dev@dpdk.org, Adrien Mazarguil , Yongseok Koh Date: Mon, 28 May 2018 13:21:44 +0200 Message-Id: X-Mailer: git-send-email 2.17.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [DPDK 18.08 v1 11/12] net/mlx5: add mark/flag flow action 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, 28 May 2018 11:21:49 -0000 Signed-off-by: Nelio Laranjeiro --- drivers/net/mlx5/mlx5_flow.c | 156 +++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index ce1b4e94b..4ef0a3fee 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -55,6 +55,10 @@ extern const struct eth_dev_ops mlx5_dev_ops_isolate; #define MLX5_FLOW_FATE_DROP (1u << 0) #define MLX5_FLOW_FATE_QUEUE (1u << 1) +/* Modify a packet. */ +#define MLX5_FLOW_MOD_FLAG (1u << 0) +#define MLX5_FLOW_MOD_MARK (1u << 1) + /* Verbs flow priority per layer level. */ #define MLX5_FLOW_PRIO_L4 0 #define MLX5_FLOW_PRIO_L3 1 @@ -69,6 +73,8 @@ struct mlx5_flow_verbs { unsigned int size; /**< Size of the attribute. */ uint32_t layers; /**< Bit-fields of present layers see MLX5_FLOW_ITEMS_*. */ + uint32_t modifier; + /**< Bit-fields of present modifier see MLX5_FLOW_MOD_*. */ uint32_t fate; /**< Bit-fields of present fate see MLX5_FLOW_FATE_*. */ struct { @@ -893,6 +899,107 @@ mlx5_flow_action_queue(struct rte_eth_dev *dev, return 0; } +/** + * Validate action flag provided by the user. + * + * @param flow + * Pointer to the rte_flow structure. + * @param error + * Pointer to error structure. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +mlx5_flow_action_flag(struct rte_flow *flow) +{ + unsigned int size = sizeof(struct ibv_flow_spec_action_tag); + struct ibv_flow_spec_action_tag tag = { + .type = IBV_FLOW_SPEC_ACTION_TAG, + .size = size, + .tag_id = mlx5_flow_mark_set(MLX5_FLOW_MARK_DEFAULT), + }; + + if (flow->verbs.modifier & MLX5_FLOW_MOD_MARK) + return 0; + mlx5_flow_spec_verbs_add(flow, &tag, size); + flow->verbs.modifier |= MLX5_FLOW_MOD_FLAG; + return 0; +} + +/** + * Update verbs specification to modify the flag to mark. + * + * @param flow + * Pointer to the rte_flow structure. + * @param mark_id + * Mark identifier to replace the flag. + */ +static void +mlx5_flow_action_mark_fate_queue(struct rte_flow *flow, uint32_t mark_id) +{ + int i; + + /* Update Verbs specification. */ + for (i = 0; i != flow->verbs.attr->num_of_specs; ++i) { + struct ibv_spec_header *hdr = + (struct ibv_spec_header *)flow->verbs.attr; + + if (hdr->type == IBV_FLOW_SPEC_ACTION_TAG) { + struct ibv_flow_spec_action_tag *t = + (struct ibv_flow_spec_action_tag *)hdr; + + t->tag_id = mlx5_flow_mark_set(mark_id); + } + } +} + +/** + * Validate action mark provided by the user. + * + * @param actions + * Pointer to flow actions array. + * @param flow + * Pointer to the rte_flow structure. + * @param error + * Pointer to error structure. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +mlx5_flow_action_mark(const struct rte_flow_action *actions, + struct rte_flow *flow, + struct rte_flow_error *error) +{ + const struct rte_flow_action_mark *mark = actions->conf; + unsigned int size = sizeof(struct ibv_flow_spec_action_tag); + struct ibv_flow_spec_action_tag tag = { + .type = IBV_FLOW_SPEC_ACTION_TAG, + .size = size, + }; + + if (!mark) + return rte_flow_error_set(error, EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + actions, + "configuration cannot be null"); + if (mark->id >= MLX5_FLOW_MARK_MAX) + return rte_flow_error_set(error, EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION_CONF, + &mark->id, + "mark must be between 0 and" + " 16777199"); + if (flow->verbs.modifier & MLX5_FLOW_MOD_FLAG) { + mlx5_flow_action_mark_fate_queue(flow, mark->id); + } else { + tag.tag_id = mlx5_flow_mark_set(mark->id); + mlx5_flow_spec_verbs_add(flow, &tag, size); + } + flow->verbs.modifier |= MLX5_FLOW_MOD_MARK; + return 0; +} + /** * Validate actions provided by the user. * @@ -917,6 +1024,18 @@ mlx5_flow_actions(struct rte_eth_dev *dev, switch (actions->type) { case RTE_FLOW_ACTION_TYPE_VOID: break; + case RTE_FLOW_ACTION_TYPE_FLAG: + if (flow->verbs.modifier & MLX5_FLOW_MOD_MARK) + return rte_flow_error_set + (error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION, + actions, + "Flag after Mark is not supported"); + ret = mlx5_flow_action_flag(flow); + break; + case RTE_FLOW_ACTION_TYPE_MARK: + ret = mlx5_flow_action_mark(actions, flow, error); + break; case RTE_FLOW_ACTION_TYPE_DROP: ret = mlx5_flow_action_drop(actions, flow, error); break; @@ -997,6 +1116,42 @@ mlx5_flow_merge(struct rte_eth_dev *dev, struct rte_flow *flow, return size; } +/** + * Enable/Disable Mark flag in Rx queues. + * + * @param dev + * Pointer to Ethernet device. + * @param flow + * Pointer to flow structure. + * @param enable + * 0 to disabled, positive value otherwise. + */ +static void +mlx5_flow_rxq_mark(struct rte_eth_dev *dev, struct rte_flow *flow, int enable) +{ + struct priv *priv = dev->data->dev_private; + struct mlx5_rxq_data *rxq_data; + const uint32_t mask = MLX5_FLOW_MOD_FLAG | MLX5_FLOW_MOD_MARK; + struct rte_flow *tmp; + uint32_t mark = !!enable; + + if (!(flow->verbs.modifier & mask)) + return; + rxq_data = (*priv->rxqs)[flow->queue]; + /** + * Mark/Flag bit can only be disabled when there is no other + * flow applied using the same queue has a MARK/FLOW action + * configured. + */ + TAILQ_FOREACH(tmp, &priv->flows, next) { + if (tmp == flow) + continue; + if (tmp->queue == flow->queue) + mark |= !!(tmp->verbs.modifier & mask); + } + rxq_data->mark = mark; +} + /** * Validate a flow supported by the NIC. * @@ -1187,6 +1342,7 @@ mlx5_flow_list_create(struct rte_eth_dev *dev, ret = mlx5_flow_fate_apply(dev, flow, error); if (ret < 0) goto error; + mlx5_flow_rxq_mark(dev, flow, 1); TAILQ_INSERT_TAIL(list, flow, next); return flow; error: -- 2.17.0