Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 6 May 2022 22:03:41 +0800
From:      Archimedes Gaviola <archimedes.gaviola@gmail.com>
To:        Hans Petter Selasky <hps@selasky.org>
Cc:        freebsd-arm@freebsd.org
Subject:   Re: Raspberry Pi 3B Over-current USB
Message-ID:  <CAJFbk7HOUm74UGS0hchGg-w9RdbKj1k8B3fcfaq8i48C1CY42A@mail.gmail.com>
In-Reply-To: <CAJFbk7EKpwMCav87nMg_5squJx_L-cO%2BeNfKSn5jA620uKT2YA@mail.gmail.com>
References:  <CAJFbk7FgSnWvN9Z7gp1wqW1CFa8bYqrr6zccMWEhotk5HMR=Tg@mail.gmail.com> <5deaf68b-267c-56dd-603d-8ec0d82ceae2@selasky.org> <CAJFbk7Hv7BHDqmg6tFaGwgFvt6%2B2%2Bu0nkCBPrqvGiNN--Y63zQ@mail.gmail.com> <8dc68431-ad3d-84db-45b4-cd661d4a15df@selasky.org> <CAJFbk7EKpwMCav87nMg_5squJx_L-cO%2BeNfKSn5jA620uKT2YA@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
--0000000000001f309d05de585405
Content-Type: text/plain; charset="UTF-8"

On Tue, Apr 12, 2022 at 5:16 PM Archimedes Gaviola <
archimedes.gaviola@gmail.com> wrote:

>
>
> On Mon, Apr 11, 2022 at 9:59 PM Hans Petter Selasky <hps@selasky.org>
> wrote:
>
>> On 4/11/22 15:59, Archimedes Gaviola wrote:
>> > Hi Hans,
>> >
>> > Noted on the self-powered hub, thanks for the suggestion, I will try.
>> >
>> > Just wanted to share the observation from the testing I've conducted
>> with
>> > my Raspberry Pi 4B with the same 14.0-CURRENT to check if overcurrent is
>> > also experienced and it did, there was overcurrent and each ports' power
>> > shut-off during the situation but it was able to recover back. I
>> initiated
>> > the command 'usbconfig reset' and each port gloriously came back alive
>> one
>> > by one and loaded my USB keyboard and Prolific uplcom(4) drivers into
>> > functional and operational states. My measuring device is showing the
>> same
>> > amount of current 460mA while the voltage stayed at 5.05 from a
>> baseline of
>> > 5.15 voltshttps://filebin.net/10vy575q6h2yl8og. Unlike my RPi 3B,
>> voltage
>> > dropped to 4.93 from a baseline of 5.19 volts. So, the difference I
>> > observed is when the voltage dropped below 5, the system will not give a
>> > chance to make the ports come back alive as a sort of protection
>> mechanism.
>> > Sharing to you the logs below (with hw.usb.uhub.debug=1).
>>
>> FreeBSD does not actively check and use "bMaxPower" .
>>
>
> Hi Hans,
>
> It's okay, just tried your recommendation on a self-powered USB hub, my
> Prolific device is now working. Thanks a lot!
>
> Archimedes
>

Hi Hans,

I got my Prolific PL2303 USB-serial device working in RPi 3B without the
self-powered USB hub. I've extended the code /usr/src/sys/dev/usb/usb_hub.c
in the uhub_explore() routine specific to handling overcurrent condition.
Below are the added lines of code.

freebsd@generic:~ % diff -Nur /usr/src/sys/dev/usb/usb_hub.c.orig
/usr/src/sys/dev/usb/usb_hub.c
--- /usr/src/sys/dev/usb/usb_hub.c.orig 2022-04-29 10:52:44.787344000 +0000
+++ /usr/src/sys/dev/usb/usb_hub.c      2022-05-03 07:29:45.159470000 +0000
@@ -1045,6 +1045,25 @@
                            udev, NULL, portno, UHF_C_PORT_OVER_CURRENT);
                        if (err != USB_ERR_NORMAL_COMPLETION)
                                retval = err;
+
+                       /* Turn on hub port power if current get
normalized. */
+                       DPRINTF("Turn on power on port %d.\n", portno);
+                       err = usbd_req_set_port_feature(
+                           udev, NULL, portno, UHF_PORT_POWER);
+                       if (err != USB_ERR_NORMAL_COMPLETION)
+                               retval = err;
+
+                       /* Re-validate if overcurrent still exists. */
+                       err = uhub_read_port_status(sc, portno);
+                       if (err != USB_ERR_NORMAL_COMPLETION)
+                               retval = err;
+                       if (sc->sc_st.port_change &
UPS_C_OVERCURRENT_INDICATOR) {
+                               DPRINTF("Overcurrent condition on port
%u.\n", portno);
+                               err = usbd_req_clear_port_feature(
+                                   udev, NULL, portno,
UHF_C_PORT_OVER_CURRENT);
+                               if (err != USB_ERR_NORMAL_COMPLETION)
+                                       retval = err;
+                       }
                }

The existing code will shut-off the USB hub port(s) right away after
encountering overcurrent and these code extensions will give chance to USB
devices by turning on the USB hub port power by calling
usbd_req_set_port_feature() with UHF_PORT_POWER argument. Turning on the
USB hub port power will verify if the current gets normalized when a USB
device is already plugged-in to a port because unlike the first time when
the USB device is inserted, there's a tendency of an abrupt current being
introduced to the system. So, when there's overcurrent situation and when
the USB device status is normal, the wPortChange value will just change
from 0x0008 (UPS_C_OVERCURRENT_INDICATOR) to 0x0001 (UPS_C_CONNECT_STATUS)
otherwise when the USB device status is not normal, it will be re-validated
for overcurrent situation thus calling again the
usbd_req_clear_port_feature() with UHF_C_PORT_OVER_CURRENT argument to sets
the ports power to shut-off.

So, based on the actual testing and logs when my Prolific PL2303 device
gets inserted to one of my RPi 3B USB port,

usb_needs_explore:
usb_bus_powerd: bus=0xffff000089394000
uhub_intr_callback:
uhub_explore: udev=0xffffa00001124000 addr=1
usb_needs_explore:
uhub_read_port_status: port 1, wPortStatus=0x0503, wPortChange=0x0000,
err=USB_ERR_NORMAL_COMPLETION
uhub_explore: udev=0xffffa000012ed000 addr=2
uhub_read_port_status: port 1, wPortStatus=0x0503, wPortChange=0x0000,
err=USB_ERR_NORMAL_COMPLETION

uhub_read_port_status: port 2, wPortStatus=0x0000, wPortChange=0x0008,
err=USB_ERR_NORMAL_COMPLETION
uhub_explore: Overcurrent on port 2.
uhub_explore: Turn on power on port 2.

(Above 3 lines, an overcurrent is detected followed by turning on the power
on port 2 and the wPortChange=0x0008 is in UPS_C_OVERCURRENT_INDICATOR, an
overcurrent status.)

uhub_read_port_status: port 2, wPortStatus=0x0101, wPortChange=0x0001,
err=USB_ERR_NORMAL_COMPLETION

(After some time, port 2 is already having wPortChange=0x0001, it's now
getting UPS_C_CONNECT_STATUS which is in connected status. Due to this
status, the code exits and never executes the re-validation of overcurrent
code as it's no longer manifesting the overcurrent status.)

uhub_reattach_port: reattaching port 2
uhub_read_port_status: port 2, wPortStatus=0x0101, wPortChange=0x0000,
err=USB_ERR_NORMAL_COMPLETION
uhub_reattach_port: Port 2 is in Host Mode
uhub_intr_callback:
usb_needs_explore:
uhub_read_port_status: port 2, wPortStatus=0x0103, wPortChange=0x0000,
err=USB_ERR_NORMAL_COMPLETION
uhub_intr_callback:
usb_needs_explore:
usb_bus_port_set_device: bus 0xffff000089394000 devices[5] =
0xffffa00018900000

ugen1.5: <Prolific Technology Inc. USB-Serial Controller> at usbus1
uplcom0 on uhub1
uplcom0: <Prolific Technology Inc. USB-Serial Controller, class 0/0, rev
2.00/3.00, addr 5> on usbus1

(The above 3 lines give the info of my PL2303 Prolific ugen(4) and
uplcom(4) device drivers were loaded successfully. Below logs are for the
rest of my USB devices such as my keyboards and Epson printer.)

uhub_read_port_status: port 3, wPortStatus=0x0301, wPortChange=0x0001,
err=USB_ERR_NORMAL_COMPLETION
uhub_reattach_port: reattaching port 3
ugen1.6: <A4Tech USB Keyboard> at usbus1 (disconnected)
ukbd0: at uhub1, port 3, addr 6 (disconnected)
uhub_child_location: device not on hub
uhub_child_pnpinfo: device not on hub
ukbd0: detached
uhid0: at uhub1, port 3, addr 6 (disconnected)
uhub_child_location: device not on hub
uhub_child_pnpinfo: device not on hub
uhid0: detached
usb_bus_port_set_device: bus 0xffff000089394000 devices[6] = 0
uhub_read_port_status: port 3, wPortStatus=0x0301, wPortChange=0x0000,
err=USB_ERR_NORMAL_COMPLETION
uhub_reattach_port: Port 3 is in Host Mode
uhub_intr_callback:
usb_needs_explore:
uhub_reset_tt_callback: TT buffer reset
uhub_reset_tt_callback: TT buffer reset
usb_needs_explore:
uhub_intr_callback:
usb_needs_explore:
uhub_read_port_status: port 3, wPortStatus=0x0303, wPortChange=0x0000,
err=USB_ERR_NORMAL_COMPLETION
usb_bus_port_set_device: bus 0xffff000089394000 devices[6] =
0xffffa000017ab000
ugen1.6: <A4Tech USB Keyboard> at usbus1
ukbd0 on uhub1
ukbd0: <A4Tech USB Keyboard, class 0/0, rev 2.00/1.05, addr 6> on usbus1
kbd1 at ukbd0
uhid0 on uhub1
uhid0: <A4Tech USB Keyboard, class 0/0, rev 2.00/1.05, addr 6> on usbus1
uhub_read_port_status: port 4, wPortStatus=0x0101, wPortChange=0x0001,
err=USB_ERR_NORMAL_COMPLETION
uhub_reattach_port: reattaching port 4
ugen1.7: <USB Adapter USB Device> at usbus1 (disconnected)
ukbd1: at uhub1, port 4, addr 7 (disconnected)
uhub_child_location: device not on hub
uhub_child_pnpinfo: device not on hub
ukbd1: detached
usb_bus_port_set_device: bus 0xffff000089394000 devices[7] = 0
uhub_read_port_status: port 4, wPortStatus=0x0101, wPortChange=0x0000,
err=USB_ERR_NORMAL_COMPLETION
uhub_reattach_port: Port 4 is in Host Mode
uhub_read_port_status: port 4, wPortStatus=0x0103, wPortChange=0x0000,
err=USB_ERR_NORMAL_COMPLETION
usb_bus_port_set_device: bus 0xffff000089394000 devices[7] =
0xffffa00018909000
ugen1.7: <USB Adapter USB Device> at usbus1
ukbd1 on uhub1
ukbd1: <USB Adapter USB Device, class 0/0, rev 1.10/0.01, addr 7> on usbus1
kbd2 at ukbd1
uhub_read_port_status: port 5, wPortStatus=0x0103, wPortChange=0x0000,
err=USB_ERR_NORMAL_COMPLETION
usb_bus_powerd: bus=0xffff000089394000
uhub_explore: udev=0xffffa00001124000 addr=1
uhub_reset_tt_callback: TT buffer reset
uhub_read_port_status: port 1, wPortStatus=0x0503, wPortChange=0x0000,
err=USB_ERR_NORMAL_COMPLETION
uhub_reset_tt_callback: TT buffer reset
uhub_explore: udev=0xffffa000012ed000 addr=2
uhub_reset_tt_callback: TT buffer reset
uhub_read_port_status: port 1, wPortStatus=0x0503, wPortChange=0x0000,
err=USB_ERR_NORMAL_COMPLETION
uhub_read_port_status: port 2, wPortStatus=0x0103, wPortChange=0x0000,
err=USB_ERR_NORMAL_COMPLETION
uhub_read_port_status: port 3, wPortStatus=0x0303, wPortChange=0x0000,
err=USB_ERR_NORMAL_COMPLETION
uhub_read_port_status: port 4, wPortStatus=0x0103, wPortChange=0x0000,
err=USB_ERR_NORMAL_COMPLETION
uhub_read_port_status: port 5, wPortStatus=0x0103, wPortChange=0x0000,
err=USB_ERR_NORMAL_COMPLETION

root@generic:~ # usbconfig
ugen1.1: <DWCOTG OTG Root HUB> at usbus1, cfg=0 md=HOST spd=HIGH (480Mbps)
pwr=SAVE (0mA)
ugen1.2: <vendor 0x0424 product 0x9514> at usbus1, cfg=0 md=HOST spd=HIGH
(480Mbps) pwr=SAVE (2mA)
ugen1.3: <vendor 0x0424 product 0xec00> at usbus1, cfg=0 md=HOST spd=HIGH
(480Mbps) pwr=ON (2mA)
ugen1.4: <EPSON EPSON UB-U03II> at usbus1, cfg=0 md=HOST spd=FULL (12Mbps)
pwr=ON (10mA)
ugen1.5: <Prolific Technology Inc. USB-Serial Controller> at usbus1, cfg=0
md=HOST spd=FULL (12Mbps) pwr=ON (100mA)
ugen1.6: <A4Tech USB Keyboard> at usbus1, cfg=0 md=HOST spd=LOW (1.5Mbps)
pwr=ON (100mA)
ugen1.7: <USB Adapter USB Device> at usbus1, cfg=0 md=HOST spd=FULL
(12Mbps) pwr=ON (100mA)

With these added extensions for some days now (14-CURRENT dated April 21,
2022), so far my RPi 3B is working normally, I haven't experienced any
system crash or freeze, keyboard, printer and PL2303 Prolific devices are
working well without any problems even the USB Ethernet (ue0) is working as
well. Plugging and unplugging this PL2303 Prolific device every now and
then from each port works as expected. Doing "usbconfig reset" works
normally as performed. Lastly, this also works with my RPi 4B.

Any comments or suggestions as I am not a seasoned kernel coder :-)

Thanks,
Archimedes

--0000000000001f309d05de585405
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">=
<div dir=3D"ltr" class=3D"gmail_attr">On Tue, Apr 12, 2022 at 5:16 PM Archi=
medes Gaviola &lt;<a href=3D"mailto:archimedes.gaviola@gmail.com">archimede=
s.gaviola@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quot=
e" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204)=
;padding-left:1ex"><div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div cla=
ss=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Mon, Apr 11, 20=
22 at 9:59 PM Hans Petter Selasky &lt;<a href=3D"mailto:hps@selasky.org" ta=
rget=3D"_blank">hps@selasky.org</a>&gt; wrote:<br></div><blockquote class=
=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rg=
b(204,204,204);padding-left:1ex">On 4/11/22 15:59, Archimedes Gaviola wrote=
:<br>
&gt; Hi Hans,<br>
&gt; <br>
&gt; Noted on the self-powered hub, thanks for the suggestion, I will try.<=
br>
&gt; <br>
&gt; Just wanted to share the observation from the testing I&#39;ve conduct=
ed with<br>
&gt; my Raspberry Pi 4B with the same 14.0-CURRENT to check if overcurrent =
is<br>
&gt; also experienced and it did, there was overcurrent and each ports&#39;=
 power<br>
&gt; shut-off during the situation but it was able to recover back. I initi=
ated<br>
&gt; the command &#39;usbconfig reset&#39; and each port gloriously came ba=
ck alive one<br>
&gt; by one and loaded my USB keyboard and Prolific uplcom(4) drivers into<=
br>
&gt; functional and operational states. My measuring device is showing the =
same<br>
&gt; amount of current 460mA while the voltage stayed at 5.05 from a baseli=
ne of<br>
&gt; 5.15 voltshttps://<a href=3D"http://filebin.net/10vy575q6h2yl8og" rel=
=3D"noreferrer" target=3D"_blank">filebin.net/10vy575q6h2yl8og</a>. Unlike =
my RPi 3B, voltage<br>
&gt; dropped to 4.93 from a baseline of 5.19 volts. So, the difference I<br=
>
&gt; observed is when the voltage dropped below 5, the system will not give=
 a<br>
&gt; chance to make the ports come back alive as a sort of protection mecha=
nism.<br>
&gt; Sharing to you the logs below (with hw.usb.uhub.debug=3D1).<br>
<br>
FreeBSD does not actively check and use &quot;bMaxPower&quot; .<br></blockq=
uote><div><br></div><div>Hi Hans,</div></div><div class=3D"gmail_quote"><br=
></div><div class=3D"gmail_quote">It&#39;s okay, just tried your recommenda=
tion on a self-powered USB hub, my Prolific device is now working. Thanks a=
 lot!</div><div class=3D"gmail_quote"><br></div><div class=3D"gmail_quote">=
Archimedes<br></div></div></blockquote><div><br></div><div>Hi Hans,</div><d=
iv><br></div><div>I got my Prolific PL2303 USB-serial=20
device working in RPi 3B without the self-powered USB hub. I&#39;ve extende=
d the code /usr/src/sys/dev/usb/usb_hub.c in the uhub_explore() routine spe=
cific to handling overcurrent condition. Below are the added lines of code.=
<br></div><div><br></div><div>freebsd@generic:~ % diff -Nur /usr/src/sys/de=
v/usb/usb_hub.c.orig /usr/src/sys/dev/usb/usb_hub.c</div><div>--- /usr/src/=
sys/dev/usb/usb_hub.c.orig 2022-04-29 10:52:44.787344000 +0000<br>+++ /usr/=
src/sys/dev/usb/usb_hub.c =C2=A0 =C2=A0 =C2=A02022-05-03 07:29:45.159470000=
 +0000<br>@@ -1045,6 +1045,25 @@<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 udev, NULL, por=
tno, UHF_C_PORT_OVER_CURRENT);<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (err !=3D USB_ERR_NORMAL_COMP=
LETION)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 retval =3D err;<br>+<br>+ =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 /* Turn on hub port power if current get normalized. */<br>+ =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 DPRINTF(=
&quot;Turn on power on port %d.\n&quot;, portno);<br>+ =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 err =3D usbd_req_s=
et_port_feature(<br>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 udev, NULL, portno, UHF_PORT_POWER);=
<br>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 if (err !=3D USB_ERR_NORMAL_COMPLETION)<br>+ =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 retval =3D err;<br>+<br>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* Re-validate if overcurrent still =
exists. */<br>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 err =3D uhub_read_port_status(sc, portno);<br>+ =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (e=
rr !=3D USB_ERR_NORMAL_COMPLETION)<br>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 retva=
l =3D err;<br>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 if (sc-&gt;sc_st.port_change &amp; UPS_C_OVERCURRENT_INDI=
CATOR) {<br>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 DPRINTF(&quot;Overcurrent con=
dition on port %u.\n&quot;, portno);<br>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 e=
rr =3D usbd_req_clear_port_feature(<br>+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 udev, NULL, portno, UHF_C_PORT_OVER_CURRENT);<br>+ =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 if (err !=3D USB_ERR_NORMAL_COMPLETION)<br>+ =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 retval =3D err;<br>+ =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }=
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }</div><div><br=
></div><div>The existing code will shut-off the USB hub port(s) right away =
after encountering overcurrent and these code extensions will give chance t=
o USB devices by turning on the USB hub port power by calling usbd_req_set_=
port_feature() with UHF_PORT_POWER argument. Turning on the USB hub port po=
wer will verify if the current gets normalized when a USB device is already=
 plugged-in to a port because unlike the first time when the USB device is =
inserted, there&#39;s a tendency of an abrupt current being introduced to t=
he system. So, when there&#39;s overcurrent situation and when the USB devi=
ce status is normal, the wPortChange value will just change from 0x0008 (UP=
S_C_OVERCURRENT_INDICATOR) to=20
0x0001 (UPS_C_CONNECT_STATUS) otherwise when the USB device status is not n=
ormal, it will be re-validated for overcurrent situation thus calling again=
 the=20
usbd_req_clear_port_feature() with=20
UHF_C_PORT_OVER_CURRENT argument to sets the ports power to shut-off.</div>=
<div><br></div><div>So, based on the actual testing and logs when my Prolif=
ic PL2303

device gets inserted to one of my RPi 3B USB port,</div><div><br></div><div=
>usb_needs_explore:<br>usb_bus_powerd: bus=3D0xffff000089394000<br>uhub_int=
r_callback:<br>uhub_explore: udev=3D0xffffa00001124000 addr=3D1<br>usb_need=
s_explore:<br>uhub_read_port_status: port 1, wPortStatus=3D0x0503, wPortCha=
nge=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION<br>uhub_explore: udev=3D0xfff=
fa000012ed000 addr=3D2<br>uhub_read_port_status: port 1, wPortStatus=3D0x05=
03, wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION</div><div><br></d=
iv><div>uhub_read_port_status: port 2, wPortStatus=3D0x0000, wPortChange=3D=
0x0008, err=3DUSB_ERR_NORMAL_COMPLETION<br></div><div></div><div>uhub_explo=
re: Overcurrent on port 2.<br>uhub_explore: Turn on power on port 2.</div><=
div><br></div><div>(Above 3 lines, an overcurrent is detected followed by t=
urning on the power on port 2 and the=20
wPortChange=3D0x0008 is in=20
UPS_C_OVERCURRENT_INDICATOR,

an overcurrent status.)<br></div><div><br></div><div>uhub_read_port_status:=
 port 2, wPortStatus=3D0x0101, wPortChange=3D0x0001, err=3DUSB_ERR_NORMAL_C=
OMPLETION</div><div><br></div><div>(After some time, port 2 is already havi=
ng
wPortChange=3D0x0001, it&#39;s now getting=20
UPS_C_CONNECT_STATUS

which is in connected status. Due to this status, the code exits and never =
executes the re-validation of overcurrent code as it&#39;s no longer manife=
sting the overcurrent status.) <br></div><div><br></div><div>uhub_reattach_=
port: reattaching port 2<br>uhub_read_port_status: port 2, wPortStatus=3D0x=
0101, wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION<br>uhub_reattac=
h_port: Port 2 is in Host Mode<br>uhub_intr_callback:<br>usb_needs_explore:=
<br>uhub_read_port_status: port 2, wPortStatus=3D0x0103, wPortChange=3D0x00=
00, err=3DUSB_ERR_NORMAL_COMPLETION<br>uhub_intr_callback:<br>usb_needs_exp=
lore:<br>usb_bus_port_set_device: bus 0xffff000089394000 devices[5] =3D 0xf=
fffa00018900000</div><div><br></div><div>ugen1.5: &lt;Prolific Technology I=
nc. USB-Serial Controller&gt; at usbus1<br>uplcom0 on uhub1<br>uplcom0: &lt=
;Prolific Technology Inc. USB-Serial Controller, class 0/0, rev 2.00/3.00, =
addr 5&gt; on usbus1<br></div><div><br></div><div>(The above 3 lines give t=
he info of my PL2303 Prolific ugen(4) and uplcom(4) device drivers were loa=
ded successfully. Below logs are for the rest of my USB devices such as my =
keyboards and Epson printer.)</div><div><br></div><div>uhub_read_port_statu=
s: port 3, wPortStatus=3D0x0301, wPortChange=3D0x0001, err=3DUSB_ERR_NORMAL=
_COMPLETION<br>uhub_reattach_port: reattaching port 3<br>ugen1.6: &lt;A4Tec=
h USB Keyboard&gt; at usbus1 (disconnected)<br>ukbd0: at uhub1, port 3, add=
r 6 (disconnected)<br>uhub_child_location: device not on hub<br>uhub_child_=
pnpinfo: device not on hub<br>ukbd0: detached<br>uhid0: at uhub1, port 3, a=
ddr 6 (disconnected)<br>uhub_child_location: device not on hub<br>uhub_chil=
d_pnpinfo: device not on hub<br>uhid0: detached<br>usb_bus_port_set_device:=
 bus 0xffff000089394000 devices[6] =3D 0<br>uhub_read_port_status: port 3, =
wPortStatus=3D0x0301, wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION=
<br>uhub_reattach_port: Port 3 is in Host Mode<br>uhub_intr_callback:<br>us=
b_needs_explore:<br>uhub_reset_tt_callback: TT buffer reset<br>uhub_reset_t=
t_callback: TT buffer reset<br>usb_needs_explore:<br>uhub_intr_callback:<br=
>usb_needs_explore:<br>uhub_read_port_status: port 3, wPortStatus=3D0x0303,=
 wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION<br>usb_bus_port_set_=
device: bus 0xffff000089394000 devices[6] =3D 0xffffa000017ab000<br>ugen1.6=
: &lt;A4Tech USB Keyboard&gt; at usbus1<br>ukbd0 on uhub1<br>ukbd0: &lt;A4T=
ech USB Keyboard, class 0/0, rev 2.00/1.05, addr 6&gt; on usbus1<br>kbd1 at=
 ukbd0<br>uhid0 on uhub1<br>uhid0: &lt;A4Tech USB Keyboard, class 0/0, rev =
2.00/1.05, addr 6&gt; on usbus1<br>uhub_read_port_status: port 4, wPortStat=
us=3D0x0101, wPortChange=3D0x0001, err=3DUSB_ERR_NORMAL_COMPLETION<br>uhub_=
reattach_port: reattaching port 4<br>ugen1.7: &lt;USB Adapter USB Device&gt=
; at usbus1 (disconnected)<br>ukbd1: at uhub1, port 4, addr 7 (disconnected=
)<br>uhub_child_location: device not on hub<br>uhub_child_pnpinfo: device n=
ot on hub<br>ukbd1: detached<br>usb_bus_port_set_device: bus 0xffff00008939=
4000 devices[7] =3D 0<br>uhub_read_port_status: port 4, wPortStatus=3D0x010=
1, wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION<br>uhub_reattach_p=
ort: Port 4 is in Host Mode<br>uhub_read_port_status: port 4, wPortStatus=
=3D0x0103, wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION<br>usb_bus=
_port_set_device: bus 0xffff000089394000 devices[7] =3D 0xffffa00018909000<=
br>ugen1.7: &lt;USB Adapter USB Device&gt; at usbus1<br>ukbd1 on uhub1<br>u=
kbd1: &lt;USB Adapter USB Device, class 0/0, rev 1.10/0.01, addr 7&gt; on u=
sbus1<br>kbd2 at ukbd1<br>uhub_read_port_status: port 5, wPortStatus=3D0x01=
03, wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION<br>usb_bus_powerd=
: bus=3D0xffff000089394000<br>uhub_explore: udev=3D0xffffa00001124000 addr=
=3D1<br>uhub_reset_tt_callback: TT buffer reset<br>uhub_read_port_status: p=
ort 1, wPortStatus=3D0x0503, wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COM=
PLETION<br>uhub_reset_tt_callback: TT buffer reset<br>uhub_explore: udev=3D=
0xffffa000012ed000 addr=3D2<br>uhub_reset_tt_callback: TT buffer reset<br>u=
hub_read_port_status: port 1, wPortStatus=3D0x0503, wPortChange=3D0x0000, e=
rr=3DUSB_ERR_NORMAL_COMPLETION<br>uhub_read_port_status: port 2, wPortStatu=
s=3D0x0103, wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION<br>uhub_r=
ead_port_status: port 3, wPortStatus=3D0x0303, wPortChange=3D0x0000, err=3D=
USB_ERR_NORMAL_COMPLETION<br>uhub_read_port_status: port 4, wPortStatus=3D0=
x0103, wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION<br>uhub_read_p=
ort_status: port 5, wPortStatus=3D0x0103, wPortChange=3D0x0000, err=3DUSB_E=
RR_NORMAL_COMPLETION</div><div><br></div><div>root@generic:~ # usbconfig</d=
iv><div>ugen1.1: &lt;DWCOTG OTG Root HUB&gt; at usbus1, cfg=3D0 md=3DHOST s=
pd=3DHIGH (480Mbps) pwr=3DSAVE (0mA)<br>ugen1.2: &lt;vendor 0x0424 product =
0x9514&gt; at usbus1, cfg=3D0 md=3DHOST spd=3DHIGH (480Mbps) pwr=3DSAVE (2m=
A)<br>ugen1.3: &lt;vendor 0x0424 product 0xec00&gt; at usbus1, cfg=3D0 md=
=3DHOST spd=3DHIGH (480Mbps) pwr=3DON (2mA)<br>ugen1.4: &lt;EPSON EPSON UB-=
U03II&gt; at usbus1, cfg=3D0 md=3DHOST spd=3DFULL (12Mbps) pwr=3DON (10mA)<=
br>ugen1.5: &lt;Prolific Technology Inc. USB-Serial Controller&gt; at usbus=
1, cfg=3D0 md=3DHOST spd=3DFULL (12Mbps) pwr=3DON (100mA)<br>ugen1.6: &lt;A=
4Tech USB Keyboard&gt; at usbus1, cfg=3D0 md=3DHOST spd=3DLOW (1.5Mbps) pwr=
=3DON (100mA)<br>ugen1.7: &lt;USB Adapter USB Device&gt; at usbus1, cfg=3D0=
 md=3DHOST spd=3DFULL (12Mbps) pwr=3DON (100mA)<br></div><div><br></div><di=
v>With these added extensions for some days now (14-CURRENT dated April 21,=
 2022), so far my RPi 3B is working normally, I haven&#39;t experienced any=
 system crash or freeze, keyboard, printer and PL2303 Prolific devices are =
working well without any problems even the USB Ethernet (ue0) is working as=
 well. Plugging and unplugging this PL2303 Prolific device every now and th=
en from each port works as expected. Doing &quot;usbconfig reset&quot; work=
s normally as performed. Lastly, this also works with my RPi 4B.</div><div>=
<br></div><div>Any comments or suggestions as I am not a seasoned kernel co=
der :-)<br></div><div><br></div><div></div><div>Thanks,</div><div>Archimede=
s<br></div><div><br></div><div><br></div><div>=C2=A0<br></div><div><br></di=
v><div><br></div><div><br></div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </div><div=
><br></div><div><br>

 </div></div></div>

--0000000000001f309d05de585405--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJFbk7HOUm74UGS0hchGg-w9RdbKj1k8B3fcfaq8i48C1CY42A>