OpenSSD Cosmos+ Platform Firmware  0.0.2
The firmware of Cosmos+ OpenSSD Platform for TOSHIBA nand flash module.
nvme_main.c File Reference
#include "xil_printf.h"
#include "debug.h"
#include "io_access.h"
#include "nvme.h"
#include "host_lld.h"
#include "nvme_main.h"
#include "nvme_admin_cmd.h"
#include "nvme_io_cmd.h"
#include "../memory_map.h"
Include dependency graph for nvme_main.c:

Go to the source code of this file.

Functions

void nvme_main ()
 

Variables

volatile NVME_CONTEXT g_nvmeTask
 

Function Documentation

◆ nvme_main()

void nvme_main ( )

The main loop of Cosmos+ firmware.

This loop can be separated into several small parts:

  • NVMe Manager
  • Low-level Scheduler

    Interpret NVMe commands received from host.

    In this step, we need to check which type of the NVMe command you got:

  • If it's Admin command:
      Handle it in NVMe Manager without forwarding to FTL.
    
  • If it's I/O (NVM) command:
      Forward to the NVM Command Manager (FTL).
    

Do scheduling.

We need to execute the requests that were put on corresponding queue in prev part.

As described in the paper, Host DMA operations have the highest priority, so we should call the CheckDoneNvmeDmaReq first, then SchedulingNandReq.

Definition at line 73 of file nvme_main.c.

74{
75 unsigned int exeLlr;
76 unsigned int rstCnt = 0;
77
78 xil_printf("!!! Wait until FTL reset complete !!! \r\n");
79
80 InitFTL();
81
82 xil_printf("\r\nFTL reset complete!!! \r\n");
83 xil_printf("Turn on the host PC \r\n");
84
93 while (1)
94 {
95 exeLlr = 1;
96
98 {
99 unsigned int ccEn;
100 ccEn = check_nvme_cc_en();
101 if (ccEn == 1)
102 {
103 set_nvme_admin_queue(1, 1, 1);
106 xil_printf("\r\nNVMe ready!!!\r\n");
107 }
108 }
110 {
111 NVME_COMMAND nvmeCmd;
112 unsigned int cmdValid;
113
114 cmdValid = get_nvme_cmd(&nvmeCmd.qID, &nvmeCmd.cmdSlotTag, &nvmeCmd.cmdSeqNum, nvmeCmd.cmdDword);
115
129 if (cmdValid == 1)
130 {
131 rstCnt = 0;
132 if (nvmeCmd.qID == 0)
133 {
134 handle_nvme_admin_cmd(&nvmeCmd);
135 }
136 else
137 {
138 handle_nvme_io_cmd(&nvmeCmd);
140 exeLlr = 0;
141 }
142 }
143 }
145 {
146 NVME_STATUS_REG nvmeReg;
148 if (nvmeReg.ccShn != 0)
149 {
150 unsigned int qID;
152
153 for (qID = 0; qID < 8; qID++)
154 {
155 set_io_cq(qID, 0, 0, 0, 0, 0, 0);
156 set_io_sq(qID, 0, 0, 0, 0, 0);
157 }
158
159 set_nvme_admin_queue(0, 0, 0);
163
164 // flush grown bad block info
166
167 xil_printf("\r\nNVMe shutdown!!!\r\n");
168 }
169 }
171 {
172 unsigned int ccEn;
173 ccEn = check_nvme_cc_en();
174 if (ccEn == 0)
175 {
180 xil_printf("\r\nNVMe disable!!!\r\n");
181 }
182 }
184 {
185 unsigned int qID;
186 for (qID = 0; qID < 8; qID++)
187 {
188 set_io_cq(qID, 0, 0, 0, 0, 0, 0);
189 set_io_sq(qID, 0, 0, 0, 0, 0);
190 }
191
192 if (rstCnt >= 5)
193 {
194 pcie_async_reset(rstCnt);
195 rstCnt = 0;
196 xil_printf("\r\nPcie iink disable!!!\r\n");
197 xil_printf("Wait few minute or reconnect the PCIe cable\r\n");
198 }
199 else
200 rstCnt++;
201
203 set_nvme_admin_queue(0, 0, 0);
207
208 xil_printf("\r\nNVMe reset!!!\r\n");
209 }
210
221 {
224 }
225 }
226}
void UpdateBadBlockTableForGrownBadBlock(unsigned int tempBufAddr)
Update the bad block table and persist to the specified block.
void InitFTL()
The entry function for FTL initialization.
Definition: ftl_config.c:62
void set_nvme_admin_queue(unsigned int sqValid, unsigned int cqValid, unsigned int cqIrqEn)
Definition: host_lld.c:225
unsigned int check_nvme_cc_en()
Definition: host_lld.c:177
void set_nvme_csts_shst(unsigned int shst)
Definition: host_lld.c:215
void set_nvme_csts_rdy(unsigned int rdy)
Definition: host_lld.c:205
void pcie_async_reset(unsigned int rstCnt)
Definition: host_lld.c:186
unsigned int get_nvme_cmd(unsigned short *qID, unsigned short *cmdSlotTag, unsigned int *cmdSeqNum, unsigned int *cmdDword)
Definition: host_lld.c:237
void set_io_sq(unsigned int ioSqIdx, unsigned int valid, unsigned int cqVector, unsigned int qSzie, unsigned int pcieBaseAddrL, unsigned int pcieBaseAddrH)
Definition: host_lld.c:301
void set_io_cq(unsigned int ioCqIdx, unsigned int valid, unsigned int irqEn, unsigned int irqVector, unsigned int qSzie, unsigned int pcieBaseAddrL, unsigned int pcieBaseAddrH)
Definition: host_lld.c:318
#define NVME_STATUS_REG_ADDR
Definition: host_lld.h:66
#define IO_READ32(addr)
Definition: io_access.h:51
#define RESERVED_DATA_BUFFER_BASE_ADDR
Definition: memory_map.h:85
#define NVME_TASK_RESET
Definition: nvme.h:199
#define NVME_TASK_IDLE
Definition: nvme.h:194
#define NVME_TASK_WAIT_RESET
Definition: nvme.h:198
#define NVME_TASK_WAIT_CC_EN
Definition: nvme.h:195
#define NVME_TASK_RUNNING
Definition: nvme.h:196
#define NVME_TASK_SHUTDOWN
Definition: nvme.h:197
void handle_nvme_admin_cmd(NVME_COMMAND *nvmeCmd)
void handle_nvme_io_cmd(NVME_COMMAND *nvmeCmd)
Definition: nvme_io_cmd.c:126
volatile NVME_CONTEXT g_nvmeTask
Definition: nvme_main.c:71
unsigned int blockedReqCnt
NVME_DMA_REQUEST_QUEUE nvmeDmaReqQ
unsigned int notCompletedNandReqCnt
#define REQ_SLOT_TAG_NONE
void SchedulingNandReq()
Iteratively do schedule on each channel by calling SchedulingNandReqPerCh.
void ReqTransSliceToLowLevel()
Data Buffer Manager. Handle all the pending slice requests.
void CheckDoneNvmeDmaReq()
unsigned int cmdSeqNum
Definition: nvme.h:209
unsigned short qID
Definition: nvme.h:207
unsigned short cmdSlotTag
Definition: nvme.h:208
unsigned int cmdDword[16]
Definition: nvme.h:233
unsigned int ccShn
Definition: host_lld.h:156
unsigned int dword
Definition: host_lld.h:152
unsigned int cacheEn
Definition: nvme.h:960
unsigned int status
Definition: nvme.h:959
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ g_nvmeTask

volatile NVME_CONTEXT g_nvmeTask

Definition at line 71 of file nvme_main.c.