From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-by2-obe.outbound.protection.outlook.com (mail-by2on0054.outbound.protection.outlook.com [207.46.100.54]) by dpdk.org (Postfix) with ESMTP id 1CD9C5A79 for ; Sat, 7 May 2016 17:18:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=gY7whyw04CFZioJqdfv0gc9BvpqDy+fjw4YM+B6RWhE=; b=K1haDziPaIA8q+aOZjJa0gflDjfgxXm6w3YrZcf7uMe/GlR+Ip7vDpbujBAMeRGlwY+E+2ZkM8gE4tfeDl9QPGM95hdhecJ5Y8mqMgtE+wIrt26kVapNt3QIxDiqpLDO9LvhwMbcZSFXgMqQjmjZUQniNb7qwYWvsCp7B/a5pn4= Authentication-Results: dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=none action=none header.from=caviumnetworks.com; Received: from localhost.localdomain.localdomain (122.167.10.92) by BN3PR0701MB1718.namprd07.prod.outlook.com (10.163.39.17) with Microsoft SMTP Server (TLS) id 15.1.492.11; Sat, 7 May 2016 15:18:14 +0000 From: Jerin Jacob To: CC: , , Jerin Jacob , Maciej Czekaj , Kamil Rytarowski , Zyta Szpak , Slawomir Rosek , Radoslaw Biernacki Date: Sat, 7 May 2016 20:46:26 +0530 Message-ID: <1462634198-2289-9-git-send-email-jerin.jacob@caviumnetworks.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1462634198-2289-1-git-send-email-jerin.jacob@caviumnetworks.com> References: <1462634198-2289-1-git-send-email-jerin.jacob@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [122.167.10.92] X-ClientProxiedBy: PN1PR01CA0050.INDPRD01.PROD.OUTLOOK.COM (10.164.136.150) To BN3PR0701MB1718.namprd07.prod.outlook.com (10.163.39.17) X-MS-Office365-Filtering-Correlation-Id: a47d0303-d802-42dc-e0a4-08d3768ad286 X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1718; 2:tT3fhm41hmuK6eefN01uBceGpmSOL+lr9dD3OldW99u7+FMKtibtcX5X+j061dMzqM2NdQo1RfAChIKPuK0uBGUA46xXLIYQ5K8UJKuGszjUZr/2uUUkvyVmz7I45xIlFUwxgmVzSPYBGqCwHKTeFYmNCAzdtUzNsXTyQ7kKa4qNtQrlvT/dMzeTJM2SHJVh; 3:kc9jt9Yd0bEE05H/d2vXq6+bZ2XDNpaU0Lb1HtvHEWCLsvRDS+pSKKFbeh/5alN9GUtAFKbuRVRgiplFaW9pCboKOc/lVhRP+wMPZblUjt1n7en1NmLOPqsqXTHtf5gJ X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR0701MB1718; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1718; 25:1AZUPZyQ+S+f8zodwrNpl+4nPAat8nTyKSJENElFywt8pM/IWrPe3IksBM/Way+o4PxNHdmMzf/QNX3nF6njhcpvN8e613jcotCDtxYto/JP10Kgbe0q69+8ofqTmOLQ/kCeSODhqX4jIxWISlK94OqqhgGQjRdtO88cIB1gSDW3mq6MKMmyIgUZnKakApFM8GSzPQPtq9vnhEQio6Kp/q/CWmvMdGKVWNHIfS3bXRdB4pTJ55iHPGdSZkRudiDf0JH8vorHr4PPdWZGuhaBSIi800MB3jsR2ARPEvCyDkE0fTpyHkgSohNBgrvV0q6fWw6w2lX+mekPnooyPKSdIYd7MROY8e07DXgF5xjrEt8Lr3GjAvYPfD1T+j13mT2oZNiDDYh8hrgtEmkt33QzRB5YofD+V2JojEb+gMSSuYtq075pCBujqD62H6X79svOCtkKUjKPK9xrpNkJOSj3x2rcO4wfE4vdIKp4kaW6V/CorqY/gib1vdNyskMm6LXBx6yMwDqNj4H0Lsz8MV5Ia3nD4ayHYzeVgTkl6QCkHGc94dCixvQVn5jf/wMwEh1ubHzrUVHthiFLygc0vDtdlsaJHUgCphKwFvY4Hu+wufKS5l99XnMzp0iockDuOyQY4ymm7djBdn7hd5YBTV0+Ygsi1IN3zPJgqbDdyO9m2MBA2W6Mh/9fgJIq5WbCk/dQLKuD7IX1wG0v4+gtrH5CQ2NdaYt+X0vzVIaUJGXu+HQ= X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1718; 20:C/4x9F+om4jdxMCsWYDzETEYT0vGOAGovJw90iKsZcrGvoOwLlRSAZpYPj5oAVxWaAaHKWbch1DCw01hWVjh/irXJeExXJeubLtxonwPRs4FX/H7j6WoS5P51uLIWWnc+B3D2Dfg3OtXdjYEnqim+0Gt0rPVqhpwZxGbvgFaVOQwVUleK/7+Ewg18UgS2zBIsImH8Ew8IfbbicmTp/aT7RdlzDe9kIaYu5wT1MnUieXrHzkY/Lp27ECQlelRcHjbG6hLqCcn77KQLxvghOexobYX+OdkEjL8w9WpQODE+iKtT1e+WpzA0E60qMIeDb8O98ObtOSY1orrUA91eUZDimmKMcRlIaE1vvG4GGcbH/O+HBH4qRD64XFLvTLUoHx+9FOFneuEwyEjng56OyGEhhF001tX7O/ti+W/j4Yb04r7FVlPwTjNaRyj15hNQPhb9v4dgtMMN4F6PPVEIrmnYRj/GP6Rk8+OACFrsBw8f9GMmhLhYR7Kc3tQSHt93nqUzaWKMngUDhx7jlxWPPtRT1B5Xy/TfBVttvlvPvWa16Q3Dj09ze5TkyHPlJany8fxfDOUnIesBN3jfaBO7HO61+EpSaMqJ1rWxifZ7PYhldc= 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:BN3PR0701MB1718; BCL:0; PCL:0; RULEID:; SRVR:BN3PR0701MB1718; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1718; 4:DaLC5femUbF201A6eXOBMTYx9FmAR0biOXO/V/cxaliqQWE/GvMUMBtOdT8xxVQfPQ7hA1584EgdELv5kglkbBHih0L+vsnxS/OXNp1Y14pGbLdcHa5Ukm8Q1bYoKUkpkKCt9awL/E3Q7v7ZDGgxTIQzk9EUn1FLQuzwVx573Y5Pmiq+UDyDFGWurIkSaXZL+4EXlQtdYIARYf8d8MFAtKZa98VXZyLYcsfLQz6Sdp+IfdiL9anpUz8x8radlO1LCAfUhCXIOL440ne4aDl/Pqdgig04Pm3r+OXkM4JUNHWdloKbEhtCjmZV1b4gp5hzTwDbmUnFXRuoh0albhLr9L2SiBrNaQs8YHm8N6w9hr1X9po4ZFLMWQXZ+sJrMNDp X-Forefront-PRVS: 09352FD734 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6069001)(50226002)(77096005)(2950100001)(48376002)(81166005)(50466002)(66066001)(47776003)(92566002)(5003940100001)(4326007)(2906002)(110136002)(50986999)(2351001)(33646002)(586003)(3846002)(6116002)(229853001)(5004730100002)(76176999)(19580395003)(19580405001)(189998001)(5008740100001)(42186005)(36756003)(7099028); DIR:OUT; SFP:1101; SCL:1; SRVR:BN3PR0701MB1718; H:localhost.localdomain.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1718; 23:BCX4Kvy3PgQNyiebInVkVu1J5KoO/VO17hl/6vcEFyi0wwoglFhiKLX/FyjYiVdoO7KpzfFnPGqdFGdB6Jh4JQhQu8gFC9s3NDG+LY0sXpR9FHb8CyE9xJQDJmW+gKL61seS0jyo8L2fcmDNCHQcZlujpNWxG09nnJXpsoBMAqvJD3VPrhKUpbXYWIMe3Xgo52i4/ToLyI/Y4mH3LGoqtCCYI4E/zAEEFSsZKZBxu93Ecv8rKbu0Gs7ma5URKKHiChUbLB9+FGbUYIEf9yv2LmYfwgM8kZeF1wOHI8ka5kkALAGfPx8oLBJpQwdGGGhKMRBvATwk07x7kBjpZqL/5WRUrrPM42x3rNE/tIDP03gNSGOwzVcF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works.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2016 15:18:14.8364 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR0701MB1718 Subject: [dpdk-dev] [PATCH 08/20] thunderx/nicvf: 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: Sat, 07 May 2016 15:18: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 | 179 ++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) diff --git a/drivers/net/thunderx/nicvf_ethdev.c b/drivers/net/thunderx/nicvf_ethdev.c index 3b94168..b99b4bb 100644 --- a/drivers/net/thunderx/nicvf_ethdev.c +++ b/drivers/net/thunderx/nicvf_ethdev.c @@ -78,6 +78,10 @@ static int nicvf_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx, const struct rte_eth_rxconf *rx_conf, struct rte_mempool *mp); static void nicvf_dev_rx_queue_release(void *rx_queue); +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); +static void nicvf_dev_tx_queue_release(void *sq); static int nicvf_dev_get_reg_length(struct rte_eth_dev *dev); static int nicvf_dev_get_regs(struct rte_eth_dev *dev, struct rte_dev_reg_info *regs); @@ -226,6 +230,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; + struct nicvf_txq *txq; + struct nicvf *nic = nicvf_pmd_priv(dev); + + PMD_INIT_FUNC_TRACE(); + + /* Socked 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 avilable 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 : + DEFAULT_TX_FREE_THRESH); + + if (tx_free_thresh > (nb_desc) || tx_free_thresh > 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->port_id = dev->data->port_id; + 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; + txq->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 (!txq->is_single_pool) + txq->tx_free_thresh = + (uint16_t)(tx_conf->tx_free_thresh == DEFAULT_TX_FREE_THRESH ? + DEFAULT_TX_FREE_MPOOL_THRESH : + tx_conf->tx_free_thresh); + txq->tail = 0; + txq->head = 0; + + /* 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) { @@ -465,6 +642,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.1.0