w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
Rw11RdmaDisk.cpp
Go to the documentation of this file.
1// $Id: Rw11RdmaDisk.cpp 1186 2019-07-12 17:49:59Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2015-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2018-09-16 1047 1.0.2 coverity fixup (uninitialized scalar)
8// 2017-04-02 865 1.0.1 Dump(): add detail arg
9// 2015-01-04 628 1.0 Initial version
10// ---------------------------------------------------------------------------
11
16#include "librtools/RosFill.hpp"
19
20#include "Rw11RdmaDisk.hpp"
21
22using namespace std;
23
29// all method definitions in namespace Retro
30namespace Retro {
31
32//------------------------------------------+-----------------------------------
34
36 : Rw11Rdma(pcntl, move(precb), move(postcb)),
37 fBuf(),
38 fpUnit(nullptr),
39 fNWord(0),
40 fNBlock(0),
41 fLba(),
42 fFunc(kFuncRead)
43{
44 fStats.Define(kStatNWritePadded, "NWritePadded" , "padded disk write");
45 fStats.Define(kStatNWChkFail, "NWChkFail" , "write check failed");
46}
47
48//------------------------------------------+-----------------------------------
50
52{}
53
54//------------------------------------------+-----------------------------------
56
57void Rw11RdmaDisk::QueueDiskRead(uint32_t addr, size_t size, uint16_t mode,
58 uint32_t lba, Rw11UnitDisk* punit)
59{
60 SetupDisk(size, lba, punit, kFuncRead);
61 QueueWMem(addr, fBuf.data(), size, mode);
62 return;
63}
64
65//------------------------------------------+-----------------------------------
67
68void Rw11RdmaDisk::QueueDiskWrite(uint32_t addr,size_t size, uint16_t mode,
69 uint32_t lba, Rw11UnitDisk* punit)
70{
71 SetupDisk(size, lba, punit, kFuncWrite);
72 QueueRMem(addr, fBuf.data(), size, mode);
73 return;
74}
75
76//------------------------------------------+-----------------------------------
78
79void Rw11RdmaDisk::QueueDiskWriteCheck(uint32_t addr, size_t size,
80 uint16_t mode, uint32_t lba,
81 Rw11UnitDisk* punit)
82{
83 SetupDisk(size, lba, punit, kFuncWriteCheck);
84 QueueRMem(addr, fBuf.data(), size, mode);
85 return;
86}
87
88//------------------------------------------+-----------------------------------
90
91size_t Rw11RdmaDisk::WriteCheck(size_t nwdone)
92{
93 if (nwdone == 0) return 0;
94
95 size_t bszwrd = fpUnit->BlockSize()/2; // block size in words
96 size_t nblk = (nwdone+bszwrd-1)/bszwrd;
97 size_t dsize = nblk*bszwrd;
98
99 std::vector<uint16_t> dbuf(dsize);
100 RerrMsg emsg;
101 bool rc = fpUnit->VirtRead(fLba, nblk,
102 reinterpret_cast<uint8_t*>(dbuf.data()), emsg);
103 if (!rc) throw Rexception("Rw11RdmaDisk::WriteCheck()",
104 "VirtRead() failed: ", emsg);
105
106 uint16_t* pdsk = dbuf.data();
107 uint16_t* pmem = fBuf.data();
108 for (size_t i=0; i<nwdone; i++) {
109 if (*pdsk++ != *pmem++) {
111 return i;
112 }
113 }
114
115 return nwdone;
116}
117
118//------------------------------------------+-----------------------------------
120
121void Rw11RdmaDisk::Dump(std::ostream& os, int ind, const char* text,
122 int detail) const
123{
124 RosFill bl(ind);
125 os << bl << (text?text:"--") << "Rw11RdmaDisk @ " << this << endl;
126 os << bl << " fBuf.size: " << RosPrintf(fBuf.size(),"d",5) << endl;
127 os << bl << " fpUnit: " << fpUnit << endl;
128 os << bl << " fNWord: " << RosPrintf(fNWord,"d",5) << endl;
129 os << bl << " fNBlock: " << RosPrintf(fNBlock,"d",5) << endl;
130 os << bl << " fLba: " << RosPrintf(fLba,"d",8) << endl;
131 os << bl << " fFunc: " << fFunc << endl;
132
133 Rw11Rdma::Dump(os, ind, " ^", detail);
134 return;
135}
136
137//------------------------------------------+-----------------------------------
139
140void Rw11RdmaDisk::SetupDisk(size_t size, uint32_t lba, Rw11UnitDisk* punit,
142{
143 fpUnit = punit;
144 size_t bszwrd = fpUnit->BlockSize()/2; // block size in words
145
146 fNWord = size;
147 fNBlock = (fNWord+bszwrd-1)/bszwrd;
148 fLba = lba;
149 fFunc = func;
150
151 size_t tsize = fNBlock*bszwrd;
152 if (fBuf.size() < tsize) fBuf.resize(tsize);
153
154 return;
155}
156
157//------------------------------------------+-----------------------------------
159
161{
162 if (fFunc != kFuncRead) return; // quit unless read request
163
164 RerrMsg emsg;
165 bool rc = fpUnit->VirtRead(fLba, fNBlock,
166 reinterpret_cast<uint8_t*>(fBuf.data()), emsg);
167 if (!rc) throw Rexception("Rw11RdmaDisk::PreRdmaHook()",
168 "VirtRead() failed: ", emsg);
169 return;
170}
171
172//------------------------------------------+-----------------------------------
174
175void Rw11RdmaDisk::PostRdmaHook(size_t nwdone)
176{
177 if (nwdone == 0) return; // quit if rdma failed early
178 if (fFunc != kFuncWrite) return; // quit unless write request
179
180 size_t bszwrd = fpUnit->BlockSize()/2; // block size in words
181 size_t nblock = (nwdone+bszwrd-1)/bszwrd;
182 size_t npad = nblock*bszwrd - nwdone;
183
184 // if an incomplete block was read, pad it with hex dead
185 if (npad) {
187 uint16_t* p = fBuf.data()+nwdone;
188 for (size_t i=0; i<npad; i++) *p++ = 0xdead;
189 }
190
191 RerrMsg emsg;
192 bool rc = fpUnit->VirtWrite(fLba, nblock,
193 reinterpret_cast<uint8_t*>(fBuf.data()), emsg);
194 if (!rc) throw Rexception("Rw11RdmaDisk::PostRdmaHook()",
195 "VirtWrite() failed: ", emsg);
196 return;
197}
198
199
200} // end namespace Retro
FIXME_docs.
Definition: RerrMsg.hpp:25
FIXME_docs.
Definition: Rexception.hpp:29
I/O appicator to generate fill characters.
Definition: RosFill.hpp:24
void Inc(size_t ind, double val=1.)
FIXME_docs.
Definition: Rstats.ipp:29
void Define(size_t ind, const std::string &name, const std::string &text)
FIXME_docs.
Definition: Rstats.cpp:72
FIXME_docs.
Definition: Rw11Cntl.hpp:42
~Rw11RdmaDisk()
Destructor.
std::vector< uint16_t > fBuf
data buffer
Rw11UnitDisk * fpUnit
UnitDisk to read VirtDisk.
size_t fNWord
words to transfer
virtual void PreRdmaHook()
FIXME_docs.
size_t fNBlock
disk blocks to transfer
virtual void PostRdmaHook(size_t nwdone)
FIXME_docs.
size_t fLba
disk lba
void QueueDiskWrite(uint32_t addr, size_t size, uint16_t mode, uint32_t lba, Rw11UnitDisk *punit)
FIXME_docs.
void SetupDisk(size_t size, uint32_t lba, Rw11UnitDisk *punit, Rw11RdmaDisk::func func)
FIXME_docs.
@ kFuncWriteCheck
write check function
@ kFuncRead
read function
@ kFuncWrite
write function
@ kStatNWritePadded
padded disk write
@ kStatNWChkFail
write check failed
void QueueDiskWriteCheck(uint32_t addr, size_t size, uint16_t mode, uint32_t lba, Rw11UnitDisk *punit)
FIXME_docs.
Rw11RdmaDisk(Rw11Cntl *pcntl, precb_t &&precb, postcb_t &&postcb)
Constructor.
virtual void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
size_t WriteCheck(size_t nwdone)
FIXME_docs.
void QueueDiskRead(uint32_t addr, size_t size, uint16_t mode, uint32_t lba, Rw11UnitDisk *punit)
FIXME_docs.
enum func fFunc
current function
FIXME_docs.
Definition: Rw11Rdma.hpp:34
virtual void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
Definition: Rw11Rdma.cpp:110
std::function< void(int, size_t, RlinkCommandList &, size_t)> postcb_t
Definition: Rw11Rdma.hpp:40
void QueueWMem(uint32_t addr, const uint16_t *block, size_t size, uint16_t mode)
FIXME_docs.
Definition: Rw11Rdma.cpp:98
std::function< void(int, size_t, size_t, RlinkCommandList &)> precb_t
Definition: Rw11Rdma.hpp:38
void QueueRMem(uint32_t addr, uint16_t *block, size_t size, uint16_t mode)
FIXME_docs.
Definition: Rw11Rdma.cpp:86
Rstats fStats
statistics
Definition: Rw11Rdma.hpp:109
bool VirtWrite(size_t lba, size_t nblk, const uint8_t *data, RerrMsg &emsg)
FIXME_docs.
size_t BlockSize() const
FIXME_docs.
bool VirtRead(size_t lba, size_t nblk, uint8_t *data, RerrMsg &emsg)
FIXME_docs.
RosPrintfS< bool > RosPrintf(bool value, const char *form=0, int width=0, int prec=0)
Creates a print object for the formatted output of a bool value.
Definition: RosPrintf.ipp:38
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47