All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cxl: Ignore CAPI adapters misplaced in switched slots
@ 2016-06-30 11:45 Philippe Bergheaud
  2016-06-30 17:02 ` Ian Munsie
  2016-07-01  8:53 ` Frederic Barrat
  0 siblings, 2 replies; 3+ messages in thread
From: Philippe Bergheaud @ 2016-06-30 11:45 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: mpe, imunsie, mikey, tgrobeck, Philippe Bergheaud

One should not attempt to switch a PHB into CAPI mode if there is
a switch between the PHB and the adapter. This patch modifies the
cxl driver to ignore CAPI adapters misplaced in switched slots.

Signed-off-by: Philippe Bergheaud <felix@linux.vnet.ibm.com>
---
This patch fixes Bz 142217.

 drivers/misc/cxl/pci.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
index a08fcc8..2f978ed 100644
--- a/drivers/misc/cxl/pci.c
+++ b/drivers/misc/cxl/pci.c
@@ -1280,6 +1280,30 @@ static void cxl_pci_remove_adapter(struct cxl *adapter)
 	device_unregister(&adapter->dev);
 }
 
+#define CXL_MAX_PCIEX_PARENT 2
+
+static int cxl_slot_is_switched(struct pci_dev *dev)
+{
+	struct device_node *np;
+	int depth = 0;
+	const __be32 *prop;
+
+	if (!(np = pci_device_to_OF_node(dev))) {
+		pr_err("cxl: np = NULL\n");
+		return -ENODEV;
+	}
+	of_node_get(np);
+	while (np) {
+		np = of_get_next_parent(np);
+		prop = of_get_property(np, "device_type", NULL);
+		if (!prop || strcmp((char *)prop, "pciex"))
+			break;
+		depth++;
+	}
+	of_node_put(np);
+	return (depth > CXL_MAX_PCIEX_PARENT);
+}
+
 static int cxl_probe(struct pci_dev *dev, const struct pci_device_id *id)
 {
 	struct cxl *adapter;
@@ -1291,6 +1315,11 @@ static int cxl_probe(struct pci_dev *dev, const struct pci_device_id *id)
 		return -ENODEV;
 	}
 
+	if (cxl_slot_is_switched(dev)) {
+		dev_dbg(&dev->dev, "cxl_init_adapter: Ignoring switched slot device\n");
+		return -ENODEV;
+	}
+
 	if (cxl_verbose)
 		dump_cxl_config_space(dev);
 
-- 
2.8.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] cxl: Ignore CAPI adapters misplaced in switched slots
  2016-06-30 11:45 [PATCH] cxl: Ignore CAPI adapters misplaced in switched slots Philippe Bergheaud
@ 2016-06-30 17:02 ` Ian Munsie
  2016-07-01  8:53 ` Frederic Barrat
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Munsie @ 2016-06-30 17:02 UTC (permalink / raw)
  To: Philippe Bergheaud; +Cc: linuxppc-dev, mikey, tgrobeck

Thanks Philippe - this looks like a decent solution to the problem (and
I intend to use this for the upcoming cx4 support as well).

Acked-by: Ian Munsie <imunsie@au1.ibm.com>

Excerpts from Philippe Bergheaud's message of 2016-06-30 13:45:37 +0200:
> One should not attempt to switch a PHB into CAPI mode if there is
> a switch between the PHB and the adapter. This patch modifies the
> cxl driver to ignore CAPI adapters misplaced in switched slots.
> 
> Signed-off-by: Philippe Bergheaud <felix@linux.vnet.ibm.com>
> ---
> This patch fixes Bz 142217.
> 
>  drivers/misc/cxl/pci.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
> index a08fcc8..2f978ed 100644
> --- a/drivers/misc/cxl/pci.c
> +++ b/drivers/misc/cxl/pci.c
> @@ -1280,6 +1280,30 @@ static void cxl_pci_remove_adapter(struct cxl *adapter)
>      device_unregister(&adapter->dev);
>  }
>  
> +#define CXL_MAX_PCIEX_PARENT 2
> +
> +static int cxl_slot_is_switched(struct pci_dev *dev)
> +{
> +    struct device_node *np;
> +    int depth = 0;
> +    const __be32 *prop;
> +
> +    if (!(np = pci_device_to_OF_node(dev))) {
> +        pr_err("cxl: np = NULL\n");
> +        return -ENODEV;
> +    }
> +    of_node_get(np);
> +    while (np) {
> +        np = of_get_next_parent(np);
> +        prop = of_get_property(np, "device_type", NULL);
> +        if (!prop || strcmp((char *)prop, "pciex"))
> +            break;
> +        depth++;
> +    }
> +    of_node_put(np);
> +    return (depth > CXL_MAX_PCIEX_PARENT);
> +}
> +
>  static int cxl_probe(struct pci_dev *dev, const struct pci_device_id *id)
>  {
>      struct cxl *adapter;
> @@ -1291,6 +1315,11 @@ static int cxl_probe(struct pci_dev *dev, const struct pci_device_id *id)
>          return -ENODEV;
>      }
>  
> +    if (cxl_slot_is_switched(dev)) {
> +        dev_dbg(&dev->dev, "cxl_init_adapter: Ignoring switched slot device\n");
> +        return -ENODEV;
> +    }
> +
>      if (cxl_verbose)
>          dump_cxl_config_space(dev);
>  

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] cxl: Ignore CAPI adapters misplaced in switched slots
  2016-06-30 11:45 [PATCH] cxl: Ignore CAPI adapters misplaced in switched slots Philippe Bergheaud
  2016-06-30 17:02 ` Ian Munsie
@ 2016-07-01  8:53 ` Frederic Barrat
  1 sibling, 0 replies; 3+ messages in thread
From: Frederic Barrat @ 2016-07-01  8:53 UTC (permalink / raw)
  To: Philippe Bergheaud, linuxppc-dev; +Cc: mikey, imunsie, tgrobeck

Salut Philippe,

Le 30/06/2016 13:45, Philippe Bergheaud a écrit :
> +	if (cxl_slot_is_switched(dev)) {
> +		dev_dbg(&dev->dev, "cxl_init_adapter: Ignoring switched slot device\n");
> +		return -ENODEV;
> +	}


I think it would be useful for the user who has inserted the card in the 
wrong slot to be notified, i.e. raise the level of the message. 
Otherwise he would be wondering why the card is not recognized.

   Fred

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-07-01  8:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-30 11:45 [PATCH] cxl: Ignore CAPI adapters misplaced in switched slots Philippe Bergheaud
2016-06-30 17:02 ` Ian Munsie
2016-07-01  8:53 ` Frederic Barrat

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.