diff options
author | Jianlin Lv <Jianlin.Lv@arm.com> | 2019-10-30 13:35:38 +0800 |
---|---|---|
committer | Andrew Yourtchenko <ayourtch@gmail.com> | 2019-11-07 13:32:36 +0000 |
commit | 1c3c9f0393e4bd3a5902efbc79cb9a4e6737bda2 (patch) | |
tree | f32b6a8449377e18bd95370039e28649a2992a05 | |
parent | 387123e675c222b52f720b6fd5ac0c7b3f016bcd (diff) |
api: Add API support for PP2 plugin to stable/1908
Support create/delete interface with marvell PP2 API
Type: feature
Signed-off-by: Jianlin Lv <Jianlin.Lv@arm.com>
Change-Id: I2a81024e0fcf2f389d39a5498167a752f8f807e5
-rw-r--r-- | src/plugins/marvell/CMakeLists.txt | 11 | ||||
-rw-r--r-- | src/plugins/marvell/pp2/cli.c | 3 | ||||
-rw-r--r-- | src/plugins/marvell/pp2/pp2.api | 70 | ||||
-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_all_api_h.h | 16 | ||||
-rw-r--r-- | src/plugins/marvell/pp2/pp2_api.c | 192 | ||||
-rw-r--r-- | src/plugins/marvell/pp2/pp2_msg_enum.h | 39 | ||||
-rw-r--r-- | src/plugins/marvell/pp2/pp2_test.c | 245 |
9 files changed, 583 insertions, 1 deletions
diff --git a/src/plugins/marvell/CMakeLists.txt b/src/plugins/marvell/CMakeLists.txt index 4e4b76886fa..a3fcee69050 100644 --- a/src/plugins/marvell/CMakeLists.txt +++ b/src/plugins/marvell/CMakeLists.txt @@ -29,6 +29,17 @@ 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 + + INSTALL_HEADERS + pp2/pp2_all_api_h.h + pp2/pp2_msg_enum.h 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..f40cdc0615c --- /dev/null +++ b/src/plugins/marvell/pp2/pp2.api @@ -0,0 +1,70 @@ +/* + *------------------------------------------------------------------ + * 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; +}; + +/** \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; +}; + +/* + * 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_all_api_h.h b/src/plugins/marvell/pp2/pp2_all_api_h.h new file mode 100644 index 00000000000..1efc02b9018 --- /dev/null +++ b/src/plugins/marvell/pp2/pp2_all_api_h.h @@ -0,0 +1,16 @@ +/* + * 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 the generated file, see BUILT_SOURCES in Makefile.am */ +#include <marvell/pp2/pp2.api.h> diff --git a/src/plugins/marvell/pp2/pp2_api.c b/src/plugins/marvell/pp2/pp2_api.c new file mode 100644 index 00000000000..e31111869b4 --- /dev/null +++ b/src/plugins/marvell/pp2/pp2_api.c @@ -0,0 +1,192 @@ +/* + *------------------------------------------------------------------ + * 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_msg_enum.h> + +/* define message structures */ +#define vl_typedefs +#include <marvell/pp2/pp2_all_api_h.h> +#undef vl_typedefs + +/* define generated endian-swappers */ +#define vl_endianfun +#include <marvell/pp2/pp2_all_api_h.h> +#undef vl_endianfun + +/* instantiate all the print functions we know about */ +#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) + +/* get the API version number */ +#define vl_api_version(n,v) static u32 api_version=(v); +#include <marvell/pp2/pp2_all_api_h.h> +#undef vl_api_version + +/* Macro to finish up custom dump fns */ +#define FINISH \ + vec_add1 (s, 0); \ + vl_print (handle, (char *)s); \ + vec_free (s); \ + return handle; + +#include <vlibapi/api_helper_macros.h> + +#define foreach_pp2_plugin_api_msg \ +_(MRVL_PP2_CREATE, mrvl_pp2_create) \ +_(MRVL_PP2_DELETE, mrvl_pp2_delete) + + +#define vl_msg_name_crc_list +#include <marvell/pp2/pp2_all_api_h.h> +#undef vl_msg_name_crc_list + +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_create_t_print (vl_api_mrvl_pp2_create_t * mp, void *handle) +{ + u8 *s; + s = format (0, "SCRIPT: mrvl_pp2_create "); + s = format (s, "if_name:%s ", mp->if_name); + if (mp->rx_q_sz) + s = format (s, "rx-queue-size:%u ", ntohs (mp->rx_q_sz)); + if (mp->tx_q_sz) + s = format (s, "tx-queue-size %u ", ntohs (mp->tx_q_sz)); + + FINISH; +} + +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); +} + +static void * +vl_api_mrvl_pp2_delete_t_print (vl_api_mrvl_pp2_delete_t * mp, void *handle) +{ + u8 *s; + + s = format (0, "SCRIPT: mrvl_pp2_delete "); + s = format (s, "sw_if_index %d ", ntohl (mp->sw_if_index)); + + FINISH; +} + + +static void +setup_message_id_table (mrvl_pp2_main_t * pp2, api_main_t * am) +{ +#define _(id,n,crc) \ + vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + pp2->msg_id_base); + foreach_vl_msg_name_crc_pp2; +#undef _ +} + + +/* 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; + api_main_t *am = &api_main; + u8 *name; + + /* construct the API name */ + name = format (0, "mrvl_pp2_%08x%c", api_version, 0); + + /* ask for a correctly-sized block of API message decode slots */ + pp2->msg_id_base = vl_msg_api_get_msg_ids + ((char *) name, VL_MSG_FIRST_AVAILABLE); + +#define _(N,n) \ + vl_msg_api_set_handlers((VL_API_##N + pp2->msg_id_base), \ + #n, \ + vl_api_##n##_t_handler, \ + vl_noop_handler, \ + vl_api_##n##_t_endian, \ + vl_api_##n##_t_print, \ + sizeof(vl_api_##n##_t), 1); + foreach_pp2_plugin_api_msg; +#undef _ + + /* set up the (msg_name, crc, message-id) table */ + setup_message_id_table (pp2, am); + + vec_free (name); + 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_msg_enum.h b/src/plugins/marvell/pp2/pp2_msg_enum.h new file mode 100644 index 00000000000..d38c153668e --- /dev/null +++ b/src/plugins/marvell/pp2/pp2_msg_enum.h @@ -0,0 +1,39 @@ +/* + *------------------------------------------------------------------ + * 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. + *------------------------------------------------------------------ + */ + +#ifndef _PP2_MSG_ENUM_H_ +#define _PP2_MSG_ENUM_H_ + +#include <vppinfra/byte_order.h> + +#define vl_msg_id(n,h) n, +typedef enum +{ +#include <marvell/pp2/pp2_all_api_h.h> + VL_MSG_FIRST_AVAILABLE, +} vl_msg_id_t; +#undef vl_msg_id + +#endif /* MRVL_PP2_MSG_ENUM_H */ + +/* + * 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..ecfdfa30535 --- /dev/null +++ b/src/plugins/marvell/pp2/pp2_test.c @@ -0,0 +1,245 @@ +/* + *------------------------------------------------------------------ + * 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 mrvl_pp2_test_main.msg_id_base +#include <vlibapi/vat_helper_macros.h> + +/* declare message IDs */ +#include <marvell/pp2/pp2_msg_enum.h> + +/* Get CRC codes of the messages defined outside of this plugin */ +#define vl_msg_name_crc_list +#include <vpp/api/vpe_all_api_h.h> +#undef vl_msg_name_crc_list + +/* define message structures */ +#define vl_typedefs +#include <vpp/api/vpe_all_api_h.h> +#include <marvell/pp2/pp2_all_api_h.h> +#undef vl_typedefs + +/* declare message handlers for each api */ +#define vl_endianfun +#include <marvell/pp2/pp2_all_api_h.h> +#undef vl_endianfun + +/* instantiate all the print functions we know about */ +#define vl_print(handle, ...) +#define vl_printfun +#include <marvell/pp2/pp2_all_api_h.h> +#undef vl_printfun + +/* get API version number */ +#define vl_api_version(n,v) static u32 api_version=(v); +#include <marvell/pp2/pp2_all_api_h.h> +#undef vp_api_version + +typedef struct +{ + /* API message ID base */ + u16 msg_id_base; + vat_main_t *vat_main; +} mrvl_pp2_test_main_t; + +mrvl_pp2_test_main_t mrvl_pp2_test_main; + +#define foreach_standard_reply_retval_handler \ +_(mrvl_pp2_delete_reply) + +#define _(n) \ + static void vl_api_##n##_t_handler \ + (vl_api_##n##_t * mp) \ + { \ + vat_main_t * vam = mrvl_pp2_test_main.vat_main; \ + i32 retval = ntohl(mp->retval); \ + if (vam->async_mode) { \ + vam->async_errors += (retval < 0); \ + } else { \ + vam->retval = retval; \ + vam->result_ready = 1; \ + } \ + } +foreach_standard_reply_retval_handler; +#undef _ + +#define foreach_vpe_api_reply_msg \ +_(MRVL_PP2_CREATE_REPLY, mrvl_pp2_create_reply) \ +_(MRVL_PP2_DELETE_REPLY, mrvl_pp2_delete_reply) + +/* 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), ARRAY_LEN (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 = mrvl_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; +} + +/* + * List of messages that the api test plugin sends, + * and that the data plane plugin processes + */ +#define foreach_vpe_api_msg \ +_(mrvl_pp2_create, "[name <ifname>] [rx-queue-size <size>]" \ + "[tx-queue-size <size>]") \ +_(mrvl_pp2_delete, "[sw_if_index <sw_if_index>]") + +static void +mrvl_pp2_vat_api_hookup (vat_main_t * vam) +{ + mrvl_pp2_test_main_t *pp2 __attribute__ ((unused)) = &mrvl_pp2_test_main; +#define _(N,n) \ + vl_msg_api_set_handlers((VL_API_##N + pp2->msg_id_base), \ + #n, \ + vl_api_##n##_t_handler, \ + vl_noop_handler, \ + vl_api_##n##_t_endian, \ + vl_api_##n##_t_print, \ + sizeof(vl_api_##n##_t), 1); + foreach_vpe_api_reply_msg; +#undef _ + +#define _(n,h) \ + hash_set_mem (vam->function_by_name, #n, api_##n); + foreach_vpe_api_msg; +#undef _ + +#define _(n,h) hash_set_mem (vam->help_by_name, #n, h); + foreach_vpe_api_msg; +#undef _ +} + +clib_error_t * +vat_plugin_register (vat_main_t * vam) +{ + mrvl_pp2_test_main_t *pp2 = &mrvl_pp2_test_main; + u8 *name; + + pp2->vat_main = vam; + + name = format (0, "mrvl_pp2_%08x%c", api_version, 0); + pp2->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name); + vec_free (name); + + if (pp2->msg_id_base == (u16) ~ 0) + return clib_error_return (0, "mrvl_pp2 plugin not loaded..."); + + mrvl_pp2_vat_api_hookup (vam); + + return 0; +} + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ |