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++) {
65 /* Currently populated by rte_eth_copy_pci_info().
67 * TODO: Once the PCI bus has arrived we should have a better
68 * way to test for being a PCI device or not.
70 if (rte_eth_devices[i].data->kdrv == RTE_KDRV_UNKNOWN ||
71 rte_eth_devices[i].data->kdrv == RTE_KDRV_NONE)
74 pci_dev = RTE_ETH_DEV_TO_PCI(&rte_eth_devices[i]);
75 eth_pci_addr = &pci_dev->addr;
77 if (pci_addr->bus == eth_pci_addr->bus &&
78 pci_addr->devid == eth_pci_addr->devid &&
79 pci_addr->domain == eth_pci_addr->domain &&
80 pci_addr->function == eth_pci_addr->function)
87 find_port_id_by_dev_name(const char *name)
91 for (i = 0; i < rte_eth_dev_count(); i++) {
92 if (rte_eth_devices[i].data == NULL)
95 if (strcmp(rte_eth_devices[i].device->name, name) == 0)
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;
111 /* try parsing as pci address, physical devices */
112 if (eal_parse_pci_DomBDF(port_str, &dev_addr) == 0) {
113 port_id = find_port_id_by_pci_addr(&dev_addr);
117 /* try parsing as device name, virtual devices */
118 port_id = find_port_id_by_dev_name(port_str);
123 /* try parsing as port id */
124 port_id = strtol(port_str, &end, 10);
125 if (*end != 0 || errno != 0)
130 if (port_id < 0 || port_id > RTE_MAX_ETHPORTS) {
131 RTE_BOND_LOG(ERR, "Slave port specified (%s) outside expected range",
139 bond_ethdev_parse_slave_port_kvarg(const char *key,
140 const char *value, void *extra_args)
142 struct bond_ethdev_slave_ports *slave_ports;
144 if (value == NULL || extra_args == NULL)
147 slave_ports = extra_args;
149 if (strcmp(key, PMD_BOND_SLAVE_PORT_KVARG) == 0) {
150 int port_id = parse_port_id(value);
152 RTE_BOND_LOG(ERR, "Invalid slave port value (%s) specified", value);
155 slave_ports->slaves[slave_ports->slave_count++] =
162 bond_ethdev_parse_slave_mode_kvarg(const char *key __rte_unused,
163 const char *value, void *extra_args)
168 if (value == NULL || extra_args == NULL)
174 *mode = strtol(value, &endptr, 10);
175 if (*endptr != 0 || errno != 0)
178 /* validate mode value */
180 case BONDING_MODE_ROUND_ROBIN:
181 case BONDING_MODE_ACTIVE_BACKUP:
182 case BONDING_MODE_BALANCE:
183 case BONDING_MODE_BROADCAST:
184 case BONDING_MODE_8023AD:
185 case BONDING_MODE_TLB:
186 case BONDING_MODE_ALB:
189 RTE_BOND_LOG(ERR, "Invalid slave mode value (%s) specified", value);
195 bond_ethdev_parse_slave_agg_mode_kvarg(const char *key __rte_unused,
196 const char *value, void *extra_args)
200 if (value == NULL || extra_args == NULL)
203 agg_mode = extra_args;
206 if (strncmp(value, "stable", 6) == 0)
207 *agg_mode = AGG_STABLE;
209 if (strncmp(value, "bandwidth", 9) == 0)
210 *agg_mode = AGG_BANDWIDTH;
212 if (strncmp(value, "count", 5) == 0)
213 *agg_mode = AGG_COUNT;
221 RTE_BOND_LOG(ERR, "Invalid agg mode value stable/bandwidth/count");
227 bond_ethdev_parse_socket_id_kvarg(const char *key __rte_unused,
228 const char *value, void *extra_args)
233 if (value == NULL || extra_args == NULL)
237 socket_id = (uint8_t)strtol(value, &endptr, 10);
238 if (*endptr != 0 || errno != 0)
241 /* validate socket id value */
242 if (socket_id >= 0) {
243 *(uint8_t *)extra_args = (uint8_t)socket_id;
250 bond_ethdev_parse_primary_slave_port_id_kvarg(const char *key __rte_unused,
251 const char *value, void *extra_args)
253 int primary_slave_port_id;
255 if (value == NULL || extra_args == NULL)
258 primary_slave_port_id = parse_port_id(value);
259 if (primary_slave_port_id < 0)
262 *(uint8_t *)extra_args = (uint8_t)primary_slave_port_id;
268 bond_ethdev_parse_balance_xmit_policy_kvarg(const char *key __rte_unused,
269 const char *value, void *extra_args)
271 uint8_t *xmit_policy;
273 if (value == NULL || extra_args == NULL)
276 xmit_policy = extra_args;
278 if (strcmp(PMD_BOND_XMIT_POLICY_LAYER2_KVARG, value) == 0)
279 *xmit_policy = BALANCE_XMIT_POLICY_LAYER2;
280 else if (strcmp(PMD_BOND_XMIT_POLICY_LAYER23_KVARG, value) == 0)
281 *xmit_policy = BALANCE_XMIT_POLICY_LAYER23;
282 else if (strcmp(PMD_BOND_XMIT_POLICY_LAYER34_KVARG, value) == 0)
283 *xmit_policy = BALANCE_XMIT_POLICY_LAYER34;
291 bond_ethdev_parse_bond_mac_addr_kvarg(const char *key __rte_unused,
292 const char *value, void *extra_args)
294 if (value == NULL || extra_args == NULL)
298 return cmdline_parse_etheraddr(NULL, value, extra_args,
299 sizeof(struct ether_addr));
303 bond_ethdev_parse_time_ms_kvarg(const char *key __rte_unused,
304 const char *value, void *extra_args)
309 if (value == NULL || extra_args == NULL)
313 time_ms = (uint32_t)strtol(value, &endptr, 10);
314 if (*endptr != 0 || errno != 0)
317 *(uint32_t *)extra_args = time_ms;