blob: de1b6c1d172c8c0866dc0fd8fb709d032bdef820 [file] [log] [blame]
Martin Schwidefsky963ed932006-09-20 15:58:29 +02001/*
Ralph Wuerthner54321142006-09-20 15:58:36 +02002 * zcrypt 2.1.0
Martin Schwidefsky963ed932006-09-20 15:58:29 +02003 *
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02004 * Copyright IBM Corp. 2001, 2006
Martin Schwidefsky963ed932006-09-20 15:58:29 +02005 * Author(s): Robert Burroughs
6 * Eric Rossman (edrossma@us.ibm.com)
7 *
8 * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
9 * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#ifndef _ZCRYPT_ERROR_H_
27#define _ZCRYPT_ERROR_H_
28
Holger Denglerdabecb22012-09-10 21:34:26 +020029#include <linux/atomic.h>
30#include "zcrypt_debug.h"
Martin Schwidefsky963ed932006-09-20 15:58:29 +020031#include "zcrypt_api.h"
32
33/**
34 * Reply Messages
35 *
36 * Error reply messages are of two types:
37 * 82: Error (see below)
38 * 88: Error (see below)
39 * Both type 82 and type 88 have the same structure in the header.
40 *
41 * Request reply messages are of three known types:
42 * 80: Reply from a Type 50 Request (see CEX2A-RELATED STRUCTS)
43 * 84: Reply from a Type 4 Request (see PCICA-RELATED STRUCTS)
44 * 86: Reply from a Type 6 Request (see PCICC/PCIXCC/CEX2C-RELATED STRUCTS)
45 *
46 */
47struct error_hdr {
48 unsigned char reserved1; /* 0x00 */
49 unsigned char type; /* 0x82 or 0x88 */
50 unsigned char reserved2[2]; /* 0x0000 */
51 unsigned char reply_code; /* reply code */
52 unsigned char reserved3[3]; /* 0x000000 */
53};
54
55#define TYPE82_RSP_CODE 0x82
56#define TYPE88_RSP_CODE 0x88
57
58#define REP82_ERROR_MACHINE_FAILURE 0x10
59#define REP82_ERROR_PREEMPT_FAILURE 0x12
60#define REP82_ERROR_CHECKPT_FAILURE 0x14
61#define REP82_ERROR_MESSAGE_TYPE 0x20
62#define REP82_ERROR_INVALID_COMM_CD 0x21 /* Type 84 */
63#define REP82_ERROR_INVALID_MSG_LEN 0x23
64#define REP82_ERROR_RESERVD_FIELD 0x24 /* was 0x50 */
65#define REP82_ERROR_FORMAT_FIELD 0x29
66#define REP82_ERROR_INVALID_COMMAND 0x30
67#define REP82_ERROR_MALFORMED_MSG 0x40
68#define REP82_ERROR_RESERVED_FIELDO 0x50 /* old value */
69#define REP82_ERROR_WORD_ALIGNMENT 0x60
70#define REP82_ERROR_MESSAGE_LENGTH 0x80
71#define REP82_ERROR_OPERAND_INVALID 0x82
72#define REP82_ERROR_OPERAND_SIZE 0x84
73#define REP82_ERROR_EVEN_MOD_IN_OPND 0x85
74#define REP82_ERROR_RESERVED_FIELD 0x88
75#define REP82_ERROR_TRANSPORT_FAIL 0x90
76#define REP82_ERROR_PACKET_TRUNCATED 0xA0
77#define REP82_ERROR_ZERO_BUFFER_LEN 0xB0
78
79#define REP88_ERROR_MODULE_FAILURE 0x10
80
81#define REP88_ERROR_MESSAGE_TYPE 0x20
82#define REP88_ERROR_MESSAGE_MALFORMD 0x22
83#define REP88_ERROR_MESSAGE_LENGTH 0x23
84#define REP88_ERROR_RESERVED_FIELD 0x24
85#define REP88_ERROR_KEY_TYPE 0x34
86#define REP88_ERROR_INVALID_KEY 0x82 /* CEX2A */
87#define REP88_ERROR_OPERAND 0x84 /* CEX2A */
88#define REP88_ERROR_OPERAND_EVEN_MOD 0x85 /* CEX2A */
89
90static inline int convert_error(struct zcrypt_device *zdev,
91 struct ap_message *reply)
92{
93 struct error_hdr *ehdr = reply->message;
94
Martin Schwidefsky963ed932006-09-20 15:58:29 +020095 switch (ehdr->reply_code) {
96 case REP82_ERROR_OPERAND_INVALID:
97 case REP82_ERROR_OPERAND_SIZE:
98 case REP82_ERROR_EVEN_MOD_IN_OPND:
99 case REP88_ERROR_MESSAGE_MALFORMD:
100 // REP88_ERROR_INVALID_KEY // '82' CEX2A
101 // REP88_ERROR_OPERAND // '84' CEX2A
102 // REP88_ERROR_OPERAND_EVEN_MOD // '85' CEX2A
103 /* Invalid input data. */
104 return -EINVAL;
105 case REP82_ERROR_MESSAGE_TYPE:
106 // REP88_ERROR_MESSAGE_TYPE // '20' CEX2A
Felix Beck1749a812008-04-17 07:46:28 +0200107 /*
Martin Schwidefsky963ed932006-09-20 15:58:29 +0200108 * To sent a message of the wrong type is a bug in the
Ingo Tuchscherer91f3e3e2013-11-20 10:47:13 +0100109 * device driver. Send error msg, disable the device
Martin Schwidefsky963ed932006-09-20 15:58:29 +0200110 * and then repeat the request.
111 */
Holger Denglerdabecb22012-09-10 21:34:26 +0200112 atomic_set(&zcrypt_rescan_req, 1);
Martin Schwidefsky963ed932006-09-20 15:58:29 +0200113 zdev->online = 0;
Ingo Tuchscherer91f3e3e2013-11-20 10:47:13 +0100114 pr_err("Cryptographic device %x failed and was set offline\n",
Ingo Tuchschererd8f51222016-01-22 16:18:29 +0100115 AP_QID_DEVICE(zdev->ap_dev->qid));
Holger Denglerdabecb22012-09-10 21:34:26 +0200116 ZCRYPT_DBF_DEV(DBF_ERR, zdev, "dev%04xo%drc%d",
Ingo Tuchschererd8f51222016-01-22 16:18:29 +0100117 AP_QID_DEVICE(zdev->ap_dev->qid), zdev->online,
118 ehdr->reply_code);
Martin Schwidefsky963ed932006-09-20 15:58:29 +0200119 return -EAGAIN;
120 case REP82_ERROR_TRANSPORT_FAIL:
121 case REP82_ERROR_MACHINE_FAILURE:
122 // REP88_ERROR_MODULE_FAILURE // '10' CEX2A
123 /* If a card fails disable it and repeat the request. */
Holger Denglerdabecb22012-09-10 21:34:26 +0200124 atomic_set(&zcrypt_rescan_req, 1);
Martin Schwidefsky963ed932006-09-20 15:58:29 +0200125 zdev->online = 0;
Ingo Tuchscherer91f3e3e2013-11-20 10:47:13 +0100126 pr_err("Cryptographic device %x failed and was set offline\n",
Ingo Tuchschererd8f51222016-01-22 16:18:29 +0100127 AP_QID_DEVICE(zdev->ap_dev->qid));
Holger Denglerdabecb22012-09-10 21:34:26 +0200128 ZCRYPT_DBF_DEV(DBF_ERR, zdev, "dev%04xo%drc%d",
Ingo Tuchschererd8f51222016-01-22 16:18:29 +0100129 AP_QID_DEVICE(zdev->ap_dev->qid), zdev->online,
130 ehdr->reply_code);
Martin Schwidefsky963ed932006-09-20 15:58:29 +0200131 return -EAGAIN;
132 default:
Martin Schwidefsky963ed932006-09-20 15:58:29 +0200133 zdev->online = 0;
Ingo Tuchscherer91f3e3e2013-11-20 10:47:13 +0100134 pr_err("Cryptographic device %x failed and was set offline\n",
Ingo Tuchschererd8f51222016-01-22 16:18:29 +0100135 AP_QID_DEVICE(zdev->ap_dev->qid));
Holger Denglerdabecb22012-09-10 21:34:26 +0200136 ZCRYPT_DBF_DEV(DBF_ERR, zdev, "dev%04xo%drc%d",
Ingo Tuchschererd8f51222016-01-22 16:18:29 +0100137 AP_QID_DEVICE(zdev->ap_dev->qid), zdev->online,
138 ehdr->reply_code);
Martin Schwidefsky963ed932006-09-20 15:58:29 +0200139 return -EAGAIN; /* repeat the request on a different device. */
140 }
141}
142
143#endif /* _ZCRYPT_ERROR_H_ */