]> git.proxmox.com Git - mirror_qemu.git/blame - hw/scsi/mptendian.c
scsi-disk: ensure block size is non-zero and changes limited to bits 8-15
[mirror_qemu.git] / hw / scsi / mptendian.c
CommitLineData
e351b826
PB
1/*
2 * QEMU LSI SAS1068 Host Bus Adapter emulation
3 * Endianness conversion for MPI data structures
4 *
5 * Copyright (c) 2016 Red Hat, Inc.
6 *
7 * Authors: Paolo Bonzini <pbonzini@redhat.com>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
61f3c91a 12 * version 2.1 of the License, or (at your option) any later version.
e351b826
PB
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 */
22
23#include "qemu/osdep.h"
e351b826
PB
24#include "hw/pci/pci.h"
25#include "sysemu/dma.h"
e351b826
PB
26#include "hw/pci/msi.h"
27#include "qemu/iov.h"
28#include "hw/scsi/scsi.h"
08e2c9f1 29#include "scsi/constants.h"
e351b826
PB
30#include "trace.h"
31
32#include "mptsas.h"
33#include "mpi.h"
34
35static void mptsas_fix_sgentry_endianness(MPISGEntry *sge)
36{
97866508 37 sge->FlagsLength = le32_to_cpu(sge->FlagsLength);
e351b826 38 if (sge->FlagsLength & MPI_SGE_FLAGS_64_BIT_ADDRESSING) {
97866508 39 sge->u.Address64 = le64_to_cpu(sge->u.Address64);
e351b826 40 } else {
97866508 41 sge->u.Address32 = le32_to_cpu(sge->u.Address32);
e351b826
PB
42 }
43}
44
45static void mptsas_fix_sgentry_endianness_reply(MPISGEntry *sge)
46{
47 if (sge->FlagsLength & MPI_SGE_FLAGS_64_BIT_ADDRESSING) {
97866508 48 sge->u.Address64 = cpu_to_le64(sge->u.Address64);
e351b826 49 } else {
97866508 50 sge->u.Address32 = cpu_to_le32(sge->u.Address32);
e351b826 51 }
97866508 52 sge->FlagsLength = cpu_to_le32(sge->FlagsLength);
e351b826
PB
53}
54
55void mptsas_fix_scsi_io_endianness(MPIMsgSCSIIORequest *req)
56{
97866508
PM
57 req->MsgContext = le32_to_cpu(req->MsgContext);
58 req->Control = le32_to_cpu(req->Control);
59 req->DataLength = le32_to_cpu(req->DataLength);
60 req->SenseBufferLowAddr = le32_to_cpu(req->SenseBufferLowAddr);
e351b826
PB
61}
62
63void mptsas_fix_scsi_io_reply_endianness(MPIMsgSCSIIOReply *reply)
64{
97866508
PM
65 reply->MsgContext = cpu_to_le32(reply->MsgContext);
66 reply->IOCStatus = cpu_to_le16(reply->IOCStatus);
67 reply->IOCLogInfo = cpu_to_le32(reply->IOCLogInfo);
68 reply->TransferCount = cpu_to_le32(reply->TransferCount);
69 reply->SenseCount = cpu_to_le32(reply->SenseCount);
70 reply->ResponseInfo = cpu_to_le32(reply->ResponseInfo);
71 reply->TaskTag = cpu_to_le16(reply->TaskTag);
e351b826
PB
72}
73
74void mptsas_fix_scsi_task_mgmt_endianness(MPIMsgSCSITaskMgmt *req)
75{
97866508
PM
76 req->MsgContext = le32_to_cpu(req->MsgContext);
77 req->TaskMsgContext = le32_to_cpu(req->TaskMsgContext);
e351b826
PB
78}
79
80void mptsas_fix_scsi_task_mgmt_reply_endianness(MPIMsgSCSITaskMgmtReply *reply)
81{
97866508
PM
82 reply->MsgContext = cpu_to_le32(reply->MsgContext);
83 reply->IOCStatus = cpu_to_le16(reply->IOCStatus);
84 reply->IOCLogInfo = cpu_to_le32(reply->IOCLogInfo);
85 reply->TerminationCount = cpu_to_le32(reply->TerminationCount);
e351b826
PB
86}
87
88void mptsas_fix_ioc_init_endianness(MPIMsgIOCInit *req)
89{
97866508
PM
90 req->MsgContext = le32_to_cpu(req->MsgContext);
91 req->ReplyFrameSize = le16_to_cpu(req->ReplyFrameSize);
92 req->HostMfaHighAddr = le32_to_cpu(req->HostMfaHighAddr);
93 req->SenseBufferHighAddr = le32_to_cpu(req->SenseBufferHighAddr);
94 req->ReplyFifoHostSignalingAddr =
95 le32_to_cpu(req->ReplyFifoHostSignalingAddr);
e351b826 96 mptsas_fix_sgentry_endianness(&req->HostPageBufferSGE);
97866508
PM
97 req->MsgVersion = le16_to_cpu(req->MsgVersion);
98 req->HeaderVersion = le16_to_cpu(req->HeaderVersion);
e351b826
PB
99}
100
101void mptsas_fix_ioc_init_reply_endianness(MPIMsgIOCInitReply *reply)
102{
97866508
PM
103 reply->MsgContext = cpu_to_le32(reply->MsgContext);
104 reply->IOCStatus = cpu_to_le16(reply->IOCStatus);
105 reply->IOCLogInfo = cpu_to_le32(reply->IOCLogInfo);
e351b826
PB
106}
107
108void mptsas_fix_ioc_facts_endianness(MPIMsgIOCFacts *req)
109{
97866508 110 req->MsgContext = le32_to_cpu(req->MsgContext);
e351b826
PB
111}
112
113void mptsas_fix_ioc_facts_reply_endianness(MPIMsgIOCFactsReply *reply)
114{
97866508
PM
115 reply->MsgVersion = cpu_to_le16(reply->MsgVersion);
116 reply->HeaderVersion = cpu_to_le16(reply->HeaderVersion);
117 reply->MsgContext = cpu_to_le32(reply->MsgContext);
118 reply->IOCExceptions = cpu_to_le16(reply->IOCExceptions);
119 reply->IOCStatus = cpu_to_le16(reply->IOCStatus);
120 reply->IOCLogInfo = cpu_to_le32(reply->IOCLogInfo);
121 reply->ReplyQueueDepth = cpu_to_le16(reply->ReplyQueueDepth);
122 reply->RequestFrameSize = cpu_to_le16(reply->RequestFrameSize);
123 reply->ProductID = cpu_to_le16(reply->ProductID);
124 reply->CurrentHostMfaHighAddr = cpu_to_le32(reply->CurrentHostMfaHighAddr);
125 reply->GlobalCredits = cpu_to_le16(reply->GlobalCredits);
126 reply->CurrentSenseBufferHighAddr =
127 cpu_to_le32(reply->CurrentSenseBufferHighAddr);
128 reply->CurReplyFrameSize = cpu_to_le16(reply->CurReplyFrameSize);
129 reply->FWImageSize = cpu_to_le32(reply->FWImageSize);
130 reply->IOCCapabilities = cpu_to_le32(reply->IOCCapabilities);
131 reply->HighPriorityQueueDepth = cpu_to_le16(reply->HighPriorityQueueDepth);
e351b826 132 mptsas_fix_sgentry_endianness_reply(&reply->HostPageBufferSGE);
97866508
PM
133 reply->ReplyFifoHostSignalingAddr =
134 cpu_to_le32(reply->ReplyFifoHostSignalingAddr);
e351b826
PB
135}
136
137void mptsas_fix_config_endianness(MPIMsgConfig *req)
138{
97866508
PM
139 req->ExtPageLength = le16_to_cpu(req->ExtPageLength);
140 req->MsgContext = le32_to_cpu(req->MsgContext);
141 req->PageAddress = le32_to_cpu(req->PageAddress);
e351b826
PB
142 mptsas_fix_sgentry_endianness(&req->PageBufferSGE);
143}
144
145void mptsas_fix_config_reply_endianness(MPIMsgConfigReply *reply)
146{
97866508
PM
147 reply->ExtPageLength = cpu_to_le16(reply->ExtPageLength);
148 reply->MsgContext = cpu_to_le32(reply->MsgContext);
149 reply->IOCStatus = cpu_to_le16(reply->IOCStatus);
150 reply->IOCLogInfo = cpu_to_le32(reply->IOCLogInfo);
e351b826
PB
151}
152
153void mptsas_fix_port_facts_endianness(MPIMsgPortFacts *req)
154{
97866508 155 req->MsgContext = le32_to_cpu(req->MsgContext);
e351b826
PB
156}
157
158void mptsas_fix_port_facts_reply_endianness(MPIMsgPortFactsReply *reply)
159{
97866508
PM
160 reply->MsgContext = cpu_to_le32(reply->MsgContext);
161 reply->IOCStatus = cpu_to_le16(reply->IOCStatus);
162 reply->IOCLogInfo = cpu_to_le32(reply->IOCLogInfo);
163 reply->MaxDevices = cpu_to_le16(reply->MaxDevices);
164 reply->PortSCSIID = cpu_to_le16(reply->PortSCSIID);
165 reply->ProtocolFlags = cpu_to_le16(reply->ProtocolFlags);
166 reply->MaxPostedCmdBuffers = cpu_to_le16(reply->MaxPostedCmdBuffers);
167 reply->MaxPersistentIDs = cpu_to_le16(reply->MaxPersistentIDs);
168 reply->MaxLanBuckets = cpu_to_le16(reply->MaxLanBuckets);
e351b826
PB
169}
170
171void mptsas_fix_port_enable_endianness(MPIMsgPortEnable *req)
172{
97866508 173 req->MsgContext = le32_to_cpu(req->MsgContext);
e351b826
PB
174}
175
176void mptsas_fix_port_enable_reply_endianness(MPIMsgPortEnableReply *reply)
177{
97866508
PM
178 reply->MsgContext = cpu_to_le32(reply->MsgContext);
179 reply->IOCStatus = cpu_to_le16(reply->IOCStatus);
180 reply->IOCLogInfo = cpu_to_le32(reply->IOCLogInfo);
e351b826
PB
181}
182
183void mptsas_fix_event_notification_endianness(MPIMsgEventNotify *req)
184{
97866508 185 req->MsgContext = le32_to_cpu(req->MsgContext);
e351b826
PB
186}
187
188void mptsas_fix_event_notification_reply_endianness(MPIMsgEventNotifyReply *reply)
189{
190 int length = reply->EventDataLength;
191 int i;
192
97866508
PM
193 reply->EventDataLength = cpu_to_le16(reply->EventDataLength);
194 reply->MsgContext = cpu_to_le32(reply->MsgContext);
195 reply->IOCStatus = cpu_to_le16(reply->IOCStatus);
196 reply->IOCLogInfo = cpu_to_le32(reply->IOCLogInfo);
197 reply->Event = cpu_to_le32(reply->Event);
198 reply->EventContext = cpu_to_le32(reply->EventContext);
e351b826
PB
199
200 /* Really depends on the event kind. This will do for now. */
201 for (i = 0; i < length; i++) {
97866508 202 reply->Data[i] = cpu_to_le32(reply->Data[i]);
e351b826
PB
203 }
204}
205