netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Graf <tgraf@suug.ch>
To: Jiri Pirko <jiri@resnulli.us>
Cc: netdev@vger.kernel.org, davem@davemloft.net,
	nhorman@tuxdriver.com, andy@greyhouse.net, dborkman@redhat.com,
	ogerlitz@mellanox.com, jesse@nicira.com, pshelar@nicira.com,
	azhou@nicira.com, ben@decadent.org.uk,
	stephen@networkplumber.org, jeffrey.t.kirsher@intel.com,
	vyasevic@redhat.com, xiyou.wangcong@gmail.com,
	john.r.fastabend@intel.com, edumazet@google.com,
	jhs@mojatatu.com, sfeldma@cumulusnetworks.com,
	f.fainelli@gmail.com, roopa@cumulusnetworks.com,
	linville@tuxdriver.com, dev@openvswitch.org
Subject: Re: [patch net-next RFC v2 4/6] net: introduce switchdev API
Date: Thu, 27 Mar 2014 11:23:39 +0000	[thread overview]
Message-ID: <20140327112339.GB1615@casper.infradead.org> (raw)
In-Reply-To: <1395851472-10524-5-git-send-email-jiri@resnulli.us>

On 03/26/14 at 05:31pm, Jiri Pirko wrote:
> switchdev API is designed to allow kernel support for various switch
> chips.
> 
> It is the responsibility of a driver to create netdevice instances which
> represents every port and for the switch master itself. Driver uses
> swdev_register and swportdev_register functions to make the core aware
> of the fact these netdevices are representing switch and switch ports.

I like this even more than the previous approach.

> 
> Signed-off-by: Jiri Pirko <jiri@resnulli.us>

> +int __swdev_register(struct net_device *dev)
> +{
> +	if (dev->priv_flags & IFF_SWITCH) {
> +		netdev_err(dev, "Device is already registered as a switch device\n");
> +		return -EBUSY;
> +	}
> +	dev->priv_flags |= IFF_SWITCH;
> +	netdev_info(dev, "Switch device registered\n");

Perhaps include name of device here?

> +	return 0;
> +}
> +EXPORT_SYMBOL(__swdev_register);
> +
> +int swdev_register(struct net_device *dev)
> +{
> +	int err;
> +
> +	rtnl_lock();
> +	err = __swdev_register(dev);
> +	rtnl_unlock();
> +	return err;
> +}
> +EXPORT_SYMBOL(swdev_register);
> +
> +void __swdev_unregister(struct net_device *dev)
> +{
> +	dev->priv_flags |= IFF_SWITCH;
> +	netdev_info(dev, "Switch device unregistered\n");

Same here

> +}
> +EXPORT_SYMBOL(__swdev_unregister);
> +
> +void swdev_unregister(struct net_device *dev)
> +{
> +	rtnl_lock();
> +	__swdev_unregister(dev);
> +	rtnl_unlock();
> +}
> +EXPORT_SYMBOL(swdev_unregister);
> +
> +
> +bool swportdev_dev_check(const struct net_device *port_dev)
> +{
> +	return port_dev->priv_flags & IFF_SWITCH_PORT;
> +}
> +EXPORT_SYMBOL(swportdev_dev_check);
> +
> +static rx_handler_result_t swportdev_handle_frame(struct sk_buff **pskb)
> +{
> +	struct sk_buff *skb = *pskb;
> +
> +	/* We don't care what comes from port device into rx path.
> +	 * If there's something there, it is destined to ETH_P_ALL
> +	 * handlers. So just consume it.
> +	 */
> +	dev_kfree_skb(skb);
> +	return RX_HANDLER_CONSUMED;
> +}
> +
> +int __swportdev_register(struct net_device *port_dev, struct net_device *dev)
> +{
> +	int err;
> +
> +	if (!(dev->priv_flags & IFF_SWITCH)) {
> +		netdev_err(dev, "Device is not a switch device\n");
> +		return -EINVAL;
> +	}
> +	if (port_dev->priv_flags & IFF_SWITCH_PORT) {
> +		netdev_err(port_dev, "Device is already registered as a switch port\n");
> +		return -EBUSY;
> +	}
> +	err = netdev_master_upper_dev_link(port_dev, dev);
> +	if (err) {
> +		netdev_err(dev, "Device %s failed to set upper link\n",
> +			   port_dev->name);
> +		return err;
> +	}
> +	err = netdev_rx_handler_register(port_dev, swportdev_handle_frame, NULL);
> +	if (err) {
> +		netdev_err(dev, "Device %s failed to register rx_handler\n",
> +			   port_dev->name);
> +		goto err_handler_register;
> +	}
> +	port_dev->priv_flags |= IFF_SWITCH_PORT;
> +	netdev_info(port_dev, "Switch port device registered\n");

and here

> +	return 0;
> +
> +err_handler_register:
> +	netdev_upper_dev_unlink(port_dev, dev);
> +	return err;
> +}
> +EXPORT_SYMBOL(__swportdev_register);
> +
> +int swportdev_register(struct net_device *port_dev, struct net_device *dev)

Maybe rename dev to switch_dev just to make it clear?

> +{
> +	int err;
> +
> +	rtnl_lock();
> +	err = __swportdev_register(port_dev, dev);
> +	rtnl_unlock();
> +	return err;
> +}
> +EXPORT_SYMBOL(swportdev_register);
> +
> +void __swportdev_unregister(struct net_device *port_dev)
> +{
> +	struct net_device *dev;
> +
> +	dev = netdev_master_upper_dev_get(port_dev);
> +	BUG_ON(!dev);
> +	port_dev->priv_flags &= ~IFF_SWITCH_PORT;
> +	netdev_rx_handler_unregister(port_dev);
> +	netdev_upper_dev_unlink(port_dev, dev);
> +	netdev_info(port_dev, "Switch port device unregistered\n");
> +}
> +EXPORT_SYMBOL(__swportdev_unregister);
> +
> +void swportdev_unregister(struct net_device *port_dev)
> +{
> +	rtnl_lock();
> +	__swportdev_unregister(port_dev);
> +	rtnl_unlock();
> +}
> +EXPORT_SYMBOL(swportdev_unregister);
> +
> +MODULE_LICENSE("GPL v2");
> +MODULE_AUTHOR("Jiri Pirko <jiri@resnulli.us>");
> +MODULE_DESCRIPTION("Switch device API");
> -- 
> 1.8.5.3
> 

  reply	other threads:[~2014-03-27 11:23 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-26 16:31 [patch net-next RFC v2 0/6] introduce infrastructure for support of switch chip datapath Jiri Pirko
2014-03-26 16:31 ` [patch net-next RFC v2 1/6] net: make packet_type->ak_packet_priv generic Jiri Pirko
2014-03-26 16:31 ` [patch net-next RFC v2 2/6] skbuff: add "missed_flow" flag Jiri Pirko
     [not found]   ` <1395851472-10524-3-git-send-email-jiri-rHqAuBHg3fBzbRFIqnYvSA@public.gmane.org>
2014-03-26 16:59     ` Alexei Starovoitov
2014-03-26 17:25       ` [ovs-dev] " Jiri Pirko
2014-03-27 10:31     ` Nicolas Dichtel
     [not found]       ` <5333FE0E.2090008-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
2014-03-27 10:34         ` Jiri Pirko
2014-03-31 20:39     ` Neil Jerram
2014-03-26 16:31 ` [patch net-next RFC v2 3/6] openvswitch: split flow structures into ovs specific and generic ones Jiri Pirko
2014-03-26 16:31 ` [patch net-next RFC v2 4/6] net: introduce switchdev API Jiri Pirko
2014-03-27 11:23   ` Thomas Graf [this message]
     [not found]     ` <20140327112339.GB1615-FZi0V3Vbi30CUdFEqe4BF2D2FQJk+8+b@public.gmane.org>
2014-03-27 11:26       ` Jiri Pirko
     [not found]   ` <1395851472-10524-5-git-send-email-jiri-rHqAuBHg3fBzbRFIqnYvSA@public.gmane.org>
2014-03-31 20:47     ` Neil Jerram
2014-03-31 20:55     ` Neil Jerram
2014-03-26 16:33 ` [patch iproute2 RFC v2] iproute: add support for dummyswport Jiri Pirko
     [not found] ` <1395851472-10524-1-git-send-email-jiri-rHqAuBHg3fBzbRFIqnYvSA@public.gmane.org>
2014-03-26 16:31   ` [patch net-next RFC v2 5/6] openvswitch: Introduce support for switchdev based datapath Jiri Pirko
2014-03-26 16:31   ` [patch net-next RFC v2 6/6] net: introduce dummy switch Jiri Pirko
2014-03-26 21:44   ` [patch net-next RFC v2 0/6] introduce infrastructure for support of switch chip datapath Jamal Hadi Salim
     [not found]     ` <53334A3F.6020105-jkUAjuhPggJWk0Htik3J/w@public.gmane.org>
2014-03-26 21:57       ` Florian Fainelli
     [not found]         ` <CAGVrzcaOph7=2WfMzTfqtwFkN1fu5uKJAH59aF7mqD4MwL7iOg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-03-27  7:23           ` Jiri Pirko
2014-03-27  7:21       ` Jiri Pirko
     [not found]         ` <20140327072107.GC2845-RDzucLLXGGI88b5SBfVpbw@public.gmane.org>
2014-03-27 10:27           ` Jamal Hadi Salim
2014-03-27 11:02             ` Thomas Graf
2014-03-27 11:17               ` Jamal Hadi Salim
     [not found]                 ` <533408C0.8000608-jkUAjuhPggJWk0Htik3J/w@public.gmane.org>
2014-03-27 12:00                   ` Thomas Graf
2014-03-27 12:32                     ` Jamal Hadi Salim
2014-03-27 12:57                       ` Jiri Pirko
     [not found]                         ` <20140327125711.GL2845-RDzucLLXGGI88b5SBfVpbw@public.gmane.org>
2014-03-27 14:03                           ` John W. Linville
2014-03-27 16:27               ` Florian Fainelli
2014-03-27 17:20                 ` Thomas Graf
     [not found]                   ` <20140327172048.GC13573-FZi0V3Vbi30CUdFEqe4BF2D2FQJk+8+b@public.gmane.org>
2014-03-27 17:26                     ` Jiri Pirko

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=20140327112339.GB1615@casper.infradead.org \
    --to=tgraf@suug.ch \
    --cc=andy@greyhouse.net \
    --cc=azhou@nicira.com \
    --cc=ben@decadent.org.uk \
    --cc=davem@davemloft.net \
    --cc=dborkman@redhat.com \
    --cc=dev@openvswitch.org \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=jesse@nicira.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=john.r.fastabend@intel.com \
    --cc=linville@tuxdriver.com \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=ogerlitz@mellanox.com \
    --cc=pshelar@nicira.com \
    --cc=roopa@cumulusnetworks.com \
    --cc=sfeldma@cumulusnetworks.com \
    --cc=stephen@networkplumber.org \
    --cc=vyasevic@redhat.com \
    --cc=xiyou.wangcong@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;
as well as URLs for NNTP newsgroup(s).