Ethernet Bridge development
 help / color / mirror / Atom feed
From: Vladimir Oltean <vladimir.oltean@nxp.com>
To: Horatiu Vultur <horatiu.vultur@microchip.com>
Cc: "ivecera@redhat.com" <ivecera@redhat.com>,
	"andrew@lunn.ch" <andrew@lunn.ch>,
	"alexandre.belloni@bootlin.com" <alexandre.belloni@bootlin.com>,
	"f.fainelli@gmail.com" <f.fainelli@gmail.com>,
	"jiri@resnulli.us" <jiri@resnulli.us>,
	"rasmus.villemoes@prevas.dk" <rasmus.villemoes@prevas.dk>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"bridge@lists.linux-foundation.org"
	<bridge@lists.linux-foundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"vivien.didelot@gmail.com" <vivien.didelot@gmail.com>,
	"UNGLinuxDriver@microchip.com" <UNGLinuxDriver@microchip.com>,
	Claudiu Manoil <claudiu.manoil@nxp.com>,
	"nikolay@nvidia.com" <nikolay@nvidia.com>,
	"roopa@nvidia.com" <roopa@nvidia.com>,
	"kuba@kernel.org" <kuba@kernel.org>,
	"davem@davemloft.net" <davem@davemloft.net>
Subject: Re: [Bridge] [PATCH net-next v4 7/8] net: dsa: add MRP support
Date: Wed, 17 Feb 2021 11:23:42 +0000	[thread overview]
Message-ID: <20210217112340.xxdfvwp3mw52isse@skbuf> (raw)
In-Reply-To: <20210216214205.32385-8-horatiu.vultur@microchip.com>

On Tue, Feb 16, 2021 at 10:42:04PM +0100, Horatiu Vultur wrote:
> Add support for offloading MRP in HW. Currently implement the switchdev
> calls 'SWITCHDEV_OBJ_ID_MRP', 'SWITCHDEV_OBJ_ID_RING_ROLE_MRP',
> to allow to create MRP instances and to set the role of these instances.
> 
> Add DSA_NOTIFIER_MRP_ADD/DEL and DSA_NOTIFIER_MRP_ADD/DEL_RING_ROLE
> which calls to .port_mrp_add/del and .port_mrp_add/del_ring_role in the
> DSA driver for the switch.
> 
> Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
> ---
>  include/net/dsa.h  |  12 ++++++
>  net/dsa/dsa_priv.h |  26 +++++++++++
>  net/dsa/port.c     |  48 +++++++++++++++++++++
>  net/dsa/slave.c    |  22 ++++++++++
>  net/dsa/switch.c   | 105 +++++++++++++++++++++++++++++++++++++++++++++
>  5 files changed, 213 insertions(+)
> 
> diff --git a/include/net/dsa.h b/include/net/dsa.h
> index 68f8159564a3..83a933e563fe 100644
> --- a/include/net/dsa.h
> +++ b/include/net/dsa.h
> @@ -792,6 +792,18 @@ struct dsa_switch_ops {
>  				 struct net_device *hsr);
>  	int	(*port_hsr_leave)(struct dsa_switch *ds, int port,
>  				  struct net_device *hsr);
> +
> +	/*
> +	 * MRP integration
> +	 */
> +	int	(*port_mrp_add)(struct dsa_switch *ds, int port,
> +				const struct switchdev_obj_mrp *mrp);
> +	int	(*port_mrp_del)(struct dsa_switch *ds, int port,
> +				const struct switchdev_obj_mrp *mrp);
> +	int	(*port_mrp_add_ring_role)(struct dsa_switch *ds, int port,
> +					  const struct switchdev_obj_ring_role_mrp *mrp);
> +	int	(*port_mrp_del_ring_role)(struct dsa_switch *ds, int port,
> +					  const struct switchdev_obj_ring_role_mrp *mrp);
>  };
>  
>  #define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes)		\
> diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
> index e9d1e76c42ba..2eeaa42f2e08 100644
> --- a/net/dsa/dsa_priv.h
> +++ b/net/dsa/dsa_priv.h
> @@ -31,6 +31,10 @@ enum {
>  	DSA_NOTIFIER_VLAN_DEL,
>  	DSA_NOTIFIER_MTU,
>  	DSA_NOTIFIER_TAG_PROTO,
> +	DSA_NOTIFIER_MRP_ADD,
> +	DSA_NOTIFIER_MRP_DEL,
> +	DSA_NOTIFIER_MRP_ADD_RING_ROLE,
> +	DSA_NOTIFIER_MRP_DEL_RING_ROLE,
>  };
>  
>  /* DSA_NOTIFIER_AGEING_TIME */
> @@ -91,6 +95,20 @@ struct dsa_notifier_tag_proto_info {
>  	const struct dsa_device_ops *tag_ops;
>  };
>  
> +/* DSA_NOTIFIER_MRP_* */
> +struct dsa_notifier_mrp_info {
> +	const struct switchdev_obj_mrp *mrp;
> +	int sw_index;
> +	int port;
> +};
> +
> +/* DSA_NOTIFIER_MRP_* */
> +struct dsa_notifier_mrp_ring_role_info {
> +	const struct switchdev_obj_ring_role_mrp *mrp;
> +	int sw_index;
> +	int port;
> +};
> +
>  struct dsa_switchdev_event_work {
>  	struct dsa_switch *ds;
>  	int port;
> @@ -198,6 +216,14 @@ int dsa_port_vlan_add(struct dsa_port *dp,
>  		      struct netlink_ext_ack *extack);
>  int dsa_port_vlan_del(struct dsa_port *dp,
>  		      const struct switchdev_obj_port_vlan *vlan);
> +int dsa_port_mrp_add(const struct dsa_port *dp,
> +		     const struct switchdev_obj_mrp *mrp);
> +int dsa_port_mrp_del(const struct dsa_port *dp,
> +		     const struct switchdev_obj_mrp *mrp);
> +int dsa_port_mrp_add_ring_role(const struct dsa_port *dp,
> +			       const struct switchdev_obj_ring_role_mrp *mrp);
> +int dsa_port_mrp_del_ring_role(const struct dsa_port *dp,
> +			       const struct switchdev_obj_ring_role_mrp *mrp);
>  int dsa_port_link_register_of(struct dsa_port *dp);
>  void dsa_port_link_unregister_of(struct dsa_port *dp);
>  int dsa_port_hsr_join(struct dsa_port *dp, struct net_device *hsr);
> diff --git a/net/dsa/port.c b/net/dsa/port.c
> index 14a1d0d77657..c9c6d7ab3f47 100644
> --- a/net/dsa/port.c
> +++ b/net/dsa/port.c
> @@ -564,6 +564,54 @@ int dsa_port_vlan_del(struct dsa_port *dp,
>  	return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_DEL, &info);
>  }
>  
> +int dsa_port_mrp_add(const struct dsa_port *dp,
> +		     const struct switchdev_obj_mrp *mrp)
> +{
> +	struct dsa_notifier_mrp_info info = {
> +		.sw_index = dp->ds->index,
> +		.port = dp->index,
> +		.mrp = mrp,
> +	};
> +
> +	return dsa_port_notify(dp, DSA_NOTIFIER_MRP_ADD, &info);
> +}
> +
> +int dsa_port_mrp_del(const struct dsa_port *dp,
> +		     const struct switchdev_obj_mrp *mrp)
> +{
> +	struct dsa_notifier_mrp_info info = {
> +		.sw_index = dp->ds->index,
> +		.port = dp->index,
> +		.mrp = mrp,
> +	};
> +
> +	return dsa_port_notify(dp, DSA_NOTIFIER_MRP_DEL, &info);
> +}
> +
> +int dsa_port_mrp_add_ring_role(const struct dsa_port *dp,
> +			       const struct switchdev_obj_ring_role_mrp *mrp)
> +{
> +	struct dsa_notifier_mrp_ring_role_info info = {
> +		.sw_index = dp->ds->index,
> +		.port = dp->index,
> +		.mrp = mrp,
> +	};
> +
> +	return dsa_port_notify(dp, DSA_NOTIFIER_MRP_ADD_RING_ROLE, &info);
> +}
> +
> +int dsa_port_mrp_del_ring_role(const struct dsa_port *dp,
> +			       const struct switchdev_obj_ring_role_mrp *mrp)
> +{
> +	struct dsa_notifier_mrp_ring_role_info info = {
> +		.sw_index = dp->ds->index,
> +		.port = dp->index,
> +		.mrp = mrp,
> +	};
> +
> +	return dsa_port_notify(dp, DSA_NOTIFIER_MRP_DEL_RING_ROLE, &info);
> +}
> +
>  void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp,
>  			       const struct dsa_device_ops *tag_ops)
>  {
> diff --git a/net/dsa/slave.c b/net/dsa/slave.c
> index 5ecb43a1b6e0..491e3761b5f4 100644
> --- a/net/dsa/slave.c
> +++ b/net/dsa/slave.c
> @@ -404,6 +404,17 @@ static int dsa_slave_port_obj_add(struct net_device *dev,
>  	case SWITCHDEV_OBJ_ID_PORT_VLAN:
>  		err = dsa_slave_vlan_add(dev, obj, extack);
>  		break;
> +	case SWITCHDEV_OBJ_ID_MRP:
> +		if (!dsa_port_offloads_netdev(dp, obj->orig_dev))
> +			return -EOPNOTSUPP;
> +		err = dsa_port_mrp_add(dp, SWITCHDEV_OBJ_MRP(obj));
> +		break;
> +	case SWITCHDEV_OBJ_ID_RING_ROLE_MRP:
> +		if (!dsa_port_offloads_netdev(dp, obj->orig_dev))
> +			return -EOPNOTSUPP;
> +		err = dsa_port_mrp_add_ring_role(dp,
> +						 SWITCHDEV_OBJ_RING_ROLE_MRP(obj));
> +		break;
>  	default:
>  		err = -EOPNOTSUPP;
>  		break;
> @@ -461,6 +472,17 @@ static int dsa_slave_port_obj_del(struct net_device *dev,
>  	case SWITCHDEV_OBJ_ID_PORT_VLAN:
>  		err = dsa_slave_vlan_del(dev, obj);
>  		break;
> +	case SWITCHDEV_OBJ_ID_MRP:
> +		if (!dsa_port_offloads_netdev(dp, obj->orig_dev))
> +			return -EOPNOTSUPP;
> +		err = dsa_port_mrp_del(dp, SWITCHDEV_OBJ_MRP(obj));
> +		break;
> +	case SWITCHDEV_OBJ_ID_RING_ROLE_MRP:
> +		if (!dsa_port_offloads_netdev(dp, obj->orig_dev))
> +			return -EOPNOTSUPP;
> +		err = dsa_port_mrp_del_ring_role(dp,
> +						 SWITCHDEV_OBJ_RING_ROLE_MRP(obj));
> +		break;
>  	default:
>  		err = -EOPNOTSUPP;
>  		break;
> diff --git a/net/dsa/switch.c b/net/dsa/switch.c
> index db2a9b221988..4b5da89dc27a 100644
> --- a/net/dsa/switch.c
> +++ b/net/dsa/switch.c
> @@ -372,6 +372,99 @@ static int dsa_switch_change_tag_proto(struct dsa_switch *ds,
>  	return 0;
>  }
>  
> +static bool dsa_switch_mrp_match(struct dsa_switch *ds, int port,
> +				 struct dsa_notifier_mrp_info *info)
> +{
> +	if (ds->index == info->sw_index && port == info->port)
> +		return true;
> +
> +	if (dsa_is_dsa_port(ds, port))
> +		return true;
> +
> +	return false;
> +}
> +
> +static int dsa_switch_mrp_add(struct dsa_switch *ds,
> +			      struct dsa_notifier_mrp_info *info)
> +{
> +	int err = 0;
> +	int port;
> +
> +	if (!ds->ops->port_mrp_add)
> +		return -EOPNOTSUPP;
> +
> +	for (port = 0; port < ds->num_ports; port++) {
> +		if (dsa_switch_mrp_match(ds, port, info)) {
> +			err = ds->ops->port_mrp_add(ds, port, info->mrp);
> +			if (err)
> +				break;
> +		}
> +	}
> +
> +	return err;
> +}
> +
> +static int dsa_switch_mrp_del(struct dsa_switch *ds,
> +			      struct dsa_notifier_mrp_info *info)
> +{
> +	if (!ds->ops->port_mrp_del)
> +		return -EOPNOTSUPP;
> +
> +	if (ds->index == info->sw_index)
> +		return ds->ops->port_mrp_del(ds, info->port, info->mrp);
> +
> +	return 0;
> +}
> +

Why not use dsa_switch_mrp_match here too? (question valid for the ring
role below too)

> +static bool
> +dsa_switch_mrp_ring_role_match(struct dsa_switch *ds, int port,
> +			       struct dsa_notifier_mrp_ring_role_info *info)
> +{
> +	if (ds->index == info->sw_index && port == info->port)
> +		return true;
> +
> +	if (dsa_is_dsa_port(ds, port))
> +		return true;
> +
> +	return false;
> +}
> +
> +static int
> +dsa_switch_mrp_add_ring_role(struct dsa_switch *ds,
> +			     struct dsa_notifier_mrp_ring_role_info *info)
> +{
> +	int err = 0;
> +	int port;
> +
> +	if (!ds->ops->port_mrp_add)
> +		return -EOPNOTSUPP;
> +
> +	for (port = 0; port < ds->num_ports; port++) {
> +		if (dsa_switch_mrp_ring_role_match(ds, port, info)) {
> +			err = ds->ops->port_mrp_add_ring_role(ds, port,
> +							      info->mrp);
> +			if (err)
> +				break;
> +		}
> +	}
> +
> +	return err;
> +}
> +
> +static int
> +dsa_switch_mrp_del_ring_role(struct dsa_switch *ds,
> +			     struct dsa_notifier_mrp_ring_role_info *info)
> +{
> +	if (!ds->ops->port_mrp_del)
> +		return -EOPNOTSUPP;
> +
> +	if (ds->index == info->sw_index)
> +		return ds->ops->port_mrp_del_ring_role(ds, info->port,
> +						       info->mrp);
> +
> +	return 0;
> +}
> +
>  static int dsa_switch_event(struct notifier_block *nb,
>  			    unsigned long event, void *info)
>  {
> @@ -427,6 +520,18 @@ static int dsa_switch_event(struct notifier_block *nb,
>  	case DSA_NOTIFIER_TAG_PROTO:
>  		err = dsa_switch_change_tag_proto(ds, info);
>  		break;
> +	case DSA_NOTIFIER_MRP_ADD:
> +		err = dsa_switch_mrp_add(ds, info);
> +		break;
> +	case DSA_NOTIFIER_MRP_DEL:
> +		err = dsa_switch_mrp_del(ds, info);
> +		break;
> +	case DSA_NOTIFIER_MRP_ADD_RING_ROLE:
> +		err = dsa_switch_mrp_add_ring_role(ds, info);
> +		break;
> +	case DSA_NOTIFIER_MRP_DEL_RING_ROLE:
> +		err = dsa_switch_mrp_del_ring_role(ds, info);
> +		break;
>  	default:
>  		err = -EOPNOTSUPP;
>  		break;
> -- 
> 2.27.0
> 

  reply	other threads:[~2021-02-17 11:23 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-16 21:41 [Bridge] [PATCH net-next v4 0/8] bridge: mrp: Extend br_mrp_switchdev_* Horatiu Vultur
2021-02-16 21:41 ` [Bridge] [PATCH net-next v4 1/8] switchdev: mrp: Remove CONFIG_BRIDGE_MRP Horatiu Vultur
2021-02-17 10:26   ` Vladimir Oltean
2021-02-16 21:41 ` [Bridge] [PATCH net-next v4 2/8] switchdev: mrp: Extend ring_role_mrp and in_role_mrp Horatiu Vultur
2021-02-17 10:34   ` Vladimir Oltean
2021-02-17 15:58     ` Horatiu Vultur
2021-02-17 16:09       ` Vladimir Oltean
2021-02-16 21:42 ` [Bridge] [PATCH net-next v4 3/8] bridge: mrp: Add 'enum br_mrp_hw_support' Horatiu Vultur
2021-02-16 21:42 ` [Bridge] [PATCH net-next v4 4/8] bridge: mrp: Extend br_mrp_switchdev to detect better the errors Horatiu Vultur
2021-02-17 10:56   ` Vladimir Oltean
2021-02-17 16:02     ` Horatiu Vultur
2021-02-16 21:42 ` [Bridge] [PATCH net-next v4 5/8] bridge: mrp: Update br_mrp to use new return values of br_mrp_switchdev Horatiu Vultur
2021-02-17 10:59   ` Vladimir Oltean
2021-02-17 16:18     ` Horatiu Vultur
2021-02-16 21:42 ` [Bridge] [PATCH net-next v4 6/8] net: mscc: ocelot: Add support for MRP Horatiu Vultur
2021-02-17 11:14   ` Vladimir Oltean
2021-02-17 16:25     ` Horatiu Vultur
2021-02-17 11:51   ` Vladimir Oltean
2021-02-16 21:42 ` [Bridge] [PATCH net-next v4 7/8] net: dsa: add MRP support Horatiu Vultur
2021-02-17 11:23   ` Vladimir Oltean [this message]
2021-02-16 21:42 ` [Bridge] [PATCH net-next v4 8/8] net: dsa: felix: Add support for MRP Horatiu Vultur
2021-02-17 10:24   ` Vladimir Oltean
2021-02-16 23:00 ` [Bridge] [PATCH net-next v4 0/8] bridge: mrp: Extend br_mrp_switchdev_* patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210217112340.xxdfvwp3mw52isse@skbuf \
    --to=vladimir.oltean@nxp.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andrew@lunn.ch \
    --cc=bridge@lists.linux-foundation.org \
    --cc=claudiu.manoil@nxp.com \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=horatiu.vultur@microchip.com \
    --cc=ivecera@redhat.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nikolay@nvidia.com \
    --cc=rasmus.villemoes@prevas.dk \
    --cc=roopa@nvidia.com \
    --cc=vivien.didelot@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox