Commit 1d2e8b1c authored by Alex Chiang's avatar Alex Chiang Committed by Jesse Barnes

PCI Hotplug: cpqphp: refactor cpqhp_save_config

Handle an empty slot at the top of the loop, and continue early.

This allows us to un-indent the rest of the function by one level.
Signed-off-by: default avatarAlex Chiang <achiang@hp.com>
Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent 4aabb58e
...@@ -359,121 +359,121 @@ int cpqhp_save_config(struct controller *ctrl, int busnumber, int is_hot_plug) ...@@ -359,121 +359,121 @@ int cpqhp_save_config(struct controller *ctrl, int busnumber, int is_hot_plug)
ctrl->pci_bus->number = busnumber; ctrl->pci_bus->number = busnumber;
for (device = FirstSupported; device <= LastSupported; device++) { for (device = FirstSupported; device <= LastSupported; device++) {
ID = 0xFFFFFFFF; ID = 0xFFFFFFFF;
rc = pci_bus_read_config_dword (ctrl->pci_bus, PCI_DEVFN(device, 0), PCI_VENDOR_ID, &ID); rc = pci_bus_read_config_dword(ctrl->pci_bus, PCI_DEVFN(device, 0), PCI_VENDOR_ID, &ID);
if (ID != 0xFFFFFFFF) { /* device in slot */ if (ID == 0xFFFFFFFF) {
rc = pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(device, 0), 0x0B, &class_code); if (is_hot_plug) {
if (rc) /* Setup slot structure with entry for empty
return rc; * slot
*/
rc = pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(device, 0), PCI_HEADER_TYPE, &header_type); new_slot = cpqhp_slot_create(busnumber);
if (rc) if (new_slot == NULL)
return rc; return 1;
/* If multi-function device, set max_functions to 8 */
if (header_type & 0x80)
max_functions = 8;
else
max_functions = 1;
function = 0; new_slot->bus = (u8) busnumber;
new_slot->device = (u8) device;
new_slot->function = 0;
new_slot->is_a_board = 0;
new_slot->presence_save = 0;
new_slot->switch_save = 0;
}
continue;
}
do { rc = pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(device, 0), 0x0B, &class_code);
DevError = 0; if (rc)
if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { return rc;
/* Recurse the subordinate bus
* get the subordinate bus number
*/
rc = pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(device, function), PCI_SECONDARY_BUS, &secondary_bus);
if (rc) {
return rc;
} else {
sub_bus = (int) secondary_bus;
/* Save secondary bus cfg spc rc = pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(device, 0), PCI_HEADER_TYPE, &header_type);
* with this recursive call. if (rc)
*/ return rc;
rc = cpqhp_save_config(ctrl, sub_bus, 0);
if (rc)
return rc;
ctrl->pci_bus->number = busnumber;
}
}
index = 0; /* If multi-function device, set max_functions to 8 */
new_slot = cpqhp_slot_find(busnumber, device, index++); if (header_type & 0x80)
while (new_slot && max_functions = 8;
(new_slot->function != (u8) function)) else
new_slot = cpqhp_slot_find(busnumber, device, index++); max_functions = 1;
if (!new_slot) { function = 0;
/* Setup slot structure. */
new_slot = cpqhp_slot_create(busnumber);
if (new_slot == NULL) do {
return(1); DevError = 0;
} if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
/* Recurse the subordinate bus
* get the subordinate bus number
*/
rc = pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(device, function), PCI_SECONDARY_BUS, &secondary_bus);
if (rc) {
return rc;
} else {
sub_bus = (int) secondary_bus;
new_slot->bus = (u8) busnumber; /* Save secondary bus cfg spc
new_slot->device = (u8) device; * with this recursive call.
new_slot->function = (u8) function; */
new_slot->is_a_board = 1; rc = cpqhp_save_config(ctrl, sub_bus, 0);
new_slot->switch_save = 0x10;
/* In case of unsupported board */
new_slot->status = DevError;
new_slot->pci_dev = pci_find_slot(new_slot->bus, (new_slot->device << 3) | new_slot->function);
for (cloop = 0; cloop < 0x20; cloop++) {
rc = pci_bus_read_config_dword (ctrl->pci_bus, PCI_DEVFN(device, function), cloop << 2, (u32 *) & (new_slot-> config_space [cloop]));
if (rc) if (rc)
return rc; return rc;
ctrl->pci_bus->number = busnumber;
} }
}
function++; index = 0;
new_slot = cpqhp_slot_find(busnumber, device, index++);
while (new_slot &&
(new_slot->function != (u8) function))
new_slot = cpqhp_slot_find(busnumber, device, index++);
stop_it = 0; if (!new_slot) {
/* Setup slot structure. */
new_slot = cpqhp_slot_create(busnumber);
if (new_slot == NULL)
return 1;
}
/* this loop skips to the next present function new_slot->bus = (u8) busnumber;
* reading in Class Code and Header type. new_slot->device = (u8) device;
*/ new_slot->function = (u8) function;
new_slot->is_a_board = 1;
new_slot->switch_save = 0x10;
/* In case of unsupported board */
new_slot->status = DevError;
new_slot->pci_dev = pci_find_slot(new_slot->bus, (new_slot->device << 3) | new_slot->function);
for (cloop = 0; cloop < 0x20; cloop++) {
rc = pci_bus_read_config_dword(ctrl->pci_bus, PCI_DEVFN(device, function), cloop << 2, (u32 *) & (new_slot-> config_space [cloop]));
if (rc)
return rc;
}
while ((function < max_functions)&&(!stop_it)) { function++;
rc = pci_bus_read_config_dword (ctrl->pci_bus, PCI_DEVFN(device, function), PCI_VENDOR_ID, &ID);
if (ID == 0xFFFFFFFF) { /* nothing there. */
function++;
} else { /* Something there */
rc = pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(device, function), 0x0B, &class_code);
if (rc)
return rc;
rc = pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(device, function), PCI_HEADER_TYPE, &header_type); stop_it = 0;
if (rc)
return rc;
stop_it++; /* this loop skips to the next present function
} * reading in Class Code and Header type.
*/
while ((function < max_functions) && (!stop_it)) {
rc = pci_bus_read_config_dword(ctrl->pci_bus, PCI_DEVFN(device, function), PCI_VENDOR_ID, &ID);
if (ID == 0xFFFFFFFF) {
function++;
continue;
} }
rc = pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(device, function), 0x0B, &class_code);
if (rc)
return rc;
} while (function < max_functions); rc = pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(device, function), PCI_HEADER_TYPE, &header_type);
} /* End of IF (device in slot?) */ if (rc)
else if (is_hot_plug) { return rc;
/* Setup slot structure with entry for empty slot */
new_slot = cpqhp_slot_create(busnumber);
if (new_slot == NULL) { stop_it++;
return(1);
} }
new_slot->bus = (u8) busnumber; } while (function < max_functions);
new_slot->device = (u8) device;
new_slot->function = 0;
new_slot->is_a_board = 0;
new_slot->presence_save = 0;
new_slot->switch_save = 0;
}
} /* End of FOR loop */ } /* End of FOR loop */
return(0); return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment