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

pciehp: cleanup wait command completion

This patch cleans up the code to wait for command completion.

Signed-off-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
Signed-off-by: Kristen Carlson Accardi <kristen.c.accardi@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Kenji Kaneshige and committed by
Greg Kroah-Hartman
44ef4cef 75e13178

+82 -193
-18
drivers/pci/hotplug/pciehp.h
··· 173 173 return NULL; 174 174 } 175 175 176 - static inline int wait_for_ctrl_irq(struct controller *ctrl) 177 - { 178 - DECLARE_WAITQUEUE(wait, current); 179 - 180 - add_wait_queue(&ctrl->queue, &wait); 181 - if (!pciehp_poll_mode) 182 - /* Sleep for up to 1 second */ 183 - msleep_interruptible(1000); 184 - else 185 - msleep_interruptible(2500); 186 - 187 - remove_wait_queue(&ctrl->queue, &wait); 188 - if (signal_pending(current)) 189 - return -EINTR; 190 - 191 - return 0; 192 - } 193 - 194 176 struct hpc_ops { 195 177 int (*power_on_slot)(struct slot *slot); 196 178 int (*power_off_slot)(struct slot *slot);
+1 -13
drivers/pci/hotplug/pciehp_core.c
··· 374 374 pciehp_ctrl_list = ctrl; 375 375 } 376 376 377 - /* Wait for exclusive access to hardware */ 378 - mutex_lock(&ctrl->ctrl_lock); 379 - 380 377 t_slot->hpc_ops->get_adapter_status(t_slot, &value); /* Check if slot is occupied */ 381 - 382 378 if ((POWER_CTRL(ctrl->ctrlcap)) && !value) { 383 379 rc = t_slot->hpc_ops->power_off_slot(t_slot); /* Power off slot if not occupied*/ 384 - if (rc) { 385 - /* Done with exclusive hardware access */ 386 - mutex_unlock(&ctrl->ctrl_lock); 380 + if (rc) 387 381 goto err_out_free_ctrl_slot; 388 - } else 389 - /* Wait for the command to complete */ 390 - wait_for_ctrl_irq (ctrl); 391 382 } 392 - 393 - /* Done with exclusive hardware access */ 394 - mutex_unlock(&ctrl->ctrl_lock); 395 383 396 384 return 0; 397 385
+48 -157
drivers/pci/hotplug/pciehp_ctrl.c
··· 229 229 230 230 static void set_slot_off(struct controller *ctrl, struct slot * pslot) 231 231 { 232 - /* Wait for exclusive access to hardware */ 233 - mutex_lock(&ctrl->ctrl_lock); 234 - 235 232 /* turn off slot, turn on Amber LED, turn off Green LED if supported*/ 236 233 if (POWER_CTRL(ctrl->ctrlcap)) { 237 234 if (pslot->hpc_ops->power_off_slot(pslot)) { 238 - err("%s: Issue of Slot Power Off command failed\n", __FUNCTION__); 239 - mutex_unlock(&ctrl->ctrl_lock); 235 + err("%s: Issue of Slot Power Off command failed\n", 236 + __FUNCTION__); 240 237 return; 241 238 } 242 - wait_for_ctrl_irq (ctrl); 243 239 } 244 240 245 - if (PWR_LED(ctrl->ctrlcap)) { 241 + if (PWR_LED(ctrl->ctrlcap)) 246 242 pslot->hpc_ops->green_led_off(pslot); 247 - wait_for_ctrl_irq (ctrl); 248 - } 249 243 250 - if (ATTN_LED(ctrl->ctrlcap)) { 251 - if (pslot->hpc_ops->set_attention_status(pslot, 1)) { 252 - err("%s: Issue of Set Attention Led command failed\n", __FUNCTION__); 253 - mutex_unlock(&ctrl->ctrl_lock); 244 + if (ATTN_LED(ctrl->ctrlcap)) { 245 + if (pslot->hpc_ops->set_attention_status(pslot, 1)) { 246 + err("%s: Issue of Set Attention Led command failed\n", 247 + __FUNCTION__); 254 248 return; 255 249 } 256 - wait_for_ctrl_irq (ctrl); 257 250 } 258 - 259 - /* Done with exclusive hardware access */ 260 - mutex_unlock(&ctrl->ctrl_lock); 261 251 } 262 252 263 253 /** ··· 260 270 static int board_added(struct slot *p_slot) 261 271 { 262 272 u8 hp_slot; 263 - int rc = 0; 273 + int retval = 0; 264 274 struct controller *ctrl = p_slot->ctrl; 265 275 266 276 hp_slot = p_slot->device - ctrl->slot_device_offset; ··· 269 279 __FUNCTION__, p_slot->device, 270 280 ctrl->slot_device_offset, hp_slot); 271 281 272 - /* Wait for exclusive access to hardware */ 273 - mutex_lock(&ctrl->ctrl_lock); 274 - 275 282 if (POWER_CTRL(ctrl->ctrlcap)) { 276 283 /* Power on slot */ 277 - rc = p_slot->hpc_ops->power_on_slot(p_slot); 278 - if (rc) { 279 - mutex_unlock(&ctrl->ctrl_lock); 280 - return -1; 281 - } 282 - 283 - /* Wait for the command to complete */ 284 - wait_for_ctrl_irq (ctrl); 284 + retval = p_slot->hpc_ops->power_on_slot(p_slot); 285 + if (retval) 286 + return retval; 285 287 } 286 288 287 - if (PWR_LED(ctrl->ctrlcap)) { 289 + if (PWR_LED(ctrl->ctrlcap)) 288 290 p_slot->hpc_ops->green_led_blink(p_slot); 289 - 290 - /* Wait for the command to complete */ 291 - wait_for_ctrl_irq (ctrl); 292 - } 293 - 294 - /* Done with exclusive hardware access */ 295 - mutex_unlock(&ctrl->ctrl_lock); 296 291 297 292 /* Wait for ~1 second */ 298 - wait_for_ctrl_irq (ctrl); 293 + msleep(1000); 299 294 300 - /* Check link training status */ 301 - rc = p_slot->hpc_ops->check_lnk_status(ctrl); 302 - if (rc) { 295 + /* Check link training status */ 296 + retval = p_slot->hpc_ops->check_lnk_status(ctrl); 297 + if (retval) { 303 298 err("%s: Failed to check link status\n", __FUNCTION__); 304 299 set_slot_off(ctrl, p_slot); 305 - return rc; 300 + return retval; 306 301 } 307 302 308 303 /* Check for a power fault */ 309 304 if (p_slot->hpc_ops->query_power_fault(p_slot)) { 310 305 dbg("%s: power fault detected\n", __FUNCTION__); 311 - rc = POWER_FAILURE; 306 + retval = POWER_FAILURE; 312 307 goto err_exit; 313 308 } 314 309 315 - rc = pciehp_configure_device(p_slot); 316 - if (rc) { 310 + retval = pciehp_configure_device(p_slot); 311 + if (retval) { 317 312 err("Cannot add device 0x%x:%x\n", p_slot->bus, 318 - p_slot->device); 313 + p_slot->device); 319 314 goto err_exit; 320 315 } 321 316 ··· 309 334 */ 310 335 if (pcie_mch_quirk) 311 336 pci_fixup_device(pci_fixup_final, ctrl->pci_dev); 312 - if (PWR_LED(ctrl->ctrlcap)) { 313 - /* Wait for exclusive access to hardware */ 314 - mutex_lock(&ctrl->ctrl_lock); 315 - 337 + if (PWR_LED(ctrl->ctrlcap)) 316 338 p_slot->hpc_ops->green_led_on(p_slot); 317 - 318 - /* Wait for the command to complete */ 319 - wait_for_ctrl_irq (ctrl); 320 - 321 - /* Done with exclusive hardware access */ 322 - mutex_unlock(&ctrl->ctrl_lock); 323 - } 339 + 324 340 return 0; 325 341 326 342 err_exit: 327 343 set_slot_off(ctrl, p_slot); 328 - return -1; 344 + return retval; 329 345 } 330 - 331 346 332 347 /** 333 348 * remove_board - Turns off slot and LED's ··· 327 362 { 328 363 u8 device; 329 364 u8 hp_slot; 330 - int rc; 365 + int retval = 0; 331 366 struct controller *ctrl = p_slot->ctrl; 332 367 333 - if (pciehp_unconfigure_device(p_slot)) 334 - return 1; 368 + retval = pciehp_unconfigure_device(p_slot); 369 + if (retval) 370 + return retval; 335 371 336 372 device = p_slot->device; 337 - 338 373 hp_slot = p_slot->device - ctrl->slot_device_offset; 339 374 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 340 375 341 376 dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot); 342 377 343 - /* Wait for exclusive access to hardware */ 344 - mutex_lock(&ctrl->ctrl_lock); 345 - 346 378 if (POWER_CTRL(ctrl->ctrlcap)) { 347 379 /* power off slot */ 348 - rc = p_slot->hpc_ops->power_off_slot(p_slot); 349 - if (rc) { 350 - err("%s: Issue of Slot Disable command failed\n", __FUNCTION__); 351 - mutex_unlock(&ctrl->ctrl_lock); 352 - return rc; 380 + retval = p_slot->hpc_ops->power_off_slot(p_slot); 381 + if (retval) { 382 + err("%s: Issue of Slot Disable command failed\n", 383 + __FUNCTION__); 384 + return retval; 353 385 } 354 - /* Wait for the command to complete */ 355 - wait_for_ctrl_irq (ctrl); 356 386 } 357 387 358 - if (PWR_LED(ctrl->ctrlcap)) { 388 + if (PWR_LED(ctrl->ctrlcap)) 359 389 /* turn off Green LED */ 360 390 p_slot->hpc_ops->green_led_off(p_slot); 361 - 362 - /* Wait for the command to complete */ 363 - wait_for_ctrl_irq (ctrl); 364 - } 365 - 366 - /* Done with exclusive hardware access */ 367 - mutex_unlock(&ctrl->ctrl_lock); 368 391 369 392 return 0; 370 393 } ··· 397 444 dbg("%s: adding bus:device(%x:%x)\n", __FUNCTION__, 398 445 p_slot->bus, p_slot->device); 399 446 400 - if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) { 401 - /* Wait for exclusive access to hardware */ 402 - mutex_lock(&p_slot->ctrl->ctrl_lock); 403 - 447 + if (pciehp_enable_slot(p_slot) && 448 + PWR_LED(p_slot->ctrl->ctrlcap)) 404 449 p_slot->hpc_ops->green_led_off(p_slot); 405 450 406 - /* Wait for the command to complete */ 407 - wait_for_ctrl_irq (p_slot->ctrl); 408 - 409 - /* Done with exclusive hardware access */ 410 - mutex_unlock(&p_slot->ctrl->ctrl_lock); 411 - } 412 451 p_slot->state = STATIC_STATE; 413 452 } 414 453 ··· 439 494 dbg("%s: adding bus:device(%x:%x)\n", 440 495 __FUNCTION__, p_slot->bus, p_slot->device); 441 496 442 - if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) { 443 - /* Wait for exclusive access to hardware */ 444 - mutex_lock(&p_slot->ctrl->ctrl_lock); 445 - 497 + if (pciehp_enable_slot(p_slot) && 498 + PWR_LED(p_slot->ctrl->ctrlcap)) 446 499 p_slot->hpc_ops->green_led_off(p_slot); 447 500 448 - /* Wait for the command to complete */ 449 - wait_for_ctrl_irq (p_slot->ctrl); 450 - 451 - /* Done with exclusive hardware access */ 452 - mutex_unlock(&p_slot->ctrl->ctrl_lock); 453 - } 454 501 p_slot->state = STATIC_STATE; 455 502 } 456 503 ··· 553 616 554 617 switch (p_slot->state) { 555 618 case BLINKINGOFF_STATE: 556 - /* Wait for exclusive access to hardware */ 557 - mutex_lock(&ctrl->ctrl_lock); 558 - 559 - if (PWR_LED(ctrl->ctrlcap)) { 619 + if (PWR_LED(ctrl->ctrlcap)) 560 620 p_slot->hpc_ops->green_led_on(p_slot); 561 - /* Wait for the command to complete */ 562 - wait_for_ctrl_irq (ctrl); 563 - } 564 - if (ATTN_LED(ctrl->ctrlcap)) { 565 - p_slot->hpc_ops->set_attention_status(p_slot, 0); 566 621 567 - /* Wait for the command to complete */ 568 - wait_for_ctrl_irq (ctrl); 569 - } 570 - /* Done with exclusive hardware access */ 571 - mutex_unlock(&ctrl->ctrl_lock); 622 + if (ATTN_LED(ctrl->ctrlcap)) 623 + p_slot->hpc_ops->set_attention_status(p_slot, 0); 572 624 break; 573 625 case BLINKINGON_STATE: 574 - /* Wait for exclusive access to hardware */ 575 - mutex_lock(&ctrl->ctrl_lock); 576 - 577 - if (PWR_LED(ctrl->ctrlcap)) { 626 + if (PWR_LED(ctrl->ctrlcap)) 578 627 p_slot->hpc_ops->green_led_off(p_slot); 579 - /* Wait for the command to complete */ 580 - wait_for_ctrl_irq (ctrl); 581 - } 582 - if (ATTN_LED(ctrl->ctrlcap)){ 583 - p_slot->hpc_ops->set_attention_status(p_slot, 0); 584 - /* Wait for the command to complete */ 585 - wait_for_ctrl_irq (ctrl); 586 - } 587 - /* Done with exclusive hardware access */ 588 - mutex_unlock(&ctrl->ctrl_lock); 589 628 629 + if (ATTN_LED(ctrl->ctrlcap)) 630 + p_slot->hpc_ops->set_attention_status(p_slot, 0); 590 631 break; 591 632 default: 592 633 warn("Not a valid state\n"); ··· 591 676 info("PCI slot #%s - powering on due to button press.\n", slot_name(p_slot)); 592 677 } 593 678 594 - /* Wait for exclusive access to hardware */ 595 - mutex_lock(&ctrl->ctrl_lock); 596 - 597 679 /* blink green LED and turn off amber */ 598 - if (PWR_LED(ctrl->ctrlcap)) { 680 + if (PWR_LED(ctrl->ctrlcap)) 599 681 p_slot->hpc_ops->green_led_blink(p_slot); 600 - /* Wait for the command to complete */ 601 - wait_for_ctrl_irq (ctrl); 602 - } 603 682 604 - if (ATTN_LED(ctrl->ctrlcap)) { 683 + if (ATTN_LED(ctrl->ctrlcap)) 605 684 p_slot->hpc_ops->set_attention_status(p_slot, 0); 606 - 607 - /* Wait for the command to complete */ 608 - wait_for_ctrl_irq (ctrl); 609 - } 610 - 611 - /* Done with exclusive hardware access */ 612 - mutex_unlock(&ctrl->ctrl_lock); 613 685 614 686 init_timer(&p_slot->task_event); 615 687 p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */ ··· 610 708 else if (ctrl->event_queue[loop].event_type == INT_POWER_FAULT) { 611 709 if (POWER_CTRL(ctrl->ctrlcap)) { 612 710 dbg("power fault\n"); 613 - /* Wait for exclusive access to hardware */ 614 - mutex_lock(&ctrl->ctrl_lock); 615 - 616 - if (ATTN_LED(ctrl->ctrlcap)) { 711 + if (ATTN_LED(ctrl->ctrlcap)) 617 712 p_slot->hpc_ops->set_attention_status(p_slot, 1); 618 - wait_for_ctrl_irq (ctrl); 619 - } 620 713 621 - if (PWR_LED(ctrl->ctrlcap)) { 714 + if (PWR_LED(ctrl->ctrlcap)) 622 715 p_slot->hpc_ops->green_led_off(p_slot); 623 - wait_for_ctrl_irq (ctrl); 624 - } 625 - 626 - /* Done with exclusive hardware access */ 627 - mutex_unlock(&ctrl->ctrl_lock); 628 716 } 629 717 } 630 718 /***********SURPRISE REMOVAL********************/ ··· 641 749 } /* End of FOR loop */ 642 750 } 643 751 } 644 - 645 752 646 753 int pciehp_enable_slot(struct slot *p_slot) 647 754 {
+33 -5
drivers/pci/hotplug/pciehp_hpc.c
··· 249 249 add_timer(&ctrl->poll_timer); 250 250 } 251 251 252 + static inline int pcie_wait_cmd(struct controller *ctrl) 253 + { 254 + DECLARE_WAITQUEUE(wait, current); 255 + 256 + add_wait_queue(&ctrl->queue, &wait); 257 + if (!pciehp_poll_mode) 258 + /* Sleep for up to 1 second */ 259 + msleep_interruptible(1000); 260 + else 261 + msleep_interruptible(2500); 262 + 263 + remove_wait_queue(&ctrl->queue, &wait); 264 + if (signal_pending(current)) 265 + return -EINTR; 266 + 267 + return 0; 268 + } 269 + 252 270 static int pcie_write_cmd(struct slot *slot, u16 cmd) 253 271 { 254 272 struct controller *ctrl = slot->ctrl; ··· 275 257 276 258 DBG_ENTER_ROUTINE 277 259 260 + mutex_lock(&ctrl->ctrl_lock); 261 + 278 262 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 279 263 if (retval) { 280 264 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); 281 - return retval; 265 + goto out; 282 266 } 283 267 284 268 if ((slot_status & CMD_COMPLETED) == CMD_COMPLETED ) { 285 - /* After 1 sec and CMD_COMPLETED still not set, just proceed forward to issue 286 - the next command according to spec. Just print out the error message */ 287 - dbg("%s : CMD_COMPLETED not clear after 1 sec.\n", __FUNCTION__); 269 + /* After 1 sec and CMD_COMPLETED still not set, just 270 + proceed forward to issue the next command according 271 + to spec. Just print out the error message */ 272 + dbg("%s: CMD_COMPLETED not clear after 1 sec.\n", 273 + __FUNCTION__); 288 274 } 289 275 290 276 retval = pciehp_writew(ctrl, SLOTCTRL, (cmd | CMD_CMPL_INTR_ENABLE)); 291 277 if (retval) { 292 278 err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__); 293 - return retval; 279 + goto out; 294 280 } 295 281 282 + /* 283 + * Wait for command completion. 284 + */ 285 + retval = pcie_wait_cmd(ctrl); 286 + out: 287 + mutex_unlock(&ctrl->ctrl_lock); 296 288 DBG_LEAVE_ROUTINE 297 289 return retval; 298 290 }