ipmi-fru.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (C) 2012 CERN (www.cern.ch)
  3. * Author: Alessandro Rubini <rubini@gnudd.com>
  4. *
  5. * Released according to the GNU GPL, version 2 or any later version.
  6. *
  7. * This work is part of the White Rabbit project, a research effort led
  8. * by CERN, the European Institute for Nuclear Research.
  9. */
  10. #ifndef __LINUX_IPMI_FRU_H__
  11. #define __LINUX_IPMI_FRU_H__
  12. #ifdef __KERNEL__
  13. # include <linux/types.h>
  14. # include <linux/string.h>
  15. #else
  16. # include <stdint.h>
  17. # include <string.h>
  18. #endif
  19. /*
  20. * These structures match the unaligned crap we have in FRU1011.pdf
  21. * (http://download.intel.com/design/servers/ipmi/FRU1011.pdf)
  22. */
  23. /* chapter 8, page 5 */
  24. struct fru_common_header {
  25. uint8_t format; /* 0x01 */
  26. uint8_t internal_use_off; /* multiple of 8 bytes */
  27. uint8_t chassis_info_off; /* multiple of 8 bytes */
  28. uint8_t board_area_off; /* multiple of 8 bytes */
  29. uint8_t product_area_off; /* multiple of 8 bytes */
  30. uint8_t multirecord_off; /* multiple of 8 bytes */
  31. uint8_t pad; /* must be 0 */
  32. uint8_t checksum; /* sum modulo 256 must be 0 */
  33. };
  34. /* chapter 9, page 5 -- internal_use: not used by us */
  35. /* chapter 10, page 6 -- chassis info: not used by us */
  36. /* chapter 13, page 9 -- used by board_info_area below */
  37. struct fru_type_length {
  38. uint8_t type_length;
  39. uint8_t data[0];
  40. };
  41. /* chapter 11, page 7 */
  42. struct fru_board_info_area {
  43. uint8_t format; /* 0x01 */
  44. uint8_t area_len; /* multiple of 8 bytes */
  45. uint8_t language; /* I hope it's 0 */
  46. uint8_t mfg_date[3]; /* LSB, minutes since 1996-01-01 */
  47. struct fru_type_length tl[0]; /* type-length stuff follows */
  48. /*
  49. * the TL there are in order:
  50. * Board Manufacturer
  51. * Board Product Name
  52. * Board Serial Number
  53. * Board Part Number
  54. * FRU File ID (may be null)
  55. * more manufacturer-specific stuff
  56. * 0xc1 as a terminator
  57. * 0x00 pad to a multiple of 8 bytes - 1
  58. * checksum (sum of all stuff module 256 must be zero)
  59. */
  60. };
  61. enum fru_type {
  62. FRU_TYPE_BINARY = 0x00,
  63. FRU_TYPE_BCDPLUS = 0x40,
  64. FRU_TYPE_ASCII6 = 0x80,
  65. FRU_TYPE_ASCII = 0xc0, /* not ascii: depends on language */
  66. };
  67. /*
  68. * some helpers
  69. */
  70. static inline struct fru_board_info_area *fru_get_board_area(
  71. const struct fru_common_header *header)
  72. {
  73. /* we know for sure that the header is 8 bytes in size */
  74. return (struct fru_board_info_area *)(header + header->board_area_off);
  75. }
  76. static inline int fru_type(struct fru_type_length *tl)
  77. {
  78. return tl->type_length & 0xc0;
  79. }
  80. static inline int fru_length(struct fru_type_length *tl)
  81. {
  82. return (tl->type_length & 0x3f) + 1; /* len of whole record */
  83. }
  84. /* assume ascii-latin1 encoding */
  85. static inline int fru_strlen(struct fru_type_length *tl)
  86. {
  87. return fru_length(tl) - 1;
  88. }
  89. static inline char *fru_strcpy(char *dest, struct fru_type_length *tl)
  90. {
  91. int len = fru_strlen(tl);
  92. memcpy(dest, tl->data, len);
  93. dest[len] = '\0';
  94. return dest;
  95. }
  96. static inline struct fru_type_length *fru_next_tl(struct fru_type_length *tl)
  97. {
  98. return tl + fru_length(tl);
  99. }
  100. static inline int fru_is_eof(struct fru_type_length *tl)
  101. {
  102. return tl->type_length == 0xc1;
  103. }
  104. /*
  105. * External functions defined in fru-parse.c.
  106. */
  107. extern int fru_header_cksum_ok(struct fru_common_header *header);
  108. extern int fru_bia_cksum_ok(struct fru_board_info_area *bia);
  109. /* All these 4 return allocated strings by calling fru_alloc() */
  110. extern char *fru_get_board_manufacturer(struct fru_common_header *header);
  111. extern char *fru_get_product_name(struct fru_common_header *header);
  112. extern char *fru_get_serial_number(struct fru_common_header *header);
  113. extern char *fru_get_part_number(struct fru_common_header *header);
  114. /* This must be defined by the caller of the above functions */
  115. extern void *fru_alloc(size_t size);
  116. #endif /* __LINUX_IMPI_FRU_H__ */