Skip to content

Commit 4acfe0a

Browse files
committed
pldm: Add support for reading file data from remote PDR
Add the pldm-platform crate, and query the PDR for the file identifier and size. We expect the file PDR as entry 1. Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
1 parent c8dce06 commit 4acfe0a

4 files changed

Lines changed: 52 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1111
1. Added support for NVMe-MI responder, gated on a new `nvme-mi` cargo feature
1212

1313
2. Added support for a PLDM for File Transfer requester, triggered on MCTP
14-
address assignment.
14+
address assignment. This performs a PLDM PDR query to retrieve the
15+
File Identifier to transfer.
1516

1617
### Changed
1718

Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ categories = ["network-programming", "hardware-support"]
99

1010
[features]
1111
nvme-mi = ["dep:nvme-mi-dev"]
12-
pldm = ["dep:pldm", "dep:pldm-file"]
12+
pldm = ["dep:pldm", "dep:pldm-file", "dep:pldm-platform"]
1313

1414
[dependencies]
1515
anyhow = "1.0.86"
@@ -29,6 +29,7 @@ nvme-mi-dev = { git = "https://github.com/CodeConstruct/nvme-mi-dev", branch = "
2929
polling = "3.7.4"
3030
pldm = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "851360ed19ef78f2e7672daa90900cb4f38ad0b6", package = "pldm", optional = true }
3131
pldm-file = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "851360ed19ef78f2e7672daa90900cb4f38ad0b6", package = "pldm-file", optional = true }
32+
pldm-platform = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "851360ed19ef78f2e7672daa90900cb4f38ad0b6", package = "pldm-platform", optional = true }
3233
simplelog = "0.12.2"
3334
smol = "2.0.0"
3435
usbredirparser = { git = "https://github.com/CodeConstruct/usbredir-rs", branch = "main", package = "usbredirparser" }

src/pldm.rs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-3.0
22

3-
use anyhow::{Context, Result};
3+
use anyhow::{bail, Context, Result};
44
use log::{debug, info, warn};
55

66
use mctp_estack::{control::ControlEvent, router::Router};
@@ -9,6 +9,7 @@ use pldm_file::{
99
client::{df_close, df_open, df_read_with},
1010
proto::{DfCloseAttributes, DfOpenAttributes, FileIdentifier},
1111
};
12+
use pldm_platform::{proto::PdrRecord, requester as platrq};
1213

1314
async fn pldm_control(chan: &mut impl mctp::AsyncReqChannel) -> Result<()> {
1415
let req_types = [pldm_file::PLDM_TYPE_FILE_TRANSFER];
@@ -25,27 +26,53 @@ async fn pldm_control(chan: &mut impl mctp::AsyncReqChannel) -> Result<()> {
2526
}
2627

2728
async fn pldm_pdr(
28-
mut _chan: &mut impl mctp::AsyncReqChannel,
29+
chan: &mut impl mctp::AsyncReqChannel,
2930
) -> Result<(FileIdentifier, usize)> {
30-
Ok((FileIdentifier(0), 4096))
31+
// PDR Repository Info
32+
let pdr_info = platrq::get_pdr_repository_info(chan)
33+
.await
34+
.context("Get PDR Repository Info failed")?;
35+
36+
debug!("PDR Repository Info: {pdr_info:?}");
37+
38+
// File Descriptor PDR
39+
let pdr_record = 1;
40+
let pdr = platrq::get_pdr(chan, pdr_record)
41+
.await
42+
.context("Get PDR failed")?;
43+
44+
let PdrRecord::FileDescriptor(file) = pdr else {
45+
bail!("Unexpected PDR record {pdr_record}: {pdr:?}");
46+
};
47+
48+
debug!("PDR: {file:?}");
49+
50+
Ok((
51+
FileIdentifier(file.file_identifier),
52+
file.file_max_size as usize,
53+
))
3154
}
3255

3356
async fn pldm_file(
3457
chan: &mut impl mctp::AsyncReqChannel,
3558
file: FileIdentifier,
36-
_size: usize,
59+
size: usize,
3760
) -> Result<()> {
3861
let attrs = DfOpenAttributes::empty();
3962
let fd = df_open(chan, file, attrs).await.context("DfOpen failed")?;
4063

4164
debug!("Open: {fd:?}");
4265

4366
let mut buf = Vec::new();
44-
let req_len = 4096;
67+
let req_len = size;
4568

4669
debug!("Reading...");
4770
let res = df_read_with(chan, fd, 0, req_len, |part| {
48-
debug!(" {} bytes", part.len());
71+
debug!(
72+
" {} bytes, {}/{req_len}",
73+
part.len(),
74+
buf.len() + part.len()
75+
);
4976
if buf.len() + part.len() > req_len {
5077
warn!(" data overflow!");
5178
Err(PldmError::NoSpace)

0 commit comments

Comments
 (0)