Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  *  Copyright IBM Corp. 2001, 2006
0004  *  Author(s): Robert Burroughs
0005  *         Eric Rossman (edrossma@us.ibm.com)
0006  *
0007  *  Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
0008  *  Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
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  * Reply Messages
0021  *
0022  * Error reply messages are of two types:
0023  *    82:  Error (see below)
0024  *    88:  Error (see below)
0025  * Both type 82 and type 88 have the same structure in the header.
0026  *
0027  * Request reply messages are of three known types:
0028  *    80:  Reply from a Type 50 Request (see CEX2A-RELATED STRUCTS)
0029  *    84:  Reply from a Type 4 Request (see PCICA-RELATED STRUCTS)
0030  *    86:  Reply from a Type 6 Request (see PCICC/PCIXCC/CEX2C-RELATED STRUCTS)
0031  *
0032  */
0033 struct error_hdr {
0034     unsigned char reserved1;    /* 0x00         */
0035     unsigned char type;     /* 0x82 or 0x88     */
0036     unsigned char reserved2[2]; /* 0x0000       */
0037     unsigned char reply_code;   /* reply code       */
0038     unsigned char reserved3[3]; /* 0x000000     */
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 /* Type 84 */
0049 #define REP82_ERROR_INVALID_MSG_LEN     0x23
0050 #define REP82_ERROR_RESERVD_FIELD       0x24 /* was 0x50    */
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 /* old value   */
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 /* CEX2A   */
0075 #define REP88_ERROR_OPERAND         0x84 /* CEX2A   */
0076 #define REP88_ERROR_OPERAND_EVEN_MOD        0x85 /* CEX2A   */
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:    /* 0x23 */
0087     case REP82_ERROR_RESERVD_FIELD:      /* 0x24 */
0088     case REP82_ERROR_FORMAT_FIELD:       /* 0x29 */
0089     case REP82_ERROR_MALFORMED_MSG:      /* 0x40 */
0090     case REP82_ERROR_INVALID_SPECIAL_CMD:    /* 0x41 */
0091     case REP82_ERROR_MESSAGE_LENGTH:     /* 0x80 */
0092     case REP82_ERROR_OPERAND_INVALID:    /* 0x82 */
0093     case REP82_ERROR_OPERAND_SIZE:       /* 0x84 */
0094     case REP82_ERROR_EVEN_MOD_IN_OPND:   /* 0x85 */
0095     case REP82_ERROR_INVALID_DOMAIN_PENDING: /* 0x8A */
0096     case REP82_ERROR_FILTERED_BY_HYPERVISOR: /* 0x8B */
0097     case REP82_ERROR_PACKET_TRUNCATED:   /* 0xA0 */
0098     case REP88_ERROR_MESSAGE_MALFORMD:   /* 0x22 */
0099     case REP88_ERROR_KEY_TYPE:       /* 0x34 */
0100         /* RY indicates malformed request */
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:    /* 0x10 */
0105     case REP82_ERROR_MESSAGE_TYPE:       /* 0x20 */
0106     case REP82_ERROR_TRANSPORT_FAIL:     /* 0x90 */
0107         /*
0108          * Msg to wrong type or card/infrastructure failure.
0109          * Trigger rescan of the ap bus, trigger retry request.
0110          */
0111         atomic_set(&zcrypt_rescan_req, 1);
0112         /* For type 86 response show the apfs value (failure reason) */
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         /* Assume request is valid and a retry will be worth it */
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 /* _ZCRYPT_ERROR_H_ */