blob: 67aab8f6d08f6053ccda634861f6e331bb4b834c [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. */
160
161 uint32_t nss_ppe_v6_l3_flows; /**< Number of IPv6 routed flows. */
162 uint32_t nss_ppe_v6_l2_flows; /**< Number of IPv6 bridge flows. */
163 uint32_t nss_ppe_v6_create_req; /**< Number of IPv6 create requests. */
164 uint32_t nss_ppe_v6_create_fail; /**< Number of IPv6 create failures. */
165 uint32_t nss_ppe_v6_destroy_req; /**< Number of IPv6 delete requests. */
166 uint32_t nss_ppe_v6_destroy_fail; /**< Number of IPv6 delete failures. */
167 uint32_t nss_ppe_v6_mc_create_req; /**< Number of IPv6 MC create requests. */
168 uint32_t nss_ppe_v6_mc_create_fail; /**< Number of IPv6 MC create failure. */
169 uint32_t nss_ppe_v6_mc_update_req; /**< Number of IPv6 MC update requests. */
170 uint32_t nss_ppe_v6_mc_update_fail; /**< Number of IPv6 MC update failure. */
171 uint32_t nss_ppe_v6_mc_destroy_req; /**< Number of IPv6 MC delete requests. */
172 uint32_t nss_ppe_v6_mc_destroy_fail; /**< Number of IPv6 MC delete failure. */
173
174 uint32_t nss_ppe_fail_vp_full;
175 /**< Request failed because the virtual port table is full */
176 uint32_t nss_ppe_fail_nh_full;
177 /**< Request failed because the next hop table is full. */
178 uint32_t nss_ppe_fail_flow_full;
179 /**< Request failed because the flow table is full. */
180 uint32_t nss_ppe_fail_host_full;
181 /**< Request failed because the host table is full. */
182 uint32_t nss_ppe_fail_pubip_full;
183 /**< Request failed because the public IP table is full. */
184 uint32_t nss_ppe_fail_port_setup;
185 /**< Request failed because the PPE port is not setup. */
186 uint32_t nss_ppe_fail_rw_fifo_full;
187 /**< Request failed because the read/write FIFO is full. */
188 uint32_t nss_ppe_fail_flow_command;
189 /**< Request failed because the PPE flow command failed. */
190 uint32_t nss_ppe_fail_unknown_proto;
191 /**< Request failed because of an unknown protocol. */
192 uint32_t nss_ppe_fail_ppe_unresponsive;
193 /**< Request failed because the PPE is not responding. */
194 uint32_t nss_ppe_ce_opaque_invalid;
195 /**< Request failed because of invalid opaque in connection entry. */
196 uint32_t nss_ppe_fail_fqg_full;
197 /**< Request failed because the flow QoS group is full. */
198};
199
Amit Guptac438e212018-04-25 19:18:14 +0530200
201/**
202 * nss_ppe_sync_stats_msg
203 * Message information for PPE synchronization statistics.
204 */
205struct nss_ppe_sync_stats_msg {
206 struct nss_ppe_stats stats; /**< General stats */
207 struct nss_ppe_stats_sc sc_stats[NSS_PPE_SC_MAX];
208 /**< Per service-code stats */
209};
210
Amit Guptacbab9f42018-04-13 16:11:25 +0530211/**
212 * nss_ppe_ipsec_port_config_msg
213 * Message structure for inline IPsec port configuration.
214 */
215struct nss_ppe_ipsec_port_config_msg {
216 uint32_t nss_ifnum; /**< NSS interface number corresponding to inline IPsec port. */
217 uint16_t mtu; /**< MTU value for inline IPsec port. */
218 uint8_t vsi_num; /**< Default port VSI for inline IPsec port. */
219};
220
221/**
222 * nss_ppe_ipsec_port_mtu_msg
223 * Message structure for inline IPsec port MTU change.
224 */
225struct nss_ppe_ipsec_port_mtu_msg {
226 uint32_t nss_ifnum; /**< NSS interface number corresponding to inline IPsec port. */
227 uint16_t mtu; /**< MTU value for inline IPsec port. */
228};
229
230/**
231 * nss_ppe_ipsec_add_intf_msg
232 * Message structure for adding dynamic IPsec/DTLS interface to inline IPsec port.
233 */
234struct nss_ppe_ipsec_add_intf_msg {
235 uint32_t nss_ifnum; /**< Dynamic IPsec/DTLS interface number. */
236};
237
238/**
239 * nss_ppe_ipsec_del_intf_msg
240 * Message structure for deleting dynamic IPsec/DTLS interface to inline IPsec port.
241 */
242struct nss_ppe_ipsec_del_intf_msg {
243 uint32_t nss_ifnum; /**< Dynamic IPsec/DTLS interface number. */
244};
245
246/**
247 * nss_ppe_msg
248 * Data for sending and receiving PPE host-to-NSS messages.
249 */
250struct nss_ppe_msg {
251 struct nss_cmn_msg cm; /**< Common message header. */
252
253 /**
254 * Payload of a PPE host-to-NSS message.
255 */
256 union {
257 struct nss_ppe_sync_stats_msg stats;
258 /**< Synchronization statistics. */
259 struct nss_ppe_ipsec_port_config_msg ipsec_config;
260 /**< PPE inline IPsec port configuration message. */
261 struct nss_ppe_ipsec_port_mtu_msg ipsec_mtu;
262 /**< Inline IPsec port MTU change message. */
263 struct nss_ppe_ipsec_add_intf_msg ipsec_addif;
264 /**< Inline IPsec NSS interface attach message. */
265 struct nss_ppe_ipsec_del_intf_msg ipsec_delif;
266 /**< Inline IPsec NSS interface detach message. */
267 } msg; /**< Message payload. */
268};
269
270/**
271 * Callback function for receiving PPE messages.
272 *
273 * @datatypes
274 * nss_ppe_msg
275 *
276 * @param[in] app_data Pointer to the application context of the message.
277 * @param[in] msg Pointer to the message data.
278 */
279typedef void (*nss_ppe_msg_callback_t)(void *app_data, struct nss_ppe_msg *msg);
280
281/**
282 * nss_ppe_tx_msg
283 * Sends PPE messages to the NSS.
284 *
285 * @datatypes
286 * nss_ctx_instance \n
287 * nss_ppe_msg
288 *
289 * @param[in] nss_ctx Pointer to the NSS context.
290 * @param[in] msg Pointer to the message data.
291 *
292 * @return
293 * Status of the Tx operation.
294 */
295nss_tx_status_t nss_ppe_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_ppe_msg *msg);
296
297/**
298 * nss_ppe_tx_msg_sync
299 * Sends PPE messages synchronously to the NSS.
300 *
301 * @datatypes
302 * nss_ctx_instance \n
303 * nss_ppe_msg
304 *
305 * @param[in] nss_ctx Pointer to the NSS context.
306 * @param[in,out] msg Pointer to the message data.
307 *
308 * @return
309 * Status of the Tx operation.
310 */
311nss_tx_status_t nss_ppe_tx_msg_sync(struct nss_ctx_instance *nss_ctx, struct nss_ppe_msg *msg);
312
313/**
314 * nss_ppe_msg_init
315 * Initializes a PPE message.
316 *
317 * @datatypes
318 * nss_ppe_msg
319 *
320 * @param[in,out] ncm Pointer to the message.
321 * @param[in] if_num Interface number
322 * @param[in] type Type of message.
323 * @param[in] len Size of the payload.
324 * @param[in] cb Callback function for the message.
325 * @param[in] app_data Pointer to the application context of the message.
326 *
327 * @return
328 * None.
329 */
330void nss_ppe_msg_init(struct nss_ppe_msg *ncm, uint16_t if_num, uint32_t type, uint32_t len, void *cb, void *app_data);
331
332/**
333 * nss_ppe_get_context
334 * Gets the PPE context used in nss_ppe_tx.
335 *
336 * @return
337 * Pointer to the NSS core context.
338 */
339struct nss_ctx_instance *nss_ppe_get_context(void);
340
341/**
342 * nss_ppe_tx_ipsec_config_msg
343 * Sends the PPE a message to configure inline IPsec port.
344 *
345 * @param[in] if_num Static IPsec interface number.
346 * @param[in] vsi_num Default VSI number associated with inline IPsec port.
347 * @param[in] mtu Default MTU of static inline IPsec port.
Vijay Vigneshan2475f412018-05-14 19:49:44 +0530348 * @param[in] mru Default MRU of static inline IPsec port.
Amit Guptacbab9f42018-04-13 16:11:25 +0530349 *
350 * @return
351 * Status of the Tx operation.
352 */
Vijay Vigneshan2475f412018-05-14 19:49:44 +0530353nss_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 +0530354
355/**
356 * nss_ppe_tx_ipsec_mtu_msg
357 * Sends the PPE a message to configure MTU value on IPsec port.
358 *
359 * @param[in] nss_ifnum Static IPsec interface number.
360 * @param[in] mtu MTU of static IPsec interface.
Vijay Vigneshan2475f412018-05-14 19:49:44 +0530361 * @param[in] mru MRU of static IPsec interface.
Amit Guptacbab9f42018-04-13 16:11:25 +0530362 *
363 * @return
364 * Status of the Tx operation.
365 */
Vijay Vigneshan2475f412018-05-14 19:49:44 +0530366nss_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 +0530367
368/**
369 * nss_ppe_tx_ipsec_add_intf_msg
370 * Sends the PPE a message to attach a dynamic interface number to IPsec port.
371 *
372 * @param[in] if_num Dynamic IPsec/DTLS interface number.
373 *
374 * @return
375 * Status of the Tx operation.
376 */
377nss_tx_status_t nss_ppe_tx_ipsec_add_intf_msg(uint32_t nss_ifnum);
378
379/**
380 * nss_ppe_tx_ipsec_del_intf_msg
381 * Sends the PPE a message to detach a dynamic interface number to IPsec port.
382 *
383 * @param[in] if_num Dynamic IPsec/DTLS interface number.
384 *
385 * @return
386 * Status of the Tx operation.
387 */
388nss_tx_status_t nss_ppe_tx_ipsec_del_intf_msg(uint32_t nss_ifnum);
389
Amit Gupta316729b2016-08-12 12:21:15 +0530390/*
391 * nss_ppe_reg_read()
392 */
393static inline void nss_ppe_reg_read(u32 reg, u32 *val)
394{
395 *val = readl((ppe_pvt.ppe_base + reg));
396}
397
398/*
399 * nss_ppe_reg_write()
400 */
401static inline void nss_ppe_reg_write(u32 reg, u32 val)
402{
403 writel(val, (ppe_pvt.ppe_base + reg));
404}
Sachin Shashidhardd7229c2018-08-07 17:33:42 -0700405
406/*
407 * nss_ppe_log.h
408 * NSS PPE Log Header File
409 */
410
411/*
412 * nss_ppe_log_tx_msg
413 * Logs a ppe message that is sent to the NSS firmware.
414 */
415void nss_ppe_log_tx_msg(struct nss_ppe_msg *npm);
416
417/*
418 * nss_ppe_log_rx_msg
419 * Logs a ppe message that is received from the NSS firmware.
420 */
421void nss_ppe_log_rx_msg(struct nss_ppe_msg *npm);