From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00046.outbound.protection.outlook.com [40.107.0.46]) by dpdk.org (Postfix) with ESMTP id 6C4411B112 for ; Fri, 28 Sep 2018 07:17:43 +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=CLiTOIzudkAFis0bdniyk+u56x5YgT3qiiLntKLa080=; b=OpHLgo+9GDykLojpnX87eWcmkbhR4eikjx41wfgKB17gT41YI9tAnJe9bzgnxV+wFlXkrVOa8Jk/H4oh+D1j03LWR3zOyZElW4/D32e29FWOlqWc8vYTAgpAvqsN0LEIS08AsDS3gutsnSaUQ0mJ8EmMSy6FU0qAYwBqw1ui0vg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=G.Singh@nxp.com; Received: from Tophie.ap.freescale.net (14.142.187.166) by DB5PR04MB1527.eurprd04.prod.outlook.com (2a01:111:e400:5993::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.20; Fri, 28 Sep 2018 05:17:39 +0000 From: Gagandeep Singh To: dev@dpdk.org, ferruh.yigit@intel.com Cc: pankaj.chauhan@nxp.com, Gagandeep Singh Date: Fri, 28 Sep 2018 10:46:45 +0530 Message-Id: <20180928051647.32341-2-g.singh@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180928051647.32341-1-g.singh@nxp.com> References: <20180913094201.17098-1-g.singh@nxp.com> <20180928051647.32341-1-g.singh@nxp.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [14.142.187.166] X-ClientProxiedBy: MAXPR0101CA0035.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:d::21) To DB5PR04MB1527.eurprd04.prod.outlook.com (2a01:111:e400:5993::21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cfbd827c-2a65-45c1-662a-08d62501b6f5 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DB5PR04MB1527; X-Microsoft-Exchange-Diagnostics: 1; DB5PR04MB1527; 3:bMsZ268wBUWqkp5idKwFJsbENmgrTepdWJESDdJHx1hJScnYX/l0YHYGh19YwfaWN1WR2BqCh0Z0ALTp1niVLARaYrgJtcWoW/2DQBxuQGJhtG1NHzq1+XdRTdKSs3yoD25GnrqDlpOzndAR7VgGwTQdsYB+AH1ketlZ3CYb9N8gx6+4GZ/egWJlruatXafsYuNyx9vmBNITUp0lnnMkjfK5Kv1CPn4eZvUKUmbLEPs2TCVSULrb236cg4yKp9BC; 25:c/MA92SguaLgsYdls2mxLPOYkERo+rqhkuv7HVe5xDu8B3BKHC1MbvDyuZDR+RRniI6hcFTOfUGH6kgRjxMv2SvACW8hz+vg3v5v+JLZS58unk6j3SeWfi/txoGr0mi15Rhoexv0XXJrEy2qVCRVtNgFXDsAmgPEA9pe0XjtBX99zWVVJobzGPjwtWfTET2jQtFW/O6aiveQdVvnzhs7e6+yn/kl5A+1mm6gQpqtrffde4ijKZ86KWfmg3BD8pP7Tfky7vgF/r4jv8p08sMwrdKpdm34xtXcrl2hQQz5r3RU0VR6Tfum4sPjvg+wcb1mdumZp0tXXpPGXgcG8kUokA==; 31:4zNwPH5kt79cB0wUj0Ov1iRxurSvp5SHBqXpIbXEqD0uzU9a4NmoPCZL72ydn1h5dvfHk5usdhVEz2dVkJOAcA5Ikqt2KYwM/R9t6s/EOW5+PLtYp2tMyKymeMxfl7xYxiSn3zV8OAEkGXE0V5gDxnPf99q/Jk9Jht7Gxr026qgfv4iGXpzk0ck0OqXJTjihjlQx3lsBYRzFfjrmvMaMXHrI6kem9GS2XiHC3oDSrcY= X-MS-TrafficTypeDiagnostic: DB5PR04MB1527: X-Microsoft-Exchange-Diagnostics: 1; DB5PR04MB1527; 20:fE5yLRPgeZD8A06kbnOMaIOhCBzL0uog8IHmwC64juwMGpQnRYWATukL7EvUeUe8+A9q34p2EBD0zi7hxZ/SUbvOsy9u/bdEiktVIQ3PiT5g9I7T3LXImED/XOks57fb7M01TsK5bPseVOU50SJI1VmoRiis/mj3JOCtkpsVgUCOjKxS4gTBsCCXgQzimiP/r0ey7Z9gFZqxjzDHqGBv9WTsdaJRbbiuCoel5gvEJ8gnT6SffSS1hiko6FvEA9hZujRnhjW16VVlfXcPFKQ9/6T7s+RMmL5B6oUj6ktpOTVIbfVZ2csA3oKgDZoGD1P1iZC/9WyF1U6WgIT1LVZXW4zAA7vCWpBMvIjeBHQA2kBwvOC2QOPt/aoRNSw46GUIH5CVywYX8jzkAsisV2yeEf9zZa607+RrnL9TDAAJgMIFOJnBNpLwh6GpQ2tnSeWUBc2kKCUmbBdPZMKuBfNjWAUq5knLT+lQ/vdzUCngN2ZMIdgfIG8ymma7NHyOJ6H6; 4:4nbiSdB1dR6mWW0nlENFGK0rBuj8bAIhbcjScNePaDHKBRCod5175hlSxqXN4AR6nChllWwQHgxN40LV3YZiSFygz7qOcMahdtDmqeuo5O5LBBqWeiznR+t+zRyZtCMBgEPdGO7S0E4XsZ/jQdB2K36chp1X7JiL/+Hjo54WVed+bY/s8NK/SH/HQ661kO2si+qfNgmCPGu/7XOWvpKxrddYWvsQvET1WyBLyQr0br7oDxwEb7fevb2lo6Y+a6f9+LKrErETpe7SpLTSiYCllJSuz2hPARszqG/Onulbk8uu63JP8OwDmgjQ++jYX1OH 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)(93006095)(93001095)(3002001)(3231355)(944501410)(52105095)(10201501046)(6055026)(149066)(150057)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123560045)(201708071742011)(7699051); SRVR:DB5PR04MB1527; BCL:0; PCL:0; RULEID:; SRVR:DB5PR04MB1527; X-Forefront-PRVS: 0809C12563 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(136003)(346002)(366004)(39860400002)(376002)(396003)(22813001)(189003)(199004)(105586002)(4326008)(53936002)(16586007)(50226002)(47776003)(6512007)(81156014)(486006)(66066001)(81166006)(8676002)(106356001)(478600001)(446003)(316002)(8936002)(476003)(97736004)(11346002)(2616005)(72206003)(6486002)(956004)(26005)(16526019)(186003)(5660300001)(14444005)(5009440100003)(1076002)(48376002)(7736002)(34290500001)(305945005)(68736007)(50466002)(36756003)(52116002)(2906002)(76176011)(51416003)(55236004)(3846002)(6666003)(6116002)(575784001)(86362001)(6506007)(386003)(25786009)(110426005); DIR:OUT; SFP:1101; SCL:1; SRVR:DB5PR04MB1527; H:Tophie.ap.freescale.net; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB5PR04MB1527; 23:sogiQ4c+XN/xmRAdAM77ZDEjIk8ofYE30E5JDuFWT?= =?us-ascii?Q?tAxN20G3eVM4DiYc72K8LPBxQejVWAMcvlHJlO5YcHGqx/9GTsssrn5QdoaW?= =?us-ascii?Q?XUu45XHcqpmipVqVYJ8DnBxfqZlQfAh70jwSdolGv4IHAdXAPmaNL796Qpzu?= =?us-ascii?Q?l2nsihXIU/iZbhz84fGYwAXUcJNa1l4HjmSJNZlVmg2KK7BsGWJ+/hYaqURx?= =?us-ascii?Q?JxTXy7wa5vqOE99gZQTKlnSJNeqdhmKGW+T6LP2I/jtShYy5YnV9iEb0EGAX?= =?us-ascii?Q?AgjB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3HVOF6BHQz9NUQHsEDgOrx1E5PE+gt5luPiw5MWooyYGL7xS7J/gWjdzQ4j5uXvIOeyIX+dKHFWkkuI2cZf2wQ==; 5:TIYj7CBbTPPLBDMhXJjObO7nHbW7Vk8NpHApNFJzDpIDNsoK0/IWvBk8+PS29+5FGFgzyXWYDOXUwfN3puaZjYpJToSO1EkiTekkhoqXgKIBdoGZm9Oi6zqAPJmkG8oj6p/po+Xj7fW72pilVhh0cnrAsNura7DeJ8H3rmLH1Es=; 7:m1li6X2m3mZ4aRv0yrvnLRtPygqZQU3akGYEzs3BjfU7ZsDLVuUFOlFkke3DZIlkhTbACEJyyEkVxe0B5yRaP2b4lyNmUzovw124gkjmly21ZvicCAgGZfKxUro2BEZuIOpez4rlrUnc8Kq/sI3YzqZuTbDe2sM3fwF/zEklRmJNfIaw6yoSRyIhplnPBHdjJfwUQoyE0GiZte4zWkL2F+S9fqx8wW+p2IIEYEB4Rpm5++tn4sKxsMzUruqo/ekz SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2018 05:17:39.7061 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cfbd827c-2a65-45c1-662a-08d62501b6f5 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR04MB1527 Subject: [dpdk-dev] [PATCH v3 1/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: Fri, 28 Sep 2018 05:17:43 -0000 Add RX and TX queue setup, datapath functions Signed-off-by: Gagandeep Singh --- drivers/net/enetc/Makefile | 3 +- drivers/net/enetc/base/enetc_hw.h | 19 +- drivers/net/enetc/enetc.h | 25 ++- drivers/net/enetc/enetc_ethdev.c | 326 +++++++++++++++++++++++++++++- drivers/net/enetc/enetc_rxtx.c | 239 ++++++++++++++++++++++ drivers/net/enetc/meson.build | 3 +- 6 files changed, 602 insertions(+), 13 deletions(-) create mode 100644 drivers/net/enetc/enetc_rxtx.c diff --git a/drivers/net/enetc/Makefile b/drivers/net/enetc/Makefile index 519153868..9895501db 100644 --- a/drivers/net/enetc/Makefile +++ b/drivers/net/enetc/Makefile @@ -14,8 +14,9 @@ EXPORT_MAP := rte_pmd_enetc_version.map LIBABIVER := 1 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_mbuf -lrte_mempool LDLIBS += -lrte_ethdev LDLIBS += -lrte_bus_pci diff --git a/drivers/net/enetc/base/enetc_hw.h b/drivers/net/enetc/base/enetc_hw.h index c962b9ca1..c74c94875 100644 --- a/drivers/net/enetc/base/enetc_hw.h +++ b/drivers/net/enetc/base/enetc_hw.h @@ -104,16 +104,19 @@ enum enetc_bdr_type {TX, RX}; #define ETH_ADDR_LEN 6 /* general register accessors */ -#define enetc_rd_reg(reg) rte_read32((reg)) -#define enetc_wr_reg(reg, val) rte_write32((val), (reg)) -#define enetc_rd(hw, off) enetc_rd_reg((hw)->reg + (off)) -#define enetc_wr(hw, off, val) enetc_wr_reg((hw)->reg + (off), val) +#define enetc_rd_reg(reg) rte_read32((void *)(reg)) +#define enetc_wr_reg(reg, val) rte_write32((val), (void *)(reg)) +#define enetc_rd(hw, off) enetc_rd_reg((size_t)(hw)->reg + (off)) +#define enetc_wr(hw, off, val) enetc_wr_reg((size_t)(hw)->reg + (off), val) /* port register accessors - PF only */ -#define enetc_port_rd(hw, off) enetc_rd_reg((hw)->port + (off)) -#define enetc_port_wr(hw, off, val) enetc_wr_reg((hw)->port + (off), val) +#define enetc_port_rd(hw, off) enetc_rd_reg((size_t)(hw)->port + (off)) +#define enetc_port_wr(hw, off, val) \ + enetc_wr_reg((size_t)(hw)->port + (off), val) /* global register accessors - PF only */ -#define enetc_global_rd(hw, off) enetc_rd_reg((hw)->global + (off)) -#define enetc_global_wr(hw, off, val) enetc_wr_reg((hw)->global + (off), val) +#define enetc_global_rd(hw, off) \ + enetc_rd_reg((size_t)(hw)->global + (off)) +#define enetc_global_wr(hw, off, val) \ + enetc_wr_reg((size_t)(hw)->global + (off), val) /* BDR register accessors, see ENETC_BDR() */ #define enetc_bdr_rd(hw, t, n, off) \ enetc_rd(hw, ENETC_BDR(t, n, off)) diff --git a/drivers/net/enetc/enetc.h b/drivers/net/enetc/enetc.h index 9fa7c726c..140daf0dd 100644 --- a/drivers/net/enetc/enetc.h +++ b/drivers/net/enetc/enetc.h @@ -18,7 +18,11 @@ #define MAX_RX_RINGS 1 /* Max BD counts per Ring. */ -#define MAX_BD_COUNT 256 +#define MAX_BD_COUNT 64000 +/* Min BD counts per Ring. */ +#define MIN_BD_COUNT 32 +/* BD ALIGN */ +#define BD_ALIGN 8 /* * upper_32_bits - return bits 32-63 of a number @@ -87,4 +91,23 @@ struct enetc_eth_adapter { #define ENETC_REG_WRITE(addr, val) (*(uint32_t *)addr = val) #define ENETC_REG_WRITE_RELAXED(addr, val) (*(uint32_t *)addr = val) +/* + * RX/TX ENETC function prototypes + */ +uint16_t enetc_xmit_pkts(void *txq, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts); +uint16_t enetc_recv_pkts(void *rxq, struct rte_mbuf **rx_pkts, + uint16_t nb_pkts); + + +int enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt); + +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; +} #endif /* _ENETC_H_ */ diff --git a/drivers/net/enetc/enetc_ethdev.c b/drivers/net/enetc/enetc_ethdev.c index 47e2a8ebf..2d90d8fd5 100644 --- a/drivers/net/enetc/enetc_ethdev.c +++ b/drivers/net/enetc/enetc_ethdev.c @@ -19,6 +19,15 @@ static void enetc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info); static int enetc_link_update(struct rte_eth_dev *dev, int wait_to_complete); static int enetc_hardware_init(struct enetc_eth_hw *hw); +static 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); +static void enetc_rx_queue_release(void *rxq); +static int enetc_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); +static void enetc_tx_queue_release(void *txq); /* * The set of PCI devices this driver supports @@ -37,6 +46,10 @@ 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, + .rx_queue_release = enetc_rx_queue_release, + .tx_queue_setup = enetc_tx_queue_setup, + .tx_queue_release = enetc_tx_queue_release, }; /** @@ -59,8 +72,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; /* Retrieving and storing the HW base address of device */ hw->hw.reg = (void *)pci_dev->mem_resource[0].addr; @@ -212,11 +225,320 @@ enetc_dev_infos_get(struct rte_eth_dev *dev __rte_unused, struct rte_eth_dev_info *dev_info) { PMD_INIT_FUNC_TRACE(); + dev_info->rx_desc_lim = (struct rte_eth_desc_lim) { + .nb_max = MAX_BD_COUNT, + .nb_min = MIN_BD_COUNT, + .nb_align = BD_ALIGN, + }; + dev_info->tx_desc_lim = (struct rte_eth_desc_lim) { + .nb_max = MAX_BD_COUNT, + .nb_min = MIN_BD_COUNT, + .nb_align = BD_ALIGN, + }; dev_info->max_rx_queues = MAX_RX_RINGS; dev_info->max_tx_queues = MAX_TX_RINGS; dev_info->max_rx_pktlen = 1500; } +static int +enetc_alloc_txbdr(struct enetc_bdr *txr, uint16_t nb_desc) +{ + int size; + + size = nb_desc * sizeof(struct enetc_swbd); + txr->q_swbd = rte_malloc(NULL, size, RTE_CACHE_LINE_SIZE); + if (txr->q_swbd == NULL) + return -ENOMEM; + + size = nb_desc * 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->bd_count = nb_desc; + 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 void +enetc_setup_txbdr(struct enetc_hw *hw, struct enetc_bdr *tx_ring) +{ + int idx = tx_ring->index; + uintptr_t base_addr; + uint32_t tbmr; + + base_addr = (uintptr_t)tx_ring->bd_base; + enetc_txbdr_wr(hw, idx, ENETC_TBBAR0, + lower_32_bits((uint64_t)base_addr)); + enetc_txbdr_wr(hw, idx, ENETC_TBBAR1, + upper_32_bits((uint64_t)base_addr)); + 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 = (void *)((size_t)hw->reg + + ENETC_BDR(TX, idx, ENETC_TBCIR)); + tx_ring->tcisr = (void *)((size_t)hw->reg + + ENETC_BDR(TX, idx, ENETC_TBCISR)); +} + +static int +enetc_alloc_tx_resources(struct rte_eth_dev *dev, + uint16_t queue_idx, + uint16_t nb_desc) +{ + int err; + struct enetc_bdr *tx_ring; + struct rte_eth_dev_data *data = dev->data; + struct enetc_eth_adapter *priv = + ENETC_DEV_PRIVATE(data->dev_private); + + tx_ring = rte_zmalloc(NULL, sizeof(struct enetc_bdr), 0); + if (tx_ring == NULL) { + ENETC_PMD_ERR("Failed to allocate TX ring memory"); + err = -ENOMEM; + return -1; + } + + err = enetc_alloc_txbdr(tx_ring, nb_desc); + if (err) + goto fail; + + tx_ring->index = queue_idx; + tx_ring->ndev = dev; + enetc_setup_txbdr(&priv->hw.hw, tx_ring); + data->tx_queues[queue_idx] = tx_ring; + + return 0; +fail: + rte_free(tx_ring); + + return err; +} + +static int +enetc_tx_queue_setup(struct rte_eth_dev *dev, + uint16_t queue_idx, + uint16_t nb_desc, + unsigned int socket_id __rte_unused, + const struct rte_eth_txconf *tx_conf __rte_unused) +{ + int err = 0; + + PMD_INIT_FUNC_TRACE(); + if (nb_desc > MAX_BD_COUNT) + return -1; + + err = enetc_alloc_tx_resources(dev, queue_idx, nb_desc); + + return err; +} + +static void +enetc_tx_queue_release(void *txq) +{ + if (txq == NULL) + return; + + struct enetc_bdr *tx_ring = (struct enetc_bdr *)txq; + struct enetc_eth_hw *eth_hw = + ENETC_DEV_PRIVATE_TO_HW(tx_ring->ndev->data->dev_private); + struct enetc_hw *hw; + struct enetc_swbd *tx_swbd; + int i; + uint32_t val; + + /* Disable the ring */ + hw = ð_hw->hw; + val = enetc_txbdr_rd(hw, tx_ring->index, ENETC_TBMR); + val &= (~ENETC_TBMR_EN); + enetc_txbdr_wr(hw, tx_ring->index, ENETC_TBMR, val); + + /* clean the ring*/ + i = tx_ring->next_to_clean; + tx_swbd = &tx_ring->q_swbd[i]; + while (tx_swbd->buffer_addr != NULL) { + 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[i]; + } + } + + enetc_free_bdr(tx_ring); + rte_free(tx_ring); +} + +static int +enetc_alloc_rxbdr(struct enetc_bdr *rxr, + uint16_t nb_rx_desc) +{ + int size; + + size = nb_rx_desc * sizeof(struct enetc_swbd); + rxr->q_swbd = rte_malloc(NULL, size, RTE_CACHE_LINE_SIZE); + if (rxr->q_swbd == NULL) + return -ENOMEM; + + size = nb_rx_desc * 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->bd_count = nb_rx_desc; + rxr->next_to_clean = 0; + rxr->next_to_use = 0; + rxr->next_to_alloc = 0; + + return 0; +} + +static void +enetc_setup_rxbdr(struct enetc_hw *hw, struct enetc_bdr *rx_ring, + struct rte_mempool *mb_pool) +{ + int idx = rx_ring->index; + uintptr_t base_addr; + uint16_t buf_size; + + base_addr = (uintptr_t)rx_ring->bd_base; + enetc_rxbdr_wr(hw, idx, ENETC_RBBAR0, + lower_32_bits((uint64_t)base_addr)); + enetc_rxbdr_wr(hw, idx, ENETC_RBBAR1, + upper_32_bits((uint64_t)base_addr)); + 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 = (void *)((size_t)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 int +enetc_alloc_rx_resources(struct rte_eth_dev *dev, + uint16_t rx_queue_id, + uint16_t nb_rx_desc, + struct rte_mempool *mb_pool) +{ + int err; + struct enetc_bdr *rx_ring; + struct rte_eth_dev_data *data = dev->data; + struct enetc_eth_adapter *adapter = + ENETC_DEV_PRIVATE(data->dev_private); + + rx_ring = rte_zmalloc(NULL, sizeof(struct enetc_bdr), 0); + if (rx_ring == NULL) { + ENETC_PMD_ERR("Failed to allocate RX ring memory"); + err = -ENOMEM; + return err; + } + + err = enetc_alloc_rxbdr(rx_ring, nb_rx_desc); + if (err) + goto fail; + + rx_ring->index = rx_queue_id; + rx_ring->ndev = dev; + enetc_setup_rxbdr(&adapter->hw.hw, rx_ring, mb_pool); + data->rx_queues[rx_queue_id] = rx_ring; + + return 0; +fail: + rte_free(rx_ring); + + return err; +} + +static int +enetc_rx_queue_setup(struct rte_eth_dev *dev, + uint16_t rx_queue_id, + uint16_t nb_rx_desc, + unsigned int socket_id __rte_unused, + const struct rte_eth_rxconf *rx_conf __rte_unused, + struct rte_mempool *mb_pool) +{ + int err = 0; + + PMD_INIT_FUNC_TRACE(); + if (nb_rx_desc > MAX_BD_COUNT) + return -1; + + err = enetc_alloc_rx_resources(dev, rx_queue_id, + nb_rx_desc, + mb_pool); + + return err; +} + +static void +enetc_rx_queue_release(void *rxq) +{ + if (rxq == NULL) + return; + + struct enetc_bdr *rx_ring = (struct enetc_bdr *)rxq; + struct enetc_eth_hw *eth_hw = + ENETC_DEV_PRIVATE_TO_HW(rx_ring->ndev->data->dev_private); + struct enetc_swbd *q_swbd; + struct enetc_hw *hw; + uint32_t val; + int i; + + /* Disable the ring */ + hw = ð_hw->hw; + val = enetc_rxbdr_rd(hw, rx_ring->index, ENETC_RBMR); + val &= (~ENETC_RBMR_EN); + enetc_rxbdr_wr(hw, rx_ring->index, ENETC_RBMR, val); + + /* Clean the ring */ + i = rx_ring->next_to_clean; + q_swbd = &rx_ring->q_swbd[i]; + while (i != rx_ring->next_to_use) { + rte_pktmbuf_free(q_swbd->buffer_addr); + q_swbd->buffer_addr = NULL; + q_swbd++; + i++; + if (unlikely(i == rx_ring->bd_count)) { + i = 0; + q_swbd = &rx_ring->q_swbd[i]; + } + } + + enetc_free_bdr(rx_ring); + rte_free(rx_ring); +} + static int enetc_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, struct rte_pci_device *pci_dev) diff --git a/drivers/net/enetc/enetc_rxtx.c b/drivers/net/enetc/enetc_rxtx.c new file mode 100644 index 000000000..631e2430d --- /dev/null +++ b/drivers/net/enetc/enetc_rxtx.c @@ -0,0 +1,239 @@ +/* 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 int +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)(uintptr_t) + rte_cpu_to_le_64((size_t)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; +} + +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)(uintptr_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); +} 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