--- /dev/null
+/** @file\r
+Copyright (c) 2004 - 2005, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module name:\r
+ snp.c\r
+\r
+Abstract:\r
+\r
+\r
+**/\r
+\r
+#include "Snp.h"\r
+\r
+EFI_STATUS\r
+pxe_start (\r
+ SNP_DRIVER *snp\r
+ );\r
+EFI_STATUS\r
+pxe_stop (\r
+ SNP_DRIVER *snp\r
+ );\r
+EFI_STATUS\r
+pxe_init (\r
+ SNP_DRIVER *snp,\r
+ UINT16 OpFlags\r
+ );\r
+EFI_STATUS\r
+pxe_shutdown (\r
+ SNP_DRIVER *snp\r
+ );\r
+EFI_STATUS\r
+pxe_get_stn_addr (\r
+ SNP_DRIVER *snp\r
+ );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeSnpNiiDriver (\r
+ IN EFI_HANDLE image_handle,\r
+ IN EFI_SYSTEM_TABLE *system_table\r
+ );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SimpleNetworkDriverSupported (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE Controller,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
+ );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SimpleNetworkDriverStart (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE Controller,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
+ );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SimpleNetworkDriverStop (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE Controller,\r
+ IN UINTN NumberOfChildren,\r
+ IN EFI_HANDLE *ChildHandleBuffer\r
+ );\r
+\r
+//\r
+// Simple Network Protocol Driver Global Variables\r
+//\r
+EFI_DRIVER_BINDING_PROTOCOL mSimpleNetworkDriverBinding = {\r
+ SimpleNetworkDriverSupported,\r
+ SimpleNetworkDriverStart,\r
+ SimpleNetworkDriverStop,\r
+ 0xa,\r
+ NULL,\r
+ NULL\r
+};\r
+\r
+//\r
+// Module global variables needed to support undi 3.0 interface\r
+//\r
+EFI_PCI_IO_PROTOCOL *mPciIoFncs;\r
+struct s_v2p *_v2p = NULL; // undi3.0 map_list head\r
+// End Global variables\r
+//\r
+\r
+/**\r
+ This routine maps the given CPU address to a Device address. It creates a\r
+ an entry in the map list with the virtual and physical addresses and the\r
+ un map cookie.\r
+\r
+ @param v2p pointer to return a map list node pointer.\r
+ @param type the direction in which the data flows from the given\r
+ virtual address device->cpu or cpu->device or both\r
+ ways.\r
+ @param vaddr virtual address (or CPU address) to be mapped\r
+ @param bsize size of the buffer to be mapped.\r
+\r
+ @retval EFI_SUCEESS routine has completed the mapping\r
+ @retval other error as indicated.\r
+\r
+**/\r
+EFI_STATUS\r
+add_v2p (\r
+ IN OUT struct s_v2p **v2p,\r
+ EFI_PCI_IO_PROTOCOL_OPERATION type,\r
+ VOID *vaddr,\r
+ UINTN bsize\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ if ((v2p == NULL) || (vaddr == NULL) || (bsize == 0)) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ *v2p = AllocatePool (sizeof (struct s_v2p));\r
+ if (*v2p != NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ Status = mPciIoFncs->Map (\r
+ mPciIoFncs,\r
+ type,\r
+ vaddr,\r
+ &bsize,\r
+ &(*v2p)->paddr,\r
+ &(*v2p)->unmap\r
+ );\r
+ if (Status != EFI_SUCCESS) {\r
+ FreePool (*v2p);\r
+ return Status;\r
+ }\r
+ (*v2p)->vaddr = vaddr;\r
+ (*v2p)->bsize = bsize;\r
+ (*v2p)->next = _v2p;\r
+ _v2p = *v2p;\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+ This routine searches the linked list of mapped address nodes (for undi3.0\r
+ interface) to find the node that corresponds to the given virtual address and\r
+ returns a pointer to that node.\r
+\r
+ @param v2p pointer to return a map list node pointer.\r
+ @param vaddr virtual address (or CPU address) to be searched in\r
+ the map list\r
+\r
+ @retval EFI_SUCEESS if a match found!\r
+ @retval Other match not found\r
+\r
+**/\r
+EFI_STATUS\r
+find_v2p (\r
+ struct s_v2p **v2p,\r
+ VOID *vaddr\r
+ )\r
+{\r
+ struct s_v2p *v;\r
+\r
+ if (v2p == NULL || vaddr == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ for (v = _v2p; v != NULL; v = v->next) {\r
+ if (v->vaddr == vaddr) {\r
+ *v2p = v;\r
+ return EFI_SUCCESS;\r
+ }\r
+ }\r
+\r
+ return EFI_NOT_FOUND;\r
+}\r
+\r
+\r
+/**\r
+ This routine unmaps the given virtual address and frees the memory allocated\r
+ for the map list node corresponding to that address.\r
+\r
+ @param vaddr virtual address (or CPU address) to be unmapped\r
+\r
+ @retval EFI_SUCEESS if successfully unmapped\r
+ @retval Other as indicated by the error\r
+\r
+**/\r
+EFI_STATUS\r
+del_v2p (\r
+ VOID *vaddr\r
+ )\r
+{\r
+ struct s_v2p *v;\r
+ struct s_v2p *t;\r
+ EFI_STATUS Status;\r
+\r
+ if (vaddr == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ if (_v2p == NULL) {\r
+ return EFI_NOT_FOUND;\r
+ }\r
+ //\r
+ // Is our node at the head of the list??\r
+ //\r
+ if ((v = _v2p)->vaddr == vaddr) {\r
+ _v2p = _v2p->next;\r
+\r
+ Status = mPciIoFncs->Unmap (mPciIoFncs, v->unmap);\r
+\r
+ FreePool (v);\r
+\r
+ if (Status) {\r
+ DEBUG ((EFI_D_ERROR, "Unmap failed with status = %x\n", Status));\r
+ }\r
+ return Status;\r
+ }\r
+\r
+ for (; v->next != NULL; v = t) {\r
+ if ((t = v->next)->vaddr == vaddr) {\r
+ v->next = t->next;\r
+ Status = mPciIoFncs->Unmap (mPciIoFncs, t->unmap);\r
+ FreePool (t);\r
+\r
+ if (Status) {\r
+ DEBUG ((EFI_D_ERROR, "Unmap failed with status = %x\n", Status));\r
+ }\r
+ return Status;\r
+ }\r
+ }\r
+\r
+ return EFI_NOT_FOUND;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+issue_hwundi_command (\r
+ UINT64 cdb\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+ DEBUG ((EFI_D_ERROR, "\nissue_hwundi_command() - This should not be called!"));\r
+\r
+ if (cdb == 0) {\r
+ return EFI_INVALID_PARAMETER;\r
+\r
+ }\r
+ //\r
+ // %%TBD - For now, nothing is done.\r
+ //\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+ Compute 8-bit checksum of a buffer.\r
+\r
+ @param ptr Pointer to buffer.\r
+ @param len Length of buffer in bytes.\r
+\r
+ @return 8-bit checksum of all bytes in buffer.\r
+ @return If ptr is NULL or len is zero, zero is returned.\r
+\r
+**/\r
+STATIC\r
+UINT8\r
+calc_8bit_cksum (\r
+ VOID *ptr,\r
+ UINTN len\r
+ )\r
+{\r
+ UINT8 *bptr;\r
+ UINT8 cksum;\r
+\r
+ bptr = ptr;\r
+ cksum = 0;\r
+\r
+ if (ptr == NULL || len == 0) {\r
+ return 0;\r
+ }\r
+\r
+ while (len--) {\r
+ cksum = (UINT8) (cksum +*bptr++);\r
+ }\r
+\r
+ return cksum;\r
+}\r
+\r
+\r
+/**\r
+ Test to see if this driver supports Controller. Any Controller\r
+ that contains a Nii protocol can be supported.\r
+\r
+ @param This Protocol instance pointer.\r
+ @param Controller Handle of device to test.\r
+ @param RemainingDevicePath Not used.\r
+\r
+ @retval EFI_SUCCESS This driver supports this device.\r
+ @retval EFI_ALREADY_STARTED This driver is already running on this device.\r
+ @retval other This driver does not support this device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SimpleNetworkDriverSupported (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE Controller,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *NiiProtocol;\r
+ PXE_UNDI *pxe;\r
+\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiDevicePathProtocolGuid,\r
+ NULL,\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiNetworkInterfaceIdentifierProtocolGuid_31,\r
+ (VOID **) &NiiProtocol,\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ if (Status == EFI_ALREADY_STARTED) {\r
+ DEBUG ((EFI_D_INFO, "Support(): Already Started. on handle %x\n", Controller));\r
+ }\r
+ return Status;\r
+ }\r
+\r
+ DEBUG ((EFI_D_INFO, "Support(): UNDI3.1 found on handle %x\n", Controller));\r
+\r
+ //\r
+ // check the version, we don't want to connect to the undi16\r
+ //\r
+ if (NiiProtocol->Type != EfiNetworkInterfaceUndi) {\r
+ Status = EFI_UNSUPPORTED;\r
+ goto Done;\r
+ }\r
+ //\r
+ // Check to see if !PXE structure is valid. Paragraph alignment of !PXE structure is required.\r
+ //\r
+ if (NiiProtocol->ID & 0x0F) {\r
+ DEBUG ((EFI_D_NET, "\n!PXE structure is not paragraph aligned.\n"));\r
+ Status = EFI_UNSUPPORTED;\r
+ goto Done;\r
+ }\r
+\r
+ pxe = (PXE_UNDI *) (UINTN) (NiiProtocol->ID);\r
+\r
+ //\r
+ // Verify !PXE revisions.\r
+ //\r
+ if (pxe->hw.Signature != PXE_ROMID_SIGNATURE) {\r
+ DEBUG ((EFI_D_NET, "\n!PXE signature is not valid.\n"));\r
+ Status = EFI_UNSUPPORTED;\r
+ goto Done;\r
+ }\r
+\r
+ if (pxe->hw.Rev < PXE_ROMID_REV) {\r
+ DEBUG ((EFI_D_NET, "\n!PXE.Rev is not supported.\n"));\r
+ Status = EFI_UNSUPPORTED;\r
+ goto Done;\r
+ }\r
+\r
+ if (pxe->hw.MajorVer < PXE_ROMID_MAJORVER) {\r
+\r
+ DEBUG ((EFI_D_NET, "\n!PXE.MajorVer is not supported.\n"));\r
+ Status = EFI_UNSUPPORTED;\r
+ goto Done;\r
+\r
+ } else if (pxe->hw.MajorVer == PXE_ROMID_MAJORVER && pxe->hw.MinorVer < PXE_ROMID_MINORVER) {\r
+ DEBUG ((EFI_D_NET, "\n!PXE.MinorVer is not supported."));\r
+ Status = EFI_UNSUPPORTED;\r
+ goto Done;\r
+ }\r
+ //\r
+ // Do S/W UNDI specific checks.\r
+ //\r
+ if ((pxe->hw.Implementation & PXE_ROMID_IMP_HW_UNDI) == 0) {\r
+ if (pxe->sw.EntryPoint < pxe->sw.Len) {\r
+ DEBUG ((EFI_D_NET, "\n!PXE S/W entry point is not valid."));\r
+ Status = EFI_UNSUPPORTED;\r
+ goto Done;\r
+ }\r
+\r
+ if (pxe->sw.BusCnt == 0) {\r
+ DEBUG ((EFI_D_NET, "\n!PXE.BusCnt is zero."));\r
+ Status = EFI_UNSUPPORTED;\r
+ goto Done;\r
+ }\r
+ }\r
+\r
+ Status = EFI_SUCCESS;\r
+ DEBUG ((EFI_D_INFO, "Support(): supported on %x\n", Controller));\r
+\r
+Done:\r
+ gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiNetworkInterfaceIdentifierProtocolGuid_31,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+\r
+ return Status;\r
+}\r
+\r
+\r
+/**\r
+ called for any handle that we said "supported" in the above call!\r
+\r
+ @param This Protocol instance pointer.\r
+ @param Controller Handle of device to start\r
+ @param RemainingDevicePath Not used.\r
+\r
+ @retval EFI_SUCCESS This driver supports this device.\r
+ @retval other This driver failed to start this device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SimpleNetworkDriverStart (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE Controller,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
+ )\r
+{\r
+ EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *Nii;\r
+ EFI_DEVICE_PATH_PROTOCOL *NiiDevicePath;\r
+ EFI_STATUS Status;\r
+ PXE_UNDI *pxe;\r
+ SNP_DRIVER *snp;\r
+ VOID *addr;\r
+ EFI_HANDLE Handle;\r
+ PXE_PCI_CONFIG_INFO ConfigInfo;\r
+ PCI_TYPE00 *ConfigHeader;\r
+ UINT32 *TempBar;\r
+ UINT8 BarIndex;\r
+ PXE_STATFLAGS InitStatFlags;\r
+\r
+ DEBUG ((EFI_D_NET, "\nSnpNotifyNetworkInterfaceIdentifier() "));\r
+\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiDevicePathProtocolGuid,\r
+ (VOID **) &NiiDevicePath,\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ Status = gBS->LocateDevicePath (\r
+ &gEfiPciIoProtocolGuid,\r
+ &NiiDevicePath,\r
+ &Handle\r
+ );\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ Status = gBS->OpenProtocol (\r
+ Handle,\r
+ &gEfiPciIoProtocolGuid,\r
+ (VOID **) &mPciIoFncs,\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ //\r
+ // Get the NII interface.\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiNetworkInterfaceIdentifierProtocolGuid_31,\r
+ (VOID **) &Nii,\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiDevicePathProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+ return Status;\r
+ }\r
+\r
+ DEBUG ((EFI_D_INFO, "Start(): UNDI3.1 found\n"));\r
+\r
+ pxe = (PXE_UNDI *) (UINTN) (Nii->ID);\r
+\r
+ if (calc_8bit_cksum (pxe, pxe->hw.Len) != 0) {\r
+ DEBUG ((EFI_D_NET, "\n!PXE checksum is not correct.\n"));\r
+ goto NiiError;\r
+ }\r
+\r
+ if ((pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED) != 0) {\r
+ //\r
+ // We can get any packets.\r
+ //\r
+ } else if ((pxe->hw.Implementation & PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED) != 0) {\r
+ //\r
+ // We need to be able to get broadcast packets for DHCP.\r
+ // If we do not have promiscuous support, we must at least have\r
+ // broadcast support or we cannot do DHCP!\r
+ //\r
+ } else {\r
+ DEBUG ((EFI_D_NET, "\nUNDI does not have promiscuous or broadcast support."));\r
+ goto NiiError;\r
+ }\r
+ //\r
+ // OK, we like this UNDI, and we know snp is not already there on this handle\r
+ // Allocate and initialize a new simple network protocol structure.\r
+ //\r
+ Status = mPciIoFncs->AllocateBuffer (\r
+ mPciIoFncs,\r
+ AllocateAnyPages,\r
+ EfiBootServicesData,\r
+ SNP_MEM_PAGES (sizeof (SNP_DRIVER)),\r
+ &addr,\r
+ 0\r
+ );\r
+\r
+ if (Status != EFI_SUCCESS) {\r
+ DEBUG ((EFI_D_NET, "\nCould not allocate SNP_DRIVER structure.\n"));\r
+ goto NiiError;\r
+ }\r
+\r
+ snp = (SNP_DRIVER *) (UINTN) addr;\r
+\r
+ ZeroMem (snp, sizeof (SNP_DRIVER));\r
+\r
+ snp->IoFncs = mPciIoFncs;\r
+ snp->Signature = SNP_DRIVER_SIGNATURE;\r
+\r
+ EfiInitializeLock (&snp->lock, TPL_NOTIFY);\r
+\r
+ snp->snp.Revision = EFI_SIMPLE_NETWORK_PROTOCOL_REVISION;\r
+ snp->snp.Start = snp_undi32_start;\r
+ snp->snp.Stop = snp_undi32_stop;\r
+ snp->snp.Initialize = snp_undi32_initialize;\r
+ snp->snp.Reset = snp_undi32_reset;\r
+ snp->snp.Shutdown = snp_undi32_shutdown;\r
+ snp->snp.ReceiveFilters = snp_undi32_receive_filters;\r
+ snp->snp.StationAddress = snp_undi32_station_address;\r
+ snp->snp.Statistics = snp_undi32_statistics;\r
+ snp->snp.MCastIpToMac = snp_undi32_mcast_ip_to_mac;\r
+ snp->snp.NvData = snp_undi32_nvdata;\r
+ snp->snp.GetStatus = snp_undi32_get_status;\r
+ snp->snp.Transmit = snp_undi32_transmit;\r
+ snp->snp.Receive = snp_undi32_receive;\r
+ snp->snp.WaitForPacket = NULL;\r
+\r
+ snp->snp.Mode = &snp->mode;\r
+\r
+ snp->tx_rx_bufsize = 0;\r
+ snp->tx_rx_buffer = NULL;\r
+\r
+ snp->if_num = Nii->IfNum;\r
+\r
+ if ((pxe->hw.Implementation & PXE_ROMID_IMP_HW_UNDI) != 0) {\r
+ snp->is_swundi = FALSE;\r
+ snp->issue_undi32_command = &issue_hwundi_command;\r
+ } else {\r
+ snp->is_swundi = TRUE;\r
+\r
+ if ((pxe->sw.Implementation & PXE_ROMID_IMP_SW_VIRT_ADDR) != 0) {\r
+ snp->issue_undi32_command = (issue_undi32_command) (UINTN) pxe->sw.EntryPoint;\r
+ } else {\r
+ snp->issue_undi32_command = (issue_undi32_command) (UINTN) ((UINT8) (UINTN) pxe + pxe->sw.EntryPoint);\r
+ }\r
+ }\r
+ //\r
+ // Allocate a global CPB and DB buffer for this UNDI interface.\r
+ // we do this because:\r
+ //\r
+ // -UNDI 3.0 wants all the addresses passed to it (even the cpb and db) to be\r
+ // within 2GB limit, create them here and map them so that when undi calls\r
+ // v2p callback to check if the physical address is < 2gb, we will pass.\r
+ //\r
+ // -This is not a requirement for 3.1 or later UNDIs but the code looks\r
+ // simpler if we use the same cpb, db variables for both old and new undi\r
+ // interfaces from all the SNP interface calls (we don't map the buffers\r
+ // for the newer undi interfaces though)\r
+ // .\r
+ // -it is OK to allocate one global set of CPB, DB pair for each UNDI\r
+ // interface as EFI does not multi-task and so SNP will not be re-entered!\r
+ //\r
+ Status = mPciIoFncs->AllocateBuffer (\r
+ mPciIoFncs,\r
+ AllocateAnyPages,\r
+ EfiBootServicesData,\r
+ SNP_MEM_PAGES (4096),\r
+ &addr,\r
+ 0\r
+ );\r
+\r
+ if (Status != EFI_SUCCESS) {\r
+ DEBUG ((EFI_D_NET, "\nCould not allocate CPB and DB structures.\n"));\r
+ goto Error_DeleteSNP;\r
+ }\r
+\r
+ snp->cpb = (VOID *) (UINTN) addr;\r
+ snp->db = (VOID *) ((UINTN) addr + 2048);\r
+\r
+ //\r
+ // pxe_start call is going to give the callback functions to UNDI, these callback\r
+ // functions use the BarIndex values from the snp structure, so these must be initialized\r
+ // with default values before doing a pxe_start. The correct values can be obtained after\r
+ // getting the config information from UNDI\r
+ //\r
+ snp->MemoryBarIndex = 0;\r
+ snp->IoBarIndex = 1;\r
+\r
+ //\r
+ // we need the undi init information many times in this snp code, just get it\r
+ // once here and store it in the snp driver structure. to get Init Info\r
+ // from UNDI we have to start undi first.\r
+ //\r
+ Status = pxe_start (snp);\r
+\r
+ if (Status != EFI_SUCCESS) {\r
+ goto Error_DeleteSNP;\r
+ }\r
+\r
+ snp->cdb.OpCode = PXE_OPCODE_GET_INIT_INFO;\r
+ snp->cdb.OpFlags = PXE_OPFLAGS_NOT_USED;\r
+\r
+ snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;\r
+ snp->cdb.CPBaddr = PXE_DBADDR_NOT_USED;\r
+\r
+ snp->cdb.DBsize = sizeof snp->init_info;\r
+ snp->cdb.DBaddr = (UINT64)(UINTN) &snp->init_info;\r
+\r
+ snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
+ snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
+\r
+ snp->cdb.IFnum = snp->if_num;\r
+ snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
+\r
+ DEBUG ((EFI_D_NET, "\nsnp->undi.get_init_info() "));\r
+\r
+ (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);\r
+\r
+ //\r
+ // Save the INIT Stat Code...\r
+ //\r
+ InitStatFlags = snp->cdb.StatFlags;\r
+\r
+ if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) {\r
+ DEBUG ((EFI_D_NET, "\nsnp->undi.init_info() %xh:%xh\n", snp->cdb.StatFlags, snp->cdb.StatCode));\r
+ pxe_stop (snp);\r
+ goto Error_DeleteSNP;\r
+ }\r
+\r
+ snp->cdb.OpCode = PXE_OPCODE_GET_CONFIG_INFO;\r
+ snp->cdb.OpFlags = PXE_OPFLAGS_NOT_USED;\r
+\r
+ snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;\r
+ snp->cdb.CPBaddr = PXE_DBADDR_NOT_USED;\r
+\r
+ snp->cdb.DBsize = sizeof ConfigInfo;\r
+ snp->cdb.DBaddr = (UINT64)(UINTN) &ConfigInfo;\r
+\r
+ snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
+ snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
+\r
+ snp->cdb.IFnum = snp->if_num;\r
+ snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
+\r
+ DEBUG ((EFI_D_NET, "\nsnp->undi.get_config_info() "));\r
+\r
+ (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);\r
+\r
+ if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) {\r
+ DEBUG ((EFI_D_NET, "\nsnp->undi.config_info() %xh:%xh\n", snp->cdb.StatFlags, snp->cdb.StatCode));\r
+ pxe_stop (snp);\r
+ goto Error_DeleteSNP;\r
+ }\r
+ //\r
+ // Find the correct BAR to do IO.\r
+ //\r
+ //\r
+ // Enumerate through the PCI BARs for the device to determine which one is\r
+ // the IO BAR. Save the index of the BAR into the adapter info structure.\r
+ // for regular 32bit BARs, 0 is memory mapped, 1 is io mapped\r
+ //\r
+ ConfigHeader = (PCI_TYPE00 *) &ConfigInfo.Config.Byte[0];\r
+ TempBar = (UINT32 *) &ConfigHeader->Device.Bar[0];\r
+ for (BarIndex = 0; BarIndex <= 5; BarIndex++) {\r
+ if ((*TempBar & PCI_BAR_MEM_MASK) == PCI_BAR_MEM_64BIT) {\r
+ //\r
+ // This is a 64-bit memory bar, skip this and the\r
+ // next bar as well.\r
+ //\r
+ TempBar++;\r
+ }\r
+\r
+ if ((*TempBar & PCI_BAR_IO_MASK) == PCI_BAR_IO_MODE) {\r
+ snp->IoBarIndex = BarIndex;\r
+ break;\r
+ }\r
+\r
+ TempBar++;\r
+ }\r
+\r
+ //\r
+ // Initialize simple network protocol mode structure\r
+ //\r
+ snp->mode.State = EfiSimpleNetworkStopped;\r
+ snp->mode.HwAddressSize = snp->init_info.HWaddrLen;\r
+ snp->mode.MediaHeaderSize = snp->init_info.MediaHeaderLen;\r
+ snp->mode.MaxPacketSize = snp->init_info.FrameDataLen;\r
+ snp->mode.NvRamAccessSize = snp->init_info.NvWidth;\r
+ snp->mode.NvRamSize = snp->init_info.NvCount * snp->mode.NvRamAccessSize;\r
+ snp->mode.IfType = snp->init_info.IFtype;\r
+ snp->mode.MaxMCastFilterCount = snp->init_info.MCastFilterCnt;\r
+ snp->mode.MCastFilterCount = 0;\r
+\r
+ switch (InitStatFlags & PXE_STATFLAGS_CABLE_DETECT_MASK) {\r
+ case PXE_STATFLAGS_CABLE_DETECT_SUPPORTED:\r
+ snp->mode.MediaPresentSupported = TRUE;\r
+ break;\r
+\r
+ case PXE_STATFLAGS_CABLE_DETECT_NOT_SUPPORTED:\r
+ default:\r
+ snp->mode.MediaPresentSupported = FALSE;\r
+ }\r
+\r
+ if ((pxe->hw.Implementation & PXE_ROMID_IMP_STATION_ADDR_SETTABLE) != 0) {\r
+ snp->mode.MacAddressChangeable = TRUE;\r
+ } else {\r
+ snp->mode.MacAddressChangeable = FALSE;\r
+ }\r
+\r
+ if ((pxe->hw.Implementation & PXE_ROMID_IMP_MULTI_FRAME_SUPPORTED) != 0) {\r
+ snp->mode.MultipleTxSupported = TRUE;\r
+ } else {\r
+ snp->mode.MultipleTxSupported = FALSE;\r
+ }\r
+\r
+ snp->mode.ReceiveFilterMask = EFI_SIMPLE_NETWORK_RECEIVE_UNICAST;\r
+\r
+ if ((pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED) != 0) {\r
+ snp->mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST;\r
+\r
+ }\r
+\r
+ if ((pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED) != 0) {\r
+ snp->mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS;\r
+\r
+ }\r
+\r
+ if ((pxe->hw.Implementation & PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED) != 0) {\r
+ snp->mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST;\r
+\r
+ }\r
+\r
+ if ((pxe->hw.Implementation & PXE_ROMID_IMP_FILTERED_MULTICAST_RX_SUPPORTED) != 0) {\r
+ snp->mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST;\r
+\r
+ }\r
+\r
+ if (pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED) {\r
+ snp->mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST;\r
+\r
+ }\r
+\r
+ snp->mode.ReceiveFilterSetting = 0;\r
+\r
+ //\r
+ // need to get the station address to save in the mode structure. we need to\r
+ // initialize the UNDI first for this.\r
+ //\r
+ snp->tx_rx_bufsize = snp->init_info.MemoryRequired;\r
+ Status = pxe_init (snp, PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE);\r
+\r
+ if (Status) {\r
+ pxe_stop (snp);\r
+ goto Error_DeleteSNP;\r
+ }\r
+\r
+ Status = pxe_get_stn_addr (snp);\r
+\r
+ if (Status != EFI_SUCCESS) {\r
+ DEBUG ((EFI_D_ERROR, "\nsnp->undi.get_station_addr() failed.\n"));\r
+ pxe_shutdown (snp);\r
+ pxe_stop (snp);\r
+ goto Error_DeleteSNP;\r
+ }\r
+\r
+ snp->mode.MediaPresent = FALSE;\r
+\r
+ //\r
+ // We should not leave UNDI started and initialized here. this DriverStart()\r
+ // routine must only find and attach the SNP interface to UNDI layer that it\r
+ // finds on the given handle!\r
+ // The UNDI layer will be started when upper layers call snp->start.\r
+ // How ever, this DriverStart() must fill up the snp mode structure which\r
+ // contains the MAC address of the NIC. For this reason we started and\r
+ // initialized UNDI here, now we are done, do a shutdown and stop of the\r
+ // UNDI interface!\r
+ //\r
+ pxe_shutdown (snp);\r
+ pxe_stop (snp);\r
+\r
+ //\r
+ // add SNP to the undi handle\r
+ //\r
+ Status = gBS->InstallProtocolInterface (\r
+ &Controller,\r
+ &gEfiSimpleNetworkProtocolGuid,\r
+ EFI_NATIVE_INTERFACE,\r
+ &(snp->snp)\r
+ );\r
+\r
+ if (!EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ Status = mPciIoFncs->FreeBuffer (\r
+ mPciIoFncs,\r
+ SNP_MEM_PAGES (4096),\r
+ snp->cpb\r
+ );\r
+\r
+Error_DeleteSNP:\r
+\r
+ mPciIoFncs->FreeBuffer (\r
+ mPciIoFncs,\r
+ SNP_MEM_PAGES (sizeof (SNP_DRIVER)),\r
+ snp\r
+ );\r
+NiiError:\r
+ gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiNetworkInterfaceIdentifierProtocolGuid_31,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+\r
+ gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiDevicePathProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+\r
+ return Status;\r
+}\r
+\r
+\r
+/**\r
+\r
+\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SimpleNetworkDriverStop (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE Controller,\r
+ IN UINTN NumberOfChildren,\r
+ IN EFI_HANDLE *ChildHandleBuffer\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_SIMPLE_NETWORK_PROTOCOL *SnpProtocol;\r
+ SNP_DRIVER *Snp;\r
+\r
+ //\r
+ // Get our context back.\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiSimpleNetworkProtocolGuid,\r
+ (VOID **) &SnpProtocol,\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (SnpProtocol);\r
+\r
+ Status = gBS->UninstallProtocolInterface (\r
+ Controller,\r
+ &gEfiSimpleNetworkProtocolGuid,\r
+ &Snp->snp\r
+ );\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ Status = gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiNetworkInterfaceIdentifierProtocolGuid_31,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+\r
+ Status = gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiDevicePathProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+\r
+ pxe_shutdown (Snp);\r
+ pxe_stop (Snp);\r
+\r
+ mPciIoFncs->FreeBuffer (\r
+ mPciIoFncs,\r
+ SNP_MEM_PAGES (4096),\r
+ Snp->cpb\r
+ );\r
+\r
+ mPciIoFncs->FreeBuffer (\r
+ mPciIoFncs,\r
+ SNP_MEM_PAGES (sizeof (SNP_DRIVER)),\r
+ Snp\r
+ );\r
+\r
+ return Status;\r
+}\r
+\r
+\r
+/**\r
+ Install all the driver protocol\r
+\r
+ @param entry EFI_IMAGE_ENTRY_POINT)\r
+\r
+ @retval EFI_SUCEESS Initialization routine has found UNDI hardware,\r
+ loaded it's ROM, and installed a notify event for\r
+ the Network Indentifier Interface Protocol\r
+ successfully.\r
+ @retval Other Return value from HandleProtocol for\r
+ DeviceIoProtocol or LoadedImageProtocol\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeSnpNiiDriver (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ return EfiLibInstallDriverBindingComponentName2 (\r
+ ImageHandle,\r
+ SystemTable,\r
+ &mSimpleNetworkDriverBinding,\r
+ NULL,\r
+ &gSimpleNetworkComponentName,\r
+ &gSimpleNetworkComponentName2\r
+ );\r
+}\r