Skip to content

Commit 0404bf4

Browse files
niklas88gregkh
authored andcommitted
s390/pci: fix misleading rc in clp_set_pci_fn()
[ Upstream commit f7addcd ] Currently clp_set_pci_fn() always returns 0 as long as the CLP request itself succeeds even if the operation itself returns a response code other than CLP_RC_OK or CLP_RC_SETPCIFN_ALRDY. This is highly misleading because calling code assumes that a zero rc means that the operation was successful. Fix this by returning the response code or cc on failure with the exception of the special handling for CLP_RC_SETPCIFN_ALRDY. Also let's not assume that the returned function handle for CLP_RC_SETPCIFN_ALRDY is 0, we don't need it anyway. 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 8b471e7 commit 0404bf4

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

‎arch/s390/pci/pci.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,10 @@ int zpci_enable_device(struct zpci_dev *zdev)
659659
{
660660
int rc;
661661

662-
rc = clp_enable_fh(zdev, ZPCI_NR_DMA_SPACES);
663-
if (rc)
662+
if (clp_enable_fh(zdev, ZPCI_NR_DMA_SPACES)) {
663+
rc = -EIO;
664664
goto out;
665+
}
665666

666667
rc = zpci_dma_init_device(zdev);
667668
if (rc)
@@ -684,7 +685,7 @@ int zpci_disable_device(struct zpci_dev *zdev)
684685
* The zPCI function may already be disabled by the platform, this is
685686
* detected in clp_disable_fh() which becomes a no-op.
686687
*/
687-
return clp_disable_fh(zdev);
688+
return clp_disable_fh(zdev) ? -EIO : 0;
688689
}
689690
EXPORT_SYMBOL_GPL(zpci_disable_device);
690691

‎arch/s390/pci/pci_clp.c‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,19 @@ int clp_query_pci_fn(struct zpci_dev *zdev)
213213
}
214214

215215
static int clp_refresh_fh(u32 fid);
216-
/*
217-
* Enable/Disable a given PCI function and update its function handle if
218-
* necessary
216+
/**
217+
* clp_set_pci_fn() - Execute a command on a PCI function
218+
* @zdev: Function that will be affected
219+
* @nr_dma_as: DMA address space number
220+
* @command: The command code to execute
221+
*
222+
* Returns: 0 on success, < 0 for Linux errors (e.g. -ENOMEM), and
223+
* > 0 for non-success platform responses
219224
*/
220225
static int clp_set_pci_fn(struct zpci_dev *zdev, u8 nr_dma_as, u8 command)
221226
{
222227
struct clp_req_rsp_set_pci *rrb;
223228
int rc, retries = 100;
224-
u32 fid = zdev->fid;
225229

226230
rrb = clp_alloc_block(GFP_KERNEL);
227231
if (!rrb)
@@ -245,17 +249,16 @@ static int clp_set_pci_fn(struct zpci_dev *zdev, u8 nr_dma_as, u8 command)
245249
}
246250
} while (rrb->response.hdr.rsp == CLP_RC_SETPCIFN_BUSY);
247251

248-
if (rc || rrb->response.hdr.rsp != CLP_RC_OK) {
249-
zpci_err("Set PCI FN:\n");
250-
zpci_err_clp(rrb->response.hdr.rsp, rc);
251-
}
252-
253252
if (!rc && rrb->response.hdr.rsp == CLP_RC_OK) {
254253
zdev->fh = rrb->response.fh;
255-
} else if (!rc && rrb->response.hdr.rsp == CLP_RC_SETPCIFN_ALRDY &&
256-
rrb->response.fh == 0) {
254+
} else if (!rc && rrb->response.hdr.rsp == CLP_RC_SETPCIFN_ALRDY) {
257255
/* Function is already in desired state - update handle */
258-
rc = clp_refresh_fh(fid);
256+
rc = clp_refresh_fh(zdev->fid);
257+
} else {
258+
zpci_err("Set PCI FN:\n");
259+
zpci_err_clp(rrb->response.hdr.rsp, rc);
260+
if (!rc)
261+
rc = rrb->response.hdr.rsp;
259262
}
260263
clp_free_block(rrb);
261264
return rc;
@@ -301,17 +304,13 @@ int clp_enable_fh(struct zpci_dev *zdev, u8 nr_dma_as)
301304

302305
rc = clp_set_pci_fn(zdev, nr_dma_as, CLP_SET_ENABLE_PCI_FN);
303306
zpci_dbg(3, "ena fid:%x, fh:%x, rc:%d\n", zdev->fid, zdev->fh, rc);
304-
if (rc)
305-
goto out;
306-
307-
if (zpci_use_mio(zdev)) {
307+
if (!rc && zpci_use_mio(zdev)) {
308308
rc = clp_set_pci_fn(zdev, nr_dma_as, CLP_SET_ENABLE_MIO);
309309
zpci_dbg(3, "ena mio fid:%x, fh:%x, rc:%d\n",
310310
zdev->fid, zdev->fh, rc);
311311
if (rc)
312312
clp_disable_fh(zdev);
313313
}
314-
out:
315314
return rc;
316315
}
317316

0 commit comments

Comments
 (0)