git: 6279646f47d3 - main - aic7xxx: make target mode enable a device hint

From: Warner Losh <imp_at_FreeBSD.org>
Date: Sat, 04 May 2024 14:44:25 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=6279646f47d3f6b916d1c9272f9db39134783ab4

commit 6279646f47d3f6b916d1c9272f9db39134783ab4
Author:     HP van Braam <hp@tmm.cx>
AuthorDate: 2024-05-04 14:40:15 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-05-04 14:40:38 +0000

    aic7xxx: make target mode enable a device hint
    
    Previously it was only possible to enable target mode for these drivers
    by rebuilding the kernel with AHC_TMODE_ENABLE or AHD_TMODE_ENABLE and a
    bitmask of which units to statically enable for target mode.
    
    There is no space-savings in the driver by not having AHC_TMODE_ENABLE
    set, so in addition to the compile time option lets also introduce some
    tunables:
    
    hint.ahc.<unit>.tmode_enable=0/1
    hint.ahd.<unit>.tmode_enable=0/1
    
    For compatibility the old behavior is retained, but it can be overridden
    with tunables
    
    Signed-off-by: HP van Braam <hp@tmm.cx>
    Reviewed by: imp, mav
    Pull Request: https://github.com/freebsd/freebsd-src/pull/1208
---
 share/man/man4/ahc.4      | 68 +++++++++++++++++++++++++++--------------------
 share/man/man4/ahd.4      | 36 ++++++++++++++++---------
 sys/dev/aic7xxx/aic79xx.c | 19 ++++++++++++-
 sys/dev/aic7xxx/aic7xxx.c | 19 ++++++++++++-
 4 files changed, 99 insertions(+), 43 deletions(-)

diff --git a/share/man/man4/ahc.4 b/share/man/man4/ahc.4
index a666885f8f4a..7d5e092089bb 100644
--- a/share/man/man4/ahc.4
+++ b/share/man/man4/ahc.4
@@ -40,12 +40,6 @@ kernel configuration file:
 .Pp
 For one or more PCI cards:
 .Cd "device pci"
-.Pp
-To allow PCI adapters to use memory mapped I/O if enabled:
-.Cd options AHC_ALLOW_MEMIO
-.Pp
-To configure one or more controllers to assume the target role:
-.Cd options AHC_TMODE_ENABLE <bitmask of units>
 .Ed
 .Pp
 Alternatively, to load the driver as a
@@ -66,29 +60,6 @@ Driver features include support for twin and wide busses,
 fast, ultra or ultra2 synchronous transfers depending on controller type,
 tagged queueing, SCB paging, and target mode.
 .Pp
-Memory mapped I/O can be enabled for PCI devices with the
-.Dq Dv AHC_ALLOW_MEMIO
-configuration option.
-Memory mapped I/O is more efficient than the alternative, programmed I/O.
-Most PCI BIOSes will map devices so that either technique for communicating
-with the card is available.
-In some cases,
-usually when the PCI device is sitting behind a PCI->PCI bridge,
-the BIOS may fail to properly initialize the chip for memory mapped I/O.
-The typical symptom of this problem is a system hang if memory mapped I/O
-is attempted.
-Most modern motherboards perform the initialization correctly and work fine
-with this option enabled.
-.Pp
-Individual controllers may be configured to operate in the target role
-through the
-.Dq Dv AHC_TMODE_ENABLE
-configuration option.
-The value assigned to this option should be a bitmap
-of all units where target mode is desired.
-For example, a value of 0x25, would enable target mode on units 0, 2, and 5.
-A value of 0x8a enables it for units 1, 3, and 7.
-.Pp
 Per target configuration performed in the
 .Tn SCSI-Select
 menu, accessible at boot
@@ -156,6 +127,45 @@ Multiple Target IDs - Allows the controller to respond to selection as a
 target on multiple SCSI IDs.
 .El
 .Ed
+.Sh CONFIGURATION OPTIONS
+.Pp
+To allow PCI adapters to use memory mapped I/O if enabled:
+.Pp
+.Cd options AHC_ALLOW_MEMIO
+.Bd -ragged -offset indent
+Memory mapped I/O is more efficient than the alternative, programmed I/O.
+Most PCI BIOSes will map devices so that either technique for communicating
+with the card is available.  In some cases, usually when the PCI device is
+sitting behind a PCI->PCI bridge, the BIOS may fail to properly initialize
+the chip for memory mapped I/O. The typical symptom of this problem is a
+system hang if memory mapped I/O is attempted.
+.Pp
+Most modern motherboards perform the initialization correctly and work fine
+with this option enabled.
+.Ed
+.Pp
+To statically configure one or more controllers to assume the target role:
+.Pp
+.Cd options AHC_TMODE_ENABLE <bitmask of units>
+.Bd -ragged -offset indent
+The value assigned to this option should be a bitmap of all units where target
+mode is desired. For example, a value of 0x25, would enable target mode on
+units 0, 2, and 5. A value of 0x8a enables it for units 1, 3, and 7.
+.Pp
+Note that controllers can be dynamically configured through a device hint
+documented below.
+.El
+.Ed
+.Sh BOOT OPTIONS
+The following options are switchable by setting values in
+.Pa /boot/device.hints .
+.Pp
+They are:
+.Bl -tag -width indent
+.It Va hint.ahc. Ns Ar N Ns Va .tmode_enable
+A hint to define whether the SCSI target mode is enabled (0 -- disabled, 1 -- enabled).
+.El
+.Ed
 .Sh HARDWARE
 The
 .Nm
diff --git a/share/man/man4/ahd.4 b/share/man/man4/ahd.4
index cf04863ce1c8..e7f9b73f085a 100644
--- a/share/man/man4/ahd.4
+++ b/share/man/man4/ahd.4
@@ -45,9 +45,6 @@ To compile in debugging code:
 .Cd options AHD_DEBUG
 .Cd options AHD_DEBUG_OPTS=<bitmask of options>
 .Cd options AHD_REG_PRETTY_PRINT
-.Pp
-To configure one or more controllers to assume the target role:
-.Cd options AHD_TMODE_ENABLE=<bitmask of units>
 .Ed
 .Pp
 Alternatively, to load the driver as a
@@ -99,15 +96,6 @@ that is printed by the debugging code.
 However, it also bloats the compiled
 size of the driver by approximately 215KB.
 .Pp
-Individual controllers may be configured to operate in the target role
-through the
-.Dv AHD_TMODE_ENABLE
-configuration option.
-The value assigned to this option should be a bitmap
-of all units where target mode is desired.
-For example, a value of 0x25 would enable target mode on units 0, 2, and 5.
-Note that target mode is only supported for ultra160 speeds and below.
-.Pp
 Per target configuration performed in the
 .Tn SCSI-Select
 menu, accessible at boot,
@@ -119,6 +107,30 @@ disconnection,
 and the host adapter's
 .Tn SCSI
 ID.
+.El
+.Ed
+.Sh CONFIGURATION OPTIONS
+To statically configure one or more controllers to assume the target role:
+.Pp
+.Cd options AHD_TMODE_ENABLE <bitmask of units>
+.Bd -ragged -offset indent
+The value assigned to this option should be a bitmap of all units where target
+mode is desired. For example, a value of 0x25, would enable target mode on
+units 0, 2, and 5. A value of 0x8a enables it for units 1, 3, and 7.
+.Pp
+Note that controllers can be dynamically configured through a device hint
+documented below.
+
+.Sh BOOT OPTIONS
+The following options are switchable by setting values in
+.Pa /boot/device.hints .
+.Pp
+They are:
+.Bl -tag -width indent
+.It Va hint.ahd. Ns Ar N Ns Va .tmode_enable
+A hint to define whether the SCSI target mode is enabled (0 -- disabled, 1 -- enabled).
+.El
+.Ed
 .Sh HARDWARE
 The
 .Nm
diff --git a/sys/dev/aic7xxx/aic79xx.c b/sys/dev/aic7xxx/aic79xx.c
index 1b1d31769f90..0c4b615c5b24 100644
--- a/sys/dev/aic7xxx/aic79xx.c
+++ b/sys/dev/aic7xxx/aic79xx.c
@@ -6229,6 +6229,9 @@ ahd_init(struct ahd_softc *ahd)
 	size_t		 driver_data_size;
 	int		 i;
 	int		 error;
+#ifdef AHD_TARGET_MODE
+	int		 tmode_enable;
+#endif
 	u_int		 warn_user;
 	uint8_t		 current_sensing;
 	uint8_t		 fstat;
@@ -6261,8 +6264,22 @@ ahd_init(struct ahd_softc *ahd)
 	/*
 	 * Only allow target mode features if this unit has them enabled.
 	 */
-	if ((AHD_TMODE_ENABLE & (0x1 << ahd->unit)) == 0)
+#ifdef AHD_TARGET_MODE
+	tmode_enable = ((AHD_TMODE_ENABLE & (0x1 << ahd->unit)) != 0);
+	resource_int_value(device_get_name(ahd->dev_softc),
+			       device_get_unit(ahd->dev_softc),
+			       "tmode_enable", &tmode_enable);
+
+	if (tmode_enable == 0) {
 		ahd->features &= ~AHD_TARGETMODE;
+	} else {
+		if (bootverbose && ((ahd->features & AHD_TARGETMODE) != 0))
+			printf("%s: enabling target mode\n", ahd_name(ahd));
+	}
+
+#else
+	ahd->features &= ~AHD_TARGETMODE;
+#endif
 
 	/* DMA tag for mapping buffers into device visible space. */
 	if (aic_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
diff --git a/sys/dev/aic7xxx/aic7xxx.c b/sys/dev/aic7xxx/aic7xxx.c
index 1560aa4fe312..c09876e9f589 100644
--- a/sys/dev/aic7xxx/aic7xxx.c
+++ b/sys/dev/aic7xxx/aic7xxx.c
@@ -4774,6 +4774,9 @@ ahc_init(struct ahc_softc *ahc)
 {
 	int	 max_targ;
 	int	 error;
+#ifdef AHC_TARGET_MODE
+	int	 tmode_enable;
+#endif
 	u_int	 i;
 	u_int	 scsi_conf;
 	u_int	 ultraenb;
@@ -4826,8 +4829,22 @@ ahc_init(struct ahc_softc *ahc)
 	/*
 	 * Only allow target mode features if this unit has them enabled.
 	 */
-	if ((AHC_TMODE_ENABLE & (0x1 << ahc->unit)) == 0)
+#ifdef AHC_TARGET_MODE
+	tmode_enable = ((AHC_TMODE_ENABLE & (0x1 << ahc->unit)) != 0);
+	resource_int_value(device_get_name(ahc->dev_softc),
+			       device_get_unit(ahc->dev_softc),
+			       "tmode_enable", &tmode_enable);
+
+	if (tmode_enable == 0) {
 		ahc->features &= ~AHC_TARGETMODE;
+	} else {
+		if (bootverbose && ((ahc->features & AHC_TARGETMODE) != 0))
+			printf("%s: enabling target mode\n", ahc_name(ahc));
+	}
+
+#else
+	ahc->features &= ~AHC_TARGETMODE;
+#endif
 
 	/* DMA tag for mapping buffers into device visible space. */
 	if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,