/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */1/*2* Xilinx SD-FEC3*4* Copyright (C) 2019 Xilinx, Inc.5*6* Description:7* This driver is developed for SDFEC16 IP. It provides a char device8* in sysfs and supports file operations like open(), close() and ioctl().9*/10#ifndef __XILINX_SDFEC_H__11#define __XILINX_SDFEC_H__1213#include <linux/types.h>1415/* Shared LDPC Tables */16#define XSDFEC_LDPC_SC_TABLE_ADDR_BASE (0x10000)17#define XSDFEC_LDPC_SC_TABLE_ADDR_HIGH (0x10400)18#define XSDFEC_LDPC_LA_TABLE_ADDR_BASE (0x18000)19#define XSDFEC_LDPC_LA_TABLE_ADDR_HIGH (0x19000)20#define XSDFEC_LDPC_QC_TABLE_ADDR_BASE (0x20000)21#define XSDFEC_LDPC_QC_TABLE_ADDR_HIGH (0x28000)2223/* LDPC tables depth */24#define XSDFEC_SC_TABLE_DEPTH \25(XSDFEC_LDPC_SC_TABLE_ADDR_HIGH - XSDFEC_LDPC_SC_TABLE_ADDR_BASE)26#define XSDFEC_LA_TABLE_DEPTH \27(XSDFEC_LDPC_LA_TABLE_ADDR_HIGH - XSDFEC_LDPC_LA_TABLE_ADDR_BASE)28#define XSDFEC_QC_TABLE_DEPTH \29(XSDFEC_LDPC_QC_TABLE_ADDR_HIGH - XSDFEC_LDPC_QC_TABLE_ADDR_BASE)3031/**32* enum xsdfec_code - Code Type.33* @XSDFEC_TURBO_CODE: Driver is configured for Turbo mode.34* @XSDFEC_LDPC_CODE: Driver is configured for LDPC mode.35*36* This enum is used to indicate the mode of the driver. The mode is determined37* by checking which codes are set in the driver. Note that the mode cannot be38* changed by the driver.39*/40enum xsdfec_code {41XSDFEC_TURBO_CODE = 0,42XSDFEC_LDPC_CODE,43};4445/**46* enum xsdfec_order - Order47* @XSDFEC_MAINTAIN_ORDER: Maintain order execution of blocks.48* @XSDFEC_OUT_OF_ORDER: Out-of-order execution of blocks.49*50* This enum is used to indicate whether the order of blocks can change from51* input to output.52*/53enum xsdfec_order {54XSDFEC_MAINTAIN_ORDER = 0,55XSDFEC_OUT_OF_ORDER,56};5758/**59* enum xsdfec_turbo_alg - Turbo Algorithm Type.60* @XSDFEC_MAX_SCALE: Max Log-Map algorithm with extrinsic scaling. When61* scaling is set to this is equivalent to the Max Log-Map62* algorithm.63* @XSDFEC_MAX_STAR: Log-Map algorithm.64* @XSDFEC_TURBO_ALG_MAX: Used to indicate out of bound Turbo algorithms.65*66* This enum specifies which Turbo Decode algorithm is in use.67*/68enum xsdfec_turbo_alg {69XSDFEC_MAX_SCALE = 0,70XSDFEC_MAX_STAR,71XSDFEC_TURBO_ALG_MAX,72};7374/**75* enum xsdfec_state - State.76* @XSDFEC_INIT: Driver is initialized.77* @XSDFEC_STARTED: Driver is started.78* @XSDFEC_STOPPED: Driver is stopped.79* @XSDFEC_NEEDS_RESET: Driver needs to be reset.80* @XSDFEC_PL_RECONFIGURE: Programmable Logic needs to be recofigured.81*82* This enum is used to indicate the state of the driver.83*/84enum xsdfec_state {85XSDFEC_INIT = 0,86XSDFEC_STARTED,87XSDFEC_STOPPED,88XSDFEC_NEEDS_RESET,89XSDFEC_PL_RECONFIGURE,90};9192/**93* enum xsdfec_axis_width - AXIS_WIDTH.DIN Setting for 128-bit width.94* @XSDFEC_1x128b: DIN data input stream consists of a 128-bit lane95* @XSDFEC_2x128b: DIN data input stream consists of two 128-bit lanes96* @XSDFEC_4x128b: DIN data input stream consists of four 128-bit lanes97*98* This enum is used to indicate the AXIS_WIDTH.DIN setting for 128-bit width.99* The number of lanes of the DIN data input stream depends upon the100* AXIS_WIDTH.DIN parameter.101*/102enum xsdfec_axis_width {103XSDFEC_1x128b = 1,104XSDFEC_2x128b = 2,105XSDFEC_4x128b = 4,106};107108/**109* enum xsdfec_axis_word_include - Words Configuration.110* @XSDFEC_FIXED_VALUE: Fixed, the DIN_WORDS AXI4-Stream interface is removed111* from the IP instance and is driven with the specified112* number of words.113* @XSDFEC_IN_BLOCK: In Block, configures the IP instance to expect a single114* DIN_WORDS value per input code block. The DIN_WORDS115* interface is present.116* @XSDFEC_PER_AXI_TRANSACTION: Per Transaction, configures the IP instance to117* expect one DIN_WORDS value per input transaction on the DIN interface. The118* DIN_WORDS interface is present.119* @XSDFEC_AXIS_WORDS_INCLUDE_MAX: Used to indicate out of bound Words120* Configurations.121*122* This enum is used to specify the DIN_WORDS configuration.123*/124enum xsdfec_axis_word_include {125XSDFEC_FIXED_VALUE = 0,126XSDFEC_IN_BLOCK,127XSDFEC_PER_AXI_TRANSACTION,128XSDFEC_AXIS_WORDS_INCLUDE_MAX,129};130131/**132* struct xsdfec_turbo - User data for Turbo codes.133* @alg: Specifies which Turbo decode algorithm to use134* @scale: Specifies the extrinsic scaling to apply when the Max Scale algorithm135* has been selected136*137* Turbo code structure to communicate parameters to XSDFEC driver.138*/139struct xsdfec_turbo {140__u32 alg;141__u8 scale;142};143144/**145* struct xsdfec_ldpc_params - User data for LDPC codes.146* @n: Number of code word bits147* @k: Number of information bits148* @psize: Size of sub-matrix149* @nlayers: Number of layers in code150* @nqc: Quasi Cyclic Number151* @nmqc: Number of M-sized QC operations in parity check matrix152* @nm: Number of M-size vectors in N153* @norm_type: Normalization required or not154* @no_packing: Determines if multiple QC ops should be performed155* @special_qc: Sub-Matrix property for Circulant weight > 0156* @no_final_parity: Decide if final parity check needs to be performed157* @max_schedule: Experimental code word scheduling limit158* @sc_off: SC offset159* @la_off: LA offset160* @qc_off: QC offset161* @sc_table: Pointer to SC Table which must be page aligned162* @la_table: Pointer to LA Table which must be page aligned163* @qc_table: Pointer to QC Table which must be page aligned164* @code_id: LDPC Code165*166* This structure describes the LDPC code that is passed to the driver by the167* application.168*/169struct xsdfec_ldpc_params {170__u32 n;171__u32 k;172__u32 psize;173__u32 nlayers;174__u32 nqc;175__u32 nmqc;176__u32 nm;177__u32 norm_type;178__u32 no_packing;179__u32 special_qc;180__u32 no_final_parity;181__u32 max_schedule;182__u32 sc_off;183__u32 la_off;184__u32 qc_off;185__u32 *sc_table;186__u32 *la_table;187__u32 *qc_table;188__u16 code_id;189};190191/**192* struct xsdfec_status - Status of SD-FEC core.193* @state: State of the SD-FEC core194* @activity: Describes if the SD-FEC instance is Active195*/196struct xsdfec_status {197__u32 state;198__s8 activity;199};200201/**202* struct xsdfec_irq - Enabling or Disabling Interrupts.203* @enable_isr: If true enables the ISR204* @enable_ecc_isr: If true enables the ECC ISR205*/206struct xsdfec_irq {207__s8 enable_isr;208__s8 enable_ecc_isr;209};210211/**212* struct xsdfec_config - Configuration of SD-FEC core.213* @code: The codes being used by the SD-FEC instance214* @order: Order of Operation215* @din_width: Width of the DIN AXI4-Stream216* @din_word_include: How DIN_WORDS are inputted217* @dout_width: Width of the DOUT AXI4-Stream218* @dout_word_include: HOW DOUT_WORDS are outputted219* @irq: Enabling or disabling interrupts220* @bypass: Is the core being bypassed221* @code_wr_protect: Is write protection of LDPC codes enabled222*/223struct xsdfec_config {224__u32 code;225__u32 order;226__u32 din_width;227__u32 din_word_include;228__u32 dout_width;229__u32 dout_word_include;230struct xsdfec_irq irq;231__s8 bypass;232__s8 code_wr_protect;233};234235/**236* struct xsdfec_stats - Stats retrived by ioctl XSDFEC_GET_STATS. Used237* to buffer atomic_t variables from struct238* xsdfec_dev. Counts are accumulated until239* the user clears them.240* @isr_err_count: Count of ISR errors241* @cecc_count: Count of Correctable ECC errors (SBE)242* @uecc_count: Count of Uncorrectable ECC errors (MBE)243*/244struct xsdfec_stats {245__u32 isr_err_count;246__u32 cecc_count;247__u32 uecc_count;248};249250/**251* struct xsdfec_ldpc_param_table_sizes - Used to store sizes of SD-FEC table252* entries for an individual LPDC code253* parameter.254* @sc_size: Size of SC table used255* @la_size: Size of LA table used256* @qc_size: Size of QC table used257*/258struct xsdfec_ldpc_param_table_sizes {259__u32 sc_size;260__u32 la_size;261__u32 qc_size;262};263264/*265* XSDFEC IOCTL List266*/267#define XSDFEC_MAGIC 'f'268/**269* DOC: XSDFEC_START_DEV270*271* @Description272*273* ioctl to start SD-FEC core274*275* This fails if the XSDFEC_SET_ORDER ioctl has not been previously called276*/277#define XSDFEC_START_DEV _IO(XSDFEC_MAGIC, 0)278/**279* DOC: XSDFEC_STOP_DEV280*281* @Description282*283* ioctl to stop the SD-FEC core284*/285#define XSDFEC_STOP_DEV _IO(XSDFEC_MAGIC, 1)286/**287* DOC: XSDFEC_GET_STATUS288*289* @Description290*291* ioctl that returns status of SD-FEC core292*/293#define XSDFEC_GET_STATUS _IOR(XSDFEC_MAGIC, 2, struct xsdfec_status)294/**295* DOC: XSDFEC_SET_IRQ296* @Parameters297*298* @struct xsdfec_irq *299* Pointer to the &struct xsdfec_irq that contains the interrupt settings300* for the SD-FEC core301*302* @Description303*304* ioctl to enable or disable irq305*/306#define XSDFEC_SET_IRQ _IOW(XSDFEC_MAGIC, 3, struct xsdfec_irq)307/**308* DOC: XSDFEC_SET_TURBO309* @Parameters310*311* @struct xsdfec_turbo *312* Pointer to the &struct xsdfec_turbo that contains the Turbo decode313* settings for the SD-FEC core314*315* @Description316*317* ioctl that sets the SD-FEC Turbo parameter values318*319* This can only be used when the driver is in the XSDFEC_STOPPED state320*/321#define XSDFEC_SET_TURBO _IOW(XSDFEC_MAGIC, 4, struct xsdfec_turbo)322/**323* DOC: XSDFEC_ADD_LDPC_CODE_PARAMS324* @Parameters325*326* @struct xsdfec_ldpc_params *327* Pointer to the &struct xsdfec_ldpc_params that contains the LDPC code328* parameters to be added to the SD-FEC Block329*330* @Description331* ioctl to add an LDPC code to the SD-FEC LDPC codes332*333* This can only be used when:334*335* - Driver is in the XSDFEC_STOPPED state336*337* - SD-FEC core is configured as LPDC338*339* - SD-FEC Code Write Protection is disabled340*/341#define XSDFEC_ADD_LDPC_CODE_PARAMS \342_IOW(XSDFEC_MAGIC, 5, struct xsdfec_ldpc_params)343/**344* DOC: XSDFEC_GET_CONFIG345* @Parameters346*347* @struct xsdfec_config *348* Pointer to the &struct xsdfec_config that contains the current349* configuration settings of the SD-FEC Block350*351* @Description352*353* ioctl that returns SD-FEC core configuration354*/355#define XSDFEC_GET_CONFIG _IOR(XSDFEC_MAGIC, 6, struct xsdfec_config)356/**357* DOC: XSDFEC_GET_TURBO358* @Parameters359*360* @struct xsdfec_turbo *361* Pointer to the &struct xsdfec_turbo that contains the current Turbo362* decode settings of the SD-FEC Block363*364* @Description365*366* ioctl that returns SD-FEC turbo param values367*/368#define XSDFEC_GET_TURBO _IOR(XSDFEC_MAGIC, 7, struct xsdfec_turbo)369/**370* DOC: XSDFEC_SET_ORDER371* @Parameters372*373* @struct unsigned long *374* Pointer to the unsigned long that contains a value from the375* @enum xsdfec_order376*377* @Description378*379* ioctl that sets order, if order of blocks can change from input to output380*381* This can only be used when the driver is in the XSDFEC_STOPPED state382*/383#define XSDFEC_SET_ORDER _IOW(XSDFEC_MAGIC, 8, unsigned long)384/**385* DOC: XSDFEC_SET_BYPASS386* @Parameters387*388* @struct bool *389* Pointer to bool that sets the bypass value, where false results in390* normal operation and false results in the SD-FEC performing the391* configured operations (same number of cycles) but output data matches392* the input data393*394* @Description395*396* ioctl that sets bypass.397*398* This can only be used when the driver is in the XSDFEC_STOPPED state399*/400#define XSDFEC_SET_BYPASS _IOW(XSDFEC_MAGIC, 9, bool)401/**402* DOC: XSDFEC_IS_ACTIVE403* @Parameters404*405* @struct bool *406* Pointer to bool that returns true if the SD-FEC is processing data407*408* @Description409*410* ioctl that determines if SD-FEC is processing data411*/412#define XSDFEC_IS_ACTIVE _IOR(XSDFEC_MAGIC, 10, bool)413/**414* DOC: XSDFEC_CLEAR_STATS415*416* @Description417*418* ioctl that clears error stats collected during interrupts419*/420#define XSDFEC_CLEAR_STATS _IO(XSDFEC_MAGIC, 11)421/**422* DOC: XSDFEC_GET_STATS423* @Parameters424*425* @struct xsdfec_stats *426* Pointer to the &struct xsdfec_stats that will contain the updated stats427* values428*429* @Description430*431* ioctl that returns SD-FEC core stats432*433* This can only be used when the driver is in the XSDFEC_STOPPED state434*/435#define XSDFEC_GET_STATS _IOR(XSDFEC_MAGIC, 12, struct xsdfec_stats)436/**437* DOC: XSDFEC_SET_DEFAULT_CONFIG438*439* @Description440*441* ioctl that returns SD-FEC core to default config, use after a reset442*443* This can only be used when the driver is in the XSDFEC_STOPPED state444*/445#define XSDFEC_SET_DEFAULT_CONFIG _IO(XSDFEC_MAGIC, 13)446447#endif /* __XILINX_SDFEC_H__ */448449450