1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018-2019 NXP
5 #ifndef _PFE_HIF_LIB_H_
6 #define _PFE_HIF_LIB_H_
10 #define HIF_CL_REQ_TIMEOUT 10
14 REQUEST_CL_REGISTER = 0,
15 REQUEST_CL_UNREGISTER,
20 /* Event to indicate that client rx queue is reached water mark level */
22 /* Event to indicate that, packet received for client */
24 /* Event to indicate that, packet tx done for client */
29 /*structure to store client queue info */
31 /*structure to store client queue info */
32 struct hif_client_rx_queue {
33 struct rx_queue_desc *base;
42 struct hif_client_tx_queue {
43 struct tx_queue_desc *base;
48 unsigned long jiffies_last_packet;
67 struct hif_client_tx_queue tx_q[HIF_CLIENT_QUEUES_MAX];
68 struct hif_client_rx_queue rx_q[HIF_CLIENT_QUEUES_MAX];
69 int (*event_handler)(void *data, int event, int qno);
70 unsigned long queue_mask[HIF_EVENT_MAX];
76 * Client specific shared memory
77 * It contains number of Rx/Tx queues, base addresses and queue sizes
79 struct hif_client_shm {
80 u32 ctrl; /*0-7: number of Rx queues, 8-15: number of tx queues */
81 unsigned long rx_qbase; /*Rx queue base address */
82 u32 rx_qsize; /*each Rx queue size, all Rx queues are of same size */
83 unsigned long tx_qbase; /* Tx queue base address */
84 u32 tx_qsize; /*each Tx queue size, all Tx queues are of same size */
87 /*Client shared memory ctrl bit description */
88 #define CLIENT_CTRL_RX_Q_CNT_OFST 0
89 #define CLIENT_CTRL_TX_Q_CNT_OFST 8
90 #define CLIENT_CTRL_RX_Q_CNT(ctrl) (((ctrl) >> CLIENT_CTRL_RX_Q_CNT_OFST) \
92 #define CLIENT_CTRL_TX_Q_CNT(ctrl) (((ctrl) >> CLIENT_CTRL_TX_Q_CNT_OFST) \
96 * Shared memory used to communicate between HIF driver and host/client drivers
97 * Before starting the hif driver rx_buf_pool ans rx_buf_pool_cnt should be
98 * initialized with host buffers and buffers count in the pool.
99 * rx_buf_pool_cnt should be >= HIF_RX_DESC_NT.
103 u32 rx_buf_pool_cnt; /*Number of rx buffers available*/
104 /*Rx buffers required to initialize HIF rx descriptors */
105 struct rte_mempool *pool;
106 void *rx_buf_pool[HIF_RX_DESC_NT];
107 unsigned long g_client_status[2]; /*Global client status bit mask */
108 /* Client specific shared memory */
109 struct hif_client_shm client[HIF_CLIENTS_MAX];
112 #define CL_DESC_OWN BIT(31)
113 /* This sets owner ship to HIF driver */
114 #define CL_DESC_LAST BIT(30)
115 /* This indicates last packet for multi buffers handling */
116 #define CL_DESC_FIRST BIT(29)
117 /* This indicates first packet for multi buffers handling */
119 #define CL_DESC_BUF_LEN(x) ((x) & 0xFFFF)
120 #define CL_DESC_FLAGS(x) (((x) & 0xF) << 16)
121 #define CL_DESC_GET_FLAGS(x) (((x) >> 16) & 0xF)
123 struct rx_queue_desc {
125 u32 ctrl; /*0-15bit len, 16-20bit flags, 31bit owner*/
129 struct tx_queue_desc {
131 u32 ctrl; /*0-15bit len, 16-20bit flags, 31bit owner*/
134 /* HIF Rx is not working properly for 2-byte aligned buffers and
135 * ip_header should be 4byte aligned for better iperformance.
136 * "ip_header = 64 + 6(hif_header) + 14 (MAC Header)" will be 4byte aligned.
137 * In case HW parse support:
138 * "ip_header = 64 + 6(hif_header) + 16 (parse) + 14 (MAC Header)" will be
141 #define PFE_HIF_SIZE sizeof(struct hif_hdr)
143 #ifdef RTE_LIBRTE_PFE_SW_PARSE
144 #define PFE_PKT_HEADER_SZ PFE_HIF_SIZE
146 #define PFE_PKT_HEADER_SZ (PFE_HIF_SIZE + sizeof(struct pfe_parse))
149 #define MAX_L2_HDR_SIZE 14 /* Not correct for VLAN/PPPoE */
150 #define MAX_L3_HDR_SIZE 20 /* Not correct for IPv6 */
151 #define MAX_L4_HDR_SIZE 60 /* TCP with maximum options */
152 #define MAX_HDR_SIZE (MAX_L2_HDR_SIZE + MAX_L3_HDR_SIZE \
154 /* Used in page mode to clamp packet size to the maximum supported by the hif
155 *hw interface (<16KiB)
157 #define MAX_PFE_PKT_SIZE 16380UL
159 extern unsigned int emac_txq_cnt;
161 int pfe_hif_lib_init(struct pfe *pfe);
162 void pfe_hif_lib_exit(struct pfe *pfe);
163 int hif_lib_client_register(struct hif_client_s *client);
164 int hif_lib_client_unregister(struct hif_client_s *client);
165 void hif_lib_xmit_pkt(struct hif_client_s *client, unsigned int qno,
166 void *data, void *data1, unsigned int len,
167 u32 client_ctrl, unsigned int flags, void *client_data);
168 void hif_lib_indicate_client(struct hif_client_s *client, int event, int data);
169 int hif_lib_event_handler_start(struct hif_client_s *client, int event, int
171 void *hif_lib_tx_get_next_complete(struct hif_client_s *client, int qno,
172 unsigned int *flags, int count);
173 int pfe_hif_shm_init(struct hif_shm *hif_shm, struct rte_mempool *mb_pool);
174 void pfe_hif_shm_clean(struct hif_shm *hif_shm);
176 int hif_lib_receive_pkt(struct hif_client_rx_queue *queue,
177 struct rte_mempool *pool,
178 struct rte_mbuf **rx_pkts,
181 #endif /* _PFE_HIF_LIB_H_ */