Commit Graph

961 Commits

Author SHA1 Message Date
Alexander Motin
a93d2db0e7 Mark inline functions static. 2020-11-29 00:35:13 +00:00
Alexander Motin
156c1ebe3b 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.
2020-11-27 15:50:20 +00:00
Alexander Motin
df9c69d239 Restore break statement lost in r367857. 2020-11-27 05:13:52 +00:00
Alexander Motin
b760d2eca9 More cleanup in response queue and reset code. 2020-11-26 18:47:23 +00:00
Alexander Motin
b05f17a12f Some minor FCoE bits I had lying around. 2020-11-26 02:14:52 +00:00
Alexander Motin
8cb0d414a8 Remove some more dead code from pre-24xx. 2020-11-26 01:59:44 +00:00
Alexander Motin
a6222dd789 Remove more legacy of parallel SCSI. 2020-11-24 22:43:27 +00:00
Alexander Motin
5bcbd98c8b Update RQSFLAG_* definitions. 2020-11-24 17:37:12 +00:00
Alexander Motin
384d27e04d 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.
2020-11-24 15:32:25 +00:00
Alexander Motin
1553bf11b9 Remove unneeded locking around xpt_bus_[de]register().
MFC after:	2 weeks
2020-11-24 14:05:52 +00:00
Alexander Motin
0f99cb55ff 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.
2020-11-24 04:16:49 +00:00
Alexander Motin
3037002e33 Fix debug build after 367926. 2020-11-22 16:13:09 +00:00
Alexander Motin
cbf33b3654 Fix build after 367926.
Option ISP_TARGET_MODE is evil.
2020-11-22 05:42:52 +00:00
Alexander Motin
0b19f90a43 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.
2020-11-22 04:29:55 +00:00
Alexander Motin
254c652b6d Do not parent all busdma tags to the payload tag.
There is not much to inherit any more, may create more problems than solve.
Instead parent them all directly to upstream.

While there, add missed payload tag and tune scratch tag destructions.
2020-11-22 04:10:13 +00:00
Alexander Motin
c515717a02 Remove remnants of execthrottle and maxalloc parameters.
The first was obsolete since 26xx, not used on 25xx and not needed on 24xx.
The second seems never worked on 24xx and up.
2020-11-22 02:51:30 +00:00
Alexander Motin
b8e2395ec5 Increase queue depths from 1024/256 to 8192/1024 IOCBs.
Qlogic chips store S/G lists in the same queue as requests themselves.  In
the worst case 1MB I/O may require up to 52 IOCBs, that means queue of 1024
IOCBs can store only 19 of such requests.  The increase reduces chances of
overflow, while we should be able to afford additional 512KB of RAM per HBA.
The Linux driver uses comparable numbers.

While there, decouple ATIO queue size from response queue size.  There is
no reason for them to be equal.
2020-11-20 19:36:34 +00:00
Alexander Motin
f6854a0cd5 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.
2020-11-20 18:02:04 +00:00
Alexander Motin
dae0ba753c Fix r367857 build without ISP_TARGET_MODE. 2020-11-20 02:03:58 +00:00
Alexander Motin
1b760be482 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
2020-11-20 01:15:48 +00:00
Alexander Motin
cf770ba3e9 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
2020-11-18 03:43:03 +00:00
Alexander Motin
9cca0e7ee5 Remove bus_dma locking/sleeping when not needed.
MFC after:	1 month
2020-11-18 02:54:05 +00:00
Alexander Motin
57713eda85 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
2020-11-18 02:12:51 +00:00
Alexander Motin
8836496815 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.
2020-10-25 19:34:02 +00:00
Pawel Biernacki
7029da5c36 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
2020-02-26 14:26:36 +00:00
Warner Losh
58aa35d429 Remove sparc64 kernel support
Remove all sparc64 specific files
Remove all sparc64 ifdefs
Removee indireeect sparc64 ifdefs
2020-02-03 17:35:11 +00:00
John Baldwin
5773ac113c Use callout_func_t instead of the deprecated timeout_t.
Reviewed by:	kib, imp
Differential Revision:	https://reviews.freebsd.org/D22752
2019-12-10 22:06:53 +00:00
Kenneth D. Merry
e26059ca18 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
2019-05-24 17:58:29 +00:00
Edward Tomasz Napierala
e52fba212d Make isp(4) suggest loading ispfw(4) when it fails to attach.
It cannot load it automatically at boot, because the root filesystem
is not there yet. An alternative would be adding ispfw(4) to GENERIC,
but it's an additional 1MB.

Reviewed by:	mav
MFC after:	2 weeks
Sponsored by:	Klara Inc.
Differential Revision:	https://reviews.freebsd.org/D19369
2019-04-28 15:08:57 +00:00
Kenneth D. Merry
6f9dbc0e6e 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
2019-03-11 14:21:14 +00:00
Alexander Motin
1f8c4546a8 Limit 24xx adapters to only MSI interrupts by default.
This was actually the known good configuration we used before.
Single MSI-X configuration doesn't even work there on my tests, just due
to lack of documentation not sure whether by design or I am doing something
wrong.

PR:		233654
MFC after:	1 week
2019-02-28 21:07:16 +00:00
Alexander Motin
8ebb14b1c6 Limit 24xx adapters to only one MSI-X interrupt by default.
These are 4Gb/s and pretty old and slow now, so I see no reason to fight
for their performance over stability.

PR:		233654
MFC after:	1 week
Sponsored by:	iXsystems, Inc.
2019-02-28 15:36:03 +00:00
Alexander Motin
17ec774693 Add to isp(4) tunables to limit MSI/MSI-X usage.
There are some problem reports possibly related to the new driver use of
multiple interrupts on older cards.  Hopefully this allow to workaround
them.

MFC after:	1 week
Sponsored by:	iXsystems, Inc.
2019-02-28 15:24:00 +00:00
Alan Somers
6040822c4e 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
2018-07-30 15:46:40 +00:00
Alexander Motin
db08ef4353 Increase ABOUT FIRMWARE command timeout to 5s.
It seems default timeout of 100ms is not enough for my 2694L card,
while it was perfectly fine for others, even for full-height 2694.

MFC after:	1 week
Sponsored by:	iXsystems, Inc.
2018-03-15 01:07:21 +00:00
Brooks Davis
8037cdcd9a 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
2018-03-13 19:56:10 +00:00
Alexander Motin
14e084ada5 Add support for Enhanced Gen 5 (16Gb) and Gen 6 (32Gb) QLogic FC HBAs.
MFC after:	2 weeks
Sponsored by:	iXsystems, Inc.
2018-02-28 16:24:32 +00:00
Pedro F. Giffuni
718cf2ccb9 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.
2017-11-27 14:52:40 +00:00
Eitan Adler
a2aef24aa3 Update several more URLs
- Primarily http -> https
- Primarily FreeBSD project URLs
2017-10-29 08:17:03 +00:00
Alexander Motin
b4af3e8a85 Add missing restart_queue initialization.
MFC after:	1 week
2017-08-23 19:00:06 +00:00
Kenneth D. Merry
fefd924a01 Remove duplicate assignments from r321622.
Submitted by:	mav
MFC after:	3 days
Sponsored by:	Spectra Logic
2017-07-27 15:51:56 +00:00
Kenneth D. Merry
a0acb3512c Fix probing FC targets with hard addressing turned on.
This largely reverts FreeBSD SVN change 289937 from October 25th, 2015.

The intent of that change was to keep loop IDs persistent across
chip reinits.

The problem is that the change turned on the PREVLOOP /
PREV_ADDRESS bit (bit 7 in Firmware Options 2), which tells the
Qlogic chip to not participate in the loop if it can't get the
requested loop address.  It also turned off soft addressing on 2400
(4Gb) and newer controllers.

The isp(4) driver defaults to loop address 0, and the tape drives
I have tested default to loop address 0 if hard addressing is turned
on.  So when hard loop addressing is turned on on the drive, the isp(4)
driver just refuses to participate in the loop.

The solution is to largely revert that change.  I left some elements
in place that are related to virtual ports, since they were new.

This does work with IBM tape drives with hard and soft addressing
turned on.  I have tested it with 4Gb, 8Gb, and 16Gb controllers.

sys/dev/isp.c:
	Largely revert FreeBSD SVN change 289937.  I left the
	ispmbox.h changes in place.

	Don't use the PREV_ADDRESS bit on initialization.  It tells
	the chip to not participate if it can't get the requested
	loop ID.

	Do use soft addressing on 2400 and newer chips.

	Use hard addressing when the user has requested a specific
	initiator ID.  (hint.isp.X.iid=N in /boot/loader.conf)

	Leave some of the virtual port options from that change in
	place, but don't turn on the PREV_ADDRESS bit.

Reviewed by:	mav
MFC after:	3 days
Sponsored by:	Spectra Logic
2017-07-27 15:33:57 +00:00
Alexander Motin
ae77193109 "Port Type not registered" is not a real error for GIT_PT. 2017-07-10 06:25:30 +00:00
Alexander Motin
a94fab67bb 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.
2017-07-03 15:56:45 +00:00
Alexander Motin
9cf87855b1 Move comment respecting previous commit. 2017-07-02 15:08:32 +00:00
Alexander Motin
3d792e6080 Slightly unify SNS requests for post- and pre-24xx. 2017-07-02 14:59:41 +00:00
Alexander Motin
6ddb89725b 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.
2017-06-30 06:10:18 +00:00
Kenneth D. Merry
57b6261f94 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
2017-05-03 13:17:01 +00:00
Alexander Motin
1c779b2849 Switch isp_reset to scratchpad not requiring ISP_MBOXDMASETUP.
MFC after:	1 week
2017-04-24 10:16:12 +00:00
Alexander Motin
e9da70a35e Fix few minor issues found by Clang Analyzer.
MFC after:	2 weeks
2017-04-09 07:53:31 +00:00