blob: 73e67b273fa8aff6aca12be7d1b27cb5a7f2c923 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From 03374d551c7fbb1b1ecc115df4f374bc5027b1f9 Mon Sep 17 00:00:00 2001
2From: Joakim Zhang <qiangqing.zhang@nxp.com>
3Date: Fri, 12 Jul 2019 08:02:41 +0000
4Subject: [PATCH] can: flexcan: use struct canfd_frame for CAN classic frame
5
6This patch prepares for CAN FD mode, using struct canfd_frame can both
7for classic format frame and fd format frame.
8
9Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
10Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
11---
12 drivers/net/can/flexcan.c | 34 +++++++++++++++++-----------------
13 drivers/net/can/rx-offload.c | 4 ++--
14 2 files changed, 19 insertions(+), 19 deletions(-)
15
16--- a/drivers/net/can/flexcan.c
17+++ b/drivers/net/can/flexcan.c
18@@ -635,10 +635,10 @@ static int flexcan_get_berr_counter(cons
19 static netdev_tx_t flexcan_start_xmit(struct sk_buff *skb, struct net_device *dev)
20 {
21 const struct flexcan_priv *priv = netdev_priv(dev);
22- struct can_frame *cf = (struct can_frame *)skb->data;
23+ struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
24 u32 can_id;
25 u32 data;
26- u32 ctrl = FLEXCAN_MB_CODE_TX_DATA | (cf->can_dlc << 16);
27+ u32 ctrl = FLEXCAN_MB_CODE_TX_DATA | (cfd->len << 16);
28 int i;
29
30 if (can_dropped_invalid_skb(dev, skb))
31@@ -646,18 +646,18 @@ static netdev_tx_t flexcan_start_xmit(st
32
33 netif_stop_queue(dev);
34
35- if (cf->can_id & CAN_EFF_FLAG) {
36- can_id = cf->can_id & CAN_EFF_MASK;
37+ if (cfd->can_id & CAN_EFF_FLAG) {
38+ can_id = cfd->can_id & CAN_EFF_MASK;
39 ctrl |= FLEXCAN_MB_CNT_IDE | FLEXCAN_MB_CNT_SRR;
40 } else {
41- can_id = (cf->can_id & CAN_SFF_MASK) << 18;
42+ can_id = (cfd->can_id & CAN_SFF_MASK) << 18;
43 }
44
45- if (cf->can_id & CAN_RTR_FLAG)
46+ if (cfd->can_id & CAN_RTR_FLAG)
47 ctrl |= FLEXCAN_MB_CNT_RTR;
48
49- for (i = 0; i < cf->can_dlc; i += sizeof(u32)) {
50- data = be32_to_cpup((__be32 *)&cf->data[i]);
51+ for (i = 0; i < cfd->len; i += sizeof(u32)) {
52+ data = be32_to_cpup((__be32 *)&cfd->data[i]);
53 priv->write(data, &priv->tx_mb->data[i / sizeof(u32)]);
54 }
55
56@@ -829,7 +829,7 @@ static struct sk_buff *flexcan_mailbox_r
57 struct flexcan_regs __iomem *regs = priv->regs;
58 struct flexcan_mb __iomem *mb;
59 struct sk_buff *skb;
60- struct can_frame *cf;
61+ struct canfd_frame *cfd;
62 u32 reg_ctrl, reg_id, reg_iflag1;
63 int i;
64
65@@ -866,8 +866,8 @@ static struct sk_buff *flexcan_mailbox_r
66 reg_ctrl = priv->read(&mb->can_ctrl);
67 }
68
69- skb = alloc_can_skb(offload->dev, &cf);
70- if (!skb) {
71+ skb = alloc_can_skb(offload->dev, (struct can_frame **)&cfd);
72+ if (unlikely(!skb)) {
73 skb = ERR_PTR(-ENOMEM);
74 goto mark_as_read;
75 }
76@@ -877,17 +877,17 @@ static struct sk_buff *flexcan_mailbox_r
77
78 reg_id = priv->read(&mb->can_id);
79 if (reg_ctrl & FLEXCAN_MB_CNT_IDE)
80- cf->can_id = ((reg_id >> 0) & CAN_EFF_MASK) | CAN_EFF_FLAG;
81+ cfd->can_id = ((reg_id >> 0) & CAN_EFF_MASK) | CAN_EFF_FLAG;
82 else
83- cf->can_id = (reg_id >> 18) & CAN_SFF_MASK;
84+ cfd->can_id = (reg_id >> 18) & CAN_SFF_MASK;
85
86 if (reg_ctrl & FLEXCAN_MB_CNT_RTR)
87- cf->can_id |= CAN_RTR_FLAG;
88- cf->can_dlc = get_can_dlc((reg_ctrl >> 16) & 0xf);
89+ cfd->can_id |= CAN_RTR_FLAG;
90+ cfd->len = get_can_dlc((reg_ctrl >> 16) & 0xf);
91
92- for (i = 0; i < cf->can_dlc; i += sizeof(u32)) {
93+ for (i = 0; i < cfd->len; i += sizeof(u32)) {
94 __be32 data = cpu_to_be32(priv->read(&mb->data[i / sizeof(u32)]));
95- *(__be32 *)(cf->data + i) = data;
96+ *(__be32 *)(cfd->data + i) = data;
97 }
98
99 mark_as_read:
100--- a/drivers/net/can/dev/rx-offload.c
101+++ b/drivers/net/can/dev/rx-offload.c
102@@ -51,11 +51,11 @@ static int can_rx_offload_napi_poll(stru
103
104 while ((work_done < quota) &&
105 (skb = skb_dequeue(&offload->skb_queue))) {
106- struct can_frame *cf = (struct can_frame *)skb->data;
107+ struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
108
109 work_done++;
110 stats->rx_packets++;
111- stats->rx_bytes += cf->can_dlc;
112+ stats->rx_bytes += cfd->len;
113 netif_receive_skb(skb);
114 }
115