xref: /linux/include/cxl/features.h (revision 5e5ac21f629de796ab5d598b59c5e468c6fe4f95)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright(c) 2024-2025 Intel Corporation. */
3 #ifndef __CXL_FEATURES_H__
4 #define __CXL_FEATURES_H__
5 
6 #include <linux/uuid.h>
7 
8 /* Feature commands capability supported by a device */
9 enum cxl_features_capability {
10 	CXL_FEATURES_NONE = 0,
11 	CXL_FEATURES_RO,
12 	CXL_FEATURES_RW,
13 };
14 
15 /* Get Supported Features (0x500h) CXL r3.2 8.2.9.6.1 */
16 struct cxl_mbox_get_sup_feats_in {
17 	__le32 count;
18 	__le16 start_idx;
19 	u8 reserved[2];
20 } __packed;
21 
22 /* CXL spec r3.2 Table 8-87 command effects */
23 #define CXL_CMD_CONFIG_CHANGE_COLD_RESET	BIT(0)
24 #define CXL_CMD_CONFIG_CHANGE_IMMEDIATE		BIT(1)
25 #define CXL_CMD_DATA_CHANGE_IMMEDIATE		BIT(2)
26 #define CXL_CMD_POLICY_CHANGE_IMMEDIATE		BIT(3)
27 #define CXL_CMD_LOG_CHANGE_IMMEDIATE		BIT(4)
28 #define CXL_CMD_SECURITY_STATE_CHANGE		BIT(5)
29 #define CXL_CMD_BACKGROUND			BIT(6)
30 #define CXL_CMD_BGCMD_ABORT_SUPPORTED		BIT(7)
31 #define CXL_CMD_EFFECTS_VALID			BIT(9)
32 #define CXL_CMD_CONFIG_CHANGE_CONV_RESET	BIT(10)
33 #define CXL_CMD_CONFIG_CHANGE_CXL_RESET		BIT(11)
34 
35 /*
36  * CXL spec r3.2 Table 8-109
37  * Get Supported Features Supported Feature Entry
38  */
39 struct cxl_feat_entry {
40 	uuid_t uuid;
41 	__le16 id;
42 	__le16 get_feat_size;
43 	__le16 set_feat_size;
44 	__le32 flags;
45 	u8 get_feat_ver;
46 	u8 set_feat_ver;
47 	__le16 effects;
48 	u8 reserved[18];
49 } __packed;
50 
51 /* @flags field for 'struct cxl_feat_entry' */
52 #define CXL_FEATURE_F_CHANGEABLE		BIT(0)
53 #define CXL_FEATURE_F_PERSIST_FW_UPDATE		BIT(4)
54 #define CXL_FEATURE_F_DEFAULT_SEL		BIT(5)
55 #define CXL_FEATURE_F_SAVED_SEL			BIT(6)
56 
57 /*
58  * CXL spec r3.2 Table 8-108
59  * Get supported Features Output Payload
60  */
61 struct cxl_mbox_get_sup_feats_out {
62 	__struct_group(cxl_mbox_get_sup_feats_out_hdr, hdr, /* no attrs */,
63 		__le16 num_entries;
64 		__le16 supported_feats;
65 		__u8 reserved[4];
66 	);
67 	struct cxl_feat_entry ents[] __counted_by_le(num_entries);
68 } __packed;
69 
70 /*
71  * Get Feature CXL spec r3.2 Spec 8.2.9.6.2
72  */
73 
74 /*
75  * Get Feature input payload
76  * CXL spec r3.2 section 8.2.9.6.2 Table 8-99
77  */
78 struct cxl_mbox_get_feat_in {
79 	uuid_t uuid;
80 	__le16 offset;
81 	__le16 count;
82 	u8 selection;
83 }  __packed;
84 
85 /* Selection field for 'struct cxl_mbox_get_feat_in' */
86 enum cxl_get_feat_selection {
87 	CXL_GET_FEAT_SEL_CURRENT_VALUE,
88 	CXL_GET_FEAT_SEL_DEFAULT_VALUE,
89 	CXL_GET_FEAT_SEL_SAVED_VALUE,
90 	CXL_GET_FEAT_SEL_MAX
91 };
92 
93 /**
94  * struct cxl_features_state - The Features state for the device
95  * @cxlds: Pointer to CXL device state
96  * @entries: CXl feature entry context
97  *	@num_features: total Features supported by the device
98  *	@ent: Flex array of Feature detail entries from the device
99  */
100 struct cxl_features_state {
101 	struct cxl_dev_state *cxlds;
102 	struct cxl_feat_entries {
103 		int num_features;
104 		struct cxl_feat_entry ent[] __counted_by(num_features);
105 	} *entries;
106 };
107 
108 struct cxl_mailbox;
109 #ifdef CONFIG_CXL_FEATURES
110 inline struct cxl_features_state *to_cxlfs(struct cxl_dev_state *cxlds);
111 int devm_cxl_setup_features(struct cxl_dev_state *cxlds);
112 #else
113 static inline struct cxl_features_state *to_cxlfs(struct cxl_dev_state *cxlds)
114 {
115 	return NULL;
116 }
117 
118 static inline int devm_cxl_setup_features(struct cxl_dev_state *cxlds)
119 {
120 	return -EOPNOTSUPP;
121 }
122 #endif
123 
124 #endif
125