vmw_pvscsi.h 12 KB

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