Skip to content

Commit 5d386e1

Browse files
kkaneshigegregkh
authored andcommitted
pciehp: Event handling rework
The event handler of PCIEHP driver is unnecessarily very complex. In addition, current event handler can only a fixed number of events at the same time, and some of events would be lost if several number of events happened at the same time. This patch simplify the event handler using 'work queue', and it also fix the above-mentioned issue. Signed-off-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com> Signed-off-by: Kristen Carlson Accardi <kristen.c.accardi@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent f7bdd12 commit 5d386e1

4 files changed

Lines changed: 321 additions & 389 deletions

File tree

‎drivers/pci/hotplug/pciehp.h‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ extern int pciehp_poll_mode;
4343
extern int pciehp_poll_time;
4444
extern int pciehp_debug;
4545
extern int pciehp_force;
46+
extern struct workqueue_struct *pciehp_wq;
4647

4748
#define dbg(format, arg...) \
4849
do { \
@@ -70,14 +71,16 @@ struct slot {
7071
struct list_head slot_list;
7172
char name[SLOT_NAME_SIZE];
7273
unsigned long last_emi_toggle;
74+
struct delayed_work work; /* work for button event */
75+
struct mutex lock;
7376
};
7477

7578
struct event_info {
7679
u32 event_type;
77-
u8 hp_slot;
80+
struct slot *p_slot;
81+
struct work_struct work;
7882
};
7983

80-
#define MAX_EVENTS 10
8184
struct controller {
8285
struct controller *next;
8386
struct mutex crit_sect; /* critical section mutex */
@@ -86,11 +89,9 @@ struct controller {
8689
int slot_num_inc; /* 1 or -1 */
8790
struct pci_dev *pci_dev;
8891
struct list_head slot_list;
89-
struct event_info event_queue[MAX_EVENTS];
9092
struct slot *slot;
9193
struct hpc_ops *hpc_ops;
9294
wait_queue_head_t queue; /* sleep & wake process */
93-
u8 next_event;
9495
u8 bus;
9596
u8 device;
9697
u8 function;
@@ -149,16 +150,15 @@ struct controller {
149150
#define HP_SUPR_RM(cap) (cap & HP_SUPR_RM_SUP)
150151
#define EMI(cap) (cap & EMI_PRSN)
151152

152-
extern int pciehp_event_start_thread(void);
153-
extern void pciehp_event_stop_thread(void);
154-
extern int pciehp_enable_slot(struct slot *slot);
155-
extern int pciehp_disable_slot(struct slot *slot);
153+
extern int pciehp_sysfs_enable_slot(struct slot *slot);
154+
extern int pciehp_sysfs_disable_slot(struct slot *slot);
156155
extern u8 pciehp_handle_attention_button(u8 hp_slot, struct controller *ctrl);
157156
extern u8 pciehp_handle_switch_change(u8 hp_slot, struct controller *ctrl);
158157
extern u8 pciehp_handle_presence_change(u8 hp_slot, struct controller *ctrl);
159158
extern u8 pciehp_handle_power_fault(u8 hp_slot, struct controller *ctrl);
160159
extern int pciehp_configure_device(struct slot *p_slot);
161160
extern int pciehp_unconfigure_device(struct slot *p_slot);
161+
extern void queue_pushbutton_work(struct work_struct *work);
162162
int pcie_init(struct controller *ctrl, struct pcie_device *dev);
163163

164164
/* Global variables */

‎drivers/pci/hotplug/pciehp_core.c‎

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ int pciehp_debug;
4141
int pciehp_poll_mode;
4242
int pciehp_poll_time;
4343
int pciehp_force;
44+
struct workqueue_struct *pciehp_wq;
4445
struct controller *pciehp_ctrl_list;
4546

4647
#define DRIVER_VERSION "0.4"
@@ -62,7 +63,6 @@ MODULE_PARM_DESC(pciehp_force, "Force pciehp, even if _OSC and OSHP are missing"
6263

6364
#define PCIE_MODULE_NAME "pciehp"
6465

65-
static int pcie_start_thread (void);
6666
static int set_attention_status (struct hotplug_slot *slot, u8 value);
6767
static int enable_slot (struct hotplug_slot *slot);
6868
static int disable_slot (struct hotplug_slot *slot);
@@ -229,6 +229,8 @@ static int init_slots(struct controller *ctrl)
229229
slot->device = ctrl->slot_device_offset + i;
230230
slot->hpc_ops = ctrl->hpc_ops;
231231
slot->number = ctrl->first_slot;
232+
mutex_init(&slot->lock);
233+
INIT_DELAYED_WORK(&slot->work, queue_pushbutton_work);
232234

233235
/* register this slot with the hotplug pci core */
234236
hotplug_slot->private = slot;
@@ -286,6 +288,9 @@ static void cleanup_slots(struct controller *ctrl)
286288
if (EMI(ctrl->ctrlcap))
287289
sysfs_remove_file(&slot->hotplug_slot->kobj,
288290
&hotplug_slot_attr_lock.attr);
291+
cancel_delayed_work(&slot->work);
292+
flush_scheduled_work();
293+
flush_workqueue(pciehp_wq);
289294
pci_hp_deregister(slot->hotplug_slot);
290295
}
291296
}
@@ -314,7 +319,7 @@ static int enable_slot(struct hotplug_slot *hotplug_slot)
314319

315320
dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
316321

317-
return pciehp_enable_slot(slot);
322+
return pciehp_sysfs_enable_slot(slot);
318323
}
319324

320325

@@ -324,7 +329,7 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
324329

325330
dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
326331

327-
return pciehp_disable_slot(slot);
332+
return pciehp_sysfs_disable_slot(slot);
328333
}
329334

330335
static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
@@ -466,9 +471,6 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_
466471

467472
t_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset);
468473

469-
/* Finish setting up the hot plug ctrl device */
470-
ctrl->next_event = 0;
471-
472474
if (!pciehp_ctrl_list) {
473475
pciehp_ctrl_list = ctrl;
474476
ctrl->next = NULL;
@@ -496,22 +498,6 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_
496498
return -ENODEV;
497499
}
498500

499-
500-
static int pcie_start_thread(void)
501-
{
502-
int retval = 0;
503-
504-
dbg("Initialize + Start the notification/polling mechanism \n");
505-
506-
retval = pciehp_event_start_thread();
507-
if (retval) {
508-
dbg("pciehp_event_start_thread() failed\n");
509-
return retval;
510-
}
511-
512-
return retval;
513-
}
514-
515501
static void __exit unload_pciehpd(void)
516502
{
517503
struct controller *ctrl;
@@ -529,10 +515,6 @@ static void __exit unload_pciehpd(void)
529515

530516
kfree(tctrl);
531517
}
532-
533-
/* Stop the notification mechanism */
534-
pciehp_event_stop_thread();
535-
536518
}
537519

538520
static void pciehp_remove (struct pcie_device *device)
@@ -585,21 +567,11 @@ static int __init pcied_init(void)
585567
pciehp_poll_mode = 1;
586568
#endif
587569

588-
retval = pcie_start_thread();
589-
if (retval)
590-
goto error_hpc_init;
591-
592570
retval = pcie_port_service_register(&hpdriver_portdrv);
593571
dbg("pcie_port_service_register = %d\n", retval);
594572
info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
595573
if (retval)
596574
dbg("%s: Failure to register service\n", __FUNCTION__);
597-
598-
error_hpc_init:
599-
if (retval) {
600-
pciehp_event_stop_thread();
601-
};
602-
603575
return retval;
604576
}
605577

0 commit comments

Comments
 (0)