-
-
Notifications
You must be signed in to change notification settings - Fork 170
Implement SIMPLE_NETWORK_PROTOCOL #606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8b61a4c
done with definitions of snp structs
d-sonuga ac664be
wrapped SNP functions
d-sonuga ffac49d
fixed an error in the snp code
d-sonuga bf204d7
fixed an error in the snp module
d-sonuga 1975acf
gave network statistics a better interface; refactored a little
d-sonuga 0e003b2
Clean up implementation of SNP and fix test code.
veluca93 d704933
Merge branch 'main' into snp
veluca93 56db749
Review comments.
veluca93 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use uefi::prelude::*; | ||
|
||
pub fn test(bt: &BootServices) { | ||
info!("Testing Network protocols"); | ||
|
||
pxe::test(bt); | ||
snp::test(bt); | ||
} | ||
|
||
mod pxe; | ||
mod snp; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
use uefi::prelude::BootServices; | ||
use uefi::proto::network::snp::{InterruptStatus, ReceiveFlags, SimpleNetwork}; | ||
use uefi::proto::network::MacAddress; | ||
use uefi::Status; | ||
|
||
pub fn test(bt: &BootServices) { | ||
info!("Testing the simple network protocol"); | ||
|
||
let handles = bt.find_handles::<SimpleNetwork>().unwrap_or_default(); | ||
|
||
for handle in handles { | ||
let simple_network = bt.open_protocol_exclusive::<SimpleNetwork>(handle); | ||
if simple_network.is_err() { | ||
continue; | ||
} | ||
let simple_network = simple_network.unwrap(); | ||
|
||
// Check shutdown | ||
simple_network | ||
.shutdown() | ||
.expect("Failed to shutdown Simple Network"); | ||
|
||
// Check stop | ||
simple_network | ||
.stop() | ||
.expect("Failed to stop Simple Network"); | ||
|
||
// Check start | ||
simple_network | ||
.start() | ||
.expect("Failed to start Simple Network"); | ||
|
||
// Check initialize | ||
simple_network | ||
.initialize(0, 0) | ||
.expect("Failed to initialize Simple Network"); | ||
|
||
simple_network.reset_statistics().unwrap(); | ||
|
||
// Reading the interrupt status clears it | ||
simple_network.get_interrupt_status().unwrap(); | ||
|
||
// Set receive filters | ||
simple_network | ||
.receive_filters( | ||
ReceiveFlags::UNICAST | ReceiveFlags::MULTICAST | ReceiveFlags::BROADCAST, | ||
ReceiveFlags::empty(), | ||
false, | ||
None, | ||
) | ||
.expect("Failed to set receive filters"); | ||
|
||
// Check media | ||
if !simple_network.mode().media_present_supported || !simple_network.mode().media_present { | ||
continue; | ||
} | ||
|
||
let payload = b"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\ | ||
\x45\x00\ | ||
\x00\x21\ | ||
\x00\x01\ | ||
\x00\x00\ | ||
\x10\ | ||
\x11\ | ||
\x07\x6a\ | ||
\xc0\xa8\x11\x0f\ | ||
\xc0\xa8\x11\x02\ | ||
\x54\x45\ | ||
\x54\x44\ | ||
\x00\x0d\ | ||
\xa9\xe4\ | ||
\x04\x01\x02\x03\x04"; | ||
|
||
let dest_addr = MacAddress([0xffu8; 32]); | ||
assert!(!simple_network | ||
.get_interrupt_status() | ||
.unwrap() | ||
.contains(InterruptStatus::TRANSMIT)); | ||
|
||
// Send the frame | ||
simple_network | ||
.transmit( | ||
simple_network.mode().media_header_size as usize, | ||
payload, | ||
None, | ||
Some(dest_addr), | ||
Some(0x0800), | ||
) | ||
.expect("Failed to transmit frame"); | ||
|
||
info!("Waiting for the transmit"); | ||
while !simple_network | ||
.get_interrupt_status() | ||
.unwrap() | ||
.contains(InterruptStatus::TRANSMIT) | ||
{} | ||
|
||
// Attempt to receive a frame | ||
let mut buffer = [0u8; 1500]; | ||
|
||
info!("Waiting for the reception"); | ||
if simple_network.receive(&mut buffer, None, None, None, None) | ||
== Err(Status::NOT_READY.into()) | ||
{ | ||
bt.stall(1_000_000); | ||
|
||
simple_network | ||
.receive(&mut buffer, None, None, None, None) | ||
.unwrap(); | ||
} | ||
|
||
assert_eq!(buffer[42..47], [4, 4, 3, 2, 1]); | ||
|
||
// Get stats | ||
let stats = simple_network | ||
.collect_statistics() | ||
.expect("Failed to collect statistics"); | ||
info!("Stats: {:?}", stats); | ||
|
||
// One frame should have been transmitted and one received | ||
assert_eq!(stats.tx_total_frames().unwrap(), 1); | ||
assert_eq!(stats.rx_total_frames().unwrap(), 1); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we could use the
wait_for_packet
here. I recall from the last PR attempting this that we couldn't get that event to fire... any idea what the problem could be there?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This event didn't seem to fire on QEMU at all, despite the packet being received. I thought I was doing something wrong, but if with the same code I try to wait for a wait_for_key event, that event resolves fine...
At this point, I think either the QEMU/OVMF implementation and the EFI spec disagree, QEMU doesn't implement this event for whatever reason (I found this thread from 10 years ago that seems to imply that the event not being implemented is fairly common, but I am not sure how I would verify), or there was something else wrong with my code that I don't undersand. ~30m of digging got me nowhere last time I tried.
This is also why the event is not exposed, since I haven't managed to get it to work :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dug around in the EDK2 and OVMF source a bit but don't have much to add. It does look like the
WaitForPacket
Event and all related machinery have been implemented for at least thevirtio-net-pci
driver in QEMU. However, even while using this driver, the event never seems to be signaled.I'll try to plug gdb into qemu tomorrow and see what might be going on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend exposing it anyway; it may well work on some non-QEMU/EDK2 environments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I exposed it with a comment that cautions the user to check before using it :)