1 From 03374d551c7fbb1b1ecc115df4f374bc5027b1f9 Mon Sep 17 00:00:00 2001
2 From: Joakim Zhang <qiangqing.zhang@nxp.com>
3 Date: Fri, 12 Jul 2019 08:02:41 +0000
4 Subject: [PATCH] can: flexcan: use struct canfd_frame for CAN classic frame
6 This patch prepares for CAN FD mode, using struct canfd_frame can both
7 for classic format frame and fd format frame.
9 Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
10 Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
12 drivers/net/can/flexcan.c | 34 +++++++++++++++++-----------------
13 drivers/net/can/rx-offload.c | 4 ++--
14 2 files changed, 19 insertions(+), 19 deletions(-)
16 --- a/drivers/net/can/flexcan.c
17 +++ b/drivers/net/can/flexcan.c
18 @@ -628,10 +628,10 @@ static int flexcan_get_berr_counter(cons
19 static netdev_tx_t flexcan_start_xmit(struct sk_buff *skb, struct net_device *dev)
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;
26 - u32 ctrl = FLEXCAN_MB_CODE_TX_DATA | (cf->can_dlc << 16);
27 + u32 ctrl = FLEXCAN_MB_CODE_TX_DATA | (cfd->len << 16);
30 if (can_dropped_invalid_skb(dev, skb))
31 @@ -639,18 +639,18 @@ static netdev_tx_t flexcan_start_xmit(st
33 netif_stop_queue(dev);
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;
41 - can_id = (cf->can_id & CAN_SFF_MASK) << 18;
42 + can_id = (cfd->can_id & CAN_SFF_MASK) << 18;
45 - if (cf->can_id & CAN_RTR_FLAG)
46 + if (cfd->can_id & CAN_RTR_FLAG)
47 ctrl |= FLEXCAN_MB_CNT_RTR;
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)]);
56 @@ -822,7 +822,7 @@ static struct sk_buff *flexcan_mailbox_r
57 struct flexcan_regs __iomem *regs = priv->regs;
58 struct flexcan_mb __iomem *mb;
60 - struct can_frame *cf;
61 + struct canfd_frame *cfd;
62 u32 reg_ctrl, reg_id, reg_iflag1;
65 @@ -859,8 +859,8 @@ static struct sk_buff *flexcan_mailbox_r
66 reg_ctrl = priv->read(&mb->can_ctrl);
69 - skb = alloc_can_skb(offload->dev, &cf);
71 + skb = alloc_can_skb(offload->dev, (struct can_frame **)&cfd);
72 + if (unlikely(!skb)) {
73 skb = ERR_PTR(-ENOMEM);
76 @@ -870,17 +870,17 @@ static struct sk_buff *flexcan_mailbox_r
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;
83 - cf->can_id = (reg_id >> 18) & CAN_SFF_MASK;
84 + cfd->can_id = (reg_id >> 18) & CAN_SFF_MASK;
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);
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;
100 --- a/drivers/net/can/rx-offload.c
101 +++ b/drivers/net/can/rx-offload.c
102 @@ -51,11 +51,11 @@ static int can_rx_offload_napi_poll(stru
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;
111 - stats->rx_bytes += cf->can_dlc;
112 + stats->rx_bytes += cfd->len;
113 netif_receive_skb(skb);