linux/drivers/net/ethernet/freescale/fman/fman.c

// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-or-later
/*
 * Copyright 2008 - 2015 Freescale Semiconductor Inc.
 * Copyright 2020 NXP
 */

#define pr_fmt(fmt)

#include <linux/fsl/guts.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/module.h>
#include <linux/of_platform.h>
#include <linux/clk.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>
#include <linux/interrupt.h>
#include <linux/libfdt_env.h>

#include "fman.h"
#include "fman_muram.h"
#include "fman_keygen.h"

/* General defines */
#define FMAN_LIODN_TBL
#define MAX_NUM_OF_MACS
#define FM_NUM_OF_FMAN_CTRL_EVENT_REGS
#define BASE_RX_PORTID
#define BASE_TX_PORTID

/* Modules registers offsets */
#define BMI_OFFSET
#define QMI_OFFSET
#define KG_OFFSET
#define DMA_OFFSET
#define FPM_OFFSET
#define IMEM_OFFSET
#define HWP_OFFSET
#define CGP_OFFSET

/* Exceptions bit map */
#define EX_DMA_BUS_ERROR
#define EX_DMA_READ_ECC
#define EX_DMA_SYSTEM_WRITE_ECC
#define EX_DMA_FM_WRITE_ECC
#define EX_FPM_STALL_ON_TASKS
#define EX_FPM_SINGLE_ECC
#define EX_FPM_DOUBLE_ECC
#define EX_QMI_SINGLE_ECC
#define EX_QMI_DEQ_FROM_UNKNOWN_PORTID
#define EX_QMI_DOUBLE_ECC
#define EX_BMI_LIST_RAM_ECC
#define EX_BMI_STORAGE_PROFILE_ECC
#define EX_BMI_STATISTICS_RAM_ECC
#define EX_IRAM_ECC
#define EX_MURAM_ECC
#define EX_BMI_DISPATCH_RAM_ECC
#define EX_DMA_SINGLE_PORT_ECC

/* DMA defines */
/* masks */
#define DMA_MODE_BER
#define DMA_MODE_ECC
#define DMA_MODE_SECURE_PROT
#define DMA_MODE_AXI_DBG_MASK

#define DMA_TRANSFER_PORTID_MASK
#define DMA_TRANSFER_TNUM_MASK
#define DMA_TRANSFER_LIODN_MASK

#define DMA_STATUS_BUS_ERR
#define DMA_STATUS_READ_ECC
#define DMA_STATUS_SYSTEM_WRITE_ECC
#define DMA_STATUS_FM_WRITE_ECC
#define DMA_STATUS_FM_SPDAT_ECC

#define DMA_MODE_CACHE_OR_SHIFT
#define DMA_MODE_AXI_DBG_SHIFT
#define DMA_MODE_CEN_SHIFT
#define DMA_MODE_CEN_MASK
#define DMA_MODE_DBG_SHIFT
#define DMA_MODE_AID_MODE_SHIFT

#define DMA_THRESH_COMMQ_SHIFT
#define DMA_THRESH_READ_INT_BUF_SHIFT
#define DMA_THRESH_READ_INT_BUF_MASK
#define DMA_THRESH_WRITE_INT_BUF_MASK

#define DMA_TRANSFER_PORTID_SHIFT
#define DMA_TRANSFER_TNUM_SHIFT

#define DMA_CAM_SIZEOF_ENTRY
#define DMA_CAM_UNITS

#define DMA_LIODN_SHIFT
#define DMA_LIODN_BASE_MASK

/* FPM defines */
#define FPM_EV_MASK_DOUBLE_ECC
#define FPM_EV_MASK_STALL
#define FPM_EV_MASK_SINGLE_ECC
#define FPM_EV_MASK_RELEASE_FM
#define FPM_EV_MASK_DOUBLE_ECC_EN
#define FPM_EV_MASK_STALL_EN
#define FPM_EV_MASK_SINGLE_ECC_EN
#define FPM_EV_MASK_EXTERNAL_HALT
#define FPM_EV_MASK_ECC_ERR_HALT

#define FPM_RAM_MURAM_ECC
#define FPM_RAM_IRAM_ECC
#define FPM_IRAM_ECC_ERR_EX_EN
#define FPM_MURAM_ECC_ERR_EX_EN
#define FPM_RAM_IRAM_ECC_EN
#define FPM_RAM_RAMS_ECC_EN
#define FPM_RAM_RAMS_ECC_EN_SRC_SEL

#define FPM_REV1_MAJOR_MASK
#define FPM_REV1_MINOR_MASK

#define FPM_DISP_LIMIT_SHIFT

#define FPM_PRT_FM_CTL1
#define FPM_PRT_FM_CTL2
#define FPM_PORT_FM_CTL_PORTID_SHIFT
#define FPM_PRC_ORA_FM_CTL_SEL_SHIFT

#define FPM_THR1_PRS_SHIFT
#define FPM_THR1_KG_SHIFT
#define FPM_THR1_PLCR_SHIFT
#define FPM_THR1_BMI_SHIFT

#define FPM_THR2_QMI_ENQ_SHIFT
#define FPM_THR2_QMI_DEQ_SHIFT
#define FPM_THR2_FM_CTL1_SHIFT
#define FPM_THR2_FM_CTL2_SHIFT

#define FPM_EV_MASK_CAT_ERR_SHIFT
#define FPM_EV_MASK_DMA_ERR_SHIFT

#define FPM_REV1_MAJOR_SHIFT

#define FPM_RSTC_FM_RESET
#define FPM_RSTC_MAC0_RESET
#define FPM_RSTC_MAC1_RESET
#define FPM_RSTC_MAC2_RESET
#define FPM_RSTC_MAC3_RESET
#define FPM_RSTC_MAC8_RESET
#define FPM_RSTC_MAC4_RESET
#define FPM_RSTC_MAC5_RESET
#define FPM_RSTC_MAC6_RESET
#define FPM_RSTC_MAC7_RESET
#define FPM_RSTC_MAC9_RESET

#define FPM_TS_INT_SHIFT
#define FPM_TS_CTL_EN

/* BMI defines */
#define BMI_INIT_START
#define BMI_ERR_INTR_EN_STORAGE_PROFILE_ECC
#define BMI_ERR_INTR_EN_LIST_RAM_ECC
#define BMI_ERR_INTR_EN_STATISTICS_RAM_ECC
#define BMI_ERR_INTR_EN_DISPATCH_RAM_ECC
#define BMI_NUM_OF_TASKS_MASK
#define BMI_NUM_OF_EXTRA_TASKS_MASK
#define BMI_NUM_OF_DMAS_MASK
#define BMI_NUM_OF_EXTRA_DMAS_MASK
#define BMI_FIFO_SIZE_MASK
#define BMI_EXTRA_FIFO_SIZE_MASK
#define BMI_CFG2_DMAS_MASK
#define BMI_CFG2_TASKS_MASK

#define BMI_CFG2_TASKS_SHIFT
#define BMI_CFG2_DMAS_SHIFT
#define BMI_CFG1_FIFO_SIZE_SHIFT
#define BMI_NUM_OF_TASKS_SHIFT
#define BMI_EXTRA_NUM_OF_TASKS_SHIFT
#define BMI_NUM_OF_DMAS_SHIFT
#define BMI_EXTRA_NUM_OF_DMAS_SHIFT

#define BMI_FIFO_ALIGN

#define BMI_EXTRA_FIFO_SIZE_SHIFT

/* QMI defines */
#define QMI_CFG_ENQ_EN
#define QMI_CFG_DEQ_EN
#define QMI_CFG_EN_COUNTERS
#define QMI_CFG_DEQ_MASK
#define QMI_CFG_ENQ_MASK
#define QMI_CFG_ENQ_SHIFT

#define QMI_ERR_INTR_EN_DOUBLE_ECC
#define QMI_ERR_INTR_EN_DEQ_FROM_DEF
#define QMI_INTR_EN_SINGLE_ECC

#define QMI_GS_HALT_NOT_BUSY

/* HWP defines */
#define HWP_RPIMAC_PEN

/* IRAM defines */
#define IRAM_IADD_AIE
#define IRAM_READY

/* Default values */
#define DEFAULT_CATASTROPHIC_ERR
#define DEFAULT_DMA_ERR
#define DEFAULT_AID_MODE
#define DEFAULT_DMA_COMM_Q_LOW
#define DEFAULT_DMA_COMM_Q_HIGH
#define DEFAULT_CACHE_OVERRIDE
#define DEFAULT_DMA_CAM_NUM_OF_ENTRIES
#define DEFAULT_DMA_DBG_CNT_MODE
#define DEFAULT_DMA_SOS_EMERGENCY
#define DEFAULT_DMA_WATCHDOG
#define DEFAULT_DISP_LIMIT
#define DEFAULT_PRS_DISP_TH
#define DEFAULT_PLCR_DISP_TH
#define DEFAULT_KG_DISP_TH
#define DEFAULT_BMI_DISP_TH
#define DEFAULT_QMI_ENQ_DISP_TH
#define DEFAULT_QMI_DEQ_DISP_TH
#define DEFAULT_FM_CTL1_DISP_TH
#define DEFAULT_FM_CTL2_DISP_TH

#define DFLT_AXI_DBG_NUM_OF_BEATS

#define DFLT_DMA_READ_INT_BUF_LOW(dma_thresh_max_buf)
#define DFLT_DMA_READ_INT_BUF_HIGH(dma_thresh_max_buf)
#define DFLT_DMA_WRITE_INT_BUF_LOW(dma_thresh_max_buf)
#define DFLT_DMA_WRITE_INT_BUF_HIGH(dma_thresh_max_buf)

#define DMA_COMM_Q_LOW_FMAN_V3
#define DMA_COMM_Q_LOW_FMAN_V2(dma_thresh_max_commq)
#define DFLT_DMA_COMM_Q_LOW(major, dma_thresh_max_commq)

#define DMA_COMM_Q_HIGH_FMAN_V3
#define DMA_COMM_Q_HIGH_FMAN_V2(dma_thresh_max_commq)
#define DFLT_DMA_COMM_Q_HIGH(major, dma_thresh_max_commq)

#define TOTAL_NUM_OF_TASKS_FMAN_V3L
#define TOTAL_NUM_OF_TASKS_FMAN_V3H
#define DFLT_TOTAL_NUM_OF_TASKS(major, minor, bmi_max_num_of_tasks)

#define DMA_CAM_NUM_OF_ENTRIES_FMAN_V3
#define DMA_CAM_NUM_OF_ENTRIES_FMAN_V2
#define DFLT_DMA_CAM_NUM_OF_ENTRIES(major)

#define FM_TIMESTAMP_1_USEC_BIT

/* Defines used for enabling/disabling FMan interrupts */
#define ERR_INTR_EN_DMA
#define ERR_INTR_EN_FPM
#define ERR_INTR_EN_BMI
#define ERR_INTR_EN_QMI
#define ERR_INTR_EN_MURAM
#define ERR_INTR_EN_MAC0
#define ERR_INTR_EN_MAC1
#define ERR_INTR_EN_MAC2
#define ERR_INTR_EN_MAC3
#define ERR_INTR_EN_MAC4
#define ERR_INTR_EN_MAC5
#define ERR_INTR_EN_MAC6
#define ERR_INTR_EN_MAC7
#define ERR_INTR_EN_MAC8
#define ERR_INTR_EN_MAC9

#define INTR_EN_QMI
#define INTR_EN_MAC0
#define INTR_EN_MAC1
#define INTR_EN_MAC2
#define INTR_EN_MAC3
#define INTR_EN_MAC4
#define INTR_EN_MAC5
#define INTR_EN_MAC6
#define INTR_EN_MAC7
#define INTR_EN_MAC8
#define INTR_EN_MAC9
#define INTR_EN_REV0
#define INTR_EN_REV1
#define INTR_EN_REV2
#define INTR_EN_REV3
#define INTR_EN_TMR

enum fman_dma_aid_mode {};

struct fman_iram_regs {};

struct fman_fpm_regs {};

struct fman_bmi_regs {};

struct fman_qmi_regs {};

struct fman_dma_regs {};

struct fman_hwp_regs {};

/* Structure that holds current FMan state.
 * Used for saving run time information.
 */
struct fman_state_struct {};

/* Structure that holds FMan initial configuration */
struct fman_cfg {};

#ifdef CONFIG_DPAA_ERRATUM_A050385
static bool fman_has_err_a050385;
#endif

static irqreturn_t fman_exceptions(struct fman *fman,
				   enum fman_exceptions exception)
{}

static irqreturn_t fman_bus_error(struct fman *fman, u8 __maybe_unused port_id,
				  u64 __maybe_unused addr,
				  u8 __maybe_unused tnum,
				  u16 __maybe_unused liodn)
{}

static inline irqreturn_t call_mac_isr(struct fman *fman, u8 id)
{}

static inline u8 hw_port_id_to_sw_port_id(u8 major, u8 hw_port_id)
{}

static void set_port_order_restoration(struct fman_fpm_regs __iomem *fpm_rg,
				       u8 port_id)
{}

static void set_port_liodn(struct fman *fman, u8 port_id,
			   u32 liodn_base, u32 liodn_ofst)
{}

static void enable_rams_ecc(struct fman_fpm_regs __iomem *fpm_rg)
{}

static void disable_rams_ecc(struct fman_fpm_regs __iomem *fpm_rg)
{}

static void fman_defconfig(struct fman_cfg *cfg)
{}

static int dma_init(struct fman *fman)
{}

static void fpm_init(struct fman_fpm_regs __iomem *fpm_rg, struct fman_cfg *cfg)
{}

static void bmi_init(struct fman_bmi_regs __iomem *bmi_rg,
		     struct fman_cfg *cfg)
{}

static void qmi_init(struct fman_qmi_regs __iomem *qmi_rg,
		     struct fman_cfg *cfg)
{}

static void hwp_init(struct fman_hwp_regs __iomem *hwp_rg)
{}

static int enable(struct fman *fman, struct fman_cfg *cfg)
{}

static int set_exception(struct fman *fman,
			 enum fman_exceptions exception, bool enable)
{}

static void resume(struct fman_fpm_regs __iomem *fpm_rg)
{}

static int fill_soc_specific_params(struct fman_state_struct *state)
{}

static bool is_init_done(struct fman_cfg *cfg)
{}

static void free_init_resources(struct fman *fman)
{}

static irqreturn_t bmi_err_event(struct fman *fman)
{}

static irqreturn_t qmi_err_event(struct fman *fman)
{}

static irqreturn_t dma_err_event(struct fman *fman)
{}

static irqreturn_t fpm_err_event(struct fman *fman)
{}

static irqreturn_t muram_err_intr(struct fman *fman)
{}

static irqreturn_t qmi_event(struct fman *fman)
{}

static void enable_time_stamp(struct fman *fman)
{}

static int clear_iram(struct fman *fman)
{}

static u32 get_exception_flag(enum fman_exceptions exception)
{}

static int get_module_event(enum fman_event_modules module, u8 mod_id,
			    enum fman_intr_type intr_type)
{}

static int set_size_of_fifo(struct fman *fman, u8 port_id, u32 *size_of_fifo,
			    u32 *extra_size_of_fifo)
{}

static int set_num_of_tasks(struct fman *fman, u8 port_id, u8 *num_of_tasks,
			    u8 *num_of_extra_tasks)
{}

static int set_num_of_open_dmas(struct fman *fman, u8 port_id,
				u8 *num_of_open_dmas,
				u8 *num_of_extra_open_dmas)
{}

static int fman_config(struct fman *fman)
{}

static int fman_reset(struct fman *fman)
{}

static int fman_init(struct fman *fman)
{}

static int fman_set_exception(struct fman *fman,
			      enum fman_exceptions exception, bool enable)
{}

/**
 * fman_register_intr
 * @fman:	A Pointer to FMan device
 * @module:	Calling module
 * @mod_id:	Module id (if more than 1 exists, '0' if not)
 * @intr_type:	Interrupt type (error/normal) selection.
 * @isr_cb:	The interrupt service routine.
 * @src_arg:	Argument to be passed to isr_cb.
 *
 * Used to register an event handler to be processed by FMan
 *
 * Return: 0 on success; Error code otherwise.
 */
void fman_register_intr(struct fman *fman, enum fman_event_modules module,
			u8 mod_id, enum fman_intr_type intr_type,
			void (*isr_cb)(void *src_arg), void *src_arg)
{}
EXPORT_SYMBOL();

/**
 * fman_unregister_intr
 * @fman:	A Pointer to FMan device
 * @module:	Calling module
 * @mod_id:	Module id (if more than 1 exists, '0' if not)
 * @intr_type:	Interrupt type (error/normal) selection.
 *
 * Used to unregister an event handler to be processed by FMan
 *
 * Return: 0 on success; Error code otherwise.
 */
void fman_unregister_intr(struct fman *fman, enum fman_event_modules module,
			  u8 mod_id, enum fman_intr_type intr_type)
{}
EXPORT_SYMBOL();

/**
 * fman_set_port_params
 * @fman:		A Pointer to FMan device
 * @port_params:	Port parameters
 *
 * Used by FMan Port to pass parameters to the FMan
 *
 * Return: 0 on success; Error code otherwise.
 */
int fman_set_port_params(struct fman *fman,
			 struct fman_port_init_params *port_params)
{}
EXPORT_SYMBOL();

/**
 * fman_reset_mac
 * @fman:	A Pointer to FMan device
 * @mac_id:	MAC id to be reset
 *
 * Reset a specific MAC
 *
 * Return: 0 on success; Error code otherwise.
 */
int fman_reset_mac(struct fman *fman, u8 mac_id)
{}
EXPORT_SYMBOL();

/**
 * fman_set_mac_max_frame
 * @fman:	A Pointer to FMan device
 * @mac_id:	MAC id
 * @mfl:	Maximum frame length
 *
 * Set maximum frame length of specific MAC in FMan driver
 *
 * Return: 0 on success; Error code otherwise.
 */
int fman_set_mac_max_frame(struct fman *fman, u8 mac_id, u16 mfl)
{}
EXPORT_SYMBOL();

/**
 * fman_get_clock_freq
 * @fman:	A Pointer to FMan device
 *
 * Get FMan clock frequency
 *
 * Return: FMan clock frequency
 */
u16 fman_get_clock_freq(struct fman *fman)
{}

/**
 * fman_get_bmi_max_fifo_size
 * @fman:	A Pointer to FMan device
 *
 * Get FMan maximum FIFO size
 *
 * Return: FMan Maximum FIFO size
 */
u32 fman_get_bmi_max_fifo_size(struct fman *fman)
{}
EXPORT_SYMBOL();

/**
 * fman_get_revision
 * @fman:		- Pointer to the FMan module
 * @rev_info:		- A structure of revision information parameters.
 *
 * Returns the FM revision
 *
 * Allowed only following fman_init().
 *
 * Return: 0 on success; Error code otherwise.
 */
void fman_get_revision(struct fman *fman, struct fman_rev_info *rev_info)
{}
EXPORT_SYMBOL();

/**
 * fman_get_qman_channel_id
 * @fman:	A Pointer to FMan device
 * @port_id:	Port id
 *
 * Get QMan channel ID associated to the Port id
 *
 * Return: QMan channel ID
 */
u32 fman_get_qman_channel_id(struct fman *fman, u32 port_id)
{}
EXPORT_SYMBOL();

/**
 * fman_get_mem_region
 * @fman:	A Pointer to FMan device
 *
 * Get FMan memory region
 *
 * Return: A structure with FMan memory region information
 */
struct resource *fman_get_mem_region(struct fman *fman)
{}
EXPORT_SYMBOL();

/* Bootargs defines */
/* Extra headroom for RX buffers - Default, min and max */
#define FSL_FM_RX_EXTRA_HEADROOM
#define FSL_FM_RX_EXTRA_HEADROOM_MIN
#define FSL_FM_RX_EXTRA_HEADROOM_MAX

/* Maximum frame length */
#define FSL_FM_MAX_FRAME_SIZE
#define FSL_FM_MAX_POSSIBLE_FRAME_SIZE
#define FSL_FM_MIN_POSSIBLE_FRAME_SIZE

/* Extra headroom for Rx buffers.
 * FMan is instructed to allocate, on the Rx path, this amount of
 * space at the beginning of a data buffer, beside the DPA private
 * data area and the IC fields.
 * Does not impact Tx buffer layout.
 * Configurable from bootargs. 64 by default, it's needed on
 * particular forwarding scenarios that add extra headers to the
 * forwarded frame.
 */
static int fsl_fm_rx_extra_headroom =;
module_param(fsl_fm_rx_extra_headroom, int, 0);
MODULE_PARM_DESC();

/* Max frame size, across all interfaces.
 * Configurable from bootargs, to avoid allocating oversized (socket)
 * buffers when not using jumbo frames.
 * Must be large enough to accommodate the network MTU, but small enough
 * to avoid wasting skb memory.
 */
static int fsl_fm_max_frm =;
module_param(fsl_fm_max_frm, int, 0);
MODULE_PARM_DESC();

/**
 * fman_get_max_frm
 *
 * Return: Max frame length configured in the FM driver
 */
u16 fman_get_max_frm(void)
{}
EXPORT_SYMBOL();

/**
 * fman_get_rx_extra_headroom
 *
 * Return: Extra headroom size configured in the FM driver
 */
int fman_get_rx_extra_headroom(void)
{}
EXPORT_SYMBOL();

/**
 * fman_bind
 * @fm_dev:	FMan OF device pointer
 *
 * Bind to a specific FMan device.
 *
 * Allowed only after the port was created.
 *
 * Return: A pointer to the FMan device
 */
struct fman *fman_bind(struct device *fm_dev)
{}
EXPORT_SYMBOL();

#ifdef CONFIG_DPAA_ERRATUM_A050385
bool fman_has_errata_a050385(void)
{
	return fman_has_err_a050385;
}
EXPORT_SYMBOL(fman_has_errata_a050385);
#endif

static irqreturn_t fman_err_irq(int irq, void *handle)
{}

static irqreturn_t fman_irq(int irq, void *handle)
{}

static const struct of_device_id fman_muram_match[] =;
MODULE_DEVICE_TABLE(of, fman_muram_match);

static struct fman *read_dts_node(struct platform_device *of_dev)
{}

static int fman_probe(struct platform_device *of_dev)
{}

static const struct of_device_id fman_match[] =;

MODULE_DEVICE_TABLE(of, fman_match);

static struct platform_driver fman_driver =;

static int __init fman_load(void)
{}
module_init();

static void __exit fman_unload(void)
{}
module_exit(fman_unload);

MODULE_LICENSE();
MODULE_DESCRIPTION();