| 1 |
|
| 2 | |
| 3 | * Copyright IBM Corp. 2001, 2006
|
| 4 | * Author(s): Robert Burroughs
|
| 5 | * Eric Rossman ([email protected])
|
| 6 | *
|
| 7 | * Hotplug & misc device support: Jochen Roehrig ([email protected])
|
| 8 | * Major cleanup & driver split: Martin Schwidefsky <[email protected]>
|
| 9 |
|
| 10 |
|
| 11 | #ifndef _ZCRYPT_ERROR_H_
|
| 12 | #define _ZCRYPT_ERROR_H_
|
| 13 |
|
| 14 | #include <linux/atomic.h>
|
| 15 | #include "zcrypt_debug.h"
|
| 16 | #include "zcrypt_api.h"
|
| 17 | #include "zcrypt_msgtype6.h"
|
| 18 |
|
| 19 | |
| 20 | * Reply Messages
|
| 21 | *
|
| 22 | * Error reply messages are of two types:
|
| 23 | * 82: Error (see below)
|
| 24 | * 88: Error (see below)
|
| 25 | * Both type 82 and type 88 have the same structure in the header.
|
| 26 | *
|
| 27 | * Request reply messages are of three known types:
|
| 28 | * 80: Reply from a Type 50 Request (see CEX2A-RELATED STRUCTS)
|
| 29 | * 84: Reply from a Type 4 Request (see PCICA-RELATED STRUCTS)
|
| 30 | * 86: Reply from a Type 6 Request (see PCICC/PCIXCC/CEX2C-RELATED STRUCTS)
|
| 31 | *
|
| 32 |
|
| 33 | struct error_hdr {
|
| 34 | unsigned char reserved1;
|
| 35 | unsigned char type;
|
| 36 | unsigned char reserved2[2];
|
| 37 | unsigned char reply_code;
|
| 38 | unsigned char reserved3[3];
|
| 39 | };
|
| 40 |
|
| 41 | #define TYPE82_RSP_CODE 0x82
|
| 42 | #define TYPE88_RSP_CODE 0x88
|
| 43 |
|
| 44 | #define REP82_ERROR_MACHINE_FAILURE 0x10
|
| 45 | #define REP82_ERROR_PREEMPT_FAILURE 0x12
|
| 46 | #define REP82_ERROR_CHECKPT_FAILURE 0x14
|
| 47 | #define REP82_ERROR_MESSAGE_TYPE 0x20
|
| 48 | #define REP82_ERROR_INVALID_COMM_CD 0x21
|
| 49 | #define REP82_ERROR_INVALID_MSG_LEN 0x23
|
| 50 | #define REP82_ERROR_RESERVD_FIELD 0x24
|
| 51 | #define REP82_ERROR_FORMAT_FIELD 0x29
|
| 52 | #define REP82_ERROR_INVALID_COMMAND 0x30
|
| 53 | #define REP82_ERROR_MALFORMED_MSG 0x40
|
| 54 | #define REP82_ERROR_INVALID_SPECIAL_CMD 0x41
|
| 55 | #define REP82_ERROR_RESERVED_FIELDO 0x50
|
| 56 | #define REP82_ERROR_WORD_ALIGNMENT 0x60
|
| 57 | #define REP82_ERROR_MESSAGE_LENGTH 0x80
|
| 58 | #define REP82_ERROR_OPERAND_INVALID 0x82
|
| 59 | #define REP82_ERROR_OPERAND_SIZE 0x84
|
| 60 | #define REP82_ERROR_EVEN_MOD_IN_OPND 0x85
|
| 61 | #define REP82_ERROR_RESERVED_FIELD 0x88
|
| 62 | #define REP82_ERROR_INVALID_DOMAIN_PENDING 0x8A
|
| 63 | #define REP82_ERROR_FILTERED_BY_HYPERVISOR 0x8B
|
| 64 | #define REP82_ERROR_TRANSPORT_FAIL 0x90
|
| 65 | #define REP82_ERROR_PACKET_TRUNCATED 0xA0
|
| 66 | #define REP82_ERROR_ZERO_BUFFER_LEN 0xB0
|
| 67 |
|
| 68 | #define REP88_ERROR_MODULE_FAILURE 0x10
|
| 69 | #define REP88_ERROR_MESSAGE_TYPE 0x20
|
| 70 | #define REP88_ERROR_MESSAGE_MALFORMD 0x22
|
| 71 | #define REP88_ERROR_MESSAGE_LENGTH 0x23
|
| 72 | #define REP88_ERROR_RESERVED_FIELD 0x24
|
| 73 | #define REP88_ERROR_KEY_TYPE 0x34
|
| 74 | #define REP88_ERROR_INVALID_KEY 0x82
|
| 75 | #define REP88_ERROR_OPERAND 0x84
|
| 76 | #define REP88_ERROR_OPERAND_EVEN_MOD 0x85
|
| 77 |
|
| 78 | static inline int convert_error(struct zcrypt_queue *zq,
|
| 79 | struct ap_message *reply)
|
| 80 | {
|
| 81 | int queue = AP_QID_QUEUE(zq->queue->qid);
|
| 82 | int card = AP_QID_CARD(zq->queue->qid);
|
| 83 | struct error_hdr *ehdr = reply->msg;
|
| 84 | struct {
|
| 85 | struct type86_hdr hdr;
|
| 86 | struct type86_fmt2_ext fmt2;
|
| 87 | } __packed * t86hdr = reply->msg;
|
| 88 |
|
| 89 | switch (ehdr->reply_code) {
|
| 90 | case REP82_ERROR_INVALID_MSG_LEN:
|
| 91 | case REP82_ERROR_RESERVD_FIELD:
|
| 92 | case REP82_ERROR_FORMAT_FIELD:
|
| 93 | case REP82_ERROR_MALFORMED_MSG:
|
| 94 | case REP82_ERROR_INVALID_SPECIAL_CMD:
|
| 95 | case REP82_ERROR_MESSAGE_LENGTH:
|
| 96 | case REP82_ERROR_OPERAND_INVALID:
|
| 97 | case REP82_ERROR_OPERAND_SIZE:
|
| 98 | case REP82_ERROR_EVEN_MOD_IN_OPND:
|
| 99 | case REP82_ERROR_INVALID_DOMAIN_PENDING:
|
| 100 | case REP82_ERROR_FILTERED_BY_HYPERVISOR:
|
| 101 | case REP82_ERROR_PACKET_TRUNCATED:
|
| 102 | case REP88_ERROR_MESSAGE_MALFORMD:
|
| 103 | case REP88_ERROR_KEY_TYPE:
|
| 104 |
|
| 105 | if (ehdr->reply_code == REP82_ERROR_FILTERED_BY_HYPERVISOR &&
|
| 106 | ehdr->type == TYPE86_RSP_CODE) {
|
| 107 | ZCRYPT_DBF_WARN("%s dev=%02x.%04x RY=0x%02x apfs=0x%x => rc=EINVAL\n",
|
| 108 | __func__, card, queue,
|
| 109 | ehdr->reply_code, t86hdr->fmt2.apfs);
|
| 110 | } else {
|
| 111 | ZCRYPT_DBF_WARN("%s dev=%02x.%04x RY=0x%02x => rc=EINVAL\n",
|
| 112 | __func__, card, queue, ehdr->reply_code);
|
| 113 | }
|
| 114 | return -EINVAL;
|
| 115 | case REP82_ERROR_MACHINE_FAILURE:
|
| 116 | case REP82_ERROR_MESSAGE_TYPE:
|
| 117 | case REP82_ERROR_TRANSPORT_FAIL:
|
| 118 | |
| 119 | * Msg to wrong type or card/infrastructure failure. Return
|
| 120 | * EAGAIN, the upper layer may do a retry on the request.
|
| 121 |
|
| 122 |
|
| 123 | if (ehdr->reply_code == REP82_ERROR_TRANSPORT_FAIL &&
|
| 124 | ehdr->type == TYPE86_RSP_CODE) {
|
| 125 | ZCRYPT_DBF_WARN(
|
| 126 | "%s dev=%02x.%04x RY=0x%02x apfs=0x%x => bus rescan, rc=EAGAIN\n",
|
| 127 | __func__, card, queue, ehdr->reply_code,
|
| 128 | t86hdr->fmt2.apfs);
|
| 129 | } else {
|
| 130 | ZCRYPT_DBF_WARN("%s dev=%02x.%04x RY=0x%02x => bus rescan, rc=EAGAIN\n",
|
| 131 | __func__, card, queue,
|
| 132 | ehdr->reply_code);
|
| 133 | }
|
| 134 | return -EAGAIN;
|
| 135 | default:
|
| 136 |
|
| 137 | ZCRYPT_DBF_WARN("%s dev=%02x.%04x RY=0x%02x => rc=EAGAIN\n",
|
| 138 | __func__, card, queue, ehdr->reply_code);
|
| 139 | return -EAGAIN;
|
| 140 | }
|
| 141 | }
|
| 142 |
|
| 143 | #endif
|