pds_fwctl: fwctl for AMD/Pensando core devices
Subsystems (7)
v5 cover pds_fwctl: fwctl for AMD/Pensando core devices
Following along from Jason's work [1] we have our initial patchset for pds_fwctl - an auxiliary_bus driver for supporting fwctl through the pds_core driver and its PDS core device.
The PDS core is PCI device that is separate and distinct from the ionic Eth device and from the other PCI devices that can be supported by the AMD/Pensando DSC. It is used by pds_vdpa and pds_vfio_pci to coordinate/communicate with the FW for setting up their services.
Until now the DSC's basic configurations for defining what devices to support and for getting low-level device debug information have been through internal commands not available from the host side, requiring access into the DSC's own OS. Adding the fwctl service allows us to start bringing these capabilities up into the host, but they don't replace the existing function-specific tools. For example, these are things that make the Eth PCI device appear on the PCI bus, while the tuning of the specific Eth features still go through the standard ethtool/devlink/ip/etc tools.
The first two patches are a bit of clean up for pds_core's add and delete of auxiliary_devices. Those are followed by a patch to add the new pds_core.fwctl auxiliary_device. This is only supported by the pds_core PF and not on any VFs.
The remaining patches add the pds_fwctl driver framework and then fill in the details for the fwctl services.
[1] https://lore.kernel.org/netdev/[email protected]/
v5:
- fix missing variable declaration
- fix kernel-doc complaint
v4: https://lore.kernel.org/netdev/[email protected]/
- fix commit description for better imperative (David)
- fix comment wording (David)
- add kdoc comment on struct fwctl_info_pds (David)
- #include <linux/bitfield.h> (Jason)
- fix for error pointer check in pdsfc_validate_rpc() (Brett and Dan)
- initialize pdsfc->caps
- add translation of FW opcode scope to fwctl scope
- several doc edits (David)
- added received Reviewd-by tags
v3: https://lore.kernel.org/netdev/[email protected]/
- rebase on Jason's tree
- better comment on "an error if there is no auxbus device support" (Jonathan)
- don't call pdsc_auxbus_dev_del() if pdsc_auxbus_dev_add() failed (Jonathan)
- struct pdsc *pdsc; is unnecessary in struct pdsfc_dev (Jonathan)
- remove unused UID field in pdsfc_info (Jonathan, Jason)
- change "Word boundary padding" to "Reserved" (Jonathan)
- remove the remaining use of cleanup pattern
- don't lose err from pds_client_adminq_cmd() in pdsfc_identify() (Jason)
- comment on pds_fwctl_ident.features (Jonathan)
- change noisy dev_errs to dev_dbg and remove a couple unnecessary ones (Jonathan, Jason)
- no cast needed on struct fwctl_rpc_pds *rpc = (struct fwctl_rpc_pds *)in (Jonathan)
- more labels and reverse order for cleanup in pdsfc_fw_rpc (Jonathan)
- __counted_by_le() on struct pds_fwctl_query_data (Jonathan)
- other comment comments on new structs (Jonathan)
- use FIELD_GET (Jason)
- Use __aligned_u64 in the uapi headers (Jason)
- call fwctl a subsystem in Docs (Jonathan)
- clean up text around endpoints in Docs (Jonathan)
v2: https://lore.kernel.org/netdev/[email protected]/
- removed the RFC tag
- add a patch to make pdsc_auxbus_dev_del() a void type (Jonathan)
- fix up error handling if pdsc_auxbus_dev_add() fails in probe (Jonathan)
- fix auxiliary spelling in commit subject header (Jonathan)
- clean up of code around use of __free() gizmo (Jonathan, David)
- removed extra whitespace and dev_xxx() calls (Leon)
- copy ident info from DMA and release DMA memory in probe (Jonathan)
- use dev_err_probe() (Jonathan)
- add counted_by_le(num_entries) (Jonathan, David)
- convert num_entries from __le32 to host in get_endpoints() (Jonathan)
- remove unnecessary variable inits (Jonathan, Leon)
v1: https://lore.kernel.org/netdev/[email protected]/
Brett Creeley (1):
pds_fwctl: add rpc and query support
Shannon Nelson (5):
pds_core: make pdsc_auxbus_dev_del() void
pds_core: specify auxiliary_device to be created
pds_core: add new fwctl auxiliary_device
pds_fwctl: initial driver framework
pds_fwctl: add Documentation entries
Documentation/userspace-api/fwctl/fwctl.rst | 1 + Documentation/userspace-api/fwctl/index.rst | 1 + .../userspace-api/fwctl/pds_fwctl.rst | 46 ++ MAINTAINERS | 7 + drivers/fwctl/Kconfig | 10 + drivers/fwctl/Makefile | 1 + drivers/fwctl/pds/Makefile | 4 + drivers/fwctl/pds/main.c | 539 ++++++++++++++++++ drivers/net/ethernet/amd/pds_core/auxbus.c | 44 +- drivers/net/ethernet/amd/pds_core/core.c | 7 + drivers/net/ethernet/amd/pds_core/core.h | 8 +- drivers/net/ethernet/amd/pds_core/devlink.c | 7 +- drivers/net/ethernet/amd/pds_core/main.c | 25 +- include/linux/pds/pds_adminq.h | 277 +++++++++ include/linux/pds/pds_common.h | 2 + include/uapi/fwctl/fwctl.h | 1 + include/uapi/fwctl/pds.h | 62 ++ 17 files changed, 1008 insertions(+), 34 deletions(-) create mode 100644 Documentation/userspace-api/fwctl/pds_fwctl.rst create mode 100644 drivers/fwctl/pds/Makefile create mode 100644 drivers/fwctl/pds/main.c create mode 100644 include/uapi/fwctl/pds.h
Signature · 1 line
2.17.1
PATCH v5 1/6 pds_core: make pdsc_auxbus_dev_del() void
Since there really is no useful return, advertising a return value is rather misleading. Make pdsc_auxbus_dev_del() a void function.
--- drivers/net/ethernet/amd/pds_core/auxbus.c | 7 +------ drivers/net/ethernet/amd/pds_core/core.h | 2 +- drivers/net/ethernet/amd/pds_core/devlink.c | 6 ++++-- 3 files changed, 6 insertions(+), 9 deletions(-)
drivers/net/ethernet/amd/pds_core/auxbus.c +1 -6
@@ -175,13 +175,9 @@ static struct pds_auxiliary_dev *pdsc_auxbus_dev_register(struct pdsc *cf,return padev; } -int pdsc_auxbus_dev_del (struct pdsc *cf,struct pdsc *pf) +void pdsc_auxbus_dev_del (struct pdsc *cf,struct pdsc *pf) {struct pds_auxiliary_dev *padev; -int err =0 ; - -if (!cf) -return -ENODEV ;mutex_lock (&pf->config_lock);
@@ -195,7 +191,6 @@ int pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf) pf->vfs[cf->vf_id].padev =NULL ;mutex_unlock (&pf->config_lock); -return err; }int pdsc_auxbus_dev_add (struct pdsc *cf,struct pdsc *pf)
drivers/net/ethernet/amd/pds_core/core.h +1 -1
@@ -304,7 +304,7 @@ int pdsc_register_notify(struct notifier_block *nb);void pdsc_unregister_notify (struct notifier_block *nb);void pdsc_notify (unsigned long event,void *data);int pdsc_auxbus_dev_add (struct pdsc *cf,struct pdsc *pf); -int pdsc_auxbus_dev_del (struct pdsc *cf,struct pdsc *pf); +void pdsc_auxbus_dev_del (struct pdsc *cf,struct pdsc *pf);void pdsc_process_adminq (struct pdsc_qcq *qcq);void pdsc_work_thread (struct work_struct *work);
drivers/net/ethernet/amd/pds_core/devlink.c +4 -2
@@ -56,8 +56,10 @@ int pdsc_dl_enable_set(struct devlink *dl, u32 id,for (vf_id =0 ; vf_id < pdsc->num_vfs; vf_id++) {struct pdsc *vf = pdsc->vfs[vf_id].vf; - err = ctx->val.vbool ?pdsc_auxbus_dev_add (vf, pdsc) : -pdsc_auxbus_dev_del (vf, pdsc); +if (ctx->val.vbool) + err =pdsc_auxbus_dev_add (vf, pdsc); +else +pdsc_auxbus_dev_del (vf, pdsc); }return err;
Signature · 1 line
2.17.1
PATCH v5 2/6 pds_core: specify auxiliary_device to be created
In reply to Shannon NelsonIn preparation for adding a new auxiliary_device for the PF, make the vif type an argument to pdsc_auxbus_dev_add(). Pass in the address of the padev pointer so that the caller can specify where to save it and keep the mutex usage within the function.
--- drivers/net/ethernet/amd/pds_core/auxbus.c | 37 ++++++++++----------- drivers/net/ethernet/amd/pds_core/core.h | 7 ++-- drivers/net/ethernet/amd/pds_core/devlink.c | 5 +-- drivers/net/ethernet/amd/pds_core/main.c | 11 +++--- 4 files changed, 33 insertions(+), 27 deletions(-)
drivers/net/ethernet/amd/pds_core/auxbus.c +18 -19
@@ -175,29 +175,32 @@ static struct pds_auxiliary_dev *pdsc_auxbus_dev_register(struct pdsc *cf,return padev; } -void pdsc_auxbus_dev_del (struct pdsc *cf,struct pdsc *pf) +void pdsc_auxbus_dev_del (struct pdsc *cf,struct pdsc *pf, +struct pds_auxiliary_dev **pd_ptr) {struct pds_auxiliary_dev *padev; +if (!*pd_ptr) +return ; +mutex_lock (&pf->config_lock); - padev = pf->vfs[cf->vf_id].padev; -if (padev) { -pds_client_unregister (pf, padev->client_id); -auxiliary_device_delete (&padev->aux_dev); -auxiliary_device_uninit (&padev->aux_dev); - padev->client_id =0 ; - } - pf->vfs[cf->vf_id].padev =NULL ; + padev = *pd_ptr; +pds_client_unregister (pf, padev->client_id); +auxiliary_device_delete (&padev->aux_dev); +auxiliary_device_uninit (&padev->aux_dev); + padev->client_id =0 ; + *pd_ptr =NULL ;mutex_unlock (&pf->config_lock); } -int pdsc_auxbus_dev_add (struct pdsc *cf,struct pdsc *pf) +int pdsc_auxbus_dev_add (struct pdsc *cf,struct pdsc *pf, +enum pds_core_vif_types vt, +struct pds_auxiliary_dev **pd_ptr) {struct pds_auxiliary_dev *padev;char devname[PDS_DEVNAME_LEN ]; -enum pds_core_vif_types vt;unsigned long mask;u16 vt_support;int client_id;
@@ -206,6 +209,9 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf)if (!cf)return -ENODEV ; +if (vt >=PDS_DEV_TYPE_MAX ) +return -EINVAL ; +mutex_lock (&pf->config_lock); mask = BIT_ULL(PDSC_S_FW_DEAD) |
@@ -217,17 +223,10 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf) goto out_unlock; } -/* We only support vDPA so far, so it is the only one to -* be verified that it is available in the Core device and -* enabled in the devlink param. In the future this might -* become a loop for several VIF types. -*/ -/* Verify that the type is supported and enabled. It is not * an error if there is no auxbus device support for this * VF, it just means something else needs to happen with it. */ - vt =PDS_DEV_TYPE_VDPA ; vt_support = !!le16_to_cpu (pf->dev_ident.vif_types[vt]); if (!(vt_support && pf->viftype_status[vt].supported &&
@@ -253,7 +252,7 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf) err =PTR_ERR (padev); goto out_unlock; } - pf->vfs[cf->vf_id].padev = padev; + *pd_ptr = padev; out_unlock:mutex_unlock (&pf->config_lock);
drivers/net/ethernet/amd/pds_core/core.h +5 -2
@@ -303,8 +303,11 @@ void pdsc_health_thread(struct work_struct *work);int pdsc_register_notify (struct notifier_block *nb);void pdsc_unregister_notify (struct notifier_block *nb);void pdsc_notify (unsigned long event,void *data); -int pdsc_auxbus_dev_add (struct pdsc *cf,struct pdsc *pf); -void pdsc_auxbus_dev_del (struct pdsc *cf,struct pdsc *pf); +int pdsc_auxbus_dev_add (struct pdsc *cf,struct pdsc *pf, +enum pds_core_vif_types vt, +struct pds_auxiliary_dev **pd_ptr); +void pdsc_auxbus_dev_del (struct pdsc *cf,struct pdsc *pf, +struct pds_auxiliary_dev **pd_ptr);void pdsc_process_adminq (struct pdsc_qcq *qcq);void pdsc_work_thread (struct work_struct *work);
drivers/net/ethernet/amd/pds_core/devlink.c +3 -2
@@ -57,9 +57,10 @@ int pdsc_dl_enable_set(struct devlink *dl, u32 id,struct pdsc *vf = pdsc->vfs[vf_id].vf;if (ctx->val.vbool) - err =pdsc_auxbus_dev_add (vf, pdsc); + err =pdsc_auxbus_dev_add (vf, pdsc, vt_entry->vif_id, + &pdsc->vfs[vf_id].padev);else -pdsc_auxbus_dev_del (vf, pdsc); +pdsc_auxbus_dev_del (vf, pdsc, &pdsc->vfs[vf_id].padev); }return err;
drivers/net/ethernet/amd/pds_core/main.c +7 -4
@@ -190,7 +190,8 @@ static int pdsc_init_vf(struct pdsc *vf)devl_unlock (dl); pf->vfs[vf->vf_id].vf = vf; - err =pdsc_auxbus_dev_add (vf, pf); + err =pdsc_auxbus_dev_add (vf, pf,PDS_DEV_TYPE_VDPA , + &pf->vfs[vf->vf_id].padev);if (err) {devl_lock (dl);devl_unregister (dl);
@@ -417,7 +418,7 @@ static void pdsc_remove(struct pci_dev *pdev) pf =pdsc_get_pf_struct (pdsc->pdev);if (!IS_ERR (pf)) { -pdsc_auxbus_dev_del (pdsc, pf); +pdsc_auxbus_dev_del (pdsc, pf, &pf->vfs[pdsc->vf_id].padev); pf->vfs[pdsc->vf_id].vf =NULL ; } }else {
@@ -482,7 +483,8 @@ static void pdsc_reset_prepare(struct pci_dev *pdev) pf =pdsc_get_pf_struct (pdsc->pdev);if (!IS_ERR (pf)) -pdsc_auxbus_dev_del (pdsc, pf); +pdsc_auxbus_dev_del (pdsc, pf, + &pf->vfs[pdsc->vf_id].padev); }pdsc_unmap_bars (pdsc);
@@ -527,7 +529,8 @@ static void pdsc_reset_done(struct pci_dev *pdev) pf =pdsc_get_pf_struct (pdsc->pdev);if (!IS_ERR (pf)) -pdsc_auxbus_dev_add (pdsc, pf); +pdsc_auxbus_dev_add (pdsc, pf,PDS_DEV_TYPE_VDPA , + &pf->vfs[pdsc->vf_id].padev); } }
Signature · 1 line
2.17.1
PATCH v5 3/6 pds_core: add new fwctl auxiliary_device
In reply to Shannon NelsonAdd support for a new fwctl-based auxiliary_device for creating a channel for fwctl support into the AMD/Pensando DSC.
--- drivers/net/ethernet/amd/pds_core/auxbus.c | 4 ++-- drivers/net/ethernet/amd/pds_core/core.c | 7 +++++++ drivers/net/ethernet/amd/pds_core/core.h | 1 + drivers/net/ethernet/amd/pds_core/main.c | 14 +++++++++++++- include/linux/pds/pds_common.h | 2 ++ 5 files changed, 25 insertions(+), 3 deletions(-)
drivers/net/ethernet/amd/pds_core/auxbus.c +2 -2
@@ -224,8 +224,8 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf, }/* Verify that the type is supported and enabled. It is not -* an error if there is no auxbus device support for this -* VF, it just means something else needs to happen with it. +* an error if the firmware doesn't support the feature, the +* driver just won't set up an auxiliary_device for it. */ vt_support = !!le16_to_cpu (pf->dev_ident.vif_types[vt]); if (!(vt_support &&
drivers/net/ethernet/amd/pds_core/core.c +7 -0
@@ -402,6 +402,9 @@ static int pdsc_core_init(struct pdsc *pdsc) }static struct pdsc_viftype pdsc_viftype_defaults[] = { + [PDS_DEV_TYPE_FWCTL ] = { .name =PDS_DEV_TYPE_FWCTL_STR , + .vif_id =PDS_DEV_TYPE_FWCTL , + .dl_id =-1 }, [PDS_DEV_TYPE_VDPA ] = { .name =PDS_DEV_TYPE_VDPA_STR , .vif_id =PDS_DEV_TYPE_VDPA , .dl_id =DEVLINK_PARAM_GENERIC_ID_ENABLE_VNET },
@@ -428,6 +431,10 @@ static int pdsc_viftypes_init(struct pdsc *pdsc)/* See what the Core device has for support */ vt_support = !!le16_to_cpu (pdsc->dev_ident.vif_types[vt]); + +if (vt ==PDS_DEV_TYPE_FWCTL ) + pdsc->viftype_status[vt].enabled = true; +dev_dbg (pdsc->dev,"VIF %s is %ssupported\n" , pdsc->viftype_status[vt].name, vt_support ?"" :"not " );
drivers/net/ethernet/amd/pds_core/core.h +1 -0
@@ -156,6 +156,7 @@ struct pdsc {struct dentry *dentry;struct device *dev;struct pdsc_dev_bar bars[PDS_CORE_BARS_MAX ]; +struct pds_auxiliary_dev *padev;struct pdsc_vf *vfs;int num_vfs;int vf_id;
drivers/net/ethernet/amd/pds_core/main.c +13 -1
@@ -265,6 +265,10 @@ static int pdsc_init_pf(struct pdsc *pdsc)mutex_unlock (&pdsc->config_lock); + err =pdsc_auxbus_dev_add (pdsc, pdsc,PDS_DEV_TYPE_FWCTL , &pdsc->padev); +if (err) + goto err_out_stop; + dl =priv_to_devlink (pdsc);devl_lock (dl); err = devl_params_register(dl, pdsc_dl_params,
@@ -273,7 +277,7 @@ static int pdsc_init_pf(struct pdsc *pdsc)devl_unlock (dl);dev_warn (pdsc->dev,"Failed to register devlink params: %pe\n" ,ERR_PTR (err)); - goto err_out_stop; + goto err_out_del_dev; } hr =devl_health_reporter_create (dl, &pdsc_fw_reporter_ops,0 , pdsc);
@@ -296,6 +300,8 @@ static int pdsc_init_pf(struct pdsc *pdsc) err_out_unreg_params:devlink_params_unregister (dl, pdsc_dl_params,ARRAY_SIZE (pdsc_dl_params)); +err_out_del_dev: +pdsc_auxbus_dev_del (pdsc, pdsc, &pdsc->padev); err_out_stop:pdsc_stop (pdsc); err_out_teardown:
@@ -427,6 +433,7 @@ static void pdsc_remove(struct pci_dev *pdev)* shut themselves down. */ pdsc_sriov_configure (pdev,0 ); +pdsc_auxbus_dev_del (pdsc, pdsc, &pdsc->padev);timer_shutdown_sync (&pdsc->wdtimer);if (pdsc->wq)
@@ -485,6 +492,8 @@ static void pdsc_reset_prepare(struct pci_dev *pdev)if (!IS_ERR (pf))pdsc_auxbus_dev_del (pdsc, pf, &pf->vfs[pdsc->vf_id].padev); + }else { +pdsc_auxbus_dev_del (pdsc, pdsc, &pdsc->padev); }pdsc_unmap_bars (pdsc);
@@ -531,6 +540,9 @@ static void pdsc_reset_done(struct pci_dev *pdev)if (!IS_ERR (pf))pdsc_auxbus_dev_add (pdsc, pf,PDS_DEV_TYPE_VDPA , &pf->vfs[pdsc->vf_id].padev); + }else { +pdsc_auxbus_dev_add (pdsc, pdsc,PDS_DEV_TYPE_FWCTL , + &pdsc->padev); } }
include/linux/pds/pds_common.h +2 -0
@@ -29,6 +29,7 @@ enum pds_core_vif_types {PDS_DEV_TYPE_ETH =3 ,PDS_DEV_TYPE_RDMA =4 ,PDS_DEV_TYPE_LM =5 , +PDS_DEV_TYPE_FWCTL =6 ,/* new ones added before this line */ PDS_DEV_TYPE_MAX =16 /* don't change - used in struct size */
@@ -40,6 +41,7 @@ enum pds_core_vif_types {#define PDS_DEV_TYPE_ETH_STR "Eth"#define PDS_DEV_TYPE_RDMA_STR "RDMA"#define PDS_DEV_TYPE_LM_STR "LM" +#define PDS_DEV_TYPE_FWCTL_STR "fwctl"#define PDS_VDPA_DEV_NAME PDS_CORE_DRV_NAME "." PDS_DEV_TYPE_VDPA_STR#define PDS_VFIO_LM_DEV_NAME PDS_CORE_DRV_NAME "." PDS_DEV_TYPE_LM_STR "." PDS_DEV_TYPE_VFIO_STR
Signature · 1 line
2.17.1
PATCH v5 4/6 pds_fwctl: initial driver framework
In reply to Shannon NelsonInitial files for adding a new fwctl driver for the AMD/Pensando PDS devices. This sets up a simple auxiliary_bus driver that registers with fwctl subsystem. It expects that a pds_core device has set up the auxiliary_device pds_core.fwctl
--- MAINTAINERS | 7 ++ drivers/fwctl/Kconfig | 10 ++ drivers/fwctl/Makefile | 1 + drivers/fwctl/pds/Makefile | 4 + drivers/fwctl/pds/main.c | 169 +++++++++++++++++++++++++++++++++ include/linux/pds/pds_adminq.h | 83 ++++++++++++++++ include/uapi/fwctl/fwctl.h | 1 + include/uapi/fwctl/pds.h | 32 +++++++ 8 files changed, 307 insertions(+) create mode 100644 drivers/fwctl/pds/Makefile create mode 100644 drivers/fwctl/pds/main.c create mode 100644 include/uapi/fwctl/pds.h
MAINTAINERS +7 -0
@@ -9576,6 +9576,13 @@ L: [email protected] S: Maintained F: drivers/fwctl/mlx5/ +FWCTL PDS DRIVER +M: Brett Creeley <[email protected]> +R: Shannon Nelson <[email protected]> +L: [email protected] +S: Maintained +F: drivers/fwctl/pds/ + GALAXYCORE GC0308 CAMERA SENSOR DRIVER M: Sebastian Reichel <[email protected]> L: [email protected]
drivers/fwctl/Kconfig +10 -0
@@ -19,5 +19,15 @@ config FWCTL_MLX5 This will allow configuration and debug tools to work out of the box on mainstream kernel. + If you don't know what to do here, say N. + +config FWCTL_PDS + tristate "AMD/Pensando pds fwctl driver" + depends on PDS_CORE + help + The pds_fwctl driver provides an fwctl interface for a user process + to access the debug and configuration information of the AMD/Pensando + DSC hardware family. + If you don't know what to do here, say N. endif
drivers/fwctl/Makefile +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_FWCTL) += fwctl.o obj-$(CONFIG_FWCTL_MLX5) += mlx5/ +obj-$(CONFIG_FWCTL_PDS) += pds/ fwctl-y += main.o
drivers/fwctl/pds/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_FWCTL_PDS) += pds_fwctl.o + +pds_fwctl-y += main.o
drivers/fwctl/pds/main.c new file +169 -0
169 lines not on this page · raw message
include/linux/pds/pds_adminq.h +83 -0
101 lines not on this page · raw message
include/uapi/fwctl/fwctl.h +1 -0
@@ -44,6 +44,7 @@ enum fwctl_device_type {FWCTL_DEVICE_TYPE_ERROR =0 ,FWCTL_DEVICE_TYPE_MLX5 =1 ,FWCTL_DEVICE_TYPE_CXL =2 , + FWCTL_DEVICE_TYPE_PDS = 4, };/**
include/uapi/fwctl/pds.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* Copyright(c) Advanced Micro Devices, Inc */ + +/* +* fwctl interface info for pds_fwctl +*/ + +#ifndef _UAPI_FWCTL_PDS_H_ +#define _UAPI_FWCTL_PDS_H_ + +#include <linux/types.h> + +/** +* struct fwctl_info_pds +* @uctx_caps: bitmap of firmware capabilities +* +* Return basic information about the FW interface available. +*/ +struct fwctl_info_pds { +__u32 uctx_caps; +}; + +/** +* enum pds_fwctl_capabilities +* @PDS_FWCTL_QUERY_CAP: firmware can be queried for information +* @PDS_FWCTL_SEND_CAP: firmware can be sent commands +*/ +enum pds_fwctl_capabilities { +PDS_FWCTL_QUERY_CAP =0 , +PDS_FWCTL_SEND_CAP , +}; +#endif /* _UAPI_FWCTL_PDS_H_ */
Signature · 1 line
2.17.1
PATCH v5 5/6 pds_fwctl: add rpc and query support
In reply to Shannon NelsonFrom: Brett Creeley <[email protected]>
The pds_fwctl driver doesn't know what RPC operations are available in the firmware, so also doesn't know what scope they might have. The userland utility supplies the firmware "endpoint" and "operation" id values and this driver queries the firmware for endpoints and their available operations. The operation descriptions include the scope information which the driver uses for scope testing.
--- drivers/fwctl/pds/main.c | 372 ++++++++++++++++++++++++++++++++- include/linux/pds/pds_adminq.h | 194 +++++++++++++++++ include/uapi/fwctl/pds.h | 30 +++ 3 files changed, 595 insertions(+), 1 deletion(-)
drivers/fwctl/pds/main.c +371 -1
@@ -5,6 +5,7 @@#include <linux/auxiliary_bus.h> #include <linux/pci.h> #include <linux/vmalloc.h> +#include <linux/bitfield.h> #include <uapi/fwctl/fwctl.h> #include <uapi/fwctl/pds.h>
@@ -20,11 +21,21 @@ struct pdsfc_uctx {u32 uctx_caps; }; +struct pdsfc_rpc_endpoint_info { +u32 endpoint; +dma_addr_t operations_pa; +struct pds_fwctl_query_data *operations; +struct mutex lock;/* lock for endpoint info management */ +}; +struct pdsfc_dev {struct fwctl_device fwctl;struct pds_auxiliary_dev *padev;u32 caps;struct pds_fwctl_ident ident; +dma_addr_t endpoints_pa; +struct pds_fwctl_query_data *endpoints; +struct pdsfc_rpc_endpoint_info *endpoint_info; };static int pdsfc_open_uctx (struct fwctl_uctx *uctx)
@@ -92,10 +103,357 @@ static int pdsfc_identify(struct pdsfc_dev *pdsfc)return err; } +static void pdsfc_free_endpoints (struct pdsfc_dev *pdsfc) +{ +struct device *dev = &pdsfc->fwctl.dev; +int i; + +if (!pdsfc->endpoints) +return ; + +for (i =0 ; pdsfc->endpoint_info && i < pdsfc->endpoints->num_entries; i++) +mutex_destroy (&pdsfc->endpoint_info[i].lock); +vfree (pdsfc->endpoint_info); + pdsfc->endpoint_info =NULL ; +dma_free_coherent (dev->parent,PAGE_SIZE , + pdsfc->endpoints, pdsfc->endpoints_pa); + pdsfc->endpoints =NULL ; + pdsfc->endpoints_pa =DMA_MAPPING_ERROR ; +} + +static void pdsfc_free_operations (struct pdsfc_dev *pdsfc) +{ +struct device *dev = &pdsfc->fwctl.dev; +u32 num_endpoints; +int i; + + num_endpoints =le32_to_cpu (pdsfc->endpoints->num_entries); +for (i =0 ; i < num_endpoints; i++) { +struct pdsfc_rpc_endpoint_info *ei = &pdsfc->endpoint_info[i]; + +if (ei->operations) { +dma_free_coherent (dev->parent,PAGE_SIZE , + ei->operations, ei->operations_pa); + ei->operations =NULL ; + ei->operations_pa =DMA_MAPPING_ERROR ; + } + } +} + +static struct pds_fwctl_query_data *pdsfc_get_endpoints (struct pdsfc_dev *pdsfc, +dma_addr_t *pa) +{ +struct device *dev = &pdsfc->fwctl.dev; +union pds_core_adminq_comp comp = {0 }; +struct pds_fwctl_query_data *data; +union pds_core_adminq_cmd cmd; +dma_addr_t data_pa; +int err; + + data =dma_alloc_coherent (dev->parent,PAGE_SIZE , &data_pa,GFP_KERNEL ); + err =dma_mapping_error (dev, data_pa); +if (err) { +dev_err (dev,"Failed to map endpoint list\n" ); +return ERR_PTR (err); + } + + cmd = (union pds_core_adminq_cmd ) { + .fwctl_query = { + .opcode =PDS_FWCTL_CMD_QUERY , + .entity =PDS_FWCTL_RPC_ROOT , + .version =0 , + .query_data_buf_len =cpu_to_le32 (PAGE_SIZE ), + .query_data_buf_pa =cpu_to_le64 (data_pa), + } + }; + + err =pds_client_adminq_cmd (pdsfc->padev, &cmd,sizeof (cmd), &comp,0 ); +if (err) { +dev_err (dev,"Failed to send adminq cmd opcode: %u entity: %u err: %d\n" , + cmd.fwctl_query.opcode, cmd.fwctl_query.entity, err); +dma_free_coherent (dev->parent,PAGE_SIZE , data, data_pa); +return ERR_PTR (err); + } + + *pa = data_pa; + +return data; +} + +static int pdsfc_init_endpoints (struct pdsfc_dev *pdsfc) +{ +struct pds_fwctl_query_data_endpoint *ep_entry; +u32 num_endpoints; +int i; + + pdsfc->endpoints =pdsfc_get_endpoints (pdsfc, &pdsfc->endpoints_pa); +if (IS_ERR (pdsfc->endpoints)) +return PTR_ERR (pdsfc->endpoints); + + num_endpoints =le32_to_cpu (pdsfc->endpoints->num_entries); + pdsfc->endpoint_info =vcalloc (num_endpoints, +sizeof (*pdsfc->endpoint_info)); +if (!pdsfc->endpoint_info) { +pdsfc_free_endpoints (pdsfc); +return -ENOMEM ; + } + + ep_entry = (struct pds_fwctl_query_data_endpoint *)pdsfc->endpoints->entries; +for (i =0 ; i < num_endpoints; i++) { +mutex_init (&pdsfc->endpoint_info[i].lock); + pdsfc->endpoint_info[i].endpoint = ep_entry[i].id; + } + +return 0 ; +} + +static struct pds_fwctl_query_data *pdsfc_get_operations (struct pdsfc_dev *pdsfc, +dma_addr_t *pa,u32 ep) +{ +struct pds_fwctl_query_data_operation *entries; +struct device *dev = &pdsfc->fwctl.dev; +union pds_core_adminq_comp comp = {0 }; +struct pds_fwctl_query_data *data; +union pds_core_adminq_cmd cmd; +dma_addr_t data_pa; +int err; +int i; + +/* Query the operations list for the given endpoint */ + data =dma_alloc_coherent (dev->parent,PAGE_SIZE , &data_pa,GFP_KERNEL ); + err =dma_mapping_error (dev->parent, data_pa); +if (err) { +dev_err (dev,"Failed to map operations list\n" ); +return ERR_PTR (err); + } + + cmd = (union pds_core_adminq_cmd ) { + .fwctl_query = { + .opcode =PDS_FWCTL_CMD_QUERY , + .entity =PDS_FWCTL_RPC_ENDPOINT , + .version =0 , + .query_data_buf_len =cpu_to_le32 (PAGE_SIZE ), + .query_data_buf_pa =cpu_to_le64 (data_pa), + .ep =cpu_to_le32 (ep), + } + }; + + err =pds_client_adminq_cmd (pdsfc->padev, &cmd,sizeof (cmd), &comp,0 ); +if (err) { +dev_err (dev,"Failed to send adminq cmd opcode: %u entity: %u err: %d\n" , + cmd.fwctl_query.opcode, cmd.fwctl_query.entity, err); +dma_free_coherent (dev->parent,PAGE_SIZE , data, data_pa); +return ERR_PTR (err); + } + + *pa = data_pa; + + entries = (struct pds_fwctl_query_data_operation *)data->entries; +dev_dbg (dev,"num_entries %d\n" , data->num_entries); +for (i =0 ; i < data->num_entries; i++) { + +/* Translate FW command attribute to fwctl scope */ +switch (entries[i].scope) { +case PDSFC_FW_CMD_ATTR_READ : +case PDSFC_FW_CMD_ATTR_WRITE : +case PDSFC_FW_CMD_ATTR_SYNC : + entries[i].scope =FWCTL_RPC_CONFIGURATION ; +break ; +case PDSFC_FW_CMD_ATTR_DEBUG_READ : + entries[i].scope =FWCTL_RPC_DEBUG_READ_ONLY ; +break ; +case PDSFC_FW_CMD_ATTR_DEBUG_WRITE : + entries[i].scope =FWCTL_RPC_DEBUG_WRITE ; +break ; +default : + entries[i].scope =FWCTL_RPC_DEBUG_WRITE_FULL ; +break ; + } +dev_dbg (dev,"endpoint %d operation: id %x scope %d\n" , + ep, entries[i].id, entries[i].scope); + } + +return data; +} + +static int pdsfc_validate_rpc (struct pdsfc_dev *pdsfc, +struct fwctl_rpc_pds *rpc, +enum fwctl_rpc_scope scope) +{ +struct pds_fwctl_query_data_operation *op_entry; +struct pdsfc_rpc_endpoint_info *ep_info =NULL ; +struct device *dev = &pdsfc->fwctl.dev; +int i; + +/* validate rpc in_len & out_len based +* on ident.max_req_sz & max_resp_sz +*/ +if (rpc->in.len > pdsfc->ident.max_req_sz) { +dev_dbg (dev,"Invalid request size %u, max %u\n" , + rpc->in.len, pdsfc->ident.max_req_sz); +return -EINVAL ; + } + +if (rpc->out.len > pdsfc->ident.max_resp_sz) { +dev_dbg (dev,"Invalid response size %u, max %u\n" , + rpc->out.len, pdsfc->ident.max_resp_sz); +return -EINVAL ; + } + +for (i =0 ; i < pdsfc->endpoints->num_entries; i++) { +if (pdsfc->endpoint_info[i].endpoint == rpc->in.ep) { + ep_info = &pdsfc->endpoint_info[i]; +break ; + } + } +if (!ep_info) { +dev_dbg (dev,"Invalid endpoint %d\n" , rpc->in.ep); +return -EINVAL ; + } + +/* query and cache this endpoint's operations */ +mutex_lock (&ep_info->lock); +if (!ep_info->operations) { +struct pds_fwctl_query_data *operations; + + operations =pdsfc_get_operations (pdsfc, + &ep_info->operations_pa, + rpc->in.ep); +if (IS_ERR (operations)) { +mutex_unlock (&ep_info->lock); +return -ENOMEM ; + } + ep_info->operations = operations; + } +mutex_unlock (&ep_info->lock); + +/* reject unsupported and/or out of scope commands */ + op_entry = (struct pds_fwctl_query_data_operation *)ep_info->operations->entries; +for (i =0 ; i < ep_info->operations->num_entries; i++) { +if (PDS_FWCTL_RPC_OPCODE_CMP (rpc->in.op, op_entry[i].id)) { +if (scope < op_entry[i].scope) +return -EPERM ; +return 0 ; + } + } + +dev_dbg (dev,"Invalid operation %d for endpoint %d\n" , rpc->in.op, rpc->in.ep); + +return -EINVAL ; +} +static void *pdsfc_fw_rpc (struct fwctl_uctx *uctx,enum fwctl_rpc_scope scope,void *in,size_t in_len,size_t *out_len) { -return NULL ; + struct pdsfc_dev *pdsfc = container_of(uctx->fwctl, struct pdsfc_dev, fwctl); +struct device *dev = &uctx->fwctl->dev; +union pds_core_adminq_comp comp = {0 }; +dma_addr_t out_payload_dma_addr =0 ; +dma_addr_t in_payload_dma_addr =0 ; +struct fwctl_rpc_pds *rpc = in; +union pds_core_adminq_cmd cmd; +void *out_payload =NULL ; +void *in_payload =NULL ; +void *out =NULL ; +int err; + + err =pdsfc_validate_rpc (pdsfc, rpc, scope); +if (err) +return ERR_PTR (err); + +if (rpc->in.len >0 ) { + in_payload =kzalloc (rpc->in.len,GFP_KERNEL ); +if (!in_payload) { +dev_err (dev,"Failed to allocate in_payload\n" ); + err = -ENOMEM ; + goto err_out; + } + +if (copy_from_user (in_payload,u64_to_user_ptr (rpc->in.payload), + rpc->in.len)) { +dev_dbg (dev,"Failed to copy in_payload from user\n" ); + err = -EFAULT ; + goto err_in_payload; + } + + in_payload_dma_addr =dma_map_single (dev->parent, in_payload, + rpc->in.len,DMA_TO_DEVICE ); + err =dma_mapping_error (dev->parent, in_payload_dma_addr); +if (err) { +dev_dbg (dev,"Failed to map in_payload\n" ); + goto err_in_payload; + } + } + +if (rpc->out.len >0 ) { + out_payload =kzalloc (rpc->out.len,GFP_KERNEL ); +if (!out_payload) { +dev_dbg (dev,"Failed to allocate out_payload\n" ); + err = -ENOMEM ; + goto err_out_payload; + } + + out_payload_dma_addr =dma_map_single (dev->parent, out_payload, + rpc->out.len,DMA_FROM_DEVICE ); + err =dma_mapping_error (dev->parent, out_payload_dma_addr); +if (err) { +dev_dbg (dev,"Failed to map out_payload\n" ); + goto err_out_payload; + } + } + + cmd = (union pds_core_adminq_cmd ) { + .fwctl_rpc = { + .opcode =PDS_FWCTL_CMD_RPC , + .flags =PDS_FWCTL_RPC_IND_REQ |PDS_FWCTL_RPC_IND_RESP , + .ep =cpu_to_le32 (rpc->in.ep), + .op =cpu_to_le32 (rpc->in.op), + .req_pa =cpu_to_le64 (in_payload_dma_addr), + .req_sz =cpu_to_le32 (rpc->in.len), + .resp_pa =cpu_to_le64 (out_payload_dma_addr), + .resp_sz =cpu_to_le32 (rpc->out.len), + } + }; + + err =pds_client_adminq_cmd (pdsfc->padev, &cmd,sizeof (cmd), &comp,0 ); +if (err) { +dev_dbg (dev,"%s: ep %d op %x req_pa %llx req_sz %d req_sg %d resp_pa %llx resp_sz %d resp_sg %d err %d\n" , + __func__, rpc->in.ep, rpc->in.op, + cmd.fwctl_rpc.req_pa, cmd.fwctl_rpc.req_sz, cmd.fwctl_rpc.req_sg_elems, + cmd.fwctl_rpc.resp_pa, cmd.fwctl_rpc.resp_sz, cmd.fwctl_rpc.resp_sg_elems, + err); + goto done; + } + +dynamic_hex_dump ("out " ,DUMP_PREFIX_OFFSET ,16 ,1 , out_payload, rpc->out.len, true); + +if (copy_to_user (u64_to_user_ptr (rpc->out.payload), out_payload, rpc->out.len)) { +dev_dbg (dev,"Failed to copy out_payload to user\n" ); + out =ERR_PTR (-EFAULT ); + goto done; + } + + rpc->out.retval =le32_to_cpu (comp.fwctl_rpc.err); + *out_len = in_len; + out = in; + +done: +if (out_payload_dma_addr) +dma_unmap_single (dev->parent, out_payload_dma_addr, + rpc->out.len,DMA_FROM_DEVICE ); +err_out_payload: +kfree (out_payload); + +if (in_payload_dma_addr) +dma_unmap_single (dev->parent, in_payload_dma_addr, + rpc->in.len,DMA_TO_DEVICE ); +err_in_payload: +kfree (in_payload); +err_out: +if (err) +return ERR_PTR (err); + +return out; }static const struct fwctl_ops pdsfc_ops = {
@@ -128,8 +486,17 @@ static int pdsfc_probe(struct auxiliary_device *adev,return dev_err_probe (dev, err,"Failed to identify device\n" ); } + err =pdsfc_init_endpoints (pdsfc); +if (err) { +fwctl_put (&pdsfc->fwctl); +return dev_err_probe (dev, err,"Failed to init endpoints\n" ); + } + + pdsfc->caps =PDS_FWCTL_QUERY_CAP |PDS_FWCTL_SEND_CAP ; + err =fwctl_register (&pdsfc->fwctl);if (err) { +pdsfc_free_endpoints (pdsfc);fwctl_put (&pdsfc->fwctl);return dev_err_probe (dev, err,"Failed to register device\n" ); }
@@ -144,6 +511,9 @@ static void pdsfc_remove(struct auxiliary_device *adev)struct pdsfc_dev *pdsfc =auxiliary_get_drvdata (adev);fwctl_unregister (&pdsfc->fwctl); +pdsfc_free_operations (pdsfc); +pdsfc_free_endpoints (pdsfc); +fwctl_put (&pdsfc->fwctl); }
include/linux/pds/pds_adminq.h +194 -0
218 lines not on this page · raw message
include/uapi/fwctl/pds.h +30 -0
@@ -29,4 +29,34 @@ enum pds_fwctl_capabilities {PDS_FWCTL_QUERY_CAP =0 , PDS_FWCTL_SEND_CAP, }; + +/** +* struct fwctl_rpc_pds +* @in.op: requested operation code +* @in.ep: firmware endpoint to operate on +* @in.rsvd: reserved +* @in.len: length of payload data +* @in.payload: address of payload buffer +* @in: rpc in parameters +* @out.retval: operation result value +* @out.rsvd: reserved +* @out.len: length of result data buffer +* @out.payload: address of payload data buffer +* @out: rpc out parameters +*/ +struct fwctl_rpc_pds { +struct { +__u32 op; +__u32 ep; +__u32 rsvd; +__u32 len; +__aligned_u64 payload; + } in; +struct { +__u32 retval; +__u32 rsvd[2 ]; +__u32 len; +__aligned_u64 payload; + } out; +};#endif /* _UAPI_FWCTL_PDS_H_ */
Signature · 1 line
2.17.1
PATCH v5 6/6 pds_fwctl: add Documentation entries
In reply to Shannon NelsonAdd pds_fwctl to the driver and fwctl documentation pages.
--- Documentation/userspace-api/fwctl/fwctl.rst | 1 + Documentation/userspace-api/fwctl/index.rst | 1 + .../userspace-api/fwctl/pds_fwctl.rst | 46 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 Documentation/userspace-api/fwctl/pds_fwctl.rst
Documentation/userspace-api/fwctl/fwctl.rst +1 -0
@@ -150,6 +150,7 @@ fwctl User API .. kernel-doc:: include/uapi/fwctl/fwctl.h .. kernel-doc:: include/uapi/fwctl/mlx5.h +.. kernel-doc:: include/uapi/fwctl/pds.h sysfs Class -----------
Documentation/userspace-api/fwctl/index.rst +1 -0
@@ -11,3 +11,4 @@ to securely construct and execute RPCs inside device firmware. fwctl fwctl-cxl + pds_fwctl
Documentation/userspace-api/fwctl/pds_fwctl.rst new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.17.1
Jason Gunthorpe
maintainerQuoted 9 lines · Shannon Nelson
Brett Creeley (1):
pds_fwctl: add rpc and query supportShannon Nelson (5):
pds_core: makepdsc_auxbus_dev_del()void
pds_core: specifyauxiliary_deviceto be created
pds_core: add new fwctlauxiliary_device
pds_fwctl: initial driver framework
pds_fwctl: add Documentation entries
Applied - though it has only been in linux-next for a few days, if there are further problems or remarks we may need a v6
Thanks,
Jason