net/bnxt: add initial TruFlow core resource management
[dpdk.git] / drivers / net / bnxt / tf_core / tf_core.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _TF_CORE_H_
7 #define _TF_CORE_H_
8
9 #include <stdint.h>
10 #include <stdlib.h>
11 #include <stdbool.h>
12 #include <stdio.h>
13
14 #include "tf_project.h"
15
16 /**
17  * @file
18  *
19  * Truflow Core API Header File
20  */
21
22 /********** BEGIN Truflow Core DEFINITIONS **********/
23
24 /**
25  * direction
26  */
27 enum tf_dir {
28         TF_DIR_RX,  /**< Receive */
29         TF_DIR_TX,  /**< Transmit */
30         TF_DIR_MAX
31 };
32
33 /********** BEGIN API FUNCTION PROTOTYPES/PARAMETERS **********/
34
35 /**
36  * @page general General
37  *
38  * @ref tf_open_session
39  *
40  * @ref tf_attach_session
41  *
42  * @ref tf_close_session
43  */
44
45
46 /** Session Version defines
47  *
48  * The version controls the format of the tf_session and
49  * tf_session_info structure. This is to assure upgrade between
50  * versions can be supported.
51  */
52 #define TF_SESSION_VER_MAJOR  1   /**< Major Version */
53 #define TF_SESSION_VER_MINOR  0   /**< Minor Version */
54 #define TF_SESSION_VER_UPDATE 0   /**< Update Version */
55
56 /** Session Name
57  *
58  * Name of the TruFlow control channel interface.  Expects
59  * format to be RTE Name specific, i.e. rte_eth_dev_get_name_by_port()
60  */
61 #define TF_SESSION_NAME_MAX       64
62
63 #define TF_FW_SESSION_ID_INVALID  0xFF  /**< Invalid FW Session ID define */
64
65 /** Session Identifier
66  *
67  * Unique session identifier which includes PCIe bus info to
68  * distinguish the PF and session info to identify the associated
69  * TruFlow session. Session ID is constructed from the passed in
70  * ctrl_chan_name in tf_open_session() together with an allocated
71  * fw_session_id. Done by TruFlow on tf_open_session().
72  */
73 union tf_session_id {
74         uint32_t id;
75         struct {
76                 uint8_t domain;
77                 uint8_t bus;
78                 uint8_t device;
79                 uint8_t fw_session_id;
80         } internal;
81 };
82
83 /** Session Version
84  *
85  * The version controls the format of the tf_session and
86  * tf_session_info structure. This is to assure upgrade between
87  * versions can be supported.
88  *
89  * Please see the TF_VER_MAJOR/MINOR and UPDATE defines.
90  */
91 struct tf_session_version {
92         uint8_t major;
93         uint8_t minor;
94         uint8_t update;
95 };
96
97 /** Session supported device types
98  *
99  */
100 enum tf_device_type {
101         TF_DEVICE_TYPE_WH = 0, /**< Whitney+  */
102         TF_DEVICE_TYPE_BRD2,   /**< TBD       */
103         TF_DEVICE_TYPE_BRD3,   /**< TBD       */
104         TF_DEVICE_TYPE_BRD4,   /**< TBD       */
105         TF_DEVICE_TYPE_MAX     /**< Maximum   */
106 };
107
108 /** TruFlow Session Information
109  *
110  * Structure defining a TruFlow Session, also known as a Management
111  * session. This structure is initialized at time of
112  * tf_open_session(). It is passed to all of the TruFlow APIs as way
113  * to prescribe and isolate resources between different TruFlow ULP
114  * Applications.
115  */
116 struct tf_session_info {
117         /**
118          * TrueFlow Version. Used to control the structure layout when
119          * sharing sessions. No guarantee that a secondary process
120          * would come from the same version of an executable.
121          * TruFlow initializes this variable on tf_open_session().
122          *
123          * Owner:  TruFlow
124          * Access: TruFlow
125          */
126         struct tf_session_version ver;
127         /**
128          * will be STAILQ_ENTRY(tf_session_info) next
129          *
130          * Owner:  ULP
131          * Access: ULP
132          */
133         void                 *next;
134         /**
135          * Session ID is a unique identifier for the session. TruFlow
136          * initializes this variable during tf_open_session()
137          * processing.
138          *
139          * Owner:  TruFlow
140          * Access: Truflow & ULP
141          */
142         union tf_session_id   session_id;
143         /**
144          * Protects access to core_data. Lock is initialized and owned
145          * by ULP. TruFlow can access the core_data without checking
146          * the lock.
147          *
148          * Owner:  ULP
149          * Access: ULP
150          */
151         uint8_t               spin_lock;
152         /**
153          * The core_data holds the TruFlow tf_session data
154          * structure. This memory is allocated and owned by TruFlow on
155          * tf_open_session().
156          *
157          * TruFlow uses this memory for session management control
158          * until the session is closed by ULP. Access control is done
159          * by the spin_lock which ULP controls ahead of TruFlow API
160          * calls.
161          *
162          * Please see tf_open_session_parms for specification details
163          * on this variable.
164          *
165          * Owner:  TruFlow
166          * Access: TruFlow
167          */
168         void                 *core_data;
169         /**
170          * The core_data_sz_bytes specifies the size of core_data in
171          * bytes.
172          *
173          * The size is set by TruFlow on tf_open_session().
174          *
175          * Please see tf_open_session_parms for specification details
176          * on this variable.
177          *
178          * Owner:  TruFlow
179          * Access: TruFlow
180          */
181         uint32_t              core_data_sz_bytes;
182 };
183
184 /** TruFlow handle
185  *
186  * Contains a pointer to the session info. Allocated by ULP and passed
187  * to TruFlow using tf_open_session(). TruFlow will populate the
188  * session info at that time. Additional 'opens' can be done using
189  * same session_info by using tf_attach_session().
190  *
191  * It is expected that ULP allocates this memory as shared memory.
192  *
193  * NOTE: This struct must be within the BNXT PMD struct bnxt
194  *       (bp). This allows use of container_of() to get access to the PMD.
195  */
196 struct tf {
197         struct tf_session_info *session;
198 };
199
200
201 /**
202  * tf_open_session parameters definition.
203  */
204 struct tf_open_session_parms {
205         /** [in] ctrl_chan_name
206          *
207          * String containing name of control channel interface to be
208          * used for this session to communicate with firmware.
209          *
210          * The ctrl_chan_name can be looked up by using
211          * rte_eth_dev_get_name_by_port() within the ULP.
212          *
213          * ctrl_chan_name will be used as part of a name for any
214          * shared memory allocation.
215          */
216         char ctrl_chan_name[TF_SESSION_NAME_MAX];
217         /** [in] shadow_copy
218          *
219          * Boolean controlling the use and availability of shadow
220          * copy. Shadow copy will allow the TruFlow to keep track of
221          * resource content on the firmware side without having to
222          * query firmware. Additional private session core_data will
223          * be allocated if this boolean is set to 'true', default
224          * 'false'.
225          *
226          * Size of memory depends on the NVM Resource settings for the
227          * control channel.
228          */
229         bool shadow_copy;
230         /** [in/out] session_id
231          *
232          * Session_id is unique per session.
233          *
234          * Session_id is composed of domain, bus, device and
235          * fw_session_id. The construction is done by parsing the
236          * ctrl_chan_name together with allocation of a fw_session_id.
237          *
238          * The session_id allows a session to be shared between devices.
239          */
240         union tf_session_id session_id;
241         /** [in] device type
242          *
243          * Device type is passed, one of Wh+, Brd2, Brd3, Brd4
244          */
245         enum tf_device_type device_type;
246 };
247
248 /**
249  * Opens a new TruFlow management session.
250  *
251  * TruFlow will allocate session specific memory, shared memory, to
252  * hold its session data. This data is private to TruFlow.
253  *
254  * Multiple PFs can share the same session. An association, refcount,
255  * between session and PFs is maintained within TruFlow. Thus, a PF
256  * can attach to an existing session, see tf_attach_session().
257  *
258  * No other TruFlow APIs will succeed unless this API is first called and
259  * succeeds.
260  *
261  * tf_open_session() returns a session id that can be used on attach.
262  *
263  * [in] tfp
264  *   Pointer to TF handle
265  * [in] parms
266  *   Pointer to open parameters
267  *
268  * Returns
269  *   - (0) if successful.
270  *   - (-EINVAL) on failure.
271  */
272 int tf_open_session(struct tf *tfp,
273                     struct tf_open_session_parms *parms);
274
275 struct tf_attach_session_parms {
276         /** [in] ctrl_chan_name
277          *
278          * String containing name of control channel interface to be
279          * used for this session to communicate with firmware.
280          *
281          * The ctrl_chan_name can be looked up by using
282          * rte_eth_dev_get_name_by_port() within the ULP.
283          *
284          * ctrl_chan_name will be used as part of a name for any
285          * shared memory allocation.
286          */
287         char ctrl_chan_name[TF_SESSION_NAME_MAX];
288
289         /** [in] attach_chan_name
290          *
291          * String containing name of attach channel interface to be
292          * used for this session.
293          *
294          * The attach_chan_name must be given to a 2nd process after
295          * the primary process has been created. This is the
296          * ctrl_chan_name of the primary process and is used to find
297          * the shared memory for the session that the attach is going
298          * to use.
299          */
300         char attach_chan_name[TF_SESSION_NAME_MAX];
301
302         /** [in] session_id
303          *
304          * Session_id is unique per session. For Attach the session_id
305          * should be the session_id that was returned on the first
306          * open.
307          *
308          * Session_id is composed of domain, bus, device and
309          * fw_session_id. The construction is done by parsing the
310          * ctrl_chan_name together with allocation of a fw_session_id
311          * during tf_open_session().
312          *
313          * A reference count will be incremented on attach. A session
314          * is first fully closed when reference count is zero by
315          * calling tf_close_session().
316          */
317         union tf_session_id session_id;
318 };
319
320 /**
321  * Attaches to an existing session. Used when more than one PF wants
322  * to share a single session. In that case all TruFlow management
323  * traffic will be sent to the TruFlow firmware using the 'PF' that
324  * did the attach not the session ctrl channel.
325  *
326  * Attach will increment a ref count as to manage the shared session data.
327  *
328  * [in] tfp, pointer to TF handle
329  * [in] parms, pointer to attach parameters
330  *
331  * Returns
332  *   - (0) if successful.
333  *   - (-EINVAL) on failure.
334  */
335 int tf_attach_session(struct tf *tfp,
336                       struct tf_attach_session_parms *parms);
337
338 /**
339  * Closes an existing session. Cleans up all hardware and firmware
340  * state associated with the TruFlow application session when the last
341  * PF associated with the session results in refcount to be zero.
342  *
343  * Returns success or failure code.
344  */
345 int tf_close_session(struct tf *tfp);
346
347 /**
348  * @page  ident Identity Management
349  *
350  * @ref tf_alloc_identifier
351  *
352  * @ref tf_free_identifier
353  */
354 enum tf_identifier_type {
355         /** The L2 Context is returned from the L2 Ctxt TCAM lookup
356          *  and can be used in WC TCAM or EM keys to virtualize further
357          *  lookups.
358          */
359         TF_IDENT_TYPE_L2_CTXT,
360         /** The WC profile func is returned from the L2 Ctxt TCAM lookup
361          *  to enable virtualization of the profile TCAM.
362          */
363         TF_IDENT_TYPE_PROF_FUNC,
364         /** The WC profile ID is included in the WC lookup key
365          *  to enable virtualization of the WC TCAM hardware.
366          */
367         TF_IDENT_TYPE_WC_PROF,
368         /** The EM profile ID is included in the EM lookup key
369          *  to enable virtualization of the EM hardware. (not required for Brd4
370          *  as it has table scope)
371          */
372         TF_IDENT_TYPE_EM_PROF,
373         /** The L2 func is included in the ILT result and from recycling to
374          *  enable virtualization of further lookups.
375          */
376         TF_IDENT_TYPE_L2_FUNC
377 };
378
379 /**
380  * TCAM table type
381  */
382 enum tf_tcam_tbl_type {
383         TF_TCAM_TBL_TYPE_L2_CTXT_TCAM,
384         TF_TCAM_TBL_TYPE_PROF_TCAM,
385         TF_TCAM_TBL_TYPE_WC_TCAM,
386         TF_TCAM_TBL_TYPE_SP_TCAM,
387         TF_TCAM_TBL_TYPE_CT_RULE_TCAM,
388         TF_TCAM_TBL_TYPE_VEB_TCAM,
389         TF_TCAM_TBL_TYPE_MAX
390
391 };
392
393 /**
394  * Enumeration of TruFlow table types. A table type is used to identify a
395  * resource object.
396  *
397  * NOTE: The table type TF_TBL_TYPE_EXT is unique in that it is
398  * the only table type that is connected with a table scope.
399  */
400 enum tf_tbl_type {
401         /** Wh+/Brd2 Action Record */
402         TF_TBL_TYPE_FULL_ACT_RECORD,
403         /** Multicast Groups */
404         TF_TBL_TYPE_MCAST_GROUPS,
405         /** Action Encap 8 Bytes */
406         TF_TBL_TYPE_ACT_ENCAP_8B,
407         /** Action Encap 16 Bytes */
408         TF_TBL_TYPE_ACT_ENCAP_16B,
409         /** Action Encap 64 Bytes */
410         TF_TBL_TYPE_ACT_ENCAP_32B,
411         /** Action Encap 64 Bytes */
412         TF_TBL_TYPE_ACT_ENCAP_64B,
413         /** Action Source Properties SMAC */
414         TF_TBL_TYPE_ACT_SP_SMAC,
415         /** Action Source Properties SMAC IPv4 */
416         TF_TBL_TYPE_ACT_SP_SMAC_IPV4,
417         /** Action Source Properties SMAC IPv6 */
418         TF_TBL_TYPE_ACT_SP_SMAC_IPV6,
419         /** Action Statistics 64 Bits */
420         TF_TBL_TYPE_ACT_STATS_64,
421         /** Action Modify L4 Src Port */
422         TF_TBL_TYPE_ACT_MODIFY_SPORT,
423         /** Action Modify L4 Dest Port */
424         TF_TBL_TYPE_ACT_MODIFY_DPORT,
425         /** Action Modify IPv4 Source */
426         TF_TBL_TYPE_ACT_MODIFY_IPV4_SRC,
427         /** Action _Modify L4 Dest Port */
428         TF_TBL_TYPE_ACT_MODIFY_IPV4_DEST,
429         /** Action Modify IPv6 Source */
430         TF_TBL_TYPE_ACT_MODIFY_IPV6_SRC,
431         /** Action Modify IPv6 Destination */
432         TF_TBL_TYPE_ACT_MODIFY_IPV6_DEST,
433
434         /* HW */
435
436         /** Meter Profiles */
437         TF_TBL_TYPE_METER_PROF,
438         /** Meter Instance */
439         TF_TBL_TYPE_METER_INST,
440         /** Mirror Config */
441         TF_TBL_TYPE_MIRROR_CONFIG,
442         /** UPAR */
443         TF_TBL_TYPE_UPAR,
444         /** Brd4 Epoch 0 table */
445         TF_TBL_TYPE_EPOCH0,
446         /** Brd4 Epoch 1 table  */
447         TF_TBL_TYPE_EPOCH1,
448         /** Brd4 Metadata  */
449         TF_TBL_TYPE_METADATA,
450         /** Brd4 CT State  */
451         TF_TBL_TYPE_CT_STATE,
452         /** Brd4 Range Profile  */
453         TF_TBL_TYPE_RANGE_PROF,
454         /** Brd4 Range Entry  */
455         TF_TBL_TYPE_RANGE_ENTRY,
456         /** Brd4 LAG Entry  */
457         TF_TBL_TYPE_LAG,
458         /** Brd4 only VNIC/SVIF Table */
459         TF_TBL_TYPE_VNIC_SVIF,
460
461         /* External */
462
463         /** External table type - initially 1 poolsize entries.
464          * All External table types are associated with a table
465          * scope. Internal types are not.
466          */
467         TF_TBL_TYPE_EXT,
468         /** Future - external pool of size0 entries */
469         TF_TBL_TYPE_EXT_0,
470         TF_TBL_TYPE_MAX
471 };
472 #endif /* _TF_CORE_H_ */