@@ -363,9 +363,8 @@ impl<'a> Controller<'a> {
363
363
io_cq_cmd. prp1 = io_queue. completion_addr ( ) . as_u64 ( ) ;
364
364
io_cq_cmd. cqid = io_queue. id ( ) ;
365
365
io_cq_cmd. q_size = ( io_queue. len ( ) - 1 ) as u16 ;
366
- io_cq_cmd. irq_vector = vector as u16 ;
367
- io_cq_cmd. cq_flags =
368
- ( CommandFlags :: CQ_IRQ_ENABLED | CommandFlags :: QUEUE_PHYS_CONTIG ) . bits ( ) ;
366
+ io_cq_cmd. irq_vector = 0 ;
367
+ io_cq_cmd. cq_flags = CommandFlags :: QUEUE_PHYS_CONTIG . bits ( ) ;
369
368
370
369
admin. submit_command ( io_cq_cmd) ;
371
370
@@ -376,8 +375,7 @@ impl<'a> Controller<'a> {
376
375
io_sq_cmd. cqid = io_queue. id ( ) ;
377
376
io_sq_cmd. sqid = io_queue. id ( ) ;
378
377
io_sq_cmd. q_size = ( io_queue. len ( ) - 1 ) as u16 ;
379
- io_sq_cmd. sq_flags =
380
- ( CommandFlags :: CQ_IRQ_ENABLED | CommandFlags :: QUEUE_PHYS_CONTIG ) . bits ( ) ;
378
+ io_sq_cmd. sq_flags = CommandFlags :: QUEUE_PHYS_CONTIG . bits ( ) ;
381
379
382
380
admin. submit_command ( io_sq_cmd) ;
383
381
@@ -396,7 +394,8 @@ impl<'a> Controller<'a> {
396
394
io_queue : Mutex :: new ( io_queue) ,
397
395
} ) ;
398
396
399
- let namespace_ids = || {
397
+ // Discover and initialize the namespaces.
398
+ let nsids = {
400
399
let nsid_list = Dma :: < u32 > :: new_uninit_slice ( this. identity . nn as usize ) ;
401
400
let mut nsid_command = IdentifyCommand :: default ( ) ;
402
401
@@ -410,48 +409,50 @@ impl<'a> Controller<'a> {
410
409
unsafe { nsid_list. assume_init ( ) }
411
410
} ;
412
411
413
- // Discover and initialize the namespaces.
414
- let nsids = namespace_ids ( ) ;
415
- let namespaces = nsids
416
- . iter ( )
417
- . map ( |nsid| {
418
- let identity = Dma :: < IdentifyNamespace > :: new ( ) ;
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 ( ) ;
425
-
426
- this. admin . lock ( ) . submit_command ( identify_command) ;
427
-
428
- let blocks = identity. nsze as usize ;
429
- let block_size = 1 << identity. lbaf [ ( identity. flbas & 0b11111 ) as usize ] . ds ;
430
-
431
- // The maximum transfer size is in units of 2^(min page size)
432
- let lba_shift = identity. lbaf [ ( identity. flbas & 0xf ) as usize ] . ds ;
433
- let max_lbas = 1 << ( max_transfer_shift - lba_shift as usize ) ;
434
- let max_prps = ( max_lbas * ( 1 << lba_shift) ) / Size4KiB :: SIZE as usize ;
435
-
436
- Namespace {
437
- controller : this. clone ( ) ,
438
- nsid : * nsid,
439
- blocks,
440
- block_size,
441
- size : blocks * block_size,
442
- max_prps,
443
- prps : Mutex :: new ( Dma :: new_uninit_slice ( max_prps) ) ,
444
- }
445
- } )
446
- . collect :: < Vec < _ > > ( ) ;
412
+ let mut namespaces = alloc:: vec![ ] ;
413
+
414
+ for & nsid in nsids. iter ( ) {
415
+ // Unused entries are zero-filled.
416
+ if nsid == 0 {
417
+ continue ;
418
+ }
419
+
420
+ let identity = Dma :: < IdentifyNamespace > :: new ( ) ;
421
+ let mut identify_command = IdentifyCommand :: default ( ) ;
422
+
423
+ identify_command. opcode = AdminOpcode :: Identify as u8 ;
424
+ identify_command. cns = IdentifyCns :: Namespace as u8 ;
425
+ identify_command. nsid = nsid;
426
+ identify_command. data_ptr . prp1 = identity. addr ( ) . as_u64 ( ) ;
427
+
428
+ this. admin . lock ( ) . submit_command ( identify_command) ;
429
+
430
+ let blocks = identity. nsze as usize ;
431
+ let block_size = 1 << identity. lbaf [ ( identity. flbas & 0b11111 ) as usize ] . ds ;
432
+
433
+ // The maximum transfer size is in units of 2^(min page size)
434
+ let lba_shift = identity. lbaf [ ( identity. flbas & 0xf ) as usize ] . ds ;
435
+ let max_lbas = 1 << ( max_transfer_shift - lba_shift as usize ) ;
436
+ let max_prps = ( max_lbas * ( 1 << lba_shift) ) / Size4KiB :: SIZE as usize ;
437
+
438
+ let namespace = Namespace {
439
+ controller : this. clone ( ) ,
440
+ nsid,
441
+ blocks,
442
+ block_size,
443
+ size : blocks * block_size,
444
+ max_prps,
445
+ prps : Mutex :: new ( Dma :: new_uninit_slice ( max_prps) ) ,
446
+ } ;
447
447
448
- for namespace in namespaces. iter ( ) {
449
448
log:: trace!(
450
449
"nvme: identified namespace (blocks={}, block_size={}, size={})" ,
451
450
namespace. blocks,
452
451
namespace. block_size,
453
452
namespace. size
454
453
) ;
454
+
455
+ namespaces. push ( namespace) ;
455
456
}
456
457
457
458
* this. namespaces . lock ( ) = namespaces;
0 commit comments