Skip to content

Commit 5e5ac21

Browse files
shijujose4davejiang
authored andcommitted
cxl/mbox: Add GET_FEATURE mailbox command
Add support for GET_FEATURE mailbox command. CXL spec r3.2 section 8.2.9.6 describes optional device specific features. The settings of a feature can be retrieved using Get Feature command. CXL spec r3.2 section 8.2.9.6.2 describes Get Feature command. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Li Ming <ming.li@zohomail.com> Reviewed-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Shiju Jose <shiju.jose@huawei.com> Link: https://patch.msgid.link/20250220194438.2281088-5-dave.jiang@intel.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent 44818d3 commit 5e5ac21

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

drivers/cxl/core/core.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,11 @@ bool cxl_need_node_perf_attrs_update(int nid);
117117
int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port,
118118
struct access_coordinate *c);
119119

120+
#ifdef CONFIG_CXL_FEATURES
121+
size_t cxl_get_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid,
122+
enum cxl_get_feat_selection selection,
123+
void *feat_out, size_t feat_out_size, u16 offset,
124+
u16 *return_code);
125+
#endif
126+
120127
#endif /* __CXL_CORE_H__ */

drivers/cxl/core/features.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <cxl/mailbox.h>
55
#include <cxl/features.h>
66
#include "cxl.h"
7+
#include "core.h"
78
#include "cxlmem.h"
89

910
inline struct cxl_features_state *to_cxlfs(struct cxl_dev_state *cxlds)
@@ -173,3 +174,52 @@ int devm_cxl_setup_features(struct cxl_dev_state *cxlds)
173174
return devm_add_action_or_reset(cxlds->dev, free_cxlfs, no_free_ptr(cxlfs));
174175
}
175176
EXPORT_SYMBOL_NS_GPL(devm_cxl_setup_features, "CXL");
177+
178+
size_t cxl_get_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid,
179+
enum cxl_get_feat_selection selection,
180+
void *feat_out, size_t feat_out_size, u16 offset,
181+
u16 *return_code)
182+
{
183+
size_t data_to_rd_size, size_out;
184+
struct cxl_mbox_get_feat_in pi;
185+
struct cxl_mbox_cmd mbox_cmd;
186+
size_t data_rcvd_size = 0;
187+
int rc;
188+
189+
if (return_code)
190+
*return_code = CXL_MBOX_CMD_RC_INPUT;
191+
192+
if (!feat_out || !feat_out_size)
193+
return 0;
194+
195+
size_out = min(feat_out_size, cxl_mbox->payload_size);
196+
uuid_copy(&pi.uuid, feat_uuid);
197+
pi.selection = selection;
198+
do {
199+
data_to_rd_size = min(feat_out_size - data_rcvd_size,
200+
cxl_mbox->payload_size);
201+
pi.offset = cpu_to_le16(offset + data_rcvd_size);
202+
pi.count = cpu_to_le16(data_to_rd_size);
203+
204+
mbox_cmd = (struct cxl_mbox_cmd) {
205+
.opcode = CXL_MBOX_OP_GET_FEATURE,
206+
.size_in = sizeof(pi),
207+
.payload_in = &pi,
208+
.size_out = size_out,
209+
.payload_out = feat_out + data_rcvd_size,
210+
.min_out = data_to_rd_size,
211+
};
212+
rc = cxl_internal_send_cmd(cxl_mbox, &mbox_cmd);
213+
if (rc < 0 || !mbox_cmd.size_out) {
214+
if (return_code)
215+
*return_code = mbox_cmd.return_code;
216+
return 0;
217+
}
218+
data_rcvd_size += mbox_cmd.size_out;
219+
} while (data_rcvd_size < feat_out_size);
220+
221+
if (return_code)
222+
*return_code = CXL_MBOX_CMD_RC_SUCCESS;
223+
224+
return data_rcvd_size;
225+
}

include/cxl/features.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,29 @@ struct cxl_mbox_get_sup_feats_out {
6767
struct cxl_feat_entry ents[] __counted_by_le(num_entries);
6868
} __packed;
6969

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+
7093
/**
7194
* struct cxl_features_state - The Features state for the device
7295
* @cxlds: Pointer to CXL device state
@@ -82,6 +105,7 @@ struct cxl_features_state {
82105
} *entries;
83106
};
84107

108+
struct cxl_mailbox;
85109
#ifdef CONFIG_CXL_FEATURES
86110
inline struct cxl_features_state *to_cxlfs(struct cxl_dev_state *cxlds);
87111
int devm_cxl_setup_features(struct cxl_dev_state *cxlds);

0 commit comments

Comments
 (0)