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 * struct cxl_features_state - The Features state for the device 72 * @cxlds: Pointer to CXL device state 73 * @entries: CXl feature entry context 74 * @num_features: total Features supported by the device 75 * @ent: Flex array of Feature detail entries from the device 76 */ 77 struct cxl_features_state { 78 struct cxl_dev_state *cxlds; 79 struct cxl_feat_entries { 80 int num_features; 81 struct cxl_feat_entry ent[] __counted_by(num_features); 82 } *entries; 83 }; 84 85 #ifdef CONFIG_CXL_FEATURES 86 inline struct cxl_features_state *to_cxlfs(struct cxl_dev_state *cxlds); 87 int devm_cxl_setup_features(struct cxl_dev_state *cxlds); 88 #else 89 static inline struct cxl_features_state *to_cxlfs(struct cxl_dev_state *cxlds) 90 { 91 return NULL; 92 } 93 94 static inline int devm_cxl_setup_features(struct cxl_dev_state *cxlds) 95 { 96 return -EOPNOTSUPP; 97 } 98 #endif 99 100 #endif 101