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: Alex Chiang <achiang@hp.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
This commit is contained in:
Alex Chiang 2009-03-31 09:23:57 -06:00 committed by Jesse Barnes
parent 4aabb58e1f
commit 1d2e8b1c58

View file

@ -359,14 +359,32 @@ 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) {
/* Setup slot structure with entry for empty
* slot
*/
new_slot = cpqhp_slot_create(busnumber);
if (new_slot == NULL)
return 1;
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;
}
rc = pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(device, 0), 0x0B, &class_code);
if (rc) if (rc)
return rc; return rc;
rc = pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(device, 0), PCI_HEADER_TYPE, &header_type); rc = pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(device, 0), PCI_HEADER_TYPE, &header_type);
if (rc) if (rc)
return rc; return rc;
@ -384,7 +402,7 @@ int cpqhp_save_config(struct controller *ctrl, int busnumber, int is_hot_plug)
/* Recurse the subordinate bus /* Recurse the subordinate bus
* get the subordinate bus number * get the subordinate bus number
*/ */
rc = pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(device, function), PCI_SECONDARY_BUS, &secondary_bus); rc = pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(device, function), PCI_SECONDARY_BUS, &secondary_bus);
if (rc) { if (rc) {
return rc; return rc;
} else { } else {
@ -409,9 +427,8 @@ int cpqhp_save_config(struct controller *ctrl, int busnumber, int is_hot_plug)
if (!new_slot) { if (!new_slot) {
/* Setup slot structure. */ /* Setup slot structure. */
new_slot = cpqhp_slot_create(busnumber); new_slot = cpqhp_slot_create(busnumber);
if (new_slot == NULL) if (new_slot == NULL)
return(1); return 1;
} }
new_slot->bus = (u8) busnumber; new_slot->bus = (u8) busnumber;
@ -424,7 +441,7 @@ int cpqhp_save_config(struct controller *ctrl, int busnumber, int is_hot_plug)
new_slot->pci_dev = pci_find_slot(new_slot->bus, (new_slot->device << 3) | new_slot->function); new_slot->pci_dev = pci_find_slot(new_slot->bus, (new_slot->device << 3) | new_slot->function);
for (cloop = 0; cloop < 0x20; cloop++) { 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])); 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;
} }
@ -436,44 +453,27 @@ int cpqhp_save_config(struct controller *ctrl, int busnumber, int is_hot_plug)
/* this loop skips to the next present function /* this loop skips to the next present function
* reading in Class Code and Header type. * reading in Class Code and Header type.
*/ */
while ((function < max_functions) && (!stop_it)) {
while ((function < max_functions)&&(!stop_it)) { rc = pci_bus_read_config_dword(ctrl->pci_bus, PCI_DEVFN(device, function), PCI_VENDOR_ID, &ID);
rc = pci_bus_read_config_dword (ctrl->pci_bus, PCI_DEVFN(device, function), PCI_VENDOR_ID, &ID); if (ID == 0xFFFFFFFF) {
if (ID == 0xFFFFFFFF) { /* nothing there. */
function++; function++;
} else { /* Something there */ continue;
rc = pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(device, function), 0x0B, &class_code); }
rc = pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(device, function), 0x0B, &class_code);
if (rc) if (rc)
return rc; return rc;
rc = pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(device, function), PCI_HEADER_TYPE, &header_type); rc = pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(device, function), PCI_HEADER_TYPE, &header_type);
if (rc) if (rc)
return rc; return rc;
stop_it++; stop_it++;
} }
}
} while (function < max_functions); } while (function < max_functions);
} /* End of IF (device in slot?) */
else if (is_hot_plug) {
/* Setup slot structure with entry for empty slot */
new_slot = cpqhp_slot_create(busnumber);
if (new_slot == NULL) {
return(1);
}
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;
}
} /* End of FOR loop */ } /* End of FOR loop */
return(0); return 0;
} }