Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp267522pxv; Thu, 8 Jul 2021 20:46:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy64V4l+cD0jH6aK5362KeDhJg9EhQgm58tyWQYO/lG6IVvceKSH/sm/oy+bq2M/54qqVMH X-Received: by 2002:a05:6402:692:: with SMTP id f18mr21455865edy.327.1625802408463; Thu, 08 Jul 2021 20:46:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625802408; cv=none; d=google.com; s=arc-20160816; b=BsQ5lOi4u1IL05KYDhptPzFEpDhhn4KufmRzCeWAuMhtSNtlM3O7uqTB0HG3/eQZWE s4YPyuKmIeu6IgkXSR1AVkoxsQ+AzjXos4IWPscUrRhvOx00UcS8sgLBxxb6qpliK3Ds WwEsliRN/vgoOodskoyjvEO1GahlCGxJnCjaDL8Prth4NqL5kA1JXWInbDJDL/p7rU/K mr6C2xJAF4oFYwb7vtbR2tyBAnoS3aiGiaMf4igubwr31U4z+/QopOzrTz/5UYsGhFLI FOHsgFmbkgGxnAtrHJd7FMgqXnvbU1T61sj8xnXdfmJjEFYbXQzuybjuylhLroAlmQC6 oFZQ== 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=xkFDtexi/vMwk8I3d6YlTg5u37i8ZW2hQo1vPp5vAsk=; b=OfUeNlHFC1jOITFu9WKcRfXxn2d1kPPwV0/8DUBE1JqxKrJhir2sFGuQsna48DZnOo i1Q8/5qY4SzEzT2gVT3iENd5iUG1QsnsjBQctAxKWIzwUYPes8Y3Jn6qyWxWG16SkMnT lR22uhvE1axIrd1YXfT19ni17fcFD9r1UMZ2DEReNvLwONr/IIkosH4mAgMFt04hJ28l puKdFr2t4yWbXEKKRu1d16V/N0Rbml9tVrAFAPNxYAgcMUhBgBBTz1z0cJ1A219rGAZo tyMjo+Z0aDjvzuFxA9PRqroP1KKYwy+JKzprsWwZGsE308EHPGuciZ/AbrfPr+4lGCAX 1rsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CIGTDosx; 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 i15si5555910ejh.658.2021.07.08.20.46.22; Thu, 08 Jul 2021 20:46:48 -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=CIGTDosx; 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 S230506AbhGIDq4 (ORCPT + 99 others); Thu, 8 Jul 2021 23:46:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230462AbhGIDqz (ORCPT ); Thu, 8 Jul 2021 23:46:55 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F6A5C061574 for ; Thu, 8 Jul 2021 20:44:11 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id p4-20020a17090a9304b029016f3020d867so5308470pjo.3 for ; Thu, 08 Jul 2021 20:44:11 -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=xkFDtexi/vMwk8I3d6YlTg5u37i8ZW2hQo1vPp5vAsk=; b=CIGTDosxAQ1YjXeC3953YY48H+KIcktvFf+jUy6Mf3aKz9wBXD27lWDOaK7UCa23Hi PWHBvkvblid2DvD713/emp6BmhVjoXVyyC2KDZPIRy9bs1eHgiqQztLd+28te0uYIV/O gE66OE3UGusmNlh4Gfxj63fcFmrH7p3KLoSLwBeIpvE8SWMgRKT8LeCKgdCikjKxin4z q9sDIgDhoRtFk21Pe8VMVmq1MAZf27Vv29rcFc6f72E1AEP2hbE15ClxubOUGaXvHSWm gOn7MT3GAU2RrDIk4/5PtozgUlwa9FLExSwt7EkkI8N1iakD8beHuDX3Z8h1G3+eNNsw 36XA== 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=xkFDtexi/vMwk8I3d6YlTg5u37i8ZW2hQo1vPp5vAsk=; b=mgo7hJ4vHXC1lWViykS+JGecL0CZWzLXNvYbQqR1lPf6/zdABJotuEj3DrxDW9F/E0 gHwgcb+++mndl4eZGCKQEXp4lQUS4Clhmhf/TtBDT3PBmKi1KflFjX65thf//dGSJVkj PuZARIxx/+rhDOa0Fbjm6y950/B0kn1rIWSRcLlXdT2Vv9fBb3wKCkkSAE0W59ATxhLJ cTtO9uqlTvbefLodRxnKCaWtVPV5VKo3yNFg0i4oxusvSjt/i4999vm7/Qz7IdgL9p2D 83rBu11b+agZvAL1+vnxqfX4rZ+3FTrC1FWcPlFDiZNBtCLH9femu5ybPaA9oR9LWg/b w0MQ== X-Gm-Message-State: AOAM533gyI/eR8fwjtV6nAdmhQXJLfBun6vPDv+ADs7zWJGgRH5MKU95 ZP2Qo2gNTbLlDKdn4ZtTIkTs/A== X-Received: by 2002:a17:90a:cd01:: with SMTP id d1mr8389091pju.106.1625802250390; Thu, 08 Jul 2021 20:44:10 -0700 (PDT) Received: from localhost ([106.201.108.2]) by smtp.gmail.com with ESMTPSA id q21sm4218209pfh.26.2021.07.08.20.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jul 2021 20:44:09 -0700 (PDT) Date: Fri, 9 Jul 2021 09:14:07 +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, gregkh@linuxfoundation.org, vincent.guittot@linaro.org, alex.bennee@linaro.org Subject: Re: [PATCH v14] i2c: virtio: add a virtio i2c frontend driver Message-ID: <20210709034407.xmglkgzubrztnxsg@vireshk-i7> References: <984ebecaf697058eb73389ed14ead9dd6d38fb53.1625796246.git.jie.deng@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <984ebecaf697058eb73389ed14ead9dd6d38fb53.1625796246.git.jie.deng@intel.com> User-Agent: NeoMutt/20180716-391-311a52 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09-07-21, 10:25, Jie Deng wrote: > Add an I2C bus driver for virtio para-virtualization. > > The controller can be emulated by the backend driver in > any device model software by following the virtio protocol. > > The device specification can be found on > https://lists.oasis-open.org/archives/virtio-comment/202101/msg00008.html. > > By following the specification, people may implement different > backend drivers to emulate different controllers according to > their needs. > > Co-developed-by: Conghui Chen > Signed-off-by: Conghui Chen > Signed-off-by: Jie Deng > --- > Changes v13 -> v14 > - Put the headers in virtio_i2c.h in alphabetical order. > - Dropped I2C_FUNC_SMBUS_QUICK support. > - Dropped few unnecessary variables and checks. > - Use "num" everywhere instead of num or nr, to be consistent. > - Added few comments which make the design more clear. Thanks a lot for following this up so far :) > +static int virtio_i2c_prepare_reqs(struct virtqueue *vq, > + struct virtio_i2c_req *reqs, > + struct i2c_msg *msgs, int num) > +{ > + struct scatterlist *sgs[3], out_hdr, msg_buf, in_hdr; > + int i; > + > + for (i = 0; i < num; i++) { > + int outcnt = 0, incnt = 0; > + > + /* > + * We don't support 0 length messages and so masked out > + * I2C_FUNC_SMBUS_QUICK in virtio_i2c_func(). > + */ > + if (!msgs[i].len) > + break; > + > + /* > + * 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 != num - 1) > + reqs[i].out_hdr.flags = cpu_to_le32(VIRTIO_I2C_FLAGS_FAIL_NEXT); > + > + 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); > + > + 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; > + > + if (virtqueue_add_sgs(vq, sgs, outcnt, incnt, &reqs[i], GFP_KERNEL)) { > + i2c_put_dma_safe_msg_buf(reqs[i].buf, &msgs[i], false); > + break; > + } > + } > + > + return i; > +} Wolfram, in case you wonder why we don't error out early as discussed earlier, then ... > +static int virtio_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, > + int num) > +{ ... > + /* > + * For the case where count < num, i.e. we weren't able to queue all the > + * msgs, ideally we should abort right away and return early, but some > + * of the messages are already sent to the remote I2C controller and the > + * virtqueue will be left in undefined state in that case. We kick the > + * remote here to clear the virtqueue, so we can try another set of > + * messages later on. > + */ ... here is the reasoning for that. Please see if you can still get it merged into 5.14-rc1/2. Thanks. Reviewed-by: Viresh Kumar Tested-by: Viresh Kumar -- viresh