Skip to content

Commit 8f3b710

Browse files
ij-intelrleon
authored andcommitted
RDMA/hfi1: Use RMW accessors for changing LNKCTL2
Convert open coded RMW accesses for LNKCTL2 to use pcie_capability_clear_and_set_word() which makes its easier to understand what the code tries to do. In addition, this futureproofs the code. LNKCTL2 is not really owned by any driver because it is a collection of control bits that PCI core might need to touch. RMW accessors already have support for proper locking for a selected set of registers to avoid losing concurrent updates (LNKCTL2 is not yet among the registers that need protection but likely will be in the future). Suggested-by: Lukas Wunner <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Dean Luick <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 44b607a commit 8f3b710

File tree

1 file changed

+8
-22
lines changed
  • drivers/infiniband/hw/hfi1

1 file changed

+8
-22
lines changed

drivers/infiniband/hw/hfi1/pcie.c

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,14 +1207,11 @@ int do_pcie_gen3_transition(struct hfi1_devdata *dd)
12071207
(u32)lnkctl2);
12081208
/* only write to parent if target is not as high as ours */
12091209
if ((lnkctl2 & PCI_EXP_LNKCTL2_TLS) < target_vector) {
1210-
lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS;
1211-
lnkctl2 |= target_vector;
1212-
dd_dev_info(dd, "%s: ..new link control2: 0x%x\n", __func__,
1213-
(u32)lnkctl2);
1214-
ret = pcie_capability_write_word(parent,
1215-
PCI_EXP_LNKCTL2, lnkctl2);
1210+
ret = pcie_capability_clear_and_set_word(parent, PCI_EXP_LNKCTL2,
1211+
PCI_EXP_LNKCTL2_TLS,
1212+
target_vector);
12161213
if (ret) {
1217-
dd_dev_err(dd, "Unable to write to PCI config\n");
1214+
dd_dev_err(dd, "Unable to change parent PCI target speed\n");
12181215
return_error = 1;
12191216
goto done;
12201217
}
@@ -1223,22 +1220,11 @@ int do_pcie_gen3_transition(struct hfi1_devdata *dd)
12231220
}
12241221

12251222
dd_dev_info(dd, "%s: setting target link speed\n", __func__);
1226-
ret = pcie_capability_read_word(dd->pcidev, PCI_EXP_LNKCTL2, &lnkctl2);
1223+
ret = pcie_capability_clear_and_set_word(dd->pcidev, PCI_EXP_LNKCTL2,
1224+
PCI_EXP_LNKCTL2_TLS,
1225+
target_vector);
12271226
if (ret) {
1228-
dd_dev_err(dd, "Unable to read from PCI config\n");
1229-
return_error = 1;
1230-
goto done;
1231-
}
1232-
1233-
dd_dev_info(dd, "%s: ..old link control2: 0x%x\n", __func__,
1234-
(u32)lnkctl2);
1235-
lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS;
1236-
lnkctl2 |= target_vector;
1237-
dd_dev_info(dd, "%s: ..new link control2: 0x%x\n", __func__,
1238-
(u32)lnkctl2);
1239-
ret = pcie_capability_write_word(dd->pcidev, PCI_EXP_LNKCTL2, lnkctl2);
1240-
if (ret) {
1241-
dd_dev_err(dd, "Unable to write to PCI config\n");
1227+
dd_dev_err(dd, "Unable to change device PCI target speed\n");
12421228
return_error = 1;
12431229
goto done;
12441230
}

0 commit comments

Comments
 (0)