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>
35 #include <rte_kvargs.h>
37 #include <cmdline_parse.h>
38 #include <cmdline_parse_etheraddr.h>
40 #include "rte_eth_bond.h"
41 #include "rte_eth_bond_private.h"
43 const char *pmd_bond_init_valid_arguments[] = {
44 PMD_BOND_SLAVE_PORT_KVARG,
45 PMD_BOND_PRIMARY_SLAVE_KVARG,
47 PMD_BOND_XMIT_POLICY_KVARG,
48 PMD_BOND_SOCKET_ID_KVARG,
49 PMD_BOND_MAC_ADDR_KVARG,
55 find_port_id_by_pci_addr(const struct rte_pci_addr *pci_addr)
57 struct rte_pci_addr *eth_pci_addr;
60 for (i = 0; i < rte_eth_dev_count(); i++) {
62 if (rte_eth_devices[i].pci_dev == NULL)
65 eth_pci_addr = &(rte_eth_devices[i].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].data->name, name) == 0)
92 * Parses a port identifier string to a port id by pci address, then by name,
93 * and finally port id.
96 parse_port_id(const char *port_str)
98 struct rte_pci_addr dev_addr;
101 /* try parsing as pci address, physical devices */
102 if (eal_parse_pci_DomBDF(port_str, &dev_addr) == 0) {
103 port_id = find_port_id_by_pci_addr(&dev_addr);
107 /* try parsing as device name, virtual devices */
108 port_id = find_port_id_by_dev_name(port_str);
113 /* try parsing as port id */
114 port_id = strtol(port_str, &end, 10);
115 if (*end != 0 || errno != 0)
120 if (port_id < 0 || port_id > RTE_MAX_ETHPORTS) {
121 RTE_BOND_LOG(ERR, "Slave port specified (%s) outside expected range",
129 bond_ethdev_parse_slave_port_kvarg(const char *key __rte_unused,
130 const char *value, void *extra_args)
132 struct bond_ethdev_slave_ports *slave_ports;
134 if (value == NULL || extra_args == NULL)
137 slave_ports = extra_args;
139 if (strcmp(key, PMD_BOND_SLAVE_PORT_KVARG) == 0) {
140 int port_id = parse_port_id(value);
142 RTE_BOND_LOG(ERR, "Invalid slave port value (%s) specified", value);
145 slave_ports->slaves[slave_ports->slave_count++] =
152 bond_ethdev_parse_slave_mode_kvarg(const char *key __rte_unused,
153 const char *value, void *extra_args)
158 if (value == NULL || extra_args == NULL)
164 *mode = strtol(value, &endptr, 10);
165 if (*endptr != 0 || errno != 0)
168 /* validate mode value */
170 case BONDING_MODE_ROUND_ROBIN:
171 case BONDING_MODE_ACTIVE_BACKUP:
172 case BONDING_MODE_BALANCE:
173 case BONDING_MODE_BROADCAST:
174 case BONDING_MODE_8023AD:
175 case BONDING_MODE_TLB:
176 case BONDING_MODE_ALB:
179 RTE_BOND_LOG(ERR, "Invalid slave mode value (%s) specified", value);
185 bond_ethdev_parse_socket_id_kvarg(const char *key __rte_unused,
186 const char *value, void *extra_args)
191 if (value == NULL || extra_args == NULL)
195 socket_id = (uint8_t)strtol(value, &endptr, 10);
196 if (*endptr != 0 || errno != 0)
199 /* validate mode value */
200 if (socket_id >= 0 && socket_id < number_of_sockets()) {
201 *(uint8_t *)extra_args = (uint8_t)socket_id;
208 bond_ethdev_parse_primary_slave_port_id_kvarg(const char *key __rte_unused,
209 const char *value, void *extra_args)
211 int primary_slave_port_id;
213 if (value == NULL || extra_args == NULL)
216 primary_slave_port_id = parse_port_id(value);
217 if (primary_slave_port_id < 0)
220 *(uint8_t *)extra_args = (uint8_t)primary_slave_port_id;
226 bond_ethdev_parse_balance_xmit_policy_kvarg(const char *key __rte_unused,
227 const char *value, void *extra_args)
229 uint8_t *xmit_policy;
231 if (value == NULL || extra_args == NULL)
234 xmit_policy = extra_args;
236 if (strcmp(PMD_BOND_XMIT_POLICY_LAYER2_KVARG, value) == 0)
237 *xmit_policy = BALANCE_XMIT_POLICY_LAYER2;
238 else if (strcmp(PMD_BOND_XMIT_POLICY_LAYER23_KVARG, value) == 0)
239 *xmit_policy = BALANCE_XMIT_POLICY_LAYER23;
240 else if (strcmp(PMD_BOND_XMIT_POLICY_LAYER34_KVARG, value) == 0)
241 *xmit_policy = BALANCE_XMIT_POLICY_LAYER34;
249 bond_ethdev_parse_bond_mac_addr_kvarg(const char *key __rte_unused,
250 const char *value, void *extra_args)
252 if (value == NULL || extra_args == NULL)
256 return cmdline_parse_etheraddr(NULL, value, extra_args,
257 sizeof(struct ether_addr));
261 bond_ethdev_parse_time_ms_kvarg(const char *key __rte_unused,
262 const char *value, void *extra_args)
267 if (value == NULL || extra_args == NULL)
271 time_ms = (uint32_t)strtol(value, &endptr, 10);
272 if (*endptr != 0 || errno != 0)
275 *(uint32_t *)extra_args = time_ms;