Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2018146rwl; Fri, 6 Jan 2023 00:19:14 -0800 (PST) X-Google-Smtp-Source: AMrXdXtKKXv+pwCQ3VJAjk6g2g+gnVWjzR4Z2GlV9ikESD8YG3V48e3jkD26Ffu8NMgrUGosh5PA X-Received: by 2002:a17:906:bc47:b0:78d:f455:3110 with SMTP id s7-20020a170906bc4700b0078df4553110mr40944363ejv.56.1672993154130; Fri, 06 Jan 2023 00:19:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672993154; cv=none; d=google.com; s=arc-20160816; b=M7SDW9b3mQ+f+c6X5LYtl0nxle0h2Msi+7h6IGPJbFS/L4TzkHjftbHViYenS7RvJn U9CCc7tBW1naprUX9vomvkZDpajPjo2n4ZleEr8/HZ9JWFKhp+rAh0u2X+QBDsfiG+wk fyewydpwu/terIGBNaCQOiPQ0qCIuM8AEd3OSq2K4ptlFRvPxZUB32YkF/yF0180ZvBG IgKNJPL6Nu+XPzdTHXAHEPvEAOvb3iM0u+bML60My4tgvpgTl7cOlfs+m9UU7y3gajSQ xnhY0pXFc3fJ8Szl9Mz72FYiu0qU1jA/XnGGJ0WF7chfJ4oWKhI1ovszi1ngRqZF2ZmL 6LvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=UZxV9V8VXb4INJX0jjy7V4lHD4YKn/SeeecfvQYyXmQ=; b=LHr23+ZDOVPMbA5OCMQQMokaUk7MxGsPaMVW9utgINJvOJLWR1uaY3RFw/38fz5Vk8 7XcT2BhsOKcCZvcga0pMsusApEPNSItgSBRh7D6ubMSUHwnowv0pKzZH0OCqnl4OnxSl DoNWuIqDUyNVzTq2Q/2gRi+olycIy8oWx50cuYVjDsQBwnMw2d9tAIXaI50v5YyxhrHT aD8CvfkvtcHG7oSpGJmzII5kxHceRGiDNQ/Z5o31UDAAgGaBSmISmREoZ8EKkcJ9pmiZ Ds63mDtn0+qVmG8WcFoHNLHVqCCG+VdAlqpw93+WY8Dj0BXo8cyMUT02x0X3+u6TFH3G BHDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zhd2tDSE; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa22-20020a1709076d1600b0083e0ec05046si734850ejc.626.2023.01.06.00.19.00; Fri, 06 Jan 2023 00:19:14 -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=@linuxfoundation.org header.s=korg header.b=zhd2tDSE; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231839AbjAFIKz (ORCPT + 56 others); Fri, 6 Jan 2023 03:10:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbjAFIK1 (ORCPT ); Fri, 6 Jan 2023 03:10:27 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFAF378E99; Fri, 6 Jan 2023 00:10:22 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3F33661D4C; Fri, 6 Jan 2023 08:10:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44FA2C433D2; Fri, 6 Jan 2023 08:10:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1672992621; bh=lFl3l56T6EeKmFd7eKwb8kpBaqgT6RyrMDeq/Q/+4Hs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=zhd2tDSE2dS6kqJ117QE2moXaS3KRy0sIGlRXifPKdSnsN+0KWeLyGd2mB/d7g8C1 OOPg8qAZkV7e1qXCwdGklizF4+r2RHlUPFQkxxvMnP0ioLJjIu9HvZ6fHDXfTTDMNt SKfHmhBci+es9br3kqixq+QPn3/V/ktha/xNV0vM= Date: Fri, 6 Jan 2023 09:10:18 +0100 From: Greg Kroah-Hartman To: Haotien Hsu Cc: Heikki Krogerus , Sing-Han Chen , Sanket Goswami , Wayne Chang , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Jonathan Hunter , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] ucsi_ccg: Refine the UCSI Interrupt handling Message-ID: References: <20230103081531.423017-1-haotienh@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230103081531.423017-1-haotienh@nvidia.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 Tue, Jan 03, 2023 at 04:15:31PM +0800, Haotien Hsu wrote: > From: Sing-Han Chen > > For the CCGx, when the OPM field in the INTR_REG is cleared, then the > CCI data in the PPM is reset. > > To align with the CCGx UCSI interface guide, this patch updates the > driver to copy CCI and MESSAGE_IN before clearing UCSI interrupt. > When a new command is sent, the driver will clear the old CCI and > MESSAGE_IN copy. > > Finally, clear UCSI_READ_INT before calling complete() to ensure that > the ucsi_ccg_sync_write() would wait for the interrupt handling to > complete. > It prevents the driver from resetting CCI prematurely. > > Signed-off-by: Sing-Han Chen > Signed-off-by: Haotien Hsu > --- > V1->V2 > - Fix uninitialized symbol 'cci' > v2->v3 > - Remove wrong Reported-by tags > --- > drivers/usb/typec/ucsi/ucsi_ccg.c | 86 ++++++++++++++++++++++++++++--- > 1 file changed, 79 insertions(+), 7 deletions(-) > > diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c > index eab3012e1b01..b35a3a97c9fb 100644 > --- a/drivers/usb/typec/ucsi/ucsi_ccg.c > +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c > @@ -192,6 +192,12 @@ struct ucsi_ccg_altmode { > bool checked; > } __packed; > > +#define CCGX_MESSAGE_IN_MAX 4 > +struct op_region { > + u32 cci; > + u32 message_in[CCGX_MESSAGE_IN_MAX]; > +}; > + > struct ucsi_ccg { > struct device *dev; > struct ucsi *ucsi; > @@ -222,6 +228,9 @@ struct ucsi_ccg { > bool has_multiple_dp; > struct ucsi_ccg_altmode orig[UCSI_MAX_ALTMODES]; > struct ucsi_ccg_altmode updated[UCSI_MAX_ALTMODES]; > + > + spinlock_t op_lock; What does this lock protect? Please document that so that we can verify if this really is a correct change _AND_ so we know what future changes need to take the lock or not. > + struct op_region op_data; > }; > > static int ccg_read(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len) > @@ -305,12 +314,57 @@ static int ccg_write(struct ucsi_ccg *uc, u16 rab, const u8 *data, u32 len) > return 0; > } > > +static void ccg_op_region_read(struct ucsi_ccg *uc, unsigned int offset, > + void *val, size_t val_len) > +{ > + struct op_region *data = &uc->op_data; > + > + spin_lock(&uc->op_lock); > + if (offset == UCSI_CCI) > + memcpy(val, &data->cci, val_len); > + else if (offset == UCSI_MESSAGE_IN) > + memcpy(val, &data->message_in, val_len); > + spin_unlock(&uc->op_lock); > +} > + > +static void ccg_op_region_update(struct ucsi_ccg *uc, u32 cci) > +{ > + u16 reg = CCGX_RAB_UCSI_DATA_BLOCK(UCSI_MESSAGE_IN); > + struct op_region *data = &uc->op_data; > + u32 message_in[CCGX_MESSAGE_IN_MAX]; > + > + if (UCSI_CCI_LENGTH(cci)) > + if (ccg_read(uc, reg, (void *)&message_in, > + sizeof(message_in))) { > + dev_err(uc->dev, "failed to read MESSAGE_IN\n"); What can userspace do with this error? Will it be repeated a lot? thanks, greg k-h