usb: typec: ucsi: Check connection on resume
Subsystems (2)
Heikki Krogerus
maintainercover usb: typec: ucsi: Check connection on resume
Hi,
I'm sending these as an RFC first because I'm not done testing.
I made a small modification to my original proposal (in the bug report). Now also connection during suspend should be covered.
I would appreciate if you guys could test these again. If everything works, and the bug is fixed, let me know, and I'll add your Tested-by tags to the patches.
thanks,
Heikki Krogerus (2):
usb: typec: ucsi: Check the connection on resume
usb: typec: ucsi: acpi: Add PM hooks
drivers/usb/typec/ucsi/ucsi.c | 42 +++++++++++++++++++++--------- drivers/usb/typec/ucsi/ucsi_acpi.c | 15 +++++++++++ 2 files changed, 44 insertions(+), 13 deletions(-)
Signature · 1 line
2.35.1
Heikki Krogerus
maintainerRFC PATCH 1/2 usb: typec: ucsi: Check the connection on resume
This fixes an issue where the partner device is not unregistered properly after resume if it's unplugged during suspend.
--- drivers/usb/typec/ucsi/ucsi.c | 42 ++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 13 deletions(-)
drivers/usb/typec/ucsi/ucsi.c +29 -13
@@ -183,16 +183,6 @@ int ucsi_send_command(struct ucsi *ucsi, u64 command, }EXPORT_SYMBOL_GPL (ucsi_send_command); -int ucsi_resume (struct ucsi *ucsi) -{ -u64 command; - -/* Restore UCSI notification enable mask after system resume */ - command =UCSI_SET_NOTIFICATION_ENABLE | ucsi->ntfy; - -return ucsi_send_command (ucsi, command,NULL ,0 ); -} -EXPORT_SYMBOL_GPL (ucsi_resume);/* -------------------------------------------------------------------------- */ struct ucsi_work {
@@ -746,6 +736,7 @@ static void ucsi_partner_change(struct ucsi_connector *con)static int ucsi_check_connection (struct ucsi_connector *con) { +u8 prev_flags = con->status.flags;u64 command;int ret;
@@ -756,10 +747,13 @@ static int ucsi_check_connection(struct ucsi_connector *con)return ret; } +if (con->status.flags == prev_flags) +return 0 ; +if (con->status.flags &UCSI_CONSTAT_CONNECTED ) { -if (UCSI_CONSTAT_PWR_OPMODE (con->status.flags) == -UCSI_CONSTAT_PWR_OPMODE_PD ) -ucsi_partner_task (con, ucsi_check_altmodes,30 ,0 ); +ucsi_register_partner (con); +ucsi_pwr_opmode_change (con); +ucsi_partner_change (con); }else {ucsi_partner_change (con);ucsi_port_psy_changed (con);
@@ -1280,6 +1274,28 @@ static int ucsi_init(struct ucsi *ucsi)return ret; } +int ucsi_resume (struct ucsi *ucsi) +{ +struct ucsi_connector *con; +u64 command; +int ret; + +/* Restore UCSI notification enable mask after system resume */ + command =UCSI_SET_NOTIFICATION_ENABLE | ucsi->ntfy; + ret =ucsi_send_command (ucsi, command,NULL ,0 ); +if (ret <0 ) +return ret; + +for (con = ucsi->connector; con->port; con++) { +mutex_lock (&con->lock); +ucsi_check_connection (con); +mutex_unlock (&con->lock); + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (ucsi_resume); +static void ucsi_init_work (struct work_struct *work) { struct ucsi *ucsi = container_of(work, struct ucsi, work.work);
Signature · 1 line
2.35.1
Heikki Krogerus
maintainerRFC PATCH 2/2 usb: typec: ucsi: acpi: Add PM hooks
In reply to Heikki KrogerusSome systems notify the driver separately after resume if the state of the connection changed during suspend, but there is no way we can rely on that.
--- drivers/usb/typec/ucsi/ucsi_acpi.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/usb/typec/ucsi/ucsi_acpi.c +15 -0
@@ -185,6 +185,20 @@ static int ucsi_acpi_remove(struct platform_device *pdev)return 0 ; } +static int ucsi_acpi_suspend (struct device *dev) +{ +return 0 ; +} + +static int ucsi_acpi_resume (struct device *dev) +{ +struct ucsi_acpi *ua =dev_get_drvdata (dev); + +return ucsi_resume (ua->ucsi); +} + +static DEFINE_SIMPLE_DEV_PM_OPS(ucsi_acpi_pm_ops, ucsi_acpi_suspend, ucsi_acpi_resume); +static const struct acpi_device_id ucsi_acpi_match[] = { {"PNP0CA0" ,0 }, { },
@@ -194,6 +208,7 @@ MODULE_DEVICE_TABLE(acpi, ucsi_acpi_match);static struct platform_driver ucsi_acpi_platform_driver = { .driver = { .name ="ucsi_acpi" , + .pm =pm_ptr (&ucsi_acpi_pm_ops), .acpi_match_table =ACPI_PTR (ucsi_acpi_match), }, .probe = ucsi_acpi_probe,
Signature · 1 line
2.35.1
Hi,
Quoted 13 lines
Hi,
I'm sending these as an RFC first because I'm not done testing.
I made a small modification to my original proposal (in the bug report). Now also connection during suspend should be covered.
I would appreciate if you guys could test these again. If everything works, and the bug is fixed, let me know, and I'll add your Tested-by tags to the patches.
thanks,
Quoted 7 lines
Heikki Krogerus (2):
usb: typec: ucsi: Check the connection on resume
usb: typec: ucsi: acpi: Add PM hooksdrivers/usb/typec/ucsi/ucsi.c | 42 +++++++++++++++++++++--------- drivers/usb/typec/ucsi/ucsi_acpi.c | 15 +++++++++++ 2 files changed, 44 insertions(+), 13 deletions(-)
I have tested this patch on Lenovo T14 Gen2i with ac adapter and everything looks good. I applied patch on linux 5.19.7.
Dear Heikki,
Quoted 9 lines
I'm sending these as an RFC first because I'm not done testing.
I made a small modification to my original proposal (in the bug report). Now also connection during suspend should be covered.
I would appreciate if you guys could test these again. If everything works, and the bug is fixed, let me know, and I'll add your Tested-by tags to the patches.
Thanks so much for these changes—that's awesome! I have just finished testing this against 5.19.7 (Arch Linux) with a Lenovo X1 (Gen 9).
I am very happy to see that, as far as I can tell, the issue disappeared completely!
However, I am receiving additional warnings via journalctl that I did not receive before; I have attached this trace as an additional log file. Nothing in there seems critical and I can confirm that the system continues to operate normally. I merely wanted to provide you with this additional information in case it is of relevance.
Please let me know if there's anything else I can do here; I really appreciate the time you spent on this!
All the best,
Bastian
ep 08 06:41:34 nimue kernel: ------------[ cut here ]------------
Sep 08 06:41:34 nimue kernel: WARNING: CPU: 0 PID: 448 at kernel/module/main.c:849 module_put+0x8f/0xa0 Sep 08 06:41:34 nimue kernel: Modules linked in: r8153_ecm cdc_ether usbnet r8152 mii typec_displayport rfcomm snd_ctl_led snd_soc_skl_hda_dsp snd_soc_intel_hda_dsp_common snd_soc_hdac_hdmi snd_sof_probes snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic snd_soc_dmic snd_sof_pci_intel_tgl snd_sof_intel_hda_common soundwire_intel soundwire_generic_allocation ccm soundwire_cadence snd_sof_intel_hda algif_aead snd_sof_pci snd_sof_xtensa_dsp des_generic libdes snd_sof ecb snd_sof_utils algif_skcipher snd_soc_hdac_hda snd_hda_ext_core snd_soc_acpi_intel_match cmac snd_soc_acpi soundwire_bus md4 algif_hash bnep snd_soc_core af_alg snd_compress joydev mousedev intel_tcc_cooling iwlmvm ac97_bus x86_pkg_temp_thermal snd_pcm_dmaengine intel_powerclamp coretemp hid_multitouch mac80211 snd_hda_intel iTCO_wdt pmt_telemetry intel_pmc_bxt snd_intel_dspcfg kvm_intel spi_nor snd_intel_sdw_acpi libarc4 iTCO_vendor_support mtd mei_hdcp mei_pxp intel_rapl_msr pmt_class think_lmi snd_hda_codec iwlwifi Sep 08 06:41:34 nimue kernel: firmware_attributes_class wmi_bmof kvm snd_hda_core irqbypass intel_cstate intel_uncore pcspkr uvcvideo psmouse iwlmei snd_hwdep vfat i2c_i801 spi_intel_pci videobuf2_vmalloc fat snd_pcm btusb spi_intel i2c_smbus videobuf2_memops intel_lpss_pci btrtl snd_timer btbcm mei_me cfg80211 intel_lpss videobuf2_v4l2 btintel idma64 videobuf2_common btmtk mei videodev mc bluetooth processor_thermal_device_pci_legacy processor_thermal_device processor_thermal_rfim ecdh_generic processor_thermal_mbox crc16 thunderbolt intel_vsec thinkpad_acpi processor_thermal_rapl ucsi_acpi intel_rapl_common ledtrig_audio typec_ucsi platform_profile igen6_edac intel_soc_dts_iosf typec rfkill roles snd wmi soundcore int3403_thermal soc_button_array int340x_thermal_zone i2c_hid_acpi i2c_hid essiv authenc mac_hid intel_hid int3400_thermal acpi_pad sparse_keymap acpi_thermal_rel acpi_tad pkcs8_key_parser crypto_user fuse bpf_preload ip_tables x_tables btrfs blake2b_generic libcrc32c crc32c_generic xor Sep 08 06:41:34 nimue kernel: raid6_pq dm_crypt cbc encrypted_keys trusted asn1_encoder tee tpm rng_core dm_mod serio_raw crct10dif_pclmul atkbd crc32_pclmul crc32c_intel libps2 ghash_clmulni_intel vivaldi_fmap nvme aesni_intel crypto_simd cryptd nvme_core xhci_pci xhci_pci_renesas i8042 serio i915 intel_gtt drm_buddy video drm_display_helper cec ttm Sep 08 06:41:34 nimue kernel: Unloaded tainted modules: pcc_cpufreq():1 acpi_cpufreq():1 acpi_cpufreq():1 acpi_cpufreq():1 acpi_cpufreq():1 pcc_cpufreq():1 acpi_cpufreq():1 pcc_cpufreq():1 acpi_cpufreq():1 pcc_cpufreq():1 acpi_cpufreq():1 acpi_cpufreq():1 acpi_cpufreq():1 pcc_cpufreq():1 acpi_cpufreq():1 pcc_cpufreq():1 pcc_cpufreq():1 acpi_cpufreq():1 acpi_cpufreq():1 pcc_cpufreq():1 acpi_cpufreq():1 pcc_cpufreq():1 acpi_cpufreq():1 pcc_cpufreq():1 pcc_cpufreq():1 acpi_cpufreq():1 acpi_cpufreq():1 pcc_cpufreq():1 acpi_cpufreq():1 pcc_cpufreq():1 acpi_cpufreq():1 pcc_cpufreq():1 acpi_cpufreq():1 pcc_cpufreq():1 acpi_cpufreq():1 pcc_cpufreq():1 acpi_cpufreq():1 acpi_cpufreq():1 pcc_cpufreq():1 acpi_cpufreq():1 pcc_cpufreq():1 fjes():1 fjes():1 acpi_cpufreq():1 asus_ec_sensors():1 pcc_cpufreq():1 acpi_cpufreq():1 fjes():1 pcc_cpufreq():1 fjes():1 pcc_cpufreq():1 acpi_cpufreq():1 fjes():1 acpi_cpufreq():1 pcc_cpufreq():1 acpi_cpufreq():1 pcc_cpufreq():1 acpi_cpufreq():1 fjes():1 acpi_cpufreq():1 Sep 08 06:41:34 nimue kernel: asus_ec_sensors():1 acpi_cpufreq():1 fjes():1 pcc_cpufreq():1 fjes():1 acpi_cpufreq():1 Sep 08 06:41:34 nimue kernel: CPU: 0 PID: 448 Comm: kworker/0:2 Tainted: G W 5.19.7-arch1-1-ucsi-patch #1 7e4375cb15cb2751a8ce700399419d2870882116 Sep 08 06:41:34 nimue kernel: Hardware name: LENOVO 20XXS33A00/20XXS33A00, BIOS N32ET75W (1.51 ) 12/02/2021 Sep 08 06:41:34 nimue kernel: Workqueue: events ucsi_handle_connector_change [typec_ucsi] Sep 08 06:41:34 nimue kernel: RIP: 0010:module_put+0x8f/0xa0 Sep 08 06:41:34 nimue kernel: Code: 0f 48 8b 40 08 48 89 fe 48 89 c7 e8 8b fa ff ff 65 ff 0d 84 05 0e 61 75 b4 e8 45 40 ec ff eb ad e8 22 40 ec ff c3 cc cc cc cc <0f> 0b eb 99 66 66 2e 0f 1f 84 00 00 00 00 00 66 90 f3 0f 1e fa 55 Sep 08 06:41:34 nimue kernel: RSP: 0018:ffffb61000487d18 EFLAGS: 00010297 Sep 08 06:41:34 nimue kernel: RAX: 0000000000000000 RBX: ffff8db49cf5b008 RCX: 0000000000000000 Sep 08 06:41:34 nimue kernel: RDX: 00000000ffffffff RSI: 0000000000000000 RDI: ffffffffc08bb180 Sep 08 06:41:34 nimue kernel: RBP: 0000000000000000 R08: ffff8db480401758 R09: ffffffffa0a51fb0 Sep 08 06:41:34 nimue kernel: R10: 0000000000000000 R11: 0000000000000000 R12: ffffffffc08bb018 Sep 08 06:41:34 nimue kernel: R13: ffff8db49cf5b088 R14: 0000000000000080 R15: ffff8db484364388 Sep 08 06:41:34 nimue kernel: FS: 0000000000000000(0000) GS:ffff8dbbbf600000(0000) knlGS:0000000000000000 Sep 08 06:41:34 nimue kernel: CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 Sep 08 06:41:34 nimue kernel: CR2: 00007f2ef985a000 CR3: 00000003d7210001 CR4: 0000000000f70ef0 Sep 08 06:41:34 nimue kernel: PKRU: 55555554 Sep 08 06:41:34 nimue kernel: Call Trace: Sep 08 06:41:34 nimue kernel: <TASK> Sep 08 06:41:34 nimue kernel: typec_altmode_update_active+0x6f/0x110 [typec 4340e8e184497847e0034f471886b5beb7adb48f] Sep 08 06:41:34 nimue kernel: typec_remove+0xf0/0x110 [typec 4340e8e184497847e0034f471886b5beb7adb48f] Sep 08 06:41:34 nimue kernel: device_release_driver_internal+0x1b6/0x230 Sep 08 06:41:34 nimue kernel: bus_remove_device+0xdc/0x150 Sep 08 06:41:34 nimue kernel: device_del+0x18f/0x410 Sep 08 06:41:34 nimue kernel: device_unregister+0x17/0x60 Sep 08 06:41:34 nimue kernel: ucsi_unregister_altmodes+0x41/0xa0 [typec_ucsi 91402ff21fa7795a95552024a8006e70bdb35a49] Sep 08 06:41:34 nimue kernel: ucsi_handle_connector_change+0x219/0x2a0 [typec_ucsi 91402ff21fa7795a95552024a8006e70bdb35a49] Sep 08 06:41:34 nimue kernel: ? kfree+0x2e5/0x300 Sep 08 06:41:34 nimue kernel: process_one_work+0x1c4/0x380 Sep 08 06:41:34 nimue kernel: worker_thread+0x51/0x390 Sep 08 06:41:34 nimue kernel: ? rescuer_thread+0x3b0/0x3b0 Sep 08 06:41:34 nimue kernel: kthread+0xdb/0x110 Sep 08 06:41:34 nimue kernel: ? kthread_complete_and_exit+0x20/0x20 Sep 08 06:41:34 nimue kernel: ret_from_fork+0x1f/0x30 Sep 08 06:41:34 nimue kernel: </TASK> Sep 08 06:41:34 nimue kernel: ---[ end trace 0000000000000000 ]---
Heikki Krogerus
maintainerQuoted 18 lines · Bastian Rieck
Dear Heikki,
Quoted 9 lines
I'm sending these as an RFC first because I'm not done testing.
I made a small modification to my original proposal (in the bug report). Now also connection during suspend should be covered.
I would appreciate if you guys could test these again. If everything works, and the bug is fixed, let me know, and I'll add your Tested-by tags to the patches.
Thanks so much for these changes—that's awesome! I have just finished testing this against 5.19.7 (Arch Linux) with a Lenovo X1 (Gen 9).
I am very happy to see that, as far as I can tell, the issue disappeared completely!
Quoted 8 lines
However, I am receiving additional warnings via
journalctlthat I did not receive before; I have attached this trace as an additional log file. Nothing in there seems critical and I can confirm that the system continues to operate normally. I merely wanted to provide you with this additional information in case it is of relevance.Please let me know if there's anything else I can do here; I really appreciate the time you spent on this!
Thank you for the report. That warning certainly needs to be sorted out before I send the final versions. I'll try to reproduce that.
thanks,
Signature · 1 line
heikki
Heikki Krogerus
maintainerHi Bastian,
Quoted 25 lines · Heikki Krogerus
Quoted 24 lines · Bastian Rieck
Dear Heikki,
Quoted 9 lines
I'm sending these as an RFC first because I'm not done testing.
I made a small modification to my original proposal (in the bug report). Now also connection during suspend should be covered.
I would appreciate if you guys could test these again. If everything works, and the bug is fixed, let me know, and I'll add your Tested-by tags to the patches.
Thanks so much for these changes—that's awesome! I have just finished testing this against 5.19.7 (Arch Linux) with a Lenovo X1 (Gen 9).
I am very happy to see that, as far as I can tell, the issue disappeared completely!
However, I am receiving additional warnings via
journalctlthat I did not receive before; I have attached this trace as an additional log file. Nothing in there seems critical and I can confirm that the system continues to operate normally. I merely wanted to provide you with this additional information in case it is of relevance.
Quoted 5 lines
Quoted 2 lines
Please let me know if there's anything else I can do here; I really appreciate the time you spent on this!
Thank you for the report. That warning certainly needs to be sorted out before I send the final versions. I'll try to reproduce that.
I'm not getting anywhere with this one. Could you provide me with the trace output from both module and ucsi events?
To enable those events - assuming debugfs is mounted to /sys/kernel/debug:
% echo 1 > /sys/kernel/debug/tracing/events/ucsi/enable % echo 1 > /sys/kernel/debug/tracing/events/module/enable
Run the suspend resume cycle, and then dump the trace output to a file:
% cat /sys/kernel/debug/tracing/trace > ucsi_trace
thanks,
Signature · 1 line
heikki
Dear Heikki, dear all,
I am still unable to reproduce the previous error messages I mentioned. In the meantime, the UCSI issues disappeared with 5.19.9 for me (!). I think this is related to a revert by Takashi Iwai [1] in 5.19.8.
Given these data, would it be useful to test your patch against 5.19.9 or a more recent version?
Thanks for all your efforts in supporting us here!
All the best,
Bastian
[1] https://www.spinics.net/lists/linux-usb/msg230368.html
Quoted 54 lines · CEST Heikki Krogerus
Hi Bastian,
Quoted 30 lines · Heikki Krogerus
Quoted 29 lines · Bastian Rieck
Dear Heikki,
Quoted 8 lines
I'm sending these as an RFC first because I'm not done testing.
I made a small modification to my original proposal (in the bug
report). Now also connection during suspend should be covered.Quoted 4 lines
I would appreciate if you guys could test these again. If everything works, and the bug is fixed, let me know, and I'll add
your Tested-by tags to the patches.Thanks so much for these changes—that's awesome! I have just finished testing this against 5.19.7 (Arch Linux) with a Lenovo X1 (Gen 9).
I am very happy to see that, as far as I can tell, the issue disappeared completely!
However, I am receiving additional warnings via
journalctlthat I did not receive before; I have attached this trace as an additional log file. Nothing in there seems critical and I can confirm that the system continues to operate normally. I merely wanted to provide you with this additional information in case it is of relevance.Quoted 6 lines
Quoted 2 lines
Please let me know if there's anything else I can do here; I really appreciate the time you spent on this!
Thank you for the report. That warning certainly needs to be sorted out before I send the final versions. I'll try to reproduce that.
I'm not getting anywhere with this one. Could you provide me with the trace output from both module and ucsi events?
To enable those events - assuming debugfs is mounted to
/sys/kernel/debug:% echo 1 >
/sys/kernel/debug/tracing/events/ucsi/enable% echo 1 >/sys/kernel/debug/tracing/events/module/enableRun the suspend resume cycle, and then dump the trace output to a file:
% cat
/sys/kernel/debug/tracing/trace>ucsi_tracethanks,
Heikki Krogerus
maintainerQuoted 9 lines · Bastian Rieck
Dear Heikki, dear all,
I am still unable to reproduce the previous error messages I mentioned. In the meantime, the UCSI issues disappeared with 5.19.9 for me (!). I think this is related to a revert by Takashi Iwai [1] in 5.19.8.
Given these data, would it be useful to test your patch against 5.19.9 or a more recent version?
No need. I'm just about to resend these.
thanks,
Signature · 1 line
heikki