mptendian.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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
  12. * version 2.1 of the License, or (at your option) any later version.
  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. #include "qemu/osdep.h"
  23. #include "hw/pci/pci.h"
  24. #include "system/dma.h"
  25. #include "hw/pci/msi.h"
  26. #include "qemu/iov.h"
  27. #include "hw/scsi/scsi.h"
  28. #include "scsi/constants.h"
  29. #include "trace.h"
  30. #include "mptsas.h"
  31. #include "mpi.h"
  32. static void mptsas_fix_sgentry_endianness(MPISGEntry *sge)
  33. {
  34. sge->FlagsLength = le32_to_cpu(sge->FlagsLength);
  35. if (sge->FlagsLength & MPI_SGE_FLAGS_64_BIT_ADDRESSING) {
  36. sge->u.Address64 = le64_to_cpu(sge->u.Address64);
  37. } else {
  38. sge->u.Address32 = le32_to_cpu(sge->u.Address32);
  39. }
  40. }
  41. static void mptsas_fix_sgentry_endianness_reply(MPISGEntry *sge)
  42. {
  43. if (sge->FlagsLength & MPI_SGE_FLAGS_64_BIT_ADDRESSING) {
  44. sge->u.Address64 = cpu_to_le64(sge->u.Address64);
  45. } else {
  46. sge->u.Address32 = cpu_to_le32(sge->u.Address32);
  47. }
  48. sge->FlagsLength = cpu_to_le32(sge->FlagsLength);
  49. }
  50. void mptsas_fix_scsi_io_endianness(MPIMsgSCSIIORequest *req)
  51. {
  52. req->MsgContext = le32_to_cpu(req->MsgContext);
  53. req->Control = le32_to_cpu(req->Control);
  54. req->DataLength = le32_to_cpu(req->DataLength);
  55. req->SenseBufferLowAddr = le32_to_cpu(req->SenseBufferLowAddr);
  56. }
  57. void mptsas_fix_scsi_io_reply_endianness(MPIMsgSCSIIOReply *reply)
  58. {
  59. reply->MsgContext = cpu_to_le32(reply->MsgContext);
  60. reply->IOCStatus = cpu_to_le16(reply->IOCStatus);
  61. reply->IOCLogInfo = cpu_to_le32(reply->IOCLogInfo);
  62. reply->TransferCount = cpu_to_le32(reply->TransferCount);
  63. reply->SenseCount = cpu_to_le32(reply->SenseCount);
  64. reply->ResponseInfo = cpu_to_le32(reply->ResponseInfo);
  65. reply->TaskTag = cpu_to_le16(reply->TaskTag);
  66. }
  67. void mptsas_fix_scsi_task_mgmt_endianness(MPIMsgSCSITaskMgmt *req)
  68. {
  69. req->MsgContext = le32_to_cpu(req->MsgContext);
  70. req->TaskMsgContext = le32_to_cpu(req->TaskMsgContext);
  71. }
  72. void mptsas_fix_scsi_task_mgmt_reply_endianness(MPIMsgSCSITaskMgmtReply *reply)
  73. {
  74. reply->MsgContext = cpu_to_le32(reply->MsgContext);
  75. reply->IOCStatus = cpu_to_le16(reply->IOCStatus);
  76. reply->IOCLogInfo = cpu_to_le32(reply->IOCLogInfo);
  77. reply->TerminationCount = cpu_to_le32(reply->TerminationCount);
  78. }
  79. void mptsas_fix_ioc_init_endianness(MPIMsgIOCInit *req)
  80. {
  81. req->MsgContext = le32_to_cpu(req->MsgContext);
  82. req->ReplyFrameSize = le16_to_cpu(req->ReplyFrameSize);
  83. req->HostMfaHighAddr = le32_to_cpu(req->HostMfaHighAddr);
  84. req->SenseBufferHighAddr = le32_to_cpu(req->SenseBufferHighAddr);
  85. req->ReplyFifoHostSignalingAddr =
  86. le32_to_cpu(req->ReplyFifoHostSignalingAddr);
  87. mptsas_fix_sgentry_endianness(&req->HostPageBufferSGE);
  88. req->MsgVersion = le16_to_cpu(req->MsgVersion);
  89. req->HeaderVersion = le16_to_cpu(req->HeaderVersion);
  90. }
  91. void mptsas_fix_ioc_init_reply_endianness(MPIMsgIOCInitReply *reply)
  92. {
  93. reply->MsgContext = cpu_to_le32(reply->MsgContext);
  94. reply->IOCStatus = cpu_to_le16(reply->IOCStatus);
  95. reply->IOCLogInfo = cpu_to_le32(reply->IOCLogInfo);
  96. }
  97. void mptsas_fix_ioc_facts_endianness(MPIMsgIOCFacts *req)
  98. {
  99. req->MsgContext = le32_to_cpu(req->MsgContext);
  100. }
  101. void mptsas_fix_ioc_facts_reply_endianness(MPIMsgIOCFactsReply *reply)
  102. {
  103. reply->MsgVersion = cpu_to_le16(reply->MsgVersion);
  104. reply->HeaderVersion = cpu_to_le16(reply->HeaderVersion);
  105. reply->MsgContext = cpu_to_le32(reply->MsgContext);
  106. reply->IOCExceptions = cpu_to_le16(reply->IOCExceptions);
  107. reply->IOCStatus = cpu_to_le16(reply->IOCStatus);
  108. reply->IOCLogInfo = cpu_to_le32(reply->IOCLogInfo);
  109. reply->ReplyQueueDepth = cpu_to_le16(reply->ReplyQueueDepth);
  110. reply->RequestFrameSize = cpu_to_le16(reply->RequestFrameSize);
  111. reply->ProductID = cpu_to_le16(reply->ProductID);
  112. reply->CurrentHostMfaHighAddr = cpu_to_le32(reply->CurrentHostMfaHighAddr);
  113. reply->GlobalCredits = cpu_to_le16(reply->GlobalCredits);
  114. reply->CurrentSenseBufferHighAddr =
  115. cpu_to_le32(reply->CurrentSenseBufferHighAddr);
  116. reply->CurReplyFrameSize = cpu_to_le16(reply->CurReplyFrameSize);
  117. reply->FWImageSize = cpu_to_le32(reply->FWImageSize);
  118. reply->IOCCapabilities = cpu_to_le32(reply->IOCCapabilities);
  119. reply->HighPriorityQueueDepth = cpu_to_le16(reply->HighPriorityQueueDepth);
  120. mptsas_fix_sgentry_endianness_reply(&reply->HostPageBufferSGE);
  121. reply->ReplyFifoHostSignalingAddr =
  122. cpu_to_le32(reply->ReplyFifoHostSignalingAddr);
  123. }
  124. void mptsas_fix_config_endianness(MPIMsgConfig *req)
  125. {
  126. req->ExtPageLength = le16_to_cpu(req->ExtPageLength);
  127. req->MsgContext = le32_to_cpu(req->MsgContext);
  128. req->PageAddress = le32_to_cpu(req->PageAddress);
  129. mptsas_fix_sgentry_endianness(&req->PageBufferSGE);
  130. }
  131. void mptsas_fix_config_reply_endianness(MPIMsgConfigReply *reply)
  132. {
  133. reply->ExtPageLength = cpu_to_le16(reply->ExtPageLength);
  134. reply->MsgContext = cpu_to_le32(reply->MsgContext);
  135. reply->IOCStatus = cpu_to_le16(reply->IOCStatus);
  136. reply->IOCLogInfo = cpu_to_le32(reply->IOCLogInfo);
  137. }
  138. void mptsas_fix_port_facts_endianness(MPIMsgPortFacts *req)
  139. {
  140. req->MsgContext = le32_to_cpu(req->MsgContext);
  141. }
  142. void mptsas_fix_port_facts_reply_endianness(MPIMsgPortFactsReply *reply)
  143. {
  144. reply->MsgContext = cpu_to_le32(reply->MsgContext);
  145. reply->IOCStatus = cpu_to_le16(reply->IOCStatus);
  146. reply->IOCLogInfo = cpu_to_le32(reply->IOCLogInfo);
  147. reply->MaxDevices = cpu_to_le16(reply->MaxDevices);
  148. reply->PortSCSIID = cpu_to_le16(reply->PortSCSIID);
  149. reply->ProtocolFlags = cpu_to_le16(reply->ProtocolFlags);
  150. reply->MaxPostedCmdBuffers = cpu_to_le16(reply->MaxPostedCmdBuffers);
  151. reply->MaxPersistentIDs = cpu_to_le16(reply->MaxPersistentIDs);
  152. reply->MaxLanBuckets = cpu_to_le16(reply->MaxLanBuckets);
  153. }
  154. void mptsas_fix_port_enable_endianness(MPIMsgPortEnable *req)
  155. {
  156. req->MsgContext = le32_to_cpu(req->MsgContext);
  157. }
  158. void mptsas_fix_port_enable_reply_endianness(MPIMsgPortEnableReply *reply)
  159. {
  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. }
  164. void mptsas_fix_event_notification_endianness(MPIMsgEventNotify *req)
  165. {
  166. req->MsgContext = le32_to_cpu(req->MsgContext);
  167. }
  168. void mptsas_fix_event_notification_reply_endianness(MPIMsgEventNotifyReply *reply)
  169. {
  170. int length = reply->EventDataLength;
  171. int i;
  172. reply->EventDataLength = cpu_to_le16(reply->EventDataLength);
  173. reply->MsgContext = cpu_to_le32(reply->MsgContext);
  174. reply->IOCStatus = cpu_to_le16(reply->IOCStatus);
  175. reply->IOCLogInfo = cpu_to_le32(reply->IOCLogInfo);
  176. reply->Event = cpu_to_le32(reply->Event);
  177. reply->EventContext = cpu_to_le32(reply->EventContext);
  178. /* Really depends on the event kind. This will do for now. */
  179. for (i = 0; i < length; i++) {
  180. reply->Data[i] = cpu_to_le32(reply->Data[i]);
  181. }
  182. }