From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20079.outbound.protection.outlook.com [40.107.2.79]) by dpdk.org (Postfix) with ESMTP id CF5425A44 for ; Thu, 13 Sep 2018 11:42:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FhGQbkCbFxXKCogO6CxmLtkxrqNNm42F0AeOe/gvKq8=; b=WqhaTHmQicaPR+cz+6hkvtlxLhpRCLBbPB1vQQXucIFZFcTj2Enb3Zu0J4DZDt/WApa9anlYljlSJ3UhQ+mcwJMNzzlHD1Mz//dUAQLtMiG8rflkWrIKeELCwZYSzJmG9ZwUGzrzjnCG26ORibDoECa1vLf5bdveUyExSfUCpWA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=G.Singh@nxp.com; Received: from Tophie.ap.freescale.net (14.142.187.166) by VI1PR04MB1533.eurprd04.prod.outlook.com (2a01:111:e400:596a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1122.17; Thu, 13 Sep 2018 09:42:34 +0000 From: Gagandeep Singh To: dev@dpdk.org, ferruh.yigit@intel.com Cc: pankaj.chauhan@nxp.com, Gagandeep Singh Date: Thu, 13 Sep 2018 15:12:01 +0530 Message-Id: <20180913094201.17098-4-g.singh@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180913094201.17098-1-g.singh@nxp.com> References: <20180906055449.21731-1-g.singh@nxp.com> <20180913094201.17098-1-g.singh@nxp.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [14.142.187.166] X-ClientProxiedBy: PN1PR0101CA0029.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:c::15) To VI1PR04MB1533.eurprd04.prod.outlook.com (2a01:111:e400:596a::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d4b9b096-e343-4c3a-10b7-08d6195d3c39 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989137)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:VI1PR04MB1533; X-Microsoft-Exchange-Diagnostics: 1; VI1PR04MB1533; 3:iC20r8I4fkmx/1K9ydODuWqItNWY9lVxEVVNxuGnXk2zBRmMtvkZBPzgikxImbG8UOdh6ioZ1OfoQVhGpFFT0sWPAuPjDdpBRdh8IQYgwji5+eCpxmaRcqkc2Ng/4NDYXfOeHP+WOKObkS/prWNFB7ln8BAhiOif90R1izSjGDHGb5bLwJZz9du896Kzp1+W6RbWRS5SrmMPwFtQ3TJhra8WW8JxFD11mRr8h1yaad2eOtJE7a4d7uC9CmBJ5e8s; 25:u+vj729IyqhQdpNldaPsQ8u5mLT3tS5o8vH9yuAIsr9MOWmzYPQ1pEV67wDDdYojeIfHL/g54pjhI7hEOWAR4UEyyk59mU/D+IPCIoqogGmq5uK4puUCCtLyxjqn61pq6TSdT7/ULFA+mQ8vQf0KcXW8nbvEVl66AMm0M6dKDxUJo+rJvchnYcpf7MTk0OFf93yrrIUU+4/gyA1jfP2O15ym7TATba3SWZIdgK6aYtusTLXwKRZF2nxArvV352wQzo3Wn7xKKRBzyYbW5raLEFpTIjevcxqBoa98OsukYbZCAr/rxIFvkw5OSMf0JFBzyHXIjo65wzuZYDP3dPL94w==; 31:4SOiZQbBS6LCkVQ+xPQCE9FHPPwHgFfStswLZdJVSYbk1Io2yOnwO4mH+TaQAvtNN1fGMMBEKCp0M8kThIo6LaPTLiUtgDvBlj1j0C2afxulnDDF45+E0E/TlFHdnlWP3mejnW0vWy//5AlVXrL5CjkcANxZQwjq7J1QRZJks+JsCoVUQLcrav+iIQ2dnSLyjYgxvNlQ8QxrZRGj9hmhvc1vZa4jNNcr7UtS8WlwL5E= X-MS-TrafficTypeDiagnostic: VI1PR04MB1533: X-Microsoft-Exchange-Diagnostics: 1; VI1PR04MB1533; 20:mmSAMrSmgGUVDQ6FQ9+4vSzqlYCfUmr+g4vvXuu8Ld6CGFsPI0dAhnkpbDPteo8pRVZBc+boC262V8ZT0GUOpRU6J69VsqqyaTlOfro1H352+5w2bOasKJOBt/Bjy5NrlgYCLeCuV+1OL0yaCqncRq6SiBrsKkRtCjBhSMI7WF30N8WEQNTVnnozXqcyhFyHPh4zh9ICZ8+DmTjmbE7nQ3hK+At5LGak1y2NKM1XFXEfsiDL5lhDG21tc14mgBdmDHWLVCd64KPi3a7g/oTKV7Q3sShGXx9hVuRAcCGH+QhgitDIgxGX7dtJ6sk2faugnYpboqYl+98W8M6p3bmbAxmym75iQ8AIoTv2xu+aeMRbxrIWbeDhZ7u9DT2xaIDxvtDJ+k2M4+TPfBcduDkMNSE3mzTy9sj5l2VCjR6dEdlC5L5gC6KCg8S4ZKXo3uxcZXZKMO0kqbpIb3twr3W875H3XY8bOYOivfv2MZHOEqGWET7CZThpd4CxFdgmcC3X; 4:KYJgMbESLXk35uVOZVkpr3hvQ1F0mYrUsP43m+lKPiOLT7sTGTqyeKaCg/Jb4FA9Eechx3cwv48P7/PLrmVFY0OQ8kqNeshWXSYJXVks6lZRc2Bg+dzfejS461tFDn6JO+9tIzkFlrzxQb1wdIA4NJgJKSOPPeU5Kl8w0PwN9+YLSeDDfoSJ5WSiRrHh/jDdzXoqtZb5iOp7ezshkfvkgmZkd/N3UlBeepatXKh0EbYbnEEXmtNLJg03RaNCJMX9H9Btfph8ql5xGBiPJoWBe9iZ4t1QAQrsvL7LjIGHkT8m0Eaxd0qDTA8mzVl/eyhC X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(823301075)(3231311)(944501410)(52105095)(3002001)(10201501046)(93006095)(93001095)(6055026)(149027)(150027)(6041310)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699050); SRVR:VI1PR04MB1533; BCL:0; PCL:0; RULEID:; SRVR:VI1PR04MB1533; X-Forefront-PRVS: 07943272E1 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(979002)(39860400002)(136003)(396003)(346002)(376002)(366004)(199004)(189003)(22813001)(105586002)(68736007)(48376002)(106356001)(50466002)(11346002)(486006)(76176011)(7736002)(36756003)(305945005)(51416003)(52116002)(86362001)(575784001)(72206003)(478600001)(8936002)(47776003)(50226002)(2616005)(476003)(316002)(446003)(956004)(16586007)(66066001)(4326008)(186003)(16526019)(53936002)(6486002)(26005)(14444005)(97736004)(6116002)(6666003)(6512007)(3846002)(55236004)(2906002)(5009440100003)(6506007)(386003)(8676002)(5660300001)(81156014)(1076002)(25786009)(81166006)(110426005)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR04MB1533; H:Tophie.ap.freescale.net; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR04MB1533; 23:qEBU/qcyjJbIjw6hgpjxQz8KB+JJHu63nFeRw+FXC?= =?us-ascii?Q?cwMRETh0TfViXSStq/mp/HtmIr74IiQ8XQgJaBBiz+1H/dPCUuZvxE6cUitj?= =?us-ascii?Q?xyKLSZ5WsrYmWeUmLgDr/pB8GkkbOrCCGpDkHag9ENdegoe3cVyeXwo0aa98?= =?us-ascii?Q?xRuGh81ESRz7vqGa3S/wn4CQ+ZUXmjnG3if1m6zAUr3fvGRI4JWnbqmGE13O?= =?us-ascii?Q?IfgoE8seYzSxuYj06dGpj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8Eo8lOo09EvpBMZ9CTxwakZcoMPZ2DMt7rzikvFe7ID5XFryWTSTDcrShD1fLRofp1K79JTW3unXaJUIZromQGU06YeMZ03vZGJD/OTtsBDCj2bG+4yAGoorLb5g/4764WhKv8HnhHrnNAODxGUAuXEIoWMI2SOMrXHHg/dx/7rdnGOo1X5JLKAXmkz47U9SmQbxLffAGzAx2hO/Q==; 5:0+7DLLevLi6H1Bdtm4DENuNYkulRCUcZUaoq6fBCiukHIPtAHj5fOW2O4jdz6W/rH4KQe1ksH00FIrxdZ8Eec91ivcnShbIsfZ+v+7AAu4Ndgi/nNg/kWSRbA3O+5NyonnG/2mt3V5TdtuGU1N75CKjUJZg1jP8kf4pljKVeGJ8=; 7:nt1PLGgFiuw+4xgqpCMc5zY6hY+Hv/HbuqXpKTxTorMg/CQUdYK9KhJQUbVm9H1iIx9Cus+DAr41Ee2u35NSMR8ZjnqUsGTpxE9vCUIbozhzjb8CQvfvz+tcPGz2uycoLvck+NCcQMhePt/6gQ2M0E6l346bhBeZaVzzZhOWi5W+LMomh4HnizpTC5wt+8L1yAYfFXOVz4/+qM6e/IKmDdaTWkhMFJ4V+wrUFFcKyp57mxBulHfffzgHhJLWFQ1P SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2018 09:42:34.1900 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d4b9b096-e343-4c3a-10b7-08d6195d3c39 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB1533 Subject: [dpdk-dev] [PATCH v2 3/3] net/enetc: enable Rx and Tx 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 09:42:38 -0000 Add RX and TX queue setup, datapath functions and enable the packet parsing Signed-off-by: Gagandeep Singh --- MAINTAINERS | 1 + drivers/net/enetc/Makefile | 3 +- drivers/net/enetc/enetc_ethdev.c | 6 +- drivers/net/enetc/enetc_rxtx.c | 447 +++++++++++++++++++++++++++++++ drivers/net/enetc/meson.build | 3 +- 5 files changed, 456 insertions(+), 4 deletions(-) create mode 100644 drivers/net/enetc/enetc_rxtx.c diff --git a/MAINTAINERS b/MAINTAINERS index fc70ac049..b67f2afa4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -645,6 +645,7 @@ F: doc/guides/nics/features/dpaa2.ini NXP enetc M: Gagandeep Singh +M: Pankaj Chauhan F: drivers/net/enetc/ F: doc/guides/nics/enetc.rst F: doc/guides/nics/features/enetc.ini diff --git a/drivers/net/enetc/Makefile b/drivers/net/enetc/Makefile index 3f4ba97da..1f886831a 100644 --- a/drivers/net/enetc/Makefile +++ b/drivers/net/enetc/Makefile @@ -16,8 +16,9 @@ LIBABIVER := 1 # all source are stored in SRCS-y # SRCS-$(CONFIG_RTE_LIBRTE_ENETC_PMD) += enetc_ethdev.c +SRCS-$(CONFIG_RTE_LIBRTE_ENETC_PMD) += enetc_rxtx.c -LDLIBS += -lrte_eal +LDLIBS += -lrte_eal -lrte_mempool LDLIBS += -lrte_ethdev LDLIBS += -lrte_bus_pci diff --git a/drivers/net/enetc/enetc_ethdev.c b/drivers/net/enetc/enetc_ethdev.c index 06438835d..67106593f 100644 --- a/drivers/net/enetc/enetc_ethdev.c +++ b/drivers/net/enetc/enetc_ethdev.c @@ -37,6 +37,8 @@ static const struct eth_dev_ops enetc_ops = { .dev_close = enetc_dev_close, .link_update = enetc_link_update, .dev_infos_get = enetc_dev_infos_get, + .rx_queue_setup = enetc_rx_queue_setup, + .tx_queue_setup = enetc_tx_queue_setup, }; /** @@ -61,8 +63,8 @@ enetc_dev_init(struct rte_eth_dev *eth_dev) PMD_INIT_FUNC_TRACE(); eth_dev->dev_ops = &enetc_ops; - eth_dev->rx_pkt_burst = NULL; - eth_dev->tx_pkt_burst = NULL; + eth_dev->rx_pkt_burst = &enetc_recv_pkts; + eth_dev->tx_pkt_burst = &enetc_xmit_pkts; rte_eth_copy_pci_info(eth_dev, pci_dev); diff --git a/drivers/net/enetc/enetc_rxtx.c b/drivers/net/enetc/enetc_rxtx.c new file mode 100644 index 000000000..b01f64b0c --- /dev/null +++ b/drivers/net/enetc/enetc_rxtx.c @@ -0,0 +1,447 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2018 NXP + */ + +#include +#include +#include + +#include "rte_ethdev.h" +#include "rte_malloc.h" +#include "rte_memzone.h" + +#include "base/enetc_hw.h" +#include "enetc.h" +#include "enetc_logs.h" + +#define ENETC_RXBD_BUNDLE 8 /* Number of BDs to update at once */ + +static inline int enetc_bd_unused(struct enetc_bdr *bdr) +{ + if (bdr->next_to_clean > bdr->next_to_use) + return bdr->next_to_clean - bdr->next_to_use - 1; + + return bdr->bd_count + bdr->next_to_clean - bdr->next_to_use - 1; +} + +static bool enetc_clean_tx_ring(struct enetc_bdr *tx_ring) +{ + int tx_frm_cnt = 0; + struct enetc_swbd *tx_swbd; + int i; + + i = tx_ring->next_to_clean; + tx_swbd = &tx_ring->q_swbd[i]; + while ((int)(enetc_rd_reg(tx_ring->tcisr) & ENETC_TBCISR_IDX_MASK) != i) { + rte_pktmbuf_free(tx_swbd->buffer_addr); + tx_swbd->buffer_addr = NULL; + tx_swbd++; + i++; + if (unlikely(i == tx_ring->bd_count)) { + i = 0; + tx_swbd = &tx_ring->q_swbd[0]; + } + + tx_frm_cnt++; + } + tx_ring->next_to_clean = i; + return tx_frm_cnt++; +} + +uint16_t enetc_xmit_pkts(void *tx_queue, + struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) +{ + struct enetc_swbd *tx_swbd; + int i, start; + struct enetc_tx_bd *txbd; + struct enetc_bdr *tx_ring = (struct enetc_bdr *)tx_queue; + + i = tx_ring->next_to_use; + start = 0; + while (nb_pkts--) { + enetc_clean_tx_ring(tx_ring); + + tx_ring->q_swbd[i].buffer_addr = tx_pkts[start]; + + txbd = ENETC_TXBD(*tx_ring, i); + tx_swbd = &tx_ring->q_swbd[i]; + txbd->frm_len = tx_pkts[start]->pkt_len; + txbd->buf_len = txbd->frm_len; + txbd->flags = rte_cpu_to_le_16(ENETC_TXBD_FLAGS_F); + txbd->addr = + (uint64_t)rte_cpu_to_le_64(tx_swbd->buffer_addr->buf_addr + + tx_swbd->buffer_addr->data_off); + i++; + start++; + if (unlikely(i == tx_ring->bd_count)) + i = 0; + } + tx_ring->next_to_use = i; + enetc_wr_reg(tx_ring->tcir, i); + return start; +} + +static int enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt) +{ + struct enetc_swbd *rx_swbd; + union enetc_rx_bd *rxbd; + int i, j; + + i = rx_ring->next_to_use; + rx_swbd = &rx_ring->q_swbd[i]; + rxbd = ENETC_RXBD(*rx_ring, i); + + for (j = 0; j < buff_cnt; j++) { + rx_swbd->buffer_addr = + rte_cpu_to_le_64(rte_mbuf_raw_alloc(rx_ring->mb_pool)); + rxbd->w.addr = (uint64_t)rx_swbd->buffer_addr->buf_addr + + rx_swbd->buffer_addr->data_off; + /* clear 'R" as well */ + rxbd->r.lstatus = 0; + rx_swbd++; + rxbd++; + i++; + + if (unlikely(i == rx_ring->bd_count)) { + i = 0; + rxbd = ENETC_RXBD(*rx_ring, 0); + rx_swbd = &rx_ring->q_swbd[i]; + } + } + if (likely(j)) { + rx_ring->next_to_alloc = i; + rx_ring->next_to_use = i; + enetc_wr_reg(rx_ring->rcir, i); + } + return j; +} + + +static inline void __attribute__((hot)) +enetc_dev_rx_parse(struct rte_mbuf *m, uint16_t parse_results) +{ + ENETC_PMD_DP_DEBUG("parse summary = 0x%x ", parse_results); + + m->packet_type = RTE_PTYPE_UNKNOWN; + switch (parse_results) { + case ENETC_PKT_TYPE_ETHER: + m->packet_type = RTE_PTYPE_L2_ETHER; + break; + case ENETC_PKT_TYPE_IPV4: + m->packet_type = RTE_PTYPE_L2_ETHER | + RTE_PTYPE_L3_IPV4; + break; + case ENETC_PKT_TYPE_IPV6: + m->packet_type = RTE_PTYPE_L2_ETHER | + RTE_PTYPE_L3_IPV6; + break; + case ENETC_PKT_TYPE_IPV4_TCP: + m->packet_type = RTE_PTYPE_L2_ETHER | + RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP; + break; + case ENETC_PKT_TYPE_IPV6_TCP: + m->packet_type = RTE_PTYPE_L2_ETHER | + RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP; + break; + case ENETC_PKT_TYPE_IPV4_UDP: + m->packet_type = RTE_PTYPE_L2_ETHER | + RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP; + break; + case ENETC_PKT_TYPE_IPV6_UDP: + m->packet_type = RTE_PTYPE_L2_ETHER | + RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_UDP; + break; + case ENETC_PKT_TYPE_IPV4_SCTP: + m->packet_type = RTE_PTYPE_L2_ETHER | + RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_SCTP; + break; + case ENETC_PKT_TYPE_IPV6_SCTP: + m->packet_type = RTE_PTYPE_L2_ETHER | + RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_SCTP; + break; + case ENETC_PKT_TYPE_IPV4_ICMP: + m->packet_type = RTE_PTYPE_L2_ETHER | + RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_ICMP; + break; + case ENETC_PKT_TYPE_IPV6_ICMP: + m->packet_type = RTE_PTYPE_L2_ETHER | + RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_ICMP; + break; + /* More switch cases can be added */ + default: + m->packet_type = RTE_PTYPE_UNKNOWN; + } +} + +static int +enetc_clean_rx_ring(struct enetc_bdr *rx_ring, struct rte_mbuf **rx_pkts, + int work_limit) +{ + int rx_frm_cnt = 0; + int cleaned_cnt, i; + struct enetc_swbd *rx_swbd; + + cleaned_cnt = enetc_bd_unused(rx_ring); + + /* next descriptor to process */ + i = rx_ring->next_to_clean; + rx_swbd = &rx_ring->q_swbd[i]; + + while (likely(rx_frm_cnt < work_limit)) { + union enetc_rx_bd *rxbd; + uint32_t bd_status; + + if (cleaned_cnt >= ENETC_RXBD_BUNDLE) { + int count = enetc_refill_rx_ring(rx_ring, cleaned_cnt); + + cleaned_cnt -= count; + } + rxbd = ENETC_RXBD(*rx_ring, i); + bd_status = rte_le_to_cpu_32(rxbd->r.lstatus); + if (!bd_status) + break; + + rx_swbd->buffer_addr->pkt_len = rxbd->r.buf_len; + rx_swbd->buffer_addr->data_len = rxbd->r.buf_len; + rx_swbd->buffer_addr->hash.rss = rxbd->r.rss_hash; + rx_swbd->buffer_addr->ol_flags = 0; + enetc_dev_rx_parse(rx_swbd->buffer_addr, rxbd->r.parse_summary); + + rx_pkts[rx_frm_cnt] = rx_swbd->buffer_addr; + + cleaned_cnt++; + rx_swbd++; + i++; + if (unlikely(i == rx_ring->bd_count)) { + i = 0; + rx_swbd = &rx_ring->q_swbd[i]; + } + rx_ring->next_to_clean = i; + rx_frm_cnt++; + } + + return rx_frm_cnt; +} + +uint16_t enetc_recv_pkts(void *rxq, struct rte_mbuf **rx_pkts, + uint16_t nb_pkts) +{ + struct enetc_bdr *rx_ring = (struct enetc_bdr *)rxq; + + return enetc_clean_rx_ring(rx_ring, rx_pkts, nb_pkts); +} + +static int enetc_alloc_txbdr(struct enetc_bdr *txr) +{ + int size; + + size = txr->bd_count * sizeof(struct enetc_swbd); + txr->q_swbd = rte_malloc(NULL, size, RTE_CACHE_LINE_SIZE); + if (txr->q_swbd == NULL) + return -ENOMEM; + + size = txr->bd_count * sizeof(struct enetc_tx_bd); + txr->bd_base = rte_malloc(NULL, size, RTE_CACHE_LINE_SIZE); + + if (txr->bd_base == NULL) { + rte_free(txr->q_swbd); + txr->q_swbd = NULL; + return -ENOMEM; + } + txr->next_to_clean = 0; + txr->next_to_use = 0; + + return 0; +} + +static void enetc_free_bdr(struct enetc_bdr *rxr) +{ + rte_free(rxr->q_swbd); + rte_free(rxr->bd_base); + rxr->q_swbd = NULL; + rxr->bd_base = NULL; +} + +static int enetc_alloc_tx_resources(struct enetc_eth_adapter *priv) +{ + int i, err; + + for (i = 0; i < priv->num_tx_rings; i++) { + err = enetc_alloc_txbdr(priv->tx_ring[i]); + + if (err) + goto fail; + priv->tx_ring[i]->index = i; + } + + return 0; + +fail: + while (i-- > 0) + enetc_free_bdr(priv->tx_ring[i]); + + return err; +} + +static void enetc_setup_txbdr(struct enetc_hw *hw, struct enetc_bdr *tx_ring) +{ + int idx = tx_ring->index; + uint32_t tbmr; + + enetc_txbdr_wr(hw, idx, ENETC_TBBAR0, + lower_32_bits((uint64_t)tx_ring->bd_base)); + + enetc_txbdr_wr(hw, idx, ENETC_TBBAR1, + upper_32_bits((uint64_t)tx_ring->bd_base)); + enetc_txbdr_wr(hw, idx, ENETC_TBLENR, + ENETC_RTBLENR_LEN(tx_ring->bd_count)); + + tbmr = ENETC_TBMR_EN; + /* enable ring */ + enetc_txbdr_wr(hw, idx, ENETC_TBMR, tbmr); + + enetc_txbdr_wr(hw, idx, ENETC_TBCIR, 0); + enetc_txbdr_wr(hw, idx, ENETC_TBCISR, 0); + tx_ring->tcir = hw->reg + ENETC_BDR(TX, idx, ENETC_TBCIR); + tx_ring->tcisr = hw->reg + ENETC_BDR(TX, idx, ENETC_TBCISR); +} + +static void enetc_setup_tx_bdrs(struct rte_eth_dev *dev) +{ + int i; + struct enetc_eth_adapter *priv = + ENETC_DEV_PRIVATE(dev->data->dev_private); + + for (i = 0; i < priv->num_tx_rings; i++) { + enetc_setup_txbdr(&priv->hw.hw, priv->tx_ring[i]); + dev->data->tx_queues[i] = priv->tx_ring[i]; + } +} + +int enetc_tx_queue_setup(struct rte_eth_dev *dev, + uint16_t queue_idx, + uint16_t nb_desc, + unsigned int socket_id, + const struct rte_eth_txconf *tx_conf) +{ + struct enetc_eth_adapter *adapter = + ENETC_DEV_PRIVATE(dev->data->dev_private); + int err = 0; + + err = enetc_alloc_tx_resources(adapter); + if (err) + goto err_alloc_tx; + + enetc_setup_tx_bdrs(dev); + +err_alloc_tx: + return err; +} + +static int enetc_alloc_rxbdr(struct enetc_bdr *rxr) +{ + int size; + + size = rxr->bd_count * sizeof(struct enetc_swbd); + rxr->q_swbd = rte_malloc(NULL, size, RTE_CACHE_LINE_SIZE); + if (rxr->q_swbd == NULL) + return -ENOMEM; + + size = rxr->bd_count * sizeof(union enetc_rx_bd); + rxr->bd_base = rte_malloc(NULL, size, RTE_CACHE_LINE_SIZE); + + if (rxr->bd_base == NULL) { + rte_free(rxr->q_swbd); + rxr->q_swbd = NULL; + return -ENOMEM; + } + + rxr->next_to_clean = 0; + rxr->next_to_use = 0; + rxr->next_to_alloc = 0; + + return 0; +} + +static int enetc_alloc_rx_resources(struct enetc_eth_adapter *priv) +{ + int i, err; + + for (i = 0; i < priv->num_rx_rings; i++) { + err = enetc_alloc_rxbdr(priv->rx_ring[i]); + + if (err) + goto fail; + + priv->rx_ring[i]->index = i; + } + return 0; +fail: + while (i-- > 0) + enetc_free_bdr(priv->rx_ring[i]); + + return err; +} + +static void enetc_setup_rxbdr(struct enetc_hw *hw, struct enetc_bdr *rx_ring, + struct rte_mempool *mb_pool) +{ + int idx = rx_ring->index; + uint16_t buf_size; + + enetc_rxbdr_wr(hw, idx, ENETC_RBBAR0, + lower_32_bits((uint64_t)rx_ring->bd_base)); + + enetc_rxbdr_wr(hw, idx, ENETC_RBBAR1, + upper_32_bits((uint64_t)rx_ring->bd_base)); + + enetc_rxbdr_wr(hw, idx, ENETC_RBLENR, + ENETC_RTBLENR_LEN(rx_ring->bd_count)); + + rx_ring->mb_pool = mb_pool; + + /* enable ring */ + enetc_rxbdr_wr(hw, idx, ENETC_RBMR, ENETC_RBMR_EN); + enetc_rxbdr_wr(hw, idx, ENETC_RBPIR, 0); + rx_ring->rcir = hw->reg + ENETC_BDR(RX, idx, ENETC_RBCIR); + + enetc_refill_rx_ring(rx_ring, (enetc_bd_unused(rx_ring))); + buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rx_ring->mb_pool) - + RTE_PKTMBUF_HEADROOM); + + enetc_rxbdr_wr(hw, idx, ENETC_RBBSR, buf_size); +} + +static void enetc_setup_bdrs(struct rte_eth_dev *dev, + struct rte_mempool *mb_pool) +{ + int i; + struct enetc_eth_adapter *priv = + ENETC_DEV_PRIVATE(dev->data->dev_private); + + for (i = 0; i < priv->num_rx_rings; i++) { + enetc_setup_rxbdr(&priv->hw.hw, priv->rx_ring[i], mb_pool); + dev->data->rx_queues[i] = priv->rx_ring[i]; + } +} + + +int enetc_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id, + uint16_t nb_rx_desc, unsigned int socket_id, + const struct rte_eth_rxconf *rx_conf, + struct rte_mempool *mb_pool) +{ + struct enetc_eth_adapter *adapter = + ENETC_DEV_PRIVATE(dev->data->dev_private); + int err = 0; + + err = enetc_alloc_rx_resources(adapter); + if (err) + goto err_alloc_rx; + + enetc_setup_bdrs(dev, mb_pool); + +err_alloc_rx: + return err; +} diff --git a/drivers/net/enetc/meson.build b/drivers/net/enetc/meson.build index 506b174ed..733156bbf 100644 --- a/drivers/net/enetc/meson.build +++ b/drivers/net/enetc/meson.build @@ -5,6 +5,7 @@ if host_machine.system() != 'linux' build = false endif -sources = files('enetc_ethdev.c') +sources = files('enetc_ethdev.c', + 'enetc_rxtx.c') includes += include_directories('base') -- 2.17.1