EmuSnpDxe.h 19 KB

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