From 40b9e7f65fe1ef9f65f80c59e11b0af3d362a80d Mon Sep 17 00:00:00 2001 From: Bing Zhao Date: Tue, 24 Mar 2020 15:34:00 +0000 Subject: [PATCH] net/mlx5: check device status before creating flow By default, flows are categorized into two types of a mlx5 device. 1. The PMD driver will create some default flows to enable the traffic and give some default behaviors on the packets. And this is transparent to the upper layer application. 2. Other flows will be created in the application based on its needs. When in the old cached mode for application flows, it is allowed to created the flow before the device is started. And when starting the device, all the flows will be applied to the hardware and take effect. The cached flows will be also applied in the same time. In non-cached mode, all the flows will never be cached when stopping a device. So it makes no sense to insert any flow into the device before it is started. Default flows owned by PMD driver are not affected in this case. Signed-off-by: Bing Zhao Acked-by: Matan Azrad --- drivers/net/mlx5/mlx5_flow.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index f2d3730d6b..6438a14487 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -4328,7 +4328,11 @@ flow_list_create(struct rte_eth_dev *dev, struct mlx5_flows *list, if (ret) goto error; } - if (dev->data->dev_started) { + /* + * If the flow is external (from application) OR device is started, then + * the flow will be applied immediately. + */ + if (external || dev->data->dev_started) { ret = flow_drv_apply(dev, flow, error); if (ret < 0) goto error; @@ -4420,6 +4424,17 @@ mlx5_flow_create(struct rte_eth_dev *dev, { struct mlx5_priv *priv = dev->data->dev_private; + /* + * If the device is not started yet, it is not allowed to created a + * flow from application. PMD default flows and traffic control flows + * are not affected. + */ + if (unlikely(!dev->data->dev_started)) { + rte_errno = ENODEV; + DRV_LOG(DEBUG, "port %u is not started when " + "inserting a flow", dev->data->port_id); + return NULL; + } return flow_list_create(dev, &priv->flows, attr, items, actions, true, error); } -- 2.20.1