MnpMain.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. /** @file
  2. Implementation of Managed Network Protocol public services.
  3. Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "MnpImpl.h"
  7. /**
  8. Returns the operational parameters for the current MNP child driver. May also
  9. support returning the underlying SNP driver mode data.
  10. The GetModeData() function is used to read the current mode data (operational
  11. parameters) from the MNP or the underlying SNP.
  12. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
  13. @param[out] MnpConfigData Pointer to storage for MNP operational parameters. Type
  14. EFI_MANAGED_NETWORK_CONFIG_DATA is defined in "Related
  15. Definitions" below.
  16. @param[out] SnpModeData Pointer to storage for SNP operational parameters. This
  17. feature may be unsupported. Type EFI_SIMPLE_NETWORK_MODE
  18. is defined in the EFI_SIMPLE_NETWORK_PROTOCOL.
  19. @retval EFI_SUCCESS The operation completed successfully.
  20. @retval EFI_INVALID_PARAMETER This is NULL.
  21. @retval EFI_UNSUPPORTED The requested feature is unsupported in this
  22. MNP implementation.
  23. @retval EFI_NOT_STARTED This MNP child driver instance has not been
  24. configured. The default values are returned in
  25. MnpConfigData if it is not NULL.
  26. @retval Others The mode data could not be read.
  27. **/
  28. EFI_STATUS
  29. EFIAPI
  30. MnpGetModeData (
  31. IN EFI_MANAGED_NETWORK_PROTOCOL *This,
  32. OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,
  33. OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL
  34. )
  35. {
  36. MNP_INSTANCE_DATA *Instance;
  37. EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
  38. EFI_TPL OldTpl;
  39. EFI_STATUS Status;
  40. UINT32 InterruptStatus;
  41. if (This == NULL) {
  42. return EFI_INVALID_PARAMETER;
  43. }
  44. Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
  45. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  46. if (MnpConfigData != NULL) {
  47. //
  48. // Copy the instance configuration data.
  49. //
  50. CopyMem (MnpConfigData, &Instance->ConfigData, sizeof (*MnpConfigData));
  51. }
  52. if (SnpModeData != NULL) {
  53. //
  54. // Copy the underlayer Snp mode data.
  55. //
  56. Snp = Instance->MnpServiceData->MnpDeviceData->Snp;
  57. //
  58. // Upon successful return of GetStatus(), the Snp->Mode->MediaPresent
  59. // will be updated to reflect any change of media status
  60. //
  61. Snp->GetStatus (Snp, &InterruptStatus, NULL);
  62. CopyMem (SnpModeData, Snp->Mode, sizeof (*SnpModeData));
  63. }
  64. if (!Instance->Configured) {
  65. Status = EFI_NOT_STARTED;
  66. } else {
  67. Status = EFI_SUCCESS;
  68. }
  69. gBS->RestoreTPL (OldTpl);
  70. return Status;
  71. }
  72. /**
  73. Sets or clears the operational parameters for the MNP child driver.
  74. The Configure() function is used to set, change, or reset the operational
  75. parameters for the MNP child driver instance. Until the operational parameters
  76. have been set, no network traffic can be sent or received by this MNP child
  77. driver instance. Once the operational parameters have been reset, no more
  78. traffic can be sent or received until the operational parameters have been set
  79. again.
  80. Each MNP child driver instance can be started and stopped independently of
  81. each other by setting or resetting their receive filter settings with the
  82. Configure() function.
  83. After any successful call to Configure(), the MNP child driver instance is
  84. started. The internal periodic timer (if supported) is enabled. Data can be
  85. transmitted and may be received if the receive filters have also been enabled.
  86. Note: If multiple MNP child driver instances will receive the same packet
  87. because of overlapping receive filter settings, then the first MNP child
  88. driver instance will receive the original packet and additional instances will
  89. receive copies of the original packet.
  90. Note: Warning: Receive filter settings that overlap will consume extra
  91. processor and/or DMA resources and degrade system and network performance.
  92. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
  93. @param[in] MnpConfigData Pointer to configuration data that will be assigned
  94. to the MNP child driver instance. If NULL, the MNP
  95. child driver instance is reset to startup defaults
  96. and all pending transmit and receive requests are
  97. flushed. Type EFI_MANAGED_NETWORK_CONFIG_DATA is
  98. defined in EFI_MANAGED_NETWORK_PROTOCOL.GetModeData().
  99. @retval EFI_SUCCESS The operation completed successfully.
  100. @retval EFI_INVALID_PARAMETER One or more of the following conditions is
  101. TRUE:
  102. * This is NULL.
  103. * MnpConfigData.ProtocolTypeFilter is not
  104. valid.
  105. The operational data for the MNP child driver
  106. instance is unchanged.
  107. @retval EFI_OUT_OF_RESOURCES Required system resources (usually memory)
  108. could not be allocated.
  109. The MNP child driver instance has been reset to
  110. startup defaults.
  111. @retval EFI_UNSUPPORTED The requested feature is unsupported in
  112. this [MNP] implementation. The operational data
  113. for the MNP child driver instance is unchanged.
  114. @retval EFI_DEVICE_ERROR An unexpected network or system error
  115. occurred. The MNP child driver instance has
  116. been reset to startup defaults.
  117. @retval Others The MNP child driver instance has been reset to
  118. startup defaults.
  119. **/
  120. EFI_STATUS
  121. EFIAPI
  122. MnpConfigure (
  123. IN EFI_MANAGED_NETWORK_PROTOCOL *This,
  124. IN EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL
  125. )
  126. {
  127. MNP_INSTANCE_DATA *Instance;
  128. EFI_TPL OldTpl;
  129. EFI_STATUS Status;
  130. if ((This == NULL) ||
  131. ((MnpConfigData != NULL) &&
  132. (MnpConfigData->ProtocolTypeFilter > 0) &&
  133. (MnpConfigData->ProtocolTypeFilter <= 1500))
  134. )
  135. {
  136. return EFI_INVALID_PARAMETER;
  137. }
  138. Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
  139. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  140. if ((MnpConfigData == NULL) && (!Instance->Configured)) {
  141. //
  142. // If the instance is not configured and a reset is requested, just return.
  143. //
  144. Status = EFI_SUCCESS;
  145. goto ON_EXIT;
  146. }
  147. //
  148. // Configure the instance.
  149. //
  150. Status = MnpConfigureInstance (Instance, MnpConfigData);
  151. ON_EXIT:
  152. gBS->RestoreTPL (OldTpl);
  153. return Status;
  154. }
  155. /**
  156. Translates an IP multicast address to a hardware (MAC) multicast address. This
  157. function may be unsupported in some MNP implementations.
  158. The McastIpToMac() function translates an IP multicast address to a hardware
  159. (MAC) multicast address. This function may be implemented by calling the
  160. underlying EFI_SIMPLE_NETWORK. MCastIpToMac() function, which may also be
  161. unsupported in some MNP implementations.
  162. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
  163. @param[in] Ipv6Flag Set to TRUE to if IpAddress is an IPv6 multicast address.
  164. Set to FALSE if IpAddress is an IPv4 multicast address.
  165. @param[in] IpAddress Pointer to the multicast IP address (in network byte
  166. order) to convert.
  167. @param[out] MacAddress Pointer to the resulting multicast MAC address.
  168. @retval EFI_SUCCESS The operation completed successfully.
  169. @retval EFI_INVALID_PARAMETER One of the following conditions is TRUE:
  170. * This is NULL.
  171. * IpAddress is NULL.
  172. * IpAddress is not a valid multicast IP
  173. address.
  174. * MacAddress is NULL.
  175. @retval EFI_NOT_STARTED This MNP child driver instance has not been
  176. configured.
  177. @retval EFI_UNSUPPORTED The requested feature is unsupported in this
  178. MNP implementation.
  179. @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
  180. @retval Others The address could not be converted.
  181. **/
  182. EFI_STATUS
  183. EFIAPI
  184. MnpMcastIpToMac (
  185. IN EFI_MANAGED_NETWORK_PROTOCOL *This,
  186. IN BOOLEAN Ipv6Flag,
  187. IN EFI_IP_ADDRESS *IpAddress,
  188. OUT EFI_MAC_ADDRESS *MacAddress
  189. )
  190. {
  191. EFI_STATUS Status;
  192. MNP_INSTANCE_DATA *Instance;
  193. EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
  194. EFI_TPL OldTpl;
  195. EFI_IPv6_ADDRESS *Ip6Address;
  196. if ((This == NULL) || (IpAddress == NULL) || (MacAddress == NULL)) {
  197. return EFI_INVALID_PARAMETER;
  198. }
  199. Ip6Address = &IpAddress->v6;
  200. if ((Ipv6Flag && !IP6_IS_MULTICAST (Ip6Address)) ||
  201. (!Ipv6Flag && !IP4_IS_MULTICAST (EFI_NTOHL (*IpAddress)))
  202. )
  203. {
  204. //
  205. // The IP address passed in is not a multicast address.
  206. //
  207. return EFI_INVALID_PARAMETER;
  208. }
  209. Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
  210. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  211. if (!Instance->Configured) {
  212. Status = EFI_NOT_STARTED;
  213. goto ON_EXIT;
  214. }
  215. Snp = Instance->MnpServiceData->MnpDeviceData->Snp;
  216. ASSERT (Snp != NULL);
  217. ZeroMem (MacAddress, sizeof (EFI_MAC_ADDRESS));
  218. if (Snp->Mode->IfType == NET_IFTYPE_ETHERNET) {
  219. if (!Ipv6Flag) {
  220. //
  221. // Translate the IPv4 address into a multicast MAC address if the NIC is an
  222. // ethernet NIC according to RFC1112..
  223. //
  224. MacAddress->Addr[0] = 0x01;
  225. MacAddress->Addr[1] = 0x00;
  226. MacAddress->Addr[2] = 0x5E;
  227. MacAddress->Addr[3] = (UINT8)(IpAddress->v4.Addr[1] & 0x7F);
  228. MacAddress->Addr[4] = IpAddress->v4.Addr[2];
  229. MacAddress->Addr[5] = IpAddress->v4.Addr[3];
  230. } else {
  231. //
  232. // Translate the IPv6 address into a multicast MAC address if the NIC is an
  233. // ethernet NIC according to RFC2464.
  234. //
  235. MacAddress->Addr[0] = 0x33;
  236. MacAddress->Addr[1] = 0x33;
  237. MacAddress->Addr[2] = Ip6Address->Addr[12];
  238. MacAddress->Addr[3] = Ip6Address->Addr[13];
  239. MacAddress->Addr[4] = Ip6Address->Addr[14];
  240. MacAddress->Addr[5] = Ip6Address->Addr[15];
  241. }
  242. Status = EFI_SUCCESS;
  243. } else {
  244. //
  245. // Invoke Snp to translate the multicast IP address.
  246. //
  247. Status = Snp->MCastIpToMac (
  248. Snp,
  249. Ipv6Flag,
  250. IpAddress,
  251. MacAddress
  252. );
  253. }
  254. ON_EXIT:
  255. gBS->RestoreTPL (OldTpl);
  256. return Status;
  257. }
  258. /**
  259. Enables and disables receive filters for multicast address. This function may
  260. be unsupported in some MNP implementations.
  261. The Groups() function only adds and removes multicast MAC addresses from the
  262. filter list. The MNP driver does not transmit or process Internet Group
  263. Management Protocol (IGMP) packets. If JoinFlag is FALSE and MacAddress is
  264. NULL, then all joined groups are left.
  265. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
  266. @param[in] JoinFlag Set to TRUE to join this multicast group.
  267. Set to FALSE to leave this multicast group.
  268. @param[in] MacAddress Pointer to the multicast MAC group (address) to join or
  269. leave.
  270. @retval EFI_SUCCESS The requested operation completed successfully.
  271. @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
  272. * This is NULL.
  273. * JoinFlag is TRUE and MacAddress is NULL.
  274. * MacAddress is not a valid multicast MAC
  275. address.
  276. * The MNP multicast group settings are
  277. unchanged.
  278. @retval EFI_NOT_STARTED This MNP child driver instance has not been
  279. configured.
  280. @retval EFI_ALREADY_STARTED The supplied multicast group is already joined.
  281. @retval EFI_NOT_FOUND The supplied multicast group is not joined.
  282. @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
  283. The MNP child driver instance has been reset to
  284. startup defaults.
  285. @retval EFI_UNSUPPORTED The requested feature is unsupported in this MNP
  286. implementation.
  287. @retval Others The requested operation could not be completed.
  288. The MNP multicast group settings are unchanged.
  289. **/
  290. EFI_STATUS
  291. EFIAPI
  292. MnpGroups (
  293. IN EFI_MANAGED_NETWORK_PROTOCOL *This,
  294. IN BOOLEAN JoinFlag,
  295. IN EFI_MAC_ADDRESS *MacAddress OPTIONAL
  296. )
  297. {
  298. MNP_INSTANCE_DATA *Instance;
  299. EFI_SIMPLE_NETWORK_MODE *SnpMode;
  300. MNP_GROUP_CONTROL_BLOCK *GroupCtrlBlk;
  301. MNP_GROUP_ADDRESS *GroupAddress;
  302. LIST_ENTRY *ListEntry;
  303. BOOLEAN AddressExist;
  304. EFI_TPL OldTpl;
  305. EFI_STATUS Status;
  306. if ((This == NULL) || (JoinFlag && (MacAddress == NULL))) {
  307. //
  308. // This is NULL, or it's a join operation but MacAddress is NULL.
  309. //
  310. return EFI_INVALID_PARAMETER;
  311. }
  312. Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
  313. SnpMode = Instance->MnpServiceData->MnpDeviceData->Snp->Mode;
  314. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  315. if (!Instance->Configured) {
  316. Status = EFI_NOT_STARTED;
  317. goto ON_EXIT;
  318. }
  319. if ((!Instance->ConfigData.EnableMulticastReceive) ||
  320. ((MacAddress != NULL) && !NET_MAC_IS_MULTICAST (MacAddress, &SnpMode->BroadcastAddress, SnpMode->HwAddressSize)))
  321. {
  322. //
  323. // The instance isn't configured to do multicast receive. OR
  324. // the passed in MacAddress is not a multicast mac address.
  325. //
  326. Status = EFI_INVALID_PARAMETER;
  327. goto ON_EXIT;
  328. }
  329. Status = EFI_SUCCESS;
  330. AddressExist = FALSE;
  331. GroupCtrlBlk = NULL;
  332. if (MacAddress != NULL) {
  333. //
  334. // Search the instance's GroupCtrlBlkList to find the specific address.
  335. //
  336. NET_LIST_FOR_EACH (ListEntry, &Instance->GroupCtrlBlkList) {
  337. GroupCtrlBlk = NET_LIST_USER_STRUCT (
  338. ListEntry,
  339. MNP_GROUP_CONTROL_BLOCK,
  340. CtrlBlkEntry
  341. );
  342. GroupAddress = GroupCtrlBlk->GroupAddress;
  343. if (0 == CompareMem (
  344. MacAddress,
  345. &GroupAddress->Address,
  346. SnpMode->HwAddressSize
  347. ))
  348. {
  349. //
  350. // There is already the same multicast mac address configured.
  351. //
  352. AddressExist = TRUE;
  353. break;
  354. }
  355. }
  356. if (JoinFlag && AddressExist) {
  357. //
  358. // The multicast mac address to join already exists.
  359. //
  360. Status = EFI_ALREADY_STARTED;
  361. }
  362. if (!JoinFlag && !AddressExist) {
  363. //
  364. // The multicast mac address to leave doesn't exist in this instance.
  365. //
  366. Status = EFI_NOT_FOUND;
  367. }
  368. if (EFI_ERROR (Status)) {
  369. goto ON_EXIT;
  370. }
  371. } else if (IsListEmpty (&Instance->GroupCtrlBlkList)) {
  372. //
  373. // The MacAddress is NULL and there is no configured multicast mac address,
  374. // just return.
  375. //
  376. goto ON_EXIT;
  377. }
  378. //
  379. // OK, it is time to take action.
  380. //
  381. Status = MnpGroupOp (Instance, JoinFlag, MacAddress, GroupCtrlBlk);
  382. ON_EXIT:
  383. gBS->RestoreTPL (OldTpl);
  384. return Status;
  385. }
  386. /**
  387. Places asynchronous outgoing data packets into the transmit queue.
  388. The Transmit() function places a completion token into the transmit packet
  389. queue. This function is always asynchronous.
  390. The caller must fill in the Token.Event and Token.TxData fields in the
  391. completion token, and these fields cannot be NULL. When the transmit operation
  392. completes, the MNP updates the Token.Status field and the Token.Event is
  393. signaled.
  394. Note: There may be a performance penalty if the packet needs to be
  395. defragmented before it can be transmitted by the network device. Systems in
  396. which performance is critical should review the requirements and features of
  397. the underlying communications device and drivers.
  398. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
  399. @param[in] Token Pointer to a token associated with the transmit data
  400. descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN
  401. is defined in "Related Definitions" below.
  402. @retval EFI_SUCCESS The transmit completion token was cached.
  403. @retval EFI_NOT_STARTED This MNP child driver instance has not been
  404. configured.
  405. @retval EFI_INVALID_PARAMETER One or more of the following conditions is
  406. TRUE:
  407. * This is NULL.
  408. * Token is NULL.
  409. * Token.Event is NULL.
  410. * Token.TxData is NULL.
  411. * Token.TxData.DestinationAddress is not
  412. NULL and Token.TxData.HeaderLength is zero.
  413. * Token.TxData.FragmentCount is zero.
  414. * (Token.TxData.HeaderLength +
  415. Token.TxData.DataLength) is not equal to the
  416. sum of the
  417. Token.TxData.FragmentTable[].FragmentLength
  418. fields.
  419. * One or more of the
  420. Token.TxData.FragmentTable[].FragmentLength
  421. fields is zero.
  422. * One or more of the
  423. Token.TxData.FragmentTable[].FragmentBufferfields
  424. is NULL.
  425. * Token.TxData.DataLength is greater than MTU.
  426. @retval EFI_ACCESS_DENIED The transmit completion token is already in the
  427. transmit queue.
  428. @retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a
  429. lack of system resources (usually memory).
  430. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  431. The MNP child driver instance has been reset to
  432. startup defaults.
  433. @retval EFI_NOT_READY The transmit request could not be queued because
  434. the transmit queue is full.
  435. **/
  436. EFI_STATUS
  437. EFIAPI
  438. MnpTransmit (
  439. IN EFI_MANAGED_NETWORK_PROTOCOL *This,
  440. IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
  441. )
  442. {
  443. EFI_STATUS Status;
  444. MNP_INSTANCE_DATA *Instance;
  445. MNP_SERVICE_DATA *MnpServiceData;
  446. UINT8 *PktBuf;
  447. UINT32 PktLen;
  448. EFI_TPL OldTpl;
  449. if ((This == NULL) || (Token == NULL)) {
  450. return EFI_INVALID_PARAMETER;
  451. }
  452. Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
  453. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  454. if (!Instance->Configured) {
  455. Status = EFI_NOT_STARTED;
  456. goto ON_EXIT;
  457. }
  458. if (!MnpIsValidTxToken (Instance, Token)) {
  459. //
  460. // The Token is invalid.
  461. //
  462. Status = EFI_INVALID_PARAMETER;
  463. goto ON_EXIT;
  464. }
  465. MnpServiceData = Instance->MnpServiceData;
  466. NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);
  467. //
  468. // Build the tx packet
  469. //
  470. Status = MnpBuildTxPacket (MnpServiceData, Token->Packet.TxData, &PktBuf, &PktLen);
  471. if (EFI_ERROR (Status)) {
  472. goto ON_EXIT;
  473. }
  474. //
  475. // OK, send the packet synchronously.
  476. //
  477. Status = MnpSyncSendPacket (MnpServiceData, PktBuf, PktLen, Token);
  478. ON_EXIT:
  479. gBS->RestoreTPL (OldTpl);
  480. return Status;
  481. }
  482. /**
  483. Places an asynchronous receiving request into the receiving queue.
  484. The Receive() function places a completion token into the receive packet
  485. queue. This function is always asynchronous.
  486. The caller must fill in the Token.Event field in the completion token, and
  487. this field cannot be NULL. When the receive operation completes, the MNP
  488. updates the Token.Status and Token.RxData fields and the Token.Event is
  489. signaled.
  490. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
  491. @param[in] Token Pointer to a token associated with the receive
  492. data descriptor. Type
  493. EFI_MANAGED_NETWORK_COMPLETION_TOKEN is defined in
  494. EFI_MANAGED_NETWORK_PROTOCOL.Transmit().
  495. @retval EFI_SUCCESS The receive completion token was cached.
  496. @retval EFI_NOT_STARTED This MNP child driver instance has not been
  497. configured.
  498. @retval EFI_INVALID_PARAMETER One or more of the following conditions is
  499. TRUE:
  500. * This is NULL.
  501. * Token is NULL.
  502. * Token.Event is NULL
  503. @retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a
  504. lack of system resources (usually memory).
  505. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  506. The MNP child driver instance has been reset to
  507. startup defaults.
  508. @retval EFI_ACCESS_DENIED The receive completion token was already in the
  509. receive queue.
  510. @retval EFI_NOT_READY The receive request could not be queued because
  511. the receive queue is full.
  512. **/
  513. EFI_STATUS
  514. EFIAPI
  515. MnpReceive (
  516. IN EFI_MANAGED_NETWORK_PROTOCOL *This,
  517. IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
  518. )
  519. {
  520. EFI_STATUS Status;
  521. MNP_INSTANCE_DATA *Instance;
  522. EFI_TPL OldTpl;
  523. if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) {
  524. return EFI_INVALID_PARAMETER;
  525. }
  526. Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
  527. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  528. if (!Instance->Configured) {
  529. Status = EFI_NOT_STARTED;
  530. goto ON_EXIT;
  531. }
  532. //
  533. // Check whether this token(event) is already in the rx token queue.
  534. //
  535. Status = NetMapIterate (&Instance->RxTokenMap, MnpTokenExist, (VOID *)Token);
  536. if (EFI_ERROR (Status)) {
  537. goto ON_EXIT;
  538. }
  539. //
  540. // Insert the Token into the RxTokenMap.
  541. //
  542. Status = NetMapInsertTail (&Instance->RxTokenMap, (VOID *)Token, NULL);
  543. if (!EFI_ERROR (Status)) {
  544. //
  545. // Try to deliver any buffered packets.
  546. //
  547. Status = MnpInstanceDeliverPacket (Instance);
  548. //
  549. // Dispatch the DPC queued by the NotifyFunction of Token->Event.
  550. //
  551. DispatchDpc ();
  552. }
  553. ON_EXIT:
  554. gBS->RestoreTPL (OldTpl);
  555. return Status;
  556. }
  557. /**
  558. Aborts an asynchronous transmit or receive request.
  559. The Cancel() function is used to abort a pending transmit or receive request.
  560. If the token is in the transmit or receive request queues, after calling this
  561. function, Token.Status will be set to EFI_ABORTED and then Token.Event will be
  562. signaled. If the token is not in one of the queues, which usually means that
  563. the asynchronous operation has completed, this function will not signal the
  564. token and EFI_NOT_FOUND is returned.
  565. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
  566. @param[in] Token Pointer to a token that has been issued by
  567. EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or
  568. EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all
  569. pending tokens are aborted.
  570. @retval EFI_SUCCESS The asynchronous I/O request was aborted and
  571. Token.Event was signaled. When Token is NULL,
  572. all pending requests were aborted and their
  573. events were signaled.
  574. @retval EFI_NOT_STARTED This MNP child driver instance has not been
  575. configured.
  576. @retval EFI_INVALID_PARAMETER This is NULL.
  577. @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O
  578. request was not found in the transmit or
  579. receive queue. It has either completed or was
  580. not issued by Transmit() and Receive().
  581. **/
  582. EFI_STATUS
  583. EFIAPI
  584. MnpCancel (
  585. IN EFI_MANAGED_NETWORK_PROTOCOL *This,
  586. IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token OPTIONAL
  587. )
  588. {
  589. EFI_STATUS Status;
  590. MNP_INSTANCE_DATA *Instance;
  591. EFI_TPL OldTpl;
  592. if (This == NULL) {
  593. return EFI_INVALID_PARAMETER;
  594. }
  595. Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
  596. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  597. if (!Instance->Configured) {
  598. Status = EFI_NOT_STARTED;
  599. goto ON_EXIT;
  600. }
  601. //
  602. // Iterate the RxTokenMap to cancel the specified Token.
  603. //
  604. Status = NetMapIterate (&Instance->RxTokenMap, MnpCancelTokens, (VOID *)Token);
  605. if (Token != NULL) {
  606. Status = (Status == EFI_ABORTED) ? EFI_SUCCESS : EFI_NOT_FOUND;
  607. }
  608. //
  609. // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
  610. //
  611. DispatchDpc ();
  612. ON_EXIT:
  613. gBS->RestoreTPL (OldTpl);
  614. return Status;
  615. }
  616. /**
  617. Polls for incoming data packets and processes outgoing data packets.
  618. The Poll() function can be used by network drivers and applications to
  619. increase the rate that data packets are moved between the communications
  620. device and the transmit and receive queues.
  621. Normally, a periodic timer event internally calls the Poll() function. But, in
  622. some systems, the periodic timer event may not call Poll() fast enough to
  623. transmit and/or receive all data packets without missing packets. Drivers and
  624. applications that are experiencing packet loss should try calling the Poll()
  625. function more often.
  626. @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
  627. @retval EFI_SUCCESS Incoming or outgoing data was processed.
  628. @retval EFI_NOT_STARTED This MNP child driver instance has not been
  629. configured.
  630. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The
  631. MNP child driver instance has been reset to startup
  632. defaults.
  633. @retval EFI_NOT_READY No incoming or outgoing data was processed. Consider
  634. increasing the polling rate.
  635. @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive
  636. queue. Consider increasing the polling rate.
  637. **/
  638. EFI_STATUS
  639. EFIAPI
  640. MnpPoll (
  641. IN EFI_MANAGED_NETWORK_PROTOCOL *This
  642. )
  643. {
  644. EFI_STATUS Status;
  645. MNP_INSTANCE_DATA *Instance;
  646. EFI_TPL OldTpl;
  647. if (This == NULL) {
  648. return EFI_INVALID_PARAMETER;
  649. }
  650. Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
  651. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  652. if (!Instance->Configured) {
  653. Status = EFI_NOT_STARTED;
  654. goto ON_EXIT;
  655. }
  656. //
  657. // Try to receive packets.
  658. //
  659. Status = MnpReceivePacket (Instance->MnpServiceData->MnpDeviceData);
  660. //
  661. // Dispatch the DPC queued by the NotifyFunction of rx token's events.
  662. //
  663. DispatchDpc ();
  664. ON_EXIT:
  665. gBS->RestoreTPL (OldTpl);
  666. return Status;
  667. }