Using the mailbox, which serves as the control message channel between driver and CoreNIC firmware.
Signed-off-by: Chaoyong He <chaoyong...@corigine.com> Reviewed-by: Long Wu <long...@corigine.com> Reviewed-by: Peng Zhang <peng.zh...@corigine.com> --- drivers/net/nfp/meson.build | 1 + drivers/net/nfp/nfp_net_cmsg.c | 66 ++++++++++++++++++++++++++++++++++ drivers/net/nfp/nfp_net_cmsg.h | 37 +++++++++++++++++++ drivers/net/nfp/nfp_net_ctrl.h | 1 + 4 files changed, 105 insertions(+) create mode 100644 drivers/net/nfp/nfp_net_cmsg.c create mode 100644 drivers/net/nfp/nfp_net_cmsg.h diff --git a/drivers/net/nfp/meson.build b/drivers/net/nfp/meson.build index 0d0a0bd8f4..46be6f60cd 100644 --- a/drivers/net/nfp/meson.build +++ b/drivers/net/nfp/meson.build @@ -34,6 +34,7 @@ sources = files( 'nfp_ipsec.c', 'nfp_logs.c', 'nfp_mtr.c', + 'nfp_net_cmsg.c', 'nfp_net_common.c', 'nfp_net_ctrl.c', 'nfp_net_flow.c', diff --git a/drivers/net/nfp/nfp_net_cmsg.c b/drivers/net/nfp/nfp_net_cmsg.c new file mode 100644 index 0000000000..f2f694be0b --- /dev/null +++ b/drivers/net/nfp/nfp_net_cmsg.c @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#include "nfp_net_cmsg.h" + +#include <rte_malloc.h> + +#include "nfp_logs.h" + +struct nfp_net_cmsg * +nfp_net_cmsg_alloc(uint32_t msg_size) +{ + struct nfp_net_cmsg *cmsg; + + cmsg = rte_zmalloc(NULL, msg_size, 0); + if (cmsg == NULL) { + PMD_DRV_LOG(ERR, "Failed malloc memory."); + return NULL; + } + + return cmsg; +} + +void +nfp_net_cmsg_free(struct nfp_net_cmsg *cmsg) +{ + rte_free(cmsg); +} + +int +nfp_net_cmsg_xmit(struct nfp_net_hw *hw, + struct nfp_net_cmsg *cmsg, + uint32_t msg_size) +{ + int ret; + uint32_t i; + + for (i = 0; i < msg_size; i++) + nn_cfg_writel(&hw->super, NFP_NET_CFG_MBOX_VAL + 4 * i, *((uint32_t *)cmsg + i)); + + ret = nfp_net_mbox_reconfig(hw, NFP_NET_CFG_MBOX_CMD_FLOW_STEER); + switch (ret) { + case NFP_NET_CFG_MBOX_RET_FS_OK: + break; + case NFP_NET_CFG_MBOX_RET_FS_ERR_NO_SPACE: + PMD_DRV_LOG(ERR, "Not enough space for cmd %u", cmsg->cmd); + ret = -ENOSPC; + break; + case NFP_NET_CFG_MBOX_RET_FS_ERR_MASK_FULL: + PMD_DRV_LOG(ERR, "The mask table is full for cmd %u", cmsg->cmd); + ret = -EXFULL; + break; + case NFP_NET_CFG_MBOX_RET_FS_ERR_CMD_INVALID: + PMD_DRV_LOG(ERR, "The mbox cmd %u invalid", cmsg->cmd); + ret = -EINVAL; + break; + default: + PMD_DRV_LOG(ERR, "Unrecognized mbox cmd %u", cmsg->cmd); + ret = -EINVAL; + break; + } + + return ret; +} diff --git a/drivers/net/nfp/nfp_net_cmsg.h b/drivers/net/nfp/nfp_net_cmsg.h new file mode 100644 index 0000000000..15e0bb60d8 --- /dev/null +++ b/drivers/net/nfp/nfp_net_cmsg.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2023 Corigine, Inc. + * All rights reserved. + */ + +#ifndef __NFP_NET_CMSG_H__ +#define __NFP_NET_CMSG_H__ + +#include "nfp_net_common.h" + +enum nfp_net_cfg_mbox_cmd { + NFP_NET_CFG_MBOX_CMD_FS_ADD_V4, /* Add Flow Steer rule for V4 table */ + NFP_NET_CFG_MBOX_CMD_FS_DEL_V4, /* Delete Flow Steer rule for V4 table */ + NFP_NET_CFG_MBOX_CMD_FS_ADD_V6, /* Add Flow Steer rule for V4 table */ + NFP_NET_CFG_MBOX_CMD_FS_DEL_V6, /* Delete Flow Steer rule for V4 table */ + NFP_NET_CFG_MBOX_CMD_FS_ADD_ETHTYPE, /* Add Flow Steer rule for Ethtype table */ + NFP_NET_CFG_MBOX_CMD_FS_DEL_ETHTYPE, /* Delete Flow Steer rule for Ethtype table */ +}; + +enum nfp_net_cfg_mbox_ret { + NFP_NET_CFG_MBOX_RET_FS_OK, /* No error happen */ + NFP_NET_CFG_MBOX_RET_FS_ERR_NO_SPACE, /* Return error code no space */ + NFP_NET_CFG_MBOX_RET_FS_ERR_MASK_FULL, /* Return error code mask table full */ + NFP_NET_CFG_MBOX_RET_FS_ERR_CMD_INVALID, /* Return error code invalid cmd */ +}; + +/* 4B cmd, and up to 500B data. */ +struct nfp_net_cmsg { + uint32_t cmd; /**< One of nfp_net_cfg_mbox_cmd */ + uint32_t data[0]; +}; + +struct nfp_net_cmsg *nfp_net_cmsg_alloc(uint32_t msg_size); +void nfp_net_cmsg_free(struct nfp_net_cmsg *cmsg); +int nfp_net_cmsg_xmit(struct nfp_net_hw *hw, struct nfp_net_cmsg *cmsg, uint32_t msg_size); + +#endif /* __NFP_NET_CMSG_H__ */ diff --git a/drivers/net/nfp/nfp_net_ctrl.h b/drivers/net/nfp/nfp_net_ctrl.h index ee1b784bb1..7ac0f89571 100644 --- a/drivers/net/nfp/nfp_net_ctrl.h +++ b/drivers/net/nfp/nfp_net_ctrl.h @@ -92,6 +92,7 @@ #define NFP_NET_CFG_MBOX_SIMPLE_VAL 0x8 #define NFP_NET_CFG_MBOX_CMD_IPSEC 3 +#define NFP_NET_CFG_MBOX_CMD_FLOW_STEER 10 /* * TLV capabilities -- 2.39.1