From: Ferruh Yigit <ferruh.yigit@amd.com>
To: Wenbo Cao <caowenbo@mucse.com>,
Anatoly Burakov <anatoly.burakov@intel.com>
Cc: dev@dpdk.org, thomas@monjalon.net, andrew.rybchenko@oktetlabs.ru,
yaojun@mucse.com
Subject: Re: [PATCH v6 3/8] net/rnp: add device init and uninit
Date: Tue, 5 Sep 2023 16:44:08 +0100 [thread overview]
Message-ID: <566b2003-cdde-0f3a-9568-184f64777038@amd.com> (raw)
In-Reply-To: <20230901023050.40893-4-caowenbo@mucse.com>
On 9/1/2023 3:30 AM, Wenbo Cao wrote:
> Add basic init and uninit function
>
> Signed-off-by: Wenbo Cao <caowenbo@mucse.com>
> ---
> drivers/net/rnp/base/rnp_hw.h | 19 ++++
> drivers/net/rnp/meson.build | 1 +
> drivers/net/rnp/rnp.h | 25 +++++
> drivers/net/rnp/rnp_ethdev.c | 196 +++++++++++++++++++++++++++++++++-
> drivers/net/rnp/rnp_logs.h | 34 ++++++
> drivers/net/rnp/rnp_osdep.h | 30 ++++++
> 6 files changed, 300 insertions(+), 5 deletions(-)
> create mode 100644 drivers/net/rnp/base/rnp_hw.h
> create mode 100644 drivers/net/rnp/rnp_logs.h
> create mode 100644 drivers/net/rnp/rnp_osdep.h
>
'rnp_osdep.h' not used at all in the patch, can you move it where it is
used?
> diff --git a/drivers/net/rnp/base/rnp_hw.h b/drivers/net/rnp/base/rnp_hw.h
> new file mode 100644
> index 0000000000..d80d23f4b4
> --- /dev/null
> +++ b/drivers/net/rnp/base/rnp_hw.h
> @@ -0,0 +1,19 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(C) 2023 Mucse IC Design Ltd.
> + */
> +#ifndef __RNP_HW_H__
> +#define __RNP_HW_H__
> +
> +struct rnp_eth_adapter;
> +struct rnp_hw {
> + struct rnp_eth_adapter *back;
> + void *iobar0;
> + uint32_t iobar0_len;
> + void *iobar4;
> + uint32_t iobar4_len;
> +
> + uint16_t device_id;
> + uint16_t vendor_id;
> +} __rte_cache_aligned;
> +
All structs seems alligned to the cache, although it may not hurt, it is
better to align ones that is necessary for performance.
<...>
> +
> +static struct rte_eth_dev *
> +rnp_alloc_eth_port(struct rte_pci_device *primary_pci, char *name)
Why variable name is 'primary_pci', are there different pci device types?
> +{
> + struct rnp_eth_port *port;
> + struct rte_eth_dev *eth_dev;
> +
> + eth_dev = rte_eth_dev_allocate(name);
> + if (!eth_dev) {
> + RNP_PMD_DRV_LOG(ERR, "Could not allocate "
> + "eth_dev for %s\n", name);
Please don't split the log message, instead can do:
RNP_PMD_DRV_LOG(ERR,
"Could not allocate eth_dev for %s\n",
name);
Same for all log messages.
> + return NULL;
> + }
> + port = rte_zmalloc_socket(name,
> + sizeof(*port),
> + RTE_CACHE_LINE_SIZE,
> + primary_pci->device.numa_node);
> + if (!port) {
> + RNP_PMD_DRV_LOG(ERR, "Could not allocate "
> + "rnp_eth_port for %s\n", name);
> + return NULL;
Should 'eth_dev' released here?
> + }
> + eth_dev->data->dev_private = port;
> + eth_dev->process_private = calloc(1, sizeof(struct rnp_share_ops));
> + if (!eth_dev->process_private) {
> + RNP_PMD_DRV_LOG(ERR, "Could not calloc "
> + "for Process_priv\n");
> + goto fail_calloc;
> + }
> + return eth_dev;
> +fail_calloc:
> + rte_free(port);
> + rte_eth_dev_release_port(eth_dev);
> +
> + return NULL;
> +}
> +
> +static int
> +rnp_eth_dev_init(struct rte_eth_dev *dev)
> +{
> + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
> + struct rnp_eth_adapter *adapter = NULL;
> + char name[RTE_ETH_NAME_MAX_LEN] = " ";
> + struct rnp_eth_port *port = NULL;
> + struct rte_eth_dev *eth_dev;
> + struct rnp_hw *hw = NULL;
> + int32_t p_id;
> + int ret;
> +
> + PMD_INIT_FUNC_TRACE();
> +
> + if (rte_eal_process_type() != RTE_PROC_PRIMARY)
> + return 0;
> + memset(name, 0, sizeof(name));
> + snprintf(name, sizeof(name), "rnp_adapter_%d", dev->data->port_id);
> + adapter = rte_zmalloc(name, sizeof(struct rnp_eth_adapter), 0);
> + if (!adapter) {
> + RNP_PMD_DRV_LOG(ERR, "zmalloc for adapter failed\n");
> + return -ENOMEM;
> + }
> + hw = &adapter->hw;
> + adapter->pdev = pci_dev;
> + adapter->eth_dev = dev;
> + adapter->num_ports = 1;
This is hardcoded value, so no need the loop below but perhaps it is for
future.
> + hw->back = adapter;
> + hw->iobar4 = pci_dev->mem_resource[RNP_CFG_BAR].addr;
> + hw->iobar0 = pci_dev->mem_resource[RNP_PF_INFO_BAR].addr;
> + hw->iobar4_len = pci_dev->mem_resource[RNP_CFG_BAR].len;
> + hw->iobar0_len = pci_dev->mem_resource[RNP_PF_INFO_BAR].len;
> + hw->device_id = pci_dev->id.device_id;
> + hw->vendor_id = pci_dev->id.vendor_id;
> + hw->device_id = pci_dev->id.device_id;
> + for (p_id = 0; p_id < adapter->num_ports; p_id++) {
> + /* port 0 resource has been allocated When Probe */
Why 'When' & 'Probe' starts with uppercase, similar usage exists many
places, although that is not an issue, just catches eye, can you please
fix them if there is no specific reason.
> + if (!p_id) {
> + eth_dev = dev;
> + } else {
> + snprintf(name, sizeof(name), "%s_%d",
> + adapter->pdev->device.name,
> + p_id);
> + eth_dev = rnp_alloc_eth_port(pci_dev, name);
> + if (eth_dev)
> + rte_memcpy(eth_dev->process_private,
> + adapter->share_priv,
> + sizeof(*adapter->share_priv));
> + if (!eth_dev) {
This can be 'else' leg of above branch.
> + ret = -ENOMEM;
> + goto eth_alloc_error;
> + }
> + }
> + ret = rnp_init_port_resource(adapter, eth_dev, name, p_id);
> + if (ret)
> + goto eth_alloc_error;
'rnp_init_port_resource()' can't return error but perhaps this check is
for future.
> +
> + rnp_mac_rx_disable(eth_dev);
> + rnp_mac_tx_disable(eth_dev);
> + }
> +
> + return 0;
> +eth_alloc_error:
> + for (p_id = 0; p_id < adapter->num_ports; p_id++) {
> + port = adapter->ports[p_id];
> + if (!port)
> + continue;
> + if (port->eth_dev) {
> + rnp_dev_close(port->eth_dev);
> + rte_eth_dev_release_port(port->eth_dev);
> + if (port->eth_dev->process_private)
This should crash, because 'port' is 'dev_private' and
'rte_eth_dev_release_port()' frees the dev_private, so can't access
'port->' here.
Also 'process_private' set to NULL in the 'rte_eth_dev_release_port()',
it should be freed in 'rnp_dev_close()', not here.
> + free(port->eth_dev->process_private);
> + }
> + rte_free(port);
> + }
> + rte_free(adapter);
> +
> + return 0;
> }
>
> static int
> rnp_eth_dev_uninit(struct rte_eth_dev *eth_dev)
> {
> - RTE_SET_USED(eth_dev);
> + struct rnp_eth_adapter *adapter = RNP_DEV_TO_ADAPTER(eth_dev);
> + struct rnp_eth_port *port = NULL;
> + uint8_t p_id;
> +
> + if (rte_eal_process_type() != RTE_PROC_PRIMARY)
> + return 0;
>
> - return -ENODEV;
> + if (adapter->eth_dev != eth_dev) {
> + RNP_PMD_DRV_LOG(ERR, "Input Argument ethdev "
> + "Isn't Primary Ethdev\n");
> + return -EINVAL;
> + }
> + for (p_id = 0; p_id < adapter->num_ports; p_id++) {
> + port = adapter->ports[p_id];
> + if (!port)
> + continue;
> + if (port->eth_dev) {
> + rnp_dev_close(port->eth_dev);
> + /* Just Release Not Primary Port Allocated By PMD */
> + if (p_id)
> + rte_eth_dev_release_port(port->eth_dev);
> + }
> + }
> +
> + return 0;
> }
>
> static int
> @@ -84,3 +259,14 @@ static struct rte_pci_driver rte_rnp_pmd = {
> RTE_PMD_REGISTER_PCI(net_rnp, rte_rnp_pmd);
> RTE_PMD_REGISTER_PCI_TABLE(net_rnp, pci_id_rnp_map);
> RTE_PMD_REGISTER_KMOD_DEP(net_rnp, "igb_uio | uio_pci_generic | vfio-pci");
> +
> +RTE_LOG_REGISTER_SUFFIX(rnp_init_logtype, init, NOTICE);
> +RTE_LOG_REGISTER_SUFFIX(rnp_drv_logtype, driver, NOTICE);
> +
Do you really need two different log types? What about reducing it to one?
<...>
> diff --git a/drivers/net/rnp/rnp_osdep.h b/drivers/net/rnp/rnp_osdep.h
> new file mode 100644
> index 0000000000..5685dd2404
> --- /dev/null
> +++ b/drivers/net/rnp/rnp_osdep.h
> @@ -0,0 +1,30 @@
> +#ifndef __RNP_OSDEP_H__
> +#define __RNP_OSDEP_H__
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(C) 2023 Mucse IC Design Ltd.
> + */
> +#include <stdint.h>
> +
> +#include <rte_byteorder.h>
> +
> +#define __iomem
> +#define _RING_(off) ((off) + 0x000000)
> +#define _DMA_(off) ((off))
> +#define _GLB_(off) ((off) + 0x000000)
> +#define _NIC_(off) ((off) + 0x000000)
> +#define _ETH_(off) ((off))
> +#define _MAC_(off) ((off))
> +#define BIT(n) (1UL << (n))
> +#define BIT64(n) (1ULL << (n))
DPDK has RTE_BIT64 / RTE_BIT32 macros that can be reused.
> +#define BITS_PER_LONG (__SIZEOF_LONG__ * 8)
> +#define GENMASK(h, l) \
> + (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
> +
> +typedef uint8_t u8;
> +typedef uint16_t u16;
> +typedef uint32_t u32;
> +typedef uint64_t u64;
> +typedef int32_t s32;
> +typedef int16_t s16;
> +typedef int8_t s8;
> +#endif /* __RNP_OSDEP_H__ */
next prev parent reply other threads:[~2023-09-05 15:44 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-01 2:30 [PATCH v6 0/8] [v6]drivers/net Add Support mucse N10 Pmd Driver Wenbo Cao
2023-09-01 2:30 ` [PATCH v6 1/8] net/rnp: add skeleton Wenbo Cao
2023-09-05 15:35 ` Ferruh Yigit
2023-09-06 8:15 ` 11
2024-03-29 11:28 ` Ferruh Yigit
2024-03-29 14:45 ` 11
2024-04-02 10:15 ` Ferruh Yigit
2023-09-01 2:30 ` [PATCH v6 2/8] net/rnp: add ethdev probe and remove Wenbo Cao
2023-09-05 15:36 ` Ferruh Yigit
2023-09-06 10:42 ` 11
2023-09-01 2:30 ` [PATCH v6 3/8] net/rnp: add device init and uninit Wenbo Cao
2023-09-05 15:44 ` Ferruh Yigit [this message]
2023-09-06 11:03 ` 11
2023-09-01 2:30 ` [PATCH v6 4/8] net/rnp: add mbx basic api feature Wenbo Cao
2023-09-05 15:45 ` Ferruh Yigit
2023-09-06 10:32 ` 11
2023-09-01 2:30 ` [PATCH v6 5/8] net/rnp add reset code for Chip Init process Wenbo Cao
2023-09-05 15:46 ` Ferruh Yigit
2023-09-06 9:23 ` 11
2023-09-01 2:30 ` [PATCH v6 6/8] net/rnp add port info resource init Wenbo Cao
2023-09-05 16:56 ` Ferruh Yigit
2023-09-06 9:07 ` 11
2023-09-01 2:30 ` [PATCH v6 7/8] net/rnp add devargs runtime parsing functions Wenbo Cao
2023-09-05 15:46 ` Ferruh Yigit
2023-09-06 9:13 ` 11
2023-09-01 2:30 ` [PATCH v6 8/8] net/rnp handle device interrupts Wenbo Cao
2023-09-05 15:34 ` [PATCH v6 0/8] [v6]drivers/net Add Support mucse N10 Pmd Driver Ferruh Yigit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=566b2003-cdde-0f3a-9568-184f64777038@amd.com \
--to=ferruh.yigit@amd.com \
--cc=anatoly.burakov@intel.com \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=caowenbo@mucse.com \
--cc=dev@dpdk.org \
--cc=thomas@monjalon.net \
--cc=yaojun@mucse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).