diff mbox series

[net-next,1/3] dsa: add support for Arrow XRS700x tag trailer

Message ID 20201120181627.21382-2-george.mccollister@gmail.com
State Superseded
Headers show
Series Arrow SpeedChips XRS700x DSA Driver | expand

Commit Message

George McCollister Nov. 20, 2020, 6:16 p.m. UTC
Add support for Arrow SpeedChips XRS700x single byte tag trailer. This
is modeled on tag_trailer.c which works in a similar way.

Signed-off-by: George McCollister <george.mccollister@gmail.com>
---
 include/net/dsa.h     |  2 ++
 net/dsa/Kconfig       |  6 ++++
 net/dsa/Makefile      |  1 +
 net/dsa/tag_xrs700x.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 100 insertions(+)
 create mode 100644 net/dsa/tag_xrs700x.c

Comments

Andrew Lunn Nov. 20, 2020, 6:58 p.m. UTC | #1
On Fri, Nov 20, 2020 at 12:16:25PM -0600, George McCollister wrote:
> Add support for Arrow SpeedChips XRS700x single byte tag trailer. This
> is modeled on tag_trailer.c which works in a similar way.
> 
> Signed-off-by: George McCollister <george.mccollister@gmail.com>
> ---
>  include/net/dsa.h     |  2 ++
>  net/dsa/Kconfig       |  6 ++++
>  net/dsa/Makefile      |  1 +
>  net/dsa/tag_xrs700x.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 100 insertions(+)
>  create mode 100644 net/dsa/tag_xrs700x.c
> 
> diff --git a/include/net/dsa.h b/include/net/dsa.h
> index 2e64e8de4631..eb46ecdcf165 100644
> --- a/include/net/dsa.h
> +++ b/include/net/dsa.h
> @@ -46,6 +46,7 @@ struct phylink_link_state;
>  #define DSA_TAG_PROTO_AR9331_VALUE		16
>  #define DSA_TAG_PROTO_RTL4_A_VALUE		17
>  #define DSA_TAG_PROTO_HELLCREEK_VALUE		18
> +#define DSA_TAG_PROTO_XRS700X_VALUE		19
>  
>  enum dsa_tag_protocol {
>  	DSA_TAG_PROTO_NONE		= DSA_TAG_PROTO_NONE_VALUE,
> @@ -67,6 +68,7 @@ enum dsa_tag_protocol {
>  	DSA_TAG_PROTO_AR9331		= DSA_TAG_PROTO_AR9331_VALUE,
>  	DSA_TAG_PROTO_RTL4_A		= DSA_TAG_PROTO_RTL4_A_VALUE,
>  	DSA_TAG_PROTO_HELLCREEK		= DSA_TAG_PROTO_HELLCREEK_VALUE,
> +	DSA_TAG_PROTO_XRS700X		= DSA_TAG_PROTO_XRS700X_VALUE,
>  };
>  
>  struct packet_type;
> diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig
> index dfecd7b22fd7..2d226a5c085f 100644
> --- a/net/dsa/Kconfig
> +++ b/net/dsa/Kconfig
> @@ -139,4 +139,10 @@ config NET_DSA_TAG_TRAILER
>  	  Say Y or M if you want to enable support for tagging frames at
>  	  with a trailed. e.g. Marvell 88E6060.
>  
> +config NET_DSA_TAG_XRS700X
> +	tristate "Tag driver for XRS700x switches"
> +	help
> +	  Say Y or M if you want to enable support for tagging frames for
> +	  Arrow SpeedChips XRS700x switches that use a single byte tag trailer.
> +
>  endif
> diff --git a/net/dsa/Makefile b/net/dsa/Makefile
> index 0fb2b75a7ae3..92cea2132241 100644
> --- a/net/dsa/Makefile
> +++ b/net/dsa/Makefile
> @@ -18,3 +18,4 @@ obj-$(CONFIG_NET_DSA_TAG_OCELOT) += tag_ocelot.o
>  obj-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o
>  obj-$(CONFIG_NET_DSA_TAG_SJA1105) += tag_sja1105.o
>  obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o
> +obj-$(CONFIG_NET_DSA_TAG_XRS700X) += tag_xrs700x.o
> diff --git a/net/dsa/tag_xrs700x.c b/net/dsa/tag_xrs700x.c
> new file mode 100644
> index 000000000000..2eda57a4a474
> --- /dev/null
> +++ b/net/dsa/tag_xrs700x.c
> @@ -0,0 +1,91 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * XRS700x tag format handling
> + * Copyright (c) 2008-2009 Marvell Semiconductor
> + * Copyright (c) 2020 NovaTech LLC
> + */
> +
> +#include <linux/etherdevice.h>
> +#include <linux/list.h>
> +#include <linux/slab.h>
> +#include <linux/bitops.h>
> +
> +#include "dsa_priv.h"
> +
> +static struct sk_buff *xrs700x_xmit(struct sk_buff *skb, struct net_device *dev)
> +{
> +	struct dsa_port *dp = dsa_slave_to_port(dev);
> +	struct sk_buff *nskb;
> +	int padlen;
> +	u8 *trailer;
> +
> +	/* We have to make sure that the trailer ends up as the very
> +	 * last byte of the packet.  This means that we have to pad
> +	 * the packet to the minimum ethernet frame size, if necessary,
> +	 * before adding the trailer.
> +	 */
> +	padlen = 0;
> +	if (skb->len < 63)
> +		padlen = 63 - skb->len;
> +
> +	nskb = alloc_skb(NET_IP_ALIGN + skb->len + padlen + 1, GFP_ATOMIC);
> +	if (!nskb)
> +		return NULL;
> +	skb_reserve(nskb, NET_IP_ALIGN);

Hi George

This needs updating to take into account:

commit a3b0b6479700a5b0af2c631cb2ec0fb7a0d978f2
Author: Vladimir Oltean <vladimir.oltean@nxp.com>
Date:   Sun Nov 1 21:16:09 2020 +0200

    net: dsa: implement a central TX reallocation procedure

which i think will handle the padding for you.

      Andrew
George McCollister Nov. 20, 2020, 8:14 p.m. UTC | #2
On Fri, Nov 20, 2020 at 12:58 PM Andrew Lunn <andrew@lunn.ch> wrote:
>
> On Fri, Nov 20, 2020 at 12:16:25PM -0600, George McCollister wrote:
> > Add support for Arrow SpeedChips XRS700x single byte tag trailer. This
> > is modeled on tag_trailer.c which works in a similar way.
> >
> > Signed-off-by: George McCollister <george.mccollister@gmail.com>
> > ---
> >  include/net/dsa.h     |  2 ++
> >  net/dsa/Kconfig       |  6 ++++
> >  net/dsa/Makefile      |  1 +
> >  net/dsa/tag_xrs700x.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++
> >  4 files changed, 100 insertions(+)
> >  create mode 100644 net/dsa/tag_xrs700x.c
> >
> > diff --git a/include/net/dsa.h b/include/net/dsa.h
> > index 2e64e8de4631..eb46ecdcf165 100644
> > --- a/include/net/dsa.h
> > +++ b/include/net/dsa.h
> > @@ -46,6 +46,7 @@ struct phylink_link_state;
> >  #define DSA_TAG_PROTO_AR9331_VALUE           16
> >  #define DSA_TAG_PROTO_RTL4_A_VALUE           17
> >  #define DSA_TAG_PROTO_HELLCREEK_VALUE                18
> > +#define DSA_TAG_PROTO_XRS700X_VALUE          19
> >
> >  enum dsa_tag_protocol {
> >       DSA_TAG_PROTO_NONE              = DSA_TAG_PROTO_NONE_VALUE,
> > @@ -67,6 +68,7 @@ enum dsa_tag_protocol {
> >       DSA_TAG_PROTO_AR9331            = DSA_TAG_PROTO_AR9331_VALUE,
> >       DSA_TAG_PROTO_RTL4_A            = DSA_TAG_PROTO_RTL4_A_VALUE,
> >       DSA_TAG_PROTO_HELLCREEK         = DSA_TAG_PROTO_HELLCREEK_VALUE,
> > +     DSA_TAG_PROTO_XRS700X           = DSA_TAG_PROTO_XRS700X_VALUE,
> >  };
> >
> >  struct packet_type;
> > diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig
> > index dfecd7b22fd7..2d226a5c085f 100644
> > --- a/net/dsa/Kconfig
> > +++ b/net/dsa/Kconfig
> > @@ -139,4 +139,10 @@ config NET_DSA_TAG_TRAILER
> >         Say Y or M if you want to enable support for tagging frames at
> >         with a trailed. e.g. Marvell 88E6060.
> >
> > +config NET_DSA_TAG_XRS700X
> > +     tristate "Tag driver for XRS700x switches"
> > +     help
> > +       Say Y or M if you want to enable support for tagging frames for
> > +       Arrow SpeedChips XRS700x switches that use a single byte tag trailer.
> > +
> >  endif
> > diff --git a/net/dsa/Makefile b/net/dsa/Makefile
> > index 0fb2b75a7ae3..92cea2132241 100644
> > --- a/net/dsa/Makefile
> > +++ b/net/dsa/Makefile
> > @@ -18,3 +18,4 @@ obj-$(CONFIG_NET_DSA_TAG_OCELOT) += tag_ocelot.o
> >  obj-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o
> >  obj-$(CONFIG_NET_DSA_TAG_SJA1105) += tag_sja1105.o
> >  obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o
> > +obj-$(CONFIG_NET_DSA_TAG_XRS700X) += tag_xrs700x.o
> > diff --git a/net/dsa/tag_xrs700x.c b/net/dsa/tag_xrs700x.c
> > new file mode 100644
> > index 000000000000..2eda57a4a474
> > --- /dev/null
> > +++ b/net/dsa/tag_xrs700x.c
> > @@ -0,0 +1,91 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * XRS700x tag format handling
> > + * Copyright (c) 2008-2009 Marvell Semiconductor
> > + * Copyright (c) 2020 NovaTech LLC
> > + */
> > +
> > +#include <linux/etherdevice.h>
> > +#include <linux/list.h>
> > +#include <linux/slab.h>
> > +#include <linux/bitops.h>
> > +
> > +#include "dsa_priv.h"
> > +
> > +static struct sk_buff *xrs700x_xmit(struct sk_buff *skb, struct net_device *dev)
> > +{
> > +     struct dsa_port *dp = dsa_slave_to_port(dev);
> > +     struct sk_buff *nskb;
> > +     int padlen;
> > +     u8 *trailer;
> > +
> > +     /* We have to make sure that the trailer ends up as the very
> > +      * last byte of the packet.  This means that we have to pad
> > +      * the packet to the minimum ethernet frame size, if necessary,
> > +      * before adding the trailer.
> > +      */
> > +     padlen = 0;
> > +     if (skb->len < 63)
> > +             padlen = 63 - skb->len;
> > +
> > +     nskb = alloc_skb(NET_IP_ALIGN + skb->len + padlen + 1, GFP_ATOMIC);
> > +     if (!nskb)
> > +             return NULL;
> > +     skb_reserve(nskb, NET_IP_ALIGN);
>
> Hi George
>
> This needs updating to take into account:
>
> commit a3b0b6479700a5b0af2c631cb2ec0fb7a0d978f2
> Author: Vladimir Oltean <vladimir.oltean@nxp.com>
> Date:   Sun Nov 1 21:16:09 2020 +0200
>
>     net: dsa: implement a central TX reallocation procedure
>
> which i think will handle the padding for you.

Done and tested. Thanks

>
>       Andrew
Florian Fainelli Nov. 23, 2020, 10:18 p.m. UTC | #3
On 11/20/2020 10:16 AM, George McCollister wrote:
> Add support for Arrow SpeedChips XRS700x single byte tag trailer. This
> is modeled on tag_trailer.c which works in a similar way.
> 
> Signed-off-by: George McCollister <george.mccollister@gmail.com>

One question below:

[snip]

> +	if (pskb_trim_rcsum(skb, skb->len - 1))
> +		return NULL;
> +
> +	/* Frame is forwarded by hardware, don't forward in software. */
> +	skb->offload_fwd_mark = 1;

Given the switch does not give you a forwarding reason, I suppose this
is fine, but do you possibly have to qualify this against different
source MAC addresses?
George McCollister Nov. 24, 2020, 8:26 p.m. UTC | #4
On Mon, Nov 23, 2020 at 4:18 PM Florian Fainelli <f.fainelli@gmail.com> wrote:
>
>
>
> On 11/20/2020 10:16 AM, George McCollister wrote:
> > Add support for Arrow SpeedChips XRS700x single byte tag trailer. This
> > is modeled on tag_trailer.c which works in a similar way.
> >
> > Signed-off-by: George McCollister <george.mccollister@gmail.com>
>
> One question below:
>
> [snip]
>
> > +     if (pskb_trim_rcsum(skb, skb->len - 1))
> > +             return NULL;
> > +
> > +     /* Frame is forwarded by hardware, don't forward in software. */
> > +     skb->offload_fwd_mark = 1;
>
> Given the switch does not give you a forwarding reason, I suppose this
> is fine, but do you possibly have to qualify this against different
> source MAC addresses?

I don't see any reason why I'd need to do that but maybe I'm missing something.

> --
> Florian
diff mbox series

Patch

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 2e64e8de4631..eb46ecdcf165 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -46,6 +46,7 @@  struct phylink_link_state;
 #define DSA_TAG_PROTO_AR9331_VALUE		16
 #define DSA_TAG_PROTO_RTL4_A_VALUE		17
 #define DSA_TAG_PROTO_HELLCREEK_VALUE		18
+#define DSA_TAG_PROTO_XRS700X_VALUE		19
 
 enum dsa_tag_protocol {
 	DSA_TAG_PROTO_NONE		= DSA_TAG_PROTO_NONE_VALUE,
@@ -67,6 +68,7 @@  enum dsa_tag_protocol {
 	DSA_TAG_PROTO_AR9331		= DSA_TAG_PROTO_AR9331_VALUE,
 	DSA_TAG_PROTO_RTL4_A		= DSA_TAG_PROTO_RTL4_A_VALUE,
 	DSA_TAG_PROTO_HELLCREEK		= DSA_TAG_PROTO_HELLCREEK_VALUE,
+	DSA_TAG_PROTO_XRS700X		= DSA_TAG_PROTO_XRS700X_VALUE,
 };
 
 struct packet_type;
diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig
index dfecd7b22fd7..2d226a5c085f 100644
--- a/net/dsa/Kconfig
+++ b/net/dsa/Kconfig
@@ -139,4 +139,10 @@  config NET_DSA_TAG_TRAILER
 	  Say Y or M if you want to enable support for tagging frames at
 	  with a trailed. e.g. Marvell 88E6060.
 
+config NET_DSA_TAG_XRS700X
+	tristate "Tag driver for XRS700x switches"
+	help
+	  Say Y or M if you want to enable support for tagging frames for
+	  Arrow SpeedChips XRS700x switches that use a single byte tag trailer.
+
 endif
diff --git a/net/dsa/Makefile b/net/dsa/Makefile
index 0fb2b75a7ae3..92cea2132241 100644
--- a/net/dsa/Makefile
+++ b/net/dsa/Makefile
@@ -18,3 +18,4 @@  obj-$(CONFIG_NET_DSA_TAG_OCELOT) += tag_ocelot.o
 obj-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o
 obj-$(CONFIG_NET_DSA_TAG_SJA1105) += tag_sja1105.o
 obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o
+obj-$(CONFIG_NET_DSA_TAG_XRS700X) += tag_xrs700x.o
diff --git a/net/dsa/tag_xrs700x.c b/net/dsa/tag_xrs700x.c
new file mode 100644
index 000000000000..2eda57a4a474
--- /dev/null
+++ b/net/dsa/tag_xrs700x.c
@@ -0,0 +1,91 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * XRS700x tag format handling
+ * Copyright (c) 2008-2009 Marvell Semiconductor
+ * Copyright (c) 2020 NovaTech LLC
+ */
+
+#include <linux/etherdevice.h>
+#include <linux/list.h>
+#include <linux/slab.h>
+#include <linux/bitops.h>
+
+#include "dsa_priv.h"
+
+static struct sk_buff *xrs700x_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+	struct dsa_port *dp = dsa_slave_to_port(dev);
+	struct sk_buff *nskb;
+	int padlen;
+	u8 *trailer;
+
+	/* We have to make sure that the trailer ends up as the very
+	 * last byte of the packet.  This means that we have to pad
+	 * the packet to the minimum ethernet frame size, if necessary,
+	 * before adding the trailer.
+	 */
+	padlen = 0;
+	if (skb->len < 63)
+		padlen = 63 - skb->len;
+
+	nskb = alloc_skb(NET_IP_ALIGN + skb->len + padlen + 1, GFP_ATOMIC);
+	if (!nskb)
+		return NULL;
+	skb_reserve(nskb, NET_IP_ALIGN);
+
+	skb_reset_mac_header(nskb);
+	skb_set_network_header(nskb, skb_network_header(skb) - skb->head);
+	skb_set_transport_header(nskb, skb_transport_header(skb) - skb->head);
+	skb_copy_and_csum_dev(skb, skb_put(nskb, skb->len));
+	consume_skb(skb);
+
+	if (padlen)
+		skb_put_zero(nskb, padlen);
+
+	trailer = skb_put(nskb, 1);
+	trailer[0] = BIT(dp->index);
+
+	return nskb;
+}
+
+static struct sk_buff *xrs700x_rcv(struct sk_buff *skb, struct net_device *dev,
+				   struct packet_type *pt)
+{
+	u8 *trailer;
+	int source_port;
+
+	if (skb_linearize(skb))
+		return NULL;
+
+	trailer = skb_tail_pointer(skb) - 1;
+
+	source_port = ffs((int)trailer[0]) - 1;
+
+	if (source_port < 0)
+		return NULL;
+
+	skb->dev = dsa_master_find_slave(dev, 0, source_port);
+	if (!skb->dev)
+		return NULL;
+
+	if (pskb_trim_rcsum(skb, skb->len - 1))
+		return NULL;
+
+	/* Frame is forwarded by hardware, don't forward in software. */
+	skb->offload_fwd_mark = 1;
+
+	return skb;
+}
+
+static const struct dsa_device_ops xrs700x_netdev_ops = {
+	.name	= "xrs700x",
+	.proto	= DSA_TAG_PROTO_XRS700X,
+	.xmit	= xrs700x_xmit,
+	.rcv	= xrs700x_rcv,
+	.overhead = 1,
+};
+
+MODULE_LICENSE("GPL");
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_XRS700X);
+
+module_dsa_tag_driver(xrs700x_netdev_ops);