ipmi_sdr.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  1. /*
  2. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * Redistribution of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  11. * Redistribution 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. * Neither the name of Sun Microsystems, Inc. or the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * This software is provided "AS IS," without a warranty of any kind.
  20. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
  21. * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
  22. * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
  23. * SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
  24. * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  25. * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
  26. * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
  27. * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
  28. * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
  29. * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
  30. * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  31. */
  32. #ifndef IPMI_SDR_H
  33. #define IPMI_SDR_H
  34. #if HAVE_CONFIG_H
  35. # include <config.h>
  36. #endif
  37. #include <inttypes.h>
  38. #include <math.h>
  39. #include <ipmitool/bswap.h>
  40. #include <ipmitool/ipmi.h>
  41. #include <ipmitool/ipmi_entity.h>
  42. int ipmi_sdr_main(struct ipmi_intf *, int, char **);
  43. #define tos32(val, bits) ((val & ((1<<((bits)-1)))) ? (-((val) & (1<<((bits)-1))) | (val)) : (val))
  44. #if WORDS_BIGENDIAN
  45. # define __TO_TOL(mtol) (uint16_t)(mtol & 0x3f)
  46. # define __TO_M(mtol) (int16_t)(tos32((((mtol & 0xff00) >> 8) | ((mtol & 0xc0) << 2)), 10))
  47. # define __TO_B(bacc) (int32_t)(tos32((((bacc & 0xff000000) >> 24) | ((bacc & 0xc00000) >> 14)), 10))
  48. # define __TO_ACC(bacc) (uint32_t)(((bacc & 0x3f0000) >> 16) | ((bacc & 0xf000) >> 6))
  49. # define __TO_ACC_EXP(bacc) (uint32_t)((bacc & 0xc00) >> 10)
  50. # define __TO_R_EXP(bacc) (int32_t)(tos32(((bacc & 0xf0) >> 4), 4))
  51. # define __TO_B_EXP(bacc) (int32_t)(tos32((bacc & 0xf), 4))
  52. #else
  53. # define __TO_TOL(mtol) (uint16_t)(BSWAP_16(mtol) & 0x3f)
  54. # define __TO_M(mtol) (int16_t)(tos32((((BSWAP_16(mtol) & 0xff00) >> 8) | ((BSWAP_16(mtol) & 0xc0) << 2)), 10))
  55. # define __TO_B(bacc) (int32_t)(tos32((((BSWAP_32(bacc) & 0xff000000) >> 24) | \
  56. ((BSWAP_32(bacc) & 0xc00000) >> 14)), 10))
  57. # define __TO_ACC(bacc) (uint32_t)(((BSWAP_32(bacc) & 0x3f0000) >> 16) | ((BSWAP_32(bacc) & 0xf000) >> 6))
  58. # define __TO_ACC_EXP(bacc) (uint32_t)((BSWAP_32(bacc) & 0xc00) >> 10)
  59. # define __TO_R_EXP(bacc) (int32_t)(tos32(((BSWAP_32(bacc) & 0xf0) >> 4), 4))
  60. # define __TO_B_EXP(bacc) (int32_t)(tos32((BSWAP_32(bacc) & 0xf), 4))
  61. #endif
  62. enum {
  63. ANALOG_SENSOR,
  64. DISCRETE_SENSOR,
  65. };
  66. #define READING_UNAVAILABLE 0x20
  67. #define SCANNING_DISABLED 0x40
  68. #define EVENT_MSG_DISABLED 0x80
  69. #define IS_READING_UNAVAILABLE(val) ((val) & READING_UNAVAILABLE)
  70. #define IS_SCANNING_DISABLED(val) (!((val) & SCANNING_DISABLED))
  71. #define IS_EVENT_MSG_DISABLED(val) (!((val) & EVENT_MSG_DISABLED))
  72. #define GET_SDR_REPO_INFO 0x20
  73. #define GET_SDR_ALLOC_INFO 0x21
  74. #define SDR_SENSOR_STAT_LO_NC (1<<0)
  75. #define SDR_SENSOR_STAT_LO_CR (1<<1)
  76. #define SDR_SENSOR_STAT_LO_NR (1<<2)
  77. #define SDR_SENSOR_STAT_HI_NC (1<<3)
  78. #define SDR_SENSOR_STAT_HI_CR (1<<4)
  79. #define SDR_SENSOR_STAT_HI_NR (1<<5)
  80. #define GET_DEVICE_SDR_INFO 0x20
  81. #define GET_DEVICE_SDR 0x21
  82. #define GET_SENSOR_FACTORS 0x23
  83. #define GET_SENSOR_FACTORS 0x23
  84. #define SET_SENSOR_HYSTERESIS 0x24
  85. #define GET_SENSOR_HYSTERESIS 0x25
  86. #define SET_SENSOR_THRESHOLDS 0x26
  87. #define GET_SENSOR_THRESHOLDS 0x27
  88. #define SET_SENSOR_EVENT_ENABLE 0x28
  89. #define GET_SENSOR_EVENT_ENABLE 0x29
  90. #define GET_SENSOR_EVENT_STATUS 0x2b
  91. #define GET_SENSOR_READING 0x2d
  92. #define GET_SENSOR_TYPE 0x2f
  93. #ifdef HAVE_PRAGMA_PACK
  94. #pragma pack(1)
  95. #endif
  96. struct sdr_repo_info_rs {
  97. uint8_t version; /* SDR version (51h) */
  98. uint16_t count; /* number of records */
  99. uint16_t free; /* free space in SDR */
  100. uint32_t add_stamp; /* last add timestamp */
  101. uint32_t erase_stamp; /* last del timestamp */
  102. uint8_t op_support; /* supported operations */
  103. } ATTRIBUTE_PACKING;
  104. #ifdef HAVE_PRAGMA_PACK
  105. #pragma pack(0)
  106. #endif
  107. #ifdef HAVE_PRAGMA_PACK
  108. #pragma pack(1)
  109. #endif
  110. /* builtin (device) sdrs support */
  111. struct sdr_device_info_rs {
  112. unsigned char count; /* number of records */
  113. unsigned char flags; /* flags */
  114. unsigned char popChangeInd[3]; /* free space in SDR */
  115. } ATTRIBUTE_PACKING;
  116. #ifdef HAVE_PRAGMA_PACK
  117. #pragma pack(0)
  118. #endif
  119. #ifdef HAVE_PRAGMA_PACK
  120. #pragma pack(1)
  121. #endif
  122. #define GET_SDR_RESERVE_REPO 0x22
  123. struct sdr_reserve_repo_rs {
  124. uint16_t reserve_id; /* reservation ID */
  125. } ATTRIBUTE_PACKING;
  126. #ifdef HAVE_PRAGMA_PACK
  127. #pragma pack(0)
  128. #endif
  129. #ifdef HAVE_PRAGMA_PACK
  130. #pragma pack(1)
  131. #endif
  132. #define GET_SDR 0x23
  133. struct sdr_get_rq {
  134. uint16_t reserve_id; /* reservation ID */
  135. uint16_t id; /* record ID */
  136. uint8_t offset; /* offset into SDR */
  137. #define GET_SDR_ENTIRE_RECORD 0xff
  138. uint8_t length; /* length to read */
  139. } ATTRIBUTE_PACKING;
  140. #ifdef HAVE_PRAGMA_PACK
  141. #pragma pack(0)
  142. #endif
  143. #ifdef HAVE_PRAGMA_PACK
  144. #pragma pack(1)
  145. #endif
  146. struct sdr_get_rs {
  147. uint16_t next; /* next record id */
  148. uint16_t id; /* record ID */
  149. uint8_t version; /* SDR version (51h) */
  150. #define SDR_RECORD_TYPE_FULL_SENSOR 0x01
  151. #define SDR_RECORD_TYPE_COMPACT_SENSOR 0x02
  152. #define SDR_RECORD_TYPE_EVENTONLY_SENSOR 0x03
  153. #define SDR_RECORD_TYPE_ENTITY_ASSOC 0x08
  154. #define SDR_RECORD_TYPE_DEVICE_ENTITY_ASSOC 0x09
  155. #define SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR 0x10
  156. #define SDR_RECORD_TYPE_FRU_DEVICE_LOCATOR 0x11
  157. #define SDR_RECORD_TYPE_MC_DEVICE_LOCATOR 0x12
  158. #define SDR_RECORD_TYPE_MC_CONFIRMATION 0x13
  159. #define SDR_RECORD_TYPE_BMC_MSG_CHANNEL_INFO 0x14
  160. #define SDR_RECORD_TYPE_OEM 0xc0
  161. uint8_t type; /* record type */
  162. uint8_t length; /* remaining record bytes */
  163. } ATTRIBUTE_PACKING;
  164. #ifdef HAVE_PRAGMA_PACK
  165. #pragma pack(0)
  166. #endif
  167. #ifdef HAVE_PRAGMA_PACK
  168. #pragma pack(1)
  169. #endif
  170. struct sdr_record_mask {
  171. union {
  172. struct {
  173. uint16_t assert_event; /* assertion event mask */
  174. uint16_t deassert_event; /* de-assertion event mask */
  175. uint16_t read; /* discrete reading mask */
  176. } ATTRIBUTE_PACKING discrete;
  177. struct {
  178. #if WORDS_BIGENDIAN
  179. uint16_t reserved:1;
  180. uint16_t status_lnr:1;
  181. uint16_t status_lcr:1;
  182. uint16_t status_lnc:1;
  183. uint16_t assert_unr_high:1;
  184. uint16_t assert_unr_low:1;
  185. uint16_t assert_ucr_high:1;
  186. uint16_t assert_ucr_low:1;
  187. uint16_t assert_unc_high:1;
  188. uint16_t assert_unc_low:1;
  189. uint16_t assert_lnr_high:1;
  190. uint16_t assert_lnr_low:1;
  191. uint16_t assert_lcr_high:1;
  192. uint16_t assert_lcr_low:1;
  193. uint16_t assert_lnc_high:1;
  194. uint16_t assert_lnc_low:1;
  195. #else
  196. uint16_t assert_lnc_low:1;
  197. uint16_t assert_lnc_high:1;
  198. uint16_t assert_lcr_low:1;
  199. uint16_t assert_lcr_high:1;
  200. uint16_t assert_lnr_low:1;
  201. uint16_t assert_lnr_high:1;
  202. uint16_t assert_unc_low:1;
  203. uint16_t assert_unc_high:1;
  204. uint16_t assert_ucr_low:1;
  205. uint16_t assert_ucr_high:1;
  206. uint16_t assert_unr_low:1;
  207. uint16_t assert_unr_high:1;
  208. uint16_t status_lnc:1;
  209. uint16_t status_lcr:1;
  210. uint16_t status_lnr:1;
  211. uint16_t reserved:1;
  212. #endif
  213. #if WORDS_BIGENDIAN
  214. uint16_t reserved_2:1;
  215. uint16_t status_unr:1;
  216. uint16_t status_ucr:1;
  217. uint16_t status_unc:1;
  218. uint16_t deassert_unr_high:1;
  219. uint16_t deassert_unr_low:1;
  220. uint16_t deassert_ucr_high:1;
  221. uint16_t deassert_ucr_low:1;
  222. uint16_t deassert_unc_high:1;
  223. uint16_t deassert_unc_low:1;
  224. uint16_t deassert_lnr_high:1;
  225. uint16_t deassert_lnr_low:1;
  226. uint16_t deassert_lcr_high:1;
  227. uint16_t deassert_lcr_low:1;
  228. uint16_t deassert_lnc_high:1;
  229. uint16_t deassert_lnc_low:1;
  230. #else
  231. uint16_t deassert_lnc_low:1;
  232. uint16_t deassert_lnc_high:1;
  233. uint16_t deassert_lcr_low:1;
  234. uint16_t deassert_lcr_high:1;
  235. uint16_t deassert_lnr_low:1;
  236. uint16_t deassert_lnr_high:1;
  237. uint16_t deassert_unc_low:1;
  238. uint16_t deassert_unc_high:1;
  239. uint16_t deassert_ucr_low:1;
  240. uint16_t deassert_ucr_high:1;
  241. uint16_t deassert_unr_low:1;
  242. uint16_t deassert_unr_high:1;
  243. uint16_t status_unc:1;
  244. uint16_t status_ucr:1;
  245. uint16_t status_unr:1;
  246. uint16_t reserved_2:1;
  247. #endif
  248. union {
  249. struct {
  250. #if WORDS_BIGENDIAN /* settable threshold mask */
  251. uint16_t reserved:2;
  252. uint16_t unr:1;
  253. uint16_t ucr:1;
  254. uint16_t unc:1;
  255. uint16_t lnr:1;
  256. uint16_t lcr:1;
  257. uint16_t lnc:1;
  258. /* padding lower 8 bits */
  259. uint16_t readable:8;
  260. #else
  261. uint16_t readable:8;
  262. uint16_t lnc:1;
  263. uint16_t lcr:1;
  264. uint16_t lnr:1;
  265. uint16_t unc:1;
  266. uint16_t ucr:1;
  267. uint16_t unr:1;
  268. uint16_t reserved:2;
  269. #endif
  270. } ATTRIBUTE_PACKING set;
  271. struct {
  272. #if WORDS_BIGENDIAN /* readable threshold mask */
  273. /* padding upper 8 bits */
  274. uint16_t settable:8;
  275. uint16_t reserved:2;
  276. uint16_t unr:1;
  277. uint16_t ucr:1;
  278. uint16_t unc:1;
  279. uint16_t lnr:1;
  280. uint16_t lcr:1;
  281. uint16_t lnc:1;
  282. #else
  283. uint16_t lnc:1;
  284. uint16_t lcr:1;
  285. uint16_t lnr:1;
  286. uint16_t unc:1;
  287. uint16_t ucr:1;
  288. uint16_t unr:1;
  289. uint16_t reserved:2;
  290. uint16_t settable:8;
  291. #endif
  292. } ATTRIBUTE_PACKING read;
  293. } ATTRIBUTE_PACKING;
  294. } ATTRIBUTE_PACKING threshold;
  295. } ATTRIBUTE_PACKING type;
  296. } ATTRIBUTE_PACKING;
  297. #ifdef HAVE_PRAGMA_PACK
  298. #pragma pack(0)
  299. #endif
  300. #ifdef HAVE_PRAGMA_PACK
  301. #pragma pack(1)
  302. #endif
  303. struct sdr_record_common_sensor {
  304. struct {
  305. uint8_t owner_id;
  306. #if WORDS_BIGENDIAN
  307. uint8_t channel:4; /* channel number */
  308. uint8_t __reserved:2;
  309. uint8_t lun:2; /* sensor owner lun */
  310. #else
  311. uint8_t lun:2; /* sensor owner lun */
  312. uint8_t __reserved:2;
  313. uint8_t channel:4; /* channel number */
  314. #endif
  315. uint8_t sensor_num; /* unique sensor number */
  316. } ATTRIBUTE_PACKING keys;
  317. struct entity_id entity;
  318. struct {
  319. struct {
  320. #if WORDS_BIGENDIAN
  321. uint8_t __reserved:1;
  322. uint8_t scanning:1;
  323. uint8_t events:1;
  324. uint8_t thresholds:1;
  325. uint8_t hysteresis:1;
  326. uint8_t type:1;
  327. uint8_t event_gen:1;
  328. uint8_t sensor_scan:1;
  329. #else
  330. uint8_t sensor_scan:1;
  331. uint8_t event_gen:1;
  332. uint8_t type:1;
  333. uint8_t hysteresis:1;
  334. uint8_t thresholds:1;
  335. uint8_t events:1;
  336. uint8_t scanning:1;
  337. uint8_t __reserved:1;
  338. #endif
  339. } ATTRIBUTE_PACKING init;
  340. struct {
  341. #if WORDS_BIGENDIAN
  342. uint8_t ignore:1;
  343. uint8_t rearm:1;
  344. uint8_t hysteresis:2;
  345. uint8_t threshold:2;
  346. uint8_t event_msg:2;
  347. #else
  348. uint8_t event_msg:2;
  349. uint8_t threshold:2;
  350. uint8_t hysteresis:2;
  351. uint8_t rearm:1;
  352. uint8_t ignore:1;
  353. #endif
  354. } ATTRIBUTE_PACKING capabilities;
  355. uint8_t type;
  356. } ATTRIBUTE_PACKING sensor;
  357. uint8_t event_type; /* event/reading type code */
  358. struct sdr_record_mask mask;
  359. struct {
  360. #if WORDS_BIGENDIAN
  361. uint8_t analog:2;
  362. uint8_t rate:3;
  363. uint8_t modifier:2;
  364. uint8_t pct:1;
  365. #else
  366. uint8_t pct:1;
  367. uint8_t modifier:2;
  368. uint8_t rate:3;
  369. uint8_t analog:2;
  370. #endif
  371. struct {
  372. uint8_t base;
  373. uint8_t modifier;
  374. } ATTRIBUTE_PACKING type;
  375. } ATTRIBUTE_PACKING unit;
  376. } ATTRIBUTE_PACKING;
  377. /* SDR Record Common Sensor header macros */
  378. #define IS_THRESHOLD_SENSOR(s) ((s)->event_type == 1)
  379. #define UNITS_ARE_DISCRETE(s) ((s)->unit.analog == 3)
  380. #ifdef HAVE_PRAGMA_PACK
  381. #pragma pack(0)
  382. #endif
  383. #ifdef HAVE_PRAGMA_PACK
  384. #pragma pack(1)
  385. #endif
  386. struct sdr_record_compact_sensor {
  387. struct sdr_record_common_sensor cmn;
  388. struct {
  389. #if WORDS_BIGENDIAN
  390. uint8_t __reserved:2;
  391. uint8_t mod_type:2;
  392. uint8_t count:4;
  393. #else
  394. uint8_t count:4;
  395. uint8_t mod_type:2;
  396. uint8_t __reserved:2;
  397. #endif
  398. #if WORDS_BIGENDIAN
  399. uint8_t entity_inst:1;
  400. uint8_t mod_offset:7;
  401. #else
  402. uint8_t mod_offset:7;
  403. uint8_t entity_inst:1;
  404. #endif
  405. } ATTRIBUTE_PACKING share;
  406. struct {
  407. struct {
  408. uint8_t positive;
  409. uint8_t negative;
  410. } ATTRIBUTE_PACKING hysteresis;
  411. } ATTRIBUTE_PACKING threshold;
  412. uint8_t __reserved[3];
  413. uint8_t oem; /* reserved for OEM use */
  414. uint8_t id_code; /* sensor ID string type/length code */
  415. uint8_t id_string[16]; /* sensor ID string bytes, only if id_code != 0 */
  416. } ATTRIBUTE_PACKING;
  417. #ifdef HAVE_PRAGMA_PACK
  418. #pragma pack(0)
  419. #endif
  420. #ifdef HAVE_PRAGMA_PACK
  421. #pragma pack(1)
  422. #endif
  423. struct sdr_record_eventonly_sensor {
  424. struct {
  425. uint8_t owner_id;
  426. #if WORDS_BIGENDIAN
  427. uint8_t channel:4; /* channel number */
  428. uint8_t fru_owner:2; /* fru device owner lun */
  429. uint8_t lun:2; /* sensor owner lun */
  430. #else
  431. uint8_t lun:2; /* sensor owner lun */
  432. uint8_t fru_owner:2; /* fru device owner lun */
  433. uint8_t channel:4; /* channel number */
  434. #endif
  435. uint8_t sensor_num; /* unique sensor number */
  436. } ATTRIBUTE_PACKING keys;
  437. struct entity_id entity;
  438. uint8_t sensor_type; /* sensor type */
  439. uint8_t event_type; /* event/reading type code */
  440. struct {
  441. #if WORDS_BIGENDIAN
  442. uint8_t __reserved:2;
  443. uint8_t mod_type:2;
  444. uint8_t count:4;
  445. #else
  446. uint8_t count:4;
  447. uint8_t mod_type:2;
  448. uint8_t __reserved:2;
  449. #endif
  450. #if WORDS_BIGENDIAN
  451. uint8_t entity_inst:1;
  452. uint8_t mod_offset:7;
  453. #else
  454. uint8_t mod_offset:7;
  455. uint8_t entity_inst:1;
  456. #endif
  457. } ATTRIBUTE_PACKING share;
  458. uint8_t __reserved;
  459. uint8_t oem; /* reserved for OEM use */
  460. uint8_t id_code; /* sensor ID string type/length code */
  461. uint8_t id_string[16]; /* sensor ID string bytes, only if id_code != 0 */
  462. } ATTRIBUTE_PACKING;
  463. #ifdef HAVE_PRAGMA_PACK
  464. #pragma pack(0)
  465. #endif
  466. #ifdef HAVE_PRAGMA_PACK
  467. #pragma pack(1)
  468. #endif
  469. struct sdr_record_full_sensor {
  470. struct sdr_record_common_sensor cmn;
  471. #define SDR_SENSOR_L_LINEAR 0x00
  472. #define SDR_SENSOR_L_LN 0x01
  473. #define SDR_SENSOR_L_LOG10 0x02
  474. #define SDR_SENSOR_L_LOG2 0x03
  475. #define SDR_SENSOR_L_E 0x04
  476. #define SDR_SENSOR_L_EXP10 0x05
  477. #define SDR_SENSOR_L_EXP2 0x06
  478. #define SDR_SENSOR_L_1_X 0x07
  479. #define SDR_SENSOR_L_SQR 0x08
  480. #define SDR_SENSOR_L_CUBE 0x09
  481. #define SDR_SENSOR_L_SQRT 0x0a
  482. #define SDR_SENSOR_L_CUBERT 0x0b
  483. #define SDR_SENSOR_L_NONLINEAR 0x70
  484. uint8_t linearization; /* 70h=non linear, 71h-7Fh=non linear, OEM */
  485. uint16_t mtol; /* M, tolerance */
  486. uint32_t bacc; /* accuracy, B, Bexp, Rexp */
  487. struct {
  488. #if WORDS_BIGENDIAN
  489. uint8_t __reserved:5;
  490. uint8_t normal_min:1; /* normal min field specified */
  491. uint8_t normal_max:1; /* normal max field specified */
  492. uint8_t nominal_read:1; /* nominal reading field specified */
  493. #else
  494. uint8_t nominal_read:1; /* nominal reading field specified */
  495. uint8_t normal_max:1; /* normal max field specified */
  496. uint8_t normal_min:1; /* normal min field specified */
  497. uint8_t __reserved:5;
  498. #endif
  499. } ATTRIBUTE_PACKING analog_flag;
  500. uint8_t nominal_read; /* nominal reading, raw value */
  501. uint8_t normal_max; /* normal maximum, raw value */
  502. uint8_t normal_min; /* normal minimum, raw value */
  503. uint8_t sensor_max; /* sensor maximum, raw value */
  504. uint8_t sensor_min; /* sensor minimum, raw value */
  505. struct {
  506. struct {
  507. uint8_t non_recover;
  508. uint8_t critical;
  509. uint8_t non_critical;
  510. } ATTRIBUTE_PACKING upper;
  511. struct {
  512. uint8_t non_recover;
  513. uint8_t critical;
  514. uint8_t non_critical;
  515. } ATTRIBUTE_PACKING lower;
  516. struct {
  517. uint8_t positive;
  518. uint8_t negative;
  519. } ATTRIBUTE_PACKING hysteresis;
  520. } ATTRIBUTE_PACKING threshold;
  521. uint8_t __reserved[2];
  522. uint8_t oem; /* reserved for OEM use */
  523. uint8_t id_code; /* sensor ID string type/length code */
  524. uint8_t id_string[16]; /* sensor ID string bytes, only if id_code != 0 */
  525. } ATTRIBUTE_PACKING;
  526. #ifdef HAVE_PRAGMA_PACK
  527. #pragma pack(0)
  528. #endif
  529. #ifdef HAVE_PRAGMA_PACK
  530. #pragma pack(1)
  531. #endif
  532. struct sdr_record_mc_locator {
  533. uint8_t dev_slave_addr;
  534. #if WORDS_BIGENDIAN
  535. uint8_t __reserved2:4;
  536. uint8_t channel_num:4;
  537. #else
  538. uint8_t channel_num:4;
  539. uint8_t __reserved2:4;
  540. #endif
  541. #if WORDS_BIGENDIAN
  542. uint8_t pwr_state_notif:3;
  543. uint8_t __reserved3:1;
  544. uint8_t global_init:4;
  545. #else
  546. uint8_t global_init:4;
  547. uint8_t __reserved3:1;
  548. uint8_t pwr_state_notif:3;
  549. #endif
  550. uint8_t dev_support;
  551. uint8_t __reserved4[3];
  552. struct entity_id entity;
  553. uint8_t oem;
  554. uint8_t id_code;
  555. uint8_t id_string[16];
  556. } ATTRIBUTE_PACKING;
  557. #ifdef HAVE_PRAGMA_PACK
  558. #pragma pack(0)
  559. #endif
  560. struct sdr_record_fru_locator {
  561. uint8_t dev_slave_addr;
  562. uint8_t device_id;
  563. #if WORDS_BIGENDIAN
  564. uint8_t logical:1;
  565. uint8_t __reserved2:2;
  566. uint8_t lun:2;
  567. uint8_t bus:3;
  568. #else
  569. uint8_t bus:3;
  570. uint8_t lun:2;
  571. uint8_t __reserved2:2;
  572. uint8_t logical:1;
  573. #endif
  574. #if WORDS_BIGENDIAN
  575. uint8_t channel_num:4;
  576. uint8_t __reserved3:4;
  577. #else
  578. uint8_t __reserved3:4;
  579. uint8_t channel_num:4;
  580. #endif
  581. uint8_t __reserved4;
  582. uint8_t dev_type;
  583. uint8_t dev_type_modifier;
  584. struct entity_id entity;
  585. uint8_t oem;
  586. uint8_t id_code;
  587. uint8_t id_string[16];
  588. } ATTRIBUTE_PACKING;
  589. #ifdef HAVE_PRAGMA_PACK
  590. #pragma pack(0)
  591. #endif
  592. #ifdef HAVE_PRAGMA_PACK
  593. #pragma pack(1)
  594. #endif
  595. struct sdr_record_generic_locator {
  596. uint8_t dev_access_addr;
  597. uint8_t dev_slave_addr;
  598. #if WORDS_BIGENDIAN
  599. uint8_t channel_num:3;
  600. uint8_t lun:2;
  601. uint8_t bus:3;
  602. #else
  603. uint8_t bus:3;
  604. uint8_t lun:2;
  605. uint8_t channel_num:3;
  606. #endif
  607. #if WORDS_BIGENDIAN
  608. uint8_t addr_span:3;
  609. uint8_t __reserved1:5;
  610. #else
  611. uint8_t __reserved1:5;
  612. uint8_t addr_span:3;
  613. #endif
  614. uint8_t __reserved2;
  615. uint8_t dev_type;
  616. uint8_t dev_type_modifier;
  617. struct entity_id entity;
  618. uint8_t oem;
  619. uint8_t id_code;
  620. uint8_t id_string[16];
  621. } ATTRIBUTE_PACKING;
  622. #ifdef HAVE_PRAGMA_PACK
  623. #pragma pack(0)
  624. #endif
  625. #ifdef HAVE_PRAGMA_PACK
  626. #pragma pack(1)
  627. #endif
  628. struct sdr_record_entity_assoc {
  629. struct entity_id entity; /* container entity ID and instance */
  630. struct {
  631. #if WORDS_BIGENDIAN
  632. uint8_t isrange:1;
  633. uint8_t islinked:1;
  634. uint8_t isaccessable:1;
  635. uint8_t __reserved:5;
  636. #else
  637. uint8_t __reserved:5;
  638. uint8_t isaccessable:1;
  639. uint8_t islinked:1;
  640. uint8_t isrange:1;
  641. #endif
  642. } flags;
  643. uint8_t entity_id_1; /* entity ID 1 | range 1 entity */
  644. uint8_t entity_inst_1; /* entity inst 1 | range 1 first instance */
  645. uint8_t entity_id_2; /* entity ID 2 | range 1 entity */
  646. uint8_t entity_inst_2; /* entity inst 2 | range 1 last instance */
  647. uint8_t entity_id_3; /* entity ID 3 | range 2 entity */
  648. uint8_t entity_inst_3; /* entity inst 3 | range 2 first instance */
  649. uint8_t entity_id_4; /* entity ID 4 | range 2 entity */
  650. uint8_t entity_inst_4; /* entity inst 4 | range 2 last instance */
  651. } ATTRIBUTE_PACKING;
  652. #ifdef HAVE_PRAGMA_PACK
  653. #pragma pack(0)
  654. #endif
  655. struct sdr_record_oem {
  656. uint8_t *data;
  657. int data_len;
  658. };
  659. /*
  660. * The Get SDR Repository Info response structure
  661. * From table 33-3 of the IPMI v2.0 spec
  662. */
  663. #ifdef HAVE_PRAGMA_PACK
  664. #pragma pack(1)
  665. #endif
  666. struct get_sdr_repository_info_rsp {
  667. uint8_t sdr_version;
  668. uint8_t record_count_lsb;
  669. uint8_t record_count_msb;
  670. uint8_t free_space[2];
  671. uint8_t most_recent_addition_timestamp[4];
  672. uint8_t most_recent_erase_timestamp[4];
  673. #if WORDS_BIGENDIAN
  674. uint8_t overflow_flag:1;
  675. uint8_t modal_update_support:2;
  676. uint8_t __reserved1:1;
  677. uint8_t delete_sdr_supported:1;
  678. uint8_t partial_add_sdr_supported:1;
  679. uint8_t reserve_sdr_repository_supported:1;
  680. uint8_t get_sdr_repository_allo_info_supported:1;
  681. #else
  682. uint8_t get_sdr_repository_allo_info_supported:1;
  683. uint8_t reserve_sdr_repository_supported:1;
  684. uint8_t partial_add_sdr_supported:1;
  685. uint8_t delete_sdr_supported:1;
  686. uint8_t __reserved1:1;
  687. uint8_t modal_update_support:2;
  688. uint8_t overflow_flag:1;
  689. #endif
  690. } ATTRIBUTE_PACKING;
  691. #ifdef HAVE_PRAGMA_PACK
  692. #pragma pack(0)
  693. #endif
  694. struct ipmi_sdr_iterator {
  695. uint16_t reservation;
  696. int total;
  697. int next;
  698. int use_built_in;
  699. };
  700. #ifdef HAVE_PRAGMA_PACK
  701. #pragma pack(1)
  702. #endif
  703. struct sdr_record_list {
  704. uint16_t id;
  705. uint8_t version;
  706. uint8_t type;
  707. uint8_t length;
  708. uint8_t *raw;
  709. struct sdr_record_list *next;
  710. union {
  711. struct sdr_record_common_sensor *common;
  712. struct sdr_record_full_sensor *full;
  713. struct sdr_record_compact_sensor *compact;
  714. struct sdr_record_eventonly_sensor *eventonly;
  715. struct sdr_record_generic_locator *genloc;
  716. struct sdr_record_fru_locator *fruloc;
  717. struct sdr_record_mc_locator *mcloc;
  718. struct sdr_record_entity_assoc *entassoc;
  719. struct sdr_record_oem *oem;
  720. } ATTRIBUTE_PACKING record;
  721. } ATTRIBUTE_PACKING;
  722. #ifdef HAVE_PRAGMA_PACK
  723. #pragma pack(0)
  724. #endif
  725. /* unit description codes (IPMI v1.5 section 37.16) */
  726. #define UNIT_MAX 0x90
  727. static const char *unit_desc[] __attribute__ ((unused)) = {
  728. "unspecified",
  729. "degrees C", "degrees F", "degrees K",
  730. "Volts", "Amps", "Watts", "Joules",
  731. "Coulombs", "VA", "Nits",
  732. "lumen", "lux", "Candela",
  733. "kPa", "PSI", "Newton",
  734. "CFM", "RPM", "Hz",
  735. "microsecond", "millisecond", "second", "minute", "hour",
  736. "day", "week", "mil", "inches", "feet", "cu in", "cu feet",
  737. "mm", "cm", "m", "cu cm", "cu m", "liters", "fluid ounce",
  738. "radians", "steradians", "revolutions", "cycles",
  739. "gravities", "ounce", "pound", "ft-lb", "oz-in", "gauss",
  740. "gilberts", "henry", "millihenry", "farad", "microfarad",
  741. "ohms", "siemens", "mole", "becquerel", "PPM", "reserved",
  742. "Decibels", "DbA", "DbC", "gray", "sievert",
  743. "color temp deg K", "bit", "kilobit", "megabit", "gigabit",
  744. "byte", "kilobyte", "megabyte", "gigabyte", "word", "dword",
  745. "qword", "line", "hit", "miss", "retry", "reset",
  746. "overflow", "underrun", "collision", "packets", "messages",
  747. "characters", "error", "correctable error", "uncorrectable error",};
  748. /* sensor type codes (IPMI v1.5 table 36.3)
  749. / Updated to v2.0 Table 42-3, Sensor Type Codes */
  750. #define SENSOR_TYPE_MAX 0x2C
  751. static const char *sensor_type_desc[] __attribute__ ((unused)) = {
  752. "reserved",
  753. "Temperature", "Voltage", "Current", "Fan",
  754. "Physical Security", "Platform Security", "Processor",
  755. "Power Supply", "Power Unit", "Cooling Device", "Other",
  756. "Memory", "Drive Slot / Bay", "POST Memory Resize",
  757. "System Firmwares", "Event Logging Disabled", "Watchdog1",
  758. "System Event", "Critical Interrupt", "Button",
  759. "Module / Board", "Microcontroller", "Add-in Card",
  760. "Chassis", "Chip Set", "Other FRU", "Cable / Interconnect",
  761. "Terminator", "System Boot Initiated", "Boot Error",
  762. "OS Boot", "OS Critical Stop", "Slot / Connector",
  763. "System ACPI Power State", "Watchdog2", "Platform Alert",
  764. "Entity Presence", "Monitor ASIC", "LAN",
  765. "Management Subsys Health", "Battery", "Session Audit",
  766. "Version Change", "FRU State" };
  767. struct sensor_reading {
  768. char s_id[17]; /* name of the sensor */
  769. struct sdr_record_full_sensor *full;
  770. struct sdr_record_compact_sensor *compact;
  771. uint8_t s_reading_valid; /* read value valididity */
  772. uint8_t s_scanning_disabled; /* read of value disabled */
  773. uint8_t s_reading_unavailable; /* read value unavailable */
  774. uint8_t s_reading; /* value which was read */
  775. uint8_t s_data2; /* data2 value read */
  776. uint8_t s_data3; /* data3 value read */
  777. uint8_t s_has_analog_value; /* sensor has analog value */
  778. double s_a_val; /* read value converted to analog */
  779. char s_a_str[16]; /* analog value as a string */
  780. const char *s_a_units; /* analog value units string */
  781. };
  782. /*
  783. * Determine if bridging is necessary to address a sensor at the given
  784. * address (_addr) and (_chan) via the interface (_intf).
  785. *
  786. * If the sensor is being addressed on channel zero, it resides on
  787. * IPMB-0. If the interface target IPMB-0 address is exactly the same as
  788. * the sensor address then the sensor resides on the target IPMB-0
  789. * so we don't need extra levels of bridging to address the sensor.
  790. * Or
  791. * If the sensor target address and channel match the interface target address
  792. * and channel then there is no extra levels of bridging required.
  793. *
  794. * Note:
  795. * The target IPMB-0 address is the address of the SDR repository that was
  796. * accessed using the user specified bridging command line arguments.
  797. * Access to any sensor on the target IPMB-0 can be addressed using the
  798. * target address and transit address in the interface.
  799. */
  800. #define BRIDGE_TO_SENSOR(_intf, _addr, _chan) \
  801. ( !((_chan == 0 && _intf->target_ipmb_addr && \
  802. _intf->target_ipmb_addr == _addr) || \
  803. (_addr == _intf->target_addr && _chan == _intf->target_channel)) )
  804. struct ipmi_sdr_iterator *ipmi_sdr_start(struct ipmi_intf *intf,
  805. int use_builtin);
  806. struct sdr_get_rs *ipmi_sdr_get_next_header(struct ipmi_intf *intf,
  807. struct ipmi_sdr_iterator *i);
  808. uint8_t *ipmi_sdr_get_record(struct ipmi_intf *intf, struct sdr_get_rs *header,
  809. struct ipmi_sdr_iterator *i);
  810. void ipmi_sdr_end(struct ipmi_intf *intf, struct ipmi_sdr_iterator *i);
  811. int ipmi_sdr_print_sdr(struct ipmi_intf *intf, uint8_t type);
  812. int ipmi_sdr_print_name_from_rawentry(struct ipmi_intf *intf,uint16_t id,
  813. uint8_t type,uint8_t * raw);
  814. int ipmi_sdr_print_rawentry(struct ipmi_intf *intf, uint8_t type, uint8_t * raw,
  815. int len);
  816. int ipmi_sdr_print_listentry(struct ipmi_intf *intf,
  817. struct sdr_record_list *entry);
  818. void ipmi_sdr_print_sensor_hysteresis(struct sdr_record_common_sensor *sensor,
  819. struct sdr_record_full_sensor *full,
  820. uint8_t hysteresis_value,
  821. const char *hdrstr);
  822. const char *ipmi_sdr_get_unit_string(uint8_t pct, uint8_t type,
  823. uint8_t base, uint8_t modifier);
  824. struct sensor_reading *
  825. ipmi_sdr_read_sensor_value(struct ipmi_intf *intf,
  826. struct sdr_record_common_sensor *sensor,
  827. uint8_t sdr_record_type, int precision);
  828. const char *ipmi_sdr_get_thresh_status(struct sensor_reading *sr,
  829. const char *invalidstr);
  830. const char *ipmi_sdr_get_status(int, const char *, uint8_t stat);
  831. double sdr_convert_sensor_tolerance(struct sdr_record_full_sensor *sensor,
  832. uint8_t val);
  833. double sdr_convert_sensor_reading(struct sdr_record_full_sensor *sensor,
  834. uint8_t val);
  835. double sdr_convert_sensor_hysterisis(struct sdr_record_full_sensor *sensor,
  836. uint8_t val);
  837. uint8_t sdr_convert_sensor_value_to_raw(struct sdr_record_full_sensor *sensor,
  838. double val);
  839. struct ipmi_rs *ipmi_sdr_get_sensor_reading(struct ipmi_intf *intf,
  840. uint8_t sensor);
  841. struct ipmi_rs *ipmi_sdr_get_sensor_reading_ipmb(struct ipmi_intf *intf,
  842. uint8_t sensor,
  843. uint8_t target,
  844. uint8_t lun,
  845. uint8_t channel);
  846. struct ipmi_rs *ipmi_sdr_get_sensor_thresholds(struct ipmi_intf *intf,
  847. uint8_t sensor,
  848. uint8_t target, uint8_t lun, uint8_t channel);
  849. struct ipmi_rs *ipmi_sdr_get_sensor_hysteresis(struct ipmi_intf *intf,
  850. uint8_t sensor,
  851. uint8_t target, uint8_t lun, uint8_t channel);
  852. int ipmi_sdr_get_reservation(struct ipmi_intf *intf, int use_builtin,
  853. uint16_t * reserve_id);
  854. int ipmi_sdr_print_sensor_eventonly(struct ipmi_intf *intf,
  855. struct sdr_record_eventonly_sensor *sensor);
  856. int ipmi_sdr_print_sensor_generic_locator(struct ipmi_intf *intf,
  857. struct sdr_record_generic_locator
  858. *fru);
  859. int ipmi_sdr_print_sensor_fru_locator(struct ipmi_intf *intf,
  860. struct sdr_record_fru_locator *fru);
  861. int ipmi_sdr_print_sensor_mc_locator(struct ipmi_intf *intf,
  862. struct sdr_record_mc_locator *mc);
  863. int ipmi_sdr_print_sensor_entity_assoc(struct ipmi_intf *intf,
  864. struct sdr_record_entity_assoc *assoc);
  865. struct sdr_record_list *ipmi_sdr_find_sdr_byentity(struct ipmi_intf *intf,
  866. struct entity_id *entity);
  867. struct sdr_record_list *ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf *intf,
  868. uint16_t gen_id, uint8_t num, uint8_t type);
  869. struct sdr_record_list *ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf,
  870. uint8_t type);
  871. struct sdr_record_list *ipmi_sdr_find_sdr_byid(struct ipmi_intf *intf,
  872. char *id);
  873. struct sdr_record_list *ipmi_sdr_find_sdr_bytype(struct ipmi_intf *intf,
  874. uint8_t type);
  875. int ipmi_sdr_list_cache(struct ipmi_intf *intf);
  876. int ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile);
  877. void ipmi_sdr_list_empty(struct ipmi_intf *intf);
  878. int ipmi_sdr_print_info(struct ipmi_intf *intf);
  879. void ipmi_sdr_print_discrete_state(struct ipmi_intf *intf,
  880. const char *desc, uint8_t sensor_type,
  881. uint8_t event_type, uint8_t state1,
  882. uint8_t state2);
  883. void ipmi_sdr_print_discrete_state_mini(struct ipmi_intf *intf,
  884. const char *header, const char *separator,
  885. uint8_t sensor_type, uint8_t event_type,
  886. uint8_t state1, uint8_t state2);
  887. int ipmi_sdr_print_sensor_event_status(struct ipmi_intf *intf,
  888. uint8_t sensor_num, uint8_t sensor_type,
  889. uint8_t event_type, int numeric_fmt,
  890. uint8_t target, uint8_t lun, uint8_t channel);
  891. int ipmi_sdr_print_sensor_event_enable(struct ipmi_intf *intf,
  892. uint8_t sensor_num, uint8_t sensor_type,
  893. uint8_t event_type, int numeric_fmt,
  894. uint8_t target, uint8_t lun, uint8_t channel);
  895. #endif /* IPMI_SDR_H */