Skip to content

Commit 35db1ec

Browse files
committed
transport: storage: add nvme support
Signed-off-by: Wilfred Mallawa <wilfred.mallawa@wdc.com>
1 parent 3b4933e commit 35db1ec

File tree

7 files changed

+727
-25
lines changed

7 files changed

+727
-25
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Install dependencies
2424
run: |
2525
sudo apt-get update; \
26-
sudo apt-get install -y cmake libclang-dev libpci-dev libssl-dev python3-dev gem; \
26+
sudo apt-get install -y cmake libclang-dev libpci-dev libssl-dev python3-dev gem libnvme-dev; \
2727
sudo gem install cbor-diag;
2828
2929
- name: Build libspdm

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ std = [
3535
"inquire",
3636
"page_size",
3737
]
38-
page_size = ["dep:page_size"]
3938

4039
[lib]
4140
name = "libspdm"
@@ -75,7 +74,7 @@ minicbor-derive = { version = "0.15", features = [
7574
], optional = true }
7675
async-std = { version = "1.12", features = ["attributes"], optional = true }
7776
futures = { version = "0.3", optional = true }
78-
nix = { version = "0.29.0", features = ["user", "fs"], optional = true }
77+
nix = {version = "0.29.0", features = ["user", "fs", "ioctl"], optional = true }
7978
libmctp = { version = "0.2" }
8079
inquire = { version = "0.7.5", optional = true}
8180

build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fn main() {
2222
println!("cargo:rustc-link-arg=-Wl,--start-group");
2323

2424
println!("cargo:rustc-link-arg=-lpci");
25+
println!("cargo:rustc-link-arg=-lnvme");
2526

2627
println!("cargo:rustc-link-arg=-lmemlib");
2728
println!("cargo:rustc-link-arg=-lmalloclib");

src/main.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ pub static SOCKET_PATH: &str = "SPDM-Utils-loopback-socket";
3030
mod cli_helpers;
3131
mod doe_pci_cfg;
3232
mod io_buffers;
33+
mod nvme;
3334
mod qemu_server;
3435
mod request;
3536
mod scsi;
3637
mod socket_client;
3738
mod socket_server;
39+
mod storage_standards;
3840
mod tcg_concise_evidence_binding;
3941
mod test_suite;
4042
mod usb_i2c;
@@ -49,7 +51,15 @@ struct Args {
4951
#[arg(short, long, requires_ifs([("true", "blk_dev_path")]))]
5052
scsi: bool,
5153

52-
/// Path to the SCSI block device
54+
/// Use NVMe commands for the target device
55+
#[arg(short, long, requires_ifs([("true", "blk_dev_path")]))]
56+
nvme: bool,
57+
58+
/// NVME NameSpace Identifier
59+
#[arg(long, default_value_t = 1)]
60+
nsid: u32,
61+
62+
/// Path to the block device
5363
#[arg(long)]
5464
blk_dev_path: Option<String>,
5565

@@ -655,6 +665,9 @@ async fn main() -> Result<(), ()> {
655665
cli.scsi.then(|| {
656666
count += 1;
657667
});
668+
cli.nvme.then(|| {
669+
count += 1;
670+
});
658671
cli.doe_pci_cfg.then(|| {
659672
count += 1;
660673
});
@@ -727,12 +740,21 @@ async fn main() -> Result<(), ()> {
727740
return Err(());
728741
}
729742
scsi::register_device(cntx_ptr, &cli.blk_dev_path.clone().unwrap())?;
743+
} else if cli.nvme {
744+
if let Err(e) = nvme::nvme_get_sec_info(&cli.blk_dev_path.clone().unwrap(), cli.nsid) {
745+
if e == Errno::ENOTSUP {
746+
error!("SPDM is not supported by this NVMe device");
747+
}
748+
return Err(());
749+
}
750+
nvme::register_device(cntx_ptr, &cli.blk_dev_path.clone().unwrap(), cli.nsid).unwrap();
730751
} else if cli.qemu_server {
731752
if let Commands::Request { .. } = cli.command {
732753
error!("QEMU Server does not support running an SPDM requester");
733754
return Err(());
734755
}
735756
if let Some(proto) = cli.spdm_transport_protocol {
757+
info!("Using {:?} transport for QEMU", proto);
736758
qemu_server::register_device(cntx_ptr, cli.qemu_port, proto)?;
737759
} else {
738760
qemu_server::register_device(cntx_ptr, cli.qemu_port, spdm::TransportLayer::Doe)?;
@@ -744,14 +766,15 @@ async fn main() -> Result<(), ()> {
744766

745767
unsafe {
746768
if let Some(proto) = cli.spdm_transport_protocol {
769+
info!("Using {:?} transport", proto);
747770
spdm::setup_transport_layer(cntx_ptr, proto, spdm::LIBSPDM_MAX_SPDM_MSG_SIZE)?;
748771
} else if cli.usb_i2c {
749772
spdm::setup_transport_layer(
750773
cntx_ptr,
751774
spdm::TransportLayer::Mctp,
752775
spdm::LIBSPDM_MAX_SPDM_MSG_SIZE,
753776
)?;
754-
} else if cli.scsi {
777+
} else if cli.scsi || cli.nvme {
755778
spdm::setup_transport_layer(
756779
cntx_ptr,
757780
spdm::TransportLayer::Storage,

0 commit comments

Comments
 (0)