Skip to content

Commit 208d754

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

3 files changed

Lines changed: 24 additions & 36 deletions

File tree

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,13 +439,14 @@ impl Controller {
439439

440440
#[derive(Debug)]
441441
struct SubsystemHealth {
442-
nss: nvme::mi::NvmSubsystemStatus,
442+
nss: FlagSet<crate::nvme::mi::NvmSubsystemStatusFlags>,
443443
}
444444

445445
impl SubsystemHealth {
446446
fn new() -> Self {
447447
Self {
448-
nss: nvme::mi::NvmSubsystemStatus::new(),
448+
nss: crate::nvme::mi::NvmSubsystemStatusFlags::Rnr
449+
| crate::nvme::mi::NvmSubsystemStatusFlags::Df,
449450
}
450451
}
451452
}

src/nvme/mi.rs

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -496,39 +496,22 @@ struct CompositeControllerStatusDataStructureResponse {
496496
impl Encode<4> for CompositeControllerStatusDataStructureResponse {}
497497

498498
// MI v2.0, 5.6, Figure 108, NSS
499-
// TODO: Convert to Flags/FlagSet
500-
#[derive(Debug)]
501-
pub struct NvmSubsystemStatus {
502-
atf: bool,
503-
sfm: bool,
504-
df: bool,
505-
rnr: bool,
506-
rd: bool,
507-
}
508-
509-
impl Default for NvmSubsystemStatus {
510-
fn default() -> Self {
511-
Self::new()
512-
}
513-
}
514-
515-
impl NvmSubsystemStatus {
516-
pub fn new() -> Self {
517-
Self {
518-
atf: false,
519-
sfm: false,
520-
df: true,
521-
rnr: true,
522-
rd: false,
523-
}
499+
flags! {
500+
pub enum NvmSubsystemStatusFlags: u8 {
501+
P1la = 1 << 2,
502+
P0la = 1 << 3,
503+
Rnr = 1 << 4,
504+
Df = 1 << 5,
505+
Sfm = 1 << 6,
506+
Atf = 1 << 7,
524507
}
525508
}
526509

527510
// MI v2.0, 5.6, Figure 108
528511
#[derive(Debug, DekuRead, DekuWrite)]
529512
#[deku(endian = "little")]
530513
struct NvmSubsystemHealthDataStructureResponse {
531-
nss: u8,
514+
nss: WireFlagSet<NvmSubsystemStatusFlags>,
532515
sw: u8,
533516
ctemp: u8,
534517
pldu: u8,

src/nvme/mi/dev.rs

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

11-
use crate::nvme::mi::PortCapabilityFlags;
11+
use crate::nvme::mi::{NvmSubsystemStatusFlags, PortCapabilityFlags};
1212
use crate::{
1313
CommandEffect, CommandEffectError, Controller, ControllerError, ControllerType, Discriminant,
1414
MAX_CONTROLLERS, MAX_NAMESPACES, NamespaceId, NamespaceIdDisposition, SubsystemError,
@@ -224,17 +224,21 @@ impl RequestHandler for NvmeMiCommandRequestHeader {
224224
let pdlu = core::cmp::min(255, 100 * ctlr.write_age / ctlr.write_lifespan);
225225

226226
let nvmshds = NvmSubsystemHealthDataStructureResponse {
227-
nss: (subsys.health.nss.atf as u8) << 7
228-
| (subsys.health.nss.sfm as u8) << 6
229-
| (subsys.health.nss.df as u8) << 5
230-
| (subsys.health.nss.rnr as u8) << 4
231-
| ((pprt.cls != crate::pcie::LinkSpeed::Inactive) as u8) << 3 // P0LA
232-
| (false as u8) << 2, // P1LA
227+
nss: {
228+
let mut flags = subsys.health.nss;
229+
230+
if pprt.cls != crate::pcie::LinkSpeed::Inactive {
231+
flags |= NvmSubsystemStatusFlags::P0la;
232+
}
233+
234+
flags
235+
}
236+
.into(),
233237
#[allow(clippy::nonminimal_bool)]
234238
sw: (!false as u8) << 5 // PMRRO
235239
| (!false as u8) << 4 // VMBF
236240
| (!ctlr.ro as u8) << 3 // AMRO
237-
| (!subsys.health.nss.rd as u8) << 2 // NDR
241+
| (!ctlr.ro as u8) << 2 // NDR
238242
| (!(ctlr.temp_range.lower <= ctlr.temp && ctlr.temp <= ctlr.temp_range.upper) as u8) << 1 // TTC
239243
| (!((100 * ctlr.spare / ctlr.capacity) < ctlr.spare_range.lower) as u8),
240244
ctemp: ctemp as u8,

0 commit comments

Comments
 (0)