NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
np_nic_telemetry_dev_main.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 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_np_dev.h>
27 #include "pcc_common_dev.h"
28 
34 uint32_t counters_started = 0;
36 uint32_t ports_num = 0;
37 
45 FORCE_INLINE uint32_t count_ports(uint32_t ports_mask)
46 {
47  // find maximum port id enabled. Assume enabled ports are continuous
48  return doca_pcc_dev_fls(ports_mask);
49 }
50 
51 /*
52  * Called on link or port info state change.
53  * This callback is used to configure port counters to query RX bytes on
54  *
55  * @return - void
56  */
58 {
60  /* number of ports to initiate counters for */
62  /* Configure counters to read */
64  counters_started = 1;
66 }
67 
68 doca_pcc_dev_error_t doca_pcc_dev_np_user_packet_handler(struct doca_pcc_np_dev_request_packet *in,
70 {
71  uint32_t *send_ts_p = (uint32_t *)(out->data);
72  uint32_t *rx_256_bytes_p = (uint32_t *)(out->data + 4);
73  uint32_t *rx_ts_p = (uint32_t *)(out->data + 8);
74 
75  if (counters_started) {
76  *send_ts_p = __builtin_bswap32(*((uint32_t *)(doca_pcc_np_dev_get_payload(in))));
79  *rx_ts_p = doca_pcc_dev_get_timer_lo();
81  }
82 
84 }
#define __DPA_MEMORY
DPA 'Memory' memory space.
Definition: dpaintrin.h:32
#define __dpa_thread_fence(MEMORY_SPACE, PRED_OP, SUCC_OP)
Definition: dpaintrin.h:54
#define __DPA_W
Write memory operation.
Definition: dpaintrin.h:41
DOCA_EXPERIMENTAL ALWAYS_INLINE void doca_pcc_dev_nic_counters_sample(void)
Sample counters according to the prior configuration call.
DOCA_EXPERIMENTAL void doca_pcc_dev_nic_counters_config(uint32_t *counter_ids, uint32_t num_counters, uint32_t *values)
Prepare a list of counters to read.
#define DOCA_PCC_DEV_GET_PORT_COUNTER_ID(port, type, plane)
Generates a unique ID using the logical port number, counter type, and plane parameters for identifyi...
#define DOCA_PCC_DEV_MAX_NUM_PORTS
Max number of NIC ports supported by the lib.
#define FORCE_INLINE
static inline wrapper
void doca_pcc_dev_user_port_info_changed(uint32_t portid)
User callback triggered on a port state change.
doca_pcc_dev_error_t
API functions return status.
DOCA_EXPERIMENTAL uint32_t doca_pcc_dev_get_logical_ports(void)
Get mask of initiated logical ports.
@ DOCA_PCC_DEV_NIC_COUNTER_TYPE_RX_BYTES
@ DOCA_PCC_DEV_STATUS_OK
DOCA_EXPERIMENTAL ALWAYS_INLINE uint8_t * doca_pcc_np_dev_get_payload(const struct doca_pcc_np_dev_request_packet *input)
Returns a pointer to the payload of the packet.
DOCA_EXPERIMENTAL ALWAYS_INLINE uint8_t doca_pcc_np_dev_get_port_num(const struct doca_pcc_np_dev_request_packet *input)
Return logical port number on which input packet arrived.
doca_pcc_dev_error_t doca_pcc_dev_np_user_packet_handler(struct doca_pcc_np_dev_request_packet *in, struct doca_pcc_np_dev_response_packet *out)
Main user function (implemented by the user) Called by the lib upon receiving a packet....
#define doca_pcc_dev_fls(a)
32b find last set
DOCA_STABLE FORCE_INLINE uint32_t doca_pcc_dev_get_timer_lo(void)
Core timer access (elapsed time in uSec) function 32 bits.
uint32_t ports_num
uint32_t counter_ids[DOCA_PCC_DEV_MAX_NUM_PORTS]
FORCE_INLINE uint32_t count_ports(uint32_t ports_mask)
Count the number of available logical ports from queried mask.
uint32_t counters_started
uint32_t current_sampled_rx_bytes[DOCA_PCC_DEV_MAX_NUM_PORTS]
structure for response packet