From nobody Sat May 07 14:35:57 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 6C2A61ADACC1 for ; Sat, 7 May 2022 14:36:15 +0000 (UTC) (envelope-from archimedes.gaviola@gmail.com) Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) (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 4KwVNt2sxmz3jnl for ; Sat, 7 May 2022 14:36:14 +0000 (UTC) (envelope-from archimedes.gaviola@gmail.com) Received: by mail-qt1-x82f.google.com with SMTP id fu47so8024171qtb.5 for ; Sat, 07 May 2022 07:36:14 -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=AUGbbFgRSqiEnY4jHKGFgPL4ic9OFFtlusyPyS3sJ/0=; b=qe0XRRNDOIZukMSZOQeg3FzMap1m5lfF2UrDspoSNrTnlrq4h2D5qoIJOqa4uNQIbV oMcp2tCYlBLb0v0RhIVxeUPMFsU0ADRHXB61uO16S96xzQQCQKenhTjxGNHUzcMHUBl9 i7sVALSPNVa3W8zhgvR1vIya7G4d+tOCgviGt2lu3L6ILpE8OHptElyvZHobwT4Ef7OJ /ajvfTfAP+72CNjlGw6DVjvWbwuSpdXym+waZD4IqqLBH1kH1/lUp4A/go/8ZHWp4dCk KFenFaw0MoS91HIaJBA/2YkH2Vhq++vXmgiRszZaDXAouyK4dDQLVXBkbTMlEDapgma9 W4kQ== 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=AUGbbFgRSqiEnY4jHKGFgPL4ic9OFFtlusyPyS3sJ/0=; b=TZ9XJ8sLJxuy4y44F5zdVYFW+RkQm1sJAqo8dPdsEnvEAgp/1jsT45ct34We+yd4jO DDxlRgEs4K/9WxPbE4oX/17OkyLJriWdIEHWe/wgbB7Piz9qI/Q5jbg6rxd8jBDnc9ro lrGO6b11b7qaz1HDAMrPxli0HSyKgkIOUy/Z52nSeZ3bsDAUij/W9pzItyYHswyFT24M quMF3PInC0XcLfpL/Q31bq6ar4kz6t7kIE3tqY7aWx1EtpFBEW7A81haJozSH1R2JFGa JROy4yxJ12maU72aKhicDowRYL5SL+sdNgtne22aso5Yjzl8fJSed4T48uumYPuHywcc mxUA== X-Gm-Message-State: AOAM533rgS66QURpxWrH7MTBNsHbJj+h5i9cgj7eJD8dz5gO/2X39Guq rM6iNEG/GmRi6MltDo4rv24Z20TJXWtfjwaYi1UITEFf+vI= X-Google-Smtp-Source: ABdhPJy0w1ysq5sShCHKceqaU/a8HnihS1MSJBsp3eHDY9nWLpRR5hmNoVpc0oV4+b6SYttA2Y/TuJ3YgUDmgxKDxoI= X-Received: by 2002:ac8:7d8e:0:b0:2f1:e909:7a1 with SMTP id c14-20020ac87d8e000000b002f1e90907a1mr7719558qtd.385.1651934168336; Sat, 07 May 2022 07:36:08 -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> <8542947f-a62d-08c8-bb0e-ba3b6b973fec@selasky.org> In-Reply-To: From: Archimedes Gaviola Date: Sat, 7 May 2022 22:35:57 +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="0000000000004bcccc05de6ce597" X-Rspamd-Queue-Id: 4KwVNt2sxmz3jnl X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20210112 header.b=qe0XRRND; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of archimedesgaviola@gmail.com designates 2607:f8b0:4864:20::82f as permitted sender) smtp.mailfrom=archimedesgaviola@gmail.com X-Spamd-Result: default: False [-4.00 / 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(-1.00)[-0.999]; 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::82f:from]; MLMMJ_DEST(0.00)[freebsd-arm]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-ThisMailContainsUnwantedMimeParts: N --0000000000004bcccc05de6ce597 Content-Type: text/plain; charset="UTF-8" On Sat, May 7, 2022 at 8:46 PM Archimedes Gaviola < archimedes.gaviola@gmail.com> wrote: > > > On Sat, May 7, 2022 at 5:20 PM Hans Petter Selasky > wrote: > >> On 5/6/22 16:03, Archimedes Gaviola wrote: >> > 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; >> >> You need a sleep here, to wait for power to come back on. >> >> > + >> > + /* 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; >> > + } >> > } >> > >> >> Can you upload the patch to https://reviews.freebsd.org and add >> "hselasky" as reviewer? >> > > Thank you Hans for the feedback! Just created an account and once approved > and activated then I'll upload it. Meanwhile, for the sleep you've > mentioned what particular function should be used? I tried these two, > sleep(3) and usleep(3) but seems to encounter errors during compilation. > Hi Hans, Submitted, please see https://reviews.freebsd.org/D35146. Thanks, Archimedes --0000000000004bcccc05de6ce597 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Sat, May 7, 2022 at 8:46 PM Archim= edes Gaviola <archimedes= .gaviola@gmail.com> wrote:


On Sat, May 7, 2022= at 5:20 PM Hans Petter Selasky <hps@selasky.org> wrote:
On 5/6/22 16:03, Archimedes Gaviola wrote:
> On Tue, Apr 12, 2022 at 5:16 PM Archimedes Gaviola <
> arch= imedes.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= 9;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 eac= h ports' power
>>>> shut-off during the situation but it was able to recover b= ack. I
>>> initiated
>>>> the command 'usbconfig reset' and each port glorio= usly came back alive
>>> one
>>>> by one and loaded my USB keyboard and Prolific uplcom(4) d= rivers into
>>>> functional and operational states. My measuring device is = showing the
>>> same
>>>> amount of current 460mA while the voltage stayed at 5.05 f= rom 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 dif= ference I
>>>> observed is when the voltage dropped below 5, the system w= ill not give a
>>>> chance to make the ports come back alive as a sort of prot= ection
>>> mechanism.
>>>> 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 recommendation on a self-powered US= B 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 t= he
> 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 conditi= on.
> 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=C2=A0 =C2=A0 =C2=A0 2022-05-03 07:2= 9: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 =C2=A0 udev, NULL, portno, UHF_C_PORT_OVER_CURR= ENT);
>=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 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/* 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 =C2=A0DPRINTF("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 =C2=A0err =3D usbd_req_set_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=A0udev, 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 =C2=A0if (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=A0retval =3D err;

You need a sleep here, to wait for power to come back on.

> +
> +=C2=A0 =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 =C2=A0err =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 =C2=A0if (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=A0retval =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=A0if (sc->sc_st.port_change &
> UPS_C_OVERCURRENT_INDICATOR) {
> +=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=A0DPRINTF("Overcurrent conditi= on 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 =C2=A0err =3D usbd_req_clear_port_featu= re(
> +=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=A0udev, 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 =C2=A0if (err !=3D USB_ERR_NORMAL_COMPL= ETION)
> +=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 =C2=A0retva= 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 =C2=A0}
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
>

Can you upload the patch to
https://reviews.freebsd.org and add
"hselasky" as reviewer?

Thank you Hans for the feedback! Just created an acc= ount and once approved and activated then I'll upload it. Meanwhile, fo= r the sleep you've mentioned what particular function should be used? I= tried these two, sleep(3) and usleep(3) but seems to encounter errors duri= ng compilation.

Hi Hans,

Submitted, please see https:= //reviews.freebsd.org/D35146.

Thanks,
Archimedes
--0000000000004bcccc05de6ce597--