From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.91]) by mx.groups.io with SMTP id smtpd.web11.28609.1678090426667275962 for ; Mon, 06 Mar 2023 00:13:46 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="no key for verify" header.i=@amperemail.onmicrosoft.com header.s=selector1-amperemail-onmicrosoft-com header.b=WQLNMPU5; spf=pass (domain: os.amperecomputing.com, ip: 40.107.92.91, mailfrom: tinhnguyen@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f6HiTNAEcp7uWdT+ahy+313HYQcAGXVXlO3bCfGiSsKsd+uiQNOZQcBPQuS1Di9xcSTkpoDIgvZ6SfaUBB0d9MjdlR4s3rVnq08MHASL/MrRy9TjIqhmOoHEfM7wuox0lEbOXYYjPybmiY21/fd6FbISH0IsldX+Y4GHcLP2KSfTGf2puexRb9PgZBc0Jj/y44beJOJSEO5AoeZjlp3n72VrHgSZMjatqhnK8ZsWthdpJocZQJvU6aZNdEjLz0jVxrEbaVD4VGuhvD1h0v+5o8oqen3wAjy1FK2ANOcD3GARq7WuI/SwwVXJ9afmFD5Ok1oV4y8tPHL0N8aMSlkuMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=okwFWLPxUU4vc/tbWhdX21wu0cWs86ThGW22+a56JHE=; b=nUXR2AdujjvTDHoVQNsn1tGz5l+wjEPll84ChfsJKR0lkuG8Es+LLSKCKA3kHKty003lIfAk4B9nozFCVNvsz30aqeh/n1q/s6IWiW9oC0QcUsSOH29ShXV+l5W5rZwJniODRSkbPd8Gn06KD442GkZmki8mX+h3eeJsaDNIo6vD/0UD2oRuXGVT8UB6CLptu6ZGLc/SI2bKwOFhGXG4CfcAWQeRZMKKDQ1bn7XTxrbT6o6gL3AOD4u8kmRR8S33++H7TVLVC6MczDCT3m5hftb4SAF7WyEtb6NXKbpvfzQ6I+UxDeK1UREg/zjvzUG8MN/wGNi/P0kLs6HmStTAJg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=amperemail.onmicrosoft.com; dkim=pass header.d=amperemail.onmicrosoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amperemail.onmicrosoft.com; s=selector1-amperemail-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=okwFWLPxUU4vc/tbWhdX21wu0cWs86ThGW22+a56JHE=; b=WQLNMPU5QNxHJDkXOUBfceLGlnCzcL2mYz2PamTDEz/yLNnWQEiE5BdHiRj5kMhY19V6n/0puPMLXGpGt31lCNMlUWn27odsoiO7ZSd7G6T6YgvoKcQrxeT6MsCLBxZjCEkUgws6gt9Od1GZW5s9eJXCFisy6BNk2N4/b9asrws= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amperemail.onmicrosoft.com; Received: from PH0PR01MB7506.prod.exchangelabs.com (2603:10b6:510:f5::22) by MN0PR01MB7634.prod.exchangelabs.com (2603:10b6:208:376::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.13; Mon, 6 Mar 2023 08:13:40 +0000 Received: from PH0PR01MB7506.prod.exchangelabs.com ([fe80::c431:46ee:f0b7:3818]) by PH0PR01MB7506.prod.exchangelabs.com ([fe80::c431:46ee:f0b7:3818%7]) with mapi id 15.20.6178.015; Mon, 6 Mar 2023 08:13:40 +0000 Message-ID: <04ad6c64-e767-3779-6734-f5175f2e6381@amperemail.onmicrosoft.com> Date: Mon, 6 Mar 2023 15:13:30 +0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [edk2-devel] [PATCH v4 2/3] UsbNetworkPkg/UsbCdcEcm: Add USB Cdc ECM devices support To: devel@edk2.groups.io, richardho@ami.com References: <20230218094743.358-1-richardho@ami.com> <20230218094743.358-2-richardho@ami.com> From: "Tinh Nguyen" In-Reply-To: <20230218094743.358-2-richardho@ami.com> X-ClientProxiedBy: SG2PR04CA0213.apcprd04.prod.outlook.com (2603:1096:4:187::11) To PH0PR01MB7506.prod.exchangelabs.com (2603:10b6:510:f5::22) Return-Path: tinhnguyen@os.amperecomputing.com MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR01MB7506:EE_|MN0PR01MB7634:EE_ X-MS-Office365-Filtering-Correlation-Id: 9981a336-c001-431e-1d1c-08db1e1ab1cd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Dyh8prnarrieB0riSCO/JUoPJ881Bdb6p+7OeJ7FofRJEpOfElQilmdlETRsb4kqH4biHTh/f9D5gWIhpZ0ziMkbL/0laogKNddHbr/pv3k+lJb9N8RgNM8vWLIsXE4dejuN3ps3QHuelbsZH6Xi4YbW19/TygN6+QCwRB0f4HCb41U1BP6zUFIuub9xKBRci4ZZVlbjAAL5IQXC7CTBSrPm/CSMCExAg2zdW/F6rpwmXVxMMrNBEZibJHfmkQBJ3sUnMLqHNmZdW1gdFqGtQEDafFc+t2UEYPzEcBK1CMZmdSyxwfMc1tv/FOCTb3+Cso0z0YKnJ9yXKKYgz2NNSmzD12cc6qLS3a3gQqjN/Zc0ROODeu6EuCGsaUKfdQ9iyk2ggCQBxdF7NKUQul4uSYGNjMWuPtBR7TkRGzthgipHI3LW9+YeMbltVmoXPn9+wCS9gt54LqYO2mRt2RVJkDulVVYhRK5DWyGsDqU5f1XgajeFGUK182BdyN8EGucBaKFNtCrdwDwSK8x6j9oQOvw5SnRwCRi3j/aPo/K9HMKcl3SUlN+jhFXhz+R0o4jzEx4QBlrFWsajE7zvrqhrYuOvEYUx29RDu7UWRONL4hsnBUZ6ICA4BqL+/WPDWjQ68YKn3El4kd2mAvJQCMsTXrWg4CAYHjDavFTBoc5szBZk6GMYSkbnCe8iK3s6QwM8/fOW04RIw8f/3p8EnrcZ3z5Zc0AM+sRvLKBDYrsnA/Q= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR01MB7506.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(396003)(366004)(346002)(376002)(136003)(39850400004)(451199018)(31686004)(316002)(6486002)(966005)(42882007)(83380400001)(66899018)(40140700001)(31696002)(186003)(2906002)(5660300002)(8936002)(66556008)(66946007)(8676002)(41300700001)(66476007)(478600001)(6512007)(26005)(53546011)(2616005)(6506007)(52116002)(6666004)(83170400001)(38350700002)(38100700002)(43740500002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?wPGVrKpSbLGEVOM+Vm2gqFC7pES2HpuvNqy8/weOvpLg1xupMDbWRHRODFed?= =?us-ascii?Q?ckHBZ+bMGXjSzJRjmzv/L5T/eiZeG8Rp/lnHD7aS6qD5qYDyWjDRyhPm4pFh?= =?us-ascii?Q?Yvip7NMaxzeLkpbpe7LXvxISmuixqvRzvt95YOVFHlHscPdnDc3j71ROOEua?= =?us-ascii?Q?DeXnYWpF9LKhE0QsNIYkROLcshBK63+0Yq1XTzx3m0ERVLgWquqRopOzPTCD?= =?us-ascii?Q?z50Teawt7SnVzfo2804Hyf9/Kxo7w9eXlQZxOMocWj1DmGI8j0zU/tbAuGo7?= =?us-ascii?Q?rhTJvv5mnByU78ci1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nofo1825XcFPstaUQrCfEKCDAc0dTyh851KfnYUssP1bIzeeYHCm1ZDhaSue?= =?us-ascii?Q?4m5hx02LcXtJZYD6GxQxkB+JCvRJi1pyBIahdYwKU/Jocb+dWNh3RaMOTOd6?= =?us-ascii?Q?DLb29BBEc9L5wIZrUpmpoyvIQfr87W/mExXCo7mARBdGemBLA24g5HRDYKet?= =?us-ascii?Q?VHHj/cDVmPJn0yNTM/OBSTBvN1oSGfSIEHwV0nlA7g6M0RpAkxi2WjY9+7dC?= =?us-ascii?Q?s1qexv63bavb/nJq6B8OEygRfcEeKV2Ty/oX4h9UDUSqOIpfSpIVgzlOMWdC?= =?us-ascii?Q?y4+oCGNOroq9BEX+EismmGFsb6KXPww9LsIi5I/4dwF2J7O2Jp1RTLI8o82G?= =?us-ascii?Q?YPnO8wT9sG+FMoqQIK+Nkqafc4op8PCSHLIjoVOAEw9NABGHprAbpv+akJmi?= =?us-ascii?Q?jYJPBAxFslr4PVOBoMhb6hILr2NiMvQMGKoXnZSmfIxf?= X-OriginatorOrg: amperemail.onmicrosoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9981a336-c001-431e-1d1c-08db1e1ab1cd X-MS-Exchange-CrossTenant-AuthSource: PH0PR01MB7506.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2023 08:13:40.6861 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: KfkCXfzGUuJ87x3W1PKVLXnPudNTi2XJWypTFuWLL9tnBD6lL+86pVxeHj/s1hjjnwciLdAvPp4ezd7PYTluJS9N9jdVLLYjzStL24dv5smuZuvoKy5RmWcxbsYWLBrw X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR01MB7634 Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Hi Richard, Please check my inline comment Could you apply this to the NCM driver? It looks like they share the=20 same logic. Thanks, Tinh On 18/02/2023 16:47, RichardHo [=E4=BD=95=E6=98=8E=E5=BF=A0] via groups.io = wrote: > + > +/** > + Check if the USB CDC Data(UsbIo) installed and return USB CDC Data Han= dle. > + > + @param[in] UsbEthPath A pointer to the EFI_DEVICE_PATH_P= ROTOCOL instance. > + @param[in, out] UsbCdcDataHandle A pointer to the EFI_HANDLE for US= B 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 =3D gBS->LocateHandleBuffer ( > + ByProtocol, > + &gEfiUsbIoProtocolGuid, > + NULL, > + &HandleCount, > + &HandleBuffer > + ); > + if (EFI_ERROR (Status)) { > + return FALSE; > + } > + > + for (Index =3D 0; Index < HandleCount; Index++) { > + Status =3D gBS->HandleProtocol ( > + HandleBuffer[Index], > + &gEfiUsbIoProtocolGuid, > + (VOID **)&UsbIo > + ); > + ASSERT_EFI_ERROR (Status); should continue if we cant get protocol if (EFI_ERROR (Status)) { =C2=A0 ASSERT_EFI_ERROR (Status); =C2=A0 continue; } > + > + Status =3D UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface); > + ASSERT_EFI_ERROR (Status); > + > + if ((Interface.InterfaceClass =3D=3D USB_CDC_DATA_CLASS) && > + (Interface.InterfaceSubClass =3D=3D USB_CDC_DATA_SUBCLASS) && > + (Interface.InterfaceProtocol =3D=3D USB_NO_CLASS_PROTOCOL)) > + { > + Status =3D gBS->HandleProtocol ( > + HandleBuffer[Index], > + &gEfiDevicePathProtocolGuid, > + (VOID **)&UsbCdcDataPath > + ); > + if (EFI_ERROR (Status)) { > + continue; > + } > + > + Status =3D IsSameDevice (UsbEthPath, UsbCdcDataPath); > + if (!EFI_ERROR (Status)) { > + CopyMem (UsbCdcDataHandle, &HandleBuffer[Index], sizeof (EFI_HAN= DLE)); > + FreePool (HandleBuffer); > + return TRUE; > + } > + } > + } > + > + FreePool (HandleBuffer); > + return FALSE; > +} > + > +/** > + Call Back Function. > + > + @param[in] Event Event whose notification function is being inv= oked. > + @param[in] Context The pointer to the notification function's con= text, > + 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 =3D gBS->LocateHandleBuffer ( > + ByProtocol, > + &gEfiUsbIoProtocolGuid, > + NULL, > + &HandleCount, > + &HandleBuffer > + ); > + if (EFI_ERROR (Status)) { > + return; > + } > + > + for (Index =3D 0; Index < HandleCount; Index++) { > + Status =3D gBS->HandleProtocol ( > + HandleBuffer[Index], > + &gEfiUsbIoProtocolGuid, > + (VOID **)&UsbIo > + ); > + ASSERT_EFI_ERROR (Status); the same here, should continue if we cant get protocol > + > + Status =3D UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface); > + ASSERT_EFI_ERROR (Status); > + > + if ((Interface.InterfaceClass =3D=3D USB_CDC_CLASS) && > + (Interface.InterfaceSubClass =3D=3D USB_CDC_ECM_SUBCLASS) && > + (Interface.InterfaceProtocol =3D=3D 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 propri= etary to American Megatrends (AMI). This communication is intended to be re= ad only by the individual or entity to whom it is addressed or by their des= ignee. 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 telepho= ne at 770-246-8600, and then delete or destroy all copies of the transmissi= on. > > >=20 > >