can: kvaser_pciefd: Add len8_dlc support
authorJimmy Assarsson <extja@kvaser.com>
Mon, 29 May 2023 13:42:46 +0000 (15:42 +0200)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Thu, 22 Jun 2023 07:44:29 +0000 (09:44 +0200)
Add support for the Classical CAN raw DLC functionality to send and receive
DLC values from 9 .. 15.

Signed-off-by: Jimmy Assarsson <extja@kvaser.com>
Reviewed-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Link: https://lore.kernel.org/all/20230529134248.752036-13-extja@kvaser.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/kvaser_pciefd.c

index 8779091..e3d7302 100644 (file)
@@ -591,15 +591,20 @@ static int kvaser_pciefd_prepare_tx_packet(struct kvaser_pciefd_tx_packet *p,
                p->header[0] |= KVASER_PCIEFD_RPACKET_IDE;
 
        p->header[0] |= FIELD_PREP(KVASER_PCIEFD_RPACKET_ID_MASK, cf->can_id);
-       p->header[1] |= FIELD_PREP(KVASER_PCIEFD_RPACKET_DLC_MASK, can_fd_len2dlc(cf->len));
        p->header[1] |= KVASER_PCIEFD_TPACKET_AREQ;
 
        if (can_is_canfd_skb(skb)) {
+               p->header[1] |= FIELD_PREP(KVASER_PCIEFD_RPACKET_DLC_MASK,
+                                          can_fd_len2dlc(cf->len));
                p->header[1] |= KVASER_PCIEFD_RPACKET_FDF;
                if (cf->flags & CANFD_BRS)
                        p->header[1] |= KVASER_PCIEFD_RPACKET_BRS;
                if (cf->flags & CANFD_ESI)
                        p->header[1] |= KVASER_PCIEFD_RPACKET_ESI;
+       } else {
+               p->header[1] |=
+                       FIELD_PREP(KVASER_PCIEFD_RPACKET_DLC_MASK,
+                                  can_get_cc_dlc((struct can_frame *)cf, can->can.ctrlmode));
        }
 
        p->header[1] |= FIELD_PREP(KVASER_PCIEFD_PACKET_SEQ_MASK, seq);
@@ -834,7 +839,8 @@ static int kvaser_pciefd_setup_can_ctrls(struct kvaser_pciefd *pcie)
 
                can->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY |
                                              CAN_CTRLMODE_FD |
-                                             CAN_CTRLMODE_FD_NON_ISO;
+                                             CAN_CTRLMODE_FD_NON_ISO |
+                                             CAN_CTRLMODE_CC_LEN8_DLC;
 
                status = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_STAT_REG);
                if (!(status & KVASER_PCIEFD_KCAN_STAT_FD)) {
@@ -996,12 +1002,14 @@ static int kvaser_pciefd_handle_data_packet(struct kvaser_pciefd *pcie,
        struct can_priv *priv;
        struct net_device_stats *stats;
        u8 ch_id = FIELD_GET(KVASER_PCIEFD_PACKET_CHID_MASK, p->header[1]);
+       u8 dlc;
 
        if (ch_id >= pcie->nr_channels)
                return -EIO;
 
        priv = &pcie->can[ch_id]->can;
        stats = &priv->dev->stats;
+       dlc = FIELD_GET(KVASER_PCIEFD_RPACKET_DLC_MASK, p->header[1]);
 
        if (p->header[1] & KVASER_PCIEFD_RPACKET_FDF) {
                skb = alloc_canfd_skb(priv->dev, &cf);
@@ -1010,6 +1018,7 @@ static int kvaser_pciefd_handle_data_packet(struct kvaser_pciefd *pcie,
                        return -ENOMEM;
                }
 
+               cf->len = can_fd_dlc2len(dlc);
                if (p->header[1] & KVASER_PCIEFD_RPACKET_BRS)
                        cf->flags |= CANFD_BRS;
 
@@ -1021,14 +1030,13 @@ static int kvaser_pciefd_handle_data_packet(struct kvaser_pciefd *pcie,
                        stats->rx_dropped++;
                        return -ENOMEM;
                }
+               can_frame_set_cc_len((struct can_frame *)cf, dlc, priv->ctrlmode);
        }
 
        cf->can_id = FIELD_GET(KVASER_PCIEFD_RPACKET_ID_MASK, p->header[0]);
        if (p->header[0] & KVASER_PCIEFD_RPACKET_IDE)
                cf->can_id |= CAN_EFF_FLAG;
 
-       cf->len = can_fd_dlc2len(FIELD_GET(KVASER_PCIEFD_RPACKET_DLC_MASK, p->header[1]));
-
        if (p->header[0] & KVASER_PCIEFD_RPACKET_RTR) {
                cf->can_id |= CAN_RTR_FLAG;
        } else {