blob: d710211454363e623d4626b1d30e3a796b0df100 [file] [log] [blame]
Amit Gupta316729b2016-08-12 12:21:15 +05301/*
2 **************************************************************************
Amit Gupta24a1ccb2018-02-26 18:32:35 +05303 * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
Amit Gupta316729b2016-08-12 12:21:15 +05304 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all copies.
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
13 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 **************************************************************************
15 */
16
17/*
18 * nss_ppe.h
19 * NSS PPE header file
20 */
21
22#include <net/sock.h>
23#include "nss_tx_rx_common.h"
24
25#define PPE_BASE_ADDR 0x3a000000
26#define PPE_REG_SIZE 0x1000000
27
28#define PPE_L3_DBG_WR_OFFSET 0x200c04
29#define PPE_L3_DBG_RD_OFFSET 0x200c0c
30#define PPE_L3_DBG0_OFFSET 0x10001
31#define PPE_L3_DBG1_OFFSET 0x10002
32#define PPE_L3_DBG2_OFFSET 0x10003
33#define PPE_L3_DBG3_OFFSET 0x10004
34#define PPE_L3_DBG4_OFFSET 0x10005
35#define PPE_L3_DBG_PORT_OFFSET 0x11e80
36
37#define PPE_PKT_CODE_WR_OFFSET 0x100080
38#define PPE_PKT_CODE_RD_OFFSET 0x100084
39#define PPE_PKT_CODE_DROP0_OFFSET 0xf000000
40#define PPE_PKT_CODE_DROP1_OFFSET 0x10000000
41#define PPE_PKT_CODE_CPU_OFFSET 0x40000000
42
43#define PPE_PKT_CODE_DROP0_GET(x) (((x) & 0xe0000000) >> 29)
44#define PPE_PKT_CODE_DROP1_GET(x) (((x) & 0x7) << 3)
Amit Gupta79c1c202017-06-30 15:28:13 +053045#define PPE_PKT_CODE_DROP_GET(d0, d1) (PPE_PKT_CODE_DROP0_GET(d0) | PPE_PKT_CODE_DROP1_GET(d1))
Amit Gupta316729b2016-08-12 12:21:15 +053046
47#define PPE_PKT_CODE_CPU_GET(x) (((x) >> 3) & 0xff)
48
Amit Gupta79c1c202017-06-30 15:28:13 +053049#define PPE_IPE_PC_REG 0x100000
50
51/*
52 * NSS_SYS_REG_DROP_CPU_CNT_TBL
53 * Address map and access APIs for DROP_CPU_CNT table.
54 */
55#define PPE_DROP_CPU_CNT_TBL_OFFSET 0x60000
56#define PPE_DROP_CPU_CNT_TBL_ENTRY_SIZE 0x10
57#define PPE_DROP_CPU_CNT_TBL_BASE_OFFSET (PPE_IPE_PC_REG + PPE_DROP_CPU_CNT_TBL_OFFSET)
58#define PPE_CPU_CODE_MAX_NUM 256
59
60/*
61 * CPU code offset
62 */
63#define PPE_CPU_CODE_OFFSET(n) (PPE_DROP_CPU_CNT_TBL_BASE_OFFSET + ((n) * PPE_DROP_CPU_CNT_TBL_ENTRY_SIZE))
64
65/*
66 * DROP code offset
67 */
68#define PPE_DROP_CODE_IDX(code, src_port) (PPE_CPU_CODE_MAX_NUM + (8 * (code)) + (src_port))
69#define PPE_DROP_CODE_OFFSET(code, src_port) (PPE_DROP_CPU_CNT_TBL_BASE_OFFSET + ((PPE_DROP_CODE_IDX(code, src_port)) * PPE_DROP_CPU_CNT_TBL_ENTRY_SIZE))
Amit Gupta316729b2016-08-12 12:21:15 +053070
Amit Gupta1263b082017-07-06 14:22:57 +053071#define NSS_PPE_TX_TIMEOUT 1000 /* 1 Second */
72
Amit Gupta316729b2016-08-12 12:21:15 +053073/*
Amit Gupta24a1ccb2018-02-26 18:32:35 +053074 * Maximum number of VSI
75 */
76#define NSS_PPE_VSI_NUM_MAX 32
77
78/*
Amit Gupta6c0f6412017-11-20 15:42:43 +053079 * ppe nss debug stats lock
Amit Gupta316729b2016-08-12 12:21:15 +053080 */
Amit Gupta6c0f6412017-11-20 15:42:43 +053081extern spinlock_t nss_ppe_stats_lock;
Amit Gupta316729b2016-08-12 12:21:15 +053082
83/*
84 * Private data structure
85 */
Amit Gupta6c0f6412017-11-20 15:42:43 +053086struct nss_ppe_pvt {
Amit Gupta316729b2016-08-12 12:21:15 +053087 void * __iomem ppe_base;
Amit Gupta1263b082017-07-06 14:22:57 +053088 struct semaphore sem;
89 struct completion complete;
90 int response;
91 void *cb;
92 void *app_data;
Amit Gupta6c0f6412017-11-20 15:42:43 +053093};
94
95/*
96 * Data structure to store to PPE private context
97 */
98extern struct nss_ppe_pvt ppe_pvt;
Amit Gupta316729b2016-08-12 12:21:15 +053099
Amit Guptacbab9f42018-04-13 16:11:25 +0530100/**
101 * nss_ppe_message_types
102 * Message types for Packet Processing Engine (PPE) requests and responses.
103 *
104 * Note: PPE messages are added as short term approach, expect all
105 * messages below to be deprecated for more integrated approach.
106 */
107enum nss_ppe_message_types {
108 NSS_PPE_MSG_SYNC_STATS,
109 NSS_PPE_MSG_IPSEC_PORT_CONFIG,
110 NSS_PPE_MSG_IPSEC_PORT_MTU_CHANGE,
111 NSS_PPE_MSG_IPSEC_ADD_INTF,
112 NSS_PPE_MSG_IPSEC_DEL_INTF,
113 NSS_PPE_MSG_MAX,
114};
115
116/**
117 * nss_ppe_msg_error_type
118 * PPE error types.
119 */
120enum nss_ppe_msg_error_type {
121 PPE_MSG_ERROR_OK,
122 PPE_MSG_ERROR_UNKNOWN_TYPE,
123 PPE_MSG_ERROR_PORT_CREATION_FAIL,
124 PPE_MSG_ERROR_INVALID_PORT_VSI,
125 PPE_MSG_ERROR_INVALID_L3_IF,
126 PPE_MSG_ERROR_IPSEC_PORT_CONFIG,
127 PPE_MSG_ERROR_IPSEC_INTF_TABLE_FULL,
128 PPE_MSG_ERROR_IPSEC_INTF_ATTACHED,
Sachin Shashidhardd7229c2018-08-07 17:33:42 -0700129 PPE_MSG_ERROR_IPSEC_INTF_UNATTACHED,
130 PPE_ERROR_MAX
Amit Guptacbab9f42018-04-13 16:11:25 +0530131};
132
133/**
Amit Guptac438e212018-04-25 19:18:14 +0530134 * nss_ppe_stats_sc
135 * Message structure for per service code stats.
136 */
137struct nss_ppe_stats_sc {
138 uint32_t nss_ppe_sc_cb_unregister; /* Per service-code counter for callback not registered */
139 uint32_t nss_ppe_sc_cb_success; /* Per service-code coutner for successful callback */
140 uint32_t nss_ppe_sc_cb_failure; /* Per service-code counter for failure callback */
141};
142
143/**
144 * nss_ppe_stats
145 * Message structure for ppe general stats
146 */
147struct nss_ppe_stats {
Amit Guptacbab9f42018-04-13 16:11:25 +0530148 uint32_t nss_ppe_v4_l3_flows; /**< Number of IPv4 routed flows. */
149 uint32_t nss_ppe_v4_l2_flows; /**< Number of IPv4 bridge flows. */
150 uint32_t nss_ppe_v4_create_req; /**< Number of IPv4 create requests. */
151 uint32_t nss_ppe_v4_create_fail; /**< Number of IPv4 create failures. */
152 uint32_t nss_ppe_v4_destroy_req; /**< Number of IPv4 delete requests. */
153 uint32_t nss_ppe_v4_destroy_fail; /**< Number of IPv4 delete failures. */
154 uint32_t nss_ppe_v4_mc_create_req; /**< Number of IPv4 MC create requests. */
155 uint32_t nss_ppe_v4_mc_create_fail; /**< Number of IPv4 MC create failure. */
156 uint32_t nss_ppe_v4_mc_update_req; /**< Number of IPv4 MC update requests. */
157 uint32_t nss_ppe_v4_mc_update_fail; /**< Number of IPv4 MC update failure. */
158 uint32_t nss_ppe_v4_mc_destroy_req; /**< Number of IPv4 MC delete requests. */
159 uint32_t nss_ppe_v4_mc_destroy_fail; /**< Number of IPv4 MC delete failure. */
Amit Guptad69abbc2018-06-19 16:00:58 +0530160 uint32_t nss_ppe_v4_unknown_interface; /**< Number of IPv4 create failures */
Amit Guptacbab9f42018-04-13 16:11:25 +0530161
162 uint32_t nss_ppe_v6_l3_flows; /**< Number of IPv6 routed flows. */
163 uint32_t nss_ppe_v6_l2_flows; /**< Number of IPv6 bridge flows. */
164 uint32_t nss_ppe_v6_create_req; /**< Number of IPv6 create requests. */
165 uint32_t nss_ppe_v6_create_fail; /**< Number of IPv6 create failures. */
166 uint32_t nss_ppe_v6_destroy_req; /**< Number of IPv6 delete requests. */
167 uint32_t nss_ppe_v6_destroy_fail; /**< Number of IPv6 delete failures. */
168 uint32_t nss_ppe_v6_mc_create_req; /**< Number of IPv6 MC create requests. */
169 uint32_t nss_ppe_v6_mc_create_fail; /**< Number of IPv6 MC create failure. */
170 uint32_t nss_ppe_v6_mc_update_req; /**< Number of IPv6 MC update requests. */
171 uint32_t nss_ppe_v6_mc_update_fail; /**< Number of IPv6 MC update failure. */
172 uint32_t nss_ppe_v6_mc_destroy_req; /**< Number of IPv6 MC delete requests. */
173 uint32_t nss_ppe_v6_mc_destroy_fail; /**< Number of IPv6 MC delete failure. */
Amit Guptad69abbc2018-06-19 16:00:58 +0530174 uint32_t nss_ppe_v6_unknown_interface; /**< Number of IPv6 create failures */
Amit Guptacbab9f42018-04-13 16:11:25 +0530175
176 uint32_t nss_ppe_fail_vp_full;
177 /**< Request failed because the virtual port table is full */
178 uint32_t nss_ppe_fail_nh_full;
179 /**< Request failed because the next hop table is full. */
180 uint32_t nss_ppe_fail_flow_full;
181 /**< Request failed because the flow table is full. */
182 uint32_t nss_ppe_fail_host_full;
183 /**< Request failed because the host table is full. */
184 uint32_t nss_ppe_fail_pubip_full;
185 /**< Request failed because the public IP table is full. */
186 uint32_t nss_ppe_fail_port_setup;
187 /**< Request failed because the PPE port is not setup. */
188 uint32_t nss_ppe_fail_rw_fifo_full;
189 /**< Request failed because the read/write FIFO is full. */
190 uint32_t nss_ppe_fail_flow_command;
191 /**< Request failed because the PPE flow command failed. */
192 uint32_t nss_ppe_fail_unknown_proto;
193 /**< Request failed because of an unknown protocol. */
194 uint32_t nss_ppe_fail_ppe_unresponsive;
195 /**< Request failed because the PPE is not responding. */
196 uint32_t nss_ppe_ce_opaque_invalid;
197 /**< Request failed because of invalid opaque in connection entry. */
198 uint32_t nss_ppe_fail_fqg_full;
199 /**< Request failed because the flow QoS group is full. */
200};
201
Amit Guptac438e212018-04-25 19:18:14 +0530202
203/**
204 * nss_ppe_sync_stats_msg
205 * Message information for PPE synchronization statistics.
206 */
207struct nss_ppe_sync_stats_msg {
208 struct nss_ppe_stats stats; /**< General stats */
209 struct nss_ppe_stats_sc sc_stats[NSS_PPE_SC_MAX];
210 /**< Per service-code stats */
211};
212
Amit Guptacbab9f42018-04-13 16:11:25 +0530213/**
214 * nss_ppe_ipsec_port_config_msg
215 * Message structure for inline IPsec port configuration.
216 */
217struct nss_ppe_ipsec_port_config_msg {
218 uint32_t nss_ifnum; /**< NSS interface number corresponding to inline IPsec port. */
219 uint16_t mtu; /**< MTU value for inline IPsec port. */
220 uint8_t vsi_num; /**< Default port VSI for inline IPsec port. */
221};
222
223/**
224 * nss_ppe_ipsec_port_mtu_msg
225 * Message structure for inline IPsec port MTU change.
226 */
227struct nss_ppe_ipsec_port_mtu_msg {
228 uint32_t nss_ifnum; /**< NSS interface number corresponding to inline IPsec port. */
229 uint16_t mtu; /**< MTU value for inline IPsec port. */
230};
231
232/**
233 * nss_ppe_ipsec_add_intf_msg
234 * Message structure for adding dynamic IPsec/DTLS interface to inline IPsec port.
235 */
236struct nss_ppe_ipsec_add_intf_msg {
237 uint32_t nss_ifnum; /**< Dynamic IPsec/DTLS interface number. */
238};
239
240/**
241 * nss_ppe_ipsec_del_intf_msg
242 * Message structure for deleting dynamic IPsec/DTLS interface to inline IPsec port.
243 */
244struct nss_ppe_ipsec_del_intf_msg {
245 uint32_t nss_ifnum; /**< Dynamic IPsec/DTLS interface number. */
246};
247
248/**
249 * nss_ppe_msg
250 * Data for sending and receiving PPE host-to-NSS messages.
251 */
252struct nss_ppe_msg {
253 struct nss_cmn_msg cm; /**< Common message header. */
254
255 /**
256 * Payload of a PPE host-to-NSS message.
257 */
258 union {
259 struct nss_ppe_sync_stats_msg stats;
260 /**< Synchronization statistics. */
261 struct nss_ppe_ipsec_port_config_msg ipsec_config;
262 /**< PPE inline IPsec port configuration message. */
263 struct nss_ppe_ipsec_port_mtu_msg ipsec_mtu;
264 /**< Inline IPsec port MTU change message. */
265 struct nss_ppe_ipsec_add_intf_msg ipsec_addif;
266 /**< Inline IPsec NSS interface attach message. */
267 struct nss_ppe_ipsec_del_intf_msg ipsec_delif;
268 /**< Inline IPsec NSS interface detach message. */
269 } msg; /**< Message payload. */
270};
271
272/**
273 * Callback function for receiving PPE messages.
274 *
275 * @datatypes
276 * nss_ppe_msg
277 *
278 * @param[in] app_data Pointer to the application context of the message.
279 * @param[in] msg Pointer to the message data.
280 */
281typedef void (*nss_ppe_msg_callback_t)(void *app_data, struct nss_ppe_msg *msg);
282
283/**
284 * nss_ppe_tx_msg
285 * Sends PPE messages to the NSS.
286 *
287 * @datatypes
288 * nss_ctx_instance \n
289 * nss_ppe_msg
290 *
291 * @param[in] nss_ctx Pointer to the NSS context.
292 * @param[in] msg Pointer to the message data.
293 *
294 * @return
295 * Status of the Tx operation.
296 */
297nss_tx_status_t nss_ppe_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_ppe_msg *msg);
298
299/**
300 * nss_ppe_tx_msg_sync
301 * Sends PPE messages synchronously to the NSS.
302 *
303 * @datatypes
304 * nss_ctx_instance \n
305 * nss_ppe_msg
306 *
307 * @param[in] nss_ctx Pointer to the NSS context.
308 * @param[in,out] msg Pointer to the message data.
309 *
310 * @return
311 * Status of the Tx operation.
312 */
313nss_tx_status_t nss_ppe_tx_msg_sync(struct nss_ctx_instance *nss_ctx, struct nss_ppe_msg *msg);
314
315/**
316 * nss_ppe_msg_init
317 * Initializes a PPE message.
318 *
319 * @datatypes
320 * nss_ppe_msg
321 *
322 * @param[in,out] ncm Pointer to the message.
323 * @param[in] if_num Interface number
324 * @param[in] type Type of message.
325 * @param[in] len Size of the payload.
326 * @param[in] cb Callback function for the message.
327 * @param[in] app_data Pointer to the application context of the message.
328 *
329 * @return
330 * None.
331 */
332void nss_ppe_msg_init(struct nss_ppe_msg *ncm, uint16_t if_num, uint32_t type, uint32_t len, void *cb, void *app_data);
333
334/**
335 * nss_ppe_get_context
336 * Gets the PPE context used in nss_ppe_tx.
337 *
338 * @return
339 * Pointer to the NSS core context.
340 */
341struct nss_ctx_instance *nss_ppe_get_context(void);
342
343/**
344 * nss_ppe_tx_ipsec_config_msg
345 * Sends the PPE a message to configure inline IPsec port.
346 *
347 * @param[in] if_num Static IPsec interface number.
348 * @param[in] vsi_num Default VSI number associated with inline IPsec port.
349 * @param[in] mtu Default MTU of static inline IPsec port.
Vijay Vigneshan2475f412018-05-14 19:49:44 +0530350 * @param[in] mru Default MRU of static inline IPsec port.
Amit Guptacbab9f42018-04-13 16:11:25 +0530351 *
352 * @return
353 * Status of the Tx operation.
354 */
Vijay Vigneshan2475f412018-05-14 19:49:44 +0530355nss_tx_status_t nss_ppe_tx_ipsec_config_msg(uint32_t nss_ifnum, uint32_t vsi_num, uint16_t mtu, uint16_t mru);
Amit Guptacbab9f42018-04-13 16:11:25 +0530356
357/**
358 * nss_ppe_tx_ipsec_mtu_msg
359 * Sends the PPE a message to configure MTU value on IPsec port.
360 *
361 * @param[in] nss_ifnum Static IPsec interface number.
362 * @param[in] mtu MTU of static IPsec interface.
Vijay Vigneshan2475f412018-05-14 19:49:44 +0530363 * @param[in] mru MRU of static IPsec interface.
Amit Guptacbab9f42018-04-13 16:11:25 +0530364 *
365 * @return
366 * Status of the Tx operation.
367 */
Vijay Vigneshan2475f412018-05-14 19:49:44 +0530368nss_tx_status_t nss_ppe_tx_ipsec_mtu_msg(uint32_t nss_ifnum, uint16_t mtu, uint16_t mru);
Amit Guptacbab9f42018-04-13 16:11:25 +0530369
370/**
371 * nss_ppe_tx_ipsec_add_intf_msg
372 * Sends the PPE a message to attach a dynamic interface number to IPsec port.
373 *
374 * @param[in] if_num Dynamic IPsec/DTLS interface number.
375 *
376 * @return
377 * Status of the Tx operation.
378 */
379nss_tx_status_t nss_ppe_tx_ipsec_add_intf_msg(uint32_t nss_ifnum);
380
381/**
382 * nss_ppe_tx_ipsec_del_intf_msg
383 * Sends the PPE a message to detach a dynamic interface number to IPsec port.
384 *
385 * @param[in] if_num Dynamic IPsec/DTLS interface number.
386 *
387 * @return
388 * Status of the Tx operation.
389 */
390nss_tx_status_t nss_ppe_tx_ipsec_del_intf_msg(uint32_t nss_ifnum);
391
Amit Gupta316729b2016-08-12 12:21:15 +0530392/*
393 * nss_ppe_reg_read()
394 */
395static inline void nss_ppe_reg_read(u32 reg, u32 *val)
396{
397 *val = readl((ppe_pvt.ppe_base + reg));
398}
399
400/*
401 * nss_ppe_reg_write()
402 */
403static inline void nss_ppe_reg_write(u32 reg, u32 val)
404{
405 writel(val, (ppe_pvt.ppe_base + reg));
406}
Sachin Shashidhardd7229c2018-08-07 17:33:42 -0700407
408/*
409 * nss_ppe_log.h
410 * NSS PPE Log Header File
411 */
412
413/*
414 * nss_ppe_log_tx_msg
415 * Logs a ppe message that is sent to the NSS firmware.
416 */
417void nss_ppe_log_tx_msg(struct nss_ppe_msg *npm);
418
419/*
420 * nss_ppe_log_rx_msg
421 * Logs a ppe message that is received from the NSS firmware.
422 */
423void nss_ppe_log_rx_msg(struct nss_ppe_msg *npm);