OpenSSD Cosmos+ Platform Firmware  0.0.2
The firmware of Cosmos+ OpenSSD Platform for TOSHIBA nand flash module.
host_lld.h
Go to the documentation of this file.
1
2// host_lld.h 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//
9// This file is part of Cosmos+ OpenSSD.
10//
11// Cosmos+ OpenSSD is free software; you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation; either version 3, or (at your option)
14// any later version.
15//
16// Cosmos+ OpenSSD is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19// See the GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with Cosmos+ OpenSSD; see the file COPYING.
23// If not, see <http://www.gnu.org/licenses/>.
25
27// Company: ENC Lab. <http://enc.hanyang.ac.kr>
28// Engineer: Sangjin Lee <sjlee@enc.hanyang.ac.kr>
29// Jaewook Kwak <jwkwak@enc.hanyang.ac.kr>
30//
31// Project Name: Cosmos+ OpenSSD
32// Design Name: Cosmos+ Firmware
33// Module Name: NVMe Low Level Driver
34// File Name: host_lld.h
35//
36// Version: v1.1.0
37//
38// Description:
39// - defines parameters and data structures of the NVMe low level driver
40// - declares functions of the NVMe low level driver
42
44// Revision History:
45//
46// * v1.1.0
47// - new DMA status type is added (HOST_DMA_ASSIST_STATUS)
48// - DMA partial done check functions are added
49//
50// * v1.0.0
51// - First draft
53
54#ifndef __HOST_LLD_H_
55#define __HOST_LLD_H_
56
57#define HOST_IP_ADDR (XPAR_NVME_CTRL_0_BASEADDR)
58
59#define DEV_IRQ_MASK_REG_ADDR (HOST_IP_ADDR + 0x4)
60#define DEV_IRQ_CLEAR_REG_ADDR (HOST_IP_ADDR + 0x8)
61#define DEV_IRQ_STATUS_REG_ADDR (HOST_IP_ADDR + 0xC)
62
63#define PCIE_STATUS_REG_ADDR (HOST_IP_ADDR + 0x100)
64#define PCIE_FUNC_REG_ADDR (HOST_IP_ADDR + 0x104)
65
66#define NVME_STATUS_REG_ADDR (HOST_IP_ADDR + 0x200)
67#define HOST_DMA_FIFO_CNT_REG_ADDR (HOST_IP_ADDR + 0x204)
68#define NVME_ADMIN_QUEUE_SET_REG_ADDR (HOST_IP_ADDR + 0x21C)
69#define NVME_IO_SQ_SET_REG_ADDR (HOST_IP_ADDR + 0x220)
70#define NVME_IO_CQ_SET_REG_ADDR (HOST_IP_ADDR + 0x260)
71
72#define NVME_CMD_FIFO_REG_ADDR (HOST_IP_ADDR + 0x300)
73#define NVME_CPL_FIFO_REG_ADDR (HOST_IP_ADDR + 0x304)
74#define HOST_DMA_CMD_FIFO_REG_ADDR (HOST_IP_ADDR + 0x310)
75
76#define NVME_CMD_SRAM_ADDR (HOST_IP_ADDR + 0x10000)
77
78#define HOST_DMA_DIRECT_TYPE (1)
79#define HOST_DMA_AUTO_TYPE (0)
80
81#define HOST_DMA_TX_DIRECTION (1)
82#define HOST_DMA_RX_DIRECTION (0)
83
84#define ONLY_CPL_TYPE (0)
85#define AUTO_CPL_TYPE (1)
86#define CMD_SLOT_RELEASE_TYPE (2)
87#define P_SLOT_TAG_WIDTH (10) // slot_modified
88
89#pragma pack(push, 1)
90
91typedef struct _DEV_IRQ_REG
92{
93 union
94 {
95 unsigned int dword;
96 struct
97 {
98 unsigned int pcieLink : 1;
99 unsigned int busMaster : 1;
100 unsigned int pcieIrq : 1;
101 unsigned int pcieMsi : 1;
102 unsigned int pcieMsix : 1;
103 unsigned int nvmeCcEn : 1;
104 unsigned int nvmeCcShn : 1;
105 unsigned int mAxiWriteErr : 1;
106 unsigned int mAxiReadErr : 1;
107 unsigned int pcieMreqErr : 1;
108 unsigned int pcieCpldErr : 1;
109 unsigned int pcieCpldLenErr : 1;
110 unsigned int reserved0 : 20;
111 };
112 };
114
115typedef struct _PCIE_STATUS_REG
116{
117 union
118 {
119 unsigned int dword;
120 struct
121 {
122 unsigned int ltssm : 6;
123 unsigned int reserved0 : 2;
124 unsigned int pcieLinkUp : 1;
125 unsigned int reserved1 : 23;
126 };
127 };
129
130typedef struct _PCIE_FUNC_REG
131{
132 union
133 {
134 unsigned int dword;
135 struct
136 {
137 unsigned int busMaster : 1;
138 unsigned int msiEnable : 1;
139 unsigned int msixEnable : 1;
140 unsigned int irqDisable : 1;
141 unsigned int msiVecNum : 3;
142 unsigned int reserved0 : 25;
143 };
144 };
146
147// offset: 0x00000200, size: 4
148typedef struct _NVME_STATUS_REG
149{
150 union
151 {
152 unsigned int dword;
153 struct
154 {
155 unsigned int ccEn : 1;
156 unsigned int ccShn : 2;
157 unsigned int reserved0 : 1;
158 unsigned int cstsRdy : 1;
159 unsigned int cstsShst : 2;
160 unsigned int rstCnt : 4;
161 unsigned int linkNum : 2;
162 unsigned int linkEn : 2;
163 unsigned int reserved1 : 17;
164 };
165 };
167
168// offset: 0x00000300, size: 4
169typedef struct _NVME_CMD_FIFO_REG
170{
171 union
172 {
173 unsigned int dword;
174 struct
175 {
176 unsigned int qID : 4;
177 unsigned int reserved0 : 1; // slot_modified
178 unsigned int cmdSlotTag : P_SLOT_TAG_WIDTH; // slot_modified
179 unsigned int reserved2 : 1; // slot_modified
180 unsigned int cmdSeqNum : 8;
181 unsigned int reserved3 : (17 - P_SLOT_TAG_WIDTH); // slot_modified
182 unsigned int cmdValid : 1;
183 };
184 };
186
187// offset: 0x00000304, size: 8
188typedef struct _NVME_CPL_FIFO_REG
189{
190 union
191 {
192 unsigned int dword[3];
193 struct
194 {
195 struct
196 {
197 unsigned int cid : 16;
198 unsigned int sqId : 4;
199 unsigned int reserved0 : 12;
200 };
201
202 unsigned int specific;
203
204 unsigned short cmdSlotTag : P_SLOT_TAG_WIDTH; // slot_modified
205 unsigned short reserved1 : (14 - P_SLOT_TAG_WIDTH); // slot_modified
206 unsigned short cplType : 2;
207
208 union
209 {
210 unsigned short statusFieldWord;
211 struct
212 {
213 unsigned short reserved0 : 1;
214 unsigned short SC : 8;
215 unsigned short SCT : 3;
216 unsigned short reserved1 : 2;
217 unsigned short MORE : 1;
218 unsigned short DNR : 1;
220 };
221 };
222 };
224
225// offset: 0x0000021C, size: 4
227{
228 union
229 {
230 unsigned int dword;
231 struct
232 {
233 unsigned int cqValid : 1;
234 unsigned int sqValid : 1;
235 unsigned int cqIrqEn : 1;
236 unsigned int reserved0 : 29;
237 };
238 };
240
241// offset: 0x00000220, size: 8
243{
244 union
245 {
246 unsigned int dword[2];
247 struct
248 {
249 unsigned int pcieBaseAddrL;
250 unsigned int pcieBaseAddrH : 16; // modified
251 unsigned int valid : 1;
252 unsigned int cqVector : 4;
253 unsigned int reserved1 : 3;
254 unsigned int sqSize : 8;
255 };
256 };
258
259// offset: 0x00000260, size: 8
261{
262 union
263 {
264 unsigned int dword[2];
265 struct
266 {
267 unsigned int pcieBaseAddrL;
268 unsigned int pcieBaseAddrH : 16; // modified
269 unsigned int valid : 1;
270 unsigned int irqVector : 3;
271 unsigned int irqEn : 1;
272 unsigned int reserved1 : 3;
273 unsigned int cqSize : 8;
274 };
275 };
277
278// offset: 0x00000204, size: 4
280{
281 union
282 {
283 unsigned int dword;
284 struct
285 {
286 unsigned char directDmaRx;
287 unsigned char directDmaTx;
288 unsigned char autoDmaRx;
289 unsigned char autoDmaTx;
290 };
291 };
293
294// offset: 0x0000030C, size: 16
296{
297 union
298 {
299 unsigned int dword[5]; // slot_modified
300 struct
301 {
302 unsigned int devAddr;
303 unsigned int pcieAddrH;
304 unsigned int pcieAddrL;
305 struct
306 {
307 unsigned int dmaLen : 13;
308 unsigned int autoCompletion : 1;
309 unsigned int cmd4KBOffset : 9;
310 unsigned int reserved0 : 7; // slot_modified
311 unsigned int dmaDirection : 1;
312 unsigned int dmaType : 1;
313 };
314 unsigned int cmdSlotTag; // slot_modified
315 };
316 };
318
319// offset: 0x00002000, size: 64 * 128
320typedef struct _NVME_CMD_SRAM
321{
322 unsigned int dword[128][16];
324
325#pragma pack(pop)
326
327typedef struct _HOST_DMA_STATUS
328{
331 unsigned int directDmaTxCnt;
332 unsigned int directDmaRxCnt;
333 unsigned int autoDmaTxCnt;
334 unsigned int autoDmaRxCnt;
336
338{
342
343void dev_irq_init();
344
345void dev_irq_handler();
346
347unsigned int check_nvme_cc_en();
348
350
351void set_nvme_csts_shst(unsigned int shst);
352
353void set_nvme_admin_queue(unsigned int sqValid, unsigned int cqValid, unsigned int cqIrqEn);
354
355unsigned int get_nvme_cmd(unsigned short *qID, unsigned short *cmdSlotTag, unsigned int *cmdSeqNum,
356 unsigned int *cmdDword);
357
358void set_auto_nvme_cpl(unsigned int cmdSlotTag, unsigned int specific, unsigned int statusFieldWord);
359
360void set_nvme_slot_release(unsigned int cmdSlotTag);
361
362void set_nvme_cpl(unsigned int sqId, unsigned int cid, unsigned int specific, unsigned int statusFieldWord);
363
364void set_io_sq(unsigned int ioSqIdx, unsigned int valid, unsigned int cqVector, unsigned int qSzie,
365 unsigned int pcieBaseAddrL, unsigned int pcieBaseAddrH);
366
367void set_io_cq(unsigned int ioCqIdx, unsigned int valid, unsigned int irqEn, unsigned int irqVector,
368 unsigned int qSzie, unsigned int pcieBaseAddrL, unsigned int pcieBaseAddrH);
369
370void set_direct_tx_dma(unsigned int devAddr, unsigned int pcieAddrH, unsigned int pcieAddrL, unsigned int len);
371
372void set_direct_rx_dma(unsigned int devAddr, unsigned int pcieAddrH, unsigned int pcieAddrL, unsigned int len);
373
374void set_auto_tx_dma(unsigned int cmdSlotTag, unsigned int cmd4KBOffset, unsigned int devAddr,
375 unsigned int autoCompletion);
376
377void set_auto_rx_dma(unsigned int cmdSlotTag, unsigned int cmd4KBOffset, unsigned int devAddr,
378 unsigned int autoCompletion);
379
380void set_link_width(unsigned int linkNum);
381
382void pcie_async_reset(unsigned int rstCnt);
383
385
387
389
391
392unsigned int check_auto_tx_dma_partial_done(unsigned int tailIndex, unsigned int tailAssistIndex);
393
394unsigned int check_auto_rx_dma_partial_done(unsigned int tailIndex, unsigned int tailAssistIndex);
395
398
399#endif //__HOST_LLD_H_
struct _NVME_CMD_FIFO_REG NVME_CMD_FIFO_REG
void set_nvme_admin_queue(unsigned int sqValid, unsigned int cqValid, unsigned int cqIrqEn)
Definition: host_lld.c:225
HOST_DMA_STATUS g_hostDmaStatus
Definition: host_lld.c:63
struct _HOST_DMA_FIFO_CNT_REG HOST_DMA_FIFO_CNT_REG
#define P_SLOT_TAG_WIDTH
Definition: host_lld.h:87
struct _DEV_IRQ_REG DEV_IRQ_REG
unsigned int check_nvme_cc_en()
Definition: host_lld.c:177
void set_auto_rx_dma(unsigned int cmdSlotTag, unsigned int cmd4KBOffset, unsigned int devAddr, unsigned int autoCompletion)
Definition: host_lld.c:419
void set_link_width(unsigned int linkNum)
Definition: host_lld.c:195
struct _HOST_DMA_CMD_FIFO_REG HOST_DMA_CMD_FIFO_REG
void dev_irq_init()
Definition: host_lld.c:66
void set_nvme_csts_rdy()
struct _HOST_DMA_ASSIST_STATUS HOST_DMA_ASSIST_STATUS
struct _NVME_IO_CQ_SET_REG NVME_IO_CQ_SET_REG
void set_direct_rx_dma(unsigned int devAddr, unsigned int pcieAddrH, unsigned int pcieAddrL, unsigned int len)
Definition: host_lld.c:361
struct _NVME_CMD_SRAM _NVME_CMD_SRAM
struct _HOST_DMA_STATUS HOST_DMA_STATUS
void set_nvme_csts_shst(unsigned int shst)
Definition: host_lld.c:215
struct _NVME_CPL_FIFO_REG NVME_CPL_FIFO_REG
struct _NVME_ADMIN_QUEUE_SET_REG NVME_ADMIN_QUEUE_SET_REG
void check_direct_rx_dma_done()
Definition: host_lld.c:461
unsigned int check_auto_rx_dma_partial_done(unsigned int tailIndex, unsigned int tailAssistIndex)
Definition: host_lld.c:524
void set_auto_tx_dma(unsigned int cmdSlotTag, unsigned int cmd4KBOffset, unsigned int devAddr, unsigned int autoCompletion)
Definition: host_lld.c:385
void set_auto_nvme_cpl(unsigned int cmdSlotTag, unsigned int specific, unsigned int statusFieldWord)
Definition: host_lld.c:260
void pcie_async_reset(unsigned int rstCnt)
Definition: host_lld.c:186
void set_nvme_cpl(unsigned int sqId, unsigned int cid, unsigned int specific, unsigned int statusFieldWord)
Definition: host_lld.c:286
void check_direct_tx_dma_done()
Definition: host_lld.c:453
void check_auto_rx_dma_done()
Definition: host_lld.c:477
struct _PCIE_STATUS_REG PCIE_STATUS_REG
struct _PCIE_FUNC_REG PCIE_FUNC_REG
unsigned int check_auto_tx_dma_partial_done(unsigned int tailIndex, unsigned int tailAssistIndex)
Definition: host_lld.c:485
void check_auto_tx_dma_done()
Definition: host_lld.c:469
void set_nvme_slot_release(unsigned int cmdSlotTag)
Definition: host_lld.c:274
struct _NVME_IO_SQ_SET_REG NVME_IO_SQ_SET_REG
HOST_DMA_ASSIST_STATUS g_hostDmaAssistStatus
Definition: host_lld.c:64
unsigned int get_nvme_cmd(unsigned short *qID, unsigned short *cmdSlotTag, unsigned int *cmdSeqNum, unsigned int *cmdDword)
Definition: host_lld.c:237
void dev_irq_handler()
Definition: host_lld.c:86
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_direct_tx_dma(unsigned int devAddr, unsigned int pcieAddrH, unsigned int pcieAddrL, unsigned int len)
Definition: host_lld.c:336
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
struct _NVME_STATUS_REG NVME_STATUS_REG
unsigned int busMaster
Definition: host_lld.h:99
unsigned int dword
Definition: host_lld.h:95
unsigned int mAxiReadErr
Definition: host_lld.h:106
unsigned int pcieCpldErr
Definition: host_lld.h:108
unsigned int pcieLink
Definition: host_lld.h:98
unsigned int nvmeCcEn
Definition: host_lld.h:103
unsigned int nvmeCcShn
Definition: host_lld.h:104
unsigned int pcieMreqErr
Definition: host_lld.h:107
unsigned int mAxiWriteErr
Definition: host_lld.h:105
unsigned int pcieMsix
Definition: host_lld.h:102
unsigned int pcieIrq
Definition: host_lld.h:100
unsigned int reserved0
Definition: host_lld.h:110
unsigned int pcieMsi
Definition: host_lld.h:101
unsigned int pcieCpldLenErr
Definition: host_lld.h:109
unsigned int autoDmaRxOverFlowCnt
Definition: host_lld.h:340
unsigned int autoDmaTxOverFlowCnt
Definition: host_lld.h:339
unsigned int reserved0
Definition: host_lld.h:310
unsigned int pcieAddrH
Definition: host_lld.h:303
unsigned int devAddr
Definition: host_lld.h:302
unsigned int pcieAddrL
Definition: host_lld.h:304
unsigned int cmdSlotTag
Definition: host_lld.h:314
unsigned int dmaLen
Definition: host_lld.h:307
unsigned int cmd4KBOffset
Definition: host_lld.h:309
unsigned int autoCompletion
Definition: host_lld.h:308
unsigned int dword[5]
Definition: host_lld.h:299
unsigned int dmaType
Definition: host_lld.h:312
unsigned int dmaDirection
Definition: host_lld.h:311
unsigned int dword
Definition: host_lld.h:283
unsigned char directDmaRx
Definition: host_lld.h:286
unsigned char autoDmaRx
Definition: host_lld.h:288
unsigned char autoDmaTx
Definition: host_lld.h:289
unsigned char directDmaTx
Definition: host_lld.h:287
unsigned int directDmaRxCnt
Definition: host_lld.h:332
HOST_DMA_FIFO_CNT_REG fifoHead
Definition: host_lld.h:329
unsigned int autoDmaRxCnt
Definition: host_lld.h:334
HOST_DMA_FIFO_CNT_REG fifoTail
Definition: host_lld.h:330
unsigned int directDmaTxCnt
Definition: host_lld.h:331
unsigned int autoDmaTxCnt
Definition: host_lld.h:333
unsigned int cqIrqEn
Definition: host_lld.h:235
unsigned int cqValid
Definition: host_lld.h:233
unsigned int sqValid
Definition: host_lld.h:234
unsigned int reserved0
Definition: host_lld.h:236
unsigned int qID
Definition: host_lld.h:176
unsigned int reserved3
Definition: host_lld.h:181
unsigned int cmdSeqNum
Definition: host_lld.h:180
unsigned int dword
Definition: host_lld.h:173
unsigned int reserved2
Definition: host_lld.h:179
unsigned int reserved0
Definition: host_lld.h:177
unsigned int cmdValid
Definition: host_lld.h:182
unsigned int cmdSlotTag
Definition: host_lld.h:178
unsigned int dword[128][16]
Definition: host_lld.h:322
unsigned short DNR
Definition: host_lld.h:218
unsigned short MORE
Definition: host_lld.h:217
unsigned short SC
Definition: host_lld.h:214
unsigned short cplType
Definition: host_lld.h:206
unsigned short SCT
Definition: host_lld.h:215
unsigned short cmdSlotTag
Definition: host_lld.h:204
unsigned int specific
Definition: host_lld.h:202
unsigned int sqId
Definition: host_lld.h:198
unsigned int dword[3]
Definition: host_lld.h:192
unsigned int reserved0
Definition: host_lld.h:199
unsigned short reserved0
Definition: host_lld.h:213
unsigned short statusFieldWord
Definition: host_lld.h:210
unsigned int cid
Definition: host_lld.h:197
struct _NVME_CPL_FIFO_REG::@25::@27::@31::@33 statusField
unsigned short reserved1
Definition: host_lld.h:205
unsigned int irqEn
Definition: host_lld.h:271
unsigned int irqVector
Definition: host_lld.h:270
unsigned int pcieBaseAddrL
Definition: host_lld.h:267
unsigned int valid
Definition: host_lld.h:269
unsigned int pcieBaseAddrH
Definition: host_lld.h:268
unsigned int reserved1
Definition: host_lld.h:272
unsigned int cqSize
Definition: host_lld.h:273
unsigned int dword[2]
Definition: host_lld.h:264
unsigned int reserved1
Definition: host_lld.h:253
unsigned int sqSize
Definition: host_lld.h:254
unsigned int pcieBaseAddrH
Definition: host_lld.h:250
unsigned int cqVector
Definition: host_lld.h:252
unsigned int dword[2]
Definition: host_lld.h:246
unsigned int valid
Definition: host_lld.h:251
unsigned int pcieBaseAddrL
Definition: host_lld.h:249
unsigned int linkNum
Definition: host_lld.h:161
unsigned int reserved0
Definition: host_lld.h:157
unsigned int ccEn
Definition: host_lld.h:155
unsigned int cstsRdy
Definition: host_lld.h:158
unsigned int cstsShst
Definition: host_lld.h:159
unsigned int ccShn
Definition: host_lld.h:156
unsigned int linkEn
Definition: host_lld.h:162
unsigned int reserved1
Definition: host_lld.h:163
unsigned int rstCnt
Definition: host_lld.h:160
unsigned int dword
Definition: host_lld.h:152
unsigned int busMaster
Definition: host_lld.h:137
unsigned int reserved0
Definition: host_lld.h:142
unsigned int irqDisable
Definition: host_lld.h:140
unsigned int msiVecNum
Definition: host_lld.h:141
unsigned int dword
Definition: host_lld.h:134
unsigned int msixEnable
Definition: host_lld.h:139
unsigned int msiEnable
Definition: host_lld.h:138
unsigned int ltssm
Definition: host_lld.h:122
unsigned int reserved1
Definition: host_lld.h:125
unsigned int dword
Definition: host_lld.h:119
unsigned int pcieLinkUp
Definition: host_lld.h:124
unsigned int reserved0
Definition: host_lld.h:123