vmw_pvscsi.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. /*
  2. * VMware PVSCSI header file
  3. *
  4. * Copyright (C) 2008-2009, VMware, Inc. All Rights Reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; version 2 of the License and no later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  13. * NON INFRINGEMENT. See the GNU General Public License for more
  14. * details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Maintained by: Arvind Kumar <arvindkumar@vmware.com>
  21. *
  22. */
  23. #ifndef VMW_PVSCSI_H
  24. #define VMW_PVSCSI_H
  25. #define VMW_PAGE_SIZE (4096)
  26. #define VMW_PAGE_SHIFT (12)
  27. #define MASK(n) ((1 << (n)) - 1) /* make an n-bit mask */
  28. /*
  29. * host adapter status/error codes
  30. */
  31. enum HostBusAdapterStatus {
  32. BTSTAT_SUCCESS = 0x00, /* CCB complete normally with no errors */
  33. BTSTAT_LINKED_COMMAND_COMPLETED = 0x0a,
  34. BTSTAT_LINKED_COMMAND_COMPLETED_WITH_FLAG = 0x0b,
  35. BTSTAT_DATA_UNDERRUN = 0x0c,
  36. BTSTAT_SELTIMEO = 0x11, /* SCSI selection timeout */
  37. BTSTAT_DATARUN = 0x12, /* data overrun/underrun */
  38. BTSTAT_BUSFREE = 0x13, /* unexpected bus free */
  39. BTSTAT_INVPHASE = 0x14, /* invalid bus phase or sequence */
  40. /* requested by target */
  41. BTSTAT_LUNMISMATCH = 0x17, /* linked CCB has different LUN */
  42. /* from first CCB */
  43. BTSTAT_SENSFAILED = 0x1b, /* auto request sense failed */
  44. BTSTAT_TAGREJECT = 0x1c, /* SCSI II tagged queueing message */
  45. /* rejected by target */
  46. BTSTAT_BADMSG = 0x1d, /* unsupported message received by */
  47. /* the host adapter */
  48. BTSTAT_HAHARDWARE = 0x20, /* host adapter hardware failed */
  49. BTSTAT_NORESPONSE = 0x21, /* target did not respond to SCSI ATN, */
  50. /* sent a SCSI RST */
  51. BTSTAT_SENTRST = 0x22, /* host adapter asserted a SCSI RST */
  52. BTSTAT_RECVRST = 0x23, /* other SCSI devices asserted a SCSI RST */
  53. BTSTAT_DISCONNECT = 0x24, /* target device reconnected improperly */
  54. /* (w/o tag) */
  55. BTSTAT_BUSRESET = 0x25, /* host adapter issued BUS device reset */
  56. BTSTAT_ABORTQUEUE = 0x26, /* abort queue generated */
  57. BTSTAT_HASOFTWARE = 0x27, /* host adapter software error */
  58. BTSTAT_HATIMEOUT = 0x30, /* host adapter hardware timeout error */
  59. BTSTAT_SCSIPARITY = 0x34, /* SCSI parity error detected */
  60. };
  61. /*
  62. * Register offsets.
  63. *
  64. * These registers are accessible both via i/o space and mm i/o.
  65. */
  66. enum PVSCSIRegOffset {
  67. PVSCSI_REG_OFFSET_COMMAND = 0x0,
  68. PVSCSI_REG_OFFSET_COMMAND_DATA = 0x4,
  69. PVSCSI_REG_OFFSET_COMMAND_STATUS = 0x8,
  70. PVSCSI_REG_OFFSET_LAST_STS_0 = 0x100,
  71. PVSCSI_REG_OFFSET_LAST_STS_1 = 0x104,
  72. PVSCSI_REG_OFFSET_LAST_STS_2 = 0x108,
  73. PVSCSI_REG_OFFSET_LAST_STS_3 = 0x10c,
  74. PVSCSI_REG_OFFSET_INTR_STATUS = 0x100c,
  75. PVSCSI_REG_OFFSET_INTR_MASK = 0x2010,
  76. PVSCSI_REG_OFFSET_KICK_NON_RW_IO = 0x3014,
  77. PVSCSI_REG_OFFSET_DEBUG = 0x3018,
  78. PVSCSI_REG_OFFSET_KICK_RW_IO = 0x4018,
  79. };
  80. /*
  81. * Virtual h/w commands.
  82. */
  83. enum PVSCSICommands {
  84. PVSCSI_CMD_FIRST = 0, /* has to be first */
  85. PVSCSI_CMD_ADAPTER_RESET = 1,
  86. PVSCSI_CMD_ISSUE_SCSI = 2,
  87. PVSCSI_CMD_SETUP_RINGS = 3,
  88. PVSCSI_CMD_RESET_BUS = 4,
  89. PVSCSI_CMD_RESET_DEVICE = 5,
  90. PVSCSI_CMD_ABORT_CMD = 6,
  91. PVSCSI_CMD_CONFIG = 7,
  92. PVSCSI_CMD_SETUP_MSG_RING = 8,
  93. PVSCSI_CMD_DEVICE_UNPLUG = 9,
  94. PVSCSI_CMD_LAST = 10 /* has to be last */
  95. };
  96. #define PVSCSI_COMMAND_PROCESSING_SUCCEEDED (0)
  97. #define PVSCSI_COMMAND_PROCESSING_FAILED (-1)
  98. #define PVSCSI_COMMAND_NOT_ENOUGH_DATA (-2)
  99. /*
  100. * Command descriptor for PVSCSI_CMD_RESET_DEVICE --
  101. */
  102. struct PVSCSICmdDescResetDevice {
  103. uint32_t target;
  104. uint8_t lun[8];
  105. } QEMU_PACKED;
  106. typedef struct PVSCSICmdDescResetDevice PVSCSICmdDescResetDevice;
  107. /*
  108. * Command descriptor for PVSCSI_CMD_ABORT_CMD --
  109. *
  110. * - currently does not support specifying the LUN.
  111. * - pad should be 0.
  112. */
  113. struct PVSCSICmdDescAbortCmd {
  114. uint64_t context;
  115. uint32_t target;
  116. uint32_t pad;
  117. } QEMU_PACKED;
  118. typedef struct PVSCSICmdDescAbortCmd PVSCSICmdDescAbortCmd;
  119. /*
  120. * Command descriptor for PVSCSI_CMD_SETUP_RINGS --
  121. *
  122. * Notes:
  123. * - reqRingNumPages and cmpRingNumPages need to be power of two.
  124. * - reqRingNumPages and cmpRingNumPages need to be different from 0,
  125. * - reqRingNumPages and cmpRingNumPages need to be inferior to
  126. * PVSCSI_SETUP_RINGS_MAX_NUM_PAGES.
  127. */
  128. #define PVSCSI_SETUP_RINGS_MAX_NUM_PAGES 32
  129. struct PVSCSICmdDescSetupRings {
  130. uint32_t reqRingNumPages;
  131. uint32_t cmpRingNumPages;
  132. uint64_t ringsStatePPN;
  133. uint64_t reqRingPPNs[PVSCSI_SETUP_RINGS_MAX_NUM_PAGES];
  134. uint64_t cmpRingPPNs[PVSCSI_SETUP_RINGS_MAX_NUM_PAGES];
  135. } QEMU_PACKED;
  136. typedef struct PVSCSICmdDescSetupRings PVSCSICmdDescSetupRings;
  137. /*
  138. * Command descriptor for PVSCSI_CMD_SETUP_MSG_RING --
  139. *
  140. * Notes:
  141. * - this command was not supported in the initial revision of the h/w
  142. * interface. Before using it, you need to check that it is supported by
  143. * writing PVSCSI_CMD_SETUP_MSG_RING to the 'command' register, then
  144. * immediately after read the 'command status' register:
  145. * * a value of -1 means that the cmd is NOT supported,
  146. * * a value != -1 means that the cmd IS supported.
  147. * If it's supported the 'command status' register should return:
  148. * sizeof(PVSCSICmdDescSetupMsgRing) / sizeof(uint32_t).
  149. * - this command should be issued _after_ the usual SETUP_RINGS so that the
  150. * RingsState page is already setup. If not, the command is a nop.
  151. * - numPages needs to be a power of two,
  152. * - numPages needs to be different from 0,
  153. * - pad should be zero.
  154. */
  155. #define PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES 16
  156. struct PVSCSICmdDescSetupMsgRing {
  157. uint32_t numPages;
  158. uint32_t pad;
  159. uint64_t ringPPNs[PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES];
  160. } QEMU_PACKED;
  161. typedef struct PVSCSICmdDescSetupMsgRing PVSCSICmdDescSetupMsgRing;
  162. enum PVSCSIMsgType {
  163. PVSCSI_MSG_DEV_ADDED = 0,
  164. PVSCSI_MSG_DEV_REMOVED = 1,
  165. PVSCSI_MSG_LAST = 2,
  166. };
  167. /*
  168. * Msg descriptor.
  169. *
  170. * sizeof(struct PVSCSIRingMsgDesc) == 128.
  171. *
  172. * - type is of type enum PVSCSIMsgType.
  173. * - the content of args depend on the type of event being delivered.
  174. */
  175. struct PVSCSIRingMsgDesc {
  176. uint32_t type;
  177. uint32_t args[31];
  178. } QEMU_PACKED;
  179. typedef struct PVSCSIRingMsgDesc PVSCSIRingMsgDesc;
  180. struct PVSCSIMsgDescDevStatusChanged {
  181. uint32_t type; /* PVSCSI_MSG_DEV _ADDED / _REMOVED */
  182. uint32_t bus;
  183. uint32_t target;
  184. uint8_t lun[8];
  185. uint32_t pad[27];
  186. } QEMU_PACKED;
  187. typedef struct PVSCSIMsgDescDevStatusChanged PVSCSIMsgDescDevStatusChanged;
  188. /*
  189. * Rings state.
  190. *
  191. * - the fields:
  192. * . msgProdIdx,
  193. * . msgConsIdx,
  194. * . msgNumEntriesLog2,
  195. * .. are only used once the SETUP_MSG_RING cmd has been issued.
  196. * - 'pad' helps to ensure that the msg related fields are on their own
  197. * cache-line.
  198. */
  199. struct PVSCSIRingsState {
  200. uint32_t reqProdIdx;
  201. uint32_t reqConsIdx;
  202. uint32_t reqNumEntriesLog2;
  203. uint32_t cmpProdIdx;
  204. uint32_t cmpConsIdx;
  205. uint32_t cmpNumEntriesLog2;
  206. uint8_t pad[104];
  207. uint32_t msgProdIdx;
  208. uint32_t msgConsIdx;
  209. uint32_t msgNumEntriesLog2;
  210. } QEMU_PACKED;
  211. typedef struct PVSCSIRingsState PVSCSIRingsState;
  212. /*
  213. * Request descriptor.
  214. *
  215. * sizeof(RingReqDesc) = 128
  216. *
  217. * - context: is a unique identifier of a command. It could normally be any
  218. * 64bit value, however we currently store it in the serialNumber variable
  219. * of struct SCSI_Command, so we have the following restrictions due to the
  220. * way this field is handled in the vmkernel storage stack:
  221. * * this value can't be 0,
  222. * * the upper 32bit need to be 0 since serialNumber is as a uint32_t.
  223. * Currently tracked as PR 292060.
  224. * - dataLen: contains the total number of bytes that need to be transferred.
  225. * - dataAddr:
  226. * * if PVSCSI_FLAG_CMD_WITH_SG_LIST is set: dataAddr is the PA of the first
  227. * s/g table segment, each s/g segment is entirely contained on a single
  228. * page of physical memory,
  229. * * if PVSCSI_FLAG_CMD_WITH_SG_LIST is NOT set, then dataAddr is the PA of
  230. * the buffer used for the DMA transfer,
  231. * - flags:
  232. * * PVSCSI_FLAG_CMD_WITH_SG_LIST: see dataAddr above,
  233. * * PVSCSI_FLAG_CMD_DIR_NONE: no DMA involved,
  234. * * PVSCSI_FLAG_CMD_DIR_TOHOST: transfer from device to main memory,
  235. * * PVSCSI_FLAG_CMD_DIR_TODEVICE: transfer from main memory to device,
  236. * * PVSCSI_FLAG_CMD_OUT_OF_BAND_CDB: reserved to handle CDBs larger than
  237. * 16bytes. To be specified.
  238. * - vcpuHint: vcpuId of the processor that will be most likely waiting for the
  239. * completion of the i/o. For guest OSes that use lowest priority message
  240. * delivery mode (such as windows), we use this "hint" to deliver the
  241. * completion action to the proper vcpu. For now, we can use the vcpuId of
  242. * the processor that initiated the i/o as a likely candidate for the vcpu
  243. * that will be waiting for the completion..
  244. * - bus should be 0: we currently only support bus 0 for now.
  245. * - unused should be zero'd.
  246. */
  247. #define PVSCSI_FLAG_CMD_WITH_SG_LIST (1 << 0)
  248. #define PVSCSI_FLAG_CMD_OUT_OF_BAND_CDB (1 << 1)
  249. #define PVSCSI_FLAG_CMD_DIR_NONE (1 << 2)
  250. #define PVSCSI_FLAG_CMD_DIR_TOHOST (1 << 3)
  251. #define PVSCSI_FLAG_CMD_DIR_TODEVICE (1 << 4)
  252. #define PVSCSI_KNOWN_FLAGS \
  253. (PVSCSI_FLAG_CMD_WITH_SG_LIST | \
  254. PVSCSI_FLAG_CMD_OUT_OF_BAND_CDB | \
  255. PVSCSI_FLAG_CMD_DIR_NONE | \
  256. PVSCSI_FLAG_CMD_DIR_TOHOST | \
  257. PVSCSI_FLAG_CMD_DIR_TODEVICE)
  258. struct PVSCSIRingReqDesc {
  259. uint64_t context;
  260. uint64_t dataAddr;
  261. uint64_t dataLen;
  262. uint64_t senseAddr;
  263. uint32_t senseLen;
  264. uint32_t flags;
  265. uint8_t cdb[16];
  266. uint8_t cdbLen;
  267. uint8_t lun[8];
  268. uint8_t tag;
  269. uint8_t bus;
  270. uint8_t target;
  271. uint8_t vcpuHint;
  272. uint8_t unused[59];
  273. } QEMU_PACKED;
  274. typedef struct PVSCSIRingReqDesc PVSCSIRingReqDesc;
  275. /*
  276. * Scatter-gather list management.
  277. *
  278. * As described above, when PVSCSI_FLAG_CMD_WITH_SG_LIST is set in the
  279. * RingReqDesc.flags, then RingReqDesc.dataAddr is the PA of the first s/g
  280. * table segment.
  281. *
  282. * - each segment of the s/g table contain a succession of struct
  283. * PVSCSISGElement.
  284. * - each segment is entirely contained on a single physical page of memory.
  285. * - a "chain" s/g element has the flag PVSCSI_SGE_FLAG_CHAIN_ELEMENT set in
  286. * PVSCSISGElement.flags and in this case:
  287. * * addr is the PA of the next s/g segment,
  288. * * length is undefined, assumed to be 0.
  289. */
  290. struct PVSCSISGElement {
  291. uint64_t addr;
  292. uint32_t length;
  293. uint32_t flags;
  294. } QEMU_PACKED;
  295. typedef struct PVSCSISGElement PVSCSISGElement;
  296. /*
  297. * Completion descriptor.
  298. *
  299. * sizeof(RingCmpDesc) = 32
  300. *
  301. * - context: identifier of the command. The same thing that was specified
  302. * under "context" as part of struct RingReqDesc at initiation time,
  303. * - dataLen: number of bytes transferred for the actual i/o operation,
  304. * - senseLen: number of bytes written into the sense buffer,
  305. * - hostStatus: adapter status,
  306. * - scsiStatus: device status,
  307. * - pad should be zero.
  308. */
  309. struct PVSCSIRingCmpDesc {
  310. uint64_t context;
  311. uint64_t dataLen;
  312. uint32_t senseLen;
  313. uint16_t hostStatus;
  314. uint16_t scsiStatus;
  315. uint32_t pad[2];
  316. } QEMU_PACKED;
  317. typedef struct PVSCSIRingCmpDesc PVSCSIRingCmpDesc;
  318. /*
  319. * Interrupt status / IRQ bits.
  320. */
  321. #define PVSCSI_INTR_CMPL_0 (1 << 0)
  322. #define PVSCSI_INTR_CMPL_1 (1 << 1)
  323. #define PVSCSI_INTR_CMPL_MASK MASK(2)
  324. #define PVSCSI_INTR_MSG_0 (1 << 2)
  325. #define PVSCSI_INTR_MSG_1 (1 << 3)
  326. #define PVSCSI_INTR_MSG_MASK (MASK(2) << 2)
  327. #define PVSCSI_INTR_ALL_SUPPORTED MASK(4)
  328. /*
  329. * Number of MSI-X vectors supported.
  330. */
  331. #define PVSCSI_MAX_INTRS 24
  332. /*
  333. * Enumeration of supported MSI-X vectors
  334. */
  335. #define PVSCSI_VECTOR_COMPLETION 0
  336. /*
  337. * Misc constants for the rings.
  338. */
  339. #define PVSCSI_MAX_NUM_PAGES_REQ_RING PVSCSI_SETUP_RINGS_MAX_NUM_PAGES
  340. #define PVSCSI_MAX_NUM_PAGES_CMP_RING PVSCSI_SETUP_RINGS_MAX_NUM_PAGES
  341. #define PVSCSI_MAX_NUM_PAGES_MSG_RING PVSCSI_SETUP_MSG_RING_MAX_NUM_PAGES
  342. #define PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE \
  343. (VMW_PAGE_SIZE / sizeof(struct PVSCSIRingReqDesc))
  344. #define PVSCSI_MAX_NUM_CMP_ENTRIES_PER_PAGE \
  345. (VMW_PAGE_SIZE / sizeof(PVSCSIRingCmpDesc))
  346. #define PVSCSI_MAX_NUM_MSG_ENTRIES_PER_PAGE \
  347. (VMW_PAGE_SIZE / sizeof(PVSCSIRingMsgDesc))
  348. #define PVSCSI_MAX_REQ_QUEUE_DEPTH \
  349. (PVSCSI_MAX_NUM_PAGES_REQ_RING * PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE)
  350. #define PVSCSI_MEM_SPACE_COMMAND_NUM_PAGES 1
  351. #define PVSCSI_MEM_SPACE_INTR_STATUS_NUM_PAGES 1
  352. #define PVSCSI_MEM_SPACE_MISC_NUM_PAGES 2
  353. #define PVSCSI_MEM_SPACE_KICK_IO_NUM_PAGES 2
  354. #define PVSCSI_MEM_SPACE_MSIX_NUM_PAGES 2
  355. enum PVSCSIMemSpace {
  356. PVSCSI_MEM_SPACE_COMMAND_PAGE = 0,
  357. PVSCSI_MEM_SPACE_INTR_STATUS_PAGE = 1,
  358. PVSCSI_MEM_SPACE_MISC_PAGE = 2,
  359. PVSCSI_MEM_SPACE_KICK_IO_PAGE = 4,
  360. PVSCSI_MEM_SPACE_MSIX_TABLE_PAGE = 6,
  361. PVSCSI_MEM_SPACE_MSIX_PBA_PAGE = 7,
  362. };
  363. #define PVSCSI_MEM_SPACE_NUM_PAGES \
  364. (PVSCSI_MEM_SPACE_COMMAND_NUM_PAGES + \
  365. PVSCSI_MEM_SPACE_INTR_STATUS_NUM_PAGES + \
  366. PVSCSI_MEM_SPACE_MISC_NUM_PAGES + \
  367. PVSCSI_MEM_SPACE_KICK_IO_NUM_PAGES + \
  368. PVSCSI_MEM_SPACE_MSIX_NUM_PAGES)
  369. #define PVSCSI_MEM_SPACE_SIZE (PVSCSI_MEM_SPACE_NUM_PAGES * VMW_PAGE_SIZE)
  370. #endif /* VMW_PVSCSI_H */