Re: [edk2-devel] [PATCH] MdeModulePkg/Xhci: Skip another size round up for TRB address translation

2024-03-10 Thread Wu, Hao A
No additional comment from my side.

Best Regards,
Hao Wu

> -Original Message-
> From: Dat Mach 
> Sent: Saturday, March 9, 2024 7:33 AM
> To: gaoliming ; devel@edk2.groups.io
> Cc: Cheng, Gao ; Wu, Hao A ;
> Ni, Ray 
> Subject: RE: [PATCH] MdeModulePkg/Xhci: Skip another size round up for TRB
> address translation
> 
> Hi Gao and Hao,
> 
> Could you please take a look at my patch and see if anything I might have
> missed?
> 
> Thanks,
> Dat
> 
> -Original Message-
> From: gaoliming 
> Sent: Monday, March 4, 2024 4:34 PM
> To: Dat Mach ; devel@edk2.groups.io
> Cc: gao.ch...@intel.com; hao.a...@intel.com; ray...@intel.com
> Subject: 回复: [PATCH] MdeModulePkg/Xhci: Skip another size round up for
> TRB address translation
> 
> External email: Use caution opening links or attachments
> 
> 
> This change looks good. Reviewed-by: Liming Gao
> 
> 
> Cheng and Hao:
>   Have you any comments for this patch?
> 
> Thanks
> Liming
> > -邮件原件-
> > 发件人: Dat Mach 
> > 发送时间: 2024年2月26日 10:00
> > 收件人: devel@edk2.groups.io
> > 抄送: gao.ch...@intel.com; hao.a...@intel.com; ray...@intel.com;
> > gaolim...@byosoft.com.cn; Dat Mach 
> > 主题: [PATCH] MdeModulePkg/Xhci: Skip another size round up for TRB
> > address translation
> >
> > REF:https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2F
> >
> bugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D4560=05%7C02%7Cd
> mach
> > %40nvidia.com%7C135326cf31634dbe703e08dc3cac0417%7C43083d1572
> 7340c1b7d
> >
> b39efd9ccc17a%7C0%7C0%7C638451956723393894%7CUnknown%7CTWFp
> bGZsb3d8eyJ
> >
> WIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%
> 7C0%7C
> > %7C%7C=JlpbOr0QHodUF7QDJZl5gY88maLemat4ktudCyDShMQ%3D
> =0
> >
> > Commit f36e1ec1f0a5fd3be84913e09181d7813444b620 had fixed the
> > DXE_ASSERT caused by the TRB size round up from 16 to 64 for most
> > cases.
> >
> > However, there is a remaining case that the TRB size is also rounded
> > up during setting TR dequeue pointer that would trigger DXE_ASSERT.
> >
> > This patch sets the alignment flag to FALSE in XhcSetTrDequeuePointer
> > to fix this issue as well.
> >
> > Signed-off-by: Dat Mach 
> > ---
> >  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 2 +-
> > MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c | 2 +-
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> > b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> > index 05528a478b..5d735008ba 100644
> > --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> > @@ -3539,7 +3539,7 @@ XhcSetTrDequeuePointer (
> >// Send stop endpoint command to transit Endpoint from running to
> > stop state
> >//
> >ZeroMem (, sizeof (CmdSetTRDeq));
> > -  PhyAddr  = UsbHcGetPciAddrForHostAddr (Xhc->MemPool,
> > Urb->Ring->RingEnqueue, sizeof (CMD_SET_TR_DEQ_POINTER), TRUE);
> > +  PhyAddr  = UsbHcGetPciAddrForHostAddr
> > (Xhc->MemPool, Urb->Ring->RingEnqueue, sizeof
> > (CMD_SET_TR_DEQ_POINTER), FALSE);
> >CmdSetTRDeq.PtrLo= XHC_LOW_32BIT (PhyAddr) |
> > Urb->Ring->RingPCS;
> >CmdSetTRDeq.PtrHi= XHC_HIGH_32BIT (PhyAddr);
> >CmdSetTRDeq.CycleBit = 1;
> > diff --git a/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c
> > b/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c
> > index 53272f62dd..c956e45907 100644
> > --- a/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c
> > +++ b/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c
> > @@ -2526,7 +2526,7 @@ XhcPeiSetTrDequeuePointer (
> >// Send stop endpoint command to transit Endpoint from running to
> > stop state
> >//
> >ZeroMem (, sizeof (CmdSetTRDeq));
> > -  PhyAddr  = UsbHcGetPciAddrForHostAddr (Xhc->MemPool,
> > Urb->Ring->RingEnqueue, sizeof (CMD_SET_TR_DEQ_POINTER), TRUE);
> > +  PhyAddr  = UsbHcGetPciAddrForHostAddr
> > (Xhc->MemPool, Urb->Ring->RingEnqueue, sizeof
> > (CMD_SET_TR_DEQ_POINTER), FALSE);
> >CmdSetTRDeq.PtrLo= XHC_LOW_32BIT (PhyAddr) |
> > Urb->Ring->RingPCS;
> >CmdSetTRDeq.PtrHi= XHC_HIGH_32BIT (PhyAddr);
> >CmdSetTRDeq.CycleBit = 1;
> > --
> > 2.44.0.rc2
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#116574): https://edk2.groups.io/g/devel/message/116574
Mute This Topic: https://groups.io/mt/104821290/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Non-zero start/stop values in XhcGetElapsedTicks

2023-10-31 Thread Wu, Hao A
Acked-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Henz,
> Patrick
> Sent: Wednesday, November 1, 2023 12:51 AM
> To: devel@edk2.groups.io
> Cc: Wu, Hao A ; Ni, Ray ; Henz,
> Patrick 
> Subject: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Non-zero start/stop
> values in XhcGetElapsedTicks
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4578
> 
> The implementation of XhcGetElapsedTicks did not account for
> non-zero start and stop values for the performance counter
> timer, potentially resulting in an incorrect elapsed tick
> count getting returned to the caller. Account for non-zero
> start and stop values when calculating the elapsed tick
> count.
> 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Signed-off-by: Patrick Henz 
> Reviewed-by:
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> index 7a2e32a9dd..6cb97b7452 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> @@ -2389,7 +2389,7 @@ XhcGetElapsedTicks (
>  // Counter counts upwards, check for an overflow condition
> 
>  //
> 
>  if (*PreviousTick > CurrentTick) {
> 
> -  Delta = (mPerformanceCounterEndValue - *PreviousTick) + CurrentTick;
> 
> +  Delta = (CurrentTick - mPerformanceCounterStartValue) +
> (mPerformanceCounterEndValue - *PreviousTick);
> 
>  } else {
> 
>Delta = CurrentTick - *PreviousTick;
> 
>  }
> 
> @@ -2398,7 +2398,7 @@ XhcGetElapsedTicks (
>  // Counter counts downwards, check for an underflow condition
> 
>  //
> 
>  if (*PreviousTick < CurrentTick) {
> 
> -  Delta = (mPerformanceCounterStartValue - CurrentTick) + *PreviousTick;
> 
> +  Delta = (mPerformanceCounterStartValue - CurrentTick) + (*PreviousTick
> - mPerformanceCounterEndValue);
> 
>  } else {
> 
>Delta = *PreviousTick - CurrentTick;
> 
>  }
> 
> --
> 2.34.1
> 
> 
> 
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> View/Reply Online (#110434):
> https://edk2.groups.io/g/devel/message/110434
> Mute This Topic: https://groups.io/mt/102301510/1768737
> Group Owner: devel+ow...@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub [hao.a...@intel.com]
> -=-=-=-=-=-=
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110463): https://edk2.groups.io/g/devel/message/110463
Mute This Topic: https://groups.io/mt/102301510/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts

2023-10-30 Thread Wu, Hao A
(Add MdePkg maintainers for their feedbacks)

Sorry that I do not have strong opinion on this one.

Some of my thoughts are:
* If you find the to-be-added APIs can be used in serveral places to reduce
  repetative codes, then it will be worthwhile to add new library APIs.

* TimerLib has many instance implementations, my take is that many post-mem
  instances use library level global variable to store information like timer
  frequency to avoid calculating it every time.
  For pre-mem instances, such caching is not feasible. I think it will be the
  API consumer's responsibility to limit the usage of these APIs for performance
  consideration.

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Henz,
> Patrick
> Sent: Tuesday, October 31, 2023 4:36 AM
> To: Wu, Hao A ; devel@edk2.groups.io; Michael Brown
> 
> Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance
> Timer for XHCI Timeouts
> 
> My changes have been in for a little over a month now, I've been looking into
> updating the TimerLib API but I'm questioning if it still makes sense to go 
> down
> that path.  The functions I had implemented, XhcGetElapsedTicks () and
> XhcConvertTimeToTicks (), now rely heavily on the use of global variables for
> caching return values from GetPerformanceCounterProperties. As-is these
> functions won't work for all instances of TimerLib, specifically if the 
> instance is
> used before memory (RAM) is available. I could implement the functions as
> they originally were, but I wouldn't be able to replace the Xhc functions
> without adding additional parameters to said TimerLib functions (e.g. adding
> Frequency, StartValue, StopValue to ConvertTimeToTicks), which feels clunky
> to me. Would a new library make sense here? Something that sits between
> the driver and the TimerLib library? Or do we just leave things as they
> currently are?
> 
> Thanks,
> Patrick Henz
> 
> -Original Message-
> From: Wu, Hao A 
> Sent: Thursday, August 10, 2023 8:43 PM
> To: Henz, Patrick ; devel@edk2.groups.io; Michael
> Brown 
> Subject: RE: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance
> Timer for XHCI Timeouts
> 
> My personal preference is to do this as two steps.
> Address the issue in XhciDxe first. Then add new TimerLib API to replace all
> driver/library internal implementations.
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: Henz, Patrick 
> > Sent: Friday, August 11, 2023 6:45 AM
> > To: devel@edk2.groups.io; Wu, Hao A ; Michael
> > Brown 
> > Subject: RE: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use
> > Performance Timer for XHCI Timeouts
> >
> > I can certainly make that change.
> >
> > For what it's worth I have been working on adding the new function,
> > GetElapsedTicks, to the various implementations of TimerLib. I've
> > finished up testing, I would just need to clean up the commits for a
> > patch. Should I move forward with that, or would we rather I just add
> > XhcGetElapsedTime to XhciDxe for the time being?
> >
> > Thanks,
> > Patrick Henz
> >
> > -Original Message-
> > From: devel@edk2.groups.io  On Behalf Of Wu,
> Hao
> > A
> > Sent: Sunday, July 30, 2023 9:57 PM
> > To: devel@edk2.groups.io; Henz, Patrick ;
> > Michael Brown 
> > Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use
> > Performance Timer for XHCI Timeouts
> >
> > For the 2 occurrences of in XhcWaitOpRegBit & XhcExecTransfer:
> >   TimeoutTime = XHC_MICROSECOND_TO_NANOSECOND (Timeout *
> > XHC_1_MILLISECOND); How about changing them to:
> >   TimeoutTime = XHC_MICROSECOND_TO_NANOSECOND ((UINT64)
> Timeout
> > * XHC_1_MILLISECOND); to address possible overflow during "Timeout *
> > XHC_1_MILLISECOND"?
> >
> > For extending XhcGetElapsedTime as a TimerLib API, I am fine to put it
> > in XhciDxe at this moment.
> > If package maintainers suggest to make it as a public library API, my
> > take is that this should be done in a separate commit.
> >
> > Best Regards,
> > Hao Wu
> >
> > > -Original Message-
> > > From: devel@edk2.groups.io  On Behalf Of Henz,
> > > Patrick
> > > Sent: Thursday, July 6, 2023 4:16 AM
> > > To: devel@edk2.groups.io
> > > Cc: Henz, Patrick 
> > > Subject: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance
> > > Timer for XHCI Timeouts
> > >
> > > REF:INVALID URI REMOVED
> > > bu
> > > g.cgi?id=2948__;!!NpxR!kyFQM5IkKYAG9CRBO4xphwBnzi_jhb2oU-
> > NKbMjOV-lctg5
> > > 

Re: [edk2-devel] [Patch 1/1] Maintainers.txt: Update based on active community members

2023-10-30 Thread Wu, Hao A
For changes to item "Hao A Wu  [hwu25]":
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: Kinney, Michael D 
> Sent: Sunday, October 29, 2023 3:24 AM
> To: devel@edk2.groups.io
> Cc: Andrew Fish ; Leif Lindholm
> ; Warkentin, Andrei
> ; West, Catharine
> ; Bi, Dandan ; Daniel
> Schaefer ; David Woodhouse
> ; De, Debkumar ; Dong,
> Eric ; Jiang, Guomin ; Wu,
> Hao A ; James Bottomley ;
> Wang, Jian J ; Justen, Jordan L
> ; Julien Grall ; Peter Grehan
> ; Zhang, Qi1 ; Ng, Ray Han Lim
> ; Stefan Berger ; Hou,
> Wenxing ; Lu, Xiaoyu1 
> Subject: [Patch 1/1] Maintainers.txt: Update based on active community
> members
> 
> Over the past few months, all the of the Maintainers and Reviewers listed in
> Maintainers.txt have been contacted to make sure Maintainers.txt accurately
> represents the TianoCore community members that are actively participating
> in their roles.  Based on specific feedback, bounced emails, and no responses,
> updates have been made.
> 
> * RISCV64: Daniel Schaefer replaced with Andrei Warkentin
> * ArmVirtPkg Xen has no remaining reviewers and review
>   responsibility defaults to ArmVirtPkg Maintainers/Reviewers.
> * ACPI modules related to S3 has no remaining reviewers and
>   review responsibility defaults to MdeModulePkg Maintainers/
>   Reviewers.
> * OVMF CSM modules has no remaining reviewers and review
>   responsibility defaults to OvmfPkg Maintainers/Reviewers.
> * Bounce: Chan Laura 
> * Many smaller updates removing individuals that are no
>   longer involved or have replacement coverage.
> 
> Cc: Andrew Fish 
> Cc: Leif Lindholm 
> Cc: Andrei Warkentin 
> Cc: Catharine West 
> Cc: Dandan Bi 
> Cc: Daniel Schaefer 
> Cc: David Woodhouse 
> Cc: Debkumar De 
> Cc: Eric Dong 
> Cc: Guomin Jiang 
> Cc: Hao A Wu 
> Cc: James Bottomley 
> Cc: Jian J Wang 
> Cc: Jordan Justen 
> Cc: Julien Grall 
> Cc: Peter Grehan 
> Cc: Qi Zhang 
> Cc: Ray Han Lim Ng 
> Cc: Stefan Berger 
> Cc: Wenxing Hou 
> Cc: Xiaoyu Lu 
> Signed-off-by: Michael D Kinney 
> ---
>  Maintainers.txt | 53 ++---
>  1 file changed, 2 insertions(+), 51 deletions(-)
> 
> diff --git a/Maintainers.txt b/Maintainers.txt index
> 3f40cdeb5554..2b03ccbe54aa 100644
> --- a/Maintainers.txt
> +++ b/Maintainers.txt
> @@ -93,7 +93,7 @@ M: Sami Mujawar 
> [samimujawar]
>  RISCV64
>  F: */RiscV64/
>  M: Sunil V L  [vlsunil]
> -R: Daniel Schaefer  [JohnAZoidberg]
> +R: Andrei Warkentin  [andreiw]
> 
>  LOONGARCH64
>  F: */LoongArch64/
> @@ -157,16 +157,6 @@ R: Leif Lindholm 
> [leiflindholm]
>  R: Sami Mujawar  [samimujawar]
>  R: Gerd Hoffmann  [kraxel]
> 
> -ArmVirtPkg: modules used on Xen
> -F: ArmVirtPkg/ArmVirtXen.*
> -F: ArmVirtPkg/Library/XenArmGenericTimerVirtCounterLib/
> -F: ArmVirtPkg/Library/XenVirtMemInfoLib/
> -F: ArmVirtPkg/PrePi/
> -F: ArmVirtPkg/XenAcpiPlatformDxe/
> -F: ArmVirtPkg/XenPlatformHasAcpiDtDxe/
> -F: ArmVirtPkg/XenioFdtDxe/
> -R: Julien Grall  [jgrall]
> -
>  BaseTools
>  F: BaseTools/
>  W: https://github.com/tianocore/tianocore.github.io/wiki/BaseTools
> @@ -187,8 +177,7 @@ F: CryptoPkg/
>  W: https://github.com/tianocore/tianocore.github.io/wiki/CryptoPkg
>  M: Jiewen Yao  [jyao1]
>  M: Yi Li  [liyi77]
> -R: Xiaoyu Lu  [xiaoyuxlu]
> -R: Guomin Jiang  [guominjia]
> +R: Wenxing Hou  [Wenxing-hou]
> 
>  DynamicTablesPkg
>  F: DynamicTablesPkg/
> @@ -202,7 +191,6 @@ W:
> https://github.com/tianocore/tianocore.github.io/wiki/EmbeddedPkg
>  M: Leif Lindholm  [leiflindholm]
>  M: Ard Biesheuvel  [ardbiesheuvel]
>  M: Abner Chang  [changab]
> -R: Daniel Schaefer  [JohnAZoidberg]
> 
>  EmulatorPkg
>  F: EmulatorPkg/
> @@ -228,7 +216,6 @@ F: FmpDevicePkg/
>  W: https://github.com/tianocore/tianocore.github.io/wiki/FmpDevicePkg
>  M: Liming Gao  [lgao4]
>  M: Michael D Kinney  [mdkinney]
> -R: Guomin Jiang  [guominjia]
>  R: Wei6 Xu  [xuweiintel]
> 
>  IntelFsp2Pkg
> @@ -237,7 +224,6 @@ W:
> https://github.com/tianocore/tianocore.github.io/wiki/IntelFsp2Pkg
>  M: Chasel Chiu  [ChaselChiu]
>  M: Nate DeSimone  [nate-desimone]
>  M: Duggapu Chinni B  [cbduggap]
> -M: Ray Han Lim Ng  [rayhanlimng]
>  R: Star Zeng  [lzeng14]
>  R: Ted Kuo  [tedkuo1]
>  R: Ashraf Ali S  [AshrafAliS] @@ -258,7 +244,6 @@
> R: Susovan Mohapatra  [susovanmohapatra]
> MdeModulePkg
>  F: MdeModulePkg/
>  W: https://github.com/tianocore/tianocore.github.io/wiki/MdeModulePkg
> -M: Jian J Wang  [jwang36]
>  M: Liming Gao  [lgao4]
> 
>  MdeModulePkg: ACPI modules
> @@ -268,15 +253,6 @@ R: Zhiguang Liu 
> [LiuZhiguang001]
>  R: Dandan 

Re: [edk2-devel] [PATCH] MdeModulePkg/UsbBus: Get device/config descriptor after port reset

2023-10-15 Thread Wu, Hao A
Please grant me some time to review this patch.
Really sorry that I am not able to provide an estimated time for the review.

Best Regards,
Hao Wu

From: Ashish Singhal 
Sent: Friday, October 13, 2023 10:13 AM
To: Rick Tseng ; devel@edk2.groups.io; Wu, Hao A 
; Ni, Ray ; Wang, Jian J 
; Gao, Liming 
Cc: Jeff Brasen 
Subject: Re: [PATCH] MdeModulePkg/UsbBus: Get device/config descriptor after 
port reset

Hello Hao/Ray/Jian/Gao,

Any feedback on this patch?

Thanks
Ashish

From: Rick Tseng mailto:rts...@nvidia.com>>
Sent: Sunday, September 24, 2023 7:54 PM
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
mailto:devel@edk2.groups.io>>
Cc: hao.a...@intel.com<mailto:hao.a...@intel.com> 
mailto:hao.a...@intel.com>>; 
ray...@intel.com<mailto:ray...@intel.com> 
mailto:ray...@intel.com>>; 
jian.j.w...@intel.com<mailto:jian.j.w...@intel.com> 
mailto:jian.j.w...@intel.com>>; 
gaolim...@byosoft.com.cn<mailto:gaolim...@byosoft.com.cn> 
mailto:gaolim...@byosoft.com.cn>>; Ashish Singhal 
mailto:ashishsin...@nvidia.com>>; Jeff Brasen 
mailto:jbra...@nvidia.com>>; Rick Tseng 
mailto:rts...@nvidia.com>>
Subject: [PATCH] MdeModulePkg/UsbBus: Get device/config descriptor after port 
reset

To fix the assert due to ASSERT(TrsRing !=NULL) in XhcSyncTrsRing.

There is a recovery in usb mass stroage driver to do port reset after
fail in transfer. And port reset operation makes that all memory
resources(descriptors, endpoint memory) belonging to this device are
reclaimed in underlying Xhci driver.

Because USB descriptors are reclaimed in underlying Xhci driver, the
next "set config" would not trigger the "Configuration Endpoint"
command in Xhci driver as there is no existing configuation
descriptor. It would prevent from allocating memory from xhci for
endpoints.

Thus there is no memmory allocated for transfering on non-default
endpoint, it makes the assert happens when usb mass stroage tries
to transfer after reset.

This change is to refetch the device and config descriptor after
port reset, it would rebuild device and configuration descriptor in
Xhci driver. So the "set config" command would trigger the
"Configuration Endpoint" in xhci and allocate memory for endpoints.

Signed-off-by: Rick Tseng mailto:rts...@nvidia.com>>
---
 MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c  | 77 ++--
 MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h | 25 
 2 files changed, 96 insertions(+), 6 deletions(-)

diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c 
b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
index c25f3cc2f2..f6e1f88b3d 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
@@ -815,12 +815,16 @@ UsbIoPortReset (
   IN EFI_USB_IO_PROTOCOL  *This
   )
 {
-  USB_INTERFACE  *UsbIf;
-  USB_INTERFACE  *HubIf;
-  USB_DEVICE *Dev;
-  EFI_TPLOldTpl;
-  EFI_STATUS Status;
-  UINT8  DevAddress;
+  USB_INTERFACE*UsbIf;
+  USB_INTERFACE*HubIf;
+  USB_DEVICE   *Dev;
+  EFI_TPL  OldTpl;
+  EFI_STATUS   Status;
+  UINT8DevAddress;
+  USB_DEVICE_DESC  DevDesc;
+  UINT8NumConfig;
+  VOID *Buf;
+  UINT8Index;

   OldTpl = gBS->RaiseTPL (USB_BUS_TPL);

@@ -882,6 +886,67 @@ UsbIoPortReset (
   // is in CONFIGURED state.
   //
   if (Dev->ActiveConfig != NULL) {
+//
+// We just do a port reset, so we need to do as a new device enumeration.
+// Need to get the device descriptor, configuration descriptor before set 
config
+//
+Status = UsbCtrlGetDesc (Dev, USB_DESC_TYPE_DEVICE, 0, 0, , sizeof 
(DevDesc));
+if (EFI_ERROR (Status)) {
+  DEBUG ((
+DEBUG_ERROR,
+"UsbIoPortReset: failed to get device desc for device %d - %r\n",
+Dev->Address,
+Status
+));
+  goto ON_EXIT;
+}
+
+NumConfig = Dev->DevDesc->Desc.NumConfigurations;
+if (NumConfig == 0) {
+  DEBUG ((
+DEBUG_ERROR,
+"UsbIoPortReset: no configuration descriptor for device %d - %r\n",
+Dev->Address,
+Status
+));
+  goto ON_EXIT;
+}
+
+for (Index = 0; Index < NumConfig; Index++) {
+  if (Dev->DevDesc->Configs[Index] == NULL) {
+DEBUG ((
+  DEBUG_ERROR,
+  "UsbIoPortReset: no configuration descriptor for index %d - %r\n",
+  Index,
+  Status
+  ));
+goto ON_EXIT;
+  }
+
+  Buf = AllocateZeroPool (Dev->DevDesc->Configs[Index]->Desc.TotalLength);
+  if (Buf == NULL) {
+DEBUG ((
+  DEBUG_ERROR,
+  "UsbIoPortReset: allocation memory fail for configuration desc - 
%r\n",
+  Status
+  ));
+goto ON_EXIT;
+  }
+
+  Status = UsbCtrlGetDesc (Dev, USB_DES

Re: [edk2-devel] [PATCH v2] MdeModulePkg/Xhci: Skip size round up for TRB during address translation

2023-09-27 Thread Wu, Hao A
Patch merged via:
PR - https://github.com/tianocore/edk2/pull/4875
Commit - 
https://github.com/tianocore/edk2/commit/f36e1ec1f0a5fd3be84913e09181d7813444b620

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Wu, Hao
> A
> Sent: Wednesday, September 27, 2023 9:05 AM
> To: Cheng, Gao ; devel@edk2.groups.io
> Cc: Ni, Ray ; Wang, Jian J ; Gao,
> Liming 
> Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg/Xhci: Skip size round up
> for TRB during address translation
> 
> Reviewed-by: Hao A Wu 
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: Cheng, Gao 
> > Sent: Tuesday, September 26, 2023 4:25 PM
> > To: devel@edk2.groups.io
> > Cc: Cheng, Gao ; Wu, Hao A
> ;
> > Ni, Ray ; Wang, Jian J ; Gao,
> > Liming 
> > Subject: [PATCH v2] MdeModulePkg/Xhci: Skip size round up for TRB during
> > address translation
> >
> > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4560
> >
> >
> >
> > TRB Template is 16 bytes. When boundary checking is 64 bytes for xHCI
> >
> > device/host memory address, it may exceed xHCI host memory pool and
> >
> > cause unwanted DXE_ASSERT. Introduce a new input parameter to indicate
> >
> > whether to enforce 64byte size alignment and round up. For TRB case,
> >
> > should set it to FALSE to skip the size round up.
> >
> >
> >
> > Signed-off-by: Gao Cheng 
> >
> > Cc: Hao A Wu 
> >
> > Cc: Ray Ni 
> >
> > Cc: Jian J Wang 
> >
> > Cc: Liming Gao 
> >
> > ---
> >
> >  MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c  | 24 ---
> >
> >  MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.h  |  8 +++-
> >
> >  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 54 +---
> >
> >  MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c  | 24 ---
> >
> >  MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.h  |  8 +++-
> >
> >  MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c | 48 +++--
> >
> >  6 files changed, 103 insertions(+), 63 deletions(-)
> >
> >
> >
> > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c
> > b/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c
> >
> > index d0ad1582e4..b54187ec22 100644
> >
> > --- a/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c
> >
> > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c
> >
> > @@ -226,6 +226,7 @@ UsbHcAllocMemFromBlock (
> >
> >@param  Pool   The memory pool of the host controller.
> >
> >@param  MemThe pointer to host memory.
> >
> >@param  Size   The size of the memory region.
> >
> > +  @param  Alignment  Alignment the size to USBHC_MEM_UNIT bytes.
> >
> >
> >
> >@returnThe pci memory address
> >
> >
> >
> > @@ -234,7 +235,8 @@ EFI_PHYSICAL_ADDRESS
> >
> >  UsbHcGetPciAddrForHostAddr (
> >
> >IN USBHC_MEM_POOL  *Pool,
> >
> >IN VOID*Mem,
> >
> > -  IN UINTN   Size
> >
> > +  IN UINTN   Size,
> >
> > +  IN BOOLEAN Alignment
> >
> >)
> >
> >  {
> >
> >USBHC_MEM_BLOCK   *Head;
> >
> > @@ -243,8 +245,12 @@ UsbHcGetPciAddrForHostAddr (
> >
> >EFI_PHYSICAL_ADDRESS  PhyAddr;
> >
> >UINTN Offset;
> >
> >
> >
> > -  Head  = Pool->Head;
> >
> > -  AllocSize = USBHC_MEM_ROUND (Size);
> >
> > +  Head = Pool->Head;
> >
> > +  if (Alignment) {
> >
> > +AllocSize = USBHC_MEM_ROUND (Size);
> >
> > +  } else {
> >
> > +AllocSize = Size;
> >
> > +  }
> >
> >
> >
> >if (Mem == NULL) {
> >
> >  return 0;
> >
> > @@ -275,6 +281,7 @@ UsbHcGetPciAddrForHostAddr (
> >
> >@param  Pool   The memory pool of the host controller.
> >
> >@param  MemThe pointer to pci memory.
> >
> >@param  Size   The size of the memory region.
> >
> > +  @param  Alignment  Alignment the size to USBHC_MEM_UNIT bytes.
> >
> >
> >
> >@returnThe host memory address
> >
> >
> >
> > @@ -283,7 +290,8 @@ EFI_PHYSICAL_ADDRESS
> >
> >  UsbHcGetHostAddrForPciAddr (
> >
> >IN USBHC_MEM_POOL  *Pool,
> >
> >IN VOID*Mem,
> >
> > -  IN UINTN   Size

Re: [edk2-devel] [PATCH v2] MdeModulePkg/Xhci: Skip size round up for TRB during address translation

2023-09-26 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: Cheng, Gao 
> Sent: Tuesday, September 26, 2023 4:25 PM
> To: devel@edk2.groups.io
> Cc: Cheng, Gao ; Wu, Hao A ;
> Ni, Ray ; Wang, Jian J ; Gao,
> Liming 
> Subject: [PATCH v2] MdeModulePkg/Xhci: Skip size round up for TRB during
> address translation
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4560
> 
> 
> 
> TRB Template is 16 bytes. When boundary checking is 64 bytes for xHCI
> 
> device/host memory address, it may exceed xHCI host memory pool and
> 
> cause unwanted DXE_ASSERT. Introduce a new input parameter to indicate
> 
> whether to enforce 64byte size alignment and round up. For TRB case,
> 
> should set it to FALSE to skip the size round up.
> 
> 
> 
> Signed-off-by: Gao Cheng 
> 
> Cc: Hao A Wu 
> 
> Cc: Ray Ni 
> 
> Cc: Jian J Wang 
> 
> Cc: Liming Gao 
> 
> ---
> 
>  MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c  | 24 ---
> 
>  MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.h  |  8 +++-
> 
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 54 +---
> 
>  MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c  | 24 ---
> 
>  MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.h  |  8 +++-
> 
>  MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c | 48 +++--
> 
>  6 files changed, 103 insertions(+), 63 deletions(-)
> 
> 
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c
> 
> index d0ad1582e4..b54187ec22 100644
> 
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c
> 
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c
> 
> @@ -226,6 +226,7 @@ UsbHcAllocMemFromBlock (
> 
>@param  Pool   The memory pool of the host controller.
> 
>@param  MemThe pointer to host memory.
> 
>@param  Size   The size of the memory region.
> 
> +  @param  Alignment  Alignment the size to USBHC_MEM_UNIT bytes.
> 
> 
> 
>@returnThe pci memory address
> 
> 
> 
> @@ -234,7 +235,8 @@ EFI_PHYSICAL_ADDRESS
> 
>  UsbHcGetPciAddrForHostAddr (
> 
>IN USBHC_MEM_POOL  *Pool,
> 
>IN VOID*Mem,
> 
> -  IN UINTN   Size
> 
> +  IN UINTN   Size,
> 
> +  IN BOOLEAN Alignment
> 
>)
> 
>  {
> 
>USBHC_MEM_BLOCK   *Head;
> 
> @@ -243,8 +245,12 @@ UsbHcGetPciAddrForHostAddr (
> 
>EFI_PHYSICAL_ADDRESS  PhyAddr;
> 
>UINTN Offset;
> 
> 
> 
> -  Head  = Pool->Head;
> 
> -  AllocSize = USBHC_MEM_ROUND (Size);
> 
> +  Head = Pool->Head;
> 
> +  if (Alignment) {
> 
> +AllocSize = USBHC_MEM_ROUND (Size);
> 
> +  } else {
> 
> +AllocSize = Size;
> 
> +  }
> 
> 
> 
>if (Mem == NULL) {
> 
>  return 0;
> 
> @@ -275,6 +281,7 @@ UsbHcGetPciAddrForHostAddr (
> 
>@param  Pool   The memory pool of the host controller.
> 
>@param  MemThe pointer to pci memory.
> 
>@param  Size   The size of the memory region.
> 
> +  @param  Alignment  Alignment the size to USBHC_MEM_UNIT bytes.
> 
> 
> 
>@returnThe host memory address
> 
> 
> 
> @@ -283,7 +290,8 @@ EFI_PHYSICAL_ADDRESS
> 
>  UsbHcGetHostAddrForPciAddr (
> 
>IN USBHC_MEM_POOL  *Pool,
> 
>IN VOID*Mem,
> 
> -  IN UINTN   Size
> 
> +  IN UINTN   Size,
> 
> +  IN BOOLEAN Alignment
> 
>)
> 
>  {
> 
>USBHC_MEM_BLOCK   *Head;
> 
> @@ -292,8 +300,12 @@ UsbHcGetHostAddrForPciAddr (
> 
>EFI_PHYSICAL_ADDRESS  HostAddr;
> 
>UINTN Offset;
> 
> 
> 
> -  Head  = Pool->Head;
> 
> -  AllocSize = USBHC_MEM_ROUND (Size);
> 
> +  Head = Pool->Head;
> 
> +  if (Alignment) {
> 
> +AllocSize = USBHC_MEM_ROUND (Size);
> 
> +  } else {
> 
> +AllocSize = Size;
> 
> +  }
> 
> 
> 
>if (Mem == NULL) {
> 
>  return 0;
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.h
> b/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.h
> 
> index c85b0b919f..b21bf9da3e 100644
> 
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.h
> 
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.h
> 
> @@ -129,6 +129,7 @@ UsbHcFreeMem (
> 
>@param  Pool   The memory pool of the host controller.
> 
>@param  MemThe pointer to host memory.
> 
>@param  Size   The size of the memory region.
> 
> +  @param  Alignment  Alignment the size to USBHC_ME

Re: [edk2-devel] [PATCH] MdeModulePkg/Xhci: Skip size round up for TRB during address translation

2023-09-25 Thread Wu, Hao A
The proposed patch failed some CI tests.
Details can be referred at: https://github.com/tianocore/edk2/pull/4866. Could 
you help to resolve them?

Please help to follow the step 11 in page: 
https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Development-Process
 and check the CI test results for the upcoming patch?

Best Regards,
Hao Wu

> -Original Message-
> From: Cheng, Gao 
> Sent: Tuesday, September 26, 2023 10:12 AM
> To: devel@edk2.groups.io
> Cc: Cheng, Gao ; Wu, Hao A ;
> Ni, Ray ; Wang, Jian J ; Gao,
> Liming 
> Subject: [PATCH] MdeModulePkg/Xhci: Skip size round up for TRB during
> address translation
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4560
> 
> TRB Template is 16 bytes. When boundary checking is 64 bytes for xHCI
> device/host memory address, it may exceed xHCI host memory pool and
> cause unwanted DXE_ASSERT. Introduce a new input parameter to indicate
> whether to enforce 64byte size alignment and round up. For TRB case,
> should set it to FALSE to skip the size round up.
> 
> Signed-off-by: Gao Cheng 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Cc: Jian J Wang 
> Cc: Liming Gao 
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c  | 20 +++--
>  MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.h  |  8 +++-
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 54 +---
>  MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c  | 20 +++--
>  MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.h  |  8 +++-
>  MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c | 48 +++--
>  6 files changed, 99 insertions(+), 59 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c
> index d0ad1582e4..8fea441fbc 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.c
> @@ -226,6 +226,7 @@ UsbHcAllocMemFromBlock (
>@param  Pool   The memory pool of the host controller.
>@param  MemThe pointer to host memory.
>@param  Size   The size of the memory region.
> +  @param  Alignment  Alignment the size to USBHC_MEM_UNIT bytes.
> 
>@returnThe pci memory address
> 
> @@ -234,7 +235,8 @@ EFI_PHYSICAL_ADDRESS
>  UsbHcGetPciAddrForHostAddr (
>IN USBHC_MEM_POOL  *Pool,
>IN VOID*Mem,
> -  IN UINTN   Size
> +  IN UINTN   Size,
> +  IN BOOLEAN Alignment
>)
>  {
>USBHC_MEM_BLOCK   *Head;
> @@ -244,7 +246,11 @@ UsbHcGetPciAddrForHostAddr (
>UINTN Offset;
> 
>Head  = Pool->Head;
> -  AllocSize = USBHC_MEM_ROUND (Size);
> +  if (Alignment) {
> +AllocSize = USBHC_MEM_ROUND (Size);
> +  } else {
> +AllocSize = Size;
> +  }
> 
>if (Mem == NULL) {
>  return 0;
> @@ -275,6 +281,7 @@ UsbHcGetPciAddrForHostAddr (
>@param  Pool   The memory pool of the host controller.
>@param  MemThe pointer to pci memory.
>@param  Size   The size of the memory region.
> +  @param  Alignment  Alignment the size to USBHC_MEM_UNIT bytes.
> 
>@returnThe host memory address
> 
> @@ -283,7 +290,8 @@ EFI_PHYSICAL_ADDRESS
>  UsbHcGetHostAddrForPciAddr (
>IN USBHC_MEM_POOL  *Pool,
>IN VOID*Mem,
> -  IN UINTN   Size
> +  IN UINTN   Size,
> +  IN BOOLEAN Alignment
>)
>  {
>USBHC_MEM_BLOCK   *Head;
> @@ -293,7 +301,11 @@ UsbHcGetHostAddrForPciAddr (
>UINTN Offset;
> 
>Head  = Pool->Head;
> -  AllocSize = USBHC_MEM_ROUND (Size);
> +  if (Alignment) {
> +AllocSize = USBHC_MEM_ROUND (Size);
> +  } else {
> +AllocSize = Size;
> +  }
> 
>if (Mem == NULL) {
>  return 0;
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.h
> b/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.h
> index c85b0b919f..b21bf9da3e 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.h
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/UsbHcMem.h
> @@ -129,6 +129,7 @@ UsbHcFreeMem (
>@param  Pool   The memory pool of the host controller.
>@param  MemThe pointer to host memory.
>@param  Size   The size of the memory region.
> +  @param  Alignment  Alignment the size to USBHC_MEM_UNIT bytes.
> 
>@returnThe pci memory address
> 
> @@ -137,7 +138,8 @@ EFI_PHYSICAL_ADDRESS
>  UsbHcGetPciAddrForHostAddr (
>IN USBHC_MEM_POOL  *Pool,
>IN VOID*Mem,
> -  IN UINTN   Size
> +  IN UINTN   Size,
> +  IN BOOLEAN Alignment
>);
> 
>  /**
> @@ -146,6 +148,7 @@ UsbHcGetPciAddrForHostAddr (
>@param  Pool   The

Re: [edk2-devel] [PATCH V2 1/1] MdeModulePkg/XhciDxe: Abort the Address Device cmd when time out

2023-09-24 Thread Wu, Hao A
Pushed via:
PR - https://github.com/tianocore/edk2/pull/4863
Commit - 
https://github.com/tianocore/edk2/commit/d11f0ea045f598e08b414eeba4f8a74ac1b4ca0b

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Wu, Hao
> A
> Sent: Thursday, September 21, 2023 2:17 PM
> To: Cai, Xianglei ; devel@edk2.groups.io
> Cc: Ni, Ray ; Wang, Jian J ; Gao,
> Liming ; Shih, More ;
> Huang, Jenny 
> Subject: Re: [edk2-devel] [PATCH V2 1/1] MdeModulePkg/XhciDxe: Abort the
> Address Device cmd when time out
> 
> Reviewed-by: Hao A Wu 
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: Cai, Xianglei 
> > Sent: Thursday, September 21, 2023 11:58 AM
> > To: devel@edk2.groups.io
> > Cc: Cai, Xianglei ; Wu, Hao A
> ;
> > Ni, Ray ; Wang, Jian J ; Gao,
> > Liming ; Shih, More ;
> > Huang, Jenny 
> > Subject: [PATCH V2 1/1] MdeModulePkg/XhciDxe: Abort the Address Device
> > cmd when time out
> >
> > https://bugzilla.tianocore.org/show_bug.cgi?id=4552
> >
> > Following XHCI spec 4.6.1.2, software may abort the
> > execution of Address Device Command when command failed
> > due to timeout.
> >
> > Cc: Hao A Wu 
> > Cc: Ray Ni   
> > Cc: Jian J Wang  
> > Cc: Liming Gao   
> > Cc: More Shih
> > Cc: Jenny Huang  
> > Signed-off-by: Xianglei Cai 
> > ---
> >  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 36
> > 
> >  1 file changed, 36 insertions(+)
> >
> > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> > b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> > index 53421e64a850..f6efcf80f376 100644
> > --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> > @@ -2121,6 +2121,26 @@ RingIntTransferDoorBell (
> >return EFI_SUCCESS;
> >  }
> >
> > +/**
> > +  Set Command abort
> > +
> > +  @param  Xhc   The XHCI Instance.
> > +  @param  SlotIdThe slot id to be disabled.
> > +
> > +**/
> > +VOID
> > +XhcCmdRingCmdAbort (
> > +  IN USB_XHCI_INSTANCE  *Xhc,
> > +  IN UINT8  SlotId
> > +  )
> > +{
> > +  //
> > +  // Set XHC_CRCR_CA bit in XHC_CRCR_OFFSET to abort command.
> > +  //
> > +  DEBUG ((DEBUG_INFO, "Command Ring Control set Command Abort,
> > SlotId: %d\n", SlotId));
> > +  XhcSetOpRegBit (Xhc, XHC_CRCR_OFFSET, XHC_CRCR_CA);
> > +}
> > +
> >  /**
> >Assign and initialize the device slot for a new device.
> >
> > @@ -2331,6 +2351,14 @@ XhcInitializeDeviceSlot (
> >  Xhc->UsbDevContext[SlotId].XhciDevAddr = DeviceAddress;
> >} else {
> >  DEBUG ((DEBUG_ERROR, "Slot %d address not assigned successfully.
> > Status = %r\n", SlotId, Status));
> > +//
> > +// Software may abort the execution of Address Device Command when
> > command failed
> > +// due to timeout by following XHCI spec. 4.6.1.2.
> > +//
> > +if (Status == EFI_TIMEOUT) {
> > +  XhcCmdRingCmdAbort (Xhc, SlotId);
> > +}
> > +
> >  XhcDisableSlotCmd (Xhc, SlotId);
> >}
> >
> > @@ -2547,6 +2575,14 @@ XhcInitializeDeviceSlot64 (
> >  Xhc->UsbDevContext[SlotId].XhciDevAddr = DeviceAddress;
> >} else {
> >  DEBUG ((DEBUG_ERROR, "Slot %d address not assigned successfully.
> > Status = %r\n", SlotId, Status));
> > +//
> > +// Software may abort the execution of Address Device Command when
> > command failed
> > +// due to timeout by following XHCI spec. 4.6.1.2.
> > +//
> > +if (Status == EFI_TIMEOUT) {
> > +  XhcCmdRingCmdAbort (Xhc, SlotId);
> > +}
> > +
> >  XhcDisableSlotCmd64 (Xhc, SlotId);
> >}
> >
> > --
> > 2.42.0.windows.2
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#109035): https://edk2.groups.io/g/devel/message/109035
Mute This Topic: https://groups.io/mt/101493909/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v3] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts

2023-09-24 Thread Wu, Hao A
Merged via:
PR - https://github.com/tianocore/edk2/pull/4862
Commit - 
https://github.com/tianocore/edk2/commit/43dcf453fc15ca152945ca41dcce7f2f43a14313

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Wu, Hao
> A
> Sent: Wednesday, September 20, 2023 3:24 PM
> To: devel@edk2.groups.io; Henz, Patrick 
> Cc: Ni, Ray 
> Subject: Re: [edk2-devel] [PATCH v3] MdeModulePkg/XhciDxe: Use
> Performance Timer for XHCI Timeouts
> 
> Reviewed-by: Hao A Wu 
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: devel@edk2.groups.io  On Behalf Of Henz,
> > Patrick
> > Sent: Wednesday, September 13, 2023 2:06 AM
> > To: devel@edk2.groups.io
> > Cc: Wu, Hao A ; Ni, Ray ; Henz,
> > Patrick 
> > Subject: [edk2-devel] [PATCH v3] MdeModulePkg/XhciDxe: Use
> Performance
> > Timer for XHCI Timeouts
> >
> > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2948
> >
> > XhciDxe uses the timer functionality provided by the
> > boot services table to detect timeout conditions. This
> > breaks the driver's ExitBootServices call back, as
> > CoreExitBootServices halts the timer before signaling
> > the ExitBootServices event. If the host controller
> > fails to halt in the call back, the timeout condition
> > will never occur and the boot gets stuck in an indefinite
> > spin loop. Use the free running timer provided by
> > TimerLib to calculate timeouts, avoiding the potential
> > hang.
> >
> > Cc: Hao A Wu 
> > Cc: Ray Ni 
> > Signed-off-by: Patrick Henz 
> > Reviewed-by:
> > ---
> >  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c  | 117
> > +++
> >  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h  |  32 +++
> >  MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf |   2 +
> >  MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c   |  68 +
> >  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c |  72 ++
> >  5 files changed, 204 insertions(+), 87 deletions(-)
> >
> > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > index 62682dd27c..7a2e32a9dd 100644
> > --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > @@ -1,6 +1,7 @@
> >  /** @file
> >
> >The XHCI controller driver.
> >
> >
> >
> > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> >
> >  Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.
> >
> >  SPDX-License-Identifier: BSD-2-Clause-Patent
> >
> >
> >
> > @@ -85,6 +86,11 @@ EFI_USB2_HC_PROTOCOL  gXhciUsb2HcTemplate = {
> >0x0
> >
> >  };
> >
> >
> >
> > +UINT64   mPerformanceCounterStartValue;
> >
> > +UINT64   mPerformanceCounterEndValue;
> >
> > +UINT64   mPerformanceCounterFrequency;
> >
> > +BOOLEAN  mPerformanceCounterValuesCached = FALSE;
> >
> > +
> >
> >  /**
> >
> >Retrieves the capability of root hub ports.
> >
> >
> >
> > @@ -2294,3 +2300,114 @@ XhcDriverBindingStop (
> >
> >
> >return EFI_SUCCESS;
> >
> >  }
> >
> > +
> >
> > +/**
> >
> > +  Converts a time in nanoseconds to a performance counter tick count.
> >
> > +
> >
> > +  @param  Time  The time in nanoseconds to be converted to performance
> > counter ticks.
> >
> > +  @return Time in nanoseconds converted to ticks.
> >
> > +**/
> >
> > +UINT64
> >
> > +XhcConvertTimeToTicks (
> >
> > +  IN UINT64  Time
> >
> > +  )
> >
> > +{
> >
> > +  UINT64  Ticks;
> >
> > +  UINT64  Remainder;
> >
> > +  UINT64  Divisor;
> >
> > +  UINTN   Shift;
> >
> > +
> >
> > +  // Cache the return values to avoid repeated calls to
> > GetPerformanceCounterProperties ()
> >
> > +  if (!mPerformanceCounterValuesCached) {
> >
> > +mPerformanceCounterFrequency = GetPerformanceCounterProperties (
> >
> > + ,
> >
> > + 
> >
> > + );
> >
> > +
> >
> > +mPerformanceCounterValuesCached = TRUE;
> >
> > +  }
> >
> > +
> >
> > +  // Prevent returning a tick value of 0, unless Time is already 0
> >
> > +  if (0 == mPerformanceCounterFrequency) {
> >
> > +r

Re: [edk2-devel] [PATCH v2 0/2] MdeModulePkg/Bus/Pci/UhciDxe: Fix issues pointed by Coverity

2023-09-21 Thread Wu, Hao A
Series pushed via:
PR - https://github.com/tianocore/edk2/pull/4856
Commits:
https://github.com/tianocore/edk2/commit/e9f5d8c0e066da55b3f79dfdbf4df5fc97ca5916
https://github.com/tianocore/edk2/commit/28a267af4024c329e58121ccd9bf5f4f7aabc0f4

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Ranbir
> Singh
> Sent: Wednesday, August 16, 2023 1:38 PM
> To: devel@edk2.groups.io; rsi...@ventanamicro.com
> Subject: [edk2-devel] [PATCH v2 0/2] MdeModulePkg/Bus/Pci/UhciDxe: Fix
> issues pointed by Coverity
> 
> v1 -> v2:
>   - Update patch wrt BAD_SHIFT changes as per review comments
> 
> Ranbir Singh (2):
>   MdeModulePkg/Bus/Pci/UhciDxe: Fix BAD_SHIFT Coverity issue
>   MdeModulePkg/Bus/Pci/UhciDxe: Fix FORWARD_NULL Coverity issues
> 
>  MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c | 10 +-
>  MdeModulePkg/Bus/Pci/UhciDxe/UsbHcMem.c  |  9 +
>  2 files changed, 18 insertions(+), 1 deletion(-)
> 
> --
> 2.34.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108977): https://edk2.groups.io/g/devel/message/108977
Mute This Topic: https://groups.io/mt/100774223/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH V2 1/1] MdeModulePkg/XhciDxe: Abort the Address Device cmd when time out

2023-09-21 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: Cai, Xianglei 
> Sent: Thursday, September 21, 2023 11:58 AM
> To: devel@edk2.groups.io
> Cc: Cai, Xianglei ; Wu, Hao A ;
> Ni, Ray ; Wang, Jian J ; Gao,
> Liming ; Shih, More ;
> Huang, Jenny 
> Subject: [PATCH V2 1/1] MdeModulePkg/XhciDxe: Abort the Address Device
> cmd when time out
> 
> https://bugzilla.tianocore.org/show_bug.cgi?id=4552
> 
> Following XHCI spec 4.6.1.2, software may abort the
> execution of Address Device Command when command failed
> due to timeout.
> 
> Cc: Hao A Wu 
> Cc: Ray Ni   
> Cc: Jian J Wang  
> Cc: Liming Gao   
> Cc: More Shih
> Cc: Jenny Huang  
> Signed-off-by: Xianglei Cai 
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 36
> 
>  1 file changed, 36 insertions(+)
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> index 53421e64a850..f6efcf80f376 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> @@ -2121,6 +2121,26 @@ RingIntTransferDoorBell (
>return EFI_SUCCESS;
>  }
> 
> +/**
> +  Set Command abort
> +
> +  @param  Xhc   The XHCI Instance.
> +  @param  SlotIdThe slot id to be disabled.
> +
> +**/
> +VOID
> +XhcCmdRingCmdAbort (
> +  IN USB_XHCI_INSTANCE  *Xhc,
> +  IN UINT8  SlotId
> +  )
> +{
> +  //
> +  // Set XHC_CRCR_CA bit in XHC_CRCR_OFFSET to abort command.
> +  //
> +  DEBUG ((DEBUG_INFO, "Command Ring Control set Command Abort,
> SlotId: %d\n", SlotId));
> +  XhcSetOpRegBit (Xhc, XHC_CRCR_OFFSET, XHC_CRCR_CA);
> +}
> +
>  /**
>Assign and initialize the device slot for a new device.
> 
> @@ -2331,6 +2351,14 @@ XhcInitializeDeviceSlot (
>  Xhc->UsbDevContext[SlotId].XhciDevAddr = DeviceAddress;
>} else {
>  DEBUG ((DEBUG_ERROR, "Slot %d address not assigned successfully.
> Status = %r\n", SlotId, Status));
> +//
> +// Software may abort the execution of Address Device Command when
> command failed
> +// due to timeout by following XHCI spec. 4.6.1.2.
> +//
> +if (Status == EFI_TIMEOUT) {
> +  XhcCmdRingCmdAbort (Xhc, SlotId);
> +}
> +
>  XhcDisableSlotCmd (Xhc, SlotId);
>}
> 
> @@ -2547,6 +2575,14 @@ XhcInitializeDeviceSlot64 (
>  Xhc->UsbDevContext[SlotId].XhciDevAddr = DeviceAddress;
>} else {
>  DEBUG ((DEBUG_ERROR, "Slot %d address not assigned successfully.
> Status = %r\n", SlotId, Status));
> +//
> +// Software may abort the execution of Address Device Command when
> command failed
> +// due to timeout by following XHCI spec. 4.6.1.2.
> +//
> +if (Status == EFI_TIMEOUT) {
> +  XhcCmdRingCmdAbort (Xhc, SlotId);
> +}
> +
>  XhcDisableSlotCmd64 (Xhc, SlotId);
>}
> 
> --
> 2.42.0.windows.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108935): https://edk2.groups.io/g/devel/message/108935
Mute This Topic: https://groups.io/mt/101493909/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH 1/1] MdeModulePkg\XhciDxe: Command Abort when times out

2023-09-20 Thread Wu, Hao A
General level comments:
1. Some CI tests failed for the proposed patch: 
https://github.com/tianocore/edk2/pull/4844. Could you help to resolve them?
Please help to follow the step 11 in page: 
https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Development-Process
 and check the CI test results for the upcoming patch?

2. Could you help to update the title of this commit to "MdeModulePkg/XhciDxe: 
Abort the Address Device cmd when time out" to better reflect the purpose of 
the change?

3. Could you help to add a brief description as the commit log message?

Serveral inline comments below:


> -Original Message-
> From: Cai, Xianglei 
> Sent: Monday, September 18, 2023 2:57 PM
> To: devel@edk2.groups.io
> Cc: Cai, Xianglei ; Wu, Hao A ;
> Ni, Ray ; Wang, Jian J ; Gao,
> Liming ; Shih, More 
> Subject: [PATCH 1/1] MdeModulePkg\XhciDxe: Command Abort when times
> out
> 
> https://bugzilla.tianocore.org/show_bug.cgi?id=4552
> 
> CC: Hao A Wu 
> CC: Ray Ni   
> CC: Jian J Wang  
> CC: Liming Gao   
> CC: More Shih
> Signed-off-by: Xianglei Cai 
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 35
> 
>  1 file changed, 35 insertions(+)
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> index 53421e64a850..5024d5e3acb9 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> @@ -2121,6 +2121,29 @@ RingIntTransferDoorBell (
>return EFI_SUCCESS;
>  }
> 
> +/**
> +  Set Command abort
> +
> +  @param  Xhc   The XHCI Instance.
> +  @param  SlotIdThe slot id to be disabled.
> +
> +  @retval EFI_SUCCESS   Successfully disable the device slot.


This function does not return value. Please help to update the above function 
description.

> +
> +**/
> +VOID
> +XhcCmdRingCmdAbort (
> +  IN USB_XHCI_INSTANCE  *Xhc,
> +  IN UINT8  SlotId
> +  )
> +{
> +  //
> +  // Some 3rd party XHCI external cards don't support single 64-bytes
> +width register access,
> +  // So divide it to two 32-bytes width register access.
> +  //


The above comments does not apply here. Please help to remove it.


> +  DEBUG ((DEBUG_INFO, "Command Ring Control set Command Abort,
> SlotId:
> +%d!\n", SlotId));
> +  XhcSetOpRegBit (Xhc, XHC_CRCR_OFFSET, XHC_CRCR_CA); }


Sorry for a question, do we need to wait the CRR bit of the CRCR register to 
become 0 to ensure the command ring is stopped?


> +
>  /**
>Assign and initialize the device slot for a new device.
> 
> @@ -2331,6 +2354,12 @@ XhcInitializeDeviceSlot (
>  Xhc->UsbDevContext[SlotId].XhciDevAddr = DeviceAddress;
>} else {
>  DEBUG ((DEBUG_ERROR, "Slot %d address not assigned successfully.
> Status = %r\n", SlotId, Status));
> +//
> +// Software need abort the command if a command times out in xHCI spec
> 4.6.
> +//


Suggest to update "xHCI spec 4.6" to "xHCI spec Revision 1.2, section 4.6.1.2"

Best Regards,
Hao Wu


> +if (Status == EFI_TIMEOUT) {
> +  XhcCmdRingCmdAbort (Xhc, SlotId);
> +}
>  XhcDisableSlotCmd (Xhc, SlotId);
>}
> 
> @@ -2547,6 +2576,12 @@ XhcInitializeDeviceSlot64 (
>  Xhc->UsbDevContext[SlotId].XhciDevAddr = DeviceAddress;
>} else {
>  DEBUG ((DEBUG_ERROR, "Slot %d address not assigned successfully.
> Status = %r\n", SlotId, Status));
> +//
> +// Software need abort the command if a command times out in xHCI spec
> 4.6.
> +//
> +if (Status == EFI_TIMEOUT) {
> +  XhcCmdRingCmdAbort (Xhc, SlotId);
> +}
>  XhcDisableSlotCmd64 (Xhc, SlotId);
>}
> 
> --
> 2.42.0.windows.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108900): https://edk2.groups.io/g/devel/message/108900
Mute This Topic: https://groups.io/mt/101435621/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v3] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts

2023-09-20 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Henz,
> Patrick
> Sent: Wednesday, September 13, 2023 2:06 AM
> To: devel@edk2.groups.io
> Cc: Wu, Hao A ; Ni, Ray ; Henz,
> Patrick 
> Subject: [edk2-devel] [PATCH v3] MdeModulePkg/XhciDxe: Use Performance
> Timer for XHCI Timeouts
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2948
> 
> XhciDxe uses the timer functionality provided by the
> boot services table to detect timeout conditions. This
> breaks the driver's ExitBootServices call back, as
> CoreExitBootServices halts the timer before signaling
> the ExitBootServices event. If the host controller
> fails to halt in the call back, the timeout condition
> will never occur and the boot gets stuck in an indefinite
> spin loop. Use the free running timer provided by
> TimerLib to calculate timeouts, avoiding the potential
> hang.
> 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Signed-off-by: Patrick Henz 
> Reviewed-by:
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c  | 117
> +++
>  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h  |  32 +++
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf |   2 +
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c   |  68 +
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c |  72 ++
>  5 files changed, 204 insertions(+), 87 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> index 62682dd27c..7a2e32a9dd 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> @@ -1,6 +1,7 @@
>  /** @file
> 
>The XHCI controller driver.
> 
> 
> 
> +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> 
>  Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.
> 
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> 
> 
> @@ -85,6 +86,11 @@ EFI_USB2_HC_PROTOCOL  gXhciUsb2HcTemplate = {
>0x0
> 
>  };
> 
> 
> 
> +UINT64   mPerformanceCounterStartValue;
> 
> +UINT64   mPerformanceCounterEndValue;
> 
> +UINT64   mPerformanceCounterFrequency;
> 
> +BOOLEAN  mPerformanceCounterValuesCached = FALSE;
> 
> +
> 
>  /**
> 
>Retrieves the capability of root hub ports.
> 
> 
> 
> @@ -2294,3 +2300,114 @@ XhcDriverBindingStop (
> 
> 
>return EFI_SUCCESS;
> 
>  }
> 
> +
> 
> +/**
> 
> +  Converts a time in nanoseconds to a performance counter tick count.
> 
> +
> 
> +  @param  Time  The time in nanoseconds to be converted to performance
> counter ticks.
> 
> +  @return Time in nanoseconds converted to ticks.
> 
> +**/
> 
> +UINT64
> 
> +XhcConvertTimeToTicks (
> 
> +  IN UINT64  Time
> 
> +  )
> 
> +{
> 
> +  UINT64  Ticks;
> 
> +  UINT64  Remainder;
> 
> +  UINT64  Divisor;
> 
> +  UINTN   Shift;
> 
> +
> 
> +  // Cache the return values to avoid repeated calls to
> GetPerformanceCounterProperties ()
> 
> +  if (!mPerformanceCounterValuesCached) {
> 
> +mPerformanceCounterFrequency = GetPerformanceCounterProperties (
> 
> + ,
> 
> + 
> 
> + );
> 
> +
> 
> +mPerformanceCounterValuesCached = TRUE;
> 
> +  }
> 
> +
> 
> +  // Prevent returning a tick value of 0, unless Time is already 0
> 
> +  if (0 == mPerformanceCounterFrequency) {
> 
> +return Time;
> 
> +  }
> 
> +
> 
> +  // Nanoseconds per second
> 
> +  Divisor = 10;
> 
> +
> 
> +  //
> 
> +  //   Frequency
> 
> +  // Ticks = - x Time
> 
> +  // 1,000,000,000
> 
> +  //
> 
> +  Ticks = MultU64x64 (
> 
> +DivU64x64Remainder (
> 
> +  mPerformanceCounterFrequency,
> 
> +  Divisor,
> 
> +  
> 
> +  ),
> 
> +Time
> 
> +);
> 
> +
> 
> +  //
> 
> +  // Ensure (Remainder * Time) will not overflow 64-bit.
> 
> +  //
> 
> +  // HighBitSet64 (Remainder) + 1 + HighBitSet64 (Time) + 1 <= 64
> 
> +  //
> 
> +  Shift = MAX (0, HighBitSet64 (Remainder) + HighBitSet64 (Time) - 62);
> 
> +  Remainder = RShiftU64 (Remainder, (UINTN)Shift);
> 
> +  Divisor   = RShiftU64 (Divisor, (UINTN)Shift);
> 
> +  Ticks+= DivU64x64Remainder (MultU64x64 (Remainder, Time), Divisor,
> NULL);
> 
> +
> 
> +  return Ticks;
> 
> +}
> 
> +
> 
> +/**
> 
> +  Computes an

Re: [edk2-devel] [PATCH v1 1/1] MdeModulePkg/Bus/Pci/NvmExpressPei: Fix DEADCODE Coverity issue

2023-09-20 Thread Wu, Hao A
Pushed via:
PR - https://github.com/tianocore/edk2/pull/4843
Commit - 
https://github.com/tianocore/edk2/commit/4317b4824bc881fe6079d04b7ee5b0f6bddf62ca

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Wu, Hao
> A
> Sent: Thursday, August 10, 2023 10:39 AM
> To: Ranbir Singh ; devel@edk2.groups.io
> Cc: Ni, Ray ; Veeresh Sangolli
> 
> Subject: Re: [edk2-devel] [PATCH v1 1/1]
> MdeModulePkg/Bus/Pci/NvmExpressPei: Fix DEADCODE Coverity issue
> 
> Reviewed-by: Hao A Wu 
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: Ranbir Singh 
> > Sent: Monday, July 17, 2023 7:40 PM
> > To: devel@edk2.groups.io; rsi...@ventanamicro.com
> > Cc: Wu, Hao A ; Ni, Ray ;
> > Veeresh Sangolli 
> > Subject: [PATCH v1 1/1] MdeModulePkg/Bus/Pci/NvmExpressPei: Fix
> > DEADCODE Coverity issue
> >
> > From: Ranbir Singh 
> >
> > The code can reach line 65 only through the else path above at line 53.
> > The else path already has the same NULL check at line 55 and hence the
> > duplicate code lines are totally redundant which can be deleted.
> >
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4220
> >
> > Cc: Hao A Wu 
> > Cc: Ray Ni 
> > Co-authored-by: Veeresh Sangolli 
> > Signed-off-by: Ranbir Singh 
> > Signed-off-by: Ranbir Singh 
> > ---
> >  MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiS3.c | 4 
> >  1 file changed, 4 deletions(-)
> >
> > diff --git a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiS3.c
> > b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiS3.c
> > index d704c62eaab3..1d03d4964025 100644
> > --- a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiS3.c
> > +++ b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiS3.c
> > @@ -62,10 +62,6 @@ NvmeS3SkipThisController (
> >  }   } -  if (S3InitDevices == NULL) {-return Skip;-  }-   //   // 
> > Only need to
> > initialize the controllers that exist in the device list.   //--
> > 2.34.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108898): https://edk2.groups.io/g/devel/message/108898
Mute This Topic: https://groups.io/mt/100212115/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 1/1] MdeModulePkg/Bus/Ata/AtaBusDxe: Fix SIGN_EXTENSION Coverity issue

2023-09-19 Thread Wu, Hao A
Pushed via:
PR - https://github.com/tianocore/edk2/pull/4841
Commit - 
https://github.com/tianocore/edk2/commit/4fb69c2bee3006b08ca2abba58843f7573e0c5c6

Best Regards,
Hao Wu

> -Original Message-
> From: Wu, Hao A
> Sent: Thursday, August 10, 2023 10:39 AM
> To: Ranbir Singh ; devel@edk2.groups.io
> Cc: Ni, Ray 
> Subject: RE: [PATCH v2 1/1] MdeModulePkg/Bus/Ata/AtaBusDxe: Fix
> SIGN_EXTENSION Coverity issue
> 
> Reviewed-by: Hao A Wu 
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: Ranbir Singh 
> > Sent: Monday, July 17, 2023 7:59 PM
> > To: devel@edk2.groups.io; rsi...@ventanamicro.com
> > Cc: Wu, Hao A ; Ni, Ray 
> > Subject: [PATCH v2 1/1] MdeModulePkg/Bus/Ata/AtaBusDxe: Fix
> > SIGN_EXTENSION Coverity issue
> >
> > From: Ranbir Singh 
> >
> > Line number 365 does contain a typecast with UINT32, but it is after
> > all the operations (16-bit left shift followed by OR'ing) are over.
> > To avoid any SIGN_EXTENSION, typecast the intermediate result after
> > 16-bit left shift operation immediately with UINT32.
> >
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4209
> >
> > Cc: Hao A Wu 
> > Cc: Ray Ni 
> > Signed-off-by: Ranbir Singh 
> > Signed-off-by: Ranbir Singh 
> > ---
> >  MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c
> > b/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c
> > index a77852bae054..57aefa04c215 100644
> > --- a/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c
> > +++ b/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c
> > @@ -362,7 +362,7 @@ IdentifyAtaDevice (
> >  // Check logical block size // if ((PhyLogicSectorSupport & 
> > BIT12) != 0)
> {-
> > BlockMedia->BlockSize = (UINT32)(((IdentifyData->logic_sector_size_hi
> > BlockMedia-><< 16)
> > | IdentifyData->logic_sector_size_lo) * sizeof (UINT16));+  BlockMedia-
> > >BlockSize = (UINT32)(((UINT32)(IdentifyData->logic_sector_size_hi <<
> > >16) |
> > IdentifyData->logic_sector_size_lo) * sizeof (UINT16)); }  
> > AtaDevice-
> > >BlockIo.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION2;--
> > 2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108897): https://edk2.groups.io/g/devel/message/108897
Mute This Topic: https://groups.io/mt/100212118/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 1/2] MdeModulePkg/Bus/Pci/UhciDxe: Fix BAD_SHIFT Coverity issue

2023-09-19 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: Ranbir Singh 
> Sent: Wednesday, August 16, 2023 1:38 PM
> To: devel@edk2.groups.io; rsi...@ventanamicro.com
> Cc: Wu, Hao A ; Ni, Ray ; Veeresh
> Sangolli 
> Subject: [PATCH v2 1/2] MdeModulePkg/Bus/Pci/UhciDxe: Fix BAD_SHIFT
> Coverity issue
> 
> From: Ranbir Singh 
> 
> The function UhciConvertPollRate has a check
> 
> ASSERT (Interval != 0);
> 
> but this comes into play only in DEBUG mode. In Release mode, there is
> no handling if the Interval parameter value is ZERO. To avoid shifting
> by a negative amount later in the code flow in this undesirable case,
> it is better to handle it as well by treating it same as if 1 is sent.
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4211
> 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Co-authored-by: Veeresh Sangolli 
> Signed-off-by: Ranbir Singh 
> Signed-off-by: Ranbir Singh 
> ---
>  MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c | 10 +-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c
> b/MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c
> index c08f9496969b..408e7d5ab7f3 100644
> --- a/MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c
> +++ b/MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c
> @@ -197,7 +197,7 @@ UhciDestoryFrameList (
>  }
> 
> 
> 
>  /**
> 
> -  Convert the poll rate to the maxium 2^n that is smaller
> 
> +  Convert the poll rate to the maximum 2^n that is smaller
> 
>than Interval.
> 
> 
> 
>@param  Interval   The poll rate to convert.
> 
> @@ -214,6 +214,14 @@ UhciConvertPollRate (
> 
> 
>ASSERT (Interval != 0);
> 
> 
> 
> +  //
> 
> +  // To safeguard RELEASE mode wherein ASSERT is effectively not there,
> 
> +  // if inadvertently Interval is still 0 here, treat it the same as 1.
> 
> +  //
> 
> +  if (Interval == 0) {
> 
> +Interval = 1;
> 
> +  }
> 
> +
> 
>//
> 
>// Find the index (1 based) of the highest non-zero bit
> 
>//
> 
> --
> 2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108896): https://edk2.groups.io/g/devel/message/108896
Mute This Topic: https://groups.io/mt/100774224/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts

2023-09-07 Thread Wu, Hao A
Thanks. I am fine with the proposal below.

Could you please help to follow the step 11 in page: 
https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Development-Process
and check the CI test results for the upcoming patch?

Best Regards,
Hao Wu

> -Original Message-
> From: Henz, Patrick 
> Sent: Friday, September 8, 2023 2:39 AM
> To: devel@edk2.groups.io; Wu, Hao A ; Mike
> Maslenkin 
> Subject: RE: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use
> Performance Timer for XHCI Timeouts
> 
> I don’t have strong opinions either. If we would prefer to cache the values
> returned by GetPerformanceCounterProperties I would be more than happy
> to do that. I could also modify XhcGetElapsedTime to return the elapsed ticks
> instead of the elapsed time in nano seconds, the functions that call into
> XhcGetElapedTime/Ticks could convert the millisecond timeout value into a
> tick count and compare the elapsed ticks against that, this would remove the
> reliance on GetTimeInNanoSecond. Does that sound more appropriate?
> 
> Thanks,
> Patrick Henz
> 
> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Wu, Hao
> A
> Sent: Thursday, September 7, 2023 2:48 AM
> To: Mike Maslenkin ; devel@edk2.groups.io
> Cc: Henz, Patrick 
> Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use
> Performance Timer for XHCI Timeouts
> 
> I do not have strong opinion on this considering it is an IO driver.
> The call of GetTimeInNanoSecond() is also likely to invoke
> GetPerformanceCounterProperties() call.
> 
> I will let the patch owner to decide on the open raised below.
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: Mike Maslenkin 
> > Sent: Thursday, September 7, 2023 3:36 PM
> > To: devel@edk2.groups.io; Wu, Hao A 
> > Cc: Henz, Patrick 
> > Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use
> > Performance Timer for XHCI Timeouts
> >
> > Hello Hao Wu,
> >
> > Isn't GetPerformanceCounterProperties (, ) call
> > too "heavy" for XHCI paths?
> > May be it's better to cache timer direction once?
> > I'm asking in a context of PcAtChipsetPkg/Library/AcpiTimerLib
> > instance used by a number of Intel's platform in edk-platforms.
> > For this  library GetPerformanceCounterProperties finally calls
> > InternalCalculateTscFrequency, that isn't simple.
> >
> > Regards,
> > Mike
> >
> > On Thu, Sep 7, 2023 at 4:27 AM Wu, Hao A  wrote:
> > >
> > > Sorry for the late response.
> > > Reviewed-by: Hao A Wu 
> > >
> > > Best Regards,
> > > Hao Wu
> > >
> > > > -Original Message-
> > > > From: devel@edk2.groups.io  On Behalf Of
> > > > Henz, Patrick
> > > > Sent: Thursday, September 7, 2023 4:37 AM
> > > > To: devel@edk2.groups.io
> > > > Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use
> > > > Performance Timer for XHCI Timeouts
> > > >
> > > > I sent this patch out a few weeks ago now but haven't seen a
> > > > reply, just checking in to make sure it didn't get missed.
> > > >
> > > > Thanks,
> > > > Patrick Henz
> > > >
> > > > -Original Message-
> > > > From: devel@edk2.groups.io  On Behalf Of
> > > > Henz, Patrick
> > > > Sent: Monday, August 14, 2023 10:52 AM
> > > > To: devel@edk2.groups.io
> > > > Cc: Henz, Patrick 
> > > > Subject: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use
> > > > Performance Timer for XHCI Timeouts
> > > >
> > > > REF:https://urldefense.com/v3/__https://bugzilla.tianocore.org/sho
> > > > w_bug.cgi?id=2948__;!!NpxR!mZRuMBKPdeR-
> UvY7sr8tWNOfIQDe0W_TW3q-K8M
> > > > tNN1cynyRZ1_bls8osaEqFWupFmjR29X_zvw0Zx1Y$
> > > >
> > > > XhciDxe uses the timer functionality provided by the boot services
> > > > table to detect timeout conditions. This breaks the driver's
> > > > ExitBootServices call back, as CoreExitBootServices halts the
> > > > timer before signaling the ExitBootServices event. If the host
> > > > controller fails to halt in the call back, the timeout condition
> > > > will never occur and the boot gets stuck in an indefinite spin
> > > > loop. Use the free running timer provided by TimerLib to calculate
> > > > timeouts, avoiding
> > the potential hang.
> > > >
> > > > Signed-off-by: Patrick Henz 
> > > > Review

Re: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts

2023-09-07 Thread Wu, Hao A
Speaking of PcAtChipsetPkg/Library/AcpiTimerLib, the implementation of below 
instances:
* PeiAcpiTimerLib.inf
* DxeAcpiTimerLib.inf
* StandaloneMmAcpiTimerLib.inf
will not calculate the TSC frequency upon every call of 
GetPerformanceCounterProperties().

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Wu, Hao
> A
> Sent: Thursday, September 7, 2023 3:48 PM
> To: Mike Maslenkin ; devel@edk2.groups.io
> Cc: Henz, Patrick 
> Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use
> Performance Timer for XHCI Timeouts
> 
> I do not have strong opinion on this considering it is an IO driver.
> The call of GetTimeInNanoSecond() is also likely to invoke
> GetPerformanceCounterProperties() call.
> 
> I will let the patch owner to decide on the open raised below.
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: Mike Maslenkin 
> > Sent: Thursday, September 7, 2023 3:36 PM
> > To: devel@edk2.groups.io; Wu, Hao A 
> > Cc: Henz, Patrick 
> > Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use
> > Performance Timer for XHCI Timeouts
> >
> > Hello Hao Wu,
> >
> > Isn't GetPerformanceCounterProperties (, ) call
> > too "heavy" for XHCI paths?
> > May be it's better to cache timer direction once?
> > I'm asking in a context of PcAtChipsetPkg/Library/AcpiTimerLib
> > instance used by a number of Intel's platform in edk-platforms.
> > For this  library GetPerformanceCounterProperties finally calls
> > InternalCalculateTscFrequency, that isn't simple.
> >
> > Regards,
> > Mike
> >
> > On Thu, Sep 7, 2023 at 4:27 AM Wu, Hao A  wrote:
> > >
> > > Sorry for the late response.
> > > Reviewed-by: Hao A Wu 
> > >
> > > Best Regards,
> > > Hao Wu
> > >
> > > > -Original Message-
> > > > From: devel@edk2.groups.io  On Behalf Of
> > > > Henz, Patrick
> > > > Sent: Thursday, September 7, 2023 4:37 AM
> > > > To: devel@edk2.groups.io
> > > > Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use
> > > > Performance Timer for XHCI Timeouts
> > > >
> > > > I sent this patch out a few weeks ago now but haven't seen a
> > > > reply, just checking in to make sure it didn't get missed.
> > > >
> > > > Thanks,
> > > > Patrick Henz
> > > >
> > > > -Original Message-
> > > > From: devel@edk2.groups.io  On Behalf Of
> > > > Henz, Patrick
> > > > Sent: Monday, August 14, 2023 10:52 AM
> > > > To: devel@edk2.groups.io
> > > > Cc: Henz, Patrick 
> > > > Subject: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use
> > > > Performance Timer for XHCI Timeouts
> > > >
> > > > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2948
> > > >
> > > > XhciDxe uses the timer functionality provided by the boot services
> > > > table to detect timeout conditions. This breaks the driver's
> > > > ExitBootServices call back, as CoreExitBootServices halts the
> > > > timer before signaling the ExitBootServices event. If the host
> > > > controller fails to halt in the call back, the timeout condition
> > > > will never occur and the boot gets stuck in an indefinite spin
> > > > loop. Use the free running timer provided by TimerLib to calculate
> > > > timeouts, avoiding
> > the potential hang.
> > > >
> > > > Signed-off-by: Patrick Henz 
> > > > Reviewed-by:
> > > > ---
> > > >  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c  | 56 +++
> > > >  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h  | 22 
> > > >  MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf |  2 +
> > > >  MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c   | 67 +--
> > > >  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 68
> > > > +---
> > > >  5 files changed, 129 insertions(+), 86 deletions(-)
> > > >
> > > > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > > > b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > > > index 62682dd27c..1dcbe20512 100644
> > > > --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > > > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > > > @@ -1,6 +1,7 @@
> > > >  /** @file
> > > >The XHCI controller driver.
> > > >
> > > > +(C) Copyri

Re: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts

2023-09-07 Thread Wu, Hao A
I do not have strong opinion on this considering it is an IO driver.
The call of GetTimeInNanoSecond() is also likely to invoke 
GetPerformanceCounterProperties() call.

I will let the patch owner to decide on the open raised below.

Best Regards,
Hao Wu

> -Original Message-
> From: Mike Maslenkin 
> Sent: Thursday, September 7, 2023 3:36 PM
> To: devel@edk2.groups.io; Wu, Hao A 
> Cc: Henz, Patrick 
> Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use
> Performance Timer for XHCI Timeouts
> 
> Hello Hao Wu,
> 
> Isn't GetPerformanceCounterProperties (, ) call too
> "heavy" for XHCI paths?
> May be it's better to cache timer direction once?
> I'm asking in a context of PcAtChipsetPkg/Library/AcpiTimerLib
> instance used by a number of Intel's platform in edk-platforms.
> For this  library GetPerformanceCounterProperties finally calls
> InternalCalculateTscFrequency, that isn't simple.
> 
> Regards,
> Mike
> 
> On Thu, Sep 7, 2023 at 4:27 AM Wu, Hao A  wrote:
> >
> > Sorry for the late response.
> > Reviewed-by: Hao A Wu 
> >
> > Best Regards,
> > Hao Wu
> >
> > > -Original Message-
> > > From: devel@edk2.groups.io  On Behalf Of Henz,
> > > Patrick
> > > Sent: Thursday, September 7, 2023 4:37 AM
> > > To: devel@edk2.groups.io
> > > Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use
> > > Performance Timer for XHCI Timeouts
> > >
> > > I sent this patch out a few weeks ago now but haven't seen a reply,
> > > just checking in to make sure it didn't get missed.
> > >
> > > Thanks,
> > > Patrick Henz
> > >
> > > -Original Message-
> > > From: devel@edk2.groups.io  On Behalf Of Henz,
> > > Patrick
> > > Sent: Monday, August 14, 2023 10:52 AM
> > > To: devel@edk2.groups.io
> > > Cc: Henz, Patrick 
> > > Subject: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use
> > > Performance Timer for XHCI Timeouts
> > >
> > > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2948
> > >
> > > XhciDxe uses the timer functionality provided by the boot services
> > > table to detect timeout conditions. This breaks the driver's
> > > ExitBootServices call back, as CoreExitBootServices halts the timer
> > > before signaling the ExitBootServices event. If the host controller
> > > fails to halt in the call back, the timeout condition will never
> > > occur and the boot gets stuck in an indefinite spin loop. Use the
> > > free running timer provided by TimerLib to calculate timeouts, avoiding
> the potential hang.
> > >
> > > Signed-off-by: Patrick Henz 
> > > Reviewed-by:
> > > ---
> > >  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c  | 56 +++
> > >  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h  | 22 
> > >  MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf |  2 +
> > >  MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c   | 67 +--
> > >  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 68
> > > +---
> > >  5 files changed, 129 insertions(+), 86 deletions(-)
> > >
> > > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > > b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > > index 62682dd27c..1dcbe20512 100644
> > > --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > > @@ -1,6 +1,7 @@
> > >  /** @file
> > >The XHCI controller driver.
> > >
> > > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> > >  Copyright (c) 2011 - 2022, Intel Corporation. All rights
> > > reserved.
> > >  SPDX-License-Identifier: BSD-2-Clause-Patent
> > >
> > > @@ -2294,3 +2295,58 @@ XhcDriverBindingStop (
> > >
> > >return EFI_SUCCESS;
> > >  }
> > > +
> > > +/**
> > > +  Computes and returns the elapsed time in nanoseconds since
> > > +  PreviousTick. The value of PreviousTick is overwritten with the
> > > +  current performance counter value.
> > > +
> > > +  @param  PreviousTickPointer to PreviousTick count.
> > > +  @return The elapsed time in nanoseconds since PreviousCount.
> > > +  PreviousCount is overwritten with the current performance
> > > +  counter value.
> > > +**/
> > > +UINT64
> > > +XhcGetElapsedTime (
> > > +  IN OUT UINT64  *PreviousTick
> > > +  )
> > > +{
> > > +  UINT

Re: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts

2023-09-06 Thread Wu, Hao A
Sorry, I found that there is a build failure for the proposed change:
PR - https://github.com/tianocore/edk2/pull/4796
Details:
https://dev.azure.com/tianocore/edk2-ci/_build/results?buildId=101097=logs=2dc6585a-9807-582d-5eb8-65e26db2b1d0=fe91d259-3a7c-5e73-4892-c865ef48cb16
ERROR - Linker #2001 from XhciDxe.lib(XhciSched.obj) : unresolved external 
symbol __allmul
ERROR - Linker #2001 from XhciDxe.lib(XhciReg.obj) : unresolved external symbol 
__allmul
ERROR - Linker #1120 from 
d:\a\1\s\Build\OvmfIa32\NOOPT_VS2019\IA32\MdeModulePkg\Bus\Pci\XhciDxe\XhciDxe\DEBUG\XhciDxe.dll
 : fatal 1 unresolved externals

I think we need to update "(UINT64)Timeout * XHC_1_MILLISECOND" by using 
BaseLib API MultU64x32().
Could you help to update the patch and check if it can pass the CI builds, 
thanks.

Best Regards,
Hao Wu

> -Original Message-----
> From: Wu, Hao A
> Sent: Thursday, September 7, 2023 9:28 AM
> To: devel@edk2.groups.io; Henz, Patrick 
> Subject: RE: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use
> Performance Timer for XHCI Timeouts
> 
> Sorry for the late response.
> Reviewed-by: Hao A Wu 
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: devel@edk2.groups.io  On Behalf Of Henz,
> > Patrick
> > Sent: Thursday, September 7, 2023 4:37 AM
> > To: devel@edk2.groups.io
> > Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use
> > Performance Timer for XHCI Timeouts
> >
> > I sent this patch out a few weeks ago now but haven't seen a reply,
> > just checking in to make sure it didn't get missed.
> >
> > Thanks,
> > Patrick Henz
> >
> > -Original Message-
> > From: devel@edk2.groups.io  On Behalf Of Henz,
> > Patrick
> > Sent: Monday, August 14, 2023 10:52 AM
> > To: devel@edk2.groups.io
> > Cc: Henz, Patrick 
> > Subject: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use Performance
> > Timer for XHCI Timeouts
> >
> > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2948
> >
> > XhciDxe uses the timer functionality provided by the boot services
> > table to detect timeout conditions. This breaks the driver's
> > ExitBootServices call back, as CoreExitBootServices halts the timer
> > before signaling the ExitBootServices event. If the host controller
> > fails to halt in the call back, the timeout condition will never occur
> > and the boot gets stuck in an indefinite spin loop. Use the free
> > running timer provided by TimerLib to calculate timeouts, avoiding the
> potential hang.
> >
> > Signed-off-by: Patrick Henz 
> > Reviewed-by:
> > ---
> >  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c  | 56 +++
> >  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h  | 22 
> >  MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf |  2 +
> >  MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c   | 67 +--
> >  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 68
> > +---
> >  5 files changed, 129 insertions(+), 86 deletions(-)
> >
> > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > index 62682dd27c..1dcbe20512 100644
> > --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > @@ -1,6 +1,7 @@
> >  /** @file
> >The XHCI controller driver.
> >
> > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> >  Copyright (c) 2011 - 2022, Intel Corporation. All rights
> > reserved.
> >  SPDX-License-Identifier: BSD-2-Clause-Patent
> >
> > @@ -2294,3 +2295,58 @@ XhcDriverBindingStop (
> >
> >return EFI_SUCCESS;
> >  }
> > +
> > +/**
> > +  Computes and returns the elapsed time in nanoseconds since
> > +  PreviousTick. The value of PreviousTick is overwritten with the
> > +  current performance counter value.
> > +
> > +  @param  PreviousTickPointer to PreviousTick count.
> > +  @return The elapsed time in nanoseconds since PreviousCount.
> > +  PreviousCount is overwritten with the current performance
> > +  counter value.
> > +**/
> > +UINT64
> > +XhcGetElapsedTime (
> > +  IN OUT UINT64  *PreviousTick
> > +  )
> > +{
> > +  UINT64  StartValue;
> > +  UINT64  EndValue;
> > +  UINT64  CurrentTick;
> > +  UINT64  Delta;
> > +
> > +  GetPerformanceCounterProperties (, );
> > +
> > +  CurrentTick = GetPerformanceCounter ();
> > +
> > +  //
> > +  // Determine if the counter is counting up or down  //  if
> > + (StartValue < EndValue) {
> > +//
> &g

Re: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts

2023-09-06 Thread Wu, Hao A
Sorry for the late response.
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Henz,
> Patrick
> Sent: Thursday, September 7, 2023 4:37 AM
> To: devel@edk2.groups.io
> Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use
> Performance Timer for XHCI Timeouts
> 
> I sent this patch out a few weeks ago now but haven't seen a reply, just
> checking in to make sure it didn't get missed.
> 
> Thanks,
> Patrick Henz
> 
> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Henz,
> Patrick
> Sent: Monday, August 14, 2023 10:52 AM
> To: devel@edk2.groups.io
> Cc: Henz, Patrick 
> Subject: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use Performance
> Timer for XHCI Timeouts
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2948
> 
> XhciDxe uses the timer functionality provided by the boot services table to
> detect timeout conditions. This breaks the driver's ExitBootServices call 
> back,
> as CoreExitBootServices halts the timer before signaling the ExitBootServices
> event. If the host controller fails to halt in the call back, the timeout 
> condition
> will never occur and the boot gets stuck in an indefinite spin loop. Use the
> free running timer provided by TimerLib to calculate timeouts, avoiding the
> potential hang.
> 
> Signed-off-by: Patrick Henz 
> Reviewed-by:
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c  | 56 +++
>  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h  | 22 
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf |  2 +
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c   | 67 +--
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 68 +---
>  5 files changed, 129 insertions(+), 86 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> index 62682dd27c..1dcbe20512 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> @@ -1,6 +1,7 @@
>  /** @file
>The XHCI controller driver.
> 
> +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
>  Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> @@ -2294,3 +2295,58 @@ XhcDriverBindingStop (
> 
>return EFI_SUCCESS;
>  }
> +
> +/**
> +  Computes and returns the elapsed time in nanoseconds since
> +  PreviousTick. The value of PreviousTick is overwritten with the
> +  current performance counter value.
> +
> +  @param  PreviousTickPointer to PreviousTick count.
> +  @return The elapsed time in nanoseconds since PreviousCount.
> +  PreviousCount is overwritten with the current performance
> +  counter value.
> +**/
> +UINT64
> +XhcGetElapsedTime (
> +  IN OUT UINT64  *PreviousTick
> +  )
> +{
> +  UINT64  StartValue;
> +  UINT64  EndValue;
> +  UINT64  CurrentTick;
> +  UINT64  Delta;
> +
> +  GetPerformanceCounterProperties (, );
> +
> +  CurrentTick = GetPerformanceCounter ();
> +
> +  //
> +  // Determine if the counter is counting up or down  //  if
> + (StartValue < EndValue) {
> +//
> +// Counter counts upwards, check for an overflow condition
> +//
> +if (*PreviousTick > CurrentTick) {
> +  Delta = (EndValue - *PreviousTick) + CurrentTick;
> +} else {
> +  Delta = CurrentTick - *PreviousTick;
> +}
> +  } else {
> +//
> +// Counter counts downwards, check for an underflow condition
> +//
> +if (*PreviousTick < CurrentTick) {
> +  Delta = (StartValue - CurrentTick) + *PreviousTick;
> +} else {
> +  Delta = *PreviousTick - CurrentTick;
> +}
> +  }
> +
> +  //
> +  // Set PreviousTick to CurrentTick
> +  //
> +  *PreviousTick = CurrentTick;
> +
> +  return GetTimeInNanoSecond (Delta);
> +}
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h
> b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h
> index ca223bd20c..77feb66647 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h
> @@ -2,6 +2,7 @@
> 
>Provides some data structure definitions used by the XHCI host controller
> driver.
> 
> +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
>  Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.
> Copyright (c) Microsoft Corporation.
>  SPDX-License-Identifier: BSD-2-Clause-Patent @@ -26,6 +27,7 @@ SPDX-
> License-Identifier: BSD-2-Clause-Patent  #include   
> #include
>   #include 
> +#include 
> 
>  #include 
> 
> @@ -37,6 +39,10 @@ typedef struct _USB_DEV_CONTEXT
> USB_DEV_CONTEXT;
>  #include "ComponentName.h"
>  #include "UsbHcMem.h"
> 
> +//
> +// Converts a count from microseconds to nanoseconds // #define
> +XHC_MICROSECOND_TO_NANOSECOND(Time)  ((UINT64)(Time) * 1000)
>  //
>  // The unit is microsecond, setting it as 1us.
>  //
> @@ -720,4 +726,20 @@ XhcAsyncIsochronousTransfer (
>IN VOID*Context
>);
> 
> +/**
> +  Computes and returns the elapsed time 

Re: [edk2-devel] [PATCH v1 1/2] MdeModulePkg/Bus/Pci/UhciDxe: Fix BAD_SHIFT Coverity issue

2023-08-14 Thread Wu, Hao A
My take is that:
For all the possible calling scenario of UhciConvertPollRate() in current
UhciDxe driver implementation, it is guaranteed that the input parameter
'Interval' will not be 0.

I think this is why the "ASSERT (Interval != 0);" statement is put here to
indicate such case will never happen and notify developers for future changes
in this driver that something is wrong.

I do not know why Coverity is unable to figure this out.

My personal preference is to return 1 (i.e. 1 << 0) as if the minimum allowed
value for 'Interval' (which is 1) is being passed into this UhciConvertPollRate
function if anything does go wrong brought by future changes.

Best Regards,
Hao Wu

From: Ranbir Singh 
Sent: Monday, August 14, 2023 3:49 PM
To: Wu, Hao A 
Cc: devel@edk2.groups.io; Ni, Ray ; Veeresh Sangolli 

Subject: Re: [PATCH v1 1/2] MdeModulePkg/Bus/Pci/UhciDxe: Fix BAD_SHIFT 
Coverity issue


On Thu, Aug 10, 2023 at 8:09 AM Wu, Hao A 
mailto:hao.a...@intel.com>> wrote:
> -Original Message-
> From: Ranbir Singh mailto:rsi...@ventanamicro.com>>
> Sent: Monday, July 17, 2023 7:39 PM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; 
> rsi...@ventanamicro.com<mailto:rsi...@ventanamicro.com>
> Cc: Wu, Hao A mailto:hao.a...@intel.com>>; Ni, Ray 
> mailto:ray...@intel.com>>; Veeresh
> Sangolli mailto:veeresh.sango...@dellteam.com>>
> Subject: [PATCH v1 1/2] MdeModulePkg/Bus/Pci/UhciDxe: Fix BAD_SHIFT
> Coverity issue
>
> From: Ranbir Singh mailto:ranbir.sin...@dell.com>>
>
> The function UhciConvertPollRate has a check
>
> ASSERT (Interval != 0);
>
> but this comes into play only in DEBUG mode. In Release mode, there is
> no handling if the Interval parameter value is ZERO. To avoid shifting
> by a negative amount later in the code flow in this undesirable case,
> it is better to handle it as well by simply returning ZERO.
>
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4211
>
> Cc: Hao A Wu mailto:hao.a...@intel.com>>
> Cc: Ray Ni mailto:ray...@intel.com>>
> Co-authored-by: Veeresh Sangolli 
> mailto:veeresh.sango...@dellteam.com>>
> Signed-off-by: Ranbir Singh 
> mailto:ranbir.sin...@dell.com>>
> Signed-off-by: Ranbir Singh 
> mailto:rsi...@ventanamicro.com>>
> ---
>  MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c | 4 
>  1 file changed, 4 insertions(+)
>
> diff --git a/MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c
> b/MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c
> index c08f9496969b..8ddef4b68ccf 100644
> --- a/MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c
> +++ b/MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c
> @@ -214,6 +214,10 @@ UhciConvertPollRate (
>
>
>ASSERT (Interval != 0);
>
>
>
> +  if (Interval == 0) {
>
> +return 0;


Return 0 will cause further issues within UhciLinkQhToFrameList() &
UhciUnlinkQhFromFrameList() where the returned value is being used in the below
'for' statement:

for (Index = 0; Index < UHCI_FRAME_NUM; Index += Qh->Interval) {

One way is to prohibit UhciCreateQh() to proceed normally by checking if 
Interval parameter value is 0 at the very beginning and may be add a DEBUG 
statement and/or an ASSERT as well - return value then has to be NULL from this 
function for this specific case of invalid Interval parameter value being 
received as 0. That should take care of the issue Hao pointed above in for loop.

UhciCreateAsyncReq() may also need to introduce a Polling Interval parameter 
value check similar to as it exists in Uhci2AsyncInterruptTransfer() for a 
future direct call scenario.

My thought is to return 1 (i.e. 1 << 0) as if the minimum allowed value for
'Interval' (which is 1) is being passed into this UhciConvertPollRate function.

If we choose to modify UhciCreateQh(), then we may have status quo in 
UhciConvertPollRate(). However, we can still pursue the return 1 (i.e. 1 << 0) 
option here in which case I guess I should update the function header as well 
to reflect the minimum 'Interval' valid value as 1 and that if 0 is wrongly 
sent, it will be treated as 1 only. When we do that in RELEASE mode, should we 
still retain ASSERT ? I think NO.

If we choose to simply modify UhciConvertPollRate() as stated, then we can have 
the status quo in UhciCreateQh() and UhciCreateAsyncReq().


Best Regards,
Hao Wu


>
> +  }
>
> +
>
>//
>
>// Find the index (1 based) of the highest non-zero bit
>
>//
>
> --
> 2.34.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107729): https://edk2.groups.io/g/devel/message/107729
Mute This Topic: https://groups.io/mt/100212109/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts

2023-08-10 Thread Wu, Hao A
My personal preference is to do this as two steps.
Address the issue in XhciDxe first. Then add new TimerLib API to replace all 
driver/library internal implementations.

Best Regards,
Hao Wu

> -Original Message-
> From: Henz, Patrick 
> Sent: Friday, August 11, 2023 6:45 AM
> To: devel@edk2.groups.io; Wu, Hao A ; Michael Brown
> 
> Subject: RE: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance
> Timer for XHCI Timeouts
> 
> I can certainly make that change.
> 
> For what it's worth I have been working on adding the new function,
> GetElapsedTicks, to the various implementations of TimerLib. I've finished up
> testing, I would just need to clean up the commits for a patch. Should I move
> forward with that, or would we rather I just add XhcGetElapsedTime to
> XhciDxe for the time being?
> 
> Thanks,
> Patrick Henz
> 
> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Wu, Hao
> A
> Sent: Sunday, July 30, 2023 9:57 PM
> To: devel@edk2.groups.io; Henz, Patrick ; Michael
> Brown 
> Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance
> Timer for XHCI Timeouts
> 
> For the 2 occurrences of in XhcWaitOpRegBit & XhcExecTransfer:
>   TimeoutTime = XHC_MICROSECOND_TO_NANOSECOND (Timeout *
> XHC_1_MILLISECOND); How about changing them to:
>   TimeoutTime = XHC_MICROSECOND_TO_NANOSECOND ((UINT64) Timeout
> * XHC_1_MILLISECOND); to address possible overflow during "Timeout *
> XHC_1_MILLISECOND"?
> 
> For extending XhcGetElapsedTime as a TimerLib API, I am fine to put it in
> XhciDxe at this moment.
> If package maintainers suggest to make it as a public library API, my take is
> that this should be done in a separate commit.
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: devel@edk2.groups.io  On Behalf Of Henz,
> > Patrick
> > Sent: Thursday, July 6, 2023 4:16 AM
> > To: devel@edk2.groups.io
> > Cc: Henz, Patrick 
> > Subject: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance
> > Timer for XHCI Timeouts
> >
> > REF:https://urldefense.com/v3/__https://bugzilla.tianocore.org/show_bu
> > g.cgi?id=2948__;!!NpxR!kyFQM5IkKYAG9CRBO4xphwBnzi_jhb2oU-
> NKbMjOV-lctg5
> > _B3K1Lcta452Gx-1twRt8At3cueAYDq_n$
> >
> > XhciDxe uses the timer functionality provided by the boot services
> > table to detect timeout conditions. This breaks the driver's
> > ExitBootServices call back, as CoreExitBootServices halts the timer
> > before signaling the ExitBootServices event. If the host controller
> > fails to halt in the call back, the timeout condition will never occur
> > and the boot gets stuck in an indefinite spin loop. Use the free
> > running timer provided by TimerLib to calculate timeouts, avoiding the
> > potential hang.
> >
> > Signed-off-by: Patrick Henz 
> > Reviewed-by:
> > ---
> >  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c  | 56 +++
> >  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h  | 22 
> >  MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf |  2 +
> >  MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c   | 67 +--
> >  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 68
> > +---
> >  5 files changed, 129 insertions(+), 86 deletions(-)
> >
> > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > index 62682dd27c..1dcbe20512 100644
> > --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > @@ -1,6 +1,7 @@
> >  /** @file
> >
> >The XHCI controller driver.
> >
> >
> >
> > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> >
> >  Copyright (c) 2011 - 2022, Intel Corporation. All rights
> > reserved.
> >
> >  SPDX-License-Identifier: BSD-2-Clause-Patent
> >
> >
> >
> > @@ -2294,3 +2295,58 @@ XhcDriverBindingStop (
> >
> >
> >return EFI_SUCCESS;
> >
> >  }
> >
> > +
> >
> > +/**
> >
> > +  Computes and returns the elapsed time in nanoseconds since
> >
> > +  PreviousTick. The value of PreviousTick is overwritten with the
> >
> > +  current performance counter value.
> >
> > +
> >
> > +  @param  PreviousTickPointer to PreviousTick count.
> >
> > +  @return The elapsed time in nanoseconds since PreviousCount.
> >
> > +  PreviousCount is overwritten with the current performance
> >
> > +  counter value.
> >
> > +**/
> >
> > +UINT64
> >
> > +

Re: [edk2-devel] [PATCH v1 2/2] MdeModulePkg/Bus/Pci/UhciDxe: Fix FORWARD_NULL Coverity issues

2023-08-09 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: Ranbir Singh 
> Sent: Monday, July 17, 2023 7:39 PM
> To: devel@edk2.groups.io; rsi...@ventanamicro.com
> Cc: Wu, Hao A ; Ni, Ray ; Veeresh
> Sangolli 
> Subject: [PATCH v1 2/2] MdeModulePkg/Bus/Pci/UhciDxe: Fix
> FORWARD_NULL Coverity issues
> 
> From: Ranbir Singh 
> 
> The function UsbHcGetPciAddressForHostMem has
> 
>   ASSERT ((Block != NULL)); and
> 
> and the function UsbHcFreeMem has
> 
>   ASSERT (Block != NULL);
> 
> statement after for loop, but these are applicable only in DEBUG mode.
> In RELEASE mode, if for whatever reasons there is no match inside for
> loop and the loop exits because of Block != NULL; condition, then there
> is no "Block" NULL pointer check afterwards and the code proceeds to do
> dereferencing "Block" which will lead to CRASH.
> 
> Hence, for safety add NULL pointer checks always.
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4211
> 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Co-authored-by: Veeresh Sangolli 
> Signed-off-by: Ranbir Singh 
> Signed-off-by: Ranbir Singh 
> ---
>  MdeModulePkg/Bus/Pci/UhciDxe/UsbHcMem.c | 9 +
>  1 file changed, 9 insertions(+)
> 
> diff --git a/MdeModulePkg/Bus/Pci/UhciDxe/UsbHcMem.c
> b/MdeModulePkg/Bus/Pci/UhciDxe/UsbHcMem.c
> index c3d46f60bed5..3794f888e132 100644
> --- a/MdeModulePkg/Bus/Pci/UhciDxe/UsbHcMem.c
> +++ b/MdeModulePkg/Bus/Pci/UhciDxe/UsbHcMem.c
> @@ -250,6 +250,11 @@ UsbHcGetPciAddressForHostMem (
>}
> 
> 
> 
>ASSERT ((Block != NULL));
> 
> +
> 
> +  if (Block == NULL) {
> 
> +return 0;
> 
> +  }
> 
> +
> 
>//
> 
>// calculate the pci memory address for host memory address.
> 
>//
> 
> @@ -536,6 +541,10 @@ UsbHcFreeMem (
>//
> 
>ASSERT (Block != NULL);
> 
> 
> 
> +  if (Block == NULL) {
> 
> +return;
> 
> +  }
> 
> +
> 
>//
> 
>// Release the current memory block if it is empty and not the head
> 
>//
> 
> --
> 2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107680): https://edk2.groups.io/g/devel/message/107680
Mute This Topic: https://groups.io/mt/100212110/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v1 1/2] MdeModulePkg/Bus/Pci/UhciDxe: Fix BAD_SHIFT Coverity issue

2023-08-09 Thread Wu, Hao A
> -Original Message-
> From: Ranbir Singh 
> Sent: Monday, July 17, 2023 7:39 PM
> To: devel@edk2.groups.io; rsi...@ventanamicro.com
> Cc: Wu, Hao A ; Ni, Ray ; Veeresh
> Sangolli 
> Subject: [PATCH v1 1/2] MdeModulePkg/Bus/Pci/UhciDxe: Fix BAD_SHIFT
> Coverity issue
> 
> From: Ranbir Singh 
> 
> The function UhciConvertPollRate has a check
> 
> ASSERT (Interval != 0);
> 
> but this comes into play only in DEBUG mode. In Release mode, there is
> no handling if the Interval parameter value is ZERO. To avoid shifting
> by a negative amount later in the code flow in this undesirable case,
> it is better to handle it as well by simply returning ZERO.
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4211
> 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Co-authored-by: Veeresh Sangolli 
> Signed-off-by: Ranbir Singh 
> Signed-off-by: Ranbir Singh 
> ---
>  MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c
> b/MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c
> index c08f9496969b..8ddef4b68ccf 100644
> --- a/MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c
> +++ b/MdeModulePkg/Bus/Pci/UhciDxe/UhciSched.c
> @@ -214,6 +214,10 @@ UhciConvertPollRate (
> 
> 
>ASSERT (Interval != 0);
> 
> 
> 
> +  if (Interval == 0) {
> 
> +return 0;


Return 0 will cause further issues within UhciLinkQhToFrameList() &
UhciUnlinkQhFromFrameList() where the returned value is being used in the below
'for' statement:

for (Index = 0; Index < UHCI_FRAME_NUM; Index += Qh->Interval) {

My thought is to return 1 (i.e. 1 << 0) as if the minimum allowed value for
'Interval' (which is 1) is being passed into this UhciConvertPollRate function.

Best Regards,
Hao Wu


> 
> +  }
> 
> +
> 
>//
> 
>// Find the index (1 based) of the highest non-zero bit
> 
>//
> 
> --
> 2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107678): https://edk2.groups.io/g/devel/message/107678
Mute This Topic: https://groups.io/mt/100212109/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 1/1] MdeModulePkg/Bus/Ata/AtaBusDxe: Fix SIGN_EXTENSION Coverity issue

2023-08-09 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: Ranbir Singh 
> Sent: Monday, July 17, 2023 7:59 PM
> To: devel@edk2.groups.io; rsi...@ventanamicro.com
> Cc: Wu, Hao A ; Ni, Ray 
> Subject: [PATCH v2 1/1] MdeModulePkg/Bus/Ata/AtaBusDxe: Fix
> SIGN_EXTENSION Coverity issue
> 
> From: Ranbir Singh 
> 
> Line number 365 does contain a typecast with UINT32, but it is after all the
> operations (16-bit left shift followed by OR'ing) are over.
> To avoid any SIGN_EXTENSION, typecast the intermediate result after 16-bit
> left shift operation immediately with UINT32.
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4209
> 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Signed-off-by: Ranbir Singh 
> Signed-off-by: Ranbir Singh 
> ---
>  MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c
> b/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c
> index a77852bae054..57aefa04c215 100644
> --- a/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c
> +++ b/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c
> @@ -362,7 +362,7 @@ IdentifyAtaDevice (
>  // Check logical block size // if ((PhyLogicSectorSupport & 
> BIT12) != 0) {-
> BlockMedia->BlockSize = (UINT32)(((IdentifyData->logic_sector_size_hi << 16)
> | IdentifyData->logic_sector_size_lo) * sizeof (UINT16));+  BlockMedia-
> >BlockSize = (UINT32)(((UINT32)(IdentifyData->logic_sector_size_hi << 16) |
> IdentifyData->logic_sector_size_lo) * sizeof (UINT16)); }  AtaDevice-
> >BlockIo.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION2;--
> 2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107677): https://edk2.groups.io/g/devel/message/107677
Mute This Topic: https://groups.io/mt/100212118/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v1 1/1] MdeModulePkg/Bus/Pci/NvmExpressPei: Fix DEADCODE Coverity issue

2023-08-09 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: Ranbir Singh 
> Sent: Monday, July 17, 2023 7:40 PM
> To: devel@edk2.groups.io; rsi...@ventanamicro.com
> Cc: Wu, Hao A ; Ni, Ray ; Veeresh
> Sangolli 
> Subject: [PATCH v1 1/1] MdeModulePkg/Bus/Pci/NvmExpressPei: Fix
> DEADCODE Coverity issue
> 
> From: Ranbir Singh 
> 
> The code can reach line 65 only through the else path above at line 53.
> The else path already has the same NULL check at line 55 and hence the
> duplicate code lines are totally redundant which can be deleted.
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4220
> 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Co-authored-by: Veeresh Sangolli 
> Signed-off-by: Ranbir Singh 
> Signed-off-by: Ranbir Singh 
> ---
>  MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiS3.c | 4 
>  1 file changed, 4 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiS3.c
> b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiS3.c
> index d704c62eaab3..1d03d4964025 100644
> --- a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiS3.c
> +++ b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiS3.c
> @@ -62,10 +62,6 @@ NvmeS3SkipThisController (
>  }   } -  if (S3InitDevices == NULL) {-return Skip;-  }-   //   // 
> Only need to
> initialize the controllers that exist in the device list.   //--
> 2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107679): https://edk2.groups.io/g/devel/message/107679
Mute This Topic: https://groups.io/mt/100212115/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v4 0/2] MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix

2023-08-01 Thread Wu, Hao A
Series pushed via:
PR - https://github.com/tianocore/edk2/pull/4707
Commits:
https://github.com/tianocore/edk2/commit/c7c1170a4568ecc0f63e14ca6a844d40f47519a9
https://github.com/tianocore/edk2/commit/d11968fcc56cbbffef7d906048b00faea9415447

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Ranbir
> Singh
> Sent: Monday, July 17, 2023 12:25 PM
> To: devel@edk2.groups.io; rsi...@ventanamicro.com
> Subject: [edk2-devel] [PATCH v4 0/2]
> MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix
> 
> v3 -> v4:
>   - [Patch 2] Further update as per review comments
>   - Status storage removal at call point
>   - Error checks moved inside SetDriveParameters function
> 
> v2 -> v3:
>   - [Patch 2] Update as per review comments
> 
> v1 -> v2:
>   - Retain outer cast
>   - Add error check instead of Status storage removal
> 
> Ranbir Singh (2):
>   MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix SIGN_EXTENSION Coverity
> issue
>   MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix UNUSED_VALUE Coverity
> issue
> 
>  MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c |  2 +-
>  MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c  | 12
> ++--
>  2 files changed, 11 insertions(+), 3 deletions(-)
> 
> --
> 2.34.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107442): https://edk2.groups.io/g/devel/message/107442
Mute This Topic: https://groups.io/mt/100212103/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 1/1] MdeModulePkg: UsbBusDxe: Rebuild Descriptor Table

2023-07-31 Thread Wu, Hao A
> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of
> brit.chesley via groups.io
> Sent: Saturday, July 8, 2023 1:07 AM
> To: devel@edk2.groups.io
> Cc: Wang, Jian J ; Gao, Liming
> ; Wu, Hao A ; Ni, Ray
> ; Abner Chang 
> Subject: [edk2-devel] [PATCH v2 1/1] MdeModulePkg: UsbBusDxe: Rebuild
> Descriptor Table
> 
> From: Britton Chesley 
> 
> Fixed a bug which led to an ASSERT due to the USB device context being
> maintained after a port reset, but the underlying XHCI context was
> uninitialized. Specifically, Xhc->UsbDevContext is freed after a reset
> and only re-allocates the default [0] enpoint transfer ring. Added build


Really sorry for another question.

My take is that the transfer ring of other endpoints (besides the Default
Control Endpoint) will be re-initialized by the below flow:
UsbSetConfig -> UsbCtrlRequest (USB_REQ_SET_CONFIG) ->
XhcSetConfigCmd(64) -> XhcInitializeEndpointContext(64)

Could you help to elaborate a bit more on what is the issue with the above
(current) flow and why rebuilding the Descriptor Table before UsbSetConfig can
resolve it?

Thanks in advance.

Best Regards,
Hao Wu


> descriptor table call in UsbIoPortReset. BZ 4456
> 
> Cc: Jian J Wang 
> Cc: Liming Gao 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Cc: Abner Chang 
> Signed-off-by: Britton Chesley 
> ---
>  MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c | 26
> -
>  1 file changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> index c25f3cc2f279..a5b798bd8d6c 100644
> --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> @@ -821,6 +821,7 @@ UsbIoPortReset (
>EFI_TPLOldTpl;
>EFI_STATUS Status;
>UINT8  DevAddress;
> +  UINT8  Config;
> 
>OldTpl = gBS->RaiseTPL (USB_BUS_TPL);
> 
> @@ -882,8 +883,26 @@ UsbIoPortReset (
>// is in CONFIGURED state.
>//
>if (Dev->ActiveConfig != NULL) {
> -Status = UsbSetConfig (Dev, Dev->ActiveConfig->Desc.ConfigurationValue);
> +UsbFreeDevDesc (Dev->DevDesc);
> 
> +Status = UsbRemoveConfig (Dev);
> +if (EFI_ERROR (Status)) {
> +  DEBUG ((DEBUG_ERROR, "UsbIoPortReset: Failed to remove
> configuration - %r\n", Status));
> +}
> +
> +Status = UsbGetMaxPacketSize0 (Dev);
> +if (EFI_ERROR (Status)) {
> +  DEBUG ((DEBUG_ERROR, "UsbIoPortReset: Failed to get max packet size -
>  %r\n", Status));
> +}
> +
> +Status = UsbBuildDescTable (Dev);
> +if (EFI_ERROR (Status)) {
> +  DEBUG ((DEBUG_ERROR, "UsbIoPortReset: Failed to build descriptor
> table - %r\n", Status));
> +}
> +
> +Config = Dev->DevDesc->Configs[0]->Desc.ConfigurationValue;
> +
> +Status = UsbSetConfig (Dev, Config);
>  if (EFI_ERROR (Status)) {
>DEBUG ((
>  DEBUG_ERROR,
> @@ -892,6 +911,11 @@ UsbIoPortReset (
>  Status
>  ));
>  }
> +
> +Status = UsbSelectConfig (Dev, Config);
> +if (EFI_ERROR (Status)) {
> +  DEBUG ((DEBUG_ERROR, "UsbIoPortReset: Failed to set configuration -
>  %r\n", Status));
> +}
>}
> 
>  ON_EXIT:
> --
> 2.36.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107396): https://edk2.groups.io/g/devel/message/107396
Mute This Topic: https://groups.io/mt/100010162/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts

2023-07-30 Thread Wu, Hao A
For the 2 occurrences of in XhcWaitOpRegBit & XhcExecTransfer:
  TimeoutTime = XHC_MICROSECOND_TO_NANOSECOND (Timeout * XHC_1_MILLISECOND);
How about changing them to:
  TimeoutTime = XHC_MICROSECOND_TO_NANOSECOND ((UINT64) Timeout * 
XHC_1_MILLISECOND);
to address possible overflow during "Timeout * XHC_1_MILLISECOND"?

For extending XhcGetElapsedTime as a TimerLib API, I am fine to put it in 
XhciDxe at this moment.
If package maintainers suggest to make it as a public library API, my take is 
that this should be done in a separate commit.

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Henz,
> Patrick
> Sent: Thursday, July 6, 2023 4:16 AM
> To: devel@edk2.groups.io
> Cc: Henz, Patrick 
> Subject: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance
> Timer for XHCI Timeouts
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2948
> 
> XhciDxe uses the timer functionality provided by the
> boot services table to detect timeout conditions. This
> breaks the driver's ExitBootServices call back, as
> CoreExitBootServices halts the timer before signaling
> the ExitBootServices event. If the host controller
> fails to halt in the call back, the timeout condition
> will never occur and the boot gets stuck in an indefinite
> spin loop. Use the free running timer provided by
> TimerLib to calculate timeouts, avoiding the potential
> hang.
> 
> Signed-off-by: Patrick Henz 
> Reviewed-by:
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c  | 56 +++
>  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h  | 22 
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf |  2 +
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c   | 67 +--
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 68 +---
>  5 files changed, 129 insertions(+), 86 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> index 62682dd27c..1dcbe20512 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> @@ -1,6 +1,7 @@
>  /** @file
> 
>The XHCI controller driver.
> 
> 
> 
> +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> 
>  Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.
> 
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> 
> 
> @@ -2294,3 +2295,58 @@ XhcDriverBindingStop (
> 
> 
>return EFI_SUCCESS;
> 
>  }
> 
> +
> 
> +/**
> 
> +  Computes and returns the elapsed time in nanoseconds since
> 
> +  PreviousTick. The value of PreviousTick is overwritten with the
> 
> +  current performance counter value.
> 
> +
> 
> +  @param  PreviousTickPointer to PreviousTick count.
> 
> +  @return The elapsed time in nanoseconds since PreviousCount.
> 
> +  PreviousCount is overwritten with the current performance
> 
> +  counter value.
> 
> +**/
> 
> +UINT64
> 
> +XhcGetElapsedTime (
> 
> +  IN OUT UINT64  *PreviousTick
> 
> +  )
> 
> +{
> 
> +  UINT64  StartValue;
> 
> +  UINT64  EndValue;
> 
> +  UINT64  CurrentTick;
> 
> +  UINT64  Delta;
> 
> +
> 
> +  GetPerformanceCounterProperties (, );
> 
> +
> 
> +  CurrentTick = GetPerformanceCounter ();
> 
> +
> 
> +  //
> 
> +  // Determine if the counter is counting up or down
> 
> +  //
> 
> +  if (StartValue < EndValue) {
> 
> +//
> 
> +// Counter counts upwards, check for an overflow condition
> 
> +//
> 
> +if (*PreviousTick > CurrentTick) {
> 
> +  Delta = (EndValue - *PreviousTick) + CurrentTick;
> 
> +} else {
> 
> +  Delta = CurrentTick - *PreviousTick;
> 
> +}
> 
> +  } else {
> 
> +//
> 
> +// Counter counts downwards, check for an underflow condition
> 
> +//
> 
> +if (*PreviousTick < CurrentTick) {
> 
> +  Delta = (StartValue - CurrentTick) + *PreviousTick;
> 
> +} else {
> 
> +  Delta = *PreviousTick - CurrentTick;
> 
> +}
> 
> +  }
> 
> +
> 
> +  //
> 
> +  // Set PreviousTick to CurrentTick
> 
> +  //
> 
> +  *PreviousTick = CurrentTick;
> 
> +
> 
> +  return GetTimeInNanoSecond (Delta);
> 
> +}
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h
> b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h
> index ca223bd20c..77feb66647 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h
> @@ -2,6 +2,7 @@
> 
> 
>Provides some data structure definitions used by the XHCI host controller
> driver.
> 
> 
> 
> +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> 
>  Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.
> 
>  Copyright (c) Microsoft Corporation.
> 
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> @@ -26,6 +27,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>  #include 
> 
>  #include 
> 
>  #include 
> 
> +#include 
> 
> 
> 
>  #include 
> 
> 
> 
> @@ -37,6 +39,10 @@ typedef struct _USB_DEV_CONTEXT
> USB_DEV_CONTEXT;
>  #include "ComponentName.h"
> 
>  #include "UsbHcMem.h"
> 
> 
> 
> +//
> 
> +// Converts a count from 

Re: [edk2-devel] [PATCH v4 2/2] MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix UNUSED_VALUE Coverity issue

2023-07-30 Thread Wu, Hao A
> -Original Message-
> From: Ranbir Singh 
> Sent: Monday, July 17, 2023 12:25 PM
> To: devel@edk2.groups.io; rsi...@ventanamicro.com
> Cc: Wu, Hao A ; Ni, Ray 
> Subject: [PATCH v4 2/2] MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix
> UNUSED_VALUE Coverity issue
> 
> From: Ranbir Singh 
> 
> The return value stored in Status after call to SetDriveParameters
> is not made of any use thereafter and hence it remains as UNUSED.
> 
> Based on Hao's findings (https://edk2.groups.io/g/devel/message/106844),
> the successful execution of SetDriveParameters() is not mandatory for
> initializing IDE mode of a hard disk device. Hence remove the 'Status'
> assignment of the return value from SetDriveParameters() and instead add
> error checks & DEBUG_WARN level messages within SetDriveParameters()
> function after sending INIT_DRIVE_PARAM & SET_MULTIPLE_MODE ATA
> commands.


Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu


> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4204
> 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Signed-off-by: Ranbir Singh 
> Signed-off-by: Ranbir Singh 
> ---
>  MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c | 12 ++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> index 75403886e44a..19d7b4930cb7 100644
> --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> @@ -1992,6 +1992,10 @@ SetDriveParameters (
>   NULL
> 
>   );
> 
> 
> 
> +  if (EFI_ERROR (Status)) {
> 
> +DEBUG ((DEBUG_WARN, "Init Drive Parameters Fail, Status = %r\n",
> Status));
> 
> +  }
> 
> +
> 
>//
> 
>// Send Set Multiple parameters
> 
>//
> 
> @@ -2008,6 +2012,10 @@ SetDriveParameters (
>   NULL
> 
>   );
> 
> 
> 
> +  if (EFI_ERROR (Status)) {
> 
> +DEBUG ((DEBUG_WARN, "Set Multiple Mode Parameters Fail, Status
> = %r\n", Status));
> 
> +  }
> 
> +
> 
>return Status;
> 
>  }
> 
> 
> 
> @@ -2549,13 +2557,13 @@ DetectAndConfigIdeDevice (
>  //
> 
>  if (DeviceType == EfiIdeHarddisk) {
> 
>//
> 
> -  // Init driver parameters
> 
> +  // Init drive parameters
> 
>//
> 
>DriveParameters.Sector = (UINT8)((ATA5_IDENTIFY_DATA
> *)())->sectors_per_track;
> 
>DriveParameters.Heads  = (UINT8)(((ATA5_IDENTIFY_DATA
> *)())->heads - 1);
> 
>DriveParameters.MultipleSector = (UINT8)((ATA5_IDENTIFY_DATA
> *)())->multi_sector_cmd_max_sct_cnt;
> 
> 
> 
> -  Status = SetDriveParameters (Instance, IdeChannel, IdeDevice,
> , NULL);
> 
> +  SetDriveParameters (Instance, IdeChannel, IdeDevice, ,
> NULL);
> 
>  }
> 
> 
> 
>  //
> 
> --
> 2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107388): https://edk2.groups.io/g/devel/message/107388
Mute This Topic: https://groups.io/mt/100212105/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] empty USB DVD disk hang Xhci

2023-07-24 Thread Wu, Hao A
Sorry, I do not have much resource to review this in detail. But the patch 
generally looks good to me:
Acked-by: Hao A Wu hao.a...@intel.com<mailto:hao.a...@intel.com>

However, I hope the below question can be answered (or add related information 
to the commit log message) before mering:
Likun, could you help to elaborate a bit more on why the below statement will 
return NULL pointer for “USB DVD with empty disk”?
EPRing= (TRANSFER_RING 
*)(UINTN)Xhc->UsbDevContext[SlotId].EndpointTransferRing[Dci-1];


Best Regards,
Hao Wu

From: gaoliming 
Sent: Tuesday, July 25, 2023 9:44 AM
To: devel@edk2.groups.io; suli...@loongson.cn; Demeter, Miki 

Cc: Wu, Hao A 
Subject: 回复: [edk2-devel] empty USB DVD disk hang Xhci

Likun:
 This change is good to me.  Reviewed-by: Liming Gao 
mailto:gaolim...@byosoft.com.cn>>

Hao:
 Have you time to review this fix?

Thanks
Liming
发件人: devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
mailto:devel@edk2.groups.io>> 代表 苏丽坤
发送时间: 2023年7月18日 9:49
收件人: gaolim...@byosoft.com.cn<mailto:gaolim...@byosoft.com.cn>; 
miki.deme...@intel.com<mailto:miki.deme...@intel.com>; 
devel@edk2.groups.io<mailto:devel@edk2.groups.io>
主题: [edk2-devel] empty USB DVD disk hang Xhci


Hi

We find a bug in xhci, USB DVD boot with emtpy disk will hang Xhci while 
Ehci can pass.

The hang log is shown as : MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c(1847): 
TrsRing != ((void *) 0)

We suggest a way to solve this bug is shown as: 
https://github.com/suling-123/edk2 the latest commit,   MdeModulePkg: Solve 
boot hang xhci driver when use USB DVD with empty disk, 
950bc8781d81b96b0c7944e7ac947382b1bc0c06

[cid:image001.png@01D9BEE1.61EECFA0]


本邮件及其附件含有龙芯中科的商业秘密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制或散发)本邮件及其附件中的信息。如果您错收本邮件,请您立即电话或邮件通知发件人并删除本邮件。
This email and its attachments contain confidential information from Loongson 
Technology , which is intended only for the person or entity whose address is 
listed above. Any use of the information contained herein in any way 
(including, but not limited to, total or partial disclosure, reproduction or 
dissemination) by persons other than the intended recipient(s) is prohibited. 
If you receive this email in error, please notify the sender by phone or email 
immediately and delete it.


本邮件及其附件含有龙芯中科的商业秘密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制或散发)本邮件及其附件中的信息。如果您错收本邮件,请您立即电话或邮件通知发件人并删除本邮件。
This email and its attachments contain confidential information from Loongson 
Technology , which is intended only for the person or entity whose address is 
listed above. Any use of the information contained herein in any way 
(including, but not limited to, total or partial disclosure, reproduction or 
dissemination) by persons other than the intended recipient(s) is prohibited. 
If you receive this email in error, please notify the sender by phone or email 
immediately and delete it.



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107215): https://edk2.groups.io/g/devel/message/107215
Mute This Topic: https://groups.io/mt/100343121/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH 1/1] MdeModulePkg/Bus/Pci/EhciDxe: Fix FORWARD_NULL Coverity issues

2023-07-16 Thread Wu, Hao A
Merged via:
PR - https://github.com/tianocore/edk2/pull/4648
Commit - 
https://github.com/tianocore/edk2/commit/dd49d448b0815c65847241a3faa957e3b4605001

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Wu, Hao A
> Sent: Wednesday, July 12, 2023 12:49 PM
> To: Ranbir Singh ; devel@edk2.groups.io
> Cc: Ni, Ray 
> Subject: Re: [edk2-devel] [PATCH 1/1] MdeModulePkg/Bus/Pci/EhciDxe: Fix
> FORWARD_NULL Coverity issues
> 
> Reviewed-by: Hao A Wu 
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: Ranbir Singh 
> > Sent: Monday, July 3, 2023 7:44 PM
> > To: devel@edk2.groups.io; rsi...@ventanamicro.com
> > Cc: Wu, Hao A ; Ni, Ray 
> > Subject: [PATCH 1/1] MdeModulePkg/Bus/Pci/EhciDxe: Fix FORWARD_NULL
> > Coverity issues
> >
> > From: Ranbir Singh 
> >
> > The function UsbHcGetPciAddressForHostMem has
> >
> > ASSERT ((Block != NULL));
> >
> > and the UsbHcFreeMem has
> >
> > ASSERT (Block != NULL);
> >
> > statement after for loop, but these are applicable only in DEBUG mode.
> > In RELEASE mode, if for whatever reasons there is no match inside the
> > for loop and the loop exits because of Block != NULL; condition, then
> > there is no "Block" NULL pointer check afterwards and the code
> > proceeds to do dereferencing "Block" which will lead to CRASH.
> >
> > Hence, for safety add NULL pointer checks always.
> >
> > Cc: Hao A Wu 
> > Cc: Ray Ni 
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4210
> > Signed-off-by: Ranbir Singh 
> > Signed-off-by: Ranbir Singh 
> > ---
> >  MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c | 9 +
> >  1 file changed, 9 insertions(+)
> >
> > diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c
> > b/MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c
> > index 0a3ceb9f711a..79575b6f6304 100644
> > --- a/MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c
> > +++ b/MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c
> > @@ -250,6 +250,11 @@ UsbHcGetPciAddressForHostMem (
> >}
> >
> >
> >
> >ASSERT ((Block != NULL));
> >
> > +
> >
> > +  if (Block == NULL) {
> >
> > +return 0;
> >
> > +  }
> >
> > +
> >
> >//
> >
> >// calculate the pci memory address for host memory address.
> >
> >//
> >
> > @@ -536,6 +541,10 @@ UsbHcFreeMem (
> >//
> >
> >ASSERT (Block != NULL);
> >
> >
> >
> > +  if (Block == NULL) {
> >
> > +return;
> >
> > +  }
> >
> > +
> >
> >//
> >
> >// Release the current memory block if it is empty and not the head
> >
> >//
> >
> > --
> > 2.34.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#106954): https://edk2.groups.io/g/devel/message/106954
Mute This Topic: https://groups.io/mt/99936708/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v3 2/2] MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix UNUSED_VALUE Coverity issue

2023-07-13 Thread Wu, Hao A
> -Original Message-
> From: Ranbir Singh 
> Sent: Friday, July 14, 2023 12:47 AM
> To: devel@edk2.groups.io; rsi...@ventanamicro.com
> Cc: Wu, Hao A ; Ni, Ray 
> Subject: [PATCH v3 2/2] MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix
> UNUSED_VALUE Coverity issue
> 
> From: Ranbir Singh 
> 
> The return value stored in Status after call to SetDriveParameters is not made
> of any use thereafter and hence it remains as UNUSED.
> 
> Add error check as is done after calls to SetDeviceTransferMode.
> 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4204
> Signed-off-by: Ranbir Singh 
> Signed-off-by: Ranbir Singh 
> ---
>  MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c | 10 +-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> index 75403886e44a..af022139cf02 100644
> --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> @@ -2549,13 +2549,21 @@ DetectAndConfigIdeDevice (
>  //
> 
>  if (DeviceType == EfiIdeHarddisk) {
> 
>//
> 
> -  // Init driver parameters
> 
> +  // Init drive parameters
> 
>//
> 
>DriveParameters.Sector = (UINT8)((ATA5_IDENTIFY_DATA
> *)())->sectors_per_track;
> 
>DriveParameters.Heads  = (UINT8)(((ATA5_IDENTIFY_DATA
> *)())->heads - 1);
> 
>DriveParameters.MultipleSector = (UINT8)((ATA5_IDENTIFY_DATA
> *)())->multi_sector_cmd_max_sct_cnt;
> 
> 
> 
>Status = SetDriveParameters (Instance, IdeChannel, IdeDevice,
> , NULL);
> 
> +
> 
> +  if (EFI_ERROR (Status)) {
> 
> +DEBUG ((DEBUG_WARN, "Set Drive Parameters Fail, Status = %r\n",
> + Status));
> 
> +//
> 
> +// Ignore warning and proceed normally
> 
> +//
> 
> +Status = EFI_SUCCESS;


To please both sides, how about:
1. Remove the 'Status' assignment of the return value from SetDriveParameters()
Based on my findings (https://edk2.groups.io/g/devel/message/106844), the
successful execution of SetDriveParameters() is not mandatory for initializing
IDE mode hard disk device.

2. Add DEBUG_WARN level debug message within SetDriveParameters() function
In function SetDriveParameters, for the 2 calls of AtaNonDataCommandIn (one
for the INITIALIZE DEVICE PARAMETERS command and the other for SET MULTIPLE
MODE command), if the return status is not EFI_SUCCESS, add debug message to
display the information.

Best Regards,
Hao Wu


> 
> +  }
> 
>  }
> 
> 
> 
>  //
> 
> --
> 2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#106930): https://edk2.groups.io/g/devel/message/106930
Mute This Topic: https://groups.io/mt/100124817/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 2/2] MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix UNUSED_VALUE Coverity issue

2023-07-12 Thread Wu, Hao A
It works for me, better to override by:
  Status = EFI_SUCCESS;

Best Regards,
Hao Wu

From: Ranbir Singh 
Sent: Wednesday, July 12, 2023 3:01 PM
To: Wu, Hao A 
Cc: devel@edk2.groups.io; Ni, Ray 
Subject: Re: [PATCH v2 2/2] MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix 
UNUSED_VALUE Coverity issue

Thanks Hao for digging deeper into this.

The if block itself might get knocked off in Release mode when there is only a 
DEBUG statement inside it and hence Coverity might still complain. So, we can 
override the Status value in this scenario inside the if block and then proceed 
normally - let me know if this is acceptable and I will update the patch as 
below then

  if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "Set Drive Parameters Fail, Status = %r\n", 
Status));
/* Ignore Warning and proceed normally */
Status = 0;
  }

Best Regards,
Ranbir Singh

On Wed, Jul 12, 2023 at 10:08 AM Wu, Hao A 
mailto:hao.a...@intel.com>> wrote:
Really sorry,

After referring to the Information Technology - AT Attachment with Packet 
Interface (ATA/ATAPI) Specification,
It seems to me that the commands being executed in function 
SetDriveParameters() are not mandatory during device initialization.

1. INITIALIZE DEVICE PARAMETERS command (ID 0x91h):
This command got obsoleted since ATA/ATAPI-6 spec version.
Also, the return status of SetDriveParameters() is irrelevant with the 
execution result of this command.

2. SET MULTIPLE MODE command (ID 0xC6h):
My take is that this command is necessary if there is subsequent usage of 
command READ MULTIPLE, READ MULTIPLE EXT, WRITE MULTIPLE, or WRITE MULTIPLE EXT.
I do not find usage of the above 4 commands within edk2, so I think the 
successful execution of SET MULTIPLE MODE command is not mandatory for 
detecting hard disk device.

Based on the above findings, could you help to update the patch to:
  Status = SetDriveParameters (Instance, IdeChannel, IdeDevice, 
, NULL);

  if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "Set Drive Parameters Fail, Status = %r\n", 
Status));
  }

Will doing so still please Coverity?

Best Regards,
Hao Wu

> -Original Message-
> From: Ranbir Singh mailto:rsi...@ventanamicro.com>>
> Sent: Friday, June 9, 2023 8:33 PM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; 
> rsi...@ventanamicro.com<mailto:rsi...@ventanamicro.com>
> Cc: Wu, Hao A mailto:hao.a...@intel.com>>; Ni, Ray 
> mailto:ray...@intel.com>>
> Subject: [PATCH v2 2/2] MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix
> UNUSED_VALUE Coverity issue
>
> From: Ranbir Singh mailto:ranbir.sin...@dell.com>>
>
> The return value stored in Status after call to SetDriveParameters
> is not made of any use thereafter and hence it remains as UNUSED.
>
> Add error check as is done after calls to SetDeviceTransferMode.
>
> Cc: Hao A Wu mailto:hao.a...@intel.com>>
> Cc: Ray Ni mailto:ray...@intel.com>>
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4204
> Signed-off-by: Ranbir Singh 
> mailto:ranbir.sin...@dell.com>>
> Signed-off-by: Ranbir Singh 
> mailto:rsi...@ventanamicro.com>>
> ---
>
> Notes:
> Add error check instead of Status storage removal
>
>  MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c | 7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> index 75403886e44a..d04b1d95a7f5 100644
> --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> @@ -2549,13 +2549,18 @@ DetectAndConfigIdeDevice (
>  //
>
>  if (DeviceType == EfiIdeHarddisk) {
>
>//
>
> -  // Init driver parameters
>
> +  // Init drive parameters
>
>//
>
>DriveParameters.Sector = (UINT8)((ATA5_IDENTIFY_DATA
> *)())->sectors_per_track;
>
>DriveParameters.Heads  = (UINT8)(((ATA5_IDENTIFY_DATA
> *)())->heads - 1);
>
>DriveParameters.MultipleSector = (UINT8)((ATA5_IDENTIFY_DATA
> *)())->multi_sector_cmd_max_sct_cnt;
>
>
>
>Status = SetDriveParameters (Instance, IdeChannel, IdeDevice,
> , NULL);
>
> +
>
> +  if (EFI_ERROR (Status)) {
>
> +DEBUG ((DEBUG_ERROR, "Set Drive Parameters Fail, Status = %r\n",
> Status));
>
> +continue;
>
> +  }
>
>  }
>
>
>
>  //
>
> --
> 2.34.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#106849): https://edk2.groups.io/g/devel/message/106849
Mute This Topic: https://groups.io/mt/99432080/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH 1/1] MdeModulePkg/Bus/Pci/EhciDxe: Fix FORWARD_NULL Coverity issues

2023-07-11 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: Ranbir Singh 
> Sent: Monday, July 3, 2023 7:44 PM
> To: devel@edk2.groups.io; rsi...@ventanamicro.com
> Cc: Wu, Hao A ; Ni, Ray 
> Subject: [PATCH 1/1] MdeModulePkg/Bus/Pci/EhciDxe: Fix FORWARD_NULL
> Coverity issues
> 
> From: Ranbir Singh 
> 
> The function UsbHcGetPciAddressForHostMem has
> 
> ASSERT ((Block != NULL));
> 
> and the UsbHcFreeMem has
> 
> ASSERT (Block != NULL);
> 
> statement after for loop, but these are applicable only in DEBUG mode.
> In RELEASE mode, if for whatever reasons there is no match inside the
> for loop and the loop exits because of Block != NULL; condition, then
> there is no "Block" NULL pointer check afterwards and the code proceeds
> to do dereferencing "Block" which will lead to CRASH.
> 
> Hence, for safety add NULL pointer checks always.
> 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4210
> Signed-off-by: Ranbir Singh 
> Signed-off-by: Ranbir Singh 
> ---
>  MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c | 9 +
>  1 file changed, 9 insertions(+)
> 
> diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c
> b/MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c
> index 0a3ceb9f711a..79575b6f6304 100644
> --- a/MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c
> +++ b/MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c
> @@ -250,6 +250,11 @@ UsbHcGetPciAddressForHostMem (
>}
> 
> 
> 
>ASSERT ((Block != NULL));
> 
> +
> 
> +  if (Block == NULL) {
> 
> +return 0;
> 
> +  }
> 
> +
> 
>//
> 
>// calculate the pci memory address for host memory address.
> 
>//
> 
> @@ -536,6 +541,10 @@ UsbHcFreeMem (
>//
> 
>ASSERT (Block != NULL);
> 
> 
> 
> +  if (Block == NULL) {
> 
> +return;
> 
> +  }
> 
> +
> 
>//
> 
>// Release the current memory block if it is empty and not the head
> 
>//
> 
> --
> 2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#106846): https://edk2.groups.io/g/devel/message/106846
Mute This Topic: https://groups.io/mt/99936708/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 1/2] MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix SIGN_EXTENSION Coverity issue

2023-07-11 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: Ranbir Singh 
> Sent: Friday, June 9, 2023 8:33 PM
> To: devel@edk2.groups.io; rsi...@ventanamicro.com
> Cc: Wu, Hao A ; Ni, Ray 
> Subject: [PATCH v2 1/2] MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix
> SIGN_EXTENSION Coverity issue
> 
> From: Ranbir Singh 
> 
> Line number 1348 does contain a typecast with UINT32, but it is after
> all the operations (16-bit left shift followed by OR'ing) are over.
> To avoid any SIGN_EXTENSION, typecast the intermediate result after
> 16-bit left shift operation immediately with UINT32.
> 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4204
> Signed-off-by: Ranbir Singh 
> Signed-off-by: Ranbir Singh 
> ---
> 
> Notes:
> Retain outer cast
> 
>  MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c
> b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c
> index 50406fe0270d..f39c909d0631 100644
> --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c
> +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c
> @@ -1345,7 +1345,7 @@ AtaPassThruPassThru (
>  // Check logical block size
> 
>  //
> 
>  if ((IdentifyData->AtaData.phy_logic_sector_support & BIT12) != 0) {
> 
> -  BlockSize = (UINT32)(((IdentifyData->AtaData.logic_sector_size_hi << 
> 16)
> | IdentifyData->AtaData.logic_sector_size_lo) * sizeof (UINT16));
> 
> +  BlockSize = (UINT32)(((UINT32)(IdentifyData-
> >AtaData.logic_sector_size_hi << 16) | IdentifyData-
> >AtaData.logic_sector_size_lo) * sizeof (UINT16));
> 
>  }
> 
>}
> 
> 
> 
> --
> 2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#106845): https://edk2.groups.io/g/devel/message/106845
Mute This Topic: https://groups.io/mt/99432079/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 2/2] MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix UNUSED_VALUE Coverity issue

2023-07-11 Thread Wu, Hao A
Really sorry,

After referring to the Information Technology - AT Attachment with Packet 
Interface (ATA/ATAPI) Specification,
It seems to me that the commands being executed in function 
SetDriveParameters() are not mandatory during device initialization.

1. INITIALIZE DEVICE PARAMETERS command (ID 0x91h):
This command got obsoleted since ATA/ATAPI-6 spec version.
Also, the return status of SetDriveParameters() is irrelevant with the 
execution result of this command.

2. SET MULTIPLE MODE command (ID 0xC6h):
My take is that this command is necessary if there is subsequent usage of 
command READ MULTIPLE, READ MULTIPLE EXT, WRITE MULTIPLE, or WRITE MULTIPLE EXT.
I do not find usage of the above 4 commands within edk2, so I think the 
successful execution of SET MULTIPLE MODE command is not mandatory for 
detecting hard disk device.

Based on the above findings, could you help to update the patch to:
  Status = SetDriveParameters (Instance, IdeChannel, IdeDevice, 
, NULL);

  if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "Set Drive Parameters Fail, Status = %r\n", 
Status));
  }

Will doing so still please Coverity?

Best Regards,
Hao Wu

> -Original Message-
> From: Ranbir Singh 
> Sent: Friday, June 9, 2023 8:33 PM
> To: devel@edk2.groups.io; rsi...@ventanamicro.com
> Cc: Wu, Hao A ; Ni, Ray 
> Subject: [PATCH v2 2/2] MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix
> UNUSED_VALUE Coverity issue
> 
> From: Ranbir Singh 
> 
> The return value stored in Status after call to SetDriveParameters
> is not made of any use thereafter and hence it remains as UNUSED.
> 
> Add error check as is done after calls to SetDeviceTransferMode.
> 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4204
> Signed-off-by: Ranbir Singh 
> Signed-off-by: Ranbir Singh 
> ---
> 
> Notes:
> Add error check instead of Status storage removal
> 
>  MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c | 7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> index 75403886e44a..d04b1d95a7f5 100644
> --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> @@ -2549,13 +2549,18 @@ DetectAndConfigIdeDevice (
>  //
> 
>  if (DeviceType == EfiIdeHarddisk) {
> 
>//
> 
> -  // Init driver parameters
> 
> +  // Init drive parameters
> 
>//
> 
>DriveParameters.Sector = (UINT8)((ATA5_IDENTIFY_DATA
> *)())->sectors_per_track;
> 
>DriveParameters.Heads  = (UINT8)(((ATA5_IDENTIFY_DATA
> *)())->heads - 1);
> 
>DriveParameters.MultipleSector = (UINT8)((ATA5_IDENTIFY_DATA
> *)())->multi_sector_cmd_max_sct_cnt;
> 
> 
> 
>Status = SetDriveParameters (Instance, IdeChannel, IdeDevice,
> , NULL);
> 
> +
> 
> +  if (EFI_ERROR (Status)) {
> 
> +DEBUG ((DEBUG_ERROR, "Set Drive Parameters Fail, Status = %r\n",
> Status));
> 
> +continue;
> 
> +  }
> 
>  }
> 
> 
> 
>  //
> 
> --
> 2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#106844): https://edk2.groups.io/g/devel/message/106844
Mute This Topic: https://groups.io/mt/99432080/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH] Maintainers.txt: Stop to be reviewer of several modules

2023-06-12 Thread Wu, Hao A
Thank you.

Best Regards,
Hao Wu


> -Original Message-
> From: Ni, Ray 
> Sent: Tuesday, June 13, 2023 11:40 AM
> To: Wu, Hao A ; devel@edk2.groups.io
> Cc: Gao, Zhichao ; Liu, Zhiguang
> ; Guo, Gua 
> Subject: RE: [PATCH] Maintainers.txt: Stop to be reviewer of several modules
> 
> Sure.
> I will update the patch to keep my name for disk modules.
> 
> Thanks,
> Ray
> 
> > -Original Message-
> > From: Wu, Hao A 
> > Sent: Tuesday, June 13, 2023 11:05 AM
> > To: Ni, Ray ; devel@edk2.groups.io
> > Cc: Gao, Zhichao ; Liu, Zhiguang
> > ; Guo, Gua 
> > Subject: RE: [PATCH] Maintainers.txt: Stop to be reviewer of several
> > modules
> >
> > > -Original Message-
> > > From: Ni, Ray 
> > > Sent: Tuesday, June 13, 2023 10:07 AM
> > > To: devel@edk2.groups.io
> > > Cc: Gao, Zhichao ; Wu, Hao A
> > > ; Liu, Zhiguang ; Guo,
> > > Gua 
> > > Subject: [PATCH] Maintainers.txt: Stop to be reviewer of several
> > > modules
> > >
> > > Remove my name from reviewer list of following modules:
> > > * MdeModulePkg: Console and Graphics modules
> > > * MdeModulePkg: Disk modules
> >
> >
> > Sorry, could you help to keep the reviewer role for "Disk modules"?
> > For modules like DiskIoDxe and PartitionDxe, your feedback/suggestion
> > is helpful and important since you are experienced for the
> > implementation of these modules.
> >
> > Best Regards,
> > Hao Wu
> >
> >
> > > * MdeModulePkg: Reset modules
> > > * MdeModulePkg: Serial modules
> > > * MdeModulePkg: Universal Payload definitions
> > >
> > > Signed-off-by: Ray Ni 
> > > Cc: Zhichao Gao 
> > > Cc: Hao A Wu 
> > > Cc: Zhiguang Liu 
> > > Cc: Gua Guo 
> > > ---
> > >  Maintainers.txt | 5 -
> > >  1 file changed, 5 deletions(-)
> > >
> > > diff --git a/Maintainers.txt b/Maintainers.txt index
> > > 42e40dced3..ba993b111d 100644
> > > --- a/Maintainers.txt
> > > +++ b/Maintainers.txt
> > > @@ -294,7 +294,6 @@ F: MdeModulePkg/Library/BaseBmpSupportLib/
> > >  F: MdeModulePkg/Library/FrameBufferBltLib/
> > >
> > >  F: MdeModulePkg/Universal/Console/
> > >
> > >  R: Zhichao Gao  [ZhichaoGao]
> > >
> > > -R: Ray Ni  [niruiyu]
> > >
> > >
> > >
> > >  MdeModulePkg: Core services (PEI, DXE and Runtime) modules
> > >
> > >  F: MdeModulePkg/*Mem*/
> > >
> > > @@ -346,7 +345,6 @@ R: Ray Ni  [niruiyu]
> > >  MdeModulePkg: Disk modules
> > >
> > >  F: MdeModulePkg/Universal/Disk/
> > >
> > >  R: Hao A Wu  [hwu25]
> > >
> > > -R: Ray Ni  [niruiyu]
> > >
> > >  R: Zhichao Gao  [ZhichaoGao]
> > >
> > >
> > >
> > >  MdeModulePkg: Firmware Update modules
> > >
> > > @@ -398,12 +396,10 @@ MdeModulePkg: Reset modules
> > >  F: MdeModulePkg/*Reset*/
> > >
> > >  F: MdeModulePkg/Include/*Reset*.h
> > >
> > >  R: Zhichao Gao  [ZhichaoGao]
> > >
> > > -R: Ray Ni  [niruiyu]
> > >
> > >
> > >
> > >  MdeModulePkg: Serial modules
> > >
> > >  F: MdeModulePkg/*Serial*/
> > >
> > >  F: MdeModulePkg/Include/*SerialPort*.h
> > >
> > > -R: Ray Ni  [niruiyu]
> > >
> > >  R: Zhichao Gao  [ZhichaoGao]
> > >
> > >
> > >
> > >  MdeModulePkg: SMBIOS modules
> > >
> > > @@ -426,7 +422,6 @@ R: Liming Gao  [lgao4]
> > >  MdeModulePkg: Universal Payload definitions
> > >
> > >  F: MdeModulePkg/Include/UniversalPayload/
> > >
> > >  R: Zhiguang Liu  [LiuZhiguang001]
> > >
> > > -R: Ray Ni  [niruiyu]
> > >
> > >  R: Gua Guo  [gguo11837463]
> > >
> > >
> > >
> > >  MdeModulePkg: Trace Hub debug message related library instance
> > >
> > > --
> > > 2.37.2.windows.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#106039): https://edk2.groups.io/g/devel/message/106039
Mute This Topic: https://groups.io/mt/99497829/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH] Maintainers.txt: Stop to be reviewer of several modules

2023-06-12 Thread Wu, Hao A
> -Original Message-
> From: Ni, Ray 
> Sent: Tuesday, June 13, 2023 10:07 AM
> To: devel@edk2.groups.io
> Cc: Gao, Zhichao ; Wu, Hao A
> ; Liu, Zhiguang ; Guo, Gua
> 
> Subject: [PATCH] Maintainers.txt: Stop to be reviewer of several modules
> 
> Remove my name from reviewer list of following modules:
> * MdeModulePkg: Console and Graphics modules
> * MdeModulePkg: Disk modules


Sorry, could you help to keep the reviewer role for "Disk modules"?
For modules like DiskIoDxe and PartitionDxe, your feedback/suggestion is 
helpful and important since you are experienced for the implementation of these 
modules.

Best Regards,
Hao Wu


> * MdeModulePkg: Reset modules
> * MdeModulePkg: Serial modules
> * MdeModulePkg: Universal Payload definitions
> 
> Signed-off-by: Ray Ni 
> Cc: Zhichao Gao 
> Cc: Hao A Wu 
> Cc: Zhiguang Liu 
> Cc: Gua Guo 
> ---
>  Maintainers.txt | 5 -
>  1 file changed, 5 deletions(-)
> 
> diff --git a/Maintainers.txt b/Maintainers.txt
> index 42e40dced3..ba993b111d 100644
> --- a/Maintainers.txt
> +++ b/Maintainers.txt
> @@ -294,7 +294,6 @@ F: MdeModulePkg/Library/BaseBmpSupportLib/
>  F: MdeModulePkg/Library/FrameBufferBltLib/
> 
>  F: MdeModulePkg/Universal/Console/
> 
>  R: Zhichao Gao  [ZhichaoGao]
> 
> -R: Ray Ni  [niruiyu]
> 
> 
> 
>  MdeModulePkg: Core services (PEI, DXE and Runtime) modules
> 
>  F: MdeModulePkg/*Mem*/
> 
> @@ -346,7 +345,6 @@ R: Ray Ni  [niruiyu]
>  MdeModulePkg: Disk modules
> 
>  F: MdeModulePkg/Universal/Disk/
> 
>  R: Hao A Wu  [hwu25]
> 
> -R: Ray Ni  [niruiyu]
> 
>  R: Zhichao Gao  [ZhichaoGao]
> 
> 
> 
>  MdeModulePkg: Firmware Update modules
> 
> @@ -398,12 +396,10 @@ MdeModulePkg: Reset modules
>  F: MdeModulePkg/*Reset*/
> 
>  F: MdeModulePkg/Include/*Reset*.h
> 
>  R: Zhichao Gao  [ZhichaoGao]
> 
> -R: Ray Ni  [niruiyu]
> 
> 
> 
>  MdeModulePkg: Serial modules
> 
>  F: MdeModulePkg/*Serial*/
> 
>  F: MdeModulePkg/Include/*SerialPort*.h
> 
> -R: Ray Ni  [niruiyu]
> 
>  R: Zhichao Gao  [ZhichaoGao]
> 
> 
> 
>  MdeModulePkg: SMBIOS modules
> 
> @@ -426,7 +422,6 @@ R: Liming Gao  [lgao4]
>  MdeModulePkg: Universal Payload definitions
> 
>  F: MdeModulePkg/Include/UniversalPayload/
> 
>  R: Zhiguang Liu  [LiuZhiguang001]
> 
> -R: Ray Ni  [niruiyu]
> 
>  R: Gua Guo  [gguo11837463]
> 
> 
> 
>  MdeModulePkg: Trace Hub debug message related library instance
> 
> --
> 2.37.2.windows.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#106037): https://edk2.groups.io/g/devel/message/106037
Mute This Topic: https://groups.io/mt/99497829/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH 2/2] MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix UNUSED_VALUE Coverity issue

2023-06-08 Thread Wu, Hao A
Hello,

Is it possible for you to verify the proposed change on a hard disk working 
under IDE mode to see:
  a) If it can still be successfully recognized;
  b) The SetDriveParameters call has been reached and returns with no error.

My opinion is that the change needs to be tested at least to ensure it will not 
bring issue to previously working devices.

Best Regards,
Hao Wu

From: Ranbir Singh 
Sent: Thursday, June 8, 2023 6:17 PM
To: Wu, Hao A 
Cc: devel@edk2.groups.io; a...@kernel.org; pedro.falc...@gmail.com; Ni, Ray 

Subject: Re: [edk2-devel] [PATCH 2/2] MdeModulePkg/Bus/Ata/AtaAtapiPassThru: 
Fix UNUSED_VALUE Coverity issue

I mentioned similar approach in 
https://bugzilla.tianocore.org/show_bug.cgi?id=4204#c1

Let me know if I should update the patch as Hao proposed -

if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Set drive parameters Fail, Status = %r\n", Status));
continue;
  }

On Thu, Jun 8, 2023 at 12:25 PM Wu, Hao A 
mailto:hao.a...@intel.com>> wrote:
> -Original Message-
> From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
> mailto:devel@edk2.groups.io>> On Behalf Of Ard
> Biesheuvel
> Sent: Monday, June 5, 2023 4:32 PM
> To: Ranbir Singh mailto:rsi...@ventanamicro.com>>
> Cc: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; 
> pedro.falc...@gmail.com<mailto:pedro.falc...@gmail.com>; Wu, Hao A
> mailto:hao.a...@intel.com>>; Ni, Ray 
> mailto:ray...@intel.com>>
> Subject: Re: [edk2-devel] [PATCH 2/2]
> MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix UNUSED_VALUE Coverity
> issue
>
> On Mon, 5 Jun 2023 at 10:10, Ranbir Singh 
> mailto:rsi...@ventanamicro.com>>
> wrote:
> >
> > I counted myself as not the right person to decide what all to do if Status 
> > is
> not successful. Adding the DEBUG statement from the Coverity aspect
> doesn't count as a fix as RELEASE mode behavior remains the same.
> >
> > In the comments / description, I already mentioned - Assuming, this non-
> usage is deliberate, so as such I did not intend to hide anything - and left 
> it in
> the status quo.
> >
> > The patch proposed may not be appropriate, but should now give a
> thinking point to active module developers / owners / maintainers if they
> indeed feel that there is a bug here and it needs to be fixed.
> >
>
> Thanks - I agree that it is a good thing that people are aware of this now.


Judging from the context in DetectAndConfigIdeDevice(), I think a fix can be:

  Status = SetDriveParameters (Instance, IdeChannel, IdeDevice, 
, NULL);
  if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Set drive parameters Fail, Status = %r\n", Status));
continue;
  }

But I do not have the device and platform environment to verify the change.
Really sorry for this. I am not sure on the potential risk of making this 
change without at least some kind of 'no-break' tests.

Best Regards,
Hao Wu


>
> > On Mon, Jun 5, 2023 at 4:33 AM Ard Biesheuvel 
> > mailto:a...@kernel.org>> wrote:
> >>
> >> On Sat, 3 Jun 2023 at 18:04, Pedro Falcato 
> >> mailto:pedro.falc...@gmail.com>>
> wrote:
> >> >
> >> > On Fri, Jun 2, 2023 at 8:42 PM Ranbir Singh 
> >> > mailto:rsi...@ventanamicro.com>>
> wrote:
> >> > >
> >> > > From: Ranbir Singh 
> >> > > mailto:ranbir.sin...@dell.com>>
> >> > >
> >> > > The return value stored in Status after call to SetDriveParameters
> >> > > is not made of any use thereafter and hence it remains as UNUSED.
> >> > > Assuming, this non-usage is deliberate, the storage in Status can be
> >> > > done away with.
> >> > >
> >> > > Cc: Hao A Wu mailto:hao.a...@intel.com>>
> >> > > Cc: Ray Ni mailto:ray...@intel.com>>
> >> > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4204
> >> > > Signed-off-by: Ranbir Singh 
> >> > > mailto:ranbir.sin...@dell.com>>
> >> > > ---
> >> > >  MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c | 2 +-
> >> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> >> > >
> >> > > diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> >> > > index 75403886e44a..c6d637afa989 100644
> >> > > --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> >> > > +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> >> > > @@ -2555,7 +2555,7 @@ DetectAndConfigIdeDevice (
> >> > >DriveParameters.Heads  = (UINT8)(((

Re: [edk2-devel] [PATCH 1/1] MdeModulePkg/Bus/Ata/AtaBusDxe: Fix SIGN_EXTENSION Coverity issue

2023-06-08 Thread Wu, Hao A
> -Original Message-
> From: Ranbir Singh 
> Sent: Saturday, June 3, 2023 12:09 AM
> To: devel@edk2.groups.io; rsi...@ventanamicro.com
> Cc: Wu, Hao A ; Ni, Ray 
> Subject: [PATCH 1/1] MdeModulePkg/Bus/Ata/AtaBusDxe: Fix
> SIGN_EXTENSION Coverity issue
> 
> From: Ranbir Singh 
> 
> Line number 365 does contain a typecast with UINT32, but it is after
> all the operations (16-bit left shift followed by OR'ing) are over.
> To avoid any SIGN_EXTENSION, typecast the intermediate result after
> 16-bit left shift operation immediately with UINT32.
> 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4209
> Signed-off-by: Ranbir Singh 
> ---
>  MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c
> b/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c
> index a77852bae054..ccd4c5f05b59 100644
> --- a/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c
> +++ b/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c
> @@ -362,7 +362,7 @@ IdentifyAtaDevice (
>  // Check logical block size
> 
>  //
> 
>  if ((PhyLogicSectorSupport & BIT12) != 0) {
> 
> -  BlockMedia->BlockSize = (UINT32)(((IdentifyData->logic_sector_size_hi
> << 16) | IdentifyData->logic_sector_size_lo) * sizeof (UINT16));
> 
> +  BlockMedia->BlockSize = (((UINT32)(IdentifyData->logic_sector_size_hi
> << 16) | IdentifyData->logic_sector_size_lo) * sizeof (UINT16));
> 
>  }


This patch seems to have the same issue with the concern raised in 
https://edk2.groups.io/g/devel/topic/99293622.

Best Regards,
Hao Wu


> 
> 
> 
>  AtaDevice->BlockIo.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION2;
> 
> --
> 2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#105919): https://edk2.groups.io/g/devel/message/105919
Mute This Topic: https://groups.io/mt/99293624/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH 2/2] MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix UNUSED_VALUE Coverity issue

2023-06-08 Thread Wu, Hao A
> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Ard
> Biesheuvel
> Sent: Monday, June 5, 2023 4:32 PM
> To: Ranbir Singh 
> Cc: devel@edk2.groups.io; pedro.falc...@gmail.com; Wu, Hao A
> ; Ni, Ray 
> Subject: Re: [edk2-devel] [PATCH 2/2]
> MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix UNUSED_VALUE Coverity
> issue
> 
> On Mon, 5 Jun 2023 at 10:10, Ranbir Singh 
> wrote:
> >
> > I counted myself as not the right person to decide what all to do if Status 
> > is
> not successful. Adding the DEBUG statement from the Coverity aspect
> doesn't count as a fix as RELEASE mode behavior remains the same.
> >
> > In the comments / description, I already mentioned - Assuming, this non-
> usage is deliberate, so as such I did not intend to hide anything - and left 
> it in
> the status quo.
> >
> > The patch proposed may not be appropriate, but should now give a
> thinking point to active module developers / owners / maintainers if they
> indeed feel that there is a bug here and it needs to be fixed.
> >
> 
> Thanks - I agree that it is a good thing that people are aware of this now.


Judging from the context in DetectAndConfigIdeDevice(), I think a fix can be:

  Status = SetDriveParameters (Instance, IdeChannel, IdeDevice, 
, NULL);
  if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Set drive parameters Fail, Status = %r\n", Status));
continue;
  }

But I do not have the device and platform environment to verify the change.
Really sorry for this. I am not sure on the potential risk of making this 
change without at least some kind of 'no-break' tests.

Best Regards,
Hao Wu


> 
> > On Mon, Jun 5, 2023 at 4:33 AM Ard Biesheuvel  wrote:
> >>
> >> On Sat, 3 Jun 2023 at 18:04, Pedro Falcato 
> wrote:
> >> >
> >> > On Fri, Jun 2, 2023 at 8:42 PM Ranbir Singh 
> wrote:
> >> > >
> >> > > From: Ranbir Singh 
> >> > >
> >> > > The return value stored in Status after call to SetDriveParameters
> >> > > is not made of any use thereafter and hence it remains as UNUSED.
> >> > > Assuming, this non-usage is deliberate, the storage in Status can be
> >> > > done away with.
> >> > >
> >> > > Cc: Hao A Wu 
> >> > > Cc: Ray Ni 
> >> > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4204
> >> > > Signed-off-by: Ranbir Singh 
> >> > > ---
> >> > >  MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c | 2 +-
> >> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> >> > >
> >> > > diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> >> > > index 75403886e44a..c6d637afa989 100644
> >> > > --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> >> > > +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
> >> > > @@ -2555,7 +2555,7 @@ DetectAndConfigIdeDevice (
> >> > >DriveParameters.Heads  = (UINT8)(((ATA5_IDENTIFY_DATA
> *)())->heads - 1);
> >> > >DriveParameters.MultipleSector = (UINT8)((ATA5_IDENTIFY_DATA
> *)())->multi_sector_cmd_max_sct_cnt;
> >> > >
> >> > > -  Status = SetDriveParameters (Instance, IdeChannel, IdeDevice,
> , NULL);
> >> > > +  SetDriveParameters (Instance, IdeChannel, IdeDevice,
> , NULL);
> >> >
> >> > I'm /fairly/ sure this is wrong and that you need to use Status.
> >> >
> >>
> >> Yeah, removing the assignment fixes the coverity warning, but now you
> >> are hiding a bug instead of fixing it.
> >>
> >> SetDriveParameters () can apparently fail, and this is being ignored.
> >> At the very least, we should emit a diagnostic here in DEBUG mode to
> >> log this. E.g.,
> >>
> >> DEBUG ((DEBUG_WARN, "%a: SetDriveParameters () failed - %r\n",
> >> __func__, Status));
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#105918): https://edk2.groups.io/g/devel/message/105918
Mute This Topic: https://groups.io/mt/99293623/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v3 1/3] MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis: Add USB RNDIS devices support

2023-06-08 Thread Wu, Hao A
Thanks.

Please help to:
* Update the DSC file in the last commit (patch 3/3 of the series). Patch 1/3 
only adds NetworkCommon & UsbRndis, this will cause build failure in certain 
scenario.
* Add the Bugzilla link information in the commit log message.

With above handled:
Acked-by: Hao A Wu 

Also sorry for a question:
  MdeModulePkg/Bus/Usb/UsbNetwork/NetworkCommon/NetworkCommon.inf
  MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcEcm/UsbCdcEcm.inf
  MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcNcm/UsbCdcNcm.inf
  MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis/UsbRndis.inf
These drivers follow the UEFI Driver Model (install EFI Driver Binding 
Protocol), why they are listed as DXE_DRIVER instead of UEFI_DRIVER in the INF 
files?

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of
> RichardHo [何明忠] via groups.io
> Sent: Thursday, June 8, 2023 11:48 AM
> To: Wu, Hao A ; devel@edk2.groups.io
> Cc: Andrew Fish ; Leif Lindholm
> ; Kinney, Michael D
> ; Michael Kubacki
> ; Liu, Zhiguang ;
> Gao, Liming ; Ni, Ray ; Tinh
> Nguyen ; Rebecca Cran
> ; Tony Lo (�_金松) 
> Subject: Re: [edk2-devel] [PATCH v3 1/3]
> MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis: Add USB RNDIS devices
> support
> 
> Hi Hao Wu,
> 
> I have created it in 2023-05-07.
> https://bugzilla.tianocore.org/show_bug.cgi?id=4451
> 
> Thanks,
> Richard


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#105916): https://edk2.groups.io/g/devel/message/105916
Mute This Topic: https://groups.io/mt/99398816/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in AhciPei PEIM

2023-06-06 Thread Wu, Hao A
Merged via:
PR - https://github.com/tianocore/edk2/pull/4478
Commit - 
https://github.com/tianocore/edk2/commit/67fc78d026490ea4c375eeb19724abb40e7be8f2

Best Regards,
Hao Wu

> -Original Message-
> From: Wu, Hao A
> Sent: Friday, June 2, 2023 11:14 AM
> To: He, Jiangang ; devel@edk2.groups.io; Hsueh,
> Hong-Chih (Neo) 
> Cc: Chang, Abner 
> Subject: RE: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in
> AhciPei PEIM
> 
> Thanks.
> Reviewed-by: Hao A Wu 
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: He, Jiangang 
> > Sent: Wednesday, May 31, 2023 10:49 PM
> > To: Wu, Hao A ; devel@edk2.groups.io; Hsueh,
> Hong-
> > Chih (Neo) 
> > Cc: Chang, Abner 
> > Subject: RE: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier
> > port in AhciPei PEIM
> >
> > [AMD Official Use Only - General]
> >
> > We did crisis recovery and Opal HD password unlock from S3 resume from
> > SATA HD test on two different version of AHCI host controllers.
> >
> > Thanks,
> > Jiangang
> > -Original Message-
> > From: Wu, Hao A 
> > Sent: Tuesday, May 30, 2023 10:30 PM
> > To: devel@edk2.groups.io; Hsueh, Hong-Chih (Neo)  > chih.hs...@amd.com>
> > Cc: He, Jiangang ; Chang, Abner
> > 
> > Subject: RE: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier
> > port in AhciPei PEIM
> >
> > Caution: This message originated from an External Source. Use proper
> > caution when opening attachments, clicking links, or responding.
> >
> >
> > Thanks, the code changes look good to me.
> > May I know what tests have been performed for the patch?
> >
> > Best Regards,
> > Hao Wu
> >
> > > -Original Message-
> > > From: devel@edk2.groups.io  On Behalf Of Neo
> > > Hsueh via groups.io
> > > Sent: Wednesday, May 24, 2023 1:07 AM
> > > To: devel@edk2.groups.io
> > > Cc: jiangang...@amd.com; abner.ch...@amd.com; Neo Hsueh  > > chih.hs...@amd.com>
> > > Subject: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port
> > > in AhciPei PEIM
> > >
> > > If there is no port multiplier, PortMultiplierPort should be
> > > converted to 0 to follow AHCI spec.
> > > The same logic already applied in AtaAtapiPassThruDxe driver.
> > >
> > > Signed-off-by: Neo Hsueh 
> > > ---
> > >  MdeModulePkg/Bus/Ata/AhciPei/AhciPeiPassThru.c | 10 ++
> > >  1 file changed, 10 insertions(+)
> > >
> > > diff --git a/MdeModulePkg/Bus/Ata/AhciPei/AhciPeiPassThru.c
> > > b/MdeModulePkg/Bus/Ata/AhciPei/AhciPeiPassThru.c
> > > index cd55272c96..7bd04661d0 100644
> > > --- a/MdeModulePkg/Bus/Ata/AhciPei/AhciPeiPassThru.c
> > > +++ b/MdeModulePkg/Bus/Ata/AhciPei/AhciPeiPassThru.c
> > > @@ -3,6 +3,7 @@
> > >mode at PEI phase.
> > >
> > >Copyright (c) 2019, Intel Corporation. All rights reserved.
> > > +  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights
> > > + reserved.
> > >
> > >SPDX-License-Identifier: BSD-2-Clause-Patent
> > >
> > > @@ -92,6 +93,15 @@ AhciPassThruExecute (  {
> > >EFI_STATUS  Status;
> > >
> > > +  if (PortMultiplierPort == 0x) {
> > > +//
> > > +// If there is no port multiplier, PortMultiplierPort will be 0x
> > > +// according to UEFI spec. Here, we convert its value to 0 to follow
> > > +// AHCI spec.
> > > +//
> > > +PortMultiplierPort = 0;
> > > +  }
> > > +
> > >switch (Packet->Protocol) {
> > >  case EFI_ATA_PASS_THRU_PROTOCOL_ATA_NON_DATA:
> > >Status = AhciNonDataTransfer (
> > > --
> > > 2.40.0.windows.1
> > >
> > >
> > >
> > > 
> > >



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#105839): https://edk2.groups.io/g/devel/message/105839
Mute This Topic: https://groups.io/mt/99093106/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] failed pr

2023-06-06 Thread Wu, Hao A
Thanks. Below approach works for me:

> From Conversation tab, scroll down to the "Some checks were not
> successful"
> area and scroll down to a check that failed.  The select "Details".
> that will take you to the specific area of the Checks tab that contains
> a failure and the drop down for "Re-run failed checks" is available.

Best Regards,
Hao Wu

> -Original Message-
> From: Kinney, Michael D 
> Sent: Wednesday, June 7, 2023 11:08 AM
> To: Wu, Hao A ; devel@edk2.groups.io; Ard
> Biesheuvel 
> Cc: Michael Kubacki ; Sean Brogan
> ; Kinney, Michael D
> 
> Subject: RE: [edk2-devel] failed pr
> 
> There seems to be multiple views in the checks tab.
> 
> From Conversation tab, scroll down to the "Some checks were not
> successful"
> area and scroll down to a check that failed.  The select "Details".
> that will take you to the specific area of the Checks tab that contains
> a failure and the drop down for "Re-run failed checks" is available.
> 
> Since we 4 groups of check jobs, you have to be in the right scope.
> 
> From the checks tab, you can also select "Azure Pipelines" and scroll
> down to a failed check.  Click on it, and "Re-run failed jobs" will be
> available.  Most of the failures are in Azure Pipelines.
> 
> Mike
> 
> > -Original Message-
> > From: Wu, Hao A 
> > Sent: Tuesday, June 6, 2023 7:02 PM
> > To: devel@edk2.groups.io; Kinney, Michael D
> ;
> > Ard Biesheuvel 
> > Cc: Michael Kubacki ; Sean Brogan
> > 
> > Subject: RE: [edk2-devel] failed pr
> >
> > Hello Mike,
> >
> > I do not see the "re-run failed jobs" under "Checks" tab for cancelled CI
> > tests:
> > https://github.com/tianocore/edk2/pull/4478
> > (Only "Re-run all checks" is found)
> >
> > What should be done to handle such case?
> >
> > Best Regards,
> > Hao Wu
> >
> > > -Original Message-
> > > From: devel@edk2.groups.io  On Behalf Of
> Michael
> > > D Kinney
> > > Sent: Wednesday, June 7, 2023 3:55 AM
> > > To: Ard Biesheuvel ; devel@edk2.groups.io
> > > Cc: Michael Kubacki ; Sean Brogan
> > > ; Kinney, Michael D
> > > 
> > > Subject: Re: [edk2-devel] failed pr
> > >
> > > All EDK II Maintainers should now have permissions to "re-run failed
> > jobs".
> > >
> > > If you see a PR with failed jobs that are not related to the code change,
> > then
> > > try rerunning the specific failed job or select "re-run failed jobs"
> > > from the drop down in top right of "Checks" tab.
> > >
> > > Please let me know if you do not see this as an option.
> > >
> > > Thanks,
> > >
> > > Mike
> > >
> > > > -Original Message-
> > > > From: Kinney, Michael D 
> > > > Sent: Friday, June 2, 2023 5:07 PM
> > > > To: Ard Biesheuvel ; devel@edk2.groups.io
> > > > Cc: Michael Kubacki ; Sean Brogan
> > > > ; Kinney, Michael D
> > > > 
> > > > Subject: RE: [edk2-devel] failed pr
> > > >
> > > > Merged
> > > >
> > > > Mike
> > > >
> > > > > -Original Message-
> > > > > From: Ard Biesheuvel 
> > > > > Sent: Friday, June 2, 2023 4:39 PM
> > > > > To: devel@edk2.groups.io; Kinney, Michael D
> > > > > 
> > > > > Cc: Michael Kubacki ; Sean Brogan
> > > > > 
> > > > > Subject: Re: [edk2-devel] failed pr
> > > > >
> > > > > Another one
> > > > >
> > > > > https://github.com/tianocore/edk2/pull/4473
> > > > >
> > > > > On Sat, 3 Jun 2023 at 00:32, Ard Biesheuvel  wrote:
> > > > > >
> > > > > > Thanks!
> > > > > >
> > > > > > On Fri, 2 Jun 2023 at 18:38, Michael D Kinney
> > > > > >  wrote:
> > > > > > >
> > > > > > > Done.
> > > > > > >
> > > > > > > Mike
> > > > > > >
> > > > > > > > -Original Message-
> > > > > > > > From: Kinney, Michael D 
> > > > > > > > Sent: Friday, June 2, 2023 9:37 AM
> > > > > > > > To: devel@edk2.groups.io; a...@kernel.org; Michael Kubacki
> > > > > > &

Re: [edk2-devel] failed pr

2023-06-06 Thread Wu, Hao A
Hello Mike,

I do not see the "re-run failed jobs" under "Checks" tab for cancelled CI tests:
https://github.com/tianocore/edk2/pull/4478
(Only "Re-run all checks" is found)

What should be done to handle such case?

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Michael
> D Kinney
> Sent: Wednesday, June 7, 2023 3:55 AM
> To: Ard Biesheuvel ; devel@edk2.groups.io
> Cc: Michael Kubacki ; Sean Brogan
> ; Kinney, Michael D
> 
> Subject: Re: [edk2-devel] failed pr
> 
> All EDK II Maintainers should now have permissions to "re-run failed jobs".
> 
> If you see a PR with failed jobs that are not related to the code change, then
> try rerunning the specific failed job or select "re-run failed jobs"
> from the drop down in top right of "Checks" tab.
> 
> Please let me know if you do not see this as an option.
> 
> Thanks,
> 
> Mike
> 
> > -Original Message-
> > From: Kinney, Michael D 
> > Sent: Friday, June 2, 2023 5:07 PM
> > To: Ard Biesheuvel ; devel@edk2.groups.io
> > Cc: Michael Kubacki ; Sean Brogan
> > ; Kinney, Michael D
> > 
> > Subject: RE: [edk2-devel] failed pr
> >
> > Merged
> >
> > Mike
> >
> > > -Original Message-
> > > From: Ard Biesheuvel 
> > > Sent: Friday, June 2, 2023 4:39 PM
> > > To: devel@edk2.groups.io; Kinney, Michael D
> > > 
> > > Cc: Michael Kubacki ; Sean Brogan
> > > 
> > > Subject: Re: [edk2-devel] failed pr
> > >
> > > Another one
> > >
> > > https://github.com/tianocore/edk2/pull/4473
> > >
> > > On Sat, 3 Jun 2023 at 00:32, Ard Biesheuvel  wrote:
> > > >
> > > > Thanks!
> > > >
> > > > On Fri, 2 Jun 2023 at 18:38, Michael D Kinney
> > > >  wrote:
> > > > >
> > > > > Done.
> > > > >
> > > > > Mike
> > > > >
> > > > > > -Original Message-
> > > > > > From: Kinney, Michael D 
> > > > > > Sent: Friday, June 2, 2023 9:37 AM
> > > > > > To: devel@edk2.groups.io; a...@kernel.org; Michael Kubacki
> > > > > > ; Sean Brogan
> > > 
> > > > > > Cc: Kinney, Michael D 
> > > > > > Subject: RE: [edk2-devel] failed pr
> > > > > >
> > > > > > I am working on it.
> > > > > >
> > > > > > Mike
> > > > > >
> > > > > > > -Original Message-
> > > > > > > From: devel@edk2.groups.io  On Behalf
> > > > > > > Of
> > Ard
> > > > > > > Biesheuvel
> > > > > > > Sent: Friday, June 2, 2023 9:19 AM
> > > > > > > To: Kinney, Michael D ; Michael
> > Kubacki
> > > > > > > ; Sean Brogan
> > > ;
> > > > > > > edk2-devel-groups-io 
> > > > > > > Subject: [edk2-devel] failed pr
> > > > > > >
> > > > > > > Could someone push the merge button on this pr please?
> > > > > > >
> > > > > > > https://github.com/tianocore/edk2/pull/4470
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#105833): https://edk2.groups.io/g/devel/message/105833
Mute This Topic: https://groups.io/mt/99289807/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v1 1/1] MdeModulePkg: UsbBusDxe: Build Descriptor table after resetting port

2023-06-05 Thread Wu, Hao A
Sorry for the late response, inline comments below:


> -Original Message-
> From: brit.ches...@amd.com 
> Sent: Wednesday, May 17, 2023 6:16 AM
> To: devel@edk2.groups.io
> Cc: Wang, Jian J ; Gao, Liming
> ; Wu, Hao A ; Ni, Ray
> 
> Subject: [PATCH v1 1/1] MdeModulePkg: UsbBusDxe: Build Descriptor table
> after resetting port
> 
> From: Britton Chesley 
> 
> Fixed a bug which led to an ASSERT due to the USB device context being
> maintained after a port reset, but the underlying XHCI context was
> uninitialized. Added build descriptor table call in UsbIoPortReset


Could you help to elaborate on what data in XHCI is not initialized that leads 
to the assert? Thanks.


> 
> Cc: Jian J Wang 
> Cc: Liming Gao 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Signed-off-by: Britton Chesley 
> ---
>  MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> index c25f3cc2f279..55e0e1f16cdb 100644
> --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> @@ -882,6 +882,12 @@ UsbIoPortReset (
>// is in CONFIGURED state.
>//
>if (Dev->ActiveConfig != NULL) {
> +Status = UsbBuildDescTable (Dev);


The UsbBuildDescTable function will allocate new buffer resources for and under 
Dev->DevDesc (device, configuration and interface descriptors).
Could you help to double check if the old buffers are properly freed for the 
proposed change?

Best Regards,
Hao Wu


> +
> +if (EFI_ERROR (Status)) {
> +  DEBUG ((DEBUG_ERROR, "UsbIoPortReset: failed to build descriptor
> table - %r\n", Status));
> +}
> +
>  Status = UsbSetConfig (Dev, Dev->ActiveConfig-
> >Desc.ConfigurationValue);
> 
>  if (EFI_ERROR (Status)) {
> --
> 2.36.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#105754): https://edk2.groups.io/g/devel/message/105754
Mute This Topic: https://groups.io/mt/98948709/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in AhciPei PEIM

2023-06-05 Thread Wu, Hao A
Add Stewards.

I cannot merge PR https://github.com/tianocore/edk2/pull/4478 due to constant 
cancelled CI tests.
Could someone help with the situation or help to merge the change? Thanks in 
advance.

Best Regards,
Hao Wu

From: devel@edk2.groups.io  On Behalf Of Wu, Hao A
Sent: Monday, June 5, 2023 12:32 PM
To: Hsueh, Hong-Chih (Neo) ; Chang, Abner 
; He, Jiangang ; devel@edk2.groups.io
Subject: Re: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in 
AhciPei PEIM

Thanks all,

Tried to merge the patch via PR - https://github.com/tianocore/edk2/pull/4478, 
but failed 3 times (all due to some canceled CI tests).
Will re-try tomorrow.

Best Regards,
Hao Wu

From: Hsueh, Hong-Chih (Neo) 
mailto:hong-chih.hs...@amd.com>>
Sent: Saturday, June 3, 2023 2:12 AM
To: Chang, Abner mailto:abner.ch...@amd.com>>; Wu, Hao A 
mailto:hao.a...@intel.com>>; He, Jiangang 
mailto:jiangang...@amd.com>>; 
devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Subject: Re: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in 
AhciPei PEIM


[AMD Official Use Only - General]

Hi Abner,

Thank you for your feedback. I updated the commit and re-create the PR as below:
https://github.com/tianocore/edk2/pull/4471

Regards,
Neo


From: Chang, Abner mailto:abner.ch...@amd.com>>
Sent: Friday, June 2, 2023 11:31 AM
To: Hsueh, Hong-Chih (Neo) 
mailto:hong-chih.hs...@amd.com>>; Wu, Hao A 
mailto:hao.a...@intel.com>>; He, Jiangang 
mailto:jiangang...@amd.com>>; 
devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
mailto:devel@edk2.groups.io>>
Subject: RE: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in 
AhciPei PEIM


[AMD Official Use Only - General]


Hi Leo,

Please add Hao's RB in the commit message below your signed-off-by, thus we 
know this patch has been reviewed.

I also suggest to update your commit subject to "MdeModulePkg/Bus: Fix port 
multiplier port in AhciPei PEIM".



Please resend the PR with above updates, then Hao will add "Push" label to this 
PR once your change passed CI.



Thanks

Abner







From: Hsueh, Hong-Chih (Neo) 
mailto:hong-chih.hs...@amd.com>>
Sent: Friday, June 2, 2023 10:37 PM
To: Wu, Hao A mailto:hao.a...@intel.com>>; He, Jiangang 
mailto:jiangang...@amd.com>>; 
devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Cc: Chang, Abner mailto:abner.ch...@amd.com>>
Subject: Re: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in 
AhciPei PEIM



[AMD Official Use Only - General]



Hi Hao,



Thank you for your review.



I already created a pull request for this commit, may I know how to proceed to 
merge it into master?



https://github.com/tianocore/edk2/pull/4424





Regards,

Neo



From: Wu, Hao A mailto:hao.a...@intel.com>>
Sent: Thursday, June 1, 2023 10:14 PM
To: He, Jiangang mailto:jiangang...@amd.com>>; 
devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
mailto:devel@edk2.groups.io>>; Hsueh, Hong-Chih (Neo) 
mailto:hong-chih.hs...@amd.com>>
Cc: Chang, Abner mailto:abner.ch...@amd.com>>
Subject: RE: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in 
AhciPei PEIM



[AMD Official Use Only - General]

Caution: This message originated from an External Source. Use proper caution 
when opening attachments, clicking links, or responding.


Thanks.
Reviewed-by: Hao A Wu mailto:hao.a...@intel.com>>

Best Regards,
Hao Wu

> -Original Message-
> From: He, Jiangang mailto:jiangang...@amd.com>>
> Sent: Wednesday, May 31, 2023 10:49 PM
> To: Wu, Hao A mailto:hao.a...@intel.com>>; 
> devel@edk2.groups.io<mailto:devel@edk2.groups.io>; Hsueh, Hong-
> Chih (Neo) mailto:hong-chih.hs...@amd.com>>
> Cc: Chang, Abner mailto:abner.ch...@amd.com>>
> Subject: RE: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in
> AhciPei PEIM
>
> [AMD Official Use Only - General]
>
> We did crisis recovery and Opal HD password unlock from S3 resume from
> SATA HD test on two different version of AHCI host controllers.
>
> Thanks,
> Jiangang
> -Original Message-
> From: Wu, Hao A mailto:hao.a...@intel.com>>
> Sent: Tuesday, May 30, 2023 10:30 PM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; Hsueh, Hong-Chih (Neo) 
>  chih.hs...@amd.com<mailto:chih.hs...@amd.com>>
> Cc: He, Jiangang mailto:jiangang...@amd.com>>; Chang, 
> Abner
> mailto:abner.ch...@amd.com>>
> Subject: RE: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in
> AhciPei PEIM
>
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
>
>
> Thanks, the code changes look good to me.
> May I know what tests have b

Re: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in AhciPei PEIM

2023-06-04 Thread Wu, Hao A
Thanks all,

Tried to merge the patch via PR - https://github.com/tianocore/edk2/pull/4478, 
but failed 3 times (all due to some canceled CI tests).
Will re-try tomorrow.

Best Regards,
Hao Wu

From: Hsueh, Hong-Chih (Neo) 
Sent: Saturday, June 3, 2023 2:12 AM
To: Chang, Abner ; Wu, Hao A ; He, 
Jiangang ; devel@edk2.groups.io
Subject: Re: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in 
AhciPei PEIM


[AMD Official Use Only - General]

Hi Abner,

Thank you for your feedback. I updated the commit and re-create the PR as below:
https://github.com/tianocore/edk2/pull/4471

Regards,
Neo


From: Chang, Abner mailto:abner.ch...@amd.com>>
Sent: Friday, June 2, 2023 11:31 AM
To: Hsueh, Hong-Chih (Neo) 
mailto:hong-chih.hs...@amd.com>>; Wu, Hao A 
mailto:hao.a...@intel.com>>; He, Jiangang 
mailto:jiangang...@amd.com>>; 
devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
mailto:devel@edk2.groups.io>>
Subject: RE: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in 
AhciPei PEIM


[AMD Official Use Only - General]


Hi Leo,

Please add Hao's RB in the commit message below your signed-off-by, thus we 
know this patch has been reviewed.

I also suggest to update your commit subject to "MdeModulePkg/Bus: Fix port 
multiplier port in AhciPei PEIM".



Please resend the PR with above updates, then Hao will add "Push" label to this 
PR once your change passed CI.



Thanks

Abner







From: Hsueh, Hong-Chih (Neo) 
mailto:hong-chih.hs...@amd.com>>
Sent: Friday, June 2, 2023 10:37 PM
To: Wu, Hao A mailto:hao.a...@intel.com>>; He, Jiangang 
mailto:jiangang...@amd.com>>; 
devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Cc: Chang, Abner mailto:abner.ch...@amd.com>>
Subject: Re: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in 
AhciPei PEIM



[AMD Official Use Only - General]



Hi Hao,



Thank you for your review.



I already created a pull request for this commit, may I know how to proceed to 
merge it into master?



https://github.com/tianocore/edk2/pull/4424





Regards,

Neo



From: Wu, Hao A mailto:hao.a...@intel.com>>
Sent: Thursday, June 1, 2023 10:14 PM
To: He, Jiangang mailto:jiangang...@amd.com>>; 
devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
mailto:devel@edk2.groups.io>>; Hsueh, Hong-Chih (Neo) 
mailto:hong-chih.hs...@amd.com>>
Cc: Chang, Abner mailto:abner.ch...@amd.com>>
Subject: RE: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in 
AhciPei PEIM



[AMD Official Use Only - General]

Caution: This message originated from an External Source. Use proper caution 
when opening attachments, clicking links, or responding.


Thanks.
Reviewed-by: Hao A Wu mailto:hao.a...@intel.com>>

Best Regards,
Hao Wu

> -Original Message-
> From: He, Jiangang mailto:jiangang...@amd.com>>
> Sent: Wednesday, May 31, 2023 10:49 PM
> To: Wu, Hao A mailto:hao.a...@intel.com>>; 
> devel@edk2.groups.io<mailto:devel@edk2.groups.io>; Hsueh, Hong-
> Chih (Neo) mailto:hong-chih.hs...@amd.com>>
> Cc: Chang, Abner mailto:abner.ch...@amd.com>>
> Subject: RE: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in
> AhciPei PEIM
>
> [AMD Official Use Only - General]
>
> We did crisis recovery and Opal HD password unlock from S3 resume from
> SATA HD test on two different version of AHCI host controllers.
>
> Thanks,
> Jiangang
> -Original Message-
> From: Wu, Hao A mailto:hao.a...@intel.com>>
> Sent: Tuesday, May 30, 2023 10:30 PM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; Hsueh, Hong-Chih (Neo) 
>  chih.hs...@amd.com<mailto:chih.hs...@amd.com>>
> Cc: He, Jiangang mailto:jiangang...@amd.com>>; Chang, 
> Abner
> mailto:abner.ch...@amd.com>>
> Subject: RE: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in
> AhciPei PEIM
>
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
>
>
> Thanks, the code changes look good to me.
> May I know what tests have been performed for the patch?
>
> Best Regards,
> Hao Wu
>
> > -Original Message-
> > From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
> > mailto:devel@edk2.groups.io>> On Behalf Of Neo
> > Hsueh via groups.io
> > Sent: Wednesday, May 24, 2023 1:07 AM
> > To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> > Cc: jiangang...@amd.com<mailto:jiangang...@amd.com>; 
> > abner.ch...@amd.com<mailto:abner.ch...@amd.com>; Neo Hsueh  > chih.hs...@amd.com<mailto:chih.hs...@amd.com>>
> > Subject: [edk2-devel] [PATCH] MdeModulePkg: 

Re: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in AhciPei PEIM

2023-06-01 Thread Wu, Hao A
Thanks.
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: He, Jiangang 
> Sent: Wednesday, May 31, 2023 10:49 PM
> To: Wu, Hao A ; devel@edk2.groups.io; Hsueh, Hong-
> Chih (Neo) 
> Cc: Chang, Abner 
> Subject: RE: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in
> AhciPei PEIM
> 
> [AMD Official Use Only - General]
> 
> We did crisis recovery and Opal HD password unlock from S3 resume from
> SATA HD test on two different version of AHCI host controllers.
> 
> Thanks,
> Jiangang
> -Original Message-
> From: Wu, Hao A 
> Sent: Tuesday, May 30, 2023 10:30 PM
> To: devel@edk2.groups.io; Hsueh, Hong-Chih (Neo)  chih.hs...@amd.com>
> Cc: He, Jiangang ; Chang, Abner
> 
> Subject: RE: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in
> AhciPei PEIM
> 
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
> 
> 
> Thanks, the code changes look good to me.
> May I know what tests have been performed for the patch?
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: devel@edk2.groups.io  On Behalf Of Neo
> > Hsueh via groups.io
> > Sent: Wednesday, May 24, 2023 1:07 AM
> > To: devel@edk2.groups.io
> > Cc: jiangang...@amd.com; abner.ch...@amd.com; Neo Hsueh  > chih.hs...@amd.com>
> > Subject: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port
> > in AhciPei PEIM
> >
> > If there is no port multiplier, PortMultiplierPort should be converted
> > to 0 to follow AHCI spec.
> > The same logic already applied in AtaAtapiPassThruDxe driver.
> >
> > Signed-off-by: Neo Hsueh 
> > ---
> >  MdeModulePkg/Bus/Ata/AhciPei/AhciPeiPassThru.c | 10 ++
> >  1 file changed, 10 insertions(+)
> >
> > diff --git a/MdeModulePkg/Bus/Ata/AhciPei/AhciPeiPassThru.c
> > b/MdeModulePkg/Bus/Ata/AhciPei/AhciPeiPassThru.c
> > index cd55272c96..7bd04661d0 100644
> > --- a/MdeModulePkg/Bus/Ata/AhciPei/AhciPeiPassThru.c
> > +++ b/MdeModulePkg/Bus/Ata/AhciPei/AhciPeiPassThru.c
> > @@ -3,6 +3,7 @@
> >mode at PEI phase.
> >
> >Copyright (c) 2019, Intel Corporation. All rights reserved.
> > +  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights
> > + reserved.
> >
> >SPDX-License-Identifier: BSD-2-Clause-Patent
> >
> > @@ -92,6 +93,15 @@ AhciPassThruExecute (  {
> >EFI_STATUS  Status;
> >
> > +  if (PortMultiplierPort == 0x) {
> > +//
> > +// If there is no port multiplier, PortMultiplierPort will be 0x
> > +// according to UEFI spec. Here, we convert its value to 0 to follow
> > +// AHCI spec.
> > +//
> > +PortMultiplierPort = 0;
> > +  }
> > +
> >switch (Packet->Protocol) {
> >  case EFI_ATA_PASS_THRU_PROTOCOL_ATA_NON_DATA:
> >Status = AhciNonDataTransfer (
> > --
> > 2.40.0.windows.1
> >
> >
> >
> > 
> >



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#105620): https://edk2.groups.io/g/devel/message/105620
Mute This Topic: https://groups.io/mt/99093106/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in AhciPei PEIM

2023-05-30 Thread Wu, Hao A
Thanks, the code changes look good to me.
May I know what tests have been performed for the patch?

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Neo
> Hsueh via groups.io
> Sent: Wednesday, May 24, 2023 1:07 AM
> To: devel@edk2.groups.io
> Cc: jiangang...@amd.com; abner.ch...@amd.com; Neo Hsueh  chih.hs...@amd.com>
> Subject: [edk2-devel] [PATCH] MdeModulePkg: Fix port multiplier port in
> AhciPei PEIM
> 
> If there is no port multiplier, PortMultiplierPort should be converted
> to 0 to follow AHCI spec.
> The same logic already applied in AtaAtapiPassThruDxe driver.
> 
> Signed-off-by: Neo Hsueh 
> ---
>  MdeModulePkg/Bus/Ata/AhciPei/AhciPeiPassThru.c | 10 ++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/MdeModulePkg/Bus/Ata/AhciPei/AhciPeiPassThru.c
> b/MdeModulePkg/Bus/Ata/AhciPei/AhciPeiPassThru.c
> index cd55272c96..7bd04661d0 100644
> --- a/MdeModulePkg/Bus/Ata/AhciPei/AhciPeiPassThru.c
> +++ b/MdeModulePkg/Bus/Ata/AhciPei/AhciPeiPassThru.c
> @@ -3,6 +3,7 @@
>mode at PEI phase.
> 
>Copyright (c) 2019, Intel Corporation. All rights reserved.
> +  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
> 
>SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> @@ -92,6 +93,15 @@ AhciPassThruExecute (
>  {
>EFI_STATUS  Status;
> 
> +  if (PortMultiplierPort == 0x) {
> +//
> +// If there is no port multiplier, PortMultiplierPort will be 0x
> +// according to UEFI spec. Here, we convert its value to 0 to follow
> +// AHCI spec.
> +//
> +PortMultiplierPort = 0;
> +  }
> +
>switch (Packet->Protocol) {
>  case EFI_ATA_PASS_THRU_PROTOCOL_ATA_NON_DATA:
>Status = AhciNonDataTransfer (
> --
> 2.40.0.windows.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#105476): https://edk2.groups.io/g/devel/message/105476
Mute This Topic: https://groups.io/mt/99093106/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH] MdeModulePkg SdMmcPciHcDxe: SD/MMC capability debug print is incorrect

2023-05-28 Thread Wu, Hao A
Merged via:
PR - https://github.com/tianocore/edk2/pull/4439
Commit - 
https://github.com/tianocore/edk2/commit/e1f5c6249af08c1df2c6257e4bb6abbf6134318c

Best Regards,
Hao Wu

> -Original Message-
> From: Giri Mudusuru 
> Sent: Thursday, May 18, 2023 2:01 AM
> To: Wu, Hao A 
> Cc: devel@edk2.groups.io; Ni, Ray ; Wang, Jian J
> ; Gao, Liming ;
> Andrew Fish ; Giri Mudusuru 
> Subject: Re: [PATCH] MdeModulePkg SdMmcPciHcDxe: SD/MMC capability
> debug print is incorrect
> 
> > Please help to use %p for printing pointers.
> Thanks for approvals. To clarify the value is 64-bit capability register 
> value.
> 
> Thanks,
> -Giri
> 
> > On May 17, 2023, at 9:49 AM, Wu, Hao A  wrote:
> >
> > Thanks for the patch, inline comment below:
> >
> >
> >> -Original Message-
> >> From: Giri Mudusuru 
> >> Sent: Friday, May 12, 2023 5:55 PM
> >> To: devel@edk2.groups.io
> >> Cc: Giri Mudusuru ; Wu, Hao A
> ;
> >> Ni, Ray ; Wang, Jian J ;
> >> Gao, Liming ; Andrew Fish
> 
> >> Subject: [PATCH] MdeModulePkg SdMmcPciHcDxe: SD/MMC capability
> debug
> >> print is incorrect
> >>
> >> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4394
> >>
> >> Fix DumpCapabilityReg() debug log to print 64 bit capability instead
> >> of 32 bit pointer
> >>
> >> Cc: Hao A Wu 
> >> Cc: Ray Ni 
> >> Cc: Jian J Wang 
> >> Cc: Liming Gao 
> >> Cc: Andrew Fish 
> >> Signed-off-by: Giri Mudusuru 
> >> ---
> >> MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> >> b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> >> index aab6815328..2e7497a89d 100644
> >> --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> >> +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> >> @@ -30,7 +30,7 @@ DumpCapabilityReg (
> >>   //
> >>
> >>   // Dump Capability Data
> >>
> >>   //
> >>
> >> -  DEBUG ((DEBUG_INFO, " == Slot [%d] Capability is 0x%x ==\n", Slot,
> >> Capability));
> >>
> >> +  DEBUG ((DEBUG_INFO, " == Slot [%d] Capability is 0x%llx ==\n",
> >> + Slot,
> >> *(UINT64 *)Capability));
> >
> >
> > Please help to use %p for printing pointers.
> >
> > Best Regards,
> > Hao Wu
> >
> >
> >>
> >>   DEBUG ((DEBUG_INFO, "   Timeout Clk Freq  %d%a\n", Capability-
> >>> TimeoutFreq, (Capability->TimeoutUnit) ? "MHz" : "KHz"));
> >>
> >>   DEBUG ((DEBUG_INFO, "   Base Clk Freq %dMHz\n", Capability-
> >>> BaseClkFreq));
> >>
> >>   DEBUG ((DEBUG_INFO, "   Max Blk Len   %dbytes\n", 512 * (1 <<
> >> Capability->MaxBlkLen)));
> >>
> >> --
> >> 2.39.2 (Apple Git-144)
> >



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#105357): https://edk2.groups.io/g/devel/message/105357
Mute This Topic: https://groups.io/mt/98846217/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH] MdeModulePkg SdMmcPciHcDxe: SD/MMC capability debug print is incorrect

2023-05-17 Thread Wu, Hao A
> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Ard
> Biesheuvel
> Sent: Wednesday, May 17, 2023 7:46 PM
> To: devel@edk2.groups.io; Wu, Hao A 
> Cc: Giri Mudusuru ; Ni, Ray ; Wang,
> Jian J ; Gao, Liming ;
> Andrew Fish 
> Subject: Re: [edk2-devel] [PATCH] MdeModulePkg SdMmcPciHcDxe: SD/MMC
> capability debug print is incorrect
> 
> On Wed, 17 May 2023 at 06:19, Wu, Hao A  wrote:
> >
> > Thanks for the patch, inline comment below:
> >
> >
> > > -Original Message-
> > > From: Giri Mudusuru 
> > > Sent: Friday, May 12, 2023 5:55 PM
> > > To: devel@edk2.groups.io
> > > Cc: Giri Mudusuru ; Wu, Hao A
> ;
> > > Ni, Ray ; Wang, Jian J ;
> > > Gao, Liming ; Andrew Fish
> > > 
> > > Subject: [PATCH] MdeModulePkg SdMmcPciHcDxe: SD/MMC capability
> debug
> > > print is incorrect
> > >
> > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4394
> > >
> > > Fix DumpCapabilityReg() debug log to print 64 bit capability instead
> > > of 32 bit pointer
> > >
> > > Cc: Hao A Wu 
> > > Cc: Ray Ni 
> > > Cc: Jian J Wang 
> > > Cc: Liming Gao 
> > > Cc: Andrew Fish 
> > > Signed-off-by: Giri Mudusuru 
> 
> Reviewed-by: Ard Biesheuvel 
> 
> > > ---
> > >  MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> > > b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> > > index aab6815328..2e7497a89d 100644
> > > --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> > > +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> > > @@ -30,7 +30,7 @@ DumpCapabilityReg (
> > >//
> > >
> > >// Dump Capability Data
> > >
> > >//
> > >
> > > -  DEBUG ((DEBUG_INFO, " == Slot [%d] Capability is 0x%x ==\n",
> > > Slot, Capability));
> > >
> > > +  DEBUG ((DEBUG_INFO, " == Slot [%d] Capability is 0x%llx ==\n",
> > > + Slot,
> > > *(UINT64 *)Capability));
> >
> >
> > Please help to use %p for printing pointers.
> >
> 
> Why? The point of this patch is that we are not interested in the pointer, 
> only
> in the value that it points to.


Thanks.
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu


> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#104974): https://edk2.groups.io/g/devel/message/104974
Mute This Topic: https://groups.io/mt/98846217/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH] MdeModulePkg SdMmcPciHcDxe: SD/MMC capability debug print is incorrect

2023-05-16 Thread Wu, Hao A
Thanks for the patch, inline comment below:


> -Original Message-
> From: Giri Mudusuru 
> Sent: Friday, May 12, 2023 5:55 PM
> To: devel@edk2.groups.io
> Cc: Giri Mudusuru ; Wu, Hao A ; Ni,
> Ray ; Wang, Jian J ; Gao, Liming
> ; Andrew Fish 
> Subject: [PATCH] MdeModulePkg SdMmcPciHcDxe: SD/MMC capability debug
> print is incorrect
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4394
> 
> Fix DumpCapabilityReg() debug log to print 64 bit capability instead of 32 bit
> pointer
> 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Cc: Jian J Wang 
> Cc: Liming Gao 
> Cc: Andrew Fish 
> Signed-off-by: Giri Mudusuru 
> ---
>  MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> index aab6815328..2e7497a89d 100644
> --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
> @@ -30,7 +30,7 @@ DumpCapabilityReg (
>//
> 
>// Dump Capability Data
> 
>//
> 
> -  DEBUG ((DEBUG_INFO, " == Slot [%d] Capability is 0x%x ==\n", Slot,
> Capability));
> 
> +  DEBUG ((DEBUG_INFO, " == Slot [%d] Capability is 0x%llx ==\n", Slot,
> *(UINT64 *)Capability));


Please help to use %p for printing pointers.

Best Regards,
Hao Wu


> 
>DEBUG ((DEBUG_INFO, "   Timeout Clk Freq  %d%a\n", Capability-
> >TimeoutFreq, (Capability->TimeoutUnit) ? "MHz" : "KHz"));
> 
>DEBUG ((DEBUG_INFO, "   Base Clk Freq %dMHz\n", Capability-
> >BaseClkFreq));
> 
>DEBUG ((DEBUG_INFO, "   Max Blk Len   %dbytes\n", 512 * (1 <<
> Capability->MaxBlkLen)));
> 
> --
> 2.39.2 (Apple Git-144)



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#104959): https://edk2.groups.io/g/devel/message/104959
Mute This Topic: https://groups.io/mt/98846217/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 04/12] MdeModulePkg/SataControllerDxe: Fix up ASSERTS (Private != NULL)

2023-05-11 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: Pedro Falcato 
> Sent: Wednesday, May 10, 2023 12:32 AM
> To: devel@edk2.groups.io
> Cc: Laszlo Ersek ; Pedro Falcato
> ; Wang, Jian J ; Gao,
> Liming ; Wu, Hao A ; Ni,
> Ray ; Mike Maslenkin 
> Subject: [PATCH v2 04/12] MdeModulePkg/SataControllerDxe: Fix up ASSERTS
> (Private != NULL)
> 
> ASSERT (Private != NULL) (where Private = CR(...)) is ineffective as
> CR(Ptr, Type, Member, Sig) either returns Ptr - offsetof(Type, Member),
> or ASSERTS on the signature, so it's unlikely to ever return NULL
> (must be passed a pointer = member's offset, or in this case, 0x4).
> 
> ASSERT on This != NULL instead.
> 
> Cc: Jian J Wang 
> Cc: Liming Gao 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Cc: Mike Maslenkin 
> Signed-off-by: Pedro Falcato 
> ---
>  MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c | 9 -
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
> b/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
> index f0ffd311d7b9..ea0116071c6a 100644
> --- a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
> +++ b/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
> @@ -611,7 +611,6 @@ SataControllerStop (
>}
> 
>Private = SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (IdeInit);
> -  ASSERT (Private != NULL);
> 
>//
>// Uninstall the IDE Controller Init Protocol from this instance
> @@ -745,8 +744,8 @@ IdeInitGetChannelInfo (
>  {
>EFI_SATA_CONTROLLER_PRIVATE_DATA  *Private;
> 
> +  ASSERT (This != NULL);
>Private = SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This);
> -  ASSERT (Private != NULL);
> 
>if (Channel < This->ChannelCount) {
>  *Enabled= TRUE;
> @@ -845,8 +844,8 @@ IdeInitSubmitData (
>EFI_SATA_CONTROLLER_PRIVATE_DATA  *Private;
>UINTN DeviceIndex;
> 
> +  ASSERT (This != NULL);
>Private = SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This);
> -  ASSERT (Private != NULL);
> 
>if ((Channel >= This->ChannelCount) || (Device >= Private->DeviceCount)) {
>  return EFI_INVALID_PARAMETER;
> @@ -924,8 +923,8 @@ IdeInitDisqualifyMode (
>EFI_SATA_CONTROLLER_PRIVATE_DATA  *Private;
>UINTN DeviceIndex;
> 
> +  ASSERT (This != NULL);
>Private = SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This);
> -  ASSERT (Private != NULL);
> 
>if ((Channel >= This->ChannelCount) || (BadModes == NULL) || (Device >=
> Private->DeviceCount)) {
>  return EFI_INVALID_PARAMETER;
> @@ -1017,8 +1016,8 @@ IdeInitCalculateMode (
>EFI_STATUSStatus;
>UINTN DeviceIndex;
> 
> +  ASSERT (This != NULL);
>Private = SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This);
> -  ASSERT (Private != NULL);
> 
>if ((Channel >= This->ChannelCount) || (SupportedModes == NULL) ||
> (Device >= Private->DeviceCount)) {
>  return EFI_INVALID_PARAMETER;
> --
> 2.40.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#104728): https://edk2.groups.io/g/devel/message/104728
Mute This Topic: https://groups.io/mt/98787857/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 02/12] MdeModulePkg/SataControllerDxe: Log expected errors at DEBUG_INFO level

2023-05-11 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: Pedro Falcato 
> Sent: Wednesday, May 10, 2023 12:32 AM
> To: devel@edk2.groups.io
> Cc: Laszlo Ersek ; Pedro Falcato
> ; Wang, Jian J ; Gao,
> Liming ; Wu, Hao A ; Ni,
> Ray 
> Subject: [PATCH v2 02/12] MdeModulePkg/SataControllerDxe: Log expected
> errors at DEBUG_INFO level
> 
> When a UEFI_DRIVER attempts to open a protocol interface with BY_DRIVER
> attribute that it already has open with BY_DRIVER attribute,
> OpenProtocol() returns EFI_ALREADY_STARTED. This is not an error. The
> UEFI-2.7 spec currently says,
> 
> > EFI_ALREADY_STARTED -- Attributes is BY_DRIVER and there is an item on
> >the open list with an attribute of BY_DRIVER
> >whose agent handle is the same as AgentHandle.
> 
> Downgrade the log mask for this one condition to DEBUG_INFO, in
> SataControllerStart(). This will match the log mask of the other two
> informative messages in this function.
> 
> (ported from commit 5dfba97)
> 
> Cc: Jian J Wang 
> Cc: Liming Gao 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Signed-off-by: Pedro Falcato 
> ---
>  .../Bus/Pci/SataControllerDxe/SataController.c| 15 +--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
> b/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
> index d67a3e69f649..277bc6182db6 100644
> --- a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
> +++ b/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
> @@ -358,10 +358,12 @@ SataControllerStart (
>UINTN TotalCount;
>UINT64Supports;
>UINT8 MaxPortNumber;
> +  UINTN BailLogMask;
> 
>DEBUG ((DEBUG_INFO, "SataControllerStart start\n"));
> 
> -  Private = NULL;
> +  Private = NULL;
> +  BailLogMask = DEBUG_ERROR;
> 
>//
>// Now test and open PCI I/O Protocol
> @@ -375,6 +377,15 @@ SataControllerStart (
>EFI_OPEN_PROTOCOL_BY_DRIVER
>);
>if (EFI_ERROR (Status)) {
> +if (Status == EFI_ALREADY_STARTED) {
> +  //
> +  // This is an expected condition for OpenProtocol() / BY_DRIVER, in a
> +  // DriverBindingStart() member function; degrade the log mask to
> +  // DEBUG_INFO in order to reduce log pollution.
> +  //
> +  BailLogMask = DEBUG_INFO;
> +}
> +
>  goto Bail;
>}
> 
> @@ -555,7 +566,7 @@ FreeSataPrivate:
>  ClosePciIo:
>gBS->CloseProtocol (Controller, , This-
> >DriverBindingHandle, Controller);
>  Bail:
> -  DEBUG ((DEBUG_ERROR, "SataControllerStart error return status = %r\n",
> Status));
> +  DEBUG ((BailLogMask, "SataControllerStart error return status = %r\n",
> Status));
>return Status;
>  }
> 
> --
> 2.40.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#104727): https://edk2.groups.io/g/devel/message/104727
Mute This Topic: https://groups.io/mt/98787855/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 01/12] MdeModulePkg/SataControllerDxe: Clean up error handling in Start()

2023-05-11 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Pedro
> Falcato
> Sent: Wednesday, May 10, 2023 12:32 AM
> To: devel@edk2.groups.io
> Cc: Laszlo Ersek ; Pedro Falcato
> ; Wang, Jian J ; Gao,
> Liming ; Wu, Hao A ; Ni,
> Ray 
> Subject: [edk2-devel] [PATCH v2 01/12] MdeModulePkg/SataControllerDxe:
> Clean up error handling in Start()
> 
> Clean up error handling using cascading labels + goto.
> 
> (port of commit 379b179 + bcab714)
> 
> Cc: Jian J Wang 
> Cc: Liming Gao 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Signed-off-by: Pedro Falcato 
> ---
>  .../Pci/SataControllerDxe/SataController.c| 80 ---
>  1 file changed, 35 insertions(+), 45 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
> b/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
> index f661efaec7e9..d67a3e69f649 100644
> --- a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
> +++ b/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
> @@ -375,8 +375,7 @@ SataControllerStart (
>EFI_OPEN_PROTOCOL_BY_DRIVER
>);
>if (EFI_ERROR (Status)) {
> -DEBUG ((DEBUG_ERROR, "SataControllerStart error. return status = %r\n",
> Status));
> -return Status;
> +goto Bail;
>}
> 
>//
> @@ -385,7 +384,7 @@ SataControllerStart (
>Private = AllocateZeroPool (sizeof (EFI_SATA_CONTROLLER_PRIVATE_DATA));
>if (Private == NULL) {
>  Status = EFI_OUT_OF_RESOURCES;
> -goto Done;
> +goto ClosePciIo;
>}
> 
>//
> @@ -412,7 +411,7 @@ SataControllerStart (
>  >OriginalPciAttributes
>  );
>if (EFI_ERROR (Status)) {
> -goto Done;
> +goto FreeSataPrivate;
>}
> 
>DEBUG ((
> @@ -428,7 +427,7 @@ SataControllerStart (
>  
>  );
>if (EFI_ERROR (Status)) {
> -goto Done;
> +goto FreeSataPrivate;
>}
> 
>DEBUG ((DEBUG_INFO, "Supported PCI Attributes = 0x%llx\n", Supports));
> @@ -441,7 +440,7 @@ SataControllerStart (
> NULL
> );
>if (EFI_ERROR (Status)) {
> -goto Done;
> +goto FreeSataPrivate;
>}
> 
>DEBUG ((DEBUG_INFO, "Enabled PCI Attributes = 0x%llx\n", Supports));
> @@ -456,7 +455,7 @@ SataControllerStart (
>  );
>if (EFI_ERROR (Status)) {
>  ASSERT (FALSE);
> -goto Done;
> +goto RestorePciAttributes;
>}
> 
>if (IS_PCI_IDE ()) {
> @@ -470,7 +469,7 @@ SataControllerStart (
>  DEBUG ((DEBUG_INFO, "Ports Implemented(PI) = 0x%x\n", Data32));
>  if (Data32 == 0) {
>Status = EFI_UNSUPPORTED;
> -  goto Done;
> +  goto RestorePciAttributes;
>  }
> 
>  MaxPortNumber = 31;
> @@ -502,19 +501,19 @@ SataControllerStart (
>Private->DisqualifiedModes = AllocateZeroPool ((sizeof
> (EFI_ATA_COLLECTIVE_MODE)) * TotalCount);
>if (Private->DisqualifiedModes == NULL) {
>  Status = EFI_OUT_OF_RESOURCES;
> -goto Done;
> +goto RestorePciAttributes;
>}
> 
>Private->IdentifyData = AllocateZeroPool ((sizeof (EFI_IDENTIFY_DATA)) *
> TotalCount);
>if (Private->IdentifyData == NULL) {
>  Status = EFI_OUT_OF_RESOURCES;
> -goto Done;
> +goto FreeDisqualifiedModes;
>}
> 
>Private->IdentifyValid = AllocateZeroPool ((sizeof (BOOLEAN)) * 
> TotalCount);
>if (Private->IdentifyValid == NULL) {
>  Status = EFI_OUT_OF_RESOURCES;
> -goto Done;
> +goto FreeIdentifyData;
>}
> 
>//
> @@ -527,46 +526,37 @@ SataControllerStart (
>NULL
>);
> 
> -Done:
>if (EFI_ERROR (Status)) {
> -gBS->CloseProtocol (
> -   Controller,
> -   ,
> -   This->DriverBindingHandle,
> -   Controller
> -   );
> -if (Private != NULL) {
> -  if (Private->DisqualifiedModes != NULL) {
> -FreePool (Private->DisqualifiedModes);
> -  }
> -
> -  if (Private->IdentifyData != NULL) {
> -FreePool (Private->IdentifyData);
> -  }
> -
> -  if (Private->IdentifyValid != NULL) {
> -FreePool (Private->IdentifyValid);
> -  }
> -
> -  if (Private->PciAttributesChanged) {
> -//
> -// Restore original PCI attributes
> -//
> -PciIo->Attributes (
> - PciIo,
> -   

Re: [edk2-devel] [PATCH v2 03/12] MdeModulePkg/SataControllerDxe: Remove useless null check

2023-05-11 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Pedro
> Falcato
> Sent: Wednesday, May 10, 2023 12:32 AM
> To: devel@edk2.groups.io
> Cc: Laszlo Ersek ; Pedro Falcato
> ; Wang, Jian J ; Gao,
> Liming ; Wu, Hao A ; Ni,
> Ray ; Mike Maslenkin 
> Subject: [edk2-devel] [PATCH v2 03/12] MdeModulePkg/SataControllerDxe:
> Remove useless null check
> 
> ASSERT (Private != NULL) already covers this check.
> See commit 81310a6.
> 
> Cc: Jian J Wang 
> Cc: Liming Gao 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Cc: Mike Maslenkin 
> Signed-off-by: Pedro Falcato 
> ---
>  .../Pci/SataControllerDxe/SataController.c| 44 +--
>  1 file changed, 21 insertions(+), 23 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
> b/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
> index 277bc6182db6..f0ffd311d7b9 100644
> --- a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
> +++ b/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
> @@ -626,34 +626,32 @@ SataControllerStop (
>  return Status;
>}
> 
> -  if (Private != NULL) {
> -if (Private->DisqualifiedModes != NULL) {
> -  FreePool (Private->DisqualifiedModes);
> -}
> -
> -if (Private->IdentifyData != NULL) {
> -  FreePool (Private->IdentifyData);
> -}
> +  if (Private->DisqualifiedModes != NULL) {
> +FreePool (Private->DisqualifiedModes);
> +  }
> 
> -if (Private->IdentifyValid != NULL) {
> -  FreePool (Private->IdentifyValid);
> -}
> +  if (Private->IdentifyData != NULL) {
> +FreePool (Private->IdentifyData);
> +  }
> 
> -if (Private->PciAttributesChanged) {
> -  //
> -  // Restore original PCI attributes
> -  //
> -  Private->PciIo->Attributes (
> -Private->PciIo,
> -EfiPciIoAttributeOperationSet,
> -Private->OriginalPciAttributes,
> -NULL
> -);
> -}
> +  if (Private->IdentifyValid != NULL) {
> +FreePool (Private->IdentifyValid);
> +  }
> 
> -FreePool (Private);
> +  if (Private->PciAttributesChanged) {
> +//
> +// Restore original PCI attributes
> +//
> +Private->PciIo->Attributes (
> +  Private->PciIo,
> +  EfiPciIoAttributeOperationSet,
> +  Private->OriginalPciAttributes,
> +  NULL
> +  );
>}
> 
> +  FreePool (Private);
> +
>//
>// Close protocols opened by Sata Controller driver
>//
> --
> 2.40.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#104725): https://edk2.groups.io/g/devel/message/104725
Mute This Topic: https://groups.io/mt/98787856/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel][PATCH v2 0/2] Add Volatile Keyword to NvmExpress Passthru CQs

2023-05-07 Thread Wu, Hao A
Pushed via:
PR - https://github.com/tianocore/edk2/pull/4353
Commits:
https://github.com/tianocore/edk2/commit/293b97d0c4624c13a4e934294d2c4b161a09a91b
https://github.com/tianocore/edk2/commit/8dbf868e02c71b407e31f9b41b5266169c702812

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Wu, Hao A
> Sent: Thursday, May 4, 2023 10:20 AM
> To: devel@edk2.groups.io; o...@linux.microsoft.com
> Cc: Ni, Ray ; Wang, Jian J ; Gao,
> Liming ; Michael Kubacki
> ; Sean Brogan 
> Subject: Re: [edk2-devel][PATCH v2 0/2] Add Volatile Keyword to NvmExpress
> Passthru CQs
> 
> For the series:
> Reviewed-by: Hao A Wu 
> 
> Will wait a couple of days before merging to see if comments from other
> reviewers.
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: devel@edk2.groups.io  On Behalf Of Oliver
> > Smith-Denny
> > Sent: Friday, April 28, 2023 1:36 AM
> > To: devel@edk2.groups.io
> > Cc: Wu, Hao A ; Ni, Ray ; Wang,
> > Jian J ; Gao, Liming
> > ; Michael Kubacki
> > ; Sean Brogan
> > 
> > Subject: [edk2-devel][PATCH v2 0/2] Add Volatile Keyword to NvmExpress
> > Passthru CQs
> >
> > NVMe CQs are hardware queues mapped to EFI memory.
> > In the NVMExpress Passthru implementations in PEI and DXE, it has been
> > observed that NVMe CQs are not marked volatile, meaning the compiler
> > has significant leeway to optimize accesses to these structures.
> >
> > This led to an issue where the passthru driver waited for a timeout
> > period for an NVMe CQ to mark that it was finished with a transaction,
> > but the compiler had optimized away the read to the actual HW mapped
> > memory, so the transaction had completed but the timeout continued.
> >
> > Marking the CQs as volatile fixes this issue as the reads happen to
> > the actual HW.
> >
> > Personal GitHub PR: https://github.com/tianocore/edk2/pull/4320
> > Github branch: https://github.com/os-d/edk2/tree/osde/volatile_cq_v2
> >
> > Changes v1 => v2:
> > =
> > - Remove volatile keyword from SQ
> >
> > Cc: Hao A Wu 
> > Cc: Ray Ni 
> > Cc: Jian J Wang 
> > Cc: Liming Gao 
> > Cc: Michael Kubacki 
> > Cc: Sean Brogan 
> >
> >
> > Oliver Smith-Denny (2):
> >   Add the volatile keyword to NvmExpressDxe's Passthru CQ
> >   Add volatile keyword to NvmExpressPei's Passthru CQ
> >
> >  MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c| 6 +++---
> >  MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiPassThru.c | 6 +++---
> >  2 files changed, 6 insertions(+), 6 deletions(-)
> >
> > --
> > 2.40.0
> >
> >
> >
> > -=-=-=-=-=-=
> > Groups.io Links: You receive all messages sent to this group.
> > View/Reply Online (#103725):
> > https://edk2.groups.io/g/devel/message/103725
> > Mute This Topic: https://groups.io/mt/98541927/1768737
> > Group Owner: devel+ow...@edk2.groups.io
> > Unsubscribe: https://edk2.groups.io/g/devel/unsub [hao.a...@intel.com]
> > -=-=-=-=-=-=
> >
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#104237): https://edk2.groups.io/g/devel/message/104237
Mute This Topic: https://groups.io/mt/98541927/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v1 1/2] Add the volatile keyword to NvmExpressDxe's Passthru CQs and SQs.

2023-04-26 Thread Wu, Hao A
Thanks Oliver,

Agree with your points. Let's keep "Sq" as is and mark "Cq" as volatile.

Best Regards,
Hao Wu

> -Original Message-
> From: Oliver Smith-Denny 
> Sent: Thursday, April 27, 2023 5:07 AM
> To: devel@edk2.groups.io; Wu, Hao A ; Ni, Ray
> 
> Cc: Wang, Jian J ; Gao, Liming
> ; Michael Kubacki
> ; Sean Brogan 
> Subject: Re: [edk2-devel] [PATCH v1 1/2] Add the volatile keyword to
> NvmExpressDxe's Passthru CQs and SQs.
> 
> Hi Hao,
> 
> Thanks for the review! For the Sq, I agree, currently some metadata is read
> from the queue, but it is not fields that are going to change (such as SGL 
> usage).
> The thought process there was in case we interact with the HW queue
> differently in the future. I will drop the Sq change in v2 of this patch.
> 
> For the Cq, I think the safer option is to mark the whole structure as 
> volatile,
> because there are other bits that we read out of there that the HW updates, 
> for
> example the status code here:
> 
> 
>//
>// Check the NVMe cmd execution result
>//
>if (Status != EFI_TIMEOUT) {
>  if ((Cq->Sct == 0) && (Cq->Sc == 0)) {
>Status = EFI_SUCCESS;
> 
> 
> Without the structure marked as volatile, I believe the compiler could 
> optimize
> the code such that it only reads these metadata fields at the beginning of 
> this
> function, potentially before they are set by the HW.
> 
> I do not believe there is much of a performance downside to marking the
> structure vs individual fields. I am curious to get your feedback here, as 
> well.
> My goal would be to have a robust solution here so we don't play whack a mole
> as different compilers make different choices, but obviously without too much
> overhead :)
> 
> Thanks,
> Oliver
> 
> 
> On 4/25/2023 11:32 PM, Wu, Hao A wrote:
> > Thanks Oliver,
> >
> > For the Submission Queue pointer "Sq", I think it is being used to format 
> > the
> command that will be sent to the NVME controller.
> > NvmExpressPassThru() does not read back its content for checking after the
> command gets submitted.
> > My opinion is that it might be not necessary to add volatile attribute for 
> > it.
> >
> > For the Completion Queue pointer "Cq", I am not sure which of the following
> is better:
> > a) Introduce a volatile pointer to "Cq->Pt", or
> > b) Mark "Cq" as volatile
> > Would like to get your feedback on this. Thanks.
> >
> > Best Regards,
> > Hao Wu
> >
> >> -Original Message-
> >> From: devel@edk2.groups.io  On Behalf Of Oliver
> >> Smith-Denny
> >> Sent: Thursday, April 20, 2023 11:48 PM
> >> To: devel@edk2.groups.io; Ni, Ray 
> >> Cc: Wu, Hao A ; Wang, Jian J
> >> ; Gao, Liming ;
> >> Michael Kubacki ; Sean Brogan
> >> 
> >> Subject: Re: [edk2-devel] [PATCH v1 1/2] Add the volatile keyword to
> >> NvmExpressDxe's Passthru CQs and SQs.
> >>
> >> Hi Ray,
> >>
> >> This is not a pure copy from HW to SW memory, we are also polling the
> >> CQ to see if a transaction has completed:
> >>
> >> //
> >> // Wait for completion queue to get filled in.
> >> //
> >> Status = EFI_TIMEOUT;
> >> while (EFI_ERROR (gBS->CheckEvent (TimerEvent))) {
> >>   if (Cq->Pt != Private->Pt[QueueId]) {
> >> Status = EFI_SUCCESS;
> >> break;
> >>   }
> >> }
> >>
> >>
> >> What we have seen happen is that without the volatile keyword, the
> >> compiler can move the Cq->Pt read outside of the loop and only do
> >> register compares inside the loop, i.e. we end up going the full
> >> timeout even if the CQ reports it is finished.
> >>
> >> Here is the issue that was filed on the project Mu side:
> >> https://github.com/microsoft/mu_basecore/issues/324.
> >>
> >> Thanks,
> >> Oliver
> >>
> >> On 4/19/2023 5:48 PM, Ni, Ray wrote:
> >>> If it's to copy from hw to sw memory, why do we need volatile?
> >>>
> >>> Thanks,
> >>> Ray
> >>>
> >>>> -Original Message-
> >>>> From: devel@edk2.groups.io  On Behalf Of
> >>>> Oliver Smith-Denny
> >>>> Sent: Thursday, April 20, 2023 7:41 AM
> >>>> To: devel@edk2.groups.io
> >>>> Cc: Wu, Hao A ; Ni, Ray ;
> >>>> Wang, Jian J ; Gao, Liming
> >

Re: [edk2-devel] [PATCH v1 1/2] Add the volatile keyword to NvmExpressDxe's Passthru CQs and SQs.

2023-04-26 Thread Wu, Hao A
Thanks Oliver,

For the Submission Queue pointer "Sq", I think it is being used to format the 
command that will be sent to the NVME controller.
NvmExpressPassThru() does not read back its content for checking after the 
command gets submitted.
My opinion is that it might be not necessary to add volatile attribute for it.

For the Completion Queue pointer "Cq", I am not sure which of the following is 
better:
a) Introduce a volatile pointer to "Cq->Pt", or
b) Mark "Cq" as volatile
Would like to get your feedback on this. Thanks. 

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Oliver
> Smith-Denny
> Sent: Thursday, April 20, 2023 11:48 PM
> To: devel@edk2.groups.io; Ni, Ray 
> Cc: Wu, Hao A ; Wang, Jian J ;
> Gao, Liming ; Michael Kubacki
> ; Sean Brogan 
> Subject: Re: [edk2-devel] [PATCH v1 1/2] Add the volatile keyword to
> NvmExpressDxe's Passthru CQs and SQs.
> 
> Hi Ray,
> 
> This is not a pure copy from HW to SW memory, we are also polling the CQ to
> see if a transaction has completed:
> 
>//
>// Wait for completion queue to get filled in.
>//
>Status = EFI_TIMEOUT;
>while (EFI_ERROR (gBS->CheckEvent (TimerEvent))) {
>  if (Cq->Pt != Private->Pt[QueueId]) {
>Status = EFI_SUCCESS;
>break;
>  }
>}
> 
> 
> What we have seen happen is that without the volatile keyword, the compiler
> can move the Cq->Pt read outside of the loop and only do register compares
> inside the loop, i.e. we end up going the full timeout even if the CQ reports 
> it is
> finished.
> 
> Here is the issue that was filed on the project Mu side:
> https://github.com/microsoft/mu_basecore/issues/324.
> 
> Thanks,
> Oliver
> 
> On 4/19/2023 5:48 PM, Ni, Ray wrote:
> > If it's to copy from hw to sw memory, why do we need volatile?
> >
> > Thanks,
> > Ray
> >
> >> -Original Message-
> >> From: devel@edk2.groups.io  On Behalf Of Oliver
> >> Smith-Denny
> >> Sent: Thursday, April 20, 2023 7:41 AM
> >> To: devel@edk2.groups.io
> >> Cc: Wu, Hao A ; Ni, Ray ; Wang,
> >> Jian J ; Gao, Liming
> >> ; Michael Kubacki
> >> ; Sean Brogan
> >> 
> >> Subject: [edk2-devel][PATCH v1 1/2] Add the volatile keyword to
> >> NvmExpressDxe's Passthru CQs and SQs.
> >>
> >> This updates the relevant functions that expect a non-volatile
> >>
> >> structure to be passed to them to take casts of the CQ and SQ,
> >>
> >> now that they are volatile.
> >>
> >>
> >>
> >> Cc: Hao A Wu 
> >>
> >> Cc: Ray Ni 
> >>
> >> Cc: Jian J Wang 
> >>
> >> Cc: Liming Gao 
> >>
> >> Cc: Michael Kubacki 
> >>
> >> Cc: Sean Brogan 
> >>
> >> Signed-off-by: Oliver Smith-Denny 
> >>
> >> ---
> >>
> >>   MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c | 10
> >> +-
> >>
> >>   1 file changed, 5 insertions(+), 5 deletions(-)
> >>
> >>
> >>
> >> diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c
> >> b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c
> >>
> >> index f37baa626a16..1a7e39500ac0 100644
> >>
> >> --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c
> >>
> >> +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c
> >>
> >> @@ -459,8 +459,8 @@ NvmExpressPassThru (
> >>
> >> EFI_STATUS Status;
> >>
> >> EFI_STATUS PreviousStatus;
> >>
> >> EFI_PCI_IO_PROTOCOL*PciIo;
> >>
> >> -  NVME_SQ*Sq;
> >>
> >> -  NVME_CQ*Cq;
> >>
> >> +  volatile NVME_SQ   *Sq;
> >>
> >> +  volatile NVME_CQ   *Cq;
> >>
> >> UINT16 QueueId;
> >>
> >> UINT16 QueueSize;
> >>
> >> UINT32 Bytes;
> >>
> >> @@ -581,7 +581,7 @@ NvmExpressPassThru (
> >>
> >>   return EFI_INVALID_PARAMETER;
> >>
> >> }
> >>
> >>
> >>
> >> -  ZeroMem (Sq, sizeof (NVME_SQ));
> >>
> >> +  ZeroMem ((VOID *)Sq, sizeof (NVME_SQ));
> >>
> >> Sq->

Re: [edk2-devel] [PATCHv2 1/1] MdeModulePkg/Ahci: Skip retry for non-transient errors

2023-04-02 Thread Wu, Hao A
Patch merged via:
PR - https://github.com/tianocore/edk2/pull/4207
Commit - 
https://github.com/tianocore/edk2/commit/eb6a74827200eedc81b8f45f332d6e9f3b3d2906

Best Regards,
Hao Wu

From: Anbazhagan, Baraneedharan 
Sent: Wednesday, March 29, 2023 10:30 AM
To: devel@edk2.groups.io; Wu, Hao A ; Albecki, Mateusz 

Cc: Ni, Ray ; Chang, Hunter 
Subject: RE: [edk2-devel] [PATCHv2 1/1] MdeModulePkg/Ahci: Skip retry for 
non-transient errors

Reviewed-by: Baraneedharan Anbazhagan 
mailto:anbazha...@hp.com>>

From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
mailto:devel@edk2.groups.io>> On Behalf Of Wu, Hao A via 
groups.io
Sent: Monday, March 27, 2023 9:03 PM
To: Albecki, Mateusz 
mailto:mateusz.albe...@intel.com>>; 
devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Cc: Ni, Ray mailto:ray...@intel.com>>; Chang, Hunter 
mailto:hunter.ch...@intel.com>>; Anbazhagan, 
Baraneedharan mailto:anbazha...@hp.com>>
Subject: Re: [edk2-devel] [PATCHv2 1/1] MdeModulePkg/Ahci: Skip retry for 
non-transient errors

Reviewed-by: Hao A Wu mailto:hao.a...@intel.com>>
Will wait a couple of days before merging to see if comments from other 
reviewers.

Best Regards,
Hao Wu

> -Original Message-
> From: Albecki, Mateusz 
> mailto:mateusz.albe...@intel.com>>
> Sent: Tuesday, March 28, 2023 5:38 AM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> Cc: Albecki, Mateusz 
> mailto:mateusz.albe...@intel.com>>; Wu, Hao A
> mailto:hao.a...@intel.com>>; Ni, Ray 
> mailto:ray...@intel.com>>; Chang, Hunter
> mailto:hunter.ch...@intel.com>>; Anbazhagan, 
> Baraneedharan
> mailto:anbazha...@hp.com>>
> Subject: [PATCHv2 1/1] MdeModulePkg/Ahci: Skip retry for non-transient errors
>
> Currently AHCI driver will try to retry all failed packets
>
> regardless of the failure cause. This is a problem in password
>
> unlock flow where number of password retries is tracked by the
>
> device. If user passes a wrong password Ahci driver will try
>
> to send the wrong password multiple times which will exhaust
>
> number of password retries and force the user to restart the
>
> machine. This commit introduces a logic to check for the cause
>
> of packet failure and only retry packets which failed due to
>
> transient conditions on the link. With this patch only packets for
>
> which CRC error is flagged are retried.
>
>
>
> Cc: Hao A Wu mailto:hao.a...@intel.com>>
>
> Cc: Ray Ni mailto:ray...@intel.com>>
>
> Cc: Hunter Chang mailto:hunter.ch...@intel.com>>
>
> Cc: Baraneedharan Anbazhagan mailto:anbazha...@hp.com>>
>
>
>
> Signed-off-by: Mateusz Albecki 
> mailto:mateusz.albe...@intel.com>>
>
> ---
>
> .../Bus/Ata/AtaAtapiPassThru/AhciMode.c | 71 +--
>
> .../Bus/Ata/AtaAtapiPassThru/AhciMode.h | 3 +-
>
> 2 files changed, 69 insertions(+), 5 deletions(-)
>
>
>
> diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
> b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
>
> index 06c4a3e052..c0c8ffbd9e 100644
>
> --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
>
> +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
>
> @@ -737,12 +737,68 @@ AhciRecoverPortError (
>
> Status = AhciResetPort (PciIo, Port);
>
> if (EFI_ERROR (Status)) {
>
> DEBUG ((DEBUG_ERROR, "Failed to reset the port %d\n", Port));
>
> + return EFI_DEVICE_ERROR;
>
> }
>
> }
>
>
>
> return EFI_SUCCESS;
>
> }
>
>
>
> +/**
>
> + This function will check if the failed command should be retired. Only error
>
> + conditions which are a result of transient conditions on a link(either to
> system or to device).
>
> +
>
> + @param[in] PciIo Pointer to AHCI controller PciIo.
>
> + @param[in] Port SATA port index on which to check.
>
> +
>
> + @retval TRUE Command failure was caused by transient condition and
> should be retried
>
> + @retval FALSE Command should not be retried
>
> +**/
>
> +BOOLEAN
>
> +AhciShouldCmdBeRetried (
>
> + IN EFI_PCI_IO_PROTOCOL *PciIo,
>
> + IN UINT8 Port
>
> + )
>
> +{
>
> + UINT32 Offset;
>
> + UINT32 PortInterrupt;
>
> + UINT32 Serr;
>
> + UINT32 Tfd;
>
> +
>
> + Offset = EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH +
> EFI_AHCI_PORT_IS;
>
> + PortInterrupt = AhciReadReg (PciIo, Offset);
>
> + Offset = EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH +
> EFI_AHCI_PORT_SERR;
>
> + Serr = AhciReadReg (PciIo, Offset);
>
> + Offset = EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH +
> EFI_AHCI_PORT_TFD;
>
> + Tfd = AhciReadReg (PciIo,

Re: [edk2-devel] [PATCHv2 1/1] MdeModulePkg/Ahci: Skip retry for non-transient errors

2023-03-27 Thread Wu, Hao A
Reviewed-by: Hao A Wu 
Will wait a couple of days before merging to see if comments from other 
reviewers.

Best Regards,
Hao Wu

> -Original Message-
> From: Albecki, Mateusz 
> Sent: Tuesday, March 28, 2023 5:38 AM
> To: devel@edk2.groups.io
> Cc: Albecki, Mateusz ; Wu, Hao A
> ; Ni, Ray ; Chang, Hunter
> ; Anbazhagan, Baraneedharan
> 
> Subject: [PATCHv2 1/1] MdeModulePkg/Ahci: Skip retry for non-transient errors
> 
> Currently AHCI driver will try to retry all failed packets
> 
> regardless of the failure cause. This is a problem in password
> 
> unlock flow where number of password retries is tracked by the
> 
> device. If user passes a wrong password Ahci driver will try
> 
> to send the wrong password multiple times which will exhaust
> 
> number of password retries and force the user to restart the
> 
> machine. This commit introduces a logic to check for the cause
> 
> of packet failure and only retry packets which failed due to
> 
> transient conditions on the link. With this patch only packets for
> 
> which CRC error is flagged are retried.
> 
> 
> 
> Cc: Hao A Wu 
> 
> Cc: Ray Ni 
> 
> Cc: Hunter Chang 
> 
> Cc: Baraneedharan Anbazhagan 
> 
> 
> 
> Signed-off-by: Mateusz Albecki 
> 
> ---
> 
>  .../Bus/Ata/AtaAtapiPassThru/AhciMode.c   | 71 +--
> 
>  .../Bus/Ata/AtaAtapiPassThru/AhciMode.h   |  3 +-
> 
>  2 files changed, 69 insertions(+), 5 deletions(-)
> 
> 
> 
> diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
> b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
> 
> index 06c4a3e052..c0c8ffbd9e 100644
> 
> --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
> 
> +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
> 
> @@ -737,12 +737,68 @@ AhciRecoverPortError (
> 
>  Status = AhciResetPort (PciIo, Port);
> 
>  if (EFI_ERROR (Status)) {
> 
>DEBUG ((DEBUG_ERROR, "Failed to reset the port %d\n", Port));
> 
> +  return EFI_DEVICE_ERROR;
> 
>  }
> 
>}
> 
> 
> 
>return EFI_SUCCESS;
> 
>  }
> 
> 
> 
> +/**
> 
> +  This function will check if the failed command should be retired. Only 
> error
> 
> +  conditions which are a result of transient conditions on a link(either to
> system or to device).
> 
> +
> 
> +  @param[in] PciIoPointer to AHCI controller PciIo.
> 
> +  @param[in] Port SATA port index on which to check.
> 
> +
> 
> +  @retval TRUE   Command failure was caused by transient condition and
> should be retried
> 
> +  @retval FALSE  Command should not be retried
> 
> +**/
> 
> +BOOLEAN
> 
> +AhciShouldCmdBeRetried (
> 
> +  IN EFI_PCI_IO_PROTOCOL  *PciIo,
> 
> +  IN UINT8Port
> 
> +  )
> 
> +{
> 
> +  UINT32  Offset;
> 
> +  UINT32  PortInterrupt;
> 
> +  UINT32  Serr;
> 
> +  UINT32  Tfd;
> 
> +
> 
> +  Offset= EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH +
> EFI_AHCI_PORT_IS;
> 
> +  PortInterrupt = AhciReadReg (PciIo, Offset);
> 
> +  Offset= EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH +
> EFI_AHCI_PORT_SERR;
> 
> +  Serr  = AhciReadReg (PciIo, Offset);
> 
> +  Offset= EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH +
> EFI_AHCI_PORT_TFD;
> 
> +  Tfd   = AhciReadReg (PciIo, Offset);
> 
> +
> 
> +  //
> 
> +  // This can occur if there was a CRC error on a path from system memory to
> 
> +  // host controller.
> 
> +  //
> 
> +  if (PortInterrupt & EFI_AHCI_PORT_IS_HBDS) {
> 
> +return TRUE;
> 
> +//
> 
> +// This can occur if there was a CRC error detected by host during
> communication
> 
> +// with the device
> 
> +//
> 
> +  } else if ((PortInterrupt & (EFI_AHCI_PORT_IS_IFS | EFI_AHCI_PORT_IS_INFS))
> &&
> 
> + (Serr & EFI_AHCI_PORT_SERR_CRCE))
> 
> +  {
> 
> +return TRUE;
> 
> +//
> 
> +// This can occur if there was a CRC error detected by device during
> communication
> 
> +// with the host. Device returns error status to host with D2H FIS.
> 
> +//
> 
> +  } else if ((PortInterrupt & EFI_AHCI_PORT_IS_TFES) &&
> 
> + (Tfd & EFI_AHCI_PORT_TFD_ERR_INT_CRC))
> 
> +  {
> 
> +return TRUE;
> 
> +  }
> 
> +
> 
> +  return FALSE;
> 
> +}
> 
> +
> 
>  /**
> 
>Checks if specified FIS has been received.
> 
> 
> 
> @@ -950,6 +1006,7 @@ AhciPioTransfer (
> 
>UINT32

Re: [edk2-devel] [PATCH 0/1] MdeModulePkg/Ahci: Skip retry for non-transient errors

2023-03-23 Thread Wu, Hao A
Thanks Baranee. We will proceed to merge the this patch after reviewing process.

For the PCD (PcdAhciCommandRetryCount) previously introduced to address the 
password retry issue, what is your opinion on it?
Do you think we can remove it or keep it for other reason? Thanks.

Best Regards,
Hao Wu

From: devel@edk2.groups.io  On Behalf Of Anbazhagan, 
Baraneedharan via groups.io
Sent: Friday, March 24, 2023 12:55 AM
To: devel@edk2.groups.io; Wu, Hao A ; Albecki, Mateusz 

Cc: Ni, Ray ; Chang, Hunter 
Subject: Re: [edk2-devel] [PATCH 0/1] MdeModulePkg/Ahci: Skip retry for 
non-transient errors

Hi,
This patch seems to resolve the issue reported in 4011 - MdeModulePkg: Need 
configurable AHCI command retries 
(tianocore.org)<https://bugzilla.tianocore.org/show_bug.cgi?id=4011> and 
verified with 'AHCI_COMMAND_RETRIES' as 5. Able to unlock the drive with 
correct password on 2nd attempt after providing an incorrect password.

Thanks,
Baranee

From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
mailto:devel@edk2.groups.io>> On Behalf Of Wu, Hao A via 
groups.io
Sent: Wednesday, March 22, 2023 1:59 AM
To: Albecki, Mateusz 
mailto:mateusz.albe...@intel.com>>; Anbazhagan, 
Baraneedharan mailto:anbazha...@hp.com>>; 
devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Cc: Ni, Ray mailto:ray...@intel.com>>; Chang, Hunter 
mailto:hunter.ch...@intel.com>>
Subject: Re: [edk2-devel] [PATCH 0/1] MdeModulePkg/Ahci: Skip retry for 
non-transient errors

CAUTION: External Email
Thanks Mateusz, the patch looks good to me.
I noticed that there are some check failures in 
https://github.com/tianocore/edk2/pull/4157, could you help to address them?


Hello Baraneedharan Anbazhagan,
Could you help to check if this patch can resolve the issue 
https://bugzilla.tianocore.org/show_bug.cgi?id=4011 when switching back to: 
"#define AHCI_COMMAND_RETRIES 5"?
This change can be accessed for integration at: 
https://patch-diff.githubusercontent.com/raw/tianocore/edk2/pull/4157.patch
Thanks in advance.

Best Regards,
Hao Wu

> -Original Message-
> From: Albecki, Mateusz 
> mailto:mateusz.albe...@intel.com>>
> Sent: Wednesday, March 22, 2023 4:20 AM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> Cc: Albecki, Mateusz 
> mailto:mateusz.albe...@intel.com>>; Wu, Hao A
> mailto:hao.a...@intel.com>>; Ni, Ray 
> mailto:ray...@intel.com>>; Chang, Hunter
> mailto:hunter.ch...@intel.com>>
> Subject: [PATCH 0/1] MdeModulePkg/Ahci: Skip retry for non-transient errors
>
> Fix for the recovery logic which causes hdd unlock to fail if user supplies
> incorrect password. Every failed packet used to be recovered which is causing
> the incorrect password to be tried multiple times. This patch series fixes the
> logic to only retry commands that failed due to CRC error.
>
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4011
>
> Github pull: https://github.com/tianocore/edk2/pull/4157
>
> Tests:
> - tested basic linux boot from AHCI on qemu
> - tested basic linux boot from AHCI on custom qemu which will fail 50% of the
> DMA commands with CRC error.
> Observed that all of the packets that failed were successfully retried. Custom
> Qemu: https://github.com/matalbec/qemu/tree/sata_dma_50p_fail
> - additionally Hunter Chang tested and confirmed that the password issue is no
> longer observed.
>
> Cc: Hao A Wu mailto:hao.a...@intel.com>>
> Cc: Ray Ni mailto:ray...@intel.com>>
> Cc: Hunter Chang mailto:hunter.ch...@intel.com>>
>
> Mateusz Albecki (1):
> MdeModulePkg/Ahci: Skip retry for non-transient errors
>
> .../Bus/Ata/AtaAtapiPassThru/AhciMode.c | 69 +--
> .../Bus/Ata/AtaAtapiPassThru/AhciMode.h | 3 +-
> 2 files changed, 67 insertions(+), 5 deletions(-)
>
> --
> 2.39.1.windows.1





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#101713): https://edk2.groups.io/g/devel/message/101713
Mute This Topic: https://groups.io/mt/97764094/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH 0/1] MdeModulePkg/Ahci: Skip retry for non-transient errors

2023-03-22 Thread Wu, Hao A
Thanks Mateusz, the patch looks good to me.
I noticed that there are some check failures in 
https://github.com/tianocore/edk2/pull/4157, could you help to address them?


Hello Baraneedharan Anbazhagan,
Could you help to check if this patch can resolve the issue 
https://bugzilla.tianocore.org/show_bug.cgi?id=4011 when switching back to: 
"#define AHCI_COMMAND_RETRIES 5"?
This change can be accessed for integration at: 
https://patch-diff.githubusercontent.com/raw/tianocore/edk2/pull/4157.patch
Thanks in advance.

Best Regards,
Hao Wu

> -Original Message-
> From: Albecki, Mateusz 
> Sent: Wednesday, March 22, 2023 4:20 AM
> To: devel@edk2.groups.io
> Cc: Albecki, Mateusz ; Wu, Hao A
> ; Ni, Ray ; Chang, Hunter
> 
> Subject: [PATCH 0/1] MdeModulePkg/Ahci: Skip retry for non-transient errors
> 
> Fix for the recovery logic which causes hdd unlock to fail if user supplies
> incorrect password. Every failed packet used to be recovered which is causing
> the incorrect password to be tried multiple times. This patch series fixes the
> logic to only retry commands that failed due to CRC error.
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4011
> 
> Github pull: https://github.com/tianocore/edk2/pull/4157
> 
> Tests:
> - tested basic linux boot from AHCI on qemu
> - tested basic linux boot from AHCI on custom qemu which will fail 50% of the
> DMA commands with CRC error.
>   Observed that all of the packets that failed were successfully retried. 
> Custom
> Qemu: https://github.com/matalbec/qemu/tree/sata_dma_50p_fail
> - additionally Hunter Chang tested and confirmed that the password issue is no
> longer observed.
> 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Cc: Hunter Chang 
> 
> Mateusz Albecki (1):
>   MdeModulePkg/Ahci: Skip retry for non-transient errors
> 
>  .../Bus/Ata/AtaAtapiPassThru/AhciMode.c   | 69 +--
>  .../Bus/Ata/AtaAtapiPassThru/AhciMode.h   |  3 +-
>  2 files changed, 67 insertions(+), 5 deletions(-)
> 
> --
> 2.39.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#101558): https://edk2.groups.io/g/devel/message/101558
Mute This Topic: https://groups.io/mt/97764094/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH 4/5] MdeModulePkg: Consume new alignment-related macros

2023-03-20 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: Gerd Hoffmann 
> Sent: Friday, March 3, 2023 2:51 PM
> To: devel@edk2.groups.io
> Cc: Ard Biesheuvel ; Gerd Hoffmann
> ; Wang, Jian J ; Yao, Jiewen
> ; Marvin Häuser ; James
> Bottomley ; Michael Roth ;
> Wu, Hao A ; Kinney, Michael D
> ; Oliver Steffen ; Xu, Min
> M ; Gao, Liming ; Ni, Ray
> ; Tom Lendacky ; Aktas,
> Erdem ; Liu, Zhiguang ;
> Pawel Polawski ; Justen, Jordan L
> ; Vitaly Cheptsov 
> Subject: [PATCH 4/5] MdeModulePkg: Consume new alignment-related macros
> 
> From: Marvin Häuser 
> 
> This patch substitutes the macros that were renamed in the first
> patch with the new, shared alignment macros.
> 
> Cc: Jian J Wang 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Cc: Vitaly Cheptsov 
> Signed-off-by: Marvin Häuser 
> ---
>  MdeModulePkg/Bus/Ata/AhciPei/AhciPei.h|  3 +-
>  .../Ata/AtaAtapiPassThru/AtaAtapiPassThru.h   |  2 --
>  MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.h   |  1 -
>  MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.h  |  2 --
>  .../Bus/Ufs/UfsBlockIoPei/UfsBlockIoPei.h |  2 --
>  .../Bus/Ufs/UfsPassThruDxe/UfsPassThru.h  |  2 --
>  MdeModulePkg/Universal/EbcDxe/EbcExecute.h|  3 +-
>  MdeModulePkg/Bus/Ata/AhciPei/AhciMode.c   |  2 +-
>  .../Bus/Ata/AhciPei/AhciPeiPassThru.c |  6 ++--
>  .../Ata/AtaAtapiPassThru/AtaAtapiPassThru.c   | 12 +++
>  .../Bus/Ata/AtaBusDxe/AtaPassThruExecute.c|  2 +-
>  MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c  |  4 +--
>  .../Bus/Ufs/UfsPassThruDxe/UfsPassThru.c  |  6 ++--
>  MdeModulePkg/Universal/EbcDxe/EbcExecute.c| 36 +--
>  14 files changed, 36 insertions(+), 47 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.h
> b/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.h
> index 71d34c962ad1..e2e4ba43e7c4 100644
> --- a/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.h
> +++ b/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.h
> @@ -146,8 +146,7 @@ typedef union {
>  #define AHCI_PORT_SERR  0x0030
>  #define AHCI_PORT_CI0x0038
> 
> -#define ADDRESS_IS_ALIGNED_(addr, size)  (((UINTN) (addr) & (size - 1)) == 0)
> -#define TIMER_PERIOD_SECONDS(Seconds)MultU64x32((UINT64)(Seconds),
> 1000)
> +#define TIMER_PERIOD_SECONDS(Seconds)  MultU64x32((UINT64)(Seconds),
> 1000)
> 
>  #pragma pack(1)
> 
> diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h
> b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h
> index 7937886614e1..016fc6890ae9 100644
> --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h
> +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h
> @@ -148,8 +148,6 @@ struct _ATA_NONBLOCK_TASK {
>  #define ATA_ATAPI_TIMEOUT   EFI_TIMER_PERIOD_SECONDS(3)
>  #define ATA_SPINUP_TIMEOUT  EFI_TIMER_PERIOD_SECONDS(10)
> 
> -#define ADDRESS_IS_ALIGNED_(addr, size)  (((UINTN) (addr) & (size - 1)) == 0)
> -
>  #define ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS(a) \
>CR (a, \
>ATA_ATAPI_PASS_THRU_INSTANCE, \
> diff --git a/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.h
> b/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.h
> index 47346e911d47..6bc345f7e777 100644
> --- a/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.h
> +++ b/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.h
> @@ -76,7 +76,6 @@
>  #define ATA_TASK_SIGNATURE  SIGNATURE_32 ('A', 'T', 'S', 'K')
>  #define ATA_DEVICE_SIGNATURESIGNATURE_32 ('A', 'B', 'I', 'D')
>  #define ATA_SUB_TASK_SIGNATURE  SIGNATURE_32 ('A', 'S', 'T', 'S')
> -#define ADDRESS_IS_ALIGNED_(addr, size)  (((UINTN) (addr) & (size - 1)) == 0)
> 
>  //
>  // ATA bus data structure for ATA controller
> diff --git a/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.h
> b/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.h
> index ed384ad52182..5a25b55c4952 100644
> --- a/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.h
> +++ b/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.h
> @@ -38,8 +38,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  #define IS_DEVICE_FIXED(a)  (a)->FixedDevice ? 1 : 0
> 
> -#define ADDRESS_IS_ALIGNED_(addr, size)  (((UINTN) (addr) & (size - 1)) == 0)
> -
>  #define UFS_WLUN_RPMB  0xC4
> 
>  typedef struct {
> diff --git a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsBlockIoPei.h
> b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsBlockIoPei.h
> index 1adb382aa8c3..ed4776f548e0 100644
> --- a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsBlockIoPei.h
> +++ b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsBlockIoPei.h
> @@ -133,8 +133,6 @@ typedef struct _UFS_PEIM_HC_PRIVATE_DATA {
> 
>  #define ROUNDUP8(x)  (((x) % 8 == 0) ? (x) : ((x) / 8 + 1) * 8)
> 
> -#define ADDRESS_IS_ALIGNED_(addr, size)  (((UINTN) (addr) & (size - 1)) == 0)
> -
>  #define GE

Re: [edk2-devel] [PATCH 1/5] MdeModulePkg: Rename IS_ALIGNED macros to avoid name collisions

2023-03-20 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: Gerd Hoffmann 
> Sent: Friday, March 3, 2023 2:51 PM
> To: devel@edk2.groups.io
> Cc: Ard Biesheuvel ; Gerd Hoffmann
> ; Wang, Jian J ; Yao, Jiewen
> ; Marvin Häuser ; James
> Bottomley ; Michael Roth ;
> Wu, Hao A ; Kinney, Michael D
> ; Oliver Steffen ; Xu, Min
> M ; Gao, Liming ; Ni, Ray
> ; Tom Lendacky ; Aktas,
> Erdem ; Liu, Zhiguang ;
> Pawel Polawski ; Justen, Jordan L
> 
> Subject: [PATCH 1/5] MdeModulePkg: Rename IS_ALIGNED macros to avoid
> name collisions
> 
> From: Marvin Häuser 
> 
> This patch is a preparation for the patches that follow. The
> subsequent patches will introduce and integrate new alignment-related
> macros, which collide with existing definitions in MdeModulePkg.
> Temporarily rename them to avoid build failure, till they can be
> substituted with the new, shared definitions.
> 
> Cc: Jian J Wang 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Signed-off-by: Marvin Häuser 
> ---
>  MdeModulePkg/Bus/Ata/AhciPei/AhciPei.h|  4 +--
>  .../Ata/AtaAtapiPassThru/AtaAtapiPassThru.h   |  2 +-
>  MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.h   |  2 +-
>  MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.h  |  2 +-
>  .../Bus/Ufs/UfsBlockIoPei/UfsBlockIoPei.h |  2 +-
>  .../Bus/Ufs/UfsPassThruDxe/UfsPassThru.h  |  2 +-
>  MdeModulePkg/Universal/EbcDxe/EbcExecute.h|  4 +--
>  MdeModulePkg/Bus/Ata/AhciPei/AhciMode.c   |  2 +-
>  .../Bus/Ata/AhciPei/AhciPeiPassThru.c |  6 ++--
>  .../Ata/AtaAtapiPassThru/AtaAtapiPassThru.c   | 12 +++
>  .../Bus/Ata/AtaBusDxe/AtaPassThruExecute.c|  2 +-
>  MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c  |  4 +--
>  .../Bus/Ufs/UfsPassThruDxe/UfsPassThru.c  |  6 ++--
>  MdeModulePkg/Universal/EbcDxe/EbcExecute.c| 36 +--
>  14 files changed, 43 insertions(+), 43 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.h
> b/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.h
> index 4aed1cb7ad8a..71d34c962ad1 100644
> --- a/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.h
> +++ b/MdeModulePkg/Bus/Ata/AhciPei/AhciPei.h
> @@ -146,8 +146,8 @@ typedef union {
>  #define AHCI_PORT_SERR  0x0030
>  #define AHCI_PORT_CI0x0038
> 
> -#define IS_ALIGNED(addr, size) (((UINTN) (addr) & (size - 1)) == 0)
> -#define TIMER_PERIOD_SECONDS(Seconds)  MultU64x32((UINT64)(Seconds),
> 1000)
> +#define ADDRESS_IS_ALIGNED_(addr, size)  (((UINTN) (addr) & (size - 1)) == 0)
> +#define TIMER_PERIOD_SECONDS(Seconds)MultU64x32((UINT64)(Seconds),
> 1000)
> 
>  #pragma pack(1)
> 
> diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h
> b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h
> index 62ba6d6680dd..7937886614e1 100644
> --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h
> +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h
> @@ -148,7 +148,7 @@ struct _ATA_NONBLOCK_TASK {
>  #define ATA_ATAPI_TIMEOUT   EFI_TIMER_PERIOD_SECONDS(3)
>  #define ATA_SPINUP_TIMEOUT  EFI_TIMER_PERIOD_SECONDS(10)
> 
> -#define IS_ALIGNED(addr, size)  (((UINTN) (addr) & (size - 1)) == 0)
> +#define ADDRESS_IS_ALIGNED_(addr, size)  (((UINTN) (addr) & (size - 1)) == 0)
> 
>  #define ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS(a) \
>CR (a, \
> diff --git a/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.h
> b/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.h
> index 4428c484fd6c..47346e911d47 100644
> --- a/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.h
> +++ b/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.h
> @@ -76,7 +76,7 @@
>  #define ATA_TASK_SIGNATURE  SIGNATURE_32 ('A', 'T', 'S', 'K')
>  #define ATA_DEVICE_SIGNATURESIGNATURE_32 ('A', 'B', 'I', 'D')
>  #define ATA_SUB_TASK_SIGNATURE  SIGNATURE_32 ('A', 'S', 'T', 'S')
> -#define IS_ALIGNED(addr, size)  (((UINTN) (addr) & (size - 1)) == 0)
> +#define ADDRESS_IS_ALIGNED_(addr, size)  (((UINTN) (addr) & (size - 1)) == 0)
> 
>  //
>  // ATA bus data structure for ATA controller
> diff --git a/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.h
> b/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.h
> index 5b4047e1dbdd..ed384ad52182 100644
> --- a/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.h
> +++ b/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.h
> @@ -38,7 +38,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  #define IS_DEVICE_FIXED(a)  (a)->FixedDevice ? 1 : 0
> 
> -#define IS_ALIGNED(addr, size)  (((UINTN) (addr) & (size - 1)) == 0)
> +#define ADDRESS_IS_ALIGNED_(addr, size)  (((UINTN) (addr) & (size - 1)) == 0)
> 
>  #define UFS_WLUN_RPMB  0xC4
> 
> diff --git a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsBlockIoPei.h
> b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/Uf

Re: [edk2-devel] [PATCH v2 1/1] MdeModulePkg: Improve formatting of DEBUG messages in UsbBusDxe

2023-03-07 Thread Wu, Hao A
Merged via:
PR - https://github.com/tianocore/edk2/pull/4102
Commit - 
https://github.com/tianocore/edk2/commit/46f51898ff716e53921b93e8d78af0fc7d06a2f9

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Wu, Hao A
> Sent: Monday, February 27, 2023 1:16 PM
> To: Rebecca Cran ; devel@edk2.groups.io; Wang, Jian J
> ; Gao, Liming ; Ni, Ray
> 
> Subject: Re: [edk2-devel] [PATCH v2 1/1] MdeModulePkg: Improve formatting
> of DEBUG messages in UsbBusDxe
> 
> Reviewed-by: Hao A Wu .
> Will merge it after the upcoming stable tag announcement.
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: Rebecca Cran 
> > Sent: Friday, February 24, 2023 8:18 AM
> > To: devel@edk2.groups.io; Wang, Jian J ; Gao,
> > Liming ; Wu, Hao A ; Ni,
> > Ray 
> > Cc: Rebecca Cran 
> > Subject: [PATCH v2 1/1] MdeModulePkg: Improve formatting of DEBUG
> > messages in UsbBusDxe
> >
> > Improve the formatting of DEBUG messages in UsbBusDxe by adding a
> > hyphen to separate the EFI_STATUS code.
> >
> > Signed-off-by: Rebecca Cran 
> > ---
> >  MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c| 12 ++--
> >  MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c   |  6 +++---
> >  MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c |  2 +-
> >  MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c|  2 +-
> >  4 files changed, 11 insertions(+), 11 deletions(-)
> >
> > diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> > b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> > index 6a3ac63c3aa0..c25f3cc2f279 100644
> > --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> > +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> > @@ -838,7 +838,7 @@ UsbIoPortReset (
> >if (EFI_ERROR (Status)) {
> >  DEBUG ((
> >DEBUG_ERROR,
> > -  "UsbIoPortReset: failed to reset hub port %d@hub  %d, %r \n",
> > +  "UsbIoPortReset: failed to reset hub port %d@hub  %d - %r\n",
> >Dev->ParentPort,
> >Dev->ParentAddr,
> >Status
> > @@ -945,7 +945,7 @@ UsbBusBuildProtocol (
> >);
> >
> >if (EFI_ERROR (Status)) {
> > -DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to open device path %r\n",
> > Status));
> > +DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to open device path -
> > + %r\n",
> > Status));
> >
> >  FreePool (UsbBus);
> >  return Status;
> > @@ -978,7 +978,7 @@ UsbBusBuildProtocol (
> > );
> >
> >if (EFI_ERROR (Status) && EFI_ERROR (Status2)) {
> > -DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to open
> > USB_HC/USB2_HC %r\n", Status));
> > +DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to open USB_HC/USB2_HC
> > + -
> >  %r\n", Status));
> >
> >  Status = EFI_DEVICE_ERROR;
> >  goto CLOSE_HC;
> > @@ -1006,7 +1006,7 @@ UsbBusBuildProtocol (
> >);
> >
> >if (EFI_ERROR (Status)) {
> > -DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to install bus protocol 
> > %r\n",
> > Status));
> > +DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to install bus protocol
> > + - %r\n",
> > Status));
> >  goto CLOSE_HC;
> >}
> >
> > @@ -1054,7 +1054,7 @@ UsbBusBuildProtocol (
> >Status = mUsbRootHubApi.Init (RootIf);
> >
> >if (EFI_ERROR (Status)) {
> > -DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to init root hub %r\n",
> > Status));
> > +DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to init root hub -
> > + %r\n",
> > Status));
> >  goto FREE_ROOTHUB;
> >}
> >
> > @@ -1102,7 +1102,7 @@ UsbBusBuildProtocol (
> >   );
> >FreePool (UsbBus);
> >
> > -  DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to start bus driver
> > %r\n", Status));
> > +  DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to start bus driver -
> > + %r\n",
> > Status));
> >return Status;
> >  }
> >
> > diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
> > b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
> > index a620a670748c..8b078e7e4936 100644
> > --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
> > +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
> > @@ -761,7 +761,7 @@ UsbGetOneConfig (
> >if (EFI_ERROR (Status)) {
> >  DEBUG ((
> >DEBUG_ERROR,
> > -  "UsbGetOneConfig: failed to get descript length(%d

Re: [edk2-devel] [edk2-platform][PATCH 1/1] MdeModulePkg: SdMmcPciHcDxe: Support for Bayhub SD/eMMC host

2023-02-27 Thread Wu, Hao A
Thanks for the patch.
The proposed method is not the intended way for the EDKII_SD_MMC_OVERRIDE 
protocol to work.

The content in BayhubHost.c should be placed a platform level driver.
This platform level driver should produce the EDKII_SD_MMC_OVERRIDE protocol.
Then SdMmcPciHcDxe will consume the protocol to perform the platform specific 
actions.

Best Regards,
Hao Wu

> -Original Message-
> From: Chevron Li 
> Sent: Friday, February 24, 2023 8:40 PM
> To: devel@edk2.groups.io
> Cc: Wu, Hao A ; Ni, Ray ; Wang,
> Jian J ; Gao, Liming ;
> shaper@bayhubtech.com; chevron...@bayhubtech.com;
> xiaoguang...@bayhubtech.com; shirley@bayhubtech.com
> Subject: [edk2-platform][PATCH 1/1] MdeModulePkg: SdMmcPciHcDxe:
> Support for Bayhub SD/eMMC host
> 
> From: "Chevron Li (WH)" 
> 
> 1.Implement override function for EdkiiSdMmcInitHostPre case to
> configure bayhub host.
> 2.Implement override function for EdkiiSdMmcInitHostPost case to
> configure bayhub host.
> 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Cc: Jian J Wang 
> Cc: Liming Gao 
> Signed-off-by: Chevron Li 
> ---
>  .../Bus/Pci/SdMmcPciHcDxe/BayhubHost.c| 676 ++
>  .../Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c |   3 +
>  .../Bus/Pci/SdMmcPciHcDxe/BayhubHost.h|  95 +++
>  .../Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf   |   2 +
>  4 files changed, 776 insertions(+)
>  create mode 100644
> MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/BayhubHost.c
>  create mode 100644
> MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/BayhubHost.h
> 
> diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/BayhubHost.c
> b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/BayhubHost.c
> new file mode 100644
> index 00..470838e37e
> --- /dev/null
> +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/BayhubHost.c
> @@ -0,0 +1,676 @@
> +/** @file
> +  This driver is used to manage SD/MMC PCI host controllers override
> function
> +  for BayHub SD/eMMC host controller.
> +
> +  Copyright (c) 2018 - 2019, BayHub Tech inc. All rights reserved.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include "BayhubHost.h"
> +#include "SdMmcPciHcDxe.h"
> +#include 
> +
> +/* Driver global variables*/
> +UINT16  BhtDeviceId = 0;
> +
> +EDKII_SD_MMC_OVERRIDE  BhtOverride = {
> +  EDKII_SD_MMC_OVERRIDE_PROTOCOL_VERSION,
> +  BhtHostOverrideCapability,
> +  BhtHostOverrideNotifyPhase
> +};
> +
> +/**
> +  Judgement function for Host type
> +
> +  @param[in]  PciIo  The PCI IO protocol instance.
> +
> +  @retval UNSUPPORT  The host isn't Bayhub host.
> +  @retval EMMC_HOST  The host is Bayhub eMMC host.
> +  @retval SD_HOSTThe host is Bayhub SD host.
> +
> +**/
> +UINT8
> +BhtHostPciSupportType (
> +  IN EFI_PCI_IO_PROTOCOL  *PciIo
> +  )
> +{
> +  PCI_TYPE00  Pci;
> +  UINT8   HostType;
> +
> +  PciIo->Pci.Read (
> +   PciIo,
> +   EfiPciIoWidthUint32,
> +   0,
> +   sizeof (PCI_TYPE00) / sizeof (UINT32),
> +   
> +   );
> +  DEBUG ((DEBUG_INFO, "Check device %04x:%04x\n", Pci.Hdr.VendorId,
> Pci.Hdr.DeviceId));
> +
> +  // Judgement bayhub device or not
> +  if (Pci.Hdr.VendorId != 0x1217) {
> +HostType = UNSUPPORT;
> +goto end;
> +  }
> +
> +  BhtDeviceId = Pci.Hdr.DeviceId;
> +
> +  // Bayhub host only 0x8620 is eMMC host
> +  switch (Pci.Hdr.DeviceId) {
> +case PCI_DEV_ID_SB0:
> +  HostType = EMMC_HOST;
> +  break;
> +case PCI_DEV_ID_SB1:
> +default:
> +  HostType = SD_HOST;
> +  break;
> +  }
> +
> +end:
> +  return HostType;
> +}
> +
> +/**
> +  Read specified SD/MMC host controller mmio register
> +
> +  @param[in]  PciIoThe PCI IO protocol instance.
> +  @param[in]  Offset   The Offset within the selected BAR to start 
> the
> +   memory operation.
> +
> +  @retval ValueThe value of specified SD/MMC host controller
> mmio register.
> +
> +**/
> +UINT32
> +BhtMmRead32 (
> +  IN EFI_PCI_IO_PROTOCOL  *PciIo,
> +  IN UINT32   Offset
> +  )
> +{
> +  UINT32  Value;
> +
> +  PciIo->Mem.Read (PciIo, EfiPciIoWidthUint32, 1, Offset, 1, );
> +  return Value;
> +}
> +
> +/**
> +  Write specified SD/MMC host controller mmio register
> +
> +  @param[in]  PciIoThe PCI IO protocol instance.
> +  @param[in]  Offset   The Offset within the selected BAR to start 
> the
> +   memory operation.
> +  @param[in]  

Re: [edk2-devel] [PATCH v2 1/1] MdeModulePkg: Improve formatting of DEBUG messages in UsbBusDxe

2023-02-26 Thread Wu, Hao A
Reviewed-by: Hao A Wu .
Will merge it after the upcoming stable tag announcement.

Best Regards,
Hao Wu

> -Original Message-
> From: Rebecca Cran 
> Sent: Friday, February 24, 2023 8:18 AM
> To: devel@edk2.groups.io; Wang, Jian J ; Gao, Liming
> ; Wu, Hao A ; Ni, Ray
> 
> Cc: Rebecca Cran 
> Subject: [PATCH v2 1/1] MdeModulePkg: Improve formatting of DEBUG
> messages in UsbBusDxe
> 
> Improve the formatting of DEBUG messages in UsbBusDxe by adding
> a hyphen to separate the EFI_STATUS code.
> 
> Signed-off-by: Rebecca Cran 
> ---
>  MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c| 12 ++--
>  MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c   |  6 +++---
>  MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c |  2 +-
>  MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c|  2 +-
>  4 files changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> index 6a3ac63c3aa0..c25f3cc2f279 100644
> --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> @@ -838,7 +838,7 @@ UsbIoPortReset (
>if (EFI_ERROR (Status)) {
>  DEBUG ((
>DEBUG_ERROR,
> -  "UsbIoPortReset: failed to reset hub port %d@hub  %d, %r \n",
> +  "UsbIoPortReset: failed to reset hub port %d@hub  %d - %r\n",
>Dev->ParentPort,
>Dev->ParentAddr,
>Status
> @@ -945,7 +945,7 @@ UsbBusBuildProtocol (
>);
> 
>if (EFI_ERROR (Status)) {
> -DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to open device path %r\n",
> Status));
> +DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to open device path - %r\n",
> Status));
> 
>  FreePool (UsbBus);
>  return Status;
> @@ -978,7 +978,7 @@ UsbBusBuildProtocol (
> );
> 
>if (EFI_ERROR (Status) && EFI_ERROR (Status2)) {
> -DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to open
> USB_HC/USB2_HC %r\n", Status));
> +DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to open USB_HC/USB2_HC -
>  %r\n", Status));
> 
>  Status = EFI_DEVICE_ERROR;
>  goto CLOSE_HC;
> @@ -1006,7 +1006,7 @@ UsbBusBuildProtocol (
>);
> 
>if (EFI_ERROR (Status)) {
> -DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to install bus protocol %r\n",
> Status));
> +DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to install bus protocol - 
> %r\n",
> Status));
>  goto CLOSE_HC;
>}
> 
> @@ -1054,7 +1054,7 @@ UsbBusBuildProtocol (
>Status = mUsbRootHubApi.Init (RootIf);
> 
>if (EFI_ERROR (Status)) {
> -DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to init root hub %r\n",
> Status));
> +DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to init root hub - %r\n",
> Status));
>  goto FREE_ROOTHUB;
>}
> 
> @@ -1102,7 +1102,7 @@ UsbBusBuildProtocol (
>   );
>FreePool (UsbBus);
> 
> -  DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to start bus driver %r\n",
> Status));
> +  DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to start bus driver - %r\n",
> Status));
>return Status;
>  }
> 
> diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
> b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
> index a620a670748c..8b078e7e4936 100644
> --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
> +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
> @@ -761,7 +761,7 @@ UsbGetOneConfig (
>if (EFI_ERROR (Status)) {
>  DEBUG ((
>DEBUG_ERROR,
> -  "UsbGetOneConfig: failed to get descript length(%d) %r\n",
> +  "UsbGetOneConfig: failed to get descript length(%d) - %r\n",
>Desc.TotalLength,
>Status
>));
> @@ -787,7 +787,7 @@ UsbGetOneConfig (
>Status = UsbCtrlGetDesc (UsbDev, USB_DESC_TYPE_CONFIG, Index, 0, Buf,
> Desc.TotalLength);
> 
>if (EFI_ERROR (Status)) {
> -DEBUG ((DEBUG_ERROR, "UsbGetOneConfig: failed to get full
> descript %r\n", Status));
> +DEBUG ((DEBUG_ERROR, "UsbGetOneConfig: failed to get full descript -
>  %r\n", Status));
> 
>  FreePool (Buf);
>  return NULL;
> @@ -891,7 +891,7 @@ UsbBuildDescTable (
>Status = UsbBuildLangTable (UsbDev);
> 
>if (EFI_ERROR (Status)) {
> -DEBUG ((DEBUG_INFO, "UsbBuildDescTable: get language ID table %r\n",
> Status));
> +DEBUG ((DEBUG_INFO, "UsbBuildDescTable: get language ID table - %r\n",
> Status));
>}
> 
>return EFI_SUCCESS;
> diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c
> b/MdeModulePkg/Bus/Usb/UsbBusDxe/Usb

Re: [edk2-devel] [PATCH 1/1] MdeModulePkg: Improve formatting of warning DEBUG in UsbSelectConfig

2023-02-22 Thread Wu, Hao A
If you think the format modification is valuable, please at least keep it 
aligned within the driver level.

A search of the keyword '%r' in UsbBusDxe shows:
  edk2\MdeModulePkg\Bus\Usb\UsbBusDxe\UsbBus.c (8 hits)
Line  841:   "UsbIoPortReset: failed to reset hub port %d@hub  %d, 
%r \n",
Line  870:   "UsbIoPortReset: failed to set address for device %d - 
%r\n",
Line  890: "UsbIoPortReset: failed to set configure for device 
%d - %r\n",
Line  948: DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to open device 
path %r\n", Status));
Line  981: DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to open 
USB_HC/USB2_HC %r\n", Status));
Line 1009: DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to install bus 
protocol %r\n", Status));
Line 1057: DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to init root 
hub %r\n", Status));
Line 1105:   DEBUG ((DEBUG_ERROR, "UsbBusStart: Failed to start bus 
driver %r\n", Status));
  edk2\MdeModulePkg\Bus\Usb\UsbBusDxe\UsbDesc.c (4 hits)
Line  764:   "UsbGetOneConfig: failed to get descript length(%d) 
%r\n",
Line  790: DEBUG ((DEBUG_ERROR, "UsbGetOneConfig: failed to get 
full descript %r\n", Status));
Line  829: DEBUG ((DEBUG_ERROR, "UsbBuildDescTable: failed to get 
device descriptor - %r\n", Status));
Line  894: DEBUG ((DEBUG_INFO, "UsbBuildDescTable: get language ID 
table %r\n", Status));
  edk2\MdeModulePkg\Bus\Usb\UsbBusDxe\UsbEnumer.c (9 hits)
Line  153: DEBUG ((DEBUG_ERROR, "UsbCreateInterface: failed to 
install UsbIo - %r\n", Status));
Line  172: DEBUG ((DEBUG_ERROR, "UsbCreateInterface: failed to open 
host for child - %r\n", Status));
Line  443: "UsbSelectConfig: failed to connect driver (%r), 
ignored\n",
Line  693:   DEBUG ((DEBUG_ERROR, "UsbEnumerateNewDev: failed to 
reset port %d - %r\n", Port, Status));
Line  794: DEBUG ((DEBUG_ERROR, "UsbEnumerateNewDev: failed to set 
device address - %r\n", Status));
Line  809: DEBUG ((DEBUG_ERROR, "UsbEnumerateNewDev: failed to get 
max packet for EP 0 - %r\n", Status));
Line  822: DEBUG ((DEBUG_ERROR, "UsbEnumerateNewDev: failed to 
build descriptor table - %r\n", Status));
Line  834: DEBUG ((DEBUG_ERROR, "UsbEnumerateNewDev: failed to set 
configure %d - %r\n", Config, Status));
Line  846: DEBUG ((DEBUG_ERROR, "UsbEnumerateNewDev: failed to 
create interfaces - %r\n", Status));
  edk2\MdeModulePkg\Bus\Usb\UsbBusDxe\UsbHub.c (5 hits)
Line  510:   DEBUG ((DEBUG_ERROR, "UsbOnHubInterrupt: failed to 
remove async transfer - %r\n", Status));
Line  525:   DEBUG ((DEBUG_ERROR, "UsbOnHubInterrupt: failed to 
submit new async transfer - %r\n", Status));
Line  612: DEBUG ((DEBUG_ERROR, "UsbHubInit: failed to read HUB 
descriptor %r\n", Status));
Line  671:   "UsbHubInit: failed to create signal for hub %d - 
%r\n",
Line  700:   "UsbHubInit: failed to queue interrupt transfer for 
hub %d - %r\n",

I found that most of them follows the pattern "... - %r ...".
Not sure if this format is good enough to you.

Best Regards,
Hao Wu

> -Original Message-
> From: Rebecca Cran 
> Sent: Wednesday, February 22, 2023 7:43 PM
> To: devel@edk2.groups.io; Wu, Hao A ; Wang, Jian J
> ; Gao, Liming ; Ni, Ray
> 
> Subject: Re: [edk2-devel] [PATCH 1/1] MdeModulePkg: Improve formatting of
> warning DEBUG in UsbSelectConfig
> 
> That's the only USB debug message I noticed that seemed unclear.
> 
> Looking through the code I see a few others that could also be improved:
> 
> 
> MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
> 764:  "UsbGetOneConfig: failed to get descript length(%d) %r\n",
> 790:    DEBUG ((DEBUG_ERROR, "UsbGetOneConfig: failed to get full
> descript %r\n", Status));
> 894:    DEBUG ((DEBUG_INFO, "UsbBuildDescTable: get language ID table %r\n",
> Status));
> 
> 
> --
> 
> Rebecca Cran
> 
> 
> On 2/22/23 12:19 AM, Wu, Hao A wrote:
> > Sorry, may I know why only this specific debug message requests format
> improving while others do not?
> >
> > Best Regards,
> > Hao Wu
> >
> >> -Original Message-
> >> From: devel@edk2.groups.io  On Behalf Of
> >> Rebecca Cran
> >> Sent: Tuesday, February 21, 2023 8:52 AM
> >> To: devel@edk2.groups.io; Wang, Jian J ; Gao,
> >> Liming ; Wu, Hao A ;
> >> Ni, Ray 
> >> Cc: Rebecca Cran 
> >> Subject: [edk2-

Re: [edk2-devel] [PATCH 1/1] MdeModulePkg: Improve formatting of warning DEBUG in UsbSelectConfig

2023-02-21 Thread Wu, Hao A
Sorry, may I know why only this specific debug message requests format 
improving while others do not?

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Rebecca
> Cran
> Sent: Tuesday, February 21, 2023 8:52 AM
> To: devel@edk2.groups.io; Wang, Jian J ; Gao, Liming
> ; Wu, Hao A ; Ni, Ray
> 
> Cc: Rebecca Cran 
> Subject: [edk2-devel] [PATCH 1/1] MdeModulePkg: Improve formatting of
> warning DEBUG in UsbSelectConfig
> 
> Improve the formatting of a warning in UsbSelectConfig by adding parentheses
> around the EFI_STATUS value.
> 
> Signed-off-by: Rebecca Cran 
> ---
>  MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c
> b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c
> index aed34596f469..29a6419c3c86 100644
> --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c
> +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c
> @@ -440,7 +440,7 @@ UsbSelectConfig (
>  if (EFI_ERROR (Status)) {
>DEBUG ((
>  DEBUG_WARN,
> -"UsbSelectConfig: failed to connect driver %r, ignored\n",
> +"UsbSelectConfig: failed to connect driver (%r), ignored\n",
>  Status
>  ));
>  }
> --
> 2.30.2
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#100433): https://edk2.groups.io/g/devel/message/100433
Mute This Topic: https://groups.io/mt/97099772/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 2/2] MdePkg: Add NVMe boot partition header definition

2023-02-05 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: Zhu, Weipu 
> Sent: Thursday, February 2, 2023 2:42 PM
> To: devel@edk2.groups.io
> Cc: Zhu, Weipu ; Wu, Hao A ;
> Kinney, Michael D ; Gao, Liming
> ; Liu, Zhiguang 
> Subject: [PATCH v2 2/2] MdePkg: Add NVMe boot partition header definition
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4304
> 
> Add NVMe boot partition header definition to NVMe.h
> according to NVMe spec 2.0.
> 
> Signed-off-by: Weipu Zhu 
> Cc: Hao Wu 
> Cc: Michael D Kinney 
> Cc: Liming Gao 
> Cc: Zhiguang Liu 
> ---
>  MdePkg/Include/IndustryStandard/Nvme.h | 13 +
>  1 file changed, 13 insertions(+)
> 
> diff --git a/MdePkg/Include/IndustryStandard/Nvme.h
> b/MdePkg/Include/IndustryStandard/Nvme.h
> index 3b4e9fe67c..8b8a1bb7f3 100644
> --- a/MdePkg/Include/IndustryStandard/Nvme.h
> +++ b/MdePkg/Include/IndustryStandard/Nvme.h
> @@ -546,6 +546,19 @@ typedef struct {
>  #define NVME_RPMB_RESULT_AUTHKEY_NOT_PROGRAMMED  0x07
>  #define NVME_RPMB_RESULT_INVALID_DCB 0x08
> 
> +//
> +// Get Log Page - Boot Partition Log Header.
> +// (ref. NVMe Base spec. v2.0 Figure 262).
> +//
> +typedef struct {
> +  UINT8 LogIdentifier;   /* Log Identifier, shall be set to 15h */
> +  UINT8 Rsvd1[3];
> +  UINT32Bpsz  : 15;  /* Boot Partition Size */
> +  UINT32Rsvd2 : 16;
> +  UINT32Abpid : 1;   /* Active Boot Partition ID */
> +  UINT8 Rsvd3[8];
> +} NVME_BOOT_PARTITION_HEADER;
> +
>  //
>  // NvmExpress Admin Identify Cmd
>  //
> --
> 2.37.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#99652): https://edk2.groups.io/g/devel/message/99652
Mute This Topic: https://groups.io/mt/96695516/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 1/2] MdePkg: Add RPMB related commands and DCB definition for NVMe

2023-02-05 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: Zhu, Weipu 
> Sent: Thursday, February 2, 2023 2:42 PM
> To: devel@edk2.groups.io
> Cc: Zhu, Weipu ; Wu, Hao A ;
> Kinney, Michael D ; Gao, Liming
> ; Liu, Zhiguang 
> Subject: [PATCH v2 1/2] MdePkg: Add RPMB related commands and DCB
> definition for NVMe
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4303
> 
> 
> 
> Add RPMB(Replay Protected Memory Block) access commands,
> 
> result and DCB(Device Configuration Block) definition for
> 
> NVMe according to the NVMe spec 2.0.
> 
> 
> 
> Signed-off-by: Weipu Zhu 
> 
> Cc: Hao Wu 
> 
> Cc: Michael D Kinney 
> 
> Cc: Liming Gao 
> 
> Cc: Zhiguang Liu 
> 
> ---
> 
>  MdePkg/Include/IndustryStandard/Nvme.h | 46
> +-
> 
>  1 file changed, 45 insertions(+), 1 deletion(-)
> 
> 
> 
> diff --git a/MdePkg/Include/IndustryStandard/Nvme.h
> b/MdePkg/Include/IndustryStandard/Nvme.h
> 
> index 4a1d92c45d..3b4e9fe67c 100644
> 
> --- a/MdePkg/Include/IndustryStandard/Nvme.h
> 
> +++ b/MdePkg/Include/IndustryStandard/Nvme.h
> 
> @@ -2,12 +2,13 @@
> 
>Definitions based on NVMe spec. version 1.1.
> 
> 
> 
>(C) Copyright 2016 Hewlett Packard Enterprise Development LP
> 
> -  Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.
> 
> +  Copyright (c) 2017 - 2023, Intel Corporation. All rights reserved.
> 
>SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> 
> 
>@par Specification Reference:
> 
>NVMe Specification 1.1
> 
>NVMe Specification 1.4
> 
> +  NVMe Specification 2.0
> 
> 
> 
>  **/
> 
> 
> 
> @@ -502,6 +503,49 @@ typedef struct {
> 
>// UINT8*Data; /* Data to be written or read 
> by signed
> access where M = 512 * Sector Count. */
> 
>  } NVME_RPMB_DATA_FRAME;
> 
> 
> 
> +//
> 
> +// RPMB Device Configuration Block Data Structure.
> 
> +// (ref. NVMe Base spec. v2.0 Figure 460).
> 
> +//
> 
> +typedef struct {
> 
> +  UINT8BPPEnable; /* Boot Partition Protection Enabled */
> 
> +  UINT8BPLock;/* Boot Partition Lock */
> 
> +  UINT8NameSpaceWrP;  /* Namespace Write Protection */
> 
> +  UINT8Rsvd1[509];/* Reserved as of Nvm Express 2.0 Spec */
> 
> +} NVME_RPMB_DCB;
> 
> +
> 
> +//
> 
> +// RPMB Request and Response Message Types.
> 
> +// (ref. NVMe Base spec. v2.0 Figure 461).
> 
> +//
> 
> +#define NVME_RPMB_AUTHKEY_PROGRAM   0x0001
> 
> +#define NVME_RPMB_COUNTER_READ  0x0002
> 
> +#define NVME_RPMB_AUTHDATA_WRITE0x0003
> 
> +#define NVME_RPMB_AUTHDATA_READ 0x0004
> 
> +#define NVME_RPMB_RESULT_READ   0x0005
> 
> +#define NVME_RPMB_DCB_WRITE 0x0006
> 
> +#define NVME_RPMB_DCB_READ  0x0007
> 
> +#define NVME_RPMB_AUTHKEY_PROGRAM_RESPONSE  0x0100
> 
> +#define NVME_RPMB_COUNTER_READ_RESPONSE 0x0200
> 
> +#define NVME_RPMB_AUTHDATA_WRITE_RESPONSE   0x0300
> 
> +#define NVME_RPMB_AUTHDATA_READ_RESPONSE0x0400
> 
> +#define NVME_RPMB_DCB_WRITE_RESPONSE0x0600
> 
> +#define NVME_RPMB_DCB_READ_RESPONSE 0x0700
> 
> +
> 
> +//
> 
> +// RPMB Operation Result.
> 
> +// (ref. NVMe Base spec. v2.0 Figure 462).
> 
> +//
> 
> +#define NVME_RPMB_RESULT_SUCCESS 0x00
> 
> +#define NVME_RPMB_RESULT_GENERAL_FAILURE 0x01
> 
> +#define NVME_RPMB_RESULT_AHTHENTICATION_FAILURE  0x02
> 
> +#define NVME_RPMB_RESULT_COUNTER_FAILURE 0x03
> 
> +#define NVME_RPMB_RESULT_ADDRESS_FAILURE 0x04
> 
> +#define NVME_RPMB_RESULT_WRITE_FAILURE   0x05
> 
> +#define NVME_RPMB_RESULT_READ_FAILURE0x06
> 
> +#define NVME_RPMB_RESULT_AUTHKEY_NOT_PROGRAMMED  0x07
> 
> +#define NVME_RPMB_RESULT_INVALID_DCB 0x08
> 
> +
> 
>  //
> 
>  // NvmExpress Admin Identify Cmd
> 
>  //
> 
> --
> 
> 2.37.1.windows.1
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#99651): https://edk2.groups.io/g/devel/message/99651
Mute This Topic: https://groups.io/mt/96695512/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v1 1/1] MdeModulePkg: ScsiDiskDxe: clean up comment in ScsiDisk.c

2023-02-05 Thread Wu, Hao A
Merged via:
PR - https://github.com/tianocore/edk2/pull/3992
Commit - 
https://github.com/tianocore/edk2/commit/7623b4bf6a4541b1bc5ad1978f27a55f2fb62c5f

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Wu, Hao
> A
> Sent: Wednesday, February 1, 2023 2:49 PM
> To: Yuan Yu ; devel@edk2.groups.io
> Cc: Ard Biesheuvel ; Gao, Liming
> ; Ni, Ray ; C, sivaparvathi
> 
> Subject: Re: [edk2-devel] [PATCH v1 1/1] MdeModulePkg: ScsiDiskDxe: clean
> up comment in ScsiDisk.c
> 
> Reviewed-by: Hao A Wu 
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: Yuan Yu 
> > Sent: Wednesday, February 1, 2023 2:31 PM
> > To: devel@edk2.groups.io
> > Cc: Ard Biesheuvel ; Gao, Liming
> > ; Wu, Hao A ; Ni, Ray
> > ; C, sivaparvathi 
> > Subject: [PATCH v1 1/1] MdeModulePkg: ScsiDiskDxe: clean up comment in
> > ScsiDisk.c
> >
> > Comment of MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c was polluted
> > by some previous merge. This patch clean it up.
> >
> > Cc: Ard Biesheuvel 
> > Cc: Liming Gao 
> > Cc: Hao A Wu 
> > Cc: Ray Ni 
> > Cc: Sivaparvathi chellaiah 
> >
> > Signed-off-by: Yuan Yu 
> > ---
> >  MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c | 4 
> >  1 file changed, 4 deletions(-)
> >
> > diff --git a/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c
> > b/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c
> > index 6555aeed7d69..fbc236cb465e 100644
> > --- a/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c
> > +++ b/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c
> > @@ -3,10 +3,6 @@
> >
> >  Copyright (c) 2006 - 2019, Intel Corporation. All rights
> > reserved.  Copyright (c) 1985 - 2022, American Megatrends
> > International LLC. -<<<<<<< HEAD -===
> > -
> > ->>>>>>> ace365b4e0 (MdeModulePkg/scsi :Coverity scan flags multiple
> > issues in edk2-stable202205)
> >  SPDX-License-Identifier: BSD-2-Clause-Patent
> >
> >  **/
> > --
> > 2.39.1.456.gfc5497dd1b-goog
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#99650): https://edk2.groups.io/g/devel/message/99650
Mute This Topic: https://groups.io/mt/96671064/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH 2/2] MdePkg: Add NVMe boot partition header definition

2023-02-01 Thread Wu, Hao A
Add MdePkg maintainers & reviewers.

One inline comment below:


> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Weipu
> Zhu
> Sent: Wednesday, February 1, 2023 2:27 PM
> To: devel@edk2.groups.io
> Cc: Zhu, Weipu 
> Subject: [edk2-devel] [PATCH 2/2] MdePkg: Add NVMe boot partition header
> definition
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4304
> 
> Add NVMe boot partition header definition to NVMe.h
> according to NVMe spec 2.0.
> 
> Signed-off-by: Weipu Zhu 
> ---
>  MdePkg/Include/IndustryStandard/Nvme.h | 11 +++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/MdePkg/Include/IndustryStandard/Nvme.h
> b/MdePkg/Include/IndustryStandard/Nvme.h
> index c37cd762b9..41d40edbba 100644
> --- a/MdePkg/Include/IndustryStandard/Nvme.h
> +++ b/MdePkg/Include/IndustryStandard/Nvme.h
> @@ -546,6 +546,17 @@ typedef struct {
>  #define RPMB_RESULT_AUTHKEY_NOT_PROGRAMMED  0x07
>  #define RPMB_RESULT_INVALID_DCB 0x08
> 
> +//
> +// Get Log Page - Boot Partition Log Header.
> +// (ref. NVMe Base spec. v2.0 Figure 262).
> +//
> +typedef struct {
> +  UINT8  LogIdentifier; /* Log Identifier, shall be set to 15h */
> +  UINT8  Rsvd1[3];  /* Reserved as of Nvm Express 2.0 Spec */
> +  NVME_BPINFOBpInfo;/* Boot Partition Information, Brs in
> NVME_BPINFO is not available here */


I suggest to not directly use NVME_BPINFO here.

Since the 'Boot Partition Information' within 'Boot Partition Header' is not
exactly the same with the one defined for controller properties (no BRS field
like you mentioned in the comment).

How about adding field definition for 'ABPID' & 'BPSZ' instead?

Best Regards,
Hao Wu


> +  UINT8  Rsvd2[8];  /* Reserved as of Nvm Express 2.0 Spec */
> +} NVME_BOOT_PARTITION_HEADER;
> +
>  //
>  // NvmExpress Admin Identify Cmd
>  //
> --
> 2.37.1.windows.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#99427): https://edk2.groups.io/g/devel/message/99427
Mute This Topic: https://groups.io/mt/96684352/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH 1/2] MdePkg: Add RPMB related commands and DCB definition for NVMe

2023-02-01 Thread Wu, Hao A
Add MdePkg maintainers & reviewers.

One general level comment, could you help to add 'NVME_' prefix to the name of
all newly added structure and macro definitions (like most existing ones in
Nvme.h)?

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Weipu
> Zhu
> Sent: Wednesday, February 1, 2023 2:27 PM
> To: devel@edk2.groups.io
> Cc: Zhu, Weipu 
> Subject: [edk2-devel] [PATCH 1/2] MdePkg: Add RPMB related commands
> and DCB definition for NVMe
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4303
> 
> Add RPMB(Replay Protected Memory Block) access commands,
> result and DCB(Device Configuration Block) definition for
> NVMe according to the NVMe spec 2.0.
> 
> Signed-off-by: Weipu Zhu 
> ---
>  MdePkg/Include/IndustryStandard/Nvme.h | 46
> +-
>  1 file changed, 45 insertions(+), 1 deletion(-)
> 
> diff --git a/MdePkg/Include/IndustryStandard/Nvme.h
> b/MdePkg/Include/IndustryStandard/Nvme.h
> index 4a1d92c45d..c37cd762b9 100644
> --- a/MdePkg/Include/IndustryStandard/Nvme.h
> +++ b/MdePkg/Include/IndustryStandard/Nvme.h
> @@ -2,12 +2,13 @@
>Definitions based on NVMe spec. version 1.1.
> 
>(C) Copyright 2016 Hewlett Packard Enterprise Development LP
> -  Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.
> +  Copyright (c) 2017 - 2023, Intel Corporation. All rights reserved.
>SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>@par Specification Reference:
>NVMe Specification 1.1
>NVMe Specification 1.4
> +  NVMe Specification 2.0
> 
>  **/
> 
> @@ -502,6 +503,49 @@ typedef struct {
>// UINT8*Data; /* Data to be written or read 
> by signed
> access where M = 512 * Sector Count. */
>  } NVME_RPMB_DATA_FRAME;
> 
> +//
> +// RPMB Device Configuration Block Data Structure.
> +// (ref. NVMe Base spec. v2.0 Figure 460).
> +//
> +typedef struct {
> +  UINT8BPPEnable; /* Boot Partition Protection Enabled */
> +  UINT8BPLock;/* Boot Partition Lock */
> +  UINT8NameSpaceWrP;  /* Namespace Write Protection */
> +  UINT8Rsvd1[509];/* Reserved as of Nvm Express 2.0 Spec */
> +} RPMB_DCB;
> +
> +//
> +// RPMB Request and Response Message Types.
> +// (ref. NVMe Base spec. v2.0 Figure 461).
> +//
> +#define RPMB_AUTHKEY_PROGRAM   0x0001
> +#define RPMB_COUNTER_READ  0x0002
> +#define RPMB_AUTHDATA_WRITE0x0003
> +#define RPMB_AUTHDATA_READ 0x0004
> +#define RPMB_RESULT_READ   0x0005
> +#define RPMB_DCB_WRITE 0x0006
> +#define RPMB_DCB_READ  0x0007
> +#define RPMB_AUTHKEY_PROGRAM_RESPONSE  0x0100
> +#define RPMB_COUNTER_READ_RESPONSE 0x0200
> +#define RPMB_AUTHDATA_WRITE_RESPONSE   0x0300
> +#define RPMB_AUTHDATA_READ_RESPONSE0x0400
> +#define RPMB_DCB_WRITE_RESPONSE0x0600
> +#define RPMB_DCB_READ_RESPONSE 0x0700
> +
> +//
> +// RPMB Operation Result.
> +// (ref. NVMe Base spec. v2.0 Figure 462).
> +//
> +#define RPMB_RESULT_SUCCESS 0x00
> +#define RPMB_RESULT_GENERAL_FAILURE 0x01
> +#define RPMB_RESULT_AHTHENTICATION_FAILURE  0x02
> +#define RPMB_RESULT_COUNTER_FAILURE 0x03
> +#define RPMB_RESULT_ADDRESS_FAILURE 0x04
> +#define RPMB_RESULT_WRITE_FAILURE   0x05
> +#define RPMB_RESULT_READ_FAILURE0x06
> +#define RPMB_RESULT_AUTHKEY_NOT_PROGRAMMED  0x07
> +#define RPMB_RESULT_INVALID_DCB 0x08
> +
>  //
>  // NvmExpress Admin Identify Cmd
>  //
> --
> 2.37.1.windows.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#99426): https://edk2.groups.io/g/devel/message/99426
Mute This Topic: https://groups.io/mt/96684351/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 1/1] MdeModulePkg: ScsiBusDxe: Refactor DiscoverScsiDevice()

2023-02-01 Thread Wu, Hao A
Merged via:
PR - https://github.com/tianocore/edk2/pull/3979
Commit - 
https://github.com/tianocore/edk2/commit/d375273c899bfa279c2732c509caf455af285006

Best Regards,
Hao Wu

From: Yuan Yu 
Sent: Thursday, February 2, 2023 2:17 AM
To: Wu, Hao A 
Cc: devel@edk2.groups.io; Ard Biesheuvel ; Gao, 
Liming ; Ni, Ray ; C, sivaparvathi 

Subject: Re: [PATCH v2 1/1] MdeModulePkg: ScsiBusDxe: Refactor 
DiscoverScsiDevice()

Sounds good. Thank you!

Best,
Yuan

On Tue, Jan 31, 2023 at 10:48 PM Wu, Hao A 
mailto:hao.a...@intel.com>> wrote:
Reviewed-by: Hao A Wu mailto:hao.a...@intel.com>>
Will update the function comment for ScsiScanCreateDevice() in ScsiBus.c to 
match the change in ScsiBus.h during merge.

Best Regards,
Hao Wu

> -Original Message-
> From: Yuan Yu mailto:yua...@google.com>>
> Sent: Tuesday, January 31, 2023 2:04 PM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> Cc: Ard Biesheuvel 
> mailto:ardb%2btianoc...@kernel.org>>; Gao, Liming
> mailto:gaolim...@byosoft.com.cn>>; Wu, Hao A 
> mailto:hao.a...@intel.com>>; Ni, Ray
> mailto:ray...@intel.com>>; C, sivaparvathi 
> mailto:sivaparvat...@ami.com>>
> Subject: [PATCH v2 1/1] MdeModulePkg: ScsiBusDxe: Refactor
> DiscoverScsiDevice()
>
> Currently DiscoverScsiDevice() returns a boolean which cannot
> distinguish a "not found" situation from a real problem like
> memory allocation failures.
>
> This patch changes the return value to an EFI_STATUS so that when
> memory allocation fails, it will return EFI_OUT_OF_RESOURCES.
>
> Without this change, any FALSE returned by DiscoverScsiDevice()
> will result in EFI_OUT_OF_RESOURCES being returned by
> ScsiScanCreateDevice(), which will cause a while loop in
> SCSIBusDriverBindingStart() to abort before other possible Puns in
> the SCSI channel are scanned, which means good devices may not have
> a chance to be discovered.  If this good device is the boot device,
> boot will fail.
>
> Cc: Ard Biesheuvel 
> mailto:ardb%2btianoc...@kernel.org>>
> Cc: Liming Gao mailto:gaolim...@byosoft.com.cn>>
> Cc: Hao A Wu mailto:hao.a...@intel.com>>
> Cc: Ray Ni mailto:ray...@intel.com>>
> Cc: Sivaparvathi chellaiah 
> mailto:sivaparvat...@ami.com>>
>
> Signed-off-by: Yuan Yu mailto:yua...@google.com>>
> ---
>  MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h | 10 ---
>  MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c | 30 ++--
>  2 files changed, 21 insertions(+), 19 deletions(-)
>
> diff --git a/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h
> b/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h
> index 68c5c02a9161..35a8a46ca7a2 100644
> --- a/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h
> +++ b/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h
> @@ -455,7 +455,8 @@ ScsiExecuteSCSICommand (
>
>@retval EFI_SUCCESS   Successfully to discover the device and 
> attach
>  ScsiIoProtocol to it.
> -  @retval EFI_OUT_OF_RESOURCES  Fail to discover the device.
> +  @retval EFI_NOT_FOUND Fail to discover the device.
> +  @retval EFI_OUT_OF_RESOURCES  Fail to allocate memory resources.
>
>  **/
>  EFI_STATUS
> @@ -473,11 +474,12 @@ ScsiScanCreateDevice (
>
>@param  ScsiIoDeviceThe pointer of SCSI_IO_DEV
>
> -  @retval  TRUE   Find SCSI Device and verify it.
> -  @retval  FALSE  Unable to find SCSI Device.
> +  @retval EFI_SUCCESS   Find SCSI Device and verify it.
> +  @retval EFI_NOT_FOUND Unable to find SCSI Device.
> +  @retval EFI_OUT_OF_RESOURCES  Fail to allocate memory resources.
>
>  **/
> -BOOLEAN
> +EFI_STATUS
>  DiscoverScsiDevice (
>IN  OUT  SCSI_IO_DEV  *ScsiIoDevice
>);
> diff --git a/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
> b/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
> index fbe14c772496..4414a65eb1e6 100644
> --- a/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
> +++ b/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
> @@ -1210,8 +1210,8 @@ ScsiScanCreateDevice (
>  ScsiBusDev->DevicePath
>  );
>
> -  if (!DiscoverScsiDevice (ScsiIoDevice)) {
> -Status = EFI_OUT_OF_RESOURCES;
> +  Status = DiscoverScsiDevice (ScsiIoDevice);
> +  if (EFI_ERROR (Status)) {
>  goto ErrorExit;
>}
>
> @@ -1276,11 +1276,12 @@ ErrorExit:
>
>@param  ScsiIoDeviceThe pointer of SCSI_IO_DEV
>
> -  @retval  TRUE   Find SCSI Device and verify it.
> -  @retval  FALSE  Unable to find SCSI Device.
> +  @retval EFI_SUCCESS   Find SCSI Device and verify it.
> +  @retval EFI_NOT_FOUND Unable to find SCSI Device.
> +  @retval EFI_OUT_OF_RESOURCES  Fail to allocate memory resources.
>
>  **/
> -BOOLEAN
> +EFI_STATUS
>  D

Re: [edk2-devel] [PATCH v1 1/1] MdeModulePkg: ScsiDiskDxe: clean up comment in ScsiDisk.c

2023-01-31 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: Yuan Yu 
> Sent: Wednesday, February 1, 2023 2:31 PM
> To: devel@edk2.groups.io
> Cc: Ard Biesheuvel ; Gao, Liming
> ; Wu, Hao A ; Ni, Ray
> ; C, sivaparvathi 
> Subject: [PATCH v1 1/1] MdeModulePkg: ScsiDiskDxe: clean up comment in
> ScsiDisk.c
> 
> Comment of MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c was polluted
> by
> some previous merge. This patch clean it up.
> 
> Cc: Ard Biesheuvel 
> Cc: Liming Gao 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Cc: Sivaparvathi chellaiah 
> 
> Signed-off-by: Yuan Yu 
> ---
>  MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c | 4 
>  1 file changed, 4 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c
> b/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c
> index 6555aeed7d69..fbc236cb465e 100644
> --- a/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c
> +++ b/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c
> @@ -3,10 +3,6 @@
> 
>  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
>  Copyright (c) 1985 - 2022, American Megatrends International LLC.
> -<<<<<<< HEAD
> -===
> -
> ->>>>>>> ace365b4e0 (MdeModulePkg/scsi :Coverity scan flags multiple
> issues in edk2-stable202205)
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> --
> 2.39.1.456.gfc5497dd1b-goog



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#99389): https://edk2.groups.io/g/devel/message/99389
Mute This Topic: https://groups.io/mt/96671064/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 1/1] MdeModulePkg: ScsiBusDxe: Refactor DiscoverScsiDevice()

2023-01-31 Thread Wu, Hao A
Reviewed-by: Hao A Wu 
Will update the function comment for ScsiScanCreateDevice() in ScsiBus.c to 
match the change in ScsiBus.h during merge.

Best Regards,
Hao Wu

> -Original Message-
> From: Yuan Yu 
> Sent: Tuesday, January 31, 2023 2:04 PM
> To: devel@edk2.groups.io
> Cc: Ard Biesheuvel ; Gao, Liming
> ; Wu, Hao A ; Ni, Ray
> ; C, sivaparvathi 
> Subject: [PATCH v2 1/1] MdeModulePkg: ScsiBusDxe: Refactor
> DiscoverScsiDevice()
> 
> Currently DiscoverScsiDevice() returns a boolean which cannot
> distinguish a "not found" situation from a real problem like
> memory allocation failures.
> 
> This patch changes the return value to an EFI_STATUS so that when
> memory allocation fails, it will return EFI_OUT_OF_RESOURCES.
> 
> Without this change, any FALSE returned by DiscoverScsiDevice()
> will result in EFI_OUT_OF_RESOURCES being returned by
> ScsiScanCreateDevice(), which will cause a while loop in
> SCSIBusDriverBindingStart() to abort before other possible Puns in
> the SCSI channel are scanned, which means good devices may not have
> a chance to be discovered.  If this good device is the boot device,
> boot will fail.
> 
> Cc: Ard Biesheuvel 
> Cc: Liming Gao 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Cc: Sivaparvathi chellaiah 
> 
> Signed-off-by: Yuan Yu 
> ---
>  MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h | 10 ---
>  MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c | 30 ++--
>  2 files changed, 21 insertions(+), 19 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h
> b/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h
> index 68c5c02a9161..35a8a46ca7a2 100644
> --- a/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h
> +++ b/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h
> @@ -455,7 +455,8 @@ ScsiExecuteSCSICommand (
> 
>@retval EFI_SUCCESS   Successfully to discover the device and 
> attach
>  ScsiIoProtocol to it.
> -  @retval EFI_OUT_OF_RESOURCES  Fail to discover the device.
> +  @retval EFI_NOT_FOUND Fail to discover the device.
> +  @retval EFI_OUT_OF_RESOURCES  Fail to allocate memory resources.
> 
>  **/
>  EFI_STATUS
> @@ -473,11 +474,12 @@ ScsiScanCreateDevice (
> 
>@param  ScsiIoDeviceThe pointer of SCSI_IO_DEV
> 
> -  @retval  TRUE   Find SCSI Device and verify it.
> -  @retval  FALSE  Unable to find SCSI Device.
> +  @retval EFI_SUCCESS   Find SCSI Device and verify it.
> +  @retval EFI_NOT_FOUND Unable to find SCSI Device.
> +  @retval EFI_OUT_OF_RESOURCES  Fail to allocate memory resources.
> 
>  **/
> -BOOLEAN
> +EFI_STATUS
>  DiscoverScsiDevice (
>IN  OUT  SCSI_IO_DEV  *ScsiIoDevice
>);
> diff --git a/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
> b/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
> index fbe14c772496..4414a65eb1e6 100644
> --- a/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
> +++ b/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
> @@ -1210,8 +1210,8 @@ ScsiScanCreateDevice (
>  ScsiBusDev->DevicePath
>  );
> 
> -  if (!DiscoverScsiDevice (ScsiIoDevice)) {
> -Status = EFI_OUT_OF_RESOURCES;
> +  Status = DiscoverScsiDevice (ScsiIoDevice);
> +  if (EFI_ERROR (Status)) {
>  goto ErrorExit;
>}
> 
> @@ -1276,11 +1276,12 @@ ErrorExit:
> 
>@param  ScsiIoDeviceThe pointer of SCSI_IO_DEV
> 
> -  @retval  TRUE   Find SCSI Device and verify it.
> -  @retval  FALSE  Unable to find SCSI Device.
> +  @retval EFI_SUCCESS   Find SCSI Device and verify it.
> +  @retval EFI_NOT_FOUND Unable to find SCSI Device.
> +  @retval EFI_OUT_OF_RESOURCES  Fail to allocate memory resources.
> 
>  **/
> -BOOLEAN
> +EFI_STATUS
>  DiscoverScsiDevice (
>IN OUT  SCSI_IO_DEV  *ScsiIoDevice
>)
> @@ -1294,7 +1295,6 @@ DiscoverScsiDevice (
>EFI_SCSI_SENSE_DATA*SenseData;
>UINT8  MaxRetry;
>UINT8  Index;
> -  BOOLEANScsiDeviceFound;
> 
>HostAdapterStatus = 0;
>TargetStatus  = 0;
> @@ -1302,7 +1302,7 @@ DiscoverScsiDevice (
> 
>InquiryData = AllocateAlignedBuffer (ScsiIoDevice, sizeof
> (EFI_SCSI_INQUIRY_DATA));
>if (InquiryData == NULL) {
> -ScsiDeviceFound = FALSE;
> +Status = EFI_OUT_OF_RESOURCES;
>  goto Done;
>}
> 
> @@ -1311,7 +1311,7 @@ DiscoverScsiDevice (
>  sizeof (EFI_SCSI_SENSE_DATA)
>  );
>if (SenseData == NULL) {
> -ScsiDeviceFound = FALSE;
> +Status = EFI_OUT_OF_RESOURCES;
>  goto Done;
>}
> 
> @@ -1342,7 +1342,7 @@ DiscoverScsiDevice (
>(SenseData->Error_Code == 0x70) &&
&

Re: [edk2-devel] [PATCH v1 1/2] MdeModulePkg: Fix bug in ScsiBusDxe/ScsiBus.c

2023-01-18 Thread Wu, Hao A
Thanks for the patch, inline comments below:


> -Original Message-
> From: Yuan Yu 
> Sent: Wednesday, January 18, 2023 5:14 PM
> To: devel@edk2.groups.io
> Cc: Ard Biesheuvel ; Gao, Liming
> ; Wu, Hao A ; Ni, Ray
> ; C, sivaparvathi 
> Subject: [PATCH v1 1/2] MdeModulePkg: Fix bug in ScsiBusDxe/ScsiBus.c
> 
> A while loop in SCSIBusDriverBindingStart() is supposed to scan all the
> possible Puns in the SCSI channel by calling ScsiScanCreateDevice() for
> each of them. Therefore, we should not abort the loop even when one of
> the Puns is disconnected.
> 
> The following is one of the scenarios.
> 
> SCSIBusDriverBindingStart()
> > ScsiScanCreateDevice()
>   > DiscoverScsiDevice()
> > ScsiInquiryCommand()
>   > ...
> > ParseResponse()
> 
> When virtio-scsi returns VIRTIO_SCSI_S_BAD_TARGET, ParseResponse() in
> VirtioScsi.c will return EFI_TIMEOUT:
> 
> case VIRTIO_SCSI_S_BAD_TARGET:
>   //
>   // This is non-intuitive but explicitly required by the
>   // EFI_EXT_SCSI_PASS_THRU_PROTOCOL.PassThru() specification for
>   // disconnected (but otherwise valid) target / LUN addresses.
>   //
>   Packet->HostAdapterStatus =
> EFI_EXT_SCSI_STATUS_HOST_ADAPTER_TIMEOUT_COMMAND;
>   return EFI_TIMEOUT;
> 
> This will eventually cause DiscoverScsiDevice() to return FALSE, which
> will cause ScsiScanCreateDevice() to return EFI_OUT_OF_RESOURCES:
> 
>   if (!DiscoverScsiDevice (ScsiIoDevice)) {
> Status = EFI_OUT_OF_RESOURCES;
> goto ErrorExit;
>   }


I think when DiscoverScsiDevice() returns FALSE, it (the current code 
implementation) is improper
to simply return EFI_OUT_OF_RESOURCES.

My take is that, under the scope of the SCSI driver, EFI_OUT_OF_RESOURCES 
should be used as return
status when memory allocation fails (due to insufficient free memory).

But when DiscoverScsiDevice() returns FALSE, there are cases where the cause is 
SCSI command
execution failure like you mentioned above.

So my recommendation is to refine the interface for DiscoverScsiDevice() to 
return accurate status
of the execution of the function, like
* EFI_SUCCESS for device successfully discovered;
* EFI_OUT_OF_RESOURCES for memory allocation failure;
* EFI_NOT_FOUND for cases when:
a) SCSI command execution failure or
b) Return data of the command indicates no device

Maybe the refined interface can look like:
EFI_STATUS
DiscoverScsiDevice (
  IN OUT  SCSI_IO_DEV  *ScsiIoDevice
  )

The caller of DiscoverScsiDevice() will return proper status rather than simply 
returning
EFI_OUT_OF_RESOURCES when device discovery fails.


The reason for the below logic in SCSIBusDriverBindingStart():

Status = ScsiScanCreateDevice (This, Controller, , Lun, 
ScsiBusDev);
if (Status == EFI_OUT_OF_RESOURCES) {
  goto ErrorExit;
}

is that it expects ScsiScanCreateDevice() to return EFI_OUT_OF_RESOURCES as an 
indication of lack
of memory resource in the system. Under such situation, subsequent memory 
allocations are very likely
to fail as well, so there is little value in continuing the loop for further 
device discovery.


Best Regards,
Hao Wu


> 
> In sum, "disconnected (but otherwise valid) target / LUN addresses" can
> result in EFI_OUT_OF_RESOURCES and when this happens the while loop in
> SCSIBusDriverBindingStart() should continue, not abort.
> 
> Without this fix, the loop can terminate prematurely with good devices
> not having a chance to be discovered. If this good device is the boot
> device, boot will fail.
> 
> Cc: Ard Biesheuvel 
> Cc: Liming Gao 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Cc: Sivaparvathi chellaiah 
> 
> Signed-off-by: Yuan Yu 
> ---
>  MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
> b/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
> index fbe14c772496..2ed816da4abe 100644
> --- a/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
> +++ b/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
> @@ -533,9 +533,6 @@ SCSIBusDriverBindingStart (
>  // then create handle and install scsi i/o protocol.
>  //
>  Status = ScsiScanCreateDevice (This, Controller, , Lun,
> ScsiBusDev);
> -if (Status == EFI_OUT_OF_RESOURCES) {
> -  goto ErrorExit;
> -}
>}
> 
>return EFI_SUCCESS;
> --
> 2.39.0.314.g84b9a713c41-goog



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#98866): https://edk2.groups.io/g/devel/message/98866
Mute This Topic: https://groups.io/mt/96350422/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH V2 1/3] MdeModulePkg/Xhci: Initial XHCI DCI slot's Context value

2023-01-15 Thread Wu, Hao A
The 3-patch series is merged via:
PR - https://github.com/tianocore/edk2/pull/3899
Commits - 7cd55f300915...47ab397011b6:
https://github.com/tianocore/edk2/commit/8147fe090fb566f9a1ed8fde24098bbe425026be
https://github.com/tianocore/edk2/commit/be8d6ef3856fac2e64e23847a8f05d37822b1f14
https://github.com/tianocore/edk2/commit/47ab397011b6d1ce4d5805117dc87d9e35f378db

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Chang,
> Abner via groups.io
> Sent: Wednesday, January 11, 2023 11:10 AM
> To: devel@edk2.groups.io
> Cc: Wu, Hao A ; Ni, Ray ; Garrett
> Kirkendall ; Abner Chang
> ; Kuei-Hung Lin 
> Subject: [edk2-devel] [PATCH V2 1/3] MdeModulePkg/Xhci: Initial XHCI DCI
> slot's Context value
> 
> From: Abner Chang 
> 
> Initialize XHCI DCI slot's context entries value.
> 
> Signed-off-by: Jiangang He 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Cc: Garrett Kirkendall 
> Cc: Abner Chang 
> Cc: Kuei-Hung Lin 
> Reviewed-by: Hao A Wu 
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 7 +++
>  MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c | 7 +++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> index 13247f7b0df..4b7462704a8 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> @@ -4,6 +4,7 @@
> 
>  Copyright (c) 2011 - 2020, Intel Corporation. All rights reserved.
>  Copyright (c) Microsoft Corporation.
> +Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -2807,6 +2808,9 @@ XhcInitializeEndpointContext (
>MaxDci = 0;
> 
>NumEp = IfDesc->NumEndpoints;
> +  if (NumEp == 0) {
> +MaxDci = 1;
> +  }
> 
>EpDesc = (USB_ENDPOINT_DESCRIPTOR *)(IfDesc + 1);
>for (EpIndex = 0; EpIndex < NumEp; EpIndex++) {
> @@ -3006,6 +3010,9 @@ XhcInitializeEndpointContext64 (
>MaxDci = 0;
> 
>NumEp = IfDesc->NumEndpoints;
> +  if (NumEp == 0) {
> +MaxDci = 1;
> +  }
> 
>EpDesc = (USB_ENDPOINT_DESCRIPTOR *)(IfDesc + 1);
>for (EpIndex = 0; EpIndex < NumEp; EpIndex++) {
> diff --git a/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c
> b/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c
> index cc597a43717..8400c90f7ad 100644
> --- a/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c
> +++ b/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c
> @@ -3,6 +3,7 @@ PEIM to produce gPeiUsb2HostControllerPpiGuid based on
> gPeiUsbControllerPpiGuid
>  which is used to enable recovery function from USB Drivers.
> 
>  Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.
> +Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
> 
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> @@ -1752,6 +1753,9 @@ XhcPeiSetConfigCmd (
>  }
> 
>  NumEp = IfDesc->NumEndpoints;
> +if ((NumEp == 0) && (MaxDci == 0)) {
> +  MaxDci = 1;
> +}
> 
>  EpDesc = (USB_ENDPOINT_DESCRIPTOR *)(IfDesc + 1);
>  for (EpIndex = 0; EpIndex < NumEp; EpIndex++) {
> @@ -1974,6 +1978,9 @@ XhcPeiSetConfigCmd64 (
>  }
> 
>  NumEp = IfDesc->NumEndpoints;
> +if ((NumEp == 0) && (MaxDci == 0)) {
> +  MaxDci = 1;
> +}
> 
>  EpDesc = (USB_ENDPOINT_DESCRIPTOR *)(IfDesc + 1);
>  for (EpIndex = 0; EpIndex < NumEp; EpIndex++) {
> --
> 2.37.1.windows.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#98533): https://edk2.groups.io/g/devel/message/98533
Mute This Topic: https://groups.io/mt/96193248/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH V2 3/3] MdeModulePkg/XhciPei: Unlinked XhciPei memory block

2023-01-13 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Chang,
> Abner via groups.io
> Sent: Wednesday, January 11, 2023 11:10 AM
> To: devel@edk2.groups.io
> Cc: Wu, Hao A ; Ni, Ray ; Garrett
> Kirkendall ; Abner Chang
> ; Kuei-Hung Lin 
> Subject: [edk2-devel] [PATCH V2 3/3] MdeModulePkg/XhciPei: Unlinked XhciPei
> memory block
> 
> From: Abner Chang 
> 
> Unlink the XhciPei memory block when it has been freed.
> 
> Signed-off-by: Jiangang He 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Cc: Garrett Kirkendall 
> Cc: Abner Chang 
> Cc: Kuei-Hung Lin 
> ---
>  MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c | 31
> +++--
>  1 file changed, 29 insertions(+), 2 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c
> b/MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c
> index c64b38fcfc8..e779a311388 100644
> --- a/MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c
> +++ b/MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c
> @@ -3,6 +3,7 @@ PEIM to produce gPeiUsb2HostControllerPpiGuid based on
> gPeiUsbControllerPpiGuid
>  which is used to enable recovery function from USB Drivers.
> 
>  Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.
> +Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
> 
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> @@ -365,6 +366,32 @@ UsbHcInitMemPool (
>return Pool;
>  }
> 
> +/**
> +  Unlink the memory block from the pool's list.
> +
> +  @param  Head   The block list head of the memory's pool.
> +  @param  BlockToUnlink  The memory block to unlink.
> +
> +**/
> +VOID
> +UsbHcUnlinkMemBlock (
> +  IN USBHC_MEM_BLOCK  *Head,
> +  IN USBHC_MEM_BLOCK  *BlockToUnlink
> +  )
> +{
> +  USBHC_MEM_BLOCK  *Block;
> +
> +  ASSERT ((Head != NULL) && (BlockToUnlink != NULL));
> +
> +  for (Block = Head; Block != NULL; Block = Block->Next) {
> +if (Block->Next == BlockToUnlink) {
> +  Block->Next = BlockToUnlink->Next;
> +  BlockToUnlink->Next = NULL;
> +  break;
> +}
> +  }
> +}
> +
>  /**
>Release the memory management pool.
> 
> @@ -386,7 +413,7 @@ UsbHcFreeMemPool (
>// first block.
>//
>for (Block = Pool->Head->Next; Block != NULL; Block = Pool->Head->Next) {
> -// UsbHcUnlinkMemBlock (Pool->Head, Block);
> +UsbHcUnlinkMemBlock (Pool->Head, Block);
>  UsbHcFreeMemBlock (Pool, Block);
>}
> 
> @@ -532,7 +559,7 @@ UsbHcFreeMem (
>// Release the current memory block if it is empty and not the head
>//
>if ((Block != Head) && UsbHcIsMemBlockEmpty (Block)) {
> -// UsbHcUnlinkMemBlock (Head, Block);
> +UsbHcUnlinkMemBlock (Head, Block);
>  UsbHcFreeMemBlock (Pool, Block);
>}
>  }
> --
> 2.37.1.windows.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#98456): https://edk2.groups.io/g/devel/message/98456
Mute This Topic: https://groups.io/mt/96193253/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH] MdeModulePkg/Bus/Pci/XhciDxe: Reset the port if status change returns an error

2023-01-03 Thread Wu, Hao A
Pushed via:
PR - https://github.com/tianocore/edk2/pull/3848
Commit  - 
https://github.com/tianocore/edk2/commit/992d5451d19b93635d52db293bab680e32142776

Best Regards,
Hao Wu

From: devel@edk2.groups.io  On Behalf Of Wu, Hao A
Sent: Tuesday, January 3, 2023 9:25 AM
To: Rhodes, Sean ; devel@edk2.groups.io
Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/Bus/Pci/XhciDxe: Reset the port 
if status change returns an error

Reviewed-by: Hao A Wu mailto:hao.a...@intel.com>>

Best Regards,
Hao Wu

From: Sean Rhodes mailto:sean@starlabs.systems>>
Sent: Friday, December 23, 2022 6:22 PM
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; Wu, Hao A 
mailto:hao.a...@intel.com>>
Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/Bus/Pci/XhciDxe: Reset the port 
if status change returns an error

Hi Hao

This PR has passed CI - https://github.com/tianocore/edk2/pull/3353

Thanks

Sean

On Fri, 23 Dec 2022 at 08:56, Wu, Hao A 
mailto:hao.a...@intel.com>> wrote:
Sorry,

The CI tests failed for the proposed patch:
https://github.com/tianocore/edk2/pull/3824

Could you help to check and resolve? Thanks.

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
> mailto:devel@edk2.groups.io>> On Behalf Of Sean
> Rhodes
> Sent: Wednesday, December 21, 2022 4:15 PM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> Cc: Rhodes, Sean mailto:sean@starlabs.systems>>
> Subject: [edk2-devel] [PATCH] MdeModulePkg/Bus/Pci/XhciDxe: Reset the
> port if status change returns an error
>
> Force resetting the port by clearing the USB_PORT_STAT_C_RESET bit in
> PortChangeStatus
> when XhcPollPortStatusChange fails
>
> Signed-off-by: Sean Rhodes 
> mailto:sean@starlabs.systems>>
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 11 ++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> index 461b2cd9b5..d8fa41f68f 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> @@ -471,7 +471,16 @@ XhcGetRootHubPortStatus (
>// For those devices behind hub, we get its attach/detach event by hooking
> Get_Port_Status request at control transfer for those hub.
>
>//
>
>ParentRouteChart.Dword = 0;
>
> -  XhcPollPortStatusChange (Xhc, ParentRouteChart, PortNumber, PortStatus);
>
> +  Status = XhcPollPortStatusChange (Xhc, ParentRouteChart,
> PortNumber, PortStatus);
>
> +
>
> +  //
>
> +  // Force resetting the port by clearing the USB_PORT_STAT_C_RESET bit in
> PortChangeStatus
>
> +  // when XhcPollPortStatusChange fails
>
> +  //
>
> +  if (EFI_ERROR (Status)) {
>
> +PortStatus->PortChangeStatus &= ~(USB_PORT_STAT_C_RESET);
>
> +Status= EFI_SUCCESS;
>
> +  }
>
>
>
>  ON_EXIT:
>
>gBS->RestoreTPL (OldTpl);
>
> --
> 2.37.2
>
>
>
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> View/Reply Online (#97683): https://edk2.groups.io/g/devel/message/97683
> Mute This Topic: https://groups.io/mt/95802798/1768737
> Group Owner: devel+ow...@edk2.groups.io<mailto:devel%2bow...@edk2.groups.io>
> Unsubscribe: https://edk2.groups.io/g/devel/unsub 
> [hao.a...@intel.com<mailto:hao.a...@intel.com>]
> -=-=-=-=-=-=
>







-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#97904): https://edk2.groups.io/g/devel/message/97904
Mute This Topic: https://groups.io/mt/95802798/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH] MdeModulePkg/Bus/Pci/XhciDxe: Reset the port if status change returns an error

2023-01-02 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

From: Sean Rhodes 
Sent: Friday, December 23, 2022 6:22 PM
To: devel@edk2.groups.io; Wu, Hao A 
Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/Bus/Pci/XhciDxe: Reset the port 
if status change returns an error

Hi Hao

This PR has passed CI - https://github.com/tianocore/edk2/pull/3353

Thanks

Sean

On Fri, 23 Dec 2022 at 08:56, Wu, Hao A 
mailto:hao.a...@intel.com>> wrote:
Sorry,

The CI tests failed for the proposed patch:
https://github.com/tianocore/edk2/pull/3824

Could you help to check and resolve? Thanks.

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> 
> mailto:devel@edk2.groups.io>> On Behalf Of Sean
> Rhodes
> Sent: Wednesday, December 21, 2022 4:15 PM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> Cc: Rhodes, Sean mailto:sean@starlabs.systems>>
> Subject: [edk2-devel] [PATCH] MdeModulePkg/Bus/Pci/XhciDxe: Reset the
> port if status change returns an error
>
> Force resetting the port by clearing the USB_PORT_STAT_C_RESET bit in
> PortChangeStatus
> when XhcPollPortStatusChange fails
>
> Signed-off-by: Sean Rhodes 
> mailto:sean@starlabs.systems>>
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 11 ++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> index 461b2cd9b5..d8fa41f68f 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> @@ -471,7 +471,16 @@ XhcGetRootHubPortStatus (
>// For those devices behind hub, we get its attach/detach event by hooking
> Get_Port_Status request at control transfer for those hub.
>
>//
>
>ParentRouteChart.Dword = 0;
>
> -  XhcPollPortStatusChange (Xhc, ParentRouteChart, PortNumber, PortStatus);
>
> +  Status = XhcPollPortStatusChange (Xhc, ParentRouteChart,
> PortNumber, PortStatus);
>
> +
>
> +  //
>
> +  // Force resetting the port by clearing the USB_PORT_STAT_C_RESET bit in
> PortChangeStatus
>
> +  // when XhcPollPortStatusChange fails
>
> +  //
>
> +  if (EFI_ERROR (Status)) {
>
> +PortStatus->PortChangeStatus &= ~(USB_PORT_STAT_C_RESET);
>
> +Status= EFI_SUCCESS;
>
> +  }
>
>
>
>  ON_EXIT:
>
>gBS->RestoreTPL (OldTpl);
>
> --
> 2.37.2
>
>
>
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> View/Reply Online (#97683): https://edk2.groups.io/g/devel/message/97683
> Mute This Topic: https://groups.io/mt/95802798/1768737
> Group Owner: devel+ow...@edk2.groups.io<mailto:devel%2bow...@edk2.groups.io>
> Unsubscribe: https://edk2.groups.io/g/devel/unsub 
> [hao.a...@intel.com<mailto:hao.a...@intel.com>]
> -=-=-=-=-=-=
>







-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#97847): https://edk2.groups.io/g/devel/message/97847
Mute This Topic: https://groups.io/mt/95802798/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH] MdeModulePkg/Bus/Pci/XhciDxe: Reset the port if status change returns an error

2022-12-23 Thread Wu, Hao A
Sorry,

The CI tests failed for the proposed patch:
https://github.com/tianocore/edk2/pull/3824

Could you help to check and resolve? Thanks.

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Sean
> Rhodes
> Sent: Wednesday, December 21, 2022 4:15 PM
> To: devel@edk2.groups.io
> Cc: Rhodes, Sean 
> Subject: [edk2-devel] [PATCH] MdeModulePkg/Bus/Pci/XhciDxe: Reset the
> port if status change returns an error
> 
> Force resetting the port by clearing the USB_PORT_STAT_C_RESET bit in
> PortChangeStatus
> when XhcPollPortStatusChange fails
> 
> Signed-off-by: Sean Rhodes 
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 11 ++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> index 461b2cd9b5..d8fa41f68f 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> @@ -471,7 +471,16 @@ XhcGetRootHubPortStatus (
>// For those devices behind hub, we get its attach/detach event by hooking
> Get_Port_Status request at control transfer for those hub.
> 
>//
> 
>ParentRouteChart.Dword = 0;
> 
> -  XhcPollPortStatusChange (Xhc, ParentRouteChart, PortNumber, PortStatus);
> 
> +  Status = XhcPollPortStatusChange (Xhc, ParentRouteChart,
> PortNumber, PortStatus);
> 
> +
> 
> +  //
> 
> +  // Force resetting the port by clearing the USB_PORT_STAT_C_RESET bit in
> PortChangeStatus
> 
> +  // when XhcPollPortStatusChange fails
> 
> +  //
> 
> +  if (EFI_ERROR (Status)) {
> 
> +PortStatus->PortChangeStatus &= ~(USB_PORT_STAT_C_RESET);
> 
> +Status= EFI_SUCCESS;
> 
> +  }
> 
> 
> 
>  ON_EXIT:
> 
>gBS->RestoreTPL (OldTpl);
> 
> --
> 2.37.2
> 
> 
> 
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> View/Reply Online (#97683): https://edk2.groups.io/g/devel/message/97683
> Mute This Topic: https://groups.io/mt/95802798/1768737
> Group Owner: devel+ow...@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub [hao.a...@intel.com]
> -=-=-=-=-=-=
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#97728): https://edk2.groups.io/g/devel/message/97728
Mute This Topic: https://groups.io/mt/95802798/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH 1/3] MdeModulePkg/Xhci: Initial XHCI DCI slot's Context value

2022-12-22 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Chang,
> Abner via groups.io
> Sent: Wednesday, December 21, 2022 11:41 PM
> To: devel@edk2.groups.io
> Cc: Wu, Hao A ; Ni, Ray ; Garrett
> Kirkendall ; Abner Chang
> ; Kuei-Hung Lin 
> Subject: [edk2-devel] [PATCH 1/3] MdeModulePkg/Xhci: Initial XHCI DCI slot's
> Context value
> 
> From: Abner Chang 
> 
> Initialize XHCI DCI slot's context entries value.
> 
> Signed-off-by: Jiangang He 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Cc: Garrett Kirkendall 
> Cc: Abner Chang 
> Cc: Kuei-Hung Lin 
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 7 +++
>  MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c | 7 +++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> index 13247f7b0df..4b7462704a8 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> @@ -4,6 +4,7 @@
> 
>  Copyright (c) 2011 - 2020, Intel Corporation. All rights reserved.
>  Copyright (c) Microsoft Corporation.
> +Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -2807,6 +2808,9 @@ XhcInitializeEndpointContext (
>MaxDci = 0;
> 
>NumEp = IfDesc->NumEndpoints;
> +  if (NumEp == 0) {
> +MaxDci = 1;
> +  }
> 
>EpDesc = (USB_ENDPOINT_DESCRIPTOR *)(IfDesc + 1);
>for (EpIndex = 0; EpIndex < NumEp; EpIndex++) {
> @@ -3006,6 +3010,9 @@ XhcInitializeEndpointContext64 (
>MaxDci = 0;
> 
>NumEp = IfDesc->NumEndpoints;
> +  if (NumEp == 0) {
> +MaxDci = 1;
> +  }
> 
>EpDesc = (USB_ENDPOINT_DESCRIPTOR *)(IfDesc + 1);
>for (EpIndex = 0; EpIndex < NumEp; EpIndex++) {
> diff --git a/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c
> b/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c
> index cc597a43717..8400c90f7ad 100644
> --- a/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c
> +++ b/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c
> @@ -3,6 +3,7 @@ PEIM to produce gPeiUsb2HostControllerPpiGuid based
> on gPeiUsbControllerPpiGuid
>  which is used to enable recovery function from USB Drivers.
> 
>  Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.
> +Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
> 
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> @@ -1752,6 +1753,9 @@ XhcPeiSetConfigCmd (
>  }
> 
>  NumEp = IfDesc->NumEndpoints;
> +if ((NumEp == 0) && (MaxDci == 0)) {
> +  MaxDci = 1;
> +}
> 
>  EpDesc = (USB_ENDPOINT_DESCRIPTOR *)(IfDesc + 1);
>  for (EpIndex = 0; EpIndex < NumEp; EpIndex++) {
> @@ -1974,6 +1978,9 @@ XhcPeiSetConfigCmd64 (
>  }
> 
>  NumEp = IfDesc->NumEndpoints;
> +if ((NumEp == 0) && (MaxDci == 0)) {
> +  MaxDci = 1;
> +}
> 
>  EpDesc = (USB_ENDPOINT_DESCRIPTOR *)(IfDesc + 1);
>  for (EpIndex = 0; EpIndex < NumEp; EpIndex++) {
> --
> 2.37.1.windows.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#97726): https://edk2.groups.io/g/devel/message/97726
Mute This Topic: https://groups.io/mt/95808331/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH 2/3] MdeModulePkg/Usb: Read a large number of blocks

2022-12-22 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Chang,
> Abner via groups.io
> Sent: Wednesday, December 21, 2022 11:42 PM
> To: devel@edk2.groups.io
> Cc: Wu, Hao A ; Ni, Ray ; Garrett
> Kirkendall ; Abner Chang
> ; Kuei-Hung Lin 
> Subject: [edk2-devel] [PATCH 2/3] MdeModulePkg/Usb: Read a large number
> of blocks
> 
> From: Abner Chang 
> 
> Changes to allow reading blocks that greater than 65535 sectors.
> 
> Signed-off-by: Jiangang He 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Cc: Garrett Kirkendall 
> Cc: Abner Chang 
> Cc: Kuei-Hung Lin 
> ---
>  MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c | 25 +++
>  1 file changed, 12 insertions(+), 13 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c
> b/MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c
> index 422ac5fec99..5111e4579e2 100644
> --- a/MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c
> +++ b/MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c
> @@ -2,6 +2,7 @@
>  Pei USB ATAPI command implementations.
> 
>  Copyright (c) 1999 - 2018, Intel Corporation. All rights reserved.
> +Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
> 
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> @@ -382,14 +383,14 @@ PeiUsbRead10 (
>ATAPI_PACKET_COMMAND  Packet;
>ATAPI_READ10_CMD  *Read10Packet;
>UINT16MaxBlock;
> -  UINT16BlocksRemaining;
> -  UINT16SectorCount;
> +  UINT32BlocksRemaining;
> +  UINT32SectorCount;
>UINT32Lba32;
>UINT32BlockSize;
>UINT32ByteCount;
>VOID  *PtrBuffer;
>EFI_STATUSStatus;
> -  UINT16TimeOut;
> +  UINT32TimeOut;
> 
>//
>// prepare command packet for the Inquiry Packet Command.
> @@ -401,16 +402,13 @@ PeiUsbRead10 (
> 
>BlockSize = (UINT32)PeiBotDevice->Media.BlockSize;
> 
> -  MaxBlock= (UINT16)(65535 / BlockSize);
> -  BlocksRemaining = (UINT16)NumberOfBlocks;
> +  MaxBlock = (UINT16)(MAX_UINT16 / BlockSize);
> +  ASSERT (NumberOfBlocks < MAX_UINT32);
> +  BlocksRemaining = (UINT32)NumberOfBlocks;
> 
>Status = EFI_SUCCESS;
>while (BlocksRemaining > 0) {
> -if (BlocksRemaining <= MaxBlock) {
> -  SectorCount = BlocksRemaining;
> -} else {
> -  SectorCount = MaxBlock;
> -}
> +SectorCount = MIN (BlocksRemaining, MaxBlock);
> 
>  //
>  // fill the Packet data structure
> @@ -435,7 +433,7 @@ PeiUsbRead10 (
> 
>  ByteCount = SectorCount * BlockSize;
> 
> -TimeOut = (UINT16)(SectorCount * 2000);
> +TimeOut = SectorCount * 2000;
> 
>  //
>  // send command packet
> @@ -448,16 +446,17 @@ PeiUsbRead10 (
> (VOID *)PtrBuffer,
> ByteCount,
> EfiUsbDataIn,
> -   TimeOut
> +   (UINT16)MIN (TimeOut, MAX_UINT16)
> );
> 
>  if (Status != EFI_SUCCESS) {
>return Status;
>  }
> 
> +ASSERT (Lba32 <= (MAX_UINT32-SectorCount));
>  Lba32  += SectorCount;
>  PtrBuffer   = (UINT8 *)PtrBuffer + SectorCount * BlockSize;
> -BlocksRemaining = (UINT16)(BlocksRemaining - SectorCount);
> +BlocksRemaining = BlocksRemaining - SectorCount;
>}
> 
>return Status;
> --
> 2.37.1.windows.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#97725): https://edk2.groups.io/g/devel/message/97725
Mute This Topic: https://groups.io/mt/95808341/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH 3/3] MdeModulePkg/XhciPei: Unlinked XhciPei memory block

2022-12-22 Thread Wu, Hao A
Sorry,

I found that I missed pointing out in the previous discussion that within 
function UsbHcFreeMem(),
below snippet of code should be updated as well:

  //
  // Release the current memory block if it is empty and not the head
  //
  if ((Block != Head) && UsbHcIsMemBlockEmpty (Block)) {
// UsbHcUnlinkMemBlock (Head, Block);
UsbHcFreeMemBlock (Pool, Block);
  }

Could you help to double check if the above UsbHcUnlinkMemBlock() call should 
be uncommented?
Thanks in advance.

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Chang,
> Abner via groups.io
> Sent: Wednesday, December 21, 2022 11:42 PM
> To: devel@edk2.groups.io
> Cc: Wu, Hao A ; Ni, Ray ; Garrett
> Kirkendall ; Abner Chang
> ; Kuei-Hung Lin 
> Subject: [edk2-devel] [PATCH 3/3] MdeModulePkg/XhciPei: Unlinked XhciPei
> memory block
> 
> From: Abner Chang 
> 
> Unlink the XhciPei memory block when it has been freed.
> 
> Signed-off-by: Jiangang He 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Cc: Garrett Kirkendall 
> Cc: Abner Chang 
> Cc: Kuei-Hung Lin 
> ---
>  MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c | 29
> -
>  1 file changed, 28 insertions(+), 1 deletion(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c
> b/MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c
> index c64b38fcfc8..7dc014e465d 100644
> --- a/MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c
> +++ b/MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c
> @@ -3,6 +3,7 @@ PEIM to produce gPeiUsb2HostControllerPpiGuid based
> on gPeiUsbControllerPpiGuid
>  which is used to enable recovery function from USB Drivers.
> 
>  Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.
> +Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
> 
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> @@ -365,6 +366,32 @@ UsbHcInitMemPool (
>return Pool;
>  }
> 
> +/**
> +  Unlink the memory block from the pool's list.
> +
> +  @param  Head   The block list head of the memory's pool.
> +  @param  BlockToUnlink  The memory block to unlink.
> +
> +**/
> +VOID
> +UsbHcUnlinkMemBlock (
> +  IN USBHC_MEM_BLOCK  *Head,
> +  IN USBHC_MEM_BLOCK  *BlockToUnlink
> +  )
> +{
> +  USBHC_MEM_BLOCK  *Block;
> +
> +  ASSERT ((Head != NULL) && (BlockToUnlink != NULL));
> +
> +  for (Block = Head; Block != NULL; Block = Block->Next) {
> +if (Block->Next == BlockToUnlink) {
> +  Block->Next = BlockToUnlink->Next;
> +  BlockToUnlink->Next = NULL;
> +  break;
> +}
> +  }
> +}
> +
>  /**
>Release the memory management pool.
> 
> @@ -386,7 +413,7 @@ UsbHcFreeMemPool (
>// first block.
>//
>for (Block = Pool->Head->Next; Block != NULL; Block = Pool->Head->Next) {
> -// UsbHcUnlinkMemBlock (Pool->Head, Block);
> +UsbHcUnlinkMemBlock (Pool->Head, Block);
>  UsbHcFreeMemBlock (Pool, Block);
>}
> 
> --
> 2.37.1.windows.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#97724): https://edk2.groups.io/g/devel/message/97724
Mute This Topic: https://groups.io/mt/95808360/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH 3/3] MdeModulePkg/Bus/Pci/XhciDxe: Check port is compatible before getting PSIV

2022-12-20 Thread Wu, Hao A
Merged via:
PR - https://github.com/tianocore/edk2/pull/3806
Commit - 
https://github.com/tianocore/edk2/commit/ec25e904c7da70302f2725e2005e3762f1ae891e

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Wu, Hao
> A
> Sent: Monday, December 19, 2022 3:46 PM
> To: devel@edk2.groups.io; Rhodes, Sean 
> Subject: Re: [edk2-devel] [PATCH 3/3] MdeModulePkg/Bus/Pci/XhciDxe:
> Check port is compatible before getting PSIV
> 
> Reviewed-by: Hao A Wu 
> 
> I will make minor modification to:
> * Function description comment
> * Input parameter name
> of XhcCheckUsbPortSpeedUsedPsic() to make the declaration (in .H) and the
> definition (in .C) match.
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: devel@edk2.groups.io  On Behalf Of Sean
> > Rhodes
> > Sent: Friday, December 16, 2022 4:58 PM
> > To: devel@edk2.groups.io
> > Cc: Rhodes, Sean 
> > Subject: [edk2-devel] [PATCH 3/3] MdeModulePkg/Bus/Pci/XhciDxe: Check
> > port is compatible before getting PSIV
> >
> > On some platforms, including Sky Lake and Kaby Lake, the PSIV
> > (Protocol Speed ID Value) indices are shared between Protocol Speed ID
> > DWORD' in the extended capabilities registers for both USB2 (Full
> > Speed) and USB3 (Super Speed).
> >
> > An example can be found below:
> >
> > XhcCheckUsbPortSpeedUsedPsic: checking for USB2 ext caps
> > XhciPsivGetPsid: found 3 PSID entries
> > XhciPsivGetPsid: looking for port speed 1
> > XhciPsivGetPsid: PSIV 1 PSIE 2 PLT 0 PSIM 12
> > XhciPsivGetPsid: PSIV 2 PSIE 1 PLT 0 PSIM 1500
> > XhciPsivGetPsid: PSIV 3 PSIE 2 PLT 0 PSIM 480
> > XhcCheckUsbPortSpeedUsedPsic: checking for USB3 ext caps
> > XhciPsivGetPsid: found 3 PSID entries
> > XhciPsivGetPsid: looking for port speed 1
> > XhciPsivGetPsid: PSIV 1 PSIE 3 PLT 0 PSIM 5
> > XhciPsivGetPsid: PSIV 2 PSIE 3 PLT 0 PSIM 10
> > XhciPsivGetPsid: PSIV 34 PSIE 2 PLT 0 PSIM 1248
> >
> > The result is edk2 detecting USB2 devices as USB3 devices, which
> > consequently causes enumeration to fail.
> >
> > To avoid incorrect detection, check the Compatible Port Offset to find
> > the starting Port of Root Hubs that support the protocol.
> >
> > Signed-off-by: Sean Rhodes 
> > ---
> >  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c|  2 +-
> >  MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c | 35 +--
> > ---
> >  MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.h |  8 +++---
> >  3 files changed, 35 insertions(+), 10 deletions(-)
> >
> > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > index 8dd7a8fbb7..461b2cd9b5 100644
> > --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > @@ -405,7 +405,7 @@ XhcGetRootHubPortStatus (
> >// Section 7.2 xHCI Support Protocol Capability
> >
> >//
> >
> >if (PortSpeed > 0) {
> >
> > -PortStatus->PortStatus = XhcCheckUsbPortSpeedUsedPsic (Xhc,
> > PortSpeed);
> >
> > +PortStatus->PortStatus = XhcCheckUsbPortSpeedUsedPsic (Xhc,
> > PortSpeed, PortNumber);
> >
> >  // If no match found in ext cap reg, fall back to PORTSC
> >
> >  if (PortStatus->PortStatus == 0) {
> >
> >//
> >
> > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
> > b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
> > index 2b4a4b2444..5700fc5fb8 100644
> > --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
> > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
> > @@ -636,6 +636,7 @@ XhcGetSupportedProtocolCapabilityAddr (
> >@param  XhcThe XHCI Instance.
> >
> >@param  ExtCapOffset   The USB Major Version in xHCI Support Protocol
> > Capability Field
> >
> >@param  PortSpeed  The Port Speed Field in USB PortSc register
> >
> > +  @param  PortNumber The Port Number (0-indexed)
> >
> >
> >
> >@return The Protocol Speed ID (PSI) from xHCI Supported Protocol
> > capability register.
> >
> >
> >
> > @@ -644,12 +645,15 @@ UINT32
> >  XhciPsivGetPsid (
> >
> >IN USB_XHCI_INSTANCE  *Xhc,
> >
> >IN UINT32 ExtCapOffset,
> >
> > -  IN UINT8  PortSpeed
> >
> > +  IN UINT8  PortSpeed,
> >
> > +  IN UINT8  PortNumber
> >
> >)
> >
> >  {
> >
> >XHC_SUPPORTED_PROTOCOL_DW2   

Re: [edk2-devel] [PATCH 2/3] MdeModulePkg/XhciDxe/Xhci: Don't check for invalid PSIV

2022-12-20 Thread Wu, Hao A
Merged via:
PR - https://github.com/tianocore/edk2/pull/3806
Commit - 
https://github.com/tianocore/edk2/commit/01c2fb0d2260d4de898e4e91e48770ffa5510153

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Wu, Hao
> A
> Sent: Monday, December 19, 2022 2:16 PM
> To: Rhodes, Sean ; devel@edk2.groups.io
> Cc: Matt DeVillier ; Ni, Ray ;
> Rhodes, Sean 
> Subject: Re: [edk2-devel] [PATCH 2/3] MdeModulePkg/XhciDxe/Xhci: Don't
> check for invalid PSIV
> 
> Reviewed-by: Hao A Wu 
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: Sean Rhodes 
> > Sent: Friday, December 16, 2022 4:58 PM
> > To: devel@edk2.groups.io
> > Cc: Matt DeVillier ; Wu, Hao A
> > ; Ni, Ray ; Rhodes, Sean
> > 
> > Subject: [PATCH 2/3] MdeModulePkg/XhciDxe/Xhci: Don't check for
> > invalid PSIV
> >
> > From: Matt DeVillier 
> >
> > PSID matching relies on comparing the PSIV against the PortSpeed
> > value. This patch stops edk2 from checking for a PSIV of 0, as it is
> > not valid; this reduces the number of register access by approximately
> > 6 per second.
> >
> > Cc: Hao A Wu 
> > Cc: Ray Ni 
> > Reviewed-by: Sean Rhodes 
> > Signed-off-by: Matt DeVillier 
> > Change-Id: If15c55ab66d2e7faa832ce8576d2e5b47157cc9a
> > ---
> >  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 44
> > -
> >  1 file changed, 25 insertions(+), 19 deletions(-)
> >
> > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > index 15fb49f28f..8dd7a8fbb7 100644
> > --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> > @@ -371,6 +371,7 @@ XhcGetRootHubPortStatus (
> >UINT32 TotalPort;
> >
> >UINTN  Index;
> >
> >UINTN  MapSize;
> >
> > +  UINT8  PortSpeed;
> >
> >EFI_STATUS Status;
> >
> >USB_DEV_ROUTE  ParentRouteChart;
> >
> >EFI_TPLOldTpl;
> >
> > @@ -397,32 +398,37 @@ XhcGetRootHubPortStatus (
> >
> >
> >State = XhcReadOpReg (Xhc, Offset);
> >
> >
> >
> > +  PortSpeed = (State & XHC_PORTSC_PS) >> 10;
> >
> > +
> >
> >//
> >
> >// According to XHCI 1.1 spec November 2017,
> >
> >// Section 7.2 xHCI Support Protocol Capability
> >
> >//
> >
> > -  PortStatus->PortStatus = XhcCheckUsbPortSpeedUsedPsic (Xhc, ((State
> > &
> > XHC_PORTSC_PS) >> 10));
> >
> > -  if (PortStatus->PortStatus == 0) {
> >
> > -//
> >
> > -// According to XHCI 1.1 spec November 2017,
> >
> > -// bit 10~13 of the root port status register identifies the speed of 
> > the
> > attached device.
> >
> > -//
> >
> > -switch ((State & XHC_PORTSC_PS) >> 10) {
> >
> > -  case 2:
> >
> > -PortStatus->PortStatus |= USB_PORT_STAT_LOW_SPEED;
> >
> > -break;
> >
> > +  if (PortSpeed > 0) {
> >
> > +PortStatus->PortStatus = XhcCheckUsbPortSpeedUsedPsic (Xhc,
> > PortSpeed);
> >
> > +// If no match found in ext cap reg, fall back to PORTSC
> >
> > +if (PortStatus->PortStatus == 0) {
> >
> > +  //
> >
> > +  // According to XHCI 1.1 spec November 2017,
> >
> > +  // bit 10~13 of the root port status register identifies the
> > + speed of the
> > attached device.
> >
> > +  //
> >
> > +  switch (PortSpeed) {
> >
> > +case 2:
> >
> > +  PortStatus->PortStatus |= USB_PORT_STAT_LOW_SPEED;
> >
> > +  break;
> >
> >
> >
> > -  case 3:
> >
> > -PortStatus->PortStatus |= USB_PORT_STAT_HIGH_SPEED;
> >
> > -break;
> >
> > +case 3:
> >
> > +  PortStatus->PortStatus |= USB_PORT_STAT_HIGH_SPEED;
> >
> > +  break;
> >
> >
> >
> > -  case 4:
> >
> > -  case 5:
> >
> > -PortStatus->PortStatus |= USB_PORT_STAT_SUPER_SPEED;
> >
> > -break;
> >
> > +case 4:
> >
> > +case 5:
> >
> > +  PortStatus->PortStatus |= USB_PORT_STAT_SUPER_SPEED;
> >
> > +  break;
> >
> >
> >
> > -  default:
> >
> > -break;
> >
> > +default:
> >
> > +  break;
> >
> > +  }
> >
> >  }
> >
> >}
> >
> >
> >
> > --
> > 2.37.2
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#97639): https://edk2.groups.io/g/devel/message/97639
Mute This Topic: https://groups.io/mt/95569298/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH V3] MdeModulePkg/Xhci: Initial XHCI DCI slot's Context value

2022-12-19 Thread Wu, Hao A
Thanks,

For this patch "MdeModulePkg/XhciPei: Unlinked XhciPei memory block", my take 
is that there will also be an updated version, right?
If this is the case, could you help to send out a single 3-patch series for 
them instead of sending 3 separated patches? Thanks in advance.

Best Regards,
Hao Wu

> -Original Message-
> From: Chang, Abner 
> Sent: Tuesday, December 20, 2022 10:45 AM
> To: Wu, Hao A ; devel@edk2.groups.io
> Cc: Lin, Kuei-Hung (Timothy) ; Ni, Ray
> ; Kirkendall, Garrett 
> Subject: RE: [PATCH V3] MdeModulePkg/Xhci: Initial XHCI DCI slot's Context
> value
> 
> [AMD Official Use Only - General]
> 
> Hi Hao,
> That is the uncrustify check error. I already fixed it at "[PATCH V3]
> MdeModulePkg/Usb: Read a large number of blocks."
> 
> Also, these three patches are passed the CI test.
> https://github.com/tianocore/edk2/pull/3794
> 
> Thanks
> Abner
> 
> > -Original Message-
> > From: Wu, Hao A 
> > Sent: Monday, December 12, 2022 11:27 AM
> > To: Chang, Abner ; devel@edk2.groups.io
> > Cc: Lin, Kuei-Hung (Timothy) ; Ni, Ray
> > ; Kirkendall, Garrett 
> > Subject: RE: [PATCH V3] MdeModulePkg/Xhci: Initial XHCI DCI slot's
> > Context value
> >
> > Caution: This message originated from an External Source. Use proper
> > caution when opening attachments, clicking links, or responding.
> >
> >
> > For the 3 patches:
> > [PATCH V2] MdeModulePkg/XhciPei: Unlinked XhciPei memory block
> [PATCH
> > V2] MdeModulePkg/Usb: Read a large number of blocks [PATCH V3]
> > MdeModulePkg/Xhci: Initial XHCI DCI slot's Context value
> >
> > I found that they will cause CI failures:
> >
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgith
> >
> ub.com%2Ftianocore%2Fedk2%2Fpull%2F3749data=05%7C01%7Cabn
> >
> er.chang%40amd.com%7Cfe921dc0e08b4cdf30a208dadbf0cb8c%7C3dd8961
> f
> >
> e4884e608e11a82d994e183d%7C0%7C0%7C638064124508360013%7CUnkno
> w
> >
> n%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1ha
> > WwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=0iQKJ3X3IJv1CSqe
> > mjTWyT1hlYvqGZsYPAdwXEi%2B%2FZ4%3Dreserved=0
> > Could you help to update them and help to ensure they can pass the CI test?
> > Thanks in advance.
> >
> > Best Regards,
> > Hao Wu
> >
> > > -Original Message-
> > > From: abner.ch...@amd.com 
> > > Sent: Saturday, December 10, 2022 11:08 PM
> > > To: devel@edk2.groups.io
> > > Cc: kuei-hung@amd.com; Wu, Hao A ; Ni, Ray
> > > ; Garrett Kirkendall ;
> > > Abner Chang 
> > > Subject: [PATCH V3] MdeModulePkg/Xhci: Initial XHCI DCI slot's
> > > Context value
> > >
> > > From: Abner Chang 
> > >
> > > In V3: Add AMD copyright.
> > > In V2: Remove the signed-off-by: Abner Chang.
> > >
> > > Initialize XHCI DCI slot's context entries value.
> > >
> > > Signed-off-by: Kuei-Hung Lin 
> > > Cc: Hao A Wu 
> > > Cc: Ray Ni 
> > > Cc: Garrett Kirkendall 
> > > Cc: Abner Chang 
> > > ---
> > >  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 7 +++
> > > MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c | 7 +++
> > >  2 files changed, 14 insertions(+)
> > >
> > > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> > > b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> > > index 13b0400e83d..f08722905f3 100644
> > > --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> > > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> > > @@ -4,6 +4,7 @@
> > >
> > >  Copyright (c) 2011 - 2020, Intel Corporation. All rights
> > > reserved.  Copyright (c) Microsoft Corporation.
> > > +Copyright (C) 2022 Advanced Micro Devices, Inc. All rights
> > > +reserved.
> > >  SPDX-License-Identifier: BSD-2-Clause-Patent
> > >
> > >  **/
> > > @@ -2807,6 +2808,9 @@ XhcInitializeEndpointContext (
> > >MaxDci = 0;
> > >
> > >NumEp = IfDesc->NumEndpoints;
> > > +  if (NumEp == 0) {
> > > +MaxDci = 1;
> > > +  }
> > >
> > >EpDesc = (USB_ENDPOINT_DESCRIPTOR *)(IfDesc + 1);
> > >for (EpIndex = 0; EpIndex < NumEp; EpIndex++) { @@ -3006,6
> > > +3010,9 @@ XhcInitializeEndpointContext64 (
> > >MaxDci = 0;
> > >
> > >NumEp = IfDesc->NumEndpoints;
> > > +  if (NumEp == 0) {
> > > +MaxDci = 1;
> > > +  }
> > >
> > >EpDesc = (USB_EN

Re: [edk2-devel] [PATCH V2] MdeModulePkg/XhciPei: Unlinked XhciPei memory block

2022-12-19 Thread Wu, Hao A
Thanks.
You are right. I agree with you that aligning with XhciDxe is a better 
resolution.

Best Regards,
Hao Wu

> -Original Message-
> From: He, Jiangang 
> Sent: Tuesday, December 20, 2022 6:54 AM
> To: Wu, Hao A ; Chang, Abner
> ; devel@edk2.groups.io
> Cc: Lin, Kuei-Hung (Timothy) ; Ni, Ray
> ; Zeng, Star ; Sun, Zhikai
> ; Kirkendall, Garrett 
> Subject: RE: [PATCH V2] MdeModulePkg/XhciPei: Unlinked XhciPei memory
> block
> 
> [AMD Official Use Only - General]
> 
> UsbHcFreeMemBlock()->IoMmuFreeBuffer()->mIoMmu->FreeBuffer(), which
> may end up calling PeiFreePages() depending on gEdkiiIoMmuPpiGuid
> implementation. Surely both will work since UsbHcFreeMemPool() can't be
> interrupted by any service call to use the memory just freed. Just for good
> coding practice reason, I pick the one aligning with XhciDxe.
> 
> Thanks,
> Jiangang
> -Original Message-
> From: Wu, Hao A 
> Sent: Monday, December 19, 2022 12:40 AM
> To: He, Jiangang ; Chang, Abner
> ; devel@edk2.groups.io
> Cc: Lin, Kuei-Hung (Timothy) ; Ni, Ray
> ; Zeng, Star ; Sun, Zhikai
> ; Kirkendall, Garrett 
> Subject: RE: [PATCH V2] MdeModulePkg/XhciPei: Unlinked XhciPei memory
> block
> 
> [AMD Official Use Only - General]
> 
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
> 
> 
> Hello,
> 
> My take is that unlike in DXE, the UsbHcFreeMemBlock() implementation in
> PEI phase does not perform freeing the memory.
> 
> So I think both the solution:
> * Provided at
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fedk2
> .groups.io%2Fg%2Fdevel%2Ftopic%2F92833071%2392165=05%7C01%7
> CJiangang.He%40amd.com%7C528424aa303f4a2c9b1808dae18be036%7C3d
> d8961fe4884e608e11a82d994e183d%7C0%7C0%7C638070288126779782%7C
> Unknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBT
> iI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=uJMNyYXMU22
> UZNjrKtDetyD2BqrvkualuorPZHAV3wg%3D=0, which aligns with
> EhciPei
> * Mentioned at the end of your previous reply, which aligns with XhciDxe
> should work fine.
> 
> I will leave it to you for the final decision.
> 
> Best Regards,
> Hao Wu
> 
> > -Original Message-
> > From: He, Jiangang 
> > Sent: Friday, December 16, 2022 12:48 AM
> > To: Chang, Abner ; Wu, Hao A
> > ; devel@edk2.groups.io
> > Cc: Lin, Kuei-Hung (Timothy) ; Ni, Ray
> > ; Zeng, Star ; Sun, Zhikai
> > ; Kirkendall, Garrett
> > 
> > Subject: RE: [PATCH V2] MdeModulePkg/XhciPei: Unlinked XhciPei memory
> > block
> >
> > [AMD Official Use Only - General]
> >
> > Yes, it is the same issue discussed in
> >
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fedk2
> > .groups.io%2Fg%2Fdevel%2Ftopic%2F92833071%2392165=05%7C01
> %7CJiang
> >
> ang.He%40amd.com%7C528424aa303f4a2c9b1808dae18be036%7C3dd8961f
> e4884e60
> >
> 8e11a82d994e183d%7C0%7C0%7C638070288126936018%7CUnknown%7CT
> WFpbGZsb3d8
> >
> eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3
> D%7C3
> >
> 000%7C%7C%7C=58j41QJxKbrQenhyZKYO4dxYj3Sat2kJejQGioZhtu4%3
> D
> > rved=0
> >
> > MdeModulePkg\Bus\Pci\XhciPei\UsbHcMem.c
> >
> >   for (Block = Pool->Head->Next; Block != NULL; Block = Pool->Head->Next) {
> > // UsbHcUnlinkMemBlock (Pool->Head, Block);
> > UsbHcFreeMemBlock (Pool, Block);
> >   }
> > Block = Pool->Head->Next never change without calling
> > UsbHcUnlinkMemBlock (Pool->Head, Block), therefore dead loop.
> >
> > Our proposed fix came from dxe version of the equivalent file
> > MdeModulePkg\Bus\Pci\XhciDxe\UsbHcMem.c but swapped two routine
> call
> > order (Now I think it is incorrect as clarified below).
> >   for (Block = Pool->Head->Next; Block != NULL; Block = Pool->Head->Next) {
> > UsbHcFreeMemBlock (Pool, Block);
> > UsbHcUnlinkMemBlock (Pool->Head, Block);
> >   }
> >
> >
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fedk2
> .groups.io%2Fg%2Fdevel%2Ftopic%2F92833071%2392165=05%7C01%7
> CJiangang.He%40amd.com%7C528424aa303f4a2c9b1808dae18be036%7C3d
> d8961fe4884e608e11a82d994e183d%7C0%7C0%7C638070288126936018%7C
> Unknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBT
> iI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=58j41QJxKbrQen
> hyZKYO4dxYj3Sat2kJejQGioZhtu4%3D=0 proposed fix:
> >
> >   for (Block = Pool->Head->Next; Block != NULL; Block = Block ->Next) {
> > // UsbHcUnlinkMemBlock (Pool->Head, Block);
> > Us

Re: [edk2-devel] [PATCH 3/3] MdeModulePkg/Bus/Pci/XhciDxe: Check port is compatible before getting PSIV

2022-12-18 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

I will make minor modification to:
* Function description comment
* Input parameter name
of XhcCheckUsbPortSpeedUsedPsic() to make the declaration (in .H) and the 
definition (in .C) match.

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Sean
> Rhodes
> Sent: Friday, December 16, 2022 4:58 PM
> To: devel@edk2.groups.io
> Cc: Rhodes, Sean 
> Subject: [edk2-devel] [PATCH 3/3] MdeModulePkg/Bus/Pci/XhciDxe: Check
> port is compatible before getting PSIV
> 
> On some platforms, including Sky Lake and Kaby Lake, the PSIV (Protocol
> Speed ID Value) indices are shared between Protocol Speed ID DWORD' in
> the extended capabilities registers for both USB2 (Full Speed) and USB3
> (Super Speed).
> 
> An example can be found below:
> 
> XhcCheckUsbPortSpeedUsedPsic: checking for USB2 ext caps
> XhciPsivGetPsid: found 3 PSID entries
> XhciPsivGetPsid: looking for port speed 1
> XhciPsivGetPsid: PSIV 1 PSIE 2 PLT 0 PSIM 12
> XhciPsivGetPsid: PSIV 2 PSIE 1 PLT 0 PSIM 1500
> XhciPsivGetPsid: PSIV 3 PSIE 2 PLT 0 PSIM 480
> XhcCheckUsbPortSpeedUsedPsic: checking for USB3 ext caps
> XhciPsivGetPsid: found 3 PSID entries
> XhciPsivGetPsid: looking for port speed 1
> XhciPsivGetPsid: PSIV 1 PSIE 3 PLT 0 PSIM 5
> XhciPsivGetPsid: PSIV 2 PSIE 3 PLT 0 PSIM 10
> XhciPsivGetPsid: PSIV 34 PSIE 2 PLT 0 PSIM 1248
> 
> The result is edk2 detecting USB2 devices as USB3 devices, which
> consequently causes enumeration to fail.
> 
> To avoid incorrect detection, check the Compatible Port Offset to find
> the starting Port of Root Hubs that support the protocol.
> 
> Signed-off-by: Sean Rhodes 
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c|  2 +-
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c | 35 +--
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.h |  8 +++---
>  3 files changed, 35 insertions(+), 10 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> index 8dd7a8fbb7..461b2cd9b5 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> @@ -405,7 +405,7 @@ XhcGetRootHubPortStatus (
>// Section 7.2 xHCI Support Protocol Capability
> 
>//
> 
>if (PortSpeed > 0) {
> 
> -PortStatus->PortStatus = XhcCheckUsbPortSpeedUsedPsic (Xhc,
> PortSpeed);
> 
> +PortStatus->PortStatus = XhcCheckUsbPortSpeedUsedPsic (Xhc,
> PortSpeed, PortNumber);
> 
>  // If no match found in ext cap reg, fall back to PORTSC
> 
>  if (PortStatus->PortStatus == 0) {
> 
>//
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
> index 2b4a4b2444..5700fc5fb8 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
> @@ -636,6 +636,7 @@ XhcGetSupportedProtocolCapabilityAddr (
>@param  XhcThe XHCI Instance.
> 
>@param  ExtCapOffset   The USB Major Version in xHCI Support Protocol
> Capability Field
> 
>@param  PortSpeed  The Port Speed Field in USB PortSc register
> 
> +  @param  PortNumber The Port Number (0-indexed)
> 
> 
> 
>@return The Protocol Speed ID (PSI) from xHCI Supported Protocol
> capability register.
> 
> 
> 
> @@ -644,12 +645,15 @@ UINT32
>  XhciPsivGetPsid (
> 
>IN USB_XHCI_INSTANCE  *Xhc,
> 
>IN UINT32 ExtCapOffset,
> 
> -  IN UINT8  PortSpeed
> 
> +  IN UINT8  PortSpeed,
> 
> +  IN UINT8  PortNumber
> 
>)
> 
>  {
> 
>XHC_SUPPORTED_PROTOCOL_DW2PortId;
> 
>XHC_SUPPORTED_PROTOCOL_PROTOCOL_SPEED_ID  Reg;
> 
>UINT32Count;
> 
> +  UINT32MinPortIndex;
> 
> +  UINT32MaxPortIndex;
> 
> 
> 
>if ((Xhc == NULL) || (ExtCapOffset == 0x)) {
> 
>  return 0;
> 
> @@ -663,6 +667,23 @@ XhciPsivGetPsid (
>//
> 
>PortId.Dword = XhcReadExtCapReg (Xhc, ExtCapOffset +
> XHC_SUPPORTED_PROTOCOL_DW2_OFFSET);
> 
> 
> 
> +  //
> 
> +  // According to XHCI 1.1 spec November 2017, valid values
> 
> +  // for CompPortOffset are 1 to CompPortCount - 1.
> 
> +  //
> 
> +  // PortNumber is zero-indexed, so subtract 1.
> 
> +  //
> 
> +  if ((PortId.Data.CompPortOffset == 0) || (PortId.Data.CompPortCount ==
> 0)) {
> 
> +return 0;
> 
> +  }
> 
> +
> 
> +  MinPortIndex = PortId.Data.CompPortOffset - 1;
> 
> +  MaxPortIndex = MinPortIndex + PortId.Data.CompPortCount - 1;
> 
> +
> 
> +  if ((PortNumber < MinPortIndex) || (PortNumber > MaxPortIndex)) {
> 
> +return 0;
> 
> +  }
> 
> +
> 
>for (Count = 0; Count < PortId.Data.Psic; Count++) {
> 
>  Reg.Dword = XhcReadExtCapReg (Xhc, ExtCapOffset +
> XHC_SUPPORTED_PROTOCOL_PSI_OFFSET + (Count << 2));
> 
>  if (Reg.Data.Psiv == PortSpeed) {
> 
> @@ -676,8 +697,9 @@ XhciPsivGetPsid (
>  /**
> 
>Find PortSpeed value match case 

Re: [edk2-devel] [PATCH V2] MdeModulePkg/XhciPei: Unlinked XhciPei memory block

2022-12-18 Thread Wu, Hao A
Hello,

My take is that unlike in DXE, the UsbHcFreeMemBlock() implementation in PEI 
phase does not perform freeing the memory.

So I think both the solution:
* Provided at https://edk2.groups.io/g/devel/topic/92833071#92165, which aligns 
with EhciPei
* Mentioned at the end of your previous reply, which aligns with XhciDxe
should work fine.

I will leave it to you for the final decision.

Best Regards,
Hao Wu

> -Original Message-
> From: He, Jiangang 
> Sent: Friday, December 16, 2022 12:48 AM
> To: Chang, Abner ; Wu, Hao A
> ; devel@edk2.groups.io
> Cc: Lin, Kuei-Hung (Timothy) ; Ni, Ray
> ; Zeng, Star ; Sun, Zhikai
> ; Kirkendall, Garrett 
> Subject: RE: [PATCH V2] MdeModulePkg/XhciPei: Unlinked XhciPei memory
> block
> 
> [AMD Official Use Only - General]
> 
> Yes, it is the same issue discussed in
> https://edk2.groups.io/g/devel/topic/92833071#92165
> 
> MdeModulePkg\Bus\Pci\XhciPei\UsbHcMem.c
> 
>   for (Block = Pool->Head->Next; Block != NULL; Block = Pool->Head->Next) {
> // UsbHcUnlinkMemBlock (Pool->Head, Block);
> UsbHcFreeMemBlock (Pool, Block);
>   }
> Block = Pool->Head->Next never change without calling
> UsbHcUnlinkMemBlock (Pool->Head, Block), therefore dead loop.
> 
> Our proposed fix came from dxe version of the equivalent file
> MdeModulePkg\Bus\Pci\XhciDxe\UsbHcMem.c but swapped two routine call
> order (Now I think it is incorrect as clarified below).
>   for (Block = Pool->Head->Next; Block != NULL; Block = Pool->Head->Next) {
> UsbHcFreeMemBlock (Pool, Block);
> UsbHcUnlinkMemBlock (Pool->Head, Block);
>   }
> 
> https://edk2.groups.io/g/devel/topic/92833071#92165 proposed fix:
> 
>   for (Block = Pool->Head->Next; Block != NULL; Block = Block ->Next) {
> // UsbHcUnlinkMemBlock (Pool->Head, Block);
> UsbHcFreeMemBlock (Pool, Block);
>   }
> 
> I think it again, both proposals have problem of reading memory content in
> the buffer that has just been freed.
> 
>   for (Block = Pool->Head->Next; Block != NULL; Block = Pool->Head->Next) {
>  UsbHcUnlinkMemBlock (Pool->Head, Block);
> UsbHcFreeMemBlock (Pool, Block);
>   }
> is right solution and matches dxe version of UsbHcMem.c.
> 
> Thanks,
> Jiangang
> 
> -Original Message-
> From: Chang, Abner 
> Sent: Wednesday, December 14, 2022 8:12 PM
> To: Wu, Hao A ; devel@edk2.groups.io
> Cc: Lin, Kuei-Hung (Timothy) ; Ni, Ray
> ; Zeng, Star ; Sun, Zhikai
> ; Kirkendall, Garrett ;
> He, Jiangang 
> Subject: RE: [PATCH V2] MdeModulePkg/XhciPei: Unlinked XhciPei memory
> block
> 
> [AMD Official Use Only - General]
> 
> Hi Jiangang,
> Could you please provide the context of this patch?
> 
> Thanks
> Abner
> 
> > -Original Message-
> > From: Wu, Hao A 
> > Sent: Monday, December 12, 2022 11:27 AM
> > To: Chang, Abner ; devel@edk2.groups.io
> > Cc: Lin, Kuei-Hung (Timothy) ; Ni, Ray
> > ; Zeng, Star ; Sun, Zhikai
> > ; Kirkendall, Garrett
> > 
> > Subject: RE: [PATCH V2] MdeModulePkg/XhciPei: Unlinked XhciPei memory
> > block
> >
> > Caution: This message originated from an External Source. Use proper
> > caution when opening attachments, clicking links, or responding.
> >
> >
> > Sorry for a question, may I know what issue was met that leads to the
> > proposed patch?
> > Could you help to check if it is related with the topic discussed in
> >
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fedk2
> > .gr
> >
> oups.io%2Fg%2Fdevel%2Ftopic%2F92833071%2392165data=05%7C0
> 1%7
> >
> Cabner.chang%40amd.com%7Ccac49c2820e741b8c48a08dadbf0cc24%7C3d
> d8
> >
> 961fe4884e608e11a82d994e183d%7C0%7C0%7C638064124512265992%7C
> Unk
> >
> nown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6I
> k1h
> >
> aWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=z1Q7NRxN4GMA
> %2
> > FBxYd2D7Gnkc3aTD23mRnwNF3H5wE0k%3Dreserved=0? Thanks in
> advance.
> >
> > Best Regards,
> > Hao Wu
> >
> > > -Original Message-
> > > From: abner.ch...@amd.com 
> > > Sent: Saturday, December 10, 2022 11:13 PM
> > > To: devel@edk2.groups.io
> > > Cc: kuei-hung@amd.com; Wu, Hao A ; Ni, Ray
> > > ; Garrett Kirkendall ;
> > > Abner Chang 
> > > Subject: [PATCH V2] MdeModulePkg/XhciPei: Unlinked XhciPei memory
> > > block
> > >
> > > From: Abner Chang 
> > >
> > > In V2: Add AMD copyright.
> > >
> > > Unlink the XhciPei memory block when it has been freed.
> > >
> > >

Re: [edk2-devel] [PATCH 2/3] MdeModulePkg/XhciDxe/Xhci: Don't check for invalid PSIV

2022-12-18 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: Sean Rhodes 
> Sent: Friday, December 16, 2022 4:58 PM
> To: devel@edk2.groups.io
> Cc: Matt DeVillier ; Wu, Hao A
> ; Ni, Ray ; Rhodes, Sean
> 
> Subject: [PATCH 2/3] MdeModulePkg/XhciDxe/Xhci: Don't check for invalid
> PSIV
> 
> From: Matt DeVillier 
> 
> PSID matching relies on comparing the PSIV against the PortSpeed
> value. This patch stops edk2 from checking for a PSIV of 0, as it
> is not valid; this reduces the number of register access by
> approximately 6 per second.
> 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Reviewed-by: Sean Rhodes 
> Signed-off-by: Matt DeVillier 
> Change-Id: If15c55ab66d2e7faa832ce8576d2e5b47157cc9a
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 44 -
>  1 file changed, 25 insertions(+), 19 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> index 15fb49f28f..8dd7a8fbb7 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> @@ -371,6 +371,7 @@ XhcGetRootHubPortStatus (
>UINT32 TotalPort;
> 
>UINTN  Index;
> 
>UINTN  MapSize;
> 
> +  UINT8  PortSpeed;
> 
>EFI_STATUS Status;
> 
>USB_DEV_ROUTE  ParentRouteChart;
> 
>EFI_TPLOldTpl;
> 
> @@ -397,32 +398,37 @@ XhcGetRootHubPortStatus (
> 
> 
>State = XhcReadOpReg (Xhc, Offset);
> 
> 
> 
> +  PortSpeed = (State & XHC_PORTSC_PS) >> 10;
> 
> +
> 
>//
> 
>// According to XHCI 1.1 spec November 2017,
> 
>// Section 7.2 xHCI Support Protocol Capability
> 
>//
> 
> -  PortStatus->PortStatus = XhcCheckUsbPortSpeedUsedPsic (Xhc, ((State &
> XHC_PORTSC_PS) >> 10));
> 
> -  if (PortStatus->PortStatus == 0) {
> 
> -//
> 
> -// According to XHCI 1.1 spec November 2017,
> 
> -// bit 10~13 of the root port status register identifies the speed of the
> attached device.
> 
> -//
> 
> -switch ((State & XHC_PORTSC_PS) >> 10) {
> 
> -  case 2:
> 
> -PortStatus->PortStatus |= USB_PORT_STAT_LOW_SPEED;
> 
> -break;
> 
> +  if (PortSpeed > 0) {
> 
> +PortStatus->PortStatus = XhcCheckUsbPortSpeedUsedPsic (Xhc,
> PortSpeed);
> 
> +// If no match found in ext cap reg, fall back to PORTSC
> 
> +if (PortStatus->PortStatus == 0) {
> 
> +  //
> 
> +  // According to XHCI 1.1 spec November 2017,
> 
> +  // bit 10~13 of the root port status register identifies the speed of 
> the
> attached device.
> 
> +  //
> 
> +  switch (PortSpeed) {
> 
> +case 2:
> 
> +  PortStatus->PortStatus |= USB_PORT_STAT_LOW_SPEED;
> 
> +  break;
> 
> 
> 
> -  case 3:
> 
> -PortStatus->PortStatus |= USB_PORT_STAT_HIGH_SPEED;
> 
> -break;
> 
> +case 3:
> 
> +  PortStatus->PortStatus |= USB_PORT_STAT_HIGH_SPEED;
> 
> +  break;
> 
> 
> 
> -  case 4:
> 
> -  case 5:
> 
> -PortStatus->PortStatus |= USB_PORT_STAT_SUPER_SPEED;
> 
> -break;
> 
> +case 4:
> 
> +case 5:
> 
> +  PortStatus->PortStatus |= USB_PORT_STAT_SUPER_SPEED;
> 
> +  break;
> 
> 
> 
> -  default:
> 
> -break;
> 
> +default:
> 
> +  break;
> 
> +  }
> 
>  }
> 
>}
> 
> 
> 
> --
> 2.37.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#97545): https://edk2.groups.io/g/devel/message/97545
Mute This Topic: https://groups.io/mt/95569298/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH 3/3] MdeModulePkg/Bus/Pci/XhciDxe: Handle incorrect PSIV indices

2022-12-14 Thread Wu, Hao A
Sorry,

Could you help to:
1. Update the function description comment for XhcCheckUsbPortSpeedUsedPsic() 
in .C/.H files for adding the new input parameter 'PortNumber'
2. Add additional checks in XhciPsivGetPsid() to not allow:
* PortId.Data.CompPortOffset having a value of 0
* PortId.Data.CompPortCount having a value of 0

Best Regards,
Hao Wu

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Sean
> Rhodes
> Sent: Saturday, December 10, 2022 4:46 AM
> To: devel@edk2.groups.io
> Cc: Rhodes, Sean 
> Subject: [edk2-devel] [PATCH 3/3] MdeModulePkg/Bus/Pci/XhciDxe: Handle
> incorrect PSIV indices
> 
> On some platforms, including Sky Lake and Kaby Lake, the PSIV (Protocol
> Speed ID Value) indices are shared between Protocol Speed ID DWORD' in
> the extended capabilities registers for both USB2 (Full Speed) and USB3
> (Super Speed).
> 
> An example can be found below:
> 
> XhcCheckUsbPortSpeedUsedPsic: checking for USB2 ext caps
> XhciPsivGetPsid: found 3 PSID entries
> XhciPsivGetPsid: looking for port speed 1
> XhciPsivGetPsid: PSIV 1 PSIE 2 PLT 0 PSIM 12
> XhciPsivGetPsid: PSIV 2 PSIE 1 PLT 0 PSIM 1500
> XhciPsivGetPsid: PSIV 3 PSIE 2 PLT 0 PSIM 480
> XhcCheckUsbPortSpeedUsedPsic: checking for USB3 ext caps
> XhciPsivGetPsid: found 3 PSID entries
> XhciPsivGetPsid: looking for port speed 1
> XhciPsivGetPsid: PSIV 1 PSIE 3 PLT 0 PSIM 5
> XhciPsivGetPsid: PSIV 2 PSIE 3 PLT 0 PSIM 10
> XhciPsivGetPsid: PSIV 34 PSIE 2 PLT 0 PSIM 1248
> 
> The result is edk2 detecting USB2 devices as USB3 devices, which
> consequently causes enumeration to fail.
> 
> To avoid incorrect detection, check the Compatible Port Offset to find
> the starting Port of Root Hubs that support the protocol.
> 
> Signed-off-by: Sean Rhodes 
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c|  2 +-
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c | 26
> ++
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.h |  3 ++-
>  3 files changed, 25 insertions(+), 6 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> index 8dd7a8fbb7..461b2cd9b5 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> @@ -405,7 +405,7 @@ XhcGetRootHubPortStatus (
>// Section 7.2 xHCI Support Protocol Capability
> 
>//
> 
>if (PortSpeed > 0) {
> 
> -PortStatus->PortStatus = XhcCheckUsbPortSpeedUsedPsic (Xhc,
> PortSpeed);
> 
> +PortStatus->PortStatus = XhcCheckUsbPortSpeedUsedPsic (Xhc,
> PortSpeed, PortNumber);
> 
>  // If no match found in ext cap reg, fall back to PORTSC
> 
>  if (PortStatus->PortStatus == 0) {
> 
>//
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
> index 2b4a4b2444..bca53e9ac0 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
> @@ -636,6 +636,7 @@ XhcGetSupportedProtocolCapabilityAddr (
>@param  XhcThe XHCI Instance.
> 
>@param  ExtCapOffset   The USB Major Version in xHCI Support Protocol
> Capability Field
> 
>@param  PortSpeed  The Port Speed Field in USB PortSc register
> 
> +  @param  PortNumber The Port Number (0-indexed)
> 
> 
> 
>@return The Protocol Speed ID (PSI) from xHCI Supported Protocol
> capability register.
> 
> 
> 
> @@ -644,12 +645,15 @@ UINT32
>  XhciPsivGetPsid (
> 
>IN USB_XHCI_INSTANCE  *Xhc,
> 
>IN UINT32 ExtCapOffset,
> 
> -  IN UINT8  PortSpeed
> 
> +  IN UINT8  PortSpeed,
> 
> +  IN UINT8  PortNumber
> 
>)
> 
>  {
> 
>XHC_SUPPORTED_PROTOCOL_DW2PortId;
> 
>XHC_SUPPORTED_PROTOCOL_PROTOCOL_SPEED_ID  Reg;
> 
>UINT32Count;
> 
> +  UINT32MinPortIndex;
> 
> +  UINT32MaxPortIndex;
> 
> 
> 
>if ((Xhc == NULL) || (ExtCapOffset == 0x)) {
> 
>  return 0;
> 
> @@ -663,6 +667,19 @@ XhciPsivGetPsid (
>//
> 
>PortId.Dword = XhcReadExtCapReg (Xhc, ExtCapOffset +
> XHC_SUPPORTED_PROTOCOL_DW2_OFFSET);
> 
> 
> 
> +  //
> 
> +  // According to XHCI 1.1 spec November 2017, valid values
> 
> +  // for CompPortOffset are 1 to CompPortCount - 1.
> 
> +  //
> 
> +  // PortNumber is zero-indexed, so subtract 1.
> 
> +  //
> 
> +  MinPortIndex = PortId.Data.CompPortOffset - 1;
> 
> +  MaxPortIndex = MinPortIndex + PortId.Data.CompPortCount - 1;
> 
> +
> 
> +  if ((PortNumber < MinPortIndex) || (PortNumber > MaxPortIndex)) {
> 
> +return 0;
> 
> +  }
> 
> +
> 
>for (Count = 0; Count < PortId.Data.Psic; Count++) {
> 
>  Reg.Dword = XhcReadExtCapReg (Xhc, ExtCapOffset +
> XHC_SUPPORTED_PROTOCOL_PSI_OFFSET + (Count << 2));
> 
>  if (Reg.Data.Psiv == PortSpeed) {
> 
> @@ -685,7 +702,8 @@ XhciPsivGetPsid (
>  UINT16
> 
>  XhcCheckUsbPortSpeedUsedPsic (
> 
>IN 

Re: [edk2-devel] [PATCH 2/3] MdeModulePkg/XhciDxe/Xhci: Don't check for invalid PSIV

2022-12-14 Thread Wu, Hao A
Reviewed-by: Hao A Wu 

Best Regards,
Hao Wu

> -Original Message-
> From: Sean Rhodes 
> Sent: Saturday, December 10, 2022 4:46 AM
> To: devel@edk2.groups.io
> Cc: Matt DeVillier ; Wu, Hao A
> ; Ni, Ray ; Rhodes, Sean
> 
> Subject: [PATCH 2/3] MdeModulePkg/XhciDxe/Xhci: Don't check for invalid
> PSIV
> 
> From: Matt DeVillier 
> 
> PSID matching relies on comparing the PSIV against the PortSpeed
> value. This patch stops edk2 from checking for a PSIV of 0, as it
> is not valid; this reduces the number of register access by
> approximately 6 per second.
> 
> Cc: Hao A Wu 
> Cc: Ray Ni 
> Reviewed-by: Sean Rhodes 
> Signed-off-by: Matt DeVillier 
> Change-Id: If15c55ab66d2e7faa832ce8576d2e5b47157cc9a
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 44 -
>  1 file changed, 25 insertions(+), 19 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> index 15fb49f28f..8dd7a8fbb7 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> @@ -371,6 +371,7 @@ XhcGetRootHubPortStatus (
>UINT32 TotalPort;
> 
>UINTN  Index;
> 
>UINTN  MapSize;
> 
> +  UINT8  PortSpeed;
> 
>EFI_STATUS Status;
> 
>USB_DEV_ROUTE  ParentRouteChart;
> 
>EFI_TPLOldTpl;
> 
> @@ -397,32 +398,37 @@ XhcGetRootHubPortStatus (
> 
> 
>State = XhcReadOpReg (Xhc, Offset);
> 
> 
> 
> +  PortSpeed = (State & XHC_PORTSC_PS) >> 10;
> 
> +
> 
>//
> 
>// According to XHCI 1.1 spec November 2017,
> 
>// Section 7.2 xHCI Support Protocol Capability
> 
>//
> 
> -  PortStatus->PortStatus = XhcCheckUsbPortSpeedUsedPsic (Xhc, ((State &
> XHC_PORTSC_PS) >> 10));
> 
> -  if (PortStatus->PortStatus == 0) {
> 
> -//
> 
> -// According to XHCI 1.1 spec November 2017,
> 
> -// bit 10~13 of the root port status register identifies the speed of the
> attached device.
> 
> -//
> 
> -switch ((State & XHC_PORTSC_PS) >> 10) {
> 
> -  case 2:
> 
> -PortStatus->PortStatus |= USB_PORT_STAT_LOW_SPEED;
> 
> -break;
> 
> +  if (PortSpeed > 0) {
> 
> +PortStatus->PortStatus = XhcCheckUsbPortSpeedUsedPsic (Xhc,
> PortSpeed);
> 
> +// If no match found in ext cap reg, fall back to PORTSC
> 
> +if (PortStatus->PortStatus == 0) {
> 
> +  //
> 
> +  // According to XHCI 1.1 spec November 2017,
> 
> +  // bit 10~13 of the root port status register identifies the speed of 
> the
> attached device.
> 
> +  //
> 
> +  switch (PortSpeed) {
> 
> +case 2:
> 
> +  PortStatus->PortStatus |= USB_PORT_STAT_LOW_SPEED;
> 
> +  break;
> 
> 
> 
> -  case 3:
> 
> -PortStatus->PortStatus |= USB_PORT_STAT_HIGH_SPEED;
> 
> -break;
> 
> +case 3:
> 
> +  PortStatus->PortStatus |= USB_PORT_STAT_HIGH_SPEED;
> 
> +  break;
> 
> 
> 
> -  case 4:
> 
> -  case 5:
> 
> -PortStatus->PortStatus |= USB_PORT_STAT_SUPER_SPEED;
> 
> -break;
> 
> +case 4:
> 
> +case 5:
> 
> +  PortStatus->PortStatus |= USB_PORT_STAT_SUPER_SPEED;
> 
> +  break;
> 
> 
> 
> -  default:
> 
> -break;
> 
> +default:
> 
> +  break;
> 
> +  }
> 
>  }
> 
>}
> 
> 
> 
> --
> 2.37.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#97406): https://edk2.groups.io/g/devel/message/97406
Mute This Topic: https://groups.io/mt/95569298/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




  1   2   3   4   5   6   7   8   9   10   >