* Re: [PATCH] scsi: qla2xxx: Take the port from ISP control/status
2026-12-03 9:17 [PATCH] scsi: qla2xxx: Take the port from ISP control/status Nilesh Javali
@ 2026-12-03 9:40 ` sashiko-bot
2026-12-03 13:24 ` Laurence Oberman
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-03 9:40 UTC (permalink / raw)
To: Nilesh Javali; +Cc: linux-scsi
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] scsi: qla2xxx: qla2x00_port_no_from_csrx() sets wrong portnum
on ISP8031
- [Medium] scsi: qla2xxx: PCI_FUNC() gate in qla2x00_port_no_from_csrx()
breaks VFIO
- [Low] scsi: qla2xxx: missing ISP_REG_DISCONNECT check in
qla2x00_port_no_from_csrx()
- [Low] scsi: qla2xxx: reused ql_log message IDs in
qla2x00_port_no_from_csrx()
--
commit 4028d2e2495092c9c8d80dc38a6aef6e800678b4
Author: Nilesh Javali <njavali@marvell.com>
scsi: qla2xxx: Take the port from ISP control/status
This commit adds qla2x00_port_no_from_csrx() to derive ha->port_no from
the ISP ctrl_status register after iospace_config() when PCI_INTERRUPT_PIN
and PCI_FUNC() are both zero, and drops the unused ha->portnum assignment
for 27xx/28xx/29xx.
> diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
> index 3c412c7fb6fe7..4ca54bc09c58c 100644
> --- a/drivers/scsi/qla2xxx/qla_os.c
> +++ b/drivers/scsi/qla2xxx/qla_os.c
> @@ -2704,6 +2704,66 @@ static struct isp_operations qla29xx_isp_ops = {
[ ... ]
> +static void
> +qla2x00_port_no_from_csrx(struct qla_hw_data *ha)
> +{
> + struct device_reg_24xx __iomem *reg;
> + u32 csr, port;
> + u8 pin = 0;
> +
> + if (!IS_FWI2_CAPABLE(ha) || IS_P3P_TYPE(ha) || !ha->iobase)
> + return;
> +
> + pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &pin);
> + if (pin || PCI_FUNC(ha->pdev->devfn))
> + return;
[Severity: Medium]
Can gating on PCI_FUNC(ha->pdev->devfn) cause port_no collisions under
multi-function VFIO passthrough?
When vfio_config_init() virtualizes PCI_INTERRUPT_PIN to 0, guest function
0 reads ctrl_status here while non-zero guest functions keep the virtual
PCI_FUNC() assigned in qla2x00_set_isp_flags().
If physical ports 1 and 0 are passed as guest .0 and .1, both get
ha->port_no == 1, read the same NVRAM/VPD, and log in with duplicate
WWPNs. On ISP8031 FCoE functions (2 and 3), keeping PCI_FUNC() misses
FLT_REG_FCOE_NVRAM_0/1 in qla2xxx_get_flt_info().
Bare-metal adapters have a non-zero PCI_INTERRUPT_PIN, so checking only
if (pin) would preserve bare metal while resolving all VFIO functions from
ctrl_status consistently.
> +
> + reg = &ha->iobase->isp24;
> + csr = rd_reg_dword(®->ctrl_status);
[Severity: Low]
Should csr be checked against ISP_REG_DISCONNECT (0xffffffffU) before
decoding the port bits?
Under Hyper-V DDA, hv_pci_read_config() emulates PCI_INTERRUPT_PIN as 0,
so probe reaches rd_reg_dword(®->ctrl_status) even on a disconnected
link. 27xx/28xx/29xx reject 0xffffffffU as out of range, but other FWI2
adapters see CSRX_FUNCTION set and silently set ha->port_no/portnum to 1.
> +
> + if (IS_QLA27XX(ha) || IS_QLA28XX(ha) || IS_QLA29XX(ha)) {
> + port = (csr & CSRX_PORT_MASK) >> CSRX_PORT_SHIFT;
> + if (port > 3) {
> + ql_log_pci(ql_log_warn, ha->pdev, 0x00e2,
> + "port %u from ctrl_status=0x%x is out of range.\n",
> + port, csr);
> + return;
> + }
> + ha->port_no = port;
> + ql_log_pci(ql_log_info, ha->pdev, 0x00e1,
> + "port %u ctrl_status=0x%x replaces the INTx pin.\n",
> + port, csr);
> + return;
> + }
> +
> + ha->port_no = (csr & CSRX_FUNCTION) ? 1 : 0;
> + ha->portnum = ha->port_no;
[Severity: Medium]
Can setting ha->portnum = ha->port_no corrupt shared IDC state on ISP8031?
On ISP8031 CNAs, ha->portnum is the physical PCI function ID, not the 0/1
FCoE port index: functions 0 and 1 are NIC functions (qlcnic), while FCoE
uses higher functions in QLA83XX_DEV_PARTINFO1/2. Setting ha->portnum = 1
collides with NIC function 1 in shared IDC presence and lock registers.
When both FCoE ports are passed through without NIC drivers, bits 0 and 1
are set in QLA83XX_IDC_DRV_PRESENCE while qla83xx_reset_ownership() masks
only ha->portnum and the real FCoE function, so neither port becomes
nic_core_reset_owner and NIC core reset times out into QLA8XXX_DEV_FAILED.
Only IS_QLA2031(ha) maps FC ports 0 and 1 to PCI functions 0 and 1, so
this assignment should exclude IS_QLA8031(ha).
> + if (IS_QLA25XX(ha))
> + ql_log_pci(ql_log_info, ha->pdev, 0x00e1,
> + "25xx port %u ctrl_status=0x%x replaces the INTx pin.\n",
> + ha->port_no, csr);
> + else
> + ql_log_pci(ql_log_info, ha->pdev, 0x00e1,
> + "pin and function are 0; ctrl_status=0x%x port=%u.\n",
> + csr, ha->port_no);
> +}
[Severity: Low]
Do these ql_log_pci() calls reuse already-allocated message IDs 0x00e1 and
0x00e2?
Both IDs are already used in drivers/scsi/qla2xxx/qla_mid.c
(qla25xx_create_rsp_que()), and the Module Init and Probe table in
drivers/scsi/qla2xxx/qla_dbg.c is allocated through 0x0199. New probe
messages should use fresh IDs past 0x0199 and update that table.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203091740.6044-1-njavali@marvell.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] scsi: qla2xxx: Take the port from ISP control/status
2026-12-03 9:17 [PATCH] scsi: qla2xxx: Take the port from ISP control/status Nilesh Javali
2026-12-03 9:40 ` sashiko-bot
@ 2026-12-03 13:24 ` Laurence Oberman
1 sibling, 0 replies; 3+ messages in thread
From: Laurence Oberman @ 2026-12-03 13:24 UTC (permalink / raw)
To: Nilesh Javali, mkp
Cc: linux-scsi, GR-FC-Storage-Upstream, emilne, jmeneghi, hare
On Thu, 2026-12-03 at 14:47 +0530, Nilesh Javali wrote:
> Hyper-V DDA forces PCI_INTERRUPT_PIN to 0 and presents every function
> as function 0, so every port selects port 0 NVRAM and the same WWPN.
> A wider PCI config read of the pin is not usable: pci-hyperv clears
> that byte at any access width.
>
> Read the port from the passed-through control/status register. On
> 27xx/28xx/29xx bits 15:12 are the physical port 0-3. On 25xx the port
> is bit 15. Replace port_no from ctrl_status only when the INTx pin
> and
> PCI function are both zero; bare metal keeps the value from
> PCI_INTERRUPT_PIN when the pin is valid. Other FWI2 adapters use bit
> 15
> under the same condition and store that value in portnum.
> 27xx/28xx/29xx
> do not use portnum.
>
> Cc: stable@vger.kernel.org
> Fixes: 7268e509b43a ("scsi: qla2xxx: Handle INTx not connected while
> passing through")
> Signed-off-by: Nilesh Javali <njavali@marvell.com>
> ---
> drivers/scsi/qla2xxx/qla_fw.h | 5 ++-
> drivers/scsi/qla2xxx/qla_os.c | 72
> +++++++++++++++++++++++++++++++++--
> 2 files changed, 72 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/scsi/qla2xxx/qla_fw.h
> b/drivers/scsi/qla2xxx/qla_fw.h
> index 98bc4a57b59b..400088e0a9e7 100644
> --- a/drivers/scsi/qla2xxx/qla_fw.h
> +++ b/drivers/scsi/qla2xxx/qla_fw.h
> @@ -1173,7 +1173,10 @@ struct device_reg_24xx {
> #define CSRX_FLASH_ACCESS_ERROR BIT_18 /* Flash/NVRAM
> Access Error. */
> #define CSRX_DMA_ACTIVE BIT_17 /* DMA Active
> status. */
> #define CSRX_DMA_SHUTDOWN BIT_16 /* DMA Shutdown control
> status. */
> -#define CSRX_FUNCTION BIT_15 /* Function number. */
> +#define CSRX_FUNCTION BIT_15 /* 24xx function 0 or 1. */
> +/* Physical port 0-3 on 27xx/28xx/29xx. */
> +#define CSRX_PORT_MASK (BIT_15 | BIT_14 | BIT_13 | BIT_12)
> +#define CSRX_PORT_SHIFT 12
> /* PCI-X Bus Mode. */
> #define CSRX_PCIX_BUS_MODE_MASK (BIT_11|BIT_10|BIT_9|BIT_8)
> #define PBM_PCI_33MHZ (0 << 8)
> diff --git a/drivers/scsi/qla2xxx/qla_os.c
> b/drivers/scsi/qla2xxx/qla_os.c
> index 71fdac896a59..78fe267238d6 100644
> --- a/drivers/scsi/qla2xxx/qla_os.c
> +++ b/drivers/scsi/qla2xxx/qla_os.c
> @@ -2704,6 +2704,66 @@ static struct isp_operations qla29xx_isp_ops =
> {
> .initialize_adapter = qla2x00_initialize_adapter,
> };
>
> +/*
> + * Physical port from the ISP control/status register.
> + *
> + * The register is in the MMIO block mapped by iospace_config (BAR0
> on
> + * 27xx/28xx/29xx, BAR1 on 25xx). Hyper-V does not emulate it, so it
> + * still names the port when DDA presents every function as function
> 0
> + * and forces PCI_INTERRUPT_PIN to 0.
> + *
> + * 27xx/28xx/29xx use ctrl_status[15:12] for physical port 0-3 when
> the
> + * INTx pin and PCI function are both 0. 25xx uses bit 15 (function
> 0
> + * or 1) under the same condition; bits 14:12 are not a port number
> on
> + * that chip. Other FWI2 adapters use bit 15 under the same
> condition.
> + * Read this after
> + * iospace_config() and before qla24xx_reset_risc() writes
> + * ctrl_status. Do not decrement.
> + */
> +static void
> +qla2x00_port_no_from_csrx(struct qla_hw_data *ha)
> +{
> + struct device_reg_24xx __iomem *reg;
> + u32 csr, port;
> + u8 pin = 0;
> +
> + if (!IS_FWI2_CAPABLE(ha) || IS_P3P_TYPE(ha) || !ha->iobase)
> + return;
> +
> + pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &pin);
> + if (pin || PCI_FUNC(ha->pdev->devfn))
> + return;
> +
> + reg = &ha->iobase->isp24;
> + csr = rd_reg_dword(®->ctrl_status);
> +
> + if (IS_QLA27XX(ha) || IS_QLA28XX(ha) || IS_QLA29XX(ha)) {
> + port = (csr & CSRX_PORT_MASK) >> CSRX_PORT_SHIFT;
> + if (port > 3) {
> + ql_log_pci(ql_log_warn, ha->pdev, 0x00e2,
> + "port %u from ctrl_status=0x%x is out of
> range.\n",
> + port, csr);
> + return;
> + }
> + ha->port_no = port;
> + ql_log_pci(ql_log_info, ha->pdev, 0x00e1,
> + "port %u ctrl_status=0x%x replaces the INTx
> pin.\n",
> + port, csr);
> + return;
> + }
> +
> + ha->port_no = (csr & CSRX_FUNCTION) ? 1 : 0;
> + ha->portnum = ha->port_no;
> + if (IS_QLA25XX(ha))
> + ql_log_pci(ql_log_info, ha->pdev, 0x00e1,
> + "25xx port %u ctrl_status=0x%x replaces the INTx
> pin.\n",
> + ha->port_no, csr);
> + else
> + ql_log_pci(ql_log_info, ha->pdev, 0x00e1,
> + "pin and function are 0; ctrl_status=0x%x
> port=%u.\n",
> + csr, ha->port_no);
> +}
> +
> static inline void
> qla2x00_set_isp_flags(struct qla_hw_data *ha)
> {
> @@ -2889,7 +2949,12 @@ qla2x00_set_isp_flags(struct qla_hw_data *ha)
> /* Get adapter physical port no from interrupt pin
> register. */
> pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN,
> &ha->port_no);
> if (ha->port_no == 0) {
> - /* None of INT[A|B|C|D] may be virtualized
> by vfio */
> + /*
> + * vfio and Hyper-V DDA clear or force the
> pin to 0;
> + * PCI_FUNC() is not the physical port on
> quad adapters.
> + * 25xx/27xx/28xx/29xx replace port_no from
> + * ctrl_status when pin and function are
> both 0.
> + */
> ha->port_no = PCI_FUNC(ha->pdev->devfn);
> } else if (IS_QLA25XX(ha) || IS_QLA2031(ha) ||
> IS_QLA27XX(ha) ||
> IS_QLA28XX(ha) || IS_QLA29XX(ha)) {
> @@ -3256,7 +3321,6 @@ qla2x00_probe_one(struct pci_dev *pdev, const
> struct pci_device_id *id)
> ha->mr.host_info_resend = false;
> ha->mr.hinfo_resend_timer_tick =
> QLAFX00_HINFO_RESEND_INTERVAL;
> } else if (IS_QLA27XX(ha)) {
> - ha->portnum = PCI_FUNC(ha->pdev->devfn);
> ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
> ha->mbx_count = MAILBOX_REGISTER_COUNT;
> req_length = REQUEST_ENTRY_CNT_83XX;
> @@ -3273,7 +3337,6 @@ qla2x00_probe_one(struct pci_dev *pdev, const
> struct pci_device_id *id)
> ha->nvram_conf_off = ~0;
> ha->nvram_data_off = ~0;
> } else if (IS_QLA28XX(ha)) {
> - ha->portnum = PCI_FUNC(ha->pdev->devfn);
> ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
> ha->mbx_count = MAILBOX_REGISTER_COUNT;
> req_length = REQUEST_ENTRY_CNT_83XX;
> @@ -3290,7 +3353,6 @@ qla2x00_probe_one(struct pci_dev *pdev, const
> struct pci_device_id *id)
> ha->nvram_conf_off = ~0;
> ha->nvram_data_off = ~0;
> } else if (IS_QLA29XX(ha)) {
> - ha->portnum = PCI_FUNC(ha->pdev->devfn);
> ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
> ha->mbx_count = MAILBOX_REGISTER_COUNT;
> req_length = REQUEST_ENTRY_CNT_83XX;
> @@ -3327,6 +3389,8 @@ qla2x00_probe_one(struct pci_dev *pdev, const
> struct pci_device_id *id)
> if (ret)
> goto iospace_config_failed;
>
> + qla2x00_port_no_from_csrx(ha);
> +
> ql_log_pci(ql_log_info, pdev, 0x001d,
> "Found an ISP%04X irq %d iobase 0x%p.\n",
> pdev->device, pdev->irq, ha->iobase);
>
>
Hi Nilesh,
Thanks for posting this.
I tested the earlier internal version of this patch, which always took
the port from ctrl_status on 25xx/27xx/28xx/29xx, on an ISP2281
(HPE SN1610Q, fw 9.06.02) on bare metal and with Hyper-V DDA simulated
by forcing the pin and PCI_FUNC() to 0:
13:00.0 ctrl_status=0x2 -> port 0, WWPN 0x51402ec01736925c
13:00.1 ctrl_status=0x1002 -> port 1, WWPN 0x51402ec01736925e
NVRAM was valid and all LUNs were found on both ports. Without the
patch, under the same simulation, both ports got port_no 0 and WWPN
0x51402ec01736925c, and the second port never came up on the fabric.
So the ctrl_status[15:12] decode is confirmed on 28xx.
On the Sashiko comments, I agree with:
- Gating on the pin alone. Bare metal always has a valid pin, and it
avoids the vfio case where guest .1 keeps a virtual PCI_FUNC() while
guest .0 reads ctrl_status.
- Excluding ISP8031 from the bit-15 path, since portnum there is the
physical function used by the shared IDC registers.
- Returning early if ctrl_status reads 0xffffffff.
- New message IDs above 0x0199.
For v2, could you also add a Link: to the original report thread [1],
and Reported-by: Laurence Oberman <loberman@redhat.com>, since this
came out of Red Hat case analysis of the Hyper-V DDA failure?
I will retest v2 the same way, on the ISP2281 and with simulated DDA,
and reply with Tested-by.
[1]
https://lore.kernel.org/all/b6b39c415514de821d8a71cefda41f3d4f53405a.camel@redhat.com/T/
Thanks,
Laurence
^ permalink raw reply [flat|nested] 3+ messages in thread