vmw_pvscsi.h 13 KB

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