can: canxl: update CAN infrastructure for CAN XL frames
[platform/kernel/linux-starfive.git] / net / can / af_can.c
index 072a6a5..9503ab1 100644 (file)
@@ -202,7 +202,9 @@ int can_send(struct sk_buff *skb, int loop)
        struct can_pkg_stats *pkg_stats = dev_net(skb->dev)->can.pkg_stats;
        int err = -EINVAL;
 
-       if (can_is_can_skb(skb)) {
+       if (can_is_canxl_skb(skb)) {
+               skb->protocol = htons(ETH_P_CANXL);
+       } else if (can_is_can_skb(skb)) {
                skb->protocol = htons(ETH_P_CAN);
        } else if (can_is_canfd_skb(skb)) {
                struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
@@ -702,6 +704,21 @@ static int canfd_rcv(struct sk_buff *skb, struct net_device *dev,
        return NET_RX_SUCCESS;
 }
 
+static int canxl_rcv(struct sk_buff *skb, struct net_device *dev,
+                    struct packet_type *pt, struct net_device *orig_dev)
+{
+       if (unlikely(dev->type != ARPHRD_CAN || (!can_is_canxl_skb(skb)))) {
+               pr_warn_once("PF_CAN: dropped non conform CAN XL skbuff: dev type %d, len %d\n",
+                            dev->type, skb->len);
+
+               kfree_skb(skb);
+               return NET_RX_DROP;
+       }
+
+       can_receive(skb, dev);
+       return NET_RX_SUCCESS;
+}
+
 /* af_can protocol functions */
 
 /**
@@ -826,6 +843,11 @@ static struct packet_type canfd_packet __read_mostly = {
        .func = canfd_rcv,
 };
 
+static struct packet_type canxl_packet __read_mostly = {
+       .type = cpu_to_be16(ETH_P_CANXL),
+       .func = canxl_rcv,
+};
+
 static const struct net_proto_family can_family_ops = {
        .family = PF_CAN,
        .create = can_create,
@@ -865,6 +887,7 @@ static __init int can_init(void)
 
        dev_add_pack(&can_packet);
        dev_add_pack(&canfd_packet);
+       dev_add_pack(&canxl_packet);
 
        return 0;