intel82599_hal/
lib.rs

1#![no_std]
2#![allow(dead_code)]
3
4pub(crate) mod regs;
5pub(crate) mod descriptors;
6pub(crate) mod transmit_head_wb;
7
8use bitflags::bitflags;
9use static_assertions::*;
10use num_enum::TryFromPrimitive;
11
12/*** Hardware Device Parameters of the Intel 82599 NIC (taken from the datasheet) ***/
13
14/// The maximum number of receive descriptors per queue.
15/// This is the maximum value that has been tested for the 82599 device.
16pub(crate) const IXGBE_MAX_RX_DESC: u16            = 8192;
17/// The maximum number of transmit descriptors per queue.
18/// This is the maximum value that has been tested for the 82599 device.
19pub(crate) const IXGBE_MAX_TX_DESC: u16            = 8192;
20/// The maximum number of rx queues available on this NIC. 
21pub(crate) const IXGBE_MAX_RX_QUEUES: u8           = 128;
22/// The maximum number of tx queues available on this NIC.
23pub(crate) const IXGBE_MAX_TX_QUEUES: u8           = 128;
24/// The number of l34 5-tuple filters.
25pub(crate) const NUM_L34_5_TUPLE_FILTERS: usize    = 128; 
26
27
28/// Possible link speeds of the 82599 NIC
29#[derive(PartialEq)]
30pub enum LinkSpeedMbps {
31    LS100 = 100,
32    LS1000 = 1000,
33    LS10000 = 10000, 
34    LSUnknown = 0,
35}
36
37impl LinkSpeedMbps {
38    /// Converts between a u32 and a LinkSpeedMbps enum.
39    /// The u32 number is the value in the links register that represents the link speed.
40    pub(crate) fn from_links_register_value(value: u32) -> LinkSpeedMbps {
41        if value == (1 << 28) {
42            Self::LS100
43        } else if value == (2 << 28) {
44            Self::LS1000
45        } else if value == (3 << 28) {
46            Self::LS10000
47        } else {
48            Self::LSUnknown
49        }
50    }
51}
52
53/// The set of receive buffer sizes that are accepted by the 82599 device.
54#[derive(Copy, Clone)]
55pub enum RxBufferSizeKiB {
56    Buffer1KiB = 1,
57    Buffer2KiB = 2,
58    Buffer3KiB = 3,
59    Buffer4KiB = 4,
60    Buffer5KiB = 5,
61    Buffer6KiB = 6,
62    Buffer7KiB = 7,
63    Buffer8KiB = 8,
64    Buffer9KiB = 9,
65    Buffer10KiB = 10,
66    Buffer11KiB = 11,
67    Buffer12KiB = 12,
68    Buffer13KiB = 13,
69    Buffer14KiB = 14,
70    Buffer15KiB = 15,
71    Buffer16KiB = 16
72}
73
74
75#[derive(Copy, Clone)]
76pub enum NumDesc {
77    Descs16 = 16,
78    Descs512 = 512,
79    Descs1k = 1024,
80    Descs2k = 2048,
81    Descs4k = 4096,
82    Descs8k = 8192
83}
84
85bitflags! {
86    /// A number that can take any value ranging in 7 bits
87    pub struct U7: u8 {
88        const B6      = 1 << 6;
89        const B5      = 1 << 5;
90        const B4      = 1 << 4;
91        const B3      = 1 << 3;
92        const B2      = 1 << 2;
93        const B1      = 1 << 1;
94        const B0      = 1 << 0;
95    }
96}
97
98
99// Ensure that we never expose bit 7 as part of the `U7` interface.
100const_assert_eq!(U7::all().bits() & 0x80, 0);
101
102impl U7 {
103    pub const fn zero() -> U7 {
104        U7::from_bits_truncate(0)
105    }
106}
107
108bitflags! {
109    /// A number that can take any value ranging in 7 bits except 0
110    pub struct HThresh: u8 {
111        const B6      = 1 << 6;
112        const B5      = 1 << 5;
113        const B4      = 1 << 4;
114        const B3      = 1 << 3;
115        const B2      = 1 << 2;
116        const B1      = 1 << 1;
117        const B0      = 1 << 0;
118    }
119}
120
121// Ensure that we never expose bit 7 as part of the `U7` interface.
122const_assert_eq!(HThresh::all().bits() & 0x80, 0);
123
124pub enum DescType {
125    Legacy,
126    AdvDesc1Buf,
127    // AdvDescHeadSplit,
128    // AdvDescHeadSplitAlways,
129}
130
131
132/***** For Filters *****/
133
134/// The list of valid filter priority levels that can be used for the L5 filters. They range from (0,7).
135#[repr(u8)]
136#[derive(PartialEq, Eq, Clone, Copy)]
137pub enum L5FilterPriority {
138    P0,
139    P1,
140    P2,
141    P3,
142    P4,
143    P5,
144    P6,
145    P7
146}
147
148/// Options for the filter protocol used in the 5-tuple filters.
149#[derive(PartialEq, Eq, Clone, Copy)]
150pub enum L5FilterProtocol {
151    Tcp = 0,
152    Udp = 1,
153    Sctp = 2,
154    Other = 3
155}
156
157#[derive(Copy, Clone, Debug, TryFromPrimitive)]
158#[repr(usize)]
159pub enum L5FilterID {
160    F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, 
161    F10, F11, F12, F13, F14, F15, F16, F17, F18, F19,
162    F20, F21, F22, F23, F24, F25, F26, F27, F28, F29, 
163    F30, F31, F32, F33, F34, F35, F36, F37, F38, F39, 
164    F40, F41, F42, F43, F44, F45, F46, F47, F48, F49, 
165    F50, F51, F52, F53, F54, F55, F56, F57, F58, F59, 
166    F60, F61, F62, F63, F64, F65, F66, F67, F68, F69, 
167    F70, F71, F72, F73, F74, F75, F76, F77, F78, F79, 
168    F80, F81, F82, F83, F84, F85, F86, F87, F88, F89, 
169    F90, F91, F92, F93, F94, F95, F96, F97, F98, F99, 
170    F100, F101, F102, F103, F104, F105, F106, F107, F108, F109, 
171    F110, F111, F112, F113, F114, F115, F116, F117, F118, F119, 
172    F120, F121, F122, F123, F124, F125, F126, F127, 
173}
174
175bitflags! {
176    // If a bit is set, then it is NOT used in the comparison
177    pub struct L5FilterMaskFlags: u32 {
178        const SOURCE_ADDRESS            = 1 << 25;
179        const DESTINATION_ADDRESS       = 1 << 26;
180        const SOURCE_PORT               = 1 << 27;
181        const DESTINATION_PORT          = 1 << 28;
182        const PROTOCOL                  = 1 << 29;
183    }
184}
185
186impl L5FilterMaskFlags {
187    pub const fn zero() -> L5FilterMaskFlags {
188        L5FilterMaskFlags::from_bits_truncate(0)
189    }
190}
191
192// Ensure that we never expose bits besides [29:25] as part of the `L5FilterMaskFlags` interface.
193const_assert_eq!(L5FilterMaskFlags::all().bits() & 0xC1FF_FFFF, 0);
194
195
196
197/***** For RSS *****/
198
199#[derive(Copy, Clone, Debug, TryFromPrimitive)]
200#[repr(usize)]
201pub enum RedirectionTableReg {
202    R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, 
203    R10, R11, R12, R13, R14, R15, R16, R17, R18, R19,
204    R20, R21, R22, R23, R24, R25, R26, R27, R28, R29, 
205    R30, R31
206}
207
208bitflags! {
209    // The fields that should be used to calculate the hash
210    pub struct RSSFieldFlags: u32 {
211        const TCP_IPV4      = 1 << 16;
212        const IPV4          = 1 << 17;
213        const IPV6          = 1 << 20;
214        const TCP_IPV6      = 1 << 21;
215        const UDP_IPV4      = 1 << 22;
216        const UDP_IPV6      = 1 << 23;
217    }
218}
219
220// Ensure that we never expose bits besides [16:17] and [20:23] as part of the `RSSFieldFlags` interface.
221const_assert_eq!(RSSFieldFlags::all().bits() & 0xFF0C_FFFF, 0);
222
223#[cfg(not(prusti))]
224impl RSSFieldFlags {
225    pub const fn zero() -> RSSFieldFlags {
226        RSSFieldFlags::from_bits_truncate(0)
227    }
228}
229
230/// The list of valid Queues that can be used in the 82599 (0,64]
231#[repr(u8)]
232#[derive(PartialEq, Eq, Clone, Copy, TryFromPrimitive)]
233pub enum QueueID {
234    Q0,Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9,
235    Q10,Q11,Q12,Q13,Q14,Q15,Q16,Q17,Q18,Q19,
236    Q20,Q21,Q22,Q23,Q24,Q25,Q26,Q27,Q28,Q29,
237    Q30,Q31,Q32,Q33,Q34,Q35,Q36,Q37,Q38,Q39,
238    Q40,Q41,Q42,Q43,Q44,Q45,Q46,Q47,Q48,Q49,
239    Q50,Q51,Q52,Q53,Q54,Q55,Q56,Q57,Q58,Q59,
240    Q60,Q61,Q62,Q63
241}
242
243impl From<RSSQueueID> for QueueID {
244    fn from(qid: RSSQueueID) -> Self {
245        match qid {
246            RSSQueueID::Q0 => QueueID::Q0,
247            RSSQueueID::Q1 => QueueID::Q1,
248            RSSQueueID::Q2 => QueueID::Q2,
249            RSSQueueID::Q3 => QueueID::Q3,
250            RSSQueueID::Q4 => QueueID::Q4,
251            RSSQueueID::Q5 => QueueID::Q5,
252            RSSQueueID::Q6 => QueueID::Q6,
253            RSSQueueID::Q7 => QueueID::Q7,
254            RSSQueueID::Q8 => QueueID::Q8,
255            RSSQueueID::Q9 => QueueID::Q9,
256            RSSQueueID::Q10 => QueueID::Q10,
257            RSSQueueID::Q11 => QueueID::Q11,
258            RSSQueueID::Q12 => QueueID::Q12,
259            RSSQueueID::Q13 => QueueID::Q13,
260            RSSQueueID::Q14 => QueueID::Q14,
261            RSSQueueID::Q15 => QueueID::Q15,
262        }
263    }
264}
265
266/// The list of valid Queues that can be used in the 82599 (0,64]
267#[repr(u8)]
268#[derive(PartialEq, Eq, Clone, Copy, TryFromPrimitive)]
269pub enum RSSQueueID {
270    Q0,Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9,
271    Q10,Q11,Q12,Q13,Q14,Q15
272}
273
274impl From<QueueID> for RSSQueueID {
275    fn from(qid: QueueID) -> Self {
276        match qid {
277            QueueID::Q0 => RSSQueueID::Q0,
278            QueueID::Q1 => RSSQueueID::Q1,
279            QueueID::Q2 => RSSQueueID::Q2,
280            QueueID::Q3 => RSSQueueID::Q3,
281            QueueID::Q4 => RSSQueueID::Q4,
282            QueueID::Q5 => RSSQueueID::Q5,
283            QueueID::Q6 => RSSQueueID::Q6,
284            QueueID::Q7 => RSSQueueID::Q7,
285            QueueID::Q8 => RSSQueueID::Q8,
286            QueueID::Q9 => RSSQueueID::Q9,
287            QueueID::Q10 => RSSQueueID::Q10,
288            QueueID::Q11 => RSSQueueID::Q11,
289            QueueID::Q12 => RSSQueueID::Q12,
290            QueueID::Q13 => RSSQueueID::Q13,
291            QueueID::Q14 => RSSQueueID::Q14,
292            QueueID::Q15 => RSSQueueID::Q15,
293            _ => panic!("Invalid QueueID for RSSQueueID conversion")
294        }
295    }
296}