net/pfe: add MAC and host interface initialisation
[dpdk.git] / drivers / net / pfe / pfe_hif_lib.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2019 NXP
3  */
4
5 #ifndef _PFE_HIF_LIB_H_
6 #define _PFE_HIF_LIB_H_
7
8 #define HIF_CL_REQ_TIMEOUT      10
9 #define GFP_DMA_PFE 0
10
11 enum {
12         REQUEST_CL_REGISTER = 0,
13         REQUEST_CL_UNREGISTER,
14         HIF_REQUEST_MAX
15 };
16
17 enum {
18         /* Event to indicate that client rx queue is reached water mark level */
19         EVENT_HIGH_RX_WM = 0,
20         /* Event to indicate that, packet received for client */
21         EVENT_RX_PKT_IND,
22         /* Event to indicate that, packet tx done for client */
23         EVENT_TXDONE_IND,
24         HIF_EVENT_MAX
25 };
26
27 /*structure to store client queue info */
28
29 /*structure to store client queue info */
30 struct hif_client_rx_queue {
31         struct rx_queue_desc *base;
32         u32     size;
33         u32     read_idx;
34         u32     write_idx;
35         u16     queue_id;
36         u16     port_id;
37         void   *priv;
38 };
39
40 struct hif_client_tx_queue {
41         struct tx_queue_desc *base;
42         u32     size;
43         u32     read_idx;
44         u32     write_idx;
45         u32     tx_pending;
46         unsigned long jiffies_last_packet;
47         u32     nocpy_flag;
48         u32     prev_tmu_tx_pkts;
49         u32     done_tmu_tx_pkts;
50         u16     queue_id;
51         u16     port_id;
52         void   *priv;
53 };
54
55 struct hif_client_s {
56         int     id;
57         unsigned int    tx_qn;
58         unsigned int    rx_qn;
59         void    *rx_qbase;
60         void    *tx_qbase;
61         int     tx_qsize;
62         int     rx_qsize;
63         int     cpu_id;
64         int     port_id;
65         struct hif_client_tx_queue tx_q[HIF_CLIENT_QUEUES_MAX];
66         struct hif_client_rx_queue rx_q[HIF_CLIENT_QUEUES_MAX];
67         int (*event_handler)(void *data, int event, int qno);
68         unsigned long queue_mask[HIF_EVENT_MAX];
69         struct pfe *pfe;
70         void *priv;
71 };
72
73 /*
74  * Client specific shared memory
75  * It contains number of Rx/Tx queues, base addresses and queue sizes
76  */
77 struct hif_client_shm {
78         u32 ctrl; /*0-7: number of Rx queues, 8-15: number of tx queues */
79         unsigned long rx_qbase; /*Rx queue base address */
80         u32 rx_qsize; /*each Rx queue size, all Rx queues are of same size */
81         unsigned long tx_qbase; /* Tx queue base address */
82         u32 tx_qsize; /*each Tx queue size, all Tx queues are of same size */
83 };
84
85 /*Client shared memory ctrl bit description */
86 #define CLIENT_CTRL_RX_Q_CNT_OFST       0
87 #define CLIENT_CTRL_TX_Q_CNT_OFST       8
88 #define CLIENT_CTRL_RX_Q_CNT(ctrl)      (((ctrl) >> CLIENT_CTRL_RX_Q_CNT_OFST) \
89                                                 & 0xFF)
90 #define CLIENT_CTRL_TX_Q_CNT(ctrl)      (((ctrl) >> CLIENT_CTRL_TX_Q_CNT_OFST) \
91                                                 & 0xFF)
92
93 /*
94  * Shared memory used to communicate between HIF driver and host/client drivers
95  * Before starting the hif driver rx_buf_pool ans rx_buf_pool_cnt should be
96  * initialized with host buffers and buffers count in the pool.
97  * rx_buf_pool_cnt should be >= HIF_RX_DESC_NT.
98  *
99  */
100 struct hif_shm {
101         u32 rx_buf_pool_cnt; /*Number of rx buffers available*/
102         /*Rx buffers required to initialize HIF rx descriptors */
103         struct rte_mempool *pool;
104         void *rx_buf_pool[HIF_RX_DESC_NT];
105         unsigned long g_client_status[2]; /*Global client status bit mask */
106         /* Client specific shared memory */
107         struct hif_client_shm client[HIF_CLIENTS_MAX];
108 };
109
110 #define CL_DESC_OWN     BIT(31)
111 /* This sets owner ship to HIF driver */
112 #define CL_DESC_LAST    BIT(30)
113 /* This indicates last packet for multi buffers handling */
114 #define CL_DESC_FIRST   BIT(29)
115 /* This indicates first packet for multi buffers handling */
116
117 #define CL_DESC_BUF_LEN(x)              ((x) & 0xFFFF)
118 #define CL_DESC_FLAGS(x)                (((x) & 0xF) << 16)
119 #define CL_DESC_GET_FLAGS(x)            (((x) >> 16) & 0xF)
120
121 struct rx_queue_desc {
122         void *data;
123         u32     ctrl; /*0-15bit len, 16-20bit flags, 31bit owner*/
124         u32     client_ctrl;
125 };
126
127 struct tx_queue_desc {
128         void *data;
129         u32     ctrl; /*0-15bit len, 16-20bit flags, 31bit owner*/
130 };
131
132 /* HIF Rx is not working properly for 2-byte aligned buffers and
133  * ip_header should be 4byte aligned for better iperformance.
134  * "ip_header = 64 + 6(hif_header) + 14 (MAC Header)" will be 4byte aligned.
135  * In case HW parse support:
136  * "ip_header = 64 + 6(hif_header) + 16 (parse) + 14 (MAC Header)" will be
137  * 4byte aligned.
138  */
139 #define PFE_HIF_SIZE            sizeof(struct hif_hdr)
140
141 #ifdef RTE_LIBRTE_PFE_SW_PARSE
142 #define PFE_PKT_HEADER_SZ       PFE_HIF_SIZE
143 #else
144 #define PFE_PKT_HEADER_SZ       (PFE_HIF_SIZE + sizeof(struct pfe_parse))
145 #endif
146
147 #define MAX_L2_HDR_SIZE         14      /* Not correct for VLAN/PPPoE */
148 #define MAX_L3_HDR_SIZE         20      /* Not correct for IPv6 */
149 #define MAX_L4_HDR_SIZE         60      /* TCP with maximum options */
150 #define MAX_HDR_SIZE            (MAX_L2_HDR_SIZE + MAX_L3_HDR_SIZE \
151                                  + MAX_L4_HDR_SIZE)
152 /* Used in page mode to clamp packet size to the maximum supported by the hif
153  *hw interface (<16KiB)
154  */
155 #define MAX_PFE_PKT_SIZE        16380UL
156
157 extern unsigned int emac_txq_cnt;
158
159 int pfe_hif_lib_init(struct pfe *pfe);
160 void pfe_hif_lib_exit(struct pfe *pfe);
161
162 #endif /* _PFE_HIF_LIB_H_ */