4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <rte_devargs.h>
36 #include <rte_kvargs.h>
38 #include <cmdline_parse.h>
39 #include <cmdline_parse_etheraddr.h>
41 #include "rte_eth_bond.h"
42 #include "rte_eth_bond_private.h"
44 const char *pmd_bond_init_valid_arguments[] = {
45 PMD_BOND_SLAVE_PORT_KVARG,
46 PMD_BOND_PRIMARY_SLAVE_KVARG,
48 PMD_BOND_XMIT_POLICY_KVARG,
49 PMD_BOND_SOCKET_ID_KVARG,
50 PMD_BOND_MAC_ADDR_KVARG,
51 PMD_BOND_AGG_MODE_KVARG,
57 find_port_id_by_pci_addr(const struct rte_pci_addr *pci_addr)
59 struct rte_pci_device *pci_dev;
60 struct rte_pci_addr *eth_pci_addr;
63 for (i = 0; i < rte_eth_dev_count(); i++) {
64 pci_dev = RTE_ETH_DEV_TO_PCI(&rte_eth_devices[i]);
65 eth_pci_addr = &pci_dev->addr;
67 if (pci_addr->bus == eth_pci_addr->bus &&
68 pci_addr->devid == eth_pci_addr->devid &&
69 pci_addr->domain == eth_pci_addr->domain &&
70 pci_addr->function == eth_pci_addr->function)
77 find_port_id_by_dev_name(const char *name)
81 for (i = 0; i < rte_eth_dev_count(); i++) {
82 if (rte_eth_devices[i].data == NULL)
85 if (strcmp(rte_eth_devices[i].device->name, name) == 0)
92 pci_addr_cmp(const struct rte_device *dev, const void *_pci_addr)
94 struct rte_pci_device *pdev;
95 const struct rte_pci_addr *paddr = _pci_addr;
97 pdev = RTE_DEV_TO_PCI(*(struct rte_device **)(void *)&dev);
98 return rte_eal_compare_pci_addr(&pdev->addr, paddr);
102 * Parses a port identifier string to a port id by pci address, then by name,
103 * and finally port id.
106 parse_port_id(const char *port_str)
108 struct rte_pci_addr dev_addr;
109 struct rte_bus *pci_bus;
110 struct rte_device *dev;
113 pci_bus = rte_bus_find_by_name("pci");
114 if (pci_bus == NULL) {
115 RTE_LOG(ERR, PMD, "unable to find PCI bus\n");
119 /* try parsing as pci address, physical devices */
120 if (pci_bus->parse(port_str, &dev_addr) == 0) {
121 dev = pci_bus->find_device(NULL, pci_addr_cmp, &dev_addr);
123 RTE_LOG(ERR, PMD, "unable to find PCI device\n");
126 port_id = find_port_id_by_pci_addr(&dev_addr);
130 /* try parsing as device name, virtual devices */
131 port_id = find_port_id_by_dev_name(port_str);
136 /* try parsing as port id */
137 port_id = strtol(port_str, &end, 10);
138 if (*end != 0 || errno != 0)
143 if (port_id < 0 || port_id > RTE_MAX_ETHPORTS) {
144 RTE_BOND_LOG(ERR, "Slave port specified (%s) outside expected range",
152 bond_ethdev_parse_slave_port_kvarg(const char *key,
153 const char *value, void *extra_args)
155 struct bond_ethdev_slave_ports *slave_ports;
157 if (value == NULL || extra_args == NULL)
160 slave_ports = extra_args;
162 if (strcmp(key, PMD_BOND_SLAVE_PORT_KVARG) == 0) {
163 int port_id = parse_port_id(value);
165 RTE_BOND_LOG(ERR, "Invalid slave port value (%s) specified", value);
168 slave_ports->slaves[slave_ports->slave_count++] =
175 bond_ethdev_parse_slave_mode_kvarg(const char *key __rte_unused,
176 const char *value, void *extra_args)
181 if (value == NULL || extra_args == NULL)
187 *mode = strtol(value, &endptr, 10);
188 if (*endptr != 0 || errno != 0)
191 /* validate mode value */
193 case BONDING_MODE_ROUND_ROBIN:
194 case BONDING_MODE_ACTIVE_BACKUP:
195 case BONDING_MODE_BALANCE:
196 case BONDING_MODE_BROADCAST:
197 case BONDING_MODE_8023AD:
198 case BONDING_MODE_TLB:
199 case BONDING_MODE_ALB:
202 RTE_BOND_LOG(ERR, "Invalid slave mode value (%s) specified", value);
208 bond_ethdev_parse_slave_agg_mode_kvarg(const char *key __rte_unused,
209 const char *value, void *extra_args)
213 if (value == NULL || extra_args == NULL)
216 agg_mode = extra_args;
219 if (strncmp(value, "stable", 6) == 0)
220 *agg_mode = AGG_STABLE;
222 if (strncmp(value, "bandwidth", 9) == 0)
223 *agg_mode = AGG_BANDWIDTH;
225 if (strncmp(value, "count", 5) == 0)
226 *agg_mode = AGG_COUNT;
234 RTE_BOND_LOG(ERR, "Invalid agg mode value stable/bandwidth/count");
240 bond_ethdev_parse_socket_id_kvarg(const char *key __rte_unused,
241 const char *value, void *extra_args)
246 if (value == NULL || extra_args == NULL)
250 socket_id = (uint8_t)strtol(value, &endptr, 10);
251 if (*endptr != 0 || errno != 0)
254 /* validate socket id value */
255 if (socket_id >= 0) {
256 *(uint8_t *)extra_args = (uint8_t)socket_id;
263 bond_ethdev_parse_primary_slave_port_id_kvarg(const char *key __rte_unused,
264 const char *value, void *extra_args)
266 int primary_slave_port_id;
268 if (value == NULL || extra_args == NULL)
271 primary_slave_port_id = parse_port_id(value);
272 if (primary_slave_port_id < 0)
275 *(uint8_t *)extra_args = (uint8_t)primary_slave_port_id;
281 bond_ethdev_parse_balance_xmit_policy_kvarg(const char *key __rte_unused,
282 const char *value, void *extra_args)
284 uint8_t *xmit_policy;
286 if (value == NULL || extra_args == NULL)
289 xmit_policy = extra_args;
291 if (strcmp(PMD_BOND_XMIT_POLICY_LAYER2_KVARG, value) == 0)
292 *xmit_policy = BALANCE_XMIT_POLICY_LAYER2;
293 else if (strcmp(PMD_BOND_XMIT_POLICY_LAYER23_KVARG, value) == 0)
294 *xmit_policy = BALANCE_XMIT_POLICY_LAYER23;
295 else if (strcmp(PMD_BOND_XMIT_POLICY_LAYER34_KVARG, value) == 0)
296 *xmit_policy = BALANCE_XMIT_POLICY_LAYER34;
304 bond_ethdev_parse_bond_mac_addr_kvarg(const char *key __rte_unused,
305 const char *value, void *extra_args)
307 if (value == NULL || extra_args == NULL)
311 return cmdline_parse_etheraddr(NULL, value, extra_args,
312 sizeof(struct ether_addr));
316 bond_ethdev_parse_time_ms_kvarg(const char *key __rte_unused,
317 const char *value, void *extra_args)
322 if (value == NULL || extra_args == NULL)
326 time_ms = (uint32_t)strtol(value, &endptr, 10);
327 if (*endptr != 0 || errno != 0)
330 *(uint32_t *)extra_args = time_ms;