zcrypt.h 11 KB

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