aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjorn Helgaas <bhelgaas@google.com>2013-10-31 16:05:13 -0400
committerBjorn Helgaas <bhelgaas@google.com>2013-10-31 16:05:13 -0400
commitcc17a67c0762a6030b43e98d775a12a99e5ff247 (patch)
tree263f0b7e3ba19e6ba7b313e87cf9a83d75d0704a
parent4efc52a9c22d4795e6960c1baf41e0f7e440682a (diff)
parentc11592fea04901920236859898f5bc82b6c1a2f1 (diff)
Merge branch 'pci/yijing-mps-v1' into next
* pci/yijing-mps-v1: drm/radeon: use pcie_get_readrq() and pcie_set_readrq() to simplify code staging: et131x: Use pci_dev->pcie_mpss and pcie_set_readrq() to simplify code IB/qib: Drop qib_tune_pcie_caps() and qib_tune_pcie_coalesce() return values IB/qib: Use pcie_set_mps() and pcie_get_mps() to simplify code IB/qib: Use pci_is_root_bus() to check whether it is a root bus tile/PCI: use cached pci_dev->pcie_mpss to simplify code PCI: Export pcie_set_mps() and pcie_get_mps()
-rw-r--r--arch/tile/kernel/pci.c7
-rw-r--r--drivers/gpu/drm/radeon/evergreen.c19
-rw-r--r--drivers/infiniband/hw/qib/qib_pcie.c126
-rw-r--r--drivers/pci/pci.c2
-rw-r--r--drivers/staging/et131x/et131x.c14
5 files changed, 56 insertions, 112 deletions
diff --git a/arch/tile/kernel/pci.c b/arch/tile/kernel/pci.c
index b7180e6e900d..c45593db7718 100644
--- a/arch/tile/kernel/pci.c
+++ b/arch/tile/kernel/pci.c
@@ -251,15 +251,12 @@ static void fixup_read_and_payload_sizes(void)
251 /* Scan for the smallest maximum payload size. */ 251 /* Scan for the smallest maximum payload size. */
252 for_each_pci_dev(dev) { 252 for_each_pci_dev(dev) {
253 u32 devcap; 253 u32 devcap;
254 int max_payload;
255 254
256 if (!pci_is_pcie(dev)) 255 if (!pci_is_pcie(dev))
257 continue; 256 continue;
258 257
259 pcie_capability_read_dword(dev, PCI_EXP_DEVCAP, &devcap); 258 if (dev->pcie_mpss < smallest_max_payload)
260 max_payload = devcap & PCI_EXP_DEVCAP_PAYLOAD; 259 smallest_max_payload = dev->pcie_mpss;
261 if (max_payload < smallest_max_payload)
262 smallest_max_payload = max_payload;
263 } 260 }
264 261
265 /* Now, set the max_payload_size for all devices to that value. */ 262 /* Now, set the max_payload_size for all devices to that value. */
diff --git a/drivers/gpu/drm/radeon/evergreen.c b/drivers/gpu/drm/radeon/evergreen.c
index 555164e270a7..871066a8c630 100644
--- a/drivers/gpu/drm/radeon/evergreen.c
+++ b/drivers/gpu/drm/radeon/evergreen.c
@@ -1174,23 +1174,16 @@ int evergreen_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
1174 1174
1175void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev) 1175void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev)
1176{ 1176{
1177 u16 ctl, v; 1177 int readrq;
1178 int err; 1178 u16 v;
1179
1180 err = pcie_capability_read_word(rdev->pdev, PCI_EXP_DEVCTL, &ctl);
1181 if (err)
1182 return;
1183
1184 v = (ctl & PCI_EXP_DEVCTL_READRQ) >> 12;
1185 1179
1180 readrq = pcie_get_readrq(rdev->pdev);
1181 v = ffs(readrq) - 8;
1186 /* if bios or OS sets MAX_READ_REQUEST_SIZE to an invalid value, fix it 1182 /* if bios or OS sets MAX_READ_REQUEST_SIZE to an invalid value, fix it
1187 * to avoid hangs or perfomance issues 1183 * to avoid hangs or perfomance issues
1188 */ 1184 */
1189 if ((v == 0) || (v == 6) || (v == 7)) { 1185 if ((v == 0) || (v == 6) || (v == 7))
1190 ctl &= ~PCI_EXP_DEVCTL_READRQ; 1186 pcie_set_readrq(rdev->pdev, 512);
1191 ctl |= (2 << 12);
1192 pcie_capability_write_word(rdev->pdev, PCI_EXP_DEVCTL, ctl);
1193 }
1194} 1187}
1195 1188
1196static bool dce4_is_in_vblank(struct radeon_device *rdev, int crtc) 1189static bool dce4_is_in_vblank(struct radeon_device *rdev, int crtc)
diff --git a/drivers/infiniband/hw/qib/qib_pcie.c b/drivers/infiniband/hw/qib/qib_pcie.c
index 3f14009fb662..c8d9c4ab142b 100644
--- a/drivers/infiniband/hw/qib/qib_pcie.c
+++ b/drivers/infiniband/hw/qib/qib_pcie.c
@@ -51,8 +51,8 @@
51 * file calls, even though this violates some 51 * file calls, even though this violates some
52 * expectations of harmlessness. 52 * expectations of harmlessness.
53 */ 53 */
54static int qib_tune_pcie_caps(struct qib_devdata *); 54static void qib_tune_pcie_caps(struct qib_devdata *);
55static int qib_tune_pcie_coalesce(struct qib_devdata *); 55static void qib_tune_pcie_coalesce(struct qib_devdata *);
56 56
57/* 57/*
58 * Do all the common PCIe setup and initialization. 58 * Do all the common PCIe setup and initialization.
@@ -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
481static 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
493static 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
504static int qib_pcie_coalesce; 480static int qib_pcie_coalesce;
505module_param_named(pcie_coalesce, qib_pcie_coalesce, int, S_IRUGO); 481module_param_named(pcie_coalesce, qib_pcie_coalesce, int, S_IRUGO);
@@ -511,7 +487,7 @@ MODULE_PARM_DESC(pcie_coalesce, "tune PCIe colescing on some Intel chipsets");
511 * of these chipsets, with some BIOS settings, and enabling it on those 487 * of these chipsets, with some BIOS settings, and enabling it on those
512 * systems may result in the system crashing, and/or data corruption. 488 * systems may result in the system crashing, and/or data corruption.
513 */ 489 */
514static int qib_tune_pcie_coalesce(struct qib_devdata *dd) 490static void qib_tune_pcie_coalesce(struct qib_devdata *dd)
515{ 491{
516 int r; 492 int r;
517 struct pci_dev *parent; 493 struct pci_dev *parent;
@@ -519,18 +495,18 @@ static int qib_tune_pcie_coalesce(struct qib_devdata *dd)
519 u32 mask, bits, val; 495 u32 mask, bits, val;
520 496
521 if (!qib_pcie_coalesce) 497 if (!qib_pcie_coalesce)
522 return 0; 498 return;
523 499
524 /* Find out supported and configured values for parent (root) */ 500 /* Find out supported and configured values for parent (root) */
525 parent = dd->pcidev->bus->self; 501 parent = dd->pcidev->bus->self;
526 if (parent->bus->parent) { 502 if (parent->bus->parent) {
527 qib_devinfo(dd->pcidev, "Parent not root\n"); 503 qib_devinfo(dd->pcidev, "Parent not root\n");
528 return 1; 504 return;
529 } 505 }
530 if (!pci_is_pcie(parent)) 506 if (!pci_is_pcie(parent))
531 return 1; 507 return;
532 if (parent->vendor != 0x8086) 508 if (parent->vendor != 0x8086)
533 return 1; 509 return;
534 510
535 /* 511 /*
536 * - bit 12: Max_rdcmp_Imt_EN: need to set to 1 512 * - bit 12: Max_rdcmp_Imt_EN: need to set to 1
@@ -563,13 +539,12 @@ static int qib_tune_pcie_coalesce(struct qib_devdata *dd)
563 mask = (3U << 24) | (7U << 10); 539 mask = (3U << 24) | (7U << 10);
564 } else { 540 } else {
565 /* not one of the chipsets that we know about */ 541 /* not one of the chipsets that we know about */
566 return 1; 542 return;
567 } 543 }
568 pci_read_config_dword(parent, 0x48, &val); 544 pci_read_config_dword(parent, 0x48, &val);
569 val &= ~mask; 545 val &= ~mask;
570 val |= bits; 546 val |= bits;
571 r = pci_write_config_dword(parent, 0x48, val); 547 r = pci_write_config_dword(parent, 0x48, val);
572 return 0;
573} 548}
574 549
575/* 550/*
@@ -580,55 +555,44 @@ static int qib_pcie_caps;
580module_param_named(pcie_caps, qib_pcie_caps, int, S_IRUGO); 555module_param_named(pcie_caps, qib_pcie_caps, int, S_IRUGO);
581MODULE_PARM_DESC(pcie_caps, "Max PCIe tuning: Payload (0..3), ReadReq (4..7)"); 556MODULE_PARM_DESC(pcie_caps, "Max PCIe tuning: Payload (0..3), ReadReq (4..7)");
582 557
583static int qib_tune_pcie_caps(struct qib_devdata *dd) 558static void qib_tune_pcie_caps(struct qib_devdata *dd)
584{ 559{
585 int ret = 1; /* Assume the worst */
586 struct pci_dev *parent; 560 struct pci_dev *parent;
587 u16 pcaps, pctl, ecaps, ectl; 561 u16 rc_mpss, rc_mps, ep_mpss, ep_mps;
588 int rc_sup, ep_sup; 562 u16 rc_mrrs, ep_mrrs, max_mrrs;
589 int rc_cur, ep_cur;
590 563
591 /* Find out supported and configured values for parent (root) */ 564 /* Find out supported and configured values for parent (root) */
592 parent = dd->pcidev->bus->self; 565 parent = dd->pcidev->bus->self;
593 if (parent->bus->parent) { 566 if (!pci_is_root_bus(parent->bus)) {
594 qib_devinfo(dd->pcidev, "Parent not root\n"); 567 qib_devinfo(dd->pcidev, "Parent not root\n");
595 goto bail; 568 return;
596 } 569 }
597 570
598 if (!pci_is_pcie(parent) || !pci_is_pcie(dd->pcidev)) 571 if (!pci_is_pcie(parent) || !pci_is_pcie(dd->pcidev))
599 goto bail; 572 return;
600 pcie_capability_read_word(parent, PCI_EXP_DEVCAP, &pcaps); 573
601 pcie_capability_read_word(parent, PCI_EXP_DEVCTL, &pctl); 574 rc_mpss = parent->pcie_mpss;
575 rc_mps = ffs(pcie_get_mps(parent)) - 8;
602 /* Find out supported and configured values for endpoint (us) */ 576 /* Find out supported and configured values for endpoint (us) */
603 pcie_capability_read_word(dd->pcidev, PCI_EXP_DEVCAP, &ecaps); 577 ep_mpss = dd->pcidev->pcie_mpss;
604 pcie_capability_read_word(dd->pcidev, PCI_EXP_DEVCTL, &ectl); 578 ep_mps = ffs(pcie_get_mps(dd->pcidev)) - 8;
605 579
606 ret = 0;
607 /* Find max payload supported by root, endpoint */ 580 /* Find max payload supported by root, endpoint */
608 rc_sup = fld2val(pcaps, PCI_EXP_DEVCAP_PAYLOAD); 581 if (rc_mpss > ep_mpss)
609 ep_sup = fld2val(ecaps, PCI_EXP_DEVCAP_PAYLOAD); 582 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 583
616 /* If Supported greater than limit in module param, limit it */ 584 /* If Supported greater than limit in module param, limit it */
617 if (rc_sup > (qib_pcie_caps & 7)) 585 if (rc_mpss > (qib_pcie_caps & 7))
618 rc_sup = qib_pcie_caps & 7; 586 rc_mpss = qib_pcie_caps & 7;
619 /* If less than (allowed, supported), bump root payload */ 587 /* If less than (allowed, supported), bump root payload */
620 if (rc_sup > rc_cur) { 588 if (rc_mpss > rc_mps) {
621 rc_cur = rc_sup; 589 rc_mps = rc_mpss;
622 pctl = (pctl & ~PCI_EXP_DEVCTL_PAYLOAD) | 590 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 } 591 }
626 /* If less than (allowed, supported), bump endpoint payload */ 592 /* If less than (allowed, supported), bump endpoint payload */
627 if (rc_sup > ep_cur) { 593 if (rc_mpss > ep_mps) {
628 ep_cur = rc_sup; 594 ep_mps = rc_mpss;
629 ectl = (ectl & ~PCI_EXP_DEVCTL_PAYLOAD) | 595 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 } 596 }
633 597
634 /* 598 /*
@@ -636,26 +600,22 @@ static int qib_tune_pcie_caps(struct qib_devdata *dd)
636 * No field for max supported, but PCIe spec limits it to 4096, 600 * No field for max supported, but PCIe spec limits it to 4096,
637 * which is code '5' (log2(4096) - 7) 601 * which is code '5' (log2(4096) - 7)
638 */ 602 */
639 rc_sup = 5; 603 max_mrrs = 5;
640 if (rc_sup > ((qib_pcie_caps >> 4) & 7)) 604 if (max_mrrs > ((qib_pcie_caps >> 4) & 7))
641 rc_sup = (qib_pcie_caps >> 4) & 7; 605 max_mrrs = (qib_pcie_caps >> 4) & 7;
642 rc_cur = fld2val(pctl, PCI_EXP_DEVCTL_READRQ); 606
643 ep_cur = fld2val(ectl, PCI_EXP_DEVCTL_READRQ); 607 max_mrrs = 128 << max_mrrs;
644 608 rc_mrrs = pcie_get_readrq(parent);
645 if (rc_sup > rc_cur) { 609 ep_mrrs = pcie_get_readrq(dd->pcidev);
646 rc_cur = rc_sup; 610
647 pctl = (pctl & ~PCI_EXP_DEVCTL_READRQ) | 611 if (max_mrrs > rc_mrrs) {
648 val2fld(rc_cur, PCI_EXP_DEVCTL_READRQ); 612 rc_mrrs = max_mrrs;
649 pcie_capability_write_word(parent, PCI_EXP_DEVCTL, pctl); 613 pcie_set_readrq(parent, rc_mrrs);
650 } 614 }
651 if (rc_sup > ep_cur) { 615 if (max_mrrs > ep_mrrs) {
652 ep_cur = rc_sup; 616 ep_mrrs = max_mrrs;
653 ectl = (ectl & ~PCI_EXP_DEVCTL_READRQ) | 617 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 } 618 }
657bail:
658 return ret;
659} 619}
660/* End of PCIe capability tuning */ 620/* End of PCIe capability tuning */
661 621
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index ad7fc72a40a0..c0805f26f339 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -3972,6 +3972,7 @@ int pcie_get_mps(struct pci_dev *dev)
3972 3972
3973 return 128 << ((ctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5); 3973 return 128 << ((ctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
3974} 3974}
3975EXPORT_SYMBOL(pcie_get_mps);
3975 3976
3976/** 3977/**
3977 * pcie_set_mps - set PCI Express maximum payload size 3978 * pcie_set_mps - set PCI Express maximum payload size
@@ -3996,6 +3997,7 @@ int pcie_set_mps(struct pci_dev *dev, int mps)
3996 return pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL, 3997 return pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
3997 PCI_EXP_DEVCTL_PAYLOAD, v); 3998 PCI_EXP_DEVCTL_PAYLOAD, v);
3998} 3999}
4000EXPORT_SYMBOL(pcie_set_mps);
3999 4001
4000/** 4002/**
4001 * pcie_get_minimum_link - determine minimum link settings of a PCI device 4003 * pcie_get_minimum_link - determine minimum link settings of a PCI device
diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c
index f73e58f5ef8d..876881d1826e 100644
--- a/drivers/staging/et131x/et131x.c
+++ b/drivers/staging/et131x/et131x.c
@@ -3605,17 +3605,10 @@ static int et131x_pci_init(struct et131x_adapter *adapter,
3605 goto err_out; 3605 goto err_out;
3606 } 3606 }
3607 3607
3608 /* Let's set up the PORT LOGIC Register. First we need to know what 3608 /* Let's set up the PORT LOGIC Register. */
3609 * the max_payload_size is
3610 */
3611 if (pcie_capability_read_word(pdev, PCI_EXP_DEVCAP, &max_payload)) {
3612 dev_err(&pdev->dev,
3613 "Could not read PCI config space for Max Payload Size\n");
3614 goto err_out;
3615 }
3616 3609
3617 /* Program the Ack/Nak latency and replay timers */ 3610 /* Program the Ack/Nak latency and replay timers */
3618 max_payload &= 0x07; 3611 max_payload = pdev->pcie_mpss;
3619 3612
3620 if (max_payload < 2) { 3613 if (max_payload < 2) {
3621 static const u16 acknak[2] = { 0x76, 0xD0 }; 3614 static const u16 acknak[2] = { 0x76, 0xD0 };
@@ -3645,8 +3638,7 @@ static int et131x_pci_init(struct et131x_adapter *adapter,
3645 } 3638 }
3646 3639
3647 /* Change the max read size to 2k */ 3640 /* Change the max read size to 2k */
3648 if (pcie_capability_clear_and_set_word(pdev, PCI_EXP_DEVCTL, 3641 if (pcie_set_readrq(pdev, 2048)) {
3649 PCI_EXP_DEVCTL_READRQ, 0x4 << 12)) {
3650 dev_err(&pdev->dev, 3642 dev_err(&pdev->dev,
3651 "Couldn't change PCI config space for Max read size\n"); 3643 "Couldn't change PCI config space for Max read size\n");
3652 goto err_out; 3644 goto err_out;