79bd0c0baef72c95ea9d6de69b9ce06e74404804
[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 static const struct rte_eth_conf port_conf = { .link_speeds = ETH_LINK_SPEED_AUTONEG };
25
26 static inline int
27 port_info(void)
28 {
29         uint8_t port_id;
30         int ret_val;
31
32         RTE_ETH_FOREACH_DEV(port_id) {
33                 ret_val = rte_eth_dev_configure(port_id, rx_rings, tx_rings, &port_conf);
34                 if (ret_val != 0)
35                         return ret_val;
36
37 #if RTE_VERSION < RTE_VERSION_NUM(19,8,0,0)
38                 struct ether_addr addr;
39 #else
40                 struct rte_ether_addr addr;
41 #endif
42                 rte_eth_macaddr_get(port_id, &addr);
43                 printf("Port %u MAC: %02" PRIx8 ":%02" PRIx8 ":%02" PRIx8
44                                    ":%02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 "\n",
45                                 (unsigned) port_id,
46                                 addr.addr_bytes[0], addr.addr_bytes[1],
47                                 addr.addr_bytes[2], addr.addr_bytes[3],
48                                 addr.addr_bytes[4], addr.addr_bytes[5]);
49         }
50
51         return 0;
52 }
53
54 int
55 main(int argc, char *argv[])
56 {
57         /* Initialize the Environment Abstraction Layer (EAL). */
58         int ret = rte_eal_init(argc, argv);
59         if (ret < 0)
60                 rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");
61
62         argc -= ret;
63         argv += ret;
64
65         return port_info();
66 }