vmw_pvscsi.h 13 KB

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