From 1e18ec58ed5c142d3ff37324c88a32d03abf9ec9 Mon Sep 17 00:00:00 2001 From: Somnath Kotur Date: Thu, 2 Jul 2020 16:28:33 -0700 Subject: [PATCH] net/bnxt: create default flow rules for port reprentor Invoked 3 new APIs for the default flow create/destroy and to get the action ptr for a default flow. Changed ulp_intf_update() to accept rte_eth_dev as input and invoke the same from the VF rep start function. ULP Mark Manager will indicate if the cfa_code returned in the Rx completion descriptor was for one of the default flow rules created for the VF representor conduit. The mark_id returned in such a case would be the VF rep's DPDK Port id, which can be used to get the corresponding rte_eth_dev struct in bnxt_vf_recv Signed-off-by: Somnath Kotur Signed-off-by: Venkat Duvvuru Reviewed-by: Ajit Khaparde --- drivers/net/bnxt/bnxt.h | 4 +- drivers/net/bnxt/bnxt_reps.c | 134 ++++++++++++++++++++++++----------- drivers/net/bnxt/bnxt_reps.h | 3 +- drivers/net/bnxt/bnxt_rxr.c | 25 +++---- drivers/net/bnxt/bnxt_txq.h | 1 + 5 files changed, 111 insertions(+), 56 deletions(-) diff --git a/drivers/net/bnxt/bnxt.h b/drivers/net/bnxt/bnxt.h index 32acced60a..f16bf33196 100644 --- a/drivers/net/bnxt/bnxt.h +++ b/drivers/net/bnxt/bnxt.h @@ -806,8 +806,10 @@ struct bnxt_vf_representor { uint16_t fw_fid; uint16_t dflt_vnic_id; uint16_t svif; - uint16_t tx_cfa_action; + uint32_t vfr_tx_cfa_action; uint16_t rx_cfa_code; + uint32_t rep2vf_flow_id; + uint32_t vf2rep_flow_id; /* Private data store of associated PF/Trusted VF */ struct rte_eth_dev *parent_dev; uint8_t mac_addr[RTE_ETHER_ADDR_LEN]; diff --git a/drivers/net/bnxt/bnxt_reps.c b/drivers/net/bnxt/bnxt_reps.c index bdbce6e8bb..47e2dd72bb 100644 --- a/drivers/net/bnxt/bnxt_reps.c +++ b/drivers/net/bnxt/bnxt_reps.c @@ -12,6 +12,9 @@ #include "bnxt_txr.h" #include "bnxt_hwrm.h" #include "hsi_struct_def_dpdk.h" +#include "bnxt_tf_common.h" +#include "ulp_port_db.h" +#include "ulp_flow_db.h" static const struct eth_dev_ops bnxt_vf_rep_dev_ops = { .dev_infos_get = bnxt_vf_rep_dev_info_get_op, @@ -29,30 +32,20 @@ static const struct eth_dev_ops bnxt_vf_rep_dev_ops = { }; uint16_t -bnxt_vfr_recv(struct bnxt *bp, uint16_t cfa_code, uint16_t queue_id, - struct rte_mbuf *mbuf) +bnxt_vfr_recv(uint16_t port_id, uint16_t queue_id, struct rte_mbuf *mbuf) { struct bnxt_sw_rx_bd *prod_rx_buf; struct bnxt_rx_ring_info *rep_rxr; struct bnxt_rx_queue *rep_rxq; struct rte_eth_dev *vfr_eth_dev; struct bnxt_vf_representor *vfr_bp; - uint16_t vf_id; uint16_t mask; uint8_t que; - vf_id = bp->cfa_code_map[cfa_code]; - /* cfa_code is invalid OR vf_id > MAX REP. Assume normal Rx */ - if (vf_id == BNXT_VF_IDX_INVALID || vf_id > BNXT_MAX_VF_REPS) - return 1; - vfr_eth_dev = bp->rep_info[vf_id].vfr_eth_dev; + vfr_eth_dev = &rte_eth_devices[port_id]; if (!vfr_eth_dev) return 1; vfr_bp = vfr_eth_dev->data->dev_private; - if (vfr_bp->rx_cfa_code != cfa_code) { - /* cfa_code not meant for this VF rep!!?? */ - return 1; - } /* If rxq_id happens to be > max rep_queue, use rxq0 */ que = queue_id < BNXT_MAX_VF_REP_RINGS ? queue_id : 0; rep_rxq = vfr_bp->rx_queues[que]; @@ -127,7 +120,7 @@ bnxt_vf_rep_tx_burst(void *tx_queue, pthread_mutex_lock(&parent->rep_info->vfr_lock); ptxq = parent->tx_queues[qid]; - ptxq->tx_cfa_action = vf_rep_bp->tx_cfa_action; + ptxq->vfr_tx_cfa_action = vf_rep_bp->vfr_tx_cfa_action; for (i = 0; i < nb_pkts; i++) { vf_rep_bp->tx_bytes[qid] += tx_pkts[i]->pkt_len; @@ -135,7 +128,7 @@ bnxt_vf_rep_tx_burst(void *tx_queue, } rc = bnxt_xmit_pkts(ptxq, tx_pkts, nb_pkts); - ptxq->tx_cfa_action = 0; + ptxq->vfr_tx_cfa_action = 0; pthread_mutex_unlock(&parent->rep_info->vfr_lock); return rc; @@ -252,10 +245,67 @@ int bnxt_vf_rep_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_compl) return rc; } -static int bnxt_vfr_alloc(struct bnxt_vf_representor *vfr) +static int bnxt_tf_vfr_alloc(struct rte_eth_dev *vfr_ethdev) +{ + int rc; + struct bnxt_vf_representor *vfr = vfr_ethdev->data->dev_private; + struct rte_eth_dev *parent_dev = vfr->parent_dev; + struct bnxt *parent_bp = parent_dev->data->dev_private; + uint16_t vfr_port_id = vfr_ethdev->data->port_id; + struct ulp_tlv_param param_list[] = { + { + .type = BNXT_ULP_DF_PARAM_TYPE_DEV_PORT_ID, + .length = 2, + .value = {(vfr_port_id >> 8) & 0xff, vfr_port_id & 0xff} + }, + { + .type = BNXT_ULP_DF_PARAM_TYPE_LAST, + .length = 0, + .value = {0} + } + }; + + ulp_port_db_dev_port_intf_update(parent_bp->ulp_ctx, vfr_ethdev); + + rc = ulp_default_flow_create(parent_dev, param_list, + BNXT_ULP_DF_TPL_VFREP_TO_VF, + &vfr->rep2vf_flow_id); + if (rc) { + BNXT_TF_DBG(DEBUG, + "Default flow rule creation for VFR->VF failed!\n"); + return -EIO; + } + + BNXT_TF_DBG(DEBUG, "*** Default flow rule created for VFR->VF! ***\n"); + BNXT_TF_DBG(DEBUG, "rep2vf_flow_id = %d\n", vfr->rep2vf_flow_id); + rc = ulp_default_flow_db_cfa_action_get(parent_bp->ulp_ctx, + vfr->rep2vf_flow_id, + &vfr->vfr_tx_cfa_action); + if (rc) { + BNXT_TF_DBG(DEBUG, + "Failed to get action_ptr for VFR->VF dflt rule\n"); + return -EIO; + } + BNXT_TF_DBG(DEBUG, "tx_cfa_action = %d\n", vfr->vfr_tx_cfa_action); + rc = ulp_default_flow_create(parent_dev, param_list, + BNXT_ULP_DF_TPL_VF_TO_VFREP, + &vfr->vf2rep_flow_id); + if (rc) { + BNXT_TF_DBG(DEBUG, + "Default flow rule creation for VF->VFR failed!\n"); + return -EIO; + } + + BNXT_TF_DBG(DEBUG, "*** Default flow rule created for VF->VFR! ***\n"); + BNXT_TF_DBG(DEBUG, "vfr2rep_flow_id = %d\n", vfr->vf2rep_flow_id); + + return 0; +} + +static int bnxt_vfr_alloc(struct rte_eth_dev *vfr_ethdev) { int rc = 0; - struct bnxt *parent_bp; + struct bnxt_vf_representor *vfr = vfr_ethdev->data->dev_private; if (!vfr || !vfr->parent_dev) { PMD_DRV_LOG(ERR, @@ -263,10 +313,8 @@ static int bnxt_vfr_alloc(struct bnxt_vf_representor *vfr) return -ENOMEM; } - parent_bp = vfr->parent_dev->data->dev_private; - /* Check if representor has been already allocated in FW */ - if (vfr->tx_cfa_action && vfr->rx_cfa_code) + if (vfr->vfr_tx_cfa_action && vfr->rx_cfa_code) return 0; /* @@ -274,24 +322,14 @@ static int bnxt_vfr_alloc(struct bnxt_vf_representor *vfr) * Otherwise the FW will create the VF-rep rules with * default drop action. */ - - /* - * This is where we need to replace invoking an HWRM cmd - * with the new TFLIB ULP API to do more/less the same job - rc = bnxt_hwrm_cfa_vfr_alloc(parent_bp, - vfr->vf_id, - &vfr->tx_cfa_action, - &vfr->rx_cfa_code); - */ - if (!rc) { - parent_bp->cfa_code_map[vfr->rx_cfa_code] = vfr->vf_id; + rc = bnxt_tf_vfr_alloc(vfr_ethdev); + if (!rc) PMD_DRV_LOG(DEBUG, "allocated representor %d in FW\n", vfr->vf_id); - } else { + else PMD_DRV_LOG(ERR, "Failed to alloc representor %d in FW\n", vfr->vf_id); - } return rc; } @@ -312,7 +350,7 @@ int bnxt_vf_rep_dev_start_op(struct rte_eth_dev *eth_dev) struct bnxt_vf_representor *rep_bp = eth_dev->data->dev_private; int rc; - rc = bnxt_vfr_alloc(rep_bp); + rc = bnxt_vfr_alloc(eth_dev); if (!rc) { eth_dev->rx_pkt_burst = &bnxt_vf_rep_rx_burst; @@ -327,6 +365,25 @@ int bnxt_vf_rep_dev_start_op(struct rte_eth_dev *eth_dev) return rc; } +static int bnxt_tf_vfr_free(struct bnxt_vf_representor *vfr) +{ + int rc = 0; + + rc = ulp_default_flow_destroy(vfr->parent_dev, + vfr->rep2vf_flow_id); + if (rc) + PMD_DRV_LOG(ERR, + "default flow destroy failed rep2vf flowid: %d\n", + vfr->rep2vf_flow_id); + rc = ulp_default_flow_destroy(vfr->parent_dev, + vfr->vf2rep_flow_id); + if (rc) + PMD_DRV_LOG(ERR, + "default flow destroy failed vf2rep flowid: %d\n", + vfr->vf2rep_flow_id); + return 0; +} + static int bnxt_vfr_free(struct bnxt_vf_representor *vfr) { int rc = 0; @@ -341,15 +398,10 @@ static int bnxt_vfr_free(struct bnxt_vf_representor *vfr) parent_bp = vfr->parent_dev->data->dev_private; /* Check if representor has been already freed in FW */ - if (!vfr->tx_cfa_action && !vfr->rx_cfa_code) + if (!vfr->vfr_tx_cfa_action && !vfr->rx_cfa_code) return 0; - /* - * This is where we need to replace invoking an HWRM cmd - * with the new TFLIB ULP API to do more/less the same job - rc = bnxt_hwrm_cfa_vfr_free(parent_bp, - vfr->vf_id); - */ + rc = bnxt_tf_vfr_free(vfr); if (rc) { PMD_DRV_LOG(ERR, "Failed to free representor %d in FW\n", @@ -360,7 +412,7 @@ static int bnxt_vfr_free(struct bnxt_vf_representor *vfr) parent_bp->cfa_code_map[vfr->rx_cfa_code] = BNXT_VF_IDX_INVALID; PMD_DRV_LOG(DEBUG, "freed representor %d in FW\n", vfr->vf_id); - vfr->tx_cfa_action = 0; + vfr->vfr_tx_cfa_action = 0; vfr->rx_cfa_code = 0; return rc; diff --git a/drivers/net/bnxt/bnxt_reps.h b/drivers/net/bnxt/bnxt_reps.h index 5c2e0a0b9b..418b95afcd 100644 --- a/drivers/net/bnxt/bnxt_reps.h +++ b/drivers/net/bnxt/bnxt_reps.h @@ -13,8 +13,7 @@ #define BNXT_VF_IDX_INVALID 0xffff uint16_t -bnxt_vfr_recv(struct bnxt *bp, uint16_t cfa_code, uint16_t queue_id, - struct rte_mbuf *mbuf); +bnxt_vfr_recv(uint16_t port_id, uint16_t queue_id, struct rte_mbuf *mbuf); int bnxt_vf_representor_init(struct rte_eth_dev *eth_dev, void *params); int bnxt_vf_representor_uninit(struct rte_eth_dev *eth_dev); int bnxt_vf_rep_dev_info_get_op(struct rte_eth_dev *eth_dev, diff --git a/drivers/net/bnxt/bnxt_rxr.c b/drivers/net/bnxt/bnxt_rxr.c index 37b534fc27..64058879e8 100644 --- a/drivers/net/bnxt/bnxt_rxr.c +++ b/drivers/net/bnxt/bnxt_rxr.c @@ -403,9 +403,9 @@ bnxt_get_rx_ts_thor(struct bnxt *bp, uint32_t rx_ts_cmpl) } #endif -static void +static uint32_t bnxt_ulp_set_mark_in_mbuf(struct bnxt *bp, struct rx_pkt_cmpl_hi *rxcmp1, - struct rte_mbuf *mbuf) + struct rte_mbuf *mbuf, uint32_t *vfr_flag) { uint32_t cfa_code; uint32_t meta_fmt; @@ -415,8 +415,6 @@ bnxt_ulp_set_mark_in_mbuf(struct bnxt *bp, struct rx_pkt_cmpl_hi *rxcmp1, uint32_t flags2; uint32_t gfid_support = 0; int rc; - uint32_t vfr_flag; - if (BNXT_GFID_ENABLED(bp)) gfid_support = 1; @@ -485,19 +483,21 @@ bnxt_ulp_set_mark_in_mbuf(struct bnxt *bp, struct rx_pkt_cmpl_hi *rxcmp1, } rc = ulp_mark_db_mark_get(bp->ulp_ctx, gfid, - cfa_code, &vfr_flag, &mark_id); + cfa_code, vfr_flag, &mark_id); if (!rc) { /* Got the mark, write it to the mbuf and return */ mbuf->hash.fdir.hi = mark_id; mbuf->udata64 = (cfa_code & 0xffffffffull) << 32; mbuf->hash.fdir.id = rxcmp1->cfa_code; mbuf->ol_flags |= PKT_RX_FDIR | PKT_RX_FDIR_ID; - return; + return mark_id; } skip_mark: mbuf->hash.fdir.hi = 0; mbuf->hash.fdir.id = 0; + + return 0; } void bnxt_set_mark_in_mbuf(struct bnxt *bp, @@ -553,7 +553,7 @@ static int bnxt_rx_pkt(struct rte_mbuf **rx_pkt, int rc = 0; uint8_t agg_buf = 0; uint16_t cmp_type; - uint32_t flags2_f = 0; + uint32_t flags2_f = 0, vfr_flag = 0, mark_id = 0; uint16_t flags_type; struct bnxt *bp = rxq->bp; @@ -632,7 +632,8 @@ static int bnxt_rx_pkt(struct rte_mbuf **rx_pkt, } if (BNXT_TRUFLOW_EN(bp)) - bnxt_ulp_set_mark_in_mbuf(rxq->bp, rxcmp1, mbuf); + mark_id = bnxt_ulp_set_mark_in_mbuf(rxq->bp, rxcmp1, mbuf, + &vfr_flag); else bnxt_set_mark_in_mbuf(rxq->bp, rxcmp1, mbuf); @@ -736,10 +737,10 @@ static int bnxt_rx_pkt(struct rte_mbuf **rx_pkt, rx: *rx_pkt = mbuf; - if ((BNXT_VF_IS_TRUSTED(rxq->bp) || BNXT_PF(rxq->bp)) && - rxq->bp->cfa_code_map && rxcmp1->cfa_code) { - if (!bnxt_vfr_recv(rxq->bp, rxcmp1->cfa_code, rxq->queue_id, - mbuf)) { + if (BNXT_TRUFLOW_EN(bp) && + (BNXT_VF_IS_TRUSTED(bp) || BNXT_PF(bp)) && + vfr_flag) { + if (!bnxt_vfr_recv(mark_id, rxq->queue_id, mbuf)) { /* Now return an error so that nb_rx_pkts is not * incremented. * This packet was meant to be given to the representor. diff --git a/drivers/net/bnxt/bnxt_txq.h b/drivers/net/bnxt/bnxt_txq.h index 69ff89aab4..a1ab3f39af 100644 --- a/drivers/net/bnxt/bnxt_txq.h +++ b/drivers/net/bnxt/bnxt_txq.h @@ -30,6 +30,7 @@ struct bnxt_tx_queue { int index; int tx_wake_thresh; uint32_t tx_cfa_action; + uint32_t vfr_tx_cfa_action; struct bnxt_tx_ring_info *tx_ring; unsigned int cp_nr_rings; -- 2.20.1