zcrypt.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
  2. /*
  3. * include/asm-s390/zcrypt.h
  4. *
  5. * zcrypt 2.1.0 (user-visible header)
  6. *
  7. * Copyright IBM Corp. 2001, 2006
  8. * Author(s): Robert Burroughs
  9. * Eric Rossman (edrossma@us.ibm.com)
  10. *
  11. * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2, or (at your option)
  16. * any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. */
  27. #ifndef __ASM_S390_ZCRYPT_H
  28. #define __ASM_S390_ZCRYPT_H
  29. #define ZCRYPT_VERSION 2
  30. #define ZCRYPT_RELEASE 1
  31. #define ZCRYPT_VARIANT 1
  32. #include <linux/ioctl.h>
  33. #include <linux/compiler.h>
  34. /**
  35. * struct ica_rsa_modexpo
  36. *
  37. * Requirements:
  38. * - outputdatalength is at least as large as inputdatalength.
  39. * - All key parts are right justified in their fields, padded on
  40. * the left with zeroes.
  41. * - length(b_key) = inputdatalength
  42. * - length(n_modulus) = inputdatalength
  43. */
  44. struct ica_rsa_modexpo {
  45. char __user * inputdata;
  46. unsigned int inputdatalength;
  47. char __user * outputdata;
  48. unsigned int outputdatalength;
  49. char __user * b_key;
  50. char __user * n_modulus;
  51. };
  52. /**
  53. * struct ica_rsa_modexpo_crt
  54. *
  55. * Requirements:
  56. * - inputdatalength is even.
  57. * - outputdatalength is at least as large as inputdatalength.
  58. * - All key parts are right justified in their fields, padded on
  59. * the left with zeroes.
  60. * - length(bp_key) = inputdatalength/2 + 8
  61. * - length(bq_key) = inputdatalength/2
  62. * - length(np_key) = inputdatalength/2 + 8
  63. * - length(nq_key) = inputdatalength/2
  64. * - length(u_mult_inv) = inputdatalength/2 + 8
  65. */
  66. struct ica_rsa_modexpo_crt {
  67. char __user * inputdata;
  68. unsigned int inputdatalength;
  69. char __user * outputdata;
  70. unsigned int outputdatalength;
  71. char __user * bp_key;
  72. char __user * bq_key;
  73. char __user * np_prime;
  74. char __user * nq_prime;
  75. char __user * u_mult_inv;
  76. };
  77. /**
  78. * CPRBX
  79. * Note that all shorts and ints are big-endian.
  80. * All pointer fields are 16 bytes long, and mean nothing.
  81. *
  82. * A request CPRB is followed by a request_parameter_block.
  83. *
  84. * The request (or reply) parameter block is organized thus:
  85. * function code
  86. * VUD block
  87. * key block
  88. */
  89. struct CPRBX {
  90. unsigned short cprb_len; /* CPRB length 220 */
  91. unsigned char cprb_ver_id; /* CPRB version id. 0x02 */
  92. unsigned char pad_000[3]; /* Alignment pad bytes */
  93. unsigned char func_id[2]; /* function id 0x5432 */
  94. unsigned char cprb_flags[4]; /* Flags */
  95. unsigned int req_parml; /* request parameter buffer len */
  96. unsigned int req_datal; /* request data buffer */
  97. unsigned int rpl_msgbl; /* reply message block length */
  98. unsigned int rpld_parml; /* replied parameter block len */
  99. unsigned int rpl_datal; /* reply data block len */
  100. unsigned int rpld_datal; /* replied data block len */
  101. unsigned int req_extbl; /* request extension block len */
  102. unsigned char pad_001[4]; /* reserved */
  103. unsigned int rpld_extbl; /* replied extension block len */
  104. unsigned char padx000[16 - sizeof (char *)];
  105. unsigned char * req_parmb; /* request parm block 'address' */
  106. unsigned char padx001[16 - sizeof (char *)];
  107. unsigned char * req_datab; /* request data block 'address' */
  108. unsigned char padx002[16 - sizeof (char *)];
  109. unsigned char * rpl_parmb; /* reply parm block 'address' */
  110. unsigned char padx003[16 - sizeof (char *)];
  111. unsigned char * rpl_datab; /* reply data block 'address' */
  112. unsigned char padx004[16 - sizeof (char *)];
  113. unsigned char * req_extb; /* request extension block 'addr'*/
  114. unsigned char padx005[16 - sizeof (char *)];
  115. unsigned char * rpl_extb; /* reply extension block 'address'*/
  116. unsigned short ccp_rtcode; /* server return code */
  117. unsigned short ccp_rscode; /* server reason code */
  118. unsigned int mac_data_len; /* Mac Data Length */
  119. unsigned char logon_id[8]; /* Logon Identifier */
  120. unsigned char mac_value[8]; /* Mac Value */
  121. unsigned char mac_content_flgs;/* Mac content flag byte */
  122. unsigned char pad_002; /* Alignment */
  123. unsigned short domain; /* Domain */
  124. unsigned char usage_domain[4];/* Usage domain */
  125. unsigned char cntrl_domain[4];/* Control domain */
  126. unsigned char S390enf_mask[4];/* S/390 enforcement mask */
  127. unsigned char pad_004[36]; /* reserved */
  128. } __attribute__((packed));
  129. /**
  130. * xcRB
  131. */
  132. struct ica_xcRB {
  133. unsigned short agent_ID;
  134. unsigned int user_defined;
  135. unsigned short request_ID;
  136. unsigned int request_control_blk_length;
  137. unsigned char padding1[16 - sizeof (char *)];
  138. char __user * request_control_blk_addr;
  139. unsigned int request_data_length;
  140. char padding2[16 - sizeof (char *)];
  141. char __user * request_data_address;
  142. unsigned int reply_control_blk_length;
  143. char padding3[16 - sizeof (char *)];
  144. char __user * reply_control_blk_addr;
  145. unsigned int reply_data_length;
  146. char padding4[16 - sizeof (char *)];
  147. char __user * reply_data_addr;
  148. unsigned short priority_window;
  149. unsigned int status;
  150. } __attribute__((packed));
  151. /**
  152. * struct ep11_cprb - EP11 connectivity programming request block
  153. * @cprb_len: CPRB header length [0x0020]
  154. * @cprb_ver_id: CPRB version id. [0x04]
  155. * @pad_000: Alignment pad bytes
  156. * @flags: Admin bit [0x80], Special bit [0x20]
  157. * @func_id: Function id / subtype [0x5434] "T4"
  158. * @source_id: Source id [originator id]
  159. * @target_id: Target id [usage/ctrl domain id]
  160. * @ret_code: Return code
  161. * @reserved1: Reserved
  162. * @reserved2: Reserved
  163. * @payload_len: Payload length
  164. */
  165. struct ep11_cprb {
  166. uint16_t cprb_len;
  167. unsigned char cprb_ver_id;
  168. unsigned char pad_000[2];
  169. unsigned char flags;
  170. unsigned char func_id[2];
  171. uint32_t source_id;
  172. uint32_t target_id;
  173. uint32_t ret_code;
  174. uint32_t reserved1;
  175. uint32_t reserved2;
  176. uint32_t payload_len;
  177. } __attribute__((packed));
  178. /**
  179. * struct ep11_target_dev - EP11 target device list
  180. * @ap_id: AP device id
  181. * @dom_id: Usage domain id
  182. */
  183. struct ep11_target_dev {
  184. uint16_t ap_id;
  185. uint16_t dom_id;
  186. };
  187. /**
  188. * struct ep11_urb - EP11 user request block
  189. * @targets_num: Number of target adapters
  190. * @targets: Addr to target adapter list
  191. * @weight: Level of request priority
  192. * @req_no: Request id/number
  193. * @req_len: Request length
  194. * @req: Addr to request block
  195. * @resp_len: Response length
  196. * @resp: Addr to response block
  197. */
  198. struct ep11_urb {
  199. uint16_t targets_num;
  200. uint64_t targets;
  201. uint64_t weight;
  202. uint64_t req_no;
  203. uint64_t req_len;
  204. uint64_t req;
  205. uint64_t resp_len;
  206. uint64_t resp;
  207. } __attribute__((packed));
  208. /**
  209. * struct zcrypt_device_status
  210. * @hwtype: raw hardware type
  211. * @qid: 6 bit device index, 8 bit domain
  212. * @functions: AP device function bit field 'abcdef'
  213. * a, b, c = reserved
  214. * d = CCA coprocessor
  215. * e = Accelerator
  216. * f = EP11 coprocessor
  217. * @online online status
  218. * @reserved reserved
  219. */
  220. struct zcrypt_device_status {
  221. unsigned int hwtype:8;
  222. unsigned int qid:14;
  223. unsigned int online:1;
  224. unsigned int functions:6;
  225. unsigned int reserved:3;
  226. };
  227. #define MAX_ZDEV_CARDIDS 64
  228. #define MAX_ZDEV_DOMAINS 256
  229. /**
  230. * Maximum number of zcrypt devices
  231. */
  232. #define MAX_ZDEV_ENTRIES (MAX_ZDEV_CARDIDS * MAX_ZDEV_DOMAINS)
  233. /**
  234. * zcrypt_device_matrix
  235. * Device matrix of all zcrypt devices
  236. */
  237. struct zcrypt_device_matrix {
  238. struct zcrypt_device_status device[MAX_ZDEV_ENTRIES];
  239. };
  240. #define AUTOSELECT ((unsigned int)0xFFFFFFFF)
  241. #define ZCRYPT_IOCTL_MAGIC 'z'
  242. /**
  243. * Interface notes:
  244. *
  245. * The ioctl()s which are implemented (along with relevant details)
  246. * are:
  247. *
  248. * ICARSAMODEXPO
  249. * Perform an RSA operation using a Modulus-Exponent pair
  250. * This takes an ica_rsa_modexpo struct as its arg.
  251. *
  252. * NOTE: please refer to the comments preceding this structure
  253. * for the implementation details for the contents of the
  254. * block
  255. *
  256. * ICARSACRT
  257. * Perform an RSA operation using a Chinese-Remainder Theorem key
  258. * This takes an ica_rsa_modexpo_crt struct as its arg.
  259. *
  260. * NOTE: please refer to the comments preceding this structure
  261. * for the implementation details for the contents of the
  262. * block
  263. *
  264. * ZSECSENDCPRB
  265. * Send an arbitrary CPRB to a crypto card.
  266. *
  267. * ZSENDEP11CPRB
  268. * Send an arbitrary EP11 CPRB to an EP11 coprocessor crypto card.
  269. *
  270. * Z90STAT_STATUS_MASK
  271. * Return an 64 element array of unsigned chars for the status of
  272. * all devices.
  273. * 0x01: PCICA
  274. * 0x02: PCICC
  275. * 0x03: PCIXCC_MCL2
  276. * 0x04: PCIXCC_MCL3
  277. * 0x05: CEX2C
  278. * 0x06: CEX2A
  279. * 0x0d: device is disabled via the proc filesystem
  280. *
  281. * Z90STAT_QDEPTH_MASK
  282. * Return an 64 element array of unsigned chars for the queue
  283. * depth of all devices.
  284. *
  285. * Z90STAT_PERDEV_REQCNT
  286. * Return an 64 element array of unsigned integers for the number
  287. * of successfully completed requests per device since the device
  288. * was detected and made available.
  289. *
  290. * Z90STAT_REQUESTQ_COUNT
  291. * Return an integer count of the number of entries waiting to be
  292. * sent to a device.
  293. *
  294. * Z90STAT_PENDINGQ_COUNT
  295. * Return an integer count of the number of entries sent to all
  296. * devices awaiting the reply.
  297. *
  298. * Z90STAT_TOTALOPEN_COUNT
  299. * Return an integer count of the number of open file handles.
  300. *
  301. * Z90STAT_DOMAIN_INDEX
  302. * Return the integer value of the Cryptographic Domain.
  303. *
  304. * The following ioctls are deprecated and should be no longer used:
  305. *
  306. * Z90STAT_TOTALCOUNT
  307. * Return an integer count of all device types together.
  308. *
  309. * Z90STAT_PCICACOUNT
  310. * Return an integer count of all PCICAs.
  311. *
  312. * Z90STAT_PCICCCOUNT
  313. * Return an integer count of all PCICCs.
  314. *
  315. * Z90STAT_PCIXCCMCL2COUNT
  316. * Return an integer count of all MCL2 PCIXCCs.
  317. *
  318. * Z90STAT_PCIXCCMCL3COUNT
  319. * Return an integer count of all MCL3 PCIXCCs.
  320. *
  321. * Z90STAT_CEX2CCOUNT
  322. * Return an integer count of all CEX2Cs.
  323. *
  324. * Z90STAT_CEX2ACOUNT
  325. * Return an integer count of all CEX2As.
  326. *
  327. * ICAZ90STATUS
  328. * Return some device driver status in a ica_z90_status struct
  329. * This takes an ica_z90_status struct as its arg.
  330. *
  331. * Z90STAT_PCIXCCCOUNT
  332. * Return an integer count of all PCIXCCs (MCL2 + MCL3).
  333. * This is DEPRECATED now that MCL3 PCIXCCs are treated differently from
  334. * MCL2 PCIXCCs.
  335. */
  336. /**
  337. * Supported ioctl calls
  338. */
  339. #define ICARSAMODEXPO _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x05, 0)
  340. #define ICARSACRT _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x06, 0)
  341. #define ZSECSENDCPRB _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x81, 0)
  342. #define ZSENDEP11CPRB _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x04, 0)
  343. #define ZDEVICESTATUS _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x4f, 0)
  344. /* New status calls */
  345. #define Z90STAT_TOTALCOUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x40, int)
  346. #define Z90STAT_PCICACOUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x41, int)
  347. #define Z90STAT_PCICCCOUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x42, int)
  348. #define Z90STAT_PCIXCCMCL2COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x4b, int)
  349. #define Z90STAT_PCIXCCMCL3COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x4c, int)
  350. #define Z90STAT_CEX2CCOUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x4d, int)
  351. #define Z90STAT_CEX2ACOUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x4e, int)
  352. #define Z90STAT_REQUESTQ_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x44, int)
  353. #define Z90STAT_PENDINGQ_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x45, int)
  354. #define Z90STAT_TOTALOPEN_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x46, int)
  355. #define Z90STAT_DOMAIN_INDEX _IOR(ZCRYPT_IOCTL_MAGIC, 0x47, int)
  356. #define Z90STAT_STATUS_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x48, char[64])
  357. #define Z90STAT_QDEPTH_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x49, char[64])
  358. #define Z90STAT_PERDEV_REQCNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x4a, int[64])
  359. #endif /* __ASM_S390_ZCRYPT_H */