diff options
author | Alex Chiang <achiang@hp.com> | 2009-03-31 11:23:57 -0400 |
---|---|---|
committer | Jesse Barnes <jbarnes@virtuousgeek.org> | 2009-06-11 15:04:13 -0400 |
commit | 1d2e8b1c58ef96b8834b139caf4357effedcb5ab (patch) | |
tree | 1531d3175f6b01172a3ea292f3c5d91be5049b04 /drivers/pci | |
parent | 4aabb58e1f544e97dbb97d0ce29bdfc9108f2f2c (diff) |
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>
Diffstat (limited to 'drivers/pci')
-rw-r--r-- | drivers/pci/hotplug/cpqphp_pci.c | 182 |
1 files changed, 91 insertions, 91 deletions
diff --git a/drivers/pci/hotplug/cpqphp_pci.c b/drivers/pci/hotplug/cpqphp_pci.c index bd384e94f212..2909e3f6caa7 100644 --- a/drivers/pci/hotplug/cpqphp_pci.c +++ b/drivers/pci/hotplug/cpqphp_pci.c | |||
@@ -359,121 +359,121 @@ int cpqhp_save_config(struct controller *ctrl, int busnumber, int is_hot_plug) | |||
359 | ctrl->pci_bus->number = busnumber; | 359 | ctrl->pci_bus->number = busnumber; |
360 | for (device = FirstSupported; device <= LastSupported; device++) { | 360 | for (device = FirstSupported; device <= LastSupported; device++) { |
361 | ID = 0xFFFFFFFF; | 361 | ID = 0xFFFFFFFF; |
362 | rc = pci_bus_read_config_dword (ctrl->pci_bus, PCI_DEVFN(device, 0), PCI_VENDOR_ID, &ID); | 362 | rc = pci_bus_read_config_dword(ctrl->pci_bus, PCI_DEVFN(device, 0), PCI_VENDOR_ID, &ID); |
363 | 363 | ||
364 | if (ID != 0xFFFFFFFF) { /* device in slot */ | 364 | if (ID == 0xFFFFFFFF) { |
365 | rc = pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(device, 0), 0x0B, &class_code); | 365 | if (is_hot_plug) { |
366 | if (rc) | 366 | /* Setup slot structure with entry for empty |
367 | return rc; | 367 | * slot |
368 | 368 | */ | |
369 | rc = pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(device, 0), PCI_HEADER_TYPE, &header_type); | 369 | new_slot = cpqhp_slot_create(busnumber); |
370 | if (rc) | 370 | if (new_slot == NULL) |
371 | return rc; | 371 | return 1; |
372 | |||
373 | /* If multi-function device, set max_functions to 8 */ | ||
374 | if (header_type & 0x80) | ||
375 | max_functions = 8; | ||
376 | else | ||
377 | max_functions = 1; | ||
378 | 372 | ||
379 | function = 0; | 373 | new_slot->bus = (u8) busnumber; |
374 | new_slot->device = (u8) device; | ||
375 | new_slot->function = 0; | ||
376 | new_slot->is_a_board = 0; | ||
377 | new_slot->presence_save = 0; | ||
378 | new_slot->switch_save = 0; | ||
379 | } | ||
380 | continue; | ||
381 | } | ||
380 | 382 | ||
381 | do { | 383 | rc = pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(device, 0), 0x0B, &class_code); |
382 | DevError = 0; | 384 | if (rc) |
383 | if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { | 385 | return rc; |
384 | /* Recurse the subordinate bus | ||
385 | * get the subordinate bus number | ||
386 | */ | ||
387 | rc = pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(device, function), PCI_SECONDARY_BUS, &secondary_bus); | ||
388 | if (rc) { | ||
389 | return rc; | ||
390 | } else { | ||
391 | sub_bus = (int) secondary_bus; | ||
392 | 386 | ||
393 | /* Save secondary bus cfg spc | 387 | rc = pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(device, 0), PCI_HEADER_TYPE, &header_type); |
394 | * with this recursive call. | 388 | if (rc) |
395 | */ | 389 | return rc; |
396 | rc = cpqhp_save_config(ctrl, sub_bus, 0); | ||
397 | if (rc) | ||
398 | return rc; | ||
399 | ctrl->pci_bus->number = busnumber; | ||
400 | } | ||
401 | } | ||
402 | 390 | ||
403 | index = 0; | 391 | /* If multi-function device, set max_functions to 8 */ |
404 | new_slot = cpqhp_slot_find(busnumber, device, index++); | 392 | if (header_type & 0x80) |
405 | while (new_slot && | 393 | max_functions = 8; |
406 | (new_slot->function != (u8) function)) | 394 | else |
407 | new_slot = cpqhp_slot_find(busnumber, device, index++); | 395 | max_functions = 1; |
408 | 396 | ||
409 | if (!new_slot) { | 397 | function = 0; |
410 | /* Setup slot structure. */ | ||
411 | new_slot = cpqhp_slot_create(busnumber); | ||
412 | 398 | ||
413 | if (new_slot == NULL) | 399 | do { |
414 | return(1); | 400 | DevError = 0; |
415 | } | 401 | if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { |
402 | /* Recurse the subordinate bus | ||
403 | * get the subordinate bus number | ||
404 | */ | ||
405 | rc = pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(device, function), PCI_SECONDARY_BUS, &secondary_bus); | ||
406 | if (rc) { | ||
407 | return rc; | ||
408 | } else { | ||
409 | sub_bus = (int) secondary_bus; | ||
416 | 410 | ||
417 | new_slot->bus = (u8) busnumber; | 411 | /* Save secondary bus cfg spc |
418 | new_slot->device = (u8) device; | 412 | * with this recursive call. |
419 | new_slot->function = (u8) function; | 413 | */ |
420 | new_slot->is_a_board = 1; | 414 | rc = cpqhp_save_config(ctrl, sub_bus, 0); |
421 | new_slot->switch_save = 0x10; | ||
422 | /* In case of unsupported board */ | ||
423 | new_slot->status = DevError; | ||
424 | new_slot->pci_dev = pci_find_slot(new_slot->bus, (new_slot->device << 3) | new_slot->function); | ||
425 | |||
426 | for (cloop = 0; cloop < 0x20; cloop++) { | ||
427 | rc = pci_bus_read_config_dword (ctrl->pci_bus, PCI_DEVFN(device, function), cloop << 2, (u32 *) & (new_slot-> config_space [cloop])); | ||
428 | if (rc) | 415 | if (rc) |
429 | return rc; | 416 | return rc; |
417 | ctrl->pci_bus->number = busnumber; | ||
430 | } | 418 | } |
419 | } | ||
431 | 420 | ||
432 | function++; | 421 | index = 0; |
422 | new_slot = cpqhp_slot_find(busnumber, device, index++); | ||
423 | while (new_slot && | ||
424 | (new_slot->function != (u8) function)) | ||
425 | new_slot = cpqhp_slot_find(busnumber, device, index++); | ||
433 | 426 | ||
434 | stop_it = 0; | 427 | if (!new_slot) { |
428 | /* Setup slot structure. */ | ||
429 | new_slot = cpqhp_slot_create(busnumber); | ||
430 | if (new_slot == NULL) | ||
431 | return 1; | ||
432 | } | ||
435 | 433 | ||
436 | /* this loop skips to the next present function | 434 | new_slot->bus = (u8) busnumber; |
437 | * reading in Class Code and Header type. | 435 | new_slot->device = (u8) device; |
438 | */ | 436 | new_slot->function = (u8) function; |
437 | new_slot->is_a_board = 1; | ||
438 | new_slot->switch_save = 0x10; | ||
439 | /* In case of unsupported board */ | ||
440 | new_slot->status = DevError; | ||
441 | new_slot->pci_dev = pci_find_slot(new_slot->bus, (new_slot->device << 3) | new_slot->function); | ||
442 | |||
443 | for (cloop = 0; cloop < 0x20; cloop++) { | ||
444 | rc = pci_bus_read_config_dword(ctrl->pci_bus, PCI_DEVFN(device, function), cloop << 2, (u32 *) & (new_slot-> config_space [cloop])); | ||
445 | if (rc) | ||
446 | return rc; | ||
447 | } | ||
439 | 448 | ||
440 | while ((function < max_functions)&&(!stop_it)) { | 449 | function++; |
441 | rc = pci_bus_read_config_dword (ctrl->pci_bus, PCI_DEVFN(device, function), PCI_VENDOR_ID, &ID); | ||
442 | if (ID == 0xFFFFFFFF) { /* nothing there. */ | ||
443 | function++; | ||
444 | } else { /* Something there */ | ||
445 | rc = pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(device, function), 0x0B, &class_code); | ||
446 | if (rc) | ||
447 | return rc; | ||
448 | 450 | ||
449 | rc = pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(device, function), PCI_HEADER_TYPE, &header_type); | 451 | stop_it = 0; |
450 | if (rc) | ||
451 | return rc; | ||
452 | 452 | ||
453 | stop_it++; | 453 | /* this loop skips to the next present function |
454 | } | 454 | * reading in Class Code and Header type. |
455 | */ | ||
456 | while ((function < max_functions) && (!stop_it)) { | ||
457 | rc = pci_bus_read_config_dword(ctrl->pci_bus, PCI_DEVFN(device, function), PCI_VENDOR_ID, &ID); | ||
458 | if (ID == 0xFFFFFFFF) { | ||
459 | function++; | ||
460 | continue; | ||
455 | } | 461 | } |
462 | rc = pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(device, function), 0x0B, &class_code); | ||
463 | if (rc) | ||
464 | return rc; | ||
456 | 465 | ||
457 | } while (function < max_functions); | 466 | rc = pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(device, function), PCI_HEADER_TYPE, &header_type); |
458 | } /* End of IF (device in slot?) */ | 467 | if (rc) |
459 | else if (is_hot_plug) { | 468 | return rc; |
460 | /* Setup slot structure with entry for empty slot */ | ||
461 | new_slot = cpqhp_slot_create(busnumber); | ||
462 | 469 | ||
463 | if (new_slot == NULL) { | 470 | stop_it++; |
464 | return(1); | ||
465 | } | 471 | } |
466 | 472 | ||
467 | new_slot->bus = (u8) busnumber; | 473 | } while (function < max_functions); |
468 | new_slot->device = (u8) device; | ||
469 | new_slot->function = 0; | ||
470 | new_slot->is_a_board = 0; | ||
471 | new_slot->presence_save = 0; | ||
472 | new_slot->switch_save = 0; | ||
473 | } | ||
474 | } /* End of FOR loop */ | 474 | } /* End of FOR loop */ |
475 | 475 | ||
476 | return(0); | 476 | return 0; |
477 | } | 477 | } |
478 | 478 | ||
479 | 479 | ||