提交 0921caf3 编写于 作者: J Jiang Liu 提交者: Bjorn Helgaas

IB/qib: Use PCI Express Capability accessors

Use PCI Express Capability access functions to simplify qib driver.
Signed-off-by: NJiang Liu <jiang.liu@huawei.com>
Signed-off-by: NYijing Wang <wangyijing@huawei.com>
Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
Acked-by: NMike Marciniszyn <mike.marciniszyn@intel.com>
上级 3c55569b
...@@ -273,10 +273,9 @@ int qib_pcie_params(struct qib_devdata *dd, u32 minw, u32 *nent, ...@@ -273,10 +273,9 @@ int qib_pcie_params(struct qib_devdata *dd, u32 minw, u32 *nent,
struct qib_msix_entry *entry) struct qib_msix_entry *entry)
{ {
u16 linkstat, speed; u16 linkstat, speed;
int pos = 0, pose, ret = 1; int pos = 0, ret = 1;
pose = pci_pcie_cap(dd->pcidev); if (!pci_is_pcie(dd->pcidev)) {
if (!pose) {
qib_dev_err(dd, "Can't find PCI Express capability!\n"); qib_dev_err(dd, "Can't find PCI Express capability!\n");
/* set up something... */ /* set up something... */
dd->lbus_width = 1; dd->lbus_width = 1;
...@@ -298,7 +297,7 @@ int qib_pcie_params(struct qib_devdata *dd, u32 minw, u32 *nent, ...@@ -298,7 +297,7 @@ int qib_pcie_params(struct qib_devdata *dd, u32 minw, u32 *nent,
if (!pos) if (!pos)
qib_enable_intx(dd->pcidev); qib_enable_intx(dd->pcidev);
pci_read_config_word(dd->pcidev, pose + PCI_EXP_LNKSTA, &linkstat); pcie_capability_read_word(dd->pcidev, PCI_EXP_LNKSTA, &linkstat);
/* /*
* speed is bits 0-3, linkwidth is bits 4-8 * speed is bits 0-3, linkwidth is bits 4-8
* no defines for them in headers * no defines for them in headers
...@@ -516,7 +515,6 @@ static int qib_tune_pcie_coalesce(struct qib_devdata *dd) ...@@ -516,7 +515,6 @@ static int qib_tune_pcie_coalesce(struct qib_devdata *dd)
{ {
int r; int r;
struct pci_dev *parent; struct pci_dev *parent;
int ppos;
u16 devid; u16 devid;
u32 mask, bits, val; u32 mask, bits, val;
...@@ -529,8 +527,7 @@ static int qib_tune_pcie_coalesce(struct qib_devdata *dd) ...@@ -529,8 +527,7 @@ static int qib_tune_pcie_coalesce(struct qib_devdata *dd)
qib_devinfo(dd->pcidev, "Parent not root\n"); qib_devinfo(dd->pcidev, "Parent not root\n");
return 1; return 1;
} }
ppos = pci_pcie_cap(parent); if (!pci_is_pcie(parent))
if (!ppos)
return 1; return 1;
if (parent->vendor != 0x8086) if (parent->vendor != 0x8086)
return 1; return 1;
...@@ -587,7 +584,6 @@ static int qib_tune_pcie_caps(struct qib_devdata *dd) ...@@ -587,7 +584,6 @@ static int qib_tune_pcie_caps(struct qib_devdata *dd)
{ {
int ret = 1; /* Assume the worst */ int ret = 1; /* Assume the worst */
struct pci_dev *parent; struct pci_dev *parent;
int ppos, epos;
u16 pcaps, pctl, ecaps, ectl; u16 pcaps, pctl, ecaps, ectl;
int rc_sup, ep_sup; int rc_sup, ep_sup;
int rc_cur, ep_cur; int rc_cur, ep_cur;
...@@ -598,19 +594,15 @@ static int qib_tune_pcie_caps(struct qib_devdata *dd) ...@@ -598,19 +594,15 @@ static int qib_tune_pcie_caps(struct qib_devdata *dd)
qib_devinfo(dd->pcidev, "Parent not root\n"); qib_devinfo(dd->pcidev, "Parent not root\n");
goto bail; goto bail;
} }
ppos = pci_pcie_cap(parent);
if (ppos) { if (!pci_is_pcie(parent) || !pci_is_pcie(dd->pcidev))
pci_read_config_word(parent, ppos + PCI_EXP_DEVCAP, &pcaps);
pci_read_config_word(parent, ppos + PCI_EXP_DEVCTL, &pctl);
} else
goto bail; goto bail;
pcie_capability_read_word(parent, PCI_EXP_DEVCAP, &pcaps);
pcie_capability_read_word(parent, PCI_EXP_DEVCTL, &pctl);
/* Find out supported and configured values for endpoint (us) */ /* Find out supported and configured values for endpoint (us) */
epos = pci_pcie_cap(dd->pcidev); pcie_capability_read_word(dd->pcidev, PCI_EXP_DEVCAP, &ecaps);
if (epos) { pcie_capability_read_word(dd->pcidev, PCI_EXP_DEVCTL, &ectl);
pci_read_config_word(dd->pcidev, epos + PCI_EXP_DEVCAP, &ecaps);
pci_read_config_word(dd->pcidev, epos + PCI_EXP_DEVCTL, &ectl);
} else
goto bail;
ret = 0; ret = 0;
/* Find max payload supported by root, endpoint */ /* Find max payload supported by root, endpoint */
rc_sup = fld2val(pcaps, PCI_EXP_DEVCAP_PAYLOAD); rc_sup = fld2val(pcaps, PCI_EXP_DEVCAP_PAYLOAD);
...@@ -629,14 +621,14 @@ static int qib_tune_pcie_caps(struct qib_devdata *dd) ...@@ -629,14 +621,14 @@ static int qib_tune_pcie_caps(struct qib_devdata *dd)
rc_cur = rc_sup; rc_cur = rc_sup;
pctl = (pctl & ~PCI_EXP_DEVCTL_PAYLOAD) | pctl = (pctl & ~PCI_EXP_DEVCTL_PAYLOAD) |
val2fld(rc_cur, PCI_EXP_DEVCTL_PAYLOAD); val2fld(rc_cur, PCI_EXP_DEVCTL_PAYLOAD);
pci_write_config_word(parent, ppos + PCI_EXP_DEVCTL, pctl); pcie_capability_write_word(parent, PCI_EXP_DEVCTL, pctl);
} }
/* If less than (allowed, supported), bump endpoint payload */ /* If less than (allowed, supported), bump endpoint payload */
if (rc_sup > ep_cur) { if (rc_sup > ep_cur) {
ep_cur = rc_sup; ep_cur = rc_sup;
ectl = (ectl & ~PCI_EXP_DEVCTL_PAYLOAD) | ectl = (ectl & ~PCI_EXP_DEVCTL_PAYLOAD) |
val2fld(ep_cur, PCI_EXP_DEVCTL_PAYLOAD); val2fld(ep_cur, PCI_EXP_DEVCTL_PAYLOAD);
pci_write_config_word(dd->pcidev, epos + PCI_EXP_DEVCTL, ectl); pcie_capability_write_word(dd->pcidev, PCI_EXP_DEVCTL, ectl);
} }
/* /*
...@@ -654,13 +646,13 @@ static int qib_tune_pcie_caps(struct qib_devdata *dd) ...@@ -654,13 +646,13 @@ static int qib_tune_pcie_caps(struct qib_devdata *dd)
rc_cur = rc_sup; rc_cur = rc_sup;
pctl = (pctl & ~PCI_EXP_DEVCTL_READRQ) | pctl = (pctl & ~PCI_EXP_DEVCTL_READRQ) |
val2fld(rc_cur, PCI_EXP_DEVCTL_READRQ); val2fld(rc_cur, PCI_EXP_DEVCTL_READRQ);
pci_write_config_word(parent, ppos + PCI_EXP_DEVCTL, pctl); pcie_capability_write_word(parent, PCI_EXP_DEVCTL, pctl);
} }
if (rc_sup > ep_cur) { if (rc_sup > ep_cur) {
ep_cur = rc_sup; ep_cur = rc_sup;
ectl = (ectl & ~PCI_EXP_DEVCTL_READRQ) | ectl = (ectl & ~PCI_EXP_DEVCTL_READRQ) |
val2fld(ep_cur, PCI_EXP_DEVCTL_READRQ); val2fld(ep_cur, PCI_EXP_DEVCTL_READRQ);
pci_write_config_word(dd->pcidev, epos + PCI_EXP_DEVCTL, ectl); pcie_capability_write_word(dd->pcidev, PCI_EXP_DEVCTL, ectl);
} }
bail: bail:
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册