Adding permanent config get/set to devlink
v4 cover Adding permanent config get/set to devlink
Changes since v3:
* Using union instead of void * to pass parameter values to/from drivers.
* Updated parameter comments / naming and added enum for enable/disable to add clarity.
* Various code cleanup in bnxt:
- change hwrm call to use mutex protected version
- use roundup() macro
- remove unnecessary error messages
- change mechanism to check for parameter-not-found
- cleanup merge w/ switchdev eswitch devlink functions
- rebased with Michael Chan's recent bnxt changes in net-next.
Suggested changes not implemented:
* re: val8 = val32 "Don't you need explicit castings for these kind of assignments to prevent warnings?" -- No, I don't think explicit castings are necessary here; I don't get any compiler warnings (w/ gcc 5.4.0)
PATCH v4 1/10 devlink: Add permanent config parameter get/set operations
Add support for permanent config parameter get/set commands. Used for persistent device configuration parameters.
--- include/net/devlink.h | 7 ++ include/uapi/linux/devlink.h | 25 ++++ net/core/devlink.c | 287 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 319 insertions(+)
include/net/devlink.h +7 -0
@@ -270,6 +270,13 @@ struct devlink_ops {int (*eswitch_inline_mode_set)(struct devlink *devlink,u8 inline_mode);int (*eswitch_encap_mode_get)(struct devlink *devlink,u8 *p_encap_mode);int (*eswitch_encap_mode_set)(struct devlink *devlink,u8 encap_mode); +int (*perm_config_get)(struct devlink *devlink, +enum devlink_perm_config_param param,u8 type, +union devlink_perm_config_value *value); +int (*perm_config_set)(struct devlink *devlink, +enum devlink_perm_config_param param,u8 type, +union devlink_perm_config_value *value, +u8 *restart_reqd); };static inline void *devlink_priv (struct devlink *devlink)
include/uapi/linux/devlink.h +25 -0
@@ -70,6 +70,10 @@ enum devlink_command {DEVLINK_CMD_DPIPE_HEADERS_GET ,DEVLINK_CMD_DPIPE_TABLE_COUNTERS_SET , +/* Permanent device config get/set */ +DEVLINK_CMD_PERM_CONFIG_GET , +DEVLINK_CMD_PERM_CONFIG_SET , +/* add new commands above here */ __DEVLINK_CMD_MAX,DEVLINK_CMD_MAX = __DEVLINK_CMD_MAX -1
@@ -202,6 +206,14 @@ enum devlink_attr {DEVLINK_ATTR_ESWITCH_ENCAP_MODE ,/* u8 */ +/* Permanent Configuration Parameters */ +DEVLINK_ATTR_PERM_CONFIGS ,/* nested */ +DEVLINK_ATTR_PERM_CONFIG ,/* nested */ +DEVLINK_ATTR_PERM_CONFIG_PARAMETER ,/* u32 */ +DEVLINK_ATTR_PERM_CONFIG_TYPE ,/* u8 */ +DEVLINK_ATTR_PERM_CONFIG_VALUE ,/* dynamic */ +DEVLINK_ATTR_PERM_CONFIG_RESTART_REQUIRED ,/* u8 */ +/* add new attributes above here, update the policy in devlink.c */ __DEVLINK_ATTR_MAX,
@@ -244,4 +256,17 @@ enum devlink_dpipe_header_id { DEVLINK_DPIPE_HEADER_IPV6, }; +/* Permanent config parameters */ +enum devlink_perm_config_param { + __DEVLINK_PERM_CONFIG_MAX, +DEVLINK_PERM_CONFIG_MAX = __DEVLINK_PERM_CONFIG_MAX -1 +}; + +/* Permanent config value */ +union devlink_perm_config_value { +__u8 value8; +__u16 value16; +__u32 value32; +}; +#endif /* _UAPI_LINUX_DEVLINK_H_ */
net/core/devlink.c +287 -0
305 lines not on this page · raw message
Signature · 1 line
2.7.4
Jiri Pirko
maintainerRe: [PATCH net-next v4 01/10] devlink: Add permanent config parameter get/set operations
Quoted 16 lines · Fri, Oct 27, 2017 at 10:54:05PM CEST, [email protected] wrote:
Add support for permanent config parameter get/set commands. Used for persistent device configuration parameters.
Signed-off-by Steve Lin <[email protected]>Acked-by Andy Gospodarek <[email protected]>---
include/net/devlink.h | 7 ++ include/uapi/linux/devlink.h | 25 ++++ net/core/devlink.c | 287 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 319 insertions(+)include/net/devlink.h +0
-0
include/net/devlink.h struct devlink_ops { · line 279
Quoted 10 lines
include/net/devlink.h +7
-0@@ -270,6 +270,13 @@ struct devlink_ops {int (*eswitch_inline_mode_set)(struct devlink *devlink,u8 inline_mode);int (*eswitch_encap_mode_get)(struct devlink *devlink,u8 *p_encap_mode);int (*eswitch_encap_mode_set)(struct devlink *devlink,u8 encap_mode); +int (*perm_config_get)(struct devlink *devlink, +enum devlink_perm_config_param param,u8 type, +union devlink_perm_config_value *value); +int (*perm_config_set)(struct devlink *devlink, +enum devlink_perm_config_param param,u8 type, +union devlink_perm_config_value *value, +u8 *restart_reqd);
type should be enum and restart_reqd should be bool.
[...]
Quoted 10 lines
include/net/devlink.h +10
-0+static int devlink_nl_single_param_set (struct sk_buff *msg, +struct devlink *devlink, +u32 param,u8 type, +union devlink_perm_config_value *value) +{ +const struct devlink_ops *ops = devlink->ops; +struct nlattr *cfgparam_attr; +u8 need_restart; +int err; +
include/net/devlink.h struct devlink_ops {
Quoted 10 lines
include/net/devlink.h +10
-0+/* Now set parameter */ + err = ops->perm_config_set (devlink, param, type, value, &need_restart); +if (err) +return err; + + cfgparam_attr =nla_nest_start (msg,DEVLINK_ATTR_PERM_CONFIG ); +/* Update restart reqd - if any param needs restart, should be set */ +if (need_restart) { + err =nla_put_u8 (msg, +DEVLINK_ATTR_PERM_CONFIG_RESTART_REQUIRED ,1 );
Why don't you just put this flag always? Otherwise it could be NLA_FLAG
Quoted 4 lines
include/net/devlink.h +4
-0+if (err) + goto nest_fail; + } +
Re: [PATCH net-next v4 01/10] devlink: Add permanent config parameter get/set operations
Quoted 21 lines · Jiri Pirko
Quoted 20 lines · Fri, Oct 27, 2017 at 10:54:05PM CEST, [email protected] wrote:
Add support for permanent config parameter get/set commands. Used for persistent device configuration parameters.
Signed-off-by Steve Lin <[email protected]>Acked-by Andy Gospodarek <[email protected]>---
include/net/devlink.h | 7 ++ include/uapi/linux/devlink.h | 25 ++++ net/core/devlink.c | 287 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 319 insertions(+)include/net/devlink.h +1
-0@@ -270,6 +270,13 @@ struct devlink_ops {int (*eswitch_inline_mode_set)(struct devlink *devlink,u8 inline_mode);int (*eswitch_encap_mode_get)(struct devlink *devlink,u8 *p_encap_mode);int (*eswitch_encap_mode_set)(struct devlink *devlink,u8 encap_mode); + int (*perm_config_get)(struct devlink *devlink,
Quoted 8 lines
include/net/devlink.h struct devlink_ops { · line 279
Quoted 6 lines
include/net/devlink.h +6
-0+ enum devlink_perm_config_param param, u8 type, + union devlink_perm_config_value *value); +int (*perm_config_set)(struct devlink *devlink, +enum devlink_perm_config_param param,u8 type, +union devlink_perm_config_value *value, +u8 *restart_reqd);type should be enum and
restart_reqdshould be bool.
Throughout devlink/netlink code, NLA_* types are not a named enum; they're defined like this in netlink.h:
enum {
NLA_UNSPEC,
NLA_U8,
NLA_U16,
NLA_U32,
.... additional types follow ....
};and are, I believe referred to as u8 or u16 in the code. I could define a new enum specifically for the config get/set types, but that seems duplicative with the NLA_* types already defined - is that what you're suggesting?
I will change restart_reqd to be bool.
Quoted 18 lines
[...]
Quoted 14 lines
include/net/devlink.h +14
-0+static int devlink_nl_single_param_set (struct sk_buff *msg, +struct devlink *devlink, +u32 param,u8 type, +union devlink_perm_config_value *value) +{ +const struct devlink_ops *ops = devlink->ops; +struct nlattr *cfgparam_attr; +u8 need_restart; +int err; + +/* Now set parameter */ + err = ops->perm_config_set (devlink, param, type, value, &need_restart); +if (err) +return err;
Quoted 8 lines
include/net/devlink.h
Quoted 6 lines
include/net/devlink.h +6
-0+ + cfgparam_attr =nla_nest_start (msg,DEVLINK_ATTR_PERM_CONFIG ); +/* Update restart reqd - if any param needs restart, should be set */ +if (need_restart) { + err =nla_put_u8 (msg, +DEVLINK_ATTR_PERM_CONFIG_RESTART_REQUIRED ,1 );Why don't you just put this flag always? Otherwise it could be
NLA_FLAG
Ok, I will change to NLA_FLAG.
Thanks,
Steve
Jiri Pirko
maintainerRe: [PATCH net-next v4 01/10] devlink: Add permanent config parameter get/set operations
Quoted 42 lines · Fri, Oct 27, 2017 at 11:26:52PM CEST, [email protected] wrote:
Quoted 21 lines · Jiri Pirko
Quoted 20 lines · Fri, Oct 27, 2017 at 10:54:05PM CEST, [email protected] wrote:
Add support for permanent config parameter get/set commands. Used for persistent device configuration parameters.
Signed-off-by Steve Lin <[email protected]>Acked-by Andy Gospodarek <[email protected]>---
include/net/devlink.h | 7 ++ include/uapi/linux/devlink.h | 25 ++++ net/core/devlink.c | 287 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 319 insertions(+)include/net/devlink.h +1
-0@@ -270,6 +270,13 @@ struct devlink_ops {int (*eswitch_inline_mode_set)(struct devlink *devlink,u8 inline_mode);int (*eswitch_encap_mode_get)(struct devlink *devlink,u8 *p_encap_mode);int (*eswitch_encap_mode_set)(struct devlink *devlink,u8 encap_mode); + int (*perm_config_get)(struct devlink *devlink,Quoted 8 lines
include/net/devlink.h struct devlink_ops { · line 279
Quoted 6 lines
include/net/devlink.h +6
-0+ enum devlink_perm_config_param param, u8 type, + union devlink_perm_config_value *value); +int (*perm_config_set)(struct devlink *devlink, +enum devlink_perm_config_param param,u8 type, +union devlink_perm_config_value *value, +u8 *restart_reqd);type should be enum and
restart_reqdshould be bool.Throughout devlink/netlink code, NLA_* types are not a named enum; they're defined like this in
netlink.h:enum { NLA_UNSPEC, NLA_U8, NLA_U16, NLA_U32, .... additional types follow .... };
Quoted 4 lines
and are, I believe referred to as u8 or u16 in the code. I could define a new enum specifically for the config get/set types, but that seems duplicative with the NLA_* types already defined - is that what you're suggesting?
Yes, and that should be aligned with union devlink_perm_config_value.
Quoted 34 lines
I will change
restart_reqdto be bool.Quoted 18 lines
[...]
Quoted 14 lines
include/net/devlink.h +14
-0+static int devlink_nl_single_param_set (struct sk_buff *msg, +struct devlink *devlink, +u32 param,u8 type, +union devlink_perm_config_value *value) +{ +const struct devlink_ops *ops = devlink->ops; +struct nlattr *cfgparam_attr; +u8 need_restart; +int err; + +/* Now set parameter */ + err = ops->perm_config_set (devlink, param, type, value, &need_restart); +if (err) +return err;Quoted 8 lines
include/net/devlink.h
Quoted 6 lines
include/net/devlink.h +6
-0+ + cfgparam_attr =nla_nest_start (msg,DEVLINK_ATTR_PERM_CONFIG ); +/* Update restart reqd - if any param needs restart, should be set */ +if (need_restart) { + err =nla_put_u8 (msg, +DEVLINK_ATTR_PERM_CONFIG_RESTART_REQUIRED ,1 );Why don't you just put this flag always? Otherwise it could be
NLA_FLAGOk, I will change to
NLA_FLAG.Thanks,
Steve
PATCH v4 2/10 devlink: Adding SR-IOV enablement perm config param
In reply to Steve LinAdding DEVLINK_PERM_CONFIG_SRIOV_ENABLED permanent config parameter. Value is permanent, so becomes the new default value for this device.
DEVLINK_PERM_CONFIG_DISABLE = Disable SR-IOV DEVLINK_PERM_CONFIG_ENABLE = Enable SR-IOV
--- include/uapi/linux/devlink.h | 14 +++++++++++++- net/core/devlink.c | 1 + 2 files changed, 14 insertions(+), 1 deletion(-)
include/uapi/linux/devlink.h +13 -1
@@ -256,8 +256,20 @@ enum devlink_dpipe_header_id { DEVLINK_DPIPE_HEADER_IPV6, }; -/* Permanent config parameters */ +enum devlink_perm_config_enabled { +DEVLINK_PERM_CONFIG_DISABLE , +DEVLINK_PERM_CONFIG_ENABLE , +}; + +/* Permanent config parameters: +* DEVLINK_PERM_CONFIG_SRIOV_ENABLED: Configures whether SR-IOV PCI capability +* provided by device. +* DEVLINK_PERM_CONFIG_DISABLE = disable SR-IOV +* DEVLINK_PERM_CONFIG_ENABLE = enable SR-IOV +*/ enum devlink_perm_config_param { +DEVLINK_PERM_CONFIG_SRIOV_ENABLED , + __DEVLINK_PERM_CONFIG_MAX,DEVLINK_PERM_CONFIG_MAX = __DEVLINK_PERM_CONFIG_MAX -1 };
net/core/devlink.c +1 -0
@@ -1569,6 +1569,7 @@ static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb,static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX +1 ];static const u8 devlink_perm_cfg_param_types[DEVLINK_PERM_CONFIG_MAX +1 ] = { + [DEVLINK_PERM_CONFIG_SRIOV_ENABLED ] =NLA_U8 , }; static int devlink_nl_single_param_get(struct sk_buff *msg,
Signature · 1 line
2.7.4
Jiri Pirko
maintainerRe: [PATCH net-next v4 02/10] devlink: Adding SR-IOV enablement perm config param
Quoted 2 lines · Fri, Oct 27, 2017 at 10:54:06PM CEST, [email protected] wrote:
Adding
DEVLINK_PERM_CONFIG_SRIOV_ENABLEDpermanent config parameter. Value is permanent, so becomes the new default
Avoid the double space.
Quoted 19 lines
value for this device.
DEVLINK_PERM_CONFIG_DISABLE= Disable SR-IOV
DEVLINK_PERM_CONFIG_ENABLE= Enable SR-IOVSigned-off-by Steve Lin <[email protected]>Acked-by Andy Gospodarek <[email protected]>---
include/uapi/linux/devlink.h| 14 +++++++++++++-net/core/devlink.c| 1 +2 files changed, 14 insertions(+), 1 deletion(-)include/uapi/linux/devlink.h +0
-0@@ -256,8 +256,20 @@ enum devlink_dpipe_header_id { DEVLINK_DPIPE_HEADER_IPV6, };
include/uapi/linux/devlink.h enum devlink_dpipe_header_id { · line 266
Quoted 10 lines
include/uapi/linux/devlink.h +8
-1-/* Permanent config parameters */ +enum devlink_perm_config_enabled { +DEVLINK_PERM_CONFIG_DISABLE , +DEVLINK_PERM_CONFIG_ENABLE , +}; + +/* Permanent config parameters: +* DEVLINK_PERM_CONFIG_SRIOV_ENABLED: Configures whether SR-IOV PCI capability +* provided by device.
I don't understand the sentense :/
include/uapi/linux/devlink.h enum devlink_dpipe_header_id { · line 268
Quoted 2 lines
include/uapi/linux/devlink.h +2
-0+* DEVLINK_PERM_CONFIG_DISABLE = disable SR-IOV +* DEVLINK_PERM_CONFIG_ENABLE = enable SR-IOV
These comments should be at the enum values, not here.
Quoted 22 lines
include/uapi/linux/devlink.h +3
-0+*/ enum devlink_perm_config_param { +DEVLINK_PERM_CONFIG_SRIOV_ENABLED , + __DEVLINK_PERM_CONFIG_MAX,DEVLINK_PERM_CONFIG_MAX = __DEVLINK_PERM_CONFIG_MAX -1 };net/core/devlink.c +1
-0@@ -1569,6 +1569,7 @@ static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb,static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX +1 ];static const u8 devlink_perm_cfg_param_types[DEVLINK_PERM_CONFIG_MAX +1 ] = { + [DEVLINK_PERM_CONFIG_SRIOV_ENABLED ] =NLA_U8 , }; static int devlink_nl_single_param_get(struct sk_buff *msg,Signature · 1 line
2.7.4
Re: [PATCH net-next v4 02/10] devlink: Adding SR-IOV enablement perm config param
Quoted 5 lines · Jiri Pirko
Quoted 2 lines · Fri, Oct 27, 2017 at 10:54:06PM CEST, [email protected] wrote:
Adding
DEVLINK_PERM_CONFIG_SRIOV_ENABLEDpermanent config parameter. Value is permanent, so becomes the new defaultAvoid the double space.
Ok.
Quoted 22 lines
Quoted 22 lines
value for this device.
DEVLINK_PERM_CONFIG_DISABLE= Disable SR-IOV
DEVLINK_PERM_CONFIG_ENABLE= Enable SR-IOVSigned-off-by Steve Lin <[email protected]>Acked-by Andy Gospodarek <[email protected]>---
include/uapi/linux/devlink.h| 14 +++++++++++++-net/core/devlink.c| 1 +2 files changed, 14 insertions(+), 1 deletion(-)include/uapi/linux/devlink.h +0
-0@@ -256,8 +256,20 @@ enum devlink_dpipe_header_id { DEVLINK_DPIPE_HEADER_IPV6, };
Quoted 11 lines
include/uapi/linux/devlink.h enum devlink_dpipe_header_id { · line 266
Quoted 9 lines
include/uapi/linux/devlink.h +8
-1-/* Permanent config parameters */ +enum devlink_perm_config_enabled { +DEVLINK_PERM_CONFIG_DISABLE , +DEVLINK_PERM_CONFIG_ENABLE , +}; + +/* Permanent config parameters: +* DEVLINK_PERM_CONFIG_SRIOV_ENABLED: Configures whether SR-IOV PCI capability +* provided by device. I don't understand the sentense :/
It means that this parameter controls whether the device advertises SR-IOV PCI capability -- perhaps I should say "advertised" rather than "provided"? Ok, will do that...
Quoted 6 lines
include/uapi/linux/devlink.h enum devlink_dpipe_header_id { · line 268
Quoted 4 lines
include/uapi/linux/devlink.h +2
-0+* DEVLINK_PERM_CONFIG_DISABLE = disable SR-IOV +* DEVLINK_PERM_CONFIG_ENABLE = enable SR-IOV These comments should be at the enum values, not here.
Ok.
Quoted 24 lines
Quoted 24 lines
include/uapi/linux/devlink.h +3
-0+*/ enum devlink_perm_config_param { +DEVLINK_PERM_CONFIG_SRIOV_ENABLED , + __DEVLINK_PERM_CONFIG_MAX,DEVLINK_PERM_CONFIG_MAX = __DEVLINK_PERM_CONFIG_MAX -1 };net/core/devlink.c +1
-1@@ -1569,6 +1569,7 @@ static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb,static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX +1 ];static const u8 devlink_perm_cfg_param_types[DEVLINK_PERM_CONFIG_MAX +1 ] = { + [DEVLINK_PERM_CONFIG_SRIOV_ENABLED ] =NLA_U8 , }; static int devlink_nl_single_param_get(struct sk_buff *msg, --2.7.4
Jiri Pirko
maintainerRe: [PATCH net-next v4 02/10] devlink: Adding SR-IOV enablement perm config param
Quoted 43 lines · Fri, Oct 27, 2017 at 11:30:06PM CEST, [email protected] wrote:
Quoted 5 lines · Jiri Pirko
Quoted 2 lines · Fri, Oct 27, 2017 at 10:54:06PM CEST, [email protected] wrote:
Adding
DEVLINK_PERM_CONFIG_SRIOV_ENABLEDpermanent config parameter. Value is permanent, so becomes the new defaultAvoid the double space.
Ok.
Quoted 22 lines
Quoted 22 lines
value for this device.
DEVLINK_PERM_CONFIG_DISABLE= Disable SR-IOV
DEVLINK_PERM_CONFIG_ENABLE= Enable SR-IOVSigned-off-by Steve Lin <[email protected]>Acked-by Andy Gospodarek <[email protected]>---
include/uapi/linux/devlink.h| 14 +++++++++++++-net/core/devlink.c| 1 +2 files changed, 14 insertions(+), 1 deletion(-)include/uapi/linux/devlink.h +0
-0@@ -256,8 +256,20 @@ enum devlink_dpipe_header_id { DEVLINK_DPIPE_HEADER_IPV6, };Quoted 11 lines
include/uapi/linux/devlink.h enum devlink_dpipe_header_id { · line 266
Quoted 9 lines
include/uapi/linux/devlink.h +8
-1-/* Permanent config parameters */ +enum devlink_perm_config_enabled { +DEVLINK_PERM_CONFIG_DISABLE , +DEVLINK_PERM_CONFIG_ENABLE , +}; + +/* Permanent config parameters: +* DEVLINK_PERM_CONFIG_SRIOV_ENABLED: Configures whether SR-IOV PCI capability +* provided by device. I don't understand the sentense :/
Quoted 3 lines
It means that this parameter controls whether the device advertises SR-IOV PCI capability -- perhaps I should say "advertised" rather than "provided"? Ok, will do that...
I'm missing "is" most probably.
Quoted 34 lines
Quoted 7 lines
include/uapi/linux/devlink.h enum devlink_dpipe_header_id { · line 268
Quoted 5 lines
include/uapi/linux/devlink.h +2
-0+* DEVLINK_PERM_CONFIG_DISABLE = disable SR-IOV +* DEVLINK_PERM_CONFIG_ENABLE = enable SR-IOV These comments should be at the enum values, not here.
Ok.
Quoted 24 lines
Quoted 24 lines
include/uapi/linux/devlink.h +3
-0+*/ enum devlink_perm_config_param { +DEVLINK_PERM_CONFIG_SRIOV_ENABLED , + __DEVLINK_PERM_CONFIG_MAX,DEVLINK_PERM_CONFIG_MAX = __DEVLINK_PERM_CONFIG_MAX -1 };net/core/devlink.c +1
-1@@ -1569,6 +1569,7 @@ static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb,static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX +1 ];static const u8 devlink_perm_cfg_param_types[DEVLINK_PERM_CONFIG_MAX +1 ] = { + [DEVLINK_PERM_CONFIG_SRIOV_ENABLED ] =NLA_U8 , }; static int devlink_nl_single_param_get(struct sk_buff *msg, --2.7.4
PATCH v4 3/10 devlink: Adding num VFs per PF permanent config param
In reply to Steve LinAdding DEVLINK_PERM_CONFIG_NUM_VF_PER_PF permanent config parameter. Value is permanent, so becomes the new default value for this device.
The value sets the number of VFs per PF in SR-IOV mode.
--- include/uapi/linux/devlink.h | 4 ++++ net/core/devlink.c | 1 + 2 files changed, 5 insertions(+)
include/uapi/linux/devlink.h +4 -0
@@ -266,9 +266,13 @@ enum devlink_perm_config_enabled {* provided by device. * DEVLINK_PERM_CONFIG_DISABLE = disable SR-IOV * DEVLINK_PERM_CONFIG_ENABLE = enable SR-IOV +* DEVLINK_PERM_CONFIG_NUM_VF_PER_PF: Configures number of total/maximum VFs +* per PF available on device. +* Value: # of VFs per PF in SR-IOV mode */ enum devlink_perm_config_param {DEVLINK_PERM_CONFIG_SRIOV_ENABLED , +DEVLINK_PERM_CONFIG_NUM_VF_PER_PF , __DEVLINK_PERM_CONFIG_MAX,DEVLINK_PERM_CONFIG_MAX = __DEVLINK_PERM_CONFIG_MAX -1
net/core/devlink.c +1 -0
@@ -1570,6 +1570,7 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1];static const u8 devlink_perm_cfg_param_types[DEVLINK_PERM_CONFIG_MAX +1 ] = { [DEVLINK_PERM_CONFIG_SRIOV_ENABLED ] =NLA_U8 , + [DEVLINK_PERM_CONFIG_NUM_VF_PER_PF ] =NLA_U32 , }; static int devlink_nl_single_param_get(struct sk_buff *msg,
Signature · 1 line
2.7.4
PATCH v4 4/10 devlink: Adding max PF MSI-X vectors perm config param
In reply to Steve LinAdding DEVLINK_PERM_CONFIG_MAX_NUM_PF_MSIX_VECT permanent config parameter. Value is permanent, so becomes the new default value for this device.
Value sets the maximum number of PF MSI-X vectors.
--- include/uapi/linux/devlink.h | 4 ++++ net/core/devlink.c | 1 + 2 files changed, 5 insertions(+)
include/uapi/linux/devlink.h +4 -0
@@ -269,10 +269,14 @@ enum devlink_perm_config_enabled {* DEVLINK_PERM_CONFIG_NUM_VF_PER_PF: Configures number of total/maximum VFs * per PF available on device. * Value: # of VFs per PF in SR-IOV mode +* DEVLINK_PERM_CONFIG_NUM_PF_MSIX_VECT: Configures # MSI-X vectors +* advertised via PCI capability for this device. +* Value = Max # of MSI-X vectors per PF */ enum devlink_perm_config_param {DEVLINK_PERM_CONFIG_SRIOV_ENABLED ,DEVLINK_PERM_CONFIG_NUM_VF_PER_PF , +DEVLINK_PERM_CONFIG_NUM_PF_MSIX_VECT , __DEVLINK_PERM_CONFIG_MAX,DEVLINK_PERM_CONFIG_MAX = __DEVLINK_PERM_CONFIG_MAX -1
net/core/devlink.c +1 -0
@@ -1571,6 +1571,7 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1];static const u8 devlink_perm_cfg_param_types[DEVLINK_PERM_CONFIG_MAX +1 ] = { [DEVLINK_PERM_CONFIG_SRIOV_ENABLED ] =NLA_U8 , [DEVLINK_PERM_CONFIG_NUM_VF_PER_PF ] =NLA_U32 , + [DEVLINK_PERM_CONFIG_NUM_PF_MSIX_VECT ] =NLA_U32 , }; static int devlink_nl_single_param_get(struct sk_buff *msg,
Signature · 1 line
2.7.4
PATCH v4 5/10 devlink: Adding num MSI-X vectors per VF perm config param
In reply to Steve LinAdding DEVLINK_PERM_CONFIG_NUM_MSIX_VECT_PER_VF permanent config parameter. Value is permanent, so becomes the new default value for this device.
Value defines number of MSI-X vectors allocated per VF.
--- include/uapi/linux/devlink.h | 4 ++++ net/core/devlink.c | 1 + 2 files changed, 5 insertions(+)
include/uapi/linux/devlink.h +4 -0
@@ -272,11 +272,15 @@ enum devlink_perm_config_enabled {* DEVLINK_PERM_CONFIG_NUM_PF_MSIX_VECT: Configures # MSI-X vectors * advertised via PCI capability for this device. * Value = Max # of MSI-X vectors per PF +* DEVLINK_PERM_CONFIG_NUM_MSIX_VECT_PER_VF: Configures # MSI-X vectors +* advertised via PCI capability for each VF on this device. +* # of MSI-X vectors per VF */ enum devlink_perm_config_param {DEVLINK_PERM_CONFIG_SRIOV_ENABLED ,DEVLINK_PERM_CONFIG_NUM_VF_PER_PF ,DEVLINK_PERM_CONFIG_NUM_PF_MSIX_VECT , +DEVLINK_PERM_CONFIG_NUM_MSIX_VECT_PER_VF , __DEVLINK_PERM_CONFIG_MAX,DEVLINK_PERM_CONFIG_MAX = __DEVLINK_PERM_CONFIG_MAX -1
net/core/devlink.c +1 -0
@@ -1572,6 +1572,7 @@ static const u8 devlink_perm_cfg_param_types[DEVLINK_PERM_CONFIG_MAX + 1] = { [DEVLINK_PERM_CONFIG_SRIOV_ENABLED] = NLA_U8, [DEVLINK_PERM_CONFIG_NUM_VF_PER_PF] = NLA_U32, [DEVLINK_PERM_CONFIG_NUM_PF_MSIX_VECT] = NLA_U32, + [DEVLINK_PERM_CONFIG_NUM_MSIX_VECT_PER_VF] = NLA_U32, }; static int devlink_nl_single_param_get(struct sk_buff *msg,
Signature · 1 line
2.7.4
PATCH v4 6/10 bnxt: Add devlink support for config get/set
In reply to Steve LinImplements get and set of configuration parameters using new devlink config get/set API. Parameters themselves defined in later patches.
--- drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c | 258 +++++++++++++++++++++- drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.h | 17 ++ 2 files changed, 263 insertions(+), 12 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +246 -12
@@ -14,26 +14,260 @@#include "bnxt_vfr.h" #include "bnxt_devlink.h" -static const struct devlink_ops bnxt_dl_ops = { -#ifdef CONFIG_BNXT_SRIOV - .eswitch_mode_set = bnxt_dl_eswitch_mode_set, - .eswitch_mode_get = bnxt_dl_eswitch_mode_get, -#endif /* CONFIG_BNXT_SRIOV */ +struct bnxt_drv_cfgparam bnxt_drv_cfgparam_list[] = { }; -int bnxt_dl_register (struct bnxt *bp) +#define BNXT_NUM_DRV_CFGPARAM ARRAY_SIZE(bnxt_drv_cfgparam_list) + +static int bnxt_nvm_read (struct bnxt *bp,int nvm_param,int idx, +void *buf,int size) { -struct devlink *dl; +struct hwrm_nvm_get_variable_input req = {0 }; +dma_addr_t dest_data_dma_addr; +void *dest_data_addr =NULL ; +int bytesize;int rc; -if (!pci_find_ext_capability (bp->pdev,PCI_EXT_CAP_ID_SRIOV )) -return 0 ; + bytesize =roundup (size,BITS_PER_BYTE ) /BITS_PER_BYTE ; + dest_data_addr =dma_alloc_coherent (&bp->pdev->dev, bytesize, + &dest_data_dma_addr,GFP_KERNEL ); +if (!dest_data_addr) +return -ENOMEM ; + +bnxt_hwrm_cmd_hdr_init (bp, &req,HWRM_NVM_GET_VARIABLE ,-1 ,-1 ); + req.dest_data_addr =cpu_to_le64 (dest_data_dma_addr); + req.data_len =cpu_to_le16 (size); + req.option_num =cpu_to_le16 (nvm_param); + req.index_0 =cpu_to_le16 (idx); +if (idx !=0 ) + req.dimensions =cpu_to_le16 (1 ); + + rc =hwrm_send_message (bp, &req,sizeof (req),HWRM_CMD_TIMEOUT ); + +memcpy (buf, dest_data_addr, bytesize); + +dma_free_coherent (&bp->pdev->dev, bytesize, dest_data_addr, + dest_data_dma_addr); + +return rc; +} + +static int bnxt_nvm_write (struct bnxt *bp,int nvm_param,int idx, +const void *buf,int size) +{ +struct hwrm_nvm_set_variable_input req = {0 }; +dma_addr_t src_data_dma_addr; +void *src_data_addr =NULL ; +int bytesize; +int rc; + + bytesize =roundup (size,BITS_PER_BYTE ) /BITS_PER_BYTE ; + + src_data_addr =dma_alloc_coherent (&bp->pdev->dev, bytesize, + &src_data_dma_addr,GFP_KERNEL ); +if (!src_data_addr) +return -ENOMEM ; + +memcpy (src_data_addr, buf, bytesize); + +bnxt_hwrm_cmd_hdr_init (bp, &req,HWRM_NVM_SET_VARIABLE ,-1 ,-1 ); + req.src_data_addr =cpu_to_le64 (src_data_dma_addr); + req.data_len =cpu_to_le16 (size); + req.option_num =cpu_to_le16 (nvm_param); + req.index_0 =cpu_to_le16 (idx); +if (idx !=0 ) + req.dimensions =cpu_to_le16 (1 ); + + rc =hwrm_send_message (bp, &req,sizeof (req),HWRM_CMD_TIMEOUT ); + +dma_free_coherent (&bp->pdev->dev, bytesize, src_data_addr, + src_data_dma_addr); -if (bp->hwrm_spec_code <0x10803 ) { -netdev_warn (bp->dev,"Firmware does not support SR-IOV E-Switch SWITCHDEV mode.\n" ); -return -ENOTSUPP ; +return 0 ; +} + +static int bnxt_dl_perm_config_set (struct devlink *devlink, +enum devlink_perm_config_param param, +u8 type, +union devlink_perm_config_value *value, +u8 *restart_reqd) +{ +struct bnxt *bp =bnxt_get_bp_from_dl (devlink); +struct bnxt_drv_cfgparam *entry =NULL ; +u32 value_int; +u32 bytesize; +int idx =0 ; +int ret =0 ; +u16 val16; +u8 val8; +int i; + + *restart_reqd =0 ; + +/* Find parameter in table */ +for (i =0 ; i <BNXT_NUM_DRV_CFGPARAM ; i++) { +if (param == bnxt_drv_cfgparam_list[i].param) { + entry = &bnxt_drv_cfgparam_list[i]; +break ; + } + } + +/* Not found */ +if (!entry) +return -EINVAL ; + +/* Check to see if this func type can access variable */ +if (BNXT_PF (bp) && !(entry->func &BNXT_DRV_PF )) +return -EOPNOTSUPP ; +if (BNXT_VF (bp) && !(entry->func &BNXT_DRV_VF )) +return -EOPNOTSUPP ; + +/* If parameter is per port or function, compute index */ +if (entry->appl ==BNXT_DRV_APPL_PORT ) { + idx = bp->pf.port_id; + }else if (entry->appl ==BNXT_DRV_APPL_FUNCTION ) { +if (BNXT_PF (bp)) + idx = bp->pf.fw_fid -BNXT_FIRST_PF_FID ; } + bytesize =roundup (entry->bitlength,BITS_PER_BYTE ) /BITS_PER_BYTE ; + +/* Type expected by device may or may not be the same as type passed +* in from devlink API. So first convert to an interval u32 value, +* then to type needed by device. +*/ +if (type ==NLA_U8 ) { + value_int = value->value8; + }else if (type ==NLA_U16 ) { + value_int = value->value16; + }else if (type ==NLA_U32 ) { + value_int = value->value32; + }else { +/* Unsupported type */ +return -EINVAL ; + } + +if (bytesize ==1 ) { + val8 = value_int; + ret =bnxt_nvm_write (bp, entry->nvm_param, idx, &val8, + entry->bitlength); + }else if (bytesize ==2 ) { + val16 = value_int; + ret =bnxt_nvm_write (bp, entry->nvm_param, idx, &val16, + entry->bitlength); + }else { + ret =bnxt_nvm_write (bp, entry->nvm_param, idx, &value_int, + entry->bitlength); + } + +/* Restart required for all nvm parameter writes */ + *restart_reqd =1 ; + +return ret; +} + +static int bnxt_dl_perm_config_get (struct devlink *devlink, +enum devlink_perm_config_param param, +u8 type, +union devlink_perm_config_value *value) +{ +struct bnxt *bp =bnxt_get_bp_from_dl (devlink); +struct bnxt_drv_cfgparam *entry =NULL ; +u32 value_int; +u32 bytesize; +int idx =0 ; +int err =0 ; +void *data; +u16 val16; +u8 val8; +int i; + +/* Find parameter in table */ +for (i =0 ; i <BNXT_NUM_DRV_CFGPARAM ; i++) { +if (param == bnxt_drv_cfgparam_list[i].param) { + entry = &bnxt_drv_cfgparam_list[i]; +break ; + } + } + +/* Not found */ +if (!entry) +return -EINVAL ; + +/* Check to see if this func type can access variable */ +if (BNXT_PF (bp) && !(entry->func &BNXT_DRV_PF )) +return -EOPNOTSUPP ; +if (BNXT_VF (bp) && !(entry->func &BNXT_DRV_VF )) +return -EOPNOTSUPP ; + +/* If parameter is per port or function, compute index */ +if (entry->appl ==BNXT_DRV_APPL_PORT ) { + idx = bp->pf.port_id; + }else if (entry->appl ==BNXT_DRV_APPL_FUNCTION ) { +if (BNXT_PF (bp)) + idx = bp->pf.fw_fid -BNXT_FIRST_PF_FID ; + } + +/* Allocate space, retrieve value, and copy to result */ + bytesize =roundup (entry->bitlength,BITS_PER_BYTE ) /BITS_PER_BYTE ; + data =kmalloc (bytesize,GFP_KERNEL ); +if (!data) +return -ENOMEM ; + err =bnxt_nvm_read (bp, entry->nvm_param, idx, data, entry->bitlength); +if (err) + goto err_data; + +/* Type returned by device may or may not be the same as type expected +* by devlink API. So first convert to an interval u32 value, then to +* type expected by devlink. +*/ +if (bytesize ==1 ) { +memcpy (&val8, data,sizeof (val8)); + value_int = val8; + }else if (bytesize ==2 ) { +memcpy (&val16, data,sizeof (val16)); + value_int = val16; + }else { +memcpy (&value_int, data,sizeof (value_int)); + } + +if (type ==NLA_U8 ) { + value->value8 = value_int; + }else if (type ==NLA_U16 ) { + value->value16 = value_int; + }else if (type ==NLA_U32 ) { + value->value32 = value_int; + }else { +/* Unsupported type */ + err = -EINVAL ; + } + +err_data: +kfree (data); + +return err; +} + +static struct devlink_ops bnxt_dl_ops = { + .perm_config_get = bnxt_dl_perm_config_get, + .perm_config_set = bnxt_dl_perm_config_set, +}; + +int bnxt_dl_register (struct bnxt *bp) +{ +struct devlink *dl; +int rc; + +#ifdef CONFIG_BNXT_SRIOV +/* Add switchdev eswitch mode setting if SRIOV supported */ +if (pci_find_ext_capability (bp->pdev,PCI_EXT_CAP_ID_SRIOV ) && + bp->hwrm_spec_code >=0x10800 ) { + bnxt_dl_ops.eswitch_mode_set = bnxt_dl_eswitch_mode_set; + bnxt_dl_ops.eswitch_mode_get = bnxt_dl_eswitch_mode_get; + } else +#endif /* CONFIG_BNXT_SRIOV */ +netdev_warn (bp->dev,"SR-IOV E-Switch SWITCHDEV mode not supported.\n" ); + dl =devlink_alloc (&bnxt_dl_ops,sizeof (struct bnxt_dl ));if (!dl) {netdev_warn (bp->dev,"devlink_alloc failed" );
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.h +17 -0
@@ -10,6 +10,23 @@ #ifndef BNXT_DEVLINK_H #define BNXT_DEVLINK_H +#define BNXT_DRV_PF 1 +#define BNXT_DRV_VF 2 + +enum bnxt_drv_appl { + BNXT_DRV_APPL_SHARED, + BNXT_DRV_APPL_PORT, + BNXT_DRV_APPL_FUNCTION +}; + +struct bnxt_drv_cfgparam { + enum devlink_perm_config_param param; + u8 func; /* BNXT_DRV_PF | BNXT_DRV_VF */ + enum bnxt_drv_appl appl; /* applicability (shared, func, port) */ + u32 bitlength; /* length, in bits */ + u32 nvm_param; +}; + /* Struct to hold housekeeping info needed by devlink interface */ struct bnxt_dl { struct bnxt *bp; /* back ptr to the controlling dev */
Signature · 1 line
2.7.4
PATCH v4 7/10 bnxt: Adding SR-IOV enablement permanent cfg param
In reply to Steve LinAdding permanent config parameter for SR-IOV enablement, using devlink API for get/set operation.
DEVLINK_PERM_CONFIG_DISABLE = SR-IOV disabledDEVLINK_PERM_CONFIG_ENABLE = SR-IOV enabled
--- drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +7 -0
@@ -14,7 +14,14 @@#include "bnxt_vfr.h" #include "bnxt_devlink.h" +/* Permanent config parameters from devlink.h: +* DEVLINK_PERM_CONFIG_SRIOV_ENABLED: +* DEVLINK_PERM_CONFIG_DISABLE = disable SR-IOV +* DEVLINK_PERM_CONFIG_ENABLE = enable SR-IOV +*/ struct bnxt_drv_cfgparam bnxt_drv_cfgparam_list[] = { + {DEVLINK_PERM_CONFIG_SRIOV_ENABLED ,BNXT_DRV_PF , +BNXT_DRV_APPL_SHARED ,1 ,401 }, };#define BNXT_NUM_DRV_CFGPARAM ARRAY_SIZE(bnxt_drv_cfgparam_list)
Signature · 1 line
2.7.4
PATCH v4 8/10 bnxt: Adding num VFs per PF perm config param
In reply to Steve LinAdding permanent config parameter for number of VFs per PF, using devlink API for get/set operation.
Value sets the number of VFs per PF in SR-IOV mode.
--- drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +4 -0
@@ -18,10 +18,14 @@* DEVLINK_PERM_CONFIG_SRIOV_ENABLED: * DEVLINK_PERM_CONFIG_DISABLE = disable SR-IOV * DEVLINK_PERM_CONFIG_ENABLE = enable SR-IOV +* DEVLINK_PERM_CONFIG_NUM_VF_PER_PF: +* # of VFs per PF in SR-IOV mode */ struct bnxt_drv_cfgparam bnxt_drv_cfgparam_list[] = { {DEVLINK_PERM_CONFIG_SRIOV_ENABLED ,BNXT_DRV_PF ,BNXT_DRV_APPL_SHARED ,1 ,401 }, + {DEVLINK_PERM_CONFIG_NUM_VF_PER_PF ,BNXT_DRV_PF , +BNXT_DRV_APPL_FUNCTION ,8 ,404 }, };#define BNXT_NUM_DRV_CFGPARAM ARRAY_SIZE(bnxt_drv_cfgparam_list)
Signature · 1 line
2.7.4
PATCH v4 9/10 bnxt: Adding max PF MSI-X vectors perm config param
In reply to Steve LinAdding permanent config parameter for maximum number of PF MSI-X vectors.
--- drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +4 -0
@@ -20,12 +20,16 @@* DEVLINK_PERM_CONFIG_ENABLE = enable SR-IOV * DEVLINK_PERM_CONFIG_NUM_VF_PER_PF: * # of VFs per PF in SR-IOV mode +* DEVLINK_PERM_CONFIG_MAX_NUM_PF_MSIX_VECT: +* Max # of MSI-X vectors per PF */ struct bnxt_drv_cfgparam bnxt_drv_cfgparam_list[] = { {DEVLINK_PERM_CONFIG_SRIOV_ENABLED ,BNXT_DRV_PF ,BNXT_DRV_APPL_SHARED ,1 ,401 }, {DEVLINK_PERM_CONFIG_NUM_VF_PER_PF ,BNXT_DRV_PF ,BNXT_DRV_APPL_FUNCTION ,8 ,404 }, + {DEVLINK_PERM_CONFIG_NUM_PF_MSIX_VECT ,BNXT_DRV_PF , +BNXT_DRV_APPL_SHARED ,10 ,108 }, };#define BNXT_NUM_DRV_CFGPARAM ARRAY_SIZE(bnxt_drv_cfgparam_list)
Signature · 1 line
2.7.4
PATCH v4 10/10 bnxt: Adding num MSI-X vectors per VF perm config param
In reply to Steve LinAdding permanent config parameter for number MSI-X vectors per VF, using devlink API for get/set operation.
--- drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +4 -0
@@ -22,6 +22,8 @@* # of VFs per PF in SR-IOV mode * DEVLINK_PERM_CONFIG_MAX_NUM_PF_MSIX_VECT: * Max # of MSI-X vectors per PF +* DEVLINK_PERM_CONFIG_NUM_MSIX_VECT_PER_VF: +* # of MSI-X vectors per VF */ struct bnxt_drv_cfgparam bnxt_drv_cfgparam_list[] = { {DEVLINK_PERM_CONFIG_SRIOV_ENABLED ,BNXT_DRV_PF ,
@@ -30,6 +32,8 @@ struct bnxt_drv_cfgparam bnxt_drv_cfgparam_list[] = { BNXT_DRV_APPL_FUNCTION, 8, 404}, {DEVLINK_PERM_CONFIG_NUM_PF_MSIX_VECT ,BNXT_DRV_PF , BNXT_DRV_APPL_SHARED, 10, 108}, + {DEVLINK_PERM_CONFIG_NUM_MSIX_VECT_PER_VF, BNXT_DRV_PF, + BNXT_DRV_APPL_FUNCTION, 10, 406}, };#define BNXT_NUM_DRV_CFGPARAM ARRAY_SIZE(bnxt_drv_cfgparam_list)
Signature · 1 line
2.7.4