xref: /kernel/linux/linux-6.6/drivers/cxl/cxlpci.h (revision 62306a36)
162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/* Copyright(c) 2020 Intel Corporation. All rights reserved. */
362306a36Sopenharmony_ci#ifndef __CXL_PCI_H__
462306a36Sopenharmony_ci#define __CXL_PCI_H__
562306a36Sopenharmony_ci#include <linux/pci.h>
662306a36Sopenharmony_ci#include "cxl.h"
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#define CXL_MEMORY_PROGIF	0x10
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci/*
1162306a36Sopenharmony_ci * See section 8.1 Configuration Space Registers in the CXL 2.0
1262306a36Sopenharmony_ci * Specification. Names are taken straight from the specification with "CXL" and
1362306a36Sopenharmony_ci * "DVSEC" redundancies removed. When obvious, abbreviations may be used.
1462306a36Sopenharmony_ci */
1562306a36Sopenharmony_ci#define PCI_DVSEC_HEADER1_LENGTH_MASK	GENMASK(31, 20)
1662306a36Sopenharmony_ci#define PCI_DVSEC_VENDOR_ID_CXL		0x1E98
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci/* CXL 2.0 8.1.3: PCIe DVSEC for CXL Device */
1962306a36Sopenharmony_ci#define CXL_DVSEC_PCIE_DEVICE					0
2062306a36Sopenharmony_ci#define   CXL_DVSEC_CAP_OFFSET		0xA
2162306a36Sopenharmony_ci#define     CXL_DVSEC_MEM_CAPABLE	BIT(2)
2262306a36Sopenharmony_ci#define     CXL_DVSEC_HDM_COUNT_MASK	GENMASK(5, 4)
2362306a36Sopenharmony_ci#define   CXL_DVSEC_CTRL_OFFSET		0xC
2462306a36Sopenharmony_ci#define     CXL_DVSEC_MEM_ENABLE	BIT(2)
2562306a36Sopenharmony_ci#define   CXL_DVSEC_RANGE_SIZE_HIGH(i)	(0x18 + (i * 0x10))
2662306a36Sopenharmony_ci#define   CXL_DVSEC_RANGE_SIZE_LOW(i)	(0x1C + (i * 0x10))
2762306a36Sopenharmony_ci#define     CXL_DVSEC_MEM_INFO_VALID	BIT(0)
2862306a36Sopenharmony_ci#define     CXL_DVSEC_MEM_ACTIVE	BIT(1)
2962306a36Sopenharmony_ci#define     CXL_DVSEC_MEM_SIZE_LOW_MASK	GENMASK(31, 28)
3062306a36Sopenharmony_ci#define   CXL_DVSEC_RANGE_BASE_HIGH(i)	(0x20 + (i * 0x10))
3162306a36Sopenharmony_ci#define   CXL_DVSEC_RANGE_BASE_LOW(i)	(0x24 + (i * 0x10))
3262306a36Sopenharmony_ci#define     CXL_DVSEC_MEM_BASE_LOW_MASK	GENMASK(31, 28)
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci#define CXL_DVSEC_RANGE_MAX		2
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci/* CXL 2.0 8.1.4: Non-CXL Function Map DVSEC */
3762306a36Sopenharmony_ci#define CXL_DVSEC_FUNCTION_MAP					2
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci/* CXL 2.0 8.1.5: CXL 2.0 Extensions DVSEC for Ports */
4062306a36Sopenharmony_ci#define CXL_DVSEC_PORT_EXTENSIONS				3
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci/* CXL 2.0 8.1.6: GPF DVSEC for CXL Port */
4362306a36Sopenharmony_ci#define CXL_DVSEC_PORT_GPF					4
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci/* CXL 2.0 8.1.7: GPF DVSEC for CXL Device */
4662306a36Sopenharmony_ci#define CXL_DVSEC_DEVICE_GPF					5
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci/* CXL 2.0 8.1.8: PCIe DVSEC for Flex Bus Port */
4962306a36Sopenharmony_ci#define CXL_DVSEC_PCIE_FLEXBUS_PORT				7
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci/* CXL 2.0 8.1.9: Register Locator DVSEC */
5262306a36Sopenharmony_ci#define CXL_DVSEC_REG_LOCATOR					8
5362306a36Sopenharmony_ci#define   CXL_DVSEC_REG_LOCATOR_BLOCK1_OFFSET			0xC
5462306a36Sopenharmony_ci#define     CXL_DVSEC_REG_LOCATOR_BIR_MASK			GENMASK(2, 0)
5562306a36Sopenharmony_ci#define	    CXL_DVSEC_REG_LOCATOR_BLOCK_ID_MASK			GENMASK(15, 8)
5662306a36Sopenharmony_ci#define     CXL_DVSEC_REG_LOCATOR_BLOCK_OFF_LOW_MASK		GENMASK(31, 16)
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci/*
5962306a36Sopenharmony_ci * NOTE: Currently all the functions which are enabled for CXL require their
6062306a36Sopenharmony_ci * vectors to be in the first 16.  Use this as the default max.
6162306a36Sopenharmony_ci */
6262306a36Sopenharmony_ci#define CXL_PCI_DEFAULT_MAX_VECTORS 16
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci/* Register Block Identifier (RBI) */
6562306a36Sopenharmony_cienum cxl_regloc_type {
6662306a36Sopenharmony_ci	CXL_REGLOC_RBI_EMPTY = 0,
6762306a36Sopenharmony_ci	CXL_REGLOC_RBI_COMPONENT,
6862306a36Sopenharmony_ci	CXL_REGLOC_RBI_VIRT,
6962306a36Sopenharmony_ci	CXL_REGLOC_RBI_MEMDEV,
7062306a36Sopenharmony_ci	CXL_REGLOC_RBI_PMU,
7162306a36Sopenharmony_ci	CXL_REGLOC_RBI_TYPES
7262306a36Sopenharmony_ci};
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_cistruct cdat_header {
7562306a36Sopenharmony_ci	__le32 length;
7662306a36Sopenharmony_ci	u8 revision;
7762306a36Sopenharmony_ci	u8 checksum;
7862306a36Sopenharmony_ci	u8 reserved[6];
7962306a36Sopenharmony_ci	__le32 sequence;
8062306a36Sopenharmony_ci} __packed;
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_cistruct cdat_entry_header {
8362306a36Sopenharmony_ci	u8 type;
8462306a36Sopenharmony_ci	u8 reserved;
8562306a36Sopenharmony_ci	__le16 length;
8662306a36Sopenharmony_ci} __packed;
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ciint devm_cxl_port_enumerate_dports(struct cxl_port *port);
8962306a36Sopenharmony_cistruct cxl_dev_state;
9062306a36Sopenharmony_ciint cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
9162306a36Sopenharmony_ci			struct cxl_endpoint_dvsec_info *info);
9262306a36Sopenharmony_civoid read_cdat_data(struct cxl_port *port);
9362306a36Sopenharmony_civoid cxl_cor_error_detected(struct pci_dev *pdev);
9462306a36Sopenharmony_cipci_ers_result_t cxl_error_detected(struct pci_dev *pdev,
9562306a36Sopenharmony_ci				    pci_channel_state_t state);
9662306a36Sopenharmony_ci#endif /* __CXL_PCI_H__ */
97