kcs_bmc.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2015-2018, Intel Corporation.
  4. */
  5. #ifndef __KCS_BMC_H__
  6. #define __KCS_BMC_H__
  7. #include <linux/miscdevice.h>
  8. /* Different phases of the KCS BMC module.
  9. * KCS_PHASE_IDLE:
  10. * BMC should not be expecting nor sending any data.
  11. * KCS_PHASE_WRITE_START:
  12. * BMC is receiving a WRITE_START command from system software.
  13. * KCS_PHASE_WRITE_DATA:
  14. * BMC is receiving a data byte from system software.
  15. * KCS_PHASE_WRITE_END_CMD:
  16. * BMC is waiting a last data byte from system software.
  17. * KCS_PHASE_WRITE_DONE:
  18. * BMC has received the whole request from system software.
  19. * KCS_PHASE_WAIT_READ:
  20. * BMC is waiting the response from the upper IPMI service.
  21. * KCS_PHASE_READ:
  22. * BMC is transferring the response to system software.
  23. * KCS_PHASE_ABORT_ERROR1:
  24. * BMC is waiting error status request from system software.
  25. * KCS_PHASE_ABORT_ERROR2:
  26. * BMC is waiting for idle status afer error from system software.
  27. * KCS_PHASE_ERROR:
  28. * BMC has detected a protocol violation at the interface level.
  29. */
  30. enum kcs_phases {
  31. KCS_PHASE_IDLE,
  32. KCS_PHASE_WRITE_START,
  33. KCS_PHASE_WRITE_DATA,
  34. KCS_PHASE_WRITE_END_CMD,
  35. KCS_PHASE_WRITE_DONE,
  36. KCS_PHASE_WAIT_READ,
  37. KCS_PHASE_READ,
  38. KCS_PHASE_ABORT_ERROR1,
  39. KCS_PHASE_ABORT_ERROR2,
  40. KCS_PHASE_ERROR
  41. };
  42. /* IPMI 2.0 - Table 9-4, KCS Interface Status Codes */
  43. enum kcs_errors {
  44. KCS_NO_ERROR = 0x00,
  45. KCS_ABORTED_BY_COMMAND = 0x01,
  46. KCS_ILLEGAL_CONTROL_CODE = 0x02,
  47. KCS_LENGTH_ERROR = 0x06,
  48. KCS_UNSPECIFIED_ERROR = 0xFF
  49. };
  50. /* IPMI 2.0 - 9.5, KCS Interface Registers
  51. * @idr: Input Data Register
  52. * @odr: Output Data Register
  53. * @str: Status Register
  54. */
  55. struct kcs_ioreg {
  56. u32 idr;
  57. u32 odr;
  58. u32 str;
  59. };
  60. struct kcs_bmc {
  61. spinlock_t lock;
  62. u32 channel;
  63. int running;
  64. /* Setup by BMC KCS controller driver */
  65. struct kcs_ioreg ioreg;
  66. u8 (*io_inputb)(struct kcs_bmc *kcs_bmc, u32 reg);
  67. void (*io_outputb)(struct kcs_bmc *kcs_bmc, u32 reg, u8 b);
  68. enum kcs_phases phase;
  69. enum kcs_errors error;
  70. wait_queue_head_t queue;
  71. bool data_in_avail;
  72. int data_in_idx;
  73. u8 *data_in;
  74. int data_out_idx;
  75. int data_out_len;
  76. u8 *data_out;
  77. struct mutex mutex;
  78. u8 *kbuffer;
  79. struct miscdevice miscdev;
  80. unsigned long priv[];
  81. };
  82. static inline void *kcs_bmc_priv(struct kcs_bmc *kcs_bmc)
  83. {
  84. return kcs_bmc->priv;
  85. }
  86. int kcs_bmc_handle_event(struct kcs_bmc *kcs_bmc);
  87. struct kcs_bmc *kcs_bmc_alloc(struct device *dev, int sizeof_priv,
  88. u32 channel);
  89. #endif /* __KCS_BMC_H__ */