-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Mux, transport binding and ctrl msg handling layers of MCTP capsu…
…le (#36) This PR adds the basic structure for the Mux MCTP driver layer, the transport binding layer, and the handling of MCTP control messages. At this stage, the code remains untested, and the modules have yet to be instantiated. The implementation includes the Set EID and Get EID commands, with plan to add other mandatory managed MCTP device commands once the basic commands have been tested and validated.
- Loading branch information
Showing
14 changed files
with
1,215 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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,15 @@ | ||
# Licensed under the Apache-2.0 license | ||
|
||
[package] | ||
name = "capsules-runtime" | ||
version.workspace = true | ||
authors.workspace = true | ||
edition.workspace = true | ||
|
||
[dependencies] | ||
kernel = { git = "https://github.com/tock/tock.git", rev = "b128ae817b86706c8c4e39d27fae5c54b98659f1" } | ||
|
||
capsules-extra = { git = "https://github.com/tock/tock.git", rev = "b128ae817b86706c8c4e39d27fae5c54b98659f1" } | ||
i3c-driver.workspace = true | ||
zerocopy.workspace = true | ||
bitfield.workspace = true |
This file contains 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,6 @@ | ||
// Licensed under the Apache-2.0 license | ||
|
||
#![cfg_attr(target_arch = "riscv32", no_std)] | ||
#![forbid(unsafe_code)] | ||
|
||
pub mod mctp; |
This file contains 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,103 @@ | ||
// Licensed under the Apache-2.0 license | ||
|
||
//! This file contains the types, structs and methods associated with the | ||
//! MCTP Transport header, including getter and setter methods and encode/decode | ||
//! functionality necessary for transmission. | ||
//! | ||
use bitfield::bitfield; | ||
use zerocopy::{FromBytes, Immutable, IntoBytes}; | ||
|
||
pub const MCTP_HDR_SIZE: usize = 4; | ||
|
||
bitfield! { | ||
#[repr(C)] | ||
#[derive(Clone, FromBytes, IntoBytes, Immutable)] | ||
pub struct MCTPHeader([u8]); | ||
impl Debug; | ||
u8; | ||
rsvd, _: 4, 0; | ||
pub hdr_version, set_hdr_version: 7, 4; | ||
pub dest_eid, set_dest_eid: 15, 8; | ||
pub src_eid, set_src_eid: 23, 16; | ||
pub som, set_som: 24, 24; | ||
pub eom, set_eom: 25, 25; | ||
pub pkt_seq, set_pkt_seq: 27, 26; | ||
pub tag_owner, set_tag_owner: 28, 28; | ||
pub msg_tag, set_msg_tag: 31, 29; | ||
} | ||
|
||
impl Default for MCTPHeader<[u8; MCTP_HDR_SIZE]> { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl MCTPHeader<[u8; MCTP_HDR_SIZE]> { | ||
pub fn new() -> Self { | ||
MCTPHeader([0; MCTP_HDR_SIZE]) | ||
} | ||
|
||
#[allow(clippy::too_many_arguments)] | ||
pub fn prepare_header( | ||
&mut self, | ||
dest_eid: u8, | ||
src_eid: u8, | ||
som: u8, | ||
eom: u8, | ||
pkt_seq: u8, | ||
tag_owner: u8, | ||
msg_tag: u8, | ||
) { | ||
self.set_hdr_version(1); | ||
self.set_dest_eid(dest_eid); | ||
self.set_src_eid(src_eid); | ||
self.set_som(som); | ||
self.set_eom(eom); | ||
self.set_pkt_seq(pkt_seq); | ||
self.set_tag_owner(tag_owner); | ||
self.set_msg_tag(msg_tag); | ||
} | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub enum MessageType { | ||
MCTPControl, | ||
PLDM, | ||
SPDM, | ||
SSPDM, | ||
VendorDefinedPCI, | ||
Invalid, | ||
} | ||
|
||
impl From<u8> for MessageType { | ||
fn from(val: u8) -> MessageType { | ||
match val { | ||
0 => MessageType::MCTPControl, | ||
1 => MessageType::PLDM, | ||
5 => MessageType::SPDM, | ||
6 => MessageType::SSPDM, | ||
0x7E => MessageType::VendorDefinedPCI, | ||
_ => MessageType::Invalid, | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_mctp_header() { | ||
let mut header = MCTPHeader::new(); | ||
header.prepare_header(0x10, 0x08, 1, 1, 0, 0, 0); | ||
assert_eq!(header.hdr_version(), 1); | ||
assert_eq!(header.dest_eid(), 0x10); | ||
assert_eq!(header.src_eid(), 0x08); | ||
assert_eq!(header.som(), 1); | ||
assert_eq!(header.eom(), 1); | ||
assert_eq!(header.pkt_seq(), 0); | ||
assert_eq!(header.tag_owner(), 0); | ||
assert_eq!(header.msg_tag(), 0); | ||
} | ||
} |
Oops, something went wrong.