ses.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /* $OpenBSD: ses.h,v 1.10 2006/05/11 00:45:59 krw Exp $ */
  2. /*
  3. * Copyright (c) 2005 Marco Peereboom
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
  19. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. * SUCH DAMAGE.
  26. *
  27. */
  28. #ifndef _SCSI_SES_H_
  29. #define _SCSI_SES_H_
  30. /* the scsi command */
  31. struct ses_scsi_diag {
  32. u_int8_t opcode; /* SEND_DIAGNOSTIC or RECEIVE_DIAGNOSTIC */
  33. u_int8_t flags;
  34. #define SES_DIAG_PCV (1<<0) /* page code valid */
  35. #define SES_DIAG_PF (1<<4) /* set this bit if page code is valid */
  36. u_int8_t pgcode;
  37. #define SES_PAGE_CONFIG 0x01 /* Configuration */
  38. #define SES_PAGE_STATUS 0x02 /* Enclosure Status */
  39. #define SES_PAGE_EDESC 0x07 /* Element Descriptor */
  40. u_int16_t length;
  41. u_int8_t control;
  42. } __packed;
  43. /* all the different sensor types */
  44. #define SES_T_UNSPEC 0x00
  45. #define SES_T_DEVICE 0x01
  46. #define SES_T_POWERSUPPLY 0x02
  47. #define SES_T_COOLING 0x03
  48. #define SES_T_TEMP 0x04
  49. #define SES_T_DOORLOCK 0x05
  50. #define SES_T_ALARM 0x06
  51. #define SES_T_ENC_SRV_CTRL 0x07
  52. #define SES_T_SCC_CTRL 0x08
  53. #define SES_T_NONVOL_CACHE 0x09
  54. #define SES_T_INV_OP_REASON 0x0a
  55. #define SES_T_UPS 0x0b
  56. #define SES_T_DISPLAY 0x0c
  57. #define SES_T_KEYPAD 0x0d
  58. #define SES_T_ENCLOSURE 0x0e
  59. #define SES_T_SCSI_PORT_TRANS 0x0f
  60. #define SES_T_LANGUAGE 0x10
  61. #define SES_T_COMM_PORT 0x11
  62. #define SES_T_VOLTAGE 0x12
  63. #define SES_T_CURRENT 0x13
  64. #define SES_T_SCSI_TARGET_PORT 0x14
  65. #define SES_T_SCSI_INIT_PORT 0x15
  66. #define SES_T_SIMP_SUBENC 0x16
  67. #define SES_T_ARRAY_DEVICE 0x17
  68. #define SES_NUM_TYPES 256
  69. /* diagnostic page header */
  70. struct ses_config_hdr {
  71. u_int8_t pgcode; /* SES_PAGE_CONFIG */
  72. u_int8_t n_subenc;
  73. u_int16_t length;
  74. u_int32_t gencode;
  75. } __packed;
  76. #define SES_CFG_HDRLEN sizeof(struct ses_config_hdr)
  77. /* enclosure descriptor header */
  78. struct ses_enc_hdr {
  79. u_int8_t enc_id;
  80. u_int8_t subenc_id;
  81. u_int8_t n_types;
  82. u_int8_t vendor_len;
  83. } __packed;
  84. #define SES_ENC_HDRLEN sizeof(struct ses_enc_hdr)
  85. /* enclosure descriptor strings */
  86. struct ses_enc_desc {
  87. u_int8_t logical_id[8]; /* this isnt a string */
  88. u_int8_t vendor_id[8];
  89. u_int8_t prod_id[16];
  90. u_int8_t prod_rev[4];
  91. u_int8_t vendor[0];
  92. } __packed;
  93. /* type descriptor header */
  94. struct ses_type_desc {
  95. u_int8_t type;
  96. u_int8_t n_elem;
  97. u_int8_t subenc_id;
  98. u_int8_t desc_len;
  99. } __packed;
  100. #define SES_TYPE_DESCLEN sizeof(struct ses_type_desc)
  101. /* status page header */
  102. struct ses_status_hdr {
  103. u_int8_t pgcode; /* SES_PAGE_STATUS */
  104. u_int8_t flags;
  105. #define SES_STAT_UNRECOV (1<<0) /* unrecoverable error */
  106. #define SES_STAT_CRIT (1<<1) /* critical error */
  107. #define SES_STAT_NONCRIT (1<<2) /* noncritical error */
  108. #define SES_STAT_INFO (1<<3) /* info available */
  109. #define SES_STAT_INVOP (1<<4) /* invalid operation */
  110. u_int16_t length;
  111. u_int32_t gencode;
  112. } __packed;
  113. #define SES_STAT_HDRLEN sizeof(struct ses_status_hdr)
  114. struct ses_status {
  115. u_int8_t com;
  116. #define SES_STAT_CODE_MASK 0x0f
  117. #define SES_STAT_CODE(x) ((x) & SES_STAT_CODE_MASK)
  118. #define SES_STAT_CODE_UNSUP 0x00 /* unsupported */
  119. #define SES_STAT_CODE_OK 0x01 /* installed and ok */
  120. #define SES_STAT_CODE_CRIT 0x02 /* critical */
  121. #define SES_STAT_CODE_NONCRIT 0x03 /* warning */
  122. #define SES_STAT_CODE_UNREC 0x04 /* unrecoverable */
  123. #define SES_STAT_CODE_NOTINST 0x05 /* not installed */
  124. #define SES_STAT_CODE_UNKNOWN 0x06 /* unknown */
  125. #define SES_STAT_CODE_NOTAVAIL 0x07 /* not available */
  126. #define SES_STAT_SWAP (1<<4) /* element has been swapped */
  127. #define SES_STAT_DISABLED (1<<5) /* disabled */
  128. #define SES_STAT_PRDFAIL (1<<6) /* predicted failure */
  129. #define SES_STAT_SELECT (1<<7) /* set to modify element */
  130. u_int8_t f1; /* use of these flags depends on the SES_T */
  131. u_int8_t f2;
  132. u_int8_t f3;
  133. } __packed;
  134. #define SES_STAT_ELEMLEN sizeof(struct ses_status)
  135. /* device status */
  136. /* f1 is the device address */
  137. /* f2 */
  138. #define SES_S_DEV_REPORT (1<<0) /* enc report in progress */
  139. #define SES_S_DEV_IDENT (1<<1) /* currently identifying */
  140. #define SES_S_DEV_REMOVE (1<<2) /* ready to remove */
  141. #define SES_S_DEV_INSERT (1<<3) /* ready to insert */
  142. #define SES_S_DEV_ENCBYPB (1<<4) /* port B bypassed by enc */
  143. #define SES_S_DEV_ENCBYPA (1<<5) /* port A bypassed by enc */
  144. #define SES_S_DEV_DONOTREM (1<<6) /* do not remove */
  145. #define SES_S_DEV_APPCLBYPA (1<<7) /* port A bypassed by app */
  146. /* f3 */
  147. #define SES_S_DEV_DEVBYPB (1<<0) /* port B bypassed by dev */
  148. #define SES_S_DEV_DEVBYPA (1<<1) /* port A bypassed by dev */
  149. #define SES_S_DEV_BYPB (1<<2)
  150. #define SES_S_DEV_BYPA (1<<3)
  151. #define SES_S_DEV_OFF (1<<4) /* device is off */
  152. #define SES_S_DEV_FAULTRQST (1<<5) /* fault indicator rqsted */
  153. #define SES_S_DEV_FAULTSENSE (1<<6) /* fault sensed */
  154. #define SES_S_DEV_APPCLBYPB (1<<7) /* port B bypassed by app */
  155. /* device configuration */
  156. /* f1 is reserved */
  157. /* f2 */
  158. #define SES_C_DEV_IDENT (1<<1) /* ident */
  159. #define SES_C_DEV_REMOVE (1<<2) /* remove */
  160. #define SES_C_DEV_INSERT (1<<3) /* insert */
  161. #define SES_C_DEV_DONOTREM (1<<6) /* do not remove */
  162. #define SES_C_DEV_ACTIVE (1<<7) /* active indicator */
  163. #define SES_C_DEV_F2MASK (SES_C_DEV_IDENT | SES_C_DEV_REMOVE | \
  164. SES_C_DEV_INSERT | SES_C_DEV_DONOTREM | SES_C_DEV_ACTIVE )
  165. /* f3 */
  166. #define SES_C_DEV_BYPB (1<<2) /* port B bypass */
  167. #define SES_C_DEV_BYPA (1<<3) /* port A bypass */
  168. #define SES_C_DEV_OFF (1<<4) /* off */
  169. #define SES_C_DEV_FAULT (1<<5) /* fault indicator */
  170. #define SES_C_DEV_F3MASK (SES_C_DEV_BYPB | SES_C_DEV_BYPA | \
  171. SES_C_DEV_OFF | SES_C_DEV_FAULT)
  172. /* power supply element */
  173. #define SES_S_PSU_IDENT(d) ((d)->f1 & (1<<6)) /* identify */
  174. #define SES_S_PSU_DCOC(d) ((d)->f2 & (1<<1)) /* DC over current */
  175. #define SES_S_PSU_DCUV(d) ((d)->f2 & (1<<2)) /* DC under voltage */
  176. #define SES_S_PSU_DCOV(d) ((d)->f2 & (1<<3)) /* DC over voltage */
  177. #define SES_S_PSU_DCFAIL(d) ((d)->f3 & (1<<0)) /* DC fail */
  178. #define SES_S_PSU_ACFAIL(d) ((d)->f3 & (1<<1)) /* AC fail */
  179. #define SES_S_PSU_TEMPWARN(d) ((d)->f3 & (1<<2)) /* Temp warn */
  180. #define SES_S_PSU_OVERTEMP(d) ((d)->f3 & (1<<3)) /* over temp fail */
  181. #define SES_S_PSU_OFF(d) ((d)->f3 & (1<<4)) /* is the unit off */
  182. #define SES_S_PSU_RQSTON(d) ((d)->f3 & (1<<5)) /* manually on */
  183. #define SES_S_PSU_FAIL(d) ((d)->f3 & (1<<6)) /* fail is set on */
  184. /* cooling element */
  185. #define SES_S_COOL_IDENT(d) ((d)->f1 & (1<<6)) /* identify */
  186. #define SES_S_COOL_SPEED_MASK 0x03
  187. #define SES_S_COOL_SPEED(d) ((d)->f2 + \
  188. ((u_int16_t)((d)->f2 & SES_S_COOL_SPEED_MASK) << 8))
  189. #define SES_S_COOL_FACTOR 10
  190. #define SES_S_COOL_CODE(d) ((d)->f3 & 0x7) /* actual speed code */
  191. #define SES_S_COOL_C_STOPPED 0x0 /* stopped */
  192. #define SES_S_COOL_C_LOW1 0x1 /* lowest speed */
  193. #define SES_S_COOL_C_LOW2 0x2 /* second lowest speed */
  194. #define SES_S_COOL_C_LOW3 0x3 /* third lowest speed */
  195. #define SES_S_COOL_C_INTER 0x4 /* intermediate speed */
  196. #define SES_S_COOL_C_HI3 0x5 /* third highest speed */
  197. #define SES_S_COOL_C_HI2 0x6 /* second highest speed */
  198. #define SES_S_COOL_C_HI1 0x7 /* highest speed */
  199. #define SES_S_COOL_OFF ((d)->f3 & (1<<4)) /* not cooling */
  200. #define SES_S_COOL_RQSTON ((d)->f3 & (1<<5)) /* manually on */
  201. #define SES_S_COOL_FAIL ((d)->f3 & (1<<6)) /* fail indic is on */
  202. /* temperature sensor */
  203. #define SES_S_TEMP_IDENT(d) ((d)->f1 & (1<<7)) /* identify */
  204. #define SES_S_TEMP(d) ((d)->f2)
  205. #define SES_S_TEMP_OFFSET (-20)
  206. #define SES_S_TEMP_UTWARN ((d)->f3 & (1<<0)) /* under temp warning */
  207. #define SES_S_TEMP_UTFAIL ((d)->f3 & (1<<1)) /* under temp failure */
  208. #define SES_S_TEMP_OTWARN ((d)->f3 & (1<<2)) /* over temp warning */
  209. #define SES_S_TEMP_OTFAIL ((d)->f3 & (1<<3)) /* over temp failure */
  210. /*
  211. * the length of the status page is the header and a status element for
  212. * each type plus the number of elements for each type
  213. */
  214. #define SES_STAT_LEN(t, e) \
  215. (SES_STAT_HDRLEN + SES_STAT_ELEMLEN * ((t)+(e)))
  216. #endif /* _SCSI_SES_H_ */