netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Justin Lai <justinlai0215@realtek.com>
Cc: kuba@kernel.org, davem@davemloft.net, edumazet@google.com,
	pabeni@redhat.com, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org, andrew@lunn.ch, jiri@resnulli.us,
	pkshih@realtek.com, larry.chiu@realtek.com
Subject: Re: [PATCH net-next v17 01/13] rtase: Add pci table supported in this module
Date: Fri, 3 May 2024 10:33:31 +0100	[thread overview]
Message-ID: <20240503093331.GN2821784@kernel.org> (raw)
In-Reply-To: <20240502091847.65181-2-justinlai0215@realtek.com>

On Thu, May 02, 2024 at 05:18:35PM +0800, Justin Lai wrote:
> Add pci table supported in this module, and implement pci_driver function
> to initialize this driver, remove this driver, or shutdown this driver.
> 
> Signed-off-by: Justin Lai <justinlai0215@realtek.com>

...

> diff --git a/drivers/net/ethernet/realtek/rtase/rtase_main.c b/drivers/net/ethernet/realtek/rtase/rtase_main.c
> new file mode 100644
> index 000000000000..5ddb5f7abfe9
> --- /dev/null
> +++ b/drivers/net/ethernet/realtek/rtase/rtase_main.c
> @@ -0,0 +1,618 @@
> +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
> +/*
> + *  rtase is the Linux device driver released for Realtek Automotive Switch
> + *  controllers with PCI-Express interface.
> + *
> + *  Copyright(c) 2023 Realtek Semiconductor Corp.
> + *
> + *  Below is a simplified block diagram of the chip and its relevant interfaces.
> + *
> + *               *************************
> + *               *                       *
> + *               *  CPU network device   *
> + *               *                       *
> + *               *   +-------------+     *
> + *               *   |  PCIE Host  |     *
> + *               ***********++************
> + *                          ||
> + *                         PCIE
> + *                          ||
> + *      ********************++**********************
> + *      *            | PCIE Endpoint |             *
> + *      *            +---------------+             *
> + *      *                | GMAC |                  *
> + *      *                +--++--+  Realtek         *
> + *      *                   ||     RTL90xx Series  *
> + *      *                   ||                     *
> + *      *     +-------------++----------------+    *
> + *      *     |           | MAC |             |    *
> + *      *     |           +-----+             |    *
> + *      *     |                               |    *
> + *      *     |     Ethernet Switch Core      |    *
> + *      *     |                               |    *
> + *      *     |   +-----+           +-----+   |    *
> + *      *     |   | MAC |...........| MAC |   |    *
> + *      *     +---+-----+-----------+-----+---+    *
> + *      *         | PHY |...........| PHY |        *
> + *      *         +--++-+           +--++-+        *
> + *      *************||****************||***********

Thanks for the diagram, I like it a lot :)

> + *
> + *  The block of the Realtek RTL90xx series is our entire chip architecture,
> + *  the GMAC is connected to the switch core, and there is no PHY in between.
> + *  In addition, this driver is mainly used to control GMAC, but does not
> + *  control the switch core, so it is not the same as DSA.
> + */

...

> +static int rtase_alloc_msix(struct pci_dev *pdev, struct rtase_private *tp)
> +{
> +	int ret;
> +	u16 i;
> +
> +	memset(tp->msix_entry, 0x0, RTASE_NUM_MSIX * sizeof(struct msix_entry));
> +
> +	for (i = 0; i < RTASE_NUM_MSIX; i++)
> +		tp->msix_entry[i].entry = i;
> +
> +	ret = pci_enable_msix_exact(pdev, tp->msix_entry, tp->int_nums);
> +	if (!ret) {

In Linux Networking code it is an idiomatic practice to keep
handle errors in branches and use the main path of execution
for the non error path.

In this case I think that would look a bit like this:

	ret = pci_enable_msix_exact(pdev, tp->msix_entry, tp->int_nums);
	if (ret)
		return ret;

	...

	return 0;

> +
> +		for (i = 0; i < tp->int_nums; i++)
> +			tp->int_vector[i].irq = pci_irq_vector(pdev, i);

pci_irq_vector() can fail, should that be handled here?

> +	}
> +
> +	return ret;
> +}
> +
> +static int rtase_alloc_interrupt(struct pci_dev *pdev,
> +				 struct rtase_private *tp)
> +{
> +	int ret;
> +
> +	ret = rtase_alloc_msix(pdev, tp);
> +	if (ret) {
> +		ret = pci_enable_msi(pdev);
> +		if (ret)
> +			dev_err(&pdev->dev,
> +				"unable to alloc interrupt.(MSI)\n");

If an error occurs then it is a good practice to unwind resource
allocations made within the context of this function call, as this
leads to more symmetric unwind paths in callers.

In this case I think any resources consumed by rtase_alloc_msix()
should be released if pci_enable_msi fails. Probably using
a goto label is appropriate here.

Likewise, I suggest that similar logic applies to errors within
rtase_alloc_msix().

> +		else
> +			tp->sw_flag |= RTASE_SWF_MSI_ENABLED;
> +	} else {
> +		tp->sw_flag |= RTASE_SWF_MSIX_ENABLED;
> +	}
> +
> +	return ret;
> +}

...

  reply	other threads:[~2024-05-03  9:33 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-02  9:18 [PATCH net-next v17 00/13] Add Realtek automotive PCIe driver Justin Lai
2024-05-02  9:18 ` [PATCH net-next v17 01/13] rtase: Add pci table supported in this module Justin Lai
2024-05-03  9:33   ` Simon Horman [this message]
2024-05-06 11:32     ` Justin Lai
2024-05-08  8:39       ` Simon Horman
2024-05-02  9:18 ` [PATCH net-next v17 02/13] rtase: Implement the .ndo_open function Justin Lai
2024-05-03  8:52   ` Simon Horman
2024-05-03 10:19     ` Justin Lai
2024-05-03 11:03       ` Simon Horman
2024-05-06  2:39         ` Justin Lai
2024-05-06  2:45     ` Justin Lai
2024-05-08  8:36       ` Simon Horman
2024-05-02  9:18 ` [PATCH net-next v17 03/13] rtase: Implement the rtase_down function Justin Lai
2024-05-02  9:18 ` [PATCH net-next v17 04/13] rtase: Implement the interrupt routine and rtase_poll Justin Lai
2024-05-02  9:18 ` [PATCH net-next v17 05/13] rtase: Implement hardware configuration function Justin Lai
2024-05-02  9:18 ` [PATCH net-next v17 06/13] rtase: Implement .ndo_start_xmit function Justin Lai
2024-05-02  9:18 ` [PATCH net-next v17 07/13] rtase: Implement a function to receive packets Justin Lai
2024-05-02  9:18 ` [PATCH net-next v17 08/13] rtase: Implement net_device_ops Justin Lai
2024-05-02  9:18 ` [PATCH net-next v17 09/13] rtase: Implement pci_driver suspend and resume function Justin Lai
2024-05-02  9:18 ` [PATCH net-next v17 10/13] rtase: Implement ethtool function Justin Lai
2024-05-02  9:18 ` [PATCH net-next v17 11/13] rtase: Add a Makefile in the rtase folder Justin Lai
2024-05-02  9:18 ` [PATCH net-next v17 12/13] realtek: Update the Makefile and Kconfig in the realtek folder Justin Lai
2024-05-03  8:35   ` Simon Horman
2024-05-06  2:59     ` Justin Lai
2024-05-07  9:44     ` Justin Lai
2024-05-08  8:40       ` Simon Horman
2024-05-04 13:39   ` kernel test robot
2024-05-04 18:01   ` kernel test robot
2024-05-06 11:39     ` Justin Lai
2024-05-02  9:18 ` [PATCH net-next v17 13/13] MAINTAINERS: Add the rtase ethernet driver entry Justin Lai
2024-05-02 10:23 ` [PATCH net-next v17 00/13] Add Realtek automotive PCIe driver Simon Horman
2024-05-06  2:55   ` Justin Lai

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=20240503093331.GN2821784@kernel.org \
    --to=horms@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jiri@resnulli.us \
    --cc=justinlai0215@realtek.com \
    --cc=kuba@kernel.org \
    --cc=larry.chiu@realtek.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pkshih@realtek.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).