History log of /freebsd-current/sys/dev/isp/isp_freebsd.c
Revision Date Author Comments
# 10ed63fc 27-Oct-2023 Joerg Pulz <Joerg.Pulz@frm2.tum.de>

isp(4): Rework firmware handling/loading

Correctly identify the active firmware in flash on adapters with
primary and secondary firmware region in flash.
Correctly identify the active NVRAM on adapters with primary
and secondary NVRAM region in flash.

Loading ispfw(4) moved from isp_pci_attach() to isp_reset().
Drop the reference to ispfw(4) after using it so one can kldunload(8) it.
New isp_load_ram() function to load either ispfw(4) or flash firmware
into RISC's RAM.
New functions to read data from flash. The old ones will be removed later.
A bunch of new helper functions to identify and validate active flash
regions for firmware, auxiliary and NVRAM.
Overhaul ISP_FW_* macros and make use of it when comparing firmware
versions. We can handle firmware versions up to 255.255.255.

Firmware load priority slightly changed:
For 27xx and newer adapters:
- load ispfw(4) firmware
- request (active) flash firmware information
- compare version numbers of ispfw(4) and flash firmware
- load firmware with highest version into RISC's RAM
- if loading ispfw(4) is disabled or failed - load firmware from flash
- if everything else fails use MBOX_LOAD_FLASH_FIRMWARE as fallback

For 26xx and older adapters nothing changed:
- load ispfw(4) firmware and load it into RISC's RAM
- if loading ispfw(4) is disabled or failed use MBOX_EXEC_FIRMWARE
- for 26xx a preceding MBOX_LOAD_FLASH_FIRMWARE is used

New read only sysctl(8)'s:
dev.isp.N.fw_version_run: the firmware version actually running
dev.isp.N.fw_version_ispfw: the firmware version provided by ispfw(4)
dev.isp.N.fw_version_flash: the (active) firmware version in flash

While here:
- firmware attribute handling/parsing reworked
+ renamed defines from ISP2400_FW_ATTR_* to ISP_FW_ATTR_*
+ changed values to match new handling/parsing
+ added some more attributes
- enable FLT support on 26xx based adapters
- log level adjustments
- new function return status codes (some for now, some for later use)
- some minor style changes

Tested and approved to work on real hardware with:
- Qlogic ISP 2532 (QLogic QLE2560 8Gb FC Adapter)
- Qlogic ISP 2031 (QLogic QLE2662 16Gbit 2Port FC Adapter)
- Qlogic ISP 2722 (QLogic QLE2690 16Gb FC Adapter)
- Qlogic ISP 2812 (QLogic QLE2772 32Gbit 2Port FC Adapter)

PR: 273263
Reviewed by: mav
Pull Request: https://github.com/freebsd/freebsd-src/pull/877
MFC after: 1 month
Sponsored by: Technical University of Munich


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# b776de67 10-Aug-2021 Alexander Motin <mav@FreeBSD.org>

Mark some sysctls as CTLFLAG_MPSAFE.

MFC after: 2 weeks


# 156c1ebe 27-Nov-2020 Alexander Motin <mav@FreeBSD.org>

Some code reorganization.

- Remove code duplication by adding two new functions to execute prepared
queue entry via either mbox or request queue and wait for result.
- Since the new function executing via request queue sleeps any way, make
it sleep also in case of overflows or handle shortages. It should make it
more reliable and less affecting other less flexible request queue users.
- Turn isp_target_put_entry() into not target-specific isp_send_entry().
- Make handling of responses with control handles more universal.
- Move RQSTYPE_RPT_ID_ACQ handling into new function.
- Inline isp_handle_other_response(), becoming trivial after above.
- Clean the list of IOCBs from pre-24xx ones.


# b760d2ec 26-Nov-2020 Alexander Motin <mav@FreeBSD.org>

More cleanup in response queue and reset code.


# 8cb0d414 25-Nov-2020 Alexander Motin <mav@FreeBSD.org>

Remove some more dead code from pre-24xx.


# a6222dd7 24-Nov-2020 Alexander Motin <mav@FreeBSD.org>

Remove more legacy of parallel SCSI.


# 384d27e0 24-Nov-2020 Alexander Motin <mav@FreeBSD.org>

Remove concept of mbox_sleep_ok.

It was broken by design and unused for years due to conflicts between
different threads, fighting for the same set of mailbox registers, not
designed for multiple requests at a time. So either request has to be
synchronous and spin under the lock, or it should be sent asynchronously
through the queues as Mailbox Command IOCB or some other way.

This removes any OS specifics from the wait code, so it can be inlined.


# 1553bf11 24-Nov-2020 Alexander Motin <mav@FreeBSD.org>

Remove unneeded locking around xpt_bus_[de]register().

MFC after: 2 weeks


# 0f99cb55 23-Nov-2020 Alexander Motin <mav@FreeBSD.org>

Implement request queue overflow protection.

Before this change in case of request queue overflow driver just froze the
device queue for 100ms to retry after. It was pretty bad for performance.
This change introduces SIM queue freezing when free space on the request
queue drops below 255 entries (worst case of maximum I/O size S/G list),
checking for a chance to release it on I/O completion. If the queue still
get overflowed somehow, the old mechanism is still in place, just with
delay reduced to 10ms.

With the earlier queue length increase overflows should not happen often,
but it is still easily reachable on synthetic tests.


# 3037002e 22-Nov-2020 Alexander Motin <mav@FreeBSD.org>

Fix debug build after 367926.


# 0b19f90a 21-Nov-2020 Alexander Motin <mav@FreeBSD.org>

Make handlers and atpds overflows unlikely.

- Allocate 256 handlers more than payload commands for management purposes.
- Increase maximum number of handlers from 8K to 16K by tuning the format.
- Just to be safe limit the number of payload commands to 16K - 256.
- Limit number of target exchanges in mixed mode to the number of atpds.
- If we still somehow get out of atpds -- return BUSY, since we really are.


# f6854a0c 20-Nov-2020 Alexander Motin <mav@FreeBSD.org>

Cleanup DMA handling.

- Make isp_start() to set all the IOCB fields aside of S/G list, removing
extra information from isp_send_cmd(), now only doing S/G lists and sending.
- Turn DMA setup/free from being card and PCI-specific into OS-specific,
instead add new card-specific method for isp_send_cmd(). Previously this
function was a monster handling all the cards.
- Remove double error code translation.


# 1b760be4 19-Nov-2020 Alexander Motin <mav@FreeBSD.org>

Remove parallel SCSI and 1/2Gb FC support from isp(4).

This removes 288KB (36%) of the driver code and zillions of hacks and
workarounds, making single driver uniformly support several different
generations of hardware interfaces, not counting minor card variations.
After years of the hopeless fight, I don't think it worth to continue
support for hardware obsolete for 15-20 years. Instead much cleaner
now code should allow to move forward toward better locking, multiple
queues and other cool features.

All the remaining Qlogic cards starting from 4Gb 24xx to 32Gb 27xx use
the same hardware/firmware interface with minor incremental improvements,
so it seems to be a good new starting point. Except one PCI-X model all
all of them are PCIe and so still usable in modern systems.

Discussed with: ken, scottl, jpaetzel, imp
Relnotes: yes


# cf770ba3 17-Nov-2020 Alexander Motin <mav@FreeBSD.org>

Move ecmd memory allocation itto separate DMA tag.

Ecmd memory is not directly related to the request queue, only referenced
from it sometimes in target mode. Separate allocation should be easier
in case of fragmented memory and can be skipped when target is not built.

MFC after: 1 month


# 57713eda 17-Nov-2020 Alexander Motin <mav@FreeBSD.org>

Don't allocate full XCMD_SIZE (512 bytes) on stack.

We need only 24 bytes (fcp_rsp_iu_t) there for isp_put_fcp_rsp_iu().

MFC after: 1 month


# 88364968 25-Oct-2020 Alexander Motin <mav@FreeBSD.org>

Introduce support of SCSI Command Priority.

SAM-3 specification introduced concept of Task Priority, that was renamed
to Command Priority in SAM-4, and supported by all modern SCSI transports.
It provides 15 levels of relative priorities: 1 - highest, 15 - lowest and
0 - default. SAT specification for SATA devices translates priorities 1-3
into NCQ high priority.

This change adds new "priority" field into empty spots of struct ccb_scsiio
and struct ccb_accept_tio of CAM and struct ctl_scsiio of CTL. Respective
support is added into iscsi(4), isp(4), mpr(4), mps(4) and ocs_fc(4) drivers
for both initiator and where applicable target roles. Minimal support was
added to CTL to receive the priority value from different frontends, pass it
between HA controllers and report in few places.

This patch does not add consumers of this functionality, so nothing should
really change yet, since the field is still set to 0 (default) on initiator
and not actively used on target. Those are to be implemented separately.

I've confirmed priority working on WD Red SATA disks connected via mpr(4)
and properly transferred to CTL target via iscsi(4), isp(4) and ocs_fc(4).

While there, added missing tag_action support to ocs_fc(4) initiator role.

MFC after: 1 month
Relnotes: yes
Sponsored by: iXsystems, Inc.


# 7029da5c 26-Feb-2020 Pawel Biernacki <kaktus@FreeBSD.org>

Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)

r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked).
Use it in preparation for a general review of all nodes.

This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Mark all obvious cases as MPSAFE. All entries that haven't been marked
as MPSAFE before are by default marked as NEEDGIANT

Approved by: kib (mentor, blanket)
Commented by: kib, gallatin, melifaro
Differential Revision: https://reviews.freebsd.org/D23718


# 5773ac11 10-Dec-2019 John Baldwin <jhb@FreeBSD.org>

Use callout_func_t instead of the deprecated timeout_t.

Reviewed by: kib, imp
Differential Revision: https://reviews.freebsd.org/D22752


# e26059ca 24-May-2019 Kenneth D. Merry <ken@FreeBSD.org>

Fix FC-Tape bugs caused in part by r345008.

The point of r345008 was to reset the Command Reference Number (CRN)
in some situations where a device stayed in the topology, but had
changed somehow.

This can include moving from a switch connection to a direct
connection or vice versa, or a device that temporarily goes away
and comes back. (e.g. moving to a different switch port)

There were a couple of bugs in that change:
- We were reporting that a device had not changed whenever the
Establish Image Pair bit was not set. That is not quite correct.
Instead, if the Establish Image Pair bit stays the same (set or
not), the device hasn't changed in that way.

- We weren't setting PRLI Word0 in the port database when a new
device arrived, so comparisons with the old value for the
Establish Image Pair bit weren't really possible. So, make sure
PRLI Word0 is set in the port database for new devices.

- We were resetting the CRN whenever the Establish Image Pair bit
was set for a device, even when the device had stayed the same
and the value of the bit hadn't changed. Now, only reset the
CRN for devices that have changed, not devices that sayed the
same.

The result of all of this was that if we had a single FC device on
an FC port and it went away and came back, we would wind up
correctly resetting the CRN.

But, if we had multiple devices connected via a switch, and there
was any change in one or more of those devices, all of the devices
that stayed the same would also have their CRN values reset.

The result, from a user standpoint, is that the tape drives, etc.
would all start to time out commands and the initiator would send
aborts.

sys/dev/isp/isp.c:
In isp_pdb_add_update(), look at whether the Establish
Image Pair bit has changed as part of the check to
determine whether a device is still the same. This was
causing erroneous change notifications. Also, when
creating a new port database entry, initialize the
PRLI Word 0 values.

sys/dev/isp/isp_freebsd.c:
In isp_async(), in the changed/stayed case, instead of
looking at the Establish Image Pair bit to determine
whether to reset the CRN, look at the command value.
(Changed vs. Stayed.) Only reset the CRN for devices
that have changed.

Sponsored by: Spectra Logic
MFC after: 3 days


# 6f9dbc0e 11-Mar-2019 Kenneth D. Merry <ken@FreeBSD.org>

Fix CRN resets in the isp(4) driver in certain situations.

The Command Reference Number (CRN) is part of the FC-Tape features
that we enable when talking to tape drives. It starts at 1, and
goes to 255 and wraps around to 1. There are a number of reset
type conditions that result in the CRN getting reset to 1. These
are detailed in section 4.10 (table 8) of the FCP-4r02b specification.

One of the conditions is when a PRLI (Process Login) is sent by
the initiator, and the Establish Image Pair bit is set in Word 0
of the PRLI.

Previously, the isp(4) driver core sent a notification via
isp_async() that the target had changed or stayed in place, but
there was no indication of whether a PRLI was sent and whether the
Establish Image Pair bit was set.

The result of this was that in some situations, notably
switching back and forth between a direct connection and a switch
connection to a tape drive, the isp(4) driver would fail to reset
the CRN in situations that require it according to the spec. When
the CRN isn't reset in a situation that requires it, the tape drive
then rejects every subsequent command that is sent to the drive.
It is assuming that the commands are being sent out of order.

So, modify the isp(4) driver to include Word 0 of the PRLI command
when it sends isp_async() notifications of target changes. Look at
the Establish Image Pair bit, and reset the CRN if that bit is set.

With this change, I am able to switch a tape drive back and forth
between a direct connection and a switch connection, and the isp(4)
driver resets the CRN when it should.

sys/dev/isp_stds.h:
Add bit definitions for PRLI Word 0.

sys/dev/ispmbox.h:
Add PRLI Word 0 to the port database type, isp_pdb_t.

sys/dev/ispvar.h
Add PRLI Word 0 to fcportdb_t.

sys/dev/isp.c:
Populate the new prli_word0 parameter in the port database.

In isp_pdb_add_update(), add a check to see if the
Establish Image Pair bit is set in PRLI Word 0. If it is,
then that is an additional reason to create a change
notification.

sys/dev/isp_freebsd.c:
In isp_async(), if the device changed or stayed, look at
PRLI Word 0 to see if the Establish Image Pair bit is set.
If it is, reset the CRN if we haven't already.

MFC after: 1 week
Sponsored by: Spectra Logic
Differential Revision: https://reviews.freebsd.org/D19472


# 6040822c 30-Jul-2018 Alan Somers <asomers@FreeBSD.org>

Make timespecadd(3) and friends public

The timespecadd(3) family of macros were imported from NetBSD back in
r35029. However, they were initially guarded by #ifdef _KERNEL. In the
meantime, we have grown at least 28 syscalls that use timespecs in some
way, leading many programs both inside and outside of the base system to
redefine those macros. It's better just to make the definitions public.

Our kernel currently defines two-argument versions of timespecadd and
timespecsub. NetBSD, OpenBSD, and FreeDesktop.org's libbsd, however, define
three-argument versions. Solaris also defines a three-argument version, but
only in its kernel. This revision changes our definition to match the
common three-argument version.

Bump _FreeBSD_version due to the breaking KPI change.

Discussed with: cem, jilles, ian, bde
Differential Revision: https://reviews.freebsd.org/D14725


# 8037cdcd 13-Mar-2018 Brooks Davis <brooks@FreeBSD.org>

Fix ISP_FC_LIP and ISP_RESCAN on big-endian 64-bit systems.

For _IO() ioctls, addr is a pointer to uap->data which is a caddr_t.
When the caddr_t stores an int, dereferencing addr as an (int *) results
in truncation on little-endian 64-bit systems and corruption (owing to
extracting top bits) on big-endian 64-bit systems. In practice the
value of chan was probably always zero on systems of the latter type as
all such FreeBSD platforms use a register-based calling convention.

Reviewed by: mav
Obtained from: CheriBSD
MFC after: 1 week
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D14673


# 718cf2cc 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/dev: further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


# b4af3e8a 23-Aug-2017 Alexander Motin <mav@FreeBSD.org>

Add missing restart_queue initialization.

MFC after: 1 week


# a94fab67 03-Jul-2017 Alexander Motin <mav@FreeBSD.org>

Switch fabric scans from GID_FT to GID_PT+GFF_ID/GFT_ID.

Instead of using GID_FT SNS request to get list of registered FCP ports,
use GID_PT to get list of all Nx_Ports, and then use GFF_ID and/or GFT_ID
requests to find whether they are FCP and target capable.

The problem with old approach is that GID_FT does not report ports without
FC-4 type registered. In particular it was impossible to boot OS from
FreeBSD FC target using QLogic FC BIOS, since one does not register FC-4
type even on new cards and so ignored by old code as incompatible.

As a side bonus this allows initiator to skip pointless logins to other
initiators by fetching that information from SNS instead.

In case some switches do not implement GFF_ID/GFT_ID correctly, add sysctls
to disable that functionality. I handled broken GFF_ID of my Brocade 200E,
but there may be other switches with different bugs.

Linux also uses GID_PT, but GFF_ID is disabled by default there, and GFT_ID
is not supported.

Sponsored by: iXsystems, Inc.


# 6ddb8972 30-Jun-2017 Alexander Motin <mav@FreeBSD.org>

Polish target_id/target_lun setting for ATIOs/INOTs.

For ATIOs it is pointless to report isp_loopid to CAM, since in other
places it operates with port database record IDs, not with loop IDs.

For INOTs target_id/target_lun seems were never set, so wildcard INOTs
probably were not working correctly when LUN IDs were important.


# 57b6261f 03-May-2017 Kenneth D. Merry <ken@FreeBSD.org>

Correct loop mode CRN resets to adhere to FCP-4 section 4.10

Prior to this change, the CRN (Command Reference Number) is reset on any
firmware LIP, LOOP DOWN, or LOOP RESET event in violation of FCP-4 which
specifies that the CRN should only be reset in response to a LIP Reset
(LIPyx) primitive. FCP-4 also indicates PLOGI/LOGO and PRLI/PRLO ELS
actions as conditions for resetting the CRN for the associated initiator
port.

These violations manifest themselves when the HBA is removed from the
loop, or a target device is removed (especially during an outstanding
command) without power cycling. If the HBA and and the target device
determine upon re-establishing the loop that no PLOGI or PRLI is
required, and the target does not issue a LIPxy to the initiator, the
CRN for the target will have been improperly reset by the isp driver. As
a result, the target port will silently ignore all FCP commands issued
during the device probe (which will time out) preventing the device from
attaching.

This change corrects thie CRN reset behavior in response to loop state
changes, also introduces CRN resets for the above mentioned ELS actions
as encountered through async PDB change events.

This change also adds cleanup of outstanding commands in isp_loop_dead()
that was previously missing.

sys/dev/isp/isp.c
Add the last login state to debug output when syncing the pdb

sys/dev/isp/isp_freebsd.c
Replace binary statement setting aborted ccb status in
isp_watchdog() with the XS_SETERR macro used elsewhere

In isp_loop_dead(), abort or complete pending commands as done
in isp_watchdog()

In isp_async(), segregate the ISPASYNC_LOOP_RESET action from
ISPASYNC_LIP, ISPASYNC_LOOP_DOWN, and ISPASYNC_LOOP_UP
fallthroughs, and only reset the CRN in the RESET case. Also add
checks to handle false LOOP RESET actions that do not have a
proper associated LIP primitive, and log the primitive in the
debug messages

In isp_async(), remove the goto from ISP_ASYNC_DEV_STAYED, and
only reset the CRN in the DEV_CHANGED action

In isp_async(), when processing an ISPASYNC_CHANGE_PDB status,
reset CRN(s) for the associated nphdl (or all ports) if the
change reason is some form of ELS login/logout. Also remove
assignment to fc since it is not used in the scope

sys/dev/isp/ispmbox.h
Add macro definition for the global N-Port handle, and correct a
macro typo 'PDB24XX_AE_PRLI_DONJE'

sys/dev/isp/ispvar.h
Add macros FCP_AL_DA_ALL, FCP_AL_PA, and FCP_IS_DEST_ALPD for
more legible code when determining if an AL_PD port matches the
portid for a given struct fcparam* by value or by virtue of the
AL_PD port being 0xFF

Submitted by: Reid Linnemann
Sponsored by: Spectra Logic
MFC after: 1 week


# e9da70a3 09-Apr-2017 Alexander Motin <mav@FreeBSD.org>

Fix few minor issues found by Clang Analyzer.

MFC after: 2 weeks


# 7e31684e 24-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Unify initiator and target DMA setup and command sending.

The code is so alike that it is pointless to keep it separate.

MFC after: 2 weeks


# 96ae113f 23-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Remove write-only crn field from struct isp_pcmd.

MFC after: 2 weeks


# ea8e769e 22-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Switch from using periph_links to sim_links.

periph_links field belongs to periph drivers and must not be used here.

MFC after: 2 weeks


# 2d24b6af 22-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Cleanup response queue processing.

MFC after: 2 weeks


# 31c161a6 21-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Improve command timeout handling.

Let firmware do its best first, and if it can't, try software recovery.
I would remove software timeout handler completely, but found bunch of
complains on command timeout on sparc64 mailing list few years ago, so
better be safe in case of interrupt loss.

MFC after: 2 weeks


# 13d9c921 21-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Clean/unify some macro usage.

MFC after: 2 weeks


# 98339da1 20-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Remove some more dead code.

MFC after: 2 weeks


# 9abc1e2b 19-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Remove some useless code.

MFC after: 2 weeks


# 08826086 19-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Add initial support for multiple MSI-X vectors.

For 24xx and above use 2 vectors (default and response queue).
For 26xx and above use 3 vectors (default, response and ATIO queues).
Due to global lock interrupt hardlers never run simultaneously now, but
at least this allows to save one regitster read per interrupt.

MFC after: 2 weeks


# 9c81a61e 19-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Remove hackish code delaying ATIOs to unknown virtual port.

Since we support RQSTYPE_RPT_ID_ACQ, that functionality is only useful
in loop mode, which probably doesn't worth having this hack in 2017.

MFC after: 2 weeks


# e2a658cb 19-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Move <= 23xx PDB workaround to generic code.

It is chip-specific and has nothing to do with platform.

MFC after: 2 weeks


# 5a5632c2 19-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Move 24xx RQSTYPE_NOTIFY handling to generic code.

This code has nothing to do with specific platform.

MFC after: 2 weeks


# 87b04de6 18-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Reorganize RQSTYPE_NOTIFY handling for chips <= 23xx.

There were two copies of the code: one in generic code was half-broken, and
another in platform code was never called. Leave only one in generic code
and working.

MFC after: 2 weeks


# 981ffc4e 18-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Move RQSTYPE_ABTS_RCVD parsing into generic code.

MFC after: 2 weeks


# 15c62456 18-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Extend nt_lun to full 8 byte.

MFC after: 2 weeks


# 782a8e7c 18-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Use isp_target_put_entry() in places where it can be.

This unifies the code and removes some duplication.

MFC after: 2 weeks


# 44a2a27a 18-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Do some notify acks cleanup.

ISPASYNC_TARGET_NOTIFY_ACK makes no sense without argument.

MFC after: 2 weeks


# d10e4cd0 15-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Remove not very useful ATIO/INOT stats.

While there polish respective debug logging.

MFC after: 2 weeks


# 0e6bc811 15-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Refactor interrupt handling.

Instead of single isp_intr() function doing all possible magic, introduce
four different functions to handle mailbox operation completions, async
events, response and ATIO queues. The goal is to isolate different code
paths to make code more readable, and to make easier support for multiple
interrupt vectors. Even oldest hardware in many cases can identify what
code path it should run on interrupt. Contemporary hardware can assign
them to different interrupt vectors.

MFC after: 2 weeks


# ce9f3237 15-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Fix panic when SIM dereferenced before allocation.

MFC after: 2 weeks


# 9c2e9bcf 14-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Remove some dead/broken code paths around async handling

MFC after: 2 weeks


# 6327b0d2 14-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Remove tangled isp_mbox_continue() mechanism.

It was implemented to reduce context switches when uploading firmware to
card's RAM. But this mechanism is not used last 10 years since all mbox
operations are now polled, and it was never used for cards produced in
last 15 years. Newer cards can use DMA to upload firmware.

MFC after: 2 weeks


# a1fa0267 14-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Improvements around attach, reset and detach.

This change fixes DMA resource leak on driver unload. Also it removes
DMA resources allocation for hardcoded number of requests before fetching
the real number from firmware. Also it prepares ground for more flexible
IRQs allocation according to firmware capabilities.

MFC after: 2 weeks


# 4599b542 14-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Remove remnant of r315163.

MFC after: 13 days


# c44f58fc 12-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Remove strange config_intrhook_establish() magic.

Interrupts are enabled as part of chip reset just during driver attach.
Later "enabling" of already enabled interrupts is useless.

MFC after: 2 weeks


# ab23521a 12-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Try to slight untangle I/O and loop status handling.

MFC after: 2 weeks


# 229203af 12-Mar-2017 Alexander Motin <mav@FreeBSD.org>

Remove code for unsupported FreeBSD versions.

MFC after: 2 weeks


# 3f072d69 27-Feb-2017 Alexander Motin <mav@FreeBSD.org>

Send TERMINATE to firmware when aborting active ATIO.

MFC after: 2 weeks


# a6036a44 25-Feb-2017 Alexander Motin <mav@FreeBSD.org>

Fix residual length reporting in target mode.

This allows to properly handle cases when target wants to receive or send
more data then initiator wants to send or receive. Previously in such
cases isp(4) returned CAM_DATA_RUN_ERR, while now it returns resid > 0.

MFC after: 2 weeks


# 87de303c 24-Feb-2017 Alexander Motin <mav@FreeBSD.org>

Respecting r314204 tighten ATIO cleanup requirements.

Every ATIO must complete with either successfully sent status or XPT_ABORT.

MFC after: 2 weeks


# 5c0b756a 23-Feb-2017 Alexander Motin <mav@FreeBSD.org>

Fix missing xpt_done() for ATIO/INOT on missing LUN.

MFC after: 2 weeks


# cfbeb41c 22-Feb-2017 Alexander Motin <mav@FreeBSD.org>

Slightly polish isp_dump_atpd().

MFC after: 2 weeks


# 8290ea90 21-Feb-2017 Alexander Motin <mav@FreeBSD.org>

Fix multiple problems around LUN disable under load.

- Move private data about ATIOs/INOTs from per-LUN to per-channel data.
This allows active commands to continue operation after LUN destruction.
This also simplifies lookup of the data by tag in some situations.
- Unify three restart_queue processing implementations.
- Complete all ATIOs from restart_queue on LUN disable.
- Delete ATIO private data when command completed or aborted, not depending
on the ATIO being requeued, that was ugly hack and could never happen. CAM
should always call ether XPT_CONT_TARGET_IO with status or XPT_ABORT.
- Implement XPT_ABORT for queued ATIOs/INOTs to allow CAM do graceful
shutdown, not depending on LUN disable, as it is done in ahd(4)/targ(4).
- Unify isp_endcmd() arguments to make it more usable in generic code.
- Remove never really used LUN state reference counter.

MFC after: 2 weeks


# 26719198 21-Feb-2017 Alexander Motin <mav@FreeBSD.org>

Remove duplicate INOT allocation.

For some reason isp_handle_platform_notify_fc() allocated INOT just
before calling isp_handle_platform_target_tmf(), which also allocates
INOT. It seems to be a braino introduced in r196008.

MFC after: 2 weeks


# 069f5ef9 20-Feb-2017 Alexander Motin <mav@FreeBSD.org>

Remove ancient __FreeBSD_version checks.

MFC after: 2 weeks


# 91d226ca 19-Feb-2017 Alexander Motin <mav@FreeBSD.org>

Remove broken remnants of obsolete INOT API.

MFC after: 2 weeks


# 0d965629 18-Feb-2017 Alexander Motin <mav@FreeBSD.org>

Missed addition to r313936.

CTIO waitq present only in ISP_TARGET_MODE.

MFC after: 2 weeks


# 09ddc7ad 18-Feb-2017 Alexander Motin <mav@FreeBSD.org>

Move CTIO waitq from per-LUN to per-channel.

All resources lack of which may put CTIO into the queue are either
per-channel or potentially per-queue, but none of them are per-LUN.

This is a first step to fix live LUN disabling. Before this change
any CTIOs held in a queue in time of disabling were just leaked.

MFC after: 2 weeks


# 4195c7de 04-Jan-2017 Alan Somers <asomers@FreeBSD.org>

Always null-terminate ccb_pathinq.(sim_vid|hba_vid|dev_name)

The sim_vid, hba_vid, and dev_name fields of struct ccb_pathinq are
fixed-length strings. AFAICT the only place they're read is in
sbin/camcontrol/camcontrol.c, which assumes they'll be null-terminated.
However, the kernel doesn't null-terminate them. A bunch of copy-pasted code
uses strncpy to write them, and doesn't guarantee null-termination. For at
least 4 drivers (mpr, mps, ciss, and hyperv), the hba_vid field actually
overflows. You can see the result by doing "camcontrol negotiate da0 -v".

This change null-terminates those fields everywhere they're set in the
kernel. It also shortens a few strings to ensure they'll fit within the
16-character field.

PR: 215474
Reported by: Coverity
CID: 1009997 1010000 1010001 1010002 1010003 1010004 1010005
CID: 1331519 1010006 1215097 1010007 1288967 1010008 1306000
CID: 1211924 1010009 1010010 1010011 1010012 1010013 1010014
CID: 1147190 1010017 1010016 1010018 1216435 1010020 1010021
CID: 1010022 1009666 1018185 1010023 1010025 1010026 1010027
CID: 1010028 1010029 1010030 1010031 1010033 1018186 1018187
CID: 1010035 1010036 1010042 1010041 1010040 1010039
Reviewed by: imp, sephe, slm
MFC after: 4 weeks
Sponsored by: Spectra Logic Corp
Differential Revision: https://reviews.freebsd.org/D9037
Differential Revision: https://reviews.freebsd.org/D9038


# 873b0260 20-May-2016 Alexander Motin <mav@FreeBSD.org>

Pass proper for 23xx arguments to isp_endcmd().


# 96b5475b 20-May-2016 Alexander Motin <mav@FreeBSD.org>

Pass task management response information from CTL through CAM to isp(4),
utilizing previously unused arg field of struct ccb_notify_acknowledge.

This makes new QUERY TASK, QUERY TASK SET and QUERY ASYNC EVENT requests
really functional for CAM target mode drivers.


# 514a71eb 19-May-2016 Alexander Motin <mav@FreeBSD.org>

Fix delaying requests to unknown virtual ports 2s after init.

This code was originally implemented 7 years ago, but never really worked
due to trivial error. I think this functionality may be not required.
Initiators supporting optional periodic command status checks detected
those terminated commands and retried them 3 seconds later. But thinking
about less featured initiators and the fact that it is our race makes
virtual ports "unknown" it may be good to have this feature.


# 352427b3 19-May-2016 Alexander Motin <mav@FreeBSD.org>

Add proper reporting for early task management errors.

This covers unknown requests and requests to unknown virtual ports.
Previously it "worked" only because of timeout handling on initiator.


# daa0dffb 16-May-2016 Alexander Motin <mav@FreeBSD.org>

Reduce verbosity of "now sending synthesized status" message.

MFC after: 1 week


# 53791a95 11-Apr-2016 Alexander Motin <mav@FreeBSD.org>

Reimplement ISP_TSK_MGMT IOCTL via asynchronous request.

I am not sure this code is not completely dead, but it used DMA scratch
are without good reason and asked to be refactored.


# a2531862 09-Mar-2016 Warner Losh <imp@FreeBSD.org>

Move to new value for XPT_GET_SIM_KNOB to avoid clash with XPT_ATA_IO.


# 970ceb2f 25-Dec-2015 Alexander Motin <mav@FreeBSD.org>

Unify handles allocation for initiator and target IOCBs.

I am not sure why this was split long ago, but I see no reason for it.
At this point this unification just slightly reduces memory usage, but
as next step I plan to reuse shared handle space for other IOCB types.


# a46709e2 24-Dec-2015 Alexander Motin <mav@FreeBSD.org>

Some polishing for command timeouts handling.


# a193dc4b 05-Dec-2015 Alexander Motin <mav@FreeBSD.org>

Rework WWNs generation to make cards without NVRAM more useful.


# e096498a 26-Nov-2015 Alexander Motin <mav@FreeBSD.org>

Remove residual functions declaration left after r291365.


# e561aa79 26-Nov-2015 Alexander Motin <mav@FreeBSD.org>

One more round of port scanner rewrite.

- Make scan aborted by event restart immediately and infinitely.
- Improve handling of some loop events from firmware.
- Remove loop down timer, adding its functionality to scanner thread.
- Some more unification and simplification.


# a4ccb5d6 23-Nov-2015 Alexander Motin <mav@FreeBSD.org>

Fix target mode support for Qlogic 2200 FC adapters.

Now target mode works for all supported FC adapters except ancient 2100,
which is not tested.


# 3e6deb33 23-Nov-2015 Alexander Motin <mav@FreeBSD.org>

Rip off target mode support for parallel SCSI QLogic adapters.

Hacks to enable target mode there complicated code, while didn't really
work. And for outdated hardware fixing it is not really interesting.

Initiator mode tested with Qlogic 1080 adapter is still working fine.


# 45b9ad7a 22-Nov-2015 Alexander Motin <mav@FreeBSD.org>

Generate fake ISPASYNC_CHANGE_PDB on fake login on pre-24xx.

This makes port scanner fix absent port ID for added initiator.


# 4187a965 21-Nov-2015 Alexander Motin <mav@FreeBSD.org>

Fix target mode with fabric for pre-24xx chips.

For those chips we are not receiving login events, adding initiators
based on ATIO requests. But there is no port ID in that structure, so
in fabric mode we have to explicitly fetch it from firmware to be able
to do normal scan after that.


# eea52482 19-Nov-2015 Alexander Motin <mav@FreeBSD.org>

Another round of port scanner rewrite.

This change simplifies and unifies port adding/updating for loop and
fabric scanners. It also fixes problems with scanning restarts due to
concurrent port databases changes. It also fixes many cosmetic issues.


# c5fd36ed 18-Nov-2015 Alexander Motin <mav@FreeBSD.org>

Remove some confusions between loopid and nphdl.

Modern cards in most cases operate abstract port handles, that have no
any relation to real loop IDs. Leave loopid used only where it really
goes about local loop IDs.

While there, fix few more cases where LUNs were still printed in decimal.


# 21daf914 14-Nov-2015 Alexander Motin <mav@FreeBSD.org>

Fix/improve CRN tracking.


# 668c0ec6 28-Oct-2015 Alexander Motin <mav@FreeBSD.org>

Change the way how target mode is enabled on 23xx chips.

Without docs I am not completely sure about this, but on my tests new
method works better then previous, at least with our latest firmware.


# b5d5037b 25-Oct-2015 Alexander Motin <mav@FreeBSD.org>

Improve Port Database Changed handling and reporting.


# dfd24649 25-Oct-2015 Alexander Motin <mav@FreeBSD.org>

Formalize/unify chip (re-)inits.


# 6af11b82 24-Oct-2015 Alexander Motin <mav@FreeBSD.org>

Add PIM_EXTLUNS support to isp(4) driver.

Now 24xx and above chips support full 8-byte LUN address space.
Older FC chips may support up to 16K LUNs when firmware allows.
Tested in both initiator and target modes for 23xx, 24xx and 25xx.


# 385490cb 24-Oct-2015 Alexander Motin <mav@FreeBSD.org>

Remove ISP_INTERNAL_TARGET code.

We have CTL now, which is real and much more functional then this joke.


# c98d2b1f 23-Oct-2015 Alexander Motin <mav@FreeBSD.org>

Add partial support for QUERY TMF to CAM and isp(4).

This change allows to decode respective functions in isp(4) in target mode
and pass them through CAM to CTL. Unfortunately neither CAM nor isp(4)
support returning response info for those task management functions now.

On the other side I just have no initiator to test this functionality.


# 37a7daac 23-Oct-2015 Alexander Motin <mav@FreeBSD.org>

Improve INOTs handling for 24xx and above chips.


# c07b9e07 23-Oct-2015 Alexander Motin <mav@FreeBSD.org>

Disable full bus scan by CAM for FC adapters.

FC port database code already notifies CAM about all devices. Additional
full scan is just a waste of time, that by definition won't find anything
that is not present in port database.


# 6ce548a1 23-Oct-2015 Alexander Motin <mav@FreeBSD.org>

Some polishing and unification in ISR code.


# e596ff7a 13-Oct-2015 Alexander Motin <mav@FreeBSD.org>

Export bunch of state variables as sysctls.


# 7dbe8f17 14-Jul-2015 Alexander Motin <mav@FreeBSD.org>

MULTI_ID supported does not mean it is used.


# d4f3ad3a 13-Jul-2015 Alexander Motin <mav@FreeBSD.org>

Switch initiator IDs in target mode to the same address space as target
IDs in initiator mode -- index in port database instead of handlers.

This makes initiator IDs persist across role changes and firmware resets,
when handlers previously assigned by firmware are lost and reused.

Sponsored by: iXsystems, Inc.


# 391f03da 13-Jul-2015 Alexander Motin <mav@FreeBSD.org>

Make role sysctl handling from r284727 less strict.


# e68eef14 13-Jul-2015 Alexander Motin <mav@FreeBSD.org>

Unify port database use for target and initiator roles.

Aside from cleaner and more consistent code, this allows ports to be both
target and initiator same time, and easily switch from any role to any.

Sponsored by: iXsystems, Inc.


# d1f40587 04-Jul-2015 Alexander Motin <mav@FreeBSD.org>

Make first step toward supporting target and initiator roles same time.

To avoid conflicts between target and initiator devices in CAM, make
CTL use target ID reported by HBA as its initiator_id in XPT_PATH_INQ.
That target ID is known to never be used for initiator role, so it won't
conflict. For Fibre Channel and FireWire HBAs this specific ID choice
is irrelevant since all target IDs there are virtual. Same time for SPI
HBAs it seems could be even requirement to use same target ID for both
initiator and target roles.

While there are some more things to polish in isp(4) driver, first tests
of using both roles same time on the same port appeared successfull:

# camcontrol devlist -v
scbus0 on isp0 bus 0:
<FREEBSD CTLDISK 0001> at scbus0 target 1 lun 0 (da20,pass21)
<> at scbus0 target 256 lun 0 (ctl0)
<> at scbus0 target -1 lun ffffffff (ctl1)


# 766a65a5 04-Jul-2015 Alexander Motin <mav@FreeBSD.org>

Remove extra level of target ID indirection (isp_dev_map).

FreeBSD never had limitation on number of target IDs, and there is no
any other requirement to allocate them densely. Since slots of port
database already populated just sequentially, there is no much need
for another indirection to allocate sequentially too.


# 8656f200 04-Jul-2015 Alexander Motin <mav@FreeBSD.org>

Change comment added in r284540.

This appeared to be not card's issue, but driver's, though solution is
the same so far.


# 6bef0aa0 04-Jul-2015 Alexander Motin <mav@FreeBSD.org>

Drop discovered targets when initiator role is disabled.


# 5cbe3e8e 24-Jun-2015 Alexander Motin <mav@FreeBSD.org>

Fix reported_gone setting, missed in some cases.

This makes driver better track reported CAM_SEL_TIMEOUTs to properly
report device reappearance later. This fixes target 0 not reappearing
after initiator mode disabled and then reenabled.

MFC after: 3 days


# 07f56f1c 23-Jun-2015 Alexander Motin <mav@FreeBSD.org>

Add dev.isp.X.role sysctl in addition to tunable.

It (mostly) allows to enable/disable initiator mode in run time.
Target mode control is blocked here to force coordination with CTL.

While there, add separate tunables/sysctls for virtual channels.


# 30363120 21-Jun-2015 Alexander Motin <mav@FreeBSD.org>

Rewrite port database handling for target mode.

Previous implementation was too fragile to initiator parameters changes.
In case of port role change it could not survive different handle assigned
to the same initiator by firmware, even though initiator was logged out.
The new implementation should be more resillient to this kind of problems,
trying to work in any situation and only warn user about suspisious events.

MFC after: 1 week
Sponsored by: iXsystems, Inc.


# af207637 18-Jun-2015 Alexander Motin <mav@FreeBSD.org>

In case of target mode disable at least ISP2532 return invalid zero
ct_rxid value on CTIO completion. Try to workaround that using tag_id
from the CCB, pointed by still valid ct_syshandle.

I don't know whether this is valid fix or dirty hack, but considering that
alternative is indefinitely stuck command -- it worth trying.

MFC after: 1 week


# 5b14cb41 21-Jan-2015 Will Andrews <will@FreeBSD.org>

Force commit to record the correct log for r277513.

If the user sends an XPT_RESET_DEV CCB, make sure to reset the
Fibre Channel Command Reference Number if we're running on a FC
controller.

We send a SCSI Target Reset when we get this CCB, and as a result
need to reset the CRN to 1 on the next command.

isp_freebsd.c:
In the XPT_RESET_DEV implementation in isp_action(), reset
the CRN if we're on a FC controller.

Submitted by: ken
MFC after: 1 week
Sponsored by: Spectra Logic
MFSpectraBSD: 1112787 on 2015/01/15


# b44e442e 21-Jan-2015 Will Andrews <will@FreeBSD.org>

Change 1112791 by kenm@ken.spectrabsd8 on 2015/01/15 16:45:13

Fix SCSI status byte reporting on 4Gb and 8Gb Qlogic boards.

The newer boards don't have the response field that indicates
whether the SCSI status byte is present. You have to just look to
see whether it is non-zero.

The code was looking to see whether the sense length was valid
before propagating the SCSI status byte (and sense information) up
the stack. With a status like Reservation Conflict, there is no
sense information, only the SCSI status byte. So it wasn't getting
correctly returned.

isp.c:
In isp_intr(), if we are on a 2400 or 2500 type board and
get a response, look at the actual contents of the
SCSI status value and set the RQSF_GOT_STATUS flag
accordingly so that return any SCSI status value we get. The
RQSF_GOT_SENSE flag will get set later on if there is
actual sense information returned.

Submitted by: ken
MFC after: 1 week
Sponsored by: Spectra Logic
MFSpectraBSD: 1112791 on 2015/01/15


# 5704e6f0 08-Jan-2015 Kenneth D. Merry <ken@FreeBSD.org>

Close a race in the isp(4) driver that caused devices to disappear
and not automatically come back if they were gone for a short
period of time.

The isp(4) driver has a 30 second gone device timer that gets
activated whenever a device goes away. If the device comes back
before the timer expires, we don't send a notification to CAM that
it has gone away. If, however, there is a command sent to the
device while it is gone and before it comes back, the isp(4) driver
sends the command back with CAM_SEL_TIMEOUT status.

CAM responds to the CAM_SEL_TIMEOUT status by removing the device.
In the case where a device comes back within the 30 second gone
device timer window, though, we weren't telling CAM the device
came back.

So, fix this by tracking whether we have told CAM the device is
gone, and if we have, send a rescan if it comes back within the 30
second window.

ispvar.h:
In the fcportdb_t structure, add a new bitfield,
reported_gone. This gets set whenever we return a command
with CAM_SEL_TIMEOUT status on a Fibre Channel device.

isp_freebsd.c:
In isp_done(), if we're sending CAM_SEL_TIMEOUT for for a
command sent to a FC device, set the reported_gone bit.

In isp_async(), in the ISPASYNC_DEV_STAYED case, rescan the
device in question if it is mapped to a target ID and has
been reported gone.

In isp_make_here(), take a port database entry argument,
and clear the reported_gone bit when we send a rescan to
CAM.

In isp_make_gone(), take a port database entry as an
argument, and set the reported_gone bit when we send an
async event telling CAM consumers that the device is gone.

Sponsored by: Spectra Logic
MFC after: 1 week


# fb4a4356 08-Jan-2015 Kenneth D. Merry <ken@FreeBSD.org>

Fix Fibre Channel Command Reference Number handling in the isp(4) driver.

The Command Reference Number is used for precise delivery of
commands, and is part of the FC-Tape functionality set. (This is
only enabled for devices that support precise delivery of commands.)
It is an 8-bit unsigned number that increments from 1 to 255. The
commands sent by the initiator must be processed by the target in
CRN order if the CRN is non-zero.

There are certain scenarios where the Command Reference Number
sequence needs to be reset. When the target is power cycled, for
instance, the initiator needs to reset the CRN to 1. The initiator
will know this because it will see a LIP (when directly connected)
or get a logout/login event (when connected to a switch).

The isp(4) driver was not resetting the CRN when a target
went away and came back. When it saw the target again after a
power cycle, it would continue the CRN sequence where it left off.
The target would ignore the command because the CRN sequence is
supposed to be reset to 1 after a power cycle or other similar
event.

The symptom that the user would see is that there would be lots of
aborted INQUIRY commands after a tape library was power cycled, and
the library would fail to probe. The INQUIRY commands were being
ignored by the tape drive due to the CRN issue mentioned above.

isp_freebsd.c:
Add a new function, isp_fcp_reset_crn(). This will reset
all of the CRNs for a given port, or the CRNs for all LUNs
on a target.

Reset the CRNs for all targets on a port when we get a LIP,
loop reset, or loop down event.

Reset the CRN for a particular target when it arrives, is changed
or departs. This is less precise behavior than the
clearing behavior specified in the FCP-4 spec (which says
that it should be reset for PRLI, PRLO, PLOGI and LOGO),
but this is the level of information we have here. If this
is insufficient, then we will need to add more precise
notification from the lower level isp(4) code.

isp_freebsd.h:
Add a prototype for isp_fcp_reset_crn().

Sponsored by: Spectra Logic
MFC after: 1 week


# 2731e062 26-Nov-2014 Alexander Motin <mav@FreeBSD.org>

Fix WWNN/WWPN generation for virtual channels.

MFC after: 1 week


# 315a4d6f 26-Nov-2014 Alexander Motin <mav@FreeBSD.org>

Some microoptimizations.

MFC after: 1 month


# b3a9e657 19-Nov-2014 Alexander Motin <mav@FreeBSD.org>

Fix build without INVARIANTS, broken by r274675.


# 2a0db815 18-Nov-2014 John Baldwin <jhb@FreeBSD.org>

Convert the refire_notify_ack timer from timeout(9) to callout(9).

Tested by: no one


# 1d0a1de2 17-Sep-2014 Will Andrews <will@FreeBSD.org>

Fix a kernel panic when unloading isp(4).

In the current implementation, the isp_kthread() threads never exit.

The target threads do have an exit mode from isp_attach(), but it is
not invoked from isp_detach().

Ensure isp_detach() notifies threads started for each channel, such
that they exit before their parent device softc detaches, and thus
before the module does. Otherwise, a page fault panic occurs later in:

sysctl_kern_proc
sysctl_out_proc
kern_proc_out
fill_kinfo_proc
fill_kinfo_thread
strlcpy(kp->ki_wmesg, td->td_wmesg, sizeof(kp->ki_wmesg));

For isp_kthread() (and isp(4) target threads), td->td_wmesg references
now-unmapped memory after the module has been unloaded. These threads
are typically msleep()ing at the time of unload, but they could also
attempt to execute now-unmapped code segments.

MFC after: 1 month
Sponsored by: Spectra Logic
MFSpectraBSD: r1070921 on 2014/06/22 13:01:17


# 950b6e12 08-Jul-2014 Alexander Motin <mav@FreeBSD.org>

Pass correct command that should be aborted to ISPCTL_ABORT_CMD.

This makes XPT_ABORT to work for me on initiator side of isp(4).
Previous code was trying to abort the XPT_ABORT itself and failed.

MFC after: 1 week


# c3167cab 24-Dec-2013 Matt Jacob <mjacob@FreeBSD.org>

Harvest one no longer used constant string.

Remove another and place it into play in the
normally ifdef protected zone it would be used
int.

Noticed by: dim


# 123055f0 30-Oct-2013 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Adjust various SCSI drivers to handle either a 32-bit or 64-bit lun_id_t,
mostly by adjustments to debugging printf() format specifiers. For high
numbered LUNs, also switch to printing them in hex as per SAM-5.

MFC after: 2 weeks


# 227d67aa 20-Oct-2013 Alexander Motin <mav@FreeBSD.org>

Merge CAM locking changes from the projects/camlock branch to radically
reduce lock congestion and improve SMP scalability of the SCSI/ATA stack,
preparing the ground for the coming next GEOM direct dispatch support.

Replace big per-SIM locks with bunch of smaller ones:
- per-LUN locks to protect device and peripheral drivers state;
- per-target locks to protect list of LUNs on target;
- per-bus locks to protect reference counting;
- per-send queue locks to protect queue of CCBs to be sent;
- per-done queue locks to protect queue of completed CCBs;
- remaining per-SIM locks now protect only HBA driver internals.

While holding LUN lock it is allowed (while not recommended for performance
reasons) to take SIM lock. The opposite acquisition order is forbidden.
All the other locks are leaf locks, that can be taken anywhere, but should
not be cascaded. Many functions, such as: xpt_action(), xpt_done(),
xpt_async(), xpt_create_path(), etc. are no longer require (but allow) SIM
lock to be held.

To keep compatibility and solve cases where SIM lock can't be dropped, all
xpt_async() calls in addition to xpt_done() calls are queued to completion
threads for async processing in clean environment without SIM lock held.

Instead of single CAM SWI thread, used for commands completion processing
before, use multiple (depending on number of CPUs) threads. Load balanced
between them using "hash" of the device B:T:L address.

HBA drivers that can drop SIM lock during completion processing and have
sufficient number of completion threads to efficiently scale to multiple
CPUs can use new function xpt_done_direct() to avoid extra context switch.
Make ahci(4) driver to use this mechanism depending on hardware setup.

Sponsored by: iXsystems, Inc.
MFC after: 2 months


# 5e63cdb4 21-Oct-2013 Alexander Motin <mav@FreeBSD.org>

Partial MFproject/camlock r256671:
Fix several target mode SIMs to not blindly clear ccb_h.flags field of
ATIO CCBs. Not all CCB flags there belong to them.


# 523ea374 17-Oct-2013 Alexander Motin <mav@FreeBSD.org>

Optimize isp(4) to reduce CPU usage, especially in target mode:
- Remove two excessive and slow register reads from isp_intr(). Instead
of rereading value every time, assume that registers contain what we have
written there.
- Avoid sequential search through 4096 array elements when looking for
command tag. Use hash of lists to store active tags separately from free
ones and so greatly speedup the searches.

Reviewed by: mjacob


# 7bf825d1 15-Aug-2013 Kenneth D. Merry <ken@FreeBSD.org>

Export the maxio field in the CAM XPT_PATH_INQ CCB in the isp(4)
driver.

This tells consumers up the stack the maximum I/O size that the
controller can handle.

The I/O size is bounded by the number of scatter/gather segments
the controller can handle and the page size. For an amd64 system,
it works out to around 5MB.

Reviewed by: mjacob
MFC after: 3 days
Sponsored by: Spectra Logic


# ab1aa38b 04-Jun-2013 Marius Strobl <marius@FreeBSD.org>

Flag isp(4) as supporting unmapped I/O; all necessary conversion actually
already has been done as part of r246713.

Reviewed by: mjacob


# e5dfa058 14-Apr-2013 Alexander Motin <mav@FreeBSD.org>

MFprojects/camlock r248982:
Stop abusing xpt_periph in random plases that really have no periph related
to CCB, for example, bus scanning. NULL value is fine in such cases and it
is correctly logged in debug messages as "noperiph". If at some point we
need some real XPT periphs (alike to pmpX now), quite likely they will be
per-bus, and not a single global instance as xpt_periph now.


# 3e0e2e20 26-Feb-2013 Matt Jacob <mjacob@FreeBSD.org>

Remove redundant xpt_alloc_ccb in isp_target_thread that was causing leakage.

Pointed out by: Sascha Wildner of DragonFly BSD
MFC after: 1 week


# 6f7aeb5f 16-Sep-2012 Matt Jacob <mjacob@FreeBSD.org>

Minor correction.

MFC after: 1 day


# 8b382bc2 16-Sep-2012 Matt Jacob <mjacob@FreeBSD.org>

Add some edits to the changed comments so that they make more sense.

MFC after: 1 day


# 96240c89 14-Sep-2012 Eitan Adler <eadler@FreeBSD.org>

Correct double "the the"

Approved by: cperciva
MFC after: 3 days


# 344aebe2 16-Aug-2012 Matt Jacob <mjacob@FreeBSD.org>

On lun disable, complete all INOTs and ATIOs with CAM_REQ_ABORTED.

Reviewed by: ken (silently), chuck
MFC after: 3 weeks


# 405b7a29 12-Aug-2012 Matt Jacob <mjacob@FreeBSD.org>

Fix an oops where we wiped out DMA maps. Don't allocate extended
command space for anything less than a 2300.

MFC after: 1 month
X-MFC: 238869


# 94dff771 08-Aug-2012 Matt Jacob <mjacob@FreeBSD.org>

More rototilling with target mode in an attemp to get multiple
CCB at a time outstanding reliable. It's not there yet, but this
is the direction to go in so might as well commit. So far,
multiple at a time CCBs work (see ISP_INTERNAL_TARGET test mode),
but it fails if there are more downstream than the SIM wants
to handle and SRR is sort of confused when this happens, plus
it is not entirely quite clear what one does if a CCB/CTIO fails
and you have more in flight (that don't fail, say) and more queued
up at the SIM level that haven't been started yet.

Some of this is driven because there apparently is no flow control
to requeue XPT_CONTINUE_IO requests like there are for XPT_SCSI_IO
requests. It is also more driven in that the few target mode
periph drivers there are are not really set up for handling pushback-
heck most of them don't even check for errors (and what would they
really do with them anyway? It's the initiator's problem, really....).

The data transfer arithmetic has been worked over again to handle
multiple outstanding commands, so you have a notion of what's been
moved already as well as what's currently in flight. It turns that
this led to uncovering a REPORT_LUNS bug in the ISP_INTERNAL_TARGET
code which was sending back 24 bytes of rpl data instead of the
specified 16. What happened furthermore here is that sending back
16 bytes and reporting an overrun of 8 bytes made the initiator
(running FC-Tape aware f/w) mad enough to request, and keep
requesting, another FCP response (I guess it didn't like the answer
so kept asking for it again).

Sponsored by: Spectralogic
MFC after: 1 month


# 387d8239 28-Jul-2012 Matt Jacob <mjacob@FreeBSD.org>

-----------
MISC CHANGES

Add a new async event- ISP_TARGET_NOTIFY_ACK, that will guarantee
eventual delivery of a NOTIFY ACK. This is tons better than just
ignoring the return from isp_notify_ack and hoping for the best.

Clean up the lower level lun enable code to be a bit more sensible.

Fix a botch in isp_endcmd which was messing up the sense data.

Fix notify ack for SRR to use a sensible error code in the case
of a reject.

Clean up and make clear what kind of firmware we've loaded and
what capabilities it has.
-----------
FULL (252 byte) SENSE DATA

In CTIOs for the ISP, there's only a limimted amount of space
to load SENSE DATA for associated CHECK CONDITIONS (24 or 26
bytes). This makes it difficult to send full SENSE DATA that can
be up to 252 bytes.

Implement MODE 2 responses which have us build the FCP Response
in system memory which the ISP will put onto the wire directly.

On the initiator side, the same problem occurs in that a command
status response only has a limited amount of space for SENSE DATA.
This data is supplemented by status continuation responses that
the ISP pushes onto the response queue after the status response.
We now pull them all together so that full sense data can be
returned to the periph driver.

This is supported on 23XX, 24XX and 25XX cards.

This is also preparation for doing >16 byte CDBs.

-----------
FC TAPE

Implement full FC-TAPE on both initiator and target mode side. This
capability is driven by firmware loaded, board type, board NVRAM
settings, or hint configuration options to enable or disable. This
is supported for 23XX, 24XX and 25XX cards.

On the initiator side, we pretty much just have to generate a command
reference number for each command we send out. This is FCP-4 compliant
in that we do this per ITL nexus to generate the allowed 1 thru 255
CRN.

In order to support the target side of FC-TAPE, we now pay attention
to more of the PRLI word 3 parameters which will tell us whether
an initiator wants confirmed responses. While we're at it, we'll
pay attention to the initiator view too and report it.

On sending back CTIOs, we will notice whether the initiator wants
confirmed responses and we'll set up flags to do so.

If a response or data frame is lost the initiator sends us an SRR
(Sequence Retransmit Request) ELS which shows up as an SRR notify
and all outstanding CTIOs are nuked with SRR Received status. The
SRR notify contains the offset that the initiator wants us to restart
the data transfer from or to retransmit the response frame.

If the ISP driver still has the CCB around for which the data segment
or response applies, it will retransmit.

However, we typically don't know about a lost data frame until we
send the FCP Response and the initiator totes up counters for data
moved and notices missing segments. In this case we've already
completed the data CCBs already and sent themn back up to the periph
driver. Because there's no really clean mechanism yet in CAM to
handle this, a hack has been put into place to complete the CTIO
CCB with the CAM_MESSAGE_RECV status which will have a MODIFY DATA
POINTER extended message in it. The internal ISP target groks this
and ctl(8) will be modified to deal with this as well.

At any rate, the data is retransmitted and an an FCP response is
sent. The whole point here is to successfully complete a command
so that you don't have to depend on ULP (SCSI) to have to recover,
which in the case of tape is not really possible (hence the name
FC-TAPE).

Sponsored by: Spectralogic
MFC after: 1 month


# 9e7d423d 24-Jun-2012 Matt Jacob <mjacob@FreeBSD.org>

Clean up multi-id mode so it's driven by the f/w loaded,
not by some hint setting. Do more preparations for FC-Tape.
Clean up resource counting for 24XX or later chipsets so
we find out after EXEC_FIRMWARE what is actually supported.
Set target mode exchange count based upon whether or not
we are supporting simultaneous target/initiator mode. Clean
up some old (pre-24XX) xfwoption and zfwoption issues.

Sponsored by: Spectralogic
MFC after: 3 days


# e2873b76 01-Jun-2012 Matt Jacob <mjacob@FreeBSD.org>

Clean up and complete the incomplete deferred enable code.
Make the default role NONE if target mode is selected. This
allows ctl(8) to switch to/from target mode via knob settings.
If we default to role 'none', this causes a reset of the
24XX f/w which then causes initiators to wake up and notice
when we come online.

Reviewed by: kdm
MFC after: 2 weeks
Sponsored by: Spectralogic


# f6683e55 27-Dec-2011 Matt Jacob <mjacob@FreeBSD.org>

Fix target mode compilation issues that arose after a change
in the sense data structures.

MFC after: 1 week


# 45210a25 13-Dec-2011 Alexander Motin <mav@FreeBSD.org>

Fix few bugs in isp(4) target mode support:
- in destroy_lun_state() assert hold == 1 instead of 0, as it should
receive hold taken by the create_lun_state() or get_lun_statep() before;
- fix hold count leak inside rls_lun_statep() that also fired above assert;
- in destroy_lun_state() use SIM bus number instead of SIM path id for
ISP_GET_PC_ADDR(), as it was before r196008;
- make isp_disable_lun() to set status in CCB;
- make isp_target_mark_aborted() set status into the proper CCB.

Reviewed by: mjacob
Sponsored by: iXsystems, inc.
MFC after: 1 month


# a0ec8e99 05-Nov-2011 Matt Jacob <mjacob@FreeBSD.org>

Implement the sysctl's for fibre channel that are listed in the man page.

MFC after: 3 days


# e95725cb 13-Aug-2011 Matt Jacob <mjacob@FreeBSD.org>

Most of these changes to isp are to allow for isp.ko unloading.
We also revive loop down freezes. We also externaliz within isp
isp_prt_endcmd so something outside the core module can print
something about a command completing. Also some work in progress to
assist in handling timed out commands better.

Partially Sponsored by: Panasas
Approved by: re (kib)
MFC after: 1 month


# de461933 12-Aug-2011 Matt Jacob <mjacob@FreeBSD.org>

Fixes zombie device and loop down timers so that they work more than
once. Use taskqueues to do the actual work.

Fix an offset line.

Fix isp_prt so that prints from just one buffer, which makes it
appear cleanly cleanly in logs on SMP systems.

Approved by: re (kib)
MFC after: 1 month


# 898899d9 28-Feb-2011 Matt Jacob <mjacob@FreeBSD.org>

Sync FreeBSD ISP with mercurial tree. Minor changes having to do with
a macro for minima.


# 37bb79f1 14-Feb-2011 Marius Strobl <marius@FreeBSD.org>

- Use the correct DMA tag/map pair for synchronize the FC scratch area.
- Allocate coherent DMA memory for the request/response queue area and
and the FC scratch area.

These changes allow isp(4) to work properly on sparc64 with usage of the
IOMMU streaming buffers enabled.

Approved by: mjacob
MFC after: 2 weeks


# c4f65bca 27-Nov-2010 Matt Jacob <mjacob@FreeBSD.org>

Partially revert 208119. We were overwriting tunable settings.

Obtained from: Oleg Sharoyko
MFC after: 1 week


# b1ce21c6 09-Nov-2010 Rebecca Cran <brucec@FreeBSD.org>

Fix typos.

PR: bin/148894
Submitted by: olgeni


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 95f7dfb2 07-Jun-2010 Matt Jacob <mjacob@FreeBSD.org>

Fix XPT_GET_TRAN_SETTING for FC which has been broken for while so that
it will figure out the correct target to handle index and be able to find
things like WWPN, etc.

MFC after: 2 weeks


# 0a100e5b 04-Jun-2010 Matt Jacob <mjacob@FreeBSD.org>

Make the internal target > SPC2 (so REPORT LUNS can be tested).
Give the NIL inquiry data real values other than just plain 0x7f
in the first byte.

MFC after: 2 weeks


# 4962e51b 04-Jun-2010 Matt Jacob <mjacob@FreeBSD.org>

I was getting panics in sleepq_add for the second sleep in isp_kthread.
I don't know why- but it occurred to me in looking at the second sleep
is that all I want is a pause- not an actual sleep. So do that instead.

MFC after: 2 weeks


# a035b0af 02-Jun-2010 Matt Jacob <mjacob@FreeBSD.org>

Various minor and not so minor fixes suggested by Coverity.
In at least one case, it's amazing that target mode worked at all.

Found by: Coverity.
MFC after: 2 weeks


# 0e85f214 26-May-2010 Matt Jacob <mjacob@FreeBSD.org>

Add a new primitive, XPT_SCAN_TGT, to cover the range between scanning a
whole bus (XPT_SCAN_BUS) and a single lun on that bus (XPT_SCAN_LUN).

It's less resource comsumptive than scanning a whole bus when the
caller knows only one target has changes.

Reviewed by: scsi@
Sponsored by: Panasas
MFC after: 1 month


# 7b0f9e6c 26-May-2010 Matt Jacob <mjacob@FreeBSD.org>

This is an MFC of 208119, 208129

Hook up some wires that were forgotten a few months ago and restore
the zombie device timeout code and the loop down time code and the fabric
hysteresis code.

Approved by: re (ken smith)


# 1c0a1eb2 25-May-2010 Matt Jacob <mjacob@FreeBSD.org>

Don't leak CCBs for every ABORT.

Submitted by: Ken Merry
MFC after: One week


# 331c6a35 25-May-2010 Matt Jacob <mjacob@FreeBSD.org>

Remove extra break left by hand editing.

X-MFC: 208542
MFC after: One Month


# dad28623 25-May-2010 Matt Jacob <mjacob@FreeBSD.org>

Treat PRLI the same as PLOGI and make a database entry for it (target mode).

Obtained from: Ken Merry
MFC after: One Month


# a6119ff6 16-May-2010 Matt Jacob <mjacob@FreeBSD.org>

Correct compilation error introduced in last commit.

X-MFC: 208119
MFC after: 1 week
Sponsored By: Panasas
Pointy Hat to: Me
Noticed by: Rob


# 427fa8f9 15-May-2010 Matt Jacob <mjacob@FreeBSD.org>

Whap. Hook up some wires that were forgotten a few months ago and restore
the zombie device timeout code and the loop down time code and the fabric
hysteresis code.
MFC after: 1 week
Sponsored By: Panasas


# fbcd5da2 24-Apr-2010 Matt Jacob <mjacob@FreeBSD.org>

This is an MFC of 205236

Put gone device timer into a structure tag that can hold more than 32 seconds. Oops.

Untangle some of the confusion about what role means when it's in the FCPARAM/SDPARAM
or isp_fc/isp_spi structures. This fixed a problem about seeing targets appear if you've
turned off autologin and find them, or rather don't, via camcontrol rescan.


# 59a8fbd2 05-Apr-2010 Matt Jacob <mjacob@FreeBSD.org>

This is an MFC of 205698

Clean up some printing stuff so that we can have a bit finer control
on debug output. Add a new platform function requirement to allow
for printing based upon the ITL nexus instead of the isp unit plus
channel, target and lun. This allows some printouts and error messages
from the core code to appear in the same format as the platform's
subsystem (in FreeBSD's case, CAM path).


# 670508b1 26-Mar-2010 Matt Jacob <mjacob@FreeBSD.org>

Clean up some printing stuff so that we can have a bit finer control
on debug output. Add a new platform function requirement to allow
for printing based upon the ITL nexus instead of the isp unit plus
channel, target and lun. This allows some printouts and error messages
from the core code to appear in the same format as the platform's
subsystem (in FreeBSD's case, CAM path).

MFC after: 1 week


# 4ecb1d4a 16-Mar-2010 Matt Jacob <mjacob@FreeBSD.org>

Put gone device timer into a structure tag that can hold more than 32 seconds. Oops.

Untangle some of the confusion about what role means when it's in the FCPARAM/SDPARAM
or isp_fc/isp_spi structures. This fixed a problem about seeing targets appear if you've
turned off autologin and find them, or rather don't, via camcontrol rescan.

MFC after: 1 month


# 87aa0933 01-Mar-2010 Matt Jacob <mjacob@FreeBSD.org>

MFC of 204397: fix problems with fast posting handles


# 443e752d 26-Feb-2010 Matt Jacob <mjacob@FreeBSD.org>

Revamp the pieces of some of the stuff I forgot to do when shifting to
32 bit handles. The RIO (reduced interrupt operation) and fast posting
for the parallel SCSI cards were all 16 bit handles. Furthermore,
target mode parallel SCSI only can have 16 bit handles.

Use part of a supplied patch to switch over to using 32 bit handles.
Be a bit more conservative here and only do this for parallel SCSI
for the 12160 (Ultra3) cards. There were a lot of marginal Ultra2
cards, and, frankly, few are findable now for testing.

Fix the target handle routine to only do 16 bit handles for parallel
SCSI cards. This is okay because the upper sixteen bits of the new
32 bit handles is a sequence number to help protect against duplicate
completions. This would be very unlikely to happen with parallel
SCSI target mode, and wasn't present before, so we're no worse off
than we used to be.

While we're at it, finally split the async mailbox completion handlers
into FC and parallel SCSI functions. This makes it much cleaner and
easier to figure out what is or isn't a legal async mailbox completion
code for different card classes.

PR: kern/144250
Submitted partially by: Charles D
MFC after: 1 week


# 94090790 23-Feb-2010 Matt Jacob <mjacob@FreeBSD.org>

xpt_rescan only honors a wildcard in the target field. Revert the previous
change and have isp_make_here scan the whole bus which will then scan all
luns.

I think xpt_rescan needs to be fixed, but that's a separable issue.

Suggested by: Alexander


# 75c1db5d 22-Feb-2010 Matt Jacob <mjacob@FreeBSD.org>

When we rescan, just scan from logical unit 0. In other words, don't
specify a wildcard lun here.

This unbreaks disk re-arrival.

MFC after: 2 days


# 7733cf8f 11-Feb-2010 Matt Jacob <mjacob@FreeBSD.org>

MFC a number of changes from head for ISP (203478,203463,203444,202418,201758,
201408,201325,200089,198822,197373,197372,197214,196162). Since one of those
changes was a semicolon cleanup from somebody else, this touches a lot more.


# c8b8a2c4 03-Feb-2010 Matt Jacob <mjacob@FreeBSD.org>

Redo how commands handles are created and managed and implement sequence
numbers and handle types in rational way. This will better protect from
(unwittingly) dealing with stale handles/commands.

Fix the watchdog timeout code to better protect itself from mistakes.

If we run an abort on a putatively timed out command, the command
may in fact get completed, so check to make sure the command we're
timing it out is still around. If the abort succeeds, btw, the command
should get returned via a different path.


# a01f5aeb 03-Dec-2009 Matt Jacob <mjacob@FreeBSD.org>

Fix cases where we've managed to get a Loop UP event prior to initializing
the loop down counter, as well as other things. This was brought to my
attention with a different fix, more for RELENG_7- this one covers the
multiple channel case.

PR: 140438
MFC after: 1 month


# ae5db118 14-Sep-2009 Matt Jacob <mjacob@FreeBSD.org>

Accomodate old style XPT_IMMED_NOTIFY and XPT_NOTIFY_ACK so that
we at least don't panic.

We don't really support dual role mode (INITIATOR/TARGET) any more. We
should but it's broken and will take a fair amount of effort to fix
and correctly manage both initiator and target roles sharing the port
database. So, for now, disallow it.


# 7922e083 12-Aug-2009 Matt Jacob <mjacob@FreeBSD.org>

MFC 196162: Have at least a fallback WWN so cards on sun branded FC cards
can configure.

Approved by: re


# 5cc3786c 12-Aug-2009 Matt Jacob <mjacob@FreeBSD.org>

Have at least *some* default WWN to fall back on,
otherwise Sun branded FC cards won't configure.

Reviewed by: Ken, Scott
Approved by: re


# 2df76c16 31-Jul-2009 Matt Jacob <mjacob@FreeBSD.org>

Add 8Gb support (isp_2500). Fix a fair number of configuration and
firmware loading bugs.

Target mode support has received some serious attention to make it
more usable and stable.

Some backward compatible additions to CAM have been made that make
target mode async events easier to deal with have also been put
into place.

Further refinement and better support for NP-IV (N-port Virtualization)
is now in place.

Code for release prior to RELENG_7 has been stripped away for code clarity.

Sponsored by: Copan Systems

Reviewed by: scottl, ken, jung-uk kim
Approved by: re


# 0ec60713 10-May-2009 Marius Strobl <marius@FreeBSD.org>

Change uses of the struct ccb_hdr timeout_ch missed when isp(4) was
adapted to MPSAFE cam(4) to a isp(4) specific callout structure.
Thanks to Florian Smeets for providing access to a machine exhibiting
this problem for debugging.

Approved by: mjacob
MFC after: 3 days


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 6bfa9a2d 27-Sep-2008 Ed Schouten <ed@FreeBSD.org>

Replace all calls to minor() with dev2unit().

After I removed all the unit2minor()/minor2unit() calls from the kernel
yesterday, I realised calling minor() everywhere is quite confusing.
Character devices now only have the ability to store a unit number, not
a minor number. Remove the confusion by using dev2unit() everywhere.

This commit could also be considered as a bug fix. A lot of drivers call
minor(), while they should actually be calling dev2unit(). In -CURRENT
this isn't a problem, but it turns out we never had any problem reports
related to that issue in the past. I suspect not many people connect
more than 256 pieces of the same hardware.

Reviewed by: kib


# 3745c395 20-Oct-2007 Julian Elischer <julian@FreeBSD.org>

Rename the kthread_xxx (e.g. kthread_create()) calls
to kproc_xxx as they actually make whole processes.
Thos makes way for us to add REAL kthread_create() and friends
that actually make theads. it turns out that most of these
calls actually end up being moved back to the thread version
when it's added. but we need to make this cosmetic change first.

I'd LOVE to do this rename in 7.0 so that we can eventually MFC the
new kthread_xxx() calls.


# fada2376 23-Aug-2007 Jung-uk Kim <jkim@FreeBSD.org>

Export 4Gbps Fibre Channel link speed correctly with inquiry commands.

Approved by: re (kensmith)
MFC after: 3 days


# 2e4637cd 10-Jul-2007 Matt Jacob <mjacob@FreeBSD.org>

Get rid of a couple of Coverity found sign comparison errors.

Approved by: re (Ken)
MFC after: 3 days


# b50569b7 16-Jun-2007 Scott Long <scottl@FreeBSD.org>

Prepare for future integration between CAM and newbus. xpt_bus_register
now takes a device_t to be the parent of the bus that is being created.
Most SIMs have been updated with a reasonable argument, but a few exceptions
just pass NULL for now. This argument isn't used yet and the newbus
integration likely won't be ready until after 7.0-RELEASE.


# 511ced9b 11-Jun-2007 Matt Jacob <mjacob@FreeBSD.org>

Remove some ioctls that were ill-thought out. There is no user
impact as no softwware using these ioctls was ever committed.

Redo locking for ispioctl.


# 1fd47020 07-Jun-2007 Matt Jacob <mjacob@FreeBSD.org>

Quiet GCC 4.2 warning.


# abeda21e 13-May-2007 Matt Jacob <mjacob@FreeBSD.org>

Temp workaround for config_intrhook_establish running the hook
right away.


# 0a70657f 05-May-2007 Matt Jacob <mjacob@FreeBSD.org>

Make this an MP safe driver but also still be multi-release.
Seems to work on RELENG_4 through -current and also on sparc64
now. There may still be some issues with the auto attach/detach
code to sort out.

MFC after: 3 days


# 8008a935 17-Apr-2007 Scott Long <scottl@FreeBSD.org>

Revert a driver API change to xpt_alloc_ccb that isn't necessary. Fix a
couple of associated error checks.


# 2b83592f 15-Apr-2007 Scott Long <scottl@FreeBSD.org>

Remove Giant from CAM. Drivers (SIMs) now register a mutex that CAM will
use to synchornize and protect all data objects that are used for that
SIM. Drivers that are not yet MPSAFE register Giant and operate as
usual. RIght now, no drivers are MPSAFE, though a few will be changed
in the coming week as this work settles down.

The driver API has changed, so all CAM drivers will need to be recompiled.
The userland API has not changed, so tools like camcontrol do not need to
be recompiled.


# 9a1b0d43 01-Apr-2007 Matt Jacob <mjacob@FreeBSD.org>

Temporarily desupport simultaneous target and initiator mode.

When the linux port changes were imported which split the
target command list to be separate from the initiator command
list and the handle format changed to encode a type in the handle
the implications to the function isp_handle_index (which only
the NetBSD/OpenBSD/FreeBSD ports use) were overlooked.

The fault is twofold: first, the index into the DMA maps
in isp_pci is wrong because a target command handle with
the type bit left in place caused a bad index (and panic)
into dma map. Secondly, the assumption of the array
of DMA maps in either PCS or SBUS attachment structures is
that there is a linear mapping between handle index and
DMA map index. This can no longer be true if there are
overlapping index spaces for initiator mode and target
mode commands.

These changes bandaid around the problem by forcing us
to not have simultaneous dual roles and doing the appropriate
masking to make sure things are indexed correctly. A longer
term fix is being devloped.


# 70273f90 11-Mar-2007 Matt Jacob <mjacob@FreeBSD.org>

Fix compilation issues found in RELENG_4 port and merge the
diffs back to -current to keep versions identical.


# e48b2487 09-Mar-2007 Matt Jacob <mjacob@FreeBSD.org>

Fix some stupid copyright mistakes that have been there for quite some time.


# ffcf6651 22-Feb-2007 Matt Jacob <mjacob@FreeBSD.org>

Use the new xpt_rescan function to truly now have dynamic
attachment of new devices that arrive (and we notice them
via async Fibre Channel events). We've always had the
right thing (of sorts) happen when devices go away- this
is the corollary function that makes multipath failover
actually work.

MFC after: 2 weeks


# 6c81a0ae 19-Jan-2007 Matt Jacob <mjacob@FreeBSD.org>

MFP4: Move default setting to the end of isp_reset instead of the
front of isp_init so we can read NVRAM even if we're role ISP_NONE.
Prepare for reintroduction of channels (for FC) for N-Port
Virtualization.

Fix a botch in handle assignment that caused us to nuke one device
when a new one arrives and end up with two devices with the same
identity in the virtual target mapping table.


# 805e1f82 18-Dec-2006 Matt Jacob <mjacob@FreeBSD.org>

Add back some CAM_NEW_TRAN code to make backporting to RELENG_6 easier.


# a4f3a2be 17-Dec-2006 Matt Jacob <mjacob@FreeBSD.org>

Try an experiment with using DMA to load firmware into a 2200- VERIFY
CHECKSUM fails. Oh well, but keep a couple of the changes.

Avoid overflow in usec counters when waiting for mailbox completion.


# 9b03492a 08-Dec-2006 Matt Jacob <mjacob@FreeBSD.org>

Find another spot where tagged command queueing got
accidentally nuked.


# dd9fc7c3 05-Dec-2006 Matt Jacob <mjacob@FreeBSD.org>

Make ISPCTL_PLOGX find a handle to log into the management server
with- not hope for the best. Change some things which were gated
off of 24XX to be gated off of 2K login support. Convert some
isp_prt calls to xpt_print calls.


# b61386a4 03-Dec-2006 Matt Jacob <mjacob@FreeBSD.org>

Fix XPT_GET_TRANSPORT_SETTINGS to zero validity and flags-
this was causing us to not negotiate sync at all, or at
random.


# f7c631bc 14-Nov-2006 Matt Jacob <mjacob@FreeBSD.org>

Push things closer to path failover by implementing loop down and
gone device timers and zombie state entries. There are tunables
that can be used to select a number of parameters.

loop_down_limit - how long to wait for loop to come back up before
declaring
all devices dead (default 300 seconds)

gone_device_time- how long to wait for a device that has appeared
to leave the loop or fabric to reappear (default 30 seconds)

Internal tunables include (which should be externalized):

quick_boot_time- how long to wait when booting for loop to come up

change_is_bad- whether or not to accept devices with the same
WWNN/WWPN that reappear at a different PortID as being the 'same'
device.

Keen students of some of the subtle issues here will ask how
one can keep devices from being re-accepted at all (the answer
is to set a gone_device_time to zero- that effectively would
be the same thing).


# 10365e5a 01-Nov-2006 Matt Jacob <mjacob@FreeBSD.org>

Add 4Gb (24XX) support and lay the foundation for a lot of new stuff.


# bd3fd815 01-Nov-2006 Matt Jacob <mjacob@FreeBSD.org>

2nd and final commit that moves us to CAM_NEW_TRAN_CODE
as the default.

Reviewed by multitudes.


# fa9ed865 30-Oct-2006 Matt Jacob <mjacob@FreeBSD.org>

The first of 3 major steps to move the CAM layer forward to using
the CAM_NEW_TRAN_CODE that has been in the tree for some years now.

This first step consists solely of adding to or correcting
CAM_NEW_TRAN_CODE pieces in the kernel source tree such
that a both a GENERIC (at least on i386) and a LINT build
with CAM_NEW_TRAN_CODE as an option will compile correctly
and run (at least with some the h/w I have).

After a short settle time, the other pieces (making
CAM_NEW_TRAN_CODE the default and updating libcam
and camcontrol) will be brought in.

This will be an incompatible change in that the size of structures
related to XPT_PATH_INQ and XPT_{GET,SET}_TRAN_SETTINGS change
in both size and content. However, basic system operation and
basic system utilities work well enough with this change.

Reviewed by: freebsd-scsi and specific stakeholders


# 9311717d 25-Sep-2006 Matt Jacob <mjacob@FreeBSD.org>

Begin the process of moving info to sysctl stuff for FreeBSD
by providing OIDs for WWNN/WWPN and Initiator ID.


# 784ed707 31-Aug-2006 Matt Jacob <mjacob@FreeBSD.org>

Add missing pre-7.0 firmware pointer. Oops.


# f0f536d1 04-Aug-2006 Matt Jacob <mjacob@FreeBSD.org>

Rename ioctl driven task management functions so they
don't collide with task management definitions on other
platforms.


# 799881e0 16-Jul-2006 Matt Jacob <mjacob@FreeBSD.org>

Some rearrangement of headers to minimize diffs with outside of
FreeBSD repository and to clean up the license header so as to
not pollute the license with file function.

Zero all mailbox structures prior to use (just in case). Change
the outgoing mailbox count for INIT_FIRMWARE to be correct.


# 02e2b2d9 10-Jul-2006 Matt Jacob <mjacob@FreeBSD.org>

Clean up the ioctl to not process nonsense on SCSI isp cards.

MFC after: 1 month


# 9a5af410 09-Jul-2006 Matt Jacob <mjacob@FreeBSD.org>

Convert isp(4) and ispfw(4) to use firmware(9) to manage firmware
loading for the QLogic cards.

Because isp(4) exists before the root is mounted, it's not really
possible for us to use the kernel's linker to load modules directly
from disk- that's really too bad.

However, the this is still a net win in in that the firmware has
been split up on a per chip (and in some cases, functionality)
basis, so the amount of stuff loaded *can* be substantially less
than the 1.5MB of firmware images that ispfw now manages. That is,
each specific f/w set is now also built as a module. For example,
QLogic 2322 f/w is built as isp_2322.ko and Initiator/Target 1080
firmware is built as isp_1080_it.ko.

For compatibility purposes (i.e., to perturb folks the least), we
also still build all of the firmware as one ispfw.ko module.

This allows us to let 'ispfw_LOAD' keep on working in existing
loader.conf files. If you now want to strip this down to just
the firmware for your h/w, you can then change loader.conf to
load the f/w you specifically want.

We also still allow for ispfw to be statically built (e.g., for
PAE and sparc64).

Future changes will look at f/w unloading and also role switching
that then uses the kernel linker to load different ips f/w sets.
MFC after: 2 months


# 6b5ec766 30-May-2006 Matt Jacob <mjacob@FreeBSD.org>

Don't set CAM_DEV_QFRZN when we get an ABORT_TASK. Just
by itself, this makes no sense.


# d4a6993a 22-May-2006 Matt Jacob <mjacob@FreeBSD.org>

Add missing case for RQSTYPE_CTIO3- neede for 64 bit target mode.


# 29f76675 22-May-2006 Matt Jacob <mjacob@FreeBSD.org>

Remove bzero/bcopy vestiges.

Be cognizant as to whether we're running 2KLogin f/w in target mode and
do the appropriate loopid load based upon that.


# 8c4e89e2 21-Apr-2006 Matt Jacob <mjacob@FreeBSD.org>

Redo some code based upon issues found by Coverity.


# 9cd7268e 21-Apr-2006 Matt Jacob <mjacob@FreeBSD.org>

Some more gratuitous format and name changes.

Pull in some target mode changes from a private branch.
Pull in some more RELENG_4 compilation changes.

A lot of lines changed, but not much content change yet.


# c1504bc0 03-Mar-2006 Matt Jacob <mjacob@FreeBSD.org>

micro fix from justin


# c6435ff3 26-Feb-2006 Matt Jacob <mjacob@FreeBSD.org>

propagate role of device for ISP_GET_PDBINFO


# 1dae40eb 14-Feb-2006 Matt Jacob <mjacob@FreeBSD.org>

a) clean up some declaration stuff (i.e., make more modern with respect
to getting rid u_int for uint and so on).

b) Turn back on 64 bit DAC support. Cheeze it a bit in that we have two
DMA callback functions- one when we have bus_addr_t > 4 bits in width and
the other which should be normal. Even Cheezier in that we turn off setting
up DMA maps to be BUS_SPACE_MAXADDR if we're in ISP_TARGET_MODE. More work
on this in a week or so.

c) Tested under amd64 and 1MB DFLTPHYS, sparc64, i386 (PAE, but insufficient
memory to really test > 4GB). LINT check under amd64.

MFC after: 1 month


# 53af7d22 02-Feb-2006 Matt Jacob <mjacob@FreeBSD.org>

Remove use of inlines and use the functions as a library.

Larger code space, possibly performance hit, but more portable.
Certainly less questionable use of inlining.

Suggested by: des


# e5265237 22-Jan-2006 Matt Jacob <mjacob@FreeBSD.org>

First of several commits as this driver is dusted off and maybe brought
up to date. Principle changes for this reelase is to support 2K Port Login
firmware. This allows us to support the 2322 (and 2422 4Gb) cards which only
come with the 2K Port Login firmware. The 2322 should now work- but we don't
have firmware sets for it in ispfw (as the change to load 2K Port Login f/w
hasn't been made- that f/w is so big it has to be loaded in more than one
chunk).

Other changes are the beginnings of cleaning up some long standing target
mode issues. The next changes here will incorporate a lot of bug fixes
from others.

Finally, some copyright cleanup and attempts to make the parts of the
driver that are FreeBSD specific start conforming more to FreeBSD style.

MFC after: 1 month


# 8e62a8ac 28-Oct-2005 Matt Jacob <mjacob@FreeBSD.org>

Add an ioctl framework for doing FC task management functions from
a user space tool- useful for doing FC target mode certification.


# 9f242f78 31-Jul-2005 Matt Jacob <mjacob@FreeBSD.org>

AT_MAKE_TAGID needs an instance as the 2nd arg- not just a 0.


# da6297fc 23-Jan-2005 Scott Long <scottl@FreeBSD.org>

Provide a needed argument to AT_MAKE_TAGID.


# 098ca2bd 05-Jan-2005 Warner Losh <imp@FreeBSD.org>

Start each of the license/copyright comments with /*-, minor shuffle of lines


# e3e49f7e 23-Aug-2004 Matt Jacob <mjacob@FreeBSD.org>

Until I can get a clearer architecture from PHK about why he wants
the geometry code to grab a mutex that prohibits any driver on the
stack below it from sleeping, it's not safe to allow anything in
the top half of isp to sleep (excepting the thread that Fibre Channel
instances use to re-scan loops/fabrics).


# 89c9c53d 16-Jun-2004 Poul-Henning Kamp <phk@FreeBSD.org>

Do the dreaded s/dev_t/struct cdev */
Bump __FreeBSD_version accordingly.


# 51e23558 24-May-2004 Nate Lawson <njl@FreeBSD.org>

Store the target handles in a separate list from normal commands. Add a
CTIO fast post routine to handle CTIO completions.

Submitted by: mjacob


# dc08ffec 21-Feb-2004 Poul-Henning Kamp <phk@FreeBSD.org>

Device megapatch 4/6:

Introduce d_version field in struct cdevsw, this must always be
initialized to D_VERSION.

Flip sense of D_NOGIANT flag to D_NEEDGIANT, this involves removing
four D_NOGIANT flags and adding 145 D_NEEDGIANT flags.


# c9c7976f 21-Feb-2004 Poul-Henning Kamp <phk@FreeBSD.org>

Device megapatch 1/6:

Free approx 86 major numbers with a mostly automatically generated patch.

A number of strategic drivers have been left behind by caution, and a few
because they still (ab)use their major number.


# 9b81514d 16-Feb-2004 Matt Jacob <mjacob@FreeBSD.org>

We aren't D_TAPE. We aren't anything. The reasons why this was ever set
at all is lost in the mists of time.


# 67ff51f1 08-Feb-2004 Matt Jacob <mjacob@FreeBSD.org>

Remove condition variables and status associated with target mode
enabling. Instead, go to an interrupt/polled model.

Fix get_lun_statep so we don't panic if there are no wildcard luns enabled.

MFC after: 6 days


# 746e9c85 06-Feb-2004 Matt Jacob <mjacob@FreeBSD.org>

Checkpoint of work in progress in cleaning up target mode. It actually
seems to work well in RELENG_4. However, 5.X locking foo means that I'll
have to do some quick redesign.

Add ioctl handlers for ISP_GETROLE and ISP_SETROLE ioctls.


# a556b68e 23-Jan-2004 Matt Jacob <mjacob@FreeBSD.org>

Add firmware major, minor and micro revsions to the ISP_FC_GETHINFO ioctl
structure.


# 70cd7713 26-Sep-2003 Poul-Henning Kamp <phk@FreeBSD.org>

The present defaults for the open and close for device drivers which
provide no methods does not make any sense, and is not used by any
driver.

It is a pretty hard to come up with even a theoretical concept of
a device driver which would always fail open and close with ENODEV.

Change the defaults to be nullopen() and nullclose() which simply
does nothing.

Remove explicit initializations to these from the drivers which
already used them.


# 56c5b842 15-Sep-2003 Mark Murray <markm@FreeBSD.org>

Add a module dependancy. Now CAM will autoload when you load this.

OK'ed by: mdodd


# fd6eb9f7 12-Sep-2003 Matt Jacob <mjacob@FreeBSD.org>

Report correct active vs. nvram node/port WWNs in an ioctl.


# aad970f1 24-Aug-2003 David E. O'Brien <obrien@FreeBSD.org>

Use __FBSDID().
Also some minor style cleanups.


# 2813692c 14-Jun-2003 Nate Lawson <njl@FreeBSD.org>

Merge common XPT_CALC_GEOMETRY functions into a single convenience function.
Devices below may experience a change in geometry.

* Due to a bug, aic(4) never used extended geometry. Changes all drives
>1G to now use extended translation.
* sbp(4) drives exactly 1 GB in size now no longer use extended geometry.
* umass(4) drives exactly 1 GB in size now no longer use extended geometry.

For all other controllers in this commit, this should be a no-op.

Looked over by: scottl


# 7ac40f5f 02-Mar-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Gigacommit to improve device-driver source compatibility between
branches:

Initialize struct cdevsw using C99 sparse initializtion and remove
all initializations to default values.

This patch is automatically generated and has been tested by compiling
LINT with all the fields in struct cdevsw in reverse order on alpha,
sparc64 and i386.

Approved by: re(scottl)


# 41ed683e 10-Oct-2002 Matt Jacob <mjacob@FreeBSD.org>

From PHK's flex tool- we can get -1 returned from xpt_path_target_id,
so don't index off of it.

MFC after: 1 day


# 316ec49a 02-Oct-2002 Scott Long <scottl@FreeBSD.org>

Some kernel threads try to do significant work, and the default KSTACK_PAGES
doesn't give them enough stack to do much before blowing away the pcb.
This adds MI and MD code to allow the allocation of an alternate kstack
who's size can be speficied when calling kthread_create. Passing the
value 0 prevents the alternate kstack from being created. Note that the
ia64 MD code is missing for now, and PowerPC was only partially written
due to the pmap.c being incomplete there.
Though this patch does not modify anything to make use of the alternate
kstack, acpi and usb are good candidates.

Reviewed by: jake, peter, jhb


# ee76282e 06-Sep-2002 Matt Jacob <mjacob@FreeBSD.org>

Tsk. Now that we're not using our own locks, we have to remember
to grab Giant in isp_kthread so that msleep is *happy* that there's
no lock being passed to it (as tsleep turns out to be...)


# 162e9893 02-Sep-2002 Matt Jacob <mjacob@FreeBSD.org>

Turn off usage of SMP style locking until we sort out CAM.


# fecafa5c 22-Aug-2002 Matt Jacob <mjacob@FreeBSD.org>

unused variable removal (pointed out by bde)


# 8a5f89b9 17-Aug-2002 Matt Jacob <mjacob@FreeBSD.org>

We only do isp_reinit from isp_async if ISP_FW_CRASH_DUMP is defined-
otherwise the core code does this.


# 4eb49427 25-Jul-2002 Matt Jacob <mjacob@FreeBSD.org>

Put MODULE_VERSION back here so that ispfw is happy.


# 73030e03 10-Jul-2002 Matt Jacob <mjacob@FreeBSD.org>

'Support' for ISP SBus cards.

This code does not imply that SBus cards work yet. They hang for me.
But I can't netboot the latest snapshot on my ultra1e, and things
hang at bus_setup_intr time.

Since I'm offline for a while, I thought I'd toss this in in case somebody
else who has a bit better luck wants to fart around with it. Please try
and wait until I get back to check things in.


# fdeb9f2f 08-Jul-2002 Matt Jacob <mjacob@FreeBSD.org>

Add get/set param ioctl support.

Remove sim queue freezes for resource shortages. I've had too many
strange race conditions where I freeze on a resource shortage but
never get unfrozen.

Consolidate the remaining sim queue freeze condition (for loopdown)
into an inline with debug messages that allows us to track problems
at ISP_LOGDEBUG0 level easier. Change a bunch of debug messages about
loop down/up conditions to ISP_LOGDEBUG0 level.

Remove dead isp_relsim code.

Change some internal flag stuff for efficiency.

Complain vociferously if we try and use our FC scratch area while it's
busy being used already (I mean, if we don't have solaris' ability
to sleep as an interrupt thread which would allow us to just use
a p/v semaphore, at least *say* when you've just borked yourself).

Add infrastructure to allow overrides of hard loopid && initiator
id from boot variables.

Fix the usual quota of silly bugs:

+ 'ktmature' needs to be per-instance. Argh.
+ When entering isp_watchdog, set intsok to zero, preserving
old value to restore later. It's not nice to try and sleep
from splsoftclock.
+ Fix tick overflow buglet in checking timeout value.

MFC after: 1 week


# 570c7a3f 15-Jun-2002 Matt Jacob <mjacob@FreeBSD.org>

Add support for ISP_FC_GETHINFO, which returns current connection
topology, speed, loopid, WWPN/WWNN, etc.

Beef up target mode. Add isp_handle_platform_notify_scsi and
isp_handle_platform_notify_fc platform handlers to handle immediate
notifies (isp_handle_platform_notify_scsi is still stubbed out).

In implementation of isp_handle_platform_notify_fc, for IN_ABORT_TASK,
peel off a pending XPT_IMMED_NOTIFY and call xpt_done on it and hope
that somebody upstream is listening.

Make sure on final CTIO2s that we set residual correctly. These are
absolutely crucial. Make sure we set relative offset for each CTIO2
based upon bytes we've already xferred. This is what the private
adjunct datat to the original ATIO is. Note state of command so
we can figure out where to find it if we get an ABORT from the firmware.

Make sure we *always* set CAM_TAG_ACTION_VALID for ATIO2s. Make sure
we keep track of the original lun.

If se sent status (or we're otherwise done with the command), don't
forget to free the adjunct structure.


# 029f13c6 04-Apr-2002 Matt Jacob <mjacob@FreeBSD.org>

Fix bus dma segment count to be based off of MAXPHYS, not BUS_SPACE_MAXSIZE.
Grumble. I've seen better documented architectures out of Redmond.

Redo fabric evaluation to not use GET ALL NEXT (GA_NXT). Switches seem
to be trying to wriggle out of supporting this well. Instead, use
GID_FT to get a list of Port IDs and then use GPN_ID/GNN_ID to find the
port and node wwn. This should make working on fabrics a bit cleaner and
more stable.

This also caused some cleanup of SNS subcommand canonicalization so that
we can actually check for FS_ACC and FS_RJT, and if we get an FS_RJT,
print out the reason and explanation codes.

We'll keep the old GA_NXT method around if people want to uncomment a
controlling definition in ispvar.h.

This also had us clean up ISPASYNC_FABRICDEV to use a local lportdb argument
and to have the caller explicitly say that a device is at the end of the
fabric list.

MFC after: 1 week


# f553351e 21-Feb-2002 Matt Jacob <mjacob@FreeBSD.org>

Reorder some of the ioctls and add a few new ones.

MFC after: 1 day


# d134aa0b 17-Feb-2002 Matt Jacob <mjacob@FreeBSD.org>

More for f/w crash dumps (bug fixing and adding ioctl entry points
and hints to enable for specific units)

MFC after: 1 week


# 2903b272 03-Jan-2002 Matt Jacob <mjacob@FreeBSD.org>

Implement REDUCED INTERRUPT OPERATION usage form FC cards- this allows the
firmware to delay completion of commands so that it can attempt to batch
a bunch of completions at once- either returning 16 bit handles in mailbox
registers, or in a resposne queue entry that has a whole wad of 16 bit handles.

Distinguish between 2300 and 2312 chipsets- if only because the revisions
on the chips have different meanings.

Add more instrumentation plus ISP_GET_STATS and ISP_CLR_STATS ioctls.
Run up the maximum number of response queue entities we'll look at
per interrupt.

If we haven't set HBA role yet, always return success from isp_fc_runstate.

MFC after: 2 weeks


# 4fd13c1b 10-Dec-2001 Matt Jacob <mjacob@FreeBSD.org>

Major restructuring for swizzling to the request queue and unswizzling from
the response queue. Instead of the ad hoc ISP_SWIZZLE_REQUEST, we now have
a complete set of inline functions in isp_inline.h. Each platform is
responsible for providing just one of a set of ISP_IOX_{GET,PUT}{8,16,32}
macros.

The reason this needs to be done is that we need to have a single set of
functions that will work correctly on multiple architectures for both little
and big endian machines. It also needs to work correctly in the case that
we have the request or response queues in memory that has to be treated
specially (e.g., have ddi_dma_sync called on it for Solaris after we update
it or before we read from it). It also has to handle the SBus cards (for
platforms that have them) which, while on a Big Endian machine, do *not*
require *most* of the request/response queue entry fields to be swizzled
or unswizzled.

One thing that falls out of this is that we no longer build requests in the
request queue itself. Instead, we build the request locally (e.g., on the
stack) and then as part of the swizzling operation, copy it to the request
queue entry we've allocated. I thought long and hard about whether this was
too expensive a change to make as it in a lot of cases requires an extra
copy. On balance, the flexbility is worth it. With any luck, the entry that
we build locally stays in a processor writeback cache (after all, it's only
64 bytes) so that the cost of actually flushing it to the memory area that is
the shared queue with the PCI device is not all that expensive. We may examine
this again and try to get clever in the future to try and avoid copies.

Another change that falls out of this is that MEMORYBARRIER should be taken
a lot more seriously. The macro ISP_ADD_REQUEST does a MEMORYBARRIER on the
entry being added. But there had been many other places this had been missing.
It's now very important that it be done.

Additional changes:

Fix a longstanding buglet of sorts. When we get an entry via isp_getrqentry,
the iptr value that gets returned is the value we intend to eventually plug
into the ISP registers as the entry *one past* the last one we've written-
*not* the current entry we're updating. All along we've been calling sync
functions on the wrong index value. Argh. The 'fix' here is to rename all
'iptr' variables as 'nxti' to remember that this is the 'next' pointer-
not the current pointer.

Devote a single bit to mboxbsy- and set aside bits for output mbox registers
that we need to pick up- we can have at least one command which does not
have any defined output registers (MBOX_EXECUTE_FIRMWARE).

MFC after: 2 weeks


# 53036e92 30-Sep-2001 Matt Jacob <mjacob@FreeBSD.org>

Begin to implement target mode that for Fibre Channel has a private
per-command component that we *don't* try and pass thru CAM. CAM just
is too risky and too much of a pain- structures get copied, but not
all info of interest can be considered safely transported thru all
consumers (including user space) from the incoming ATIO to the outgoing
CTIO- it's just much safer to have a buddy structure, identified by the
command's tag which *does* make it thru safely.

Pay attention to link speed and report 200MB/s xfer speed for a
23XX card in 2GPs mode.

MFC after: 1 week


# b40ce416 12-Sep-2001 Julian Elischer <julian@FreeBSD.org>

KSE Milestone 2
Note ALL MODULES MUST BE RECOMPILED
make the kernel aware that there are smaller units of scheduling than the
process. (but only allow one thread per process at this time).
This is functionally equivalent to teh previousl -current except
that there is a thread associated with each process.

Sorry john! (your next MFC will be a doosie!)

Reviewed by: peter@freebsd.org, dillon@freebsd.org

X-MFC after: ha ha ha ha


# 64edff94 04-Sep-2001 Matt Jacob <mjacob@FreeBSD.org>

I don't know what I was thinking- if I have two separate busses on on
SIM (as is true for the 1280 and the 12160), then I have to have separate
flags && status for *both* busses. *Whap*.

Implement condition variables for coordination with some target mode
events. It's nice to use these and not panic in obscure little places
in the kernel like 'propagate_priority' just because we went to sleep
holding a mutex, or some other absurd thing.

Remove some bogus ISP_UNLOCK calls. *Whap*.

No longer require that somebody do a lun enable on the wildcard device
to enable target mode. They are, in fact, orthogonal. A wildcard open
is a statement that somebody upstream is willing to accept commands which
are otherwise unrouteable. Now, for QLogic regular SCSI target mode, this
won't matter for a damn because we'll never see ATIOs for luns we haven't
enabled (are listening for, if you will). But for SCCLUN fibre channel
SCSI, we get all kinds of ATIOs. We can either reflect them back here
with minimal info (which is isp_target.c:isp_endcmd() is for), or the
wildcard device (nominally targbh) can handle them.

Do further checking against firmware attributes to see whether we can,
in fact, support target mode in Fibre Channel. For now, require SCCLUN
f/w to supoprt FC target mode.

This is an awful lot of change, but target mode *still* isn't quite right.

MFC after: 4 weeks


# 126ec864 31-Aug-2001 Matt Jacob <mjacob@FreeBSD.org>

Add 2 Gigabit Fibre Channel support (2300 && 2312 cards). This required
some reworking (and consequent cleanup) of the interrupt service code.

Also begin to start a cleanup of target mode support that will (eventually)
not require more inforamtion routed with the ATIO to come back with the
CTIO other than tag.

MFC after: 4 weeks


# be534d5f 16-Aug-2001 Matt Jacob <mjacob@FreeBSD.org>

Thanks to PHK for spotting: ISPASYNC_UNHANDLED_RESPONSE not
handle in isp_async.


# 9ce9bdaf 29-Jul-2001 Matt Jacob <mjacob@FreeBSD.org>

Redo how we manage SCSI device settings- have a 3rd flags (nvram) that records
either what's in NVRAM or what the safe defaults would be if we lack NVRAM.
Then we rename cur_XXXX to actv_XXXX (these are the currently active settings)
and the dev_XXX settings to goal_XXXX (these are the settings which we want
cur_XXXX to converge to).

This probably isn't entirely final as yet- but it's a lot closer to now
being what it should be, including allowing camcontrol to actually set
specific settings.


# f44257c2 24-Jul-2001 Matt Jacob <mjacob@FreeBSD.org>

Remove ISP_SMPLOCK stuff- we're just using locking now.

Correctly reintroduce loop_seen_once semantics- that is, if we've never
seen good link, start bouncing commands with CAM_SEL_TIMEOUT. But we
have to be careful to have let ourselves try (in isp_kthread) to check
for loop up at least once.

PR: 28992
MFC after: 1 week


# 8e6a12fc 05-Jul-2001 Matt Jacob <mjacob@FreeBSD.org>

Oops- missed a CAMLOCK_2_ISP case.


# 45c9a36a 05-Jul-2001 Matt Jacob <mjacob@FreeBSD.org>

Things have become cinched down more tightly about assertions for Giant.
This uncovered some missing spots where I trade off between isp's lock
and Giant as I enter CAM.


# ab163f5f 04-Jul-2001 Matt Jacob <mjacob@FreeBSD.org>

Add CAM_NEW_TRAN_CODE support. Use correct CAMLOCK_2_ISPLOCK macros.

For fibre channel, start going for the gusto and using AC_FOUND_DEVICE
and AC_LOST_DEVICE calls to xpt_async when devices appear and disappear
as the loop or fabric changes.

ISPASYNC_FW_CRASH is the async event code where the platform layer
deals with a firmware crash.


# 5d571944 28-May-2001 Matt Jacob <mjacob@FreeBSD.org>

Spring MegaChange #1.

----

Make a device for each ISP- really usable only with devfs and add an ioctl
entry point (this can be used to (re)set debug levels, reset the HBA,
rescan the fabric, issue lips, etc).

----

Add in a kernel thread for Fibre Channel cards. The purpose of this
thread is to be woken up to clean up after Fibre Channel events
block things. Basically, any FC event that casts doubt on the
location or identify of FC devices blocks the queues. When, and
if, we get the PORT DATABASE CHANGED or NAME SERVER DATABASE CHANGED
async event, we activate the kthread which will then, in full thread
context, re-evaluate the local loop and/or the fabric. When it's
satisfied that things are stable, it can then release the blocked
queues and let commands flow again.

The prior mechanism was a lazy evaluation. That is, the next command
to come down the pipe after change events would pay the full price
for re-evaluation. And if this was done off of a softcall, it really
could hang up the system.

These changes brings the FreeBSD port more in line with the Solaris,
Linux and NetBSD ports. It also, more importantly, gets us being
more proactive about topology changes which could then be reflected
upwards to CAM so that the periph driver can be informed sooner
rather than later when things arrive or depart.

---

Add in the (correct) usage of locking macros- we now have lock transition
macros which allow us to transition from holding the CAM lock (Giant)
and grabbing the softc lock and vice versa. Switch over to having this
HBA do real locking. Some folks claim this won't be a win. They're right.
But you have to start somewhere, and this will begin to teach us how
to DTRT for HBAs, etc.

--

Start putting in prototype 2300 support. Add back in LIP
and Loop Reset as async events that each platform will handle.
Add in another int_bogus instrumentation point.

Do some more substantial target mode cleanups.

MFC after: 8 weeks


# a1bc34c6 04-Apr-2001 Matt Jacob <mjacob@FreeBSD.org>

Redo a lot of the target mode infrastructure to be cognizant of Dual Bus
cards like the 1280 && the 12160. Cleanup isp_target_putback_atio.
Make sure bus and correct tag ids and firmware handles get propagated
as needed.


# 290dc24b 20-Mar-2001 Matt Jacob <mjacob@FreeBSD.org>

Check CT2_SENDSTATUS/CT_SENDSTATUS against cto->ct_flags, not
CAM_SEND_STATUS. Set a timeout of 2 seconds per CTIO. Make sure
that the 'real' tag value is being checked against- not the
one that also carries the firmware handle.


# 5f5aafe1 01-Mar-2001 Matt Jacob <mjacob@FreeBSD.org>

Switch to using 16 bit handles instead of 32 bit handles.
This is a pretty invasive change, but there are three good
reasons to do this:

1. We'll never have > 16 bits of handle.
2. We can (eventually) enable the RIO (Reduced Interrupt Operation)
bits which return multiple completing 16 bit handles in mailbox
registers.
3. The !)$*)$*~)@$*~)$* Qlogic target mode for parallel SCSI spec
changed such that at_reserved (which was 32 bits) was split into
two pieces- and one of which was a 16 bit handle id that functions
like the at_rxid for Fibre Channel (a tag for the f/w to correlate
CTIOs with a particular command). Since we had to muck with that
and this changed the whole handler architecture, we might as well...

Propagate new at_handle on through int ct_fwhandle. Follow
implications of changing to 16 bit handles.

These above changes at least get Qlogic 1040 cards working in target
mode again. 1080/12160 cards don't work yet.

In isp.c:
Prepare for doing all loop management in outer layers.


# 3c75bb14 28-Feb-2001 Matt Jacob <mjacob@FreeBSD.org>

Finally eliminate as many of the printf calls as possible (still leaving
ones where we have a CAM path) and replacing them with calls to isp_prt.,

Eliminate isp_unit references- we no longer have an isp_unit- we now
have an isp_dev that device_get_unit can work with.


# b0a3ba7e 26-Feb-2001 Matt Jacob <mjacob@FreeBSD.org>

Fix at2_entry_t to reflect what the firmware actually writes (instead
of just deriving from SCSI at_entry_t). In this case, there is no
'suggested sense' for FC cards.


# d6e5500f 10-Feb-2001 Matt Jacob <mjacob@FreeBSD.org>

Do some cleanup based upon adapter role- mainly not enabling interrupts
if we're ISP_ROLE_NONE. Change ISPASYNC_LOGGED_INOUT to ISPASYNC_PROMENADE.
Make sure we note if something is a fabric device.

Target mode:
Finally fix (to a first approximation) SCSI Target Mode again- we needed
to correctly check against CAM_TARGET_WILDCARD and CAM_LUN_WILDCARD
so that targbh won't confuse us. Comment out the drainqueue stuff for
now. Use isp_fc_runstate instead if isp_control/ISPCTL_FCLINK_TEST.


# 9ed346ba 08-Feb-2001 Bosko Milekic <bmilekic@FreeBSD.org>

Change and clean the mutex lock interface.

mtx_enter(lock, type) becomes:

mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)

similarily, for releasing a lock, we now have:

mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.

The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.

Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:

MTX_QUIET and MTX_NOSWITCH

The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:

mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.

Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.

Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.

Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.

Finally, caught up to the interface changes in all sys code.

Contributors: jake, jhb, jasone (in no particular order)


# d69a5f7d 16-Jan-2001 Matt Jacob <mjacob@FreeBSD.org>

Guard against overflow of the calculated timeout value.


# 70d2ccce 15-Jan-2001 Matt Jacob <mjacob@FreeBSD.org>

Do more cleanup of the usage of 0..125 for F-port topologies.


# 4b9d588e 08-Jan-2001 Matt Jacob <mjacob@FreeBSD.org>

Follow the ISPASYNC_PDB_CHANGED -> ISPASYNC_LOGGED_INOUT change. Also,
ISPASYNC_NOTIFY_CHANGE now is for both local loop && fabric changes.


# 91f1caa2 31-Dec-2000 Matt Jacob <mjacob@FreeBSD.org>

Fix problems with incomplete conversions from printf to isp_prt.


# c40e096e 29-Dec-2000 Matt Jacob <mjacob@FreeBSD.org>

Make sure we do locking if we call isp_intr.
Make sure we enter Giant for now if we call into cam for completion.


# bfbab170 05-Dec-2000 Matt Jacob <mjacob@FreeBSD.org>

Replace some more printfs with isp_prt's. Use isp_prt/ISP_LOGDEBUG0
for rate setting/getting printouts.


# ea8b5a9a 03-Dec-2000 David Malone <dwmalone@FreeBSD.org>

More M_ZERO patches.

Submitted by: josh@zipperup.org
Submitted by: Robert Drehmel <robd@gmx.net>
Approved by: mjacob


# 39f3fc6f 17-Oct-2000 Matt Jacob <mjacob@FreeBSD.org>

remove "SERVICING_INTERRUPT" nonsense


# aa57fd6f 21-Sep-2000 Matt Jacob <mjacob@FreeBSD.org>

some copyright cleanups


# b6b6ad2f 27-Aug-2000 Matt Jacob <mjacob@FreeBSD.org>

various fixes


# 3ea883b4 02-Aug-2000 Matt Jacob <mjacob@FreeBSD.org>

Add a comment as to where stdarg.h applies.


# 7d615c1d 02-Aug-2000 John Baldwin <jhb@FreeBSD.org>

Use <machine/stdarg.h> instead of <stdarg.h> so that this will compile.
While I'm at it, move the #include line up to the top of the file.


# b09b0095 01-Aug-2000 Matt Jacob <mjacob@FreeBSD.org>

Core version 2.0 rewrite. In this file we replace isp_tdebug with
isp_prt calls. We now use an argument to the ISPCTL_FCLINK_TEST
call. We change all IDPRINTF macros to isp_prt calls. We add
the isp_prt function here.


# f48ce188 18-Jul-2000 Matt Jacob <mjacob@FreeBSD.org>

Add a isp_target_putback_atio- we aren't using CCINCR at this time, so
we need a function that tells the Qlogic f/w that a target mode command
is done, so increase the resource count for that lun. Add in a timeout
function to kick the putback again if we fail to do it the first time (we
may not have the request queue space for ATIO push). Split the function
isp_handle_platform_ctio into two parts so that the timeout function for
the ATIO push or isp_handle_platform_ctio can inform CAM that the requested
CTIO(s) are now done.

Clean up (cough) residual handling. What we need for Fibre Channel
is to preserve the at_datalen field from the original incoming ATIO
so we can calculate a 'true' residual. Unfortunately, we're not
guaranteed to get that back from CAM. We'll *try* to find it hiding
in the periph_priv field (layering violation)- but if an ATIO was
passed in from user land- forget it. This means that we'll probably
get residuals wrong for Fibre Channel commands we're completing
with an error. It's too late to 4.1 release to fix this- too bad.
Luckily the only device we'd really care about this occurring on
is a tape device and they're still so rare as FC attached devices
that this can be considered an untested combination anyway.

Remove all CCINCR usage (resource autoreplenish). When we've proved
to ourself that things are working properly, we can add it back
in.

Make sure we propage 'suggested' sense data from the incoming ATIO
into the created system ATIO- and set sense_len appropriately.
Correctly propagate tag values.

Fall back to the model of generating (well, the functions in isp_pci.c
do the work) multiple CTIOs based upon what we get from XPT. Instead
of being able to pair Qlogic generated ATIOs with CAM ATIOs, and then
to pair CAM CTIOs with Qlogic CTIOs, we have to take the CTIO passed
to us from XPT, and if it implies that we have to generate extra
Qlogic CTIOs, so be it. This means that we have to wait until the
last CTIO in a sequence we generated completes before calling xpt_done.

Executive summary- target mode actually now pretty much works well
enough to tell folks about.


# 1fcf5deb 05-Jul-2000 Matt Jacob <mjacob@FreeBSD.org>

Oops! If we're deciding a command is now really dead, make *darned*
sure that it really is by issuing a ISPCTL_ABORT_CMD just on the
off chance the f/w will start it up again and, ha ha, start using
the DMA resources we gave it but are now taking away.


# f6e75de2 03-Jul-2000 Matt Jacob <mjacob@FreeBSD.org>

Add in config_hook for catching when interrupts are safe- this allows
us to not the ints are ok and also to (re)ENABLE isp interrupts. Remove
all splcam()/splx() invocates and replace them with ISP_LOCK/ISP_UNLOCK
macros.


# b85389e1 27-Jun-2000 Matt Jacob <mjacob@FreeBSD.org>

Add in the enabling of interrupts (to isp_attach). Clean up a busted
comment. Check against firmware state- not loop state when enabling
target mode. Other changes have to do with no longer enabling/disabling
interrupts at will.

Rearchitect command watchdog timeouts-

First of all, set the timeout period for a command that has a
timeout (in isp_action) to the period of time requested *plus* two
seconds. We don't want the Qlogic firmware and the host system to
race each other to report a dead command (the watchdog is there to
catch dead and/or broken firmware).

Next, make sure that the command being watched isn't done yet. If
it's not done yet, check for INT_PENDING and call isp_intr- if that
said it serviced an interrupt, check to see whether the command is
now done (this is what the "IN WATCHDOG" private flag is for- if
isp_intr completes the command, it won't call xpt_done on it because
isp_watchdog is still looking at the command).

If no interrupt was pending, or the command wasn't completed, check
to see if we've set the private 'grace period' flag. If so, the
command really *is* dead, so report it as dead and complete it with
a CAM_CMD_TIMEOUT value.

If the grace period flag wasn't set, set it and issue a SYNCHRONIZE_ALL
Marker Request Queue entry and re-set the timeout for one second
from now (see Revision 1.45 isp.c notes for more on this) to give
the firmware a final chance to complete this command.


# 2ad50ca5 17-Jun-2000 Matt Jacob <mjacob@FreeBSD.org>

Remove all ISP2100_SCCLUN define protected code and replace it with
runtime checks.


# 52df5dfd 12-Jun-2000 Matt Jacob <mjacob@FreeBSD.org>

Fix breakage to target mode support.

What we'd like to know is whether or not we have a listener
upstream that really hasn't configured yet. If we do, then
we can give a more sensible reply here. If not, then we can
reject this out of hand.

Choices for what to send were
Not Ready, Unit Not Self-Configured Yet
(0x2,0x3e,0x00)
for the former and
Illegal Request, Logical Unit Not Supported
(0x5,0x25,0x00)
for the latter.

We used to decide whether there was at least one listener
based upon whether the black hole driver was configured.

However, recent config(8) changes have made this hard to do
at this time.

Actually, we didn't use the above quite yet, but were sure considering it.


# cc8df88b 08-May-2000 Matt Jacob <mjacob@FreeBSD.org>

Add in a watchdog routine to catch cases where we've dropped the command.
Apparently the f/w has finished the command, but somehow an interrupt is
being lost. So, we just plain wedge when booting alphas.

This is a general routine we've needed for a while.


# 16c9a708 21-Apr-2000 Matt Jacob <mjacob@FreeBSD.org>

Now that we fixed the isp_sendmarker botch, we can now do initial bus
resets for ULTRA2/ULTRA3 cards again (which were turned off really because
of a botch for dual bus configurations).


# 3389ae93 19-Apr-2000 Poul-Henning Kamp <phk@FreeBSD.org>

Remove ~25 unneeded #include <sys/conf.h>
Remove ~60 unneeded #include <sys/malloc.h>


# 6ca3a52f 13-Mar-2000 Matt Jacob <mjacob@FreeBSD.org>

Don't do bus resets for ULTRA2 or later cards because what seems to
happen currently is that several commands issued *after* the bus reset are
then reported destroyed.


# 40cfc8fe 28-Feb-2000 Matt Jacob <mjacob@FreeBSD.org>

Prettier print of fabric devices being attached- say what kind of
port they are (e.g., F_Port vs. N_Port).

Approved: jkh


# d667c06c 14-Feb-2000 Matt Jacob <mjacob@FreeBSD.org>

Clean up some target mode debug messages. Fix (finally, I believe)
Andrew's problems with SCSI on some alphas- do not call isp_update
directly to update parameters- just mark them as being ready to
update for the next command- the system would just hang on a READ
CAPACITY for a drive. Really annoying because it wouldn't even timeout
(and it has a timeout) so either the SET PARAMETERS call was nuking
things or the f/w was really dropping the ball.

approved: jkh

Reviewed by: gallatin@freebsd.org


# 00a8e174 14-Jan-2000 Matt Jacob <mjacob@FreeBSD.org>

a whale of a lot of target mode cleanup


# 92a1e549 03-Jan-2000 Matt Jacob <mjacob@FreeBSD.org>

Clean up some debug printing. Find the correct lun when SCCLUN is
defined. If we complete with a check condition but no sense data,
say we had an AUTOSENSE failure.


# d81ba9d5 03-Jan-2000 Matt Jacob <mjacob@FreeBSD.org>

Make a static chain of isp softcs- gdb usage becomes a lot easier.
Add in a very large amount of target mode support code- this is just
a first pass at this. It's a difficult thing because some of the code
can be in platform independent areas (see isp_target.?) but a lot has
to be in platform dependent areas because of not only the tight coupling
of received commands/events and the specific OS subsystem but because
the platform independent code has (deliberately) no event/wait mechanisms.


# f9e908dc 19-Dec-1999 Matt Jacob <mjacob@FreeBSD.org>

Clean up lun width determination based upon f/w revisions
for the parallel SCSI cards (4.55..4.65 :: 8.55..8.65).


# 22e1dc85 15-Dec-1999 Matt Jacob <mjacob@FreeBSD.org>

Add Dual LVD bus (1280) support


# ab6c4b31 17-Oct-1999 Matt Jacob <mjacob@FreeBSD.org>

Add in isp_debug variable. It defaults to zero unless CAMDEBUG is defined
where it defaults to one. Change simq width allocation to the max number
of commands supported by the HBA after f/w fires up- not the constant
MAXISPREQUEST value. Do some stylistic changes.


# c3aac50f 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 0470d791 16-Aug-1999 Matt Jacob <mjacob@FreeBSD.org>

Clarify and cleanup some CAM queueing breakages.


# 3692397b 05-Jul-1999 Matt Jacob <mjacob@FreeBSD.org>

add 2200 f/w; fix botched define


# a0259281 02-Jul-1999 Matt Jacob <mjacob@FreeBSD.org>

Well, don't try and probe 65535 luns- things just don't really work well
when this happens. Limit to 16 luns for the 2100/2200 for now.


# 02ab3379 02-Jul-1999 Matt Jacob <mjacob@FreeBSD.org>

Remove all pre-CAM code. Fix breakage for SCCLUN when it is in fact
ISP2100_SCCLUN. Make changes for how ISPASYNC_PDB_CHANGE_COMPLETE
is now ISPASYNC_PDB_CHANGED. Add in ISPASYNC_FABRIC_DEV case.


# 83ae4407 12-May-1999 Matt Jacob <mjacob@FreeBSD.org>

When asked to get the current transfer settings go do a dev_refresh
isp_update call to get a better chance at seeing whether a recent
settings change has latched up.


# ea6f23cd 10-May-1999 Matt Jacob <mjacob@FreeBSD.org>

A large set of changes to handle dual bus adapters.


# 9deea857 06-May-1999 Kenneth D. Merry <ken@FreeBSD.org>

Add a number of interrelated CAM feature enhancements and bug fixes.

NOTE: These changes will require recompilation of any userland
applications, like cdrecord, xmcd, etc., that use the CAM passthrough
interface. A make world is recommended.

camcontrol.[c8]:
- We now support two new commands, "tags" and "negotiate".

- The tags commands allows users to view the number of tagged
openings for a device as well as a number of other related
parameters, and it allows users to set tagged openings for
a device.

- The negotiate command allows users to enable and disable
disconnection and tagged queueing, set sync rates, offsets
and bus width. Note that not all of those features are
available for all controllers. Only the adv, ahc, and ncr
drivers fully support all of the features at this point.
Some cards do not allow the setting of sync rates, offsets and
the like, and some of the drivers don't have any facilities to
do so. Some drivers, like the adw driver, only support enabling
or disabling sync negotiation, but do not support setting sync
rates.

- new description in the camcontrol man page of how to format a disk
- cleanup of the camcontrol inquiry command
- add support in the 'devlist' command for skipping unconfigured devices if
-v was not specified on the command line.
- make use of the new base_transfer_speed in the path inquiry CCB.
- fix CCB bzero cases

cam_xpt.c, cam_sim.[ch], cam_ccb.h:

- new flags on many CCB function codes to designate whether they're
non-immediate, use a user-supplied CCB, and can only be passed from
userland programs via the xpt device. Use these flags in the transport
layer and pass driver to categorize CCBs.

- new flag in the transport layer device matching code for device nodes
that indicates whether a device is unconfigured

- bump the CAM version from 0x10 to 0x11

- Change the CAM ioctls to use the version as their group code, so we can
force users to recompile code even when the CCB size doesn't change.

- add + fill in a new value in the path inquiry CCB, base_transfer_speed.
Remove a corresponding field from the cam_sim structure, and add code to
every SIM to set this field to the proper value.

- Fix the set transfer settings code in the transport layer.

scsi_cd.c:

- make some variables volatile instead of just casting them in various
places
- fix a race condition in the changer code
- attach unless we get a "logical unit not supported" error. This should
fix all of the cases where people have devices that return weird errors
when they don't have media in the drive.

scsi_da.c:

- attach unless we get a "logical unit not supported" error

scsi_pass.c:

- for immediate CCBs, just malloc a CCB to send the user request in. This
gets rid of the 'held' count problem in camcontrol tags.

scsi_pass.h:

- change the CAM ioctls to use the CAM version as their group code.

adv driver:

- Allow changing the sync rate and offset separately.

adw driver

- Allow changing the sync rate and offset separately.

aha driver:

- Don't return CAM_REQ_CMP for SET_TRAN_SETTINGS CCBs.

ahc driver:

- Allow setting offset and sync rate separately

bt driver:

- Don't return CAM_REQ_CMP for SET_TRAN_SETTINGS CCBs.

NCR driver:

- Fix the ultra/ultra 2 negotiation bug
- allow setting both the sync rate and offset separately

Other HBA drivers:
- Put code in to set the base_transfer_speed field for
XPT_GET_TRAN_SETTINGS CCBs.

Reviewed by: gibbs, mjacob (isp), imp (aha)


# 8ea807ad 03-Apr-1999 Matt Jacob <mjacob@FreeBSD.org>

oops on this last


# 92718a7f 03-Apr-1999 Matt Jacob <mjacob@FreeBSD.org>

F/W revisions now a tuple (not a duple). Fix pre-CAM code.


# 4394c92f 25-Mar-1999 Matt Jacob <mjacob@FreeBSD.org>

Add in 1080 LVD support and some basis also for the 1240. The port database
printout is now enabled.


# 57c801f5 16-Mar-1999 Matt Jacob <mjacob@FreeBSD.org>

A wad of changes- prepping for 1080/1240 support (which caused a massive
thwank in register layout goop). A different mboxcmd approach. Some PDB change
infrastructure. Some better management of loopdown/loopup events (keep them
distinct from resource starvation for simq freeze/unfreeze actions).


# 2b052931 08-Feb-1999 Matt Jacob <mjacob@FreeBSD.org>

Allow fibre channel 'bus resets' to go through. Handle Loop Down/Loop Up
events by freezing/unfreezing the simq- nice to have such control at this
level! Do bus resets in attach layer (non-CAM defined code).


# cbf57b47 30-Jan-1999 Matt Jacob <mjacob@FreeBSD.org>

Implement and use Fast Posting for both parallel && fibre. Redo a bit of
the startup code. Implement a call to outer framework function so that
asynchronous events can be handled (e.g., speed negotiation, target mode).

Roll internal release tags.


# c3055363 28-Dec-1998 Matt Jacob <mjacob@FreeBSD.org>

clarify headers;move uninit to outer layer;remove watchdog


# d3a9eb2e 04-Dec-1998 Matt Jacob <mjacob@FreeBSD.org>

make a real "done" func; clarify some LUN widths


# 4663e367 15-Oct-1998 Justin T. Gibbs <gibbs@FreeBSD.org>

-Wunused cleanup.

Submitted by: Poul-Henning Kamp <phk@freebsd.org>


# 3dd37e438 17-Sep-1998 Matt Jacob <mjacob@FreeBSD.org>

(requested by gibbs) Remove the SCSI_CAM option (and rework the isp driver
that had depended on it for compilation within or without CAM to use
__FreeBSD_version instead).


# c6904df9 17-Sep-1998 Matt Jacob <mjacob@FreeBSD.org>

Remove commented out and no longer pertinent EAGAIN message. Redo CMD_COMPLETE
logic for returns from inner layer (just make sure that a CAM_REQ_INPROG
doesn't get xpt_done'd).


# 00f50ce8 16-Sep-1998 Matt Jacob <mjacob@FreeBSD.org>

Fix the (unported) resource shortage case- I'd done a xpt_freeze_simq
but had never done a CAM_RELEASE_SIMQ to restart the queues.


# aad446c0 16-Sep-1998 Matt Jacob <mjacob@FreeBSD.org>

alpha port fixes from Doug.
Reviewed by: dfr


# 478f8a96 15-Sep-1998 Justin T. Gibbs <gibbs@FreeBSD.org>

Update QLogic ISP support for CAM. Add preliminary target mode support.

Submitted by: Matthew Jacob <mjacob@feral.com>


# d8bb36bb 24-Jul-1998 Matt Jacob <mjacob@FreeBSD.org>

minphys means something different in FreeBSD than in NetBSD- not needed here and in the way


# 6054c3f6 22-Apr-1998 Matt Jacob <mjacob@FreeBSD.org>

Add support for the Qlogic ISP SCSI && FC/AL Adapters