diff mbox series

[v2,1/3] PCI: endpoint: Add 'started' to pci_epc to set whether the controller is started

Message ID 1611500977-24816-2-git-send-email-hayashi.kunihiko@socionext.com (mailing list archive)
State New, archived
Delegated to: Lorenzo Pieralisi
Headers show
Series PCI: endpoint: Add endpoint restart management support | expand

Commit Message

Kunihiko Hayashi Jan. 24, 2021, 3:09 p.m. UTC
This adds a member 'started' as a boolean value to struct pci_epc to set
whether the controller is started, and also adds a function to get the
value.

Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
---
 drivers/pci/endpoint/pci-epc-core.c | 2 ++
 include/linux/pci-epc.h             | 7 +++++++
 2 files changed, 9 insertions(+)

Comments

Kishon Vijay Abraham I Jan. 28, 2021, 2:11 p.m. UTC | #1
Hi Kunihiko,

On 24/01/21 8:39 pm, Kunihiko Hayashi wrote:
> This adds a member 'started' as a boolean value to struct pci_epc to set
> whether the controller is started, and also adds a function to get the
> value.
> 
> Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
> ---
>  drivers/pci/endpoint/pci-epc-core.c | 2 ++
>  include/linux/pci-epc.h             | 7 +++++++
>  2 files changed, 9 insertions(+)
> 
> diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
> index cc8f9eb..2904175 100644
> --- a/drivers/pci/endpoint/pci-epc-core.c
> +++ b/drivers/pci/endpoint/pci-epc-core.c
> @@ -174,6 +174,7 @@ void pci_epc_stop(struct pci_epc *epc)
>  
>  	mutex_lock(&epc->lock);
>  	epc->ops->stop(epc);
> +	epc->started = false;
>  	mutex_unlock(&epc->lock);
>  }
>  EXPORT_SYMBOL_GPL(pci_epc_stop);
> @@ -196,6 +197,7 @@ int pci_epc_start(struct pci_epc *epc)
>  
>  	mutex_lock(&epc->lock);
>  	ret = epc->ops->start(epc);
> +	epc->started = true;
>  	mutex_unlock(&epc->lock);
>  
>  	return ret;
> diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
> index b82c9b1..5808952 100644
> --- a/include/linux/pci-epc.h
> +++ b/include/linux/pci-epc.h
> @@ -131,6 +131,7 @@ struct pci_epc_mem {
>   * @lock: mutex to protect pci_epc ops
>   * @function_num_map: bitmap to manage physical function number
>   * @notifier: used to notify EPF of any EPC events (like linkup)
> + * @started: true if this EPC is started
>   */
>  struct pci_epc {
>  	struct device			dev;
> @@ -145,6 +146,7 @@ struct pci_epc {
>  	struct mutex			lock;
>  	unsigned long			function_num_map;
>  	struct atomic_notifier_head	notifier;
> +	bool				started;
>  };
>  
>  /**
> @@ -191,6 +193,11 @@ pci_epc_register_notifier(struct pci_epc *epc, struct notifier_block *nb)
>  	return atomic_notifier_chain_register(&epc->notifier, nb);
>  }
>  
> +static inline bool pci_epc_is_started(struct pci_epc *epc)
> +{
> +	return epc->started;
> +}

This should also be protected.

Thanks
Kishon
> +
>  struct pci_epc *
>  __devm_pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
>  		      struct module *owner);
>
Kunihiko Hayashi Feb. 2, 2021, 4:13 p.m. UTC | #2
Hi Kishon,

On 2021/01/28 23:11, Kishon Vijay Abraham I wrote:
> Hi Kunihiko,
> 
> On 24/01/21 8:39 pm, Kunihiko Hayashi wrote:
>> This adds a member 'started' as a boolean value to struct pci_epc to set
>> whether the controller is started, and also adds a function to get the
>> value.
>>
>> Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
>> ---
>>   drivers/pci/endpoint/pci-epc-core.c | 2 ++
>>   include/linux/pci-epc.h             | 7 +++++++
>>   2 files changed, 9 insertions(+)
>>
>> diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
>> index cc8f9eb..2904175 100644
>> --- a/drivers/pci/endpoint/pci-epc-core.c
>> +++ b/drivers/pci/endpoint/pci-epc-core.c
>> @@ -174,6 +174,7 @@ void pci_epc_stop(struct pci_epc *epc)
>>   
>>   	mutex_lock(&epc->lock);
>>   	epc->ops->stop(epc);
>> +	epc->started = false;
>>   	mutex_unlock(&epc->lock);
>>   }
>>   EXPORT_SYMBOL_GPL(pci_epc_stop);
>> @@ -196,6 +197,7 @@ int pci_epc_start(struct pci_epc *epc)
>>   
>>   	mutex_lock(&epc->lock);
>>   	ret = epc->ops->start(epc);
>> +	epc->started = true;
>>   	mutex_unlock(&epc->lock);
>>   
>>   	return ret;
>> diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
>> index b82c9b1..5808952 100644
>> --- a/include/linux/pci-epc.h
>> +++ b/include/linux/pci-epc.h
>> @@ -131,6 +131,7 @@ struct pci_epc_mem {
>>    * @lock: mutex to protect pci_epc ops
>>    * @function_num_map: bitmap to manage physical function number
>>    * @notifier: used to notify EPF of any EPC events (like linkup)
>> + * @started: true if this EPC is started
>>    */
>>   struct pci_epc {
>>   	struct device			dev;
>> @@ -145,6 +146,7 @@ struct pci_epc {
>>   	struct mutex			lock;
>>   	unsigned long			function_num_map;
>>   	struct atomic_notifier_head	notifier;
>> +	bool				started;
>>   };
>>   
>>   /**
>> @@ -191,6 +193,11 @@ pci_epc_register_notifier(struct pci_epc *epc, struct notifier_block *nb)
>>   	return atomic_notifier_chain_register(&epc->notifier, nb);
>>   }
>>   
>> +static inline bool pci_epc_is_started(struct pci_epc *epc)
>> +{
>> +	return epc->started;
>> +}
> 
> This should also be protected.

Ok, I prepared this function for restart management in patch 2/3.
This also needs to be reconsidered.

Thank you,

---
Best Regards
Kunihiko Hayashi
diff mbox series

Patch

diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index cc8f9eb..2904175 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -174,6 +174,7 @@  void pci_epc_stop(struct pci_epc *epc)
 
 	mutex_lock(&epc->lock);
 	epc->ops->stop(epc);
+	epc->started = false;
 	mutex_unlock(&epc->lock);
 }
 EXPORT_SYMBOL_GPL(pci_epc_stop);
@@ -196,6 +197,7 @@  int pci_epc_start(struct pci_epc *epc)
 
 	mutex_lock(&epc->lock);
 	ret = epc->ops->start(epc);
+	epc->started = true;
 	mutex_unlock(&epc->lock);
 
 	return ret;
diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h
index b82c9b1..5808952 100644
--- a/include/linux/pci-epc.h
+++ b/include/linux/pci-epc.h
@@ -131,6 +131,7 @@  struct pci_epc_mem {
  * @lock: mutex to protect pci_epc ops
  * @function_num_map: bitmap to manage physical function number
  * @notifier: used to notify EPF of any EPC events (like linkup)
+ * @started: true if this EPC is started
  */
 struct pci_epc {
 	struct device			dev;
@@ -145,6 +146,7 @@  struct pci_epc {
 	struct mutex			lock;
 	unsigned long			function_num_map;
 	struct atomic_notifier_head	notifier;
+	bool				started;
 };
 
 /**
@@ -191,6 +193,11 @@  pci_epc_register_notifier(struct pci_epc *epc, struct notifier_block *nb)
 	return atomic_notifier_chain_register(&epc->notifier, nb);
 }
 
+static inline bool pci_epc_is_started(struct pci_epc *epc)
+{
+	return epc->started;
+}
+
 struct pci_epc *
 __devm_pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
 		      struct module *owner);