mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 10:49:33 +00:00
s390/pci: simplify CLP List PCI handling
Currently clp_get_state() and clp_refresh_fh() awkwardly use the clp_list_pci() callback mechanism to find the entry for a specific FID and update its zdev, respectively return its state. This is both needlessly complex and means we are always going through the entire PCI function list even if the FID has already been found. Instead lets introduce a clp_find_pci() function to find a specific entry and share the CLP List PCI request handling code with clp_list_pci(). With that in place we can also easily make the function handle a simple out parameter instead of directly altering the zdev allowing easier access to the updated function handle by the caller. Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
This commit is contained in:
parent
8256adda1f
commit
cc049eecfb
3 changed files with 103 additions and 88 deletions
|
@ -216,10 +216,10 @@ void zpci_remove_reserved_devices(void);
|
||||||
int clp_setup_writeback_mio(void);
|
int clp_setup_writeback_mio(void);
|
||||||
int clp_scan_pci_devices(void);
|
int clp_scan_pci_devices(void);
|
||||||
int clp_query_pci_fn(struct zpci_dev *zdev);
|
int clp_query_pci_fn(struct zpci_dev *zdev);
|
||||||
int clp_enable_fh(struct zpci_dev *, u8);
|
int clp_enable_fh(struct zpci_dev *zdev, u32 *fh, u8 nr_dma_as);
|
||||||
int clp_disable_fh(struct zpci_dev *);
|
int clp_disable_fh(struct zpci_dev *zdev, u32 *fh);
|
||||||
int clp_get_state(u32 fid, enum zpci_state *state);
|
int clp_get_state(u32 fid, enum zpci_state *state);
|
||||||
int clp_refresh_fh(u32 fid);
|
int clp_refresh_fh(u32 fid, u32 *fh);
|
||||||
|
|
||||||
/* UID */
|
/* UID */
|
||||||
void update_uid_checking(bool new);
|
void update_uid_checking(bool new);
|
||||||
|
|
|
@ -653,12 +653,14 @@ void zpci_free_domain(int domain)
|
||||||
|
|
||||||
int zpci_enable_device(struct zpci_dev *zdev)
|
int zpci_enable_device(struct zpci_dev *zdev)
|
||||||
{
|
{
|
||||||
|
u32 fh = zdev->fh;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (clp_enable_fh(zdev, ZPCI_NR_DMA_SPACES)) {
|
if (clp_enable_fh(zdev, &fh, ZPCI_NR_DMA_SPACES)) {
|
||||||
rc = -EIO;
|
rc = -EIO;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
zdev->fh = fh;
|
||||||
|
|
||||||
rc = zpci_dma_init_device(zdev);
|
rc = zpci_dma_init_device(zdev);
|
||||||
if (rc)
|
if (rc)
|
||||||
|
@ -667,29 +669,33 @@ int zpci_enable_device(struct zpci_dev *zdev)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_dma:
|
out_dma:
|
||||||
clp_disable_fh(zdev);
|
clp_disable_fh(zdev, &fh);
|
||||||
out:
|
out:
|
||||||
|
zdev->fh = fh;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int zpci_disable_device(struct zpci_dev *zdev)
|
int zpci_disable_device(struct zpci_dev *zdev)
|
||||||
{
|
{
|
||||||
|
u32 fh = zdev->fh;
|
||||||
int cc, rc = 0;
|
int cc, rc = 0;
|
||||||
|
|
||||||
zpci_dma_exit_device(zdev);
|
zpci_dma_exit_device(zdev);
|
||||||
/*
|
if (!zdev_enabled(zdev))
|
||||||
* The zPCI function may already be disabled by the platform, this is
|
return 0;
|
||||||
* detected in clp_disable_fh() which becomes a no-op.
|
cc = clp_disable_fh(zdev, &fh);
|
||||||
*/
|
if (!cc) {
|
||||||
cc = clp_disable_fh(zdev);
|
zdev->fh = fh;
|
||||||
if (cc == CLP_RC_SETPCIFN_ALRDY) {
|
} else if (cc == CLP_RC_SETPCIFN_ALRDY) {
|
||||||
pr_info("Disabling PCI function %08x had no effect as it was already disabled\n",
|
pr_info("Disabling PCI function %08x had no effect as it was already disabled\n",
|
||||||
zdev->fid);
|
zdev->fid);
|
||||||
/* Function is already disabled - update handle */
|
/* Function is already disabled - update handle */
|
||||||
rc = clp_refresh_fh(zdev->fid);
|
rc = clp_refresh_fh(zdev->fid, &fh);
|
||||||
if (!rc)
|
if (!rc) {
|
||||||
|
zdev->fh = fh;
|
||||||
rc = -EINVAL;
|
rc = -EINVAL;
|
||||||
} else if (cc) {
|
}
|
||||||
|
} else {
|
||||||
rc = -EIO;
|
rc = -EIO;
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
|
|
|
@ -215,17 +215,19 @@ int clp_query_pci_fn(struct zpci_dev *zdev)
|
||||||
/**
|
/**
|
||||||
* clp_set_pci_fn() - Execute a command on a PCI function
|
* clp_set_pci_fn() - Execute a command on a PCI function
|
||||||
* @zdev: Function that will be affected
|
* @zdev: Function that will be affected
|
||||||
|
* @fh: Out parameter for updated function handle
|
||||||
* @nr_dma_as: DMA address space number
|
* @nr_dma_as: DMA address space number
|
||||||
* @command: The command code to execute
|
* @command: The command code to execute
|
||||||
*
|
*
|
||||||
* Returns: 0 on success, < 0 for Linux errors (e.g. -ENOMEM), and
|
* Returns: 0 on success, < 0 for Linux errors (e.g. -ENOMEM), and
|
||||||
* > 0 for non-success platform responses
|
* > 0 for non-success platform responses
|
||||||
*/
|
*/
|
||||||
static int clp_set_pci_fn(struct zpci_dev *zdev, u8 nr_dma_as, u8 command)
|
static int clp_set_pci_fn(struct zpci_dev *zdev, u32 *fh, u8 nr_dma_as, u8 command)
|
||||||
{
|
{
|
||||||
struct clp_req_rsp_set_pci *rrb;
|
struct clp_req_rsp_set_pci *rrb;
|
||||||
int rc, retries = 100;
|
int rc, retries = 100;
|
||||||
|
|
||||||
|
*fh = 0;
|
||||||
rrb = clp_alloc_block(GFP_KERNEL);
|
rrb = clp_alloc_block(GFP_KERNEL);
|
||||||
if (!rrb)
|
if (!rrb)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -249,7 +251,7 @@ static int clp_set_pci_fn(struct zpci_dev *zdev, u8 nr_dma_as, u8 command)
|
||||||
} while (rrb->response.hdr.rsp == CLP_RC_SETPCIFN_BUSY);
|
} while (rrb->response.hdr.rsp == CLP_RC_SETPCIFN_BUSY);
|
||||||
|
|
||||||
if (!rc && rrb->response.hdr.rsp == CLP_RC_OK) {
|
if (!rc && rrb->response.hdr.rsp == CLP_RC_OK) {
|
||||||
zdev->fh = rrb->response.fh;
|
*fh = rrb->response.fh;
|
||||||
} else {
|
} else {
|
||||||
zpci_err("Set PCI FN:\n");
|
zpci_err("Set PCI FN:\n");
|
||||||
zpci_err_clp(rrb->response.hdr.rsp, rc);
|
zpci_err_clp(rrb->response.hdr.rsp, rc);
|
||||||
|
@ -294,31 +296,62 @@ int clp_setup_writeback_mio(void)
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int clp_enable_fh(struct zpci_dev *zdev, u8 nr_dma_as)
|
int clp_enable_fh(struct zpci_dev *zdev, u32 *fh, u8 nr_dma_as)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = clp_set_pci_fn(zdev, nr_dma_as, CLP_SET_ENABLE_PCI_FN);
|
rc = clp_set_pci_fn(zdev, fh, nr_dma_as, CLP_SET_ENABLE_PCI_FN);
|
||||||
zpci_dbg(3, "ena fid:%x, fh:%x, rc:%d\n", zdev->fid, zdev->fh, rc);
|
zpci_dbg(3, "ena fid:%x, fh:%x, rc:%d\n", zdev->fid, *fh, rc);
|
||||||
if (!rc && zpci_use_mio(zdev)) {
|
if (!rc && zpci_use_mio(zdev)) {
|
||||||
rc = clp_set_pci_fn(zdev, nr_dma_as, CLP_SET_ENABLE_MIO);
|
rc = clp_set_pci_fn(zdev, fh, nr_dma_as, CLP_SET_ENABLE_MIO);
|
||||||
zpci_dbg(3, "ena mio fid:%x, fh:%x, rc:%d\n",
|
zpci_dbg(3, "ena mio fid:%x, fh:%x, rc:%d\n",
|
||||||
zdev->fid, zdev->fh, rc);
|
zdev->fid, *fh, rc);
|
||||||
if (rc)
|
if (rc)
|
||||||
clp_disable_fh(zdev);
|
clp_disable_fh(zdev, fh);
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int clp_disable_fh(struct zpci_dev *zdev)
|
int clp_disable_fh(struct zpci_dev *zdev, u32 *fh)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (!zdev_enabled(zdev))
|
if (!zdev_enabled(zdev))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
rc = clp_set_pci_fn(zdev, 0, CLP_SET_DISABLE_PCI_FN);
|
rc = clp_set_pci_fn(zdev, fh, 0, CLP_SET_DISABLE_PCI_FN);
|
||||||
zpci_dbg(3, "dis fid:%x, fh:%x, rc:%d\n", zdev->fid, zdev->fh, rc);
|
zpci_dbg(3, "dis fid:%x, fh:%x, rc:%d\n", zdev->fid, *fh, rc);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int clp_list_pci_req(struct clp_req_rsp_list_pci *rrb,
|
||||||
|
u64 *resume_token, int *nentries)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
memset(rrb, 0, sizeof(*rrb));
|
||||||
|
rrb->request.hdr.len = sizeof(rrb->request);
|
||||||
|
rrb->request.hdr.cmd = CLP_LIST_PCI;
|
||||||
|
/* store as many entries as possible */
|
||||||
|
rrb->response.hdr.len = CLP_BLK_SIZE - LIST_PCI_HDR_LEN;
|
||||||
|
rrb->request.resume_token = *resume_token;
|
||||||
|
|
||||||
|
/* Get PCI function handle list */
|
||||||
|
rc = clp_req(rrb, CLP_LPS_PCI);
|
||||||
|
if (rc || rrb->response.hdr.rsp != CLP_RC_OK) {
|
||||||
|
zpci_err("List PCI FN:\n");
|
||||||
|
zpci_err_clp(rrb->response.hdr.rsp, rc);
|
||||||
|
return -EIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
update_uid_checking(rrb->response.uid_checking);
|
||||||
|
WARN_ON_ONCE(rrb->response.entry_size !=
|
||||||
|
sizeof(struct clp_fh_list_entry));
|
||||||
|
|
||||||
|
*nentries = (rrb->response.hdr.len - LIST_PCI_HDR_LEN) /
|
||||||
|
rrb->response.entry_size;
|
||||||
|
*resume_token = rrb->response.resume_token;
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,40 +359,42 @@ static int clp_list_pci(struct clp_req_rsp_list_pci *rrb, void *data,
|
||||||
void (*cb)(struct clp_fh_list_entry *, void *))
|
void (*cb)(struct clp_fh_list_entry *, void *))
|
||||||
{
|
{
|
||||||
u64 resume_token = 0;
|
u64 resume_token = 0;
|
||||||
int entries, i, rc;
|
int nentries, i, rc;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
memset(rrb, 0, sizeof(*rrb));
|
rc = clp_list_pci_req(rrb, &resume_token, &nentries);
|
||||||
rrb->request.hdr.len = sizeof(rrb->request);
|
if (rc)
|
||||||
rrb->request.hdr.cmd = CLP_LIST_PCI;
|
return rc;
|
||||||
/* store as many entries as possible */
|
for (i = 0; i < nentries; i++)
|
||||||
rrb->response.hdr.len = CLP_BLK_SIZE - LIST_PCI_HDR_LEN;
|
|
||||||
rrb->request.resume_token = resume_token;
|
|
||||||
|
|
||||||
/* Get PCI function handle list */
|
|
||||||
rc = clp_req(rrb, CLP_LPS_PCI);
|
|
||||||
if (rc || rrb->response.hdr.rsp != CLP_RC_OK) {
|
|
||||||
zpci_err("List PCI FN:\n");
|
|
||||||
zpci_err_clp(rrb->response.hdr.rsp, rc);
|
|
||||||
rc = -EIO;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
update_uid_checking(rrb->response.uid_checking);
|
|
||||||
WARN_ON_ONCE(rrb->response.entry_size !=
|
|
||||||
sizeof(struct clp_fh_list_entry));
|
|
||||||
|
|
||||||
entries = (rrb->response.hdr.len - LIST_PCI_HDR_LEN) /
|
|
||||||
rrb->response.entry_size;
|
|
||||||
|
|
||||||
resume_token = rrb->response.resume_token;
|
|
||||||
for (i = 0; i < entries; i++)
|
|
||||||
cb(&rrb->response.fh_list[i], data);
|
cb(&rrb->response.fh_list[i], data);
|
||||||
} while (resume_token);
|
} while (resume_token);
|
||||||
out:
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int clp_find_pci(struct clp_req_rsp_list_pci *rrb, u32 fid,
|
||||||
|
struct clp_fh_list_entry *entry)
|
||||||
|
{
|
||||||
|
struct clp_fh_list_entry *fh_list;
|
||||||
|
u64 resume_token = 0;
|
||||||
|
int nentries, i, rc;
|
||||||
|
|
||||||
|
do {
|
||||||
|
rc = clp_list_pci_req(rrb, &resume_token, &nentries);
|
||||||
|
if (rc)
|
||||||
|
return rc;
|
||||||
|
for (i = 0; i < nentries; i++) {
|
||||||
|
fh_list = rrb->response.fh_list;
|
||||||
|
if (fh_list[i].fid == fid) {
|
||||||
|
*entry = fh_list[i];
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (resume_token);
|
||||||
|
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
static void __clp_add(struct clp_fh_list_entry *entry, void *data)
|
static void __clp_add(struct clp_fh_list_entry *entry, void *data)
|
||||||
{
|
{
|
||||||
struct zpci_dev *zdev;
|
struct zpci_dev *zdev;
|
||||||
|
@ -387,67 +422,41 @@ int clp_scan_pci_devices(void)
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __clp_refresh_fh(struct clp_fh_list_entry *entry, void *data)
|
|
||||||
{
|
|
||||||
struct zpci_dev *zdev;
|
|
||||||
u32 fid = *((u32 *)data);
|
|
||||||
|
|
||||||
if (!entry->vendor_id || fid != entry->fid)
|
|
||||||
return;
|
|
||||||
|
|
||||||
zdev = get_zdev_by_fid(fid);
|
|
||||||
if (!zdev)
|
|
||||||
return;
|
|
||||||
|
|
||||||
zdev->fh = entry->fh;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Refresh the function handle of the function matching @fid
|
* Get the current function handle of the function matching @fid
|
||||||
*/
|
*/
|
||||||
int clp_refresh_fh(u32 fid)
|
int clp_refresh_fh(u32 fid, u32 *fh)
|
||||||
{
|
{
|
||||||
struct clp_req_rsp_list_pci *rrb;
|
struct clp_req_rsp_list_pci *rrb;
|
||||||
|
struct clp_fh_list_entry entry;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rrb = clp_alloc_block(GFP_NOWAIT);
|
rrb = clp_alloc_block(GFP_NOWAIT);
|
||||||
if (!rrb)
|
if (!rrb)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
rc = clp_list_pci(rrb, &fid, __clp_refresh_fh);
|
rc = clp_find_pci(rrb, fid, &entry);
|
||||||
|
if (!rc)
|
||||||
|
*fh = entry.fh;
|
||||||
|
|
||||||
clp_free_block(rrb);
|
clp_free_block(rrb);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct clp_state_data {
|
|
||||||
u32 fid;
|
|
||||||
enum zpci_state state;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void __clp_get_state(struct clp_fh_list_entry *entry, void *data)
|
|
||||||
{
|
|
||||||
struct clp_state_data *sd = data;
|
|
||||||
|
|
||||||
if (entry->fid != sd->fid)
|
|
||||||
return;
|
|
||||||
|
|
||||||
sd->state = entry->config_state;
|
|
||||||
}
|
|
||||||
|
|
||||||
int clp_get_state(u32 fid, enum zpci_state *state)
|
int clp_get_state(u32 fid, enum zpci_state *state)
|
||||||
{
|
{
|
||||||
struct clp_req_rsp_list_pci *rrb;
|
struct clp_req_rsp_list_pci *rrb;
|
||||||
struct clp_state_data sd = {fid, ZPCI_FN_STATE_RESERVED};
|
struct clp_fh_list_entry entry;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
*state = ZPCI_FN_STATE_RESERVED;
|
||||||
rrb = clp_alloc_block(GFP_ATOMIC);
|
rrb = clp_alloc_block(GFP_ATOMIC);
|
||||||
if (!rrb)
|
if (!rrb)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
rc = clp_list_pci(rrb, &sd, __clp_get_state);
|
rc = clp_find_pci(rrb, fid, &entry);
|
||||||
if (!rc)
|
if (!rc)
|
||||||
*state = sd.state;
|
*state = entry.config_state;
|
||||||
|
|
||||||
clp_free_block(rrb);
|
clp_free_block(rrb);
|
||||||
return rc;
|
return rc;
|
||||||
|
|
Loading…
Reference in a new issue