On Tue, Aug 26, 2025 at 10:26:38PM -0700, Randy Dunlap wrote: > On 8/26/25 8:45 PM, Dong Yibo wrote: > > Initialize basic mbx_fw ops, such as get_capability, reset phy > > and so on. > > > > Signed-off-by: Dong Yibo <dong100@xxxxxxxxx> > > --- > > drivers/net/ethernet/mucse/rnpgbe/Makefile | 3 +- > > drivers/net/ethernet/mucse/rnpgbe/rnpgbe.h | 1 + > > .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c | 253 ++++++++++++++++++ > > .../net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h | 126 +++++++++ > > 4 files changed, 382 insertions(+), 1 deletion(-) > > create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c > > create mode 100644 drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.h > > > > > > diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c > > new file mode 100644 > > index 000000000000..d3b323760708 > > --- /dev/null > > +++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c > > @@ -0,0 +1,253 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* Copyright(c) 2020 - 2025 Mucse Corporation. */ > > + > > +#include <linux/pci.h> > > +#include <linux/if_ether.h> > > + > > +#include "rnpgbe.h" > > +#include "rnpgbe_hw.h" > > +#include "rnpgbe_mbx.h" > > +#include "rnpgbe_mbx_fw.h" > > + > > +/** > > + * mucse_fw_send_cmd_wait - Send cmd req and wait for response > > + * @hw: pointer to the HW structure > > + * @req: pointer to the cmd req structure > > + * @reply: pointer to the fw reply structure > > + * > > + * mucse_fw_send_cmd_wait sends req to pf-fw mailbox and wait > > + * reply from fw. > > + * > > + * @return: 0 on success, negative on failure > > Use of @return: is not a documented feature although kernel-doc does accept it. > I prefer that people don't use it, but I can't insist since it does work. > > Maybe change it like this? Return: 0 on success, negative errno on failure > > + **/ > > +static int mucse_fw_send_cmd_wait(struct mucse_hw *hw, > > + struct mbx_fw_cmd_req *req, > > + struct mbx_fw_cmd_reply *reply) > > +{ > > + int len = le16_to_cpu(req->datalen); > > + int retry_cnt = 3; > > + int err; > > + > > + err = mutex_lock_interruptible(&hw->mbx.lock); > > + if (err) > > + return err; > > + err = mucse_write_posted_mbx(hw, (u32 *)req, len); > > + if (err) > > + goto out; > > + do { > > + err = mucse_read_posted_mbx(hw, (u32 *)reply, > > + sizeof(*reply)); > > + if (err) > > + goto out; > > + /* mucse_write_posted_mbx return 0 means fw has > > + * received request, wait for the expect opcode > > + * reply with 'retry_cnt' times. > > + */ > > + } while (--retry_cnt >= 0 && reply->opcode != req->opcode); > > +out: > > + mutex_unlock(&hw->mbx.lock); > > + if (!err && retry_cnt < 0) > > + return -ETIMEDOUT; > > + if (!err && reply->error_code) > > + return -EIO; > > + return err; > > +} > > > [snip] > > > + > > +/** > > + * mucse_fw_get_capability - Get hw abilities from fw > > + * @hw: pointer to the HW structure > > + * @abil: pointer to the hw_abilities structure > > + * > > + * mucse_fw_get_capability tries to get hw abilities from > > + * hw. > > + * > > + * @return: 0 on success, negative on failure > > negative errno or just some negative number? > errno, -EINTR, -EIO, -ETIMEDOUT Maybe update it like this? Return: 0 on success, negative errno on failure > > + **/ > > +static int mucse_fw_get_capability(struct mucse_hw *hw, > > + struct hw_abilities *abil) > > +{ > > + struct mbx_fw_cmd_reply reply = {}; > > + struct mbx_fw_cmd_req req = {}; > > + int err; > > + > > + build_phy_abilities_req(&req); > > + err = mucse_fw_send_cmd_wait(hw, &req, &reply); > > + if (!err) > > + memcpy(abil, &reply.hw_abilities, sizeof(*abil)); > > + return err; > > +} > > -- > ~Randy > > Thanks for your feedback.