VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/E1kNetDxe/SnpReceive.c

Last change on this file was 106066, checked in by vboxsync, 8 weeks ago

Manual copyright year updates.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1/** @file
2
3 Implementation of the SNP.Receive() function and its private helpers if any.
4
5 Copyright (c) 2021 - 2024, Oracle and/or its affiliates.
6 Copyright (C) 2013, Red Hat, Inc.
7 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
8
9 SPDX-License-Identifier: BSD-2-Clause-Patent
10
11**/
12
13#include <Library/BaseLib.h>
14#include <Library/BaseMemoryLib.h>
15#include <Library/UefiBootServicesTableLib.h>
16
17#include "E1kNet.h"
18
19/**
20 Receives a packet from a network interface.
21
22 @param This The protocol instance pointer.
23 @param HeaderSize The size, in bytes, of the media header received on the
24 network interface. If this parameter is NULL, then the
25 media header size will not be returned.
26 @param BufferSize On entry, the size, in bytes, of Buffer. On exit, the
27 size, in bytes, of the packet that was received on the
28 network interface.
29 @param Buffer A pointer to the data buffer to receive both the media
30 header and the data.
31 @param SrcAddr The source HW MAC address. If this parameter is NULL, the
32 HW MAC source address will not be extracted from the media
33 header.
34 @param DestAddr The destination HW MAC address. If this parameter is NULL,
35 the HW MAC destination address will not be extracted from
36 the media header.
37 @param Protocol The media header type. If this parameter is NULL, then the
38 protocol will not be extracted from the media header. See
39 RFC 1700 section "Ether Types" for examples.
40
41 @retval EFI_SUCCESS The received data was stored in Buffer, and
42 BufferSize has been updated to the number of
43 bytes received.
44 @retval EFI_NOT_STARTED The network interface has not been started.
45 @retval EFI_NOT_READY The network interface is too busy to accept
46 this transmit request.
47 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
48 @retval EFI_INVALID_PARAMETER One or more of the parameters has an
49 unsupported value.
50 @retval EFI_DEVICE_ERROR The command could not be sent to the network
51 interface.
52 @retval EFI_UNSUPPORTED This function is not supported by the network
53 interface.
54
55**/
56
57EFI_STATUS
58EFIAPI
59E1kNetReceive (
60 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
61 OUT UINTN *HeaderSize OPTIONAL,
62 IN OUT UINTN *BufferSize,
63 OUT VOID *Buffer,
64 OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
65 OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL,
66 OUT UINT16 *Protocol OPTIONAL
67 )
68{
69 E1K_NET_DEV *Dev;
70 EFI_TPL OldTpl;
71 EFI_STATUS Status;
72 UINT32 RdhCur;
73 UINT32 RxLen;
74 UINTN OrigBufferSize;
75 EFI_PHYSICAL_ADDRESS BufferAddress;
76 UINT8 *RxPtr;
77 UINTN RxBufOffset;
78
79 DEBUG((DEBUG_INFO, "E1kNetReceive: HeaderSize=%p BufferSize=%u Buffer=%p\n",
80 HeaderSize, *BufferSize, Buffer));
81
82 if (This == NULL || BufferSize == NULL || Buffer == NULL) {
83 return EFI_INVALID_PARAMETER;
84 }
85
86 Dev = E1K_NET_FROM_SNP (This);
87 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
88 switch (Dev->Snm.State) {
89 case EfiSimpleNetworkStopped:
90 Status = EFI_NOT_STARTED;
91 goto Exit;
92 case EfiSimpleNetworkStarted:
93 Status = EFI_DEVICE_ERROR;
94 goto Exit;
95 default:
96 break;
97 }
98
99 E1kNetRegRead32(Dev, E1K_REG_RDH, &RdhCur);
100
101 if (Dev->RdhLastSeen == RdhCur) {
102 Status = EFI_NOT_READY;
103 goto Exit;
104 }
105
106 RxLen = Dev->RxRing[Dev->RdhLastSeen].BufferLength;
107 //
108 // the host must not have filled in more data than requested
109 //
110 ASSERT (RxLen <= 2048);
111
112 OrigBufferSize = *BufferSize;
113 *BufferSize = RxLen;
114
115 if (OrigBufferSize < RxLen) {
116 Status = EFI_BUFFER_TOO_SMALL;
117 goto Exit; // keep the packet
118 }
119
120 if (RxLen < Dev->Snm.MediaHeaderSize) {
121 Status = EFI_DEVICE_ERROR;
122 goto RecycleDesc; // drop useless short packet
123 }
124
125 if (HeaderSize != NULL) {
126 *HeaderSize = Dev->Snm.MediaHeaderSize;
127 }
128
129 BufferAddress = Dev->RxRing[Dev->RdhLastSeen].AddrBufferLow;
130 BufferAddress |= LShiftU64(Dev->RxRing[Dev->RdhLastSeen].AddrBufferHigh, 32);
131 RxBufOffset = (UINTN)(BufferAddress - Dev->RxBufDeviceBase);
132 RxPtr = Dev->RxBuf + RxBufOffset;
133 CopyMem (Buffer, RxPtr, RxLen);
134
135 if (DestAddr != NULL) {
136 CopyMem (DestAddr, RxPtr, sizeof (E1K_NET_MAC));
137 }
138 RxPtr += sizeof (E1K_NET_MAC);
139
140 if (SrcAddr != NULL) {
141 CopyMem (SrcAddr, RxPtr, sizeof (E1K_NET_MAC));
142 }
143 RxPtr += sizeof (E1K_NET_MAC);
144
145 if (Protocol != NULL) {
146 *Protocol = (UINT16) ((RxPtr[0] << 8) | RxPtr[1]);
147 }
148 RxPtr += sizeof (UINT16);
149
150 Status = EFI_SUCCESS;
151
152RecycleDesc:
153 Dev->RdhLastSeen = (Dev->RdhLastSeen + 1) % E1K_NET_MAX_PENDING;
154 E1kNetRegWrite32(Dev, E1K_REG_RDT, Dev->RdhLastSeen);
155
156Exit:
157 gBS->RestoreTPL (OldTpl);
158 return Status;
159}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette