18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Microsemi Switchtec PCIe Driver 48c2ecf20Sopenharmony_ci * Copyright (c) 2017, Microsemi Corporation 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#ifndef _SWITCHTEC_H 88c2ecf20Sopenharmony_ci#define _SWITCHTEC_H 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/pci.h> 118c2ecf20Sopenharmony_ci#include <linux/cdev.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#define SWITCHTEC_MRPC_PAYLOAD_SIZE 1024 148c2ecf20Sopenharmony_ci#define SWITCHTEC_MAX_PFF_CSR 255 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#define SWITCHTEC_EVENT_OCCURRED BIT(0) 178c2ecf20Sopenharmony_ci#define SWITCHTEC_EVENT_CLEAR BIT(0) 188c2ecf20Sopenharmony_ci#define SWITCHTEC_EVENT_EN_LOG BIT(1) 198c2ecf20Sopenharmony_ci#define SWITCHTEC_EVENT_EN_CLI BIT(2) 208c2ecf20Sopenharmony_ci#define SWITCHTEC_EVENT_EN_IRQ BIT(3) 218c2ecf20Sopenharmony_ci#define SWITCHTEC_EVENT_FATAL BIT(4) 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define SWITCHTEC_DMA_MRPC_EN BIT(0) 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define MRPC_GAS_READ 0x29 268c2ecf20Sopenharmony_ci#define MRPC_GAS_WRITE 0x87 278c2ecf20Sopenharmony_ci#define MRPC_CMD_ID(x) ((x) & 0xffff) 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cienum { 308c2ecf20Sopenharmony_ci SWITCHTEC_GAS_MRPC_OFFSET = 0x0000, 318c2ecf20Sopenharmony_ci SWITCHTEC_GAS_TOP_CFG_OFFSET = 0x1000, 328c2ecf20Sopenharmony_ci SWITCHTEC_GAS_SW_EVENT_OFFSET = 0x1800, 338c2ecf20Sopenharmony_ci SWITCHTEC_GAS_SYS_INFO_OFFSET = 0x2000, 348c2ecf20Sopenharmony_ci SWITCHTEC_GAS_FLASH_INFO_OFFSET = 0x2200, 358c2ecf20Sopenharmony_ci SWITCHTEC_GAS_PART_CFG_OFFSET = 0x4000, 368c2ecf20Sopenharmony_ci SWITCHTEC_GAS_NTB_OFFSET = 0x10000, 378c2ecf20Sopenharmony_ci SWITCHTEC_GAS_PFF_CSR_OFFSET = 0x134000, 388c2ecf20Sopenharmony_ci}; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cienum switchtec_gen { 418c2ecf20Sopenharmony_ci SWITCHTEC_GEN3, 428c2ecf20Sopenharmony_ci SWITCHTEC_GEN4, 438c2ecf20Sopenharmony_ci}; 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistruct mrpc_regs { 468c2ecf20Sopenharmony_ci u8 input_data[SWITCHTEC_MRPC_PAYLOAD_SIZE]; 478c2ecf20Sopenharmony_ci u8 output_data[SWITCHTEC_MRPC_PAYLOAD_SIZE]; 488c2ecf20Sopenharmony_ci u32 cmd; 498c2ecf20Sopenharmony_ci u32 status; 508c2ecf20Sopenharmony_ci u32 ret_value; 518c2ecf20Sopenharmony_ci u32 dma_en; 528c2ecf20Sopenharmony_ci u64 dma_addr; 538c2ecf20Sopenharmony_ci u32 dma_vector; 548c2ecf20Sopenharmony_ci u32 dma_ver; 558c2ecf20Sopenharmony_ci} __packed; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_cienum mrpc_status { 588c2ecf20Sopenharmony_ci SWITCHTEC_MRPC_STATUS_INPROGRESS = 1, 598c2ecf20Sopenharmony_ci SWITCHTEC_MRPC_STATUS_DONE = 2, 608c2ecf20Sopenharmony_ci SWITCHTEC_MRPC_STATUS_ERROR = 0xFF, 618c2ecf20Sopenharmony_ci SWITCHTEC_MRPC_STATUS_INTERRUPTED = 0x100, 628c2ecf20Sopenharmony_ci}; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_cistruct sw_event_regs { 658c2ecf20Sopenharmony_ci u64 event_report_ctrl; 668c2ecf20Sopenharmony_ci u64 reserved1; 678c2ecf20Sopenharmony_ci u64 part_event_bitmap; 688c2ecf20Sopenharmony_ci u64 reserved2; 698c2ecf20Sopenharmony_ci u32 global_summary; 708c2ecf20Sopenharmony_ci u32 reserved3[3]; 718c2ecf20Sopenharmony_ci u32 stack_error_event_hdr; 728c2ecf20Sopenharmony_ci u32 stack_error_event_data; 738c2ecf20Sopenharmony_ci u32 reserved4[4]; 748c2ecf20Sopenharmony_ci u32 ppu_error_event_hdr; 758c2ecf20Sopenharmony_ci u32 ppu_error_event_data; 768c2ecf20Sopenharmony_ci u32 reserved5[4]; 778c2ecf20Sopenharmony_ci u32 isp_error_event_hdr; 788c2ecf20Sopenharmony_ci u32 isp_error_event_data; 798c2ecf20Sopenharmony_ci u32 reserved6[4]; 808c2ecf20Sopenharmony_ci u32 sys_reset_event_hdr; 818c2ecf20Sopenharmony_ci u32 reserved7[5]; 828c2ecf20Sopenharmony_ci u32 fw_exception_hdr; 838c2ecf20Sopenharmony_ci u32 reserved8[5]; 848c2ecf20Sopenharmony_ci u32 fw_nmi_hdr; 858c2ecf20Sopenharmony_ci u32 reserved9[5]; 868c2ecf20Sopenharmony_ci u32 fw_non_fatal_hdr; 878c2ecf20Sopenharmony_ci u32 reserved10[5]; 888c2ecf20Sopenharmony_ci u32 fw_fatal_hdr; 898c2ecf20Sopenharmony_ci u32 reserved11[5]; 908c2ecf20Sopenharmony_ci u32 twi_mrpc_comp_hdr; 918c2ecf20Sopenharmony_ci u32 twi_mrpc_comp_data; 928c2ecf20Sopenharmony_ci u32 reserved12[4]; 938c2ecf20Sopenharmony_ci u32 twi_mrpc_comp_async_hdr; 948c2ecf20Sopenharmony_ci u32 twi_mrpc_comp_async_data; 958c2ecf20Sopenharmony_ci u32 reserved13[4]; 968c2ecf20Sopenharmony_ci u32 cli_mrpc_comp_hdr; 978c2ecf20Sopenharmony_ci u32 cli_mrpc_comp_data; 988c2ecf20Sopenharmony_ci u32 reserved14[4]; 998c2ecf20Sopenharmony_ci u32 cli_mrpc_comp_async_hdr; 1008c2ecf20Sopenharmony_ci u32 cli_mrpc_comp_async_data; 1018c2ecf20Sopenharmony_ci u32 reserved15[4]; 1028c2ecf20Sopenharmony_ci u32 gpio_interrupt_hdr; 1038c2ecf20Sopenharmony_ci u32 gpio_interrupt_data; 1048c2ecf20Sopenharmony_ci u32 reserved16[4]; 1058c2ecf20Sopenharmony_ci u32 gfms_event_hdr; 1068c2ecf20Sopenharmony_ci u32 gfms_event_data; 1078c2ecf20Sopenharmony_ci u32 reserved17[4]; 1088c2ecf20Sopenharmony_ci} __packed; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_cienum { 1118c2ecf20Sopenharmony_ci SWITCHTEC_GEN3_CFG0_RUNNING = 0x04, 1128c2ecf20Sopenharmony_ci SWITCHTEC_GEN3_CFG1_RUNNING = 0x05, 1138c2ecf20Sopenharmony_ci SWITCHTEC_GEN3_IMG0_RUNNING = 0x03, 1148c2ecf20Sopenharmony_ci SWITCHTEC_GEN3_IMG1_RUNNING = 0x07, 1158c2ecf20Sopenharmony_ci}; 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_cienum { 1188c2ecf20Sopenharmony_ci SWITCHTEC_GEN4_MAP0_RUNNING = 0x00, 1198c2ecf20Sopenharmony_ci SWITCHTEC_GEN4_MAP1_RUNNING = 0x01, 1208c2ecf20Sopenharmony_ci SWITCHTEC_GEN4_KEY0_RUNNING = 0x02, 1218c2ecf20Sopenharmony_ci SWITCHTEC_GEN4_KEY1_RUNNING = 0x03, 1228c2ecf20Sopenharmony_ci SWITCHTEC_GEN4_BL2_0_RUNNING = 0x04, 1238c2ecf20Sopenharmony_ci SWITCHTEC_GEN4_BL2_1_RUNNING = 0x05, 1248c2ecf20Sopenharmony_ci SWITCHTEC_GEN4_CFG0_RUNNING = 0x06, 1258c2ecf20Sopenharmony_ci SWITCHTEC_GEN4_CFG1_RUNNING = 0x07, 1268c2ecf20Sopenharmony_ci SWITCHTEC_GEN4_IMG0_RUNNING = 0x08, 1278c2ecf20Sopenharmony_ci SWITCHTEC_GEN4_IMG1_RUNNING = 0x09, 1288c2ecf20Sopenharmony_ci}; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_cienum { 1318c2ecf20Sopenharmony_ci SWITCHTEC_GEN4_KEY0_ACTIVE = 0, 1328c2ecf20Sopenharmony_ci SWITCHTEC_GEN4_KEY1_ACTIVE = 1, 1338c2ecf20Sopenharmony_ci SWITCHTEC_GEN4_BL2_0_ACTIVE = 0, 1348c2ecf20Sopenharmony_ci SWITCHTEC_GEN4_BL2_1_ACTIVE = 1, 1358c2ecf20Sopenharmony_ci SWITCHTEC_GEN4_CFG0_ACTIVE = 0, 1368c2ecf20Sopenharmony_ci SWITCHTEC_GEN4_CFG1_ACTIVE = 1, 1378c2ecf20Sopenharmony_ci SWITCHTEC_GEN4_IMG0_ACTIVE = 0, 1388c2ecf20Sopenharmony_ci SWITCHTEC_GEN4_IMG1_ACTIVE = 1, 1398c2ecf20Sopenharmony_ci}; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_cistruct sys_info_regs_gen3 { 1428c2ecf20Sopenharmony_ci u32 reserved1; 1438c2ecf20Sopenharmony_ci u32 vendor_table_revision; 1448c2ecf20Sopenharmony_ci u32 table_format_version; 1458c2ecf20Sopenharmony_ci u32 partition_id; 1468c2ecf20Sopenharmony_ci u32 cfg_file_fmt_version; 1478c2ecf20Sopenharmony_ci u16 cfg_running; 1488c2ecf20Sopenharmony_ci u16 img_running; 1498c2ecf20Sopenharmony_ci u32 reserved2[57]; 1508c2ecf20Sopenharmony_ci char vendor_id[8]; 1518c2ecf20Sopenharmony_ci char product_id[16]; 1528c2ecf20Sopenharmony_ci char product_revision[4]; 1538c2ecf20Sopenharmony_ci char component_vendor[8]; 1548c2ecf20Sopenharmony_ci u16 component_id; 1558c2ecf20Sopenharmony_ci u8 component_revision; 1568c2ecf20Sopenharmony_ci} __packed; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_cistruct sys_info_regs_gen4 { 1598c2ecf20Sopenharmony_ci u16 gas_layout_ver; 1608c2ecf20Sopenharmony_ci u8 evlist_ver; 1618c2ecf20Sopenharmony_ci u8 reserved1; 1628c2ecf20Sopenharmony_ci u16 mgmt_cmd_set_ver; 1638c2ecf20Sopenharmony_ci u16 fabric_cmd_set_ver; 1648c2ecf20Sopenharmony_ci u32 reserved2[2]; 1658c2ecf20Sopenharmony_ci u8 mrpc_uart_ver; 1668c2ecf20Sopenharmony_ci u8 mrpc_twi_ver; 1678c2ecf20Sopenharmony_ci u8 mrpc_eth_ver; 1688c2ecf20Sopenharmony_ci u8 mrpc_inband_ver; 1698c2ecf20Sopenharmony_ci u32 reserved3[7]; 1708c2ecf20Sopenharmony_ci u32 fw_update_tmo; 1718c2ecf20Sopenharmony_ci u32 xml_version_cfg; 1728c2ecf20Sopenharmony_ci u32 xml_version_img; 1738c2ecf20Sopenharmony_ci u32 partition_id; 1748c2ecf20Sopenharmony_ci u16 bl2_running; 1758c2ecf20Sopenharmony_ci u16 cfg_running; 1768c2ecf20Sopenharmony_ci u16 img_running; 1778c2ecf20Sopenharmony_ci u16 key_running; 1788c2ecf20Sopenharmony_ci u32 reserved4[43]; 1798c2ecf20Sopenharmony_ci u32 vendor_seeprom_twi; 1808c2ecf20Sopenharmony_ci u32 vendor_table_revision; 1818c2ecf20Sopenharmony_ci u32 vendor_specific_info[2]; 1828c2ecf20Sopenharmony_ci u16 p2p_vendor_id; 1838c2ecf20Sopenharmony_ci u16 p2p_device_id; 1848c2ecf20Sopenharmony_ci u8 p2p_revision_id; 1858c2ecf20Sopenharmony_ci u8 reserved5[3]; 1868c2ecf20Sopenharmony_ci u32 p2p_class_id; 1878c2ecf20Sopenharmony_ci u16 subsystem_vendor_id; 1888c2ecf20Sopenharmony_ci u16 subsystem_id; 1898c2ecf20Sopenharmony_ci u32 p2p_serial_number[2]; 1908c2ecf20Sopenharmony_ci u8 mac_addr[6]; 1918c2ecf20Sopenharmony_ci u8 reserved6[2]; 1928c2ecf20Sopenharmony_ci u32 reserved7[3]; 1938c2ecf20Sopenharmony_ci char vendor_id[8]; 1948c2ecf20Sopenharmony_ci char product_id[24]; 1958c2ecf20Sopenharmony_ci char product_revision[2]; 1968c2ecf20Sopenharmony_ci u16 reserved8; 1978c2ecf20Sopenharmony_ci} __packed; 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_cistruct sys_info_regs { 2008c2ecf20Sopenharmony_ci u32 device_id; 2018c2ecf20Sopenharmony_ci u32 device_version; 2028c2ecf20Sopenharmony_ci u32 firmware_version; 2038c2ecf20Sopenharmony_ci union { 2048c2ecf20Sopenharmony_ci struct sys_info_regs_gen3 gen3; 2058c2ecf20Sopenharmony_ci struct sys_info_regs_gen4 gen4; 2068c2ecf20Sopenharmony_ci }; 2078c2ecf20Sopenharmony_ci} __packed; 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_cistruct partition_info { 2108c2ecf20Sopenharmony_ci u32 address; 2118c2ecf20Sopenharmony_ci u32 length; 2128c2ecf20Sopenharmony_ci}; 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_cistruct flash_info_regs_gen3 { 2158c2ecf20Sopenharmony_ci u32 flash_part_map_upd_idx; 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci struct active_partition_info_gen3 { 2188c2ecf20Sopenharmony_ci u32 address; 2198c2ecf20Sopenharmony_ci u32 build_version; 2208c2ecf20Sopenharmony_ci u32 build_string; 2218c2ecf20Sopenharmony_ci } active_img; 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci struct active_partition_info_gen3 active_cfg; 2248c2ecf20Sopenharmony_ci struct active_partition_info_gen3 inactive_img; 2258c2ecf20Sopenharmony_ci struct active_partition_info_gen3 inactive_cfg; 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci u32 flash_length; 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci struct partition_info cfg0; 2308c2ecf20Sopenharmony_ci struct partition_info cfg1; 2318c2ecf20Sopenharmony_ci struct partition_info img0; 2328c2ecf20Sopenharmony_ci struct partition_info img1; 2338c2ecf20Sopenharmony_ci struct partition_info nvlog; 2348c2ecf20Sopenharmony_ci struct partition_info vendor[8]; 2358c2ecf20Sopenharmony_ci}; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_cistruct flash_info_regs_gen4 { 2388c2ecf20Sopenharmony_ci u32 flash_address; 2398c2ecf20Sopenharmony_ci u32 flash_length; 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci struct active_partition_info_gen4 { 2428c2ecf20Sopenharmony_ci unsigned char bl2; 2438c2ecf20Sopenharmony_ci unsigned char cfg; 2448c2ecf20Sopenharmony_ci unsigned char img; 2458c2ecf20Sopenharmony_ci unsigned char key; 2468c2ecf20Sopenharmony_ci } active_flag; 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci u32 reserved[3]; 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci struct partition_info map0; 2518c2ecf20Sopenharmony_ci struct partition_info map1; 2528c2ecf20Sopenharmony_ci struct partition_info key0; 2538c2ecf20Sopenharmony_ci struct partition_info key1; 2548c2ecf20Sopenharmony_ci struct partition_info bl2_0; 2558c2ecf20Sopenharmony_ci struct partition_info bl2_1; 2568c2ecf20Sopenharmony_ci struct partition_info cfg0; 2578c2ecf20Sopenharmony_ci struct partition_info cfg1; 2588c2ecf20Sopenharmony_ci struct partition_info img0; 2598c2ecf20Sopenharmony_ci struct partition_info img1; 2608c2ecf20Sopenharmony_ci struct partition_info nvlog; 2618c2ecf20Sopenharmony_ci struct partition_info vendor[8]; 2628c2ecf20Sopenharmony_ci}; 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_cistruct flash_info_regs { 2658c2ecf20Sopenharmony_ci union { 2668c2ecf20Sopenharmony_ci struct flash_info_regs_gen3 gen3; 2678c2ecf20Sopenharmony_ci struct flash_info_regs_gen4 gen4; 2688c2ecf20Sopenharmony_ci }; 2698c2ecf20Sopenharmony_ci}; 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_cienum { 2728c2ecf20Sopenharmony_ci SWITCHTEC_NTB_REG_INFO_OFFSET = 0x0000, 2738c2ecf20Sopenharmony_ci SWITCHTEC_NTB_REG_CTRL_OFFSET = 0x4000, 2748c2ecf20Sopenharmony_ci SWITCHTEC_NTB_REG_DBMSG_OFFSET = 0x64000, 2758c2ecf20Sopenharmony_ci}; 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_cistruct ntb_info_regs { 2788c2ecf20Sopenharmony_ci u8 partition_count; 2798c2ecf20Sopenharmony_ci u8 partition_id; 2808c2ecf20Sopenharmony_ci u16 reserved1; 2818c2ecf20Sopenharmony_ci u64 ep_map; 2828c2ecf20Sopenharmony_ci u16 requester_id; 2838c2ecf20Sopenharmony_ci u16 reserved2; 2848c2ecf20Sopenharmony_ci u32 reserved3[4]; 2858c2ecf20Sopenharmony_ci struct nt_partition_info { 2868c2ecf20Sopenharmony_ci u32 xlink_enabled; 2878c2ecf20Sopenharmony_ci u32 target_part_low; 2888c2ecf20Sopenharmony_ci u32 target_part_high; 2898c2ecf20Sopenharmony_ci u32 reserved; 2908c2ecf20Sopenharmony_ci } ntp_info[48]; 2918c2ecf20Sopenharmony_ci} __packed; 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_cistruct part_cfg_regs { 2948c2ecf20Sopenharmony_ci u32 status; 2958c2ecf20Sopenharmony_ci u32 state; 2968c2ecf20Sopenharmony_ci u32 port_cnt; 2978c2ecf20Sopenharmony_ci u32 usp_port_mode; 2988c2ecf20Sopenharmony_ci u32 usp_pff_inst_id; 2998c2ecf20Sopenharmony_ci u32 vep_pff_inst_id; 3008c2ecf20Sopenharmony_ci u32 dsp_pff_inst_id[47]; 3018c2ecf20Sopenharmony_ci u32 reserved1[11]; 3028c2ecf20Sopenharmony_ci u16 vep_vector_number; 3038c2ecf20Sopenharmony_ci u16 usp_vector_number; 3048c2ecf20Sopenharmony_ci u32 port_event_bitmap; 3058c2ecf20Sopenharmony_ci u32 reserved2[3]; 3068c2ecf20Sopenharmony_ci u32 part_event_summary; 3078c2ecf20Sopenharmony_ci u32 reserved3[3]; 3088c2ecf20Sopenharmony_ci u32 part_reset_hdr; 3098c2ecf20Sopenharmony_ci u32 part_reset_data[5]; 3108c2ecf20Sopenharmony_ci u32 mrpc_comp_hdr; 3118c2ecf20Sopenharmony_ci u32 mrpc_comp_data[5]; 3128c2ecf20Sopenharmony_ci u32 mrpc_comp_async_hdr; 3138c2ecf20Sopenharmony_ci u32 mrpc_comp_async_data[5]; 3148c2ecf20Sopenharmony_ci u32 dyn_binding_hdr; 3158c2ecf20Sopenharmony_ci u32 dyn_binding_data[5]; 3168c2ecf20Sopenharmony_ci u32 intercomm_notify_hdr; 3178c2ecf20Sopenharmony_ci u32 intercomm_notify_data[5]; 3188c2ecf20Sopenharmony_ci u32 reserved4[153]; 3198c2ecf20Sopenharmony_ci} __packed; 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_cienum { 3228c2ecf20Sopenharmony_ci NTB_CTRL_PART_OP_LOCK = 0x1, 3238c2ecf20Sopenharmony_ci NTB_CTRL_PART_OP_CFG = 0x2, 3248c2ecf20Sopenharmony_ci NTB_CTRL_PART_OP_RESET = 0x3, 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci NTB_CTRL_PART_STATUS_NORMAL = 0x1, 3278c2ecf20Sopenharmony_ci NTB_CTRL_PART_STATUS_LOCKED = 0x2, 3288c2ecf20Sopenharmony_ci NTB_CTRL_PART_STATUS_LOCKING = 0x3, 3298c2ecf20Sopenharmony_ci NTB_CTRL_PART_STATUS_CONFIGURING = 0x4, 3308c2ecf20Sopenharmony_ci NTB_CTRL_PART_STATUS_RESETTING = 0x5, 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci NTB_CTRL_BAR_VALID = 1 << 0, 3338c2ecf20Sopenharmony_ci NTB_CTRL_BAR_DIR_WIN_EN = 1 << 4, 3348c2ecf20Sopenharmony_ci NTB_CTRL_BAR_LUT_WIN_EN = 1 << 5, 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci NTB_CTRL_REQ_ID_EN = 1 << 0, 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci NTB_CTRL_LUT_EN = 1 << 0, 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci NTB_PART_CTRL_ID_PROT_DIS = 1 << 0, 3418c2ecf20Sopenharmony_ci}; 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_cistruct ntb_ctrl_regs { 3448c2ecf20Sopenharmony_ci u32 partition_status; 3458c2ecf20Sopenharmony_ci u32 partition_op; 3468c2ecf20Sopenharmony_ci u32 partition_ctrl; 3478c2ecf20Sopenharmony_ci u32 bar_setup; 3488c2ecf20Sopenharmony_ci u32 bar_error; 3498c2ecf20Sopenharmony_ci u16 lut_table_entries; 3508c2ecf20Sopenharmony_ci u16 lut_table_offset; 3518c2ecf20Sopenharmony_ci u32 lut_error; 3528c2ecf20Sopenharmony_ci u16 req_id_table_size; 3538c2ecf20Sopenharmony_ci u16 req_id_table_offset; 3548c2ecf20Sopenharmony_ci u32 req_id_error; 3558c2ecf20Sopenharmony_ci u32 reserved1[7]; 3568c2ecf20Sopenharmony_ci struct { 3578c2ecf20Sopenharmony_ci u32 ctl; 3588c2ecf20Sopenharmony_ci u32 win_size; 3598c2ecf20Sopenharmony_ci u64 xlate_addr; 3608c2ecf20Sopenharmony_ci } bar_entry[6]; 3618c2ecf20Sopenharmony_ci struct { 3628c2ecf20Sopenharmony_ci u32 win_size; 3638c2ecf20Sopenharmony_ci u32 reserved[3]; 3648c2ecf20Sopenharmony_ci } bar_ext_entry[6]; 3658c2ecf20Sopenharmony_ci u32 reserved2[192]; 3668c2ecf20Sopenharmony_ci u32 req_id_table[512]; 3678c2ecf20Sopenharmony_ci u32 reserved3[256]; 3688c2ecf20Sopenharmony_ci u64 lut_entry[512]; 3698c2ecf20Sopenharmony_ci} __packed; 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci#define NTB_DBMSG_IMSG_STATUS BIT_ULL(32) 3728c2ecf20Sopenharmony_ci#define NTB_DBMSG_IMSG_MASK BIT_ULL(40) 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_cistruct ntb_dbmsg_regs { 3758c2ecf20Sopenharmony_ci u32 reserved1[1024]; 3768c2ecf20Sopenharmony_ci u64 odb; 3778c2ecf20Sopenharmony_ci u64 odb_mask; 3788c2ecf20Sopenharmony_ci u64 idb; 3798c2ecf20Sopenharmony_ci u64 idb_mask; 3808c2ecf20Sopenharmony_ci u8 idb_vec_map[64]; 3818c2ecf20Sopenharmony_ci u32 msg_map; 3828c2ecf20Sopenharmony_ci u32 reserved2; 3838c2ecf20Sopenharmony_ci struct { 3848c2ecf20Sopenharmony_ci u32 msg; 3858c2ecf20Sopenharmony_ci u32 status; 3868c2ecf20Sopenharmony_ci } omsg[4]; 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci struct { 3898c2ecf20Sopenharmony_ci u32 msg; 3908c2ecf20Sopenharmony_ci u8 status; 3918c2ecf20Sopenharmony_ci u8 mask; 3928c2ecf20Sopenharmony_ci u8 src; 3938c2ecf20Sopenharmony_ci u8 reserved; 3948c2ecf20Sopenharmony_ci } imsg[4]; 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci u8 reserved3[3928]; 3978c2ecf20Sopenharmony_ci u8 msix_table[1024]; 3988c2ecf20Sopenharmony_ci u8 reserved4[3072]; 3998c2ecf20Sopenharmony_ci u8 pba[24]; 4008c2ecf20Sopenharmony_ci u8 reserved5[4072]; 4018c2ecf20Sopenharmony_ci} __packed; 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_cienum { 4048c2ecf20Sopenharmony_ci SWITCHTEC_PART_CFG_EVENT_RESET = 1 << 0, 4058c2ecf20Sopenharmony_ci SWITCHTEC_PART_CFG_EVENT_MRPC_CMP = 1 << 1, 4068c2ecf20Sopenharmony_ci SWITCHTEC_PART_CFG_EVENT_MRPC_ASYNC_CMP = 1 << 2, 4078c2ecf20Sopenharmony_ci SWITCHTEC_PART_CFG_EVENT_DYN_PART_CMP = 1 << 3, 4088c2ecf20Sopenharmony_ci}; 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_cistruct pff_csr_regs { 4118c2ecf20Sopenharmony_ci u16 vendor_id; 4128c2ecf20Sopenharmony_ci u16 device_id; 4138c2ecf20Sopenharmony_ci u16 pcicmd; 4148c2ecf20Sopenharmony_ci u16 pcists; 4158c2ecf20Sopenharmony_ci u32 pci_class; 4168c2ecf20Sopenharmony_ci u32 pci_opts; 4178c2ecf20Sopenharmony_ci union { 4188c2ecf20Sopenharmony_ci u32 pci_bar[6]; 4198c2ecf20Sopenharmony_ci u64 pci_bar64[3]; 4208c2ecf20Sopenharmony_ci }; 4218c2ecf20Sopenharmony_ci u32 pci_cardbus; 4228c2ecf20Sopenharmony_ci u32 pci_subsystem_id; 4238c2ecf20Sopenharmony_ci u32 pci_expansion_rom; 4248c2ecf20Sopenharmony_ci u32 pci_cap_ptr; 4258c2ecf20Sopenharmony_ci u32 reserved1; 4268c2ecf20Sopenharmony_ci u32 pci_irq; 4278c2ecf20Sopenharmony_ci u32 pci_cap_region[48]; 4288c2ecf20Sopenharmony_ci u32 pcie_cap_region[448]; 4298c2ecf20Sopenharmony_ci u32 indirect_gas_window[128]; 4308c2ecf20Sopenharmony_ci u32 indirect_gas_window_off; 4318c2ecf20Sopenharmony_ci u32 reserved[127]; 4328c2ecf20Sopenharmony_ci u32 pff_event_summary; 4338c2ecf20Sopenharmony_ci u32 reserved2[3]; 4348c2ecf20Sopenharmony_ci u32 aer_in_p2p_hdr; 4358c2ecf20Sopenharmony_ci u32 aer_in_p2p_data[5]; 4368c2ecf20Sopenharmony_ci u32 aer_in_vep_hdr; 4378c2ecf20Sopenharmony_ci u32 aer_in_vep_data[5]; 4388c2ecf20Sopenharmony_ci u32 dpc_hdr; 4398c2ecf20Sopenharmony_ci u32 dpc_data[5]; 4408c2ecf20Sopenharmony_ci u32 cts_hdr; 4418c2ecf20Sopenharmony_ci u32 cts_data[5]; 4428c2ecf20Sopenharmony_ci u32 uec_hdr; 4438c2ecf20Sopenharmony_ci u32 uec_data[5]; 4448c2ecf20Sopenharmony_ci u32 hotplug_hdr; 4458c2ecf20Sopenharmony_ci u32 hotplug_data[5]; 4468c2ecf20Sopenharmony_ci u32 ier_hdr; 4478c2ecf20Sopenharmony_ci u32 ier_data[5]; 4488c2ecf20Sopenharmony_ci u32 threshold_hdr; 4498c2ecf20Sopenharmony_ci u32 threshold_data[5]; 4508c2ecf20Sopenharmony_ci u32 power_mgmt_hdr; 4518c2ecf20Sopenharmony_ci u32 power_mgmt_data[5]; 4528c2ecf20Sopenharmony_ci u32 tlp_throttling_hdr; 4538c2ecf20Sopenharmony_ci u32 tlp_throttling_data[5]; 4548c2ecf20Sopenharmony_ci u32 force_speed_hdr; 4558c2ecf20Sopenharmony_ci u32 force_speed_data[5]; 4568c2ecf20Sopenharmony_ci u32 credit_timeout_hdr; 4578c2ecf20Sopenharmony_ci u32 credit_timeout_data[5]; 4588c2ecf20Sopenharmony_ci u32 link_state_hdr; 4598c2ecf20Sopenharmony_ci u32 link_state_data[5]; 4608c2ecf20Sopenharmony_ci u32 reserved4[174]; 4618c2ecf20Sopenharmony_ci} __packed; 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_cistruct switchtec_ntb; 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_cistruct dma_mrpc_output { 4668c2ecf20Sopenharmony_ci u32 status; 4678c2ecf20Sopenharmony_ci u32 cmd_id; 4688c2ecf20Sopenharmony_ci u32 rtn_code; 4698c2ecf20Sopenharmony_ci u32 output_size; 4708c2ecf20Sopenharmony_ci u8 data[SWITCHTEC_MRPC_PAYLOAD_SIZE]; 4718c2ecf20Sopenharmony_ci}; 4728c2ecf20Sopenharmony_ci 4738c2ecf20Sopenharmony_cistruct switchtec_dev { 4748c2ecf20Sopenharmony_ci struct pci_dev *pdev; 4758c2ecf20Sopenharmony_ci struct device dev; 4768c2ecf20Sopenharmony_ci struct cdev cdev; 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_ci enum switchtec_gen gen; 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci int partition; 4818c2ecf20Sopenharmony_ci int partition_count; 4828c2ecf20Sopenharmony_ci int pff_csr_count; 4838c2ecf20Sopenharmony_ci char pff_local[SWITCHTEC_MAX_PFF_CSR]; 4848c2ecf20Sopenharmony_ci 4858c2ecf20Sopenharmony_ci void __iomem *mmio; 4868c2ecf20Sopenharmony_ci struct mrpc_regs __iomem *mmio_mrpc; 4878c2ecf20Sopenharmony_ci struct sw_event_regs __iomem *mmio_sw_event; 4888c2ecf20Sopenharmony_ci struct sys_info_regs __iomem *mmio_sys_info; 4898c2ecf20Sopenharmony_ci struct flash_info_regs __iomem *mmio_flash_info; 4908c2ecf20Sopenharmony_ci struct ntb_info_regs __iomem *mmio_ntb; 4918c2ecf20Sopenharmony_ci struct part_cfg_regs __iomem *mmio_part_cfg; 4928c2ecf20Sopenharmony_ci struct part_cfg_regs __iomem *mmio_part_cfg_all; 4938c2ecf20Sopenharmony_ci struct pff_csr_regs __iomem *mmio_pff_csr; 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ci /* 4968c2ecf20Sopenharmony_ci * The mrpc mutex must be held when accessing the other 4978c2ecf20Sopenharmony_ci * mrpc_ fields, alive flag and stuser->state field 4988c2ecf20Sopenharmony_ci */ 4998c2ecf20Sopenharmony_ci struct mutex mrpc_mutex; 5008c2ecf20Sopenharmony_ci struct list_head mrpc_queue; 5018c2ecf20Sopenharmony_ci int mrpc_busy; 5028c2ecf20Sopenharmony_ci struct work_struct mrpc_work; 5038c2ecf20Sopenharmony_ci struct delayed_work mrpc_timeout; 5048c2ecf20Sopenharmony_ci bool alive; 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_ci wait_queue_head_t event_wq; 5078c2ecf20Sopenharmony_ci atomic_t event_cnt; 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci struct work_struct link_event_work; 5108c2ecf20Sopenharmony_ci void (*link_notifier)(struct switchtec_dev *stdev); 5118c2ecf20Sopenharmony_ci u8 link_event_count[SWITCHTEC_MAX_PFF_CSR]; 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_ci struct switchtec_ntb *sndev; 5148c2ecf20Sopenharmony_ci 5158c2ecf20Sopenharmony_ci struct dma_mrpc_output *dma_mrpc; 5168c2ecf20Sopenharmony_ci dma_addr_t dma_mrpc_dma_addr; 5178c2ecf20Sopenharmony_ci}; 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_cistatic inline struct switchtec_dev *to_stdev(struct device *dev) 5208c2ecf20Sopenharmony_ci{ 5218c2ecf20Sopenharmony_ci return container_of(dev, struct switchtec_dev, dev); 5228c2ecf20Sopenharmony_ci} 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ciextern struct class *switchtec_class; 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_ci#endif 527