Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp288357pxv; Wed, 30 Jun 2021 21:06:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4wMmegZj/KKHabzrTkzwa/X+LD3DzZ5NEhMLia7sb3sYEs48qy4HBV6j90AmQV83Fulxe X-Received: by 2002:aa7:c70d:: with SMTP id i13mr51251318edq.249.1625112402831; Wed, 30 Jun 2021 21:06:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625112402; cv=none; d=google.com; s=arc-20160816; b=oFV7J8xyUGu/5yZXAGrCk1DqvJds55MNaXovUJe2OGkwcDEXeM6BLbYS6hal0IU3bC M09QtDF+K3YGcTI5fpuOrPAVZYxilHGeuafs3UCMXprpYoxZ8DRKK3HRMFiU2LSnTV4G xq4y+86/YHNq6pBQ7g9OatdLbFRxwDzfAc8fjpAAcpLYW3ZtMoirj1Sq5E5X08bzqxqi 71aoIE7+jdmZCGMkx/XaEjiUvioZBJnNrIyfidgqBM4IxO0JNAI04on5YRYWa5+PnDSW B9vucrB2TxDEVNqVtslXJpA2p7bs8R2AKKAsf8IGTPfmiF8RH+1jgV4pzy15w9d8j9oJ nuqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=tlLiC0/suIzFL9Kc0HiGXCJ9guNpwuTifmDbO7ccBmk=; b=YoO/Yt4ZIlYdWYFCTCu/e6A70cw2/HGzvzMLOOQOnySqvuj/jbjrhleMs5/NkeGv1F adxq3edkKcPAh2S98YEg48bdzbRn/X0uMOQLr6cjxoxIktgxQoIYUsit6n18bHvJ49rX krMD97kGlbALDTFly8n0ml8WZiWnF3h9Bzi255k7o64fci06IiPvWWYYIi84Z1v7lDT0 v9FBVijnH7ClwgA5HBeBrHLVem7V8Kg8goLxsTVxQzTVZzHSMCSD2PXehfEIsHCq5ZjT yD6ZZwD25yy9RUSxS5bs/+gfVzlyKEhaclq/7JMIWdB3gioNMWgN+xibEXZYqZiz/nRQ n3XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GjsPDXLq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hd32si2280871ejc.260.2021.06.30.21.06.19; Wed, 30 Jun 2021 21:06:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GjsPDXLq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229664AbhGAEHK (ORCPT + 99 others); Thu, 1 Jul 2021 00:07:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229577AbhGAEHJ (ORCPT ); Thu, 1 Jul 2021 00:07:09 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10CBAC061756 for ; Wed, 30 Jun 2021 21:04:39 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id q91so3449177pjk.3 for ; Wed, 30 Jun 2021 21:04:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=tlLiC0/suIzFL9Kc0HiGXCJ9guNpwuTifmDbO7ccBmk=; b=GjsPDXLqMMYdUtQ04S9QypWLzNfxSIdZN+wtJfxqs98oJc5FP3ISRbX2vsRPb4PlIW vEvCOlQb4NcDvwQh5ovIc6R2cKiIg/jsRX7gUTseHHRA8lYhQejsePqoDy5Z3Rh8pXKc z4Yt71s9d61EOaJklZX8BRcv2MrKq67YrL/S19LYhy4+A9066tuu43r7Efu/+SjFbuBy 3TYYVI/ZhG/3Sguxn9jXBA6u9DqiuKUwNnHi7164E4LbbRuHY8X8qHTZMPCIBcLjAdDs FIXOytssI5Ir/j4ocrqCrh8rXPlWkphvsLk6m2qOpsh/vq3gA0a1sW2PmFdFyjEF63Am VofQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=tlLiC0/suIzFL9Kc0HiGXCJ9guNpwuTifmDbO7ccBmk=; b=IukpJGg6Ti3jrywHf1gTt1LXDQKAEZ88t3lFvMumRS1fVH13pYO8Qm1sEBSSPYEUge BZcGiik9YLbl5W/NUxqZ573m3q59u464y6xugPnLihK5aKfaJn9YJ0xxB5YyOCLW/9SH vdr20jTtGxEsCyt+UnifebXeX1e3HS1oiK2hx7GEFu7u1cYd813qhP/wnIowv5CvS5B1 rUphH1/krs0nMazoYm7VoOnI65quR+cdf2C3N/0ZdSE9uXBDyOVzh9OxY3cojElbpMg7 1zX+jsZCtjbOdQ4/rAERzF1XlTr52kkbsv8Je2zJi+8hzrEXTc4m52gSKnpBDa42aHvO 1jjg== X-Gm-Message-State: AOAM532UZmj+GVkp/agx/VP0ie+u/1yWPtUM64FIhZcQzArzljTja0L+ H4nTB26B5w857q2tUQxE5v9u4w== X-Received: by 2002:a17:90b:2504:: with SMTP id ns4mr8022103pjb.140.1625112278476; Wed, 30 Jun 2021 21:04:38 -0700 (PDT) Received: from localhost ([106.201.108.2]) by smtp.gmail.com with ESMTPSA id q7sm17404549pfk.192.2021.06.30.21.04.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 21:04:38 -0700 (PDT) Date: Thu, 1 Jul 2021 09:34:36 +0530 From: Viresh Kumar To: Jie Deng Cc: linux-i2c@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, wsa@kernel.org, wsa+renesas@sang-engineering.com, mst@redhat.com, arnd@arndb.de, jasowang@redhat.com, andriy.shevchenko@linux.intel.com, yu1.wang@intel.com, shuo.a.liu@intel.com, conghui.chen@intel.com, stefanha@redhat.com Subject: Re: [PATCH v11] i2c: virtio: add a virtio i2c frontend driver Message-ID: <20210701040436.p7kega6rzeqz5tlm@vireshk-i7> References: <510c876952efa693339ab0d6cc78ba7be9ef6897.1625104206.git.jie.deng@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <510c876952efa693339ab0d6cc78ba7be9ef6897.1625104206.git.jie.deng@intel.com> User-Agent: NeoMutt/20180716-391-311a52 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01-07-21, 11:24, Jie Deng wrote: > Changes v10 -> v11 > - Remove vi->adap.class = I2C_CLASS_DEPRECATED. > - Use #ifdef CONFIG_PM_SLEEP to replace the "__maybe_unused". > - Remove "struct mutex lock" in "struct virtio_i2c". > - Support zero-length request. > - Remove unnecessary logs. > - Remove vi->adap.timeout = HZ / 10, just use the default value. > - Use BIT(0) to define VIRTIO_I2C_FLAGS_FAIL_NEXT. > - Add the virtio_device index to adapter's naming mechanism. Thanks Jie. I hope you are going to send a fix for specification as well (for the zero-length request) ? > diff --git a/drivers/i2c/busses/i2c-virtio.c b/drivers/i2c/busses/i2c-virtio.c > +static int virtio_i2c_send_reqs(struct virtqueue *vq, > + struct virtio_i2c_req *reqs, > + struct i2c_msg *msgs, int nr) > +{ > + struct scatterlist *sgs[3], out_hdr, msg_buf, in_hdr; > + int i, outcnt, incnt, err = 0; > + > + for (i = 0; i < nr; i++) { > + /* > + * Only 7-bit mode supported for this moment. For the address format, > + * Please check the Virtio I2C Specification. > + */ > + reqs[i].out_hdr.addr = cpu_to_le16(msgs[i].addr << 1); > + > + if (i != nr - 1) > + reqs[i].out_hdr.flags = cpu_to_le32(VIRTIO_I2C_FLAGS_FAIL_NEXT); > + > + outcnt = incnt = 0; > + sg_init_one(&out_hdr, &reqs[i].out_hdr, sizeof(reqs[i].out_hdr)); > + sgs[outcnt++] = &out_hdr; > + > + reqs[i].buf = i2c_get_dma_safe_msg_buf(&msgs[i], 1); > + if (!reqs[i].buf) > + break; > + > + sg_init_one(&msg_buf, reqs[i].buf, msgs[i].len); The len can be zero here for zero-length transfers. > + > + if (msgs[i].flags & I2C_M_RD) > + sgs[outcnt + incnt++] = &msg_buf; > + else > + sgs[outcnt++] = &msg_buf; > + > + sg_init_one(&in_hdr, &reqs[i].in_hdr, sizeof(reqs[i].in_hdr)); > + sgs[outcnt + incnt++] = &in_hdr; Why are we still sending the msg_buf if the length is 0? Sending the buffer makes sense if you have some data to send, but otherwise it is just an extra sg element, which isn't required to be sent. > + > + err = virtqueue_add_sgs(vq, sgs, outcnt, incnt, &reqs[i], GFP_KERNEL); > + if (err < 0) { > + i2c_put_dma_safe_msg_buf(reqs[i].buf, &msgs[i], false); > + break; > + } > + } > + > + return i; I just noticed this now, but this function even tries to send data partially, which isn't right. If the caller (i2c device's driver) calls this for 5 struct i2c_msg instances, then all 5 need to get through or none.. where as we try to send as many as possible here. This looks broken to me. Rather return an error value here on success, or make it complete failure. Though to be fair I see i2c-core also returns number of messages processed from i2c_transfer(). Wolfram, what's expected here ? Shouldn't all message transfer or none? > +#ifdef CONFIG_PM_SLEEP > +static int virtio_i2c_freeze(struct virtio_device *vdev) > +{ > + virtio_i2c_del_vqs(vdev); > + return 0; > +} > + > +static int virtio_i2c_restore(struct virtio_device *vdev) > +{ > + return virtio_i2c_setup_vqs(vdev->priv); > +} > +#endif > + > +static struct virtio_driver virtio_i2c_driver = { > + .id_table = id_table, > + .probe = virtio_i2c_probe, > + .remove = virtio_i2c_remove, > + .driver = { > + .name = "i2c_virtio", > + }, > +#ifdef CONFIG_PM_SLEEP You could avoid this pair of ifdef by creating dummy versions of below routines for !CONFIG_PM_SLEEP case. Up to you. > + .freeze = virtio_i2c_freeze, > + .restore = virtio_i2c_restore, > +#endif > +}; -- viresh