common.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /* Copyright IBM Corp 2019 */
  3. #ifndef OCC_COMMON_H
  4. #define OCC_COMMON_H
  5. #include <linux/hwmon-sysfs.h>
  6. #include <linux/mutex.h>
  7. #include <linux/sysfs.h>
  8. struct device;
  9. #define OCC_RESP_DATA_BYTES 4089
  10. /*
  11. * Same response format for all OCC versions.
  12. * Allocate the largest possible response.
  13. */
  14. struct occ_response {
  15. u8 seq_no;
  16. u8 cmd_type;
  17. u8 return_status;
  18. __be16 data_length;
  19. u8 data[OCC_RESP_DATA_BYTES];
  20. __be16 checksum;
  21. } __packed;
  22. struct occ_sensor_data_block_header {
  23. u8 eye_catcher[4];
  24. u8 reserved;
  25. u8 sensor_format;
  26. u8 sensor_length;
  27. u8 num_sensors;
  28. } __packed;
  29. struct occ_sensor_data_block {
  30. struct occ_sensor_data_block_header header;
  31. u32 data;
  32. } __packed;
  33. struct occ_poll_response_header {
  34. u8 status;
  35. u8 ext_status;
  36. u8 occs_present;
  37. u8 config_data;
  38. u8 occ_state;
  39. u8 mode;
  40. u8 ips_status;
  41. u8 error_log_id;
  42. __be32 error_log_start_address;
  43. __be16 error_log_length;
  44. u16 reserved;
  45. u8 occ_code_level[16];
  46. u8 eye_catcher[6];
  47. u8 num_sensor_data_blocks;
  48. u8 sensor_data_block_header_version;
  49. } __packed;
  50. struct occ_poll_response {
  51. struct occ_poll_response_header header;
  52. struct occ_sensor_data_block block;
  53. } __packed;
  54. struct occ_sensor {
  55. u8 num_sensors;
  56. u8 version;
  57. void *data; /* pointer to sensor data start within response */
  58. };
  59. /*
  60. * OCC only provides one sensor data block of each type, but any number of
  61. * sensors within that block.
  62. */
  63. struct occ_sensors {
  64. struct occ_sensor temp;
  65. struct occ_sensor freq;
  66. struct occ_sensor power;
  67. struct occ_sensor caps;
  68. struct occ_sensor extended;
  69. };
  70. /*
  71. * Use our own attribute struct so we can dynamically allocate space for the
  72. * name.
  73. */
  74. struct occ_attribute {
  75. char name[32];
  76. struct sensor_device_attribute_2 sensor;
  77. };
  78. struct occ {
  79. struct device *bus_dev;
  80. struct occ_response resp;
  81. struct occ_sensors sensors;
  82. int powr_sample_time_us; /* average power sample time */
  83. u8 poll_cmd_data; /* to perform OCC poll command */
  84. int (*send_cmd)(struct occ *occ, u8 *cmd, size_t len, void *resp,
  85. size_t resp_len);
  86. unsigned long next_update;
  87. struct mutex lock; /* lock OCC access */
  88. struct device *hwmon;
  89. struct occ_attribute *attrs;
  90. struct attribute_group group;
  91. const struct attribute_group *groups[2];
  92. bool active;
  93. int error; /* final transfer error after retry */
  94. int last_error; /* latest transfer error */
  95. unsigned int error_count; /* number of xfr errors observed */
  96. unsigned long last_safe; /* time OCC entered "safe" state */
  97. /*
  98. * Store the previous state data for comparison in order to notify
  99. * sysfs readers of state changes.
  100. */
  101. int prev_error;
  102. u8 prev_stat;
  103. u8 prev_ext_stat;
  104. u8 prev_occs_present;
  105. u8 prev_ips_status;
  106. u8 prev_mode;
  107. };
  108. int occ_active(struct occ *occ, bool active);
  109. int occ_setup(struct occ *occ);
  110. int occ_setup_sysfs(struct occ *occ);
  111. void occ_shutdown(struct occ *occ);
  112. void occ_shutdown_sysfs(struct occ *occ);
  113. void occ_sysfs_poll_done(struct occ *occ);
  114. int occ_update_response(struct occ *occ);
  115. #endif /* OCC_COMMON_H */