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