NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
rp_switch_telemetry_dev_main.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #include <doca_pcc_dev.h>
27 #include <doca_pcc_dev_event.h>
29 #include "pcc_common_dev.h"
30 #include "telem_template.h"
31 
32 #define DOCA_PCC_DEV_EVNT_ROCE_ACK_MASK (1 << DOCA_PCC_DEV_EVNT_ROCE_ACK)
33 
34 /*
35  * Main entry point to user CC algorithm (Reference code)
36  * This function starts the algorithm code of a single event
37  * It receives the flow context data, the event info and outputs the new rate parameters
38  * The function can support multiple algorithms and can call the per algorithm handler based on
39  * the algo type. If a single algorithm is required this code can be simplified
40  * The function can not be renamed as it is called by the handler infrastructure
41  *
42  * @algo_ctxt [in]: A pointer to a flow context data retrieved by libpcc.
43  * @event [in]: A pointer to an event data structure to be passed to extractor functions
44  * @attr [in]: A pointer to additional parameters (algo type).
45  * @results [out]: A pointer to result struct to update rate in HW.
46  */
48  doca_pcc_dev_event_t *event,
49  const doca_pcc_dev_attr_t *attr,
50  doca_pcc_dev_results_t *results)
51 {
52  uint32_t port_num = doca_pcc_dev_get_ev_attr(event).port_num;
53  uint32_t *param = doca_pcc_dev_get_algo_params(port_num, attr->algo_slot);
54  uint32_t *counter = doca_pcc_dev_get_counters(port_num, attr->algo_slot);
55 
56  switch (attr->algo_slot) {
57  case 0: {
58  telem_template_algo(event, param, counter, algo_ctxt, results);
59  break;
60  }
61  default: {
62  doca_pcc_dev_default_internal_algo(algo_ctxt, event, attr, results);
63  break;
64  }
65  };
66 }
67 
68 /*
69  * Main entry point to user algorithm initialization (reference code)
70  * This function starts the user algorithm initialization code
71  * The function will be called once per process load and should init all supported
72  * algorithms and all ports
73  *
74  * @disable_event_bitmask [out]: user code can tell the infrastructure which event
75  * types to ignore (mask out). Events of this type will be dropped and not passed to
76  * any algo
77  */
78 void doca_pcc_dev_user_init(uint32_t *disable_event_bitmask)
79 {
80  uint32_t algo_idx = 0, algo_slot = 0, algo_en = 1;
81 
82  /* Initialize algorithm with algo_idx=0 */
83  telem_template_init(algo_idx);
84 
85  for (int port_num = 0; port_num < DOCA_PCC_DEV_MAX_NUM_PORTS; ++port_num) {
86  /* Slot 0 will use algo_idx 0, default enabled */
87  doca_pcc_dev_init_algo_slot(port_num, algo_slot, algo_idx, algo_en);
88  doca_pcc_dev_trace_5(0, port_num, algo_idx, algo_slot, algo_en, DOCA_PCC_DEV_EVNT_ROCE_ACK_MASK);
89  }
90 
91  /* disable events of below type */
92  *disable_event_bitmask = DOCA_PCC_DEV_EVNT_ROCE_ACK_MASK;
94  *disable_event_bitmask |= (1 << DOCA_PCC_DEV_EVNT_ROCE_TX_FOR_ACK_NACK);
95  }
96 
97  doca_pcc_dev_printf("%s, disable_event_bitmask=0x%x\n", __func__, *disable_event_bitmask);
99 }
100 
101 /*
102  * Called when the parameter change was set externally.
103  * The implementation should:
104  * Check the given new_parameters values. If those are correct from the algorithm perspective,
105  * assign them to the given parameter array.
106 
107  * @port_num [in]: index of the port
108  * @algo_slot [in]: Algo slot identifier as referred to in the PPCC command field "algo_slot"
109  * if possible it should be equal to the algo_idx
110  * @param_id_base [in]: id of the first parameter that was changed.
111  * @param_num [in]: number of all parameters that were changed
112  * @new_param_values [in]: pointer to an array which holds param_num number of new values for parameters
113  * @params [in]: pointer to an array which holds beginning of the current parameters to be changed
114  * @return -
115  * DOCA_PCC_DEV_STATUS_OK: Parameters were set
116  * DOCA_PCC_DEV_STATUS_FAIL: the values (one or more) are not legal. No parameters were changed
117  */
119  uint32_t algo_slot,
120  uint32_t param_id_base,
121  uint32_t param_num,
122  const uint32_t *new_param_values,
123  uint32_t *params)
124 {
125  /* Notify the user that a change happened to take action.
126  * I.E.: Pre calculate values to be used in the algo that are based on the parameter value.
127  * Support more complex checks. E.G.: Param is a bit mask - min and max do not help
128  * Param dependency checking.
129  */
131 
132  switch (algo_slot) {
133  case 0: {
134  uint32_t algo_idx = doca_pcc_dev_get_algo_index(port_num, algo_slot);
135 
136  if (algo_idx == 0)
137  ret = telem_template_set_algo_params(param_id_base, param_num, new_param_values, params);
138  else
140 
141  break;
142  }
143  default:
144  break;
145  }
146  return ret;
147 }
DOCA_STABLE uint32_t * doca_pcc_dev_get_algo_params(uint32_t port_num, uint32_t algo_slot)
Get pointer to param array of a specific algo and specific port.
DOCA_STABLE uint32_t * doca_pcc_dev_get_counters(uint32_t port_num, uint32_t algo_slot)
Get pointer to counter array of a specific algo and specific port.
DOCA_STABLE doca_pcc_dev_error_t doca_pcc_dev_init_algo_slot(uint32_t portid, uint32_t algo_slot, uint32_t algo_idx, uint32_t algo_en)
Initialize the algo per port database.
DOCA_STABLE uint32_t doca_pcc_dev_get_algo_index(uint32_t port_num, uint32_t algo_slot)
Get identifier of a specific algo and specific port.
#define DOCA_PCC_DEV_MAX_NUM_PORTS
Max number of NIC ports supported by the lib.
doca_pcc_dev_error_t
API functions return status.
@ DOCA_PCC_DEV_STATUS_OK
@ DOCA_PCC_DEV_STATUS_FAIL
DOCA_STABLE FORCE_INLINE doca_pcc_dev_event_general_attr_t doca_pcc_dev_get_ev_attr(doca_pcc_dev_event_t *event)
For all events, return structure with general information such as event type, subtype,...
DOCA_STABLE void doca_pcc_dev_trace_flush(void)
Flush the trace message buffer to Host.
DOCA_STABLE void DOCA_STABLE void doca_pcc_dev_trace_5(int format_id, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5)
Creates trace message entry with 5 arguments.
DOCA_STABLE void doca_pcc_dev_printf(const char *format,...) __attribute__((format(printf
Print to Host.
doca_pcc_dev_error_t doca_pcc_dev_user_set_algo_params(uint32_t port_num, uint32_t algo_slot, uint32_t param_id_base, uint32_t param_num, const uint32_t *new_param_values, uint32_t *params)
User callback executed then parameters are set.
void doca_pcc_dev_user_init(uint32_t *disable_event_bitmask)
Entry point to the user one time initialization code.
DOCA_STABLE void doca_pcc_dev_default_internal_algo(doca_pcc_dev_algo_ctxt_t *algo_ctxt, doca_pcc_dev_event_t *event, const doca_pcc_dev_attr_t *attr, doca_pcc_dev_results_t *results)
Implements the internal CC algorithm provided by the lib.
void doca_pcc_dev_user_algo(doca_pcc_dev_algo_ctxt_t *algo_ctxt, doca_pcc_dev_event_t *event, const doca_pcc_dev_attr_t *attr, doca_pcc_dev_results_t *results)
Entry point to the user algorithm handling code.
#define DOCA_PCC_DEV_ACK_NACK_TX_EVENT_DISABLED_SUPPORTED
Definition: doca_pcc_dev.h:81
@ DOCA_PCC_DEV_EVNT_ROCE_TX_FOR_ACK_NACK
Definition: doca_pcc_dev.h:53
#define DOCA_PCC_DEV_EVNT_ROCE_ACK_MASK
CC algorithm results.
Definition: doca_pcc_dev.h:69
void telem_template_algo(doca_pcc_dev_event_t *event, uint32_t *param, uint32_t *counter, doca_pcc_dev_algo_ctxt_t *algo_ctxt, doca_pcc_dev_results_t *results)
doca_pcc_dev_error_t telem_template_set_algo_params(uint32_t param_id_base, uint32_t param_num, const uint32_t *new_param_values, uint32_t *params)
void telem_template_init(uint32_t algo_idx)