<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
This RFC proposes Rust API for basic DPDK port management and IO operations.</div>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
```rust</div>
<pre><div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);"><i>/// Configuration details for a DPDK port.<br>///<br>/// # Overview<br>///<br>/// `DpdkPortConf` is used to initialize and configure ports in a DPDK environment. It includes:<br>/// - Device information (`dev_info`) pulled from DPDK.<br>/// - Transmit and receive configurations, including queue settings and memory pools.<br>/// - Details about the number of queues and descriptors for transmission and reception.<br>///<br>/// This struct is typically instantiated using the [`DpdkPortConf::new_from`] method.<br>///<br>/// # Example<br>///<br>/// ```<br>/// let conf = DpdkPortConf::new_from(<br>/// port_id,<br>/// dev_conf,<br>/// tx_conf,<br>/// rx_conf,<br>/// 8, // Number of RX queues<br>/// 8, // Number of TX queues<br>/// 512, // RX descriptors<br>/// 512, // TX descriptors<br>/// 0, // RX queue socket ID<br>/// 0, // TX queue socket ID<br>/// Some(rx_mempool) // RX queue mempool<br>/// ).unwrap();<br>/// ```<br>/// <br></i>#[derive(Clone)]<br>pub struct DpdkPortConf {<br> <i>/// Information about the DPDK Ethernet device (e.g., driver, capabilities, etc.).<br> </i>pub dev_info: rte_eth_dev_info,<br><br> <i>/// Configuration for the Ethernet device. Determines the overall behavior of the device.<br> </i>pub dev_conf: rte_eth_conf,<br><br> <i>/// Configuration for transmitting (Tx) packets on the Ethernet device.<br> </i>pub tx_conf: rte_eth_txconf,<br><br> <i>/// Configuration for receiving (Rx) packets on the Ethernet device.<br> </i>pub rx_conf: rte_eth_rxconf,<br><br> <i>/// Number of receive (Rx) queues configured on this port.<br> </i>pub rxq_num: u16,<br><br> <i>/// Number of transmit (Tx) queues configured on this port.<br> </i>pub txq_num: u16,<br><br> <i>/// Number of descriptors for each transmit (Tx) queue.<br> /// Descriptors represent items in a queue to handle packets.<br> </i>pub tx_desc_num: u16,<br><br> <i>/// Number of descriptors for each receive (Rx) queue.<br> </i>pub rx_desc_num: u16,<br><br> <i>/// NUMA socket ID associated with the memory used by receive (Rx) queues.<br> </i>pub rxq_socket_id: u32,<br><br> <i>/// NUMA socket ID associated with the memory used by transmit (Tx) queues.<br> </i>pub txq_socket_id: u32,<br><br> <i>/// Memory pool associated with receive (Rx) queues.<br> /// This manages the buffers used for storing incoming packets.<br> </i>pub rxq_mempool: Option<Arc<DpdkMempool>>,<br>}</div><div class="elementToProof" style="white-space: normal; font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);"><br></div><pre><div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);"><i>/// A trait defining basic operations for managing and interacting with a DPDK port.<br>///<br>/// # Overview<br>///<br>/// The `DpdkPort` trait standardizes how to operate on DPDK ports, making it possible to:<br>/// - Configure the Ethernet device using [`configure`].<br>/// - Start the device using [`start`].<br>/// - Handle Rx and Tx bursts of packets using [`rx_burst`] and [`tx_burst`].<br>///<br></i>pub trait DpdkPort: Send + Sync {<br> <i>/// Returns the port ID of the DPDK port.<br> ///<br> /// # Return Value<br> /// A `u16` that uniquely identifies the DPDK port.<br> ///<br> /// # Example<br> /// ```<br> /// let port_id = dpdk_port.port_id();<br> /// println!("DPDK port ID: {}", port_id);<br> /// ```<br> </i>fn port_id(&self) -> u16;<br><br> <i>/// Returns a reference to the configuration object of the DPDK port.<br> ///<br> /// # Return Value<br> /// A reference to [`DpdkPortConf`], which contains various settings like Rx/Tx queue configurations,<br> /// memory pools, and NUMA socket IDs.<br> ///<br> /// # Example<br> /// ```<br> /// let port_config = dpdk_port.port_conf();<br> /// println!("Rx queues: {}", port_config.rxq_num);<br> /// ```<br> </i>fn port_conf(&self) -> &DpdkPortConf;<br><br> <i>/// Configures the DPDK Ethernet device with the settings specified in the port configuration.<br> ///<br> /// This method is typically called before starting the port to ensure it is prepared for Rx and Tx operations.<br> ///<br> /// # Return Value<br> /// - `Ok(())` if the configuration was applied successfully.<br> /// - `Err(String)` with a descriptive error message if the configuration failed.<br> ///<br> /// # Example<br> /// ```<br> /// let result = dpdk_port.configure();<br> /// if let Err(err) = result {<br> /// eprintln!("Failed to configure the port: {}", err);<br> /// }<br> /// ```<br> </i>fn configure(&mut self) -> Result<(), String>;<br><br> <i>/// Starts the DPDK Ethernet device.<br> ///<br> /// This method initializes the Rx and Tx queues, making the port ready for data transmission<br> /// and reception.<br> ///<br> /// # Return Value<br> /// - `Ok(())` if the port was started successfully.<br> /// - `Err(String)` if the startup process failed, with a descriptive error message.<br> ///<br> /// # Example<br> /// ```<br> /// let result = dpdk_port.start();<br> /// if let Err(err) = result {<br> /// eprintln!("Failed to start the port: {}", err);<br> /// }<br> /// ```<br> </i>fn start(&mut self) -> Result<(), String>;<br><br> <i>/// Receives a burst of packets on the specified Rx queue.<br> ///<br> /// # Parameters<br> /// - `queue_id`: The ID of the Rx queue to receive packets from.<br> /// - `pkts`: A mutable reference to an array of packet buffers (`*mut rte_mbuf`) where received packets<br> /// will be written.<br> ///<br> /// # Return Value<br> /// - `Ok(u16)` containing the number of packets successfully received.<br> /// - `Err(String)` if the operation failed.<br> ///<br> /// # Example<br> /// ```<br> /// let pkts: Vec<*mut rte_mbuf> = vec![std::ptr::null_mut(); 32];<br> /// let received = dpdk_port.rx_burst(0, &pkts);<br> /// match received {<br> /// Ok(count) => println!("Received {} packets", count),<br> /// Err(err) => eprintln!("Rx burst failed: {}", err),<br> /// }<br> /// ```<br> </i>fn rx_burst(&mut self, queue_id: u16, pkts: &[*mut rte_mbuf]) -> Result<u16, String>;<br><br> <i>/// Sends a burst of packets on the specified Tx queue.<br> ///<br> /// # Parameters<br> /// - `queue_id`: The ID of the Tx queue to send packets on.<br> /// - `pkts`: A reference to an array of packet buffers (`*mut rte_mbuf`) to send.<br> ///<br> /// # Return Value<br> /// - `Ok(u16)` containing the number of packets successfully sent.<br> /// - `Err(String)` if the operation failed.<br> ///<br> /// # Example<br> /// ```<br> /// let pkts: Vec<*mut rte_mbuf> = vec![some_packet_ptr1, some_packet_ptr2];<br> /// let sent = dpdk_port.tx_burst(0, &pkts);<br> /// match sent {<br> /// Ok(count) => println!("Sent {} packets", count),<br> /// Err(err) => eprintln!("Tx burst failed: {}", err),<br> /// }<br> /// ```<br> </i>fn tx_burst(&mut self, queue_id: u16, pkts: &[*mut rte_mbuf]) -> Result<u16, String>;<br>}</div></pre></pre>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
```</div>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
The API uses raw FFI pointers in DpdkPort rx_burst() and tx_burst() to preserve DPDK performance.</div>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
The API implementation is here:<br>
<br>
API definition:</div>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
<a href="https://github.com/getelson-at-mellanox/rdpdk/blob/main/lib/port/port.rs" id="LPlnk">https://github.com/getelson-at-mellanox/rdpdk/blob/main/lib/port/port.rs</a></div>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
API implementation with RTE function calls:</div>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
<a href="https://github.com/getelson-at-mellanox/rdpdk/blob/main/lib/port/raw_port.rs" id="LPlnk">https://github.com/getelson-at-mellanox/rdpdk/blob/main/lib/port/raw_port.rs</a></div>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
Implement direct calls to mlx5 Rx/Tx IO functions: </div>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
<a href="https://github.com/getelson-at-mellanox/rdpdk/blob/main/port/mlx5/mlx5_port.rs" id="LPlnk880790">https://github.com/getelson-at-mellanox/rdpdk/blob/main/port/mlx5/mlx5_port.rs</a></div>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
Signed-off-by: Gregory Etelson <getelson@nvidia.com></div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: "Aptos Mono", Aptos_EmbeddedFont, Aptos_MSFontService, monospace; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
</body>
</html>