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