On 11/27/2019 2:50 PM, Kishon Vijay Abraham I wrote:
Hi,Nope. I'll remove them.
On 13/11/19 2:38 PM, Vidya Sagar wrote:
Add support to defer core initialization and to receive a notifier
when core is ready to accommodate platforms where core is not for
initialization untile reference clock from host is available.
Signed-off-by: Vidya Sagar <vidyas@xxxxxxxxxx>
---
 drivers/pci/endpoint/functions/pci-epf-test.c | 114 ++++++++++++------
 1 file changed, 77 insertions(+), 37 deletions(-)
diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index bddff15052cc..068024fab544 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -360,18 +360,6 @@ static void pci_epf_test_cmd_handler(struct work_struct *work)
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ msecs_to_jiffies(1));
 }
-static int pci_epf_test_notifier(struct notifier_block *nb, unsigned long val,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ void *data)
-{
-ÂÂÂ struct pci_epf *epf = container_of(nb, struct pci_epf, nb);
-ÂÂÂ struct pci_epf_test *epf_test = epf_get_drvdata(epf);
-
-ÂÂÂ queue_delayed_work(kpcitest_workqueue, &epf_test->cmd_handler,
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ msecs_to_jiffies(1));
-
-ÂÂÂ return NOTIFY_OK;
-}
-
 static void pci_epf_test_unbind(struct pci_epf *epf)
 {
ÂÂÂÂÂ struct pci_epf_test *epf_test = epf_get_drvdata(epf);
@@ -428,6 +416,78 @@ static int pci_epf_test_set_bar(struct pci_epf *epf)
ÂÂÂÂÂ return 0;
 }
+static int pci_epf_test_core_init(struct pci_epf *epf)
+{
+ÂÂÂ struct pci_epf_header *header = epf->header;
+ÂÂÂ const struct pci_epc_features *epc_features;
+ÂÂÂ struct pci_epc *epc = epf->epc;
+ÂÂÂ struct device *dev = &epf->dev;
+ÂÂÂ bool msix_capable = false;
+ÂÂÂ bool msi_capable = true;
+ÂÂÂ int ret;
+
+ÂÂÂ epc_features = pci_epc_get_features(epc, epf->func_no);
+ÂÂÂ if (epc_features) {
+ÂÂÂÂÂÂÂ msix_capable = epc_features->msix_capable;
+ÂÂÂÂÂÂÂ msi_capable = epc_features->msi_capable;
+ÂÂÂ }
+
+ÂÂÂ ret = pci_epc_write_header(epc, epf->func_no, header);
+ÂÂÂ if (ret) {
+ÂÂÂÂÂÂÂ dev_err(dev, "Configuration header write failed\n");
+ÂÂÂÂÂÂÂ return ret;
+ÂÂÂ }
+
+ÂÂÂ ret = pci_epf_test_set_bar(epf);
+ÂÂÂ if (ret)
+ÂÂÂÂÂÂÂ return ret;
+
+ÂÂÂ if (msi_capable) {
+ÂÂÂÂÂÂÂ ret = pci_epc_set_msi(epc, epf->func_no, epf->msi_interrupts);
+ÂÂÂÂÂÂÂ if (ret) {
+ÂÂÂÂÂÂÂÂÂÂÂ dev_err(dev, "MSI configuration failed\n");
+ÂÂÂÂÂÂÂÂÂÂÂ return ret;
+ÂÂÂÂÂÂÂ }
+ÂÂÂ }
+
+ÂÂÂ if (msix_capable) {
+ÂÂÂÂÂÂÂ ret = pci_epc_set_msix(epc, epf->func_no, epf->msix_interrupts);
+ÂÂÂÂÂÂÂ if (ret) {
+ÂÂÂÂÂÂÂÂÂÂÂ dev_err(dev, "MSI-X configuration failed\n");
+ÂÂÂÂÂÂÂÂÂÂÂ return ret;
+ÂÂÂÂÂÂÂ }
+ÂÂÂ }
+
+ÂÂÂ return 0;
+}
+
+static int pci_epf_test_notifier(struct notifier_block *nb, unsigned long val,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ void *data)
+{
+ÂÂÂ struct pci_epf *epf = container_of(nb, struct pci_epf, nb);
+ÂÂÂ struct pci_epf_test *epf_test = epf_get_drvdata(epf);
+ÂÂÂ int ret;
+
+ÂÂÂ switch (val) {
+ÂÂÂ case CORE_INIT:
+ÂÂÂÂÂÂÂ ret = pci_epf_test_core_init(epf);
+ÂÂÂÂÂÂÂ if (ret)
+ÂÂÂÂÂÂÂÂÂÂÂ return NOTIFY_BAD;
+ÂÂÂÂÂÂÂ break;
+
+ÂÂÂ case LINK_UP:
+ÂÂÂÂÂÂÂ queue_delayed_work(kpcitest_workqueue, &epf_test->cmd_handler,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ msecs_to_jiffies(1));
+ÂÂÂÂÂÂÂ break;
+
+ÂÂÂ default:
+ÂÂÂÂÂÂÂ dev_err(&epf->dev, "Invalid EPF test notifier event\n");
+ÂÂÂÂÂÂÂ return NOTIFY_BAD;
+ÂÂÂ }
+
+ÂÂÂ return NOTIFY_OK;
+}
+
 static int pci_epf_test_alloc_space(struct pci_epf *epf)
 {
ÂÂÂÂÂ struct pci_epf_test *epf_test = epf_get_drvdata(epf);
@@ -496,12 +556,11 @@ static int pci_epf_test_bind(struct pci_epf *epf)
 {
ÂÂÂÂÂ int ret;
ÂÂÂÂÂ struct pci_epf_test *epf_test = epf_get_drvdata(epf);
-ÂÂÂ struct pci_epf_header *header = epf->header;
ÂÂÂÂÂ const struct pci_epc_features *epc_features;
ÂÂÂÂÂ enum pci_barno test_reg_bar = BAR_0;
ÂÂÂÂÂ struct pci_epc *epc = epf->epc;
-ÂÂÂ struct device *dev = &epf->dev;
ÂÂÂÂÂ bool linkup_notifier = false;
+ÂÂÂ bool skip_core_init = false;
ÂÂÂÂÂ bool msix_capable = false;
ÂÂÂÂÂ bool msi_capable = true;
@@ -511,6 +570,7 @@ static int pci_epf_test_bind(struct pci_epf *epf)
ÂÂÂÂÂ epc_features = pci_epc_get_features(epc, epf->func_no);
ÂÂÂÂÂ if (epc_features) {
ÂÂÂÂÂÂÂÂÂ linkup_notifier = epc_features->linkup_notifier;
+ÂÂÂÂÂÂÂ skip_core_init = epc_features->skip_core_init;
ÂÂÂÂÂÂÂÂÂ msix_capable = epc_features->msix_capable;
ÂÂÂÂÂÂÂÂÂ msi_capable = epc_features->msi_capable;
Are these used anywhere in this function?
Yes, but I would like to keep only the code that touches hardware in pci_epf_test_core_init()ÂÂÂÂÂÂÂÂÂ test_reg_bar = pci_epc_get_first_free_bar(epc_features);
@@ -520,34 +580,14 @@ static int pci_epf_test_bind(struct pci_epf *epf)
ÂÂÂÂÂ epf_test->test_reg_bar = test_reg_bar;
ÂÂÂÂÂ epf_test->epc_features = epc_features;
-ÂÂÂ ret = pci_epc_write_header(epc, epf->func_no, header);
-ÂÂÂ if (ret) {
-ÂÂÂÂÂÂÂ dev_err(dev, "Configuration header write failed\n");
-ÂÂÂÂÂÂÂ return ret;
-ÂÂÂ }
-
ÂÂÂÂÂ ret = pci_epf_test_alloc_space(epf);
ÂÂÂÂÂ if (ret)
ÂÂÂÂÂÂÂÂÂ return ret;
-ÂÂÂ ret = pci_epf_test_set_bar(epf);
-ÂÂÂ if (ret)
-ÂÂÂÂÂÂÂ return ret;
-
-ÂÂÂ if (msi_capable) {
-ÂÂÂÂÂÂÂ ret = pci_epc_set_msi(epc, epf->func_no, epf->msi_interrupts);
-ÂÂÂÂÂÂÂ if (ret) {
-ÂÂÂÂÂÂÂÂÂÂÂ dev_err(dev, "MSI configuration failed\n");
-ÂÂÂÂÂÂÂÂÂÂÂ return ret;
-ÂÂÂÂÂÂÂ }
-ÂÂÂ }
-
-ÂÂÂ if (msix_capable) {
-ÂÂÂÂÂÂÂ ret = pci_epc_set_msix(epc, epf->func_no, epf->msix_interrupts);
-ÂÂÂÂÂÂÂ if (ret) {
-ÂÂÂÂÂÂÂÂÂÂÂ dev_err(dev, "MSI-X configuration failed\n");
+ÂÂÂ if (!skip_core_init) {
+ÂÂÂÂÂÂÂ ret = pci_epf_test_core_init(epf);
+ÂÂÂÂÂÂÂ if (ret)
ÂÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
-ÂÂÂÂÂÂÂ }
ÂÂÂÂÂ }
ÂÂÂÂÂ if (linkup_notifier) {
This could as well be moved to pci_epf_test_core_init().
to minimize the time it takes to execute it. Is there any strong reason to move it? if not,
I would prefer to leave it here in this function itself.