blob: f4a008f41a1f25a439f9f5cf647c1d2866dfb6ef [file] [log] [blame]
Aaron Williams4fd1e552021-04-23 19:56:32 +02001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2020 Marvell International Ltd.
4 *
5 * Interface to the hardware Input Packet Data unit.
6 */
7
8#ifndef __CVMX_IPD_H__
9#define __CVMX_IPD_H__
10
11#include "cvmx-pki.h"
12
13/* CSR typedefs have been moved to cvmx-ipd-defs.h */
14
15typedef cvmx_ipd_1st_mbuff_skip_t cvmx_ipd_mbuff_not_first_skip_t;
16typedef cvmx_ipd_1st_next_ptr_back_t cvmx_ipd_second_next_ptr_back_t;
17
18typedef struct cvmx_ipd_tag_fields {
19 u64 ipv6_src_ip : 1;
20 u64 ipv6_dst_ip : 1;
21 u64 ipv6_src_port : 1;
22 u64 ipv6_dst_port : 1;
23 u64 ipv6_next_header : 1;
24 u64 ipv4_src_ip : 1;
25 u64 ipv4_dst_ip : 1;
26 u64 ipv4_src_port : 1;
27 u64 ipv4_dst_port : 1;
28 u64 ipv4_protocol : 1;
29 u64 input_port : 1;
30} cvmx_ipd_tag_fields_t;
31
32typedef struct cvmx_pip_port_config {
33 u64 parse_mode;
34 u64 tag_type;
35 u64 tag_mode;
36 cvmx_ipd_tag_fields_t tag_fields;
37} cvmx_pip_port_config_t;
38
39typedef struct cvmx_ipd_config_struct {
40 u64 first_mbuf_skip;
41 u64 not_first_mbuf_skip;
42 u64 ipd_enable;
43 u64 enable_len_M8_fix;
44 u64 cache_mode;
45 cvmx_fpa_pool_config_t packet_pool;
46 cvmx_fpa_pool_config_t wqe_pool;
47 cvmx_pip_port_config_t port_config;
48} cvmx_ipd_config_t;
49
50extern cvmx_ipd_config_t cvmx_ipd_cfg;
51
52/**
53 * Gets the fpa pool number of packet pool
54 */
55static inline s64 cvmx_fpa_get_packet_pool(void)
56{
57 return (cvmx_ipd_cfg.packet_pool.pool_num);
58}
59
60/**
61 * Gets the buffer size of packet pool buffer
62 */
63static inline u64 cvmx_fpa_get_packet_pool_block_size(void)
64{
65 return (cvmx_ipd_cfg.packet_pool.buffer_size);
66}
67
68/**
69 * Gets the buffer count of packet pool
70 */
71static inline u64 cvmx_fpa_get_packet_pool_buffer_count(void)
72{
73 return (cvmx_ipd_cfg.packet_pool.buffer_count);
74}
75
76/**
77 * Gets the fpa pool number of wqe pool
78 */
79static inline s64 cvmx_fpa_get_wqe_pool(void)
80{
81 return (cvmx_ipd_cfg.wqe_pool.pool_num);
82}
83
84/**
85 * Gets the buffer size of wqe pool buffer
86 */
87static inline u64 cvmx_fpa_get_wqe_pool_block_size(void)
88{
89 return (cvmx_ipd_cfg.wqe_pool.buffer_size);
90}
91
92/**
93 * Gets the buffer count of wqe pool
94 */
95static inline u64 cvmx_fpa_get_wqe_pool_buffer_count(void)
96{
97 return (cvmx_ipd_cfg.wqe_pool.buffer_count);
98}
99
100/**
101 * Sets the ipd related configuration in internal structure which is then used
102 * for seting IPD hardware block
103 */
104int cvmx_ipd_set_config(cvmx_ipd_config_t ipd_config);
105
106/**
107 * Gets the ipd related configuration from internal structure.
108 */
109void cvmx_ipd_get_config(cvmx_ipd_config_t *ipd_config);
110
111/**
112 * Sets the internal FPA pool data structure for packet buffer pool.
113 * @param pool fpa pool number yo use
114 * @param buffer_size buffer size of pool
115 * @param buffer_count number of buufers to allocate to pool
116 */
117void cvmx_ipd_set_packet_pool_config(s64 pool, u64 buffer_size, u64 buffer_count);
118
119/**
120 * Sets the internal FPA pool data structure for wqe pool.
121 * @param pool fpa pool number yo use
122 * @param buffer_size buffer size of pool
123 * @param buffer_count number of buufers to allocate to pool
124 */
125void cvmx_ipd_set_wqe_pool_config(s64 pool, u64 buffer_size, u64 buffer_count);
126
127/**
128 * Gets the FPA packet buffer pool parameters.
129 */
130static inline void cvmx_fpa_get_packet_pool_config(s64 *pool, u64 *buffer_size, u64 *buffer_count)
131{
132 if (pool)
133 *pool = cvmx_ipd_cfg.packet_pool.pool_num;
134 if (buffer_size)
135 *buffer_size = cvmx_ipd_cfg.packet_pool.buffer_size;
136 if (buffer_count)
137 *buffer_count = cvmx_ipd_cfg.packet_pool.buffer_count;
138}
139
140/**
141 * Sets the FPA packet buffer pool parameters.
142 */
143static inline void cvmx_fpa_set_packet_pool_config(s64 pool, u64 buffer_size, u64 buffer_count)
144{
145 cvmx_ipd_set_packet_pool_config(pool, buffer_size, buffer_count);
146}
147
148/**
149 * Gets the FPA WQE pool parameters.
150 */
151static inline void cvmx_fpa_get_wqe_pool_config(s64 *pool, u64 *buffer_size, u64 *buffer_count)
152{
153 if (pool)
154 *pool = cvmx_ipd_cfg.wqe_pool.pool_num;
155 if (buffer_size)
156 *buffer_size = cvmx_ipd_cfg.wqe_pool.buffer_size;
157 if (buffer_count)
158 *buffer_count = cvmx_ipd_cfg.wqe_pool.buffer_count;
159}
160
161/**
162 * Sets the FPA WQE pool parameters.
163 */
164static inline void cvmx_fpa_set_wqe_pool_config(s64 pool, u64 buffer_size, u64 buffer_count)
165{
166 cvmx_ipd_set_wqe_pool_config(pool, buffer_size, buffer_count);
167}
168
169/**
170 * Configure IPD
171 *
172 * @param mbuff_size Packets buffer size in 8 byte words
173 * @param first_mbuff_skip
174 * Number of 8 byte words to skip in the first buffer
175 * @param not_first_mbuff_skip
176 * Number of 8 byte words to skip in each following buffer
177 * @param first_back Must be same as first_mbuff_skip / 128
178 * @param second_back
179 * Must be same as not_first_mbuff_skip / 128
180 * @param wqe_fpa_pool
181 * FPA pool to get work entries from
182 * @param cache_mode
183 * @param back_pres_enable_flag
184 * Enable or disable port back pressure at a global level.
185 * This should always be 1 as more accurate control can be
186 * found in IPD_PORTX_BP_PAGE_CNT[BP_ENB].
187 */
188void cvmx_ipd_config(u64 mbuff_size, u64 first_mbuff_skip, u64 not_first_mbuff_skip, u64 first_back,
189 u64 second_back, u64 wqe_fpa_pool, cvmx_ipd_mode_t cache_mode,
190 u64 back_pres_enable_flag);
191/**
192 * Enable IPD
193 */
194void cvmx_ipd_enable(void);
195
196/**
197 * Disable IPD
198 */
199void cvmx_ipd_disable(void);
200
201void __cvmx_ipd_free_ptr(void);
202
203void cvmx_ipd_set_packet_pool_buffer_count(u64 buffer_count);
204void cvmx_ipd_set_wqe_pool_buffer_count(u64 buffer_count);
205
206/**
207 * Setup Random Early Drop on a specific input queue
208 *
209 * @param queue Input queue to setup RED on (0-7)
210 * @param pass_thresh
211 * Packets will begin slowly dropping when there are less than
212 * this many packet buffers free in FPA 0.
213 * @param drop_thresh
214 * All incoming packets will be dropped when there are less
215 * than this many free packet buffers in FPA 0.
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100216 * Return: Zero on success. Negative on failure
Aaron Williams4fd1e552021-04-23 19:56:32 +0200217 */
218int cvmx_ipd_setup_red_queue(int queue, int pass_thresh, int drop_thresh);
219
220/**
221 * Setup Random Early Drop to automatically begin dropping packets.
222 *
223 * @param pass_thresh
224 * Packets will begin slowly dropping when there are less than
225 * this many packet buffers free in FPA 0.
226 * @param drop_thresh
227 * All incoming packets will be dropped when there are less
228 * than this many free packet buffers in FPA 0.
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100229 * Return: Zero on success. Negative on failure
Aaron Williams4fd1e552021-04-23 19:56:32 +0200230 */
231int cvmx_ipd_setup_red(int pass_thresh, int drop_thresh);
232
233#endif /* __CVMX_IPD_H__ */