Skip to content

Commit

Permalink
aic7xxx: make target mode enable a device hint
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
hpvb committed Apr 30, 2024
1 parent 9718d4a commit 3c6e999
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 43 deletions.
68 changes: 39 additions & 29 deletions share/man/man4/ahc.4
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
36 changes: 24 additions & 12 deletions share/man/man4/ahd.4
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
28 changes: 27 additions & 1 deletion sys/dev/aic7xxx/aic79xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -6261,8 +6264,31 @@ 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);

if (resource_int_value(device_get_name(ahd->dev_softc),

Check failure on line 6270 in sys/dev/aic7xxx/aic79xx.c

View workflow job for this annotation

GitHub Actions / Style Checker

suspect code indent for conditional statements (8, 8)
device_get_unit(ahd->dev_softc),
"tmode_enable", &tmode_enable) != 0) {
} else {
if (bootverbose)
printf("%s: Using hint %s.%i.tmode_enable=%i\n",
ahd_name(ahd), device_get_name(ahd->dev_softc),
device_get_unit(ahd->dev_softc), tmode_enable);
}

if (tmode_enable == 0) {
if (bootverbose)
printf("%s: not enabling target mode\n", ahd_name(ahd));
ahd->features &= ~AHD_TARGETMODE;
} else {
if (bootverbose)
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,
Expand Down
28 changes: 27 additions & 1 deletion sys/dev/aic7xxx/aic7xxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -4826,8 +4829,31 @@ 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);

if (resource_int_value(device_get_name(ahc->dev_softc),

Check failure on line 4835 in sys/dev/aic7xxx/aic7xxx.c

View workflow job for this annotation

GitHub Actions / Style Checker

suspect code indent for conditional statements (8, 8)
device_get_unit(ahc->dev_softc),
"tmode_enable", &tmode_enable) != 0) {
} else {
if (bootverbose)
printf("%s: Using hint %s.%i.tmode_enable=%i\n",
ahc_name(ahc), device_get_name(ahc->dev_softc),
device_get_unit(ahc->dev_softc), tmode_enable);
}

if (tmode_enable == 0) {
if (bootverbose)
printf("%s: not enabling target mode\n", ahc_name(ahc));
ahc->features &= ~AHC_TARGETMODE;
} else {
if (bootverbose)
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,
Expand Down

0 comments on commit 3c6e999

Please sign in to comment.