Sorry, missed one change, “EPState” field should be cleared to 0 for input context:
INPUT_CONTEXT_64 *InputContext;
DEVICE_CONTEXT_64 *OutputContext;
EFI_PHYSICAL_ADDRESS PhyAddr;
ASSERT (Xhc->UsbDevContext[SlotId].SlotId != 0);
//
// 4.6.7 Evaluate Context
//
InputContext = Xhc->UsbDevContext[SlotId].InputContext;
OutputContext = Xhc->UsbDevContext[SlotId].OutputContext;
ZeroMem (InputContext, sizeof (INPUT_CONTEXT_64));
CopyMem (&InputContext->EP[0], &OutputContext->EP[0], sizeof (ENDPOINT_CONTEXT_64));
InputContext->InputControlContext.Dword2 |= BIT1;
InputContext->EP[0].MaxPacketSize = MaxPacketSize;
InputContext->EP[0].EPState = 0;
From: devel@edk2.groups.io <devel@edk2.groups.io>
On Behalf Of Wu, Hao A
Sent: Tuesday, September 20, 2022 11:04 AM
To: Jiading Zhang <jdzhang@kunluntech.com.cn>; devel@edk2.groups.io
Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/Bus/Pci/XhciDxe: Fix the Bug of clean InputContext in XhcEvaluateContext64();
Thanks for the information.
Yes, I think the “EPType” field should be initialized properly for the Evaluate Context command to work.
The spec mentions in 6.2.3 Endpoint Context that:
* Note: Unless otherwise stated: As Input, all fields of the Endpoint Context shall be initialized to the appropriate value by software before issuing a command.
* Endpoint Type (EP Type). This field identifies whether an Endpoint Context is Valid
Could you help to update XhcEvaluateContext64 to (please help to update XhcEvaluateContext accordingly as well) and check below changes work on your environment?
INPUT_CONTEXT_64 *InputContext;
DEVICE_CONTEXT_64 *OutputContext;
EFI_PHYSICAL_ADDRESS PhyAddr;
ASSERT (Xhc->UsbDevContext[SlotId].SlotId != 0);
//
// 4.6.7 Evaluate Context
//
InputContext = Xhc->UsbDevContext[SlotId].InputContext;
OutputContext = Xhc->UsbDevContext[SlotId].OutputContext;
ZeroMem (InputContext, sizeof (INPUT_CONTEXT_64));
CopyMem (&InputContext->EP[0], &OutputContext->EP[0], sizeof (ENDPOINT_CONTEXT_64));
My take is that doing so will initialize the input context of EP0 for the Evaluate Context command with previous output context of the Address Device command.
Best Regards,
Hao Wu
From: Jiading Zhang <jdzhang@kunluntech.com.cn>
Sent: Tuesday, September 20, 2022 8:46 AM
To: Wu; Wu, Hao A <hao.a.wu@intel.com>;
devel@edk2.groups.io
Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/Bus/Pci/XhciDxe: Fix the Bug of clean InputContext in XhcEvaluateContext64();
Hello,
I test for several times and find that if add the following line, the KB and MassStorage will work,
InputContext->EP[0].EPType = ED_CONTROL_BIDIR;
I don't know if the issue is brought in by the different of xHCI controllers or else.