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 <bingz@mellanox.com>
Acked-by: Matan Azrad <matan@mellanox.com>
This commit is contained in:
Bing Zhao 2020-03-24 15:34:00 +00:00 committed by Ferruh Yigit
parent e7bfa3596a
commit 40b9e7f65f

View File

@ -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);
}