@@ -13,6 +13,7 @@ cfg_if::cfg_if! {
13
13
use alloc:: boxed:: Box ;
14
14
use alloc:: vec:: Vec ;
15
15
use core:: mem:: { MaybeUninit , transmute} ;
16
+ use core:: str:: FromStr ;
16
17
17
18
use smallvec:: SmallVec ;
18
19
use smoltcp:: phy:: { Checksum , ChecksumCapabilities } ;
@@ -59,15 +60,24 @@ fn determine_mtu(dev_cfg: &NetDevCfg) -> u16 {
59
60
}
60
61
}
61
62
62
- fn determine_buf_size ( dev_cfg : & NetDevCfg ) -> u32 {
63
+ fn determine_rx_buf_size ( dev_cfg : & NetDevCfg ) -> u32 {
63
64
// See Virtio specification v1.1 - 5.1.6.3.1 and 5.1.4.2
64
65
65
66
// Our desired minimum buffer size - we want it to be at least the MTU generally
66
67
let mut min_buf_size = determine_mtu ( dev_cfg) . into ( ) ;
67
68
68
69
// If VIRTIO_NET_F_MRG_RXBUF is negotiated, each buffer MUST be at least the size of the struct virtio_net_hdr.
69
70
// We just use MTU in that case, but otherwise...
70
- if !dev_cfg. features . contains ( virtio:: net:: F :: MRG_RXBUF ) {
71
+ if dev_cfg. features . contains ( virtio:: net:: F :: MRG_RXBUF )
72
+ && let Some ( my_mrg_rxbuf_size) = hermit_var ! ( "HERMIT_MRG_RXBUF_SIZE" )
73
+ {
74
+ let my_mrg_rxbuf_size = u32:: from_str ( & my_mrg_rxbuf_size) . unwrap ( ) ;
75
+ assert ! (
76
+ my_mrg_rxbuf_size > 0 ,
77
+ "VIRTIO does not allow buffer elements of size 0."
78
+ ) ;
79
+ min_buf_size = my_mrg_rxbuf_size;
80
+ } else {
71
81
// If [...] are negotiated, the driver SHOULD populate the receive queue(s) with buffers of at least 65562 bytes.
72
82
if dev_cfg. features . contains ( virtio:: net:: F :: GUEST_TSO4 )
73
83
|| dev_cfg. features . contains ( virtio:: net:: F :: GUEST_TSO6 )
@@ -92,7 +102,7 @@ impl RxQueues {
92
102
pub fn new ( vqs : Vec < VirtQueue > , dev_cfg : & NetDevCfg ) -> Self {
93
103
Self {
94
104
vqs,
95
- buf_size : determine_buf_size ( dev_cfg) ,
105
+ buf_size : determine_rx_buf_size ( dev_cfg) ,
96
106
}
97
107
}
98
108
@@ -167,7 +177,7 @@ impl TxQueues {
167
177
pub fn new ( vqs : Vec < VirtQueue > , dev_cfg : & NetDevCfg ) -> Self {
168
178
Self {
169
179
vqs,
170
- buf_size : determine_buf_size ( dev_cfg) ,
180
+ buf_size : determine_mtu ( dev_cfg) . into ( ) ,
171
181
}
172
182
}
173
183
0 commit comments