Skip to content

Commit a7da216

Browse files
l1kbjorn-helgaas
authored andcommitted
PCI: hotplug: Drop hotplug_slot_info
Ever since the PCI hotplug core was introduced in 2002, drivers had to allocate and register a struct hotplug_slot_info for every slot: https://git.kernel.org/tglx/history/c/a8a2069f432c Apparently the idea was that drivers furnish the hotplug core with an up-to-date card presence status, power status, latch status and attention indicator status as well as notify the hotplug core of changes thereof. However only 4 out of 12 hotplug drivers bother to notify the hotplug core with pci_hp_change_slot_info() and the hotplug core never made any use of the information: There is just a single macro in pci_hotplug_core.c, GET_STATUS(), which uses the hotplug_slot_info if the driver lacks the corresponding callback in hotplug_slot_ops. The macro is called when the user reads the attribute via sysfs. Now, if the callback isn't defined, the attribute isn't exposed in sysfs in the first place (see e.g. has_power_file()). There are only two situations when the hotplug_slot_info would actually be accessed: * If the driver defines ->enable_slot or ->disable_slot but not ->get_power_status. * If the driver defines ->set_attention_status but not ->get_attention_status. There is no driver doing the former and just a single driver doing the latter, namely pnv_php.c. Amend it with a ->get_attention_status callback. With that, the hotplug_slot_info becomes completely unused by the PCI hotplug core. But a few drivers use it internally as a cache: cpcihp uses it to cache the latch_status and adapter_status. cpqhp uses it to cache the adapter_status. pnv_php and rpaphp use it to cache the attention_status. shpchp uses it to cache all four values. Amend these drivers to cache the information in their private slot struct. shpchp's slot struct already contains members to cache the power_status and adapter_status, so additional members are only needed for the other two values. In the case of cpqphp, the cached value is only accessed in a single place, so instead of caching it, read the current value from the hardware. Caution: acpiphp, cpci, cpqhp, shpchp, asus-wmi and eeepc-laptop populate the hotplug_slot_info with initial values on probe. That code is herewith removed. There is a theoretical chance that the code has side effects without which the driver fails to function, e.g. if the ACPI method to read the adapter status needs to be executed at least once on probe. That seems unlikely to me, still maintainers should review the changes carefully for this possibility. Rafael adds: "I'm not aware of any case in which it will break anything, [...] but if that happens, it may be necessary to add the execution of the control methods in question directly to the initialization part." Signed-off-by: Lukas Wunner <lukas@wunner.de> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Tyrel Datwyler <tyreld@linux.vnet.ibm.com> # drivers/pci/hotplug/rpa* Acked-by: Sebastian Ott <sebott@linux.ibm.com> # drivers/pci/hotplug/s390* Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com> # drivers/platform/x86 Cc: Len Brown <lenb@kernel.org> Cc: Scott Murray <scott@spiteful.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Oliver OHalloran <oliveroh@au1.ibm.com> Cc: Gavin Shan <gwshan@linux.vnet.ibm.com> Cc: Gerald Schaefer <gerald.schaefer@de.ibm.com> Cc: Corentin Chary <corentin.chary@gmail.com> Cc: Darren Hart <dvhart@infradead.org>
1 parent 81c4b5b commit a7da216

24 files changed

Lines changed: 64 additions & 340 deletions

‎arch/powerpc/include/asm/pnv-pci.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ void pnv_cxl_release_hwirq_ranges(struct cxl_irq_ranges *irqs,
5454

5555
struct pnv_php_slot {
5656
struct hotplug_slot slot;
57-
struct hotplug_slot_info slot_info;
5857
uint64_t id;
5958
char *name;
6059
int slot_no;
@@ -72,6 +71,7 @@ struct pnv_php_slot {
7271
struct pci_dev *pdev;
7372
struct pci_bus *bus;
7473
bool power_state_check;
74+
u8 attention_state;
7575
void *fdt;
7676
void *dt;
7777
struct of_changeset ocs;

‎drivers/pci/hotplug/acpiphp.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ struct acpiphp_slot;
3535
struct slot {
3636
struct hotplug_slot *hotplug_slot;
3737
struct acpiphp_slot *acpi_slot;
38-
struct hotplug_slot_info info;
3938
unsigned int sun; /* ACPI _SUN (Slot User Number) value */
4039
};
4140

‎drivers/pci/hotplug/acpiphp_core.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,10 @@ int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot,
270270
if (!slot->hotplug_slot)
271271
goto error_slot;
272272

273-
slot->hotplug_slot->info = &slot->info;
274-
275273
slot->hotplug_slot->private = slot;
276274
slot->hotplug_slot->ops = &acpi_hotplug_slot_ops;
277275

278276
slot->acpi_slot = acpiphp_slot;
279-
slot->hotplug_slot->info->power_status = acpiphp_get_power_status(slot->acpi_slot);
280-
slot->hotplug_slot->info->attention_status = 0;
281-
slot->hotplug_slot->info->latch_status = acpiphp_get_latch_status(slot->acpi_slot);
282-
slot->hotplug_slot->info->adapter_status = acpiphp_get_adapter_status(slot->acpi_slot);
283277

284278
acpiphp_slot->slot = slot;
285279
slot->sun = sun;

‎drivers/pci/hotplug/cpci_hotplug.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ struct slot {
3232
unsigned int devfn;
3333
struct pci_bus *bus;
3434
struct pci_dev *dev;
35+
unsigned int latch_status:1;
36+
unsigned int adapter_status:1;
3537
unsigned int extracting;
3638
struct hotplug_slot *hotplug_slot;
3739
struct list_head slot_list;

‎drivers/pci/hotplug/cpci_hotplug_core.c‎

Lines changed: 14 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,6 @@ static const struct hotplug_slot_ops cpci_hotplug_slot_ops = {
6767
.get_latch_status = get_latch_status,
6868
};
6969

70-
static int
71-
update_latch_status(struct hotplug_slot *hotplug_slot, u8 value)
72-
{
73-
struct hotplug_slot_info info;
74-
75-
memcpy(&info, hotplug_slot->info, sizeof(struct hotplug_slot_info));
76-
info.latch_status = value;
77-
return pci_hp_change_slot_info(hotplug_slot, &info);
78-
}
79-
80-
static int
81-
update_adapter_status(struct hotplug_slot *hotplug_slot, u8 value)
82-
{
83-
struct hotplug_slot_info info;
84-
85-
memcpy(&info, hotplug_slot->info, sizeof(struct hotplug_slot_info));
86-
info.adapter_status = value;
87-
return pci_hp_change_slot_info(hotplug_slot, &info);
88-
}
89-
9070
static int
9171
enable_slot(struct hotplug_slot *hotplug_slot)
9272
{
@@ -135,8 +115,7 @@ disable_slot(struct hotplug_slot *hotplug_slot)
135115
goto disable_error;
136116
}
137117

138-
if (update_adapter_status(slot->hotplug_slot, 0))
139-
warn("failure to update adapter file");
118+
slot->adapter_status = 0;
140119

141120
if (slot->extracting) {
142121
slot->extracting = 0;
@@ -184,20 +163,23 @@ set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
184163
static int
185164
get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
186165
{
187-
*value = hotplug_slot->info->adapter_status;
166+
struct slot *slot = hotplug_slot->private;
167+
168+
*value = slot->adapter_status;
188169
return 0;
189170
}
190171

191172
static int
192173
get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
193174
{
194-
*value = hotplug_slot->info->latch_status;
175+
struct slot *slot = hotplug_slot->private;
176+
177+
*value = slot->latch_status;
195178
return 0;
196179
}
197180

198181
static void release_slot(struct slot *slot)
199182
{
200-
kfree(slot->hotplug_slot->info);
201183
kfree(slot->hotplug_slot);
202184
pci_dev_put(slot->dev);
203185
kfree(slot);
@@ -210,7 +192,6 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
210192
{
211193
struct slot *slot;
212194
struct hotplug_slot *hotplug_slot;
213-
struct hotplug_slot_info *info;
214195
char name[SLOT_NAME_SIZE];
215196
int status;
216197
int i;
@@ -237,13 +218,6 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
237218
}
238219
slot->hotplug_slot = hotplug_slot;
239220

240-
info = kzalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
241-
if (!info) {
242-
status = -ENOMEM;
243-
goto error_hpslot;
244-
}
245-
hotplug_slot->info = info;
246-
247221
slot->bus = bus;
248222
slot->number = i;
249223
slot->devfn = PCI_DEVFN(i, 0);
@@ -253,19 +227,11 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
253227
hotplug_slot->private = slot;
254228
hotplug_slot->ops = &cpci_hotplug_slot_ops;
255229

256-
/*
257-
* Initialize the slot info structure with some known
258-
* good values.
259-
*/
260-
dbg("initializing slot %s", name);
261-
info->power_status = cpci_get_power_status(slot);
262-
info->attention_status = cpci_get_attention_status(slot);
263-
264230
dbg("registering slot %s", name);
265231
status = pci_hp_register(slot->hotplug_slot, bus, i, name);
266232
if (status) {
267233
err("pci_hp_register failed with error %d", status);
268-
goto error_info;
234+
goto error_hpslot;
269235
}
270236
dbg("slot registered with name: %s", slot_name(slot));
271237

@@ -276,8 +242,6 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
276242
up_write(&list_rwsem);
277243
}
278244
return 0;
279-
error_info:
280-
kfree(info);
281245
error_hpslot:
282246
kfree(hotplug_slot);
283247
error_slot:
@@ -359,10 +323,8 @@ init_slots(int clear_ins)
359323
__func__, slot_name(slot));
360324
dev = pci_get_slot(slot->bus, PCI_DEVFN(slot->number, 0));
361325
if (dev) {
362-
if (update_adapter_status(slot->hotplug_slot, 1))
363-
warn("failure to update adapter file");
364-
if (update_latch_status(slot->hotplug_slot, 1))
365-
warn("failure to update latch file");
326+
slot->adapter_status = 1;
327+
slot->latch_status = 1;
366328
slot->dev = dev;
367329
}
368330
}
@@ -424,11 +386,8 @@ check_slots(void)
424386
dbg("%s - slot %s HS_CSR (2) = %04x",
425387
__func__, slot_name(slot), hs_csr);
426388

427-
if (update_latch_status(slot->hotplug_slot, 1))
428-
warn("failure to update latch file");
429-
430-
if (update_adapter_status(slot->hotplug_slot, 1))
431-
warn("failure to update adapter file");
389+
slot->latch_status = 1;
390+
slot->adapter_status = 1;
432391

433392
cpci_led_off(slot);
434393

@@ -449,9 +408,7 @@ check_slots(void)
449408
__func__, slot_name(slot), hs_csr);
450409

451410
if (!slot->extracting) {
452-
if (update_latch_status(slot->hotplug_slot, 0))
453-
warn("failure to update latch file");
454-
411+
slot->latch_status = 0;
455412
slot->extracting = 1;
456413
atomic_inc(&extracting);
457414
}
@@ -465,8 +422,7 @@ check_slots(void)
465422
*/
466423
err("card in slot %s was improperly removed",
467424
slot_name(slot));
468-
if (update_adapter_status(slot->hotplug_slot, 0))
469-
warn("failure to update adapter file");
425+
slot->adapter_status = 0;
470426
slot->extracting = 0;
471427
atomic_dec(&extracting);
472428
}

‎drivers/pci/hotplug/cpqphp_core.c‎

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ static int ctrl_slot_cleanup(struct controller *ctrl)
276276
while (old_slot) {
277277
next_slot = old_slot->next;
278278
pci_hp_deregister(old_slot->hotplug_slot);
279-
kfree(old_slot->hotplug_slot->info);
280279
kfree(old_slot->hotplug_slot);
281280
kfree(old_slot);
282281
old_slot = next_slot;
@@ -579,7 +578,6 @@ static int ctrl_slot_setup(struct controller *ctrl,
579578
{
580579
struct slot *slot;
581580
struct hotplug_slot *hotplug_slot;
582-
struct hotplug_slot_info *hotplug_slot_info;
583581
struct pci_bus *bus = ctrl->pci_bus;
584582
u8 number_of_slots;
585583
u8 slot_device;
@@ -613,14 +611,6 @@ static int ctrl_slot_setup(struct controller *ctrl,
613611
}
614612
hotplug_slot = slot->hotplug_slot;
615613

616-
hotplug_slot->info = kzalloc(sizeof(*(hotplug_slot->info)),
617-
GFP_KERNEL);
618-
if (!hotplug_slot->info) {
619-
result = -ENOMEM;
620-
goto error_hpslot;
621-
}
622-
hotplug_slot_info = hotplug_slot->info;
623-
624614
slot->ctrl = ctrl;
625615
slot->bus = ctrl->bus;
626616
slot->device = slot_device;
@@ -673,14 +663,6 @@ static int ctrl_slot_setup(struct controller *ctrl,
673663
snprintf(name, SLOT_NAME_SIZE, "%u", slot->number);
674664
hotplug_slot->ops = &cpqphp_hotplug_slot_ops;
675665

676-
hotplug_slot_info->power_status = get_slot_enabled(ctrl, slot);
677-
hotplug_slot_info->attention_status =
678-
cpq_get_attention_status(ctrl, slot);
679-
hotplug_slot_info->latch_status =
680-
cpq_get_latch_status(ctrl, slot);
681-
hotplug_slot_info->adapter_status =
682-
get_presence_status(ctrl, slot);
683-
684666
dbg("registering bus %d, dev %d, number %d, ctrl->slot_device_offset %d, slot %d\n",
685667
slot->bus, slot->device,
686668
slot->number, ctrl->slot_device_offset,
@@ -691,7 +673,7 @@ static int ctrl_slot_setup(struct controller *ctrl,
691673
name);
692674
if (result) {
693675
err("pci_hp_register failed with error %d\n", result);
694-
goto error_info;
676+
goto error_hpslot;
695677
}
696678

697679
slot->next = ctrl->slot;
@@ -703,8 +685,6 @@ static int ctrl_slot_setup(struct controller *ctrl,
703685
}
704686

705687
return 0;
706-
error_info:
707-
kfree(hotplug_slot_info);
708688
error_hpslot:
709689
kfree(hotplug_slot);
710690
error_slot:

‎drivers/pci/hotplug/cpqphp_ctrl.c‎

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,9 +1130,9 @@ static u8 set_controller_speed(struct controller *ctrl, u8 adapter_speed, u8 hp_
11301130
for (slot = ctrl->slot; slot; slot = slot->next) {
11311131
if (slot->device == (hp_slot + ctrl->slot_device_offset))
11321132
continue;
1133-
if (!slot->hotplug_slot || !slot->hotplug_slot->info)
1133+
if (!slot->hotplug_slot)
11341134
continue;
1135-
if (slot->hotplug_slot->info->adapter_status == 0)
1135+
if (get_presence_status(ctrl, slot) == 0)
11361136
continue;
11371137
/* If another adapter is running on the same segment but at a
11381138
* lower speed/mode, we allow the new adapter to function at
@@ -1767,24 +1767,6 @@ void cpqhp_event_stop_thread(void)
17671767
}
17681768

17691769

1770-
static int update_slot_info(struct controller *ctrl, struct slot *slot)
1771-
{
1772-
struct hotplug_slot_info *info;
1773-
int result;
1774-
1775-
info = kmalloc(sizeof(*info), GFP_KERNEL);
1776-
if (!info)
1777-
return -ENOMEM;
1778-
1779-
info->power_status = get_slot_enabled(ctrl, slot);
1780-
info->attention_status = cpq_get_attention_status(ctrl, slot);
1781-
info->latch_status = cpq_get_latch_status(ctrl, slot);
1782-
info->adapter_status = get_presence_status(ctrl, slot);
1783-
result = pci_hp_change_slot_info(slot->hotplug_slot, info);
1784-
kfree(info);
1785-
return result;
1786-
}
1787-
17881770
static void interrupt_event_handler(struct controller *ctrl)
17891771
{
17901772
int loop = 0;
@@ -1884,9 +1866,6 @@ static void interrupt_event_handler(struct controller *ctrl)
18841866
/***********POWER FAULT */
18851867
else if (ctrl->event_queue[loop].event_type == INT_POWER_FAULT) {
18861868
dbg("power fault\n");
1887-
} else {
1888-
/* refresh notification */
1889-
update_slot_info(ctrl, p_slot);
18901869
}
18911870

18921871
ctrl->event_queue[loop].event_type = 0;
@@ -2057,9 +2036,6 @@ int cpqhp_process_SI(struct controller *ctrl, struct pci_func *func)
20572036
if (rc)
20582037
dbg("%s: rc = %d\n", __func__, rc);
20592038

2060-
if (p_slot)
2061-
update_slot_info(ctrl, p_slot);
2062-
20632039
return rc;
20642040
}
20652041

@@ -2125,9 +2101,6 @@ int cpqhp_process_SS(struct controller *ctrl, struct pci_func *func)
21252101
rc = 1;
21262102
}
21272103

2128-
if (p_slot)
2129-
update_slot_info(ctrl, p_slot);
2130-
21312104
return rc;
21322105
}
21332106

0 commit comments

Comments
 (0)