141118Sjdp/*- 241118Sjdp * SPDX-License-Identifier: BSD-2-Clause 341118Sjdp * 441118Sjdp * Copyright (c) 2019 Leandro Lupori 541118Sjdp * 641118Sjdp * Redistribution and use in source and binary forms, with or without 741118Sjdp * modification, are permitted provided that the following conditions 841118Sjdp * are met: 941118Sjdp * 1. Redistributions of source code must retain the above copyright 1041118Sjdp * notice, this list of conditions and the following disclaimer. 1141118Sjdp * 2. Redistributions in binary form must reproduce the above copyright 1241118Sjdp * notice, this list of conditions and the following disclaimer in the 1341118Sjdp * documentation and/or other materials provided with the distribution. 1441118Sjdp * 1541118Sjdp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1641118Sjdp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1741118Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1841118Sjdp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1941118Sjdp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2041118Sjdp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2141118Sjdp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2241118Sjdp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2341118Sjdp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2441118Sjdp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2541118Sjdp * SUCH DAMAGE. 2641118Sjdp */ 2741118Sjdp 2841118Sjdp#include <sys/param.h> 2941118Sjdp#include <sys/types.h> 3041118Sjdp 3141118Sjdp#include <dev/aacraid/aacraid_reg.h> 3241118Sjdp#include <dev/aacraid/aacraid_endian.h> 3341118Sjdp 3441118Sjdp#if _BYTE_ORDER != _LITTLE_ENDIAN 3541118Sjdp 3696154Sbrian#define TOH2(field, bits) field = le##bits##toh(field) 3741118Sjdp#define TOH(field, bits) TOH2(field, bits) 3852709Sjdp 3952709Sjdp#define TOLE2(field, bits) field = htole##bits(field) 4052709Sjdp#define TOLE(field, bits) TOLE2(field, bits) 4152709Sjdp 4241118Sjdp/* Convert from Little-Endian to host order (TOH) */ 4341118Sjdp 4441118Sjdpvoid 4541118Sjdpaac_fib_header_toh(struct aac_fib_header *ptr) 4652709Sjdp{ 4741118Sjdp TOH(ptr->XferState, 32); 4841118Sjdp TOH(ptr->Command, 16); 4941118Sjdp TOH(ptr->Size, 16); 5041118Sjdp TOH(ptr->SenderSize, 16); 5141118Sjdp TOH(ptr->SenderFibAddress, 32); 5241118Sjdp TOH(ptr->u.ReceiverFibAddress, 32); 5341118Sjdp TOH(ptr->Handle, 32); 5441118Sjdp TOH(ptr->Previous, 32); 5541118Sjdp TOH(ptr->Next, 32); 5641118Sjdp} 5741118Sjdp 5841118Sjdpvoid 5941118Sjdpaac_adapter_info_toh(struct aac_adapter_info *ptr) 6041118Sjdp{ 6141118Sjdp TOH(ptr->PlatformBase, 32); 6241118Sjdp TOH(ptr->CpuArchitecture, 32); 6341118Sjdp TOH(ptr->CpuVariant, 32); 6441118Sjdp TOH(ptr->ClockSpeed, 32); 6541118Sjdp TOH(ptr->ExecutionMem, 32); 6641118Sjdp TOH(ptr->BufferMem, 32); 6741118Sjdp TOH(ptr->TotalMem, 32); 6841118Sjdp 6941118Sjdp TOH(ptr->KernelRevision.buildNumber, 32); 7041118Sjdp TOH(ptr->MonitorRevision.buildNumber, 32); 7141118Sjdp TOH(ptr->HardwareRevision.buildNumber, 32); 7241118Sjdp TOH(ptr->BIOSRevision.buildNumber, 32); 7341118Sjdp 7441118Sjdp TOH(ptr->ClusteringEnabled, 32); 7541118Sjdp TOH(ptr->ClusterChannelMask, 32); 7641118Sjdp TOH(ptr->SerialNumber, 64); 7741118Sjdp TOH(ptr->batteryPlatform, 32); 7841118Sjdp TOH(ptr->SupportedOptions, 32); 7941118Sjdp TOH(ptr->OemVariant, 32); 8041118Sjdp} 8141118Sjdp 8241118Sjdpvoid 8343662Sbrianaac_container_creation_toh(struct aac_container_creation *ptr) 8441118Sjdp{ 8541118Sjdp u_int32_t *date = (u_int32_t *)ptr + 1; 8641118Sjdp 8743662Sbrian *date = le32toh(*date); 8843662Sbrian TOH(ptr->ViaAdapterSerialNumber, 64); 8943662Sbrian} 9052709Sjdp 9141118Sjdpvoid 9241118Sjdpaac_mntobj_toh(struct aac_mntobj *ptr) 9396154Sbrian{ 9496154Sbrian TOH(ptr->ObjectId, 32); 9596154Sbrian aac_container_creation_toh(&ptr->CreateInfo); 9696154Sbrian TOH(ptr->Capacity, 32); 9796154Sbrian TOH(ptr->VolType, 32); 9896154Sbrian TOH(ptr->ObjType, 32); 9996154Sbrian TOH(ptr->ContentState, 32); 10041118Sjdp 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 106void 107aac_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 115void 116aac_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 125void 126aac_cnt_config_toh(struct aac_cnt_config *ptr) 127{ 128 TOH(ptr->Command, 32); 129 aac_fsa_ctm_toh(&ptr->CTCommand); 130} 131 132void 133aac_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 140void 141aac_getbusinf_toh(struct aac_getbusinf *ptr) 142{ 143 TOH(ptr->ProbeComplete, 32); 144 TOH(ptr->BusCount, 32); 145 TOH(ptr->TargetsPerBus, 32); 146} 147 148void 149aac_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 159void 160aac_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 171void 172aac_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 196void 197aac_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 210void 211aac_mntinfo_tole(struct aac_mntinfo *ptr) 212{ 213 TOLE(ptr->Command, 32); 214 TOLE(ptr->MntType, 32); 215 TOLE(ptr->MntCount, 32); 216} 217 218void 219aac_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 228void 229aac_cnt_config_tole(struct aac_cnt_config *ptr) 230{ 231 TOLE(ptr->Command, 32); 232 aac_fsa_ctm_tole(&ptr->CTCommand); 233} 234 235void 236aac_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 246void 247aac_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 258void 259aac_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 266void 267aac_ctcfg_tole(struct aac_ctcfg *ptr) 268{ 269 TOLE(ptr->Command, 32); 270 TOLE(ptr->cmd, 32); 271 TOLE(ptr->param, 32); 272} 273 274void 275aac_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 285void 286aac_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 298void 299aac_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 312void 313aac_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 321void 322aac_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 331void 332aac_sg_entry_tole(struct aac_sg_entry *ptr) 333{ 334 TOLE(ptr->SgAddress, 32); 335 TOLE(ptr->SgByteCount, 32); 336} 337 338void 339aac_sg_entry64_tole(struct aac_sg_entry64 *ptr) 340{ 341 TOLE(ptr->SgAddress, 64); 342 TOLE(ptr->SgByteCount, 32); 343} 344 345void 346aac_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 354void 355aac_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 364void 365aac_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 375void 376aac_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