mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
Pull pci updates from Bjorn Helgaas:
"Enumeration:
- Allow TLP Processing Hints to be enabled for RCiEPs (George Abraham
P)
- Enable AtomicOps only if we know the Root Port supports them (Gerd
Bayer)
- Don't enable AtomicOps for RCiEPs since none of them need Atomic
Ops and we can't tell whether the Root Complex would support them
(Gerd Bayer)
- Leave Precision Time Measurement disabled until a driver enables it
to avoid PCIe errors (Mika Westerberg)
- Make pci_set_vga_state() fail if bridge doesn't support VGA
routing, i.e., PCI_BRIDGE_CTL_VGA is not writable, and return
errors to vga_get() callers including userspace via
/dev/vga_arbiter (Simon Richter)
- Validate max-link-speed from DT in j721e, brcmstb, mediatek-gen3,
rzg3s drivers (where the actual controller constraints are known),
and remove validation from the generic OF DT accessor (Hans Zhang)
- Remove pc110pad driver (no longer useful after 486 CPU support
removed) and no_pci_devices() (pc110pad was the last user) (Dmitry
Torokhov, Heiner Kallweit)
Resource management:
- Prevent assigning space to unimplemented bridge windows; previously
we mistakenly assumed prefetchable window existed and assigned
space and put a BAR there (Ahmed Naseef)
- Avoid shrinking bridge windows to fit in the initial Root Port
window; fixes one problem with devices with large BARs connected
via switches, e.g., Thunderbolt (Ilpo Järvinen)
- Pass full extent of empty space, not just the aligned space, to
resource_alignf callback so free space before the requested
alignment can be used (Ilpo Järvinen)
- Place small resources before larger ones for better utilization of
address space (Ilpo Järvinen)
- Fix alignment calculation for resource size larger than align,
e.g., bridge windows larger than the 1MB required alignment (Ilpo
Järvinen)
Reset:
- Update slot handling so all ARI functions are treated as being in
the same slot. They're all reset by Secondary Bus Reset, but
previously drivers of ARI functions that appeared to be on a
non-zero device weren't notified and fatal hardware errors could
result (Keith Busch)
- Make sysfs reset_subordinate hotplug safe to avoid spurious hotplug
events (Keith Busch)
- Hide Secondary Bus Reset ('bus') from sysfs reset_methods if masked
by CXL because it has no effect (Vidya Sagar)
- Avoid FLR for AMD NPU device, where it causes the device to hang
(Lizhi Hou)
Error handling:
- Clear only error bits in PCIe Device Status to avoid accidentally
clearing Emergency Power Reduction Detected (Shuai Xue)
- Check for AER errors even in devices without drivers (Lukas Wunner)
- Initialize ratelimit info so DPC and EDR paths log AER error
information (Kuppuswamy Sathyanarayanan)
Power control:
- Add UPD720201/UPD720202 USB 3.0 xHCI Host Controller .compatible so
generic pwrctrl driver can control it (Neil Armstrong)
Hotplug:
- Set LED_HW_PLUGGABLE for NPEM hotplug-capable ports so LED core
doesn't complain when setting brightness fails because the endpoint
is gone (Richard Cheng)
Peer-to-peer DMA:
- Allow wildcards in list of host bridges that support peer-to-peer
DMA between hierarchy domains and add all Google SoCs (Jacob
Moroni)
Endpoint framework:
- Advertise dynamic inbound mapping support in pci-epf-test and
update host pci_endpoint_test to skip doorbell testing if not
advertised by endpoint (Koichiro Den)
- Return 0, not remaining timeout, when MHI eDMA ops complete so
mhi_ep_ring_add_element() doesn't interpret non-zero as failure
(Daniel Hodges)
- Remove vntb and ntb duplicate resource teardown that leads to oops
when .allow_link() fails or .drop_link() is called (Koichiro Den)
- Disable vntb delayed work before clearing BAR mappings and
doorbells to avoid oops caused by doing the work after resources
have been torn down (Koichiro Den)
- Add a way to describe reserved subregions within BARs, e.g.,
platform-owned fixed register windows, and use it for the RK3588
BAR4 DMA ctrl window (Koichiro Den)
- Add BAR_DISABLED for BARs that will never be available to an EPF
driver, and change some BAR_RESERVED annotations to BAR_DISABLED
(Niklas Cassel)
- Add NTB .get_dma_dev() callback for cases where DMA API requires a
different device, e.g., vNTB devices (Koichiro Den)
- Add reserved region types for MSI-X Table and PBA so Endpoint
controllers can them as describe hardware-owned regions in a
BAR_RESERVED BAR (Manikanta Maddireddy)
- Make Tegra194/234 BAR0 programmable and remove 1MB size limit
(Manikanta Maddireddy)
- Expose Tegra BAR2 (MSI-X) and BAR4 (DMA) as 64-bit BAR_RESERVED
(Manikanta Maddireddy)
- Add Tegra194 and Tegra234 device table entries to pci_endpoint_test
(Manikanta Maddireddy)
- Skip the BAR subrange selftest if there are not enough inbound
window resources to run the test (Christian Bruel)
New native PCIe controller drivers:
- Add DT binding and driver for Andes QiLai SoC PCIe host controller
(Randolph Lin)
- Add DT binding and driver for ESWIN PCIe Root Complex (Senchuan
Zhang)
Baikal T-1 PCIe controller driver:
- Remove driver since it never quite became usable (Andy Shevchenko)
Cadence PCIe controller driver:
- Implement byte/word config reads with dword (32-bit) reads because
some Cadence controllers don't support sub-dword accesses (Aksh
Garg)
CIX Sky1 PCIe controller driver:
- Add 'power-domains' to DT binding for SCMI power domain (Gary Yang)
Freescale i.MX6 PCIe controller driver:
- Add i.MX94 and i.MX943 to fsl,imx6q-pcie-ep DT binding (Richard
Zhu)
- Delay instead of polling for L2/L3 Ready after PME_Turn_off when
suspending i.MX6SX because LTSSM registers are inaccessible
(Richard Zhu)
- Separate PERST# assertion (for resetting endpoints) from core reset
(for resetting the RC itself) to prepare for new DTs with PERST#
GPIO in per-Root Port nodes (Sherry Sun)
- Retain Root Port MSI capability on i.MX7D, i.MX8MM, and i.MX8MQ so
MSI from downstream devices will work (Richard Zhu)
- Fix i.MX95 reference clock source selection when internal refclk is
used (Franz Schnyder)
Freescale Layerscape PCIe controller driver:
- Allow building as a removable module (Sascha Hauer)
MediaTek PCIe Gen3 controller driver:
- Use dev_err_probe() to simplify error paths and make deferred probe
messages visible in /sys/kernel/debug/devices_deferred (Chen-Yu
Tsai)
- Power off device if setup fails (Chen-Yu Tsai)
- Integrate new pwrctrl API to enable power control for WiFi/BT
adapters on mainboard or in PCIe or M.2 slots (Chen-Yu Tsai)
NVIDIA Tegra194 PCIe controller driver:
- Poll less aggressively and non-atomically for PME_TO_Ack during
transition to L2 (Vidya Sagar)
- Disable LTSSM after transition to Detect on surprise link down to
stop toggling between Polling and Detect (Manikanta Maddireddy)
- Don't force the device into the D0 state before L2 when suspending
or shutting down the controller (Vidya Sagar)
- Disable PERST# IRQ only in Endpoint mode because it's not
registered in Root Port mode (Manikanta Maddireddy)
- Handle 'nvidia,refclk-select' as optional (Vidya Sagar)
- Disable direct speed change in Endpoint mode so link speed change
is controlled by the host (Vidya Sagar)
- Set LTR values before link up to avoid bogus LTR messages with 0
latency (Vidya Sagar)
- Allow system suspend when the Endpoint link is down (Vidya Sagar)
- Use DWC IP core version, not Tegra custom values, to avoid DWC core
version check warnings (Manikanta Maddireddy)
- Apply ECRC workaround to devices based on DesignWare 5.00a as well
as 4.90a (Manikanta Maddireddy)
- Disable PM Substate L1.2 in Endpoint mode to work around Tegra234
erratum (Vidya Sagar)
- Delay post-PERST# cleanup until core is powered on to avoid CBB
timeout (Manikanta Maddireddy)
- Assert CLKREQ# so switches that forward it to their downstream side
can bring up those links successfully (Vidya Sagar)
- Calibrate pipe to UPHY for Endpoint mode to reset stale PLL state
from any previous bad link state (Vidya Sagar)
- Remove IRQF_ONESHOT flag from Endpoint interrupt registration so
DMA driver and Endpoint controller driver can share the interrupt
line (Vidya Sagar)
- Enable DMA interrupt to support DMA in both Root Port and Endpoint
modes (Vidya Sagar)
- Enable hardware link retraining after link goes down in Endpoint
mode (Vidya Sagar)
- Add DT binding and driver support for core clock monitoring (Vidya
Sagar)
Qualcomm PCIe controller driver:
- Advertise 'Hot-Plug Capable' and set 'No Command Completed Support'
since Qcom Root Ports support hotplug events like DL_Up/Down and
can accept writes to Slot Control without delays between writes
(Krishna Chaitanya Chundru)
Renesas R-Car PCIe controller driver:
- Mark Endpoint BAR0 and BAR2 as Resizable (Koichiro Den)
- Reduce EPC BAR alignment requirement to 4K (Koichiro Den)
Renesas RZ/G3S PCIe controller driver:
- Add RZ/G3E to DT binding and to driver (John Madieu)
- Assert (not deassert) resets in probe error path (John Madieu)
- Assert resets in suspend path in reverse order they were deasserted
during probe (John Madieu)
- Rework inbound window algorithm to prevent mapping more than
intended region and enforce alignment on size, to prepare for
RZ/G3E support (John Madieu)
Rockchip DesignWare PCIe controller driver:
- Add tracepoints for PCIe controller LTSSM transitions and link rate
changes (Shawn Lin)
- Trace LTSSM events collected by the dw-rockchip debug FIFO (Shawn
Lin)
SOPHGO PCIe controller driver:
- Disable ASPM L0s and L1 on Sophgo 2042 PCIe Root Ports that
advertise support for them (Yao Zi)
Synopsys DesignWare PCIe controller driver:
- Continue with system suspend even if an Endpoint doesn't respond
with PME_TO_Ack message (Manivannan Sadhasivam)
- Set Endpoint MSI-X Table Size in the correct function of a
multi-function device when configuring MSI-X, not in Function 0
(Aksh Garg)
- Set Max Link Width and Max Link Speed for all functions of a
multi-function device, not just Function 0 (Aksh Garg)
- Expose PCIe event counters in groups 5-7 in debugfs (Hans Zhang)
Miscellaneous:
- Warn only once about invalid ACS kernel parameter format (Richard
Cheng)
- Suppress FW_BUG warning when writing sysfs 'numa_node' with the
current value (Li RongQing)
- Drop redundant 'depends on PCI' from Kconfig (Julian Braha)"
* tag 'pci-v7.1-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci: (165 commits)
PCI/P2PDMA: Add Google SoCs to the P2P DMA host bridge list
PCI/P2PDMA: Allow wildcard Device IDs in host bridge list
PCI: sg2042: Avoid L0s and L1 on Sophgo 2042 PCIe Root Ports
PCI: cadence: Add flags for disabling ASPM capability for broken Root Ports
PCI: tegra194: Add core monitor clock support
dt-bindings: PCI: tegra194: Add monitor clock support
PCI: tegra194: Enable hardware hot reset mode in Endpoint mode
PCI: tegra194: Enable DMA interrupt
PCI: tegra194: Remove IRQF_ONESHOT flag during Endpoint interrupt registration
PCI: tegra194: Calibrate pipe to UPHY for Endpoint mode
PCI: tegra194: Assert CLKREQ# explicitly by default
PCI: tegra194: Fix CBB timeout caused by DBI access before core power-on
PCI: tegra194: Disable L1.2 capability of Tegra234 EP
PCI: dwc: Apply ECRC workaround to DesignWare 5.00a as well
PCI: tegra194: Use DWC IP core version
PCI: tegra194: Free up Endpoint resources during remove()
PCI: tegra194: Allow system suspend when the Endpoint link is not up
PCI: tegra194: Set LTR message request before PCIe link up in Endpoint mode
PCI: tegra194: Disable direct speed change for Endpoint mode
PCI: tegra194: Use devm_gpiod_get_optional() to parse "nvidia,refclk-select"
...
526 lines
13 KiB
C
526 lines
13 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* TPH (TLP Processing Hints) support
|
|
*
|
|
* Copyright (C) 2024 Advanced Micro Devices, Inc.
|
|
* Eric Van Tassell <Eric.VanTassell@amd.com>
|
|
* Wei Huang <wei.huang2@amd.com>
|
|
*/
|
|
#include <linux/pci.h>
|
|
#include <linux/pci-acpi.h>
|
|
#include <linux/msi.h>
|
|
#include <linux/bitfield.h>
|
|
#include <linux/pci-tph.h>
|
|
|
|
#include "pci.h"
|
|
|
|
/* System-wide TPH disabled */
|
|
static bool pci_tph_disabled;
|
|
|
|
#ifdef CONFIG_ACPI
|
|
/*
|
|
* The st_info struct defines the Steering Tag (ST) info returned by the
|
|
* firmware PCI ACPI _DSM method (rev=0x7, func=0xF, "_DSM to Query Cache
|
|
* Locality TPH Features"), as specified in the approved ECN for PCI Firmware
|
|
* Spec and available at https://members.pcisig.com/wg/PCI-SIG/document/15470.
|
|
*
|
|
* @vm_st_valid: 8-bit ST for volatile memory is valid
|
|
* @vm_xst_valid: 16-bit extended ST for volatile memory is valid
|
|
* @vm_ph_ignore: 1 => PH was and will be ignored, 0 => PH should be supplied
|
|
* @vm_st: 8-bit ST for volatile mem
|
|
* @vm_xst: 16-bit extended ST for volatile mem
|
|
* @pm_st_valid: 8-bit ST for persistent memory is valid
|
|
* @pm_xst_valid: 16-bit extended ST for persistent memory is valid
|
|
* @pm_ph_ignore: 1 => PH was and will be ignored, 0 => PH should be supplied
|
|
* @pm_st: 8-bit ST for persistent mem
|
|
* @pm_xst: 16-bit extended ST for persistent mem
|
|
*/
|
|
union st_info {
|
|
struct {
|
|
u64 vm_st_valid : 1;
|
|
u64 vm_xst_valid : 1;
|
|
u64 vm_ph_ignore : 1;
|
|
u64 rsvd1 : 5;
|
|
u64 vm_st : 8;
|
|
u64 vm_xst : 16;
|
|
u64 pm_st_valid : 1;
|
|
u64 pm_xst_valid : 1;
|
|
u64 pm_ph_ignore : 1;
|
|
u64 rsvd2 : 5;
|
|
u64 pm_st : 8;
|
|
u64 pm_xst : 16;
|
|
};
|
|
u64 value;
|
|
};
|
|
|
|
static u16 tph_extract_tag(enum tph_mem_type mem_type, u8 req_type,
|
|
union st_info *info)
|
|
{
|
|
switch (req_type) {
|
|
case PCI_TPH_REQ_TPH_ONLY: /* 8-bit tag */
|
|
switch (mem_type) {
|
|
case TPH_MEM_TYPE_VM:
|
|
if (info->vm_st_valid)
|
|
return info->vm_st;
|
|
break;
|
|
case TPH_MEM_TYPE_PM:
|
|
if (info->pm_st_valid)
|
|
return info->pm_st;
|
|
break;
|
|
}
|
|
break;
|
|
case PCI_TPH_REQ_EXT_TPH: /* 16-bit tag */
|
|
switch (mem_type) {
|
|
case TPH_MEM_TYPE_VM:
|
|
if (info->vm_xst_valid)
|
|
return info->vm_xst;
|
|
break;
|
|
case TPH_MEM_TYPE_PM:
|
|
if (info->pm_xst_valid)
|
|
return info->pm_xst;
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
return 0;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
#define TPH_ST_DSM_FUNC_INDEX 0xF
|
|
static acpi_status tph_invoke_dsm(acpi_handle handle, u32 cpu_uid,
|
|
union st_info *st_out)
|
|
{
|
|
union acpi_object arg3[3], in_obj, *out_obj;
|
|
|
|
if (!acpi_check_dsm(handle, &pci_acpi_dsm_guid, 7,
|
|
BIT(TPH_ST_DSM_FUNC_INDEX)))
|
|
return AE_ERROR;
|
|
|
|
/* DWORD: feature ID (0 for processor cache ST query) */
|
|
arg3[0].integer.type = ACPI_TYPE_INTEGER;
|
|
arg3[0].integer.value = 0;
|
|
|
|
/* DWORD: target UID */
|
|
arg3[1].integer.type = ACPI_TYPE_INTEGER;
|
|
arg3[1].integer.value = cpu_uid;
|
|
|
|
/* QWORD: properties, all 0's */
|
|
arg3[2].integer.type = ACPI_TYPE_INTEGER;
|
|
arg3[2].integer.value = 0;
|
|
|
|
in_obj.type = ACPI_TYPE_PACKAGE;
|
|
in_obj.package.count = ARRAY_SIZE(arg3);
|
|
in_obj.package.elements = arg3;
|
|
|
|
out_obj = acpi_evaluate_dsm(handle, &pci_acpi_dsm_guid, 7,
|
|
TPH_ST_DSM_FUNC_INDEX, &in_obj);
|
|
if (!out_obj)
|
|
return AE_ERROR;
|
|
|
|
if (out_obj->type != ACPI_TYPE_BUFFER) {
|
|
ACPI_FREE(out_obj);
|
|
return AE_ERROR;
|
|
}
|
|
|
|
st_out->value = *((u64 *)(out_obj->buffer.pointer));
|
|
|
|
ACPI_FREE(out_obj);
|
|
|
|
return AE_OK;
|
|
}
|
|
#endif
|
|
|
|
/* Update the TPH Requester Enable field of TPH Control Register */
|
|
static void set_ctrl_reg_req_en(struct pci_dev *pdev, u8 req_type)
|
|
{
|
|
u32 reg;
|
|
|
|
pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CTRL, ®);
|
|
|
|
reg &= ~PCI_TPH_CTRL_REQ_EN_MASK;
|
|
reg |= FIELD_PREP(PCI_TPH_CTRL_REQ_EN_MASK, req_type);
|
|
|
|
pci_write_config_dword(pdev, pdev->tph_cap + PCI_TPH_CTRL, reg);
|
|
}
|
|
|
|
static u8 get_st_modes(struct pci_dev *pdev)
|
|
{
|
|
u32 reg;
|
|
|
|
pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CAP, ®);
|
|
reg &= PCI_TPH_CAP_ST_NS | PCI_TPH_CAP_ST_IV | PCI_TPH_CAP_ST_DS;
|
|
|
|
return reg;
|
|
}
|
|
|
|
/**
|
|
* pcie_tph_get_st_table_loc - Return the device's ST table location
|
|
* @pdev: PCI device to query
|
|
*
|
|
* Return:
|
|
* PCI_TPH_LOC_NONE - Not present
|
|
* PCI_TPH_LOC_CAP - Located in the TPH Requester Extended Capability
|
|
* PCI_TPH_LOC_MSIX - Located in the MSI-X Table
|
|
*/
|
|
u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev)
|
|
{
|
|
u32 reg;
|
|
|
|
pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CAP, ®);
|
|
|
|
return FIELD_GET(PCI_TPH_CAP_LOC_MASK, reg);
|
|
}
|
|
EXPORT_SYMBOL(pcie_tph_get_st_table_loc);
|
|
|
|
/*
|
|
* Return the size of ST table. If ST table is not in TPH Requester Extended
|
|
* Capability space, return 0. Otherwise return the ST Table Size + 1.
|
|
*/
|
|
u16 pcie_tph_get_st_table_size(struct pci_dev *pdev)
|
|
{
|
|
u32 reg;
|
|
u32 loc;
|
|
|
|
/* Check ST table location first */
|
|
loc = pcie_tph_get_st_table_loc(pdev);
|
|
|
|
/* Convert loc to match with PCI_TPH_LOC_* defined in pci_regs.h */
|
|
loc = FIELD_PREP(PCI_TPH_CAP_LOC_MASK, loc);
|
|
if (loc != PCI_TPH_LOC_CAP)
|
|
return 0;
|
|
|
|
pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CAP, ®);
|
|
|
|
return FIELD_GET(PCI_TPH_CAP_ST_MASK, reg) + 1;
|
|
}
|
|
EXPORT_SYMBOL(pcie_tph_get_st_table_size);
|
|
|
|
/* Return device's Root Port completer capability */
|
|
static u8 get_rp_completer_type(struct pci_dev *pdev)
|
|
{
|
|
struct pci_dev *rp;
|
|
u32 reg;
|
|
int ret;
|
|
|
|
rp = pcie_find_root_port(pdev);
|
|
if (!rp)
|
|
return 0;
|
|
|
|
ret = pcie_capability_read_dword(rp, PCI_EXP_DEVCAP2, ®);
|
|
if (ret)
|
|
return 0;
|
|
|
|
return FIELD_GET(PCI_EXP_DEVCAP2_TPH_COMP_MASK, reg);
|
|
}
|
|
|
|
/* Write tag to ST table - Return 0 if OK, otherwise -errno */
|
|
static int write_tag_to_st_table(struct pci_dev *pdev, int index, u16 tag)
|
|
{
|
|
int st_table_size;
|
|
int offset;
|
|
|
|
/* Check if index is out of bound */
|
|
st_table_size = pcie_tph_get_st_table_size(pdev);
|
|
if (index >= st_table_size)
|
|
return -ENXIO;
|
|
|
|
offset = pdev->tph_cap + PCI_TPH_BASE_SIZEOF + index * sizeof(u16);
|
|
|
|
return pci_write_config_word(pdev, offset, tag);
|
|
}
|
|
|
|
/**
|
|
* pcie_tph_get_cpu_st() - Retrieve Steering Tag for a target memory associated
|
|
* with a specific CPU
|
|
* @pdev: PCI device
|
|
* @mem_type: target memory type (volatile or persistent RAM)
|
|
* @cpu: associated CPU id
|
|
* @tag: Steering Tag to be returned
|
|
*
|
|
* Return the Steering Tag for a target memory that is associated with a
|
|
* specific CPU as indicated by cpu.
|
|
*
|
|
* Return: 0 if success, otherwise negative value (-errno)
|
|
*/
|
|
int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type,
|
|
unsigned int cpu, u16 *tag)
|
|
{
|
|
#ifdef CONFIG_ACPI
|
|
struct pci_dev *rp;
|
|
acpi_handle rp_acpi_handle;
|
|
union st_info info;
|
|
u32 cpu_uid;
|
|
int ret;
|
|
|
|
ret = acpi_get_cpu_uid(cpu, &cpu_uid);
|
|
if (ret != 0)
|
|
return ret;
|
|
|
|
rp = pcie_find_root_port(pdev);
|
|
if (!rp || !rp->bus || !rp->bus->bridge)
|
|
return -ENODEV;
|
|
|
|
rp_acpi_handle = ACPI_HANDLE(rp->bus->bridge);
|
|
|
|
if (tph_invoke_dsm(rp_acpi_handle, cpu_uid, &info) != AE_OK) {
|
|
*tag = 0;
|
|
return -EINVAL;
|
|
}
|
|
|
|
*tag = tph_extract_tag(mem_type, pdev->tph_req_type, &info);
|
|
|
|
pci_dbg(pdev, "get steering tag: mem_type=%s, cpu=%d, tag=%#04x\n",
|
|
(mem_type == TPH_MEM_TYPE_VM) ? "volatile" : "persistent",
|
|
cpu, *tag);
|
|
|
|
return 0;
|
|
#else
|
|
return -ENODEV;
|
|
#endif
|
|
}
|
|
EXPORT_SYMBOL(pcie_tph_get_cpu_st);
|
|
|
|
/**
|
|
* pcie_tph_set_st_entry() - Set Steering Tag in the ST table entry
|
|
* @pdev: PCI device
|
|
* @index: ST table entry index
|
|
* @tag: Steering Tag to be written
|
|
*
|
|
* Figure out the proper location of ST table, either in the MSI-X table or
|
|
* in the TPH Extended Capability space, and write the Steering Tag into
|
|
* the ST entry pointed by index.
|
|
*
|
|
* Return: 0 if success, otherwise negative value (-errno)
|
|
*/
|
|
int pcie_tph_set_st_entry(struct pci_dev *pdev, unsigned int index, u16 tag)
|
|
{
|
|
u32 loc;
|
|
int err = 0;
|
|
|
|
if (!pdev->tph_cap)
|
|
return -EINVAL;
|
|
|
|
if (!pdev->tph_enabled)
|
|
return -EINVAL;
|
|
|
|
/* No need to write tag if device is in "No ST Mode" */
|
|
if (pdev->tph_mode == PCI_TPH_ST_NS_MODE)
|
|
return 0;
|
|
|
|
/*
|
|
* Disable TPH before updating ST to avoid potential instability as
|
|
* cautioned in PCIe r6.2, sec 6.17.3, "ST Modes of Operation"
|
|
*/
|
|
set_ctrl_reg_req_en(pdev, PCI_TPH_REQ_DISABLE);
|
|
|
|
loc = pcie_tph_get_st_table_loc(pdev);
|
|
/* Convert loc to match with PCI_TPH_LOC_* */
|
|
loc = FIELD_PREP(PCI_TPH_CAP_LOC_MASK, loc);
|
|
|
|
switch (loc) {
|
|
case PCI_TPH_LOC_MSIX:
|
|
err = pci_msix_write_tph_tag(pdev, index, tag);
|
|
break;
|
|
case PCI_TPH_LOC_CAP:
|
|
err = write_tag_to_st_table(pdev, index, tag);
|
|
break;
|
|
default:
|
|
err = -EINVAL;
|
|
}
|
|
|
|
if (err) {
|
|
pcie_disable_tph(pdev);
|
|
return err;
|
|
}
|
|
|
|
set_ctrl_reg_req_en(pdev, pdev->tph_req_type);
|
|
|
|
pci_dbg(pdev, "set steering tag: %s table, index=%d, tag=%#04x\n",
|
|
(loc == PCI_TPH_LOC_MSIX) ? "MSI-X" : "ST", index, tag);
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(pcie_tph_set_st_entry);
|
|
|
|
/**
|
|
* pcie_disable_tph - Turn off TPH support for device
|
|
* @pdev: PCI device
|
|
*
|
|
* Return: none
|
|
*/
|
|
void pcie_disable_tph(struct pci_dev *pdev)
|
|
{
|
|
if (!pdev->tph_cap)
|
|
return;
|
|
|
|
if (!pdev->tph_enabled)
|
|
return;
|
|
|
|
pci_write_config_dword(pdev, pdev->tph_cap + PCI_TPH_CTRL, 0);
|
|
|
|
pdev->tph_mode = 0;
|
|
pdev->tph_req_type = 0;
|
|
pdev->tph_enabled = 0;
|
|
}
|
|
EXPORT_SYMBOL(pcie_disable_tph);
|
|
|
|
/**
|
|
* pcie_enable_tph - Enable TPH support for device using a specific ST mode
|
|
* @pdev: PCI device
|
|
* @mode: ST mode to enable. Current supported modes include:
|
|
*
|
|
* - PCI_TPH_ST_NS_MODE: NO ST Mode
|
|
* - PCI_TPH_ST_IV_MODE: Interrupt Vector Mode
|
|
* - PCI_TPH_ST_DS_MODE: Device Specific Mode
|
|
*
|
|
* Check whether the mode is actually supported by the device before enabling
|
|
* and return an error if not. Additionally determine what types of requests,
|
|
* TPH or extended TPH, can be issued by the device based on its TPH requester
|
|
* capability and the Root Port's completer capability.
|
|
*
|
|
* Return: 0 on success, otherwise negative value (-errno)
|
|
*/
|
|
int pcie_enable_tph(struct pci_dev *pdev, int mode)
|
|
{
|
|
u32 reg;
|
|
u8 dev_modes;
|
|
u8 rp_req_type;
|
|
|
|
/* Honor "notph" kernel parameter */
|
|
if (pci_tph_disabled)
|
|
return -EINVAL;
|
|
|
|
if (!pdev->tph_cap)
|
|
return -EINVAL;
|
|
|
|
if (pdev->tph_enabled)
|
|
return -EBUSY;
|
|
|
|
/* Sanitize and check ST mode compatibility */
|
|
mode &= PCI_TPH_CTRL_MODE_SEL_MASK;
|
|
dev_modes = get_st_modes(pdev);
|
|
if (!((1 << mode) & dev_modes))
|
|
return -EINVAL;
|
|
|
|
pdev->tph_mode = mode;
|
|
|
|
/* Get req_type supported by device and its Root Port */
|
|
pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CAP, ®);
|
|
if (FIELD_GET(PCI_TPH_CAP_EXT_TPH, reg))
|
|
pdev->tph_req_type = PCI_TPH_REQ_EXT_TPH;
|
|
else
|
|
pdev->tph_req_type = PCI_TPH_REQ_TPH_ONLY;
|
|
|
|
/* Check if the device is behind a Root Port */
|
|
if (pci_pcie_type(pdev) != PCI_EXP_TYPE_RC_END) {
|
|
rp_req_type = get_rp_completer_type(pdev);
|
|
|
|
/* Final req_type is the smallest value of two */
|
|
pdev->tph_req_type = min(pdev->tph_req_type, rp_req_type);
|
|
}
|
|
|
|
if (pdev->tph_req_type == PCI_TPH_REQ_DISABLE)
|
|
return -EINVAL;
|
|
|
|
/* Write them into TPH control register */
|
|
pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CTRL, ®);
|
|
|
|
reg &= ~PCI_TPH_CTRL_MODE_SEL_MASK;
|
|
reg |= FIELD_PREP(PCI_TPH_CTRL_MODE_SEL_MASK, pdev->tph_mode);
|
|
|
|
reg &= ~PCI_TPH_CTRL_REQ_EN_MASK;
|
|
reg |= FIELD_PREP(PCI_TPH_CTRL_REQ_EN_MASK, pdev->tph_req_type);
|
|
|
|
pci_write_config_dword(pdev, pdev->tph_cap + PCI_TPH_CTRL, reg);
|
|
|
|
pdev->tph_enabled = 1;
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(pcie_enable_tph);
|
|
|
|
void pci_restore_tph_state(struct pci_dev *pdev)
|
|
{
|
|
struct pci_cap_saved_state *save_state;
|
|
int num_entries, i, offset;
|
|
u16 *st_entry;
|
|
u32 *cap;
|
|
|
|
if (!pdev->tph_cap)
|
|
return;
|
|
|
|
if (!pdev->tph_enabled)
|
|
return;
|
|
|
|
save_state = pci_find_saved_ext_cap(pdev, PCI_EXT_CAP_ID_TPH);
|
|
if (!save_state)
|
|
return;
|
|
|
|
/* Restore control register and all ST entries */
|
|
cap = &save_state->cap.data[0];
|
|
pci_write_config_dword(pdev, pdev->tph_cap + PCI_TPH_CTRL, *cap++);
|
|
st_entry = (u16 *)cap;
|
|
offset = PCI_TPH_BASE_SIZEOF;
|
|
num_entries = pcie_tph_get_st_table_size(pdev);
|
|
for (i = 0; i < num_entries; i++) {
|
|
pci_write_config_word(pdev, pdev->tph_cap + offset,
|
|
*st_entry++);
|
|
offset += sizeof(u16);
|
|
}
|
|
}
|
|
|
|
void pci_save_tph_state(struct pci_dev *pdev)
|
|
{
|
|
struct pci_cap_saved_state *save_state;
|
|
int num_entries, i, offset;
|
|
u16 *st_entry;
|
|
u32 *cap;
|
|
|
|
if (!pdev->tph_cap)
|
|
return;
|
|
|
|
if (!pdev->tph_enabled)
|
|
return;
|
|
|
|
save_state = pci_find_saved_ext_cap(pdev, PCI_EXT_CAP_ID_TPH);
|
|
if (!save_state)
|
|
return;
|
|
|
|
/* Save control register */
|
|
cap = &save_state->cap.data[0];
|
|
pci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CTRL, cap++);
|
|
|
|
/* Save all ST entries in extended capability structure */
|
|
st_entry = (u16 *)cap;
|
|
offset = PCI_TPH_BASE_SIZEOF;
|
|
num_entries = pcie_tph_get_st_table_size(pdev);
|
|
for (i = 0; i < num_entries; i++) {
|
|
pci_read_config_word(pdev, pdev->tph_cap + offset,
|
|
st_entry++);
|
|
offset += sizeof(u16);
|
|
}
|
|
}
|
|
|
|
void pci_no_tph(void)
|
|
{
|
|
pci_tph_disabled = true;
|
|
|
|
pr_info("PCIe TPH is disabled\n");
|
|
}
|
|
|
|
void pci_tph_init(struct pci_dev *pdev)
|
|
{
|
|
int num_entries;
|
|
u32 save_size;
|
|
|
|
pdev->tph_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_TPH);
|
|
if (!pdev->tph_cap)
|
|
return;
|
|
|
|
num_entries = pcie_tph_get_st_table_size(pdev);
|
|
save_size = sizeof(u32) + num_entries * sizeof(u16);
|
|
pci_add_ext_cap_save_buffer(pdev, PCI_EXT_CAP_ID_TPH, save_size);
|
|
}
|