OpenSSD Cosmos+ Platform Firmware  0.0.2
The firmware of Cosmos+ OpenSSD Platform for TOSHIBA nand flash module.
nvme_io_cmd.c
Go to the documentation of this file.
1
2// nvme_io_cmd.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//
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 IO Command Handler
34// File Name: nvme_io_cmd.c
35//
36// Version: v1.0.1
37//
38// Description:
39// - handles NVMe IO command
41
43// Revision History:
44//
45// * v1.0.1
46// - header file for buffer is changed from "ia_lru_buffer.h" to "lru_buffer.h"
47//
48// * v1.0.0
49// - First draft
51
52#include "xil_printf.h"
53#include "debug.h"
54#include "io_access.h"
55
56#include "nvme.h"
57#include "host_lld.h"
58#include "nvme_io_cmd.h"
59
60#include "../ftl_config.h"
61#include "../request_transform.h"
62
72void handle_nvme_io_read(unsigned int cmdSlotTag, NVME_IO_COMMAND *nvmeIOCmd)
73{
74 IO_READ_COMMAND_DW12 readInfo12;
75 // IO_READ_COMMAND_DW13 readInfo13;
76 // IO_READ_COMMAND_DW15 readInfo15;
77 unsigned int startLba[2];
78 unsigned int nlb;
79
80 readInfo12.dword = nvmeIOCmd->dword[12];
81 // readInfo13.dword = nvmeIOCmd->dword[13];
82 // readInfo15.dword = nvmeIOCmd->dword[15];
83
84 startLba[0] = nvmeIOCmd->dword[10];
85 startLba[1] = nvmeIOCmd->dword[11];
86 nlb = readInfo12.NLB;
87
88 ASSERT(startLba[0] < storageCapacity_L && (startLba[1] < STORAGE_CAPACITY_H || startLba[1] == 0));
89 // ASSERT(nlb < MAX_NUM_OF_NLB);
90 ASSERT((nvmeIOCmd->PRP1[0] & 0x3) == 0 && (nvmeIOCmd->PRP2[0] & 0x3) == 0); // error
91 ASSERT(nvmeIOCmd->PRP1[1] < 0x10000 && nvmeIOCmd->PRP2[1] < 0x10000);
92
93 ReqTransNvmeToSlice(cmdSlotTag, startLba[0], nlb, IO_NVM_READ);
94}
95
99void handle_nvme_io_write(unsigned int cmdSlotTag, NVME_IO_COMMAND *nvmeIOCmd)
100{
101 IO_READ_COMMAND_DW12 writeInfo12;
102 // IO_READ_COMMAND_DW13 writeInfo13;
103 // IO_READ_COMMAND_DW15 writeInfo15;
104 unsigned int startLba[2];
105 unsigned int nlb;
106
107 writeInfo12.dword = nvmeIOCmd->dword[12];
108 // writeInfo13.dword = nvmeIOCmd->dword[13];
109 // writeInfo15.dword = nvmeIOCmd->dword[15];
110
111 // if(writeInfo12.FUA == 1)
112 // xil_printf("write FUA\r\n");
113
114 startLba[0] = nvmeIOCmd->dword[10];
115 startLba[1] = nvmeIOCmd->dword[11];
116 nlb = writeInfo12.NLB;
117
118 ASSERT(startLba[0] < storageCapacity_L && (startLba[1] < STORAGE_CAPACITY_H || startLba[1] == 0));
119 // ASSERT(nlb < MAX_NUM_OF_NLB);
120 ASSERT((nvmeIOCmd->PRP1[0] & 0xF) == 0 && (nvmeIOCmd->PRP2[0] & 0xF) == 0);
121 ASSERT(nvmeIOCmd->PRP1[1] < 0x10000 && nvmeIOCmd->PRP2[1] < 0x10000);
122
123 ReqTransNvmeToSlice(cmdSlotTag, startLba[0], nlb, IO_NVM_WRITE);
124}
125
127{
128 NVME_IO_COMMAND *nvmeIOCmd;
129 NVME_COMPLETION nvmeCPL;
130 unsigned int opc;
131
132 nvmeIOCmd = (NVME_IO_COMMAND *)nvmeCmd->cmdDword;
133 /* xil_printf("OPC = 0x%X\r\n", nvmeIOCmd->OPC);
134 xil_printf("PRP1[63:32] = 0x%X, PRP1[31:0] = 0x%X\r\n", nvmeIOCmd->PRP1[1],
135 nvmeIOCmd->PRP1[0]); xil_printf("PRP2[63:32] = 0x%X, PRP2[31:0] = 0x%X\r\n", nvmeIOCmd->PRP2[1],
136 nvmeIOCmd->PRP2[0]); xil_printf("dword10 = 0x%X\r\n", nvmeIOCmd->dword10); xil_printf("dword11 = 0x%X\r\n",
137 nvmeIOCmd->dword11); xil_printf("dword12 = 0x%X\r\n", nvmeIOCmd->dword12);*/
138
139 opc = (unsigned int)nvmeIOCmd->OPC;
140
141 switch (opc)
142 {
143 case IO_NVM_FLUSH:
144 {
145 xil_printf("IO Flush Command\r\n");
146 nvmeCPL.dword[0] = 0;
147 nvmeCPL.specific = 0x0;
148 set_auto_nvme_cpl(nvmeCmd->cmdSlotTag, nvmeCPL.specific, nvmeCPL.statusFieldWord);
149 break;
150 }
151 case IO_NVM_WRITE:
152 {
153 // xil_printf("IO Write Command\r\n");
154 handle_nvme_io_write(nvmeCmd->cmdSlotTag, nvmeIOCmd);
155 break;
156 }
157 case IO_NVM_READ:
158 {
159 // xil_printf("IO Read Command\r\n");
160 handle_nvme_io_read(nvmeCmd->cmdSlotTag, nvmeIOCmd);
161 break;
162 }
163 default:
164 {
165 xil_printf("Not Support IO Command OPC: %X\r\n", opc);
166 ASSERT(0);
167 break;
168 }
169 }
170}
#define ASSERT(cond,...)
Definition: debug.h:96
unsigned int storageCapacity_L
Definition: ftl_config.c:56
void set_auto_nvme_cpl(unsigned int cmdSlotTag, unsigned int specific, unsigned int statusFieldWord)
Definition: host_lld.c:260
#define IO_NVM_FLUSH
Definition: nvme.h:83
#define STORAGE_CAPACITY_H
Definition: nvme.h:60
#define IO_NVM_READ
Definition: nvme.h:85
#define IO_NVM_WRITE
Definition: nvme.h:84
void handle_nvme_io_write(unsigned int cmdSlotTag, NVME_IO_COMMAND *nvmeIOCmd)
Definition: nvme_io_cmd.c:99
void handle_nvme_io_read(unsigned int cmdSlotTag, NVME_IO_COMMAND *nvmeIOCmd)
The entry function for translating the given NVMe command into slice requests.
Definition: nvme_io_cmd.c:72
void handle_nvme_io_cmd(NVME_COMMAND *nvmeCmd)
Definition: nvme_io_cmd.c:126
void ReqTransNvmeToSlice(unsigned int cmdSlotTag, unsigned int startLba, unsigned int nlb, unsigned int cmdCode)
Split NVMe command into slice requests.
unsigned int dword
Definition: nvme.h:845
unsigned short NLB
Definition: nvme.h:849
unsigned short cmdSlotTag
Definition: nvme.h:208
unsigned int cmdDword[16]
Definition: nvme.h:233
The main structure of completion queue entry.
Definition: nvme.h:350
unsigned int specific
Definition: nvme.h:370
unsigned short statusFieldWord
Definition: nvme.h:358
unsigned int dword[2]
Definition: nvme.h:353
unsigned int dword[16]
Definition: nvme.h:291
unsigned int PRP1[2]
Definition: nvme.h:324
unsigned char OPC
Definition: nvme.h:296
unsigned int PRP2[2]
Definition: nvme.h:325