xref: /linux/drivers/thunderbolt/nhi.h (revision 7db28abbea0f7dc1ec4fdfdc149db5fbd9e4c994)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Thunderbolt driver - NHI driver
4  *
5  * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
6  * Copyright (C) 2018, Intel Corporation
7  */
8 
9 #ifndef DSL3510_H_
10 #define DSL3510_H_
11 
12 #include <linux/thunderbolt.h>
13 
14 enum nhi_fw_mode {
15 	NHI_FW_SAFE_MODE,
16 	NHI_FW_AUTH_MODE,
17 	NHI_FW_EP_MODE,
18 	NHI_FW_CM_MODE,
19 };
20 
21 enum nhi_mailbox_cmd {
22 	NHI_MAILBOX_SAVE_DEVS = 0x05,
23 	NHI_MAILBOX_DISCONNECT_PCIE_PATHS = 0x06,
24 	NHI_MAILBOX_DRV_UNLOADS = 0x07,
25 	NHI_MAILBOX_DISCONNECT_PA = 0x10,
26 	NHI_MAILBOX_DISCONNECT_PB = 0x11,
27 	NHI_MAILBOX_ALLOW_ALL_DEVS = 0x23,
28 };
29 
30 int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data);
31 enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi);
32 void nhi_enable_int_throttling(struct tb_nhi *nhi);
33 void nhi_disable_interrupts(struct tb_nhi *nhi);
34 void nhi_interrupt_work(struct work_struct *work);
35 irqreturn_t nhi_msi(int irq, void *data);
36 irqreturn_t ring_msix(int irq, void *data);
37 int nhi_probe(struct tb_nhi *nhi);
38 void nhi_shutdown(struct tb_nhi *nhi);
39 void nhi_reset_interface(struct tb_nhi *nhi);
40 
41 extern const struct dev_pm_ops nhi_pm_ops;
42 
43 /**
44  * struct tb_nhi_ops - NHI specific optional operations
45  * @init: NHI specific initialization
46  * @suspend_noirq: NHI specific suspend_noirq hook
47  * @resume_noirq: NHI specific resume_noirq hook
48  * @runtime_suspend: NHI specific runtime_suspend hook
49  * @runtime_resume: NHI specific runtime_resume hook
50  * @shutdown: NHI specific shutdown
51  * @pre_nvm_auth: hook to run before Thunderbolt 3 NVM authentication
52  * @post_nvm_auth: hook to run after Thunderbolt 3 NVM authentication
53  * @request_ring_irq: NHI specific interrupt retrieval hook
54  * @release_ring_irq: NHI specific interrupt release hook
55  * @is_present: Whether the device is currently present on the parent bus
56  * @init_interrupts: NHI specific interrupt initialization hook
57  * @reset_interface: Resets the host interface
58  */
59 struct tb_nhi_ops {
60 	int (*init)(struct tb_nhi *nhi);
61 	int (*suspend_noirq)(struct tb_nhi *nhi, bool wakeup);
62 	int (*resume_noirq)(struct tb_nhi *nhi);
63 	int (*runtime_suspend)(struct tb_nhi *nhi);
64 	int (*runtime_resume)(struct tb_nhi *nhi);
65 	void (*shutdown)(struct tb_nhi *nhi);
66 	void (*pre_nvm_auth)(struct tb_nhi *nhi);
67 	void (*post_nvm_auth)(struct tb_nhi *nhi);
68 	int (*request_ring_irq)(struct tb_ring *ring, bool no_suspend);
69 	void (*release_ring_irq)(struct tb_ring *ring);
70 	bool (*is_present)(struct tb_nhi *nhi);
71 	int (*init_interrupts)(struct tb_nhi *nhi);
72 	void (*reset_interface)(struct tb_nhi *nhi);
73 };
74 
75 /*
76  * PCI IDs used in this driver from Win Ridge forward. There is no
77  * need for the PCI quirk anymore as we will use ICM also on Apple
78  * hardware.
79  */
80 #define PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_2C_NHI		0x1134
81 #define PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_4C_NHI		0x1137
82 #define PCI_DEVICE_ID_INTEL_WIN_RIDGE_2C_NHI            0x157d
83 #define PCI_DEVICE_ID_INTEL_WIN_RIDGE_2C_BRIDGE         0x157e
84 #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_NHI		0x15bf
85 #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_BRIDGE	0x15c0
86 #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_NHI	0x15d2
87 #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_BRIDGE	0x15d3
88 #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_NHI	0x15d9
89 #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_BRIDGE	0x15da
90 #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_USBONLY_NHI	0x15dc
91 #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_USBONLY_NHI	0x15dd
92 #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_USBONLY_NHI	0x15de
93 #define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_BRIDGE	0x15e7
94 #define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_NHI		0x15e8
95 #define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_BRIDGE	0x15ea
96 #define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_NHI		0x15eb
97 #define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_BRIDGE	0x15ef
98 #define PCI_DEVICE_ID_INTEL_ADL_NHI0			0x463e
99 #define PCI_DEVICE_ID_INTEL_ADL_NHI1			0x466d
100 #define PCI_DEVICE_ID_INTEL_WCL_NHI0			0x4d33
101 #define PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HOST_80G_NHI	0x5781
102 #define PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HOST_40G_NHI	0x5784
103 #define PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HUB_80G_BRIDGE 0x5786
104 #define PCI_DEVICE_ID_INTEL_BARLOW_RIDGE_HUB_40G_BRIDGE 0x57a4
105 #define PCI_DEVICE_ID_INTEL_MTL_M_NHI0			0x7eb2
106 #define PCI_DEVICE_ID_INTEL_MTL_P_NHI0			0x7ec2
107 #define PCI_DEVICE_ID_INTEL_MTL_P_NHI1			0x7ec3
108 #define PCI_DEVICE_ID_INTEL_ICL_NHI1			0x8a0d
109 #define PCI_DEVICE_ID_INTEL_ICL_NHI0			0x8a17
110 #define PCI_DEVICE_ID_INTEL_TGL_NHI0			0x9a1b
111 #define PCI_DEVICE_ID_INTEL_TGL_NHI1			0x9a1d
112 #define PCI_DEVICE_ID_INTEL_TGL_H_NHI0			0x9a1f
113 #define PCI_DEVICE_ID_INTEL_TGL_H_NHI1			0x9a21
114 #define PCI_DEVICE_ID_INTEL_RPL_NHI0			0xa73e
115 #define PCI_DEVICE_ID_INTEL_RPL_NHI1			0xa76d
116 #define PCI_DEVICE_ID_INTEL_LNL_NHI0			0xa833
117 #define PCI_DEVICE_ID_INTEL_LNL_NHI1			0xa834
118 #define PCI_DEVICE_ID_INTEL_PTL_M_NHI0			0xe333
119 #define PCI_DEVICE_ID_INTEL_PTL_M_NHI1			0xe334
120 #define PCI_DEVICE_ID_INTEL_PTL_P_NHI0			0xe433
121 #define PCI_DEVICE_ID_INTEL_PTL_P_NHI1			0xe434
122 
123 #define PCI_DEVICE_ID_AMD_1AH_M60H_NHI0			0x1120
124 #define PCI_DEVICE_ID_AMD_1AH_M60H_NHI1			0x1121
125 #define PCI_DEVICE_ID_AMD_1AH_M68H_NHI0			0x113b
126 #define PCI_DEVICE_ID_AMD_1AH_M68H_NHI1			0x113c
127 #define PCI_DEVICE_ID_AMD_1AH_M80H_NHI0			0x1155
128 #define PCI_DEVICE_ID_AMD_1AH_M80H_NHI1			0x1158
129 #define PCI_DEVICE_ID_AMD_1AH_M80H_NHI2			0x1159
130 #define PCI_DEVICE_ID_AMD_1AH_M24H_NHI0			0x151c
131 #define PCI_DEVICE_ID_AMD_1AH_M24H_NHI1			0x151d
132 #define PCI_DEVICE_ID_AMD_1AH_M70H_NHI0			0x158d
133 #define PCI_DEVICE_ID_AMD_1AH_M70H_NHI1			0x158e
134 
135 #define PCI_CLASS_SERIAL_USB_USB4			0x0c0340
136 
137 /* Host interface quirks */
138 #define QUIRK_AUTO_CLEAR_INT				BIT(0)
139 #define QUIRK_E2E					BIT(1)
140 #define QUIRK_RESET_DMA_ON_TEARDOWN			BIT(2)
141 
142 /*
143  * Minimal number of vectors when we use MSI-X. Two for control channel
144  * Rx/Tx and the rest four are for cross domain DMA paths.
145  */
146 #define MSIX_MIN_VECS		6
147 #define MSIX_MAX_VECS		16
148 
149 #endif
150