vmw_pvscsi.h 13 KB

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