Skip to content

Commit 0948395

Browse files
PCI: dwc: Add support for configuring lane equalization presets
PCIe equalization presets are predefined settings used to optimize signal integrity by compensating for signal loss and distortion in high-speed data transmission. Based upon the number of lanes and the data rate supported, write the preset data read from the device tree in to the lane equalization control registers. These preset values will be used by the controller during the LTSSM lane equalization procedure. Signed-off-by: Krishna Chaitanya Chundru <[email protected]> [mani: reworded the commit message and comments in the driver] Signed-off-by: Manivannan Sadhasivam <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 178af54 commit 0948395

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

drivers/pci/controller/dwc/pcie-designware-host.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,10 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)
526526
if (pci->num_lanes < 1)
527527
pci->num_lanes = dw_pcie_link_get_max_link_width(pci);
528528

529+
ret = of_pci_get_equalization_presets(dev, &pp->presets, pci->num_lanes);
530+
if (ret)
531+
goto err_free_msi;
532+
529533
/*
530534
* Allocate the resource for MSG TLP before programming the iATU
531535
* outbound window in dw_pcie_setup_rc(). Since the allocation depends
@@ -831,6 +835,77 @@ static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp)
831835
return 0;
832836
}
833837

838+
static void dw_pcie_program_presets(struct dw_pcie_rp *pp, enum pci_bus_speed speed)
839+
{
840+
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
841+
u8 lane_eq_offset, lane_reg_size, cap_id;
842+
u8 *presets;
843+
u32 cap;
844+
int i;
845+
846+
if (speed == PCIE_SPEED_8_0GT) {
847+
presets = (u8 *)pp->presets.eq_presets_8gts;
848+
lane_eq_offset = PCI_SECPCI_LE_CTRL;
849+
cap_id = PCI_EXT_CAP_ID_SECPCI;
850+
/* For data rate of 8 GT/S each lane equalization control is 16bits wide*/
851+
lane_reg_size = 0x2;
852+
} else if (speed == PCIE_SPEED_16_0GT) {
853+
presets = pp->presets.eq_presets_Ngts[EQ_PRESET_TYPE_16GTS - 1];
854+
lane_eq_offset = PCI_PL_16GT_LE_CTRL;
855+
cap_id = PCI_EXT_CAP_ID_PL_16GT;
856+
lane_reg_size = 0x1;
857+
} else if (speed == PCIE_SPEED_32_0GT) {
858+
presets = pp->presets.eq_presets_Ngts[EQ_PRESET_TYPE_32GTS - 1];
859+
lane_eq_offset = PCI_PL_32GT_LE_CTRL;
860+
cap_id = PCI_EXT_CAP_ID_PL_32GT;
861+
lane_reg_size = 0x1;
862+
} else if (speed == PCIE_SPEED_64_0GT) {
863+
presets = pp->presets.eq_presets_Ngts[EQ_PRESET_TYPE_64GTS - 1];
864+
lane_eq_offset = PCI_PL_64GT_LE_CTRL;
865+
cap_id = PCI_EXT_CAP_ID_PL_64GT;
866+
lane_reg_size = 0x1;
867+
} else {
868+
return;
869+
}
870+
871+
if (presets[0] == PCI_EQ_RESV)
872+
return;
873+
874+
cap = dw_pcie_find_ext_capability(pci, cap_id);
875+
if (!cap)
876+
return;
877+
878+
/*
879+
* Write preset values to the registers byte-by-byte for the given
880+
* number of lanes and register size.
881+
*/
882+
for (i = 0; i < pci->num_lanes * lane_reg_size; i++)
883+
dw_pcie_writeb_dbi(pci, cap + lane_eq_offset + i, presets[i]);
884+
}
885+
886+
static void dw_pcie_config_presets(struct dw_pcie_rp *pp)
887+
{
888+
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
889+
enum pci_bus_speed speed = pcie_link_speed[pci->max_link_speed];
890+
891+
/*
892+
* Lane equalization settings need to be applied for all data rates the
893+
* controller supports and for all supported lanes.
894+
*/
895+
896+
if (speed >= PCIE_SPEED_8_0GT)
897+
dw_pcie_program_presets(pp, PCIE_SPEED_8_0GT);
898+
899+
if (speed >= PCIE_SPEED_16_0GT)
900+
dw_pcie_program_presets(pp, PCIE_SPEED_16_0GT);
901+
902+
if (speed >= PCIE_SPEED_32_0GT)
903+
dw_pcie_program_presets(pp, PCIE_SPEED_32_0GT);
904+
905+
if (speed >= PCIE_SPEED_64_0GT)
906+
dw_pcie_program_presets(pp, PCIE_SPEED_64_0GT);
907+
}
908+
834909
int dw_pcie_setup_rc(struct dw_pcie_rp *pp)
835910
{
836911
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
@@ -884,6 +959,7 @@ int dw_pcie_setup_rc(struct dw_pcie_rp *pp)
884959
PCI_COMMAND_MASTER | PCI_COMMAND_SERR;
885960
dw_pcie_writel_dbi(pci, PCI_COMMAND, val);
886961

962+
dw_pcie_config_presets(pp);
887963
/*
888964
* If the platform provides its own child bus config accesses, it means
889965
* the platform uses its own address translation component rather than

drivers/pci/controller/dwc/pcie-designware.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <linux/pci-epc.h>
2626
#include <linux/pci-epf.h>
2727

28+
#include "../../pci.h"
29+
2830
/* DWC PCIe IP-core versions (native support since v4.70a) */
2931
#define DW_PCIE_VER_365A 0x3336352a
3032
#define DW_PCIE_VER_460A 0x3436302a
@@ -412,6 +414,7 @@ struct dw_pcie_rp {
412414
int msg_atu_index;
413415
struct resource *msg_res;
414416
bool use_linkup_irq;
417+
struct pci_eq_presets presets;
415418
};
416419

417420
struct dw_pcie_ep_ops {

0 commit comments

Comments
 (0)