fru.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (c) 2019-2020, Broadcom
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef FRU_H
  7. #define FRU_H
  8. #include <stdbool.h>
  9. #include <stdint.h>
  10. /* max string length */
  11. #define FRU_MAX_STR_LEN 32
  12. /* max number of DDR channels */
  13. #define BCM_MAX_NR_DDR 3
  14. /* max supported FRU table size */
  15. #define BCM_MAX_FRU_LEN 512
  16. /* FRU table starting offset */
  17. #define BCM_FRU_TBL_OFFSET 0x300000
  18. /* FRU time constants */
  19. #define MINS_PER_DAY 1440
  20. #define MINS_PER_HOUR 60
  21. #define FRU_YEAR_START 1996
  22. #define FRU_MONTH_START 1
  23. #define FRU_DAY_START 1
  24. #define MONTHS_PER_YEAR 12
  25. /*
  26. * FRU areas based on the spec
  27. */
  28. enum fru_area_name {
  29. FRU_AREA_INTERNAL = 0,
  30. FRU_AREA_CHASSIS_INFO,
  31. FRU_AREA_BOARD_INFO,
  32. FRU_AREA_PRODUCT_INFO,
  33. FRU_AREA_MRECORD_INFO,
  34. FRU_MAX_NR_AREAS
  35. };
  36. /*
  37. * FRU area information
  38. *
  39. * @use: indicate this area is being used
  40. * @version: format version
  41. * @offset: offset of this area from the beginning of the FRU table
  42. * @len: total length of the area
  43. */
  44. struct fru_area_info {
  45. bool use;
  46. uint8_t version;
  47. unsigned int offset;
  48. unsigned int len;
  49. };
  50. /*
  51. * DDR MCB information
  52. *
  53. * @idx: DDR channel index
  54. * @size_mb: DDR size of this channel in MB
  55. * @ref_id: DDR MCB reference ID
  56. */
  57. struct ddr_mcb {
  58. unsigned int idx;
  59. unsigned int size_mb;
  60. uint32_t ref_id;
  61. };
  62. /*
  63. * DDR information
  64. *
  65. * @ddr_info: array that contains MCB related info for each channel
  66. */
  67. struct ddr_info {
  68. struct ddr_mcb mcb[BCM_MAX_NR_DDR];
  69. };
  70. /*
  71. * FRU board area information
  72. *
  73. * @lang: Language code
  74. * @mfg_date: Manufacturing date
  75. * @manufacturer: Manufacturer
  76. * @product_name: Product name
  77. * @serial_number: Serial number
  78. * @part_number: Part number
  79. * @file_id: FRU file ID
  80. */
  81. struct fru_board_info {
  82. unsigned char lang;
  83. unsigned int mfg_date;
  84. unsigned char manufacturer[FRU_MAX_STR_LEN];
  85. unsigned char product_name[FRU_MAX_STR_LEN];
  86. unsigned char serial_number[FRU_MAX_STR_LEN];
  87. unsigned char part_number[FRU_MAX_STR_LEN];
  88. unsigned char file_id[FRU_MAX_STR_LEN];
  89. };
  90. /*
  91. * FRU manufacture date in human readable format
  92. */
  93. struct fru_time {
  94. unsigned int min;
  95. unsigned int hour;
  96. unsigned int day;
  97. unsigned int month;
  98. unsigned int year;
  99. };
  100. #ifdef USE_FRU
  101. int fru_validate(uint8_t *data, struct fru_area_info *fru_area);
  102. int fru_parse_ddr(uint8_t *data, struct fru_area_info *area,
  103. struct ddr_info *ddr);
  104. int fru_parse_board(uint8_t *data, struct fru_area_info *area,
  105. struct fru_board_info *board);
  106. void fru_format_time(unsigned int min, struct fru_time *tm);
  107. #else
  108. static inline int fru_validate(uint8_t *data, struct fru_area_info *fru_area)
  109. {
  110. return -1;
  111. }
  112. static inline int fru_parse_ddr(uint8_t *data, struct fru_area_info *area,
  113. struct ddr_info *ddr)
  114. {
  115. return -1;
  116. }
  117. static inline int fru_parse_board(uint8_t *data, struct fru_area_info *area,
  118. struct fru_board_info *board)
  119. {
  120. return -1;
  121. }
  122. static inline void fru_format_time(unsigned int min, struct fru_time *tm)
  123. {
  124. }
  125. #endif /* USE_FRU */
  126. #endif /* FRU_H */