From 1c518ee11e31a296888d6851654651db4ef02d3b Mon Sep 17 00:00:00 2001 From: Sunil Kumar Kori Date: Tue, 6 Apr 2021 20:11:14 +0530 Subject: [PATCH] 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 Acked-by: Nithin Dabilpuram --- drivers/common/cnxk/meson.build | 2 + drivers/common/cnxk/roc_nix.h | 25 +++++++ drivers/common/cnxk/roc_nix_mcast.c | 98 ++++++++++++++++++++++++++ drivers/common/cnxk/roc_nix_npc.c | 103 ++++++++++++++++++++++++++++ drivers/common/cnxk/version.map | 9 +++ 5 files changed, 237 insertions(+) create mode 100644 drivers/common/cnxk/roc_nix_mcast.c create mode 100644 drivers/common/cnxk/roc_nix_npc.c diff --git a/drivers/common/cnxk/meson.build b/drivers/common/cnxk/meson.build index b9da55b11d..f216d4aad2 100644 --- a/drivers/common/cnxk/meson.build +++ b/drivers/common/cnxk/meson.build @@ -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', diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h index 66e0bfa5ba..638f82789a 100644 --- a/drivers/common/cnxk/roc_nix.h +++ b/drivers/common/cnxk/roc_nix.h @@ -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_ */ diff --git a/drivers/common/cnxk/roc_nix_mcast.c b/drivers/common/cnxk/roc_nix_mcast.c new file mode 100644 index 0000000000..87d083ebb3 --- /dev/null +++ b/drivers/common/cnxk/roc_nix_mcast.c @@ -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); +} diff --git a/drivers/common/cnxk/roc_nix_npc.c b/drivers/common/cnxk/roc_nix_npc.c new file mode 100644 index 0000000000..c0666c87d5 --- /dev/null +++ b/drivers/common/cnxk/roc_nix_npc.c @@ -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); +} diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map index 1f41a8831d..bc6c9884d2 100644 --- a/drivers/common/cnxk/version.map +++ b/drivers/common/cnxk/version.map @@ -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; -- 2.20.1