-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdata_buffer_ccmd.c
188 lines (163 loc) · 7.46 KB
/
data_buffer_ccmd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include "xil_printf.h"
#include <assert.h>
#include "memory_map.h"
P_CCMD_DATA_BUF_MAP ccmdDataBufMapPtr;
CCMD_DATA_BUF_LRU_LIST ccmdDataBufLruList;
P_CCMD_DATA_BUF_HASH_TABLE ccmdDataBufHashTablePtr;
void InitCcmdDataBuf()
{
int bufEntry;
ccmdDataBufMapPtr = (P_CCMD_DATA_BUF_MAP) CCMD_DATA_BUF_MAP_ADDR;
ccmdDataBufHashTablePtr = (P_CCMD_DATA_BUF_HASH_TABLE)CCMD_DATA_BUF_HASH_TABLE_ADDR;
for(bufEntry = 0; bufEntry < AVAILABLE_CCMD_DATA_BUFFER_ENTRY_COUNT; bufEntry++)
{
ccmdDataBufMapPtr->dataBuf[bufEntry].logicalSliceAddr = LSA_NONE;
ccmdDataBufMapPtr->dataBuf[bufEntry].prevEntry = bufEntry-1;
ccmdDataBufMapPtr->dataBuf[bufEntry].nextEntry = bufEntry+1;
ccmdDataBufMapPtr->dataBuf[bufEntry].dirty = DATA_BUF_CLEAN;
ccmdDataBufMapPtr->dataBuf[bufEntry].blockingReqTail = REQ_SLOT_TAG_NONE;
ccmdDataBufHashTablePtr->dataBufHash[bufEntry].headEntry = DATA_BUF_NONE;
ccmdDataBufHashTablePtr->dataBufHash[bufEntry].tailEntry = DATA_BUF_NONE;
ccmdDataBufMapPtr->dataBuf[bufEntry].hashPrevEntry = DATA_BUF_NONE;
ccmdDataBufMapPtr->dataBuf[bufEntry].hashNextEntry = DATA_BUF_NONE;
}
ccmdDataBufMapPtr->dataBuf[0].prevEntry = DATA_BUF_NONE;
ccmdDataBufMapPtr->dataBuf[AVAILABLE_CCMD_DATA_BUFFER_ENTRY_COUNT - 1].nextEntry = DATA_BUF_NONE;
ccmdDataBufLruList.headEntry = 0 ;
ccmdDataBufLruList.tailEntry = AVAILABLE_CCMD_DATA_BUFFER_ENTRY_COUNT - 1;
}
unsigned int CheckCcmdDataBufHit(unsigned int reqSlotTag)
{
unsigned int bufEntry, logicalSliceAddr, prevBufEntry, nextBufEntry;
logicalSliceAddr = reqPoolPtr->reqPool[reqSlotTag].logicalSliceAddr;
bufEntry = ccmdDataBufHashTablePtr->dataBufHash[FindCcmdDataBufHashTableEntry(logicalSliceAddr)].headEntry;
while(bufEntry != DATA_BUF_NONE)
{
if(ccmdDataBufMapPtr->dataBuf[bufEntry].logicalSliceAddr == logicalSliceAddr)
{
prevBufEntry = ccmdDataBufMapPtr->dataBuf[bufEntry].prevEntry;
nextBufEntry = ccmdDataBufMapPtr->dataBuf[bufEntry].nextEntry;
if((nextBufEntry != DATA_BUF_NONE) && (prevBufEntry != DATA_BUF_NONE))
{
ccmdDataBufMapPtr->dataBuf[prevBufEntry].nextEntry = ccmdDataBufMapPtr->dataBuf[bufEntry].nextEntry;
ccmdDataBufMapPtr->dataBuf[nextBufEntry].prevEntry = ccmdDataBufMapPtr->dataBuf[bufEntry].prevEntry;
}
else if((nextBufEntry == DATA_BUF_NONE) && (prevBufEntry != DATA_BUF_NONE))
{
ccmdDataBufMapPtr->dataBuf[prevBufEntry].nextEntry = DATA_BUF_NONE;
ccmdDataBufLruList.tailEntry = ccmdDataBufMapPtr->dataBuf[bufEntry].prevEntry;
}
else if((nextBufEntry != DATA_BUF_NONE) && (prevBufEntry == DATA_BUF_NONE))
{
ccmdDataBufMapPtr->dataBuf[nextBufEntry].prevEntry = DATA_BUF_NONE;
ccmdDataBufLruList.headEntry = ccmdDataBufMapPtr->dataBuf[bufEntry].nextEntry;
}
else
{
ccmdDataBufLruList.tailEntry = DATA_BUF_NONE;
ccmdDataBufLruList.headEntry = DATA_BUF_NONE;
}
if(ccmdDataBufLruList.headEntry != DATA_BUF_NONE)
{
ccmdDataBufMapPtr->dataBuf[bufEntry].prevEntry = DATA_BUF_NONE;
ccmdDataBufMapPtr->dataBuf[bufEntry].nextEntry = ccmdDataBufLruList.headEntry;
ccmdDataBufMapPtr->dataBuf[ccmdDataBufLruList.headEntry].prevEntry = bufEntry;
ccmdDataBufLruList.headEntry = bufEntry;
}
else
{
ccmdDataBufMapPtr->dataBuf[bufEntry].prevEntry = DATA_BUF_NONE;
ccmdDataBufMapPtr->dataBuf[bufEntry].nextEntry = DATA_BUF_NONE;
ccmdDataBufLruList.headEntry = bufEntry;
ccmdDataBufLruList.tailEntry = bufEntry;
}
return bufEntry;
}
else
bufEntry = ccmdDataBufMapPtr->dataBuf[bufEntry].hashNextEntry;
}
return DATA_BUF_FAIL;
}
unsigned int AllocateCcmdDataBuf()
{
unsigned int evictedEntry = ccmdDataBufLruList.tailEntry;
if(evictedEntry == DATA_BUF_NONE)
assert(!"[WARNING] There is no valid buffer entry [WARNING]");
if(ccmdDataBufMapPtr->dataBuf[evictedEntry].prevEntry != DATA_BUF_NONE)
{
ccmdDataBufMapPtr->dataBuf[ccmdDataBufMapPtr->dataBuf[evictedEntry].prevEntry].nextEntry = DATA_BUF_NONE;
ccmdDataBufLruList.tailEntry = ccmdDataBufMapPtr->dataBuf[evictedEntry].prevEntry;
ccmdDataBufMapPtr->dataBuf[evictedEntry].prevEntry = DATA_BUF_NONE;
ccmdDataBufMapPtr->dataBuf[evictedEntry].nextEntry = ccmdDataBufLruList.headEntry;
ccmdDataBufMapPtr->dataBuf[ccmdDataBufLruList.headEntry].prevEntry = evictedEntry;
ccmdDataBufLruList.headEntry = evictedEntry;
}
else
{
ccmdDataBufMapPtr->dataBuf[evictedEntry].prevEntry = DATA_BUF_NONE;
ccmdDataBufMapPtr->dataBuf[evictedEntry].nextEntry = DATA_BUF_NONE;
ccmdDataBufLruList.headEntry = evictedEntry;
ccmdDataBufLruList.tailEntry = evictedEntry;
}
SelectiveGetFromCcmdDataBufHashList(evictedEntry);
return evictedEntry;
}
void UpdateCcmdDataBufEntryInfoBlockingReq(unsigned int bufEntry, unsigned int reqSlotTag)
{
if(ccmdDataBufMapPtr->dataBuf[bufEntry].blockingReqTail != REQ_SLOT_TAG_NONE)
{
reqPoolPtr->reqPool[reqSlotTag].prevBlockingReq = ccmdDataBufMapPtr->dataBuf[bufEntry].blockingReqTail;
reqPoolPtr->reqPool[reqPoolPtr->reqPool[reqSlotTag].prevBlockingReq].nextBlockingReq = reqSlotTag;
}
ccmdDataBufMapPtr->dataBuf[bufEntry].blockingReqTail = reqSlotTag;
GetTimeBlockedBufferDef(reqPoolPtr->reqPool[reqSlotTag].nvmeCmdSlotTag);
}
void PutToCcmdDataBufHashList(unsigned int bufEntry)
{
unsigned int hashEntry;
hashEntry = FindCcmdDataBufHashTableEntry(ccmdDataBufMapPtr->dataBuf[bufEntry].logicalSliceAddr);
if(ccmdDataBufHashTablePtr->dataBufHash[hashEntry].tailEntry != DATA_BUF_NONE)
{
ccmdDataBufMapPtr->dataBuf[bufEntry].hashPrevEntry = ccmdDataBufHashTablePtr->dataBufHash[hashEntry].tailEntry ;
ccmdDataBufMapPtr->dataBuf[bufEntry].hashNextEntry = REQ_SLOT_TAG_NONE;
ccmdDataBufMapPtr->dataBuf[ccmdDataBufHashTablePtr->dataBufHash[hashEntry].tailEntry].hashNextEntry = bufEntry;
ccmdDataBufHashTablePtr->dataBufHash[hashEntry].tailEntry = bufEntry;
}
else
{
ccmdDataBufMapPtr->dataBuf[bufEntry].hashPrevEntry = REQ_SLOT_TAG_NONE;
ccmdDataBufMapPtr->dataBuf[bufEntry].hashNextEntry = REQ_SLOT_TAG_NONE;
ccmdDataBufHashTablePtr->dataBufHash[hashEntry].headEntry = bufEntry;
ccmdDataBufHashTablePtr->dataBufHash[hashEntry].tailEntry = bufEntry;
}
}
void SelectiveGetFromCcmdDataBufHashList(unsigned int bufEntry)
{
if(ccmdDataBufMapPtr->dataBuf[bufEntry].logicalSliceAddr != LSA_NONE)
{
unsigned int prevBufEntry, nextBufEntry, hashEntry;
prevBufEntry = ccmdDataBufMapPtr->dataBuf[bufEntry].hashPrevEntry;
nextBufEntry = ccmdDataBufMapPtr->dataBuf[bufEntry].hashNextEntry;
hashEntry = FindCcmdDataBufHashTableEntry(ccmdDataBufMapPtr->dataBuf[bufEntry].logicalSliceAddr);
if((nextBufEntry != DATA_BUF_NONE) && (prevBufEntry != DATA_BUF_NONE))
{
ccmdDataBufMapPtr->dataBuf[prevBufEntry].hashNextEntry = nextBufEntry;
ccmdDataBufMapPtr->dataBuf[nextBufEntry].hashPrevEntry = prevBufEntry;
}
else if((nextBufEntry == DATA_BUF_NONE) && (prevBufEntry != DATA_BUF_NONE))
{
ccmdDataBufMapPtr->dataBuf[prevBufEntry].hashNextEntry = DATA_BUF_NONE;
ccmdDataBufHashTablePtr->dataBufHash[hashEntry].tailEntry = prevBufEntry;
}
else if((nextBufEntry != DATA_BUF_NONE) && (prevBufEntry == DATA_BUF_NONE))
{
ccmdDataBufMapPtr->dataBuf[nextBufEntry].hashPrevEntry = DATA_BUF_NONE;
ccmdDataBufHashTablePtr->dataBufHash[hashEntry].headEntry = nextBufEntry;
}
else
{
ccmdDataBufHashTablePtr->dataBufHash[hashEntry].headEntry = DATA_BUF_NONE;
ccmdDataBufHashTablePtr->dataBufHash[hashEntry].tailEntry = DATA_BUF_NONE;
}
}
}