From nobody Fri May 6 14:03:41 2022 X-Original-To: freebsd-arm@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 032B11AB15D5 for ; Fri, 6 May 2022 14:03:55 +0000 (UTC) (envelope-from archimedes.gaviola@gmail.com) Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Kvsk20mZ2z3Dcc for ; Fri, 6 May 2022 14:03:54 +0000 (UTC) (envelope-from archimedes.gaviola@gmail.com) Received: by mail-qt1-x830.google.com with SMTP id t16so6016351qtr.9 for ; Fri, 06 May 2022 07:03:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=p/J514D1rsLTocA+35T29+k1OBU2M8Dk21Smu2TCJ/g=; b=iSe1yRs4fRGlT2BVl8BsVsDHjfYWoF9ugqWiX+X0Tp8hoxaTn8+ZCnn7wESB7kgapT r/T/IQL1fMPIrIAxHbSn/wvlK5o6v++WEb+PNDn97+uG3JXGM4MQjnl50ZTEEB+P60Hb H4jPHd6kA5/LHGyD+pxxl3K1ZJhySKey0dZFQhoeuMi7N5gINRPDXWLQ11l/SzrdSGAK a1lmjo6DOZS0sAmnRXicznGque/k9DI2C7EZ4URs9HeWMSYz9qU5bGQalfkBaLfa2VVP GqIf/cysZUqQPoiGMkkO3hu1StB1bY9jukOpy4x+fu/c4TWFir/k4dh9nw8/ip6Kj10w DSAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=p/J514D1rsLTocA+35T29+k1OBU2M8Dk21Smu2TCJ/g=; b=TTQj+zPp2t19yGiG4ZWIgfhPTAw+JKq4Mty74LVxJzkIwqmwyp39f73m202855mcoe 43Px7tMswEhqX165cuLFWJOeKiGH3o9vF+Sh/nVTbPGZZ66rLDbSMVTSLFHqdgMqB0qS UTN1225OAlTYPRbb1RDBV3dFIAI6d9rLy0sDgK3c4XgjUzo/Vg0QmQECpHaXnTysjR0F 8+yTtDWnhDON//I59zfwYNkEMFyGTjHk3JcwPb8YvnXblL5edsQav291s9eyZ5YR2KqM FziLOG8kSmkBu5EK1OFXM/TCBFYoySBSWe5ikU61TEZGxGGoXMjj8Jvo/8p4If1aPKLp +dug== X-Gm-Message-State: AOAM530mxEmXXLkrUs5/e23OKO0dKBO6WTUK8M+UjxRhDq7W322kp5jS cDsgUxv3ro5xKVSflR4grBf+ThoB3E6TiuZWiJHYk1OATj+LZw== X-Google-Smtp-Source: ABdhPJxaMKvlHEyVHenMcm0POd8wuwNm+CUDFfNoeHVLhF0JfvPoeXZyU8G9jKKMdKhZJvO5s1dCgjnn1lUfVfFXb/4= X-Received: by 2002:a05:622a:412:b0:2e1:de3b:d110 with SMTP id n18-20020a05622a041200b002e1de3bd110mr2917842qtx.420.1651845833370; Fri, 06 May 2022 07:03:53 -0700 (PDT) List-Id: Porting FreeBSD to ARM processors List-Archive: https://lists.freebsd.org/archives/freebsd-arm List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-arm@freebsd.org MIME-Version: 1.0 References: <5deaf68b-267c-56dd-603d-8ec0d82ceae2@selasky.org> <8dc68431-ad3d-84db-45b4-cd661d4a15df@selasky.org> In-Reply-To: From: Archimedes Gaviola Date: Fri, 6 May 2022 22:03:41 +0800 Message-ID: Subject: Re: Raspberry Pi 3B Over-current USB To: Hans Petter Selasky Cc: freebsd-arm@freebsd.org Content-Type: multipart/alternative; boundary="0000000000001f309d05de585405" X-Rspamd-Queue-Id: 4Kvsk20mZ2z3Dcc X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20210112 header.b=iSe1yRs4; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of archimedesgaviola@gmail.com designates 2607:f8b0:4864:20::830 as permitted sender) smtp.mailfrom=archimedesgaviola@gmail.com X-Spamd-Result: default: False [-3.02 / 15.00]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36:c]; FREEMAIL_FROM(0.00)[gmail.com]; MID_RHS_MATCH_FROMTLD(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; RCPT_COUNT_TWO(0.00)[2]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; NEURAL_HAM_SHORT(-0.02)[-0.023]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; TAGGED_FROM(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20210112]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-arm@freebsd.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::830:from]; MLMMJ_DEST(0.00)[freebsd-arm]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-ThisMailContainsUnwantedMimeParts: N Status: O Content-Length: 26025 Lines: 488 --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 > 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: at usbus1 uplcom0 on uhub1 uplcom0: 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: 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: at usbus1 ukbd0 on uhub1 ukbd0: on usbus1 kbd1 at ukbd0 uhid0 on uhub1 uhid0: 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: 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: at usbus1 ukbd1 on uhub1 ukbd1: 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: at usbus1, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA) ugen1.2: at usbus1, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (2mA) ugen1.3: at usbus1, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON (2mA) ugen1.4: at usbus1, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (10mA) ugen1.5: at usbus1, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (100mA) ugen1.6: at usbus1, cfg=0 md=HOST spd=LOW (1.5Mbps) pwr=ON (100mA) ugen1.7: 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


=
On Tue, Apr 12, 2022 at 5:16 PM Archi= medes Gaviola <archimede= s.gaviola@gmail.com> wrote:


On Mon, Apr 11, 20= 22 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.<= br> >
> Just wanted to share the observation from the testing I've conduct= ed 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 initi= ated
> the command 'usbconfig reset' and each port gloriously came ba= ck alive one
> by one and loaded my USB keyboard and Prolific uplcom(4) drivers into<= br> > functional and operational states. My measuring device is showing the = same
> amount of current 460mA while the voltage stayed at 5.05 from a baseli= ne 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 mecha= nism.
> Sharing to you the logs below (with hw.usb.uhub.debug=3D1).

FreeBSD does not actively check and use "bMaxPower" .

Hi Hans,
It's okay, just tried your recommenda= tion 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=20 device working in RPi 3B without the self-powered USB hub. I'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.=

freebsd@generic:~ % diff -Nur /usr/src/sys/de= v/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 =C2=A0 =C2=A0 =C2=A02022-05-03 07:29:45.159470000= +0000
@@ -1045,6 +1045,25 @@
=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);
=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)
=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;
+
+ = =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. */
+ =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 DPRINTF(= "Turn on power on port %d.\n", portno);
+ =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(
+ =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);=
+ =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)
+ =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;
+
+ =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. */
+ =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);
+ =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)
+ =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;
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 if (sc->sc_st.port_change & UPS_C_OVERCURRENT_INDI= CATOR) {
+ =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("Overcurrent con= dition on port %u.\n", portno);
+ =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(
+ =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);
+ =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)
+ =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;
+ =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 }
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's a tendency of an abrupt current being introduced to t= he system. So, when there'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.
=

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

usb_needs_explore:
usb_bus_powerd: bus=3D0xffff000089394000
uhub_int= r_callback:
uhub_explore: udev=3D0xffffa00001124000 addr=3D1
usb_need= s_explore:
uhub_read_port_status: port 1, wPortStatus=3D0x0503, wPortCha= nge=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION
uhub_explore: udev=3D0xfff= fa000012ed000 addr=3D2
uhub_read_port_status: port 1, wPortStatus=3D0x05= 03, wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION

uhub_read_port_status: port 2, wPortStatus=3D0x0000, wPortChange=3D= 0x0008, err=3DUSB_ERR_NORMAL_COMPLETION
uhub_explo= re: Overcurrent on port 2.
uhub_explore: Turn on power on port 2.
<= 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.)

uhub_read_port_status:= port 2, wPortStatus=3D0x0101, wPortChange=3D0x0001, err=3DUSB_ERR_NORMAL_C= OMPLETION

(After some time, port 2 is already havi= ng wPortChange=3D0x0001, it'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's no longer manife= sting the overcurrent status.)

uhub_reattach_= port: reattaching port 2
uhub_read_port_status: port 2, wPortStatus=3D0x= 0101, wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION
uhub_reattac= h_port: Port 2 is in Host Mode
uhub_intr_callback:
usb_needs_explore:=
uhub_read_port_status: port 2, wPortStatus=3D0x0103, wPortChange=3D0x00= 00, err=3DUSB_ERR_NORMAL_COMPLETION
uhub_intr_callback:
usb_needs_exp= lore:
usb_bus_port_set_device: bus 0xffff000089394000 devices[5] =3D 0xf= fffa00018900000

ugen1.5: <Prolific Technology I= nc. 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 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.)

uhub_read_port_statu= s: port 3, wPortStatus=3D0x0301, wPortChange=3D0x0001, err=3DUSB_ERR_NORMAL= _COMPLETION
uhub_reattach_port: reattaching port 3
ugen1.6: <A4Tec= h USB Keyboard> at usbus1 (disconnected)
ukbd0: at uhub1, port 3, add= r 6 (disconnected)
uhub_child_location: device not on hub
uhub_child_= pnpinfo: device not on hub
ukbd0: detached
uhid0: at uhub1, port 3, a= ddr 6 (disconnected)
uhub_child_location: device not on hub
uhub_chil= d_pnpinfo: device not on hub
uhid0: detached
usb_bus_port_set_device:= bus 0xffff000089394000 devices[6] =3D 0
uhub_read_port_status: port 3, = wPortStatus=3D0x0301, wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION=
uhub_reattach_port: Port 3 is in Host Mode
uhub_intr_callback:
us= b_needs_explore:
uhub_reset_tt_callback: TT buffer reset
uhub_reset_t= t_callback: TT buffer reset
usb_needs_explore:
uhub_intr_callback:usb_needs_explore:
uhub_read_port_status: port 3, wPortStatus=3D0x0303,= wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION
usb_bus_port_set_= device: bus 0xffff000089394000 devices[6] =3D 0xffffa000017ab000
ugen1.6= : <A4Tech USB Keyboard> at usbus1
ukbd0 on uhub1
ukbd0: <A4T= ech 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, wPortStat= us=3D0x0101, wPortChange=3D0x0001, err=3DUSB_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 n= ot on hub
ukbd1: detached
usb_bus_port_set_device: bus 0xffff00008939= 4000 devices[7] =3D 0
uhub_read_port_status: port 4, wPortStatus=3D0x010= 1, wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION
uhub_reattach_p= ort: Port 4 is in Host Mode
uhub_read_port_status: port 4, wPortStatus= =3D0x0103, wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION
usb_bus= _port_set_device: bus 0xffff000089394000 devices[7] =3D 0xffffa00018909000<= br>ugen1.7: <USB Adapter USB Device> at usbus1
ukbd1 on uhub1
u= kbd1: <USB Adapter USB Device, class 0/0, rev 1.10/0.01, addr 7> on u= sbus1
kbd2 at ukbd1
uhub_read_port_status: port 5, wPortStatus=3D0x01= 03, wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION
usb_bus_powerd= : bus=3D0xffff000089394000
uhub_explore: udev=3D0xffffa00001124000 addr= =3D1
uhub_reset_tt_callback: TT buffer reset
uhub_read_port_status: p= ort 1, wPortStatus=3D0x0503, wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COM= PLETION
uhub_reset_tt_callback: TT buffer reset
uhub_explore: udev=3D= 0xffffa000012ed000 addr=3D2
uhub_reset_tt_callback: TT buffer reset
u= hub_read_port_status: port 1, wPortStatus=3D0x0503, wPortChange=3D0x0000, e= rr=3DUSB_ERR_NORMAL_COMPLETION
uhub_read_port_status: port 2, wPortStatu= s=3D0x0103, wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION
uhub_r= ead_port_status: port 3, wPortStatus=3D0x0303, wPortChange=3D0x0000, err=3D= USB_ERR_NORMAL_COMPLETION
uhub_read_port_status: port 4, wPortStatus=3D0= x0103, wPortChange=3D0x0000, err=3DUSB_ERR_NORMAL_COMPLETION
uhub_read_p= ort_status: port 5, wPortStatus=3D0x0103, wPortChange=3D0x0000, err=3DUSB_E= RR_NORMAL_COMPLETION

root@generic:~ # usbconfig
ugen1.1: <DWCOTG OTG Root HUB> at usbus1, cfg=3D0 md=3DHOST s= pd=3DHIGH (480Mbps) pwr=3DSAVE (0mA)
ugen1.2: <vendor 0x0424 product = 0x9514> at usbus1, cfg=3D0 md=3DHOST spd=3DHIGH (480Mbps) pwr=3DSAVE (2m= A)
ugen1.3: <vendor 0x0424 product 0xec00> at usbus1, cfg=3D0 md= =3DHOST spd=3DHIGH (480Mbps) pwr=3DON (2mA)
ugen1.4: <EPSON EPSON UB-= U03II> at usbus1, cfg=3D0 md=3DHOST spd=3DFULL (12Mbps) pwr=3DON (10mA)<= br>ugen1.5: <Prolific Technology Inc. USB-Serial Controller> at usbus= 1, cfg=3D0 md=3DHOST spd=3DFULL (12Mbps) pwr=3DON (100mA)
ugen1.6: <A= 4Tech USB Keyboard> at usbus1, cfg=3D0 md=3DHOST spd=3DLOW (1.5Mbps) pwr= =3DON (100mA)
ugen1.7: <USB Adapter USB Device> at usbus1, cfg=3D0= md=3DHOST spd=3DFULL (12Mbps) pwr=3DON (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 th= en from each port works as expected. Doing "usbconfig reset" work= s normally as performed. Lastly, this also works with my RPi 4B.
=
Any comments or suggestions as I am not a seasoned kernel co= der :-)

Thanks,
Archimede= s


=C2=A0



=C2=A0 =C2=A0 =C2=A0 =C2=A0


--0000000000001f309d05de585405--