1963ed931SMartin Schwidefsky /* 25432114bSRalph Wuerthner * zcrypt 2.1.0 3963ed931SMartin Schwidefsky * 4a53c8fabSHeiko Carstens * Copyright IBM Corp. 2001, 2006 5963ed931SMartin Schwidefsky * Author(s): Robert Burroughs 6963ed931SMartin Schwidefsky * Eric Rossman (edrossma@us.ibm.com) 7963ed931SMartin Schwidefsky * 8963ed931SMartin Schwidefsky * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com) 9963ed931SMartin Schwidefsky * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com> 10963ed931SMartin Schwidefsky * 11963ed931SMartin Schwidefsky * This program is free software; you can redistribute it and/or modify 12963ed931SMartin Schwidefsky * it under the terms of the GNU General Public License as published by 13963ed931SMartin Schwidefsky * the Free Software Foundation; either version 2, or (at your option) 14963ed931SMartin Schwidefsky * any later version. 15963ed931SMartin Schwidefsky * 16963ed931SMartin Schwidefsky * This program is distributed in the hope that it will be useful, 17963ed931SMartin Schwidefsky * but WITHOUT ANY WARRANTY; without even the implied warranty of 18963ed931SMartin Schwidefsky * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19963ed931SMartin Schwidefsky * GNU General Public License for more details. 20963ed931SMartin Schwidefsky * 21963ed931SMartin Schwidefsky * You should have received a copy of the GNU General Public License 22963ed931SMartin Schwidefsky * along with this program; if not, write to the Free Software 23963ed931SMartin Schwidefsky * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24963ed931SMartin Schwidefsky */ 25963ed931SMartin Schwidefsky 26963ed931SMartin Schwidefsky #ifndef _ZCRYPT_ERROR_H_ 27963ed931SMartin Schwidefsky #define _ZCRYPT_ERROR_H_ 28963ed931SMartin Schwidefsky 29dabecb29SHolger Dengler #include <linux/atomic.h> 30dabecb29SHolger Dengler #include "zcrypt_debug.h" 31963ed931SMartin Schwidefsky #include "zcrypt_api.h" 32963ed931SMartin Schwidefsky 33963ed931SMartin Schwidefsky /** 34963ed931SMartin Schwidefsky * Reply Messages 35963ed931SMartin Schwidefsky * 36963ed931SMartin Schwidefsky * Error reply messages are of two types: 37963ed931SMartin Schwidefsky * 82: Error (see below) 38963ed931SMartin Schwidefsky * 88: Error (see below) 39963ed931SMartin Schwidefsky * Both type 82 and type 88 have the same structure in the header. 40963ed931SMartin Schwidefsky * 41963ed931SMartin Schwidefsky * Request reply messages are of three known types: 42963ed931SMartin Schwidefsky * 80: Reply from a Type 50 Request (see CEX2A-RELATED STRUCTS) 43963ed931SMartin Schwidefsky * 84: Reply from a Type 4 Request (see PCICA-RELATED STRUCTS) 44963ed931SMartin Schwidefsky * 86: Reply from a Type 6 Request (see PCICC/PCIXCC/CEX2C-RELATED STRUCTS) 45963ed931SMartin Schwidefsky * 46963ed931SMartin Schwidefsky */ 47963ed931SMartin Schwidefsky struct error_hdr { 48963ed931SMartin Schwidefsky unsigned char reserved1; /* 0x00 */ 49963ed931SMartin Schwidefsky unsigned char type; /* 0x82 or 0x88 */ 50963ed931SMartin Schwidefsky unsigned char reserved2[2]; /* 0x0000 */ 51963ed931SMartin Schwidefsky unsigned char reply_code; /* reply code */ 52963ed931SMartin Schwidefsky unsigned char reserved3[3]; /* 0x000000 */ 53963ed931SMartin Schwidefsky }; 54963ed931SMartin Schwidefsky 55963ed931SMartin Schwidefsky #define TYPE82_RSP_CODE 0x82 56963ed931SMartin Schwidefsky #define TYPE88_RSP_CODE 0x88 57963ed931SMartin Schwidefsky 58963ed931SMartin Schwidefsky #define REP82_ERROR_MACHINE_FAILURE 0x10 59963ed931SMartin Schwidefsky #define REP82_ERROR_PREEMPT_FAILURE 0x12 60963ed931SMartin Schwidefsky #define REP82_ERROR_CHECKPT_FAILURE 0x14 61963ed931SMartin Schwidefsky #define REP82_ERROR_MESSAGE_TYPE 0x20 62963ed931SMartin Schwidefsky #define REP82_ERROR_INVALID_COMM_CD 0x21 /* Type 84 */ 63963ed931SMartin Schwidefsky #define REP82_ERROR_INVALID_MSG_LEN 0x23 64963ed931SMartin Schwidefsky #define REP82_ERROR_RESERVD_FIELD 0x24 /* was 0x50 */ 65963ed931SMartin Schwidefsky #define REP82_ERROR_FORMAT_FIELD 0x29 66963ed931SMartin Schwidefsky #define REP82_ERROR_INVALID_COMMAND 0x30 67963ed931SMartin Schwidefsky #define REP82_ERROR_MALFORMED_MSG 0x40 68963ed931SMartin Schwidefsky #define REP82_ERROR_RESERVED_FIELDO 0x50 /* old value */ 69963ed931SMartin Schwidefsky #define REP82_ERROR_WORD_ALIGNMENT 0x60 70963ed931SMartin Schwidefsky #define REP82_ERROR_MESSAGE_LENGTH 0x80 71963ed931SMartin Schwidefsky #define REP82_ERROR_OPERAND_INVALID 0x82 72963ed931SMartin Schwidefsky #define REP82_ERROR_OPERAND_SIZE 0x84 73963ed931SMartin Schwidefsky #define REP82_ERROR_EVEN_MOD_IN_OPND 0x85 74963ed931SMartin Schwidefsky #define REP82_ERROR_RESERVED_FIELD 0x88 75963ed931SMartin Schwidefsky #define REP82_ERROR_TRANSPORT_FAIL 0x90 76963ed931SMartin Schwidefsky #define REP82_ERROR_PACKET_TRUNCATED 0xA0 77963ed931SMartin Schwidefsky #define REP82_ERROR_ZERO_BUFFER_LEN 0xB0 78963ed931SMartin Schwidefsky 79963ed931SMartin Schwidefsky #define REP88_ERROR_MODULE_FAILURE 0x10 80963ed931SMartin Schwidefsky 81963ed931SMartin Schwidefsky #define REP88_ERROR_MESSAGE_TYPE 0x20 82963ed931SMartin Schwidefsky #define REP88_ERROR_MESSAGE_MALFORMD 0x22 83963ed931SMartin Schwidefsky #define REP88_ERROR_MESSAGE_LENGTH 0x23 84963ed931SMartin Schwidefsky #define REP88_ERROR_RESERVED_FIELD 0x24 85963ed931SMartin Schwidefsky #define REP88_ERROR_KEY_TYPE 0x34 86963ed931SMartin Schwidefsky #define REP88_ERROR_INVALID_KEY 0x82 /* CEX2A */ 87963ed931SMartin Schwidefsky #define REP88_ERROR_OPERAND 0x84 /* CEX2A */ 88963ed931SMartin Schwidefsky #define REP88_ERROR_OPERAND_EVEN_MOD 0x85 /* CEX2A */ 89963ed931SMartin Schwidefsky 90*e28d2af4SIngo Tuchscherer static inline int convert_error(struct zcrypt_queue *zq, 91963ed931SMartin Schwidefsky struct ap_message *reply) 92963ed931SMartin Schwidefsky { 93963ed931SMartin Schwidefsky struct error_hdr *ehdr = reply->message; 94963ed931SMartin Schwidefsky 95963ed931SMartin Schwidefsky switch (ehdr->reply_code) { 96963ed931SMartin Schwidefsky case REP82_ERROR_OPERAND_INVALID: 97963ed931SMartin Schwidefsky case REP82_ERROR_OPERAND_SIZE: 98963ed931SMartin Schwidefsky case REP82_ERROR_EVEN_MOD_IN_OPND: 99963ed931SMartin Schwidefsky case REP88_ERROR_MESSAGE_MALFORMD: 100963ed931SMartin Schwidefsky // REP88_ERROR_INVALID_KEY // '82' CEX2A 101963ed931SMartin Schwidefsky // REP88_ERROR_OPERAND // '84' CEX2A 102963ed931SMartin Schwidefsky // REP88_ERROR_OPERAND_EVEN_MOD // '85' CEX2A 103963ed931SMartin Schwidefsky /* Invalid input data. */ 104963ed931SMartin Schwidefsky return -EINVAL; 105963ed931SMartin Schwidefsky case REP82_ERROR_MESSAGE_TYPE: 106963ed931SMartin Schwidefsky // REP88_ERROR_MESSAGE_TYPE // '20' CEX2A 1071749a81dSFelix Beck /* 108963ed931SMartin Schwidefsky * To sent a message of the wrong type is a bug in the 10991f3e3eaSIngo Tuchscherer * device driver. Send error msg, disable the device 110963ed931SMartin Schwidefsky * and then repeat the request. 111963ed931SMartin Schwidefsky */ 112dabecb29SHolger Dengler atomic_set(&zcrypt_rescan_req, 1); 113*e28d2af4SIngo Tuchscherer zq->online = 0; 114*e28d2af4SIngo Tuchscherer pr_err("Cryptographic device %02x.%04x failed and was set offline\n", 115*e28d2af4SIngo Tuchscherer AP_QID_CARD(zq->queue->qid), 116*e28d2af4SIngo Tuchscherer AP_QID_QUEUE(zq->queue->qid)); 117*e28d2af4SIngo Tuchscherer ZCRYPT_DBF_DEV(DBF_ERR, zq, "dev%02x%04xo%drc%d", 118*e28d2af4SIngo Tuchscherer AP_QID_CARD(zq->queue->qid), 119*e28d2af4SIngo Tuchscherer AP_QID_QUEUE(zq->queue->qid), zq->online, 120d8f51227SIngo Tuchscherer ehdr->reply_code); 121963ed931SMartin Schwidefsky return -EAGAIN; 122963ed931SMartin Schwidefsky case REP82_ERROR_TRANSPORT_FAIL: 123963ed931SMartin Schwidefsky case REP82_ERROR_MACHINE_FAILURE: 124963ed931SMartin Schwidefsky // REP88_ERROR_MODULE_FAILURE // '10' CEX2A 125963ed931SMartin Schwidefsky /* If a card fails disable it and repeat the request. */ 126dabecb29SHolger Dengler atomic_set(&zcrypt_rescan_req, 1); 127*e28d2af4SIngo Tuchscherer zq->online = 0; 128*e28d2af4SIngo Tuchscherer pr_err("Cryptographic device %02x.%04x failed and was set offline\n", 129*e28d2af4SIngo Tuchscherer AP_QID_CARD(zq->queue->qid), 130*e28d2af4SIngo Tuchscherer AP_QID_QUEUE(zq->queue->qid)); 131*e28d2af4SIngo Tuchscherer ZCRYPT_DBF_DEV(DBF_ERR, zq, "dev%02x%04xo%drc%d", 132*e28d2af4SIngo Tuchscherer AP_QID_CARD(zq->queue->qid), 133*e28d2af4SIngo Tuchscherer AP_QID_QUEUE(zq->queue->qid), zq->online, 134d8f51227SIngo Tuchscherer ehdr->reply_code); 135963ed931SMartin Schwidefsky return -EAGAIN; 136963ed931SMartin Schwidefsky default: 137*e28d2af4SIngo Tuchscherer zq->online = 0; 138*e28d2af4SIngo Tuchscherer pr_err("Cryptographic device %02x.%04x failed and was set offline\n", 139*e28d2af4SIngo Tuchscherer AP_QID_CARD(zq->queue->qid), 140*e28d2af4SIngo Tuchscherer AP_QID_QUEUE(zq->queue->qid)); 141*e28d2af4SIngo Tuchscherer ZCRYPT_DBF_DEV(DBF_ERR, zq, "dev%02x%04xo%drc%d", 142*e28d2af4SIngo Tuchscherer AP_QID_CARD(zq->queue->qid), 143*e28d2af4SIngo Tuchscherer AP_QID_QUEUE(zq->queue->qid), zq->online, 144d8f51227SIngo Tuchscherer ehdr->reply_code); 145963ed931SMartin Schwidefsky return -EAGAIN; /* repeat the request on a different device. */ 146963ed931SMartin Schwidefsky } 147963ed931SMartin Schwidefsky } 148963ed931SMartin Schwidefsky 149963ed931SMartin Schwidefsky #endif /* _ZCRYPT_ERROR_H_ */ 150