Commit 10659034 authored by Shannon Nelson's avatar Shannon Nelson Committed by David S. Miller

pds_core: add the aux client API

Add the client API operations for running adminq commands.
The core registers the client with the FW, then the client
has a context for requesting adminq services.  We expect
to add additional operations for other clients, including
requesting additional private adminqs and IRQs, but don't have
the need yet.
Signed-off-by: default avatarShannon Nelson <shannon.nelson@amd.com>
Acked-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 40ced894
...@@ -6,6 +6,136 @@ ...@@ -6,6 +6,136 @@
#include "core.h" #include "core.h"
#include <linux/pds/pds_auxbus.h> #include <linux/pds/pds_auxbus.h>
/**
* pds_client_register - Link the client to the firmware
* @pf_pdev: ptr to the PF driver struct
* @devname: name that includes service into, e.g. pds_core.vDPA
*
* Return: 0 on success, or
* negative for error
*/
int pds_client_register(struct pci_dev *pf_pdev, char *devname)
{
union pds_core_adminq_comp comp = {};
union pds_core_adminq_cmd cmd = {};
struct pdsc *pf;
int err;
u16 ci;
pf = pci_get_drvdata(pf_pdev);
if (pf->state)
return -ENXIO;
cmd.client_reg.opcode = PDS_AQ_CMD_CLIENT_REG;
strscpy(cmd.client_reg.devname, devname,
sizeof(cmd.client_reg.devname));
err = pdsc_adminq_post(pf, &cmd, &comp, false);
if (err) {
dev_info(pf->dev, "register dev_name %s with DSC failed, status %d: %pe\n",
devname, comp.status, ERR_PTR(err));
return err;
}
ci = le16_to_cpu(comp.client_reg.client_id);
if (!ci) {
dev_err(pf->dev, "%s: device returned null client_id\n",
__func__);
return -EIO;
}
dev_dbg(pf->dev, "%s: device returned client_id %d for %s\n",
__func__, ci, devname);
return ci;
}
EXPORT_SYMBOL_GPL(pds_client_register);
/**
* pds_client_unregister - Unlink the client from the firmware
* @pf_pdev: ptr to the PF driver struct
* @client_id: id returned from pds_client_register()
*
* Return: 0 on success, or
* negative for error
*/
int pds_client_unregister(struct pci_dev *pf_pdev, u16 client_id)
{
union pds_core_adminq_comp comp = {};
union pds_core_adminq_cmd cmd = {};
struct pdsc *pf;
int err;
pf = pci_get_drvdata(pf_pdev);
if (pf->state)
return -ENXIO;
cmd.client_unreg.opcode = PDS_AQ_CMD_CLIENT_UNREG;
cmd.client_unreg.client_id = cpu_to_le16(client_id);
err = pdsc_adminq_post(pf, &cmd, &comp, false);
if (err)
dev_info(pf->dev, "unregister client_id %d failed, status %d: %pe\n",
client_id, comp.status, ERR_PTR(err));
return err;
}
EXPORT_SYMBOL_GPL(pds_client_unregister);
/**
* pds_client_adminq_cmd - Process an adminq request for the client
* @padev: ptr to the client device
* @req: ptr to buffer with request
* @req_len: length of actual struct used for request
* @resp: ptr to buffer where answer is to be copied
* @flags: optional flags from pds_core_adminq_flags
*
* Return: 0 on success, or
* negative for error
*
* Client sends pointers to request and response buffers
* Core copies request data into pds_core_client_request_cmd
* Core sets other fields as needed
* Core posts to AdminQ
* Core copies completion data into response buffer
*/
int pds_client_adminq_cmd(struct pds_auxiliary_dev *padev,
union pds_core_adminq_cmd *req,
size_t req_len,
union pds_core_adminq_comp *resp,
u64 flags)
{
union pds_core_adminq_cmd cmd = {};
struct pci_dev *pf_pdev;
struct pdsc *pf;
size_t cp_len;
int err;
pf_pdev = pci_physfn(padev->vf_pdev);
pf = pci_get_drvdata(pf_pdev);
dev_dbg(pf->dev, "%s: %s opcode %d\n",
__func__, dev_name(&padev->aux_dev.dev), req->opcode);
if (pf->state)
return -ENXIO;
/* Wrap the client's request */
cmd.client_request.opcode = PDS_AQ_CMD_CLIENT_CMD;
cmd.client_request.client_id = cpu_to_le16(padev->client_id);
cp_len = min_t(size_t, req_len, sizeof(cmd.client_request.client_cmd));
memcpy(cmd.client_request.client_cmd, req, cp_len);
err = pdsc_adminq_post(pf, &cmd, resp,
!!(flags & PDS_AQ_FLAG_FASTPOLL));
if (err && err != -EAGAIN)
dev_info(pf->dev, "client admin cmd failed: %pe\n",
ERR_PTR(err));
return err;
}
EXPORT_SYMBOL_GPL(pds_client_adminq_cmd);
static void pdsc_auxbus_dev_release(struct device *dev) static void pdsc_auxbus_dev_release(struct device *dev)
{ {
struct pds_auxiliary_dev *padev = struct pds_auxiliary_dev *padev =
...@@ -16,6 +146,7 @@ static void pdsc_auxbus_dev_release(struct device *dev) ...@@ -16,6 +146,7 @@ static void pdsc_auxbus_dev_release(struct device *dev)
static struct pds_auxiliary_dev *pdsc_auxbus_dev_register(struct pdsc *cf, static struct pds_auxiliary_dev *pdsc_auxbus_dev_register(struct pdsc *cf,
struct pdsc *pf, struct pdsc *pf,
u16 client_id,
char *name) char *name)
{ {
struct auxiliary_device *aux_dev; struct auxiliary_device *aux_dev;
...@@ -27,6 +158,7 @@ static struct pds_auxiliary_dev *pdsc_auxbus_dev_register(struct pdsc *cf, ...@@ -27,6 +158,7 @@ static struct pds_auxiliary_dev *pdsc_auxbus_dev_register(struct pdsc *cf,
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
padev->vf_pdev = cf->pdev; padev->vf_pdev = cf->pdev;
padev->client_id = client_id;
aux_dev = &padev->aux_dev; aux_dev = &padev->aux_dev;
aux_dev->name = name; aux_dev->name = name;
...@@ -66,8 +198,10 @@ int pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf) ...@@ -66,8 +198,10 @@ int pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf)
padev = pf->vfs[cf->vf_id].padev; padev = pf->vfs[cf->vf_id].padev;
if (padev) { if (padev) {
pds_client_unregister(pf->pdev, padev->client_id);
auxiliary_device_delete(&padev->aux_dev); auxiliary_device_delete(&padev->aux_dev);
auxiliary_device_uninit(&padev->aux_dev); auxiliary_device_uninit(&padev->aux_dev);
padev->client_id = 0;
} }
pf->vfs[cf->vf_id].padev = NULL; pf->vfs[cf->vf_id].padev = NULL;
...@@ -79,7 +213,9 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf) ...@@ -79,7 +213,9 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf)
{ {
struct pds_auxiliary_dev *padev; struct pds_auxiliary_dev *padev;
enum pds_core_vif_types vt; enum pds_core_vif_types vt;
char devname[PDS_DEVNAME_LEN];
u16 vt_support; u16 vt_support;
int client_id;
int err = 0; int err = 0;
mutex_lock(&pf->config_lock); mutex_lock(&pf->config_lock);
...@@ -101,9 +237,22 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf) ...@@ -101,9 +237,22 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf)
pf->viftype_status[vt].enabled)) pf->viftype_status[vt].enabled))
goto out_unlock; goto out_unlock;
padev = pdsc_auxbus_dev_register(cf, pf, /* Need to register with FW and get the client_id before
* creating the aux device so that the aux client can run
* adminq commands as part its probe
*/
snprintf(devname, sizeof(devname), "%s.%s.%d",
PDS_CORE_DRV_NAME, pf->viftype_status[vt].name, cf->uid);
client_id = pds_client_register(pf->pdev, devname);
if (client_id < 0) {
err = client_id;
goto out_unlock;
}
padev = pdsc_auxbus_dev_register(cf, pf, client_id,
pf->viftype_status[vt].name); pf->viftype_status[vt].name);
if (IS_ERR(padev)) { if (IS_ERR(padev)) {
pds_client_unregister(pf->pdev, client_id);
err = PTR_ERR(padev); err = PTR_ERR(padev);
goto out_unlock; goto out_unlock;
} }
......
...@@ -11,4 +11,10 @@ struct pds_auxiliary_dev { ...@@ -11,4 +11,10 @@ struct pds_auxiliary_dev {
struct pci_dev *vf_pdev; struct pci_dev *vf_pdev;
u16 client_id; u16 client_id;
}; };
int pds_client_adminq_cmd(struct pds_auxiliary_dev *padev,
union pds_core_adminq_cmd *req,
size_t req_len,
union pds_core_adminq_comp *resp,
u64 flags);
#endif /* _PDSC_AUXBUS_H_ */ #endif /* _PDSC_AUXBUS_H_ */
...@@ -61,4 +61,6 @@ enum pds_core_logical_qtype { ...@@ -61,4 +61,6 @@ enum pds_core_logical_qtype {
}; };
void *pdsc_get_pf_struct(struct pci_dev *vf_pdev); void *pdsc_get_pf_struct(struct pci_dev *vf_pdev);
int pds_client_register(struct pci_dev *pf_pdev, char *devname);
int pds_client_unregister(struct pci_dev *pf_pdev, u16 client_id);
#endif /* _PDS_COMMON_H_ */ #endif /* _PDS_COMMON_H_ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment