From: "Xin Tian" <tianx@yunsilicon.com>
To: "Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Jason Gunthorpe" <jgg@ziepe.ca>,
"Leon Romanovsky" <leon@kernel.org>,
"Junxian Huang" <huangjunxian6@hisilicon.com>
Cc: <weihg@yunsilicon.com>, <linux-kernel@vger.kernel.org>,
<netdev@vger.kernel.org>, <linux-rdma@vger.kernel.org>,
<kerneljasonxing@gmail.com>
Subject: [PATCH v2 04/11] net/xsc: query HCA capabilities and reset function
Date: Thu, 26 Nov 2026 22:57:23 +0800 [thread overview]
Message-ID: <20261126145721.70868-5-tianx@yunsilicon.com> (raw)
In-Reply-To: <20261126145711.70868-1-tianx@yunsilicon.com>
resources
Query the firmware HCA capabilities needed by the ethernet driver and
reset the function resources during probe.
Signed-off-by: Xin Tian <tianx@yunsilicon.com>
---
.../ethernet/yunsilicon/xsc/common/xsc_core.h | 18 +++++
.../net/ethernet/yunsilicon/xsc/pci/main.c | 70 +++++++++++++++++++
2 files changed, 88 insertions(+)
diff --git a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
index a6f0149ed..1ffbc2daa 100644
--- a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
+++ b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
@@ -24,6 +24,18 @@
#define XSC_PAGE_SHIFT_4K 12
#define XSC_PAGE_SIZE_4K (_AC(1, UL) << XSC_PAGE_SHIFT_4K)
+struct xsc_caps {
+ u32 max_cqes;
+ u32 send_ds_num;
+ u32 recv_ds_num;
+ u8 log_max_qp_depth;
+ u16 msix_base;
+ u16 msix_num;
+ u32 nic_caps;
+};
+
+#define XSC_CAP_MAC_PORT_MASK GENMASK(15, 8)
+
struct xsc_cmd;
struct xsc_core_device {
@@ -33,6 +45,12 @@ struct xsc_core_device {
void __iomem *bar;
int bar_num;
+ u8 mac_port;
+ u8 pcie_no;
+ u8 pf_id;
+ u16 glb_func_id;
+
+ struct xsc_caps caps;
struct xsc_cmd *cmd;
};
diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/main.c b/drivers/net/ethernet/yunsilicon/xsc/pci/main.c
index 9b08580f5..42c5a1bae 100644
--- a/drivers/net/ethernet/yunsilicon/xsc/pci/main.c
+++ b/drivers/net/ethernet/yunsilicon/xsc/pci/main.c
@@ -29,6 +29,63 @@ static int xsc_set_dma_caps(struct pci_dev *pdev)
return err;
}
+static int xsc_cmd_query_hca_cap(struct xsc_core_device *xdev,
+ struct xsc_caps *caps)
+{
+ struct xsc_cmd_query_hca_cap_mbox_out *out;
+ struct xsc_cmd_query_hca_cap_mbox_in in;
+ int err;
+
+ out = kzalloc_obj(*out, GFP_KERNEL);
+ if (!out)
+ return -ENOMEM;
+
+ memset(&in, 0, sizeof(in));
+ in.hdr.opcode = cpu_to_be16(XSC_CMD_OP_QUERY_HCA_CAP);
+ in.cpu_num = cpu_to_be16(num_online_cpus());
+
+ err = xsc_cmd_exec(xdev, &in, sizeof(in), out, sizeof(*out));
+ if (err)
+ goto err_free;
+
+ xdev->glb_func_id = be32_to_cpu(out->hca_cap.glb_func_id);
+
+ caps->max_cqes = 1 << out->hca_cap.log_max_cq_sz;
+ caps->send_ds_num = out->hca_cap.send_seg_num;
+ caps->recv_ds_num = out->hca_cap.recv_seg_num;
+
+ caps->nic_caps = (caps->nic_caps & ~XSC_CAP_MAC_PORT_MASK) |
+ FIELD_PREP(XSC_CAP_MAC_PORT_MASK,
+ out->hca_cap.mac_port & 0xff);
+ xdev->mac_port = FIELD_GET(XSC_CAP_MAC_PORT_MASK, caps->nic_caps);
+
+ caps->msix_base = be16_to_cpu(out->hca_cap.msix_base);
+ caps->msix_num = be16_to_cpu(out->hca_cap.msix_num);
+
+ caps->log_max_qp_depth = out->hca_cap.log_max_qp_depth & 0xff;
+
+ xdev->pcie_no = out->hca_cap.pcie_no;
+ xdev->pf_id = out->hca_cap.pf_id;
+
+ kfree(out);
+ return 0;
+err_free:
+ kfree(out);
+ return err;
+}
+
+static int xsc_reset_function_resource(struct xsc_core_device *xdev)
+{
+ struct xsc_function_reset_mbox_out out;
+ struct xsc_function_reset_mbox_in in;
+
+ memset(&in, 0, sizeof(in));
+ in.hdr.opcode = cpu_to_be16(XSC_CMD_OP_FUNCTION_RESET);
+ in.glb_func_id = cpu_to_be16(xdev->glb_func_id);
+
+ return xsc_cmd_exec(xdev, &in, sizeof(in), &out, sizeof(out));
+}
+
static int xsc_pci_init(struct xsc_core_device *xdev,
const struct pci_device_id *id)
{
@@ -90,6 +147,19 @@ static int xsc_pci_init(struct xsc_core_device *xdev,
goto err_cmd_cleanup;
}
+ err = xsc_cmd_query_hca_cap(xdev, &xdev->caps);
+ if (err) {
+ pci_err(pdev, "failed to query hca caps: err=%d\n", err);
+ goto err_cmd_cleanup;
+ }
+
+ err = xsc_reset_function_resource(xdev);
+ if (err) {
+ pci_err(pdev, "failed to reset function resource: err=%d\n",
+ err);
+ goto err_cmd_cleanup;
+ }
+
return 0;
err_cmd_cleanup:
--
2.43.0
next prev parent reply other threads:[~2026-11-26 14:57 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 14:57 [PATCH v2 00/11] net/xsc: add the Yunsilicon XSC ethernet driver Xin Tian
2026-11-26 14:57 ` [PATCH v2 01/11] net/xsc: add Yunsilicon XSC ethernet PCI driver Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 02/11] net/xsc: add doorbell and cmdq MMIO accessors Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 03/11] net/xsc: add the command queue Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` Xin Tian [this message]
2026-11-27 15:57 ` [PATCH v2 04/11] net/xsc: query HCA capabilities and reset function netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 05/11] net/xsc: add event queues and MSI-X Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 06/11] net/xsc: add CQ and QP helpers Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 07/11] net/xsc: add the ethernet netdev Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 08/11] net/xsc: add the single TX/RX channel Xin Tian
2026-11-27 15:58 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 09/11] net/xsc: report link state changes Xin Tian
2026-11-27 15:58 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 10/11] net/xsc: add the transmit path Xin Tian
2026-11-27 15:58 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 11/11] net/xsc: add the receive path Xin Tian
2026-11-27 15:58 ` netdev-bot+sashiko
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=20261126145721.70868-5-tianx@yunsilicon.com \
--to=tianx@yunsilicon.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=huangjunxian6@hisilicon.com \
--cc=jgg@ziepe.ca \
--cc=kerneljasonxing@gmail.com \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=weihg@yunsilicon.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
all inboxes | Powered by JetHome®