Fix compilation issue with older gcc
[samplevnf.git] / common / VIL / l2l3_stack / bond.c
1 /*
2 // Copyright (c) 2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #include <interface.h>
18 #include "tsx.h"
19 extern interface_main_t ifm;
20 extern uint8_t ifm_debug;
21 extern int USE_RTM_LOCKS;
22 extern rte_rwlock_t rwlock;
23
24 int ifm_bond_port_create(const char *name, int mode, port_config_t * portconf)
25 {
26         int port_id;
27         l2_phy_interface_t *bond_port;
28         if (ifm_debug && IFM_DEBUG_CONFIG)
29                 RTE_LOG(INFO, IFM, "%s: i/p name %p, mode %d\n\r", __FUNCTION__,
30                         name, mode);
31         if (name == NULL) {
32                 RTE_LOG(ERR, IFM, "%s: Param name cannot be NULL\n\r",
33                         __FUNCTION__);
34                 return IFM_FAILURE;
35         }
36         if (mode < 0 || mode > 6) {
37                 RTE_LOG(ERR, IFM, "%s: Param mode should be withing 0 to 6\n\r",
38                         __FUNCTION__);
39                 return IFM_FAILURE;
40         }
41         if (portconf == NULL) {
42                 RTE_LOG(ERR, IFM, "%s: Param portconf cannot be NULL\n\r",
43                         __FUNCTION__);
44                 return IFM_FAILURE;
45         }
46         bond_port = ifm_get_port_by_name(name);
47         if (bond_port == NULL) {
48                 if (ifm_debug && IFM_DEBUG_CONFIG)
49                         RTE_LOG(INFO, IFM, "Call ifm_port_setup %s\n\r", name);
50                 port_id = rte_eth_bond_create(name, mode, 0);
51                 if (port_id < 0) {
52                         RTE_LOG(ERR, IFM,
53                                 "%s: Failed to create bond port %s with mode %u\n\r",
54                                 __FUNCTION__, name, mode);
55                         return IFM_FAILURE;
56                 }
57                 RTE_LOG(INFO, IFM,
58                         "%s: Created bond port %s(%u) on socket %u with "
59                         "mode %u.\n\r", __FUNCTION__, name, port_id,
60                         rte_eth_dev_socket_id(port_id), mode);
61
62                 bond_port = (l2_phy_interface_t *) rte_zmalloc(NULL,
63                                                                                  sizeof
64                                                                                  (l2_phy_interface_t),
65                                                                                  RTE_CACHE_LINE_SIZE);
66                 bond_port->pmdid = port_id;
67                 strncpy(bond_port->ifname, name, IFM_IFNAME_LEN);
68                 memcpy(&bond_port->port_config, portconf,
69                                          sizeof(port_config_t));
70                 bond_port->flags |= IFM_MASTER;
71                 struct bond_port *bond_info;
72                 bond_info = (struct bond_port *)rte_zmalloc(NULL,
73                                                                         sizeof(struct
74                                                                          bond_port),
75                                                                         RTE_CACHE_LINE_SIZE);
76                 bond_info->socket_id = rte_eth_dev_socket_id(port_id);
77                 bond_info->mode = mode;
78                 bond_info->bond_portid = port_id;
79                 bond_port->bond_config = bond_info;
80                 if (mode == IFM_BONDING_MODE_8023AD)
81                         bond_port->tx_buf_len =
82                                         (2 * RTE_ETH_TX_BUFFER_SIZE(IFM_BURST_SIZE)) *
83                                         RTE_MAX_ETHPORTS;
84                 //ifm_add_port_to_port_list(bond_port);
85                 ifm.port_list[port_id] = bond_port;
86                 if (ifm_debug && IFM_DEBUG_CONFIG)
87                         RTE_LOG(INFO, IFM,
88                                 "%s: Added bond port %s(%u) to port list\n\r",
89                                 __FUNCTION__, name, port_id);
90         } else {
91                 RTE_LOG(INFO, IFM, "%s: Port %s already exists in the"
92                         " port list\n\r", __FUNCTION__, name);
93                 if (ifm_debug & IFM_DEBUG_LOCKS)
94                         RTE_LOG(INFO, IFM, "%s: Acquiring lock @ %d\n\r",
95                                 __FUNCTION__, __LINE__);
96                 if (USE_RTM_LOCKS)
97                         rtm_lock();
98                 else
99                         rte_rwlock_write_lock(&rwlock);
100
101                 if (!(bond_port->flags & IFM_MASTER)) {
102                         RTE_LOG(ERR, IFM, "%s: Previously port %s was not "
103                                 "configured as Bond port\n\r", __FUNCTION__,
104                                 name);
105                         if (ifm_debug & IFM_DEBUG_LOCKS)
106                                 RTE_LOG(INFO, IFM,
107                                         "%s: Releasing lock @ %d\n\r",
108                                         __FUNCTION__, __LINE__);
109                         if (USE_RTM_LOCKS)
110                                 rtm_unlock();
111                         else
112                                 rte_rwlock_write_unlock(&rwlock);
113                         return IFM_FAILURE;
114                 }
115                 if (bond_port->bond_config->mode != mode) {
116                         if (rte_eth_bond_mode_set(bond_port->pmdid, mode) < 0) {
117                                 RTE_LOG(ERR, IFM, "%s: rte_eth_bond_mode_set "
118                                         "failed\n\r", __FUNCTION__);
119                                 if (ifm_debug & IFM_DEBUG_LOCKS)
120                                         RTE_LOG(INFO, IFM,
121                                                 "%s: Releasing lock @ %d\n\r",
122                                                 __FUNCTION__, __LINE__);
123                                 if (USE_RTM_LOCKS)
124                                         rtm_unlock();
125                                 else
126                                         rte_rwlock_write_unlock(&rwlock);
127                                 return IFM_FAILURE;
128                         }
129
130                         bond_port->bond_config->mode =
131                                         rte_eth_bond_mode_get(bond_port->pmdid);
132                         /* xmit policy may change for based on mode */
133                         bond_port->bond_config->xmit_policy =
134                                         rte_eth_bond_xmit_policy_get(bond_port->pmdid);
135                         if (ifm_debug && IFM_DEBUG_CONFIG)
136                                 RTE_LOG(INFO, IFM,
137                                         "%s: Bond port %u mode is updated. Mode %u xmit_policy %u."
138                                         "\n\r", __FUNCTION__, bond_port->pmdid,
139                                         bond_port->bond_config->mode,
140                                         bond_port->bond_config->xmit_policy);
141                 }
142                 port_id = bond_port->pmdid;
143                 if (ifm_debug & IFM_DEBUG_LOCKS)
144                         RTE_LOG(INFO, IFM, "%s: Acquiring lock @ %d\n\r",
145                                 __FUNCTION__, __LINE__);
146                 if (USE_RTM_LOCKS)
147                         rtm_unlock();
148                 else
149                         rte_rwlock_write_unlock(&rwlock);
150         }
151         return port_id;
152 }
153
154 int ifm_bond_port_delete(const char *name)
155 {
156         l2_phy_interface_t *bond_port;
157         if (name == NULL) {
158                 RTE_LOG(ERR, IFM, "%s: Param name cannot be NULL\n\r",
159                         __FUNCTION__);
160                 return IFM_FAILURE;
161         }
162         bond_port = ifm_get_port_by_name(name);
163         if (ifm_debug & IFM_DEBUG_LOCKS)
164                 RTE_LOG(INFO, IFM, "%s: Acquiring WR lock @ %d\n\r",
165                         __FUNCTION__, __LINE__);
166         if (USE_RTM_LOCKS)
167                 rtm_lock();
168         else
169                 rte_rwlock_write_lock(&rwlock);
170         if (bond_port == NULL) {
171                 RTE_LOG(ERR, IFM, "%s: Given bond port with name %s not"
172                         " found in the list\n\r", __FUNCTION__, name);
173                 return IFM_FAILURE;
174         }
175         if (!(bond_port->flags & IFM_MASTER)) {
176                 RTE_LOG(ERR, IFM, "%s: Given bond port %s is not "
177                         "configured is not bond port\n\r", __FUNCTION__, name);
178                 if (ifm_debug & IFM_DEBUG_LOCKS)
179                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
180                                 __FUNCTION__, __LINE__);
181                 if (USE_RTM_LOCKS) {
182                         rtm_unlock();
183                 } else {
184                         rte_rwlock_write_unlock(&rwlock);
185                 }
186                 return IFM_FAILURE;
187         }
188         if (bond_port->bond_config && bond_port->bond_config->slave_count > 0) {
189                 RTE_LOG(ERR, IFM, "%s: First unbind all slave "
190                         "ports from the bond port %s\n\r", __FUNCTION__, name);
191                 if (ifm_debug & IFM_DEBUG_LOCKS)
192                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
193                                 __FUNCTION__, __LINE__);
194                 if (USE_RTM_LOCKS) {
195                         rtm_unlock();
196                 } else {
197                         rte_rwlock_write_unlock(&rwlock);
198                 }
199                 return IFM_FAILURE;
200         }
201         int ret;
202         ret = rte_eth_bond_free(name);
203         if (ret < 0) {
204                 RTE_LOG(ERR, IFM, "%s: Failed to delete "
205                         "bond port %s\n\r", __FUNCTION__, name);
206                 if (ifm_debug & IFM_DEBUG_LOCKS)
207                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
208                                 __FUNCTION__, __LINE__);
209                 if (USE_RTM_LOCKS) {
210                         rtm_unlock();
211                 } else {
212                         rte_rwlock_write_unlock(&rwlock);
213                 }
214                 return IFM_FAILURE;
215         }
216         if (ifm_debug & IFM_DEBUG_CONFIG)
217                 RTE_LOG(INFO, IFM, "%s: Bond port %s deleted successfully\n\r",
218                         __FUNCTION__, name);
219
220         if (bond_port && bond_port->bond_config != NULL) {
221                 rte_free(bond_port->bond_config);
222                 bond_port->bond_config = NULL;
223         }
224         if (ifm_debug & IFM_DEBUG_LOCKS)
225                 RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
226                         __FUNCTION__, __LINE__);
227         if (USE_RTM_LOCKS)
228                 rtm_unlock();
229         else
230                 rte_rwlock_write_unlock(&rwlock);
231         ifm_remove_port_details(bond_port->pmdid);
232         //ifm.port_list[bond_port->pmdid] = NULL;
233         return IFM_SUCCESS;
234 }
235
236 int ifm_add_slave_port(uint8_t bonded_port_id, uint8_t slave_port_id)
237 {
238         l2_phy_interface_t *bond_port, *slave_port;
239         bond_port = ifm_get_port(bonded_port_id);
240         //   bond_port = ifm.port_list[bonded_port_id];
241         slave_port = ifm_get_port(slave_port_id);
242         // slave_port = ifm.port_list[slave_port_id];
243         if (ifm_debug & IFM_DEBUG)
244                 RTE_LOG(INFO, IFM, "%s: i/p bond id %u, slave id %u\n\r",
245                         __FUNCTION__, bonded_port_id, slave_port_id);
246         if (ifm_debug & IFM_DEBUG_LOCKS)
247                 RTE_LOG(INFO, IFM, "%s: Acquiring WR lock @ %d\n\r",
248                         __FUNCTION__, __LINE__);
249         if (USE_RTM_LOCKS) {
250                 rtm_lock();
251         } else {
252                 rte_rwlock_write_lock(&rwlock);
253         }
254         if (bond_port == NULL) {
255                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available in"
256                         " port list.\n\r", __FUNCTION__, bonded_port_id);
257                 if (ifm_debug & IFM_DEBUG_LOCKS)
258                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
259                                 __FUNCTION__, __LINE__);
260                 if (USE_RTM_LOCKS) {
261                         rtm_unlock();
262                 } else {
263                         rte_rwlock_write_unlock(&rwlock);
264                 }
265                 return IFM_FAILURE;
266         }
267         if (slave_port == NULL) {
268                 RTE_LOG(ERR, IFM, "%s: Given slave port %u is not available in "
269                         "port list.\n\r", __FUNCTION__, slave_port_id);
270                 if (ifm_debug & IFM_DEBUG_LOCKS)
271                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
272                                 __FUNCTION__, __LINE__);
273                 if (USE_RTM_LOCKS) {
274                         rtm_unlock();
275                 } else {
276                         rte_rwlock_write_unlock(&rwlock);
277                 }
278                 return IFM_FAILURE;
279         }
280         if (bond_port && !(bond_port->flags & IFM_MASTER)) {
281                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not configured "
282                         "as Master port. %u\n\r", __FUNCTION__, bonded_port_id,
283                         bond_port->flags & IFM_MASTER);
284                 if (ifm_debug & IFM_DEBUG_LOCKS)
285                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
286                                 __FUNCTION__, __LINE__);
287                 if (USE_RTM_LOCKS) {
288                         rtm_unlock();
289                 } else {
290                         rte_rwlock_write_unlock(&rwlock);
291                 }
292                 return IFM_FAILURE;
293         }
294         if (bond_port && bond_port->bond_config
295                         && bond_port->bond_config->slave_count == RTE_MAX_ETHPORTS) {
296                 RTE_LOG(ERR, IFM,
297                         "%s: Failed to bind.Already %u ports are bonded to master port...\n\r ",
298                         __FUNCTION__, RTE_MAX_ETHPORTS);
299                 if (ifm_debug & IFM_DEBUG_LOCKS)
300                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
301                                 __FUNCTION__, __LINE__);
302                 if (USE_RTM_LOCKS) {
303                         rtm_unlock();
304                 } else {
305                         rte_rwlock_write_unlock(&rwlock);
306                 }
307                 return IFM_FAILURE;
308         }
309         if (slave_port && slave_port->flags & IFM_SLAVE) {
310                 /* Have to check whether the port is already part of someother bond port */
311                 if (slave_port->bond_config != NULL) {
312                         if (bonded_port_id !=
313                                         slave_port->bond_config->bond_portid) {
314                                 RTE_LOG(ERR, IFM,
315                                         "%s: Slave port %u is already part"
316                                         " of other bond port %u.\n\r",
317                                         __FUNCTION__, slave_port_id,
318                                         slave_port->bond_config->bond_portid);
319                                 if (ifm_debug & IFM_DEBUG_LOCKS)
320                                         RTE_LOG(INFO, IFM,
321                                                 "%s: Releasing WR lock @ %d\n\r",
322                                                 __FUNCTION__, __LINE__);
323                                 if (USE_RTM_LOCKS) {
324                                         rtm_unlock();
325                                 } else {
326                                         rte_rwlock_write_unlock(&rwlock);
327                                 }
328                                 return IFM_FAILURE;
329                         } else {
330                                 if (ifm_debug & IFM_DEBUG)
331                                         RTE_LOG(INFO, IFM,
332                                                 "%s: Slave port %u is already bounded to %u\n\r",
333                                                 __FUNCTION__, slave_port_id,
334                                                 bonded_port_id);
335                                 if (ifm_debug & IFM_DEBUG_LOCKS)
336                                         RTE_LOG(INFO, IFM,
337                                                 "%s: Releasing WR lock @ %d\n\r",
338                                                 __FUNCTION__, __LINE__);
339                                 if (USE_RTM_LOCKS) {
340                                         rtm_unlock();
341                                 } else {
342                                         rte_rwlock_write_unlock(&rwlock);
343                                 }
344                                 return IFM_SUCCESS;
345                         }
346                 }
347         }
348         if (bond_port->bond_config && bond_port->bond_config->slave_count &&
349                         bond_port->link_speed != slave_port->link_speed
350                         && bond_port->link_duplex != slave_port->link_duplex) {
351                 RTE_LOG(ERR, IFM,
352                         "%s: Error in adding slave port to bond port. Reason speed mismatch\n\r",
353                         __FUNCTION__);
354                 if (ifm_debug & IFM_DEBUG_LOCKS)
355                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
356                                 __FUNCTION__, __LINE__);
357                 if (USE_RTM_LOCKS) {
358                         rtm_unlock();
359                 } else {
360                         rte_rwlock_write_unlock(&rwlock);
361                 }
362                 return IFM_FAILURE;
363         }
364         if (ifm_debug & IFM_DEBUG)
365                 RTE_LOG(INFO, IFM, "%s: Slave port %u Master port %u\n\r",
366                         __FUNCTION__, slave_port_id, bonded_port_id);
367         int ret;
368         ret = rte_eth_bond_slave_add(bond_port->pmdid, slave_port->pmdid);
369         if (ret < 0) {
370                 RTE_LOG(ERR, IFM, "%s: Failed to add slave port %u to bond "
371                         "port %u.\n\r", __FUNCTION__, slave_port->pmdid,
372                         bond_port->pmdid);
373                 if (ifm_debug & IFM_DEBUG_LOCKS)
374                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
375                                 __FUNCTION__, __LINE__);
376                 if (USE_RTM_LOCKS) {
377                         rtm_unlock();
378                 } else {
379                         rte_rwlock_write_unlock(&rwlock);
380                 }
381                 return IFM_FAILURE;
382         }
383         slave_port->flags |= IFM_SLAVE;
384         /* Populate bond config information */
385         if (bond_port->bond_config) {
386                 bond_port->bond_config->xmit_policy =
387                                 rte_eth_bond_xmit_policy_get(bond_port->pmdid);
388                 bond_port->bond_config->internal_ms =
389                                 rte_eth_bond_link_monitoring_get(bond_port->pmdid);
390                 bond_port->bond_config->link_up_delay_ms =
391                                 rte_eth_bond_link_up_prop_delay_get(bond_port->pmdid);
392                 bond_port->bond_config->link_down_delay_ms =
393                                 rte_eth_bond_link_down_prop_delay_get(bond_port->pmdid);
394                 bond_port->bond_config->primary =
395                                 rte_eth_bond_primary_get(bond_port->pmdid);
396                 bond_port->bond_config->slave_count =
397                                 rte_eth_bond_slaves_get(bond_port->pmdid,
398                                                         bond_port->bond_config->slaves,
399                                                         RTE_MAX_ETHPORTS);
400                 bond_port->bond_config->active_slave_count =
401                                 rte_eth_bond_active_slaves_get(bond_port->pmdid,
402                                                          bond_port->bond_config->
403                                                          active_slaves,
404                                                          RTE_MAX_ETHPORTS);
405                 slave_port->bond_config = bond_port->bond_config;
406                 if (ifm_debug & IFM_DEBUG)
407                         RTE_LOG(INFO, IFM, "%s: Slave count is %u\n\r",
408                                 __FUNCTION__,
409                                 bond_port->bond_config->slave_count);
410                 if (bond_port->bond_config->slave_count == 1) {
411                         ret =
412                                         ifm_port_setup(bond_port->pmdid,
413                                                  &(bond_port->port_config));
414                         if (ret < 0) {
415                                 RTE_LOG(ERR, IFM,
416                                         "%s: Failed to start bond port %u.\n\r",
417                                         __FUNCTION__, bond_port->pmdid);
418                                 if (ifm_debug & IFM_DEBUG_LOCKS)
419                                         RTE_LOG(INFO, IFM,
420                                                 "%s: Releasing WR lock @ %d\n\r",
421                                                 __FUNCTION__, __LINE__);
422                                 if (USE_RTM_LOCKS) {
423                                         rtm_unlock();
424                                 } else {
425                                         rte_rwlock_write_unlock(&rwlock);
426                                 }
427                                 return IFM_FAILURE;
428                         }
429                 } else {
430                         if (ifm_debug & IFM_DEBUG)
431                                 RTE_LOG(INFO, IFM, "%s: Skipping"
432                                         " port setup\n\r", __FUNCTION__);
433                 }
434         }
435         if (ifm_debug & IFM_DEBUG_LOCKS)
436                 RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
437                         __FUNCTION__, __LINE__);
438         if (USE_RTM_LOCKS) {
439                 rtm_unlock();
440         } else {
441                 rte_rwlock_write_unlock(&rwlock);
442         }
443         return IFM_SUCCESS;
444 }
445
446 int ifm_remove_slave_port(uint8_t bonded_port_id, uint8_t slave_port_id)
447 {
448         l2_phy_interface_t *bond_port, *slave_port;
449
450         bond_port = ifm_get_port(bonded_port_id);
451         //bond_port = ifm.port_list[bonded_port_id];
452         slave_port = ifm_get_port(slave_port_id);
453         //slave_port = ifm.port_list[slave_port_id];
454
455         if (ifm_debug & IFM_DEBUG_LOCKS)
456                 RTE_LOG(INFO, IFM, "%s: Acquiring WR lock @ %d\n\r",
457                         __FUNCTION__, __LINE__);
458         if (USE_RTM_LOCKS) {
459                 rtm_lock();
460         } else {
461                 rte_rwlock_write_lock(&rwlock);
462         }
463         if (bond_port == NULL) {
464                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available "
465                         "in port list.\n\r", __FUNCTION__, bonded_port_id);
466                 if (ifm_debug & IFM_DEBUG_LOCKS)
467                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
468                                 __FUNCTION__, __LINE__);
469                 if (USE_RTM_LOCKS)
470                         rtm_unlock();
471                 else
472                         rte_rwlock_write_unlock(&rwlock);
473                 return IFM_FAILURE;
474         }
475         if (slave_port == NULL) {
476                 RTE_LOG(ERR, IFM, "%s: Given slave port %u is not available "
477                         "in port list.\n\r", __FUNCTION__, slave_port_id);
478                 if (ifm_debug & IFM_DEBUG_LOCKS)
479                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
480                                 __FUNCTION__, __LINE__);
481                 if (USE_RTM_LOCKS)
482                         rtm_unlock();
483                 else
484                         rte_rwlock_write_unlock(&rwlock);
485                 return IFM_FAILURE;
486         }
487         if (bond_port && !(bond_port->flags & IFM_MASTER)) {
488                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not configured "
489                         "as Master port.\n\r", __FUNCTION__, bonded_port_id);
490                 if (ifm_debug & IFM_DEBUG_LOCKS)
491                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
492                                 __FUNCTION__, __LINE__);
493                 if (USE_RTM_LOCKS)
494                         rtm_unlock();
495                 else
496                         rte_rwlock_write_unlock(&rwlock);
497                 return IFM_FAILURE;
498         }
499         if (slave_port && !(slave_port->flags & IFM_SLAVE)) {
500                 RTE_LOG(ERR, IFM, "%s: Given slave port %u is not configured"
501                         " as slave port.\n\r", __FUNCTION__, slave_port_id);
502                 if (ifm_debug & IFM_DEBUG_LOCKS)
503                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
504                                 __FUNCTION__, __LINE__);
505                 if (USE_RTM_LOCKS)
506                         rtm_unlock();
507                 else
508                         rte_rwlock_write_unlock(&rwlock);
509                 return IFM_FAILURE;
510         }
511         int i;
512         int found = 0;
513         for (i = 0; i < bond_port->bond_config->slave_count; i++) {
514                 if (slave_port_id == bond_port->bond_config->slaves[i]) {
515                         found = 1;
516                         break;
517                 }
518         }
519         if (!found) {
520                 RTE_LOG(ERR, IFM, "%s: Given slave port %u is not binded "
521                         "with bond port %u\n\r", __FUNCTION__, slave_port_id,
522                         bonded_port_id);
523                 if (ifm_debug & IFM_DEBUG_LOCKS)
524                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
525                                 __FUNCTION__, __LINE__);
526                 if (USE_RTM_LOCKS)
527                         rtm_unlock();
528                 else
529                         rte_rwlock_write_unlock(&rwlock);
530                 return IFM_FAILURE;
531         }
532         if (rte_eth_bond_slave_remove(bonded_port_id, slave_port_id) < 0) {
533                 RTE_LOG(ERR, IFM, "%s: Failed to unbind slave port %u"
534                         " from bond port %u\n\r", __FUNCTION__, slave_port_id,
535                         bonded_port_id);
536                 if (ifm_debug & IFM_DEBUG_LOCKS)
537                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
538                                 __FUNCTION__, __LINE__);
539                 if (USE_RTM_LOCKS)
540                         rtm_unlock();
541                 else
542                         rte_rwlock_write_unlock(&rwlock);
543                 return IFM_FAILURE;
544         }
545         slave_port->flags &= ~IFM_SLAVE;
546         slave_port->bond_config = NULL;
547         bond_port->bond_config->primary =
548                         rte_eth_bond_primary_get(bond_port->pmdid);
549         bond_port->bond_config->slave_count =
550                         rte_eth_bond_slaves_get(bond_port->pmdid,
551                                                 bond_port->bond_config->slaves,
552                                                 RTE_MAX_ETHPORTS);
553         bond_port->bond_config->active_slave_count =
554                         rte_eth_bond_active_slaves_get(bond_port->pmdid,
555                                                  bond_port->bond_config->
556                                                  active_slaves, RTE_MAX_ETHPORTS);
557
558         if (ifm_debug & IFM_DEBUG)
559                 RTE_LOG(ERR, IFM, "%s: Unbinded slave port %u from the bond "
560                         "port %u %d\n\r", __FUNCTION__, slave_port_id,
561                         bonded_port_id,
562                         rte_eth_bond_primary_get(bond_port->pmdid));
563         if (ifm_debug & IFM_DEBUG_LOCKS)
564                 RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
565                         __FUNCTION__, __LINE__);
566         if (USE_RTM_LOCKS)
567                 rtm_unlock();
568         else
569                 rte_rwlock_write_unlock(&rwlock);
570         return IFM_SUCCESS;
571 }
572
573 int set_bond_mode(uint8_t bonded_port_id, uint8_t mode)
574 {
575         l2_phy_interface_t *bond_port;
576         bond_port = ifm_get_port(bonded_port_id);
577         //bond_port = ifm.port_list[bonded_port_id];
578
579         if (ifm_debug & IFM_DEBUG_LOCKS)
580                 RTE_LOG(INFO, IFM, "%s: Acquiring WR lock @ %d\n\r",
581                         __FUNCTION__, __LINE__);
582         if (USE_RTM_LOCKS)
583                 rtm_lock();
584         else
585                 rte_rwlock_write_lock(&rwlock);
586         if(bond_port)
587         ifm_remove_port_details(bond_port->pmdid);
588         if (bond_port == NULL) {
589                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available in"
590                         " port list.\n\r", __FUNCTION__, bonded_port_id);
591                 return IFM_FAILURE;
592         }
593         if (bond_port && bond_port->bond_config->mode == mode) {
594                 if (ifm_debug & IFM_DEBUG)
595                         RTE_LOG(INFO, IFM,
596                                 "%s: Already bond port is set with the given"
597                                 " mode %u\n\r.", __FUNCTION__, mode);
598                 if (ifm_debug & IFM_DEBUG_LOCKS)
599                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
600                                 __FUNCTION__, __LINE__);
601                 if (USE_RTM_LOCKS)
602                         rtm_unlock();
603                 else
604                         rte_rwlock_write_unlock(&rwlock);
605                 ifm_remove_port_details(bond_port->pmdid);
606                 return IFM_SUCCESS;
607
608         }
609         if (rte_eth_bond_mode_set(bond_port->pmdid, mode) < 0) {
610                 RTE_LOG(ERR, IFM,
611                         "%s: Failed to set bond mode %u for port id %u\n\r.",
612                         __FUNCTION__, mode, bond_port->pmdid);
613                 if (ifm_debug & IFM_DEBUG_LOCKS)
614                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
615                                 __FUNCTION__, __LINE__);
616                 if (USE_RTM_LOCKS)
617                         rtm_unlock();
618                 else
619                         rte_rwlock_write_unlock(&rwlock);
620                 ifm_remove_port_details(bond_port->pmdid);
621                 return IFM_FAILURE;
622         }
623
624         bond_port->bond_config->mode = rte_eth_bond_mode_get(bond_port->pmdid);
625         /* xmit policy may change for based on mode */
626         bond_port->bond_config->xmit_policy =
627                         rte_eth_bond_xmit_policy_get(bond_port->pmdid);
628         if (ifm_debug & IFM_DEBUG)
629                 RTE_LOG(INFO, IFM,
630                         "%s: Bond port %u mode is updated. Mode %u xmit_policy %u."
631                         "\n\r.", __FUNCTION__, bond_port->pmdid,
632                         bond_port->bond_config->mode,
633                         bond_port->bond_config->xmit_policy);
634         if (ifm_debug & IFM_DEBUG_LOCKS)
635                 RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
636                         __FUNCTION__, __LINE__);
637         if (USE_RTM_LOCKS)
638                 rtm_unlock();
639         else
640                 rte_rwlock_write_unlock(&rwlock);
641         ifm_remove_port_details(bond_port->pmdid);
642         return IFM_SUCCESS;
643 }
644
645 int get_bond_mode(uint8_t bonded_port_id)
646 {
647         l2_phy_interface_t *bond_port;
648         bond_port = ifm_get_port(bonded_port_id);
649         //bond_port = ifm.port_list[bonded_port_id];
650
651         if (ifm_debug & IFM_DEBUG_LOCKS)
652                 RTE_LOG(INFO, IFM, "%s: Acquiring RD lock @ %d\n\r",
653                         __FUNCTION__, __LINE__);
654         if (USE_RTM_LOCKS) {
655                 rtm_lock();
656         } else {
657                 rte_rwlock_read_lock(&rwlock);
658         }
659         if (bond_port == NULL) {
660                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available in"
661                         " port list.\n\r", __FUNCTION__, bonded_port_id);
662                 if (ifm_debug & IFM_DEBUG_LOCKS)
663                         RTE_LOG(INFO, IFM, "%s: Releasing RD lock @ %d\n\r",
664                                 __FUNCTION__, __LINE__);
665                 if (USE_RTM_LOCKS) {
666                         rtm_unlock();
667                 } else {
668                         rte_rwlock_read_unlock(&rwlock);
669                 }
670                 return IFM_FAILURE;
671         }
672         uint8_t mode = bond_port->bond_config->mode;
673         if (ifm_debug & IFM_DEBUG_LOCKS)
674                 RTE_LOG(INFO, IFM, "%s: Releasing RD lock @ %d\n\r",
675                         __FUNCTION__, __LINE__);
676         if (USE_RTM_LOCKS) {
677                 rtm_unlock();
678         } else {
679                 rte_rwlock_read_unlock(&rwlock);
680         }
681         return mode;
682 }
683
684 int set_bond_primary(uint8_t bonded_port_id, uint8_t slave_port_id)
685 {
686         l2_phy_interface_t *bond_port;
687         l2_phy_interface_t *slave_port;
688         bond_port = ifm_get_port(bonded_port_id);
689         //  bond_port = ifm.port_list[bonded_port_id];
690         slave_port = ifm_get_port(slave_port_id);
691         //  slave_port = ifm.port_list[slave_port_id];
692
693         if (ifm_debug & IFM_DEBUG_LOCKS)
694                 RTE_LOG(INFO, IFM, "%s: Acquiring WR lock @ %d\n\r",
695                         __FUNCTION__, __LINE__);
696         if (USE_RTM_LOCKS)
697                 rtm_lock();
698         else
699                 rte_rwlock_write_lock(&rwlock);
700         if (bond_port == NULL) {
701                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available in"
702                         " port list.\n\r", __FUNCTION__, bonded_port_id);
703                 if (ifm_debug & IFM_DEBUG_LOCKS)
704                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
705                                 __FUNCTION__, __LINE__);
706                 if (USE_RTM_LOCKS)
707                         rtm_unlock();
708                 else
709                         rte_rwlock_write_unlock(&rwlock);
710                 return IFM_FAILURE;
711         }
712         if (slave_port == NULL) {
713                 RTE_LOG(ERR, IFM, "%s: Given slave port %u is not available in"
714                         " port list.\n\r", __FUNCTION__, bonded_port_id);
715                 if (ifm_debug & IFM_DEBUG_LOCKS)
716                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
717                                 __FUNCTION__, __LINE__);
718                 if (USE_RTM_LOCKS)
719                         rtm_unlock();
720                 else
721                         rte_rwlock_write_unlock(&rwlock);
722                 return IFM_FAILURE;
723         }
724         int i;
725         int found = 0;
726         for (i = 0; i < bond_port->bond_config->slave_count; i++) {
727                 if (slave_port_id == bond_port->bond_config->slaves[i]) {
728                         found = 1;
729                         break;
730                 }
731         }
732         if (!found) {
733                 RTE_LOG(ERR, IFM, "%s: Slave port %u is not binded "
734                         "with bond port %u. Slave port should be binded first\n\r",
735                         __FUNCTION__, slave_port_id, bonded_port_id);
736                 if (ifm_debug & IFM_DEBUG_LOCKS)
737                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
738                                 __FUNCTION__, __LINE__);
739                 if (USE_RTM_LOCKS)
740                         rtm_unlock();
741                 else
742                         rte_rwlock_write_unlock(&rwlock);
743                 return IFM_FAILURE;
744         }
745
746         if (bond_port->bond_config->primary == slave_port_id) {
747                 if (ifm_debug & IFM_DEBUG)
748                         RTE_LOG(INFO, IFM,
749                                 "%s: Already slave port %u is primary for bond port"
750                                 "%u\n\r.", __FUNCTION__, bonded_port_id,
751                                 slave_port_id);
752                 if (ifm_debug & IFM_DEBUG_LOCKS)
753                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
754                                 __FUNCTION__, __LINE__);
755                 if (USE_RTM_LOCKS)
756                         rtm_unlock();
757                 else
758                         rte_rwlock_write_unlock(&rwlock);
759                 return IFM_SUCCESS;
760
761         }
762         if (rte_eth_bond_primary_set(bond_port->pmdid, slave_port->pmdid) < 0) {
763                 RTE_LOG(ERR, IFM,
764                         "%s:Failed to set slave %u as primary for bond port %u\n\r.",
765                         __FUNCTION__, slave_port->pmdid, bond_port->pmdid);
766                 if (ifm_debug & IFM_DEBUG_LOCKS)
767                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
768                                 __FUNCTION__, __LINE__);
769                 if (USE_RTM_LOCKS)
770                         rtm_unlock();
771                 else
772                         rte_rwlock_write_unlock(&rwlock);
773                 return IFM_FAILURE;
774         }
775
776         bond_port->bond_config->primary =
777                         rte_eth_bond_primary_get(bond_port->pmdid);
778         if (ifm_debug & IFM_DEBUG)
779                 RTE_LOG(INFO, IFM,
780                         "%s: Primary port is updated as %u for bond port %u",
781                         __FUNCTION__, bond_port->bond_config->primary,
782                         bond_port->pmdid);
783         if (ifm_debug & IFM_DEBUG_LOCKS)
784                 RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
785                         __FUNCTION__, __LINE__);
786         if (USE_RTM_LOCKS)
787                 rtm_unlock();
788         else
789                 rte_rwlock_write_unlock(&rwlock);
790         return IFM_SUCCESS;
791 }
792
793 int get_bond_primary_port(uint8_t bonded_port_id)
794 {
795         l2_phy_interface_t *bond_port;
796         bond_port = ifm_get_port(bonded_port_id);
797         //bond_port = ifm.port_list[bonded_port_id];
798
799         if (ifm_debug & IFM_DEBUG_LOCKS)
800                 RTE_LOG(INFO, IFM, "%s: Acquiring RD lock @ %d\n\r",
801                         __FUNCTION__, __LINE__);
802         if (USE_RTM_LOCKS) {
803                 rtm_lock();
804         } else {
805                 rte_rwlock_read_lock(&rwlock);
806         }
807         if (bond_port == NULL) {
808                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available in"
809                         " port list.\n\r", __FUNCTION__, bonded_port_id);
810                 if (ifm_debug & IFM_DEBUG_LOCKS)
811                         RTE_LOG(INFO, IFM, "%s: Releasing RD lock @ %d\n\r",
812                                 __FUNCTION__, __LINE__);
813                 if (USE_RTM_LOCKS) {
814                         rtm_unlock();
815                 } else {
816                         rte_rwlock_read_unlock(&rwlock);
817                 }
818                 return IFM_FAILURE;
819         }
820         uint8_t primary = bond_port->bond_config->primary;
821         if (ifm_debug & IFM_DEBUG_LOCKS)
822                 RTE_LOG(INFO, IFM, "%s: Releasing RD lock @ %d\n\r",
823                         __FUNCTION__, __LINE__);
824         if (USE_RTM_LOCKS) {
825                 rtm_unlock();
826         } else {
827                 rte_rwlock_read_unlock(&rwlock);
828         }
829         return primary;
830 }
831
832 int get_bond_slave_count(uint8_t bonded_port_id)
833 {
834         l2_phy_interface_t *bond_port;
835         bond_port = ifm_get_port(bonded_port_id);
836         // bond_port = ifm.port_list[bonded_port_id];
837
838         if (ifm_debug & IFM_DEBUG_LOCKS)
839                 RTE_LOG(INFO, IFM, "%s: Acquiring RD lock @ %d\n\r",
840                         __FUNCTION__, __LINE__);
841         if (USE_RTM_LOCKS) {
842                 rtm_lock();
843         } else {
844                 rte_rwlock_read_lock(&rwlock);
845         }
846         if (bond_port == NULL) {
847                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available in"
848                         " port list.\n\r", __FUNCTION__, bonded_port_id);
849                 if (ifm_debug & IFM_DEBUG_LOCKS)
850                         RTE_LOG(INFO, IFM, "%s: Releasing RD lock @ %d\n\r",
851                                 __FUNCTION__, __LINE__);
852                 if (USE_RTM_LOCKS) {
853                         rtm_unlock();
854                 } else {
855                         rte_rwlock_read_unlock(&rwlock);
856                 }
857                 return IFM_FAILURE;
858         }
859         uint32_t slave_count = bond_port->bond_config->slave_count;
860         if (ifm_debug & IFM_DEBUG_LOCKS)
861                 RTE_LOG(INFO, IFM, "%s: Releasing RD lock @ %d\n\r",
862                         __FUNCTION__, __LINE__);
863         if (USE_RTM_LOCKS) {
864                 rtm_unlock();
865         } else {
866                 rte_rwlock_read_unlock(&rwlock);
867         }
868         return slave_count;
869 }
870
871 int get_bond_active_slave_count(uint8_t bonded_port_id)
872 {
873         l2_phy_interface_t *bond_port;
874         bond_port = ifm_get_port(bonded_port_id);
875         //bond_port = ifm.port_list[bonded_port_id];
876
877         if (ifm_debug & IFM_DEBUG_LOCKS)
878                 RTE_LOG(INFO, IFM, "%s: Acquiring RD lock @ %d\n\r",
879                         __FUNCTION__, __LINE__);
880         if (USE_RTM_LOCKS) {
881                 rtm_lock();
882         } else {
883                 rte_rwlock_read_lock(&rwlock);
884         }
885         if (bond_port == NULL) {
886                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available in"
887                         " port list.\n\r", __FUNCTION__, bonded_port_id);
888                 if (ifm_debug & IFM_DEBUG_LOCKS)
889                         RTE_LOG(INFO, IFM, "%s: Releasing RD lock @ %d\n\r",
890                                 __FUNCTION__, __LINE__);
891                 if (USE_RTM_LOCKS) {
892                         rtm_unlock();
893                 } else {
894                         rte_rwlock_read_unlock(&rwlock);
895                 }
896                 return IFM_FAILURE;
897         }
898         uint32_t slave_count = bond_port->bond_config->active_slave_count;
899         if (ifm_debug & IFM_DEBUG_LOCKS)
900                 RTE_LOG(INFO, IFM, "%s: Releasing RD lock @ %d\n\r",
901                         __FUNCTION__, __LINE__);
902         if (USE_RTM_LOCKS) {
903                 rtm_unlock();
904         } else {
905                 rte_rwlock_read_unlock(&rwlock);
906         }
907         return slave_count;
908 }
909
910 int get_bond_slaves(uint8_t bonded_port_id, uint8_t slaves[RTE_MAX_ETHPORTS])
911 {
912         l2_phy_interface_t *bond_port;
913         bond_port = ifm_get_port(bonded_port_id);
914         //bond_port = ifm.port_list[bonded_port_id];
915
916         if (ifm_debug & IFM_DEBUG_LOCKS)
917                 RTE_LOG(INFO, IFM, "%s: Acquiring RD lock @ %d\n\r",
918                         __FUNCTION__, __LINE__);
919         if (USE_RTM_LOCKS) {
920                 rtm_lock();
921         } else {
922                 rte_rwlock_read_lock(&rwlock);
923         }
924         if (bond_port == NULL) {
925                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available in"
926                         " port list.\n\r", __FUNCTION__, bonded_port_id);
927                 return IFM_FAILURE;
928         }
929         memcpy(slaves, bond_port->bond_config->slaves,
930                                  bond_port->bond_config->slave_count);
931         if (ifm_debug & IFM_DEBUG_LOCKS)
932                 RTE_LOG(INFO, IFM, "%s: Releasing RD lock @ %d\n\r",
933                         __FUNCTION__, __LINE__);
934         if (USE_RTM_LOCKS) {
935                 rtm_unlock();
936         } else {
937                 rte_rwlock_read_unlock(&rwlock);
938         }
939         return IFM_SUCCESS;
940 }
941
942 int get_bond_active_slaves(uint8_t bonded_port_id,
943                                  uint8_t active_slaves[RTE_MAX_ETHPORTS])
944 {
945         l2_phy_interface_t *bond_port;
946         bond_port = ifm_get_port(bonded_port_id);
947         //bond_port = ifm.port_list[bonded_port_id];
948
949         if (ifm_debug & IFM_DEBUG_LOCKS)
950                 RTE_LOG(INFO, IFM, "%s: Acquiring RD lock @ %d\n\r",
951                         __FUNCTION__, __LINE__);
952         if (USE_RTM_LOCKS) {
953                 rtm_lock();
954         } else {
955                 rte_rwlock_read_lock(&rwlock);
956         }
957         if (bond_port == NULL) {
958                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available in"
959                         " port list.\n\r", __FUNCTION__, bonded_port_id);
960                 return IFM_FAILURE;
961         }
962         memcpy(active_slaves, bond_port->bond_config->active_slaves,
963                                  bond_port->bond_config->active_slave_count);
964         if (ifm_debug & IFM_DEBUG_LOCKS)
965                 RTE_LOG(INFO, IFM, "%s: Releasing RD lock @ %d\n\r",
966                         __FUNCTION__, __LINE__);
967         if (USE_RTM_LOCKS) {
968                 rtm_unlock();
969         } else {
970                 rte_rwlock_read_unlock(&rwlock);
971         }
972         return IFM_SUCCESS;
973 }
974
975 int set_bond_mac_address(uint8_t bonded_port_id, struct ether_addr *mac_addr)
976 {
977         l2_phy_interface_t *bond_port;
978         bond_port = ifm_get_port(bonded_port_id);
979         //bond_port = ifm.port_list[bonded_port_id];
980
981         if (ifm_debug & IFM_DEBUG_LOCKS)
982                 RTE_LOG(INFO, IFM, "%s: Acquiring WR lock @ %d\n\r",
983                         __FUNCTION__, __LINE__);
984         if (USE_RTM_LOCKS) {
985                 rtm_lock();
986         } else {
987                 rte_rwlock_write_lock(&rwlock);
988         }
989         if (mac_addr == NULL) {
990                 RTE_LOG(ERR, IFM, "%s: MAC address cannot be NULL.\n\r",
991                         __FUNCTION__);
992                 if (ifm_debug & IFM_DEBUG_LOCKS)
993                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
994                                 __FUNCTION__, __LINE__);
995                 if (USE_RTM_LOCKS) {
996                         rtm_unlock();
997                 } else {
998                         rte_rwlock_write_unlock(&rwlock);
999                 }
1000                 return IFM_FAILURE;
1001         }
1002
1003         if (bond_port == NULL) {
1004                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available in"
1005                         " port list.\n\r", __FUNCTION__, bonded_port_id);
1006                 if (ifm_debug & IFM_DEBUG_LOCKS)
1007                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1008                                 __FUNCTION__, __LINE__);
1009                 if (USE_RTM_LOCKS) {
1010                         rtm_unlock();
1011                 } else {
1012                         rte_rwlock_write_unlock(&rwlock);
1013                 }
1014                 return IFM_FAILURE;
1015         }
1016         if (rte_eth_bond_mac_address_set(bond_port->pmdid, mac_addr) < 0) {
1017                 RTE_LOG(ERR, IFM, "%s: Failed to set MAC addr for port %u\n\r",
1018                         __FUNCTION__, bond_port->pmdid);
1019                 if (ifm_debug & IFM_DEBUG_LOCKS)
1020                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1021                                 __FUNCTION__, __LINE__);
1022                 if (USE_RTM_LOCKS) {
1023                         rtm_unlock();
1024                 } else {
1025                         rte_rwlock_write_unlock(&rwlock);
1026                 }
1027                 return IFM_FAILURE;
1028         }
1029         rte_eth_macaddr_get(bond_port->pmdid,
1030                                         (struct ether_addr *)bond_port->macaddr);
1031         if (ifm_debug & IFM_DEBUG_LOCKS)
1032                 RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1033                         __FUNCTION__, __LINE__);
1034         if (USE_RTM_LOCKS) {
1035                 rtm_unlock();
1036         } else {
1037                 rte_rwlock_write_unlock(&rwlock);
1038         }
1039         return IFM_SUCCESS;
1040 }
1041
1042 int reset_bond_mac_addr(uint8_t bonded_port_id)
1043 {
1044         l2_phy_interface_t *bond_port;
1045         bond_port = ifm_get_port(bonded_port_id);
1046         //   bond_port = ifm.port_list[bonded_port_id];
1047
1048         if (ifm_debug & IFM_DEBUG_LOCKS)
1049                 RTE_LOG(INFO, IFM, "%s: Acquiring WR lock @ %d\n\r",
1050                         __FUNCTION__, __LINE__);
1051         if (USE_RTM_LOCKS) {
1052                 rtm_lock();
1053         } else {
1054                 rte_rwlock_write_lock(&rwlock);
1055         }
1056         if (bond_port == NULL) {
1057                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available in"
1058                         " port list.\n\r", __FUNCTION__, bonded_port_id);
1059                 if (ifm_debug & IFM_DEBUG_LOCKS)
1060                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1061                                 __FUNCTION__, __LINE__);
1062                 if (USE_RTM_LOCKS) {
1063                         rtm_unlock();
1064                 } else {
1065                         rte_rwlock_write_unlock(&rwlock);
1066                 }
1067                 return IFM_FAILURE;
1068         }
1069         if (rte_eth_bond_mac_address_reset(bond_port->pmdid) < 0) {
1070                 RTE_LOG(ERR, IFM,
1071                         "%s: Failed to reset MAC addr for port %u\n\r",
1072                         __FUNCTION__, bond_port->pmdid);
1073                 if (ifm_debug & IFM_DEBUG_LOCKS)
1074                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1075                                 __FUNCTION__, __LINE__);
1076                 if (USE_RTM_LOCKS) {
1077                         rtm_unlock();
1078                 } else {
1079                         rte_rwlock_write_unlock(&rwlock);
1080                 }
1081                 return IFM_FAILURE;
1082         }
1083         rte_eth_macaddr_get(bond_port->pmdid,
1084                                         (struct ether_addr *)bond_port->macaddr);
1085         if (ifm_debug & IFM_DEBUG_LOCKS)
1086                 RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1087                         __FUNCTION__, __LINE__);
1088         if (USE_RTM_LOCKS) {
1089                 rtm_unlock();
1090         } else {
1091                 rte_rwlock_write_unlock(&rwlock);
1092         }
1093         return IFM_FAILURE;
1094 }
1095
1096 int set_bond_xmitpolicy(uint8_t bonded_port_id, uint8_t policy)
1097 {
1098
1099         l2_phy_interface_t *bond_port;
1100         bond_port = ifm_get_port(bonded_port_id);
1101         //bond_port = ifm.port_list[bonded_port_id];
1102         int ret = 0;
1103
1104         if (ifm_debug & IFM_DEBUG_LOCKS)
1105                 RTE_LOG(INFO, IFM, "%s: Acquiring WR lock @ %d\n\r",
1106                         __FUNCTION__, __LINE__);
1107         if (USE_RTM_LOCKS) {
1108                 rtm_lock();
1109         } else {
1110                 rte_rwlock_write_lock(&rwlock);
1111         }
1112         if (bond_port == NULL) {
1113                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available in"
1114                         " port list.\n\r", __FUNCTION__, bonded_port_id);
1115                 if (ifm_debug & IFM_DEBUG_LOCKS)
1116                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1117                                 __FUNCTION__, __LINE__);
1118                 if (USE_RTM_LOCKS) {
1119                         rtm_unlock();
1120                 } else {
1121                         rte_rwlock_write_unlock(&rwlock);
1122                 }
1123                 return IFM_FAILURE;
1124         }
1125         if (bond_port->bond_config->xmit_policy == policy) {
1126                 if (ifm_debug & IFM_DEBUG)
1127                         RTE_LOG(INFO, IFM,
1128                                 "%s: For port %u, old policy value and new value are same\n\r",
1129                                 __FUNCTION__, bonded_port_id);
1130                 if (ifm_debug & IFM_DEBUG_LOCKS)
1131                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1132                                 __FUNCTION__, __LINE__);
1133                 if (USE_RTM_LOCKS) {
1134                         rtm_unlock();
1135                 } else {
1136                         rte_rwlock_write_unlock(&rwlock);
1137                 }
1138                 return IFM_SUCCESS;
1139         }
1140         if (rte_eth_bond_xmit_policy_set(bond_port->pmdid, policy) < 0) {
1141                 RTE_LOG(ERR, IFM, "%s: Failed to set policy for port %u\n\r",
1142                         __FUNCTION__, bond_port->pmdid);
1143                 if (ifm_debug & IFM_DEBUG_LOCKS)
1144                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1145                                 __FUNCTION__, __LINE__);
1146                 if (USE_RTM_LOCKS) {
1147                         rtm_unlock();
1148                 } else {
1149                         rte_rwlock_write_unlock(&rwlock);
1150                 }
1151                 return IFM_FAILURE;
1152         }
1153         ret = rte_eth_bond_xmit_policy_get(bond_port->pmdid);
1154         if (ret < 0) {
1155                 if (ifm_debug & IFM_DEBUG)
1156                         RTE_LOG(INFO, IFM,
1157                                 "%s: rte_eth_bond_xmit_policy_set failed\n\r",
1158                                 __FUNCTION__);
1159                 if (ifm_debug & IFM_DEBUG_LOCKS)
1160                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1161                                 __FUNCTION__, __LINE__);
1162                 if (USE_RTM_LOCKS) {
1163                         rtm_unlock();
1164                 } else {
1165                         rte_rwlock_write_unlock(&rwlock);
1166                 }
1167                 return IFM_FAILURE;
1168         }
1169         bond_port->bond_config->xmit_policy = policy;
1170         if (ifm_debug & IFM_DEBUG_LOCKS)
1171                 RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1172                         __FUNCTION__, __LINE__);
1173         if (USE_RTM_LOCKS) {
1174                 rtm_unlock();
1175         } else {
1176                 rte_rwlock_write_unlock(&rwlock);
1177         }
1178         return IFM_SUCCESS;
1179 }
1180
1181 int get_bond_xmitpolicy(uint8_t bonded_port_id)
1182 {
1183         l2_phy_interface_t *bond_port;
1184
1185         bond_port = ifm_get_port(bonded_port_id);
1186
1187         if (ifm_debug & IFM_DEBUG_LOCKS)
1188                 RTE_LOG(INFO, IFM, "%s: RD Acquiring lock @ %d\n\r",
1189                         __FUNCTION__, __LINE__);
1190         if (USE_RTM_LOCKS) {
1191                 rtm_lock();
1192         } else {
1193                 rte_rwlock_read_lock(&rwlock);
1194         }
1195         if (bond_port == NULL) {
1196                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available in"
1197                         " port list.\n\r", __FUNCTION__, bonded_port_id);
1198                 if (ifm_debug & IFM_DEBUG_LOCKS)
1199                         RTE_LOG(INFO, IFM, "%s:Releasing RD lock @ %d\n\r",
1200                                 __FUNCTION__, __LINE__);
1201                 if (USE_RTM_LOCKS) {
1202                         rtm_unlock();
1203                 } else {
1204                         rte_rwlock_read_unlock(&rwlock);
1205                 }
1206                 return IFM_FAILURE;
1207         }
1208         uint8_t policy = bond_port->bond_config->xmit_policy;
1209         if (ifm_debug & IFM_DEBUG_LOCKS)
1210                 RTE_LOG(INFO, IFM, "%s:Releasing RD lock @ %d\n\r",
1211                         __FUNCTION__, __LINE__);
1212         if (USE_RTM_LOCKS) {
1213                 rtm_unlock();
1214         } else {
1215                 rte_rwlock_read_unlock(&rwlock);
1216         }
1217         return policy;
1218 }
1219
1220 int set_bond_link_montitor_frequency(uint8_t bonded_port_id,
1221                                                  uint32_t internal_ms)
1222 {
1223         l2_phy_interface_t *bond_port;
1224         if (ifm_debug & IFM_DEBUG_LOCKS)
1225                 RTE_LOG(INFO, IFM, "%s: Acquiring WR lock @ %d\n\r",
1226                         __FUNCTION__, __LINE__);
1227         if (USE_RTM_LOCKS) {
1228                 rtm_lock();
1229         } else {
1230                 rte_rwlock_write_lock(&rwlock);
1231         }
1232 //      bond_port = ifm.port_list[bonded_port_id];
1233         bond_port = ifm_get_port(bonded_port_id);
1234         int ret = 0;
1235
1236         if (bond_port == NULL) {
1237                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available in"
1238                         " port list.\n\r", __FUNCTION__, bonded_port_id);
1239                 if (ifm_debug & IFM_DEBUG_LOCKS)
1240                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1241                                 __FUNCTION__, __LINE__);
1242                 if (USE_RTM_LOCKS) {
1243                         rtm_unlock();
1244                 } else {
1245                         rte_rwlock_write_unlock(&rwlock);
1246                 }
1247                 return IFM_FAILURE;
1248         }
1249         if (bond_port->bond_config->internal_ms == internal_ms) {
1250                 if (ifm_debug & IFM_DEBUG)
1251                         RTE_LOG(INFO, IFM,
1252                                 "%s: For port %u, old frequency value and new value are same\n\r",
1253                                 __FUNCTION__, bonded_port_id);
1254                 if (ifm_debug & IFM_DEBUG_LOCKS)
1255                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1256                                 __FUNCTION__, __LINE__);
1257                 if (USE_RTM_LOCKS) {
1258                         rtm_unlock();
1259                 } else {
1260                         rte_rwlock_write_unlock(&rwlock);
1261                 }
1262                 return IFM_SUCCESS;
1263         }
1264         if (rte_eth_bond_link_monitoring_set(bond_port->pmdid, internal_ms) < 0) {
1265                 RTE_LOG(ERR, IFM,
1266                         "%s: Failed to set link monitor frequency for port %u\n\r",
1267                         __FUNCTION__, bond_port->pmdid);
1268                 if (ifm_debug & IFM_DEBUG_LOCKS)
1269                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1270                                 __FUNCTION__, __LINE__);
1271                 if (USE_RTM_LOCKS) {
1272                         rtm_unlock();
1273                 } else {
1274                         rte_rwlock_write_unlock(&rwlock);
1275                 }
1276                 return IFM_FAILURE;
1277         }
1278         ret = rte_eth_bond_link_monitoring_get(bond_port->pmdid);
1279         if (ret < 0) {
1280                 if (ifm_debug & IFM_DEBUG)
1281                         RTE_LOG(INFO, IFM,
1282                                 "%s: rte_eth_bond_link_monitoring_get failed\n\r",
1283                                 __FUNCTION__);
1284                 if (ifm_debug & IFM_DEBUG_LOCKS)
1285                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1286                                 __FUNCTION__, __LINE__);
1287                 if (USE_RTM_LOCKS) {
1288                         rtm_unlock();
1289                 } else {
1290                         rte_rwlock_write_unlock(&rwlock);
1291                 }
1292                 return IFM_FAILURE;
1293         }
1294         bond_port->bond_config->internal_ms = internal_ms;
1295         if (ifm_debug & IFM_DEBUG_LOCKS)
1296                 RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1297                         __FUNCTION__, __LINE__);
1298         if (USE_RTM_LOCKS) {
1299                 rtm_unlock();
1300         } else {
1301                 rte_rwlock_write_unlock(&rwlock);
1302         }
1303         return IFM_SUCCESS;
1304 }
1305
1306 int get_bond_link_monitor_frequency(uint8_t bonded_port_id)
1307 {
1308         l2_phy_interface_t *bond_port;
1309 //      bond_port = ifm.port_list[bonded_port_id];
1310         bond_port = ifm_get_port(bonded_port_id);
1311
1312         if (ifm_debug & IFM_DEBUG_LOCKS)
1313                 RTE_LOG(INFO, IFM, "%s:  Acquiring RD lock @ %d\n\r",
1314                         __FUNCTION__, __LINE__);
1315         if (USE_RTM_LOCKS) {
1316                 rtm_lock();
1317         } else {
1318                 rte_rwlock_read_lock(&rwlock);
1319         }
1320         if (bond_port == NULL) {
1321                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available in"
1322                         " port list.\n\r", __FUNCTION__, bonded_port_id);
1323                 if (ifm_debug & IFM_DEBUG_LOCKS)
1324                         RTE_LOG(INFO, IFM, "%s: Releasing RD lock @ %d\n\r",
1325                                 __FUNCTION__, __LINE__);
1326                 if (USE_RTM_LOCKS) {
1327                         rtm_unlock();
1328                 } else {
1329                         rte_rwlock_read_unlock(&rwlock);
1330                 }
1331                 return IFM_FAILURE;
1332         }
1333         uint32_t internal_ms = bond_port->bond_config->internal_ms;
1334         if (ifm_debug & IFM_DEBUG_LOCKS)
1335                 RTE_LOG(INFO, IFM, "%s: Releasing RD lock @ %d\n\r",
1336                         __FUNCTION__, __LINE__);
1337         if (USE_RTM_LOCKS) {
1338                 rtm_unlock();
1339         } else {
1340                 rte_rwlock_read_unlock(&rwlock);
1341         }
1342         return internal_ms;
1343 }
1344
1345 int set_bond_linkdown_delay(uint8_t bonded_port_id, uint32_t delay_ms)
1346 {
1347         l2_phy_interface_t *bond_port;
1348         if (ifm_debug & IFM_DEBUG_LOCKS)
1349                 RTE_LOG(INFO, IFM, "%s: Acquiring WR lock @ %d\n\r",
1350                         __FUNCTION__, __LINE__);
1351
1352         if (USE_RTM_LOCKS) {
1353                 rtm_lock();
1354         } else {
1355                 rte_rwlock_write_lock(&rwlock);
1356         }
1357 //      bond_port = ifm.port_list[bonded_port_id];
1358         bond_port = ifm_get_port(bonded_port_id);
1359         int delay = 0;
1360
1361         if (bond_port == NULL) {
1362                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available in"
1363                         " port list.\n\r", __FUNCTION__, bonded_port_id);
1364                 if (ifm_debug & IFM_DEBUG_LOCKS)
1365                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1366                                 __FUNCTION__, __LINE__);
1367
1368                 if (USE_RTM_LOCKS) {
1369                         rtm_unlock();
1370                 } else {
1371                         rte_rwlock_write_unlock(&rwlock);
1372                 }
1373                 return IFM_FAILURE;
1374         }
1375         if (bond_port->bond_config->link_down_delay_ms == delay_ms) {
1376                 if (ifm_debug & IFM_DEBUG)
1377                         RTE_LOG(INFO, IFM,
1378                                 "%s: For port %u, old delay value and new value are same\n\r",
1379                                 __FUNCTION__, bonded_port_id);
1380                 if (ifm_debug & IFM_DEBUG_LOCKS)
1381                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1382                                 __FUNCTION__, __LINE__);
1383
1384                 if (USE_RTM_LOCKS) {
1385                         rtm_unlock();
1386                 } else {
1387                         rte_rwlock_write_unlock(&rwlock);
1388                 }
1389                 return IFM_SUCCESS;
1390         }
1391         if (rte_eth_bond_link_down_prop_delay_set(bond_port->pmdid, delay_ms) <
1392                         0) {
1393                 RTE_LOG(ERR, IFM, "%s: Failed to set delay for port %u\n\r",
1394                         __FUNCTION__, bond_port->pmdid);
1395                 if (ifm_debug & IFM_DEBUG_LOCKS)
1396                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1397                                 __FUNCTION__, __LINE__);
1398
1399                 if (USE_RTM_LOCKS) {
1400                         rtm_unlock();
1401                 } else {
1402                         rte_rwlock_write_unlock(&rwlock);
1403                 }
1404                 return IFM_FAILURE;
1405         }
1406         delay = rte_eth_bond_link_down_prop_delay_get(bond_port->pmdid);
1407         if (delay < 0) {
1408                 if (ifm_debug & IFM_DEBUG)
1409                         RTE_LOG(INFO, IFM,
1410                                 "%s: rte_eth_bond_link_down_prop_delay_get failed\n\r",
1411                                 __FUNCTION__);
1412                 if (ifm_debug & IFM_DEBUG_LOCKS)
1413                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1414                                 __FUNCTION__, __LINE__);
1415
1416                 if (USE_RTM_LOCKS) {
1417                         rtm_unlock();
1418                 } else {
1419                         rte_rwlock_write_unlock(&rwlock);
1420                 }
1421                 return IFM_FAILURE;
1422         }
1423         bond_port->bond_config->link_down_delay_ms = delay;
1424         if (ifm_debug & IFM_DEBUG_LOCKS)
1425                 RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1426                         __FUNCTION__, __LINE__);
1427
1428         if (USE_RTM_LOCKS) {
1429                 rtm_unlock();
1430         } else {
1431                 rte_rwlock_write_unlock(&rwlock);
1432         }
1433         return IFM_SUCCESS;
1434 }
1435
1436 int get_bond_link_down_delay(uint8_t bonded_port_id)
1437 {
1438         l2_phy_interface_t *bond_port;
1439         //bond_port = ifm.port_list[bonded_port_id];
1440         bond_port = ifm_get_port(bonded_port_id);
1441         if (ifm_debug & IFM_DEBUG_LOCKS)
1442                 RTE_LOG(INFO, IFM, "%s: Acquiring RD lock @ %d\n\r",
1443                         __FUNCTION__, __LINE__);
1444         if (USE_RTM_LOCKS)
1445                 rtm_lock();
1446         else
1447                 rte_rwlock_read_lock(&rwlock);
1448
1449         if (bond_port == NULL) {
1450                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available in"
1451                         " port list.\n\r", __FUNCTION__, bonded_port_id);
1452                 if (ifm_debug & IFM_DEBUG_LOCKS)
1453                         RTE_LOG(INFO, IFM, "%s: Releasing RD lock @ %d\n\r",
1454                                 __FUNCTION__, __LINE__);
1455                 if (USE_RTM_LOCKS) {
1456                         rtm_unlock();
1457                 } else {
1458                         rte_rwlock_read_unlock(&rwlock);
1459                 }
1460                 return IFM_FAILURE;
1461         }
1462         uint32_t delay_ms = bond_port->bond_config->link_down_delay_ms;
1463         if (ifm_debug & IFM_DEBUG_LOCKS)
1464                 RTE_LOG(INFO, IFM, "%s: Releasing RD lock @ %d\n\r",
1465                         __FUNCTION__, __LINE__);
1466         if (USE_RTM_LOCKS) {
1467                 rtm_unlock();
1468         } else {
1469                 rte_rwlock_read_unlock(&rwlock);
1470         }
1471         return delay_ms;
1472
1473 }
1474
1475 int set_bond_linkup_delay(uint8_t bonded_port_id, uint32_t delay_ms)
1476 {
1477         l2_phy_interface_t *bond_port;
1478         int delay = 0;
1479         bond_port = ifm_get_port(bonded_port_id);
1480
1481         if (ifm_debug & IFM_DEBUG_LOCKS)
1482                 RTE_LOG(INFO, IFM, "%s: Acquiring WR lock @ %d\n\r",
1483                         __FUNCTION__, __LINE__);
1484         if (USE_RTM_LOCKS)
1485                 rtm_unlock();
1486         else
1487                 rte_rwlock_write_unlock(&rwlock);
1488
1489         if (bond_port == NULL) {
1490                 RTE_LOG(ERR, IFM, "%s: Given bond port %u is not available in"
1491                         " port list.\n\r", __FUNCTION__, bonded_port_id);
1492                 if (ifm_debug & IFM_DEBUG_LOCKS)
1493                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1494                                 __FUNCTION__, __LINE__);
1495                 if (USE_RTM_LOCKS)
1496                         rtm_unlock();
1497                 else
1498                         rte_rwlock_write_unlock(&rwlock);
1499                 return IFM_FAILURE;
1500         }
1501         if (bond_port->bond_config->link_up_delay_ms == delay_ms) {
1502                 if (ifm_debug & IFM_DEBUG)
1503                         RTE_LOG(INFO, IFM,
1504                                 "%s: For port %u, old delay value and new value are same\n\r",
1505                                 __FUNCTION__, bonded_port_id);
1506                 if (ifm_debug & IFM_DEBUG_LOCKS)
1507                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1508                                 __FUNCTION__, __LINE__);
1509                 if (USE_RTM_LOCKS)
1510                         rtm_unlock();
1511                 else
1512                         rte_rwlock_write_unlock(&rwlock);
1513                 return IFM_SUCCESS;
1514         }
1515         if (rte_eth_bond_link_up_prop_delay_set(bond_port->pmdid, delay_ms) < 0) {
1516                 RTE_LOG(ERR, IFM, "%s: Failed to set delay for port %u\n\r",
1517                         __FUNCTION__, bond_port->pmdid);
1518                 if (ifm_debug & IFM_DEBUG_LOCKS)
1519                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1520                                 __FUNCTION__, __LINE__);
1521
1522                 if (USE_RTM_LOCKS)
1523                         rtm_unlock();
1524                 else
1525                         rte_rwlock_write_unlock(&rwlock);
1526                 return IFM_FAILURE;
1527         }
1528         delay = rte_eth_bond_link_up_prop_delay_get(bond_port->pmdid);
1529         if (delay < 0) {
1530                 RTE_LOG(INFO, IFM,
1531                         "%s: rte_eth_bond_link_up_prop_delay_get failed\n\r",
1532                         __FUNCTION__);
1533                 if (ifm_debug & IFM_DEBUG_LOCKS)
1534                         RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1535                                 __FUNCTION__, __LINE__);
1536
1537                 if (USE_RTM_LOCKS)
1538                         rtm_unlock();
1539                 else
1540                         rte_rwlock_write_unlock(&rwlock);
1541                 return IFM_FAILURE;
1542         }
1543         bond_port->bond_config->link_up_delay_ms = delay;
1544         if (ifm_debug & IFM_DEBUG_LOCKS)
1545                 RTE_LOG(INFO, IFM, "%s: Releasing WR lock @ %d\n\r",
1546                         __FUNCTION__, __LINE__);
1547
1548         if (USE_RTM_LOCKS)
1549                 rtm_unlock();
1550         else
1551                 rte_rwlock_write_unlock(&rwlock);
1552         return IFM_SUCCESS;
1553 }
1554
1555 int get_bond_link_up_delay(uint8_t bonded_port_id)
1556 {
1557         l2_phy_interface_t *bond_port;
1558         uint32_t delay_ms;
1559
1560         bond_port = ifm_get_port(bonded_port_id);
1561
1562         if (ifm_debug & IFM_DEBUG_LOCKS)
1563                 RTE_LOG(INFO, IFM, "%s: Acquiring RD lock @ %d\n\r",
1564                         __FUNCTION__, __LINE__);
1565         if (USE_RTM_LOCKS)
1566                 rtm_lock();
1567         else
1568                 rte_rwlock_read_lock(&rwlock);
1569         if (bond_port == NULL) {
1570                 if (ifm_debug & IFM_DEBUG) {
1571                         RTE_LOG(ERR, IFM,
1572                                 "%s: Given bond port %u is not available in"
1573                                 " port list.\n\r", __FUNCTION__,
1574                                 bonded_port_id);
1575                 }
1576                 if (ifm_debug & IFM_DEBUG_LOCKS)
1577                         RTE_LOG(INFO, IFM, "%s: Releasing RD lock @ %d\n\r",
1578                                 __FUNCTION__, __LINE__);
1579                 if (USE_RTM_LOCKS)
1580                         rtm_unlock();
1581                 else
1582                         rte_rwlock_read_unlock(&rwlock);
1583                 return IFM_FAILURE;
1584         }
1585         delay_ms = bond_port->bond_config->link_up_delay_ms;
1586
1587         if (ifm_debug & IFM_DEBUG_LOCKS)
1588                 RTE_LOG(INFO, IFM, "%s: Releasing RD lock @ %d\n\r",
1589                         __FUNCTION__, __LINE__);
1590         if (USE_RTM_LOCKS)
1591                 rtm_unlock();
1592         else
1593                 rte_rwlock_read_unlock(&rwlock);
1594         return delay_ms;
1595 }