0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef _ZCRYPT_ERROR_H_
0012 #define _ZCRYPT_ERROR_H_
0013
0014 #include <linux/atomic.h>
0015 #include "zcrypt_debug.h"
0016 #include "zcrypt_api.h"
0017 #include "zcrypt_msgtype6.h"
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 struct error_hdr {
0034 unsigned char reserved1;
0035 unsigned char type;
0036 unsigned char reserved2[2];
0037 unsigned char reply_code;
0038 unsigned char reserved3[3];
0039 };
0040
0041 #define TYPE82_RSP_CODE 0x82
0042 #define TYPE88_RSP_CODE 0x88
0043
0044 #define REP82_ERROR_MACHINE_FAILURE 0x10
0045 #define REP82_ERROR_PREEMPT_FAILURE 0x12
0046 #define REP82_ERROR_CHECKPT_FAILURE 0x14
0047 #define REP82_ERROR_MESSAGE_TYPE 0x20
0048 #define REP82_ERROR_INVALID_COMM_CD 0x21
0049 #define REP82_ERROR_INVALID_MSG_LEN 0x23
0050 #define REP82_ERROR_RESERVD_FIELD 0x24
0051 #define REP82_ERROR_FORMAT_FIELD 0x29
0052 #define REP82_ERROR_INVALID_COMMAND 0x30
0053 #define REP82_ERROR_MALFORMED_MSG 0x40
0054 #define REP82_ERROR_INVALID_SPECIAL_CMD 0x41
0055 #define REP82_ERROR_RESERVED_FIELDO 0x50
0056 #define REP82_ERROR_WORD_ALIGNMENT 0x60
0057 #define REP82_ERROR_MESSAGE_LENGTH 0x80
0058 #define REP82_ERROR_OPERAND_INVALID 0x82
0059 #define REP82_ERROR_OPERAND_SIZE 0x84
0060 #define REP82_ERROR_EVEN_MOD_IN_OPND 0x85
0061 #define REP82_ERROR_RESERVED_FIELD 0x88
0062 #define REP82_ERROR_INVALID_DOMAIN_PENDING 0x8A
0063 #define REP82_ERROR_FILTERED_BY_HYPERVISOR 0x8B
0064 #define REP82_ERROR_TRANSPORT_FAIL 0x90
0065 #define REP82_ERROR_PACKET_TRUNCATED 0xA0
0066 #define REP82_ERROR_ZERO_BUFFER_LEN 0xB0
0067
0068 #define REP88_ERROR_MODULE_FAILURE 0x10
0069 #define REP88_ERROR_MESSAGE_TYPE 0x20
0070 #define REP88_ERROR_MESSAGE_MALFORMD 0x22
0071 #define REP88_ERROR_MESSAGE_LENGTH 0x23
0072 #define REP88_ERROR_RESERVED_FIELD 0x24
0073 #define REP88_ERROR_KEY_TYPE 0x34
0074 #define REP88_ERROR_INVALID_KEY 0x82
0075 #define REP88_ERROR_OPERAND 0x84
0076 #define REP88_ERROR_OPERAND_EVEN_MOD 0x85
0077
0078 static inline int convert_error(struct zcrypt_queue *zq,
0079 struct ap_message *reply)
0080 {
0081 struct error_hdr *ehdr = reply->msg;
0082 int card = AP_QID_CARD(zq->queue->qid);
0083 int queue = AP_QID_QUEUE(zq->queue->qid);
0084
0085 switch (ehdr->reply_code) {
0086 case REP82_ERROR_INVALID_MSG_LEN:
0087 case REP82_ERROR_RESERVD_FIELD:
0088 case REP82_ERROR_FORMAT_FIELD:
0089 case REP82_ERROR_MALFORMED_MSG:
0090 case REP82_ERROR_INVALID_SPECIAL_CMD:
0091 case REP82_ERROR_MESSAGE_LENGTH:
0092 case REP82_ERROR_OPERAND_INVALID:
0093 case REP82_ERROR_OPERAND_SIZE:
0094 case REP82_ERROR_EVEN_MOD_IN_OPND:
0095 case REP82_ERROR_INVALID_DOMAIN_PENDING:
0096 case REP82_ERROR_FILTERED_BY_HYPERVISOR:
0097 case REP82_ERROR_PACKET_TRUNCATED:
0098 case REP88_ERROR_MESSAGE_MALFORMD:
0099 case REP88_ERROR_KEY_TYPE:
0100
0101 ZCRYPT_DBF_WARN("%s dev=%02x.%04x RY=0x%02x => rc=EINVAL\n",
0102 __func__, card, queue, ehdr->reply_code);
0103 return -EINVAL;
0104 case REP82_ERROR_MACHINE_FAILURE:
0105 case REP82_ERROR_MESSAGE_TYPE:
0106 case REP82_ERROR_TRANSPORT_FAIL:
0107
0108
0109
0110
0111 atomic_set(&zcrypt_rescan_req, 1);
0112
0113 if (ehdr->reply_code == REP82_ERROR_TRANSPORT_FAIL &&
0114 ehdr->type == TYPE86_RSP_CODE) {
0115 struct {
0116 struct type86_hdr hdr;
0117 struct type86_fmt2_ext fmt2;
0118 } __packed * head = reply->msg;
0119 unsigned int apfs = *((u32 *)head->fmt2.apfs);
0120
0121 ZCRYPT_DBF_WARN(
0122 "%s dev=%02x.%04x RY=0x%02x apfs=0x%x => bus rescan, rc=EAGAIN\n",
0123 __func__, card, queue, ehdr->reply_code, apfs);
0124 } else {
0125 ZCRYPT_DBF_WARN("%s dev=%02x.%04x RY=0x%02x => bus rescan, rc=EAGAIN\n",
0126 __func__, card, queue,
0127 ehdr->reply_code);
0128 }
0129 return -EAGAIN;
0130 default:
0131
0132 ZCRYPT_DBF_WARN("%s dev=%02x.%04x RY=0x%02x => rc=EAGAIN\n",
0133 __func__, card, queue, ehdr->reply_code);
0134 return -EAGAIN;
0135 }
0136 }
0137
0138 #endif