aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/hotplug/pciehp_hpc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci/hotplug/pciehp_hpc.c')
-rw-r--r--drivers/pci/hotplug/pciehp_hpc.c203
1 files changed, 54 insertions, 149 deletions
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index 016eea94a8a5..06d025b8b13f 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -39,37 +39,6 @@
39 39
40#include "../pci.h" 40#include "../pci.h"
41#include "pciehp.h" 41#include "pciehp.h"
42#ifdef DEBUG
43#define DBG_K_TRACE_ENTRY ((unsigned int)0x00000001) /* On function entry */
44#define DBG_K_TRACE_EXIT ((unsigned int)0x00000002) /* On function exit */
45#define DBG_K_INFO ((unsigned int)0x00000004) /* Info messages */
46#define DBG_K_ERROR ((unsigned int)0x00000008) /* Error messages */
47#define DBG_K_TRACE (DBG_K_TRACE_ENTRY|DBG_K_TRACE_EXIT)
48#define DBG_K_STANDARD (DBG_K_INFO|DBG_K_ERROR|DBG_K_TRACE)
49/* Redefine this flagword to set debug level */
50#define DEBUG_LEVEL DBG_K_STANDARD
51
52#define DEFINE_DBG_BUFFER char __dbg_str_buf[256];
53
54#define DBG_PRINT( dbg_flags, args... ) \
55 do { \
56 if ( DEBUG_LEVEL & ( dbg_flags ) ) \
57 { \
58 int len; \
59 len = sprintf( __dbg_str_buf, "%s:%d: %s: ", \
60 __FILE__, __LINE__, __FUNCTION__ ); \
61 sprintf( __dbg_str_buf + len, args ); \
62 printk( KERN_NOTICE "%s\n", __dbg_str_buf ); \
63 } \
64 } while (0)
65
66#define DBG_ENTER_ROUTINE DBG_PRINT (DBG_K_TRACE_ENTRY, "%s", "[Entry]");
67#define DBG_LEAVE_ROUTINE DBG_PRINT (DBG_K_TRACE_EXIT, "%s", "[Exit]");
68#else
69#define DEFINE_DBG_BUFFER
70#define DBG_ENTER_ROUTINE
71#define DBG_LEAVE_ROUTINE
72#endif /* DEBUG */
73 42
74static atomic_t pciehp_num_controllers = ATOMIC_INIT(0); 43static atomic_t pciehp_num_controllers = ATOMIC_INIT(0);
75 44
@@ -160,10 +129,10 @@ static inline int pciehp_writel(struct controller *ctrl, int reg, u32 value)
160/* Link Width Encoding */ 129/* Link Width Encoding */
161#define LNK_X1 0x01 130#define LNK_X1 0x01
162#define LNK_X2 0x02 131#define LNK_X2 0x02
163#define LNK_X4 0x04 132#define LNK_X4 0x04
164#define LNK_X8 0x08 133#define LNK_X8 0x08
165#define LNK_X12 0x0C 134#define LNK_X12 0x0C
166#define LNK_X16 0x10 135#define LNK_X16 0x10
167#define LNK_X32 0x20 136#define LNK_X32 0x20
168 137
169/*Field definitions of Link Status Register */ 138/*Field definitions of Link Status Register */
@@ -221,8 +190,6 @@ static inline int pciehp_writel(struct controller *ctrl, int reg, u32 value)
221#define EMI_STATE 0x0080 190#define EMI_STATE 0x0080
222#define EMI_STATUS_BIT 7 191#define EMI_STATUS_BIT 7
223 192
224DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */
225
226static irqreturn_t pcie_isr(int irq, void *dev_id); 193static irqreturn_t pcie_isr(int irq, void *dev_id);
227static void start_int_poll_timer(struct controller *ctrl, int sec); 194static void start_int_poll_timer(struct controller *ctrl, int sec);
228 195
@@ -231,14 +198,12 @@ static void int_poll_timeout(unsigned long data)
231{ 198{
232 struct controller *ctrl = (struct controller *)data; 199 struct controller *ctrl = (struct controller *)data;
233 200
234 DBG_ENTER_ROUTINE
235
236 /* Poll for interrupt events. regs == NULL => polling */ 201 /* Poll for interrupt events. regs == NULL => polling */
237 pcie_isr(0, ctrl); 202 pcie_isr(0, ctrl);
238 203
239 init_timer(&ctrl->poll_timer); 204 init_timer(&ctrl->poll_timer);
240 if (!pciehp_poll_time) 205 if (!pciehp_poll_time)
241 pciehp_poll_time = 2; /* reset timer to poll in 2 secs if user doesn't specify at module installation*/ 206 pciehp_poll_time = 2; /* default polling interval is 2 sec */
242 207
243 start_int_poll_timer(ctrl, pciehp_poll_time); 208 start_int_poll_timer(ctrl, pciehp_poll_time);
244} 209}
@@ -289,8 +254,6 @@ static int pcie_write_cmd(struct slot *slot, u16 cmd, u16 mask)
289 u16 slot_ctrl; 254 u16 slot_ctrl;
290 unsigned long flags; 255 unsigned long flags;
291 256
292 DBG_ENTER_ROUTINE
293
294 mutex_lock(&ctrl->ctrl_lock); 257 mutex_lock(&ctrl->ctrl_lock);
295 258
296 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 259 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
@@ -299,7 +262,7 @@ static int pcie_write_cmd(struct slot *slot, u16 cmd, u16 mask)
299 goto out; 262 goto out;
300 } 263 }
301 264
302 if ((slot_status & CMD_COMPLETED) == CMD_COMPLETED ) { 265 if ((slot_status & CMD_COMPLETED) == CMD_COMPLETED ) {
303 /* After 1 sec and CMD_COMPLETED still not set, just 266 /* After 1 sec and CMD_COMPLETED still not set, just
304 proceed forward to issue the next command according 267 proceed forward to issue the next command according
305 to spec. Just print out the error message */ 268 to spec. Just print out the error message */
@@ -332,7 +295,6 @@ static int pcie_write_cmd(struct slot *slot, u16 cmd, u16 mask)
332 retval = pcie_wait_cmd(ctrl); 295 retval = pcie_wait_cmd(ctrl);
333 out: 296 out:
334 mutex_unlock(&ctrl->ctrl_lock); 297 mutex_unlock(&ctrl->ctrl_lock);
335 DBG_LEAVE_ROUTINE
336 return retval; 298 return retval;
337} 299}
338 300
@@ -341,8 +303,6 @@ static int hpc_check_lnk_status(struct controller *ctrl)
341 u16 lnk_status; 303 u16 lnk_status;
342 int retval = 0; 304 int retval = 0;
343 305
344 DBG_ENTER_ROUTINE
345
346 retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status); 306 retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status);
347 if (retval) { 307 if (retval) {
348 err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__); 308 err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__);
@@ -350,26 +310,22 @@ static int hpc_check_lnk_status(struct controller *ctrl)
350 } 310 }
351 311
352 dbg("%s: lnk_status = %x\n", __FUNCTION__, lnk_status); 312 dbg("%s: lnk_status = %x\n", __FUNCTION__, lnk_status);
353 if ( (lnk_status & LNK_TRN) || (lnk_status & LNK_TRN_ERR) || 313 if ( (lnk_status & LNK_TRN) || (lnk_status & LNK_TRN_ERR) ||
354 !(lnk_status & NEG_LINK_WD)) { 314 !(lnk_status & NEG_LINK_WD)) {
355 err("%s : Link Training Error occurs \n", __FUNCTION__); 315 err("%s : Link Training Error occurs \n", __FUNCTION__);
356 retval = -1; 316 retval = -1;
357 return retval; 317 return retval;
358 } 318 }
359 319
360 DBG_LEAVE_ROUTINE
361 return retval; 320 return retval;
362} 321}
363 322
364
365static int hpc_get_attention_status(struct slot *slot, u8 *status) 323static int hpc_get_attention_status(struct slot *slot, u8 *status)
366{ 324{
367 struct controller *ctrl = slot->ctrl; 325 struct controller *ctrl = slot->ctrl;
368 u16 slot_ctrl; 326 u16 slot_ctrl;
369 u8 atten_led_state; 327 u8 atten_led_state;
370 int retval = 0; 328 int retval = 0;
371
372 DBG_ENTER_ROUTINE
373 329
374 retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); 330 retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
375 if (retval) { 331 if (retval) {
@@ -400,7 +356,6 @@ static int hpc_get_attention_status(struct slot *slot, u8 *status)
400 break; 356 break;
401 } 357 }
402 358
403 DBG_LEAVE_ROUTINE
404 return 0; 359 return 0;
405} 360}
406 361
@@ -410,8 +365,6 @@ static int hpc_get_power_status(struct slot *slot, u8 *status)
410 u16 slot_ctrl; 365 u16 slot_ctrl;
411 u8 pwr_state; 366 u8 pwr_state;
412 int retval = 0; 367 int retval = 0;
413
414 DBG_ENTER_ROUTINE
415 368
416 retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); 369 retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
417 if (retval) { 370 if (retval) {
@@ -428,35 +381,30 @@ static int hpc_get_power_status(struct slot *slot, u8 *status)
428 *status = 1; 381 *status = 1;
429 break; 382 break;
430 case 1: 383 case 1:
431 *status = 0; 384 *status = 0;
432 break; 385 break;
433 default: 386 default:
434 *status = 0xFF; 387 *status = 0xFF;
435 break; 388 break;
436 } 389 }
437 390
438 DBG_LEAVE_ROUTINE
439 return retval; 391 return retval;
440} 392}
441 393
442
443static int hpc_get_latch_status(struct slot *slot, u8 *status) 394static int hpc_get_latch_status(struct slot *slot, u8 *status)
444{ 395{
445 struct controller *ctrl = slot->ctrl; 396 struct controller *ctrl = slot->ctrl;
446 u16 slot_status; 397 u16 slot_status;
447 int retval = 0; 398 int retval = 0;
448 399
449 DBG_ENTER_ROUTINE
450
451 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 400 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
452 if (retval) { 401 if (retval) {
453 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); 402 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
454 return retval; 403 return retval;
455 } 404 }
456 405
457 *status = (((slot_status & MRL_STATE) >> 5) == 0) ? 0 : 1; 406 *status = (((slot_status & MRL_STATE) >> 5) == 0) ? 0 : 1;
458 407
459 DBG_LEAVE_ROUTINE
460 return 0; 408 return 0;
461} 409}
462 410
@@ -467,8 +415,6 @@ static int hpc_get_adapter_status(struct slot *slot, u8 *status)
467 u8 card_state; 415 u8 card_state;
468 int retval = 0; 416 int retval = 0;
469 417
470 DBG_ENTER_ROUTINE
471
472 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 418 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
473 if (retval) { 419 if (retval) {
474 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); 420 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
@@ -477,7 +423,6 @@ static int hpc_get_adapter_status(struct slot *slot, u8 *status)
477 card_state = (u8)((slot_status & PRSN_STATE) >> 6); 423 card_state = (u8)((slot_status & PRSN_STATE) >> 6);
478 *status = (card_state == 1) ? 1 : 0; 424 *status = (card_state == 1) ? 1 : 0;
479 425
480 DBG_LEAVE_ROUTINE
481 return 0; 426 return 0;
482} 427}
483 428
@@ -488,16 +433,13 @@ static int hpc_query_power_fault(struct slot *slot)
488 u8 pwr_fault; 433 u8 pwr_fault;
489 int retval = 0; 434 int retval = 0;
490 435
491 DBG_ENTER_ROUTINE
492
493 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 436 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
494 if (retval) { 437 if (retval) {
495 err("%s: Cannot check for power fault\n", __FUNCTION__); 438 err("%s: Cannot check for power fault\n", __FUNCTION__);
496 return retval; 439 return retval;
497 } 440 }
498 pwr_fault = (u8)((slot_status & PWR_FAULT_DETECTED) >> 1); 441 pwr_fault = (u8)((slot_status & PWR_FAULT_DETECTED) >> 1);
499 442
500 DBG_LEAVE_ROUTINE
501 return pwr_fault; 443 return pwr_fault;
502} 444}
503 445
@@ -507,8 +449,6 @@ static int hpc_get_emi_status(struct slot *slot, u8 *status)
507 u16 slot_status; 449 u16 slot_status;
508 int retval = 0; 450 int retval = 0;
509 451
510 DBG_ENTER_ROUTINE
511
512 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 452 retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
513 if (retval) { 453 if (retval) {
514 err("%s : Cannot check EMI status\n", __FUNCTION__); 454 err("%s : Cannot check EMI status\n", __FUNCTION__);
@@ -516,7 +456,6 @@ static int hpc_get_emi_status(struct slot *slot, u8 *status)
516 } 456 }
517 *status = (slot_status & EMI_STATE) >> EMI_STATUS_BIT; 457 *status = (slot_status & EMI_STATE) >> EMI_STATUS_BIT;
518 458
519 DBG_LEAVE_ROUTINE
520 return retval; 459 return retval;
521} 460}
522 461
@@ -526,8 +465,6 @@ static int hpc_toggle_emi(struct slot *slot)
526 u16 cmd_mask; 465 u16 cmd_mask;
527 int rc; 466 int rc;
528 467
529 DBG_ENTER_ROUTINE
530
531 slot_cmd = EMI_CTRL; 468 slot_cmd = EMI_CTRL;
532 cmd_mask = EMI_CTRL; 469 cmd_mask = EMI_CTRL;
533 if (!pciehp_poll_mode) { 470 if (!pciehp_poll_mode) {
@@ -537,7 +474,7 @@ static int hpc_toggle_emi(struct slot *slot)
537 474
538 rc = pcie_write_cmd(slot, slot_cmd, cmd_mask); 475 rc = pcie_write_cmd(slot, slot_cmd, cmd_mask);
539 slot->last_emi_toggle = get_seconds(); 476 slot->last_emi_toggle = get_seconds();
540 DBG_LEAVE_ROUTINE 477
541 return rc; 478 return rc;
542} 479}
543 480
@@ -548,8 +485,6 @@ static int hpc_set_attention_status(struct slot *slot, u8 value)
548 u16 cmd_mask; 485 u16 cmd_mask;
549 int rc; 486 int rc;
550 487
551 DBG_ENTER_ROUTINE
552
553 cmd_mask = ATTN_LED_CTRL; 488 cmd_mask = ATTN_LED_CTRL;
554 switch (value) { 489 switch (value) {
555 case 0 : /* turn off */ 490 case 0 : /* turn off */
@@ -572,19 +507,15 @@ static int hpc_set_attention_status(struct slot *slot, u8 value)
572 rc = pcie_write_cmd(slot, slot_cmd, cmd_mask); 507 rc = pcie_write_cmd(slot, slot_cmd, cmd_mask);
573 dbg("%s: SLOTCTRL %x write cmd %x\n", 508 dbg("%s: SLOTCTRL %x write cmd %x\n",
574 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); 509 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
575 510
576 DBG_LEAVE_ROUTINE
577 return rc; 511 return rc;
578} 512}
579 513
580
581static void hpc_set_green_led_on(struct slot *slot) 514static void hpc_set_green_led_on(struct slot *slot)
582{ 515{
583 struct controller *ctrl = slot->ctrl; 516 struct controller *ctrl = slot->ctrl;
584 u16 slot_cmd; 517 u16 slot_cmd;
585 u16 cmd_mask; 518 u16 cmd_mask;
586
587 DBG_ENTER_ROUTINE
588 519
589 slot_cmd = 0x0100; 520 slot_cmd = 0x0100;
590 cmd_mask = PWR_LED_CTRL; 521 cmd_mask = PWR_LED_CTRL;
@@ -597,8 +528,6 @@ static void hpc_set_green_led_on(struct slot *slot)
597 528
598 dbg("%s: SLOTCTRL %x write cmd %x\n", 529 dbg("%s: SLOTCTRL %x write cmd %x\n",
599 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); 530 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
600 DBG_LEAVE_ROUTINE
601 return;
602} 531}
603 532
604static void hpc_set_green_led_off(struct slot *slot) 533static void hpc_set_green_led_off(struct slot *slot)
@@ -607,8 +536,6 @@ static void hpc_set_green_led_off(struct slot *slot)
607 u16 slot_cmd; 536 u16 slot_cmd;
608 u16 cmd_mask; 537 u16 cmd_mask;
609 538
610 DBG_ENTER_ROUTINE
611
612 slot_cmd = 0x0300; 539 slot_cmd = 0x0300;
613 cmd_mask = PWR_LED_CTRL; 540 cmd_mask = PWR_LED_CTRL;
614 if (!pciehp_poll_mode) { 541 if (!pciehp_poll_mode) {
@@ -619,9 +546,6 @@ static void hpc_set_green_led_off(struct slot *slot)
619 pcie_write_cmd(slot, slot_cmd, cmd_mask); 546 pcie_write_cmd(slot, slot_cmd, cmd_mask);
620 dbg("%s: SLOTCTRL %x write cmd %x\n", 547 dbg("%s: SLOTCTRL %x write cmd %x\n",
621 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); 548 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
622
623 DBG_LEAVE_ROUTINE
624 return;
625} 549}
626 550
627static void hpc_set_green_led_blink(struct slot *slot) 551static void hpc_set_green_led_blink(struct slot *slot)
@@ -629,8 +553,6 @@ static void hpc_set_green_led_blink(struct slot *slot)
629 struct controller *ctrl = slot->ctrl; 553 struct controller *ctrl = slot->ctrl;
630 u16 slot_cmd; 554 u16 slot_cmd;
631 u16 cmd_mask; 555 u16 cmd_mask;
632
633 DBG_ENTER_ROUTINE
634 556
635 slot_cmd = 0x0200; 557 slot_cmd = 0x0200;
636 cmd_mask = PWR_LED_CTRL; 558 cmd_mask = PWR_LED_CTRL;
@@ -643,14 +565,10 @@ static void hpc_set_green_led_blink(struct slot *slot)
643 565
644 dbg("%s: SLOTCTRL %x write cmd %x\n", 566 dbg("%s: SLOTCTRL %x write cmd %x\n",
645 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); 567 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
646 DBG_LEAVE_ROUTINE
647 return;
648} 568}
649 569
650static void hpc_release_ctlr(struct controller *ctrl) 570static void hpc_release_ctlr(struct controller *ctrl)
651{ 571{
652 DBG_ENTER_ROUTINE
653
654 if (pciehp_poll_mode) 572 if (pciehp_poll_mode)
655 del_timer(&ctrl->poll_timer); 573 del_timer(&ctrl->poll_timer);
656 else 574 else
@@ -662,8 +580,6 @@ static void hpc_release_ctlr(struct controller *ctrl)
662 */ 580 */
663 if (atomic_dec_and_test(&pciehp_num_controllers)) 581 if (atomic_dec_and_test(&pciehp_num_controllers))
664 destroy_workqueue(pciehp_wq); 582 destroy_workqueue(pciehp_wq);
665
666 DBG_LEAVE_ROUTINE
667} 583}
668 584
669static int hpc_power_on_slot(struct slot * slot) 585static int hpc_power_on_slot(struct slot * slot)
@@ -674,8 +590,6 @@ static int hpc_power_on_slot(struct slot * slot)
674 u16 slot_status; 590 u16 slot_status;
675 int retval = 0; 591 int retval = 0;
676 592
677 DBG_ENTER_ROUTINE
678
679 dbg("%s: slot->hp_slot %x\n", __FUNCTION__, slot->hp_slot); 593 dbg("%s: slot->hp_slot %x\n", __FUNCTION__, slot->hp_slot);
680 594
681 /* Clear sticky power-fault bit from previous power failures */ 595 /* Clear sticky power-fault bit from previous power failures */
@@ -719,8 +633,6 @@ static int hpc_power_on_slot(struct slot * slot)
719 dbg("%s: SLOTCTRL %x write cmd %x\n", 633 dbg("%s: SLOTCTRL %x write cmd %x\n",
720 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); 634 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
721 635
722 DBG_LEAVE_ROUTINE
723
724 return retval; 636 return retval;
725} 637}
726 638
@@ -731,8 +643,6 @@ static int hpc_power_off_slot(struct slot * slot)
731 u16 cmd_mask; 643 u16 cmd_mask;
732 int retval = 0; 644 int retval = 0;
733 645
734 DBG_ENTER_ROUTINE
735
736 dbg("%s: slot->hp_slot %x\n", __FUNCTION__, slot->hp_slot); 646 dbg("%s: slot->hp_slot %x\n", __FUNCTION__, slot->hp_slot);
737 647
738 slot_cmd = POWER_OFF; 648 slot_cmd = POWER_OFF;
@@ -764,8 +674,6 @@ static int hpc_power_off_slot(struct slot * slot)
764 dbg("%s: SLOTCTRL %x write cmd %x\n", 674 dbg("%s: SLOTCTRL %x write cmd %x\n",
765 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); 675 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd);
766 676
767 DBG_LEAVE_ROUTINE
768
769 return retval; 677 return retval;
770} 678}
771 679
@@ -784,8 +692,8 @@ static irqreturn_t pcie_isr(int irq, void *dev_id)
784 return IRQ_NONE; 692 return IRQ_NONE;
785 } 693 }
786 694
787 intr_detect = ( ATTN_BUTTN_PRESSED | PWR_FAULT_DETECTED | MRL_SENS_CHANGED | 695 intr_detect = (ATTN_BUTTN_PRESSED | PWR_FAULT_DETECTED |
788 PRSN_DETECT_CHANGED | CMD_COMPLETED ); 696 MRL_SENS_CHANGED | PRSN_DETECT_CHANGED | CMD_COMPLETED);
789 697
790 intr_loc = slot_status & intr_detect; 698 intr_loc = slot_status & intr_detect;
791 699
@@ -807,7 +715,8 @@ static irqreturn_t pcie_isr(int irq, void *dev_id)
807 715
808 dbg("%s: pciehp_readw(SLOTCTRL) with value %x\n", 716 dbg("%s: pciehp_readw(SLOTCTRL) with value %x\n",
809 __FUNCTION__, temp_word); 717 __FUNCTION__, temp_word);
810 temp_word = (temp_word & ~HP_INTR_ENABLE & ~CMD_CMPL_INTR_ENABLE) | 0x00; 718 temp_word = (temp_word & ~HP_INTR_ENABLE &
719 ~CMD_CMPL_INTR_ENABLE) | 0x00;
811 rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); 720 rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
812 if (rc) { 721 if (rc) {
813 err("%s: Cannot write to SLOTCTRL register\n", 722 err("%s: Cannot write to SLOTCTRL register\n",
@@ -825,7 +734,7 @@ static irqreturn_t pcie_isr(int irq, void *dev_id)
825 } 734 }
826 dbg("%s: pciehp_readw(SLOTSTATUS) with value %x\n", 735 dbg("%s: pciehp_readw(SLOTSTATUS) with value %x\n",
827 __FUNCTION__, slot_status); 736 __FUNCTION__, slot_status);
828 737
829 /* Clear command complete interrupt caused by this write */ 738 /* Clear command complete interrupt caused by this write */
830 temp_word = 0x1f; 739 temp_word = 0x1f;
831 rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); 740 rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word);
@@ -835,10 +744,10 @@ static irqreturn_t pcie_isr(int irq, void *dev_id)
835 return IRQ_NONE; 744 return IRQ_NONE;
836 } 745 }
837 } 746 }
838 747
839 if (intr_loc & CMD_COMPLETED) { 748 if (intr_loc & CMD_COMPLETED) {
840 /* 749 /*
841 * Command Complete Interrupt Pending 750 * Command Complete Interrupt Pending
842 */ 751 */
843 ctrl->cmd_busy = 0; 752 ctrl->cmd_busy = 0;
844 wake_up_interruptible(&ctrl->queue); 753 wake_up_interruptible(&ctrl->queue);
@@ -892,7 +801,7 @@ static irqreturn_t pcie_isr(int irq, void *dev_id)
892 __FUNCTION__); 801 __FUNCTION__);
893 return IRQ_NONE; 802 return IRQ_NONE;
894 } 803 }
895 804
896 /* Clear command complete interrupt caused by this write */ 805 /* Clear command complete interrupt caused by this write */
897 temp_word = 0x1F; 806 temp_word = 0x1F;
898 rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); 807 rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word);
@@ -904,19 +813,17 @@ static irqreturn_t pcie_isr(int irq, void *dev_id)
904 dbg("%s: pciehp_writew(SLOTSTATUS) with value %x\n", 813 dbg("%s: pciehp_writew(SLOTSTATUS) with value %x\n",
905 __FUNCTION__, temp_word); 814 __FUNCTION__, temp_word);
906 } 815 }
907 816
908 return IRQ_HANDLED; 817 return IRQ_HANDLED;
909} 818}
910 819
911static int hpc_get_max_lnk_speed (struct slot *slot, enum pci_bus_speed *value) 820static int hpc_get_max_lnk_speed(struct slot *slot, enum pci_bus_speed *value)
912{ 821{
913 struct controller *ctrl = slot->ctrl; 822 struct controller *ctrl = slot->ctrl;
914 enum pcie_link_speed lnk_speed; 823 enum pcie_link_speed lnk_speed;
915 u32 lnk_cap; 824 u32 lnk_cap;
916 int retval = 0; 825 int retval = 0;
917 826
918 DBG_ENTER_ROUTINE
919
920 retval = pciehp_readl(ctrl, LNKCAP, &lnk_cap); 827 retval = pciehp_readl(ctrl, LNKCAP, &lnk_cap);
921 if (retval) { 828 if (retval) {
922 err("%s: Cannot read LNKCAP register\n", __FUNCTION__); 829 err("%s: Cannot read LNKCAP register\n", __FUNCTION__);
@@ -934,19 +841,18 @@ static int hpc_get_max_lnk_speed (struct slot *slot, enum pci_bus_speed *value)
934 841
935 *value = lnk_speed; 842 *value = lnk_speed;
936 dbg("Max link speed = %d\n", lnk_speed); 843 dbg("Max link speed = %d\n", lnk_speed);
937 DBG_LEAVE_ROUTINE 844
938 return retval; 845 return retval;
939} 846}
940 847
941static int hpc_get_max_lnk_width (struct slot *slot, enum pcie_link_width *value) 848static int hpc_get_max_lnk_width(struct slot *slot,
849 enum pcie_link_width *value)
942{ 850{
943 struct controller *ctrl = slot->ctrl; 851 struct controller *ctrl = slot->ctrl;
944 enum pcie_link_width lnk_wdth; 852 enum pcie_link_width lnk_wdth;
945 u32 lnk_cap; 853 u32 lnk_cap;
946 int retval = 0; 854 int retval = 0;
947 855
948 DBG_ENTER_ROUTINE
949
950 retval = pciehp_readl(ctrl, LNKCAP, &lnk_cap); 856 retval = pciehp_readl(ctrl, LNKCAP, &lnk_cap);
951 if (retval) { 857 if (retval) {
952 err("%s: Cannot read LNKCAP register\n", __FUNCTION__); 858 err("%s: Cannot read LNKCAP register\n", __FUNCTION__);
@@ -985,19 +891,17 @@ static int hpc_get_max_lnk_width (struct slot *slot, enum pcie_link_width *value
985 891
986 *value = lnk_wdth; 892 *value = lnk_wdth;
987 dbg("Max link width = %d\n", lnk_wdth); 893 dbg("Max link width = %d\n", lnk_wdth);
988 DBG_LEAVE_ROUTINE 894
989 return retval; 895 return retval;
990} 896}
991 897
992static int hpc_get_cur_lnk_speed (struct slot *slot, enum pci_bus_speed *value) 898static int hpc_get_cur_lnk_speed(struct slot *slot, enum pci_bus_speed *value)
993{ 899{
994 struct controller *ctrl = slot->ctrl; 900 struct controller *ctrl = slot->ctrl;
995 enum pcie_link_speed lnk_speed = PCI_SPEED_UNKNOWN; 901 enum pcie_link_speed lnk_speed = PCI_SPEED_UNKNOWN;
996 int retval = 0; 902 int retval = 0;
997 u16 lnk_status; 903 u16 lnk_status;
998 904
999 DBG_ENTER_ROUTINE
1000
1001 retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status); 905 retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status);
1002 if (retval) { 906 if (retval) {
1003 err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__); 907 err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__);
@@ -1015,25 +919,24 @@ static int hpc_get_cur_lnk_speed (struct slot *slot, enum pci_bus_speed *value)
1015 919
1016 *value = lnk_speed; 920 *value = lnk_speed;
1017 dbg("Current link speed = %d\n", lnk_speed); 921 dbg("Current link speed = %d\n", lnk_speed);
1018 DBG_LEAVE_ROUTINE 922
1019 return retval; 923 return retval;
1020} 924}
1021 925
1022static int hpc_get_cur_lnk_width (struct slot *slot, enum pcie_link_width *value) 926static int hpc_get_cur_lnk_width(struct slot *slot,
927 enum pcie_link_width *value)
1023{ 928{
1024 struct controller *ctrl = slot->ctrl; 929 struct controller *ctrl = slot->ctrl;
1025 enum pcie_link_width lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN; 930 enum pcie_link_width lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN;
1026 int retval = 0; 931 int retval = 0;
1027 u16 lnk_status; 932 u16 lnk_status;
1028 933
1029 DBG_ENTER_ROUTINE
1030
1031 retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status); 934 retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status);
1032 if (retval) { 935 if (retval) {
1033 err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__); 936 err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__);
1034 return retval; 937 return retval;
1035 } 938 }
1036 939
1037 switch ((lnk_status & 0x03F0) >> 4){ 940 switch ((lnk_status & 0x03F0) >> 4){
1038 case 0: 941 case 0:
1039 lnk_wdth = PCIE_LNK_WIDTH_RESRV; 942 lnk_wdth = PCIE_LNK_WIDTH_RESRV;
@@ -1066,7 +969,7 @@ static int hpc_get_cur_lnk_width (struct slot *slot, enum pcie_link_width *value
1066 969
1067 *value = lnk_wdth; 970 *value = lnk_wdth;
1068 dbg("Current link width = %d\n", lnk_wdth); 971 dbg("Current link width = %d\n", lnk_wdth);
1069 DBG_LEAVE_ROUTINE 972
1070 return retval; 973 return retval;
1071} 974}
1072 975
@@ -1085,12 +988,12 @@ static struct hpc_ops pciehp_hpc_ops = {
1085 .get_cur_bus_speed = hpc_get_cur_lnk_speed, 988 .get_cur_bus_speed = hpc_get_cur_lnk_speed,
1086 .get_max_lnk_width = hpc_get_max_lnk_width, 989 .get_max_lnk_width = hpc_get_max_lnk_width,
1087 .get_cur_lnk_width = hpc_get_cur_lnk_width, 990 .get_cur_lnk_width = hpc_get_cur_lnk_width,
1088 991
1089 .query_power_fault = hpc_query_power_fault, 992 .query_power_fault = hpc_query_power_fault,
1090 .green_led_on = hpc_set_green_led_on, 993 .green_led_on = hpc_set_green_led_on,
1091 .green_led_off = hpc_set_green_led_off, 994 .green_led_off = hpc_set_green_led_off,
1092 .green_led_blink = hpc_set_green_led_blink, 995 .green_led_blink = hpc_set_green_led_blink,
1093 996
1094 .release_ctlr = hpc_release_ctlr, 997 .release_ctlr = hpc_release_ctlr,
1095 .check_lnk_status = hpc_check_lnk_status, 998 .check_lnk_status = hpc_check_lnk_status,
1096}; 999};
@@ -1138,6 +1041,7 @@ int pciehp_acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev)
1138 dbg("Trying to get hotplug control for %s \n", 1041 dbg("Trying to get hotplug control for %s \n",
1139 (char *)string.pointer); 1042 (char *)string.pointer);
1140 status = pci_osc_control_set(handle, 1043 status = pci_osc_control_set(handle,
1044 OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL |
1141 OSC_PCI_EXPRESS_NATIVE_HP_CONTROL); 1045 OSC_PCI_EXPRESS_NATIVE_HP_CONTROL);
1142 if (status == AE_NOT_FOUND) 1046 if (status == AE_NOT_FOUND)
1143 status = acpi_run_oshp(handle); 1047 status = acpi_run_oshp(handle);
@@ -1163,8 +1067,6 @@ int pciehp_acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev)
1163} 1067}
1164#endif 1068#endif
1165 1069
1166
1167
1168int pcie_init(struct controller * ctrl, struct pcie_device *dev) 1070int pcie_init(struct controller * ctrl, struct pcie_device *dev)
1169{ 1071{
1170 int rc; 1072 int rc;
@@ -1176,8 +1078,6 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev)
1176 u16 slot_status, slot_ctrl; 1078 u16 slot_status, slot_ctrl;
1177 struct pci_dev *pdev; 1079 struct pci_dev *pdev;
1178 1080
1179 DBG_ENTER_ROUTINE
1180
1181 pdev = dev->port; 1081 pdev = dev->port;
1182 ctrl->pci_dev = pdev; /* save pci_dev in context */ 1082 ctrl->pci_dev = pdev; /* save pci_dev in context */
1183 1083
@@ -1201,9 +1101,11 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev)
1201 dbg("%s: CAPREG offset %x cap_reg %x\n", 1101 dbg("%s: CAPREG offset %x cap_reg %x\n",
1202 __FUNCTION__, ctrl->cap_base + CAPREG, cap_reg); 1102 __FUNCTION__, ctrl->cap_base + CAPREG, cap_reg);
1203 1103
1204 if (((cap_reg & SLOT_IMPL) == 0) || (((cap_reg & DEV_PORT_TYPE) != 0x0040) 1104 if (((cap_reg & SLOT_IMPL) == 0) ||
1105 (((cap_reg & DEV_PORT_TYPE) != 0x0040)
1205 && ((cap_reg & DEV_PORT_TYPE) != 0x0060))) { 1106 && ((cap_reg & DEV_PORT_TYPE) != 0x0060))) {
1206 dbg("%s : This is not a root port or the port is not connected to a slot\n", __FUNCTION__); 1107 dbg("%s : This is not a root port or the port is not "
1108 "connected to a slot\n", __FUNCTION__);
1207 goto abort_free_ctlr; 1109 goto abort_free_ctlr;
1208 } 1110 }
1209 1111
@@ -1236,14 +1138,15 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev)
1236 dbg("%s: SLOTCTRL offset %x slot_ctrl %x\n", 1138 dbg("%s: SLOTCTRL offset %x slot_ctrl %x\n",
1237 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_ctrl); 1139 __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_ctrl);
1238 1140
1239 for ( rc = 0; rc < DEVICE_COUNT_RESOURCE; rc++) 1141 for (rc = 0; rc < DEVICE_COUNT_RESOURCE; rc++)
1240 if (pci_resource_len(pdev, rc) > 0) 1142 if (pci_resource_len(pdev, rc) > 0)
1241 dbg("pci resource[%d] start=0x%llx(len=0x%llx)\n", rc, 1143 dbg("pci resource[%d] start=0x%llx(len=0x%llx)\n", rc,
1242 (unsigned long long)pci_resource_start(pdev, rc), 1144 (unsigned long long)pci_resource_start(pdev, rc),
1243 (unsigned long long)pci_resource_len(pdev, rc)); 1145 (unsigned long long)pci_resource_len(pdev, rc));
1244 1146
1245 info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, 1147 info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n",
1246 pdev->subsystem_vendor, pdev->subsystem_device); 1148 pdev->vendor, pdev->device,
1149 pdev->subsystem_vendor, pdev->subsystem_device);
1247 1150
1248 mutex_init(&ctrl->crit_sect); 1151 mutex_init(&ctrl->crit_sect);
1249 mutex_init(&ctrl->ctrl_lock); 1152 mutex_init(&ctrl->ctrl_lock);
@@ -1267,7 +1170,8 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev)
1267 1170
1268 dbg("%s: SLOTCTRL %x value read %x\n", 1171 dbg("%s: SLOTCTRL %x value read %x\n",
1269 __FUNCTION__, ctrl->cap_base + SLOTCTRL, temp_word); 1172 __FUNCTION__, ctrl->cap_base + SLOTCTRL, temp_word);
1270 temp_word = (temp_word & ~HP_INTR_ENABLE & ~CMD_CMPL_INTR_ENABLE) | 0x00; 1173 temp_word = (temp_word & ~HP_INTR_ENABLE & ~CMD_CMPL_INTR_ENABLE) |
1174 0x00;
1271 1175
1272 rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); 1176 rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
1273 if (rc) { 1177 if (rc) {
@@ -1330,14 +1234,14 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev)
1330 1234
1331 if (ATTN_BUTTN(slot_cap)) 1235 if (ATTN_BUTTN(slot_cap))
1332 intr_enable = intr_enable | ATTN_BUTTN_ENABLE; 1236 intr_enable = intr_enable | ATTN_BUTTN_ENABLE;
1333 1237
1334 if (POWER_CTRL(slot_cap)) 1238 if (POWER_CTRL(slot_cap))
1335 intr_enable = intr_enable | PWR_FAULT_DETECT_ENABLE; 1239 intr_enable = intr_enable | PWR_FAULT_DETECT_ENABLE;
1336 1240
1337 if (MRL_SENS(slot_cap)) 1241 if (MRL_SENS(slot_cap))
1338 intr_enable = intr_enable | MRL_DETECT_ENABLE; 1242 intr_enable = intr_enable | MRL_DETECT_ENABLE;
1339 1243
1340 temp_word = (temp_word & ~intr_enable) | intr_enable; 1244 temp_word = (temp_word & ~intr_enable) | intr_enable;
1341 1245
1342 if (pciehp_poll_mode) { 1246 if (pciehp_poll_mode) {
1343 temp_word = (temp_word & ~HP_INTR_ENABLE) | 0x0; 1247 temp_word = (temp_word & ~HP_INTR_ENABLE) | 0x0;
@@ -1345,7 +1249,10 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev)
1345 temp_word = (temp_word & ~HP_INTR_ENABLE) | HP_INTR_ENABLE; 1249 temp_word = (temp_word & ~HP_INTR_ENABLE) | HP_INTR_ENABLE;
1346 } 1250 }
1347 1251
1348 /* Unmask Hot-plug Interrupt Enable for the interrupt notification mechanism case */ 1252 /*
1253 * Unmask Hot-plug Interrupt Enable for the interrupt
1254 * notification mechanism case.
1255 */
1349 rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); 1256 rc = pciehp_writew(ctrl, SLOTCTRL, temp_word);
1350 if (rc) { 1257 if (rc) {
1351 err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__); 1258 err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__);
@@ -1356,14 +1263,14 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev)
1356 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); 1263 err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__);
1357 goto abort_disable_intr; 1264 goto abort_disable_intr;
1358 } 1265 }
1359 1266
1360 temp_word = 0x1F; /* Clear all events */ 1267 temp_word = 0x1F; /* Clear all events */
1361 rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); 1268 rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word);
1362 if (rc) { 1269 if (rc) {
1363 err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__); 1270 err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__);
1364 goto abort_disable_intr; 1271 goto abort_disable_intr;
1365 } 1272 }
1366 1273
1367 if (pciehp_force) { 1274 if (pciehp_force) {
1368 dbg("Bypassing BIOS check for pciehp use on %s\n", 1275 dbg("Bypassing BIOS check for pciehp use on %s\n",
1369 pci_name(ctrl->pci_dev)); 1276 pci_name(ctrl->pci_dev));
@@ -1375,10 +1282,9 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev)
1375 1282
1376 ctrl->hpc_ops = &pciehp_hpc_ops; 1283 ctrl->hpc_ops = &pciehp_hpc_ops;
1377 1284
1378 DBG_LEAVE_ROUTINE
1379 return 0; 1285 return 0;
1380 1286
1381 /* We end up here for the many possible ways to fail this API. */ 1287 /* We end up here for the many possible ways to fail this API. */
1382abort_disable_intr: 1288abort_disable_intr:
1383 rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); 1289 rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word);
1384 if (!rc) { 1290 if (!rc) {
@@ -1395,6 +1301,5 @@ abort_free_irq:
1395 free_irq(ctrl->pci_dev->irq, ctrl); 1301 free_irq(ctrl->pci_dev->irq, ctrl);
1396 1302
1397abort_free_ctlr: 1303abort_free_ctlr:
1398 DBG_LEAVE_ROUTINE
1399 return -1; 1304 return -1;
1400} 1305}