Re: [PATCH v1] PCI: pciehp: Fix the slot in BLINKINGON_STATE when Presence Detect Changed event occurred

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 4/16/23 11:18 PM, Lukas Wunner wrote:
> On Mon, Apr 03, 2023 at 01:46:19PM +0800, Rongguang Wei wrote:
>> When a Presence Detect Changed event has occurred, the slot status
>> in either BLINKINGOFF_STATE or OFF_STATE, turn it off unconditionally.
>> But if the slot status is in BLINKINGON_STATE and the slot is currently
>> empty, the slot status was staying in BLINKINGON_STATE.
>>
>> The message print like this:
>>     pcieport 0000:00:01.5: pciehp: Slot(0-5): Attention button pressed
>>     pcieport 0000:00:01.5: pciehp: Slot(0-5) Powering on due to button press
>>     pcieport 0000:00:01.5: pciehp: Slot(0-5): Attention button pressed
>>     pcieport 0000:00:01.5: pciehp: Slot(0-5): Button cancel
>>     pcieport 0000:00:01.5: pciehp: Slot(0-5): Action canceled due to button press
>>
>> It cause the next Attention Button Pressed event become Button cancel
>> and missing the Presence Detect Changed event with this button press
>> though this button presses event is occurred after 5s.
> 
> I see what you mean.
> 
> pciehp's behavior is incorrect if the Attention Button is pressed
> on an unoccupied slot:
> 
> Upon a button press, pciehp_queue_pushbutton_work() is scheduled to run
> after 5 seconds.  It synthesizes a Presence Detect Changed event,
> whereupon pciehp_handle_presence_or_link_change() runs.
> 
> Should the slot be empty, pciehp_handle_presence_or_link_change() just
> bails out and the state incorrectly remains in BLINKINGON_STATE.
> 
> 
>> --- a/drivers/pci/hotplug/pciehp_ctrl.c
>> +++ b/drivers/pci/hotplug/pciehp_ctrl.c
>> @@ -232,6 +232,7 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events)
>>  	 */
>>  	mutex_lock(&ctrl->state_lock);
>>  	switch (ctrl->state) {
>> +	case BLINKINGON_STATE:
>>  	case BLINKINGOFF_STATE:
>>  		cancel_delayed_work(&ctrl->button_work);
>>  		fallthrough;
> 
> This solution has the disadvantage that a gratuitous "Card not present"
> message is emitted even if the slot is occupied.
> 
Thank you for your advice.

I think when the "Card not present" is emitted, it may not consider the slot status
from the beginning. If the slot is in ON_STATE and is occupied, turn the slot off and then back on. The message is also emitted at first.

> I'd prefer the following simpler solution:
> 
> diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c
> index 529c348..e680444 100644
> --- a/drivers/pci/hotplug/pciehp_ctrl.c
> +++ b/drivers/pci/hotplug/pciehp_ctrl.c
> @@ -256,6 +256,7 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events)
>  	present = pciehp_card_present(ctrl);
>  	link_active = pciehp_check_link_active(ctrl);
>  	if (present <= 0 && link_active <= 0) {
> +		ctrl->state = POWEROFF_STATE;
>  		mutex_unlock(&ctrl->state_lock);
>  		return;
>  	}
>> Optionally the assignment can be made conditional on
> "if (ctrl->state == BLINKINGON_STATE)" for clarity.
> 
> Likewise, a "Card not present" message can optionally be emitted here.
It should set crtl->state = OFF_STATE in direct and add cancel_delayed_work(&ctrl->button_work). And add message here looks a bit redundancy.
> 
> Thanks,
> 
> Lukas
> 
Maybe I can rework to add like this to prevent the gratuitous message:

diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c
index 86fc9342be68..8dbf767a65ac 100644
--- a/drivers/pci/hotplug/pciehp_ctrl.c
+++ b/drivers/pci/hotplug/pciehp_ctrl.c
@@ -239,12 +239,6 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events)
 	case ON_STATE:
 		ctrl->state = POWEROFF_STATE;
 		mutex_unlock(&ctrl->state_lock);
-		if (events & PCI_EXP_SLTSTA_DLLSC)
-			ctrl_info(ctrl, "Slot(%s): Link Down\n",
-				  slot_name(ctrl));
-		if (events & PCI_EXP_SLTSTA_PDC)
-			ctrl_info(ctrl, "Slot(%s): Card not present\n",
-				  slot_name(ctrl));
 		pciehp_disable_slot(ctrl, SURPRISE_REMOVAL);
 		break;
 	default:
@@ -257,6 +251,12 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events)
 	present = pciehp_card_present(ctrl);
 	link_active = pciehp_check_link_active(ctrl);
 	if (present <= 0 && link_active <= 0) {
 		mutex_unlock(&ctrl->state_lock);
+		if (events & PCI_EXP_SLTSTA_DLLSC)
+			ctrl_info(ctrl, "Slot(%s): Link Down\n",
+				  slot_name(ctrl));
+		if (events & PCI_EXP_SLTSTA_PDC)
+			ctrl_info(ctrl, "Slot(%s): Card not present\n",
+				  slot_name(ctrl));
 		return;
 	}

Thanks,

Wei




[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux