xref: /openbmc/linux/drivers/cxl/cxlpci.h (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
1af9cae9fSDan Williams /* SPDX-License-Identifier: GPL-2.0-only */
2af9cae9fSDan Williams /* Copyright(c) 2020 Intel Corporation. All rights reserved. */
3af9cae9fSDan Williams #ifndef __CXL_PCI_H__
4af9cae9fSDan Williams #define __CXL_PCI_H__
554cdbf84SBen Widawsky #include <linux/pci.h>
6af9cae9fSDan Williams #include "cxl.h"
7af9cae9fSDan Williams 
8af9cae9fSDan Williams #define CXL_MEMORY_PROGIF	0x10
9af9cae9fSDan Williams 
10af9cae9fSDan Williams /*
11af9cae9fSDan Williams  * See section 8.1 Configuration Space Registers in the CXL 2.0
12af9cae9fSDan Williams  * Specification. Names are taken straight from the specification with "CXL" and
13af9cae9fSDan Williams  * "DVSEC" redundancies removed. When obvious, abbreviations may be used.
14af9cae9fSDan Williams  */
15af9cae9fSDan Williams #define PCI_DVSEC_HEADER1_LENGTH_MASK	GENMASK(31, 20)
16af9cae9fSDan Williams #define PCI_DVSEC_VENDOR_ID_CXL		0x1E98
17af9cae9fSDan Williams 
18af9cae9fSDan Williams /* CXL 2.0 8.1.3: PCIe DVSEC for CXL Device */
19af9cae9fSDan Williams #define CXL_DVSEC_PCIE_DEVICE					0
20560f7855SBen Widawsky #define   CXL_DVSEC_CAP_OFFSET		0xA
21560f7855SBen Widawsky #define     CXL_DVSEC_MEM_CAPABLE	BIT(2)
22560f7855SBen Widawsky #define     CXL_DVSEC_HDM_COUNT_MASK	GENMASK(5, 4)
23560f7855SBen Widawsky #define   CXL_DVSEC_CTRL_OFFSET		0xC
24560f7855SBen Widawsky #define     CXL_DVSEC_MEM_ENABLE	BIT(2)
25560f7855SBen Widawsky #define   CXL_DVSEC_RANGE_SIZE_HIGH(i)	(0x18 + (i * 0x10))
26560f7855SBen Widawsky #define   CXL_DVSEC_RANGE_SIZE_LOW(i)	(0x1C + (i * 0x10))
27560f7855SBen Widawsky #define     CXL_DVSEC_MEM_INFO_VALID	BIT(0)
28560f7855SBen Widawsky #define     CXL_DVSEC_MEM_ACTIVE	BIT(1)
29560f7855SBen Widawsky #define     CXL_DVSEC_MEM_SIZE_LOW_MASK	GENMASK(31, 28)
30560f7855SBen Widawsky #define   CXL_DVSEC_RANGE_BASE_HIGH(i)	(0x20 + (i * 0x10))
31560f7855SBen Widawsky #define   CXL_DVSEC_RANGE_BASE_LOW(i)	(0x24 + (i * 0x10))
32560f7855SBen Widawsky #define     CXL_DVSEC_MEM_BASE_LOW_MASK	GENMASK(31, 28)
33af9cae9fSDan Williams 
34*ce17ad0dSDave Jiang #define CXL_DVSEC_RANGE_MAX		2
35*ce17ad0dSDave Jiang 
36af9cae9fSDan Williams /* CXL 2.0 8.1.4: Non-CXL Function Map DVSEC */
37af9cae9fSDan Williams #define CXL_DVSEC_FUNCTION_MAP					2
38af9cae9fSDan Williams 
39af9cae9fSDan Williams /* CXL 2.0 8.1.5: CXL 2.0 Extensions DVSEC for Ports */
40af9cae9fSDan Williams #define CXL_DVSEC_PORT_EXTENSIONS				3
41af9cae9fSDan Williams 
42af9cae9fSDan Williams /* CXL 2.0 8.1.6: GPF DVSEC for CXL Port */
43af9cae9fSDan Williams #define CXL_DVSEC_PORT_GPF					4
44af9cae9fSDan Williams 
45af9cae9fSDan Williams /* CXL 2.0 8.1.7: GPF DVSEC for CXL Device */
46af9cae9fSDan Williams #define CXL_DVSEC_DEVICE_GPF					5
47af9cae9fSDan Williams 
48af9cae9fSDan Williams /* CXL 2.0 8.1.8: PCIe DVSEC for Flex Bus Port */
49af9cae9fSDan Williams #define CXL_DVSEC_PCIE_FLEXBUS_PORT				7
50af9cae9fSDan Williams 
51af9cae9fSDan Williams /* CXL 2.0 8.1.9: Register Locator DVSEC */
52af9cae9fSDan Williams #define CXL_DVSEC_REG_LOCATOR					8
53af9cae9fSDan Williams #define   CXL_DVSEC_REG_LOCATOR_BLOCK1_OFFSET			0xC
54af9cae9fSDan Williams #define     CXL_DVSEC_REG_LOCATOR_BIR_MASK			GENMASK(2, 0)
55af9cae9fSDan Williams #define	    CXL_DVSEC_REG_LOCATOR_BLOCK_ID_MASK			GENMASK(15, 8)
56af9cae9fSDan Williams #define     CXL_DVSEC_REG_LOCATOR_BLOCK_OFF_LOW_MASK		GENMASK(31, 16)
57af9cae9fSDan Williams 
58a49aa814SDavidlohr Bueso /*
59a49aa814SDavidlohr Bueso  * NOTE: Currently all the functions which are enabled for CXL require their
60a49aa814SDavidlohr Bueso  * vectors to be in the first 16.  Use this as the default max.
61a49aa814SDavidlohr Bueso  */
62a49aa814SDavidlohr Bueso #define CXL_PCI_DEFAULT_MAX_VECTORS 16
63a49aa814SDavidlohr Bueso 
64af9cae9fSDan Williams /* Register Block Identifier (RBI) */
65af9cae9fSDan Williams enum cxl_regloc_type {
66af9cae9fSDan Williams 	CXL_REGLOC_RBI_EMPTY = 0,
67af9cae9fSDan Williams 	CXL_REGLOC_RBI_COMPONENT,
68af9cae9fSDan Williams 	CXL_REGLOC_RBI_VIRT,
69af9cae9fSDan Williams 	CXL_REGLOC_RBI_MEMDEV,
70af9cae9fSDan Williams 	CXL_REGLOC_RBI_PMU,
71af9cae9fSDan Williams 	CXL_REGLOC_RBI_TYPES
72af9cae9fSDan Williams };
73b56faef2SLukas Wunner 
74b56faef2SLukas Wunner struct cdat_header {
75b56faef2SLukas Wunner 	__le32 length;
76b56faef2SLukas Wunner 	u8 revision;
77b56faef2SLukas Wunner 	u8 checksum;
78b56faef2SLukas Wunner 	u8 reserved[6];
79b56faef2SLukas Wunner 	__le32 sequence;
80b56faef2SLukas Wunner } __packed;
81b56faef2SLukas Wunner 
82b56faef2SLukas Wunner struct cdat_entry_header {
83b56faef2SLukas Wunner 	u8 type;
84b56faef2SLukas Wunner 	u8 reserved;
85b56faef2SLukas Wunner 	__le16 length;
86b56faef2SLukas Wunner } __packed;
87664bf115SDan Williams 
8814d78874SDan Williams int devm_cxl_port_enumerate_dports(struct cxl_port *port);
8959c3368bSDave Jiang struct cxl_dev_state;
9059c3368bSDave Jiang int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
91c9700604SIra Weiny 			struct cxl_endpoint_dvsec_info *info);
924a20bc3eSDan Williams void read_cdat_data(struct cxl_port *port);
934a20bc3eSDan Williams void cxl_cor_error_detected(struct pci_dev *pdev);
944a20bc3eSDan Williams pci_ers_result_t cxl_error_detected(struct pci_dev *pdev,
95af9cae9fSDan Williams 				    pci_channel_state_t state);
96 #endif /* __CXL_PCI_H__ */
97