From: Masami Hiramatsu <masami.hiramatsu@linaro.org>
To: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: Kazuhiko Sakamoto <sakamoto.kazuhiko@socionext.com>,
Masami Hiramatsu <masami.hiramatsu@linaro.org>,
Jassi Brar <jaswinder.singh@linaro.org>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
u-boot@lists.denx.de
Subject: [PATCH 3/3] efi_selftest: Recieve the packets until the receive buffer is empty
Date: Thu, 16 Sep 2021 17:53:44 +0900 [thread overview]
Message-ID: <163178242457.65790.16820317670072849950.stgit@localhost> (raw)
In-Reply-To: <163178239865.65790.17211919979018423637.stgit@localhost>
Repeatedly receive the packets until the receive buffer is empty.
If the buffer is empty, EFI_SIMPLE_NETWORK_PROTOCOL::Receive()
returns EFI_NOT_READY. We don't need to use the wait_for_event()
every time.
Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
---
lib/efi_selftest/efi_selftest_snp.c | 67 +++++++++++++++++++----------------
1 file changed, 37 insertions(+), 30 deletions(-)
diff --git a/lib/efi_selftest/efi_selftest_snp.c b/lib/efi_selftest/efi_selftest_snp.c
index c5366c872c..818cbfcacd 100644
--- a/lib/efi_selftest/efi_selftest_snp.c
+++ b/lib/efi_selftest/efi_selftest_snp.c
@@ -362,39 +362,46 @@ static int execute(void)
continue;
}
/*
- * Receive packet
+ * Receive packets until buffer is empty
*/
- buffer_size = sizeof(buffer);
- ret = net->receive(net, NULL, &buffer_size, &buffer,
- &srcaddr, &destaddr, NULL);
- if (ret != EFI_SUCCESS) {
- efi_st_error("Failed to receive packet");
- return EFI_ST_FAILURE;
+ for (;;) {
+ buffer_size = sizeof(buffer);
+ ret = net->receive(net, NULL, &buffer_size, &buffer,
+ &srcaddr, &destaddr, NULL);
+ if (ret == EFI_NOT_READY) {
+ /* The received buffer is empty. */
+ break;
+ }
+
+ if (ret != EFI_SUCCESS) {
+ efi_st_error("Failed to receive packet");
+ return EFI_ST_FAILURE;
+ }
+ /*
+ * Check the packet is meant for this system.
+ * Unfortunately QEMU ignores the broadcast flag.
+ * So we have to check for broadcasts too.
+ */
+ if (memcmp(&destaddr, &net->mode->current_address, ARP_HLEN) &&
+ memcmp(&destaddr, BROADCAST_MAC, ARP_HLEN))
+ continue;
+ /*
+ * Check this is a DHCP reply
+ */
+ if (buffer.p.eth_hdr.et_protlen != ntohs(PROT_IP) ||
+ buffer.p.ip_udp.ip_hl_v != 0x45 ||
+ buffer.p.ip_udp.ip_p != IPPROTO_UDP ||
+ buffer.p.ip_udp.udp_src != ntohs(67) ||
+ buffer.p.ip_udp.udp_dst != ntohs(68) ||
+ buffer.p.dhcp_hdr.op != BOOTREPLY)
+ continue;
+ /*
+ * We successfully received a DHCP reply.
+ */
+ goto received;
}
- /*
- * Check the packet is meant for this system.
- * Unfortunately QEMU ignores the broadcast flag.
- * So we have to check for broadcasts too.
- */
- if (memcmp(&destaddr, &net->mode->current_address, ARP_HLEN) &&
- memcmp(&destaddr, BROADCAST_MAC, ARP_HLEN))
- continue;
- /*
- * Check this is a DHCP reply
- */
- if (buffer.p.eth_hdr.et_protlen != ntohs(PROT_IP) ||
- buffer.p.ip_udp.ip_hl_v != 0x45 ||
- buffer.p.ip_udp.ip_p != IPPROTO_UDP ||
- buffer.p.ip_udp.udp_src != ntohs(67) ||
- buffer.p.ip_udp.udp_dst != ntohs(68) ||
- buffer.p.dhcp_hdr.op != BOOTREPLY)
- continue;
- /*
- * We successfully received a DHCP reply.
- */
- break;
}
-
+received:
/*
* Write a log message.
*/
next prev parent reply other threads:[~2021-09-16 8:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-16 8:53 [PATCH 0/3] efi_selftest: Update SIMPLE_NETWORK_PROTOCOL selftest Masami Hiramatsu
2021-09-16 8:53 ` [PATCH 1/3] efi_selftest: Use EFI_SIMPLE_NETWORK_PROTOCOL::GetStatus() for media check Masami Hiramatsu
2021-09-16 8:53 ` [PATCH 2/3] efi_selftest: Do not check EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT Masami Hiramatsu
2021-09-16 9:30 ` Heinrich Schuchardt
2021-09-16 9:57 ` Masami Hiramatsu
2021-09-16 8:53 ` Masami Hiramatsu [this message]
2021-09-16 9:29 ` [PATCH 3/3] efi_selftest: Recieve the packets until the receive buffer is empty Heinrich Schuchardt
2021-09-16 10:05 ` Masami Hiramatsu
2021-09-17 3:54 ` [PATCH 0/3] efi_selftest: Update SIMPLE_NETWORK_PROTOCOL selftest Heinrich Schuchardt
2021-09-17 4:47 ` Masami Hiramatsu
2021-10-04 5:08 ` Masami Hiramatsu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=163178242457.65790.16820317670072849950.stgit@localhost \
--to=masami.hiramatsu@linaro.org \
--cc=ilias.apalodimas@linaro.org \
--cc=jaswinder.singh@linaro.org \
--cc=sakamoto.kazuhiko@socionext.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox