New upstream version 18.08
[deb_dpdk.git] / drivers / bus / ifpga / ifpga_common.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2018 Intel Corporation
3  */
4
5 #include <string.h>
6 #include <inttypes.h>
7 #include <stdint.h>
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <sys/queue.h>
11 #include <sys/mman.h>
12 #include <sys/types.h>
13 #include <unistd.h>
14 #include <fcntl.h>
15
16 #include <rte_errno.h>
17 #include <rte_bus.h>
18 #include <rte_per_lcore.h>
19 #include <rte_memory.h>
20 #include <rte_memzone.h>
21 #include <rte_eal.h>
22 #include <rte_common.h>
23
24 #include <rte_devargs.h>
25 #include <rte_kvargs.h>
26 #include <rte_alarm.h>
27
28 #include "rte_bus_ifpga.h"
29 #include "ifpga_logs.h"
30 #include "ifpga_common.h"
31
32 int rte_ifpga_get_string_arg(const char *key __rte_unused,
33         const char *value, void *extra_args)
34 {
35         if (!value || !extra_args)
36                 return -EINVAL;
37
38         *(char **)extra_args = strdup(value);
39
40         if (!*(char **)extra_args)
41                 return -ENOMEM;
42
43         return 0;
44 }
45 int rte_ifpga_get_integer32_arg(const char *key __rte_unused,
46         const char *value, void *extra_args)
47 {
48         if (!value || !extra_args)
49                 return -EINVAL;
50
51         *(int *)extra_args = strtoull(value, NULL, 0);
52
53         return 0;
54 }
55 int ifpga_get_integer64_arg(const char *key __rte_unused,
56         const char *value, void *extra_args)
57 {
58         if (!value || !extra_args)
59                 return -EINVAL;
60
61         *(uint64_t *)extra_args = strtoull(value, NULL, 0);
62
63         return 0;
64 }
65 int ifpga_get_unsigned_long(const char *str, int base)
66 {
67         unsigned long num;
68         char *end = NULL;
69
70         errno = 0;
71
72         num = strtoul(str, &end, base);
73         if ((str[0] == '\0') || (end == NULL) || (*end != '\0') || (errno != 0))
74                 return -1;
75
76         return num;
77 }
78
79 int ifpga_afu_id_cmp(const struct rte_afu_id *afu_id0,
80         const struct rte_afu_id *afu_id1)
81 {
82         if ((afu_id0->uuid.uuid_low == afu_id1->uuid.uuid_low) &&
83                 (afu_id0->uuid.uuid_high == afu_id1->uuid.uuid_high) &&
84                 (afu_id0->port == afu_id1->port)) {
85                 return 0;
86         } else
87                 return 1;
88 }