net/bonding: fix setting VLAN ID on slave ports
[dpdk.git] / drivers / net / bonding / rte_eth_bond_api.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2017 Intel Corporation
3  */
4
5 #include <string.h>
6
7 #include <rte_mbuf.h>
8 #include <rte_malloc.h>
9 #include <rte_ethdev_driver.h>
10 #include <rte_tcp.h>
11 #include <rte_bus_vdev.h>
12 #include <rte_kvargs.h>
13
14 #include "rte_eth_bond.h"
15 #include "rte_eth_bond_private.h"
16 #include "rte_eth_bond_8023ad_private.h"
17
18 int
19 check_for_bonded_ethdev(const struct rte_eth_dev *eth_dev)
20 {
21         /* Check valid pointer */
22         if (eth_dev->device->driver->name == NULL)
23                 return -1;
24
25         /* return 0 if driver name matches */
26         return eth_dev->device->driver->name != pmd_bond_drv.driver.name;
27 }
28
29 int
30 valid_bonded_port_id(uint16_t port_id)
31 {
32         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
33         return check_for_bonded_ethdev(&rte_eth_devices[port_id]);
34 }
35
36 int
37 check_for_master_bonded_ethdev(const struct rte_eth_dev *eth_dev)
38 {
39         int i;
40         struct bond_dev_private *internals;
41
42         if (check_for_bonded_ethdev(eth_dev) != 0)
43                 return 0;
44
45         internals = eth_dev->data->dev_private;
46
47         /* Check if any of slave devices is a bonded device */
48         for (i = 0; i < internals->slave_count; i++)
49                 if (valid_bonded_port_id(internals->slaves[i].port_id) == 0)
50                         return 1;
51
52         return 0;
53 }
54
55 int
56 valid_slave_port_id(uint16_t port_id, uint8_t mode)
57 {
58         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
59
60         /* Verify that port_id refers to a non bonded port */
61         if (check_for_bonded_ethdev(&rte_eth_devices[port_id]) == 0 &&
62                         mode == BONDING_MODE_8023AD) {
63                 RTE_BOND_LOG(ERR, "Cannot add slave to bonded device in 802.3ad"
64                                 " mode as slave is also a bonded device, only "
65                                 "physical devices can be support in this mode.");
66                 return -1;
67         }
68
69         return 0;
70 }
71
72 void
73 activate_slave(struct rte_eth_dev *eth_dev, uint16_t port_id)
74 {
75         struct bond_dev_private *internals = eth_dev->data->dev_private;
76         uint8_t active_count = internals->active_slave_count;
77
78         if (internals->mode == BONDING_MODE_8023AD)
79                 bond_mode_8023ad_activate_slave(eth_dev, port_id);
80
81         if (internals->mode == BONDING_MODE_TLB
82                         || internals->mode == BONDING_MODE_ALB) {
83
84                 internals->tlb_slaves_order[active_count] = port_id;
85         }
86
87         RTE_ASSERT(internals->active_slave_count <
88                         (RTE_DIM(internals->active_slaves) - 1));
89
90         internals->active_slaves[internals->active_slave_count] = port_id;
91         internals->active_slave_count++;
92
93         if (internals->mode == BONDING_MODE_TLB)
94                 bond_tlb_activate_slave(internals);
95         if (internals->mode == BONDING_MODE_ALB)
96                 bond_mode_alb_client_list_upd(eth_dev);
97 }
98
99 void
100 deactivate_slave(struct rte_eth_dev *eth_dev, uint16_t port_id)
101 {
102         uint16_t slave_pos;
103         struct bond_dev_private *internals = eth_dev->data->dev_private;
104         uint16_t active_count = internals->active_slave_count;
105
106         if (internals->mode == BONDING_MODE_8023AD) {
107                 bond_mode_8023ad_stop(eth_dev);
108                 bond_mode_8023ad_deactivate_slave(eth_dev, port_id);
109         } else if (internals->mode == BONDING_MODE_TLB
110                         || internals->mode == BONDING_MODE_ALB)
111                 bond_tlb_disable(internals);
112
113         slave_pos = find_slave_by_id(internals->active_slaves, active_count,
114                         port_id);
115
116         /* If slave was not at the end of the list
117          * shift active slaves up active array list */
118         if (slave_pos < active_count) {
119                 active_count--;
120                 memmove(internals->active_slaves + slave_pos,
121                                 internals->active_slaves + slave_pos + 1,
122                                 (active_count - slave_pos) *
123                                         sizeof(internals->active_slaves[0]));
124         }
125
126         RTE_ASSERT(active_count < RTE_DIM(internals->active_slaves));
127         internals->active_slave_count = active_count;
128
129         if (eth_dev->data->dev_started) {
130                 if (internals->mode == BONDING_MODE_8023AD) {
131                         bond_mode_8023ad_start(eth_dev);
132                 } else if (internals->mode == BONDING_MODE_TLB) {
133                         bond_tlb_enable(internals);
134                 } else if (internals->mode == BONDING_MODE_ALB) {
135                         bond_tlb_enable(internals);
136                         bond_mode_alb_client_list_upd(eth_dev);
137                 }
138         }
139 }
140
141 int
142 rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id)
143 {
144         struct bond_dev_private *internals;
145         char devargs[52];
146         uint16_t port_id;
147         int ret;
148
149         if (name == NULL) {
150                 RTE_BOND_LOG(ERR, "Invalid name specified");
151                 return -EINVAL;
152         }
153
154         ret = snprintf(devargs, sizeof(devargs),
155                 "driver=net_bonding,mode=%d,socket_id=%d", mode, socket_id);
156         if (ret < 0 || ret >= (int)sizeof(devargs))
157                 return -ENOMEM;
158
159         ret = rte_vdev_init(name, devargs);
160         if (ret)
161                 return -ENOMEM;
162
163         ret = rte_eth_dev_get_port_by_name(name, &port_id);
164         RTE_ASSERT(!ret);
165
166         /*
167          * To make bond_ethdev_configure() happy we need to free the
168          * internals->kvlist here.
169          *
170          * Also see comment in bond_ethdev_configure().
171          */
172         internals = rte_eth_devices[port_id].data->dev_private;
173         rte_kvargs_free(internals->kvlist);
174         internals->kvlist = NULL;
175
176         return port_id;
177 }
178
179 int
180 rte_eth_bond_free(const char *name)
181 {
182         return rte_vdev_uninit(name);
183 }
184
185 static int
186 slave_vlan_filter_set(uint16_t bonded_port_id, uint16_t slave_port_id)
187 {
188         struct rte_eth_dev *bonded_eth_dev;
189         struct bond_dev_private *internals;
190         int found;
191         int res = 0;
192         uint64_t slab = 0;
193         uint32_t pos = 0;
194         uint16_t first;
195
196         bonded_eth_dev = &rte_eth_devices[bonded_port_id];
197         if (bonded_eth_dev->data->dev_conf.rxmode.hw_vlan_filter == 0)
198                 return 0;
199
200         internals = bonded_eth_dev->data->dev_private;
201         found = rte_bitmap_scan(internals->vlan_filter_bmp, &pos, &slab);
202         first = pos;
203
204         if (!found)
205                 return 0;
206
207         do {
208                 uint32_t i;
209                 uint64_t mask;
210
211                 for (i = 0, mask = 1;
212                      i < RTE_BITMAP_SLAB_BIT_SIZE;
213                      i ++, mask <<= 1) {
214                         if (unlikely(slab & mask)) {
215                                 uint16_t vlan_id = pos + i;
216
217                                 res = rte_eth_dev_vlan_filter(slave_port_id,
218                                                               vlan_id, 1);
219                         }
220                 }
221                 found = rte_bitmap_scan(internals->vlan_filter_bmp,
222                                         &pos, &slab);
223         } while (found && first != pos && res == 0);
224
225         return res;
226 }
227
228 static int
229 __eth_bond_slave_add_lock_free(uint16_t bonded_port_id, uint16_t slave_port_id)
230 {
231         struct rte_eth_dev *bonded_eth_dev, *slave_eth_dev;
232         struct bond_dev_private *internals;
233         struct rte_eth_link link_props;
234         struct rte_eth_dev_info dev_info;
235
236         bonded_eth_dev = &rte_eth_devices[bonded_port_id];
237         internals = bonded_eth_dev->data->dev_private;
238
239         if (valid_slave_port_id(slave_port_id, internals->mode) != 0)
240                 return -1;
241
242         slave_eth_dev = &rte_eth_devices[slave_port_id];
243         if (slave_eth_dev->data->dev_flags & RTE_ETH_DEV_BONDED_SLAVE) {
244                 RTE_BOND_LOG(ERR, "Slave device is already a slave of a bonded device");
245                 return -1;
246         }
247
248         rte_eth_dev_info_get(slave_port_id, &dev_info);
249         if (dev_info.max_rx_pktlen < internals->max_rx_pktlen) {
250                 RTE_BOND_LOG(ERR, "Slave (port %u) max_rx_pktlen too small",
251                              slave_port_id);
252                 return -1;
253         }
254
255         slave_add(internals, slave_eth_dev);
256
257         /* We need to store slaves reta_size to be able to synchronize RETA for all
258          * slave devices even if its sizes are different.
259          */
260         internals->slaves[internals->slave_count].reta_size = dev_info.reta_size;
261
262         if (internals->slave_count < 1) {
263                 /* if MAC is not user defined then use MAC of first slave add to
264                  * bonded device */
265                 if (!internals->user_defined_mac) {
266                         if (mac_address_set(bonded_eth_dev,
267                                             slave_eth_dev->data->mac_addrs)) {
268                                 RTE_BOND_LOG(ERR, "Failed to set MAC address");
269                                 return -1;
270                         }
271                 }
272
273                 /* Inherit eth dev link properties from first slave */
274                 link_properties_set(bonded_eth_dev,
275                                 &(slave_eth_dev->data->dev_link));
276
277                 /* Make primary slave */
278                 internals->primary_port = slave_port_id;
279                 internals->current_primary_port = slave_port_id;
280
281                 /* Inherit queues settings from first slave */
282                 internals->nb_rx_queues = slave_eth_dev->data->nb_rx_queues;
283                 internals->nb_tx_queues = slave_eth_dev->data->nb_tx_queues;
284
285                 internals->reta_size = dev_info.reta_size;
286
287                 /* Take the first dev's offload capabilities */
288                 internals->rx_offload_capa = dev_info.rx_offload_capa;
289                 internals->tx_offload_capa = dev_info.tx_offload_capa;
290                 internals->flow_type_rss_offloads = dev_info.flow_type_rss_offloads;
291
292                 /* Inherit first slave's max rx packet size */
293                 internals->candidate_max_rx_pktlen = dev_info.max_rx_pktlen;
294
295         } else {
296                 internals->rx_offload_capa &= dev_info.rx_offload_capa;
297                 internals->tx_offload_capa &= dev_info.tx_offload_capa;
298                 internals->flow_type_rss_offloads &= dev_info.flow_type_rss_offloads;
299
300                 if (link_properties_valid(bonded_eth_dev,
301                                 &slave_eth_dev->data->dev_link) != 0) {
302                         RTE_BOND_LOG(ERR, "Invalid link properties for slave %d"
303                                         " in bonding mode %d", slave_port_id,
304                                         internals->mode);
305                         return -1;
306                 }
307
308                 /* RETA size is GCD of all slaves RETA sizes, so, if all sizes will be
309                  * the power of 2, the lower one is GCD
310                  */
311                 if (internals->reta_size > dev_info.reta_size)
312                         internals->reta_size = dev_info.reta_size;
313
314                 if (!internals->max_rx_pktlen &&
315                     dev_info.max_rx_pktlen < internals->candidate_max_rx_pktlen)
316                         internals->candidate_max_rx_pktlen = dev_info.max_rx_pktlen;
317         }
318
319         bonded_eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf &=
320                         internals->flow_type_rss_offloads;
321
322         internals->slave_count++;
323
324         if (bonded_eth_dev->data->dev_started) {
325                 if (slave_configure(bonded_eth_dev, slave_eth_dev) != 0) {
326                         internals->slave_count--;
327                         RTE_BOND_LOG(ERR, "rte_bond_slaves_configure: port=%d",
328                                         slave_port_id);
329                         return -1;
330                 }
331         }
332
333         /* Add slave details to bonded device */
334         slave_eth_dev->data->dev_flags |= RTE_ETH_DEV_BONDED_SLAVE;
335
336         /* Update all slave devices MACs*/
337         mac_address_slaves_update(bonded_eth_dev);
338
339         /* Register link status change callback with bonded device pointer as
340          * argument*/
341         rte_eth_dev_callback_register(slave_port_id, RTE_ETH_EVENT_INTR_LSC,
342                         bond_ethdev_lsc_event_callback, &bonded_eth_dev->data->port_id);
343
344         /* If bonded device is started then we can add the slave to our active
345          * slave array */
346         if (bonded_eth_dev->data->dev_started) {
347                 rte_eth_link_get_nowait(slave_port_id, &link_props);
348
349                  if (link_props.link_status == ETH_LINK_UP) {
350                         if (internals->active_slave_count == 0 &&
351                             !internals->user_defined_primary_port)
352                                 bond_ethdev_primary_set(internals,
353                                                         slave_port_id);
354
355                         if (find_slave_by_id(internals->active_slaves,
356                                              internals->active_slave_count,
357                                              slave_port_id) == internals->active_slave_count)
358                                 activate_slave(bonded_eth_dev, slave_port_id);
359                 }
360         }
361
362         slave_vlan_filter_set(bonded_port_id, slave_port_id);
363
364         return 0;
365
366 }
367
368 int
369 rte_eth_bond_slave_add(uint16_t bonded_port_id, uint16_t slave_port_id)
370 {
371         struct rte_eth_dev *bonded_eth_dev;
372         struct bond_dev_private *internals;
373
374         int retval;
375
376         /* Verify that port id's are valid bonded and slave ports */
377         if (valid_bonded_port_id(bonded_port_id) != 0)
378                 return -1;
379
380         bonded_eth_dev = &rte_eth_devices[bonded_port_id];
381         internals = bonded_eth_dev->data->dev_private;
382
383         rte_spinlock_lock(&internals->lock);
384
385         retval = __eth_bond_slave_add_lock_free(bonded_port_id, slave_port_id);
386
387         rte_spinlock_unlock(&internals->lock);
388
389         return retval;
390 }
391
392 static int
393 __eth_bond_slave_remove_lock_free(uint16_t bonded_port_id,
394                                    uint16_t slave_port_id)
395 {
396         struct rte_eth_dev *bonded_eth_dev;
397         struct bond_dev_private *internals;
398         struct rte_eth_dev *slave_eth_dev;
399         int i, slave_idx;
400
401         bonded_eth_dev = &rte_eth_devices[bonded_port_id];
402         internals = bonded_eth_dev->data->dev_private;
403
404         if (valid_slave_port_id(slave_port_id, internals->mode) < 0)
405                 return -1;
406
407         /* first remove from active slave list */
408         slave_idx = find_slave_by_id(internals->active_slaves,
409                 internals->active_slave_count, slave_port_id);
410
411         if (slave_idx < internals->active_slave_count)
412                 deactivate_slave(bonded_eth_dev, slave_port_id);
413
414         slave_idx = -1;
415         /* now find in slave list */
416         for (i = 0; i < internals->slave_count; i++)
417                 if (internals->slaves[i].port_id == slave_port_id) {
418                         slave_idx = i;
419                         break;
420                 }
421
422         if (slave_idx < 0) {
423                 RTE_BOND_LOG(ERR, "Couldn't find slave in port list, slave count %d",
424                                 internals->slave_count);
425                 return -1;
426         }
427
428         /* Un-register link status change callback with bonded device pointer as
429          * argument*/
430         rte_eth_dev_callback_unregister(slave_port_id, RTE_ETH_EVENT_INTR_LSC,
431                         bond_ethdev_lsc_event_callback,
432                         &rte_eth_devices[bonded_port_id].data->port_id);
433
434         /* Restore original MAC address of slave device */
435         rte_eth_dev_default_mac_addr_set(slave_port_id,
436                         &(internals->slaves[slave_idx].persisted_mac_addr));
437
438         slave_eth_dev = &rte_eth_devices[slave_port_id];
439         slave_remove(internals, slave_eth_dev);
440         slave_eth_dev->data->dev_flags &= (~RTE_ETH_DEV_BONDED_SLAVE);
441
442         /*  first slave in the active list will be the primary by default,
443          *  otherwise use first device in list */
444         if (internals->current_primary_port == slave_port_id) {
445                 if (internals->active_slave_count > 0)
446                         internals->current_primary_port = internals->active_slaves[0];
447                 else if (internals->slave_count > 0)
448                         internals->current_primary_port = internals->slaves[0].port_id;
449                 else
450                         internals->primary_port = 0;
451         }
452
453         if (internals->active_slave_count < 1) {
454                 /* if no slaves are any longer attached to bonded device and MAC is not
455                  * user defined then clear MAC of bonded device as it will be reset
456                  * when a new slave is added */
457                 if (internals->slave_count < 1 && !internals->user_defined_mac)
458                         memset(rte_eth_devices[bonded_port_id].data->mac_addrs, 0,
459                                         sizeof(*(rte_eth_devices[bonded_port_id].data->mac_addrs)));
460         }
461         if (internals->slave_count == 0) {
462                 internals->rx_offload_capa = 0;
463                 internals->tx_offload_capa = 0;
464                 internals->flow_type_rss_offloads = ETH_RSS_PROTO_MASK;
465                 internals->reta_size = 0;
466                 internals->candidate_max_rx_pktlen = 0;
467                 internals->max_rx_pktlen = 0;
468         }
469         return 0;
470 }
471
472 int
473 rte_eth_bond_slave_remove(uint16_t bonded_port_id, uint16_t slave_port_id)
474 {
475         struct rte_eth_dev *bonded_eth_dev;
476         struct bond_dev_private *internals;
477         int retval;
478
479         if (valid_bonded_port_id(bonded_port_id) != 0)
480                 return -1;
481
482         bonded_eth_dev = &rte_eth_devices[bonded_port_id];
483         internals = bonded_eth_dev->data->dev_private;
484
485         rte_spinlock_lock(&internals->lock);
486
487         retval = __eth_bond_slave_remove_lock_free(bonded_port_id, slave_port_id);
488
489         rte_spinlock_unlock(&internals->lock);
490
491         return retval;
492 }
493
494 int
495 rte_eth_bond_mode_set(uint16_t bonded_port_id, uint8_t mode)
496 {
497         struct rte_eth_dev *bonded_eth_dev;
498
499         if (valid_bonded_port_id(bonded_port_id) != 0)
500                 return -1;
501
502         bonded_eth_dev = &rte_eth_devices[bonded_port_id];
503
504         if (check_for_master_bonded_ethdev(bonded_eth_dev) != 0 &&
505                         mode == BONDING_MODE_8023AD)
506                 return -1;
507
508         return bond_ethdev_mode_set(bonded_eth_dev, mode);
509 }
510
511 int
512 rte_eth_bond_mode_get(uint16_t bonded_port_id)
513 {
514         struct bond_dev_private *internals;
515
516         if (valid_bonded_port_id(bonded_port_id) != 0)
517                 return -1;
518
519         internals = rte_eth_devices[bonded_port_id].data->dev_private;
520
521         return internals->mode;
522 }
523
524 int
525 rte_eth_bond_primary_set(uint16_t bonded_port_id, uint16_t slave_port_id)
526 {
527         struct bond_dev_private *internals;
528
529         if (valid_bonded_port_id(bonded_port_id) != 0)
530                 return -1;
531
532         internals = rte_eth_devices[bonded_port_id].data->dev_private;
533
534         if (valid_slave_port_id(slave_port_id, internals->mode) != 0)
535                 return -1;
536
537         internals->user_defined_primary_port = 1;
538         internals->primary_port = slave_port_id;
539
540         bond_ethdev_primary_set(internals, slave_port_id);
541
542         return 0;
543 }
544
545 int
546 rte_eth_bond_primary_get(uint16_t bonded_port_id)
547 {
548         struct bond_dev_private *internals;
549
550         if (valid_bonded_port_id(bonded_port_id) != 0)
551                 return -1;
552
553         internals = rte_eth_devices[bonded_port_id].data->dev_private;
554
555         if (internals->slave_count < 1)
556                 return -1;
557
558         return internals->current_primary_port;
559 }
560
561 int
562 rte_eth_bond_slaves_get(uint16_t bonded_port_id, uint16_t slaves[],
563                         uint16_t len)
564 {
565         struct bond_dev_private *internals;
566         uint8_t i;
567
568         if (valid_bonded_port_id(bonded_port_id) != 0)
569                 return -1;
570
571         if (slaves == NULL)
572                 return -1;
573
574         internals = rte_eth_devices[bonded_port_id].data->dev_private;
575
576         if (internals->slave_count > len)
577                 return -1;
578
579         for (i = 0; i < internals->slave_count; i++)
580                 slaves[i] = internals->slaves[i].port_id;
581
582         return internals->slave_count;
583 }
584
585 int
586 rte_eth_bond_active_slaves_get(uint16_t bonded_port_id, uint16_t slaves[],
587                 uint16_t len)
588 {
589         struct bond_dev_private *internals;
590
591         if (valid_bonded_port_id(bonded_port_id) != 0)
592                 return -1;
593
594         if (slaves == NULL)
595                 return -1;
596
597         internals = rte_eth_devices[bonded_port_id].data->dev_private;
598
599         if (internals->active_slave_count > len)
600                 return -1;
601
602         memcpy(slaves, internals->active_slaves,
603         internals->active_slave_count * sizeof(internals->active_slaves[0]));
604
605         return internals->active_slave_count;
606 }
607
608 int
609 rte_eth_bond_mac_address_set(uint16_t bonded_port_id,
610                 struct ether_addr *mac_addr)
611 {
612         struct rte_eth_dev *bonded_eth_dev;
613         struct bond_dev_private *internals;
614
615         if (valid_bonded_port_id(bonded_port_id) != 0)
616                 return -1;
617
618         bonded_eth_dev = &rte_eth_devices[bonded_port_id];
619         internals = bonded_eth_dev->data->dev_private;
620
621         /* Set MAC Address of Bonded Device */
622         if (mac_address_set(bonded_eth_dev, mac_addr))
623                 return -1;
624
625         internals->user_defined_mac = 1;
626
627         /* Update all slave devices MACs*/
628         if (internals->slave_count > 0)
629                 return mac_address_slaves_update(bonded_eth_dev);
630
631         return 0;
632 }
633
634 int
635 rte_eth_bond_mac_address_reset(uint16_t bonded_port_id)
636 {
637         struct rte_eth_dev *bonded_eth_dev;
638         struct bond_dev_private *internals;
639
640         if (valid_bonded_port_id(bonded_port_id) != 0)
641                 return -1;
642
643         bonded_eth_dev = &rte_eth_devices[bonded_port_id];
644         internals = bonded_eth_dev->data->dev_private;
645
646         internals->user_defined_mac = 0;
647
648         if (internals->slave_count > 0) {
649                 /* Set MAC Address of Bonded Device */
650                 if (mac_address_set(bonded_eth_dev,
651                                 &internals->slaves[internals->primary_port].persisted_mac_addr)
652                                 != 0) {
653                         RTE_BOND_LOG(ERR, "Failed to set MAC address on bonded device");
654                         return -1;
655                 }
656                 /* Update all slave devices MAC addresses */
657                 return mac_address_slaves_update(bonded_eth_dev);
658         }
659         /* No need to update anything as no slaves present */
660         return 0;
661 }
662
663 int
664 rte_eth_bond_xmit_policy_set(uint16_t bonded_port_id, uint8_t policy)
665 {
666         struct bond_dev_private *internals;
667
668         if (valid_bonded_port_id(bonded_port_id) != 0)
669                 return -1;
670
671         internals = rte_eth_devices[bonded_port_id].data->dev_private;
672
673         switch (policy) {
674         case BALANCE_XMIT_POLICY_LAYER2:
675                 internals->balance_xmit_policy = policy;
676                 internals->burst_xmit_hash = burst_xmit_l2_hash;
677                 break;
678         case BALANCE_XMIT_POLICY_LAYER23:
679                 internals->balance_xmit_policy = policy;
680                 internals->burst_xmit_hash = burst_xmit_l23_hash;
681                 break;
682         case BALANCE_XMIT_POLICY_LAYER34:
683                 internals->balance_xmit_policy = policy;
684                 internals->burst_xmit_hash = burst_xmit_l34_hash;
685                 break;
686
687         default:
688                 return -1;
689         }
690         return 0;
691 }
692
693 int
694 rte_eth_bond_xmit_policy_get(uint16_t bonded_port_id)
695 {
696         struct bond_dev_private *internals;
697
698         if (valid_bonded_port_id(bonded_port_id) != 0)
699                 return -1;
700
701         internals = rte_eth_devices[bonded_port_id].data->dev_private;
702
703         return internals->balance_xmit_policy;
704 }
705
706 int
707 rte_eth_bond_link_monitoring_set(uint16_t bonded_port_id, uint32_t internal_ms)
708 {
709         struct bond_dev_private *internals;
710
711         if (valid_bonded_port_id(bonded_port_id) != 0)
712                 return -1;
713
714         internals = rte_eth_devices[bonded_port_id].data->dev_private;
715         internals->link_status_polling_interval_ms = internal_ms;
716
717         return 0;
718 }
719
720 int
721 rte_eth_bond_link_monitoring_get(uint16_t bonded_port_id)
722 {
723         struct bond_dev_private *internals;
724
725         if (valid_bonded_port_id(bonded_port_id) != 0)
726                 return -1;
727
728         internals = rte_eth_devices[bonded_port_id].data->dev_private;
729
730         return internals->link_status_polling_interval_ms;
731 }
732
733 int
734 rte_eth_bond_link_down_prop_delay_set(uint16_t bonded_port_id,
735                                        uint32_t delay_ms)
736
737 {
738         struct bond_dev_private *internals;
739
740         if (valid_bonded_port_id(bonded_port_id) != 0)
741                 return -1;
742
743         internals = rte_eth_devices[bonded_port_id].data->dev_private;
744         internals->link_down_delay_ms = delay_ms;
745
746         return 0;
747 }
748
749 int
750 rte_eth_bond_link_down_prop_delay_get(uint16_t bonded_port_id)
751 {
752         struct bond_dev_private *internals;
753
754         if (valid_bonded_port_id(bonded_port_id) != 0)
755                 return -1;
756
757         internals = rte_eth_devices[bonded_port_id].data->dev_private;
758
759         return internals->link_down_delay_ms;
760 }
761
762 int
763 rte_eth_bond_link_up_prop_delay_set(uint16_t bonded_port_id, uint32_t delay_ms)
764
765 {
766         struct bond_dev_private *internals;
767
768         if (valid_bonded_port_id(bonded_port_id) != 0)
769                 return -1;
770
771         internals = rte_eth_devices[bonded_port_id].data->dev_private;
772         internals->link_up_delay_ms = delay_ms;
773
774         return 0;
775 }
776
777 int
778 rte_eth_bond_link_up_prop_delay_get(uint16_t bonded_port_id)
779 {
780         struct bond_dev_private *internals;
781
782         if (valid_bonded_port_id(bonded_port_id) != 0)
783                 return -1;
784
785         internals = rte_eth_devices[bonded_port_id].data->dev_private;
786
787         return internals->link_up_delay_ms;
788 }