xilinx_sdfec.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
  2. /*
  3. * Xilinx SD-FEC
  4. *
  5. * Copyright (C) 2019 Xilinx, Inc.
  6. *
  7. * Description:
  8. * This driver is developed for SDFEC16 IP. It provides a char device
  9. * in sysfs and supports file operations like open(), close() and ioctl().
  10. */
  11. #ifndef __XILINX_SDFEC_H__
  12. #define __XILINX_SDFEC_H__
  13. #include <linux/types.h>
  14. /* Shared LDPC Tables */
  15. #define XSDFEC_LDPC_SC_TABLE_ADDR_BASE (0x10000)
  16. #define XSDFEC_LDPC_SC_TABLE_ADDR_HIGH (0x10400)
  17. #define XSDFEC_LDPC_LA_TABLE_ADDR_BASE (0x18000)
  18. #define XSDFEC_LDPC_LA_TABLE_ADDR_HIGH (0x19000)
  19. #define XSDFEC_LDPC_QC_TABLE_ADDR_BASE (0x20000)
  20. #define XSDFEC_LDPC_QC_TABLE_ADDR_HIGH (0x28000)
  21. /* LDPC tables depth */
  22. #define XSDFEC_SC_TABLE_DEPTH \
  23. (XSDFEC_LDPC_SC_TABLE_ADDR_HIGH - XSDFEC_LDPC_SC_TABLE_ADDR_BASE)
  24. #define XSDFEC_LA_TABLE_DEPTH \
  25. (XSDFEC_LDPC_LA_TABLE_ADDR_HIGH - XSDFEC_LDPC_LA_TABLE_ADDR_BASE)
  26. #define XSDFEC_QC_TABLE_DEPTH \
  27. (XSDFEC_LDPC_QC_TABLE_ADDR_HIGH - XSDFEC_LDPC_QC_TABLE_ADDR_BASE)
  28. /**
  29. * enum xsdfec_code - Code Type.
  30. * @XSDFEC_TURBO_CODE: Driver is configured for Turbo mode.
  31. * @XSDFEC_LDPC_CODE: Driver is configured for LDPC mode.
  32. *
  33. * This enum is used to indicate the mode of the driver. The mode is determined
  34. * by checking which codes are set in the driver. Note that the mode cannot be
  35. * changed by the driver.
  36. */
  37. enum xsdfec_code {
  38. XSDFEC_TURBO_CODE = 0,
  39. XSDFEC_LDPC_CODE,
  40. };
  41. /**
  42. * enum xsdfec_order - Order
  43. * @XSDFEC_MAINTAIN_ORDER: Maintain order execution of blocks.
  44. * @XSDFEC_OUT_OF_ORDER: Out-of-order execution of blocks.
  45. *
  46. * This enum is used to indicate whether the order of blocks can change from
  47. * input to output.
  48. */
  49. enum xsdfec_order {
  50. XSDFEC_MAINTAIN_ORDER = 0,
  51. XSDFEC_OUT_OF_ORDER,
  52. };
  53. /**
  54. * enum xsdfec_turbo_alg - Turbo Algorithm Type.
  55. * @XSDFEC_MAX_SCALE: Max Log-Map algorithm with extrinsic scaling. When
  56. * scaling is set to this is equivalent to the Max Log-Map
  57. * algorithm.
  58. * @XSDFEC_MAX_STAR: Log-Map algorithm.
  59. * @XSDFEC_TURBO_ALG_MAX: Used to indicate out of bound Turbo algorithms.
  60. *
  61. * This enum specifies which Turbo Decode algorithm is in use.
  62. */
  63. enum xsdfec_turbo_alg {
  64. XSDFEC_MAX_SCALE = 0,
  65. XSDFEC_MAX_STAR,
  66. XSDFEC_TURBO_ALG_MAX,
  67. };
  68. /**
  69. * enum xsdfec_state - State.
  70. * @XSDFEC_INIT: Driver is initialized.
  71. * @XSDFEC_STARTED: Driver is started.
  72. * @XSDFEC_STOPPED: Driver is stopped.
  73. * @XSDFEC_NEEDS_RESET: Driver needs to be reset.
  74. * @XSDFEC_PL_RECONFIGURE: Programmable Logic needs to be recofigured.
  75. *
  76. * This enum is used to indicate the state of the driver.
  77. */
  78. enum xsdfec_state {
  79. XSDFEC_INIT = 0,
  80. XSDFEC_STARTED,
  81. XSDFEC_STOPPED,
  82. XSDFEC_NEEDS_RESET,
  83. XSDFEC_PL_RECONFIGURE,
  84. };
  85. /**
  86. * enum xsdfec_axis_width - AXIS_WIDTH.DIN Setting for 128-bit width.
  87. * @XSDFEC_1x128b: DIN data input stream consists of a 128-bit lane
  88. * @XSDFEC_2x128b: DIN data input stream consists of two 128-bit lanes
  89. * @XSDFEC_4x128b: DIN data input stream consists of four 128-bit lanes
  90. *
  91. * This enum is used to indicate the AXIS_WIDTH.DIN setting for 128-bit width.
  92. * The number of lanes of the DIN data input stream depends upon the
  93. * AXIS_WIDTH.DIN parameter.
  94. */
  95. enum xsdfec_axis_width {
  96. XSDFEC_1x128b = 1,
  97. XSDFEC_2x128b = 2,
  98. XSDFEC_4x128b = 4,
  99. };
  100. /**
  101. * enum xsdfec_axis_word_include - Words Configuration.
  102. * @XSDFEC_FIXED_VALUE: Fixed, the DIN_WORDS AXI4-Stream interface is removed
  103. * from the IP instance and is driven with the specified
  104. * number of words.
  105. * @XSDFEC_IN_BLOCK: In Block, configures the IP instance to expect a single
  106. * DIN_WORDS value per input code block. The DIN_WORDS
  107. * interface is present.
  108. * @XSDFEC_PER_AXI_TRANSACTION: Per Transaction, configures the IP instance to
  109. * expect one DIN_WORDS value per input transaction on the DIN interface. The
  110. * DIN_WORDS interface is present.
  111. * @XSDFEC_AXIS_WORDS_INCLUDE_MAX: Used to indicate out of bound Words
  112. * Configurations.
  113. *
  114. * This enum is used to specify the DIN_WORDS configuration.
  115. */
  116. enum xsdfec_axis_word_include {
  117. XSDFEC_FIXED_VALUE = 0,
  118. XSDFEC_IN_BLOCK,
  119. XSDFEC_PER_AXI_TRANSACTION,
  120. XSDFEC_AXIS_WORDS_INCLUDE_MAX,
  121. };
  122. /**
  123. * struct xsdfec_turbo - User data for Turbo codes.
  124. * @alg: Specifies which Turbo decode algorithm to use
  125. * @scale: Specifies the extrinsic scaling to apply when the Max Scale algorithm
  126. * has been selected
  127. *
  128. * Turbo code structure to communicate parameters to XSDFEC driver.
  129. */
  130. struct xsdfec_turbo {
  131. __u32 alg;
  132. __u8 scale;
  133. };
  134. /**
  135. * struct xsdfec_ldpc_params - User data for LDPC codes.
  136. * @n: Number of code word bits
  137. * @k: Number of information bits
  138. * @psize: Size of sub-matrix
  139. * @nlayers: Number of layers in code
  140. * @nqc: Quasi Cyclic Number
  141. * @nmqc: Number of M-sized QC operations in parity check matrix
  142. * @nm: Number of M-size vectors in N
  143. * @norm_type: Normalization required or not
  144. * @no_packing: Determines if multiple QC ops should be performed
  145. * @special_qc: Sub-Matrix property for Circulant weight > 0
  146. * @no_final_parity: Decide if final parity check needs to be performed
  147. * @max_schedule: Experimental code word scheduling limit
  148. * @sc_off: SC offset
  149. * @la_off: LA offset
  150. * @qc_off: QC offset
  151. * @sc_table: Pointer to SC Table which must be page aligned
  152. * @la_table: Pointer to LA Table which must be page aligned
  153. * @qc_table: Pointer to QC Table which must be page aligned
  154. * @code_id: LDPC Code
  155. *
  156. * This structure describes the LDPC code that is passed to the driver by the
  157. * application.
  158. */
  159. struct xsdfec_ldpc_params {
  160. __u32 n;
  161. __u32 k;
  162. __u32 psize;
  163. __u32 nlayers;
  164. __u32 nqc;
  165. __u32 nmqc;
  166. __u32 nm;
  167. __u32 norm_type;
  168. __u32 no_packing;
  169. __u32 special_qc;
  170. __u32 no_final_parity;
  171. __u32 max_schedule;
  172. __u32 sc_off;
  173. __u32 la_off;
  174. __u32 qc_off;
  175. __u32 *sc_table;
  176. __u32 *la_table;
  177. __u32 *qc_table;
  178. __u16 code_id;
  179. };
  180. /**
  181. * struct xsdfec_status - Status of SD-FEC core.
  182. * @state: State of the SD-FEC core
  183. * @activity: Describes if the SD-FEC instance is Active
  184. */
  185. struct xsdfec_status {
  186. __u32 state;
  187. __s8 activity;
  188. };
  189. /**
  190. * struct xsdfec_irq - Enabling or Disabling Interrupts.
  191. * @enable_isr: If true enables the ISR
  192. * @enable_ecc_isr: If true enables the ECC ISR
  193. */
  194. struct xsdfec_irq {
  195. __s8 enable_isr;
  196. __s8 enable_ecc_isr;
  197. };
  198. /**
  199. * struct xsdfec_config - Configuration of SD-FEC core.
  200. * @code: The codes being used by the SD-FEC instance
  201. * @order: Order of Operation
  202. * @din_width: Width of the DIN AXI4-Stream
  203. * @din_word_include: How DIN_WORDS are inputted
  204. * @dout_width: Width of the DOUT AXI4-Stream
  205. * @dout_word_include: HOW DOUT_WORDS are outputted
  206. * @irq: Enabling or disabling interrupts
  207. * @bypass: Is the core being bypassed
  208. * @code_wr_protect: Is write protection of LDPC codes enabled
  209. */
  210. struct xsdfec_config {
  211. __u32 code;
  212. __u32 order;
  213. __u32 din_width;
  214. __u32 din_word_include;
  215. __u32 dout_width;
  216. __u32 dout_word_include;
  217. struct xsdfec_irq irq;
  218. __s8 bypass;
  219. __s8 code_wr_protect;
  220. };
  221. /**
  222. * struct xsdfec_stats - Stats retrived by ioctl XSDFEC_GET_STATS. Used
  223. * to buffer atomic_t variables from struct
  224. * xsdfec_dev. Counts are accumulated until
  225. * the user clears them.
  226. * @isr_err_count: Count of ISR errors
  227. * @cecc_count: Count of Correctable ECC errors (SBE)
  228. * @uecc_count: Count of Uncorrectable ECC errors (MBE)
  229. */
  230. struct xsdfec_stats {
  231. __u32 isr_err_count;
  232. __u32 cecc_count;
  233. __u32 uecc_count;
  234. };
  235. /**
  236. * struct xsdfec_ldpc_param_table_sizes - Used to store sizes of SD-FEC table
  237. * entries for an individual LPDC code
  238. * parameter.
  239. * @sc_size: Size of SC table used
  240. * @la_size: Size of LA table used
  241. * @qc_size: Size of QC table used
  242. */
  243. struct xsdfec_ldpc_param_table_sizes {
  244. __u32 sc_size;
  245. __u32 la_size;
  246. __u32 qc_size;
  247. };
  248. /*
  249. * XSDFEC IOCTL List
  250. */
  251. #define XSDFEC_MAGIC 'f'
  252. /**
  253. * DOC: XSDFEC_START_DEV
  254. *
  255. * @Description
  256. *
  257. * ioctl to start SD-FEC core
  258. *
  259. * This fails if the XSDFEC_SET_ORDER ioctl has not been previously called
  260. */
  261. #define XSDFEC_START_DEV _IO(XSDFEC_MAGIC, 0)
  262. /**
  263. * DOC: XSDFEC_STOP_DEV
  264. *
  265. * @Description
  266. *
  267. * ioctl to stop the SD-FEC core
  268. */
  269. #define XSDFEC_STOP_DEV _IO(XSDFEC_MAGIC, 1)
  270. /**
  271. * DOC: XSDFEC_GET_STATUS
  272. *
  273. * @Description
  274. *
  275. * ioctl that returns status of SD-FEC core
  276. */
  277. #define XSDFEC_GET_STATUS _IOR(XSDFEC_MAGIC, 2, struct xsdfec_status)
  278. /**
  279. * DOC: XSDFEC_SET_IRQ
  280. * @Parameters
  281. *
  282. * @struct xsdfec_irq *
  283. * Pointer to the &struct xsdfec_irq that contains the interrupt settings
  284. * for the SD-FEC core
  285. *
  286. * @Description
  287. *
  288. * ioctl to enable or disable irq
  289. */
  290. #define XSDFEC_SET_IRQ _IOW(XSDFEC_MAGIC, 3, struct xsdfec_irq)
  291. /**
  292. * DOC: XSDFEC_SET_TURBO
  293. * @Parameters
  294. *
  295. * @struct xsdfec_turbo *
  296. * Pointer to the &struct xsdfec_turbo that contains the Turbo decode
  297. * settings for the SD-FEC core
  298. *
  299. * @Description
  300. *
  301. * ioctl that sets the SD-FEC Turbo parameter values
  302. *
  303. * This can only be used when the driver is in the XSDFEC_STOPPED state
  304. */
  305. #define XSDFEC_SET_TURBO _IOW(XSDFEC_MAGIC, 4, struct xsdfec_turbo)
  306. /**
  307. * DOC: XSDFEC_ADD_LDPC_CODE_PARAMS
  308. * @Parameters
  309. *
  310. * @struct xsdfec_ldpc_params *
  311. * Pointer to the &struct xsdfec_ldpc_params that contains the LDPC code
  312. * parameters to be added to the SD-FEC Block
  313. *
  314. * @Description
  315. * ioctl to add an LDPC code to the SD-FEC LDPC codes
  316. *
  317. * This can only be used when:
  318. *
  319. * - Driver is in the XSDFEC_STOPPED state
  320. *
  321. * - SD-FEC core is configured as LPDC
  322. *
  323. * - SD-FEC Code Write Protection is disabled
  324. */
  325. #define XSDFEC_ADD_LDPC_CODE_PARAMS \
  326. _IOW(XSDFEC_MAGIC, 5, struct xsdfec_ldpc_params)
  327. /**
  328. * DOC: XSDFEC_GET_CONFIG
  329. * @Parameters
  330. *
  331. * @struct xsdfec_config *
  332. * Pointer to the &struct xsdfec_config that contains the current
  333. * configuration settings of the SD-FEC Block
  334. *
  335. * @Description
  336. *
  337. * ioctl that returns SD-FEC core configuration
  338. */
  339. #define XSDFEC_GET_CONFIG _IOR(XSDFEC_MAGIC, 6, struct xsdfec_config)
  340. /**
  341. * DOC: XSDFEC_GET_TURBO
  342. * @Parameters
  343. *
  344. * @struct xsdfec_turbo *
  345. * Pointer to the &struct xsdfec_turbo that contains the current Turbo
  346. * decode settings of the SD-FEC Block
  347. *
  348. * @Description
  349. *
  350. * ioctl that returns SD-FEC turbo param values
  351. */
  352. #define XSDFEC_GET_TURBO _IOR(XSDFEC_MAGIC, 7, struct xsdfec_turbo)
  353. /**
  354. * DOC: XSDFEC_SET_ORDER
  355. * @Parameters
  356. *
  357. * @struct unsigned long *
  358. * Pointer to the unsigned long that contains a value from the
  359. * @enum xsdfec_order
  360. *
  361. * @Description
  362. *
  363. * ioctl that sets order, if order of blocks can change from input to output
  364. *
  365. * This can only be used when the driver is in the XSDFEC_STOPPED state
  366. */
  367. #define XSDFEC_SET_ORDER _IOW(XSDFEC_MAGIC, 8, unsigned long)
  368. /**
  369. * DOC: XSDFEC_SET_BYPASS
  370. * @Parameters
  371. *
  372. * @struct bool *
  373. * Pointer to bool that sets the bypass value, where false results in
  374. * normal operation and false results in the SD-FEC performing the
  375. * configured operations (same number of cycles) but output data matches
  376. * the input data
  377. *
  378. * @Description
  379. *
  380. * ioctl that sets bypass.
  381. *
  382. * This can only be used when the driver is in the XSDFEC_STOPPED state
  383. */
  384. #define XSDFEC_SET_BYPASS _IOW(XSDFEC_MAGIC, 9, bool)
  385. /**
  386. * DOC: XSDFEC_IS_ACTIVE
  387. * @Parameters
  388. *
  389. * @struct bool *
  390. * Pointer to bool that returns true if the SD-FEC is processing data
  391. *
  392. * @Description
  393. *
  394. * ioctl that determines if SD-FEC is processing data
  395. */
  396. #define XSDFEC_IS_ACTIVE _IOR(XSDFEC_MAGIC, 10, bool)
  397. /**
  398. * DOC: XSDFEC_CLEAR_STATS
  399. *
  400. * @Description
  401. *
  402. * ioctl that clears error stats collected during interrupts
  403. */
  404. #define XSDFEC_CLEAR_STATS _IO(XSDFEC_MAGIC, 11)
  405. /**
  406. * DOC: XSDFEC_GET_STATS
  407. * @Parameters
  408. *
  409. * @struct xsdfec_stats *
  410. * Pointer to the &struct xsdfec_stats that will contain the updated stats
  411. * values
  412. *
  413. * @Description
  414. *
  415. * ioctl that returns SD-FEC core stats
  416. *
  417. * This can only be used when the driver is in the XSDFEC_STOPPED state
  418. */
  419. #define XSDFEC_GET_STATS _IOR(XSDFEC_MAGIC, 12, struct xsdfec_stats)
  420. /**
  421. * DOC: XSDFEC_SET_DEFAULT_CONFIG
  422. *
  423. * @Description
  424. *
  425. * ioctl that returns SD-FEC core to default config, use after a reset
  426. *
  427. * This can only be used when the driver is in the XSDFEC_STOPPED state
  428. */
  429. #define XSDFEC_SET_DEFAULT_CONFIG _IO(XSDFEC_MAGIC, 13)
  430. #endif /* __XILINX_SDFEC_H__ */