From: Andrew Lunn <andrew@lunn.ch>
To: "illusion.wang" <illusion.wang@nebula-matrix.com>
Cc: dimon.zhao@nebula-matrix.com, alvin.wang@nebula-matrix.com,
sam.chen@nebula-matrix.com, netdev@vger.kernel.org,
andrew+netdev@lunn.ch, corbet@lwn.net, kuba@kernel.org,
linux-doc@vger.kernel.org, lorenzo@kernel.org, pabeni@redhat.com,
horms@kernel.org, vadim.fedorenko@linux.dev,
lukas.bulwahn@redhat.com, edumazet@google.com,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 net-next 02/11] net/nebula-matrix: add our driver architecture
Date: Fri, 6 Feb 2026 04:39:42 +0100 [thread overview]
Message-ID: <769fbfa8-a881-403f-bc65-56c60c389185@lunn.ch> (raw)
In-Reply-To: <20260206021608.85381-3-illusion.wang@nebula-matrix.com>
> +static int
> +nbl_chan_setup_chan_mgt(struct nbl_adapter *adapter,
> + struct nbl_init_param *param,
> + struct nbl_channel_mgt_leonis **chan_mgt_leonis)
It is pretty unusual to pass ** pointers. More normal would be
> +static struct nbl_channel_mgt_leonis *
> +nbl_chan_setup_chan_mgt(struct nbl_adapter *adapter,
> + struct nbl_init_param *param)
> +{
> + struct nbl_hw_ops_tbl *hw_ops_tbl = adapter->intf.hw_ops_tbl;
> + struct nbl_common_info *common = &adapter->common;
struct nbl_channel_mgt_leonis *chan_mgt_leonis;
> + struct device *dev = &adapter->pdev->dev;
> + struct nbl_chan_info *mailbox;
> +
> + chan_mgt_leonis = devm_kzalloc(dev,
> + sizeof(struct nbl_channel_mgt_leonis),
> + GFP_KERNEL);
> + if (!chan_mgt_leonis)
> + goto alloc_channel_mgt_leonis_fail;
> +
> + chan_mgt_leonis->chan_mgt->common = common;
> + chan_mgt_leonis->chan_mgt.hw_ops_tbl = hw_ops_tbl;
> +
> + mailbox = devm_kzalloc(dev, sizeof(struct nbl_chan_info), GFP_KERNEL);
> + if (!mailbox)
> + goto alloc_mailbox_fail;
> + mailbox->chan_type = NBL_CHAN_TYPE_MAILBOX;
> + chan_mgt_leonis->chan_mgt->chan_info[NBL_CHAN_TYPE_MAILBOX] =
> + mailbox;
> +
return chan_mgt_leonis;
> +alloc_mailbox_fail:
> +alloc_channel_mgt_leonis_fail:
> + return ERR_PTR(-ENOMEM);
This is starting to look like Linux driver code now. Lots of () have
been removed. Your aim is to make the driver look like all other
drivers in linux, by copying the common patterns.
I would probably also remove the two labels, and just due the return
ERR_PTR() inline.
Please spend some time reading other drivers. Learn from them, and
make your driver look like them.
> +#define NBL_ADAP_TO_HW_MGT(adapter) ((adapter)->core.hw_mgt)
> +#define NBL_ADAP_TO_RES_MGT(adapter) ((adapter)->core.res_mgt)
> +#define NBL_ADAP_TO_DISP_MGT(adapter) ((adapter)->core.disp_mgt)
> +#define NBL_ADAP_TO_DEV_MGT(adapter) ((adapter)->core.dev_mgt)
> +#define NBL_ADAP_TO_CHAN_MGT(adapter) ((adapter)->core.chan_mgt)
I would suggest removing these. Just use adapter->core.chan_mgt
directly in the code. Using macros normally means there is some magic
involved, but this is just plain pointers, nothing magical.
> +int nbl_hw_init_leonis(struct nbl_adapter *adapter,
> + struct nbl_init_param *param)
> +{
> + struct nbl_hw_ops_tbl **hw_ops_tbl = &adapter->intf.hw_ops_tbl;
> + struct nbl_common_info *common = &adapter->common;
> + struct nbl_hw_mgt_leonis **hw_mgt_leonis;
> + struct pci_dev *pdev = common->pdev;
> + struct nbl_hw_mgt *hw_mgt;
> + int bar_mask;
> + int ret = 0;
> +
> + hw_mgt_leonis =
> + (struct nbl_hw_mgt_leonis **)&NBL_ADAP_TO_HW_MGT(adapter);
Why the cast? Cast like this suggest your data structure design is not
correct.
> +static inline u32 rd32(u8 __iomem *addr, u64 reg)
> +{
> + return readl(addr + (reg));
> +}
> +
> +static inline void wr32_barrier(u8 __iomem *addr, u64 reg, u32 value)
> +{
> + writel((value), (addr + (reg)));
> +}
Why _barrier here for write, but not for rd32()? readl() has a barrier
same as writel()? Should rd32 actually be using readl_relaxed()?
> +static inline void nbl_hw_rd_regs(struct nbl_hw_mgt *hw_mgt, u64 reg, u8 *data,
> + u32 len)
> +{
> + u32 size = len / 4;
> + u32 i = 0;
> +
> + if (len % 4)
> + return;
It is actually a bug?
> +
> + spin_lock(&hw_mgt->reg_lock);
> +
> + for (i = 0; i < size; i++)
> + *(u32 *)(data + i * sizeof(u32)) =
> + rd32(hw_mgt->hw_addr, reg + i * sizeof(u32));
> + spin_unlock(&hw_mgt->reg_lock);
> +}
This function is a bit big for inline. Have you used bloat-o-meter to
look at the size with this and the next as functions vs inline?
> +static inline void nbl_hw_wr_regs(struct nbl_hw_mgt *hw_mgt, u64 reg,
> + const u8 *data, u32 len)
> +{
> + u32 size = len / 4;
> + u32 i = 0;
> +
> + if (len % 4)
> + return;
> + spin_lock(&hw_mgt->reg_lock);
> + for (i = 0; i < size; i++)
> + /* Used for emu, make sure that we won't write too frequently */
> + wr32_barrier(hw_mgt->hw_addr, reg + i * sizeof(u32),
> + *(u32 *)(data + i * sizeof(u32)));
> + spin_unlock(&hw_mgt->reg_lock);
> +}
Andrew
next prev parent reply other threads:[~2026-02-06 3:39 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-06 2:15 [PATCH v4 net-next 00/11] nbl driver for Nebulamatrix NICs illusion.wang
2026-02-06 2:15 ` [PATCH v4 net-next 01/11] net/nebula-matrix: add minimum nbl build framework illusion.wang
2026-02-06 3:01 ` Andrew Lunn
2026-02-07 2:24 ` [v4,net-next,01/11] " Jakub Kicinski
2026-02-06 2:15 ` [PATCH v4 net-next 02/11] net/nebula-matrix: add our driver architecture illusion.wang
2026-02-06 3:39 ` Andrew Lunn [this message]
2026-02-06 9:26 ` 回复:[PATCH " Illusion Wang
2026-02-07 17:19 ` Andrew Lunn
2026-02-07 2:24 ` [v4,net-next,02/11] " Jakub Kicinski
2026-02-06 2:15 ` [PATCH v4 net-next 03/11] net/nebula-matrix: add chip related definitions illusion.wang
2026-02-07 2:24 ` [v4,net-next,03/11] " Jakub Kicinski
2026-02-06 2:15 ` [PATCH v4 net-next 04/11] net/nebula-matrix: channel msg value and msg struct illusion.wang
2026-02-06 2:15 ` [PATCH v4 net-next 05/11] net/nebula-matrix: add channel layer illusion.wang
2026-02-06 3:47 ` Andrew Lunn
2026-02-07 2:24 ` [v4,net-next,05/11] " Jakub Kicinski
2026-02-06 2:15 ` [PATCH v4 net-next 06/11] net/nebula-matrix: add common resource implementation illusion.wang
2026-02-07 2:24 ` [v4,net-next,06/11] " Jakub Kicinski
2026-02-06 2:15 ` [PATCH v4 net-next 07/11] net/nebula-matrix: add intr " illusion.wang
2026-02-07 2:24 ` [v4,net-next,07/11] " Jakub Kicinski
2026-02-06 2:16 ` [PATCH v4 net-next 08/11] net/nebula-matrix: add vsi " illusion.wang
2026-02-07 2:24 ` [v4,net-next,08/11] " Jakub Kicinski
2026-02-06 2:16 ` [PATCH v4 net-next 09/11] net/nebula-matrix: add Dispatch layer implementation illusion.wang
2026-02-06 2:16 ` [PATCH v4 net-next 10/11] net/nebula-matrix: add common/ctrl dev init/reinit operation illusion.wang
2026-02-07 2:25 ` [v4,net-next,10/11] " Jakub Kicinski
2026-02-06 2:16 ` [PATCH v4 net-next 11/11] net/nebula-matrix: add common dev start/stop operation illusion.wang
2026-02-07 2:25 ` [v4,net-next,11/11] " Jakub Kicinski
2026-02-10 2:07 ` 回复:[v4,net-next,11/11] " Illusion Wang
2026-02-10 13:42 ` Andrew Lunn
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=769fbfa8-a881-403f-bc65-56c60c389185@lunn.ch \
--to=andrew@lunn.ch \
--cc=alvin.wang@nebula-matrix.com \
--cc=andrew+netdev@lunn.ch \
--cc=corbet@lwn.net \
--cc=dimon.zhao@nebula-matrix.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=illusion.wang@nebula-matrix.com \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenzo@kernel.org \
--cc=lukas.bulwahn@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sam.chen@nebula-matrix.com \
--cc=vadim.fedorenko@linux.dev \
/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
all inboxes | Powered by JetHome®