xref: /linux-6.15/include/linux/switchtec.h (revision 8a74e4ea)
12025cf9eSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
25a1c269fSLogan Gunthorpe /*
35a1c269fSLogan Gunthorpe  * Microsemi Switchtec PCIe Driver
45a1c269fSLogan Gunthorpe  * Copyright (c) 2017, Microsemi Corporation
55a1c269fSLogan Gunthorpe  */
65a1c269fSLogan Gunthorpe 
75a1c269fSLogan Gunthorpe #ifndef _SWITCHTEC_H
85a1c269fSLogan Gunthorpe #define _SWITCHTEC_H
95a1c269fSLogan Gunthorpe 
105a1c269fSLogan Gunthorpe #include <linux/pci.h>
115a1c269fSLogan Gunthorpe #include <linux/cdev.h>
125a1c269fSLogan Gunthorpe 
135a1c269fSLogan Gunthorpe #define SWITCHTEC_MRPC_PAYLOAD_SIZE 1024
14ba8a3982SWesley Sheng #define SWITCHTEC_MAX_PFF_CSR 255
155a1c269fSLogan Gunthorpe 
165a1c269fSLogan Gunthorpe #define SWITCHTEC_EVENT_OCCURRED BIT(0)
175a1c269fSLogan Gunthorpe #define SWITCHTEC_EVENT_CLEAR    BIT(0)
185a1c269fSLogan Gunthorpe #define SWITCHTEC_EVENT_EN_LOG   BIT(1)
195a1c269fSLogan Gunthorpe #define SWITCHTEC_EVENT_EN_CLI   BIT(2)
205a1c269fSLogan Gunthorpe #define SWITCHTEC_EVENT_EN_IRQ   BIT(3)
215a1c269fSLogan Gunthorpe #define SWITCHTEC_EVENT_FATAL    BIT(4)
229f37ab04SLogan Gunthorpe #define SWITCHTEC_EVENT_NOT_SUPP BIT(31)
235a1c269fSLogan Gunthorpe 
24f7eb7b8aSWesley Sheng #define SWITCHTEC_DMA_MRPC_EN	BIT(0)
25ce7c8860SKelvin Cao 
26ce7c8860SKelvin Cao #define MRPC_GAS_READ		0x29
27ce7c8860SKelvin Cao #define MRPC_GAS_WRITE		0x87
28ce7c8860SKelvin Cao #define MRPC_CMD_ID(x)		((x) & 0xffff)
29ce7c8860SKelvin Cao 
305a1c269fSLogan Gunthorpe enum {
315a1c269fSLogan Gunthorpe 	SWITCHTEC_GAS_MRPC_OFFSET       = 0x0000,
325a1c269fSLogan Gunthorpe 	SWITCHTEC_GAS_TOP_CFG_OFFSET    = 0x1000,
335a1c269fSLogan Gunthorpe 	SWITCHTEC_GAS_SW_EVENT_OFFSET   = 0x1800,
345a1c269fSLogan Gunthorpe 	SWITCHTEC_GAS_SYS_INFO_OFFSET   = 0x2000,
355a1c269fSLogan Gunthorpe 	SWITCHTEC_GAS_FLASH_INFO_OFFSET = 0x2200,
365a1c269fSLogan Gunthorpe 	SWITCHTEC_GAS_PART_CFG_OFFSET   = 0x4000,
375a1c269fSLogan Gunthorpe 	SWITCHTEC_GAS_NTB_OFFSET        = 0x10000,
385a1c269fSLogan Gunthorpe 	SWITCHTEC_GAS_PFF_CSR_OFFSET    = 0x134000,
395a1c269fSLogan Gunthorpe };
405a1c269fSLogan Gunthorpe 
41b13313a0SLogan Gunthorpe enum switchtec_gen {
42b13313a0SLogan Gunthorpe 	SWITCHTEC_GEN3,
43a3321ca3SLogan Gunthorpe 	SWITCHTEC_GEN4,
440fb53e64SKelvin Cao 	SWITCHTEC_GEN5,
45b13313a0SLogan Gunthorpe };
46b13313a0SLogan Gunthorpe 
475a1c269fSLogan Gunthorpe struct mrpc_regs {
485a1c269fSLogan Gunthorpe 	u8 input_data[SWITCHTEC_MRPC_PAYLOAD_SIZE];
495a1c269fSLogan Gunthorpe 	u8 output_data[SWITCHTEC_MRPC_PAYLOAD_SIZE];
505a1c269fSLogan Gunthorpe 	u32 cmd;
515a1c269fSLogan Gunthorpe 	u32 status;
525a1c269fSLogan Gunthorpe 	u32 ret_value;
53f7eb7b8aSWesley Sheng 	u32 dma_en;
54f7eb7b8aSWesley Sheng 	u64 dma_addr;
55f7eb7b8aSWesley Sheng 	u32 dma_vector;
56f7eb7b8aSWesley Sheng 	u32 dma_ver;
575a1c269fSLogan Gunthorpe } __packed;
585a1c269fSLogan Gunthorpe 
595a1c269fSLogan Gunthorpe enum mrpc_status {
605a1c269fSLogan Gunthorpe 	SWITCHTEC_MRPC_STATUS_INPROGRESS = 1,
615a1c269fSLogan Gunthorpe 	SWITCHTEC_MRPC_STATUS_DONE = 2,
625a1c269fSLogan Gunthorpe 	SWITCHTEC_MRPC_STATUS_ERROR = 0xFF,
635a1c269fSLogan Gunthorpe 	SWITCHTEC_MRPC_STATUS_INTERRUPTED = 0x100,
645a1c269fSLogan Gunthorpe };
655a1c269fSLogan Gunthorpe 
665a1c269fSLogan Gunthorpe struct sw_event_regs {
675a1c269fSLogan Gunthorpe 	u64 event_report_ctrl;
685a1c269fSLogan Gunthorpe 	u64 reserved1;
695a1c269fSLogan Gunthorpe 	u64 part_event_bitmap;
705a1c269fSLogan Gunthorpe 	u64 reserved2;
715a1c269fSLogan Gunthorpe 	u32 global_summary;
725a1c269fSLogan Gunthorpe 	u32 reserved3[3];
735a1c269fSLogan Gunthorpe 	u32 stack_error_event_hdr;
745a1c269fSLogan Gunthorpe 	u32 stack_error_event_data;
755a1c269fSLogan Gunthorpe 	u32 reserved4[4];
765a1c269fSLogan Gunthorpe 	u32 ppu_error_event_hdr;
775a1c269fSLogan Gunthorpe 	u32 ppu_error_event_data;
785a1c269fSLogan Gunthorpe 	u32 reserved5[4];
795a1c269fSLogan Gunthorpe 	u32 isp_error_event_hdr;
805a1c269fSLogan Gunthorpe 	u32 isp_error_event_data;
815a1c269fSLogan Gunthorpe 	u32 reserved6[4];
825a1c269fSLogan Gunthorpe 	u32 sys_reset_event_hdr;
835a1c269fSLogan Gunthorpe 	u32 reserved7[5];
845a1c269fSLogan Gunthorpe 	u32 fw_exception_hdr;
855a1c269fSLogan Gunthorpe 	u32 reserved8[5];
865a1c269fSLogan Gunthorpe 	u32 fw_nmi_hdr;
875a1c269fSLogan Gunthorpe 	u32 reserved9[5];
885a1c269fSLogan Gunthorpe 	u32 fw_non_fatal_hdr;
895a1c269fSLogan Gunthorpe 	u32 reserved10[5];
905a1c269fSLogan Gunthorpe 	u32 fw_fatal_hdr;
915a1c269fSLogan Gunthorpe 	u32 reserved11[5];
925a1c269fSLogan Gunthorpe 	u32 twi_mrpc_comp_hdr;
935a1c269fSLogan Gunthorpe 	u32 twi_mrpc_comp_data;
945a1c269fSLogan Gunthorpe 	u32 reserved12[4];
955a1c269fSLogan Gunthorpe 	u32 twi_mrpc_comp_async_hdr;
965a1c269fSLogan Gunthorpe 	u32 twi_mrpc_comp_async_data;
975a1c269fSLogan Gunthorpe 	u32 reserved13[4];
985a1c269fSLogan Gunthorpe 	u32 cli_mrpc_comp_hdr;
995a1c269fSLogan Gunthorpe 	u32 cli_mrpc_comp_data;
1005a1c269fSLogan Gunthorpe 	u32 reserved14[4];
1015a1c269fSLogan Gunthorpe 	u32 cli_mrpc_comp_async_hdr;
1025a1c269fSLogan Gunthorpe 	u32 cli_mrpc_comp_async_data;
1035a1c269fSLogan Gunthorpe 	u32 reserved15[4];
1045a1c269fSLogan Gunthorpe 	u32 gpio_interrupt_hdr;
1055a1c269fSLogan Gunthorpe 	u32 gpio_interrupt_data;
1065a1c269fSLogan Gunthorpe 	u32 reserved16[4];
107f0edce7aSLogan Gunthorpe 	u32 gfms_event_hdr;
108f0edce7aSLogan Gunthorpe 	u32 gfms_event_data;
109f0edce7aSLogan Gunthorpe 	u32 reserved17[4];
1105a1c269fSLogan Gunthorpe } __packed;
1115a1c269fSLogan Gunthorpe 
1125a1c269fSLogan Gunthorpe enum {
113fcccd282SLogan Gunthorpe 	SWITCHTEC_GEN3_CFG0_RUNNING = 0x04,
114fcccd282SLogan Gunthorpe 	SWITCHTEC_GEN3_CFG1_RUNNING = 0x05,
115fcccd282SLogan Gunthorpe 	SWITCHTEC_GEN3_IMG0_RUNNING = 0x03,
116fcccd282SLogan Gunthorpe 	SWITCHTEC_GEN3_IMG1_RUNNING = 0x07,
1175a1c269fSLogan Gunthorpe };
1185a1c269fSLogan Gunthorpe 
1194efa1d2eSKelvin Cao enum {
1204efa1d2eSKelvin Cao 	SWITCHTEC_GEN4_MAP0_RUNNING = 0x00,
1214efa1d2eSKelvin Cao 	SWITCHTEC_GEN4_MAP1_RUNNING = 0x01,
1224efa1d2eSKelvin Cao 	SWITCHTEC_GEN4_KEY0_RUNNING = 0x02,
1234efa1d2eSKelvin Cao 	SWITCHTEC_GEN4_KEY1_RUNNING = 0x03,
1244efa1d2eSKelvin Cao 	SWITCHTEC_GEN4_BL2_0_RUNNING = 0x04,
1254efa1d2eSKelvin Cao 	SWITCHTEC_GEN4_BL2_1_RUNNING = 0x05,
1264efa1d2eSKelvin Cao 	SWITCHTEC_GEN4_CFG0_RUNNING = 0x06,
1274efa1d2eSKelvin Cao 	SWITCHTEC_GEN4_CFG1_RUNNING = 0x07,
1284efa1d2eSKelvin Cao 	SWITCHTEC_GEN4_IMG0_RUNNING = 0x08,
1294efa1d2eSKelvin Cao 	SWITCHTEC_GEN4_IMG1_RUNNING = 0x09,
1304efa1d2eSKelvin Cao };
1314efa1d2eSKelvin Cao 
1324efa1d2eSKelvin Cao enum {
1334efa1d2eSKelvin Cao 	SWITCHTEC_GEN4_KEY0_ACTIVE = 0,
1344efa1d2eSKelvin Cao 	SWITCHTEC_GEN4_KEY1_ACTIVE = 1,
1354efa1d2eSKelvin Cao 	SWITCHTEC_GEN4_BL2_0_ACTIVE = 0,
1364efa1d2eSKelvin Cao 	SWITCHTEC_GEN4_BL2_1_ACTIVE = 1,
1374efa1d2eSKelvin Cao 	SWITCHTEC_GEN4_CFG0_ACTIVE = 0,
1384efa1d2eSKelvin Cao 	SWITCHTEC_GEN4_CFG1_ACTIVE = 1,
1394efa1d2eSKelvin Cao 	SWITCHTEC_GEN4_IMG0_ACTIVE = 0,
1404efa1d2eSKelvin Cao 	SWITCHTEC_GEN4_IMG1_ACTIVE = 1,
1414efa1d2eSKelvin Cao };
1424efa1d2eSKelvin Cao 
143993d208dSLogan Gunthorpe struct sys_info_regs_gen3 {
1445a1c269fSLogan Gunthorpe 	u32 reserved1;
1455a1c269fSLogan Gunthorpe 	u32 vendor_table_revision;
1465a1c269fSLogan Gunthorpe 	u32 table_format_version;
1475a1c269fSLogan Gunthorpe 	u32 partition_id;
1485a1c269fSLogan Gunthorpe 	u32 cfg_file_fmt_version;
1495a1c269fSLogan Gunthorpe 	u16 cfg_running;
1505a1c269fSLogan Gunthorpe 	u16 img_running;
1515a1c269fSLogan Gunthorpe 	u32 reserved2[57];
1525a1c269fSLogan Gunthorpe 	char vendor_id[8];
1535a1c269fSLogan Gunthorpe 	char product_id[16];
1545a1c269fSLogan Gunthorpe 	char product_revision[4];
1555a1c269fSLogan Gunthorpe 	char component_vendor[8];
1565a1c269fSLogan Gunthorpe 	u16 component_id;
1575a1c269fSLogan Gunthorpe 	u8 component_revision;
1585a1c269fSLogan Gunthorpe } __packed;
1595a1c269fSLogan Gunthorpe 
160a3321ca3SLogan Gunthorpe struct sys_info_regs_gen4 {
161a3321ca3SLogan Gunthorpe 	u16 gas_layout_ver;
162a3321ca3SLogan Gunthorpe 	u8 evlist_ver;
163a3321ca3SLogan Gunthorpe 	u8 reserved1;
164a3321ca3SLogan Gunthorpe 	u16 mgmt_cmd_set_ver;
165a3321ca3SLogan Gunthorpe 	u16 fabric_cmd_set_ver;
166a3321ca3SLogan Gunthorpe 	u32 reserved2[2];
167a3321ca3SLogan Gunthorpe 	u8 mrpc_uart_ver;
168a3321ca3SLogan Gunthorpe 	u8 mrpc_twi_ver;
169a3321ca3SLogan Gunthorpe 	u8 mrpc_eth_ver;
170a3321ca3SLogan Gunthorpe 	u8 mrpc_inband_ver;
171a3321ca3SLogan Gunthorpe 	u32 reserved3[7];
172a3321ca3SLogan Gunthorpe 	u32 fw_update_tmo;
173a3321ca3SLogan Gunthorpe 	u32 xml_version_cfg;
174a3321ca3SLogan Gunthorpe 	u32 xml_version_img;
175a3321ca3SLogan Gunthorpe 	u32 partition_id;
176a3321ca3SLogan Gunthorpe 	u16 bl2_running;
177a3321ca3SLogan Gunthorpe 	u16 cfg_running;
178a3321ca3SLogan Gunthorpe 	u16 img_running;
179a3321ca3SLogan Gunthorpe 	u16 key_running;
180a3321ca3SLogan Gunthorpe 	u32 reserved4[43];
181a3321ca3SLogan Gunthorpe 	u32 vendor_seeprom_twi;
182a3321ca3SLogan Gunthorpe 	u32 vendor_table_revision;
183a3321ca3SLogan Gunthorpe 	u32 vendor_specific_info[2];
184a3321ca3SLogan Gunthorpe 	u16 p2p_vendor_id;
185a3321ca3SLogan Gunthorpe 	u16 p2p_device_id;
186a3321ca3SLogan Gunthorpe 	u8 p2p_revision_id;
187a3321ca3SLogan Gunthorpe 	u8 reserved5[3];
188a3321ca3SLogan Gunthorpe 	u32 p2p_class_id;
189a3321ca3SLogan Gunthorpe 	u16 subsystem_vendor_id;
190a3321ca3SLogan Gunthorpe 	u16 subsystem_id;
191a3321ca3SLogan Gunthorpe 	u32 p2p_serial_number[2];
192a3321ca3SLogan Gunthorpe 	u8 mac_addr[6];
193a3321ca3SLogan Gunthorpe 	u8 reserved6[2];
194a3321ca3SLogan Gunthorpe 	u32 reserved7[3];
195a3321ca3SLogan Gunthorpe 	char vendor_id[8];
196a3321ca3SLogan Gunthorpe 	char product_id[24];
197a3321ca3SLogan Gunthorpe 	char  product_revision[2];
198a3321ca3SLogan Gunthorpe 	u16 reserved8;
199a3321ca3SLogan Gunthorpe } __packed;
200a3321ca3SLogan Gunthorpe 
201993d208dSLogan Gunthorpe struct sys_info_regs {
202993d208dSLogan Gunthorpe 	u32 device_id;
203993d208dSLogan Gunthorpe 	u32 device_version;
204993d208dSLogan Gunthorpe 	u32 firmware_version;
205993d208dSLogan Gunthorpe 	union {
206993d208dSLogan Gunthorpe 		struct sys_info_regs_gen3 gen3;
207a3321ca3SLogan Gunthorpe 		struct sys_info_regs_gen4 gen4;
208993d208dSLogan Gunthorpe 	};
209993d208dSLogan Gunthorpe } __packed;
210993d208dSLogan Gunthorpe 
211993d208dSLogan Gunthorpe struct partition_info {
212993d208dSLogan Gunthorpe 	u32 address;
213993d208dSLogan Gunthorpe 	u32 length;
214993d208dSLogan Gunthorpe };
215993d208dSLogan Gunthorpe 
216993d208dSLogan Gunthorpe struct flash_info_regs_gen3 {
2175a1c269fSLogan Gunthorpe 	u32 flash_part_map_upd_idx;
2185a1c269fSLogan Gunthorpe 
219993d208dSLogan Gunthorpe 	struct active_partition_info_gen3 {
2205a1c269fSLogan Gunthorpe 		u32 address;
2215a1c269fSLogan Gunthorpe 		u32 build_version;
2225a1c269fSLogan Gunthorpe 		u32 build_string;
2235a1c269fSLogan Gunthorpe 	} active_img;
2245a1c269fSLogan Gunthorpe 
225993d208dSLogan Gunthorpe 	struct active_partition_info_gen3 active_cfg;
226993d208dSLogan Gunthorpe 	struct active_partition_info_gen3 inactive_img;
227993d208dSLogan Gunthorpe 	struct active_partition_info_gen3 inactive_cfg;
2285a1c269fSLogan Gunthorpe 
2295a1c269fSLogan Gunthorpe 	u32 flash_length;
2305a1c269fSLogan Gunthorpe 
231993d208dSLogan Gunthorpe 	struct partition_info cfg0;
2325a1c269fSLogan Gunthorpe 	struct partition_info cfg1;
2335a1c269fSLogan Gunthorpe 	struct partition_info img0;
2345a1c269fSLogan Gunthorpe 	struct partition_info img1;
2355a1c269fSLogan Gunthorpe 	struct partition_info nvlog;
2365a1c269fSLogan Gunthorpe 	struct partition_info vendor[8];
2375a1c269fSLogan Gunthorpe };
2385a1c269fSLogan Gunthorpe 
2394efa1d2eSKelvin Cao struct flash_info_regs_gen4 {
2404efa1d2eSKelvin Cao 	u32 flash_address;
2414efa1d2eSKelvin Cao 	u32 flash_length;
2424efa1d2eSKelvin Cao 
2434efa1d2eSKelvin Cao 	struct active_partition_info_gen4 {
2444efa1d2eSKelvin Cao 		unsigned char bl2;
2454efa1d2eSKelvin Cao 		unsigned char cfg;
2464efa1d2eSKelvin Cao 		unsigned char img;
2474efa1d2eSKelvin Cao 		unsigned char key;
2484efa1d2eSKelvin Cao 	} active_flag;
2494efa1d2eSKelvin Cao 
2504efa1d2eSKelvin Cao 	u32 reserved[3];
2514efa1d2eSKelvin Cao 
2524efa1d2eSKelvin Cao 	struct partition_info map0;
2534efa1d2eSKelvin Cao 	struct partition_info map1;
2544efa1d2eSKelvin Cao 	struct partition_info key0;
2554efa1d2eSKelvin Cao 	struct partition_info key1;
2564efa1d2eSKelvin Cao 	struct partition_info bl2_0;
2574efa1d2eSKelvin Cao 	struct partition_info bl2_1;
2584efa1d2eSKelvin Cao 	struct partition_info cfg0;
2594efa1d2eSKelvin Cao 	struct partition_info cfg1;
2604efa1d2eSKelvin Cao 	struct partition_info img0;
2614efa1d2eSKelvin Cao 	struct partition_info img1;
2624efa1d2eSKelvin Cao 	struct partition_info nvlog;
2634efa1d2eSKelvin Cao 	struct partition_info vendor[8];
2644efa1d2eSKelvin Cao };
2654efa1d2eSKelvin Cao 
266993d208dSLogan Gunthorpe struct flash_info_regs {
267993d208dSLogan Gunthorpe 	union {
268993d208dSLogan Gunthorpe 		struct flash_info_regs_gen3 gen3;
2694efa1d2eSKelvin Cao 		struct flash_info_regs_gen4 gen4;
270993d208dSLogan Gunthorpe 	};
271993d208dSLogan Gunthorpe };
272993d208dSLogan Gunthorpe 
273c082b04cSLogan Gunthorpe enum {
274c082b04cSLogan Gunthorpe 	SWITCHTEC_NTB_REG_INFO_OFFSET   = 0x0000,
275c082b04cSLogan Gunthorpe 	SWITCHTEC_NTB_REG_CTRL_OFFSET   = 0x4000,
276c082b04cSLogan Gunthorpe 	SWITCHTEC_NTB_REG_DBMSG_OFFSET  = 0x64000,
277c082b04cSLogan Gunthorpe };
278c082b04cSLogan Gunthorpe 
2795a1c269fSLogan Gunthorpe struct ntb_info_regs {
2805a1c269fSLogan Gunthorpe 	u8  partition_count;
2815a1c269fSLogan Gunthorpe 	u8  partition_id;
2825a1c269fSLogan Gunthorpe 	u16 reserved1;
2835a1c269fSLogan Gunthorpe 	u64 ep_map;
2845a1c269fSLogan Gunthorpe 	u16 requester_id;
2853df54c87SKelvin Cao 	u16 reserved2;
2863df54c87SKelvin Cao 	u32 reserved3[4];
2873df54c87SKelvin Cao 	struct nt_partition_info {
2883df54c87SKelvin Cao 		u32 xlink_enabled;
2893df54c87SKelvin Cao 		u32 target_part_low;
2903df54c87SKelvin Cao 		u32 target_part_high;
2913df54c87SKelvin Cao 		u32 reserved;
2923df54c87SKelvin Cao 	} ntp_info[48];
2935a1c269fSLogan Gunthorpe } __packed;
2945a1c269fSLogan Gunthorpe 
2955a1c269fSLogan Gunthorpe struct part_cfg_regs {
2965a1c269fSLogan Gunthorpe 	u32 status;
2975a1c269fSLogan Gunthorpe 	u32 state;
2985a1c269fSLogan Gunthorpe 	u32 port_cnt;
2995a1c269fSLogan Gunthorpe 	u32 usp_port_mode;
3005a1c269fSLogan Gunthorpe 	u32 usp_pff_inst_id;
3015a1c269fSLogan Gunthorpe 	u32 vep_pff_inst_id;
3025a1c269fSLogan Gunthorpe 	u32 dsp_pff_inst_id[47];
3035a1c269fSLogan Gunthorpe 	u32 reserved1[11];
3045a1c269fSLogan Gunthorpe 	u16 vep_vector_number;
3055a1c269fSLogan Gunthorpe 	u16 usp_vector_number;
3065a1c269fSLogan Gunthorpe 	u32 port_event_bitmap;
3075a1c269fSLogan Gunthorpe 	u32 reserved2[3];
3085a1c269fSLogan Gunthorpe 	u32 part_event_summary;
3095a1c269fSLogan Gunthorpe 	u32 reserved3[3];
3105a1c269fSLogan Gunthorpe 	u32 part_reset_hdr;
3115a1c269fSLogan Gunthorpe 	u32 part_reset_data[5];
3125a1c269fSLogan Gunthorpe 	u32 mrpc_comp_hdr;
3135a1c269fSLogan Gunthorpe 	u32 mrpc_comp_data[5];
3145a1c269fSLogan Gunthorpe 	u32 mrpc_comp_async_hdr;
3155a1c269fSLogan Gunthorpe 	u32 mrpc_comp_async_data[5];
3165a1c269fSLogan Gunthorpe 	u32 dyn_binding_hdr;
3175a1c269fSLogan Gunthorpe 	u32 dyn_binding_data[5];
318a6b0ef9aSLogan Gunthorpe 	u32 intercomm_notify_hdr;
319a6b0ef9aSLogan Gunthorpe 	u32 intercomm_notify_data[5];
320a6b0ef9aSLogan Gunthorpe 	u32 reserved4[153];
3215a1c269fSLogan Gunthorpe } __packed;
3225a1c269fSLogan Gunthorpe 
3235a1c269fSLogan Gunthorpe enum {
324c082b04cSLogan Gunthorpe 	NTB_CTRL_PART_OP_LOCK = 0x1,
325c082b04cSLogan Gunthorpe 	NTB_CTRL_PART_OP_CFG = 0x2,
326c082b04cSLogan Gunthorpe 	NTB_CTRL_PART_OP_RESET = 0x3,
327c082b04cSLogan Gunthorpe 
328c082b04cSLogan Gunthorpe 	NTB_CTRL_PART_STATUS_NORMAL = 0x1,
329c082b04cSLogan Gunthorpe 	NTB_CTRL_PART_STATUS_LOCKED = 0x2,
330c082b04cSLogan Gunthorpe 	NTB_CTRL_PART_STATUS_LOCKING = 0x3,
331c082b04cSLogan Gunthorpe 	NTB_CTRL_PART_STATUS_CONFIGURING = 0x4,
332c082b04cSLogan Gunthorpe 	NTB_CTRL_PART_STATUS_RESETTING = 0x5,
333c082b04cSLogan Gunthorpe 
334c082b04cSLogan Gunthorpe 	NTB_CTRL_BAR_VALID = 1 << 0,
335c082b04cSLogan Gunthorpe 	NTB_CTRL_BAR_DIR_WIN_EN = 1 << 4,
336c082b04cSLogan Gunthorpe 	NTB_CTRL_BAR_LUT_WIN_EN = 1 << 5,
337c082b04cSLogan Gunthorpe 
338c082b04cSLogan Gunthorpe 	NTB_CTRL_REQ_ID_EN = 1 << 0,
339c082b04cSLogan Gunthorpe 
340c082b04cSLogan Gunthorpe 	NTB_CTRL_LUT_EN = 1 << 0,
341c082b04cSLogan Gunthorpe };
342c082b04cSLogan Gunthorpe 
343c082b04cSLogan Gunthorpe struct ntb_ctrl_regs {
344c082b04cSLogan Gunthorpe 	u32 partition_status;
345c082b04cSLogan Gunthorpe 	u32 partition_op;
346c082b04cSLogan Gunthorpe 	u32 partition_ctrl;
347c082b04cSLogan Gunthorpe 	u32 bar_setup;
348c082b04cSLogan Gunthorpe 	u32 bar_error;
349c082b04cSLogan Gunthorpe 	u16 lut_table_entries;
350c082b04cSLogan Gunthorpe 	u16 lut_table_offset;
351c082b04cSLogan Gunthorpe 	u32 lut_error;
352c082b04cSLogan Gunthorpe 	u16 req_id_table_size;
353c082b04cSLogan Gunthorpe 	u16 req_id_table_offset;
354c082b04cSLogan Gunthorpe 	u32 req_id_error;
355c082b04cSLogan Gunthorpe 	u32 reserved1[7];
356c082b04cSLogan Gunthorpe 	struct {
357c082b04cSLogan Gunthorpe 		u32 ctl;
358c082b04cSLogan Gunthorpe 		u32 win_size;
359c082b04cSLogan Gunthorpe 		u64 xlate_addr;
360c082b04cSLogan Gunthorpe 	} bar_entry[6];
361a2585cdcSPaul Selles 	struct {
362a2585cdcSPaul Selles 		u32 win_size;
363a2585cdcSPaul Selles 		u32 reserved[3];
364a2585cdcSPaul Selles 	} bar_ext_entry[6];
365a2585cdcSPaul Selles 	u32 reserved2[192];
366d123fab7SWesley Sheng 	u32 req_id_table[512];
367d123fab7SWesley Sheng 	u32 reserved3[256];
368c082b04cSLogan Gunthorpe 	u64 lut_entry[512];
369c082b04cSLogan Gunthorpe } __packed;
370c082b04cSLogan Gunthorpe 
371c082b04cSLogan Gunthorpe #define NTB_DBMSG_IMSG_STATUS BIT_ULL(32)
372c082b04cSLogan Gunthorpe #define NTB_DBMSG_IMSG_MASK   BIT_ULL(40)
373c082b04cSLogan Gunthorpe 
374c082b04cSLogan Gunthorpe struct ntb_dbmsg_regs {
375c082b04cSLogan Gunthorpe 	u32 reserved1[1024];
376c082b04cSLogan Gunthorpe 	u64 odb;
377c082b04cSLogan Gunthorpe 	u64 odb_mask;
378c082b04cSLogan Gunthorpe 	u64 idb;
379c082b04cSLogan Gunthorpe 	u64 idb_mask;
380c082b04cSLogan Gunthorpe 	u8  idb_vec_map[64];
381c082b04cSLogan Gunthorpe 	u32 msg_map;
382c082b04cSLogan Gunthorpe 	u32 reserved2;
383c082b04cSLogan Gunthorpe 	struct {
384c082b04cSLogan Gunthorpe 		u32 msg;
385c082b04cSLogan Gunthorpe 		u32 status;
386c082b04cSLogan Gunthorpe 	} omsg[4];
387c082b04cSLogan Gunthorpe 
388c082b04cSLogan Gunthorpe 	struct {
389c082b04cSLogan Gunthorpe 		u32 msg;
390c082b04cSLogan Gunthorpe 		u8  status;
391c082b04cSLogan Gunthorpe 		u8  mask;
392c082b04cSLogan Gunthorpe 		u8  src;
393c082b04cSLogan Gunthorpe 		u8  reserved;
394c082b04cSLogan Gunthorpe 	} imsg[4];
395c082b04cSLogan Gunthorpe 
396c082b04cSLogan Gunthorpe 	u8 reserved3[3928];
397c082b04cSLogan Gunthorpe 	u8 msix_table[1024];
398c082b04cSLogan Gunthorpe 	u8 reserved4[3072];
399c082b04cSLogan Gunthorpe 	u8 pba[24];
400c082b04cSLogan Gunthorpe 	u8 reserved5[4072];
401c082b04cSLogan Gunthorpe } __packed;
402c082b04cSLogan Gunthorpe 
403c082b04cSLogan Gunthorpe enum {
4045a1c269fSLogan Gunthorpe 	SWITCHTEC_PART_CFG_EVENT_RESET = 1 << 0,
4055a1c269fSLogan Gunthorpe 	SWITCHTEC_PART_CFG_EVENT_MRPC_CMP = 1 << 1,
4065a1c269fSLogan Gunthorpe 	SWITCHTEC_PART_CFG_EVENT_MRPC_ASYNC_CMP = 1 << 2,
4075a1c269fSLogan Gunthorpe 	SWITCHTEC_PART_CFG_EVENT_DYN_PART_CMP = 1 << 3,
4085a1c269fSLogan Gunthorpe };
4095a1c269fSLogan Gunthorpe 
4105a1c269fSLogan Gunthorpe struct pff_csr_regs {
4115a1c269fSLogan Gunthorpe 	u16 vendor_id;
4125a1c269fSLogan Gunthorpe 	u16 device_id;
41345f447deSLogan Gunthorpe 	u16 pcicmd;
41445f447deSLogan Gunthorpe 	u16 pcists;
41545f447deSLogan Gunthorpe 	u32 pci_class;
41645f447deSLogan Gunthorpe 	u32 pci_opts;
41745f447deSLogan Gunthorpe 	union {
41845f447deSLogan Gunthorpe 		u32 pci_bar[6];
41945f447deSLogan Gunthorpe 		u64 pci_bar64[3];
42045f447deSLogan Gunthorpe 	};
42145f447deSLogan Gunthorpe 	u32 pci_cardbus;
42245f447deSLogan Gunthorpe 	u32 pci_subsystem_id;
42345f447deSLogan Gunthorpe 	u32 pci_expansion_rom;
42445f447deSLogan Gunthorpe 	u32 pci_cap_ptr;
42545f447deSLogan Gunthorpe 	u32 reserved1;
42645f447deSLogan Gunthorpe 	u32 pci_irq;
4275a1c269fSLogan Gunthorpe 	u32 pci_cap_region[48];
4285a1c269fSLogan Gunthorpe 	u32 pcie_cap_region[448];
4295a1c269fSLogan Gunthorpe 	u32 indirect_gas_window[128];
4305a1c269fSLogan Gunthorpe 	u32 indirect_gas_window_off;
4315a1c269fSLogan Gunthorpe 	u32 reserved[127];
4325a1c269fSLogan Gunthorpe 	u32 pff_event_summary;
4335a1c269fSLogan Gunthorpe 	u32 reserved2[3];
4345a1c269fSLogan Gunthorpe 	u32 aer_in_p2p_hdr;
4355a1c269fSLogan Gunthorpe 	u32 aer_in_p2p_data[5];
4365a1c269fSLogan Gunthorpe 	u32 aer_in_vep_hdr;
4375a1c269fSLogan Gunthorpe 	u32 aer_in_vep_data[5];
4385a1c269fSLogan Gunthorpe 	u32 dpc_hdr;
4395a1c269fSLogan Gunthorpe 	u32 dpc_data[5];
4405a1c269fSLogan Gunthorpe 	u32 cts_hdr;
4415a1c269fSLogan Gunthorpe 	u32 cts_data[5];
442a6b0ef9aSLogan Gunthorpe 	u32 uec_hdr;
443a6b0ef9aSLogan Gunthorpe 	u32 uec_data[5];
4445a1c269fSLogan Gunthorpe 	u32 hotplug_hdr;
4455a1c269fSLogan Gunthorpe 	u32 hotplug_data[5];
4465a1c269fSLogan Gunthorpe 	u32 ier_hdr;
4475a1c269fSLogan Gunthorpe 	u32 ier_data[5];
4485a1c269fSLogan Gunthorpe 	u32 threshold_hdr;
4495a1c269fSLogan Gunthorpe 	u32 threshold_data[5];
4505a1c269fSLogan Gunthorpe 	u32 power_mgmt_hdr;
4515a1c269fSLogan Gunthorpe 	u32 power_mgmt_data[5];
4525a1c269fSLogan Gunthorpe 	u32 tlp_throttling_hdr;
4535a1c269fSLogan Gunthorpe 	u32 tlp_throttling_data[5];
4545a1c269fSLogan Gunthorpe 	u32 force_speed_hdr;
4555a1c269fSLogan Gunthorpe 	u32 force_speed_data[5];
4565a1c269fSLogan Gunthorpe 	u32 credit_timeout_hdr;
4575a1c269fSLogan Gunthorpe 	u32 credit_timeout_data[5];
4585a1c269fSLogan Gunthorpe 	u32 link_state_hdr;
4595a1c269fSLogan Gunthorpe 	u32 link_state_data[5];
4605a1c269fSLogan Gunthorpe 	u32 reserved4[174];
4615a1c269fSLogan Gunthorpe } __packed;
4625a1c269fSLogan Gunthorpe 
46333dea5aaSLogan Gunthorpe struct switchtec_ntb;
46433dea5aaSLogan Gunthorpe 
465f7eb7b8aSWesley Sheng struct dma_mrpc_output {
466f7eb7b8aSWesley Sheng 	u32 status;
467f7eb7b8aSWesley Sheng 	u32 cmd_id;
468f7eb7b8aSWesley Sheng 	u32 rtn_code;
469f7eb7b8aSWesley Sheng 	u32 output_size;
470f7eb7b8aSWesley Sheng 	u8 data[SWITCHTEC_MRPC_PAYLOAD_SIZE];
471f7eb7b8aSWesley Sheng };
472f7eb7b8aSWesley Sheng 
4735a1c269fSLogan Gunthorpe struct switchtec_dev {
4745a1c269fSLogan Gunthorpe 	struct pci_dev *pdev;
4755a1c269fSLogan Gunthorpe 	struct device dev;
4765a1c269fSLogan Gunthorpe 	struct cdev cdev;
4775a1c269fSLogan Gunthorpe 
478b13313a0SLogan Gunthorpe 	enum switchtec_gen gen;
479b13313a0SLogan Gunthorpe 
4805a1c269fSLogan Gunthorpe 	int partition;
4815a1c269fSLogan Gunthorpe 	int partition_count;
4825a1c269fSLogan Gunthorpe 	int pff_csr_count;
4835a1c269fSLogan Gunthorpe 	char pff_local[SWITCHTEC_MAX_PFF_CSR];
4845a1c269fSLogan Gunthorpe 
4855a1c269fSLogan Gunthorpe 	void __iomem *mmio;
4865a1c269fSLogan Gunthorpe 	struct mrpc_regs __iomem *mmio_mrpc;
4875a1c269fSLogan Gunthorpe 	struct sw_event_regs __iomem *mmio_sw_event;
4885a1c269fSLogan Gunthorpe 	struct sys_info_regs __iomem *mmio_sys_info;
4895a1c269fSLogan Gunthorpe 	struct flash_info_regs __iomem *mmio_flash_info;
4905a1c269fSLogan Gunthorpe 	struct ntb_info_regs __iomem *mmio_ntb;
4915a1c269fSLogan Gunthorpe 	struct part_cfg_regs __iomem *mmio_part_cfg;
4925a1c269fSLogan Gunthorpe 	struct part_cfg_regs __iomem *mmio_part_cfg_all;
4935a1c269fSLogan Gunthorpe 	struct pff_csr_regs __iomem *mmio_pff_csr;
4945a1c269fSLogan Gunthorpe 
4955a1c269fSLogan Gunthorpe 	/*
4965a1c269fSLogan Gunthorpe 	 * The mrpc mutex must be held when accessing the other
4975a1c269fSLogan Gunthorpe 	 * mrpc_ fields, alive flag and stuser->state field
4985a1c269fSLogan Gunthorpe 	 */
4995a1c269fSLogan Gunthorpe 	struct mutex mrpc_mutex;
5005a1c269fSLogan Gunthorpe 	struct list_head mrpc_queue;
5015a1c269fSLogan Gunthorpe 	int mrpc_busy;
5025a1c269fSLogan Gunthorpe 	struct work_struct mrpc_work;
5035a1c269fSLogan Gunthorpe 	struct delayed_work mrpc_timeout;
5045a1c269fSLogan Gunthorpe 	bool alive;
5055a1c269fSLogan Gunthorpe 
5065a1c269fSLogan Gunthorpe 	wait_queue_head_t event_wq;
5075a1c269fSLogan Gunthorpe 	atomic_t event_cnt;
50848c302dcSLogan Gunthorpe 
50948c302dcSLogan Gunthorpe 	struct work_struct link_event_work;
51048c302dcSLogan Gunthorpe 	void (*link_notifier)(struct switchtec_dev *stdev);
51148c302dcSLogan Gunthorpe 	u8 link_event_count[SWITCHTEC_MAX_PFF_CSR];
51233dea5aaSLogan Gunthorpe 
51333dea5aaSLogan Gunthorpe 	struct switchtec_ntb *sndev;
514f7eb7b8aSWesley Sheng 
515f7eb7b8aSWesley Sheng 	struct dma_mrpc_output *dma_mrpc;
516f7eb7b8aSWesley Sheng 	dma_addr_t dma_mrpc_dma_addr;
5175a1c269fSLogan Gunthorpe };
5185a1c269fSLogan Gunthorpe 
to_stdev(struct device * dev)5195a1c269fSLogan Gunthorpe static inline struct switchtec_dev *to_stdev(struct device *dev)
5205a1c269fSLogan Gunthorpe {
5215a1c269fSLogan Gunthorpe 	return container_of(dev, struct switchtec_dev, dev);
5225a1c269fSLogan Gunthorpe }
5235a1c269fSLogan Gunthorpe 
524*8a74e4eaSGreg Kroah-Hartman extern const struct class switchtec_class;
525302e994dSLogan Gunthorpe 
5265a1c269fSLogan Gunthorpe #endif
527