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.
35 #include <rte_malloc.h>
36 #include <rte_ethdev.h>
40 #include <rte_devargs.h>
41 #include <rte_kvargs.h>
43 #include <rte_alarm.h>
45 #include "rte_eth_bond.h"
46 #include "rte_eth_bond_private.h"
47 #include "rte_eth_bond_8023ad_private.h"
50 bond_ethdev_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
52 struct bond_dev_private *internals;
54 uint16_t num_rx_slave = 0;
55 uint16_t num_rx_total = 0;
59 /* Cast to structure, containing bonded device's port id and queue id */
60 struct bond_rx_queue *bd_rx_q = (struct bond_rx_queue *)queue;
62 internals = bd_rx_q->dev_private;
65 for (i = 0; i < internals->active_slave_count && nb_pkts; i++) {
66 /* Offset of pointer to *bufs increases as packets are received
67 * from other slaves */
68 num_rx_slave = rte_eth_rx_burst(internals->active_slaves[i],
69 bd_rx_q->queue_id, bufs + num_rx_total, nb_pkts);
71 num_rx_total += num_rx_slave;
72 nb_pkts -= num_rx_slave;
80 bond_ethdev_rx_burst_active_backup(void *queue, struct rte_mbuf **bufs,
83 struct bond_dev_private *internals;
85 /* Cast to structure, containing bonded device's port id and queue id */
86 struct bond_rx_queue *bd_rx_q = (struct bond_rx_queue *)queue;
88 internals = bd_rx_q->dev_private;
90 return rte_eth_rx_burst(internals->current_primary_port,
91 bd_rx_q->queue_id, bufs, nb_pkts);
95 bond_ethdev_rx_burst_8023ad(void *queue, struct rte_mbuf **bufs,
98 /* Cast to structure, containing bonded device's port id and queue id */
99 struct bond_rx_queue *bd_rx_q = (struct bond_rx_queue *)queue;
100 struct bond_dev_private *internals = bd_rx_q->dev_private;
101 struct ether_addr bond_mac;
103 struct ether_hdr *hdr;
105 const uint16_t ether_type_slow_be = rte_be_to_cpu_16(ETHER_TYPE_SLOW);
106 uint16_t num_rx_total = 0; /* Total number of received packets */
107 uint8_t slaves[RTE_MAX_ETHPORTS];
110 uint8_t collecting; /* current slave collecting status */
111 const uint8_t promisc = internals->promiscuous_en;
114 rte_eth_macaddr_get(internals->port_id, &bond_mac);
115 /* Copy slave list to protect against slave up/down changes during tx
117 slave_count = internals->active_slave_count;
118 memcpy(slaves, internals->active_slaves,
119 sizeof(internals->active_slaves[0]) * slave_count);
121 for (i = 0; i < slave_count && num_rx_total < nb_pkts; i++) {
123 collecting = ACTOR_STATE(&mode_8023ad_ports[slaves[i]], COLLECTING);
125 /* Read packets from this slave */
126 num_rx_total += rte_eth_rx_burst(slaves[i], bd_rx_q->queue_id,
127 &bufs[num_rx_total], nb_pkts - num_rx_total);
129 for (k = j; k < 2 && k < num_rx_total; k++)
130 rte_prefetch0(rte_pktmbuf_mtod(bufs[k], void *));
132 /* Handle slow protocol packets. */
133 while (j < num_rx_total) {
134 if (j + 3 < num_rx_total)
135 rte_prefetch0(rte_pktmbuf_mtod(bufs[j + 3], void *));
137 hdr = rte_pktmbuf_mtod(bufs[j], struct ether_hdr *);
138 /* Remove packet from array if it is slow packet or slave is not
139 * in collecting state or bondign interface is not in promiscus
140 * mode and packet address does not match. */
141 if (unlikely(hdr->ether_type == ether_type_slow_be ||
142 !collecting || (!promisc &&
143 !is_same_ether_addr(&bond_mac, &hdr->d_addr)))) {
145 if (hdr->ether_type == ether_type_slow_be) {
146 bond_mode_8023ad_handle_slow_pkt(internals, slaves[i],
149 rte_pktmbuf_free(bufs[j]);
151 /* Packet is managed by mode 4 or dropped, shift the array */
153 if (j < num_rx_total) {
154 memmove(&bufs[j], &bufs[j + 1], sizeof(bufs[0]) *
166 bond_ethdev_tx_burst_round_robin(void *queue, struct rte_mbuf **bufs,
169 struct bond_dev_private *internals;
170 struct bond_tx_queue *bd_tx_q;
172 struct rte_mbuf *slave_bufs[RTE_MAX_ETHPORTS][nb_pkts];
173 uint16_t slave_nb_pkts[RTE_MAX_ETHPORTS] = { 0 };
175 uint8_t num_of_slaves;
176 uint8_t slaves[RTE_MAX_ETHPORTS];
178 uint16_t num_tx_total = 0, num_tx_slave;
180 static int slave_idx = 0;
181 int i, cslave_idx = 0, tx_fail_total = 0;
183 bd_tx_q = (struct bond_tx_queue *)queue;
184 internals = bd_tx_q->dev_private;
186 /* Copy slave list to protect against slave up/down changes during tx
188 num_of_slaves = internals->active_slave_count;
189 memcpy(slaves, internals->active_slaves,
190 sizeof(internals->active_slaves[0]) * num_of_slaves);
192 if (num_of_slaves < 1)
195 /* Populate slaves mbuf with which packets are to be sent on it */
196 for (i = 0; i < nb_pkts; i++) {
197 cslave_idx = (slave_idx + i) % num_of_slaves;
198 slave_bufs[cslave_idx][(slave_nb_pkts[cslave_idx])++] = bufs[i];
201 /* increment current slave index so the next call to tx burst starts on the
203 slave_idx = ++cslave_idx;
205 /* Send packet burst on each slave device */
206 for (i = 0; i < num_of_slaves; i++) {
207 if (slave_nb_pkts[i] > 0) {
208 num_tx_slave = rte_eth_tx_burst(slaves[i], bd_tx_q->queue_id,
209 slave_bufs[i], slave_nb_pkts[i]);
211 /* if tx burst fails move packets to end of bufs */
212 if (unlikely(num_tx_slave < slave_nb_pkts[i])) {
213 int tx_fail_slave = slave_nb_pkts[i] - num_tx_slave;
215 tx_fail_total += tx_fail_slave;
217 memcpy(&bufs[nb_pkts - tx_fail_total],
218 &slave_bufs[i][num_tx_slave],
219 tx_fail_slave * sizeof(bufs[0]));
221 num_tx_total += num_tx_slave;
229 bond_ethdev_tx_burst_active_backup(void *queue,
230 struct rte_mbuf **bufs, uint16_t nb_pkts)
232 struct bond_dev_private *internals;
233 struct bond_tx_queue *bd_tx_q;
235 bd_tx_q = (struct bond_tx_queue *)queue;
236 internals = bd_tx_q->dev_private;
238 if (internals->active_slave_count < 1)
241 return rte_eth_tx_burst(internals->current_primary_port, bd_tx_q->queue_id,
245 static inline uint16_t
246 ether_hash(struct ether_hdr *eth_hdr)
248 uint16_t *word_src_addr = (uint16_t *)eth_hdr->s_addr.addr_bytes;
249 uint16_t *word_dst_addr = (uint16_t *)eth_hdr->d_addr.addr_bytes;
251 return (word_src_addr[0] ^ word_dst_addr[0]) ^
252 (word_src_addr[1] ^ word_dst_addr[1]) ^
253 (word_src_addr[2] ^ word_dst_addr[2]);
256 static inline uint32_t
257 ipv4_hash(struct ipv4_hdr *ipv4_hdr)
259 return (ipv4_hdr->src_addr ^ ipv4_hdr->dst_addr);
262 static inline uint32_t
263 ipv6_hash(struct ipv6_hdr *ipv6_hdr)
265 uint32_t *word_src_addr = (uint32_t *)&(ipv6_hdr->src_addr[0]);
266 uint32_t *word_dst_addr = (uint32_t *)&(ipv6_hdr->dst_addr[0]);
268 return (word_src_addr[0] ^ word_dst_addr[0]) ^
269 (word_src_addr[1] ^ word_dst_addr[1]) ^
270 (word_src_addr[2] ^ word_dst_addr[2]) ^
271 (word_src_addr[3] ^ word_dst_addr[3]);
275 udp_hash(struct udp_hdr *hdr)
277 return hdr->src_port ^ hdr->dst_port;
280 static inline uint16_t
281 xmit_slave_hash(const struct rte_mbuf *buf, uint8_t slave_count, uint8_t policy)
283 struct ether_hdr *eth_hdr;
284 struct udp_hdr *udp_hdr;
285 size_t eth_offset = 0;
288 if (slave_count == 1)
292 case BALANCE_XMIT_POLICY_LAYER2:
293 eth_hdr = rte_pktmbuf_mtod(buf, struct ether_hdr *);
295 hash = ether_hash(eth_hdr);
297 return hash % slave_count;
299 case BALANCE_XMIT_POLICY_LAYER23:
300 eth_hdr = rte_pktmbuf_mtod(buf, struct ether_hdr *);
302 if (buf->ol_flags & PKT_RX_VLAN_PKT)
303 eth_offset = sizeof(struct ether_hdr) + sizeof(struct vlan_hdr);
305 eth_offset = sizeof(struct ether_hdr);
307 if (buf->ol_flags & PKT_RX_IPV4_HDR) {
308 struct ipv4_hdr *ipv4_hdr;
309 ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(buf,
310 unsigned char *) + eth_offset);
312 hash = ether_hash(eth_hdr) ^ ipv4_hash(ipv4_hdr);
315 struct ipv6_hdr *ipv6_hdr;
317 ipv6_hdr = (struct ipv6_hdr *)(rte_pktmbuf_mtod(buf,
318 unsigned char *) + eth_offset);
320 hash = ether_hash(eth_hdr) ^ ipv6_hash(ipv6_hdr);
324 case BALANCE_XMIT_POLICY_LAYER34:
325 if (buf->ol_flags & PKT_RX_VLAN_PKT)
326 eth_offset = sizeof(struct ether_hdr) + sizeof(struct vlan_hdr);
328 eth_offset = sizeof(struct ether_hdr);
330 if (buf->ol_flags & PKT_RX_IPV4_HDR) {
331 struct ipv4_hdr *ipv4_hdr = (struct ipv4_hdr *)
332 (rte_pktmbuf_mtod(buf, unsigned char *) + eth_offset);
334 if (ipv4_hdr->next_proto_id == IPPROTO_UDP) {
335 udp_hdr = (struct udp_hdr *)
336 (rte_pktmbuf_mtod(buf, unsigned char *) + eth_offset +
337 sizeof(struct ipv4_hdr));
338 hash = ipv4_hash(ipv4_hdr) ^ udp_hash(udp_hdr);
340 hash = ipv4_hash(ipv4_hdr);
343 struct ipv6_hdr *ipv6_hdr = (struct ipv6_hdr *)
344 (rte_pktmbuf_mtod(buf, unsigned char *) + eth_offset);
346 if (ipv6_hdr->proto == IPPROTO_UDP) {
347 udp_hdr = (struct udp_hdr *)
348 (rte_pktmbuf_mtod(buf, unsigned char *) + eth_offset +
349 sizeof(struct ipv6_hdr));
350 hash = ipv6_hash(ipv6_hdr) ^ udp_hash(udp_hdr);
352 hash = ipv6_hash(ipv6_hdr);
361 return hash % slave_count;
365 bond_ethdev_tx_burst_balance(void *queue, struct rte_mbuf **bufs,
368 struct bond_dev_private *internals;
369 struct bond_tx_queue *bd_tx_q;
371 uint8_t num_of_slaves;
372 uint8_t slaves[RTE_MAX_ETHPORTS];
374 uint16_t num_tx_total = 0, num_tx_slave = 0, tx_fail_total = 0;
378 struct rte_mbuf *slave_bufs[RTE_MAX_ETHPORTS][nb_pkts];
379 uint16_t slave_nb_pkts[RTE_MAX_ETHPORTS] = { 0 };
381 bd_tx_q = (struct bond_tx_queue *)queue;
382 internals = bd_tx_q->dev_private;
384 /* Copy slave list to protect against slave up/down changes during tx
386 num_of_slaves = internals->active_slave_count;
387 memcpy(slaves, internals->active_slaves,
388 sizeof(internals->active_slaves[0]) * num_of_slaves);
390 if (num_of_slaves < 1)
393 /* Populate slaves mbuf with the packets which are to be sent on it */
394 for (i = 0; i < nb_pkts; i++) {
395 /* Select output slave using hash based on xmit policy */
396 op_slave_id = xmit_slave_hash(bufs[i], num_of_slaves,
397 internals->balance_xmit_policy);
399 /* Populate slave mbuf arrays with mbufs for that slave */
400 slave_bufs[op_slave_id][slave_nb_pkts[op_slave_id]++] = bufs[i];
403 /* Send packet burst on each slave device */
404 for (i = 0; i < num_of_slaves; i++) {
405 if (slave_nb_pkts[i] > 0) {
406 num_tx_slave = rte_eth_tx_burst(slaves[i], bd_tx_q->queue_id,
407 slave_bufs[i], slave_nb_pkts[i]);
409 /* if tx burst fails move packets to end of bufs */
410 if (unlikely(num_tx_slave < slave_nb_pkts[i])) {
411 int slave_tx_fail_count = slave_nb_pkts[i] - num_tx_slave;
413 tx_fail_total += slave_tx_fail_count;
414 memcpy(&bufs[nb_pkts - tx_fail_total],
415 &slave_bufs[i][num_tx_slave],
416 slave_tx_fail_count * sizeof(bufs[0]));
419 num_tx_total += num_tx_slave;
427 bond_ethdev_tx_burst_8023ad(void *queue, struct rte_mbuf **bufs,
430 struct bond_dev_private *internals;
431 struct bond_tx_queue *bd_tx_q;
433 uint8_t num_of_slaves;
434 uint8_t slaves[RTE_MAX_ETHPORTS];
435 /* possitions in slaves, not ID */
436 uint8_t distributing_offsets[RTE_MAX_ETHPORTS];
437 uint8_t distributing_count;
439 uint16_t num_tx_slave, num_tx_total = 0, num_tx_fail_total = 0;
440 uint16_t i, j, op_slave_idx;
441 const uint16_t buffs_size = nb_pkts + BOND_MODE_8023AX_SLAVE_TX_PKTS + 1;
443 /* Allocate additional packets in case 8023AD mode. */
444 struct rte_mbuf *slave_bufs[RTE_MAX_ETHPORTS][buffs_size];
445 void *slow_pkts[BOND_MODE_8023AX_SLAVE_TX_PKTS];
447 /* Total amount of packets in slave_bufs */
448 uint16_t slave_nb_pkts[RTE_MAX_ETHPORTS] = { 0 };
449 /* Slow packets placed in each slave */
450 uint8_t slave_slow_nb_pkts[RTE_MAX_ETHPORTS] = { 0 };
452 bd_tx_q = (struct bond_tx_queue *)queue;
453 internals = bd_tx_q->dev_private;
455 /* Copy slave list to protect against slave up/down changes during tx
457 num_of_slaves = internals->active_slave_count;
458 if (num_of_slaves < 1)
461 memcpy(slaves, internals->active_slaves, sizeof(slaves[0]) * num_of_slaves);
463 distributing_count = 0;
464 for (i = 0; i < num_of_slaves; i++) {
465 struct port *port = &mode_8023ad_ports[slaves[i]];
467 slave_slow_nb_pkts[i] = rte_ring_dequeue_burst(port->tx_ring,
468 slow_pkts, BOND_MODE_8023AX_SLAVE_TX_PKTS);
469 slave_nb_pkts[i] = slave_slow_nb_pkts[i];
471 for (j = 0; j < slave_slow_nb_pkts[i]; j++)
472 slave_bufs[i][j] = slow_pkts[j];
474 if (ACTOR_STATE(port, DISTRIBUTING))
475 distributing_offsets[distributing_count++] = i;
478 if (likely(distributing_count > 0)) {
479 /* Populate slaves mbuf with the packets which are to be sent on it */
480 for (i = 0; i < nb_pkts; i++) {
481 /* Select output slave using hash based on xmit policy */
482 op_slave_idx = xmit_slave_hash(bufs[i], distributing_count,
483 internals->balance_xmit_policy);
485 /* Populate slave mbuf arrays with mbufs for that slave. Use only
486 * slaves that are currently distributing. */
487 uint8_t slave_offset = distributing_offsets[op_slave_idx];
488 slave_bufs[slave_offset][slave_nb_pkts[slave_offset]] = bufs[i];
489 slave_nb_pkts[slave_offset]++;
493 /* Send packet burst on each slave device */
494 for (i = 0; i < num_of_slaves; i++) {
495 if (slave_nb_pkts[i] == 0)
498 num_tx_slave = rte_eth_tx_burst(slaves[i], bd_tx_q->queue_id,
499 slave_bufs[i], slave_nb_pkts[i]);
501 /* If tx burst fails drop slow packets */
502 for ( ; num_tx_slave < slave_slow_nb_pkts[i]; num_tx_slave++)
503 rte_pktmbuf_free(slave_bufs[i][num_tx_slave]);
505 num_tx_total += num_tx_slave - slave_slow_nb_pkts[i];
506 num_tx_fail_total += slave_nb_pkts[i] - num_tx_slave;
508 /* If tx burst fails move packets to end of bufs */
509 if (unlikely(num_tx_slave < slave_nb_pkts[i])) {
510 uint16_t j = nb_pkts - num_tx_fail_total;
511 for ( ; num_tx_slave < slave_nb_pkts[i]; j++, num_tx_slave++)
512 bufs[j] = slave_bufs[i][num_tx_slave];
519 #ifdef RTE_MBUF_REFCNT
521 bond_ethdev_tx_burst_broadcast(void *queue, struct rte_mbuf **bufs,
524 struct bond_dev_private *internals;
525 struct bond_tx_queue *bd_tx_q;
527 uint8_t tx_failed_flag = 0, num_of_slaves;
528 uint8_t slaves[RTE_MAX_ETHPORTS];
530 uint16_t max_nb_of_tx_pkts = 0;
532 int slave_tx_total[RTE_MAX_ETHPORTS];
533 int i, most_successful_tx_slave = -1;
535 bd_tx_q = (struct bond_tx_queue *)queue;
536 internals = bd_tx_q->dev_private;
538 /* Copy slave list to protect against slave up/down changes during tx
540 num_of_slaves = internals->active_slave_count;
541 memcpy(slaves, internals->active_slaves,
542 sizeof(internals->active_slaves[0]) * num_of_slaves);
544 if (num_of_slaves < 1)
547 /* Increment reference count on mbufs */
548 for (i = 0; i < nb_pkts; i++)
549 rte_mbuf_refcnt_update(bufs[i], num_of_slaves - 1);
551 /* Transmit burst on each active slave */
552 for (i = 0; i < num_of_slaves; i++) {
553 slave_tx_total[i] = rte_eth_tx_burst(slaves[i], bd_tx_q->queue_id,
556 if (unlikely(slave_tx_total[i] < nb_pkts))
559 /* record the value and slave index for the slave which transmits the
560 * maximum number of packets */
561 if (slave_tx_total[i] > max_nb_of_tx_pkts) {
562 max_nb_of_tx_pkts = slave_tx_total[i];
563 most_successful_tx_slave = i;
567 /* if slaves fail to transmit packets from burst, the calling application
568 * is not expected to know about multiple references to packets so we must
569 * handle failures of all packets except those of the most successful slave
571 if (unlikely(tx_failed_flag))
572 for (i = 0; i < num_of_slaves; i++)
573 if (i != most_successful_tx_slave)
574 while (slave_tx_total[i] < nb_pkts)
575 rte_pktmbuf_free(bufs[slave_tx_total[i]++]);
577 return max_nb_of_tx_pkts;
582 link_properties_set(struct rte_eth_dev *bonded_eth_dev,
583 struct rte_eth_link *slave_dev_link)
585 struct rte_eth_link *bonded_dev_link = &bonded_eth_dev->data->dev_link;
586 struct bond_dev_private *internals = bonded_eth_dev->data->dev_private;
588 if (slave_dev_link->link_status &&
589 bonded_eth_dev->data->dev_started) {
590 bonded_dev_link->link_duplex = slave_dev_link->link_duplex;
591 bonded_dev_link->link_speed = slave_dev_link->link_speed;
593 internals->link_props_set = 1;
598 link_properties_reset(struct rte_eth_dev *bonded_eth_dev)
600 struct bond_dev_private *internals = bonded_eth_dev->data->dev_private;
602 memset(&(bonded_eth_dev->data->dev_link), 0,
603 sizeof(bonded_eth_dev->data->dev_link));
605 internals->link_props_set = 0;
609 link_properties_valid(struct rte_eth_link *bonded_dev_link,
610 struct rte_eth_link *slave_dev_link)
612 if (bonded_dev_link->link_duplex != slave_dev_link->link_duplex ||
613 bonded_dev_link->link_speed != slave_dev_link->link_speed)
620 mac_address_get(struct rte_eth_dev *eth_dev, struct ether_addr *dst_mac_addr)
622 struct ether_addr *mac_addr;
624 mac_addr = eth_dev->data->mac_addrs;
626 if (eth_dev == NULL) {
627 RTE_LOG(ERR, PMD, "%s: NULL pointer eth_dev specified\n", __func__);
631 if (dst_mac_addr == NULL) {
632 RTE_LOG(ERR, PMD, "%s: NULL pointer MAC specified\n", __func__);
636 ether_addr_copy(mac_addr, dst_mac_addr);
641 mac_address_set(struct rte_eth_dev *eth_dev, struct ether_addr *new_mac_addr)
643 struct ether_addr *mac_addr;
645 mac_addr = eth_dev->data->mac_addrs;
647 if (eth_dev == NULL) {
648 RTE_BOND_LOG(ERR, "NULL pointer eth_dev specified");
652 if (new_mac_addr == NULL) {
653 RTE_BOND_LOG(ERR, "NULL pointer MAC specified");
657 /* If new MAC is different to current MAC then update */
658 if (memcmp(mac_addr, new_mac_addr, sizeof(*mac_addr)) != 0)
659 memcpy(mac_addr, new_mac_addr, sizeof(*mac_addr));
665 mac_address_slaves_update(struct rte_eth_dev *bonded_eth_dev)
667 struct bond_dev_private *internals = bonded_eth_dev->data->dev_private;
670 /* Update slave devices MAC addresses */
671 if (internals->slave_count < 1)
674 switch (internals->mode) {
675 case BONDING_MODE_ROUND_ROBIN:
676 case BONDING_MODE_BALANCE:
677 #ifdef RTE_MBUF_REFCNT
678 case BONDING_MODE_BROADCAST:
680 for (i = 0; i < internals->slave_count; i++) {
681 if (mac_address_set(&rte_eth_devices[internals->slaves[i].port_id],
682 bonded_eth_dev->data->mac_addrs)) {
683 RTE_BOND_LOG(ERR, "Failed to update port Id %d MAC address",
684 internals->slaves[i].port_id);
689 case BONDING_MODE_8023AD:
690 bond_mode_8023ad_mac_address_update(bonded_eth_dev);
692 case BONDING_MODE_ACTIVE_BACKUP:
694 for (i = 0; i < internals->slave_count; i++) {
695 if (internals->slaves[i].port_id ==
696 internals->current_primary_port) {
697 if (mac_address_set(&rte_eth_devices[internals->primary_port],
698 bonded_eth_dev->data->mac_addrs)) {
699 RTE_BOND_LOG(ERR, "Failed to update port Id %d MAC address",
700 internals->current_primary_port);
705 &rte_eth_devices[internals->slaves[i].port_id],
706 &internals->slaves[i].persisted_mac_addr)) {
707 RTE_BOND_LOG(ERR, "Failed to update port Id %d MAC address",
708 internals->slaves[i].port_id);
719 bond_ethdev_mode_set(struct rte_eth_dev *eth_dev, int mode)
721 struct bond_dev_private *internals;
723 internals = eth_dev->data->dev_private;
726 case BONDING_MODE_ROUND_ROBIN:
727 eth_dev->tx_pkt_burst = bond_ethdev_tx_burst_round_robin;
728 eth_dev->rx_pkt_burst = bond_ethdev_rx_burst;
730 case BONDING_MODE_ACTIVE_BACKUP:
731 eth_dev->tx_pkt_burst = bond_ethdev_tx_burst_active_backup;
732 eth_dev->rx_pkt_burst = bond_ethdev_rx_burst_active_backup;
734 case BONDING_MODE_BALANCE:
735 eth_dev->tx_pkt_burst = bond_ethdev_tx_burst_balance;
736 eth_dev->rx_pkt_burst = bond_ethdev_rx_burst;
738 #ifdef RTE_MBUF_REFCNT
739 case BONDING_MODE_BROADCAST:
740 eth_dev->tx_pkt_burst = bond_ethdev_tx_burst_broadcast;
741 eth_dev->rx_pkt_burst = bond_ethdev_rx_burst;
744 case BONDING_MODE_8023AD:
745 if (bond_mode_8023ad_enable(eth_dev) != 0)
748 eth_dev->rx_pkt_burst = bond_ethdev_rx_burst_8023ad;
749 eth_dev->tx_pkt_burst = bond_ethdev_tx_burst_8023ad;
750 RTE_BOND_LOG(WARNING,
751 "Using mode 4, it is necessary to do TX burst and RX burst "
752 "at least every 100ms.");
758 internals->mode = mode;
764 slave_configure(struct rte_eth_dev *bonded_eth_dev,
765 struct rte_eth_dev *slave_eth_dev)
767 struct bond_rx_queue *bd_rx_q;
768 struct bond_tx_queue *bd_tx_q;
773 rte_eth_dev_stop(slave_eth_dev->data->port_id);
775 /* Enable interrupts on slave device if supported */
776 if (slave_eth_dev->driver->pci_drv.drv_flags & RTE_PCI_DRV_INTR_LSC)
777 slave_eth_dev->data->dev_conf.intr_conf.lsc = 1;
779 /* Configure device */
780 errval = rte_eth_dev_configure(slave_eth_dev->data->port_id,
781 bonded_eth_dev->data->nb_rx_queues,
782 bonded_eth_dev->data->nb_tx_queues,
783 &(slave_eth_dev->data->dev_conf));
785 RTE_BOND_LOG(ERR, "Cannot configure slave device: port %u , err (%d)",
786 slave_eth_dev->data->port_id, errval);
790 /* Setup Rx Queues */
791 for (q_id = 0; q_id < bonded_eth_dev->data->nb_rx_queues; q_id++) {
792 bd_rx_q = (struct bond_rx_queue *)bonded_eth_dev->data->rx_queues[q_id];
794 errval = rte_eth_rx_queue_setup(slave_eth_dev->data->port_id, q_id,
796 rte_eth_dev_socket_id(slave_eth_dev->data->port_id),
797 &(bd_rx_q->rx_conf), bd_rx_q->mb_pool);
800 "rte_eth_rx_queue_setup: port=%d queue_id %d, err (%d)",
801 slave_eth_dev->data->port_id, q_id, errval);
806 /* Setup Tx Queues */
807 for (q_id = 0; q_id < bonded_eth_dev->data->nb_tx_queues; q_id++) {
808 bd_tx_q = (struct bond_tx_queue *)bonded_eth_dev->data->tx_queues[q_id];
810 errval = rte_eth_tx_queue_setup(slave_eth_dev->data->port_id, q_id,
812 rte_eth_dev_socket_id(slave_eth_dev->data->port_id),
816 "rte_eth_tx_queue_setup: port=%d queue_id %d, err (%d)",
817 slave_eth_dev->data->port_id, q_id, errval);
823 errval = rte_eth_dev_start(slave_eth_dev->data->port_id);
825 RTE_BOND_LOG(ERR, "rte_eth_dev_start: port=%u, err (%d)",
826 slave_eth_dev->data->port_id, errval);
834 slave_remove(struct bond_dev_private *internals,
835 struct rte_eth_dev *slave_eth_dev)
839 for (i = 0; i < internals->slave_count; i++) {
840 if (internals->slaves[i].port_id == slave_eth_dev->data->port_id)
843 if (found && i < (internals->slave_count - 1))
844 memcpy(&internals->slaves[i], &internals->slaves[i+1],
845 sizeof(internals->slaves[i]));
848 internals->slave_count--;
852 bond_ethdev_slave_link_status_change_monitor(void *cb_arg);
855 slave_add(struct bond_dev_private *internals,
856 struct rte_eth_dev *slave_eth_dev)
858 struct bond_slave_details *slave_details =
859 &internals->slaves[internals->slave_count];
861 slave_details->port_id = slave_eth_dev->data->port_id;
862 slave_details->last_link_status = 0;
864 /* If slave device doesn't support interrupts then we need to enabled
865 * polling to monitor link status */
866 if (!(slave_eth_dev->pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)) {
867 slave_details->link_status_poll_enabled = 1;
869 if (!internals->link_status_polling_enabled) {
870 internals->link_status_polling_enabled = 1;
872 rte_eal_alarm_set(internals->link_status_polling_interval_ms * 1000,
873 bond_ethdev_slave_link_status_change_monitor,
874 (void *)&rte_eth_devices[internals->port_id]);
878 slave_details->link_status_wait_to_complete = 0;
880 memcpy(&(slave_details->persisted_mac_addr), slave_eth_dev->data->mac_addrs,
881 sizeof(struct ether_addr));
885 bond_ethdev_primary_set(struct bond_dev_private *internals,
886 uint8_t slave_port_id)
890 if (internals->active_slave_count < 1)
891 internals->current_primary_port = slave_port_id;
893 /* Search bonded device slave ports for new proposed primary port */
894 for (i = 0; i < internals->active_slave_count; i++) {
895 if (internals->active_slaves[i] == slave_port_id)
896 internals->current_primary_port = slave_port_id;
901 bond_ethdev_promiscuous_enable(struct rte_eth_dev *eth_dev);
904 bond_ethdev_start(struct rte_eth_dev *eth_dev)
906 struct bond_dev_private *internals;
909 /* slave eth dev will be started by bonded device */
910 if (valid_bonded_ethdev(eth_dev)) {
911 RTE_BOND_LOG(ERR, "User tried to explicitly start a slave eth_dev (%d)",
912 eth_dev->data->port_id);
916 eth_dev->data->dev_link.link_status = 0;
917 eth_dev->data->dev_started = 1;
919 internals = eth_dev->data->dev_private;
921 if (internals->slave_count == 0) {
922 RTE_BOND_LOG(ERR, "Cannot start port since there are no slave devices");
926 if (internals->user_defined_mac == 0) {
927 struct ether_addr *new_mac_addr = NULL;
929 for (i = 0; i < internals->slave_count; i++)
930 if (internals->slaves[i].port_id == internals->primary_port)
931 new_mac_addr = &internals->slaves[i].persisted_mac_addr;
933 if (new_mac_addr == NULL)
936 if (mac_address_set(eth_dev, new_mac_addr) != 0) {
937 RTE_BOND_LOG(ERR, "bonded port (%d) failed to update MAC address",
938 eth_dev->data->port_id);
943 /* Update all slave devices MACs*/
944 if (mac_address_slaves_update(eth_dev) != 0)
947 /* If bonded device is configure in promiscuous mode then re-apply config */
948 if (internals->promiscuous_en)
949 bond_ethdev_promiscuous_enable(eth_dev);
951 /* Reconfigure each slave device if starting bonded device */
952 for (i = 0; i < internals->slave_count; i++) {
953 if (slave_configure(eth_dev,
954 &(rte_eth_devices[internals->slaves[i].port_id])) != 0) {
956 "bonded port (%d) failed to reconfigure slave device (%d)",
957 eth_dev->data->port_id, internals->slaves[i].port_id);
962 if (internals->user_defined_primary_port)
963 bond_ethdev_primary_set(internals, internals->primary_port);
965 if (internals->mode == BONDING_MODE_8023AD)
966 bond_mode_8023ad_start(eth_dev);
972 bond_ethdev_stop(struct rte_eth_dev *eth_dev)
974 struct bond_dev_private *internals = eth_dev->data->dev_private;
977 if (internals->mode == BONDING_MODE_8023AD) {
981 bond_mode_8023ad_stop(eth_dev);
983 /* Discard all messages to/from mode 4 state machines */
984 for (i = 0; i < internals->slave_count; i++) {
985 port = &mode_8023ad_ports[internals->slaves[i].port_id];
987 RTE_VERIFY(port->rx_ring != NULL);
988 while (rte_ring_dequeue(port->rx_ring, &pkt) != -ENOENT)
989 rte_pktmbuf_free(pkt);
991 RTE_VERIFY(port->tx_ring != NULL);
992 while (rte_ring_dequeue(port->tx_ring, &pkt) != -ENOENT)
993 rte_pktmbuf_free(pkt);
997 internals->active_slave_count = 0;
998 internals->link_status_polling_enabled = 0;
1000 eth_dev->data->dev_link.link_status = 0;
1001 eth_dev->data->dev_started = 0;
1005 bond_ethdev_close(struct rte_eth_dev *dev __rte_unused)
1009 /* forward declaration */
1010 static int bond_ethdev_configure(struct rte_eth_dev *dev);
1013 bond_ethdev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1015 dev_info->driver_name = driver_name;
1016 dev_info->max_mac_addrs = 1;
1018 dev_info->max_rx_pktlen = (uint32_t)2048;
1020 dev_info->max_rx_queues = (uint16_t)128;
1021 dev_info->max_tx_queues = (uint16_t)512;
1023 dev_info->min_rx_bufsize = 0;
1024 dev_info->pci_dev = dev->pci_dev;
1028 bond_ethdev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
1029 uint16_t nb_rx_desc, unsigned int socket_id __rte_unused,
1030 const struct rte_eth_rxconf *rx_conf, struct rte_mempool *mb_pool)
1032 struct bond_rx_queue *bd_rx_q = (struct bond_rx_queue *)
1033 rte_zmalloc_socket(NULL, sizeof(struct bond_rx_queue),
1034 0, dev->pci_dev->numa_node);
1035 if (bd_rx_q == NULL)
1038 bd_rx_q->queue_id = rx_queue_id;
1039 bd_rx_q->dev_private = dev->data->dev_private;
1041 bd_rx_q->nb_rx_desc = nb_rx_desc;
1043 memcpy(&(bd_rx_q->rx_conf), rx_conf, sizeof(struct rte_eth_rxconf));
1044 bd_rx_q->mb_pool = mb_pool;
1046 dev->data->rx_queues[rx_queue_id] = bd_rx_q;
1052 bond_ethdev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
1053 uint16_t nb_tx_desc, unsigned int socket_id __rte_unused,
1054 const struct rte_eth_txconf *tx_conf)
1056 struct bond_tx_queue *bd_tx_q = (struct bond_tx_queue *)
1057 rte_zmalloc_socket(NULL, sizeof(struct bond_tx_queue),
1058 0, dev->pci_dev->numa_node);
1060 if (bd_tx_q == NULL)
1063 bd_tx_q->queue_id = tx_queue_id;
1064 bd_tx_q->dev_private = dev->data->dev_private;
1066 bd_tx_q->nb_tx_desc = nb_tx_desc;
1067 memcpy(&(bd_tx_q->tx_conf), tx_conf, sizeof(bd_tx_q->tx_conf));
1069 dev->data->tx_queues[tx_queue_id] = bd_tx_q;
1075 bond_ethdev_rx_queue_release(void *queue)
1084 bond_ethdev_tx_queue_release(void *queue)
1093 bond_ethdev_slave_link_status_change_monitor(void *cb_arg)
1095 struct rte_eth_dev *bonded_ethdev, *slave_ethdev;
1096 struct bond_dev_private *internals;
1098 /* Default value for polling slave found is true as we don't want to
1099 * disable the polling thread if we cannot get the lock */
1100 int i, polling_slave_found = 1;
1105 bonded_ethdev = (struct rte_eth_dev *)cb_arg;
1106 internals = (struct bond_dev_private *)bonded_ethdev->data->dev_private;
1108 if (!bonded_ethdev->data->dev_started ||
1109 !internals->link_status_polling_enabled)
1112 /* If device is currently being configured then don't check slaves link
1113 * status, wait until next period */
1114 if (rte_spinlock_trylock(&internals->lock)) {
1115 if (internals->slave_count > 0)
1116 polling_slave_found = 0;
1118 for (i = 0; i < internals->slave_count; i++) {
1119 if (!internals->slaves[i].link_status_poll_enabled)
1122 slave_ethdev = &rte_eth_devices[internals->slaves[i].port_id];
1123 polling_slave_found = 1;
1125 /* Update slave link status */
1126 (*slave_ethdev->dev_ops->link_update)(slave_ethdev,
1127 internals->slaves[i].link_status_wait_to_complete);
1129 /* if link status has changed since last checked then call lsc
1131 if (slave_ethdev->data->dev_link.link_status !=
1132 internals->slaves[i].last_link_status) {
1133 internals->slaves[i].last_link_status =
1134 slave_ethdev->data->dev_link.link_status;
1136 bond_ethdev_lsc_event_callback(internals->slaves[i].port_id,
1137 RTE_ETH_EVENT_INTR_LSC,
1138 &bonded_ethdev->data->port_id);
1141 rte_spinlock_unlock(&internals->lock);
1144 if (polling_slave_found)
1145 /* Set alarm to continue monitoring link status of slave ethdev's */
1146 rte_eal_alarm_set(internals->link_status_polling_interval_ms * 1000,
1147 bond_ethdev_slave_link_status_change_monitor, cb_arg);
1151 bond_ethdev_link_update(struct rte_eth_dev *bonded_eth_dev,
1152 int wait_to_complete)
1154 struct bond_dev_private *internals = bonded_eth_dev->data->dev_private;
1156 if (!bonded_eth_dev->data->dev_started ||
1157 internals->active_slave_count == 0) {
1158 bonded_eth_dev->data->dev_link.link_status = 0;
1161 struct rte_eth_dev *slave_eth_dev;
1164 for (i = 0; i < internals->active_slave_count; i++) {
1165 slave_eth_dev = &rte_eth_devices[internals->active_slaves[i]];
1167 (*slave_eth_dev->dev_ops->link_update)(slave_eth_dev,
1169 if (slave_eth_dev->data->dev_link.link_status == 1) {
1175 bonded_eth_dev->data->dev_link.link_status = link_up;
1182 bond_ethdev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1184 struct bond_dev_private *internals = dev->data->dev_private;
1185 struct rte_eth_stats slave_stats;
1189 /* clear bonded stats before populating from slaves */
1190 memset(stats, 0, sizeof(*stats));
1192 for (i = 0; i < internals->slave_count; i++) {
1193 rte_eth_stats_get(internals->slaves[i].port_id, &slave_stats);
1195 stats->ipackets += slave_stats.ipackets;
1196 stats->opackets += slave_stats.opackets;
1197 stats->ibytes += slave_stats.ibytes;
1198 stats->obytes += slave_stats.obytes;
1199 stats->ierrors += slave_stats.ierrors;
1200 stats->oerrors += slave_stats.oerrors;
1201 stats->imcasts += slave_stats.imcasts;
1202 stats->rx_nombuf += slave_stats.rx_nombuf;
1203 stats->fdirmatch += slave_stats.fdirmatch;
1204 stats->fdirmiss += slave_stats.fdirmiss;
1205 stats->tx_pause_xon += slave_stats.tx_pause_xon;
1206 stats->rx_pause_xon += slave_stats.rx_pause_xon;
1207 stats->tx_pause_xoff += slave_stats.tx_pause_xoff;
1208 stats->rx_pause_xoff += slave_stats.rx_pause_xoff;
1213 bond_ethdev_stats_reset(struct rte_eth_dev *dev)
1215 struct bond_dev_private *internals = dev->data->dev_private;
1218 for (i = 0; i < internals->slave_count; i++)
1219 rte_eth_stats_reset(internals->slaves[i].port_id);
1223 bond_ethdev_promiscuous_enable(struct rte_eth_dev *eth_dev)
1225 struct bond_dev_private *internals = eth_dev->data->dev_private;
1228 internals->promiscuous_en = 1;
1230 switch (internals->mode) {
1231 /* Promiscuous mode is propagated to all slaves */
1232 case BONDING_MODE_ROUND_ROBIN:
1233 case BONDING_MODE_BALANCE:
1234 #ifdef RTE_MBUF_REFCNT
1235 case BONDING_MODE_BROADCAST:
1237 for (i = 0; i < internals->slave_count; i++)
1238 rte_eth_promiscuous_enable(internals->slaves[i].port_id);
1240 /* In mode4 promiscus mode is managed when slave is added/removed */
1241 case BONDING_MODE_8023AD:
1243 /* Promiscuous mode is propagated only to primary slave */
1244 case BONDING_MODE_ACTIVE_BACKUP:
1246 rte_eth_promiscuous_enable(internals->current_primary_port);
1251 bond_ethdev_promiscuous_disable(struct rte_eth_dev *dev)
1253 struct bond_dev_private *internals = dev->data->dev_private;
1256 internals->promiscuous_en = 0;
1258 switch (internals->mode) {
1259 /* Promiscuous mode is propagated to all slaves */
1260 case BONDING_MODE_ROUND_ROBIN:
1261 case BONDING_MODE_BALANCE:
1262 #ifdef RTE_MBUF_REFCNT
1263 case BONDING_MODE_BROADCAST:
1265 for (i = 0; i < internals->slave_count; i++)
1266 rte_eth_promiscuous_disable(internals->slaves[i].port_id);
1268 /* In mode4 promiscus mode is set managed when slave is added/removed */
1269 case BONDING_MODE_8023AD:
1271 /* Promiscuous mode is propagated only to primary slave */
1272 case BONDING_MODE_ACTIVE_BACKUP:
1274 rte_eth_promiscuous_disable(internals->current_primary_port);
1279 bond_ethdev_delayed_lsc_propagation(void *arg)
1284 _rte_eth_dev_callback_process((struct rte_eth_dev *)arg,
1285 RTE_ETH_EVENT_INTR_LSC);
1289 bond_ethdev_lsc_event_callback(uint8_t port_id, enum rte_eth_event_type type,
1292 struct rte_eth_dev *bonded_eth_dev, *slave_eth_dev;
1293 struct bond_dev_private *internals;
1294 struct rte_eth_link link;
1296 int i, valid_slave = 0;
1298 uint8_t lsc_flag = 0;
1300 if (type != RTE_ETH_EVENT_INTR_LSC || param == NULL)
1303 bonded_eth_dev = &rte_eth_devices[*(uint8_t *)param];
1304 slave_eth_dev = &rte_eth_devices[port_id];
1306 if (valid_bonded_ethdev(bonded_eth_dev))
1309 internals = bonded_eth_dev->data->dev_private;
1311 /* If the device isn't started don't handle interrupts */
1312 if (!bonded_eth_dev->data->dev_started)
1315 /* verify that port_id is a valid slave of bonded port */
1316 for (i = 0; i < internals->slave_count; i++) {
1317 if (internals->slaves[i].port_id == port_id) {
1326 /* Search for port in active port list */
1327 active_pos = find_slave_by_id(internals->active_slaves,
1328 internals->active_slave_count, port_id);
1330 rte_eth_link_get_nowait(port_id, &link);
1331 if (link.link_status) {
1332 if (active_pos < internals->active_slave_count)
1335 /* if no active slave ports then set this port to be primary port */
1336 if (internals->active_slave_count < 1) {
1337 /* If first active slave, then change link status */
1338 bonded_eth_dev->data->dev_link.link_status = 1;
1339 internals->current_primary_port = port_id;
1342 /* Inherit eth dev link properties from first active slave */
1343 link_properties_set(bonded_eth_dev,
1344 &(slave_eth_dev->data->dev_link));
1347 activate_slave(bonded_eth_dev, port_id);
1349 /* If user has defined the primary port then default to using it */
1350 if (internals->user_defined_primary_port &&
1351 internals->primary_port == port_id)
1352 bond_ethdev_primary_set(internals, port_id);
1354 if (active_pos == internals->active_slave_count)
1357 /* Remove from active slave list */
1358 deactivate_slave(bonded_eth_dev, port_id);
1360 /* No active slaves, change link status to down and reset other
1361 * link properties */
1362 if (internals->active_slave_count < 1) {
1364 bonded_eth_dev->data->dev_link.link_status = 0;
1366 link_properties_reset(bonded_eth_dev);
1369 /* Update primary id, take first active slave from list or if none
1370 * available set to -1 */
1371 if (port_id == internals->current_primary_port) {
1372 if (internals->active_slave_count > 0)
1373 bond_ethdev_primary_set(internals,
1374 internals->active_slaves[0]);
1376 internals->current_primary_port = internals->primary_port;
1381 /* Cancel any possible outstanding interrupts if delays are enabled */
1382 if (internals->link_up_delay_ms > 0 ||
1383 internals->link_down_delay_ms > 0)
1384 rte_eal_alarm_cancel(bond_ethdev_delayed_lsc_propagation,
1387 if (bonded_eth_dev->data->dev_link.link_status) {
1388 if (internals->link_up_delay_ms > 0)
1389 rte_eal_alarm_set(internals->link_up_delay_ms * 1000,
1390 bond_ethdev_delayed_lsc_propagation,
1391 (void *)bonded_eth_dev);
1393 _rte_eth_dev_callback_process(bonded_eth_dev,
1394 RTE_ETH_EVENT_INTR_LSC);
1397 if (internals->link_down_delay_ms > 0)
1398 rte_eal_alarm_set(internals->link_down_delay_ms * 1000,
1399 bond_ethdev_delayed_lsc_propagation,
1400 (void *)bonded_eth_dev);
1402 _rte_eth_dev_callback_process(bonded_eth_dev,
1403 RTE_ETH_EVENT_INTR_LSC);
1408 struct eth_dev_ops default_dev_ops = {
1409 .dev_start = bond_ethdev_start,
1410 .dev_stop = bond_ethdev_stop,
1411 .dev_close = bond_ethdev_close,
1412 .dev_configure = bond_ethdev_configure,
1413 .dev_infos_get = bond_ethdev_info,
1414 .rx_queue_setup = bond_ethdev_rx_queue_setup,
1415 .tx_queue_setup = bond_ethdev_tx_queue_setup,
1416 .rx_queue_release = bond_ethdev_rx_queue_release,
1417 .tx_queue_release = bond_ethdev_tx_queue_release,
1418 .link_update = bond_ethdev_link_update,
1419 .stats_get = bond_ethdev_stats_get,
1420 .stats_reset = bond_ethdev_stats_reset,
1421 .promiscuous_enable = bond_ethdev_promiscuous_enable,
1422 .promiscuous_disable = bond_ethdev_promiscuous_disable
1426 bond_init(const char *name, const char *params)
1428 struct bond_dev_private *internals;
1429 struct rte_kvargs *kvlist;
1430 uint8_t bonding_mode, socket_id;
1431 int arg_count, port_id;
1433 RTE_LOG(INFO, EAL, "Initializing pmd_bond for %s\n", name);
1435 kvlist = rte_kvargs_parse(params, pmd_bond_init_valid_arguments);
1439 /* Parse link bonding mode */
1440 if (rte_kvargs_count(kvlist, PMD_BOND_MODE_KVARG) == 1) {
1441 if (rte_kvargs_process(kvlist, PMD_BOND_MODE_KVARG,
1442 &bond_ethdev_parse_slave_mode_kvarg, &bonding_mode) != 0) {
1443 RTE_LOG(ERR, EAL, "Invalid mode for bonded device %s\n", name);
1448 "Mode must be specified only once for bonded device %s\n",
1453 /* Parse socket id to create bonding device on */
1454 arg_count = rte_kvargs_count(kvlist, PMD_BOND_SOCKET_ID_KVARG);
1455 if (arg_count == 1) {
1456 if (rte_kvargs_process(kvlist, PMD_BOND_SOCKET_ID_KVARG,
1457 &bond_ethdev_parse_socket_id_kvarg, &socket_id) != 0) {
1459 "Invalid socket Id specified for bonded device %s\n",
1463 } else if (arg_count > 1) {
1465 "Socket Id can be specified only once for bonded device %s\n",
1469 socket_id = rte_socket_id();
1472 /* Create link bonding eth device */
1473 port_id = rte_eth_bond_create(name, bonding_mode, socket_id);
1476 "Failed to create socket %s in mode %u on socket %u.\n",
1477 name, bonding_mode, socket_id);
1480 internals = rte_eth_devices[port_id].data->dev_private;
1481 internals->kvlist = kvlist;
1484 "Create bonded device %s on port %d in mode %u on socket %u.\n",
1485 name, port_id, bonding_mode, socket_id);
1489 /* this part will resolve the slave portids after all the other pdev and vdev
1490 * have been allocated */
1492 bond_ethdev_configure(struct rte_eth_dev *dev)
1494 char *name = dev->data->name;
1495 struct bond_dev_private *internals = dev->data->dev_private;
1496 struct rte_kvargs *kvlist = internals->kvlist;
1497 int arg_count, port_id = dev - rte_eth_devices;
1500 * if no kvlist, it means that this bonded device has been created
1501 * through the bonding api.
1506 /* Parse MAC address for bonded device */
1507 arg_count = rte_kvargs_count(kvlist, PMD_BOND_MAC_ADDR_KVARG);
1508 if (arg_count == 1) {
1509 struct ether_addr bond_mac;
1511 if (rte_kvargs_process(kvlist, PMD_BOND_MAC_ADDR_KVARG,
1512 &bond_ethdev_parse_bond_mac_addr_kvarg, &bond_mac) < 0) {
1513 RTE_LOG(INFO, EAL, "Invalid mac address for bonded device %s\n",
1518 /* Set MAC address */
1519 if (rte_eth_bond_mac_address_set(port_id, &bond_mac) != 0) {
1521 "Failed to set mac address on bonded device %s\n",
1525 } else if (arg_count > 1) {
1527 "MAC address can be specified only once for bonded device %s\n",
1532 /* Parse/set balance mode transmit policy */
1533 arg_count = rte_kvargs_count(kvlist, PMD_BOND_XMIT_POLICY_KVARG);
1534 if (arg_count == 1) {
1535 uint8_t xmit_policy;
1537 if (rte_kvargs_process(kvlist, PMD_BOND_XMIT_POLICY_KVARG,
1538 &bond_ethdev_parse_balance_xmit_policy_kvarg, &xmit_policy) !=
1541 "Invalid xmit policy specified for bonded device %s\n",
1546 /* Set balance mode transmit policy*/
1547 if (rte_eth_bond_xmit_policy_set(port_id, xmit_policy) != 0) {
1549 "Failed to set balance xmit policy on bonded device %s\n",
1553 } else if (arg_count > 1) {
1555 "Transmit policy can be specified only once for bonded device"
1560 /* Parse/add slave ports to bonded device */
1561 if (rte_kvargs_count(kvlist, PMD_BOND_SLAVE_PORT_KVARG) > 0) {
1562 struct bond_ethdev_slave_ports slave_ports;
1565 memset(&slave_ports, 0, sizeof(slave_ports));
1567 if (rte_kvargs_process(kvlist, PMD_BOND_SLAVE_PORT_KVARG,
1568 &bond_ethdev_parse_slave_port_kvarg, &slave_ports) != 0) {
1570 "Failed to parse slave ports for bonded device %s\n",
1575 for (i = 0; i < slave_ports.slave_count; i++) {
1576 if (rte_eth_bond_slave_add(port_id, slave_ports.slaves[i]) != 0) {
1578 "Failed to add port %d as slave to bonded device %s\n",
1579 slave_ports.slaves[i], name);
1584 RTE_LOG(INFO, EAL, "No slaves specified for bonded device %s\n", name);
1588 /* Parse/set primary slave port id*/
1589 arg_count = rte_kvargs_count(kvlist, PMD_BOND_PRIMARY_SLAVE_KVARG);
1590 if (arg_count == 1) {
1591 uint8_t primary_slave_port_id;
1593 if (rte_kvargs_process(kvlist,
1594 PMD_BOND_PRIMARY_SLAVE_KVARG,
1595 &bond_ethdev_parse_primary_slave_port_id_kvarg,
1596 &primary_slave_port_id) < 0) {
1598 "Invalid primary slave port id specified for bonded device"
1603 /* Set balance mode transmit policy*/
1604 if (rte_eth_bond_primary_set(port_id, (uint8_t)primary_slave_port_id)
1607 "Failed to set primary slave port %d on bonded device %s\n",
1608 primary_slave_port_id, name);
1611 } else if (arg_count > 1) {
1613 "Primary slave can be specified only once for bonded device"
1618 /* Parse link status monitor polling interval */
1619 arg_count = rte_kvargs_count(kvlist, PMD_BOND_LSC_POLL_PERIOD_KVARG);
1620 if (arg_count == 1) {
1621 uint32_t lsc_poll_interval_ms;
1623 if (rte_kvargs_process(kvlist,
1624 PMD_BOND_LSC_POLL_PERIOD_KVARG,
1625 &bond_ethdev_parse_time_ms_kvarg,
1626 &lsc_poll_interval_ms) < 0) {
1628 "Invalid lsc polling interval value specified for bonded"
1629 " device %s\n", name);
1633 if (rte_eth_bond_link_monitoring_set(port_id, lsc_poll_interval_ms)
1636 "Failed to set lsc monitor polling interval (%u ms) on"
1637 " bonded device %s\n", lsc_poll_interval_ms, name);
1640 } else if (arg_count > 1) {
1642 "LSC polling interval can be specified only once for bonded"
1643 " device %s\n", name);
1647 /* Parse link up interrupt propagation delay */
1648 arg_count = rte_kvargs_count(kvlist, PMD_BOND_LINK_UP_PROP_DELAY_KVARG);
1649 if (arg_count == 1) {
1650 uint32_t link_up_delay_ms;
1652 if (rte_kvargs_process(kvlist,
1653 PMD_BOND_LINK_UP_PROP_DELAY_KVARG,
1654 &bond_ethdev_parse_time_ms_kvarg,
1655 &link_up_delay_ms) < 0) {
1657 "Invalid link up propagation delay value specified for"
1658 " bonded device %s\n", name);
1662 /* Set balance mode transmit policy*/
1663 if (rte_eth_bond_link_up_prop_delay_set(port_id, link_up_delay_ms)
1666 "Failed to set link up propagation delay (%u ms) on bonded"
1667 " device %s\n", link_up_delay_ms, name);
1670 } else if (arg_count > 1) {
1672 "Link up propagation delay can be specified only once for"
1673 " bonded device %s\n", name);
1677 /* Parse link down interrupt propagation delay */
1678 arg_count = rte_kvargs_count(kvlist, PMD_BOND_LINK_DOWN_PROP_DELAY_KVARG);
1679 if (arg_count == 1) {
1680 uint32_t link_down_delay_ms;
1682 if (rte_kvargs_process(kvlist,
1683 PMD_BOND_LINK_DOWN_PROP_DELAY_KVARG,
1684 &bond_ethdev_parse_time_ms_kvarg,
1685 &link_down_delay_ms) < 0) {
1687 "Invalid link down propagation delay value specified for"
1688 " bonded device %s\n", name);
1692 /* Set balance mode transmit policy*/
1693 if (rte_eth_bond_link_down_prop_delay_set(port_id, link_down_delay_ms)
1696 "Failed to set link down propagation delay (%u ms) on"
1697 " bonded device %s\n", link_down_delay_ms, name);
1700 } else if (arg_count > 1) {
1702 "Link down propagation delay can be specified only once for"
1703 " bonded device %s\n", name);
1710 static struct rte_driver bond_drv = {
1716 PMD_REGISTER_DRIVER(bond_drv);