From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.8 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796390324; b=nEjnBY1e9paoZvODCtY93Vq+QpKs8kHV5VwCWS/xm/fbp/R85iGJJb/0E0i2iAxwDBiM Cuvh7F9YONXoV2xDb/Z3x9Yv0OPFIV88pAGWM5X/qxNUcqcA+X053y+RTLEbA+PhEdcqt jZyJ0I7i4SAQ3V70PfIM4NeczrLZzumwnLnbealXJdGYbIE2oeqmred6zF/N+4CMWQHA3 ZY0s0UZQRnR7FvMnVgGaUf8YBIm+8S0Mb1TStaA5UxydrSGXQJFZZCvqaXOVeMHsJMpK3 3B/rElb73QUXTZ4BjVaTwmEtB5gctKWoAKidpAefych7zCIU0YSO0cMLE3ihxgFUDcw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796390324; 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=JmwWUkMPofLG53n/4Ky9FCnWDYfgYQSOIgbdZ7AS5+k=; b=CrkjDCP+1NW441sPr1zBznqfGbI3t8IJ/RWnMJYzVRxfSzFeFXHsxWlSa5OoW4bzrGOo 6lU8VhGU7TxtY6r1KsaQ19TFf0zuydmeQ0S7kZXNMZgRnkIrnjytvUq7IUj+WGaYjS9K7 MzDBj/qEqVcrAuJ663+pgOAIaNwQ2MAjWLW+kcNqUYwD1P2i0FrhWI1mwSgDMFv6vwAyX 8KpO6a1G969eXS6x/xbgphXnNBj1CsrxpOwMyA+8XVuQafMmoBN7Qd3F9k1Ui+J76x1kd FCpggoX2djVCY8EaGzohJwClrm3YLjSdgEpAKRtA6RwGot3skzwMxvsjVNLOLgjvLzA== 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=JhsTFJtI; arc=none smtp.remote-ip=192.198.163.8 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 49EE1606A334; Fri, 4 Dec 2026 13:18:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 49EE1606A334 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=JhsTFJtI DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796390324; x=1827926324; h=from:date:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=JmwWUkMPofLG53n/4Ky9FCnWDYfgYQSOIgbdZ7AS5+k=; b=JhsTFJtINuMvvb2FVvLQrMQ9m84klfSx5qwrcsUeHA756Wm+3Pq8bS+f qjbDJPalgo4GT+CqRI4s8iKE40eBZdAQQAiBSvQ3VhCgnFsrlVn8Zq9u5 1RLGzn+eXGMSLnKtqU2V3wgifjCf4n8Q6uYEXS9D3snYwKPjhphPgsjp0 fcrauFn6H7njQJJTOuSvPbsvU9M2i8EY2daVeQb1uqWkCaGFUfVJN1m/a bbUhC6LVEo4Dv9tAVLSIjw2tLAuo4sA7it2oZ11vdQYbn3n8vA1FAwgiy 5wOYJPEDEw5zcCSekK5uslBOIIbY4CKmBuSgGpywmr9tVfWlTIQwFBAeG A==; X-CSE-ConnectionGUID: k3BWhr5vRgalqswpnhCS9Q== X-CSE-MsgGUID: rU886n0nTZuo7Tlb5aCafg== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5256204" X-IronPort-AV: E=Sophos;i="6.29,78,1794902400"; d="scan'208";a="5256204" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 05:18:43 -0800 X-CSE-ConnectionGUID: 9SmhU1o5RNuvFD+CUCwCgA== X-CSE-MsgGUID: 3Zlvf79CRdKNyoz+CDtuOw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,78,1794902400"; d="scan'208";a="14081114" 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:18:39 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Fri, 4 Dec 2026 15:18:36 +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 2/2] usb: typec: ucsi: gaokun: Defer missing USB events per connector In-Reply-To: Message-ID: <07f58521-7264-a4e7-e151-36cc18e9623e@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 IRQ thread dispatches both connector and USB events through a > blocking notifier. Waiting in the connector callback holds up the IRQ > thread that would deliver the USB event. The first USB event also > completes every port's wait, and those completions are never rearmed. > > Schedule the existing two-second fallback on a freezable workqueue and > return from the notifier. Track each connector independently. A USB > update cancels only the matching fallback. A newer connector change > moves its deadline even if the older worker is already running. > > Serialize mode updates and acknowledgments from the two paths. Stop > notifications and drain per-port work before unregistering UCSI. > > Fixes: 00327d7f2c8c ("usb: typec: ucsi: add Huawei Matebook E Go ucsi driver") > Cc: stable@vger.kernel.org > Signed-off-by: Lee Youngjoon > --- > drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c | 99 ++++++++++++--------- > 1 file changed, 58 insertions(+), 41 deletions(-) > > diff --git a/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c > b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c > index 22ffc13c4..3ed39c90e 100644 > --- a/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c > +++ b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c > @@ -8,9 +8,10 @@ > #include > #include > #include > -#include > #include > +#include > #include > +#include > #include > #include > #include > @@ -19,13 +20,15 @@ > #include > #include > #include > -#include > +#include > > #include "ucsi.h" > > #define EC_EVENT_UCSI 0x21 > #define EC_EVENT_USB 0x22 > > +#define USB_EVENT_TIMEOUT (2 * HZ) > + > #define GAOKUN_CCX_MASK GENMASK(1, 0) > #define GAOKUN_MUX_MASK GENMASK(3, 2) > > @@ -80,7 +83,9 @@ struct gaokun_ucsi_reg { > } __packed; > > struct gaokun_ucsi_port { > - struct completion usb_ack; > + struct delayed_work usb_fallback; > + unsigned long usb_fallback_deadline; > + bool usb_fallback_pending; > spinlock_t lock; /* serializing port resource access */ > > struct gaokun_ucsi *ucsi; > @@ -105,6 +110,7 @@ struct gaokun_ucsi { > struct gaokun_ucsi_port *ports; > struct device *dev; > struct delayed_work work; > + struct mutex usb_lock; /* serialize EC mode and PAN operations */ > struct notifier_block nb; > u16 version; > u8 num_ports; > @@ -329,56 +335,63 @@ static void gaokun_ucsi_handle_usb_mode(struct > gaokun_ucsi_port *port) > gaokun_ec_ucsi_write_pan_ack(uec->ec, BIT(idx)); > } > > -static void gaokun_ucsi_usb_notify_ind(struct gaokun_ucsi *uec, int expected) > +static void gaokun_ucsi_usb_event(struct gaokun_ucsi *uec) > { > + struct gaokun_ucsi_port *port; > int num; > > - if (!uec->ucsi->connector) { /* slow to register */ > - dev_err_ratelimited(uec->dev, "ucsi connector is not initialized yet\n"); > + guard(mutex)(&uec->usb_lock); > + if (!READ_ONCE(uec->ucsi->connector)) Add include. This patch too looked somehow corrupted. -- i. > return; > - } > > - num = gaokun_ucsi_refresh(uec, expected); > - if (!num && expected == GAOKUN_UCSI_ANY_PORT) > + num = gaokun_ucsi_refresh(uec, GAOKUN_UCSI_ANY_PORT); > + if (!num) > gaokun_ec_ucsi_write_pan_ack(uec->ec, 0); > - else if (num > 0) > - gaokun_ucsi_handle_usb_mode(&uec->ports[num - 1]); > + if (num <= 0) > + return; > + > + port = &uec->ports[num - 1]; > + gaokun_ucsi_handle_usb_mode(port); > + port->usb_fallback_pending = false; > + cancel_delayed_work(&port->usb_fallback); > } > > -/* > - * When inserting, 2 UCSI events(connector change) are followed by USB events. > - * If we received one USB event, that means USB events are not blocked, so we > - * can complelte for all ports, and we should signal all events. > - */ > -static void gaokun_ucsi_complete_usb_ack(struct gaokun_ucsi *uec) > +static void gaokun_ucsi_usb_fallback(struct work_struct *work) > { > - struct gaokun_ucsi_port *port; > - int idx = 0; > + struct gaokun_ucsi_port *port = > + container_of(to_delayed_work(work), struct gaokun_ucsi_port, usb_fallback); > + struct gaokun_ucsi *uec = port->ucsi; > + unsigned long now; > > - while (idx < uec->num_ports) { > - port = &uec->ports[idx++]; > - if (!completion_done(&port->usb_ack)) > - complete_all(&port->usb_ack); > + guard(mutex)(&uec->usb_lock); > + if (!port->usb_fallback_pending || !READ_ONCE(uec->ucsi->connector)) > + return; > + > + /* A newer connector notification may have moved the deadline. */ > + now = jiffies; > + if (time_before(now, port->usb_fallback_deadline)) { > + mod_delayed_work(system_freezable_wq, &port->usb_fallback, > + port->usb_fallback_deadline - now); > + return; > } > + > + port->usb_fallback_pending = false; > + if (gaokun_ucsi_refresh(uec, port->idx) > 0) > + gaokun_ucsi_handle_usb_mode(port); > } > > -/* > - * USB event is necessary for enabling altmode, the event should follow > - * UCSI event, if not after timeout(this notify may be disabled somehow), > - * then force to enable altmode. > - */ > -static void gaokun_ucsi_handle_no_usb_event(struct gaokun_ucsi *uec, int idx) > +static void gaokun_ucsi_queue_usb_fallback(struct gaokun_ucsi *uec, > unsigned int num) > { > struct gaokun_ucsi_port *port; > > - if (idx < 0 || idx >= uec->num_ports) > + if (!num || num > uec->num_ports || !READ_ONCE(uec->ucsi->connector)) > 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, idx); > - } > + guard(mutex)(&uec->usb_lock); > + port = &uec->ports[num - 1]; > + port->usb_fallback_deadline = jiffies + USB_EVENT_TIMEOUT; > + port->usb_fallback_pending = true; > + mod_delayed_work(system_freezable_wq, &port->usb_fallback, USB_EVENT_TIMEOUT); > } > > static int gaokun_ucsi_notify(struct notifier_block *nb, > @@ -390,8 +403,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_ANY_PORT); > + gaokun_ucsi_usb_event(uec); > return NOTIFY_OK; > > case EC_EVENT_UCSI: > @@ -401,7 +413,7 @@ static int gaokun_ucsi_notify(struct notifier_block *nb, > > ucsi_notify_common(uec->ucsi, cci); > if (UCSI_CCI_CONNECTOR(cci)) > - gaokun_ucsi_handle_no_usb_event(uec, UCSI_CCI_CONNECTOR(cci) - 1); > + gaokun_ucsi_queue_usb_fallback(uec, UCSI_CCI_CONNECTOR(cci)); > > return NOTIFY_OK; > > @@ -436,7 +448,7 @@ static int gaokun_ucsi_ports_init(struct gaokun_ucsi *uec) > ucsi_port->ccx = USBC_CCX_NONE; > ucsi_port->idx = i; > ucsi_port->ucsi = uec; > - init_completion(&ucsi_port->usb_ack); > + INIT_DELAYED_WORK(&ucsi_port->usb_fallback, gaokun_ucsi_usb_fallback); > spin_lock_init(&ucsi_port->lock); > } > > @@ -522,6 +534,7 @@ static int gaokun_ucsi_probe(struct auxiliary_device *adev, > uec->version = UCSI_VERSION_1_0; > uec->nb.notifier_call = gaokun_ucsi_notify; > > + mutex_init(&uec->usb_lock); > INIT_DELAYED_WORK(&uec->work, gaokun_ucsi_register_worker); > > ret = gaokun_ucsi_ports_init(uec); > @@ -547,10 +560,14 @@ static void gaokun_ucsi_remove(struct > auxiliary_device *adev) > int i; > > disable_delayed_work_sync(&uec->work); > - if (uec->registered) { > + if (uec->registered) > gaokun_ec_unregister_notify(uec->ec, &uec->nb); > + > + for (i = 0; i < uec->num_ports; i++) > + disable_delayed_work_sync(&uec->ports[i].usb_fallback); > + > + if (uec->registered) > ucsi_unregister(uec->ucsi); > - } > > for (i = 0; i < uec->num_ports; ++i) > typec_mux_put(uec->ports[i].typec_mux); >