From patchwork Fri Jan 29 16:56:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parav Pandit X-Patchwork-Id: 373687 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B84D9C433DB for ; Fri, 29 Jan 2021 16:57:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7990464DFF for ; Fri, 29 Jan 2021 16:57:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231184AbhA2Q5y (ORCPT ); Fri, 29 Jan 2021 11:57:54 -0500 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:7917 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230388AbhA2Q5a (ORCPT ); Fri, 29 Jan 2021 11:57:30 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Fri, 29 Jan 2021 08:56:49 -0800 Received: from sw-mtx-036.mtx.labs.mlnx (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 29 Jan 2021 16:56:48 +0000 From: Parav Pandit To: , , CC: Parav Pandit Subject: [PATCH iproute2-next 1/5] devlink: Update kernel headers Date: Fri, 29 Jan 2021 18:56:04 +0200 Message-ID: <20210129165608.134965-2-parav@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210129165608.134965-1-parav@nvidia.com> References: <20210129165608.134965-1-parav@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1611939409; bh=AuH/Q3/waYP71Nw3G+7Q6GvDcq9qnn2Kg8lLFXk/Q8I=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=G5bynGXYEnL/EEaHebtMT80v8FRfcUfQnwLz/2MIjSCeO0d1sEInyrqDkH3jSg0Dv X1swYpOVo5yuq2w1lRcA9/zlJGmkC3TPS6C8uNbbRe420hXtzWvGHc2rucxyVRfIXn j8wxq6LVNz2NyUJM/1iW0MtC59YsZ9GjkxmnT1jKECmwD+kEARcKE9uFbEf1uq0R5a JdVbhmacEl3rBiJ9c/WcFGvhp3gYwUv+YAD3ElxtUdPYnZvTeQKkzthicpmO537RUv P0jgC1GzwPJtlF+6fz2SBLxnbiJ/DbxqhfoNnww4b4d8nZkOH5ngB1cckKa4pA/war LFtCdSVZR4Xwg== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Update kernel headers to commit a556dded9c23 ("devlink: Support get and set state of port function") Signed-off-by: Parav Pandit --- include/uapi/linux/devlink.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index 958ef7b9..a430775d 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -200,6 +200,10 @@ enum devlink_port_flavour { DEVLINK_PORT_FLAVOUR_UNUSED, /* Port which exists in the switch, but * is not used in any way. */ + DEVLINK_PORT_FLAVOUR_PCI_SF, /* Represents eswitch port + * for the PCI SF. It is an internal + * port that faces the PCI SF. + */ }; enum devlink_param_cmode { @@ -529,6 +533,7 @@ enum devlink_attr { DEVLINK_ATTR_RELOAD_ACTION_INFO, /* nested */ DEVLINK_ATTR_RELOAD_ACTION_STATS, /* nested */ + DEVLINK_ATTR_PORT_PCI_SF_NUMBER, /* u32 */ /* add new attributes above here, update the policy in devlink.c */ __DEVLINK_ATTR_MAX, @@ -578,9 +583,29 @@ enum devlink_resource_unit { enum devlink_port_function_attr { DEVLINK_PORT_FUNCTION_ATTR_UNSPEC, DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR, /* binary */ + DEVLINK_PORT_FN_ATTR_STATE, /* u8 */ + DEVLINK_PORT_FN_ATTR_OPSTATE, /* u8 */ __DEVLINK_PORT_FUNCTION_ATTR_MAX, DEVLINK_PORT_FUNCTION_ATTR_MAX = __DEVLINK_PORT_FUNCTION_ATTR_MAX - 1 }; +enum devlink_port_fn_state { + DEVLINK_PORT_FN_STATE_INACTIVE, + DEVLINK_PORT_FN_STATE_ACTIVE, +}; + +/** + * enum devlink_port_fn_opstate - indicates operational state of the function + * @DEVLINK_PORT_FN_OPSTATE_ATTACHED: Driver is attached to the function. + * For graceful tear down of the function, after inactivation of the + * function, user should wait for operational state to turn DETACHED. + * @DEVLINK_PORT_FN_OPSTATE_DETACHED: Driver is detached from the function. + * It is safe to delete the port. + */ +enum devlink_port_fn_opstate { + DEVLINK_PORT_FN_OPSTATE_DETACHED, + DEVLINK_PORT_FN_OPSTATE_ATTACHED, +}; + #endif /* _LINUX_DEVLINK_H_ */ From patchwork Fri Jan 29 16:56:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parav Pandit X-Patchwork-Id: 374009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB87CC433DB for ; Fri, 29 Jan 2021 16:58:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4FFA464DFF for ; Fri, 29 Jan 2021 16:58:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231585AbhA2Q6A (ORCPT ); Fri, 29 Jan 2021 11:58:00 -0500 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:19370 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231132AbhA2Q5a (ORCPT ); Fri, 29 Jan 2021 11:57:30 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Fri, 29 Jan 2021 08:56:50 -0800 Received: from sw-mtx-036.mtx.labs.mlnx (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 29 Jan 2021 16:56:49 +0000 From: Parav Pandit To: , , CC: Parav Pandit , Jiri Pirko Subject: [PATCH iproute2-next 2/5] devlink: Introduce PCI SF port flavour and attribute Date: Fri, 29 Jan 2021 18:56:05 +0200 Message-ID: <20210129165608.134965-3-parav@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210129165608.134965-1-parav@nvidia.com> References: <20210129165608.134965-1-parav@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1611939410; bh=YQIjfcjwbqmoFhFxgeDLpwLc53Eb3BlQdWa9PRmD5ZY=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=D/H1Di34iWYa/d031shLwOJV/45YosGb2xEpuF/wB/qmPLXwEonmYFQXFvGt9RzQi Bxwjh7DeA7qMm7rQMsDRfQrhZuduVcTjgi5PPq2vzNOmHPhODbcnWHfWtFLg3+QVLD aDij9qMo2KtVMn3qcUA+xu1hCU5+g9PUyi08mBTl2zqYYBDVv8d3Y9OYzDbnaf/kKc wpKp8d1Kfj2VzWMW5CuNQ7yX2QRYuQ8L4dGz3+h/hqP7y3vI5KieY/W9UmVeC5pccf Qkbn/SRRTHXXT24Rlbbd2gffaBbSVCPrQLs0rs08/oyzyVkYKmzHvC1xYFoaayiSft brpuwIG0r+g0g== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Introduce PCI SF port flavour and port attributes such as PF number and SF number. $ devlink dev eswitch set pci/0000:06:00.0 mode switchdev $ devlink port show pci/0000:06:00.0/65535: type eth netdev ens2f0np0 flavour physical port 0 splittable false $ devlink port add pci/0000:06:00.0 flavour pcisf pfnum 0 sfnum 88 pci/0000:08:00.0/32768: type eth netdev eth6 flavour pcisf controller 0 pfnum 0 sfnum 88 splittable false function: hw_addr 00:00:00:00:00:00 state inactive opstate detached $ devlink port show pci/0000:06:00.0/32768 pci/0000:06:00.0/32768: type eth netdev ens2f0npf0sf88 flavour pcisf controller 0 pfnum 0 sfnum 88 splittable false function: hw_addr 00:00:00:00:00:00 state inactive opstate detached $ devlink port function set pci/0000:06:00.0/32768 hw_addr 00:00:00:00:88:88 state active $ devlink port show pci/0000:06:00.0/32768 -jp { "port": { "pci/0000:06:00.0/32768": { "type": "eth", "netdev": "ens2f0npf0sf88", "flavour": "pcisf", "controller": 0, "pfnum": 0, "sfnum": 88, "splittable": false, "function": { "hw_addr": "00:00:00:00:88:88", "state": "active", "opstate": "attached" } } } } Signed-off-by: Parav Pandit Reviewed-by: Jiri Pirko --- devlink/devlink.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index a2e06644..ceafd179 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -3728,6 +3728,8 @@ static const char *port_flavour_name(uint16_t flavour) return "pcipf"; case DEVLINK_PORT_FLAVOUR_PCI_VF: return "pcivf"; + case DEVLINK_PORT_FLAVOUR_PCI_SF: + return "pcisf"; case DEVLINK_PORT_FLAVOUR_VIRTUAL: return "virtual"; default: @@ -3735,7 +3737,7 @@ static const char *port_flavour_name(uint16_t flavour) } } -static void pr_out_port_pfvf_num(struct dl *dl, struct nlattr **tb) +static void pr_out_port_pfvfsf_num(struct dl *dl, struct nlattr **tb) { uint16_t fn_num; @@ -3750,6 +3752,10 @@ static void pr_out_port_pfvf_num(struct dl *dl, struct nlattr **tb) fn_num = mnl_attr_get_u16(tb[DEVLINK_ATTR_PORT_PCI_VF_NUMBER]); print_uint(PRINT_ANY, "vfnum", " vfnum %u", fn_num); } + if (tb[DEVLINK_ATTR_PORT_PCI_SF_NUMBER]) { + fn_num = mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_PCI_SF_NUMBER]); + print_uint(PRINT_ANY, "sfnum", " sfnum %u", fn_num); + } if (tb[DEVLINK_ATTR_PORT_EXTERNAL]) { uint8_t external; @@ -3827,7 +3833,8 @@ static void pr_out_port(struct dl *dl, struct nlattr **tb) switch (port_flavour) { case DEVLINK_PORT_FLAVOUR_PCI_PF: case DEVLINK_PORT_FLAVOUR_PCI_VF: - pr_out_port_pfvf_num(dl, tb); + case DEVLINK_PORT_FLAVOUR_PCI_SF: + pr_out_port_pfvfsf_num(dl, tb); break; default: break; From patchwork Fri Jan 29 16:56:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parav Pandit X-Patchwork-Id: 373686 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4156BC433E6 for ; Fri, 29 Jan 2021 16:58:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F151D64DEB for ; Fri, 29 Jan 2021 16:58:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231603AbhA2Q6G (ORCPT ); Fri, 29 Jan 2021 11:58:06 -0500 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:7089 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231396AbhA2Q5b (ORCPT ); Fri, 29 Jan 2021 11:57:31 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Fri, 29 Jan 2021 08:56:50 -0800 Received: from sw-mtx-036.mtx.labs.mlnx (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 29 Jan 2021 16:56:49 +0000 From: Parav Pandit To: , , CC: Parav Pandit , Jiri Pirko Subject: [PATCH iproute2-next 3/5] devlink: Supporting add and delete of devlink port Date: Fri, 29 Jan 2021 18:56:06 +0200 Message-ID: <20210129165608.134965-4-parav@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210129165608.134965-1-parav@nvidia.com> References: <20210129165608.134965-1-parav@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1611939410; bh=AwR3naE4x4sJ+ex7mNMET55B0A5R8YYng16UADu3Sn8=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=EegzR05HA+dejlCQW7DAjbVAJY4Bd3D6kiRwCWaIGzutlttTlgx1unrRhvIZ+PM3a 37bFP/WFLLx9x16QR3s7qrCXwqL5TCUHmKNimUyNM1FJUtDaJlPwHxE7nYZvc7QPe1 8pAPx0m8xE93n7kZHK1hfXyAIyvs0qHVKVKyK8h6BSc+ijrvtX5l2i77lpjjBz74E7 XEtgYUbDoj2D+RtuYe5DCeqyQftgRv+9oEo1Qn+4JaKCrKPIUyk6ixwHBWO1Ixo55/ DbOvEj+Ey6XC5pz23/KbFle3cCsE3oNMo8X5C1ArPyc6xNBYVD3KYylTa0RZQS+LqF G7RSvQiJvi50A== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Enable user to add and delete the devlink port. Examples for adding and deleting one SF port: Examples of add, show and delete commands: $ devlink dev eswitch set pci/0000:06:00.0 mode switchdev $ devlink port show pci/0000:06:00.0/65535: type eth netdev ens2f0np0 flavour physical port 0 splittable false Add devlink port of flavour 'pcipf' for PF number 0 SF number 88: $ devlink port add pci/0000:06:00.0 flavour pcisf pfnum 0 sfnum 88 pci/0000:06:00.0/32768: type eth netdev eth6 flavour pcisf controller 0 pfnum 0 sfnum 88 splittable false function: hw_addr 00:00:00:00:00:00 state inactive opstate detached Delete newly added devlink port $ devlink port del pci/0000:06:00.0/32768 Signed-off-by: Parav Pandit Reviewed-by: Jiri Pirko --- devlink/devlink.c | 128 ++++++++++++++++++++++++++++++++++++++++ man/man8/devlink-port.8 | 63 ++++++++++++++++++++ 2 files changed, 191 insertions(+) diff --git a/devlink/devlink.c b/devlink/devlink.c index ceafd179..515dadc8 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -306,6 +306,9 @@ static void ifname_map_free(struct ifname_map *ifname_map) #define DL_OPT_FLASH_OVERWRITE BIT(39) #define DL_OPT_RELOAD_ACTION BIT(40) #define DL_OPT_RELOAD_LIMIT BIT(41) +#define DL_OPT_PORT_FLAVOUR BIT(42) +#define DL_OPT_PORT_PFNUMBER BIT(43) +#define DL_OPT_PORT_SFNUMBER BIT(44) struct dl_opts { uint64_t present; /* flags of present items */ @@ -356,6 +359,9 @@ struct dl_opts { uint32_t overwrite_mask; enum devlink_reload_action reload_action; enum devlink_reload_limit reload_limit; + uint32_t port_sfnumber; + uint16_t port_flavour; + uint16_t port_pfnumber; }; struct dl { @@ -1383,6 +1389,37 @@ static int reload_limit_get(struct dl *dl, const char *limitstr, return 0; } +static int port_flavour_parse(const char *flavour, uint16_t *value) +{ + if (!flavour) + return -EINVAL; + + if (strcmp(flavour, "physical") == 0) { + *value = DEVLINK_PORT_FLAVOUR_PHYSICAL; + return 0; + } else if (strcmp(flavour, "cpu") == 0) { + *value = DEVLINK_PORT_FLAVOUR_CPU; + return 0; + } else if (strcmp(flavour, "dsa") == 0) { + *value = DEVLINK_PORT_FLAVOUR_DSA; + return 0; + } else if (strcmp(flavour, "pcipf") == 0) { + *value = DEVLINK_PORT_FLAVOUR_PCI_PF; + return 0; + } else if (strcmp(flavour, "pcivf") == 0) { + *value = DEVLINK_PORT_FLAVOUR_PCI_VF; + return 0; + } else if (strcmp(flavour, "pcisf") == 0) { + *value = DEVLINK_PORT_FLAVOUR_PCI_SF; + return 0; + } else if (strcmp(flavour, "virtual") == 0) { + *value = DEVLINK_PORT_FLAVOUR_VIRTUAL; + return 0; + } else { + return -EINVAL; + } +} + struct dl_args_metadata { uint64_t o_flag; char err_msg[DL_ARGS_REQUIRED_MAX_ERR_LEN]; @@ -1414,6 +1451,8 @@ static const struct dl_args_metadata dl_args_required[] = { {DL_OPT_TRAP_NAME, "Trap's name is expected."}, {DL_OPT_TRAP_GROUP_NAME, "Trap group's name is expected."}, {DL_OPT_PORT_FUNCTION_HW_ADDR, "Port function's hardware address is expected."}, + {DL_OPT_PORT_FLAVOUR, "Port flavour is expected."}, + {DL_OPT_PORT_PFNUMBER, "Port PCI PF number is expected."}, }; static int dl_args_finding_required_validate(uint64_t o_required, @@ -1832,7 +1871,29 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required, if (err) return err; o_found |= DL_OPT_PORT_FUNCTION_HW_ADDR; + } else if (dl_argv_match(dl, "flavour") && (o_all & DL_OPT_PORT_FLAVOUR)) { + const char *flavourstr; + dl_arg_inc(dl); + err = dl_argv_str(dl, &flavourstr); + if (err) + return err; + err = port_flavour_parse(flavourstr, &opts->port_flavour); + if (err) + return err; + o_found |= DL_OPT_PORT_FLAVOUR; + } else if (dl_argv_match(dl, "pfnum") && (o_all & DL_OPT_PORT_PFNUMBER)) { + dl_arg_inc(dl); + err = dl_argv_uint16_t(dl, &opts->port_pfnumber); + if (err) + return err; + o_found |= DL_OPT_PORT_PFNUMBER; + } else if (dl_argv_match(dl, "sfnum") && (o_all & DL_OPT_PORT_SFNUMBER)) { + dl_arg_inc(dl); + err = dl_argv_uint32_t(dl, &opts->port_sfnumber); + if (err) + return err; + o_found |= DL_OPT_PORT_SFNUMBER; } else { pr_err("Unknown option \"%s\"\n", dl_argv(dl)); return -EINVAL; @@ -2015,6 +2076,12 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl) opts->trap_policer_burst); if (opts->present & DL_OPT_PORT_FUNCTION_HW_ADDR) dl_function_attr_put(nlh, opts); + if (opts->present & DL_OPT_PORT_FLAVOUR) + mnl_attr_put_u16(nlh, DEVLINK_ATTR_PORT_FLAVOUR, opts->port_flavour); + if (opts->present & DL_OPT_PORT_PFNUMBER) + mnl_attr_put_u16(nlh, DEVLINK_ATTR_PORT_PCI_PF_NUMBER, opts->port_pfnumber); + if (opts->present & DL_OPT_PORT_SFNUMBER) + mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_PCI_SF_NUMBER, opts->port_sfnumber); } static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl, @@ -3702,6 +3769,8 @@ static void cmd_port_help(void) pr_err(" devlink port unsplit DEV/PORT_INDEX\n"); pr_err(" devlink port function set DEV/PORT_INDEX [ hw_addr ADDR ]\n"); pr_err(" devlink port health show [ DEV/PORT_INDEX reporter REPORTER_NAME ]\n"); + pr_err(" devlink port add DEV/PORT_INDEX flavour FLAVOUR [ controller CNUM ] pfnum PFNUM [ sfnum SFNUM ]\n"); + pr_err(" devlink port del DEV/PORT_INDEX\n"); } static const char *port_type_name(uint32_t type) @@ -3977,6 +4046,58 @@ static int cmd_port_function(struct dl *dl) static int cmd_health(struct dl *dl); static int __cmd_health_show(struct dl *dl, bool show_device, bool show_port); +static void cmd_port_add_help(void) +{ + pr_err(" devlink port add { DEV | DEV/PORT_INDEX } flavour FLAVOUR pfnum PFNUM [ sfnum SFNUM ]\n"); +} + +static int cmd_port_add(struct dl *dl) +{ + struct nlmsghdr *nlh; + int err; + + if (dl_argv_match(dl, "help") || dl_no_arg(dl)) { + cmd_port_add_help(); + return 0; + } + + nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_NEW, + NLM_F_REQUEST | NLM_F_ACK); + + err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE | DL_OPT_HANDLEP | + DL_OPT_PORT_FLAVOUR | DL_OPT_PORT_PFNUMBER, + DL_OPT_PORT_SFNUMBER); + if (err) + return err; + + return _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_port_show_cb, dl); +} + +static void cmd_port_del_help(void) +{ + pr_err(" devlink port del DEV/PORT_INDEX\n"); +} + +static int cmd_port_del(struct dl *dl) +{ + struct nlmsghdr *nlh; + int err; + + if (dl_argv_match(dl, "help") || dl_no_arg(dl)) { + cmd_port_del_help(); + return 0; + } + + nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_DEL, + NLM_F_REQUEST | NLM_F_ACK); + + err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP, 0); + if (err) + return err; + + return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL); +} + static int cmd_port(struct dl *dl) { if (dl_argv_match(dl, "help")) { @@ -4007,7 +4128,14 @@ static int cmd_port(struct dl *dl) } else { return cmd_health(dl); } + } else if (dl_argv_match(dl, "add")) { + dl_arg_inc(dl); + return cmd_port_add(dl); + } else if (dl_argv_match(dl, "del")) { + dl_arg_inc(dl); + return cmd_port_del(dl); } + pr_err("Command \"%s\" not found\n", dl_argv(dl)); return -ENOENT; } diff --git a/man/man8/devlink-port.8 b/man/man8/devlink-port.8 index 966faae6..4a1d3800 100644 --- a/man/man8/devlink-port.8 +++ b/man/man8/devlink-port.8 @@ -43,6 +43,23 @@ devlink-port \- devlink port configuration .B devlink port health .RI "{ " show " | " recover " | " diagnose " | " dump " | " set " }" +.ti -8 +.BI "devlink port add" +.RB "[" +.IR "DEV | DEV/PORT_INDEX" +.RB "] " +.RB "[ " flavour +.IR FLAVOUR " ]" +.RB "[ " pcipf +.IR PFNUMBER " ]" +.RB "{ " pcisf +.IR SFNUMBER " }" +.br + +.ti -8 +.B devlink port del +.IR DEV/PORT_INDEX + .ti -8 .B devlink port help @@ -99,6 +116,42 @@ If this argument is omitted all ports are listed. Is an alias for .BR devlink-health (8). +.ti -8 +.SS devlink port add - add a devlink port +.PP +.B "DEV" +- specifies the devlink device to operate on. or + +.PP +.B "DEV/PORT_INDEX" +- specifies the devlink port index to use for the requested new port. +This is optional. When ommited, driver allocates unique port index. + +.TP +.BR flavour " { " pcipf " | " pcisf " } " +set port flavour + +.I pcipf +- PCI PF port + +.I pcisf +- PCI SF port + +.TP +.BR pfnum " { " pfnumber " } " +Specifies PCI pfnumber to use on which a SF device to create + +.TP +.BR sfnum " { " sfnumber " } " +Specifies sfnumber to assign to the device of the SF. +This field is optional for those devices which supports auto assignment of the SF number. + +.ti -8 +.SS devlink port del - delete a devlink port +.PP +.B "DEV/PORT_INDEX" +- specifies the devlink port to delete. + .SH "EXAMPLES" .PP devlink port show @@ -135,6 +188,16 @@ devlink port health show pci/0000:01:00.0/1 reporter tx .RS 4 Shows status and configuration of tx reporter registered on pci/0000:01:00.0/1 devlink port. .RE +.PP +devlink port add pci/0000:06:00.0 flavour pcisf pfnum 0 sfnum 88 +.RS 4 +Add a devlink port of flavour PCI SF on PCI PF having number 0 with SF number 88. +.RE +.PP +devlink port del pci/0000:06:00.0/1 +.RS 4 +Delete previously created devlink port. +.RE .SH SEE ALSO .BR devlink (8), From patchwork Fri Jan 29 16:56:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parav Pandit X-Patchwork-Id: 374008 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A5F2C433E0 for ; Fri, 29 Jan 2021 16:58:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 25C6264DEB for ; Fri, 29 Jan 2021 16:58:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231643AbhA2Q6I (ORCPT ); Fri, 29 Jan 2021 11:58:08 -0500 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:7923 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230389AbhA2Q5b (ORCPT ); Fri, 29 Jan 2021 11:57:31 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Fri, 29 Jan 2021 08:56:51 -0800 Received: from sw-mtx-036.mtx.labs.mlnx (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 29 Jan 2021 16:56:50 +0000 From: Parav Pandit To: , , CC: Parav Pandit , Jiri Pirko Subject: [PATCH iproute2-next 4/5] devlink: Support get port function state Date: Fri, 29 Jan 2021 18:56:07 +0200 Message-ID: <20210129165608.134965-5-parav@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210129165608.134965-1-parav@nvidia.com> References: <20210129165608.134965-1-parav@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1611939411; bh=tUtPGk8jRz74ATIdOu3RFyrGGheiaPs5Dibv7fjAh54=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=nxtiF38EbUJmwqQ/yBKb0cIs5PWzyUwcQWu4H5a0l+E7oJLpDXY+aJTOlnPFNTEnS npOCDbwBX/x3rzjwCM5OlvlQ7ScRVqS8Ko9m2035DsmLkRO7BSdT7ozdtdcOzh39Q1 QXNt2Gl+L/IXFEMNoQj8i8V1L9soYcgCn9c4nOduV63vn5bQrtuztRWJX4rN4Pajal hWPIrn9NEz8ZuYChI71bF+xUXTlLf4ZQLmm8kefkzkSBt2xdMFGLiOQuyOZA3PcAbL JLNPyX5JJgtbVaf8DufjBpehQIxKO8HyHJzBCpzQuLqMJXmmP0sh2jFD2gcLXcBYvn 3w1uV35IWTEKQ== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Print port function state and operational state whenever reported by kernel. Example of a PCI SF port function which supports the state: $ devlink dev eswitch set pci/0000:06:00.0 mode switchdev $ devlink port show pci/0000:06:00.0/65535: type eth netdev ens2f0np0 flavour physical port 0 splittable false $ devlink port add pci/0000:06:00.0 flavour pcisf pfnum 0 sfnum 88 pci/0000:08:00.0/32768: type eth netdev eth6 flavour pcisf controller 0 pfnum 0 sfnum 88 splittable false function: hw_addr 00:00:00:00:00:00 state inactive opstate detached $ devlink port show pci/0000:06:00.0/32768 pci/0000:06:00.0/32768: type eth netdev ens2f0npf0sf88 flavour pcisf controller 0 pfnum 0 sfnum 88 splittable false function: hw_addr 00:00:00:00:00:00 state inactive opstate detached $ devlink port function set pci/0000:06:00.0/32768 hw_addr 00:00:00:00:88:88 $ devlink port show pci/0000:06:00.0/32768 -jp { "port": { "pci/0000:06:00.0/32768": { "type": "eth", "netdev": "ens2f0npf0sf88", "flavour": "pcisf", "controller": 0, "pfnum": 0, "sfnum": 88, "splittable": false, "function": { "hw_addr": "00:00:00:00:88:88", "state": "inactive", "opstate": "detached" } } } } Signed-off-by: Parav Pandit Reviewed-by: Jiri Pirko --- devlink/devlink.c | 55 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index 515dadc8..85b9bce9 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -3833,6 +3833,30 @@ static void pr_out_port_pfvfsf_num(struct dl *dl, struct nlattr **tb) } } +static const char *port_function_state(uint8_t state) +{ + switch (state) { + case DEVLINK_PORT_FN_STATE_INACTIVE: + return "inactive"; + case DEVLINK_PORT_FN_STATE_ACTIVE: + return "active"; + default: + return "unknown"; + } +} + +static const char *port_function_opstate(uint8_t state) +{ + switch (state) { + case DEVLINK_PORT_FN_OPSTATE_DETACHED: + return "detached"; + case DEVLINK_PORT_FN_OPSTATE_ATTACHED: + return "attached"; + default: + return "unknown"; + } +} + static void pr_out_port_function(struct dl *dl, struct nlattr **tb_port) { struct nlattr *tb[DEVLINK_PORT_FUNCTION_ATTR_MAX + 1] = {}; @@ -3849,16 +3873,31 @@ static void pr_out_port_function(struct dl *dl, struct nlattr **tb_port) if (err != MNL_CB_OK) return; - if (!tb[DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR]) - return; - - len = mnl_attr_get_payload_len(tb[DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR]); - data = mnl_attr_get_payload(tb[DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR]); - pr_out_object_start(dl, "function"); check_indent_newline(dl); - print_string(PRINT_ANY, "hw_addr", "hw_addr %s", - ll_addr_n2a(data, len, 0, hw_addr, sizeof(hw_addr))); + + if (tb[DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR]) { + len = mnl_attr_get_payload_len(tb[DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR]); + data = mnl_attr_get_payload(tb[DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR]); + + print_string(PRINT_ANY, "hw_addr", "hw_addr %s", + ll_addr_n2a(data, len, 0, hw_addr, sizeof(hw_addr))); + } + if (tb[DEVLINK_PORT_FN_ATTR_STATE]) { + uint8_t state; + + state = mnl_attr_get_u8(tb[DEVLINK_PORT_FN_ATTR_STATE]); + + print_string(PRINT_ANY, "state", " state %s", port_function_state(state)); + } + if (tb[DEVLINK_PORT_FN_ATTR_OPSTATE]) { + uint8_t state; + + state = mnl_attr_get_u8(tb[DEVLINK_PORT_FN_ATTR_OPSTATE]); + + print_string(PRINT_ANY, "opstate", " opstate %s", port_function_opstate(state)); + } + if (!dl->json_output) __pr_out_indent_dec(); pr_out_object_end(dl); From patchwork Fri Jan 29 16:56:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parav Pandit X-Patchwork-Id: 373685 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDEAEC433DB for ; Fri, 29 Jan 2021 16:58:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7002164DEB for ; Fri, 29 Jan 2021 16:58:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231691AbhA2Q6K (ORCPT ); Fri, 29 Jan 2021 11:58:10 -0500 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:7925 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231482AbhA2Q5c (ORCPT ); Fri, 29 Jan 2021 11:57:32 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Fri, 29 Jan 2021 08:56:51 -0800 Received: from sw-mtx-036.mtx.labs.mlnx (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 29 Jan 2021 16:56:51 +0000 From: Parav Pandit To: , , CC: Parav Pandit , Jiri Pirko Subject: [PATCH iproute2-next 5/5] devlink: Support set of port function state Date: Fri, 29 Jan 2021 18:56:08 +0200 Message-ID: <20210129165608.134965-6-parav@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210129165608.134965-1-parav@nvidia.com> References: <20210129165608.134965-1-parav@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1611939411; bh=vdRxMoWfot/LGe8p7aAL1Z+UaGnNZRBUh1OqdO7Aogw=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:Content-Type: X-Originating-IP:X-ClientProxiedBy; b=QxgSFVm9tW5iWtVn/5ha//07VKvV1HACgEMwfk2UW6oR+emqroWl2qQcFx4CNUfo9 SDnnyqlgXxApkVpQANx0L1Ss99sAAOc3ocoD486jHU9+UIsRgDJwYqPvQMA12VbeHO cMNx7ZQhU0elUWqxmZEG66hr6HLPXT+n+wqgwPuhxXXeKvhtS5Z3W7ookQwNDBRiEe sKRVg+TYMz+N2AuR9zwN3Ne5f2+ity5SSGpOYCTVe0mkZzETkoeNf6P4apaNDw85vv +rEAkH/9gqBALFP/5Ql2tXfva6NxxKIo86n9ta4j5PnaB/9BZ4Am3QXJiK4DWRyluE QDkrXL2joE0nw== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Support set operation of the devlink port function state. Example of a PCI SF port function which supports the state: $ devlink dev eswitch set pci/0000:06:00.0 mode switchdev $ devlink port show pci/0000:06:00.0/65535: type eth netdev ens2f0np0 flavour physical port 0 splittable false $ devlink port add pci/0000:06:00.0 flavour pcisf pfnum 0 sfnum 88 pci/0000:08:00.0/32768: type eth netdev eth6 flavour pcisf controller 0 pfnum 0 sfnum 88 splittable false function: hw_addr 00:00:00:00:00:00 state inactive opstate detached $ devlink port show pci/0000:06:00.0/32768 pci/0000:06:00.0/32768: type eth netdev ens2f0npf0sf88 flavour pcisf controller 0 pfnum 0 sfnum 88 splittable false function: hw_addr 00:00:00:00:00:00 state inactive opstate detached $ devlink port function set pci/0000:06:00.0/32768 hw_addr 00:00:00:00:88:88 state active $ devlink port show pci/0000:06:00.0/32768 -jp { "port": { "pci/0000:06:00.0/32768": { "type": "eth", "netdev": "ens2f0npf0sf88", "flavour": "pcisf", "controller": 0, "pfnum": 0, "sfnum": 88, "splittable": false, "function": { "hw_addr": "00:00:00:00:88:88", "state": "active", "opstate": "attached" } } } } Signed-off-by: Parav Pandit Reviewed-by: Jiri Pirko --- devlink/devlink.c | 57 +++++++++++++++++++++++++++++----- man/man8/devlink-port.8 | 68 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 115 insertions(+), 10 deletions(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index 85b9bce9..d233dcdd 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -309,6 +309,7 @@ static void ifname_map_free(struct ifname_map *ifname_map) #define DL_OPT_PORT_FLAVOUR BIT(42) #define DL_OPT_PORT_PFNUMBER BIT(43) #define DL_OPT_PORT_SFNUMBER BIT(44) +#define DL_OPT_PORT_FUNCTION_STATE BIT(45) struct dl_opts { uint64_t present; /* flags of present items */ @@ -362,6 +363,7 @@ struct dl_opts { uint32_t port_sfnumber; uint16_t port_flavour; uint16_t port_pfnumber; + uint8_t port_function_state; }; struct dl { @@ -747,6 +749,7 @@ static int attr_stats_cb(const struct nlattr *attr, void *data) static const enum mnl_attr_data_type devlink_function_policy[DEVLINK_PORT_FUNCTION_ATTR_MAX + 1] = { [DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR ] = MNL_TYPE_BINARY, + [DEVLINK_PORT_FN_ATTR_STATE] = MNL_TYPE_U8, }; static int function_attr_cb(const struct nlattr *attr, void *data) @@ -1420,6 +1423,22 @@ static int port_flavour_parse(const char *flavour, uint16_t *value) } } +static int port_function_state_parse(const char *statestr, uint8_t *state) +{ + if (!statestr) + return -EINVAL; + + if (strcmp(statestr, "inactive") == 0) { + *state = DEVLINK_PORT_FN_STATE_INACTIVE; + return 0; + } else if (strcmp(statestr, "active") == 0) { + *state = DEVLINK_PORT_FN_STATE_ACTIVE; + return 0; + } else { + return -EINVAL; + } +} + struct dl_args_metadata { uint64_t o_flag; char err_msg[DL_ARGS_REQUIRED_MAX_ERR_LEN]; @@ -1871,6 +1890,19 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required, if (err) return err; o_found |= DL_OPT_PORT_FUNCTION_HW_ADDR; + } else if (dl_argv_match(dl, "state") && + (o_all & DL_OPT_PORT_FUNCTION_STATE)) { + const char *statestr; + + dl_arg_inc(dl); + err = dl_argv_str(dl, &statestr); + if (err) + return err; + err = port_function_state_parse(statestr, &opts->port_function_state); + if (err) + return err; + + o_found |= DL_OPT_PORT_FUNCTION_STATE; } else if (dl_argv_match(dl, "flavour") && (o_all & DL_OPT_PORT_FLAVOUR)) { const char *flavourstr; @@ -1916,9 +1948,14 @@ dl_function_attr_put(struct nlmsghdr *nlh, const struct dl_opts *opts) struct nlattr *nest; nest = mnl_attr_nest_start(nlh, DEVLINK_ATTR_PORT_FUNCTION); - mnl_attr_put(nlh, DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR, - opts->port_function_hw_addr_len, - opts->port_function_hw_addr); + + if (opts->present & DL_OPT_PORT_FUNCTION_HW_ADDR) + mnl_attr_put(nlh, DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR, + opts->port_function_hw_addr_len, + opts->port_function_hw_addr); + if (opts->present & DL_OPT_PORT_FUNCTION_STATE) + mnl_attr_put_u8(nlh, DEVLINK_PORT_FN_ATTR_STATE, + opts->port_function_state); mnl_attr_nest_end(nlh, nest); } @@ -2074,7 +2111,7 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl) if (opts->present & DL_OPT_TRAP_POLICER_BURST) mnl_attr_put_u64(nlh, DEVLINK_ATTR_TRAP_POLICER_BURST, opts->trap_policer_burst); - if (opts->present & DL_OPT_PORT_FUNCTION_HW_ADDR) + if (opts->present & (DL_OPT_PORT_FUNCTION_HW_ADDR | DL_OPT_PORT_FUNCTION_STATE)) dl_function_attr_put(nlh, opts); if (opts->present & DL_OPT_PORT_FLAVOUR) mnl_attr_put_u16(nlh, DEVLINK_ATTR_PORT_FLAVOUR, opts->port_flavour); @@ -3767,7 +3804,7 @@ static void cmd_port_help(void) pr_err(" devlink port set DEV/PORT_INDEX [ type { eth | ib | auto} ]\n"); pr_err(" devlink port split DEV/PORT_INDEX count COUNT\n"); pr_err(" devlink port unsplit DEV/PORT_INDEX\n"); - pr_err(" devlink port function set DEV/PORT_INDEX [ hw_addr ADDR ]\n"); + pr_err(" devlink port function set DEV/PORT_INDEX [ hw_addr ADDR ] [ state STATE ]\n"); pr_err(" devlink port health show [ DEV/PORT_INDEX reporter REPORTER_NAME ]\n"); pr_err(" devlink port add DEV/PORT_INDEX flavour FLAVOUR [ controller CNUM ] pfnum PFNUM [ sfnum SFNUM ]\n"); pr_err(" devlink port del DEV/PORT_INDEX\n"); @@ -3897,7 +3934,6 @@ static void pr_out_port_function(struct dl *dl, struct nlattr **tb_port) print_string(PRINT_ANY, "opstate", " opstate %s", port_function_opstate(state)); } - if (!dl->json_output) __pr_out_indent_dec(); pr_out_object_end(dl); @@ -4052,7 +4088,7 @@ static int cmd_port_unsplit(struct dl *dl) static void cmd_port_function_help(void) { - pr_err("Usage: devlink port function set DEV/PORT_INDEX [ hw_addr ADDR ]\n"); + pr_err("Usage: devlink port function set DEV/PORT_INDEX [ hw_addr ADDR ] [ state STATE ]\n"); } static int cmd_port_function_set(struct dl *dl) @@ -4060,9 +4096,14 @@ static int cmd_port_function_set(struct dl *dl) struct nlmsghdr *nlh; int err; + if (dl_no_arg(dl)) { + cmd_port_function_help(); + return 0; + } nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PORT_SET, NLM_F_REQUEST | NLM_F_ACK); - err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | DL_OPT_PORT_FUNCTION_HW_ADDR, 0); + err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP, + DL_OPT_PORT_FUNCTION_HW_ADDR | DL_OPT_PORT_FUNCTION_STATE); if (err) return err; diff --git a/man/man8/devlink-port.8 b/man/man8/devlink-port.8 index 4a1d3800..55f1cce6 100644 --- a/man/man8/devlink-port.8 +++ b/man/man8/devlink-port.8 @@ -60,6 +60,16 @@ devlink-port \- devlink port configuration .B devlink port del .IR DEV/PORT_INDEX +.ti -8 +.BR "devlink port function set " +.IR DEV/PORT_INDEX +.RI "{ " +.BR "hw_addr " +.RI "ADDR }" +.RI "{ " +.BR "state" +.RI "STATE }" + .ti -8 .B devlink port help @@ -144,7 +154,30 @@ Specifies PCI pfnumber to use on which a SF device to create .TP .BR sfnum " { " sfnumber " } " Specifies sfnumber to assign to the device of the SF. -This field is optional for those devices which supports auto assignment of the SF number. +This field is optional for those devices which supports auto assignment of the +SF number. + +.ti -8 +.SS devlink port function set - Set the port function attribute(s). + +.PP +.B "DEV/PORT_INDEX" +- specifies the devlink port to operate on. + +.TP +.BR hw_addr " ADDR" +- hardware address of the function to set. This is a Ethernet MAC address when +port type is Ethernet. + +.TP +.BR state " { " active " | " inactive " } " +- new state of the function to change to. + +.I active +- Once configuration of the function is done, activate the function. + +.I inactive +- To inactivate the function and its device(s), set to inactive. .ti -8 .SS devlink port del - delete a devlink port @@ -192,11 +225,42 @@ Shows status and configuration of tx reporter registered on pci/0000:01:00.0/1 d devlink port add pci/0000:06:00.0 flavour pcisf pfnum 0 sfnum 88 .RS 4 Add a devlink port of flavour PCI SF on PCI PF having number 0 with SF number 88. +To make use of the function an example sequence is to add a port, configure the +function attribute and activate the function. Once function usage is completed, +inactivate the function and finally delete the port. When there is desire to +reuse the port without deletion, it can be reconfigured and activated again when +function is in inactive state and function's operational state is detached. .RE .PP devlink port del pci/0000:06:00.0/1 .RS 4 -Delete previously created devlink port. +Delete previously created devlink port. It is recommended to first deactivate +the function if the function supports state management. +.RE +.PP +devlink port function set pci/0000:01:00.0/1 hw_addr 00:00:00:11:22:33 +.RS 4 +Configure hardware address of the PCI function represented by devlink port. +If the port supports change in function state, hardware address must be configured +before activating the function. +.RE +.PP +devlink port function set pci/0000:01:00.0/1 state active +.RS 4 +Activate the function. This will initiate the function enumeration and driver loading. +.RE +.PP +devlink port function set pci/0000:01:00.0/1 state inactive +.RS 4 +Deactivate the function. This will initiate the function teardown which results +in driver unload and device removal. +.RE +.PP +devlink port function set pci/0000:01:00.0/1 hw_addr 00:00:00:11:22:33 state active +.RS 4 +Configure hardware address and also active the function. When a function is +activated together with other configuration in a single command, all the +configuration is applied first before changing the state to active. .RE .SH SEE ALSO