Skip to content

Commit 317f5ef

Browse files
Ian Munsiempe
authored andcommitted
cxl: Add support for using the kernel API with a real PHB
This hooks up support for using the kernel API with a real PHB. After the AFU initialisation has completed it calls into the PHB code to pass it the AFU that will be used by other peer physical functions on the adapter. The cxl_pci_to_afu API is extended to work with peer PCI devices, retrieving the peer AFU from the PHB. This API may also now return an error if it is called on a PCI device that is not associated with either a cxl vPHB or a peer PCI device to an AFU, and this error is propagated down. Signed-off-by: Ian Munsie <imunsie@au1.ibm.com> Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 4361b03 commit 317f5ef

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎drivers/misc/cxl/api.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/file.h>
1414
#include <misc/cxl.h>
1515
#include <linux/fs.h>
16+
#include <asm/pnv-pci.h>
1617

1718
#include "cxl.h"
1819

@@ -24,6 +25,8 @@ struct cxl_context *cxl_dev_context_init(struct pci_dev *dev)
2425
int rc;
2526

2627
afu = cxl_pci_to_afu(dev);
28+
if (IS_ERR(afu))
29+
return ERR_CAST(afu);
2730

2831
ctx = cxl_context_alloc();
2932
if (IS_ERR(ctx)) {
@@ -438,6 +441,8 @@ EXPORT_SYMBOL_GPL(cxl_perst_reloads_same_image);
438441
ssize_t cxl_read_adapter_vpd(struct pci_dev *dev, void *buf, size_t count)
439442
{
440443
struct cxl_afu *afu = cxl_pci_to_afu(dev);
444+
if (IS_ERR(afu))
445+
return -ENODEV;
441446

442447
return cxl_ops->read_adapter_vpd(afu->adapter, buf, count);
443448
}

‎drivers/misc/cxl/pci.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,9 @@ static int cxl_probe(struct pci_dev *dev, const struct pci_device_id *id)
15021502
dev_err(&dev->dev, "AFU %i failed to start: %i\n", slice, rc);
15031503
}
15041504

1505+
if (pnv_pci_on_cxl_phb(dev) && adapter->slices >= 1)
1506+
pnv_cxl_phb_set_peer_afu(dev, adapter->afu[0]);
1507+
15051508
return 0;
15061509
}
15071510

‎drivers/misc/cxl/vphb.c‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <linux/pci.h>
1111
#include <misc/cxl.h>
12+
#include <asm/pnv-pci.h>
1213
#include "cxl.h"
1314

1415
static int cxl_dma_set_mask(struct pci_dev *pdev, u64 dma_mask)
@@ -258,13 +259,18 @@ void cxl_pci_vphb_remove(struct cxl_afu *afu)
258259
pcibios_free_controller(phb);
259260
}
260261

262+
static bool _cxl_pci_is_vphb_device(struct pci_controller *phb)
263+
{
264+
return (phb->ops == &cxl_pcie_pci_ops);
265+
}
266+
261267
bool cxl_pci_is_vphb_device(struct pci_dev *dev)
262268
{
263269
struct pci_controller *phb;
264270

265271
phb = pci_bus_to_host(dev->bus);
266272

267-
return (phb->ops == &cxl_pcie_pci_ops);
273+
return _cxl_pci_is_vphb_device(phb);
268274
}
269275

270276
struct cxl_afu *cxl_pci_to_afu(struct pci_dev *dev)
@@ -273,7 +279,13 @@ struct cxl_afu *cxl_pci_to_afu(struct pci_dev *dev)
273279

274280
phb = pci_bus_to_host(dev->bus);
275281

276-
return (struct cxl_afu *)phb->private_data;
282+
if (_cxl_pci_is_vphb_device(phb))
283+
return (struct cxl_afu *)phb->private_data;
284+
285+
if (pnv_pci_on_cxl_phb(dev))
286+
return pnv_cxl_phb_to_afu(phb);
287+
288+
return ERR_PTR(-ENODEV);
277289
}
278290
EXPORT_SYMBOL_GPL(cxl_pci_to_afu);
279291

0 commit comments

Comments
 (0)