Show a patch.

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

{
    "id": 41084,
    "url": "http://patches.dpdk.org/api/patches/41084/",
    "web_url": "http://patches.dpdk.org/patch/41084/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/",
        "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"
    },
    "msgid": "<20180614083047.10812-7-adrien.mazarguil@6wind.com>",
    "date": "2018-06-14T08:35:00",
    "name": "[v2,6/7] net/mlx5: probe all port representors",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "dc652cb893766cdfc01354afe02cc404992abdae",
    "submitter": {
        "id": 165,
        "url": "http://patches.dpdk.org/api/people/165/",
        "name": "Adrien Mazarguil",
        "email": "adrien.mazarguil@6wind.com"
    },
    "delegate": null,
    "mbox": "http://patches.dpdk.org/patch/41084/mbox/",
    "series": [
        {
            "id": 118,
            "url": "http://patches.dpdk.org/api/series/118/",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=118",
            "date": "2018-06-14T08:34:47",
            "name": "net/mlx5: add port representor support",
            "version": 2,
            "mbox": "http://patches.dpdk.org/series/118/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/41084/comments/",
    "check": "fail",
    "checks": "http://patches.dpdk.org/api/patches/41084/checks/",
    "tags": {},
    "headers": {
        "X-Mailman-Version": "2.1.15",
        "In-Reply-To": "<20180614083047.10812-1-adrien.mazarguil@6wind.com>",
        "Errors-To": "dev-bounces@dpdk.org",
        "X-Mailer": "git-send-email 2.11.0",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id D568E1E40F;\n\tThu, 14 Jun 2018 10:35:18 +0200 (CEST)",
            "from mail-wm0-f67.google.com (mail-wm0-f67.google.com\n\t[74.125.82.67]) by dpdk.org (Postfix) with ESMTP id 184A11E4BB\n\tfor <dev@dpdk.org>; Thu, 14 Jun 2018 10:35:16 +0200 (CEST)",
            "by mail-wm0-f67.google.com with SMTP id v16-v6so9044074wmh.5\n\tfor <dev@dpdk.org>; Thu, 14 Jun 2018 01:35:16 -0700 (PDT)",
            "from 6wind.com (host.78.145.23.62.rev.coltfrance.com.\n\t[62.23.145.78]) by smtp.gmail.com with ESMTPSA id\n\tc53-v6sm12025494wrg.12.2018.06.14.01.35.15\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tThu, 14 Jun 2018 01:35:15 -0700 (PDT)"
        ],
        "References": "<20180525161814.13873-1-adrien.mazarguil@6wind.com>\n\t<20180614083047.10812-1-adrien.mazarguil@6wind.com>",
        "X-Google-Smtp-Source": "ADUXVKJ9ug0aBgNiWjVSg5Sz8qmoMlkx+pe3+WBu4OOoHOnQjR9MqbnVm93Rg0g4gBYq2BVGDhq3/A==",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=6wind-com.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:in-reply-to;\n\tbh=ZtBAoQ1EF3KjkOzULMCfu4AfjlyWij9k6c/UDyXWHmI=;\n\tb=wGgEwV+D91L2HARzedZTZIHYxh/nFbjgRWusYb2ukqI9nDusFjBHnbE7f1AtEbvFmm\n\t4W1wQUz1W6oIiF3A5WvNm4R7hzJhqV2x56Qn+H9BsQ0D3bWkQluwptK97H/QOSxdLleu\n\tosoS5rGWcnTYs2a/JA9hkUWG0vi90dVfWeJOBP5OfK4MdVpny1DdGBpJn9B5sOm//RF7\n\tvOkKpG20ds5DNsPCV9c1s5a84swGtuy7ioNeAcqjg+fWpiE+Y/QYO+axa2JLVxcfFZja\n\t2HddUayyGRZ2weqIohJeEvuGHQLVWOtUMVZTMlydSmdWNYGRfrB58mlpDrma+p11zfTO\n\thLYg==",
        "MIME-Version": "1.0",
        "X-Received": "by 2002:a1c:f513:: with SMTP id\n\tt19-v6mr1149987wmh.50.1528965316304; \n\tThu, 14 Jun 2018 01:35:16 -0700 (PDT)",
        "Message-ID": "<20180614083047.10812-7-adrien.mazarguil@6wind.com>",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:in-reply-to;\n\tbh=ZtBAoQ1EF3KjkOzULMCfu4AfjlyWij9k6c/UDyXWHmI=;\n\tb=GZZY3Yy+yeeTKGoLf5bAZ/+pZ1g4/SqW4lQSMzVpqT0kooE8+opl6TXZ7XVDqfy2xQ\n\tbmI5LmWQ9B4QkcQaO0F20lmCSC/yvqfObesKE9bdI9ELNYPRa8cANpczzkSztRhgmEiO\n\tRi07NDa7qV/78VJWNWvP4dCzHIWwZNmrwW3XUxujXaJh6hrfo+iMMHVNdr21HMINzN7p\n\tSOsXxCx7otO8lE+3IaXzX68QXay4wsek9DYqXfPqZ0K+6ZrqagIj7ws7sbItsCkPH6Zu\n\tfmPGPeEqT3k/+6Mtikyr1axxiOdVgLsMpL1nDoSdGB7h1XVv3O2TKEUoid07wrkgG1S0\n\tiwHA==",
        "Delivered-To": "patchwork@dpdk.org",
        "Precedence": "list",
        "From": "Adrien Mazarguil <adrien.mazarguil@6wind.com>",
        "X-Original-To": "patchwork@dpdk.org",
        "Content-Type": "text/plain; charset=us-ascii",
        "Content-Disposition": "inline",
        "Return-Path": "<dev-bounces@dpdk.org>",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "To": "Shahaf Shuler <shahafs@mellanox.com>",
        "List-Subscribe": "<https://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "Date": "Thu, 14 Jun 2018 10:35:00 +0200",
        "X-Gm-Message-State": "APt69E2XiWkp2fyJ2yKzmbKSElp5tUWhX2t1tdH+4S7QlzEH4qOWa31H\n\tVTYpXYYPXgy/GmHnPfZ1aBg/Gg==",
        "Cc": "dev@dpdk.org",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "X-BeenThere": "dev@dpdk.org",
        "Subject": "[dpdk-dev] [PATCH v2 6/7] net/mlx5: probe all port representors"
    },
    "content": "Probe existing port representors in addition to their master device and\nassociate them automatically.\n\nTo avoid name collision between Ethernet devices, their names use the same\nconvention as ixgbe and i40e PMDs, that is, instead of only a PCI address\nin DBDF notation:\n\n- \"net_{DBDF}_0\" for master/switch devices.\n- \"net_{DBDF}_representor_{rep}\" with \"rep\" starting from 0 for port\n  representors.\n\nBoth optionally suffixed with \"_port_{num}\" instead of \" port {num}\" for\ndevices that expose several Verbs ports (note this is never the case on\nmlx5, but kept for historical reasons for the time being).\n\n(Patch based on prior work from Yuanhan Liu)\n\nSigned-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>\n--\nv2 changes:\n\n- Added representor information to dev_infos_get(). DPDK port ID of master\n  device is now stored in the private structure to retrieve it\n  conveniently.\n- Master device is assigned dummy representor ID value -1 to better\n  distinguish from the the first actual representor reported by\n  dev_infos_get() as those are indexed from 0.\n- Added RTE_ETH_DEV_REPRESENTOR device flag.\n---\n drivers/net/mlx5/mlx5.c        | 138 ++++++++++++++++++++++++--------\n drivers/net/mlx5/mlx5.h        |   9 ++-\n drivers/net/mlx5/mlx5_ethdev.c | 151 ++++++++++++++++++++++++++++++++----\n drivers/net/mlx5/mlx5_mac.c    |   2 +-\n drivers/net/mlx5/mlx5_stats.c  |   6 +-\n 5 files changed, 252 insertions(+), 54 deletions(-)",
    "diff": "diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c\nindex 498f80c89..716c9d9a5 100644\n--- a/drivers/net/mlx5/mlx5.c\n+++ b/drivers/net/mlx5/mlx5.c\n@@ -304,6 +304,9 @@ mlx5_dev_close(struct rte_eth_dev *dev)\n \tif (ret)\n \t\tDRV_LOG(WARNING, \"port %u some flows still remain\",\n \t\t\tdev->data->port_id);\n+\tif (!priv->representor &&\n+\t    priv->domain_id != RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID)\n+\t\tclaim_zero(rte_eth_switch_domain_free(priv->domain_id));\n \tmemset(priv, 0, sizeof(*priv));\n }\n \n@@ -648,6 +651,10 @@ mlx5_uar_init_secondary(struct rte_eth_dev *dev)\n  *   Verbs device attributes.\n  * @param port\n  *   Verbs port to use (indexed from 1).\n+ * @param master\n+ *   Master device in case @p ibv_dev is a port representor.\n+ * @param rep_id\n+ *   Representor identifier when @p master is non-NULL.\n  *\n  * @return\n  *   A valid Ethernet device object on success, NULL otherwise and rte_errno\n@@ -658,7 +665,9 @@ mlx5_dev_spawn_one(struct rte_device *dpdk_dev,\n \t\t   struct ibv_device *ibv_dev,\n \t\t   int vf,\n \t\t   const struct ibv_device_attr_ex *attr,\n-\t\t   unsigned int port)\n+\t\t   unsigned int port,\n+\t\t   struct rte_eth_dev *master,\n+\t\t   unsigned int rep_id)\n {\n \tstruct ibv_context *ctx;\n \tstruct ibv_port_attr port_attr;\n@@ -802,11 +811,14 @@ mlx5_dev_spawn_one(struct rte_device *dpdk_dev,\n \t\t\" old OFED/rdma-core version or firmware configuration\");\n #endif\n \tconfig.mpls_en = mpls_en;\n-\tif (attr->orig_attr.phys_port_cnt > 1)\n-\t\tsnprintf(name, sizeof(name), \"%s port %u\",\n-\t\t\t dpdk_dev->name, port);\n+\tif (!master)\n+\t\tsnprintf(name, sizeof(name), \"net_%s_0\", dpdk_dev->name);\n \telse\n-\t\tsnprintf(name, sizeof(name), \"%s\", dpdk_dev->name);\n+\t\tsnprintf(name, sizeof(name), \"net_%s_representor_%u\",\n+\t\t\t dpdk_dev->name, rep_id);\n+\tif (attr->orig_attr.phys_port_cnt > 1)\n+\t\tsnprintf(name, sizeof(name), \"%s_port_%u\", name, port);\n+\tDRV_LOG(DEBUG, \"naming Ethernet device \\\"%s\\\"\", name);\n \tif (rte_eal_process_type() == RTE_PROC_SECONDARY) {\n \t\teth_dev = rte_eth_dev_attach_secondary(name);\n \t\tif (eth_dev == NULL) {\n@@ -883,6 +895,30 @@ mlx5_dev_spawn_one(struct rte_device *dpdk_dev,\n \tpriv->port = port;\n \tpriv->pd = pd;\n \tpriv->mtu = ETHER_MTU;\n+\t/*\n+\t * Allocate a switch domain for master devices and share it with\n+\t * port representors.\n+\t */\n+\tif (!master) {\n+\t\tpriv->representor = 0;\n+\t\tpriv->master_id = -1; /* Updated once known. */\n+\t\tpriv->domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;\n+\t\tpriv->rep_id = -1; /* Dummy unique value. */\n+\t\terr = rte_eth_switch_domain_alloc(&priv->domain_id);\n+\t\tif (err) {\n+\t\t\terr = rte_errno;\n+\t\t\tDRV_LOG(ERR, \"unable to allocate switch domain: %s\",\n+\t\t\t\tstrerror(rte_errno));\n+\t\t\tgoto error;\n+\t\t}\n+\t} else {\n+\t\tpriv->representor = 1;\n+\t\tpriv->master_id =\n+\t\t\t((struct priv *)master->data->dev_private)->master_id;\n+\t\tpriv->domain_id =\n+\t\t\t((struct priv *)master->data->dev_private)->domain_id;\n+\t\tpriv->rep_id = rep_id;\n+\t}\n \terr = mlx5_args(&config, dpdk_dev->devargs);\n \tif (err) {\n \t\terr = rte_errno;\n@@ -964,6 +1000,18 @@ mlx5_dev_spawn_one(struct rte_device *dpdk_dev,\n \t\terr = ENOMEM;\n \t\tgoto error;\n \t}\n+\t/*\n+\t * Now that eth_dev is allocated and its port ID is known, make\n+\t * non-representor ports target their own port ID as master for\n+\t * convenience.\n+\t *\n+\t * Master port ID is already set for actual representors. Those only\n+\t * need the right device flag.\n+\t */\n+\tif (!master)\n+\t\tpriv->master_id = eth_dev->data->port_id;\n+\telse\n+\t\teth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;\n \teth_dev->data->dev_private = priv;\n \tpriv->dev_data = eth_dev->data;\n \teth_dev->data->mac_addrs = priv->mac;\n@@ -1083,8 +1131,12 @@ mlx5_dev_spawn_one(struct rte_device *dpdk_dev,\n \trte_rwlock_write_unlock(&mlx5_shared_data->mem_event_rwlock);\n \treturn eth_dev;\n error:\n-\tif (priv)\n+\tif (priv) {\n+\t\tif (!priv->representor &&\n+\t\t    priv->domain_id != RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID)\n+\t\t\tclaim_zero(rte_eth_switch_domain_free(priv->domain_id));\n \t\trte_free(priv);\n+\t}\n \tif (pd)\n \t\tclaim_zero(mlx5_glue->dealloc_pd(pd));\n \tif (eth_dev)\n@@ -1097,12 +1149,14 @@ mlx5_dev_spawn_one(struct rte_device *dpdk_dev,\n }\n \n /**\n- * Spawn Ethernet devices from Verbs information, one per detected port.\n+ * Spawn Ethernet devices from Verbs information, one per detected port and\n+ * port representor.\n  *\n  * @param dpdk_dev\n  *   Backing DPDK device.\n  * @param ibv_dev\n- *   Verbs device.\n+ *   NULL-terminated list of Verbs devices. First entry is the master device\n+ *   (mandatory), followed by optional representors.\n  * @param vf\n  *   If nonzero, enable VF-specific features.\n  *\n@@ -1113,17 +1167,21 @@ mlx5_dev_spawn_one(struct rte_device *dpdk_dev,\n  */\n static struct rte_eth_dev **\n mlx5_dev_spawn(struct rte_device *dpdk_dev,\n-\t       struct ibv_device *ibv_dev,\n+\t       struct ibv_device **ibv_dev,\n \t       int vf)\n {\n \tstruct rte_eth_dev **eth_list = NULL;\n \tstruct ibv_context *ctx;\n \tstruct ibv_device_attr_ex attr;\n+\tvoid *tmp;\n \tunsigned int i;\n+\tunsigned int j = 0;\n+\tunsigned int n = 0;\n \tint ret;\n \n+next:\n \terrno = 0;\n-\tctx = mlx5_glue->open_device(ibv_dev);\n+\tctx = mlx5_glue->open_device(ibv_dev[j]);\n \tif (!ctx) {\n \t\trte_errno = errno ? errno : ENODEV;\n \t\tif (rte_errno == ENODEV)\n@@ -1132,7 +1190,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,\n \t\telse\n \t\t\tDRV_LOG(ERR,\n \t\t\t\t\"cannot use device, are drivers up to date?\");\n-\t\treturn NULL;\n+\t\tgoto error;\n \t}\n \tret = mlx5_glue->query_device_ex(ctx, NULL, &attr);\n \tmlx5_glue->close_device(ctx);\n@@ -1140,34 +1198,42 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,\n \t\trte_errno = ret;\n \t\tDRV_LOG(ERR, \"unable to query device information: %s\",\n \t\t\tstrerror(rte_errno));\n-\t\treturn NULL;\n+\t\tgoto error;\n \t}\n-\tDRV_LOG(INFO, \"%u port(s) detected\", attr.orig_attr.phys_port_cnt);\n-\teth_list = malloc(sizeof(*eth_list) *\n-\t\t\t  (attr.orig_attr.phys_port_cnt + 1));\n-\tif (!eth_list) {\n+\tDRV_LOG(INFO, \"%u port(s) detected on \\\"%s\\\"\",\n+\t\tattr.orig_attr.phys_port_cnt, ibv_dev[j]->name);\n+\ttmp = realloc(eth_list, sizeof(*eth_list) *\n+\t\t      (n + attr.orig_attr.phys_port_cnt + 1));\n+\tif (!tmp) {\n \t\trte_errno = errno;\n-\t\treturn NULL;\n+\t\tgoto error;\n \t}\n+\teth_list = tmp;\n \tfor (i = 0; i < attr.orig_attr.phys_port_cnt; ++i) {\n-\t\teth_list[i] = mlx5_dev_spawn_one(dpdk_dev, ibv_dev, vf,\n-\t\t\t\t\t\t &attr, i + 1);\n-\t\tif (eth_list[i])\n-\t\t\tcontinue;\n-\t\t/* Save rte_errno and roll back in case of failure. */\n-\t\tret = rte_errno;\n-\t\twhile (i--) {\n-\t\t\tmlx5_dev_close(eth_list[i]);\n-\t\t\tif (rte_eal_process_type() == RTE_PROC_PRIMARY)\n-\t\t\t\trte_free(eth_list[i]->data->dev_private);\n-\t\t\tclaim_zero(rte_eth_dev_release_port(eth_list[i]));\n-\t\t}\n-\t\tfree(eth_list);\n-\t\trte_errno = ret;\n-\t\treturn NULL;\n+\t\teth_list[n] = mlx5_dev_spawn_one(dpdk_dev, ibv_dev[j], vf,\n+\t\t\t\t\t\t &attr, i + 1,\n+\t\t\t\t\t\t j ? eth_list[0] : NULL,\n+\t\t\t\t\t\t j - 1);\n+\t\tif (!eth_list[n])\n+\t\t\tgoto error;\n+\t\t++n;\n \t}\n-\teth_list[i] = NULL;\n+\tif (ibv_dev[++j])\n+\t\tgoto next;\n+\teth_list[n] = NULL;\n \treturn eth_list;\n+error:\n+\t/* Save rte_errno and roll back in case of failure. */\n+\tret = rte_errno;\n+\twhile (n--) {\n+\t\tmlx5_dev_close(eth_list[n]);\n+\t\tif (rte_eal_process_type() == RTE_PROC_PRIMARY)\n+\t\t\trte_free(eth_list[n]->data->dev_private);\n+\t\tclaim_zero(rte_eth_dev_release_port(eth_list[n]));\n+\t}\n+\tfree(eth_list);\n+\trte_errno = ret;\n+\treturn NULL;\n }\n \n /**\n@@ -1282,7 +1348,7 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,\n \t\t\t\tibv_match[ret]->name, ret - 1);\n \t}\n \tif (n)\n-\t\teth_list = mlx5_dev_spawn(&pci_dev->device, ibv_match[0], vf);\n+\t\teth_list = mlx5_dev_spawn(&pci_dev->device, ibv_match, vf);\n \tmlx5_glue->free_device_list(ibv_list);\n \tif (!n) {\n \t\tDRV_LOG(WARNING,\n@@ -1302,7 +1368,11 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,\n \t\tret = -rte_errno;\n \t} else {\n \t\tfor (ret = 0; eth_list[ret]; ++ret) {\n+\t\t\tuint32_t restore = eth_list[ret]->data->dev_flags;\n+\n \t\t\trte_eth_copy_pci_info(eth_list[ret], pci_dev);\n+\t\t\t/* Restore non-PCI flags cleared by the above call. */\n+\t\t\teth_list[ret]->data->dev_flags |= restore;\n \t\t\trte_eth_dev_probing_finish(eth_list[ret]);\n \t\t}\n \t\tret = 0;\ndiff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h\nindex 997b04a33..0fe467140 100644\n--- a/drivers/net/mlx5/mlx5.h\n+++ b/drivers/net/mlx5/mlx5.h\n@@ -161,6 +161,10 @@ struct priv {\n \tuint16_t mtu; /* Configured MTU. */\n \tuint8_t port; /* Physical port number. */\n \tunsigned int isolated:1; /* Whether isolated mode is enabled. */\n+\tunsigned int representor:1; /* Device is a port representor. */\n+\tuint16_t master_id; /* DPDK port ID of switch domain master. */\n+\tuint16_t domain_id; /* Switch domain identifier. */\n+\tunsigned int rep_id; /* Port representor identifier. */\n \t/* RX/TX queues. */\n \tunsigned int rxqs_n; /* RX queues array size. */\n \tunsigned int txqs_n; /* TX queues array size. */\n@@ -209,9 +213,12 @@ int mlx5_getenv_int(const char *);\n \n /* mlx5_ethdev.c */\n \n+int mlx5_get_master_ifname(const struct rte_eth_dev *dev,\n+\t\t\t   char (*ifname)[IF_NAMESIZE]);\n int mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[IF_NAMESIZE]);\n int mlx5_ifindex(const struct rte_eth_dev *dev);\n-int mlx5_ifreq(const struct rte_eth_dev *dev, int req, struct ifreq *ifr);\n+int mlx5_ifreq(const struct rte_eth_dev *dev, int req, struct ifreq *ifr,\n+\t       int master);\n int mlx5_get_mtu(struct rte_eth_dev *dev, uint16_t *mtu);\n int mlx5_set_flags(struct rte_eth_dev *dev, unsigned int keep,\n \t\t   unsigned int flags);\ndiff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c\nindex 90488af33..9d579659e 100644\n--- a/drivers/net/mlx5/mlx5_ethdev.c\n+++ b/drivers/net/mlx5/mlx5_ethdev.c\n@@ -93,7 +93,7 @@ struct ethtool_link_settings {\n #endif\n \n /**\n- * Get interface name from private structure.\n+ * Get master interface name from private structure.\n  *\n  * @param[in] dev\n  *   Pointer to Ethernet device.\n@@ -104,7 +104,8 @@ struct ethtool_link_settings {\n  *   0 on success, a negative errno value otherwise and rte_errno is set.\n  */\n int\n-mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[IF_NAMESIZE])\n+mlx5_get_master_ifname(const struct rte_eth_dev *dev,\n+\t\t       char (*ifname)[IF_NAMESIZE])\n {\n \tstruct priv *priv = dev->data->dev_private;\n \tDIR *dir;\n@@ -179,6 +180,113 @@ mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[IF_NAMESIZE])\n }\n \n /**\n+ * Get interface name from private structure.\n+ *\n+ * This is a port representor-aware version of mlx5_get_master_ifname().\n+ *\n+ * @param[in] dev\n+ *   Pointer to Ethernet device.\n+ * @param[out] ifname\n+ *   Interface name output buffer.\n+ *\n+ * @return\n+ *   0 on success, a negative errno value otherwise and rte_errno is set.\n+ */\n+int\n+mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[IF_NAMESIZE])\n+{\n+\tstruct priv *priv = dev->data->dev_private;\n+\tint ret;\n+\tchar master[IF_NAMESIZE];\n+\tFILE *file;\n+\tDIR *dir;\n+\tuint64_t phys_switch_id;\n+\n+\tif (!priv->representor)\n+\t\treturn mlx5_get_master_ifname(dev, ifname);\n+\tret = mlx5_get_master_ifname(dev, &master);\n+\tif (ret)\n+\t\treturn ret;\n+\t{\n+\t\tMKSTR(path, \"%s/device/net/%s/phys_switch_id\",\n+\t\t      priv->ibdev_path, master);\n+\n+\t\tfile = fopen(path, \"rb\");\n+\t}\n+\tif (!file) {\n+\t\trte_errno = errno;\n+\t\treturn -rte_errno;\n+\t}\n+\tret = fscanf(file, \"%\" SCNx64, &phys_switch_id);\n+\tfclose(file);\n+\tif (ret != 1) {\n+\t\trte_errno = EINVAL;\n+\t\treturn -rte_errno;\n+\t}\n+\t{\n+\t\tMKSTR(path, \"%s/device/net/%s/subsystem\",\n+\t\t      priv->ibdev_path, master);\n+\n+\t\tdir = opendir(path);\n+\t}\n+\tif (!dir) {\n+\t\trte_errno = errno;\n+\t\treturn -rte_errno;\n+\t}\n+\t/*\n+\t * Scan network interfaces to find one with matching phys_switch_id\n+\t * and phys_switch_name.\n+\t */\n+\tdo {\n+\t\tstruct dirent *dent;\n+\t\tuint64_t phys_switch_id_rep;\n+\t\tint rep_id;\n+\n+\t\tret = -ENOENT;\n+\t\tdent = readdir(dir);\n+\t\tif (!dent)\n+\t\t\tbreak;\n+\t\t{\n+\t\t\tMKSTR(path,\n+\t\t\t      \"%s/device/net/%s/subsystem/%s/phys_switch_id\",\n+\t\t\t      priv->ibdev_path, master, dent->d_name);\n+\n+\t\t\tfile = fopen(path, \"rb\");\n+\t\t}\n+\t\tif (!file)\n+\t\t\tcontinue;\n+\t\tret = fscanf(file, \"%\" SCNx64, &phys_switch_id_rep);\n+\t\tfclose(file);\n+\t\tif (ret != 1)\n+\t\t\tcontinue;\n+\t\tif (phys_switch_id_rep != phys_switch_id)\n+\t\t\tcontinue;\n+\t\t{\n+\t\t\tMKSTR(path,\n+\t\t\t      \"%s/device/net/%s/subsystem/%s/phys_port_name\",\n+\t\t\t      priv->ibdev_path, master, dent->d_name);\n+\n+\t\t\tfile = fopen(path, \"rb\");\n+\t\t}\n+\t\tif (!file)\n+\t\t\tcontinue;\n+\t\tret = fscanf(file, \"%d\", &rep_id);\n+\t\tfclose(file);\n+\t\tif (ret != 1)\n+\t\t\tcontinue;\n+\t\tif (rep_id < 0 || (unsigned int)rep_id != priv->rep_id)\n+\t\t\tcontinue;\n+\t\tstrlcpy(*ifname, dent->d_name, sizeof(*ifname));\n+\t\tret = 0;\n+\t\tbreak;\n+\t} while (1);\n+\tclosedir(dir);\n+\tif (ret)\n+\t\trte_errno = -ret;\n+\treturn ret;\n+}\n+\n+/**\n  * Get the interface index from device name.\n  *\n  * @param[in] dev\n@@ -214,12 +322,16 @@ mlx5_ifindex(const struct rte_eth_dev *dev)\n  *   Request number to pass to ioctl().\n  * @param[out] ifr\n  *   Interface request structure output buffer.\n+ * @param master\n+ *   When device is a port representor, perform request on master device\n+ *   instead.\n  *\n  * @return\n  *   0 on success, a negative errno value otherwise and rte_errno is set.\n  */\n int\n-mlx5_ifreq(const struct rte_eth_dev *dev, int req, struct ifreq *ifr)\n+mlx5_ifreq(const struct rte_eth_dev *dev, int req, struct ifreq *ifr,\n+\t   int master)\n {\n \tint sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);\n \tint ret = 0;\n@@ -228,7 +340,10 @@ mlx5_ifreq(const struct rte_eth_dev *dev, int req, struct ifreq *ifr)\n \t\trte_errno = errno;\n \t\treturn -rte_errno;\n \t}\n-\tret = mlx5_get_ifname(dev, &ifr->ifr_name);\n+\tif (master)\n+\t\tret = mlx5_get_master_ifname(dev, &ifr->ifr_name);\n+\telse\n+\t\tret = mlx5_get_ifname(dev, &ifr->ifr_name);\n \tif (ret)\n \t\tgoto error;\n \tret = ioctl(sock, req, ifr);\n@@ -258,7 +373,7 @@ int\n mlx5_get_mtu(struct rte_eth_dev *dev, uint16_t *mtu)\n {\n \tstruct ifreq request;\n-\tint ret = mlx5_ifreq(dev, SIOCGIFMTU, &request);\n+\tint ret = mlx5_ifreq(dev, SIOCGIFMTU, &request, 0);\n \n \tif (ret)\n \t\treturn ret;\n@@ -282,7 +397,7 @@ mlx5_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)\n {\n \tstruct ifreq request = { .ifr_mtu = mtu, };\n \n-\treturn mlx5_ifreq(dev, SIOCSIFMTU, &request);\n+\treturn mlx5_ifreq(dev, SIOCSIFMTU, &request, 0);\n }\n \n /**\n@@ -302,13 +417,13 @@ int\n mlx5_set_flags(struct rte_eth_dev *dev, unsigned int keep, unsigned int flags)\n {\n \tstruct ifreq request;\n-\tint ret = mlx5_ifreq(dev, SIOCGIFFLAGS, &request);\n+\tint ret = mlx5_ifreq(dev, SIOCGIFFLAGS, &request, 0);\n \n \tif (ret)\n \t\treturn ret;\n \trequest.ifr_flags &= keep;\n \trequest.ifr_flags |= flags & ~keep;\n-\treturn mlx5_ifreq(dev, SIOCSIFFLAGS, &request);\n+\treturn mlx5_ifreq(dev, SIOCSIFFLAGS, &request, 0);\n }\n \n /**\n@@ -477,6 +592,12 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)\n \tinfo->speed_capa = priv->link_speed_capa;\n \tinfo->flow_type_rss_offloads = ~MLX5_RSS_HF_MASK;\n \tmlx5_set_default_params(dev, info);\n+\tif (rte_eth_dev_is_valid_port(priv->master_id)) {\n+\t\tinfo->switch_info.name =\n+\t\t\trte_eth_devices[priv->master_id].data->name;\n+\t\tinfo->switch_info.domain_id = priv->domain_id;\n+\t\tinfo->switch_info.port_id = priv->rep_id;\n+\t}\n }\n \n /**\n@@ -540,7 +661,7 @@ mlx5_link_update_unlocked_gset(struct rte_eth_dev *dev,\n \tint link_speed = 0;\n \tint ret;\n \n-\tret = mlx5_ifreq(dev, SIOCGIFFLAGS, &ifr);\n+\tret = mlx5_ifreq(dev, SIOCGIFFLAGS, &ifr, 1);\n \tif (ret) {\n \t\tDRV_LOG(WARNING, \"port %u ioctl(SIOCGIFFLAGS) failed: %s\",\n \t\t\tdev->data->port_id, strerror(rte_errno));\n@@ -550,7 +671,7 @@ mlx5_link_update_unlocked_gset(struct rte_eth_dev *dev,\n \tdev_link.link_status = ((ifr.ifr_flags & IFF_UP) &&\n \t\t\t\t(ifr.ifr_flags & IFF_RUNNING));\n \tifr.ifr_data = (void *)&edata;\n-\tret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);\n+\tret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr, 1);\n \tif (ret) {\n \t\tDRV_LOG(WARNING,\n \t\t\t\"port %u ioctl(SIOCETHTOOL, ETHTOOL_GSET) failed: %s\",\n@@ -611,7 +732,7 @@ mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev,\n \tuint64_t sc;\n \tint ret;\n \n-\tret = mlx5_ifreq(dev, SIOCGIFFLAGS, &ifr);\n+\tret = mlx5_ifreq(dev, SIOCGIFFLAGS, &ifr, 1);\n \tif (ret) {\n \t\tDRV_LOG(WARNING, \"port %u ioctl(SIOCGIFFLAGS) failed: %s\",\n \t\t\tdev->data->port_id, strerror(rte_errno));\n@@ -621,7 +742,7 @@ mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev,\n \tdev_link.link_status = ((ifr.ifr_flags & IFF_UP) &&\n \t\t\t\t(ifr.ifr_flags & IFF_RUNNING));\n \tifr.ifr_data = (void *)&gcmd;\n-\tret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);\n+\tret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr, 1);\n \tif (ret) {\n \t\tDRV_LOG(DEBUG,\n \t\t\t\"port %u ioctl(SIOCETHTOOL, ETHTOOL_GLINKSETTINGS)\"\n@@ -638,7 +759,7 @@ mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev,\n \n \t*ecmd = gcmd;\n \tifr.ifr_data = (void *)ecmd;\n-\tret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);\n+\tret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr, 1);\n \tif (ret) {\n \t\tDRV_LOG(DEBUG,\n \t\t\t\"port %u ioctl(SIOCETHTOOL, ETHTOOL_GLINKSETTINGS)\"\n@@ -801,7 +922,7 @@ mlx5_dev_get_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)\n \tint ret;\n \n \tifr.ifr_data = (void *)&ethpause;\n-\tret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);\n+\tret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr, 1);\n \tif (ret) {\n \t\tDRV_LOG(WARNING,\n \t\t\t\"port %u ioctl(SIOCETHTOOL, ETHTOOL_GPAUSEPARAM) failed:\"\n@@ -854,7 +975,7 @@ mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)\n \t\tethpause.tx_pause = 1;\n \telse\n \t\tethpause.tx_pause = 0;\n-\tret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);\n+\tret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr, 0);\n \tif (ret) {\n \t\tDRV_LOG(WARNING,\n \t\t\t\"port %u ioctl(SIOCETHTOOL, ETHTOOL_SPAUSEPARAM)\"\ndiff --git a/drivers/net/mlx5/mlx5_mac.c b/drivers/net/mlx5/mlx5_mac.c\nindex 672a47619..12ee37f55 100644\n--- a/drivers/net/mlx5/mlx5_mac.c\n+++ b/drivers/net/mlx5/mlx5_mac.c\n@@ -49,7 +49,7 @@ mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[ETHER_ADDR_LEN])\n \tstruct ifreq request;\n \tint ret;\n \n-\tret = mlx5_ifreq(dev, SIOCGIFHWADDR, &request);\n+\tret = mlx5_ifreq(dev, SIOCGIFHWADDR, &request, 0);\n \tif (ret)\n \t\treturn ret;\n \tmemcpy(mac, request.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);\ndiff --git a/drivers/net/mlx5/mlx5_stats.c b/drivers/net/mlx5/mlx5_stats.c\nindex 875dd1027..91f3d474a 100644\n--- a/drivers/net/mlx5/mlx5_stats.c\n+++ b/drivers/net/mlx5/mlx5_stats.c\n@@ -146,7 +146,7 @@ mlx5_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats)\n \tet_stats->cmd = ETHTOOL_GSTATS;\n \tet_stats->n_stats = xstats_ctrl->stats_n;\n \tifr.ifr_data = (caddr_t)et_stats;\n-\tret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);\n+\tret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr, 1);\n \tif (ret) {\n \t\tDRV_LOG(WARNING,\n \t\t\t\"port %u unable to read statistic values from device\",\n@@ -194,7 +194,7 @@ mlx5_ethtool_get_stats_n(struct rte_eth_dev *dev) {\n \n \tdrvinfo.cmd = ETHTOOL_GDRVINFO;\n \tifr.ifr_data = (caddr_t)&drvinfo;\n-\tret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);\n+\tret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr, 1);\n \tif (ret) {\n \t\tDRV_LOG(WARNING, \"port %u unable to query number of statistics\",\n \t\t\tdev->data->port_id);\n@@ -244,7 +244,7 @@ mlx5_xstats_init(struct rte_eth_dev *dev)\n \tstrings->string_set = ETH_SS_STATS;\n \tstrings->len = dev_stats_n;\n \tifr.ifr_data = (caddr_t)strings;\n-\tret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);\n+\tret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr, 1);\n \tif (ret) {\n \t\tDRV_LOG(WARNING, \"port %u unable to get statistic names\",\n \t\t\tdev->data->port_id);\n",
    "prefixes": [
        "v2",
        "6/7"
    ]
}