[edk2-devel] [PATCH v4 2/3] UsbNetworkPkg/UsbCdcEcm: Add USB Cdc ECM devices support

Tinh Nguyen via groups.io tinhnguyen=os.amperecomputing.com at groups.io
Mon Mar 6 08:13:30 UTC 2023


Hi Richard,

Please check my inline comment

Could you apply this to the NCM driver? It looks like they share the 
same logic.

Thanks,

Tinh


On 18/02/2023 16:47, RichardHo [何明忠] via groups.io wrote:
> +
> +/**
> +  Check if the USB CDC Data(UsbIo) installed and return USB CDC Data Handle.
> +
> +  @param[in]      UsbEthPath          A pointer to the EFI_DEVICE_PATH_PROTOCOL instance.
> +  @param[in, out] UsbCdcDataHandle    A pointer to the EFI_HANDLE for USB CDC Data.
> +
> +  @retval TRUE                USB CDC Data(UsbIo) installed.
> +  @retval FALSE               USB CDC Data(UsbIo) did not installed.
> +
> +**/
> +BOOLEAN
> +IsUsbCdcData (
> +  IN      EFI_DEVICE_PATH_PROTOCOL  *UsbEthPath,
> +  IN OUT  EFI_HANDLE                *UsbCdcDataHandle
> +  )
> +{
> +  EFI_STATUS                    Status;
> +  UINTN                         Index;
> +  UINTN                         HandleCount;
> +  EFI_HANDLE                    *HandleBuffer;
> +  EFI_USB_IO_PROTOCOL           *UsbIo;
> +  EFI_USB_INTERFACE_DESCRIPTOR  Interface;
> +  EFI_DEVICE_PATH_PROTOCOL      *UsbCdcDataPath;
> +
> +  Status = gBS->LocateHandleBuffer (
> +                  ByProtocol,
> +                  &gEfiUsbIoProtocolGuid,
> +                  NULL,
> +                  &HandleCount,
> +                  &HandleBuffer
> +                  );
> +  if (EFI_ERROR (Status)) {
> +    return FALSE;
> +  }
> +
> +  for (Index = 0; Index < HandleCount; Index++) {
> +    Status = gBS->HandleProtocol (
> +                    HandleBuffer[Index],
> +                    &gEfiUsbIoProtocolGuid,
> +                    (VOID **)&UsbIo
> +                    );
> +    ASSERT_EFI_ERROR (Status);

should continue if we cant get protocol

if (EFI_ERROR (Status)) {

   ASSERT_EFI_ERROR (Status);

   continue;

}

> +
> +    Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface);
> +    ASSERT_EFI_ERROR (Status);
> +
> +    if ((Interface.InterfaceClass == USB_CDC_DATA_CLASS) &&
> +        (Interface.InterfaceSubClass == USB_CDC_DATA_SUBCLASS) &&
> +        (Interface.InterfaceProtocol == USB_NO_CLASS_PROTOCOL))
> +    {
> +      Status = gBS->HandleProtocol (
> +                      HandleBuffer[Index],
> +                      &gEfiDevicePathProtocolGuid,
> +                      (VOID **)&UsbCdcDataPath
> +                      );
> +      if (EFI_ERROR (Status)) {
> +        continue;
> +      }
> +
> +      Status = IsSameDevice (UsbEthPath, UsbCdcDataPath);
> +      if (!EFI_ERROR (Status)) {
> +        CopyMem (UsbCdcDataHandle, &HandleBuffer[Index], sizeof (EFI_HANDLE));
> +        FreePool (HandleBuffer);
> +        return TRUE;
> +      }
> +    }
> +  }
> +
> +  FreePool (HandleBuffer);
> +  return FALSE;
> +}
> +
> +/**
> +  Call Back Function.
> +
> +  @param[in]  Event       Event whose notification function is being invoked.
> +  @param[in]  Context     The pointer to the notification function's context,
> +                          which is implementation-dependent.
> +
> +**/
> +VOID
> +EFIAPI
> +CallbackFunction (
> +  IN EFI_EVENT  Event,
> +  IN VOID       *Context
> +  )
> +{
> +  EFI_STATUS                    Status;
> +  UINTN                         Index;
> +  UINTN                         HandleCount;
> +  EFI_HANDLE                    *HandleBuffer;
> +  EFI_USB_IO_PROTOCOL           *UsbIo;
> +  EFI_USB_INTERFACE_DESCRIPTOR  Interface;
> +
> +  Status = gBS->LocateHandleBuffer (
> +                  ByProtocol,
> +                  &gEfiUsbIoProtocolGuid,
> +                  NULL,
> +                  &HandleCount,
> +                  &HandleBuffer
> +                  );
> +  if (EFI_ERROR (Status)) {
> +    return;
> +  }
> +
> +  for (Index = 0; Index < HandleCount; Index++) {
> +    Status = gBS->HandleProtocol (
> +                    HandleBuffer[Index],
> +                    &gEfiUsbIoProtocolGuid,
> +                    (VOID **)&UsbIo
> +                    );
> +    ASSERT_EFI_ERROR (Status);
the same here, should continue if we cant get protocol
> +
> +    Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface);
> +    ASSERT_EFI_ERROR (Status);
> +
> +    if ((Interface.InterfaceClass == USB_CDC_CLASS) &&
> +        (Interface.InterfaceSubClass == USB_CDC_ECM_SUBCLASS) &&
> +        (Interface.InterfaceProtocol == USB_NO_CLASS_PROTOCOL))
> +    {
> +      gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
> +    }
> +  }
> +
>
> --
> 2.35.1.windows.2
> -The information contained in this message may be confidential and proprietary to American Megatrends (AMI). This communication is intended to be read only by the individual or entity to whom it is addressed or by their designee. If the reader of this message is not the intended recipient, you are on notice that any distribution of this message, in any form, is strictly prohibited. Please promptly notify the sender by reply e-mail or by telephone at 770-246-8600, and then delete or destroy all copies of the transmission.
>
>
> 
>
>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#100716): https://edk2.groups.io/g/devel/message/100716
Mute This Topic: https://groups.io/mt/97046154/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list