• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 
3  Copyright (c) 2010, Apple, Inc. All rights reserved.<BR>
4 
5     This program and the accompanying materials
6     are licensed and made available under the terms and conditions of the BSD License
7     which accompanies this distribution. The full text of the license may be found at
8     http://opensource.org/licenses/bsd-license.php
9 
10     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 Module Name:
14 
15   EmuSnp.h
16 
17 Abstract:
18 
19 -**/
20 
21 #ifndef _EMU_SNP_H_
22 #define _EMU_SNP_H_
23 
24 #include <Uefi.h>
25 
26 #include <Protocol/SimpleNetwork.h>
27 #include <Protocol/DevicePath.h>
28 #include <Protocol/EmuIoThunk.h>
29 #include <Protocol/EmuSnp.h>
30 
31 
32 #include <Library/BaseLib.h>
33 #include <Library/DebugLib.h>
34 #include <Library/BaseMemoryLib.h>
35 #include <Library/UefiBootServicesTableLib.h>
36 #include <Library/UefiLib.h>
37 #include <Library/DevicePathLib.h>
38 #include <Library/MemoryAllocationLib.h>
39 #include <Library/NetLib.h>
40 
41 #define NET_ETHER_HEADER_SIZE     14
42 
43 //
44 //  Private data for driver.
45 //
46 #define EMU_SNP_PRIVATE_DATA_SIGNATURE SIGNATURE_32( 'U', 'S', 'N', 'P' )
47 
48 typedef struct {
49   UINTN                       Signature;
50   EMU_IO_THUNK_PROTOCOL       *IoThunk;
51   EMU_SNP_PROTOCOL            *Io;
52   EFI_DEVICE_PATH_PROTOCOL    *DevicePath;
53 
54   EFI_HANDLE                  EfiHandle;
55   EFI_HANDLE                  DeviceHandle;
56 
57   EFI_SIMPLE_NETWORK_PROTOCOL Snp;
58   EFI_SIMPLE_NETWORK_MODE     Mode;
59 
60   EFI_UNICODE_STRING_TABLE    *ControllerNameTable;
61 
62 } EMU_SNP_PRIVATE_DATA;
63 
64 #define EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS(a) \
65       CR( a, EMU_SNP_PRIVATE_DATA, Snp, EMU_SNP_PRIVATE_DATA_SIGNATURE )
66 
67 extern EFI_DRIVER_BINDING_PROTOCOL    gEmuSnpDriverBinding;
68 extern EFI_COMPONENT_NAME_PROTOCOL    gEmuSnpDriverComponentName;
69 extern EFI_COMPONENT_NAME2_PROTOCOL   gEmuSnpDriverComponentName2;
70 
71 /**
72   Test to see if this driver supports ControllerHandle. This service
73   is called by the EFI boot service ConnectController(). In
74   order to make drivers as small as possible, there are a few calling
75   restrictions for this service. ConnectController() must
76   follow these calling restrictions. If any other agent wishes to call
77   Supported() it must also follow these calling restrictions.
78 
79   @param  This                Protocol instance pointer.
80   @param  ControllerHandle    Handle of device to test
81   @param  RemainingDevicePath Optional parameter use to pick a specific child
82                               device to start.
83 
84   @retval EFI_SUCCESS         This driver supports this device
85   @retval EFI_UNSUPPORTED     This driver does not support this device
86 
87 **/
88 EFI_STATUS
89 EFIAPI
90 EmuSnpDriverBindingSupported (
91   IN EFI_DRIVER_BINDING_PROTOCOL  * This,
92   IN EFI_HANDLE                   ControllerHandle,
93   IN EFI_DEVICE_PATH_PROTOCOL     * RemainingDevicePath OPTIONAL
94   );
95 
96 /**
97   Start this driver on ControllerHandle. This service is called by the
98   EFI boot service ConnectController(). In order to make
99   drivers as small as possible, there are a few calling restrictions for
100   this service. ConnectController() must follow these
101   calling restrictions. If any other agent wishes to call Start() it
102   must also follow these calling restrictions.
103 
104   @param  This                 Protocol instance pointer.
105   @param  ControllerHandle     Handle of device to bind driver to
106   @param  RemainingDevicePath  Optional parameter use to pick a specific child
107                                device to start.
108 
109   @retval EFI_SUCCESS          Always succeeds.
110 
111 **/
112 EFI_STATUS
113 EFIAPI
114 EmuSnpDriverBindingStart (
115   IN EFI_DRIVER_BINDING_PROTOCOL  * This,
116   IN EFI_HANDLE                   ControllerHandle,
117   IN EFI_DEVICE_PATH_PROTOCOL     * RemainingDevicePath OPTIONAL
118   );
119 
120 /**
121   Stop this driver on ControllerHandle. This service is called by the
122   EFI boot service DisconnectController(). In order to
123   make drivers as small as possible, there are a few calling
124   restrictions for this service. DisconnectController()
125   must follow these calling restrictions. If any other agent wishes
126   to call Stop() it must also follow these calling restrictions.
127 
128   @param  This              Protocol instance pointer.
129   @param  ControllerHandle  Handle of device to stop driver on
130   @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of
131                             children is zero stop the entire bus driver.
132   @param  ChildHandleBuffer List of Child Handles to Stop.
133 
134   @retval EFI_SUCCESS       Always succeeds.
135 
136 **/
137 EFI_STATUS
138 EFIAPI
139 EmuSnpDriverBindingStop (
140   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,
141   IN  EFI_HANDLE                   ControllerHandle,
142   IN  UINTN                        NumberOfChildren,
143   IN  EFI_HANDLE                   *ChildHandleBuffer
144   );
145 
146 /**
147   Changes the state of a network interface from "stopped" to "started".
148 
149   @param  This Protocol instance pointer.
150 
151   @retval EFI_SUCCESS           Always succeeds.
152 
153 **/
154 EFI_STATUS
155 EFIAPI
156 EmuSnpStart(
157   IN EFI_SIMPLE_NETWORK_PROTOCOL*    This
158   );
159 
160 /**
161   Changes the state of a network interface from "started" to "stopped".
162 
163   @param  This Protocol instance pointer.
164 
165   @retval EFI_SUCCESS           Always succeeds.
166 
167 **/
168 EFI_STATUS
169 EFIAPI
170 EmuSnpStop(
171   IN EFI_SIMPLE_NETWORK_PROTOCOL*    This
172   );
173 
174 /**
175   Resets a network adapter and allocates the transmit and receive buffers
176   required by the network interface; optionally, also requests allocation
177   of additional transmit and receive buffers.
178 
179   @param  This              Protocol instance pointer.
180   @param  ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
181                             that the driver should allocate for the network interface.
182                             Some network interfaces will not be able to use the extra
183                             buffer, and the caller will not know if it is actually
184                             being used.
185   @param  ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
186                             that the driver should allocate for the network interface.
187                             Some network interfaces will not be able to use the extra
188                             buffer, and the caller will not know if it is actually
189                             being used.
190 
191   @retval EFI_SUCCESS           Always succeeds.
192 
193 **/
194 EFI_STATUS
195 EFIAPI
196 EmuSnpInitialize(
197   IN EFI_SIMPLE_NETWORK_PROTOCOL*    This,
198   IN UINTN              ExtraRxBufferSize OPTIONAL,
199   IN UINTN              ExtraTxBufferSize OPTIONAL
200   );
201 
202 /**
203   Resets a network adapter and re-initializes it with the parameters that were
204   provided in the previous call to Initialize().
205 
206   @param  This                 Protocol instance pointer.
207   @param  ExtendedVerification Indicates that the driver may perform a more
208                                exhaustive verification operation of the device
209                                during reset.
210 
211   @retval EFI_SUCCESS           Always succeeds.
212 
213 **/
214 EFI_STATUS
215 EFIAPI
216 EmuSnpReset(
217   IN EFI_SIMPLE_NETWORK_PROTOCOL*    This,
218   IN BOOLEAN              ExtendedVerification
219   );
220 
221 /**
222   Resets a network adapter and leaves it in a state that is safe for
223   another driver to initialize.
224 
225   @param  This Protocol instance pointer.
226 
227   @retval EFI_SUCCESS           Always succeeds.
228 
229 **/
230 EFI_STATUS
231 EFIAPI
232 EmuSnpShutdown(
233   IN EFI_SIMPLE_NETWORK_PROTOCOL*    This
234   );
235 
236 /**
237   Manages the multicast receive filters of a network interface.
238 
239   @param  This               Protocol instance pointer.
240   @param  EnableBits         A bit mask of receive filters to enable on the network interface.
241   @param  DisableBits        A bit mask of receive filters to disable on the network interface.
242   @param  ResetMcastFilter   Set to TRUE to reset the contents of the multicast receive
243                              filters on the network interface to their default values.
244   @param  McastFilterCount   Number of multicast HW MAC addresses in the new
245                              MCastFilter list. This value must be less than or equal to
246                              the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This
247                              field is optional if ResetMCastFilter is TRUE.
248   @param  McastFilter        A pointer to a list of new multicast receive filter HW MAC
249                              addresses. This list will replace any existing multicast
250                              HW MAC address list. This field is optional if
251                              ResetMCastFilter is TRUE.
252 
253   @retval EFI_SUCCESS           The multicast receive filter list was updated.
254   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
255 
256 **/
257 EFI_STATUS
258 EFIAPI
259 EmuSnpReceiveFilters(
260   IN EFI_SIMPLE_NETWORK_PROTOCOL*    This,
261   IN UINT32              EnableBits,
262   IN UINT32              DisableBits,
263   IN BOOLEAN              ResetMcastFilter,
264   IN UINTN              McastFilterCount OPTIONAL,
265   IN EFI_MAC_ADDRESS*          McastFilter OPTIONAL
266   );
267 
268 /**
269   Modifies or resets the current station address, if supported.
270 
271   @param  This         Protocol instance pointer.
272   @param  Reset        Flag used to reset the station address to the network interfaces
273                        permanent address.
274   @param  NewMacAddr   New station address to be used for the network interface.
275 
276   @retval EFI_UNSUPPORTED       Not supported yet.
277 
278 **/
279 EFI_STATUS
280 EFIAPI
281 EmuSnpStationAddress(
282   IN EFI_SIMPLE_NETWORK_PROTOCOL*    This,
283   IN BOOLEAN              Reset,
284   IN EFI_MAC_ADDRESS*          NewMacAddr OPTIONAL
285   );
286 
287 /**
288   Resets or collects the statistics on a network interface.
289 
290   @param  This            Protocol instance pointer.
291   @param  Reset           Set to TRUE to reset the statistics for the network interface.
292   @param  StatisticsSize  On input the size, in bytes, of StatisticsTable. On
293                           output the size, in bytes, of the resulting table of
294                           statistics.
295   @param  StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
296                           contains the statistics.
297 
298   @retval EFI_SUCCESS           The statistics were collected from the network interface.
299   @retval EFI_NOT_STARTED       The network interface has not been started.
300   @retval EFI_BUFFER_TOO_SMALL  The Statistics buffer was too small. The current buffer
301                                 size needed to hold the statistics is returned in
302                                 StatisticsSize.
303   @retval EFI_UNSUPPORTED       Not supported yet.
304 
305 **/
306 EFI_STATUS
307 EFIAPI
308 EmuSnpStatistics(
309   IN EFI_SIMPLE_NETWORK_PROTOCOL*    This,
310   IN BOOLEAN              Reset,
311   IN OUT UINTN*            StatisticsSize OPTIONAL,
312   OUT EFI_NETWORK_STATISTICS*      StatisticsTable OPTIONAL
313   );
314 
315 /**
316   Converts a multicast IP address to a multicast HW MAC address.
317 
318   @param  This  Protocol instance pointer.
319   @param  Ipv6  Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
320                 to FALSE if the multicast IP address is IPv4 [RFC 791].
321   @param  Ip    The multicast IP address that is to be converted to a multicast
322                 HW MAC address.
323   @param  Mac   The multicast HW MAC address that is to be generated from IP.
324 
325   @retval EFI_SUCCESS           The multicast IP address was mapped to the multicast
326                                 HW MAC address.
327   @retval EFI_NOT_STARTED       The network interface has not been started.
328   @retval EFI_BUFFER_TOO_SMALL  The Statistics buffer was too small. The current buffer
329                                 size needed to hold the statistics is returned in
330                                 StatisticsSize.
331   @retval EFI_UNSUPPORTED       Not supported yet.
332 
333 **/
334 EFI_STATUS
335 EFIAPI
336 EmuSnpMcastIptoMac(
337   IN EFI_SIMPLE_NETWORK_PROTOCOL*    This,
338   IN BOOLEAN              Ipv6,
339   IN EFI_IP_ADDRESS*          Ip,
340   OUT EFI_MAC_ADDRESS*        Mac
341   );
342 
343 /**
344   Performs read and write operations on the NVRAM device attached to a
345   network interface.
346 
347   @param  This         Protocol instance pointer.
348   @param  ReadOrWrite  TRUE for read operations, FALSE for write operations.
349   @param  Offset       Byte offset in the NVRAM device at which to start the read or
350                        write operation. This must be a multiple of NvRamAccessSize and
351                        less than NvRamSize.
352   @param  BufferSize   The number of bytes to read or write from the NVRAM device.
353                        This must also be a multiple of NvramAccessSize.
354   @param  Buffer       A pointer to the data buffer.
355 
356   @retval EFI_UNSUPPORTED       Not supported yet.
357 
358 **/
359 EFI_STATUS
360 EFIAPI
361 EmuSnpNvdata(
362   IN EFI_SIMPLE_NETWORK_PROTOCOL*    This,
363   IN BOOLEAN              ReadOrWrite,
364   IN UINTN              Offset,
365   IN UINTN              BufferSize,
366   IN OUT VOID*            Buffer
367   );
368 
369 /**
370   Reads the current interrupt status and recycled transmit buffer status from
371   a network interface.
372 
373   @param  This            Protocol instance pointer.
374   @param  InterruptStatus A pointer to the bit mask of the currently active interrupts
375                           If this is NULL, the interrupt status will not be read from
376                           the device. If this is not NULL, the interrupt status will
377                           be read from the device. When the  interrupt status is read,
378                           it will also be cleared. Clearing the transmit  interrupt
379                           does not empty the recycled transmit buffer array.
380   @param  TxBuffer        Recycled transmit buffer address. The network interface will
381                           not transmit if its internal recycled transmit buffer array
382                           is full. Reading the transmit buffer does not clear the
383                           transmit interrupt. If this is NULL, then the transmit buffer
384                           status will not be read. If there are no transmit buffers to
385                           recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
386 
387   @retval EFI_SUCCESS           Always succeeds.
388 
389 **/
390 EFI_STATUS
391 EFIAPI
392 EmuSnpGetStatus(
393   IN EFI_SIMPLE_NETWORK_PROTOCOL*    This,
394   OUT UINT32*              InterruptStatus,
395   OUT VOID**              TxBuffer
396   );
397 
398 /**
399   Places a packet in the transmit queue of a network interface.
400 
401   @param  This       Protocol instance pointer.
402   @param  HeaderSize The size, in bytes, of the media header to be filled in by
403                      the Transmit() function. If HeaderSize is non-zero, then it
404                      must be equal to This->Mode->MediaHeaderSize and the DestAddr
405                      and Protocol parameters must not be NULL.
406   @param  BufferSize The size, in bytes, of the entire packet (media header and
407                      data) to be transmitted through the network interface.
408   @param  Buffer     A pointer to the packet (media header followed by data) to be
409                      transmitted. This parameter cannot be NULL. If HeaderSize is zero,
410                      then the media header in Buffer must already be filled in by the
411                      caller. If HeaderSize is non-zero, then the media header will be
412                      filled in by the Transmit() function.
413   @param  SrcAddr    The source HW MAC address. If HeaderSize is zero, then this parameter
414                      is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
415                      This->Mode->CurrentAddress is used for the source HW MAC address.
416   @param  DestAddr   The destination HW MAC address. If HeaderSize is zero, then this
417                      parameter is ignored.
418   @param  Protocol   The type of header to build. If HeaderSize is zero, then this
419                      parameter is ignored. See RFC 1700, section "Ether Types", for
420                      examples.
421 
422   @retval EFI_SUCCESS           The packet was placed on the transmit queue.
423   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
424   @retval EFI_ACCESS_DENIED     Error acquire global lock for operation.
425 
426 **/
427 EFI_STATUS
428 EFIAPI
429 EmuSnpTransmit(
430   IN EFI_SIMPLE_NETWORK_PROTOCOL*    This,
431   IN UINTN              HeaderSize,
432   IN UINTN              BufferSize,
433   IN VOID*              Buffer,
434   IN EFI_MAC_ADDRESS*          SrcAddr OPTIONAL,
435   IN EFI_MAC_ADDRESS*          DestAddr OPTIONAL,
436   IN UINT16*              Protocol OPTIONAL
437   );
438 
439 /**
440   Receives a packet from a network interface.
441 
442   @param  This             Protocol instance pointer.
443   @param  HeaderSize       The size, in bytes, of the media header received on the network
444                            interface. If this parameter is NULL, then the media header size
445                            will not be returned.
446   @param  BuffSize         On entry, the size, in bytes, of Buffer. On exit, the size, in
447                            bytes, of the packet that was received on the network interface.
448   @param  Buffer           A pointer to the data buffer to receive both the media header and
449                            the data.
450   @param  SourceAddr       The source HW MAC address. If this parameter is NULL, the
451                            HW MAC source address will not be extracted from the media
452                            header.
453   @param  DestinationAddr  The destination HW MAC address. If this parameter is NULL,
454                            the HW MAC destination address will not be extracted from the
455                            media header.
456   @param  Protocol         The media header type. If this parameter is NULL, then the
457                            protocol will not be extracted from the media header. See
458                            RFC 1700 section "Ether Types" for examples.
459 
460   @retval  EFI_SUCCESS           The received data was stored in Buffer, and BufferSize has
461                                  been updated to the number of bytes received.
462   @retval  EFI_NOT_READY         The network interface is too busy to accept this transmit
463                                  request.
464   @retval  EFI_BUFFER_TOO_SMALL  The BufferSize parameter is too small.
465   @retval  EFI_DEVICE_ERROR      The command could not be sent to the network interface.
466   @retval  EFI_ACCESS_DENIED     Error acquire global lock for operation.
467 
468 **/
469 EFI_STATUS
470 EFIAPI
471 EmuSnpReceive(
472   IN EFI_SIMPLE_NETWORK_PROTOCOL*    This,
473   OUT UINTN*              HeaderSize OPTIONAL,
474   IN OUT UINTN*            BuffSize,
475   OUT VOID*              Buffer,
476   OUT EFI_MAC_ADDRESS*        SourceAddr OPTIONAL,
477   OUT EFI_MAC_ADDRESS*        DestinationAddr OPTIONAL,
478   OUT UINT16*              Protocol OPTIONAL
479   );
480 
481 VOID
482 EFIAPI
483 EmuSnpWaitForPacketNotify(
484   IN EFI_EVENT            Event,
485   IN VOID*              Private
486   );
487 
488 #endif  // _EMU_SNP_H_
489