aiclib.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Largely written by Julian Elischer (julian@tfs.com)
  3. * for TRW Financial Systems.
  4. *
  5. * TRW Financial Systems, in accordance with their agreement with Carnegie
  6. * Mellon University, makes this software available to CMU to distribute
  7. * or use in any manner that they see fit as long as this message is kept with
  8. * the software. For this reason TFS also grants any other persons or
  9. * organisations permission to use or modify this software.
  10. *
  11. * TFS supplies this software to be publicly redistributed
  12. * on the understanding that TFS is not responsible for the correct
  13. * functioning of this software in any circumstances.
  14. *
  15. * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
  16. *
  17. * $FreeBSD: src/sys/cam/scsi/scsi_all.h,v 1.21 2002/10/08 17:12:44 ken Exp $
  18. *
  19. * Copyright (c) 2003 Adaptec Inc.
  20. * All rights reserved.
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. * 1. Redistributions of source code must retain the above copyright
  26. * notice, this list of conditions, and the following disclaimer,
  27. * without modification.
  28. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  29. * substantially similar to the "NO WARRANTY" disclaimer below
  30. * ("Disclaimer") and any redistribution must be conditioned upon
  31. * including a substantially similar Disclaimer requirement for further
  32. * binary redistribution.
  33. * 3. Neither the names of the above-listed copyright holders nor the names
  34. * of any contributors may be used to endorse or promote products derived
  35. * from this software without specific prior written permission.
  36. *
  37. * Alternatively, this software may be distributed under the terms of the
  38. * GNU General Public License ("GPL") version 2 as published by the Free
  39. * Software Foundation.
  40. *
  41. * NO WARRANTY
  42. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  43. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  44. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  45. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  46. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  47. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  48. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  49. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  50. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  51. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  52. * POSSIBILITY OF SUCH DAMAGES.
  53. *
  54. * $Id$
  55. */
  56. #ifndef _AICLIB_H
  57. #define _AICLIB_H
  58. struct scsi_sense
  59. {
  60. uint8_t opcode;
  61. uint8_t byte2;
  62. uint8_t unused[2];
  63. uint8_t length;
  64. uint8_t control;
  65. };
  66. #define SCSI_REV_0 0
  67. #define SCSI_REV_CCS 1
  68. #define SCSI_REV_2 2
  69. #define SCSI_REV_SPC 3
  70. #define SCSI_REV_SPC2 4
  71. struct scsi_sense_data
  72. {
  73. uint8_t error_code;
  74. #define SSD_ERRCODE 0x7F
  75. #define SSD_CURRENT_ERROR 0x70
  76. #define SSD_DEFERRED_ERROR 0x71
  77. #define SSD_ERRCODE_VALID 0x80
  78. uint8_t segment;
  79. uint8_t flags;
  80. #define SSD_KEY 0x0F
  81. #define SSD_KEY_NO_SENSE 0x00
  82. #define SSD_KEY_RECOVERED_ERROR 0x01
  83. #define SSD_KEY_NOT_READY 0x02
  84. #define SSD_KEY_MEDIUM_ERROR 0x03
  85. #define SSD_KEY_HARDWARE_ERROR 0x04
  86. #define SSD_KEY_ILLEGAL_REQUEST 0x05
  87. #define SSD_KEY_UNIT_ATTENTION 0x06
  88. #define SSD_KEY_DATA_PROTECT 0x07
  89. #define SSD_KEY_BLANK_CHECK 0x08
  90. #define SSD_KEY_Vendor_Specific 0x09
  91. #define SSD_KEY_COPY_ABORTED 0x0a
  92. #define SSD_KEY_ABORTED_COMMAND 0x0b
  93. #define SSD_KEY_EQUAL 0x0c
  94. #define SSD_KEY_VOLUME_OVERFLOW 0x0d
  95. #define SSD_KEY_MISCOMPARE 0x0e
  96. #define SSD_KEY_RESERVED 0x0f
  97. #define SSD_ILI 0x20
  98. #define SSD_EOM 0x40
  99. #define SSD_FILEMARK 0x80
  100. uint8_t info[4];
  101. uint8_t extra_len;
  102. uint8_t cmd_spec_info[4];
  103. uint8_t add_sense_code;
  104. uint8_t add_sense_code_qual;
  105. uint8_t fru;
  106. uint8_t sense_key_spec[3];
  107. #define SSD_SCS_VALID 0x80
  108. #define SSD_FIELDPTR_CMD 0x40
  109. #define SSD_BITPTR_VALID 0x08
  110. #define SSD_BITPTR_VALUE 0x07
  111. #define SSD_MIN_SIZE 18
  112. uint8_t extra_bytes[14];
  113. #define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
  114. };
  115. /*
  116. * Status Byte
  117. */
  118. #define SCSI_STATUS_OK 0x00
  119. #define SCSI_STATUS_CHECK_COND 0x02
  120. #define SCSI_STATUS_COND_MET 0x04
  121. #define SCSI_STATUS_BUSY 0x08
  122. #define SCSI_STATUS_INTERMED 0x10
  123. #define SCSI_STATUS_INTERMED_COND_MET 0x14
  124. #define SCSI_STATUS_RESERV_CONFLICT 0x18
  125. #define SCSI_STATUS_CMD_TERMINATED 0x22 /* Obsolete in SAM-2 */
  126. #define SCSI_STATUS_QUEUE_FULL 0x28
  127. #define SCSI_STATUS_ACA_ACTIVE 0x30
  128. #define SCSI_STATUS_TASK_ABORTED 0x40
  129. /************************* Large Disk Handling ********************************/
  130. static inline int
  131. aic_sector_div(sector_t capacity, int heads, int sectors)
  132. {
  133. /* ugly, ugly sector_div calling convention.. */
  134. sector_div(capacity, (heads * sectors));
  135. return (int)capacity;
  136. }
  137. static inline uint32_t
  138. scsi_4btoul(uint8_t *bytes)
  139. {
  140. uint32_t rv;
  141. rv = (bytes[0] << 24) |
  142. (bytes[1] << 16) |
  143. (bytes[2] << 8) |
  144. bytes[3];
  145. return (rv);
  146. }
  147. /* Macros for generating the elements of the PCI ID tables. */
  148. #define GETID(v, s) (unsigned)(((v) >> (s)) & 0xFFFF ?: PCI_ANY_ID)
  149. #define ID_C(x, c) \
  150. { \
  151. GETID(x,32), GETID(x,48), GETID(x,0), GETID(x,16), \
  152. (c) << 8, 0xFFFF00, 0 \
  153. }
  154. #define ID2C(x) \
  155. ID_C(x, PCI_CLASS_STORAGE_SCSI), \
  156. ID_C(x, PCI_CLASS_STORAGE_RAID)
  157. #define IDIROC(x) ((x) | ~ID_ALL_IROC_MASK)
  158. /* Generate IDs for all 16 possibilites.
  159. * The argument has already masked out
  160. * the 4 least significant bits of the device id.
  161. * (e.g., mask: ID_9005_GENERIC_MASK).
  162. */
  163. #define ID16(x) \
  164. ID(x), \
  165. ID((x) | 0x0001000000000000ull), \
  166. ID((x) | 0x0002000000000000ull), \
  167. ID((x) | 0x0003000000000000ull), \
  168. ID((x) | 0x0004000000000000ull), \
  169. ID((x) | 0x0005000000000000ull), \
  170. ID((x) | 0x0006000000000000ull), \
  171. ID((x) | 0x0007000000000000ull), \
  172. ID((x) | 0x0008000000000000ull), \
  173. ID((x) | 0x0009000000000000ull), \
  174. ID((x) | 0x000A000000000000ull), \
  175. ID((x) | 0x000B000000000000ull), \
  176. ID((x) | 0x000C000000000000ull), \
  177. ID((x) | 0x000D000000000000ull), \
  178. ID((x) | 0x000E000000000000ull), \
  179. ID((x) | 0x000F000000000000ull)
  180. #endif /*_AICLIB_H */