Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH] scsi: qla2xxx: Take the port from ISP control/status
@ 2026-12-03  9:17 Nilesh Javali
  2026-12-03  9:40 ` sashiko-bot
  2026-12-03 13:24 ` Laurence Oberman
  0 siblings, 2 replies; 3+ messages in thread
From: Nilesh Javali @ 2026-12-03  9:17 UTC (permalink / raw)
  To: mkp; +Cc: linux-scsi, GR-FC-Storage-Upstream, emilne, jmeneghi, hare,
	loberman

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(&reg->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);
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-03 13:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox