get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/98299/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 98299,
    "url": "http://patchwork.dpdk.org/api/patches/98299/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/20210908083758.312055-19-jiawenwu@trustnetic.com/",
    "project": {
        "id": 1,
        "url": "http://patchwork.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20210908083758.312055-19-jiawenwu@trustnetic.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20210908083758.312055-19-jiawenwu@trustnetic.com",
    "date": "2021-09-08T08:37:44",
    "name": "[18/32] net/ngbe: support SRIOV",
    "commit_ref": null,
    "pull_url": null,
    "state": "changes-requested",
    "archived": true,
    "hash": "5e0a4555891a7bc2b523e041553ac8cfcd9856de",
    "submitter": {
        "id": 1932,
        "url": "http://patchwork.dpdk.org/api/people/1932/?format=api",
        "name": "Jiawen Wu",
        "email": "jiawenwu@trustnetic.com"
    },
    "delegate": {
        "id": 319,
        "url": "http://patchwork.dpdk.org/api/users/319/?format=api",
        "username": "fyigit",
        "first_name": "Ferruh",
        "last_name": "Yigit",
        "email": "ferruh.yigit@amd.com"
    },
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/20210908083758.312055-19-jiawenwu@trustnetic.com/mbox/",
    "series": [
        {
            "id": 18760,
            "url": "http://patchwork.dpdk.org/api/series/18760/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=18760",
            "date": "2021-09-08T08:37:26",
            "name": "net/ngbe: add many features",
            "version": 1,
            "mbox": "http://patchwork.dpdk.org/series/18760/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/98299/comments/",
    "check": "success",
    "checks": "http://patchwork.dpdk.org/api/patches/98299/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 1CEFDA0C56;\n\tWed,  8 Sep 2021 10:38:23 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 9F785411E5;\n\tWed,  8 Sep 2021 10:37:01 +0200 (CEST)",
            "from smtpbgsg2.qq.com (smtpbgsg2.qq.com [54.254.200.128])\n by mails.dpdk.org (Postfix) with ESMTP id E4A20411B9\n for <dev@dpdk.org>; Wed,  8 Sep 2021 10:36:59 +0200 (CEST)",
            "from wxdbg.localdomain.com (unknown [183.129.236.74])\n by esmtp6.qq.com (ESMTP) with\n id ; Wed, 08 Sep 2021 16:36:53 +0800 (CST)"
        ],
        "X-QQ-mid": "bizesmtp47t1631090214thw9svho",
        "X-QQ-SSF": "01400000002000E0G000B00A0000000",
        "X-QQ-FEAT": "b6Px4984bbNRSt4IRKpenuLJYYWStPpnBl9ciRyQudp5L9h+1r7s0yCaLRHyx\n 8dIpVUfwC/K3+n6wzDi0d4+1dJpsJl9GO+dB6RrN22LD/EWM94TSciprquTgW9epH4NXXD5\n 9RlqF2EzZOH4BXnjmHJIdxtcuWg9rziVvTOWo9VTINHeQskgL+LvcliwA5CiRGoGFh0R8DM\n fuwDJfobGAoIS4+4XO1kW4duzuU+5c1l/EB9jbfwT3YUksLIDP9PlYB00AWFn9OH4PnCXTh\n Py/I6LU6zOp+eeaRLCk5TbcxlihAmot83k4YVxVWVmsJLRgDZMRwNx2vRQnaxZuCAFZSy4w\n HGOOhGaAh58D4280OiUtQrfPvb3g/MtEIniCML3",
        "X-QQ-GoodBg": "2",
        "From": "Jiawen Wu <jiawenwu@trustnetic.com>",
        "To": "dev@dpdk.org",
        "Cc": "Jiawen Wu <jiawenwu@trustnetic.com>",
        "Date": "Wed,  8 Sep 2021 16:37:44 +0800",
        "Message-Id": "<20210908083758.312055-19-jiawenwu@trustnetic.com>",
        "X-Mailer": "git-send-email 2.27.0",
        "In-Reply-To": "<20210908083758.312055-1-jiawenwu@trustnetic.com>",
        "References": "<20210908083758.312055-1-jiawenwu@trustnetic.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-QQ-SENDSIZE": "520",
        "Feedback-ID": "bizesmtp:trustnetic.com:qybgforeign:qybgforeign1",
        "X-QQ-Bgrelay": "1",
        "Subject": "[dpdk-dev] [PATCH 18/32] net/ngbe: support SRIOV",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Initialize and configure PF module to support SRIOV.\n\nSigned-off-by: Jiawen Wu <jiawenwu@trustnetic.com>\n---\n doc/guides/nics/features/ngbe.ini  |   1 +\n drivers/net/ngbe/base/meson.build  |   1 +\n drivers/net/ngbe/base/ngbe_dummy.h |  17 +++\n drivers/net/ngbe/base/ngbe_hw.c    |  47 ++++++-\n drivers/net/ngbe/base/ngbe_mbx.c   |  30 +++++\n drivers/net/ngbe/base/ngbe_mbx.h   |  11 ++\n drivers/net/ngbe/base/ngbe_type.h  |  22 ++++\n drivers/net/ngbe/meson.build       |   1 +\n drivers/net/ngbe/ngbe_ethdev.c     |  32 ++++-\n drivers/net/ngbe/ngbe_ethdev.h     |  19 +++\n drivers/net/ngbe/ngbe_pf.c         | 196 +++++++++++++++++++++++++++++\n drivers/net/ngbe/ngbe_rxtx.c       |  26 ++--\n 12 files changed, 390 insertions(+), 13 deletions(-)\n create mode 100644 drivers/net/ngbe/base/ngbe_mbx.c\n create mode 100644 drivers/net/ngbe/base/ngbe_mbx.h\n create mode 100644 drivers/net/ngbe/ngbe_pf.c",
    "diff": "diff --git a/doc/guides/nics/features/ngbe.ini b/doc/guides/nics/features/ngbe.ini\nindex 70d731a695..9a497ccae6 100644\n--- a/doc/guides/nics/features/ngbe.ini\n+++ b/doc/guides/nics/features/ngbe.ini\n@@ -20,6 +20,7 @@ Multicast MAC filter = Y\n RSS hash             = Y\n RSS key update       = Y\n RSS reta update      = Y\n+SR-IOV               = Y\n VLAN filter          = Y\n CRC offload          = P\n VLAN offload         = P\ndiff --git a/drivers/net/ngbe/base/meson.build b/drivers/net/ngbe/base/meson.build\nindex 6081281135..390b0f9c12 100644\n--- a/drivers/net/ngbe/base/meson.build\n+++ b/drivers/net/ngbe/base/meson.build\n@@ -4,6 +4,7 @@\n sources = [\n         'ngbe_eeprom.c',\n         'ngbe_hw.c',\n+        'ngbe_mbx.c',\n         'ngbe_mng.c',\n         'ngbe_phy.c',\n         'ngbe_phy_rtl.c',\ndiff --git a/drivers/net/ngbe/base/ngbe_dummy.h b/drivers/net/ngbe/base/ngbe_dummy.h\nindex 7814fd6226..5cb09bfcaa 100644\n--- a/drivers/net/ngbe/base/ngbe_dummy.h\n+++ b/drivers/net/ngbe/base/ngbe_dummy.h\n@@ -136,6 +136,14 @@ static inline s32 ngbe_mac_clear_vfta_dummy(struct ngbe_hw *TUP0)\n {\n \treturn NGBE_ERR_OPS_DUMMY;\n }\n+static inline void ngbe_mac_set_mac_anti_spoofing_dummy(struct ngbe_hw *TUP0,\n+\t\t\t\t\tbool TUP1, int TUP2)\n+{\n+}\n+static inline void ngbe_mac_set_vlan_anti_spoofing_dummy(struct ngbe_hw *TUP0,\n+\t\t\t\t\tbool TUP1, int TUP2)\n+{\n+}\n static inline s32 ngbe_mac_init_thermal_ssth_dummy(struct ngbe_hw *TUP0)\n {\n \treturn NGBE_ERR_OPS_DUMMY;\n@@ -187,6 +195,12 @@ static inline s32 ngbe_phy_check_link_dummy(struct ngbe_hw *TUP0, u32 *TUP1,\n {\n \treturn NGBE_ERR_OPS_DUMMY;\n }\n+\n+/* struct ngbe_mbx_operations */\n+static inline void ngbe_mbx_init_params_dummy(struct ngbe_hw *TUP0)\n+{\n+}\n+\n static inline void ngbe_init_ops_dummy(struct ngbe_hw *hw)\n {\n \thw->bus.set_lan_id = ngbe_bus_set_lan_id_dummy;\n@@ -214,6 +228,8 @@ static inline void ngbe_init_ops_dummy(struct ngbe_hw *hw)\n \thw->mac.init_rx_addrs = ngbe_mac_init_rx_addrs_dummy;\n \thw->mac.update_mc_addr_list = ngbe_mac_update_mc_addr_list_dummy;\n \thw->mac.clear_vfta = ngbe_mac_clear_vfta_dummy;\n+\thw->mac.set_mac_anti_spoofing = ngbe_mac_set_mac_anti_spoofing_dummy;\n+\thw->mac.set_vlan_anti_spoofing = ngbe_mac_set_vlan_anti_spoofing_dummy;\n \thw->mac.init_thermal_sensor_thresh = ngbe_mac_init_thermal_ssth_dummy;\n \thw->mac.check_overtemp = ngbe_mac_check_overtemp_dummy;\n \thw->phy.identify = ngbe_phy_identify_dummy;\n@@ -225,6 +241,7 @@ static inline void ngbe_init_ops_dummy(struct ngbe_hw *hw)\n \thw->phy.write_reg_unlocked = ngbe_phy_write_reg_unlocked_dummy;\n \thw->phy.setup_link = ngbe_phy_setup_link_dummy;\n \thw->phy.check_link = ngbe_phy_check_link_dummy;\n+\thw->mbx.init_params = ngbe_mbx_init_params_dummy;\n }\n \n #endif /* _NGBE_TYPE_DUMMY_H_ */\ndiff --git a/drivers/net/ngbe/base/ngbe_hw.c b/drivers/net/ngbe/base/ngbe_hw.c\nindex ce0867575a..8b45a91f78 100644\n--- a/drivers/net/ngbe/base/ngbe_hw.c\n+++ b/drivers/net/ngbe/base/ngbe_hw.c\n@@ -4,6 +4,7 @@\n  */\n \n #include \"ngbe_type.h\"\n+#include \"ngbe_mbx.h\"\n #include \"ngbe_phy.h\"\n #include \"ngbe_eeprom.h\"\n #include \"ngbe_mng.h\"\n@@ -1008,6 +1009,44 @@ s32 ngbe_setup_mac_link_em(struct ngbe_hw *hw,\n \treturn status;\n }\n \n+/**\n+ *  ngbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing\n+ *  @hw: pointer to hardware structure\n+ *  @enable: enable or disable switch for MAC anti-spoofing\n+ *  @vf: Virtual Function pool - VF Pool to set for MAC anti-spoofing\n+ *\n+ **/\n+void ngbe_set_mac_anti_spoofing(struct ngbe_hw *hw, bool enable, int vf)\n+{\n+\tu32 pfvfspoof;\n+\n+\tpfvfspoof = rd32(hw, NGBE_POOLTXASMAC);\n+\tif (enable)\n+\t\tpfvfspoof |= (1 << vf);\n+\telse\n+\t\tpfvfspoof &= ~(1 << vf);\n+\twr32(hw, NGBE_POOLTXASMAC, pfvfspoof);\n+}\n+\n+/**\n+ *  ngbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing\n+ *  @hw: pointer to hardware structure\n+ *  @enable: enable or disable switch for VLAN anti-spoofing\n+ *  @vf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing\n+ *\n+ **/\n+void ngbe_set_vlan_anti_spoofing(struct ngbe_hw *hw, bool enable, int vf)\n+{\n+\tu32 pfvfspoof;\n+\n+\tpfvfspoof = rd32(hw, NGBE_POOLTXASVLAN);\n+\tif (enable)\n+\t\tpfvfspoof |= (1 << vf);\n+\telse\n+\t\tpfvfspoof &= ~(1 << vf);\n+\twr32(hw, NGBE_POOLTXASVLAN, pfvfspoof);\n+}\n+\n /**\n  *  ngbe_init_thermal_sensor_thresh - Inits thermal sensor thresholds\n  *  @hw: pointer to hardware structure\n@@ -1231,6 +1270,7 @@ s32 ngbe_init_ops_pf(struct ngbe_hw *hw)\n \tstruct ngbe_mac_info *mac = &hw->mac;\n \tstruct ngbe_phy_info *phy = &hw->phy;\n \tstruct ngbe_rom_info *rom = &hw->rom;\n+\tstruct ngbe_mbx_info *mbx = &hw->mbx;\n \n \tDEBUGFUNC(\"ngbe_init_ops_pf\");\n \n@@ -1258,7 +1298,8 @@ s32 ngbe_init_ops_pf(struct ngbe_hw *hw)\n \n \tmac->disable_sec_rx_path = ngbe_disable_sec_rx_path;\n \tmac->enable_sec_rx_path = ngbe_enable_sec_rx_path;\n-\t/* RAR, Multicast */\n+\n+\t/* RAR, Multicast, VLAN */\n \tmac->set_rar = ngbe_set_rar;\n \tmac->clear_rar = ngbe_clear_rar;\n \tmac->init_rx_addrs = ngbe_init_rx_addrs;\n@@ -1266,6 +1307,8 @@ s32 ngbe_init_ops_pf(struct ngbe_hw *hw)\n \tmac->set_vmdq = ngbe_set_vmdq;\n \tmac->clear_vmdq = ngbe_clear_vmdq;\n \tmac->clear_vfta = ngbe_clear_vfta;\n+\tmac->set_mac_anti_spoofing = ngbe_set_mac_anti_spoofing;\n+\tmac->set_vlan_anti_spoofing = ngbe_set_vlan_anti_spoofing;\n \n \t/* Link */\n \tmac->get_link_capabilities = ngbe_get_link_capabilities_em;\n@@ -1276,6 +1319,8 @@ s32 ngbe_init_ops_pf(struct ngbe_hw *hw)\n \tmac->init_thermal_sensor_thresh = ngbe_init_thermal_sensor_thresh;\n \tmac->check_overtemp = ngbe_mac_check_overtemp;\n \n+\tmbx->init_params = ngbe_init_mbx_params_pf;\n+\n \t/* EEPROM */\n \trom->init_params = ngbe_init_eeprom_params;\n \trom->read32 = ngbe_ee_read32;\ndiff --git a/drivers/net/ngbe/base/ngbe_mbx.c b/drivers/net/ngbe/base/ngbe_mbx.c\nnew file mode 100644\nindex 0000000000..1ac9531ceb\n--- /dev/null\n+++ b/drivers/net/ngbe/base/ngbe_mbx.c\n@@ -0,0 +1,30 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2018-2021 Beijing WangXun Technology Co., Ltd.\n+ * Copyright(c) 2010-2017 Intel Corporation\n+ */\n+\n+#include \"ngbe_type.h\"\n+\n+#include \"ngbe_mbx.h\"\n+\n+/**\n+ *  ngbe_init_mbx_params_pf - set initial values for pf mailbox\n+ *  @hw: pointer to the HW structure\n+ *\n+ *  Initializes the hw->mbx struct to correct values for pf mailbox\n+ */\n+void ngbe_init_mbx_params_pf(struct ngbe_hw *hw)\n+{\n+\tstruct ngbe_mbx_info *mbx = &hw->mbx;\n+\n+\tmbx->timeout = 0;\n+\tmbx->usec_delay = 0;\n+\n+\tmbx->size = NGBE_P2VMBX_SIZE;\n+\n+\tmbx->stats.msgs_tx = 0;\n+\tmbx->stats.msgs_rx = 0;\n+\tmbx->stats.reqs = 0;\n+\tmbx->stats.acks = 0;\n+\tmbx->stats.rsts = 0;\n+}\ndiff --git a/drivers/net/ngbe/base/ngbe_mbx.h b/drivers/net/ngbe/base/ngbe_mbx.h\nnew file mode 100644\nindex 0000000000..d280945baf\n--- /dev/null\n+++ b/drivers/net/ngbe/base/ngbe_mbx.h\n@@ -0,0 +1,11 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2018-2021 Beijing WangXun Technology Co., Ltd.\n+ * Copyright(c) 2010-2017 Intel Corporation\n+ */\n+\n+#ifndef _NGBE_MBX_H_\n+#define _NGBE_MBX_H_\n+\n+void ngbe_init_mbx_params_pf(struct ngbe_hw *hw);\n+\n+#endif /* _NGBE_MBX_H_ */\ndiff --git a/drivers/net/ngbe/base/ngbe_type.h b/drivers/net/ngbe/base/ngbe_type.h\nindex 5a88d38e84..bc95fcf609 100644\n--- a/drivers/net/ngbe/base/ngbe_type.h\n+++ b/drivers/net/ngbe/base/ngbe_type.h\n@@ -254,6 +254,9 @@ struct ngbe_mac_info {\n \t\t\t\t      u32 mc_addr_count,\n \t\t\t\t      ngbe_mc_addr_itr func, bool clear);\n \ts32 (*clear_vfta)(struct ngbe_hw *hw);\n+\tvoid (*set_mac_anti_spoofing)(struct ngbe_hw *hw, bool enable, int vf);\n+\tvoid (*set_vlan_anti_spoofing)(struct ngbe_hw *hw,\n+\t\t\t\t\tbool enable, int vf);\n \n \t/* Manageability interface */\n \ts32 (*init_thermal_sensor_thresh)(struct ngbe_hw *hw);\n@@ -305,6 +308,24 @@ struct ngbe_phy_info {\n \tu32 autoneg_advertised;\n };\n \n+struct ngbe_mbx_stats {\n+\tu32 msgs_tx;\n+\tu32 msgs_rx;\n+\n+\tu32 acks;\n+\tu32 reqs;\n+\tu32 rsts;\n+};\n+\n+struct ngbe_mbx_info {\n+\tvoid (*init_params)(struct ngbe_hw *hw);\n+\n+\tstruct ngbe_mbx_stats stats;\n+\tu32 timeout;\n+\tu32 usec_delay;\n+\tu16 size;\n+};\n+\n enum ngbe_isb_idx {\n \tNGBE_ISB_HEADER,\n \tNGBE_ISB_MISC,\n@@ -321,6 +342,7 @@ struct ngbe_hw {\n \tstruct ngbe_phy_info phy;\n \tstruct ngbe_rom_info rom;\n \tstruct ngbe_bus_info bus;\n+\tstruct ngbe_mbx_info mbx;\n \tu16 device_id;\n \tu16 vendor_id;\n \tu16 sub_device_id;\ndiff --git a/drivers/net/ngbe/meson.build b/drivers/net/ngbe/meson.build\nindex c55e6c20e8..8b5195aab3 100644\n--- a/drivers/net/ngbe/meson.build\n+++ b/drivers/net/ngbe/meson.build\n@@ -13,6 +13,7 @@ objs = [base_objs]\n sources = files(\n         'ngbe_ethdev.c',\n         'ngbe_ptypes.c',\n+        'ngbe_pf.c',\n         'ngbe_rxtx.c',\n )\n \ndiff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c\nindex 0bc1400aea..70e471b2c2 100644\n--- a/drivers/net/ngbe/ngbe_ethdev.c\n+++ b/drivers/net/ngbe/ngbe_ethdev.c\n@@ -304,7 +304,7 @@ eth_ngbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)\n \tstruct rte_intr_handle *intr_handle = &pci_dev->intr_handle;\n \tconst struct rte_memzone *mz;\n \tuint32_t ctrl_ext;\n-\tint err;\n+\tint err, ret;\n \n \tPMD_INIT_FUNC_TRACE();\n \n@@ -423,6 +423,16 @@ eth_ngbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)\n \t/* initialize the hw strip bitmap*/\n \tmemset(hwstrip, 0, sizeof(*hwstrip));\n \n+\t/* initialize PF if max_vfs not zero */\n+\tret = ngbe_pf_host_init(eth_dev);\n+\tif (ret) {\n+\t\trte_free(eth_dev->data->mac_addrs);\n+\t\teth_dev->data->mac_addrs = NULL;\n+\t\trte_free(eth_dev->data->hash_mac_addrs);\n+\t\teth_dev->data->hash_mac_addrs = NULL;\n+\t\treturn ret;\n+\t}\n+\n \tctrl_ext = rd32(hw, NGBE_PORTCTL);\n \t/* let hardware know driver is loaded */\n \tctrl_ext |= NGBE_PORTCTL_DRVLOAD;\n@@ -926,6 +936,9 @@ ngbe_dev_start(struct rte_eth_dev *dev)\n \thw->mac.start_hw(hw);\n \thw->mac.get_link_status = true;\n \n+\t/* configure PF module if SRIOV enabled */\n+\tngbe_pf_host_configure(dev);\n+\n \tngbe_dev_phy_intr_setup(dev);\n \n \t/* check and configure queue intr-vector mapping */\n@@ -1087,8 +1100,10 @@ ngbe_dev_stop(struct rte_eth_dev *dev)\n \tstruct rte_eth_link link;\n \tstruct ngbe_adapter *adapter = ngbe_dev_adapter(dev);\n \tstruct ngbe_hw *hw = ngbe_dev_hw(dev);\n+\tstruct ngbe_vf_info *vfinfo = *NGBE_DEV_VFDATA(dev);\n \tstruct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);\n \tstruct rte_intr_handle *intr_handle = &pci_dev->intr_handle;\n+\tint vf;\n \n \tif (hw->adapter_stopped)\n \t\treturn 0;\n@@ -1111,6 +1126,9 @@ ngbe_dev_stop(struct rte_eth_dev *dev)\n \t/* stop adapter */\n \tngbe_stop_hw(hw);\n \n+\tfor (vf = 0; vfinfo != NULL && vf < pci_dev->max_vfs; vf++)\n+\t\tvfinfo[vf].clear_to_send = false;\n+\n \tngbe_dev_clear_queues(dev);\n \n \t/* Clear stored conf */\n@@ -1183,6 +1201,9 @@ ngbe_dev_close(struct rte_eth_dev *dev)\n \t\trte_delay_ms(100);\n \t} while (retries++ < (10 + NGBE_LINK_UP_TIME));\n \n+\t/* uninitialize PF if max_vfs not zero */\n+\tngbe_pf_host_uninit(dev);\n+\n \trte_free(dev->data->mac_addrs);\n \tdev->data->mac_addrs = NULL;\n \n@@ -1200,6 +1221,15 @@ ngbe_dev_reset(struct rte_eth_dev *dev)\n {\n \tint ret;\n \n+\t/* When a DPDK PMD PF begin to reset PF port, it should notify all\n+\t * its VF to make them align with it. The detailed notification\n+\t * mechanism is PMD specific. As to ngbe PF, it is rather complex.\n+\t * To avoid unexpected behavior in VF, currently reset of PF with\n+\t * SR-IOV activation is not supported. It might be supported later.\n+\t */\n+\tif (dev->data->sriov.active)\n+\t\treturn -ENOTSUP;\n+\n \tret = eth_ngbe_dev_uninit(dev);\n \tif (ret != 0)\n \t\treturn ret;\ndiff --git a/drivers/net/ngbe/ngbe_ethdev.h b/drivers/net/ngbe/ngbe_ethdev.h\nindex 083db6080b..f5a1363d10 100644\n--- a/drivers/net/ngbe/ngbe_ethdev.h\n+++ b/drivers/net/ngbe/ngbe_ethdev.h\n@@ -7,6 +7,8 @@\n #define _NGBE_ETHDEV_H_\n \n #include \"ngbe_ptypes.h\"\n+#include <rte_ethdev.h>\n+#include <rte_ethdev_core.h>\n \n /* need update link, bit flag */\n #define NGBE_FLAG_NEED_LINK_UPDATE  ((uint32_t)(1 << 0))\n@@ -75,6 +77,12 @@ struct ngbe_uta_info {\n \tuint32_t uta_shadow[NGBE_MAX_UTA];\n };\n \n+struct ngbe_vf_info {\n+\tuint8_t vf_mac_addresses[RTE_ETHER_ADDR_LEN];\n+\tbool clear_to_send;\n+\tuint16_t switch_domain_id;\n+};\n+\n /*\n  * Structure to store private data for each driver instance (for each port).\n  */\n@@ -85,6 +93,7 @@ struct ngbe_adapter {\n \tstruct ngbe_stat_mappings  stat_mappings;\n \tstruct ngbe_vfta           shadow_vfta;\n \tstruct ngbe_hwstrip        hwstrip;\n+\tstruct ngbe_vf_info        *vfdata;\n \tstruct ngbe_uta_info       uta_info;\n \tbool                       rx_bulk_alloc_allowed;\n \n@@ -129,6 +138,10 @@ ngbe_dev_intr(struct rte_eth_dev *dev)\n \n #define NGBE_DEV_HWSTRIP(dev) \\\n \t(&((struct ngbe_adapter *)(dev)->data->dev_private)->hwstrip)\n+\n+#define NGBE_DEV_VFDATA(dev) \\\n+\t(&((struct ngbe_adapter *)(dev)->data->dev_private)->vfdata)\n+\n #define NGBE_DEV_UTA_INFO(dev) \\\n \t(&((struct ngbe_adapter *)(dev)->data->dev_private)->uta_info)\n \n@@ -216,6 +229,12 @@ void ngbe_vlan_hw_filter_disable(struct rte_eth_dev *dev);\n \n void ngbe_vlan_hw_strip_config(struct rte_eth_dev *dev);\n \n+int ngbe_pf_host_init(struct rte_eth_dev *eth_dev);\n+\n+void ngbe_pf_host_uninit(struct rte_eth_dev *eth_dev);\n+\n+int ngbe_pf_host_configure(struct rte_eth_dev *eth_dev);\n+\n #define NGBE_LINK_DOWN_CHECK_TIMEOUT 4000 /* ms */\n #define NGBE_LINK_UP_CHECK_TIMEOUT   1000 /* ms */\n #define NGBE_VMDQ_NUM_UC_MAC         4096 /* Maximum nb. of UC MAC addr. */\ndiff --git a/drivers/net/ngbe/ngbe_pf.c b/drivers/net/ngbe/ngbe_pf.c\nnew file mode 100644\nindex 0000000000..2f9dfc4284\n--- /dev/null\n+++ b/drivers/net/ngbe/ngbe_pf.c\n@@ -0,0 +1,196 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2018-2021 Beijing WangXun Technology Co., Ltd.\n+ * Copyright(c) 2010-2017 Intel Corporation\n+ */\n+\n+#include <rte_ether.h>\n+#include <ethdev_driver.h>\n+#include <rte_malloc.h>\n+#include <rte_bus_pci.h>\n+\n+#include \"base/ngbe.h\"\n+#include \"ngbe_ethdev.h\"\n+\n+#define NGBE_MAX_VFTA     (128)\n+\n+static inline uint16_t\n+dev_num_vf(struct rte_eth_dev *eth_dev)\n+{\n+\tstruct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);\n+\n+\t/* EM only support 7 VFs. */\n+\treturn pci_dev->max_vfs;\n+}\n+\n+static inline\n+int ngbe_vf_perm_addr_gen(struct rte_eth_dev *dev, uint16_t vf_num)\n+{\n+\tunsigned char vf_mac_addr[RTE_ETHER_ADDR_LEN];\n+\tstruct ngbe_vf_info *vfinfo = *NGBE_DEV_VFDATA(dev);\n+\tuint16_t vfn;\n+\n+\tfor (vfn = 0; vfn < vf_num; vfn++) {\n+\t\trte_eth_random_addr(vf_mac_addr);\n+\t\t/* keep the random address as default */\n+\t\tmemcpy(vfinfo[vfn].vf_mac_addresses, vf_mac_addr,\n+\t\t\t   RTE_ETHER_ADDR_LEN);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+int ngbe_pf_host_init(struct rte_eth_dev *eth_dev)\n+{\n+\tstruct ngbe_vf_info **vfinfo = NGBE_DEV_VFDATA(eth_dev);\n+\tstruct ngbe_uta_info *uta_info = NGBE_DEV_UTA_INFO(eth_dev);\n+\tstruct ngbe_hw *hw = ngbe_dev_hw(eth_dev);\n+\tuint16_t vf_num;\n+\tuint8_t nb_queue = 1;\n+\tint ret = 0;\n+\n+\tPMD_INIT_FUNC_TRACE();\n+\n+\tRTE_ETH_DEV_SRIOV(eth_dev).active = 0;\n+\tvf_num = dev_num_vf(eth_dev);\n+\tif (vf_num == 0)\n+\t\treturn ret;\n+\n+\t*vfinfo = rte_zmalloc(\"vf_info\",\n+\t\t\tsizeof(struct ngbe_vf_info) * vf_num, 0);\n+\tif (*vfinfo == NULL) {\n+\t\tPMD_INIT_LOG(ERR,\n+\t\t\t\"Cannot allocate memory for private VF data\\n\");\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\tret = rte_eth_switch_domain_alloc(&(*vfinfo)->switch_domain_id);\n+\tif (ret) {\n+\t\tPMD_INIT_LOG(ERR,\n+\t\t\t\"failed to allocate switch domain for device %d\", ret);\n+\t\trte_free(*vfinfo);\n+\t\t*vfinfo = NULL;\n+\t\treturn ret;\n+\t}\n+\n+\tmemset(uta_info, 0, sizeof(struct ngbe_uta_info));\n+\thw->mac.mc_filter_type = 0;\n+\n+\tRTE_ETH_DEV_SRIOV(eth_dev).active = ETH_8_POOLS;\n+\tRTE_ETH_DEV_SRIOV(eth_dev).nb_q_per_pool = nb_queue;\n+\tRTE_ETH_DEV_SRIOV(eth_dev).def_pool_q_idx =\n+\t\t\t(uint16_t)(vf_num * nb_queue);\n+\n+\tngbe_vf_perm_addr_gen(eth_dev, vf_num);\n+\n+\t/* init_mailbox_params */\n+\thw->mbx.init_params(hw);\n+\n+\treturn ret;\n+}\n+\n+void ngbe_pf_host_uninit(struct rte_eth_dev *eth_dev)\n+{\n+\tstruct ngbe_vf_info **vfinfo;\n+\tuint16_t vf_num;\n+\tint ret;\n+\n+\tPMD_INIT_FUNC_TRACE();\n+\n+\tRTE_ETH_DEV_SRIOV(eth_dev).active = 0;\n+\tRTE_ETH_DEV_SRIOV(eth_dev).nb_q_per_pool = 0;\n+\tRTE_ETH_DEV_SRIOV(eth_dev).def_pool_q_idx = 0;\n+\n+\tvf_num = dev_num_vf(eth_dev);\n+\tif (vf_num == 0)\n+\t\treturn;\n+\n+\tvfinfo = NGBE_DEV_VFDATA(eth_dev);\n+\tif (*vfinfo == NULL)\n+\t\treturn;\n+\n+\tret = rte_eth_switch_domain_free((*vfinfo)->switch_domain_id);\n+\tif (ret)\n+\t\tPMD_INIT_LOG(WARNING, \"failed to free switch domain: %d\", ret);\n+\n+\trte_free(*vfinfo);\n+\t*vfinfo = NULL;\n+}\n+\n+int ngbe_pf_host_configure(struct rte_eth_dev *eth_dev)\n+{\n+\tuint32_t vtctl, fcrth;\n+\tuint32_t vfre_offset;\n+\tuint16_t vf_num;\n+\tconst uint8_t VFRE_SHIFT = 5;  /* VFRE 32 bits per slot */\n+\tconst uint8_t VFRE_MASK = (uint8_t)((1U << VFRE_SHIFT) - 1);\n+\tstruct ngbe_hw *hw = ngbe_dev_hw(eth_dev);\n+\tuint32_t gpie;\n+\tuint32_t gcr_ext;\n+\tuint32_t vlanctrl;\n+\tint i;\n+\n+\tvf_num = dev_num_vf(eth_dev);\n+\tif (vf_num == 0)\n+\t\treturn -1;\n+\n+\t/* set the default pool for PF */\n+\tvtctl = rd32(hw, NGBE_POOLCTL);\n+\tvtctl &= ~NGBE_POOLCTL_DEFPL_MASK;\n+\tvtctl |= NGBE_POOLCTL_DEFPL(vf_num);\n+\tvtctl |= NGBE_POOLCTL_RPLEN;\n+\twr32(hw, NGBE_POOLCTL, vtctl);\n+\n+\tvfre_offset = vf_num & VFRE_MASK;\n+\n+\t/* Enable pools reserved to PF only */\n+\twr32(hw, NGBE_POOLRXENA(0), (~0U) << vfre_offset);\n+\twr32(hw, NGBE_POOLTXENA(0), (~0U) << vfre_offset);\n+\n+\twr32(hw, NGBE_PSRCTL, NGBE_PSRCTL_LBENA);\n+\n+\t/* clear VMDq map to perment rar 0 */\n+\thw->mac.clear_vmdq(hw, 0, BIT_MASK32);\n+\n+\t/* clear VMDq map to scan rar 31 */\n+\twr32(hw, NGBE_ETHADDRIDX, hw->mac.num_rar_entries);\n+\twr32(hw, NGBE_ETHADDRASS, 0);\n+\n+\t/* set VMDq map to default PF pool */\n+\thw->mac.set_vmdq(hw, 0, vf_num);\n+\n+\t/*\n+\t * SW msut set PORTCTL.VT_Mode the same as GPIE.VT_Mode\n+\t */\n+\tgpie = rd32(hw, NGBE_GPIE);\n+\tgpie |= NGBE_GPIE_MSIX;\n+\tgcr_ext = rd32(hw, NGBE_PORTCTL);\n+\tgcr_ext &= ~NGBE_PORTCTL_NUMVT_MASK;\n+\n+\tif (RTE_ETH_DEV_SRIOV(eth_dev).active == ETH_8_POOLS)\n+\t\tgcr_ext |= NGBE_PORTCTL_NUMVT_8;\n+\n+\twr32(hw, NGBE_PORTCTL, gcr_ext);\n+\twr32(hw, NGBE_GPIE, gpie);\n+\n+\t/*\n+\t * enable vlan filtering and allow all vlan tags through\n+\t */\n+\tvlanctrl = rd32(hw, NGBE_VLANCTL);\n+\tvlanctrl |= NGBE_VLANCTL_VFE; /* enable vlan filters */\n+\twr32(hw, NGBE_VLANCTL, vlanctrl);\n+\n+\t/* enable all vlan filters */\n+\tfor (i = 0; i < NGBE_MAX_VFTA; i++)\n+\t\twr32(hw, NGBE_VLANTBL(i), 0xFFFFFFFF);\n+\n+\t/* Enable MAC Anti-Spoofing */\n+\thw->mac.set_mac_anti_spoofing(hw, FALSE, vf_num);\n+\n+\t/* set flow control threshold to max to avoid tx switch hang */\n+\twr32(hw, NGBE_FCWTRLO, 0);\n+\tfcrth = rd32(hw, NGBE_PBRXSIZE) - 32;\n+\twr32(hw, NGBE_FCWTRHI, fcrth);\n+\n+\treturn 0;\n+}\n+\ndiff --git a/drivers/net/ngbe/ngbe_rxtx.c b/drivers/net/ngbe/ngbe_rxtx.c\nindex 04abc2bb47..91cafed7fc 100644\n--- a/drivers/net/ngbe/ngbe_rxtx.c\n+++ b/drivers/net/ngbe/ngbe_rxtx.c\n@@ -1886,7 +1886,8 @@ ngbe_dev_tx_queue_setup(struct rte_eth_dev *dev,\n \ttxq->hthresh = tx_conf->tx_thresh.hthresh;\n \ttxq->wthresh = tx_conf->tx_thresh.wthresh;\n \ttxq->queue_id = queue_idx;\n-\ttxq->reg_idx = queue_idx;\n+\ttxq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?\n+\t\tqueue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);\n \ttxq->port_id = dev->data->port_id;\n \ttxq->offloads = offloads;\n \ttxq->ops = &def_txq_ops;\n@@ -2138,7 +2139,8 @@ ngbe_dev_rx_queue_setup(struct rte_eth_dev *dev,\n \trxq->nb_rx_desc = nb_desc;\n \trxq->rx_free_thresh = rx_conf->rx_free_thresh;\n \trxq->queue_id = queue_idx;\n-\trxq->reg_idx = queue_idx;\n+\trxq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?\n+\t\tqueue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);\n \trxq->port_id = dev->data->port_id;\n \tif (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_KEEP_CRC)\n \t\trxq->crc_len = RTE_ETHER_CRC_LEN;\n@@ -2530,16 +2532,18 @@ ngbe_alloc_rx_queue_mbufs(struct ngbe_rx_queue *rxq)\n static int\n ngbe_dev_mq_rx_configure(struct rte_eth_dev *dev)\n {\n-\tswitch (dev->data->dev_conf.rxmode.mq_mode) {\n-\tcase ETH_MQ_RX_RSS:\n-\t\tngbe_rss_configure(dev);\n-\t\tbreak;\n+\tif (RTE_ETH_DEV_SRIOV(dev).active == 0) {\n+\t\tswitch (dev->data->dev_conf.rxmode.mq_mode) {\n+\t\tcase ETH_MQ_RX_RSS:\n+\t\t\tngbe_rss_configure(dev);\n+\t\t\tbreak;\n \n-\tcase ETH_MQ_RX_NONE:\n-\tdefault:\n-\t\t/* if mq_mode is none, disable rss mode.*/\n-\t\tngbe_rss_disable(dev);\n-\t\tbreak;\n+\t\tcase ETH_MQ_RX_NONE:\n+\t\tdefault:\n+\t\t\t/* if mq_mode is none, disable rss mode.*/\n+\t\t\tngbe_rss_disable(dev);\n+\t\t\tbreak;\n+\t\t}\n \t}\n \n \treturn 0;\n",
    "prefixes": [
        "18/32"
    ]
}