From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10080.outbound.protection.outlook.com [40.107.1.80]) by dpdk.org (Postfix) with ESMTP id A304B37B7 for ; Thu, 6 Sep 2018 07:55:38 +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=Q4A+a8RTGgGTq4Ac+Zb7mxliGc+5TK413soj0gHZ9No=; b=i7j88NJ8ZtppzOzvB4V7lRZvOmalY7aM9FM1twjHFKGFLI0zURi2BQZP7k0FoQv6uqKVuNoVlRB0YRmjQow1xW3qbhOx8EKJQFSozdMfu/HrFotEGf2z9e601Cs0enQrQIgqXb5O1wiJjlsu3RoDoC17XtLvwEP4DlG55ffUV8Y= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=G.Singh@nxp.com; Received: from Tophie.ap.freescale.net (14.142.187.166) by AM4PR04MB1521.eurprd04.prod.outlook.com (2a01:111:e400:59e4::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1101.17; Thu, 6 Sep 2018 05:55:35 +0000 From: Gagandeep Singh To: dev@dpdk.org, ferruh.yigit@intel.com Cc: pankaj.chauhan@nxp.com, Gagandeep Singh Date: Thu, 6 Sep 2018 11:24:49 +0530 Message-Id: <20180906055449.21731-4-g.singh@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180906055449.21731-1-g.singh@nxp.com> References: <20180906055449.21731-1-g.singh@nxp.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [14.142.187.166] X-ClientProxiedBy: BM1PR0101CA0023.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:18::33) To AM4PR04MB1521.eurprd04.prod.outlook.com (2a01:111:e400:59e4::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e0fc342b-8418-4492-b6e2-08d613bd5e2d 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:AM4PR04MB1521; X-Microsoft-Exchange-Diagnostics: 1; AM4PR04MB1521; 3:MvdHL4H2e9YDKLSsEZ4pRR+rNrp1fL96o/sbrQ5C2nKuJxQRKuYAg3ivYYErCzdtEDpWwqRjTGW3zpc2MxuWlIYWq+zwXaBEepHROPbGdw7UeE6lkMFBrJRS5fozRfyUzqBOxhqhBRo+avIGB/KMR/b6AYVpROsPmaPyxtnyGv0ZG8YYbHYHt3FkKS9N/Nu7BjQ8o8TSTfh8fTgGUn/wHaaztj+4M0vZPUvvMDa0s/PI56vV/rRgRN1+W1Nqn3Ts; 25:/CVmLWsKNkiZVH9vh3X1IH4vF9cC3UrC5SiK2HGh3BCzBXhkHAbhGnh+A6m6TAIhAiH3E9HOfB1bl6T0gviFcU6zKXkfHdrEwfOexgDK70Tjd3p5j0wx9PnCtqE/jYKcSoqhyKEXjIPXanfAqDXd4I0cmzZVJ7Cx58TxEsTSsDvWnVimiBStwOJlIYt7+408g4Ag4o4a5A2I0rx6g+yH+qtdU+kYEk6qvd8fQCsoH6+ITJZ+7U9XoUhvr0YU61MXq/Q2vmtXOkSzlv4tFCMlIPfAjMZdVwo+BaIySs+NTuv3EZsn+ACWbpugWxCRVodotCyGysblIB9bkXOzkAWQ3A==; 31:JneAIyX2k8NNJbFei++SrMd198DCDdYvM4Dkjtn7yB08GSW0LFWICYLoWnaIXX+s4HjiC2yQUo1sPfUF/r0ycSDYwVieyYPkNZD7lYd9KPr/YJG5VW6MRif49abENX9uAwnF4ZuEBl3Jtw5mSdyvsLGKRr89KdgHX1M0VBUSXYEFX80Z+iLPAV42aVoop8w2SEaLi0b67Q6O/M0HlbfUYU6uSrnl+tDvAlNUfYh/39o= X-MS-TrafficTypeDiagnostic: AM4PR04MB1521: X-Microsoft-Exchange-Diagnostics: 1; AM4PR04MB1521; 20:33EiYHFKw1Dr49kLRjGzOWSz2+jLCaWFc/yq+6bLw5UA6okzEZAeIcXduG2fsi+kkxUQ/0q+o/2Hxy9FLN+fedWhGI4Dzmk3MbPCXgVGTuSwPC2Vh4XYQ4dSshdfKWX7qfd35EIyIqGhzgoSS5MPyt+2hFkt3M0EiJFqXAAmYj7fwoE2qPSVx9yMstmGmtpX/wRNhduKvwTVPb2nBJ1j2MbUN95bDwDJKLBhUu0oRSIcuHXW6mxZAbh79bNSi+r1ZEOCZwm8fY3CVEcXibgwcTm9mqe52+M5V9w0KwGHD8JdxMtOm7uyfltNAC/iXeOQNJDth+pGSMTFKi33Cq0pOCFjJHxXOxFFgqlUAJM0GXsnBfjjf/iMCXex9b5o5CUcx7dzZKvF+7XqFMkQI+ncn5apIBh3criuQBxuFyqRz117J2Tnzk58g6CdcH5gwOt6MH26hCqoOM7rodDsDzKW+9RP4ef1Ei+vuu0T8IqqZ54wDvM4klub8qm1K479vXkP; 4:sXmKep77PtZCr7xud3JAu9Q22mIZdfjQw2B6IcN5p444bT6zVg7ug7ExE6Hsis4xU9NPq+ikywxYyW6F4PHGoH1srh2xA5AdyUUFcLA+xGPHsijqEvHEARLZfsboqJ+0gmzoOA1BPnagqqOGNAWhB1NbLnBxpwagGU61/waIGBa83Wm0AhSU60Prb2xFMSoWAWEWmV1h5nGSMRCLTP/PL3VMVjupfDiPsEMyblV7NyvBcODM6AFgCJ7u50dQbLwCrpdl/QLEzm+p/QSl0wtJjSnLyt7KtkKUIkwYtcslzk2cwC+2FQl6KEdsB2cSmR0S 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)(8121501046)(5005006)(823301075)(10201501046)(93006095)(93001095)(3231311)(944501410)(52105095)(3002001)(6055026)(149027)(150027)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699016); SRVR:AM4PR04MB1521; BCL:0; PCL:0; RULEID:; SRVR:AM4PR04MB1521; X-Forefront-PRVS: 0787459938 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(346002)(376002)(39860400002)(136003)(366004)(22813001)(199004)(189003)(6666003)(53936002)(6486002)(6512007)(305945005)(575784001)(14444005)(86362001)(7736002)(8676002)(68736007)(105586002)(36756003)(2906002)(26005)(72206003)(48376002)(476003)(2616005)(956004)(66066001)(11346002)(478600001)(316002)(25786009)(6506007)(106356001)(386003)(55236004)(16586007)(50226002)(446003)(50466002)(52116002)(51416003)(76176011)(81156014)(81166006)(8936002)(186003)(16526019)(1076002)(486006)(5660300001)(4326008)(97736004)(6116002)(5009440100003)(3846002)(47776003)(110426005); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR04MB1521; 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; AM4PR04MB1521; 23:BvvXC9biOf68S5pOasVqXenzuqvXjYBwMFUy+xJLy?= =?us-ascii?Q?+SeZJvaCEiy18AcGX2M37Gfp3lAL7IYuP0ZmcAUIsdOncdh8JXbZl2N6RljH?= =?us-ascii?Q?8xsuQ97WoZ3D4Bpi/DCg1srd9IyE41xdRA8I2IuW3mOMhuWo1sOlAHMzIyI8?= =?us-ascii?Q?7ag8IHHjNxI4yzo/E4Ll6rKm8F4b0NFX5gaBh0MpWl1DXjlXHgR0Q3YnlgEu?= =?us-ascii?Q?y79Adqlrc02a6ssFiWxyCcfCewuZFG19ZRJ1Jmo/SzDhmpMs41MpMgVgk6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jqjNo139pWN44i4z0EXxb9+9Salo4GyarHJ+EYubNcLmxou8b4RTIBs1uw==; 5:gD0rlTBo9QbvHj7ZfyvvIiSkKJPKb73cJE7qm4Ifln5Adp/bLzGJ4jmMvc0pE+0BJewetSEX0VGYw/hWtVEQ96vr+nxef+PVp4ywAvEIQCmz7/PdQdXs8lRYUo4bzKlGMlLCKigGJnaSHMTJ12WhxamZf98npujarZENEe1ruMM=; 7:sKv8KI2gurEPEi6qRmqIEoQhp9nuCIYECnaLxvrgqFEz3ABet69iVI/meG/+45HCGkD33q9cEcqiufsvcMT9m50YASo/t3oIt/3aTCWbmZCxH4Da4Cs/CLnBvhINYXTYyGPM1mFH3KqZMB8/EzWHk/lLVdcLXXEyqnG1Xywe0wEse9UlkVh6xHi3CNJR5RvOKvVtEaH+TZ0X/pt6HtPUPUUfA0xOSmwpbbTYMh/WqDre/P8msv+WmLN+Fg17Dp5E SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2018 05:55:35.7965 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e0fc342b-8418-4492-b6e2-08d613bd5e2d X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR04MB1521 Subject: [dpdk-dev] [PATCH 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, 06 Sep 2018 05:55:39 -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 fac43bd2a..353b5eebb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -629,6 +629,7 @@ F: doc/guides/nics/features/nfp*.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