All of lore.kernel.org
 help / color / mirror / Atom feed
From: Caleb Schlossin <calebs@linux.ibm.com>
To: Saif Abrar <saif.abrar@linux.ibm.com>,
	qemu-ppc@nongnu.org, qemu-devel@nongnu.org
Cc: harshpb@linux.ibm.com, clg@kaod.org, npiggin@gmail.com,
	fbarrat@linux.ibm.com, mst@redhat.com,
	marcel.apfelbaum@gmail.com, cohuck@redhat.com,
	pbonzini@redhat.com, thuth@redhat.com, lvivier@redhat.com,
	danielhb413@gmail.com, kowal@linux.ibm.com,
	chalapathi.v@linux.ibm.com, milesg@linux.ibm.com,
	jishnuvw@linux.ibm.com, adityag@linux.ibm.com,
	amachhiw@linux.ibm.com
Subject: Re: [PATCH v5 6/9] pnv/phb5: Set link-active status in HPSTAT and LMR registers
Date: Tue, 23 Jun 2026 15:43:39 -0500	[thread overview]
Message-ID: <3889e623-d5fb-4d13-b192-01bae5e95a06@linux.ibm.com> (raw)
In-Reply-To: <20260617095058.652789-7-saif.abrar@linux.ibm.com>

Reviewed-by: Caleb Schlossin <calebs@linux.ibm.com>

On 6/17/26 4:50 AM, Saif Abrar wrote:
> From: Saif Abrar <saif.abrar@linux.vnet.ibm.com>
> 
> Config-read the link-status register in the PCI-E macro,
> Depending on the link-active bit, set the link-active status
> in the HOTPLUG_STATUS and LINK_MANAGEMENT registers
> Also, clear the Presence-status active low bit in HOTPLUG_STATUS reg
> after config-reading the slot-status in the PCI-E macro.
> 
> Signed-off-by: Saif Abrar <saif.abrar@linux.ibm.com>
> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> Reviewed-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
> Reviewed-by: Aditya Gupta <adityag@linux.ibm.com>
> Reviewed-by: Jishnu Warrier <Jishnu.Warrier@ibm.com>
> ---
> v5: Using be16_to_cpu as required.
> v4: Variables declaration moved to the top of the method pnv_phb4_reg_read().
> v3: Updates for coding guidelines.
> 
> 
>  hw/pci-host/pnv_phb4.c | 61 +++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 60 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c
> index 838f9d3c23..125f610790 100644
> --- a/hw/pci-host/pnv_phb4.c
> +++ b/hw/pci-host/pnv_phb4.c
> @@ -511,6 +511,21 @@ static uint32_t get_exp_offset(PCIDevice *pdev)
>      return rpc->exp_offset;
>  }
>  
> +/*
> + * Config-read the link-status register in the PCI-E macro,
> + * convert to LE and check the link-active bit.
> + */
> +static uint32_t is_link_active(PnvPHB4 *phb)
> +{
> +    PCIHostState *pci = PCI_HOST_BRIDGE(phb->phb_base);
> +    PCIDevice *pdev = pci_find_device(pci->bus, 0, 0);
> +    uint32_t exp_offset = get_exp_offset(pdev);
> +
> +    return (be16_to_cpu(pnv_phb4_rc_config_read(phb,
> +                        exp_offset + PCI_EXP_LNKSTA, 4)) &
> +                        PCI_EXP_LNKSTA_DLLLA);
> +}
> +
>  /*
>   * Apply sticky-mask 's' to the reset-value 'v' and write to the address 'a'.
>   * RC-config space values and masks are LE.
> @@ -727,6 +742,11 @@ static void pnv_phb4_reg_write(void *opaque, hwaddr off, uint64_t val,
>          val = 0;
>          break;
>  
> +    case PHB_PCIE_HOTPLUG_STATUS:
> +        /* For normal operations, Simspeed diagnostic bit is always zero */
> +        val &= PHB_PCIE_HPSTAT_SIMDIAG;
> +        break;
> +
>      /* Read only registers */
>      case PHB_CPU_LOADSTORE_STATUS:
>      case PHB_ETU_ERR_SUMMARY:
> @@ -874,6 +894,10 @@ static void pnv_phb4_reg_write(void *opaque, hwaddr off, uint64_t val,
>  static uint64_t pnv_phb4_reg_read(void *opaque, hwaddr off, unsigned size)
>  {
>      PnvPHB4 *phb = PNV_PHB4(opaque);
> +    /* Get the PCI-E capability offset from the root-port */
> +    PCIHostState *pci = PCI_HOST_BRIDGE(phb->phb_base);
> +    PCIDevice *pdev = pci_find_device(pci->bus, 0, 0);
> +    uint32_t exp_base = get_exp_offset(pdev);
>      uint64_t val;
>  
>      if ((off & 0xfffc) == PHB_CONFIG_DATA) {
> @@ -942,8 +966,38 @@ static uint64_t pnv_phb4_reg_read(void *opaque, hwaddr off, unsigned size)
>          val |= PHB_PCIE_DLP_INBAND_PRESENCE | PHB_PCIE_DLP_TL_LINKACT;
>          return val;
>  
> +    /*
> +     * Read PCI-E registers and set status for:
> +     * - Card present (active low bit 10)
> +     * - Link active  (bit 12)
> +     */
>      case PHB_PCIE_HOTPLUG_STATUS:
> -        /* Clear write-only bit */
> +        /*
> +         * Presence-status bit hpi_present_n is active-low, with reset value 1.
> +         * Start by setting this bit to 1, indicating the card is not present.
> +         * Then check the PCI-E register and clear the bit if card is present.
> +         */
> +        val |= PHB_PCIE_HPSTAT_PRESENCE;
> +
> +        /*
> +         * Config-read the PCI-E macro register for slot-status.
> +         * Method for config-read converts to BE value.
> +         * To check actual bit in the PCI-E register,
> +         * convert the value back to host format.
> +         * Clear the Presence-status active low bit.
> +         */
> +        if (be16_to_cpu(pnv_phb4_rc_config_read(phb, exp_base + PCI_EXP_SLTSTA,
> +                                                4))
> +                    & PCI_EXP_SLTSTA_PDS) {
> +            val &= ~PHB_PCIE_HPSTAT_PRESENCE;
> +        }
> +
> +        /* Check if link is active and set the bit */
> +        if (is_link_active(phb)) {
> +            val |= PHB_PCIE_HPSTAT_LINKACTIVE;
> +        }
> +
> +        /* Clear write-only resample-bit */
>          val &= ~PHB_PCIE_HPSTAT_RESAMPLE;
>          return val;
>  
> @@ -951,6 +1005,11 @@ static uint64_t pnv_phb4_reg_read(void *opaque, hwaddr off, unsigned size)
>      case PHB_PCIE_LMR:
>          /* These write-only bits always read as 0 */
>          val &= ~(PHB_PCIE_LMR_CHANGELW | PHB_PCIE_LMR_RETRAINLINK);
> +
> +        /* Check if link is active and set the bit */
> +        if (is_link_active(phb)) {
> +            val |= PHB_PCIE_LMR_LINKACTIVE;
> +        }
>          return val;
>  
>      /* Silent simple reads */



  reply	other threads:[~2026-06-23 20:44 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-17  9:50 [PATCH v5 0/9] pnv/phb5: Update PHB4 to the latest PHB5 spec Saif Abrar
2026-06-17  9:50 ` [PATCH v5 1/9] qtest/phb5: Add testbench for PHB Saif Abrar
2026-06-23 18:24   ` Caleb Schlossin
2026-06-25 17:02   ` Aditya Gupta
2026-06-17  9:50 ` [PATCH v5 2/9] pnv/phb5: Add reset logic to PHB5 Saif Abrar
2026-06-23 18:24   ` Caleb Schlossin
2026-06-17  9:50 ` [PATCH v5 3/9] pnv/phb5: Implement sticky reset logic in PHB5 Saif Abrar
2026-06-23 18:42   ` Caleb Schlossin
2026-06-17  9:50 ` [PATCH v5 4/9] pnv/phb5: Implement read-only and write-only bits of registers Saif Abrar
2026-06-23 18:52   ` Caleb Schlossin
2026-06-17  9:50 ` [PATCH v5 5/9] pnv/phb5: Implement write-clear and return 1's on unimplemented reg read Saif Abrar
2026-06-23 18:53   ` Caleb Schlossin
2026-06-17  9:50 ` [PATCH v5 6/9] pnv/phb5: Set link-active status in HPSTAT and LMR registers Saif Abrar
2026-06-23 20:43   ` Caleb Schlossin [this message]
2026-06-17  9:50 ` [PATCH v5 7/9] pnv/phb5: Set link speed and width in the DLP training control register Saif Abrar
2026-06-23 20:43   ` Caleb Schlossin
2026-06-17  9:50 ` [PATCH v5 8/9] pnv/phb5: Implement IODA PCT table Saif Abrar
2026-06-23 20:44   ` Caleb Schlossin
2026-06-29 11:08   ` Aditya Gupta
2026-06-17  9:50 ` [PATCH v5 9/9] pnv/phb5: Mask off LSI Source-ID based on number of interrupts Saif Abrar
2026-06-23 20:44   ` Caleb Schlossin
2026-06-24  4:47 ` [PATCH v5 0/9] pnv/phb5: Update PHB4 to the latest PHB5 spec Harsh Prateek Bora
2026-06-25  8:02 ` Aditya Gupta
2026-06-30 10:22 ` Saif Abrar
2026-06-30 13:39   ` Michael S. Tsirkin
2026-06-30 14:47   ` Cédric Le Goater

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3889e623-d5fb-4d13-b192-01bae5e95a06@linux.ibm.com \
    --to=calebs@linux.ibm.com \
    --cc=adityag@linux.ibm.com \
    --cc=amachhiw@linux.ibm.com \
    --cc=chalapathi.v@linux.ibm.com \
    --cc=clg@kaod.org \
    --cc=cohuck@redhat.com \
    --cc=danielhb413@gmail.com \
    --cc=fbarrat@linux.ibm.com \
    --cc=harshpb@linux.ibm.com \
    --cc=jishnuvw@linux.ibm.com \
    --cc=kowal@linux.ibm.com \
    --cc=lvivier@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=milesg@linux.ibm.com \
    --cc=mst@redhat.com \
    --cc=npiggin@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=saif.abrar@linux.ibm.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.