common/cnxk: add NIX specific NPC operations

Add NIX specific NPC operations such as NPC mac address get/set,
mcast entry add/delete, promiscuous mode enable/disable etc.

Signed-off-by: Sunil Kumar Kori <skori@marvell.com>
Acked-by: Nithin Dabilpuram <ndabilpuram@marvell.com>
This commit is contained in:
Sunil Kumar Kori 2021-04-06 20:11:14 +05:30 committed by Jerin Jacob
parent 313cc41830
commit 1c518ee11e
5 changed files with 237 additions and 0 deletions

View File

@ -18,6 +18,8 @@ sources = files('roc_dev.c',
'roc_nix.c',
'roc_nix_irq.c',
'roc_nix_mac.c',
'roc_nix_mcast.c',
'roc_nix_npc.c',
'roc_nix_queue.c',
'roc_npa.c',
'roc_npa_debug.c',

View File

@ -193,6 +193,18 @@ int __roc_api roc_nix_mac_link_cb_register(struct roc_nix *roc_nix,
link_status_t link_update);
void __roc_api roc_nix_mac_link_cb_unregister(struct roc_nix *roc_nix);
/* NPC */
int __roc_api roc_nix_npc_promisc_ena_dis(struct roc_nix *roc_nix, int enable);
int __roc_api roc_nix_npc_mac_addr_set(struct roc_nix *roc_nix, uint8_t addr[]);
int __roc_api roc_nix_npc_mac_addr_get(struct roc_nix *roc_nix, uint8_t *addr);
int __roc_api roc_nix_npc_rx_ena_dis(struct roc_nix *roc_nix, bool enable);
int __roc_api roc_nix_npc_mcast_config(struct roc_nix *roc_nix,
bool mcast_enable, bool prom_enable);
/* Queue */
int __roc_api roc_nix_rq_init(struct roc_nix *roc_nix, struct roc_nix_rq *rq,
bool ena);
@ -205,4 +217,17 @@ int __roc_api roc_nix_cq_fini(struct roc_nix_cq *cq);
int __roc_api roc_nix_sq_init(struct roc_nix *roc_nix, struct roc_nix_sq *sq);
int __roc_api roc_nix_sq_fini(struct roc_nix_sq *sq);
/* MCAST*/
int __roc_api roc_nix_mcast_mcam_entry_alloc(struct roc_nix *roc_nix,
uint16_t nb_entries,
uint8_t priority,
uint16_t index[]);
int __roc_api roc_nix_mcast_mcam_entry_free(struct roc_nix *roc_nix,
uint32_t index);
int __roc_api roc_nix_mcast_mcam_entry_write(struct roc_nix *roc_nix,
struct mcam_entry *entry,
uint32_t index, uint8_t intf,
uint64_t action);
int __roc_api roc_nix_mcast_mcam_entry_ena_dis(struct roc_nix *roc_nix,
uint32_t index, bool enable);
#endif /* _ROC_NIX_H_ */

View File

@ -0,0 +1,98 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(C) 2021 Marvell.
*/
#include "roc_api.h"
#include "roc_priv.h"
static inline struct mbox *
get_mbox(struct roc_nix *roc_nix)
{
struct nix *nix = roc_nix_to_nix_priv(roc_nix);
struct dev *dev = &nix->dev;
return dev->mbox;
}
int
roc_nix_mcast_mcam_entry_alloc(struct roc_nix *roc_nix, uint16_t nb_entries,
uint8_t priority, uint16_t index[])
{
struct mbox *mbox = get_mbox(roc_nix);
struct npc_mcam_alloc_entry_req *req;
struct npc_mcam_alloc_entry_rsp *rsp;
int rc = -ENOSPC, i;
req = mbox_alloc_msg_npc_mcam_alloc_entry(mbox);
if (req == NULL)
return rc;
req->priority = priority;
req->count = nb_entries;
rc = mbox_process_msg(mbox, (void *)&rsp);
if (rc)
return rc;
for (i = 0; i < rsp->count; i++)
index[i] = rsp->entry_list[i];
return rsp->count;
}
int
roc_nix_mcast_mcam_entry_free(struct roc_nix *roc_nix, uint32_t index)
{
struct mbox *mbox = get_mbox(roc_nix);
struct npc_mcam_free_entry_req *req;
int rc = -ENOSPC;
req = mbox_alloc_msg_npc_mcam_free_entry(mbox);
if (req == NULL)
return rc;
req->entry = index;
return mbox_process_msg(mbox, NULL);
}
int
roc_nix_mcast_mcam_entry_write(struct roc_nix *roc_nix,
struct mcam_entry *entry, uint32_t index,
uint8_t intf, uint64_t action)
{
struct mbox *mbox = get_mbox(roc_nix);
struct npc_mcam_write_entry_req *req;
int rc = -ENOSPC;
req = mbox_alloc_msg_npc_mcam_write_entry(mbox);
if (req == NULL)
return rc;
req->entry = index;
req->intf = intf;
req->enable_entry = true;
mbox_memcpy(&req->entry_data, entry, sizeof(struct mcam_entry));
req->entry_data.action = action;
return mbox_process(mbox);
}
int
roc_nix_mcast_mcam_entry_ena_dis(struct roc_nix *roc_nix, uint32_t index,
bool enable)
{
struct npc_mcam_ena_dis_entry_req *req;
struct mbox *mbox = get_mbox(roc_nix);
int rc = -ENOSPC;
if (enable) {
req = mbox_alloc_msg_npc_mcam_ena_entry(mbox);
if (req == NULL)
return rc;
} else {
req = mbox_alloc_msg_npc_mcam_dis_entry(mbox);
if (req == NULL)
return rc;
}
req->entry = index;
return mbox_process(mbox);
}

View File

@ -0,0 +1,103 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(C) 2021 Marvell.
*/
#include "roc_api.h"
#include "roc_priv.h"
static inline struct mbox *
get_mbox(struct roc_nix *roc_nix)
{
struct nix *nix = roc_nix_to_nix_priv(roc_nix);
struct dev *dev = &nix->dev;
return dev->mbox;
}
int
roc_nix_npc_promisc_ena_dis(struct roc_nix *roc_nix, int enable)
{
struct mbox *mbox = get_mbox(roc_nix);
struct nix_rx_mode *req;
int rc = -ENOSPC;
if (roc_nix_is_vf_or_sdp(roc_nix))
return NIX_ERR_PARAM;
req = mbox_alloc_msg_nix_set_rx_mode(mbox);
if (req == NULL)
return rc;
if (enable)
req->mode = NIX_RX_MODE_UCAST | NIX_RX_MODE_PROMISC;
return mbox_process(mbox);
}
int
roc_nix_npc_mac_addr_set(struct roc_nix *roc_nix, uint8_t addr[])
{
struct mbox *mbox = get_mbox(roc_nix);
struct nix_set_mac_addr *req;
req = mbox_alloc_msg_nix_set_mac_addr(mbox);
mbox_memcpy(req->mac_addr, addr, PLT_ETHER_ADDR_LEN);
return mbox_process(mbox);
}
int
roc_nix_npc_mac_addr_get(struct roc_nix *roc_nix, uint8_t *addr)
{
struct mbox *mbox = get_mbox(roc_nix);
struct nix_get_mac_addr_rsp *rsp;
int rc;
mbox_alloc_msg_nix_get_mac_addr(mbox);
rc = mbox_process_msg(mbox, (void *)&rsp);
if (rc)
return rc;
mbox_memcpy(addr, rsp->mac_addr, PLT_ETHER_ADDR_LEN);
return 0;
}
int
roc_nix_npc_rx_ena_dis(struct roc_nix *roc_nix, bool enable)
{
struct mbox *mbox = get_mbox(roc_nix);
int rc;
if (enable)
mbox_alloc_msg_nix_lf_start_rx(mbox);
else
mbox_alloc_msg_nix_lf_stop_rx(mbox);
rc = mbox_process(mbox);
if (!rc)
roc_nix->io_enabled = enable;
return rc;
}
int
roc_nix_npc_mcast_config(struct roc_nix *roc_nix, bool mcast_enable,
bool prom_enable)
{
struct mbox *mbox = get_mbox(roc_nix);
struct nix_rx_mode *req;
int rc = -ENOSPC;
if (roc_nix_is_vf_or_sdp(roc_nix))
return 0;
req = mbox_alloc_msg_nix_set_rx_mode(mbox);
if (req == NULL)
return rc;
if (mcast_enable)
req->mode = NIX_RX_MODE_ALLMULTI;
else if (prom_enable)
req->mode = NIX_RX_MODE_PROMISC;
return mbox_process(mbox);
}

View File

@ -45,6 +45,15 @@ INTERNAL {
roc_nix_mac_promisc_mode_enable;
roc_nix_mac_rxtx_start_stop;
roc_nix_max_pkt_len;
roc_nix_mcast_mcam_entry_alloc;
roc_nix_mcast_mcam_entry_ena_dis;
roc_nix_mcast_mcam_entry_free;
roc_nix_mcast_mcam_entry_write;
roc_nix_npc_mac_addr_get;
roc_nix_npc_mac_addr_set;
roc_nix_npc_promisc_ena_dis;
roc_nix_npc_rx_ena_dis;
roc_nix_npc_mcast_config;
roc_nix_ras_intr_ena_dis;
roc_nix_register_cq_irqs;
roc_nix_register_queue_irqs;