net/bnxt: cleanup VF representor device operations
[dpdk.git] / drivers / net / bnxt / bnxt_reps.c
index b318c5a..6fa9a30 100644 (file)
@@ -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,
@@ -26,33 +29,24 @@ static const struct eth_dev_ops bnxt_vf_rep_dev_ops = {
        .dev_stop = bnxt_vf_rep_dev_stop_op,
        .stats_get = bnxt_vf_rep_stats_get_op,
        .stats_reset = bnxt_vf_rep_stats_reset_op,
+       .filter_ctrl = bnxt_filter_ctrl_op
 };
 
 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 +121,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,12 +129,10 @@ 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;
-
-       return 0;
 }
 
 int bnxt_vf_representor_init(struct rte_eth_dev *eth_dev, void *params)
@@ -150,6 +142,7 @@ int bnxt_vf_representor_init(struct rte_eth_dev *eth_dev, void *params)
                                 (struct bnxt_vf_representor *)params;
        struct rte_eth_link *link;
        struct bnxt *parent_bp;
+       int rc = 0;
 
        vf_rep_bp->vf_id = rep_params->vf_id;
        vf_rep_bp->switch_domain_id = rep_params->switch_domain_id;
@@ -179,6 +172,17 @@ int bnxt_vf_representor_init(struct rte_eth_dev *eth_dev, void *params)
        eth_dev->data->dev_link.link_status = link->link_status;
        eth_dev->data->dev_link.link_autoneg = link->link_autoneg;
 
+       vf_rep_bp->fw_fid = rep_params->vf_id + parent_bp->first_vf_id;
+       PMD_DRV_LOG(INFO, "vf_rep->fw_fid = %d\n", vf_rep_bp->fw_fid);
+       rc = bnxt_hwrm_get_dflt_vnic_svif(parent_bp, vf_rep_bp->fw_fid,
+                                         &vf_rep_bp->dflt_vnic_id,
+                                         &vf_rep_bp->svif);
+       if (rc)
+               PMD_DRV_LOG(ERR, "Failed to get default vnic id of VF\n");
+       else
+               PMD_DRV_LOG(INFO, "vf_rep->dflt_vnic_id = %d\n",
+                           vf_rep_bp->dflt_vnic_id);
+
        PMD_DRV_LOG(INFO, "calling bnxt_print_link_info\n");
        bnxt_print_link_info(eth_dev);
 
@@ -226,6 +230,9 @@ int bnxt_vf_rep_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_compl)
        int rc;
 
        parent_bp = rep->parent_dev->data->dev_private;
+       if (!parent_bp)
+               return 0;
+
        rc = bnxt_link_update_op(parent_bp->eth_dev, wait_to_compl);
 
        /* Link state. Inherited from PF or trusted VF */
@@ -240,10 +247,78 @@ 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");
+               goto err;
+       }
+
+       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");
+               goto rep2vf_free;
+       }
+       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");
+               goto rep2vf_free;
+       }
+
+       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);
+
+       rc = bnxt_hwrm_cfa_vfr_alloc(parent_bp, vfr->vf_id);
+       if (rc)
+               goto vf2rep_free;
+
+       return 0;
+
+vf2rep_free:
+       ulp_default_flow_destroy(vfr->parent_dev, vfr->vf2rep_flow_id);
+rep2vf_free:
+       ulp_default_flow_destroy(vfr->parent_dev, vfr->rep2vf_flow_id);
+err:
+       return -EIO;
+}
+
+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,
@@ -251,10 +326,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)
                return 0;
 
        /*
@@ -262,24 +335,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;
 }
@@ -300,7 +363,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;
@@ -315,6 +378,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;
@@ -327,17 +409,14 @@ static int bnxt_vfr_free(struct bnxt_vf_representor *vfr)
        }
 
        parent_bp = vfr->parent_dev->data->dev_private;
+       if (!parent_bp)
+               return 0;
 
        /* Check if representor has been already freed in FW */
-       if (!vfr->tx_cfa_action && !vfr->rx_cfa_code)
+       if (!vfr->vfr_tx_cfa_action)
                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",
@@ -345,11 +424,11 @@ static int bnxt_vfr_free(struct bnxt_vf_representor *vfr)
                return rc;
        }
 
-       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->rx_cfa_code = 0;
+       vfr->vfr_tx_cfa_action = 0;
+
+       rc = bnxt_hwrm_cfa_vfr_free(parent_bp, vfr->vf_id);
 
        return rc;
 }
@@ -380,7 +459,6 @@ int bnxt_vf_rep_dev_info_get_op(struct rte_eth_dev *eth_dev,
 {
        struct bnxt_vf_representor *rep_bp = eth_dev->data->dev_private;
        struct bnxt *parent_bp;
-       uint16_t max_vnics, i, j, vpool, vrxq;
        unsigned int max_rx_rings;
        int rc = 0;
 
@@ -400,7 +478,6 @@ int bnxt_vf_rep_dev_info_get_op(struct rte_eth_dev *eth_dev,
        dev_info->max_tx_queues = max_rx_rings;
        dev_info->reta_size = bnxt_rss_hash_tbl_size(parent_bp);
        dev_info->hash_key_size = 40;
-       max_vnics = parent_bp->max_vnics;
 
        /* MTU specifics */
        dev_info->min_mtu = RTE_ETHER_MIN_MTU;
@@ -416,68 +493,6 @@ int bnxt_vf_rep_dev_info_get_op(struct rte_eth_dev *eth_dev,
        dev_info->tx_offload_capa = BNXT_DEV_TX_OFFLOAD_SUPPORT;
        dev_info->flow_type_rss_offloads = BNXT_ETH_RSS_SUPPORT;
 
-       /* *INDENT-OFF* */
-       dev_info->default_rxconf = (struct rte_eth_rxconf) {
-               .rx_thresh = {
-                       .pthresh = 8,
-                       .hthresh = 8,
-                       .wthresh = 0,
-               },
-               .rx_free_thresh = 32,
-               /* If no descriptors available, pkts are dropped by default */
-               .rx_drop_en = 1,
-       };
-
-       dev_info->default_txconf = (struct rte_eth_txconf) {
-               .tx_thresh = {
-                       .pthresh = 32,
-                       .hthresh = 0,
-                       .wthresh = 0,
-               },
-               .tx_free_thresh = 32,
-               .tx_rs_thresh = 32,
-       };
-       eth_dev->data->dev_conf.intr_conf.lsc = 1;
-
-       eth_dev->data->dev_conf.intr_conf.rxq = 1;
-       dev_info->rx_desc_lim.nb_min = BNXT_MIN_RING_DESC;
-       dev_info->rx_desc_lim.nb_max = BNXT_MAX_RX_RING_DESC;
-       dev_info->tx_desc_lim.nb_min = BNXT_MIN_RING_DESC;
-       dev_info->tx_desc_lim.nb_max = BNXT_MAX_TX_RING_DESC;
-
-       /* *INDENT-ON* */
-
-       /*
-        * TODO: default_rxconf, default_txconf, rx_desc_lim, and tx_desc_lim
-        *       need further investigation.
-        */
-
-       /* VMDq resources */
-       vpool = 64; /* ETH_64_POOLS */
-       vrxq = 128; /* ETH_VMDQ_DCB_NUM_QUEUES */
-       for (i = 0; i < 4; vpool >>= 1, i++) {
-               if (max_vnics > vpool) {
-                       for (j = 0; j < 5; vrxq >>= 1, j++) {
-                               if (dev_info->max_rx_queues > vrxq) {
-                                       if (vpool > vrxq)
-                                               vpool = vrxq;
-                                       goto found;
-                               }
-                       }
-                       /* Not enough resources to support VMDq */
-                       break;
-               }
-       }
-       /* Not enough resources to support VMDq */
-       vpool = 0;
-       vrxq = 0;
-found:
-       dev_info->max_vmdq_pools = vpool;
-       dev_info->vmdq_queue_num = vrxq;
-
-       dev_info->vmdq_pool_base = 0;
-       dev_info->vmdq_queue_base = 0;
-
        return 0;
 }