xref: /linux/drivers/s390/crypto/zcrypt_error.h (revision 8d6be876bbd7c09190b025ccc478260f5a40c216)
1ac2b96f3SHarald Freudenberger /* SPDX-License-Identifier: GPL-2.0+ */
2963ed931SMartin Schwidefsky /*
3a53c8fabSHeiko Carstens  *  Copyright IBM Corp. 2001, 2006
4963ed931SMartin Schwidefsky  *  Author(s): Robert Burroughs
5963ed931SMartin Schwidefsky  *	       Eric Rossman (edrossma@us.ibm.com)
6963ed931SMartin Schwidefsky  *
7963ed931SMartin Schwidefsky  *  Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
8963ed931SMartin Schwidefsky  *  Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
9963ed931SMartin Schwidefsky  */
10963ed931SMartin Schwidefsky 
11963ed931SMartin Schwidefsky #ifndef _ZCRYPT_ERROR_H_
12963ed931SMartin Schwidefsky #define _ZCRYPT_ERROR_H_
13963ed931SMartin Schwidefsky 
14dabecb29SHolger Dengler #include <linux/atomic.h>
15dabecb29SHolger Dengler #include "zcrypt_debug.h"
16963ed931SMartin Schwidefsky #include "zcrypt_api.h"
17a17b92e0SHarald Freudenberger #include "zcrypt_msgtype6.h"
18963ed931SMartin Schwidefsky 
19963ed931SMartin Schwidefsky /**
20963ed931SMartin Schwidefsky  * Reply Messages
21963ed931SMartin Schwidefsky  *
22963ed931SMartin Schwidefsky  * Error reply messages are of two types:
23963ed931SMartin Schwidefsky  *    82:  Error (see below)
24963ed931SMartin Schwidefsky  *    88:  Error (see below)
25963ed931SMartin Schwidefsky  * Both type 82 and type 88 have the same structure in the header.
26963ed931SMartin Schwidefsky  *
27963ed931SMartin Schwidefsky  * Request reply messages are of three known types:
28963ed931SMartin Schwidefsky  *    80:  Reply from a Type 50 Request (see CEX2A-RELATED STRUCTS)
29963ed931SMartin Schwidefsky  *    84:  Reply from a Type 4 Request (see PCICA-RELATED STRUCTS)
30963ed931SMartin Schwidefsky  *    86:  Reply from a Type 6 Request (see PCICC/PCIXCC/CEX2C-RELATED STRUCTS)
31963ed931SMartin Schwidefsky  *
32963ed931SMartin Schwidefsky  */
33963ed931SMartin Schwidefsky struct error_hdr {
34963ed931SMartin Schwidefsky 	unsigned char reserved1;	/* 0x00			*/
35963ed931SMartin Schwidefsky 	unsigned char type;		/* 0x82 or 0x88		*/
36963ed931SMartin Schwidefsky 	unsigned char reserved2[2];	/* 0x0000		*/
37963ed931SMartin Schwidefsky 	unsigned char reply_code;	/* reply code		*/
38963ed931SMartin Schwidefsky 	unsigned char reserved3[3];	/* 0x000000		*/
39963ed931SMartin Schwidefsky };
40963ed931SMartin Schwidefsky 
41963ed931SMartin Schwidefsky #define TYPE82_RSP_CODE 0x82
42963ed931SMartin Schwidefsky #define TYPE88_RSP_CODE 0x88
43963ed931SMartin Schwidefsky 
44963ed931SMartin Schwidefsky #define REP82_ERROR_MACHINE_FAILURE	    0x10
45963ed931SMartin Schwidefsky #define REP82_ERROR_PREEMPT_FAILURE	    0x12
46963ed931SMartin Schwidefsky #define REP82_ERROR_CHECKPT_FAILURE	    0x14
47963ed931SMartin Schwidefsky #define REP82_ERROR_MESSAGE_TYPE	    0x20
48963ed931SMartin Schwidefsky #define REP82_ERROR_INVALID_COMM_CD	    0x21 /* Type 84	*/
49963ed931SMartin Schwidefsky #define REP82_ERROR_INVALID_MSG_LEN	    0x23
50963ed931SMartin Schwidefsky #define REP82_ERROR_RESERVD_FIELD	    0x24 /* was 0x50	*/
51963ed931SMartin Schwidefsky #define REP82_ERROR_FORMAT_FIELD	    0x29
52963ed931SMartin Schwidefsky #define REP82_ERROR_INVALID_COMMAND	    0x30
53963ed931SMartin Schwidefsky #define REP82_ERROR_MALFORMED_MSG	    0x40
54be534791SHarald Freudenberger #define REP82_ERROR_INVALID_SPECIAL_CMD	    0x41
55963ed931SMartin Schwidefsky #define REP82_ERROR_RESERVED_FIELDO	    0x50 /* old value	*/
56963ed931SMartin Schwidefsky #define REP82_ERROR_WORD_ALIGNMENT	    0x60
57963ed931SMartin Schwidefsky #define REP82_ERROR_MESSAGE_LENGTH	    0x80
58963ed931SMartin Schwidefsky #define REP82_ERROR_OPERAND_INVALID	    0x82
59963ed931SMartin Schwidefsky #define REP82_ERROR_OPERAND_SIZE	    0x84
60963ed931SMartin Schwidefsky #define REP82_ERROR_EVEN_MOD_IN_OPND	    0x85
61963ed931SMartin Schwidefsky #define REP82_ERROR_RESERVED_FIELD	    0x88
62bf9f3119SHarald Freudenberger #define REP82_ERROR_INVALID_DOMAIN_PENDING  0x8A
636733775aSHarald Freudenberger #define REP82_ERROR_FILTERED_BY_HYPERVISOR  0x8B
64963ed931SMartin Schwidefsky #define REP82_ERROR_TRANSPORT_FAIL	    0x90
65963ed931SMartin Schwidefsky #define REP82_ERROR_PACKET_TRUNCATED	    0xA0
66963ed931SMartin Schwidefsky #define REP82_ERROR_ZERO_BUFFER_LEN	    0xB0
67963ed931SMartin Schwidefsky 
68963ed931SMartin Schwidefsky #define REP88_ERROR_MODULE_FAILURE	    0x10
69963ed931SMartin Schwidefsky #define REP88_ERROR_MESSAGE_TYPE	    0x20
70963ed931SMartin Schwidefsky #define REP88_ERROR_MESSAGE_MALFORMD	    0x22
71963ed931SMartin Schwidefsky #define REP88_ERROR_MESSAGE_LENGTH	    0x23
72963ed931SMartin Schwidefsky #define REP88_ERROR_RESERVED_FIELD	    0x24
73963ed931SMartin Schwidefsky #define REP88_ERROR_KEY_TYPE		    0x34
74963ed931SMartin Schwidefsky #define REP88_ERROR_INVALID_KEY	    0x82 /* CEX2A	*/
75963ed931SMartin Schwidefsky #define REP88_ERROR_OPERAND		    0x84 /* CEX2A	*/
76963ed931SMartin Schwidefsky #define REP88_ERROR_OPERAND_EVEN_MOD	    0x85 /* CEX2A	*/
77963ed931SMartin Schwidefsky 
78e28d2af4SIngo Tuchscherer static inline int convert_error(struct zcrypt_queue *zq,
79963ed931SMartin Schwidefsky 				struct ap_message *reply)
80963ed931SMartin Schwidefsky {
8174ecbef7SHarald Freudenberger 	struct error_hdr *ehdr = reply->msg;
82cccd85bfSHarald Freudenberger 	int card = AP_QID_CARD(zq->queue->qid);
83cccd85bfSHarald Freudenberger 	int queue = AP_QID_QUEUE(zq->queue->qid);
84963ed931SMartin Schwidefsky 
85963ed931SMartin Schwidefsky 	switch (ehdr->reply_code) {
86e0332629SHarald Freudenberger 	case REP82_ERROR_INVALID_MSG_LEN:	 /* 0x23 */
87e0332629SHarald Freudenberger 	case REP82_ERROR_RESERVD_FIELD:		 /* 0x24 */
88e0332629SHarald Freudenberger 	case REP82_ERROR_FORMAT_FIELD:		 /* 0x29 */
89e0332629SHarald Freudenberger 	case REP82_ERROR_MALFORMED_MSG:		 /* 0x40 */
90e0332629SHarald Freudenberger 	case REP82_ERROR_INVALID_SPECIAL_CMD:	 /* 0x41 */
91e0332629SHarald Freudenberger 	case REP82_ERROR_MESSAGE_LENGTH:	 /* 0x80 */
92e0332629SHarald Freudenberger 	case REP82_ERROR_OPERAND_INVALID:	 /* 0x82 */
93e0332629SHarald Freudenberger 	case REP82_ERROR_OPERAND_SIZE:		 /* 0x84 */
94e0332629SHarald Freudenberger 	case REP82_ERROR_EVEN_MOD_IN_OPND:	 /* 0x85 */
95e0332629SHarald Freudenberger 	case REP82_ERROR_INVALID_DOMAIN_PENDING: /* 0x8A */
96e0332629SHarald Freudenberger 	case REP82_ERROR_FILTERED_BY_HYPERVISOR: /* 0x8B */
97e0332629SHarald Freudenberger 	case REP82_ERROR_PACKET_TRUNCATED:	 /* 0xA0 */
98e0332629SHarald Freudenberger 	case REP88_ERROR_MESSAGE_MALFORMD:	 /* 0x22 */
99e0332629SHarald Freudenberger 	case REP88_ERROR_KEY_TYPE:		 /* 0x34 */
100e0332629SHarald Freudenberger 		/* RY indicates malformed request */
101*8d6be876SHarald Freudenberger 		if (ehdr->reply_code == REP82_ERROR_FILTERED_BY_HYPERVISOR &&
102*8d6be876SHarald Freudenberger 		    ehdr->type == TYPE86_RSP_CODE) {
103*8d6be876SHarald Freudenberger 			struct {
104*8d6be876SHarald Freudenberger 				struct type86_hdr hdr;
105*8d6be876SHarald Freudenberger 				struct type86_fmt2_ext fmt2;
106*8d6be876SHarald Freudenberger 			} __packed * head = reply->msg;
107*8d6be876SHarald Freudenberger 			unsigned int apfs = *((u32 *)head->fmt2.apfs);
108*8d6be876SHarald Freudenberger 
109*8d6be876SHarald Freudenberger 			ZCRYPT_DBF_WARN("%s dev=%02x.%04x RY=0x%02x apfs=0x%x => rc=EINVAL\n",
110*8d6be876SHarald Freudenberger 					__func__, card, queue,
111*8d6be876SHarald Freudenberger 					ehdr->reply_code, apfs);
112*8d6be876SHarald Freudenberger 		} else {
1133f74eb5fSHarald Freudenberger 			ZCRYPT_DBF_WARN("%s dev=%02x.%04x RY=0x%02x => rc=EINVAL\n",
114*8d6be876SHarald Freudenberger 					__func__, card, queue,
115*8d6be876SHarald Freudenberger 					ehdr->reply_code);
116*8d6be876SHarald Freudenberger 		}
117963ed931SMartin Schwidefsky 		return -EINVAL;
118e0332629SHarald Freudenberger 	case REP82_ERROR_MACHINE_FAILURE:	 /* 0x10 */
119e0332629SHarald Freudenberger 	case REP82_ERROR_MESSAGE_TYPE:		 /* 0x20 */
120e0332629SHarald Freudenberger 	case REP82_ERROR_TRANSPORT_FAIL:	 /* 0x90 */
1211749a81dSFelix Beck 		/*
122e0332629SHarald Freudenberger 		 * Msg to wrong type or card/infrastructure failure.
123e0332629SHarald Freudenberger 		 * Trigger rescan of the ap bus, trigger retry request.
124963ed931SMartin Schwidefsky 		 */
125dabecb29SHolger Dengler 		atomic_set(&zcrypt_rescan_req, 1);
126a17b92e0SHarald Freudenberger 		/* For type 86 response show the apfs value (failure reason) */
127e0332629SHarald Freudenberger 		if (ehdr->reply_code == REP82_ERROR_TRANSPORT_FAIL &&
128e0332629SHarald Freudenberger 		    ehdr->type == TYPE86_RSP_CODE) {
129a17b92e0SHarald Freudenberger 			struct {
130a17b92e0SHarald Freudenberger 				struct type86_hdr hdr;
131a17b92e0SHarald Freudenberger 				struct type86_fmt2_ext fmt2;
13274ecbef7SHarald Freudenberger 			} __packed * head = reply->msg;
133a17b92e0SHarald Freudenberger 			unsigned int apfs = *((u32 *)head->fmt2.apfs);
134a17b92e0SHarald Freudenberger 
1353f74eb5fSHarald Freudenberger 			ZCRYPT_DBF_WARN(
1363f74eb5fSHarald Freudenberger 				"%s dev=%02x.%04x RY=0x%02x apfs=0x%x => bus rescan, rc=EAGAIN\n",
1373f74eb5fSHarald Freudenberger 				__func__, card, queue, ehdr->reply_code, apfs);
1382004b57cSHarald Freudenberger 		} else {
1393f74eb5fSHarald Freudenberger 			ZCRYPT_DBF_WARN("%s dev=%02x.%04x RY=0x%02x => bus rescan, rc=EAGAIN\n",
1403f74eb5fSHarald Freudenberger 					__func__, card, queue,
1413f74eb5fSHarald Freudenberger 					ehdr->reply_code);
1422004b57cSHarald Freudenberger 		}
143963ed931SMartin Schwidefsky 		return -EAGAIN;
144963ed931SMartin Schwidefsky 	default:
145e0332629SHarald Freudenberger 		/* Assume request is valid and a retry will be worth it */
1463f74eb5fSHarald Freudenberger 		ZCRYPT_DBF_WARN("%s dev=%02x.%04x RY=0x%02x => rc=EAGAIN\n",
1473f74eb5fSHarald Freudenberger 				__func__, card, queue, ehdr->reply_code);
148e0332629SHarald Freudenberger 		return -EAGAIN;
149963ed931SMartin Schwidefsky 	}
150963ed931SMartin Schwidefsky }
151963ed931SMartin Schwidefsky 
152963ed931SMartin Schwidefsky #endif /* _ZCRYPT_ERROR_H_ */
153