PCI: shpchp: Remove hpc_ops
PATCH v3 1/1 PCI: shpchp: Remove hpc_ops
Remove the hpc_ops struct from shpchp. This struct is unnecessary as no other hotplug controller implements it. A similar thing has already been done in pciehp with commit 82a9e79ef132 ("PCI: pciehp: remove hpc_ops")
---
Changes in v2:
- Fix a few typos
- Remove hpc_ops from the slot and the controller struct
Changes in v3:
- Update the commit message according to the Bjorn's response
- Remove the related task from the TODO file
drivers/pci/hotplug/TODO | 5 -- drivers/pci/hotplug/shpchp.h | 38 +++++++-------- drivers/pci/hotplug/shpchp_core.c | 15 +++--- drivers/pci/hotplug/shpchp_ctrl.c | 79 +++++++++++++++---------------- drivers/pci/hotplug/shpchp_hpc.c | 63 ++++++++---------------- 5 files changed, 82 insertions(+), 118 deletions(-)
drivers/pci/hotplug/TODO +0 -5
@@ -51,11 +51,6 @@ ibmphp: shpchp: -* There is only a single implementation of struct hpc_ops. Can the struct be - removed and its functions invoked directly? This has already been done in - pciehp with commit 82a9e79ef132 ("PCI: pciehp: remove hpc_ops"). Clarify - if there was a specific reason not to apply the same change to shpchp. - * The hardirq handler shpc_isr() queues events on a workqueue. It can be simplified by converting it to threaded IRQ handling. Use pciehp as a template.
drivers/pci/hotplug/shpchp.h +17 -21
@@ -72,7 +72,6 @@ struct slot {u8 latch_save;u8 pwr_save;struct controller *ctrl; -const struct hpc_ops *hpc_ops;struct hotplug_slot hotplug_slot;struct list_head slot_list;struct delayed_work work;/* work for button event */
@@ -94,7 +93,6 @@ struct controller {int slot_num_inc;/* 1 or -1 */ struct pci_dev *pci_dev;struct list_head slot_list; -const struct hpc_ops *hpc_ops;wait_queue_head_t queue;/* sleep & wake process */ u8 slot_device_offset;u32 pcix_misc2_reg;/* for amd pogo errata */
@@ -300,24 +298,22 @@ static inline void amd_pogo_errata_restore_misc_reg(struct slot *p_slot)pci_write_config_dword (p_slot->ctrl->pci_dev,PCIX_MISCII_OFFSET , pcix_misc2_temp); } -struct hpc_ops { -int (*power_on_slot)(struct slot *slot); -int (*slot_enable)(struct slot *slot); -int (*slot_disable)(struct slot *slot); -int (*set_bus_speed_mode)(struct slot *slot,enum pci_bus_speed speed); -int (*get_power_status)(struct slot *slot,u8 *status); -int (*get_attention_status)(struct slot *slot,u8 *status); -int (*set_attention_status)(struct slot *slot,u8 status); -int (*get_latch_status)(struct slot *slot,u8 *status); -int (*get_adapter_status)(struct slot *slot,u8 *status); -int (*get_adapter_speed)(struct slot *slot,enum pci_bus_speed *speed); -int (*get_prog_int)(struct slot *slot,u8 *prog_int); -int (*query_power_fault)(struct slot *slot); -void (*green_led_on)(struct slot *slot); -void (*green_led_off)(struct slot *slot); -void (*green_led_blink)(struct slot *slot); -void (*release_ctlr)(struct controller *ctrl); -int (*check_cmd_status)(struct controller *ctrl); -}; +int shpchp_power_on_slot (struct slot *slot); +int shpchp_slot_enable (struct slot *slot); +int shpchp_slot_disable (struct slot *slot); +int shpchp_set_bus_speed_mode (struct slot *slot,enum pci_bus_speed speed); +int shpchp_get_power_status (struct slot *slot,u8 *status); +int shpchp_get_attention_status (struct slot *slot,u8 *status); +int shpchp_set_attention_status (struct slot *slot,u8 status); +int shpchp_get_latch_status (struct slot *slot,u8 *status); +int shpchp_get_adapter_status (struct slot *slot,u8 *status); +int shpchp_get_adapter_speed (struct slot *slot,enum pci_bus_speed *speed); +int shpchp_get_prog_int (struct slot *slot,u8 *prog_int); +int shpchp_query_power_fault (struct slot *slot); +void shpchp_green_led_on (struct slot *slot); +void shpchp_green_led_off (struct slot *slot); +void shpchp_green_led_blink (struct slot *slot); +void shpchp_release_ctlr (struct controller *ctrl); +int shpchp_check_cmd_status (struct controller *ctrl);#endif /* _SHPCHP_H */
drivers/pci/hotplug/shpchp_core.c +7 -8
@@ -81,7 +81,6 @@ static int init_slots(struct controller *ctrl) slot->ctrl = ctrl; slot->bus = ctrl->pci_dev->subordinate->number; slot->device = ctrl->slot_device_offset + i; - slot->hpc_ops = ctrl->hpc_ops; slot->number = ctrl->first_slot + (ctrl->slot_num_inc * i); slot->wq =alloc_workqueue ("shpchp-%d" ,0 ,0 , slot->number);
@@ -150,7 +149,7 @@ static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status) __func__, slot_name(slot)); slot->attention_save = status; - slot->hpc_ops->set_attention_status (slot, status); +shpchp_set_attention_status (slot, status);return 0 ; }
@@ -183,7 +182,7 @@ static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)ctrl_dbg (slot->ctrl,"%s: physical_slot = %s\n" , __func__,slot_name (slot)); - retval = slot->hpc_ops->get_power_status (slot, value); + retval =shpchp_get_power_status (slot, value);if (retval <0 ) *value = slot->pwr_save;
@@ -198,7 +197,7 @@ static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)ctrl_dbg (slot->ctrl,"%s: physical_slot = %s\n" , __func__,slot_name (slot)); - retval = slot->hpc_ops->get_attention_status (slot, value); + retval =shpchp_get_attention_status (slot, value);if (retval <0 ) *value = slot->attention_save;
@@ -213,7 +212,7 @@ static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)ctrl_dbg (slot->ctrl,"%s: physical_slot = %s\n" , __func__,slot_name (slot)); - retval = slot->hpc_ops->get_latch_status (slot, value); + retval =shpchp_get_latch_status (slot, value);if (retval <0 ) *value = slot->latch_save;
@@ -228,7 +227,7 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)ctrl_dbg (slot->ctrl,"%s: physical_slot = %s\n" , __func__,slot_name (slot)); - retval = slot->hpc_ops->get_adapter_status (slot, value); + retval =shpchp_get_adapter_status (slot, value);if (retval <0 ) *value = slot->presence_save;
@@ -293,7 +292,7 @@ static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err_cleanup_slots:cleanup_slots (ctrl); err_out_release_ctlr: - ctrl->hpc_ops->release_ctlr (ctrl); +shpchp_release_ctlr (ctrl); err_out_free_ctrl:kfree (ctrl); err_out_none:
@@ -306,7 +305,7 @@ static void shpc_remove(struct pci_dev *dev) dev->shpc_managed =0 ;shpchp_remove_ctrl_files (ctrl); - ctrl->hpc_ops->release_ctlr (ctrl); +shpchp_release_ctlr (ctrl);kfree (ctrl); }
drivers/pci/hotplug/shpchp_ctrl.c +39 -40
240 lines not on this page · raw message
drivers/pci/hotplug/shpchp_hpc.c +19 -44
189 lines not on this page · raw message
Signature · 1 line
2.45.2
Quoted 14 lines · ngn
Remove the
hpc_opsstruct from shpchp. This struct is unnecessary as no other hotplug controller implements it. A similar thing has already been done in pciehp with commit82a9e79ef132("PCI: pciehp: removehpc_ops")+++
b/drivers/pci/hotplug/shpchp_hpc.cdrivers/pci/hotplug/shpchp_hpc.c +0
-1@@ -167,7 +167,6 @@static irqreturn_t shpc_isr (int irq,void *dev_id);static void start_int_poll_timer (struct controller *ctrl,int sec); -static int hpc_check_cmd_status (struct controller *ctrl);static inline u8 shpc_readb (struct controller *ctrl,int reg) {
drivers/pci/hotplug/shpchp_hpc.c static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd) · line 319
Quoted 5 lines
drivers/pci/hotplug/shpchp_hpc.c +1
-1@@ -317,7 +316,7 @@ static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)if (retval) goto out; - cmd_status =hpc_check_cmd_status (slot->ctrl); + cmd_status =shpchp_check_cmd_status (slot->ctrl);
This rename looks like it should be a separate patch because it's not part of removing hpc_ops.
Quoted 12 lines
drivers/pci/hotplug/shpchp_hpc.c +1
-1if (cmd_status) {ctrl_err (ctrl,"Failed to issued command 0x%x (error code = %d)\n" , cmd, cmd_status);@@ -328,7 +327,7 @@ static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)return retval; } -static int hpc_check_cmd_status (struct controller *ctrl) +int shpchp_check_cmd_status (struct controller *ctrl) {int retval =0 ;u16 cmd_status =shpc_readw (ctrl,CMD_STATUS ) &0x000F ;
Quoted 18 lines · Bjorn Helgaas
Quoted 17 lines · ngn
Remove the
hpc_opsstruct from shpchp. This struct is unnecessary as no other hotplug controller implements it. A similar thing has already been done in pciehp with commit82a9e79ef132("PCI: pciehp: removehpc_ops")+++
b/drivers/pci/hotplug/shpchp_hpc.cdrivers/pci/hotplug/shpchp_hpc.c +0
-1@@ -167,7 +167,6 @@static irqreturn_t shpc_isr (int irq,void *dev_id);static void start_int_poll_timer (struct controller *ctrl,int sec); -static int hpc_check_cmd_status (struct controller *ctrl);static inline u8 shpc_readb (struct controller *ctrl,int reg) {@@ -317,7 +316,7 @@ static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)if (retval) goto out;
Quoted 5 lines
drivers/pci/hotplug/shpchp_hpc.c static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd) · line 319
Quoted 2 lines
drivers/pci/hotplug/shpchp_hpc.c +1
-1- cmd_status =hpc_check_cmd_status (slot->ctrl); + cmd_status =shpchp_check_cmd_status (slot->ctrl);This rename looks like it should be a separate patch because it's not part of removing
hpc_ops.
I think hpc_check_cmd_status meant to be a part of the hpc_ops struct. Here is the original struct:
struct hpc_ops {
int (*power_on_slot)(struct slot *slot);
int (*slot_enable)(struct slot *slot);
int (*slot_disable)(struct slot *slot);
int (*set_bus_speed_mode)(struct slot *slot, enum pci_bus_speed speed);
int (*get_power_status)(struct slot *slot, u8 *status);
int (*get_attention_status)(struct slot *slot, u8 *status);
int (*set_attention_status)(struct slot *slot, u8 status);
int (*get_latch_status)(struct slot *slot, u8 *status);
int (*get_adapter_status)(struct slot *slot, u8 *status);
int (*get_adapter_speed)(struct slot *slot, enum pci_bus_speed *speed);
int (*get_prog_int)(struct slot *slot, u8 *prog_int);
int (*query_power_fault)(struct slot *slot);
void (*green_led_on)(struct slot *slot);
void (*green_led_off)(struct slot *slot);
void (*green_led_blink)(struct slot *slot);
void (*release_ctlr)(struct controller *ctrl);
int (*check_cmd_status)(struct controller *ctrl);
};As you can see it contains a pointer for check_cmd_status function, however the hpc_check_cmd_status was never assigned to it:
static const struct hpc_ops shpchp_hpc_ops = {
.power_on_slot = hpc_power_on_slot,
.slot_enable = hpc_slot_enable,
.slot_disable = hpc_slot_disable,
.set_bus_speed_mode = hpc_set_bus_speed_mode,
.set_attention_status = hpc_set_attention_status,
.get_power_status = hpc_get_power_status,
.get_attention_status = hpc_get_attention_status,
.get_latch_status = hpc_get_latch_status,
.get_adapter_status = hpc_get_adapter_status,
.get_adapter_speed = hpc_get_adapter_speed,
.get_prog_int = hpc_get_prog_int,
.query_power_fault = hpc_query_power_fault,
.green_led_on = hpc_set_green_led_on,
.green_led_off = hpc_set_green_led_off,
.green_led_blink = hpc_set_green_led_blink,
.release_ctlr = hpc_release_ctlr,
};Which made me believe that this function supposed to be a part of the hpc_ops struct and whoever wrote the code added a pointer for it but then they forgot to assign the function to it during the actual definition of the struct. So I renamed it anyway.
Quoted 73 lines · ngn
Quoted 18 lines · Bjorn Helgaas
Quoted 17 lines · ngn
Remove the
hpc_opsstruct from shpchp. This struct is unnecessary as no other hotplug controller implements it. A similar thing has already been done in pciehp with commit82a9e79ef132("PCI: pciehp: removehpc_ops")+++
b/drivers/pci/hotplug/shpchp_hpc.cdrivers/pci/hotplug/shpchp_hpc.c +0
-1@@ -167,7 +167,6 @@static irqreturn_t shpc_isr (int irq,void *dev_id);static void start_int_poll_timer (struct controller *ctrl,int sec); -static int hpc_check_cmd_status (struct controller *ctrl);static inline u8 shpc_readb (struct controller *ctrl,int reg) {@@ -317,7 +316,7 @@ static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)if (retval) goto out;Quoted 5 lines
drivers/pci/hotplug/shpchp_hpc.c static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd) · line 319
Quoted 2 lines
drivers/pci/hotplug/shpchp_hpc.c +1
-1- cmd_status =hpc_check_cmd_status (slot->ctrl); + cmd_status =shpchp_check_cmd_status (slot->ctrl);This rename looks like it should be a separate patch because it's not part of removing
hpc_ops.I think
hpc_check_cmd_statusmeant to be a part of thehpc_opsstruct. Here is the original struct:struct hpc_ops { int (*power_on_slot)(struct slot *slot); int (*slot_enable)(struct slot *slot); int (*slot_disable)(struct slot *slot); int (*set_bus_speed_mode)(struct slot *slot, enum pci_bus_speed speed); int (*get_power_status)(struct slot *slot, u8 *status); int (*get_attention_status)(struct slot *slot, u8 *status); int (*set_attention_status)(struct slot *slot, u8 status); int (*get_latch_status)(struct slot *slot, u8 *status); int (*get_adapter_status)(struct slot *slot, u8 *status); int (*get_adapter_speed)(struct slot *slot, enum pci_bus_speed *speed); int (*get_prog_int)(struct slot *slot, u8 *prog_int); int (*query_power_fault)(struct slot *slot); void (*green_led_on)(struct slot *slot); void (*green_led_off)(struct slot *slot); void (*green_led_blink)(struct slot *slot); void (*release_ctlr)(struct controller *ctrl); int (*check_cmd_status)(struct controller *ctrl); };As you can see it contains a pointer for
check_cmd_statusfunction, however thehpc_check_cmd_statuswas never assigned to it:static const struct hpc_ops shpchp_hpc_ops = { .power_on_slot = hpc_power_on_slot, .slot_enable = hpc_slot_enable, .slot_disable = hpc_slot_disable, .set_bus_speed_mode = hpc_set_bus_speed_mode, .set_attention_status = hpc_set_attention_status, .get_power_status = hpc_get_power_status, .get_attention_status = hpc_get_attention_status, .get_latch_status = hpc_get_latch_status, .get_adapter_status = hpc_get_adapter_status, .get_adapter_speed = hpc_get_adapter_speed, .get_prog_int = hpc_get_prog_int, .query_power_fault = hpc_query_power_fault, .green_led_on = hpc_set_green_led_on, .green_led_off = hpc_set_green_led_off, .green_led_blink = hpc_set_green_led_blink, .release_ctlr = hpc_release_ctlr, };
Quoted 4 lines
Which made me believe that this function supposed to be a part of the
hpc_opsstruct and whoever wrote the code added a pointer for it but then they forgot to assign the function to it during the actual definition of the struct. So I renamed it anyway.
Good point, thanks. Applied to pci/hotplug for v6.12, thanks for your work!
Bjorn