NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
rmax_set_clock_sample.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 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 "rmax_common.h"
27 
28 DOCA_LOG_REGISTER(RMAX_SET_CLOCK);
29 
30 /*
31  * Sets PTP clock device to be used internally in DOCA RMAX
32  *
33  * @pcie_addr [in]: PCIe address, to set the PTP clock capability for
34  * @state [in]: a place holder for DOCA core related objects
35  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
36  */
37 doca_error_t set_clock(const char *pcie_addr, struct program_core_objects *state)
38 {
40 
41  /* open DOCA device with the given PCI address */
42  result = open_doca_device_with_pci(pcie_addr, NULL, &state->dev);
43  if (result != DOCA_SUCCESS)
44  return result;
45 
46  /* DOCA RMAX library Initialization */
47  result = doca_rmax_init();
48  if (result != DOCA_SUCCESS) {
49  DOCA_LOG_ERR("Failed to initialize DOCA RMAX library: %s", doca_error_get_descr(result));
50  destroy_core_objects(state);
51  return result;
52  }
53 
54  /* Set the device to use for obtaining PTP time */
55  result = doca_rmax_set_clock(state->dev);
56  if (result != DOCA_SUCCESS) {
57  DOCA_LOG_ERR("Failed to clock for the device to use for obtaining PTP time.: %s",
59  doca_rmax_release();
60  return result;
61  }
62 
63  result = doca_rmax_release();
64  if (result != DOCA_SUCCESS) {
65  DOCA_LOG_ERR("Failed to clock for the device to use for obtaining PTP time.: %s",
67  return result;
68  }
69 
70  return result;
71 }
#define NULL
Definition: __stddef_null.h:26
int32_t result
doca_error_t destroy_core_objects(struct program_core_objects *state)
Definition: common.c:392
static doca_error_t open_doca_device_with_pci(const char *pcie_value, struct doca_dev **retval)
Definition: device.c:43
enum doca_error doca_error_t
DOCA API return codes.
DOCA_STABLE const char * doca_error_get_descr(doca_error_t error)
Returns the description string of an error code.
@ DOCA_SUCCESS
Definition: doca_error.h:38
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
Definition: doca_log.h:466
doca_error_t set_clock(const char *pcie_addr, struct program_core_objects *state)
DOCA_LOG_REGISTER(RMAX_SET_CLOCK)
struct doca_dev * dev
Definition: common.h:46