Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1404048rwd; Sun, 14 May 2023 19:26:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4JdKcoO2nOv3XXGI0/KpoYtULgRVK0iLaV/NMnvYXfA+Xi+p/DHnvzky8eJ+UARa+h2mgN X-Received: by 2002:a17:902:eb4b:b0:1a6:7632:2b20 with SMTP id i11-20020a170902eb4b00b001a676322b20mr33976044pli.40.1684117599089; Sun, 14 May 2023 19:26:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684117599; cv=none; d=google.com; s=arc-20160816; b=aaIsoktbiVVPmAcgkXdI8RgAqC2BHHuk7tlSkT5qt04BHMBv8UTMILWuQUZLIF6Yp0 Fn9K9GxIQ8Zk6HqnCfuCCzkBlngo2beLFAnH6dHmqYa47yd+fqYpxHYf7d5HDRQGcoMK w4lZavECoooN+0ykAMcQdOAzDebvboPcCqQznRqHDz2EXPMwwICWbcfwz2sMfsabhnr1 8rPFAJesRNaabb3T+plbeEIIMAlUabQ5NiSnAjlHmHTt/k9FclW3eaPo6i86U6XkhfaG KChjWGAyIScikz8Pn6kAWUqwddkHc+75xaKJSdtsw5SegooakPQqhJ3LYgxgSKIse6mZ SXyQ== 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; bh=oToW+Q4w2tcSTz/9eetaZ91mGtQUL7Hi7EcIr13WLLY=; b=l2xwQ7Fo9c4Bphcw2fu9QjVco3fCBtGGrV1LE8fps7OUYmiAxkDp9F2pj8LseQgZas 0DqcnP//sz5c2y9jD5lKBxHdFyJdGcGt2MT4WbbO6AIzGsAgYfoUbYM4zXaSP14CixUw daKukvTMP3mDEfwECPvccdVWvp3aVg3LWZw6MuNbD63RAae0qKldMFgLGSVXWPXPrFRW tcG5w3KInVAbib2Q7VXxF5Q4iKQsPdTPoGXbVFv2Ic90AJ8qtQrMmag6vRvKsgvaCZni Mz2kmeJ/HLh7rHzRLKiIkWlrF5C9CrSZLsRLjWMHnT+tJzvFOCma/HPXdPHwNBEgnCEN 9o7g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e19-20020a170902f1d300b001addf547a59si7022278plc.0.2023.05.14.19.26.26; Sun, 14 May 2023 19:26:39 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230166AbjEOB5w (ORCPT + 99 others); Sun, 14 May 2023 21:57:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230094AbjEOB5v (ORCPT ); Sun, 14 May 2023 21:57:51 -0400 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 086941734; Sun, 14 May 2023 18:57:50 -0700 (PDT) Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-643ac91c51fso7743219b3a.1; Sun, 14 May 2023 18:57:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684115869; x=1686707869; 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=oToW+Q4w2tcSTz/9eetaZ91mGtQUL7Hi7EcIr13WLLY=; b=IeAqc4bkRD+CGHO0/OkA63XOZdxiNLgVzDEoPQ04abKwDM4irCbhiP1/vpL4RbznEs 6AqbTg5YcE2szlWG8lg/m1JjAJ4JZSszXh3SlFsMMuCqP0xGow/gpqKPDACas414aYGB 7VLlyRkOnoJfIU4BdAu2DMSwvGxzDjBPj2CfXrcXMmQbdzVuR4qw3C67O71vL3MHn3YQ qOwjnkOcqpIcyvxprfQun8QqWp2Y7vatHgyJ8qBcHp0U0JmfrRmG7+IAy5qmBsZP+2ig /CveHKzRmM1AkcS3ZxNts7DcYxok/NDYobMMNTri8eWDQO7wBYn8Y4ScpZwN+PidI7Va kLHw== X-Gm-Message-State: AC+VfDwMYaOXD+Lza1y0B2MtJnBHqKQ0raxrbEtQqPwOl+rfYisnwTJs BFVZdjEHp6Win0QDwQ1b+480qG5mLF3+7rEVKDQ= X-Received: by 2002:a05:6a20:748c:b0:104:ffd0:2338 with SMTP id p12-20020a056a20748c00b00104ffd02338mr8596245pzd.26.1684115869303; Sun, 14 May 2023 18:57:49 -0700 (PDT) MIME-Version: 1.0 References: <20230511151444.162882-1-Mikhail.Golubev-Ciuchea@opensynergy.com> <3950ac4f-3292-e6ca-7484-77f3a5639305@opensynergy.com> In-Reply-To: <3950ac4f-3292-e6ca-7484-77f3a5639305@opensynergy.com> From: Vincent MAILHOL Date: Mon, 15 May 2023 10:57:38 +0900 Message-ID: Subject: Re: [RFC PATCH v3] can: virtio: Initial virtio CAN driver. To: Harald Mommer Cc: Mikhail Golubev-Ciuchea , virtio-dev@lists.oasis-open.org, linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, Wolfgang Grandegger , Marc Kleine-Budde , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S . Tsirkin" , Jason Wang , Damir Shaikhutdinov Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 Sat. 13 May 2023 at 23:18, Harald Mommer wrote: > Hello Vincent, > > sometimes it's close to weekend and already late. I've to correct myself. Yeah... I understand that. There is no hurry to answer quickly (and this is why you see my answer just today). Hope you had a restful weekend. > On 12.05.23 11:53, Vincent MAILHOL wrote: > > > >> +static netdev_tx_t virtio_can_start_xmit(struct sk_buff *skb, > >> + struct net_device *dev) > >> +{ > >> + struct virtio_can_priv *priv = netdev_priv(dev); > >> + struct canfd_frame *cf = (struct canfd_frame *)skb->data; > >> + struct virtio_can_tx *can_tx_msg; > >> + struct virtqueue *vq = priv->vqs[VIRTIO_CAN_QUEUE_TX]; > >> + struct scatterlist sg_out[1]; > >> + struct scatterlist sg_in[1]; > >> + struct scatterlist *sgs[2]; > This 2 here. > > > >> + /* Normal queue stop when no transmission slots are left */ > >> + if (atomic_read(&priv->tx_inflight) >= priv->can.echo_skb_max || > >> + vq->num_free == 0 || (vq->num_free < 2 && > > Replace the Magic number 2 with a #define. > > Is this 2 here. > > Obviously with my previous answer I switched into panic mode thinking > already about explaining indirect descriptors and all kind of virtio > details and the expression in depth not realizing any more that > something different was requested. > > Appropriate answer: > > /* CAN TX needs 2 descriptors: 1 device readable and 1 device writable */ > #define CAN_TX_DESC (1 + 1) > > Or something with ARRAY_SIZE(sgs) to get the number of elements in sgs > keeping the first 2 above. ARRAY_SIZE(sgs) looks good! It is better than a #define. > And then I'll have to think again whether I really want to keep > sgs_in[1] and sgs_out[1] as arrays. Not now, now is weekend. > > >> + !virtio_has_feature(vq->vdev, VIRTIO_RING_F_INDIRECT_DESC))) { > >> + netif_stop_queue(dev); > >> + netdev_dbg(dev, "TX: Normal stop queue\n"); > >> + } > >> + > >> + spin_unlock_irqrestore(&priv->tx_lock, flags); > >> + > >> +kick: > >> + if (netif_queue_stopped(dev) || !netdev_xmit_more()) { > >> + if (!virtqueue_kick(vq)) > >> + netdev_err(dev, "%s(): Kick failed\n", __func__); > >> + } > >> + > >> + return xmit_ret; > >> +} > >>