]> Git Repo - linux.git/blob - drivers/cxl/cxlmem.h
arm64: avoid prototype warnings for syscalls
[linux.git] / drivers / cxl / cxlmem.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright(c) 2020-2021 Intel Corporation. */
3 #ifndef __CXL_MEM_H__
4 #define __CXL_MEM_H__
5 #include <uapi/linux/cxl_mem.h>
6 #include <linux/cdev.h>
7 #include <linux/uuid.h>
8 #include "cxl.h"
9
10 /* CXL 2.0 8.2.8.5.1.1 Memory Device Status Register */
11 #define CXLMDEV_STATUS_OFFSET 0x0
12 #define   CXLMDEV_DEV_FATAL BIT(0)
13 #define   CXLMDEV_FW_HALT BIT(1)
14 #define   CXLMDEV_STATUS_MEDIA_STATUS_MASK GENMASK(3, 2)
15 #define     CXLMDEV_MS_NOT_READY 0
16 #define     CXLMDEV_MS_READY 1
17 #define     CXLMDEV_MS_ERROR 2
18 #define     CXLMDEV_MS_DISABLED 3
19 #define CXLMDEV_READY(status)                                                  \
20         (FIELD_GET(CXLMDEV_STATUS_MEDIA_STATUS_MASK, status) ==                \
21          CXLMDEV_MS_READY)
22 #define   CXLMDEV_MBOX_IF_READY BIT(4)
23 #define   CXLMDEV_RESET_NEEDED_MASK GENMASK(7, 5)
24 #define     CXLMDEV_RESET_NEEDED_NOT 0
25 #define     CXLMDEV_RESET_NEEDED_COLD 1
26 #define     CXLMDEV_RESET_NEEDED_WARM 2
27 #define     CXLMDEV_RESET_NEEDED_HOT 3
28 #define     CXLMDEV_RESET_NEEDED_CXL 4
29 #define CXLMDEV_RESET_NEEDED(status)                                           \
30         (FIELD_GET(CXLMDEV_RESET_NEEDED_MASK, status) !=                       \
31          CXLMDEV_RESET_NEEDED_NOT)
32
33 /**
34  * struct cxl_memdev - CXL bus object representing a Type-3 Memory Device
35  * @dev: driver core device object
36  * @cdev: char dev core object for ioctl operations
37  * @cxlds: The device state backing this device
38  * @detach_work: active memdev lost a port in its ancestry
39  * @cxl_nvb: coordinate removal of @cxl_nvd if present
40  * @cxl_nvd: optional bridge to an nvdimm if the device supports pmem
41  * @id: id number of this memdev instance.
42  * @depth: endpoint port depth
43  */
44 struct cxl_memdev {
45         struct device dev;
46         struct cdev cdev;
47         struct cxl_dev_state *cxlds;
48         struct work_struct detach_work;
49         struct cxl_nvdimm_bridge *cxl_nvb;
50         struct cxl_nvdimm *cxl_nvd;
51         int id;
52         int depth;
53 };
54
55 static inline struct cxl_memdev *to_cxl_memdev(struct device *dev)
56 {
57         return container_of(dev, struct cxl_memdev, dev);
58 }
59
60 static inline struct cxl_port *cxled_to_port(struct cxl_endpoint_decoder *cxled)
61 {
62         return to_cxl_port(cxled->cxld.dev.parent);
63 }
64
65 static inline struct cxl_port *cxlrd_to_port(struct cxl_root_decoder *cxlrd)
66 {
67         return to_cxl_port(cxlrd->cxlsd.cxld.dev.parent);
68 }
69
70 static inline struct cxl_memdev *
71 cxled_to_memdev(struct cxl_endpoint_decoder *cxled)
72 {
73         struct cxl_port *port = to_cxl_port(cxled->cxld.dev.parent);
74
75         return to_cxl_memdev(port->uport);
76 }
77
78 bool is_cxl_memdev(const struct device *dev);
79 static inline bool is_cxl_endpoint(struct cxl_port *port)
80 {
81         return is_cxl_memdev(port->uport);
82 }
83
84 struct cxl_memdev *devm_cxl_add_memdev(struct cxl_dev_state *cxlds);
85 int devm_cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled,
86                          resource_size_t base, resource_size_t len,
87                          resource_size_t skipped);
88
89 static inline struct cxl_ep *cxl_ep_load(struct cxl_port *port,
90                                          struct cxl_memdev *cxlmd)
91 {
92         if (!port)
93                 return NULL;
94
95         return xa_load(&port->endpoints, (unsigned long)&cxlmd->dev);
96 }
97
98 /**
99  * struct cxl_mbox_cmd - A command to be submitted to hardware.
100  * @opcode: (input) The command set and command submitted to hardware.
101  * @payload_in: (input) Pointer to the input payload.
102  * @payload_out: (output) Pointer to the output payload. Must be allocated by
103  *               the caller.
104  * @size_in: (input) Number of bytes to load from @payload_in.
105  * @size_out: (input) Max number of bytes loaded into @payload_out.
106  *            (output) Number of bytes generated by the device. For fixed size
107  *            outputs commands this is always expected to be deterministic. For
108  *            variable sized output commands, it tells the exact number of bytes
109  *            written.
110  * @min_out: (input) internal command output payload size validation
111  * @return_code: (output) Error code returned from hardware.
112  *
113  * This is the primary mechanism used to send commands to the hardware.
114  * All the fields except @payload_* correspond exactly to the fields described in
115  * Command Register section of the CXL 2.0 8.2.8.4.5. @payload_in and
116  * @payload_out are written to, and read from the Command Payload Registers
117  * defined in CXL 2.0 8.2.8.4.8.
118  */
119 struct cxl_mbox_cmd {
120         u16 opcode;
121         void *payload_in;
122         void *payload_out;
123         size_t size_in;
124         size_t size_out;
125         size_t min_out;
126         u16 return_code;
127 };
128
129 /*
130  * Per CXL 3.0 Section 8.2.8.4.5.1
131  */
132 #define CMD_CMD_RC_TABLE                                                        \
133         C(SUCCESS, 0, NULL),                                                    \
134         C(BACKGROUND, -ENXIO, "background cmd started successfully"),           \
135         C(INPUT, -ENXIO, "cmd input was invalid"),                              \
136         C(UNSUPPORTED, -ENXIO, "cmd is not supported"),                         \
137         C(INTERNAL, -ENXIO, "internal device error"),                           \
138         C(RETRY, -ENXIO, "temporary error, retry once"),                        \
139         C(BUSY, -ENXIO, "ongoing background operation"),                        \
140         C(MEDIADISABLED, -ENXIO, "media access is disabled"),                   \
141         C(FWINPROGRESS, -ENXIO, "one FW package can be transferred at a time"), \
142         C(FWOOO, -ENXIO, "FW package content was transferred out of order"),    \
143         C(FWAUTH, -ENXIO, "FW package authentication failed"),                  \
144         C(FWSLOT, -ENXIO, "FW slot is not supported for requested operation"),  \
145         C(FWROLLBACK, -ENXIO, "rolled back to the previous active FW"),         \
146         C(FWRESET, -ENXIO, "FW failed to activate, needs cold reset"),          \
147         C(HANDLE, -ENXIO, "one or more Event Record Handles were invalid"),     \
148         C(PADDR, -EFAULT, "physical address specified is invalid"),             \
149         C(POISONLMT, -ENXIO, "poison injection limit has been reached"),        \
150         C(MEDIAFAILURE, -ENXIO, "permanent issue with the media"),              \
151         C(ABORT, -ENXIO, "background cmd was aborted by device"),               \
152         C(SECURITY, -ENXIO, "not valid in the current security state"),         \
153         C(PASSPHRASE, -ENXIO, "phrase doesn't match current set passphrase"),   \
154         C(MBUNSUPPORTED, -ENXIO, "unsupported on the mailbox it was issued on"),\
155         C(PAYLOADLEN, -ENXIO, "invalid payload length"),                        \
156         C(LOG, -ENXIO, "invalid or unsupported log page"),                      \
157         C(INTERRUPTED, -ENXIO, "asynchronous event occured"),                   \
158         C(FEATUREVERSION, -ENXIO, "unsupported feature version"),               \
159         C(FEATURESELVALUE, -ENXIO, "unsupported feature selection value"),      \
160         C(FEATURETRANSFERIP, -ENXIO, "feature transfer in progress"),           \
161         C(FEATURETRANSFEROOO, -ENXIO, "feature transfer out of order"),         \
162         C(RESOURCEEXHAUSTED, -ENXIO, "resources are exhausted"),                \
163         C(EXTLIST, -ENXIO, "invalid Extent List"),                              \
164
165 #undef C
166 #define C(a, b, c) CXL_MBOX_CMD_RC_##a
167 enum  { CMD_CMD_RC_TABLE };
168 #undef C
169 #define C(a, b, c) { b, c }
170 struct cxl_mbox_cmd_rc {
171         int err;
172         const char *desc;
173 };
174
175 static const
176 struct cxl_mbox_cmd_rc cxl_mbox_cmd_rctable[] ={ CMD_CMD_RC_TABLE };
177 #undef C
178
179 static inline const char *cxl_mbox_cmd_rc2str(struct cxl_mbox_cmd *mbox_cmd)
180 {
181         return cxl_mbox_cmd_rctable[mbox_cmd->return_code].desc;
182 }
183
184 static inline int cxl_mbox_cmd_rc2errno(struct cxl_mbox_cmd *mbox_cmd)
185 {
186         return cxl_mbox_cmd_rctable[mbox_cmd->return_code].err;
187 }
188
189 /*
190  * CXL 2.0 - Memory capacity multiplier
191  * See Section 8.2.9.5
192  *
193  * Volatile, Persistent, and Partition capacities are specified to be in
194  * multiples of 256MB - define a multiplier to convert to/from bytes.
195  */
196 #define CXL_CAPACITY_MULTIPLIER SZ_256M
197
198 /**
199  * Event Interrupt Policy
200  *
201  * CXL rev 3.0 section 8.2.9.2.4; Table 8-52
202  */
203 enum cxl_event_int_mode {
204         CXL_INT_NONE            = 0x00,
205         CXL_INT_MSI_MSIX        = 0x01,
206         CXL_INT_FW              = 0x02
207 };
208 struct cxl_event_interrupt_policy {
209         u8 info_settings;
210         u8 warn_settings;
211         u8 failure_settings;
212         u8 fatal_settings;
213 } __packed;
214
215 /**
216  * struct cxl_event_state - Event log driver state
217  *
218  * @event_buf: Buffer to receive event data
219  * @event_log_lock: Serialize event_buf and log use
220  */
221 struct cxl_event_state {
222         struct cxl_get_event_payload *buf;
223         struct mutex log_lock;
224 };
225
226 /* Device enabled poison commands */
227 enum poison_cmd_enabled_bits {
228         CXL_POISON_ENABLED_LIST,
229         CXL_POISON_ENABLED_INJECT,
230         CXL_POISON_ENABLED_CLEAR,
231         CXL_POISON_ENABLED_SCAN_CAPS,
232         CXL_POISON_ENABLED_SCAN_MEDIA,
233         CXL_POISON_ENABLED_SCAN_RESULTS,
234         CXL_POISON_ENABLED_MAX
235 };
236
237 /**
238  * struct cxl_poison_state - Driver poison state info
239  *
240  * @max_errors: Maximum media error records held in device cache
241  * @enabled_cmds: All poison commands enabled in the CEL
242  * @list_out: The poison list payload returned by device
243  * @lock: Protect reads of the poison list
244  *
245  * Reads of the poison list are synchronized to ensure that a reader
246  * does not get an incomplete list because their request overlapped
247  * (was interrupted or preceded by) another read request of the same
248  * DPA range. CXL Spec 3.0 Section 8.2.9.8.4.1
249  */
250 struct cxl_poison_state {
251         u32 max_errors;
252         DECLARE_BITMAP(enabled_cmds, CXL_POISON_ENABLED_MAX);
253         struct cxl_mbox_poison_out *list_out;
254         struct mutex lock;  /* Protect reads of poison list */
255 };
256
257 /**
258  * struct cxl_dev_state - The driver device state
259  *
260  * cxl_dev_state represents the CXL driver/device state.  It provides an
261  * interface to mailbox commands as well as some cached data about the device.
262  * Currently only memory devices are represented.
263  *
264  * @dev: The device associated with this CXL state
265  * @cxlmd: The device representing the CXL.mem capabilities of @dev
266  * @regs: Parsed register blocks
267  * @cxl_dvsec: Offset to the PCIe device DVSEC
268  * @rcd: operating in RCD mode (CXL 3.0 9.11.8 CXL Devices Attached to an RCH)
269  * @payload_size: Size of space for payload
270  *                (CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register)
271  * @lsa_size: Size of Label Storage Area
272  *                (CXL 2.0 8.2.9.5.1.1 Identify Memory Device)
273  * @mbox_mutex: Mutex to synchronize mailbox access.
274  * @firmware_version: Firmware version for the memory device.
275  * @enabled_cmds: Hardware commands found enabled in CEL.
276  * @exclusive_cmds: Commands that are kernel-internal only
277  * @dpa_res: Overall DPA resource tree for the device
278  * @pmem_res: Active Persistent memory capacity configuration
279  * @ram_res: Active Volatile memory capacity configuration
280  * @total_bytes: sum of all possible capacities
281  * @volatile_only_bytes: hard volatile capacity
282  * @persistent_only_bytes: hard persistent capacity
283  * @partition_align_bytes: alignment size for partition-able capacity
284  * @active_volatile_bytes: sum of hard + soft volatile
285  * @active_persistent_bytes: sum of hard + soft persistent
286  * @next_volatile_bytes: volatile capacity change pending device reset
287  * @next_persistent_bytes: persistent capacity change pending device reset
288  * @component_reg_phys: register base of component registers
289  * @info: Cached DVSEC information about the device.
290  * @serial: PCIe Device Serial Number
291  * @event: event log driver state
292  * @poison: poison driver state info
293  * @mbox_send: @dev specific transport for transmitting mailbox commands
294  *
295  * See section 8.2.9.5.2 Capacity Configuration and Label Storage for
296  * details on capacity parameters.
297  */
298 struct cxl_dev_state {
299         struct device *dev;
300         struct cxl_memdev *cxlmd;
301
302         struct cxl_regs regs;
303         int cxl_dvsec;
304
305         bool rcd;
306         size_t payload_size;
307         size_t lsa_size;
308         struct mutex mbox_mutex; /* Protects device mailbox and firmware */
309         char firmware_version[0x10];
310         DECLARE_BITMAP(enabled_cmds, CXL_MEM_COMMAND_ID_MAX);
311         DECLARE_BITMAP(exclusive_cmds, CXL_MEM_COMMAND_ID_MAX);
312
313         struct resource dpa_res;
314         struct resource pmem_res;
315         struct resource ram_res;
316         u64 total_bytes;
317         u64 volatile_only_bytes;
318         u64 persistent_only_bytes;
319         u64 partition_align_bytes;
320
321         u64 active_volatile_bytes;
322         u64 active_persistent_bytes;
323         u64 next_volatile_bytes;
324         u64 next_persistent_bytes;
325
326         resource_size_t component_reg_phys;
327         u64 serial;
328
329         struct cxl_event_state event;
330         struct cxl_poison_state poison;
331
332         int (*mbox_send)(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd);
333 };
334
335 enum cxl_opcode {
336         CXL_MBOX_OP_INVALID             = 0x0000,
337         CXL_MBOX_OP_RAW                 = CXL_MBOX_OP_INVALID,
338         CXL_MBOX_OP_GET_EVENT_RECORD    = 0x0100,
339         CXL_MBOX_OP_CLEAR_EVENT_RECORD  = 0x0101,
340         CXL_MBOX_OP_GET_EVT_INT_POLICY  = 0x0102,
341         CXL_MBOX_OP_SET_EVT_INT_POLICY  = 0x0103,
342         CXL_MBOX_OP_GET_FW_INFO         = 0x0200,
343         CXL_MBOX_OP_ACTIVATE_FW         = 0x0202,
344         CXL_MBOX_OP_SET_TIMESTAMP       = 0x0301,
345         CXL_MBOX_OP_GET_SUPPORTED_LOGS  = 0x0400,
346         CXL_MBOX_OP_GET_LOG             = 0x0401,
347         CXL_MBOX_OP_IDENTIFY            = 0x4000,
348         CXL_MBOX_OP_GET_PARTITION_INFO  = 0x4100,
349         CXL_MBOX_OP_SET_PARTITION_INFO  = 0x4101,
350         CXL_MBOX_OP_GET_LSA             = 0x4102,
351         CXL_MBOX_OP_SET_LSA             = 0x4103,
352         CXL_MBOX_OP_GET_HEALTH_INFO     = 0x4200,
353         CXL_MBOX_OP_GET_ALERT_CONFIG    = 0x4201,
354         CXL_MBOX_OP_SET_ALERT_CONFIG    = 0x4202,
355         CXL_MBOX_OP_GET_SHUTDOWN_STATE  = 0x4203,
356         CXL_MBOX_OP_SET_SHUTDOWN_STATE  = 0x4204,
357         CXL_MBOX_OP_GET_POISON          = 0x4300,
358         CXL_MBOX_OP_INJECT_POISON       = 0x4301,
359         CXL_MBOX_OP_CLEAR_POISON        = 0x4302,
360         CXL_MBOX_OP_GET_SCAN_MEDIA_CAPS = 0x4303,
361         CXL_MBOX_OP_SCAN_MEDIA          = 0x4304,
362         CXL_MBOX_OP_GET_SCAN_MEDIA      = 0x4305,
363         CXL_MBOX_OP_GET_SECURITY_STATE  = 0x4500,
364         CXL_MBOX_OP_SET_PASSPHRASE      = 0x4501,
365         CXL_MBOX_OP_DISABLE_PASSPHRASE  = 0x4502,
366         CXL_MBOX_OP_UNLOCK              = 0x4503,
367         CXL_MBOX_OP_FREEZE_SECURITY     = 0x4504,
368         CXL_MBOX_OP_PASSPHRASE_SECURE_ERASE     = 0x4505,
369         CXL_MBOX_OP_MAX                 = 0x10000
370 };
371
372 #define DEFINE_CXL_CEL_UUID                                                    \
373         UUID_INIT(0xda9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79, 0x96, 0xb1, 0x62,     \
374                   0x3b, 0x3f, 0x17)
375
376 #define DEFINE_CXL_VENDOR_DEBUG_UUID                                           \
377         UUID_INIT(0xe1819d9, 0x11a9, 0x400c, 0x81, 0x1f, 0xd6, 0x07, 0x19,     \
378                   0x40, 0x3d, 0x86)
379
380 struct cxl_mbox_get_supported_logs {
381         __le16 entries;
382         u8 rsvd[6];
383         struct cxl_gsl_entry {
384                 uuid_t uuid;
385                 __le32 size;
386         } __packed entry[];
387 }  __packed;
388
389 struct cxl_cel_entry {
390         __le16 opcode;
391         __le16 effect;
392 } __packed;
393
394 struct cxl_mbox_get_log {
395         uuid_t uuid;
396         __le32 offset;
397         __le32 length;
398 } __packed;
399
400 /* See CXL 2.0 Table 175 Identify Memory Device Output Payload */
401 struct cxl_mbox_identify {
402         char fw_revision[0x10];
403         __le64 total_capacity;
404         __le64 volatile_capacity;
405         __le64 persistent_capacity;
406         __le64 partition_align;
407         __le16 info_event_log_size;
408         __le16 warning_event_log_size;
409         __le16 failure_event_log_size;
410         __le16 fatal_event_log_size;
411         __le32 lsa_size;
412         u8 poison_list_max_mer[3];
413         __le16 inject_poison_limit;
414         u8 poison_caps;
415         u8 qos_telemetry_caps;
416 } __packed;
417
418 /*
419  * Common Event Record Format
420  * CXL rev 3.0 section 8.2.9.2.1; Table 8-42
421  */
422 struct cxl_event_record_hdr {
423         uuid_t id;
424         u8 length;
425         u8 flags[3];
426         __le16 handle;
427         __le16 related_handle;
428         __le64 timestamp;
429         u8 maint_op_class;
430         u8 reserved[15];
431 } __packed;
432
433 #define CXL_EVENT_RECORD_DATA_LENGTH 0x50
434 struct cxl_event_record_raw {
435         struct cxl_event_record_hdr hdr;
436         u8 data[CXL_EVENT_RECORD_DATA_LENGTH];
437 } __packed;
438
439 /*
440  * Get Event Records output payload
441  * CXL rev 3.0 section 8.2.9.2.2; Table 8-50
442  */
443 #define CXL_GET_EVENT_FLAG_OVERFLOW             BIT(0)
444 #define CXL_GET_EVENT_FLAG_MORE_RECORDS         BIT(1)
445 struct cxl_get_event_payload {
446         u8 flags;
447         u8 reserved1;
448         __le16 overflow_err_count;
449         __le64 first_overflow_timestamp;
450         __le64 last_overflow_timestamp;
451         __le16 record_count;
452         u8 reserved2[10];
453         struct cxl_event_record_raw records[];
454 } __packed;
455
456 /*
457  * CXL rev 3.0 section 8.2.9.2.2; Table 8-49
458  */
459 enum cxl_event_log_type {
460         CXL_EVENT_TYPE_INFO = 0x00,
461         CXL_EVENT_TYPE_WARN,
462         CXL_EVENT_TYPE_FAIL,
463         CXL_EVENT_TYPE_FATAL,
464         CXL_EVENT_TYPE_MAX
465 };
466
467 /*
468  * Clear Event Records input payload
469  * CXL rev 3.0 section 8.2.9.2.3; Table 8-51
470  */
471 struct cxl_mbox_clear_event_payload {
472         u8 event_log;           /* enum cxl_event_log_type */
473         u8 clear_flags;
474         u8 nr_recs;
475         u8 reserved[3];
476         __le16 handles[];
477 } __packed;
478 #define CXL_CLEAR_EVENT_MAX_HANDLES U8_MAX
479
480 /*
481  * General Media Event Record
482  * CXL rev 3.0 Section 8.2.9.2.1.1; Table 8-43
483  */
484 #define CXL_EVENT_GEN_MED_COMP_ID_SIZE  0x10
485 struct cxl_event_gen_media {
486         struct cxl_event_record_hdr hdr;
487         __le64 phys_addr;
488         u8 descriptor;
489         u8 type;
490         u8 transaction_type;
491         u8 validity_flags[2];
492         u8 channel;
493         u8 rank;
494         u8 device[3];
495         u8 component_id[CXL_EVENT_GEN_MED_COMP_ID_SIZE];
496         u8 reserved[46];
497 } __packed;
498
499 /*
500  * DRAM Event Record - DER
501  * CXL rev 3.0 section 8.2.9.2.1.2; Table 3-44
502  */
503 #define CXL_EVENT_DER_CORRECTION_MASK_SIZE      0x20
504 struct cxl_event_dram {
505         struct cxl_event_record_hdr hdr;
506         __le64 phys_addr;
507         u8 descriptor;
508         u8 type;
509         u8 transaction_type;
510         u8 validity_flags[2];
511         u8 channel;
512         u8 rank;
513         u8 nibble_mask[3];
514         u8 bank_group;
515         u8 bank;
516         u8 row[3];
517         u8 column[2];
518         u8 correction_mask[CXL_EVENT_DER_CORRECTION_MASK_SIZE];
519         u8 reserved[0x17];
520 } __packed;
521
522 /*
523  * Get Health Info Record
524  * CXL rev 3.0 section 8.2.9.8.3.1; Table 8-100
525  */
526 struct cxl_get_health_info {
527         u8 health_status;
528         u8 media_status;
529         u8 add_status;
530         u8 life_used;
531         u8 device_temp[2];
532         u8 dirty_shutdown_cnt[4];
533         u8 cor_vol_err_cnt[4];
534         u8 cor_per_err_cnt[4];
535 } __packed;
536
537 /*
538  * Memory Module Event Record
539  * CXL rev 3.0 section 8.2.9.2.1.3; Table 8-45
540  */
541 struct cxl_event_mem_module {
542         struct cxl_event_record_hdr hdr;
543         u8 event_type;
544         struct cxl_get_health_info info;
545         u8 reserved[0x3d];
546 } __packed;
547
548 struct cxl_mbox_get_partition_info {
549         __le64 active_volatile_cap;
550         __le64 active_persistent_cap;
551         __le64 next_volatile_cap;
552         __le64 next_persistent_cap;
553 } __packed;
554
555 struct cxl_mbox_get_lsa {
556         __le32 offset;
557         __le32 length;
558 } __packed;
559
560 struct cxl_mbox_set_lsa {
561         __le32 offset;
562         __le32 reserved;
563         u8 data[];
564 } __packed;
565
566 struct cxl_mbox_set_partition_info {
567         __le64 volatile_capacity;
568         u8 flags;
569 } __packed;
570
571 #define  CXL_SET_PARTITION_IMMEDIATE_FLAG       BIT(0)
572
573 /* Set Timestamp CXL 3.0 Spec 8.2.9.4.2 */
574 struct cxl_mbox_set_timestamp_in {
575         __le64 timestamp;
576
577 } __packed;
578
579 /* Get Poison List  CXL 3.0 Spec 8.2.9.8.4.1 */
580 struct cxl_mbox_poison_in {
581         __le64 offset;
582         __le64 length;
583 } __packed;
584
585 struct cxl_mbox_poison_out {
586         u8 flags;
587         u8 rsvd1;
588         __le64 overflow_ts;
589         __le16 count;
590         u8 rsvd2[20];
591         struct cxl_poison_record {
592                 __le64 address;
593                 __le32 length;
594                 __le32 rsvd;
595         } __packed record[];
596 } __packed;
597
598 /*
599  * Get Poison List address field encodes the starting
600  * address of poison, and the source of the poison.
601  */
602 #define CXL_POISON_START_MASK           GENMASK_ULL(63, 6)
603 #define CXL_POISON_SOURCE_MASK          GENMASK(2, 0)
604
605 /* Get Poison List record length is in units of 64 bytes */
606 #define CXL_POISON_LEN_MULT     64
607
608 /* Kernel defined maximum for a list of poison errors */
609 #define CXL_POISON_LIST_MAX     1024
610
611 /* Get Poison List: Payload out flags */
612 #define CXL_POISON_FLAG_MORE            BIT(0)
613 #define CXL_POISON_FLAG_OVERFLOW        BIT(1)
614 #define CXL_POISON_FLAG_SCANNING        BIT(2)
615
616 /* Get Poison List: Poison Source */
617 #define CXL_POISON_SOURCE_UNKNOWN       0
618 #define CXL_POISON_SOURCE_EXTERNAL      1
619 #define CXL_POISON_SOURCE_INTERNAL      2
620 #define CXL_POISON_SOURCE_INJECTED      3
621 #define CXL_POISON_SOURCE_VENDOR        7
622
623 /* Inject & Clear Poison  CXL 3.0 Spec 8.2.9.8.4.2/3 */
624 struct cxl_mbox_inject_poison {
625         __le64 address;
626 };
627
628 /* Clear Poison  CXL 3.0 Spec 8.2.9.8.4.3 */
629 struct cxl_mbox_clear_poison {
630         __le64 address;
631         u8 write_data[CXL_POISON_LEN_MULT];
632 } __packed;
633
634 /**
635  * struct cxl_mem_command - Driver representation of a memory device command
636  * @info: Command information as it exists for the UAPI
637  * @opcode: The actual bits used for the mailbox protocol
638  * @flags: Set of flags effecting driver behavior.
639  *
640  *  * %CXL_CMD_FLAG_FORCE_ENABLE: In cases of error, commands with this flag
641  *    will be enabled by the driver regardless of what hardware may have
642  *    advertised.
643  *
644  * The cxl_mem_command is the driver's internal representation of commands that
645  * are supported by the driver. Some of these commands may not be supported by
646  * the hardware. The driver will use @info to validate the fields passed in by
647  * the user then submit the @opcode to the hardware.
648  *
649  * See struct cxl_command_info.
650  */
651 struct cxl_mem_command {
652         struct cxl_command_info info;
653         enum cxl_opcode opcode;
654         u32 flags;
655 #define CXL_CMD_FLAG_FORCE_ENABLE BIT(0)
656 };
657
658 #define CXL_PMEM_SEC_STATE_USER_PASS_SET        0x01
659 #define CXL_PMEM_SEC_STATE_MASTER_PASS_SET      0x02
660 #define CXL_PMEM_SEC_STATE_LOCKED               0x04
661 #define CXL_PMEM_SEC_STATE_FROZEN               0x08
662 #define CXL_PMEM_SEC_STATE_USER_PLIMIT          0x10
663 #define CXL_PMEM_SEC_STATE_MASTER_PLIMIT        0x20
664
665 /* set passphrase input payload */
666 struct cxl_set_pass {
667         u8 type;
668         u8 reserved[31];
669         /* CXL field using NVDIMM define, same length */
670         u8 old_pass[NVDIMM_PASSPHRASE_LEN];
671         u8 new_pass[NVDIMM_PASSPHRASE_LEN];
672 } __packed;
673
674 /* disable passphrase input payload */
675 struct cxl_disable_pass {
676         u8 type;
677         u8 reserved[31];
678         u8 pass[NVDIMM_PASSPHRASE_LEN];
679 } __packed;
680
681 /* passphrase secure erase payload */
682 struct cxl_pass_erase {
683         u8 type;
684         u8 reserved[31];
685         u8 pass[NVDIMM_PASSPHRASE_LEN];
686 } __packed;
687
688 enum {
689         CXL_PMEM_SEC_PASS_MASTER = 0,
690         CXL_PMEM_SEC_PASS_USER,
691 };
692
693 int cxl_internal_send_cmd(struct cxl_dev_state *cxlds,
694                           struct cxl_mbox_cmd *cmd);
695 int cxl_dev_state_identify(struct cxl_dev_state *cxlds);
696 int cxl_await_media_ready(struct cxl_dev_state *cxlds);
697 int cxl_enumerate_cmds(struct cxl_dev_state *cxlds);
698 int cxl_mem_create_range_info(struct cxl_dev_state *cxlds);
699 struct cxl_dev_state *cxl_dev_state_create(struct device *dev);
700 void set_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cmds);
701 void clear_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cmds);
702 void cxl_mem_get_event_records(struct cxl_dev_state *cxlds, u32 status);
703 int cxl_set_timestamp(struct cxl_dev_state *cxlds);
704 int cxl_poison_state_init(struct cxl_dev_state *cxlds);
705 int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
706                        struct cxl_region *cxlr);
707 int cxl_trigger_poison_list(struct cxl_memdev *cxlmd);
708 int cxl_inject_poison(struct cxl_memdev *cxlmd, u64 dpa);
709 int cxl_clear_poison(struct cxl_memdev *cxlmd, u64 dpa);
710
711 #ifdef CONFIG_CXL_SUSPEND
712 void cxl_mem_active_inc(void);
713 void cxl_mem_active_dec(void);
714 #else
715 static inline void cxl_mem_active_inc(void)
716 {
717 }
718 static inline void cxl_mem_active_dec(void)
719 {
720 }
721 #endif
722
723 struct cxl_hdm {
724         struct cxl_component_regs regs;
725         unsigned int decoder_count;
726         unsigned int target_count;
727         unsigned int interleave_mask;
728         struct cxl_port *port;
729 };
730
731 struct seq_file;
732 struct dentry *cxl_debugfs_create_dir(const char *dir);
733 void cxl_dpa_debug(struct seq_file *file, struct cxl_dev_state *cxlds);
734 #endif /* __CXL_MEM_H__ */
This page took 0.072797 seconds and 4 git commands to generate.