zcrypt_error.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * linux/drivers/s390/crypto/zcrypt_error.h
  3. *
  4. * zcrypt 2.1.0
  5. *
  6. * Copyright (C) 2001, 2006 IBM Corporation
  7. * Author(s): Robert Burroughs
  8. * Eric Rossman (edrossma@us.ibm.com)
  9. *
  10. * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
  11. * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2, or (at your option)
  16. * any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. */
  27. #ifndef _ZCRYPT_ERROR_H_
  28. #define _ZCRYPT_ERROR_H_
  29. #include "zcrypt_api.h"
  30. /**
  31. * Reply Messages
  32. *
  33. * Error reply messages are of two types:
  34. * 82: Error (see below)
  35. * 88: Error (see below)
  36. * Both type 82 and type 88 have the same structure in the header.
  37. *
  38. * Request reply messages are of three known types:
  39. * 80: Reply from a Type 50 Request (see CEX2A-RELATED STRUCTS)
  40. * 84: Reply from a Type 4 Request (see PCICA-RELATED STRUCTS)
  41. * 86: Reply from a Type 6 Request (see PCICC/PCIXCC/CEX2C-RELATED STRUCTS)
  42. *
  43. */
  44. struct error_hdr {
  45. unsigned char reserved1; /* 0x00 */
  46. unsigned char type; /* 0x82 or 0x88 */
  47. unsigned char reserved2[2]; /* 0x0000 */
  48. unsigned char reply_code; /* reply code */
  49. unsigned char reserved3[3]; /* 0x000000 */
  50. };
  51. #define TYPE82_RSP_CODE 0x82
  52. #define TYPE88_RSP_CODE 0x88
  53. #define REP82_ERROR_MACHINE_FAILURE 0x10
  54. #define REP82_ERROR_PREEMPT_FAILURE 0x12
  55. #define REP82_ERROR_CHECKPT_FAILURE 0x14
  56. #define REP82_ERROR_MESSAGE_TYPE 0x20
  57. #define REP82_ERROR_INVALID_COMM_CD 0x21 /* Type 84 */
  58. #define REP82_ERROR_INVALID_MSG_LEN 0x23
  59. #define REP82_ERROR_RESERVD_FIELD 0x24 /* was 0x50 */
  60. #define REP82_ERROR_FORMAT_FIELD 0x29
  61. #define REP82_ERROR_INVALID_COMMAND 0x30
  62. #define REP82_ERROR_MALFORMED_MSG 0x40
  63. #define REP82_ERROR_RESERVED_FIELDO 0x50 /* old value */
  64. #define REP82_ERROR_WORD_ALIGNMENT 0x60
  65. #define REP82_ERROR_MESSAGE_LENGTH 0x80
  66. #define REP82_ERROR_OPERAND_INVALID 0x82
  67. #define REP82_ERROR_OPERAND_SIZE 0x84
  68. #define REP82_ERROR_EVEN_MOD_IN_OPND 0x85
  69. #define REP82_ERROR_RESERVED_FIELD 0x88
  70. #define REP82_ERROR_TRANSPORT_FAIL 0x90
  71. #define REP82_ERROR_PACKET_TRUNCATED 0xA0
  72. #define REP82_ERROR_ZERO_BUFFER_LEN 0xB0
  73. #define REP88_ERROR_MODULE_FAILURE 0x10
  74. #define REP88_ERROR_MESSAGE_TYPE 0x20
  75. #define REP88_ERROR_MESSAGE_MALFORMD 0x22
  76. #define REP88_ERROR_MESSAGE_LENGTH 0x23
  77. #define REP88_ERROR_RESERVED_FIELD 0x24
  78. #define REP88_ERROR_KEY_TYPE 0x34
  79. #define REP88_ERROR_INVALID_KEY 0x82 /* CEX2A */
  80. #define REP88_ERROR_OPERAND 0x84 /* CEX2A */
  81. #define REP88_ERROR_OPERAND_EVEN_MOD 0x85 /* CEX2A */
  82. static inline int convert_error(struct zcrypt_device *zdev,
  83. struct ap_message *reply)
  84. {
  85. struct error_hdr *ehdr = reply->message;
  86. PRINTK("Hardware error : Type %02x Message Header: %08x%08x\n",
  87. ehdr->type, *(unsigned int *) reply->message,
  88. *(unsigned int *) (reply->message + 4));
  89. switch (ehdr->reply_code) {
  90. case REP82_ERROR_OPERAND_INVALID:
  91. case REP82_ERROR_OPERAND_SIZE:
  92. case REP82_ERROR_EVEN_MOD_IN_OPND:
  93. case REP88_ERROR_MESSAGE_MALFORMD:
  94. // REP88_ERROR_INVALID_KEY // '82' CEX2A
  95. // REP88_ERROR_OPERAND // '84' CEX2A
  96. // REP88_ERROR_OPERAND_EVEN_MOD // '85' CEX2A
  97. /* Invalid input data. */
  98. return -EINVAL;
  99. case REP82_ERROR_MESSAGE_TYPE:
  100. // REP88_ERROR_MESSAGE_TYPE // '20' CEX2A
  101. /**
  102. * To sent a message of the wrong type is a bug in the
  103. * device driver. Warn about it, disable the device
  104. * and then repeat the request.
  105. */
  106. WARN_ON(1);
  107. zdev->online = 0;
  108. return -EAGAIN;
  109. case REP82_ERROR_TRANSPORT_FAIL:
  110. case REP82_ERROR_MACHINE_FAILURE:
  111. // REP88_ERROR_MODULE_FAILURE // '10' CEX2A
  112. /* If a card fails disable it and repeat the request. */
  113. zdev->online = 0;
  114. return -EAGAIN;
  115. default:
  116. PRINTKW("unknown type %02x reply code = %d\n",
  117. ehdr->type, ehdr->reply_code);
  118. zdev->online = 0;
  119. return -EAGAIN; /* repeat the request on a different device. */
  120. }
  121. }
  122. #endif /* _ZCRYPT_ERROR_H_ */