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