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)
22 #define SWITCHTEC_EVENT_NOT_SUPP BIT(31)
24 #define SWITCHTEC_DMA_MRPC_EN BIT(0)
26 #define MRPC_GAS_READ 0x29
27 #define MRPC_GAS_WRITE 0x87
28 #define MRPC_CMD_ID(x) ((x) & 0xffff)
31 SWITCHTEC_GAS_MRPC_OFFSET
= 0x0000,
32 SWITCHTEC_GAS_TOP_CFG_OFFSET
= 0x1000,
33 SWITCHTEC_GAS_SW_EVENT_OFFSET
= 0x1800,
34 SWITCHTEC_GAS_SYS_INFO_OFFSET
= 0x2000,
35 SWITCHTEC_GAS_FLASH_INFO_OFFSET
= 0x2200,
36 SWITCHTEC_GAS_PART_CFG_OFFSET
= 0x4000,
37 SWITCHTEC_GAS_NTB_OFFSET
= 0x10000,
38 SWITCHTEC_GAS_PFF_CSR_OFFSET
= 0x134000,
48 u8 input_data
[SWITCHTEC_MRPC_PAYLOAD_SIZE
];
49 u8 output_data
[SWITCHTEC_MRPC_PAYLOAD_SIZE
];
60 SWITCHTEC_MRPC_STATUS_INPROGRESS
= 1,
61 SWITCHTEC_MRPC_STATUS_DONE
= 2,
62 SWITCHTEC_MRPC_STATUS_ERROR
= 0xFF,
63 SWITCHTEC_MRPC_STATUS_INTERRUPTED
= 0x100,
66 struct sw_event_regs
{
67 u64 event_report_ctrl
;
69 u64 part_event_bitmap
;
73 u32 stack_error_event_hdr
;
74 u32 stack_error_event_data
;
76 u32 ppu_error_event_hdr
;
77 u32 ppu_error_event_data
;
79 u32 isp_error_event_hdr
;
80 u32 isp_error_event_data
;
82 u32 sys_reset_event_hdr
;
92 u32 twi_mrpc_comp_hdr
;
93 u32 twi_mrpc_comp_data
;
95 u32 twi_mrpc_comp_async_hdr
;
96 u32 twi_mrpc_comp_async_data
;
98 u32 cli_mrpc_comp_hdr
;
99 u32 cli_mrpc_comp_data
;
101 u32 cli_mrpc_comp_async_hdr
;
102 u32 cli_mrpc_comp_async_data
;
104 u32 gpio_interrupt_hdr
;
105 u32 gpio_interrupt_data
;
113 SWITCHTEC_GEN3_CFG0_RUNNING
= 0x04,
114 SWITCHTEC_GEN3_CFG1_RUNNING
= 0x05,
115 SWITCHTEC_GEN3_IMG0_RUNNING
= 0x03,
116 SWITCHTEC_GEN3_IMG1_RUNNING
= 0x07,
120 SWITCHTEC_GEN4_MAP0_RUNNING
= 0x00,
121 SWITCHTEC_GEN4_MAP1_RUNNING
= 0x01,
122 SWITCHTEC_GEN4_KEY0_RUNNING
= 0x02,
123 SWITCHTEC_GEN4_KEY1_RUNNING
= 0x03,
124 SWITCHTEC_GEN4_BL2_0_RUNNING
= 0x04,
125 SWITCHTEC_GEN4_BL2_1_RUNNING
= 0x05,
126 SWITCHTEC_GEN4_CFG0_RUNNING
= 0x06,
127 SWITCHTEC_GEN4_CFG1_RUNNING
= 0x07,
128 SWITCHTEC_GEN4_IMG0_RUNNING
= 0x08,
129 SWITCHTEC_GEN4_IMG1_RUNNING
= 0x09,
133 SWITCHTEC_GEN4_KEY0_ACTIVE
= 0,
134 SWITCHTEC_GEN4_KEY1_ACTIVE
= 1,
135 SWITCHTEC_GEN4_BL2_0_ACTIVE
= 0,
136 SWITCHTEC_GEN4_BL2_1_ACTIVE
= 1,
137 SWITCHTEC_GEN4_CFG0_ACTIVE
= 0,
138 SWITCHTEC_GEN4_CFG1_ACTIVE
= 1,
139 SWITCHTEC_GEN4_IMG0_ACTIVE
= 0,
140 SWITCHTEC_GEN4_IMG1_ACTIVE
= 1,
143 struct sys_info_regs_gen3
{
145 u32 vendor_table_revision
;
146 u32 table_format_version
;
148 u32 cfg_file_fmt_version
;
154 char product_revision
[4];
155 char component_vendor
[8];
157 u8 component_revision
;
160 struct sys_info_regs_gen4
{
164 u16 mgmt_cmd_set_ver
;
165 u16 fabric_cmd_set_ver
;
181 u32 vendor_seeprom_twi
;
182 u32 vendor_table_revision
;
183 u32 vendor_specific_info
[2];
189 u16 subsystem_vendor_id
;
191 u32 p2p_serial_number
[2];
197 char product_revision
[2];
201 struct sys_info_regs
{
204 u32 firmware_version
;
206 struct sys_info_regs_gen3 gen3
;
207 struct sys_info_regs_gen4 gen4
;
211 struct partition_info
{
216 struct flash_info_regs_gen3
{
217 u32 flash_part_map_upd_idx
;
219 struct active_partition_info_gen3
{
225 struct active_partition_info_gen3 active_cfg
;
226 struct active_partition_info_gen3 inactive_img
;
227 struct active_partition_info_gen3 inactive_cfg
;
231 struct partition_info cfg0
;
232 struct partition_info cfg1
;
233 struct partition_info img0
;
234 struct partition_info img1
;
235 struct partition_info nvlog
;
236 struct partition_info vendor
[8];
239 struct flash_info_regs_gen4
{
243 struct active_partition_info_gen4
{
252 struct partition_info map0
;
253 struct partition_info map1
;
254 struct partition_info key0
;
255 struct partition_info key1
;
256 struct partition_info bl2_0
;
257 struct partition_info bl2_1
;
258 struct partition_info cfg0
;
259 struct partition_info cfg1
;
260 struct partition_info img0
;
261 struct partition_info img1
;
262 struct partition_info nvlog
;
263 struct partition_info vendor
[8];
266 struct flash_info_regs
{
268 struct flash_info_regs_gen3 gen3
;
269 struct flash_info_regs_gen4 gen4
;
274 SWITCHTEC_NTB_REG_INFO_OFFSET
= 0x0000,
275 SWITCHTEC_NTB_REG_CTRL_OFFSET
= 0x4000,
276 SWITCHTEC_NTB_REG_DBMSG_OFFSET
= 0x64000,
279 struct ntb_info_regs
{
287 struct nt_partition_info
{
290 u32 target_part_high
;
295 struct part_cfg_regs
{
302 u32 dsp_pff_inst_id
[47];
304 u16 vep_vector_number
;
305 u16 usp_vector_number
;
306 u32 port_event_bitmap
;
308 u32 part_event_summary
;
311 u32 part_reset_data
[5];
313 u32 mrpc_comp_data
[5];
314 u32 mrpc_comp_async_hdr
;
315 u32 mrpc_comp_async_data
[5];
317 u32 dyn_binding_data
[5];
318 u32 intercomm_notify_hdr
;
319 u32 intercomm_notify_data
[5];
324 NTB_CTRL_PART_OP_LOCK
= 0x1,
325 NTB_CTRL_PART_OP_CFG
= 0x2,
326 NTB_CTRL_PART_OP_RESET
= 0x3,
328 NTB_CTRL_PART_STATUS_NORMAL
= 0x1,
329 NTB_CTRL_PART_STATUS_LOCKED
= 0x2,
330 NTB_CTRL_PART_STATUS_LOCKING
= 0x3,
331 NTB_CTRL_PART_STATUS_CONFIGURING
= 0x4,
332 NTB_CTRL_PART_STATUS_RESETTING
= 0x5,
334 NTB_CTRL_BAR_VALID
= 1 << 0,
335 NTB_CTRL_BAR_DIR_WIN_EN
= 1 << 4,
336 NTB_CTRL_BAR_LUT_WIN_EN
= 1 << 5,
338 NTB_CTRL_REQ_ID_EN
= 1 << 0,
340 NTB_CTRL_LUT_EN
= 1 << 0,
343 struct ntb_ctrl_regs
{
344 u32 partition_status
;
349 u16 lut_table_entries
;
350 u16 lut_table_offset
;
352 u16 req_id_table_size
;
353 u16 req_id_table_offset
;
366 u32 req_id_table
[512];
371 #define NTB_DBMSG_IMSG_STATUS BIT_ULL(32)
372 #define NTB_DBMSG_IMSG_MASK BIT_ULL(40)
374 struct ntb_dbmsg_regs
{
404 SWITCHTEC_PART_CFG_EVENT_RESET
= 1 << 0,
405 SWITCHTEC_PART_CFG_EVENT_MRPC_CMP
= 1 << 1,
406 SWITCHTEC_PART_CFG_EVENT_MRPC_ASYNC_CMP
= 1 << 2,
407 SWITCHTEC_PART_CFG_EVENT_DYN_PART_CMP
= 1 << 3,
410 struct pff_csr_regs
{
422 u32 pci_subsystem_id
;
423 u32 pci_expansion_rom
;
427 u32 pci_cap_region
[48];
428 u32 pcie_cap_region
[448];
429 u32 indirect_gas_window
[128];
430 u32 indirect_gas_window_off
;
432 u32 pff_event_summary
;
435 u32 aer_in_p2p_data
[5];
437 u32 aer_in_vep_data
[5];
449 u32 threshold_data
[5];
451 u32 power_mgmt_data
[5];
452 u32 tlp_throttling_hdr
;
453 u32 tlp_throttling_data
[5];
455 u32 force_speed_data
[5];
456 u32 credit_timeout_hdr
;
457 u32 credit_timeout_data
[5];
459 u32 link_state_data
[5];
463 struct switchtec_ntb
;
465 struct dma_mrpc_output
{
470 u8 data
[SWITCHTEC_MRPC_PAYLOAD_SIZE
];
473 struct switchtec_dev
{
474 struct pci_dev
*pdev
;
478 enum switchtec_gen gen
;
483 char pff_local
[SWITCHTEC_MAX_PFF_CSR
];
486 struct mrpc_regs __iomem
*mmio_mrpc
;
487 struct sw_event_regs __iomem
*mmio_sw_event
;
488 struct sys_info_regs __iomem
*mmio_sys_info
;
489 struct flash_info_regs __iomem
*mmio_flash_info
;
490 struct ntb_info_regs __iomem
*mmio_ntb
;
491 struct part_cfg_regs __iomem
*mmio_part_cfg
;
492 struct part_cfg_regs __iomem
*mmio_part_cfg_all
;
493 struct pff_csr_regs __iomem
*mmio_pff_csr
;
496 * The mrpc mutex must be held when accessing the other
497 * mrpc_ fields, alive flag and stuser->state field
499 struct mutex mrpc_mutex
;
500 struct list_head mrpc_queue
;
502 struct work_struct mrpc_work
;
503 struct delayed_work mrpc_timeout
;
506 wait_queue_head_t event_wq
;
509 struct work_struct link_event_work
;
510 void (*link_notifier
)(struct switchtec_dev
*stdev
);
511 u8 link_event_count
[SWITCHTEC_MAX_PFF_CSR
];
513 struct switchtec_ntb
*sndev
;
515 struct dma_mrpc_output
*dma_mrpc
;
516 dma_addr_t dma_mrpc_dma_addr
;
519 static inline struct switchtec_dev
*to_stdev(struct device
*dev
)
521 return container_of(dev
, struct switchtec_dev
, dev
);
524 extern const struct class switchtec_class
;