xref: /dpdk/drivers/net/pfe/pfe_hif_lib.h (revision f513f620591370c7b10f43fc7baa2e258d2f428d)
15253fe37SGagandeep Singh /* SPDX-License-Identifier: BSD-3-Clause
2*f513f620SSachin Saxena  * Copyright 2018-2019 NXP
35253fe37SGagandeep Singh  */
45253fe37SGagandeep Singh 
55253fe37SGagandeep Singh #ifndef _PFE_HIF_LIB_H_
65253fe37SGagandeep Singh #define _PFE_HIF_LIB_H_
75253fe37SGagandeep Singh 
8fe38ad9bSGagandeep Singh #include "pfe_hif.h"
9fe38ad9bSGagandeep Singh 
105253fe37SGagandeep Singh #define HIF_CL_REQ_TIMEOUT	10
115253fe37SGagandeep Singh #define GFP_DMA_PFE 0
125253fe37SGagandeep Singh 
135253fe37SGagandeep Singh enum {
145253fe37SGagandeep Singh 	REQUEST_CL_REGISTER = 0,
155253fe37SGagandeep Singh 	REQUEST_CL_UNREGISTER,
165253fe37SGagandeep Singh 	HIF_REQUEST_MAX
175253fe37SGagandeep Singh };
185253fe37SGagandeep Singh 
195253fe37SGagandeep Singh enum {
205253fe37SGagandeep Singh 	/* Event to indicate that client rx queue is reached water mark level */
215253fe37SGagandeep Singh 	EVENT_HIGH_RX_WM = 0,
225253fe37SGagandeep Singh 	/* Event to indicate that, packet received for client */
235253fe37SGagandeep Singh 	EVENT_RX_PKT_IND,
245253fe37SGagandeep Singh 	/* Event to indicate that, packet tx done for client */
255253fe37SGagandeep Singh 	EVENT_TXDONE_IND,
265253fe37SGagandeep Singh 	HIF_EVENT_MAX
275253fe37SGagandeep Singh };
285253fe37SGagandeep Singh 
295253fe37SGagandeep Singh /*structure to store client queue info */
305253fe37SGagandeep Singh 
315253fe37SGagandeep Singh /*structure to store client queue info */
325253fe37SGagandeep Singh struct hif_client_rx_queue {
335253fe37SGagandeep Singh 	struct rx_queue_desc *base;
345253fe37SGagandeep Singh 	u32	size;
355253fe37SGagandeep Singh 	u32	read_idx;
365253fe37SGagandeep Singh 	u32	write_idx;
375253fe37SGagandeep Singh 	u16	queue_id;
385253fe37SGagandeep Singh 	u16	port_id;
395253fe37SGagandeep Singh 	void   *priv;
405253fe37SGagandeep Singh };
415253fe37SGagandeep Singh 
425253fe37SGagandeep Singh struct hif_client_tx_queue {
435253fe37SGagandeep Singh 	struct tx_queue_desc *base;
445253fe37SGagandeep Singh 	u32	size;
455253fe37SGagandeep Singh 	u32	read_idx;
465253fe37SGagandeep Singh 	u32	write_idx;
475253fe37SGagandeep Singh 	u32	tx_pending;
485253fe37SGagandeep Singh 	unsigned long jiffies_last_packet;
495253fe37SGagandeep Singh 	u32	nocpy_flag;
505253fe37SGagandeep Singh 	u32	prev_tmu_tx_pkts;
515253fe37SGagandeep Singh 	u32	done_tmu_tx_pkts;
525253fe37SGagandeep Singh 	u16	queue_id;
535253fe37SGagandeep Singh 	u16	port_id;
545253fe37SGagandeep Singh 	void   *priv;
555253fe37SGagandeep Singh };
565253fe37SGagandeep Singh 
575253fe37SGagandeep Singh struct hif_client_s {
585253fe37SGagandeep Singh 	int	id;
595253fe37SGagandeep Singh 	unsigned int	tx_qn;
605253fe37SGagandeep Singh 	unsigned int	rx_qn;
615253fe37SGagandeep Singh 	void	*rx_qbase;
625253fe37SGagandeep Singh 	void	*tx_qbase;
635253fe37SGagandeep Singh 	int	tx_qsize;
645253fe37SGagandeep Singh 	int	rx_qsize;
655253fe37SGagandeep Singh 	int	cpu_id;
665253fe37SGagandeep Singh 	int	port_id;
675253fe37SGagandeep Singh 	struct hif_client_tx_queue tx_q[HIF_CLIENT_QUEUES_MAX];
685253fe37SGagandeep Singh 	struct hif_client_rx_queue rx_q[HIF_CLIENT_QUEUES_MAX];
695253fe37SGagandeep Singh 	int (*event_handler)(void *data, int event, int qno);
705253fe37SGagandeep Singh 	unsigned long queue_mask[HIF_EVENT_MAX];
715253fe37SGagandeep Singh 	struct pfe *pfe;
725253fe37SGagandeep Singh 	void *priv;
735253fe37SGagandeep Singh };
745253fe37SGagandeep Singh 
755253fe37SGagandeep Singh /*
765253fe37SGagandeep Singh  * Client specific shared memory
775253fe37SGagandeep Singh  * It contains number of Rx/Tx queues, base addresses and queue sizes
785253fe37SGagandeep Singh  */
795253fe37SGagandeep Singh struct hif_client_shm {
805253fe37SGagandeep Singh 	u32 ctrl; /*0-7: number of Rx queues, 8-15: number of tx queues */
815253fe37SGagandeep Singh 	unsigned long rx_qbase; /*Rx queue base address */
825253fe37SGagandeep Singh 	u32 rx_qsize; /*each Rx queue size, all Rx queues are of same size */
835253fe37SGagandeep Singh 	unsigned long tx_qbase; /* Tx queue base address */
845253fe37SGagandeep Singh 	u32 tx_qsize; /*each Tx queue size, all Tx queues are of same size */
855253fe37SGagandeep Singh };
865253fe37SGagandeep Singh 
875253fe37SGagandeep Singh /*Client shared memory ctrl bit description */
885253fe37SGagandeep Singh #define CLIENT_CTRL_RX_Q_CNT_OFST	0
895253fe37SGagandeep Singh #define CLIENT_CTRL_TX_Q_CNT_OFST	8
905253fe37SGagandeep Singh #define CLIENT_CTRL_RX_Q_CNT(ctrl)	(((ctrl) >> CLIENT_CTRL_RX_Q_CNT_OFST) \
915253fe37SGagandeep Singh 						& 0xFF)
925253fe37SGagandeep Singh #define CLIENT_CTRL_TX_Q_CNT(ctrl)	(((ctrl) >> CLIENT_CTRL_TX_Q_CNT_OFST) \
935253fe37SGagandeep Singh 						& 0xFF)
945253fe37SGagandeep Singh 
955253fe37SGagandeep Singh /*
965253fe37SGagandeep Singh  * Shared memory used to communicate between HIF driver and host/client drivers
975253fe37SGagandeep Singh  * Before starting the hif driver rx_buf_pool ans rx_buf_pool_cnt should be
985253fe37SGagandeep Singh  * initialized with host buffers and buffers count in the pool.
995253fe37SGagandeep Singh  * rx_buf_pool_cnt should be >= HIF_RX_DESC_NT.
1005253fe37SGagandeep Singh  *
1015253fe37SGagandeep Singh  */
1025253fe37SGagandeep Singh struct hif_shm {
1035253fe37SGagandeep Singh 	u32 rx_buf_pool_cnt; /*Number of rx buffers available*/
1045253fe37SGagandeep Singh 	/*Rx buffers required to initialize HIF rx descriptors */
1055253fe37SGagandeep Singh 	struct rte_mempool *pool;
1065253fe37SGagandeep Singh 	void *rx_buf_pool[HIF_RX_DESC_NT];
1075253fe37SGagandeep Singh 	unsigned long g_client_status[2]; /*Global client status bit mask */
1085253fe37SGagandeep Singh 	/* Client specific shared memory */
1095253fe37SGagandeep Singh 	struct hif_client_shm client[HIF_CLIENTS_MAX];
1105253fe37SGagandeep Singh };
1115253fe37SGagandeep Singh 
1125253fe37SGagandeep Singh #define CL_DESC_OWN	BIT(31)
1135253fe37SGagandeep Singh /* This sets owner ship to HIF driver */
1145253fe37SGagandeep Singh #define CL_DESC_LAST	BIT(30)
1155253fe37SGagandeep Singh /* This indicates last packet for multi buffers handling */
1165253fe37SGagandeep Singh #define CL_DESC_FIRST	BIT(29)
1175253fe37SGagandeep Singh /* This indicates first packet for multi buffers handling */
1185253fe37SGagandeep Singh 
1195253fe37SGagandeep Singh #define CL_DESC_BUF_LEN(x)		((x) & 0xFFFF)
1205253fe37SGagandeep Singh #define CL_DESC_FLAGS(x)		(((x) & 0xF) << 16)
1215253fe37SGagandeep Singh #define CL_DESC_GET_FLAGS(x)		(((x) >> 16) & 0xF)
1225253fe37SGagandeep Singh 
1235253fe37SGagandeep Singh struct rx_queue_desc {
1245253fe37SGagandeep Singh 	void *data;
1255253fe37SGagandeep Singh 	u32	ctrl; /*0-15bit len, 16-20bit flags, 31bit owner*/
1265253fe37SGagandeep Singh 	u32	client_ctrl;
1275253fe37SGagandeep Singh };
1285253fe37SGagandeep Singh 
1295253fe37SGagandeep Singh struct tx_queue_desc {
1305253fe37SGagandeep Singh 	void *data;
1315253fe37SGagandeep Singh 	u32	ctrl; /*0-15bit len, 16-20bit flags, 31bit owner*/
1325253fe37SGagandeep Singh };
1335253fe37SGagandeep Singh 
1345253fe37SGagandeep Singh /* HIF Rx is not working properly for 2-byte aligned buffers and
1355253fe37SGagandeep Singh  * ip_header should be 4byte aligned for better iperformance.
1365253fe37SGagandeep Singh  * "ip_header = 64 + 6(hif_header) + 14 (MAC Header)" will be 4byte aligned.
1375253fe37SGagandeep Singh  * In case HW parse support:
1385253fe37SGagandeep Singh  * "ip_header = 64 + 6(hif_header) + 16 (parse) + 14 (MAC Header)" will be
1395253fe37SGagandeep Singh  * 4byte aligned.
1405253fe37SGagandeep Singh  */
1415253fe37SGagandeep Singh #define PFE_HIF_SIZE		sizeof(struct hif_hdr)
1425253fe37SGagandeep Singh 
1435253fe37SGagandeep Singh #ifdef RTE_LIBRTE_PFE_SW_PARSE
1445253fe37SGagandeep Singh #define PFE_PKT_HEADER_SZ	PFE_HIF_SIZE
1455253fe37SGagandeep Singh #else
1465253fe37SGagandeep Singh #define PFE_PKT_HEADER_SZ	(PFE_HIF_SIZE + sizeof(struct pfe_parse))
1475253fe37SGagandeep Singh #endif
1485253fe37SGagandeep Singh 
1495253fe37SGagandeep Singh #define MAX_L2_HDR_SIZE		14	/* Not correct for VLAN/PPPoE */
1505253fe37SGagandeep Singh #define MAX_L3_HDR_SIZE		20	/* Not correct for IPv6 */
1515253fe37SGagandeep Singh #define MAX_L4_HDR_SIZE		60	/* TCP with maximum options */
1525253fe37SGagandeep Singh #define MAX_HDR_SIZE		(MAX_L2_HDR_SIZE + MAX_L3_HDR_SIZE \
1535253fe37SGagandeep Singh 				 + MAX_L4_HDR_SIZE)
1545253fe37SGagandeep Singh /* Used in page mode to clamp packet size to the maximum supported by the hif
1555253fe37SGagandeep Singh  *hw interface (<16KiB)
1565253fe37SGagandeep Singh  */
1575253fe37SGagandeep Singh #define MAX_PFE_PKT_SIZE	16380UL
1585253fe37SGagandeep Singh 
1595253fe37SGagandeep Singh extern unsigned int emac_txq_cnt;
1605253fe37SGagandeep Singh 
1615253fe37SGagandeep Singh int pfe_hif_lib_init(struct pfe *pfe);
1625253fe37SGagandeep Singh void pfe_hif_lib_exit(struct pfe *pfe);
163fe38ad9bSGagandeep Singh int hif_lib_client_register(struct hif_client_s *client);
164fe38ad9bSGagandeep Singh int hif_lib_client_unregister(struct  hif_client_s *client);
16536220514SGagandeep Singh void hif_lib_xmit_pkt(struct hif_client_s *client, unsigned int qno,
16636220514SGagandeep Singh 			void *data, void *data1, unsigned int len,
16736220514SGagandeep Singh 			u32 client_ctrl, unsigned int flags, void *client_data);
168fe38ad9bSGagandeep Singh void hif_lib_indicate_client(struct hif_client_s *client, int event, int data);
169fe38ad9bSGagandeep Singh int hif_lib_event_handler_start(struct hif_client_s *client, int event, int
170fe38ad9bSGagandeep Singh 					data);
171fe38ad9bSGagandeep Singh void *hif_lib_tx_get_next_complete(struct hif_client_s *client, int qno,
172fe38ad9bSGagandeep Singh 				   unsigned int *flags, int count);
173fe38ad9bSGagandeep Singh int pfe_hif_shm_init(struct hif_shm *hif_shm, struct rte_mempool *mb_pool);
174fe38ad9bSGagandeep Singh void pfe_hif_shm_clean(struct hif_shm *hif_shm);
1755253fe37SGagandeep Singh 
17636220514SGagandeep Singh int hif_lib_receive_pkt(struct hif_client_rx_queue *queue,
17736220514SGagandeep Singh 			     struct rte_mempool *pool,
17836220514SGagandeep Singh 			     struct rte_mbuf **rx_pkts,
17936220514SGagandeep Singh 			     uint16_t nb_pkts);
18036220514SGagandeep Singh 
1815253fe37SGagandeep Singh #endif /* _PFE_HIF_LIB_H_ */
182