zcrypt_error.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright IBM Corp. 2001, 2006
  4. * Author(s): Robert Burroughs
  5. * Eric Rossman (edrossma@us.ibm.com)
  6. *
  7. * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
  8. * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
  9. */
  10. #ifndef _ZCRYPT_ERROR_H_
  11. #define _ZCRYPT_ERROR_H_
  12. #include <linux/atomic.h>
  13. #include "zcrypt_debug.h"
  14. #include "zcrypt_api.h"
  15. #include "zcrypt_msgtype6.h"
  16. /**
  17. * Reply Messages
  18. *
  19. * Error reply messages are of two types:
  20. * 82: Error (see below)
  21. * 88: Error (see below)
  22. * Both type 82 and type 88 have the same structure in the header.
  23. *
  24. * Request reply messages are of three known types:
  25. * 80: Reply from a Type 50 Request (see CEX2A-RELATED STRUCTS)
  26. * 84: Reply from a Type 4 Request (see PCICA-RELATED STRUCTS)
  27. * 86: Reply from a Type 6 Request (see PCICC/PCIXCC/CEX2C-RELATED STRUCTS)
  28. *
  29. */
  30. struct error_hdr {
  31. unsigned char reserved1; /* 0x00 */
  32. unsigned char type; /* 0x82 or 0x88 */
  33. unsigned char reserved2[2]; /* 0x0000 */
  34. unsigned char reply_code; /* reply code */
  35. unsigned char reserved3[3]; /* 0x000000 */
  36. };
  37. #define TYPE82_RSP_CODE 0x82
  38. #define TYPE88_RSP_CODE 0x88
  39. #define REP82_ERROR_MACHINE_FAILURE 0x10
  40. #define REP82_ERROR_PREEMPT_FAILURE 0x12
  41. #define REP82_ERROR_CHECKPT_FAILURE 0x14
  42. #define REP82_ERROR_MESSAGE_TYPE 0x20
  43. #define REP82_ERROR_INVALID_COMM_CD 0x21 /* Type 84 */
  44. #define REP82_ERROR_INVALID_MSG_LEN 0x23
  45. #define REP82_ERROR_RESERVD_FIELD 0x24 /* was 0x50 */
  46. #define REP82_ERROR_FORMAT_FIELD 0x29
  47. #define REP82_ERROR_INVALID_COMMAND 0x30
  48. #define REP82_ERROR_MALFORMED_MSG 0x40
  49. #define REP82_ERROR_INVALID_DOMAIN_PRECHECK 0x42
  50. #define REP82_ERROR_RESERVED_FIELDO 0x50 /* old value */
  51. #define REP82_ERROR_WORD_ALIGNMENT 0x60
  52. #define REP82_ERROR_MESSAGE_LENGTH 0x80
  53. #define REP82_ERROR_OPERAND_INVALID 0x82
  54. #define REP82_ERROR_OPERAND_SIZE 0x84
  55. #define REP82_ERROR_EVEN_MOD_IN_OPND 0x85
  56. #define REP82_ERROR_RESERVED_FIELD 0x88
  57. #define REP82_ERROR_INVALID_DOMAIN_PENDING 0x8A
  58. #define REP82_ERROR_TRANSPORT_FAIL 0x90
  59. #define REP82_ERROR_PACKET_TRUNCATED 0xA0
  60. #define REP82_ERROR_ZERO_BUFFER_LEN 0xB0
  61. #define REP88_ERROR_MODULE_FAILURE 0x10
  62. #define REP88_ERROR_MESSAGE_TYPE 0x20
  63. #define REP88_ERROR_MESSAGE_MALFORMD 0x22
  64. #define REP88_ERROR_MESSAGE_LENGTH 0x23
  65. #define REP88_ERROR_RESERVED_FIELD 0x24
  66. #define REP88_ERROR_KEY_TYPE 0x34
  67. #define REP88_ERROR_INVALID_KEY 0x82 /* CEX2A */
  68. #define REP88_ERROR_OPERAND 0x84 /* CEX2A */
  69. #define REP88_ERROR_OPERAND_EVEN_MOD 0x85 /* CEX2A */
  70. static inline int convert_error(struct zcrypt_queue *zq,
  71. struct ap_message *reply)
  72. {
  73. struct error_hdr *ehdr = reply->message;
  74. int card = AP_QID_CARD(zq->queue->qid);
  75. int queue = AP_QID_QUEUE(zq->queue->qid);
  76. switch (ehdr->reply_code) {
  77. case REP82_ERROR_OPERAND_INVALID:
  78. case REP82_ERROR_OPERAND_SIZE:
  79. case REP82_ERROR_EVEN_MOD_IN_OPND:
  80. case REP88_ERROR_MESSAGE_MALFORMD:
  81. case REP82_ERROR_INVALID_DOMAIN_PRECHECK:
  82. case REP82_ERROR_INVALID_DOMAIN_PENDING:
  83. // REP88_ERROR_INVALID_KEY // '82' CEX2A
  84. // REP88_ERROR_OPERAND // '84' CEX2A
  85. // REP88_ERROR_OPERAND_EVEN_MOD // '85' CEX2A
  86. /* Invalid input data. */
  87. ZCRYPT_DBF(DBF_WARN,
  88. "device=%02x.%04x reply=0x%02x => rc=EINVAL\n",
  89. card, queue, ehdr->reply_code);
  90. return -EINVAL;
  91. case REP82_ERROR_MESSAGE_TYPE:
  92. // REP88_ERROR_MESSAGE_TYPE // '20' CEX2A
  93. /*
  94. * To sent a message of the wrong type is a bug in the
  95. * device driver. Send error msg, disable the device
  96. * and then repeat the request.
  97. */
  98. atomic_set(&zcrypt_rescan_req, 1);
  99. zq->online = 0;
  100. pr_err("Cryptographic device %02x.%04x failed and was set offline\n",
  101. card, queue);
  102. ZCRYPT_DBF(DBF_ERR,
  103. "device=%02x.%04x reply=0x%02x => online=0 rc=EAGAIN\n",
  104. card, queue, ehdr->reply_code);
  105. return -EAGAIN;
  106. case REP82_ERROR_TRANSPORT_FAIL:
  107. /* Card or infrastructure failure, disable card */
  108. atomic_set(&zcrypt_rescan_req, 1);
  109. zq->online = 0;
  110. pr_err("Cryptographic device %02x.%04x failed and was set offline\n",
  111. card, queue);
  112. /* For type 86 response show the apfs value (failure reason) */
  113. if (ehdr->type == TYPE86_RSP_CODE) {
  114. struct {
  115. struct type86_hdr hdr;
  116. struct type86_fmt2_ext fmt2;
  117. } __packed * head = reply->message;
  118. unsigned int apfs = *((u32 *)head->fmt2.apfs);
  119. ZCRYPT_DBF(DBF_ERR,
  120. "device=%02x.%04x reply=0x%02x apfs=0x%x => online=0 rc=EAGAIN\n",
  121. card, queue, apfs, ehdr->reply_code);
  122. } else
  123. ZCRYPT_DBF(DBF_ERR,
  124. "device=%02x.%04x reply=0x%02x => online=0 rc=EAGAIN\n",
  125. card, queue, ehdr->reply_code);
  126. return -EAGAIN;
  127. case REP82_ERROR_MACHINE_FAILURE:
  128. // REP88_ERROR_MODULE_FAILURE // '10' CEX2A
  129. /* If a card fails disable it and repeat the request. */
  130. atomic_set(&zcrypt_rescan_req, 1);
  131. zq->online = 0;
  132. pr_err("Cryptographic device %02x.%04x failed and was set offline\n",
  133. card, queue);
  134. ZCRYPT_DBF(DBF_ERR,
  135. "device=%02x.%04x reply=0x%02x => online=0 rc=EAGAIN\n",
  136. card, queue, ehdr->reply_code);
  137. return -EAGAIN;
  138. default:
  139. zq->online = 0;
  140. pr_err("Cryptographic device %02x.%04x failed and was set offline\n",
  141. card, queue);
  142. ZCRYPT_DBF(DBF_ERR,
  143. "device=%02x.%04x reply=0x%02x => online=0 rc=EAGAIN\n",
  144. card, queue, ehdr->reply_code);
  145. return -EAGAIN; /* repeat the request on a different device. */
  146. }
  147. }
  148. #endif /* _ZCRYPT_ERROR_H_ */