From d33a8afc755e9ff99f72be9a0c401d6a295d8d14 Mon Sep 17 00:00:00 2001 From: Rong Liu Date: Thu, 10 Jun 2021 06:34:31 +0000 Subject: [PATCH] dm: get native rootport's max payload Get and save native root port's max payload in dev cap register in vrp_config data structure which will be used to configure vrp's max payload by hv. Tracked-On: #5915 Signed-off-by: Rong Liu Reviewed-by: Jason Chen CJ --- devicemodel/hw/pci/ptm.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/devicemodel/hw/pci/ptm.c b/devicemodel/hw/pci/ptm.c index 4a0d18bc3..199ad0db7 100644 --- a/devicemodel/hw/pci/ptm.c +++ b/devicemodel/hw/pci/ptm.c @@ -66,6 +66,8 @@ static int add_vroot_port(struct vmctx *ctx, struct passthru_dev *ptdev, struct pci_device *root_port, int ptm_cap_offset) { int error = 0; + int offset = 0; + uint32_t dev_cap = 0; struct acrn_emul_dev rp_vdev = {}; struct vrp_config *rp_priv = (struct vrp_config *)&rp_vdev.args; @@ -89,8 +91,19 @@ add_vroot_port(struct vmctx *ctx, struct passthru_dev *ptdev, struct pci_device rp_priv->ptm_cap_offset = ptm_cap_offset; - pr_info("%s: virtual root port info: vbdf=0x%x, phy_bdf=0x%x, prim_bus=%x, sec_bus=%x, sub_bus=%x, ptm_cpa_offset=0x%x.\n", __func__, - rp_vdev.slot, rp_priv->phy_bdf, rp_priv->primary_bus, rp_priv->secondary_bus, rp_priv->subordinate_bus, rp_priv->ptm_cap_offset); + /* It seems important that passthru device's max payload settings match + * the settings on the native device otherwise passthru device may not work. + * So we have to set vrp's max payload capacity the same as native root port + * otherwise we may accidentally change passthru device's max payload since + * during guest OS's pci enumeration, pass-thru device will renegotiate + * its max payload's setting with vrp. + */ + offset = pci_find_cap(root_port, PCIY_EXPRESS); + pci_device_cfg_read_u32(root_port, &dev_cap, offset + PCIER_DEVICE_CAP); + rp_priv->max_payload = dev_cap & PCIEM_CAP_MAX_PAYLOAD; + pr_info("%s: virtual root port info: vbdf=0x%x, phy_bdf=0x%x, prim_bus=%x, sec_bus=%x, sub_bus=%x, ptm_cpa_offset=0x%x, max_payload=0x%x.\n", + __func__, rp_vdev.slot, rp_priv->phy_bdf, rp_priv->primary_bus, rp_priv->secondary_bus, rp_priv->subordinate_bus, + rp_priv->ptm_cap_offset, rp_priv->max_payload); error = vm_add_hv_vdev(ctx, &rp_vdev); if (error) {