sislite.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. /*
  2. * CXL Flash Device Driver
  3. *
  4. * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
  5. * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
  6. *
  7. * Copyright (C) 2015 IBM Corporation
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. */
  14. #ifndef _SISLITE_H
  15. #define _SISLITE_H
  16. #include <linux/types.h>
  17. typedef u16 ctx_hndl_t;
  18. typedef u32 res_hndl_t;
  19. #define SIZE_4K 4096
  20. #define SIZE_64K 65536
  21. /*
  22. * IOARCB: 64 bytes, min 16 byte alignment required, host native endianness
  23. * except for SCSI CDB which remains big endian per SCSI standards.
  24. */
  25. struct sisl_ioarcb {
  26. u16 ctx_id; /* ctx_hndl_t */
  27. u16 req_flags;
  28. #define SISL_REQ_FLAGS_RES_HNDL 0x8000U /* bit 0 (MSB) */
  29. #define SISL_REQ_FLAGS_PORT_LUN_ID 0x0000U
  30. #define SISL_REQ_FLAGS_SUP_UNDERRUN 0x4000U /* bit 1 */
  31. #define SISL_REQ_FLAGS_TIMEOUT_SECS 0x0000U /* bits 8,9 */
  32. #define SISL_REQ_FLAGS_TIMEOUT_MSECS 0x0040U
  33. #define SISL_REQ_FLAGS_TIMEOUT_USECS 0x0080U
  34. #define SISL_REQ_FLAGS_TIMEOUT_CYCLES 0x00C0U
  35. #define SISL_REQ_FLAGS_TMF_CMD 0x0004u /* bit 13 */
  36. #define SISL_REQ_FLAGS_AFU_CMD 0x0002U /* bit 14 */
  37. #define SISL_REQ_FLAGS_HOST_WRITE 0x0001U /* bit 15 (LSB) */
  38. #define SISL_REQ_FLAGS_HOST_READ 0x0000U
  39. union {
  40. u32 res_hndl; /* res_hndl_t */
  41. u32 port_sel; /* this is a selection mask:
  42. * 0x1 -> port#0 can be selected,
  43. * 0x2 -> port#1 can be selected.
  44. * Can be bitwise ORed.
  45. */
  46. };
  47. u64 lun_id;
  48. u32 data_len; /* 4K for read/write */
  49. u32 ioadl_len;
  50. union {
  51. u64 data_ea; /* min 16 byte aligned */
  52. u64 ioadl_ea;
  53. };
  54. u8 msi; /* LISN to send on RRQ write */
  55. #define SISL_MSI_CXL_PFAULT 0 /* reserved for CXL page faults */
  56. #define SISL_MSI_SYNC_ERROR 1 /* recommended for AFU sync error */
  57. #define SISL_MSI_RRQ_UPDATED 2 /* recommended for IO completion */
  58. #define SISL_MSI_ASYNC_ERROR 3 /* master only - for AFU async error */
  59. u8 rrq; /* 0 for a single RRQ */
  60. u16 timeout; /* in units specified by req_flags */
  61. u32 rsvd1;
  62. u8 cdb[16]; /* must be in big endian */
  63. struct scsi_cmnd *scp;
  64. } __packed;
  65. struct sisl_rc {
  66. u8 flags;
  67. #define SISL_RC_FLAGS_SENSE_VALID 0x80U
  68. #define SISL_RC_FLAGS_FCP_RSP_CODE_VALID 0x40U
  69. #define SISL_RC_FLAGS_OVERRUN 0x20U
  70. #define SISL_RC_FLAGS_UNDERRUN 0x10U
  71. u8 afu_rc;
  72. #define SISL_AFU_RC_RHT_INVALID 0x01U /* user error */
  73. #define SISL_AFU_RC_RHT_UNALIGNED 0x02U /* should never happen */
  74. #define SISL_AFU_RC_RHT_OUT_OF_BOUNDS 0x03u /* user error */
  75. #define SISL_AFU_RC_RHT_DMA_ERR 0x04u /* see afu_extra
  76. may retry if afu_retry is off
  77. possible on master exit
  78. */
  79. #define SISL_AFU_RC_RHT_RW_PERM 0x05u /* no RW perms, user error */
  80. #define SISL_AFU_RC_LXT_UNALIGNED 0x12U /* should never happen */
  81. #define SISL_AFU_RC_LXT_OUT_OF_BOUNDS 0x13u /* user error */
  82. #define SISL_AFU_RC_LXT_DMA_ERR 0x14u /* see afu_extra
  83. may retry if afu_retry is off
  84. possible on master exit
  85. */
  86. #define SISL_AFU_RC_LXT_RW_PERM 0x15u /* no RW perms, user error */
  87. #define SISL_AFU_RC_NOT_XLATE_HOST 0x1au /* possible if master exited */
  88. /* NO_CHANNELS means the FC ports selected by dest_port in
  89. * IOARCB or in the LXT entry are down when the AFU tried to select
  90. * a FC port. If the port went down on an active IO, it will set
  91. * fc_rc to =0x54(NOLOGI) or 0x57(LINKDOWN) instead.
  92. */
  93. #define SISL_AFU_RC_NO_CHANNELS 0x20U /* see afu_extra, may retry */
  94. #define SISL_AFU_RC_CAP_VIOLATION 0x21U /* either user error or
  95. afu reset/master restart
  96. */
  97. #define SISL_AFU_RC_OUT_OF_DATA_BUFS 0x30U /* always retry */
  98. #define SISL_AFU_RC_DATA_DMA_ERR 0x31U /* see afu_extra
  99. may retry if afu_retry is off
  100. */
  101. u8 scsi_rc; /* SCSI status byte, retry as appropriate */
  102. #define SISL_SCSI_RC_CHECK 0x02U
  103. #define SISL_SCSI_RC_BUSY 0x08u
  104. u8 fc_rc; /* retry */
  105. /*
  106. * We should only see fc_rc=0x57 (LINKDOWN) or 0x54(NOLOGI) for
  107. * commands that are in flight when a link goes down or is logged out.
  108. * If the link is down or logged out before AFU selects the port, either
  109. * it will choose the other port or we will get afu_rc=0x20 (no_channel)
  110. * if there is no valid port to use.
  111. *
  112. * ABORTPEND/ABORTOK/ABORTFAIL/TGTABORT can be retried, typically these
  113. * would happen if a frame is dropped and something times out.
  114. * NOLOGI or LINKDOWN can be retried if the other port is up.
  115. * RESIDERR can be retried as well.
  116. *
  117. * ABORTFAIL might indicate that lots of frames are getting CRC errors.
  118. * So it maybe retried once and reset the link if it happens again.
  119. * The link can also be reset on the CRC error threshold interrupt.
  120. */
  121. #define SISL_FC_RC_ABORTPEND 0x52 /* exchange timeout or abort request */
  122. #define SISL_FC_RC_WRABORTPEND 0x53 /* due to write XFER_RDY invalid */
  123. #define SISL_FC_RC_NOLOGI 0x54 /* port not logged in, in-flight cmds */
  124. #define SISL_FC_RC_NOEXP 0x55 /* FC protocol error or HW bug */
  125. #define SISL_FC_RC_INUSE 0x56 /* tag already in use, HW bug */
  126. #define SISL_FC_RC_LINKDOWN 0x57 /* link down, in-flight cmds */
  127. #define SISL_FC_RC_ABORTOK 0x58 /* pending abort completed w/success */
  128. #define SISL_FC_RC_ABORTFAIL 0x59 /* pending abort completed w/fail */
  129. #define SISL_FC_RC_RESID 0x5A /* ioasa underrun/overrun flags set */
  130. #define SISL_FC_RC_RESIDERR 0x5B /* actual data len does not match SCSI
  131. reported len, possibly due to dropped
  132. frames */
  133. #define SISL_FC_RC_TGTABORT 0x5C /* command aborted by target */
  134. };
  135. #define SISL_SENSE_DATA_LEN 20 /* Sense data length */
  136. /*
  137. * IOASA: 64 bytes & must follow IOARCB, min 16 byte alignment required,
  138. * host native endianness
  139. */
  140. struct sisl_ioasa {
  141. union {
  142. struct sisl_rc rc;
  143. u32 ioasc;
  144. #define SISL_IOASC_GOOD_COMPLETION 0x00000000U
  145. };
  146. u32 resid;
  147. u8 port;
  148. u8 afu_extra;
  149. /* when afu_rc=0x04, 0x14, 0x31 (_xxx_DMA_ERR):
  150. * afu_exta contains PSL response code. Useful codes are:
  151. */
  152. #define SISL_AFU_DMA_ERR_PAGE_IN 0x0A /* AFU_retry_on_pagein Action
  153. * Enabled N/A
  154. * Disabled retry
  155. */
  156. #define SISL_AFU_DMA_ERR_INVALID_EA 0x0B /* this is a hard error
  157. * afu_rc Implies
  158. * 0x04, 0x14 master exit.
  159. * 0x31 user error.
  160. */
  161. /* when afu rc=0x20 (no channels):
  162. * afu_extra bits [4:5]: available portmask, [6:7]: requested portmask.
  163. */
  164. #define SISL_AFU_NO_CLANNELS_AMASK(afu_extra) (((afu_extra) & 0x0C) >> 2)
  165. #define SISL_AFU_NO_CLANNELS_RMASK(afu_extra) ((afu_extra) & 0x03)
  166. u8 scsi_extra;
  167. u8 fc_extra;
  168. u8 sense_data[SISL_SENSE_DATA_LEN];
  169. /* These fields are defined by the SISlite architecture for the
  170. * host to use as they see fit for their implementation.
  171. */
  172. union {
  173. u64 host_use[4];
  174. u8 host_use_b[32];
  175. };
  176. } __packed;
  177. #define SISL_RESP_HANDLE_T_BIT 0x1ULL /* Toggle bit */
  178. /* MMIO space is required to support only 64-bit access */
  179. /*
  180. * This AFU has two mechanisms to deal with endian-ness.
  181. * One is a global configuration (in the afu_config) register
  182. * below that specifies the endian-ness of the host.
  183. * The other is a per context (i.e. application) specification
  184. * controlled by the endian_ctrl field here. Since the master
  185. * context is one such application the master context's
  186. * endian-ness is set to be the same as the host.
  187. *
  188. * As per the SISlite spec, the MMIO registers are always
  189. * big endian.
  190. */
  191. #define SISL_ENDIAN_CTRL_BE 0x8000000000000080ULL
  192. #define SISL_ENDIAN_CTRL_LE 0x0000000000000000ULL
  193. #ifdef __BIG_ENDIAN
  194. #define SISL_ENDIAN_CTRL SISL_ENDIAN_CTRL_BE
  195. #else
  196. #define SISL_ENDIAN_CTRL SISL_ENDIAN_CTRL_LE
  197. #endif
  198. /* per context host transport MMIO */
  199. struct sisl_host_map {
  200. __be64 endian_ctrl; /* Per context Endian Control. The AFU will
  201. * operate on whatever the context is of the
  202. * host application.
  203. */
  204. __be64 intr_status; /* this sends LISN# programmed in ctx_ctrl.
  205. * Only recovery in a PERM_ERR is a context
  206. * exit since there is no way to tell which
  207. * command caused the error.
  208. */
  209. #define SISL_ISTATUS_PERM_ERR_CMDROOM 0x0010ULL /* b59, user error */
  210. #define SISL_ISTATUS_PERM_ERR_RCB_READ 0x0008ULL /* b60, user error */
  211. #define SISL_ISTATUS_PERM_ERR_SA_WRITE 0x0004ULL /* b61, user error */
  212. #define SISL_ISTATUS_PERM_ERR_RRQ_WRITE 0x0002ULL /* b62, user error */
  213. /* Page in wait accessing RCB/IOASA/RRQ is reported in b63.
  214. * Same error in data/LXT/RHT access is reported via IOASA.
  215. */
  216. #define SISL_ISTATUS_TEMP_ERR_PAGEIN 0x0001ULL /* b63, can be generated
  217. * only when AFU auto
  218. * retry is disabled.
  219. * If user can determine
  220. * the command that
  221. * caused the error, it
  222. * can be retried.
  223. */
  224. #define SISL_ISTATUS_UNMASK (0x001FULL) /* 1 means unmasked */
  225. #define SISL_ISTATUS_MASK ~(SISL_ISTATUS_UNMASK) /* 1 means masked */
  226. __be64 intr_clear;
  227. __be64 intr_mask;
  228. __be64 ioarrin; /* only write what cmd_room permits */
  229. __be64 rrq_start; /* start & end are both inclusive */
  230. __be64 rrq_end; /* write sequence: start followed by end */
  231. __be64 cmd_room;
  232. __be64 ctx_ctrl; /* least significant byte or b56:63 is LISN# */
  233. __be64 mbox_w; /* restricted use */
  234. };
  235. /* per context provisioning & control MMIO */
  236. struct sisl_ctrl_map {
  237. __be64 rht_start;
  238. __be64 rht_cnt_id;
  239. /* both cnt & ctx_id args must be ULL */
  240. #define SISL_RHT_CNT_ID(cnt, ctx_id) (((cnt) << 48) | ((ctx_id) << 32))
  241. __be64 ctx_cap; /* afu_rc below is when the capability is violated */
  242. #define SISL_CTX_CAP_PROXY_ISSUE 0x8000000000000000ULL /* afu_rc 0x21 */
  243. #define SISL_CTX_CAP_REAL_MODE 0x4000000000000000ULL /* afu_rc 0x21 */
  244. #define SISL_CTX_CAP_HOST_XLATE 0x2000000000000000ULL /* afu_rc 0x1a */
  245. #define SISL_CTX_CAP_PROXY_TARGET 0x1000000000000000ULL /* afu_rc 0x21 */
  246. #define SISL_CTX_CAP_AFU_CMD 0x0000000000000008ULL /* afu_rc 0x21 */
  247. #define SISL_CTX_CAP_GSCSI_CMD 0x0000000000000004ULL /* afu_rc 0x21 */
  248. #define SISL_CTX_CAP_WRITE_CMD 0x0000000000000002ULL /* afu_rc 0x21 */
  249. #define SISL_CTX_CAP_READ_CMD 0x0000000000000001ULL /* afu_rc 0x21 */
  250. __be64 mbox_r;
  251. };
  252. /* single copy global regs */
  253. struct sisl_global_regs {
  254. __be64 aintr_status;
  255. /* In cxlflash, each FC port/link gets a byte of status */
  256. #define SISL_ASTATUS_FC0_OTHER 0x8000ULL /* b48, other err,
  257. FC_ERRCAP[31:20] */
  258. #define SISL_ASTATUS_FC0_LOGO 0x4000ULL /* b49, target sent FLOGI/PLOGI/LOGO
  259. while logged in */
  260. #define SISL_ASTATUS_FC0_CRC_T 0x2000ULL /* b50, CRC threshold exceeded */
  261. #define SISL_ASTATUS_FC0_LOGI_R 0x1000ULL /* b51, login state machine timed out
  262. and retrying */
  263. #define SISL_ASTATUS_FC0_LOGI_F 0x0800ULL /* b52, login failed,
  264. FC_ERROR[19:0] */
  265. #define SISL_ASTATUS_FC0_LOGI_S 0x0400ULL /* b53, login succeeded */
  266. #define SISL_ASTATUS_FC0_LINK_DN 0x0200ULL /* b54, link online to offline */
  267. #define SISL_ASTATUS_FC0_LINK_UP 0x0100ULL /* b55, link offline to online */
  268. #define SISL_ASTATUS_FC1_OTHER 0x0080ULL /* b56 */
  269. #define SISL_ASTATUS_FC1_LOGO 0x0040ULL /* b57 */
  270. #define SISL_ASTATUS_FC1_CRC_T 0x0020ULL /* b58 */
  271. #define SISL_ASTATUS_FC1_LOGI_R 0x0010ULL /* b59 */
  272. #define SISL_ASTATUS_FC1_LOGI_F 0x0008ULL /* b60 */
  273. #define SISL_ASTATUS_FC1_LOGI_S 0x0004ULL /* b61 */
  274. #define SISL_ASTATUS_FC1_LINK_DN 0x0002ULL /* b62 */
  275. #define SISL_ASTATUS_FC1_LINK_UP 0x0001ULL /* b63 */
  276. #define SISL_FC_INTERNAL_UNMASK 0x0000000300000000ULL /* 1 means unmasked */
  277. #define SISL_FC_INTERNAL_MASK ~(SISL_FC_INTERNAL_UNMASK)
  278. #define SISL_FC_INTERNAL_SHIFT 32
  279. #define SISL_FC_SHUTDOWN_NORMAL 0x0000000000000010ULL
  280. #define SISL_FC_SHUTDOWN_ABRUPT 0x0000000000000020ULL
  281. #define SISL_STATUS_SHUTDOWN_ACTIVE 0x0000000000000010ULL
  282. #define SISL_STATUS_SHUTDOWN_COMPLETE 0x0000000000000020ULL
  283. #define SISL_ASTATUS_UNMASK 0xFFFFULL /* 1 means unmasked */
  284. #define SISL_ASTATUS_MASK ~(SISL_ASTATUS_UNMASK) /* 1 means masked */
  285. __be64 aintr_clear;
  286. __be64 aintr_mask;
  287. __be64 afu_ctrl;
  288. __be64 afu_hb;
  289. __be64 afu_scratch_pad;
  290. __be64 afu_port_sel;
  291. #define SISL_AFUCONF_AR_IOARCB 0x4000ULL
  292. #define SISL_AFUCONF_AR_LXT 0x2000ULL
  293. #define SISL_AFUCONF_AR_RHT 0x1000ULL
  294. #define SISL_AFUCONF_AR_DATA 0x0800ULL
  295. #define SISL_AFUCONF_AR_RSRC 0x0400ULL
  296. #define SISL_AFUCONF_AR_IOASA 0x0200ULL
  297. #define SISL_AFUCONF_AR_RRQ 0x0100ULL
  298. /* Aggregate all Auto Retry Bits */
  299. #define SISL_AFUCONF_AR_ALL (SISL_AFUCONF_AR_IOARCB|SISL_AFUCONF_AR_LXT| \
  300. SISL_AFUCONF_AR_RHT|SISL_AFUCONF_AR_DATA| \
  301. SISL_AFUCONF_AR_RSRC|SISL_AFUCONF_AR_IOASA| \
  302. SISL_AFUCONF_AR_RRQ)
  303. #ifdef __BIG_ENDIAN
  304. #define SISL_AFUCONF_ENDIAN 0x0000ULL
  305. #else
  306. #define SISL_AFUCONF_ENDIAN 0x0020ULL
  307. #endif
  308. #define SISL_AFUCONF_MBOX_CLR_READ 0x0010ULL
  309. __be64 afu_config;
  310. __be64 rsvd[0xf8];
  311. __le64 afu_version;
  312. __be64 interface_version;
  313. };
  314. #define CXLFLASH_NUM_FC_PORTS 2
  315. #define CXLFLASH_MAX_CONTEXT 512 /* how many contexts per afu */
  316. #define CXLFLASH_NUM_VLUNS 512
  317. struct sisl_global_map {
  318. union {
  319. struct sisl_global_regs regs;
  320. char page0[SIZE_4K]; /* page 0 */
  321. };
  322. char page1[SIZE_4K]; /* page 1 */
  323. /* pages 2 & 3 */
  324. __be64 fc_regs[CXLFLASH_NUM_FC_PORTS][CXLFLASH_NUM_VLUNS];
  325. /* pages 4 & 5 (lun tbl) */
  326. __be64 fc_port[CXLFLASH_NUM_FC_PORTS][CXLFLASH_NUM_VLUNS];
  327. };
  328. /*
  329. * CXL Flash Memory Map
  330. *
  331. * +-------------------------------+
  332. * | 512 * 64 KB User MMIO |
  333. * | (per context) |
  334. * | User Accessible |
  335. * +-------------------------------+
  336. * | 512 * 128 B per context |
  337. * | Provisioning and Control |
  338. * | Trusted Process accessible |
  339. * +-------------------------------+
  340. * | 64 KB Global |
  341. * | Trusted Process accessible |
  342. * +-------------------------------+
  343. */
  344. struct cxlflash_afu_map {
  345. union {
  346. struct sisl_host_map host;
  347. char harea[SIZE_64K]; /* 64KB each */
  348. } hosts[CXLFLASH_MAX_CONTEXT];
  349. union {
  350. struct sisl_ctrl_map ctrl;
  351. char carea[cache_line_size()]; /* 128B each */
  352. } ctrls[CXLFLASH_MAX_CONTEXT];
  353. union {
  354. struct sisl_global_map global;
  355. char garea[SIZE_64K]; /* 64KB single block */
  356. };
  357. };
  358. /*
  359. * LXT - LBA Translation Table
  360. * LXT control blocks
  361. */
  362. struct sisl_lxt_entry {
  363. u64 rlba_base; /* bits 0:47 is base
  364. * b48:55 is lun index
  365. * b58:59 is write & read perms
  366. * (if no perm, afu_rc=0x15)
  367. * b60:63 is port_sel mask
  368. */
  369. };
  370. /*
  371. * RHT - Resource Handle Table
  372. * Per the SISlite spec, RHT entries are to be 16-byte aligned
  373. */
  374. struct sisl_rht_entry {
  375. struct sisl_lxt_entry *lxt_start;
  376. u32 lxt_cnt;
  377. u16 rsvd;
  378. u8 fp; /* format & perm nibbles.
  379. * (if no perm, afu_rc=0x05)
  380. */
  381. u8 nmask;
  382. } __packed __aligned(16);
  383. struct sisl_rht_entry_f1 {
  384. u64 lun_id;
  385. union {
  386. struct {
  387. u8 valid;
  388. u8 rsvd[5];
  389. u8 fp;
  390. u8 port_sel;
  391. };
  392. u64 dw;
  393. };
  394. } __packed __aligned(16);
  395. /* make the fp byte */
  396. #define SISL_RHT_FP(fmt, perm) (((fmt) << 4) | (perm))
  397. /* make the fp byte for a clone from a source fp and clone flags
  398. * flags must be only 2 LSB bits.
  399. */
  400. #define SISL_RHT_FP_CLONE(src_fp, cln_flags) ((src_fp) & (0xFC | (cln_flags)))
  401. #define RHT_PERM_READ 0x01U
  402. #define RHT_PERM_WRITE 0x02U
  403. #define RHT_PERM_RW (RHT_PERM_READ | RHT_PERM_WRITE)
  404. /* extract the perm bits from a fp */
  405. #define SISL_RHT_PERM(fp) ((fp) & RHT_PERM_RW)
  406. #define PORT0 0x01U
  407. #define PORT1 0x02U
  408. #define BOTH_PORTS (PORT0 | PORT1)
  409. /* AFU Sync Mode byte */
  410. #define AFU_LW_SYNC 0x0U
  411. #define AFU_HW_SYNC 0x1U
  412. #define AFU_GSYNC 0x2U
  413. /* Special Task Management Function CDB */
  414. #define TMF_LUN_RESET 0x1U
  415. #define TMF_CLEAR_ACA 0x2U
  416. #define SISLITE_MAX_WS_BLOCKS 512
  417. #endif /* _SISLITE_H */