@@ -233,12 +233,13 @@ impl<'a> Namespace<'a> {
233233 assert ! ( size_bytes != 0 ) ;
234234
235235 let blocks = size_bytes. div_ceil ( self . block_size ) ;
236- let mut read_cmd = ReadWriteCommand :: default ( ) ;
237-
238- read_cmd. opcode = opcode as u8 ;
239- read_cmd. nsid = self . nsid ;
240- read_cmd. start_lba = sector as u64 ;
241- read_cmd. length = ( blocks - 1 ) as u16 ;
236+ let mut read_cmd = ReadWriteCommand {
237+ opcode : opcode as u8 ,
238+ nsid : self . nsid ,
239+ start_lba : sector as u64 ,
240+ length : ( blocks - 1 ) as u16 ,
241+ ..Default :: default ( )
242+ } ;
242243
243244 if size_bytes > Size4KiB :: SIZE as usize {
244245 // The data cannot fit in 8KiB frames, so we need to use
@@ -338,13 +339,18 @@ impl<'a> Controller<'a> {
338339 registers. set_enable ( true ) ?;
339340
340341 let identity = Dma :: < IdentifyController > :: zeroed ( ) ;
341- let mut identify_command = IdentifyCommand :: default ( ) ;
342342
343- identify_command. opcode = AdminOpcode :: Identify as u8 ;
344- identify_command. cns = IdentifyCns :: Controller as u8 ;
345- identify_command. data_ptr . prp1 = identity. addr ( ) . as_u64 ( ) ;
346-
347- admin. submit_command ( identify_command) ;
343+ // TODO(andypython): builder pattern for building a command? We also shouldn't be required
344+ // to manually fill in the `opcode` field.
345+ admin. submit_command ( IdentifyCommand {
346+ opcode : AdminOpcode :: Identify as u8 ,
347+ cns : IdentifyCns :: Controller as u8 ,
348+ data_ptr : DataPointer {
349+ prp1 : identity. addr ( ) . as_u64 ( ) ,
350+ ..Default :: default ( )
351+ } ,
352+ ..Default :: default ( )
353+ } ) ;
348354
349355 log:: trace!(
350356 "nvme: identifed controller (vendor={}, subsystem_vendor={})" ,
@@ -355,27 +361,25 @@ impl<'a> Controller<'a> {
355361 // Create and initialize the I/O queues.
356362 let io_queue = QueuePair :: new ( registers, queue_size) ?;
357363
358- let mut io_cq_cmd = CreateCQCommand :: default ( ) ;
359-
360- io_cq_cmd. opcode = AdminOpcode :: CreateCq as u8 ;
361- io_cq_cmd. prp1 = io_queue. completion_addr ( ) . as_u64 ( ) ;
362- io_cq_cmd. cqid = io_queue. id ( ) ;
363- io_cq_cmd. q_size = ( io_queue. len ( ) - 1 ) as u16 ;
364- io_cq_cmd. irq_vector = 0 ;
365- io_cq_cmd. cq_flags = CommandFlags :: QUEUE_PHYS_CONTIG . bits ( ) ;
366-
367- admin. submit_command ( io_cq_cmd) ;
368-
369- let mut io_sq_cmd = CreateSQCommand :: default ( ) ;
370-
371- io_sq_cmd. opcode = AdminOpcode :: CreateSq as u8 ;
372- io_sq_cmd. prp1 = io_queue. submission_addr ( ) . as_u64 ( ) ;
373- io_sq_cmd. cqid = io_queue. id ( ) ;
374- io_sq_cmd. sqid = io_queue. id ( ) ;
375- io_sq_cmd. q_size = ( io_queue. len ( ) - 1 ) as u16 ;
376- io_sq_cmd. sq_flags = CommandFlags :: QUEUE_PHYS_CONTIG . bits ( ) ;
364+ admin. submit_command ( CreateCQCommand {
365+ opcode : AdminOpcode :: CreateCq as u8 ,
366+ prp1 : io_queue. completion_addr ( ) . as_u64 ( ) ,
367+ cqid : io_queue. id ( ) ,
368+ q_size : ( io_queue. len ( ) - 1 ) as u16 ,
369+ irq_vector : 0 ,
370+ cq_flags : CommandFlags :: QUEUE_PHYS_CONTIG . bits ( ) ,
371+ ..Default :: default ( )
372+ } ) ;
377373
378- admin. submit_command ( io_sq_cmd) ;
374+ admin. submit_command ( CreateSQCommand {
375+ opcode : AdminOpcode :: CreateSq as u8 ,
376+ prp1 : io_queue. submission_addr ( ) . as_u64 ( ) ,
377+ cqid : io_queue. id ( ) ,
378+ sqid : io_queue. id ( ) ,
379+ q_size : ( io_queue. len ( ) - 1 ) as u16 ,
380+ sq_flags : CommandFlags :: QUEUE_PHYS_CONTIG . bits ( ) ,
381+ ..Default :: default ( )
382+ } ) ;
379383
380384 let shift = 12 + registers. capability . mpsmin ( ) as usize ;
381385 let max_transfer_shift = if identity. mdts != 0 {
@@ -395,13 +399,16 @@ impl<'a> Controller<'a> {
395399 // Discover and initialize the namespaces.
396400 let nsids = {
397401 let nsid_list = Dma :: < u32 > :: new_uninit_slice ( this. identity . nn as usize ) ;
398- let mut nsid_command = IdentifyCommand :: default ( ) ;
399402
400- nsid_command. opcode = AdminOpcode :: Identify as u8 ;
401- nsid_command. cns = IdentifyCns :: ActivateList as u8 ;
402- nsid_command. data_ptr . prp1 = nsid_list. addr ( ) . as_u64 ( ) ;
403-
404- this. admin . lock ( ) . submit_command ( nsid_command) ;
403+ this. admin . lock ( ) . submit_command ( IdentifyCommand {
404+ opcode : AdminOpcode :: Identify as u8 ,
405+ cns : IdentifyCns :: ActivateList as u8 ,
406+ data_ptr : DataPointer {
407+ prp1 : nsid_list. addr ( ) . as_u64 ( ) ,
408+ ..Default :: default ( )
409+ } ,
410+ ..Default :: default ( )
411+ } ) ;
405412
406413 // SAFETY: The list is initialized above.
407414 unsafe { nsid_list. assume_init ( ) }
@@ -416,14 +423,17 @@ impl<'a> Controller<'a> {
416423 }
417424
418425 let identity = Dma :: < IdentifyNamespace > :: zeroed ( ) ;
419- let mut identify_command = IdentifyCommand :: default ( ) ;
420-
421- identify_command. opcode = AdminOpcode :: Identify as u8 ;
422- identify_command. cns = IdentifyCns :: Namespace as u8 ;
423- identify_command. nsid = nsid;
424- identify_command. data_ptr . prp1 = identity. addr ( ) . as_u64 ( ) ;
425426
426- this. admin . lock ( ) . submit_command ( identify_command) ;
427+ this. admin . lock ( ) . submit_command ( IdentifyCommand {
428+ opcode : AdminOpcode :: Identify as u8 ,
429+ cns : IdentifyCns :: Namespace as u8 ,
430+ nsid,
431+ data_ptr : DataPointer {
432+ prp1 : identity. addr ( ) . as_u64 ( ) ,
433+ ..Default :: default ( )
434+ } ,
435+ ..Default :: default ( )
436+ } ) ;
427437
428438 let blocks = identity. nsze as usize ;
429439 let block_size = 1 << identity. lbaf [ ( identity. flbas & 0b11111 ) as usize ] . ds ;
0 commit comments