From: Benedikt Spranger <b.spranger@linutronix.de>
To: netdev@vger.kernel.org
Cc: Alexander Frank <Alexander.Frank@eberspaecher.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Holger Dengler <dengler@linutronix.de>,
Benedikt Spranger <b.spranger@linutronix.de>
Subject: [PATCH 14/16] flexcard: can: CAN local loopback using SKB pflags
Date: Mon, 9 Sep 2013 09:25:11 +0200 [thread overview]
Message-ID: <1378711513-2548-15-git-send-email-b.spranger@linutronix.de> (raw)
In-Reply-To: <1378711513-2548-1-git-send-email-b.spranger@linutronix.de>
Flexcard receives CAN local loopback in hardware. Include the direction
information from the raw CAN message (DMA) in the pflags of SKB and use it
later in the CAN raw layer.
Signed-off-by: Holger Dengler <dengler@linutronix.de>
---
drivers/net/can/c_can/c_can_platform.c | 14 +++++++++++---
include/uapi/linux/can/raw.h | 20 ++++++++++++++++++++
net/can/raw.c | 22 ++++++----------------
3 files changed, 37 insertions(+), 19 deletions(-)
diff --git a/drivers/net/can/c_can/c_can_platform.c b/drivers/net/can/c_can/c_can_platform.c
index c6c1eb4..d8b99b5 100644
--- a/drivers/net/can/c_can/c_can_platform.c
+++ b/drivers/net/can/c_can/c_can_platform.c
@@ -35,6 +35,7 @@
#include <linux/flexcard.h>
#include <linux/can/dev.h>
+#include <linux/can/raw.h>
#include "c_can.h"
@@ -125,6 +126,7 @@ static int c_can_rx_pkt(void *p, void *data, size_t len)
struct can_frame *frame;
struct sk_buff *skb;
u32 flags, id, state, type;
+ unsigned int *pflags;
switch (le32_to_cpu(pb->header.type)) {
case fc_packet_type_can:
@@ -142,14 +144,20 @@ static int c_can_rx_pkt(void *p, void *data, size_t len)
else
frame->can_id = id & CAN_SFF_MASK;
+ if (flags & BIT(12)) {
+ pflags = can_raw_flags(skb);
+ *pflags |= CAN_RAW_TX_ECHO;
+ } else {
+ /* No accounting for local echo packages */
+ stats->rx_packets++;
+ stats->rx_bytes += frame->can_dlc;
+ }
+
if (flags & BIT(13))
frame->can_id |= CAN_RTR_FLAG;
frame->can_dlc = (flags >> 8) & 0xf;
memcpy(frame->data, pt->can_packet.data, frame->can_dlc);
netif_receive_skb(skb);
-
- stats->rx_packets++;
- stats->rx_bytes += frame->can_dlc;
break;
case fc_packet_type_can_error:
diff --git a/include/uapi/linux/can/raw.h b/include/uapi/linux/can/raw.h
index a814062..188738c 100644
--- a/include/uapi/linux/can/raw.h
+++ b/include/uapi/linux/can/raw.h
@@ -27,4 +27,24 @@ enum {
CAN_RAW_FD_FRAMES, /* allow CAN FD frames (default:off) */
};
+#ifdef __KERNEL__
+
+#define CAN_RAW_TX_ECHO 0x00000001 /* CAN hardware TX echo packet */
+
+/*
+ * Return pointer to store the extra msg flags for raw_recvmsg().
+ * We use the space of one unsigned int beyond the 'struct sockaddr_can'
+ * in skb->cb.
+ */
+static inline unsigned int *can_raw_flags(struct sk_buff *skb)
+{
+ BUILD_BUG_ON(sizeof(skb->cb) <= (sizeof(struct sockaddr_can) +
+ sizeof(unsigned int)));
+
+ /* return pointer after struct sockaddr_can */
+ return (unsigned int *)(&((struct sockaddr_can *)skb->cb)[1]);
+}
+
+#endif /* __KERNEL__ */
+
#endif
diff --git a/net/can/raw.c b/net/can/raw.c
index 641e1c8..80498cf 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -90,20 +90,6 @@ struct raw_sock {
can_err_mask_t err_mask;
};
-/*
- * Return pointer to store the extra msg flags for raw_recvmsg().
- * We use the space of one unsigned int beyond the 'struct sockaddr_can'
- * in skb->cb.
- */
-static inline unsigned int *raw_flags(struct sk_buff *skb)
-{
- BUILD_BUG_ON(sizeof(skb->cb) <= (sizeof(struct sockaddr_can) +
- sizeof(unsigned int)));
-
- /* return pointer after struct sockaddr_can */
- return (unsigned int *)(&((struct sockaddr_can *)skb->cb)[1]);
-}
-
static inline struct raw_sock *raw_sk(const struct sock *sk)
{
return (struct raw_sock *)sk;
@@ -117,6 +103,10 @@ static void raw_rcv(struct sk_buff *oskb, void *data)
struct sk_buff *skb;
unsigned int *pflags;
+ pflags = can_raw_flags(oskb);
+ if (*pflags & CAN_RAW_TX_ECHO)
+ oskb->sk = sk;
+
/* check the received tx sock reference */
if (!ro->recv_own_msgs && oskb->sk == sk)
return;
@@ -148,7 +138,7 @@ static void raw_rcv(struct sk_buff *oskb, void *data)
addr->can_ifindex = skb->dev->ifindex;
/* add CAN specific message flags for raw_recvmsg() */
- pflags = raw_flags(skb);
+ pflags = can_raw_flags(skb);
*pflags = 0;
if (oskb->sk)
*pflags |= MSG_DONTROUTE;
@@ -780,7 +770,7 @@ static int raw_recvmsg(struct kiocb *iocb, struct socket *sock,
}
/* assign the flags that have been recorded in raw_rcv() */
- msg->msg_flags |= *(raw_flags(skb));
+ msg->msg_flags |= *(can_raw_flags(skb));
skb_free_datagram(sk, skb);
--
1.8.4.rc3
next prev parent reply other threads:[~2013-09-09 7:43 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-09 7:24 [PATCH 00/16] Support for Eberspächer Flexcard DCAN function Benedikt Spranger
2013-09-09 7:24 ` [PATCH 01/16] c_can_platform: add FlexCard D-CAN support Benedikt Spranger
2013-09-09 8:22 ` Marc Kleine-Budde
2013-09-09 7:24 ` [PATCH 02/16] c_can: add generic D-CAN RAM initialization support Benedikt Spranger
2013-09-09 8:34 ` Marc Kleine-Budde
2013-09-09 7:25 ` [PATCH 03/16] c_can: simplify arbitration register handling Benedikt Spranger
2013-09-09 9:16 ` Marc Kleine-Budde
2013-09-09 7:25 ` [PATCH 04/16] c_can: fix receive buffer configuration Benedikt Spranger
2013-09-09 10:51 ` Marc Kleine-Budde
2013-09-09 7:25 ` [PATCH 05/16] c_can: use 32 bit access for D_CAN Benedikt Spranger
2013-09-09 9:37 ` Marc Kleine-Budde
2013-09-09 7:25 ` [PATCH 06/16] c_can: consider set bittiming may fail Benedikt Spranger
2013-09-09 9:39 ` Marc Kleine-Budde
2013-09-09 7:25 ` [PATCH 07/16] c_can: reconfigre message objects after leaving init state Benedikt Spranger
2013-09-09 7:25 ` [PATCH 08/16] c_can: Add FlexCard CAN TX fifo support Benedikt Spranger
2013-09-09 9:47 ` Marc Kleine-Budde
2013-09-09 7:25 ` [PATCH 09/16] c_can: expicit 32bit access on D_CAN to message buffer data register Benedikt Spranger
2013-09-09 11:20 ` Marc Kleine-Budde
2013-09-09 7:25 ` [PATCH 10/16] c_can: add 16bit align 32bit access functions Benedikt Spranger
2013-09-09 9:57 ` Marc Kleine-Budde
2013-09-09 7:25 ` [PATCH 11/16] c_can: stop netqueue if hardware is busy Benedikt Spranger
2013-09-09 10:05 ` Marc Kleine-Budde
2013-09-09 10:21 ` Marc Kleine-Budde
2013-09-09 7:25 ` [PATCH 12/16] c_can: Add flag to disable automatic retransmission of CAN frames Benedikt Spranger
2013-09-09 10:21 ` Marc Kleine-Budde
2013-09-09 10:34 ` Marc Kleine-Budde
2013-09-09 7:25 ` [PATCH 13/16] c_can: flexcard: add ioctl to reset FIFO message object Benedikt Spranger
2013-09-09 10:24 ` Marc Kleine-Budde
2013-09-09 7:25 ` Benedikt Spranger [this message]
2013-09-09 7:25 ` [PATCH 15/16] flexcard: can: Configure CAN loopback packages (TXACK) Benedikt Spranger
2013-09-09 10:29 ` Marc Kleine-Budde
2013-09-09 7:25 ` [PATCH 16/16] c_can: fix TX packet accounting Benedikt Spranger
2013-09-09 10:31 ` Marc Kleine-Budde
2013-09-09 7:54 ` [PATCH 00/16] Support for Eberspächer Flexcard DCAN function Marc Kleine-Budde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1378711513-2548-15-git-send-email-b.spranger@linutronix.de \
--to=b.spranger@linutronix.de \
--cc=Alexander.Frank@eberspaecher.com \
--cc=bigeasy@linutronix.de \
--cc=dengler@linutronix.de \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).