Commit d9b90b05 authored by Joakim Zhang's avatar Joakim Zhang Committed by Marc Kleine-Budde

can: flexcan: use struct canfd_frame for CAN classic frame

This patch prepares for CAN FD mode, using struct canfd_frame can both
for classic format frame and fd format frame.
Signed-off-by: default avatarJoakim Zhang <qiangqing.zhang@nxp.com>
Link: https://lore.kernel.org/r/20190712075926.7357-3-qiangqing.zhang@nxp.comSigned-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent 890599bc
...@@ -646,10 +646,10 @@ static int flexcan_get_berr_counter(const struct net_device *dev, ...@@ -646,10 +646,10 @@ static int flexcan_get_berr_counter(const struct net_device *dev,
static netdev_tx_t flexcan_start_xmit(struct sk_buff *skb, struct net_device *dev) static netdev_tx_t flexcan_start_xmit(struct sk_buff *skb, struct net_device *dev)
{ {
const struct flexcan_priv *priv = netdev_priv(dev); const struct flexcan_priv *priv = netdev_priv(dev);
struct can_frame *cf = (struct can_frame *)skb->data; struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
u32 can_id; u32 can_id;
u32 data; u32 data;
u32 ctrl = FLEXCAN_MB_CODE_TX_DATA | (cf->can_dlc << 16); u32 ctrl = FLEXCAN_MB_CODE_TX_DATA | (cfd->len << 16);
int i; int i;
if (can_dropped_invalid_skb(dev, skb)) if (can_dropped_invalid_skb(dev, skb))
...@@ -657,18 +657,18 @@ static netdev_tx_t flexcan_start_xmit(struct sk_buff *skb, struct net_device *de ...@@ -657,18 +657,18 @@ static netdev_tx_t flexcan_start_xmit(struct sk_buff *skb, struct net_device *de
netif_stop_queue(dev); netif_stop_queue(dev);
if (cf->can_id & CAN_EFF_FLAG) { if (cfd->can_id & CAN_EFF_FLAG) {
can_id = cf->can_id & CAN_EFF_MASK; can_id = cfd->can_id & CAN_EFF_MASK;
ctrl |= FLEXCAN_MB_CNT_IDE | FLEXCAN_MB_CNT_SRR; ctrl |= FLEXCAN_MB_CNT_IDE | FLEXCAN_MB_CNT_SRR;
} else { } else {
can_id = (cf->can_id & CAN_SFF_MASK) << 18; can_id = (cfd->can_id & CAN_SFF_MASK) << 18;
} }
if (cf->can_id & CAN_RTR_FLAG) if (cfd->can_id & CAN_RTR_FLAG)
ctrl |= FLEXCAN_MB_CNT_RTR; ctrl |= FLEXCAN_MB_CNT_RTR;
for (i = 0; i < cf->can_dlc; i += sizeof(u32)) { for (i = 0; i < cfd->len; i += sizeof(u32)) {
data = be32_to_cpup((__be32 *)&cf->data[i]); data = be32_to_cpup((__be32 *)&cfd->data[i]);
priv->write(data, &priv->tx_mb->data[i / sizeof(u32)]); priv->write(data, &priv->tx_mb->data[i / sizeof(u32)]);
} }
...@@ -840,7 +840,7 @@ static struct sk_buff *flexcan_mailbox_read(struct can_rx_offload *offload, ...@@ -840,7 +840,7 @@ static struct sk_buff *flexcan_mailbox_read(struct can_rx_offload *offload,
struct flexcan_regs __iomem *regs = priv->regs; struct flexcan_regs __iomem *regs = priv->regs;
struct flexcan_mb __iomem *mb; struct flexcan_mb __iomem *mb;
struct sk_buff *skb; struct sk_buff *skb;
struct can_frame *cf; struct canfd_frame *cfd;
u32 reg_ctrl, reg_id, reg_iflag1; u32 reg_ctrl, reg_id, reg_iflag1;
int i; int i;
...@@ -877,8 +877,8 @@ static struct sk_buff *flexcan_mailbox_read(struct can_rx_offload *offload, ...@@ -877,8 +877,8 @@ static struct sk_buff *flexcan_mailbox_read(struct can_rx_offload *offload,
reg_ctrl = priv->read(&mb->can_ctrl); reg_ctrl = priv->read(&mb->can_ctrl);
} }
skb = alloc_can_skb(offload->dev, &cf); skb = alloc_can_skb(offload->dev, (struct can_frame **)&cfd);
if (!skb) { if (unlikely(!skb)) {
skb = ERR_PTR(-ENOMEM); skb = ERR_PTR(-ENOMEM);
goto mark_as_read; goto mark_as_read;
} }
...@@ -888,17 +888,17 @@ static struct sk_buff *flexcan_mailbox_read(struct can_rx_offload *offload, ...@@ -888,17 +888,17 @@ static struct sk_buff *flexcan_mailbox_read(struct can_rx_offload *offload,
reg_id = priv->read(&mb->can_id); reg_id = priv->read(&mb->can_id);
if (reg_ctrl & FLEXCAN_MB_CNT_IDE) if (reg_ctrl & FLEXCAN_MB_CNT_IDE)
cf->can_id = ((reg_id >> 0) & CAN_EFF_MASK) | CAN_EFF_FLAG; cfd->can_id = ((reg_id >> 0) & CAN_EFF_MASK) | CAN_EFF_FLAG;
else else
cf->can_id = (reg_id >> 18) & CAN_SFF_MASK; cfd->can_id = (reg_id >> 18) & CAN_SFF_MASK;
if (reg_ctrl & FLEXCAN_MB_CNT_RTR) if (reg_ctrl & FLEXCAN_MB_CNT_RTR)
cf->can_id |= CAN_RTR_FLAG; cfd->can_id |= CAN_RTR_FLAG;
cf->can_dlc = get_can_dlc((reg_ctrl >> 16) & 0xf); cfd->len = get_can_dlc((reg_ctrl >> 16) & 0xf);
for (i = 0; i < cf->can_dlc; i += sizeof(u32)) { for (i = 0; i < cfd->len; i += sizeof(u32)) {
__be32 data = cpu_to_be32(priv->read(&mb->data[i / sizeof(u32)])); __be32 data = cpu_to_be32(priv->read(&mb->data[i / sizeof(u32)]));
*(__be32 *)(cf->data + i) = data; *(__be32 *)(cfd->data + i) = data;
} }
mark_as_read: mark_as_read:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment