Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp141524lqt; Mon, 18 Mar 2024 04:11:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWDY0VHWi9iD+ED7QmVXZzYe2O9iwS9AhTLAzDvQifJtfy3sZ0iS98TJ72OGF8MfAwCuIP76Ot7V+rEPGoLQWRiZVnLiH18yM+tBymQ7Q== X-Google-Smtp-Source: AGHT+IHvW4NcbEOsGKQcBS+X+Fo6XCmxTVUg5wwc58JoIMq5JrngkAdecyx/w9Ez6LBUep9GMnjL X-Received: by 2002:ac8:7e83:0:b0:42e:f3a3:c7b4 with SMTP id w3-20020ac87e83000000b0042ef3a3c7b4mr16363453qtj.14.1710760309400; Mon, 18 Mar 2024 04:11:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710760309; cv=pass; d=google.com; s=arc-20160816; b=DXzRRnoU+Q++/A39xwu3Yq8h/0d7KdTZE89E191y/3m+DA8cxAdhcVVdZCbuq5UG09 OX5oAOeSTrLF5tAWdU1EExwQkQB6DqhXHiwgx8pC8MK1d/WWZj9gEEdpYVo6Bsk3CLdt P2P9yE5Uv7/GiGVpr51fEEG5L2COnYHRx/1iZAjr1dxY9ccDk/ZaucxjzykFybJ2prAt j68H9HrVzJD2M6rHrMFt4y5rDm+cGMnTXyFNAiCI282xRGXizeAJBB+CtedfLzO7yl8G jFE3wTlMG40wnBPGcn3WIrjCH+jSTSXLYt6GcMsE0Orkte+fZ5guP+N/WwIOd+m9YTJh 5cAA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=x7vOyPOD384YtWOw8mmf4X2zR5fetyicRBqYwP1EaJQ=; fh=IgDv2fqL49gOboXXzCXMN0XID3/S4C2lxLde4mXZeek=; b=OcfQTKNxYEI0fZd4fPt7pus691mHxSppcNYtOX9qzgjSMeaFPPGmAuhfqJv3qLhTiU T9HbNaFxa1dgeuFamVLs5/LLCdm6Xsh2JLmuPkVrJTWtzzb19yfBYhh03y778zHIfr0Y z9onTkv3x2nHXV2jJc8nC74+ptDev9GEumHmFY9TtxLyhER/2Rr+32jF8IFT2w+gapAf trCbX3IHgigYqiOuQUlJdBVM3uurC+VAP0aldp42m7vgSdU2mcJCc+gyDXAH6JVZCfxk g03FioKhmFs/dbYvCFR8erEE62M8gs9GPet5MNS2eUT2TfQ0BiKYmsgZiMZPqZa9IsLI oIlA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XPng3DZO; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-106043-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106043-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id n11-20020a05622a11cb00b0042f3069a0a6si6097099qtk.455.2024.03.18.04.11.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 04:11:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-106043-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XPng3DZO; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-106043-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106043-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D4D4C1C21456 for ; Mon, 18 Mar 2024 11:11:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A361364D6; Mon, 18 Mar 2024 11:11:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XPng3DZO" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8397E31A66; Mon, 18 Mar 2024 11:11:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710760298; cv=none; b=I88lFzlK77gZY1y+2LzpDKB1y6Gn0VxBvYKw+kTRE19ARUZ5An42gTSgYjH3z1Yj+K7Oc+O21VAVhqlt3s/MlUddCiTftNnYyu1yzgS51uHFFSIGcWku/YiwstjDIKT8tN69Id0HOtLa1/hUX4J/hhKPbMr5fCjkLBXWS4uEU9Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710760298; c=relaxed/simple; bh=/eNWMsh0F9jXQBWzGgZPQU2dDcVV4ugepMs2kdOvIcA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HBBQ1BJN52U5KlnXHDhuJXiV0nYcert4oq6jQXpd55IthNeSDeURJLJqZ3vUs8OPRAjScOjsVIYAT5OmH5yaedgEOkDqfRr1HbA4Ok4iAUjMKHX5519bzoPSfKlyqlYHqC+CvPRg1Ip0a74zIw8YlDoLLdw94dJlfq8agBbfoz0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=XPng3DZO; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710760297; x=1742296297; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=/eNWMsh0F9jXQBWzGgZPQU2dDcVV4ugepMs2kdOvIcA=; b=XPng3DZO7w8UttmABkFa5gYOR6zZjTF607GFjPr/Dh+Kv9MzObjrCBvu vDWah2AuBd9mAYyTKSEctz3/N1CKtEM/sipcpHuBJtWHuVhwawym/lUBd sZ/UJagKIAS3PP/zAZmhFtlaVaTXxzAAzXqCpqOIwpUfKUNyrqmM+4z9V KfW11KpQQixkUWi2u9hf5SbmAVAjZ0RVJABsKo/rRCGbTNZ3jAIbkupl5 SvYIxIp6JXBga5amdq7GqbWikfmrEdeCSKWcem6qXbbyRuxElDUuK2qvc 4prcXmfwh6RRbEpzOqFq/PBLtbzzONCVcARwl8j9xeFKcU2wViFCkEV6Z g==; X-IronPort-AV: E=McAfee;i="6600,9927,11016"; a="17012273" X-IronPort-AV: E=Sophos;i="6.07,134,1708416000"; d="scan'208";a="17012273" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2024 04:11:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11016"; a="937060155" X-IronPort-AV: E=Sophos;i="6.07,134,1708416000"; d="scan'208";a="937060155" Received: from kuha.fi.intel.com ([10.237.72.185]) by fmsmga001.fm.intel.com with SMTP; 18 Mar 2024 04:11:30 -0700 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Mon, 18 Mar 2024 13:11:30 +0200 Date: Mon, 18 Mar 2024 13:11:30 +0200 From: Heikki Krogerus To: Jameson Thies Cc: linux-usb@vger.kernel.org, pmalani@chromium.org, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/1] usb: typec: ucsi: Check capabilities before cable and identity discovery Message-ID: References: <20240315171836.343830-1-jthies@google.com> <20240315171836.343830-2-jthies@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240315171836.343830-2-jthies@google.com> On Fri, Mar 15, 2024 at 05:18:35PM +0000, Jameson Thies wrote: > Check the UCSI_CAP_GET_PD_MESSAGE bit before sending GET_PD_MESSAGE to > discover partner and cable identity, check UCSI_CAP_CABLE_DETAILS before > sending GET_CABLE_PROPERTY to discover the cable and check > UCSI_CAP_ALT_MODE_DETAILS before registering the a cable plug. Additionally, > move 8 bits from reserved_1 to features in the ucsi_capability struct. This > makes the field 16 bits, still 8 short of the 24 bits allocated for it in > UCSI v3.0, but it will not overflow because UCSI only defines 14 bits in > bmOptionalFeatures. > > Fixes: 38ca416597b0 ("usb: typec: ucsi: Register cables based on GET_CABLE_PROPERTY") > Link: https://lore.kernel.org/linux-usb/44e8142f-d9b3-487b-83fe-39deadddb492@linaro.org > Suggested-by: Neil Armstrong > Signed-off-by: Jameson Thies Reviewed-by: Heikki Krogerus > --- > Confirmed a device which supports GET_PD_MESSAGE, GET_CABLE_PROPERTY and > GET_ALTERNATE_MODES still requested identity and cable information. > > drivers/usb/typec/ucsi/ucsi.c | 34 +++++++++++++++++++++------------- > drivers/usb/typec/ucsi/ucsi.h | 5 +++-- > 2 files changed, 24 insertions(+), 15 deletions(-) > > diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c > index cf52cb34d2859..958dc82989b60 100644 > --- a/drivers/usb/typec/ucsi/ucsi.c > +++ b/drivers/usb/typec/ucsi/ucsi.c > @@ -1133,17 +1133,21 @@ static int ucsi_check_cable(struct ucsi_connector *con) > if (ret < 0) > return ret; > > - ret = ucsi_get_cable_identity(con); > - if (ret < 0) > - return ret; > + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) { > + ret = ucsi_get_cable_identity(con); > + if (ret < 0) > + return ret; > + } > > - ret = ucsi_register_plug(con); > - if (ret < 0) > - return ret; > + if (con->ucsi->cap.features & UCSI_CAP_ALT_MODE_DETAILS) { > + ret = ucsi_register_plug(con); > + if (ret < 0) > + return ret; > > - ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P); > - if (ret < 0) > - return ret; > + ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P); > + if (ret < 0) > + return ret; > + } > > return 0; > } > @@ -1189,8 +1193,10 @@ static void ucsi_handle_connector_change(struct work_struct *work) > ucsi_register_partner(con); > ucsi_partner_task(con, ucsi_check_connection, 1, HZ); > ucsi_partner_task(con, ucsi_check_connector_capability, 1, HZ); > - ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ); > - ucsi_partner_task(con, ucsi_check_cable, 1, HZ); > + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) > + ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ); > + if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS) > + ucsi_partner_task(con, ucsi_check_cable, 1, HZ); > > if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) == > UCSI_CONSTAT_PWR_OPMODE_PD) > @@ -1589,8 +1595,10 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con) > ucsi_register_partner(con); > ucsi_pwr_opmode_change(con); > ucsi_port_psy_changed(con); > - ucsi_get_partner_identity(con); > - ucsi_check_cable(con); > + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) > + ucsi_get_partner_identity(con); > + if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS) > + ucsi_check_cable(con); > } > > /* Only notify USB controller if partner supports USB data */ > diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h > index 32daf5f586505..0e7c92eb1b227 100644 > --- a/drivers/usb/typec/ucsi/ucsi.h > +++ b/drivers/usb/typec/ucsi/ucsi.h > @@ -206,7 +206,7 @@ struct ucsi_capability { > #define UCSI_CAP_ATTR_POWER_OTHER BIT(10) > #define UCSI_CAP_ATTR_POWER_VBUS BIT(14) > u8 num_connectors; > - u8 features; > + u16 features; > #define UCSI_CAP_SET_UOM BIT(0) > #define UCSI_CAP_SET_PDM BIT(1) > #define UCSI_CAP_ALT_MODE_DETAILS BIT(2) > @@ -215,7 +215,8 @@ struct ucsi_capability { > #define UCSI_CAP_CABLE_DETAILS BIT(5) > #define UCSI_CAP_EXT_SUPPLY_NOTIFICATIONS BIT(6) > #define UCSI_CAP_PD_RESET BIT(7) > - u16 reserved_1; > +#define UCSI_CAP_GET_PD_MESSAGE BIT(8) > + u8 reserved_1; > u8 num_alt_modes; > u8 reserved_2; > u16 bc_version; > -- > 2.44.0.291.gc1ea87d7ee-goog -- heikki