zcrypt.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
  2. /*
  3. * include/asm-s390/zcrypt.h
  4. *
  5. * zcrypt 2.2.1 (user-visible header)
  6. *
  7. * Copyright IBM Corp. 2001, 2022
  8. * Author(s): Robert Burroughs
  9. * Eric Rossman ([email protected])
  10. *
  11. * Hotplug & misc device support: Jochen Roehrig ([email protected])
  12. */
  13. #ifndef __ASM_S390_ZCRYPT_H
  14. #define __ASM_S390_ZCRYPT_H
  15. #define ZCRYPT_VERSION 2
  16. #define ZCRYPT_RELEASE 2
  17. #define ZCRYPT_VARIANT 1
  18. #include <linux/ioctl.h>
  19. #include <linux/compiler.h>
  20. #include <linux/types.h>
  21. /* Name of the zcrypt device driver. */
  22. #define ZCRYPT_NAME "zcrypt"
  23. /**
  24. * struct ica_rsa_modexpo
  25. *
  26. * Requirements:
  27. * - outputdatalength is at least as large as inputdatalength.
  28. * - All key parts are right justified in their fields, padded on
  29. * the left with zeroes.
  30. * - length(b_key) = inputdatalength
  31. * - length(n_modulus) = inputdatalength
  32. */
  33. struct ica_rsa_modexpo {
  34. __u8 __user *inputdata;
  35. __u32 inputdatalength;
  36. __u8 __user *outputdata;
  37. __u32 outputdatalength;
  38. __u8 __user *b_key;
  39. __u8 __user *n_modulus;
  40. };
  41. /**
  42. * struct ica_rsa_modexpo_crt
  43. *
  44. * Requirements:
  45. * - inputdatalength is even.
  46. * - outputdatalength is at least as large as inputdatalength.
  47. * - All key parts are right justified in their fields, padded on
  48. * the left with zeroes.
  49. * - length(bp_key) = inputdatalength/2 + 8
  50. * - length(bq_key) = inputdatalength/2
  51. * - length(np_key) = inputdatalength/2 + 8
  52. * - length(nq_key) = inputdatalength/2
  53. * - length(u_mult_inv) = inputdatalength/2 + 8
  54. */
  55. struct ica_rsa_modexpo_crt {
  56. __u8 __user *inputdata;
  57. __u32 inputdatalength;
  58. __u8 __user *outputdata;
  59. __u32 outputdatalength;
  60. __u8 __user *bp_key;
  61. __u8 __user *bq_key;
  62. __u8 __user *np_prime;
  63. __u8 __user *nq_prime;
  64. __u8 __user *u_mult_inv;
  65. };
  66. /**
  67. * CPRBX
  68. * Note that all shorts and ints are big-endian.
  69. * All pointer fields are 16 bytes long, and mean nothing.
  70. *
  71. * A request CPRB is followed by a request_parameter_block.
  72. *
  73. * The request (or reply) parameter block is organized thus:
  74. * function code
  75. * VUD block
  76. * key block
  77. */
  78. struct CPRBX {
  79. __u16 cprb_len; /* CPRB length 220 */
  80. __u8 cprb_ver_id; /* CPRB version id. 0x02 */
  81. __u8 _pad_000[3]; /* Alignment pad bytes */
  82. __u8 func_id[2]; /* function id 0x5432 */
  83. __u8 cprb_flags[4]; /* Flags */
  84. __u32 req_parml; /* request parameter buffer len */
  85. __u32 req_datal; /* request data buffer */
  86. __u32 rpl_msgbl; /* reply message block length */
  87. __u32 rpld_parml; /* replied parameter block len */
  88. __u32 rpl_datal; /* reply data block len */
  89. __u32 rpld_datal; /* replied data block len */
  90. __u32 req_extbl; /* request extension block len */
  91. __u8 _pad_001[4]; /* reserved */
  92. __u32 rpld_extbl; /* replied extension block len */
  93. __u8 _pad_002[16 - sizeof(__u8 *)];
  94. __u8 __user *req_parmb; /* request parm block 'address' */
  95. __u8 _pad_003[16 - sizeof(__u8 *)];
  96. __u8 __user *req_datab; /* request data block 'address' */
  97. __u8 _pad_004[16 - sizeof(__u8 *)];
  98. __u8 __user *rpl_parmb; /* reply parm block 'address' */
  99. __u8 _pad_005[16 - sizeof(__u8 *)];
  100. __u8 __user *rpl_datab; /* reply data block 'address' */
  101. __u8 _pad_006[16 - sizeof(__u8 *)];
  102. __u8 __user *req_extb; /* request extension block 'addr'*/
  103. __u8 _pad_007[16 - sizeof(__u8 *)];
  104. __u8 __user *rpl_extb; /* reply extension block 'address'*/
  105. __u16 ccp_rtcode; /* server return code */
  106. __u16 ccp_rscode; /* server reason code */
  107. __u32 mac_data_len; /* Mac Data Length */
  108. __u8 logon_id[8]; /* Logon Identifier */
  109. __u8 mac_value[8]; /* Mac Value */
  110. __u8 mac_content_flgs; /* Mac content flag byte */
  111. __u8 _pad_008; /* Alignment */
  112. __u16 domain; /* Domain */
  113. __u8 _pad_009[12]; /* reserved, checked for zeros */
  114. __u8 _pad_010[36]; /* reserved */
  115. } __attribute__((packed));
  116. /**
  117. * xcRB
  118. */
  119. struct ica_xcRB {
  120. __u16 agent_ID;
  121. __u32 user_defined;
  122. __u16 request_ID;
  123. __u32 request_control_blk_length;
  124. __u8 _padding1[16 - sizeof(__u8 *)];
  125. __u8 __user *request_control_blk_addr;
  126. __u32 request_data_length;
  127. __u8 _padding2[16 - sizeof(__u8 *)];
  128. __u8 __user *request_data_address;
  129. __u32 reply_control_blk_length;
  130. __u8 _padding3[16 - sizeof(__u8 *)];
  131. __u8 __user *reply_control_blk_addr;
  132. __u32 reply_data_length;
  133. __u8 __padding4[16 - sizeof(__u8 *)];
  134. __u8 __user *reply_data_addr;
  135. __u16 priority_window;
  136. __u32 status;
  137. } __attribute__((packed));
  138. /**
  139. * struct ep11_cprb - EP11 connectivity programming request block
  140. * @cprb_len: CPRB header length [0x0020]
  141. * @cprb_ver_id: CPRB version id. [0x04]
  142. * @pad_000: Alignment pad bytes
  143. * @flags: Admin bit [0x80], Special bit [0x20]
  144. * @func_id: Function id / subtype [0x5434] "T4"
  145. * @source_id: Source id [originator id]
  146. * @target_id: Target id [usage/ctrl domain id]
  147. * @ret_code: Return code
  148. * @reserved1: Reserved
  149. * @reserved2: Reserved
  150. * @payload_len: Payload length
  151. */
  152. struct ep11_cprb {
  153. __u16 cprb_len;
  154. __u8 cprb_ver_id;
  155. __u8 pad_000[2];
  156. __u8 flags;
  157. __u8 func_id[2];
  158. __u32 source_id;
  159. __u32 target_id;
  160. __u32 ret_code;
  161. __u32 reserved1;
  162. __u32 reserved2;
  163. __u32 payload_len;
  164. } __attribute__((packed));
  165. /**
  166. * struct ep11_target_dev - EP11 target device list
  167. * @ap_id: AP device id
  168. * @dom_id: Usage domain id
  169. */
  170. struct ep11_target_dev {
  171. __u16 ap_id;
  172. __u16 dom_id;
  173. };
  174. /**
  175. * struct ep11_urb - EP11 user request block
  176. * @targets_num: Number of target adapters
  177. * @targets: Addr to target adapter list
  178. * @weight: Level of request priority
  179. * @req_no: Request id/number
  180. * @req_len: Request length
  181. * @req: Addr to request block
  182. * @resp_len: Response length
  183. * @resp: Addr to response block
  184. */
  185. struct ep11_urb {
  186. __u16 targets_num;
  187. __u8 __user *targets;
  188. __u64 weight;
  189. __u64 req_no;
  190. __u64 req_len;
  191. __u8 __user *req;
  192. __u64 resp_len;
  193. __u8 __user *resp;
  194. } __attribute__((packed));
  195. /**
  196. * struct zcrypt_device_status_ext
  197. * @hwtype: raw hardware type
  198. * @qid: 8 bit device index, 8 bit domain
  199. * @functions: AP device function bit field 'abcdef'
  200. * a, b, c = reserved
  201. * d = CCA coprocessor
  202. * e = Accelerator
  203. * f = EP11 coprocessor
  204. * @online online status
  205. * @reserved reserved
  206. */
  207. struct zcrypt_device_status_ext {
  208. unsigned int hwtype:8;
  209. unsigned int qid:16;
  210. unsigned int online:1;
  211. unsigned int functions:6;
  212. unsigned int reserved:1;
  213. };
  214. #define MAX_ZDEV_CARDIDS_EXT 256
  215. #define MAX_ZDEV_DOMAINS_EXT 256
  216. /* Maximum number of zcrypt devices */
  217. #define MAX_ZDEV_ENTRIES_EXT (MAX_ZDEV_CARDIDS_EXT * MAX_ZDEV_DOMAINS_EXT)
  218. /* Device matrix of all zcrypt devices */
  219. struct zcrypt_device_matrix_ext {
  220. struct zcrypt_device_status_ext device[MAX_ZDEV_ENTRIES_EXT];
  221. };
  222. #define AUTOSELECT 0xFFFFFFFF
  223. #define AUTOSEL_AP ((__u16)0xFFFF)
  224. #define AUTOSEL_DOM ((__u16)0xFFFF)
  225. #define ZCRYPT_IOCTL_MAGIC 'z'
  226. /**
  227. * Interface notes:
  228. *
  229. * The ioctl()s which are implemented (along with relevant details)
  230. * are:
  231. *
  232. * ICARSAMODEXPO
  233. * Perform an RSA operation using a Modulus-Exponent pair
  234. * This takes an ica_rsa_modexpo struct as its arg.
  235. *
  236. * NOTE: please refer to the comments preceding this structure
  237. * for the implementation details for the contents of the
  238. * block
  239. *
  240. * ICARSACRT
  241. * Perform an RSA operation using a Chinese-Remainder Theorem key
  242. * This takes an ica_rsa_modexpo_crt struct as its arg.
  243. *
  244. * NOTE: please refer to the comments preceding this structure
  245. * for the implementation details for the contents of the
  246. * block
  247. *
  248. * ZSECSENDCPRB
  249. * Send an arbitrary CPRB to a crypto card.
  250. *
  251. * ZSENDEP11CPRB
  252. * Send an arbitrary EP11 CPRB to an EP11 coprocessor crypto card.
  253. *
  254. * ZCRYPT_DEVICE_STATUS
  255. * The given struct zcrypt_device_matrix_ext is updated with
  256. * status information for each currently known apqn.
  257. *
  258. * ZCRYPT_STATUS_MASK
  259. * Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned chars for the
  260. * status of all devices.
  261. * 0x01: PCICA
  262. * 0x02: PCICC
  263. * 0x03: PCIXCC_MCL2
  264. * 0x04: PCIXCC_MCL3
  265. * 0x05: CEX2C
  266. * 0x06: CEX2A
  267. * 0x07: CEX3C
  268. * 0x08: CEX3A
  269. * 0x0a: CEX4
  270. * 0x0b: CEX5
  271. * 0x0c: CEX6, CEX7 or CEX8
  272. * 0x0d: device is disabled
  273. *
  274. * ZCRYPT_QDEPTH_MASK
  275. * Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned chars for the
  276. * queue depth of all devices.
  277. *
  278. * ZCRYPT_PERDEV_REQCNT
  279. * Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned integers for
  280. * the number of successfully completed requests per device since the
  281. * device was detected and made available.
  282. *
  283. */
  284. /**
  285. * Supported ioctl calls
  286. */
  287. #define ICARSAMODEXPO _IOC(_IOC_READ | _IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x05, 0)
  288. #define ICARSACRT _IOC(_IOC_READ | _IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x06, 0)
  289. #define ZSECSENDCPRB _IOC(_IOC_READ | _IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x81, 0)
  290. #define ZSENDEP11CPRB _IOC(_IOC_READ | _IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x04, 0)
  291. #define ZCRYPT_DEVICE_STATUS _IOC(_IOC_READ | _IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x5f, 0)
  292. #define ZCRYPT_STATUS_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x58, char[MAX_ZDEV_CARDIDS_EXT])
  293. #define ZCRYPT_QDEPTH_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x59, char[MAX_ZDEV_CARDIDS_EXT])
  294. #define ZCRYPT_PERDEV_REQCNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x5a, int[MAX_ZDEV_CARDIDS_EXT])
  295. /*
  296. * Support for multiple zcrypt device nodes.
  297. */
  298. /* Nr of minor device node numbers to allocate. */
  299. #define ZCRYPT_MAX_MINOR_NODES 256
  300. /* Max amount of possible ioctls */
  301. #define MAX_ZDEV_IOCTLS (1 << _IOC_NRBITS)
  302. /*
  303. * Only deprecated defines, structs and ioctls below this line.
  304. */
  305. /* Deprecated: use MAX_ZDEV_CARDIDS_EXT */
  306. #define MAX_ZDEV_CARDIDS 64
  307. /* Deprecated: use MAX_ZDEV_DOMAINS_EXT */
  308. #define MAX_ZDEV_DOMAINS 256
  309. /* Deprecated: use MAX_ZDEV_ENTRIES_EXT */
  310. #define MAX_ZDEV_ENTRIES (MAX_ZDEV_CARDIDS * MAX_ZDEV_DOMAINS)
  311. /* Deprecated: use struct zcrypt_device_status_ext */
  312. struct zcrypt_device_status {
  313. unsigned int hwtype:8;
  314. unsigned int qid:14;
  315. unsigned int online:1;
  316. unsigned int functions:6;
  317. unsigned int reserved:3;
  318. };
  319. /* Deprecated: use struct zcrypt_device_matrix_ext */
  320. struct zcrypt_device_matrix {
  321. struct zcrypt_device_status device[MAX_ZDEV_ENTRIES];
  322. };
  323. /* Deprecated: use ZCRYPT_DEVICE_STATUS */
  324. #define ZDEVICESTATUS _IOC(_IOC_READ | _IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x4f, 0)
  325. /* Deprecated: use ZCRYPT_STATUS_MASK */
  326. #define Z90STAT_STATUS_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x48, char[64])
  327. /* Deprecated: use ZCRYPT_QDEPTH_MASK */
  328. #define Z90STAT_QDEPTH_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x49, char[64])
  329. /* Deprecated: use ZCRYPT_PERDEV_REQCNT */
  330. #define Z90STAT_PERDEV_REQCNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x4a, int[64])
  331. /* Deprecated: use sysfs to query these values */
  332. #define Z90STAT_REQUESTQ_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x44, int)
  333. #define Z90STAT_PENDINGQ_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x45, int)
  334. #define Z90STAT_TOTALOPEN_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x46, int)
  335. #define Z90STAT_DOMAIN_INDEX _IOR(ZCRYPT_IOCTL_MAGIC, 0x47, int)
  336. /*
  337. * The ioctl number ranges 0x40 - 0x42 and 0x4b - 0x4e had been used in the
  338. * past, don't assign new ioctls for these.
  339. */
  340. #endif /* __ASM_S390_ZCRYPT_H */