mnpmain.c

来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 655 行 · 第 1/2 页

C
655
字号
                &GroupAddress->Address,
                SnpMode->HwAddressSize
                )) {
        //
        // There is already the same multicast mac address configured.
        //
        AddressExist = TRUE;
        break;
      }
    }

    if (JoinFlag && AddressExist) {
      //
      // The multicast mac address to join already exists.
      //
      return EFI_ALREADY_STARTED;
    }

    if (!JoinFlag && !AddressExist) {
      //
      // The multicast mac address to leave doesn't exist in this instance.
      //
      return EFI_NOT_FOUND;
    }
  } else if (NetListIsEmpty (&Instance->GroupCtrlBlkList)) {
    //
    // The MacAddress is NULL and there is no configured multicast mac address,
    // just return.
    //
    return EFI_SUCCESS;
  }

  //
  // OK, it is time to take action.
  //
  return MnpGroupOp (Instance, JoinFlag, MacAddress, GroupCtrlBlk);
}

EFI_STATUS
EFIAPI
MnpTransmit (
  IN EFI_MANAGED_NETWORK_PROTOCOL          *This,
  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token
  )
/*++

Routine Description:

  Place an outgoing packet into the transmit queue.
    
Arguments:

  This  - Pointer to the Managed Network Protocol.
  Token - Pointer to a token associated with the transmit data descriptor.
    
Returns:
    
  EFI_SUCCESS             - The operation completed successfully.
  EFI_INVALID_PARAMETER   - One or more parameter is invalid
  EFI_NOT_STARTED         - This MNP child driver instance has not been configured.
  EFI_ACCESS_DENIED       - The transmit completion token is already in the
                            transmit queue.
  EFI_OUT_OF_RESOURCES    - The transmit data could not be queued due to a
                            lack of system resources (usually memory).
  EFI_DEVICE_ERROR        - An unexpected system or network error occurred. 
                            The MNP child driver instance has been reset
                            to startup defaults.
  EFI_NOT_READY           - The transmit request could not be queued because
                            the transmit queue is full.

--*/
{
  EFI_STATUS        Status;
  MNP_INSTANCE_DATA *Instance;
  MNP_SERVICE_DATA  *MnpServiceData;
  UINT8             *PktBuf;
  UINT32            PktLen;

  if ((This == NULL) || (Token == NULL)) {

    return EFI_INVALID_PARAMETER;
  }

  Instance = MNP_INSTANCE_DATA_FROM_THIS (This);

  if (!Instance->Configured) {

    return EFI_NOT_STARTED;
  }

  if (!MnpIsValidTxToken (Instance, Token)) {
    //
    // The Token is invalid.
    //
    return EFI_INVALID_PARAMETER;
  }

  MnpServiceData = Instance->MnpServiceData;
  NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);

  //
  // Try to acquire the TxLock.
  //
  if (EFI_ERROR (NET_TRYLOCK (&MnpServiceData->TxLock))) {

    return EFI_ACCESS_DENIED;
  }
  //
  // Build the tx packet
  //
  MnpBuildTxPacket (MnpServiceData, Token->Packet.TxData, &PktBuf, &PktLen);

  //
  //  OK, send the packet synchronously.
  //
  Status = MnpSyncSendPacket (MnpServiceData, PktBuf, PktLen, Token);

  NET_UNLOCK (&MnpServiceData->TxLock);

  return Status;
}

EFI_STATUS
EFIAPI
MnpReceive (
  IN EFI_MANAGED_NETWORK_PROTOCOL          *This,
  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token
  )
/*++

Routine Description:

  Place an asynchronous receiving request into the receiving queue.
    
Arguments:

  This  - Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
  Token - Pointer to a token associated with the receive data descriptor. 
    
Returns:

  EFI_SUCCESS             - The receive completion token was cached.
  EFI_NOT_STARTED         - This MNP child driver instance has not been configured.
  EFI_INVALID_PARAMETER   - One or more parameter is invalid.
  EFI_OUT_OF_RESOURCES    - The transmit data could not be queued due to a lack of
                            system resources (usually memory).
  EFI_DEVICE_ERROR        - An unexpected system or network error occurred. The MNP
                            child driver instance has been reset to startup defaults.
  EFI_ACCESS_DENIED       - The receive completion token was already in the receive queue.
  EFI_NOT_READY           - The receive request could not be queued because the receive
                            queue is full.

--*/
{
  EFI_STATUS        Status;
  MNP_INSTANCE_DATA *Instance;

  if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) {

    return EFI_INVALID_PARAMETER;
  }

  Instance = MNP_INSTANCE_DATA_FROM_THIS (This);

  if (!Instance->Configured) {

    return EFI_NOT_STARTED;
  }
  //
  // Try to acquire the lock
  //
  if (EFI_ERROR (NET_TRYLOCK (&Instance->RxLock))) {

    return EFI_ACCESS_DENIED;
  }
  //
  // Check whether this token(event) is already in the rx token queue.
  //
  Status = NetMapIterate (&Instance->RxTokenMap, MnpTokenExist, (VOID *) Token);
  if (EFI_ERROR (Status)) {

    goto UNLOCK_EXIT;
  }

  //
  // Insert the Token into the RxTokenMap.
  //
  Status = NetMapInsertTail (&Instance->RxTokenMap, (VOID *) Token, NULL);

  if (!EFI_ERROR (Status)) {
    //
    // Try to deliver any buffered packets.
    //
    Status = MnpInstanceDeliverPacket (Instance);
  }

UNLOCK_EXIT:

  NET_UNLOCK (&Instance->RxLock);

  return Status;
}

EFI_STATUS
EFIAPI
MnpCancel (
  IN EFI_MANAGED_NETWORK_PROTOCOL          *This,
  IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN  *Token OPTIONAL
  )
/*++

Routine Description:

  Abort a pending transmit or receive request.
    
Arguments:

  This    - Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
  Token   - Pointer to a token that has been issued by
            EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or
            EFI_MANAGED_NETWORK_PROTOCOL.Receive().
            If NULL, all pending tokens are aborted.
    
Returns:
    
  EFI_SUCCESS           - The asynchronous I/O request was aborted and Token->Event
                          was signaled.
  EFI_NOT_STARTED       - This MNP child driver instance has not been configured.
  EFI_INVALID_PARAMETER - This is NULL.
  EFI_NOT_FOUND         - The asynchronous I/O request was not found in the transmit or
                          receive queue. It has either completed or was not issued by
                          Transmit() and Receive().

--*/
{
  EFI_STATUS        Status;
  MNP_INSTANCE_DATA *Instance;

  if (This == NULL) {

    return EFI_INVALID_PARAMETER;
  }

  Instance = MNP_INSTANCE_DATA_FROM_THIS (This);

  if (!Instance->Configured) {

    return EFI_NOT_STARTED;
  }

  if (EFI_ERROR (NET_TRYLOCK (&Instance->RxLock))) {
    return EFI_ACCESS_DENIED;
  }

  //
  // Iterate the RxTokenMap to cancel the specified Token.
  //
  Status = NetMapIterate (&Instance->RxTokenMap, MnpCancelTokens, (VOID *) Token);

  NET_UNLOCK (&Instance->RxLock);

  if (Token != NULL) {

    Status = (Status == EFI_ABORTED) ? EFI_SUCCESS : EFI_NOT_FOUND;
  }

  return Status;
}

EFI_STATUS
EFIAPI
MnpPoll (
  IN EFI_MANAGED_NETWORK_PROTOCOL  *This
  )
/*++

Routine Description:

  Poll the network interface to do transmit/receive work.
    
Arguments:

  This    - Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
    
Returns:

  EFI_SUCCESS      - Incoming or outgoing data was processed.
  EFI_NOT_STARTED  - This MNP child driver instance has not been configured.
  EFI_DEVICE_ERROR - An unexpected system or network error occurred.
                     The MNP child driver instance has been reset to startup defaults.
  EFI_NOT_READY    - No incoming or outgoing data was processed.
  EFI_TIMEOUT      - Data was dropped out of the transmit and/or receive queue.

--*/
{
  EFI_STATUS        Status;
  MNP_INSTANCE_DATA *Instance;

  if (This == NULL) {

    return EFI_INVALID_PARAMETER;
  }

  Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
  ASSERT (Instance->Signature == MNP_INSTANCE_DATA_SIGNATURE);

  if (!Instance->Configured) {

    return EFI_NOT_STARTED;
  }
  //
  // Try to acquire the rx lock.
  //
  if (EFI_ERROR (NET_TRYLOCK (&Instance->RxLock))) {

    return EFI_SUCCESS;
  }
  //
  // Try to receive packets.
  //
  Status = MnpReceivePacket (Instance->MnpServiceData);

  NET_UNLOCK (&Instance->RxLock);

  return Status;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?