1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
5 #include <rte_devargs.h>
7 #include <rte_bus_pci.h>
8 #include <rte_kvargs.h>
10 #include "rte_eth_bond.h"
11 #include "eth_bond_private.h"
13 const char *pmd_bond_init_valid_arguments[] = {
14 PMD_BOND_SLAVE_PORT_KVARG,
15 PMD_BOND_PRIMARY_SLAVE_KVARG,
17 PMD_BOND_XMIT_POLICY_KVARG,
18 PMD_BOND_SOCKET_ID_KVARG,
19 PMD_BOND_MAC_ADDR_KVARG,
20 PMD_BOND_AGG_MODE_KVARG,
26 bond_pci_addr_cmp(const struct rte_device *dev, const void *_pci_addr)
28 const struct rte_pci_device *pdev = RTE_DEV_TO_PCI_CONST(dev);
29 const struct rte_pci_addr *paddr = _pci_addr;
31 return rte_pci_addr_cmp(&pdev->addr, paddr);
35 find_port_id_by_pci_addr(const struct rte_pci_addr *pci_addr)
37 struct rte_bus *pci_bus;
38 struct rte_device *dev;
41 pci_bus = rte_bus_find_by_name("pci");
42 if (pci_bus == NULL) {
43 RTE_BOND_LOG(ERR, "No PCI bus found");
47 dev = pci_bus->find_device(NULL, bond_pci_addr_cmp, pci_addr);
49 RTE_BOND_LOG(ERR, "unable to find PCI device");
53 RTE_ETH_FOREACH_DEV(i)
54 if (rte_eth_devices[i].device == dev)
60 find_port_id_by_dev_name(const char *name)
64 RTE_ETH_FOREACH_DEV(i) {
65 if (rte_eth_devices[i].data == NULL)
68 if (strcmp(rte_eth_devices[i].device->name, name) == 0)
75 * Parses a port identifier string to a port id by pci address, then by name,
76 * and finally port id.
79 parse_port_id(const char *port_str)
81 struct rte_pci_addr dev_addr;
84 /* try parsing as pci address, physical devices */
85 if (rte_pci_addr_parse(port_str, &dev_addr) == 0) {
86 port_id = find_port_id_by_pci_addr(&dev_addr);
90 /* try parsing as device name, virtual devices */
91 port_id = find_port_id_by_dev_name(port_str);
96 /* try parsing as port id */
97 port_id = strtol(port_str, &end, 10);
98 if (*end != 0 || errno != 0)
103 if (!rte_eth_dev_is_valid_port(port_id)) {
104 RTE_BOND_LOG(ERR, "Specified port (%s) is invalid", port_str);
111 bond_ethdev_parse_slave_port_kvarg(const char *key,
112 const char *value, void *extra_args)
114 struct bond_ethdev_slave_ports *slave_ports;
116 if (value == NULL || extra_args == NULL)
119 slave_ports = extra_args;
121 if (strcmp(key, PMD_BOND_SLAVE_PORT_KVARG) == 0) {
122 int port_id = parse_port_id(value);
124 RTE_BOND_LOG(ERR, "Invalid slave port value (%s) specified",
128 slave_ports->slaves[slave_ports->slave_count++] =
135 bond_ethdev_parse_slave_mode_kvarg(const char *key __rte_unused,
136 const char *value, void *extra_args)
141 if (value == NULL || extra_args == NULL)
147 *mode = strtol(value, &endptr, 10);
148 if (*endptr != 0 || errno != 0)
151 /* validate mode value */
153 case BONDING_MODE_ROUND_ROBIN:
154 case BONDING_MODE_ACTIVE_BACKUP:
155 case BONDING_MODE_BALANCE:
156 case BONDING_MODE_BROADCAST:
157 case BONDING_MODE_8023AD:
158 case BONDING_MODE_TLB:
159 case BONDING_MODE_ALB:
162 RTE_BOND_LOG(ERR, "Invalid slave mode value (%s) specified", value);
168 bond_ethdev_parse_slave_agg_mode_kvarg(const char *key __rte_unused,
169 const char *value, void *extra_args)
173 if (value == NULL || extra_args == NULL)
176 agg_mode = extra_args;
179 if (strncmp(value, "stable", 6) == 0)
180 *agg_mode = AGG_STABLE;
182 if (strncmp(value, "bandwidth", 9) == 0)
183 *agg_mode = AGG_BANDWIDTH;
185 if (strncmp(value, "count", 5) == 0)
186 *agg_mode = AGG_COUNT;
194 RTE_BOND_LOG(ERR, "Invalid agg mode value stable/bandwidth/count");
200 bond_ethdev_parse_socket_id_kvarg(const char *key __rte_unused,
201 const char *value, void *extra_args)
206 if (value == NULL || extra_args == NULL)
210 socket_id = strtol(value, &endptr, 10);
211 if (*endptr != 0 || errno != 0)
214 /* validate socket id value */
215 if (socket_id >= 0 && socket_id < RTE_MAX_NUMA_NODES) {
216 *(int *)extra_args = (int)socket_id;
223 bond_ethdev_parse_primary_slave_port_id_kvarg(const char *key __rte_unused,
224 const char *value, void *extra_args)
226 int primary_slave_port_id;
228 if (value == NULL || extra_args == NULL)
231 primary_slave_port_id = parse_port_id(value);
232 if (primary_slave_port_id < 0)
235 *(uint16_t *)extra_args = (uint16_t)primary_slave_port_id;
241 bond_ethdev_parse_balance_xmit_policy_kvarg(const char *key __rte_unused,
242 const char *value, void *extra_args)
244 uint8_t *xmit_policy;
246 if (value == NULL || extra_args == NULL)
249 xmit_policy = extra_args;
251 if (strcmp(PMD_BOND_XMIT_POLICY_LAYER2_KVARG, value) == 0)
252 *xmit_policy = BALANCE_XMIT_POLICY_LAYER2;
253 else if (strcmp(PMD_BOND_XMIT_POLICY_LAYER23_KVARG, value) == 0)
254 *xmit_policy = BALANCE_XMIT_POLICY_LAYER23;
255 else if (strcmp(PMD_BOND_XMIT_POLICY_LAYER34_KVARG, value) == 0)
256 *xmit_policy = BALANCE_XMIT_POLICY_LAYER34;
264 bond_ethdev_parse_bond_mac_addr_kvarg(const char *key __rte_unused,
265 const char *value, void *extra_args)
267 if (value == NULL || extra_args == NULL)
271 return rte_ether_unformat_addr(value, extra_args);
275 bond_ethdev_parse_time_ms_kvarg(const char *key __rte_unused,
276 const char *value, void *extra_args)
281 if (value == NULL || extra_args == NULL)
285 time_ms = (uint32_t)strtol(value, &endptr, 10);
286 if (*endptr != 0 || errno != 0)
289 *(uint32_t *)extra_args = time_ms;