From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9A52D457CA; Thu, 15 Aug 2024 07:28:03 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6FFA14027E; Thu, 15 Aug 2024 07:28:03 +0200 (CEST) Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by mails.dpdk.org (Postfix) with ESMTP id 3D6764025F for ; Thu, 15 Aug 2024 07:28:01 +0200 (CEST) X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 47F5RvXwA3643316, This message is accepted by code: ctloc85258 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=realsil.com.cn; s=dkim; t=1723699678; bh=xHGPuJG46+VhyTu8F9C5+9Xc7QEft3kB5qyIjvUO6TA=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:Content-Type; b=uHuXzI7loqg6WkO+4GO5UM1d1izkV8whpT7UYgLZmPBEQ4DjAJzegfxB6ctjohyca OGqYWUaRp+dCwvtMgUuUMzTrMYTeQzafaKsMH1OonUfQlXNUE3iqmKq+mNRrrrtvhn 3En6HZ6+RpQviTfe9qkSIAwOV3Oc/7GNUX7HbsH+B284mXL4eSvN5Pt1Dg/S3x1Auk 3G+TKooKkdRC6im9l8evXccYxpSFstZmoKU2bdaiJVhj4qIOGB153pvwA41tYbvwpP iJh52JeIIFgE+Z2QHVm/aPGiQOGvX+h5Qs4f2/sUDEtQNb+nWMlDGTrc05mqfbPvxU l/eXpkFHfB09Q== Received: from RSEXH36502.realsil.com.cn (rsn1.realsil.com.cn[172.29.17.3]) by rtits2.realtek.com.tw (8.15.2/3.02/5.92) with ESMTPS id 47F5RvXwA3643316 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 15 Aug 2024 13:27:58 +0800 Received: from RSEXDAG02.realsil.com.cn (172.29.17.196) by RSEXH36502.realsil.com.cn (172.29.17.3) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 15 Aug 2024 13:27:50 +0800 Received: from RSEXH36501.realsil.com.cn (172.29.17.2) by RSEXDAG02.realsil.com.cn (172.29.17.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 15 Aug 2024 13:27:50 +0800 Received: from 172.29.32.27 (172.29.32.27) by RSEXH36501.realsil.com.cn (172.29.17.2) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 15 Aug 2024 13:27:50 +0800 From: Howard Wang To: CC: , Howard Wang Subject: [PATCH] net/r8169: add PMD driver skeleton Date: Thu, 15 Aug 2024 13:27:55 +0800 Message-ID: <20240815052755.23082-1-howard_wang@realsil.com.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Meson build infrastructure, r8169_ethdev minimal skeleton, header with Realtek NIC device and vendor IDs. Signed-off-by: Howard Wang --- MAINTAINERS | 7 ++ drivers/net/meson.build | 1 + drivers/net/r8169/meson.build | 7 ++ drivers/net/r8169/r8169_base.h | 16 +++ drivers/net/r8169/r8169_ethdev.c | 181 +++++++++++++++++++++++++++++++ drivers/net/r8169/r8169_ethdev.h | 41 +++++++ 6 files changed, 253 insertions(+) create mode 100644 drivers/net/r8169/meson.build create mode 100644 drivers/net/r8169/r8169_base.h create mode 100644 drivers/net/r8169/r8169_ethdev.c create mode 100644 drivers/net/r8169/r8169_ethdev.h diff --git a/MAINTAINERS b/MAINTAINERS index c5a703b5c0..5f9eccc43f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1076,6 +1076,13 @@ F: drivers/net/memif/ F: doc/guides/nics/memif.rst F: doc/guides/nics/features/memif.ini +Realtek r8169 +M: Howard Wang +M: ChunHao Lin +M: Xing Wang +M: Realtek NIC SW +F: drivers/net/r8169 + Crypto Drivers -------------- diff --git a/drivers/net/meson.build b/drivers/net/meson.build index fb6d34b782..fddcf39655 100644 --- a/drivers/net/meson.build +++ b/drivers/net/meson.build @@ -53,6 +53,7 @@ drivers = [ 'pfe', 'qede', 'ring', + 'r8169', 'sfc', 'softnic', 'tap', diff --git a/drivers/net/r8169/meson.build b/drivers/net/r8169/meson.build new file mode 100644 index 0000000000..e37b4fb237 --- /dev/null +++ b/drivers/net/r8169/meson.build @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2024 Realtek Corporation. All rights reserved + +sources = files( + 'r8169_ethdev.c', +) + diff --git a/drivers/net/r8169/r8169_base.h b/drivers/net/r8169/r8169_base.h new file mode 100644 index 0000000000..c3b0186daa --- /dev/null +++ b/drivers/net/r8169/r8169_base.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 Realtek Corporation. All rights reserved + */ + +#ifndef _R8169_BASE_H_ +#define _R8169_BASE_H_ + +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +typedef uint64_t u64; + +#define PCI_VENDOR_ID_REALTEK 0x10EC + +#endif + diff --git a/drivers/net/r8169/r8169_ethdev.c b/drivers/net/r8169/r8169_ethdev.c new file mode 100644 index 0000000000..b3db7fdaab --- /dev/null +++ b/drivers/net/r8169/r8169_ethdev.c @@ -0,0 +1,181 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 Realtek Corporation. All rights reserved + */ + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "r8169_ethdev.h" +#include "r8169_base.h" + +static int rtl_dev_configure(struct rte_eth_dev *dev __rte_unused); +static int rtl_dev_start(struct rte_eth_dev *dev); +static int rtl_dev_stop(struct rte_eth_dev *dev); +static int rtl_dev_reset(struct rte_eth_dev *dev); +static int rtl_dev_close(struct rte_eth_dev *dev); + +/* + * The set of PCI devices this driver supports + */ +static const struct rte_pci_id pci_id_r8169_map[] = { + { RTE_PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8125) }, + { RTE_PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8162) }, + { RTE_PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8126) }, + { RTE_PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x5000) }, + {.vendor_id = 0, /* sentinel */ }, +}; + +static const struct eth_dev_ops rtl_eth_dev_ops = { + .dev_configure = rtl_dev_configure, + .dev_start = rtl_dev_start, + .dev_stop = rtl_dev_stop, + .dev_close = rtl_dev_close, + .dev_reset = rtl_dev_reset, +}; + +static int +rtl_dev_configure(struct rte_eth_dev *dev __rte_unused) +{ + return 0; +} + +/* + * Configure device link speed and setup link. + * It returns 0 on success. + */ +static int +rtl_dev_start(struct rte_eth_dev *dev) +{ + struct rtl_adapter *adapter = RTL_DEV_PRIVATE(dev); + struct rtl_hw *hw = &adapter->hw; + + hw->adapter_stopped = 0; + + return 0; +} + +/* + * Stop device: disable RX and TX functions to allow for reconfiguring. + */ +static int +rtl_dev_stop(struct rte_eth_dev *dev) +{ + struct rtl_adapter *adapter = RTL_DEV_PRIVATE(dev); + struct rtl_hw *hw = &adapter->hw; + + if (hw->adapter_stopped) + return 0; + + hw->adapter_stopped = 1; + dev->data->dev_started = 0; + + return 0; +} + +/* + * Reset and stop device. + */ +static int +rtl_dev_close(struct rte_eth_dev *dev) +{ + int ret_stp; + + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return 0; + + ret_stp = rtl_dev_stop(dev); + + return ret_stp; +} + +static int +rtl_dev_init(struct rte_eth_dev *dev) +{ + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); + struct rte_intr_handle *intr_handle = pci_dev->intr_handle; + struct rtl_adapter *adapter = RTL_DEV_PRIVATE(dev); + struct rtl_hw *hw = &adapter->hw; + + dev->dev_ops = &rtl_eth_dev_ops; + //dev->tx_pkt_burst = &rtl_xmit_pkts; + //dev->rx_pkt_burst = &rtl_recv_pkts; + + /* For secondary processes, the primary process has done all the work */ + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return 0; + + rte_eth_copy_pci_info(dev, pci_dev); + + return 0; +} + +static int +rtl_dev_uninit(struct rte_eth_dev *dev) +{ + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -EPERM; + + rtl_dev_close(dev); + + return 0; +} + +static int +rtl_dev_reset(struct rte_eth_dev *dev) +{ + int ret; + + ret = rtl_dev_uninit(dev); + if (ret) + return ret; + + ret = rtl_dev_init(dev); + + return ret; +} + +static int +rtl_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, + struct rte_pci_device *pci_dev) +{ + return rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct rtl_adapter), + rtl_dev_init); +} + +static int +rtl_pci_remove(struct rte_pci_device *pci_dev) +{ + return rte_eth_dev_pci_generic_remove(pci_dev, rtl_dev_uninit); +} + +static struct rte_pci_driver rte_r8169_pmd = { + .id_table = pci_id_r8169_map, + .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC, + .probe = rtl_pci_probe, + .remove = rtl_pci_remove, +}; + +RTE_PMD_REGISTER_PCI(net_r8169, rte_r8169_pmd); +RTE_PMD_REGISTER_PCI_TABLE(net_r8169, pci_id_r8169_map); +RTE_PMD_REGISTER_KMOD_DEP(net_r8169, "* igb_uio | uio_pci_generic | vfio-pci"); + diff --git a/drivers/net/r8169/r8169_ethdev.h b/drivers/net/r8169/r8169_ethdev.h new file mode 100644 index 0000000000..5453832e04 --- /dev/null +++ b/drivers/net/r8169/r8169_ethdev.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 Realtek Corporation. All rights reserved + */ + +#ifndef _R8169_ETHDEV_H_ +#define _R8169_ETHDEV_H_ + +#include +#include + +#include +#include + +#include "r8169_base.h" + +struct rtl_hw { + u8 adapter_stopped; +}; + +struct rtl_sw_stats { + u64 tx_packets; + u64 tx_bytes; + u64 tx_errors; + u64 rx_packets; + u64 rx_bytes; + u64 rx_errors; +}; + +struct rtl_adapter { + struct rtl_hw hw; + struct rtl_sw_stats sw_stats; +}; + +#define RTL_DEV_PRIVATE(eth_dev) \ + ((struct rtl_adapter *)((eth_dev)->data->dev_private)) + +uint16_t rtl_xmit_pkts(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts); +uint16_t rtl_recv_pkts(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts); + +#endif + -- 2.34.1