Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1354371rwb; Mon, 7 Nov 2022 00:12:10 -0800 (PST) X-Google-Smtp-Source: AMsMyM7uHAwrztHmZIUDcLElGnBDcaPKa6rboygHfKDNGh5Wmhp6meHRl++fTMZwHJAjKaSdgAJq X-Received: by 2002:a17:902:c946:b0:186:7070:8ab4 with SMTP id i6-20020a170902c94600b0018670708ab4mr759578pla.23.1667808730351; Mon, 07 Nov 2022 00:12:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667808730; cv=none; d=google.com; s=arc-20160816; b=vjozlmcpknl1tbs05jjK6ETd2y/ej/2omhUkMQKUT03XPuov9GXqNgEhHT0bGBPJtq YMgbbumMyjrEJ+dFuDWJqLGd7Io5/q2w6i3v6cNR1CkjtspxP0x25XKluYLZAUzK+MVf IKyTztn9cGbZytMjaYUa6pzjpyf8+p1LdXZZXBE0qazbItrmcvyT7bfMejxSdZDiL0PI MXRd6YmnzJx1cRzpsI4mZl+PuFZCxUET8MhIzQ7O7+95LEeN3MvEUDtb7eoHWlIwkINL zdApmUOXtL/qt+oWAQM48K+r3ZFtFq1Hsafqj5oY5da23/ccQR2SzELU5ZIPLWe2R87u 0uQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=G/umIMIn7QwrlwD2FDIhmw1+/5xDnupaEF2D59WiIPc=; b=HgR15ow9ygh0Duh/lhboQv/olrw1tAQ1OVB/+oAxprclKOhbfcLCCUqeWyPVMX4EwE v30u9iF6b9vd8HhjOcize6SexMGjshBrFqpsqI/iv4FMLmI6UGJJYED/y3LHtkm0lzcK NUl+f23IRPVlX/wPe7II6pEY9frsaiO/151inVHIJYb8gm85Wi8T72DWS2AddDzwMYgI MOXBZ/YyoibDbBzdjomFoIrNqnhqYBsu+jfrShYZKQXcf+iRSuyUf8mnJf7hnAwrwuhq C3H0R40hq2ZOkHf1UoQFL0Qjp8sZaOoEdYE5zFpkLwqgbe//q0Q+qfNi9ifjuegBmiKv +Avw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=l+EtDMmH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q197-20020a632ace000000b00439c930538csi9960734pgq.85.2022.11.07.00.11.58; Mon, 07 Nov 2022 00:12:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=l+EtDMmH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231307AbiKGHfi (ORCPT + 95 others); Mon, 7 Nov 2022 02:35:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230425AbiKGHfe (ORCPT ); Mon, 7 Nov 2022 02:35:34 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1839D5F51; Sun, 6 Nov 2022 23:35:34 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id d20so9243961plr.10; Sun, 06 Nov 2022 23:35:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=G/umIMIn7QwrlwD2FDIhmw1+/5xDnupaEF2D59WiIPc=; b=l+EtDMmHV9cHEOQG0c94ZKw1JCVIHlaQzH3tZnG8YAVl75UUfldCWY3V2KLqE6VYQF SmmeA4ZBFO72tKpyDtSp3yacShaOOT93R1tjnMnHTymYP3zZBRf9xuvlLEQs965aY0Wn ADVG28tv8/Dvde//Wnioboh8llwH28Bs/S6v603EQ6zTCXFlsOzvJJPSIhmdFt6NjJOI UncThvRnXAMCz30Qwv0pq/jOq0+OshbqO+YZXPv/ZfjP1JtPzmwmid3gKBfRhAvqfjez x3Glna43AtzxUaUMlFsh9zVGvIvJFtGvERvujei3rLTCcwI/nCAZ0tap6jBHAx0VTAxW y4uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=G/umIMIn7QwrlwD2FDIhmw1+/5xDnupaEF2D59WiIPc=; b=rgm/9gLAkAuxXNpBDW3Z86PiXaR+//hOyuHABBbt7ErOMjugU7BRmOmkxRgUojSYjF GRvSy6TWbOsvB135aOkxgzK69p3wTbXp8NS1GCaKNuG7L7ok2i/gKoKE2DZ+fHGJ8U/U oOpzioa22+UmrpcI8NUdOubcDW6h4r/A8ESqOEb07rhwA6fJNual7zVybXKmoh1UPD9t C2l+gIZa1BhoN/plX4NzCeh1BsNquqgbb0rNmgm+Sfob8WKExJf/pw8VlzvcubvrFKIy GDOEiLnVa5nSskzwuH1BIOhFuEXKWzUIoh2IHIu+BqcSTyTX+ds1PwZDkjEVvO3B6smp gD5w== X-Gm-Message-State: ACrzQf3I6DJw10TZk1P7UWz3z/ALLGkKLykDj7+7V6bOLqLQGJhAPY0A e4dV6Wy/t2fA0QeJ97mRrjrSFhUz2G5++aRqAik= X-Received: by 2002:a17:90b:4ac3:b0:213:3918:f276 with SMTP id mh3-20020a17090b4ac300b002133918f276mr65419929pjb.19.1667806533470; Sun, 06 Nov 2022 23:35:33 -0800 (PST) MIME-Version: 1.0 References: <20221104172421.8271-1-Harald.Mommer@opensynergy.com> <20221104172421.8271-2-Harald.Mommer@opensynergy.com> <4782632.31r3eYUQgx@steina-w> In-Reply-To: <4782632.31r3eYUQgx@steina-w> From: Vincent Mailhol Date: Mon, 7 Nov 2022 16:35:22 +0900 Message-ID: Subject: Re: [RFC PATCH v2 1/2] can: virtio: Initial virtio CAN driver. To: Alexander Stein Cc: virtio-dev@lists.oasis-open.org, linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Harald Mommer , Wolfgang Grandegger , Marc Kleine-Budde , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Dariusz Stojaczyk , Damir Shaikhutdinov Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon. 7 Nov. 2022 at 16:15, Alexander Stein wrote: > Am Freitag, 4. November 2022, 18:24:20 CET schrieb Harald Mommer: > > From: Harald Mommer > > > > - CAN Control > > > > - "ip link set up can0" starts the virtual CAN controller, > > - "ip link set up can0" stops the virtual CAN controller > > > > - CAN RX > > > > Receive CAN frames. CAN frames can be standard or extended, classic or > > CAN FD. Classic CAN RTR frames are supported. > > > > - CAN TX > > > > Send CAN frames. CAN frames can be standard or extended, classic or > > CAN FD. Classic CAN RTR frames are supported. > > > > - CAN Event indication (BusOff) > > > > The bus off handling is considered code complete but until now bus off > > handling is largely untested. > > > > This is version 2 of the driver after having gotten review comments. > > > > Signed-off-by: Harald Mommer > > Cc: Damir Shaikhutdinov [...] > > diff --git a/include/uapi/linux/virtio_can.h > > b/include/uapi/linux/virtio_can.h new file mode 100644 > > index 000000000000..0ca75c7a98ee > > --- /dev/null > > +++ b/include/uapi/linux/virtio_can.h > > @@ -0,0 +1,69 @@ > > +/* SPDX-License-Identifier: BSD-3-Clause */ > > +/* > > + * Copyright (C) 2021 OpenSynergy GmbH > > + */ > > +#ifndef _LINUX_VIRTIO_VIRTIO_CAN_H > > +#define _LINUX_VIRTIO_VIRTIO_CAN_H > > + > > +#include > > +#include > > +#include > > +#include > > + > > +/* Feature bit numbers */ > > +#define VIRTIO_CAN_F_CAN_CLASSIC 0u > > +#define VIRTIO_CAN_F_CAN_FD 1u > > +#define VIRTIO_CAN_F_LATE_TX_ACK 2u > > +#define VIRTIO_CAN_F_RTR_FRAMES 3u > > + > > +/* CAN Result Types */ > > +#define VIRTIO_CAN_RESULT_OK 0u > > +#define VIRTIO_CAN_RESULT_NOT_OK 1u > > + > > +/* CAN flags to determine type of CAN Id */ > > +#define VIRTIO_CAN_FLAGS_EXTENDED 0x8000u > > +#define VIRTIO_CAN_FLAGS_FD 0x4000u > > +#define VIRTIO_CAN_FLAGS_RTR 0x2000u > > + > > +/* TX queue message types */ > > +struct virtio_can_tx_out { > > +#define VIRTIO_CAN_TX 0x0001u > > + __le16 msg_type; > > + __le16 reserved; > > + __le32 flags; > > + __le32 can_id; > > + __u8 sdu[64u]; > > 64u is CANFD_MAX_DLEN, right? Is it sensible to use that define instead? > I guess if CAN XL support is to be added at some point, a dedicated struct is > needed, to fit for CANXL_MAX_DLEN (2048 [1]). > > [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ > commit/?id=1a3e3034c049503ec6992a4a7d573e7fff31fac4 To add to Alexander's comment, what is the reason to have the msg_type flag? The struct can_frame, canfd_frame and canxl_frame are done such that it is feasible to decide the type (Classic, FD, XL) from the content of the structure. Why not just reusing the current structures? > > +}; > > + > > +struct virtio_can_tx_in { > > + __u8 result; > > +}; > > + > > +/* RX queue message types */ > > +struct virtio_can_rx { > > +#define VIRTIO_CAN_RX 0x0101u > > + __le16 msg_type; > > + __le16 reserved; > > + __le32 flags; > > + __le32 can_id; > > + __u8 sdu[64u]; > > +}; > > I have no experience with virtio drivers, but is there a need for dedicated > structs for Tx and Rx? They are identical anyway. > > Best regards, > Alexander > > > + > > +/* Control queue message types */ > > +struct virtio_can_control_out { > > +#define VIRTIO_CAN_SET_CTRL_MODE_START 0x0201u > > +#define VIRTIO_CAN_SET_CTRL_MODE_STOP 0x0202u > > + __le16 msg_type; > > +}; > > + > > +struct virtio_can_control_in { > > + __u8 result; > > +}; > > + > > +/* Indication queue message types */ > > +struct virtio_can_event_ind { > > +#define VIRTIO_CAN_BUSOFF_IND 0x0301u > > + __le16 msg_type; > > +}; > > + > > +#endif /* #ifndef _LINUX_VIRTIO_VIRTIO_CAN_H */