diff options
Diffstat (limited to 'drivers/infiniband/hw/qib/qib_pcie.c')
-rw-r--r-- | drivers/infiniband/hw/qib/qib_pcie.c | 96 |
1 files changed, 30 insertions, 66 deletions
diff --git a/drivers/infiniband/hw/qib/qib_pcie.c b/drivers/infiniband/hw/qib/qib_pcie.c index 45e55ff33dbf..24973c8b8443 100644 --- a/drivers/infiniband/hw/qib/qib_pcie.c +++ b/drivers/infiniband/hw/qib/qib_pcie.c | |||
@@ -476,30 +476,6 @@ void qib_pcie_reenable(struct qib_devdata *dd, u16 cmd, u8 iline, u8 cline) | |||
476 | "pci_enable_device failed after reset: %d\n", r); | 476 | "pci_enable_device failed after reset: %d\n", r); |
477 | } | 477 | } |
478 | 478 | ||
479 | /* code to adjust PCIe capabilities. */ | ||
480 | |||
481 | static int fld2val(int wd, int mask) | ||
482 | { | ||
483 | int lsbmask; | ||
484 | |||
485 | if (!mask) | ||
486 | return 0; | ||
487 | wd &= mask; | ||
488 | lsbmask = mask ^ (mask & (mask - 1)); | ||
489 | wd /= lsbmask; | ||
490 | return wd; | ||
491 | } | ||
492 | |||
493 | static int val2fld(int wd, int mask) | ||
494 | { | ||
495 | int lsbmask; | ||
496 | |||
497 | if (!mask) | ||
498 | return 0; | ||
499 | lsbmask = mask ^ (mask & (mask - 1)); | ||
500 | wd *= lsbmask; | ||
501 | return wd; | ||
502 | } | ||
503 | 479 | ||
504 | static int qib_pcie_coalesce; | 480 | static int qib_pcie_coalesce; |
505 | module_param_named(pcie_coalesce, qib_pcie_coalesce, int, S_IRUGO); | 481 | module_param_named(pcie_coalesce, qib_pcie_coalesce, int, S_IRUGO); |
@@ -584,9 +560,8 @@ static int qib_tune_pcie_caps(struct qib_devdata *dd) | |||
584 | { | 560 | { |
585 | int ret = 1; /* Assume the worst */ | 561 | int ret = 1; /* Assume the worst */ |
586 | struct pci_dev *parent; | 562 | struct pci_dev *parent; |
587 | u16 pcaps, pctl, ecaps, ectl; | 563 | u16 rc_mpss, rc_mps, ep_mpss, ep_mps; |
588 | int rc_sup, ep_sup; | 564 | u16 rc_mrrs, ep_mrrs, max_mrrs; |
589 | int rc_cur, ep_cur; | ||
590 | 565 | ||
591 | /* Find out supported and configured values for parent (root) */ | 566 | /* Find out supported and configured values for parent (root) */ |
592 | parent = dd->pcidev->bus->self; | 567 | parent = dd->pcidev->bus->self; |
@@ -597,38 +572,29 @@ static int qib_tune_pcie_caps(struct qib_devdata *dd) | |||
597 | 572 | ||
598 | if (!pci_is_pcie(parent) || !pci_is_pcie(dd->pcidev)) | 573 | if (!pci_is_pcie(parent) || !pci_is_pcie(dd->pcidev)) |
599 | goto bail; | 574 | goto bail; |
600 | pcie_capability_read_word(parent, PCI_EXP_DEVCAP, &pcaps); | 575 | rc_mpss = parent->pcie_mpss; |
601 | pcie_capability_read_word(parent, PCI_EXP_DEVCTL, &pctl); | 576 | rc_mps = ffs(pcie_get_mps(parent)) - 8; |
602 | /* Find out supported and configured values for endpoint (us) */ | 577 | /* Find out supported and configured values for endpoint (us) */ |
603 | pcie_capability_read_word(dd->pcidev, PCI_EXP_DEVCAP, &ecaps); | 578 | ep_mpss = dd->pcidev->pcie_mpss; |
604 | pcie_capability_read_word(dd->pcidev, PCI_EXP_DEVCTL, &ectl); | 579 | ep_mps = ffs(pcie_get_mps(dd->pcidev)) - 8; |
605 | 580 | ||
606 | ret = 0; | 581 | ret = 0; |
607 | /* Find max payload supported by root, endpoint */ | 582 | /* Find max payload supported by root, endpoint */ |
608 | rc_sup = fld2val(pcaps, PCI_EXP_DEVCAP_PAYLOAD); | 583 | if (rc_mpss > ep_mpss) |
609 | ep_sup = fld2val(ecaps, PCI_EXP_DEVCAP_PAYLOAD); | 584 | rc_mpss = ep_mpss; |
610 | if (rc_sup > ep_sup) | ||
611 | rc_sup = ep_sup; | ||
612 | |||
613 | rc_cur = fld2val(pctl, PCI_EXP_DEVCTL_PAYLOAD); | ||
614 | ep_cur = fld2val(ectl, PCI_EXP_DEVCTL_PAYLOAD); | ||
615 | 585 | ||
616 | /* If Supported greater than limit in module param, limit it */ | 586 | /* If Supported greater than limit in module param, limit it */ |
617 | if (rc_sup > (qib_pcie_caps & 7)) | 587 | if (rc_mpss > (qib_pcie_caps & 7)) |
618 | rc_sup = qib_pcie_caps & 7; | 588 | rc_mpss = qib_pcie_caps & 7; |
619 | /* If less than (allowed, supported), bump root payload */ | 589 | /* If less than (allowed, supported), bump root payload */ |
620 | if (rc_sup > rc_cur) { | 590 | if (rc_mpss > rc_mps) { |
621 | rc_cur = rc_sup; | 591 | rc_mps = rc_mpss; |
622 | pctl = (pctl & ~PCI_EXP_DEVCTL_PAYLOAD) | | 592 | pcie_set_mps(parent, 128 << rc_mps); |
623 | val2fld(rc_cur, PCI_EXP_DEVCTL_PAYLOAD); | ||
624 | pcie_capability_write_word(parent, PCI_EXP_DEVCTL, pctl); | ||
625 | } | 593 | } |
626 | /* If less than (allowed, supported), bump endpoint payload */ | 594 | /* If less than (allowed, supported), bump endpoint payload */ |
627 | if (rc_sup > ep_cur) { | 595 | if (rc_mpss > ep_mps) { |
628 | ep_cur = rc_sup; | 596 | ep_mps = rc_mpss; |
629 | ectl = (ectl & ~PCI_EXP_DEVCTL_PAYLOAD) | | 597 | pcie_set_mps(dd->pcidev, 128 << ep_mps); |
630 | val2fld(ep_cur, PCI_EXP_DEVCTL_PAYLOAD); | ||
631 | pcie_capability_write_word(dd->pcidev, PCI_EXP_DEVCTL, ectl); | ||
632 | } | 598 | } |
633 | 599 | ||
634 | /* | 600 | /* |
@@ -636,23 +602,21 @@ static int qib_tune_pcie_caps(struct qib_devdata *dd) | |||
636 | * No field for max supported, but PCIe spec limits it to 4096, | 602 | * No field for max supported, but PCIe spec limits it to 4096, |
637 | * which is code '5' (log2(4096) - 7) | 603 | * which is code '5' (log2(4096) - 7) |
638 | */ | 604 | */ |
639 | rc_sup = 5; | 605 | max_mrrs = 5; |
640 | if (rc_sup > ((qib_pcie_caps >> 4) & 7)) | 606 | if (max_mrrs > ((qib_pcie_caps >> 4) & 7)) |
641 | rc_sup = (qib_pcie_caps >> 4) & 7; | 607 | max_mrrs = (qib_pcie_caps >> 4) & 7; |
642 | rc_cur = fld2val(pctl, PCI_EXP_DEVCTL_READRQ); | 608 | |
643 | ep_cur = fld2val(ectl, PCI_EXP_DEVCTL_READRQ); | 609 | max_mrrs = 128 << max_mrrs; |
644 | 610 | rc_mrrs = pcie_get_readrq(parent); | |
645 | if (rc_sup > rc_cur) { | 611 | ep_mrrs = pcie_get_readrq(dd->pcidev); |
646 | rc_cur = rc_sup; | 612 | |
647 | pctl = (pctl & ~PCI_EXP_DEVCTL_READRQ) | | 613 | if (max_mrrs > rc_mrrs) { |
648 | val2fld(rc_cur, PCI_EXP_DEVCTL_READRQ); | 614 | rc_mrrs = max_mrrs; |
649 | pcie_capability_write_word(parent, PCI_EXP_DEVCTL, pctl); | 615 | pcie_set_readrq(parent, rc_mrrs); |
650 | } | 616 | } |
651 | if (rc_sup > ep_cur) { | 617 | if (max_mrrs > ep_mrrs) { |
652 | ep_cur = rc_sup; | 618 | ep_mrrs = max_mrrs; |
653 | ectl = (ectl & ~PCI_EXP_DEVCTL_READRQ) | | 619 | pcie_set_readrq(dd->pcidev, ep_mrrs); |
654 | val2fld(ep_cur, PCI_EXP_DEVCTL_READRQ); | ||
655 | pcie_capability_write_word(dd->pcidev, PCI_EXP_DEVCTL, ectl); | ||
656 | } | 620 | } |
657 | bail: | 621 | bail: |
658 | return ret; | 622 | return ret; |