From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-bn1-obe.outbound.protection.outlook.com (mail-bn1bon0096.outbound.protection.outlook.com [157.56.111.96]) by dpdk.org (Postfix) with ESMTP id 3E5509AF5 for ; Tue, 7 Jun 2016 18:41:53 +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=aggmx4z1Ync3dmhMdjz9DklkYpcBdGPMse78FPkG2i4=; b=njbeBayZUUjT1HMElSVQbBKoGK00RuVshfzf8ic8sNXbbgAZOwFOQWGZslXPtnhb8NTvah3YL35mx78GA9+1qwsnaoA4D2m8IUhUtYLAFfhyxm0z0c9VUdTPSpoRAFBFGz48bibNPGTRZEM3IGAJPya3c3EQPI2wECPutStjlGo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jerin.Jacob@cavium.com; Received: from localhost.caveonetworks.com (111.93.218.67) by BN3PR0701MB1719.namprd07.prod.outlook.com (10.163.39.18) with Microsoft SMTP Server (TLS) id 15.1.511.8; Tue, 7 Jun 2016 16:41:48 +0000 From: Jerin Jacob To: CC: , , Jerin Jacob , Maciej Czekaj , Kamil Rytarowski , Zyta Szpak , Slawomir Rosek , Radoslaw Biernacki Date: Tue, 7 Jun 2016 22:10:20 +0530 Message-ID: <1465317632-11471-9-git-send-email-jerin.jacob@caviumnetworks.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1465317632-11471-1-git-send-email-jerin.jacob@caviumnetworks.com> References: <1464540424-12631-1-git-send-email-jerin.jacob@caviumnetworks.com> <1465317632-11471-1-git-send-email-jerin.jacob@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: MAXPR01CA0054.INDPRD01.PROD.OUTLOOK.COM (10.164.146.154) To BN3PR0701MB1719.namprd07.prod.outlook.com (10.163.39.18) X-MS-Office365-Filtering-Correlation-Id: 9480da4a-4842-4f1f-088b-08d38ef2a070 X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1719; 2:/K5nYG7MSEBKGlmUZXvupe1uzM5s0XNSsN5pGFeTTP82baTrUhZa00ktqzKt7PBHtjIkGgA6xFRsKjNydvjWQrJx12Lb5PKPditLnMfQVYIc8fKAT688D1mzThhe03fxu0KGdVBOJMyqmikI1Nu5/eeD6iyxuXQoU1Vy5RJydflglJGlPfodZ0uJ9Vjow+yh; 3:oPjgc5f/nyITCPUq4XUbdwap6U9WBXeIw9hzxHDxbs9bmoJI/5E8f7mMBRrx1Az6p50E9F4G0b5KGXKxTRNOp8v3afVEH+9euM119VFC4O+0y/Hn9JSDQ0i3nmnlc/Ft X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR0701MB1719; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1719; 25:eoHoulIR3pdsQLUAcoX5tME1j+0ewlyuN+y4vZZKkulst+AtAXl76Jqqo1tfHy6Y3pNBbpLvNGqeNHtc9qrMTxCu7HxeC+40T8QtwYijayHqHXFD6nAZhLRa2gA9gB1mJyjI23SX3YDs6Y6TxFAJ6WxnsDOH0ICW5W2iLDYdKjJln08a4JgvSLDbTfCgqxrbV6dA05lwHX/6lMOdYQCqcIfLS6tG8lPKi0aH0IhuIuWO2UuwEJgGMArbWZz4zjIGu3WU7eFQQ6eE7M+go21EZ5bFGhz/b+C6SjlPwtgfEkeeEzoYULATC48ZfxDz0zUnIfbeon50pq3SOAdDGPj+hqMkBNu7BnpuCMOEXtjMQOQd0jpTkO2tETpLo2Yy1YFSTsvE1ksv9lNZwjWyQhYxxgdn1l9zcfp79+cSjPVNtipbd9EqKVlQoMy6K1bfaJ/xmDcDwmQo9HEf2+DHkLIx0s0HXD9tmiQKlEwQwwvbaL8bCd7xofj40lbs8NxP1Y9w5kYNt4MjSIkCINVLSj+FhY74H81YzFJyds4PCDC98kzyU64FhH6x604RLuJxXyiCPCWIqDgIa/vFWxYV0ts8BSVPxNnSRb0PFxyp6MLhG8C6wHqp/qkysor3p4cm4TTX5fwnMxIY0RL45Onk6V8XGZkGyYDbTbx9JPfj71OQeA15Ro8N8HBNyw3gqIfTTrt3G/V7omzcwz/qqiHCrfCJncrMucctailV+Qocj0VLwOs= X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1719; 20:g97xn83yAA8wTyJFDdwW4KPRuEeKx9YSTHhyIL5xPDkpwE5nfy40GfX6ggo80xOkYOzdVgjG+7I7wvakkqLFHt4+B3UPxwIXUZLKC6P7UaoKL/CuZ/opSkwcVZox1LX6Q+sutgJXM06AZYf3Yp4yV07LrETCYc9AllpvpSf4ZeqO5attKfgv8Xrgt8fFa09wPUm3GWtOfybNAUXQhkf1o0VcMhNbzyQNCQhSGlODSEoTWUhigkogv0u75XHk+5ZAkVM53k0r4is+QYE0qf5WszVLskTyYTfm+wV/3qvu0wO53RU7bTtkBhOuJ/9iHUEQNjdFfPcRQz71Qg24Sxuz4iDvFoH50NqI91RrMCH+UTTicDlwWs6h9/J9dzPTTk2pNXOzWftiy0Ga7Tjhb4yRzhoFJcOacW4E5HCiTSS8CsU5/2fJfdTDAz8YY6wFttXC0YiZqzhvaYGnCtDrh+GO57ZW0PyLKnLIpQqfZwJHaY3APSPfEhTRrI5sTm2lZ92u9Z/9YKdwImUOj4zky2+IXDRtzHRn6oO88q5kTMG0sn7syd5YmeZHQM9CHmPaPLFI8BJCf8RXVAf4Xdkex+TvSvYoNdiNAVdyGsPxj/1nHhw= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046); SRVR:BN3PR0701MB1719; BCL:0; PCL:0; RULEID:; SRVR:BN3PR0701MB1719; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1719; 4:jui4q5VlurULjAipZPAjjKWYNkhchwLu0i2Gydy/VpTf1xHdas8HIHxobAWgBBSdoMuCUvPkrCaGCMqBcKAjPAGt06aa/NdItwkiG2foL/ed1awqQL/q4Dnt7qO+ZfRzXTQvljFf0zQDTDPOI+fdbF1YGqybJNmIDSd/TEbOx8lJbdQj1TsSF0u/Flc3E7aBCoYFyoa1Xj6/5Cr98wWxoLuq6qp82QS8dK/zVqu0d2AeJ+82n26o/xYA+JO59lLkNbrEPerkXoSyawQINIDUtLp3gBRwS9O68TA+ms/7fEaSxQB36WVcHn4bdb/UGUon71ZVevd6jKihqfhLg61z8QgEOoWm6W1cDznyufQwuA6IAKidGYvfpEdpKJY+HKpf X-Forefront-PRVS: 09669DB681 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(199003)(189002)(81166006)(8676002)(81156014)(47776003)(66066001)(36756003)(92566002)(2950100001)(586003)(2351001)(48376002)(76506005)(42186005)(50466002)(4326007)(77096005)(3846002)(6116002)(5003940100001)(53416004)(5004730100002)(105586002)(97736004)(2906002)(5008740100001)(106356001)(189998001)(19580395003)(69596002)(101416001)(110136002)(19580405001)(68736007)(33646002)(76176999)(50986999)(229853001)(50226002)(5009440100003)(7099028); DIR:OUT; SFP:1101; SCL:1; SRVR:BN3PR0701MB1719; H:localhost.caveonetworks.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN3PR0701MB1719; 23:5ZO678Oj0Y6G2aMf9bKo5RtjDOCbImv46V48BOm?= =?us-ascii?Q?/r/2WHcuGty60OnWWl6asBfZYiHwO34PK1RdUAHVKnWJSYLLz4C58EeGsjKw?= =?us-ascii?Q?/g44OP0EqeSkich/bnujmxIo8mgnVXTexHv2CCWi55O8GL90SRqMqenzDVRb?= =?us-ascii?Q?Y7vGAyzwGgFNQ+8S96NZVck/M+Jw1+/RAC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XNaIdol5Bk+CMTU6WbBQq5DYhGjp2Llu5RsOXPwb/Myqyc/?= =?us-ascii?Q?7XPiJu9QrCrv0wTBJKvQX9eQzfMXiUtZSUr5GqMeFq4n7+6V9WzFwEg=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1719; 5:HqApd7aIaF4EyKTndZiE1Ef0oN1B27xb7IG8IPxolQSlAcMGX0zrJ6MGJhPNlbsKIDhOzwLxJ+cE9W6sTKSuE36lARyoRiwCpLNL4UcoSJWL2ongbClgiCHLjo9vr5xSiDAqGMWzRujdog7e2wx7Vg==; 24:vWzmaV5cokFm9GF3rsf/aFP0FM7iVAgY699k6MiYxbYAwqXvESDhGlzNeROJHwYL8/h1VsXofoKiLmoqi1InFg9bC0ZGure6fCRdYaz6QxU=; 7:b3qvziMfXLLCEso8kVdwScNz7D2h/qYcw/RRVUZ4knlNXh85hp331QTxU5uIcs9MWnahkKer/ASxlEYQwOzn8GKMdBGw1Qz+wwnzNa6kZ2Jet1hRPJTG0HHUee+mNd0Mgp2ypVeZa0wLDDTDyGx444QcCdlQlDthr0JKiWOgDoZAmKpqJ/8ndQli2aCl9A+k2/837o6anxJNewcx35MegvSFqk9n76G8cYC5EBMSwIk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jun 2016 16:41:48.5531 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR0701MB1719 Subject: [dpdk-dev] [PATCH v3 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: Tue, 07 Jun 2016 16:41:53 -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 6150ef0..0891a26 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); @@ -204,6 +208,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 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 : + 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) { @@ -443,6 +620,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