[V2,4/4] PCI: endpoint: Add deinit in epf test driver

Message ID 20221013181815.2133-5-vidyas@nvidia.com
State New
Headers
Series Add DeInit support in the PCIe Endpoint framework |

Commit Message

Vidya Sagar Oct. 13, 2022, 6:18 p.m. UTC
  Add support for clearing the BAR info during the deinitialization phase of
the epf test driver.

Signed-off-by: Vidya Sagar <vidyas@nvidia.com>
---
V2:
* This is a new patch in this series

 drivers/pci/endpoint/functions/pci-epf-test.c | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)
  

Comments

Manivannan Sadhasivam Nov. 1, 2022, 12:54 p.m. UTC | #1
On Thu, Oct 13, 2022 at 11:48:15PM +0530, Vidya Sagar wrote:
> Add support for clearing the BAR info during the deinitialization phase of
> the epf test driver.
> 

BAR is currently cleared during unbind() time. With this deinit callback, it
has to be removed from unbind().

> Signed-off-by: Vidya Sagar <vidyas@nvidia.com>
> ---
> V2:
> * This is a new patch in this series
> 
>  drivers/pci/endpoint/functions/pci-epf-test.c | 30 +++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
> diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
> index 136470019a24..25ac3d161fac 100644
> --- a/drivers/pci/endpoint/functions/pci-epf-test.c
> +++ b/drivers/pci/endpoint/functions/pci-epf-test.c
> @@ -826,6 +826,35 @@ static int pci_epf_test_core_init(struct pci_epf *epf)
>  	return 0;
>  }
>  
> +static int pci_epf_test_clear_bar(struct pci_epf *epf)
> +{
> +	int bar, add;

I don't think "add" is a good variable name. Maybe "bar_type"?

Thanks,
Mani

> +	struct pci_epf_bar *epf_bar;
> +	struct pci_epc *epc = epf->epc;
> +	struct pci_epf_test *epf_test = epf_get_drvdata(epf);
> +	const struct pci_epc_features *epc_features;
> +
> +	epc_features = epf_test->epc_features;
> +
> +	for (bar = 0; bar < PCI_STD_NUM_BARS; bar += add) {
> +		epf_bar = &epf->bar[bar];
> +		add = (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) ? 2 : 1;
> +
> +		if (!!(epc_features->reserved_bar & (1 << bar)))
> +			continue;
> +
> +		pci_epc_clear_bar(epc, epf->func_no, epf->vfunc_no, epf_bar);
> +	}
> +
> +	return 0;
> +}
> +
> +static int pci_epf_test_core_deinit(struct pci_epf *epf)
> +{
> +	pci_epf_test_clear_bar(epf);
> +	return 0;
> +}
> +
>  int pci_epf_test_link_up(struct pci_epf *epf)
>  {
>  	struct pci_epf_test *epf_test = epf_get_drvdata(epf);
> @@ -839,6 +868,7 @@ int pci_epf_test_link_up(struct pci_epf *epf)
>  static const struct pci_epc_event_ops pci_epf_test_event_ops = {
>  	.core_init = pci_epf_test_core_init,
>  	.link_up = pci_epf_test_link_up,
> +	.core_deinit = pci_epf_test_core_deinit,
>  };
>  
>  static int pci_epf_test_alloc_space(struct pci_epf *epf)
> -- 
> 2.17.1
>
  

Patch

diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index 136470019a24..25ac3d161fac 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -826,6 +826,35 @@  static int pci_epf_test_core_init(struct pci_epf *epf)
 	return 0;
 }
 
+static int pci_epf_test_clear_bar(struct pci_epf *epf)
+{
+	int bar, add;
+	struct pci_epf_bar *epf_bar;
+	struct pci_epc *epc = epf->epc;
+	struct pci_epf_test *epf_test = epf_get_drvdata(epf);
+	const struct pci_epc_features *epc_features;
+
+	epc_features = epf_test->epc_features;
+
+	for (bar = 0; bar < PCI_STD_NUM_BARS; bar += add) {
+		epf_bar = &epf->bar[bar];
+		add = (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) ? 2 : 1;
+
+		if (!!(epc_features->reserved_bar & (1 << bar)))
+			continue;
+
+		pci_epc_clear_bar(epc, epf->func_no, epf->vfunc_no, epf_bar);
+	}
+
+	return 0;
+}
+
+static int pci_epf_test_core_deinit(struct pci_epf *epf)
+{
+	pci_epf_test_clear_bar(epf);
+	return 0;
+}
+
 int pci_epf_test_link_up(struct pci_epf *epf)
 {
 	struct pci_epf_test *epf_test = epf_get_drvdata(epf);
@@ -839,6 +868,7 @@  int pci_epf_test_link_up(struct pci_epf *epf)
 static const struct pci_epc_event_ops pci_epf_test_event_ops = {
 	.core_init = pci_epf_test_core_init,
 	.link_up = pci_epf_test_link_up,
+	.core_deinit = pci_epf_test_core_deinit,
 };
 
 static int pci_epf_test_alloc_space(struct pci_epf *epf)