All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marek Behún" <kabel@kernel.org>
To: Roman Bacik <roman.bacik@broadcom.com>
Cc: U-Boot Mailing List <u-boot@lists.denx.de>,
	Pali Rohar <pali@kernel.org>,
	Bharat Gooty <bharat.gooty@broadcom.com>,
	Joe Hershberger <joe.hershberger@ni.com>,
	Ramon Fried <rfried.dev@gmail.com>
Subject: Re: [PATCH v10 1/2] net: brcm: netXtreme driver
Date: Tue, 9 Nov 2021 00:43:06 +0100	[thread overview]
Message-ID: <20211109004306.6203a36a@thinkpad> (raw)
In-Reply-To: <20211108144556.v10.1.I1edaad77041c1300213c307eef6741499504047@changeid>

Hello Roman,

some last requests from me.

On Mon,  8 Nov 2021 14:46:10 -0800
Roman Bacik <roman.bacik@broadcom.com> wrote:

> +#define bnxt_down_chip(bp)     bnxt_hwrm_run(down_chip, bp, 0)
> +#define bnxt_bring_chip(bp)    bnxt_hwrm_run(bring_chip, bp, 1)

Could these be changed to functions instead of macros, please?

> +int bnxt_free_rx_iob(struct bnxt *bp)
> +{
> +	unsigned int i;
> +
> +	if (!(FLAG_TEST(bp->flag_hwrm, VALID_RX_IOB)))
> +		return STATUS_SUCCESS;

Please change all STATUS_SUCCESS to 0 and STATUS_FAILURE to either -1
or appropriate -errno, as is customary in U-Boot.

At first I thought that you have implemented this driver by starting
from kernel's implementation. They look very similar. But it was
probably an old version of kernel implementation (perhaps broadcom
internal?), because many things are different now.

> +static void set_rx_desc(u8 *buf, void *iob, u16 cons_id, u32 iob_idx)
> +{
> +	struct rx_prod_pkt_bd *desc;
> +	u16 off = cons_id * sizeof(struct rx_prod_pkt_bd);
> +
> +	desc = (struct rx_prod_pkt_bd *)&buf[off];
> +	desc->flags_type = RX_PROD_PKT_BD_TYPE_RX_PROD_PKT;
> +	desc->len	 = MAX_ETHERNET_PACKET_BUFFER_SIZE;

What bugs me with this driver most is that it reimplements many things on
its own. MAX_ETHERNET_PACKET_BUFFER_SIZE is 1536, but we have
PKTSIZE_ALIGN in include/net.h for that.

> +	bp->link_status       = STATUS_LINK_DOWN;

This can be a simple bool: link is either up or down...


> +typedef int (*hwrm_func_t)(struct bnxt *bp);
> +
> +hwrm_func_t down_chip[] = {
> +	bnxt_hwrm_cfa_l2_filter_free,    /* Free l2 filter  */
> +	bnxt_free_rx_iob,                /* Free rx iob     */
> +	bnxt_hwrm_vnic_free,             /* Free vnic       */
> +	bnxt_hwrm_ring_free_grp,         /* Free ring group */
> +	bnxt_hwrm_ring_free_rx,          /* Free rx ring    */
> +	bnxt_hwrm_ring_free_tx,          /* Free tx ring    */
> +	bnxt_hwrm_ring_free_cq,          /* Free CQ ring    */
> +	bnxt_hwrm_stat_ctx_free,         /* Free Stat ctx   */
> +	bnxt_hwrm_func_drv_unrgtr,       /* unreg driver    */
> +	NULL,
> +};
> +
> +hwrm_func_t bring_chip[] = {
> +	bnxt_hwrm_ver_get,              /* HWRM_VER_GET                 */
> +	bnxt_hwrm_func_reset_req,       /* HWRM_FUNC_RESET              */
> +	bnxt_hwrm_func_drv_rgtr,        /* HWRM_FUNC_DRV_RGTR           */
> +	bnxt_hwrm_func_resource_qcaps,  /* HWRM_FUNC_RESOURCE_QCAPS     */
> +	bnxt_hwrm_func_qcfg_req,        /* HWRM_FUNC_QCFG               */
> +	bnxt_hwrm_func_qcaps_req,       /* HWRM_FUNC_QCAPS              */
> +	bnxt_hwrm_get_link_speed,       /* HWRM_NVM_GET_VARIABLE - 203  */
> +	bnxt_hwrm_port_mac_cfg,         /* HWRM_PORT_MAC_CFG            */
> +	bnxt_qphy_link,                 /* HWRM_PORT_PHY_QCFG           */
> +	bnxt_hwrm_func_cfg_req,         /* HWRM_FUNC_CFG - ring resource*/
> +	bnxt_hwrm_stat_ctx_alloc,       /* Allocate Stat Ctx ID         */
> +	bnxt_hwrm_ring_alloc_cq,        /* Allocate CQ Ring             */
> +	bnxt_hwrm_ring_alloc_tx,        /* Allocate Tx ring             */
> +	bnxt_hwrm_ring_alloc_rx,        /* Allocate Rx Ring             */
> +	bnxt_hwrm_ring_alloc_grp,       /* Create Ring Group            */
> +	post_rx_buffers,                /* Post RX buffers              */
> +	bnxt_hwrm_set_async_event,      /* ENABLES_ASYNC_EVENT_CR       */
> +	bnxt_hwrm_vnic_alloc,           /* Alloc VNIC                   */
> +	bnxt_hwrm_vnic_cfg,             /* Config VNIC                  */
> +	bnxt_hwrm_cfa_l2_filter_alloc,  /* Alloc L2 Filter              */
> +	get_phy_link,                   /* Get Physical Link            */
> +	NULL,
> +};
> +
> +int bnxt_hwrm_run(hwrm_func_t cmds[], struct bnxt *bp, int flag)
> +{
> +	hwrm_func_t *ptr;
> +	int ret;
> +	int status = STATUS_SUCCESS;
> +
> +	for (ptr = cmds; *ptr; ++ptr) {
> +		ret = (*ptr)(bp);
> +		if (ret) {
> +			status = STATUS_FAILURE;
> +			/* Continue till all cleanup routines are called */
> +			if (flag)
> +				return STATUS_FAILURE;

Please change this function to return 0 on success and the error value
from last failed function on failure:
  int ret = 0;
  for (...) {
    ret = (*ptr)(bp);
    if (ret)
      break;
  }
  return ret;

If you can, maybe return -errno codes that make sense on failures in
places where you now return STATUS_FAILURE.


I'll be honest that I don't like how this driver uses code construct
that are many time different from that in U-Boot/Linux. I guess this
is how the Broadcom people wrote it, and it probably looked this way
also in Linux, but was changed since then to conform to Linux style. (Or
maybe they didn't accept it until it conformed?)

Anyway, these are probably the last changes that I will be suggesting.
I don't like many things here, but I guess beggars cannot be choosers,
and we in U-Boot are more on the side of beggars when talking about
man-hours companies are willing to spend for U-Boot :( Since the
driver works for you, maybe we should accept it as it is.

Marek

  parent reply	other threads:[~2021-11-08 23:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-08 22:46 [PATCH v10 1/2] net: brcm: netXtreme driver Roman Bacik
2021-11-08 22:46 ` [PATCH v10 2/2] board: brcm-ns3: Load netXtreme firmware Roman Bacik
2021-12-02  6:27   ` Ramon Fried
2021-11-08 23:43 ` Marek Behún [this message]
2021-11-09  0:48   ` [PATCH v10 1/2] net: brcm: netXtreme driver Roman Bacik
2021-11-09  1:11     ` Marek Behún
2021-11-09  2:20       ` Roman Bacik
2021-11-09  2:55         ` Marek Behún
2021-11-09  8:37           ` Ramon Fried
2021-11-09 15:23             ` Roman Bacik
2021-12-02  6:26               ` Ramon Fried

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=20211109004306.6203a36a@thinkpad \
    --to=kabel@kernel.org \
    --cc=bharat.gooty@broadcom.com \
    --cc=joe.hershberger@ni.com \
    --cc=pali@kernel.org \
    --cc=rfried.dev@gmail.com \
    --cc=roman.bacik@broadcom.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.