18585bdadSSean Anderson // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-or-later
218a6c85fSIgal Liberman /*
318a6c85fSIgal Liberman  * Copyright 2008 - 2015 Freescale Semiconductor Inc.
418a6c85fSIgal Liberman  */
518a6c85fSIgal Liberman 
618a6c85fSIgal Liberman #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
718a6c85fSIgal Liberman 
818a6c85fSIgal Liberman #include <linux/io.h>
9*3d40aed8SRob Herring #include <linux/platform_device.h>
1018a6c85fSIgal Liberman #include <linux/slab.h>
1118a6c85fSIgal Liberman #include <linux/module.h>
1218a6c85fSIgal Liberman #include <linux/interrupt.h>
1318a6c85fSIgal Liberman #include <linux/of_platform.h>
1418a6c85fSIgal Liberman #include <linux/of_address.h>
1518a6c85fSIgal Liberman #include <linux/delay.h>
1618a6c85fSIgal Liberman #include <linux/libfdt_env.h>
1718a6c85fSIgal Liberman 
18ca58ce57SMadalin Bucur #include "fman.h"
19ca58ce57SMadalin Bucur #include "fman_port.h"
20ca58ce57SMadalin Bucur #include "fman_sp.h"
217472f4f2SIordache Florinel-R70177 #include "fman_keygen.h"
22ca58ce57SMadalin Bucur 
2318a6c85fSIgal Liberman /* Queue ID */
2418a6c85fSIgal Liberman #define DFLT_FQ_ID		0x00FFFFFF
2518a6c85fSIgal Liberman 
2618a6c85fSIgal Liberman /* General defines */
2718a6c85fSIgal Liberman #define PORT_BMI_FIFO_UNITS		0x100
2818a6c85fSIgal Liberman 
2918a6c85fSIgal Liberman #define MAX_PORT_FIFO_SIZE(bmi_max_fifo_size)	\
3018a6c85fSIgal Liberman 	min((u32)bmi_max_fifo_size, (u32)1024 * FMAN_BMI_FIFO_UNITS)
3118a6c85fSIgal Liberman 
3218a6c85fSIgal Liberman #define PORT_CG_MAP_NUM			8
3318a6c85fSIgal Liberman #define PORT_PRS_RESULT_WORDS_NUM	8
3418a6c85fSIgal Liberman #define PORT_IC_OFFSET_UNITS		0x10
3518a6c85fSIgal Liberman 
3618a6c85fSIgal Liberman #define MIN_EXT_BUF_SIZE		64
3718a6c85fSIgal Liberman 
3818a6c85fSIgal Liberman #define BMI_PORT_REGS_OFFSET				0
3918a6c85fSIgal Liberman #define QMI_PORT_REGS_OFFSET				0x400
401df653cfSMadalin Bucur #define HWP_PORT_REGS_OFFSET				0x800
4118a6c85fSIgal Liberman 
4218a6c85fSIgal Liberman /* Default values */
4318a6c85fSIgal Liberman #define DFLT_PORT_BUFFER_PREFIX_CONTEXT_DATA_ALIGN		\
4418a6c85fSIgal Liberman 	DFLT_FM_SP_BUFFER_PREFIX_CONTEXT_DATA_ALIGN
4518a6c85fSIgal Liberman 
4618a6c85fSIgal Liberman #define DFLT_PORT_CUT_BYTES_FROM_END		4
4718a6c85fSIgal Liberman 
4818a6c85fSIgal Liberman #define DFLT_PORT_ERRORS_TO_DISCARD		FM_PORT_FRM_ERR_CLS_DISCARD
4918a6c85fSIgal Liberman #define DFLT_PORT_MAX_FRAME_LENGTH		9600
5018a6c85fSIgal Liberman 
5118a6c85fSIgal Liberman #define DFLT_PORT_RX_FIFO_PRI_ELEVATION_LEV(bmi_max_fifo_size)	\
5218a6c85fSIgal Liberman 	MAX_PORT_FIFO_SIZE(bmi_max_fifo_size)
5318a6c85fSIgal Liberman 
5418a6c85fSIgal Liberman #define DFLT_PORT_RX_FIFO_THRESHOLD(major, bmi_max_fifo_size)	\
5518a6c85fSIgal Liberman 	(major == 6 ?						\
5618a6c85fSIgal Liberman 	MAX_PORT_FIFO_SIZE(bmi_max_fifo_size) :		\
5718a6c85fSIgal Liberman 	(MAX_PORT_FIFO_SIZE(bmi_max_fifo_size) * 3 / 4))	\
5818a6c85fSIgal Liberman 
5918a6c85fSIgal Liberman #define DFLT_PORT_EXTRA_NUM_OF_FIFO_BUFS		0
6018a6c85fSIgal Liberman 
6118a6c85fSIgal Liberman /* QMI defines */
6218a6c85fSIgal Liberman #define QMI_DEQ_CFG_SUBPORTAL_MASK		0x1f
6318a6c85fSIgal Liberman 
6418a6c85fSIgal Liberman #define QMI_PORT_CFG_EN				0x80000000
6518a6c85fSIgal Liberman #define QMI_PORT_STATUS_DEQ_FD_BSY		0x20000000
6618a6c85fSIgal Liberman 
6718a6c85fSIgal Liberman #define QMI_DEQ_CFG_PRI				0x80000000
6818a6c85fSIgal Liberman #define QMI_DEQ_CFG_TYPE1			0x10000000
6918a6c85fSIgal Liberman #define QMI_DEQ_CFG_TYPE2			0x20000000
7018a6c85fSIgal Liberman #define QMI_DEQ_CFG_TYPE3			0x30000000
7118a6c85fSIgal Liberman #define QMI_DEQ_CFG_PREFETCH_PARTIAL		0x01000000
7218a6c85fSIgal Liberman #define QMI_DEQ_CFG_PREFETCH_FULL		0x03000000
7318a6c85fSIgal Liberman #define QMI_DEQ_CFG_SP_MASK			0xf
7418a6c85fSIgal Liberman #define QMI_DEQ_CFG_SP_SHIFT			20
7518a6c85fSIgal Liberman 
7618a6c85fSIgal Liberman #define QMI_BYTE_COUNT_LEVEL_CONTROL(_type)	\
7718a6c85fSIgal Liberman 	(_type == FMAN_PORT_TYPE_TX ? 0x1400 : 0x400)
7818a6c85fSIgal Liberman 
7918a6c85fSIgal Liberman /* BMI defins */
8018a6c85fSIgal Liberman #define BMI_EBD_EN				0x80000000
8118a6c85fSIgal Liberman 
8218a6c85fSIgal Liberman #define BMI_PORT_CFG_EN				0x80000000
8318a6c85fSIgal Liberman 
8418a6c85fSIgal Liberman #define BMI_PORT_STATUS_BSY			0x80000000
8518a6c85fSIgal Liberman 
8618a6c85fSIgal Liberman #define BMI_DMA_ATTR_SWP_SHIFT			FMAN_SP_DMA_ATTR_SWP_SHIFT
8718a6c85fSIgal Liberman #define BMI_DMA_ATTR_WRITE_OPTIMIZE		FMAN_SP_DMA_ATTR_WRITE_OPTIMIZE
8818a6c85fSIgal Liberman 
8918a6c85fSIgal Liberman #define BMI_RX_FIFO_PRI_ELEVATION_SHIFT	16
9018a6c85fSIgal Liberman #define BMI_RX_FIFO_THRESHOLD_ETHE		0x80000000
9118a6c85fSIgal Liberman 
9218a6c85fSIgal Liberman #define BMI_FRAME_END_CS_IGNORE_SHIFT		24
9318a6c85fSIgal Liberman #define BMI_FRAME_END_CS_IGNORE_MASK		0x0000001f
9418a6c85fSIgal Liberman 
9518a6c85fSIgal Liberman #define BMI_RX_FRAME_END_CUT_SHIFT		16
9618a6c85fSIgal Liberman #define BMI_RX_FRAME_END_CUT_MASK		0x0000001f
9718a6c85fSIgal Liberman 
9818a6c85fSIgal Liberman #define BMI_IC_TO_EXT_SHIFT			FMAN_SP_IC_TO_EXT_SHIFT
9918a6c85fSIgal Liberman #define BMI_IC_TO_EXT_MASK			0x0000001f
10018a6c85fSIgal Liberman #define BMI_IC_FROM_INT_SHIFT			FMAN_SP_IC_FROM_INT_SHIFT
10118a6c85fSIgal Liberman #define BMI_IC_FROM_INT_MASK			0x0000000f
10218a6c85fSIgal Liberman #define BMI_IC_SIZE_MASK			0x0000001f
10318a6c85fSIgal Liberman 
10418a6c85fSIgal Liberman #define BMI_INT_BUF_MARG_SHIFT			28
10518a6c85fSIgal Liberman #define BMI_INT_BUF_MARG_MASK			0x0000000f
10618a6c85fSIgal Liberman #define BMI_EXT_BUF_MARG_START_SHIFT		FMAN_SP_EXT_BUF_MARG_START_SHIFT
10718a6c85fSIgal Liberman #define BMI_EXT_BUF_MARG_START_MASK		0x000001ff
10818a6c85fSIgal Liberman #define BMI_EXT_BUF_MARG_END_MASK		0x000001ff
10918a6c85fSIgal Liberman 
11018a6c85fSIgal Liberman #define BMI_CMD_MR_LEAC				0x00200000
11118a6c85fSIgal Liberman #define BMI_CMD_MR_SLEAC			0x00100000
11218a6c85fSIgal Liberman #define BMI_CMD_MR_MA				0x00080000
11318a6c85fSIgal Liberman #define BMI_CMD_MR_DEAS				0x00040000
11418a6c85fSIgal Liberman #define BMI_CMD_RX_MR_DEF			(BMI_CMD_MR_LEAC | \
11518a6c85fSIgal Liberman 						BMI_CMD_MR_SLEAC | \
11618a6c85fSIgal Liberman 						BMI_CMD_MR_MA | \
11718a6c85fSIgal Liberman 						BMI_CMD_MR_DEAS)
11818a6c85fSIgal Liberman #define BMI_CMD_TX_MR_DEF			0
11918a6c85fSIgal Liberman 
12018a6c85fSIgal Liberman #define BMI_CMD_ATTR_ORDER			0x80000000
12118a6c85fSIgal Liberman #define BMI_CMD_ATTR_SYNC			0x02000000
12218a6c85fSIgal Liberman #define BMI_CMD_ATTR_COLOR_SHIFT		26
12318a6c85fSIgal Liberman 
12418a6c85fSIgal Liberman #define BMI_FIFO_PIPELINE_DEPTH_SHIFT		12
12518a6c85fSIgal Liberman #define BMI_FIFO_PIPELINE_DEPTH_MASK		0x0000000f
12618a6c85fSIgal Liberman #define BMI_NEXT_ENG_FD_BITS_SHIFT		24
12718a6c85fSIgal Liberman 
12818a6c85fSIgal Liberman #define BMI_EXT_BUF_POOL_VALID			FMAN_SP_EXT_BUF_POOL_VALID
12918a6c85fSIgal Liberman #define BMI_EXT_BUF_POOL_EN_COUNTER		FMAN_SP_EXT_BUF_POOL_EN_COUNTER
13018a6c85fSIgal Liberman #define BMI_EXT_BUF_POOL_BACKUP		FMAN_SP_EXT_BUF_POOL_BACKUP
13118a6c85fSIgal Liberman #define BMI_EXT_BUF_POOL_ID_SHIFT		16
13218a6c85fSIgal Liberman #define BMI_EXT_BUF_POOL_ID_MASK		0x003F0000
13318a6c85fSIgal Liberman #define BMI_POOL_DEP_NUM_OF_POOLS_SHIFT	16
13418a6c85fSIgal Liberman 
13518a6c85fSIgal Liberman #define BMI_TX_FIFO_MIN_FILL_SHIFT		16
13618a6c85fSIgal Liberman 
13718a6c85fSIgal Liberman #define BMI_PRIORITY_ELEVATION_LEVEL ((0x3FF + 1) * PORT_BMI_FIFO_UNITS)
13818a6c85fSIgal Liberman #define BMI_FIFO_THRESHOLD	      ((0x3FF + 1) * PORT_BMI_FIFO_UNITS)
13918a6c85fSIgal Liberman 
14018a6c85fSIgal Liberman #define BMI_DEQUEUE_PIPELINE_DEPTH(_type, _speed)		\
14118a6c85fSIgal Liberman 	((_type == FMAN_PORT_TYPE_TX && _speed == 10000) ? 4 : 1)
14218a6c85fSIgal Liberman 
14318a6c85fSIgal Liberman #define RX_ERRS_TO_ENQ				  \
14418a6c85fSIgal Liberman 	(FM_PORT_FRM_ERR_DMA			| \
14518a6c85fSIgal Liberman 	FM_PORT_FRM_ERR_PHYSICAL		| \
14618a6c85fSIgal Liberman 	FM_PORT_FRM_ERR_SIZE			| \
14718a6c85fSIgal Liberman 	FM_PORT_FRM_ERR_EXTRACTION		| \
14818a6c85fSIgal Liberman 	FM_PORT_FRM_ERR_NO_SCHEME		| \
14918a6c85fSIgal Liberman 	FM_PORT_FRM_ERR_PRS_TIMEOUT		| \
15018a6c85fSIgal Liberman 	FM_PORT_FRM_ERR_PRS_ILL_INSTRUCT	| \
15118a6c85fSIgal Liberman 	FM_PORT_FRM_ERR_BLOCK_LIMIT_EXCEEDED	| \
15218a6c85fSIgal Liberman 	FM_PORT_FRM_ERR_PRS_HDR_ERR		| \
15318a6c85fSIgal Liberman 	FM_PORT_FRM_ERR_KEYSIZE_OVERFLOW	| \
15418a6c85fSIgal Liberman 	FM_PORT_FRM_ERR_IPRE)
15518a6c85fSIgal Liberman 
15618a6c85fSIgal Liberman /* NIA defines */
15718a6c85fSIgal Liberman #define NIA_ORDER_RESTOR				0x00800000
15818a6c85fSIgal Liberman #define NIA_ENG_BMI					0x00500000
15918a6c85fSIgal Liberman #define NIA_ENG_QMI_ENQ					0x00540000
16018a6c85fSIgal Liberman #define NIA_ENG_QMI_DEQ					0x00580000
1611df653cfSMadalin Bucur #define NIA_ENG_HWP					0x00440000
1627472f4f2SIordache Florinel-R70177 #define NIA_ENG_HWK					0x00480000
16318a6c85fSIgal Liberman #define NIA_BMI_AC_ENQ_FRAME				0x00000002
16418a6c85fSIgal Liberman #define NIA_BMI_AC_TX_RELEASE				0x000002C0
16518a6c85fSIgal Liberman #define NIA_BMI_AC_RELEASE				0x000000C0
16618a6c85fSIgal Liberman #define NIA_BMI_AC_TX					0x00000274
16718a6c85fSIgal Liberman #define NIA_BMI_AC_FETCH_ALL_FRAME			0x0000020c
16818a6c85fSIgal Liberman 
16918a6c85fSIgal Liberman /* Port IDs */
17018a6c85fSIgal Liberman #define TX_10G_PORT_BASE		0x30
17118a6c85fSIgal Liberman #define RX_10G_PORT_BASE		0x10
17218a6c85fSIgal Liberman 
17318a6c85fSIgal Liberman /* BMI Rx port register map */
17418a6c85fSIgal Liberman struct fman_port_rx_bmi_regs {
17518a6c85fSIgal Liberman 	u32 fmbm_rcfg;		/* Rx Configuration */
17618a6c85fSIgal Liberman 	u32 fmbm_rst;		/* Rx Status */
17718a6c85fSIgal Liberman 	u32 fmbm_rda;		/* Rx DMA attributes */
17818a6c85fSIgal Liberman 	u32 fmbm_rfp;		/* Rx FIFO Parameters */
17918a6c85fSIgal Liberman 	u32 fmbm_rfed;		/* Rx Frame End Data */
18018a6c85fSIgal Liberman 	u32 fmbm_ricp;		/* Rx Internal Context Parameters */
18118a6c85fSIgal Liberman 	u32 fmbm_rim;		/* Rx Internal Buffer Margins */
18218a6c85fSIgal Liberman 	u32 fmbm_rebm;		/* Rx External Buffer Margins */
18318a6c85fSIgal Liberman 	u32 fmbm_rfne;		/* Rx Frame Next Engine */
18418a6c85fSIgal Liberman 	u32 fmbm_rfca;		/* Rx Frame Command Attributes. */
18518a6c85fSIgal Liberman 	u32 fmbm_rfpne;		/* Rx Frame Parser Next Engine */
18618a6c85fSIgal Liberman 	u32 fmbm_rpso;		/* Rx Parse Start Offset */
18718a6c85fSIgal Liberman 	u32 fmbm_rpp;		/* Rx Policer Profile  */
18818a6c85fSIgal Liberman 	u32 fmbm_rccb;		/* Rx Coarse Classification Base */
18918a6c85fSIgal Liberman 	u32 fmbm_reth;		/* Rx Excessive Threshold */
19018a6c85fSIgal Liberman 	u32 reserved003c[1];	/* (0x03C 0x03F) */
19118a6c85fSIgal Liberman 	u32 fmbm_rprai[PORT_PRS_RESULT_WORDS_NUM];
19218a6c85fSIgal Liberman 	/* Rx Parse Results Array Init */
19318a6c85fSIgal Liberman 	u32 fmbm_rfqid;		/* Rx Frame Queue ID */
19418a6c85fSIgal Liberman 	u32 fmbm_refqid;	/* Rx Error Frame Queue ID */
19518a6c85fSIgal Liberman 	u32 fmbm_rfsdm;		/* Rx Frame Status Discard Mask */
19618a6c85fSIgal Liberman 	u32 fmbm_rfsem;		/* Rx Frame Status Error Mask */
19718a6c85fSIgal Liberman 	u32 fmbm_rfene;		/* Rx Frame Enqueue Next Engine */
19818a6c85fSIgal Liberman 	u32 reserved0074[0x2];	/* (0x074-0x07C)  */
19918a6c85fSIgal Liberman 	u32 fmbm_rcmne;		/* Rx Frame Continuous Mode Next Engine */
20018a6c85fSIgal Liberman 	u32 reserved0080[0x20];	/* (0x080 0x0FF)  */
20118a6c85fSIgal Liberman 	u32 fmbm_ebmpi[FMAN_PORT_MAX_EXT_POOLS_NUM];
20218a6c85fSIgal Liberman 	/* Buffer Manager pool Information- */
20318a6c85fSIgal Liberman 	u32 fmbm_acnt[FMAN_PORT_MAX_EXT_POOLS_NUM];	/* Allocate Counter- */
20418a6c85fSIgal Liberman 	u32 reserved0130[8];	/* 0x130/0x140 - 0x15F reserved - */
20518a6c85fSIgal Liberman 	u32 fmbm_rcgm[PORT_CG_MAP_NUM];	/* Congestion Group Map */
20618a6c85fSIgal Liberman 	u32 fmbm_mpd;		/* BM Pool Depletion  */
20718a6c85fSIgal Liberman 	u32 reserved0184[0x1F];	/* (0x184 0x1FF) */
20818a6c85fSIgal Liberman 	u32 fmbm_rstc;		/* Rx Statistics Counters */
20918a6c85fSIgal Liberman 	u32 fmbm_rfrc;		/* Rx Frame Counter */
21018a6c85fSIgal Liberman 	u32 fmbm_rfbc;		/* Rx Bad Frames Counter */
21118a6c85fSIgal Liberman 	u32 fmbm_rlfc;		/* Rx Large Frames Counter */
21218a6c85fSIgal Liberman 	u32 fmbm_rffc;		/* Rx Filter Frames Counter */
21318a6c85fSIgal Liberman 	u32 fmbm_rfdc;		/* Rx Frame Discard Counter */
21418a6c85fSIgal Liberman 	u32 fmbm_rfldec;		/* Rx Frames List DMA Error Counter */
21518a6c85fSIgal Liberman 	u32 fmbm_rodc;		/* Rx Out of Buffers Discard nntr */
21618a6c85fSIgal Liberman 	u32 fmbm_rbdc;		/* Rx Buffers Deallocate Counter */
21718a6c85fSIgal Liberman 	u32 fmbm_rpec;		/* RX Prepare to enqueue Counte */
21818a6c85fSIgal Liberman 	u32 reserved0224[0x16];	/* (0x224 0x27F) */
21918a6c85fSIgal Liberman 	u32 fmbm_rpc;		/* Rx Performance Counters */
22018a6c85fSIgal Liberman 	u32 fmbm_rpcp;		/* Rx Performance Count Parameters */
22118a6c85fSIgal Liberman 	u32 fmbm_rccn;		/* Rx Cycle Counter */
22218a6c85fSIgal Liberman 	u32 fmbm_rtuc;		/* Rx Tasks Utilization Counter */
22318a6c85fSIgal Liberman 	u32 fmbm_rrquc;		/* Rx Receive Queue Utilization cntr */
22418a6c85fSIgal Liberman 	u32 fmbm_rduc;		/* Rx DMA Utilization Counter */
22518a6c85fSIgal Liberman 	u32 fmbm_rfuc;		/* Rx FIFO Utilization Counter */
22618a6c85fSIgal Liberman 	u32 fmbm_rpac;		/* Rx Pause Activation Counter */
22718a6c85fSIgal Liberman 	u32 reserved02a0[0x18];	/* (0x2A0 0x2FF) */
22818a6c85fSIgal Liberman 	u32 fmbm_rdcfg[0x3];	/* Rx Debug Configuration */
22918a6c85fSIgal Liberman 	u32 fmbm_rgpr;		/* Rx General Purpose Register */
23018a6c85fSIgal Liberman 	u32 reserved0310[0x3a];
23118a6c85fSIgal Liberman };
23218a6c85fSIgal Liberman 
23318a6c85fSIgal Liberman /* BMI Tx port register map */
23418a6c85fSIgal Liberman struct fman_port_tx_bmi_regs {
23518a6c85fSIgal Liberman 	u32 fmbm_tcfg;		/* Tx Configuration */
23618a6c85fSIgal Liberman 	u32 fmbm_tst;		/* Tx Status */
23718a6c85fSIgal Liberman 	u32 fmbm_tda;		/* Tx DMA attributes */
23818a6c85fSIgal Liberman 	u32 fmbm_tfp;		/* Tx FIFO Parameters */
23918a6c85fSIgal Liberman 	u32 fmbm_tfed;		/* Tx Frame End Data */
24018a6c85fSIgal Liberman 	u32 fmbm_ticp;		/* Tx Internal Context Parameters */
24118a6c85fSIgal Liberman 	u32 fmbm_tfdne;		/* Tx Frame Dequeue Next Engine. */
24218a6c85fSIgal Liberman 	u32 fmbm_tfca;		/* Tx Frame Command attribute. */
24318a6c85fSIgal Liberman 	u32 fmbm_tcfqid;	/* Tx Confirmation Frame Queue ID. */
24418a6c85fSIgal Liberman 	u32 fmbm_tefqid;	/* Tx Frame Error Queue ID */
24518a6c85fSIgal Liberman 	u32 fmbm_tfene;		/* Tx Frame Enqueue Next Engine */
24618a6c85fSIgal Liberman 	u32 fmbm_trlmts;	/* Tx Rate Limiter Scale */
24718a6c85fSIgal Liberman 	u32 fmbm_trlmt;		/* Tx Rate Limiter */
24818a6c85fSIgal Liberman 	u32 reserved0034[0x0e];	/* (0x034-0x6c) */
24918a6c85fSIgal Liberman 	u32 fmbm_tccb;		/* Tx Coarse Classification base */
25018a6c85fSIgal Liberman 	u32 fmbm_tfne;		/* Tx Frame Next Engine */
25118a6c85fSIgal Liberman 	u32 fmbm_tpfcm[0x02];
25218a6c85fSIgal Liberman 	/* Tx Priority based Flow Control (PFC) Mapping */
25318a6c85fSIgal Liberman 	u32 fmbm_tcmne;		/* Tx Frame Continuous Mode Next Engine */
25418a6c85fSIgal Liberman 	u32 reserved0080[0x60];	/* (0x080-0x200) */
25518a6c85fSIgal Liberman 	u32 fmbm_tstc;		/* Tx Statistics Counters */
25618a6c85fSIgal Liberman 	u32 fmbm_tfrc;		/* Tx Frame Counter */
25718a6c85fSIgal Liberman 	u32 fmbm_tfdc;		/* Tx Frames Discard Counter */
25818a6c85fSIgal Liberman 	u32 fmbm_tfledc;	/* Tx Frame len error discard cntr */
25918a6c85fSIgal Liberman 	u32 fmbm_tfufdc;	/* Tx Frame unsprt frmt discard cntr */
26018a6c85fSIgal Liberman 	u32 fmbm_tbdc;		/* Tx Buffers Deallocate Counter */
26118a6c85fSIgal Liberman 	u32 reserved0218[0x1A];	/* (0x218-0x280) */
26218a6c85fSIgal Liberman 	u32 fmbm_tpc;		/* Tx Performance Counters */
26318a6c85fSIgal Liberman 	u32 fmbm_tpcp;		/* Tx Performance Count Parameters */
26418a6c85fSIgal Liberman 	u32 fmbm_tccn;		/* Tx Cycle Counter */
26518a6c85fSIgal Liberman 	u32 fmbm_ttuc;		/* Tx Tasks Utilization Counter */
26618a6c85fSIgal Liberman 	u32 fmbm_ttcquc;	/* Tx Transmit conf Q util Counter */
26718a6c85fSIgal Liberman 	u32 fmbm_tduc;		/* Tx DMA Utilization Counter */
26818a6c85fSIgal Liberman 	u32 fmbm_tfuc;		/* Tx FIFO Utilization Counter */
26918a6c85fSIgal Liberman 	u32 reserved029c[16];	/* (0x29C-0x2FF) */
27018a6c85fSIgal Liberman 	u32 fmbm_tdcfg[0x3];	/* Tx Debug Configuration */
27118a6c85fSIgal Liberman 	u32 fmbm_tgpr;		/* Tx General Purpose Register */
27218a6c85fSIgal Liberman 	u32 reserved0310[0x3a]; /* (0x310-0x3FF) */
27318a6c85fSIgal Liberman };
27418a6c85fSIgal Liberman 
27518a6c85fSIgal Liberman /* BMI port register map */
27618a6c85fSIgal Liberman union fman_port_bmi_regs {
27718a6c85fSIgal Liberman 	struct fman_port_rx_bmi_regs rx;
27818a6c85fSIgal Liberman 	struct fman_port_tx_bmi_regs tx;
27918a6c85fSIgal Liberman };
28018a6c85fSIgal Liberman 
28118a6c85fSIgal Liberman /* QMI port register map */
28218a6c85fSIgal Liberman struct fman_port_qmi_regs {
28318a6c85fSIgal Liberman 	u32 fmqm_pnc;		/* PortID n Configuration Register */
28418a6c85fSIgal Liberman 	u32 fmqm_pns;		/* PortID n Status Register */
28518a6c85fSIgal Liberman 	u32 fmqm_pnts;		/* PortID n Task Status Register */
28618a6c85fSIgal Liberman 	u32 reserved00c[4];	/* 0xn00C - 0xn01B */
28718a6c85fSIgal Liberman 	u32 fmqm_pnen;		/* PortID n Enqueue NIA Register */
28818a6c85fSIgal Liberman 	u32 fmqm_pnetfc;		/* PortID n Enq Total Frame Counter */
28918a6c85fSIgal Liberman 	u32 reserved024[2];	/* 0xn024 - 0x02B */
29018a6c85fSIgal Liberman 	u32 fmqm_pndn;		/* PortID n Dequeue NIA Register */
29118a6c85fSIgal Liberman 	u32 fmqm_pndc;		/* PortID n Dequeue Config Register */
29218a6c85fSIgal Liberman 	u32 fmqm_pndtfc;		/* PortID n Dequeue tot Frame cntr */
29318a6c85fSIgal Liberman 	u32 fmqm_pndfdc;		/* PortID n Dequeue FQID Dflt Cntr */
29418a6c85fSIgal Liberman 	u32 fmqm_pndcc;		/* PortID n Dequeue Confirm Counter */
29518a6c85fSIgal Liberman };
29618a6c85fSIgal Liberman 
2971df653cfSMadalin Bucur #define HWP_HXS_COUNT 16
2981df653cfSMadalin Bucur #define HWP_HXS_PHE_REPORT 0x00000800
2991df653cfSMadalin Bucur #define HWP_HXS_PCAC_PSTAT 0x00000100
3001df653cfSMadalin Bucur #define HWP_HXS_PCAC_PSTOP 0x00000001
301b95f6fbcSMadalin Bucur #define HWP_HXS_TCP_OFFSET 0xA
302b95f6fbcSMadalin Bucur #define HWP_HXS_UDP_OFFSET 0xB
303b95f6fbcSMadalin Bucur #define HWP_HXS_SH_PAD_REM 0x80000000
304b95f6fbcSMadalin Bucur 
3051df653cfSMadalin Bucur struct fman_port_hwp_regs {
3061df653cfSMadalin Bucur 	struct {
3071df653cfSMadalin Bucur 		u32 ssa; /* Soft Sequence Attachment */
3081df653cfSMadalin Bucur 		u32 lcv; /* Line-up Enable Confirmation Mask */
3091df653cfSMadalin Bucur 	} pmda[HWP_HXS_COUNT]; /* Parse Memory Direct Access Registers */
3101df653cfSMadalin Bucur 	u32 reserved080[(0x3f8 - 0x080) / 4]; /* (0x080-0x3f7) */
3111df653cfSMadalin Bucur 	u32 fmpr_pcac; /* Configuration Access Control */
3121df653cfSMadalin Bucur };
3131df653cfSMadalin Bucur 
31418a6c85fSIgal Liberman /* QMI dequeue prefetch modes */
31518a6c85fSIgal Liberman enum fman_port_deq_prefetch {
31618a6c85fSIgal Liberman 	FMAN_PORT_DEQ_NO_PREFETCH, /* No prefetch mode */
31718a6c85fSIgal Liberman 	FMAN_PORT_DEQ_PART_PREFETCH, /* Partial prefetch mode */
31818a6c85fSIgal Liberman 	FMAN_PORT_DEQ_FULL_PREFETCH /* Full prefetch mode */
31918a6c85fSIgal Liberman };
32018a6c85fSIgal Liberman 
32118a6c85fSIgal Liberman /* A structure for defining FM port resources */
32218a6c85fSIgal Liberman struct fman_port_rsrc {
32318a6c85fSIgal Liberman 	u32 num; /* Committed required resource */
32418a6c85fSIgal Liberman 	u32 extra; /* Extra (not committed) required resource */
32518a6c85fSIgal Liberman };
32618a6c85fSIgal Liberman 
32718a6c85fSIgal Liberman enum fman_port_dma_swap {
32818a6c85fSIgal Liberman 	FMAN_PORT_DMA_NO_SWAP,	/* No swap, transfer data as is */
32918a6c85fSIgal Liberman 	FMAN_PORT_DMA_SWAP_LE,
33018a6c85fSIgal Liberman 	/* The transferred data should be swapped in PPC Little Endian mode */
33118a6c85fSIgal Liberman 	FMAN_PORT_DMA_SWAP_BE
33218a6c85fSIgal Liberman 	/* The transferred data should be swapped in Big Endian mode */
33318a6c85fSIgal Liberman };
33418a6c85fSIgal Liberman 
33518a6c85fSIgal Liberman /* Default port color */
33618a6c85fSIgal Liberman enum fman_port_color {
33718a6c85fSIgal Liberman 	FMAN_PORT_COLOR_GREEN,	/* Default port color is green */
33818a6c85fSIgal Liberman 	FMAN_PORT_COLOR_YELLOW,	/* Default port color is yellow */
33918a6c85fSIgal Liberman 	FMAN_PORT_COLOR_RED,		/* Default port color is red */
34018a6c85fSIgal Liberman 	FMAN_PORT_COLOR_OVERRIDE	/* Ignore color */
34118a6c85fSIgal Liberman };
34218a6c85fSIgal Liberman 
34318a6c85fSIgal Liberman /* QMI dequeue from the SP channel - types */
34418a6c85fSIgal Liberman enum fman_port_deq_type {
34518a6c85fSIgal Liberman 	FMAN_PORT_DEQ_BY_PRI,
34618a6c85fSIgal Liberman 	/* Priority precedence and Intra-Class scheduling */
34718a6c85fSIgal Liberman 	FMAN_PORT_DEQ_ACTIVE_FQ,
34818a6c85fSIgal Liberman 	/* Active FQ precedence and Intra-Class scheduling */
34918a6c85fSIgal Liberman 	FMAN_PORT_DEQ_ACTIVE_FQ_NO_ICS
35018a6c85fSIgal Liberman 	/* Active FQ precedence and override Intra-Class scheduling */
35118a6c85fSIgal Liberman };
35218a6c85fSIgal Liberman 
35318a6c85fSIgal Liberman /* External buffer pools configuration */
35418a6c85fSIgal Liberman struct fman_port_bpools {
35518a6c85fSIgal Liberman 	u8 count;			/* Num of pools to set up */
35618a6c85fSIgal Liberman 	bool counters_enable;		/* Enable allocate counters */
35718a6c85fSIgal Liberman 	u8 grp_bp_depleted_num;
35818a6c85fSIgal Liberman 	/* Number of depleted pools - if reached the BMI indicates
35918a6c85fSIgal Liberman 	 * the MAC to send a pause frame
36018a6c85fSIgal Liberman 	 */
36118a6c85fSIgal Liberman 	struct {
36218a6c85fSIgal Liberman 		u8 bpid;		/* BM pool ID */
36318a6c85fSIgal Liberman 		u16 size;
36418a6c85fSIgal Liberman 		/* Pool's size - must be in ascending order */
36518a6c85fSIgal Liberman 		bool is_backup;
36618a6c85fSIgal Liberman 		/* If this is a backup pool */
36718a6c85fSIgal Liberman 		bool grp_bp_depleted;
36818a6c85fSIgal Liberman 		/* Consider this buffer in multiple pools depletion criteria */
36918a6c85fSIgal Liberman 		bool single_bp_depleted;
37018a6c85fSIgal Liberman 		/* Consider this buffer in single pool depletion criteria */
37118a6c85fSIgal Liberman 	} bpool[FMAN_PORT_MAX_EXT_POOLS_NUM];
37218a6c85fSIgal Liberman };
37318a6c85fSIgal Liberman 
37418a6c85fSIgal Liberman struct fman_port_cfg {
37518a6c85fSIgal Liberman 	u32 dflt_fqid;
37618a6c85fSIgal Liberman 	u32 err_fqid;
3777472f4f2SIordache Florinel-R70177 	u32 pcd_base_fqid;
3787472f4f2SIordache Florinel-R70177 	u32 pcd_fqs_count;
37918a6c85fSIgal Liberman 	u8 deq_sp;
38018a6c85fSIgal Liberman 	bool deq_high_priority;
38118a6c85fSIgal Liberman 	enum fman_port_deq_type deq_type;
38218a6c85fSIgal Liberman 	enum fman_port_deq_prefetch deq_prefetch_option;
38318a6c85fSIgal Liberman 	u16 deq_byte_cnt;
38418a6c85fSIgal Liberman 	u8 cheksum_last_bytes_ignore;
38518a6c85fSIgal Liberman 	u8 rx_cut_end_bytes;
38618a6c85fSIgal Liberman 	struct fman_buf_pool_depletion buf_pool_depletion;
38718a6c85fSIgal Liberman 	struct fman_ext_pools ext_buf_pools;
38818a6c85fSIgal Liberman 	u32 tx_fifo_min_level;
38918a6c85fSIgal Liberman 	u32 tx_fifo_low_comf_level;
39018a6c85fSIgal Liberman 	u32 rx_pri_elevation;
39118a6c85fSIgal Liberman 	u32 rx_fifo_thr;
39218a6c85fSIgal Liberman 	struct fman_sp_buf_margins buf_margins;
39318a6c85fSIgal Liberman 	u32 int_buf_start_margin;
39418a6c85fSIgal Liberman 	struct fman_sp_int_context_data_copy int_context;
39518a6c85fSIgal Liberman 	u32 discard_mask;
39618a6c85fSIgal Liberman 	u32 err_mask;
39718a6c85fSIgal Liberman 	struct fman_buffer_prefix_content buffer_prefix_content;
39818a6c85fSIgal Liberman 	bool dont_release_buf;
39918a6c85fSIgal Liberman 
40018a6c85fSIgal Liberman 	u8 rx_fd_bits;
40118a6c85fSIgal Liberman 	u32 tx_fifo_deq_pipeline_depth;
40218a6c85fSIgal Liberman 	bool errata_A006320;
40318a6c85fSIgal Liberman 	bool excessive_threshold_register;
40418a6c85fSIgal Liberman 	bool fmbm_tfne_has_features;
40518a6c85fSIgal Liberman 
40618a6c85fSIgal Liberman 	enum fman_port_dma_swap dma_swap_data;
40718a6c85fSIgal Liberman 	enum fman_port_color color;
40818a6c85fSIgal Liberman };
40918a6c85fSIgal Liberman 
41018a6c85fSIgal Liberman struct fman_port_rx_pools_params {
41118a6c85fSIgal Liberman 	u8 num_of_pools;
41218a6c85fSIgal Liberman 	u16 largest_buf_size;
41318a6c85fSIgal Liberman };
41418a6c85fSIgal Liberman 
41518a6c85fSIgal Liberman struct fman_port_dts_params {
41618a6c85fSIgal Liberman 	void __iomem *base_addr;	/* FMan port virtual memory */
41718a6c85fSIgal Liberman 	enum fman_port_type type;	/* Port type */
41818a6c85fSIgal Liberman 	u16 speed;			/* Port speed */
41918a6c85fSIgal Liberman 	u8 id;				/* HW Port Id */
42018a6c85fSIgal Liberman 	u32 qman_channel_id;		/* QMan channel id (non RX only) */
42118a6c85fSIgal Liberman 	struct fman *fman;		/* FMan Handle */
42218a6c85fSIgal Liberman };
42318a6c85fSIgal Liberman 
42418a6c85fSIgal Liberman struct fman_port {
42518a6c85fSIgal Liberman 	void *fm;
42618a6c85fSIgal Liberman 	struct device *dev;
42718a6c85fSIgal Liberman 	struct fman_rev_info rev_info;
42818a6c85fSIgal Liberman 	u8 port_id;
42918a6c85fSIgal Liberman 	enum fman_port_type port_type;
43018a6c85fSIgal Liberman 	u16 port_speed;
43118a6c85fSIgal Liberman 
43218a6c85fSIgal Liberman 	union fman_port_bmi_regs __iomem *bmi_regs;
43318a6c85fSIgal Liberman 	struct fman_port_qmi_regs __iomem *qmi_regs;
4341df653cfSMadalin Bucur 	struct fman_port_hwp_regs __iomem *hwp_regs;
43518a6c85fSIgal Liberman 
43618a6c85fSIgal Liberman 	struct fman_sp_buffer_offsets buffer_offsets;
43718a6c85fSIgal Liberman 
43818a6c85fSIgal Liberman 	u8 internal_buf_offset;
43918a6c85fSIgal Liberman 	struct fman_ext_pools ext_buf_pools;
44018a6c85fSIgal Liberman 
44118a6c85fSIgal Liberman 	u16 max_frame_length;
44218a6c85fSIgal Liberman 	struct fman_port_rsrc open_dmas;
44318a6c85fSIgal Liberman 	struct fman_port_rsrc tasks;
44418a6c85fSIgal Liberman 	struct fman_port_rsrc fifo_bufs;
44518a6c85fSIgal Liberman 	struct fman_port_rx_pools_params rx_pools_params;
44618a6c85fSIgal Liberman 
44718a6c85fSIgal Liberman 	struct fman_port_cfg *cfg;
44818a6c85fSIgal Liberman 	struct fman_port_dts_params dts_params;
44918a6c85fSIgal Liberman 
45018a6c85fSIgal Liberman 	u8 ext_pools_num;
45118a6c85fSIgal Liberman 	u32 max_port_fifo_size;
45218a6c85fSIgal Liberman 	u32 max_num_of_ext_pools;
45318a6c85fSIgal Liberman 	u32 max_num_of_sub_portals;
45418a6c85fSIgal Liberman 	u32 bm_max_num_of_pools;
45518a6c85fSIgal Liberman };
45618a6c85fSIgal Liberman 
init_bmi_rx(struct fman_port * port)45718a6c85fSIgal Liberman static int init_bmi_rx(struct fman_port *port)
45818a6c85fSIgal Liberman {
45918a6c85fSIgal Liberman 	struct fman_port_rx_bmi_regs __iomem *regs = &port->bmi_regs->rx;
46018a6c85fSIgal Liberman 	struct fman_port_cfg *cfg = port->cfg;
46118a6c85fSIgal Liberman 	u32 tmp;
46218a6c85fSIgal Liberman 
46318a6c85fSIgal Liberman 	/* DMA attributes */
46418a6c85fSIgal Liberman 	tmp = (u32)cfg->dma_swap_data << BMI_DMA_ATTR_SWP_SHIFT;
46518a6c85fSIgal Liberman 	/* Enable write optimization */
46618a6c85fSIgal Liberman 	tmp |= BMI_DMA_ATTR_WRITE_OPTIMIZE;
46718a6c85fSIgal Liberman 	iowrite32be(tmp, &regs->fmbm_rda);
46818a6c85fSIgal Liberman 
46918a6c85fSIgal Liberman 	/* Rx FIFO parameters */
47018a6c85fSIgal Liberman 	tmp = (cfg->rx_pri_elevation / PORT_BMI_FIFO_UNITS - 1) <<
47118a6c85fSIgal Liberman 		BMI_RX_FIFO_PRI_ELEVATION_SHIFT;
47218a6c85fSIgal Liberman 	tmp |= cfg->rx_fifo_thr / PORT_BMI_FIFO_UNITS - 1;
47318a6c85fSIgal Liberman 	iowrite32be(tmp, &regs->fmbm_rfp);
47418a6c85fSIgal Liberman 
47518a6c85fSIgal Liberman 	if (cfg->excessive_threshold_register)
47618a6c85fSIgal Liberman 		/* always allow access to the extra resources */
47718a6c85fSIgal Liberman 		iowrite32be(BMI_RX_FIFO_THRESHOLD_ETHE, &regs->fmbm_reth);
47818a6c85fSIgal Liberman 
47918a6c85fSIgal Liberman 	/* Frame end data */
48018a6c85fSIgal Liberman 	tmp = (cfg->cheksum_last_bytes_ignore & BMI_FRAME_END_CS_IGNORE_MASK) <<
48118a6c85fSIgal Liberman 		BMI_FRAME_END_CS_IGNORE_SHIFT;
48218a6c85fSIgal Liberman 	tmp |= (cfg->rx_cut_end_bytes & BMI_RX_FRAME_END_CUT_MASK) <<
48318a6c85fSIgal Liberman 		BMI_RX_FRAME_END_CUT_SHIFT;
48418a6c85fSIgal Liberman 	if (cfg->errata_A006320)
48518a6c85fSIgal Liberman 		tmp &= 0xffe0ffff;
48618a6c85fSIgal Liberman 	iowrite32be(tmp, &regs->fmbm_rfed);
48718a6c85fSIgal Liberman 
48818a6c85fSIgal Liberman 	/* Internal context parameters */
48918a6c85fSIgal Liberman 	tmp = ((cfg->int_context.ext_buf_offset / PORT_IC_OFFSET_UNITS) &
49018a6c85fSIgal Liberman 		BMI_IC_TO_EXT_MASK) << BMI_IC_TO_EXT_SHIFT;
49118a6c85fSIgal Liberman 	tmp |= ((cfg->int_context.int_context_offset / PORT_IC_OFFSET_UNITS) &
49218a6c85fSIgal Liberman 		BMI_IC_FROM_INT_MASK) << BMI_IC_FROM_INT_SHIFT;
49318a6c85fSIgal Liberman 	tmp |= (cfg->int_context.size / PORT_IC_OFFSET_UNITS) &
49418a6c85fSIgal Liberman 		BMI_IC_SIZE_MASK;
49518a6c85fSIgal Liberman 	iowrite32be(tmp, &regs->fmbm_ricp);
49618a6c85fSIgal Liberman 
49718a6c85fSIgal Liberman 	/* Internal buffer offset */
49818a6c85fSIgal Liberman 	tmp = ((cfg->int_buf_start_margin / PORT_IC_OFFSET_UNITS) &
49918a6c85fSIgal Liberman 		BMI_INT_BUF_MARG_MASK) << BMI_INT_BUF_MARG_SHIFT;
50018a6c85fSIgal Liberman 	iowrite32be(tmp, &regs->fmbm_rim);
50118a6c85fSIgal Liberman 
50218a6c85fSIgal Liberman 	/* External buffer margins */
50318a6c85fSIgal Liberman 	tmp = (cfg->buf_margins.start_margins & BMI_EXT_BUF_MARG_START_MASK) <<
50418a6c85fSIgal Liberman 		BMI_EXT_BUF_MARG_START_SHIFT;
50518a6c85fSIgal Liberman 	tmp |= cfg->buf_margins.end_margins & BMI_EXT_BUF_MARG_END_MASK;
50618a6c85fSIgal Liberman 	iowrite32be(tmp, &regs->fmbm_rebm);
50718a6c85fSIgal Liberman 
50818a6c85fSIgal Liberman 	/* Frame attributes */
50918a6c85fSIgal Liberman 	tmp = BMI_CMD_RX_MR_DEF;
51018a6c85fSIgal Liberman 	tmp |= BMI_CMD_ATTR_ORDER;
51118a6c85fSIgal Liberman 	tmp |= (u32)cfg->color << BMI_CMD_ATTR_COLOR_SHIFT;
51218a6c85fSIgal Liberman 	/* Synchronization request */
51318a6c85fSIgal Liberman 	tmp |= BMI_CMD_ATTR_SYNC;
51418a6c85fSIgal Liberman 
51518a6c85fSIgal Liberman 	iowrite32be(tmp, &regs->fmbm_rfca);
51618a6c85fSIgal Liberman 
51718a6c85fSIgal Liberman 	/* NIA */
51818a6c85fSIgal Liberman 	tmp = (u32)cfg->rx_fd_bits << BMI_NEXT_ENG_FD_BITS_SHIFT;
51918a6c85fSIgal Liberman 
5201df653cfSMadalin Bucur 	tmp |= NIA_ENG_HWP;
52118a6c85fSIgal Liberman 	iowrite32be(tmp, &regs->fmbm_rfne);
52218a6c85fSIgal Liberman 
5231df653cfSMadalin Bucur 	/* Parser Next Engine NIA */
5241df653cfSMadalin Bucur 	iowrite32be(NIA_ENG_BMI | NIA_BMI_AC_ENQ_FRAME, &regs->fmbm_rfpne);
5251df653cfSMadalin Bucur 
52618a6c85fSIgal Liberman 	/* Enqueue NIA */
52718a6c85fSIgal Liberman 	iowrite32be(NIA_ENG_QMI_ENQ | NIA_ORDER_RESTOR, &regs->fmbm_rfene);
52818a6c85fSIgal Liberman 
52918a6c85fSIgal Liberman 	/* Default/error queues */
53018a6c85fSIgal Liberman 	iowrite32be((cfg->dflt_fqid & DFLT_FQ_ID), &regs->fmbm_rfqid);
53118a6c85fSIgal Liberman 	iowrite32be((cfg->err_fqid & DFLT_FQ_ID), &regs->fmbm_refqid);
53218a6c85fSIgal Liberman 
53318a6c85fSIgal Liberman 	/* Discard/error masks */
53418a6c85fSIgal Liberman 	iowrite32be(cfg->discard_mask, &regs->fmbm_rfsdm);
53518a6c85fSIgal Liberman 	iowrite32be(cfg->err_mask, &regs->fmbm_rfsem);
53618a6c85fSIgal Liberman 
53718a6c85fSIgal Liberman 	return 0;
53818a6c85fSIgal Liberman }
53918a6c85fSIgal Liberman 
init_bmi_tx(struct fman_port * port)54018a6c85fSIgal Liberman static int init_bmi_tx(struct fman_port *port)
54118a6c85fSIgal Liberman {
54218a6c85fSIgal Liberman 	struct fman_port_tx_bmi_regs __iomem *regs = &port->bmi_regs->tx;
54318a6c85fSIgal Liberman 	struct fman_port_cfg *cfg = port->cfg;
54418a6c85fSIgal Liberman 	u32 tmp;
54518a6c85fSIgal Liberman 
54618a6c85fSIgal Liberman 	/* Tx Configuration register */
54718a6c85fSIgal Liberman 	tmp = 0;
54818a6c85fSIgal Liberman 	iowrite32be(tmp, &regs->fmbm_tcfg);
54918a6c85fSIgal Liberman 
55018a6c85fSIgal Liberman 	/* DMA attributes */
55118a6c85fSIgal Liberman 	tmp = (u32)cfg->dma_swap_data << BMI_DMA_ATTR_SWP_SHIFT;
55218a6c85fSIgal Liberman 	iowrite32be(tmp, &regs->fmbm_tda);
55318a6c85fSIgal Liberman 
55418a6c85fSIgal Liberman 	/* Tx FIFO parameters */
55518a6c85fSIgal Liberman 	tmp = (cfg->tx_fifo_min_level / PORT_BMI_FIFO_UNITS) <<
55618a6c85fSIgal Liberman 		BMI_TX_FIFO_MIN_FILL_SHIFT;
55718a6c85fSIgal Liberman 	tmp |= ((cfg->tx_fifo_deq_pipeline_depth - 1) &
55818a6c85fSIgal Liberman 		BMI_FIFO_PIPELINE_DEPTH_MASK) << BMI_FIFO_PIPELINE_DEPTH_SHIFT;
55918a6c85fSIgal Liberman 	tmp |= (cfg->tx_fifo_low_comf_level / PORT_BMI_FIFO_UNITS) - 1;
56018a6c85fSIgal Liberman 	iowrite32be(tmp, &regs->fmbm_tfp);
56118a6c85fSIgal Liberman 
56218a6c85fSIgal Liberman 	/* Frame end data */
56318a6c85fSIgal Liberman 	tmp = (cfg->cheksum_last_bytes_ignore & BMI_FRAME_END_CS_IGNORE_MASK) <<
56418a6c85fSIgal Liberman 		BMI_FRAME_END_CS_IGNORE_SHIFT;
56518a6c85fSIgal Liberman 	iowrite32be(tmp, &regs->fmbm_tfed);
56618a6c85fSIgal Liberman 
56718a6c85fSIgal Liberman 	/* Internal context parameters */
56818a6c85fSIgal Liberman 	tmp = ((cfg->int_context.ext_buf_offset / PORT_IC_OFFSET_UNITS) &
56918a6c85fSIgal Liberman 		BMI_IC_TO_EXT_MASK) << BMI_IC_TO_EXT_SHIFT;
57018a6c85fSIgal Liberman 	tmp |= ((cfg->int_context.int_context_offset / PORT_IC_OFFSET_UNITS) &
57118a6c85fSIgal Liberman 		BMI_IC_FROM_INT_MASK) << BMI_IC_FROM_INT_SHIFT;
57218a6c85fSIgal Liberman 	tmp |= (cfg->int_context.size / PORT_IC_OFFSET_UNITS) &
57318a6c85fSIgal Liberman 		BMI_IC_SIZE_MASK;
57418a6c85fSIgal Liberman 	iowrite32be(tmp, &regs->fmbm_ticp);
57518a6c85fSIgal Liberman 
57618a6c85fSIgal Liberman 	/* Frame attributes */
57718a6c85fSIgal Liberman 	tmp = BMI_CMD_TX_MR_DEF;
57818a6c85fSIgal Liberman 	tmp |= BMI_CMD_ATTR_ORDER;
57918a6c85fSIgal Liberman 	tmp |= (u32)cfg->color << BMI_CMD_ATTR_COLOR_SHIFT;
58018a6c85fSIgal Liberman 	iowrite32be(tmp, &regs->fmbm_tfca);
58118a6c85fSIgal Liberman 
58218a6c85fSIgal Liberman 	/* Dequeue NIA + enqueue NIA */
58318a6c85fSIgal Liberman 	iowrite32be(NIA_ENG_QMI_DEQ, &regs->fmbm_tfdne);
58418a6c85fSIgal Liberman 	iowrite32be(NIA_ENG_QMI_ENQ | NIA_ORDER_RESTOR, &regs->fmbm_tfene);
58518a6c85fSIgal Liberman 	if (cfg->fmbm_tfne_has_features)
58618a6c85fSIgal Liberman 		iowrite32be(!cfg->dflt_fqid ?
58718a6c85fSIgal Liberman 			    BMI_EBD_EN | NIA_BMI_AC_FETCH_ALL_FRAME :
58818a6c85fSIgal Liberman 			    NIA_BMI_AC_FETCH_ALL_FRAME, &regs->fmbm_tfne);
58918a6c85fSIgal Liberman 	if (!cfg->dflt_fqid && cfg->dont_release_buf) {
59018a6c85fSIgal Liberman 		iowrite32be(DFLT_FQ_ID, &regs->fmbm_tcfqid);
59118a6c85fSIgal Liberman 		iowrite32be(NIA_ENG_BMI | NIA_BMI_AC_TX_RELEASE,
59218a6c85fSIgal Liberman 			    &regs->fmbm_tfene);
59318a6c85fSIgal Liberman 		if (cfg->fmbm_tfne_has_features)
59418a6c85fSIgal Liberman 			iowrite32be(ioread32be(&regs->fmbm_tfne) & ~BMI_EBD_EN,
59518a6c85fSIgal Liberman 				    &regs->fmbm_tfne);
59618a6c85fSIgal Liberman 	}
59718a6c85fSIgal Liberman 
59818a6c85fSIgal Liberman 	/* Confirmation/error queues */
59918a6c85fSIgal Liberman 	if (cfg->dflt_fqid || !cfg->dont_release_buf)
60018a6c85fSIgal Liberman 		iowrite32be(cfg->dflt_fqid & DFLT_FQ_ID, &regs->fmbm_tcfqid);
60118a6c85fSIgal Liberman 	iowrite32be((cfg->err_fqid & DFLT_FQ_ID), &regs->fmbm_tefqid);
60218a6c85fSIgal Liberman 
60318a6c85fSIgal Liberman 	return 0;
60418a6c85fSIgal Liberman }
60518a6c85fSIgal Liberman 
init_qmi(struct fman_port * port)60618a6c85fSIgal Liberman static int init_qmi(struct fman_port *port)
60718a6c85fSIgal Liberman {
60818a6c85fSIgal Liberman 	struct fman_port_qmi_regs __iomem *regs = port->qmi_regs;
60918a6c85fSIgal Liberman 	struct fman_port_cfg *cfg = port->cfg;
61018a6c85fSIgal Liberman 	u32 tmp;
61118a6c85fSIgal Liberman 
61218a6c85fSIgal Liberman 	/* Rx port configuration */
61318a6c85fSIgal Liberman 	if (port->port_type == FMAN_PORT_TYPE_RX) {
61418a6c85fSIgal Liberman 		/* Enqueue NIA */
61518a6c85fSIgal Liberman 		iowrite32be(NIA_ENG_BMI | NIA_BMI_AC_RELEASE, &regs->fmqm_pnen);
61618a6c85fSIgal Liberman 		return 0;
61718a6c85fSIgal Liberman 	}
61818a6c85fSIgal Liberman 
61918a6c85fSIgal Liberman 	/* Continue with Tx port configuration */
62018a6c85fSIgal Liberman 	if (port->port_type == FMAN_PORT_TYPE_TX) {
62118a6c85fSIgal Liberman 		/* Enqueue NIA */
62218a6c85fSIgal Liberman 		iowrite32be(NIA_ENG_BMI | NIA_BMI_AC_TX_RELEASE,
62318a6c85fSIgal Liberman 			    &regs->fmqm_pnen);
62418a6c85fSIgal Liberman 		/* Dequeue NIA */
62518a6c85fSIgal Liberman 		iowrite32be(NIA_ENG_BMI | NIA_BMI_AC_TX, &regs->fmqm_pndn);
62618a6c85fSIgal Liberman 	}
62718a6c85fSIgal Liberman 
62818a6c85fSIgal Liberman 	/* Dequeue Configuration register */
62918a6c85fSIgal Liberman 	tmp = 0;
63018a6c85fSIgal Liberman 	if (cfg->deq_high_priority)
63118a6c85fSIgal Liberman 		tmp |= QMI_DEQ_CFG_PRI;
63218a6c85fSIgal Liberman 
63318a6c85fSIgal Liberman 	switch (cfg->deq_type) {
63418a6c85fSIgal Liberman 	case FMAN_PORT_DEQ_BY_PRI:
63518a6c85fSIgal Liberman 		tmp |= QMI_DEQ_CFG_TYPE1;
63618a6c85fSIgal Liberman 		break;
63718a6c85fSIgal Liberman 	case FMAN_PORT_DEQ_ACTIVE_FQ:
63818a6c85fSIgal Liberman 		tmp |= QMI_DEQ_CFG_TYPE2;
63918a6c85fSIgal Liberman 		break;
64018a6c85fSIgal Liberman 	case FMAN_PORT_DEQ_ACTIVE_FQ_NO_ICS:
64118a6c85fSIgal Liberman 		tmp |= QMI_DEQ_CFG_TYPE3;
64218a6c85fSIgal Liberman 		break;
64318a6c85fSIgal Liberman 	default:
64418a6c85fSIgal Liberman 		return -EINVAL;
64518a6c85fSIgal Liberman 	}
64618a6c85fSIgal Liberman 
64718a6c85fSIgal Liberman 	switch (cfg->deq_prefetch_option) {
64818a6c85fSIgal Liberman 	case FMAN_PORT_DEQ_NO_PREFETCH:
64918a6c85fSIgal Liberman 		break;
65018a6c85fSIgal Liberman 	case FMAN_PORT_DEQ_PART_PREFETCH:
65118a6c85fSIgal Liberman 		tmp |= QMI_DEQ_CFG_PREFETCH_PARTIAL;
65218a6c85fSIgal Liberman 		break;
65318a6c85fSIgal Liberman 	case FMAN_PORT_DEQ_FULL_PREFETCH:
65418a6c85fSIgal Liberman 		tmp |= QMI_DEQ_CFG_PREFETCH_FULL;
65518a6c85fSIgal Liberman 		break;
65618a6c85fSIgal Liberman 	default:
65718a6c85fSIgal Liberman 		return -EINVAL;
65818a6c85fSIgal Liberman 	}
65918a6c85fSIgal Liberman 
66018a6c85fSIgal Liberman 	tmp |= (cfg->deq_sp & QMI_DEQ_CFG_SP_MASK) << QMI_DEQ_CFG_SP_SHIFT;
66118a6c85fSIgal Liberman 	tmp |= cfg->deq_byte_cnt;
66218a6c85fSIgal Liberman 	iowrite32be(tmp, &regs->fmqm_pndc);
66318a6c85fSIgal Liberman 
66418a6c85fSIgal Liberman 	return 0;
66518a6c85fSIgal Liberman }
66618a6c85fSIgal Liberman 
stop_port_hwp(struct fman_port * port)6671df653cfSMadalin Bucur static void stop_port_hwp(struct fman_port *port)
6681df653cfSMadalin Bucur {
6691df653cfSMadalin Bucur 	struct fman_port_hwp_regs __iomem *regs = port->hwp_regs;
6701df653cfSMadalin Bucur 	int cnt = 100;
6711df653cfSMadalin Bucur 
6721df653cfSMadalin Bucur 	iowrite32be(HWP_HXS_PCAC_PSTOP, &regs->fmpr_pcac);
6731df653cfSMadalin Bucur 
6741df653cfSMadalin Bucur 	while (cnt-- > 0 &&
6751df653cfSMadalin Bucur 	       (ioread32be(&regs->fmpr_pcac) & HWP_HXS_PCAC_PSTAT))
6761df653cfSMadalin Bucur 		udelay(10);
6771df653cfSMadalin Bucur 	if (!cnt)
6781df653cfSMadalin Bucur 		pr_err("Timeout stopping HW Parser\n");
6791df653cfSMadalin Bucur }
6801df653cfSMadalin Bucur 
start_port_hwp(struct fman_port * port)6811df653cfSMadalin Bucur static void start_port_hwp(struct fman_port *port)
6821df653cfSMadalin Bucur {
6831df653cfSMadalin Bucur 	struct fman_port_hwp_regs __iomem *regs = port->hwp_regs;
6841df653cfSMadalin Bucur 	int cnt = 100;
6851df653cfSMadalin Bucur 
6861df653cfSMadalin Bucur 	iowrite32be(0, &regs->fmpr_pcac);
6871df653cfSMadalin Bucur 
6881df653cfSMadalin Bucur 	while (cnt-- > 0 &&
6891df653cfSMadalin Bucur 	       !(ioread32be(&regs->fmpr_pcac) & HWP_HXS_PCAC_PSTAT))
6901df653cfSMadalin Bucur 		udelay(10);
6911df653cfSMadalin Bucur 	if (!cnt)
6921df653cfSMadalin Bucur 		pr_err("Timeout starting HW Parser\n");
6931df653cfSMadalin Bucur }
6941df653cfSMadalin Bucur 
init_hwp(struct fman_port * port)6951df653cfSMadalin Bucur static void init_hwp(struct fman_port *port)
6961df653cfSMadalin Bucur {
6971df653cfSMadalin Bucur 	struct fman_port_hwp_regs __iomem *regs = port->hwp_regs;
6981df653cfSMadalin Bucur 	int i;
6991df653cfSMadalin Bucur 
7001df653cfSMadalin Bucur 	stop_port_hwp(port);
7011df653cfSMadalin Bucur 
7021df653cfSMadalin Bucur 	for (i = 0; i < HWP_HXS_COUNT; i++) {
7031df653cfSMadalin Bucur 		/* enable HXS error reporting into FD[STATUS] PHE */
7041df653cfSMadalin Bucur 		iowrite32be(0x00000000, &regs->pmda[i].ssa);
7051df653cfSMadalin Bucur 		iowrite32be(0xffffffff, &regs->pmda[i].lcv);
7061df653cfSMadalin Bucur 	}
7071df653cfSMadalin Bucur 
708b95f6fbcSMadalin Bucur 	/* Short packet padding removal from checksum calculation */
709b95f6fbcSMadalin Bucur 	iowrite32be(HWP_HXS_SH_PAD_REM, &regs->pmda[HWP_HXS_TCP_OFFSET].ssa);
710b95f6fbcSMadalin Bucur 	iowrite32be(HWP_HXS_SH_PAD_REM, &regs->pmda[HWP_HXS_UDP_OFFSET].ssa);
711b95f6fbcSMadalin Bucur 
7121df653cfSMadalin Bucur 	start_port_hwp(port);
7131df653cfSMadalin Bucur }
7141df653cfSMadalin Bucur 
init(struct fman_port * port)71518a6c85fSIgal Liberman static int init(struct fman_port *port)
71618a6c85fSIgal Liberman {
71718a6c85fSIgal Liberman 	int err;
71818a6c85fSIgal Liberman 
71918a6c85fSIgal Liberman 	/* Init BMI registers */
72018a6c85fSIgal Liberman 	switch (port->port_type) {
72118a6c85fSIgal Liberman 	case FMAN_PORT_TYPE_RX:
72218a6c85fSIgal Liberman 		err = init_bmi_rx(port);
7231df653cfSMadalin Bucur 		if (!err)
7241df653cfSMadalin Bucur 			init_hwp(port);
72518a6c85fSIgal Liberman 		break;
72618a6c85fSIgal Liberman 	case FMAN_PORT_TYPE_TX:
72718a6c85fSIgal Liberman 		err = init_bmi_tx(port);
72818a6c85fSIgal Liberman 		break;
72918a6c85fSIgal Liberman 	default:
73018a6c85fSIgal Liberman 		return -EINVAL;
73118a6c85fSIgal Liberman 	}
73218a6c85fSIgal Liberman 
73318a6c85fSIgal Liberman 	if (err)
73418a6c85fSIgal Liberman 		return err;
73518a6c85fSIgal Liberman 
73618a6c85fSIgal Liberman 	/* Init QMI registers */
73718a6c85fSIgal Liberman 	err = init_qmi(port);
7381df653cfSMadalin Bucur 	if (err)
73918a6c85fSIgal Liberman 		return err;
74018a6c85fSIgal Liberman 
74118a6c85fSIgal Liberman 	return 0;
74218a6c85fSIgal Liberman }
74318a6c85fSIgal Liberman 
set_bpools(const struct fman_port * port,const struct fman_port_bpools * bp)74418a6c85fSIgal Liberman static int set_bpools(const struct fman_port *port,
74518a6c85fSIgal Liberman 		      const struct fman_port_bpools *bp)
74618a6c85fSIgal Liberman {
74718a6c85fSIgal Liberman 	u32 __iomem *bp_reg, *bp_depl_reg;
74818a6c85fSIgal Liberman 	u32 tmp;
74918a6c85fSIgal Liberman 	u8 i, max_bp_num;
75018a6c85fSIgal Liberman 	bool grp_depl_used = false, rx_port;
75118a6c85fSIgal Liberman 
75218a6c85fSIgal Liberman 	switch (port->port_type) {
75318a6c85fSIgal Liberman 	case FMAN_PORT_TYPE_RX:
75418a6c85fSIgal Liberman 		max_bp_num = port->ext_pools_num;
75518a6c85fSIgal Liberman 		rx_port = true;
75618a6c85fSIgal Liberman 		bp_reg = port->bmi_regs->rx.fmbm_ebmpi;
75718a6c85fSIgal Liberman 		bp_depl_reg = &port->bmi_regs->rx.fmbm_mpd;
75818a6c85fSIgal Liberman 		break;
75918a6c85fSIgal Liberman 	default:
76018a6c85fSIgal Liberman 		return -EINVAL;
76118a6c85fSIgal Liberman 	}
76218a6c85fSIgal Liberman 
76318a6c85fSIgal Liberman 	if (rx_port) {
76418a6c85fSIgal Liberman 		/* Check buffers are provided in ascending order */
76518a6c85fSIgal Liberman 		for (i = 0; (i < (bp->count - 1) &&
76618a6c85fSIgal Liberman 			     (i < FMAN_PORT_MAX_EXT_POOLS_NUM - 1)); i++) {
76718a6c85fSIgal Liberman 			if (bp->bpool[i].size > bp->bpool[i + 1].size)
76818a6c85fSIgal Liberman 				return -EINVAL;
76918a6c85fSIgal Liberman 		}
77018a6c85fSIgal Liberman 	}
77118a6c85fSIgal Liberman 
77218a6c85fSIgal Liberman 	/* Set up external buffers pools */
77318a6c85fSIgal Liberman 	for (i = 0; i < bp->count; i++) {
77418a6c85fSIgal Liberman 		tmp = BMI_EXT_BUF_POOL_VALID;
77518a6c85fSIgal Liberman 		tmp |= ((u32)bp->bpool[i].bpid <<
77618a6c85fSIgal Liberman 			BMI_EXT_BUF_POOL_ID_SHIFT) & BMI_EXT_BUF_POOL_ID_MASK;
77718a6c85fSIgal Liberman 
77818a6c85fSIgal Liberman 		if (rx_port) {
77918a6c85fSIgal Liberman 			if (bp->counters_enable)
78018a6c85fSIgal Liberman 				tmp |= BMI_EXT_BUF_POOL_EN_COUNTER;
78118a6c85fSIgal Liberman 
78218a6c85fSIgal Liberman 			if (bp->bpool[i].is_backup)
78318a6c85fSIgal Liberman 				tmp |= BMI_EXT_BUF_POOL_BACKUP;
78418a6c85fSIgal Liberman 
78518a6c85fSIgal Liberman 			tmp |= (u32)bp->bpool[i].size;
78618a6c85fSIgal Liberman 		}
78718a6c85fSIgal Liberman 
78818a6c85fSIgal Liberman 		iowrite32be(tmp, &bp_reg[i]);
78918a6c85fSIgal Liberman 	}
79018a6c85fSIgal Liberman 
79118a6c85fSIgal Liberman 	/* Clear unused pools */
79218a6c85fSIgal Liberman 	for (i = bp->count; i < max_bp_num; i++)
79318a6c85fSIgal Liberman 		iowrite32be(0, &bp_reg[i]);
79418a6c85fSIgal Liberman 
79518a6c85fSIgal Liberman 	/* Pools depletion */
79618a6c85fSIgal Liberman 	tmp = 0;
79718a6c85fSIgal Liberman 	for (i = 0; i < FMAN_PORT_MAX_EXT_POOLS_NUM; i++) {
79818a6c85fSIgal Liberman 		if (bp->bpool[i].grp_bp_depleted) {
79918a6c85fSIgal Liberman 			grp_depl_used = true;
80018a6c85fSIgal Liberman 			tmp |= 0x80000000 >> i;
80118a6c85fSIgal Liberman 		}
80218a6c85fSIgal Liberman 
80318a6c85fSIgal Liberman 		if (bp->bpool[i].single_bp_depleted)
80418a6c85fSIgal Liberman 			tmp |= 0x80 >> i;
80518a6c85fSIgal Liberman 	}
80618a6c85fSIgal Liberman 
80718a6c85fSIgal Liberman 	if (grp_depl_used)
80818a6c85fSIgal Liberman 		tmp |= ((u32)bp->grp_bp_depleted_num - 1) <<
80918a6c85fSIgal Liberman 		    BMI_POOL_DEP_NUM_OF_POOLS_SHIFT;
81018a6c85fSIgal Liberman 
81118a6c85fSIgal Liberman 	iowrite32be(tmp, bp_depl_reg);
81218a6c85fSIgal Liberman 	return 0;
81318a6c85fSIgal Liberman }
81418a6c85fSIgal Liberman 
is_init_done(struct fman_port_cfg * cfg)81518a6c85fSIgal Liberman static bool is_init_done(struct fman_port_cfg *cfg)
81618a6c85fSIgal Liberman {
81718a6c85fSIgal Liberman 	/* Checks if FMan port driver parameters were initialized */
81818a6c85fSIgal Liberman 	if (!cfg)
81918a6c85fSIgal Liberman 		return true;
82018a6c85fSIgal Liberman 
82118a6c85fSIgal Liberman 	return false;
82218a6c85fSIgal Liberman }
82318a6c85fSIgal Liberman 
verify_size_of_fifo(struct fman_port * port)82418a6c85fSIgal Liberman static int verify_size_of_fifo(struct fman_port *port)
82518a6c85fSIgal Liberman {
82618a6c85fSIgal Liberman 	u32 min_fifo_size_required = 0, opt_fifo_size_for_b2b = 0;
82718a6c85fSIgal Liberman 
82818a6c85fSIgal Liberman 	/* TX Ports */
82918a6c85fSIgal Liberman 	if (port->port_type == FMAN_PORT_TYPE_TX) {
83018a6c85fSIgal Liberman 		min_fifo_size_required = (u32)
83118a6c85fSIgal Liberman 		    (roundup(port->max_frame_length,
83218a6c85fSIgal Liberman 			     FMAN_BMI_FIFO_UNITS) + (3 * FMAN_BMI_FIFO_UNITS));
83318a6c85fSIgal Liberman 
83418a6c85fSIgal Liberman 		min_fifo_size_required +=
83518a6c85fSIgal Liberman 		    port->cfg->tx_fifo_deq_pipeline_depth *
83618a6c85fSIgal Liberman 		    FMAN_BMI_FIFO_UNITS;
83718a6c85fSIgal Liberman 
83818a6c85fSIgal Liberman 		opt_fifo_size_for_b2b = min_fifo_size_required;
83918a6c85fSIgal Liberman 
84018a6c85fSIgal Liberman 		/* Add some margin for back-to-back capability to improve
84118a6c85fSIgal Liberman 		 * performance, allows the hardware to pipeline new frame dma
84218a6c85fSIgal Liberman 		 * while the previous frame not yet transmitted.
84318a6c85fSIgal Liberman 		 */
84418a6c85fSIgal Liberman 		if (port->port_speed == 10000)
84518a6c85fSIgal Liberman 			opt_fifo_size_for_b2b += 3 * FMAN_BMI_FIFO_UNITS;
84618a6c85fSIgal Liberman 		else
84718a6c85fSIgal Liberman 			opt_fifo_size_for_b2b += 2 * FMAN_BMI_FIFO_UNITS;
84818a6c85fSIgal Liberman 	}
84918a6c85fSIgal Liberman 
85018a6c85fSIgal Liberman 	/* RX Ports */
85118a6c85fSIgal Liberman 	else if (port->port_type == FMAN_PORT_TYPE_RX) {
85218a6c85fSIgal Liberman 		if (port->rev_info.major >= 6)
85318a6c85fSIgal Liberman 			min_fifo_size_required = (u32)
85418a6c85fSIgal Liberman 			(roundup(port->max_frame_length,
85518a6c85fSIgal Liberman 				 FMAN_BMI_FIFO_UNITS) +
85618a6c85fSIgal Liberman 				 (5 * FMAN_BMI_FIFO_UNITS));
85718a6c85fSIgal Liberman 			/* 4 according to spec + 1 for FOF>0 */
85818a6c85fSIgal Liberman 		else
85918a6c85fSIgal Liberman 			min_fifo_size_required = (u32)
86018a6c85fSIgal Liberman 			(roundup(min(port->max_frame_length,
86118a6c85fSIgal Liberman 				     port->rx_pools_params.largest_buf_size),
86218a6c85fSIgal Liberman 				     FMAN_BMI_FIFO_UNITS) +
86318a6c85fSIgal Liberman 				     (7 * FMAN_BMI_FIFO_UNITS));
86418a6c85fSIgal Liberman 
86518a6c85fSIgal Liberman 		opt_fifo_size_for_b2b = min_fifo_size_required;
86618a6c85fSIgal Liberman 
86718a6c85fSIgal Liberman 		/* Add some margin for back-to-back capability to improve
86818a6c85fSIgal Liberman 		 * performance,allows the hardware to pipeline new frame dma
86918a6c85fSIgal Liberman 		 * while the previous frame not yet transmitted.
87018a6c85fSIgal Liberman 		 */
87118a6c85fSIgal Liberman 		if (port->port_speed == 10000)
87218a6c85fSIgal Liberman 			opt_fifo_size_for_b2b += 8 * FMAN_BMI_FIFO_UNITS;
87318a6c85fSIgal Liberman 		else
87418a6c85fSIgal Liberman 			opt_fifo_size_for_b2b += 3 * FMAN_BMI_FIFO_UNITS;
87518a6c85fSIgal Liberman 	}
87618a6c85fSIgal Liberman 
87718a6c85fSIgal Liberman 	WARN_ON(min_fifo_size_required <= 0);
87818a6c85fSIgal Liberman 	WARN_ON(opt_fifo_size_for_b2b < min_fifo_size_required);
87918a6c85fSIgal Liberman 
88018a6c85fSIgal Liberman 	/* Verify the size  */
88118a6c85fSIgal Liberman 	if (port->fifo_bufs.num < min_fifo_size_required)
88218a6c85fSIgal Liberman 		dev_dbg(port->dev, "%s: FIFO size should be enlarged to %d bytes\n",
88318a6c85fSIgal Liberman 			__func__, min_fifo_size_required);
88418a6c85fSIgal Liberman 	else if (port->fifo_bufs.num < opt_fifo_size_for_b2b)
88518a6c85fSIgal Liberman 		dev_dbg(port->dev, "%s: For b2b processing,FIFO may be enlarged to %d bytes\n",
88618a6c85fSIgal Liberman 			__func__, opt_fifo_size_for_b2b);
88718a6c85fSIgal Liberman 
88818a6c85fSIgal Liberman 	return 0;
88918a6c85fSIgal Liberman }
89018a6c85fSIgal Liberman 
set_ext_buffer_pools(struct fman_port * port)89118a6c85fSIgal Liberman static int set_ext_buffer_pools(struct fman_port *port)
89218a6c85fSIgal Liberman {
89318a6c85fSIgal Liberman 	struct fman_ext_pools *ext_buf_pools = &port->cfg->ext_buf_pools;
89418a6c85fSIgal Liberman 	struct fman_buf_pool_depletion *buf_pool_depletion =
89518a6c85fSIgal Liberman 	&port->cfg->buf_pool_depletion;
89618a6c85fSIgal Liberman 	u8 ordered_array[FMAN_PORT_MAX_EXT_POOLS_NUM];
89718a6c85fSIgal Liberman 	u16 sizes_array[BM_MAX_NUM_OF_POOLS];
89818a6c85fSIgal Liberman 	int i = 0, j = 0, err;
89918a6c85fSIgal Liberman 	struct fman_port_bpools bpools;
90018a6c85fSIgal Liberman 
90118a6c85fSIgal Liberman 	memset(&ordered_array, 0, sizeof(u8) * FMAN_PORT_MAX_EXT_POOLS_NUM);
90218a6c85fSIgal Liberman 	memset(&sizes_array, 0, sizeof(u16) * BM_MAX_NUM_OF_POOLS);
90318a6c85fSIgal Liberman 	memcpy(&port->ext_buf_pools, ext_buf_pools,
90418a6c85fSIgal Liberman 	       sizeof(struct fman_ext_pools));
90518a6c85fSIgal Liberman 
90618a6c85fSIgal Liberman 	fman_sp_set_buf_pools_in_asc_order_of_buf_sizes(ext_buf_pools,
90718a6c85fSIgal Liberman 							ordered_array,
90818a6c85fSIgal Liberman 							sizes_array);
90918a6c85fSIgal Liberman 
91018a6c85fSIgal Liberman 	memset(&bpools, 0, sizeof(struct fman_port_bpools));
91118a6c85fSIgal Liberman 	bpools.count = ext_buf_pools->num_of_pools_used;
91218a6c85fSIgal Liberman 	bpools.counters_enable = true;
91318a6c85fSIgal Liberman 	for (i = 0; i < ext_buf_pools->num_of_pools_used; i++) {
91418a6c85fSIgal Liberman 		bpools.bpool[i].bpid = ordered_array[i];
91518a6c85fSIgal Liberman 		bpools.bpool[i].size = sizes_array[ordered_array[i]];
91618a6c85fSIgal Liberman 	}
91718a6c85fSIgal Liberman 
91818a6c85fSIgal Liberman 	/* save pools parameters for later use */
91918a6c85fSIgal Liberman 	port->rx_pools_params.num_of_pools = ext_buf_pools->num_of_pools_used;
92018a6c85fSIgal Liberman 	port->rx_pools_params.largest_buf_size =
92118a6c85fSIgal Liberman 	    sizes_array[ordered_array[ext_buf_pools->num_of_pools_used - 1]];
92218a6c85fSIgal Liberman 
92318a6c85fSIgal Liberman 	/* FMBM_RMPD reg. - pool depletion */
92418a6c85fSIgal Liberman 	if (buf_pool_depletion->pools_grp_mode_enable) {
92518a6c85fSIgal Liberman 		bpools.grp_bp_depleted_num = buf_pool_depletion->num_of_pools;
92618a6c85fSIgal Liberman 		for (i = 0; i < port->bm_max_num_of_pools; i++) {
92718a6c85fSIgal Liberman 			if (buf_pool_depletion->pools_to_consider[i]) {
92818a6c85fSIgal Liberman 				for (j = 0; j < ext_buf_pools->
92918a6c85fSIgal Liberman 				     num_of_pools_used; j++) {
93018a6c85fSIgal Liberman 					if (i == ordered_array[j]) {
93118a6c85fSIgal Liberman 						bpools.bpool[j].
93218a6c85fSIgal Liberman 						    grp_bp_depleted = true;
93318a6c85fSIgal Liberman 						break;
93418a6c85fSIgal Liberman 					}
93518a6c85fSIgal Liberman 				}
93618a6c85fSIgal Liberman 			}
93718a6c85fSIgal Liberman 		}
93818a6c85fSIgal Liberman 	}
93918a6c85fSIgal Liberman 
94018a6c85fSIgal Liberman 	if (buf_pool_depletion->single_pool_mode_enable) {
94118a6c85fSIgal Liberman 		for (i = 0; i < port->bm_max_num_of_pools; i++) {
94218a6c85fSIgal Liberman 			if (buf_pool_depletion->
94318a6c85fSIgal Liberman 			    pools_to_consider_for_single_mode[i]) {
94418a6c85fSIgal Liberman 				for (j = 0; j < ext_buf_pools->
94518a6c85fSIgal Liberman 				     num_of_pools_used; j++) {
94618a6c85fSIgal Liberman 					if (i == ordered_array[j]) {
94718a6c85fSIgal Liberman 						bpools.bpool[j].
94818a6c85fSIgal Liberman 						    single_bp_depleted = true;
94918a6c85fSIgal Liberman 						break;
95018a6c85fSIgal Liberman 					}
95118a6c85fSIgal Liberman 				}
95218a6c85fSIgal Liberman 			}
95318a6c85fSIgal Liberman 		}
95418a6c85fSIgal Liberman 	}
95518a6c85fSIgal Liberman 
95618a6c85fSIgal Liberman 	err = set_bpools(port, &bpools);
95718a6c85fSIgal Liberman 	if (err != 0) {
95818a6c85fSIgal Liberman 		dev_err(port->dev, "%s: set_bpools() failed\n", __func__);
95918a6c85fSIgal Liberman 		return -EINVAL;
96018a6c85fSIgal Liberman 	}
96118a6c85fSIgal Liberman 
96218a6c85fSIgal Liberman 	return 0;
96318a6c85fSIgal Liberman }
96418a6c85fSIgal Liberman 
init_low_level_driver(struct fman_port * port)96518a6c85fSIgal Liberman static int init_low_level_driver(struct fman_port *port)
96618a6c85fSIgal Liberman {
96718a6c85fSIgal Liberman 	struct fman_port_cfg *cfg = port->cfg;
96818a6c85fSIgal Liberman 	u32 tmp_val;
96918a6c85fSIgal Liberman 
97018a6c85fSIgal Liberman 	switch (port->port_type) {
97118a6c85fSIgal Liberman 	case FMAN_PORT_TYPE_RX:
97218a6c85fSIgal Liberman 		cfg->err_mask = (RX_ERRS_TO_ENQ & ~cfg->discard_mask);
97318a6c85fSIgal Liberman 		break;
97418a6c85fSIgal Liberman 	default:
97518a6c85fSIgal Liberman 		break;
97618a6c85fSIgal Liberman 	}
97718a6c85fSIgal Liberman 
97818a6c85fSIgal Liberman 	tmp_val = (u32)((port->internal_buf_offset % OFFSET_UNITS) ?
97918a6c85fSIgal Liberman 		(port->internal_buf_offset / OFFSET_UNITS + 1) :
98018a6c85fSIgal Liberman 		(port->internal_buf_offset / OFFSET_UNITS));
98118a6c85fSIgal Liberman 	port->internal_buf_offset = (u8)(tmp_val * OFFSET_UNITS);
98218a6c85fSIgal Liberman 	port->cfg->int_buf_start_margin = port->internal_buf_offset;
98318a6c85fSIgal Liberman 
98418a6c85fSIgal Liberman 	if (init(port) != 0) {
98518a6c85fSIgal Liberman 		dev_err(port->dev, "%s: fman port initialization failed\n",
98618a6c85fSIgal Liberman 			__func__);
98718a6c85fSIgal Liberman 		return -ENODEV;
98818a6c85fSIgal Liberman 	}
98918a6c85fSIgal Liberman 
99018a6c85fSIgal Liberman 	/* The code bellow is a trick so the FM will not release the buffer
99118a6c85fSIgal Liberman 	 * to BM nor will try to enqueue the frame to QM
99218a6c85fSIgal Liberman 	 */
99318a6c85fSIgal Liberman 	if (port->port_type == FMAN_PORT_TYPE_TX) {
99418a6c85fSIgal Liberman 		if (!cfg->dflt_fqid && cfg->dont_release_buf) {
99518a6c85fSIgal Liberman 			/* override fmbm_tcfqid 0 with a false non-0 value.
99618a6c85fSIgal Liberman 			 * This will force FM to act according to tfene.
99718a6c85fSIgal Liberman 			 * Otherwise, if fmbm_tcfqid is 0 the FM will release
99818a6c85fSIgal Liberman 			 * buffers to BM regardless of fmbm_tfene
99918a6c85fSIgal Liberman 			 */
100018a6c85fSIgal Liberman 			iowrite32be(0xFFFFFF, &port->bmi_regs->tx.fmbm_tcfqid);
100118a6c85fSIgal Liberman 			iowrite32be(NIA_ENG_BMI | NIA_BMI_AC_TX_RELEASE,
100218a6c85fSIgal Liberman 				    &port->bmi_regs->tx.fmbm_tfene);
100318a6c85fSIgal Liberman 		}
100418a6c85fSIgal Liberman 	}
100518a6c85fSIgal Liberman 
100618a6c85fSIgal Liberman 	return 0;
100718a6c85fSIgal Liberman }
100818a6c85fSIgal Liberman 
fill_soc_specific_params(struct fman_port * port)100918a6c85fSIgal Liberman static int fill_soc_specific_params(struct fman_port *port)
101018a6c85fSIgal Liberman {
101118a6c85fSIgal Liberman 	u32 bmi_max_fifo_size;
101218a6c85fSIgal Liberman 
101318a6c85fSIgal Liberman 	bmi_max_fifo_size = fman_get_bmi_max_fifo_size(port->fm);
101418a6c85fSIgal Liberman 	port->max_port_fifo_size = MAX_PORT_FIFO_SIZE(bmi_max_fifo_size);
101518a6c85fSIgal Liberman 	port->bm_max_num_of_pools = 64;
101618a6c85fSIgal Liberman 
101718a6c85fSIgal Liberman 	/* P4080 - Major 2
101818a6c85fSIgal Liberman 	 * P2041/P3041/P5020/P5040 - Major 3
101918a6c85fSIgal Liberman 	 * Tx/Bx - Major 6
102018a6c85fSIgal Liberman 	 */
102118a6c85fSIgal Liberman 	switch (port->rev_info.major) {
102218a6c85fSIgal Liberman 	case 2:
102318a6c85fSIgal Liberman 	case 3:
102418a6c85fSIgal Liberman 		port->max_num_of_ext_pools		= 4;
102518a6c85fSIgal Liberman 		port->max_num_of_sub_portals		= 12;
102618a6c85fSIgal Liberman 		break;
102718a6c85fSIgal Liberman 
102818a6c85fSIgal Liberman 	case 6:
102918a6c85fSIgal Liberman 		port->max_num_of_ext_pools		= 8;
103018a6c85fSIgal Liberman 		port->max_num_of_sub_portals		= 16;
103118a6c85fSIgal Liberman 		break;
103218a6c85fSIgal Liberman 
103318a6c85fSIgal Liberman 	default:
103418a6c85fSIgal Liberman 		dev_err(port->dev, "%s: Unsupported FMan version\n", __func__);
103518a6c85fSIgal Liberman 		return -EINVAL;
103618a6c85fSIgal Liberman 	}
103718a6c85fSIgal Liberman 
103818a6c85fSIgal Liberman 	return 0;
103918a6c85fSIgal Liberman }
104018a6c85fSIgal Liberman 
get_dflt_fifo_deq_pipeline_depth(u8 major,enum fman_port_type type,u16 speed)104118a6c85fSIgal Liberman static int get_dflt_fifo_deq_pipeline_depth(u8 major, enum fman_port_type type,
104218a6c85fSIgal Liberman 					    u16 speed)
104318a6c85fSIgal Liberman {
104418a6c85fSIgal Liberman 	switch (type) {
104518a6c85fSIgal Liberman 	case FMAN_PORT_TYPE_RX:
104618a6c85fSIgal Liberman 	case FMAN_PORT_TYPE_TX:
104718a6c85fSIgal Liberman 		switch (speed) {
104818a6c85fSIgal Liberman 		case 10000:
104918a6c85fSIgal Liberman 			return 4;
105018a6c85fSIgal Liberman 		case 1000:
105118a6c85fSIgal Liberman 			if (major >= 6)
105218a6c85fSIgal Liberman 				return 2;
105318a6c85fSIgal Liberman 			else
105418a6c85fSIgal Liberman 				return 1;
105518a6c85fSIgal Liberman 		default:
105618a6c85fSIgal Liberman 			return 0;
105718a6c85fSIgal Liberman 		}
105818a6c85fSIgal Liberman 	default:
105918a6c85fSIgal Liberman 		return 0;
106018a6c85fSIgal Liberman 	}
106118a6c85fSIgal Liberman }
106218a6c85fSIgal Liberman 
get_dflt_num_of_tasks(u8 major,enum fman_port_type type,u16 speed)106318a6c85fSIgal Liberman static int get_dflt_num_of_tasks(u8 major, enum fman_port_type type,
106418a6c85fSIgal Liberman 				 u16 speed)
106518a6c85fSIgal Liberman {
106618a6c85fSIgal Liberman 	switch (type) {
106718a6c85fSIgal Liberman 	case FMAN_PORT_TYPE_RX:
106818a6c85fSIgal Liberman 	case FMAN_PORT_TYPE_TX:
106918a6c85fSIgal Liberman 		switch (speed) {
107018a6c85fSIgal Liberman 		case 10000:
107118a6c85fSIgal Liberman 			return 16;
107218a6c85fSIgal Liberman 		case 1000:
107318a6c85fSIgal Liberman 			if (major >= 6)
107418a6c85fSIgal Liberman 				return 4;
107518a6c85fSIgal Liberman 			else
107618a6c85fSIgal Liberman 				return 3;
107718a6c85fSIgal Liberman 		default:
107818a6c85fSIgal Liberman 			return 0;
107918a6c85fSIgal Liberman 		}
108018a6c85fSIgal Liberman 	default:
108118a6c85fSIgal Liberman 		return 0;
108218a6c85fSIgal Liberman 	}
108318a6c85fSIgal Liberman }
108418a6c85fSIgal Liberman 
get_dflt_extra_num_of_tasks(u8 major,enum fman_port_type type,u16 speed)108518a6c85fSIgal Liberman static int get_dflt_extra_num_of_tasks(u8 major, enum fman_port_type type,
108618a6c85fSIgal Liberman 				       u16 speed)
108718a6c85fSIgal Liberman {
108818a6c85fSIgal Liberman 	switch (type) {
108918a6c85fSIgal Liberman 	case FMAN_PORT_TYPE_RX:
109018a6c85fSIgal Liberman 		/* FMan V3 */
109118a6c85fSIgal Liberman 		if (major >= 6)
109218a6c85fSIgal Liberman 			return 0;
109318a6c85fSIgal Liberman 
109418a6c85fSIgal Liberman 		/* FMan V2 */
109518a6c85fSIgal Liberman 		if (speed == 10000)
109618a6c85fSIgal Liberman 			return 8;
109718a6c85fSIgal Liberman 		else
109818a6c85fSIgal Liberman 			return 2;
109918a6c85fSIgal Liberman 	case FMAN_PORT_TYPE_TX:
110018a6c85fSIgal Liberman 	default:
110118a6c85fSIgal Liberman 		return 0;
110218a6c85fSIgal Liberman 	}
110318a6c85fSIgal Liberman }
110418a6c85fSIgal Liberman 
get_dflt_num_of_open_dmas(u8 major,enum fman_port_type type,u16 speed)110518a6c85fSIgal Liberman static int get_dflt_num_of_open_dmas(u8 major, enum fman_port_type type,
110618a6c85fSIgal Liberman 				     u16 speed)
110718a6c85fSIgal Liberman {
110818a6c85fSIgal Liberman 	int val;
110918a6c85fSIgal Liberman 
111018a6c85fSIgal Liberman 	if (major >= 6) {
111118a6c85fSIgal Liberman 		switch (type) {
111218a6c85fSIgal Liberman 		case FMAN_PORT_TYPE_TX:
111318a6c85fSIgal Liberman 			if (speed == 10000)
111418a6c85fSIgal Liberman 				val = 12;
111518a6c85fSIgal Liberman 			else
111618a6c85fSIgal Liberman 				val = 3;
111718a6c85fSIgal Liberman 			break;
111818a6c85fSIgal Liberman 		case FMAN_PORT_TYPE_RX:
111918a6c85fSIgal Liberman 			if (speed == 10000)
112018a6c85fSIgal Liberman 				val = 8;
112118a6c85fSIgal Liberman 			else
112218a6c85fSIgal Liberman 				val = 2;
112318a6c85fSIgal Liberman 			break;
112418a6c85fSIgal Liberman 		default:
112518a6c85fSIgal Liberman 			return 0;
112618a6c85fSIgal Liberman 		}
112718a6c85fSIgal Liberman 	} else {
112818a6c85fSIgal Liberman 		switch (type) {
112918a6c85fSIgal Liberman 		case FMAN_PORT_TYPE_TX:
113018a6c85fSIgal Liberman 		case FMAN_PORT_TYPE_RX:
113118a6c85fSIgal Liberman 			if (speed == 10000)
113218a6c85fSIgal Liberman 				val = 8;
113318a6c85fSIgal Liberman 			else
113418a6c85fSIgal Liberman 				val = 1;
113518a6c85fSIgal Liberman 			break;
113618a6c85fSIgal Liberman 		default:
113718a6c85fSIgal Liberman 			val = 0;
113818a6c85fSIgal Liberman 		}
113918a6c85fSIgal Liberman 	}
114018a6c85fSIgal Liberman 
114118a6c85fSIgal Liberman 	return val;
114218a6c85fSIgal Liberman }
114318a6c85fSIgal Liberman 
get_dflt_extra_num_of_open_dmas(u8 major,enum fman_port_type type,u16 speed)114418a6c85fSIgal Liberman static int get_dflt_extra_num_of_open_dmas(u8 major, enum fman_port_type type,
114518a6c85fSIgal Liberman 					   u16 speed)
114618a6c85fSIgal Liberman {
114718a6c85fSIgal Liberman 	/* FMan V3 */
114818a6c85fSIgal Liberman 	if (major >= 6)
114918a6c85fSIgal Liberman 		return 0;
115018a6c85fSIgal Liberman 
115118a6c85fSIgal Liberman 	/* FMan V2 */
115218a6c85fSIgal Liberman 	switch (type) {
115318a6c85fSIgal Liberman 	case FMAN_PORT_TYPE_RX:
115418a6c85fSIgal Liberman 	case FMAN_PORT_TYPE_TX:
115518a6c85fSIgal Liberman 		if (speed == 10000)
115618a6c85fSIgal Liberman 			return 8;
115718a6c85fSIgal Liberman 		else
115818a6c85fSIgal Liberman 			return 1;
115918a6c85fSIgal Liberman 	default:
116018a6c85fSIgal Liberman 		return 0;
116118a6c85fSIgal Liberman 	}
116218a6c85fSIgal Liberman }
116318a6c85fSIgal Liberman 
get_dflt_num_of_fifo_bufs(u8 major,enum fman_port_type type,u16 speed)116418a6c85fSIgal Liberman static int get_dflt_num_of_fifo_bufs(u8 major, enum fman_port_type type,
116518a6c85fSIgal Liberman 				     u16 speed)
116618a6c85fSIgal Liberman {
116718a6c85fSIgal Liberman 	int val;
116818a6c85fSIgal Liberman 
116918a6c85fSIgal Liberman 	if (major >= 6) {
117018a6c85fSIgal Liberman 		switch (type) {
117118a6c85fSIgal Liberman 		case FMAN_PORT_TYPE_TX:
117218a6c85fSIgal Liberman 			if (speed == 10000)
117318a6c85fSIgal Liberman 				val = 64;
117418a6c85fSIgal Liberman 			else
117518a6c85fSIgal Liberman 				val = 50;
117618a6c85fSIgal Liberman 			break;
117718a6c85fSIgal Liberman 		case FMAN_PORT_TYPE_RX:
117818a6c85fSIgal Liberman 			if (speed == 10000)
117918a6c85fSIgal Liberman 				val = 96;
118018a6c85fSIgal Liberman 			else
118118a6c85fSIgal Liberman 				val = 50;
118218a6c85fSIgal Liberman 			break;
118318a6c85fSIgal Liberman 		default:
118418a6c85fSIgal Liberman 			val = 0;
118518a6c85fSIgal Liberman 		}
118618a6c85fSIgal Liberman 	} else {
118718a6c85fSIgal Liberman 		switch (type) {
118818a6c85fSIgal Liberman 		case FMAN_PORT_TYPE_TX:
118918a6c85fSIgal Liberman 			if (speed == 10000)
119018a6c85fSIgal Liberman 				val = 48;
119118a6c85fSIgal Liberman 			else
119218a6c85fSIgal Liberman 				val = 44;
119318a6c85fSIgal Liberman 			break;
119418a6c85fSIgal Liberman 		case FMAN_PORT_TYPE_RX:
119518a6c85fSIgal Liberman 			if (speed == 10000)
119618a6c85fSIgal Liberman 				val = 48;
119718a6c85fSIgal Liberman 			else
119818a6c85fSIgal Liberman 				val = 45;
119918a6c85fSIgal Liberman 			break;
120018a6c85fSIgal Liberman 		default:
120118a6c85fSIgal Liberman 			val = 0;
120218a6c85fSIgal Liberman 		}
120318a6c85fSIgal Liberman 	}
120418a6c85fSIgal Liberman 
120518a6c85fSIgal Liberman 	return val;
120618a6c85fSIgal Liberman }
120718a6c85fSIgal Liberman 
set_dflt_cfg(struct fman_port * port,struct fman_port_params * port_params)120818a6c85fSIgal Liberman static void set_dflt_cfg(struct fman_port *port,
120918a6c85fSIgal Liberman 			 struct fman_port_params *port_params)
121018a6c85fSIgal Liberman {
121118a6c85fSIgal Liberman 	struct fman_port_cfg *cfg = port->cfg;
121218a6c85fSIgal Liberman 
121318a6c85fSIgal Liberman 	cfg->dma_swap_data = FMAN_PORT_DMA_NO_SWAP;
121418a6c85fSIgal Liberman 	cfg->color = FMAN_PORT_COLOR_GREEN;
121518a6c85fSIgal Liberman 	cfg->rx_cut_end_bytes = DFLT_PORT_CUT_BYTES_FROM_END;
121618a6c85fSIgal Liberman 	cfg->rx_pri_elevation = BMI_PRIORITY_ELEVATION_LEVEL;
121718a6c85fSIgal Liberman 	cfg->rx_fifo_thr = BMI_FIFO_THRESHOLD;
121818a6c85fSIgal Liberman 	cfg->tx_fifo_low_comf_level = (5 * 1024);
121918a6c85fSIgal Liberman 	cfg->deq_type = FMAN_PORT_DEQ_BY_PRI;
122018a6c85fSIgal Liberman 	cfg->deq_prefetch_option = FMAN_PORT_DEQ_FULL_PREFETCH;
122118a6c85fSIgal Liberman 	cfg->tx_fifo_deq_pipeline_depth =
122218a6c85fSIgal Liberman 		BMI_DEQUEUE_PIPELINE_DEPTH(port->port_type, port->port_speed);
122318a6c85fSIgal Liberman 	cfg->deq_byte_cnt = QMI_BYTE_COUNT_LEVEL_CONTROL(port->port_type);
122418a6c85fSIgal Liberman 
122518a6c85fSIgal Liberman 	cfg->rx_pri_elevation =
122618a6c85fSIgal Liberman 		DFLT_PORT_RX_FIFO_PRI_ELEVATION_LEV(port->max_port_fifo_size);
122718a6c85fSIgal Liberman 	port->cfg->rx_fifo_thr =
122818a6c85fSIgal Liberman 		DFLT_PORT_RX_FIFO_THRESHOLD(port->rev_info.major,
122918a6c85fSIgal Liberman 					    port->max_port_fifo_size);
123018a6c85fSIgal Liberman 
123118a6c85fSIgal Liberman 	if ((port->rev_info.major == 6) &&
123218a6c85fSIgal Liberman 	    ((port->rev_info.minor == 0) || (port->rev_info.minor == 3)))
123318a6c85fSIgal Liberman 		cfg->errata_A006320 = true;
123418a6c85fSIgal Liberman 
123518a6c85fSIgal Liberman 	/* Excessive Threshold register - exists for pre-FMv3 chips only */
123618a6c85fSIgal Liberman 	if (port->rev_info.major < 6)
123718a6c85fSIgal Liberman 		cfg->excessive_threshold_register = true;
123818a6c85fSIgal Liberman 	else
123918a6c85fSIgal Liberman 		cfg->fmbm_tfne_has_features = true;
124018a6c85fSIgal Liberman 
124118a6c85fSIgal Liberman 	cfg->buffer_prefix_content.data_align =
124218a6c85fSIgal Liberman 		DFLT_PORT_BUFFER_PREFIX_CONTEXT_DATA_ALIGN;
124318a6c85fSIgal Liberman }
124418a6c85fSIgal Liberman 
set_rx_dflt_cfg(struct fman_port * port,struct fman_port_params * port_params)124518a6c85fSIgal Liberman static void set_rx_dflt_cfg(struct fman_port *port,
124618a6c85fSIgal Liberman 			    struct fman_port_params *port_params)
124718a6c85fSIgal Liberman {
124818a6c85fSIgal Liberman 	port->cfg->discard_mask = DFLT_PORT_ERRORS_TO_DISCARD;
124918a6c85fSIgal Liberman 
125018a6c85fSIgal Liberman 	memcpy(&port->cfg->ext_buf_pools,
125118a6c85fSIgal Liberman 	       &port_params->specific_params.rx_params.ext_buf_pools,
125218a6c85fSIgal Liberman 	       sizeof(struct fman_ext_pools));
125318a6c85fSIgal Liberman 	port->cfg->err_fqid =
125418a6c85fSIgal Liberman 		port_params->specific_params.rx_params.err_fqid;
125518a6c85fSIgal Liberman 	port->cfg->dflt_fqid =
125618a6c85fSIgal Liberman 		port_params->specific_params.rx_params.dflt_fqid;
12577472f4f2SIordache Florinel-R70177 	port->cfg->pcd_base_fqid =
12587472f4f2SIordache Florinel-R70177 		port_params->specific_params.rx_params.pcd_base_fqid;
12597472f4f2SIordache Florinel-R70177 	port->cfg->pcd_fqs_count =
12607472f4f2SIordache Florinel-R70177 		port_params->specific_params.rx_params.pcd_fqs_count;
126118a6c85fSIgal Liberman }
126218a6c85fSIgal Liberman 
set_tx_dflt_cfg(struct fman_port * port,struct fman_port_params * port_params,struct fman_port_dts_params * dts_params)126318a6c85fSIgal Liberman static void set_tx_dflt_cfg(struct fman_port *port,
126418a6c85fSIgal Liberman 			    struct fman_port_params *port_params,
126518a6c85fSIgal Liberman 			    struct fman_port_dts_params *dts_params)
126618a6c85fSIgal Liberman {
126718a6c85fSIgal Liberman 	port->cfg->tx_fifo_deq_pipeline_depth =
126818a6c85fSIgal Liberman 		get_dflt_fifo_deq_pipeline_depth(port->rev_info.major,
126918a6c85fSIgal Liberman 						 port->port_type,
127018a6c85fSIgal Liberman 						 port->port_speed);
127118a6c85fSIgal Liberman 	port->cfg->err_fqid =
127218a6c85fSIgal Liberman 		port_params->specific_params.non_rx_params.err_fqid;
127318a6c85fSIgal Liberman 	port->cfg->deq_sp =
127418a6c85fSIgal Liberman 		(u8)(dts_params->qman_channel_id & QMI_DEQ_CFG_SUBPORTAL_MASK);
127518a6c85fSIgal Liberman 	port->cfg->dflt_fqid =
127618a6c85fSIgal Liberman 		port_params->specific_params.non_rx_params.dflt_fqid;
127718a6c85fSIgal Liberman 	port->cfg->deq_high_priority = true;
127818a6c85fSIgal Liberman }
127918a6c85fSIgal Liberman 
128018a6c85fSIgal Liberman /**
128118a6c85fSIgal Liberman  * fman_port_config
128218a6c85fSIgal Liberman  * @port:	Pointer to the port structure
128318a6c85fSIgal Liberman  * @params:	Pointer to data structure of parameters
128418a6c85fSIgal Liberman  *
128518a6c85fSIgal Liberman  * Creates a descriptor for the FM PORT module.
128618a6c85fSIgal Liberman  * The routine returns a pointer to the FM PORT object.
128718a6c85fSIgal Liberman  * This descriptor must be passed as first parameter to all other FM PORT
128818a6c85fSIgal Liberman  * function calls.
128918a6c85fSIgal Liberman  * No actual initialization or configuration of FM hardware is done by this
129018a6c85fSIgal Liberman  * routine.
129118a6c85fSIgal Liberman  *
129218a6c85fSIgal Liberman  * Return: 0 on success; Error code otherwise.
129318a6c85fSIgal Liberman  */
fman_port_config(struct fman_port * port,struct fman_port_params * params)129418a6c85fSIgal Liberman int fman_port_config(struct fman_port *port, struct fman_port_params *params)
129518a6c85fSIgal Liberman {
129618a6c85fSIgal Liberman 	void __iomem *base_addr = port->dts_params.base_addr;
129718a6c85fSIgal Liberman 	int err;
129818a6c85fSIgal Liberman 
129918a6c85fSIgal Liberman 	/* Allocate the FM driver's parameters structure */
130018a6c85fSIgal Liberman 	port->cfg = kzalloc(sizeof(*port->cfg), GFP_KERNEL);
130118a6c85fSIgal Liberman 	if (!port->cfg)
1302226327b2SMadalin Bucur 		return -EINVAL;
130318a6c85fSIgal Liberman 
130418a6c85fSIgal Liberman 	/* Initialize FM port parameters which will be kept by the driver */
130518a6c85fSIgal Liberman 	port->port_type = port->dts_params.type;
130618a6c85fSIgal Liberman 	port->port_speed = port->dts_params.speed;
130718a6c85fSIgal Liberman 	port->port_id = port->dts_params.id;
130818a6c85fSIgal Liberman 	port->fm = port->dts_params.fman;
130918a6c85fSIgal Liberman 	port->ext_pools_num = (u8)8;
131018a6c85fSIgal Liberman 
131118a6c85fSIgal Liberman 	/* get FM revision */
131218a6c85fSIgal Liberman 	fman_get_revision(port->fm, &port->rev_info);
131318a6c85fSIgal Liberman 
131418a6c85fSIgal Liberman 	err = fill_soc_specific_params(port);
131518a6c85fSIgal Liberman 	if (err)
131618a6c85fSIgal Liberman 		goto err_port_cfg;
131718a6c85fSIgal Liberman 
131818a6c85fSIgal Liberman 	switch (port->port_type) {
131918a6c85fSIgal Liberman 	case FMAN_PORT_TYPE_RX:
132018a6c85fSIgal Liberman 		set_rx_dflt_cfg(port, params);
1321df561f66SGustavo A. R. Silva 		fallthrough;
132218a6c85fSIgal Liberman 	case FMAN_PORT_TYPE_TX:
132318a6c85fSIgal Liberman 		set_tx_dflt_cfg(port, params, &port->dts_params);
1324df561f66SGustavo A. R. Silva 		fallthrough;
132518a6c85fSIgal Liberman 	default:
132618a6c85fSIgal Liberman 		set_dflt_cfg(port, params);
132718a6c85fSIgal Liberman 	}
132818a6c85fSIgal Liberman 
132918a6c85fSIgal Liberman 	/* Continue with other parameters */
133018a6c85fSIgal Liberman 	/* set memory map pointers */
133118a6c85fSIgal Liberman 	port->bmi_regs = base_addr + BMI_PORT_REGS_OFFSET;
133218a6c85fSIgal Liberman 	port->qmi_regs = base_addr + QMI_PORT_REGS_OFFSET;
13331df653cfSMadalin Bucur 	port->hwp_regs = base_addr + HWP_PORT_REGS_OFFSET;
133418a6c85fSIgal Liberman 
133518a6c85fSIgal Liberman 	port->max_frame_length = DFLT_PORT_MAX_FRAME_LENGTH;
133618a6c85fSIgal Liberman 	/* resource distribution. */
133718a6c85fSIgal Liberman 
133818a6c85fSIgal Liberman 	port->fifo_bufs.num =
133918a6c85fSIgal Liberman 	get_dflt_num_of_fifo_bufs(port->rev_info.major, port->port_type,
134018a6c85fSIgal Liberman 				  port->port_speed) * FMAN_BMI_FIFO_UNITS;
134118a6c85fSIgal Liberman 	port->fifo_bufs.extra =
134218a6c85fSIgal Liberman 	DFLT_PORT_EXTRA_NUM_OF_FIFO_BUFS * FMAN_BMI_FIFO_UNITS;
134318a6c85fSIgal Liberman 
134418a6c85fSIgal Liberman 	port->open_dmas.num =
134518a6c85fSIgal Liberman 	get_dflt_num_of_open_dmas(port->rev_info.major,
134618a6c85fSIgal Liberman 				  port->port_type, port->port_speed);
134718a6c85fSIgal Liberman 	port->open_dmas.extra =
134818a6c85fSIgal Liberman 	get_dflt_extra_num_of_open_dmas(port->rev_info.major,
134918a6c85fSIgal Liberman 					port->port_type, port->port_speed);
135018a6c85fSIgal Liberman 	port->tasks.num =
135118a6c85fSIgal Liberman 	get_dflt_num_of_tasks(port->rev_info.major,
135218a6c85fSIgal Liberman 			      port->port_type, port->port_speed);
135318a6c85fSIgal Liberman 	port->tasks.extra =
135418a6c85fSIgal Liberman 	get_dflt_extra_num_of_tasks(port->rev_info.major,
135518a6c85fSIgal Liberman 				    port->port_type, port->port_speed);
135618a6c85fSIgal Liberman 
135718a6c85fSIgal Liberman 	/* FM_HEAVY_TRAFFIC_SEQUENCER_HANG_ERRATA_FMAN_A006981 errata
135818a6c85fSIgal Liberman 	 * workaround
135918a6c85fSIgal Liberman 	 */
136018a6c85fSIgal Liberman 	if ((port->rev_info.major == 6) && (port->rev_info.minor == 0) &&
136118a6c85fSIgal Liberman 	    (((port->port_type == FMAN_PORT_TYPE_TX) &&
136218a6c85fSIgal Liberman 	    (port->port_speed == 1000)))) {
136318a6c85fSIgal Liberman 		port->open_dmas.num = 16;
136418a6c85fSIgal Liberman 		port->open_dmas.extra = 0;
136518a6c85fSIgal Liberman 	}
136618a6c85fSIgal Liberman 
136718a6c85fSIgal Liberman 	if (port->rev_info.major >= 6 &&
136818a6c85fSIgal Liberman 	    port->port_type == FMAN_PORT_TYPE_TX &&
136918a6c85fSIgal Liberman 	    port->port_speed == 1000) {
137018a6c85fSIgal Liberman 		/* FM_WRONG_RESET_VALUES_ERRATA_FMAN_A005127 Errata
137118a6c85fSIgal Liberman 		 * workaround
137218a6c85fSIgal Liberman 		 */
137318a6c85fSIgal Liberman 		u32 reg;
137418a6c85fSIgal Liberman 
137518a6c85fSIgal Liberman 		reg = 0x00001013;
137618a6c85fSIgal Liberman 		iowrite32be(reg, &port->bmi_regs->tx.fmbm_tfp);
137718a6c85fSIgal Liberman 	}
137818a6c85fSIgal Liberman 
137918a6c85fSIgal Liberman 	return 0;
138018a6c85fSIgal Liberman 
138118a6c85fSIgal Liberman err_port_cfg:
138218a6c85fSIgal Liberman 	kfree(port->cfg);
138318a6c85fSIgal Liberman 	return -EINVAL;
138418a6c85fSIgal Liberman }
138518a6c85fSIgal Liberman EXPORT_SYMBOL(fman_port_config);
138618a6c85fSIgal Liberman 
1387d0ea5cbdSJesse Brandeburg /*
13887472f4f2SIordache Florinel-R70177  * fman_port_use_kg_hash
1389d0ea5cbdSJesse Brandeburg  * @port: A pointer to a FM Port module.
1390d0ea5cbdSJesse Brandeburg  * @enable: enable or disable
1391d0ea5cbdSJesse Brandeburg  *
13927472f4f2SIordache Florinel-R70177  * Sets the HW KeyGen or the BMI as HW Parser next engine, enabling
13937472f4f2SIordache Florinel-R70177  * or bypassing the KeyGen hashing of Rx traffic
13947472f4f2SIordache Florinel-R70177  */
fman_port_use_kg_hash(struct fman_port * port,bool enable)13957472f4f2SIordache Florinel-R70177 void fman_port_use_kg_hash(struct fman_port *port, bool enable)
13967472f4f2SIordache Florinel-R70177 {
13977472f4f2SIordache Florinel-R70177 	if (enable)
13987472f4f2SIordache Florinel-R70177 		/* After the Parser frames go to KeyGen */
13997472f4f2SIordache Florinel-R70177 		iowrite32be(NIA_ENG_HWK, &port->bmi_regs->rx.fmbm_rfpne);
14007472f4f2SIordache Florinel-R70177 	else
14017472f4f2SIordache Florinel-R70177 		/* After the Parser frames go to BMI */
14027472f4f2SIordache Florinel-R70177 		iowrite32be(NIA_ENG_BMI | NIA_BMI_AC_ENQ_FRAME,
14037472f4f2SIordache Florinel-R70177 			    &port->bmi_regs->rx.fmbm_rfpne);
14047472f4f2SIordache Florinel-R70177 }
14057472f4f2SIordache Florinel-R70177 EXPORT_SYMBOL(fman_port_use_kg_hash);
14067472f4f2SIordache Florinel-R70177 
14077472f4f2SIordache Florinel-R70177 /**
140818a6c85fSIgal Liberman  * fman_port_init
1409d0ea5cbdSJesse Brandeburg  * @port:	A pointer to a FM Port module.
1410d0ea5cbdSJesse Brandeburg  *
141118a6c85fSIgal Liberman  * Initializes the FM PORT module by defining the software structure and
141218a6c85fSIgal Liberman  * configuring the hardware registers.
141318a6c85fSIgal Liberman  *
141418a6c85fSIgal Liberman  * Return: 0 on success; Error code otherwise.
141518a6c85fSIgal Liberman  */
fman_port_init(struct fman_port * port)141618a6c85fSIgal Liberman int fman_port_init(struct fman_port *port)
141718a6c85fSIgal Liberman {
14187472f4f2SIordache Florinel-R70177 	struct fman_port_init_params params;
14197472f4f2SIordache Florinel-R70177 	struct fman_keygen *keygen;
142018a6c85fSIgal Liberman 	struct fman_port_cfg *cfg;
142118a6c85fSIgal Liberman 	int err;
142218a6c85fSIgal Liberman 
142318a6c85fSIgal Liberman 	if (is_init_done(port->cfg))
142418a6c85fSIgal Liberman 		return -EINVAL;
142518a6c85fSIgal Liberman 
142618a6c85fSIgal Liberman 	err = fman_sp_build_buffer_struct(&port->cfg->int_context,
142718a6c85fSIgal Liberman 					  &port->cfg->buffer_prefix_content,
142818a6c85fSIgal Liberman 					  &port->cfg->buf_margins,
142918a6c85fSIgal Liberman 					  &port->buffer_offsets,
143018a6c85fSIgal Liberman 					  &port->internal_buf_offset);
143118a6c85fSIgal Liberman 	if (err)
143218a6c85fSIgal Liberman 		return err;
143318a6c85fSIgal Liberman 
143418a6c85fSIgal Liberman 	cfg = port->cfg;
143518a6c85fSIgal Liberman 
143618a6c85fSIgal Liberman 	if (port->port_type == FMAN_PORT_TYPE_RX) {
143718a6c85fSIgal Liberman 		/* Call the external Buffer routine which also checks fifo
143818a6c85fSIgal Liberman 		 * size and updates it if necessary
143918a6c85fSIgal Liberman 		 */
144018a6c85fSIgal Liberman 		/* define external buffer pools and pool depletion */
144118a6c85fSIgal Liberman 		err = set_ext_buffer_pools(port);
144218a6c85fSIgal Liberman 		if (err)
144318a6c85fSIgal Liberman 			return err;
144418a6c85fSIgal Liberman 		/* check if the largest external buffer pool is large enough */
144518a6c85fSIgal Liberman 		if (cfg->buf_margins.start_margins + MIN_EXT_BUF_SIZE +
144618a6c85fSIgal Liberman 		    cfg->buf_margins.end_margins >
144718a6c85fSIgal Liberman 		    port->rx_pools_params.largest_buf_size) {
144818a6c85fSIgal Liberman 			dev_err(port->dev, "%s: buf_margins.start_margins (%d) + minimum buf size (64) + buf_margins.end_margins (%d) is larger than maximum external buffer size (%d)\n",
144918a6c85fSIgal Liberman 				__func__, cfg->buf_margins.start_margins,
145018a6c85fSIgal Liberman 				cfg->buf_margins.end_margins,
145118a6c85fSIgal Liberman 				port->rx_pools_params.largest_buf_size);
145218a6c85fSIgal Liberman 			return -EINVAL;
145318a6c85fSIgal Liberman 		}
145418a6c85fSIgal Liberman 	}
145518a6c85fSIgal Liberman 
145618a6c85fSIgal Liberman 	/* Call FM module routine for communicating parameters */
145718a6c85fSIgal Liberman 	memset(&params, 0, sizeof(params));
145818a6c85fSIgal Liberman 	params.port_id = port->port_id;
145918a6c85fSIgal Liberman 	params.port_type = port->port_type;
146018a6c85fSIgal Liberman 	params.port_speed = port->port_speed;
146118a6c85fSIgal Liberman 	params.num_of_tasks = (u8)port->tasks.num;
146218a6c85fSIgal Liberman 	params.num_of_extra_tasks = (u8)port->tasks.extra;
146318a6c85fSIgal Liberman 	params.num_of_open_dmas = (u8)port->open_dmas.num;
146418a6c85fSIgal Liberman 	params.num_of_extra_open_dmas = (u8)port->open_dmas.extra;
146518a6c85fSIgal Liberman 
146618a6c85fSIgal Liberman 	if (port->fifo_bufs.num) {
146718a6c85fSIgal Liberman 		err = verify_size_of_fifo(port);
146818a6c85fSIgal Liberman 		if (err)
146918a6c85fSIgal Liberman 			return err;
147018a6c85fSIgal Liberman 	}
147118a6c85fSIgal Liberman 	params.size_of_fifo = port->fifo_bufs.num;
147218a6c85fSIgal Liberman 	params.extra_size_of_fifo = port->fifo_bufs.extra;
147318a6c85fSIgal Liberman 	params.deq_pipeline_depth = port->cfg->tx_fifo_deq_pipeline_depth;
147418a6c85fSIgal Liberman 	params.max_frame_length = port->max_frame_length;
147518a6c85fSIgal Liberman 
147618a6c85fSIgal Liberman 	err = fman_set_port_params(port->fm, &params);
147718a6c85fSIgal Liberman 	if (err)
147818a6c85fSIgal Liberman 		return err;
147918a6c85fSIgal Liberman 
148018a6c85fSIgal Liberman 	err = init_low_level_driver(port);
148118a6c85fSIgal Liberman 	if (err)
148218a6c85fSIgal Liberman 		return err;
148318a6c85fSIgal Liberman 
14847472f4f2SIordache Florinel-R70177 	if (port->cfg->pcd_fqs_count) {
14857472f4f2SIordache Florinel-R70177 		keygen = port->dts_params.fman->keygen;
14867472f4f2SIordache Florinel-R70177 		err = keygen_port_hashing_init(keygen, port->port_id,
14877472f4f2SIordache Florinel-R70177 					       port->cfg->pcd_base_fqid,
14887472f4f2SIordache Florinel-R70177 					       port->cfg->pcd_fqs_count);
14897472f4f2SIordache Florinel-R70177 		if (err)
14907472f4f2SIordache Florinel-R70177 			return err;
14917472f4f2SIordache Florinel-R70177 
14927472f4f2SIordache Florinel-R70177 		fman_port_use_kg_hash(port, true);
14937472f4f2SIordache Florinel-R70177 	}
14947472f4f2SIordache Florinel-R70177 
149518a6c85fSIgal Liberman 	kfree(port->cfg);
149618a6c85fSIgal Liberman 	port->cfg = NULL;
149718a6c85fSIgal Liberman 
149818a6c85fSIgal Liberman 	return 0;
149918a6c85fSIgal Liberman }
150018a6c85fSIgal Liberman EXPORT_SYMBOL(fman_port_init);
150118a6c85fSIgal Liberman 
150218a6c85fSIgal Liberman /**
150318a6c85fSIgal Liberman  * fman_port_cfg_buf_prefix_content
1504d0ea5cbdSJesse Brandeburg  * @port:			A pointer to a FM Port module.
1505d0ea5cbdSJesse Brandeburg  * @buffer_prefix_content:	A structure of parameters describing
150618a6c85fSIgal Liberman  *				the structure of the buffer.
150718a6c85fSIgal Liberman  *				Out parameter:
150818a6c85fSIgal Liberman  *				Start margin - offset of data from
150918a6c85fSIgal Liberman  *				start of external buffer.
151018a6c85fSIgal Liberman  * Defines the structure, size and content of the application buffer.
151118a6c85fSIgal Liberman  * The prefix, in Tx ports, if 'pass_prs_result', the application should set
151218a6c85fSIgal Liberman  * a value to their offsets in the prefix of the FM will save the first
151318a6c85fSIgal Liberman  * 'priv_data_size', than, depending on 'pass_prs_result' and
151418a6c85fSIgal Liberman  * 'pass_time_stamp', copy parse result and timeStamp, and the packet itself
151518a6c85fSIgal Liberman  * (in this order), to the application buffer, and to offset.
151618a6c85fSIgal Liberman  * Calling this routine changes the buffer margins definitions in the internal
151718a6c85fSIgal Liberman  * driver data base from its default configuration:
151818a6c85fSIgal Liberman  * Data size:  [DEFAULT_PORT_BUFFER_PREFIX_CONTENT_PRIV_DATA_SIZE]
151918a6c85fSIgal Liberman  * Pass Parser result: [DEFAULT_PORT_BUFFER_PREFIX_CONTENT_PASS_PRS_RESULT].
152018a6c85fSIgal Liberman  * Pass timestamp: [DEFAULT_PORT_BUFFER_PREFIX_CONTENT_PASS_TIME_STAMP].
152118a6c85fSIgal Liberman  * May be used for all ports
152218a6c85fSIgal Liberman  *
152318a6c85fSIgal Liberman  * Allowed only following fman_port_config() and before fman_port_init().
152418a6c85fSIgal Liberman  *
152518a6c85fSIgal Liberman  * Return: 0 on success; Error code otherwise.
152618a6c85fSIgal Liberman  */
fman_port_cfg_buf_prefix_content(struct fman_port * port,struct fman_buffer_prefix_content * buffer_prefix_content)152718a6c85fSIgal Liberman int fman_port_cfg_buf_prefix_content(struct fman_port *port,
152818a6c85fSIgal Liberman 				     struct fman_buffer_prefix_content *
152918a6c85fSIgal Liberman 				     buffer_prefix_content)
153018a6c85fSIgal Liberman {
153118a6c85fSIgal Liberman 	if (is_init_done(port->cfg))
153218a6c85fSIgal Liberman 		return -EINVAL;
153318a6c85fSIgal Liberman 
153418a6c85fSIgal Liberman 	memcpy(&port->cfg->buffer_prefix_content,
153518a6c85fSIgal Liberman 	       buffer_prefix_content,
153618a6c85fSIgal Liberman 	       sizeof(struct fman_buffer_prefix_content));
153718a6c85fSIgal Liberman 	/* if data_align was not initialized by user,
153818a6c85fSIgal Liberman 	 * we return to driver's default
153918a6c85fSIgal Liberman 	 */
154018a6c85fSIgal Liberman 	if (!port->cfg->buffer_prefix_content.data_align)
154118a6c85fSIgal Liberman 		port->cfg->buffer_prefix_content.data_align =
154218a6c85fSIgal Liberman 		DFLT_PORT_BUFFER_PREFIX_CONTEXT_DATA_ALIGN;
154318a6c85fSIgal Liberman 
154418a6c85fSIgal Liberman 	return 0;
154518a6c85fSIgal Liberman }
154618a6c85fSIgal Liberman EXPORT_SYMBOL(fman_port_cfg_buf_prefix_content);
154718a6c85fSIgal Liberman 
154818a6c85fSIgal Liberman /**
154918a6c85fSIgal Liberman  * fman_port_disable
1550d0ea5cbdSJesse Brandeburg  * @port:	A pointer to a FM Port module.
155118a6c85fSIgal Liberman  *
155218a6c85fSIgal Liberman  * Gracefully disable an FM port. The port will not start new	tasks after all
155318a6c85fSIgal Liberman  * tasks associated with the port are terminated.
155418a6c85fSIgal Liberman  *
155518a6c85fSIgal Liberman  * This is a blocking routine, it returns after port is gracefully stopped,
155618a6c85fSIgal Liberman  * i.e. the port will not except new frames, but it will finish all frames
155718a6c85fSIgal Liberman  * or tasks which were already began.
155818a6c85fSIgal Liberman  * Allowed only following fman_port_init().
155918a6c85fSIgal Liberman  *
156018a6c85fSIgal Liberman  * Return: 0 on success; Error code otherwise.
156118a6c85fSIgal Liberman  */
fman_port_disable(struct fman_port * port)156218a6c85fSIgal Liberman int fman_port_disable(struct fman_port *port)
156318a6c85fSIgal Liberman {
15645df6f7faSMadalin Bucur 	u32 __iomem *bmi_cfg_reg, *bmi_status_reg;
15655df6f7faSMadalin Bucur 	u32 tmp;
156618a6c85fSIgal Liberman 	bool rx_port, failure = false;
156718a6c85fSIgal Liberman 	int count;
156818a6c85fSIgal Liberman 
156918a6c85fSIgal Liberman 	if (!is_init_done(port->cfg))
157018a6c85fSIgal Liberman 		return -EINVAL;
157118a6c85fSIgal Liberman 
157218a6c85fSIgal Liberman 	switch (port->port_type) {
157318a6c85fSIgal Liberman 	case FMAN_PORT_TYPE_RX:
157418a6c85fSIgal Liberman 		bmi_cfg_reg = &port->bmi_regs->rx.fmbm_rcfg;
157518a6c85fSIgal Liberman 		bmi_status_reg = &port->bmi_regs->rx.fmbm_rst;
157618a6c85fSIgal Liberman 		rx_port = true;
157718a6c85fSIgal Liberman 		break;
157818a6c85fSIgal Liberman 	case FMAN_PORT_TYPE_TX:
157918a6c85fSIgal Liberman 		bmi_cfg_reg = &port->bmi_regs->tx.fmbm_tcfg;
158018a6c85fSIgal Liberman 		bmi_status_reg = &port->bmi_regs->tx.fmbm_tst;
158118a6c85fSIgal Liberman 		rx_port = false;
158218a6c85fSIgal Liberman 		break;
158318a6c85fSIgal Liberman 	default:
158418a6c85fSIgal Liberman 		return -EINVAL;
158518a6c85fSIgal Liberman 	}
158618a6c85fSIgal Liberman 
158718a6c85fSIgal Liberman 	/* Disable QMI */
158818a6c85fSIgal Liberman 	if (!rx_port) {
158918a6c85fSIgal Liberman 		tmp = ioread32be(&port->qmi_regs->fmqm_pnc) & ~QMI_PORT_CFG_EN;
159018a6c85fSIgal Liberman 		iowrite32be(tmp, &port->qmi_regs->fmqm_pnc);
159118a6c85fSIgal Liberman 
159218a6c85fSIgal Liberman 		/* Wait for QMI to finish FD handling */
159318a6c85fSIgal Liberman 		count = 100;
159418a6c85fSIgal Liberman 		do {
159518a6c85fSIgal Liberman 			udelay(10);
159618a6c85fSIgal Liberman 			tmp = ioread32be(&port->qmi_regs->fmqm_pns);
159718a6c85fSIgal Liberman 		} while ((tmp & QMI_PORT_STATUS_DEQ_FD_BSY) && --count);
159818a6c85fSIgal Liberman 
159918a6c85fSIgal Liberman 		if (count == 0) {
160018a6c85fSIgal Liberman 			/* Timeout */
160118a6c85fSIgal Liberman 			failure = true;
160218a6c85fSIgal Liberman 		}
160318a6c85fSIgal Liberman 	}
160418a6c85fSIgal Liberman 
160518a6c85fSIgal Liberman 	/* Disable BMI */
160618a6c85fSIgal Liberman 	tmp = ioread32be(bmi_cfg_reg) & ~BMI_PORT_CFG_EN;
160718a6c85fSIgal Liberman 	iowrite32be(tmp, bmi_cfg_reg);
160818a6c85fSIgal Liberman 
160918a6c85fSIgal Liberman 	/* Wait for graceful stop end */
161018a6c85fSIgal Liberman 	count = 500;
161118a6c85fSIgal Liberman 	do {
161218a6c85fSIgal Liberman 		udelay(10);
161318a6c85fSIgal Liberman 		tmp = ioread32be(bmi_status_reg);
161418a6c85fSIgal Liberman 	} while ((tmp & BMI_PORT_STATUS_BSY) && --count);
161518a6c85fSIgal Liberman 
161618a6c85fSIgal Liberman 	if (count == 0) {
161718a6c85fSIgal Liberman 		/* Timeout */
161818a6c85fSIgal Liberman 		failure = true;
161918a6c85fSIgal Liberman 	}
162018a6c85fSIgal Liberman 
162118a6c85fSIgal Liberman 	if (failure)
162218a6c85fSIgal Liberman 		dev_dbg(port->dev, "%s: FMan Port[%d]: BMI or QMI is Busy. Port forced down\n",
162318a6c85fSIgal Liberman 			__func__,  port->port_id);
162418a6c85fSIgal Liberman 
162518a6c85fSIgal Liberman 	return 0;
162618a6c85fSIgal Liberman }
162718a6c85fSIgal Liberman EXPORT_SYMBOL(fman_port_disable);
162818a6c85fSIgal Liberman 
162918a6c85fSIgal Liberman /**
163018a6c85fSIgal Liberman  * fman_port_enable
1631d0ea5cbdSJesse Brandeburg  * @port:	A pointer to a FM Port module.
163218a6c85fSIgal Liberman  *
163318a6c85fSIgal Liberman  * A runtime routine provided to allow disable/enable of port.
163418a6c85fSIgal Liberman  *
163518a6c85fSIgal Liberman  * Allowed only following fman_port_init().
163618a6c85fSIgal Liberman  *
163718a6c85fSIgal Liberman  * Return: 0 on success; Error code otherwise.
163818a6c85fSIgal Liberman  */
fman_port_enable(struct fman_port * port)163918a6c85fSIgal Liberman int fman_port_enable(struct fman_port *port)
164018a6c85fSIgal Liberman {
16415df6f7faSMadalin Bucur 	u32 __iomem *bmi_cfg_reg;
16425df6f7faSMadalin Bucur 	u32 tmp;
164318a6c85fSIgal Liberman 	bool rx_port;
164418a6c85fSIgal Liberman 
164518a6c85fSIgal Liberman 	if (!is_init_done(port->cfg))
164618a6c85fSIgal Liberman 		return -EINVAL;
164718a6c85fSIgal Liberman 
164818a6c85fSIgal Liberman 	switch (port->port_type) {
164918a6c85fSIgal Liberman 	case FMAN_PORT_TYPE_RX:
165018a6c85fSIgal Liberman 		bmi_cfg_reg = &port->bmi_regs->rx.fmbm_rcfg;
165118a6c85fSIgal Liberman 		rx_port = true;
165218a6c85fSIgal Liberman 		break;
165318a6c85fSIgal Liberman 	case FMAN_PORT_TYPE_TX:
165418a6c85fSIgal Liberman 		bmi_cfg_reg = &port->bmi_regs->tx.fmbm_tcfg;
165518a6c85fSIgal Liberman 		rx_port = false;
165618a6c85fSIgal Liberman 		break;
165718a6c85fSIgal Liberman 	default:
165818a6c85fSIgal Liberman 		return -EINVAL;
165918a6c85fSIgal Liberman 	}
166018a6c85fSIgal Liberman 
166118a6c85fSIgal Liberman 	/* Enable QMI */
166218a6c85fSIgal Liberman 	if (!rx_port) {
166318a6c85fSIgal Liberman 		tmp = ioread32be(&port->qmi_regs->fmqm_pnc) | QMI_PORT_CFG_EN;
166418a6c85fSIgal Liberman 		iowrite32be(tmp, &port->qmi_regs->fmqm_pnc);
166518a6c85fSIgal Liberman 	}
166618a6c85fSIgal Liberman 
166718a6c85fSIgal Liberman 	/* Enable BMI */
166818a6c85fSIgal Liberman 	tmp = ioread32be(bmi_cfg_reg) | BMI_PORT_CFG_EN;
166918a6c85fSIgal Liberman 	iowrite32be(tmp, bmi_cfg_reg);
167018a6c85fSIgal Liberman 
167118a6c85fSIgal Liberman 	return 0;
167218a6c85fSIgal Liberman }
167318a6c85fSIgal Liberman EXPORT_SYMBOL(fman_port_enable);
167418a6c85fSIgal Liberman 
167518a6c85fSIgal Liberman /**
167618a6c85fSIgal Liberman  * fman_port_bind
1677d0ea5cbdSJesse Brandeburg  * @dev:		FMan Port OF device pointer
167818a6c85fSIgal Liberman  *
167918a6c85fSIgal Liberman  * Bind to a specific FMan Port.
168018a6c85fSIgal Liberman  *
168118a6c85fSIgal Liberman  * Allowed only after the port was created.
168218a6c85fSIgal Liberman  *
168318a6c85fSIgal Liberman  * Return: A pointer to the FMan port device.
168418a6c85fSIgal Liberman  */
fman_port_bind(struct device * dev)168518a6c85fSIgal Liberman struct fman_port *fman_port_bind(struct device *dev)
168618a6c85fSIgal Liberman {
168718a6c85fSIgal Liberman 	return (struct fman_port *)(dev_get_drvdata(get_device(dev)));
168818a6c85fSIgal Liberman }
168918a6c85fSIgal Liberman EXPORT_SYMBOL(fman_port_bind);
169018a6c85fSIgal Liberman 
169118a6c85fSIgal Liberman /**
169218a6c85fSIgal Liberman  * fman_port_get_qman_channel_id
1693d0ea5cbdSJesse Brandeburg  * @port:	Pointer to the FMan port devuce
169418a6c85fSIgal Liberman  *
169518a6c85fSIgal Liberman  * Get the QMan channel ID for the specific port
169618a6c85fSIgal Liberman  *
169718a6c85fSIgal Liberman  * Return: QMan channel ID
169818a6c85fSIgal Liberman  */
fman_port_get_qman_channel_id(struct fman_port * port)169918a6c85fSIgal Liberman u32 fman_port_get_qman_channel_id(struct fman_port *port)
170018a6c85fSIgal Liberman {
170118a6c85fSIgal Liberman 	return port->dts_params.qman_channel_id;
170218a6c85fSIgal Liberman }
170318a6c85fSIgal Liberman EXPORT_SYMBOL(fman_port_get_qman_channel_id);
170418a6c85fSIgal Liberman 
1705681e3838SLaurentiu Tudor /**
1706681e3838SLaurentiu Tudor  * fman_port_get_device
1707d0ea5cbdSJesse Brandeburg  * @port:	Pointer to the FMan port device
1708681e3838SLaurentiu Tudor  *
1709681e3838SLaurentiu Tudor  * Get the 'struct device' associated to the specified FMan port device
1710681e3838SLaurentiu Tudor  *
1711681e3838SLaurentiu Tudor  * Return: pointer to associated 'struct device'
1712681e3838SLaurentiu Tudor  */
fman_port_get_device(struct fman_port * port)1713681e3838SLaurentiu Tudor struct device *fman_port_get_device(struct fman_port *port)
1714681e3838SLaurentiu Tudor {
1715681e3838SLaurentiu Tudor 	return port->dev;
1716681e3838SLaurentiu Tudor }
1717681e3838SLaurentiu Tudor EXPORT_SYMBOL(fman_port_get_device);
1718681e3838SLaurentiu Tudor 
fman_port_get_hash_result_offset(struct fman_port * port,u32 * offset)1719056057e2SMadalin Bucur int fman_port_get_hash_result_offset(struct fman_port *port, u32 *offset)
1720056057e2SMadalin Bucur {
1721056057e2SMadalin Bucur 	if (port->buffer_offsets.hash_result_offset == ILLEGAL_BASE)
1722056057e2SMadalin Bucur 		return -EINVAL;
1723056057e2SMadalin Bucur 
1724056057e2SMadalin Bucur 	*offset = port->buffer_offsets.hash_result_offset;
1725056057e2SMadalin Bucur 
1726056057e2SMadalin Bucur 	return 0;
1727056057e2SMadalin Bucur }
1728056057e2SMadalin Bucur EXPORT_SYMBOL(fman_port_get_hash_result_offset);
1729056057e2SMadalin Bucur 
fman_port_get_tstamp(struct fman_port * port,const void * data,u64 * tstamp)1730880f874cSYangbo Lu int fman_port_get_tstamp(struct fman_port *port, const void *data, u64 *tstamp)
1731880f874cSYangbo Lu {
1732880f874cSYangbo Lu 	if (port->buffer_offsets.time_stamp_offset == ILLEGAL_BASE)
1733880f874cSYangbo Lu 		return -EINVAL;
1734880f874cSYangbo Lu 
1735880f874cSYangbo Lu 	*tstamp = be64_to_cpu(*(__be64 *)(data +
1736880f874cSYangbo Lu 			port->buffer_offsets.time_stamp_offset));
1737880f874cSYangbo Lu 
1738880f874cSYangbo Lu 	return 0;
1739880f874cSYangbo Lu }
1740880f874cSYangbo Lu EXPORT_SYMBOL(fman_port_get_tstamp);
1741880f874cSYangbo Lu 
fman_port_probe(struct platform_device * of_dev)174218a6c85fSIgal Liberman static int fman_port_probe(struct platform_device *of_dev)
174318a6c85fSIgal Liberman {
174418a6c85fSIgal Liberman 	struct fman_port *port;
174518a6c85fSIgal Liberman 	struct fman *fman;
174618a6c85fSIgal Liberman 	struct device_node *fm_node, *port_node;
174705720546SFlorinel Iordache 	struct platform_device *fm_pdev;
174818a6c85fSIgal Liberman 	struct resource res;
174918a6c85fSIgal Liberman 	struct resource *dev_res;
1750537a3165SMadalin Bucur 	u32 val;
175118a6c85fSIgal Liberman 	int err = 0, lenp;
175218a6c85fSIgal Liberman 	enum fman_port_type port_type;
175318a6c85fSIgal Liberman 	u16 port_speed;
175418a6c85fSIgal Liberman 	u8 port_id;
175518a6c85fSIgal Liberman 
175618a6c85fSIgal Liberman 	port = kzalloc(sizeof(*port), GFP_KERNEL);
175718a6c85fSIgal Liberman 	if (!port)
175818a6c85fSIgal Liberman 		return -ENOMEM;
175918a6c85fSIgal Liberman 
176018a6c85fSIgal Liberman 	port->dev = &of_dev->dev;
176118a6c85fSIgal Liberman 
176218a6c85fSIgal Liberman 	port_node = of_node_get(of_dev->dev.of_node);
176318a6c85fSIgal Liberman 
176418a6c85fSIgal Liberman 	/* Get the FM node */
176518a6c85fSIgal Liberman 	fm_node = of_get_parent(port_node);
176618a6c85fSIgal Liberman 	if (!fm_node) {
176718a6c85fSIgal Liberman 		dev_err(port->dev, "%s: of_get_parent() failed\n", __func__);
176818a6c85fSIgal Liberman 		err = -ENODEV;
176918a6c85fSIgal Liberman 		goto return_err;
177018a6c85fSIgal Liberman 	}
177118a6c85fSIgal Liberman 
177205720546SFlorinel Iordache 	fm_pdev = of_find_device_by_node(fm_node);
177318a6c85fSIgal Liberman 	of_node_put(fm_node);
177405720546SFlorinel Iordache 	if (!fm_pdev) {
177505720546SFlorinel Iordache 		err = -EINVAL;
177605720546SFlorinel Iordache 		goto return_err;
177705720546SFlorinel Iordache 	}
177805720546SFlorinel Iordache 
177905720546SFlorinel Iordache 	fman = dev_get_drvdata(&fm_pdev->dev);
178018a6c85fSIgal Liberman 	if (!fman) {
178118a6c85fSIgal Liberman 		err = -EINVAL;
1782bf2b09feSMiaoqian Lin 		goto put_device;
178318a6c85fSIgal Liberman 	}
178418a6c85fSIgal Liberman 
1785537a3165SMadalin Bucur 	err = of_property_read_u32(port_node, "cell-index", &val);
1786537a3165SMadalin Bucur 	if (err) {
1787f7ce9103SRob Herring 		dev_err(port->dev, "%s: reading cell-index for %pOF failed\n",
1788f7ce9103SRob Herring 			__func__, port_node);
178918a6c85fSIgal Liberman 		err = -EINVAL;
1790bf2b09feSMiaoqian Lin 		goto put_device;
179118a6c85fSIgal Liberman 	}
1792537a3165SMadalin Bucur 	port_id = (u8)val;
179318a6c85fSIgal Liberman 	port->dts_params.id = port_id;
179418a6c85fSIgal Liberman 
179518a6c85fSIgal Liberman 	if (of_device_is_compatible(port_node, "fsl,fman-v3-port-tx")) {
179618a6c85fSIgal Liberman 		port_type = FMAN_PORT_TYPE_TX;
179718a6c85fSIgal Liberman 		port_speed = 1000;
1798537a3165SMadalin Bucur 		if (of_find_property(port_node, "fsl,fman-10g-port", &lenp))
179918a6c85fSIgal Liberman 			port_speed = 10000;
180018a6c85fSIgal Liberman 
180118a6c85fSIgal Liberman 	} else if (of_device_is_compatible(port_node, "fsl,fman-v2-port-tx")) {
180218a6c85fSIgal Liberman 		if (port_id >= TX_10G_PORT_BASE)
180318a6c85fSIgal Liberman 			port_speed = 10000;
180418a6c85fSIgal Liberman 		else
180518a6c85fSIgal Liberman 			port_speed = 1000;
180618a6c85fSIgal Liberman 		port_type = FMAN_PORT_TYPE_TX;
180718a6c85fSIgal Liberman 
180818a6c85fSIgal Liberman 	} else if (of_device_is_compatible(port_node, "fsl,fman-v3-port-rx")) {
180918a6c85fSIgal Liberman 		port_type = FMAN_PORT_TYPE_RX;
181018a6c85fSIgal Liberman 		port_speed = 1000;
1811537a3165SMadalin Bucur 		if (of_find_property(port_node, "fsl,fman-10g-port", &lenp))
181218a6c85fSIgal Liberman 			port_speed = 10000;
181318a6c85fSIgal Liberman 
181418a6c85fSIgal Liberman 	} else if (of_device_is_compatible(port_node, "fsl,fman-v2-port-rx")) {
181518a6c85fSIgal Liberman 		if (port_id >= RX_10G_PORT_BASE)
181618a6c85fSIgal Liberman 			port_speed = 10000;
181718a6c85fSIgal Liberman 		else
181818a6c85fSIgal Liberman 			port_speed = 1000;
181918a6c85fSIgal Liberman 		port_type = FMAN_PORT_TYPE_RX;
182018a6c85fSIgal Liberman 
182118a6c85fSIgal Liberman 	}  else {
182218a6c85fSIgal Liberman 		dev_err(port->dev, "%s: Illegal port type\n", __func__);
182318a6c85fSIgal Liberman 		err = -EINVAL;
1824bf2b09feSMiaoqian Lin 		goto put_device;
182518a6c85fSIgal Liberman 	}
182618a6c85fSIgal Liberman 
182718a6c85fSIgal Liberman 	port->dts_params.type = port_type;
182818a6c85fSIgal Liberman 	port->dts_params.speed = port_speed;
182918a6c85fSIgal Liberman 
183018a6c85fSIgal Liberman 	if (port_type == FMAN_PORT_TYPE_TX) {
183118a6c85fSIgal Liberman 		u32 qman_channel_id;
183218a6c85fSIgal Liberman 
183318a6c85fSIgal Liberman 		qman_channel_id = fman_get_qman_channel_id(fman, port_id);
183418a6c85fSIgal Liberman 		if (qman_channel_id == 0) {
183518a6c85fSIgal Liberman 			dev_err(port->dev, "%s: incorrect qman-channel-id\n",
183618a6c85fSIgal Liberman 				__func__);
183718a6c85fSIgal Liberman 			err = -EINVAL;
1838bf2b09feSMiaoqian Lin 			goto put_device;
183918a6c85fSIgal Liberman 		}
184018a6c85fSIgal Liberman 		port->dts_params.qman_channel_id = qman_channel_id;
184118a6c85fSIgal Liberman 	}
184218a6c85fSIgal Liberman 
184318a6c85fSIgal Liberman 	err = of_address_to_resource(port_node, 0, &res);
184418a6c85fSIgal Liberman 	if (err < 0) {
184518a6c85fSIgal Liberman 		dev_err(port->dev, "%s: of_address_to_resource() failed\n",
184618a6c85fSIgal Liberman 			__func__);
184718a6c85fSIgal Liberman 		err = -ENOMEM;
1848bf2b09feSMiaoqian Lin 		goto put_device;
184918a6c85fSIgal Liberman 	}
185018a6c85fSIgal Liberman 
185118a6c85fSIgal Liberman 	port->dts_params.fman = fman;
185218a6c85fSIgal Liberman 
185318a6c85fSIgal Liberman 	of_node_put(port_node);
185418a6c85fSIgal Liberman 
185518a6c85fSIgal Liberman 	dev_res = __devm_request_region(port->dev, &res, res.start,
185618a6c85fSIgal Liberman 					resource_size(&res), "fman-port");
185718a6c85fSIgal Liberman 	if (!dev_res) {
185818a6c85fSIgal Liberman 		dev_err(port->dev, "%s: __devm_request_region() failed\n",
185918a6c85fSIgal Liberman 			__func__);
186018a6c85fSIgal Liberman 		err = -EINVAL;
186118a6c85fSIgal Liberman 		goto free_port;
186218a6c85fSIgal Liberman 	}
186318a6c85fSIgal Liberman 
186418a6c85fSIgal Liberman 	port->dts_params.base_addr = devm_ioremap(port->dev, res.start,
186518a6c85fSIgal Liberman 						  resource_size(&res));
18665df6f7faSMadalin Bucur 	if (!port->dts_params.base_addr)
186718a6c85fSIgal Liberman 		dev_err(port->dev, "%s: devm_ioremap() failed\n", __func__);
186818a6c85fSIgal Liberman 
186918a6c85fSIgal Liberman 	dev_set_drvdata(&of_dev->dev, port);
187018a6c85fSIgal Liberman 
187118a6c85fSIgal Liberman 	return 0;
187218a6c85fSIgal Liberman 
1873bf2b09feSMiaoqian Lin put_device:
1874bf2b09feSMiaoqian Lin 	put_device(&fm_pdev->dev);
187518a6c85fSIgal Liberman return_err:
187618a6c85fSIgal Liberman 	of_node_put(port_node);
187718a6c85fSIgal Liberman free_port:
187818a6c85fSIgal Liberman 	kfree(port);
187918a6c85fSIgal Liberman 	return err;
188018a6c85fSIgal Liberman }
188118a6c85fSIgal Liberman 
188218a6c85fSIgal Liberman static const struct of_device_id fman_port_match[] = {
188318a6c85fSIgal Liberman 	{.compatible = "fsl,fman-v3-port-rx"},
188418a6c85fSIgal Liberman 	{.compatible = "fsl,fman-v2-port-rx"},
188518a6c85fSIgal Liberman 	{.compatible = "fsl,fman-v3-port-tx"},
188618a6c85fSIgal Liberman 	{.compatible = "fsl,fman-v2-port-tx"},
188718a6c85fSIgal Liberman 	{}
188818a6c85fSIgal Liberman };
188918a6c85fSIgal Liberman 
189018a6c85fSIgal Liberman MODULE_DEVICE_TABLE(of, fman_port_match);
189118a6c85fSIgal Liberman 
189218a6c85fSIgal Liberman static struct platform_driver fman_port_driver = {
189318a6c85fSIgal Liberman 	.driver = {
189418a6c85fSIgal Liberman 		.name = "fsl-fman-port",
189518a6c85fSIgal Liberman 		.of_match_table = fman_port_match,
189618a6c85fSIgal Liberman 	},
189718a6c85fSIgal Liberman 	.probe = fman_port_probe,
189818a6c85fSIgal Liberman };
189918a6c85fSIgal Liberman 
fman_port_load(void)190029c4684eSIgal Liberman static int __init fman_port_load(void)
190129c4684eSIgal Liberman {
190229c4684eSIgal Liberman 	int err;
190329c4684eSIgal Liberman 
190429c4684eSIgal Liberman 	pr_debug("FSL DPAA FMan driver\n");
190529c4684eSIgal Liberman 
190629c4684eSIgal Liberman 	err = platform_driver_register(&fman_port_driver);
190729c4684eSIgal Liberman 	if (err < 0)
190829c4684eSIgal Liberman 		pr_err("Error, platform_driver_register() = %d\n", err);
190929c4684eSIgal Liberman 
191029c4684eSIgal Liberman 	return err;
191129c4684eSIgal Liberman }
191229c4684eSIgal Liberman module_init(fman_port_load);
191329c4684eSIgal Liberman 
fman_port_unload(void)191429c4684eSIgal Liberman static void __exit fman_port_unload(void)
191529c4684eSIgal Liberman {
191629c4684eSIgal Liberman 	platform_driver_unregister(&fman_port_driver);
191729c4684eSIgal Liberman }
191829c4684eSIgal Liberman module_exit(fman_port_unload);
191929c4684eSIgal Liberman 
192029c4684eSIgal Liberman MODULE_LICENSE("Dual BSD/GPL");
192129c4684eSIgal Liberman MODULE_DESCRIPTION("Freescale DPAA Frame Manager Port driver");
1922