OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.74/] [tools/] [src/] [librw11/] [Rw11RdmaDisk.cpp] - Blame information for rev 38

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 29 wfjm
// $Id: Rw11RdmaDisk.cpp 648 2015-02-20 20:16:21Z mueller $
2 28 wfjm
//
3
// Copyright 2015- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4
//
5
// This program is free software; you may redistribute and/or modify it under
6
// the terms of the GNU General Public License as published by the Free
7
// Software Foundation, either version 2, or at your option any later version.
8
//
9
// This program is distributed in the hope that it will be useful, but
10
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
// for complete details.
13
// 
14
// Revision History: 
15
// Date         Rev Version  Comment
16
// 2015-01-04   628   1.0    Initial version
17
// ---------------------------------------------------------------------------
18
 
19
/*!
20
  \file
21 29 wfjm
  \version $Id: Rw11RdmaDisk.cpp 648 2015-02-20 20:16:21Z mueller $
22 28 wfjm
  \brief   Implemenation of Rw11RdmaDisk.
23
*/
24
 
25
#include "librtools/RosFill.hpp"
26
#include "librtools/RosPrintf.hpp"
27
#include "librtools/Rexception.hpp"
28
 
29
#include "Rw11RdmaDisk.hpp"
30
 
31
using namespace std;
32
 
33
/*!
34
  \class Retro::Rw11RdmaDisk
35
  \brief FIXME_docs
36
*/
37
 
38
// all method definitions in namespace Retro
39
namespace Retro {
40
 
41
//------------------------------------------+-----------------------------------
42
//! Constructor
43
 
44
Rw11RdmaDisk::Rw11RdmaDisk(Rw11Cntl* pcntl, const precb_t& precb,
45
                           const postcb_t& postcb)
46
  : Rw11Rdma(pcntl, precb, postcb),
47
    fBuf(),
48
    fpUnit(nullptr),
49
    fNWord(0),
50
    fNBlock(0),
51
    fLba()
52
{
53
  fStats.Define(kStatNWritePadded, "NWritePadded" , "padded disk write");
54
  fStats.Define(kStatNWChkFail,    "NWChkFail"    , "write check failed");
55
}
56
 
57
//------------------------------------------+-----------------------------------
58
//! Destructor
59
 
60
Rw11RdmaDisk::~Rw11RdmaDisk()
61
{}
62
 
63
//------------------------------------------+-----------------------------------
64
//! FIXME_docs
65
 
66
void Rw11RdmaDisk::QueueDiskRead(uint32_t addr, size_t size, uint16_t mode,
67
                                 uint32_t lba, Rw11UnitDisk* punit)
68
{
69
  SetupDisk(size, lba, punit, kFuncRead);
70
  QueueWMem(addr, fBuf.data(), size, mode);
71
  return;
72
}
73
 
74
//------------------------------------------+-----------------------------------
75
//! FIXME_docs
76
 
77
void Rw11RdmaDisk::QueueDiskWrite(uint32_t addr,size_t size, uint16_t mode,
78
                                  uint32_t lba, Rw11UnitDisk* punit)
79
{
80
  SetupDisk(size, lba, punit, kFuncWrite);
81
  QueueRMem(addr, fBuf.data(), size, mode);
82
  return;
83
}
84
 
85
//------------------------------------------+-----------------------------------
86
//! FIXME_docs
87
 
88
void Rw11RdmaDisk::QueueDiskWriteCheck(uint32_t addr, size_t size,
89
                                       uint16_t mode, uint32_t lba,
90
                                       Rw11UnitDisk* punit)
91
{
92
  SetupDisk(size, lba, punit, kFuncWriteCheck);
93
  QueueRMem(addr, fBuf.data(), size, mode);
94
  return;
95
}
96
 
97
//------------------------------------------+-----------------------------------
98
//! FIXME_docs
99
 
100 29 wfjm
size_t Rw11RdmaDisk::WriteCheck(size_t nwdone)
101 28 wfjm
{
102 29 wfjm
  if (nwdone == 0) return 0;
103 28 wfjm
 
104
  size_t bszwrd = fpUnit->BlockSize()/2;    // block size in words
105 29 wfjm
  size_t nblk   = (nwdone+bszwrd-1)/bszwrd;
106 28 wfjm
  size_t dsize  = nblk*bszwrd;
107
 
108
  std::vector<uint16_t>  dbuf(dsize);
109
  RerrMsg emsg;
110
  bool rc = fpUnit->VirtRead(fLba, nblk,
111
                             reinterpret_cast<uint8_t*>(dbuf.data()), emsg);
112
  if (!rc) throw Rexception("Rw11RdmaDisk::WriteCheck()",
113
                            "VirtRead() failed: ", emsg);
114
 
115
  uint16_t* pdsk = dbuf.data();
116
  uint16_t* pmem = fBuf.data();
117 29 wfjm
  for (size_t i=0; i<nwdone; i++) {
118 28 wfjm
    if (*pdsk++ != *pmem++) {
119
      fStats.Inc(kStatNWChkFail);
120
      return i;
121
    }
122
  }
123
 
124 29 wfjm
  return nwdone;
125 28 wfjm
}
126
 
127
//------------------------------------------+-----------------------------------
128
//! FIXME_docs
129
 
130
void Rw11RdmaDisk::Dump(std::ostream& os, int ind, const char* text) const
131
{
132
  RosFill bl(ind);
133
  os << bl << (text?text:"--") << "Rw11RdmaDisk @ " << this << endl;
134
  os << bl << "  fBuf.size()      " << RosPrintf(fBuf.size(),"d",5) << endl;
135
  os << bl << "  fpUnit:          " << fpUnit << endl;
136
  os << bl << "  fNWord:          " << RosPrintf(fNWord,"d",5) << endl;
137
  os << bl << "  fNBlock:         " << RosPrintf(fNBlock,"d",5) << endl;
138
  os << bl << "  fLba:            " << RosPrintf(fLba,"d",8) << endl;
139
  os << bl << "  fFunc:           " << fFunc << endl;
140
 
141
  Rw11Rdma::Dump(os, ind, " ^");
142
  return;
143
}
144
 
145
//------------------------------------------+-----------------------------------
146
//! FIXME_docs
147
 
148
void Rw11RdmaDisk::SetupDisk(size_t size, uint32_t lba, Rw11UnitDisk* punit,
149
                             Rw11RdmaDisk::func func)
150
{
151
  fpUnit = punit;
152
  size_t bszwrd = fpUnit->BlockSize()/2;    // block size in words
153
 
154
  fNWord  = size;
155
  fNBlock = (fNWord+bszwrd-1)/bszwrd;
156
  fLba    = lba;
157
  fFunc   = func;
158
 
159
  size_t tsize = fNBlock*bszwrd;
160
  if (fBuf.size() < tsize) fBuf.resize(tsize);
161
 
162
  return;
163
}
164
 
165
//------------------------------------------+-----------------------------------
166
//! FIXME_docs
167
 
168
void Rw11RdmaDisk::PreRdmaHook()
169
{
170
  if (fFunc != kFuncRead) return;          // quit unless read request
171
 
172
  RerrMsg emsg;
173
  bool rc = fpUnit->VirtRead(fLba, fNBlock,
174
                             reinterpret_cast<uint8_t*>(fBuf.data()), emsg);
175
  if (!rc) throw Rexception("Rw11RdmaDisk::PreRdmaHook()",
176
                            "VirtRead() failed: ", emsg);
177
  return;
178
}
179
 
180
//------------------------------------------+-----------------------------------
181
//! FIXME_docs
182
 
183 29 wfjm
void Rw11RdmaDisk::PostRdmaHook(size_t nwdone)
184 28 wfjm
{
185 29 wfjm
  if (nwdone == 0) return;                  // quit if rdma failed early
186 28 wfjm
  if (fFunc != kFuncWrite) return;          // quit unless write request
187
 
188
  size_t bszwrd = fpUnit->BlockSize()/2;    // block size in words
189 29 wfjm
  size_t nblock = (nwdone+bszwrd-1)/bszwrd;
190
  size_t npad   = nblock*bszwrd - nwdone;
191 28 wfjm
 
192
  // if an incomplete block was read, pad it with hex dead
193
  if (npad) {
194
    fStats.Inc(kStatNWritePadded);
195 29 wfjm
    uint16_t* p = fBuf.data()+nwdone;
196 28 wfjm
    for (size_t i=0; i<npad; i++) *p++ = 0xdead;
197
  }
198
 
199
  RerrMsg emsg;
200
  bool rc = fpUnit->VirtWrite(fLba, nblock,
201
                              reinterpret_cast<uint8_t*>(fBuf.data()), emsg);
202
  if (!rc) throw Rexception("Rw11RdmaDisk::PostRdmaHook()",
203
                            "VirtWrite() failed: ", emsg);
204
  return;
205
}
206
 
207
 
208
} // end namespace Retro

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.