From patchwork Thu Aug 15 08:57:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 820028 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (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 59103224EF for ; Thu, 15 Aug 2024 08:57:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723712253; cv=none; b=SN9AkadlETfxQNUdye3c8guLkzShj7xf1GGtMywYdQ4r+EV80d3msULDIkc17Or7soycmG27u3UO06Xc6xdYB6C/Dv3Kz9Cu8ZDXqVyjcJjh0H4m/aWKfiis18MntoHa9yRjKOod6x74Lw7Ki9UhPxEVWPZ0ljK6Q5Z3iTuqk54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723712253; c=relaxed/simple; bh=/z1O6sxhAD+1JW5Zk+q8BJxcWMYP48XEeXaQvDIHEkY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JrOZEvcF4DKmO5rb6MOtgrk1DfCh9xpt44Jpvjf9J+I8iPf2pRCiHQpzLPTeu8V+S3mEHMMrJwvYEN3HCI8BSuXN4kPo3zEjYr3YVn3BcqXkUAG3+buvo4P9/bro3drS/Tt8R8bBZMFh9JaAUlVhY9c1yeCF+xsWo9OzyOFoIxE= 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=iKBz5p1w; arc=none smtp.client-ip=198.175.65.17 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="iKBz5p1w" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723712253; x=1755248253; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/z1O6sxhAD+1JW5Zk+q8BJxcWMYP48XEeXaQvDIHEkY=; b=iKBz5p1w4NNe4mKcojLf2++kaxeXTfT0kGIO+rZt5HMjok5PxJ2vc+rF 4QUvn4jvNY2Sxl9zxW7M6JT14D+NpGNypu0r39la8Pz147+GOIjzXCCq8 yQ+p6geDe+6LDzKMo0ZAc8skrGuAN0olM8Do/ttfFeBC4dLV6D1NYWKO7 crNxcO4exr6Ymk0aC5srrrLX15lAMugGdwE/K5CU4wbiKKY42GZ4E+vM4 y7nsgsF25khDZPU3Ivej/n7vFrLkCZtzXYyD9IP9fJRYCBU9rAunsUCJv w9Fy6Xxvi0qgSIsQidOLMx/NsbBxvOl4YFPg9eRilD8QF7/IcG9ArWNxr A==; X-CSE-ConnectionGUID: J9VPUij1RMartpA8iZbCxA== X-CSE-MsgGUID: amV02Tz9SvKBtxTQJBcZzQ== X-IronPort-AV: E=McAfee;i="6700,10204,11164"; a="22094622" X-IronPort-AV: E=Sophos;i="6.10,148,1719903600"; d="scan'208";a="22094622" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Aug 2024 01:57:32 -0700 X-CSE-ConnectionGUID: fJlmeUfASlaYfsskBHQsOA== X-CSE-MsgGUID: J7KVDNiIRA+7CDOiUTgbrg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,148,1719903600"; d="scan'208";a="96816949" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 15 Aug 2024 01:57:29 -0700 From: Heikki Krogerus To: Greg Kroah-Hartman Cc: Jameson Thies , Benson Leung , Prashant Malani , Dmitry Baryshkov , linux-usb@vger.kernel.org Subject: [PATCH 1/5] usb: typec: ucsi: Don't truncate the reads Date: Thu, 15 Aug 2024 11:57:22 +0300 Message-ID: <20240815085726.2865482-2-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240815085726.2865482-1-heikki.krogerus@linux.intel.com> References: <20240815085726.2865482-1-heikki.krogerus@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 That may silently corrupt the data. Instead, failing attempts to read more than the interface can handle. Signed-off-by: Heikki Krogerus --- drivers/usb/typec/ucsi/ucsi.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 4039851551c1..96ef099a6f84 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -99,12 +99,8 @@ static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci, *cci = 0; - /* - * Below UCSI 2.0, MESSAGE_IN was limited to 16 bytes. Truncate the - * reads here. - */ - if (ucsi->version <= UCSI_VERSION_1_2) - size = clamp(size, 0, 16); + if (size > UCSI_MAX_DATA_LENGTH(ucsi)) + return -EINVAL; ret = ucsi->ops->sync_control(ucsi, command); if (ret) From patchwork Thu Aug 15 08:57:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 819683 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (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 993F61BA895 for ; Thu, 15 Aug 2024 08:57:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723712256; cv=none; b=McSJ0PZb4+9DSyqjJhbASfq5y06cuA0rH6kwO58AMjYVKZPuhLLOIdpHQC4TM/mnMbEt5pQl7yZcVtL+pwkxuUIcWGzXset1J3L2MyroDGvqaLcrP9A1OLQRLwGQbBtaKNw+4s5Rks9o0CCv4NjrBN1keqWTaDjwRWdNiXEZPQg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723712256; c=relaxed/simple; bh=TE7c8VVSjm4laoQSHm/9MpjOwYlJekw9z/Vh/WVESBA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f9MFbwW18KJe3hJnhDy89tE+wZWJpI/XWFBhhsu5Hyr7LrnVaDxxzgRFKoB/wXPIt+gwqZRhDnJ2fTISIfBOtS2HYlIEptElGXk3x0ytw9mp118wu/976IIJCFe+RwiyN0iTNLwpcc/KlIv2lVfolnzEc3KZqcaERspt75k374g= 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=KDpUF0Cy; arc=none smtp.client-ip=198.175.65.17 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="KDpUF0Cy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723712255; x=1755248255; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TE7c8VVSjm4laoQSHm/9MpjOwYlJekw9z/Vh/WVESBA=; b=KDpUF0CydJJC7G3es9t6lgfTU0veYwgpCPpQdY33LgxsHfI365bdbkLG Gi1YbfKSKybREe0SHjt3l/M6dYO8sP+h3sTix1NBc2EvIgK6T3xouxbjI Rte9MjsTIsqWCzfntn2fxbqmfg7TOXjGG7ni7w+vbflAS5zzb0y5MUn9Q VbG+OS8o2StL3/CEAqPTGcK/6SXw6hjfI5KjnDAv8Hqf0zwJKmC/6xjq1 BpMuhi3Wp9j8H9okBauZ6gXlUj/Mx3OyNc5ieCwDkOKDFKT87JVDbGBkp iVr25wmHWKLRT4FGodFixm2WMUzPFxPmeZSIDQcZXIeuBtk/mVYxaqiDY Q==; X-CSE-ConnectionGUID: TX5QCS+JQny13Na9Kv+4ig== X-CSE-MsgGUID: 8huyyKjqS1uyteasdaTgfw== X-IronPort-AV: E=McAfee;i="6700,10204,11164"; a="22094632" X-IronPort-AV: E=Sophos;i="6.10,148,1719903600"; d="scan'208";a="22094632" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Aug 2024 01:57:34 -0700 X-CSE-ConnectionGUID: vIJJ5o7xT9Wp6FlXbFiq4w== X-CSE-MsgGUID: xGHy3UMQT5eAXKSoR5Ub/w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,148,1719903600"; d="scan'208";a="96816952" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 15 Aug 2024 01:57:32 -0700 From: Heikki Krogerus To: Greg Kroah-Hartman Cc: Jameson Thies , Benson Leung , Prashant Malani , Dmitry Baryshkov , linux-usb@vger.kernel.org Subject: [PATCH 2/5] usb: typec: ucsi: Only assign the identity structure if the PPM supports it Date: Thu, 15 Aug 2024 11:57:23 +0300 Message-ID: <20240815085726.2865482-3-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240815085726.2865482-1-heikki.krogerus@linux.intel.com> References: <20240815085726.2865482-1-heikki.krogerus@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This will make sure that the identity sysfs attribute files are kept hidden if the UCSI interface doesn't support reading the USB Power Delivery messages. Signed-off-by: Heikki Krogerus --- drivers/usb/typec/ucsi/ucsi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 96ef099a6f84..1f6e3f0d25c1 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -979,7 +979,8 @@ static int ucsi_register_cable(struct ucsi_connector *con) break; } - desc.identity = &con->cable_identity; + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) + desc.identity = &con->cable_identity; desc.active = !!(UCSI_CABLE_PROP_FLAG_ACTIVE_CABLE & con->cable_prop.flags); desc.pd_revision = UCSI_CABLE_PROP_FLAG_PD_MAJOR_REV_AS_BCD( @@ -1058,7 +1059,8 @@ static int ucsi_register_partner(struct ucsi_connector *con) if (pwr_opmode == UCSI_CONSTAT_PWR_OPMODE_PD) ucsi_register_device_pdos(con); - desc.identity = &con->partner_identity; + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) + desc.identity = &con->partner_identity; desc.usb_pd = pwr_opmode == UCSI_CONSTAT_PWR_OPMODE_PD; desc.pd_revision = UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD(con->cap.flags); From patchwork Thu Aug 15 08:57:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 820027 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (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 822CC1C9DE4 for ; Thu, 15 Aug 2024 08:57:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723712258; cv=none; b=i8vkdyLD5VfxbEpUOGx22ToT+xJnrl0FoQJBM+FQriXfXVFwhNhhov46ERlrjKy+vjFh7Iw30uCFDmKGTCojWuzw4xxiVKiJZRKr/jWplpiDKR2fOhgcjtWM3WRaL0MW06R7YltqRb9qhPBruOdLRkZiV7sO0IjFRXkJc3IAT80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723712258; c=relaxed/simple; bh=ttAEBBMHteYNMKU6zZSTXKXc9wFfw4su+pVjbQWN5Zk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tSxE/9doQMnFvVgFpK7Xw4vkkSTp3nqmB51NEf3//Sv7guavB9/+39d8ET1OKDpzWW/IXIwJ3jwbIy84lqxQi4nD7RLyzcy3fLIduj/dvfZVgzHQB/UARDE0w0rvewJvXbyeCmT3s/k3wFRxZxxJ4HPIG+ctr5aitPxYYKAstlo= 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=kFI36NOy; arc=none smtp.client-ip=198.175.65.17 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="kFI36NOy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723712257; x=1755248257; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ttAEBBMHteYNMKU6zZSTXKXc9wFfw4su+pVjbQWN5Zk=; b=kFI36NOyanA57lTAR+LvPGRpgsy5XmCVVCC802YwDnRcW5HnekFhhj7n RDsUjTTFrdqf1KH8EowtsoTRLKMmrGvHJoVuoq+DOiyDA0+27K/rDGaLJ K5P3dhYom3js0up5lP9t7AdilnyS48/z2WIkF0EIv6Udc/yV8Ei8Z+AJA 1BW9LkLbM+j/iJK/QSZjQ/+l1wDNfnBHs4oaXp9e8fOfb4qfNLDF0JFwn ynd59RA9ipKRWDe2XvivUrvQa2Xhb8PFIaHn3N7MeHKsbknx0CLJjeImB x9RMSjp7vyMmACoLT/bhOy1lhkK25BAl5d5QxyrYC8BbAPCku3fRorWmH g==; X-CSE-ConnectionGUID: zx4brguWTjqLyK7e476VOg== X-CSE-MsgGUID: P7M7AGU9Rme4/pZqVPAf7Q== X-IronPort-AV: E=McAfee;i="6700,10204,11164"; a="22094637" X-IronPort-AV: E=Sophos;i="6.10,148,1719903600"; d="scan'208";a="22094637" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Aug 2024 01:57:37 -0700 X-CSE-ConnectionGUID: J15wsc6vTWa0M9P7zI2MMg== X-CSE-MsgGUID: uKVvOtorT1CFk7zW+UZVQQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,148,1719903600"; d="scan'208";a="96816957" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 15 Aug 2024 01:57:34 -0700 From: Heikki Krogerus To: Greg Kroah-Hartman Cc: Jameson Thies , Benson Leung , Prashant Malani , Dmitry Baryshkov , linux-usb@vger.kernel.org Subject: [PATCH 3/5] usb: typec: ucsi: Common function for the GET_PD_MESSAGE command Date: Thu, 15 Aug 2024 11:57:24 +0300 Message-ID: <20240815085726.2865482-4-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240815085726.2865482-1-heikki.krogerus@linux.intel.com> References: <20240815085726.2865482-1-heikki.krogerus@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 So far that command was only used to read the response to the Discover Identity Request, but it is handled with two separate functions, which is not really necessary. Squashing the command execution into a single function. That function can now also be used to read other messages on top of the Request Identity response. Signed-off-by: Heikki Krogerus --- drivers/usb/typec/ucsi/ucsi.c | 92 ++++++++++------------------------- drivers/usb/typec/ucsi/ucsi.h | 14 +----- 2 files changed, 29 insertions(+), 77 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 1f6e3f0d25c1..470c9532b4f2 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -748,104 +748,66 @@ static struct usb_power_delivery_capabilities *ucsi_get_pd_caps(struct ucsi_conn &pd_caps); } -static int ucsi_read_identity(struct ucsi_connector *con, u8 recipient, - u8 offset, u8 bytes, void *resp) +static int ucsi_get_pd_message(struct ucsi_connector *con, u8 recipient, + size_t bytes, void *data, u8 type) { - struct ucsi *ucsi = con->ucsi; + size_t len = min(bytes, UCSI_MAX_DATA_LENGTH(con->ucsi)); u64 command; + u8 offset; int ret; - command = UCSI_COMMAND(UCSI_GET_PD_MESSAGE) | - UCSI_CONNECTOR_NUMBER(con->num); - command |= UCSI_GET_PD_MESSAGE_RECIPIENT(recipient); - command |= UCSI_GET_PD_MESSAGE_OFFSET(offset); - command |= UCSI_GET_PD_MESSAGE_BYTES(bytes); - command |= UCSI_GET_PD_MESSAGE_TYPE(UCSI_GET_PD_MESSAGE_TYPE_IDENTITY); - - ret = ucsi_send_command(ucsi, command, resp, bytes); - if (ret < 0) - dev_err(ucsi->dev, "UCSI_GET_PD_MESSAGE failed (%d)\n", ret); - - return ret; -} - -static int ucsi_get_identity(struct ucsi_connector *con, u8 recipient, - struct usb_pd_identity *id) -{ - struct ucsi *ucsi = con->ucsi; - struct ucsi_pd_message_disc_id resp = {}; - int ret; - - if (ucsi->version < UCSI_VERSION_2_0) { - /* - * Before UCSI v2.0, MESSAGE_IN is 16 bytes which cannot fit - * the 28 byte identity response including the VDM header. - * First request the VDM header, ID Header VDO, Cert Stat VDO - * and Product VDO. - */ - ret = ucsi_read_identity(con, recipient, 0, 0x10, &resp); - if (ret < 0) - return ret; + for (offset = 0; offset < bytes; offset += len) { + len = min(len, bytes - offset); + command = UCSI_COMMAND(UCSI_GET_PD_MESSAGE) | UCSI_CONNECTOR_NUMBER(con->num); + command |= UCSI_GET_PD_MESSAGE_RECIPIENT(recipient); + command |= UCSI_GET_PD_MESSAGE_OFFSET(offset); + command |= UCSI_GET_PD_MESSAGE_BYTES(len); + command |= UCSI_GET_PD_MESSAGE_TYPE(type); - /* Then request Product Type VDO1 through Product Type VDO3. */ - ret = ucsi_read_identity(con, recipient, 0x10, 0xc, - &resp.vdo[0]); - if (ret < 0) - return ret; - - } else { - /* - * In UCSI v2.0 and after, MESSAGE_IN is large enough to request - * the large enough to request the full Discover Identity - * response at once. - */ - ret = ucsi_read_identity(con, recipient, 0x0, 0x1c, &resp); + ret = ucsi_send_command(con->ucsi, command, data + offset, len); if (ret < 0) return ret; } - id->id_header = resp.id_header; - id->cert_stat = resp.cert_stat; - id->product = resp.product; - id->vdo[0] = resp.vdo[0]; - id->vdo[1] = resp.vdo[1]; - id->vdo[2] = resp.vdo[2]; return 0; } static int ucsi_get_partner_identity(struct ucsi_connector *con) { + u32 vdo[7] = {}; int ret; - ret = ucsi_get_identity(con, UCSI_RECIPIENT_SOP, - &con->partner_identity); + ret = ucsi_get_pd_message(con, UCSI_RECIPIENT_SOP, sizeof(vdo), vdo, + UCSI_GET_PD_MESSAGE_TYPE_IDENTITY); if (ret < 0) return ret; + /* VDM Header is not part of struct usb_pd_identity, so dropping it. */ + con->partner_identity = *(struct usb_pd_identity *)&vdo[1]; + ret = typec_partner_set_identity(con->partner); - if (ret < 0) { - dev_err(con->ucsi->dev, "Failed to set partner identity (%d)\n", - ret); - } + if (ret < 0) + dev_err(con->ucsi->dev, "Failed to set partner identity (%d)\n", ret); return ret; } static int ucsi_get_cable_identity(struct ucsi_connector *con) { + u32 vdo[7] = {}; int ret; - ret = ucsi_get_identity(con, UCSI_RECIPIENT_SOP_P, - &con->cable_identity); + ret = ucsi_get_pd_message(con, UCSI_RECIPIENT_SOP_P, sizeof(vdo), vdo, + UCSI_GET_PD_MESSAGE_TYPE_IDENTITY); if (ret < 0) return ret; + con->cable_identity = *(struct usb_pd_identity *)&vdo[1]; + ret = typec_cable_set_identity(con->cable); - if (ret < 0) { - dev_err(con->ucsi->dev, "Failed to set cable identity (%d)\n", - ret); - } + if (ret < 0) + dev_err(con->ucsi->dev, "Failed to set cable identity (%d)\n", ret); return ret; } diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 57129f3c0814..ddacce21cabf 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -375,18 +375,6 @@ struct ucsi_connector_status { ((get_unaligned_le32(&(_p_)[5]) & GENMASK(16, 1)) >> 1) } __packed; -/* - * Data structure filled by PPM in response to GET_PD_MESSAGE command with the - * Response Message Type set to Discover Identity Response. - */ -struct ucsi_pd_message_disc_id { - u32 vdm_header; - u32 id_header; - u32 cert_stat; - u32 product; - u32 vdo[3]; -} __packed; - /* -------------------------------------------------------------------------- */ struct ucsi_debugfs_entry { @@ -435,6 +423,8 @@ struct ucsi { #define UCSI_DELAY_DEVICE_PDOS BIT(1) /* Reading PDOs fails until the parter is in PD mode */ }; +#define UCSI_MAX_DATA_LENGTH(u) (((u)->version < UCSI_VERSION_2_0) ? 0x10 : 0xff) + #define UCSI_MAX_SVID 5 #define UCSI_MAX_ALTMODES (UCSI_MAX_SVID * 6) From patchwork Thu Aug 15 08:57:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 819682 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (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 B2DAD1C9EA8 for ; Thu, 15 Aug 2024 08:57:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723712260; cv=none; b=ZkC4vrhz1VIpn7ArwVjzlvZVkRsK8JwQyl59pyGR7aN6WfKJB116UEPnYPseYgpPd/2ixYb0+0oZKgeG/bZ1owG6kurxjCOvir70IiZIVk9cvXvRGvBLc2PIexVdIUu8fAxp/rGzjGuq3D/JMBRKnawEMjF8iHWe11fyASOZuGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723712260; c=relaxed/simple; bh=3R2pm5Kuk4wEYjoyM3jFKb/ppgX0RodA/DTz5vhow0A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jEl+iwOovzuw+BPwZ1rrNj2FYwdNA6Mp8HUTJ8+9jqAb2A7uBIPik6yo8/Fr7pKI4UXmsmEHCqHyd22iRoPgm8nMip6nUTnzEtDfa/aaZVlF83ZIQexwIiWCR5ba1Us71xBjeAwavopuVWwpT9KkAHuSZLBEIvakMT64E7O7qOQ= 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=gl9MU1CN; arc=none smtp.client-ip=198.175.65.17 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gl9MU1CN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723712259; x=1755248259; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3R2pm5Kuk4wEYjoyM3jFKb/ppgX0RodA/DTz5vhow0A=; b=gl9MU1CNSDNoFs3PuHzUc1PLfuD/vRKhOQsxvDZzQDubD1sUuIrJTC8b HdU2io9hqlPlSm9hJRufBN4bgq090jUL1Zeu06N20sXI3iUsrDb613t8r lXmrThBO5IpsWNz+gnkQfVvXjs+ej21JvTSqMDv+/d+MfsZVcYRQGVEjt DVrlbo2mUSXF4jECchzIFmttiIE10VF63cJafmB7glQtvJaKsVGNx9zXB aZVacrxn3adQINIh4v5+4PPSYGK0keu5ZVXmSHH+qNK01dn2IbDJQKHtQ CyvefFH664DxEXHmyvlwQ7SWReiSdkUZ6dNwsuTlUXcdEsrZWjnTYuXSO w==; X-CSE-ConnectionGUID: 0Q9QaxAnQVykgbCOEqYH2A== X-CSE-MsgGUID: ohAkgIXRTE+PikrjxKF2kg== X-IronPort-AV: E=McAfee;i="6700,10204,11164"; a="22094643" X-IronPort-AV: E=Sophos;i="6.10,148,1719903600"; d="scan'208";a="22094643" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Aug 2024 01:57:39 -0700 X-CSE-ConnectionGUID: y4WTKTVlQQa1exUjmMQdIA== X-CSE-MsgGUID: wjIqw0bATP22aszI/szEIw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,148,1719903600"; d="scan'208";a="96816961" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 15 Aug 2024 01:57:36 -0700 From: Heikki Krogerus To: Greg Kroah-Hartman Cc: Jameson Thies , Benson Leung , Prashant Malani , Dmitry Baryshkov , linux-usb@vger.kernel.org Subject: [PATCH 4/5] usb: typec: ucsi: Call CANCEL from single location Date: Thu, 15 Aug 2024 11:57:25 +0300 Message-ID: <20240815085726.2865482-5-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240815085726.2865482-1-heikki.krogerus@linux.intel.com> References: <20240815085726.2865482-1-heikki.krogerus@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The command cancellation can be done right after detecting that the PPM is busy. There is no need to do it separately in ucsi_read_error() and ucsi_send_command_common(). Signed-off-by: Heikki Krogerus --- drivers/usb/typec/ucsi/ucsi.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 470c9532b4f2..64fe59e05b4f 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -111,7 +111,7 @@ static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci, return ret; if (*cci & UCSI_CCI_BUSY) - return -EBUSY; + return ucsi_run_command(ucsi, UCSI_CANCEL, cci, NULL, 0, false) ?: -EBUSY; if (!(*cci & UCSI_CCI_COMMAND_COMPLETE)) return -EIO; @@ -144,15 +144,7 @@ static int ucsi_read_error(struct ucsi *ucsi, u8 connector_num) int ret; command = UCSI_GET_ERROR_STATUS | UCSI_CONNECTOR_NUMBER(connector_num); - ret = ucsi_run_command(ucsi, command, &cci, - &error, sizeof(error), false); - - if (cci & UCSI_CCI_BUSY) { - ret = ucsi_run_command(ucsi, UCSI_CANCEL, &cci, NULL, 0, false); - - return ret ? ret : -EBUSY; - } - + ret = ucsi_run_command(ucsi, command, &cci, &error, sizeof(error), false); if (ret < 0) return ret; @@ -234,9 +226,8 @@ static int ucsi_send_command_common(struct ucsi *ucsi, u64 cmd, mutex_lock(&ucsi->ppm_lock); ret = ucsi_run_command(ucsi, cmd, &cci, data, size, conn_ack); - if (cci & UCSI_CCI_BUSY) - ret = ucsi_run_command(ucsi, UCSI_CANCEL, &cci, NULL, 0, false) ?: -EBUSY; - else if (cci & UCSI_CCI_ERROR) + + if (cci & UCSI_CCI_ERROR) ret = ucsi_read_error(ucsi, connector_num); mutex_unlock(&ucsi->ppm_lock); From patchwork Thu Aug 15 08:57:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 820026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (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 EEF751C9EB7 for ; Thu, 15 Aug 2024 08:57:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723712262; cv=none; b=jkxe8d4MMmaLFKAfCGqOyBgjA733Hk3ryTINzrSe7JKDgqn2iP7+XERHo1wJr8NJ2+Pp6fXuNJQOeENkbHi5xKzND58MUp98pQB+5dNTH2XaKAvwgdYXiGO91+w4ak4ZIIIuzveXkej9pnS7MYhjRsY0w5GaUo167t0akHSZ8oA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723712262; c=relaxed/simple; bh=G2lurmo+k3UCRLAgigooeszpiMhc7Uh1WD01LPPpFNA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JA84Wrnr89mJ214Cm29yYvjEsTP8RqmnkmrYyohevOOd/EbN00kIJZlA1hXMh/npFkrweQ43XGZ/1GoMJIoeooc5vhgZPaTjlRP81YaBR7Rvgg8XTzsN/MX7tzkv5jHy1be5lkPdps62yVryaaKofberSrg+ksdfAY5ij0jl6/Y= 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=B2yPGx0L; arc=none smtp.client-ip=198.175.65.17 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="B2yPGx0L" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723712261; x=1755248261; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=G2lurmo+k3UCRLAgigooeszpiMhc7Uh1WD01LPPpFNA=; b=B2yPGx0LVSsVUj7Ud1v7W4AD6fWFSKaPkrcd9DfFMPTihIY0ltssy6UO 39ygq5M8XXFPR4AAlDU6HFbEuqjh4UQs6UOxJeXT7eefmWpBBrkL/ONCW cPSj2lyIZ7k9pqHU4XltmLkV81mTmQ0hpqrV2IeOLgvsYdIV+gfKtqgNZ 949TY4SmFOk4Ey1oez5c2fi9XFElh2qR60QxHML0tpJ5yMSIpOU5vFlSS +5lduBqYWhe4jpG9kd15oeE4owSGdxcIRFcRfu+y4VcYvcaA//uCoXOXG LIdVnRqJDz9EIWROXIhC4NdLOb9FcIHylHGp94sW3cI4Vzp2Vw2RTC7a6 A==; X-CSE-ConnectionGUID: CTqxkxtNTjuwGwoxKNj8nQ== X-CSE-MsgGUID: ZIkGqT6ASaW57AHGM3UKyQ== X-IronPort-AV: E=McAfee;i="6700,10204,11164"; a="22094650" X-IronPort-AV: E=Sophos;i="6.10,148,1719903600"; d="scan'208";a="22094650" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Aug 2024 01:57:41 -0700 X-CSE-ConnectionGUID: UsisgDi4TvabopBEekV2/Q== X-CSE-MsgGUID: HhJpaF1oQp+W+hcdzkTh0A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,148,1719903600"; d="scan'208";a="96816966" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 15 Aug 2024 01:57:39 -0700 From: Heikki Krogerus To: Greg Kroah-Hartman Cc: Jameson Thies , Benson Leung , Prashant Malani , Dmitry Baryshkov , linux-usb@vger.kernel.org Subject: [PATCH 5/5] usb: typec: ucsi: Remove useless error check from ucsi_read_error() Date: Thu, 15 Aug 2024 11:57:26 +0300 Message-ID: <20240815085726.2865482-6-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240815085726.2865482-1-heikki.krogerus@linux.intel.com> References: <20240815085726.2865482-1-heikki.krogerus@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If the GET_ERROR_STATUS command fails, ucsi_read_error() can not reach the condition where the CCI error bit is checked, because ucsi_run_command() has already checked that bit and returned an error. Signed-off-by: Heikki Krogerus --- drivers/usb/typec/ucsi/ucsi.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 64fe59e05b4f..927007230cb8 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -148,9 +148,6 @@ static int ucsi_read_error(struct ucsi *ucsi, u8 connector_num) if (ret < 0) return ret; - if (cci & UCSI_CCI_ERROR) - return -EIO; - switch (error) { case UCSI_ERROR_INCOMPATIBLE_PARTNER: return -EOPNOTSUPP;