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