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 <netinet/in.h>
37 #include <rte_malloc.h>
38 #include <rte_ethdev.h>
42 #include <rte_devargs.h>
43 #include <rte_kvargs.h>
45 #include <rte_alarm.h>
46 #include <rte_cycles.h>
48 #include "rte_eth_bond.h"
49 #include "rte_eth_bond_private.h"
50 #include "rte_eth_bond_8023ad_private.h"
52 #define REORDER_PERIOD_MS 10
54 #define HASH_L4_PORTS(h) ((h)->src_port ^ (h)->dst_port)
56 /* Table for statistics in mode 5 TLB */
57 static uint64_t tlb_last_obytets[RTE_MAX_ETHPORTS];
60 get_vlan_offset(struct ether_hdr *eth_hdr, uint16_t *proto)
62 size_t vlan_offset = 0;
64 if (rte_cpu_to_be_16(ETHER_TYPE_VLAN) == *proto) {
65 struct vlan_hdr *vlan_hdr = (struct vlan_hdr *)(eth_hdr + 1);
67 vlan_offset = sizeof(struct vlan_hdr);
68 *proto = vlan_hdr->eth_proto;
70 if (rte_cpu_to_be_16(ETHER_TYPE_VLAN) == *proto) {
71 vlan_hdr = vlan_hdr + 1;
72 *proto = vlan_hdr->eth_proto;
73 vlan_offset += sizeof(struct vlan_hdr);
80 bond_ethdev_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
82 struct bond_dev_private *internals;
84 uint16_t num_rx_slave = 0;
85 uint16_t num_rx_total = 0;
89 /* Cast to structure, containing bonded device's port id and queue id */
90 struct bond_rx_queue *bd_rx_q = (struct bond_rx_queue *)queue;
92 internals = bd_rx_q->dev_private;
95 for (i = 0; i < internals->active_slave_count && nb_pkts; i++) {
96 /* Offset of pointer to *bufs increases as packets are received
97 * from other slaves */
98 num_rx_slave = rte_eth_rx_burst(internals->active_slaves[i],
99 bd_rx_q->queue_id, bufs + num_rx_total, nb_pkts);
101 num_rx_total += num_rx_slave;
102 nb_pkts -= num_rx_slave;
110 bond_ethdev_rx_burst_active_backup(void *queue, struct rte_mbuf **bufs,
113 struct bond_dev_private *internals;
115 /* Cast to structure, containing bonded device's port id and queue id */
116 struct bond_rx_queue *bd_rx_q = (struct bond_rx_queue *)queue;
118 internals = bd_rx_q->dev_private;
120 return rte_eth_rx_burst(internals->current_primary_port,
121 bd_rx_q->queue_id, bufs, nb_pkts);
125 bond_ethdev_rx_burst_8023ad(void *queue, struct rte_mbuf **bufs,
128 /* Cast to structure, containing bonded device's port id and queue id */
129 struct bond_rx_queue *bd_rx_q = (struct bond_rx_queue *)queue;
130 struct bond_dev_private *internals = bd_rx_q->dev_private;
131 struct ether_addr bond_mac;
133 struct ether_hdr *hdr;
135 const uint16_t ether_type_slow_be = rte_be_to_cpu_16(ETHER_TYPE_SLOW);
136 uint16_t num_rx_total = 0; /* Total number of received packets */
137 uint8_t slaves[RTE_MAX_ETHPORTS];
140 uint8_t collecting; /* current slave collecting status */
141 const uint8_t promisc = internals->promiscuous_en;
144 rte_eth_macaddr_get(internals->port_id, &bond_mac);
145 /* Copy slave list to protect against slave up/down changes during tx
147 slave_count = internals->active_slave_count;
148 memcpy(slaves, internals->active_slaves,
149 sizeof(internals->active_slaves[0]) * slave_count);
151 for (i = 0; i < slave_count && num_rx_total < nb_pkts; i++) {
153 collecting = ACTOR_STATE(&mode_8023ad_ports[slaves[i]], COLLECTING);
155 /* Read packets from this slave */
156 num_rx_total += rte_eth_rx_burst(slaves[i], bd_rx_q->queue_id,
157 &bufs[num_rx_total], nb_pkts - num_rx_total);
159 for (k = j; k < 2 && k < num_rx_total; k++)
160 rte_prefetch0(rte_pktmbuf_mtod(bufs[k], void *));
162 /* Handle slow protocol packets. */
163 while (j < num_rx_total) {
164 if (j + 3 < num_rx_total)
165 rte_prefetch0(rte_pktmbuf_mtod(bufs[j + 3], void *));
167 hdr = rte_pktmbuf_mtod(bufs[j], struct ether_hdr *);
168 /* Remove packet from array if it is slow packet or slave is not
169 * in collecting state or bondign interface is not in promiscus
170 * mode and packet address does not match. */
171 if (unlikely(hdr->ether_type == ether_type_slow_be ||
172 !collecting || (!promisc &&
173 !is_same_ether_addr(&bond_mac, &hdr->d_addr)))) {
175 if (hdr->ether_type == ether_type_slow_be) {
176 bond_mode_8023ad_handle_slow_pkt(internals, slaves[i],
179 rte_pktmbuf_free(bufs[j]);
181 /* Packet is managed by mode 4 or dropped, shift the array */
183 if (j < num_rx_total) {
184 memmove(&bufs[j], &bufs[j + 1], sizeof(bufs[0]) *
195 #if defined(RTE_LIBRTE_BOND_DEBUG_ALB) || defined(RTE_LIBRTE_BOND_DEBUG_ALB_L1)
196 uint32_t burstnumberRX;
197 uint32_t burstnumberTX;
199 #ifdef RTE_LIBRTE_BOND_DEBUG_ALB
202 arp_op_name(uint16_t arp_op, char *buf)
206 snprintf(buf, sizeof("ARP Request"), "%s", "ARP Request");
209 snprintf(buf, sizeof("ARP Reply"), "%s", "ARP Reply");
211 case ARP_OP_REVREQUEST:
212 snprintf(buf, sizeof("Reverse ARP Request"), "%s",
213 "Reverse ARP Request");
215 case ARP_OP_REVREPLY:
216 snprintf(buf, sizeof("Reverse ARP Reply"), "%s",
217 "Reverse ARP Reply");
219 case ARP_OP_INVREQUEST:
220 snprintf(buf, sizeof("Peer Identify Request"), "%s",
221 "Peer Identify Request");
223 case ARP_OP_INVREPLY:
224 snprintf(buf, sizeof("Peer Identify Reply"), "%s",
225 "Peer Identify Reply");
230 snprintf(buf, sizeof("Unknown"), "%s", "Unknown");
234 #define MaxIPv4String 16
236 ipv4_addr_to_dot(uint32_t be_ipv4_addr, char *buf, uint8_t buf_size)
240 ipv4_addr = rte_be_to_cpu_32(be_ipv4_addr);
241 snprintf(buf, buf_size, "%d.%d.%d.%d", (ipv4_addr >> 24) & 0xFF,
242 (ipv4_addr >> 16) & 0xFF, (ipv4_addr >> 8) & 0xFF,
246 #define MAX_CLIENTS_NUMBER 128
247 uint8_t active_clients;
248 struct client_stats_t {
251 uint32_t ipv4_rx_packets;
252 uint32_t ipv4_tx_packets;
254 struct client_stats_t client_stats[MAX_CLIENTS_NUMBER];
257 update_client_stats(uint32_t addr, uint8_t port, uint32_t *TXorRXindicator)
261 for (; i < MAX_CLIENTS_NUMBER; i++) {
262 if ((client_stats[i].ipv4_addr == addr) && (client_stats[i].port == port)) {
263 /* Just update RX packets number for this client */
264 if (TXorRXindicator == &burstnumberRX)
265 client_stats[i].ipv4_rx_packets++;
267 client_stats[i].ipv4_tx_packets++;
271 /* We have a new client. Insert him to the table, and increment stats */
272 if (TXorRXindicator == &burstnumberRX)
273 client_stats[active_clients].ipv4_rx_packets++;
275 client_stats[active_clients].ipv4_tx_packets++;
276 client_stats[active_clients].ipv4_addr = addr;
277 client_stats[active_clients].port = port;
282 void print_client_stats(void);
283 void print_client_stats(void)
286 char buf[MaxIPv4String];
288 for (; i < active_clients; i++) {
289 ipv4_addr_to_dot(client_stats[i].ipv4_addr, buf, MaxIPv4String);
290 printf("port:%d client:%s RX:%d TX:%d\n", client_stats[i].port, buf,
291 client_stats[i].ipv4_rx_packets,
292 client_stats[i].ipv4_tx_packets);
295 #ifdef RTE_LIBRTE_BOND_DEBUG_ALB
296 #define MODE6_DEBUG(info, src_ip, dst_ip, eth_h, arp_op, port, burstnumber) \
297 RTE_LOG(DEBUG, PMD, \
300 "SrcMAC:%02X:%02X:%02X:%02X:%02X:%02X " \
302 "DstMAC:%02X:%02X:%02X:%02X:%02X:%02X " \
308 eth_h->s_addr.addr_bytes[0], \
309 eth_h->s_addr.addr_bytes[1], \
310 eth_h->s_addr.addr_bytes[2], \
311 eth_h->s_addr.addr_bytes[3], \
312 eth_h->s_addr.addr_bytes[4], \
313 eth_h->s_addr.addr_bytes[5], \
315 eth_h->d_addr.addr_bytes[0], \
316 eth_h->d_addr.addr_bytes[1], \
317 eth_h->d_addr.addr_bytes[2], \
318 eth_h->d_addr.addr_bytes[3], \
319 eth_h->d_addr.addr_bytes[4], \
320 eth_h->d_addr.addr_bytes[5], \
327 mode6_debug(const char __attribute__((unused)) *info, struct ether_hdr *eth_h,
328 uint8_t port, uint32_t __attribute__((unused)) *burstnumber)
330 struct ipv4_hdr *ipv4_h;
331 #ifdef RTE_LIBRTE_BOND_DEBUG_ALB
332 struct arp_hdr *arp_h;
339 uint16_t ether_type = eth_h->ether_type;
340 uint16_t offset = get_vlan_offset(eth_h, ðer_type);
342 #ifdef RTE_LIBRTE_BOND_DEBUG_ALB
343 snprintf(buf, 16, "%s", info);
346 if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) {
347 ipv4_h = (struct ipv4_hdr *)((char *)(eth_h + 1) + offset);
348 ipv4_addr_to_dot(ipv4_h->src_addr, src_ip, MaxIPv4String);
349 #ifdef RTE_LIBRTE_BOND_DEBUG_ALB
350 ipv4_addr_to_dot(ipv4_h->dst_addr, dst_ip, MaxIPv4String);
351 MODE6_DEBUG(buf, src_ip, dst_ip, eth_h, "", port, *burstnumber);
353 update_client_stats(ipv4_h->src_addr, port, burstnumber);
355 #ifdef RTE_LIBRTE_BOND_DEBUG_ALB
356 else if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_ARP)) {
357 arp_h = (struct arp_hdr *)((char *)(eth_h + 1) + offset);
358 ipv4_addr_to_dot(arp_h->arp_data.arp_sip, src_ip, MaxIPv4String);
359 ipv4_addr_to_dot(arp_h->arp_data.arp_tip, dst_ip, MaxIPv4String);
360 arp_op_name(rte_be_to_cpu_16(arp_h->arp_op), ArpOp);
361 MODE6_DEBUG(buf, src_ip, dst_ip, eth_h, ArpOp, port, *burstnumber);
368 bond_ethdev_rx_burst_alb(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
370 struct bond_tx_queue *bd_tx_q = (struct bond_tx_queue *)queue;
371 struct bond_dev_private *internals = bd_tx_q->dev_private;
372 struct ether_hdr *eth_h;
373 uint16_t ether_type, offset;
374 uint16_t nb_recv_pkts;
377 nb_recv_pkts = bond_ethdev_rx_burst(queue, bufs, nb_pkts);
379 for (i = 0; i < nb_recv_pkts; i++) {
380 eth_h = rte_pktmbuf_mtod(bufs[i], struct ether_hdr *);
381 ether_type = eth_h->ether_type;
382 offset = get_vlan_offset(eth_h, ðer_type);
384 if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_ARP)) {
385 #if defined(RTE_LIBRTE_BOND_DEBUG_ALB) || defined(RTE_LIBRTE_BOND_DEBUG_ALB_L1)
386 mode6_debug("RX ARP:", eth_h, bufs[i]->port, &burstnumberRX);
388 bond_mode_alb_arp_recv(eth_h, offset, internals);
390 #if defined(RTE_LIBRTE_BOND_DEBUG_ALB) || defined(RTE_LIBRTE_BOND_DEBUG_ALB_L1)
391 else if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4))
392 mode6_debug("RX IPv4:", eth_h, bufs[i]->port, &burstnumberRX);
400 bond_ethdev_tx_burst_round_robin(void *queue, struct rte_mbuf **bufs,
403 struct bond_dev_private *internals;
404 struct bond_tx_queue *bd_tx_q;
406 struct rte_mbuf *slave_bufs[RTE_MAX_ETHPORTS][nb_pkts];
407 uint16_t slave_nb_pkts[RTE_MAX_ETHPORTS] = { 0 };
409 uint8_t num_of_slaves;
410 uint8_t slaves[RTE_MAX_ETHPORTS];
412 uint16_t num_tx_total = 0, num_tx_slave;
414 static int slave_idx = 0;
415 int i, cslave_idx = 0, tx_fail_total = 0;
417 bd_tx_q = (struct bond_tx_queue *)queue;
418 internals = bd_tx_q->dev_private;
420 /* Copy slave list to protect against slave up/down changes during tx
422 num_of_slaves = internals->active_slave_count;
423 memcpy(slaves, internals->active_slaves,
424 sizeof(internals->active_slaves[0]) * num_of_slaves);
426 if (num_of_slaves < 1)
429 /* Populate slaves mbuf with which packets are to be sent on it */
430 for (i = 0; i < nb_pkts; i++) {
431 cslave_idx = (slave_idx + i) % num_of_slaves;
432 slave_bufs[cslave_idx][(slave_nb_pkts[cslave_idx])++] = bufs[i];
435 /* increment current slave index so the next call to tx burst starts on the
437 slave_idx = ++cslave_idx;
439 /* Send packet burst on each slave device */
440 for (i = 0; i < num_of_slaves; i++) {
441 if (slave_nb_pkts[i] > 0) {
442 num_tx_slave = rte_eth_tx_burst(slaves[i], bd_tx_q->queue_id,
443 slave_bufs[i], slave_nb_pkts[i]);
445 /* if tx burst fails move packets to end of bufs */
446 if (unlikely(num_tx_slave < slave_nb_pkts[i])) {
447 int tx_fail_slave = slave_nb_pkts[i] - num_tx_slave;
449 tx_fail_total += tx_fail_slave;
451 memcpy(&bufs[nb_pkts - tx_fail_total],
452 &slave_bufs[i][num_tx_slave],
453 tx_fail_slave * sizeof(bufs[0]));
455 num_tx_total += num_tx_slave;
463 bond_ethdev_tx_burst_active_backup(void *queue,
464 struct rte_mbuf **bufs, uint16_t nb_pkts)
466 struct bond_dev_private *internals;
467 struct bond_tx_queue *bd_tx_q;
469 bd_tx_q = (struct bond_tx_queue *)queue;
470 internals = bd_tx_q->dev_private;
472 if (internals->active_slave_count < 1)
475 return rte_eth_tx_burst(internals->current_primary_port, bd_tx_q->queue_id,
479 static inline uint16_t
480 ether_hash(struct ether_hdr *eth_hdr)
482 uint16_t *word_src_addr = (uint16_t *)eth_hdr->s_addr.addr_bytes;
483 uint16_t *word_dst_addr = (uint16_t *)eth_hdr->d_addr.addr_bytes;
485 return (word_src_addr[0] ^ word_dst_addr[0]) ^
486 (word_src_addr[1] ^ word_dst_addr[1]) ^
487 (word_src_addr[2] ^ word_dst_addr[2]);
490 static inline uint32_t
491 ipv4_hash(struct ipv4_hdr *ipv4_hdr)
493 return (ipv4_hdr->src_addr ^ ipv4_hdr->dst_addr);
496 static inline uint32_t
497 ipv6_hash(struct ipv6_hdr *ipv6_hdr)
499 uint32_t *word_src_addr = (uint32_t *)&(ipv6_hdr->src_addr[0]);
500 uint32_t *word_dst_addr = (uint32_t *)&(ipv6_hdr->dst_addr[0]);
502 return (word_src_addr[0] ^ word_dst_addr[0]) ^
503 (word_src_addr[1] ^ word_dst_addr[1]) ^
504 (word_src_addr[2] ^ word_dst_addr[2]) ^
505 (word_src_addr[3] ^ word_dst_addr[3]);
509 xmit_l2_hash(const struct rte_mbuf *buf, uint8_t slave_count)
511 struct ether_hdr *eth_hdr = rte_pktmbuf_mtod(buf, struct ether_hdr *);
513 uint32_t hash = ether_hash(eth_hdr);
515 return (hash ^= hash >> 8) % slave_count;
519 xmit_l23_hash(const struct rte_mbuf *buf, uint8_t slave_count)
521 struct ether_hdr *eth_hdr = rte_pktmbuf_mtod(buf, struct ether_hdr *);
522 uint16_t proto = eth_hdr->ether_type;
523 size_t vlan_offset = get_vlan_offset(eth_hdr, &proto);
524 uint32_t hash, l3hash = 0;
526 hash = ether_hash(eth_hdr);
528 if (rte_cpu_to_be_16(ETHER_TYPE_IPv4) == proto) {
529 struct ipv4_hdr *ipv4_hdr = (struct ipv4_hdr *)
530 ((char *)(eth_hdr + 1) + vlan_offset);
531 l3hash = ipv4_hash(ipv4_hdr);
533 } else if (rte_cpu_to_be_16(ETHER_TYPE_IPv6) == proto) {
534 struct ipv6_hdr *ipv6_hdr = (struct ipv6_hdr *)
535 ((char *)(eth_hdr + 1) + vlan_offset);
536 l3hash = ipv6_hash(ipv6_hdr);
539 hash = hash ^ l3hash;
543 return hash % slave_count;
547 xmit_l34_hash(const struct rte_mbuf *buf, uint8_t slave_count)
549 struct ether_hdr *eth_hdr = rte_pktmbuf_mtod(buf, struct ether_hdr *);
550 uint16_t proto = eth_hdr->ether_type;
551 size_t vlan_offset = get_vlan_offset(eth_hdr, &proto);
553 struct udp_hdr *udp_hdr = NULL;
554 struct tcp_hdr *tcp_hdr = NULL;
555 uint32_t hash, l3hash = 0, l4hash = 0;
557 if (rte_cpu_to_be_16(ETHER_TYPE_IPv4) == proto) {
558 struct ipv4_hdr *ipv4_hdr = (struct ipv4_hdr *)
559 ((char *)(eth_hdr + 1) + vlan_offset);
560 size_t ip_hdr_offset;
562 l3hash = ipv4_hash(ipv4_hdr);
564 ip_hdr_offset = (ipv4_hdr->version_ihl & IPV4_HDR_IHL_MASK) *
567 if (ipv4_hdr->next_proto_id == IPPROTO_TCP) {
568 tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr +
570 l4hash = HASH_L4_PORTS(tcp_hdr);
571 } else if (ipv4_hdr->next_proto_id == IPPROTO_UDP) {
572 udp_hdr = (struct udp_hdr *)((char *)ipv4_hdr +
574 l4hash = HASH_L4_PORTS(udp_hdr);
576 } else if (rte_cpu_to_be_16(ETHER_TYPE_IPv6) == proto) {
577 struct ipv6_hdr *ipv6_hdr = (struct ipv6_hdr *)
578 ((char *)(eth_hdr + 1) + vlan_offset);
579 l3hash = ipv6_hash(ipv6_hdr);
581 if (ipv6_hdr->proto == IPPROTO_TCP) {
582 tcp_hdr = (struct tcp_hdr *)(ipv6_hdr + 1);
583 l4hash = HASH_L4_PORTS(tcp_hdr);
584 } else if (ipv6_hdr->proto == IPPROTO_UDP) {
585 udp_hdr = (struct udp_hdr *)(ipv6_hdr + 1);
586 l4hash = HASH_L4_PORTS(udp_hdr);
590 hash = l3hash ^ l4hash;
594 return hash % slave_count;
598 uint64_t bwg_left_int;
599 uint64_t bwg_left_remainder;
604 bond_tlb_activate_slave(struct bond_dev_private *internals) {
607 for (i = 0; i < internals->active_slave_count; i++) {
608 tlb_last_obytets[internals->active_slaves[i]] = 0;
613 bandwidth_cmp(const void *a, const void *b)
615 const struct bwg_slave *bwg_a = a;
616 const struct bwg_slave *bwg_b = b;
617 int64_t diff = (int64_t)bwg_b->bwg_left_int - (int64_t)bwg_a->bwg_left_int;
618 int64_t diff2 = (int64_t)bwg_b->bwg_left_remainder -
619 (int64_t)bwg_a->bwg_left_remainder;
633 bandwidth_left(int port_id, uint64_t load, uint8_t update_idx,
634 struct bwg_slave *bwg_slave)
636 struct rte_eth_link link_status;
638 rte_eth_link_get(port_id, &link_status);
639 uint64_t link_bwg = link_status.link_speed * 1000000ULL / 8;
642 link_bwg = link_bwg * (update_idx+1) * REORDER_PERIOD_MS;
643 bwg_slave->bwg_left_int = (link_bwg - 1000*load) / link_bwg;
644 bwg_slave->bwg_left_remainder = (link_bwg - 1000*load) % link_bwg;
648 bond_ethdev_update_tlb_slave_cb(void *arg)
650 struct bond_dev_private *internals = arg;
651 struct rte_eth_stats slave_stats;
652 struct bwg_slave bwg_array[RTE_MAX_ETHPORTS];
656 uint8_t update_stats = 0;
659 internals->slave_update_idx++;
662 if (internals->slave_update_idx >= REORDER_PERIOD_MS)
665 for (i = 0; i < internals->active_slave_count; i++) {
666 slave_id = internals->active_slaves[i];
667 rte_eth_stats_get(slave_id, &slave_stats);
668 tx_bytes = slave_stats.obytes - tlb_last_obytets[slave_id];
669 bandwidth_left(slave_id, tx_bytes,
670 internals->slave_update_idx, &bwg_array[i]);
671 bwg_array[i].slave = slave_id;
674 tlb_last_obytets[slave_id] = slave_stats.obytes;
678 if (update_stats == 1)
679 internals->slave_update_idx = 0;
682 qsort(bwg_array, slave_count, sizeof(bwg_array[0]), bandwidth_cmp);
683 for (i = 0; i < slave_count; i++)
684 internals->tlb_slaves_order[i] = bwg_array[i].slave;
686 rte_eal_alarm_set(REORDER_PERIOD_MS * 1000, bond_ethdev_update_tlb_slave_cb,
687 (struct bond_dev_private *)internals);
691 bond_ethdev_tx_burst_tlb(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
693 struct bond_tx_queue *bd_tx_q = (struct bond_tx_queue *)queue;
694 struct bond_dev_private *internals = bd_tx_q->dev_private;
696 struct rte_eth_dev *primary_port =
697 &rte_eth_devices[internals->primary_port];
698 uint16_t num_tx_total = 0;
701 uint8_t num_of_slaves = internals->active_slave_count;
702 uint8_t slaves[RTE_MAX_ETHPORTS];
704 struct ether_hdr *ether_hdr;
705 struct ether_addr primary_slave_addr;
706 struct ether_addr active_slave_addr;
708 if (num_of_slaves < 1)
711 memcpy(slaves, internals->tlb_slaves_order,
712 sizeof(internals->tlb_slaves_order[0]) * num_of_slaves);
715 ether_addr_copy(primary_port->data->mac_addrs, &primary_slave_addr);
718 for (i = 0; i < 3; i++)
719 rte_prefetch0(rte_pktmbuf_mtod(bufs[i], void*));
722 for (i = 0; i < num_of_slaves; i++) {
723 rte_eth_macaddr_get(slaves[i], &active_slave_addr);
724 for (j = num_tx_total; j < nb_pkts; j++) {
726 rte_prefetch0(rte_pktmbuf_mtod(bufs[j+3], void*));
728 ether_hdr = rte_pktmbuf_mtod(bufs[j], struct ether_hdr *);
729 if (is_same_ether_addr(ðer_hdr->s_addr, &primary_slave_addr))
730 ether_addr_copy(&active_slave_addr, ðer_hdr->s_addr);
731 #if defined(RTE_LIBRTE_BOND_DEBUG_ALB) || defined(RTE_LIBRTE_BOND_DEBUG_ALB_L1)
732 mode6_debug("TX IPv4:", ether_hdr, slaves[i], &burstnumberTX);
736 num_tx_total += rte_eth_tx_burst(slaves[i], bd_tx_q->queue_id,
737 bufs + num_tx_total, nb_pkts - num_tx_total);
739 if (num_tx_total == nb_pkts)
747 bond_tlb_disable(struct bond_dev_private *internals)
749 rte_eal_alarm_cancel(bond_ethdev_update_tlb_slave_cb, internals);
753 bond_tlb_enable(struct bond_dev_private *internals)
755 bond_ethdev_update_tlb_slave_cb(internals);
759 bond_ethdev_tx_burst_alb(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
761 struct bond_tx_queue *bd_tx_q = (struct bond_tx_queue *)queue;
762 struct bond_dev_private *internals = bd_tx_q->dev_private;
764 struct ether_hdr *eth_h;
765 uint16_t ether_type, offset;
767 struct client_data *client_info;
770 * We create transmit buffers for every slave and one additional to send
771 * through tlb. In worst case every packet will be send on one port.
773 struct rte_mbuf *slave_bufs[RTE_MAX_ETHPORTS + 1][nb_pkts];
774 uint16_t slave_bufs_pkts[RTE_MAX_ETHPORTS + 1] = { 0 };
777 * We create separate transmit buffers for update packets as they wont be
778 * counted in num_tx_total.
780 struct rte_mbuf *update_bufs[RTE_MAX_ETHPORTS][ALB_HASH_TABLE_SIZE];
781 uint16_t update_bufs_pkts[RTE_MAX_ETHPORTS] = { 0 };
783 struct rte_mbuf *upd_pkt;
786 uint16_t num_send, num_not_send = 0;
787 uint16_t num_tx_total = 0;
792 /* Search tx buffer for ARP packets and forward them to alb */
793 for (i = 0; i < nb_pkts; i++) {
794 eth_h = rte_pktmbuf_mtod(bufs[i], struct ether_hdr *);
795 ether_type = eth_h->ether_type;
796 offset = get_vlan_offset(eth_h, ðer_type);
798 if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_ARP)) {
799 slave_idx = bond_mode_alb_arp_xmit(eth_h, offset, internals);
801 /* Change src mac in eth header */
802 rte_eth_macaddr_get(slave_idx, ð_h->s_addr);
804 /* Add packet to slave tx buffer */
805 slave_bufs[slave_idx][slave_bufs_pkts[slave_idx]] = bufs[i];
806 slave_bufs_pkts[slave_idx]++;
808 /* If packet is not ARP, send it with TLB policy */
809 slave_bufs[RTE_MAX_ETHPORTS][slave_bufs_pkts[RTE_MAX_ETHPORTS]] =
811 slave_bufs_pkts[RTE_MAX_ETHPORTS]++;
815 /* Update connected client ARP tables */
816 if (internals->mode6.ntt) {
817 for (i = 0; i < ALB_HASH_TABLE_SIZE; i++) {
818 client_info = &internals->mode6.client_table[i];
820 if (client_info->in_use) {
821 /* Allocate new packet to send ARP update on current slave */
822 upd_pkt = rte_pktmbuf_alloc(internals->mode6.mempool);
823 if (upd_pkt == NULL) {
824 RTE_LOG(ERR, PMD, "Failed to allocate ARP packet from pool\n");
827 pkt_size = sizeof(struct ether_hdr) + sizeof(struct arp_hdr)
828 + client_info->vlan_count * sizeof(struct vlan_hdr);
829 upd_pkt->data_len = pkt_size;
830 upd_pkt->pkt_len = pkt_size;
832 slave_idx = bond_mode_alb_arp_upd(client_info, upd_pkt,
835 /* Add packet to update tx buffer */
836 update_bufs[slave_idx][update_bufs_pkts[slave_idx]] = upd_pkt;
837 update_bufs_pkts[slave_idx]++;
840 internals->mode6.ntt = 0;
843 /* Send ARP packets on proper slaves */
844 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
845 if (slave_bufs_pkts[i] > 0) {
846 num_send = rte_eth_tx_burst(i, bd_tx_q->queue_id,
847 slave_bufs[i], slave_bufs_pkts[i]);
848 for (j = 0; j < slave_bufs_pkts[i] - num_send; j++) {
849 bufs[nb_pkts - 1 - num_not_send - j] =
850 slave_bufs[i][nb_pkts - 1 - j];
853 num_tx_total += num_send;
854 num_not_send += slave_bufs_pkts[i] - num_send;
856 #if defined(RTE_LIBRTE_BOND_DEBUG_ALB) || defined(RTE_LIBRTE_BOND_DEBUG_ALB_L1)
857 /* Print TX stats including update packets */
858 for (j = 0; j < slave_bufs_pkts[i]; j++) {
859 eth_h = rte_pktmbuf_mtod(slave_bufs[i][j], struct ether_hdr *);
860 mode6_debug("TX ARP:", eth_h, i, &burstnumberTX);
866 /* Send update packets on proper slaves */
867 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
868 if (update_bufs_pkts[i] > 0) {
869 num_send = rte_eth_tx_burst(i, bd_tx_q->queue_id, update_bufs[i],
870 update_bufs_pkts[i]);
871 for (j = num_send; j < update_bufs_pkts[i]; j++) {
872 rte_pktmbuf_free(update_bufs[i][j]);
874 #if defined(RTE_LIBRTE_BOND_DEBUG_ALB) || defined(RTE_LIBRTE_BOND_DEBUG_ALB_L1)
875 for (j = 0; j < update_bufs_pkts[i]; j++) {
876 eth_h = rte_pktmbuf_mtod(update_bufs[i][j], struct ether_hdr *);
877 mode6_debug("TX ARPupd:", eth_h, i, &burstnumberTX);
883 /* Send non-ARP packets using tlb policy */
884 if (slave_bufs_pkts[RTE_MAX_ETHPORTS] > 0) {
885 num_send = bond_ethdev_tx_burst_tlb(queue,
886 slave_bufs[RTE_MAX_ETHPORTS],
887 slave_bufs_pkts[RTE_MAX_ETHPORTS]);
889 for (j = 0; j < slave_bufs_pkts[RTE_MAX_ETHPORTS]; j++) {
890 bufs[nb_pkts - 1 - num_not_send - j] =
891 slave_bufs[RTE_MAX_ETHPORTS][nb_pkts - 1 - j];
894 num_tx_total += num_send;
895 num_not_send += slave_bufs_pkts[RTE_MAX_ETHPORTS] - num_send;
902 bond_ethdev_tx_burst_balance(void *queue, struct rte_mbuf **bufs,
905 struct bond_dev_private *internals;
906 struct bond_tx_queue *bd_tx_q;
908 uint8_t num_of_slaves;
909 uint8_t slaves[RTE_MAX_ETHPORTS];
911 uint16_t num_tx_total = 0, num_tx_slave = 0, tx_fail_total = 0;
915 struct rte_mbuf *slave_bufs[RTE_MAX_ETHPORTS][nb_pkts];
916 uint16_t slave_nb_pkts[RTE_MAX_ETHPORTS] = { 0 };
918 bd_tx_q = (struct bond_tx_queue *)queue;
919 internals = bd_tx_q->dev_private;
921 /* Copy slave list to protect against slave up/down changes during tx
923 num_of_slaves = internals->active_slave_count;
924 memcpy(slaves, internals->active_slaves,
925 sizeof(internals->active_slaves[0]) * num_of_slaves);
927 if (num_of_slaves < 1)
930 /* Populate slaves mbuf with the packets which are to be sent on it */
931 for (i = 0; i < nb_pkts; i++) {
932 /* Select output slave using hash based on xmit policy */
933 op_slave_id = internals->xmit_hash(bufs[i], num_of_slaves);
935 /* Populate slave mbuf arrays with mbufs for that slave */
936 slave_bufs[op_slave_id][slave_nb_pkts[op_slave_id]++] = bufs[i];
939 /* Send packet burst on each slave device */
940 for (i = 0; i < num_of_slaves; i++) {
941 if (slave_nb_pkts[i] > 0) {
942 num_tx_slave = rte_eth_tx_burst(slaves[i], bd_tx_q->queue_id,
943 slave_bufs[i], slave_nb_pkts[i]);
945 /* if tx burst fails move packets to end of bufs */
946 if (unlikely(num_tx_slave < slave_nb_pkts[i])) {
947 int slave_tx_fail_count = slave_nb_pkts[i] - num_tx_slave;
949 tx_fail_total += slave_tx_fail_count;
950 memcpy(&bufs[nb_pkts - tx_fail_total],
951 &slave_bufs[i][num_tx_slave],
952 slave_tx_fail_count * sizeof(bufs[0]));
955 num_tx_total += num_tx_slave;
963 bond_ethdev_tx_burst_8023ad(void *queue, struct rte_mbuf **bufs,
966 struct bond_dev_private *internals;
967 struct bond_tx_queue *bd_tx_q;
969 uint8_t num_of_slaves;
970 uint8_t slaves[RTE_MAX_ETHPORTS];
971 /* positions in slaves, not ID */
972 uint8_t distributing_offsets[RTE_MAX_ETHPORTS];
973 uint8_t distributing_count;
975 uint16_t num_tx_slave, num_tx_total = 0, num_tx_fail_total = 0;
976 uint16_t i, j, op_slave_idx;
977 const uint16_t buffs_size = nb_pkts + BOND_MODE_8023AX_SLAVE_TX_PKTS + 1;
979 /* Allocate additional packets in case 8023AD mode. */
980 struct rte_mbuf *slave_bufs[RTE_MAX_ETHPORTS][buffs_size];
981 void *slow_pkts[BOND_MODE_8023AX_SLAVE_TX_PKTS] = { NULL };
983 /* Total amount of packets in slave_bufs */
984 uint16_t slave_nb_pkts[RTE_MAX_ETHPORTS] = { 0 };
985 /* Slow packets placed in each slave */
986 uint8_t slave_slow_nb_pkts[RTE_MAX_ETHPORTS] = { 0 };
988 bd_tx_q = (struct bond_tx_queue *)queue;
989 internals = bd_tx_q->dev_private;
991 /* Copy slave list to protect against slave up/down changes during tx
993 num_of_slaves = internals->active_slave_count;
994 if (num_of_slaves < 1)
997 memcpy(slaves, internals->active_slaves, sizeof(slaves[0]) * num_of_slaves);
999 distributing_count = 0;
1000 for (i = 0; i < num_of_slaves; i++) {
1001 struct port *port = &mode_8023ad_ports[slaves[i]];
1003 slave_slow_nb_pkts[i] = rte_ring_dequeue_burst(port->tx_ring,
1004 slow_pkts, BOND_MODE_8023AX_SLAVE_TX_PKTS);
1005 slave_nb_pkts[i] = slave_slow_nb_pkts[i];
1007 for (j = 0; j < slave_slow_nb_pkts[i]; j++)
1008 slave_bufs[i][j] = slow_pkts[j];
1010 if (ACTOR_STATE(port, DISTRIBUTING))
1011 distributing_offsets[distributing_count++] = i;
1014 if (likely(distributing_count > 0)) {
1015 /* Populate slaves mbuf with the packets which are to be sent on it */
1016 for (i = 0; i < nb_pkts; i++) {
1017 /* Select output slave using hash based on xmit policy */
1018 op_slave_idx = internals->xmit_hash(bufs[i], distributing_count);
1020 /* Populate slave mbuf arrays with mbufs for that slave. Use only
1021 * slaves that are currently distributing. */
1022 uint8_t slave_offset = distributing_offsets[op_slave_idx];
1023 slave_bufs[slave_offset][slave_nb_pkts[slave_offset]] = bufs[i];
1024 slave_nb_pkts[slave_offset]++;
1028 /* Send packet burst on each slave device */
1029 for (i = 0; i < num_of_slaves; i++) {
1030 if (slave_nb_pkts[i] == 0)
1033 num_tx_slave = rte_eth_tx_burst(slaves[i], bd_tx_q->queue_id,
1034 slave_bufs[i], slave_nb_pkts[i]);
1036 /* If tx burst fails drop slow packets */
1037 for ( ; num_tx_slave < slave_slow_nb_pkts[i]; num_tx_slave++)
1038 rte_pktmbuf_free(slave_bufs[i][num_tx_slave]);
1040 num_tx_total += num_tx_slave - slave_slow_nb_pkts[i];
1041 num_tx_fail_total += slave_nb_pkts[i] - num_tx_slave;
1043 /* If tx burst fails move packets to end of bufs */
1044 if (unlikely(num_tx_slave < slave_nb_pkts[i])) {
1045 uint16_t j = nb_pkts - num_tx_fail_total;
1046 for ( ; num_tx_slave < slave_nb_pkts[i]; j++, num_tx_slave++)
1047 bufs[j] = slave_bufs[i][num_tx_slave];
1051 return num_tx_total;
1055 bond_ethdev_tx_burst_broadcast(void *queue, struct rte_mbuf **bufs,
1058 struct bond_dev_private *internals;
1059 struct bond_tx_queue *bd_tx_q;
1061 uint8_t tx_failed_flag = 0, num_of_slaves;
1062 uint8_t slaves[RTE_MAX_ETHPORTS];
1064 uint16_t max_nb_of_tx_pkts = 0;
1066 int slave_tx_total[RTE_MAX_ETHPORTS];
1067 int i, most_successful_tx_slave = -1;
1069 bd_tx_q = (struct bond_tx_queue *)queue;
1070 internals = bd_tx_q->dev_private;
1072 /* Copy slave list to protect against slave up/down changes during tx
1074 num_of_slaves = internals->active_slave_count;
1075 memcpy(slaves, internals->active_slaves,
1076 sizeof(internals->active_slaves[0]) * num_of_slaves);
1078 if (num_of_slaves < 1)
1081 /* Increment reference count on mbufs */
1082 for (i = 0; i < nb_pkts; i++)
1083 rte_mbuf_refcnt_update(bufs[i], num_of_slaves - 1);
1085 /* Transmit burst on each active slave */
1086 for (i = 0; i < num_of_slaves; i++) {
1087 slave_tx_total[i] = rte_eth_tx_burst(slaves[i], bd_tx_q->queue_id,
1090 if (unlikely(slave_tx_total[i] < nb_pkts))
1093 /* record the value and slave index for the slave which transmits the
1094 * maximum number of packets */
1095 if (slave_tx_total[i] > max_nb_of_tx_pkts) {
1096 max_nb_of_tx_pkts = slave_tx_total[i];
1097 most_successful_tx_slave = i;
1101 /* if slaves fail to transmit packets from burst, the calling application
1102 * is not expected to know about multiple references to packets so we must
1103 * handle failures of all packets except those of the most successful slave
1105 if (unlikely(tx_failed_flag))
1106 for (i = 0; i < num_of_slaves; i++)
1107 if (i != most_successful_tx_slave)
1108 while (slave_tx_total[i] < nb_pkts)
1109 rte_pktmbuf_free(bufs[slave_tx_total[i]++]);
1111 return max_nb_of_tx_pkts;
1115 link_properties_set(struct rte_eth_dev *bonded_eth_dev,
1116 struct rte_eth_link *slave_dev_link)
1118 struct rte_eth_link *bonded_dev_link = &bonded_eth_dev->data->dev_link;
1119 struct bond_dev_private *internals = bonded_eth_dev->data->dev_private;
1121 if (slave_dev_link->link_status &&
1122 bonded_eth_dev->data->dev_started) {
1123 bonded_dev_link->link_duplex = slave_dev_link->link_duplex;
1124 bonded_dev_link->link_speed = slave_dev_link->link_speed;
1126 internals->link_props_set = 1;
1131 link_properties_reset(struct rte_eth_dev *bonded_eth_dev)
1133 struct bond_dev_private *internals = bonded_eth_dev->data->dev_private;
1135 memset(&(bonded_eth_dev->data->dev_link), 0,
1136 sizeof(bonded_eth_dev->data->dev_link));
1138 internals->link_props_set = 0;
1142 link_properties_valid(struct rte_eth_link *bonded_dev_link,
1143 struct rte_eth_link *slave_dev_link)
1145 if (bonded_dev_link->link_duplex != slave_dev_link->link_duplex ||
1146 bonded_dev_link->link_speed != slave_dev_link->link_speed)
1153 mac_address_get(struct rte_eth_dev *eth_dev, struct ether_addr *dst_mac_addr)
1155 struct ether_addr *mac_addr;
1157 if (eth_dev == NULL) {
1158 RTE_LOG(ERR, PMD, "%s: NULL pointer eth_dev specified\n", __func__);
1162 if (dst_mac_addr == NULL) {
1163 RTE_LOG(ERR, PMD, "%s: NULL pointer MAC specified\n", __func__);
1167 mac_addr = eth_dev->data->mac_addrs;
1169 ether_addr_copy(mac_addr, dst_mac_addr);
1174 mac_address_set(struct rte_eth_dev *eth_dev, struct ether_addr *new_mac_addr)
1176 struct ether_addr *mac_addr;
1178 if (eth_dev == NULL) {
1179 RTE_BOND_LOG(ERR, "NULL pointer eth_dev specified");
1183 if (new_mac_addr == NULL) {
1184 RTE_BOND_LOG(ERR, "NULL pointer MAC specified");
1188 mac_addr = eth_dev->data->mac_addrs;
1190 /* If new MAC is different to current MAC then update */
1191 if (memcmp(mac_addr, new_mac_addr, sizeof(*mac_addr)) != 0)
1192 memcpy(mac_addr, new_mac_addr, sizeof(*mac_addr));
1198 mac_address_slaves_update(struct rte_eth_dev *bonded_eth_dev)
1200 struct bond_dev_private *internals = bonded_eth_dev->data->dev_private;
1203 /* Update slave devices MAC addresses */
1204 if (internals->slave_count < 1)
1207 switch (internals->mode) {
1208 case BONDING_MODE_ROUND_ROBIN:
1209 case BONDING_MODE_BALANCE:
1210 case BONDING_MODE_BROADCAST:
1211 for (i = 0; i < internals->slave_count; i++) {
1212 if (mac_address_set(&rte_eth_devices[internals->slaves[i].port_id],
1213 bonded_eth_dev->data->mac_addrs)) {
1214 RTE_BOND_LOG(ERR, "Failed to update port Id %d MAC address",
1215 internals->slaves[i].port_id);
1220 case BONDING_MODE_8023AD:
1221 bond_mode_8023ad_mac_address_update(bonded_eth_dev);
1223 case BONDING_MODE_ACTIVE_BACKUP:
1224 case BONDING_MODE_TLB:
1225 case BONDING_MODE_ALB:
1227 for (i = 0; i < internals->slave_count; i++) {
1228 if (internals->slaves[i].port_id ==
1229 internals->current_primary_port) {
1230 if (mac_address_set(&rte_eth_devices[internals->primary_port],
1231 bonded_eth_dev->data->mac_addrs)) {
1232 RTE_BOND_LOG(ERR, "Failed to update port Id %d MAC address",
1233 internals->current_primary_port);
1237 if (mac_address_set(
1238 &rte_eth_devices[internals->slaves[i].port_id],
1239 &internals->slaves[i].persisted_mac_addr)) {
1240 RTE_BOND_LOG(ERR, "Failed to update port Id %d MAC address",
1241 internals->slaves[i].port_id);
1252 bond_ethdev_mode_set(struct rte_eth_dev *eth_dev, int mode)
1254 struct bond_dev_private *internals;
1256 internals = eth_dev->data->dev_private;
1259 case BONDING_MODE_ROUND_ROBIN:
1260 eth_dev->tx_pkt_burst = bond_ethdev_tx_burst_round_robin;
1261 eth_dev->rx_pkt_burst = bond_ethdev_rx_burst;
1263 case BONDING_MODE_ACTIVE_BACKUP:
1264 eth_dev->tx_pkt_burst = bond_ethdev_tx_burst_active_backup;
1265 eth_dev->rx_pkt_burst = bond_ethdev_rx_burst_active_backup;
1267 case BONDING_MODE_BALANCE:
1268 eth_dev->tx_pkt_burst = bond_ethdev_tx_burst_balance;
1269 eth_dev->rx_pkt_burst = bond_ethdev_rx_burst;
1271 case BONDING_MODE_BROADCAST:
1272 eth_dev->tx_pkt_burst = bond_ethdev_tx_burst_broadcast;
1273 eth_dev->rx_pkt_burst = bond_ethdev_rx_burst;
1275 case BONDING_MODE_8023AD:
1276 if (bond_mode_8023ad_enable(eth_dev) != 0)
1279 eth_dev->rx_pkt_burst = bond_ethdev_rx_burst_8023ad;
1280 eth_dev->tx_pkt_burst = bond_ethdev_tx_burst_8023ad;
1281 RTE_LOG(WARNING, PMD,
1282 "Using mode 4, it is necessary to do TX burst and RX burst "
1283 "at least every 100ms.\n");
1285 case BONDING_MODE_TLB:
1286 eth_dev->tx_pkt_burst = bond_ethdev_tx_burst_tlb;
1287 eth_dev->rx_pkt_burst = bond_ethdev_rx_burst_active_backup;
1289 case BONDING_MODE_ALB:
1290 if (bond_mode_alb_enable(eth_dev) != 0)
1293 eth_dev->tx_pkt_burst = bond_ethdev_tx_burst_alb;
1294 eth_dev->rx_pkt_burst = bond_ethdev_rx_burst_alb;
1300 internals->mode = mode;
1306 slave_configure(struct rte_eth_dev *bonded_eth_dev,
1307 struct rte_eth_dev *slave_eth_dev)
1309 struct bond_rx_queue *bd_rx_q;
1310 struct bond_tx_queue *bd_tx_q;
1315 rte_eth_dev_stop(slave_eth_dev->data->port_id);
1317 /* Enable interrupts on slave device if supported */
1318 if (slave_eth_dev->driver->pci_drv.drv_flags & RTE_PCI_DRV_INTR_LSC)
1319 slave_eth_dev->data->dev_conf.intr_conf.lsc = 1;
1321 /* Configure device */
1322 errval = rte_eth_dev_configure(slave_eth_dev->data->port_id,
1323 bonded_eth_dev->data->nb_rx_queues,
1324 bonded_eth_dev->data->nb_tx_queues,
1325 &(slave_eth_dev->data->dev_conf));
1327 RTE_BOND_LOG(ERR, "Cannot configure slave device: port %u , err (%d)",
1328 slave_eth_dev->data->port_id, errval);
1332 /* Setup Rx Queues */
1333 for (q_id = 0; q_id < bonded_eth_dev->data->nb_rx_queues; q_id++) {
1334 bd_rx_q = (struct bond_rx_queue *)bonded_eth_dev->data->rx_queues[q_id];
1336 errval = rte_eth_rx_queue_setup(slave_eth_dev->data->port_id, q_id,
1337 bd_rx_q->nb_rx_desc,
1338 rte_eth_dev_socket_id(slave_eth_dev->data->port_id),
1339 &(bd_rx_q->rx_conf), bd_rx_q->mb_pool);
1342 "rte_eth_rx_queue_setup: port=%d queue_id %d, err (%d)",
1343 slave_eth_dev->data->port_id, q_id, errval);
1348 /* Setup Tx Queues */
1349 for (q_id = 0; q_id < bonded_eth_dev->data->nb_tx_queues; q_id++) {
1350 bd_tx_q = (struct bond_tx_queue *)bonded_eth_dev->data->tx_queues[q_id];
1352 errval = rte_eth_tx_queue_setup(slave_eth_dev->data->port_id, q_id,
1353 bd_tx_q->nb_tx_desc,
1354 rte_eth_dev_socket_id(slave_eth_dev->data->port_id),
1358 "rte_eth_tx_queue_setup: port=%d queue_id %d, err (%d)",
1359 slave_eth_dev->data->port_id, q_id, errval);
1365 errval = rte_eth_dev_start(slave_eth_dev->data->port_id);
1367 RTE_BOND_LOG(ERR, "rte_eth_dev_start: port=%u, err (%d)",
1368 slave_eth_dev->data->port_id, errval);
1376 slave_remove(struct bond_dev_private *internals,
1377 struct rte_eth_dev *slave_eth_dev)
1381 for (i = 0; i < internals->slave_count; i++)
1382 if (internals->slaves[i].port_id ==
1383 slave_eth_dev->data->port_id)
1386 if (i < (internals->slave_count - 1))
1387 memmove(&internals->slaves[i], &internals->slaves[i + 1],
1388 sizeof(internals->slaves[0]) *
1389 (internals->slave_count - i - 1));
1391 internals->slave_count--;
1395 bond_ethdev_slave_link_status_change_monitor(void *cb_arg);
1398 slave_add(struct bond_dev_private *internals,
1399 struct rte_eth_dev *slave_eth_dev)
1401 struct bond_slave_details *slave_details =
1402 &internals->slaves[internals->slave_count];
1404 slave_details->port_id = slave_eth_dev->data->port_id;
1405 slave_details->last_link_status = 0;
1407 /* If slave device doesn't support interrupts then we need to enabled
1408 * polling to monitor link status */
1409 if (!(slave_eth_dev->pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)) {
1410 slave_details->link_status_poll_enabled = 1;
1412 if (!internals->link_status_polling_enabled) {
1413 internals->link_status_polling_enabled = 1;
1415 rte_eal_alarm_set(internals->link_status_polling_interval_ms * 1000,
1416 bond_ethdev_slave_link_status_change_monitor,
1417 (void *)&rte_eth_devices[internals->port_id]);
1421 slave_details->link_status_wait_to_complete = 0;
1422 /* clean tlb_last_obytes when adding port for bonding device */
1423 memcpy(&(slave_details->persisted_mac_addr), slave_eth_dev->data->mac_addrs,
1424 sizeof(struct ether_addr));
1428 bond_ethdev_primary_set(struct bond_dev_private *internals,
1429 uint8_t slave_port_id)
1433 if (internals->active_slave_count < 1)
1434 internals->current_primary_port = slave_port_id;
1436 /* Search bonded device slave ports for new proposed primary port */
1437 for (i = 0; i < internals->active_slave_count; i++) {
1438 if (internals->active_slaves[i] == slave_port_id)
1439 internals->current_primary_port = slave_port_id;
1444 bond_ethdev_promiscuous_enable(struct rte_eth_dev *eth_dev);
1447 bond_ethdev_start(struct rte_eth_dev *eth_dev)
1449 struct bond_dev_private *internals;
1452 /* slave eth dev will be started by bonded device */
1453 if (valid_bonded_ethdev(eth_dev)) {
1454 RTE_BOND_LOG(ERR, "User tried to explicitly start a slave eth_dev (%d)",
1455 eth_dev->data->port_id);
1459 eth_dev->data->dev_link.link_status = 0;
1460 eth_dev->data->dev_started = 1;
1462 internals = eth_dev->data->dev_private;
1464 if (internals->slave_count == 0) {
1465 RTE_BOND_LOG(ERR, "Cannot start port since there are no slave devices");
1469 if (internals->user_defined_mac == 0) {
1470 struct ether_addr *new_mac_addr = NULL;
1472 for (i = 0; i < internals->slave_count; i++)
1473 if (internals->slaves[i].port_id == internals->primary_port)
1474 new_mac_addr = &internals->slaves[i].persisted_mac_addr;
1476 if (new_mac_addr == NULL)
1479 if (mac_address_set(eth_dev, new_mac_addr) != 0) {
1480 RTE_BOND_LOG(ERR, "bonded port (%d) failed to update MAC address",
1481 eth_dev->data->port_id);
1486 /* Update all slave devices MACs*/
1487 if (mac_address_slaves_update(eth_dev) != 0)
1490 /* If bonded device is configure in promiscuous mode then re-apply config */
1491 if (internals->promiscuous_en)
1492 bond_ethdev_promiscuous_enable(eth_dev);
1494 /* Reconfigure each slave device if starting bonded device */
1495 for (i = 0; i < internals->slave_count; i++) {
1496 if (slave_configure(eth_dev,
1497 &(rte_eth_devices[internals->slaves[i].port_id])) != 0) {
1499 "bonded port (%d) failed to reconfigure slave device (%d)",
1500 eth_dev->data->port_id, internals->slaves[i].port_id);
1505 if (internals->user_defined_primary_port)
1506 bond_ethdev_primary_set(internals, internals->primary_port);
1508 if (internals->mode == BONDING_MODE_8023AD)
1509 bond_mode_8023ad_start(eth_dev);
1511 if (internals->mode == BONDING_MODE_TLB ||
1512 internals->mode == BONDING_MODE_ALB)
1513 bond_tlb_enable(internals);
1519 bond_ethdev_stop(struct rte_eth_dev *eth_dev)
1521 struct bond_dev_private *internals = eth_dev->data->dev_private;
1524 if (internals->mode == BONDING_MODE_8023AD) {
1528 bond_mode_8023ad_stop(eth_dev);
1530 /* Discard all messages to/from mode 4 state machines */
1531 for (i = 0; i < internals->slave_count; i++) {
1532 port = &mode_8023ad_ports[internals->slaves[i].port_id];
1534 RTE_VERIFY(port->rx_ring != NULL);
1535 while (rte_ring_dequeue(port->rx_ring, &pkt) != -ENOENT)
1536 rte_pktmbuf_free(pkt);
1538 RTE_VERIFY(port->tx_ring != NULL);
1539 while (rte_ring_dequeue(port->tx_ring, &pkt) != -ENOENT)
1540 rte_pktmbuf_free(pkt);
1544 if (internals->mode == BONDING_MODE_TLB ||
1545 internals->mode == BONDING_MODE_ALB) {
1546 bond_tlb_disable(internals);
1547 for (i = 0; i < internals->active_slave_count; i++)
1548 tlb_last_obytets[internals->active_slaves[i]] = 0;
1551 internals->active_slave_count = 0;
1552 internals->link_status_polling_enabled = 0;
1554 eth_dev->data->dev_link.link_status = 0;
1555 eth_dev->data->dev_started = 0;
1559 bond_ethdev_close(struct rte_eth_dev *dev __rte_unused)
1563 /* forward declaration */
1564 static int bond_ethdev_configure(struct rte_eth_dev *dev);
1567 bond_ethdev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1569 struct bond_dev_private *internals = dev->data->dev_private;
1571 dev_info->driver_name = driver_name;
1572 dev_info->max_mac_addrs = 1;
1574 dev_info->max_rx_pktlen = (uint32_t)2048;
1576 dev_info->max_rx_queues = (uint16_t)128;
1577 dev_info->max_tx_queues = (uint16_t)512;
1579 dev_info->min_rx_bufsize = 0;
1580 dev_info->pci_dev = dev->pci_dev;
1582 dev_info->rx_offload_capa = internals->rx_offload_capa;
1583 dev_info->tx_offload_capa = internals->tx_offload_capa;
1587 bond_ethdev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
1588 uint16_t nb_rx_desc, unsigned int socket_id __rte_unused,
1589 const struct rte_eth_rxconf *rx_conf, struct rte_mempool *mb_pool)
1591 struct bond_rx_queue *bd_rx_q = (struct bond_rx_queue *)
1592 rte_zmalloc_socket(NULL, sizeof(struct bond_rx_queue),
1593 0, dev->pci_dev->numa_node);
1594 if (bd_rx_q == NULL)
1597 bd_rx_q->queue_id = rx_queue_id;
1598 bd_rx_q->dev_private = dev->data->dev_private;
1600 bd_rx_q->nb_rx_desc = nb_rx_desc;
1602 memcpy(&(bd_rx_q->rx_conf), rx_conf, sizeof(struct rte_eth_rxconf));
1603 bd_rx_q->mb_pool = mb_pool;
1605 dev->data->rx_queues[rx_queue_id] = bd_rx_q;
1611 bond_ethdev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
1612 uint16_t nb_tx_desc, unsigned int socket_id __rte_unused,
1613 const struct rte_eth_txconf *tx_conf)
1615 struct bond_tx_queue *bd_tx_q = (struct bond_tx_queue *)
1616 rte_zmalloc_socket(NULL, sizeof(struct bond_tx_queue),
1617 0, dev->pci_dev->numa_node);
1619 if (bd_tx_q == NULL)
1622 bd_tx_q->queue_id = tx_queue_id;
1623 bd_tx_q->dev_private = dev->data->dev_private;
1625 bd_tx_q->nb_tx_desc = nb_tx_desc;
1626 memcpy(&(bd_tx_q->tx_conf), tx_conf, sizeof(bd_tx_q->tx_conf));
1628 dev->data->tx_queues[tx_queue_id] = bd_tx_q;
1634 bond_ethdev_rx_queue_release(void *queue)
1643 bond_ethdev_tx_queue_release(void *queue)
1652 bond_ethdev_slave_link_status_change_monitor(void *cb_arg)
1654 struct rte_eth_dev *bonded_ethdev, *slave_ethdev;
1655 struct bond_dev_private *internals;
1657 /* Default value for polling slave found is true as we don't want to
1658 * disable the polling thread if we cannot get the lock */
1659 int i, polling_slave_found = 1;
1664 bonded_ethdev = (struct rte_eth_dev *)cb_arg;
1665 internals = (struct bond_dev_private *)bonded_ethdev->data->dev_private;
1667 if (!bonded_ethdev->data->dev_started ||
1668 !internals->link_status_polling_enabled)
1671 /* If device is currently being configured then don't check slaves link
1672 * status, wait until next period */
1673 if (rte_spinlock_trylock(&internals->lock)) {
1674 if (internals->slave_count > 0)
1675 polling_slave_found = 0;
1677 for (i = 0; i < internals->slave_count; i++) {
1678 if (!internals->slaves[i].link_status_poll_enabled)
1681 slave_ethdev = &rte_eth_devices[internals->slaves[i].port_id];
1682 polling_slave_found = 1;
1684 /* Update slave link status */
1685 (*slave_ethdev->dev_ops->link_update)(slave_ethdev,
1686 internals->slaves[i].link_status_wait_to_complete);
1688 /* if link status has changed since last checked then call lsc
1690 if (slave_ethdev->data->dev_link.link_status !=
1691 internals->slaves[i].last_link_status) {
1692 internals->slaves[i].last_link_status =
1693 slave_ethdev->data->dev_link.link_status;
1695 bond_ethdev_lsc_event_callback(internals->slaves[i].port_id,
1696 RTE_ETH_EVENT_INTR_LSC,
1697 &bonded_ethdev->data->port_id);
1700 rte_spinlock_unlock(&internals->lock);
1703 if (polling_slave_found)
1704 /* Set alarm to continue monitoring link status of slave ethdev's */
1705 rte_eal_alarm_set(internals->link_status_polling_interval_ms * 1000,
1706 bond_ethdev_slave_link_status_change_monitor, cb_arg);
1710 bond_ethdev_link_update(struct rte_eth_dev *bonded_eth_dev,
1711 int wait_to_complete)
1713 struct bond_dev_private *internals = bonded_eth_dev->data->dev_private;
1715 if (!bonded_eth_dev->data->dev_started ||
1716 internals->active_slave_count == 0) {
1717 bonded_eth_dev->data->dev_link.link_status = 0;
1720 struct rte_eth_dev *slave_eth_dev;
1723 for (i = 0; i < internals->active_slave_count; i++) {
1724 slave_eth_dev = &rte_eth_devices[internals->active_slaves[i]];
1726 (*slave_eth_dev->dev_ops->link_update)(slave_eth_dev,
1728 if (slave_eth_dev->data->dev_link.link_status == 1) {
1734 bonded_eth_dev->data->dev_link.link_status = link_up;
1741 bond_ethdev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1743 struct bond_dev_private *internals = dev->data->dev_private;
1744 struct rte_eth_stats slave_stats;
1748 /* clear bonded stats before populating from slaves */
1749 memset(stats, 0, sizeof(*stats));
1751 for (i = 0; i < internals->slave_count; i++) {
1752 rte_eth_stats_get(internals->slaves[i].port_id, &slave_stats);
1754 stats->ipackets += slave_stats.ipackets;
1755 stats->opackets += slave_stats.opackets;
1756 stats->ibytes += slave_stats.ibytes;
1757 stats->obytes += slave_stats.obytes;
1758 stats->ierrors += slave_stats.ierrors;
1759 stats->oerrors += slave_stats.oerrors;
1760 stats->imcasts += slave_stats.imcasts;
1761 stats->rx_nombuf += slave_stats.rx_nombuf;
1762 stats->fdirmatch += slave_stats.fdirmatch;
1763 stats->fdirmiss += slave_stats.fdirmiss;
1764 stats->tx_pause_xon += slave_stats.tx_pause_xon;
1765 stats->rx_pause_xon += slave_stats.rx_pause_xon;
1766 stats->tx_pause_xoff += slave_stats.tx_pause_xoff;
1767 stats->rx_pause_xoff += slave_stats.rx_pause_xoff;
1772 bond_ethdev_stats_reset(struct rte_eth_dev *dev)
1774 struct bond_dev_private *internals = dev->data->dev_private;
1777 for (i = 0; i < internals->slave_count; i++)
1778 rte_eth_stats_reset(internals->slaves[i].port_id);
1782 bond_ethdev_promiscuous_enable(struct rte_eth_dev *eth_dev)
1784 struct bond_dev_private *internals = eth_dev->data->dev_private;
1787 internals->promiscuous_en = 1;
1789 switch (internals->mode) {
1790 /* Promiscuous mode is propagated to all slaves */
1791 case BONDING_MODE_ROUND_ROBIN:
1792 case BONDING_MODE_BALANCE:
1793 case BONDING_MODE_BROADCAST:
1794 for (i = 0; i < internals->slave_count; i++)
1795 rte_eth_promiscuous_enable(internals->slaves[i].port_id);
1797 /* In mode4 promiscus mode is managed when slave is added/removed */
1798 case BONDING_MODE_8023AD:
1800 /* Promiscuous mode is propagated only to primary slave */
1801 case BONDING_MODE_ACTIVE_BACKUP:
1802 case BONDING_MODE_TLB:
1803 case BONDING_MODE_ALB:
1805 rte_eth_promiscuous_enable(internals->current_primary_port);
1810 bond_ethdev_promiscuous_disable(struct rte_eth_dev *dev)
1812 struct bond_dev_private *internals = dev->data->dev_private;
1815 internals->promiscuous_en = 0;
1817 switch (internals->mode) {
1818 /* Promiscuous mode is propagated to all slaves */
1819 case BONDING_MODE_ROUND_ROBIN:
1820 case BONDING_MODE_BALANCE:
1821 case BONDING_MODE_BROADCAST:
1822 for (i = 0; i < internals->slave_count; i++)
1823 rte_eth_promiscuous_disable(internals->slaves[i].port_id);
1825 /* In mode4 promiscus mode is set managed when slave is added/removed */
1826 case BONDING_MODE_8023AD:
1828 /* Promiscuous mode is propagated only to primary slave */
1829 case BONDING_MODE_ACTIVE_BACKUP:
1830 case BONDING_MODE_TLB:
1831 case BONDING_MODE_ALB:
1833 rte_eth_promiscuous_disable(internals->current_primary_port);
1838 bond_ethdev_delayed_lsc_propagation(void *arg)
1843 _rte_eth_dev_callback_process((struct rte_eth_dev *)arg,
1844 RTE_ETH_EVENT_INTR_LSC);
1848 bond_ethdev_lsc_event_callback(uint8_t port_id, enum rte_eth_event_type type,
1851 struct rte_eth_dev *bonded_eth_dev, *slave_eth_dev;
1852 struct bond_dev_private *internals;
1853 struct rte_eth_link link;
1855 int i, valid_slave = 0;
1857 uint8_t lsc_flag = 0;
1859 if (type != RTE_ETH_EVENT_INTR_LSC || param == NULL)
1862 bonded_eth_dev = &rte_eth_devices[*(uint8_t *)param];
1863 slave_eth_dev = &rte_eth_devices[port_id];
1865 if (valid_bonded_ethdev(bonded_eth_dev))
1868 internals = bonded_eth_dev->data->dev_private;
1870 /* If the device isn't started don't handle interrupts */
1871 if (!bonded_eth_dev->data->dev_started)
1874 /* verify that port_id is a valid slave of bonded port */
1875 for (i = 0; i < internals->slave_count; i++) {
1876 if (internals->slaves[i].port_id == port_id) {
1885 /* Search for port in active port list */
1886 active_pos = find_slave_by_id(internals->active_slaves,
1887 internals->active_slave_count, port_id);
1889 rte_eth_link_get_nowait(port_id, &link);
1890 if (link.link_status) {
1891 if (active_pos < internals->active_slave_count)
1894 /* if no active slave ports then set this port to be primary port */
1895 if (internals->active_slave_count < 1) {
1896 /* If first active slave, then change link status */
1897 bonded_eth_dev->data->dev_link.link_status = 1;
1898 internals->current_primary_port = port_id;
1901 mac_address_slaves_update(bonded_eth_dev);
1903 /* Inherit eth dev link properties from first active slave */
1904 link_properties_set(bonded_eth_dev,
1905 &(slave_eth_dev->data->dev_link));
1908 activate_slave(bonded_eth_dev, port_id);
1910 /* If user has defined the primary port then default to using it */
1911 if (internals->user_defined_primary_port &&
1912 internals->primary_port == port_id)
1913 bond_ethdev_primary_set(internals, port_id);
1915 if (active_pos == internals->active_slave_count)
1918 /* Remove from active slave list */
1919 deactivate_slave(bonded_eth_dev, port_id);
1921 /* No active slaves, change link status to down and reset other
1922 * link properties */
1923 if (internals->active_slave_count < 1) {
1925 bonded_eth_dev->data->dev_link.link_status = 0;
1927 link_properties_reset(bonded_eth_dev);
1930 /* Update primary id, take first active slave from list or if none
1931 * available set to -1 */
1932 if (port_id == internals->current_primary_port) {
1933 if (internals->active_slave_count > 0)
1934 bond_ethdev_primary_set(internals,
1935 internals->active_slaves[0]);
1937 internals->current_primary_port = internals->primary_port;
1942 /* Cancel any possible outstanding interrupts if delays are enabled */
1943 if (internals->link_up_delay_ms > 0 ||
1944 internals->link_down_delay_ms > 0)
1945 rte_eal_alarm_cancel(bond_ethdev_delayed_lsc_propagation,
1948 if (bonded_eth_dev->data->dev_link.link_status) {
1949 if (internals->link_up_delay_ms > 0)
1950 rte_eal_alarm_set(internals->link_up_delay_ms * 1000,
1951 bond_ethdev_delayed_lsc_propagation,
1952 (void *)bonded_eth_dev);
1954 _rte_eth_dev_callback_process(bonded_eth_dev,
1955 RTE_ETH_EVENT_INTR_LSC);
1958 if (internals->link_down_delay_ms > 0)
1959 rte_eal_alarm_set(internals->link_down_delay_ms * 1000,
1960 bond_ethdev_delayed_lsc_propagation,
1961 (void *)bonded_eth_dev);
1963 _rte_eth_dev_callback_process(bonded_eth_dev,
1964 RTE_ETH_EVENT_INTR_LSC);
1969 struct eth_dev_ops default_dev_ops = {
1970 .dev_start = bond_ethdev_start,
1971 .dev_stop = bond_ethdev_stop,
1972 .dev_close = bond_ethdev_close,
1973 .dev_configure = bond_ethdev_configure,
1974 .dev_infos_get = bond_ethdev_info,
1975 .rx_queue_setup = bond_ethdev_rx_queue_setup,
1976 .tx_queue_setup = bond_ethdev_tx_queue_setup,
1977 .rx_queue_release = bond_ethdev_rx_queue_release,
1978 .tx_queue_release = bond_ethdev_tx_queue_release,
1979 .link_update = bond_ethdev_link_update,
1980 .stats_get = bond_ethdev_stats_get,
1981 .stats_reset = bond_ethdev_stats_reset,
1982 .promiscuous_enable = bond_ethdev_promiscuous_enable,
1983 .promiscuous_disable = bond_ethdev_promiscuous_disable
1987 bond_init(const char *name, const char *params)
1989 struct bond_dev_private *internals;
1990 struct rte_kvargs *kvlist;
1991 uint8_t bonding_mode, socket_id;
1992 int arg_count, port_id;
1994 RTE_LOG(INFO, EAL, "Initializing pmd_bond for %s\n", name);
1996 kvlist = rte_kvargs_parse(params, pmd_bond_init_valid_arguments);
2000 /* Parse link bonding mode */
2001 if (rte_kvargs_count(kvlist, PMD_BOND_MODE_KVARG) == 1) {
2002 if (rte_kvargs_process(kvlist, PMD_BOND_MODE_KVARG,
2003 &bond_ethdev_parse_slave_mode_kvarg,
2004 &bonding_mode) != 0) {
2005 RTE_LOG(ERR, EAL, "Invalid mode for bonded device %s\n",
2010 RTE_LOG(ERR, EAL, "Mode must be specified only once for bonded "
2011 "device %s\n", name);
2015 /* Parse socket id to create bonding device on */
2016 arg_count = rte_kvargs_count(kvlist, PMD_BOND_SOCKET_ID_KVARG);
2017 if (arg_count == 1) {
2018 if (rte_kvargs_process(kvlist, PMD_BOND_SOCKET_ID_KVARG,
2019 &bond_ethdev_parse_socket_id_kvarg, &socket_id)
2021 RTE_LOG(ERR, EAL, "Invalid socket Id specified for "
2022 "bonded device %s\n", name);
2025 } else if (arg_count > 1) {
2026 RTE_LOG(ERR, EAL, "Socket Id can be specified only once for "
2027 "bonded device %s\n", name);
2030 socket_id = rte_socket_id();
2033 /* Create link bonding eth device */
2034 port_id = rte_eth_bond_create(name, bonding_mode, socket_id);
2036 RTE_LOG(ERR, EAL, "Failed to create socket %s in mode %u on "
2037 "socket %u.\n", name, bonding_mode, socket_id);
2040 internals = rte_eth_devices[port_id].data->dev_private;
2041 internals->kvlist = kvlist;
2043 RTE_LOG(INFO, EAL, "Create bonded device %s on port %d in mode %u on "
2044 "socket %u.\n", name, port_id, bonding_mode, socket_id);
2048 rte_kvargs_free(kvlist);
2053 /* this part will resolve the slave portids after all the other pdev and vdev
2054 * have been allocated */
2056 bond_ethdev_configure(struct rte_eth_dev *dev)
2058 char *name = dev->data->name;
2059 struct bond_dev_private *internals = dev->data->dev_private;
2060 struct rte_kvargs *kvlist = internals->kvlist;
2061 int arg_count, port_id = dev - rte_eth_devices;
2064 * if no kvlist, it means that this bonded device has been created
2065 * through the bonding api.
2070 /* Parse MAC address for bonded device */
2071 arg_count = rte_kvargs_count(kvlist, PMD_BOND_MAC_ADDR_KVARG);
2072 if (arg_count == 1) {
2073 struct ether_addr bond_mac;
2075 if (rte_kvargs_process(kvlist, PMD_BOND_MAC_ADDR_KVARG,
2076 &bond_ethdev_parse_bond_mac_addr_kvarg, &bond_mac) < 0) {
2077 RTE_LOG(INFO, EAL, "Invalid mac address for bonded device %s\n",
2082 /* Set MAC address */
2083 if (rte_eth_bond_mac_address_set(port_id, &bond_mac) != 0) {
2085 "Failed to set mac address on bonded device %s\n",
2089 } else if (arg_count > 1) {
2091 "MAC address can be specified only once for bonded device %s\n",
2096 /* Parse/set balance mode transmit policy */
2097 arg_count = rte_kvargs_count(kvlist, PMD_BOND_XMIT_POLICY_KVARG);
2098 if (arg_count == 1) {
2099 uint8_t xmit_policy;
2101 if (rte_kvargs_process(kvlist, PMD_BOND_XMIT_POLICY_KVARG,
2102 &bond_ethdev_parse_balance_xmit_policy_kvarg, &xmit_policy) !=
2105 "Invalid xmit policy specified for bonded device %s\n",
2110 /* Set balance mode transmit policy*/
2111 if (rte_eth_bond_xmit_policy_set(port_id, xmit_policy) != 0) {
2113 "Failed to set balance xmit policy on bonded device %s\n",
2117 } else if (arg_count > 1) {
2119 "Transmit policy can be specified only once for bonded device"
2124 /* Parse/add slave ports to bonded device */
2125 if (rte_kvargs_count(kvlist, PMD_BOND_SLAVE_PORT_KVARG) > 0) {
2126 struct bond_ethdev_slave_ports slave_ports;
2129 memset(&slave_ports, 0, sizeof(slave_ports));
2131 if (rte_kvargs_process(kvlist, PMD_BOND_SLAVE_PORT_KVARG,
2132 &bond_ethdev_parse_slave_port_kvarg, &slave_ports) != 0) {
2134 "Failed to parse slave ports for bonded device %s\n",
2139 for (i = 0; i < slave_ports.slave_count; i++) {
2140 if (rte_eth_bond_slave_add(port_id, slave_ports.slaves[i]) != 0) {
2142 "Failed to add port %d as slave to bonded device %s\n",
2143 slave_ports.slaves[i], name);
2148 RTE_LOG(INFO, EAL, "No slaves specified for bonded device %s\n", name);
2152 /* Parse/set primary slave port id*/
2153 arg_count = rte_kvargs_count(kvlist, PMD_BOND_PRIMARY_SLAVE_KVARG);
2154 if (arg_count == 1) {
2155 uint8_t primary_slave_port_id;
2157 if (rte_kvargs_process(kvlist,
2158 PMD_BOND_PRIMARY_SLAVE_KVARG,
2159 &bond_ethdev_parse_primary_slave_port_id_kvarg,
2160 &primary_slave_port_id) < 0) {
2162 "Invalid primary slave port id specified for bonded device"
2167 /* Set balance mode transmit policy*/
2168 if (rte_eth_bond_primary_set(port_id, (uint8_t)primary_slave_port_id)
2171 "Failed to set primary slave port %d on bonded device %s\n",
2172 primary_slave_port_id, name);
2175 } else if (arg_count > 1) {
2177 "Primary slave can be specified only once for bonded device"
2182 /* Parse link status monitor polling interval */
2183 arg_count = rte_kvargs_count(kvlist, PMD_BOND_LSC_POLL_PERIOD_KVARG);
2184 if (arg_count == 1) {
2185 uint32_t lsc_poll_interval_ms;
2187 if (rte_kvargs_process(kvlist,
2188 PMD_BOND_LSC_POLL_PERIOD_KVARG,
2189 &bond_ethdev_parse_time_ms_kvarg,
2190 &lsc_poll_interval_ms) < 0) {
2192 "Invalid lsc polling interval value specified for bonded"
2193 " device %s\n", name);
2197 if (rte_eth_bond_link_monitoring_set(port_id, lsc_poll_interval_ms)
2200 "Failed to set lsc monitor polling interval (%u ms) on"
2201 " bonded device %s\n", lsc_poll_interval_ms, name);
2204 } else if (arg_count > 1) {
2206 "LSC polling interval can be specified only once for bonded"
2207 " device %s\n", name);
2211 /* Parse link up interrupt propagation delay */
2212 arg_count = rte_kvargs_count(kvlist, PMD_BOND_LINK_UP_PROP_DELAY_KVARG);
2213 if (arg_count == 1) {
2214 uint32_t link_up_delay_ms;
2216 if (rte_kvargs_process(kvlist,
2217 PMD_BOND_LINK_UP_PROP_DELAY_KVARG,
2218 &bond_ethdev_parse_time_ms_kvarg,
2219 &link_up_delay_ms) < 0) {
2221 "Invalid link up propagation delay value specified for"
2222 " bonded device %s\n", name);
2226 /* Set balance mode transmit policy*/
2227 if (rte_eth_bond_link_up_prop_delay_set(port_id, link_up_delay_ms)
2230 "Failed to set link up propagation delay (%u ms) on bonded"
2231 " device %s\n", link_up_delay_ms, name);
2234 } else if (arg_count > 1) {
2236 "Link up propagation delay can be specified only once for"
2237 " bonded device %s\n", name);
2241 /* Parse link down interrupt propagation delay */
2242 arg_count = rte_kvargs_count(kvlist, PMD_BOND_LINK_DOWN_PROP_DELAY_KVARG);
2243 if (arg_count == 1) {
2244 uint32_t link_down_delay_ms;
2246 if (rte_kvargs_process(kvlist,
2247 PMD_BOND_LINK_DOWN_PROP_DELAY_KVARG,
2248 &bond_ethdev_parse_time_ms_kvarg,
2249 &link_down_delay_ms) < 0) {
2251 "Invalid link down propagation delay value specified for"
2252 " bonded device %s\n", name);
2256 /* Set balance mode transmit policy*/
2257 if (rte_eth_bond_link_down_prop_delay_set(port_id, link_down_delay_ms)
2260 "Failed to set link down propagation delay (%u ms) on"
2261 " bonded device %s\n", link_down_delay_ms, name);
2264 } else if (arg_count > 1) {
2266 "Link down propagation delay can be specified only once for"
2267 " bonded device %s\n", name);
2274 static struct rte_driver bond_drv = {
2280 PMD_REGISTER_DRIVER(bond_drv);