Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp875643pxb; Tue, 1 Feb 2022 12:13:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJw3q+5dFBv0MOluENMlt0k3PmTH0qSJAw0OI2erVme/nl0JpN2+DG6qj5sjtJ7O6sWCG+WK X-Received: by 2002:a63:9346:: with SMTP id w6mr22268887pgm.65.1643746411790; Tue, 01 Feb 2022 12:13:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643746411; cv=none; d=google.com; s=arc-20160816; b=dRCLrXDXdHAJNkQdIKgKto8EgPD2HxGq7qMjA1uRMSZe8Y1LHJsa1aCHjS2IUUfGni OvcTL6Wwb6cIC75wNg4kOIGJO224QzSwBwme5d8IAs8n8QYg/PQmVN32hp84AKWQ/EGZ AI3B5qUJhDdCDNYNLlOx1cVPkJxGHQiqaVCfy1OHm3nCTtVNzvI8z2XkDf+VXMVFFEgr Qy5UJTxB7qZ1i2qPWqbLhdqTnWW68orADB/H5RyGUt9GwWVj6JnD7wFeYU6WqwHHNjvM p8T6NKkfQU2bcaTGlAurtlLCJmj9B065Lo8T7/TeZD8FCV8E7vaM05ef4nlFPGAC63OD xtVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=/4FIhrzPl2pkQFAAhaZP7iIv/6qR95SaVWHtftnRGBs=; b=kNvbW65Ak81jQTnUHERJC8YEJIFsKe60T7uwE9++EjSurLusvJolL+5ODQGkVD85B0 VROhg0MPerR0DVhT2oTROeW9/sLFO2/KoP021p+2Y5dGaJ6cpEWX/Q/4rS8sDeIppczx IJJ3IfhL09m3aCrCtyr+GAHuqOtLFzMcsiDmlsu7Ma4KR0eMEVWTF81+kIDwCn4gsAXh /sfvu5usXpxCOaKtpgfvQlDcL3t2KrwamHrvl8ZkhmowTkM6wB92Di6IdnUgODq1fNBr h2HD0wezfrer+o+0CV2ny3kI/LwoCXNhDkpfmlzlD7ytK3WUP1bbP+n72lu75yD6FDMu 9Hkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf-com.20210112.gappssmtp.com header.s=20210112 header.b=05zQRZk3; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i2si3324820pla.84.2022.02.01.12.13.14; Tue, 01 Feb 2022 12:13:31 -0800 (PST) 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=@semihalf-com.20210112.gappssmtp.com header.s=20210112 header.b=05zQRZk3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377375AbiAaMKr (ORCPT + 99 others); Mon, 31 Jan 2022 07:10:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376627AbiAaMKN (ORCPT ); Mon, 31 Jan 2022 07:10:13 -0500 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11A13C06174A for ; Mon, 31 Jan 2022 04:10:13 -0800 (PST) Received: by mail-pg1-x52e.google.com with SMTP id e9so12079954pgb.3 for ; Mon, 31 Jan 2022 04:10:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=/4FIhrzPl2pkQFAAhaZP7iIv/6qR95SaVWHtftnRGBs=; b=05zQRZk3/8/Zb9Roy3RfNfi4qT5k7S7AOipuFtI6WtOtGTjspmvO7tlg3c2klgCKHz WFNfFMbZWdyEI7DrNsn5UgaGNRDqgM20I4ETc7qQjCw65G7KqyVpJI9b05LHVtWA6YJF K/gQaD1qtTB8+20RCKBYHbMjxgTpHD4ctEix1eNtsZIFUy9faEjaLEMW1tK1ImMSUfh7 6NU1796vQlWrKPQD/oOvh5HU8y4VgoHPn2+tsHtica0muSsGYES+UwyBI9S63If0vg5w /+L9jdI2osyP31IaTAMDd9j/O1jOvKefcpcuQcMtGZIM4/MI29C/KYLiEpAripzriByH tVYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=/4FIhrzPl2pkQFAAhaZP7iIv/6qR95SaVWHtftnRGBs=; b=oaEo6nhFrAlmGN0+UKsRvAjrTUpmSBRrzBvmBw22NsFNVUgyY85HGB+4XhyCtlvquz LxJ+FwvmQunIayoTFFa+eDks6J3b1XdIBNiG3xsAcnL+oIpIGI799Q2e1NeMZIa/wV/z IItpOY9XtYOEo9ocqHUyN0Cw6+gPqsrzlS5ByavsVYjSGCue9t/NOX4G0vL1he9YoLMV bQ28Y7RMaVFi+29loM6VpjkocPzAnWyvKYxAG9FUGmXgWzTEKHDUzn5U14OKJAZAcYX7 WLcREPVHeNKUlfClyNXjNKM2pG99Cnasm6IQ2llb0nV8yy+M+8R+FrWUIe4umljCAirK YjIw== X-Gm-Message-State: AOAM533PEmaVgmBF9vwDSWtUQ6QPjVwgWuA+ZjIPvrAnNAXBxWpefT27 84fIj9QAi04XWB+9wXaR/h9h9iMZiVNBUxWt3HbisQ== X-Received: by 2002:a05:6a00:2408:: with SMTP id z8mr18846694pfh.68.1643631012444; Mon, 31 Jan 2022 04:10:12 -0800 (PST) MIME-Version: 1.0 References: <20220120001621.705352-2-jsd@semihalf.com> <20220128144811.783279-1-jsd@semihalf.com> <20220128144811.783279-3-jsd@semihalf.com> In-Reply-To: From: =?UTF-8?B?SmFuIETEhWJyb8Wb?= Date: Mon, 31 Jan 2022 13:10:01 +0100 Message-ID: Subject: Re: [PATCH v2 2/2] i2c: designware: Add AMD PSP I2C bus support To: Andy Shevchenko Cc: Linux Kernel Mailing List , linux-i2c , Jarkko Nikula , Mika Westerberg , Hans de Goede , Wolfram Sang , Raul E Rangel , Marcin Wojtas , Grzegorz Jaszczyk , upstream@semihalf.com, Tom Lendacky , "Deucher, Alexander" , "Easow, Nimesh" , "Limonciello, Mario" , kernel test robot Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Aargh.. so if this won't be enough to use wrong email address in v2 - I not used plain text above. Mailing list (understandably) aren't happy with this, thus resending my answers to Andy.. Again sorry for noise. pt., 28 sty 2022 o 16:50 Andy Shevchenko napisa=C5=82(a): > > On Fri, Jan 28, 2022 at 03:59:40PM +0100, Jan D=C4=85bro=C5=9B wrote: > > Hi, > > > > Adding proper Andy's email address (and removing wrong one) in the > > whole patchset. Sorry for noise! > > Thanks! > > > pt., 28 sty 2022 o 15:48 Jan Dabros napisa=C5=82(a): > > > > > > Implement an I2C controller sharing mechanism between the host (kerne= l) > > > and PSP co-processor on some platforms equipped with AMD Cezanne SoC. > > > > > > On these platforms we need to implement "software" i2c arbitration. > > > Default arbitration owner is PSP and kernel asks for acquire as well > > > as inform about release of the i2c bus via mailbox mechanism. > > > > > > +---------+ > > > <- ACQUIRE | | > > > +---------| CPU |\ > > > | | | \ +----------+ SDA > > > | +---------+ \ | |------- > > > MAILBOX +--> | I2C-DW | SCL > > > | +---------+ | |------- > > > | | | +----------+ > > > +---------| PSP | > > > <- ACK | | > > > +---------+ > > > > > > +---------+ > > > <- RELEASE | | > > > +---------| CPU | > > > | | | +----------+ SDA > > > | +---------+ | |------- > > > MAILBOX +--> | I2C-DW | SCL > > > | +---------+ / | |------- > > > | | | / +----------+ > > > +---------| PSP |/ > > > <- ACK | | > > > +---------+ > > > > > > The solution is similar to i2c-designware-baytrail.c implementation, = where > > > we are using a generic i2c-designware-* driver with a small "wrapper"= . > > > > > > In contrary to baytrail semaphore implementation, beside internal > > > acquire_lock() and release_lock() methods we are also applying quirks= to > > > lock_bus() and unlock_bus() global adapter methods. With this in plac= e > > > all i2c clients drivers may lock i2c bus for a desired number of i2c > > > transactions (e.g. write-wait-read) without being aware of that such = bus > > > is shared with another entity. > > > > > > Modify i2c_dw_probe_lock_support() to select correct semaphore > > > implementation at runtime, since now we have more than one available. > > > > > > Configure new matching ACPI ID "AMDI0019" and register > > > ARBITRATION_SEMAPHORE flag in order to distinguish setup with PSP > > > arbitration. > > > > > > Add myself as a reviewer for I2C DesignWare in order to help with rev= iewing > > > and testing possible changes touching new i2c-designware-amdpsp.c mod= ule. > > > > > > Signed-off-by: Jan Dabros > > > > Reported-by: kernel test robot > > > Reported-by: kernel test robot > > New feature can't be reported. > If you want to give a credit to CI, do it in changelog. OK, will remove this. > ... > > > > + depends on X86_64 > > Not sure if it's better than using non-atomic IO helpers. There are 2 issues reported by kernel robot for my patchset: 1. Lack of ; 2. Missing declaration for 'writeq'. Actually above was my idea to fix first issue, but please see below. > At least you can't run 32-bit kernels on that platforms > in order to get this functionality working. Doest it mean > those platforms do not have 32-bit compatibility mode > anymore? Correct, I was focusing too much on my use case, where I'm building only 64-bit. This isn't right. Furthermore I should rather use dependency on CONFIG_X86_MSR which is better suited for ensuring above msr.h header is present. > > ... > > > > +#include > > Ah, this is not needed if you keep code running exclusively on 64-bit > platforms. Will keep this, since switching to "depends on X86_MSR". > ... > > > > +struct psp_mbox { > > > + u32 cmd_fields; > > > > + phys_addr_t i2c_req_addr; > > But phys_addr_t is platform-dependent type. Perhaps you meant to use u64 = here > always? Once I remove the "depends on X86_64" I believe this should be left platform-dependent. > > > +} __packed; > > ... > > > > + struct psp_mbox __iomem *mbox =3D (struct psp_mbox __iomem *)= mbox_iomem; > > For void * pointers the cast is implied, i.o.w. it's not needed here. ACK. > ... > > > > +static int psp_send_check_i2c_req(struct psp_i2c_req *req) > > > +{ > > > + if (psp_send_cmd(req)) > > > > + return -EIO; > > Why is error code shadowed? > > > > + return check_i2c_req_sts(req); > > > +} Just as a side note - it wasn't modified in v2 when moving above to psp_send_check_i2c_req(), but let me explain why I have introduced this initially. We have two means of timeouts in the context of this driver: 1. Timeout of internal mailbox, which means we cannot communicate with a PSP for a programmed timeout. This timeout is encountered inside psp_send_cmd(). 2. Timeout of i2c arbitration - which means that we can communicate with PSP, but PSP refuses to release i2c bus for too long. This timeout is returned by psp_send_i2c_req() in case of error. (side note: both error conditions are very unlikely to happen at runtime) I wanted to clearly distinguish between these two and thus put all errors around mailbox into "-EIO category", which is actually true. > ... > > > > +cleanup: > > > + mutex_unlock(&psp_i2c_access_mutex); > > > + return 0; > > Not sure I understand why we ignore all above errors here. Actually we are not ignoring them, since each error sets "psp_i2c_mbox_fail =3D true;". This means that if there is any error on x86-PSP interface, we are ignoring i2c-arbitration and just fall back to normal (that is no-quirk) operation. From the i2c-client perspective (who is eventually gathering error code from above) I think we can claim that everything is fine, since bus is granted to it. For developers there is an error message in case some debug will be necessary. > ... > > > > + if (!dev || !dev->dev) > > > + return -ENODEV; > > At which circumstances may we get > dev !=3D NULL > dev->dev =3D=3D NULL > ? > > ... > > > > if (!dev || !dev->dev) > > > - return 0; > > > + return -ENODEV; > > I see the same here, perhaps Hans knows the answer :-) Right, so I must admit that I simply used *-baytrail.c as a reference and thinking that additional check shouldn't hurt us (always better than not enough safety..). Looking more at this now - `dw_i2c_plat_probe()` will boil-out earlier if `dev->dev =3D=3D NULL`. Should I remove this extra check in *-baytrail.c in the same commit? > ... > > > > +static int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev) > > > +{ > > > + const struct i2c_dw_semaphore_callbacks *ptr; > > > + int i =3D 0; > > > + int ret; > > > + > > > + ptr =3D i2c_dw_semaphore_cb_table; > > > + > > > + dev->semaphore_idx =3D -1; > > > + > > > + while (ptr->probe) { > > > + ret =3D ptr->probe(dev); > > > + if (ret) { > > > > + /* > > > + * If there is no semaphore device attached t= o this > > > + * controller, we shouldn't abort general i2c= _controller > > > + * probe. > > > + */ > > > + if (ret =3D=3D -ENODEV) { > > > + i++; > > > + ptr++; > > > + continue; > > > + } else { > > Redundant 'else', but see below. > > > > + return ret; > > > + } > > May it be > > if (ret !=3D -ENODEV) > return ret; > > i++; > ptr++; > continue; > > ? Yes, looks good. Thanks! Best Regards, Jan > > > > + } > > > + > > > + dev->semaphore_idx =3D i; > > > + break; > > > + } > > > + > > > + return 0; > > > +} > > -- > With Best Regards, > Andy Shevchenko > >