switchtec.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Microsemi Switchtec PCIe Driver
  4. * Copyright (c) 2017, Microsemi Corporation
  5. */
  6. #ifndef _SWITCHTEC_H
  7. #define _SWITCHTEC_H
  8. #include <linux/pci.h>
  9. #include <linux/cdev.h>
  10. #define SWITCHTEC_MRPC_PAYLOAD_SIZE 1024
  11. #define SWITCHTEC_MAX_PFF_CSR 255
  12. #define SWITCHTEC_EVENT_OCCURRED BIT(0)
  13. #define SWITCHTEC_EVENT_CLEAR BIT(0)
  14. #define SWITCHTEC_EVENT_EN_LOG BIT(1)
  15. #define SWITCHTEC_EVENT_EN_CLI BIT(2)
  16. #define SWITCHTEC_EVENT_EN_IRQ BIT(3)
  17. #define SWITCHTEC_EVENT_FATAL BIT(4)
  18. #define SWITCHTEC_DMA_MRPC_EN BIT(0)
  19. enum {
  20. SWITCHTEC_GAS_MRPC_OFFSET = 0x0000,
  21. SWITCHTEC_GAS_TOP_CFG_OFFSET = 0x1000,
  22. SWITCHTEC_GAS_SW_EVENT_OFFSET = 0x1800,
  23. SWITCHTEC_GAS_SYS_INFO_OFFSET = 0x2000,
  24. SWITCHTEC_GAS_FLASH_INFO_OFFSET = 0x2200,
  25. SWITCHTEC_GAS_PART_CFG_OFFSET = 0x4000,
  26. SWITCHTEC_GAS_NTB_OFFSET = 0x10000,
  27. SWITCHTEC_GAS_PFF_CSR_OFFSET = 0x134000,
  28. };
  29. struct mrpc_regs {
  30. u8 input_data[SWITCHTEC_MRPC_PAYLOAD_SIZE];
  31. u8 output_data[SWITCHTEC_MRPC_PAYLOAD_SIZE];
  32. u32 cmd;
  33. u32 status;
  34. u32 ret_value;
  35. u32 dma_en;
  36. u64 dma_addr;
  37. u32 dma_vector;
  38. u32 dma_ver;
  39. } __packed;
  40. enum mrpc_status {
  41. SWITCHTEC_MRPC_STATUS_INPROGRESS = 1,
  42. SWITCHTEC_MRPC_STATUS_DONE = 2,
  43. SWITCHTEC_MRPC_STATUS_ERROR = 0xFF,
  44. SWITCHTEC_MRPC_STATUS_INTERRUPTED = 0x100,
  45. };
  46. struct sw_event_regs {
  47. u64 event_report_ctrl;
  48. u64 reserved1;
  49. u64 part_event_bitmap;
  50. u64 reserved2;
  51. u32 global_summary;
  52. u32 reserved3[3];
  53. u32 stack_error_event_hdr;
  54. u32 stack_error_event_data;
  55. u32 reserved4[4];
  56. u32 ppu_error_event_hdr;
  57. u32 ppu_error_event_data;
  58. u32 reserved5[4];
  59. u32 isp_error_event_hdr;
  60. u32 isp_error_event_data;
  61. u32 reserved6[4];
  62. u32 sys_reset_event_hdr;
  63. u32 reserved7[5];
  64. u32 fw_exception_hdr;
  65. u32 reserved8[5];
  66. u32 fw_nmi_hdr;
  67. u32 reserved9[5];
  68. u32 fw_non_fatal_hdr;
  69. u32 reserved10[5];
  70. u32 fw_fatal_hdr;
  71. u32 reserved11[5];
  72. u32 twi_mrpc_comp_hdr;
  73. u32 twi_mrpc_comp_data;
  74. u32 reserved12[4];
  75. u32 twi_mrpc_comp_async_hdr;
  76. u32 twi_mrpc_comp_async_data;
  77. u32 reserved13[4];
  78. u32 cli_mrpc_comp_hdr;
  79. u32 cli_mrpc_comp_data;
  80. u32 reserved14[4];
  81. u32 cli_mrpc_comp_async_hdr;
  82. u32 cli_mrpc_comp_async_data;
  83. u32 reserved15[4];
  84. u32 gpio_interrupt_hdr;
  85. u32 gpio_interrupt_data;
  86. u32 reserved16[4];
  87. u32 gfms_event_hdr;
  88. u32 gfms_event_data;
  89. u32 reserved17[4];
  90. } __packed;
  91. enum {
  92. SWITCHTEC_CFG0_RUNNING = 0x04,
  93. SWITCHTEC_CFG1_RUNNING = 0x05,
  94. SWITCHTEC_IMG0_RUNNING = 0x03,
  95. SWITCHTEC_IMG1_RUNNING = 0x07,
  96. };
  97. struct sys_info_regs {
  98. u32 device_id;
  99. u32 device_version;
  100. u32 firmware_version;
  101. u32 reserved1;
  102. u32 vendor_table_revision;
  103. u32 table_format_version;
  104. u32 partition_id;
  105. u32 cfg_file_fmt_version;
  106. u16 cfg_running;
  107. u16 img_running;
  108. u32 reserved2[57];
  109. char vendor_id[8];
  110. char product_id[16];
  111. char product_revision[4];
  112. char component_vendor[8];
  113. u16 component_id;
  114. u8 component_revision;
  115. } __packed;
  116. struct flash_info_regs {
  117. u32 flash_part_map_upd_idx;
  118. struct active_partition_info {
  119. u32 address;
  120. u32 build_version;
  121. u32 build_string;
  122. } active_img;
  123. struct active_partition_info active_cfg;
  124. struct active_partition_info inactive_img;
  125. struct active_partition_info inactive_cfg;
  126. u32 flash_length;
  127. struct partition_info {
  128. u32 address;
  129. u32 length;
  130. } cfg0;
  131. struct partition_info cfg1;
  132. struct partition_info img0;
  133. struct partition_info img1;
  134. struct partition_info nvlog;
  135. struct partition_info vendor[8];
  136. };
  137. enum {
  138. SWITCHTEC_NTB_REG_INFO_OFFSET = 0x0000,
  139. SWITCHTEC_NTB_REG_CTRL_OFFSET = 0x4000,
  140. SWITCHTEC_NTB_REG_DBMSG_OFFSET = 0x64000,
  141. };
  142. struct ntb_info_regs {
  143. u8 partition_count;
  144. u8 partition_id;
  145. u16 reserved1;
  146. u64 ep_map;
  147. u16 requester_id;
  148. u16 reserved2;
  149. u32 reserved3[4];
  150. struct nt_partition_info {
  151. u32 xlink_enabled;
  152. u32 target_part_low;
  153. u32 target_part_high;
  154. u32 reserved;
  155. } ntp_info[48];
  156. } __packed;
  157. struct part_cfg_regs {
  158. u32 status;
  159. u32 state;
  160. u32 port_cnt;
  161. u32 usp_port_mode;
  162. u32 usp_pff_inst_id;
  163. u32 vep_pff_inst_id;
  164. u32 dsp_pff_inst_id[47];
  165. u32 reserved1[11];
  166. u16 vep_vector_number;
  167. u16 usp_vector_number;
  168. u32 port_event_bitmap;
  169. u32 reserved2[3];
  170. u32 part_event_summary;
  171. u32 reserved3[3];
  172. u32 part_reset_hdr;
  173. u32 part_reset_data[5];
  174. u32 mrpc_comp_hdr;
  175. u32 mrpc_comp_data[5];
  176. u32 mrpc_comp_async_hdr;
  177. u32 mrpc_comp_async_data[5];
  178. u32 dyn_binding_hdr;
  179. u32 dyn_binding_data[5];
  180. u32 reserved4[159];
  181. } __packed;
  182. enum {
  183. NTB_CTRL_PART_OP_LOCK = 0x1,
  184. NTB_CTRL_PART_OP_CFG = 0x2,
  185. NTB_CTRL_PART_OP_RESET = 0x3,
  186. NTB_CTRL_PART_STATUS_NORMAL = 0x1,
  187. NTB_CTRL_PART_STATUS_LOCKED = 0x2,
  188. NTB_CTRL_PART_STATUS_LOCKING = 0x3,
  189. NTB_CTRL_PART_STATUS_CONFIGURING = 0x4,
  190. NTB_CTRL_PART_STATUS_RESETTING = 0x5,
  191. NTB_CTRL_BAR_VALID = 1 << 0,
  192. NTB_CTRL_BAR_DIR_WIN_EN = 1 << 4,
  193. NTB_CTRL_BAR_LUT_WIN_EN = 1 << 5,
  194. NTB_CTRL_REQ_ID_EN = 1 << 0,
  195. NTB_CTRL_LUT_EN = 1 << 0,
  196. NTB_PART_CTRL_ID_PROT_DIS = 1 << 0,
  197. };
  198. struct ntb_ctrl_regs {
  199. u32 partition_status;
  200. u32 partition_op;
  201. u32 partition_ctrl;
  202. u32 bar_setup;
  203. u32 bar_error;
  204. u16 lut_table_entries;
  205. u16 lut_table_offset;
  206. u32 lut_error;
  207. u16 req_id_table_size;
  208. u16 req_id_table_offset;
  209. u32 req_id_error;
  210. u32 reserved1[7];
  211. struct {
  212. u32 ctl;
  213. u32 win_size;
  214. u64 xlate_addr;
  215. } bar_entry[6];
  216. struct {
  217. u32 win_size;
  218. u32 reserved[3];
  219. } bar_ext_entry[6];
  220. u32 reserved2[192];
  221. u32 req_id_table[512];
  222. u32 reserved3[256];
  223. u64 lut_entry[512];
  224. } __packed;
  225. #define NTB_DBMSG_IMSG_STATUS BIT_ULL(32)
  226. #define NTB_DBMSG_IMSG_MASK BIT_ULL(40)
  227. struct ntb_dbmsg_regs {
  228. u32 reserved1[1024];
  229. u64 odb;
  230. u64 odb_mask;
  231. u64 idb;
  232. u64 idb_mask;
  233. u8 idb_vec_map[64];
  234. u32 msg_map;
  235. u32 reserved2;
  236. struct {
  237. u32 msg;
  238. u32 status;
  239. } omsg[4];
  240. struct {
  241. u32 msg;
  242. u8 status;
  243. u8 mask;
  244. u8 src;
  245. u8 reserved;
  246. } imsg[4];
  247. u8 reserved3[3928];
  248. u8 msix_table[1024];
  249. u8 reserved4[3072];
  250. u8 pba[24];
  251. u8 reserved5[4072];
  252. } __packed;
  253. enum {
  254. SWITCHTEC_PART_CFG_EVENT_RESET = 1 << 0,
  255. SWITCHTEC_PART_CFG_EVENT_MRPC_CMP = 1 << 1,
  256. SWITCHTEC_PART_CFG_EVENT_MRPC_ASYNC_CMP = 1 << 2,
  257. SWITCHTEC_PART_CFG_EVENT_DYN_PART_CMP = 1 << 3,
  258. };
  259. struct pff_csr_regs {
  260. u16 vendor_id;
  261. u16 device_id;
  262. u16 pcicmd;
  263. u16 pcists;
  264. u32 pci_class;
  265. u32 pci_opts;
  266. union {
  267. u32 pci_bar[6];
  268. u64 pci_bar64[3];
  269. };
  270. u32 pci_cardbus;
  271. u32 pci_subsystem_id;
  272. u32 pci_expansion_rom;
  273. u32 pci_cap_ptr;
  274. u32 reserved1;
  275. u32 pci_irq;
  276. u32 pci_cap_region[48];
  277. u32 pcie_cap_region[448];
  278. u32 indirect_gas_window[128];
  279. u32 indirect_gas_window_off;
  280. u32 reserved[127];
  281. u32 pff_event_summary;
  282. u32 reserved2[3];
  283. u32 aer_in_p2p_hdr;
  284. u32 aer_in_p2p_data[5];
  285. u32 aer_in_vep_hdr;
  286. u32 aer_in_vep_data[5];
  287. u32 dpc_hdr;
  288. u32 dpc_data[5];
  289. u32 cts_hdr;
  290. u32 cts_data[5];
  291. u32 reserved3[6];
  292. u32 hotplug_hdr;
  293. u32 hotplug_data[5];
  294. u32 ier_hdr;
  295. u32 ier_data[5];
  296. u32 threshold_hdr;
  297. u32 threshold_data[5];
  298. u32 power_mgmt_hdr;
  299. u32 power_mgmt_data[5];
  300. u32 tlp_throttling_hdr;
  301. u32 tlp_throttling_data[5];
  302. u32 force_speed_hdr;
  303. u32 force_speed_data[5];
  304. u32 credit_timeout_hdr;
  305. u32 credit_timeout_data[5];
  306. u32 link_state_hdr;
  307. u32 link_state_data[5];
  308. u32 reserved4[174];
  309. } __packed;
  310. struct switchtec_ntb;
  311. struct dma_mrpc_output {
  312. u32 status;
  313. u32 cmd_id;
  314. u32 rtn_code;
  315. u32 output_size;
  316. u8 data[SWITCHTEC_MRPC_PAYLOAD_SIZE];
  317. };
  318. struct switchtec_dev {
  319. struct pci_dev *pdev;
  320. struct device dev;
  321. struct cdev cdev;
  322. int partition;
  323. int partition_count;
  324. int pff_csr_count;
  325. char pff_local[SWITCHTEC_MAX_PFF_CSR];
  326. void __iomem *mmio;
  327. struct mrpc_regs __iomem *mmio_mrpc;
  328. struct sw_event_regs __iomem *mmio_sw_event;
  329. struct sys_info_regs __iomem *mmio_sys_info;
  330. struct flash_info_regs __iomem *mmio_flash_info;
  331. struct ntb_info_regs __iomem *mmio_ntb;
  332. struct part_cfg_regs __iomem *mmio_part_cfg;
  333. struct part_cfg_regs __iomem *mmio_part_cfg_all;
  334. struct pff_csr_regs __iomem *mmio_pff_csr;
  335. /*
  336. * The mrpc mutex must be held when accessing the other
  337. * mrpc_ fields, alive flag and stuser->state field
  338. */
  339. struct mutex mrpc_mutex;
  340. struct list_head mrpc_queue;
  341. int mrpc_busy;
  342. struct work_struct mrpc_work;
  343. struct delayed_work mrpc_timeout;
  344. bool alive;
  345. wait_queue_head_t event_wq;
  346. atomic_t event_cnt;
  347. struct work_struct link_event_work;
  348. void (*link_notifier)(struct switchtec_dev *stdev);
  349. u8 link_event_count[SWITCHTEC_MAX_PFF_CSR];
  350. struct switchtec_ntb *sndev;
  351. struct dma_mrpc_output *dma_mrpc;
  352. dma_addr_t dma_mrpc_dma_addr;
  353. };
  354. static inline struct switchtec_dev *to_stdev(struct device *dev)
  355. {
  356. return container_of(dev, struct switchtec_dev, dev);
  357. }
  358. extern struct class *switchtec_class;
  359. #endif