1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Microsemi Switchtec PCIe Driver
4 * Copyright (c) 2017, Microsemi Corporation
10 #include <linux/pci.h>
11 #include <linux/cdev.h>
13 #define SWITCHTEC_MRPC_PAYLOAD_SIZE 1024
14 #define SWITCHTEC_MAX_PFF_CSR 255
16 #define SWITCHTEC_EVENT_OCCURRED BIT(0)
17 #define SWITCHTEC_EVENT_CLEAR BIT(0)
18 #define SWITCHTEC_EVENT_EN_LOG BIT(1)
19 #define SWITCHTEC_EVENT_EN_CLI BIT(2)
20 #define SWITCHTEC_EVENT_EN_IRQ BIT(3)
21 #define SWITCHTEC_EVENT_FATAL BIT(4)
23 #define SWITCHTEC_DMA_MRPC_EN BIT(0)
25 SWITCHTEC_GAS_MRPC_OFFSET = 0x0000,
26 SWITCHTEC_GAS_TOP_CFG_OFFSET = 0x1000,
27 SWITCHTEC_GAS_SW_EVENT_OFFSET = 0x1800,
28 SWITCHTEC_GAS_SYS_INFO_OFFSET = 0x2000,
29 SWITCHTEC_GAS_FLASH_INFO_OFFSET = 0x2200,
30 SWITCHTEC_GAS_PART_CFG_OFFSET = 0x4000,
31 SWITCHTEC_GAS_NTB_OFFSET = 0x10000,
32 SWITCHTEC_GAS_PFF_CSR_OFFSET = 0x134000,
41 u8 input_data[SWITCHTEC_MRPC_PAYLOAD_SIZE];
42 u8 output_data[SWITCHTEC_MRPC_PAYLOAD_SIZE];
53 SWITCHTEC_MRPC_STATUS_INPROGRESS = 1,
54 SWITCHTEC_MRPC_STATUS_DONE = 2,
55 SWITCHTEC_MRPC_STATUS_ERROR = 0xFF,
56 SWITCHTEC_MRPC_STATUS_INTERRUPTED = 0x100,
59 struct sw_event_regs {
60 u64 event_report_ctrl;
62 u64 part_event_bitmap;
66 u32 stack_error_event_hdr;
67 u32 stack_error_event_data;
69 u32 ppu_error_event_hdr;
70 u32 ppu_error_event_data;
72 u32 isp_error_event_hdr;
73 u32 isp_error_event_data;
75 u32 sys_reset_event_hdr;
85 u32 twi_mrpc_comp_hdr;
86 u32 twi_mrpc_comp_data;
88 u32 twi_mrpc_comp_async_hdr;
89 u32 twi_mrpc_comp_async_data;
91 u32 cli_mrpc_comp_hdr;
92 u32 cli_mrpc_comp_data;
94 u32 cli_mrpc_comp_async_hdr;
95 u32 cli_mrpc_comp_async_data;
97 u32 gpio_interrupt_hdr;
98 u32 gpio_interrupt_data;
106 SWITCHTEC_GEN3_CFG0_RUNNING = 0x04,
107 SWITCHTEC_GEN3_CFG1_RUNNING = 0x05,
108 SWITCHTEC_GEN3_IMG0_RUNNING = 0x03,
109 SWITCHTEC_GEN3_IMG1_RUNNING = 0x07,
112 struct sys_info_regs_gen3 {
114 u32 vendor_table_revision;
115 u32 table_format_version;
117 u32 cfg_file_fmt_version;
123 char product_revision[4];
124 char component_vendor[8];
126 u8 component_revision;
129 struct sys_info_regs_gen4 {
133 u16 mgmt_cmd_set_ver;
134 u16 fabric_cmd_set_ver;
150 u32 vendor_seeprom_twi;
151 u32 vendor_table_revision;
152 u32 vendor_specific_info[2];
158 u16 subsystem_vendor_id;
160 u32 p2p_serial_number[2];
166 char product_revision[2];
170 struct sys_info_regs {
173 u32 firmware_version;
175 struct sys_info_regs_gen3 gen3;
176 struct sys_info_regs_gen4 gen4;
180 struct partition_info {
185 struct flash_info_regs_gen3 {
186 u32 flash_part_map_upd_idx;
188 struct active_partition_info_gen3 {
194 struct active_partition_info_gen3 active_cfg;
195 struct active_partition_info_gen3 inactive_img;
196 struct active_partition_info_gen3 inactive_cfg;
200 struct partition_info cfg0;
201 struct partition_info cfg1;
202 struct partition_info img0;
203 struct partition_info img1;
204 struct partition_info nvlog;
205 struct partition_info vendor[8];
208 struct flash_info_regs {
210 struct flash_info_regs_gen3 gen3;
215 SWITCHTEC_NTB_REG_INFO_OFFSET = 0x0000,
216 SWITCHTEC_NTB_REG_CTRL_OFFSET = 0x4000,
217 SWITCHTEC_NTB_REG_DBMSG_OFFSET = 0x64000,
220 struct ntb_info_regs {
228 struct nt_partition_info {
231 u32 target_part_high;
236 struct part_cfg_regs {
243 u32 dsp_pff_inst_id[47];
245 u16 vep_vector_number;
246 u16 usp_vector_number;
247 u32 port_event_bitmap;
249 u32 part_event_summary;
252 u32 part_reset_data[5];
254 u32 mrpc_comp_data[5];
255 u32 mrpc_comp_async_hdr;
256 u32 mrpc_comp_async_data[5];
258 u32 dyn_binding_data[5];
259 u32 intercomm_notify_hdr;
260 u32 intercomm_notify_data[5];
265 NTB_CTRL_PART_OP_LOCK = 0x1,
266 NTB_CTRL_PART_OP_CFG = 0x2,
267 NTB_CTRL_PART_OP_RESET = 0x3,
269 NTB_CTRL_PART_STATUS_NORMAL = 0x1,
270 NTB_CTRL_PART_STATUS_LOCKED = 0x2,
271 NTB_CTRL_PART_STATUS_LOCKING = 0x3,
272 NTB_CTRL_PART_STATUS_CONFIGURING = 0x4,
273 NTB_CTRL_PART_STATUS_RESETTING = 0x5,
275 NTB_CTRL_BAR_VALID = 1 << 0,
276 NTB_CTRL_BAR_DIR_WIN_EN = 1 << 4,
277 NTB_CTRL_BAR_LUT_WIN_EN = 1 << 5,
279 NTB_CTRL_REQ_ID_EN = 1 << 0,
281 NTB_CTRL_LUT_EN = 1 << 0,
283 NTB_PART_CTRL_ID_PROT_DIS = 1 << 0,
286 struct ntb_ctrl_regs {
287 u32 partition_status;
292 u16 lut_table_entries;
293 u16 lut_table_offset;
295 u16 req_id_table_size;
296 u16 req_id_table_offset;
309 u32 req_id_table[512];
314 #define NTB_DBMSG_IMSG_STATUS BIT_ULL(32)
315 #define NTB_DBMSG_IMSG_MASK BIT_ULL(40)
317 struct ntb_dbmsg_regs {
347 SWITCHTEC_PART_CFG_EVENT_RESET = 1 << 0,
348 SWITCHTEC_PART_CFG_EVENT_MRPC_CMP = 1 << 1,
349 SWITCHTEC_PART_CFG_EVENT_MRPC_ASYNC_CMP = 1 << 2,
350 SWITCHTEC_PART_CFG_EVENT_DYN_PART_CMP = 1 << 3,
353 struct pff_csr_regs {
365 u32 pci_subsystem_id;
366 u32 pci_expansion_rom;
370 u32 pci_cap_region[48];
371 u32 pcie_cap_region[448];
372 u32 indirect_gas_window[128];
373 u32 indirect_gas_window_off;
375 u32 pff_event_summary;
378 u32 aer_in_p2p_data[5];
380 u32 aer_in_vep_data[5];
392 u32 threshold_data[5];
394 u32 power_mgmt_data[5];
395 u32 tlp_throttling_hdr;
396 u32 tlp_throttling_data[5];
398 u32 force_speed_data[5];
399 u32 credit_timeout_hdr;
400 u32 credit_timeout_data[5];
402 u32 link_state_data[5];
406 struct switchtec_ntb;
408 struct dma_mrpc_output {
413 u8 data[SWITCHTEC_MRPC_PAYLOAD_SIZE];
416 struct switchtec_dev {
417 struct pci_dev *pdev;
421 enum switchtec_gen gen;
426 char pff_local[SWITCHTEC_MAX_PFF_CSR];
429 struct mrpc_regs __iomem *mmio_mrpc;
430 struct sw_event_regs __iomem *mmio_sw_event;
431 struct sys_info_regs __iomem *mmio_sys_info;
432 struct flash_info_regs __iomem *mmio_flash_info;
433 struct ntb_info_regs __iomem *mmio_ntb;
434 struct part_cfg_regs __iomem *mmio_part_cfg;
435 struct part_cfg_regs __iomem *mmio_part_cfg_all;
436 struct pff_csr_regs __iomem *mmio_pff_csr;
439 * The mrpc mutex must be held when accessing the other
440 * mrpc_ fields, alive flag and stuser->state field
442 struct mutex mrpc_mutex;
443 struct list_head mrpc_queue;
445 struct work_struct mrpc_work;
446 struct delayed_work mrpc_timeout;
449 wait_queue_head_t event_wq;
452 struct work_struct link_event_work;
453 void (*link_notifier)(struct switchtec_dev *stdev);
454 u8 link_event_count[SWITCHTEC_MAX_PFF_CSR];
456 struct switchtec_ntb *sndev;
458 struct dma_mrpc_output *dma_mrpc;
459 dma_addr_t dma_mrpc_dma_addr;
462 static inline struct switchtec_dev *to_stdev(struct device *dev)
464 return container_of(dev, struct switchtec_dev, dev);
467 extern struct class *switchtec_class;