xref: /linux/drivers/ntb/hw/intel/ntb_hw_gen4.h (revision d5081bf5dcfb1cb83fb538708b0ac07a10a79cc4)
126bfe3d0SDave Jiang /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)          */
226bfe3d0SDave Jiang /* Copyright(c) 2020 Intel Corporation. All rights reserved.   */
326bfe3d0SDave Jiang #ifndef _NTB_INTEL_GEN4_H_
426bfe3d0SDave Jiang #define _NTB_INTEL_GEN4_H_
526bfe3d0SDave Jiang 
626bfe3d0SDave Jiang #include "ntb_hw_intel.h"
726bfe3d0SDave Jiang 
8134a8654SDave Jiang /* Supported PCI device revision range for ICX */
9134a8654SDave Jiang #define PCI_DEVICE_REVISION_ICX_MIN	0x2
10134a8654SDave Jiang #define PCI_DEVICE_REVISION_ICX_MAX	0xF
11134a8654SDave Jiang 
1226bfe3d0SDave Jiang /* Intel Gen4 NTB hardware */
1326bfe3d0SDave Jiang /* PCIe config space */
1426bfe3d0SDave Jiang #define GEN4_IMBAR23SZ_OFFSET		0x00c4
1526bfe3d0SDave Jiang #define GEN4_IMBAR45SZ_OFFSET		0x00c5
1626bfe3d0SDave Jiang #define GEN4_EMBAR23SZ_OFFSET		0x00c6
1726bfe3d0SDave Jiang #define GEN4_EMBAR45SZ_OFFSET		0x00c7
1826bfe3d0SDave Jiang #define GEN4_DEVCTRL_OFFSET		0x0048
1926bfe3d0SDave Jiang #define GEN4_DEVSTS_OFFSET		0x004a
2026bfe3d0SDave Jiang #define GEN4_UNCERRSTS_OFFSET		0x0104
2126bfe3d0SDave Jiang #define GEN4_CORERRSTS_OFFSET		0x0110
2226bfe3d0SDave Jiang 
2326bfe3d0SDave Jiang /* BAR0 MMIO */
2426bfe3d0SDave Jiang #define GEN4_NTBCNTL_OFFSET		0x0000
2526bfe3d0SDave Jiang #define GEN4_IM23XBASE_OFFSET		0x0010	/* IMBAR1XBASE */
2626bfe3d0SDave Jiang #define GEN4_IM23XLMT_OFFSET		0x0018  /* IMBAR1XLMT */
2726bfe3d0SDave Jiang #define GEN4_IM45XBASE_OFFSET		0x0020	/* IMBAR2XBASE */
2826bfe3d0SDave Jiang #define GEN4_IM45XLMT_OFFSET		0x0028  /* IMBAR2XLMT */
2926bfe3d0SDave Jiang #define GEN4_IM_INT_STATUS_OFFSET	0x0040
3026bfe3d0SDave Jiang #define GEN4_IM_INT_DISABLE_OFFSET	0x0048
3126bfe3d0SDave Jiang #define GEN4_INTVEC_OFFSET		0x0050  /* 0-32 vecs */
3226bfe3d0SDave Jiang #define GEN4_IM23XBASEIDX_OFFSET	0x0074
3326bfe3d0SDave Jiang #define GEN4_IM45XBASEIDX_OFFSET	0x0076
3426bfe3d0SDave Jiang #define GEN4_IM_SPAD_OFFSET		0x0080  /* 0-15 SPADs */
3526bfe3d0SDave Jiang #define GEN4_IM_SPAD_SEM_OFFSET		0x00c0	/* SPAD hw semaphore */
3626bfe3d0SDave Jiang #define GEN4_IM_SPAD_STICKY_OFFSET	0x00c4  /* sticky SPAD */
3726bfe3d0SDave Jiang #define GEN4_IM_DOORBELL_OFFSET		0x0100  /* 0-31 doorbells */
3875b6f648SDave Jiang #define GEN4_LTR_SWSEL_OFFSET		0x30ec
3975b6f648SDave Jiang #define GEN4_LTR_ACTIVE_OFFSET		0x30f0
4075b6f648SDave Jiang #define GEN4_LTR_IDLE_OFFSET		0x30f4
4126bfe3d0SDave Jiang #define GEN4_EM_SPAD_OFFSET		0x8080
4226bfe3d0SDave Jiang /* note, link status is now in MMIO and not config space for NTB */
4326bfe3d0SDave Jiang #define GEN4_LINK_CTRL_OFFSET		0xb050
4426bfe3d0SDave Jiang #define GEN4_LINK_STATUS_OFFSET		0xb052
4526bfe3d0SDave Jiang #define GEN4_PPD0_OFFSET		0xb0d4
4626bfe3d0SDave Jiang #define GEN4_PPD1_OFFSET		0xb4c0
4726bfe3d0SDave Jiang #define GEN4_LTSSMSTATEJMP		0xf040
4826bfe3d0SDave Jiang 
4926bfe3d0SDave Jiang #define GEN4_PPD_CLEAR_TRN		0x0001
5026bfe3d0SDave Jiang #define GEN4_PPD_LINKTRN		0x0008
5126bfe3d0SDave Jiang #define GEN4_PPD_CONN_MASK		0x0300
52*d5081bf5SDave Jiang #define SPR_PPD_CONN_MASK		0x0700
5326bfe3d0SDave Jiang #define GEN4_PPD_CONN_B2B		0x0200
5426bfe3d0SDave Jiang #define GEN4_PPD_DEV_MASK		0x1000
5526bfe3d0SDave Jiang #define GEN4_PPD_DEV_DSD		0x1000
5626bfe3d0SDave Jiang #define GEN4_PPD_DEV_USD		0x0000
57*d5081bf5SDave Jiang #define SPR_PPD_DEV_MASK		0x4000
58*d5081bf5SDave Jiang #define SPR_PPD_DEV_DSD 		0x4000
59*d5081bf5SDave Jiang #define SPR_PPD_DEV_USD 		0x0000
6026bfe3d0SDave Jiang #define GEN4_LINK_CTRL_LINK_DISABLE	0x0010
6126bfe3d0SDave Jiang 
6226bfe3d0SDave Jiang #define GEN4_SLOTSTS			0xb05a
6326bfe3d0SDave Jiang #define GEN4_SLOTSTS_DLLSCS		0x100
6426bfe3d0SDave Jiang 
6526bfe3d0SDave Jiang #define GEN4_PPD_TOPO_MASK	(GEN4_PPD_CONN_MASK | GEN4_PPD_DEV_MASK)
6626bfe3d0SDave Jiang #define GEN4_PPD_TOPO_B2B_USD	(GEN4_PPD_CONN_B2B | GEN4_PPD_DEV_USD)
6726bfe3d0SDave Jiang #define GEN4_PPD_TOPO_B2B_DSD	(GEN4_PPD_CONN_B2B | GEN4_PPD_DEV_DSD)
6826bfe3d0SDave Jiang 
69*d5081bf5SDave Jiang #define SPR_PPD_TOPO_MASK	(SPR_PPD_CONN_MASK | SPR_PPD_DEV_MASK)
70*d5081bf5SDave Jiang #define SPR_PPD_TOPO_B2B_USD	(GEN4_PPD_CONN_B2B | SPR_PPD_DEV_USD)
71*d5081bf5SDave Jiang #define SPR_PPD_TOPO_B2B_DSD	(GEN4_PPD_CONN_B2B | SPR_PPD_DEV_DSD)
72*d5081bf5SDave Jiang 
7326bfe3d0SDave Jiang #define GEN4_DB_COUNT			32
7426bfe3d0SDave Jiang #define GEN4_DB_LINK			32
7526bfe3d0SDave Jiang #define GEN4_DB_LINK_BIT		BIT_ULL(GEN4_DB_LINK)
7626bfe3d0SDave Jiang #define GEN4_DB_MSIX_VECTOR_COUNT	33
7726bfe3d0SDave Jiang #define GEN4_DB_MSIX_VECTOR_SHIFT	1
7826bfe3d0SDave Jiang #define GEN4_DB_TOTAL_SHIFT		33
7926bfe3d0SDave Jiang #define GEN4_SPAD_COUNT			16
8026bfe3d0SDave Jiang 
8126bfe3d0SDave Jiang #define NTB_CTL_E2I_BAR23_SNOOP		0x000004
8226bfe3d0SDave Jiang #define NTB_CTL_E2I_BAR23_NOSNOOP	0x000008
8326bfe3d0SDave Jiang #define NTB_CTL_I2E_BAR23_SNOOP		0x000010
8426bfe3d0SDave Jiang #define NTB_CTL_I2E_BAR23_NOSNOOP	0x000020
8526bfe3d0SDave Jiang #define NTB_CTL_E2I_BAR45_SNOOP		0x000040
8626bfe3d0SDave Jiang #define NTB_CTL_E2I_BAR45_NOSNOO	0x000080
8726bfe3d0SDave Jiang #define NTB_CTL_I2E_BAR45_SNOOP		0x000100
8826bfe3d0SDave Jiang #define NTB_CTL_I2E_BAR45_NOSNOOP	0x000200
8926bfe3d0SDave Jiang #define NTB_CTL_BUSNO_DIS_INC		0x000400
9026bfe3d0SDave Jiang #define NTB_CTL_LINK_DOWN		0x010000
9126bfe3d0SDave Jiang 
9226bfe3d0SDave Jiang #define NTB_SJC_FORCEDETECT		0x000004
9326bfe3d0SDave Jiang 
9475b6f648SDave Jiang #define NTB_LTR_SWSEL_ACTIVE		0x0
9575b6f648SDave Jiang #define NTB_LTR_SWSEL_IDLE		0x1
9675b6f648SDave Jiang 
9775b6f648SDave Jiang #define NTB_LTR_NS_SHIFT		16
9875b6f648SDave Jiang #define NTB_LTR_ACTIVE_VAL		0x0000  /* 0 us */
9975b6f648SDave Jiang #define NTB_LTR_ACTIVE_LATSCALE		0x0800  /* 1us scale */
10075b6f648SDave Jiang #define NTB_LTR_ACTIVE_REQMNT		0x8000  /* snoop req enable */
10175b6f648SDave Jiang 
10275b6f648SDave Jiang #define NTB_LTR_IDLE_VAL		0x0258  /* 600 us */
10375b6f648SDave Jiang #define NTB_LTR_IDLE_LATSCALE		0x0800  /* 1us scale */
10475b6f648SDave Jiang #define NTB_LTR_IDLE_REQMNT		0x8000  /* snoop req enable */
10575b6f648SDave Jiang 
10626bfe3d0SDave Jiang ssize_t ndev_ntb4_debugfs_read(struct file *filp, char __user *ubuf,
10726bfe3d0SDave Jiang 				      size_t count, loff_t *offp);
10826bfe3d0SDave Jiang int gen4_init_dev(struct intel_ntb_dev *ndev);
10926bfe3d0SDave Jiang ssize_t ndev_ntb4_debugfs_read(struct file *filp, char __user *ubuf,
11026bfe3d0SDave Jiang 				      size_t count, loff_t *offp);
11126bfe3d0SDave Jiang 
11226bfe3d0SDave Jiang extern const struct ntb_dev_ops intel_ntb4_ops;
11326bfe3d0SDave Jiang 
114134a8654SDave Jiang static inline int pdev_is_ICX(struct pci_dev *pdev)
115134a8654SDave Jiang {
116134a8654SDave Jiang 	if (pdev_is_gen4(pdev) &&
117134a8654SDave Jiang 	    pdev->revision >= PCI_DEVICE_REVISION_ICX_MIN &&
118134a8654SDave Jiang 	    pdev->revision <= PCI_DEVICE_REVISION_ICX_MAX)
119134a8654SDave Jiang 		return 1;
120134a8654SDave Jiang 	return 0;
121134a8654SDave Jiang }
122134a8654SDave Jiang 
123*d5081bf5SDave Jiang static inline int pdev_is_SPR(struct pci_dev *pdev)
124*d5081bf5SDave Jiang {
125*d5081bf5SDave Jiang 	if (pdev_is_gen4(pdev) &&
126*d5081bf5SDave Jiang 	    pdev->revision > PCI_DEVICE_REVISION_ICX_MAX)
127*d5081bf5SDave Jiang 		return 1;
128*d5081bf5SDave Jiang 	return 0;
129*d5081bf5SDave Jiang }
130*d5081bf5SDave Jiang 
13126bfe3d0SDave Jiang #endif
132