netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] net/devlink: Add E-Switch encapsulation control
@ 2017-02-09 16:23 Or Gerlitz
  2017-02-09 16:23 ` [PATCH net-next 1/2] " Or Gerlitz
  2017-02-09 16:23 ` [PATCH net-next 2/2] net/mlx5: E-Switch, Add control for encapsulation Or Gerlitz
  0 siblings, 2 replies; 5+ messages in thread
From: Or Gerlitz @ 2017-02-09 16:23 UTC (permalink / raw)
  To: David S. Miller; +Cc: Jiri Pirko, netdev, Or Gerlitz, Hadar Har-Zion

from:  Roi Dayan <roid@mellanox.com>

Add an e-switch global knob to enable/disable HW support for applying
encapsulation/decapsulation to VF traffic as part of SRIOV e-switch 
offloading which is controlled with devlink. Support that in mlx5.

Dave, the series is rebased over the cleanup series Jiri sent earlier today [1]

Or.

[1] http://marc.info/?l=linux-netdev&m=148665219924363&w=2

Roi Dayan (2):
  net/devlink: Add E-Switch encapsulation control
  net/mlx5: E-Switch, Add control for encapsulation

 drivers/net/ethernet/mellanox/mlx5/core/eswitch.c  |  1 +
 drivers/net/ethernet/mellanox/mlx5/core/eswitch.h  |  3 ++
 .../ethernet/mellanox/mlx5/core/eswitch_offloads.c | 41 ++++++++++++++++++++--
 drivers/net/ethernet/mellanox/mlx5/core/main.c     |  2 ++
 include/net/devlink.h                              |  2 ++
 include/uapi/linux/devlink.h                       |  1 +
 net/core/devlink.c                                 | 22 ++++++++++++
 7 files changed, 70 insertions(+), 2 deletions(-)

-- 
2.5.5

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net-next 1/2] net/devlink: Add E-Switch encapsulation control
  2017-02-09 16:23 [PATCH net-next 0/2] net/devlink: Add E-Switch encapsulation control Or Gerlitz
@ 2017-02-09 16:23 ` Or Gerlitz
  2017-02-09 17:10   ` Jiri Pirko
  2017-02-09 16:23 ` [PATCH net-next 2/2] net/mlx5: E-Switch, Add control for encapsulation Or Gerlitz
  1 sibling, 1 reply; 5+ messages in thread
From: Or Gerlitz @ 2017-02-09 16:23 UTC (permalink / raw)
  To: David S. Miller; +Cc: Jiri Pirko, netdev, Or Gerlitz, Hadar Har-Zion, Roi Dayan

From: Roi Dayan <roid@mellanox.com>

This is an e-switch global knob to enable/disable HW support for applying
encapsulation/decapsulation to VF traffic as part of SRIOV e-switch offloading.

The actual encap/decap is carried out (along with the matching and other actions)
per offloaded e-switch rules, e.g as done when offloading the TC tunnel key action.

The supported mode are enable/disable.

Signed-off-by: Roi Dayan <roid@mellanox.com>
Reviewed-by: Or Gerlitz <ogerlitz@mellanox.com>
---
 include/net/devlink.h        |  2 ++
 include/uapi/linux/devlink.h |  1 +
 net/core/devlink.c           | 22 ++++++++++++++++++++++
 3 files changed, 25 insertions(+)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index d29e5fc..a09bff4 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -94,6 +94,8 @@ struct devlink_ops {
 	int (*eswitch_mode_set)(struct devlink *devlink, u16 mode);
 	int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
 	int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode);
+	int (*eswitch_encap_get)(struct devlink *devlink, bool *p_encap);
+	int (*eswitch_encap_set)(struct devlink *devlink, bool encap);
 };
 
 static inline void *devlink_priv(struct devlink *devlink)
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index 0f1f3a1..c3f05c6 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -147,6 +147,7 @@ enum devlink_attr {
 	DEVLINK_ATTR_SB_OCC_MAX,		/* u32 */
 	DEVLINK_ATTR_ESWITCH_MODE,		/* u16 */
 	DEVLINK_ATTR_ESWITCH_INLINE_MODE,	/* u8 */
+	DEVLINK_ATTR_ESWITCH_ENCAP,		/* u8 */
 
 	/* add new attributes above here, update the policy in devlink.c */
 
diff --git a/net/core/devlink.c b/net/core/devlink.c
index e9c1e6a..9af5372 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -1401,6 +1401,7 @@ static int devlink_nl_eswitch_fill(struct sk_buff *msg, struct devlink *devlink,
 	int err = 0;
 	u16 mode;
 	u8 inline_mode;
+	bool encap;
 
 	hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd);
 	if (!hdr)
@@ -1429,6 +1430,15 @@ static int devlink_nl_eswitch_fill(struct sk_buff *msg, struct devlink *devlink,
 			goto nla_put_failure;
 	}
 
+	if (mode == DEVLINK_ESWITCH_MODE_SWITCHDEV && ops->eswitch_encap_get) {
+		err = ops->eswitch_encap_get(devlink, &encap);
+		if (err)
+			goto nla_put_failure;
+		err = nla_put_u8(msg, DEVLINK_ATTR_ESWITCH_ENCAP, encap);
+		if (err)
+			goto nla_put_failure;
+	}
+
 	genlmsg_end(msg, hdr);
 	return 0;
 
@@ -1470,11 +1480,23 @@ static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb,
 	const struct devlink_ops *ops = devlink->ops;
 	u16 mode;
 	u8 inline_mode;
+	bool encap;
 	int err = 0;
 
 	if (!ops)
 		return -EOPNOTSUPP;
 
+	if (info->attrs[DEVLINK_ATTR_ESWITCH_ENCAP]) {
+		if (!ops->eswitch_encap_set)
+			return -EOPNOTSUPP;
+		if (!info->attrs[DEVLINK_ATTR_ESWITCH_MODE])
+			return -EINVAL;
+		encap = nla_get_u8(info->attrs[DEVLINK_ATTR_ESWITCH_ENCAP]);
+		err = ops->eswitch_encap_set(devlink, encap);
+		if (err)
+			return err;
+	}
+
 	if (info->attrs[DEVLINK_ATTR_ESWITCH_MODE]) {
 		if (!ops->eswitch_mode_set)
 			return -EOPNOTSUPP;
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net-next 2/2] net/mlx5: E-Switch, Add control for encapsulation
  2017-02-09 16:23 [PATCH net-next 0/2] net/devlink: Add E-Switch encapsulation control Or Gerlitz
  2017-02-09 16:23 ` [PATCH net-next 1/2] " Or Gerlitz
@ 2017-02-09 16:23 ` Or Gerlitz
  1 sibling, 0 replies; 5+ messages in thread
From: Or Gerlitz @ 2017-02-09 16:23 UTC (permalink / raw)
  To: David S. Miller; +Cc: Jiri Pirko, netdev, Or Gerlitz, Hadar Har-Zion, Roi Dayan

From: Roi Dayan <roid@mellanox.com>

Implement the devlink e-switch encapsulation control set and get
callbacks. Apply the value set by the user on the switchdev offloads
mode when creating the flow table that is going to hold offloaded rules.

Signed-off-by: Roi Dayan <roid@mellanox.com>
Reviewed-by: Or Gerlitz <ogerlitz@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/eswitch.c  |  1 +
 drivers/net/ethernet/mellanox/mlx5/core/eswitch.h  |  3 ++
 .../ethernet/mellanox/mlx5/core/eswitch_offloads.c | 41 ++++++++++++++++++++--
 drivers/net/ethernet/mellanox/mlx5/core/main.c     |  2 ++
 4 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
index fcd5bc7..06065fd 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
@@ -1803,6 +1803,7 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev)
 	esw->enabled_vports = 0;
 	esw->mode = SRIOV_NONE;
 	esw->offloads.inline_mode = MLX5_INLINE_MODE_NONE;
+	esw->offloads.encap = false;
 
 	dev->priv.eswitch = esw;
 	return 0;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
index 5b78883..6b1ddb9 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
@@ -209,6 +209,7 @@ struct mlx5_esw_offload {
 	struct mlx5_eswitch_rep *vport_reps;
 	DECLARE_HASHTABLE(encap_tbl, 8);
 	u8 inline_mode;
+	bool encap;
 };
 
 struct mlx5_eswitch {
@@ -315,6 +316,8 @@ int mlx5_devlink_eswitch_mode_get(struct devlink *devlink, u16 *mode);
 int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode);
 int mlx5_devlink_eswitch_inline_mode_get(struct devlink *devlink, u8 *mode);
 int mlx5_eswitch_inline_mode_get(struct mlx5_eswitch *esw, int nvfs, u8 *mode);
+int mlx5_devlink_eswitch_encap_set(struct devlink *devlink, bool encap);
+int mlx5_devlink_eswitch_encap_get(struct devlink *devlink, bool *encap);
 void mlx5_eswitch_register_vport_rep(struct mlx5_eswitch *esw,
 				     int vport_index,
 				     struct mlx5_eswitch_rep *rep);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
index 4f5b0d4..5787586 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
@@ -434,8 +434,7 @@ static int esw_create_offloads_fdb_table(struct mlx5_eswitch *esw, int nvports)
 	esw_size = min_t(int, MLX5_CAP_GEN(dev, max_flow_counter) * ESW_OFFLOADS_NUM_GROUPS,
 			 1 << MLX5_CAP_ESW_FLOWTABLE_FDB(dev, log_max_ft_size));
 
-	if (MLX5_CAP_ESW_FLOWTABLE_FDB(dev, encap) &&
-	    MLX5_CAP_ESW_FLOWTABLE_FDB(dev, decap))
+	if (esw->offloads.encap)
 		flags |= MLX5_FLOW_TABLE_TUNNEL_EN;
 
 	fdb = mlx5_create_auto_grouped_flow_table(root_ns, FDB_FAST_PATH,
@@ -978,6 +977,44 @@ int mlx5_eswitch_inline_mode_get(struct mlx5_eswitch *esw, int nvfs, u8 *mode)
 	return 0;
 }
 
+int mlx5_devlink_eswitch_encap_set(struct devlink *devlink, bool encap)
+{
+	struct mlx5_core_dev *dev = devlink_priv(devlink);
+	struct mlx5_eswitch *esw = dev->priv.eswitch;
+
+	if (!MLX5_CAP_GEN(dev, vport_group_manager))
+		return -EOPNOTSUPP;
+
+	if (esw->mode == SRIOV_NONE)
+		return -EOPNOTSUPP;
+
+	if (!encap)
+		goto out;
+
+	if (!MLX5_CAP_ESW_FLOWTABLE_FDB(dev, encap) ||
+	    !MLX5_CAP_ESW_FLOWTABLE_FDB(dev, decap))
+		return -EOPNOTSUPP;
+
+out:
+	esw->offloads.encap = encap;
+	return 0;
+}
+
+int mlx5_devlink_eswitch_encap_get(struct devlink *devlink, bool *encap)
+{
+	struct mlx5_core_dev *dev = devlink_priv(devlink);
+	struct mlx5_eswitch *esw = dev->priv.eswitch;
+
+	if (!MLX5_CAP_GEN(dev, vport_group_manager))
+		return -EOPNOTSUPP;
+
+	if (esw->mode == SRIOV_NONE)
+		return -EOPNOTSUPP;
+
+	*encap = esw->offloads.encap;
+	return 0;
+}
+
 void mlx5_eswitch_register_vport_rep(struct mlx5_eswitch *esw,
 				     int vport_index,
 				     struct mlx5_eswitch_rep *__rep)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c
index c4242a4..9f0a2c31 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
@@ -1280,6 +1280,8 @@ static const struct devlink_ops mlx5_devlink_ops = {
 	.eswitch_mode_get = mlx5_devlink_eswitch_mode_get,
 	.eswitch_inline_mode_set = mlx5_devlink_eswitch_inline_mode_set,
 	.eswitch_inline_mode_get = mlx5_devlink_eswitch_inline_mode_get,
+	.eswitch_encap_set = mlx5_devlink_eswitch_encap_set,
+	.eswitch_encap_get = mlx5_devlink_eswitch_encap_get,
 #endif
 };
 
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next 1/2] net/devlink: Add E-Switch encapsulation control
  2017-02-09 16:23 ` [PATCH net-next 1/2] " Or Gerlitz
@ 2017-02-09 17:10   ` Jiri Pirko
       [not found]     ` <2ccce1b4-4407-fe66-847a-9159579fac27@mellanox.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Jiri Pirko @ 2017-02-09 17:10 UTC (permalink / raw)
  To: Or Gerlitz; +Cc: David S. Miller, Jiri Pirko, netdev, Hadar Har-Zion, Roi Dayan

Thu, Feb 09, 2017 at 05:23:17PM CET, ogerlitz@mellanox.com wrote:
>From: Roi Dayan <roid@mellanox.com>
>
>This is an e-switch global knob to enable/disable HW support for applying
>encapsulation/decapsulation to VF traffic as part of SRIOV e-switch offloading.
>
>The actual encap/decap is carried out (along with the matching and other actions)
>per offloaded e-switch rules, e.g as done when offloading the TC tunnel key action.
>
>The supported mode are enable/disable.
>
>Signed-off-by: Roi Dayan <roid@mellanox.com>
>Reviewed-by: Or Gerlitz <ogerlitz@mellanox.com>
>---

[...]

>@@ -1470,11 +1480,23 @@ static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb,
> 	const struct devlink_ops *ops = devlink->ops;
> 	u16 mode;
> 	u8 inline_mode;
>+	bool encap;
> 	int err = 0;
> 
> 	if (!ops)
> 		return -EOPNOTSUPP;
> 
>+	if (info->attrs[DEVLINK_ATTR_ESWITCH_ENCAP]) {
>+		if (!ops->eswitch_encap_set)
>+			return -EOPNOTSUPP;
>+		if (!info->attrs[DEVLINK_ATTR_ESWITCH_MODE])
>+			return -EINVAL;
>+		encap = nla_get_u8(info->attrs[DEVLINK_ATTR_ESWITCH_ENCAP]);
>+		err = ops->eswitch_encap_set(devlink, encap);
>+		if (err)
>+			return err;
>+	}

Please maintain the same order as the attr enum and getters and put this
behind the inline_mode. Thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next 1/2] net/devlink: Add E-Switch encapsulation control
       [not found]     ` <2ccce1b4-4407-fe66-847a-9159579fac27@mellanox.com>
@ 2017-02-09 17:36       ` Jiri Pirko
  0 siblings, 0 replies; 5+ messages in thread
From: Jiri Pirko @ 2017-02-09 17:36 UTC (permalink / raw)
  To: Or Gerlitz; +Cc: David S. Miller, Jiri Pirko, netdev, Hadar Har-Zion, Roi Dayan

Thu, Feb 09, 2017 at 06:20:14PM CET, ogerlitz@mellanox.com wrote:
>On 2/9/2017 7:10 PM, Jiri Pirko wrote:
>> > @@ -1470,11 +1480,23 @@ static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb,
>> > 	const struct devlink_ops *ops = devlink->ops;
>> > 	u16 mode;
>> > 	u8 inline_mode;
>> > +	bool encap;
>> > 	int err = 0;
>> > 
>> > 	if (!ops)
>> > 		return -EOPNOTSUPP;
>> > 
>> > +	if (info->attrs[DEVLINK_ATTR_ESWITCH_ENCAP]) {
>> > +		if (!ops->eswitch_encap_set)
>> > +			return -EOPNOTSUPP;
>> > +		if (!info->attrs[DEVLINK_ATTR_ESWITCH_MODE])

Why you need to check this? Should be possible to set the attrs
separatelly.


>> > +			return -EINVAL;
>> > +		encap = nla_get_u8(info->attrs[DEVLINK_ATTR_ESWITCH_ENCAP]);
>> > +		err = ops->eswitch_encap_set(devlink, encap);
>> > +		if (err)
>> > +			return err;
>> > +	}
>> Please maintain the same order as the attr enum and getters and put this
>> behind the inline_mode.
>
>The HW driver might want to use the attributes only when they are called to
>change the eswitch mode.

I don't get it. Should be a separate attribute - separate op


>
>I see that the patch is not too consistent with setting the inline mode which
>is done after setting the eswitch mode, mmm, guess we need to fix that.
>
>Or.
>
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-02-09 17:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-09 16:23 [PATCH net-next 0/2] net/devlink: Add E-Switch encapsulation control Or Gerlitz
2017-02-09 16:23 ` [PATCH net-next 1/2] " Or Gerlitz
2017-02-09 17:10   ` Jiri Pirko
     [not found]     ` <2ccce1b4-4407-fe66-847a-9159579fac27@mellanox.com>
2017-02-09 17:36       ` Jiri Pirko
2017-02-09 16:23 ` [PATCH net-next 2/2] net/mlx5: E-Switch, Add control for encapsulation Or Gerlitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).