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 find_port_id_by_pci_addr(const struct rte_pci_addr *pci_addr)
28 struct rte_pci_device *pci_dev;
29 struct rte_pci_addr *eth_pci_addr;
32 RTE_ETH_FOREACH_DEV(i) {
33 pci_dev = RTE_ETH_DEV_TO_PCI(&rte_eth_devices[i]);
34 eth_pci_addr = &pci_dev->addr;
36 if (pci_addr->bus == eth_pci_addr->bus &&
37 pci_addr->devid == eth_pci_addr->devid &&
38 pci_addr->domain == eth_pci_addr->domain &&
39 pci_addr->function == eth_pci_addr->function)
46 find_port_id_by_dev_name(const char *name)
50 RTE_ETH_FOREACH_DEV(i) {
51 if (rte_eth_devices[i].data == NULL)
54 if (strcmp(rte_eth_devices[i].device->name, name) == 0)
61 bond_pci_addr_cmp(const struct rte_device *dev, const void *_pci_addr)
63 const struct rte_pci_device *pdev = RTE_DEV_TO_PCI_CONST(dev);
64 const struct rte_pci_addr *paddr = _pci_addr;
66 return rte_pci_addr_cmp(&pdev->addr, paddr);
70 * Parses a port identifier string to a port id by pci address, then by name,
71 * and finally port id.
74 parse_port_id(const char *port_str)
76 struct rte_pci_addr dev_addr;
77 struct rte_bus *pci_bus;
78 struct rte_device *dev;
81 pci_bus = rte_bus_find_by_name("pci");
82 if (pci_bus == NULL) {
83 RTE_BOND_LOG(ERR, "unable to find PCI bus\n");
87 /* try parsing as pci address, physical devices */
88 if (pci_bus->parse(port_str, &dev_addr) == 0) {
89 dev = pci_bus->find_device(NULL, bond_pci_addr_cmp, &dev_addr);
91 RTE_BOND_LOG(ERR, "unable to find PCI device");
94 port_id = find_port_id_by_pci_addr(&dev_addr);
98 /* try parsing as device name, virtual devices */
99 port_id = find_port_id_by_dev_name(port_str);
104 /* try parsing as port id */
105 port_id = strtol(port_str, &end, 10);
106 if (*end != 0 || errno != 0)
111 if (!rte_eth_dev_is_valid_port(port_id)) {
112 RTE_BOND_LOG(ERR, "Specified port (%s) is invalid", port_str);
119 bond_ethdev_parse_slave_port_kvarg(const char *key,
120 const char *value, void *extra_args)
122 struct bond_ethdev_slave_ports *slave_ports;
124 if (value == NULL || extra_args == NULL)
127 slave_ports = extra_args;
129 if (strcmp(key, PMD_BOND_SLAVE_PORT_KVARG) == 0) {
130 int port_id = parse_port_id(value);
132 RTE_BOND_LOG(ERR, "Invalid slave port value (%s) specified",
136 slave_ports->slaves[slave_ports->slave_count++] =
143 bond_ethdev_parse_slave_mode_kvarg(const char *key __rte_unused,
144 const char *value, void *extra_args)
149 if (value == NULL || extra_args == NULL)
155 *mode = strtol(value, &endptr, 10);
156 if (*endptr != 0 || errno != 0)
159 /* validate mode value */
161 case BONDING_MODE_ROUND_ROBIN:
162 case BONDING_MODE_ACTIVE_BACKUP:
163 case BONDING_MODE_BALANCE:
164 case BONDING_MODE_BROADCAST:
165 case BONDING_MODE_8023AD:
166 case BONDING_MODE_TLB:
167 case BONDING_MODE_ALB:
170 RTE_BOND_LOG(ERR, "Invalid slave mode value (%s) specified", value);
176 bond_ethdev_parse_slave_agg_mode_kvarg(const char *key __rte_unused,
177 const char *value, void *extra_args)
181 if (value == NULL || extra_args == NULL)
184 agg_mode = extra_args;
187 if (strncmp(value, "stable", 6) == 0)
188 *agg_mode = AGG_STABLE;
190 if (strncmp(value, "bandwidth", 9) == 0)
191 *agg_mode = AGG_BANDWIDTH;
193 if (strncmp(value, "count", 5) == 0)
194 *agg_mode = AGG_COUNT;
202 RTE_BOND_LOG(ERR, "Invalid agg mode value stable/bandwidth/count");
208 bond_ethdev_parse_socket_id_kvarg(const char *key __rte_unused,
209 const char *value, void *extra_args)
214 if (value == NULL || extra_args == NULL)
218 socket_id = (uint8_t)strtol(value, &endptr, 10);
219 if (*endptr != 0 || errno != 0)
222 /* validate socket id value */
223 if (socket_id >= 0) {
224 *(uint8_t *)extra_args = (uint8_t)socket_id;
231 bond_ethdev_parse_primary_slave_port_id_kvarg(const char *key __rte_unused,
232 const char *value, void *extra_args)
234 int primary_slave_port_id;
236 if (value == NULL || extra_args == NULL)
239 primary_slave_port_id = parse_port_id(value);
240 if (primary_slave_port_id < 0)
243 *(uint16_t *)extra_args = (uint16_t)primary_slave_port_id;
249 bond_ethdev_parse_balance_xmit_policy_kvarg(const char *key __rte_unused,
250 const char *value, void *extra_args)
252 uint8_t *xmit_policy;
254 if (value == NULL || extra_args == NULL)
257 xmit_policy = extra_args;
259 if (strcmp(PMD_BOND_XMIT_POLICY_LAYER2_KVARG, value) == 0)
260 *xmit_policy = BALANCE_XMIT_POLICY_LAYER2;
261 else if (strcmp(PMD_BOND_XMIT_POLICY_LAYER23_KVARG, value) == 0)
262 *xmit_policy = BALANCE_XMIT_POLICY_LAYER23;
263 else if (strcmp(PMD_BOND_XMIT_POLICY_LAYER34_KVARG, value) == 0)
264 *xmit_policy = BALANCE_XMIT_POLICY_LAYER34;
272 bond_ethdev_parse_bond_mac_addr_kvarg(const char *key __rte_unused,
273 const char *value, void *extra_args)
275 if (value == NULL || extra_args == NULL)
279 return rte_ether_unformat_addr(value, extra_args);
283 bond_ethdev_parse_time_ms_kvarg(const char *key __rte_unused,
284 const char *value, void *extra_args)
289 if (value == NULL || extra_args == NULL)
293 time_ms = (uint32_t)strtol(value, &endptr, 10);
294 if (*endptr != 0 || errno != 0)
297 *(uint32_t *)extra_args = time_ms;