From: Dong Aisheng <aisheng.d...@nxp.com>

Using struct canfd_frame instead of can_frame to add support for CAN FD
mode in offload. FlexCAN controller will set the is_canfd variable when
it supports CAN FD mode.

Signed-off-by: Dong Aisheng <aisheng.d...@nxp.com>
Signed-off-by: Joakim Zhang <qiangqing.zh...@nxp.com>
---
 drivers/net/can/rx-offload.c   | 16 ++++++++++------
 include/linux/can/rx-offload.h |  4 +++-
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/net/can/rx-offload.c b/drivers/net/can/rx-offload.c
index 2ce4fa8698c7..131fe600deb3 100644
--- a/drivers/net/can/rx-offload.c
+++ b/drivers/net/can/rx-offload.c
@@ -55,11 +55,11 @@ static int can_rx_offload_napi_poll(struct napi_struct 
*napi, int quota)
 
        while ((work_done < quota) &&
               (skb = skb_dequeue(&offload->skb_queue))) {
-               struct can_frame *cf = (struct can_frame *)skb->data;
+               struct canfd_frame *cf = (struct canfd_frame *)skb->data;
 
                work_done++;
                stats->rx_packets++;
-               stats->rx_bytes += cf->can_dlc;
+               stats->rx_bytes += cf->len;
                netif_receive_skb(skb);
        }
 
@@ -122,16 +122,20 @@ static struct sk_buff *can_rx_offload_offload_one(struct 
can_rx_offload *offload
 {
        struct sk_buff *skb = NULL;
        struct can_rx_offload_cb *cb;
-       struct can_frame *cf;
+       struct canfd_frame *cf;
        int ret;
 
        /* If queue is full or skb not available, read to discard mailbox */
        if (likely(skb_queue_len(&offload->skb_queue) <=
-                  offload->skb_queue_len_max))
-               skb = alloc_can_skb(offload->dev, &cf);
+                  offload->skb_queue_len_max)) {
+               if (offload->is_canfd)
+                       skb = alloc_canfd_skb(offload->dev, &cf);
+               else
+                       skb = alloc_can_skb(offload->dev, (struct can_frame 
**)&cf);
+       }
 
        if (!skb) {
-               struct can_frame cf_overflow;
+               struct canfd_frame cf_overflow;
                u32 timestamp;
 
                ret = offload->mailbox_read(offload, &cf_overflow,
diff --git a/include/linux/can/rx-offload.h b/include/linux/can/rx-offload.h
index 8268811a697e..6448e7dfc170 100644
--- a/include/linux/can/rx-offload.h
+++ b/include/linux/can/rx-offload.h
@@ -23,7 +23,7 @@
 struct can_rx_offload {
        struct net_device *dev;
 
-       unsigned int (*mailbox_read)(struct can_rx_offload *offload, struct 
can_frame *cf,
+       unsigned int (*mailbox_read)(struct can_rx_offload *offload, struct 
canfd_frame *cf,
                                     u32 *timestamp, unsigned int mb);
 
        struct sk_buff_head skb_queue;
@@ -35,6 +35,8 @@ struct can_rx_offload {
        struct napi_struct napi;
 
        bool inc;
+
+       bool is_canfd;
 };
 
 int can_rx_offload_add_timestamp(struct net_device *dev, struct can_rx_offload 
*offload);
-- 
2.17.1

Reply via email to