mailbox.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright(c) 2024 Intel Corporation. */
  3. #ifndef __CXL_MBOX_H__
  4. #define __CXL_MBOX_H__
  5. #include <linux/rcuwait.h>
  6. #include <cxl/features.h>
  7. #include <uapi/linux/cxl_mem.h>
  8. /**
  9. * struct cxl_mbox_cmd - A command to be submitted to hardware.
  10. * @opcode: (input) The command set and command submitted to hardware.
  11. * @payload_in: (input) Pointer to the input payload.
  12. * @payload_out: (output) Pointer to the output payload. Must be allocated by
  13. * the caller.
  14. * @size_in: (input) Number of bytes to load from @payload_in.
  15. * @size_out: (input) Max number of bytes loaded into @payload_out.
  16. * (output) Number of bytes generated by the device. For fixed size
  17. * outputs commands this is always expected to be deterministic. For
  18. * variable sized output commands, it tells the exact number of bytes
  19. * written.
  20. * @min_out: (input) internal command output payload size validation
  21. * @poll_count: (input) Number of timeouts to attempt.
  22. * @poll_interval_ms: (input) Time between mailbox background command polling
  23. * interval timeouts.
  24. * @return_code: (output) Error code returned from hardware.
  25. *
  26. * This is the primary mechanism used to send commands to the hardware.
  27. * All the fields except @payload_* correspond exactly to the fields described in
  28. * Command Register section of the CXL 2.0 8.2.8.4.5. @payload_in and
  29. * @payload_out are written to, and read from the Command Payload Registers
  30. * defined in CXL 2.0 8.2.8.4.8.
  31. */
  32. struct cxl_mbox_cmd {
  33. u16 opcode;
  34. void *payload_in;
  35. void *payload_out;
  36. size_t size_in;
  37. size_t size_out;
  38. size_t min_out;
  39. int poll_count;
  40. int poll_interval_ms;
  41. u16 return_code;
  42. };
  43. /**
  44. * struct cxl_mailbox - context for CXL mailbox operations
  45. * @host: device that hosts the mailbox
  46. * @enabled_cmds: mailbox commands that are enabled by the driver
  47. * @exclusive_cmds: mailbox commands that are exclusive to the kernel
  48. * @payload_size: Size of space for payload
  49. * (CXL 3.1 8.2.8.4.3 Mailbox Capabilities Register)
  50. * @mbox_mutex: mutex protects device mailbox and firmware
  51. * @mbox_wait: rcuwait for mailbox
  52. * @mbox_send: @dev specific transport for transmitting mailbox commands
  53. * @feat_cap: Features capability
  54. */
  55. struct cxl_mailbox {
  56. struct device *host;
  57. DECLARE_BITMAP(enabled_cmds, CXL_MEM_COMMAND_ID_MAX);
  58. DECLARE_BITMAP(exclusive_cmds, CXL_MEM_COMMAND_ID_MAX);
  59. size_t payload_size;
  60. struct mutex mbox_mutex; /* lock to protect mailbox context */
  61. struct rcuwait mbox_wait;
  62. int (*mbox_send)(struct cxl_mailbox *cxl_mbox, struct cxl_mbox_cmd *cmd);
  63. enum cxl_features_capability feat_cap;
  64. };
  65. int cxl_mailbox_init(struct cxl_mailbox *cxl_mbox, struct device *host);
  66. #endif