linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Axtens <dja@axtens.net>
To: linuxppc-dev@ozlabs.org
Cc: mpe@ellerman.id.au, benh@kernel.crashing.org, cyrilbur@gmail.com,
	"Matthew R. Ochs" <mrochs@linux.vnet.ibm.com>,
	Manoj Kumar <kumarmn@us.ibm.com>,
	mikey@neuling.org, imunsie@au.ibm.com,
	Daniel Axtens <dja@axtens.net>
Subject: [PATCH v4 07/11] cxl: Refactor AFU init/teardown
Date: Thu, 13 Aug 2015 14:11:25 +1000	[thread overview]
Message-ID: <1439439089-25151-8-git-send-email-dja@axtens.net> (raw)
In-Reply-To: <1439439089-25151-1-git-send-email-dja@axtens.net>

As with an adapter, some aspects of initialisation are done only once
in the lifetime of an AFU: for example, allocating memory, or setting
up sysfs/debugfs files.

However, we may want to be able to do some parts of the initialisation
multiple times: for example, in error recovery we want to be able to
tear down and then re-map IO memory and IRQs.

Therefore, refactor AFU init/teardown as follows.

 - Create two new functions: 'cxl_configure_afu', and its pair
   'cxl_deconfigure_afu'. As with the adapter functions,
   these (de)configure resources that do not need to last the entire
   lifetime of the AFU.

 - Allocating and releasing memory remain the task of 'cxl_alloc_afu'
   and 'cxl_release_afu'.

 - Once-only functions that do not involve allocating/releasing memory
   stay in the overarching 'cxl_init_afu'/'cxl_remove_afu' pair.
   However, the task of picking an AFU mode and activating it has been
   broken out.

Signed-off-by: Daniel Axtens <dja@axtens.net>
---
 drivers/misc/cxl/pci.c | 124 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 77 insertions(+), 47 deletions(-)

diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
index f3c5998f2f37..8e7b0f3ad254 100644
--- a/drivers/misc/cxl/pci.c
+++ b/drivers/misc/cxl/pci.c
@@ -752,45 +752,77 @@ ssize_t cxl_afu_read_err_buffer(struct cxl_afu *afu, char *buf,
 	return count;
 }
 
-static int cxl_init_afu(struct cxl *adapter, int slice, struct pci_dev *dev)
+static int cxl_configure_afu(struct cxl_afu *afu, struct cxl *adapter, struct pci_dev *dev)
 {
-	struct cxl_afu *afu;
-	bool free = true;
 	int rc;
 
-	if (!(afu = cxl_alloc_afu(adapter, slice)))
-		return -ENOMEM;
-
-	if ((rc = dev_set_name(&afu->dev, "afu%i.%i", adapter->adapter_num, slice)))
-		goto err1;
+	rc = cxl_map_slice_regs(afu, adapter, dev);
+	if (rc)
+		return rc;
 
-	if ((rc = cxl_map_slice_regs(afu, adapter, dev)))
+	rc = sanitise_afu_regs(afu);
+	if (rc)
 		goto err1;
 
-	if ((rc = sanitise_afu_regs(afu)))
-		goto err2;
-
 	/* We need to reset the AFU before we can read the AFU descriptor */
-	if ((rc = __cxl_afu_reset(afu)))
-		goto err2;
+	rc = __cxl_afu_reset(afu);
+	if (rc)
+		goto err1;
 
 	if (cxl_verbose)
 		dump_afu_descriptor(afu);
 
-	if ((rc = cxl_read_afu_descriptor(afu)))
-		goto err2;
+	rc = cxl_read_afu_descriptor(afu);
+	if (rc)
+		goto err1;
 
-	if ((rc = cxl_afu_descriptor_looks_ok(afu)))
-		goto err2;
+	rc = cxl_afu_descriptor_looks_ok(afu);
+	if (rc)
+		goto err1;
 
-	if ((rc = init_implementation_afu_regs(afu)))
-		goto err2;
+	rc = init_implementation_afu_regs(afu);
+	if (rc)
+		goto err1;
+
+	rc = cxl_register_serr_irq(afu);
+	if (rc)
+		goto err1;
 
-	if ((rc = cxl_register_serr_irq(afu)))
+	rc = cxl_register_psl_irq(afu);
+	if (rc)
 		goto err2;
 
-	if ((rc = cxl_register_psl_irq(afu)))
-		goto err3;
+	return 0;
+
+err2:
+	cxl_release_serr_irq(afu);
+err1:
+	cxl_unmap_slice_regs(afu);
+	return rc;
+}
+
+static void cxl_deconfigure_afu(struct cxl_afu *afu)
+{
+	cxl_release_psl_irq(afu);
+	cxl_release_serr_irq(afu);
+	cxl_unmap_slice_regs(afu);
+}
+
+static int cxl_init_afu(struct cxl *adapter, int slice, struct pci_dev *dev)
+{
+	struct cxl_afu *afu;
+	int rc;
+
+	if (!(afu = cxl_alloc_afu(adapter, slice)))
+		return -ENOMEM;
+
+	rc = dev_set_name(&afu->dev, "afu%i.%i", adapter->adapter_num, slice);
+	if (rc)
+		goto err_free;
+
+	rc = cxl_configure_afu(afu, adapter, dev);
+	if (rc)
+		goto err_free;
 
 	/* Don't care if this fails */
 	cxl_debugfs_afu_add(afu);
@@ -799,38 +831,32 @@ static int cxl_init_afu(struct cxl *adapter, int slice, struct pci_dev *dev)
 	 * After we call this function we must not free the afu directly, even
 	 * if it returns an error!
 	 */
-	if ((rc = cxl_register_afu(afu)))
+	rc = cxl_register_afu(afu);
+	if (rc)
 		goto err_put1;
 
-	if ((rc = cxl_sysfs_afu_add(afu)))
+	rc = cxl_sysfs_afu_add(afu);
+	if (rc)
 		goto err_put1;
 
-
-	if ((rc = cxl_afu_select_best_mode(afu)))
-		goto err_put2;
-
 	adapter->afu[afu->slice] = afu;
 
-	if ((rc = cxl_pci_vphb_add(afu)))
+	rc = cxl_pci_vphb_add(afu);
+	if (rc)
 		dev_info(&afu->dev, "Can't register vPHB\n");
 
 	return 0;
 
-err_put2:
-	cxl_sysfs_afu_remove(afu);
 err_put1:
-	device_unregister(&afu->dev);
-	free = false;
+	cxl_deconfigure_afu(afu);
 	cxl_debugfs_afu_remove(afu);
-	cxl_release_psl_irq(afu);
-err3:
-	cxl_release_serr_irq(afu);
-err2:
-	cxl_unmap_slice_regs(afu);
-err1:
-	if (free)
-		kfree(afu);
+	device_unregister(&afu->dev);
 	return rc;
+
+err_free:
+	kfree(afu);
+	return rc;
+
 }
 
 static void cxl_remove_afu(struct cxl_afu *afu)
@@ -850,10 +876,7 @@ static void cxl_remove_afu(struct cxl_afu *afu)
 	cxl_context_detach_all(afu);
 	cxl_afu_deactivate_mode(afu);
 
-	cxl_release_psl_irq(afu);
-	cxl_release_serr_irq(afu);
-	cxl_unmap_slice_regs(afu);
-
+	cxl_deconfigure_afu(afu);
 	device_unregister(&afu->dev);
 }
 
@@ -1218,8 +1241,15 @@ static int cxl_probe(struct pci_dev *dev, const struct pci_device_id *id)
 	}
 
 	for (slice = 0; slice < adapter->slices; slice++) {
-		if ((rc = cxl_init_afu(adapter, slice, dev)))
+		rc = cxl_init_afu(adapter, slice, dev);
+		if (rc) {
 			dev_err(&dev->dev, "AFU %i failed to initialise: %i\n", slice, rc);
+			continue;
+		}
+
+		rc = cxl_afu_select_best_mode(adapter->afu[slice]);
+		if (rc)
+			dev_err(&dev->dev, "AFU %i failed to start: %i\n", slice, rc);
 	}
 
 	return 0;
-- 
2.1.4

  parent reply	other threads:[~2015-08-13  4:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-13  4:11 [PATCH v4 00/11] CXL EEH Handling Daniel Axtens
2015-08-13  4:11 ` [PATCH v4 01/11] cxl: Convert MMIO read/write macros to inline functions Daniel Axtens
2015-08-14  5:12   ` Ian Munsie
2015-08-13  4:11 ` [PATCH v4 02/11] cxl: Drop commands if the PCI channel is not in normal state Daniel Axtens
2015-08-14  5:23   ` Ian Munsie
2015-08-13  4:11 ` [PATCH v4 03/11] cxl: Allocate and release the SPA with the AFU Daniel Axtens
2015-08-14  5:35   ` Ian Munsie
2015-08-13  4:11 ` [PATCH v4 04/11] cxl: Make IRQ release idempotent Daniel Axtens
2015-08-14  5:35   ` Ian Munsie
2015-08-13  4:11 ` [PATCH v4 05/11] cxl: Clean up adapter MMIO unmap path Daniel Axtens
2015-08-14  5:37   ` Ian Munsie
2015-08-13  4:11 ` [PATCH v4 06/11] cxl: Refactor adaptor init/teardown Daniel Axtens
2015-08-14  6:12   ` Ian Munsie
2015-08-14  7:55     ` Daniel Axtens
2015-08-13  4:11 ` Daniel Axtens [this message]
2015-08-14  6:22   ` [PATCH v4 07/11] cxl: Refactor AFU init/teardown Ian Munsie
2015-08-13  4:11 ` [PATCH v4 08/11] cxl: Don't remove AFUs/vPHBs in cxl_reset Daniel Axtens
2015-08-14  6:23   ` Ian Munsie
2015-08-13  4:11 ` [PATCH v4 09/11] cxl: Allow the kernel to trust that an image won't change on PERST Daniel Axtens
2015-08-14  6:27   ` Ian Munsie
2015-08-13  4:11 ` [PATCH v4 10/11] cxl: EEH support Daniel Axtens
2015-08-14  6:31   ` Ian Munsie
2015-08-13  4:11 ` [PATCH v4 11/11] cxl: Add CONFIG_CXL_EEH symbol Daniel Axtens
2015-08-14  6:33   ` Ian Munsie

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=1439439089-25151-8-git-send-email-dja@axtens.net \
    --to=dja@axtens.net \
    --cc=benh@kernel.crashing.org \
    --cc=cyrilbur@gmail.com \
    --cc=imunsie@au.ibm.com \
    --cc=kumarmn@us.ibm.com \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=mikey@neuling.org \
    --cc=mpe@ellerman.id.au \
    --cc=mrochs@linux.vnet.ibm.com \
    /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).