Home | History | Annotate | only in /src/sys/dev/iscsi
History log of /src/sys/dev/iscsi
RevisionDateAuthorComments
 1.3 30-May-2015  joerg Remove ISCSI_PERFTEST.
 1.2 30-May-2015  joerg Remove ISCSI_TEST_MODE and corresponding dev/iscsi_test.h header.
 1.1 23-Oct-2011  agc branches: 1.1.12; 1.1.30;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.1.30.1 06-Jun-2015  skrll Sync with HEAD
 1.1.12.1 03-Dec-2017  jdolecek update from HEAD
 1.2 18-Apr-2017  maya Remove redundant duplicate assignment.

from clang static analyzer
 1.1 23-Oct-2011  agc branches: 1.1.12; 1.1.30; 1.1.34; 1.1.38;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.1.38.1 21-Apr-2017  bouyer Sync with HEAD
 1.1.34.1 26-Apr-2017  pgoyette Sync with HEAD
 1.1.30.1 28-Aug-2017  skrll Sync with HEAD
 1.1.12.1 03-Dec-2017  jdolecek update from HEAD
 1.1 23-Oct-2011  agc Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.5 30-May-2015  joerg Remove ISCSI_PERFTEST.
 1.4 30-May-2015  joerg Remove ISCSI_TEST_MODE and corresponding dev/iscsi_test.h header.
 1.3 12-Apr-2015  joerg ISCSI_DEBUG needs a value, so make it a param.
 1.2 09-Nov-2011  riz branches: 1.2.10; 1.2.28;
Don't add iscsi_utils.c without 'iscsi' condition.
 1.1 23-Oct-2011  agc branches: 1.1.2;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.1.2.1 10-Nov-2011  yamt sync with head
 1.2.28.1 06-Jun-2015  skrll Sync with HEAD
 1.2.10.1 03-Dec-2017  jdolecek update from HEAD
 1.5 25-Nov-2023  mlelstv Adapt to bignum representation of target.
Fix negotiation for mutual authentication.
Prepare for more CHAP types.
Fix crashes for invalid socket descriptors passed to kernel.
Protect usecount with connection mutex, avoids race on connection close.
Minor cosmetics.
 1.4 15-Jun-2016  mlelstv branches: 1.4.50;
Remove throttling code, instead signal scsipi layer to reduce the openings
and retry the command. Start with a small openings number and let scsipi
request to grow it up to the current send window.

Adjust ccb and pdu counts to avoid ressource shortages. These are still
very ad-hoc numbers, but seem to be sufficient for a Gigabit link.

Use separate condvar for PDU pool and add counter to help debugging.

Revert setting PDU disposition to UNUSED before freeing. free_pdu
uses this as a flag to detect already returned PDUs.

Add reference counter for open commands to defer unmapping a session
that would lead to crashes in scsipi.

Move session cleanup to cleanup thread.

Use get_sernum to retrieve current serial number where possible and
make it check for immediate commands itself.

Adjust debug output.
 1.3 19-Nov-2011  agc branches: 1.3.10; 1.3.28;
grab major 203 for the iSCSI communications device (between kernel
driver and /sbin/iscsid)
 1.2 29-Oct-2011  christos branches: 1.2.2;
make all bitfields unsigned int
 1.1 23-Oct-2011  agc Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.3.28.1 09-Jul-2016  skrll Sync with HEAD
 1.3.10.1 03-Dec-2017  jdolecek update from HEAD
 1.4.50.1 18-Dec-2023  martin Pull up following revision(s) (requested by mlelstv in ticket #505):

sys/dev/iscsi/iscsi_utils.c: revision 1.29
sys/dev/iscsi/iscsi.h: revision 1.5
sys/dev/iscsi/iscsi_ioctl.c: revision 1.34
sys/dev/iscsi/iscsi_globals.h: revision 1.28
sys/dev/iscsi/iscsi_text.c: revision 1.14
sys/dev/iscsi/iscsi_send.c: revision 1.40

Adapt to bignum representation of target.

Fix negotiation for mutual authentication.

Prepare for more CHAP types.

Fix crashes for invalid socket descriptors passed to kernel.

Protect usecount with connection mutex, avoids race on connection close.

Minor cosmetics.
 1.28 25-Nov-2023  mlelstv Adapt to bignum representation of target.
Fix negotiation for mutual authentication.
Prepare for more CHAP types.
Fix crashes for invalid socket descriptors passed to kernel.
Protect usecount with connection mutex, avoids race on connection close.
Minor cosmetics.
 1.27 13-Sep-2022  mlelstv branches: 1.27.4;
kill_session now uses the session id to avoid stale session pointers.
protect network socket with rwlock to handle recconnects.
always take over socket from iscsid to prevent leaks.
keep a good connection alive.
don't forget child device when config_detach fails.
fix locking when reassigning CCBs.
pducount is protected by lock, no need for atomic.
some code rework, refined debug messages.
 1.26 21-Jun-2020  chs avoid the use of UVM internals in the iscsi ioctl code.
copyin/out are fine in this context.
 1.25 21-Apr-2019  maya wether -> whether
 1.24 21-Apr-2019  mlelstv Replace build option to enable hex encoded bignum parameters with a sysctl.
 1.23 03-Dec-2017  christos branches: 1.23.4;
- add a prefix to struct members (but not the ioctl ones because they affect
the API)
- use consistent variable names.
 1.22 05-Feb-2017  mlelstv Destroy callouts when cleaning up.
 1.21 15-Jun-2016  mlelstv branches: 1.21.2; 1.21.4;
Remove throttling code, instead signal scsipi layer to reduce the openings
and retry the command. Start with a small openings number and let scsipi
request to grow it up to the current send window.

Adjust ccb and pdu counts to avoid ressource shortages. These are still
very ad-hoc numbers, but seem to be sufficient for a Gigabit link.

Use separate condvar for PDU pool and add counter to help debugging.

Revert setting PDU disposition to UNUSED before freeing. free_pdu
uses this as a flag to detect already returned PDUs.

Add reference counter for open commands to defer unmapping a session
that would lead to crashes in scsipi.

Move session cleanup to cleanup thread.

Use get_sernum to retrieve current serial number where possible and
make it check for immediate commands itself.

Adjust debug output.
 1.20 15-Jun-2016  mlelstv drop unused debug helper routine
 1.19 05-Jun-2016  mlelstv Replace the simple tag counter with the command tag coming down from scsipi.
Also set attributes according to tag types.
 1.18 05-Jun-2016  mlelstv Fix serial number check and account for commands in flight to avoid
unnecessary recovery actions.
 1.17 05-Jun-2016  mlelstv When stopping a callout, wait until the cleanup thread has processed them.
 1.16 01-Jun-2016  mlelstv refactor callouts
remove timed out ccbs and connections from cleanup queue when stopping timeout.
 1.15 01-Jun-2016  mlelstv factor out sernum handling.
make incrementing sernum atomic.
declare variables for atomic operations as volatile.
 1.14 29-May-2016  mlelstv Several improvements to the ISCSI driver.

- Enable debug messages but set log level to be quiet. Provide a
system (hw.iscsi.debug) to set the log level at run time.
- Replace old tsleep/wakeup synchronization with mutexes and condvars.
- Defer actions from callouts (basically timeouts) to the cleanup thread.
- Protect lists and unique ids with mutexes. protect connection usecount
by using atomic operations.
- Assert kernel lock when calling into scsipi and network code.
- Use this to make send/receive/cleanup threads MPSAFE.

- Fix handling of out-of-CCB/out-of-PDU conditions against the scsipi layer.
- Bump number of PDUs to 128 to avoid virtually all out-of-PDU conditions

- Make use of softc structure for attach/detach operations.
- Track open file handles to prevent detach when busy.

- Move some global variables to make them static.

- Fix 'Overlapping Commands Attempted' error by marking commands as
simply ordered (ATTR_SIMPLE) like FreeBSD.
 1.13 30-May-2015  joerg Create a per-device state for iscsi(4), effectively making it a cloning
device.
 1.12 30-May-2015  joerg Save space by making ack flag booleans.
 1.11 30-May-2015  joerg Inline SET_CCB_TIMEOUT and SET_CONN_TIMEOUT
 1.10 30-May-2015  joerg Remove ISCSI_PERFTEST.
 1.9 30-May-2015  joerg Remove ISCSI_TEST_MODE and corresponding dev/iscsi_test.h header.
 1.8 15-May-2015  joerg Remove conditionals for NetBSD before 4.0.
 1.7 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.6 29-Dec-2012  mlelstv branches: 1.6.14;
- defer session cleanup to not force detachments
- use more and explicit locking
- improve connection recovery
- use larger timeouts
- handle ccb buffer underflow correctly
- simplify throttling code

Sessions can now temporarily exist without a valid
connection, you also need to update iscsid(8).
 1.5 12-Aug-2012  mlelstv branches: 1.5.2;
Don't use common variables, also prefix global variables to avoid
namespace pollution.
 1.4 09-Jun-2012  mlelstv Close file descriptor passed into the kernel on success.
Fix locking of file handle. More cleanup on error paths.
Keep track of CCBs, so they cannot be used after a session ends.
Handle CCB timeouts even when the connection is terminated.
Compute firstdata, firstimmed correctly.
 1.3 02-Jun-2012  mlelstv avoid namespace pollution when debugging
don't panic when printing data for a dead (NULL) connection
 1.2 29-Nov-2011  tls branches: 1.2.4;
Remove rnd_extract_data from the public kernel API (it is for use by the
stream generators only). Clean up some related minor issues.
 1.1 23-Oct-2011  agc branches: 1.1.2;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.1.2.3 23-Jan-2013  yamt sync with head
 1.1.2.2 30-Oct-2012  yamt sync with head
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.2.4.1 03-Jul-2012  jdc Pull up revisions:
src/sys/dev/iscsi/iscsi_globals.h revisions 1.3,1.4
src/sys/dev/iscsi/iscsi_main.c revisions 1.4,1.5
src/sys/dev/iscsi/iscsi_text.c revisions 1.4,1.5
src/sys/dev/iscsi/iscsi_ioctl.c revisions 1.3,1.4
src/sys/dev/iscsi/iscsi_send.c revisions 1.3,1.4,1.5
src/sys/dev/iscsi/iscsi_utils.c revisions 1.2,1.3,1.4
src/sbin/iscsid/iscsid_discover.c revision 1.4
src/sys/dev/iscsi/iscsi_rcv.c revision 1.3
src/sbin/iscsictl/iscsic_driverif.c revisions 1.5,1.6
(requested by martin in ticket #357, with updates from mhitch and mlelstv).

avoid namespace pollution when debugging
don't panic when printing data for a dead (NULL) connection

Close file descriptor passed into the kernel on success.
Fix locking of file handle. More cleanup on error paths.
Keep track of CCBs, so they cannot be used after a session ends.
Handle CCB timeouts even when the connection is terminated.
Compute firstdata, firstimmed correctly.

assemble_login_parameters() has a strange error reporting convention:
errors are positive numbers, so <= 0 is good, not >= ...
This makes CHAP authenticated iscsi logins work.

use first successful connection to a ISNS server

Add more debugging, fix filehandle usage, login negotiation and session
shutdown.
Add #ifdef'd code to send negotiation parameters in hex instead of base64,
so it works against older Linux targets.

report luns returns a 32bit list length.

Make digests work also on big endian machines.

it's really 32bit
 1.5.2.2 03-Dec-2017  jdolecek update from HEAD
 1.5.2.1 25-Feb-2013  tls resync with head
 1.6.14.3 28-Aug-2017  skrll Sync with HEAD
 1.6.14.2 09-Jul-2016  skrll Sync with HEAD
 1.6.14.1 06-Jun-2015  skrll Sync with HEAD
 1.21.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.21.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.23.4.1 10-Jun-2019  christos Sync with HEAD
 1.27.4.1 18-Dec-2023  martin Pull up following revision(s) (requested by mlelstv in ticket #505):

sys/dev/iscsi/iscsi_utils.c: revision 1.29
sys/dev/iscsi/iscsi.h: revision 1.5
sys/dev/iscsi/iscsi_ioctl.c: revision 1.34
sys/dev/iscsi/iscsi_globals.h: revision 1.28
sys/dev/iscsi/iscsi_text.c: revision 1.14
sys/dev/iscsi/iscsi_send.c: revision 1.40

Adapt to bignum representation of target.

Fix negotiation for mutual authentication.

Prepare for more CHAP types.

Fix crashes for invalid socket descriptors passed to kernel.

Protect usecount with connection mutex, avoids race on connection close.

Minor cosmetics.
 1.37 03-Nov-2024  mlelstv Release cleanup mutex before calling kill_connection.
 1.36 03-Nov-2024  mlelstv Take lock when updating conn state.
 1.35 24-Aug-2024  mlelstv Avoid race in timeout handling.
Don't try to wake up CCB without connection (which led to a NULL pointer deref).
 1.34 25-Nov-2023  mlelstv branches: 1.34.2;
Adapt to bignum representation of target.
Fix negotiation for mutual authentication.
Prepare for more CHAP types.
Fix crashes for invalid socket descriptors passed to kernel.
Protect usecount with connection mutex, avoids race on connection close.
Minor cosmetics.
 1.33 13-Sep-2022  mlelstv branches: 1.33.4;
kill_session now uses the session id to avoid stale session pointers.
protect network socket with rwlock to handle recconnects.
always take over socket from iscsid to prevent leaks.
keep a good connection alive.
don't forget child device when config_detach fails.
fix locking when reassigning CCBs.
pducount is protected by lock, no need for atomic.
some code rework, refined debug messages.
 1.32 21-Jun-2020  chs avoid the use of UVM internals in the iscsi ioctl code.
copyin/out are fine in this context.
 1.31 26-May-2020  kamil Catch up with the usage of struct vmspace::vm_refcnt

Use the dedicated reference counting routines.

Change the type of struct vmspace::vm_refcnt and struct vm_map::ref_count
to volatile.

Remove the unnecessary vm->vm_map.misc_lock locking in process_domem().

Reviewed by <ad>
 1.30 07-Dec-2018  mlelstv interlock isn't taken when cleaning up.
 1.29 06-Dec-2017  ozaki-r branches: 1.29.2; 1.29.4;
Fix typo
 1.28 03-Dec-2017  christos - add a prefix to struct members (but not the ioctl ones because they affect
the API)
- use consistent variable names.
 1.27 03-Dec-2017  mlelstv use same lock for ref/deref.
 1.26 24-Jun-2017  mlelstv Fix session cleanup.
 1.25 25-Feb-2017  mlelstv branches: 1.25.6;
Use correct lock for session wakeup.
 1.24 05-Feb-2017  mlelstv Destroy callouts when cleaning up.
 1.23 25-Dec-2016  mlelstv branches: 1.23.2;
Lock correctly around CV calls.
Fix handling of session termination.
Enable MPSAFE processing for scsipi.
 1.22 15-Jun-2016  mlelstv branches: 1.22.2;
Remove throttling code, instead signal scsipi layer to reduce the openings
and retry the command. Start with a small openings number and let scsipi
request to grow it up to the current send window.

Adjust ccb and pdu counts to avoid ressource shortages. These are still
very ad-hoc numbers, but seem to be sufficient for a Gigabit link.

Use separate condvar for PDU pool and add counter to help debugging.

Revert setting PDU disposition to UNUSED before freeing. free_pdu
uses this as a flag to detect already returned PDUs.

Add reference counter for open commands to defer unmapping a session
that would lead to crashes in scsipi.

Move session cleanup to cleanup thread.

Use get_sernum to retrieve current serial number where possible and
make it check for immediate commands itself.

Adjust debug output.
 1.21 05-Jun-2016  mlelstv use correct comparison of serial numbers
 1.20 05-Jun-2016  mlelstv More debug output. Dump pending CCBs when cleaning up.
 1.19 05-Jun-2016  mlelstv appease compiler
 1.18 05-Jun-2016  mlelstv When stopping a callout, wait until the cleanup thread has processed them.
 1.17 03-Jun-2016  mlelstv use sernum handling function
 1.16 01-Jun-2016  mlelstv refactor callouts
remove timed out ccbs and connections from cleanup queue when stopping timeout.
 1.15 01-Jun-2016  mlelstv close session when last connection is removed.
 1.14 29-May-2016  mlelstv Several improvements to the ISCSI driver.

- Enable debug messages but set log level to be quiet. Provide a
system (hw.iscsi.debug) to set the log level at run time.
- Replace old tsleep/wakeup synchronization with mutexes and condvars.
- Defer actions from callouts (basically timeouts) to the cleanup thread.
- Protect lists and unique ids with mutexes. protect connection usecount
by using atomic operations.
- Assert kernel lock when calling into scsipi and network code.
- Use this to make send/receive/cleanup threads MPSAFE.

- Fix handling of out-of-CCB/out-of-PDU conditions against the scsipi layer.
- Bump number of PDUs to 128 to avoid virtually all out-of-PDU conditions

- Make use of softc structure for attach/detach operations.
- Track open file handles to prevent detach when busy.

- Move some global variables to make them static.

- Fix 'Overlapping Commands Attempted' error by marking commands as
simply ordered (ATTR_SIMPLE) like FreeBSD.
 1.13 19-Sep-2015  dholland Use value *before* freeing it. Found by brainy, reported by maxv.
 1.12 30-May-2015  joerg Create a per-device state for iscsi(4), effectively making it a cloning
device.
 1.11 30-May-2015  joerg Inline SET_CCB_TIMEOUT and SET_CONN_TIMEOUT
 1.10 30-May-2015  joerg Remove ISCSI_PERFTEST.
 1.9 30-May-2015  joerg Remove ISCSI_TEST_MODE and corresponding dev/iscsi_test.h header.
 1.8 15-May-2015  joerg Remove conditionals for NetBSD before 4.0.
 1.7 03-May-2015  joerg Make sure callout is halted, not just stopped, before freeing memory.
 1.6 29-Dec-2012  mlelstv branches: 1.6.14;
- defer session cleanup to not force detachments
- use more and explicit locking
- improve connection recovery
- use larger timeouts
- handle ccb buffer underflow correctly
- simplify throttling code

Sessions can now temporarily exist without a valid
connection, you also need to update iscsid(8).
 1.5 12-Aug-2012  mlelstv branches: 1.5.2;
Don't use common variables, also prefix global variables to avoid
namespace pollution.
 1.4 24-Jun-2012  mlelstv Add more debugging, fix filehandle usage, login negotiation and session
shutdown.
Add #ifdef'd code to send negotiation parameters in hex instead of base64,
so it works against older Linux targets.
 1.3 09-Jun-2012  mlelstv Close file descriptor passed into the kernel on success.
Fix locking of file handle. More cleanup on error paths.
Keep track of CCBs, so they cannot be used after a session ends.
Handle CCB timeouts even when the connection is terminated.
Compute firstdata, firstimmed correctly.
 1.2 27-Jan-2012  para branches: 1.2.2;
extending vmem(9) to be able to allocated resources for it's own needs.
simplifying uvm_map handling (no special kernel entries anymore no relocking)
make malloc(9) a thin wrapper around kmem(9)
(with private interface for interrupt safety reasons)

releng@ acknowledged
 1.1 23-Oct-2011  agc branches: 1.1.2; 1.1.6;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.1.6.1 18-Feb-2012  mrg merge to -current.
 1.1.2.3 23-Jan-2013  yamt sync with head
 1.1.2.2 30-Oct-2012  yamt sync with head
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.2.2.1 03-Jul-2012  jdc Pull up revisions:
src/sys/dev/iscsi/iscsi_globals.h revisions 1.3,1.4
src/sys/dev/iscsi/iscsi_main.c revisions 1.4,1.5
src/sys/dev/iscsi/iscsi_text.c revisions 1.4,1.5
src/sys/dev/iscsi/iscsi_ioctl.c revisions 1.3,1.4
src/sys/dev/iscsi/iscsi_send.c revisions 1.3,1.4,1.5
src/sys/dev/iscsi/iscsi_utils.c revisions 1.2,1.3,1.4
src/sbin/iscsid/iscsid_discover.c revision 1.4
src/sys/dev/iscsi/iscsi_rcv.c revision 1.3
src/sbin/iscsictl/iscsic_driverif.c revisions 1.5,1.6
(requested by martin in ticket #357, with updates from mhitch and mlelstv).

avoid namespace pollution when debugging
don't panic when printing data for a dead (NULL) connection

Close file descriptor passed into the kernel on success.
Fix locking of file handle. More cleanup on error paths.
Keep track of CCBs, so they cannot be used after a session ends.
Handle CCB timeouts even when the connection is terminated.
Compute firstdata, firstimmed correctly.

assemble_login_parameters() has a strange error reporting convention:
errors are positive numbers, so <= 0 is good, not >= ...
This makes CHAP authenticated iscsi logins work.

use first successful connection to a ISNS server

Add more debugging, fix filehandle usage, login negotiation and session
shutdown.
Add #ifdef'd code to send negotiation parameters in hex instead of base64,
so it works against older Linux targets.

report luns returns a 32bit list length.

Make digests work also on big endian machines.

it's really 32bit
 1.5.2.2 03-Dec-2017  jdolecek update from HEAD
 1.5.2.1 25-Feb-2013  tls resync with head
 1.6.14.5 28-Aug-2017  skrll Sync with HEAD
 1.6.14.4 05-Feb-2017  skrll Sync with HEAD
 1.6.14.3 09-Jul-2016  skrll Sync with HEAD
 1.6.14.2 22-Sep-2015  skrll Sync with HEAD
 1.6.14.1 06-Jun-2015  skrll Sync with HEAD
 1.22.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.22.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.23.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.25.6.1 21-Dec-2017  snj Pull up following revision(s) (requested by mlelstv in ticket #437):
sys/dev/iscsi/iscsi_ioctl.c: 1.26-1.27
sys/dev/iscsi/iscsi_main.c: 1.26
sys/dev/iscsi/iscsi_send.c: 1.35
Fix session cleanup.
--
add debug messages
-
use same lock for ref/deref.
--
unreference session only for responses to SCSI commands.
 1.29.4.1 10-Jun-2019  christos Sync with HEAD
 1.29.2.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.33.4.2 01-Nov-2024  martin Pull up following revision(s) (requested by rin in ticket #997):

sys/dev/iscsi/iscsi_ioctl.c: revision 1.35
sys/dev/iscsi/iscsi_main.c: revision 1.42
sys/dev/iscsi/iscsi_send.c: revision 1.41

Use correct status value SCSI_BUSY (0x08) instead of XS_BUSY (7) when
running out of sessions. The bug had no impact as scsipi was only comparing
against SCSI_CHECK (0x02) and SCSI_QUEUE_FULL (0x28).

Avoid race in timeout handling.

Don't try to wake up CCB without connection (which led to a NULL pointer
deref).
 1.33.4.1 18-Dec-2023  martin Pull up following revision(s) (requested by mlelstv in ticket #505):

sys/dev/iscsi/iscsi_utils.c: revision 1.29
sys/dev/iscsi/iscsi.h: revision 1.5
sys/dev/iscsi/iscsi_ioctl.c: revision 1.34
sys/dev/iscsi/iscsi_globals.h: revision 1.28
sys/dev/iscsi/iscsi_text.c: revision 1.14
sys/dev/iscsi/iscsi_send.c: revision 1.40

Adapt to bignum representation of target.

Fix negotiation for mutual authentication.

Prepare for more CHAP types.

Fix crashes for invalid socket descriptors passed to kernel.

Protect usecount with connection mutex, avoids race on connection close.

Minor cosmetics.
 1.34.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 04-Apr-2013  dsl Explicitly #include <sys/scsiio.h> so that the build of usr/bin/kdump
doesn't rely on the order it happens to use for the headers.
 1.2 29-Oct-2011  christos branches: 1.2.2; 1.2.12;
make all bitfields unsigned int
 1.1 23-Oct-2011  agc Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.2.12.1 23-Jun-2013  tls resync from head
 1.2.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.42 28-Dec-2023  mlelstv Use correct status value SCSI_BUSY (0x08) instead of XS_BUSY (7) when running
out of sessions. The bug had no impact as scsipi was only comparing
against SCSI_CHECK (0x02) and SCSI_QUEUE_FULL (0x28).
 1.41 13-Sep-2022  mlelstv branches: 1.41.4;
kill_session now uses the session id to avoid stale session pointers.
protect network socket with rwlock to handle recconnects.
always take over socket from iscsid to prevent leaks.
keep a good connection alive.
don't forget child device when config_detach fails.
fix locking when reassigning CCBs.
pducount is protected by lock, no need for atomic.
some code rework, refined debug messages.
 1.40 14-Apr-2022  pgoyette Split some common stuff into scsi_subr module. This enables loading
of the iscsi module whether or not there are any scsi things built
into the kernel.

Addresses the iscsi portion of kern/56772
 1.39 31-Mar-2022  pgoyette For device modules that provide both auto-config and /dev/xxx
interfaces, make sure that initialization and destruction
follow the proper sequence. This is triggered by the recent
changes to the devsw stuff; per riastradh@ the required call
sequence is:

devsw_attach()
config_init_component() or config_cf*_attach()
...
config_fini_component() or config_cf*_detach()
devsw_detach()

While here, add a few missing calls to some of the detach
routines.

Testing of these changes has been limited to:
1. compile without build break
2. no related test failures from atf
3. modload/modunload work as well as
before.

No functional device testing done, since I don't have any
of these devices. Let me know of any damage I might cause
here!

XXX Some of the modules affected by this commit are already
XXX broken; see kern/56772. This commit does not break
any additional modules (as far as I know).
 1.38 13-Feb-2022  riastradh iscsi(4): Fix config_found usage -- needs kernel lock.

Candidate fix for PR kern/56709.
 1.37 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.36 06-Jun-2021  mlelstv branches: 1.36.2;
Provide missing file ops. Before a simple read() would panic the kernel.
No longer fail close().
 1.35 24-Apr-2021  thorpej branches: 1.35.2; 1.35.6;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.34 07-Mar-2021  mlelstv branches: 1.34.2;
Stop advertising more openings after limit is reached.
 1.33 13-May-2020  jdolecek branches: 1.33.2;
make the iscsi attached message aprint_verbose(), no need to show normally
 1.32 01-Oct-2019  chs in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.
 1.31 07-Aug-2019  pgoyette Many years ago someone created a new __link_set_sysctl_funcs to hold
the list of routines that need to be called for setting up sysctl
variables. This worked great for all code included in the kernel
itself, but didn't deal with modules that want to create their own
sysctl data. So, we ended up with a lot of #ifdef _MODULE blocks
so modules could explicitly call their setup functions when loaded
as non-built-in modules.

So today, we complete the task that was started so many years ago.

When modules are loaded, after we've called xxx_modcmd(INIT...) we
check if the module contains its own __link_set_sysctl_funcs, and
if so we call the functions listed. We add a struct sysctllog member
to the struct module so we can call sysctl_teardown() when the module
gets unloaded. (The sequence of events ensures that the sysctl stuff
doesn't get created until the rest of the module's init code does any
required memory allocation.)

So, no more need to explicitly call the sysctl setup routines when
built as a loadable module.
 1.30 13-Jul-2019  mlelstv register with pmf to allow suspend.
 1.29 21-Apr-2019  mlelstv Replace build option to enable hex encoded bignum parameters with a sysctl.
 1.28 11-Apr-2019  kamil Fix CVS Id

NFCI
 1.27 03-Dec-2017  christos branches: 1.27.4;
- add a prefix to struct members (but not the ioctl ones because they affect
the API)
- use consistent variable names.
 1.26 03-Dec-2017  mlelstv unreference session only for responses to SCSI commands.
 1.25 30-Nov-2017  christos add fo_name so we can identify the fileops in a simple way.
 1.24 25-Dec-2016  mlelstv branches: 1.24.6; 1.24.8;
Lock correctly around CV calls.
Fix handling of session termination.
Enable MPSAFE processing for scsipi.
 1.23 15-Jun-2016  mlelstv branches: 1.23.2;
Remove throttling code, instead signal scsipi layer to reduce the openings
and retry the command. Start with a small openings number and let scsipi
request to grow it up to the current send window.

Adjust ccb and pdu counts to avoid ressource shortages. These are still
very ad-hoc numbers, but seem to be sufficient for a Gigabit link.

Use separate condvar for PDU pool and add counter to help debugging.

Revert setting PDU disposition to UNUSED before freeing. free_pdu
uses this as a flag to detect already returned PDUs.

Add reference counter for open commands to defer unmapping a session
that would lead to crashes in scsipi.

Move session cleanup to cleanup thread.

Use get_sernum to retrieve current serial number where possible and
make it check for immediate commands itself.

Adjust debug output.
 1.22 05-Jun-2016  mlelstv Keep 1 CCB free for private use. This avoids frequent recovery in scsipi when
resources appear to be exhausted.
 1.21 05-Jun-2016  mlelstv Tear down sysctls only after detaching children. This lets you enable
debugging while detaching hangs.
 1.20 05-Jun-2016  mlelstv Whitespace
 1.19 05-Jun-2016  mlelstv More debugging output, changed debug levels for some.
 1.18 29-May-2016  mlelstv Several improvements to the ISCSI driver.

- Enable debug messages but set log level to be quiet. Provide a
system (hw.iscsi.debug) to set the log level at run time.
- Replace old tsleep/wakeup synchronization with mutexes and condvars.
- Defer actions from callouts (basically timeouts) to the cleanup thread.
- Protect lists and unique ids with mutexes. protect connection usecount
by using atomic operations.
- Assert kernel lock when calling into scsipi and network code.
- Use this to make send/receive/cleanup threads MPSAFE.

- Fix handling of out-of-CCB/out-of-PDU conditions against the scsipi layer.
- Bump number of PDUs to 128 to avoid virtually all out-of-PDU conditions

- Make use of softc structure for attach/detach operations.
- Track open file handles to prevent detach when busy.

- Move some global variables to make them static.

- Fix 'Overlapping Commands Attempted' error by marking commands as
simply ordered (ATTR_SIMPLE) like FreeBSD.
 1.17 20-Aug-2015  christos include "ioconf.h" to get the 'void <driver>attach(int count);' prototype.
 1.16 30-May-2015  joerg Create a per-device state for iscsi(4), effectively making it a cloning
device.
 1.15 30-May-2015  joerg Remove ISCSI_PERFTEST.
 1.14 15-May-2015  joerg Don't pre-compute string sizes in a relatively cold function.
 1.13 15-May-2015  joerg Remove conditionals for NetBSD before 4.0.
 1.12 21-Feb-2015  joerg Revert and add comment that this dance is for the sake of builtin module
registration.
 1.11 21-Feb-2015  joerg Simplify.
 1.10 24-Nov-2014  joerg branches: 1.10.2;
iscsi_attrs is not used when iscsi(4) is compiled into the kernel.
 1.9 25-Jul-2014  dholland Add d_discard to all struct cdevsw instances I could find.

All have been set to "nodiscard"; some should get a real implementation.
 1.8 16-Mar-2014  dholland branches: 1.8.2;
Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
 1.7 29-Dec-2012  mlelstv branches: 1.7.2;
- defer session cleanup to not force detachments
- use more and explicit locking
- improve connection recovery
- use larger timeouts
- handle ccb buffer underflow correctly
- simplify throttling code

Sessions can now temporarily exist without a valid
connection, you also need to update iscsid(8).
 1.6 12-Aug-2012  mlelstv branches: 1.6.2;
Don't use common variables, also prefix global variables to avoid
namespace pollution.
 1.5 09-Jun-2012  mlelstv Close file descriptor passed into the kernel on success.
Fix locking of file handle. More cleanup on error paths.
Keep track of CCBs, so they cannot be used after a session ends.
Handle CCB timeouts even when the connection is terminated.
Compute firstdata, firstimmed correctly.
 1.4 02-Jun-2012  mlelstv avoid namespace pollution when debugging
don't panic when printing data for a dead (NULL) connection
 1.3 28-May-2012  riz Expose some of the module framework when _MODULE is not defined, so
iscsi becomes a "built in" module in that case.
 1.2 28-May-2012  riz Don't allow iscsi to autounload. The default unload timeout is short,
and too much state is lost.
 1.1 23-Oct-2011  agc branches: 1.1.2; 1.1.6; 1.1.8;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.1.8.2 03-Jul-2012  jdc Pull up revisions:
src/sys/dev/iscsi/iscsi_globals.h revisions 1.3,1.4
src/sys/dev/iscsi/iscsi_main.c revisions 1.4,1.5
src/sys/dev/iscsi/iscsi_text.c revisions 1.4,1.5
src/sys/dev/iscsi/iscsi_ioctl.c revisions 1.3,1.4
src/sys/dev/iscsi/iscsi_send.c revisions 1.3,1.4,1.5
src/sys/dev/iscsi/iscsi_utils.c revisions 1.2,1.3,1.4
src/sbin/iscsid/iscsid_discover.c revision 1.4
src/sys/dev/iscsi/iscsi_rcv.c revision 1.3
src/sbin/iscsictl/iscsic_driverif.c revisions 1.5,1.6
(requested by martin in ticket #357, with updates from mhitch and mlelstv).

avoid namespace pollution when debugging
don't panic when printing data for a dead (NULL) connection

Close file descriptor passed into the kernel on success.
Fix locking of file handle. More cleanup on error paths.
Keep track of CCBs, so they cannot be used after a session ends.
Handle CCB timeouts even when the connection is terminated.
Compute firstdata, firstimmed correctly.

assemble_login_parameters() has a strange error reporting convention:
errors are positive numbers, so <= 0 is good, not >= ...
This makes CHAP authenticated iscsi logins work.

use first successful connection to a ISNS server

Add more debugging, fix filehandle usage, login negotiation and session
shutdown.
Add #ifdef'd code to send negotiation parameters in hex instead of base64,
so it works against older Linux targets.

report luns returns a 32bit list length.

Make digests work also on big endian machines.

it's really 32bit
 1.1.8.1 30-May-2012  sborrill Pull up the following revisions(s) (requested by riz in ticket #291):
etc/MAKEDEV.tmpl: revision 1.155
sbin/iscsictl/iscsictl.8: revision 1.2-1.4
sbin/iscsid/iscsid_driverif.c: revision 1.4-1.5
sbin/iscsid/iscsid_lists.c: revision 1.4-1.7
sbin/iscsid/iscsid_targets.c: revision 1.4
sbin/iscsid/iscsid_globals.h: revision 1.5-1.7
sbin/iscsid/iscsid_main.c: revision 1.4-1.7
sbin/iscsid/Makefile: revision 1.2-1.4
sbin/iscsid/iscsid.8: revision 1.3-1.8
sbin/iscsid/iscsid.h: revision 1.3
sys/dev/iscsi/iscsi_main.c: revision 1.2-1.3

Fix bugs in iscsid target list handling, and improve documentation
somewhat for the in-kernel iSCSI initiator.
 1.1.6.1 02-Jun-2012  mrg sync to latest -current.
 1.1.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.2.2 23-Jan-2013  yamt sync with head
 1.1.2.1 30-Oct-2012  yamt sync with head
 1.6.2.3 03-Dec-2017  jdolecek update from HEAD
 1.6.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.2.1 25-Feb-2013  tls resync with head
 1.7.2.1 18-May-2014  rmind sync with head
 1.8.2.1 10-Aug-2014  tls Rebase.
 1.10.2.5 05-Feb-2017  skrll Sync with HEAD
 1.10.2.4 09-Jul-2016  skrll Sync with HEAD
 1.10.2.3 22-Sep-2015  skrll Sync with HEAD
 1.10.2.2 06-Jun-2015  skrll Sync with HEAD
 1.10.2.1 06-Apr-2015  skrll Sync with HEAD
 1.23.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.24.8.1 21-Dec-2017  snj Pull up following revision(s) (requested by mlelstv in ticket #437):
sys/dev/iscsi/iscsi_ioctl.c: 1.26-1.27
sys/dev/iscsi/iscsi_main.c: 1.26
sys/dev/iscsi/iscsi_send.c: 1.35
Fix session cleanup.
--
add debug messages
-
use same lock for ref/deref.
--
unreference session only for responses to SCSI commands.
 1.24.6.1 17-May-2017  pgoyette At suggestion of chuq@, modify config_attach_pseudo() to return with a
reference held on the device.

Adapt callers to expect the reference to exist, and to ensure that the
reference is released.
 1.27.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.27.4.1 10-Jun-2019  christos Sync with HEAD
 1.33.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.34.2.1 21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.35.6.1 06-Jun-2021  cjep sync with head
 1.35.2.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.36.2.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.41.4.1 01-Nov-2024  martin Pull up following revision(s) (requested by rin in ticket #997):

sys/dev/iscsi/iscsi_ioctl.c: revision 1.35
sys/dev/iscsi/iscsi_main.c: revision 1.42
sys/dev/iscsi/iscsi_send.c: revision 1.41

Use correct status value SCSI_BUSY (0x08) instead of XS_BUSY (7) when
running out of sessions. The bug had no impact as scsipi was only comparing
against SCSI_CHECK (0x02) and SCSI_QUEUE_FULL (0x28).

Avoid race in timeout handling.

Don't try to wake up CCB without connection (which led to a NULL pointer
deref).
 1.4 03-Dec-2017  christos - add a prefix to struct members (but not the ioctl ones because they affect
the API)
- use consistent variable names.
 1.3 15-Jun-2016  mlelstv Fix field name in response pdu.
 1.2 21-Jun-2014  dholland branches: 1.2.4;
__attribute__ ((__packed__)) -> __packed
 1.1 23-Oct-2011  agc branches: 1.1.12; 1.1.26;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.1.26.1 10-Aug-2014  tls Rebase.
 1.1.12.2 03-Dec-2017  jdolecek update from HEAD
 1.1.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.4.1 09-Jul-2016  skrll Sync with HEAD
 1.2 30-May-2015  joerg Remove ISCSI_PERFTEST.
 1.1 23-Oct-2011  agc branches: 1.1.12; 1.1.30;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.1.30.1 06-Jun-2015  skrll Sync with HEAD
 1.1.12.1 03-Dec-2017  jdolecek update from HEAD
 1.2 30-May-2015  joerg Remove ISCSI_PERFTEST.
 1.1 23-Oct-2011  agc branches: 1.1.12; 1.1.30;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.1.30.1 06-Jun-2015  skrll Sync with HEAD
 1.1.12.1 03-Dec-2017  jdolecek update from HEAD
 1.2 30-May-2015  joerg Remove ISCSI_PERFTEST.
 1.1 23-Oct-2011  agc branches: 1.1.12; 1.1.30;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.1.30.1 06-Jun-2015  skrll Sync with HEAD
 1.1.12.1 03-Dec-2017  jdolecek update from HEAD
 1.27 03-Nov-2024  mlelstv Take lock when updating conn state.
 1.26 13-Sep-2022  mlelstv branches: 1.26.10;
kill_session now uses the session id to avoid stale session pointers.
protect network socket with rwlock to handle recconnects.
always take over socket from iscsid to prevent leaks.
keep a good connection alive.
don't forget child device when config_detach fails.
fix locking when reassigning CCBs.
pducount is protected by lock, no need for atomic.
some code rework, refined debug messages.
 1.25 04-Mar-2018  mlelstv Add sanity check.
 1.24 03-Dec-2017  christos - add a prefix to struct members (but not the ioctl ones because they affect
the API)
- use consistent variable names.
 1.23 25-Dec-2016  mlelstv branches: 1.23.8;
Lock correctly around CV calls.
Fix handling of session termination.
Enable MPSAFE processing for scsipi.
 1.22 15-Jun-2016  mlelstv branches: 1.22.2;
Work around an issue with MSG_WAITALL that would block for too long by
replacing it with a receive loop.
 1.21 15-Jun-2016  mlelstv Remove throttling code, instead signal scsipi layer to reduce the openings
and retry the command. Start with a small openings number and let scsipi
request to grow it up to the current send window.

Adjust ccb and pdu counts to avoid ressource shortages. These are still
very ad-hoc numbers, but seem to be sufficient for a Gigabit link.

Use separate condvar for PDU pool and add counter to help debugging.

Revert setting PDU disposition to UNUSED before freeing. free_pdu
uses this as a flag to detect already returned PDUs.

Add reference counter for open commands to defer unmapping a session
that would lead to crashes in scsipi.

Move session cleanup to cleanup thread.

Use get_sernum to retrieve current serial number where possible and
make it check for immediate commands itself.

Adjust debug output.
 1.20 05-Jun-2016  mlelstv Don't resume throttled CCBs when connection is terminating, except for
those being actively waited for. Stop unthrottling when reaching MaxCmdSN
again.
 1.19 05-Jun-2016  mlelstv more debug output
 1.18 05-Jun-2016  mlelstv Whitespace, braces.
 1.17 05-Jun-2016  mlelstv No need to acquire KERNEL_LOCK when entering network code.
Also use the socket callbacks.
 1.16 05-Jun-2016  mlelstv Handle ExpCmdSN and MaxCmdSN updates as specified. Don't compare
serial numbers as integers.
 1.15 05-Jun-2016  mlelstv Fix serial number check and account for commands in flight to avoid
unnecessary recovery actions.
 1.14 05-Jun-2016  mlelstv ignore invalid ITT
 1.13 05-Jun-2016  mlelstv More debugging output, changed debug levels for some.
 1.12 01-Jun-2016  mlelstv refactor callouts
remove timed out ccbs and connections from cleanup queue when stopping timeout.
 1.11 29-May-2016  mlelstv Several improvements to the ISCSI driver.

- Enable debug messages but set log level to be quiet. Provide a
system (hw.iscsi.debug) to set the log level at run time.
- Replace old tsleep/wakeup synchronization with mutexes and condvars.
- Defer actions from callouts (basically timeouts) to the cleanup thread.
- Protect lists and unique ids with mutexes. protect connection usecount
by using atomic operations.
- Assert kernel lock when calling into scsipi and network code.
- Use this to make send/receive/cleanup threads MPSAFE.

- Fix handling of out-of-CCB/out-of-PDU conditions against the scsipi layer.
- Bump number of PDUs to 128 to avoid virtually all out-of-PDU conditions

- Make use of softc structure for attach/detach operations.
- Track open file handles to prevent detach when busy.

- Move some global variables to make them static.

- Fix 'Overlapping Commands Attempted' error by marking commands as
simply ordered (ATTR_SIMPLE) like FreeBSD.
 1.10 30-May-2015  joerg Inline SET_CCB_TIMEOUT and SET_CONN_TIMEOUT
 1.9 30-May-2015  joerg Remove ISCSI_PERFTEST.
 1.8 30-May-2015  joerg Remove ISCSI_TEST_MODE and corresponding dev/iscsi_test.h header.
 1.7 15-May-2015  joerg Remove conditionals for NetBSD before 4.0.
 1.6 05-Sep-2014  matt branches: 1.6.2;
Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.
 1.5 20-Oct-2013  christos 2 splbios in a row does not make sense. make the second one splx.
 1.4 29-Dec-2012  mlelstv branches: 1.4.2;
- defer session cleanup to not force detachments
- use more and explicit locking
- improve connection recovery
- use larger timeouts
- handle ccb buffer underflow correctly
- simplify throttling code

Sessions can now temporarily exist without a valid
connection, you also need to update iscsid(8).
 1.3 24-Jun-2012  mlelstv branches: 1.3.2;
Add more debugging, fix filehandle usage, login negotiation and session
shutdown.
Add #ifdef'd code to send negotiation parameters in hex instead of base64,
so it works against older Linux targets.
 1.2 05-Jun-2012  mhitch Fix system freeze when trying to write to a raw iSCSI device with MAXPHYS
bytes. Newfs does large writes when initializing the filesystem.
First, don't copy the head of a TAILQ to make a copy - the first entry will
still point back to the original head. This caused the ccb list to link to
itself, resulting in a continous loop processing the same ccb and blocked
interrupts. Use TAILQ_CONCAT() to copy the list.
Next, the ccb disposition was not set in the ccb when the ccb was throttled,
losing the CCBDISP_SCSIPI, so when a throttled ccb was resent, it failed to
call scscipi_done(), and left that I/O hanging.
I am now able to newfs an iSCSI device, was well as issued large writes
using dd.
 1.1 23-Oct-2011  agc branches: 1.1.2; 1.1.8;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.1.8.2 03-Jul-2012  jdc Pull up revisions:
src/sys/dev/iscsi/iscsi_globals.h revisions 1.3,1.4
src/sys/dev/iscsi/iscsi_main.c revisions 1.4,1.5
src/sys/dev/iscsi/iscsi_text.c revisions 1.4,1.5
src/sys/dev/iscsi/iscsi_ioctl.c revisions 1.3,1.4
src/sys/dev/iscsi/iscsi_send.c revisions 1.3,1.4,1.5
src/sys/dev/iscsi/iscsi_utils.c revisions 1.2,1.3,1.4
src/sbin/iscsid/iscsid_discover.c revision 1.4
src/sys/dev/iscsi/iscsi_rcv.c revision 1.3
src/sbin/iscsictl/iscsic_driverif.c revisions 1.5,1.6
(requested by martin in ticket #357, with updates from mhitch and mlelstv).

avoid namespace pollution when debugging
don't panic when printing data for a dead (NULL) connection

Close file descriptor passed into the kernel on success.
Fix locking of file handle. More cleanup on error paths.
Keep track of CCBs, so they cannot be used after a session ends.
Handle CCB timeouts even when the connection is terminated.
Compute firstdata, firstimmed correctly.

assemble_login_parameters() has a strange error reporting convention:
errors are positive numbers, so <= 0 is good, not >= ...
This makes CHAP authenticated iscsi logins work.

use first successful connection to a ISNS server

Add more debugging, fix filehandle usage, login negotiation and session
shutdown.
Add #ifdef'd code to send negotiation parameters in hex instead of base64,
so it works against older Linux targets.

report luns returns a 32bit list length.

Make digests work also on big endian machines.

it's really 32bit
 1.1.8.1 12-Jun-2012  riz Pull up following revision(s) (requested by mhitch in ticket #323):
sys/dev/iscsi/iscsi_send.c: revision 1.2
sys/dev/iscsi/iscsi_rcv.c: revision 1.2
Fix system freeze when trying to write to a raw iSCSI device with MAXPHYS
bytes. Newfs does large writes when initializing the filesystem.
First, don't copy the head of a TAILQ to make a copy - the first entry will
still point back to the original head. This caused the ccb list to link to
itself, resulting in a continous loop processing the same ccb and blocked
interrupts. Use TAILQ_CONCAT() to copy the list.
Next, the ccb disposition was not set in the ccb when the ccb was throttled,
losing the CCBDISP_SCSIPI, so when a throttled ccb was resent, it failed to
call scscipi_done(), and left that I/O hanging.
I am now able to newfs an iSCSI device, was well as issued large writes
using dd.
 1.1.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.2.2 23-Jan-2013  yamt sync with head
 1.1.2.1 30-Oct-2012  yamt sync with head
 1.3.2.3 03-Dec-2017  jdolecek update from HEAD
 1.3.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.3.2.1 25-Feb-2013  tls resync with head
 1.4.2.1 18-May-2014  rmind sync with head
 1.6.2.3 05-Feb-2017  skrll Sync with HEAD
 1.6.2.2 09-Jul-2016  skrll Sync with HEAD
 1.6.2.1 06-Jun-2015  skrll Sync with HEAD
 1.22.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.23.8.1 09-Apr-2018  bouyer Pull up following revision(s) (requested by mlelstv in ticket #709):
sys/dev/iscsi/iscsi_send.c: revision 1.37 via patch
sys/dev/iscsi/iscsi_rcv.c: revision 1.25 via patch
Return temporary errors when the session is trying to recover the last
connection. The scsipi layer will retry.
Add sanity check.
 1.26.10.1 02-Aug-2025  perseant Sync with HEAD
 1.41 24-Aug-2024  mlelstv Avoid race in timeout handling.
Don't try to wake up CCB without connection (which led to a NULL pointer deref).
 1.40 25-Nov-2023  mlelstv branches: 1.40.2;
Adapt to bignum representation of target.
Fix negotiation for mutual authentication.
Prepare for more CHAP types.
Fix crashes for invalid socket descriptors passed to kernel.
Protect usecount with connection mutex, avoids race on connection close.
Minor cosmetics.
 1.39 13-Sep-2022  mlelstv branches: 1.39.4;
kill_session now uses the session id to avoid stale session pointers.
protect network socket with rwlock to handle recconnects.
always take over socket from iscsid to prevent leaks.
keep a good connection alive.
don't forget child device when config_detach fails.
fix locking when reassigning CCBs.
pducount is protected by lock, no need for atomic.
some code rework, refined debug messages.
 1.38 06-Jun-2021  mlelstv Schedule command timeout without connection lock being held to prevent
a deadlock.
 1.37 04-Mar-2018  mlelstv branches: 1.37.22; 1.37.26;
Return temporary errors when the session is trying to recover the last
connection. The scsipi layer will retry.
 1.36 03-Dec-2017  christos - add a prefix to struct members (but not the ioctl ones because they affect
the API)
- use consistent variable names.
 1.35 03-Dec-2017  mlelstv add debug messages
 1.34 25-Feb-2017  mlelstv branches: 1.34.6;
Use correct lock for session wakeup.
 1.33 05-Feb-2017  mlelstv Destroy callouts when cleaning up.
 1.32 25-Dec-2016  mlelstv branches: 1.32.2;
Lock correctly around CV calls.
Fix handling of session termination.
Enable MPSAFE processing for scsipi.
 1.31 15-Jun-2016  mlelstv branches: 1.31.2;
Remove throttling code, instead signal scsipi layer to reduce the openings
and retry the command. Start with a small openings number and let scsipi
request to grow it up to the current send window.

Adjust ccb and pdu counts to avoid ressource shortages. These are still
very ad-hoc numbers, but seem to be sufficient for a Gigabit link.

Use separate condvar for PDU pool and add counter to help debugging.

Revert setting PDU disposition to UNUSED before freeing. free_pdu
uses this as a flag to detect already returned PDUs.

Add reference counter for open commands to defer unmapping a session
that would lead to crashes in scsipi.

Move session cleanup to cleanup thread.

Use get_sernum to retrieve current serial number where possible and
make it check for immediate commands itself.

Adjust debug output.
 1.30 05-Jun-2016  mlelstv Handle freeing of PDU when referencing CCB is freed.
 1.29 05-Jun-2016  mlelstv wrong assertion.
 1.28 05-Jun-2016  mlelstv Need session mutex to read serial number.
 1.27 05-Jun-2016  mlelstv Add missing mutex_exit().
 1.26 05-Jun-2016  mlelstv Whitespace, braces.
 1.25 05-Jun-2016  mlelstv Replace the simple tag counter with the command tag coming down from scsipi.
Also set attributes according to tag types.
 1.24 05-Jun-2016  mlelstv No need to acquire KERNEL_LOCK when entering network code.
Also use the socket callbacks.
 1.23 05-Jun-2016  mlelstv Make PDU init routines record serial number in CCB too.
 1.22 05-Jun-2016  mlelstv Fix locking for pdu flags here, in particular PDUF_INQUEUE.
 1.21 05-Jun-2016  mlelstv More debugging output, changed debug levels for some.
 1.20 03-Jun-2016  mlelstv fix debug message
 1.19 01-Jun-2016  mlelstv don't sleep in run_xfer path.
 1.18 01-Jun-2016  mlelstv refactor callouts
remove timed out ccbs and connections from cleanup queue when stopping timeout.
 1.17 01-Jun-2016  mlelstv factor out sernum handling.
make incrementing sernum atomic.
declare variables for atomic operations as volatile.
 1.16 29-May-2016  mlelstv Several improvements to the ISCSI driver.

- Enable debug messages but set log level to be quiet. Provide a
system (hw.iscsi.debug) to set the log level at run time.
- Replace old tsleep/wakeup synchronization with mutexes and condvars.
- Defer actions from callouts (basically timeouts) to the cleanup thread.
- Protect lists and unique ids with mutexes. protect connection usecount
by using atomic operations.
- Assert kernel lock when calling into scsipi and network code.
- Use this to make send/receive/cleanup threads MPSAFE.

- Fix handling of out-of-CCB/out-of-PDU conditions against the scsipi layer.
- Bump number of PDUs to 128 to avoid virtually all out-of-PDU conditions

- Make use of softc structure for attach/detach operations.
- Track open file handles to prevent detach when busy.

- Move some global variables to make them static.

- Fix 'Overlapping Commands Attempted' error by marking commands as
simply ordered (ATTR_SIMPLE) like FreeBSD.
 1.15 24-Dec-2015  knakahara fix amd64/conf/ALL build failure
 1.14 30-May-2015  joerg Inline SET_CCB_TIMEOUT and SET_CONN_TIMEOUT
 1.13 30-May-2015  joerg Remove ISCSI_PERFTEST.
 1.12 30-May-2015  joerg Remove ISCSI_TEST_MODE and corresponding dev/iscsi_test.h header.
 1.11 15-May-2015  joerg Remove conditionals for NetBSD before 4.0.
 1.10 25-Sep-2014  tls branches: 1.10.2;
The "throttling" code in the in-kernel iSCSI initiator is very questionable;
it sleeps on a ccb that appears highly unlikely to wake up, since it seems
to be waiting to _submit_ that very ccb! This is doubtless why someone tried
to disable it in the default case via several #defines.

Unfortunately one of those #defines is later tested backwards. Fix that.
The in-kernel initiator now seems to survive a system build without hanging.
 1.9 05-Sep-2014  matt Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.
 1.8 29-Dec-2012  mlelstv branches: 1.8.12;
- defer session cleanup to not force detachments
- use more and explicit locking
- improve connection recovery
- use larger timeouts
- handle ccb buffer underflow correctly
- simplify throttling code

Sessions can now temporarily exist without a valid
connection, you also need to update iscsid(8).
 1.7 09-Sep-2012  mhitch branches: 1.7.2;
Remove an erroneous change that crept in. It was part of an earlier,
incorrect fix I had done for writing > 64K bytes. It was still in the
set of changes mlelstv had committed. I noticed it at the time, but did
not think it was problematic - until now. This fixes the ccb corruption
I was seeing and fixes PR kern/46896.
 1.6 12-Aug-2012  mlelstv Don't use common variables, also prefix global variables to avoid
namespace pollution.
 1.5 24-Jun-2012  mlelstv Add more debugging, fix filehandle usage, login negotiation and session
shutdown.
Add #ifdef'd code to send negotiation parameters in hex instead of base64,
so it works against older Linux targets.
 1.4 19-Jun-2012  martin assemble_login_parameters() has a strange error reporting convention:
errors are positive numbers, so <= 0 is good, not >= ...
This makes CHAP authenticated iscsi logins work.
 1.3 09-Jun-2012  mlelstv Close file descriptor passed into the kernel on success.
Fix locking of file handle. More cleanup on error paths.
Keep track of CCBs, so they cannot be used after a session ends.
Handle CCB timeouts even when the connection is terminated.
Compute firstdata, firstimmed correctly.
 1.2 05-Jun-2012  mhitch Fix system freeze when trying to write to a raw iSCSI device with MAXPHYS
bytes. Newfs does large writes when initializing the filesystem.
First, don't copy the head of a TAILQ to make a copy - the first entry will
still point back to the original head. This caused the ccb list to link to
itself, resulting in a continous loop processing the same ccb and blocked
interrupts. Use TAILQ_CONCAT() to copy the list.
Next, the ccb disposition was not set in the ccb when the ccb was throttled,
losing the CCBDISP_SCSIPI, so when a throttled ccb was resent, it failed to
call scscipi_done(), and left that I/O hanging.
I am now able to newfs an iSCSI device, was well as issued large writes
using dd.
 1.1 23-Oct-2011  agc branches: 1.1.2; 1.1.8;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.1.8.2 03-Jul-2012  jdc Pull up revisions:
src/sys/dev/iscsi/iscsi_globals.h revisions 1.3,1.4
src/sys/dev/iscsi/iscsi_main.c revisions 1.4,1.5
src/sys/dev/iscsi/iscsi_text.c revisions 1.4,1.5
src/sys/dev/iscsi/iscsi_ioctl.c revisions 1.3,1.4
src/sys/dev/iscsi/iscsi_send.c revisions 1.3,1.4,1.5
src/sys/dev/iscsi/iscsi_utils.c revisions 1.2,1.3,1.4
src/sbin/iscsid/iscsid_discover.c revision 1.4
src/sys/dev/iscsi/iscsi_rcv.c revision 1.3
src/sbin/iscsictl/iscsic_driverif.c revisions 1.5,1.6
(requested by martin in ticket #357, with updates from mhitch and mlelstv).

avoid namespace pollution when debugging
don't panic when printing data for a dead (NULL) connection

Close file descriptor passed into the kernel on success.
Fix locking of file handle. More cleanup on error paths.
Keep track of CCBs, so they cannot be used after a session ends.
Handle CCB timeouts even when the connection is terminated.
Compute firstdata, firstimmed correctly.

assemble_login_parameters() has a strange error reporting convention:
errors are positive numbers, so <= 0 is good, not >= ...
This makes CHAP authenticated iscsi logins work.

use first successful connection to a ISNS server

Add more debugging, fix filehandle usage, login negotiation and session
shutdown.
Add #ifdef'd code to send negotiation parameters in hex instead of base64,
so it works against older Linux targets.

report luns returns a 32bit list length.

Make digests work also on big endian machines.

it's really 32bit
 1.1.8.1 12-Jun-2012  riz Pull up following revision(s) (requested by mhitch in ticket #323):
sys/dev/iscsi/iscsi_send.c: revision 1.2
sys/dev/iscsi/iscsi_rcv.c: revision 1.2
Fix system freeze when trying to write to a raw iSCSI device with MAXPHYS
bytes. Newfs does large writes when initializing the filesystem.
First, don't copy the head of a TAILQ to make a copy - the first entry will
still point back to the original head. This caused the ccb list to link to
itself, resulting in a continous loop processing the same ccb and blocked
interrupts. Use TAILQ_CONCAT() to copy the list.
Next, the ccb disposition was not set in the ccb when the ccb was throttled,
losing the CCBDISP_SCSIPI, so when a throttled ccb was resent, it failed to
call scscipi_done(), and left that I/O hanging.
I am now able to newfs an iSCSI device, was well as issued large writes
using dd.
 1.1.2.2 23-Jan-2013  yamt sync with head
 1.1.2.1 30-Oct-2012  yamt sync with head
 1.7.2.2 03-Dec-2017  jdolecek update from HEAD
 1.7.2.1 25-Feb-2013  tls resync with head
 1.8.12.1 29-Sep-2014  msaitoh Pull up following revision(s) (requested by tls in ticket #119):
sys/dev/iscsi/iscsi_send.c: revision 1.10
The "throttling" code in the in-kernel iSCSI initiator is very questionable;
it sleeps on a ccb that appears highly unlikely to wake up, since it seems
to be waiting to _submit_ that very ccb! This is doubtless why someone tried
to disable it in the default case via several #defines.
Unfortunately one of those #defines is later tested backwards. Fix that.
The in-kernel initiator now seems to survive a system build without hanging.
 1.10.2.5 28-Aug-2017  skrll Sync with HEAD
 1.10.2.4 05-Feb-2017  skrll Sync with HEAD
 1.10.2.3 09-Jul-2016  skrll Sync with HEAD
 1.10.2.2 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.10.2.1 06-Jun-2015  skrll Sync with HEAD
 1.31.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.31.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.32.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.34.6.2 09-Apr-2018  bouyer Pull up following revision(s) (requested by mlelstv in ticket #709):
sys/dev/iscsi/iscsi_send.c: revision 1.37 via patch
sys/dev/iscsi/iscsi_rcv.c: revision 1.25 via patch
Return temporary errors when the session is trying to recover the last
connection. The scsipi layer will retry.
Add sanity check.
 1.34.6.1 21-Dec-2017  snj Pull up following revision(s) (requested by mlelstv in ticket #437):
sys/dev/iscsi/iscsi_ioctl.c: 1.26-1.27
sys/dev/iscsi/iscsi_main.c: 1.26
sys/dev/iscsi/iscsi_send.c: 1.35
Fix session cleanup.
--
add debug messages
-
use same lock for ref/deref.
--
unreference session only for responses to SCSI commands.
 1.37.26.1 06-Jun-2021  cjep sync with head
 1.37.22.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.39.4.2 01-Nov-2024  martin Pull up following revision(s) (requested by rin in ticket #997):

sys/dev/iscsi/iscsi_ioctl.c: revision 1.35
sys/dev/iscsi/iscsi_main.c: revision 1.42
sys/dev/iscsi/iscsi_send.c: revision 1.41

Use correct status value SCSI_BUSY (0x08) instead of XS_BUSY (7) when
running out of sessions. The bug had no impact as scsipi was only comparing
against SCSI_CHECK (0x02) and SCSI_QUEUE_FULL (0x28).

Avoid race in timeout handling.

Don't try to wake up CCB without connection (which led to a NULL pointer
deref).
 1.39.4.1 18-Dec-2023  martin Pull up following revision(s) (requested by mlelstv in ticket #505):

sys/dev/iscsi/iscsi_utils.c: revision 1.29
sys/dev/iscsi/iscsi.h: revision 1.5
sys/dev/iscsi/iscsi_ioctl.c: revision 1.34
sys/dev/iscsi/iscsi_globals.h: revision 1.28
sys/dev/iscsi/iscsi_text.c: revision 1.14
sys/dev/iscsi/iscsi_send.c: revision 1.40

Adapt to bignum representation of target.

Fix negotiation for mutual authentication.

Prepare for more CHAP types.

Fix crashes for invalid socket descriptors passed to kernel.

Protect usecount with connection mutex, avoids race on connection close.

Minor cosmetics.
 1.40.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 30-May-2015  joerg Remove ISCSI_TEST_MODE and corresponding dev/iscsi_test.h header.
 1.4 13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.3 29-Dec-2012  mlelstv branches: 1.3.14;
- defer session cleanup to not force detachments
- use more and explicit locking
- improve connection recovery
- use larger timeouts
- handle ccb buffer underflow correctly
- simplify throttling code

Sessions can now temporarily exist without a valid
connection, you also need to update iscsid(8).
 1.2 29-Nov-2011  tls branches: 1.2.8;
Remove rnd_extract_data from the public kernel API (it is for use by the
stream generators only). Clean up some related minor issues.
 1.1 23-Oct-2011  agc branches: 1.1.2;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.1.2.2 23-Jan-2013  yamt sync with head
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.2.8.2 03-Dec-2017  jdolecek update from HEAD
 1.2.8.1 25-Feb-2013  tls resync with head
 1.3.14.1 06-Jun-2015  skrll Sync with HEAD
 1.2 30-May-2015  joerg Remove ISCSI_TEST_MODE and corresponding dev/iscsi_test.h header.
 1.1 23-Oct-2011  agc branches: 1.1.12; 1.1.30;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.1.30.1 06-Jun-2015  skrll Sync with HEAD
 1.1.12.1 03-Dec-2017  jdolecek update from HEAD
 1.2 30-May-2015  joerg Remove ISCSI_TEST_MODE and corresponding dev/iscsi_test.h header.
 1.1 23-Oct-2011  agc branches: 1.1.12; 1.1.30;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.1.30.1 06-Jun-2015  skrll Sync with HEAD
 1.1.12.1 03-Dec-2017  jdolecek update from HEAD
 1.15 08-Feb-2024  andvar s/should't/shouldn't/ and s/mistmatch/mismatch/ in comments.
 1.14 25-Nov-2023  mlelstv Adapt to bignum representation of target.
Fix negotiation for mutual authentication.
Prepare for more CHAP types.
Fix crashes for invalid socket descriptors passed to kernel.
Protect usecount with connection mutex, avoids race on connection close.
Minor cosmetics.
 1.13 21-Apr-2019  maya branches: 1.13.28;
wether -> whether
 1.12 21-Apr-2019  mlelstv Replace build option to enable hex encoded bignum parameters with a sysctl.
 1.11 03-Dec-2017  christos branches: 1.11.4;
- add a prefix to struct members (but not the ioctl ones because they affect
the API)
- use consistent variable names.
 1.10 29-May-2016  mlelstv Several improvements to the ISCSI driver.

- Enable debug messages but set log level to be quiet. Provide a
system (hw.iscsi.debug) to set the log level at run time.
- Replace old tsleep/wakeup synchronization with mutexes and condvars.
- Defer actions from callouts (basically timeouts) to the cleanup thread.
- Protect lists and unique ids with mutexes. protect connection usecount
by using atomic operations.
- Assert kernel lock when calling into scsipi and network code.
- Use this to make send/receive/cleanup threads MPSAFE.

- Fix handling of out-of-CCB/out-of-PDU conditions against the scsipi layer.
- Bump number of PDUs to 128 to avoid virtually all out-of-PDU conditions

- Make use of softc structure for attach/detach operations.
- Track open file handles to prevent detach when busy.

- Move some global variables to make them static.

- Fix 'Overlapping Commands Attempted' error by marking commands as
simply ordered (ATTR_SIMPLE) like FreeBSD.
 1.9 30-May-2015  joerg Remove ISCSI_TEST_MODE and corresponding dev/iscsi_test.h header.
 1.8 15-May-2015  joerg Drop conditional support for writing large numbers as hex.
 1.7 28-Mar-2014  christos branches: 1.7.6;
avoid buffer overflow
 1.6 12-Aug-2012  mlelstv branches: 1.6.2; 1.6.4;
Don't use common variables, also prefix global variables to avoid
namespace pollution.
 1.5 24-Jun-2012  mlelstv Add more debugging, fix filehandle usage, login negotiation and session
shutdown.
Add #ifdef'd code to send negotiation parameters in hex instead of base64,
so it works against older Linux targets.
 1.4 09-Jun-2012  mlelstv Close file descriptor passed into the kernel on success.
Fix locking of file handle. More cleanup on error paths.
Keep track of CCBs, so they cannot be used after a session ends.
Handle CCB timeouts even when the connection is terminated.
Compute firstdata, firstimmed correctly.
 1.3 17-Dec-2011  tls branches: 1.3.2;

Separate /dev/random pseudodevice implemenation from kernel entropy pool
implementation. Rewrite pseudodevice code to use cprng_strong(9).

The new pseudodevice is cloning, so each caller gets bits from a stream
generated with its own key. Users of /dev/urandom get their generators
keyed on a "best effort" basis -- the kernel will rekey generators
whenever the entropy pool hits the high water mark -- while users of
/dev/random get their generators rekeyed every time key-length bits
are output.

The underlying cprng_strong API can use AES-256 or AES-128, but we use
AES-128 because of concerns about related-key attacks on AES-256. This
improves performance (and reduces entropy pool depletion) significantly
for users of /dev/urandom but does cause users of /dev/random to rekey
twice as often.

Also fixes various bugs (including some missing locking and a reseed-counter
overflow in the CTR_DRBG code) found while testing this.

For long reads, this generator is approximately 20 times as fast as the
old generator (dd with bs=64K yields 53MB/sec on 2Ghz Core2 instead of
2.5MB/sec) and also uses a separate mutex per instance so concurrency
is greatly improved. For reads of typical key sizes for modern
cryptosystems (16-32 bytes) performance is about the same as the old
code: a little better for 32 bytes, a little worse for 16 bytes.
 1.2 29-Nov-2011  tls branches: 1.2.2;
Remove rnd_extract_data from the public kernel API (it is for use by the
stream generators only). Clean up some related minor issues.
 1.1 23-Oct-2011  agc branches: 1.1.2;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.1.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.2.2 30-Oct-2012  yamt sync with head
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.2.2.1 18-Feb-2012  mrg merge to -current.
 1.3.2.1 03-Jul-2012  jdc Pull up revisions:
src/sys/dev/iscsi/iscsi_globals.h revisions 1.3,1.4
src/sys/dev/iscsi/iscsi_main.c revisions 1.4,1.5
src/sys/dev/iscsi/iscsi_text.c revisions 1.4,1.5
src/sys/dev/iscsi/iscsi_ioctl.c revisions 1.3,1.4
src/sys/dev/iscsi/iscsi_send.c revisions 1.3,1.4,1.5
src/sys/dev/iscsi/iscsi_utils.c revisions 1.2,1.3,1.4
src/sbin/iscsid/iscsid_discover.c revision 1.4
src/sys/dev/iscsi/iscsi_rcv.c revision 1.3
src/sbin/iscsictl/iscsic_driverif.c revisions 1.5,1.6
(requested by martin in ticket #357, with updates from mhitch and mlelstv).

avoid namespace pollution when debugging
don't panic when printing data for a dead (NULL) connection

Close file descriptor passed into the kernel on success.
Fix locking of file handle. More cleanup on error paths.
Keep track of CCBs, so they cannot be used after a session ends.
Handle CCB timeouts even when the connection is terminated.
Compute firstdata, firstimmed correctly.

assemble_login_parameters() has a strange error reporting convention:
errors are positive numbers, so <= 0 is good, not >= ...
This makes CHAP authenticated iscsi logins work.

use first successful connection to a ISNS server

Add more debugging, fix filehandle usage, login negotiation and session
shutdown.
Add #ifdef'd code to send negotiation parameters in hex instead of base64,
so it works against older Linux targets.

report luns returns a 32bit list length.

Make digests work also on big endian machines.

it's really 32bit
 1.6.4.1 18-May-2014  rmind sync with head
 1.6.2.2 03-Dec-2017  jdolecek update from HEAD
 1.6.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7.6.2 09-Jul-2016  skrll Sync with HEAD
 1.7.6.1 06-Jun-2015  skrll Sync with HEAD
 1.11.4.1 10-Jun-2019  christos Sync with HEAD
 1.13.28.1 18-Dec-2023  martin Pull up following revision(s) (requested by mlelstv in ticket #505):

sys/dev/iscsi/iscsi_utils.c: revision 1.29
sys/dev/iscsi/iscsi.h: revision 1.5
sys/dev/iscsi/iscsi_ioctl.c: revision 1.34
sys/dev/iscsi/iscsi_globals.h: revision 1.28
sys/dev/iscsi/iscsi_text.c: revision 1.14
sys/dev/iscsi/iscsi_send.c: revision 1.40

Adapt to bignum representation of target.

Fix negotiation for mutual authentication.

Prepare for more CHAP types.

Fix crashes for invalid socket descriptors passed to kernel.

Protect usecount with connection mutex, avoids race on connection close.

Minor cosmetics.
 1.29 25-Nov-2023  mlelstv Adapt to bignum representation of target.
Fix negotiation for mutual authentication.
Prepare for more CHAP types.
Fix crashes for invalid socket descriptors passed to kernel.
Protect usecount with connection mutex, avoids race on connection close.
Minor cosmetics.
 1.28 13-Sep-2022  mlelstv branches: 1.28.4;
kill_session now uses the session id to avoid stale session pointers.
protect network socket with rwlock to handle recconnects.
always take over socket from iscsid to prevent leaks.
keep a good connection alive.
don't forget child device when config_detach fails.
fix locking when reassigning CCBs.
pducount is protected by lock, no need for atomic.
some code rework, refined debug messages.
 1.27 21-Apr-2019  maya wether -> whether
 1.26 01-Apr-2019  msaitoh Fix typo in comment (s/numer/number/).
 1.25 01-Feb-2019  mrg fix FALLTRHOUGH spell-o.
 1.24 03-Dec-2017  christos branches: 1.24.4;
- add a prefix to struct members (but not the ioctl ones because they affect
the API)
- use consistent variable names.
 1.23 05-Feb-2017  mlelstv Destroy callouts when cleaning up.
 1.22 25-Dec-2016  mlelstv branches: 1.22.2;
Lock correctly around CV calls.
Fix handling of session termination.
Enable MPSAFE processing for scsipi.
 1.21 15-Jun-2016  mlelstv branches: 1.21.2;
Remove throttling code, instead signal scsipi layer to reduce the openings
and retry the command. Start with a small openings number and let scsipi
request to grow it up to the current send window.

Adjust ccb and pdu counts to avoid ressource shortages. These are still
very ad-hoc numbers, but seem to be sufficient for a Gigabit link.

Use separate condvar for PDU pool and add counter to help debugging.

Revert setting PDU disposition to UNUSED before freeing. free_pdu
uses this as a flag to detect already returned PDUs.

Add reference counter for open commands to defer unmapping a session
that would lead to crashes in scsipi.

Move session cleanup to cleanup thread.

Use get_sernum to retrieve current serial number where possible and
make it check for immediate commands itself.

Adjust debug output.
 1.20 15-Jun-2016  mlelstv drop unused debug helper routine
 1.19 05-Jun-2016  mlelstv Handle freeing of PDU when referencing CCB is freed.
 1.18 05-Jun-2016  mlelstv acquire session lock when changing throttling queue
 1.17 05-Jun-2016  mlelstv initialize before check.
 1.16 05-Jun-2016  mlelstv ensure that timeout counter is cleared when ccb is (re-)used.
 1.15 05-Jun-2016  mlelstv Replace the simple tag counter with the command tag coming down from scsipi.
Also set attributes according to tag types.
 1.14 05-Jun-2016  mlelstv Fix locking for pdu flags here, in particular PDUF_INQUEUE.
 1.13 05-Jun-2016  mlelstv When stopping a callout, wait until the cleanup thread has processed them.
 1.12 05-Jun-2016  mlelstv More debugging output, changed debug levels for some.
 1.11 01-Jun-2016  mlelstv refactor callouts
remove timed out ccbs and connections from cleanup queue when stopping timeout.
 1.10 01-Jun-2016  mlelstv factor out sernum handling.
make incrementing sernum atomic.
declare variables for atomic operations as volatile.
 1.9 29-May-2016  mlelstv Several improvements to the ISCSI driver.

- Enable debug messages but set log level to be quiet. Provide a
system (hw.iscsi.debug) to set the log level at run time.
- Replace old tsleep/wakeup synchronization with mutexes and condvars.
- Defer actions from callouts (basically timeouts) to the cleanup thread.
- Protect lists and unique ids with mutexes. protect connection usecount
by using atomic operations.
- Assert kernel lock when calling into scsipi and network code.
- Use this to make send/receive/cleanup threads MPSAFE.

- Fix handling of out-of-CCB/out-of-PDU conditions against the scsipi layer.
- Bump number of PDUs to 128 to avoid virtually all out-of-PDU conditions

- Make use of softc structure for attach/detach operations.
- Track open file handles to prevent detach when busy.

- Move some global variables to make them static.

- Fix 'Overlapping Commands Attempted' error by marking commands as
simply ordered (ATTR_SIMPLE) like FreeBSD.
 1.8 30-May-2015  joerg Save space by making ack flag booleans.
 1.7 30-May-2015  joerg Remove ISCSI_PERFTEST.
 1.6 15-May-2015  joerg Remove conditionals for NetBSD before 4.0.
 1.5 29-Dec-2012  mlelstv branches: 1.5.14;
- defer session cleanup to not force detachments
- use more and explicit locking
- improve connection recovery
- use larger timeouts
- handle ccb buffer underflow correctly
- simplify throttling code

Sessions can now temporarily exist without a valid
connection, you also need to update iscsid(8).
 1.4 25-Jun-2012  mlelstv branches: 1.4.2;
Make digests work also on big endian machines.
 1.3 24-Jun-2012  mlelstv Add more debugging, fix filehandle usage, login negotiation and session
shutdown.
Add #ifdef'd code to send negotiation parameters in hex instead of base64,
so it works against older Linux targets.
 1.2 09-Jun-2012  mlelstv Close file descriptor passed into the kernel on success.
Fix locking of file handle. More cleanup on error paths.
Keep track of CCBs, so they cannot be used after a session ends.
Handle CCB timeouts even when the connection is terminated.
Compute firstdata, firstimmed correctly.
 1.1 23-Oct-2011  agc branches: 1.1.2; 1.1.8;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/sys/dev/iscsi

to

src/sys/dev/iscsi
 1.1.8.1 03-Jul-2012  jdc Pull up revisions:
src/sys/dev/iscsi/iscsi_globals.h revisions 1.3,1.4
src/sys/dev/iscsi/iscsi_main.c revisions 1.4,1.5
src/sys/dev/iscsi/iscsi_text.c revisions 1.4,1.5
src/sys/dev/iscsi/iscsi_ioctl.c revisions 1.3,1.4
src/sys/dev/iscsi/iscsi_send.c revisions 1.3,1.4,1.5
src/sys/dev/iscsi/iscsi_utils.c revisions 1.2,1.3,1.4
src/sbin/iscsid/iscsid_discover.c revision 1.4
src/sys/dev/iscsi/iscsi_rcv.c revision 1.3
src/sbin/iscsictl/iscsic_driverif.c revisions 1.5,1.6
(requested by martin in ticket #357, with updates from mhitch and mlelstv).

avoid namespace pollution when debugging
don't panic when printing data for a dead (NULL) connection

Close file descriptor passed into the kernel on success.
Fix locking of file handle. More cleanup on error paths.
Keep track of CCBs, so they cannot be used after a session ends.
Handle CCB timeouts even when the connection is terminated.
Compute firstdata, firstimmed correctly.

assemble_login_parameters() has a strange error reporting convention:
errors are positive numbers, so <= 0 is good, not >= ...
This makes CHAP authenticated iscsi logins work.

use first successful connection to a ISNS server

Add more debugging, fix filehandle usage, login negotiation and session
shutdown.
Add #ifdef'd code to send negotiation parameters in hex instead of base64,
so it works against older Linux targets.

report luns returns a 32bit list length.

Make digests work also on big endian machines.

it's really 32bit
 1.1.2.2 23-Jan-2013  yamt sync with head
 1.1.2.1 30-Oct-2012  yamt sync with head
 1.4.2.2 03-Dec-2017  jdolecek update from HEAD
 1.4.2.1 25-Feb-2013  tls resync with head
 1.5.14.4 28-Aug-2017  skrll Sync with HEAD
 1.5.14.3 05-Feb-2017  skrll Sync with HEAD
 1.5.14.2 09-Jul-2016  skrll Sync with HEAD
 1.5.14.1 06-Jun-2015  skrll Sync with HEAD
 1.21.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.21.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.22.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.24.4.1 10-Jun-2019  christos Sync with HEAD
 1.28.4.1 18-Dec-2023  martin Pull up following revision(s) (requested by mlelstv in ticket #505):

sys/dev/iscsi/iscsi_utils.c: revision 1.29
sys/dev/iscsi/iscsi.h: revision 1.5
sys/dev/iscsi/iscsi_ioctl.c: revision 1.34
sys/dev/iscsi/iscsi_globals.h: revision 1.28
sys/dev/iscsi/iscsi_text.c: revision 1.14
sys/dev/iscsi/iscsi_send.c: revision 1.40

Adapt to bignum representation of target.

Fix negotiation for mutual authentication.

Prepare for more CHAP types.

Fix crashes for invalid socket descriptors passed to kernel.

Protect usecount with connection mutex, avoids race on connection close.

Minor cosmetics.

RSS XML Feed