From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.20 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796390144; b=yt7DYdu50jfXg7AILmZ2ykwFUcytDvaHnjHJeWdMiuxG8qP9MrP8FsXWoFHnT2iq8peW ++cWqaFoI+jaxPqs9BIcf0kBf21NpW4CpjT5dgmRPtARRHO6m3Jqgg69khZoiUyJIGwOn SpZ6S30zu+Nj/jqd24TgJJI8W3P5gNQ7RNpZMf3hTAwXcSyviUYz8/BAdByaaO8vH7N97 4bMpMLUkov617J1q2kAqW2vKA5MGbMmr7fDgVv2AelY21DNZkX1BRNrg1lGPzN2+5F8Zw xCxl2jefnqM2N3G2NKcAVH8alttZlguqamgrs+jfbW3iN54/gehLNqQO0Q2B7ZJH3DQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796390144; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:Date:To:cc: Subject:In-Reply-To:Message-ID:References:MIME-Version:Content-Type; bh=XaEaGUx7Bazpu8z7lNpXI5ehQGmxmE0toDS0iib5Ae4=; b=ikd5jIdjLDyBJN3bNEkcvrfsDZl3E+rAgeNubuGjf3Tv3jb2QsAyao03I5wqUX8fWMYM Olh/2BTwXDjee86FY/fLTT+Ru/hB0QOYjcIJblNjSoThpHxr4SNosH9D14+k59fZ/4ZkQ SbcklvXwbJK1V8dm67EV0rX9lrrq5VW/alXTf7epJA7thVnsU3FePpWbP9gZ7F+bclTb5 Q4zz7zfCDbC7TJpb59bnrwKhjRB2bt9sv5Nt0YAZxDG8xtvi8DIaYzDwpdhHow13FMj88 YhFedkYyEnKARZzJJZOV7fBksJGPCKnZFAKY6TIF8YAD1rOC+MGlzHazaoop21lHawQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=AVPGHBV4; arc=none smtp.remote-ip=198.175.65.20 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AAD2606A32D; Fri, 4 Dec 2026 13:15:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6AAD2606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass 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.a=rsa-sha256 header.s=Intel header.b=AVPGHBV4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796390144; x=1827926144; h=from:date:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=XaEaGUx7Bazpu8z7lNpXI5ehQGmxmE0toDS0iib5Ae4=; b=AVPGHBV4d9CGvHvQDk2KwjW9vykqOh0S3IEuMkZtO8t380mfEqUR7fkK /g6N9e0qm0005QoyB8cVcR3qzfDyRgI3XbNcMGMfF1NKHhnaqAwEUreBa gSuOGgvI45NWvSsBYWj8pL3AhhLZwlBidkLaYxdh3HTVTOox7Br56KnYn urneVwWALM7RQkO87kpMHYg4GXFBYp6D4KpHYAc0v+eP0PI3PNxLRVNeH vbRl+Mypkf+9c83K02F/Lu3TQVNXYXWf7sXMBZzyS0dH0LJmpwA3wJdnJ Q3fYrwgad+3lfKk4U5y8bVWP5jjiMYHJ/vKe9j8f7yQiFK1Wl6s1M4Jjz g==; X-CSE-ConnectionGUID: Oa3Vro2xQrO6Tly1Z9D6pg== X-CSE-MsgGUID: v+gKlMLBQ9aVulfPMxxnTg== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5416676" X-IronPort-AV: E=Sophos;i="6.29,78,1794902400"; d="scan'208";a="5416676" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 05:15:43 -0800 X-CSE-ConnectionGUID: pBwzNv0XTMC2zwzF6JGeTw== X-CSE-MsgGUID: nBcdoTQoSa6d7VV1VLAvRg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,78,1794902400"; d="scan'208";a="14468187" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.245.47]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 05:15:39 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Fri, 4 Dec 2026 15:15:35 +0200 (EET) To: Lee Youngjoon cc: Pengyu Luo , Heikki Krogerus , Greg Kroah-Hartman , Hans de Goede , Bryan O'Donoghue , platform-driver-x86@vger.kernel.org, linux-usb@vger.kernel.org, LKML , stable@vger.kernel.org Subject: Re: [PATCH v4 1/2] usb: typec: ucsi: gaokun: Distinguish empty updates from EC errors In-Reply-To: Message-ID: <95d692e6-00d7-23ed-eeb3-1a7ddf83757d@linux.intel.com> References: X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII On Thu, 3 Dec 2026, Lee Youngjoon wrote: > The EC UCSI_REG_READ (0xd3) response contains a port count, an update > mask and per-port state. A failed read currently looks like an empty > update, so the USB event handler sends a zero PAN acknowledgment without > having read a valid response. > > Keep read errors separate from an empty mask. Send a zero acknowledgment > only when a USB event's successful read reports no update. A connector > timeout with no matching update sends no acknowledgment. Bound the port > array at probe by the space available for per-port state in the response, > and select only a port within that array. > > Construct the acknowledgment mask in the UCSI driver after selecting a > port and pass the mask to the EC writer. This also avoids shifting by > the negative no-update sentinel in the EC driver. > > Fixes: 00327d7f2c8c ("usb: typec: ucsi: add Huawei Matebook E Go ucsi driver") > Fixes: 7636f090d02e ("platform: arm64: add Huawei Matebook E Go EC driver") > Cc: stable@vger.kernel.org > Signed-off-by: Lee Youngjoon > --- > drivers/platform/arm64/huawei-gaokun-ec.c | 16 ++---- > drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c | 52 ++++++++++++------- > .../linux/platform_data/huawei-gaokun-ec.h | 4 +- > 3 files changed, 39 insertions(+), 33 deletions(-) > > diff --git a/drivers/platform/arm64/huawei-gaokun-ec.c > b/drivers/platform/arm64/huawei-gaokun-ec.c > index ac21f732d..ed9a1deee 100644 > --- a/drivers/platform/arm64/huawei-gaokun-ec.c > +++ b/drivers/platform/arm64/huawei-gaokun-ec.c > @@ -445,27 +445,21 @@ int gaokun_ec_ucsi_get_reg(struct gaokun_ec *ec, > struct gaokun_ucsi_reg *ureg) > EXPORT_SYMBOL_GPL(gaokun_ec_ucsi_get_reg); > > /** > - * gaokun_ec_ucsi_pan_ack - Ack pin assignment notifications from EC > + * gaokun_ec_ucsi_write_pan_ack - Ack pin assignment notifications from EC > * @ec: The gaokun_ec structure > - * @port_id: The port id receiving and handling the notifications > + * @mask: Bit of the port being acknowledged, or zero for an empty update > * > * Ack pin assignment notifications (used by UCSI subdriver). > * > * Return: 0 on success or negative error code. > */ > -int gaokun_ec_ucsi_pan_ack(struct gaokun_ec *ec, int port_id) > +int gaokun_ec_ucsi_write_pan_ack(struct gaokun_ec *ec, u8 mask) > { > - u8 ec_req[] = MKREQ(0x03, UCSI_REG_WRITE, 1); > - u8 data = 1 << port_id; > - > - if (port_id == GAOKUN_UCSI_NO_PORT_UPDATE) > - data = 0; > - > - refill_req_byte(ec_req, &data); > + u8 ec_req[] = MKREQ(0x03, UCSI_REG_WRITE, 1, mask); > > return gaokun_ec_write(ec, ec_req); > } > -EXPORT_SYMBOL_GPL(gaokun_ec_ucsi_pan_ack); > +EXPORT_SYMBOL_GPL(gaokun_ec_ucsi_write_pan_ack); > > /* -------------------------------------------------------------------------- > */ > /* EC Sysfs */ > diff --git a/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c > b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c > index 56f8bbab9..22ffc13c4 100644 > --- a/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c > +++ b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c > @@ -33,6 +33,9 @@ > #define GAOKUN_HPD_STATE_MASK BIT(4) > #define GAOKUN_HPD_IRQ_MASK BIT(5) > > +#define GAOKUN_UCSI_PORT_DATA_SIZE 2 /* DCC and DDI bytes per port */ > +#define GAOKUN_UCSI_ANY_PORT (-1) > + > #define GET_IDX(updt) (ffs(updt) - 1) > > #define CCX_TO_ORI(ccx) (++(ccx) % 3) /* convert ccx to enum > typec_orientation */ > @@ -217,7 +220,7 @@ static void gaokun_ucsi_port_update(struct > gaokun_ucsi_port *port, > const u8 *port_data) > { > struct gaokun_ucsi *uec = port->ucsi; > - int offset = port->idx * 2; /* every port has 2 Bytes data */ > + int offset = port->idx * GAOKUN_UCSI_PORT_DATA_SIZE; > unsigned long flags; > u8 dcc, ddi; > > @@ -273,23 +276,25 @@ static void gaokun_ucsi_port_update(struct > gaokun_ucsi_port *port, > spin_unlock_irqrestore(&port->lock, flags); > } > > -static int gaokun_ucsi_refresh(struct gaokun_ucsi *uec) > +/* Return a one-based connector number, zero for an empty mask, or an errno. */ > +static int gaokun_ucsi_refresh(struct gaokun_ucsi *uec, int expected) > { > struct gaokun_ucsi_reg ureg; > int ret, idx; > > ret = gaokun_ec_ucsi_get_reg(uec->ec, &ureg); > if (ret) > - return GAOKUN_UCSI_NO_PORT_UPDATE; > + return ret < 0 ? ret : -EIO; > > - uec->num_ports = ureg.num_ports; > - idx = GET_IDX(ureg.port_updt); > + if (!ureg.port_updt) > + return 0; > > - if (idx < 0 || idx >= ureg.num_ports) > - return GAOKUN_UCSI_NO_PORT_UPDATE; > + idx = expected >= 0 ? expected : GET_IDX(ureg.port_updt); > + if (idx >= uec->num_ports || !(ureg.port_updt & BIT(idx))) > + return -ENODATA; > > gaokun_ucsi_port_update(&uec->ports[idx], ureg.port_data); > - return idx; > + return idx + 1; > } > > static void gaokun_ucsi_handle_usb_mode(struct gaokun_ucsi_port *port) > @@ -321,23 +326,23 @@ static void gaokun_ucsi_handle_usb_mode(struct > gaokun_ucsi_port *port) > connector_status_connected : > connector_status_disconnected); > > - gaokun_ec_ucsi_pan_ack(uec->ec, port->idx); > + gaokun_ec_ucsi_write_pan_ack(uec->ec, BIT(idx)); > } > > -static void gaokun_ucsi_usb_notify_ind(struct gaokun_ucsi *uec) > +static void gaokun_ucsi_usb_notify_ind(struct gaokun_ucsi *uec, int expected) > { > - int idx; > + int num; > > if (!uec->ucsi->connector) { /* slow to register */ > dev_err_ratelimited(uec->dev, "ucsi connector is not initialized yet\n"); > return; > } > > - idx = gaokun_ucsi_refresh(uec); > - if (idx == GAOKUN_UCSI_NO_PORT_UPDATE) > - gaokun_ec_ucsi_pan_ack(uec->ec, idx); /* ack directly if no update */ > - else > - gaokun_ucsi_handle_usb_mode(&uec->ports[idx]); > + num = gaokun_ucsi_refresh(uec, expected); > + if (!num && expected == GAOKUN_UCSI_ANY_PORT) > + gaokun_ec_ucsi_write_pan_ack(uec->ec, 0); > + else if (num > 0) > + gaokun_ucsi_handle_usb_mode(&uec->ports[num - 1]); > } > > /* > @@ -366,10 +371,13 @@ static void > gaokun_ucsi_handle_no_usb_event(struct gaokun_ucsi *uec, int idx) > { > struct gaokun_ucsi_port *port; > > + if (idx < 0 || idx >= uec->num_ports) > + return; > + > port = &uec->ports[idx]; > if (!wait_for_completion_timeout(&port->usb_ack, 2 * HZ)) { > dev_warn(uec->dev, "No USB EVENT, triggered by UCSI EVENT"); > - gaokun_ucsi_usb_notify_ind(uec); > + gaokun_ucsi_usb_notify_ind(uec, idx); > } > } > > @@ -383,7 +391,7 @@ static int gaokun_ucsi_notify(struct notifier_block *nb, > switch (action) { > case EC_EVENT_USB: > gaokun_ucsi_complete_usb_ack(uec); > - gaokun_ucsi_usb_notify_ind(uec); > + gaokun_ucsi_usb_notify_ind(uec, GAOKUN_UCSI_ANY_PORT); > return NOTIFY_OK; > > case EC_EVENT_UCSI: > @@ -411,8 +419,14 @@ static int gaokun_ucsi_ports_init(struct gaokun_ucsi *uec) > int i, ret, num_ports; > u32 port; > > - gaokun_ec_ucsi_get_reg(uec->ec, &ureg); > + ret = gaokun_ec_ucsi_get_reg(uec->ec, &ureg); > + if (ret) > + return ret < 0 ? ret : -EIO; > num_ports = ureg.num_ports; > + if (!num_ports || num_ports > ARRAY_SIZE(ureg.port_data) / > GAOKUN_UCSI_PORT_DATA_SIZE) > + return -EINVAL; > + uec->num_ports = num_ports; > + > uec->ports = devm_kzalloc_objs(dev, *uec->ports, num_ports); > if (!uec->ports) > return -ENOMEM; > diff --git a/include/linux/platform_data/huawei-gaokun-ec.h > b/include/linux/platform_data/huawei-gaokun-ec.h > index faa15d315..9e7b8ab93 100644 > --- a/include/linux/platform_data/huawei-gaokun-ec.h > +++ b/include/linux/platform_data/huawei-gaokun-ec.h > @@ -13,8 +13,6 @@ > #define GAOKUN_UCSI_READ_SIZE (GAOKUN_UCSI_CCI_SIZE + GAOKUN_UCSI_MSGI_SIZE) > #define GAOKUN_UCSI_WRITE_SIZE 24 /* 8B CTRL, 16B MSGO */ > > -#define GAOKUN_UCSI_NO_PORT_UPDATE (-1) > - > #define GAOKUN_SMART_CHARGE_DATA_SIZE 4 /* mode, delay, start, end */ > > /* -------------------------------------------------------------------------- > */ > @@ -74,6 +72,6 @@ int gaokun_ec_ucsi_write(struct gaokun_ec *ec, > const u8 req[GAOKUN_UCSI_WRITE_SIZE]); > > int gaokun_ec_ucsi_get_reg(struct gaokun_ec *ec, struct gaokun_ucsi_reg *ureg); > -int gaokun_ec_ucsi_pan_ack(struct gaokun_ec *ec, int port_id); > +int gaokun_ec_ucsi_write_pan_ack(struct gaokun_ec *ec, u8 mask); > > #endif /* __HUAWEI_GAOKUN_EC_H__ */ > The patch is corrupted somewhere. This look also quite messy. I wonder if the return value conversion have to be part of it or if they could be put into a separate change in the series? -- i.