From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.231.27 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796116958; b=zZgpdsy3Y/Wj7AsYGhZ9ofyDHuX3ydHiI1a7s3hihaQvNNoRv26ms8V83NL7dsmJgDb8 NVlF37HB2ERBkJ9/3jP6w9sEi4jiLFkDft/ngwF/WrxcYeWWx5dZpnm3ANGENQoDy4yhD kzQ7Ov8ryH5gmFbppGCwZnSd5SZh192682C2bz/itUMqv0RsgCcHhI0kxJy+n61rIZwVC liXKXtm+RA3hR6AFGeA2GURxWRwj9HGsP149+sd1O9fMhDJqG1Y68Ez5WY6gY7U8ySWl4 z+sX4DElKMXObyaI2L34uyidw+dsBx/N/KHV5gYxKGJ3raTnA2DCt3OBpNRMjUcMalw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796116958; h=DMARC-Filter:DKIM-Signature:Cc:Message-Id:X-Lms-Return-Path: Content-Type:To:Mime-Version:Received:X-Original-From:User-Agent: In-Reply-To:From:Subject:Date:Content-Transfer-Encoding:References; bh=N/4MPFM/E2rfGgVCjt6vk//caR8m0fA5Ci1ig9zr8kw=; b=pDABkIorzVXJBpDGHWbycbGi9bZJajuNaI+PqwwNMsrX5C6DF6W3QE5fMoGryetg+6Bh FqN52YVjFh7bdM9JXXaOihXm/sRYHEQm/PVtSLvPhIyjcQCN82NKhJ0oJvICSOsPs4L/Q hkYpcc/Mk2XtZ1ICtsqkqjI4MGgIh7ZpUqy8u//y5vKntmjysfUuyuFyoOj+9PW0SqNO8 6yALWD9QndURSVLCHLPkbfEDgZIbZxdWApYDbfQw9S4y4LkfN4gwIOI+4e4lrTUrY1I8m 3LZOZQzIE6hWARN6NuPn9OTpahyAr2tREMqOJN4XlKN8Nq2E8wNqzvZFpIXTcAmTQyg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=yunsilicon.com; spf=pass smtp.mailfrom=yunsilicon.com; dkim=pass header.d=yunsilicon.com header.i=@yunsilicon.com header.a=rsa-sha256 header.s=feishu2403070942 header.b=LH5LGX7h; arc=none smtp.remote-ip=209.127.231.27 Received: from va-2-27.ptr.blmpb.com (va-2-27.ptr.blmpb.com [209.127.231.27]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C1AE606A327 for ; Tue, 1 Dec 2026 09:22:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7C1AE606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=yunsilicon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yunsilicon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=yunsilicon.com header.i=@yunsilicon.com header.a=rsa-sha256 header.s=feishu2403070942 header.b=LH5LGX7h DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1796116951; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=N/4MPFM/E2rfGgVCjt6vk//caR8m0fA5Ci1ig9zr8kw=; b=LH5LGX7hmvGojikjDR7C8TqOzf61yToM0pseLqj79qwF0wyhUsnXuEhlpy7ah/yqepcKRq syOr6O00iq0AgtmfeeC/JbL3i3fC+7KYxn4D+YkCA6GSyLLRFITbgoYCSBSWAosJQue4r4 DNXCE7dD4TXk9pgEgqxmyaPrGNG236QAnJl0PH205BUJ74a3t4/oN/jqOTNnBo+Nyd7LPE WhIduvC/zoda2KxkUIflgNoGzXkU8d6gYpuhymDTFIAlfu8KKRJoydT4jYfTO1PbMUIMz1 jiS5sjRGF1UnVtUTZXfBmVkXtGintsw7qn11pDva4P1rB+qHDMFEqjAWhioqSA== Cc: "Andrew Lunn" , "David S. Miller" , "Eric Dumazet" , "Jakub Kicinski" , "Paolo Abeni" , "Jason Gunthorpe" , "Leon Romanovsky" , "Junxian Huang" , , , , Message-Id: <65f9fb97-fb21-4ffc-9eb3-ee1446cfad8e@yunsilicon.com> X-Lms-Return-Path: Content-Type: text/plain; charset=UTF-8 To: "Jason Xing" X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Received: from [127.0.0.1] ([183.193.56.176]) by smtp.feishu.cn with ESMTPS; Tue, 01 Dec 2026 17:22:28 +0800 X-Original-From: Xin Tian User-Agent: Mozilla Thunderbird In-Reply-To: From: "Xin Tian" Subject: Re: [PATCH v2 03/11] net/xsc: add the command queue Date: Tue, 1 Dec 2026 17:22:26 +0800 Content-Transfer-Encoding: quoted-printable References: <20261126145711.70868-1-tianx@yunsilicon.com> <20261126145718.70868-4-tianx@yunsilicon.com> On 11/29/2026 3:30 PM, Jason Xing wrote: > On Thu, Nov 26, 2026 at 10:57=E2=80=AFPM Xin Tian = wrote: >> Provide the mailbox-based firmware command interface: a single polling >> thread, the command exec path with status-to-errno mapping, and the >> firmware version check. Event-driven mode is deferred. > Out of curiosity, what is the reason why the event-driven is deferred? > Polling mode is a bit less efficient. >> Signed-off-by: Xin Tian >> --- >> .../ethernet/yunsilicon/xsc/common/xsc_cmd.h | 560 ++++++++++++++ >> .../ethernet/yunsilicon/xsc/common/xsc_core.h | 4 + >> .../net/ethernet/yunsilicon/xsc/pci/Makefile | 2 +- >> drivers/net/ethernet/yunsilicon/xsc/pci/cmd.c | 708 ++++++++++++++++++ >> drivers/net/ethernet/yunsilicon/xsc/pci/cmd.h | 87 +++ >> .../net/ethernet/yunsilicon/xsc/pci/main.c | 18 + >> 6 files changed, 1378 insertions(+), 1 deletion(-) >> create mode 100644 drivers/net/ethernet/yunsilicon/xsc/common/xsc_cmd.= h >> create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/cmd.c >> create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/cmd.h >> >> diff --git a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_cmd.h b/driv= ers/net/ethernet/yunsilicon/xsc/common/xsc_cmd.h >> new file mode 100644 >> index 000000000..4dc650f83 >> --- /dev/null >> +++ b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_cmd.h >> @@ -0,0 +1,560 @@ >> +/* SPDX-License-Identifier: GPL-2.0 */ >> +/* Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd. >> + * All rights reserved. >> + */ >> + >> +#ifndef __XSC_CMD_H >> +#define __XSC_CMD_H >> + >> +#include >> +#include >> + >> +struct xsc_core_device; >> + >> +#define XSC_CMDQ_VERSION 0x32 >> + >> +#define XSC_BOARD_SN_LEN 32 >> +#define XSC_MAX_NUM_PCIE_INTF 2 >> +#define XSC_MAX_PF_NUM_PER_PCIE 8 >> + >> +/* hca_cap mbox version */ >> +#define XSC_CMD_QUERY_HCA_CAP_V1 1 >> + >> +enum { >> + XSC_CMD_STAT_OK =3D 0x0, >> + XSC_CMD_STAT_BAD_OP_ERR =3D 0x2, >> + XSC_CMD_STAT_BAD_PARAM_ERR =3D 0x3, >> + XSC_CMD_STAT_RES_BUSY =3D 0x6, >> + XSC_CMD_STAT_IX_ERR =3D 0xa, >> + XSC_CMD_STAT_QP_FLUSH_BUSY =3D 0x4b, >> + XSC_CMD_STAT_QP_FLUSH_PENDING =3D 0x4c, >> + XSC_CMD_STAT_INVAL_FUNC =3D 0x41, >> +}; >> + >> +enum { >> + XSC_CMD_OP_QUERY_HCA_CAP =3D 0x100, >> + XSC_CMD_OP_QUERY_CMDQ_VERSION =3D 0x10a, >> + XSC_CMD_OP_FUNCTION_RESET =3D 0x10c, >> + >> + XSC_CMD_OP_CREATE_EQ =3D 0x301, >> + XSC_CMD_OP_DESTROY_EQ =3D 0x302, >> + >> + XSC_CMD_OP_CREATE_CQ =3D 0x400, >> + XSC_CMD_OP_DESTROY_CQ =3D 0x401, >> + >> + XSC_CMD_OP_CREATE_QP =3D 0x500, >> + XSC_CMD_OP_DESTROY_QP =3D 0x501, >> + XSC_CMD_OP_2RST_QP =3D 0x50a, >> + XSC_CMD_OP_RTR2RTS_QP =3D 0x504, >> + >> + XSC_CMD_OP_ENABLE_NIC_HCA =3D 0x810, >> + XSC_CMD_OP_DISABLE_NIC_HCA =3D 0x811, >> + XSC_CMD_OP_MODIFY_RAW_QP =3D 0x81f, >> + >> + XSC_CMD_OP_QUERY_VPORT_STATE =3D 0x822, >> + XSC_CMD_OP_QUERY_EVENT_TYPE =3D 0x831, >> + >> + XSC_CMD_OP_ENABLE_MSIX =3D 0x850, >> + >> + XSC_CMD_OP_SET_MTU =3D 0x1100, >> + XSC_CMD_OP_QUERY_ETH_MAC =3D 0x1101, >> + >> + XSC_CMD_OP_SET_PORT_ADMIN_STATUS =3D 0x1801, >> +}; >> + >> +enum xsc_dma_direct { >> + XSC_DMA_DIR_TO_MAC, >> +}; >> + >> +enum { >> + XSC_TBM_CAP_HASH_PPH =3D 0, >> + XSC_TBM_CAP_RSS, >> + XSC_TBM_CAP_PCT_DROP_CONFIG, >> +}; >> + >> +struct xsc_inbox_hdr { >> + __be16 opcode; >> + u8 rsvd[4]; >> + __be16 ver; >> +}; >> + >> +struct xsc_outbox_hdr { >> + u8 status; >> + u8 rsvd[5]; >> + __be16 ver; >> +}; >> + >> +/* CQ mbox */ >> +struct xsc_cq_context { >> + __be16 eqn; >> + __be16 pa_num; >> + __be16 glb_func_id; >> + u8 log_cq_sz; >> + u8 cq_type; >> +}; >> + >> +struct xsc_create_cq_mbox_in { >> + struct xsc_inbox_hdr hdr; >> + struct xsc_cq_context ctx; >> + __be64 pas[]; >> +}; >> + >> +struct xsc_create_cq_mbox_out { >> + struct xsc_outbox_hdr hdr; >> + __be32 cqn; >> + u8 rsvd[4]; >> +}; >> + >> +struct xsc_destroy_cq_mbox_in { >> + struct xsc_inbox_hdr hdr; >> + __be32 cqn; >> + u8 rsvd[4]; >> +}; >> + >> +struct xsc_destroy_cq_mbox_out { >> + struct xsc_outbox_hdr hdr; >> + u8 rsvd[8]; >> +}; >> + >> +/* QP mbox */ >> +struct __packed xsc_create_qp_request { >> + __be16 input_qpn; >> + __be16 pa_num; >> + u8 qp_type; >> + u8 log_sq_sz; >> + u8 log_rq_sz; >> + u8 dma_direct; >> + __be32 pdn; >> + __be16 cqn_send; >> + __be16 cqn_recv; >> + __be16 glb_funcid; >> + u8 page_shift; >> + u8 rsvd[5]; >> + __be64 pas[]; >> +}; >> + >> +struct xsc_create_qp_mbox_in { >> + struct xsc_inbox_hdr hdr; >> + struct xsc_create_qp_request req; >> +}; >> + >> +struct xsc_create_qp_mbox_out { >> + struct xsc_outbox_hdr hdr; >> + __be32 qpn; >> + u8 rsvd[4]; >> +}; >> + >> +struct xsc_destroy_qp_mbox_in { >> + struct xsc_inbox_hdr hdr; >> + __be32 qpn; >> + u8 rsvd[4]; >> +}; >> + >> +struct xsc_destroy_qp_mbox_out { >> + struct xsc_outbox_hdr hdr; >> + u8 rsvd[8]; >> +}; >> + >> +struct xsc_qp_context { >> + __be32 remote_qpn; >> + __be32 cqn_send; >> + __be32 cqn_recv; >> + __be32 next_send_psn; >> + __be32 next_recv_psn; >> + __be32 pdn; >> + __be16 src_udp_port; >> + __be16 path_id; >> + u8 mtu_mode; >> + u8 lag_sel; >> + u8 lag_sel_en; >> + u8 retry_cnt; >> + u8 rnr_retry; >> + u8 dscp; >> + u8 state; >> + u8 hop_limit; >> + u8 dmac[6]; >> + u8 smac[6]; >> + __be32 dip[4]; >> + __be32 sip[4]; >> + __be16 ip_type; >> + __be16 grp_id; >> + u8 vlan_valid; >> + u8 dci_cfi_prio_sl; >> + __be16 vlan_id; >> + u8 qp_out_port; >> + u8 pcie_no; >> + __be16 lag_id; >> + __be16 func_id; >> + u8 max_sra; >> + u8 max_rra; >> + u8 no_need_wait; >> + u8 swith_qp_type; >> + u8 rsvd0[2]; >> + __be32 qp_access_flags; >> +}; >> + >> +struct xsc_modify_qp_mbox_in { >> + struct xsc_inbox_hdr hdr; >> + __be32 qpn; >> + struct xsc_qp_context ctx; >> + u8 no_need_wait; >> +}; >> + >> +struct xsc_modify_qp_mbox_out { >> + struct xsc_outbox_hdr hdr; >> + u8 rsvd[8]; >> +}; >> + >> +struct xsc_modify_raw_qp_request { >> + __be16 qpn; >> + __be16 lag_id; >> + __be16 func_id; >> + u8 dma_direct; >> + u8 prio; >> + u8 qp_out_port; >> + u8 rsvd[7]; >> +}; >> + >> +struct xsc_modify_raw_qp_mbox_in { >> + struct xsc_inbox_hdr hdr; >> + u8 pcie_no; >> + u8 rsvd[7]; >> + struct xsc_modify_raw_qp_request req; >> +}; >> + >> +struct xsc_modify_raw_qp_mbox_out { >> + struct xsc_outbox_hdr hdr; >> + u8 rsvd[8]; >> +}; >> + >> +/* MSIX TABLE mbox */ >> +struct xsc_msix_table_info_mbox_in { >> + struct xsc_inbox_hdr hdr; >> + __be16 index; >> + u8 rsvd[6]; >> +}; >> + >> +struct xsc_msix_table_info_mbox_out { >> + struct xsc_outbox_hdr hdr; >> + __be32 addr_lo; >> + __be32 addr_hi; >> + __be32 data; >> +}; >> + >> +/* EQ mbox */ >> +struct xsc_eq_context { >> + __be16 vecidx; >> + __be16 pa_num; >> + u8 log_eq_sz; >> + u8 rsvd1; >> + __be16 glb_func_id; >> + u8 is_async_eq; >> + u8 rsvd; >> +}; >> + >> +struct xsc_create_eq_mbox_in { >> + struct xsc_inbox_hdr hdr; >> + struct xsc_eq_context ctx; >> + u8 rsvd[6]; >> + __be64 pas[]; >> +}; >> + >> +struct xsc_create_eq_mbox_out { >> + struct xsc_outbox_hdr hdr; >> + __be32 eqn; >> + u8 rsvd[4]; >> +}; >> + >> +struct xsc_destroy_eq_mbox_in { >> + struct xsc_inbox_hdr hdr; >> + __be32 eqn; >> + u8 rsvd[4]; >> +}; >> + >> +struct xsc_destroy_eq_mbox_out { >> + struct xsc_outbox_hdr hdr; >> + u8 rsvd[8]; >> +}; >> + >> +struct xsc_cmd_query_cmdq_ver_mbox_in { >> + struct xsc_inbox_hdr hdr; >> + u8 rsvd[8]; >> +}; >> + >> +struct xsc_cmd_query_cmdq_ver_mbox_out { >> + struct xsc_outbox_hdr hdr; >> + __be16 cmdq_ver; >> + u8 rsvd[6]; >> +}; >> + >> +/* fw mailbox layout, do not change */ >> +struct xsc_fw_version { >> + u8 rsvd[16]; >> +}; >> + >> +struct __packed xsc_hca_cap { >> + u8 rsvd1[12]; >> + u8 send_seg_num; >> + u8 send_wqe_shift; >> + u8 recv_seg_num; >> + u8 recv_wqe_shift; >> + u8 log_max_srq_sz; >> + u8 log_max_qp_sz; >> + u8 log_max_mtt; >> + u8 log_max_qp; >> + u8 log_max_strq_sz; >> + u8 log_max_srqs; >> + u8 rsvd4[2]; >> + u8 log_max_tso; >> + u8 log_max_cq_sz; >> + u8 rsvd6; >> + u8 log_max_cq; >> + u8 log_max_eq_sz; >> + u8 log_max_mkey; >> + u8 log_max_msix; >> + u8 log_max_eq; >> + u8 max_indirection; >> + u8 log_max_mrw_sz; >> + u8 log_max_bsf_list_sz; >> + u8 log_max_klm_list_sz; >> + u8 rsvd_8_0; >> + u8 log_max_ra_req_dc; >> + u8 rsvd_8_1; >> + u8 log_max_ra_res_dc; >> + u8 rsvd9; >> + u8 log_max_ra_req_qp; >> + u8 log_max_qp_depth; >> + u8 log_max_ra_res_qp; >> + __be16 max_vfs; >> + __be16 raweth_qp_id_end; >> + __be16 raw_tpe_qp_num; >> + __be16 max_qp_count; >> + __be16 raweth_qp_id_base; >> + u8 rsvd13; >> + u8 local_ca_ack_delay; >> + u8 max_num_eqs; >> + u8 num_ports; >> + u8 log_max_msg; >> + u8 mac_port; >> + __be16 raweth_rss_qp_id_base; >> + __be16 stat_rate_support; >> + u8 rsvd16[8]; >> + __be64 flags; >> + u8 rsvd17; >> + u8 uar_sz; >> + u8 rsvd18; >> + u8 log_pg_sz; >> + __be16 bf_log_bf_reg_size; >> + __be16 msix_base; >> + __be16 msix_num; >> + __be16 max_desc_sz_sq; >> + u8 rsvd20[2]; >> + __be16 max_desc_sz_rq; >> + u8 rsvd21[2]; >> + __be16 max_desc_sz_sq_dc; >> + u8 rsvd22[4]; >> + __be16 max_qp_mcg; >> + u8 rsvd23; >> + u8 log_max_mcg; >> + u8 rsvd24; >> + u8 log_max_pd; >> + u8 rsvd25; >> + u8 log_max_xrcd; >> + u8 rsvd26[40]; >> + __be32 uar_page_sz; >> + u8 rsvd27[8]; >> + __be32 hw_feature_flag; >> + __be16 pf0_vf_funcid_base; >> + __be16 pf0_vf_funcid_top; >> + __be16 pf1_vf_funcid_base; >> + __be16 pf1_vf_funcid_top; >> + __be16 pcie0_pf_funcid_base; >> + __be16 pcie0_pf_funcid_top; >> + __be16 pcie1_pf_funcid_base; >> + __be16 pcie1_pf_funcid_top; >> + u8 log_msx_atomic_size_qp; >> + u8 pcie_host; >> + u8 rsvd28; >> + u8 log_msx_atomic_size_dc; >> + u8 board_sn[XSC_BOARD_SN_LEN]; >> + u8 max_tc; >> + u8 mac_bit; >> + __be16 funcid_to_logic_port; >> + u8 rsvd29[6]; >> + u8 nif_port_num; >> + u8 reg_mr_via_cmdq; >> + __be32 hca_core_clock; >> + __be32 max_rwq_indirection_tables; >> + __be32 max_rwq_indirection_table_size; >> + __be32 chip_ver_h; >> + __be32 chip_ver_m; >> + __be32 chip_ver_l; >> + __be32 hotfix_num; >> + __be32 feature_flag; >> + __be32 rx_pkt_len_max; >> + __be32 glb_func_id; >> + __be64 tx_db; >> + __be64 rx_db; >> + __be64 complete_db; >> + __be64 complete_reg; >> + __be64 event_db; >> + __be32 qp_rate_limit_min; >> + __be32 qp_rate_limit_max; >> + struct xsc_fw_version fw_ver; >> + u8 lag_logic_port_ofst; >> + u8 rsvd32[7]; >> + /* V1 */ >> + __be64 max_mr_size; >> + __be16 max_cmd_in_len; >> + __be16 max_cmd_out_len; >> + u8 rsvd_v2_v3[36]; >> + /* V4 */ >> + __be16 vf_funcid_base[XSC_MAX_NUM_PCIE_INTF][XSC_MAX_PF= _NUM_PER_PCIE]; >> + __be16 vf_funcid_top[XSC_MAX_NUM_PCIE_INTF][XSC_MAX_PF_= NUM_PER_PCIE]; >> + __be16 pf_funcid_base[XSC_MAX_NUM_PCIE_INTF]; >> + __be16 pf_funcid_top[XSC_MAX_NUM_PCIE_INTF]; >> + u8 pcie_no; >> + u8 pf_id; >> + __be16 vf_id; >> + u8 pcie_host_num; >> + u8 pf_num_per_pcie; >> + u8 rsvd_v6[46]; >> +}; >> + >> +struct xsc_cmd_query_hca_cap_mbox_in { >> + struct xsc_inbox_hdr hdr; >> + __be16 cpu_num; >> + u8 rsvd[6]; >> +}; >> + >> +struct xsc_cmd_query_hca_cap_mbox_out { >> + struct xsc_outbox_hdr hdr; >> + u8 rsvd0[8]; >> + struct xsc_hca_cap hca_cap; >> +}; >> + >> +struct xsc_query_vport_state_out { >> + struct xsc_outbox_hdr hdr; >> + u8 state; >> +#define XSC_QUERY_VPORT_ADMIN_STATE_MASK GENMASK(3, 0) >> +#define XSC_QUERY_VPORT_STATE_MASK GENMASK(7, 4) >> +}; >> + >> +struct xsc_query_vport_state_in { >> + struct xsc_inbox_hdr hdr; >> + __be32 data0; >> +#define XSC_QUERY_VPORT_OTHER_VPORT BIT(0) >> +#define XSC_QUERY_VPORT_VPORT_NUM_MASK GENMASK(16, 1) >> +}; >> + >> +enum { >> + XSC_CMD_EVENT_RESP_CHANGE_LINK =3D BIT(0), >> +}; >> + >> +struct xsc_event_resp { >> + u8 resp_cmd_type; >> +}; >> + >> +struct xsc_event_query_type_mbox_in { >> + struct xsc_inbox_hdr hdr; >> + u8 rsvd[2]; >> +}; >> + >> +struct xsc_event_query_type_mbox_out { >> + struct xsc_outbox_hdr hdr; >> + struct xsc_event_resp ctx; >> +}; >> + >> +struct xsc_set_mtu_mbox_in { >> + struct xsc_inbox_hdr hdr; >> + __be16 mtu; >> + __be16 rx_buf_sz_min; >> + u8 mac_port; >> + u8 rsvd; >> +}; >> + >> +struct xsc_set_mtu_mbox_out { >> + struct xsc_outbox_hdr hdr; >> +}; >> + >> +struct xsc_query_eth_mac_mbox_in { >> + struct xsc_inbox_hdr hdr; >> + u8 index; >> +}; >> + >> +struct xsc_query_eth_mac_mbox_out { >> + struct xsc_outbox_hdr hdr; >> + u8 mac[ETH_ALEN]; >> +}; >> + >> +struct xsc_nic_attr { >> + __be16 caps; >> + __be16 caps_mask; >> + u8 mac_addr[ETH_ALEN]; >> +}; >> + >> +struct xsc_rss_attr { >> + u8 rss_en; >> + u8 hfunc; >> + __be16 rqn_base; >> + __be16 rqn_num; >> + u8 rsvd[2]; >> + __be32 hash_tmpl; >> +}; >> + >> +struct xsc_cmd_enable_nic_hca_mbox_in { >> + struct xsc_inbox_hdr hdr; >> + struct xsc_nic_attr nic; >> + struct xsc_rss_attr rss; >> +}; >> + >> +struct xsc_cmd_enable_nic_hca_mbox_out { >> + struct xsc_outbox_hdr hdr; >> + u8 rsvd0[2]; >> +}; >> + >> +struct xsc_nic_dis_attr { >> + __be16 caps; >> +}; >> + >> +struct xsc_cmd_disable_nic_hca_mbox_in { >> + struct xsc_inbox_hdr hdr; >> + struct xsc_nic_dis_attr nic; >> +}; >> + >> +struct xsc_cmd_disable_nic_hca_mbox_out { >> + struct xsc_outbox_hdr hdr; >> + u8 rsvd0[4]; >> +}; >> + >> +struct xsc_function_reset_mbox_in { >> + struct xsc_inbox_hdr hdr; >> + __be16 glb_func_id; >> + u8 rsvd[6]; >> +}; >> + >> +struct xsc_function_reset_mbox_out { >> + struct xsc_outbox_hdr hdr; >> + u8 rsvd[8]; >> +}; >> + >> +struct xsc_event_set_port_admin_status_mbox_in { >> + struct xsc_inbox_hdr hdr; >> + __be16 status; >> +}; >> + >> +struct xsc_event_set_port_admin_status_mbox_out { >> + struct xsc_outbox_hdr hdr; >> + __be32 status; >> +}; >> + >> +int xsc_cmd_init(struct xsc_core_device *xdev); >> +void xsc_cmd_cleanup(struct xsc_core_device *xdev); >> +int xsc_cmd_exec(struct xsc_core_device *xdev, >> + void *in, unsigned int in_size, >> + void *out, unsigned int out_size); >> +int xsc_cmd_version_check(struct xsc_core_device *xdev); >> + >> +int xsc_cmd_status_to_err(struct xsc_outbox_hdr *hdr); >> + >> +#endif >> diff --git a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h b/dri= vers/net/ethernet/yunsilicon/xsc/common/xsc_core.h >> index 9580d89a1..a6f0149ed 100644 >> --- a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h >> +++ b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h >> @@ -24,12 +24,16 @@ >> #define XSC_PAGE_SHIFT_4K 12 >> #define XSC_PAGE_SIZE_4K (_AC(1, UL) << XSC_PAGE_SHIFT_4= K) >> >> +struct xsc_cmd; >> + >> struct xsc_core_device { >> struct pci_dev *pdev; >> struct device *device; >> >> void __iomem *bar; >> int bar_num; >> + >> + struct xsc_cmd *cmd; >> }; >> >> void xsc_update_tx_db(struct xsc_core_device *xdev, u32 sqn, u32 next_= pid); >> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/Makefile b/drivers/= net/ethernet/yunsilicon/xsc/pci/Makefile >> index 4a08b92cd..e17a10cc1 100644 >> --- a/drivers/net/ethernet/yunsilicon/xsc/pci/Makefile >> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/Makefile >> @@ -6,4 +6,4 @@ ccflags-y +=3D -I$(srctree)/drivers/net/ethernet/yunsili= con/xsc >> >> obj-$(CONFIG_YUNSILICON_XSC_PCI) +=3D xsc_pci.o >> >> -xsc_pci-y :=3D main.o doorbell.o >> +xsc_pci-y :=3D main.o cmd.o doorbell.o >> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/cmd.c b/drivers/net= /ethernet/yunsilicon/xsc/pci/cmd.c >> new file mode 100644 >> index 000000000..45dcdb2b4 >> --- /dev/null >> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/cmd.c >> @@ -0,0 +1,708 @@ >> +// SPDX-License-Identifier: GPL-2.0 >> +/* >> + * Copyright (c) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd. >> + * All rights reserved. >> + * Copyright (c) 2013-2016, Mellanox Technologies. All rights reserved. >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +#include "common/xsc_cmd.h" >> +#include "cmd.h" >> +#include "common/xsc_core.h" >> + >> +#define XSC_CMD_DATA_BLOCK_SIZE 512 >> +#define XSC_CMD_FIRST_SIZE 8 >> + >> +struct xsc_cmd_prot_block { >> + u8 data[XSC_CMD_DATA_BLOCK_SIZE]; >> + u8 rsvd0[48]; >> + __be64 next; >> + __be32 block_num; >> + u8 owner_status; >> + u8 token; >> + u8 ctrl_sig; >> + u8 sig; >> +}; >> + >> +/* hw layout, do not change */ >> +struct xsc_cmd_layout { >> + u16 rsv0; >> + u8 rsv[2]; >> + __be32 inlen; >> + __be64 in_ptr; >> + __be32 in[XSC_CMD_FIRST_SIZE]; >> + __be64 out_ptr; >> + __be32 outlen; >> + u8 token; >> + u8 sig; >> + u8 idx; >> + u8 type_owner; >> +}; >> + >> +struct xsc_rsp_layout { >> + u16 rsv0; >> + u8 rsv[2]; >> + __be32 out[XSC_RSP_FIRST_SIZE]; >> + u8 token; >> + u8 sig; >> + u8 idx; >> + u8 type_owner; >> +}; >> + >> +#define XSC_CMD_TYPE_MASK GENMASK(6, 0) >> +#define XSC_CMD_OWNER_BIT BIT(7) >> + >> +enum { >> + XSC_CMDQ_ERR_HW_READ_REQ_ERR =3D BIT(0), >> + XSC_CMDQ_ERR_HW_WRITE_REQ_ERR =3D BIT(1), >> + XSC_CMDQ_ERR_REQ_PID_ERR =3D BIT(2), >> + XSC_CMDQ_ERR_RSP_CID_ERR =3D BIT(3), >> +}; >> + >> +enum { >> + XSC_CMDQ_ELEMENT_SIZE_LOG =3D 6, >> + XSC_CMDQ_Q_DEPTH_LOG =3D 5, >> +}; >> + >> +static int xsc_alloc_ent(struct xsc_cmd *cmd) >> +{ >> + unsigned long flags; >> + int ret; >> + >> + spin_lock_irqsave(&cmd->alloc_lock, flags); >> + ret =3D find_first_bit(&cmd->cmd_entry_mask, cmd->max_reg_cmds); >> + if (ret < cmd->max_reg_cmds) >> + clear_bit(ret, &cmd->cmd_entry_mask); >> + spin_unlock_irqrestore(&cmd->alloc_lock, flags); >> + >> + return ret < cmd->max_reg_cmds ? ret : -ENOSPC; >> +} >> + >> +static void xsc_free_ent(struct xsc_cmd *cmd, int idx) >> +{ >> + unsigned long flags; >> + >> + spin_lock_irqsave(&cmd->alloc_lock, flags); >> + set_bit(idx, &cmd->cmd_entry_mask); >> + spin_unlock_irqrestore(&cmd->alloc_lock, flags); >> +} >> + >> +static struct xsc_cmd_layout *xsc_get_inst(struct xsc_cmd *cmd, int idx= ) >> +{ >> + return cmd->cmd_buf + (idx << cmd->log_stride); >> +} >> + >> +static struct xsc_rsp_layout *xsc_get_cq_inst(struct xsc_cmd *cmd, int = idx) >> +{ >> + return cmd->cq_buf + (idx << cmd->log_stride); >> +} >> + >> +static u8 xsc_rsp_owner_bit(struct xsc_rsp_layout *rsp) >> +{ >> + return !!(rsp->type_owner & XSC_CMD_OWNER_BIT); >> +} >> + >> +static u16 xsc_msg_to_opcode(const struct xsc_cmd_msg *in) >> +{ >> + const struct xsc_inbox_hdr *hdr =3D (const void *)in->first; >> + >> + return be16_to_cpu(hdr->opcode); >> +} >> + >> +static struct xsc_cmd_mailbox *xsc_alloc_cmd_box(struct xsc_core_device= *xdev, >> + gfp_t flags) >> +{ >> + struct xsc_cmd_mailbox *mailbox; >> + >> + mailbox =3D kmalloc_obj(*mailbox, flags); >> + if (!mailbox) >> + return ERR_PTR(-ENOMEM); >> + >> + mailbox->buf =3D dma_pool_zalloc(xdev->cmd->pool, flags, &mailbo= x->dma); >> + if (!mailbox->buf) { >> + kfree(mailbox); >> + return ERR_PTR(-ENOMEM); >> + } >> + mailbox->next =3D NULL; >> + >> + return mailbox; >> +} >> + >> +static void xsc_free_cmd_box(struct xsc_core_device *xdev, >> + struct xsc_cmd_mailbox *mailbox) >> +{ >> + dma_pool_free(xdev->cmd->pool, mailbox->buf, mailbox->dma); >> + kfree(mailbox); >> +} >> + >> +static struct xsc_cmd_msg *xsc_alloc_msg(struct xsc_core_device *xdev, >> + unsigned int size, >> + unsigned int first_size) >> +{ >> + struct xsc_cmd_mailbox *tmp, *head =3D NULL; >> + struct xsc_cmd_prot_block *block; >> + struct xsc_cmd_msg *msg; >> + unsigned int blen; >> + int err; >> + int n; >> + int i; >> + >> + msg =3D kzalloc_obj(*msg, GFP_KERNEL); >> + if (!msg) >> + return ERR_PTR(-ENOMEM); >> + >> + blen =3D size - min(size, first_size); >> + n =3D DIV_ROUND_UP(blen, XSC_CMD_DATA_BLOCK_SIZE); >> + >> + for (i =3D 0; i < n; i++) { >> + tmp =3D xsc_alloc_cmd_box(xdev, GFP_KERNEL); >> + if (IS_ERR(tmp)) { >> + pci_err(xdev->pdev, "failed allocating block\n")= ; >> + err =3D PTR_ERR(tmp); >> + goto err_free; >> + } >> + >> + block =3D tmp->buf; >> + tmp->next =3D head; >> + block->next =3D cpu_to_be64(tmp->next ? tmp->next->dma := 0); >> + block->block_num =3D cpu_to_be32(n - i - 1); >> + head =3D tmp; >> + } >> + msg->next =3D head; >> + msg->len =3D size; >> + msg->first_size =3D first_size; >> + >> + return msg; >> + >> +err_free: >> + while (head) { >> + tmp =3D head->next; >> + xsc_free_cmd_box(xdev, head); >> + head =3D tmp; >> + } >> + kfree(msg); >> + >> + return ERR_PTR(err); >> +} >> + >> +static void xsc_free_msg(struct xsc_core_device *xdev, struct xsc_cmd_m= sg *msg) >> +{ >> + struct xsc_cmd_mailbox *head =3D msg->next; >> + struct xsc_cmd_mailbox *next; >> + >> + while (head) { >> + next =3D head->next; >> + xsc_free_cmd_box(xdev, head); >> + head =3D next; >> + } >> + kfree(msg); >> +} >> + >> +static int xsc_copy_to_cmd_msg(struct xsc_cmd_msg *to, const void *from= , >> + unsigned int size) >> +{ >> + struct xsc_cmd_prot_block *block; >> + struct xsc_cmd_mailbox *next; >> + const u8 *src =3D from; >> + unsigned int copy; >> + >> + copy =3D min(size, to->first_size); >> + memcpy(to->first, src, copy); >> + size -=3D copy; >> + src +=3D copy; >> + >> + next =3D to->next; >> + while (size) { >> + if (!next) { >> + WARN_ONCE(1, "Mailbox too short\n"); >> + return -ENOMEM; >> + } >> + >> + copy =3D min(size, XSC_CMD_DATA_BLOCK_SIZE); >> + block =3D next->buf; >> + memcpy(block->data, src, copy); >> + block->owner_status =3D 0; >> + src +=3D copy; >> + size -=3D copy; >> + next =3D next->next; >> + } >> + >> + return 0; >> +} >> + >> +static int xsc_copy_from_rsp_msg(void *to, const struct xsc_cmd_msg *fr= om, >> + unsigned int size) >> +{ >> + struct xsc_cmd_prot_block *block; >> + struct xsc_cmd_mailbox *next; >> + u8 *dst =3D to; >> + unsigned int copy; >> + >> + copy =3D min(size, from->first_size); >> + memcpy(dst, from->first, copy); >> + size -=3D copy; >> + dst +=3D copy; >> + >> + next =3D from->next; >> + while (size) { >> + if (!next) { >> + WARN_ONCE(1, "Mailbox too short\n"); >> + return -ENOMEM; >> + } >> + >> + copy =3D min(size, XSC_CMD_DATA_BLOCK_SIZE); >> + block =3D next->buf; >> + if (!block->owner_status) >> + return -EIO; >> + >> + memcpy(dst, block->data, copy); >> + dst +=3D copy; >> + size -=3D copy; >> + next =3D next->next; >> + } >> + >> + return 0; >> +} >> + >> +static int xsc_cmd_invoke(struct xsc_core_device *xdev, struct xsc_cmd_= msg *in, >> + struct xsc_cmd_msg *out, u8 *status) >> +{ >> + struct xsc_cmd *cmd =3D xdev->cmd; >> + struct xsc_cmd_layout *lay; >> + struct xsc_cmd_work_ent *ent; >> + unsigned long timeout; >> + unsigned long flags; >> + int err; >> + >> + ent =3D kzalloc_obj(*ent, GFP_KERNEL); >> + if (!ent) >> + return -ENOMEM; >> + >> + ent->in =3D in; >> + ent->out =3D out; >> + init_completion(&ent->done); >> + down(&cmd->sem); >> + ent->idx =3D xsc_alloc_ent(cmd); >> + if (ent->idx < 0) { >> + pci_err(xdev->pdev, "failed to allocate command entry\n"= ); >> + up(&cmd->sem); >> + kfree(ent); >> + return -ENOMEM; >> + } >> + ent->token =3D ent->idx + 1; >> + cmd->ent_arr[ent->idx] =3D ent; >> + >> + spin_lock_irqsave(&cmd->doorbell_lock, flags); >> + lay =3D xsc_get_inst(cmd, cmd->cmd_pid); >> + memset(lay, 0, sizeof(*lay)); >> + memcpy(lay->in, in->first, sizeof(lay->in)); >> + if (in->next) >> + lay->in_ptr =3D cpu_to_be64(in->next->dma); >> + lay->inlen =3D cpu_to_be32(in->len); >> + if (out->next) >> + lay->out_ptr =3D cpu_to_be64(out->next->dma); >> + lay->outlen =3D cpu_to_be32(out->len); >> + lay->type_owner =3D FIELD_PREP(XSC_CMD_TYPE_MASK, XSC_PCI_CMD_XP= ORT); >> + lay->token =3D ent->token; >> + lay->idx =3D ent->idx; >> + lay->sig =3D 0xff; >> + >> + /* ring doorbell after the descriptor is valid */ >> + wmb(); >> + >> + cmd->cmd_pid =3D (cmd->cmd_pid + 1) % (1 << cmd->log_sz); >> + xsc_update_cmdq_req_pid(xdev, cmd->cmd_pid); >> + spin_unlock_irqrestore(&cmd->doorbell_lock, flags); >> + >> + timeout =3D msecs_to_jiffies(XSC_CMD_TIMEOUT_MSEC); >> + if (!wait_for_completion_timeout(&ent->done, timeout)) { >> + cmd->cmd_status =3D XSC_CMD_STATUS_TIMEDOUT; >> + pci_err(xdev->pdev, "wait for opcode 0x%x response timeo= ut\n", >> + xsc_msg_to_opcode(in)); >> + /* the entry stays registered for the completion handler= */ >> + return -ETIMEDOUT; >> + } >> + >> + err =3D ent->ret; >> + *status =3D ent->status; >> + >> + spin_lock_irqsave(&cmd->alloc_lock, flags); >> + if (cmd->ent_arr[ent->idx] =3D=3D ent) >> + cmd->ent_arr[ent->idx] =3D NULL; >> + spin_unlock_irqrestore(&cmd->alloc_lock, flags); >> + kfree(ent); >> + >> + return err; >> +} >> + >> +static void xsc_cmd_comp_handler(struct xsc_core_device *xdev, u8 idx, >> + struct xsc_rsp_layout *rsp) >> +{ >> + struct xsc_cmd *cmd =3D xdev->cmd; >> + struct xsc_cmd_work_ent *ent; >> + >> + if (idx >=3D cmd->max_reg_cmds || (cmd->cmd_entry_mask & BIT(idx= ))) { >> + pci_err(xdev->pdev, "idx[%d] exceeds max cmds or has no = request\n", >> + idx); >> + return; >> + } >> + ent =3D cmd->ent_arr[idx]; >> + >> + memcpy(ent->out->first, rsp->out, sizeof(rsp->out)); >> + ent->ret =3D 0; >> + ent->status =3D ((struct xsc_outbox_hdr *)ent->out->first)->stat= us; >> + cmd->retry_cnt =3D 0; >> + >> + xsc_free_ent(cmd, ent->idx); >> + complete(&ent->done); >> + up(&cmd->sem); >> +} >> + >> +static void xsc_cmd_handle_rsp_before_reload(struct xsc_cmd *cmd, >> + struct xsc_core_device *xde= v) >> +{ >> + u32 rsp_pid, rsp_cid; >> + >> + rsp_pid =3D xsc_get_cmdq_rsp_pid(xdev) & XSC_CMDQ_INDEX_MASK; >> + rsp_cid =3D xsc_get_cmdq_rsp_cid(xdev) & XSC_CMDQ_INDEX_MASK; >> + if (rsp_pid =3D=3D rsp_cid) >> + return; >> + >> + cmd->cq_cid =3D rsp_pid; >> + xsc_update_cmdq_rsp_cid(xdev, cmd->cq_cid); >> +} >> + >> +static void xsc_cmd_err_handler(struct xsc_core_device *xdev, u32 raw) >> +{ >> + struct xsc_cmd *cmd =3D xdev->cmd; >> + unsigned long flags; >> + int err =3D 0; >> + int retry =3D 0; >> + u32 stat =3D raw; >> + >> + while (stat) { >> + err++; >> + if (stat & XSC_CMDQ_ERR_HW_READ_REQ_ERR) { >> + retry =3D 1; >> + stat &=3D ~XSC_CMDQ_ERR_HW_READ_REQ_ERR; >> + pci_err(xdev->pdev, "hw read request from host f= ailed\n"); >> + } else if (stat & XSC_CMDQ_ERR_HW_WRITE_REQ_ERR) { >> + retry =3D 1; >> + stat &=3D ~XSC_CMDQ_ERR_HW_WRITE_REQ_ERR; >> + pci_err(xdev->pdev, "hw write request to fw fail= ed\n"); >> + } else if (stat & XSC_CMDQ_ERR_REQ_PID_ERR) { >> + stat &=3D ~XSC_CMDQ_ERR_REQ_PID_ERR; >> + pci_err(xdev->pdev, "hw reported unexpected req = pid\n"); >> + } else if (stat & XSC_CMDQ_ERR_RSP_CID_ERR) { >> + stat &=3D ~XSC_CMDQ_ERR_RSP_CID_ERR; >> + pci_err(xdev->pdev, "hw reported unexpected rsp = cid\n"); >> + } else { >> + stat =3D 0; >> + pci_err(xdev->pdev, "ignore unknown cmdq error\n= "); >> + } >> + } >> + >> + if (retry) { >> + if (cmd->retry_cnt >=3D XSC_CMD_MAX_RETRY_CNT) { >> + pci_warn(xdev->pdev, "error handler retried %d t= imes, stop retrying\n", >> + cmd->retry_cnt); >> + } else { >> + spin_lock_irqsave(&cmd->doorbell_lock, flags); >> + xsc_update_cmdq_req_pid(xdev, cmd->cmd_pid); >> + cmd->retry_cnt++; >> + spin_unlock_irqrestore(&cmd->doorbell_lock, flag= s); >> + } >> + } >> + >> + if (err) >> + xsc_clear_cmdq_err_status(xdev, raw); >> +} >> + >> +static int xsc_cmd_cq_polling(void *data) >> +{ >> + struct xsc_core_device *xdev =3D data; >> + struct xsc_cmd *cmd =3D xdev->cmd; >> + struct xsc_rsp_layout *rsp; >> + u32 err_status; >> + u32 cq_pid; >> + >> + while (!kthread_should_stop()) { >> + if (need_resched()) >> + schedule(); > cond_resched() Will use cond_resched(). > >> + >> + err_status =3D xsc_read_cmdq_err_status(xdev); >> + if (err_status) >> + xsc_cmd_err_handler(xdev, err_status); >> + >> + cq_pid =3D xsc_get_cmdq_rsp_pid(xdev) & XSC_CMDQ_INDEX_M= ASK; >> + if (cmd->cq_cid =3D=3D cq_pid) { >> + usleep_range(1000, 2000); > xsc_cmd_init() creates a kthread that polls the response ring every > 1-2ms, even with no command in flight. 1-2ms means around 1000 > periodic wakeups/context switches on one cpu. > > It reminds me of future RDMA support. I noticed there are a few > production applications where frequent create/modify/destroy of pairs > are unavoidable, meaning the latency there is sensitive. It's unlike > TCP 3-way handshake. 1-2ms will possibly add huge latency > comparatively. > > With that said, what I had in my mind is there are three directions: > 1. event-driven as you mentioned. Patch 5 already brings up the EQ and MS= I-X. > 2. demand-driven (dedicated) thread. Keep the kthread, but let the > submitter wake it and have it sleep on a waitqueue once no command is > outstanding. > 3. Or drop the kthread and let the submitter poll in xsc_cmd_invoke() > with read_poll_timeout(), using a staged delay (udelay(1) a few times, > then usleep_range(20, 30), then 1ms) as bnxt does in __hwrm_send(). > This also removes the fixed 1ms floor per command. > > Any thoughts on this? > > Thanks, > Jason =C2=A0 This is an intentional trade-off for =C2=A0 this series. The command queue only serves the control plane (QP/CQ= /EQ =C2=A0 create/destroy, queries, config), not the data path, so the complet= ion =C2=A0 latency does not affect throughput. This version ships a single-cha= nnel =C2=A0 ethernet driver where polling is sufficient, and to keep the series= lean =C2=A0 (the earlier ~6000-line concern) we keep only the poller for now. W= e do =C2=A0 plan to move the command queue to EQ-driven completion when multi-c= hannel =C2=A0 and RDMA support land. So I'd like to keep the poller -- I hope the =C2=A0 rationale makes sense. Thanks, Xin