From nobody Sun May 5 17:15:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95973+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95973+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1667593728; cv=none; d=zohomail.com; s=zohoarc; b=NyEib9CEpGrtmrcPlptsFdKGVnVYB1GBEcSe9gMczTmJhqntX1BEZfPZwJ+KeU9AIJfF77UmMR/Sn8hI2U2oZFKNKk4uJ72L6dU8vt4vknB/6OqYJnHfqA0XR1B3D2jgZVe6InA+pbidGS02gYJkOhTSMkCK3lMrssJtmdMmdk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667593728; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=bOsjTjo0FGLOJ9+KUrIpSmD0EKzaCxe5Kt3Z/mwoeZU=; b=iE+cMcCrZsukq9l5m4oKS3d4y7O1D3trGJ8TIPD64VMOCBk5WpkWAyCdB32GCjJgZGrXGF8V9pT/wGgwIkfws2ijYTIUeSJimxqdk1E4jP2HdyXsWlqaEqOmGwW25/dapfGxg2nZcQkfYBxTWbjptTta+JyEqDwIJbcBnMYZyxg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95973+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1667593728662578.1175289780762; Fri, 4 Nov 2022 13:28:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Zz3EYY1788612xZmjMbzU7hv; Fri, 04 Nov 2022 13:28:48 -0700 X-Received: from outbound.soverin.net (outbound.soverin.net [185.233.34.18]) by mx.groups.io with SMTP id smtpd.web10.8850.1667550644525707717 for ; Fri, 04 Nov 2022 01:30:44 -0700 X-Received: from smtp.freedom.nl (c04smtp-lb01.int.sover.in [10.10.4.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by outbound.soverin.net (Postfix) with ESMTPS id 4N3Yjb0YWVz6t; Fri, 4 Nov 2022 08:30:43 +0000 (UTC) X-Received: from smtp.freedom.nl (smtp.freedom.nl [10.10.4.107]) by freedom.nl (Postfix) with ESMTPSA id 4N3YjY5FMJzLJ; Fri, 4 Nov 2022 08:30:41 +0000 (UTC) X-Soverin-Authenticated: true From: =?UTF-8?q?Frederik=20van=20H=C3=B6vell?= To: devel@edk2.groups.io Cc: Maciej Rabeda , Jiaxin Wu , Siyuan Fu , =?UTF-8?q?Frederik=20van=20H=C3=B6vell?= Subject: [edk2-devel] [Patch v1 1/2] [NetworkPkg/SnpDxe] More logging to see why SnpDxe fails to start Date: Fri, 4 Nov 2022 09:30:26 +0100 Message-Id: <20221104083027.115025-2-frederik@fvhovell.nl> In-Reply-To: <20221104083027.115025-1-frederik@fvhovell.nl> References: <20221104083027.115025-1-frederik@fvhovell.nl> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,frederik@fvhovell.nl X-Gm-Message-State: SSY89Gano19FX7hdggnsoDhJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1667593728; bh=1Gzh4LnHjyx/1ABtlO2xpOHYODfaEygwsnCLHJL4QQE=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=mFIxjrP5TR9qjQEwE5hlTe8PoiK4bHpx7lIoJtstP7Tynu7RNVvKxKZcTbjY4V2f/gI LTWLGrAWpQnMZdXqlP5wr3rGxW82t2FXBy5oNkH35fga9uiJj3aW2HQrmXyQJIPEo8q7V FEYwwCoQZKEowZHqXrt+vLDbo48hpyLnekk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1667593730644100004 Content-Type: text/plain; charset="utf-8" Add debug logging to see where SnpDxe is failing using a UsbIo UNDI driver. Signed-off-by: Frederik van H=C3=B6vell --- NetworkPkg/SnpDxe/Snp.h | 1 + NetworkPkg/SnpDxe/Snp.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/NetworkPkg/SnpDxe/Snp.h b/NetworkPkg/SnpDxe/Snp.h index d57804ca2873..dec238c9eb2c 100644 --- a/NetworkPkg/SnpDxe/Snp.h +++ b/NetworkPkg/SnpDxe/Snp.h @@ -27,6 +27,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include =20 #include #include diff --git a/NetworkPkg/SnpDxe/Snp.c b/NetworkPkg/SnpDxe/Snp.c index 95361c3cd343..86bf527f31dd 100644 --- a/NetworkPkg/SnpDxe/Snp.c +++ b/NetworkPkg/SnpDxe/Snp.c @@ -160,6 +160,7 @@ SimpleNetworkDriverSupported ( // check the version, we don't want to connect to the undi16 // if (NiiProtocol->Type !=3D EfiNetworkInterfaceUndi) { + DEBUG ((DEBUG_NET, "%a: Unsupported type %a for handle %p\n", __FUNCTI= ON__, NiiProtocol->Type, Controller)); Status =3D EFI_UNSUPPORTED; goto Done; } @@ -218,7 +219,7 @@ SimpleNetworkDriverSupported ( } =20 Status =3D EFI_SUCCESS; - DEBUG ((DEBUG_INFO, "Support(): supported on %p\n", Controller)); + DEBUG ((DEBUG_INFO, "%a: supported on %p\n", __FUNCTION__, Controller)); =20 Done: gBS->CloseProtocol ( @@ -283,6 +284,7 @@ SimpleNetworkDriverStart ( ); =20 if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to get DevicePath for driver %p and h= andle %p - status %r\n", __FUNCTION__, This->DriverBindingHandle, Controlle= r, Status)); return Status; } =20 @@ -293,6 +295,7 @@ SimpleNetworkDriverStart ( ); =20 if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to locate DevicePath using PCI path %= s - status %r\n", __FUNCTION__, ConvertDevicePathToText(NiiDevicePath, TRUE= , TRUE), Status)); return Status; } =20 @@ -305,6 +308,7 @@ SimpleNetworkDriverStart ( EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to open PciIo protocol for driver %p = and handle %p - status %r\n", __FUNCTION__, This->DriverBindingHandle, Hand= le, Status)); return Status; } =20 @@ -320,6 +324,7 @@ SimpleNetworkDriverStart ( EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to open NII protocol for driver %p an= d controller %p - status %r\n", __FUNCTION__, This->DriverBindingHandle, Co= ntroller, Status)); gBS->CloseProtocol ( Controller, &gEfiDevicePathProtocolGuid, --=20 2.35.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95973): https://edk2.groups.io/g/devel/message/95973 Mute This Topic: https://groups.io/mt/94814714/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 5 17:15:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95974+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95974+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1667593728; cv=none; d=zohomail.com; s=zohoarc; b=c78Vwj1tUQIp1tnM7jFxZ5D6EJqOlSFUM8X0K1CZv1PckYHY1HeixVFnpbTZOggfa9EUDeR4J2k1DNJHhfvJFMfDc31nykRNcr0IJkPw/KT3z8wMXkyCTiD8QbenldCfre+As2eeQOtyRUxcdhWA69Ig28f2qRm3CbbRAST/I78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667593728; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=YP/vi/Dpd9KDaHeIaZPHxSsWJJOqu/ldIddGWg90+Dc=; b=HdFgLufQl3Q9JuX4YS9obCPqsU+OnTRSw/nV95fn9NOxOLd4C8xOBrx45AzPYReuNzUGYVttEpGgSfaXoyZGTejIJIajaRmUYOTiRoBjmIOudtwZZb+kK+hNSVuQmLXEk7d6nIDnAUWbBzPCevTVAHZupPZwaSeFeYSKwwFATEE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95974+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1667593728730890.3352476940471; Fri, 4 Nov 2022 13:28:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ddzcYY1788612xTHRkh8H2KR; Fri, 04 Nov 2022 13:28:48 -0700 X-Received: from outbound.soverin.net (outbound.soverin.net [185.233.34.20]) by mx.groups.io with SMTP id smtpd.web09.8848.1667550646284701855 for ; Fri, 04 Nov 2022 01:30:47 -0700 X-Received: from smtp.freedom.nl (c04smtp-lb01.int.sover.in [10.10.4.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by outbound.soverin.net (Postfix) with ESMTPS id 4N3Yjc2K01z6n; Fri, 4 Nov 2022 08:30:44 +0000 (UTC) X-Received: from smtp.freedom.nl (smtp.freedom.nl [10.10.4.107]) by freedom.nl (Postfix) with ESMTPSA id 4N3Yjb0PWKzFl; Fri, 4 Nov 2022 08:30:43 +0000 (UTC) X-Soverin-Authenticated: true From: =?UTF-8?q?Frederik=20van=20H=C3=B6vell?= To: devel@edk2.groups.io Cc: Maciej Rabeda , Jiaxin Wu , Siyuan Fu , =?UTF-8?q?Frederik=20van=20H=C3=B6vell?= Subject: [edk2-devel] [Patch v1 2/2] [NetworkPkg/SnpDxe] Support SNP over UsbIo-based UNDI driver Date: Fri, 4 Nov 2022 09:30:27 +0100 Message-Id: <20221104083027.115025-3-frederik@fvhovell.nl> In-Reply-To: <20221104083027.115025-1-frederik@fvhovell.nl> References: <20221104083027.115025-1-frederik@fvhovell.nl> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,frederik@fvhovell.nl X-Gm-Message-State: uvr3WUN4909Y1eKcaLcs7BvZx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1667593728; bh=rnRTIRLkLpB9u/Bo4SUIRJJMlrhuBGv8JB3yQX/N3cU=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=vU5AOf54Y84xI4QFAinfDiiznT9jjUt8/vv6JCc7xoQO3eTuHWW9fLMStroUYX/Hu62 +Xjrwy/Ucea4z2uH5hOCsQ9s5NZi0ss31M/T9ANlYj8bidAHtnf2k6p8sP55Ufekwv4Nh yX41Bmt5BEHUvb6yyYN2urPhXVFlOCCw6rA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1667593730676100010 Content-Type: text/plain; charset="utf-8" Refactor SimpleNetworkDriverStart() and SimpleNetworkDriverStop() to add support over UsbIo UNDI driver next to PciIo UNDI driver. Signed-off-by: Frederik van H=C3=B6vell --- NetworkPkg/SnpDxe/SnpDxe.inf | 2 +- NetworkPkg/SnpDxe/Snp.h | 3 + NetworkPkg/SnpDxe/Snp.c | 225 ++++++++++++-------- 3 files changed, 146 insertions(+), 84 deletions(-) diff --git a/NetworkPkg/SnpDxe/SnpDxe.inf b/NetworkPkg/SnpDxe/SnpDxe.inf index d16f1888b30f..678e5efc5d01 100644 --- a/NetworkPkg/SnpDxe/SnpDxe.inf +++ b/NetworkPkg/SnpDxe/SnpDxe.inf @@ -54,7 +54,6 @@ [Packages] MdePkg/MdePkg.dec NetworkPkg/NetworkPkg.dec =20 - [LibraryClasses] UefiLib BaseLib @@ -72,6 +71,7 @@ [Protocols] gEfiDevicePathProtocolGuid ## TO_START gEfiNetworkInterfaceIdentifierProtocolGuid_31 ## TO_START gEfiPciIoProtocolGuid ## TO_START + gEfiUsbIoProtocolGuid ## TO_START =20 [Pcd] gEfiNetworkPkgTokenSpaceGuid.PcdSnpCreateExitBootServicesEvent ## CONS= UMES diff --git a/NetworkPkg/SnpDxe/Snp.h b/NetworkPkg/SnpDxe/Snp.h index dec238c9eb2c..cbc36c7b073d 100644 --- a/NetworkPkg/SnpDxe/Snp.h +++ b/NetworkPkg/SnpDxe/Snp.h @@ -13,6 +13,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include #include +#include +#include #include #include =20 @@ -94,6 +96,7 @@ typedef struct { VOID *FillHeaderBufferUnmap; =20 EFI_PCI_IO_PROTOCOL *PciIo; + EFI_USB_IO_PROTOCOL *UsbIo; UINT8 IoBarIndex; UINT8 MemoryBarIndex; =20 diff --git a/NetworkPkg/SnpDxe/Snp.c b/NetworkPkg/SnpDxe/Snp.c index 86bf527f31dd..6ecaa57feda3 100644 --- a/NetworkPkg/SnpDxe/Snp.c +++ b/NetworkPkg/SnpDxe/Snp.c @@ -268,6 +268,7 @@ SimpleNetworkDriverStart ( UINT8 BarIndex; PXE_STATFLAGS InitStatFlags; EFI_PCI_IO_PROTOCOL *PciIo; + EFI_USB_IO_PROTOCOL *UsbIo; EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *BarDesc; BOOLEAN FoundIoBar; BOOLEAN FoundMemoryBar; @@ -293,22 +294,44 @@ SimpleNetworkDriverStart ( &NiiDevicePath, &Handle ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: Failed to locate DevicePath using PCI path %= s - status %r\n", __FUNCTION__, ConvertDevicePathToText(NiiDevicePath, TRUE= , TRUE), Status)); - return Status; + DEBUG ((DEBUG_VERBOSE, "%a: Failed to locate DevicePath using PciIoPro= tocol path %s - status %r\n", __FUNCTION__, ConvertDevicePathToText(NiiDevi= cePath, TRUE, TRUE), Status)); + + Status =3D gBS->LocateDevicePath ( + &gEfiUsbIoProtocolGuid, + &NiiDevicePath, + &Handle + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_VERBOSE, "%a: Failed to locate DevicePath using UsbIoP= rotocol path %s - status %r\n", __FUNCTION__, ConvertDevicePathToText(NiiDe= vicePath, TRUE, TRUE), Status)); + + return Status; + } else { + // Found NiiDevicePath using UsbIoProtocol + Status =3D gBS->OpenProtocol ( + Handle, + &gEfiUsbIoProtocolGuid, + (VOID **) &UsbIo, + This->DriverBindingHandle, + Controller, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + } + } else { + // Found NiiDevicePath using PciIoProtocol + Status =3D gBS->OpenProtocol ( + Handle, + &gEfiPciIoProtocolGuid, + (VOID **) &PciIo, + This->DriverBindingHandle, + Controller, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); } =20 - Status =3D gBS->OpenProtocol ( - Handle, - &gEfiPciIoProtocolGuid, - (VOID **)&PciIo, - This->DriverBindingHandle, - Controller, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); + if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: Failed to open PciIo protocol for driver %p = and handle %p - status %r\n", __FUNCTION__, This->DriverBindingHandle, Hand= le, Status)); + DEBUG ((DEBUG_ERROR, "%a: Failed to open protocol for driver %p and ha= ndle %p - status %r\n", __FUNCTION__, This->DriverBindingHandle, Handle, St= atus)); return Status; } =20 @@ -323,7 +346,7 @@ SimpleNetworkDriverStart ( Controller, EFI_OPEN_PROTOCOL_BY_DRIVER ); - if (EFI_ERROR (Status)) { + if (EFI_ERROR (Status) || Nii =3D=3D NULL) { DEBUG ((DEBUG_ERROR, "%a: Failed to open NII protocol for driver %p an= d controller %p - status %r\n", __FUNCTION__, This->DriverBindingHandle, Co= ntroller, Status)); gBS->CloseProtocol ( Controller, @@ -334,7 +357,7 @@ SimpleNetworkDriverStart ( return Status; } =20 - DEBUG ((DEBUG_INFO, "Start(): UNDI3.1 found\n")); + DEBUG ((DEBUG_INFO, "%a: UNDI3.1 found\n", __FUNCTION__)); =20 Pxe =3D (PXE_UNDI *)(UINTN)(Nii->Id); =20 @@ -362,14 +385,22 @@ SimpleNetworkDriverStart ( // OK, we like this UNDI, and we know snp is not already there on this h= andle // Allocate and initialize a new simple network protocol structure. // - Status =3D PciIo->AllocateBuffer ( - PciIo, - AllocateAnyPages, - EfiBootServicesData, - SNP_MEM_PAGES (sizeof (SNP_DRIVER)), - &Address, - 0 - ); + if (PciIo !=3D NULL) { + Status =3D PciIo->AllocateBuffer( + PciIo, + AllocateAnyPages, + EfiBootServicesData, + SNP_MEM_PAGES (sizeof (SNP_DRIVER)), + &Address, + 0 + ); + } else if (UsbIo !=3D NULL) { + DEBUG ((DEBUG_INFO, "%a: AllocatePool for SNP structure with size: %d\= n", __FUNCTION__, sizeof (SNP_DRIVER) )); + Address =3D AllocatePool(sizeof (SNP_DRIVER)); + if (Address =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + } + } =20 if (Status !=3D EFI_SUCCESS) { DEBUG ((DEBUG_NET, "\nCould not allocate SNP_DRIVER structure.\n")); @@ -381,6 +412,7 @@ SimpleNetworkDriverStart ( ZeroMem (Snp, sizeof (SNP_DRIVER)); =20 Snp->PciIo =3D PciIo; + Snp->UsbIo =3D UsbIo; Snp->Signature =3D SNP_DRIVER_SIGNATURE; =20 EfiInitializeLock (&Snp->Lock, TPL_NOTIFY); @@ -450,14 +482,22 @@ SimpleNetworkDriverStart ( // -it is OK to allocate one global set of CPB, DB pair for each UNDI // interface as EFI does not multi-task and so SNP will not be re-entere= d! // - Status =3D PciIo->AllocateBuffer ( - PciIo, - AllocateAnyPages, - EfiBootServicesData, - SNP_MEM_PAGES (4096), - &Address, - 0 - ); + if (PciIo !=3D NULL) { + Status =3D PciIo->AllocateBuffer ( + PciIo, + AllocateAnyPages, + EfiBootServicesData, + SNP_MEM_PAGES (4096), + &Address, + 0 + ); + } else if (UsbIo !=3D NULL) { + DEBUG ((DEBUG_INFO, "%a: AllocatePool for CPB and DB buffers with size= : %d\n", __FUNCTION__, 6144)); + Address =3D AllocatePool (6144); + if (Address =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + } + } =20 if (Status !=3D EFI_SUCCESS) { DEBUG ((DEBUG_NET, "\nCould not allocate CPB and DB structures.\n")); @@ -467,42 +507,44 @@ SimpleNetworkDriverStart ( Snp->Cpb =3D (VOID *)(UINTN)Address; Snp->Db =3D (VOID *)((UINTN)Address + 2048); =20 - // - // Find the correct BAR to do IO. - // - // Enumerate through the PCI BARs for the device to determine which one = is - // the IO BAR. Save the index of the BAR into the adapter info structur= e. - // for regular 32bit BARs, 0 is memory mapped, 1 is io mapped - // - Snp->MemoryBarIndex =3D PCI_MAX_BAR; - Snp->IoBarIndex =3D PCI_MAX_BAR; - FoundMemoryBar =3D FALSE; - FoundIoBar =3D FALSE; - for (BarIndex =3D 0; BarIndex < PCI_MAX_BAR; BarIndex++) { - Status =3D PciIo->GetBarAttributes ( - PciIo, - BarIndex, - NULL, - (VOID **)&BarDesc - ); - if (Status =3D=3D EFI_UNSUPPORTED) { - continue; - } else if (EFI_ERROR (Status)) { - goto Error_DeleteSNP; - } + if (PciIo !=3D NULL) { + // + // Find the correct BAR to do IO. + // + // Enumerate through the PCI BARs for the device to determine which on= e is + // the IO BAR. Save the index of the BAR into the adapter info struct= ure. + // for regular 32bit BARs, 0 is memory mapped, 1 is io mapped + // + Snp->MemoryBarIndex =3D PCI_MAX_BAR; + Snp->IoBarIndex =3D PCI_MAX_BAR; + FoundMemoryBar =3D FALSE; + FoundIoBar =3D FALSE; + for (BarIndex =3D 0; BarIndex < PCI_MAX_BAR; BarIndex++) { + Status =3D PciIo->GetBarAttributes ( + PciIo, + BarIndex, + NULL, + (VOID **)&BarDesc + ); + if (Status =3D=3D EFI_UNSUPPORTED) { + continue; + } else if (EFI_ERROR (Status)) { + goto Error_DeleteSNP; + } =20 - if ((!FoundMemoryBar) && (BarDesc->ResType =3D=3D ACPI_ADDRESS_SPACE_T= YPE_MEM)) { - Snp->MemoryBarIndex =3D BarIndex; - FoundMemoryBar =3D TRUE; - } else if ((!FoundIoBar) && (BarDesc->ResType =3D=3D ACPI_ADDRESS_SPAC= E_TYPE_IO)) { - Snp->IoBarIndex =3D BarIndex; - FoundIoBar =3D TRUE; - } + if ((!FoundMemoryBar) && (BarDesc->ResType =3D=3D ACPI_ADDRESS_SPACE= _TYPE_MEM)) { + Snp->MemoryBarIndex =3D BarIndex; + FoundMemoryBar =3D TRUE; + } else if ((!FoundIoBar) && (BarDesc->ResType =3D=3D ACPI_ADDRESS_SP= ACE_TYPE_IO)) { + Snp->IoBarIndex =3D BarIndex; + FoundIoBar =3D TRUE; + } =20 - FreePool (BarDesc); + FreePool (BarDesc); =20 - if (FoundMemoryBar && FoundIoBar) { - break; + if (FoundMemoryBar && FoundIoBar) { + break; + } } } =20 @@ -682,11 +724,15 @@ SimpleNetworkDriverStart ( return Status; } =20 - PciIo->FreeBuffer ( - PciIo, - SNP_MEM_PAGES (4096), - Snp->Cpb - ); + if (PciIo !=3D NULL) { + PciIo->FreeBuffer ( + PciIo, + SNP_MEM_PAGES (4096), + Snp->Cpb + ); + } else if (UsbIo !=3D NULL) { + FreePool (Snp->Cpb); + } =20 Error_DeleteSNP: =20 @@ -694,11 +740,15 @@ Error_DeleteSNP: FreePool (Snp->RecycledTxBuf); } =20 - PciIo->FreeBuffer ( - PciIo, - SNP_MEM_PAGES (sizeof (SNP_DRIVER)), - Snp - ); + if (PciIo !=3D NULL) { + PciIo->FreeBuffer ( + PciIo, + SNP_MEM_PAGES (sizeof (SNP_DRIVER)), + Snp + ); + } else if (UsbIo !=3D NULL) { + FreePool (Snp); + } NiiError: gBS->CloseProtocol ( Controller, @@ -755,6 +805,7 @@ SimpleNetworkDriverStop ( EFI_SIMPLE_NETWORK_PROTOCOL *SnpProtocol; SNP_DRIVER *Snp; EFI_PCI_IO_PROTOCOL *PciIo; + EFI_USB_IO_PROTOCOL *UsbIo; =20 // // Get our context back. @@ -811,17 +862,25 @@ SimpleNetworkDriverStop ( FreePool (Snp->RecycledTxBuf); =20 PciIo =3D Snp->PciIo; - PciIo->FreeBuffer ( - PciIo, - SNP_MEM_PAGES (4096), - Snp->Cpb - ); + if (PciIo !=3D NULL) { + PciIo->FreeBuffer ( + PciIo, + SNP_MEM_PAGES (4096), + Snp->Cpb + ); =20 - PciIo->FreeBuffer ( - PciIo, - SNP_MEM_PAGES (sizeof (SNP_DRIVER)), - Snp - ); + PciIo->FreeBuffer ( + PciIo, + SNP_MEM_PAGES (sizeof (SNP_DRIVER)), + Snp + ); + } else { + UsbIo =3D Snp->UsbIo; + FreePool (Snp->Cpb); + + FreePool (Snp); + + } =20 return Status; } --=20 2.35.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95974): https://edk2.groups.io/g/devel/message/95974 Mute This Topic: https://groups.io/mt/94814715/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-