Skip to content

Commit 0c8dbd7

Browse files
committed
Update to mctp-rs 77da3b1
This pulls in CRC fixes, but we also need to update to the new Router API. This now allows us to unify the Router lifetime handling, and avoid &'a Router<'a>. Updates from Matt Johnston <[email protected]>. Signed-off-by: Jeremy Kerr <[email protected]>
1 parent fce9fbc commit 0c8dbd7

File tree

4 files changed

+42
-49
lines changed

4 files changed

+42
-49
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ futures-io = "0.3.30"
2525
hex = { version = "0.4.3", optional = true }
2626
log = "0.4.22"
2727
mctp = "0.2.0"
28-
mctp-estack = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "8051f2ee30e83efea8cadc1cfdc6d976dba41ed3", package = "mctp-estack" }
28+
mctp-estack = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "77da3b1c4d35b7c9ba37747da968d29fc4cde696", package = "mctp-estack" }
2929
nvme-mi-dev = { git = "https://github.com/CodeConstruct/nvme-mi-dev", branch = "main", optional = true }
3030
polling = "3.7.4"
31-
pldm = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "8051f2ee30e83efea8cadc1cfdc6d976dba41ed3", package = "pldm", optional = true }
32-
pldm-file = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "8051f2ee30e83efea8cadc1cfdc6d976dba41ed3", package = "pldm-file", optional = true }
33-
pldm-platform = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "8051f2ee30e83efea8cadc1cfdc6d976dba41ed3", package = "pldm-platform", optional = true }
31+
pldm = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "77da3b1c4d35b7c9ba37747da968d29fc4cde696", package = "pldm", optional = true }
32+
pldm-file = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "77da3b1c4d35b7c9ba37747da968d29fc4cde696", package = "pldm-file", optional = true }
33+
pldm-platform = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "77da3b1c4d35b7c9ba37747da968d29fc4cde696", package = "pldm-platform", optional = true }
3434
sha2 = {version = "0.10.9", optional = true }
3535
simplelog = "0.12.2"
3636
smol = "2.0.0"
@@ -39,4 +39,4 @@ uuid = { version = "1.16.0", features = ["v4"] }
3939

4040
# update nvme-mi-dev mctp dependency
4141
[patch.crates-io]
42-
mctp = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "8051f2ee30e83efea8cadc1cfdc6d976dba41ed3", package = "mctp" }
42+
mctp = { git = "https://github.com/CodeConstruct/mctp-rs", rev = "77da3b1c4d35b7c9ba37747da968d29fc4cde696", package = "mctp" }

src/main.rs

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use log::{debug, info, warn, LevelFilter};
77
use mctp::{AsyncListener, AsyncRespChannel, Eid};
88
use mctp_estack::{
99
control::{ControlEvent, MctpControl},
10-
router::{
11-
PortBottom, PortBuilder, PortId, PortLookup, PortStorage, Router,
12-
},
10+
router::{Port, PortId, PortLookup, PortTop, Router},
1311
};
1412
use std::time::Instant;
1513

@@ -81,15 +79,15 @@ struct Routes {}
8179

8280
impl PortLookup for Routes {
8381
fn by_eid(
84-
&mut self,
82+
&self,
8583
_eid: Eid,
8684
source_port: Option<PortId>,
87-
) -> Option<PortId> {
85+
) -> (Option<PortId>, Option<usize>) {
8886
// we're an endpoint device, don't forward packets from other ports
8987
if source_port.is_some() {
90-
return None;
88+
return (None, None);
9189
}
92-
Some(PortId(0))
90+
(Some(PortId(0)), None)
9391
}
9492
}
9593

@@ -101,10 +99,10 @@ async fn update_router_time(router: &Router<'_>, start_time: Instant) {
10199
}
102100
}
103101

104-
async fn run<'a>(
102+
async fn run(
105103
mut transport: Transport,
106-
mut port: PortBottom<'_>,
107-
router: &'a Router<'a>,
104+
mut port: Port<'_>,
105+
router: &Router<'_>,
108106
start_time: Instant,
109107
) -> std::io::Result<()> {
110108
let portid = PortId(0);
@@ -146,8 +144,8 @@ async fn echo<'a>(router: &'a Router<'a>) -> std::io::Result<()> {
146144
}
147145
}
148146

149-
async fn control<'a>(
150-
router: &'a Router<'a>,
147+
async fn control(
148+
router: &Router<'_>,
151149
ctrl_ev_sender: async_channel::Sender<ControlEvent>,
152150
) -> std::io::Result<()> {
153151
let mut l = router.listener(mctp::MCTP_TYPE_CONTROL)?;
@@ -183,7 +181,7 @@ async fn control<'a>(
183181
}
184182

185183
#[cfg(feature = "nvme-mi")]
186-
async fn nvme_mi<'a>(router: &'a Router<'a>) -> std::io::Result<()> {
184+
async fn nvme_mi(router: &Router<'_>) -> std::io::Result<()> {
187185
let mut l = router.listener(mctp::MCTP_TYPE_NVME)?;
188186

189187
let mut subsys = Subsystem::new(SubsystemInfo::environment());
@@ -226,16 +224,16 @@ async fn nvme_mi<'a>(router: &'a Router<'a>) -> std::io::Result<()> {
226224
}
227225
}
228226
#[cfg(not(feature = "nvme-mi"))]
229-
async fn nvme_mi<'a>(_router: &'a Router<'a>) -> std::io::Result<()> {
227+
async fn nvme_mi(_router: &Router<'_>) -> std::io::Result<()> {
230228
futures::future::pending().await
231229
}
232230

233231
#[cfg(feature = "pldm")]
234232
mod pldm;
235233
#[cfg(not(feature = "pldm"))]
236234
mod pldm {
237-
pub async fn pldm<'a>(
238-
_router: &'a super::Router<'a>,
235+
pub async fn pldm(
236+
_router: &super::Router<'_>,
239237
_recv: async_channel::Receiver<super::ControlEvent>,
240238
) -> std::io::Result<()> {
241239
futures::future::pending().await
@@ -249,36 +247,29 @@ fn main() -> Result<()> {
249247
simplelog::SimpleLogger::init(LevelFilter::Debug, conf)?;
250248

251249
let eid = Eid(0);
252-
let mtu = 68usize;
253250

254-
let mut port_storage = PortStorage::<4>::new();
255-
let mut port = PortBuilder::new(&mut port_storage);
256-
let (port_top, port_bottom) = port.build(mtu).unwrap();
257-
let ports = [port_top];
251+
let mut port_top = PortTop::new();
252+
let routes = Routes {};
253+
let mut router = Router::new(eid, &routes, 0);
254+
let port_id = router.add_port(&mut port_top)?;
255+
let port = router.port(port_id)?;
258256

259-
let start_time = Instant::now();
260-
261-
let stack = mctp_estack::Stack::new(eid, mtu, 0u64);
262-
263-
let mut routes = Routes {};
264-
let router = Router::new(stack, &ports, &mut routes);
265-
266-
let (transport, mut port) = match opts.transport {
257+
let (transport, mut t_port) = match opts.transport {
267258
TransportSubcommand::Serial(s) => {
268259
let serial = serial::MctpSerial::new(&s.tty)?;
269260
info!("Created MCTP Serial transport on {}", s.tty);
270261
let t = Transport::Serial(serial);
271262
(t, None)
272263
}
273264
TransportSubcommand::Usb(u) => {
274-
let (usbredir, port) = usbredir::MctpUsbRedir::new(&u.path)?;
265+
let (usbredir, t_port) = usbredir::MctpUsbRedir::new(&u.path)?;
275266
info!("Created MCTP USB transport on {}", u.path);
276267
let t = Transport::Usb(usbredir);
277-
(t, Some(port))
268+
(t, Some(t_port))
278269
}
279270
};
280271

281-
let fut = match port {
272+
let fut = match t_port {
282273
Some(ref mut p) => futures::future::Either::Left(p.process()),
283274
None => futures::future::Either::Right(futures::future::pending()),
284275
};
@@ -288,12 +279,13 @@ fn main() -> Result<()> {
288279
smol::block_on(async {
289280
select!(
290281
_ = fut.fuse() => (),
291-
_ = run(transport, port_bottom, &router, start_time).fuse() => (),
282+
_ = run(transport, port, &router, Instant::now()).fuse() => (),
292283
_ = control(&router, ctrl_ev_tx).fuse() => (),
293284
_ = nvme_mi(&router).fuse() => (),
294285
_ = pldm::pldm(&router, ctrl_ev_rx).fuse() => (),
295-
)
296-
});
286+
);
287+
Ok::<_, anyhow::Error>(())
288+
})?;
297289

298290
Ok(())
299291
}

src/pldm.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,11 @@ async fn pldm_session(mut chan: impl mctp::AsyncReqChannel) -> Result<()> {
120120
Ok(())
121121
}
122122

123-
pub async fn pldm<'a>(
124-
router: &'a Router<'a>,
123+
pub async fn pldm(
124+
router: &Router<'_>,
125125
ctrl_ev_receiver: async_channel::Receiver<ControlEvent>,
126126
) -> std::io::Result<()> {
127+
info!("PLDM handler started");
127128
loop {
128129
let peer = loop {
129130
let res = ctrl_ev_receiver.recv().await;

0 commit comments

Comments
 (0)