From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3950EA2EDB for ; Fri, 6 Sep 2019 14:35:42 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0F43D1F32F; Fri, 6 Sep 2019 14:35:42 +0200 (CEST) Received: from huawei.com (szxga05-in.huawei.com [45.249.212.191]) by dpdk.org (Postfix) with ESMTP id DB6CE1F316 for ; Fri, 6 Sep 2019 14:35:39 +0200 (CEST) Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id E52174DD4DB70D1E1835 for ; Fri, 6 Sep 2019 20:35:38 +0800 (CST) Received: from tester.localdomain (10.175.119.39) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.439.0; Fri, 6 Sep 2019 20:35:31 +0800 From: Ziyang Xuan To: CC: , , , , , , , , Xiaoyun Wang Date: Fri, 6 Sep 2019 20:50:52 +0800 Message-ID: <8a01e9c2612db35a3cf9f648d62c16a1b0d0ea82.1567773211.git.xuanziyang2@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.119.39] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH v1 03/15] net/hinic: add VF PMD operation interfaces X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Xiaoyun Wang This patch adds VF PMD operation interfaces to support SRIOV. Signed-off-by: Ziyang Xuan --- drivers/net/hinic/hinic_pmd_ethdev.c | 236 +++++++++++++++++++++++------------ 1 file changed, 159 insertions(+), 77 deletions(-) diff --git a/drivers/net/hinic/hinic_pmd_ethdev.c b/drivers/net/hinic/hinic_pmd_ethdev.c index 044af90..90ebc16 100644 --- a/drivers/net/hinic/hinic_pmd_ethdev.c +++ b/drivers/net/hinic/hinic_pmd_ethdev.c @@ -20,6 +20,7 @@ #include "base/hinic_pmd_cmdq.h" #include "base/hinic_pmd_niccfg.h" #include "base/hinic_pmd_nicio.h" +#include "base/hinic_pmd_mbox.h" #include "hinic_pmd_ethdev.h" #include "hinic_pmd_tx.h" #include "hinic_pmd_rx.h" @@ -32,6 +33,8 @@ #define HINIC_DEV_ID_MEZZ_25GE 0x0210 #define HINIC_DEV_ID_MEZZ_40GE 0x020D #define HINIC_DEV_ID_MEZZ_100GE 0x0205 +#define HINIC_DEV_ID_VF 0x375E +#define HINIC_DEV_ID_VF_HV 0x379E #define HINIC_SERVICE_MODE_NIC 2 @@ -197,10 +200,16 @@ struct hinic_xstats_name_off { static int hinic_xstats_calc_num(struct hinic_nic_dev *nic_dev) { - return (HINIC_VPORT_XSTATS_NUM + - HINIC_PHYPORT_XSTATS_NUM + - HINIC_RXQ_XSTATS_NUM * nic_dev->num_rq + - HINIC_TXQ_XSTATS_NUM * nic_dev->num_sq); + if (HINIC_IS_VF(nic_dev->hwdev)) { + return (HINIC_VPORT_XSTATS_NUM + + HINIC_RXQ_XSTATS_NUM * nic_dev->num_rq + + HINIC_TXQ_XSTATS_NUM * nic_dev->num_sq); + } else { + return (HINIC_VPORT_XSTATS_NUM + + HINIC_PHYPORT_XSTATS_NUM + + HINIC_RXQ_XSTATS_NUM * nic_dev->num_rq + + HINIC_TXQ_XSTATS_NUM * nic_dev->num_sq); + } } static const struct rte_eth_desc_lim hinic_rx_desc_lim = { @@ -913,6 +922,8 @@ static int hinic_dev_start(struct rte_eth_dev *dev) (void)hinic_set_vport_enable(nic_dev->hwdev, false); en_vport_fail: + hinic_set_pf_status(nic_dev->hwdev->hwif, HINIC_PF_STATUS_INIT); + /* Flush tx && rx chip resources in case of set vport fake fail */ (void)hinic_flush_qp_res(nic_dev->hwdev); rte_delay_ms(100); @@ -1670,6 +1681,9 @@ static int hinic_dev_xstats_get(struct rte_eth_dev *dev, count++; } + if (HINIC_IS_VF(nic_dev->hwdev)) + return count; + /* Get stats from hinic_phy_port_stats */ err = hinic_get_phy_port_stats(nic_dev->hwdev, &port_stats); if (err) @@ -1738,6 +1752,9 @@ static int hinic_dev_xstats_get_names(struct rte_eth_dev *dev, count++; } + if (HINIC_IS_VF(nic_dev->hwdev)) + return count; + /* get phy port stats */ for (i = 0; i < HINIC_PHYPORT_XSTATS_NUM; i++) { snprintf(xstats_names[count].name, @@ -1778,18 +1795,39 @@ static int hinic_set_default_dcb_feature(struct hinic_nic_dev *nic_dev) up_pgid, up_bw, up_strict); } -static void hinic_init_default_cos(struct hinic_nic_dev *nic_dev) +static int hinic_init_default_cos(struct hinic_nic_dev *nic_dev) { - nic_dev->default_cos = - (hinic_global_func_id(nic_dev->hwdev) + - DEFAULT_BASE_COS) % NR_MAX_COS; + u8 cos_id = 0; + int err; + + if (!HINIC_IS_VF(nic_dev->hwdev)) { + nic_dev->default_cos = + (hinic_global_func_id(nic_dev->hwdev) + + DEFAULT_BASE_COS) % NR_MAX_COS; + } else { + err = hinic_vf_get_default_cos(nic_dev->hwdev, &cos_id); + if (err) { + PMD_DRV_LOG(ERR, "Get VF default cos failed, err: %d", + err); + return HINIC_ERROR; + } + + nic_dev->default_cos = cos_id; + } + + return 0; } static int hinic_set_default_hw_feature(struct hinic_nic_dev *nic_dev) { int err; - hinic_init_default_cos(nic_dev); + err = hinic_init_default_cos(nic_dev); + if (err) + return err; + + if (hinic_func_type(nic_dev->hwdev) == TYPE_VF) + return 0; /* Restore DCB configure to default status */ err = hinic_set_default_dcb_feature(nic_dev); @@ -1825,6 +1863,9 @@ static int32_t hinic_card_workmode_check(struct hinic_nic_dev *nic_dev) struct hinic_board_info info = { 0 }; int rc; + if (hinic_func_type(nic_dev->hwdev) == TYPE_VF) + return 0; + rc = hinic_get_board_info(nic_dev->hwdev, &info); if (rc) return rc; @@ -1840,7 +1881,7 @@ static int hinic_copy_mempool_init(struct hinic_nic_dev *nic_dev) nic_dev->cpy_mpool = rte_pktmbuf_pool_create(nic_dev->proc_dev_name, HINIC_COPY_MEMPOOL_DEPTH, - RTE_CACHE_LINE_SIZE, 0, + 0, 0, HINIC_COPY_MBUF_SIZE, rte_socket_id()); if (!nic_dev->cpy_mpool) { @@ -1951,6 +1992,14 @@ static int hinic_nic_dev_create(struct rte_eth_dev *eth_dev) goto init_pf_to_mgmt_fail; } + /* init mailbox */ + rc = hinic_comm_func_to_func_init(nic_dev->hwdev); + if (rc) { + PMD_DRV_LOG(ERR, "Initialize func_to_func failed, dev_name: %s", + eth_dev->data->name); + goto init_func_to_func_fail; + } + rc = hinic_card_workmode_check(nic_dev); if (rc) { PMD_DRV_LOG(ERR, "Check card workmode failed, dev_name: %s", @@ -2050,6 +2099,9 @@ static int hinic_nic_dev_create(struct rte_eth_dev *eth_dev) init_cmdq_fail: l2nic_reset_fail: workmode_check_fail: + hinic_comm_func_to_func_free(nic_dev->hwdev); + +init_func_to_func_fail: hinic_comm_pf_to_mgmt_free(nic_dev->hwdev); init_pf_to_mgmt_fail: @@ -2083,6 +2135,7 @@ static void hinic_nic_dev_destroy(struct rte_eth_dev *eth_dev) hinic_deinit_nicio(nic_dev->hwdev); hinic_deactivate_hwdev_state(nic_dev->hwdev); hinic_comm_cmdqs_free(nic_dev->hwdev); + hinic_comm_func_to_func_free(nic_dev->hwdev); hinic_comm_pf_to_mgmt_free(nic_dev->hwdev); hinic_comm_aeqs_free(nic_dev->hwdev); free_cfg_mgmt(nic_dev->hwdev); @@ -2092,6 +2145,93 @@ static void hinic_nic_dev_destroy(struct rte_eth_dev *eth_dev) nic_dev->hwdev = NULL; } +/** + * DPDK callback to close the device. + * + * @param dev + * Pointer to Ethernet device structure. + */ +static void hinic_dev_close(struct rte_eth_dev *dev) +{ + struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev); + + if (hinic_test_and_set_bit(HINIC_DEV_CLOSE, &nic_dev->dev_status)) { + PMD_DRV_LOG(WARNING, "Device %s already closed", + dev->data->name); + return; + } + + /* stop device first */ + hinic_dev_stop(dev); + + /* rx_cqe, rx_info */ + hinic_free_all_rx_resources(dev); + + /* tx_info */ + hinic_free_all_tx_resources(dev); + + /* free wq, pi_dma_addr */ + hinic_free_all_rq(nic_dev); + + /* free wq, db_addr */ + hinic_free_all_sq(nic_dev); + + /* deinit mac vlan tbl */ + hinic_deinit_mac_addr(dev); + + /* disable hardware and uio interrupt */ + hinic_disable_interrupt(dev); + + /* deinit nic hardware device */ + hinic_nic_dev_destroy(dev); +} + +static const struct eth_dev_ops hinic_pmd_ops = { + .dev_configure = hinic_dev_configure, + .dev_infos_get = hinic_dev_infos_get, + .rx_queue_setup = hinic_rx_queue_setup, + .tx_queue_setup = hinic_tx_queue_setup, + .dev_start = hinic_dev_start, + .link_update = hinic_link_update, + .rx_queue_release = hinic_rx_queue_release, + .tx_queue_release = hinic_tx_queue_release, + .dev_stop = hinic_dev_stop, + .dev_close = hinic_dev_close, + .promiscuous_enable = hinic_dev_promiscuous_enable, + .promiscuous_disable = hinic_dev_promiscuous_disable, + .rss_hash_update = hinic_rss_hash_update, + .rss_hash_conf_get = hinic_rss_conf_get, + .reta_update = hinic_rss_indirtbl_update, + .reta_query = hinic_rss_indirtbl_query, + .stats_get = hinic_dev_stats_get, + .stats_reset = hinic_dev_stats_reset, + .xstats_get = hinic_dev_xstats_get, + .xstats_reset = hinic_dev_xstats_reset, + .xstats_get_names = hinic_dev_xstats_get_names, +}; + +static const struct eth_dev_ops hinic_pmd_vf_ops = { + .dev_configure = hinic_dev_configure, + .dev_infos_get = hinic_dev_infos_get, + .rx_queue_setup = hinic_rx_queue_setup, + .tx_queue_setup = hinic_tx_queue_setup, + .dev_start = hinic_dev_start, + .link_update = hinic_link_update, + .rx_queue_release = hinic_rx_queue_release, + .tx_queue_release = hinic_tx_queue_release, + .dev_stop = hinic_dev_stop, + .dev_close = hinic_dev_close, + .rss_hash_update = hinic_rss_hash_update, + .rss_hash_conf_get = hinic_rss_conf_get, + .reta_update = hinic_rss_indirtbl_update, + .reta_query = hinic_rss_indirtbl_query, + .stats_get = hinic_dev_stats_get, + .stats_reset = hinic_dev_stats_reset, + .xstats_get = hinic_dev_xstats_get, + .xstats_reset = hinic_dev_xstats_reset, + .xstats_get_names = hinic_dev_xstats_get_names, +}; + static int hinic_func_init(struct rte_eth_dev *eth_dev) { struct rte_pci_device *pci_dev; @@ -2146,6 +2286,11 @@ static int hinic_func_init(struct rte_eth_dev *eth_dev) goto create_nic_dev_fail; } + if (HINIC_IS_VF(nic_dev->hwdev)) + eth_dev->dev_ops = &hinic_pmd_vf_ops; + else + eth_dev->dev_ops = &hinic_pmd_ops; + rc = hinic_init_mac_addr(eth_dev); if (rc) { PMD_DRV_LOG(ERR, "Initialize mac table failed, dev_name: %s", @@ -2187,6 +2332,7 @@ static int hinic_func_init(struct rte_eth_dev *eth_dev) hinic_deinit_mac_addr(eth_dev); init_mac_fail: + eth_dev->dev_ops = NULL; hinic_nic_dev_destroy(eth_dev); create_nic_dev_fail: @@ -2199,71 +2345,6 @@ static int hinic_func_init(struct rte_eth_dev *eth_dev) return rc; } -/** - * DPDK callback to close the device. - * - * @param dev - * Pointer to Ethernet device structure. - */ -static void hinic_dev_close(struct rte_eth_dev *dev) -{ - struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev); - - if (hinic_test_and_set_bit(HINIC_DEV_CLOSE, &nic_dev->dev_status)) { - PMD_DRV_LOG(WARNING, "Device %s already closed", - dev->data->name); - return; - } - - /* stop device first */ - hinic_dev_stop(dev); - - /* rx_cqe, rx_info */ - hinic_free_all_rx_resources(dev); - - /* tx_info */ - hinic_free_all_tx_resources(dev); - - /* free wq, pi_dma_addr */ - hinic_free_all_rq(nic_dev); - - /* free wq, db_addr */ - hinic_free_all_sq(nic_dev); - - /* deinit mac vlan tbl */ - hinic_deinit_mac_addr(dev); - - /* disable hardware and uio interrupt */ - hinic_disable_interrupt(dev); - - /* deinit nic hardware device */ - hinic_nic_dev_destroy(dev); -} - -static const struct eth_dev_ops hinic_pmd_ops = { - .dev_configure = hinic_dev_configure, - .dev_infos_get = hinic_dev_infos_get, - .rx_queue_setup = hinic_rx_queue_setup, - .tx_queue_setup = hinic_tx_queue_setup, - .dev_start = hinic_dev_start, - .link_update = hinic_link_update, - .rx_queue_release = hinic_rx_queue_release, - .tx_queue_release = hinic_tx_queue_release, - .dev_stop = hinic_dev_stop, - .dev_close = hinic_dev_close, - .promiscuous_enable = hinic_dev_promiscuous_enable, - .promiscuous_disable = hinic_dev_promiscuous_disable, - .rss_hash_update = hinic_rss_hash_update, - .rss_hash_conf_get = hinic_rss_conf_get, - .reta_update = hinic_rss_indirtbl_update, - .reta_query = hinic_rss_indirtbl_query, - .stats_get = hinic_dev_stats_get, - .stats_reset = hinic_dev_stats_reset, - .xstats_get = hinic_dev_xstats_get, - .xstats_reset = hinic_dev_xstats_reset, - .xstats_get_names = hinic_dev_xstats_get_names, -}; - static int hinic_dev_init(struct rte_eth_dev *eth_dev) { struct rte_pci_device *pci_dev; @@ -2276,8 +2357,7 @@ static int hinic_dev_init(struct rte_eth_dev *eth_dev) (rte_eal_process_type() == RTE_PROC_PRIMARY) ? "primary" : "secondary"); - /* rte_eth_dev ops, rx_burst and tx_burst */ - eth_dev->dev_ops = &hinic_pmd_ops; + /* rte_eth_dev rx_burst and tx_burst */ eth_dev->rx_pkt_burst = hinic_recv_pkts; eth_dev->tx_pkt_burst = hinic_xmit_pkts; @@ -2311,6 +2391,8 @@ static int hinic_dev_uninit(struct rte_eth_dev *dev) { RTE_PCI_DEVICE(HINIC_HUAWEI_VENDOR_ID, HINIC_DEV_ID_MEZZ_25GE) }, { RTE_PCI_DEVICE(HINIC_HUAWEI_VENDOR_ID, HINIC_DEV_ID_MEZZ_40GE) }, { RTE_PCI_DEVICE(HINIC_HUAWEI_VENDOR_ID, HINIC_DEV_ID_MEZZ_100GE) }, + { RTE_PCI_DEVICE(HINIC_HUAWEI_VENDOR_ID, HINIC_DEV_ID_VF) }, + { RTE_PCI_DEVICE(HINIC_HUAWEI_VENDOR_ID, HINIC_DEV_ID_VF_HV) }, {.vendor_id = 0}, }; -- 1.8.3.1