9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Michael Forney <mforney@mforney.org>
To: 9front@9front.org
Subject: [9front] [PATCH] usbxhci: wait for reset to complete before continuing initialization
Date: Sat, 12 Nov 2022 01:11:09 +0000	[thread overview]
Message-ID: <636f05eb.170a0220.934c8.4131@mx.google.com> (raw)


The xhci spec says that the HCRST bit is cleared once the reset is
complete, and that no operational or runtime registers shall be
written while the bit is set.

Waiting for the reset to complete fixes initialization of some host
controllers, such as the ASMedia ASM1142, which otherwise enter an
endless init-recover loop.

Also, add a comment about the reason for the 1ms delay. This appears
to work around a system hang bug in intel chipsets through the 400
series (see errata 15 in [0]).

[0] https://cdrdv2-public.intel.com/620856/620856-009.pdf
---
I was trying to figure out why the two USB 3.1 ports on my system
didn't work, and adding some debug prints in init() appeared to
provide enough delay that it started working. I believe the root
cause is not waiting for HCRST to clear, which is what xhci drivers
in other operating systems do.

diff a39eb30ffa2138a817bd787fdfd25eb65927e7d4 7fdb19aa0098ee41192d1a478db8dfed3514c706
--- a/sys/src/9/port/usbxhci.c
+++ b/sys/src/9/port/usbxhci.c
@@ -481,7 +481,10 @@
 		tsleep(&up->sleep, return0, nil, 10);
 
 	ctlr->opr[USBCMD] = HCRST;
+	/* some intel controllers require 1ms delay after reset */
 	delay(1);
+	for(i=0; (ctlr->opr[USBCMD] & HCRST) != 0 && i<100; i++)
+		tsleep(&up->sleep, return0, nil, 10);
 	for(i=0; (ctlr->opr[USBSTS] & (CNR|HCH)) != HCH && i<100; i++)
 		tsleep(&up->sleep, return0, nil, 10);
 

             reply	other threads:[~2022-11-12  2:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-12  1:11 Michael Forney [this message]
2022-11-24  3:20 ` ori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=636f05eb.170a0220.934c8.4131@mx.google.com \
    --to=mforney@mforney.org \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).