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