From nobody Wed Sep 10 02:01:34 2025 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B97A30CD93; Fri, 5 Sep 2025 08:29:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757060956; cv=none; b=dxBhweP3p95xSIdnqL65BsGbtvY2JIImZ1H1dD27pFEYWup3ZKSN/P7j4eqhTQ4Z8r00rEj1SbkDC0IDLi1siqI09fDinjynShfQ5hBfusIVRMUfpQQOSYpFlIblhAePaGoJlgZjuNeIhThO9mOfcWJvdaejR16DE2xV2WhDp+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757060956; c=relaxed/simple; bh=BlZ5Qyg2AvEvaDO5MPR4REot4z1AfmBDWbmZ5/jyIDI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RfAcyQYNnIAsHz3TXi1rl4A6yabmKvJIE3X+TsMVYMiKA0LMnk0aHf5+IgttM5u3EC/fjB2xOBzxVeEhxmsYFf+UZjL3xUr29X2rBciJeT7Vsbf7bzrsbK1cSepRT1+DT8dg23LbJAHEiMVafC2+khmg9roy5g93ZFufOVa+pXo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4cJ8cY4jd2ztTWp; Fri, 5 Sep 2025 16:28:13 +0800 (CST) Received: from kwepemf100013.china.huawei.com (unknown [7.202.181.12]) by mail.maildlp.com (Postfix) with ESMTPS id A87C51402EB; Fri, 5 Sep 2025 16:29:09 +0800 (CST) Received: from DESKTOP-62GVMTR.china.huawei.com (10.174.189.55) by kwepemf100013.china.huawei.com (7.202.181.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 5 Sep 2025 16:29:07 +0800 From: Fan Gong To: Fan Gong , Zhu Yikai CC: , , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Andrew Lunn , , Jonathan Corbet , Bjorn Helgaas , luosifu , Xin Guo , Shen Chenyang , Zhou Shuai , Wu Like , Shi Jing , Luo Yang , Meny Yossefi , Gur Stavi , Lee Trager , Michael Ellerman , Vadim Fedorenko , Suman Ghosh , Przemek Kitszel , Joe Damato , Christophe JAILLET Subject: [PATCH net-next v04 06/14] hinic3: Nic_io initialization Date: Fri, 5 Sep 2025 16:28:40 +0800 Message-ID: <0d48674ae76a54bf52dcdba64fb60eb26e7e7e70.1757057860.git.zhuyikai1@h-partners.com> X-Mailer: git-send-email 2.51.0.windows.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To kwepemf100013.china.huawei.com (7.202.181.12) Content-Type: text/plain; charset="utf-8" Add nic_io initialization to enable NIC service, initialize function table and negotiate activation of NIC features. Co-developed-by: Zhu Yikai Signed-off-by: Zhu Yikai Signed-off-by: Fan Gong Reviewed-by: Vadim Fedorenko --- .../net/ethernet/huawei/hinic3/hinic3_hwdev.c | 15 ++++++ .../ethernet/huawei/hinic3/hinic3_nic_cfg.c | 23 +++++++++ .../ethernet/huawei/hinic3/hinic3_nic_cfg.h | 2 + .../ethernet/huawei/hinic3/hinic3_nic_io.c | 51 +++++++++++++++++-- 4 files changed, 88 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/huawei/hinic3/hinic3_hwdev.c b/drivers/ne= t/ethernet/huawei/hinic3/hinic3_hwdev.c index fa418e4f2654..95a213133be9 100644 --- a/drivers/net/ethernet/huawei/hinic3/hinic3_hwdev.c +++ b/drivers/net/ethernet/huawei/hinic3/hinic3_hwdev.c @@ -436,6 +436,18 @@ static void hinic3_uninit_comm_ch(struct hinic3_hwdev = *hwdev) free_base_mgmt_channel(hwdev); } =20 +static DEFINE_IDA(hinic3_adev_ida); + +static int hinic3_adev_idx_alloc(void) +{ + return ida_alloc(&hinic3_adev_ida, GFP_KERNEL); +} + +static void hinic3_adev_idx_free(int id) +{ + ida_free(&hinic3_adev_ida, id); +} + int hinic3_init_hwdev(struct pci_dev *pdev) { struct hinic3_pcidev *pci_adapter =3D pci_get_drvdata(pdev); @@ -451,6 +463,7 @@ int hinic3_init_hwdev(struct pci_dev *pdev) hwdev->pdev =3D pci_adapter->pdev; hwdev->dev =3D &pci_adapter->pdev->dev; hwdev->func_state =3D 0; + hwdev->dev_id =3D hinic3_adev_idx_alloc(); spin_lock_init(&hwdev->channel_lock); =20 err =3D hinic3_init_hwif(hwdev); @@ -504,6 +517,7 @@ int hinic3_init_hwdev(struct pci_dev *pdev) hinic3_free_hwif(hwdev); err_free_hwdev: pci_adapter->hwdev =3D NULL; + hinic3_adev_idx_free(hwdev->dev_id); kfree(hwdev); =20 return err; @@ -519,6 +533,7 @@ void hinic3_free_hwdev(struct hinic3_hwdev *hwdev) hinic3_free_cfg_mgmt(hwdev); destroy_workqueue(hwdev->workq); hinic3_free_hwif(hwdev); + hinic3_adev_idx_free(hwdev->dev_id); kfree(hwdev); } =20 diff --git a/drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c b/drivers/= net/ethernet/huawei/hinic3/hinic3_nic_cfg.c index 5b1a91a18c67..049f9536cb86 100644 --- a/drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c +++ b/drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c @@ -39,6 +39,12 @@ static int hinic3_feature_nego(struct hinic3_hwdev *hwde= v, u8 opcode, return 0; } =20 +int hinic3_get_nic_feature_from_hw(struct hinic3_nic_dev *nic_dev) +{ + return hinic3_feature_nego(nic_dev->hwdev, MGMT_MSG_CMD_OP_GET, + &nic_dev->nic_io->feature_cap, 1); +} + int hinic3_set_nic_feature_to_hw(struct hinic3_nic_dev *nic_dev) { return hinic3_feature_nego(nic_dev->hwdev, MGMT_MSG_CMD_OP_SET, @@ -82,6 +88,23 @@ static int hinic3_set_function_table(struct hinic3_hwdev= *hwdev, u32 cfg_bitmap, return 0; } =20 +int hinic3_init_function_table(struct hinic3_nic_dev *nic_dev) +{ + struct hinic3_nic_io *nic_io =3D nic_dev->nic_io; + struct l2nic_func_tbl_cfg func_tbl_cfg =3D {}; + u32 cfg_bitmap; + + func_tbl_cfg.mtu =3D 0x3FFF; /* default, max mtu */ + func_tbl_cfg.rx_wqe_buf_size =3D nic_io->rx_buf_len; + + cfg_bitmap =3D BIT(L2NIC_FUNC_TBL_CFG_INIT) | + BIT(L2NIC_FUNC_TBL_CFG_MTU) | + BIT(L2NIC_FUNC_TBL_CFG_RX_BUF_SIZE); + + return hinic3_set_function_table(nic_dev->hwdev, cfg_bitmap, + &func_tbl_cfg); +} + int hinic3_set_port_mtu(struct net_device *netdev, u16 new_mtu) { struct hinic3_nic_dev *nic_dev =3D netdev_priv(netdev); diff --git a/drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.h b/drivers/= net/ethernet/huawei/hinic3/hinic3_nic_cfg.h index bf9ce51dc401..6b6851650a37 100644 --- a/drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.h +++ b/drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.h @@ -22,11 +22,13 @@ enum hinic3_nic_event_type { HINIC3_NIC_EVENT_LINK_UP =3D 1, }; =20 +int hinic3_get_nic_feature_from_hw(struct hinic3_nic_dev *nic_dev); int hinic3_set_nic_feature_to_hw(struct hinic3_nic_dev *nic_dev); bool hinic3_test_support(struct hinic3_nic_dev *nic_dev, enum hinic3_nic_feature_cap feature_bits); void hinic3_update_nic_feature(struct hinic3_nic_dev *nic_dev, u64 feature= _cap); =20 +int hinic3_init_function_table(struct hinic3_nic_dev *nic_dev); int hinic3_set_port_mtu(struct net_device *netdev, u16 new_mtu); =20 int hinic3_set_mac(struct hinic3_hwdev *hwdev, const u8 *mac_addr, u16 vla= n_id, diff --git a/drivers/net/ethernet/huawei/hinic3/hinic3_nic_io.c b/drivers/n= et/ethernet/huawei/hinic3/hinic3_nic_io.c index 34a1f5bd5ac1..35168f03e0fa 100644 --- a/drivers/net/ethernet/huawei/hinic3/hinic3_nic_io.c +++ b/drivers/net/ethernet/huawei/hinic3/hinic3_nic_io.c @@ -11,11 +11,56 @@ =20 int hinic3_init_nic_io(struct hinic3_nic_dev *nic_dev) { - /* Completed by later submission due to LoC limit. */ - return -EFAULT; + struct hinic3_hwdev *hwdev =3D nic_dev->hwdev; + struct hinic3_nic_io *nic_io; + int err; + + nic_io =3D kzalloc(sizeof(*nic_io), GFP_KERNEL); + if (!nic_io) + return -ENOMEM; + + nic_dev->nic_io =3D nic_io; + + err =3D hinic3_set_func_svc_used_state(hwdev, COMM_FUNC_SVC_T_NIC, 1); + if (err) { + dev_err(hwdev->dev, "Failed to set function svc used state\n"); + goto err_free_nicio; + } + + err =3D hinic3_init_function_table(nic_dev); + if (err) { + dev_err(hwdev->dev, "Failed to init function table\n"); + goto err_clear_func_svc_used_state; + } + + nic_io->rx_buf_len =3D nic_dev->rx_buf_len; + + err =3D hinic3_get_nic_feature_from_hw(nic_dev); + if (err) { + dev_err(hwdev->dev, "Failed to get nic features\n"); + goto err_clear_func_svc_used_state; + } + + nic_io->feature_cap &=3D HINIC3_NIC_F_ALL_MASK; + nic_io->feature_cap &=3D HINIC3_NIC_DRV_DEFAULT_FEATURE; + dev_dbg(hwdev->dev, "nic features: 0x%llx\n\n", nic_io->feature_cap); + + return 0; + +err_clear_func_svc_used_state: + hinic3_set_func_svc_used_state(hwdev, COMM_FUNC_SVC_T_NIC, 0); +err_free_nicio: + nic_dev->nic_io =3D NULL; + kfree(nic_io); + + return err; } =20 void hinic3_free_nic_io(struct hinic3_nic_dev *nic_dev) { - /* Completed by later submission due to LoC limit. */ + struct hinic3_nic_io *nic_io =3D nic_dev->nic_io; + + hinic3_set_func_svc_used_state(nic_dev->hwdev, COMM_FUNC_SVC_T_NIC, 0); + nic_dev->nic_io =3D NULL; + kfree(nic_io); } --=20 2.43.0