Netdev List
 help / color / mirror / Atom feed
* Re: [PATCH net] vxlan: fix sparse warnings
From: David Miller @ 2016-03-21 17:30 UTC (permalink / raw)
  To: jbenc; +Cc: netdev, fengguang.wu
In-Reply-To: <c100b5ed75967714ab32287f37d250b729753282.1458578309.git.jbenc@redhat.com>

From: Jiri Benc <jbenc@redhat.com>
Date: Mon, 21 Mar 2016 17:39:18 +0100

> Sparse reports false positives for the header manipulation inlines. Annotate
> them correctly.
> 
> Tested by sparse on a little endian and big endian machine.
> 
> Fixes: 54bfd872bf16d ("vxlan: keep flags and vni in network byte order")
> Reported-by: kbuild test robot <fengguang.wu@intel.com>
> Signed-off-by: Jiri Benc <jbenc@redhat.com>

Applied, thanks Jiri.

> As a side note, I tried to simplify all of these functions by using nested
> be32_to_cpu(cpu_to_be32()) calls but GCC seems not to be clever enough to
> optimize the byteswaps out.

Ok, thanks for the note, thanks again.

^ permalink raw reply

* [PATCH net-next v2 1/2] ethtool: minor doc update
From: David Decotigny @ 2016-03-21 17:15 UTC (permalink / raw)
  To: David S. Miller, linux-kernel, netdev
  Cc: Nikolay Aleksandrov, Michael S. Tsirkin, Ben Hutchings,
	Jeff Kirsher, David Decotigny, Nicolas Dichtel, Andrew Lunn,
	Hadar Hen Zion, Edward Cree, John Fastabend, Herbert Xu,
	Thomas Graf, Daniel Borkmann, Ken-ichirou MATSUZAWA,
	Florian Westphal, David Herrmann
In-Reply-To: <1458580535-112916-1-git-send-email-ddecotig@gmail.com>

From: David Decotigny <decot@googlers.com>

Updates: commit 793cf87de9d1 ("ethtool: Set cmd field in
         ETHTOOL_GLINKSETTINGS response to wrong nwords")

Signed-off-by: David Decotigny <decot@googlers.com>
---
 include/uapi/linux/ethtool.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h
index 2835b07..9222db8 100644
--- a/include/uapi/linux/ethtool.h
+++ b/include/uapi/linux/ethtool.h
@@ -1648,9 +1648,9 @@ enum ethtool_reset_flags {
  *	%ETHTOOL_GLINKSETTINGS: on entry, number of words passed by user
  *	(>= 0); on return, if handshake in progress, negative if
  *	request size unsupported by kernel: absolute value indicates
- *	kernel recommended size and cmd field is 0, as well as all the
- *	other fields; otherwise (handshake completed), strictly
- *	positive to indicate size used by kernel and cmd field is
+ *	kernel expected size and all the other fields but cmd
+ *	are 0; otherwise (handshake completed), strictly positive
+ *	to indicate size used by kernel and cmd field stays
  *	%ETHTOOL_GLINKSETTINGS, all other fields populated by driver. For
  *	%ETHTOOL_SLINKSETTINGS: must be valid on entry, ie. a positive
  *	value returned previously by %ETHTOOL_GLINKSETTINGS, otherwise
-- 
2.8.0.rc3.226.g39d4020

^ permalink raw reply related

* [PATCH net-next v2 0/2] basic ioctl support for netlink sockets
From: David Decotigny @ 2016-03-21 17:15 UTC (permalink / raw)
  To: David S. Miller, linux-kernel, netdev
  Cc: Nikolay Aleksandrov, Michael S. Tsirkin, Ben Hutchings,
	Jeff Kirsher, David Decotigny, Nicolas Dichtel, Andrew Lunn,
	Hadar Hen Zion, Edward Cree, John Fastabend, Herbert Xu,
	Thomas Graf, Daniel Borkmann, Ken-ichirou MATSUZAWA,
	Florian Westphal, David Herrmann

From: David Decotigny <decot@googlers.com>

This removes the requirement that ethtool be tied to the support
of a specific L3 protocol, also updates a comment.

History:
  v2
    updated commit description for the netlink ioctl patch
  v1
    initial submission

############################################
# Patch Set Summary:

David Decotigny (2):
  ethtool: minor doc update
  netlink: add support for NIC driver ioctls

 include/uapi/linux/ethtool.h |  6 +++---
 net/netlink/af_netlink.c     | 10 +++++++++-
 2 files changed, 12 insertions(+), 4 deletions(-)

-- 
2.8.0.rc3.226.g39d4020

^ permalink raw reply

* [PATCH net-next v2 2/2] netlink: add support for NIC driver ioctls
From: David Decotigny @ 2016-03-21 17:15 UTC (permalink / raw)
  To: David S. Miller, linux-kernel, netdev
  Cc: Nikolay Aleksandrov, Michael S. Tsirkin, Ben Hutchings,
	Jeff Kirsher, David Decotigny, Nicolas Dichtel, Andrew Lunn,
	Hadar Hen Zion, Edward Cree, John Fastabend, Herbert Xu,
	Thomas Graf, Daniel Borkmann, Ken-ichirou MATSUZAWA,
	Florian Westphal, David Herrmann
In-Reply-To: <1458580535-112916-1-git-send-email-ddecotig@gmail.com>

From: David Decotigny <decot@googlers.com>

By returning -ENOIOCTLCMD, sock_do_ioctl() falls back to calling
dev_ioctl(), which provides support for NIC driver ioctls, which
includes ethtool support. This is similar to the way ioctls are handled
in udp.c or tcp.c.

This removes the requirement that ethtool for example be tied to the
support of a specific L3 protocol (ethtool uses an AF_INET socket
today).

Signed-off-by: David Decotigny <decot@googlers.com>
---
 net/netlink/af_netlink.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index c841679..215fc08 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1033,6 +1033,14 @@ static int netlink_getname(struct socket *sock, struct sockaddr *addr,
 	return 0;
 }
 
+static int netlink_ioctl(struct socket *sock, unsigned int cmd,
+			 unsigned long arg)
+{
+	/* try to hand this ioctl down to the NIC drivers.
+	 */
+	return -ENOIOCTLCMD;
+}
+
 static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
 {
 	struct sock *sock;
@@ -2494,7 +2502,7 @@ static const struct proto_ops netlink_ops = {
 	.accept =	sock_no_accept,
 	.getname =	netlink_getname,
 	.poll =		datagram_poll,
-	.ioctl =	sock_no_ioctl,
+	.ioctl =	netlink_ioctl,
 	.listen =	sock_no_listen,
 	.shutdown =	sock_no_shutdown,
 	.setsockopt =	netlink_setsockopt,
-- 
2.8.0.rc3.226.g39d4020

^ permalink raw reply related

* Re: [PATCH] ipv6: Fix the pmtu path for connected UDP socket
From: Wei Wang @ 2016-03-21 17:13 UTC (permalink / raw)
  To: Cong Wang
  Cc: Wei Wang, Martin KaFai Lau, Eric Dumazet, David Miller,
	Eric Dumazet, Linux Kernel Network Developers
In-Reply-To: <CAM_iQpWvKUyTmvH=08FbeyGWKfV_WaM_L1MgOQ-9r9hjfvzPyA@mail.gmail.com>

Hey Cong,

This solution probably will not work.
First of all, if you look into __ip6_rt_update_pmtu(), it creates a
new dst and this dst does not get passed back to its caller. So unless
we tweak this function to pass the new dst back, we can only update
sk->sk_dst_cache inside the function itself.
Secondly, ip6_update_pmtu is called in multiple places. Not only here.
I am not sure how many places need to be changed like this. It seems
not a good thing to do.

Thanks.
Wei

On Fri, Mar 18, 2016 at 3:09 PM, Cong Wang <xiyou.wangcong@gmail.com> wrote:
> On Fri, Mar 18, 2016 at 2:26 PM, Wei Wang <tracywwnj@gmail.com> wrote:
>> I don't think ip6_sk_update_pmtu() is a good place to put it as all it
>> does is to call ip6_update_pmtu(). And ip6_update_pmtu() does the
>> route lookup and call __ip6_rt_update_pmtu.
>> We can put it in ip6_update_pmtu(). But that still means we need to
>> pass sk to ip6_update_pmtu() and I don't think it makes any difference
>> compared to the current fix.
>>
>
> Well, your patch touches all the callers of ip6_update_pmtu() , if you just
> fix ip6_sk_update_pmtu() as I suggested, you only need to change one
> function, ideally. And the ipv4 code is there, although I am not sure, it
> looks like we can just mimic the logic here:
>
> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index ed44663..b88c2ff 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -1417,8 +1417,28 @@ EXPORT_SYMBOL_GPL(ip6_update_pmtu);
>
>  void ip6_sk_update_pmtu(struct sk_buff *skb, struct sock *sk, __be32 mtu)
>  {
> -       ip6_update_pmtu(skb, sock_net(sk), mtu,
> -                       sk->sk_bound_dev_if, sk->sk_mark);
> +       const struct ipv6hdr *iph = (struct ipv6hdr *) skb->data;
> +       struct net *net = sock_net(sk);
> +       struct dst_entry *dst;
> +       struct flowi6 fl6;
> +
> +       bh_lock_sock(sk);
> +
> +       memset(&fl6, 0, sizeof(fl6));
> +       fl6.flowi6_oif = sk->sk_bound_dev_if;
> +       fl6.flowi6_mark = sk->sk_mark ? : IP6_REPLY_MARK(net, skb->mark);
> +       fl6.daddr = iph->daddr;
> +       fl6.saddr = iph->saddr;
> +       fl6.flowlabel = ip6_flowinfo(iph);
> +
> +       dst = ip6_route_output(net, NULL, &fl6);
> +       if (!dst->error)
> +               __ip6_rt_update_pmtu(dst, NULL, iph, ntohl(mtu));
> +
> +       sk_dst_set(sk, &rt->dst);
> +       bh_unlock_sock(sk);
> +
> +       dst_release(dst);
>  }
>
>
> Please don't judge me on the code, it could still miss a lot of things,
> but it can show my idea...

^ permalink raw reply

* Re: [RFCv2 0/3] mac80211: implement fq codel
From: Dave Taht @ 2016-03-21 17:10 UTC (permalink / raw)
  To: Michal Kazior
  Cc: Network Development, linux-wireless, ath10k@lists.infradead.org,
	Jasmine Strong, codel@lists.bufferbloat.net, make-wifi-fast

[-- Attachment #1: Type: text/plain, Size: 818 bytes --]

thx.

a lot to digest.

A) quick notes on "flent-gui bursts_11e-2016-03-21T09*.gz"

1) the new bursts_11e test *should* have stuck stuff in the VI and VO
queues, and there *should* have been some sort of difference shown on
the plots with it. There wasn't.

For diffserv markings I used BE=CS0, BK=CS1, VI=CS5, and VO=EF.
CS6/CS7 should also land in VO (at least with the soft mac handler
last I looked). Is there a way to check if you are indeed exercising
all four 802.11e hardware queues in this test? in ath9k it is the
"xmit" sysfs var....

2) In all the old cases the BE UDP_RR flow died on the first burst
(why?), and the fullpatch preserved it. (I would have kind of hoped to
have seen the BK flow die, actually, in the fullpatch)

3) I am also confused on 802.11ac - can VO aggregate? ( can't in in 802.11n).

[-- Attachment #2: vivosame.png --]
[-- Type: image/png, Size: 276624 bytes --]

[-- Attachment #3: Type: text/plain, Size: 140 bytes --]

_______________________________________________
Codel mailing list
Codel@lists.bufferbloat.net
https://lists.bufferbloat.net/listinfo/codel

^ permalink raw reply

* [PATCH net 1/2] net/rtnetlink: add IFLA_GSO_MAX_SEGS and IFLA_GSO_MAX_SIZE attributes
From: Eric Dumazet @ 2016-03-21 16:55 UTC (permalink / raw)
  To: David S . Miller
  Cc: netdev, Eric Dumazet, Eric Dumazet, Petri Gynther,
	Stephen Hemminger
In-Reply-To: <1458579311-17699-1-git-send-email-edumazet@google.com>

It can be useful to report dev->gso_max_segs and dev->gso_max_size
so that "ip -d link" can display them to help debugging.

For the moment, these attributes are read-only.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Petri Gynther <pgynther@google.com>
Cc: Stephen Hemminger <stephen@networkplumber.org>
---
 include/uapi/linux/if_link.h | 2 ++
 net/core/rtnetlink.c         | 4 ++++
 2 files changed, 6 insertions(+)

diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 8e3f88fa5b59..76d315ca597d 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -153,6 +153,8 @@ enum {
 	IFLA_LINK_NETNSID,
 	IFLA_PHYS_PORT_NAME,
 	IFLA_PROTO_DOWN,
+	IFLA_GSO_MAX_SEGS,
+	IFLA_GSO_MAX_SIZE,
 	__IFLA_MAX
 };
 
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index d2d9e5ebf58e..a69cd0c097b5 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -895,6 +895,8 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
 	       + nla_total_size(4) /* IFLA_PROMISCUITY */
 	       + nla_total_size(4) /* IFLA_NUM_TX_QUEUES */
 	       + nla_total_size(4) /* IFLA_NUM_RX_QUEUES */
+	       + nla_total_size(4) /* IFLA_MAX_GSO_SEGS */
+	       + nla_total_size(4) /* IFLA_MAX_GSO_SIZE */
 	       + nla_total_size(1) /* IFLA_OPERSTATE */
 	       + nla_total_size(1) /* IFLA_LINKMODE */
 	       + nla_total_size(4) /* IFLA_CARRIER_CHANGES */
@@ -1223,6 +1225,8 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
 	    nla_put_u32(skb, IFLA_GROUP, dev->group) ||
 	    nla_put_u32(skb, IFLA_PROMISCUITY, dev->promiscuity) ||
 	    nla_put_u32(skb, IFLA_NUM_TX_QUEUES, dev->num_tx_queues) ||
+	    nla_put_u32(skb, IFLA_GSO_MAX_SEGS, dev->gso_max_segs) ||
+	    nla_put_u32(skb, IFLA_GSO_MAX_SIZE, dev->gso_max_size) ||
 #ifdef CONFIG_RPS
 	    nla_put_u32(skb, IFLA_NUM_RX_QUEUES, dev->num_rx_queues) ||
 #endif
-- 
2.8.0.rc3.226.g39d4020

^ permalink raw reply related

* [PATCH net 2/2] bridge: update max_gso_segs and max_gso_size
From: Eric Dumazet @ 2016-03-21 16:55 UTC (permalink / raw)
  To: David S . Miller
  Cc: netdev, Eric Dumazet, Eric Dumazet, Petri Gynther,
	Stephen Hemminger
In-Reply-To: <1458579311-17699-1-git-send-email-edumazet@google.com>

It can be useful to lower max_gso_segs on NIC with very low
number of TX descriptors like bcmgenet.

However, this is defeated by bridge since it does not propagate
the lower value of max_gso_segs and max_gso_size.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Petri Gynther <pgynther@google.com>
Cc: Stephen Hemminger <stephen@networkplumber.org>
---
 net/bridge/br_if.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index a73df3315df9..8217aecf025b 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -437,6 +437,20 @@ int br_min_mtu(const struct net_bridge *br)
 	return mtu;
 }
 
+static void br_set_gso_limits(struct net_bridge *br)
+{
+	unsigned int gso_max_size = GSO_MAX_SIZE;
+	u16 gso_max_segs = GSO_MAX_SEGS;
+	const struct net_bridge_port *p;
+
+	list_for_each_entry(p, &br->port_list, list) {
+		gso_max_size = min(gso_max_size, p->dev->gso_max_size);
+		gso_max_segs = min(gso_max_segs, p->dev->gso_max_segs);
+	}
+	br->dev->gso_max_size = gso_max_size;
+	br->dev->gso_max_segs = gso_max_segs;
+}
+
 /*
  * Recomputes features using slave's features
  */
@@ -564,6 +578,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)
 		call_netdevice_notifiers(NETDEV_CHANGEADDR, br->dev);
 
 	dev_set_mtu(br->dev, br_min_mtu(br));
+	br_set_gso_limits(br);
 
 	kobject_uevent(&p->kobj, KOBJ_ADD);
 
@@ -610,6 +625,7 @@ int br_del_if(struct net_bridge *br, struct net_device *dev)
 	del_nbp(p);
 
 	dev_set_mtu(br->dev, br_min_mtu(br));
+	br_set_gso_limits(br);
 
 	spin_lock_bh(&br->lock);
 	changed_addr = br_stp_recalculate_bridge_id(br);
-- 
2.8.0.rc3.226.g39d4020

^ permalink raw reply related

* [PATCH net 0/2] net: propagate max_gso_segs and max_gso_size
From: Eric Dumazet @ 2016-03-21 16:55 UTC (permalink / raw)
  To: David S . Miller
  Cc: netdev, Eric Dumazet, Eric Dumazet, Petri Gynther,
	Stephen Hemminger

bridge code does not properly update max_gso_segs and max_gso_size.

Since this was not really obvious, first patch adds two new rtnetlink
attributes to help debugging this kind of issues (ip -d link)

Second patch fixes bridge code.

Eric Dumazet (2):
  net/rtnetlink: add IFLA_GSO_MAX_SEGS and IFLA_GSO_MAX_SIZE attributes
  bridge: update max_gso_segs and max_gso_size

 include/uapi/linux/if_link.h |  2 ++
 net/bridge/br_if.c           | 16 ++++++++++++++++
 net/core/rtnetlink.c         |  4 ++++
 3 files changed, 22 insertions(+)

-- 
2.8.0.rc3.226.g39d4020

^ permalink raw reply

* [PATCH 2/2] can: rcar_can: Move Renesas CAN driver to rcar dir
From: Ramesh Shanmugasundaram @ 2016-03-21 16:45 UTC (permalink / raw)
  To: mkl, wg, socketcan, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak
  Cc: linux-renesas-soc, devicetree, linux-can, netdev, chris.paterson2,
	Ramesh Shanmugasundaram
In-Reply-To: <1458578756-42898-1-git-send-email-ramesh.shanmugasundaram@bp.renesas.com>

This patch clubs the Renesas controller drivers in one rcar dir.

Signed-off-by: Ramesh Shanmugasundaram <ramesh.shanmugasundaram@bp.renesas.com>
---
 drivers/net/can/Kconfig               | 10 ----------
 drivers/net/can/Makefile              |  1 -
 drivers/net/can/rcar/Kconfig          | 10 ++++++++++
 drivers/net/can/rcar/Makefile         |  3 ++-
 drivers/net/can/{ => rcar}/rcar_can.c |  0
 5 files changed, 12 insertions(+), 12 deletions(-)
 rename drivers/net/can/{ => rcar}/rcar_can.c (100%)

diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
index 13003a9..22570ea 100644
--- a/drivers/net/can/Kconfig
+++ b/drivers/net/can/Kconfig
@@ -104,16 +104,6 @@ config CAN_JANZ_ICAN3
 	  This driver can also be built as a module. If so, the module will be
 	  called janz-ican3.ko.
 
-config CAN_RCAR
-	tristate "Renesas R-Car CAN controller"
-	depends on ARCH_RENESAS || ARM
-	---help---
-	  Say Y here if you want to use CAN controller found on Renesas R-Car
-	  SoCs.
-
-	  To compile this driver as a module, choose M here: the module will
-	  be called rcar_can.
-
 config CAN_SUN4I
 	tristate "Allwinner A10 CAN controller"
 	depends on MACH_SUN4I || MACH_SUN7I || COMPILE_TEST
diff --git a/drivers/net/can/Makefile b/drivers/net/can/Makefile
index 226d5b5..26ba4b7 100644
--- a/drivers/net/can/Makefile
+++ b/drivers/net/can/Makefile
@@ -25,7 +25,6 @@ obj-$(CONFIG_CAN_IFI_CANFD)	+= ifi_canfd/
 obj-$(CONFIG_CAN_JANZ_ICAN3)	+= janz-ican3.o
 obj-$(CONFIG_CAN_MSCAN)		+= mscan/
 obj-$(CONFIG_CAN_M_CAN)		+= m_can/
-obj-$(CONFIG_CAN_RCAR)		+= rcar_can.o
 obj-$(CONFIG_CAN_SJA1000)	+= sja1000/
 obj-$(CONFIG_CAN_SUN4I)		+= sun4i_can.o
 obj-$(CONFIG_CAN_TI_HECC)	+= ti_hecc.o
diff --git a/drivers/net/can/rcar/Kconfig b/drivers/net/can/rcar/Kconfig
index 6ea64d1..7b03a3a 100644
--- a/drivers/net/can/rcar/Kconfig
+++ b/drivers/net/can/rcar/Kconfig
@@ -1,3 +1,13 @@
+config CAN_RCAR
+	tristate "Renesas R-Car CAN controller"
+	depends on ARCH_RENESAS || ARM
+	---help---
+	  Say Y here if you want to use CAN controller found on Renesas R-Car
+	  SoCs.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called rcar_can.
+
 config CAN_RCAR_CANFD
 	tristate "Renesas R-Car CAN FD controller"
 	depends on ARCH_RENESAS || ARM
diff --git a/drivers/net/can/rcar/Makefile b/drivers/net/can/rcar/Makefile
index cbaf498e..08de36a 100644
--- a/drivers/net/can/rcar/Makefile
+++ b/drivers/net/can/rcar/Makefile
@@ -1,5 +1,6 @@
 #
-#  Makefile for the Renesas R-Car CAN FD controller driver
+#  Makefile for the Renesas R-Car CAN & CAN FD controller drivers
 #
 
+obj-$(CONFIG_CAN_RCAR)		+= rcar_can.o
 obj-$(CONFIG_CAN_RCAR_CANFD)	+= rcar_canfd.o
diff --git a/drivers/net/can/rcar_can.c b/drivers/net/can/rcar/rcar_can.c
similarity index 100%
rename from drivers/net/can/rcar_can.c
rename to drivers/net/can/rcar/rcar_can.c
-- 
1.9.1

^ permalink raw reply related

* [PATCH 1/2] can: rcar_canfd: Add Renesas R-Car CAN FD driver
From: Ramesh Shanmugasundaram @ 2016-03-21 16:45 UTC (permalink / raw)
  To: mkl, wg, socketcan, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak
  Cc: linux-renesas-soc, devicetree, linux-can, netdev, chris.paterson2,
	Ramesh Shanmugasundaram
In-Reply-To: <1458578756-42898-1-git-send-email-ramesh.shanmugasundaram@bp.renesas.com>

This patch adds support for the CAN FD controller found in Renesas R-Car
SoCs. The controller operates in CAN FD only mode by default.

CAN FD mode supports both Classical CAN & CAN FD frame formats. The
controller supports ISO 11898-1:2015 CAN FD format only.

This controller supports two channels and the driver can enable either
or both of the channels.

Driver uses Rx FIFOs (one per channel) for reception & Common FIFOs (one
per channel) for transmission. Rx filter rules are configured to the
minimum (one per channel) and it accepts Standard, Extended, Data &
Remote Frame combinations.

Note: There are few documentation errors in R-Car Gen3 Hardware User
Manual v0.5E with respect to CAN FD controller. They are listed below:

1. CAN FD interrupt numbers 29 & 30 are listed as per channel
interrupts. However, they are common to both channels (i.e.) they are
global and channel interrupts respectively.

2. CANFD clock is derived from PLL1. This is not documented.

3. CANFD clock is further divided by (1/2) within the CAN FD controller.
This is not documented.

4. The minimum value of NTSEG1 in RSCFDnCFDCmNCFG register is 2 Tq. It
is specified 4 Tq in the manual.

5. The maximum number of message RAM area the controller can use is 3584
bytes. It is specified 10752 bytes in the manual.

Signed-off-by: Ramesh Shanmugasundaram <ramesh.shanmugasundaram@bp.renesas.com>
Acked-by: Rob Herring <robh@kernel.org>
---
 .../devicetree/bindings/net/can/rcar_canfd.txt     |   89 ++
 drivers/net/can/Kconfig                            |    1 +
 drivers/net/can/Makefile                           |    1 +
 drivers/net/can/rcar/Kconfig                       |   11 +
 drivers/net/can/rcar/Makefile                      |    5 +
 drivers/net/can/rcar/rcar_canfd.c                  | 1623 ++++++++++++++++++++
 6 files changed, 1730 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/can/rcar_canfd.txt
 create mode 100644 drivers/net/can/rcar/Kconfig
 create mode 100644 drivers/net/can/rcar/Makefile
 create mode 100644 drivers/net/can/rcar/rcar_canfd.c

diff --git a/Documentation/devicetree/bindings/net/can/rcar_canfd.txt b/Documentation/devicetree/bindings/net/can/rcar_canfd.txt
new file mode 100644
index 0000000..d45182b
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/can/rcar_canfd.txt
@@ -0,0 +1,89 @@
+Renesas R-Car CAN FD controller Device Tree Bindings
+----------------------------------------------------
+
+Required properties:
+- compatible: Must contain one or more of the following:
+  - "renesas,rcar-gen3-canfd" for R-Car Gen3 compatible controller.
+  - "renesas,r8a7795-canfd" for R8A7795 (R-Car H3) compatible controller.
+
+  When compatible with the generic version, nodes must list the
+  SoC-specific version corresponding to the platform first, followed by the
+  family-specific and/or generic versions.
+
+- reg: physical base address and size of the R-Car CAN FD register map.
+- interrupts: interrupt specifier for the Global & Channel interrupts
+- clocks: phandles and clock specifiers for 3 clock inputs.
+- clock-names: 3 clock input name strings: "fck", "canfd", "can_clk".
+- pinctrl-0: pin control group to be used for this controller.
+- pinctrl-names: must be "default".
+
+Required child nodes:
+The controller supports two channels and each is represented as a child node.
+The name of the child nodes are "channel0" and "channel1" respectively. Each
+child node supports the "status" property only, which is used to
+enable/disable the respective channel.
+
+Required properties for "renesas,r8a7795-canfd" compatible:
+In R8A7795 SoC, canfd clock is a div6 clock and can be used by both CAN
+and CAN FD controller at the same time. It needs to be scaled to maximum
+frequency if any of these controllers use it. This is done using the
+below properties.
+
+- assigned-clocks: phandle of canfd clock.
+- assigned-clock-rates: maximum frequency of this clock.
+
+Example
+-------
+
+SoC common .dtsi file:
+
+		canfd: can@e66c0000 {
+			compatible = "renesas,r8a7795-canfd",
+				     "renesas,rcar-gen3-canfd";
+			reg = <0 0xe66c0000 0 0x8000>;
+			interrupts = <GIC_SPI 29 IRQ_TYPE_LEVEL_HIGH>,
+				   <GIC_SPI 30 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&cpg CPG_MOD 914>,
+			       <&cpg CPG_CORE R8A7795_CLK_CANFD>,
+			       <&can_clk>;
+			clock-names = "fck", "canfd", "can_clk";
+			assigned-clocks = <&cpg CPG_CORE R8A7795_CLK_CANFD>;
+			assigned-clock-rates = <40000000>;
+			power-domains = <&cpg>;
+			status = "disabled";
+
+			channel0 {
+				status = "disabled";
+			};
+
+			channel1 {
+				status = "disabled";
+			};
+		};
+
+Board specific .dts file:
+
+E.g. below enables Channel 1 alone in the board.
+
+&canfd {
+        pinctrl-0 = <&canfd1_pins>;
+        pinctrl-names = "default";
+        status = "okay";
+
+	channel1 {
+		status = "okay";
+	};
+};
+
+E.g. below enables Channel 0 alone in the board using External clock
+as fCAN clock.
+
+&canfd {
+        pinctrl-0 = <&canfd0_pins &can_clk_pins>;
+        pinctrl-names = "default";
+        status = "okay";
+
+	channel0 {
+		status = "okay";
+	};
+};
diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
index 0d40aef..13003a9 100644
--- a/drivers/net/can/Kconfig
+++ b/drivers/net/can/Kconfig
@@ -152,6 +152,7 @@ source "drivers/net/can/cc770/Kconfig"
 source "drivers/net/can/ifi_canfd/Kconfig"
 source "drivers/net/can/m_can/Kconfig"
 source "drivers/net/can/mscan/Kconfig"
+source "drivers/net/can/rcar/Kconfig"
 source "drivers/net/can/sja1000/Kconfig"
 source "drivers/net/can/softing/Kconfig"
 source "drivers/net/can/spi/Kconfig"
diff --git a/drivers/net/can/Makefile b/drivers/net/can/Makefile
index e3db0c8..226d5b5 100644
--- a/drivers/net/can/Makefile
+++ b/drivers/net/can/Makefile
@@ -10,6 +10,7 @@ can-dev-y			:= dev.o
 
 can-dev-$(CONFIG_CAN_LEDS)	+= led.o
 
+obj-y				+= rcar/
 obj-y				+= spi/
 obj-y				+= usb/
 obj-y				+= softing/
diff --git a/drivers/net/can/rcar/Kconfig b/drivers/net/can/rcar/Kconfig
new file mode 100644
index 0000000..6ea64d1
--- /dev/null
+++ b/drivers/net/can/rcar/Kconfig
@@ -0,0 +1,11 @@
+config CAN_RCAR_CANFD
+	tristate "Renesas R-Car CAN FD controller"
+	depends on ARCH_RENESAS || ARM
+	---help---
+	  Say Y here if you want to use CAN FD controller found on
+	  Renesas R-Car SoCs. The driver puts the controller in CAN FD only
+	  mode, which can interoperate with CAN2.0 nodes but does not support
+	  dedicated CAN 2.0 mode.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called rcar_canfd.
diff --git a/drivers/net/can/rcar/Makefile b/drivers/net/can/rcar/Makefile
new file mode 100644
index 0000000..cbaf498e
--- /dev/null
+++ b/drivers/net/can/rcar/Makefile
@@ -0,0 +1,5 @@
+#
+#  Makefile for the Renesas R-Car CAN FD controller driver
+#
+
+obj-$(CONFIG_CAN_RCAR_CANFD)	+= rcar_canfd.o
diff --git a/drivers/net/can/rcar/rcar_canfd.c b/drivers/net/can/rcar/rcar_canfd.c
new file mode 100644
index 0000000..62a7898
--- /dev/null
+++ b/drivers/net/can/rcar/rcar_canfd.c
@@ -0,0 +1,1623 @@
+/* Renesas R-Car CAN FD device driver
+ *
+ * Copyright (C) 2015 Renesas Electronics Corp.
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ */
+
+/* The R-Car CAN FD controller can operate in either one of the below two modes
+ *  - CAN FD only mode
+ *  - Classical CAN (CAN 2.0) only mode
+ *
+ * This driver puts the controller in CAN FD only mode by default. In this
+ * mode, the controller acts as a CAN FD node that can also interoperate with
+ * CAN 2.0 nodes.
+ *
+ * As of now, this driver does not support the Classical CAN (CAN 2.0) mode,
+ * which is handled by a different register map compared to CAN FD only mode.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/interrupt.h>
+#include <linux/errno.h>
+#include <linux/netdevice.h>
+#include <linux/platform_device.h>
+#include <linux/can/led.h>
+#include <linux/can/dev.h>
+#include <linux/clk.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/bitmap.h>
+#include <linux/bitops.h>
+#include <linux/iopoll.h>
+
+#define RCANFD_DRV_NAME			"rcar_canfd"
+
+#define RCANFD_FIFO_DEPTH		8	/* Tx FIFO depth */
+#define RCANFD_NAPI_WEIGHT		8	/* Rx poll quota */
+
+#define RCANFD_NUM_CHANNELS		2
+#define RCANFD_CHANNELS_MASK		0x3	/* Two channels max */
+
+/* Rx FIFO is a global resource of the controller. There are 8 such FIFOs
+ * available. Each channel gets a dedicated Rx FIFO (i.e.) the channel
+ * number is added to RFFIFO index.
+ */
+#define RCANFD_RFFIFO_IDX		0
+
+/* Tx/Rx or Common FIFO is a per channel resource. Each channel has 3 Common
+ * FIFOs dedicated to them. Use the first (index 0) FIFO out of the 3 for Tx.
+ */
+#define RCANFD_CFFIFO_IDX		0
+
+/* Global register bits */
+#define RCANFD_GINTF_CANFD		BIT(0)
+
+#define RCANFD_GCFG_TPRI		BIT(0)
+#define RCANFD_GCFG_DCE			BIT(1)
+#define RCANFD_GCFG_DCS			BIT(4)
+#define RCANFD_GCFG_CMPOC		BIT(5)
+#define RCANFD_GCFG_EEFE		BIT(6)
+
+#define RCANFD_GCTR_SLPR		BIT(2)
+#define RCANFD_GCTR_MODEMASK		(0x3)
+#define RCANFD_GCTR_GOPM		(0x0)
+#define RCANFD_GCTR_GRESET		(0x1)
+#define RCANFD_GCTR_GHLT		(0x2)
+
+#define RCANFD_GCTR_DEIE		BIT(8)
+#define RCANFD_GCTR_MEIE		BIT(9)
+#define RCANFD_GCTR_THLEIE		BIT(10)
+#define RCANFD_GCTR_CFMPOFIE		BIT(11)
+#define RCANFD_GCTR_TSRST		BIT(16)
+
+#define RCANFD_GSTS_RAMINIT		BIT(3)
+#define RCANFD_GSTS_SLP			BIT(2)
+#define RCANFD_GSTS_HLT			BIT(1)
+#define RCANFD_GSTS_RESET		BIT(0)
+
+#define RCANFD_GSTS_GNOPM		(BIT(0) | BIT(1) | BIT(2) | BIT(3))
+
+/* Channel register bits */
+#define RCANFD_CCTR_CSLPR		BIT(2)
+#define RCANFD_CCTR_MODEMASK		(0x3)
+#define RCANFD_CCTR_COPM		(0x0)
+#define RCANFD_CCTR_CRESET		(0x1)
+#define RCANFD_CCTR_CHLT		(0x2)
+#define RCANFD_CCTR_CTMASK		(0x3 << 25)
+#define RCANFD_CCTR_CTMS_ILB		(0x3 << 25)
+#define RCANFD_CCTR_CTME		BIT(24)
+#define RCANFD_CCTR_ERRD		BIT(23)
+#define RCANFD_CCTR_BOMMASK		(0x3 << 21)
+#define RCANFD_CCTR_BOM_ENTRY		(0x1 << 21)
+#define RCANFD_CCTR_TDCVFIE		BIT(19)
+#define RCANFD_CCTR_SOCOIE		BIT(18)
+#define RCANFD_CCTR_EOCOIE		BIT(17)
+#define RCANFD_CCTR_TAIE		BIT(16)
+#define RCANFD_CCTR_ALIE		BIT(15)
+#define RCANFD_CCTR_BLIE		BIT(14)
+#define RCANFD_CCTR_OLIE		BIT(13)
+#define RCANFD_CCTR_BORIE		BIT(12)
+#define RCANFD_CCTR_BOEIE		BIT(11)
+#define RCANFD_CCTR_EPIE		BIT(10)
+#define RCANFD_CCTR_EWIE		BIT(9)
+#define RCANFD_CCTR_BEIE		BIT(8)
+
+#define RCANFD_CSTS_COM			BIT(7)
+#define RCANFD_CSTS_REC			BIT(6)
+#define RCANFD_CSTS_TRM			BIT(5)
+#define RCANFD_CSTS_BO			BIT(4)
+#define RCANFD_CSTS_EP			BIT(3)
+#define RCANFD_CSTS_SLP			BIT(2)
+#define RCANFD_CSTS_HALT		BIT(1)
+#define RCANFD_CSTS_RESET		BIT(0)
+
+#define RCANFD_CSTS_TECCNT(x)		(((x) >> 24) & 0xff)
+#define RCANFD_CSTS_RECCNT(x)		(((x) >> 16) & 0xff)
+
+/* Bit Configuration register */
+#define RCANFD_BRP(x)			(((x) & 0x3ff) << 0)
+#define RCANFD_SJW(x)			(((x) & 0x3) << 24)
+#define RCANFD_TSEG1(x)			(((x) & 0xf) << 16)
+#define RCANFD_TSEG2(x)			(((x) & 0x7) << 20)
+
+#define RCANFD_NR_BRP(x)		(((x) & 0x3ff) << 0)
+#define RCANFD_NR_SJW(x)		(((x) & 0x1f) << 11)
+#define RCANFD_NR_TSEG1(x)		(((x) & 0x7f) << 16)
+#define RCANFD_NR_TSEG2(x)		(((x) & 0x1f) << 24)
+
+#define RCANFD_DR_BRP(x)		(((x) & 0xff) << 0)
+#define RCANFD_DR_SJW(x)		(((x) & 0x7) << 24)
+#define RCANFD_DR_TSEG1(x)		(((x) & 0xf) << 16)
+#define RCANFD_DR_TSEG2(x)		(((x) & 0x7) << 20)
+
+/* Global Error flag bits */
+#define RCANFD_GERFL_EEF1		BIT(17)
+#define RCANFD_GERFL_EEF0		BIT(16)
+#define RCANFD_GERFL_CMPOF		BIT(3)
+#define RCANFD_GERFL_THLES		BIT(2)
+#define RCANFD_GERFL_MES		BIT(1)
+#define RCANFD_GERFL_DEF		BIT(0)
+
+#define RCANFD_GERFL_ERR(x)		((x) & (RCANFD_GERFL_EEF1 |\
+						RCANFD_GERFL_EEF0 |\
+						RCANFD_GERFL_MES |\
+						RCANFD_GERFL_CMPOF))
+
+/* Channel Error flag bits */
+#define RCANFD_CERFL_ADEF		BIT(14)
+#define RCANFD_CERFL_B0EF		BIT(13)
+#define RCANFD_CERFL_B1EF		BIT(12)
+#define RCANFD_CERFL_CEF		BIT(11)
+#define RCANFD_CERFL_AEF		BIT(10)
+#define RCANFD_CERFL_FEF		BIT(9)
+#define RCANFD_CERFL_SEF		BIT(8)
+#define RCANFD_CERFL_ALEF		BIT(7)
+#define RCANFD_CERFL_BLEF		BIT(6)
+#define RCANFD_CERFL_OLEF		BIT(5)
+#define RCANFD_CERFL_BOREF		BIT(4)
+#define RCANFD_CERFL_BOEEF		BIT(3)
+#define RCANFD_CERFL_EPEF		BIT(2)
+#define RCANFD_CERFL_EWEF		BIT(1)
+#define RCANFD_CERFL_BEF		BIT(0)
+
+#define RCANFD_CERFL_ERR(x)		((x) & (0x7fff)) /* above bits 14:0 */
+
+/* CAN FD specific registers */
+#define RCANFD_DCFG_TDCE		BIT(9)
+#define RCANFD_DCFG_TDCOC		BIT(8)
+#define RCANFD_DCFG_TDCO(x)		(((x) & 0x7f) >> 16)
+
+#define RCANFD_DCSTS_TDCR(x)		(((x) >> 0) & 0x7f)
+#define RCANFD_DCSTS_SOCCNT(x)		(((x) >> 24) & 0xff)
+#define RCANFD_DCSTS_EOCCNT(x)		(((x) >> 16) & 0xff)
+
+#define RCANFD_DCSTS_TDCVF		BIT(7)
+#define RCANFD_DCSTS_EOCO		BIT(8)
+#define RCANFD_DCSTS_SOCO		BIT(9)
+
+/* Rx FIFO bits */
+#define RCANFD_RFFIFO_RFIF		BIT(3)
+#define RCANFD_RFFIFO_RFMLT		BIT(2)
+#define RCANFD_RFFIFO_RFFLL		BIT(1)
+#define RCANFD_RFFIFO_RFEMP		BIT(0)
+
+#define RCANFD_RFFIFO_RFESI		BIT(0)
+#define RCANFD_RFFIFO_RFBRS		BIT(1)
+#define RCANFD_RFFIFO_RFFDF		BIT(2)
+
+#define RCANFD_RFFIFO_RFIDE		BIT(31)
+#define RCANFD_RFFIFO_RFRTR		BIT(30)
+
+#define RCANFD_RFFIFO_RFDLC(x)		(((x) >> 28) & 0xf)
+#define RCANFD_RFFIFO_RFPTR(x)		(((x) >> 16) & 0xfff)
+#define RCANFD_RFFIFO_RFTS(x)		(((x) >> 0) & 0xff)
+
+#define RCANFD_RFFIFO_RFIM		BIT(12)
+#define RCANFD_RFFIFO_RFDC(x)		(((x) & 0x7) << 8)
+#define RCANFD_RFFIFO_RFPLS(x)		(((x) & 0x7) << 4)
+#define RCANFD_RFFIFO_RFIE		BIT(1)
+#define RCANFD_RFFIFO_RFE		BIT(0)
+
+/* Common FIFO bits */
+#define RCANFD_CMFIFO_TML(x)		(((x) & 0xf) << 20)
+#define RCANFD_CMFIFO_M(x)		(((x) & 0x3) << 16)
+#define RCANFD_CMFIFO_CFIM		BIT(12)
+#define RCANFD_CMFIFO_DC(x)		(((x) & 0x7) << 8)
+#define RCANFD_CMFIFO_PLS(x)		(((x) & 0x7) << 4)
+#define RCANFD_CMFIFO_CFTXIE		BIT(2)
+#define RCANFD_CMFIFO_CFE		BIT(0)
+
+#define RCANFD_CMFIFO_CFTXIF		BIT(4)
+#define RCANFD_CMFIFO_CFMLT		BIT(2)
+#define RCANFD_CMFIFO_CFFLL		BIT(1)
+#define RCANFD_CMFIFO_CFEMP		BIT(0)
+#define RCANFD_CMFIFO_CFMC(x)		(((x) >> 8) & 0xff)
+
+#define RCANFD_CMFIFO_CFESI		BIT(0)
+#define RCANFD_CMFIFO_CFBRS		BIT(1)
+#define RCANFD_CMFIFO_CFFDF		BIT(2)
+
+#define RCANFD_CMFIFO_CFIDE		BIT(31)
+#define RCANFD_CMFIFO_CFRTR		BIT(30)
+#define RCANFD_CMFIFO_CFID(x)		((x) & 0x1fffffff)
+
+#define RCANFD_CMFIFO_CFDLC(x)		(((x) & 0xf) << 28)
+#define RCANFD_CMFIFO_CFPTR(x)		(((x) & 0xfff) << 16)
+#define RCANFD_CMFIFO_CFTS(x)		(((x) & 0xff) << 0)
+
+/* Global Test Config register */
+#define RCANFD_GTSTCFG_C0CBCE		BIT(0)
+#define RCANFD_GTSTCFG_C1CBCE		BIT(1)
+
+#define RCANFD_GTSTCTR_ICBCTME		BIT(0)
+
+/* AFL Rx rules registers */
+#define RCANFD_AFLCFG_SETRNC0(x)	(((x) & 0xff) << 24)
+#define RCANFD_AFLCFG_SETRNC1(x)	(((x) & 0xff) << 16)
+#define RCANFD_AFLCFG_GETRNC0(x)	(((x) >> 24) & 0xff)
+#define RCANFD_AFLCFG_GETRNC1(x)	(((x) >> 16) & 0xff)
+
+#define RCANFD_AFL_PAGENUM(entry)	((entry) / 16)
+
+#define RCANFD_AFLCTR_AFLDAE		BIT(8)
+#define RCANFD_AFLCTR_AFLPN(x)		((x) & 0x1f)
+#define RCANFD_CHANNEL_NUMRULES		1	/* only one rule per channel */
+#define RCANFD_AFLID_GAFLLB		BIT(29)
+#define RCANFD_AFLPTR1_RFFIFO(x)	(1 << (x))
+
+/* Common register map offsets */
+
+/* Nominal rate registers */
+#define RCANFD_CCFG(m)			(0x0000 + (0x10 * (m)))
+#define RCANFD_CCTR(m)			(0x0004 + (0x10 * (m)))
+#define RCANFD_CSTS(m)			(0x0008 + (0x10 * (m)))
+#define RCANFD_CERFL(m)			(0x000C + (0x10 * (m)))
+
+/* Global registers */
+#define RCANFD_GCFG			(0x0084)
+#define RCANFD_GCTR			(0x0088)
+#define RCANFD_GSTS			(0x008c)
+#define RCANFD_GERFL			(0x0090)
+#define RCANFD_GTSC			(0x0094)
+#define RCANFD_GAFLECTR			(0x0098)
+#define RCANFD_GAFLCFG0			(0x009c)
+#define RCANFD_GAFLCFG1			(0x00a0)
+#define RCANFD_RMNB			(0x00a4)
+
+#define RCANFD_RMND(y)			(0x00a8 + (0x04 * (y)))
+
+/* Rx FIFO Control registers */
+#define RCANFD_RFCC(x)			(0x00b8 + (0x04 * (x)))
+#define RCANFD_RFSTS(x)			(0x00d8 + (0x04 * (x)))
+#define RCANFD_RFPCTR(x)		(0x00f8 + (0x04 * (x)))
+
+/* Common FIFO Control registers */
+#define RCANFD_CFCC(ch, idx)		(0x0118 + (0x0c * (ch)) + \
+					 (0x04 * (idx)))
+#define RCANFD_CFSTS(ch, idx)		(0x0178 + (0x0c * (ch)) + \
+					 (0x04 * (idx)))
+#define RCANFD_CFPCTR(ch, idx)		(0x01d8 + (0x0c * (ch)) + \
+					 (0x04 * (idx)))
+
+#define RCANFD_FESTS			(0x0238)
+#define RCANFD_FFSTS			(0x023c)
+#define RCANFD_FMSTS			(0x0240)
+#define RCANFD_RFISTS			(0x0244)
+#define RCANFD_CFRISTS			(0x0248)
+#define RCANFD_CFTISTS			(0x024c)
+
+#define RCANFD_TMC(p)			(0x0250 + (0x01 * (p)))
+#define RCANFD_TMSTS(p)			(0x02d0 + (0x01 * (p)))
+
+#define RCANFD_TMTRSTS(y)		(0x0350 + (0x04 * (y)))
+#define RCANFD_TMTARSTS(y)		(0x0360 + (0x04 * (y)))
+#define RCANFD_TMTCSTS(y)		(0x0370 + (0x04 * (y)))
+#define RCANFD_TMTASTS(y)		(0x0380 + (0x04 * (y)))
+#define RCANFD_TMIEC(y)			(0x0390 + (0x04 * (y)))
+
+#define RCANFD_TXQCC(m)			(0x03a0 + (0x04 * (m)))
+#define RCANFD_TXQSTS(m)		(0x03c0 + (0x04 * (m)))
+#define RCANFD_TXQPCTR(m)		(0x03e0 + (0x04 * (m)))
+
+#define RCANFD_THLCC(m)			(0x0400 + (0x04 * (m)))
+#define RCANFD_THLSTS(m)		(0x0420 + (0x04 * (m)))
+#define RCANFD_THLPCTR(m)		(0x0440 + (0x04 * (m)))
+
+#define RCANFD_GTINTSTS0		(0x0460)
+#define RCANFD_GTINTSTS1		(0x0464)
+#define RCANFD_GTSTCFG			(0x0468)
+#define RCANFD_GTSTCTR			(0x046c)
+#define RCANFD_GLOCKK			(0x047c)
+#define RCANFD_GRMCFG			(0x04fc)
+
+/* Receive rule registers */
+#define RCANFD_GAFLID(offset, j)	((offset) + (0x10 * (j)))
+#define RCANFD_GAFLM(offset, j)		((offset) + 0x04 + (0x10 * (j)))
+#define RCANFD_GAFLP0(offset, j)	((offset) + 0x08 + (0x10 * (j)))
+#define RCANFD_GAFLP1(offset, j)	((offset) + 0x0c + (0x10 * (j)))
+
+/* CAN FD mode specific regsiter map */
+
+/* Data bitrate registers */
+#define RCANFD_F_CDFG(m)		(0x0500 + (0x20 * (m)))
+#define RCANFD_F_CFDCFG(m)		(0x0504 + (0x20 * (m)))
+#define RCANFD_F_CFDCTR(m)		(0x0508 + (0x20 * (m)))
+#define RCANFD_F_CFDSTS(m)		(0x050c + (0x20 * (m)))
+#define RCANFD_F_CFDCRC(m)		(0x0510 + (0x20 * (m)))
+
+#define RCANFD_F_GAFL_OFFSET		(0x1000)
+
+#define RCANFD_F_RMID(q)		(0x2000 + (0x10 * (q)))
+#define RCANFD_F_RMPTR(q)		(0x2004 + (0x10 * (q)))
+#define RCANFD_F_RMFDSTS(q)		(0x2008 + (0x10 * (q)))
+#define RCANFD_F_RMDF(q, b)		(0x200c + (0x04 * (b)) + (0x20 * (q)))
+
+/* Rx FIFO data registers */
+#define RCANFD_F_RFOFFSET		(0x3000)
+#define RCANFD_F_RFID(x)		(RCANFD_F_RFOFFSET + (0x80 * (x)))
+#define RCANFD_F_RFPTR(x)		(RCANFD_F_RFOFFSET + 0x04 + \
+					 (0x80 * (x)))
+#define RCANFD_F_RFFDSTS(x)		(RCANFD_F_RFOFFSET + 0x08 + \
+					 (0x80 * (x)))
+#define RCANFD_F_RFDF(x, df)		(RCANFD_F_RFOFFSET + 0x0c + \
+					 (0x80 * (x)) + (0x04 * (df)))
+
+/* Common FIFO data registers */
+#define RCANFD_F_CFOFFSET		(0x3400)
+#define RCANFD_F_CFID(ch, idx)		(RCANFD_F_CFOFFSET + (0x180 * (ch)) + \
+					 (0x80 * (idx)))
+#define RCANFD_F_CFPTR(ch, idx)		(RCANFD_F_CFOFFSET + 0x04 + \
+					 (0x180 * (ch)) + (0x80 * (idx)))
+#define RCANFD_F_CFFDCSTS(ch, idx)	(RCANFD_F_CFOFFSET + 0x08 + \
+					 (0x180 * (ch)) + (0x80 * (idx)))
+#define RCANFD_F_CFDF(ch, idx, df)	(RCANFD_F_CFOFFSET + 0x0c + \
+					 (0x180 * (ch)) + (0x80 * (idx)) + \
+					 (0x04 * (df)))
+
+#define RCANFD_F_TMID(p)		(0x4000 + (0x20 * (p)))
+#define RCANFD_F_TMPTR(p)		(0x4004 + (0x20 * (p)))
+#define RCANFD_F_TMFDCTR(p)		(0x4008 + (0x20 * (p)))
+#define RCANFD_F_TMDF(p, b)		(0x400c + (0x20 * (p)) + (0x04 * (b)))
+
+#define RCANFD_F_THLACC(m)		(0x6000 + (0x04 * (m)))
+#define RCANFD_F_RPGACC(r)		(0x6400 + (0x04 * (r)))
+
+struct rcar_canfd_global;
+
+/* Channel priv data */
+struct rcar_canfd_channel {
+	struct can_priv can;			/* Must be the first member */
+	struct net_device *ndev;
+	struct rcar_canfd_global *gpriv;	/* Controller reference */
+	void __iomem *base;			/* Register base address */
+	struct napi_struct napi;
+	u8  tx_len[RCANFD_FIFO_DEPTH];		/* For net stats */
+	u32 tx_head;				/* Incremented on xmit */
+	u32 tx_tail;				/* Incremented on xmit done */
+	u32 channel;				/* Channel number */
+	spinlock_t tx_lock;			/* To protect tx path */
+};
+
+/* Global priv data */
+struct rcar_canfd_global {
+	struct rcar_canfd_channel *ch[RCANFD_NUM_CHANNELS];
+	void __iomem *base;		/* Register base address */
+	struct platform_device *pdev;	/* Respective platform device */
+	struct clk *clkp;		/* Peripheral clock */
+	struct clk *can_clk;		/* fCAN clock */
+	int clock_select;		/* CANFD or Ext clock */
+	unsigned long channels_mask;	/* Enabled channels mask */
+	u32 freq;			/* fCAN clock frequency in Hz */
+};
+
+/* CAN FD mode nominal rate constants */
+static const struct can_bittiming_const rcar_canfd_nom_bittiming_const = {
+	.name = RCANFD_DRV_NAME,
+	.tseg1_min = 2,
+	.tseg1_max = 128,
+	.tseg2_min = 2,
+	.tseg2_max = 32,
+	.sjw_max = 32,
+	.brp_min = 1,
+	.brp_max = 1024,
+	.brp_inc = 1,
+};
+
+/* CAN FD mode data rate constants */
+static const struct can_bittiming_const rcar_canfd_data_bittiming_const = {
+	.name = RCANFD_DRV_NAME,
+	.tseg1_min = 2,
+	.tseg1_max = 16,
+	.tseg2_min = 2,
+	.tseg2_max = 8,
+	.sjw_max = 8,
+	.brp_min = 1,
+	.brp_max = 256,
+	.brp_inc = 1,
+};
+
+/* fCAN clock select register settings */
+enum {
+	RCANFD_CANFDCLK = 0,	/* CANFD clock */
+	RCANFD_EXTCLK,		/* Externally input clock */
+};
+
+/* Helper functions */
+static inline void rcar_canfd_update(u32 mask, u32 val, u32 __iomem *reg)
+{
+	u32 data = readl(reg);
+
+	data &= ~mask;
+	data |= (val & mask);
+	writel(data, reg);
+}
+
+#define rcar_canfd_read(priv, offset)			\
+	readl(priv->base + (offset))
+#define rcar_canfd_write(priv, offset, val)		\
+	writel(val, priv->base + (offset))
+#define rcar_canfd_set_bit(priv, reg, val)		\
+	rcar_canfd_update(val, val, priv->base + (reg))
+#define rcar_canfd_clear_bit(priv, reg, val)		\
+	rcar_canfd_update(val, 0, priv->base + (reg))
+#define rcar_canfd_update_bit(priv, reg, mask, val)	\
+	rcar_canfd_update(mask, val, priv->base + (reg))
+
+static void rcar_canfd_get_data(struct canfd_frame *cf,
+				struct rcar_canfd_channel *priv, u32 off)
+{
+	u32 i, lwords;
+
+	lwords = cf->len / sizeof(u32);
+	if (cf->len % sizeof(u32))
+		lwords++;
+	for (i = 0; i < lwords; i++)
+		*((u32 *)cf->data + i) =
+			rcar_canfd_read(priv, off + (i * sizeof(u32)));
+}
+
+static void rcar_canfd_put_data(struct canfd_frame *cf,
+				struct rcar_canfd_channel *priv, u32 off)
+{
+	u32 i, j, lwords, leftover;
+	u32 data = 0;
+
+	lwords = cf->len / sizeof(u32);
+	leftover = cf->len % sizeof(u32);
+	for (i = 0; i < lwords; i++)
+		rcar_canfd_write(priv, off + (i * sizeof(u32)),
+				 *((u32 *)cf->data + i));
+
+	if (leftover) {
+		u8 *p = (u8 *)((u32 *)cf->data + i);
+
+		for (j = 0; j < leftover; j++)
+			data |= p[j] << (j * 8);
+		rcar_canfd_write(priv, off + (i * sizeof(u32)), data);
+	}
+}
+
+static void rcar_canfd_tx_failure_cleanup(struct net_device *ndev)
+{
+	u32 i;
+
+	for (i = 0; i < RCANFD_FIFO_DEPTH; i++)
+		can_free_echo_skb(ndev, i);
+}
+
+static int rcar_canfd_reset_controller(struct rcar_canfd_global *gpriv)
+{
+	u32 sts, ch;
+	int err;
+
+	/* Check RAMINIT flag as CAN RAM initialization takes place
+	 * after the MCU reset
+	 */
+	err = readl_poll_timeout((gpriv->base + RCANFD_GSTS), sts,
+				 !(sts & RCANFD_GSTS_RAMINIT), 2, 500000);
+	if (err) {
+		dev_dbg(&gpriv->pdev->dev, "global raminit failed\n");
+		return err;
+	}
+
+	/* Transition to Global Reset mode */
+	rcar_canfd_clear_bit(gpriv, RCANFD_GCTR, RCANFD_GCTR_SLPR);
+	rcar_canfd_update_bit(gpriv, RCANFD_GCTR,
+			      RCANFD_GCTR_MODEMASK, RCANFD_GCTR_GRESET);
+
+	/* Ensure Global reset mode */
+	err = readl_poll_timeout((gpriv->base + RCANFD_GSTS), sts,
+				 (sts & RCANFD_GSTS_RESET), 2, 500000);
+	if (err) {
+		dev_dbg(&gpriv->pdev->dev, "global reset failed\n");
+		return err;
+	}
+
+	/* Reset Global error flags */
+	rcar_canfd_write(gpriv, RCANFD_GERFL, 0x0);
+
+	/* Set the controller into FD mode */
+	rcar_canfd_set_bit(gpriv, RCANFD_GRMCFG, RCANFD_GINTF_CANFD);
+
+	/* Transition all Channels to reset mode */
+	for_each_set_bit(ch, &gpriv->channels_mask, RCANFD_NUM_CHANNELS) {
+		rcar_canfd_clear_bit(gpriv, RCANFD_CCTR(ch), RCANFD_CCTR_CSLPR);
+
+		rcar_canfd_update_bit(gpriv, RCANFD_CCTR(ch),
+				      RCANFD_CCTR_MODEMASK,
+				      RCANFD_CCTR_CRESET);
+
+		/* Ensure Channel reset mode */
+		err = readl_poll_timeout((gpriv->base + RCANFD_CSTS(ch)), sts,
+					 (sts & RCANFD_CSTS_RESET), 2, 500000);
+		if (err) {
+			dev_dbg(&gpriv->pdev->dev,
+				"channel %u reset failed\n", ch);
+			return err;
+		}
+	}
+	return 0;
+}
+
+static void rcar_canfd_configure_controller(struct rcar_canfd_global *gpriv)
+{
+	u32 cfg, ch;
+
+	/* Global Configuration settings */
+	cfg = RCANFD_GCFG_EEFE;		/* ECC error flag enabled */
+
+	/* Set External Clock if selected */
+	if (gpriv->clock_select != RCANFD_CANFDCLK)
+		cfg |= RCANFD_GCFG_DCS;
+
+	/* Truncate payload to configured message size RFPLS */
+	cfg |= RCANFD_GCFG_CMPOC;
+
+	rcar_canfd_set_bit(gpriv, RCANFD_GCFG, cfg);
+
+	/* Channel configuration settings */
+	for_each_set_bit(ch, &gpriv->channels_mask, RCANFD_NUM_CHANNELS) {
+		rcar_canfd_set_bit(gpriv, RCANFD_CCTR(ch), RCANFD_CCTR_ERRD);
+		rcar_canfd_update_bit(gpriv, RCANFD_CCTR(ch),
+				      RCANFD_CCTR_BOMMASK,
+				      RCANFD_CCTR_BOM_ENTRY);
+	}
+}
+
+static void rcar_canfd_configure_afl_rules(struct rcar_canfd_global *gpriv,
+					   u32 ch)
+{
+	u32 cfg;
+	int start, page, num_rules = RCANFD_CHANNEL_NUMRULES;
+	u32 ridx = ch + RCANFD_RFFIFO_IDX;
+
+	if (ch == 0) {
+		start = 0; /* Start from 0th rule */
+	} else {
+		/* Get number of existing rules and adjust */
+		cfg = rcar_canfd_read(gpriv, RCANFD_GAFLCFG0);
+		start = RCANFD_AFLCFG_GETRNC0(cfg);
+	}
+
+	/* Enable write access to entry */
+	page = RCANFD_AFL_PAGENUM(start);
+	rcar_canfd_set_bit(gpriv, RCANFD_GAFLECTR,
+			   (RCANFD_AFLCTR_AFLPN(page) | RCANFD_AFLCTR_AFLDAE));
+
+	/* Write number of rules for channel */
+	if (ch == 0)
+		rcar_canfd_set_bit(gpriv, RCANFD_GAFLCFG0,
+				   RCANFD_AFLCFG_SETRNC0(num_rules));
+	else
+		rcar_canfd_set_bit(gpriv, RCANFD_GAFLCFG0,
+				   RCANFD_AFLCFG_SETRNC1(num_rules));
+
+	/* Accept all IDs */
+	rcar_canfd_write(gpriv, RCANFD_GAFLID(RCANFD_F_GAFL_OFFSET, start), 0);
+	/* IDE or RTR is not considered for matching */
+	rcar_canfd_write(gpriv, RCANFD_GAFLM(RCANFD_F_GAFL_OFFSET, start), 0);
+	/* Any data length accepted */
+	rcar_canfd_write(gpriv, RCANFD_GAFLP0(RCANFD_F_GAFL_OFFSET, start), 0);
+	/* Place the msg in corresponding Rx FIFO entry */
+	rcar_canfd_write(gpriv, RCANFD_GAFLP1(RCANFD_F_GAFL_OFFSET, start),
+			 RCANFD_AFLPTR1_RFFIFO(ridx));
+
+	/* Disable write access to page */
+	rcar_canfd_clear_bit(gpriv, RCANFD_GAFLECTR, RCANFD_AFLCTR_AFLDAE);
+}
+
+static void rcar_canfd_configure_rx(struct rcar_canfd_global *gpriv, u32 ch)
+{
+	/* Rx FIFO is used for reception */
+	u32 cfg;
+	u16 rfdc, rfpls;
+
+	/* Select Rx FIFO based on channel */
+	u32 ridx = ch + RCANFD_RFFIFO_IDX;
+
+	rfdc = 2;		/* b010 - 8 messages Rx FIFO depth */
+	rfpls = 7;		/* b111 - Max 64 bytes payload */
+
+	cfg = (RCANFD_RFFIFO_RFIM | RCANFD_RFFIFO_RFDC(rfdc) |
+		RCANFD_RFFIFO_RFPLS(rfpls) | RCANFD_RFFIFO_RFIE);
+	rcar_canfd_write(gpriv, RCANFD_RFCC(ridx), cfg);
+}
+
+static void rcar_canfd_configure_tx(struct rcar_canfd_global *gpriv, u32 ch)
+{
+	/* Tx/Rx(Common) FIFO configured in Tx mode is
+	 * used for transmission
+	 *
+	 * Each channel has 3 Common FIFO dedicated to them.
+	 * Use the 1st (index 0) out of 3
+	 */
+	u32 cfg;
+	u16 cftml, cfm, cfdc, cfpls;
+
+	cftml = 0;		/* 0th buffer */
+	cfm = 1;		/* b01 - Transmit mode */
+	cfdc = 2;		/* b010 - 8 messages Tx FIFO depth */
+	cfpls = 7;		/* b111 - Max 64 bytes payload */
+
+	cfg = (RCANFD_CMFIFO_TML(cftml) | RCANFD_CMFIFO_M(cfm) |
+		RCANFD_CMFIFO_CFIM | RCANFD_CMFIFO_DC(cfdc) |
+		RCANFD_CMFIFO_PLS(cfpls) | RCANFD_CMFIFO_CFTXIE);
+	rcar_canfd_write(gpriv, RCANFD_CFCC(ch, RCANFD_CFFIFO_IDX), cfg);
+
+	/* Clear FD mode specific control/status register */
+	rcar_canfd_write(gpriv, RCANFD_F_CFFDCSTS(ch, RCANFD_CFFIFO_IDX), 0);
+}
+
+static void rcar_canfd_enable_global_interrupts(struct rcar_canfd_global *gpriv)
+{
+	u32 ctr;
+
+	/* Clear any stray error interrupt flags */
+	rcar_canfd_write(gpriv, RCANFD_GERFL, 0);
+
+	/* Global interrupts setup */
+	ctr = RCANFD_GCTR_MEIE;
+	ctr |= RCANFD_GCTR_CFMPOFIE;
+
+	rcar_canfd_set_bit(gpriv, RCANFD_GCTR, ctr);
+}
+
+static void rcar_canfd_disable_global_interrupts(struct rcar_canfd_global
+						 *gpriv)
+{
+	/* Disable all interrupts */
+	rcar_canfd_write(gpriv, RCANFD_GCTR, 0);
+
+	/* Clear any stray error interrupt flags */
+	rcar_canfd_write(gpriv, RCANFD_GERFL, 0);
+}
+
+static void rcar_canfd_enable_channel_interrupts(struct rcar_canfd_channel
+						 *priv)
+{
+	u32 ctr, ch = priv->channel;
+
+	/* Clear any stray error flags */
+	rcar_canfd_write(priv, RCANFD_CERFL(ch), 0);
+
+	/* Channel interrupts setup */
+	ctr = (RCANFD_CCTR_TAIE |
+	       RCANFD_CCTR_ALIE | RCANFD_CCTR_BLIE |
+	       RCANFD_CCTR_OLIE | RCANFD_CCTR_BORIE |
+	       RCANFD_CCTR_BOEIE | RCANFD_CCTR_EPIE |
+	       RCANFD_CCTR_EWIE | RCANFD_CCTR_BEIE);
+	rcar_canfd_set_bit(priv, RCANFD_CCTR(ch), ctr);
+}
+
+static void rcar_canfd_disable_channel_interrupts(struct rcar_canfd_channel
+						  *priv)
+{
+	u32 ctr, ch = priv->channel;
+
+	ctr = (RCANFD_CCTR_TAIE |
+	       RCANFD_CCTR_ALIE | RCANFD_CCTR_BLIE |
+	       RCANFD_CCTR_OLIE | RCANFD_CCTR_BORIE |
+	       RCANFD_CCTR_BOEIE | RCANFD_CCTR_EPIE |
+	       RCANFD_CCTR_EWIE | RCANFD_CCTR_BEIE);
+	rcar_canfd_clear_bit(priv, RCANFD_CCTR(ch), ctr);
+
+	/* Clear any stray error flags */
+	rcar_canfd_write(priv, RCANFD_CERFL(ch), 0);
+}
+
+static void rcar_canfd_global_error(struct net_device *ndev)
+{
+	struct rcar_canfd_channel *priv = netdev_priv(ndev);
+	struct net_device_stats *stats = &ndev->stats;
+	u32 ch = priv->channel;
+	u32 gerfl, sts;
+	u32 ridx = ch + RCANFD_RFFIFO_IDX;
+
+	gerfl = rcar_canfd_read(priv, RCANFD_GERFL);
+	if ((gerfl & RCANFD_GERFL_EEF0) && (ch == 0)) {
+		netdev_dbg(ndev, "Ch0: ECC Error flag\n");
+		stats->tx_dropped++;
+	}
+	if ((gerfl & RCANFD_GERFL_EEF1) && (ch == 1)) {
+		netdev_dbg(ndev, "Ch1: ECC Error flag\n");
+		stats->tx_dropped++;
+	}
+	if (gerfl & RCANFD_GERFL_MES) {
+		sts = rcar_canfd_read(priv,
+				      RCANFD_CFSTS(ch, RCANFD_CFFIFO_IDX));
+		if (sts & RCANFD_CMFIFO_CFMLT) {
+			netdev_dbg(ndev, "Tx Message Lost flag\n");
+			stats->tx_dropped++;
+			rcar_canfd_write(priv,
+					 RCANFD_CFSTS(ch, RCANFD_CFFIFO_IDX),
+					 sts & ~RCANFD_CMFIFO_CFMLT);
+		}
+
+		sts = rcar_canfd_read(priv, RCANFD_RFSTS(ridx));
+		if (sts & RCANFD_RFFIFO_RFMLT) {
+			netdev_dbg(ndev, "Rx Message Lost flag\n");
+			stats->rx_dropped++;
+			rcar_canfd_write(priv, RCANFD_RFSTS(ridx),
+					 sts & ~RCANFD_RFFIFO_RFMLT);
+		}
+	}
+	if (gerfl & RCANFD_GERFL_CMPOF) {
+		/* Message Lost flag will be set for respective channel
+		 * when this condition happens with counters and flags
+		 * already updated.
+		 */
+		netdev_dbg(ndev, "global payload overflow interrupt\n");
+	}
+
+	/* Clear all global error interrupts. Only affected channels bits
+	 * get cleared
+	 */
+	rcar_canfd_write(priv, RCANFD_GERFL, 0);
+}
+
+static void rcar_canfd_error(struct net_device *ndev)
+{
+	struct rcar_canfd_channel *priv = netdev_priv(ndev);
+	struct net_device_stats *stats = &ndev->stats;
+	struct can_frame *cf;
+	struct sk_buff *skb;
+	u32 cerfl, csts;
+	u32 txerr = 0, rxerr = 0;
+	u32 ch = priv->channel;
+
+	/* Propagate the error condition to the CAN stack */
+	skb = alloc_can_err_skb(ndev, &cf);
+	if (!skb) {
+		stats->rx_dropped++;
+		return;
+	}
+
+	/* Channel error interrupt */
+	cerfl = rcar_canfd_read(priv, RCANFD_CERFL(ch));
+	csts = rcar_canfd_read(priv, RCANFD_CSTS(ch));
+	txerr = RCANFD_CSTS_TECCNT(csts);
+	rxerr = RCANFD_CSTS_RECCNT(csts);
+
+	netdev_dbg(ndev, "ch erfl %x sts %x txerr %u rxerr %u\n",
+		   cerfl, csts, txerr, rxerr);
+
+	if (cerfl & RCANFD_CERFL_BEF) {
+		netdev_dbg(ndev, "Bus error\n");
+		cf->can_id |= CAN_ERR_BUSERROR | CAN_ERR_PROT;
+		cf->data[2] = CAN_ERR_PROT_UNSPEC;
+		priv->can.can_stats.bus_error++;
+	}
+	if (cerfl & RCANFD_CERFL_ADEF) {
+		netdev_dbg(ndev, "ACK Delimiter Error\n");
+		stats->tx_errors++;
+		cf->data[3] |= CAN_ERR_PROT_LOC_ACK_DEL;
+	}
+	if (cerfl & RCANFD_CERFL_B0EF) {
+		netdev_dbg(ndev, "Bit Error (dominant)\n");
+		stats->tx_errors++;
+		cf->data[2] |= CAN_ERR_PROT_BIT0;
+	}
+	if (cerfl & RCANFD_CERFL_B1EF) {
+		netdev_dbg(ndev, "Bit Error (recessive)\n");
+		stats->tx_errors++;
+		cf->data[2] |= CAN_ERR_PROT_BIT1;
+	}
+	if (cerfl & RCANFD_CERFL_CEF) {
+		netdev_dbg(ndev, "CRC Error\n");
+		stats->rx_errors++;
+		cf->data[3] |= CAN_ERR_PROT_LOC_CRC_SEQ;
+	}
+	if (cerfl & RCANFD_CERFL_AEF) {
+		netdev_dbg(ndev, "ACK Error\n");
+		stats->tx_errors++;
+		cf->can_id |= CAN_ERR_ACK;
+		cf->data[3] |= CAN_ERR_PROT_LOC_ACK;
+	}
+	if (cerfl & RCANFD_CERFL_FEF) {
+		netdev_dbg(ndev, "Form Error\n");
+		stats->rx_errors++;
+		cf->data[2] |= CAN_ERR_PROT_FORM;
+	}
+	if (cerfl & RCANFD_CERFL_SEF) {
+		netdev_dbg(ndev, "Stuff Error\n");
+		stats->rx_errors++;
+		cf->data[2] |= CAN_ERR_PROT_STUFF;
+	}
+	if (cerfl & RCANFD_CERFL_ALEF) {
+		netdev_dbg(ndev, "Arbitration lost Error\n");
+		priv->can.can_stats.arbitration_lost++;
+		cf->can_id |= CAN_ERR_LOSTARB;
+		cf->data[0] |= CAN_ERR_LOSTARB_UNSPEC;
+	}
+	if (cerfl & RCANFD_CERFL_BLEF) {
+		netdev_dbg(ndev, "Bus Lock Error\n");
+		stats->rx_errors++;
+		cf->can_id |= CAN_ERR_BUSERROR;
+	}
+	if (cerfl & RCANFD_CERFL_EWEF) {
+		netdev_dbg(ndev, "Error warning interrupt\n");
+		priv->can.state = CAN_STATE_ERROR_WARNING;
+		priv->can.can_stats.error_warning++;
+		cf->can_id |= CAN_ERR_CRTL;
+		cf->data[1] = txerr > rxerr ? CAN_ERR_CRTL_TX_WARNING :
+			CAN_ERR_CRTL_RX_WARNING;
+		cf->data[6] = txerr;
+		cf->data[7] = rxerr;
+	}
+	if (cerfl & RCANFD_CERFL_EPEF) {
+		netdev_dbg(ndev, "Error passive interrupt\n");
+		priv->can.state = CAN_STATE_ERROR_PASSIVE;
+		priv->can.can_stats.error_passive++;
+		cf->can_id |= CAN_ERR_CRTL;
+		cf->data[1] = txerr > rxerr ? CAN_ERR_CRTL_TX_PASSIVE :
+			CAN_ERR_CRTL_RX_PASSIVE;
+		cf->data[6] = txerr;
+		cf->data[7] = rxerr;
+	}
+	if (cerfl & RCANFD_CERFL_BOEEF) {
+		netdev_dbg(ndev, "Bus-off entry interrupt\n");
+		rcar_canfd_tx_failure_cleanup(ndev);
+		priv->can.state = CAN_STATE_BUS_OFF;
+		priv->can.can_stats.bus_off++;
+		can_bus_off(ndev);
+		cf->can_id |= CAN_ERR_BUSOFF;
+	}
+	if (cerfl & RCANFD_CERFL_OLEF) {
+		netdev_dbg(ndev,
+			   "Overload Frame Transmission error interrupt\n");
+		stats->tx_errors++;
+		cf->can_id |= CAN_ERR_PROT;
+		cf->data[2] |= CAN_ERR_PROT_OVERLOAD;
+	}
+
+	/* Clear all channel error interrupts */
+	rcar_canfd_write(priv, RCANFD_CERFL(ch), 0);
+	stats->rx_packets++;
+	stats->rx_bytes += cf->can_dlc;
+	netif_rx(skb);
+}
+
+static void rcar_canfd_tx_done(struct net_device *ndev)
+{
+	struct rcar_canfd_channel *priv = netdev_priv(ndev);
+	struct net_device_stats *stats = &ndev->stats;
+	u32 sts;
+	unsigned long flags;
+	u32 ch = priv->channel;
+
+	do {
+		u8 unsent, sent;
+
+		sent = priv->tx_tail % RCANFD_FIFO_DEPTH;
+		stats->tx_packets++;
+		stats->tx_bytes += priv->tx_len[sent];
+		priv->tx_len[sent] = 0;
+		can_get_echo_skb(ndev, sent);
+
+		spin_lock_irqsave(&priv->tx_lock, flags);
+		priv->tx_tail++;
+		sts = rcar_canfd_read(priv,
+				      RCANFD_CFSTS(ch, RCANFD_CFFIFO_IDX));
+		unsent = RCANFD_CMFIFO_CFMC(sts);
+
+		/* Wake producer only when there is room */
+		if (unsent != RCANFD_FIFO_DEPTH)
+			netif_wake_queue(ndev);
+
+		if (priv->tx_head - priv->tx_tail <= unsent) {
+			spin_unlock_irqrestore(&priv->tx_lock, flags);
+			break;
+		}
+		spin_unlock_irqrestore(&priv->tx_lock, flags);
+
+	} while (1);
+
+	/* Clear interrupt */
+	rcar_canfd_write(priv, RCANFD_CFSTS(ch, RCANFD_CFFIFO_IDX),
+			 sts & ~RCANFD_CMFIFO_CFTXIF);
+	can_led_event(ndev, CAN_LED_EVENT_TX);
+}
+
+static irqreturn_t rcar_canfd_global_interrupt(int irq, void *dev_id)
+{
+	struct rcar_canfd_global *gpriv = dev_id;
+	struct net_device *ndev;
+	struct rcar_canfd_channel *priv;
+	u32 sts, gerfl;
+	u32 ch, ridx;
+
+	/* Global error interrupts still indicate a condition specific
+	 * to a channel. RxFIFO interrupt is a global interrupt.
+	 */
+	for_each_set_bit(ch, &gpriv->channels_mask, RCANFD_NUM_CHANNELS) {
+		priv = gpriv->ch[ch];
+		ndev = priv->ndev;
+		ridx = ch + RCANFD_RFFIFO_IDX;
+
+		/* Global error interrupts */
+		gerfl = rcar_canfd_read(priv, RCANFD_GERFL);
+		if (RCANFD_GERFL_ERR(gerfl))
+			rcar_canfd_global_error(ndev);
+
+		/* Handle Rx interrupts */
+		sts = rcar_canfd_read(priv, RCANFD_RFSTS(ridx));
+		if (sts & RCANFD_RFFIFO_RFIF) {
+			if (napi_schedule_prep(&priv->napi)) {
+				/* Disable Rx FIFO interrupts */
+				rcar_canfd_clear_bit(priv,
+						     RCANFD_RFCC(ridx),
+						     RCANFD_RFFIFO_RFIE);
+				__napi_schedule(&priv->napi);
+			}
+		}
+	}
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t rcar_canfd_channel_interrupt(int irq, void *dev_id)
+{
+	struct rcar_canfd_global *gpriv = dev_id;
+	struct net_device *ndev;
+	struct rcar_canfd_channel *priv;
+	u32 sts, cerfl, ch;
+
+	/* Common FIFO is a per channel resource */
+	for_each_set_bit(ch, &gpriv->channels_mask, RCANFD_NUM_CHANNELS) {
+		priv = gpriv->ch[ch];
+		ndev = priv->ndev;
+
+		/* Channel error interrupts */
+		cerfl = rcar_canfd_read(priv, RCANFD_CERFL(ch));
+		if (RCANFD_CERFL_ERR(cerfl))
+			rcar_canfd_error(ndev);
+
+		/* Handle Tx interrupts */
+		sts = rcar_canfd_read(priv,
+				      RCANFD_CFSTS(ch, RCANFD_CFFIFO_IDX));
+		if (sts & RCANFD_CMFIFO_CFTXIF)
+			rcar_canfd_tx_done(ndev);
+	}
+	return IRQ_HANDLED;
+}
+
+static void rcar_canfd_set_bittiming(struct net_device *dev)
+{
+	struct rcar_canfd_channel *priv = netdev_priv(dev);
+	const struct can_bittiming *bt = &priv->can.bittiming;
+	const struct can_bittiming *dbt = &priv->can.data_bittiming;
+	u16 brp, sjw, tseg1, tseg2;
+	u32 cfg;
+	u32 ch = priv->channel;
+
+	/* Nominal bit timing settings */
+	brp = bt->brp - 1;
+	sjw = bt->sjw - 1;
+	tseg1 = bt->prop_seg + bt->phase_seg1 - 1;
+	tseg2 = bt->phase_seg2 - 1;
+
+	cfg = (RCANFD_NR_TSEG1(tseg1) | RCANFD_NR_BRP(brp) |
+	       RCANFD_NR_SJW(sjw) | RCANFD_NR_TSEG2(tseg2));
+
+	rcar_canfd_write(priv, RCANFD_CCFG(ch), cfg);
+	netdev_dbg(priv->ndev, "nrate: brp %u, sjw %u, tseg1 %u, tseg2 %u\n",
+		   brp, sjw, tseg1, tseg2);
+
+	/* Data bit timing settings */
+	brp = dbt->brp - 1;
+	sjw = dbt->sjw - 1;
+	tseg1 = dbt->prop_seg + dbt->phase_seg1 - 1;
+	tseg2 = dbt->phase_seg2 - 1;
+
+	cfg = (RCANFD_DR_TSEG1(tseg1) | RCANFD_DR_BRP(brp) |
+	       RCANFD_DR_SJW(sjw) | RCANFD_DR_TSEG2(tseg2));
+
+	rcar_canfd_write(priv, RCANFD_F_CDFG(ch), cfg);
+	netdev_dbg(priv->ndev, "drate: brp %u, sjw %u, tseg1 %u, tseg2 %u\n",
+		   brp, sjw, tseg1, tseg2);
+}
+
+static int rcar_canfd_start(struct net_device *ndev)
+{
+	struct rcar_canfd_channel *priv = netdev_priv(ndev);
+	int err = -EOPNOTSUPP;
+	u32 sts, ch = priv->channel;
+	u32 ridx = ch + RCANFD_RFFIFO_IDX;
+
+	rcar_canfd_set_bittiming(ndev);
+
+	rcar_canfd_enable_channel_interrupts(priv);
+
+	/* Set channel to Operational mode */
+	rcar_canfd_update_bit(priv, RCANFD_CCTR(ch),
+			      RCANFD_CCTR_MODEMASK, RCANFD_CCTR_COPM);
+
+	/* Verify channel mode change */
+	err = readl_poll_timeout((priv->base + RCANFD_CSTS(ch)), sts,
+				 (sts & RCANFD_CSTS_COM), 2, 500000);
+	if (err) {
+		netdev_err(ndev, "channel %u communication state failed\n", ch);
+		goto fail_mode_change;
+	}
+
+	/* Enable Common & Rx FIFO */
+	rcar_canfd_set_bit(priv, RCANFD_CFCC(ch, RCANFD_CFFIFO_IDX),
+			   RCANFD_CMFIFO_CFE);
+	rcar_canfd_set_bit(priv, RCANFD_RFCC(ridx), RCANFD_RFFIFO_RFE);
+
+	priv->can.state = CAN_STATE_ERROR_ACTIVE;
+	return 0;
+
+fail_mode_change:
+	rcar_canfd_disable_channel_interrupts(priv);
+	return err;
+}
+
+static int rcar_canfd_open(struct net_device *ndev)
+{
+	struct rcar_canfd_channel *priv = netdev_priv(ndev);
+	struct rcar_canfd_global *gpriv = priv->gpriv;
+	int err;
+
+	/* Peripheral clock is already enabled in probe */
+	err = clk_prepare_enable(gpriv->can_clk);
+	if (err) {
+		netdev_err(ndev, "failed to enable CAN clock, error %d\n", err);
+		goto out_clock;
+	}
+
+	err = open_candev(ndev);
+	if (err) {
+		netdev_err(ndev, "open_candev() failed, error %d\n", err);
+		goto out_can_clock;
+	}
+
+	napi_enable(&priv->napi);
+	err = rcar_canfd_start(ndev);
+	if (err)
+		goto out_close;
+	netif_start_queue(ndev);
+	can_led_event(ndev, CAN_LED_EVENT_OPEN);
+	return 0;
+out_close:
+	napi_disable(&priv->napi);
+	close_candev(ndev);
+out_can_clock:
+	clk_disable_unprepare(gpriv->can_clk);
+out_clock:
+	return err;
+}
+
+static void rcar_canfd_stop(struct net_device *ndev)
+{
+	struct rcar_canfd_channel *priv = netdev_priv(ndev);
+	int err;
+	u32 sts, ch = priv->channel;
+	u32 ridx = ch + RCANFD_RFFIFO_IDX;
+
+	/* Transition to channel reset mode  */
+	rcar_canfd_update_bit(priv, RCANFD_CCTR(ch),
+			      RCANFD_CCTR_MODEMASK, RCANFD_CCTR_CRESET);
+
+	/* Check Channel reset mode */
+	err = readl_poll_timeout((priv->base + RCANFD_CSTS(ch)), sts,
+				 (sts & RCANFD_CSTS_RESET), 2, 500000);
+	if (err)
+		netdev_err(ndev, "channel %u reset failed\n", ch);
+
+	rcar_canfd_disable_channel_interrupts(priv);
+
+	/* Disable Common & Rx FIFO */
+	rcar_canfd_clear_bit(priv, RCANFD_CFCC(ch, RCANFD_CFFIFO_IDX),
+			     RCANFD_CMFIFO_CFE);
+	rcar_canfd_clear_bit(priv, RCANFD_RFCC(ridx), RCANFD_RFFIFO_RFE);
+
+	/* Set the state as STOPPED */
+	priv->can.state = CAN_STATE_STOPPED;
+}
+
+static int rcar_canfd_close(struct net_device *ndev)
+{
+	struct rcar_canfd_channel *priv = netdev_priv(ndev);
+	struct rcar_canfd_global *gpriv = priv->gpriv;
+
+	netif_stop_queue(ndev);
+	rcar_canfd_stop(ndev);
+	napi_disable(&priv->napi);
+	clk_disable_unprepare(gpriv->can_clk);
+	close_candev(ndev);
+	can_led_event(ndev, CAN_LED_EVENT_STOP);
+	return 0;
+}
+
+static netdev_tx_t rcar_canfd_start_xmit(struct sk_buff *skb,
+					 struct net_device *ndev)
+{
+	struct rcar_canfd_channel *priv = netdev_priv(ndev);
+	struct canfd_frame *cf = (struct canfd_frame *)skb->data;
+	u32 sts, id, ptr;
+	unsigned long flags;
+	u32 ch = priv->channel;
+
+	if (can_dropped_invalid_skb(ndev, skb))
+		return NETDEV_TX_OK;
+
+	if (cf->can_id & CAN_EFF_FLAG) {
+		id = cf->can_id & CAN_EFF_MASK;
+		id |= RCANFD_CMFIFO_CFIDE;
+	} else {
+		id = cf->can_id & CAN_SFF_MASK;
+	}
+
+	if (cf->can_id & CAN_RTR_FLAG)
+		id |= RCANFD_CMFIFO_CFRTR;
+
+	rcar_canfd_write(priv, RCANFD_F_CFID(ch, RCANFD_CFFIFO_IDX),
+			 id);
+	ptr = RCANFD_CMFIFO_CFDLC(can_len2dlc(cf->len));
+	rcar_canfd_write(priv, RCANFD_F_CFPTR(ch, RCANFD_CFFIFO_IDX),
+			 ptr);
+
+	sts = rcar_canfd_read(priv, RCANFD_F_CFFDCSTS(ch, RCANFD_CFFIFO_IDX));
+	if (can_is_canfd_skb(skb)) {
+		/* CAN FD frame format */
+		sts |= RCANFD_CMFIFO_CFFDF;
+		if (cf->flags & CANFD_BRS)
+			sts |= RCANFD_CMFIFO_CFBRS;
+		else
+			sts &= ~RCANFD_CMFIFO_CFBRS;
+	} else {
+		sts &= ~RCANFD_CMFIFO_CFFDF;
+	}
+	rcar_canfd_write(priv, RCANFD_F_CFFDCSTS(ch, RCANFD_CFFIFO_IDX), sts);
+
+	rcar_canfd_put_data(cf, priv,
+			    RCANFD_F_CFDF(ch, RCANFD_CFFIFO_IDX, 0));
+
+	priv->tx_len[priv->tx_head % RCANFD_FIFO_DEPTH] = cf->len;
+	can_put_echo_skb(skb, ndev, priv->tx_head % RCANFD_FIFO_DEPTH);
+
+	spin_lock_irqsave(&priv->tx_lock, flags);
+	priv->tx_head++;
+
+	/* Start Tx: Write 0xff to CFPC to increment the CPU-side
+	 * pointer for the Common FIFO
+	 */
+	rcar_canfd_write(priv, RCANFD_CFPCTR(ch, RCANFD_CFFIFO_IDX), 0xff);
+
+	/* Stop the queue if we've filled all FIFO entries */
+	if (priv->tx_head - priv->tx_tail >= RCANFD_FIFO_DEPTH)
+		netif_stop_queue(ndev);
+
+	spin_unlock_irqrestore(&priv->tx_lock, flags);
+	return NETDEV_TX_OK;
+}
+
+static void rcar_canfd_rx_pkt(struct rcar_canfd_channel *priv)
+{
+	struct net_device_stats *stats = &priv->ndev->stats;
+	struct canfd_frame *cf;
+	struct sk_buff *skb;
+	u32 sts = 0, id, ptr;
+	u32 ch = priv->channel;
+	u32 ridx = ch + RCANFD_RFFIFO_IDX;
+
+	id = rcar_canfd_read(priv, RCANFD_F_RFID(ridx));
+	ptr = rcar_canfd_read(priv, RCANFD_F_RFPTR(ridx));
+
+	sts = rcar_canfd_read(priv, RCANFD_F_RFFDSTS(ridx));
+	if (sts & RCANFD_RFFIFO_RFFDF)
+		skb = alloc_canfd_skb(priv->ndev, &cf);
+	else
+		skb = alloc_can_skb(priv->ndev,
+				    (struct can_frame **)&cf);
+
+	if (!skb) {
+		stats->rx_dropped++;
+		return;
+	}
+
+	if (sts & RCANFD_RFFIFO_RFFDF)
+		cf->len = can_dlc2len(RCANFD_RFFIFO_RFDLC(ptr));
+	else
+		cf->len = get_can_dlc(RCANFD_RFFIFO_RFDLC(ptr));
+
+	if (sts & RCANFD_RFFIFO_RFESI) {
+		cf->flags |= CANFD_ESI;
+		netdev_dbg(priv->ndev, "ESI Error\n");
+	}
+
+	if (id & RCANFD_RFFIFO_RFIDE)
+		cf->can_id = (id & CAN_EFF_MASK) | CAN_EFF_FLAG;
+	else
+		cf->can_id = id & CAN_SFF_MASK;
+
+	if (!(sts & RCANFD_RFFIFO_RFFDF) && (id & RCANFD_RFFIFO_RFRTR)) {
+		cf->can_id |= CAN_RTR_FLAG;
+	} else {
+		if (sts & RCANFD_RFFIFO_RFBRS)
+			cf->flags |= CANFD_BRS;
+
+		rcar_canfd_get_data(cf, priv, RCANFD_F_RFDF(ridx, 0));
+	}
+
+	/* Write 0xff to RFPC to increment the CPU-side
+	 * pointer of the Rx FIFO
+	 */
+	rcar_canfd_write(priv, RCANFD_RFPCTR(ridx), 0xff);
+
+	can_led_event(priv->ndev, CAN_LED_EVENT_RX);
+
+	stats->rx_bytes += cf->len;
+	stats->rx_packets++;
+	netif_receive_skb(skb);
+}
+
+static int rcar_canfd_rx_poll(struct napi_struct *napi, int quota)
+{
+	struct rcar_canfd_channel *priv =
+		container_of(napi, struct rcar_canfd_channel, napi);
+	int num_pkts;
+	u32 sts;
+	u32 ch = priv->channel;
+	u32 ridx = ch + RCANFD_RFFIFO_IDX;
+
+	for (num_pkts = 0; num_pkts < quota; num_pkts++) {
+		sts = rcar_canfd_read(priv, RCANFD_RFSTS(ridx));
+		/* Clear interrupt bit */
+		if (sts & RCANFD_RFFIFO_RFIF)
+			rcar_canfd_write(priv, RCANFD_RFSTS(ridx),
+					 sts & ~RCANFD_RFFIFO_RFIF);
+
+		/* Check FIFO empty condition */
+		if (sts & RCANFD_RFFIFO_RFEMP)
+			break;
+
+		rcar_canfd_rx_pkt(priv);
+	}
+
+	/* All packets processed */
+	if (num_pkts < quota) {
+		napi_complete(napi);
+		/* Enable Rx FIFO interrupts */
+		rcar_canfd_set_bit(priv, RCANFD_RFCC(ridx), RCANFD_RFFIFO_RFIE);
+	}
+	return num_pkts;
+}
+
+static int rcar_canfd_do_set_mode(struct net_device *ndev, enum can_mode mode)
+{
+	int err;
+
+	switch (mode) {
+	case CAN_MODE_START:
+		err = rcar_canfd_start(ndev);
+		if (err)
+			return err;
+		netif_wake_queue(ndev);
+		return 0;
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static int rcar_canfd_get_berr_counter(const struct net_device *dev,
+				       struct can_berr_counter *bec)
+{
+	struct rcar_canfd_channel *priv = netdev_priv(dev);
+	u32 val, ch = priv->channel;
+
+	/* Peripheral clock is already enabled in probe */
+	val = rcar_canfd_read(priv, RCANFD_CSTS(ch));
+	bec->txerr = RCANFD_CSTS_TECCNT(val);
+	bec->rxerr = RCANFD_CSTS_RECCNT(val);
+	return 0;
+}
+
+static const struct net_device_ops rcar_canfd_netdev_ops = {
+	.ndo_open = rcar_canfd_open,
+	.ndo_stop = rcar_canfd_close,
+	.ndo_start_xmit = rcar_canfd_start_xmit,
+	.ndo_change_mtu = can_change_mtu,
+};
+
+static int rcar_canfd_channel_probe(struct rcar_canfd_global *gpriv, u32 ch)
+{
+	struct platform_device *pdev = gpriv->pdev;
+	struct rcar_canfd_channel *priv;
+	struct net_device *ndev;
+	int err = -ENODEV;
+
+	ndev = alloc_candev(sizeof(*priv), RCANFD_FIFO_DEPTH);
+	if (!ndev) {
+		dev_err(&pdev->dev, "alloc_candev() failed\n");
+		err = -ENOMEM;
+		goto fail;
+	}
+	priv = netdev_priv(ndev);
+
+	ndev->netdev_ops = &rcar_canfd_netdev_ops;
+	ndev->flags |= IFF_ECHO;
+	priv->ndev = ndev;
+	priv->base = gpriv->base;
+	priv->channel = ch;
+	priv->can.clock.freq = gpriv->freq;
+	dev_info(&pdev->dev, "can_clk rate is %u\n", priv->can.clock.freq);
+
+	priv->can.bittiming_const = &rcar_canfd_nom_bittiming_const;
+	priv->can.data_bittiming_const =
+		&rcar_canfd_data_bittiming_const;
+
+	/* Controller starts in CAN FD only mode */
+	can_set_static_ctrlmode(ndev, CAN_CTRLMODE_FD);
+	priv->can.ctrlmode_supported = CAN_CTRLMODE_BERR_REPORTING;
+
+	priv->can.do_set_mode = rcar_canfd_do_set_mode;
+	priv->can.do_get_berr_counter = rcar_canfd_get_berr_counter;
+	priv->gpriv = gpriv;
+	SET_NETDEV_DEV(ndev, &pdev->dev);
+
+	netif_napi_add(ndev, &priv->napi, rcar_canfd_rx_poll,
+		       RCANFD_NAPI_WEIGHT);
+	err = register_candev(ndev);
+	if (err) {
+		dev_err(&pdev->dev,
+			"register_candev() failed, error %d\n", err);
+		goto fail_candev;
+	}
+	spin_lock_init(&priv->tx_lock);
+	devm_can_led_init(ndev);
+	gpriv->ch[priv->channel] = priv;
+	dev_info(&pdev->dev, "device registered (channel %u)\n", priv->channel);
+	return 0;
+
+fail_candev:
+	netif_napi_del(&priv->napi);
+	free_candev(ndev);
+fail:
+	return err;
+}
+
+static void rcar_canfd_channel_remove(struct rcar_canfd_global *gpriv, u32 ch)
+{
+	struct rcar_canfd_channel *priv = gpriv->ch[ch];
+
+	if (priv) {
+		unregister_candev(priv->ndev);
+		netif_napi_del(&priv->napi);
+		free_candev(priv->ndev);
+	}
+}
+
+static int rcar_canfd_probe(struct platform_device *pdev)
+{
+	struct resource *mem;
+	void __iomem *addr;
+	u32 sts, ch;
+	struct rcar_canfd_global *gpriv;
+	struct device_node *of_child;
+	unsigned long channels_mask = 0;
+	int err, ch_irq, g_irq;
+
+	of_child = of_get_child_by_name(pdev->dev.of_node, "channel0");
+	if (of_child && of_device_is_available(of_child))
+		channels_mask |= BIT(0);	/* Channel 0 */
+
+	of_child = of_get_child_by_name(pdev->dev.of_node, "channel1");
+	if (of_child && of_device_is_available(of_child))
+		channels_mask |= BIT(1);	/* Channel 1 */
+
+	ch_irq = platform_get_irq(pdev, 0);
+	if (ch_irq < 0) {
+		dev_err(&pdev->dev, "no Channel IRQ resource\n");
+		err = ch_irq;
+		goto fail_dev;
+	}
+
+	g_irq = platform_get_irq(pdev, 1);
+	if (g_irq < 0) {
+		dev_err(&pdev->dev, "no Global IRQ resource\n");
+		err = g_irq;
+		goto fail_dev;
+	}
+
+	/* Global controller context */
+	gpriv = devm_kzalloc(&pdev->dev, sizeof(*gpriv), GFP_KERNEL);
+	if (!gpriv) {
+		err = -ENOMEM;
+		goto fail_dev;
+	}
+	gpriv->pdev = pdev;
+	gpriv->channels_mask = channels_mask;
+
+	/* Peripheral clock */
+	gpriv->clkp = devm_clk_get(&pdev->dev, "fck");
+	if (IS_ERR(gpriv->clkp)) {
+		err = PTR_ERR(gpriv->clkp);
+		dev_err(&pdev->dev, "cannot get peripheral clock, error %d\n",
+			err);
+		goto fail_dev;
+	}
+
+	/* fCAN clock: Pick External clock. If not available fallback to
+	 * CANFD clock
+	 */
+	gpriv->can_clk = devm_clk_get(&pdev->dev, "can_clk");
+	if (IS_ERR(gpriv->can_clk)) {
+		gpriv->can_clk = devm_clk_get(&pdev->dev, "canfd");
+		if (IS_ERR(gpriv->can_clk)) {
+			err = PTR_ERR(gpriv->can_clk);
+			dev_err(&pdev->dev,
+				"cannot get canfd clock, error %d\n", err);
+			goto fail_dev;
+		}
+		gpriv->clock_select = RCANFD_CANFDCLK;
+
+	} else {
+		gpriv->clock_select = RCANFD_EXTCLK;
+	}
+	gpriv->freq = clk_get_rate(gpriv->can_clk);
+
+	if (gpriv->clock_select == RCANFD_CANFDCLK)
+		/* CANFD clock is further divided by (1/2) within the IP */
+		gpriv->freq /= 2;
+
+	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	addr = devm_ioremap_resource(&pdev->dev, mem);
+	if (IS_ERR(addr)) {
+		err = PTR_ERR(addr);
+		goto fail_dev;
+	}
+	gpriv->base = addr;
+
+	/* Request IRQ that's common for both channels */
+	err = devm_request_irq(&pdev->dev, ch_irq,
+			       rcar_canfd_channel_interrupt, 0,
+			       "canfd.chn", gpriv);
+	if (err) {
+		dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n",
+			ch_irq, err);
+		goto fail_dev;
+	}
+	err = devm_request_irq(&pdev->dev, g_irq,
+			       rcar_canfd_global_interrupt, 0,
+			       "canfd.gbl", gpriv);
+	if (err) {
+		dev_err(&pdev->dev, "devm_request_irq(%d) failed, error %d\n",
+			g_irq, err);
+		goto fail_dev;
+	}
+
+	/* Enable peripheral clock for register access */
+	err = clk_prepare_enable(gpriv->clkp);
+	if (err) {
+		dev_err(&pdev->dev,
+			"failed to enable peripheral clock, error %d\n", err);
+		goto fail_dev;
+	}
+
+	err = rcar_canfd_reset_controller(gpriv);
+	if (err) {
+		dev_err(&pdev->dev, "reset controller failed\n");
+		goto fail_clk;
+	}
+
+	/* Controller in Global reset & Channel reset mode */
+	rcar_canfd_configure_controller(gpriv);
+
+	/* Configure per channel attributes */
+	for_each_set_bit(ch, &gpriv->channels_mask, RCANFD_NUM_CHANNELS) {
+		/* Configure Channel's Rx fifo */
+		rcar_canfd_configure_rx(gpriv, ch);
+
+		/* Configure Channel's Tx (Common) fifo */
+		rcar_canfd_configure_tx(gpriv, ch);
+
+		/* Configure receive rules */
+		rcar_canfd_configure_afl_rules(gpriv, ch);
+	}
+
+	/* Configure common interrupts */
+	rcar_canfd_enable_global_interrupts(gpriv);
+
+	/* Start Global operation mode */
+	rcar_canfd_update_bit(gpriv, RCANFD_GCTR, RCANFD_GCTR_MODEMASK,
+			      RCANFD_GCTR_GOPM);
+
+	/* Verify mode change */
+	err = readl_poll_timeout((gpriv->base + RCANFD_GSTS), sts,
+				 !(sts & RCANFD_GSTS_GNOPM), 2, 500000);
+	if (err) {
+		dev_err(&pdev->dev, "global operational mode failed\n");
+		goto fail_mode;
+	}
+
+	for_each_set_bit(ch, &gpriv->channels_mask, RCANFD_NUM_CHANNELS) {
+		err = rcar_canfd_channel_probe(gpriv, ch);
+		if (err)
+			goto fail_channel;
+	}
+
+	platform_set_drvdata(pdev, gpriv);
+	dev_info(&pdev->dev, "global operational state (clk %d)\n",
+		 gpriv->clock_select);
+	return 0;
+
+fail_channel:
+	for_each_set_bit(ch, &gpriv->channels_mask, RCANFD_NUM_CHANNELS)
+		rcar_canfd_channel_remove(gpriv, ch);
+fail_mode:
+	rcar_canfd_disable_global_interrupts(gpriv);
+fail_clk:
+	clk_disable_unprepare(gpriv->clkp);
+fail_dev:
+	return err;
+}
+
+static int rcar_canfd_remove(struct platform_device *pdev)
+{
+	struct rcar_canfd_global *gpriv = platform_get_drvdata(pdev);
+	struct rcar_canfd_channel *priv;
+	u32 ch;
+
+	rcar_canfd_reset_controller(gpriv);
+	rcar_canfd_disable_global_interrupts(gpriv);
+
+	for_each_set_bit(ch, &gpriv->channels_mask, RCANFD_NUM_CHANNELS) {
+		priv = gpriv->ch[ch];
+		if (priv) {
+			rcar_canfd_disable_channel_interrupts(priv);
+			unregister_candev(priv->ndev);
+			netif_napi_del(&priv->napi);
+			free_candev(priv->ndev);
+		}
+	}
+
+	/* Enter global sleep mode */
+	rcar_canfd_set_bit(gpriv, RCANFD_GCTR, RCANFD_GCTR_SLPR);
+	clk_disable_unprepare(gpriv->clkp);
+	return 0;
+}
+
+static int __maybe_unused rcar_canfd_suspend(struct device *dev)
+{
+	return 0;
+}
+
+static int __maybe_unused rcar_canfd_resume(struct device *dev)
+{
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(rcar_canfd_pm_ops, rcar_canfd_suspend,
+			 rcar_canfd_resume);
+
+static const struct of_device_id rcar_canfd_of_table[] = {
+	{ .compatible = "renesas,rcar-gen3-canfd" },
+	{ }
+};
+
+MODULE_DEVICE_TABLE(of, rcar_canfd_of_table);
+
+static struct platform_driver rcar_canfd_driver = {
+	.driver = {
+		.name = RCANFD_DRV_NAME,
+		.of_match_table = of_match_ptr(rcar_canfd_of_table),
+		.pm = &rcar_canfd_pm_ops,
+	},
+	.probe = rcar_canfd_probe,
+	.remove = rcar_canfd_remove,
+};
+
+module_platform_driver(rcar_canfd_driver);
+
+MODULE_AUTHOR("Ramesh Shanmugasundaram <ramesh.shanmugasundaram@bp.renesas.com>");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("CAN FD driver for Renesas R-Car SoC");
+MODULE_ALIAS("platform:" RCANFD_DRV_NAME);
-- 
1.9.1

^ permalink raw reply related

* [PATCH net v2] vxlan: fix too large pskb_may_pull with remote checksum
From: Jiri Benc @ 2016-03-21 16:50 UTC (permalink / raw)
  To: netdev; +Cc: Tom Herbert

vxlan_remcsum is called after iptunnel_pull_header and thus the skb has
vxlan header already pulled. Don't include vxlan header again in the
calculation.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
---
v2: Changed wording of the patch description to explain where the header is
    pulled.
---
 drivers/net/vxlan.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index 7bfcb9a62a5d..1c0fa364323e 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -1143,7 +1143,7 @@ static int vxlan_igmp_leave(struct vxlan_dev *vxlan)
 static bool vxlan_remcsum(struct vxlanhdr *unparsed,
 			  struct sk_buff *skb, u32 vxflags)
 {
-	size_t start, offset, plen;
+	size_t start, offset;
 
 	if (!(unparsed->vx_flags & VXLAN_HF_RCO) || skb->remcsum_offload)
 		goto out;
@@ -1151,9 +1151,7 @@ static bool vxlan_remcsum(struct vxlanhdr *unparsed,
 	start = vxlan_rco_start(unparsed->vx_vni);
 	offset = start + vxlan_rco_offset(unparsed->vx_vni);
 
-	plen = sizeof(struct vxlanhdr) + offset + sizeof(u16);
-
-	if (!pskb_may_pull(skb, plen))
+	if (!pskb_may_pull(skb, offset + sizeof(u16)))
 		return false;
 
 	skb_remcsum_process(skb, (void *)(vxlan_hdr(skb) + 1), start, offset,
-- 
1.8.3.1

^ permalink raw reply related

* [PATCH v4 0/2] Add CAN FD driver support to r8a7795 SoC
From: Ramesh Shanmugasundaram @ 2016-03-21 16:45 UTC (permalink / raw)
  To: mkl, wg, socketcan, robh+dt, pawel.moll, mark.rutland,
	ijc+devicetree, galak
  Cc: linux-renesas-soc, devicetree, linux-can, netdev, chris.paterson2,
	Ramesh Shanmugasundaram
In-Reply-To: <1458035294-8150-1-git-send-email-ramesh.shanmugasundaram@bp.renesas.com>

Hi All,

   Thanks for the review comments.

   This patch is based on linux-can-next tag (linux-can-next-for-4.6-20160310)

   This patch depends on

   [RFC] [PATCH v4] can: fix handling of unmodifiable configuration options
   (http://permalink.gmane.org/gmane.linux.can/9148)

Changes since v3:
	* Split v3 patch into two (Marc K)
	  (1) Introduce rcar_canfd.c driver in drivers/net/can/rcar dir
	  (2) Move rcar_can.c driver to new drivers/net/can/rcar dir
	* Added Acked-by Rob H for the bindings
	* Added comments on CAN FD only mode in driver & Kconfig (Oliver H)

Changes since v2:
	* Rebased to latest tag (linux-can-next-for-4.6-20160310)
	* Cleaned up leftover debugfs code (Thanks Oliver H)
	* Revised devicetree documentation text (as suggested by Rob H)
	  (https://www.mail-archive.com/linux-renesas-soc@vger.kernel.org/msg01597.html)
	* Used new can subsystem api to set static configuration & removed check in rcar_canfd_start (as suggested by Oliver H)
	  (Refer: http://comments.gmane.org/gmane.linux.can/9126 &
	   https://www.mail-archive.com/linux-renesas-soc@vger.kernel.org/msg01867.html)
	* Clubbed Renesas controller drivers to driver/net/can/rcar dir (as suggested by Oliver H)
	* Updated commit message

Changes since v1:
	* Removed testmodes & debugfs code (suggested by Oliver H)
	* Fixed tx path race issue by introducing lock (suggested by Marc K)
	* Removed __maybe_unused attribute of rcar_canfd_of_table


Ramesh Shanmugasundaram (2):
  can: rcar_canfd: Add Renesas R-Car CAN FD driver
  can: rcar_can: Move Renesas CAN driver to rcar dir

 .../devicetree/bindings/net/can/rcar_canfd.txt     |   89 ++
 drivers/net/can/Kconfig                            |   11 +-
 drivers/net/can/Makefile                           |    2 +-
 drivers/net/can/rcar/Kconfig                       |   21 +
 drivers/net/can/rcar/Makefile                      |    6 +
 drivers/net/can/{ => rcar}/rcar_can.c              |    0
 drivers/net/can/rcar/rcar_canfd.c                  | 1623 ++++++++++++++++++++
 7 files changed, 1741 insertions(+), 11 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/can/rcar_canfd.txt
 create mode 100644 drivers/net/can/rcar/Kconfig
 create mode 100644 drivers/net/can/rcar/Makefile
 rename drivers/net/can/{ => rcar}/rcar_can.c (100%)
 create mode 100644 drivers/net/can/rcar/rcar_canfd.c

-- 
1.9.1

^ permalink raw reply

* [PATCH net] vxlan: fix sparse warnings
From: Jiri Benc @ 2016-03-21 16:39 UTC (permalink / raw)
  To: netdev; +Cc: kbuild test robot

Sparse reports false positives for the header manipulation inlines. Annotate
them correctly.

Tested by sparse on a little endian and big endian machine.

Fixes: 54bfd872bf16d ("vxlan: keep flags and vni in network byte order")
Reported-by: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: Jiri Benc <jbenc@redhat.com>
---
As a side note, I tried to simplify all of these functions by using nested
be32_to_cpu(cpu_to_be32()) calls but GCC seems not to be clever enough to
optimize the byteswaps out.
---
 include/net/vxlan.h | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/net/vxlan.h b/include/net/vxlan.h
index a763c96ecde4..73ed2e951c02 100644
--- a/include/net/vxlan.h
+++ b/include/net/vxlan.h
@@ -271,36 +271,36 @@ static inline struct vxlanhdr *vxlan_hdr(struct sk_buff *skb)
 static inline __be32 vxlan_vni(__be32 vni_field)
 {
 #if defined(__BIG_ENDIAN)
-	return vni_field >> 8;
+	return (__force __be32)((__force u32)vni_field >> 8);
 #else
-	return (vni_field & VXLAN_VNI_MASK) << 8;
+	return (__force __be32)((__force u32)(vni_field & VXLAN_VNI_MASK) << 8);
 #endif
 }
 
 static inline __be32 vxlan_vni_field(__be32 vni)
 {
 #if defined(__BIG_ENDIAN)
-	return vni << 8;
+	return (__force __be32)((__force u32)vni << 8);
 #else
-	return vni >> 8;
+	return (__force __be32)((__force u32)vni >> 8);
 #endif
 }
 
 static inline __be32 vxlan_tun_id_to_vni(__be64 tun_id)
 {
 #if defined(__BIG_ENDIAN)
-	return tun_id;
+	return (__force __be32)tun_id;
 #else
-	return tun_id >> 32;
+	return (__force __be32)((__force u64)tun_id >> 32);
 #endif
 }
 
 static inline __be64 vxlan_vni_to_tun_id(__be32 vni)
 {
 #if defined(__BIG_ENDIAN)
-	return (__be64)vni;
+	return (__force __be64)vni;
 #else
-	return (__be64)vni << 32;
+	return (__force __be64)((u64)(__force u32)vni << 32);
 #endif
 }
 
-- 
1.8.3.1

^ permalink raw reply related

* [PATCH] net: add description for len argument of dev_get_phys_port_name
From: Luis de Bethencourt @ 2016-03-21 16:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: davem, edumazet, jiri, ast, daniel, jarod, tom, makita.toshiaki,
	ja, netdev, Luis de Bethencourt

When the function dev_get_phys_port_name was added it missed a description
for it's len argument. Adding it.

Fixes: db24a9044ee1 ("net: add support for phys_port_name")
Signed-off-by: Luis de Bethencourt <luisbg@osg.samsung.com>
---
Hi,

Noticed this when running make htmldocs. It gives the following warning:
.//net/core/dev.c:6453: warning: No description found for parameter 'len'

Thanks,
Luis

 net/core/dev.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/core/dev.c b/net/core/dev.c
index 43c74ca..b9bcbe7 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -6445,6 +6445,7 @@ EXPORT_SYMBOL(dev_get_phys_port_id);
  *	dev_get_phys_port_name - Get device physical port name
  *	@dev: device
  *	@name: port name
+ *	@len: limit of bytes to copy to name
  *
  *	Get device physical port name
  */
-- 
2.6.4

^ permalink raw reply related

* Re: [PATCH net] ipv4: fix broadcast packets reception
From: Paolo Abeni @ 2016-03-21 16:12 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, kuznet, sbohrer, hannes
In-Reply-To: <20160321.115009.1222014596215287583.davem@davemloft.net>

On Mon, 2016-03-21 at 11:50 -0400, David Miller wrote:
> From: Paolo Abeni <pabeni@redhat.com>
> Date: Mon, 21 Mar 2016 16:42:11 +0100
> 
> > Currently, ingress ipv4 broadcast datagrams are dropped if the
> > ingress interface lacks an ipv4 address. This is caused by
> > multiple issues:
> > 
> > - in udp_v4_early_demux() ip_check_mc_rcu is invoked even on
> >   bcast packets
> > 
> > - ip_route_input_slow() always try to validate the source
> > 
> > This patch tries to address both issues, invoking ip_check_mc_rcu()
> > only for mcast packets and calling fib_validate_source() only
> > if the in_device has an address, at least.
> > 
> > Fixes: 6e5403093261 ("ipv4/udp: Verify multicast group is ours in upd_v4_early_demux()")
> > Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> 
> I'm extremely weary to change the routing lookup code wrt. broadcast, multicast,
> etc. policies, ever.  The checks in there have multiple decades of precedence
> and therefore are extremely dangerous to modify.
> 
> The UDP change in question didn't touch the generic routing code, therfore you
> must fix this bug without modifying it either.

ok, I'll try to find something less intrusive. I'm not sure if it will
be possible.

Just a little addendum: the current issue is not caused only by the
commit 6e5403093261, but also by some less trivial/older change into the
routing lookup code I was unable to track exactly.

Cheers,

Paolo 

^ permalink raw reply

* Re: net/bluetooth: workqueue destruction WARNING in hci_unregister_dev
From: Jiri Slaby @ 2016-03-21 15:58 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Dmitry Vyukov, Marcel Holtmann, Gustavo Padovan, Johan Hedberg,
	David S. Miller, linux-bluetooth, netdev, LKML, syzkaller,
	Kostya Serebryany, Alexander Potapenko, Sasha Levin, Eric Dumazet,
	Takashi Iwai
In-Reply-To: <20160318205231.GO20028@mtj.duckdns.org>

Hello,

On 03/18/2016, 09:52 PM, Tejun Heo wrote:
> On Thu, Mar 17, 2016 at 01:00:13PM +0100, Jiri Slaby wrote:
>>>> I have not done that yet, but today, I see:
>>>> destroy_workqueue: name='req_hci0' pwq=ffff88002f590300
>>>> wq->dfl_pwq=ffff88002f591e00 pwq->refcnt=2 pwq->nr_active=0 delayed_works:
>>>>    pwq 12: cpus=0-1 node=0 flags=0x4 nice=-20 active=0/1
>>>>      in-flight: 18568:wq_barrier_func
>>>
>>> So, this means that there's flush_work() racing against workqueue
>>> destruction, which can't be safe. :(
>>
>> But I cannot trigger the WARN_ONs in the attached patch, so I am
>> confused how this can happen :(. (While I am still seeing the destroy
>> WARNINGs.)
> 
> So, no operations should be in progress when destroy_workqueue() is
> called.  If somebody was flushing a work item, the flush call must
> have returned before destroy_workqueue() was invoked, which doesn't
> seem to be the case here.  Can you trigger BUG_ON() or sysrq-t when
> the above triggers?  There must be a task which is flushing a work
> item there and it shouldn't be difficult to pinpoint what's going on
> from it.

The output of sysrq-t is here (> 200k), but I cannot see anything
suspicious in it:
http://www.fi.muni.cz/~xslaby/sklad/panics/jctl.txt

This is what the code does now:
+               if ((pwq != wq->dfl_pwq) && (pwq->refcnt > 1)) {
+                       pr_info("%s: name='%s' pwq=%p wq->dfl_pwq=%p
pwq->refcnt=%d pwq->nr_active=%d delayed_works:",
+                                       __func__, wq->name, pwq,
wq->dfl_pwq,
+                                       pwq->refcnt, pwq->nr_active);
+
+                       show_pwq(pwq);
+
+                       mutex_unlock(&wq->mutex);
+                       show_state();
+                       show_workqueue_state();
+                       WARN_ON(1);
+                       return;
+               }

thanks,
-- 
js
suse labs

^ permalink raw reply

* Re: [GIT] Networking
From: Yishai Hadas @ 2016-03-21 15:57 UTC (permalink / raw)
  To: David Miller
  Cc: torvalds, akpm, netdev, linux-kernel, yishaih@mellanox.com,
	Majd Dibbiny
In-Reply-To: <20160319.004247.586283396471702061.davem@davemloft.net>

On 3/19/2016 6:42 AM, David Miller wrote:
>
> There is a merge conflict against the RDMA tree pull wrt the mlx4 driver,
> which I don't know how to resolve.

Can you please point on the conflict ? is it still open that needs our 
input ?

^ permalink raw reply

* Re: [PATCH net] ipv4: fix broadcast packets reception
From: David Miller @ 2016-03-21 15:50 UTC (permalink / raw)
  To: pabeni; +Cc: netdev, kuznet, sbohrer, hannes
In-Reply-To: <b2a74da9e3b01065d0244088c2038c8b6ec1d334.1458574841.git.pabeni@redhat.com>

From: Paolo Abeni <pabeni@redhat.com>
Date: Mon, 21 Mar 2016 16:42:11 +0100

> Currently, ingress ipv4 broadcast datagrams are dropped if the
> ingress interface lacks an ipv4 address. This is caused by
> multiple issues:
> 
> - in udp_v4_early_demux() ip_check_mc_rcu is invoked even on
>   bcast packets
> 
> - ip_route_input_slow() always try to validate the source
> 
> This patch tries to address both issues, invoking ip_check_mc_rcu()
> only for mcast packets and calling fib_validate_source() only
> if the in_device has an address, at least.
> 
> Fixes: 6e5403093261 ("ipv4/udp: Verify multicast group is ours in upd_v4_early_demux()")
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>

I'm extremely weary to change the routing lookup code wrt. broadcast, multicast,
etc. policies, ever.  The checks in there have multiple decades of precedence
and therefore are extremely dangerous to modify.

The UDP change in question didn't touch the generic routing code, therfore you
must fix this bug without modifying it either.

Sorry.

^ permalink raw reply

* Re: [PATCH net 06/10] net: hns: fix return value of the function about rss
From: David Miller @ 2016-03-21 15:42 UTC (permalink / raw)
  To: Yisen.Zhuang
  Cc: yankejian, huangdaode, salil.mehta, lisheng011, lipeng321,
	liguozhu, arnd, xieqianqian, andrew, ivecera, netdev,
	linux-kernel, linuxarm
In-Reply-To: <1458558401-190165-7-git-send-email-Yisen.Zhuang@huawei.com>

From: Yisen Zhuang <Yisen.Zhuang@huawei.com>
Date: Mon, 21 Mar 2016 19:06:37 +0800

> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> index 3c4a3bc..f3a5e05 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
 ...
> @@ -1235,12 +1226,11 @@ hns_set_rss(struct net_device *netdev, const u32 *indir, const u8 *key,
>  {
>  	struct hns_nic_priv *priv = netdev_priv(netdev);
>  	struct hnae_ae_ops *ops;
> -	int ret;
>  
>  	if (AE_IS_VER1(priv->enet_ver)) {
>  		netdev_err(netdev,
>  			   "RSS feature is not supported on this hardware\n");
> -		return -EOPNOTSUPP;
> +		return (u32)-EOPNOTSUPP;
>  	}
>  

This is incredibly broken, you cannot cast this negative error return value to
an unsigned integer.

^ permalink raw reply

* [PATCH net] ipv4: fix broadcast packets reception
From: Paolo Abeni @ 2016-03-21 15:42 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Alexey Kuznetsov, Shawn Bohrer,
	Hannes Frederic Sowa

Currently, ingress ipv4 broadcast datagrams are dropped if the
ingress interface lacks an ipv4 address. This is caused by
multiple issues:

- in udp_v4_early_demux() ip_check_mc_rcu is invoked even on
  bcast packets

- ip_route_input_slow() always try to validate the source

This patch tries to address both issues, invoking ip_check_mc_rcu()
only for mcast packets and calling fib_validate_source() only
if the in_device has an address, at least.

Fixes: 6e5403093261 ("ipv4/udp: Verify multicast group is ours in upd_v4_early_demux()")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
 net/ipv4/route.c |  6 +++++-
 net/ipv4/udp.c   | 12 ++++++++----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 02c6229..e86d33d 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1867,7 +1867,11 @@ brd_input:
 	if (skb->protocol != htons(ETH_P_IP))
 		goto e_inval;
 
-	if (!ipv4_is_zeronet(saddr)) {
+	/* Do not validate the source if this device not not have an
+	 * IPv4 address yet and the destination is the broadcast address.
+	 */
+	if (!ipv4_is_zeronet(saddr) && (in_dev->ifa_list ||
+					!ipv4_is_lbcast(daddr))) {
 		err = fib_validate_source(skb, saddr, 0, tos, 0, dev,
 					  in_dev, &itag);
 		if (err < 0)
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 836abe5..08eed5e 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -2070,10 +2070,14 @@ void udp_v4_early_demux(struct sk_buff *skb)
 		if (!in_dev)
 			return;
 
-		ours = ip_check_mc_rcu(in_dev, iph->daddr, iph->saddr,
-				       iph->protocol);
-		if (!ours)
-			return;
+		/* we are supposed to accept bcast packets */
+		if (skb->pkt_type == PACKET_MULTICAST) {
+			ours = ip_check_mc_rcu(in_dev, iph->daddr, iph->saddr,
+					       iph->protocol);
+			if (!ours)
+				return;
+		}
+
 		sk = __udp4_lib_mcast_demux_lookup(net, uh->dest, iph->daddr,
 						   uh->source, iph->saddr, dif);
 	} else if (skb->pkt_type == PACKET_HOST) {
-- 
1.8.3.1

^ permalink raw reply related

* Re: [PATCH net 03/10] net: hns: add uc match for debug ports
From: David Miller @ 2016-03-21 15:40 UTC (permalink / raw)
  To: Yisen.Zhuang
  Cc: yankejian, huangdaode, salil.mehta, lisheng011, lipeng321,
	liguozhu, arnd, xieqianqian, andrew, ivecera, netdev,
	linux-kernel, linuxarm
In-Reply-To: <1458558401-190165-4-git-send-email-Yisen.Zhuang@huawei.com>

From: Yisen Zhuang <Yisen.Zhuang@huawei.com>
Date: Mon, 21 Mar 2016 19:06:34 +0800

> +	(void)hns_mac_set_promisc(mac_cb, (u8)!!en);

This cast to void is unnecssary.

> +static void hns_gmac_set_uc_match(void *mac_drv, u16 en)
> +{
> +	struct mac_driver *drv = (struct mac_driver *)mac_drv;

Casts from void pointers are unnecessary.

> +{
> +	struct mac_driver *drv = (struct mac_driver *)mac_drv;

Likewise.

^ permalink raw reply

* Re: [PATCH net 01/10] net: hns: bug fix about ping6
From: David Miller @ 2016-03-21 15:39 UTC (permalink / raw)
  To: Yisen.Zhuang
  Cc: yankejian, huangdaode, salil.mehta, lisheng011, lipeng321,
	liguozhu, arnd, xieqianqian, andrew, ivecera, netdev,
	linux-kernel, linuxarm
In-Reply-To: <1458558401-190165-2-git-send-email-Yisen.Zhuang@huawei.com>

From: Yisen Zhuang <Yisen.Zhuang@huawei.com>
Date: Mon, 21 Mar 2016 19:06:32 +0800

> From: Kejian Yan <yankejian@huawei.com>
> 
> The current upstreaming code fails to ping other IPv6 net device, because
> the enet receives the multicast packets with the src mac addr whick is the
                                                                ^^^^^

"which"

> @@ -670,6 +671,14 @@ out_bnum_err:
>  		return -EFAULT;
>  	}
>  
> +	/* filter out multicast pkt with the same src mac as this port */
> +	eh = (struct ethhdr *)skb->data;

Please use the "eth_hdr()" helper.

^ permalink raw reply

* Re: [PATCH] net: phy: at803x: don't depend on GPIOLIB
From: Sebastian Frias @ 2016-03-21 15:36 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Daniel Mack, David S. Miller, netdev, lkml, mason,
	Florian Fainelli, Mans Rullgard, Fabio Estevam,
	Martin Blumenstingl, Linus Walleij
In-Reply-To: <20160321135457.GX4292@pengutronix.de>

Hi Uwe,

On 03/21/2016 02:54 PM, Uwe Kleine-König wrote:
>>
>> Two things:
>> - I suppose that in such hypothetical case the dependency on GPIOLIB
>>   would be required and thus be there
> 
> I don't agree. There are bugs out there, and maybe the reason is as
> simple as "the implementor of the reset-gpio handling had GPIOLIB on and
> didn't test without GPIOLIB".

:-) fair enough, let's wait for his comments then.

> 
>> - We'd also need to check that 'gpiod' is not NULL
> 
> That is the optional part. If gpiod is NULL, you have one of the devices
> that don't need to handle the enable line.

gpiod=NULL (because the key is not there) or gpiod=ERR (because
GPIOLIB=n + my patch) will result in the same behaviour, ie: driver
binds, but fails to reset.

> 
>> In the scenario at hand only some devices require a hack and
>> gpiod_reset=NULL is valid (ie: device will not fail probing)
> 
> With your patch and GPIOLIB=n you bind the driver even for the devices
> that need the hack. This is broken!

It is a degraded mode I agree and had proposed to print a warning.
However, I fail to see how is GPIOLIB=n different from just not having
"reset" present.

The fact that GPIOLIB=y does not means that the "reset" key will be there.
I mean, you assume that "reset" will be present for devices that need
the hack, yet there is no such guarantee and the code clearly assumes
that it can be missing.
For all we know, the key is actually missing on systems that do use the
faulty PHY (all systems designed prior to the hack being implemented)
And that, regardless of GPIOLIB status.

Since the reset line can be missing, it can be missing for whatever reason.
Whether it is because the "reset" key is not present or because
GPIOLIB=n, it does not matter, it will result on the same outcome.

Furthermore, if "reset" is really required for certain devices that need
the hack, then both cases:
- GPIOLIB=n
- "reset" not present
should be handled the same way (ie: not bind the driver) for such devices.

By the way, I think not binding the driver is too strong too.
Having a GPIO free and being able to route it to the PHY for reset may
not even be possible on some systems.
Are they supposed to stop working?

> 
>>> For consistency I'd recommend to do the
>>> same for reset even though there is a chance to get a working device.
>>
>> I'm not so sure, because then information would be lost, handling both
>> ("enable" and "reset") the same way aliases different intents and
>> requirements.
>> Indeed, only "enable" would be really mandatory, "reset" is essentially
>> optional (only 1 of 3 devices of the family require the hack).
>>
>> Besides, if "reset" was really mandatory, we would also fail the probe
>> if the pointer for the reset GPIO is NULL.
> 
> No, if reset was mandatory you'd use gpiod_get instead of
> gpiod_get_optional and fail iff that call fails, too.

Ok, but the current code for "reset" is using devm_gpiod_get_optional()
so "reset" is clearly optional.
And that call will return NULL if "reset" is not present, even with
GPIOLIB=y

> 
>> Indeed, even with GPIOLIB=y the pointer can be NULL if the "reset" (or
>> "enable" in your scenario) is not present.
>> From a functionality perspective, a NULL pointer for "reset" will result
>> in the same behaviour as GPIOLIB=n, ie: not being able to reset the PHY.
> 
> Right, but you only get reset=NULL iff the device tree (or whatever is
> the source of information for gpiod_get) doesn't specify a reset gpio
> which then means "This device doesn't need a reset gpio.". This is
> different from the GPIOLIB=n case, where the return code signals "It's
> unknown if the device needs a reset gpio.".

I think somehow you try to make a difference on the reason why the
reset=INVALID (NULL or ERR), but IMHO there's none.

If somebody using AT8030 PHY (the one that requires the hack) either
does not configure a "reset" key on the DT, either does not enable
GPIOLIB, the result will be the same.
There is no warning in either case and it will run on a degraded mode.

> 
>> So, the current code (your commit) and previous code (Daniel's commit)
>> clearly points to "reset" being optional.
>>
>> Furthermore, I think we should not even register the
>> "link_change_notify" callback when dealing with AT803x PHYs that do not
>> require the hack.
>> Another solution (considering the callback is statically registered in
>> the "phy_driver" structs for all AT803x PHYs) would be for the callback
>> to disable itself.
>> Once it detects that the PHY does not require the hack, it could just
>> perform:
>>
>>     phydev->drv->link_change_notify = NULL;
>>
>> or call a new generic function to do the same if encapsulation is required.
>>
>> If everybody agrees I can make such change as well, but I really think
>> Daniel should give his opinion first.
>>
>>>
>>>> What would you think of making at803x_link_change_notify() print a
>>>> message every time it should do a reset but does not has a way to do it?
>>>
>>> Then this question is obsolete because the device doesn't probe.
>>
>> I think you assume that "reset" is mandatory for all AT803x devices, but
>> that's not what the code says.
> 
> No, you're wrong here. I'm aware that the code supports devices without
> reset.

Ok, then I did not understand what you meant with "the question is
obsolete because the device doesn't probe".
Unless I'm missing something, the only way the driver won't bind
correctly with current code is if GPIOLIB=n

Systems using the faulty PHY and having GPIOLIB=y but with an outdated
DT that does not has a "reset" key would have the PHY driver bind yet
have it fail due to missing "reset".

> 
>> As such, my proposal was to:
>> - keep my proposed patch
> 
> I don't agree.
> 
>> - make another patch to print a warning when gpiod_reset is NULL (which
>>   can happen, even without my patch)
> 
> This only happens if no reset gpio is needed and in this case the driver
> does the right thing. So if you ask me, there is no need to modify the
> driver. Better add a dependency to GPIOLIB. This is necessary even for
> devices which don't need a reset gpio to answer the question "does this
> driver need a reset gpio?" correctly.

I don't see how the dependency on GPIOLIB=y improves the situation in
any useful way.

To put an example: in our case we don't use the faulty PHY.
So, the DT does not has the "reset" key.
Why should then the PHY driver be dependent on GPIOLIB?

Best regards,

Sebastian

^ permalink raw reply

* Re: [PATCH v5 2/4] Documentation: Bindings: Add STM32 DWMAC glue
From: Joachim Eastwood @ 2016-03-21 15:36 UTC (permalink / raw)
  To: Rob Herring
  Cc: Chen-Yu Tsai, Alexandre TORGUE, Maxime Coquelin,
	Giuseppe Cavallaro, netdev, devicetree, linux-kernel,
	linux-arm-kernel
In-Reply-To: <20160321124043.GA26873@rob-hp-laptop>

On 21 March 2016 at 13:40, Rob Herring <robh@kernel.org> wrote:
> On Sat, Mar 19, 2016 at 12:00:22AM +0800, Chen-Yu Tsai wrote:
>> Hi,
>>
>> On Fri, Mar 18, 2016 at 11:37 PM, Alexandre TORGUE
>> <alexandre.torgue@gmail.com> wrote:
>> > +- clocks: Must contain a phandle for each entry in clock-names.
>> > +- clock-names: Should be "stmmaceth" for the host clock.
>
> This doesn't sound like the clock input signal name...
>
>> > +              Should be "tx-clk" for the MAC TX clock.
>> > +              Should be "rx-clk" for the MAC RX clock.
>
> How can other DWMAC blocks not have these clocks? The glue can't really
> add these clocks. It could combine them into one or a new version of
> DWMAC could have a different number of clock inputs. So if there is
> variation here, then some of the bindings are probably wrong. I guess
> the only change I'm suggesting is possibly moving these into common
> binding doc.

The LPC18xx implementation probably have these clocks as well but the
LPC1850 user manual only documents the main clock. Someone with access
to the IP block doc from Synopsys should be able to check which clocks
the MAC really needs.

Rockchip bindings have two clocks named "mac_clk_rx" and "mac_clk_tx".
These are probably the same as stm32 needs so maybe use these names
and move them into the main doc and update the rockchip binding.


regards,
Joachim Eastwood

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox