c8fb42c4648954310c909555054401c7c052adcf
[dpdk.git] / lib / librte_pmd_bond / rte_eth_bond_api.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
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
16  *       distribution.
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.
20  *
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.
32  */
33
34 #include <string.h>
35
36 #include <rte_mbuf.h>
37 #include <rte_malloc.h>
38 #include <rte_ethdev.h>
39 #include <rte_tcp.h>
40
41 #include "rte_eth_bond.h"
42 #include "rte_eth_bond_private.h"
43 #include "rte_eth_bond_8023ad_private.h"
44
45 #define DEFAULT_POLLING_INTERVAL_10_MS (10)
46
47 int
48 valid_bonded_ethdev(struct rte_eth_dev *eth_dev)
49 {
50         size_t len;
51
52         /* Check valid pointer */
53         if (eth_dev->driver->pci_drv.name == NULL || driver_name == NULL)
54                 return -1;
55
56         /* Check string lengths are equal */
57         len = strlen(driver_name);
58         if (strlen(eth_dev->driver->pci_drv.name) != len)
59                 return -1;
60
61         /* Compare strings */
62         return strncmp(eth_dev->driver->pci_drv.name, driver_name, len);
63 }
64
65 int
66 valid_port_id(uint8_t port_id)
67 {
68         /* Verify that port id is valid */
69         int ethdev_count = rte_eth_dev_count();
70         if (port_id >= ethdev_count) {
71                 RTE_BOND_LOG(ERR, "Port Id %d is greater than rte_eth_dev_count %d",
72                                 port_id, ethdev_count);
73                 return -1;
74         }
75
76         return 0;
77 }
78
79 int
80 valid_bonded_port_id(uint8_t port_id)
81 {
82         /* Verify that port id's are valid */
83         if (valid_port_id(port_id))
84                 return -1;
85
86         /* Verify that bonded_port_id refers to a bonded port */
87         if (valid_bonded_ethdev(&rte_eth_devices[port_id])) {
88                 RTE_BOND_LOG(ERR, "Specified port Id %d is not a bonded eth_dev device",
89                                 port_id);
90                 return -1;
91         }
92
93         return 0;
94 }
95
96 int
97 valid_slave_port_id(uint8_t port_id)
98 {
99         /* Verify that port id's are valid */
100         if (valid_port_id(port_id))
101                 return -1;
102
103         /* Verify that port_id refers to a non bonded port */
104         if (!valid_bonded_ethdev(&rte_eth_devices[port_id]))
105                 return -1;
106
107         return 0;
108 }
109
110 void
111 activate_slave(struct rte_eth_dev *eth_dev, uint8_t port_id)
112 {
113         struct bond_dev_private *internals = eth_dev->data->dev_private;
114
115         if (internals->mode == BONDING_MODE_8023AD)
116                 bond_mode_8023ad_activate_slave(eth_dev, port_id);
117
118         internals->active_slaves[internals->active_slave_count] = port_id;
119         internals->active_slave_count++;
120 }
121
122 void
123 deactivate_slave(struct rte_eth_dev *eth_dev, uint8_t port_id)
124 {
125         uint8_t slave_pos;
126         struct bond_dev_private *internals = eth_dev->data->dev_private;
127         uint8_t active_count = internals->active_slave_count;
128
129         if (internals->mode == BONDING_MODE_8023AD) {
130                 bond_mode_8023ad_stop(eth_dev);
131                 bond_mode_8023ad_deactivate_slave(eth_dev, port_id);
132         }
133
134         slave_pos = find_slave_by_id(internals->active_slaves, active_count,
135                         port_id);
136
137         /* If slave was not at the end of the list
138          * shift active slaves up active array list */
139         if (slave_pos < active_count) {
140                 active_count--;
141                 memmove(internals->active_slaves + slave_pos,
142                                 internals->active_slaves + slave_pos + 1,
143                                 (active_count - slave_pos) *
144                                         sizeof(internals->active_slaves[0]));
145         }
146
147         internals->active_slave_count = active_count;
148
149         if (eth_dev->data->dev_started && internals->mode == BONDING_MODE_8023AD)
150                 bond_mode_8023ad_start(eth_dev);
151 }
152
153 uint8_t
154 number_of_sockets(void)
155 {
156         int sockets = 0;
157         int i;
158         const struct rte_memseg *ms = rte_eal_get_physmem_layout();
159
160         for (i = 0; ((i < RTE_MAX_MEMSEG) && (ms[i].addr != NULL)); i++) {
161                 if (sockets < ms[i].socket_id)
162                         sockets = ms[i].socket_id;
163         }
164
165         /* Number of sockets = maximum socket_id + 1 */
166         return ++sockets;
167 }
168
169 const char *driver_name = "Link Bonding PMD";
170
171 int
172 rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id)
173 {
174         struct rte_pci_device *pci_dev = NULL;
175         struct bond_dev_private *internals = NULL;
176         struct rte_eth_dev *eth_dev = NULL;
177         struct eth_driver *eth_drv = NULL;
178         struct rte_pci_driver *pci_drv = NULL;
179         struct rte_pci_id *pci_id_table = NULL;
180         /* now do all data allocation - for eth_dev structure, dummy pci driver
181          * and internal (private) data
182          */
183
184         if (name == NULL) {
185                 RTE_BOND_LOG(ERR, "Invalid name specified");
186                 goto err;
187         }
188
189         if (socket_id >= number_of_sockets()) {
190                 RTE_BOND_LOG(ERR,
191                                 "Invalid socket id specified to create bonded device on.");
192                 goto err;
193         }
194
195         pci_dev = rte_zmalloc_socket(name, sizeof(*pci_dev), 0, socket_id);
196         if (pci_dev == NULL) {
197                 RTE_BOND_LOG(ERR, "Unable to malloc pci dev on socket");
198                 goto err;
199         }
200
201         eth_drv = rte_zmalloc_socket(name, sizeof(*eth_drv), 0, socket_id);
202         if (eth_drv == NULL) {
203                 RTE_BOND_LOG(ERR, "Unable to malloc eth_drv on socket");
204                 goto err;
205         }
206
207         pci_drv = rte_zmalloc_socket(name, sizeof(*pci_drv), 0, socket_id);
208         if (pci_drv == NULL) {
209                 RTE_BOND_LOG(ERR, "Unable to malloc pci_drv on socket");
210                 goto err;
211         }
212         pci_id_table = rte_zmalloc_socket(name, sizeof(*pci_id_table), 0, socket_id);
213         if (pci_drv == NULL) {
214                 RTE_BOND_LOG(ERR, "Unable to malloc pci_id_table on socket");
215                 goto err;
216         }
217
218         pci_drv->id_table = pci_id_table;
219
220         pci_drv->id_table->device_id = PCI_ANY_ID;
221         pci_drv->id_table->subsystem_device_id = PCI_ANY_ID;
222         pci_drv->id_table->vendor_id = PCI_ANY_ID;
223         pci_drv->id_table->subsystem_vendor_id = PCI_ANY_ID;
224
225         pci_drv->drv_flags = RTE_PCI_DRV_INTR_LSC;
226
227         internals = rte_zmalloc_socket(name, sizeof(*internals), 0, socket_id);
228         if (internals == NULL) {
229                 RTE_BOND_LOG(ERR, "Unable to malloc internals on socket");
230                 goto err;
231         }
232
233         /* reserve an ethdev entry */
234         eth_dev = rte_eth_dev_allocate(name);
235         if (eth_dev == NULL) {
236                 RTE_BOND_LOG(ERR, "Unable to allocate rte_eth_dev");
237                 goto err;
238         }
239
240         pci_dev->numa_node = socket_id;
241         pci_drv->name = driver_name;
242
243         eth_drv->pci_drv = (struct rte_pci_driver)(*pci_drv);
244         eth_dev->driver = eth_drv;
245
246         eth_dev->data->dev_private = internals;
247         eth_dev->data->nb_rx_queues = (uint16_t)1;
248         eth_dev->data->nb_tx_queues = (uint16_t)1;
249
250         TAILQ_INIT(&(eth_dev->callbacks));
251
252         eth_dev->data->dev_link.link_status = 0;
253
254         eth_dev->data->mac_addrs = rte_zmalloc_socket(name, ETHER_ADDR_LEN, 0,
255                         socket_id);
256
257         eth_dev->data->dev_started = 0;
258         eth_dev->data->promiscuous = 0;
259         eth_dev->data->scattered_rx = 0;
260         eth_dev->data->all_multicast = 0;
261
262         eth_dev->dev_ops = &default_dev_ops;
263         eth_dev->pci_dev = pci_dev;
264
265         rte_spinlock_init(&internals->lock);
266
267         internals->port_id = eth_dev->data->port_id;
268         internals->mode = BONDING_MODE_INVALID;
269         internals->current_primary_port = 0;
270         internals->balance_xmit_policy = BALANCE_XMIT_POLICY_LAYER2;
271         internals->user_defined_mac = 0;
272         internals->link_props_set = 0;
273
274         internals->link_status_polling_enabled = 0;
275
276         internals->link_status_polling_interval_ms = DEFAULT_POLLING_INTERVAL_10_MS;
277         internals->link_down_delay_ms = 0;
278         internals->link_up_delay_ms = 0;
279
280         internals->slave_count = 0;
281         internals->active_slave_count = 0;
282
283         memset(internals->active_slaves, 0, sizeof(internals->active_slaves));
284         memset(internals->slaves, 0, sizeof(internals->slaves));
285
286         /* Set mode 4 default configuration */
287         bond_mode_8023ad_setup(eth_dev, NULL);
288         if (bond_ethdev_mode_set(eth_dev, mode)) {
289                 RTE_BOND_LOG(ERR, "Failed to set bonded device %d mode too %d",
290                                  eth_dev->data->port_id, mode);
291                 goto err;
292         }
293
294         return eth_dev->data->port_id;
295
296 err:
297         if (pci_dev)
298                 rte_free(pci_dev);
299         if (pci_drv)
300                 rte_free(pci_drv);
301         if (pci_id_table)
302                 rte_free(pci_id_table);
303         if (eth_drv)
304                 rte_free(eth_drv);
305         if (internals)
306                 rte_free(internals);
307         return -1;
308 }
309
310 static int
311 __eth_bond_slave_add_lock_free(uint8_t bonded_port_id, uint8_t slave_port_id)
312 {
313         struct rte_eth_dev *bonded_eth_dev, *slave_eth_dev;
314         struct bond_dev_private *internals;
315         struct bond_dev_private *temp_internals;
316         struct rte_eth_link link_props;
317
318         int i, j;
319
320         if (valid_slave_port_id(slave_port_id) != 0)
321                 return -1;
322
323         bonded_eth_dev = &rte_eth_devices[bonded_port_id];
324         internals = bonded_eth_dev->data->dev_private;
325
326         /* Verify that new slave device is not already a slave of another
327          * bonded device */
328         for (i = rte_eth_dev_count()-1; i >= 0; i--) {
329                 if (valid_bonded_ethdev(&rte_eth_devices[i]) == 0) {
330                         temp_internals = rte_eth_devices[i].data->dev_private;
331
332                         for (j = 0; j < temp_internals->slave_count; j++) {
333                                 /* Device already a slave of a bonded device */
334                                 if (temp_internals->slaves[j].port_id == slave_port_id) {
335                                         RTE_BOND_LOG(ERR, "Slave port %d is already a slave",
336                                                         slave_port_id);
337                                         return -1;
338                                 }
339                         }
340                 }
341         }
342
343         slave_eth_dev = &rte_eth_devices[slave_port_id];
344
345         /* Add slave details to bonded device */
346         slave_add(internals, slave_eth_dev);
347
348         if (internals->slave_count < 1) {
349                 /* if MAC is not user defined then use MAC of first slave add to
350                  * bonded device */
351                 if (!internals->user_defined_mac)
352                         mac_address_set(bonded_eth_dev, slave_eth_dev->data->mac_addrs);
353
354                 /* Inherit eth dev link properties from first slave */
355                 link_properties_set(bonded_eth_dev,
356                                 &(slave_eth_dev->data->dev_link));
357
358                 /* Make primary slave */
359                 internals->primary_port = slave_port_id;
360         } else {
361                 /* Check slave link properties are supported if props are set,
362                  * all slaves must be the same */
363                 if (internals->link_props_set) {
364                         if (link_properties_valid(&(bonded_eth_dev->data->dev_link),
365                                                                           &(slave_eth_dev->data->dev_link))) {
366                                 RTE_BOND_LOG(ERR,
367                                                 "Slave port %d link speed/duplex not supported",
368                                                 slave_port_id);
369                                 return -1;
370                         }
371                 } else {
372                         link_properties_set(bonded_eth_dev,
373                                         &(slave_eth_dev->data->dev_link));
374                 }
375         }
376
377         internals->slave_count++;
378
379         /* Update all slave devices MACs*/
380         mac_address_slaves_update(bonded_eth_dev);
381
382         if (bonded_eth_dev->data->dev_started) {
383                 if (slave_configure(bonded_eth_dev, slave_eth_dev) != 0) {
384                         RTE_BOND_LOG(ERR, "rte_bond_slaves_configure: port=%d",
385                                         slave_port_id);
386                         return -1;
387                 }
388         }
389
390         /* Register link status change callback with bonded device pointer as
391          * argument*/
392         rte_eth_dev_callback_register(slave_port_id, RTE_ETH_EVENT_INTR_LSC,
393                         bond_ethdev_lsc_event_callback, &bonded_eth_dev->data->port_id);
394
395         /* If bonded device is started then we can add the slave to our active
396          * slave array */
397         if (bonded_eth_dev->data->dev_started) {
398                 rte_eth_link_get_nowait(slave_port_id, &link_props);
399
400                  if (link_props.link_status == 1)
401                         activate_slave(bonded_eth_dev, slave_port_id);
402         }
403         return 0;
404
405 }
406
407 int
408 rte_eth_bond_slave_add(uint8_t bonded_port_id, uint8_t slave_port_id)
409 {
410         struct rte_eth_dev *bonded_eth_dev;
411         struct bond_dev_private *internals;
412
413         int retval;
414
415         /* Verify that port id's are valid bonded and slave ports */
416         if (valid_bonded_port_id(bonded_port_id) != 0)
417                 return -1;
418
419         bonded_eth_dev = &rte_eth_devices[bonded_port_id];
420         internals = bonded_eth_dev->data->dev_private;
421
422         rte_spinlock_lock(&internals->lock);
423
424         retval = __eth_bond_slave_add_lock_free(bonded_port_id, slave_port_id);
425
426         rte_spinlock_unlock(&internals->lock);
427
428         return retval;
429 }
430
431 static int
432 __eth_bond_slave_remove_lock_free(uint8_t bonded_port_id, uint8_t slave_port_id)
433 {
434         struct rte_eth_dev *bonded_eth_dev;
435         struct bond_dev_private *internals;
436
437         int i, slave_idx;
438
439         if (valid_slave_port_id(slave_port_id) != 0)
440                 return -1;
441
442         bonded_eth_dev = &rte_eth_devices[bonded_port_id];
443         internals = bonded_eth_dev->data->dev_private;
444
445         /* first remove from active slave list */
446         slave_idx = find_slave_by_id(internals->active_slaves,
447                 internals->active_slave_count, slave_port_id);
448
449         if (slave_idx < internals->active_slave_count)
450                 deactivate_slave(bonded_eth_dev, slave_port_id);
451
452         slave_idx = -1;
453         /* now find in slave list */
454         for (i = 0; i < internals->slave_count; i++)
455                 if (internals->slaves[i].port_id == slave_port_id) {
456                         slave_idx = i;
457                         break;
458                 }
459
460         if (slave_idx < 0) {
461                 RTE_BOND_LOG(ERR, "Couldn't find slave in port list, slave count %d",
462                                 internals->slave_count);
463                 return -1;
464         }
465
466         /* Un-register link status change callback with bonded device pointer as
467          * argument*/
468         rte_eth_dev_callback_unregister(slave_port_id, RTE_ETH_EVENT_INTR_LSC,
469                         bond_ethdev_lsc_event_callback,
470                         &rte_eth_devices[bonded_port_id].data->port_id);
471
472         /* Restore original MAC address of slave device */
473         mac_address_set(&rte_eth_devices[slave_port_id],
474                         &(internals->slaves[slave_idx].persisted_mac_addr));
475
476         slave_remove(internals, &rte_eth_devices[slave_port_id]);
477
478         /*  first slave in the active list will be the primary by default,
479          *  otherwise use first device in list */
480         if (internals->current_primary_port == slave_port_id) {
481                 if (internals->active_slave_count > 0)
482                         internals->current_primary_port = internals->active_slaves[0];
483                 else if (internals->slave_count > 0)
484                         internals->current_primary_port = internals->slaves[0].port_id;
485                 else
486                         internals->primary_port = 0;
487         }
488
489         if (internals->active_slave_count < 1) {
490                 /* reset device link properties as no slaves are active */
491                 link_properties_reset(&rte_eth_devices[bonded_port_id]);
492
493                 /* if no slaves are any longer attached to bonded device and MAC is not
494                  * user defined then clear MAC of bonded device as it will be reset
495                  * when a new slave is added */
496                 if (internals->slave_count < 1 && !internals->user_defined_mac)
497                         memset(rte_eth_devices[bonded_port_id].data->mac_addrs, 0,
498                                         sizeof(*(rte_eth_devices[bonded_port_id].data->mac_addrs)));
499         }
500
501         return 0;
502 }
503
504 int
505 rte_eth_bond_slave_remove(uint8_t bonded_port_id, uint8_t slave_port_id)
506 {
507         struct rte_eth_dev *bonded_eth_dev;
508         struct bond_dev_private *internals;
509         int retval;
510
511         if (valid_bonded_port_id(bonded_port_id) != 0)
512                 return -1;
513
514         bonded_eth_dev = &rte_eth_devices[bonded_port_id];
515         internals = bonded_eth_dev->data->dev_private;
516
517         rte_spinlock_lock(&internals->lock);
518
519         retval = __eth_bond_slave_remove_lock_free(bonded_port_id, slave_port_id);
520
521         rte_spinlock_unlock(&internals->lock);
522
523         return retval;
524 }
525
526 int
527 rte_eth_bond_mode_set(uint8_t bonded_port_id, uint8_t mode)
528 {
529         if (valid_bonded_port_id(bonded_port_id) != 0)
530                 return -1;
531
532         return bond_ethdev_mode_set(&rte_eth_devices[bonded_port_id], mode);
533 }
534
535 int
536 rte_eth_bond_mode_get(uint8_t bonded_port_id)
537 {
538         struct bond_dev_private *internals;
539
540         if (valid_bonded_port_id(bonded_port_id) != 0)
541                 return -1;
542
543         internals = rte_eth_devices[bonded_port_id].data->dev_private;
544
545         return internals->mode;
546 }
547
548 int
549 rte_eth_bond_primary_set(uint8_t bonded_port_id, uint8_t slave_port_id)
550 {
551         struct bond_dev_private *internals;
552
553         if (valid_bonded_port_id(bonded_port_id) != 0)
554                 return -1;
555
556         if (valid_slave_port_id(slave_port_id) != 0)
557                 return -1;
558
559         internals =  rte_eth_devices[bonded_port_id].data->dev_private;
560
561         internals->user_defined_primary_port = 1;
562         internals->primary_port = slave_port_id;
563
564         bond_ethdev_primary_set(internals, slave_port_id);
565
566         return 0;
567 }
568
569 int
570 rte_eth_bond_primary_get(uint8_t bonded_port_id)
571 {
572         struct bond_dev_private *internals;
573
574         if (valid_bonded_port_id(bonded_port_id) != 0)
575                 return -1;
576
577         internals = rte_eth_devices[bonded_port_id].data->dev_private;
578
579         if (internals->slave_count < 1)
580                 return -1;
581
582         return internals->current_primary_port;
583 }
584
585 int
586 rte_eth_bond_slaves_get(uint8_t bonded_port_id, uint8_t slaves[], uint8_t len)
587 {
588         struct bond_dev_private *internals;
589         uint8_t i;
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->slave_count > len)
600                 return -1;
601
602         for (i = 0; i < internals->slave_count; i++)
603                 slaves[i] = internals->slaves[i].port_id;
604
605         return internals->slave_count;
606 }
607
608 int
609 rte_eth_bond_active_slaves_get(uint8_t bonded_port_id, uint8_t slaves[],
610                 uint8_t len)
611 {
612         struct bond_dev_private *internals;
613
614         if (valid_bonded_port_id(bonded_port_id) != 0)
615                 return -1;
616
617         if (slaves == NULL)
618                 return -1;
619
620         internals = rte_eth_devices[bonded_port_id].data->dev_private;
621
622         if (internals->active_slave_count > len)
623                 return -1;
624
625         memcpy(slaves, internals->active_slaves, internals->active_slave_count);
626
627         return internals->active_slave_count;
628 }
629
630 int
631 rte_eth_bond_mac_address_set(uint8_t bonded_port_id,
632                 struct ether_addr *mac_addr)
633 {
634         struct rte_eth_dev *bonded_eth_dev;
635         struct bond_dev_private *internals;
636
637         if (valid_bonded_port_id(bonded_port_id) != 0)
638                 return -1;
639
640         bonded_eth_dev = &rte_eth_devices[bonded_port_id];
641         internals = bonded_eth_dev->data->dev_private;
642
643         /* Set MAC Address of Bonded Device */
644         if (mac_address_set(bonded_eth_dev, mac_addr))
645                 return -1;
646
647         internals->user_defined_mac = 1;
648
649         /* Update all slave devices MACs*/
650         if (internals->slave_count > 0)
651                 return mac_address_slaves_update(bonded_eth_dev);
652
653         return 0;
654 }
655
656 int
657 rte_eth_bond_mac_address_reset(uint8_t bonded_port_id)
658 {
659         struct rte_eth_dev *bonded_eth_dev;
660         struct bond_dev_private *internals;
661
662         if (valid_bonded_port_id(bonded_port_id) != 0)
663                 return -1;
664
665         bonded_eth_dev = &rte_eth_devices[bonded_port_id];
666         internals = bonded_eth_dev->data->dev_private;
667
668         internals->user_defined_mac = 0;
669
670         if (internals->slave_count > 0) {
671                 /* Set MAC Address of Bonded Device */
672                 if (mac_address_set(bonded_eth_dev,
673                                 &internals->slaves[internals->primary_port].persisted_mac_addr)
674                                 != 0) {
675                         RTE_BOND_LOG(ERR, "Failed to set MAC address on bonded device");
676                         return -1;
677                 }
678                 /* Update all slave devices MAC addresses */
679                 return mac_address_slaves_update(bonded_eth_dev);
680         }
681         /* No need to update anything as no slaves present */
682         return 0;
683 }
684
685 int
686 rte_eth_bond_xmit_policy_set(uint8_t bonded_port_id, uint8_t policy)
687 {
688         struct bond_dev_private *internals;
689
690         if (valid_bonded_port_id(bonded_port_id) != 0)
691                 return -1;
692
693         internals = rte_eth_devices[bonded_port_id].data->dev_private;
694
695         switch (policy) {
696         case BALANCE_XMIT_POLICY_LAYER2:
697         case BALANCE_XMIT_POLICY_LAYER23:
698         case BALANCE_XMIT_POLICY_LAYER34:
699                 internals->balance_xmit_policy = policy;
700                 break;
701
702         default:
703                 return -1;
704         }
705         return 0;
706 }
707
708 int
709 rte_eth_bond_xmit_policy_get(uint8_t bonded_port_id)
710 {
711         struct bond_dev_private *internals;
712
713         if (valid_bonded_port_id(bonded_port_id) != 0)
714                 return -1;
715
716         internals = rte_eth_devices[bonded_port_id].data->dev_private;
717
718         return internals->balance_xmit_policy;
719 }
720
721 int
722 rte_eth_bond_link_monitoring_set(uint8_t bonded_port_id, uint32_t internal_ms)
723 {
724         struct bond_dev_private *internals;
725
726         if (valid_bonded_port_id(bonded_port_id) != 0)
727                 return -1;
728
729         internals = rte_eth_devices[bonded_port_id].data->dev_private;
730         internals->link_status_polling_interval_ms = internal_ms;
731
732         return 0;
733 }
734
735 int
736 rte_eth_bond_link_monitoring_get(uint8_t bonded_port_id)
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
745         return internals->link_status_polling_interval_ms;
746 }
747
748 int
749 rte_eth_bond_link_down_prop_delay_set(uint8_t bonded_port_id, uint32_t delay_ms)
750
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         internals->link_down_delay_ms = delay_ms;
759
760         return 0;
761 }
762
763 int
764 rte_eth_bond_link_down_prop_delay_get(uint8_t bonded_port_id)
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
773         return internals->link_down_delay_ms;
774 }
775
776 int
777 rte_eth_bond_link_up_prop_delay_set(uint8_t bonded_port_id, uint32_t delay_ms)
778
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         internals->link_up_delay_ms = delay_ms;
787
788         return 0;
789 }
790
791 int
792 rte_eth_bond_link_up_prop_delay_get(uint8_t bonded_port_id)
793 {
794         struct bond_dev_private *internals;
795
796         if (valid_bonded_port_id(bonded_port_id) != 0)
797                 return -1;
798
799         internals = rte_eth_devices[bonded_port_id].data->dev_private;
800
801         return internals->link_up_delay_ms;
802 }