Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/dev/aacraid/aacraid_endian.c
39562 views
1
/*-
2
* SPDX-License-Identifier: BSD-2-Clause
3
*
4
* Copyright (c) 2019 Leandro Lupori
5
*
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
8
* are met:
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
*
15
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
* SUCH DAMAGE.
26
*/
27
28
#include <sys/param.h>
29
#include <sys/types.h>
30
31
#include <dev/aacraid/aacraid_reg.h>
32
#include <dev/aacraid/aacraid_endian.h>
33
34
#if _BYTE_ORDER != _LITTLE_ENDIAN
35
36
#define TOH2(field, bits) field = le##bits##toh(field)
37
#define TOH(field, bits) TOH2(field, bits)
38
39
#define TOLE2(field, bits) field = htole##bits(field)
40
#define TOLE(field, bits) TOLE2(field, bits)
41
42
/* Convert from Little-Endian to host order (TOH) */
43
44
void
45
aac_fib_header_toh(struct aac_fib_header *ptr)
46
{
47
TOH(ptr->XferState, 32);
48
TOH(ptr->Command, 16);
49
TOH(ptr->Size, 16);
50
TOH(ptr->SenderSize, 16);
51
TOH(ptr->SenderFibAddress, 32);
52
TOH(ptr->u.ReceiverFibAddress, 32);
53
TOH(ptr->Handle, 32);
54
TOH(ptr->Previous, 32);
55
TOH(ptr->Next, 32);
56
}
57
58
void
59
aac_adapter_info_toh(struct aac_adapter_info *ptr)
60
{
61
TOH(ptr->PlatformBase, 32);
62
TOH(ptr->CpuArchitecture, 32);
63
TOH(ptr->CpuVariant, 32);
64
TOH(ptr->ClockSpeed, 32);
65
TOH(ptr->ExecutionMem, 32);
66
TOH(ptr->BufferMem, 32);
67
TOH(ptr->TotalMem, 32);
68
69
TOH(ptr->KernelRevision.buildNumber, 32);
70
TOH(ptr->MonitorRevision.buildNumber, 32);
71
TOH(ptr->HardwareRevision.buildNumber, 32);
72
TOH(ptr->BIOSRevision.buildNumber, 32);
73
74
TOH(ptr->ClusteringEnabled, 32);
75
TOH(ptr->ClusterChannelMask, 32);
76
TOH(ptr->SerialNumber, 64);
77
TOH(ptr->batteryPlatform, 32);
78
TOH(ptr->SupportedOptions, 32);
79
TOH(ptr->OemVariant, 32);
80
}
81
82
void
83
aac_container_creation_toh(struct aac_container_creation *ptr)
84
{
85
u_int32_t *date = (u_int32_t *)ptr + 1;
86
87
*date = le32toh(*date);
88
TOH(ptr->ViaAdapterSerialNumber, 64);
89
}
90
91
void
92
aac_mntobj_toh(struct aac_mntobj *ptr)
93
{
94
TOH(ptr->ObjectId, 32);
95
aac_container_creation_toh(&ptr->CreateInfo);
96
TOH(ptr->Capacity, 32);
97
TOH(ptr->VolType, 32);
98
TOH(ptr->ObjType, 32);
99
TOH(ptr->ContentState, 32);
100
TOH(ptr->ObjExtension.BlockDevice.BlockSize, 32);
101
TOH(ptr->ObjExtension.BlockDevice.bdLgclPhysMap, 32);
102
TOH(ptr->AlterEgoId, 32);
103
TOH(ptr->CapacityHigh, 32);
104
}
105
106
void
107
aac_mntinforesp_toh(struct aac_mntinforesp *ptr)
108
{
109
TOH(ptr->Status, 32);
110
TOH(ptr->MntType, 32);
111
TOH(ptr->MntRespCount, 32);
112
aac_mntobj_toh(&ptr->MntTable[0]);
113
}
114
115
void
116
aac_fsa_ctm_toh(struct aac_fsa_ctm *ptr)
117
{
118
int i;
119
120
TOH(ptr->command, 32);
121
for (i = 0; i < CT_FIB_PARAMS; i++)
122
TOH(ptr->param[i], 32);
123
}
124
125
void
126
aac_cnt_config_toh(struct aac_cnt_config *ptr)
127
{
128
TOH(ptr->Command, 32);
129
aac_fsa_ctm_toh(&ptr->CTCommand);
130
}
131
132
void
133
aac_ctcfg_resp_toh(struct aac_ctcfg_resp *ptr)
134
{
135
TOH(ptr->Status, 32);
136
TOH(ptr->resp, 32);
137
TOH(ptr->param, 32);
138
}
139
140
void
141
aac_getbusinf_toh(struct aac_getbusinf *ptr)
142
{
143
TOH(ptr->ProbeComplete, 32);
144
TOH(ptr->BusCount, 32);
145
TOH(ptr->TargetsPerBus, 32);
146
}
147
148
void
149
aac_vmi_businf_resp_toh(struct aac_vmi_businf_resp *ptr)
150
{
151
TOH(ptr->Status, 32);
152
TOH(ptr->ObjType, 32);
153
TOH(ptr->MethId, 32);
154
TOH(ptr->ObjId, 32);
155
TOH(ptr->IoctlCmd, 32);
156
aac_getbusinf_toh(&ptr->BusInf);
157
}
158
159
void
160
aac_srb_response_toh(struct aac_srb_response *ptr)
161
{
162
TOH(ptr->fib_status, 32);
163
TOH(ptr->srb_status, 32);
164
TOH(ptr->scsi_status, 32);
165
TOH(ptr->data_len, 32);
166
TOH(ptr->sense_len, 32);
167
}
168
169
/* Convert from host order to Little-Endian (TOLE) */
170
171
void
172
aac_adapter_init_tole(struct aac_adapter_init *ptr)
173
{
174
TOLE(ptr->InitStructRevision, 32);
175
TOLE(ptr->NoOfMSIXVectors, 32);
176
TOLE(ptr->FilesystemRevision, 32);
177
TOLE(ptr->CommHeaderAddress, 32);
178
TOLE(ptr->FastIoCommAreaAddress, 32);
179
TOLE(ptr->AdapterFibsPhysicalAddress, 32);
180
TOLE(ptr->AdapterFibsVirtualAddress, 32);
181
TOLE(ptr->AdapterFibsSize, 32);
182
TOLE(ptr->AdapterFibAlign, 32);
183
TOLE(ptr->PrintfBufferAddress, 32);
184
TOLE(ptr->PrintfBufferSize, 32);
185
TOLE(ptr->HostPhysMemPages, 32);
186
TOLE(ptr->HostElapsedSeconds, 32);
187
TOLE(ptr->InitFlags, 32);
188
TOLE(ptr->MaxIoCommands, 32);
189
TOLE(ptr->MaxIoSize, 32);
190
TOLE(ptr->MaxFibSize, 32);
191
TOLE(ptr->MaxNumAif, 32);
192
TOLE(ptr->HostRRQ_AddrLow, 32);
193
TOLE(ptr->HostRRQ_AddrHigh, 32);
194
}
195
196
void
197
aac_fib_header_tole(struct aac_fib_header *ptr)
198
{
199
TOLE(ptr->XferState, 32);
200
TOLE(ptr->Command, 16);
201
TOLE(ptr->Size, 16);
202
TOLE(ptr->SenderSize, 16);
203
TOLE(ptr->SenderFibAddress, 32);
204
TOLE(ptr->u.ReceiverFibAddress, 32);
205
TOLE(ptr->Handle, 32);
206
TOLE(ptr->Previous, 32);
207
TOLE(ptr->Next, 32);
208
}
209
210
void
211
aac_mntinfo_tole(struct aac_mntinfo *ptr)
212
{
213
TOLE(ptr->Command, 32);
214
TOLE(ptr->MntType, 32);
215
TOLE(ptr->MntCount, 32);
216
}
217
218
void
219
aac_fsa_ctm_tole(struct aac_fsa_ctm *ptr)
220
{
221
int i;
222
223
TOLE(ptr->command, 32);
224
for (i = 0; i < CT_FIB_PARAMS; i++)
225
TOLE(ptr->param[i], 32);
226
}
227
228
void
229
aac_cnt_config_tole(struct aac_cnt_config *ptr)
230
{
231
TOLE(ptr->Command, 32);
232
aac_fsa_ctm_tole(&ptr->CTCommand);
233
}
234
235
void
236
aac_raw_io_tole(struct aac_raw_io *ptr)
237
{
238
TOLE(ptr->BlockNumber, 64);
239
TOLE(ptr->ByteCount, 32);
240
TOLE(ptr->ContainerId, 16);
241
TOLE(ptr->Flags, 16);
242
TOLE(ptr->BpTotal, 16);
243
TOLE(ptr->BpComplete, 16);
244
}
245
246
void
247
aac_raw_io2_tole(struct aac_raw_io2 *ptr)
248
{
249
TOLE(ptr->strtBlkLow, 32);
250
TOLE(ptr->strtBlkHigh, 32);
251
TOLE(ptr->byteCnt, 32);
252
TOLE(ptr->ldNum, 16);
253
TOLE(ptr->flags, 16);
254
TOLE(ptr->sgeFirstSize, 32);
255
TOLE(ptr->sgeNominalSize, 32);
256
}
257
258
void
259
aac_fib_xporthdr_tole(struct aac_fib_xporthdr *ptr)
260
{
261
TOLE(ptr->HostAddress, 64);
262
TOLE(ptr->Size, 32);
263
TOLE(ptr->Handle, 32);
264
}
265
266
void
267
aac_ctcfg_tole(struct aac_ctcfg *ptr)
268
{
269
TOLE(ptr->Command, 32);
270
TOLE(ptr->cmd, 32);
271
TOLE(ptr->param, 32);
272
}
273
274
void
275
aac_vmioctl_tole(struct aac_vmioctl *ptr)
276
{
277
TOLE(ptr->Command, 32);
278
TOLE(ptr->ObjType, 32);
279
TOLE(ptr->MethId, 32);
280
TOLE(ptr->ObjId, 32);
281
TOLE(ptr->IoctlCmd, 32);
282
TOLE(ptr->IoctlBuf[0], 32);
283
}
284
285
void
286
aac_pause_command_tole(struct aac_pause_command *ptr)
287
{
288
TOLE(ptr->Command, 32);
289
TOLE(ptr->Type, 32);
290
TOLE(ptr->Timeout, 32);
291
TOLE(ptr->Min, 32);
292
TOLE(ptr->NoRescan, 32);
293
TOLE(ptr->Parm3, 32);
294
TOLE(ptr->Parm4, 32);
295
TOLE(ptr->Count, 32);
296
}
297
298
void
299
aac_srb_tole(struct aac_srb *ptr)
300
{
301
TOLE(ptr->function, 32);
302
TOLE(ptr->bus, 32);
303
TOLE(ptr->target, 32);
304
TOLE(ptr->lun, 32);
305
TOLE(ptr->timeout, 32);
306
TOLE(ptr->flags, 32);
307
TOLE(ptr->data_len, 32);
308
TOLE(ptr->retry_limit, 32);
309
TOLE(ptr->cdb_len, 32);
310
}
311
312
void
313
aac_sge_ieee1212_tole(struct aac_sge_ieee1212 *ptr)
314
{
315
TOLE(ptr->addrLow, 32);
316
TOLE(ptr->addrHigh, 32);
317
TOLE(ptr->length, 32);
318
TOLE(ptr->flags, 32);
319
}
320
321
void
322
aac_sg_entryraw_tole(struct aac_sg_entryraw *ptr)
323
{
324
TOLE(ptr->Next, 32);
325
TOLE(ptr->Prev, 32);
326
TOLE(ptr->SgAddress, 64);
327
TOLE(ptr->SgByteCount, 32);
328
TOLE(ptr->Flags, 32);
329
}
330
331
void
332
aac_sg_entry_tole(struct aac_sg_entry *ptr)
333
{
334
TOLE(ptr->SgAddress, 32);
335
TOLE(ptr->SgByteCount, 32);
336
}
337
338
void
339
aac_sg_entry64_tole(struct aac_sg_entry64 *ptr)
340
{
341
TOLE(ptr->SgAddress, 64);
342
TOLE(ptr->SgByteCount, 32);
343
}
344
345
void
346
aac_blockread_tole(struct aac_blockread *ptr)
347
{
348
TOLE(ptr->Command, 32);
349
TOLE(ptr->ContainerId, 32);
350
TOLE(ptr->BlockNumber, 32);
351
TOLE(ptr->ByteCount, 32);
352
}
353
354
void
355
aac_blockwrite_tole(struct aac_blockwrite *ptr)
356
{
357
TOLE(ptr->Command, 32);
358
TOLE(ptr->ContainerId, 32);
359
TOLE(ptr->BlockNumber, 32);
360
TOLE(ptr->ByteCount, 32);
361
TOLE(ptr->Stable, 32);
362
}
363
364
void
365
aac_blockread64_tole(struct aac_blockread64 *ptr)
366
{
367
TOLE(ptr->Command, 32);
368
TOLE(ptr->ContainerId, 16);
369
TOLE(ptr->SectorCount, 16);
370
TOLE(ptr->BlockNumber, 32);
371
TOLE(ptr->Pad, 16);
372
TOLE(ptr->Flags, 16);
373
}
374
375
void
376
aac_blockwrite64_tole(struct aac_blockwrite64 *ptr)
377
{
378
TOLE(ptr->Command, 32);
379
TOLE(ptr->ContainerId, 16);
380
TOLE(ptr->SectorCount, 16);
381
TOLE(ptr->BlockNumber, 32);
382
TOLE(ptr->Pad, 16);
383
TOLE(ptr->Flags, 16);
384
}
385
386
#endif
387
388