From: Frederic Barrat <fbarrat@linux.vnet.ibm.com>
To: Ian Munsie <imunsie@au1.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Michael Neuling <mikey@neuling.org>,
Andrew Donnellan <andrew.donnellan@au1.ibm.com>,
linuxppc-dev@lists.ozlabs.org, Huy Nguyen <huyn@mellanox.com>
Cc: Gavin Shan <gwshan@linux.vnet.ibm.com>
Subject: Re: [PATCH 14/14] cxl: Add cxl_check_and_switch_mode() API to switch bi-modal cards
Date: Wed, 6 Jul 2016 20:51:42 +0200 [thread overview]
Message-ID: <577D533E.4030605@linux.vnet.ibm.com> (raw)
In-Reply-To: <1467638532-9250-15-git-send-email-imunsie@au.ibm.com>
Le 04/07/2016 15:22, Ian Munsie a écrit :
> From: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
>
> Add a new API, cxl_check_and_switch_mode() to allow for switching of
> bi-modal CAPI cards, such as the Mellanox CX-4 network card.
>
> When a driver requests to switch a card to CAPI mode, use PCI hotplug
> infrastructure to remove all PCI devices underneath the slot. We then write
> an updated mode control register to the CAPI VSEC, hot reset the card, and
> reprobe the card.
>
> As the card may present a different set of PCI devices after the mode
> switch, use the infrastructure provided by the pnv_php driver and the OPAL
> PCI slot management facilities to ensure that:
>
> * the old devices are removed from both the OPAL and Linux device trees
> * the new devices are probed by OPAL and added to the OPAL device tree
> * the new devices are added to the Linux device tree and probed through
> the regular PCI device probe path
>
> As such, introduce a new option, CONFIG_CXL_BIMODAL, with a dependency on
> the pnv_php driver.
>
> Refactor existing code that touches the mode control register in the
> regular single mode case into a new function, setup_cxl_protocol_area().
>
> Co-authored-by: Ian Munsie <imunsie@au1.ibm.com>
> Cc: Gavin Shan <gwshan@linux.vnet.ibm.com>
> Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
> Reviewed-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
> ---
> drivers/misc/cxl/Kconfig | 8 ++
> drivers/misc/cxl/pci.c | 234 +++++++++++++++++++++++++++++++++++++++++++----
> include/misc/cxl.h | 25 +++++
> 3 files changed, 249 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/misc/cxl/Kconfig b/drivers/misc/cxl/Kconfig
> index 560412c..6859723 100644
> --- a/drivers/misc/cxl/Kconfig
> +++ b/drivers/misc/cxl/Kconfig
> @@ -38,3 +38,11 @@ config CXL
> CAPI adapters are found in POWER8 based systems.
>
> If unsure, say N.
> +
> +config CXL_BIMODAL
> + bool "Support for bi-modal CAPI cards"
> + depends on HOTPLUG_PCI_POWERNV = y && CXL || HOTPLUG_PCI_POWERNV = m && CXL = m
> + default y
> + help
> + Select this option to enable support for bi-modal CAPI cards, such as
> + the Mellanox CX-4.
> \ No newline at end of file
> diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
> index 090eee8..63abd26 100644
> --- a/drivers/misc/cxl/pci.c
> +++ b/drivers/misc/cxl/pci.c
> @@ -55,6 +55,8 @@
> pci_read_config_byte(dev, vsec + 0xa, dest)
> #define CXL_WRITE_VSEC_MODE_CONTROL(dev, vsec, val) \
> pci_write_config_byte(dev, vsec + 0xa, val)
> +#define CXL_WRITE_VSEC_MODE_CONTROL_BUS(bus, devfn, vsec, val) \
> + pci_bus_write_config_byte(bus, devfn, vsec + 0xa, val)
> #define CXL_VSEC_PROTOCOL_MASK 0xe0
> #define CXL_VSEC_PROTOCOL_1024TB 0x80
> #define CXL_VSEC_PROTOCOL_512TB 0x40
> @@ -614,36 +616,232 @@ static int setup_cxl_bars(struct pci_dev *dev)
> return 0;
> }
>
> -/* pciex node: ibm,opal-m64-window = <0x3d058 0x0 0x3d058 0x0 0x8 0x0>; */
> -static int switch_card_to_cxl(struct pci_dev *dev)
> -{
> +#ifdef CONFIG_CXL_BIMODAL
> +
> +struct cxl_switch_work {
> + struct pci_dev *dev;
> + struct work_struct work;
> int vsec;
> + int mode;
> +};
> +
> +static void switch_card_to_cxl(struct work_struct *work)
> +{
> + struct cxl_switch_work *switch_work =
> + container_of(work, struct cxl_switch_work, work);
> + struct pci_dev *dev = switch_work->dev;
> + struct pci_bus *bus = dev->bus;
> + struct pci_controller *hose = pci_bus_to_host(bus);
> + struct pci_dev *bridge;
> + struct pnv_php_slot *php_slot;
> + unsigned int devfn;
> u8 val;
> int rc;
>
> - dev_info(&dev->dev, "switch card to CXL\n");
> + dev_info(&bus->dev, "cxl: Preparing for mode switch...\n");
> + bridge = list_first_entry_or_null(&hose->bus->devices, struct pci_dev,
> + bus_list);
> + if (!bridge) {
> + dev_WARN(&bus->dev, "cxl: Couldn't find root port!\n");
> + goto err_free_work;
> + }
>
> - if (!(vsec = find_cxl_vsec(dev))) {
> - dev_err(&dev->dev, "ABORTING: CXL VSEC not found!\n");
> + php_slot = pnv_php_find_slot(pci_device_to_OF_node(bridge));
> + if (!php_slot) {
> + dev_err(&bus->dev, "cxl: Failed to find slot hotplug "
> + "information. You may need to upgrade "
> + "skiboot. Aborting.\n");
> + pci_dev_put(dev);
> + goto err_free_work;
> + }
> +
> + rc = CXL_READ_VSEC_MODE_CONTROL(dev, switch_work->vsec, &val);
> + if (rc) {
> + dev_err(&bus->dev, "cxl: Failed to read CAPI mode control: %i\n", rc);
> + pci_dev_put(dev);
> + goto err_free_work;
> + }
> + devfn = dev->devfn;
> + pci_dev_put(dev);
This is to balance the 'get' done in cxl_check_and_switch_mode(), right?
A comment wouldn't hurt. I think we're missing the 'put' on the first
error path above (!bridge).
I was half-expecting to see a new entry in the cxl_pci_tbl pci ID table
for the Mellanox entry, but no such thing. By what magic is cxl_probe()
called after the switch? Because of the device class?
Out of curiosity, could you tell me what the 3rd pci function looks like
(vendor ID, device ID, ....)?
Thanks!
Fred
next prev parent reply other threads:[~2016-07-06 18:51 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-04 13:21 powerpc / cxl: Add support for the Mellanox CX4 in cxl mode Ian Munsie
2016-07-04 13:21 ` [PATCH 01/14] powerpc/powernv: Split cxl code out into a separate file Ian Munsie
2016-07-06 3:44 ` Andrew Donnellan
2016-07-06 16:27 ` Frederic Barrat
2016-07-04 13:22 ` [PATCH 02/14] cxl: Add cxl_slot_is_supported API Ian Munsie
2016-07-06 2:02 ` Andrew Donnellan
2016-07-06 16:36 ` Frederic Barrat
2016-07-04 13:22 ` [PATCH 03/14] cxl: Enable bus mastering for devices using CAPP DMA mode Ian Munsie
2016-07-06 4:04 ` Andrew Donnellan
2016-07-06 16:37 ` Frederic Barrat
2016-07-04 13:22 ` [PATCH 04/14] cxl: Move cxl_afu_get / cxl_afu_put to base Ian Munsie
2016-07-05 2:10 ` Andrew Donnellan
2016-07-06 16:45 ` Frederic Barrat
2016-07-04 13:22 ` [PATCH 05/14] cxl: Allow a default context to be associated with an external pci_dev Ian Munsie
2016-07-06 16:51 ` Frederic Barrat
2016-07-04 13:22 ` [PATCH 06/14] powerpc/powernv: Add support for the cxl kernel api on the real phb Ian Munsie
2016-07-06 17:38 ` Frederic Barrat
2016-07-07 6:28 ` Ian Munsie
2016-07-04 13:22 ` [PATCH 07/14] cxl: Add support for using the kernel API with a real PHB Ian Munsie
2016-07-06 17:39 ` Frederic Barrat
2016-07-06 18:30 ` Frederic Barrat
2016-07-07 6:32 ` Ian Munsie
2016-07-04 13:22 ` [PATCH 08/14] cxl: Add kernel APIs to get & set the max irqs per context Ian Munsie
2016-07-06 18:11 ` Frederic Barrat
2016-07-07 6:00 ` Ian Munsie
2016-07-04 13:22 ` [PATCH 09/14] cxl: Add preliminary workaround for CX4 interrupt limitation Ian Munsie
2016-07-06 18:34 ` Frederic Barrat
2016-07-04 13:22 ` [PATCH 10/14] cxl: Add support for interrupts on the Mellanox CX4 Ian Munsie
2016-07-06 18:41 ` Frederic Barrat
2016-07-07 6:03 ` Ian Munsie
2016-07-04 13:22 ` [PATCH 11/14] cxl: Workaround PE=0 hardware limitation in " Ian Munsie
2016-07-06 4:42 ` Andrew Donnellan
2016-07-06 18:42 ` Frederic Barrat
2016-07-04 13:22 ` [PATCH 12/14] PCI/hotplug: pnv_php: export symbols and move struct types needed by cxl Ian Munsie
2016-07-05 0:03 ` Gavin Shan
2016-07-05 1:08 ` Andrew Donnellan
2016-07-04 13:22 ` [PATCH 13/14] PCI/hotplug: pnv_php: handle OPAL_PCI_SLOT_OFFLINE power state Ian Munsie
2016-07-04 13:22 ` [PATCH 14/14] cxl: Add cxl_check_and_switch_mode() API to switch bi-modal cards Ian Munsie
2016-07-06 3:55 ` Andrew Donnellan
2016-07-06 18:51 ` Frederic Barrat [this message]
2016-07-07 1:18 ` Andrew Donnellan
2016-07-07 6:26 ` Ian Munsie
2016-07-07 6:44 ` Andrew Donnellan
2016-07-07 8:15 ` Andrew Donnellan
2016-07-11 9:19 ` Ian Munsie
2016-07-12 1:20 ` Andrew Donnellan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=577D533E.4030605@linux.vnet.ibm.com \
--to=fbarrat@linux.vnet.ibm.com \
--cc=andrew.donnellan@au1.ibm.com \
--cc=gwshan@linux.vnet.ibm.com \
--cc=huyn@mellanox.com \
--cc=imunsie@au1.ibm.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mikey@neuling.org \
--cc=mpe@ellerman.id.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).