zcrypt.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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. /**
  208. * struct zcrypt_device_status
  209. * @hwtype: raw hardware type
  210. * @qid: 6 bit device index, 8 bit domain
  211. * @functions: AP device function bit field 'abcdef'
  212. * a, b, c = reserved
  213. * d = CCA coprocessor
  214. * e = Accelerator
  215. * f = EP11 coprocessor
  216. * @online online status
  217. * @reserved reserved
  218. */
  219. struct zcrypt_device_status {
  220. unsigned int hwtype:8;
  221. unsigned int qid:14;
  222. unsigned int online:1;
  223. unsigned int functions:6;
  224. unsigned int reserved:3;
  225. };
  226. #define MAX_ZDEV_CARDIDS 64
  227. #define MAX_ZDEV_DOMAINS 256
  228. /**
  229. * Maximum number of zcrypt devices
  230. */
  231. #define MAX_ZDEV_ENTRIES (MAX_ZDEV_CARDIDS * MAX_ZDEV_DOMAINS)
  232. /**
  233. * zcrypt_device_matrix
  234. * Device matrix of all zcrypt devices
  235. */
  236. struct zcrypt_device_matrix {
  237. struct zcrypt_device_status device[MAX_ZDEV_ENTRIES];
  238. };
  239. #define AUTOSELECT ((unsigned int)0xFFFFFFFF)
  240. #define ZCRYPT_IOCTL_MAGIC 'z'
  241. /**
  242. * Interface notes:
  243. *
  244. * The ioctl()s which are implemented (along with relevant details)
  245. * are:
  246. *
  247. * ICARSAMODEXPO
  248. * Perform an RSA operation using a Modulus-Exponent pair
  249. * This takes an ica_rsa_modexpo struct as its arg.
  250. *
  251. * NOTE: please refer to the comments preceding this structure
  252. * for the implementation details for the contents of the
  253. * block
  254. *
  255. * ICARSACRT
  256. * Perform an RSA operation using a Chinese-Remainder Theorem key
  257. * This takes an ica_rsa_modexpo_crt struct as its arg.
  258. *
  259. * NOTE: please refer to the comments preceding this structure
  260. * for the implementation details for the contents of the
  261. * block
  262. *
  263. * ZSECSENDCPRB
  264. * Send an arbitrary CPRB to a crypto card.
  265. *
  266. * ZSENDEP11CPRB
  267. * Send an arbitrary EP11 CPRB to an EP11 coprocessor crypto card.
  268. *
  269. * Z90STAT_STATUS_MASK
  270. * Return an 64 element array of unsigned chars for the status of
  271. * all devices.
  272. * 0x01: PCICA
  273. * 0x02: PCICC
  274. * 0x03: PCIXCC_MCL2
  275. * 0x04: PCIXCC_MCL3
  276. * 0x05: CEX2C
  277. * 0x06: CEX2A
  278. * 0x0d: device is disabled via the proc filesystem
  279. *
  280. * Z90STAT_QDEPTH_MASK
  281. * Return an 64 element array of unsigned chars for the queue
  282. * depth of all devices.
  283. *
  284. * Z90STAT_PERDEV_REQCNT
  285. * Return an 64 element array of unsigned integers for the number
  286. * of successfully completed requests per device since the device
  287. * was detected and made available.
  288. *
  289. * Z90STAT_REQUESTQ_COUNT
  290. * Return an integer count of the number of entries waiting to be
  291. * sent to a device.
  292. *
  293. * Z90STAT_PENDINGQ_COUNT
  294. * Return an integer count of the number of entries sent to all
  295. * devices awaiting the reply.
  296. *
  297. * Z90STAT_TOTALOPEN_COUNT
  298. * Return an integer count of the number of open file handles.
  299. *
  300. * Z90STAT_DOMAIN_INDEX
  301. * Return the integer value of the Cryptographic Domain.
  302. *
  303. * The following ioctls are deprecated and should be no longer used:
  304. *
  305. * Z90STAT_TOTALCOUNT
  306. * Return an integer count of all device types together.
  307. *
  308. * Z90STAT_PCICACOUNT
  309. * Return an integer count of all PCICAs.
  310. *
  311. * Z90STAT_PCICCCOUNT
  312. * Return an integer count of all PCICCs.
  313. *
  314. * Z90STAT_PCIXCCMCL2COUNT
  315. * Return an integer count of all MCL2 PCIXCCs.
  316. *
  317. * Z90STAT_PCIXCCMCL3COUNT
  318. * Return an integer count of all MCL3 PCIXCCs.
  319. *
  320. * Z90STAT_CEX2CCOUNT
  321. * Return an integer count of all CEX2Cs.
  322. *
  323. * Z90STAT_CEX2ACOUNT
  324. * Return an integer count of all CEX2As.
  325. *
  326. * ICAZ90STATUS
  327. * Return some device driver status in a ica_z90_status struct
  328. * This takes an ica_z90_status struct as its arg.
  329. *
  330. * Z90STAT_PCIXCCCOUNT
  331. * Return an integer count of all PCIXCCs (MCL2 + MCL3).
  332. * This is DEPRECATED now that MCL3 PCIXCCs are treated differently from
  333. * MCL2 PCIXCCs.
  334. */
  335. /**
  336. * Supported ioctl calls
  337. */
  338. #define ICARSAMODEXPO _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x05, 0)
  339. #define ICARSACRT _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x06, 0)
  340. #define ZSECSENDCPRB _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x81, 0)
  341. #define ZSENDEP11CPRB _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x04, 0)
  342. #define ZDEVICESTATUS _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x4f, 0)
  343. /* New status calls */
  344. #define Z90STAT_TOTALCOUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x40, int)
  345. #define Z90STAT_PCICACOUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x41, int)
  346. #define Z90STAT_PCICCCOUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x42, int)
  347. #define Z90STAT_PCIXCCMCL2COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x4b, int)
  348. #define Z90STAT_PCIXCCMCL3COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x4c, int)
  349. #define Z90STAT_CEX2CCOUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x4d, int)
  350. #define Z90STAT_CEX2ACOUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x4e, int)
  351. #define Z90STAT_REQUESTQ_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x44, int)
  352. #define Z90STAT_PENDINGQ_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x45, int)
  353. #define Z90STAT_TOTALOPEN_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x46, int)
  354. #define Z90STAT_DOMAIN_INDEX _IOR(ZCRYPT_IOCTL_MAGIC, 0x47, int)
  355. #define Z90STAT_STATUS_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x48, char[64])
  356. #define Z90STAT_QDEPTH_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x49, char[64])
  357. #define Z90STAT_PERDEV_REQCNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x4a, int[64])
  358. #endif /* __ASM_S390_ZCRYPT_H */