Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] shpchp - cleanup check command status

This patch cleanups codes that check the command status. For this, it
introduces a new semaphore "cmd_sem" for each controller.

Signed-off-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Kenji Kaneshige and committed by
Greg Kroah-Hartman
d29aadda a4534560

+23 -123
+1
drivers/pci/hotplug/shpchp.h
··· 80 80 struct controller { 81 81 struct list_head ctrl_list; 82 82 struct mutex crit_sect; /* critical section mutex */ 83 + struct mutex cmd_lock; /* command lock */ 83 84 struct php_ctlr_state_s *hpc_ctlr_handle; /* HPC controller handle */ 84 85 int num_slots; /* Number of slots on ctlr */ 85 86 int slot_num_inc; /* 1 or -1 */
+1 -119
drivers/pci/hotplug/shpchp_ctrl.c
··· 242 242 int rc = 0; 243 243 244 244 dbg("%s: change to speed %d\n", __FUNCTION__, speed); 245 - mutex_lock(&ctrl->crit_sect); 246 245 if ((rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, speed))) { 247 246 err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__); 248 - mutex_unlock(&ctrl->crit_sect); 249 247 return WRONG_BUS_FREQUENCY; 250 248 } 251 - 252 - if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) { 253 - err("%s: Can't set bus speed/mode in the case of adapter & bus mismatch\n", 254 - __FUNCTION__); 255 - err("%s: Error code (%d)\n", __FUNCTION__, rc); 256 - mutex_unlock(&ctrl->crit_sect); 257 - return WRONG_BUS_FREQUENCY; 258 - } 259 - mutex_unlock(&ctrl->crit_sect); 260 249 return rc; 261 250 } 262 251 ··· 319 330 return -1; 320 331 } 321 332 322 - rc = p_slot->hpc_ops->check_cmd_status(ctrl); 323 - if (rc) { 324 - err("%s: Failed to power on slot, error code(%d)\n", __FUNCTION__, rc); 325 - /* Done with exclusive hardware access */ 326 - mutex_unlock(&ctrl->crit_sect); 327 - return -1; 328 - } 329 - 330 - 331 333 if ((ctrl->pci_dev->vendor == 0x8086) && (ctrl->pci_dev->device == 0x0332)) { 332 334 if (slots_not_empty) 333 335 return WRONG_BUS_FREQUENCY; ··· 329 349 return WRONG_BUS_FREQUENCY; 330 350 } 331 351 332 - if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) { 333 - err("%s: Can't set bus speed/mode in the case of adapter & bus mismatch\n", 334 - __FUNCTION__); 335 - err("%s: Error code (%d)\n", __FUNCTION__, rc); 336 - mutex_unlock(&ctrl->crit_sect); 337 - return WRONG_BUS_FREQUENCY; 338 - } 339 352 /* turn on board, blink green LED, turn off Amber LED */ 340 353 if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) { 341 354 err("%s: Issue of Slot Enable command failed\n", __FUNCTION__); 342 355 mutex_unlock(&ctrl->crit_sect); 343 356 return rc; 344 - } 345 - 346 - if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) { 347 - err("%s: Failed to enable slot, error code(%d)\n", __FUNCTION__, rc); 348 - mutex_unlock(&ctrl->crit_sect); 349 - return rc; 350 357 } 351 358 } 352 359 ··· 448 481 return rc; 449 482 } 450 483 451 - mutex_lock(&ctrl->crit_sect); 452 484 /* turn on board, blink green LED, turn off Amber LED */ 453 485 if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) { 454 486 err("%s: Issue of Slot Enable command failed\n", __FUNCTION__); 455 - mutex_unlock(&ctrl->crit_sect); 456 487 return rc; 457 488 } 458 - 459 - if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) { 460 - err("%s: Failed to enable slot, error code(%d)\n", __FUNCTION__, rc); 461 - mutex_unlock(&ctrl->crit_sect); 462 - return rc; 463 - } 464 - 465 - mutex_unlock(&ctrl->crit_sect); 466 489 467 490 /* Wait for ~1 second */ 468 491 wait_for_ctrl_irq (ctrl); ··· 477 520 p_slot->is_a_board = 0x01; 478 521 p_slot->pwr_save = 1; 479 522 480 - /* Wait for exclusive access to hardware */ 481 - mutex_lock(&ctrl->crit_sect); 482 - 483 523 p_slot->hpc_ops->green_led_on(p_slot); 484 - 485 - /* Done with exclusive hardware access */ 486 - mutex_unlock(&ctrl->crit_sect); 487 524 488 525 return 0; 489 526 490 527 err_exit: 491 - /* Wait for exclusive access to hardware */ 492 - mutex_lock(&ctrl->crit_sect); 493 - 494 528 /* turn off slot, turn on Amber LED, turn off Green LED */ 495 529 rc = p_slot->hpc_ops->slot_disable(p_slot); 496 530 if (rc) { 497 531 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__); 498 - /* Done with exclusive hardware access */ 499 - mutex_unlock(&ctrl->crit_sect); 500 532 return rc; 501 533 } 502 - 503 - rc = p_slot->hpc_ops->check_cmd_status(ctrl); 504 - if (rc) { 505 - err("%s: Failed to disable slot, error code(%d)\n", __FUNCTION__, rc); 506 - /* Done with exclusive hardware access */ 507 - mutex_unlock(&ctrl->crit_sect); 508 - return rc; 509 - } 510 - 511 - /* Done with exclusive hardware access */ 512 - mutex_unlock(&ctrl->crit_sect); 513 534 514 535 return(rc); 515 536 } ··· 515 580 if (p_slot->is_a_board) 516 581 p_slot->status = 0x01; 517 582 518 - /* Wait for exclusive access to hardware */ 519 - mutex_lock(&ctrl->crit_sect); 520 - 521 583 /* turn off slot, turn on Amber LED, turn off Green LED */ 522 584 rc = p_slot->hpc_ops->slot_disable(p_slot); 523 585 if (rc) { 524 586 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__); 525 - /* Done with exclusive hardware access */ 526 - mutex_unlock(&ctrl->crit_sect); 527 587 return rc; 528 - } 529 - 530 - rc = p_slot->hpc_ops->check_cmd_status(ctrl); 531 - if (rc) { 532 - err("%s: Failed to disable slot, error code(%d)\n", __FUNCTION__, rc); 533 - /* Done with exclusive hardware access */ 534 - mutex_unlock(&ctrl->crit_sect); 535 - return rc; 536 588 } 537 589 538 590 rc = p_slot->hpc_ops->set_attention_status(p_slot, 0); 539 591 if (rc) { 540 592 err("%s: Issue of Set Attention command failed\n", __FUNCTION__); 541 - /* Done with exclusive hardware access */ 542 - mutex_unlock(&ctrl->crit_sect); 543 593 return rc; 544 594 } 545 - 546 - /* Done with exclusive hardware access */ 547 - mutex_unlock(&ctrl->crit_sect); 548 595 549 596 p_slot->pwr_save = 0; 550 597 p_slot->is_a_board = 0; ··· 571 654 } else { 572 655 p_slot->state = POWERON_STATE; 573 656 574 - if (shpchp_enable_slot(p_slot)) { 575 - /* Wait for exclusive access to hardware */ 576 - mutex_lock(&p_slot->ctrl->crit_sect); 577 - 657 + if (shpchp_enable_slot(p_slot)) 578 658 p_slot->hpc_ops->green_led_off(p_slot); 579 659 580 - /* Done with exclusive hardware access */ 581 - mutex_unlock(&p_slot->ctrl->crit_sect); 582 - } 583 660 p_slot->state = STATIC_STATE; 584 661 } 585 662 ··· 678 767 679 768 switch (p_slot->state) { 680 769 case BLINKINGOFF_STATE: 681 - /* Wait for exclusive access to hardware */ 682 - mutex_lock(&ctrl->crit_sect); 683 - 684 770 p_slot->hpc_ops->green_led_on(p_slot); 685 - 686 771 p_slot->hpc_ops->set_attention_status(p_slot, 0); 687 - 688 - /* Done with exclusive hardware access */ 689 - mutex_unlock(&ctrl->crit_sect); 690 772 break; 691 773 case BLINKINGON_STATE: 692 - /* Wait for exclusive access to hardware */ 693 - mutex_lock(&ctrl->crit_sect); 694 - 695 774 p_slot->hpc_ops->green_led_off(p_slot); 696 - 697 775 p_slot->hpc_ops->set_attention_status(p_slot, 0); 698 - 699 - /* Done with exclusive hardware access */ 700 - mutex_unlock(&ctrl->crit_sect); 701 - 702 776 break; 703 777 default: 704 778 warn("Not a valid state\n"); ··· 708 812 info(msg_button_on, p_slot->number); 709 813 } 710 814 711 - /* Wait for exclusive access to hardware */ 712 - mutex_lock(&ctrl->crit_sect); 713 - 714 815 /* blink green LED and turn off amber */ 715 816 p_slot->hpc_ops->green_led_blink(p_slot); 716 - 717 817 p_slot->hpc_ops->set_attention_status(p_slot, 0); 718 - 719 - /* Done with exclusive hardware access */ 720 - mutex_unlock(&ctrl->crit_sect); 721 818 722 819 init_timer(&p_slot->task_event); 723 820 p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */ ··· 722 833 } else if (ctrl->event_queue[loop].event_type == INT_POWER_FAULT) { 723 834 /***********POWER FAULT********************/ 724 835 dbg("%s: power fault\n", __FUNCTION__); 725 - /* Wait for exclusive access to hardware */ 726 - mutex_lock(&ctrl->crit_sect); 727 - 728 836 p_slot->hpc_ops->set_attention_status(p_slot, 1); 729 - 730 837 p_slot->hpc_ops->green_led_off(p_slot); 731 - 732 - /* Done with exclusive hardware access */ 733 - mutex_unlock(&ctrl->crit_sect); 734 838 } else { 735 839 /* refresh notification */ 736 840 if (p_slot)
+21 -4
drivers/pci/hotplug/shpchp_hpc.c
··· 231 231 static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs); 232 232 233 233 static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds); 234 + static int hpc_check_cmd_status(struct controller *ctrl); 234 235 235 236 /* This is the interrupt polling timeout function. */ 236 237 static void int_poll_timeout(unsigned long lphp_ctlr) ··· 304 303 int i; 305 304 306 305 DBG_ENTER_ROUTINE 307 - 306 + 307 + mutex_lock(&slot->ctrl->cmd_lock); 308 + 308 309 if (!php_ctlr) { 309 310 err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 310 - return -1; 311 + retval = -EINVAL; 312 + goto out; 311 313 } 312 314 313 315 for (i = 0; i < 10; i++) { ··· 327 323 if (cmd_status & 0x1) { 328 324 /* After 1 sec and and the controller is still busy */ 329 325 err("%s : Controller is still busy after 1 sec.\n", __FUNCTION__); 330 - return -1; 326 + retval = -EBUSY; 327 + goto out; 331 328 } 332 329 333 330 ++t_slot; ··· 345 340 * Wait for command completion. 346 341 */ 347 342 retval = shpc_wait_cmd(slot->ctrl); 343 + if (retval) 344 + goto out; 345 + 346 + cmd_status = hpc_check_cmd_status(slot->ctrl); 347 + if (cmd_status) { 348 + err("%s: Failed to issued command 0x%x (error code = %d)\n", 349 + __FUNCTION__, cmd, cmd_status); 350 + retval = -EIO; 351 + } 352 + out: 353 + mutex_unlock(&slot->ctrl->cmd_lock); 348 354 349 355 DBG_LEAVE_ROUTINE 350 356 return retval; ··· 1359 1343 .green_led_blink = hpc_set_green_led_blink, 1360 1344 1361 1345 .release_ctlr = hpc_release_ctlr, 1362 - .check_cmd_status = hpc_check_cmd_status, 1363 1346 }; 1364 1347 1365 1348 inline static int shpc_indirect_creg_read(struct controller *ctrl, int index, ··· 1470 1455 dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg); 1471 1456 1472 1457 mutex_init(&ctrl->crit_sect); 1458 + mutex_init(&ctrl->cmd_lock); 1459 + 1473 1460 /* Setup wait queue */ 1474 1461 init_waitqueue_head(&ctrl->queue); 1475 1462