]> git.proxmox.com Git - mirror_edk2.git/commitdiff
rename
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 20 Feb 2008 02:41:47 +0000 (02:41 +0000)
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 20 Feb 2008 02:41:47 +0000 (02:41 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4734 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/Network/SnpDxe/Transmit.c [new file with mode: 0644]

diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Transmit.c b/MdeModulePkg/Universal/Network/SnpDxe/Transmit.c
new file mode 100644 (file)
index 0000000..8ee0cad
--- /dev/null
@@ -0,0 +1,327 @@
+/** @file\r
+Copyright (c) 2004 - 2007, 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
+\r
+    transmit.c\r
+\r
+Abstract:\r
+\r
+Revision history:\r
+  2000-Feb-03 M(f)J   Genesis.\r
+\r
+**/\r
+\r
+#include "Snp.h"\r
+\r
+\r
+/**\r
+  This routine calls undi to create the meadia header for the given data buffer.\r
+\r
+  @param  snp                 pointer to SNP driver structure\r
+  @param  MacHeaderPtr        address where the media header will be filled in.\r
+  @param  MacHeaderSize       size of the memory at MacHeaderPtr\r
+  @param  BufferPtr           data buffer pointer\r
+  @param  BufferLength        Size of data in the BufferPtr\r
+  @param  DestinationAddrPtr  address of the destination mac address buffer\r
+  @param  SourceAddrPtr       address of the source mac address buffer\r
+  @param  ProtocolPtr         address of the protocol type\r
+\r
+  @retval EFI_SUCCESS         if successfully completed the undi call\r
+  @retval Other               error return from undi call.\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+pxe_fillheader (\r
+  SNP_DRIVER      *snp,\r
+  VOID            *MacHeaderPtr,\r
+  UINTN           MacHeaderSize,\r
+  VOID            *BufferPtr,\r
+  UINTN           BufferLength,\r
+  EFI_MAC_ADDRESS *DestinationAddrPtr,\r
+  EFI_MAC_ADDRESS *SourceAddrPtr,\r
+  UINT16          *ProtocolPtr\r
+  )\r
+{\r
+  PXE_CPB_FILL_HEADER_FRAGMENTED  *cpb;\r
+\r
+  cpb = snp->cpb;\r
+  if (SourceAddrPtr) {\r
+    CopyMem (\r
+      (VOID *) cpb->SrcAddr,\r
+      (VOID *) SourceAddrPtr,\r
+      snp->mode.HwAddressSize\r
+      );\r
+  } else {\r
+    CopyMem (\r
+      (VOID *) cpb->SrcAddr,\r
+      (VOID *) &(snp->mode.CurrentAddress),\r
+      snp->mode.HwAddressSize\r
+      );\r
+  }\r
+\r
+  CopyMem (\r
+    (VOID *) cpb->DestAddr,\r
+    (VOID *) DestinationAddrPtr,\r
+    snp->mode.HwAddressSize\r
+    );\r
+\r
+  //\r
+  // we need to do the byte swapping\r
+  //\r
+  cpb->Protocol             = (UINT16) PXE_SWAP_UINT16 (*ProtocolPtr);\r
+\r
+  cpb->PacketLen            = (UINT32) (BufferLength);\r
+  cpb->MediaHeaderLen       = (UINT16) MacHeaderSize;\r
+\r
+  cpb->FragCnt              = 2;\r
+  cpb->reserved             = 0;\r
+\r
+  cpb->FragDesc[0].FragAddr = (UINT64)(UINTN) MacHeaderPtr;\r
+  cpb->FragDesc[0].FragLen  = (UINT32) MacHeaderSize;\r
+  cpb->FragDesc[1].FragAddr = (UINT64)(UINTN) BufferPtr;\r
+  cpb->FragDesc[1].FragLen  = (UINT32) BufferLength;\r
+\r
+  cpb->FragDesc[0].reserved = cpb->FragDesc[1].reserved = 0;\r
+\r
+  snp->cdb.OpCode     = PXE_OPCODE_FILL_HEADER;\r
+  snp->cdb.OpFlags    = PXE_OPFLAGS_FILL_HEADER_FRAGMENTED;\r
+\r
+  snp->cdb.DBsize     = PXE_DBSIZE_NOT_USED;\r
+  snp->cdb.DBaddr     = PXE_DBADDR_NOT_USED;\r
+\r
+  snp->cdb.CPBsize    = sizeof (PXE_CPB_FILL_HEADER_FRAGMENTED);\r
+  snp->cdb.CPBaddr    = (UINT64)(UINTN) cpb;\r
+\r
+  snp->cdb.StatCode   = PXE_STATCODE_INITIALIZE;\r
+  snp->cdb.StatFlags  = PXE_STATFLAGS_INITIALIZE;\r
+  snp->cdb.IFnum      = snp->if_num;\r
+  snp->cdb.Control    = PXE_CONTROL_LAST_CDB_IN_LIST;\r
+\r
+  //\r
+  // Issue UNDI command and check result.\r
+  //\r
+  DEBUG ((EFI_D_NET, "\nsnp->undi.fill_header()  "));\r
+\r
+  (*snp->issue_undi32_command) ((UINT64) (UINTN) &snp->cdb);\r
+\r
+  switch (snp->cdb.StatCode) {\r
+  case PXE_STATCODE_SUCCESS:\r
+    return EFI_SUCCESS;\r
+\r
+  case PXE_STATCODE_INVALID_PARAMETER:\r
+    DEBUG (\r
+      (EFI_D_ERROR,\r
+      "\nsnp->undi.fill_header()  %xh:%xh\n",\r
+      snp->cdb.StatFlags,\r
+      snp->cdb.StatCode)\r
+      );\r
+\r
+    return EFI_INVALID_PARAMETER;\r
+\r
+  default:\r
+    DEBUG (\r
+      (EFI_D_ERROR,\r
+      "\nsnp->undi.fill_header()  %xh:%xh\n",\r
+      snp->cdb.StatFlags,\r
+      snp->cdb.StatCode)\r
+      );\r
+\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+}\r
+\r
+\r
+/**\r
+  This routine calls undi to transmit the given data buffer\r
+\r
+  @param  snp                 pointer to SNP driver structure\r
+  @param  BufferPtr           data buffer pointer\r
+  @param  BufferLength        Size of data in the BufferPtr\r
+\r
+  @retval EFI_SUCCESS         if successfully completed the undi call\r
+  @retval Other               error return from undi call.\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+pxe_transmit (\r
+  SNP_DRIVER *snp,\r
+  VOID       *BufferPtr,\r
+  UINTN      BufferLength\r
+  )\r
+{\r
+  PXE_CPB_TRANSMIT  *cpb;\r
+  EFI_STATUS        Status;\r
+\r
+  cpb             = snp->cpb;\r
+  cpb->FrameAddr  = (UINT64) (UINTN) BufferPtr;\r
+  cpb->DataLen    = (UINT32) BufferLength;\r
+\r
+  cpb->MediaheaderLen = 0;\r
+  cpb->reserved       = 0;\r
+\r
+  snp->cdb.OpFlags    = PXE_OPFLAGS_TRANSMIT_WHOLE;\r
+\r
+  snp->cdb.CPBsize    = sizeof (PXE_CPB_TRANSMIT);\r
+  snp->cdb.CPBaddr    = (UINT64)(UINTN) cpb;\r
+\r
+  snp->cdb.OpCode     = PXE_OPCODE_TRANSMIT;\r
+  snp->cdb.DBsize     = PXE_DBSIZE_NOT_USED;\r
+  snp->cdb.DBaddr     = PXE_DBADDR_NOT_USED;\r
+\r
+  snp->cdb.StatCode   = PXE_STATCODE_INITIALIZE;\r
+  snp->cdb.StatFlags  = PXE_STATFLAGS_INITIALIZE;\r
+  snp->cdb.IFnum      = snp->if_num;\r
+  snp->cdb.Control    = PXE_CONTROL_LAST_CDB_IN_LIST;\r
+\r
+  //\r
+  // Issue UNDI command and check result.\r
+  //\r
+  DEBUG ((EFI_D_NET, "\nsnp->undi.transmit()  "));\r
+  DEBUG ((EFI_D_NET, "\nsnp->cdb.OpCode  == %x", snp->cdb.OpCode));\r
+  DEBUG ((EFI_D_NET, "\nsnp->cdb.CPBaddr == %X", snp->cdb.CPBaddr));\r
+  DEBUG ((EFI_D_NET, "\nsnp->cdb.DBaddr  == %X", snp->cdb.DBaddr));\r
+  DEBUG ((EFI_D_NET, "\ncpb->FrameAddr   == %X\n", cpb->FrameAddr));\r
+\r
+  (*snp->issue_undi32_command) ((UINT64) (UINTN) &snp->cdb);\r
+\r
+  DEBUG ((EFI_D_NET, "\nexit snp->undi.transmit()  "));\r
+  DEBUG ((EFI_D_NET, "\nsnp->cdb.StatCode == %r", snp->cdb.StatCode));\r
+\r
+  //\r
+  // we will unmap the buffers in get_status call, not here\r
+  //\r
+  switch (snp->cdb.StatCode) {\r
+  case PXE_STATCODE_SUCCESS:\r
+    return EFI_SUCCESS;\r
+\r
+  case PXE_STATCODE_QUEUE_FULL:\r
+  case PXE_STATCODE_BUSY:\r
+    Status = EFI_NOT_READY;\r
+    break;\r
+\r
+  default:\r
+    Status = EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  DEBUG (\r
+    (EFI_D_ERROR,\r
+    "\nsnp->undi.transmit()  %xh:%xh\n",\r
+    snp->cdb.StatFlags,\r
+    snp->cdb.StatCode)\r
+    );\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  This is the snp interface routine for transmitting a packet. this routine\r
+  basically retrieves the snp structure, checks the snp state and calls\r
+  pxe_fill_header and pxe_transmit calls to complete the transmission.\r
+\r
+  @param  this                pointer to SNP driver context\r
+  @param  MacHeaderSize       size of the memory at MacHeaderPtr\r
+  @param  BufferLength        Size of data in the BufferPtr\r
+  @param  BufferPtr           data buffer pointer\r
+  @param  SourceAddrPtr       address of the source mac address buffer\r
+  @param  DestinationAddrPtr  address of the destination mac address buffer\r
+  @param  ProtocolPtr         address of the protocol type\r
+\r
+  @retval EFI_SUCCESS         if successfully completed the undi call\r
+  @retval Other               error return from undi call.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+snp_undi32_transmit (\r
+  IN EFI_SIMPLE_NETWORK_PROTOCOL * this,\r
+  IN UINTN                       MacHeaderSize,\r
+  IN UINTN                       BufferLength,\r
+  IN VOID                        *BufferPtr,\r
+  IN EFI_MAC_ADDRESS             * SourceAddrPtr OPTIONAL,\r
+  IN EFI_MAC_ADDRESS             * DestinationAddrPtr OPTIONAL,\r
+  IN UINT16                      *ProtocolPtr OPTIONAL\r
+  )\r
+{\r
+  SNP_DRIVER  *snp;\r
+  EFI_STATUS  Status;\r
+  EFI_TPL     OldTpl;\r
+\r
+  if (this == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  if (snp == NULL) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  switch (snp->mode.State) {\r
+  case EfiSimpleNetworkInitialized:\r
+    break;\r
+\r
+  case EfiSimpleNetworkStopped:\r
+    Status = EFI_NOT_STARTED;\r
+    goto ON_EXIT;\r
+\r
+  default:\r
+    Status = EFI_DEVICE_ERROR;\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  if (BufferPtr == NULL) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  if (BufferLength < snp->mode.MediaHeaderSize) {\r
+    Status = EFI_BUFFER_TOO_SMALL;\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  //\r
+  // if the MacHeaderSize is non-zero, we need to fill up the header and for that\r
+  // we need the destination address and the protocol\r
+  //\r
+  if (MacHeaderSize != 0) {\r
+    if (MacHeaderSize != snp->mode.MediaHeaderSize || DestinationAddrPtr == 0 || ProtocolPtr == 0) {\r
+      Status = EFI_INVALID_PARAMETER;\r
+      goto ON_EXIT;\r
+    }\r
+\r
+    Status = pxe_fillheader (\r
+              snp,\r
+              BufferPtr,\r
+              MacHeaderSize,\r
+              (UINT8 *) BufferPtr + MacHeaderSize,\r
+              BufferLength - MacHeaderSize,\r
+              DestinationAddrPtr,\r
+              SourceAddrPtr,\r
+              ProtocolPtr\r
+              );\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_EXIT;\r
+    }\r
+  }\r
+\r
+  Status = pxe_transmit (snp, BufferPtr, BufferLength);\r
+\r
+ON_EXIT:\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return Status;\r
+}\r