aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/plugins/odp/cli.c44
-rwxr-xr-xsrc/plugins/odp/device.c90
-rwxr-xr-xsrc/plugins/odp/node.c222
-rwxr-xr-xsrc/plugins/odp/odp_packet.c175
-rwxr-xr-xsrc/plugins/odp/odp_packet.h21
5 files changed, 249 insertions, 303 deletions
diff --git a/src/plugins/odp/cli.c b/src/plugins/odp/cli.c
index b7d846b7..e965022e 100755
--- a/src/plugins/odp/cli.c
+++ b/src/plugins/odp/cli.c
@@ -1,18 +1,7 @@
-/*
- *------------------------------------------------------------------
- * Copyright (c) 2016 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
+/* Copyright (c) 2017, Linaro Limited
+ * All rights reserved.
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *------------------------------------------------------------------
+ * SPDX-License-Identifier: BSD-3-Clause
*/
#include <fcntl.h> /* for open */
@@ -30,14 +19,14 @@
static clib_error_t *
odp_packet_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ vlib_cli_command_t * cmd)
{
unformat_input_t _line_input, *line_input = &_line_input;
u8 *host_if_name = NULL;
u8 hwaddr[6];
u8 *hw_addr_ptr = 0;
u32 sw_if_index;
- u32 mode=0;
+ u32 mode = 0;
int r;
if (!unformat_user (input, unformat_line_input, line_input))
@@ -47,15 +36,13 @@ odp_packet_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (line_input, "name %s", &host_if_name))
- ;
+ ;
else
if (unformat
(line_input, "hw-addr %U", unformat_ethernet_address, hwaddr))
hw_addr_ptr = hwaddr;
- else
- if (unformat
- (line_input, "mode %d", &mode))
- ;
+ else if (unformat (line_input, "mode %d", &mode))
+ ;
else
return clib_error_return (0, "unknown input `%U'",
format_unformat_error, input);
@@ -65,7 +52,8 @@ odp_packet_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
if (host_if_name == NULL)
return clib_error_return (0, "missing host interface name");
- r = odp_packet_create_if (vm, host_if_name, hw_addr_ptr, &sw_if_index, mode);
+ r =
+ odp_packet_create_if (vm, host_if_name, hw_addr_ptr, &sw_if_index, mode);
vec_free (host_if_name);
if (r == VNET_API_ERROR_SYSCALL_ERROR_1)
@@ -93,21 +81,21 @@ VLIB_CLI_COMMAND (odp_packet_create_command, static) = {
static clib_error_t *
odp_packet_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ vlib_cli_command_t * cmd)
{
unformat_input_t _line_input, *line_input = &_line_input;
u8 *host_if_name = NULL;
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return 0;
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (line_input, "name %s", &host_if_name))
- ;
+ ;
else
- return clib_error_return (0, "unknown input `%U'",
- format_unformat_error, input);
+ return clib_error_return (0, "unknown input `%U'",
+ format_unformat_error, input);
}
unformat_free (line_input);
@@ -117,7 +105,7 @@ odp_packet_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
odp_packet_delete_if (vm, host_if_name);
- vec_free(host_if_name);
+ vec_free (host_if_name);
return 0;
}
diff --git a/src/plugins/odp/device.c b/src/plugins/odp/device.c
index 6acc5ac7..cf7493c6 100755
--- a/src/plugins/odp/device.c
+++ b/src/plugins/odp/device.c
@@ -1,18 +1,7 @@
-/*
- *------------------------------------------------------------------
- * Copyright (c) 2016 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
+/* Copyright (c) 2017, Linaro Limited
+ * All rights reserved.
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *------------------------------------------------------------------
+ * SPDX-License-Identifier: BSD-3-Clause
*/
#include <linux/if_packet.h>
@@ -70,25 +59,25 @@ format_odp_packet_tx_trace (u8 * s, va_list * args)
static uword
odp_packet_interface_tx (vlib_main_t * vm,
- vlib_node_runtime_t * node, vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
odp_packet_main_t *om = &odp_packet_main;
u32 *buffers = vlib_frame_args (frame);
u32 n_left = frame->n_vectors;
vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
- odp_packet_if_t *oif =pool_elt_at_index (om->interfaces, rd->dev_instance);
+ odp_packet_if_t *oif = pool_elt_at_index (om->interfaces, rd->dev_instance);
odp_pktout_queue_t pktout;
odp_packet_t pkt_tbl[VLIB_FRAME_SIZE];
- u32 sent=0, count=0;
+ u32 sent = 0, count = 0;
if (PREDICT_FALSE (oif->lockp != 0))
{
while (__sync_lock_test_and_set (oif->lockp, 1))
- ;
+ ;
}
- if (odp_pktout_queue(oif->pktio, &pktout, 1) != 1)
+ if (odp_pktout_queue (oif->pktio, &pktout, 1) != 1)
{
return -1;
}
@@ -102,35 +91,35 @@ odp_packet_interface_tx (vlib_main_t * vm,
buffers++;
do
- {
- b0 = vlib_get_buffer (vm, bi);
- len = b0->current_length;
- pkt_tbl[count] = odp_packet_alloc(om->pool, len);
-
- if (pkt_tbl[count] == ODP_PACKET_INVALID)
- {
- clib_warning("odp packet alloc failed");
- }
-
- clib_memcpy ((u8 *) (odp_packet_data(pkt_tbl[count])),
- vlib_buffer_get_current (b0), len);
- count++;
- }
+ {
+ b0 = vlib_get_buffer (vm, bi);
+ len = b0->current_length;
+ pkt_tbl[count] = odp_packet_alloc (om->pool, len);
+
+ if (pkt_tbl[count] == ODP_PACKET_INVALID)
+ {
+ clib_warning ("odp packet alloc failed");
+ }
+
+ clib_memcpy ((u8 *) (odp_packet_data (pkt_tbl[count])),
+ vlib_buffer_get_current (b0), len);
+ count++;
+ }
while ((bi = b0->next_buffer) && (count < VLIB_FRAME_SIZE));
- }
+ }
CLIB_MEMORY_BARRIER ();
- sent = odp_pktout_send(pktout, pkt_tbl, count);
- sent= sent > 0 ? sent : 0;
+ sent = odp_pktout_send (pktout, pkt_tbl, count);
+ sent = sent > 0 ? sent : 0;
- if (odp_unlikely( sent < count ))
+ if (odp_unlikely (sent < count))
{
do
- {
- odp_packet_free(pkt_tbl[sent]);
- }
- while(++sent < count );
+ {
+ odp_packet_free (pkt_tbl[sent]);
+ }
+ while (++sent < count);
}
if (PREDICT_FALSE (oif->lockp != 0))
@@ -143,7 +132,7 @@ odp_packet_interface_tx (vlib_main_t * vm,
static void
odp_packet_set_interface_next_node (vnet_main_t * vnm, u32 hw_if_index,
- u32 node_index)
+ u32 node_index)
{
odp_packet_main_t *om = &odp_packet_main;
vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
@@ -156,8 +145,8 @@ odp_packet_set_interface_next_node (vnet_main_t * vnm, u32 hw_if_index,
}
oif->per_interface_next_index =
- vlib_node_add_next (vlib_get_main (), odp_packet_input_node.index,
- node_index);
+ vlib_node_add_next (vlib_get_main (), odp_packet_input_node.index,
+ node_index);
}
@@ -169,20 +158,19 @@ odp_packet_clear_hw_interface_counters (u32 instance)
static clib_error_t *
odp_packet_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index,
- u32 flags)
+ u32 flags)
{
odp_packet_main_t *om = &odp_packet_main;
vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
- odp_packet_if_t *oif =
- pool_elt_at_index (om->interfaces, hw->dev_instance);
+ odp_packet_if_t *oif = pool_elt_at_index (om->interfaces, hw->dev_instance);
u32 hw_flags;
oif->is_admin_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
if (oif->is_admin_up)
- hw_flags = VNET_HW_INTERFACE_FLAG_LINK_UP;
+ hw_flags = VNET_HW_INTERFACE_FLAG_LINK_UP;
else
- hw_flags = 0;
+ hw_flags = 0;
vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
@@ -191,8 +179,8 @@ odp_packet_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index,
static clib_error_t *
odp_packet_subif_add_del_function (vnet_main_t * vnm,
- u32 hw_if_index,
- struct vnet_sw_interface_t *st, int is_add)
+ u32 hw_if_index,
+ struct vnet_sw_interface_t *st, int is_add)
{
/* Nothing for now */
return 0;
diff --git a/src/plugins/odp/node.c b/src/plugins/odp/node.c
index 79892ce3..d03480c1 100755
--- a/src/plugins/odp/node.c
+++ b/src/plugins/odp/node.c
@@ -1,18 +1,7 @@
-/*
- *------------------------------------------------------------------
- * Copyright (c) 2016 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
+/* Copyright (c) 2017, Linaro Limited
+ * All rights reserved.
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *------------------------------------------------------------------
+ * SPDX-License-Identifier: BSD-3-Clause
*/
#include <linux/if_packet.h>
@@ -55,7 +44,7 @@ format_odp_packet_input_trace (u8 * s, va_list * args)
odp_packet_input_trace_t *t = va_arg (*args, odp_packet_input_trace_t *);
s = format (s, "odp_packet: hw_if_index %d next-index %d",
- t->hw_if_index, t->next_index);
+ t->hw_if_index, t->next_index);
return s;
}
@@ -86,34 +75,35 @@ odp_packet_queue_mode (odp_pktio_t pktio, u32 mode, odp_packet_t pkt_tbl[])
u32 num_evts = 0, num_pkts = 0, i = 0;
odp_queue_t inq;
odp_event_t evt_tbl[VLIB_FRAME_SIZE];
- u64 sched_wait = odp_schedule_wait_time(ODP_TIME_MSEC_IN_NS * 100);
+ u64 sched_wait = odp_schedule_wait_time (ODP_TIME_MSEC_IN_NS * 100);
if (pktio == ODP_PKTIO_INVALID)
{
- clib_warning("odp_pktio_lookup() failed");
+ clib_warning ("odp_pktio_lookup() failed");
return -1;
}
inq = ODP_QUEUE_INVALID;
if ((mode == APPL_MODE_PKT_QUEUE) &&
- (odp_pktin_event_queue(pktio, &inq, 1) != 1))
+ (odp_pktin_event_queue (pktio, &inq, 1) != 1))
{
- clib_warning("Error:no input queue");
+ clib_warning ("Error:no input queue");
return -1;
}
if (inq != ODP_QUEUE_INVALID)
- num_evts = odp_queue_deq_multi(inq, evt_tbl, VLIB_FRAME_SIZE);
+ num_evts = odp_queue_deq_multi (inq, evt_tbl, VLIB_FRAME_SIZE);
else
- num_evts = odp_schedule_multi(NULL, sched_wait, evt_tbl, VLIB_FRAME_SIZE);
+ num_evts =
+ odp_schedule_multi (NULL, sched_wait, evt_tbl, VLIB_FRAME_SIZE);
/* convert events to packets, discarding any non-packet events */
for (i = 0; i < num_evts; ++i)
{
- if (odp_event_type(evt_tbl[i]) == ODP_EVENT_PACKET)
- pkt_tbl[num_pkts++] = odp_packet_from_event(evt_tbl[i]);
- else
- odp_event_free(evt_tbl[i]);
+ if (odp_event_type (evt_tbl[i]) == ODP_EVENT_PACKET)
+ pkt_tbl[num_pkts++] = odp_packet_from_event (evt_tbl[i]);
+ else
+ odp_event_free (evt_tbl[i]);
}
return num_pkts;
@@ -121,17 +111,18 @@ odp_packet_queue_mode (odp_pktio_t pktio, u32 mode, odp_packet_t pkt_tbl[])
}
always_inline int
-odp_packet_burst_mode (odp_pktio_t pktio, odp_pktin_queue_t pktin, odp_packet_t pkt_tbl[])
+odp_packet_burst_mode (odp_pktio_t pktio, odp_pktin_queue_t pktin,
+ odp_packet_t pkt_tbl[])
{
u32 num_pkts;
- if (odp_pktin_queue(pktio, &pktin, 1) != 1)
+ if (odp_pktin_queue (pktio, &pktin, 1) != 1)
{
- clib_warning("odp_pktio_open() failed: no pktin queue");
+ clib_warning ("odp_pktio_open() failed: no pktin queue");
return -1;
}
- num_pkts = odp_pktin_recv(pktin, pkt_tbl, VLIB_FRAME_SIZE);
+ num_pkts = odp_pktin_recv (pktin, pkt_tbl, VLIB_FRAME_SIZE);
return num_pkts;
@@ -139,7 +130,7 @@ odp_packet_burst_mode (odp_pktio_t pktio, odp_pktin_queue_t pktin, odp_packet_t
always_inline uword
odp_packet_device_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
- vlib_frame_t * frame, odp_packet_if_t *oif)
+ vlib_frame_t * frame, odp_packet_if_t * oif)
{
u32 next_index = VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT;
uword n_trace = vlib_get_trace_count (vm, node);
@@ -148,15 +139,15 @@ odp_packet_device_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
u32 n_rx_bytes = 0;
u32 *to_next = 0;
u32 n_free_bufs;
- u32 thread_index = vlib_get_thread_index();
+ u32 thread_index = vlib_get_thread_index ();
odp_pktin_queue_t pktin = { 0 };
- odp_packet_t pkt,pkt_tbl[VLIB_FRAME_SIZE];
+ odp_packet_t pkt, pkt_tbl[VLIB_FRAME_SIZE];
u32 pkts = 0, pkts_ok = 0;
u32 n_buffer_bytes = vlib_buffer_free_list_buffer_size (vm,
- VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
+ VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
if (oif->per_interface_next_index != ~0)
- next_index = oif->per_interface_next_index;
+ next_index = oif->per_interface_next_index;
n_free_bufs = vec_len (om->rx_buffers[thread_index]);
if (PREDICT_FALSE (n_free_bufs < VLIB_FRAME_SIZE))
@@ -170,76 +161,74 @@ odp_packet_device_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
}
- if ((oif->mode ==( APPL_MODE_PKT_QUEUE)) ||
- (oif->mode ==(APPL_MODE_PKT_SCHED)))
+ if ((oif->mode == (APPL_MODE_PKT_QUEUE)) ||
+ (oif->mode == (APPL_MODE_PKT_SCHED)))
{
- pkts = odp_packet_queue_mode(oif->pktio, oif->mode, pkt_tbl);
+ pkts = odp_packet_queue_mode (oif->pktio, oif->mode, pkt_tbl);
}
else
{
- pkts = odp_packet_burst_mode(oif->pktio, pktin, pkt_tbl);
+ pkts = odp_packet_burst_mode (oif->pktio, pktin, pkt_tbl);
}
if (pkts > 0)
{
- u32 n_left_to_next,i = 0;
+ u32 n_left_to_next, i = 0;
u32 next0 = next_index;
- pkts_ok = drop_err_pkts(pkt_tbl, pkts);
+ pkts_ok = drop_err_pkts (pkt_tbl, pkts);
vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
- while((i < pkts_ok) && (n_left_to_next) && (n_free_bufs))
- {
- vlib_buffer_t *first_b0 = 0;
- u32 offset = 0;
- u32 bi0 = 0, first_bi0 = 0, prev_bi0;
- uint8_t *data_buf;
- pkt = pkt_tbl[i];
- u32 data_len = odp_packet_len(pkt);
- data_buf = malloc(data_len);
- memset(data_buf, 0, data_len);
- odp_packet_copy_to_mem(pkt, 0, data_len, data_buf);
-
- while (data_len && n_free_bufs)
- {
- vlib_buffer_t *b0;
- /* grab free buffer */
- u32 last_empty_buffer =
- vec_len (om->rx_buffers[thread_index]) - 1;
- prev_bi0 = bi0;
- bi0 = om->rx_buffers[thread_index][last_empty_buffer];
- b0 = vlib_get_buffer (vm, bi0);
- _vec_len (om->rx_buffers[thread_index]) = last_empty_buffer;
- n_free_bufs--;
- /* copy data */
- u32 bytes_to_copy =
- data_len > n_buffer_bytes ? n_buffer_bytes : data_len;
- b0->current_data = 0;
- clib_memcpy (vlib_buffer_get_current (b0),
- (u8 *) data_buf + offset,
- bytes_to_copy);
-
- /* fill buffer header */
- b0->current_length = bytes_to_copy;
-
- if (offset == 0)
- {
- b0->total_length_not_including_first_buffer = 0;
- b0->flags = VLIB_BUFFER_TOTAL_LENGTH_VALID;
- vnet_buffer (b0)->sw_if_index[VLIB_RX] =
- oif->sw_if_index;
- vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
- first_bi0 = bi0;
- first_b0 = vlib_get_buffer (vm, first_bi0);
- }
- else
- {
- buffer_add_to_chain (vm, bi0, first_bi0, prev_bi0);
- }
-
- offset += bytes_to_copy;
- data_len -= bytes_to_copy;
- }
- /* trace */
+ while ((i < pkts_ok) && (n_left_to_next) && (n_free_bufs))
+ {
+ vlib_buffer_t *first_b0 = 0;
+ u32 offset = 0;
+ u32 bi0 = 0, first_bi0 = 0, prev_bi0;
+ uint8_t *data_buf;
+ pkt = pkt_tbl[i];
+ u32 data_len = odp_packet_len (pkt);
+ data_buf = malloc (data_len);
+ memset (data_buf, 0, data_len);
+ odp_packet_copy_to_mem (pkt, 0, data_len, data_buf);
+
+ while (data_len && n_free_bufs)
+ {
+ vlib_buffer_t *b0;
+ /* grab free buffer */
+ u32 last_empty_buffer =
+ vec_len (om->rx_buffers[thread_index]) - 1;
+ prev_bi0 = bi0;
+ bi0 = om->rx_buffers[thread_index][last_empty_buffer];
+ b0 = vlib_get_buffer (vm, bi0);
+ _vec_len (om->rx_buffers[thread_index]) = last_empty_buffer;
+ n_free_bufs--;
+ /* copy data */
+ u32 bytes_to_copy =
+ data_len > n_buffer_bytes ? n_buffer_bytes : data_len;
+ b0->current_data = 0;
+ clib_memcpy (vlib_buffer_get_current (b0),
+ (u8 *) data_buf + offset, bytes_to_copy);
+
+ /* fill buffer header */
+ b0->current_length = bytes_to_copy;
+
+ if (offset == 0)
+ {
+ b0->total_length_not_including_first_buffer = 0;
+ b0->flags = VLIB_BUFFER_TOTAL_LENGTH_VALID;
+ vnet_buffer (b0)->sw_if_index[VLIB_RX] = oif->sw_if_index;
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
+ first_bi0 = bi0;
+ first_b0 = vlib_get_buffer (vm, first_bi0);
+ }
+ else
+ {
+ buffer_add_to_chain (vm, bi0, first_bi0, prev_bi0);
+ }
+
+ offset += bytes_to_copy;
+ data_len -= bytes_to_copy;
+ }
+ /* trace */
VLIB_BUFFER_TRACE_TRAJECTORY_INIT (first_b0);
if (PREDICT_FALSE (n_trace > 0))
{
@@ -251,33 +240,34 @@ odp_packet_device_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
tr->hw_if_index = oif->hw_if_index;
}
- /* redirect if feature path enabled */
+ /* redirect if feature path enabled */
vnet_feature_start_device_input_x1 (oif->sw_if_index, &next0,
- first_b0);
+ first_b0);
- /* enque and take next packet */
+ /* enque and take next packet */
vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
- n_left_to_next, first_bi0,
- next0);
+ n_left_to_next, first_bi0, next0);
- /* next packet */
+ /* next packet */
n_rx_packets++;
- n_rx_bytes += odp_packet_len(pkt);
+ n_rx_bytes += odp_packet_len (pkt);
to_next[0] = first_bi0;
to_next += 1;
- n_left_to_next--;
- free(data_buf);
- odp_packet_free(pkt_tbl[i]);
- i++;
- }
+ n_left_to_next--;
+ free (data_buf);
+ odp_packet_free (pkt_tbl[i]);
+ i++;
+ }
- vlib_put_next_frame (vm, node, next_index, n_left_to_next);
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
- }
+ }
- vlib_increment_combined_counter(vnet_get_main ()->interface_main.combined_sw_if_counters
- + VNET_INTERFACE_COUNTER_RX,
- vlib_get_thread_index (), oif->hw_if_index, n_rx_packets, n_rx_bytes);
+ vlib_increment_combined_counter (vnet_get_main ()->
+ interface_main.combined_sw_if_counters +
+ VNET_INTERFACE_COUNTER_RX,
+ vlib_get_thread_index (), oif->hw_if_index,
+ n_rx_packets, n_rx_bytes);
return n_rx_packets;
@@ -285,7 +275,7 @@ odp_packet_device_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
static uword
odp_packet_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_frame_t * frame)
{
int i;
@@ -299,11 +289,11 @@ odp_packet_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
oif = vec_elt_at_index (om->interfaces, i);
if (oif->is_admin_up &&
- (i % om->input_cpu_count) ==
- (thread_index - om->input_cpu_first_index))
- {
- n_rx_packets += odp_packet_device_input_fn (vm, node, frame, oif);
- }
+ (i % om->input_cpu_count) ==
+ (thread_index - om->input_cpu_first_index))
+ {
+ n_rx_packets += odp_packet_device_input_fn (vm, node, frame, oif);
+ }
}
return n_rx_packets;
diff --git a/src/plugins/odp/odp_packet.c b/src/plugins/odp/odp_packet.c
index a8c606d8..d2088142 100755
--- a/src/plugins/odp/odp_packet.c
+++ b/src/plugins/odp/odp_packet.c
@@ -1,18 +1,7 @@
-/*
- *------------------------------------------------------------------
- * Copyright (c) 2016 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
+/* Copyright (c) 2017, Linaro Limited
+ * All rights reserved.
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *------------------------------------------------------------------
+ * SPDX-License-Identifier: BSD-3-Clause
*/
#include <linux/if_ether.h>
@@ -27,7 +16,7 @@
static u32
odp_packet_eth_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi,
- u32 flags)
+ u32 flags)
{
/* nothing for now */
return 0;
@@ -45,7 +34,7 @@ odp_packet_eth_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi,
* @return Number of packets with no detected error
*/
u32
-drop_err_pkts(odp_packet_t pkt_tbl[], unsigned len)
+drop_err_pkts (odp_packet_t pkt_tbl[], unsigned len)
{
odp_packet_t pkt;
unsigned pkt_cnt = len;
@@ -55,72 +44,72 @@ drop_err_pkts(odp_packet_t pkt_tbl[], unsigned len)
{
pkt = pkt_tbl[i];
- if (odp_unlikely(odp_packet_has_error(pkt)))
- {
- odp_packet_free(pkt); /* Drop */
- pkt_cnt--;
- }
- else if (odp_unlikely(i != j++))
- {
- pkt_tbl[j-1] = pkt;
- }
+ if (odp_unlikely (odp_packet_has_error (pkt)))
+ {
+ odp_packet_free (pkt); /* Drop */
+ pkt_cnt--;
+ }
+ else if (odp_unlikely (i != j++))
+ {
+ pkt_tbl[j - 1] = pkt;
+ }
}
return pkt_cnt;
}
static odp_pktio_t
-create_pktio(const char *dev, odp_pool_t pool, u32 mode)
+create_pktio (const char *dev, odp_pool_t pool, u32 mode)
{
odp_pktio_t pktio;
int ret;
odp_pktio_param_t pktio_param;
odp_pktin_queue_param_t pktin_param;
- odp_pktio_param_init(&pktio_param);
+ odp_pktio_param_init (&pktio_param);
- switch(mode)
+ switch (mode)
{
- case APPL_MODE_PKT_BURST:
+ case APPL_MODE_PKT_BURST:
pktio_param.in_mode = ODP_PKTIN_MODE_DIRECT;
break;
- case APPL_MODE_PKT_QUEUE:
+ case APPL_MODE_PKT_QUEUE:
pktio_param.in_mode = ODP_PKTIN_MODE_QUEUE;
break;
- case APPL_MODE_PKT_SCHED:
+ case APPL_MODE_PKT_SCHED:
pktio_param.in_mode = ODP_PKTIN_MODE_SCHED;
break;
- default:
- clib_warning("Invalid mode\n");
+ default:
+ clib_warning ("Invalid mode\n");
}
/* Open a packet IO instance */
- pktio = odp_pktio_open(dev, pool, &pktio_param);
+ pktio = odp_pktio_open (dev, pool, &pktio_param);
if (pktio == ODP_PKTIO_INVALID)
{
- clib_warning("Error: pktio create failed for %s",dev);
+ clib_warning ("Error: pktio create failed for %s", dev);
}
- odp_pktin_queue_param_init(&pktin_param);
+ odp_pktin_queue_param_init (&pktin_param);
if (mode == APPL_MODE_PKT_SCHED)
pktin_param.queue_param.sched.sync = ODP_SCHED_SYNC_ATOMIC;
- if (odp_pktin_queue_config(pktio, &pktin_param))
+ if (odp_pktin_queue_config (pktio, &pktin_param))
{
- clib_warning("Error: pktin config failed");
+ clib_warning ("Error: pktin config failed");
}
- if (odp_pktout_queue_config(pktio, NULL))
+ if (odp_pktout_queue_config (pktio, NULL))
{
- clib_warning("Error: pktout config failed");
+ clib_warning ("Error: pktout config failed");
}
- ret = odp_pktio_start(pktio);
+ ret = odp_pktio_start (pktio);
if (ret != 0)
{
- clib_warning("Error: unable to start");
+ clib_warning ("Error: unable to start");
}
return pktio;
@@ -132,30 +121,30 @@ odp_worker_thread_enable ()
/*If worker threads are enabled, switch to polling mode */
foreach_vlib_main ((
- {
- vlib_node_set_state (this_vlib_main,
- odp_packet_input_node.index,
- VLIB_NODE_STATE_POLLING);
- }));
+ {
+ vlib_node_set_state (this_vlib_main,
+ odp_packet_input_node.index,
+ VLIB_NODE_STATE_POLLING);
+ }));
return 0;
}
int
odp_worker_thread_disable ()
{
- foreach_vlib_main ((
- {
- vlib_node_set_state (this_vlib_main,
- odp_packet_input_node.index,
- VLIB_NODE_STATE_DISABLED);
- }));
+ foreach_vlib_main ((
+ {
+ vlib_node_set_state (this_vlib_main,
+ odp_packet_input_node.index,
+ VLIB_NODE_STATE_DISABLED);
+ }));
return 0;
}
u32
odp_packet_create_if (vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set,
- u32 * sw_if_index , u32 mode)
+ u32 * sw_if_index, u32 mode)
{
odp_packet_main_t *om = &odp_packet_main;
int ret = 0;
@@ -165,8 +154,8 @@ odp_packet_create_if (vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set,
vnet_sw_interface_t *sw;
vnet_main_t *vnm = vnet_get_main ();
uword *p;
- u8 *host_if_name_dup=vec_dup(host_if_name);
- vlib_thread_main_t *tm= vlib_get_thread_main();
+ u8 *host_if_name_dup = vec_dup (host_if_name);
+ vlib_thread_main_t *tm = vlib_get_thread_main ();
p = mhash_get (&om->if_index_by_host_if_name, host_if_name);
if (p)
@@ -175,17 +164,17 @@ odp_packet_create_if (vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set,
pool_get (om->interfaces, oif);
oif->if_index = oif - om->interfaces;
oif->host_if_name = host_if_name_dup;
- oif->per_interface_next_index= ~0;
+ oif->per_interface_next_index = ~0;
/* Create a pktio instance */
- oif->pktio=create_pktio((char*)host_if_name, om->pool, mode);
- oif->mode=mode;
+ oif->pktio = create_pktio ((char *) host_if_name, om->pool, mode);
+ oif->mode = mode;
om->if_count++;
if (tm->n_vlib_mains > 1)
{
oif->lockp = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
- CLIB_CACHE_LINE_BYTES);
+ CLIB_CACHE_LINE_BYTES);
memset ((void *) oif->lockp, 0, CLIB_CACHE_LINE_BYTES);
}
@@ -205,7 +194,9 @@ odp_packet_create_if (vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set,
}
error = ethernet_register_interface (vnm, odp_packet_device_class.index,
- oif->if_index, hw_addr, &oif->hw_if_index, odp_packet_eth_flag_change);
+ oif->if_index, hw_addr,
+ &oif->hw_if_index,
+ odp_packet_eth_flag_change);
if (error)
{
@@ -222,24 +213,24 @@ odp_packet_create_if (vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set,
vnet_hw_interface_set_flags (vnm, oif->hw_if_index,
VNET_HW_INTERFACE_FLAG_LINK_UP);
- mhash_set_mem (&om->if_index_by_host_if_name, host_if_name_dup, &oif->if_index,
- 0);
+ mhash_set_mem (&om->if_index_by_host_if_name, host_if_name_dup,
+ &oif->if_index, 0);
if (sw_if_index)
*sw_if_index = oif->sw_if_index;
if (tm->n_vlib_mains > 1 && pool_elts (om->interfaces) == 1)
{
- /*Fixme :Workers support commented for now as vlib_buffer not thread safe*/
+ /*Fixme :Workers support commented for now as vlib_buffer not thread safe */
//odp_worker_thread_enable ();
}
- else
+ else
{
- vlib_node_set_state (vm, odp_packet_input_node.index,
- VLIB_NODE_STATE_POLLING);
+ vlib_node_set_state (vm, odp_packet_input_node.index,
+ VLIB_NODE_STATE_POLLING);
}
return 0;
- error:
+error:
vec_free (host_if_name_dup);
return ret;
@@ -252,7 +243,7 @@ odp_packet_delete_if (vlib_main_t * vm, u8 * host_if_name)
odp_packet_main_t *om = &odp_packet_main;
odp_packet_if_t *oif = 0;
uword *p;
- vlib_thread_main_t *tm= vlib_get_thread_main();
+ vlib_thread_main_t *tm = vlib_get_thread_main ();
p = mhash_get (&om->if_index_by_host_if_name, host_if_name);
@@ -267,8 +258,8 @@ odp_packet_delete_if (vlib_main_t * vm, u8 * host_if_name)
om->if_count--;
- odp_pktio_stop(odp_pktio_lookup((char*)host_if_name));
- odp_pktio_close(odp_pktio_lookup((char*)host_if_name));
+ odp_pktio_stop (odp_pktio_lookup ((char *) host_if_name));
+ odp_pktio_close (odp_pktio_lookup ((char *) host_if_name));
vec_free (oif->host_if_name);
oif->host_if_name = NULL;
@@ -276,12 +267,12 @@ odp_packet_delete_if (vlib_main_t * vm, u8 * host_if_name)
mhash_unset (&om->if_index_by_host_if_name, host_if_name, &oif->if_index);
ethernet_delete_interface (vnm, oif->hw_if_index);
- pool_put(om->interfaces, oif);
+ pool_put (om->interfaces, oif);
if (tm->n_vlib_mains > 1 && pool_elts (om->interfaces) == 0)
{
- odp_pool_destroy(om->pool);
- /*Fixme :Workers support commented for now*/
+ odp_pool_destroy (om->pool);
+ /*Fixme :Workers support commented for now */
// odp_worker_thread_disable ();
}
@@ -299,49 +290,49 @@ odp_packet_init (vlib_main_t * vm)
odp_platform_init_t platform_params;
odp_pool_param_t params;
- memset(om, 0, sizeof(odp_packet_main_t));
+ memset (om, 0, sizeof (odp_packet_main_t));
om->input_cpu_first_index = 0;
om->input_cpu_count = 1;
om->if_count = 0;
- memset(&platform_params, 0, sizeof(platform_params));
+ memset (&platform_params, 0, sizeof (platform_params));
- if (odp_init_global(&om->instance, NULL, &platform_params))
- clib_warning("Error:ODP global init failed");
+ if (odp_init_global (&om->instance, NULL, &platform_params))
+ clib_warning ("Error:ODP global init failed");
- if (odp_init_local(om->instance, ODP_THREAD_CONTROL) != 0)
+ if (odp_init_local (om->instance, ODP_THREAD_CONTROL) != 0)
{
- clib_warning("Error: ODP local init failed");
- odp_term_global(om->instance);
+ clib_warning ("Error: ODP local init failed");
+ odp_term_global (om->instance);
}
/* Create packet pool */
- odp_pool_param_init(&params);
+ odp_pool_param_init (&params);
params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE;
- params.pkt.len = SHM_PKT_POOL_BUF_SIZE;
- params.type = ODP_POOL_PACKET;
- params.pkt.num = SHM_PKT_POOL_NB_PKTS;
+ params.pkt.len = SHM_PKT_POOL_BUF_SIZE;
+ params.type = ODP_POOL_PACKET;
+ params.pkt.num = SHM_PKT_POOL_NB_PKTS;
- om->pool = odp_pool_create(SHM_PKT_POOL_NAME, &params);
+ om->pool = odp_pool_create (SHM_PKT_POOL_NAME, &params);
if (om->pool == ODP_POOL_INVALID)
{
- clib_warning("Error: packet pool create failed");
+ clib_warning ("Error: packet pool create failed");
}
/* find out which cpus will be used for input */
- p = hash_get_mem (tm->thread_registrations_by_name, "workers");
- tr = p ? (vlib_thread_registration_t *) p[0] : 0;
+ p = hash_get_mem (tm->thread_registrations_by_name, "workers");
+ tr = p ? (vlib_thread_registration_t *) p[0] : 0;
if (tr && tr->count > 0)
{
- om->input_cpu_first_index = tr->first_index;
- om->input_cpu_count = tr->count;
+ om->input_cpu_first_index = tr->first_index;
+ om->input_cpu_count = tr->count;
}
mhash_init_vec_string (&om->if_index_by_host_if_name, sizeof (uword));
vec_validate_aligned (om->rx_buffers, tm->n_vlib_mains - 1,
- CLIB_CACHE_LINE_BYTES);
+ CLIB_CACHE_LINE_BYTES);
return 0;
}
diff --git a/src/plugins/odp/odp_packet.h b/src/plugins/odp/odp_packet.h
index 3ece9627..32c31f8f 100755
--- a/src/plugins/odp/odp_packet.h
+++ b/src/plugins/odp/odp_packet.h
@@ -1,18 +1,7 @@
-/*
- *------------------------------------------------------------------
- * Copyright (c) 2016 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
+/* Copyright (c) 2017, Linaro Limited
+ * All rights reserved.
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *------------------------------------------------------------------
+ * SPDX-License-Identifier: BSD-3-Clause
*/
#include <odp_api.h>
@@ -60,10 +49,10 @@ extern vnet_device_class_t odp_packet_device_class;
extern vlib_node_registration_t odp_packet_input_node;
u32 odp_packet_create_if (vlib_main_t * vm, u8 * host_if_name,
- u8 * hw_addr_set, u32 * sw_if_index, u32 mode);
+ u8 * hw_addr_set, u32 * sw_if_index, u32 mode);
u32 odp_packet_delete_if (vlib_main_t * vm, u8 * host_if_name);
-u32 drop_err_pkts(odp_packet_t pkt_tbl[], u32 len);
+u32 drop_err_pkts (odp_packet_t pkt_tbl[], u32 len);
/*
* fd.io coding-style-patch-verification: ON