Skip to content

Commit

Permalink
netdev-dpdk: Expose flow creation/destruction calls
Browse files Browse the repository at this point in the history
Before offloading code was added to the netdev-dpdk.c file (MARK and
RSS actions) the only DPDK RTE calls in use were rte_flow_create() and
rte_flow_destroy(). In preparation for splitting the offloading code
from the netdev-dpdk.c file to a separate file, it is required
to embed these RTE calls into a global netdev-dpdk-* API so that
they can be called from the new file. An example for this requirement
can be seen in the handling of dev->mutex, which should be encapsulated
inside netdev-dpdk class (netdev-dpdk.c file), and should be unknown
to the outside callers. This commit embeds the rte_flow_create() call
inside the netdev_dpdk_flow_create() API and the rte_flow_destroy()
call inside the netdev_dpdk_rte_flow_destroy() API.

Reviewed-by: Asaf Penso <asafp@mellanox.com>
Signed-off-by: Roni Bar Yanai <roniba@mellanox.com>
Signed-off-by: Ophir Munk <ophirmu@mellanox.com>
Co-authored-by: Ophir Munk <ophirmu@mellanox.com>
Acked-by: Ilya Maximets <i.maximets@samsung.com>
Signed-off-by: Ian Stokes <ian.stokes@intel.com>
  • Loading branch information
2 people authored and istokes committed Mar 19, 2019
1 parent 2e97b84 commit 6775bdf
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
47 changes: 32 additions & 15 deletions lib/netdev-dpdk.c
Expand Up @@ -785,7 +785,6 @@ dpdk_mp_get(struct netdev_dpdk *dev, int mtu, bool per_port_mp)
}
}


ovs_mutex_unlock(&dpdk_mp_mutex);

return dmp;
Expand Down Expand Up @@ -3684,7 +3683,6 @@ netdev_dpdk_class_init(void)
return 0;
}


/* Client Rings */

static int
Expand Down Expand Up @@ -4203,6 +4201,35 @@ netdev_dpdk_vhost_client_reconfigure(struct netdev *netdev)
return err;
}

int
netdev_dpdk_rte_flow_destroy(struct netdev *netdev,
struct rte_flow *rte_flow,
struct rte_flow_error *error)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
int ret;

ovs_mutex_lock(&dev->mutex);
ret = rte_flow_destroy(dev->port_id, rte_flow, error);
ovs_mutex_unlock(&dev->mutex);
return ret;
}

struct rte_flow *
netdev_dpdk_rte_flow_create(struct netdev *netdev,
const struct rte_flow_attr *attr,
const struct rte_flow_item *items,
const struct rte_flow_action *actions,
struct rte_flow_error *error)
{
struct rte_flow *flow;
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);

ovs_mutex_lock(&dev->mutex);
flow = rte_flow_create(dev->port_id, attr, items, actions, error);
ovs_mutex_unlock(&dev->mutex);
return flow;
}

/* Find rte_flow with @ufid */
static struct rte_flow *
Expand Down Expand Up @@ -4554,7 +4581,6 @@ netdev_dpdk_add_rte_flow_offload(struct netdev *netdev,
size_t actions_len OVS_UNUSED,
const ovs_u128 *ufid,
struct offload_info *info) {
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
const struct rte_flow_attr flow_attr = {
.group = 0,
.priority = 0,
Expand Down Expand Up @@ -4726,15 +4752,11 @@ netdev_dpdk_add_rte_flow_offload(struct netdev *netdev,
mark.id = info->flow_mark;
add_flow_action(&actions, RTE_FLOW_ACTION_TYPE_MARK, &mark);

ovs_mutex_lock(&dev->mutex);

rss = add_flow_rss_action(&actions, netdev);
add_flow_action(&actions, RTE_FLOW_ACTION_TYPE_END, NULL);

flow = rte_flow_create(dev->port_id, &flow_attr, patterns.items,
actions.actions, &error);

ovs_mutex_unlock(&dev->mutex);
flow = netdev_dpdk_rte_flow_create(netdev, &flow_attr,patterns.items,
actions.actions, &error);

free(rss);
if (!flow) {
Expand Down Expand Up @@ -4828,13 +4850,9 @@ static int
netdev_dpdk_destroy_rte_flow(struct netdev *netdev,
const ovs_u128 *ufid,
struct rte_flow *rte_flow) {
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
struct rte_flow_error error;
int ret;
int ret = netdev_dpdk_rte_flow_destroy(netdev, rte_flow, &error);

ovs_mutex_lock(&dev->mutex);

ret = rte_flow_destroy(dev->port_id, rte_flow, &error);
if (ret == 0) {
ufid_to_rte_flow_disassociate(ufid);
VLOG_DBG("%s: removed rte flow %p associated with ufid " UUID_FMT "\n",
Expand All @@ -4845,7 +4863,6 @@ netdev_dpdk_destroy_rte_flow(struct netdev *netdev,
netdev_get_name(netdev), error.type, error.message);
}

ovs_mutex_unlock(&dev->mutex);
return ret;
}

Expand Down
17 changes: 17 additions & 0 deletions lib/netdev-dpdk.h
Expand Up @@ -22,11 +22,28 @@
#include "openvswitch/compiler.h"

struct dp_packet;
struct netdev;

#ifdef DPDK_NETDEV

struct rte_flow;
struct rte_flow_error;
struct rte_flow_attr;
struct rte_flow_item;
struct rte_flow_action;

void netdev_dpdk_register(void);
void free_dpdk_buf(struct dp_packet *);
int
netdev_dpdk_rte_flow_destroy(struct netdev *netdev,
struct rte_flow *rte_flow,
struct rte_flow_error *error);
struct rte_flow *
netdev_dpdk_rte_flow_create(struct netdev *netdev,
const struct rte_flow_attr *attr,
const struct rte_flow_item *items,
const struct rte_flow_action *actions,
struct rte_flow_error *error);

#else

Expand Down

0 comments on commit 6775bdf

Please sign in to comment.