blob: 23fc40dde27eabb3bd920f66bf3df5705c3f4c1b [file] [log] [blame]
Dan Williams5f50d6b2021-05-13 22:21:49 -07001/* 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
6/* CXL 2.0 8.2.8.5.1.1 Memory Device Status Register */
7#define CXLMDEV_STATUS_OFFSET 0x0
8#define CXLMDEV_DEV_FATAL BIT(0)
9#define CXLMDEV_FW_HALT BIT(1)
10#define CXLMDEV_STATUS_MEDIA_STATUS_MASK GENMASK(3, 2)
11#define CXLMDEV_MS_NOT_READY 0
12#define CXLMDEV_MS_READY 1
13#define CXLMDEV_MS_ERROR 2
14#define CXLMDEV_MS_DISABLED 3
15#define CXLMDEV_READY(status) \
16 (FIELD_GET(CXLMDEV_STATUS_MEDIA_STATUS_MASK, status) == \
17 CXLMDEV_MS_READY)
18#define CXLMDEV_MBOX_IF_READY BIT(4)
19#define CXLMDEV_RESET_NEEDED_MASK GENMASK(7, 5)
20#define CXLMDEV_RESET_NEEDED_NOT 0
21#define CXLMDEV_RESET_NEEDED_COLD 1
22#define CXLMDEV_RESET_NEEDED_WARM 2
23#define CXLMDEV_RESET_NEEDED_HOT 3
24#define CXLMDEV_RESET_NEEDED_CXL 4
25#define CXLMDEV_RESET_NEEDED(status) \
26 (FIELD_GET(CXLMDEV_RESET_NEEDED_MASK, status) != \
27 CXLMDEV_RESET_NEEDED_NOT)
28
29/*
30 * An entire PCI topology full of devices should be enough for any
31 * config
32 */
33#define CXL_MEM_MAX_DEVS 65536
34
35/**
36 * struct cxl_memdev - CXL bus object representing a Type-3 Memory Device
37 * @dev: driver core device object
38 * @cdev: char dev core object for ioctl operations
39 * @cxlm: pointer to the parent device driver data
40 * @id: id number of this memdev instance.
41 */
42struct cxl_memdev {
43 struct device dev;
44 struct cdev cdev;
45 struct cxl_mem *cxlm;
46 int id;
47};
48
49/**
50 * struct cxl_mem - A CXL memory device
51 * @pdev: The PCI device associated with this CXL device.
Dan Williams8ac75dd2021-05-13 22:21:54 -070052 * @base: IO mappings to the device's MMIO
53 * @cxlmd: Logical memory device chardev / interface
54 * @regs: Parsed register blocks
Dan Williams5f50d6b2021-05-13 22:21:49 -070055 * @payload_size: Size of space for payload
56 * (CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register)
Vishal Verma199cf8c2021-05-20 13:47:45 -060057 * @lsa_size: Size of Label Storage Area
58 * (CXL 2.0 8.2.9.5.1.1 Identify Memory Device)
Dan Williams5f50d6b2021-05-13 22:21:49 -070059 * @mbox_mutex: Mutex to synchronize mailbox access.
60 * @firmware_version: Firmware version for the memory device.
61 * @enabled_cmds: Hardware commands found enabled in CEL.
62 * @pmem_range: Persistent memory capacity information.
63 * @ram_range: Volatile memory capacity information.
64 */
65struct cxl_mem {
66 struct pci_dev *pdev;
Dan Williams8ac75dd2021-05-13 22:21:54 -070067 void __iomem *base;
Dan Williams5f50d6b2021-05-13 22:21:49 -070068 struct cxl_memdev *cxlmd;
69
Dan Williams8ac75dd2021-05-13 22:21:54 -070070 struct cxl_regs regs;
Dan Williams5f50d6b2021-05-13 22:21:49 -070071
72 size_t payload_size;
Vishal Verma199cf8c2021-05-20 13:47:45 -060073 size_t lsa_size;
Dan Williams5f50d6b2021-05-13 22:21:49 -070074 struct mutex mbox_mutex; /* Protects device mailbox and firmware */
75 char firmware_version[0x10];
76 unsigned long *enabled_cmds;
77
78 struct range pmem_range;
79 struct range ram_range;
80};
81#endif /* __CXL_MEM_H__ */