aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/bus/ifpga/ifpga_common.c
blob: 78e2eaee4e9ab0106f7b9de2a05a3cbd4a83f379 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2010-2018 Intel Corporation
 */

#include <string.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/queue.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>

#include <rte_errno.h>
#include <rte_bus.h>
#include <rte_per_lcore.h>
#include <rte_memory.h>
#include <rte_memzone.h>
#include <rte_eal.h>
#include <rte_common.h>

#include <rte_devargs.h>
#include <rte_kvargs.h>
#include <rte_alarm.h>

#include "rte_bus_ifpga.h"
#include "ifpga_logs.h"
#include "ifpga_common.h"

int rte_ifpga_get_string_arg(const char *key __rte_unused,
	const char *value, void *extra_args)
{
	if (!value || !extra_args)
		return -EINVAL;

	*(char **)extra_args = strdup(value);

	if (!*(char **)extra_args)
		return -ENOMEM;

	return 0;
}
int rte_ifpga_get_integer32_arg(const char *key __rte_unused,
	const char *value, void *extra_args)
{
	if (!value || !extra_args)
		return -EINVAL;

	*(int *)extra_args = strtoull(value, NULL, 0);

	return 0;
}
int ifpga_get_integer64_arg(const char *key __rte_unused,
	const char *value, void *extra_args)
{
	if (!value || !extra_args)
		return -EINVAL;

	*(uint64_t *)extra_args = strtoull(value, NULL, 0);

	return 0;
}
int ifpga_get_unsigned_long(const char *str, int base)
{
	unsigned long num;
	char *end = NULL;

	errno = 0;

	num = strtoul(str, &end, base);
	if ((str[0] == '\0') || (end == NULL) || (*end != '\0') || (errno != 0))
		return -1;

	return num;
}

int ifpga_afu_id_cmp(const struct rte_afu_id *afu_id0,
	const struct rte_afu_id *afu_id1)
{
	if ((afu_id0->uuid.uuid_low == afu_id1->uuid.uuid_low) &&
		(afu_id0->uuid.uuid_high == afu_id1->uuid.uuid_high) &&
		(afu_id0->port == afu_id1->port)) {
		return 0;
	} else
		return 1;
}