Commit graph

53 commits

Author SHA1 Message Date
Mark Johnston a01ff11cb7 ocs: Check for copyin errors in the ioctl handler
If copyin() fails, the driver will blindly proceed with whatever had
been in the uninitialized DMA buffer.  This is not what we want.  Check
for copyin failures.

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by:	ram
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43097
2023-12-25 21:04:00 -05:00
Ram Kishore Vegesna a9504d76cc ocs_fc: Use xpt_path_sbuf() to copy the path to sbuf.
Reported by:	imp
 MFC after:	1 week
2023-12-18 14:22:06 +05:30
Ram Kishore Vegesna 70547544ce ocs_fc: IO timeout handling and error reporting fix.
Hardware timeout uses a 8-bit timeout value and expects the timeout to
be less than 255 seconds. Added software timer implemetation to timeout
and abort the IOs with timeout more than 255 seconds.

Fix the timeout problem by dividing CAM timeouts by 1000 as hardware
expects timeout value in seconds.  Before this change, CAM timeouts in
milliseconds were getting truncated to 8 bits and converted to seconds.
So the actual timeout used when going down to the card would depend on
the bottom 8 bits of the timeout used.

Add the mapping of ocs_fc error status to CAM status.

Reported by:	ken
Reviewed by:	ken
Tested by:	ken, ram
Approved by:	ken
MFC after:	1 week
2023-12-12 10:22:58 -05:00
John Baldwin 7aa5b2a9e7 ocs: Fix a couple of type mismatches in function prototypes
Reported by:	GCC 13 via -Wenum-int-mismatch
Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D42585
2023-11-14 18:36:48 -08:00
Warner Losh 95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
John Baldwin fb4a86164d ocs: Fix mismatch in array bounds.
Reported by:	GCC -Warray-parameter
Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D37545
2022-12-07 12:31:33 -08:00
Elliott Mitchell 21cc0918c7 sys: Nuke double-semicolons
A distinct number of double-semicolons have ended up in FreeBSD.  Take a
pass at getting rid of many of these harmless typos.

Reviewed by: emaste, rrs
Pull Request: https://github.com/freebsd/freebsd-src/pull/609
Differential Revision: https://reviews.freebsd.org/D31716
2022-11-02 09:34:20 -06:00
Gordon Bergling dabebd0ba2 ocs_fc(4): Fix a typo in an error message
- s/faild/failed/

MFC after:	5 days
2022-10-25 12:52:24 +02:00
Gordon Bergling eb2f7d9a5a ocs_fc(4): Remove double words in source code comments
- s/to to/to/

MFC after:	3 days
2022-09-10 13:00:23 +02:00
Dimitry Andric 8d9e292846 Fix unused variable warning in ocs_cam.c
With clang 15, the following -Werror warning is produced:

    sys/dev/ocs_fc/ocs_cam.c:2556:11: error: variable 'count' set but not used [-Werror,-Wunused-but-set-variable]
            uint32_t        count;
                            ^

The 'count' variable seems to be a left-over from some debugging code
that no longer exists, and can be removed without any functional change.

MFC after:	3 days
2022-07-21 19:36:12 +02:00
John Baldwin b64711b6e7 ocs_fc: Remove unused devclass argument to DRIVER_MODULE. 2022-05-06 15:46:55 -07:00
John Baldwin afda855350 ocs: Remove unused variable. 2022-04-07 17:01:27 -07:00
Gordon Bergling cededdff9b ocs_fc(4): Fix a typo in a source code comment
- s/initialzied/initialized/

MFC after:	3 days
2022-04-02 14:28:30 +02:00
Eric van Gyzen aca2a7faca stack_zero is not needed before stack_save
The man page was recently clarified to commit to this contract.

MFC after:	1 week
Sponsored by:	Dell EMC Isilon
2022-03-25 20:10:38 -05:00
Ram Kishore Vegesna 625a8bfb04 ocs_fc: Ignore flogi failure when the remote node is pt2pt winner
Updated commit 79c56c9af5, do not proceed with discovery
if flogi fails in pt2pt winner case.

MFC after: 3 days
2022-03-04 20:23:38 +05:30
Ram Kishore Vegesna 965e2154e7 ocs_fc: Support persistent topology feature
Summary: Enable persistent topology across power cycles/firmware resets.

Reviewed by: mav

MFC after: 3 days

Differential Revision: https://reviews.freebsd.org/D34425
2022-03-04 10:19:03 +05:30
Ram Kishore Vegesna 57e4b67755 ocs_fc: Do not respond to unsolicited NOP BLS command.
Summary: Drop unsolicited BLS commands other than ABTS.

Reviewed by: mav

MFC after: 3 days

Differential Revision: https://reviews.freebsd.org/D34423
2022-03-04 10:19:03 +05:30
Ram Kishore Vegesna 79c56c9af5 ocs_fc: Ignore flogi failure when the discovery is already done.
Summary:
Some targets are not responding to the FLOGI in point-to-point topology,
If the pt2pt discovery is done, Ignore the FLOGI failure.

MFC after: 3 days

Differential Revision: https://reviews.freebsd.org/D34422
2022-03-04 10:19:03 +05:30
Ram Kishore Vegesna 7bf31432fd ocs_fc: Fix a possible Null pointer dereference
Fix a possible Null pointer dereference in ocs_hw_get_profile_list_cb()

PR: 261453
Reported by: lwhsu

MFC after: 3 days
2022-02-09 16:18:21 +05:30
Ram Kishore Vegesna a2523baed5 ocs_fc: Remove giant lock usage in sysctl.
Summary: Replace CTLFLAG_NEEDGIANT with CTLFLAG_MPSAFE.

Reviewers: ken, mav

Subscribers: imp

Approved by: mav

Differential Revision: https://reviews.freebsd.org/D33752
2022-01-06 14:13:06 +05:30
Ram Kishore Vegesna cba757ef2a ocs_fc: Populate subvendor and subdevice ids.
Enable serialnumber reporting.

Reviewed by: mav
MFC after: 3 days
2021-12-21 12:41:51 +05:30
Ram Kishore Vegesna 6f78736cb1 ocs_fc: Remove unused function delarations.
Remove unused function declarations.
Changes required for internal tool.

Approved by: ken
2021-12-07 14:14:38 +05:30
Gordon Bergling 7b56cb0462 ocs_fs: Fix two typos in source code comments
- s/maxium/maximum/
- s/maxiumum/maximum/

MFC after:	3 days
2021-11-03 17:17:51 +01:00
Ram Kishore Vegesna 41e9466943 ocs_fc: Fix device lost timer where device is not getting deleted.
Issue: Devices wont go away after the link down.

Device lost timer functionality in ocs_fc is broken,
`is_target` flag is not set in the target database and target delete is skipped.

Fix: Remove unused flags and delete the device when timer expires.

Reported by: ken@kdm.org
Reviewed by: mav, ken
2021-09-30 13:01:17 +05:30
Ram Kishore Vegesna d063d1bc92 ocs_fc: When commands complete with an error, freeze the device queue.
Proper error recovery depends on freezing the device queue when an
error occurs, so we can recover from an error before sending
additional commands.

The ocs_fc(4) driver was not freezing the device queue for most
SCSI errors, and that broke error recovery.

sys/dev/ocs_fc/ocs_cam.c:
	In ocs_scsi_initiator_io_cb(), freeze the device queue if
        we're passing back status other than CAM_REQ_CMP.

Submitted by: ken@kdm.org
Reviewed by: mav, ken
2021-09-30 13:01:17 +05:30
Ram Kishore Vegesna 1af49c2eeb ocs_fc: Fix CAM status reporting in ocs_fc(4) when no data is returned.
In ocs_scsi_initiator_io_cb(), if the SCSI command that is
        getting completed had a residual equal to the transfer length,
        it was setting the CCB status to CAM_REQ_CMP.

        That breaks the expected behavior for commands like READ ATTRIBUTE.
        For READ ATTRIBUTE, if the first attribute requested doesn't exist,
        the command is supposed to return an error (Illegal Request,
        Invalid Field in CDB).  The broken behavior for READ ATTRIBUTE
        caused LTFS tape formatting to fail.  It looks for attribute
        0x1623, and expects to see an error if the attribute isn't present.

        In addition, if the residual is negative (indicating an overrun),
        only set the CCB status to CAM_DATA_RUN_ERR if we have not already
        reported an error.  The SCSI sense data will have more detail about
        what went wrong.

        sys/dev/ocs_fc/ocs_cam.c:
                In ocs_scsi_initiator_io_cb(), don't set the status to
                CAM_REQ_CMP if the residual is equal to the transfer length.

                Also, only set CAM_DATA_RUN_ERR if we didn't get SCSI
                status.

Submitted by: ken@kdm.org
Reviewed by: mav, ken
2021-09-30 13:01:16 +05:30
Ram Kishore Vegesna 322dbb8ce8 ocs_fc: Increase maximum supported SG elements to support larger transfer sizes.
Reported by: ken@kdm.org
Reviewed by: mav, ken
2021-09-30 13:01:16 +05:30
Ram Kishore Vegesna 3bf42363b0 ocs_fc: Emulex Gen 7 HBA support.
Emulex Gen7 adapter support in ocs_fc driver.

Reviewed by: mav, ken
2021-09-30 13:01:15 +05:30
Gordon Bergling 16b71d98d9 ocs_fs(4): Fix some common typos in source code comments
- s/transfered/transferred/
- s/associted/associated/

MFC after:	3 days
2021-08-28 18:24:08 +02:00
Ram Kishore Vegesna 29e2dbd42c ocs_fc: Add gendump and dump_to_host ioctl command support.
Support to generate firmware dump.

Approved by: mav(mentor)
2021-07-06 21:08:11 +05:30
Ram Kishore Vegesna 7377d3831b ocs_fc: Fix use after free bug in ocs_hw_async_call()
Freed ctx is used in the later callee ocs_hw_command(),
which is a use after free bug.

Return error if sli_cmd_common_nop() failed.

PR: 255865
Reported by: lylgood@foxmail.com
Approved by:: markj
2021-05-28 11:21:10 +05:30
Ram Kishore Vegesna dd722ccd6e ocs_fc: Fix a use after free in ocs_sport_free
Domain which could be freed is used while freeing the sport.
Use ocs from sport.

PR: 255866
Reported by: lylgood@foxmail.com
Approved by:: markj
2021-05-28 10:56:13 +05:30
Ram Kishore Vegesna fc620f9782 ocs_fc: Fix memory leak in ocs_scsi_io_alloc()
PR: 254690
Approved by: mav(mentor)
MFC after: 2 weeks
2021-04-22 17:48:37 +05:30
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
Alexander Motin eb5a54f880 Fix incorrect constants of target tag action.
ocs_scsi_recv_cmd() receives the flags after ocs_get_flags_fcp_cmd(),
which translates them from FCP_TASK_ATTR_* to OCS_SCSI_CMD_*.  As result
non-SIMPLE requests turned into HEAD or ORDERED depending on direction.

MFC after:	2 weeks
2020-10-25 16:58:48 +00:00
Mateusz Guzik 98d835ae88 ocs_fc: clean up empty lines in .c and .h files 2020-09-01 22:02:12 +00:00
Brooks Davis 6671366a55 Fix -Wvoid-pointer-to-enum-cast warnings.
This pattern is used in callbacks with void * data arguments and seems
both relatively uncommon and relatively harmless.  Silence the warning
by casting through uintptr_t.

This warning is on by default in Clang 11.

Reviewed by:	arichardson
Obtained from:	CheriBSD (partial)
MFC after:	1 week
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D24425
2020-04-15 18:15:58 +00:00
Ed Maste aeb665b538 remove extraneous double ;s in sys/ 2020-03-30 16:04:25 +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
Jeff Roberson 61a74c5ccd schedlock 1/4
Eliminate recursion from most thread_lock consumers.  Return from
sched_add() without the thread_lock held.  This eliminates unnecessary
atomics and lock word loads as well as reducing the hold time for
scheduler locks.  This will eventually allow for lockless remote adds.

Discussed with:	kib
Reviewed by:	jhb
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D22626
2019-12-15 21:11:15 +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
Ram Kishore Vegesna 4915e5c719 Fixed issues reported by coverity scan.
Approved by: mav
MFC after: 3 weeks
2019-01-23 17:34:01 +00:00
Mark Johnston f9be23fd42 ocs_fc: Ensure that we zero-initialize memory before copying it out.
Note that the affected interface is available only to root.

admbugs:	765
Reported by:	Vlad Tsyrklevich <vlad@tsyrklevich.net>
Reviewed by:	emaste, ram
MFC after:	1 day
Security:	Kernel memory disclosure
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D18914
2019-01-23 17:28:39 +00:00
Ram Kishore Vegesna b9732f789d Remove accessing remote node and domain objects while processing cam actions.
Issue:
  ocs_fc(4) driver panics. It's induced by setting the port_state
sysctl to offline, then online, then offline, then online, and so
forth and so on in rapid succession.

Reason:
  While we set the port_state to online fc discovery will start and OS
is enumerating the target discs by calling ocs_action(),  then set the
port state to "offline" which deletes domain/sport/nodes.

  In ocs_action()->XPT_GET_TRAN_SETTINGS we are accessing the remote
node which can be invalid to get the wwpn, wwnn and port.

Fix:
  Removed accessing of remote node and domain in some ocs_action() cases.
  Populated the required values from ocs_fcport.
  This removes the dependency of node and domain structures while
processing XPT_PATH_INQ and XPT_GET_TRAN_SETTINGS.
   We will invalidate the target entries after the device lost
timeout(30 seconds).

Approved by: ken, mav
MFC after: 3 weeks
2019-01-11 15:59:24 +00:00
Mark Johnston 84f0fb8a93 Use the right buffer size when calling snprintf().
PR:	229952
2018-07-22 18:31:15 +00:00
Ram Kishore Vegesna 6affb8eb8f Implemented Device Lost Timer, which is used to give target device the time to recover before marking dead.
Issue: IO fails immediately after doing port-toggle.
Fix: Added LDT(Device Lost Timer)- we wait a specific period of time prior to telling the OS about lost device.

Approved by: ken, mav
MFC after: 3 days
Differential Revision: D16196
2018-07-18 07:01:34 +00:00
Dimitry Andric bc5ea07c09 Fix build of ocs_fs with base gcc on i386
Add a few intermediate casts to uintptr_t to suppress "cast to pointer
from integer of different size" warnings from gcc.  Also remove a few
incorrect casts.

Reviewed by:	ram
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D15747
2018-06-11 07:57:32 +00:00
Ram Kishore Vegesna ca21db8546 Issue:
Utility hangs when  OCS_IOCTL_CMD_MGMT_GET_ALL called in parallel on port 0 and port 1.

Fix: Using static structure for results is corrupting the second ioctl request. Removed static for results structure.
Approved by: ken
MFC after: 3 days
2018-06-05 15:05:26 +00:00
Kenneth D. Merry e440863e06 Clear out the entire structure, not just the size of a pointer to it.
sys/dev/ocs/ocs_os.c:
	In ocs_thread_create(), use sizeof(*thread) (instead of
	sizeof(thread)) as the size argument to memset so that we clear
	out the entire thread structure instead of just a few bytes of it.

Submitted by:	jtl
MFC after:	3 days
2018-05-11 14:50:26 +00:00
Ram Kishore Vegesna 5eaf9435d0 Moved opts-stack.h include before all other includes.
PR: 227446
Approved by: ken
MFC after: 3 days
2018-04-17 15:29:32 +00:00