From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-by2-obe.outbound.protection.outlook.com (mail-by2on0093.outbound.protection.outlook.com [207.46.100.93]) by dpdk.org (Postfix) with ESMTP id B155F567B for ; Mon, 13 Jun 2016 15:57:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=OAaxJOaQNI5cBnt51x/tx8lQkD8elwGsTY7DkheJMtw=; b=Y2J8DvCqjSPe1epdYcM3/y6bJCchgZYgCfljiBSovyED6dU5wOAS220jWvA3Ac2j87ba+Fj0nVG0Ru3fBVRWlEFl5snarmkSqn63Fs1xweKVtGO7Adk98xZ2uCR47HVufJ11V9U6WCTgmy7ZfRGRfwT4CJCHwhbMTSvyuWRVdC4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jerin.Jacob@cavium.com; Received: from localhost.localdomain.localdomain (171.48.21.3) by BN3PR0701MB1717.namprd07.prod.outlook.com (10.163.39.16) with Microsoft SMTP Server (TLS) id 15.1.517.8; Mon, 13 Jun 2016 13:57:08 +0000 From: Jerin Jacob To: CC: , , , Jerin Jacob , Maciej Czekaj , Kamil Rytarowski , Zyta Szpak , Slawomir Rosek , Radoslaw Biernacki Date: Mon, 13 Jun 2016 19:25:32 +0530 Message-ID: <1465826143-22159-9-git-send-email-jerin.jacob@caviumnetworks.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1465826143-22159-1-git-send-email-jerin.jacob@caviumnetworks.com> References: <1465317632-11471-2-git-send-email-jerin.jacob@caviumnetworks.com> <1465826143-22159-1-git-send-email-jerin.jacob@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [171.48.21.3] X-ClientProxiedBy: BM1PR01CA0031.INDPRD01.PROD.OUTLOOK.COM (10.163.198.166) To BN3PR0701MB1717.namprd07.prod.outlook.com (10.163.39.16) X-MS-Office365-Filtering-Correlation-Id: 46fae40c-3519-4639-3ce7-08d393929ea3 X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1717; 2:aHvjVcHWSDzro+PmAHNMBMo81Xg0Vjb8v+OOE7V0tcnPFCIkuDr7Mi05bMS3Q2Sdhz/HcarXz9Lvptg6iM2hQXUD8uSRmKxfpMifpCTuRkl8cXQN6tN0jz99nOJdnWZjFUCy6CUspJyZQfER/m/RG/ayDc05ndhkB+scih35UY1DtbXzcS/cyMbYxN4qHAD+; 3:Dm4K8VgHrVYCJDjxqBqX14CiHtC2YN3+8u0Ug6GWSPVV2fnYJYVF9S29RQemqluKDMzpYkuCqwTi56v7QvkoyaXrLeYgpJHpS1fZSWsGv+jQk4zGNomTrVGtrHw7hAJX X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR0701MB1717; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1717; 25:amVv3mo5A6rMt/LiHlq+pD76iRUoPavDIe+1V3hxGQu2Cfsn0gzxqdd1PLTsi22DqorMCUNwIGPCh8e82NoWU0eEYNwhbsJNdSK+BMrqn8lIILs5WYRR7Npq5AwMvRQD3Km7UGjc4AKNbvmJ/qnP/eeeqrqUQyfXsdopUuqU610cnogo0KynMRxhkfuS5QXkquD2VhVJitSBMNQB4KyRz/T+PwTmRmjxsW2yPo9Z4ChSJwU6sOdiPcRu3aDw36K0fad9gU68oWplVH96tACtRSB1El8ZLdGHnsDWraVJCcILewNwf3TJ8Rd+0aA1Bjug2r9b0dh5Dge06BO83v1HX0aDtjjea4ZbJJJobzeAK8Vu4ZQFYfVw7xQRMM4QiZPeBsdLU3sEhISG7zd0w5hiycRfpRBRi/xFQqzVHsTvPaBamUvRbchGSrJUkCMkrDq4fQPXXn/RuLg1mbn7ciYP6tS4coG8hSDWxwedy9xIxKfR3MtcpLqIzircxWlwhJCocodIPPhTcViB5gNerW+oWFUGuQc2Jk23INGhYXCJDk6XWcVoqE/iIo/juqcs5KowPusAei3p7l0F1CUiFxPiaWTmz72u8jxUVUtO+z3+nSLD8ZWrbe+ImNCBTqRoCnc2KrJ6r4JNU4glGp66C6Ujz/ngSyA0o9W0+bvAhfG5UmG9YdnZ39ch43sJGSKErPoeElx80JGZoXyngM0xrcSa45jwoAsgEhtcNpJMeFHCXE5ps8Ec+AVpIzO27E4NDgpx X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1717; 20:zNLYY6oz6pddyZQLW+FWIfFbkMDWPjHFq3ZPCCKnJC+Zfcv4gvknMc0CubYFVR67jmI23FEe3xc3X5U+VkE9nFYg5BjpqaShFGx8g6bebJWnJOuk1faQABVPuVSDrcVUOtXWWLtQf2PyrQpABQJlfdNkxof1x0tEGg8L8VJvfvYXqGtthG8tasnTYBYcbt6r/omxG3azBxe5W7F3JwI30yDG/FSEHBWVkBu1R9/ebLb2c04g3/NSUtS49eKfl1BTGFuvpSlY0/MFDH6ug/Z2UfkG5PusoSmhg/wLLGDz5aQM8bqsydvEZ7eNALQtaLX2HjB+oyk/novn7C+mzf/cXNhECClXjD7PujNGxy25JNk4fko6pzj7XqRuVwd5dPaguY/wLC7PBVRI62bo/cCxKhVJh0oCzAhFhDESOhBA591YM1sp5+4pZ+DXnTRNBKoeluCX5oAW8oHCp9qG2fpfn74Cuaq1rqGasckQ5OswKZuP2kk1/+HFVg2FnkLaujUBuYOc/1Ir6QAaKJs9wicepr51dpnjOLCu4loXlldB+6CpK0WrW25kvdZUVWVfc3jRr10kd8F3U++kAegM9Us0EMeR5T4YOZQQVZGVDqu6G2I= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:BN3PR0701MB1717; BCL:0; PCL:0; RULEID:; SRVR:BN3PR0701MB1717; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1717; 4:G+ZokFpbJLAYocoKAncWzCqyWusW02va25SoVx+O8d3vI32X2J2zzvGTu0hvNtWnoJle/Ht6rJuN3DzhVNXHi/g4G+fbsWzktcOD6mR7i3rasnyytJBHgumuE26yqTjtr7K6AXObSEeDm1uaSBppoIKCXnnVR2+o7PxmAo78qLmcAT2ptphrvzphWctMgiB7ybd0i/dxHhGRMj7nCYCrENNZdZw6XRKQ8L2t5bdk8+F+fBfCfjqvcOtX1FaJSvhOceOKKbZQ2hGvQUubodQFPvvhq5W2ik3E1LVOPtjrYuMeyMEkhK3RzrBNxfFn+NQPO3VjR7IPn9q58Cass4YrgrOY7/r5vQPqMfAKjdymefv3n7z6C/jdEWDU1gT1GfYe X-Forefront-PRVS: 0972DEC1D9 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6069001)(7916002)(189002)(199003)(50466002)(48376002)(101416001)(42186005)(50986999)(92566002)(76176999)(105586002)(106356001)(33646002)(2351001)(5004730100002)(47776003)(66066001)(36756003)(586003)(3846002)(6116002)(19580405001)(19580395003)(77096005)(8676002)(2906002)(81156014)(81166006)(4326007)(189998001)(97736004)(2950100001)(110136002)(5008740100001)(229853001)(5003940100001)(50226002)(68736007); DIR:OUT; SFP:1101; SCL:1; SRVR:BN3PR0701MB1717; H:localhost.localdomain.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; CAT:NONE; LANG:en; CAT:NONE; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN3PR0701MB1717; 23:obo7TqnOyIf2d7B1hRD24U78RLTGyJDdqcAIni3?= =?us-ascii?Q?jKaLQ4zTH7gpnuwLfqqN8IA86TlOXUbnk+VyOl0X43SWpmVDK4YeHEII7hiR?= =?us-ascii?Q?Guef6jqVrTDjQVcP9U4Q7ineDupAjBfJN0s+O3lVC27UEqrt4V6oYaausjRJ?= =?us-ascii?Q?laWPwVWiHZIu8zTWX4oZGliSu+Qu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sPgXlAl5TzfP7z/9ds?= X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1717; 6:5K3ZMG1HrjnylPC+yOjLYkGtsDKfe6ZsUoauLT08eXeAv05mngscw05TVAKaxBd0HFTjeRoSstugvNppela73nG5z75zCJr3Yee7LQUz9JsrPSD4o7yaqWspaHIFRVffXNpkieqCZl1FfTQx1Awt2nrx0YvZiCGw9d91KR0IH8/4Plq4t/9jfOJUJf3fLGFnK/5CkT91CGuerlVPburd1qKdFYE61Q9BOkfBIAFy9EzPO1VC1l4bVt501oaYo8B4qh0l5DYfxfEp8Cd8UOppPs6ei/X5YoxZbqsA89aIotE=; 5:6lOS/W0jJ7jFQQQdgLZBMb/jXkW25FQPGxvzGVY3Ec1HjzSCZXF7Zh1vITfVXC0VmDRTeeZMLhOUHcst+zFBaUdyKVukOTzmLGrGA+o+JSrxENGci7XPW/t48YETmvz7gALg2mWbQGzDcrw5IlhFew==; 24:xj9pwn5lzDHVK1rGsw/gubEREOxAOsdwk7qtehJ0UkdURlQ5OFJvBcBRzCqa9jHKSOuJKcfDd6MnC6O799lYFk2aqJ4DuCHVW2UDLgMbbfg=; 7:sxJuWAJZC9YNJqq72rnnyH0dGXNK5niwxeXl8IZvijP1nX+ELqcB4K2LvMhPxtcZ6di7YfbKsKkcwpIOz8/tqfDNnS98Yc4XSCUnFN+J2mKkm+HT9XNQwNaNyHPzd92/XFqWi/bZ+jKZ5bx+Z4y3SY6PLyewqCjBDzMWtJ+T5ecwaA4Gfz4rmIVIXvmZPaE/NXynxOGwBZ0Q8c4hN4f2DUlEBRd+1LZP/3Gm2ZtGY5k= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2016 13:57:08.6176 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR0701MB1717 Subject: [dpdk-dev] [PATCH v4 08/19] net/thunderx: add tx_queue_setup/release support X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jun 2016 13:57:21 -0000 Signed-off-by: Jerin Jacob Signed-off-by: Maciej Czekaj Signed-off-by: Kamil Rytarowski Signed-off-by: Zyta Szpak Signed-off-by: Slawomir Rosek Signed-off-by: Radoslaw Biernacki --- drivers/net/thunderx/nicvf_ethdev.c | 175 ++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) diff --git a/drivers/net/thunderx/nicvf_ethdev.c b/drivers/net/thunderx/nicvf_ethdev.c index 4652438..167149e 100644 --- a/drivers/net/thunderx/nicvf_ethdev.c +++ b/drivers/net/thunderx/nicvf_ethdev.c @@ -191,6 +191,179 @@ nicvf_qset_cq_alloc(struct nicvf *nic, struct nicvf_rxq *rxq, uint16_t qidx, return 0; } +static int +nicvf_qset_sq_alloc(struct nicvf *nic, struct nicvf_txq *sq, uint16_t qidx, + uint32_t desc_cnt) +{ + const struct rte_memzone *rz; + uint32_t ring_size = desc_cnt * sizeof(union sq_entry_t); + + rz = rte_eth_dma_zone_reserve(nic->eth_dev, "sq", qidx, ring_size, + NICVF_SQ_BASE_ALIGN_BYTES, nic->node); + if (rz == NULL) { + PMD_INIT_LOG(ERR, "Failed allocate mem for sq hw ring"); + return -ENOMEM; + } + + memset(rz->addr, 0, ring_size); + + sq->phys = rz->phys_addr; + sq->desc = rz->addr; + sq->qlen_mask = desc_cnt - 1; + + return 0; +} + +static inline void +nicvf_tx_queue_release_mbufs(struct nicvf_txq *txq) +{ + uint32_t head; + + head = txq->head; + while (head != txq->tail) { + if (txq->txbuffs[head]) { + rte_pktmbuf_free_seg(txq->txbuffs[head]); + txq->txbuffs[head] = NULL; + } + head++; + head = head & txq->qlen_mask; + } +} + +static void +nicvf_tx_queue_reset(struct nicvf_txq *txq) +{ + uint32_t txq_desc_cnt = txq->qlen_mask + 1; + + memset(txq->desc, 0, sizeof(union sq_entry_t) * txq_desc_cnt); + memset(txq->txbuffs, 0, sizeof(struct rte_mbuf *) * txq_desc_cnt); + txq->tail = 0; + txq->head = 0; + txq->xmit_bufs = 0; +} + +static void +nicvf_dev_tx_queue_release(void *sq) +{ + struct nicvf_txq *txq; + + PMD_INIT_FUNC_TRACE(); + + txq = (struct nicvf_txq *)sq; + if (txq) { + if (txq->txbuffs != NULL) { + nicvf_tx_queue_release_mbufs(txq); + rte_free(txq->txbuffs); + txq->txbuffs = NULL; + } + rte_free(txq); + } +} + +static int +nicvf_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx, + uint16_t nb_desc, unsigned int socket_id, + const struct rte_eth_txconf *tx_conf) +{ + uint16_t tx_free_thresh; + uint8_t is_single_pool; + struct nicvf_txq *txq; + struct nicvf *nic = nicvf_pmd_priv(dev); + + PMD_INIT_FUNC_TRACE(); + + /* Socket id check */ + if (socket_id != (unsigned int)SOCKET_ID_ANY && socket_id != nic->node) + PMD_DRV_LOG(WARNING, "socket_id expected %d, configured %d", + socket_id, nic->node); + + /* Tx deferred start is not supported */ + if (tx_conf->tx_deferred_start) { + PMD_INIT_LOG(ERR, "Tx deferred start not supported"); + return -EINVAL; + } + + /* Roundup nb_desc to available qsize and validate max number of desc */ + nb_desc = nicvf_qsize_sq_roundup(nb_desc); + if (nb_desc == 0) { + PMD_INIT_LOG(ERR, "Value of nb_desc beyond available sq qsize"); + return -EINVAL; + } + + /* Validate tx_free_thresh */ + tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ? + tx_conf->tx_free_thresh : + NICVF_DEFAULT_TX_FREE_THRESH); + + if (tx_free_thresh > (nb_desc) || + tx_free_thresh > NICVF_MAX_TX_FREE_THRESH) { + PMD_INIT_LOG(ERR, + "tx_free_thresh must be less than the number of TX " + "descriptors. (tx_free_thresh=%u port=%d " + "queue=%d)", (unsigned int)tx_free_thresh, + (int)dev->data->port_id, (int)qidx); + return -EINVAL; + } + + /* Free memory prior to re-allocation if needed. */ + if (dev->data->tx_queues[qidx] != NULL) { + PMD_TX_LOG(DEBUG, "Freeing memory prior to re-allocation %d", + qidx); + nicvf_dev_tx_queue_release(dev->data->tx_queues[qidx]); + dev->data->tx_queues[qidx] = NULL; + } + + /* Allocating tx queue data structure */ + txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct nicvf_txq), + RTE_CACHE_LINE_SIZE, nic->node); + if (txq == NULL) { + PMD_INIT_LOG(ERR, "Failed to allocate txq=%d", qidx); + return -ENOMEM; + } + + txq->nic = nic; + txq->queue_id = qidx; + txq->tx_free_thresh = tx_free_thresh; + txq->txq_flags = tx_conf->txq_flags; + txq->sq_head = nicvf_qset_base(nic, qidx) + NIC_QSET_SQ_0_7_HEAD; + txq->sq_door = nicvf_qset_base(nic, qidx) + NIC_QSET_SQ_0_7_DOOR; + is_single_pool = (txq->txq_flags & ETH_TXQ_FLAGS_NOREFCOUNT && + txq->txq_flags & ETH_TXQ_FLAGS_NOMULTMEMP); + + /* Choose optimum free threshold value for multipool case */ + if (!is_single_pool) { + txq->tx_free_thresh = (uint16_t) + (tx_conf->tx_free_thresh == NICVF_DEFAULT_TX_FREE_THRESH ? + NICVF_TX_FREE_MPOOL_THRESH : + tx_conf->tx_free_thresh); + } + + /* Allocate software ring */ + txq->txbuffs = rte_zmalloc_socket("txq->txbuffs", + nb_desc * sizeof(struct rte_mbuf *), + RTE_CACHE_LINE_SIZE, nic->node); + + if (txq->txbuffs == NULL) { + nicvf_dev_tx_queue_release(txq); + return -ENOMEM; + } + + if (nicvf_qset_sq_alloc(nic, txq, qidx, nb_desc)) { + PMD_INIT_LOG(ERR, "Failed to allocate mem for sq %d", qidx); + nicvf_dev_tx_queue_release(txq); + return -ENOMEM; + } + + nicvf_tx_queue_reset(txq); + + PMD_TX_LOG(DEBUG, "[%d] txq=%p nb_desc=%d desc=%p phys=0x%" PRIx64, + qidx, txq, nb_desc, txq->desc, txq->phys); + + dev->data->tx_queues[qidx] = txq; + dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED; + return 0; +} + static void nicvf_rx_queue_reset(struct nicvf_rxq *rxq) { @@ -430,6 +603,8 @@ static const struct eth_dev_ops nicvf_eth_dev_ops = { .dev_infos_get = nicvf_dev_info_get, .rx_queue_setup = nicvf_dev_rx_queue_setup, .rx_queue_release = nicvf_dev_rx_queue_release, + .tx_queue_setup = nicvf_dev_tx_queue_setup, + .tx_queue_release = nicvf_dev_tx_queue_release, .get_reg_length = nicvf_dev_get_reg_length, .get_reg = nicvf_dev_get_regs, }; -- 2.5.5