Simplify PCIe hotplug indicator control
cover Simplify PCIe hotplug indicator control
PCIe defines two optional hotplug indicators: a Power indicator and an Attention indicator. Both are controlled by the same register, and each can be on, off or blinking. The current interfaces (pciehp_green_led_{on,off,blink}() and pciehp_set_attention_status()) are non-uniform and require two register writes in many cases where we could do one.
This patchset introduces the new function pciehp_set_indicators(). It allows one to set two indicators with a single register write. All calls to previous interfaces (pciehp_green_led_* and pciehp_set_attention_status()) are replaced with a new one.
Denis Efremov (4):
PCI: pciehp: Add pciehp_set_indicators() to jointly set LED indicators
PCI: pciehp: Switch LED indicators with a single write
PCI: pciehp: Replace pciehp_set_attention_status()
PCI: pciehp: Replace pciehp_green_led_{on,off,blink}()
drivers/pci/hotplug/pciehp.h | 31 +++++++++-- drivers/pci/hotplug/pciehp_ctrl.c | 14 ++--- drivers/pci/hotplug/pciehp_hpc.c | 87 +++++++++++++------------------ 3 files changed, 69 insertions(+), 63 deletions(-)
Signature · 1 line
2.21.0
PATCH 1/4 PCI: pciehp: Add pciehp_set_indicators() to jointly set LED indicators
This commit adds pciehp_set_indicators() to set power and attention indicators with a single register write. enum pciehp_indicator introduced to switch between the indicators statuses. Attention indicator statuses are explicitly set with values in the enum to transparently comply with pciehp_set_attention_status() from pciehp_hpc.c and set_attention_status() from pciehp_core.c
--- drivers/pci/hotplug/pciehp.h | 15 ++++++++++ drivers/pci/hotplug/pciehp_hpc.c | 49 ++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+)
drivers/pci/hotplug/pciehp.h +15 -0
@@ -150,6 +150,18 @@ struct controller {#define NO_CMD_CMPL (ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_NCCS)#define PSN (ctrl) (((ctrl)->slot_cap & PCI_EXP_SLTCAP_PSN) >> 19) +enum pciehp_indicator { +// Explicit values to match set_attention_status interface +ATTN_NONE =-1 , +ATTN_OFF =0 , +ATTN_ON =1 , +ATTN_BLINK =2 , +PWR_NONE , +PWR_OFF , +PWR_ON , +PWR_BLINK +}; +void pciehp_request (struct controller *ctrl,int action);void pciehp_handle_button_press (struct controller *ctrl);void pciehp_handle_disable_request (struct controller *ctrl);
@@ -167,6 +179,9 @@ int pciehp_power_on_slot(struct controller *ctrl);void pciehp_power_off_slot (struct controller *ctrl);void pciehp_get_power_status (struct controller *ctrl,u8 *status); +void pciehp_set_indicators (struct controller *ctrl, +enum pciehp_indicator pwr, +enum pciehp_indicator attn);void pciehp_set_attention_status (struct controller *ctrl,u8 status);void pciehp_get_latch_status (struct controller *ctrl,u8 *status);int pciehp_query_power_fault (struct controller *ctrl);
drivers/pci/hotplug/pciehp_hpc.c +49 -0
55 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH 2/4 PCI: pciehp: Switch LED indicators with a single write
In reply to Denis EfremovThis patch replaces all consecutive switches of power and attention indicators with pciehp_set_indicators() call. Thus, performing only single write to a register.
--- drivers/pci/hotplug/pciehp_ctrl.c | 14 +++++--------- drivers/pci/hotplug/pciehp_hpc.c | 3 +-- 2 files changed, 6 insertions(+), 11 deletions(-)
drivers/pci/hotplug/pciehp_ctrl.c +5 -9
@@ -42,8 +42,7 @@ static void set_slot_off(struct controller *ctrl)msleep (1000 ); } -pciehp_green_led_off (ctrl); -pciehp_set_attention_status (ctrl,1 ); +pciehp_set_indicators (ctrl,PWR_OFF ,ATTN_ON ); }/**
@@ -90,8 +89,7 @@ static int board_added(struct controller *ctrl) } } -pciehp_green_led_on (ctrl); -pciehp_set_attention_status (ctrl,0 ); +pciehp_set_indicators (ctrl,PWR_ON ,ATTN_OFF );return 0 ; err_exit:
@@ -172,8 +170,7 @@ void pciehp_handle_button_press(struct controller *ctrl) slot_name(ctrl)); }/* blink green LED and turn off amber */ -pciehp_green_led_blink (ctrl); -pciehp_set_attention_status (ctrl,0 ); +pciehp_set_indicators (ctrl,PWR_BLINK ,ATTN_OFF );schedule_delayed_work (&ctrl->button_work,5 *HZ );break ;case BLINKINGOFF_STATE :
@@ -187,12 +184,11 @@ void pciehp_handle_button_press(struct controller *ctrl)cancel_delayed_work (&ctrl->button_work);if (ctrl->state ==BLINKINGOFF_STATE ) { ctrl->state =ON_STATE ; -pciehp_green_led_on (ctrl); +pciehp_set_indicators (ctrl,PWR_ON ,ATTN_OFF ); }else { ctrl->state =OFF_STATE ; -pciehp_green_led_off (ctrl); +pciehp_set_indicators (ctrl,PWR_OFF ,ATTN_OFF ); } -pciehp_set_attention_status (ctrl,0 );ctrl_info (ctrl,"Slot(%s): Action canceled due to button press\n" ,slot_name (ctrl));break ;
drivers/pci/hotplug/pciehp_hpc.c +1 -2
@@ -687,8 +687,7 @@ static irqreturn_t pciehp_ist(int irq, void *dev_id)if ((events &PCI_EXP_SLTSTA_PFD ) && !ctrl->power_fault_detected) { ctrl->power_fault_detected =1 ;ctrl_err (ctrl,"Slot(%s): Power fault\n" ,slot_name (ctrl)); -pciehp_set_attention_status (ctrl,1 ); -pciehp_green_led_off (ctrl); +pciehp_set_indicators (ctrl,PWR_OFF ,ATTN_ON ); }/*
Signature · 1 line
2.21.0
PATCH 3/4 PCI: pciehp: Replace pciehp_set_attention_status()
In reply to Denis EfremovThis patch replaces pciehp_set_attention_status() with pciehp_set_indicators().
--- drivers/pci/hotplug/pciehp.h | 4 +++- drivers/pci/hotplug/pciehp_hpc.c | 25 ------------------------- 2 files changed, 3 insertions(+), 26 deletions(-)
drivers/pci/hotplug/pciehp.h +3 -1
@@ -182,7 +182,6 @@ void pciehp_get_power_status(struct controller *ctrl, u8 *status);void pciehp_set_indicators (struct controller *ctrl,enum pciehp_indicator pwr,enum pciehp_indicator attn); -void pciehp_set_attention_status (struct controller *ctrl,u8 status);void pciehp_get_latch_status (struct controller *ctrl,u8 *status);int pciehp_query_power_fault (struct controller *ctrl);void pciehp_green_led_on (struct controller *ctrl);
@@ -201,6 +200,9 @@ int pciehp_get_attention_status(struct hotplug_slot *hotplug_slot, u8 *status);int pciehp_set_raw_indicator_status (struct hotplug_slot *h_slot,u8 status);int pciehp_get_raw_indicator_status (struct hotplug_slot *h_slot,u8 *status); +#define pciehp_set_attention_status (crtl, status) \ + pciehp_set_indicators(ctrl, PWR_NONE, status) +static inline const char *slot_name (struct controller *ctrl) {return hotplug_slot_name (&ctrl->hotplug_slot);
drivers/pci/hotplug/pciehp_hpc.c +0 -25
@@ -418,31 +418,6 @@ int pciehp_set_raw_indicator_status(struct hotplug_slot *hotplug_slot,return 0 ; } -void pciehp_set_attention_status (struct controller *ctrl,u8 value) -{ -u16 slot_cmd; - -if (!ATTN_LED (ctrl)) -return ; - -switch (value) { -case 0 :/* turn off */ - slot_cmd =PCI_EXP_SLTCTL_ATTN_IND_OFF ; -break ; -case 1 :/* turn on */ - slot_cmd =PCI_EXP_SLTCTL_ATTN_IND_ON ; -break ; -case 2 :/* turn blink */ - slot_cmd =PCI_EXP_SLTCTL_ATTN_IND_BLINK ; -break ; -default : -return ; - } -pcie_write_cmd_nowait (ctrl, slot_cmd,PCI_EXP_SLTCTL_AIC ); -ctrl_dbg (ctrl,"%s: SLOTCTRL %x write cmd %x\n" , __func__, -pci_pcie_cap (ctrl->pcie->port) +PCI_EXP_SLTCTL , slot_cmd); -} -void pciehp_set_indicators (struct controller *ctrl,enum pciehp_indicator pwr,enum pciehp_indicator attn)
Signature · 1 line
2.21.0
PATCH 4/4 PCI: pciehp: Replace pciehp_green_led_{on,off,blink}()
In reply to Denis EfremovThis patch replaces pciehp_green_led_{on,off,blink}() with pciehp_set_indicators().
--- drivers/pci/hotplug/pciehp.h | 12 ++++++++--- drivers/pci/hotplug/pciehp_hpc.c | 36 -------------------------------- 2 files changed, 9 insertions(+), 39 deletions(-)
drivers/pci/hotplug/pciehp.h +9 -3
@@ -184,9 +184,6 @@ void pciehp_set_indicators(struct controller *ctrl, enum pciehp_indicator attn);void pciehp_get_latch_status (struct controller *ctrl,u8 *status);int pciehp_query_power_fault (struct controller *ctrl); -void pciehp_green_led_on (struct controller *ctrl); -void pciehp_green_led_off (struct controller *ctrl); -void pciehp_green_led_blink (struct controller *ctrl);bool pciehp_card_present (struct controller *ctrl);bool pciehp_card_present_or_link_active (struct controller *ctrl);int pciehp_check_link_status (struct controller *ctrl);
@@ -203,6 +200,15 @@ int pciehp_get_raw_indicator_status(struct hotplug_slot *h_slot, u8 *status);#define pciehp_set_attention_status (crtl, status) \ pciehp_set_indicators(ctrl, PWR_NONE, status) +#define pciehp_green_led_on (ctrl) \ + pciehp_set_indicators(ctrl, PWR_ON, ATTN_NONE) + +#define pciehp_green_led_off (ctrl) \ + pciehp_set_indicators(ctrl, PWR_OFF, ATTN_NONE) + +#define pciehp_green_led_blink (ctrl) \ + pciehp_set_indicators(ctrl, PWR_BLINK, ATTN_NONE) +static inline const char *slot_name (struct controller *ctrl) {return hotplug_slot_name (&ctrl->hotplug_slot);
drivers/pci/hotplug/pciehp_hpc.c +0 -36
@@ -467,42 +467,6 @@ void pciehp_set_indicators(struct controller *ctrl, cmd); } -void pciehp_green_led_on (struct controller *ctrl) -{ -if (!PWR_LED (ctrl)) -return ; - -pcie_write_cmd_nowait (ctrl,PCI_EXP_SLTCTL_PWR_IND_ON , -PCI_EXP_SLTCTL_PIC ); -ctrl_dbg (ctrl,"%s: SLOTCTRL %x write cmd %x\n" , __func__, -pci_pcie_cap (ctrl->pcie->port) +PCI_EXP_SLTCTL , -PCI_EXP_SLTCTL_PWR_IND_ON ); -} - -void pciehp_green_led_off (struct controller *ctrl) -{ -if (!PWR_LED (ctrl)) -return ; - -pcie_write_cmd_nowait (ctrl,PCI_EXP_SLTCTL_PWR_IND_OFF , -PCI_EXP_SLTCTL_PIC ); -ctrl_dbg (ctrl,"%s: SLOTCTRL %x write cmd %x\n" , __func__, -pci_pcie_cap (ctrl->pcie->port) +PCI_EXP_SLTCTL , -PCI_EXP_SLTCTL_PWR_IND_OFF ); -} - -void pciehp_green_led_blink (struct controller *ctrl) -{ -if (!PWR_LED (ctrl)) -return ; - -pcie_write_cmd_nowait (ctrl,PCI_EXP_SLTCTL_PWR_IND_BLINK , -PCI_EXP_SLTCTL_PIC ); -ctrl_dbg (ctrl,"%s: SLOTCTRL %x write cmd %x\n" , __func__, -pci_pcie_cap (ctrl->pcie->port) +PCI_EXP_SLTCTL , -PCI_EXP_SLTCTL_PWR_IND_BLINK ); -} -int pciehp_power_on_slot (struct controller *ctrl) {struct pci_dev *pdev =ctrl_dev (ctrl);
Signature · 1 line
2.21.0
Re: [PATCH 1/4] PCI: pciehp: Add pciehp_set_indicators() to jointly set LED indicators
In reply to Denis EfremovQuoted 1 line · Denis Efremov
This commit adds
pciehp_set_indicators()to set power and attention
Nit: "This commit ..." is superfluous, just say "Add ...".
Quoted 5 lines
indicators with a single register write. enum
pciehp_indicatorintroduced to switch between the indicators statuses. Attention indicator statuses are explicitly set with values in the enum to transparently comply withpciehp_set_attention_status()frompciehp_hpc.candset_attention_status()frompciehp_core.c
Please document the motivation of the change (the "why").
One motivation might be to avoid waiting twice for Command Complete.
Another motivation might be to change both LEDs at the same time in a glitch-free manner, thereby achieving a smoother user experience.
drivers/pci/hotplug/pciehp.h struct controller { · line 154
Quoted 4 lines
drivers/pci/hotplug/pciehp.h +2
-0+enum pciehp_indicator { +// Explicit values to match set_attention_status interface
Kernel coding style is typically /* */, not //.
drivers/pci/hotplug/pciehp.h struct controller { · line 163
Quoted 9 lines
drivers/pci/hotplug/pciehp.h +9
-0+ATTN_NONE =-1 , +ATTN_OFF =0 , +ATTN_ON =1 , +ATTN_BLINK =2 , +PWR_NONE , +PWR_OFF , +PWR_ON , + PWR_BLINK +};
I'd suggest using the same values that are written to the register, i.e.:
enum pciehp_indicator {
ATTN_NONE = -1,
ATTN_ON = 1,
ATTN_BLINK = 2,
ATTN_OFF = 3,
PWR_NONE = -1,
PWR_ON = 1,
PWR_BLINK = 2,
PWR_OFF = 3,
};
Then you can just shift the values to the proper offset and don't need a translation between enum pciehp_indicator and register value.
drivers/pci/hotplug/pciehp.h
Quoted 13 lines
drivers/pci/hotplug/pciehp.h +13
-0+void pciehp_set_indicators (struct controller *ctrl, +enum pciehp_indicator pwr, +enum pciehp_indicator attn) +{ +u16 cmd =0 ; +bool pwr_none = (pwr ==PWR_NONE ); +bool attn_none = (attn ==ATTN_NONE ); +bool pwr_led =PWR_LED (ctrl); +bool attn_led =ATTN_LED (ctrl); + +if ((!pwr_led && !attn_led) || (pwr_none && attn_none) || + (!attn_led && pwr_none) || (!pwr_led && attn_none)) +return ;
I'd suggest the following simpler construct:
if (!PWR_LED(ctrl) || pwr == PWR_NONE) && !ATTN_LED(ctrl) || attn == ATTN_NONE)) return;
drivers/pci/hotplug/pciehp.h
Quoted 13 lines
drivers/pci/hotplug/pciehp.h +13
-0+switch (pwr) { +case PWR_OFF : + cmd =PCI_EXP_SLTCTL_PWR_IND_OFF ; +break ; +case PWR_ON : + cmd =PCI_EXP_SLTCTL_PWR_IND_ON ; +break ; +case PWR_BLINK : + cmd =PCI_EXP_SLTCTL_PWR_IND_BLINK ; +break ; +default : +break ; + }
If you follow my suggestion above to use the register value for "pwr", then you can just fold all three cases into one, i.e.
case PWR_ON: case PWR_BLINK: case PWR_OFF: cmd = pwr << 8; mask |= PCI_EXP_SLTCTL_PIC; break;
Feel free to add a PCI_EXP_SLTCTL_PWR_IND_OFFSET macro for the offset 8. Add a "u16 mask = 0" to the top of the function and pass "mask" to pcie_write_cmd_nowait().
Thanks,
Lukas
Re: [PATCH 2/4] PCI: pciehp: Switch LED indicators with a single write
In reply to Denis EfremovQuoted 5 lines · Denis Efremov
This patch replaces all consecutive switches of power and attention indicators with
pciehp_set_indicators()call. Thus, performing only single write to a register.Signed-off-by Denis Efremov <[email protected]>
Re: [PATCH 3/4] PCI: pciehp: Replace pciehp_set_attention_status()
In reply to Denis Efremovdrivers/pci/hotplug/pciehp.h int pciehp_get_attention_status(struct hotplug_slot *hotplug_slot, u8 *status); · line 205
Quoted 3 lines · Denis Efremov
drivers/pci/hotplug/pciehp.h +3
-0+#define pciehp_set_attention_status (crtl, status) \ + pciehp_set_indicators(ctrl, PWR_NONE, status) +
There's a typo here, s/crtl/ctrl/.
With that addressed,
Re: [PATCH 4/4] PCI: pciehp: Replace pciehp_green_led_{on,off,blink}()
In reply to Denis EfremovQuoted 4 lines · Denis Efremov
This patch replaces pciehp_green_led_{on,off,blink}() with
pciehp_set_indicators().Signed-off-by Denis Efremov <[email protected]>
Re: [PATCH 1/4] PCI: pciehp: Add pciehp_set_indicators() to jointly set LED indicators
In reply to Lukas WunnerQuoted 3 lines · Lukas Wunner
if (!PWR_LED(ctrl) || pwr == PWR_NONE) && !ATTN_LED(ctrl) || attn == ATTN_NONE)) return;
Forgot an opening brace in two spots here, sorry.
Re: [PATCH 1/4] PCI: pciehp: Add pciehp_set_indicators() to jointly set LED indicators
In reply to Lukas WunnerThank you for the review, I will send v2.
Quoted 108 lines · Lukas Wunner
Quoted 1 line · Denis Efremov
This commit adds
pciehp_set_indicators()to set power and attentionNit: "This commit ..." is superfluous, just say "Add ...".
Quoted 5 lines
indicators with a single register write. enum
pciehp_indicatorintroduced to switch between the indicators statuses. Attention indicator statuses are explicitly set with values in the enum to transparently comply withpciehp_set_attention_status()frompciehp_hpc.candset_attention_status()frompciehp_core.cPlease document the motivation of the change (the "why").
One motivation might be to avoid waiting twice for Command Complete.
Another motivation might be to change both LEDs at the same time in a glitch-free manner, thereby achieving a smoother user experience.
drivers/pci/hotplug/pciehp.h struct controller { · line 154
Quoted 4 lines
drivers/pci/hotplug/pciehp.h +2
-0+enum pciehp_indicator { +// Explicit values to match set_attention_status interface Kernel coding style is typically /* */, not //.
drivers/pci/hotplug/pciehp.h struct controller { · line 163
Quoted 9 lines
drivers/pci/hotplug/pciehp.h +9
-0+ATTN_NONE =-1 , +ATTN_OFF =0 , +ATTN_ON =1 , +ATTN_BLINK =2 , +PWR_NONE , +PWR_OFF , +PWR_ON , + PWR_BLINK +};I'd suggest using the same values that are written to the register, i.e.:
enum
pciehp_indicator{
ATTN_NONE= -1,
ATTN_ON= 1,
ATTN_BLINK= 2,
ATTN_OFF= 3,
PWR_NONE= -1,
PWR_ON= 1,
PWR_BLINK= 2,
PWR_OFF= 3,
};Then you can just shift the values to the proper offset and don't need a translation between enum
pciehp_indicatorand register value.drivers/pci/hotplug/pciehp.h
Quoted 13 lines
drivers/pci/hotplug/pciehp.h +13
-0+void pciehp_set_indicators (struct controller *ctrl, +enum pciehp_indicator pwr, +enum pciehp_indicator attn) +{ +u16 cmd =0 ; +bool pwr_none = (pwr ==PWR_NONE ); +bool attn_none = (attn ==ATTN_NONE ); +bool pwr_led =PWR_LED (ctrl); +bool attn_led =ATTN_LED (ctrl); + +if ((!pwr_led && !attn_led) || (pwr_none && attn_none) || + (!attn_led && pwr_none) || (!pwr_led && attn_none)) +return ;I'd suggest the following simpler construct:
if (!PWR_LED(ctrl) || pwr == PWR_NONE) && !ATTN_LED(ctrl) || attn == ATTN_NONE)) return;drivers/pci/hotplug/pciehp.h
Quoted 13 lines
drivers/pci/hotplug/pciehp.h +13
-0+switch (pwr) { +case PWR_OFF : + cmd =PCI_EXP_SLTCTL_PWR_IND_OFF ; +break ; +case PWR_ON : + cmd =PCI_EXP_SLTCTL_PWR_IND_ON ; +break ; +case PWR_BLINK : + cmd =PCI_EXP_SLTCTL_PWR_IND_BLINK ; +break ; +default : +break ; + }If you follow my suggestion above to use the register value for "pwr", then you can just fold all three cases into one, i.e.
case PWR_ON: case PWR_BLINK: case PWR_OFF: cmd = pwr << 8; mask |= PCI_EXP_SLTCTL_PIC; break;Feel free to add a
PCI_EXP_SLTCTL_PWR_IND_OFFSETmacro for the offset 8. Add a "u16 mask = 0" to the top of the function and pass "mask" topcie_write_cmd_nowait().Thanks,
Lukas