From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0EDE4A0A0C; Thu, 1 Jul 2021 13:41:13 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EEF70412FF; Thu, 1 Jul 2021 13:40:43 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mails.dpdk.org (Postfix) with ESMTP id 2B7D2412E9 for ; Thu, 1 Jul 2021 13:40:41 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10031"; a="205513435" X-IronPort-AV: E=Sophos;i="5.83,314,1616482800"; d="scan'208";a="205513435" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2021 04:40:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,313,1616482800"; d="scan'208";a="457624134" Received: from dpdk-xuting-second.sh.intel.com ([10.67.116.193]) by fmsmga008.fm.intel.com with ESMTP; 01 Jul 2021 04:40:39 -0700 From: Ting Xu To: dev@dpdk.org Cc: qi.z.zhang@intel.com, jingjing.wu@intel.com, beilei.xing@intel.com, qiming.yang@intel.com, Ting Xu Date: Thu, 1 Jul 2021 19:41:23 +0800 Message-Id: <20210701114124.6174-7-ting.xu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210701114124.6174-1-ting.xu@intel.com> References: <20210601014034.36100-1-ting.xu@intel.com> <20210701114124.6174-1-ting.xu@intel.com> Subject: [dpdk-dev] [PATCH v5 6/7] net/iavf: check Tx packet with correct UP and queue X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add check in the Tx packet preparation function, to guarantee that the packet with specific user priority is distributed to the correct Tx queue according to the configured Tx queue TC mapping. Signed-off-by: Ting Xu --- drivers/net/iavf/iavf.h | 10 ++++++++ drivers/net/iavf/iavf_rxtx.c | 49 ++++++++++++++++++++++++++++++++++++ drivers/net/iavf/iavf_rxtx.h | 1 + drivers/net/iavf/iavf_tm.c | 13 ++++++++++ 4 files changed, 73 insertions(+) diff --git a/drivers/net/iavf/iavf.h b/drivers/net/iavf/iavf.h index feb8337b55..b3bd078111 100644 --- a/drivers/net/iavf/iavf.h +++ b/drivers/net/iavf/iavf.h @@ -86,6 +86,8 @@ #define IAVF_BITS_PER_BYTE 8 +#define IAVF_VLAN_TAG_PCP_OFFSET 13 + struct iavf_adapter; struct iavf_rx_queue; struct iavf_tx_queue; @@ -165,6 +167,13 @@ struct iavf_tm_conf { bool committed; }; +/* Struct to store queue TC mapping. Queue is continuous in one TC */ +struct iavf_qtc_map { + uint8_t tc; + uint16_t start_queue_id; + uint16_t queue_count; +}; + /* Structure to store private data specific for VF instance. */ struct iavf_info { uint16_t num_queue_pairs; @@ -213,6 +222,7 @@ struct iavf_info { bool lv_enabled; struct virtchnl_qos_cap_list *qos_cap; + struct iavf_qtc_map *qtc_map; struct iavf_tm_conf tm_conf; }; diff --git a/drivers/net/iavf/iavf_rxtx.c b/drivers/net/iavf/iavf_rxtx.c index 0361af0d85..f817fbc49b 100644 --- a/drivers/net/iavf/iavf_rxtx.c +++ b/drivers/net/iavf/iavf_rxtx.c @@ -785,6 +785,22 @@ iavf_dev_tx_queue_setup(struct rte_eth_dev *dev, ad->tx_vec_allowed = false; } + if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_QOS && + vf->tm_conf.committed) { + int tc; + for (tc = 0; tc < vf->qos_cap->num_elem; tc++) { + if (txq->queue_id >= vf->qtc_map[tc].start_queue_id && + txq->queue_id < (vf->qtc_map[tc].start_queue_id + + vf->qtc_map[tc].queue_count)) + break; + } + if (tc >= vf->qos_cap->num_elem) { + PMD_INIT_LOG(ERR, "Queue TC mapping is not correct"); + return -EINVAL; + } + txq->tc = tc; + } + return 0; } @@ -2342,6 +2358,27 @@ iavf_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) return nb_tx; } +/* Check if the packet with vlan user priority is transmitted in the + * correct queue. + */ +static int +iavf_check_vlan_up2tc(struct iavf_tx_queue *txq, struct rte_mbuf *m) +{ + struct rte_eth_dev *dev = &rte_eth_devices[txq->port_id]; + struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private); + uint16_t up; + + up = m->vlan_tci >> IAVF_VLAN_TAG_PCP_OFFSET; + + if (!(vf->qos_cap->cap[txq->tc].tc_prio & BIT(up))) { + PMD_TX_LOG(ERR, "packet with vlan pcp %u cannot transmit in queue %u\n", + up, txq->queue_id); + return -1; + } else { + return 0; + } +} + /* TX prep functions */ uint16_t iavf_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts, @@ -2350,6 +2387,9 @@ iavf_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts, int i, ret; uint64_t ol_flags; struct rte_mbuf *m; + struct iavf_tx_queue *txq = tx_queue; + struct rte_eth_dev *dev = &rte_eth_devices[txq->port_id]; + struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private); for (i = 0; i < nb_pkts; i++) { m = tx_pkts[i]; @@ -2385,6 +2425,15 @@ iavf_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts, rte_errno = -ret; return i; } + + if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_QOS && + ol_flags & (PKT_RX_VLAN_STRIPPED | PKT_RX_VLAN)) { + ret = iavf_check_vlan_up2tc(txq, m); + if (ret != 0) { + rte_errno = -ret; + return i; + } + } } return i; diff --git a/drivers/net/iavf/iavf_rxtx.h b/drivers/net/iavf/iavf_rxtx.h index 19b6028a15..e210b913d6 100644 --- a/drivers/net/iavf/iavf_rxtx.h +++ b/drivers/net/iavf/iavf_rxtx.h @@ -252,6 +252,7 @@ struct iavf_tx_queue { #define IAVF_TX_FLAGS_VLAN_TAG_LOC_L2TAG1 BIT(0) #define IAVF_TX_FLAGS_VLAN_TAG_LOC_L2TAG2 BIT(1) uint8_t vlan_flag; + uint8_t tc; }; /* Offload features */ diff --git a/drivers/net/iavf/iavf_tm.c b/drivers/net/iavf/iavf_tm.c index 03349619d1..558021014e 100644 --- a/drivers/net/iavf/iavf_tm.c +++ b/drivers/net/iavf/iavf_tm.c @@ -655,6 +655,7 @@ static int iavf_hierarchy_commit(struct rte_eth_dev *dev, struct virtchnl_queue_tc_mapping *q_tc_mapping; struct iavf_tm_node_list *queue_list = &vf->tm_conf.queue_list; struct iavf_tm_node *tm_node; + struct iavf_qtc_map *qtc_map; uint16_t size; int index = 0, node_committed = 0; int i, ret_val = IAVF_SUCCESS; @@ -690,6 +691,7 @@ static int iavf_hierarchy_commit(struct rte_eth_dev *dev, q_tc_mapping->vsi_id = vf->vsi.vsi_id; q_tc_mapping->num_tc = vf->qos_cap->num_elem; q_tc_mapping->num_queue_pairs = vf->num_queue_pairs; + TAILQ_FOREACH(tm_node, queue_list, node) { if (tm_node->tc >= q_tc_mapping->num_tc) { PMD_DRV_LOG(ERR, "TC%d is not enabled", tm_node->tc); @@ -707,15 +709,26 @@ static int iavf_hierarchy_commit(struct rte_eth_dev *dev, goto fail_clear; } + /* store the queue TC mapping info */ + qtc_map = rte_zmalloc("qtc_map", + sizeof(struct iavf_qtc_map) * q_tc_mapping->num_tc, 0); + if (!qtc_map) + return IAVF_ERR_NO_MEMORY; + for (i = 0; i < q_tc_mapping->num_tc; i++) { q_tc_mapping->tc[i].req.start_queue_id = index; index += q_tc_mapping->tc[i].req.queue_count; + qtc_map[i].tc = i; + qtc_map[i].start_queue_id = + q_tc_mapping->tc[i].req.start_queue_id; + qtc_map[i].queue_count = q_tc_mapping->tc[i].req.queue_count; } ret_val = iavf_set_q_tc_map(dev, q_tc_mapping, size); if (ret_val) goto fail_clear; + vf->qtc_map = qtc_map; vf->tm_conf.committed = true; return ret_val; -- 2.17.1