OpenSSD Cosmos+ Platform Firmware  0.0.2
The firmware of Cosmos+ OpenSSD Platform for TOSHIBA nand flash module.
nvme_main.c
Go to the documentation of this file.
1
2// nvme_main.c for Cosmos+ OpenSSD
3// Copyright (c) 2016 Hanyang University ENC Lab.
4// Contributed by Yong Ho Song <yhsong@enc.hanyang.ac.kr>
5// Youngjin Jo <yjjo@enc.hanyang.ac.kr>
6// Sangjin Lee <sjlee@enc.hanyang.ac.kr>
7// Jaewook Kwak <jwkwak@enc.hanyang.ac.kr>
8// Kibin Park <kbpark@enc.hanyang.ac.kr>
9//
10// This file is part of Cosmos+ OpenSSD.
11//
12// Cosmos+ OpenSSD is free software; you can redistribute it and/or modify
13// it under the terms of the GNU General Public License as published by
14// the Free Software Foundation; either version 3, or (at your option)
15// any later version.
16//
17// Cosmos+ OpenSSD is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20// See the GNU General Public License for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with Cosmos+ OpenSSD; see the file COPYING.
24// If not, see <http://www.gnu.org/licenses/>.
26
28// Company: ENC Lab. <http://enc.hanyang.ac.kr>
29// Engineer: Sangjin Lee <sjlee@enc.hanyang.ac.kr>
30// Jaewook Kwak <jwkwak@enc.hanyang.ac.kr>
31// Kibin Park <kbpark@enc.hanyang.ac.kr>
32//
33// Project Name: Cosmos+ OpenSSD
34// Design Name: Cosmos+ Firmware
35// Module Name: NVMe Main
36// File Name: nvme_main.c
37//
38// Version: v1.2.0
39//
40// Description:
41// - initializes FTL and NAND
42// - handles NVMe controller
44
46// Revision History:
47//
48// * v1.2.0
49// - header file for buffer is changed from "ia_lru_buffer.h" to "lru_buffer.h"
50// - Low level scheduler execution is allowed when there is no i/o command
51//
52// * v1.1.0
53// - DMA status initialization is added
54//
55// * v1.0.0
56// - First draft
58
59#include "xil_printf.h"
60#include "debug.h"
61#include "io_access.h"
62
63#include "nvme.h"
64#include "host_lld.h"
65#include "nvme_main.h"
66#include "nvme_admin_cmd.h"
67#include "nvme_io_cmd.h"
68
69#include "../memory_map.h"
70
72
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
void nvme_main()
Definition: nvme_main.c:73
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