All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <simon.horman@netronome.com>
To: David Miller <davem@davemloft.net>,
	Jakub Kicinski <jakub.kicinski@netronome.com>
Cc: netdev@vger.kernel.org, oss-drivers@netronome.com,
	Simon Horman <simon.horman@netronome.com>
Subject: [PATCH net-next v2 2/9] nfp: add phys_switch_id support
Date: Wed, 28 Jun 2017 22:29:55 +0200	[thread overview]
Message-ID: <1498681802-2897-3-git-send-email-simon.horman@netronome.com> (raw)
In-Reply-To: <1498681802-2897-1-git-send-email-simon.horman@netronome.com>

Add phys_switch_id support by allowing lookup of
SWITCHDEV_ATTR_ID_PORT_PARENT_ID via the nfp_repr_port_attr_get
switchdev operation.

This is visible to user-space in the phys_switch_id attribute
of a netdev.

e.g.
cd /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0
find . -name phys_switch_id | xargs grep .
./net/eth3/phys_switch_id:00154d1300bd
./net/eth4/phys_switch_id:00154d1300bd
./net/eth2/phys_switch_id:00154d1300bd
grep: ./net/eth5/phys_switch_id: Operation not supported

In the above eth2 and eth3 and representor netdevs for the first and second
physical port. eth4 is the representor for the PF. And eth5 is the PF netdev.

Signed-off-by: Simon Horman <simon.horman@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
 .../net/ethernet/netronome/nfp/nfp_net_common.c    |  3 +++
 drivers/net/ethernet/netronome/nfp/nfp_net_repr.c  |  2 ++
 drivers/net/ethernet/netronome/nfp/nfp_port.c      | 28 ++++++++++++++++++++++
 drivers/net/ethernet/netronome/nfp/nfp_port.h      |  3 +++
 4 files changed, 36 insertions(+)

diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
index 2e728543e840..b5834525c5f0 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
@@ -64,6 +64,7 @@
 #include <linux/vmalloc.h>
 #include <linux/ktime.h>
 
+#include <net/switchdev.h>
 #include <net/vxlan.h>
 
 #include "nfpcore/nfp_nsp.h"
@@ -3703,6 +3704,8 @@ static void nfp_net_netdev_init(struct nfp_net *nn)
 	netdev->netdev_ops = &nfp_net_netdev_ops;
 	netdev->watchdog_timeo = msecs_to_jiffies(5 * 1000);
 
+	SWITCHDEV_SET_OPS(netdev, &nfp_port_switchdev_ops);
+
 	/* MTU range: 68 - hw-specific max */
 	netdev->min_mtu = ETH_MIN_MTU;
 	netdev->max_mtu = nn->max_mtu;
diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c
index 046b89eb4cf2..bc9108071e5b 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_net_repr.c
@@ -35,6 +35,7 @@
 #include <linux/io-64-nonatomic-hi-lo.h>
 #include <linux/lockdep.h>
 #include <net/dst_metadata.h>
+#include <net/switchdev.h>
 
 #include "nfpcore/nfp_cpp.h"
 #include "nfpcore/nfp_nsp.h"
@@ -299,6 +300,7 @@ int nfp_repr_init(struct nfp_app *app, struct net_device *netdev,
 	repr->dst->u.port_info.lower_dev = pf_netdev;
 
 	netdev->netdev_ops = &nfp_repr_netdev_ops;
+	SWITCHDEV_SET_OPS(netdev, &nfp_port_switchdev_ops);
 
 	err = register_netdev(netdev);
 	if (err)
diff --git a/drivers/net/ethernet/netronome/nfp/nfp_port.c b/drivers/net/ethernet/netronome/nfp/nfp_port.c
index 0b44952945d8..c95215eb87c2 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_port.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_port.c
@@ -59,6 +59,34 @@ struct nfp_port *nfp_port_from_netdev(struct net_device *netdev)
 	return NULL;
 }
 
+static int
+nfp_port_attr_get(struct net_device *netdev, struct switchdev_attr *attr)
+{
+	struct nfp_port *port;
+
+	port = nfp_port_from_netdev(netdev);
+	if (!port)
+		return -EOPNOTSUPP;
+
+	switch (attr->id) {
+	case SWITCHDEV_ATTR_ID_PORT_PARENT_ID: {
+		const u8 *serial;
+		/* N.B: attr->u.ppid.id is binary data */
+		attr->u.ppid.id_len = nfp_cpp_serial(port->app->cpp, &serial);
+		memcpy(&attr->u.ppid.id, serial, attr->u.ppid.id_len);
+		break;
+	}
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}
+
+const struct switchdev_ops nfp_port_switchdev_ops = {
+	.switchdev_port_attr_get	= nfp_port_attr_get,
+};
+
 struct nfp_port *
 nfp_port_from_id(struct nfp_pf *pf, enum nfp_port_type type, unsigned int id)
 {
diff --git a/drivers/net/ethernet/netronome/nfp/nfp_port.h b/drivers/net/ethernet/netronome/nfp/nfp_port.h
index 57d852a4ca59..de60cacd3362 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_port.h
+++ b/drivers/net/ethernet/netronome/nfp/nfp_port.h
@@ -35,6 +35,7 @@
 #define _NFP_PORT_H_
 
 #include <net/devlink.h>
+#include <net/switchdev.h>
 
 struct net_device;
 struct nfp_app;
@@ -106,6 +107,8 @@ struct nfp_port {
 	struct list_head port_list;
 };
 
+extern const struct switchdev_ops nfp_port_switchdev_ops;
+
 struct nfp_port *nfp_port_from_netdev(struct net_device *netdev);
 struct nfp_port *
 nfp_port_from_id(struct nfp_pf *pf, enum nfp_port_type type, unsigned int id);
-- 
2.1.4

  parent reply	other threads:[~2017-06-28 20:31 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-28 20:29 [PATCH net-next v2 0/9] introduce flower offload capabilities Simon Horman
2017-06-28 20:29 ` [PATCH net-next v2 1/9] net: switchdev: add SET_SWITCHDEV_OPS helper Simon Horman
2017-06-28 20:29 ` Simon Horman [this message]
2017-06-28 20:29 ` [PATCH net-next v2 3/9] nfp: provide infrastructure for offloading flower based TC filters Simon Horman
2017-06-29  1:35   ` Jakub Kicinski
2017-06-29  5:41     ` Simon Horman
2017-06-29  1:53   ` Jakub Kicinski
2017-06-29  8:16     ` Simon Horman
2017-06-29 13:56   ` Or Gerlitz
2017-06-29 14:31     ` Simon Horman
2017-06-28 20:29 ` [PATCH net-next v2 4/9] nfp: extend flower add flow offload Simon Horman
2017-06-29  6:18   ` Yunsheng Lin
2017-06-29  6:48     ` Jakub Kicinski
2017-06-29 13:47       ` David Laight
2017-06-28 20:29 ` [PATCH net-next v2 5/9] nfp: extend flower matching capabilities Simon Horman
2017-06-29 14:31   ` Or Gerlitz
2017-06-29 15:01     ` Simon Horman
2017-06-29 14:33   ` Or Gerlitz
2017-06-29 15:00     ` Simon Horman
2017-06-28 20:29 ` [PATCH net-next v2 6/9] nfp: add basic action capabilities to flower offloads Simon Horman
2017-06-28 20:30 ` [PATCH net-next v2 7/9] nfp: add metadata to each flow offload Simon Horman
2017-06-29  2:33   ` Jakub Kicinski
2017-06-29  8:14     ` [oss-drivers] " Simon Horman
2017-06-29  8:42       ` Jakub Kicinski
2017-06-29 11:22         ` Simon Horman
2017-06-28 20:30 ` [PATCH net-next v2 8/9] nfp: add a stats handler for flower offloads Simon Horman
2017-06-29  1:28   ` Jakub Kicinski
2017-06-29  8:14     ` [oss-drivers] " Simon Horman
2017-06-29  2:55   ` Jakub Kicinski
2017-06-29  8:15     ` [oss-drivers] " Simon Horman
2017-06-29 14:39   ` Or Gerlitz
2017-06-29 14:53     ` Simon Horman
2017-06-29 15:16   ` Or Gerlitz
2017-06-29 15:27     ` Simon Horman
2017-06-28 20:30 ` [PATCH net-next v2 9/9] nfp: add control message passing capabilities to " Simon Horman
2017-06-29 13:46   ` Or Gerlitz
2017-06-29 14:45     ` David Laight
2017-06-29 15:21   ` Or Gerlitz
2017-06-29 15:30     ` Simon Horman
2017-06-29 15:59       ` Or Gerlitz
2017-06-29 17:35         ` Simon Horman

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=1498681802-2897-3-git-send-email-simon.horman@netronome.com \
    --to=simon.horman@netronome.com \
    --cc=davem@davemloft.net \
    --cc=jakub.kicinski@netronome.com \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@netronome.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.