diff options
author | Jianlin Lv <Jianlin.Lv@arm.com> | 2019-09-27 09:35:41 +0800 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2019-10-07 20:22:00 +0000 |
commit | 859b59133c143b09fed86af1d409d320fa45424f (patch) | |
tree | f06e0a48070ce080c893f8b673574d5addacf586 /src | |
parent | 3a1ef47c39eacdb2177cedca48db543d1c514f9c (diff) |
api: Add API support for marvell PP2 plugin
Support create/delete interface with PP2 api
Type: feature
Signed-off-by: Jianlin Lv <Jianlin.Lv@arm.com>
Change-Id: Ia9c0ac0f237fd9f71f5480d736d6bcabee763fff
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/marvell/CMakeLists.txt | 7 | ||||
-rw-r--r-- | src/plugins/marvell/pp2/cli.c | 3 | ||||
-rw-r--r-- | src/plugins/marvell/pp2/pp2.api | 72 | ||||
-rw-r--r-- | src/plugins/marvell/pp2/pp2.c | 1 | ||||
-rw-r--r-- | src/plugins/marvell/pp2/pp2.h | 7 | ||||
-rw-r--r-- | src/plugins/marvell/pp2/pp2_api.c | 103 | ||||
-rw-r--r-- | src/plugins/marvell/pp2/pp2_test.c | 144 |
7 files changed, 336 insertions, 1 deletions
diff --git a/src/plugins/marvell/CMakeLists.txt b/src/plugins/marvell/CMakeLists.txt index 4e4b76886fa..336d4d6c4a3 100644 --- a/src/plugins/marvell/CMakeLists.txt +++ b/src/plugins/marvell/CMakeLists.txt @@ -29,6 +29,13 @@ if(MUSDK_INCLUDE_DIR AND MUSDK_LIB) pp2/input.c pp2/output.c pp2/pp2.c + pp2/pp2_api.c + + API_FILES + pp2/pp2.api + + API_TEST_SOURCES + pp2/pp2_test.c LINK_FLAGS ${MUSDK_LINK_FLAGS} diff --git a/src/plugins/marvell/pp2/cli.c b/src/plugins/marvell/pp2/cli.c index 761cdb5b6b6..345b237e45a 100644 --- a/src/plugins/marvell/pp2/cli.c +++ b/src/plugins/marvell/pp2/cli.c @@ -117,6 +117,9 @@ VLIB_CLI_COMMAND (mrvl_pp2_delete_command, static) = { clib_error_t * mrvl_pp2_cli_init (vlib_main_t * vm) { + /* initialize binary API */ + mrvl_pp2_plugin_api_hookup (vm); + return 0; } diff --git a/src/plugins/marvell/pp2/pp2.api b/src/plugins/marvell/pp2/pp2.api new file mode 100644 index 00000000000..2925e69691a --- /dev/null +++ b/src/plugins/marvell/pp2/pp2.api @@ -0,0 +1,72 @@ +/* + *------------------------------------------------------------------ + * Copyright (c) 2019 Arm Limited. + * 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 + * + * 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. + *------------------------------------------------------------------ + */ + +option version = "1.0.0"; + + +/** \brief + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param if_name - interface name + @param rx_q_sz - receive queue size + @param tx_q_sz - transmit queue size +*/ +define mrvl_pp2_create +{ + u32 client_index; + u32 context; + + u8 if_name[64]; + u16 rx_q_sz; + u16 tx_q_sz; + option vat_help = "[name <ifname>] [rx-queue-size <size>] [tx-queue-size <size>]"; +}; + +/** \brief + @param context - sender context, to match reply w/ request + @param retval - return value for request + @param sw_if_index - software index for the new pp2 interface +*/ + +define mrvl_pp2_create_reply +{ + u32 context; + i32 retval; + u32 sw_if_index; +}; + + +/** \brief + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param sw_if_index - interface index +*/ + +autoreply define mrvl_pp2_delete +{ + u32 client_index; + u32 context; + + u32 sw_if_index; + option vat_help = "sw_if_index <sw_if_index>"; +}; + +/* + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/marvell/pp2/pp2.c b/src/plugins/marvell/pp2/pp2.c index 411e28b212b..36b191a178b 100644 --- a/src/plugins/marvell/pp2/pp2.c +++ b/src/plugins/marvell/pp2/pp2.c @@ -300,6 +300,7 @@ mrvl_pp2_create_if (mrvl_pp2_create_if_args_t * args) sw = vnet_get_hw_sw_interface (vnm, ppif->hw_if_index); ppif->sw_if_index = sw->sw_if_index; ppif->per_interface_next_index = ~0; + args->sw_if_index = sw->sw_if_index; vnet_hw_interface_set_input_node (vnm, ppif->hw_if_index, mrvl_pp2_input_node.index); vnet_hw_interface_assign_rx_thread (vnm, ppif->hw_if_index, 0, ~0); diff --git a/src/plugins/marvell/pp2/pp2.h b/src/plugins/marvell/pp2/pp2.h index 93b95aa134b..f8fb78f50be 100644 --- a/src/plugins/marvell/pp2/pp2.h +++ b/src/plugins/marvell/pp2/pp2.h @@ -78,6 +78,9 @@ typedef struct { mrvl_pp2_if_t *interfaces; mrvl_pp2_per_thread_data_t *per_thread_data; + + /* API message ID base */ + u16 msg_id_base; } mrvl_pp2_main_t; extern vnet_device_class_t mrvl_pp2_device_class; @@ -90,12 +93,14 @@ typedef struct u16 tx_q_sz; /* return */ - int rv; + i32 rv; + u32 sw_if_index; clib_error_t *error; } mrvl_pp2_create_if_args_t; void mrvl_pp2_create_if (mrvl_pp2_create_if_args_t * args); void mrvl_pp2_delete_if (mrvl_pp2_if_t * dfif); +clib_error_t *mrvl_pp2_plugin_api_hookup (vlib_main_t * vm); /* output.c */ diff --git a/src/plugins/marvell/pp2/pp2_api.c b/src/plugins/marvell/pp2/pp2_api.c new file mode 100644 index 00000000000..a3672c442d4 --- /dev/null +++ b/src/plugins/marvell/pp2/pp2_api.c @@ -0,0 +1,103 @@ +/* + *------------------------------------------------------------------ + * Copyright (c) 2019 Arm Limited. + * 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 + * + * 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. + *------------------------------------------------------------------ + */ + +#include <vlib/vlib.h> +#include <vlib/unix/unix.h> +#include <vnet/ethernet/ethernet.h> + +#include <marvell/pp2/pp2.h> + +#include <vlibapi/api.h> +#include <vlibmemory/api.h> + +/* define message IDs */ +#include <marvell/pp2/pp2.api_enum.h> +#include <marvell/pp2/pp2.api_types.h> + +#include <vlibapi/api_helper_macros.h> + +static void +vl_api_mrvl_pp2_create_t_handler (vl_api_mrvl_pp2_create_t * mp) +{ + mrvl_pp2_main_t *pp2 = &mrvl_pp2_main; + mrvl_pp2_create_if_args_t args = { 0 }; + vl_api_mrvl_pp2_create_reply_t *rmp; + int rv; + + args.name = format (0, "%s", mp->if_name); + args.rx_q_sz = ntohs (mp->rx_q_sz); + args.tx_q_sz = ntohs (mp->tx_q_sz); + mrvl_pp2_create_if (&args); + rv = args.rv; + vec_free (args.name); + if (args.error) + { + clib_error_free (args.error); + } + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_MRVL_PP2_CREATE_REPLY + pp2->msg_id_base, + ({ + rmp->sw_if_index = ntohl (args.sw_if_index); + })); + /* *INDENT-ON* */ +} + +static void +vl_api_mrvl_pp2_delete_t_handler (vl_api_mrvl_pp2_delete_t * mp) +{ + vnet_main_t *vnm = vnet_get_main (); + vnet_hw_interface_t *hw; + mrvl_pp2_main_t *pp2 = &mrvl_pp2_main; + vl_api_mrvl_pp2_delete_reply_t *rmp; + mrvl_pp2_if_t *dif; + int rv = 0; + mp->sw_if_index = ntohl (mp->sw_if_index); + hw = vnet_get_sup_hw_interface (vnm, mp->sw_if_index); + if (hw == NULL || mrvl_pp2_device_class.index != hw->dev_class_index) + { + rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; + goto reply; + } + + dif = pool_elt_at_index (pp2->interfaces, hw->dev_instance); + + mrvl_pp2_delete_if (dif); + +reply: + REPLY_MACRO (VL_API_MRVL_PP2_DELETE_REPLY + pp2->msg_id_base); +} + +#include <marvell/pp2/pp2.api.c> +/* set up the API message handling tables */ +clib_error_t * +mrvl_pp2_plugin_api_hookup (vlib_main_t * vm) +{ + mrvl_pp2_main_t *pp2 = &mrvl_pp2_main; + + /* ask for a correctly-sized block of API message decode slots */ + pp2->msg_id_base = setup_message_id_table (); + + return 0; +} + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/marvell/pp2/pp2_test.c b/src/plugins/marvell/pp2/pp2_test.c new file mode 100644 index 00000000000..26a9e9a6e34 --- /dev/null +++ b/src/plugins/marvell/pp2/pp2_test.c @@ -0,0 +1,144 @@ +/* + *------------------------------------------------------------------ + * Copyright (c) 2019 Arm Limited. + * 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 + * + * 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. + *------------------------------------------------------------------ + */ + +#include <vlib/vlib.h> +#include <vlib/unix/unix.h> +#include <vnet/ethernet/ethernet.h> + +#include <vat/vat.h> +#include <vlibapi/api.h> +#include <vlibmemory/api.h> + +#include <vppinfra/error.h> +#include <marvell/pp2/pp2.h> + +#define __plugin_msg_base pp2_test_main.msg_id_base +#include <vlibapi/vat_helper_macros.h> + +/* declare message IDs */ +#include <marvell/pp2/pp2.api_enum.h> +#include <marvell/pp2/pp2.api_types.h> + +typedef struct +{ + /* API message ID base */ + u16 msg_id_base; + vat_main_t *vat_main; +} pp2_test_main_t; + +pp2_test_main_t pp2_test_main; + +/* mrvl_pp2 create API */ +static int +api_mrvl_pp2_create (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_mrvl_pp2_create_t *mp; + mrvl_pp2_create_if_args_t args; + int ret; + u16 size; + + clib_memset (&args, 0, sizeof (mrvl_pp2_create_if_args_t)); + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "name %s", &args.name)) + ; + else if (unformat (i, "rx-queue-size %u", &size)) + args.rx_q_sz = size; + else if (unformat (i, "tx-queue-size %u", &size)) + args.tx_q_sz = size; + else + { + clib_warning ("unknown input '%U'", format_unformat_error, i); + return -99; + } + } + + M (MRVL_PP2_CREATE, mp); + + strncpy_s ((char *) mp->if_name, ARRAY_LEN (mp->if_name), + (char *) (args.name), strlen ((char *) args.name)); + mp->rx_q_sz = clib_host_to_net_u16 (args.rx_q_sz); + mp->tx_q_sz = clib_host_to_net_u16 (args.tx_q_sz); + + S (mp); + W (ret); + + vec_free (args.name); + + return ret; +} + +/* mrvl_pp2 create reply handler */ +static void +vl_api_mrvl_pp2_create_reply_t_handler (vl_api_mrvl_pp2_create_reply_t * mp) +{ + vat_main_t *vam = pp2_test_main.vat_main; + i32 retval = ntohl (mp->retval); + + if (retval == 0) + { + fformat (vam->ofp, "created mrvl_pp2 with sw_if_index %d\n", + ntohl (mp->sw_if_index)); + } + + vam->retval = retval; + vam->result_ready = 1; + vam->regenerate_interface_table = 1; +} + + +/* mrvl_pp2 delete API */ +static int +api_mrvl_pp2_delete (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + //vnet_main_t *vnm = vnet_get_main (); + vl_api_mrvl_pp2_delete_t *mp; + u32 sw_if_index = 0; + int ret; + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "sw_if_index %d", &sw_if_index)) + ; + else + { + clib_warning ("unknown input '%U'", format_unformat_error, i); + return -99; + } + } + + M (MRVL_PP2_DELETE, mp); + + mp->sw_if_index = clib_host_to_net_u32 (sw_if_index); + + S (mp); + W (ret); + + return ret; +} + +#include <marvell/pp2/pp2.api_test.c> + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ |