Skip to content

Commit 67fcb71

Browse files
committed
nvme: mi: Convert PortInformationResponse to FlagSet
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
1 parent 3a4569c commit 67fcb71

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

src/nvme/mi.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,14 +603,14 @@ struct NvmSubsystemInformationResponse {
603603
impl Encode<32> for NvmSubsystemInformationResponse {}
604604

605605
// MI v2.0, 5.7.2, Figure 114, PRTTYP
606-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
606+
#[derive(Clone, Copy, Debug, DekuRead, DekuWrite, PartialEq, Eq)]
607+
#[deku(ctx = "endian: Endian", endian = "endian", id_type = "u8")]
607608
#[repr(u8)]
608609
pub enum PortType {
609610
Inactive = 0x00,
610611
Pcie = 0x01,
611612
TwoWire = 0x02,
612613
}
613-
unsafe impl Discriminant<u8> for PortType {}
614614

615615
impl From<&crate::PortType> for PortType {
616616
fn from(value: &crate::PortType) -> Self {
@@ -622,12 +622,20 @@ impl From<&crate::PortType> for PortType {
622622
}
623623
}
624624

625+
// MI v2.0, 5.7.2, Figure 114, PRTCAP
626+
flags! {
627+
enum PortCapabilityFlags: u8 {
628+
Ciaps,
629+
Aems,
630+
}
631+
}
632+
625633
// MI v2.0, 5.7.2, Figure 114
626634
#[derive(Debug, DekuWrite)]
627635
#[deku(endian = "little")]
628636
struct PortInformationResponse {
629-
prttyp: u8,
630-
prtcap: u8,
637+
prttyp: PortType,
638+
prtcap: WireFlagSet<PortCapabilityFlags>,
631639
mmtus: u16,
632640
mebs: u32,
633641
}

src/nvme/mi/dev.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use heapless::Vec;
88
use log::debug;
99
use mctp::{AsyncRespChannel, MsgIC};
1010

11+
use crate::nvme::mi::PortCapabilityFlags;
1112
use crate::{
1213
CommandEffect, CommandEffectError, Controller, ControllerError, ControllerType, Discriminant,
1314
MAX_CONTROLLERS, MAX_NAMESPACES, NamespaceId, NamespaceIdDisposition, SubsystemError,
@@ -635,9 +636,21 @@ impl RequestHandler for NvmeMiDataStructureRequest {
635636
return Err(ResponseStatus::InvalidParameter);
636637
};
637638
let pi = PortInformationResponse {
638-
// FIXME: Change prttyp to crate::nvme::mi::PortType
639-
prttyp: Into::<crate::nvme::mi::PortType>::into(&port.typ).id(),
640-
prtcap: (port.caps.aems as u8) << 1 | (port.caps.ciaps as u8),
639+
prttyp: Into::<crate::nvme::mi::PortType>::into(&port.typ),
640+
prtcap: {
641+
let mut flags = FlagSet::empty();
642+
643+
if port.caps.ciaps {
644+
flags |= PortCapabilityFlags::Ciaps;
645+
}
646+
647+
if port.caps.aems {
648+
flags |= PortCapabilityFlags::Aems;
649+
}
650+
651+
flags
652+
}
653+
.into(),
641654
mmtus: port.mmtus,
642655
mebs: port.mebs,
643656
}

0 commit comments

Comments
 (0)