blob: 542cc47bed09f3fc2f0165cede1b635aad1e1445 [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_sc_type
135 * PPE service code types
Amit Guptacbab9f42018-04-13 16:11:25 +0530136 */
Amit Guptac438e212018-04-25 19:18:14 +0530137enum nss_ppe_sc_type {
138 NSS_PPE_SC_NONE, /* Normal PPE processing */
139 NSS_PPE_SC_BYPASS_ALL, /* Bypasses all stages in PPE */
140 NSS_PPE_SC_ADV_QOS_BRIDGED, /* Adv QoS redirection for bridged flow */
141 NSS_PPE_SC_BR_QOS, /* Bridge QoS redirection */
142 NSS_PPE_SC_BNC_0, /* QoS bounce */
143 NSS_PPE_SC_BNC_CMPL_0, /* QoS bounce complete */
144 NSS_PPE_SC_ADV_QOS_ROUTED, /* Adv QoS redirection for routed flow */
145 NSS_PPE_SC_IPSEC_PPE2EIP, /* Inline IPsec redirection from PPE TO EIP */
146 NSS_PPE_SC_IPSEC_EIP2PPE, /* Inline IPsec redirection from EIP to PPE */
Adil Irfan32da4e72018-10-30 19:13:00 +0530147 NSS_PPE_SC_VLAN_FILTER_BYPASS, /* VLAN filter bypass for bridge flows between 2 different VSIs */
Amit Guptac438e212018-04-25 19:18:14 +0530148 NSS_PPE_SC_MAX, /* Max service code */
149};
150
151/**
152 * nss_ppe_stats_sc
153 * Message structure for per service code stats.
154 */
155struct nss_ppe_stats_sc {
156 uint32_t nss_ppe_sc_cb_unregister; /* Per service-code counter for callback not registered */
157 uint32_t nss_ppe_sc_cb_success; /* Per service-code coutner for successful callback */
158 uint32_t nss_ppe_sc_cb_failure; /* Per service-code counter for failure callback */
159};
160
161/**
162 * nss_ppe_stats
163 * Message structure for ppe general stats
164 */
165struct nss_ppe_stats {
Amit Guptacbab9f42018-04-13 16:11:25 +0530166 uint32_t nss_ppe_v4_l3_flows; /**< Number of IPv4 routed flows. */
167 uint32_t nss_ppe_v4_l2_flows; /**< Number of IPv4 bridge flows. */
168 uint32_t nss_ppe_v4_create_req; /**< Number of IPv4 create requests. */
169 uint32_t nss_ppe_v4_create_fail; /**< Number of IPv4 create failures. */
170 uint32_t nss_ppe_v4_destroy_req; /**< Number of IPv4 delete requests. */
171 uint32_t nss_ppe_v4_destroy_fail; /**< Number of IPv4 delete failures. */
172 uint32_t nss_ppe_v4_mc_create_req; /**< Number of IPv4 MC create requests. */
173 uint32_t nss_ppe_v4_mc_create_fail; /**< Number of IPv4 MC create failure. */
174 uint32_t nss_ppe_v4_mc_update_req; /**< Number of IPv4 MC update requests. */
175 uint32_t nss_ppe_v4_mc_update_fail; /**< Number of IPv4 MC update failure. */
176 uint32_t nss_ppe_v4_mc_destroy_req; /**< Number of IPv4 MC delete requests. */
177 uint32_t nss_ppe_v4_mc_destroy_fail; /**< Number of IPv4 MC delete failure. */
178
179 uint32_t nss_ppe_v6_l3_flows; /**< Number of IPv6 routed flows. */
180 uint32_t nss_ppe_v6_l2_flows; /**< Number of IPv6 bridge flows. */
181 uint32_t nss_ppe_v6_create_req; /**< Number of IPv6 create requests. */
182 uint32_t nss_ppe_v6_create_fail; /**< Number of IPv6 create failures. */
183 uint32_t nss_ppe_v6_destroy_req; /**< Number of IPv6 delete requests. */
184 uint32_t nss_ppe_v6_destroy_fail; /**< Number of IPv6 delete failures. */
185 uint32_t nss_ppe_v6_mc_create_req; /**< Number of IPv6 MC create requests. */
186 uint32_t nss_ppe_v6_mc_create_fail; /**< Number of IPv6 MC create failure. */
187 uint32_t nss_ppe_v6_mc_update_req; /**< Number of IPv6 MC update requests. */
188 uint32_t nss_ppe_v6_mc_update_fail; /**< Number of IPv6 MC update failure. */
189 uint32_t nss_ppe_v6_mc_destroy_req; /**< Number of IPv6 MC delete requests. */
190 uint32_t nss_ppe_v6_mc_destroy_fail; /**< Number of IPv6 MC delete failure. */
191
192 uint32_t nss_ppe_fail_vp_full;
193 /**< Request failed because the virtual port table is full */
194 uint32_t nss_ppe_fail_nh_full;
195 /**< Request failed because the next hop table is full. */
196 uint32_t nss_ppe_fail_flow_full;
197 /**< Request failed because the flow table is full. */
198 uint32_t nss_ppe_fail_host_full;
199 /**< Request failed because the host table is full. */
200 uint32_t nss_ppe_fail_pubip_full;
201 /**< Request failed because the public IP table is full. */
202 uint32_t nss_ppe_fail_port_setup;
203 /**< Request failed because the PPE port is not setup. */
204 uint32_t nss_ppe_fail_rw_fifo_full;
205 /**< Request failed because the read/write FIFO is full. */
206 uint32_t nss_ppe_fail_flow_command;
207 /**< Request failed because the PPE flow command failed. */
208 uint32_t nss_ppe_fail_unknown_proto;
209 /**< Request failed because of an unknown protocol. */
210 uint32_t nss_ppe_fail_ppe_unresponsive;
211 /**< Request failed because the PPE is not responding. */
212 uint32_t nss_ppe_ce_opaque_invalid;
213 /**< Request failed because of invalid opaque in connection entry. */
214 uint32_t nss_ppe_fail_fqg_full;
215 /**< Request failed because the flow QoS group is full. */
216};
217
Amit Guptac438e212018-04-25 19:18:14 +0530218
219/**
220 * nss_ppe_sync_stats_msg
221 * Message information for PPE synchronization statistics.
222 */
223struct nss_ppe_sync_stats_msg {
224 struct nss_ppe_stats stats; /**< General stats */
225 struct nss_ppe_stats_sc sc_stats[NSS_PPE_SC_MAX];
226 /**< Per service-code stats */
227};
228
Amit Guptacbab9f42018-04-13 16:11:25 +0530229/**
230 * nss_ppe_ipsec_port_config_msg
231 * Message structure for inline IPsec port configuration.
232 */
233struct nss_ppe_ipsec_port_config_msg {
234 uint32_t nss_ifnum; /**< NSS interface number corresponding to inline IPsec port. */
235 uint16_t mtu; /**< MTU value for inline IPsec port. */
236 uint8_t vsi_num; /**< Default port VSI for inline IPsec port. */
237};
238
239/**
240 * nss_ppe_ipsec_port_mtu_msg
241 * Message structure for inline IPsec port MTU change.
242 */
243struct nss_ppe_ipsec_port_mtu_msg {
244 uint32_t nss_ifnum; /**< NSS interface number corresponding to inline IPsec port. */
245 uint16_t mtu; /**< MTU value for inline IPsec port. */
246};
247
248/**
249 * nss_ppe_ipsec_add_intf_msg
250 * Message structure for adding dynamic IPsec/DTLS interface to inline IPsec port.
251 */
252struct nss_ppe_ipsec_add_intf_msg {
253 uint32_t nss_ifnum; /**< Dynamic IPsec/DTLS interface number. */
254};
255
256/**
257 * nss_ppe_ipsec_del_intf_msg
258 * Message structure for deleting dynamic IPsec/DTLS interface to inline IPsec port.
259 */
260struct nss_ppe_ipsec_del_intf_msg {
261 uint32_t nss_ifnum; /**< Dynamic IPsec/DTLS interface number. */
262};
263
264/**
265 * nss_ppe_msg
266 * Data for sending and receiving PPE host-to-NSS messages.
267 */
268struct nss_ppe_msg {
269 struct nss_cmn_msg cm; /**< Common message header. */
270
271 /**
272 * Payload of a PPE host-to-NSS message.
273 */
274 union {
275 struct nss_ppe_sync_stats_msg stats;
276 /**< Synchronization statistics. */
277 struct nss_ppe_ipsec_port_config_msg ipsec_config;
278 /**< PPE inline IPsec port configuration message. */
279 struct nss_ppe_ipsec_port_mtu_msg ipsec_mtu;
280 /**< Inline IPsec port MTU change message. */
281 struct nss_ppe_ipsec_add_intf_msg ipsec_addif;
282 /**< Inline IPsec NSS interface attach message. */
283 struct nss_ppe_ipsec_del_intf_msg ipsec_delif;
284 /**< Inline IPsec NSS interface detach message. */
285 } msg; /**< Message payload. */
286};
287
288/**
289 * Callback function for receiving PPE messages.
290 *
291 * @datatypes
292 * nss_ppe_msg
293 *
294 * @param[in] app_data Pointer to the application context of the message.
295 * @param[in] msg Pointer to the message data.
296 */
297typedef void (*nss_ppe_msg_callback_t)(void *app_data, struct nss_ppe_msg *msg);
298
299/**
300 * nss_ppe_tx_msg
301 * Sends PPE messages 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] msg Pointer to the message data.
309 *
310 * @return
311 * Status of the Tx operation.
312 */
313nss_tx_status_t nss_ppe_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_ppe_msg *msg);
314
315/**
316 * nss_ppe_tx_msg_sync
317 * Sends PPE messages synchronously to the NSS.
318 *
319 * @datatypes
320 * nss_ctx_instance \n
321 * nss_ppe_msg
322 *
323 * @param[in] nss_ctx Pointer to the NSS context.
324 * @param[in,out] msg Pointer to the message data.
325 *
326 * @return
327 * Status of the Tx operation.
328 */
329nss_tx_status_t nss_ppe_tx_msg_sync(struct nss_ctx_instance *nss_ctx, struct nss_ppe_msg *msg);
330
331/**
332 * nss_ppe_msg_init
333 * Initializes a PPE message.
334 *
335 * @datatypes
336 * nss_ppe_msg
337 *
338 * @param[in,out] ncm Pointer to the message.
339 * @param[in] if_num Interface number
340 * @param[in] type Type of message.
341 * @param[in] len Size of the payload.
342 * @param[in] cb Callback function for the message.
343 * @param[in] app_data Pointer to the application context of the message.
344 *
345 * @return
346 * None.
347 */
348void nss_ppe_msg_init(struct nss_ppe_msg *ncm, uint16_t if_num, uint32_t type, uint32_t len, void *cb, void *app_data);
349
350/**
351 * nss_ppe_get_context
352 * Gets the PPE context used in nss_ppe_tx.
353 *
354 * @return
355 * Pointer to the NSS core context.
356 */
357struct nss_ctx_instance *nss_ppe_get_context(void);
358
359/**
360 * nss_ppe_tx_ipsec_config_msg
361 * Sends the PPE a message to configure inline IPsec port.
362 *
363 * @param[in] if_num Static IPsec interface number.
364 * @param[in] vsi_num Default VSI number associated with inline IPsec port.
365 * @param[in] mtu Default MTU of static inline IPsec port.
Vijay Vigneshan2475f412018-05-14 19:49:44 +0530366 * @param[in] mru Default MRU of static inline IPsec port.
Amit Guptacbab9f42018-04-13 16:11:25 +0530367 *
368 * @return
369 * Status of the Tx operation.
370 */
Vijay Vigneshan2475f412018-05-14 19:49:44 +0530371nss_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 +0530372
373/**
374 * nss_ppe_tx_ipsec_mtu_msg
375 * Sends the PPE a message to configure MTU value on IPsec port.
376 *
377 * @param[in] nss_ifnum Static IPsec interface number.
378 * @param[in] mtu MTU of static IPsec interface.
Vijay Vigneshan2475f412018-05-14 19:49:44 +0530379 * @param[in] mru MRU of static IPsec interface.
Amit Guptacbab9f42018-04-13 16:11:25 +0530380 *
381 * @return
382 * Status of the Tx operation.
383 */
Vijay Vigneshan2475f412018-05-14 19:49:44 +0530384nss_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 +0530385
386/**
387 * nss_ppe_tx_ipsec_add_intf_msg
388 * Sends the PPE a message to attach a dynamic interface number to IPsec port.
389 *
390 * @param[in] if_num Dynamic IPsec/DTLS interface number.
391 *
392 * @return
393 * Status of the Tx operation.
394 */
395nss_tx_status_t nss_ppe_tx_ipsec_add_intf_msg(uint32_t nss_ifnum);
396
397/**
398 * nss_ppe_tx_ipsec_del_intf_msg
399 * Sends the PPE a message to detach a dynamic interface number to IPsec port.
400 *
401 * @param[in] if_num Dynamic IPsec/DTLS interface number.
402 *
403 * @return
404 * Status of the Tx operation.
405 */
406nss_tx_status_t nss_ppe_tx_ipsec_del_intf_msg(uint32_t nss_ifnum);
407
Amit Gupta316729b2016-08-12 12:21:15 +0530408/*
409 * nss_ppe_reg_read()
410 */
411static inline void nss_ppe_reg_read(u32 reg, u32 *val)
412{
413 *val = readl((ppe_pvt.ppe_base + reg));
414}
415
416/*
417 * nss_ppe_reg_write()
418 */
419static inline void nss_ppe_reg_write(u32 reg, u32 val)
420{
421 writel(val, (ppe_pvt.ppe_base + reg));
422}
Sachin Shashidhardd7229c2018-08-07 17:33:42 -0700423
424/*
425 * nss_ppe_log.h
426 * NSS PPE Log Header File
427 */
428
429/*
430 * nss_ppe_log_tx_msg
431 * Logs a ppe message that is sent to the NSS firmware.
432 */
433void nss_ppe_log_tx_msg(struct nss_ppe_msg *npm);
434
435/*
436 * nss_ppe_log_rx_msg
437 * Logs a ppe message that is received from the NSS firmware.
438 */
439void nss_ppe_log_rx_msg(struct nss_ppe_msg *npm);