Adding permanent config get/set to devlink
v5 cover Adding permanent config get/set to devlink
Changes since v4:
* Created / used enum for permanent config param / types.
* Use bool and NLA_FLAG for restart_required indication.
* Move and reworded comments and git commit messagess for clarity and removed double-spaces after sentences.
PATCH v5 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 | 9 ++ include/uapi/linux/devlink.h | 33 +++++ net/core/devlink.c | 293 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 335 insertions(+)
include/net/devlink.h +9 -0
@@ -270,6 +270,15 @@ 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, +enum devlink_perm_config_type type, +union devlink_perm_config_value *value); +int (*perm_config_set)(struct devlink *devlink, +enum devlink_perm_config_param param, +enum devlink_perm_config_type type, +union devlink_perm_config_value *value, +bool *restart_reqd); };static inline void *devlink_priv (struct devlink *devlink)
include/uapi/linux/devlink.h +33 -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 ,/* flag */ +/* add new attributes above here, update the policy in devlink.c */ __DEVLINK_ATTR_MAX,
@@ -244,4 +256,25 @@ 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 types */ +enum devlink_perm_config_type { +DEVLINK_PERM_CONFIG_TYPE_UNSPEC , +DEVLINK_PERM_CONFIG_TYPE_U8 , +DEVLINK_PERM_CONFIG_TYPE_U16 , +DEVLINK_PERM_CONFIG_TYPE_U32 , +}; + +/* Permanent config value */ +union devlink_perm_config_value { +__u8 value8; +__u16 value16; +__u32 value32; +}; +#endif /* _UAPI_LINUX_DEVLINK_H_ */
net/core/devlink.c +293 -0
311 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v5 2/10 devlink: Adding SR-IOV enablement perm config param
In reply to Steve LinAdding DEVLINK_PERM_CONFIG_SRIOV_ENABLED permanent config parameter; this parameter controls whether the device advertises the SR-IOV PCI capability. 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 | 18 +++++++++++++++++- net/core/devlink.c | 1 + 2 files changed, 18 insertions(+), 1 deletion(-)
include/uapi/linux/devlink.h +17 -1
@@ -256,8 +256,24 @@ enum devlink_dpipe_header_id { DEVLINK_DPIPE_HEADER_IPV6, }; -/* Permanent config parameters */ +/* Permanent config parameter enable/disable +* DEVLINK_PERM_CONFIG_DISABLE = disable a permanent config parameter +* DEVLINK_PERM_CONFIG_ENBALE = enable a permanent config parameter +*/ +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 +* is advertised by the 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
PATCH v5 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
@@ -270,9 +270,13 @@ enum devlink_perm_config_enabled {* is advertised by the device. * DEVLINK_PERM_CONFIG_DISABLE = disable SR-IOV * DEVLINK_PERM_CONFIG_ENABLE = enable SR-IOV +* DEVLINK_PERM_CONFIG_NUM_VF_PER_PF: Configures the 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 v5 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
@@ -273,10 +273,14 @@ enum devlink_perm_config_enabled {* DEVLINK_PERM_CONFIG_NUM_VF_PER_PF: Configures the 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 the # of 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 v5 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
@@ -276,11 +276,15 @@ enum devlink_perm_config_enabled {* DEVLINK_PERM_CONFIG_NUM_PF_MSIX_VECT: Configures the # of 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 the # of 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 v5 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, +enum devlink_perm_config_type type, +union devlink_perm_config_value *value, +bool *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 ==DEVLINK_PERM_CONFIG_TYPE_U8 ) { + value_int = value->value8; + }else if (type ==DEVLINK_PERM_CONFIG_TYPE_U16 ) { + value_int = value->value16; + }else if (type ==DEVLINK_PERM_CONFIG_TYPE_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, +enum devlink_perm_config_type 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 ==DEVLINK_PERM_CONFIG_TYPE_U8 ) { + value->value8 = value_int; + }else if (type ==DEVLINK_PERM_CONFIG_TYPE_U16 ) { + value->value16 = value_int; + }else if (type ==DEVLINK_PERM_CONFIG_TYPE_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 v5 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 v5 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 v5 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 v5 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
Jiri Pirko
maintainerRe: [PATCH net-next v5 01/10] devlink: Add permanent config parameter get/set operations
In reply to Steve LinQuoted 5 lines · Mon, Oct 30, 2017 at 03:46:07PM CET, [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]>
In general, I don't like how you use netlink. Please see the rest of this code. We should do things in the common way. More info inlined.
[...]
include/uapi/linux/devlink.h enum devlink_dpipe_header_id { · line 267
Quoted 10 lines
include/uapi/linux/devlink.h +9
-0+/* Permanent config parameters */ +enum devlink_perm_config_param { + __DEVLINK_PERM_CONFIG_MAX, +DEVLINK_PERM_CONFIG_MAX = __DEVLINK_PERM_CONFIG_MAX -1 +}; + +/* Permanent config types */ +enum devlink_perm_config_type { +DEVLINK_PERM_CONFIG_TYPE_UNSPEC ,
You should not need this. Type should be always specified.
include/uapi/linux/devlink.h enum devlink_dpipe_header_id { · line 271
Quoted 4 lines
include/uapi/linux/devlink.h +4
-0+DEVLINK_PERM_CONFIG_TYPE_U8 , +DEVLINK_PERM_CONFIG_TYPE_U16 , + DEVLINK_PERM_CONFIG_TYPE_U32, +};
This definitelly should not be in uapi header.
include/uapi/linux/devlink.h enum devlink_dpipe_header_id { · line 278
Quoted 7 lines
include/uapi/linux/devlink.h +7
-0+ +/* Permanent config value */ +union devlink_perm_config_value { +__u8 value8; +__u16 value16; +__u32 value32; +};
This definitelly should not be in uapi header.
Quoted 2 lines
+
#endif /* _UAPI_LINUX_DEVLINK_H_ */
[...]
Quoted 21 lines
net/core/devlink.c +21
-0+static int devlink_nl_config_get_fill (struct sk_buff *msg, +struct devlink *devlink, +enum devlink_command cmd, +struct genl_info *info) +{ +struct nlattr *tb[DEVLINK_ATTR_MAX +1 ]; +enum devlink_perm_config_param param; +enum devlink_perm_config_type type; +struct nlattr *cfgparam_attr; +struct nlattr *attr; +void *hdr; +int err; +int rem; + + hdr =genlmsg_put (msg, info->snd_portid, info->snd_seq, + &devlink_nl_family,0 , cmd); +if (!hdr) +return -EMSGSIZE ; + + err =devlink_nl_put_handle (msg, devlink); +if (err)
net/core/devlink.c static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb, · line 1656
Quoted 10 lines
net/core/devlink.c +10
-0+ goto nla_put_failure; + +if (!info->attrs[DEVLINK_ATTR_PERM_CONFIGS ]) { + err = -EINVAL ; + goto nla_put_failure; + } + + cfgparam_attr =nla_nest_start (msg,DEVLINK_ATTR_PERM_CONFIGS ); + + nla_for_each_nested(attr, info->attrs[DEVLINK_ATTR_PERM_CONFIGS],
Okay. So I have to know what is in kernel in order to get the value.
We need a dump operation. In fact, why can't we just have dump operation?
net/core/devlink.c static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb, · line 1667
Quoted 11 lines
net/core/devlink.c +11
-0+ rem) { + err =nla_parse_nested (tb,DEVLINK_ATTR_MAX , attr, + devlink_nl_policy,NULL ); +if (err) + goto nla_nest_failure; +if (!tb[DEVLINK_ATTR_PERM_CONFIG_PARAMETER ] || + !tb[DEVLINK_ATTR_PERM_CONFIG_TYPE ]) +continue ; + + param =nla_get_u32 (tb[DEVLINK_ATTR_PERM_CONFIG_PARAMETER ]); + type =nla_get_u8 (tb[DEVLINK_ATTR_PERM_CONFIG_TYPE ]);
So to get parameter, I have to specify a type? What if I specify wrong type? That is wrong. The type should be read attr for get.
You should have a param -> type table and always use that.
Quoted 9 lines
net/core/devlink.c +9
-0+if (param >DEVLINK_PERM_CONFIG_MAX || + type >NLA_TYPE_MAX ) { +continue ; + } +/* Note if single_param_get fails, that param won't be in +* response msg, so caller will know which param(s) failed to +* get. +*/ +devlink_nl_single_param_get (msg, devlink, param, type);
net/core/devlink.c static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb, · line 1686
Quoted 10 lines
net/core/devlink.c +10
-0+ } + +nla_nest_end (msg, cfgparam_attr); + +genlmsg_end (msg, hdr); +return 0 ; + +nla_nest_failure: +nla_nest_cancel (msg, cfgparam_attr); +nla_put_failure:
You should make this multipart aware. If config parameters won't fit into a single skb, you have to allocate another one. See devlink_dpipe_tables_fill as an example how to do it. It is important to have this from the beginning as the userspace knows to expect multipart message.
Quoted 38 lines
net/core/devlink.c +38
-0+genlmsg_cancel (msg, hdr); +return err; +} + +static int devlink_nl_cmd_perm_config_get_doit (struct sk_buff *skb, +struct genl_info *info) +{ +struct devlink *devlink = info->user_ptr[0 ]; +struct sk_buff *msg; +int err; + +if (!devlink->ops || !devlink->ops->perm_config_get) +return -EOPNOTSUPP ; + + msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); +if (!msg) +return -ENOMEM ; + + err =devlink_nl_config_get_fill (msg, devlink, +DEVLINK_CMD_PERM_CONFIG_GET , info); + +if (err) { +nlmsg_free (msg); +return err; + } + +return genlmsg_reply (msg, info); +} + +static int devlink_nl_single_param_set (struct sk_buff *msg, +struct devlink *devlink, +enum devlink_perm_config_param param, +enum devlink_perm_config_type type, +union devlink_perm_config_value *value) +{ +const struct devlink_ops *ops = devlink->ops; +struct nlattr *cfgparam_attr; +bool need_restart;
net/core/devlink.c static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb, · line 1734
Quoted 10 lines
net/core/devlink.c +10
-0+int err; + +/* 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) {
You should propagate this out so the caller would fill it to the message. This is a global thing, not per-param, shoult not be nested.
Quoted 84 lines
net/core/devlink.c +84
-0+ err =nla_put_flag (msg, +DEVLINK_ATTR_PERM_CONFIG_RESTART_REQUIRED ); +if (err) + goto nest_fail; + } + +/* Since set was successful, write attr back to msg */ + err =nla_put_u32 (msg,DEVLINK_ATTR_PERM_CONFIG_PARAMETER , param); +if (err) + goto nest_fail; + +nla_nest_end (msg, cfgparam_attr); + +return 0 ; + +nest_fail: +nla_nest_cancel (msg, cfgparam_attr); +return err; +} + +static int devlink_nl_cmd_perm_config_set_doit (struct sk_buff *skb, +struct genl_info *info) +{ +struct devlink *devlink = info->user_ptr[0 ]; +struct nlattr *tb[DEVLINK_ATTR_MAX +1 ]; +union devlink_perm_config_value value; +enum devlink_perm_config_param param; +enum devlink_perm_config_type type; +struct nlattr *cfgparam_attr; +struct sk_buff *msg; +struct nlattr *attr; +void *hdr; +int rem; +int err; + +if (!devlink->ops || !devlink->ops->perm_config_get || + !devlink->ops->perm_config_set) +return -EOPNOTSUPP ; + + msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); +if (!msg) +return -ENOMEM ; + + hdr =genlmsg_put (msg, info->snd_portid, info->snd_seq, + &devlink_nl_family,0 ,DEVLINK_CMD_PERM_CONFIG_SET ); +if (!hdr) { + err = -EMSGSIZE ; + goto nla_msg_failure; + } + + err =devlink_nl_put_handle (msg, devlink); +if (err) + goto nla_put_failure; + + cfgparam_attr =nla_nest_start (msg,DEVLINK_ATTR_PERM_CONFIGS ); + +nla_for_each_nested (attr, info->attrs[DEVLINK_ATTR_PERM_CONFIGS ], rem) { + err =nla_parse_nested (tb,DEVLINK_ATTR_MAX , attr, + devlink_nl_policy,NULL ); +if (err) + goto nla_nest_failure; + +if (!tb[DEVLINK_ATTR_PERM_CONFIG_PARAMETER ] || + !tb[DEVLINK_ATTR_PERM_CONFIG_TYPE ] || + !tb[DEVLINK_ATTR_PERM_CONFIG_VALUE ]) +continue ; + + param =nla_get_u32 (tb[DEVLINK_ATTR_PERM_CONFIG_PARAMETER ]); + type =nla_get_u8 (tb[DEVLINK_ATTR_PERM_CONFIG_TYPE ]); +if (param >DEVLINK_PERM_CONFIG_MAX || + type >NLA_TYPE_MAX ) { +continue ; + } + +switch (type) { +case DEVLINK_PERM_CONFIG_TYPE_U8 : + value.value8 = +nla_get_u8 (tb[DEVLINK_ATTR_PERM_CONFIG_VALUE ]); +break ; +case DEVLINK_PERM_CONFIG_TYPE_U16 : + value.value16 = +nla_get_u16 (tb[DEVLINK_ATTR_PERM_CONFIG_VALUE ]); +break ; +case DEVLINK_PERM_CONFIG_TYPE_U32 :
net/core/devlink.c static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb, · line 1828
Quoted 10 lines
net/core/devlink.c +10
-0+ value.value32 = +nla_get_u32 (tb[DEVLINK_ATTR_PERM_CONFIG_VALUE ]); +break ; +default : +continue ; + } + +/* Note if single_param_set fails, that param won't be in +* response msg, so caller will know which param(s) failed to +* set.
No. You should not send the params back on set operation. That is wrong. You should use extact in order to tell anything useful to the user.
Quoted 30 lines
net/core/devlink.c +17
-0+*/ +devlink_nl_single_param_set (msg, devlink, param, type, &value); + } + +nla_nest_end (msg, cfgparam_attr); + +genlmsg_end (msg, hdr); +return genlmsg_reply (msg, info); + +nla_nest_failure: +nla_nest_cancel (msg, cfgparam_attr); +nla_put_failure: +genlmsg_cancel (msg, hdr); +nla_msg_failure: +return err; +} +int devlink_dpipe_match_put(struct
sk_buff*skb,
structdevlink_dpipe_match*match)
{net/core/devlink.c +2
-0@@ -2291,6 +2568,8 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = { [DEVLINK_ATTR_ESWITCH_ENCAP_MODE] = { .type = NLA_U8 }, [DEVLINK_ATTR_DPIPE_TABLE_NAME] = { .type = NLA_NUL_STRING }, [DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED] = { .type = NLA_U8 }, + [DEVLINK_ATTR_PERM_CONFIG_PARAMETER] = { .type = NLA_U32 }, + [DEVLINK_ATTR_PERM_CONFIG_TYPE] = { .type = NLA_U8 }, };static const struct genl_ops devlink_nl_ops[] = {
net/core/devlink.c static const struct genl_ops devlink_nl_ops[] = { · line 2735
Quoted 6 lines
net/core/devlink.c +3
-0@@ -2451,6 +2730,20 @@ static const struct genl_ops devlink_nl_ops[] = { .flags = GENL_ADMIN_PERM, .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, }, + { + .cmd = DEVLINK_CMD_PERM_CONFIG_GET, + .doit = devlink_nl_cmd_perm_config_get_doit,
As I said, you need dumpit.
Quoted 17 lines
net/core/devlink.c +11
-0+ .policy = devlink_nl_policy, + .flags = GENL_ADMIN_PERM, + .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, + }, + { + .cmd = DEVLINK_CMD_PERM_CONFIG_SET, + .doit = devlink_nl_cmd_perm_config_set_doit, + .policy = devlink_nl_policy, + .flags = GENL_ADMIN_PERM, + .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, + }, };static struct genl_family devlink_nl_family__ro_after_init = {Signature · 1 line
2.7.4
Jiri Pirko
maintainerRe: [PATCH net-next v5 02/10] devlink: Adding SR-IOV enablement perm config param
In reply to Steve LinQuoted 22 lines · Mon, Oct 30, 2017 at 03:46:08PM CET, [email protected] wrote:
Adding
DEVLINK_PERM_CONFIG_SRIOV_ENABLEDpermanent config parameter; this parameter controls whether the device advertises the SR-IOV PCI capability. 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-IOVSigned-off-by Steve Lin <[email protected]>Acked-by Andy Gospodarek <[email protected]>---
include/uapi/linux/devlink.h| 18 +++++++++++++++++-net/core/devlink.c| 1 +2 files changed, 18 insertions(+), 1 deletion(-)include/uapi/linux/devlink.h +0
-0@@ -256,8 +256,24 @@ 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 */ +/* Permanent config parameter enable/disable +* DEVLINK_PERM_CONFIG_DISABLE = disable a permanent config parameter +* DEVLINK_PERM_CONFIG_ENBALE = enable a permanent config parameter +*/ +enum devlink_perm_config_enabled { +DEVLINK_PERM_CONFIG_DISABLE , +DEVLINK_PERM_CONFIG_ENABLE , +};
Basically, this is "bool"
Why don't you use some own enum instead of NLA_U*. Like team does for example:
enum team_option_type {
TEAM_OPTION_TYPE_U32,
TEAM_OPTION_TYPE_STRING,
TEAM_OPTION_TYPE_BINARY,
TEAM_OPTION_TYPE_BOOL,
TEAM_OPTION_TYPE_S32,
};include/uapi/linux/devlink.h enum devlink_dpipe_header_id { · line 275
Quoted 9 lines
include/uapi/linux/devlink.h +8
-0+ +/* Permanent config parameters: +* DEVLINK_PERM_CONFIG_SRIOV_ENABLED: Configures whether SR-IOV PCI capability +* is advertised by the 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 ,
Please align "ENABLED" vs "ENABLE".
The rest of devlink code uses "ENABLED"
Quoted 19 lines
include/uapi/linux/devlink.h +1
-0+ __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 v5 06/10] bnxt: Add devlink support for config get/set
In reply to Steve LinQuoted 12 lines · Mon, Oct 30, 2017 at 03:46:12PM CET, [email protected] wrote:
Implements get and set of configuration parameters using new devlink config get/set API. Parameters themselves defined in later patches.
Signed-off-by Steve Lin <[email protected]>Acked-by Andy Gospodarek <[email protected]>---
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 +0
-0
[...]
Quoted 70 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +42
-0+static int bnxt_dl_perm_config_set (struct devlink *devlink, +enum devlink_perm_config_param param, +enum devlink_perm_config_type type, +union devlink_perm_config_value *value, +bool *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 ;}drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +25
-0+ 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 ==DEVLINK_PERM_CONFIG_TYPE_U8 ) { + value_int = value->value8; + }else if (type ==DEVLINK_PERM_CONFIG_TYPE_U16 ) { + value_int = value->value16; + }else if (type ==DEVLINK_PERM_CONFIG_TYPE_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);
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c line 167
Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +10
-0+ }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; +}
I don't like this swissknife approach for setters and getters. It's messy, and hard to read. There should be clean get/set pair function per parameter defined in array.
Something like:
static int bnxt_param_sriov_enabled_get(struct devlink *devlink, bool *p_value)
{
...
}static int bnxt_param_sriov_enabled_set(struct devlink *devlink, bool value,
bool *restart_reqd)
{
...
}static int bnxt_param_num_vf_per_pf_get(struct devlink *devlink, u32 *p_value)
{
...
}static int bnxt_param_num_vf_per_pf_set(struct devlink *devlink, u32 value,
bool *restart_reqd)
{
...
}static const struct devlink_config_param bnxt_params[] = {
DEVLINK_CONFIG_PARAM_BOOL(DEVLINK_PERM_CONFIG_SRIOV_ENABLED,
bnxt_param_sriov_enabled_get,
bnxt_param_sriov_enabled_set),
DEVLINK_CONFIG_PARAM_U32(DEVLINK_PERM_CONFIG_NUM_VF_PER_PF,
bnxt_param_num_vf_per_pf_get,
bnxt_param_num_vf_per_pf_set),
};and then in init:
err = devlink_config_param_register(devlink, bnxt_params,
ARRAY_SIZE(bnxt_params));
The register function will check types against the internal devlink param->type table.
Also, the restart_reqd could be signalized by some pre-defined positive setter return value.
Re: [PATCH net-next v5 01/10] devlink: Add permanent config parameter get/set operations
In reply to Jiri PirkoQuoted 14 lines · Jiri Pirko
Quoted 5 lines · Mon, Oct 30, 2017 at 03:46:07PM CET, [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]>In general, I don't like how you use netlink. Please see the rest of this code. We should do things in the common way. More info inlined.
[...]
Quoted 1 line
Quoted 11 lines
include/uapi/linux/devlink.h enum devlink_dpipe_header_id { · line 267
Quoted 9 lines
include/uapi/linux/devlink.h +9
-0+/* Permanent config parameters */ +enum devlink_perm_config_param { + __DEVLINK_PERM_CONFIG_MAX, +DEVLINK_PERM_CONFIG_MAX = __DEVLINK_PERM_CONFIG_MAX -1 +}; + +/* Permanent config types */ +enum devlink_perm_config_type { +DEVLINK_PERM_CONFIG_TYPE_UNSPEC ,You should not need this. Type should be always specified.
This was an attempt to align enum devlink_perm_config_type with the NLA_* enums in netlink.h, which include the unspecified type. I will remove the unspecified enum, but it seems like having multiple type enums that are not aligned with each other could be problematic.
Quoted 10 lines
include/uapi/linux/devlink.h enum devlink_dpipe_header_id { · line 271
Quoted 6 lines
include/uapi/linux/devlink.h +4
-0+DEVLINK_PERM_CONFIG_TYPE_U8 , +DEVLINK_PERM_CONFIG_TYPE_U16 , + DEVLINK_PERM_CONFIG_TYPE_U32, +};This definitelly should not be in uapi header.
Quoted 9 lines
include/uapi/linux/devlink.h enum devlink_dpipe_header_id { · line 278
Quoted 7 lines
include/uapi/linux/devlink.h +7
-0+ +/* Permanent config value */ +union devlink_perm_config_value { +__u8 value8; +__u16 value16; +__u32 value32; +};This definitelly should not be in uapi header.
Ok, will move these.
Quoted 44 lines
Quoted 5 lines
+
#endif /* _UAPI_LINUX_DEVLINK_H_ */[...]
Quoted 21 lines
net/core/devlink.c +21
-0+static int devlink_nl_config_get_fill (struct sk_buff *msg, +struct devlink *devlink, +enum devlink_command cmd, +struct genl_info *info) +{ +struct nlattr *tb[DEVLINK_ATTR_MAX +1 ]; +enum devlink_perm_config_param param; +enum devlink_perm_config_type type; +struct nlattr *cfgparam_attr; +struct nlattr *attr; +void *hdr; +int err; +int rem; + + hdr =genlmsg_put (msg, info->snd_portid, info->snd_seq, + &devlink_nl_family,0 , cmd); +if (!hdr) +return -EMSGSIZE ; + + err =devlink_nl_put_handle (msg, devlink); +if (err)net/core/devlink.c static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb, · line 1656
Quoted 10 lines
net/core/devlink.c +10
-0+ goto nla_put_failure; + +if (!info->attrs[DEVLINK_ATTR_PERM_CONFIGS ]) { + err = -EINVAL ; + goto nla_put_failure; + } + + cfgparam_attr =nla_nest_start (msg,DEVLINK_ATTR_PERM_CONFIGS ); + + nla_for_each_nested(attr, info->attrs[DEVLINK_ATTR_PERM_CONFIGS],Okay. So I have to know what is in kernel in order to get the value.
Quoted 1 line
We need a dump operation. In fact, why can't we just have dump operation?
Ok, I can add a dump operation.
Quoted 15 lines
Quoted 4 lines
net/core/devlink.c +1
-0+ rem) {net/core/devlink.c static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb, · line 1667
Quoted 10 lines
net/core/devlink.c +10
-0+ err =nla_parse_nested (tb,DEVLINK_ATTR_MAX , attr, + devlink_nl_policy,NULL ); +if (err) + goto nla_nest_failure; +if (!tb[DEVLINK_ATTR_PERM_CONFIG_PARAMETER ] || + !tb[DEVLINK_ATTR_PERM_CONFIG_TYPE ]) +continue ; + + param =nla_get_u32 (tb[DEVLINK_ATTR_PERM_CONFIG_PARAMETER ]); + type =nla_get_u8 (tb[DEVLINK_ATTR_PERM_CONFIG_TYPE ]);
Quoted 2 lines
So to get parameter, I have to specify a type? What if I specify wrong type? That is wrong. The type should be read attr for get.
For set, seems like the user would need to know and set the type. So, I was just doing the same for get(). But I can make the type a read attribute for get.
Quoted 21 lines
You should have a param -> type table and always use that.
Quoted 17 lines
net/core/devlink.c +17
-0+if (param >DEVLINK_PERM_CONFIG_MAX || + type >NLA_TYPE_MAX ) { +continue ; + } +/* Note if single_param_get fails, that param won't be in +* response msg, so caller will know which param(s) failed to +* get. +*/ +devlink_nl_single_param_get (msg, devlink, param, type); + } + +nla_nest_end (msg, cfgparam_attr); + +genlmsg_end (msg, hdr); +return 0 ; + +nla_nest_failure:
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ nla_nest_cancel(msg, cfgparam_attr); +nla_put_failure:You should make this multipart aware. If config parameters won't fit into a single skb, you have to allocate another one. See
devlink_dpipe_tables_fillas an example how to do it. It is important to have this from the beginning as the userspace knows to expect multipart message.
In a response to a similar comment from v2, I tried to describe why I felt multipart messages wouldn't be required. There was no response to my reply, so I thought that my argument was accepted. Apparently not, so I will add multipart support.
Quoted 46 lines
Quoted 46 lines
net/core/devlink.c +43
-0+genlmsg_cancel (msg, hdr); +return err; +} + +static int devlink_nl_cmd_perm_config_get_doit (struct sk_buff *skb, +struct genl_info *info) +{ +struct devlink *devlink = info->user_ptr[0 ]; +struct sk_buff *msg; +int err; + +if (!devlink->ops || !devlink->ops->perm_config_get) +return -EOPNOTSUPP ; + + msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); +if (!msg) +return -ENOMEM ; + + err =devlink_nl_config_get_fill (msg, devlink, +DEVLINK_CMD_PERM_CONFIG_GET , info); + +if (err) { +nlmsg_free (msg); +return err; + } + +return genlmsg_reply (msg, info); +} + +static int devlink_nl_single_param_set (struct sk_buff *msg, +struct devlink *devlink, +enum devlink_perm_config_param param, +enum devlink_perm_config_type type, +union devlink_perm_config_value *value) +{ +const struct devlink_ops *ops = devlink->ops; +struct nlattr *cfgparam_attr; +bool need_restart; +int err; + +/* Now set parameter */ + err = ops->perm_config_set (devlink, param, type, value, &need_restart); +if (err)
Quoted 8 lines
net/core/devlink.c static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb, · line 1734
Quoted 5 lines
net/core/devlink.c +5
-0+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) {You should propagate this out so the caller would fill it to the message. This is a global thing, not per-param, shoult not be nested.
The idea here was that some parameters may require a restart and some may not. By reporting it per param, the caller knows which parameter have taken effect immediately.
But, per your comment below, I will no longer report back which parameters were successfully set (and thus also not return the restart_required information), and instead just put any extra needed information into extack.
Quoted 92 lines
Quoted 92 lines
net/core/devlink.c +89
-0+ err =nla_put_flag (msg, +DEVLINK_ATTR_PERM_CONFIG_RESTART_REQUIRED ); +if (err) + goto nest_fail; + } + +/* Since set was successful, write attr back to msg */ + err =nla_put_u32 (msg,DEVLINK_ATTR_PERM_CONFIG_PARAMETER , param); +if (err) + goto nest_fail; + +nla_nest_end (msg, cfgparam_attr); + +return 0 ; + +nest_fail: +nla_nest_cancel (msg, cfgparam_attr); +return err; +} + +static int devlink_nl_cmd_perm_config_set_doit (struct sk_buff *skb, +struct genl_info *info) +{ +struct devlink *devlink = info->user_ptr[0 ]; +struct nlattr *tb[DEVLINK_ATTR_MAX +1 ]; +union devlink_perm_config_value value; +enum devlink_perm_config_param param; +enum devlink_perm_config_type type; +struct nlattr *cfgparam_attr; +struct sk_buff *msg; +struct nlattr *attr; +void *hdr; +int rem; +int err; + +if (!devlink->ops || !devlink->ops->perm_config_get || + !devlink->ops->perm_config_set) +return -EOPNOTSUPP ; + + msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); +if (!msg) +return -ENOMEM ; + + hdr =genlmsg_put (msg, info->snd_portid, info->snd_seq, + &devlink_nl_family,0 ,DEVLINK_CMD_PERM_CONFIG_SET ); +if (!hdr) { + err = -EMSGSIZE ; + goto nla_msg_failure; + } + + err =devlink_nl_put_handle (msg, devlink); +if (err) + goto nla_put_failure; + + cfgparam_attr =nla_nest_start (msg,DEVLINK_ATTR_PERM_CONFIGS ); + +nla_for_each_nested (attr, info->attrs[DEVLINK_ATTR_PERM_CONFIGS ], rem) { + err =nla_parse_nested (tb,DEVLINK_ATTR_MAX , attr, + devlink_nl_policy,NULL ); +if (err) + goto nla_nest_failure; + +if (!tb[DEVLINK_ATTR_PERM_CONFIG_PARAMETER ] || + !tb[DEVLINK_ATTR_PERM_CONFIG_TYPE ] || + !tb[DEVLINK_ATTR_PERM_CONFIG_VALUE ]) +continue ; + + param =nla_get_u32 (tb[DEVLINK_ATTR_PERM_CONFIG_PARAMETER ]); + type =nla_get_u8 (tb[DEVLINK_ATTR_PERM_CONFIG_TYPE ]); +if (param >DEVLINK_PERM_CONFIG_MAX || + type >NLA_TYPE_MAX ) { +continue ; + } + +switch (type) { +case DEVLINK_PERM_CONFIG_TYPE_U8 : + value.value8 = +nla_get_u8 (tb[DEVLINK_ATTR_PERM_CONFIG_VALUE ]); +break ; +case DEVLINK_PERM_CONFIG_TYPE_U16 : + value.value16 = +nla_get_u16 (tb[DEVLINK_ATTR_PERM_CONFIG_VALUE ]); +break ; +case DEVLINK_PERM_CONFIG_TYPE_U32 : + value.value32 = +nla_get_u32 (tb[DEVLINK_ATTR_PERM_CONFIG_VALUE ]); +break ; +default : +continue ;
Quoted 8 lines
net/core/devlink.c static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb, · line 1828
Quoted 5 lines
net/core/devlink.c +5
-0+ } + +/* Note if single_param_set fails, that param won't be in +* response msg, so caller will know which param(s) failed to +* set. No. You should not send the params back on set operation. That is wrong. You should use extact in order to tell anything useful to the user.
Ok, see above.
Quoted 60 lines
Quoted 32 lines
net/core/devlink.c +17
-0+*/ +devlink_nl_single_param_set (msg, devlink, param, type, &value); + } + +nla_nest_end (msg, cfgparam_attr); + +genlmsg_end (msg, hdr); +return genlmsg_reply (msg, info); + +nla_nest_failure: +nla_nest_cancel (msg, cfgparam_attr); +nla_put_failure: +genlmsg_cancel (msg, hdr); +nla_msg_failure: +return err; +} +int devlink_dpipe_match_put(struct
sk_buff*skb,
structdevlink_dpipe_match*match)
{net/core/devlink.c +2
-0@@ -2291,6 +2568,8 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = { [DEVLINK_ATTR_ESWITCH_ENCAP_MODE] = { .type = NLA_U8 }, [DEVLINK_ATTR_DPIPE_TABLE_NAME] = { .type = NLA_NUL_STRING }, [DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED] = { .type = NLA_U8 }, + [DEVLINK_ATTR_PERM_CONFIG_PARAMETER] = { .type = NLA_U32 }, + [DEVLINK_ATTR_PERM_CONFIG_TYPE] = { .type = NLA_U8 }, };static const struct genl_ops devlink_nl_ops[] = {net/core/devlink.c static const struct genl_ops devlink_nl_ops[] = { · line 2735
Quoted 6 lines
net/core/devlink.c +3
-0@@ -2451,6 +2730,20 @@ static const struct genl_ops devlink_nl_ops[] = { .flags = GENL_ADMIN_PERM, .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, }, + { + .cmd = DEVLINK_CMD_PERM_CONFIG_GET, + .doit = devlink_nl_cmd_perm_config_get_doit,As I said, you need dumpit.
Quoted 17 lines
net/core/devlink.c +11
-1+ .policy = devlink_nl_policy, + .flags = GENL_ADMIN_PERM, + .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, + }, + { + .cmd = DEVLINK_CMD_PERM_CONFIG_SET, + .doit = devlink_nl_cmd_perm_config_set_doit, + .policy = devlink_nl_policy, + .flags = GENL_ADMIN_PERM, + .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, + }, };static struct genl_family devlink_nl_family__ro_after_init = { --2.7.4
Re: [PATCH net-next v5 02/10] devlink: Adding SR-IOV enablement perm config param
In reply to Jiri PirkoQuoted 40 lines · Jiri Pirko
Quoted 22 lines · Mon, Oct 30, 2017 at 03:46:08PM CET, [email protected] wrote:
Adding
DEVLINK_PERM_CONFIG_SRIOV_ENABLEDpermanent config parameter; this parameter controls whether the device advertises the SR-IOV PCI capability. 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-IOVSigned-off-by Steve Lin <[email protected]>Acked-by Andy Gospodarek <[email protected]>---
include/uapi/linux/devlink.h| 18 +++++++++++++++++-net/core/devlink.c| 1 +2 files changed, 18 insertions(+), 1 deletion(-)include/uapi/linux/devlink.h +0
-0@@ -256,8 +256,24 @@ 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 */ +/* Permanent config parameter enable/disable +* DEVLINK_PERM_CONFIG_DISABLE = disable a permanent config parameter +* DEVLINK_PERM_CONFIG_ENBALE = enable a permanent config parameter +*/ +enum devlink_perm_config_enabled { +DEVLINK_PERM_CONFIG_DISABLE , +DEVLINK_PERM_CONFIG_ENABLE , +};Basically, this is "bool"
Why don't you use some own enum instead of NLA_U*. Like team does for example:
Quoted 9 lines
enum team_option_type {
TEAM_OPTION_TYPE_U32,
TEAM_OPTION_TYPE_STRING,
TEAM_OPTION_TYPE_BINARY,
TEAM_OPTION_TYPE_BOOL,
TEAM_OPTION_TYPE_S32,
};I had added enum devlink_perm_config_type in v5 based on your comments in v4 - I will add BOOL if it helps clarity.
Quoted 15 lines
include/uapi/linux/devlink.h enum devlink_dpipe_header_id { · line 275
Quoted 10 lines
include/uapi/linux/devlink.h +8
-0+ +/* Permanent config parameters: +* DEVLINK_PERM_CONFIG_SRIOV_ENABLED: Configures whether SR-IOV PCI capability +* is advertised by the 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 ,Please align "ENABLED" vs "ENABLE".
The rest of devlink code uses "ENABLED"
Ok.
Quoted 20 lines
Quoted 20 lines
include/uapi/linux/devlink.h +1
-0+ __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
Re: [PATCH net-next v5 06/10] bnxt: Add devlink support for config get/set
In reply to Jiri PirkoQuoted 92 lines · Jiri Pirko
Quoted 12 lines · Mon, Oct 30, 2017 at 03:46:12PM CET, [email protected] wrote:
Implements get and set of configuration parameters using new devlink config get/set API. Parameters themselves defined in later patches.
Signed-off-by Steve Lin <[email protected]>Acked-by Andy Gospodarek <[email protected]>---
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 +0
-0[...]
Quoted 76 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +73
-0+static int bnxt_dl_perm_config_set (struct devlink *devlink, +enum devlink_perm_config_param param, +enum devlink_perm_config_type type, +union devlink_perm_config_value *value, +bool *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 ==DEVLINK_PERM_CONFIG_TYPE_U8 ) { + value_int = value->value8; + }else if (type ==DEVLINK_PERM_CONFIG_TYPE_U16 ) { + value_int = value->value16; + }else if (type ==DEVLINK_PERM_CONFIG_TYPE_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 */
Quoted 8 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c line 167
Quoted 4 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +4
-0+ *restart_reqd =1 ; + +return ret; +}I don't like this swissknife approach for setters and getters. It's messy, and hard to read. There should be clean get/set pair function per parameter defined in array.
The advantage of the swiss kinfe approach is that you don't have a large number of almost-identical functions (i.e. any "set" that operates on a u32 will be doing essentially the exact same thing) in the driver, which could lead to code bloat and also make it harder to catch errors (since any bug that may creep in during the copy/paste to make so many functions will only be caught when that specific parameter is set, rather than when any parameter is set).
In general, I very much appreciate the thorough review. I do feel, though, like some of this basic architectural stuff could have been addressed more efficiently in v1 or v2, rather than v5. I admit that when the comments to v4 included suggestions like removing extra spaces in the commit message, I was thinking that we were close to reaching consensus. :)
I just want to make sure that you feel that the overall goal of this effort is worthwhile - I will make the changes you've suggested here and in the other replies to v5, but I am hopeful that v6 does not result in another set of big architectural changes.
Quoted 35 lines
Something like:
static int
bnxt_param_sriov_enabled_get(struct devlink *devlink, bool *p_value){ ... }static int bnxt_param_sriov_enabled_set(struct devlink *devlink, bool value,
bool*restart_reqd){ ... }static int
bnxt_param_num_vf_per_pf_get(struct devlink *devlink, u32 *p_value){ ... }static int bnxt_param_num_vf_per_pf_set(struct devlink *devlink, u32 value,
bool*restart_reqd){ ... }static const struct devlink_config_param bnxt_params[] = { DEVLINK_CONFIG_PARAM_BOOL(DEVLINK_PERM_CONFIG_SRIOV_ENABLED, bnxt_param_sriov_enabled_get, bnxt_param_sriov_enabled_set), DEVLINK_CONFIG_PARAM_U32(DEVLINK_PERM_CONFIG_NUM_VF_PER_PF, bnxt_param_num_vf_per_pf_get, bnxt_param_num_vf_per_pf_set), };and then in init:
Quoted 8 lines
err = devlink_config_param_register(devlink,
bnxt_params,ARRAY_SIZE(bnxt_params));The register function will check types against the internal devlink
param->typetable.Also, the
restart_reqdcould be signalized by some pre-defined positive setter return value.
Understood - like I said, I thought it preferable to use a global getter/setter rather than one for each individual parameter, but I will make the requested change, in hopes of reaching a conclusion soon.
Re: [PATCH net-next v5 01/10] devlink: Add permanent config parameter get/set operations
In reply to Jiri PirkoQuoted 6 lines · Jiri Pirko
net/core/devlink.c static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb, · line 1734
Quoted 3 lines
net/core/devlink.c +3
-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) {You should propagate this out so the caller would fill it to the message. This is a global thing, not per-param, shoult not be nested.
Right, I think Jiri has already asked for this but I feel like we should provide the ability to query running/pending configurations independently. I don't see it in this patch set?
I'm not sure what the status of the reconfig trigger patches for mlxsw is, but we actually may need 3 config sets:
- current/runtime configurable,
- requiring soft reset of the device/driver reinit;
- requiring hard reset/set on boot.
Secondly, IMHO calling set/get parameters "permanent" is a bit backwards. One device may not be able to change max VF counts or MSIX allocation without full reinit of PCIe blocks, but for others soft reset is more than enough. Port splitting is another example. For NICs port splitting at runtime is usually not a priority in HW/FW development, so some form of reset is generally required, while switches can split a port at runtime. IOW we should define parameters without assigning them to config sets in the ABI itself. And also we should make it in a way which will allow existing parameters to be reused in permanent/sort reset required/runtime modes.
Does that make sense?
Jiri Pirko
maintainerRe: [PATCH net-next v5 02/10] devlink: Adding SR-IOV enablement perm config param
In reply to Steve LinQuoted 51 lines · Mon, Oct 30, 2017 at 09:17:16PM CET, [email protected] wrote:
Quoted 40 lines · Jiri Pirko
Quoted 22 lines · Mon, Oct 30, 2017 at 03:46:08PM CET, [email protected] wrote:
Adding
DEVLINK_PERM_CONFIG_SRIOV_ENABLEDpermanent config parameter; this parameter controls whether the device advertises the SR-IOV PCI capability. 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-IOVSigned-off-by Steve Lin <[email protected]>Acked-by Andy Gospodarek <[email protected]>---
include/uapi/linux/devlink.h| 18 +++++++++++++++++-net/core/devlink.c| 1 +2 files changed, 18 insertions(+), 1 deletion(-)include/uapi/linux/devlink.h +0
-0@@ -256,8 +256,24 @@ 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 */ +/* Permanent config parameter enable/disable +* DEVLINK_PERM_CONFIG_DISABLE = disable a permanent config parameter +* DEVLINK_PERM_CONFIG_ENBALE = enable a permanent config parameter +*/ +enum devlink_perm_config_enabled { +DEVLINK_PERM_CONFIG_DISABLE , +DEVLINK_PERM_CONFIG_ENABLE , +};Basically, this is "bool"
Why don't you use some own enum instead of NLA_U*. Like team does for example:
Quoted 9 lines
enum team_option_type { TEAM_OPTION_TYPE_U32, TEAM_OPTION_TYPE_STRING, TEAM_OPTION_TYPE_BINARY, TEAM_OPTION_TYPE_BOOL, TEAM_OPTION_TYPE_S32, };
Quoted 2 lines
I had added enum
devlink_perm_config_typein v5 based on your comments in v4 - I will add BOOL if it helps clarity.
But you did not use it in uapi for some reason. That is what I suggest.
Quoted 39 lines
Quoted 16 lines
include/uapi/linux/devlink.h enum devlink_dpipe_header_id { · line 275
Quoted 11 lines
include/uapi/linux/devlink.h +8
-0+ +/* Permanent config parameters: +* DEVLINK_PERM_CONFIG_SRIOV_ENABLED: Configures whether SR-IOV PCI capability +* is advertised by the 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 ,Please align "ENABLED" vs "ENABLE".
The rest of devlink code uses "ENABLED"Ok.
Quoted 20 lines
Quoted 20 lines
include/uapi/linux/devlink.h +1
-0+ __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 v5 01/10] devlink: Add permanent config parameter get/set operations
In reply to Jakub KicinskiQuoted 11 lines · Mon, Oct 30, 2017 at 11:12:13PM CET, [email protected] wrote:
Quoted 6 lines · Jiri Pirko
net/core/devlink.c static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb, · line 1734
Quoted 3 lines
net/core/devlink.c +3
-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) {You should propagate this out so the caller would fill it to the message. This is a global thing, not per-param, shoult not be nested.
Right, I think Jiri has already asked for this but I feel like we should provide the ability to query running/pending configurations independently. I don't see it in this patch set?
I don't see it either :/
Quoted 18 lines
I'm not sure what the status of the reconfig trigger patches for mlxsw is, but we actually may need 3 config sets:
- current/runtime configurable,
- requiring soft reset of the device/driver reinit;
- requiring hard reset/set on boot.Secondly, IMHO calling set/get parameters "permanent" is a bit backwards. One device may not be able to change max VF counts or MSIX allocation without full reinit of PCIe blocks, but for others soft reset is more than enough. Port splitting is another example. For NICs port splitting at runtime is usually not a priority in HW/FW development, so some form of reset is generally required, while switches can split a port at runtime. IOW we should define parameters without assigning them to config sets in the ABI itself. And also we should make it in a way which will allow existing parameters to be reused in permanent/sort reset required/runtime modes.
Quoted 1 line
Does that make sense?
"IOW we should define parameters without assigning them to config sets in the ABI itself" - I don't understand what do you mean by this.
Jiri Pirko
maintainerRe: [PATCH net-next v5 06/10] bnxt: Add devlink support for config get/set
In reply to Steve LinQuoted 102 lines · Mon, Oct 30, 2017 at 09:20:17PM CET, [email protected] wrote:
Quoted 92 lines · Jiri Pirko
Quoted 12 lines · Mon, Oct 30, 2017 at 03:46:12PM CET, [email protected] wrote:
Implements get and set of configuration parameters using new devlink config get/set API. Parameters themselves defined in later patches.
Signed-off-by Steve Lin <[email protected]>Acked-by Andy Gospodarek <[email protected]>---
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 +0
-0[...]
Quoted 76 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +73
-0+static int bnxt_dl_perm_config_set (struct devlink *devlink, +enum devlink_perm_config_param param, +enum devlink_perm_config_type type, +union devlink_perm_config_value *value, +bool *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 ==DEVLINK_PERM_CONFIG_TYPE_U8 ) { + value_int = value->value8; + }else if (type ==DEVLINK_PERM_CONFIG_TYPE_U16 ) { + value_int = value->value16; + }else if (type ==DEVLINK_PERM_CONFIG_TYPE_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 */ Quoted 8 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c line 167
Quoted 4 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +4
-0+ *restart_reqd =1 ; + +return ret; +}I don't like this swissknife approach for setters and getters. It's messy, and hard to read. There should be clean get/set pair function per parameter defined in array.
Quoted 7 lines
The advantage of the swiss kinfe approach is that you don't have a large number of almost-identical functions (i.e. any "set" that operates on a u32 will be doing essentially the exact same thing) in the driver, which could lead to code bloat and also make it harder to catch errors (since any bug that may creep in during the copy/paste to make so many functions will only be caught when that specific parameter is set, rather than when any parameter is set).
You can always do some common functions to do the work. But if gives the driver freedom, unlike the swissknife approach.
Quoted 7 lines
In general, I very much appreciate the thorough review. I do feel, though, like some of this basic architectural stuff could have been addressed more efficiently in v1 or v2, rather than v5. I admit that when the comments to v4 included suggestions like removing extra spaces in the commit message, I was thinking that we were close to reaching consensus. :)
Yeah, I noticed this just now.
Quoted 5 lines
I just want to make sure that you feel that the overall goal of this effort is worthwhile - I will make the changes you've suggested here and in the other replies to v5, but I am hopeful that v6 does not result in another set of big architectural changes.
Hopefully.
Quoted 49 lines
Quoted 36 lines
Something like:
static int
bnxt_param_sriov_enabled_get(struct devlink *devlink, bool *p_value){ ... }static int bnxt_param_sriov_enabled_set(struct devlink *devlink, bool value,
bool*restart_reqd){ ... }static int
bnxt_param_num_vf_per_pf_get(struct devlink *devlink, u32 *p_value){ ... }static int bnxt_param_num_vf_per_pf_set(struct devlink *devlink, u32 value,
bool*restart_reqd){ ... }static const struct devlink_config_param bnxt_params[] = { DEVLINK_CONFIG_PARAM_BOOL(DEVLINK_PERM_CONFIG_SRIOV_ENABLED, bnxt_param_sriov_enabled_get, bnxt_param_sriov_enabled_set), DEVLINK_CONFIG_PARAM_U32(DEVLINK_PERM_CONFIG_NUM_VF_PER_PF, bnxt_param_num_vf_per_pf_get, bnxt_param_num_vf_per_pf_set), };and then in init:
Quoted 8 lines
err = devlink_config_param_register(devlink,
bnxt_params,ARRAY_SIZE(bnxt_params));The register function will check types against the internal devlink
param->typetable.Also, the
restart_reqdcould be signalized by some pre-defined positive setter return value.Understood - like I said, I thought it preferable to use a global getter/setter rather than one for each individual parameter, but I will make the requested change, in hopes of reaching a conclusion soon.
Re: [PATCH net-next v5 01/10] devlink: Add permanent config parameter get/set operations
In reply to Jiri PirkoQuoted 19 lines · Jiri Pirko
Quoted 18 lines · Mon, Oct 30, 2017 at 11:12:13PM CET, [email protected] wrote:
On Mon, 30 Oct 2017 18:03:01 +0100, Jiri Pirko wrote:
I'm not sure what the status of the reconfig trigger patches for mlxsw is, but we actually may need 3 config sets:
- current/runtime configurable,
- requiring soft reset of the device/driver reinit;
- requiring hard reset/set on boot.Secondly, IMHO calling set/get parameters "permanent" is a bit backwards. One device may not be able to change max VF counts or MSIX allocation without full reinit of PCIe blocks, but for others soft reset is more than enough. Port splitting is another example. For NICs port splitting at runtime is usually not a priority in HW/FW development, so some form of reset is generally required, while switches can split a port at runtime. IOW we should define parameters without assigning them to config sets in the ABI itself. And also we should make it in a way which will allow existing parameters to be reused in permanent/sort reset required/runtime modes.
Quoted 4 lines
Quoted 1 line
Does that make sense?
"IOW we should define parameters without assigning them to config sets in the ABI itself" - I don't understand what do you mean by this.
OK, whether the setting is permanent or not - is device specific.
I'm basically asking to remove the "PERM" from the names and indicate which config set (of the 3 enumerated above) user wants it applied in a separate attribute.
Jiri Pirko
maintainerRe: [PATCH net-next v5 01/10] devlink: Add permanent config parameter get/set operations
Quoted 22 lines · Tue, Oct 31, 2017 at 09:04:18AM CET, [email protected] wrote:
Quoted 21 lines · Jiri Pirko
Quoted 19 lines · Mon, Oct 30, 2017 at 11:12:13PM CET, [email protected] wrote:
On Mon, 30 Oct 2017 18:03:01 +0100, Jiri Pirko wrote:
I'm not sure what the status of the reconfig trigger patches for mlxsw is, but we actually may need 3 config sets:
- current/runtime configurable,
- requiring soft reset of the device/driver reinit;
- requiring hard reset/set on boot.Secondly, IMHO calling set/get parameters "permanent" is a bit backwards. One device may not be able to change max VF counts or MSIX allocation without full reinit of PCIe blocks, but for others soft reset is more than enough. Port splitting is another example. For NICs port splitting at runtime is usually not a priority in HW/FW development, so some form of reset is generally required, while switches can split a port at runtime. IOW we should define parameters without assigning them to config sets in the ABI itself. And also we should make it in a way which will allow existing parameters to be reused in permanent/sort reset required/runtime modes.
Does that make sense?
Quoted 8 lines
Quoted 2 lines
"IOW we should define parameters without assigning them to config sets in the ABI itself" - I don't understand what do you mean by this.
OK, whether the setting is permanent or not - is device specific.
I'm basically asking to remove the "PERM" from the names and indicate which config set (of the 3 enumerated above) user wants it applied in a separate attribute.
Yesh, would be good if driver could indicate which option is of what type and devlink should expose this information to the user.
But it probably should be flags. Driver may provide possibility to configure for example VF count as runtime and also permanent option. User should pass the correct flags along the set message so the driver knows what to set. Makes sense?
Re: [PATCH net-next v5 01/10] devlink: Add permanent config parameter get/set operations
Quoted 26 lines · Jiri Pirko
Quoted 25 lines · Tue, Oct 31, 2017 at 09:04:18AM CET, [email protected] wrote:
Quoted 23 lines · Jiri Pirko
Quoted 18 lines · Mon, Oct 30, 2017 at 11:12:13PM CET, [email protected] wrote:
On Mon, 30 Oct 2017 18:03:01 +0100, Jiri Pirko wrote:
I'm not sure what the status of the reconfig trigger patches for mlxsw is, but we actually may need 3 config sets:
- current/runtime configurable,
- requiring soft reset of the device/driver reinit;
- requiring hard reset/set on boot.Secondly, IMHO calling set/get parameters "permanent" is a bit backwards. One device may not be able to change max VF counts or MSIX allocation without full reinit of PCIe blocks, but for others soft reset is more than enough. Port splitting is another example. For NICs port splitting at runtime is usually not a priority in HW/FW development, so some form of reset is generally required, while switches can split a port at runtime. IOW we should define parameters without assigning them to config sets in the ABI itself. And also we should make it in a way which will allow existing parameters to be reused in permanent/sort reset required/runtime modes.
Quoted 1 line
Does that make sense?
"IOW we should define parameters without assigning them to config sets in the ABI itself" - I don't understand what do you mean by this.
Quoted 8 lines
Quoted 5 lines
OK, whether the setting is permanent or not - is device specific.
I'm basically asking to remove the "PERM" from the names and indicate which config set (of the 3 enumerated above) user wants it applied in a separate attribute.
Yesh, would be good if driver could indicate which option is of what type and devlink should expose this information to the user.
Sounds like there would be one dump with all settings each marked with a flag indicating if it's permanent/init time or run time. How would users check the current vs pending configurations?
Quoted 4 lines
But it probably should be flags. Driver may provide possibility to configure for example VF count as runtime and also permanent option. User should pass the correct flags along the set message so the driver knows what to set. Makes sense?
SGTM. And we can also extend port splitting to take the same flags? :)