intro
nvme device는 host가 issue 하는 command를 수행하기 위해서, controller initialize 동작을 해야 한다. 어떤 순서로 어떻게 하는지 알아보고자 한다.
Controller Initialization
1. Set the PCI and PCI Express registers described in section 2 appropriately based on the system configuration.
PCI Device는 PCI configuration space라는 구조체를 들고 있다. Host는 configuration space의 register를 보고, 이 PCI Device가 무엇이고, 어떻게 통신해야 하는지를 알 수 있다. 어떤 register는 host가, 또 다른 register는 PCI Device가 설정해줘야 한다는 것으로 이해된다.

2. The host waits for the controller to indicate that any previous reset is complete by waiting for CSTS.RDY to become ‘0’;
CSTS는 Controller Status를 나타내는 Controller Register이다. Controller가 Set해야, Host가 Controller Status를 알 수 있겠구나. CSTS.RDY가 0이라는 것은, 이전 reset(CC.EN 0)에 의해서 controller가 command를 처리할 수 없는 상태가 됐음을 의미한다.
3. The Admin Queue should be configured. The Admin Queue is configured by setting the Admin Queue Attributes (AQA), Admin Submission Queue Base Address (ASQ), and Admin Completion Queue Base Address (ACQ) to appropriate values;
AQA(Admin SQ/CQ의 Queue Entry 개수), ASQ, ACQ는 Controller Register이다. 이는 Host가 설정한다.
왜?? 일반적으로 Host Memory에 SQ/CQ가 존재하고, Controller가 해당 Queue의 주소를 알아야, SQ에서 Command를 가져오거나, CQ에 Completion posting을 할 수 있기 때문인가?
4. The controller settings should be configured. Specifically:
a. The arbitration mechanism should be selected in CC.AMS;
b. The memory page size should be initialized in CC.MPS; and
c. The I/O Command Set that is to be used should be selected in CC.CSS or CC.CSS field should be set to the value indicating that only the Admin Command Set is supported;
CC는 Controller Configuration을 나타내는 Controller Register이다. 이는 Host가 설정한다.
AMS는 여러 개의 queue에서 command 처리 우선순위 방식을 정하는 값이다
MPS는 PRP Entry size에 사용되는 값이다.
CSS는 Command Set 지원여부를 나타내는 값이다.
5. The controller should be enabled by setting CC.EN to ‘1’;
Controller Enable 하라는 의미이므로, Device는 command를 처리할 수 있는 상태가 되도록 해야한다.
6. The host should wait for the controller to indicate that the controller is ready to process commands. The controller is ready to process commands when CSTS.RDY is set to ‘1’;
Device가 command 처리할 수 있는 상태가 완료되면, CSTS.RDY를 1로 Set 한다.
7. The host should determine the configuration of the controller by issuing the Identify command, specifying the Controller data structure. The host should then determine the configuration of each namespace by issuing the Identify command for each namespace, specifying the Namespace data structure;
Host는 CSTS.RDY를 확인한 후에, identify command를 Issue 해서, controller config 또는 각각의 namespace config를 알고자 한다.
8. If the controller implements I/O queues, then the host should determine the number of I/O Submission Queues and I/O Completion Queues supported using the Set Features command with the Number of Queues feature identifier. After determining the number of I/O Queues, the MSI and/or MSI-X registers should be configured;
7. 에서 CSTS.RDY가 됐다는 것은 Admin Command를 처리할 수 있음을 의미한다. Host는 I/O SQ, CQ 개수를 정하고 싶다면, Set Feature Command - Number Of Queue로 설정할 수 있다. I/O Queue가 정해진 후에 MSI 또는 MSI-X register config값이 정해져야 한다.
reference
- PCI configuration space - Wikipedia
- 커널개발기 (zum.com) PCI configuration space란 무엇인가
- PCI configuration space란? 개념 정리 - Easy is Perfect (melonicedlatte.com)
'컴퓨터 > SSD' 카테고리의 다른 글
| [PCIe] Enumeration (0) | 2023.06.22 |
|---|---|
| [NVMe] Reservation (0) | 2023.06.07 |
| [NVMe] Feature (0) | 2023.05.21 |
| [PCIe] Reset (1) | 2023.05.01 |
| [NVMe] Protection Information (0) | 2023.03.13 |