Fix compilation for DPDK22.11
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / rapid / port_info / port_info.c
1 /*
2 // Copyright (c) 2019 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #include <stdint.h>
18 #include <inttypes.h>
19 #include <rte_eal.h>
20 #include <rte_ethdev.h>
21 #include <rte_version.h>
22
23 static const uint16_t rx_rings = 1, tx_rings = 1;
24 #if RTE_VERSION < RTE_VERSION_NUM(21,11,0,0)
25 static const struct rte_eth_conf port_conf = { .link_speeds = ETH_LINK_SPEED_AUTONEG };
26 #else
27 static const struct rte_eth_conf port_conf = { .link_speeds = RTE_ETH_LINK_SPEED_AUTONEG };
28 #endif
29
30 static inline int
31 port_info(void)
32 {
33         uint8_t port_id;
34         int ret_val;
35
36         RTE_ETH_FOREACH_DEV(port_id) {
37                 ret_val = rte_eth_dev_configure(port_id, rx_rings, tx_rings, &port_conf);
38                 if (ret_val != 0)
39                         return ret_val;
40
41 #if RTE_VERSION < RTE_VERSION_NUM(19,8,0,0)
42                 struct ether_addr addr;
43 #else
44                 struct rte_ether_addr addr;
45 #endif
46                 rte_eth_macaddr_get(port_id, &addr);
47                 printf("Port %u MAC: %02" PRIx8 ":%02" PRIx8 ":%02" PRIx8
48                                    ":%02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 "\n",
49                                 (unsigned) port_id,
50                                 addr.addr_bytes[0], addr.addr_bytes[1],
51                                 addr.addr_bytes[2], addr.addr_bytes[3],
52                                 addr.addr_bytes[4], addr.addr_bytes[5]);
53         }
54
55         return 0;
56 }
57
58 int
59 main(int argc, char *argv[])
60 {
61         /* Initialize the Environment Abstraction Layer (EAL). */
62         int ret = rte_eal_init(argc, argv);
63         if (ret < 0)
64                 rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");
65
66         argc -= ret;
67         argv += ret;
68
69         return port_info();
70 }