netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Crispin <john@phrozen.org>
To: "David S. Miller" <davem@davemloft.net>,
	Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	John Crispin <john@phrozen.org>
Subject: [PATCH] net: dsa: add FIB support
Date: Mon, 12 Sep 2016 12:13:53 +0200	[thread overview]
Message-ID: <1473675233-36952-1-git-send-email-john@phrozen.org> (raw)

Add SWITCHDEV_OBJ_ID_IPV4_FIB support to the DSA layer.

Signed-off-by: John Crispin <john@phrozen.org>
---
 Documentation/networking/dsa/dsa.txt |   18 +++++++++++++++
 include/net/dsa.h                    |   13 +++++++++++
 net/dsa/slave.c                      |   41 ++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)

diff --git a/Documentation/networking/dsa/dsa.txt b/Documentation/networking/dsa/dsa.txt
index 6d6c07c..6cd5831 100644
--- a/Documentation/networking/dsa/dsa.txt
+++ b/Documentation/networking/dsa/dsa.txt
@@ -607,6 +607,24 @@ of DSA, would be the its port-based VLAN, used by the associated bridge device.
   function that the driver has to call for each MAC address known to be behind
   the given port. A switchdev object is used to carry the VID and MDB info.
 
+Route offloading
+----------------
+
+- ipv4_fib_prepare: routing layer function invoked to prepare the installation
+  of an ipv4 route into the switches routing database. If the operation is not
+  supported this function should return -EOPNOTSUPP. No hardware setup must be
+  done in this function. See ipv4_fib_add for this and details.
+
+- ipv4_fib_add: routing layer function invoked when a new ipv4 route should be
+  installed into the routing database of the switch, it should be programmed
+  with the route for the specified VLAN ID of the device that the route applies
+  to.
+
+- ipv4_fib_del: routing layer function invoked when an ipv4 route should be
+  removed from the routing database, the switch hardware should be programmed
+  to delete the specified MAC address of the nexthop from the specified VLAN ID
+  if it was mapped into the forwarding database.
+
 TODO
 ====
 
diff --git a/include/net/dsa.h b/include/net/dsa.h
index 7556646..7fdd63e 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -237,6 +237,7 @@ struct switchdev_obj;
 struct switchdev_obj_port_fdb;
 struct switchdev_obj_port_mdb;
 struct switchdev_obj_port_vlan;
+struct switchdev_obj_ipv4_fib;
 
 struct dsa_switch_ops {
 	struct list_head	list;
@@ -386,6 +387,18 @@ struct dsa_switch_ops {
 	int	(*port_mdb_dump)(struct dsa_switch *ds, int port,
 				 struct switchdev_obj_port_mdb *mdb,
 				 int (*cb)(struct switchdev_obj *obj));
+
+	/*
+	 * IPV4 routing
+	 */
+	int	(*ipv4_fib_prepare)(struct dsa_switch *ds, int port,
+				    const struct switchdev_obj_ipv4_fib *fib4,
+				    struct switchdev_trans *trans);
+	int	(*ipv4_fib_add)(struct dsa_switch *ds, int port,
+				const struct switchdev_obj_ipv4_fib *fib4,
+				struct switchdev_trans *trans);
+	int	(*ipv4_fib_del)(struct dsa_switch *ds, int port,
+				const struct switchdev_obj_ipv4_fib *fib4);
 };
 
 void register_switch_driver(struct dsa_switch_ops *type);
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 9ecbe78..9e6ceb2 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -334,6 +334,38 @@ static int dsa_slave_port_mdb_dump(struct net_device *dev,
 	return -EOPNOTSUPP;
 }
 
+static int dsa_slave_ipv4_fib_add(struct net_device *dev,
+				  const struct switchdev_obj_ipv4_fib *fib4,
+				  struct switchdev_trans *trans)
+{
+	struct dsa_slave_priv *p = netdev_priv(dev);
+	struct dsa_switch *ds = p->parent;
+	int ret;
+
+	if (!ds->drv->ipv4_fib_prepare || !ds->drv->ipv4_fib_add)
+		return -EOPNOTSUPP;
+
+	if (switchdev_trans_ph_prepare(trans))
+		ret = ds->drv->ipv4_fib_prepare(ds, p->port, fib4, trans);
+	else
+		ret = ds->drv->ipv4_fib_add(ds, p->port, fib4, trans);
+
+	return ret;
+}
+
+static int dsa_slave_ipv4_fib_del(struct net_device *dev,
+				  const struct switchdev_obj_ipv4_fib *fib4)
+{
+	struct dsa_slave_priv *p = netdev_priv(dev);
+	struct dsa_switch *ds = p->parent;
+	int ret = -EOPNOTSUPP;
+
+	if (ds->drv->ipv4_fib_del)
+		ret = ds->drv->ipv4_fib_del(ds, p->port, fib4);
+
+	return ret;
+}
+
 static int dsa_slave_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 {
 	struct dsa_slave_priv *p = netdev_priv(dev);
@@ -465,6 +497,11 @@ static int dsa_slave_port_obj_add(struct net_device *dev,
 					      SWITCHDEV_OBJ_PORT_VLAN(obj),
 					      trans);
 		break;
+	case SWITCHDEV_OBJ_ID_IPV4_FIB:
+		err = dsa_slave_ipv4_fib_add(dev,
+					     SWITCHDEV_OBJ_IPV4_FIB(obj),
+					     trans);
+		break;
 	default:
 		err = -EOPNOTSUPP;
 		break;
@@ -490,6 +527,10 @@ static int dsa_slave_port_obj_del(struct net_device *dev,
 		err = dsa_slave_port_vlan_del(dev,
 					      SWITCHDEV_OBJ_PORT_VLAN(obj));
 		break;
+	case SWITCHDEV_OBJ_ID_IPV4_FIB:
+		err = dsa_slave_ipv4_fib_del(dev,
+					     SWITCHDEV_OBJ_IPV4_FIB(obj));
+		break;
 	default:
 		err = -EOPNOTSUPP;
 		break;
-- 
1.7.10.4

             reply	other threads:[~2016-09-12 10:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-12 10:13 John Crispin [this message]
2016-09-12 11:48 ` [PATCH] net: dsa: add FIB support kbuild test robot
2016-09-12 12:05 ` kbuild test robot
2016-09-12 13:49 ` kbuild test robot
2016-09-12 14:00 ` Andrew Lunn
2016-09-12 18:34   ` John Crispin

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=1473675233-36952-1-git-send-email-john@phrozen.org \
    --to=john@phrozen.org \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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).