@@ -7,6 +7,11 @@ pub mod mi;
77use hmac:: Mac ;
88use uuid:: Uuid ;
99
10+ const MAX_CONTROLLERS : usize = 2 ;
11+ const MAX_NAMESPACES : usize = 2 ;
12+ const MAX_PORTS : usize = 2 ;
13+ const MAX_NIDTS : usize = 2 ;
14+
1015#[ allow( dead_code) ]
1116#[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
1217#[ repr( u8 ) ]
@@ -97,19 +102,12 @@ impl Default for PCIePort {
97102}
98103
99104#[ allow( dead_code) ]
100- #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
101- #[ repr( u8 ) ]
105+ #[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
102106enum SMBusFrequency {
103- FreqNotSupported = 0x00 ,
104- Freq100kHz = 0x01 ,
105- Freq400kHz = 0x02 ,
106- Freq1MHz = 0x03 ,
107- }
108-
109- impl From < SMBusFrequency > for u8 {
110- fn from ( freq : SMBusFrequency ) -> Self {
111- freq as Self
112- }
107+ FreqNotSupported ,
108+ Freq100kHz ,
109+ Freq400kHz ,
110+ Freq1MHz ,
113111}
114112
115113#[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
@@ -367,43 +365,21 @@ impl SubsystemHealth {
367365 }
368366}
369367
370- #[ derive( Debug ) ]
371- #[ repr( u8 ) ]
368+ #[ derive( Clone , Copy , Debug ) ]
372369pub enum CommandSetIdentifier {
373- NVMCommandSet = 0 ,
374- KeyValueCommandSet = 1 ,
375- ZonedNamespaceCommandSet = 2 ,
376- SubsystemLocalMemoryCommandSet = 3 ,
377- ComputationalProgramsCommandSet = 4 ,
378- }
379-
380- impl CommandSetIdentifier {
381- fn id ( & self ) -> u8 {
382- // https://doc.rust-lang.org/reference/items/enumerations.html#r-items.enum.discriminant.access-memory
383- unsafe { * ( self as * const Self as * const u8 ) }
384- }
370+ NVMCommandSet ,
371+ KeyValueCommandSet ,
372+ ZonedNamespaceCommandSet ,
373+ SubsystemLocalMemoryCommandSet ,
374+ ComputationalProgramsCommandSet ,
385375}
386376
387- // NSID
388- #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
389- pub struct NamespaceId ( u32 ) ;
390-
391- // NID: 5.1.13.2.3, Base v2.1
392- #[ derive( Debug ) ]
393- #[ repr( u8 ) ]
377+ #[ derive( Clone , Copy , Debug ) ]
394378pub enum NamespaceIdentifierType {
395- Reserved = 0 ,
396- IEUID ( [ u8 ; 8 ] ) = 1 ,
397- NGUID ( [ u8 ; 16 ] ) = 2 ,
398- NUUID ( Uuid ) = 3 ,
399- CSI ( CommandSetIdentifier ) = 4 ,
400- }
401-
402- impl NamespaceIdentifierType {
403- fn id ( & self ) -> u8 {
404- // https://doc.rust-lang.org/reference/items/enumerations.html#r-items.enum.discriminant.access-memory
405- unsafe { * ( self as * const Self as * const u8 ) }
406- }
379+ IEUID ( [ u8 ; 8 ] ) ,
380+ NGUID ( [ u8 ; 16 ] ) ,
381+ NUUID ( Uuid ) ,
382+ CSI ( CommandSetIdentifier ) ,
407383}
408384
409385#[ derive( Debug ) ]
@@ -415,6 +391,10 @@ pub struct Namespace {
415391 nids : [ NamespaceIdentifierType ; 2 ] ,
416392}
417393
394+ // NSID
395+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
396+ pub struct NamespaceId ( u32 ) ;
397+
418398impl Namespace {
419399 fn generate_uuid ( seed : & [ u8 ] , nsid : NamespaceId ) -> Uuid {
420400 let mut hasher = hmac:: Hmac :: < sha2:: Sha256 > :: new_from_slice ( seed) . unwrap ( ) ;
@@ -438,10 +418,6 @@ impl Namespace {
438418 }
439419}
440420
441- const MAX_CONTROLLERS : usize = 2 ;
442- const MAX_NAMESPACES : usize = 2 ;
443- const MAX_PORTS : usize = 2 ;
444-
445421#[ derive( Clone , Copy , Debug ) ]
446422pub struct SubsystemInfo {
447423 pub pci_vid : u16 ,
0 commit comments