From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on0043.outbound.protection.outlook.com [104.47.32.43]) by dpdk.org (Postfix) with ESMTP id 63F695F29 for ; Thu, 13 Sep 2018 13:36:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=AQUANTIA1COM.onmicrosoft.com; s=selector1-aquantia-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oe42r5pWXcaEJ0jXo1KGUnNRf5GtyGaG22fsO3C0kVI=; b=pXAFDGe2H4G0k7gPeezK3cbobRUTBd7mgazornfpLsiESc8m/VCjYoL3vVTq2cMbjVhqimZ9xWldtdg9K+aHMqksSSLMU1rzC1Wom/efc7JJyw5UY8qSmgX3T2yU6xOQKl2pblOj+RXs2Woah/DVL6ilMvDNSUYoFeDMomJ8Xrc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Igor.Russkikh@aquantia.com; Received: from ubuntubox.rdc.aquantia.com (95.79.108.179) by BLUPR0701MB1650.namprd07.prod.outlook.com (2a01:111:e400:58c6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.15; Thu, 13 Sep 2018 11:36:14 +0000 From: Igor Russkikh To: dev@dpdk.org Cc: pavel.belous@aquantia.com, igor.russkikh@aquantia.com Date: Thu, 13 Sep 2018 14:35:28 +0300 Message-Id: <1536838528-11800-21-git-send-email-igor.russkikh@aquantia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1536838528-11800-1-git-send-email-igor.russkikh@aquantia.com> References: <1536838528-11800-1-git-send-email-igor.russkikh@aquantia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [95.79.108.179] X-ClientProxiedBy: VI1PR0202CA0026.eurprd02.prod.outlook.com (2603:10a6:803:14::39) To BLUPR0701MB1650.namprd07.prod.outlook.com (2a01:111:e400:58c6::20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bf57287d-d24c-4a30-e824-08d6196d1da0 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:BLUPR0701MB1650; X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1650; 3:lyB8iLU0rkZksscKDq/0nDN5qDPhg3azj4ypudMllVQe7BF9iV6yzXVEl/m12RF0Jy3HqWJdDfc8vl4GztEfG1X7AyvkVcs+cnLYZryQ6wvAt/7C0+FHg+L4Wi553Ib1bwTtFVSmgK1jDgu2l3nzVjwrCLUiusjJEFWz1ZBiAzvdY8ECIpY7IS2rEDu2DFNTkV4GdR7qRbnxYQpfnzsEfFFyOzIUH9+JIIToWoSzJ2h770ASHFQBO96sYSLvPQEG; 25:mXRnVdC/328WSYOSHhyPaKTJcJMFJ4IdVfUtSqBf2WAaTxkS0lCjactF/XSVY79jdJ+C6S96t6Fpc1OeGus1mDTRPkNHDdLkp02kIVQTJLvOLxIToxz+1RW42dOj4PDh20e3ZknnyJi0OLcdcKE4okpmw016Hr0OtCQA/D9xrwtKq5cRCT3R0Vq0zab1E+FSoHTAj2CT4sm4dQZzD+4o0kzBrvcBbW5vU+Ap49R+uXwXikNHjhzcYulpOHA/lP4pBZXr/ROpyPSqFP1h2HqAz8FNYMdemlf4utQAw/AYX3GOGkfQY9Hro3CzNtV1FV/q4dianq6bJBSn05LA8VGHA6vbIRifSlV0c+2ds7k3gFQ=; 31:kqeNlxcnRxyN4YbpavFukw4dFKjSKTVBrPijLdogk69bMKs2ZDzcpWaQYPuY3LQ3TKs2bscU3U7ZW/FVSGLVBVmGHTQDpazyIBU4/u1MI81mBz/uOpnafVaZoWfQ7Zhs74iLKYq60jxLILanc5yzjTynj2QjgwUn+rSH47j5o5lve72yZQOkMys2Ll+A+yQTzer0HX7oyB/ftelu5PFbiWG78PkBdrhE6vmSTUW+jfo= X-MS-TrafficTypeDiagnostic: BLUPR0701MB1650: X-Microsoft-Exchange-Diagnostics: 1; BLUPR0701MB1650; 20:vH4pucOgXx9/P0hQNYGuVNMcRBI6eBuSy2OlXMIdEgSV9Lu7ZUyUsX1s4lNJXwqULBwyxz7FpUF7F7c2Of9GULEVPBTqVrxdnQnQoyrPag2cqOmXS8wt/jLMESYa5JByfs2WuhmDgyoz8gU2OM6QrCvLKzsU0LS7+i1Cnpuixj6QKfaKnMvjiR7wWaEVy5uVBPxVx8+oAyCy7d11g7M62Z4g6IiTjk8zPHDV9v23yjEzApk0kQtb8xMAvCxwe5krXSiiYCs+9NoMJmoHyurDVykEl9snH4kpznHVyY0uAlU0ukGDZlqE4OHpUJNVHw7DHMhWCHJROqSpPh92NGqmaudWwWci1kxiLGEt7P6WeoqCwgAabanlZUvM2iy7ndWqnZj5jet8VtJmUXG/hRTO8dk8CELL8iCsrX9QgUfy3DhB/o2OCvbA9IvmxdKngTdnb3Mr30YgKGmvwNdRj2FzoOQxjNcrOtLzE9UuOkpND+KjNz6IgDV/N8Qorzj5cnze; 4:HUr7JI+weQH5UILrFhQvSuITTJyU18jigo5GTU4+t/DbpYQWnZCWHRcVLzOKg4qDYRaO6ZAeUoVxm4bvIW+7AgQ0Z/d7FzMKhFfn1qf/BYsxZaZUexEpS+pJ/iSiLjZ8YL7Yxp/VLNTgM86KlEFmXTYodlNJPGpZFKjSvBGiKV8R7MEh5DnKN97/Z4Pqo9u0c8Y92PIhgdMTHXn2UWOM475uAg0hhFjmo7mrs94x/hRFhdabE6Vcy9yQngw20vqFdHqq35T3EBMDp5MaoRHY5g== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231311)(944501410)(52105095)(10201501046)(3002001)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(201708071742011)(7699050); SRVR:BLUPR0701MB1650; BCL:0; PCL:0; RULEID:; SRVR:BLUPR0701MB1650; X-Forefront-PRVS: 07943272E1 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39840400004)(366004)(396003)(376002)(136003)(346002)(199004)(189003)(6666003)(6916009)(97736004)(8936002)(68736007)(25786009)(50226002)(81166006)(81156014)(4326008)(107886003)(6486002)(51416003)(2906002)(53936002)(5660300001)(36756003)(86362001)(316002)(52116002)(8676002)(16586007)(7736002)(305945005)(11346002)(446003)(476003)(956004)(47776003)(72206003)(66066001)(44832011)(478600001)(486006)(186003)(26005)(16526019)(14444005)(386003)(48376002)(2351001)(106356001)(2361001)(2616005)(3846002)(105586002)(50466002)(7696005)(6116002)(76176011)(309714004); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR0701MB1650; H:ubuntubox.rdc.aquantia.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: aquantia.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR0701MB1650; 23:ZCNlKhg1fWy1jIEycsDoiOAROXLzglBlZalyA26?= =?us-ascii?Q?E++eRQCZFdbW9SnrbgRLPG92tdBuVzWOFBIiVKsCJHtBAq2UBNsZOMvqEuBD?= =?us-ascii?Q?ZmTN5mUfx9//asDbQlTtD/Y9EGK8gRp9hiXfcjEqiHPk304OgEJwLl/cbP4q?= =?us-ascii?Q?F/MGRu/5+MpILNzYGu31Lk9coI7JCZdYhwE+arXtqJuiLX2/yvnxTim8Gosg?= =?us-ascii?Q?bmk+0/6z5qz/nCT77X0poH2Vw3gjf1A2U6c7myHV7xN2hieCTAo7pj9ZE60S?= =?us-ascii?Q?3dIYUJAbLx4M9RVWbkqN/tcSGxVJQhB082Y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FJFAIw9ytrhAfqIGsg1uINr2dTbn+TbZaqLtDAa9MTonsllaLxcF3Hgl+guYaQfnZWYjAQOyktPolgulJ2ca3MunIxI4vxTfnilfZVCIDKzWm9TcBXl5V2pczEduktBMKgVtadVUUtc0IQ/jDTKOiCZ3kn3M9hF4QAI=; 7:SmEvZoL2QI5tvG5y/1367cNiY0YfOAdlzEMsUxXolDEqAP5EzWquuTAD07es9XoksiI9/YFicLeI00Tt6aCqGmY/IVh38oG2TnOIHGbPuuTtElvreF6Oen836ft6iYYWUwL5bTMqoJHFFhUNzYTs+58n5lUbBMpxwZNhVYaLEaUMruDqP82gDULOLz48nP0XpUlEiHN5CtMcQaqSVmsJ2USKhG3TPx+jUfQqh+DIN3QA5FsxOl+2QaPNR8e4Su7g SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2018 11:36:14.9800 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bf57287d-d24c-4a30-e824-08d6196d1da0 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 83e2e134-991c-4ede-8ced-34d47e38e6b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0701MB1650 Subject: [dpdk-dev] [PATCH v2 21/21] net/atlantic: TX side structures and implementation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Sep 2018 11:36:18 -0000 From: Pavel Belous Signed-off-by: Igor Russkikh --- drivers/net/atlantic/atl_ethdev.c | 10 + drivers/net/atlantic/atl_rxtx.c | 578 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 588 insertions(+) diff --git a/drivers/net/atlantic/atl_ethdev.c b/drivers/net/atlantic/atl_ethdev.c index 8f81761f3..1a5ec8907 100644 --- a/drivers/net/atlantic/atl_ethdev.c +++ b/drivers/net/atlantic/atl_ethdev.c @@ -304,6 +304,11 @@ static const struct eth_dev_ops atl_eth_dev_ops = { .rx_queue_setup = atl_rx_queue_setup, .rx_queue_release = atl_rx_queue_release, + .tx_queue_start = atl_tx_queue_start, + .tx_queue_stop = atl_tx_queue_stop, + .tx_queue_setup = atl_tx_queue_setup, + .tx_queue_release = atl_tx_queue_release, + .rx_queue_intr_enable = atl_dev_rx_queue_intr_enable, .rx_queue_intr_disable = atl_dev_rx_queue_intr_disable, @@ -331,6 +336,8 @@ static const struct eth_dev_ops atl_eth_dev_ops = { .mac_addr_set = atl_set_default_mac_addr, .set_mc_addr_list = atl_dev_set_mc_addr_list, .rxq_info_get = atl_rxq_info_get, + .txq_info_get = atl_txq_info_get, + .reta_update = atl_reta_update, .reta_query = atl_reta_query, .rss_hash_update = atl_rss_hash_update, @@ -648,6 +655,9 @@ atl_dev_start(struct rte_eth_dev *dev) } } + /* initialize transmission unit */ + atl_tx_init(dev); + /* This can fail when allocating mbufs for descriptor rings */ err = atl_rx_init(dev); if (err) { diff --git a/drivers/net/atlantic/atl_rxtx.c b/drivers/net/atlantic/atl_rxtx.c index 77009e095..5b9e216cd 100644 --- a/drivers/net/atlantic/atl_rxtx.c +++ b/drivers/net/atlantic/atl_rxtx.c @@ -46,6 +46,20 @@ #include "hw_atl/hw_atl_b0.h" #include "hw_atl/hw_atl_b0_internal.h" +#define ATL_TX_CKSUM_OFFLOAD_MASK ( \ + PKT_TX_IP_CKSUM | \ + PKT_TX_L4_MASK | \ + PKT_TX_TCP_SEG) + +#define ATL_TX_OFFLOAD_MASK ( \ + PKT_TX_VLAN_PKT | \ + PKT_TX_IP_CKSUM | \ + PKT_TX_L4_MASK | \ + PKT_TX_TCP_SEG) + +#define ATL_TX_OFFLOAD_NOTSUP_MASK \ + (PKT_TX_OFFLOAD_MASK ^ ATL_TX_OFFLOAD_MASK) + /** * Structure associated with each descriptor of the RX ring of a RX queue. */ @@ -54,6 +68,15 @@ struct atl_rx_entry { }; /** + * Structure associated with each descriptor of the TX ring of a TX queue. + */ +struct atl_tx_entry { + struct rte_mbuf *mbuf; + uint16_t next_id; + uint16_t last_id; +}; + +/** * Structure associated with each RX queue. */ struct atl_rx_queue { @@ -72,6 +95,22 @@ struct atl_rx_queue { bool l4_csum_enabled; }; +/** + * Structure associated with each TX queue. + */ +struct atl_tx_queue { + struct hw_atl_txd_s *hw_ring; + uint64_t hw_ring_phys_addr; + struct atl_tx_entry *sw_ring; + uint16_t nb_tx_desc; + uint16_t tx_tail; + uint16_t tx_head; + uint16_t queue_id; + uint16_t port_id; + uint16_t tx_free_thresh; + uint16_t tx_free; +}; + static inline void atl_reset_rx_queue(struct atl_rx_queue *rxq) { @@ -174,6 +213,140 @@ atl_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id, return 0; } +static inline void +atl_reset_tx_queue(struct atl_tx_queue *txq) +{ + struct atl_tx_entry *tx_entry; + union hw_atl_txc_s *txc; + uint16_t i; + + PMD_INIT_FUNC_TRACE(); + + if (!txq) { + PMD_DRV_LOG(ERR, "Pointer to txq is NULL"); + return; + } + + tx_entry = txq->sw_ring; + + for (i = 0; i < txq->nb_tx_desc; i++) { + txc = (union hw_atl_txc_s *)&txq->hw_ring[i]; + txc->flags1 = 0; + txc->flags2 = 2; + } + + for (i = 0; i < txq->nb_tx_desc; i++) { + txq->hw_ring[i].dd = 1; + tx_entry[i].mbuf = NULL; + } + + txq->tx_tail = 0; + txq->tx_head = 0; + txq->tx_free = txq->nb_tx_desc - 1; +} + +int +atl_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id, + uint16_t nb_tx_desc, unsigned int socket_id, + const struct rte_eth_txconf *tx_conf) +{ + struct atl_tx_queue *txq; + const struct rte_memzone *mz; + + PMD_INIT_FUNC_TRACE(); + + /* make sure a valid number of descriptors have been requested */ + if (nb_tx_desc < AQ_HW_MIN_TX_RING_SIZE || + nb_tx_desc > AQ_HW_MAX_TX_RING_SIZE) { + PMD_INIT_LOG(ERR, "Number of Tx descriptors must be " + "less than or equal to %d, " + "greater than or equal to %d", AQ_HW_MAX_TX_RING_SIZE, + AQ_HW_MIN_TX_RING_SIZE); + return -EINVAL; + } + + /* + * if this queue existed already, free the associated memory. The + * queue cannot be reused in case we need to allocate memory on + * different socket than was previously used. + */ + if (dev->data->tx_queues[tx_queue_id] != NULL) { + atl_tx_queue_release(dev->data->tx_queues[tx_queue_id]); + dev->data->tx_queues[tx_queue_id] = NULL; + } + + /* allocate memory for the queue structure */ + txq = rte_zmalloc_socket("atlantic Tx queue", sizeof(*txq), + RTE_CACHE_LINE_SIZE, socket_id); + if (txq == NULL) { + PMD_INIT_LOG(ERR, "Cannot allocate queue structure"); + return -ENOMEM; + } + + /* setup queue */ + txq->nb_tx_desc = nb_tx_desc; + txq->port_id = dev->data->port_id; + txq->queue_id = tx_queue_id; + txq->tx_free_thresh = tx_conf->tx_free_thresh; + + + /* allocate memory for the software ring */ + txq->sw_ring = rte_zmalloc_socket("atlantic sw tx ring", + nb_tx_desc * sizeof(struct atl_tx_entry), + RTE_CACHE_LINE_SIZE, socket_id); + if (txq->sw_ring == NULL) { + PMD_INIT_LOG(ERR, "Cannot allocate software ring"); + rte_free(txq); + return -ENOMEM; + } + + /* + * allocate memory for the hardware descriptor ring. A memzone large + * enough to hold the maximum ring size is requested to allow for + * resizing in later calls to the queue setup function. + */ + mz = rte_eth_dma_zone_reserve(dev, "tx hw_ring", tx_queue_id, + HW_ATL_B0_MAX_TXD * sizeof(struct hw_atl_txd_s), + 128, socket_id); + if (mz == NULL) { + PMD_INIT_LOG(ERR, "Cannot allocate hardware ring"); + rte_free(txq->sw_ring); + rte_free(txq); + return -ENOMEM; + } + txq->hw_ring = mz->addr; + txq->hw_ring_phys_addr = mz->iova; + + atl_reset_tx_queue(txq); + + dev->data->tx_queues[tx_queue_id] = txq; + return 0; +} + +int +atl_tx_init(struct rte_eth_dev *eth_dev) +{ + struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private); + struct atl_tx_queue *txq; + uint64_t base_addr = 0; + int i = 0; + int err = 0; + + PMD_INIT_FUNC_TRACE(); + + for (i = 0; i < eth_dev->data->nb_tx_queues; i++) { + txq = eth_dev->data->tx_queues[i]; + base_addr = txq->hw_ring_phys_addr; + + err = hw_atl_b0_hw_ring_tx_init(hw, base_addr, + txq->queue_id, + txq->nb_tx_desc, 0, + txq->port_id); + } + + return err; +} + int atl_rx_init(struct rte_eth_dev *eth_dev) { @@ -343,6 +516,77 @@ atl_rx_queue_release(void *rx_queue) } } +static void +atl_tx_queue_release_mbufs(struct atl_tx_queue *txq) +{ + int i; + + PMD_INIT_FUNC_TRACE(); + + if (txq->sw_ring != NULL) { + for (i = 0; i < txq->nb_tx_desc; i++) { + if (txq->sw_ring[i].mbuf != NULL) { + rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf); + txq->sw_ring[i].mbuf = NULL; + } + } + } +} + +int +atl_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id) +{ + struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private); + + PMD_INIT_FUNC_TRACE(); + + if (tx_queue_id < dev->data->nb_tx_queues) { + hw_atl_b0_hw_ring_tx_start(hw, tx_queue_id); + + rte_wmb(); + hw_atl_b0_hw_tx_ring_tail_update(hw, 0, tx_queue_id); + dev->data->tx_queue_state[tx_queue_id] = + RTE_ETH_QUEUE_STATE_STARTED; + } else { + return -1; + } + + return 0; +} + +int +atl_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id) +{ + struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private); + struct atl_tx_queue *txq; + + PMD_INIT_FUNC_TRACE(); + + txq = dev->data->tx_queues[tx_queue_id]; + + hw_atl_b0_hw_ring_tx_stop(hw, tx_queue_id); + + atl_tx_queue_release_mbufs(txq); + atl_reset_tx_queue(txq); + dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED; + + return 0; +} + +void +atl_tx_queue_release(void *tx_queue) +{ + PMD_INIT_FUNC_TRACE(); + + if (tx_queue != NULL) { + struct atl_tx_queue *txq = (struct atl_tx_queue *)tx_queue; + + atl_tx_queue_release_mbufs(txq); + rte_free(txq->sw_ring); + rte_free(txq); + } +} + void atl_free_queues(struct rte_eth_dev *dev) { @@ -355,6 +599,12 @@ atl_free_queues(struct rte_eth_dev *dev) dev->data->rx_queues[i] = 0; } dev->data->nb_rx_queues = 0; + + for (i = 0; i < dev->data->nb_tx_queues; i++) { + atl_tx_queue_release(dev->data->tx_queues[i]); + dev->data->tx_queues[i] = 0; + } + dev->data->nb_tx_queues = 0; } int @@ -364,6 +614,13 @@ atl_start_queues(struct rte_eth_dev *dev) PMD_INIT_FUNC_TRACE(); + for (i = 0; i < dev->data->nb_tx_queues; i++) { + if (atl_tx_queue_start(dev, i) != 0) { + PMD_DRV_LOG(ERR, "Start Tx queue %d failed", i); + return -1; + } + } + for (i = 0; i < dev->data->nb_rx_queues; i++) { if (atl_rx_queue_start(dev, i) != 0) { PMD_DRV_LOG(ERR, "Start Rx queue %d failed", i); @@ -381,6 +638,13 @@ atl_stop_queues(struct rte_eth_dev *dev) PMD_INIT_FUNC_TRACE(); + for (i = 0; i < dev->data->nb_tx_queues; i++) { + if (atl_tx_queue_stop(dev, i) != 0) { + PMD_DRV_LOG(ERR, "Stop Tx queue %d failed", i); + return -1; + } + } + for (i = 0; i < dev->data->nb_rx_queues; i++) { if (atl_rx_queue_stop(dev, i) != 0) { PMD_DRV_LOG(ERR, "Stop Rx queue %d failed", i); @@ -406,6 +670,19 @@ atl_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, qinfo->nb_desc = rxq->nb_rx_desc; } +void +atl_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, + struct rte_eth_txq_info *qinfo) +{ + struct atl_tx_queue *txq; + + PMD_INIT_FUNC_TRACE(); + + txq = dev->data->tx_queues[queue_id]; + + qinfo->nb_desc = txq->nb_tx_desc; +} + /* Return Rx queue avail count */ uint32_t @@ -478,6 +755,31 @@ atl_dev_rx_descriptor_status(void *rx_queue, uint16_t offset) return RTE_ETH_RX_DESC_AVAIL; } +int +atl_dev_tx_descriptor_status(void *tx_queue, uint16_t offset) +{ + struct atl_tx_queue *txq = tx_queue; + struct hw_atl_txd_s *txd; + uint32_t idx; + + PMD_INIT_FUNC_TRACE(); + + if (unlikely(offset >= txq->nb_tx_desc)) + return -EINVAL; + + idx = txq->tx_tail + offset; + + if (idx >= txq->nb_tx_desc) + idx -= txq->nb_tx_desc; + + txd = &txq->hw_ring[idx]; + + if (txd->dd) + return RTE_ETH_TX_DESC_DONE; + + return RTE_ETH_TX_DESC_FULL; +} + static int atl_rx_enable_intr(struct rte_eth_dev *dev, uint16_t queue_id, bool enable) { @@ -514,6 +816,47 @@ atl_dev_rx_queue_intr_disable(struct rte_eth_dev *eth_dev, uint16_t queue_id) return atl_rx_enable_intr(eth_dev, queue_id, false); } +uint16_t +atl_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) +{ + int i, ret; + uint64_t ol_flags; + struct rte_mbuf *m; + + PMD_INIT_FUNC_TRACE(); + + for (i = 0; i < nb_pkts; i++) { + m = tx_pkts[i]; + ol_flags = m->ol_flags; + + if (m->nb_segs > AQ_HW_MAX_SEGS_SIZE) { + rte_errno = -EINVAL; + return i; + } + + if (ol_flags & ATL_TX_OFFLOAD_NOTSUP_MASK) { + rte_errno = -ENOTSUP; + return i; + } + +#ifdef RTE_LIBRTE_ETHDEV_DEBUG + ret = rte_validate_tx_offload(m); + if (ret != 0) { + rte_errno = ret; + return i; + } +#endif + ret = rte_net_intel_cksum_prepare(m); + if (ret != 0) { + rte_errno = ret; + return i; + } + } + + return i; +} + static uint64_t atl_desc_to_offload_flags(struct atl_rx_queue *rxq, struct hw_atl_rxd_wb_s *rxd_wb) @@ -785,3 +1128,238 @@ atl_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) return nb_rx; } + +static void +atl_xmit_cleanup(struct atl_tx_queue *txq) +{ + struct atl_tx_entry *sw_ring; + struct hw_atl_txd_s *txd; + int to_clean = 0; + + PMD_INIT_FUNC_TRACE(); + + if (txq != NULL) { + sw_ring = txq->sw_ring; + int head = txq->tx_head; + int cnt; + int i; + + for (i = 0, cnt = head; ; i++) { + txd = &txq->hw_ring[cnt]; + + if (txd->dd) + to_clean++; + + cnt = (cnt + 1) % txq->nb_tx_desc; + if (cnt == txq->tx_tail) + break; + } + + if (to_clean == 0) + return; + + while (to_clean) { + txd = &txq->hw_ring[head]; + + struct atl_tx_entry *rx_entry = &sw_ring[head]; + + if (rx_entry->mbuf) { + rte_pktmbuf_free_seg(rx_entry->mbuf); + rx_entry->mbuf = NULL; + } + + if (txd->dd) + to_clean--; + + txd->buf_addr = 0; + txd->flags = 0; + + head = (head + 1) % txq->nb_tx_desc; + txq->tx_free++; + } + + txq->tx_head = head; + } +} + +static int +atl_tso_setup(struct rte_mbuf *tx_pkt, union hw_atl_txc_s *txc) +{ + uint32_t tx_cmd = 0; + uint64_t ol_flags = tx_pkt->ol_flags; + + PMD_INIT_FUNC_TRACE(); + + if (ol_flags & PKT_TX_TCP_SEG) { + PMD_DRV_LOG(DEBUG, "xmit TSO pkt"); + + tx_cmd |= tx_desc_cmd_lso | tx_desc_cmd_l4cs; + + txc->cmd = 0x4; + + if (ol_flags & PKT_TX_IPV6) + txc->cmd |= 0x2; + + txc->l2_len = tx_pkt->l2_len; + txc->l3_len = tx_pkt->l3_len; + txc->l4_len = tx_pkt->l4_len; + + txc->mss_len = tx_pkt->tso_segsz; + } + + if (ol_flags & PKT_TX_VLAN_PKT) { + tx_cmd |= tx_desc_cmd_vlan; + txc->vlan_tag = tx_pkt->vlan_tci; + } + + if (tx_cmd) { + txc->type = tx_desc_type_ctx; + txc->idx = 0; + } + + return tx_cmd; +} + +static inline void +atl_setup_csum_offload(struct rte_mbuf *mbuf, struct hw_atl_txd_s *txd, + uint32_t tx_cmd) +{ + txd->cmd |= tx_desc_cmd_fcs; + txd->cmd |= (mbuf->ol_flags & PKT_TX_IP_CKSUM) ? tx_desc_cmd_ipv4 : 0; + /* L4 csum requested */ + txd->cmd |= (mbuf->ol_flags & PKT_TX_L4_MASK) ? tx_desc_cmd_l4cs : 0; + txd->cmd |= tx_cmd; +} + +static inline void +atl_xmit_pkt(struct aq_hw_s *hw, struct atl_tx_queue *txq, + struct rte_mbuf *tx_pkt) +{ + struct atl_adapter *adapter = + ATL_DEV_TO_ADAPTER(&rte_eth_devices[txq->port_id]); + uint32_t pay_len = 0; + int tail = 0; + struct atl_tx_entry *tx_entry; + uint64_t buf_dma_addr; + struct rte_mbuf *m_seg; + union hw_atl_txc_s *txc = NULL; + struct hw_atl_txd_s *txd = NULL; + u32 tx_cmd = 0U; + int desc_count = 0; + + PMD_INIT_FUNC_TRACE(); + + tail = txq->tx_tail; + + txc = (union hw_atl_txc_s *)&txq->hw_ring[tail]; + + txc->flags1 = 0U; + txc->flags2 = 0U; + + tx_cmd = atl_tso_setup(tx_pkt, txc); + + if (tx_cmd) { + /* We've consumed the first desc, adjust counters */ + tail = (tail + 1) % txq->nb_tx_desc; + txq->tx_tail = tail; + txq->tx_free -= 1; + + txd = &txq->hw_ring[tail]; + txd->flags = 0U; + } else { + txd = (struct hw_atl_txd_s *)txc; + } + + txd->ct_en = !!tx_cmd; + + txd->type = tx_desc_type_desc; + + atl_setup_csum_offload(tx_pkt, txd, tx_cmd); + + if (tx_cmd) + txd->ct_idx = 0; + + pay_len = tx_pkt->pkt_len; + + txd->pay_len = pay_len; + + for (m_seg = tx_pkt; m_seg; m_seg = m_seg->next) { + if (desc_count > 0) { + txd = &txq->hw_ring[tail]; + txd->flags = 0U; + } + + buf_dma_addr = rte_mbuf_data_iova(m_seg); + txd->buf_addr = rte_cpu_to_le_64(buf_dma_addr); + + txd->type = tx_desc_type_desc; + txd->len = m_seg->data_len; + txd->pay_len = pay_len; + + /* Store mbuf for freeing later */ + tx_entry = &txq->sw_ring[tail]; + + if (tx_entry->mbuf) + rte_pktmbuf_free_seg(tx_entry->mbuf); + tx_entry->mbuf = m_seg; + + tail = (tail + 1) % txq->nb_tx_desc; + + desc_count++; + } + + // Last descriptor requires EOP and WB + txd->eop = 1U; + txd->cmd |= tx_desc_cmd_wb; + + hw_atl_b0_hw_tx_ring_tail_update(hw, tail, txq->queue_id); + + txq->tx_tail = tail; + + txq->tx_free -= desc_count; + + adapter->sw_stats.q_opackets[txq->queue_id]++; + adapter->sw_stats.q_obytes[txq->queue_id] += pay_len; +} + +uint16_t +atl_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) +{ + struct rte_eth_dev *dev = NULL; + struct aq_hw_s *hw = NULL; + struct atl_tx_queue *txq = tx_queue; + struct rte_mbuf *tx_pkt; + uint16_t nb_tx; + + dev = &rte_eth_devices[txq->port_id]; + hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private); + + PMD_TX_LOG(DEBUG, "txq%d pkts: %d tx_free=%d tx_tail=%d tx_head=%d", + txq->queue_id, nb_pkts, txq->tx_free, + txq->tx_tail, txq->tx_head); + + for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) { + tx_pkt = *tx_pkts++; + + /* Clean Tx queue if needed */ + if (txq->tx_free < txq->tx_free_thresh) + atl_xmit_cleanup(txq); + + /* Check if we have enough free descriptors */ + if (txq->tx_free < tx_pkt->nb_segs) + break; + + /* check mbuf is valid */ + if ((tx_pkt->nb_segs == 0) || + ((tx_pkt->nb_segs > 1) && (tx_pkt->next == NULL))) + break; + + /* Send the packet */ + atl_xmit_pkt(hw, txq, tx_pkt); + } + + PMD_TX_LOG(DEBUG, "atl_xmit_pkts %d transmitted", nb_tx); + + return nb_tx; +} + -- 2.13.3.windows.1