[Midnightbsd-cvs] src [10102] trunk/sys/dev: sync with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun May 27 19:40:40 EDT 2018


Revision: 10102
          http://svnweb.midnightbsd.org/src/?rev=10102
Author:   laffer1
Date:     2018-05-27 19:40:39 -0400 (Sun, 27 May 2018)
Log Message:
-----------
sync with freebsd

Modified Paths:
--------------
    trunk/sys/dev/isci/environment.h
    trunk/sys/dev/isci/isci.c
    trunk/sys/dev/isci/isci.h
    trunk/sys/dev/isci/isci_controller.c
    trunk/sys/dev/isci/isci_domain.c
    trunk/sys/dev/isci/isci_interrupt.c
    trunk/sys/dev/isci/isci_io_request.c
    trunk/sys/dev/isci/isci_logger.c
    trunk/sys/dev/isci/isci_oem_parameters.c
    trunk/sys/dev/isci/isci_remote_device.c
    trunk/sys/dev/isci/isci_sysctl.c
    trunk/sys/dev/isci/isci_task_request.c
    trunk/sys/dev/isci/isci_timer.c
    trunk/sys/dev/isci/sci_environment.h
    trunk/sys/dev/isci/scil/intel_ata.h
    trunk/sys/dev/isci/scil/intel_pci.h
    trunk/sys/dev/isci/scil/intel_sas.h
    trunk/sys/dev/isci/scil/intel_sat.h
    trunk/sys/dev/isci/scil/intel_sata.h
    trunk/sys/dev/isci/scil/intel_scsi.h
    trunk/sys/dev/isci/scil/sati.c
    trunk/sys/dev/isci/scil/sati.h
    trunk/sys/dev/isci/scil/sati_abort_task_set.c
    trunk/sys/dev/isci/scil/sati_abort_task_set.h
    trunk/sys/dev/isci/scil/sati_atapi.c
    trunk/sys/dev/isci/scil/sati_atapi.h
    trunk/sys/dev/isci/scil/sati_callbacks.h
    trunk/sys/dev/isci/scil/sati_design.h
    trunk/sys/dev/isci/scil/sati_device.c
    trunk/sys/dev/isci/scil/sati_device.h
    trunk/sys/dev/isci/scil/sati_inquiry.c
    trunk/sys/dev/isci/scil/sati_inquiry.h
    trunk/sys/dev/isci/scil/sati_log_sense.c
    trunk/sys/dev/isci/scil/sati_log_sense.h
    trunk/sys/dev/isci/scil/sati_lun_reset.c
    trunk/sys/dev/isci/scil/sati_lun_reset.h
    trunk/sys/dev/isci/scil/sati_mode_pages.c
    trunk/sys/dev/isci/scil/sati_mode_pages.h
    trunk/sys/dev/isci/scil/sati_mode_select.c
    trunk/sys/dev/isci/scil/sati_mode_select.h
    trunk/sys/dev/isci/scil/sati_mode_sense.c
    trunk/sys/dev/isci/scil/sati_mode_sense.h
    trunk/sys/dev/isci/scil/sati_mode_sense_10.c
    trunk/sys/dev/isci/scil/sati_mode_sense_10.h
    trunk/sys/dev/isci/scil/sati_mode_sense_6.c
    trunk/sys/dev/isci/scil/sati_mode_sense_6.h
    trunk/sys/dev/isci/scil/sati_move.c
    trunk/sys/dev/isci/scil/sati_move.h
    trunk/sys/dev/isci/scil/sati_passthrough.c
    trunk/sys/dev/isci/scil/sati_passthrough.h
    trunk/sys/dev/isci/scil/sati_read.c
    trunk/sys/dev/isci/scil/sati_read.h
    trunk/sys/dev/isci/scil/sati_read_buffer.c
    trunk/sys/dev/isci/scil/sati_read_buffer.h
    trunk/sys/dev/isci/scil/sati_read_capacity.c
    trunk/sys/dev/isci/scil/sati_read_capacity.h
    trunk/sys/dev/isci/scil/sati_reassign_blocks.c
    trunk/sys/dev/isci/scil/sati_reassign_blocks.h
    trunk/sys/dev/isci/scil/sati_report_luns.c
    trunk/sys/dev/isci/scil/sati_report_luns.h
    trunk/sys/dev/isci/scil/sati_request_sense.c
    trunk/sys/dev/isci/scil/sati_request_sense.h
    trunk/sys/dev/isci/scil/sati_start_stop_unit.c
    trunk/sys/dev/isci/scil/sati_start_stop_unit.h
    trunk/sys/dev/isci/scil/sati_synchronize_cache.c
    trunk/sys/dev/isci/scil/sati_synchronize_cache.h
    trunk/sys/dev/isci/scil/sati_test_unit_ready.c
    trunk/sys/dev/isci/scil/sati_test_unit_ready.h
    trunk/sys/dev/isci/scil/sati_translator_sequence.h
    trunk/sys/dev/isci/scil/sati_types.h
    trunk/sys/dev/isci/scil/sati_unmap.c
    trunk/sys/dev/isci/scil/sati_unmap.h
    trunk/sys/dev/isci/scil/sati_util.c
    trunk/sys/dev/isci/scil/sati_util.h
    trunk/sys/dev/isci/scil/sati_verify.c
    trunk/sys/dev/isci/scil/sati_verify.h
    trunk/sys/dev/isci/scil/sati_write.c
    trunk/sys/dev/isci/scil/sati_write.h
    trunk/sys/dev/isci/scil/sati_write_and_verify.c
    trunk/sys/dev/isci/scil/sati_write_and_verify.h
    trunk/sys/dev/isci/scil/sati_write_buffer.c
    trunk/sys/dev/isci/scil/sati_write_buffer.h
    trunk/sys/dev/isci/scil/sati_write_long.c
    trunk/sys/dev/isci/scil/sati_write_long.h
    trunk/sys/dev/isci/scil/sci_abstract_list.c
    trunk/sys/dev/isci/scil/sci_abstract_list.h
    trunk/sys/dev/isci/scil/sci_base_controller.c
    trunk/sys/dev/isci/scil/sci_base_controller.h
    trunk/sys/dev/isci/scil/sci_base_domain.c
    trunk/sys/dev/isci/scil/sci_base_domain.h
    trunk/sys/dev/isci/scil/sci_base_iterator.c
    trunk/sys/dev/isci/scil/sci_base_iterator.h
    trunk/sys/dev/isci/scil/sci_base_library.c
    trunk/sys/dev/isci/scil/sci_base_library.h
    trunk/sys/dev/isci/scil/sci_base_logger.c
    trunk/sys/dev/isci/scil/sci_base_logger.h
    trunk/sys/dev/isci/scil/sci_base_memory_descriptor_list.c
    trunk/sys/dev/isci/scil/sci_base_memory_descriptor_list.h
    trunk/sys/dev/isci/scil/sci_base_memory_descriptor_list_decorator.c
    trunk/sys/dev/isci/scil/sci_base_object.c
    trunk/sys/dev/isci/scil/sci_base_object.h
    trunk/sys/dev/isci/scil/sci_base_observer.c
    trunk/sys/dev/isci/scil/sci_base_observer.h
    trunk/sys/dev/isci/scil/sci_base_phy.c
    trunk/sys/dev/isci/scil/sci_base_phy.h
    trunk/sys/dev/isci/scil/sci_base_port.c
    trunk/sys/dev/isci/scil/sci_base_port.h
    trunk/sys/dev/isci/scil/sci_base_remote_device.c
    trunk/sys/dev/isci/scil/sci_base_remote_device.h
    trunk/sys/dev/isci/scil/sci_base_request.c
    trunk/sys/dev/isci/scil/sci_base_request.h
    trunk/sys/dev/isci/scil/sci_base_state.h
    trunk/sys/dev/isci/scil/sci_base_state_machine.c
    trunk/sys/dev/isci/scil/sci_base_state_machine.h
    trunk/sys/dev/isci/scil/sci_base_state_machine_logger.c
    trunk/sys/dev/isci/scil/sci_base_state_machine_logger.h
    trunk/sys/dev/isci/scil/sci_base_state_machine_observer.c
    trunk/sys/dev/isci/scil/sci_base_state_machine_observer.h
    trunk/sys/dev/isci/scil/sci_base_subject.c
    trunk/sys/dev/isci/scil/sci_base_subject.h
    trunk/sys/dev/isci/scil/sci_controller.h
    trunk/sys/dev/isci/scil/sci_controller_constants.h
    trunk/sys/dev/isci/scil/sci_fast_list.h
    trunk/sys/dev/isci/scil/sci_iterator.h
    trunk/sys/dev/isci/scil/sci_library.h
    trunk/sys/dev/isci/scil/sci_logger.h
    trunk/sys/dev/isci/scil/sci_memory_descriptor_list.h
    trunk/sys/dev/isci/scil/sci_memory_descriptor_list_decorator.h
    trunk/sys/dev/isci/scil/sci_object.h
    trunk/sys/dev/isci/scil/sci_overview.h
    trunk/sys/dev/isci/scil/sci_pool.h
    trunk/sys/dev/isci/scil/sci_simple_list.h
    trunk/sys/dev/isci/scil/sci_status.h
    trunk/sys/dev/isci/scil/sci_types.h
    trunk/sys/dev/isci/scil/sci_util.c
    trunk/sys/dev/isci/scil/sci_util.h
    trunk/sys/dev/isci/scil/scic_config_parameters.h
    trunk/sys/dev/isci/scil/scic_controller.h
    trunk/sys/dev/isci/scil/scic_io_request.h
    trunk/sys/dev/isci/scil/scic_library.h
    trunk/sys/dev/isci/scil/scic_logger.h
    trunk/sys/dev/isci/scil/scic_overview.h
    trunk/sys/dev/isci/scil/scic_phy.h
    trunk/sys/dev/isci/scil/scic_port.h
    trunk/sys/dev/isci/scil/scic_remote_device.h
    trunk/sys/dev/isci/scil/scic_sds_controller.c
    trunk/sys/dev/isci/scil/scic_sds_controller.h
    trunk/sys/dev/isci/scil/scic_sds_controller_registers.h
    trunk/sys/dev/isci/scil/scic_sds_library.c
    trunk/sys/dev/isci/scil/scic_sds_library.h
    trunk/sys/dev/isci/scil/scic_sds_logger.h
    trunk/sys/dev/isci/scil/scic_sds_pci.c
    trunk/sys/dev/isci/scil/scic_sds_pci.h
    trunk/sys/dev/isci/scil/scic_sds_phy.c
    trunk/sys/dev/isci/scil/scic_sds_phy.h
    trunk/sys/dev/isci/scil/scic_sds_phy_registers.h
    trunk/sys/dev/isci/scil/scic_sds_port.c
    trunk/sys/dev/isci/scil/scic_sds_port.h
    trunk/sys/dev/isci/scil/scic_sds_port_configuration_agent.c
    trunk/sys/dev/isci/scil/scic_sds_port_configuration_agent.h
    trunk/sys/dev/isci/scil/scic_sds_port_registers.h
    trunk/sys/dev/isci/scil/scic_sds_remote_device.c
    trunk/sys/dev/isci/scil/scic_sds_remote_device.h
    trunk/sys/dev/isci/scil/scic_sds_remote_node_context.c
    trunk/sys/dev/isci/scil/scic_sds_remote_node_context.h
    trunk/sys/dev/isci/scil/scic_sds_remote_node_table.c
    trunk/sys/dev/isci/scil/scic_sds_remote_node_table.h
    trunk/sys/dev/isci/scil/scic_sds_request.c
    trunk/sys/dev/isci/scil/scic_sds_request.h
    trunk/sys/dev/isci/scil/scic_sds_sgpio.c
    trunk/sys/dev/isci/scil/scic_sds_smp_remote_device.c
    trunk/sys/dev/isci/scil/scic_sds_smp_request.c
    trunk/sys/dev/isci/scil/scic_sds_smp_request.h
    trunk/sys/dev/isci/scil/scic_sds_ssp_request.c
    trunk/sys/dev/isci/scil/scic_sds_stp_packet_request.c
    trunk/sys/dev/isci/scil/scic_sds_stp_packet_request.h
    trunk/sys/dev/isci/scil/scic_sds_stp_pio_request.h
    trunk/sys/dev/isci/scil/scic_sds_stp_remote_device.c
    trunk/sys/dev/isci/scil/scic_sds_stp_request.c
    trunk/sys/dev/isci/scil/scic_sds_stp_request.h
    trunk/sys/dev/isci/scil/scic_sds_unsolicited_frame_control.c
    trunk/sys/dev/isci/scil/scic_sds_unsolicited_frame_control.h
    trunk/sys/dev/isci/scil/scic_sgpio.h
    trunk/sys/dev/isci/scil/scic_task_request.h
    trunk/sys/dev/isci/scil/scic_user_callback.h
    trunk/sys/dev/isci/scil/scif_config_parameters.h
    trunk/sys/dev/isci/scil/scif_controller.h
    trunk/sys/dev/isci/scil/scif_domain.h
    trunk/sys/dev/isci/scil/scif_io_request.h
    trunk/sys/dev/isci/scil/scif_library.h
    trunk/sys/dev/isci/scil/scif_logger.h
    trunk/sys/dev/isci/scil/scif_overview.h
    trunk/sys/dev/isci/scil/scif_remote_device.h
    trunk/sys/dev/isci/scil/scif_sas_constants.h
    trunk/sys/dev/isci/scil/scif_sas_controller.c
    trunk/sys/dev/isci/scil/scif_sas_controller.h
    trunk/sys/dev/isci/scil/scif_sas_controller_state_handlers.c
    trunk/sys/dev/isci/scil/scif_sas_controller_states.c
    trunk/sys/dev/isci/scil/scif_sas_design.h
    trunk/sys/dev/isci/scil/scif_sas_domain.c
    trunk/sys/dev/isci/scil/scif_sas_domain.h
    trunk/sys/dev/isci/scil/scif_sas_domain_state_handlers.c
    trunk/sys/dev/isci/scil/scif_sas_domain_states.c
    trunk/sys/dev/isci/scil/scif_sas_high_priority_request_queue.c
    trunk/sys/dev/isci/scil/scif_sas_high_priority_request_queue.h
    trunk/sys/dev/isci/scil/scif_sas_internal_io_request.c
    trunk/sys/dev/isci/scil/scif_sas_internal_io_request.h
    trunk/sys/dev/isci/scil/scif_sas_io_request.c
    trunk/sys/dev/isci/scil/scif_sas_io_request.h
    trunk/sys/dev/isci/scil/scif_sas_io_request_state_handlers.c
    trunk/sys/dev/isci/scil/scif_sas_io_request_states.c
    trunk/sys/dev/isci/scil/scif_sas_library.c
    trunk/sys/dev/isci/scil/scif_sas_library.h
    trunk/sys/dev/isci/scil/scif_sas_logger.h
    trunk/sys/dev/isci/scil/scif_sas_remote_device.c
    trunk/sys/dev/isci/scil/scif_sas_remote_device.h
    trunk/sys/dev/isci/scil/scif_sas_remote_device_ready_substate_handlers.c
    trunk/sys/dev/isci/scil/scif_sas_remote_device_ready_substates.c
    trunk/sys/dev/isci/scil/scif_sas_remote_device_starting_substate_handlers.c
    trunk/sys/dev/isci/scil/scif_sas_remote_device_starting_substates.c
    trunk/sys/dev/isci/scil/scif_sas_remote_device_state_handlers.c
    trunk/sys/dev/isci/scil/scif_sas_remote_device_states.c
    trunk/sys/dev/isci/scil/scif_sas_request.c
    trunk/sys/dev/isci/scil/scif_sas_request.h
    trunk/sys/dev/isci/scil/scif_sas_sati_binding.h
    trunk/sys/dev/isci/scil/scif_sas_smp_activity_clear_affiliation.c
    trunk/sys/dev/isci/scil/scif_sas_smp_io_request.c
    trunk/sys/dev/isci/scil/scif_sas_smp_io_request.h
    trunk/sys/dev/isci/scil/scif_sas_smp_phy.c
    trunk/sys/dev/isci/scil/scif_sas_smp_phy.h
    trunk/sys/dev/isci/scil/scif_sas_smp_remote_device.c
    trunk/sys/dev/isci/scil/scif_sas_smp_remote_device.h
    trunk/sys/dev/isci/scil/scif_sas_stp_io_request.c
    trunk/sys/dev/isci/scil/scif_sas_stp_io_request.h
    trunk/sys/dev/isci/scil/scif_sas_stp_remote_device.c
    trunk/sys/dev/isci/scil/scif_sas_stp_remote_device.h
    trunk/sys/dev/isci/scil/scif_sas_stp_task_request.c
    trunk/sys/dev/isci/scil/scif_sas_stp_task_request.h
    trunk/sys/dev/isci/scil/scif_sas_task_request.c
    trunk/sys/dev/isci/scil/scif_sas_task_request.h
    trunk/sys/dev/isci/scil/scif_sas_task_request_state_handlers.c
    trunk/sys/dev/isci/scil/scif_sas_task_request_states.c
    trunk/sys/dev/isci/scil/scif_sas_timer.c
    trunk/sys/dev/isci/scil/scif_task_request.h
    trunk/sys/dev/isci/scil/scif_user_callback.h
    trunk/sys/dev/isci/scil/scu_bios_definitions.h
    trunk/sys/dev/isci/scil/scu_completion_codes.h
    trunk/sys/dev/isci/scil/scu_constants.h
    trunk/sys/dev/isci/scil/scu_event_codes.h
    trunk/sys/dev/isci/scil/scu_registers.h
    trunk/sys/dev/isci/scil/scu_remote_node_context.h
    trunk/sys/dev/isci/scil/scu_task_context.h
    trunk/sys/dev/isci/scil/scu_unsolicited_frame.h
    trunk/sys/dev/isci/scil/scu_viit_data.h
    trunk/sys/dev/isci/types.h
    trunk/sys/dev/iwi/if_iwi.c
    trunk/sys/dev/iwi/if_iwireg.h
    trunk/sys/dev/iwi/if_iwivar.h

Added Paths:
-----------
    trunk/sys/dev/iscsi/icl.c
    trunk/sys/dev/iscsi/icl.h
    trunk/sys/dev/iscsi/icl_proxy.c
    trunk/sys/dev/iscsi/iscsi.c
    trunk/sys/dev/iscsi/iscsi.h
    trunk/sys/dev/iscsi/iscsi_ioctl.h
    trunk/sys/dev/iscsi/iscsi_proto.h
    trunk/sys/dev/iscsi_initiator/
    trunk/sys/dev/iscsi_initiator/isc_cam.c
    trunk/sys/dev/iscsi_initiator/isc_sm.c
    trunk/sys/dev/iscsi_initiator/isc_soc.c
    trunk/sys/dev/iscsi_initiator/isc_subr.c
    trunk/sys/dev/iscsi_initiator/iscsi.c
    trunk/sys/dev/iscsi_initiator/iscsi.h
    trunk/sys/dev/iscsi_initiator/iscsi_subr.c
    trunk/sys/dev/iscsi_initiator/iscsivar.h

Modified: trunk/sys/dev/isci/environment.h
===================================================================
--- trunk/sys/dev/isci/environment.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/environment.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * BSD LICENSE
  *
@@ -27,7 +28,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/environment.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 
 #ifndef ENVIRONMENT_H_

Modified: trunk/sys/dev/isci/isci.c
===================================================================
--- trunk/sys/dev/isci/isci.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/isci.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * BSD LICENSE
  *
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/isci.c 287677 2015-09-11 17:01:01Z jimharris $");
 
 #include <dev/isci/isci.h>
 
@@ -38,11 +39,14 @@
 
 #include <cam/cam_periph.h>
 
+#include <dev/led/led.h>
+
 #include <dev/pci/pcireg.h>
 #include <dev/pci/pcivar.h>
 
 #include <dev/isci/scil/scic_logger.h>
 #include <dev/isci/scil/scic_library.h>
+#include <dev/isci/scil/scic_sgpio.h>
 #include <dev/isci/scil/scic_user_callback.h>
 
 #include <dev/isci/scil/scif_controller.h>
@@ -81,6 +85,7 @@
 };
 
 DRIVER_MODULE(isci, pci, isci_pci_driver, isci_devclass, 0, 0);
+MODULE_DEPEND(isci, cam, 1, 1, 1);
 
 static struct _pcsid
 {
@@ -159,6 +164,7 @@
 
 	g_isci = isci;
 	isci->device = device;
+	pci_enable_busmaster(device);
 
 	isci_allocate_pci_memory(isci);
 
@@ -180,7 +186,7 @@
 isci_detach(device_t device)
 {
 	struct isci_softc *isci = DEVICE2SOFTC(device);
-	int i;
+	int i, phy;
 
 	for (i = 0; i < isci->controller_count; i++) {
 		struct ISCI_CONTROLLER *controller = &isci->controllers[i];
@@ -220,6 +226,14 @@
 		if (controller->remote_device_memory != NULL)
 			free(controller->remote_device_memory, M_ISCI);
 
+		for (phy = 0; phy < SCI_MAX_PHYS; phy++) {
+			if (controller->phys[phy].cdev_fault)
+				led_destroy(controller->phys[phy].cdev_fault);
+
+			if (controller->phys[phy].cdev_locate)
+				led_destroy(controller->phys[phy].cdev_locate);
+		}
+
 		while (1) {
 			sci_pool_get(controller->unmap_buffer_pool, unmap_buffer);
 			if (unmap_buffer == NULL)
@@ -260,6 +274,7 @@
 
 		pci_release_msi(device);
 	}
+	pci_disable_busmaster(device);
 
 	return (0);
 }

Modified: trunk/sys/dev/isci/isci.h
===================================================================
--- trunk/sys/dev/isci/isci.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/isci.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * BSD LICENSE
  *
@@ -27,7 +28,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/isci.h 268073 2014-07-01 06:23:48Z scottl $
  */
 
 #ifndef _ISCI_H
@@ -143,6 +144,16 @@
 
 };
 
+struct ISCI_PHY
+{
+	struct cdev		*cdev_fault;
+	struct cdev		*cdev_locate;
+	SCI_CONTROLLER_HANDLE_T	handle;
+	int			index;
+	int			led_fault;
+	int			led_locate;
+};
+
 struct ISCI_CONTROLLER
 {
 	struct isci_softc 	*isci;
@@ -154,6 +165,7 @@
 	uint32_t		initial_discovery_mask;
 	BOOL			is_frozen;
 	BOOL			release_queued_ccbs;
+	BOOL			fail_on_task_timeout;
 	uint8_t			*remote_device_memory;
 	struct ISCI_MEMORY	cached_controller_memory;
 	struct ISCI_MEMORY	uncached_controller_memory;
@@ -169,6 +181,7 @@
 	uint32_t		queue_depth;
 	uint32_t		sim_queue_depth;
 	SCI_FAST_LIST_T		pending_device_reset_list;
+	struct ISCI_PHY		phys[SCI_MAX_PHYS];
 
 	SCI_MEMORY_DESCRIPTOR_LIST_HANDLE_T mdl;
 

Modified: trunk/sys/dev/isci/isci_controller.c
===================================================================
--- trunk/sys/dev/isci/isci_controller.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/isci_controller.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * BSD LICENSE
  *
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/isci_controller.c 315813 2017-03-23 06:41:13Z mav $");
 
 #include <dev/isci/isci.h>
 
@@ -49,7 +50,10 @@
 #include <dev/isci/scil/scif_remote_device.h>
 #include <dev/isci/scil/scif_domain.h>
 #include <dev/isci/scil/scif_user_callback.h>
+#include <dev/isci/scil/scic_sgpio.h>
 
+#include <dev/led/led.h>
+
 void isci_action(struct cam_sim *sim, union ccb *ccb);
 void isci_poll(struct cam_sim *sim);
 
@@ -271,11 +275,34 @@
 	sci_pool_initialize(controller->unmap_buffer_pool);
 }
 
+static void isci_led_fault_func(void *priv, int onoff)
+{
+	struct ISCI_PHY *phy = priv;
+
+	/* map onoff to the fault LED */
+	phy->led_fault = onoff;
+	scic_sgpio_update_led_state(phy->handle, 1 << phy->index, 
+		phy->led_fault, phy->led_locate, 0);
+}
+
+static void isci_led_locate_func(void *priv, int onoff)
+{
+	struct ISCI_PHY *phy = priv;
+
+	/* map onoff to the locate LED */
+	phy->led_locate = onoff;
+	scic_sgpio_update_led_state(phy->handle, 1 << phy->index, 
+		phy->led_fault, phy->led_locate, 0);
+}
+
 SCI_STATUS isci_controller_initialize(struct ISCI_CONTROLLER *controller)
 {
 	SCIC_USER_PARAMETERS_T scic_user_parameters;
 	SCI_CONTROLLER_HANDLE_T scic_controller_handle;
+	char led_name[64];
 	unsigned long tunable;
+	uint32_t io_shortage;
+	uint32_t fail_on_timeout;
 	int i;
 
 	scic_controller_handle =
@@ -341,10 +368,14 @@
 	 *  this io_shortage parameter, which will tell CAM that we have a
 	 *  large queue depth than we really do.
 	 */
-	uint32_t io_shortage = 0;
+	io_shortage = 0;
 	TUNABLE_INT_FETCH("hw.isci.io_shortage", &io_shortage);
 	controller->sim_queue_depth += io_shortage;
 
+	fail_on_timeout = 1;
+	TUNABLE_INT_FETCH("hw.isci.fail_on_task_timeout", &fail_on_timeout);
+	controller->fail_on_task_timeout = fail_on_timeout;
+
 	/* Attach to CAM using xpt_bus_register now, then immediately freeze
 	 *  the simq.  It will get released later when initial domain discovery
 	 *  is complete.
@@ -355,6 +386,23 @@
 	xpt_freeze_simq(controller->sim, 1);
 	mtx_unlock(&controller->lock);
 
+	for (i = 0; i < SCI_MAX_PHYS; i++) {
+		controller->phys[i].handle = scic_controller_handle;
+		controller->phys[i].index = i;
+
+		/* fault */
+		controller->phys[i].led_fault = 0;
+		sprintf(led_name, "isci.bus%d.port%d.fault", controller->index, i);
+		controller->phys[i].cdev_fault = led_create(isci_led_fault_func,
+		    &controller->phys[i], led_name);
+			
+		/* locate */
+		controller->phys[i].led_locate = 0;
+		sprintf(led_name, "isci.bus%d.port%d.locate", controller->index, i);
+		controller->phys[i].cdev_locate = led_create(isci_led_locate_func,
+		    &controller->phys[i], led_name);
+	}
+
 	return (scif_controller_initialize(controller->scif_controller_handle));
 }
 
@@ -539,7 +587,7 @@
 			 */
 			union ccb *ccb = xpt_alloc_ccb_nowait();
 
-			xpt_create_path(&ccb->ccb_h.path, xpt_periph,
+			xpt_create_path(&ccb->ccb_h.path, NULL,
 			    cam_sim_path(isci_controller->sim),
 			    CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
 
@@ -632,7 +680,8 @@
 			cpi->version_num = 1;
 			cpi->hba_inquiry = PI_TAG_ABLE;
 			cpi->target_sprt = 0;
-			cpi->hba_misc = PIM_NOBUSRESET | PIM_SEQSCAN;
+			cpi->hba_misc = PIM_NOBUSRESET | PIM_SEQSCAN |
+			    PIM_UNMAPPED;
 			cpi->hba_eng_cnt = 0;
 			cpi->max_target = SCI_MAX_REMOTE_DEVICES - 1;
 			cpi->max_lun = ISCI_MAX_LUN;
@@ -643,9 +692,9 @@
 			cpi->bus_id = bus;
 			cpi->initiator_id = SCI_MAX_REMOTE_DEVICES;
 			cpi->base_transfer_speed = 300000;
-			strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
-			strncpy(cpi->hba_vid, "Intel Corp.", HBA_IDLEN);
-			strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
+			strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
+			strlcpy(cpi->hba_vid, "Intel Corp.", HBA_IDLEN);
+			strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
 			cpi->transport = XPORT_SAS;
 			cpi->transport_version = 0;
 			cpi->protocol = PROTO_SCSI;
@@ -692,6 +741,11 @@
 		}
 		break;
 	case XPT_SCSI_IO:
+		if (ccb->ccb_h.flags & CAM_CDB_PHYS) {
+			ccb->ccb_h.status = CAM_REQ_INVALID;
+			xpt_done(ccb);
+			break;
+		}
 		isci_io_request_execute_scsi_io(ccb, controller);
 		break;
 #if __FreeBSD_version >= 900026
@@ -754,6 +808,7 @@
 {
 	struct ISCI_REMOTE_DEVICE *dev;
 	struct ccb_hdr *ccb_h;
+	uint8_t *ptr;
 	int dev_idx;
 
 	KASSERT(mtx_owned(&controller->lock), ("controller lock not owned"));
@@ -773,8 +828,8 @@
 			if (ccb_h == NULL)
 				continue;
 
-			isci_log_message(1, "ISCI", "release %p %x\n", ccb_h,
-			    ((union ccb *)ccb_h)->csio.cdb_io.cdb_bytes[0]);
+			ptr = scsiio_cdb_ptr(&((union ccb *)ccb_h)->csio);
+			isci_log_message(1, "ISCI", "release %p %x\n", ccb_h, *ptr);
 
 			dev->queued_ccb_in_progress = (union ccb *)ccb_h;
 			isci_io_request_execute_scsi_io(

Modified: trunk/sys/dev/isci/isci_domain.c
===================================================================
--- trunk/sys/dev/isci/isci_domain.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/isci_domain.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * BSD LICENSE
  *
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/isci_domain.c 249468 2013-04-14 09:55:48Z mav $");
 
 #include <dev/isci/isci.h>
 
@@ -300,7 +301,7 @@
 
 	isci_controller->remote_device[isci_remote_device->index] = NULL;
 
-	xpt_create_path(&ccb->ccb_h.path, xpt_periph, path,
+	xpt_create_path(&ccb->ccb_h.path, NULL, path,
 	    isci_remote_device->index, CAM_LUN_WILDCARD);
 
 	xpt_rescan(ccb);

Modified: trunk/sys/dev/isci/isci_interrupt.c
===================================================================
--- trunk/sys/dev/isci/isci_interrupt.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/isci_interrupt.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * BSD LICENSE
  *
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/isci_interrupt.c 287678 2015-09-11 17:06:57Z jimharris $");
 
 #include <dev/isci/isci.h>
 
@@ -136,8 +137,8 @@
 	    pci_msix_count(isci->device) >= max_msix_messages) {
 
 		isci->num_interrupts = max_msix_messages;
-		pci_alloc_msix(isci->device, &isci->num_interrupts);
-		if (isci->num_interrupts == max_msix_messages)
+		if (pci_alloc_msix(isci->device, &isci->num_interrupts) == 0 &&
+		    isci->num_interrupts == max_msix_messages)
 			use_msix = TRUE;
 	}
 

Modified: trunk/sys/dev/isci/isci_io_request.c
===================================================================
--- trunk/sys/dev/isci/isci_io_request.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/isci_io_request.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * BSD LICENSE
  *
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/isci_io_request.c 314667 2017-03-04 13:03:31Z avg $");
 
 #include <dev/isci/isci.h>
 
@@ -86,6 +87,7 @@
 	struct ISCI_REMOTE_DEVICE *isci_remote_device;
 	union ccb *ccb;
 	BOOL complete_ccb;
+	struct ccb_scsiio *csio;
 
 	complete_ccb = TRUE;
 	isci_controller = (struct ISCI_CONTROLLER *) sci_object_get_association(scif_controller);
@@ -93,7 +95,7 @@
 		(struct ISCI_REMOTE_DEVICE *) sci_object_get_association(remote_device);
 
 	ccb = isci_request->ccb;
-
+	csio = &ccb->csio;
 	ccb->ccb_h.status &= ~CAM_STATUS_MASK;
 
 	switch (completion_status) {
@@ -124,7 +126,6 @@
 		SCI_SSP_RESPONSE_IU_T * response_buffer;
 		uint32_t sense_length;
 		int error_code, sense_key, asc, ascq;
-		struct ccb_scsiio *csio = &ccb->csio;
 
 		response_buffer = (SCI_SSP_RESPONSE_IU_T *)
 		    scif_io_request_get_response_iu_address(
@@ -146,7 +147,7 @@
 		isci_log_message(1, "ISCI",
 		    "isci: bus=%x target=%x lun=%x cdb[0]=%x status=%x key=%x asc=%x ascq=%x\n",
 		    ccb->ccb_h.path_id, ccb->ccb_h.target_id,
-		    ccb->ccb_h.target_lun, csio->cdb_io.cdb_bytes[0],
+		    ccb->ccb_h.target_lun, scsiio_cdb_ptr(csio),
 		    csio->scsi_status, sense_key, asc, ascq);
 		break;
 	}
@@ -153,14 +154,19 @@
 
 	case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED:
 		isci_remote_device_reset(isci_remote_device, NULL);
+		ccb->ccb_h.status |= CAM_REQ_TERMIO;
+		isci_log_message(0, "ISCI",
+		    "isci: bus=%x target=%x lun=%x cdb[0]=%x remote device reset required\n",
+		    ccb->ccb_h.path_id, ccb->ccb_h.target_id,
+		    ccb->ccb_h.target_lun, scsiio_cdb_ptr(csio));
+		break;
 
-		/* drop through */
 	case SCI_IO_FAILURE_TERMINATED:
 		ccb->ccb_h.status |= CAM_REQ_TERMIO;
-		isci_log_message(1, "ISCI",
+		isci_log_message(0, "ISCI",
 		    "isci: bus=%x target=%x lun=%x cdb[0]=%x terminated\n",
 		    ccb->ccb_h.path_id, ccb->ccb_h.target_id,
-		    ccb->ccb_h.target_lun, ccb->csio.cdb_io.cdb_bytes[0]);
+		    ccb->ccb_h.target_lun, scsiio_cdb_ptr(csio));
 		break;
 
 	case SCI_IO_FAILURE_INVALID_STATE:
@@ -203,7 +209,7 @@
 		isci_log_message(1, "ISCI",
 		    "isci: bus=%x target=%x lun=%x cdb[0]=%x completion status=%x\n",
 		    ccb->ccb_h.path_id, ccb->ccb_h.target_id,
-		    ccb->ccb_h.target_lun, ccb->csio.cdb_io.cdb_bytes[0],
+		    ccb->ccb_h.target_lun, scsiio_cdb_ptr(csio),
 		    completion_status);
 		ccb->ccb_h.status |= CAM_REQ_CMP_ERR;
 		break;
@@ -280,13 +286,13 @@
 			 *   get a ready notification for this device.
 			 */
 			isci_log_message(1, "ISCI", "already queued %p %x\n",
-			    ccb, ccb->csio.cdb_io.cdb_bytes[0]);
+			    ccb, scsiio_cdb_ptr(csio));
 
 			isci_remote_device->queued_ccb_in_progress = NULL;
 
 		} else {
 			isci_log_message(1, "ISCI", "queue %p %x\n", ccb,
-			    ccb->csio.cdb_io.cdb_bytes[0]);
+			    scsiio_cdb_ptr(csio));
 			ccb->ccb_h.status |= CAM_SIM_QUEUED;
 
 			TAILQ_INSERT_TAIL(&isci_remote_device->queued_ccbs,
@@ -368,7 +374,7 @@
 	struct ISCI_IO_REQUEST *isci_request =
 	    (struct ISCI_IO_REQUEST *)scif_user_io_request;
 
-	return (isci_request->ccb->csio.cdb_io.cdb_bytes);
+	return (scsiio_cdb_ptr(&isci_request->ccb->csio));
 }
 
 /**
@@ -506,10 +512,31 @@
 scif_cb_io_request_get_virtual_address_from_sgl(void * scif_user_io_request,
     uint32_t byte_offset)
 {
-	struct ISCI_IO_REQUEST *isci_request =
-	    (struct ISCI_IO_REQUEST *)scif_user_io_request;
+	struct ISCI_IO_REQUEST	*isci_request;
+	union ccb		*ccb;
 
-	return (isci_request->ccb->csio.data_ptr + byte_offset);
+
+	isci_request = scif_user_io_request;
+	ccb = isci_request->ccb;
+
+	/*
+	 * This callback is only invoked for SCSI/ATA translation of
+	 *  PIO commands such as INQUIRY and READ_CAPACITY, to allow
+	 *  the driver to write the translated data directly into the
+	 *  data buffer.  It is never invoked for READ/WRITE commands.
+	 *  The driver currently assumes only READ/WRITE commands will
+	 *  be unmapped.
+	 *
+	 * As a safeguard against future changes to unmapped commands,
+	 *  add an explicit panic here should the DATA_MASK != VADDR.
+	 *  Otherwise, we would return some garbage pointer back to the
+	 *  caller which would result in a panic or more subtle data
+	 *  corruption later on.
+	 */
+	if ((ccb->ccb_h.flags & CAM_DATA_MASK) != CAM_DATA_VADDR)
+		panic("%s: requesting pointer into unmapped ccb", __func__);
+
+	return (ccb->csio.data_ptr + byte_offset);
 }
 
 /**
@@ -654,7 +681,7 @@
 	request->dma_tag = io_buffer_dma_tag;
 	request->physical_address = physical_address;
 	bus_dmamap_create(request->dma_tag, 0, &request->dma_map);
-	callout_init(&request->timer, CALLOUT_MPSAFE);
+	callout_init(&request->timer, 1);
 }
 
 static void
@@ -705,8 +732,9 @@
 	}
 
 	if (ccb->ccb_h.timeout != CAM_TIME_INFINITY)
-		callout_reset(&io_request->parent.timer, ccb->ccb_h.timeout,
-		    isci_io_request_timeout, io_request);
+		callout_reset_sbt(&io_request->parent.timer,
+		    SBT_1MS * ccb->ccb_h.timeout, 0, isci_io_request_timeout,
+		    io_request, 0);
 }
 
 void
@@ -713,7 +741,6 @@
 isci_io_request_execute_scsi_io(union ccb *ccb,
     struct ISCI_CONTROLLER *controller)
 {
-	struct ccb_scsiio *csio = &ccb->csio;
 	target_id_t target_id = ccb->ccb_h.target_id;
 	struct ISCI_REQUEST *request;
 	struct ISCI_IO_REQUEST *io_request;
@@ -748,29 +775,17 @@
 	io_request->current_sge_index = 0;
 	io_request->parent.remote_device_handle = device->sci_object;
 
-	if ((ccb->ccb_h.flags & CAM_SCATTER_VALID) != 0)
-		panic("Unexpected CAM_SCATTER_VALID flag!  flags = 0x%x\n",
-		    ccb->ccb_h.flags);
-
-	if ((ccb->ccb_h.flags & CAM_DATA_PHYS) != 0)
-		panic("Unexpected CAM_DATA_PHYS flag!  flags = 0x%x\n",
-		    ccb->ccb_h.flags);
-
-	if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
-		error = bus_dmamap_load(io_request->parent.dma_tag,
-		    io_request->parent.dma_map, csio->data_ptr, csio->dxfer_len,
-		    isci_io_request_construct, io_request, 0x0);
-
-		/* A resource shortage from BUSDMA will be automatically
-		 * continued at a later point, pushing the CCB processing
-		 * forward, which will in turn unfreeze the simq.
-		 */
-		if (error == EINPROGRESS) {
-			xpt_freeze_simq(controller->sim, 1);
-			ccb->ccb_h.flags |= CAM_RELEASE_SIMQ;
-		}
-	} else
-		isci_io_request_construct(io_request, NULL, 0, 0);
+	error = bus_dmamap_load_ccb(io_request->parent.dma_tag,
+	    io_request->parent.dma_map, ccb,
+	    isci_io_request_construct, io_request, 0x0);
+	/* A resource shortage from BUSDMA will be automatically
+	 * continued at a later point, pushing the CCB processing
+	 * forward, which will in turn unfreeze the simq.
+	 */
+	if (error == EINPROGRESS) {
+		xpt_freeze_simq(controller->sim, 1);
+		ccb->ccb_h.flags |= CAM_RELEASE_SIMQ;
+	}
 }
 
 void
@@ -970,7 +985,8 @@
 	}
 
 	if (ccb->ccb_h.timeout != CAM_TIME_INFINITY)
-		callout_reset(&io_request->parent.timer, ccb->ccb_h.timeout,
-		    isci_io_request_timeout, request);
+		callout_reset_sbt(&io_request->parent.timer,
+		    SBT_1MS *  ccb->ccb_h.timeout, 0, isci_io_request_timeout,
+		    request, 0);
 }
 #endif

Modified: trunk/sys/dev/isci/isci_logger.c
===================================================================
--- trunk/sys/dev/isci/isci_logger.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/isci_logger.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * BSD LICENSE
  *
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/isci_logger.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 #include <dev/isci/isci.h>
 

Modified: trunk/sys/dev/isci/isci_oem_parameters.c
===================================================================
--- trunk/sys/dev/isci/isci_oem_parameters.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/isci_oem_parameters.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * BSD LICENSE
  *
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/isci_oem_parameters.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 #include <dev/isci/isci.h>
 #include <vm/vm.h>

Modified: trunk/sys/dev/isci/isci_remote_device.c
===================================================================
--- trunk/sys/dev/isci/isci_remote_device.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/isci_remote_device.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * BSD LICENSE
  *
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/isci_remote_device.c 249468 2013-04-14 09:55:48Z mav $");
 
 #include <dev/isci/isci.h>
 
@@ -83,7 +84,7 @@
 			 */
 			union ccb *ccb = xpt_alloc_ccb_nowait();
 
-			xpt_create_path(&ccb->ccb_h.path, xpt_periph,
+			xpt_create_path(&ccb->ccb_h.path, NULL,
 			    cam_sim_path(isci_controller->sim),
 			    isci_remote_device->index, CAM_LUN_WILDCARD);
 
@@ -262,7 +263,7 @@
 	if (!(remote_device->frozen_lun_mask & (1 << lun))) {
 		struct cam_path *path;
 
-		xpt_create_path(&path, xpt_periph,
+		xpt_create_path(&path, NULL,
 		    cam_sim_path(remote_device->domain->controller->sim),
 		    remote_device->index, lun);
 		xpt_freeze_devq(path, 1);
@@ -279,7 +280,7 @@
 		struct cam_path *path;
 
 		remote_device->frozen_lun_mask &= ~(1 << lun);
-		xpt_create_path(&path, xpt_periph,
+		xpt_create_path(&path, NULL,
 		    cam_sim_path(remote_device->domain->controller->sim),
 		    remote_device->index, lun);
 		xpt_release_devq(path, 1, TRUE);

Modified: trunk/sys/dev/isci/isci_sysctl.c
===================================================================
--- trunk/sys/dev/isci/isci_sysctl.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/isci_sysctl.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * BSD LICENSE
  *
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/isci_sysctl.c 276269 2014-12-26 23:18:09Z scottl $");
 
 #include <dev/isci/isci.h>
 
@@ -193,6 +194,54 @@
 	return 0;
 }
 
+static int
+isci_sysctl_log_frozen_lun_masks(SYSCTL_HANDLER_ARGS)
+{
+	struct isci_softc	*isci = (struct isci_softc *)arg1;
+	struct ISCI_REMOTE_DEVICE *device;
+	int32_t			log_frozen_devices = 0;
+	int			error, i, j;
+
+	error = sysctl_handle_int(oidp, &log_frozen_devices, 0, req);
+
+	if (error || log_frozen_devices == 0)
+		return (error);
+
+	for (i = 0; i < isci->controller_count; i++) {
+		for (j = 0; j < SCI_MAX_REMOTE_DEVICES; j++) {
+			device = isci->controllers[i].remote_device[j];
+
+			if (device == NULL)
+				continue;
+
+			device_printf(isci->device,
+			    "controller %d device %3d frozen_lun_mask 0x%02x\n",
+			    i, j, device->frozen_lun_mask);
+		}
+	}
+
+	return (0);
+}
+
+static int
+isci_sysctl_fail_on_task_timeout(SYSCTL_HANDLER_ARGS)
+{
+	struct isci_softc	*isci = (struct isci_softc *)arg1;
+	int32_t			fail_on_timeout;
+	int			error, i;
+
+	fail_on_timeout = isci->controllers[0].fail_on_task_timeout;
+	error = sysctl_handle_int(oidp, &fail_on_timeout, 0, req);
+
+	if (error || req->newptr == NULL)
+		return (error);
+
+	for (i = 0; i < isci->controller_count; i++)
+		isci->controllers[i].fail_on_task_timeout = fail_on_timeout;
+
+	return (0);
+}
+
 void isci_sysctl_initialize(struct isci_softc *isci)
 {
 	struct sysctl_ctx_list *sysctl_ctx = device_get_sysctl_ctx(isci->device);
@@ -225,5 +274,15 @@
 	SYSCTL_ADD_PROC(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree), OID_AUTO,
 	    "start_phy", CTLTYPE_UINT| CTLFLAG_RW, isci, 0,
 	    isci_sysctl_start_phy, "IU", "Start PHY on a controller");
+
+	SYSCTL_ADD_PROC(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree), OID_AUTO,
+	    "log_frozen_lun_masks", CTLTYPE_UINT| CTLFLAG_RW, isci, 0,
+	    isci_sysctl_log_frozen_lun_masks, "IU",
+	    "Log frozen lun masks to kernel log");
+
+	SYSCTL_ADD_PROC(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree), OID_AUTO,
+	    "fail_on_task_timeout", CTLTYPE_UINT | CTLFLAG_RW, isci, 0,
+	    isci_sysctl_fail_on_task_timeout, "IU",
+	    "Fail a command that has encountered a task management timeout");
 }
 

Modified: trunk/sys/dev/isci/isci_task_request.c
===================================================================
--- trunk/sys/dev/isci/isci_task_request.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/isci_task_request.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * BSD LICENSE
  *
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/isci_task_request.c 311921 2017-01-11 07:46:01Z mav $");
 
 #include <dev/isci/isci.h>
 
@@ -194,13 +195,32 @@
 		break;
 
 	case SCI_TASK_FAILURE_INVALID_STATE:
+		retry_task = TRUE;
+		isci_log_message(0, "ISCI",
+		    "task failure (invalid state) - retrying\n");
+		break;
+
 	case SCI_TASK_FAILURE_INSUFFICIENT_RESOURCES:
-	case SCI_FAILURE_TIMEOUT:
 		retry_task = TRUE;
 		isci_log_message(0, "ISCI",
-		    "unhandled task completion code 0x%x\n", completion_status);
+		    "task failure (insufficient resources) - retrying\n");
 		break;
 
+	case SCI_FAILURE_TIMEOUT:
+		if (isci_controller->fail_on_task_timeout) {
+			retry_task = FALSE;
+			isci_log_message(0, "ISCI",
+			    "task timeout - not retrying\n");
+			scif_cb_domain_device_removed(scif_controller,
+			    isci_remote_device->domain->sci_object,
+			    remote_device);
+		} else {
+			retry_task = TRUE;
+			isci_log_message(0, "ISCI",
+			    "task timeout - retrying\n");
+		}
+		break;
+
 	case SCI_TASK_FAILURE:
 	case SCI_TASK_FAILURE_UNSUPPORTED_PROTOCOL:
 	case SCI_TASK_FAILURE_INVALID_TAG:

Modified: trunk/sys/dev/isci/isci_timer.c
===================================================================
--- trunk/sys/dev/isci/isci_timer.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/isci_timer.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * BSD LICENSE
  *
@@ -29,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/isci_timer.c 275982 2014-12-21 03:06:11Z smh $");
 
 #include <dev/isci/isci.h>
 
@@ -79,8 +80,8 @@
 
 	isci_timer->is_started = TRUE;
 	isci_log_message(3, "TIMER", "start %p %d\n", timer, milliseconds);
-	callout_reset(&isci_timer->callout, (milliseconds * hz)/1000,
-	    isci_timer_timeout, timer);
+	callout_reset_sbt(&isci_timer->callout, SBT_1MS * milliseconds, 0,
+	    isci_timer_timeout, timer, 0);
 }
 
 /**

Modified: trunk/sys/dev/isci/sci_environment.h
===================================================================
--- trunk/sys/dev/isci/sci_environment.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/sci_environment.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1 +1,2 @@
+/* $MidnightBSD$ */
 /* empty file for now. compiler needs it */

Modified: trunk/sys/dev/isci/scil/intel_ata.h
===================================================================
--- trunk/sys/dev/isci/scil/intel_ata.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/intel_ata.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/intel_ata.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/intel_pci.h
===================================================================
--- trunk/sys/dev/isci/scil/intel_pci.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/intel_pci.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/intel_pci.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _INTEL_PCI_H_
 #define _INTEL_PCI_H_

Modified: trunk/sys/dev/isci/scil/intel_sas.h
===================================================================
--- trunk/sys/dev/isci/scil/intel_sas.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/intel_sas.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/intel_sas.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _INTEL_SAS_H_
 #define _INTEL_SAS_H_

Modified: trunk/sys/dev/isci/scil/intel_sat.h
===================================================================
--- trunk/sys/dev/isci/scil/intel_sat.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/intel_sat.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/intel_sat.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SAT_H_
 #define _SAT_H_

Modified: trunk/sys/dev/isci/scil/intel_sata.h
===================================================================
--- trunk/sys/dev/isci/scil/intel_sata.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/intel_sata.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/intel_sata.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATA_H_
 #define _SATA_H_

Modified: trunk/sys/dev/isci/scil/intel_scsi.h
===================================================================
--- trunk/sys/dev/isci/scil/intel_scsi.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/intel_scsi.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/intel_scsi.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati.c
===================================================================
--- trunk/sys/dev/isci/scil/sati.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati.c 240518 2012-09-14 21:28:56Z eadler $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati.h
===================================================================
--- trunk/sys/dev/isci/scil/sati.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_H_
 #define _SATI_H_

Modified: trunk/sys/dev/isci/scil/sati_abort_task_set.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_abort_task_set.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_abort_task_set.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_abort_task_set.c 231296 2012-02-09 17:50:24Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_abort_task_set.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_abort_task_set.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_abort_task_set.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_abort_task_set.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_ABORT_TASK_SET_H_
 #define _SATI_ABORT_TASK_SET_H_

Modified: trunk/sys/dev/isci/scil/sati_atapi.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_atapi.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_atapi.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_atapi.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_atapi.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_atapi.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_atapi.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_atapi.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_ATAPI_H_
 #define _SATI_ATAPI_H_

Modified: trunk/sys/dev/isci/scil/sati_callbacks.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_callbacks.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_callbacks.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_callbacks.h 240518 2012-09-14 21:28:56Z eadler $
  */
 #ifndef _SATI_CALLBACKS_H_
 #define _SATI_CALLBACKS_H_

Modified: trunk/sys/dev/isci/scil/sati_design.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_design.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_design.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_design.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_DESIGN_H_
 #define _SATI_DESIGN_H_

Modified: trunk/sys/dev/isci/scil/sati_device.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_device.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_device.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_device.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_device.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_device.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_device.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_device.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_DEVICE_H_
 #define _SATI_DEVICE_H_

Modified: trunk/sys/dev/isci/scil/sati_inquiry.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_inquiry.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_inquiry.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_inquiry.c 235043 2012-05-04 23:45:34Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_inquiry.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_inquiry.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_inquiry.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_inquiry.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_INQUIRY_H_
 #define _SATI_INQUIRY_H_

Modified: trunk/sys/dev/isci/scil/sati_log_sense.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_log_sense.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_log_sense.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_log_sense.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
 * @file

Modified: trunk/sys/dev/isci/scil/sati_log_sense.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_log_sense.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_log_sense.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_log_sense.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_lun_reset.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_lun_reset.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_lun_reset.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_lun_reset.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_lun_reset.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_lun_reset.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_lun_reset.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_lun_reset.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_LUN_RESET_H_
 #define _SATI_LUN_RESET_H_

Modified: trunk/sys/dev/isci/scil/sati_mode_pages.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_mode_pages.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_mode_pages.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_mode_pages.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_mode_pages.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_mode_pages.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_mode_pages.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_mode_pages.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_mode_select.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_mode_select.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_mode_select.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_mode_select.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_mode_select.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_mode_select.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_mode_select.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_mode_select.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_MODE_SELECT_H_
 #define _SATI_MODE_SELECT_H_

Modified: trunk/sys/dev/isci/scil/sati_mode_sense.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_mode_sense.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_mode_sense.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
  /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_mode_sense.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_mode_sense.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_mode_sense.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_mode_sense.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_mode_sense.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_MODE_SENSE_H_
 #define _SATI_MODE_SENSE_H_

Modified: trunk/sys/dev/isci/scil/sati_mode_sense_10.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_mode_sense_10.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_mode_sense_10.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_mode_sense_10.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_mode_sense_10.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_mode_sense_10.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_mode_sense_10.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_mode_sense_10.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_MODE_SENSE_10_H_
 #define _SATI_MODE_SENSE_10_H_

Modified: trunk/sys/dev/isci/scil/sati_mode_sense_6.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_mode_sense_6.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_mode_sense_6.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_mode_sense_6.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_mode_sense_6.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_mode_sense_6.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_mode_sense_6.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_mode_sense_6.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_MODE_SENSE_6_H_
 #define _SATI_MODE_SENSE_6_H_

Modified: trunk/sys/dev/isci/scil/sati_move.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_move.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_move.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_move.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_move.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_move.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_move.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_move.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_MOVE_H_
 #define _SATI_MOVE_H_

Modified: trunk/sys/dev/isci/scil/sati_passthrough.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_passthrough.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_passthrough.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_passthrough.c 265570 2014-05-07 16:56:20Z jimharris $");
 
 /**
  * @file
@@ -85,6 +86,7 @@
 // Protocols
 #define PASSTHROUGH_PIO_DATA_IN            0x4
 #define PASSTHROUGH_PIO_DATA_OUT           0x5
+#define PASSTHROUGH_DMA                    0x6
 #define PASSTHROUGH_UDMA_DATA_IN           0xA
 #define PASSTHROUGH_UDMA_DATA_OUT          0xB
 #define PASSTHROUGH_RETURN_RESPONSE        0xF
@@ -252,8 +254,8 @@
    U8           * cdb
 )
 {
-   if ((PASSTHROUGH_CDB_PROTOCOL(cdb) == PASSTHROUGH_PIO_DATA_IN) ||
-       (PASSTHROUGH_CDB_PROTOCOL(cdb) == PASSTHROUGH_UDMA_DATA_IN))
+   if ((sequence->protocol == PASSTHROUGH_PIO_DATA_IN) ||
+       (sequence->protocol == PASSTHROUGH_UDMA_DATA_IN))
    {
       if (PASSTHROUGH_CDB_T_DIR(cdb) == 0x0)
       {
@@ -264,8 +266,8 @@
          sequence->data_direction = SATI_DATA_DIRECTION_IN;
       }
    }
-   else if ((PASSTHROUGH_CDB_PROTOCOL(cdb) == PASSTHROUGH_PIO_DATA_OUT) ||
-            (PASSTHROUGH_CDB_PROTOCOL(cdb) == PASSTHROUGH_UDMA_DATA_OUT))
+   else if ((sequence->protocol == PASSTHROUGH_PIO_DATA_OUT) ||
+            (sequence->protocol == PASSTHROUGH_UDMA_DATA_OUT))
    {
       if (PASSTHROUGH_CDB_T_DIR(cdb) == 0x1)
       {
@@ -318,6 +320,26 @@
    sequence->protocol = PASSTHROUGH_CDB_PROTOCOL (cdb);
    register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
 
+   /*
+    * CAM will send passthrough commands with protocol set to multiword
+    * DMA even though no multiword DMA mode is selected on the device.
+    * This is because some controllers (LSI) will only accept
+    * ATA_PASSTHROUGH commands with DMA mode - not UDMA_IN/OUT.
+    *
+    * Since isci does not support multiword DMA, fix this up here.
+    */
+   if (sequence->protocol == PASSTHROUGH_DMA)
+   {
+      if (PASSTHROUGH_CDB_T_DIR(cdb) == 0x1)
+      {
+         sequence->protocol = PASSTHROUGH_UDMA_DATA_IN;
+      }
+      else
+      {
+         sequence->protocol = PASSTHROUGH_UDMA_DATA_OUT;
+      }
+   }
+
    if (sati_passthrough_check_direction(sequence, cdb) != SATI_COMPLETE
        || sati_passthrough_multiple_count_error(cdb)
       )
@@ -376,6 +398,26 @@
    sequence->protocol = PASSTHROUGH_CDB_PROTOCOL(cdb);
    register_fis = sati_cb_get_h2d_register_fis_address(ata_io);
 
+   /*
+    * CAM will send passthrough commands with protocol set to multiword
+    * DMA even though no multiword DMA mode is selected on the device.
+    * This is because some controllers (LSI) will only accept
+    * ATA_PASSTHROUGH commands with DMA mode - not UDMA_IN/OUT.
+    *
+    * Since isci does not support multiword DMA, fix this up here.
+    */
+   if (sequence->protocol == PASSTHROUGH_DMA)
+   {
+      if (PASSTHROUGH_CDB_T_DIR(cdb) == 0x1)
+      {
+         sequence->protocol = PASSTHROUGH_UDMA_DATA_IN;
+      }
+      else
+      {
+         sequence->protocol = PASSTHROUGH_UDMA_DATA_OUT;
+      }
+   }
+
    if (sati_passthrough_check_direction(sequence, cdb) != SATI_COMPLETE
        || sati_passthrough_multiple_count_error(cdb)
       )
@@ -400,6 +442,13 @@
       sati_set_ata_lba_mid_exp(register_fis, sati_get_cdb_byte(cdb, 9));
       sati_set_ata_lba_high_exp(register_fis, sati_get_cdb_byte(cdb, 11));
    }
+
+   if (PASSTHROUGH_CDB_CK_COND(cdb) ||
+       PASSTHROUGH_CDB_PROTOCOL(cdb) == PASSTHROUGH_RETURN_RESPONSE)
+   {
+      sequence->is_translate_response_required = TRUE;
+   }
+
    sati_set_ata_features(register_fis, sati_get_cdb_byte(cdb, 4));
    sati_set_ata_sector_count(register_fis, sati_get_cdb_byte(cdb, 6));
    sati_set_ata_lba_low(register_fis, sati_get_cdb_byte(cdb, 8));
@@ -442,6 +491,8 @@
       return SATI_FAILURE_CHECK_RESPONSE_DATA;
    }
 
+   sequence->state = SATI_SEQUENCE_STATE_FINAL;
+
    // If the user set the check condition bit, fill out the sense data
    if (PASSTHROUGH_CDB_CK_COND(cdb) ||
        PASSTHROUGH_CDB_PROTOCOL(cdb) == PASSTHROUGH_RETURN_RESPONSE)
@@ -455,10 +506,9 @@
          SCSI_ASC_NO_ADDITIONAL_SENSE,
          SCSI_ASCQ_ATA_PASS_THROUGH_INFORMATION_AVAILABLE
       );
+      return SATI_FAILURE_CHECK_RESPONSE_DATA;
    }
 
-   sequence->state = SATI_SEQUENCE_STATE_FINAL;
-
    return SATI_COMPLETE;
 }
 

Modified: trunk/sys/dev/isci/scil/sati_passthrough.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_passthrough.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_passthrough.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_passthrough.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_PASSTHROUGH_H_
 #define _SATI_PASSTHROUGH_H_

Modified: trunk/sys/dev/isci/scil/sati_read.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_read.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_read.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_read.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_read.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_read.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_read.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_read.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_READ_H_
 #define _SATI_READ_H_

Modified: trunk/sys/dev/isci/scil/sati_read_buffer.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_read_buffer.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_read_buffer.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_read_buffer.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
 * @file

Modified: trunk/sys/dev/isci/scil/sati_read_buffer.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_read_buffer.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_read_buffer.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_read_buffer.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 /**
 * @file

Modified: trunk/sys/dev/isci/scil/sati_read_capacity.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_read_capacity.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_read_capacity.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_read_capacity.c 233663 2012-03-29 15:43:07Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_read_capacity.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_read_capacity.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_read_capacity.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_read_capacity.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_READ_CAPACITY_H_
 #define _SATI_READ_CAPACITY_H_

Modified: trunk/sys/dev/isci/scil/sati_reassign_blocks.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_reassign_blocks.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_reassign_blocks.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_reassign_blocks.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_reassign_blocks.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_reassign_blocks.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_reassign_blocks.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_reassign_blocks.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_REASSIGN_BLOCKS_H_
 #define _SATI_REASSIGN_BLOCKS_H_

Modified: trunk/sys/dev/isci/scil/sati_report_luns.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_report_luns.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_report_luns.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_report_luns.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_report_luns.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_report_luns.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_report_luns.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_report_luns.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_REPORT_LUNS_H_
 #define _SATI_REPORT_LUNS_H_

Modified: trunk/sys/dev/isci/scil/sati_request_sense.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_request_sense.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_request_sense.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_request_sense.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_request_sense.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_request_sense.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_request_sense.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_request_sense.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_start_stop_unit.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_start_stop_unit.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_start_stop_unit.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_start_stop_unit.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_start_stop_unit.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_start_stop_unit.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_start_stop_unit.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_start_stop_unit.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_START_STOP_UNIT_H_
 #define _SATI_START_STOP_UNIT_H_

Modified: trunk/sys/dev/isci/scil/sati_synchronize_cache.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_synchronize_cache.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_synchronize_cache.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_synchronize_cache.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_synchronize_cache.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_synchronize_cache.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_synchronize_cache.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_synchronize_cache.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_SYNCHRONIZE_CACHE_H_
 #define _SATI_SYNCHRONIZE_CACHE_H_

Modified: trunk/sys/dev/isci/scil/sati_test_unit_ready.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_test_unit_ready.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_test_unit_ready.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_test_unit_ready.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_test_unit_ready.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_test_unit_ready.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_test_unit_ready.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_test_unit_ready.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_TEST_UNIT_READY_H_
 #define _SATI_TEST_UNIT_READY_H_

Modified: trunk/sys/dev/isci/scil/sati_translator_sequence.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_translator_sequence.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_translator_sequence.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_translator_sequence.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_TRANSLATOR_SEQUENCE_H_
 #define _SATI_TRANSLATOR_SEQUENCE_H_

Modified: trunk/sys/dev/isci/scil/sati_types.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_types.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_types.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_types.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_TYPES_H_
 #define _SATI_TYPES_H_

Modified: trunk/sys/dev/isci/scil/sati_unmap.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_unmap.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_unmap.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_unmap.c 239545 2012-08-21 22:28:14Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_unmap.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_unmap.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_unmap.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_unmap.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_UNMAP_H_
 #define _SATI_UNMAP_H_

Modified: trunk/sys/dev/isci/scil/sati_util.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_util.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_util.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_util.c 240514 2012-09-14 20:05:38Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_util.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_util.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_util.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_util.h 265571 2014-05-07 16:57:33Z jimharris $
  */
 #ifndef _SATI_UTIL_H_
 #define _SATI_UTIL_H_
@@ -62,6 +63,8 @@
  *        structure data, fill in sense data, etc.
  */
 
+#include <sys/param.h>
+
 #include <dev/isci/scil/sati_types.h>
 #include <dev/isci/scil/sati_translator_sequence.h>
 
@@ -144,15 +147,6 @@
 #define ATA_MICROCODE_OFFSET_DOWNLOAD        0x03
 #define ATA_MICROCODE_DOWNLOAD_SAVE          0x07
 
-#ifndef MIN
-#define MIN(x,y) ((x) < (y) ? (x) : (y))
-#endif
-
-#ifndef MAX
-#define MAX(x,y) ((x) > (y) ? (x) : (y))
-#endif
-
-
 void sati_ata_non_data_command(
    void                        * ata_io,
    SATI_TRANSLATOR_SEQUENCE_T  * sequence

Modified: trunk/sys/dev/isci/scil/sati_verify.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_verify.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_verify.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_verify.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_verify.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_verify.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_verify.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_verify.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_VERIFY_H_
 #define _SATI_VERIFY_H_

Modified: trunk/sys/dev/isci/scil/sati_write.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_write.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_write.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_write.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_write.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_write.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_write.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_write.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SATI_WRITE_H_
 #define _SATI_WRITE_H_

Modified: trunk/sys/dev/isci/scil/sati_write_and_verify.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_write_and_verify.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_write_and_verify.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_write_and_verify.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
 * @file

Modified: trunk/sys/dev/isci/scil/sati_write_and_verify.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_write_and_verify.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_write_and_verify.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_write_and_verify.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 /**
 * @file

Modified: trunk/sys/dev/isci/scil/sati_write_buffer.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_write_buffer.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_write_buffer.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_write_buffer.c 240514 2012-09-14 20:05:38Z jimharris $");
 
 /**
 * @file

Modified: trunk/sys/dev/isci/scil/sati_write_buffer.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_write_buffer.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_write_buffer.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_write_buffer.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 /**
 * @file

Modified: trunk/sys/dev/isci/scil/sati_write_long.c
===================================================================
--- trunk/sys/dev/isci/scil/sati_write_long.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_write_long.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sati_write_long.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sati_write_long.h
===================================================================
--- trunk/sys/dev/isci/scil/sati_write_long.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sati_write_long.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sati_write_long.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_abstract_list.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_abstract_list.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_abstract_list.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_abstract_list.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_abstract_list.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_abstract_list.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_abstract_list.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_abstract_list.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_base_controller.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_controller.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_controller.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_base_controller.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_base_controller.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_controller.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_controller.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_base_controller.h 240518 2012-09-14 21:28:56Z eadler $
  */
 #ifndef _SCI_BASE_CONTROLLER_H_
 #define _SCI_BASE_CONTROLLER_H_

Modified: trunk/sys/dev/isci/scil/sci_base_domain.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_domain.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_domain.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_base_domain.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_base_domain.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_domain.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_domain.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_base_domain.h 240518 2012-09-14 21:28:56Z eadler $
  */
 #ifndef _SCI_BASE_DOMAIN_H_
 #define _SCI_BASE_DOMAIN_H_

Modified: trunk/sys/dev/isci/scil/sci_base_iterator.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_iterator.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_iterator.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_base_iterator.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_base_iterator.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_iterator.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_iterator.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_base_iterator.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_base_library.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_library.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_library.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_base_library.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_base_library.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_library.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_library.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_base_library.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_BASE_LIBRARY_H_
 #define _SCI_BASE_LIBRARY_H_

Modified: trunk/sys/dev/isci/scil/sci_base_logger.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_logger.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_logger.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_base_logger.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_base_logger.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_logger.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_logger.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_base_logger.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_BASE_LOGGER_H_
 #define _SCI_BASE_LOGGER_H_

Modified: trunk/sys/dev/isci/scil/sci_base_memory_descriptor_list.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_memory_descriptor_list.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_memory_descriptor_list.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_base_memory_descriptor_list.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_base_memory_descriptor_list.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_memory_descriptor_list.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_memory_descriptor_list.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_base_memory_descriptor_list.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_BASE_MEMORY_DESCRIPTOR_LIST_H_
 #define _SCI_BASE_MEMORY_DESCRIPTOR_LIST_H_

Modified: trunk/sys/dev/isci/scil/sci_base_memory_descriptor_list_decorator.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_memory_descriptor_list_decorator.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_memory_descriptor_list_decorator.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_base_memory_descriptor_list_decorator.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_base_object.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_object.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_object.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_base_object.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_base_object.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_object.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_object.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_base_object.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_BASE_OBJECT_H_
 #define _SCI_BASE_OBJECT_H_

Modified: trunk/sys/dev/isci/scil/sci_base_observer.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_observer.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_observer.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_base_observer.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_base_observer.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_observer.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_observer.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_base_observer.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_BASE_OBSERVER_H_
 #define _SCI_BASE_OBSERVER_H_

Modified: trunk/sys/dev/isci/scil/sci_base_phy.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_phy.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_phy.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_base_phy.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_base_phy.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_phy.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_phy.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_base_phy.h 240518 2012-09-14 21:28:56Z eadler $
  */
 #ifndef _SCI_BASE_PHY_H_
 #define _SCI_BASE_PHY_H_

Modified: trunk/sys/dev/isci/scil/sci_base_port.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_port.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_port.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_base_port.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_base_port.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_port.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_port.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_base_port.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_BASE_PORT_H_
 #define _SCI_BASE_PORT_H_

Modified: trunk/sys/dev/isci/scil/sci_base_remote_device.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_remote_device.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_remote_device.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_base_remote_device.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 #include <dev/isci/scil/sci_base_remote_device.h>
 

Modified: trunk/sys/dev/isci/scil/sci_base_remote_device.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_remote_device.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_remote_device.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_base_remote_device.h 240518 2012-09-14 21:28:56Z eadler $
  */
 #ifndef _SCI_BASE_REMOTE_DEVICE_H_
 #define _SCI_BASE_REMOTE_DEVICE_H_

Modified: trunk/sys/dev/isci/scil/sci_base_request.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_request.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_request.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_base_request.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 #include <dev/isci/scil/sci_base_request.h>
 

Modified: trunk/sys/dev/isci/scil/sci_base_request.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_request.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_request.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_base_request.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_BASE_REQUST_H_
 #define _SCI_BASE_REQUST_H_

Modified: trunk/sys/dev/isci/scil/sci_base_state.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_state.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_state.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_base_state.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_BASE_STATE_H_
 #define _SCI_BASE_STATE_H_

Modified: trunk/sys/dev/isci/scil/sci_base_state_machine.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_state_machine.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_state_machine.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_base_state_machine.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_base_state_machine.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_state_machine.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_state_machine.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_base_state_machine.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_BASE_STATE_MACHINE_H_
 #define _SCI_BASE_STATE_MACHINE_H_

Modified: trunk/sys/dev/isci/scil/sci_base_state_machine_logger.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_state_machine_logger.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_state_machine_logger.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_base_state_machine_logger.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_base_state_machine_logger.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_state_machine_logger.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_state_machine_logger.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_base_state_machine_logger.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_BASE_STATE_MACHINE_LOGGER_H_
 #define _SCI_BASE_STATE_MACHINE_LOGGER_H_

Modified: trunk/sys/dev/isci/scil/sci_base_state_machine_observer.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_state_machine_observer.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_state_machine_observer.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_base_state_machine_observer.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_base_state_machine_observer.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_state_machine_observer.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_state_machine_observer.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_base_state_machine_observer.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_BASE_STATE_MACHINE_OBSERVER_H_
 #define _SCI_BASE_STATE_MACHINE_OBSERVER_H_

Modified: trunk/sys/dev/isci/scil/sci_base_subject.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_subject.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_subject.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_base_subject.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_base_subject.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_base_subject.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_base_subject.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_base_subject.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_BASE_SUBJECT_H_
 #define _SCI_BASE_SUBJECT_H_

Modified: trunk/sys/dev/isci/scil/sci_controller.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_controller.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_controller.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_controller.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_CONTROLLER_H_
 #define _SCI_CONTROLLER_H_

Modified: trunk/sys/dev/isci/scil/sci_controller_constants.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_controller_constants.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_controller_constants.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,11 +50,13 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_controller_constants.h 265571 2014-05-07 16:57:33Z jimharris $
  */
 #ifndef _SCI_CONTROLLER_CONSTANTS_H_
 #define _SCI_CONTROLLER_CONSTANTS_H_
 
+#include <sys/param.h>
+
 /**
  * @file
  *
@@ -148,8 +151,13 @@
 /**
  * This constant defines the maximum number of Scatter-Gather Elements
  * to be used by any SCI component.
+ *
+ * Note: number of elements must be an even number, since descriptors
+ * posted to hardware always contain pairs of elements (with second
+ * element set to zeroes if not needed).
  */
-#define SCI_MAX_SCATTER_GATHER_ELEMENTS 130
+#define __MAXPHYS_ELEMENTS ((MAXPHYS / PAGE_SIZE) + 1)
+#define SCI_MAX_SCATTER_GATHER_ELEMENTS  ((__MAXPHYS_ELEMENTS + 1) & ~0x1)
 #endif
 
 #ifndef SCI_MIN_SCATTER_GATHER_ELEMENTS

Modified: trunk/sys/dev/isci/scil/sci_fast_list.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_fast_list.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_fast_list.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_fast_list.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_FAST_LIST_HEADER_
 #define _SCI_FAST_LIST_HEADER_

Modified: trunk/sys/dev/isci/scil/sci_iterator.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_iterator.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_iterator.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_iterator.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_library.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_library.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_library.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_library.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_LIBRARY_H_
 #define _SCI_LIBRARY_H_

Modified: trunk/sys/dev/isci/scil/sci_logger.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_logger.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_logger.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_logger.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_LOGGER_H_
 #define _SCI_LOGGER_H_

Modified: trunk/sys/dev/isci/scil/sci_memory_descriptor_list.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_memory_descriptor_list.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_memory_descriptor_list.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_memory_descriptor_list.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_MEMORY_DESCRIPTOR_LIST_H_
 #define _SCI_MEMORY_DESCRIPTOR_LIST_H_

Modified: trunk/sys/dev/isci/scil/sci_memory_descriptor_list_decorator.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_memory_descriptor_list_decorator.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_memory_descriptor_list_decorator.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_memory_descriptor_list_decorator.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_MEMORY_DESCRIPTOR_LIST_DECORATOR_H_
 #define _SCI_MEMORY_DESCRIPTOR_LIST_DECORATOR_H_

Modified: trunk/sys/dev/isci/scil/sci_object.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_object.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_object.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_object.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_OBJECT_H_
 #define _SCI_OBJECT_H_

Modified: trunk/sys/dev/isci/scil/sci_overview.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_overview.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_overview.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_overview.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_OVERVIEW_H_
 #define _SCI_OVERVIEW_H_

Modified: trunk/sys/dev/isci/scil/sci_pool.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_pool.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_pool.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_pool.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/sci_simple_list.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_simple_list.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_simple_list.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_simple_list.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_SIMPLE_LIST_HEADER_
 #define _SCI_SIMPLE_LIST_HEADER_

Modified: trunk/sys/dev/isci/scil/sci_status.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_status.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_status.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_status.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_STATUS_H_
 #define _SCI_STATUS_H_

Modified: trunk/sys/dev/isci/scil/sci_types.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_types.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_types.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_types.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCI_TYPES_H_
 #define _SCI_TYPES_H_

Modified: trunk/sys/dev/isci/scil/sci_util.c
===================================================================
--- trunk/sys/dev/isci/scil/sci_util.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_util.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/sci_util.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 #include <dev/isci/scil/sci_util.h>
 

Modified: trunk/sys/dev/isci/scil/sci_util.h
===================================================================
--- trunk/sys/dev/isci/scil/sci_util.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/sci_util.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,11 +50,13 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/sci_util.h 265571 2014-05-07 16:57:33Z jimharris $
  */
 #ifndef _SCI_UTIL_H_
 #define _SCI_UTIL_H_
 
+#include <sys/param.h>
+
 #include <dev/isci/scil/sci_types.h>
 
 #ifndef ARRAY_SIZE
@@ -60,14 +63,6 @@
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 #endif
 
-#ifndef MIN
-#define MIN(x,y) ((x) < (y) ? (x) : (y))
-#endif
-
-#ifndef MAX
-#define MAX(x,y) ((x) > (y) ? (x) : (y))
-#endif
-
 /**
  * Normal byte swap macro
  */

Modified: trunk/sys/dev/isci/scil/scic_config_parameters.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_config_parameters.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_config_parameters.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_config_parameters.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_SDS_USER_PARAMETERS_H_
 #define _SCIC_SDS_USER_PARAMETERS_H_

Modified: trunk/sys/dev/isci/scil/scic_controller.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_controller.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_controller.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_controller.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_CONTROLLER_H_
 #define _SCIC_CONTROLLER_H_

Modified: trunk/sys/dev/isci/scil/scic_io_request.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_io_request.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_io_request.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_io_request.h 240520 2012-09-14 21:59:55Z eadler $
  */
 #ifndef _SCIC_IO_REQUEST_H_
 #define _SCIC_IO_REQUEST_H_

Modified: trunk/sys/dev/isci/scil/scic_library.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_library.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_library.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_library.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_LIBRARY_H_
 #define _SCIC_LIBRARY_H_

Modified: trunk/sys/dev/isci/scil/scic_logger.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_logger.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_logger.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_logger.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_LOGGER_H_
 #define _SCIC_LOGGER_H_

Modified: trunk/sys/dev/isci/scil/scic_overview.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_overview.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_overview.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_overview.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_OVERVIEW_H_
 #define _SCIC_OVERVIEW_H_

Modified: trunk/sys/dev/isci/scil/scic_phy.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_phy.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_phy.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_phy.h 300060 2016-05-17 15:18:01Z pfg $
  */
 #ifndef _SCIC_PHY_H_
 #define _SCIC_PHY_H_
@@ -308,7 +309,7 @@
 
 /**
  * @brief This method will enable the user to retrieve information
- *        specific to a SATA phy, such as: the recieved signature
+ *        specific to a SATA phy, such as: the received signature
  *        FIS, if a port selector is present, etc.
  *
  * @param[in]  phy this parameter specifies the phy for which to

Modified: trunk/sys/dev/isci/scil/scic_port.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_port.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_port.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_port.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_PORT_H_
 #define _SCIC_PORT_H_

Modified: trunk/sys/dev/isci/scil/scic_remote_device.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_remote_device.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_remote_device.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_remote_device.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_REMOTE_DEVICE_H_
 #define _SCIC_REMOTE_DEVICE_H_

Modified: trunk/sys/dev/isci/scil/scic_sds_controller.c
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_controller.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_controller.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_controller.c 231296 2012-02-09 17:50:24Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scic_sds_controller.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_controller.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_controller.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_controller.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_SDS_CONTROLLER_H_
 #define _SCIC_SDS_CONTROLLER_H_

Modified: trunk/sys/dev/isci/scil/scic_sds_controller_registers.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_controller_registers.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_controller_registers.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_controller_registers.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_SDS_CONTROLLER_REGISTERS_H_
 #define _SCIC_SDS_CONTROLLER_REGISTERS_H_

Modified: trunk/sys/dev/isci/scil/scic_sds_library.c
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_library.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_library.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_library.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scic_sds_library.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_library.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_library.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_library.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_SDS_LIBRARY_H_
 #define _SCIC_SDS_LIBRARY_H_

Modified: trunk/sys/dev/isci/scil/scic_sds_logger.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_logger.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_logger.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_logger.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_SDS_LOGGER_H_
 #define _SCIC_SDS_LOGGER_H_

Modified: trunk/sys/dev/isci/scil/scic_sds_pci.c
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_pci.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_pci.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_pci.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scic_sds_pci.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_pci.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_pci.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_pci.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_SDS_PCI_H_
 #define _SCIC_SDS_PCI_H_

Modified: trunk/sys/dev/isci/scil/scic_sds_phy.c
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_phy.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_phy.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_phy.c 300060 2016-05-17 15:18:01Z pfg $");
 
 /**
  * @file
@@ -749,7 +750,7 @@
       this_phy, link_layer_registers
    ));
 
-   // Perfrom the initialization of the TL hardware
+   // Perform the initialization of the TL hardware
    scic_sds_phy_transport_layer_initialization(this_phy, transport_layer_registers);
 
    // Perofrm the initialization of the PE hardware
@@ -975,7 +976,7 @@
  *
  * @param[in] controller This parameter specifies the core controller, one of
  *            its phy's resources are to be released.
- * @param[in] this_phy This parameter specifies the phy whose resourse is to
+ * @param[in] this_phy This parameter specifies the phy whose resource is to
  *            be released.
  */
 void scic_sds_phy_release_resource(
@@ -1029,7 +1030,7 @@
 }
 
 /**
- * @brief This method will process the event code recieved.
+ * @brief This method will process the event code received.
  *
  * @param[in] this_phy
  * @param[in] event_code
@@ -1052,7 +1053,7 @@
 }
 
 /**
- * @brief This method will process the frame index recieved.
+ * @brief This method will process the frame index received.
  *
  * @param[in] this_phy
  * @param[in] frame_index
@@ -1754,7 +1755,7 @@
    SCIC_LOG_WARNING((
       sci_base_object_get_logger(this_phy),
       SCIC_LOG_OBJECT_PHY,
-      "SCIC Phy 0x%08x recieved unexpected frame data %d while in state %d\n",
+      "SCIC Phy 0x%08x received unexpected frame data %d while in state %d\n",
       this_phy, frame_index,
       sci_base_state_machine_get_state(&this_phy->parent.state_machine)
    ));
@@ -1866,7 +1867,7 @@
  * This method takes the SCIC_SDS_PHY from a stopped state and destroys it.
  *    - This function takes no action.
  *
- * @todo Shouldnt this function transition the SCI_BASE_PHY::state_machine to
+ * @todo Shouldn't this function transition the SCI_BASE_PHY::state_machine to
  *        the SCI_BASE_PHY_STATE_FINAL?
  *
  * @param[in] phy This is the SCI_BASE_PHY object which is cast into a
@@ -1964,7 +1965,7 @@
  *    - decoded event is a link failure
  *       - transition the SCIC_SDS_PHY back to the SCI_BASE_PHY_STATE_STARTING
  *         state.
- *    - any other event recived will report a warning message
+ *    - any other event received will report a warning message
  *
  * @param[in] phy This is the SCIC_SDS_PHY object which has received the
  *       event.
@@ -2020,7 +2021,7 @@
       SCIC_LOG_WARNING((
          sci_base_object_get_logger(this_phy),
          SCIC_LOG_OBJECT_PHY | SCIC_LOG_OBJECT_RECEIVED_EVENTS,
-         "SCIC PHY 0x%x ready state machine recieved unexpected event_code %x\n",
+         "SCIC PHY 0x%x ready state machine received unexpected event_code %x\n",
          this_phy, event_code
       ));
       result = SCI_FAILURE_INVALID_STATE;
@@ -2066,7 +2067,7 @@
       SCIC_LOG_WARNING((
          sci_base_object_get_logger(this_phy),
          SCIC_LOG_OBJECT_PHY | SCIC_LOG_OBJECT_RECEIVED_EVENTS,
-         "SCIC PHY 0x%x resetting state machine recieved unexpected event_code %x\n",
+         "SCIC PHY 0x%x resetting state machine received unexpected event_code %x\n",
          this_phy, event_code
       ));
 
@@ -2691,7 +2692,7 @@
       SCIC_LOG_WARNING((
          sci_base_object_get_logger(this_phy),
          SCIC_LOG_OBJECT_PHY | SCIC_LOG_OBJECT_RECEIVED_EVENTS,
-         "PHY starting substate machine recieved unexpected event_code %x\n",
+         "PHY starting substate machine received unexpected event_code %x\n",
          event_code
       ));
 
@@ -2772,7 +2773,7 @@
       SCIC_LOG_WARNING((
          sci_base_object_get_logger(this_phy),
          SCIC_LOG_OBJECT_PHY | SCIC_LOG_OBJECT_RECEIVED_EVENTS,
-         "PHY starting substate machine recieved unexpected event_code %x\n",
+         "PHY starting substate machine received unexpected event_code %x\n",
          event_code
       ));
 
@@ -2834,7 +2835,7 @@
       SCIC_LOG_WARNING((
          sci_base_object_get_logger(this_phy),
          SCIC_LOG_OBJECT_PHY | SCIC_LOG_OBJECT_RECEIVED_EVENTS,
-         "PHY starting substate machine recieved unexpected event_code %x\n",
+         "PHY starting substate machine received unexpected event_code %x\n",
          event_code
       ));
 
@@ -2879,7 +2880,7 @@
       SCIC_LOG_WARNING((
          sci_base_object_get_logger(this_phy),
          SCIC_LOG_OBJECT_PHY | SCIC_LOG_OBJECT_RECEIVED_EVENTS,
-         "PHY starting substate machine recieved unexpected event_code %x\n",
+         "PHY starting substate machine received unexpected event_code %x\n",
          event_code
       ));
 
@@ -2935,7 +2936,7 @@
       SCIC_LOG_WARNING((
          sci_base_object_get_logger(this_phy),
          SCIC_LOG_OBJECT_PHY | SCIC_LOG_OBJECT_RECEIVED_EVENTS,
-         "PHY starting substate machine recieved unexpected event_code %x\n",
+         "PHY starting substate machine received unexpected event_code %x\n",
          event_code
       ));
 
@@ -3003,7 +3004,7 @@
       SCIC_LOG_WARNING((
          sci_base_object_get_logger(this_phy),
          SCIC_LOG_OBJECT_PHY | SCIC_LOG_OBJECT_RECEIVED_EVENTS,
-         "PHY starting substate machine recieved unexpected event_code %x\n",
+         "PHY starting substate machine received unexpected event_code %x\n",
          event_code
       ));
 
@@ -3090,7 +3091,7 @@
       SCIC_LOG_WARNING((
          sci_base_object_get_logger(this_phy),
          SCIC_LOG_OBJECT_PHY | SCIC_LOG_OBJECT_RECEIVED_EVENTS,
-         "PHY starting substate machine recieved unexpected event_code %x\n",
+         "PHY starting substate machine received unexpected event_code %x\n",
          event_code
       ));
 
@@ -3147,7 +3148,7 @@
       SCIC_LOG_WARNING((
          sci_base_object_get_logger(this_phy),
          SCIC_LOG_OBJECT_PHY | SCIC_LOG_OBJECT_RECEIVED_EVENTS,
-         "PHY starting substate machine recieved unexpected event_code %x\n",
+         "PHY starting substate machine received unexpected event_code %x\n",
          event_code
       ));
 
@@ -3246,7 +3247,7 @@
       SCIC_LOG_WARNING((
          sci_base_object_get_logger(this_phy),
          SCIC_LOG_OBJECT_PHY | SCIC_LOG_OBJECT_UNSOLICITED_FRAMES,
-         "PHY starting substate machine recieved unexpected frame id %x\n",
+         "PHY starting substate machine received unexpected frame id %x\n",
          frame_index
       ));
    }
@@ -3332,7 +3333,7 @@
       SCIC_LOG_WARNING((
          sci_base_object_get_logger(this_phy),
          SCIC_LOG_OBJECT_PHY | SCIC_LOG_OBJECT_UNSOLICITED_FRAMES,
-         "PHY starting substate machine recieved unexpected frame id %x\n",
+         "PHY starting substate machine received unexpected frame id %x\n",
          frame_index
       ));
    }

Modified: trunk/sys/dev/isci/scil/scic_sds_phy.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_phy.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_phy.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_phy.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_SDS_PHY_H_
 #define _SCIC_SDS_PHY_H_

Modified: trunk/sys/dev/isci/scil/scic_sds_phy_registers.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_phy_registers.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_phy_registers.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_phy_registers.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_SDS_PHY_REGISTERS_H_
 #define _SCIC_SDS_PHY_REGISTERS_H_

Modified: trunk/sys/dev/isci/scil/scic_sds_port.c
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_port.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_port.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_port.c 249586 2013-04-17 11:47:32Z gabor $");
 
 /**
  * @file
@@ -1537,7 +1538,7 @@
  *
  * @param[in] controller This parameter specifies the core controller, one of
  *            its phy's resources are to be released.
- * @param[in] this_port This parameter specifies the port whose resourse is to
+ * @param[in] this_port This parameter specifies the port whose resource is to
  *            be released.
  */
 void scic_sds_port_release_resource(

Modified: trunk/sys/dev/isci/scil/scic_sds_port.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_port.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_port.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_port.h 240518 2012-09-14 21:28:56Z eadler $
  */
 #ifndef _SCIC_SDS_PORT_H_
 #define _SCIC_SDS_PORT_H_

Modified: trunk/sys/dev/isci/scil/scic_sds_port_configuration_agent.c
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_port_configuration_agent.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_port_configuration_agent.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_port_configuration_agent.c 249586 2013-04-17 11:47:32Z gabor $");
 
 /**
  * @file
@@ -1109,7 +1110,7 @@
  *
  * @param[in] controller This parameter specifies the core controller, one of
  *            its phy's resources are to be released.
- * @param[in] this_phy This parameter specifies the phy whose resourse is to
+ * @param[in] this_phy This parameter specifies the phy whose resource is to
  *            be released.
  */
 void scic_sds_port_configuration_agent_release_resource(

Modified: trunk/sys/dev/isci/scil/scic_sds_port_configuration_agent.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_port_configuration_agent.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_port_configuration_agent.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_port_configuration_agent.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_SDS_PORT_CONFIGURATION_AGENT_H_
 #define _SCIC_SDS_PORT_CONFIGURATION_AGENT_H_

Modified: trunk/sys/dev/isci/scil/scic_sds_port_registers.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_port_registers.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_port_registers.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_port_registers.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_SDS_PORT_REGISTERS_H_
 #define _SCIC_SDS_PORT_REGISTERS_H_

Modified: trunk/sys/dev/isci/scil/scic_sds_remote_device.c
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_remote_device.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_remote_device.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_remote_device.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scic_sds_remote_device.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_remote_device.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_remote_device.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_remote_device.h 240521 2012-09-14 22:00:03Z eadler $
  */
 #ifndef _SCIC_SDS_REMOTE_DEVICE_H_
 #define _SCIC_SDS_REMOTE_DEVICE_H_

Modified: trunk/sys/dev/isci/scil/scic_sds_remote_node_context.c
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_remote_node_context.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_remote_node_context.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_remote_node_context.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
 * @file

Modified: trunk/sys/dev/isci/scil/scic_sds_remote_node_context.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_remote_node_context.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_remote_node_context.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_remote_node_context.h 240518 2012-09-14 21:28:56Z eadler $
  */
 #ifndef _SCIC_SDS_REMOTE_NODE_CONTEXT_H_
 #define _SCIC_SDS_REMOTE_NODE_CONTEXT_H_

Modified: trunk/sys/dev/isci/scil/scic_sds_remote_node_table.c
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_remote_node_table.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_remote_node_table.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_remote_node_table.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scic_sds_remote_node_table.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_remote_node_table.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_remote_node_table.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_remote_node_table.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_SDS_REMOTE_NODE_TABLE_H_
 #define _SCIC_SDS_REMOTE_NODE_TABLE_H_

Modified: trunk/sys/dev/isci/scil/scic_sds_request.c
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_request.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_request.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_request.c 240518 2012-09-14 21:28:56Z eadler $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scic_sds_request.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_request.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_request.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_request.h 265571 2014-05-07 16:57:33Z jimharris $
  */
 #ifndef _SCIC_SDS_IO_REQUEST_H_
 #define _SCIC_SDS_IO_REQUEST_H_
@@ -65,6 +66,8 @@
 extern "C" {
 #endif // __cplusplus
 
+#include <sys/param.h>
+
 #include <dev/isci/scil/scic_io_request.h>
 
 #include <dev/isci/scil/sci_base_request.h>
@@ -331,7 +334,6 @@
 #define scic_sds_request_get_task_context(request) \
    ((request)->task_context_buffer)
 
-#define CACHE_LINE_SIZE (64)
 #define scic_sds_request_align_task_context_buffer(address) \
    ((SCU_TASK_CONTEXT_T *)( \
        (((POINTER_UINT)(address)) + (CACHE_LINE_SIZE - 1)) \

Modified: trunk/sys/dev/isci/scil/scic_sds_sgpio.c
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_sgpio.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_sgpio.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_sgpio.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
 * @file

Modified: trunk/sys/dev/isci/scil/scic_sds_smp_remote_device.c
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_smp_remote_device.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_smp_remote_device.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_smp_remote_device.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scic_sds_smp_request.c
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_smp_request.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_smp_request.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_smp_request.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 #include <dev/isci/scil/scic_sds_smp_request.h>
 #include <dev/isci/scil/scic_sds_logger.h>

Modified: trunk/sys/dev/isci/scil/scic_sds_smp_request.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_smp_request.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_smp_request.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_smp_request.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_SDS_SMP_REQUEST_T_
 #define _SCIC_SDS_SMP_REQUEST_T_

Modified: trunk/sys/dev/isci/scil/scic_sds_ssp_request.c
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_ssp_request.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_ssp_request.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_ssp_request.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scic_sds_stp_packet_request.c
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_stp_packet_request.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_stp_packet_request.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_stp_packet_request.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 #if !defined(DISABLE_ATAPI)
 

Modified: trunk/sys/dev/isci/scil/scic_sds_stp_packet_request.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_stp_packet_request.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_stp_packet_request.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_stp_packet_request.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_SDS_STP_PACKET_REQUEST_H_
 #define _SCIC_SDS_STP_PACKET_REQUEST_H_

Modified: trunk/sys/dev/isci/scil/scic_sds_stp_pio_request.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_stp_pio_request.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_stp_pio_request.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_stp_pio_request.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_SDS_SATA_PIO_REQUEST_H_
 #define _SCIC_SDS_SATA_PIO_REQUEST_H_

Modified: trunk/sys/dev/isci/scil/scic_sds_stp_remote_device.c
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_stp_remote_device.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_stp_remote_device.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_stp_remote_device.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scic_sds_stp_request.c
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_stp_request.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_stp_request.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_stp_request.c 268073 2014-07-01 06:23:48Z scottl $");
 
 #include <dev/isci/scil/intel_sat.h>
 #include <dev/isci/scil/intel_sata.h>
@@ -1222,6 +1223,7 @@
          length -= copy_length;
          sgl_offset += copy_length;
          data_offset += copy_length;
+         source_address += copy_length;
 #endif
       }
    }

Modified: trunk/sys/dev/isci/scil/scic_sds_stp_request.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_stp_request.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_stp_request.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_stp_request.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_SDS_STP_REQUEST_T_
 #define _SCIC_SDS_STP_REQUEST_T_

Modified: trunk/sys/dev/isci/scil/scic_sds_unsolicited_frame_control.c
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_unsolicited_frame_control.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_unsolicited_frame_control.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_unsolicited_frame_control.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scic_sds_unsolicited_frame_control.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sds_unsolicited_frame_control.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sds_unsolicited_frame_control.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sds_unsolicited_frame_control.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scic_sgpio.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_sgpio.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_sgpio.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_sgpio.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_SGPIO_H_
 #define _SCIC_SGPIO_H_

Modified: trunk/sys/dev/isci/scil/scic_task_request.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_task_request.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_task_request.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_task_request.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_TASK_REQUEST_H_
 #define _SCIC_TASK_REQUEST_H_

Modified: trunk/sys/dev/isci/scil/scic_user_callback.h
===================================================================
--- trunk/sys/dev/isci/scil/scic_user_callback.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scic_user_callback.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scic_user_callback.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIC_USER_CALLBACK_H_
 #define _SCIC_USER_CALLBACK_H_

Modified: trunk/sys/dev/isci/scil/scif_config_parameters.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_config_parameters.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_config_parameters.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_config_parameters.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_USER_PARAMETERS_H_
 #define _SCIF_SAS_USER_PARAMETERS_H_

Modified: trunk/sys/dev/isci/scil/scif_controller.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_controller.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_controller.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_controller.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_CONTROLLER_H_
 #define _SCIF_CONTROLLER_H_

Modified: trunk/sys/dev/isci/scil/scif_domain.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_domain.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_domain.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_domain.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_DOMAIN_H_
 #define _SCIF_DOMAIN_H_

Modified: trunk/sys/dev/isci/scil/scif_io_request.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_io_request.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_io_request.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_io_request.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_IO_REQUEST_H_
 #define _SCIF_IO_REQUEST_H_

Modified: trunk/sys/dev/isci/scil/scif_library.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_library.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_library.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_library.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_LIBRARY_H_
 #define _SCIF_LIBRARY_H_

Modified: trunk/sys/dev/isci/scil/scif_logger.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_logger.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_logger.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_logger.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_LOGGER_H_
 #define _SCIF_LOGGER_H_

Modified: trunk/sys/dev/isci/scil/scif_overview.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_overview.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_overview.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_overview.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_OVERVIEW_H_
 #define _SCIF_OVERVIEW_H_

Modified: trunk/sys/dev/isci/scil/scif_remote_device.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_remote_device.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_remote_device.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_remote_device.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_REMOTE_DEVICE_H_
 #define _SCIF_REMOTE_DEVICE_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_constants.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_constants.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_constants.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_constants.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_CONSTANTS_H_
 #define _SCIF_SAS_CONSTANTS_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_controller.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_controller.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_controller.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_controller.c 231296 2012-02-09 17:50:24Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_controller.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_controller.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_controller.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_controller.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_CONTROLLER_H_
 #define _SCIF_SAS_CONTROLLER_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_controller_state_handlers.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_controller_state_handlers.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_controller_state_handlers.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_controller_state_handlers.c 231296 2012-02-09 17:50:24Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_controller_states.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_controller_states.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_controller_states.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_controller_states.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_design.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_design.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_design.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_design.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_DESIGN_H_
 #define _SCIF_SAS_DESIGN_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_domain.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_domain.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_domain.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_domain.c 250460 2013-05-10 16:41:26Z eadler $");
 
 /**
  * @file
@@ -637,7 +638,7 @@
       SCIF_SAS_REQUEST_T      * request = NULL;
 
       // Cycle through the fast list of IO requests.  Terminate each
-      // oustanding requests that matches the criteria supplied by the
+      // outstanding requests that matches the criteria supplied by the
       // caller.
       while (element != NULL)
       {
@@ -1275,7 +1276,7 @@
    SCIC_TRANSPORT_PROTOCOL   protocol;
 
    // Cycle through the fast list of IO requests.  Terminate each
-   // oustanding requests that matches the criteria supplied by the
+   // outstanding requests that matches the criteria supplied by the
    // caller.
    while (element != NULL)
    {

Modified: trunk/sys/dev/isci/scil/scif_sas_domain.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_domain.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_domain.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_domain.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_DOMAIN_H_
 #define _SCIF_SAS_DOMAIN_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_domain_state_handlers.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_domain_state_handlers.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_domain_state_handlers.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_domain_state_handlers.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_domain_states.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_domain_states.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_domain_states.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_domain_states.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_high_priority_request_queue.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_high_priority_request_queue.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_high_priority_request_queue.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_high_priority_request_queue.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_high_priority_request_queue.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_high_priority_request_queue.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_high_priority_request_queue.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_high_priority_request_queue.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_HIGH_PRIORITY_REQUEST_QUEUE_H_
 #define _SCIF_SAS_HIGH_PRIORITY_REQUEST_QUEUE_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_internal_io_request.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_internal_io_request.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_internal_io_request.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_internal_io_request.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_internal_io_request.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_internal_io_request.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_internal_io_request.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_internal_io_request.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_INTERNAL_REQUEST_H_
 #define _SCIF_SAS_INTERNAL_REQUEST_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_io_request.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_io_request.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_io_request.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_io_request.c 231296 2012-02-09 17:50:24Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_io_request.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_io_request.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_io_request.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_io_request.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_IO_REQUEST_H_
 #define _SCIF_SAS_IO_REQUEST_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_io_request_state_handlers.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_io_request_state_handlers.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_io_request_state_handlers.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_io_request_state_handlers.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_io_request_states.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_io_request_states.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_io_request_states.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_io_request_states.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_library.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_library.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_library.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_library.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_library.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_library.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_library.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_library.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_LIBRARY_H_
 #define _SCIF_SAS_LIBRARY_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_logger.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_logger.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_logger.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_logger.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_LOGGER_H_
 #define _SCIF_SAS_LOGGER_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_remote_device.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_remote_device.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_remote_device.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_remote_device.c 231137 2012-02-07 17:45:11Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_remote_device.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_remote_device.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_remote_device.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_remote_device.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_REMOTE_DEVICE_H_
 #define _SCIF_SAS_REMOTE_DEVICE_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_remote_device_ready_substate_handlers.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_remote_device_ready_substate_handlers.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_remote_device_ready_substate_handlers.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_remote_device_ready_substate_handlers.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_remote_device_ready_substates.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_remote_device_ready_substates.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_remote_device_ready_substates.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_remote_device_ready_substates.c 231296 2012-02-09 17:50:24Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_remote_device_starting_substate_handlers.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_remote_device_starting_substate_handlers.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_remote_device_starting_substate_handlers.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_remote_device_starting_substate_handlers.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_remote_device_starting_substates.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_remote_device_starting_substates.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_remote_device_starting_substates.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_remote_device_starting_substates.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_remote_device_state_handlers.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_remote_device_state_handlers.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_remote_device_state_handlers.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_remote_device_state_handlers.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_remote_device_states.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_remote_device_states.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_remote_device_states.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_remote_device_states.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_request.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_request.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_request.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_request.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_request.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_request.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_request.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_request.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_REQUEST_H_
 #define _SCIF_SAS_REQUEST_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_sati_binding.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_sati_binding.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_sati_binding.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_sati_binding.h 239545 2012-08-21 22:28:14Z jimharris $
  */
 #ifndef _SCIF_SAS_SATI_BINDING_H_
 #define _SCIF_SAS_SATI_BINDING_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_smp_activity_clear_affiliation.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_smp_activity_clear_affiliation.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_smp_activity_clear_affiliation.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_smp_activity_clear_affiliation.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_smp_io_request.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_smp_io_request.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_smp_io_request.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_smp_io_request.c 231137 2012-02-07 17:45:11Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_smp_io_request.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_smp_io_request.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_smp_io_request.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_smp_io_request.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_SMP_REQUEST_H_
 #define _SCIF_SAS_SMP_REQUEST_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_smp_phy.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_smp_phy.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_smp_phy.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_smp_phy.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_smp_phy.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_smp_phy.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_smp_phy.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_smp_phy.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_SMP_PHY_H_
 #define _SCIF_SAS_SMP_PHY_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_smp_remote_device.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_smp_remote_device.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_smp_remote_device.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_smp_remote_device.c 231296 2012-02-09 17:50:24Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_smp_remote_device.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_smp_remote_device.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_smp_remote_device.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_smp_remote_device.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_SMP_REMOTE_DEVICE_H_
 #define _SCIF_SAS_SMP_REMOTE_DEVICE_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_stp_io_request.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_stp_io_request.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_stp_io_request.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_stp_io_request.c 239545 2012-08-21 22:28:14Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_stp_io_request.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_stp_io_request.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_stp_io_request.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_stp_io_request.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_STP_IO_REQUEST_H_
 #define _SCIF_SAS_STP_IO_REQUEST_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_stp_remote_device.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_stp_remote_device.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_stp_remote_device.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_stp_remote_device.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_stp_remote_device.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_stp_remote_device.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_stp_remote_device.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_stp_remote_device.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_STP_REMOTE_DEVICE_H_
 #define _SCIF_SAS_STP_REMOTE_DEVICE_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_stp_task_request.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_stp_task_request.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_stp_task_request.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_stp_task_request.c 231296 2012-02-09 17:50:24Z jimharris $");
 
 #include <dev/isci/scil/sati.h>
 #include <dev/isci/scil/scif_sas_logger.h>

Modified: trunk/sys/dev/isci/scil/scif_sas_stp_task_request.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_stp_task_request.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_stp_task_request.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_stp_task_request.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_STP_TASK_REQUEST_H_
 #define _SCIF_SAS_STP_TASK_REQUEST_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_task_request.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_task_request.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_task_request.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_task_request.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_task_request.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_task_request.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_task_request.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_task_request.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_SAS_TASK_REQUEST_H_
 #define _SCIF_SAS_TASK_REQUEST_H_

Modified: trunk/sys/dev/isci/scil/scif_sas_task_request_state_handlers.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_task_request_state_handlers.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_task_request_state_handlers.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_task_request_state_handlers.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_task_request_states.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_task_request_states.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_task_request_states.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_task_request_states.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_sas_timer.c
===================================================================
--- trunk/sys/dev/isci/scil/scif_sas_timer.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_sas_timer.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -51,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/dev/isci/scil/scif_sas_timer.c 231136 2012-02-07 17:43:58Z jimharris $");
 
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scif_task_request.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_task_request.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_task_request.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_task_request.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_TASK_REQUEST_H_
 #define _SCIF_TASK_REQUEST_H_

Modified: trunk/sys/dev/isci/scil/scif_user_callback.h
===================================================================
--- trunk/sys/dev/isci/scil/scif_user_callback.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scif_user_callback.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scif_user_callback.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCIF_USER_CALLBACK_H_
 #define _SCIF_USER_CALLBACK_H_

Modified: trunk/sys/dev/isci/scil/scu_bios_definitions.h
===================================================================
--- trunk/sys/dev/isci/scil/scu_bios_definitions.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scu_bios_definitions.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scu_bios_definitions.h 240518 2012-09-14 21:28:56Z eadler $
  */
 #ifndef _SCU_BIOS_DEFINITIONS_H_
 #define _SCU_BIOS_DEFINITIONS_H_

Modified: trunk/sys/dev/isci/scil/scu_completion_codes.h
===================================================================
--- trunk/sys/dev/isci/scil/scu_completion_codes.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scu_completion_codes.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scu_completion_codes.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCU_COMPLETION_CODES_HEADER_
 #define _SCU_COMPLETION_CODES_HEADER_

Modified: trunk/sys/dev/isci/scil/scu_constants.h
===================================================================
--- trunk/sys/dev/isci/scil/scu_constants.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scu_constants.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scu_constants.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCU_CONSTANTS_H_
 #define _SCU_CONSTANTS_H_

Modified: trunk/sys/dev/isci/scil/scu_event_codes.h
===================================================================
--- trunk/sys/dev/isci/scil/scu_event_codes.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scu_event_codes.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scu_event_codes.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef __SCU_EVENT_CODES_HEADER__
 #define __SCU_EVENT_CODES_HEADER__

Modified: trunk/sys/dev/isci/scil/scu_registers.h
===================================================================
--- trunk/sys/dev/isci/scil/scu_registers.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scu_registers.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scu_registers.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCU_REGISTERS_H_
 #define _SCU_REGISTERS_H_

Modified: trunk/sys/dev/isci/scil/scu_remote_node_context.h
===================================================================
--- trunk/sys/dev/isci/scil/scu_remote_node_context.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scu_remote_node_context.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scu_remote_node_context.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef __SCU_REMOTE_NODE_CONTEXT_HEADER__
 #define __SCU_REMOTE_NODE_CONTEXT_HEADER__

Modified: trunk/sys/dev/isci/scil/scu_task_context.h
===================================================================
--- trunk/sys/dev/isci/scil/scu_task_context.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scu_task_context.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scu_task_context.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCU_TASK_CONTEXT_H_
 #define _SCU_TASK_CONTEXT_H_

Modified: trunk/sys/dev/isci/scil/scu_unsolicited_frame.h
===================================================================
--- trunk/sys/dev/isci/scil/scu_unsolicited_frame.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scu_unsolicited_frame.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scu_unsolicited_frame.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 /**
  * @file

Modified: trunk/sys/dev/isci/scil/scu_viit_data.h
===================================================================
--- trunk/sys/dev/isci/scil/scu_viit_data.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/scil/scu_viit_data.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * This file is provided under a dual BSD/GPLv2 license.  When using or
  * redistributing this file, you may do so under either license.
@@ -49,7 +50,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/scil/scu_viit_data.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _SCU_VIIT_DATA_HEADER_
 #define _SCU_VIIT_DATA_HEADER_

Modified: trunk/sys/dev/isci/types.h
===================================================================
--- trunk/sys/dev/isci/types.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/isci/types.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * BSD LICENSE
  *
@@ -27,7 +28,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/dev/isci/types.h 231136 2012-02-07 17:43:58Z jimharris $
  */
 #ifndef _DRIVER_INCLUDE_TYPES_H_
 #define _DRIVER_INCLUDE_TYPES_H_

Added: trunk/sys/dev/iscsi/icl.c
===================================================================
--- trunk/sys/dev/iscsi/icl.c	                        (rev 0)
+++ trunk/sys/dev/iscsi/icl.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -0,0 +1,1468 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2012 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Edward Tomasz Napierala under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/*
+ * iSCSI Common Layer.  It's used by both the initiator and target to send
+ * and receive iSCSI PDUs.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/sys/dev/iscsi/icl.c 307378 2016-10-15 17:39:40Z mav $");
+
+#include <sys/param.h>
+#include <sys/capsicum.h>
+#include <sys/condvar.h>
+#include <sys/conf.h>
+#include <sys/file.h>
+#include <sys/kernel.h>
+#include <sys/kthread.h>
+#include <sys/lock.h>
+#include <sys/mbuf.h>
+#include <sys/mutex.h>
+#include <sys/module.h>
+#include <sys/protosw.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/sysctl.h>
+#include <sys/systm.h>
+#include <sys/sx.h>
+#include <sys/uio.h>
+#include <vm/uma.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+
+#include <dev/iscsi/icl.h>
+#include <dev/iscsi/iscsi_proto.h>
+
+SYSCTL_NODE(_kern, OID_AUTO, icl, CTLFLAG_RD, 0, "iSCSI Common Layer");
+static int debug = 1;
+TUNABLE_INT("kern.icl.debug", &debug);
+SYSCTL_INT(_kern_icl, OID_AUTO, debug, CTLFLAG_RWTUN,
+    &debug, 0, "Enable debug messages");
+static int coalesce = 1;
+TUNABLE_INT("kern.icl.coalesce", &coalesce);
+SYSCTL_INT(_kern_icl, OID_AUTO, coalesce, CTLFLAG_RWTUN,
+    &coalesce, 0, "Try to coalesce PDUs before sending");
+static int partial_receive_len = 128 * 1024;
+TUNABLE_INT("kern.icl.partial_receive_len", &partial_receive_len);
+SYSCTL_INT(_kern_icl, OID_AUTO, partial_receive_len, CTLFLAG_RWTUN,
+    &partial_receive_len, 0, "Minimum read size for partially received "
+    "data segment");
+static int sendspace = 1048576;
+TUNABLE_INT("kern.icl.sendspace", &sendspace);
+SYSCTL_INT(_kern_icl, OID_AUTO, sendspace, CTLFLAG_RWTUN,
+    &sendspace, 0, "Default send socket buffer size");
+static int recvspace = 1048576;
+TUNABLE_INT("kern.icl.recvspace", &recvspace);
+SYSCTL_INT(_kern_icl, OID_AUTO, recvspace, CTLFLAG_RWTUN,
+    &recvspace, 0, "Default receive socket buffer size");
+
+static uma_zone_t icl_conn_zone;
+static uma_zone_t icl_pdu_zone;
+
+static volatile u_int	icl_ncons;
+
+#define	ICL_DEBUG(X, ...)						\
+	do {								\
+		if (debug > 1)						\
+			printf("%s: " X "\n", __func__, ## __VA_ARGS__);\
+	} while (0)
+
+#define	ICL_WARN(X, ...)						\
+	do {								\
+		if (debug > 0) {					\
+			printf("WARNING: %s: " X "\n",			\
+			    __func__, ## __VA_ARGS__);			\
+		}							\
+	} while (0)
+
+#define ICL_CONN_LOCK(X)		mtx_lock(X->ic_lock)
+#define ICL_CONN_UNLOCK(X)		mtx_unlock(X->ic_lock)
+#define ICL_CONN_LOCK_ASSERT(X)		mtx_assert(X->ic_lock, MA_OWNED)
+#define ICL_CONN_LOCK_ASSERT_NOT(X)	mtx_assert(X->ic_lock, MA_NOTOWNED)
+
+STAILQ_HEAD(icl_pdu_stailq, icl_pdu);
+
+static void
+icl_conn_fail(struct icl_conn *ic)
+{
+	if (ic->ic_socket == NULL)
+		return;
+
+	/*
+	 * XXX
+	 */
+	ic->ic_socket->so_error = EDOOFUS;
+	(ic->ic_error)(ic);
+}
+
+static struct mbuf *
+icl_conn_receive(struct icl_conn *ic, size_t len)
+{
+	struct uio uio;
+	struct socket *so;
+	struct mbuf *m;
+	int error, flags;
+
+	so = ic->ic_socket;
+
+	memset(&uio, 0, sizeof(uio));
+	uio.uio_resid = len;
+
+	flags = MSG_DONTWAIT;
+	error = soreceive(so, NULL, &uio, &m, NULL, &flags);
+	if (error != 0) {
+		ICL_DEBUG("soreceive error %d", error);
+		return (NULL);
+	}
+	if (uio.uio_resid != 0) {
+		m_freem(m);
+		ICL_DEBUG("short read");
+		return (NULL);
+	}
+
+	return (m);
+}
+
+static struct icl_pdu *
+icl_pdu_new_empty(struct icl_conn *ic, int flags)
+{
+	struct icl_pdu *ip;
+
+#ifdef DIAGNOSTIC
+	refcount_acquire(&ic->ic_outstanding_pdus);
+#endif
+	ip = uma_zalloc(icl_pdu_zone, flags | M_ZERO);
+	if (ip == NULL) {
+		ICL_WARN("failed to allocate %zd bytes", sizeof(*ip));
+#ifdef DIAGNOSTIC
+		refcount_release(&ic->ic_outstanding_pdus);
+#endif
+		return (NULL);
+	}
+
+	ip->ip_conn = ic;
+
+	return (ip);
+}
+
+void
+icl_pdu_free(struct icl_pdu *ip)
+{
+	struct icl_conn *ic;
+
+	ic = ip->ip_conn;
+
+	m_freem(ip->ip_bhs_mbuf);
+	m_freem(ip->ip_ahs_mbuf);
+	m_freem(ip->ip_data_mbuf);
+	uma_zfree(icl_pdu_zone, ip);
+#ifdef DIAGNOSTIC
+	refcount_release(&ic->ic_outstanding_pdus);
+#endif
+}
+
+/*
+ * Allocate icl_pdu with empty BHS to fill up by the caller.
+ */
+struct icl_pdu *
+icl_pdu_new(struct icl_conn *ic, int flags)
+{
+	struct icl_pdu *ip;
+
+	ip = icl_pdu_new_empty(ic, flags);
+	if (ip == NULL)
+		return (NULL);
+
+	ip->ip_bhs_mbuf = m_getm2(NULL, sizeof(struct iscsi_bhs),
+	    flags, MT_DATA, M_PKTHDR);
+	if (ip->ip_bhs_mbuf == NULL) {
+		ICL_WARN("failed to allocate %zd bytes", sizeof(*ip));
+		icl_pdu_free(ip);
+		return (NULL);
+	}
+	ip->ip_bhs = mtod(ip->ip_bhs_mbuf, struct iscsi_bhs *);
+	memset(ip->ip_bhs, 0, sizeof(struct iscsi_bhs));
+	ip->ip_bhs_mbuf->m_len = sizeof(struct iscsi_bhs);
+
+	return (ip);
+}
+
+static int
+icl_pdu_ahs_length(const struct icl_pdu *request)
+{
+
+	return (request->ip_bhs->bhs_total_ahs_len * 4);
+}
+
+size_t
+icl_pdu_data_segment_length(const struct icl_pdu *request)
+{
+	uint32_t len = 0;
+
+	len += request->ip_bhs->bhs_data_segment_len[0];
+	len <<= 8;
+	len += request->ip_bhs->bhs_data_segment_len[1];
+	len <<= 8;
+	len += request->ip_bhs->bhs_data_segment_len[2];
+
+	return (len);
+}
+
+static void
+icl_pdu_set_data_segment_length(struct icl_pdu *response, uint32_t len)
+{
+
+	response->ip_bhs->bhs_data_segment_len[2] = len;
+	response->ip_bhs->bhs_data_segment_len[1] = len >> 8;
+	response->ip_bhs->bhs_data_segment_len[0] = len >> 16;
+}
+
+static size_t
+icl_pdu_padding(const struct icl_pdu *ip)
+{
+
+	if ((ip->ip_data_len % 4) != 0)
+		return (4 - (ip->ip_data_len % 4));
+
+	return (0);
+}
+
+static size_t
+icl_pdu_size(const struct icl_pdu *response)
+{
+	size_t len;
+
+	KASSERT(response->ip_ahs_len == 0, ("responding with AHS"));
+
+	len = sizeof(struct iscsi_bhs) + response->ip_data_len +
+	    icl_pdu_padding(response);
+	if (response->ip_conn->ic_header_crc32c)
+		len += ISCSI_HEADER_DIGEST_SIZE;
+	if (response->ip_data_len != 0 && response->ip_conn->ic_data_crc32c)
+		len += ISCSI_DATA_DIGEST_SIZE;
+
+	return (len);
+}
+
+static int
+icl_pdu_receive_bhs(struct icl_pdu *request, size_t *availablep)
+{
+	struct mbuf *m;
+
+	m = icl_conn_receive(request->ip_conn, sizeof(struct iscsi_bhs));
+	if (m == NULL) {
+		ICL_DEBUG("failed to receive BHS");
+		return (-1);
+	}
+
+	request->ip_bhs_mbuf = m_pullup(m, sizeof(struct iscsi_bhs));
+	if (request->ip_bhs_mbuf == NULL) {
+		ICL_WARN("m_pullup failed");
+		return (-1);
+	}
+	request->ip_bhs = mtod(request->ip_bhs_mbuf, struct iscsi_bhs *);
+
+	/*
+	 * XXX: For architectures with strict alignment requirements
+	 * 	we may need to allocate ip_bhs and copy the data into it.
+	 * 	For some reason, though, not doing this doesn't seem
+	 * 	to cause problems; tested on sparc64.
+	 */
+
+	*availablep -= sizeof(struct iscsi_bhs);
+	return (0);
+}
+
+static int
+icl_pdu_receive_ahs(struct icl_pdu *request, size_t *availablep)
+{
+
+	request->ip_ahs_len = icl_pdu_ahs_length(request);
+	if (request->ip_ahs_len == 0)
+		return (0);
+
+	request->ip_ahs_mbuf = icl_conn_receive(request->ip_conn,
+	    request->ip_ahs_len);
+	if (request->ip_ahs_mbuf == NULL) {
+		ICL_DEBUG("failed to receive AHS");
+		return (-1);
+	}
+
+	*availablep -= request->ip_ahs_len;
+	return (0);
+}
+
+static uint32_t
+icl_mbuf_to_crc32c(const struct mbuf *m0)
+{
+	uint32_t digest = 0xffffffff;
+	const struct mbuf *m;
+
+	for (m = m0; m != NULL; m = m->m_next)
+		digest = calculate_crc32c(digest,
+		    mtod(m, const void *), m->m_len);
+
+	digest = digest ^ 0xffffffff;
+
+	return (digest);
+}
+
+static int
+icl_pdu_check_header_digest(struct icl_pdu *request, size_t *availablep)
+{
+	struct mbuf *m;
+	uint32_t received_digest, valid_digest;
+
+	if (request->ip_conn->ic_header_crc32c == false)
+		return (0);
+
+	m = icl_conn_receive(request->ip_conn, ISCSI_HEADER_DIGEST_SIZE);
+	if (m == NULL) {
+		ICL_DEBUG("failed to receive header digest");
+		return (-1);
+	}
+
+	CTASSERT(sizeof(received_digest) == ISCSI_HEADER_DIGEST_SIZE);
+	m_copydata(m, 0, ISCSI_HEADER_DIGEST_SIZE, (void *)&received_digest);
+	m_freem(m);
+
+	*availablep -= ISCSI_HEADER_DIGEST_SIZE;
+
+	/*
+	 * XXX: Handle AHS.
+	 */
+	valid_digest = icl_mbuf_to_crc32c(request->ip_bhs_mbuf);
+	if (received_digest != valid_digest) {
+		ICL_WARN("header digest check failed; got 0x%x, "
+		    "should be 0x%x", received_digest, valid_digest);
+		return (-1);
+	}
+
+	return (0);
+}
+
+/*
+ * Return the number of bytes that should be waiting in the receive socket
+ * before icl_pdu_receive_data_segment() gets called.
+ */
+static size_t
+icl_pdu_data_segment_receive_len(const struct icl_pdu *request)
+{
+	size_t len;
+
+	len = icl_pdu_data_segment_length(request);
+	if (len == 0)
+		return (0);
+
+	/*
+	 * Account for the parts of data segment already read from
+	 * the socket buffer.
+	 */
+	KASSERT(len > request->ip_data_len, ("len <= request->ip_data_len"));
+	len -= request->ip_data_len;
+
+	/*
+	 * Don't always wait for the full data segment to be delivered
+	 * to the socket; this might badly affect performance due to
+	 * TCP window scaling.
+	 */
+	if (len > partial_receive_len) {
+#if 0
+		ICL_DEBUG("need %zd bytes of data, limiting to %zd",
+		    len, partial_receive_len));
+#endif
+		len = partial_receive_len;
+
+		return (len);
+	}
+
+	/*
+	 * Account for padding.  Note that due to the way code is written,
+	 * the icl_pdu_receive_data_segment() must always receive padding
+	 * along with the last part of data segment, because it would be
+	 * impossible to tell whether we've already received the full data
+	 * segment including padding, or without it.
+	 */
+	if ((len % 4) != 0)
+		len += 4 - (len % 4);
+
+#if 0
+	ICL_DEBUG("need %zd bytes of data", len));
+#endif
+
+	return (len);
+}
+
+static int
+icl_pdu_receive_data_segment(struct icl_pdu *request,
+    size_t *availablep, bool *more_neededp)
+{
+	struct icl_conn *ic;
+	size_t len, padding = 0;
+	struct mbuf *m;
+
+	ic = request->ip_conn;
+
+	*more_neededp = false;
+	ic->ic_receive_len = 0;
+
+	len = icl_pdu_data_segment_length(request);
+	if (len == 0)
+		return (0);
+
+	if ((len % 4) != 0)
+		padding = 4 - (len % 4);
+
+	/*
+	 * Account for already received parts of data segment.
+	 */
+	KASSERT(len > request->ip_data_len, ("len <= request->ip_data_len"));
+	len -= request->ip_data_len;
+
+	if (len + padding > *availablep) {
+		/*
+		 * Not enough data in the socket buffer.  Receive as much
+		 * as we can.  Don't receive padding, since, obviously, it's
+		 * not the end of data segment yet.
+		 */
+#if 0
+		ICL_DEBUG("limited from %zd to %zd",
+		    len + padding, *availablep - padding));
+#endif
+		len = *availablep - padding;
+		*more_neededp = true;
+		padding = 0;
+	}
+
+	/*
+	 * Must not try to receive padding without at least one byte
+	 * of actual data segment.
+	 */
+	if (len > 0) {
+		m = icl_conn_receive(request->ip_conn, len + padding);
+		if (m == NULL) {
+			ICL_DEBUG("failed to receive data segment");
+			return (-1);
+		}
+
+		if (request->ip_data_mbuf == NULL)
+			request->ip_data_mbuf = m;
+		else
+			m_cat(request->ip_data_mbuf, m);
+
+		request->ip_data_len += len;
+		*availablep -= len + padding;
+	} else
+		ICL_DEBUG("len 0");
+
+	if (*more_neededp)
+		ic->ic_receive_len =
+		    icl_pdu_data_segment_receive_len(request);
+
+	return (0);
+}
+
+static int
+icl_pdu_check_data_digest(struct icl_pdu *request, size_t *availablep)
+{
+	struct mbuf *m;
+	uint32_t received_digest, valid_digest;
+
+	if (request->ip_conn->ic_data_crc32c == false)
+		return (0);
+
+	if (request->ip_data_len == 0)
+		return (0);
+
+	m = icl_conn_receive(request->ip_conn, ISCSI_DATA_DIGEST_SIZE);
+	if (m == NULL) {
+		ICL_DEBUG("failed to receive data digest");
+		return (-1);
+	}
+
+	CTASSERT(sizeof(received_digest) == ISCSI_DATA_DIGEST_SIZE);
+	m_copydata(m, 0, ISCSI_DATA_DIGEST_SIZE, (void *)&received_digest);
+	m_freem(m);
+
+	*availablep -= ISCSI_DATA_DIGEST_SIZE;
+
+	/*
+	 * Note that ip_data_mbuf also contains padding; since digest
+	 * calculation is supposed to include that, we iterate over
+	 * the entire ip_data_mbuf chain, not just ip_data_len bytes of it.
+	 */
+	valid_digest = icl_mbuf_to_crc32c(request->ip_data_mbuf);
+	if (received_digest != valid_digest) {
+		ICL_WARN("data digest check failed; got 0x%x, "
+		    "should be 0x%x", received_digest, valid_digest);
+		return (-1);
+	}
+
+	return (0);
+}
+
+/*
+ * Somewhat contrary to the name, this attempts to receive only one
+ * "part" of PDU at a time; call it repeatedly until it returns non-NULL.
+ */
+static struct icl_pdu *
+icl_conn_receive_pdu(struct icl_conn *ic, size_t *availablep)
+{
+	struct icl_pdu *request;
+	struct socket *so;
+	size_t len;
+	int error;
+	bool more_needed;
+
+	so = ic->ic_socket;
+
+	if (ic->ic_receive_state == ICL_CONN_STATE_BHS) {
+		KASSERT(ic->ic_receive_pdu == NULL,
+		    ("ic->ic_receive_pdu != NULL"));
+		request = icl_pdu_new_empty(ic, M_NOWAIT);
+		if (request == NULL) {
+			ICL_DEBUG("failed to allocate PDU; "
+			    "dropping connection");
+			icl_conn_fail(ic);
+			return (NULL);
+		}
+		ic->ic_receive_pdu = request;
+	} else {
+		KASSERT(ic->ic_receive_pdu != NULL,
+		    ("ic->ic_receive_pdu == NULL"));
+		request = ic->ic_receive_pdu;
+	}
+
+	if (*availablep < ic->ic_receive_len) {
+#if 0
+		ICL_DEBUG("not enough data; need %zd, "
+		    "have %zd", ic->ic_receive_len, *availablep);
+#endif
+		return (NULL);
+	}
+
+	switch (ic->ic_receive_state) {
+	case ICL_CONN_STATE_BHS:
+		//ICL_DEBUG("receiving BHS");
+		error = icl_pdu_receive_bhs(request, availablep);
+		if (error != 0) {
+			ICL_DEBUG("failed to receive BHS; "
+			    "dropping connection");
+			break;
+		}
+
+		/*
+		 * We don't enforce any limit for AHS length;
+		 * its length is stored in 8 bit field.
+		 */
+
+		len = icl_pdu_data_segment_length(request);
+		if (len > ic->ic_max_data_segment_length) {
+			ICL_WARN("received data segment "
+			    "length %zd is larger than negotiated "
+			    "MaxDataSegmentLength %zd; "
+			    "dropping connection",
+			    len, ic->ic_max_data_segment_length);
+			error = EINVAL;
+			break;
+		}
+
+		ic->ic_receive_state = ICL_CONN_STATE_AHS;
+		ic->ic_receive_len = icl_pdu_ahs_length(request);
+		break;
+
+	case ICL_CONN_STATE_AHS:
+		//ICL_DEBUG("receiving AHS");
+		error = icl_pdu_receive_ahs(request, availablep);
+		if (error != 0) {
+			ICL_DEBUG("failed to receive AHS; "
+			    "dropping connection");
+			break;
+		}
+		ic->ic_receive_state = ICL_CONN_STATE_HEADER_DIGEST;
+		if (ic->ic_header_crc32c == false)
+			ic->ic_receive_len = 0;
+		else
+			ic->ic_receive_len = ISCSI_HEADER_DIGEST_SIZE;
+		break;
+
+	case ICL_CONN_STATE_HEADER_DIGEST:
+		//ICL_DEBUG("receiving header digest");
+		error = icl_pdu_check_header_digest(request, availablep);
+		if (error != 0) {
+			ICL_DEBUG("header digest failed; "
+			    "dropping connection");
+			break;
+		}
+
+		ic->ic_receive_state = ICL_CONN_STATE_DATA;
+		ic->ic_receive_len =
+		    icl_pdu_data_segment_receive_len(request);
+		break;
+
+	case ICL_CONN_STATE_DATA:
+		//ICL_DEBUG("receiving data segment");
+		error = icl_pdu_receive_data_segment(request, availablep,
+		    &more_needed);
+		if (error != 0) {
+			ICL_DEBUG("failed to receive data segment;"
+			    "dropping connection");
+			break;
+		}
+
+		if (more_needed)
+			break;
+
+		ic->ic_receive_state = ICL_CONN_STATE_DATA_DIGEST;
+		if (request->ip_data_len == 0 || ic->ic_data_crc32c == false)
+			ic->ic_receive_len = 0;
+		else
+			ic->ic_receive_len = ISCSI_DATA_DIGEST_SIZE;
+		break;
+
+	case ICL_CONN_STATE_DATA_DIGEST:
+		//ICL_DEBUG("receiving data digest");
+		error = icl_pdu_check_data_digest(request, availablep);
+		if (error != 0) {
+			ICL_DEBUG("data digest failed; "
+			    "dropping connection");
+			break;
+		}
+
+		/*
+		 * We've received complete PDU; reset the receive state machine
+		 * and return the PDU.
+		 */
+		ic->ic_receive_state = ICL_CONN_STATE_BHS;
+		ic->ic_receive_len = sizeof(struct iscsi_bhs);
+		ic->ic_receive_pdu = NULL;
+		return (request);
+
+	default:
+		panic("invalid ic_receive_state %d\n", ic->ic_receive_state);
+	}
+
+	if (error != 0) {
+		/*
+		 * Don't free the PDU; it's pointed to by ic->ic_receive_pdu
+		 * and will get freed in icl_conn_close().
+		 */
+		icl_conn_fail(ic);
+	}
+
+	return (NULL);
+}
+
+static void
+icl_conn_receive_pdus(struct icl_conn *ic, size_t available)
+{
+	struct icl_pdu *response;
+	struct socket *so;
+
+	so = ic->ic_socket;
+
+	/*
+	 * This can never happen; we're careful to only mess with ic->ic_socket
+	 * pointer when the send/receive threads are not running.
+	 */
+	KASSERT(so != NULL, ("NULL socket"));
+
+	for (;;) {
+		if (ic->ic_disconnecting)
+			return;
+
+		if (so->so_error != 0) {
+			ICL_DEBUG("connection error %d; "
+			    "dropping connection", so->so_error);
+			icl_conn_fail(ic);
+			return;
+		}
+
+		/*
+		 * Loop until we have a complete PDU or there is not enough
+		 * data in the socket buffer.
+		 */
+		if (available < ic->ic_receive_len) {
+#if 0
+			ICL_DEBUG("not enough data; have %zd, "
+			    "need %zd", available,
+			    ic->ic_receive_len);
+#endif
+			return;
+		}
+
+		response = icl_conn_receive_pdu(ic, &available);
+		if (response == NULL)
+			continue;
+
+		if (response->ip_ahs_len > 0) {
+			ICL_WARN("received PDU with unsupported "
+			    "AHS; opcode 0x%x; dropping connection",
+			    response->ip_bhs->bhs_opcode);
+			icl_pdu_free(response);
+			icl_conn_fail(ic);
+			return;
+		}
+
+		(ic->ic_receive)(response);
+	}
+}
+
+static void
+icl_receive_thread(void *arg)
+{
+	struct icl_conn *ic;
+	size_t available;
+	struct socket *so;
+
+	ic = arg;
+	so = ic->ic_socket;
+
+	for (;;) {
+		if (ic->ic_disconnecting) {
+			//ICL_DEBUG("terminating");
+			break;
+		}
+
+		/*
+		 * Set the low watermark, to be checked by
+		 * soreadable() in icl_soupcall_receive()
+		 * to avoid unneccessary wakeups until there
+		 * is enough data received to read the PDU.
+		 */
+		SOCKBUF_LOCK(&so->so_rcv);
+		available = so->so_rcv.sb_cc;
+		if (available < ic->ic_receive_len) {
+			so->so_rcv.sb_lowat = ic->ic_receive_len;
+			cv_wait(&ic->ic_receive_cv, &so->so_rcv.sb_mtx);
+		} else
+			so->so_rcv.sb_lowat = so->so_rcv.sb_hiwat + 1;
+		SOCKBUF_UNLOCK(&so->so_rcv);
+
+		icl_conn_receive_pdus(ic, available);
+	}
+
+	ICL_CONN_LOCK(ic);
+	ic->ic_receive_running = false;
+	cv_signal(&ic->ic_send_cv);
+	ICL_CONN_UNLOCK(ic);
+	kthread_exit();
+}
+
+static int
+icl_soupcall_receive(struct socket *so, void *arg, int waitflag)
+{
+	struct icl_conn *ic;
+
+	if (!soreadable(so))
+		return (SU_OK);
+
+	ic = arg;
+	cv_signal(&ic->ic_receive_cv);
+	return (SU_OK);
+}
+
+static int
+icl_pdu_finalize(struct icl_pdu *request)
+{
+	size_t padding, pdu_len;
+	uint32_t digest, zero = 0;
+	int ok;
+	struct icl_conn *ic;
+
+	ic = request->ip_conn;
+
+	icl_pdu_set_data_segment_length(request, request->ip_data_len);
+
+	pdu_len = icl_pdu_size(request);
+
+	if (ic->ic_header_crc32c) {
+		digest = icl_mbuf_to_crc32c(request->ip_bhs_mbuf);
+		ok = m_append(request->ip_bhs_mbuf, sizeof(digest),
+		    (void *)&digest);
+		if (ok != 1) {
+			ICL_WARN("failed to append header digest");
+			return (1);
+		}
+	}
+
+	if (request->ip_data_len != 0) {
+		padding = icl_pdu_padding(request);
+		if (padding > 0) {
+			ok = m_append(request->ip_data_mbuf, padding,
+			    (void *)&zero);
+			if (ok != 1) {
+				ICL_WARN("failed to append padding");
+				return (1);
+			}
+		}
+
+		if (ic->ic_data_crc32c) {
+			digest = icl_mbuf_to_crc32c(request->ip_data_mbuf);
+
+			ok = m_append(request->ip_data_mbuf, sizeof(digest),
+			    (void *)&digest);
+			if (ok != 1) {
+				ICL_WARN("failed to append data digest");
+				return (1);
+			}
+		}
+
+		m_cat(request->ip_bhs_mbuf, request->ip_data_mbuf);
+		request->ip_data_mbuf = NULL;
+	}
+
+	request->ip_bhs_mbuf->m_pkthdr.len = pdu_len;
+
+	return (0);
+}
+
+static void
+icl_conn_send_pdus(struct icl_conn *ic, struct icl_pdu_stailq *queue)
+{
+	struct icl_pdu *request, *request2;
+	struct socket *so;
+	size_t available, size, size2;
+	int coalesced, error;
+
+	ICL_CONN_LOCK_ASSERT_NOT(ic);
+
+	so = ic->ic_socket;
+
+	SOCKBUF_LOCK(&so->so_snd);
+	/*
+	 * Check how much space do we have for transmit.  We can't just
+	 * call sosend() and retry when we get EWOULDBLOCK or EMSGSIZE,
+	 * as it always frees the mbuf chain passed to it, even in case
+	 * of error.
+	 */
+	available = sbspace(&so->so_snd);
+
+	/*
+	 * Notify the socket upcall that we don't need wakeups
+	 * for the time being.
+	 */
+	so->so_snd.sb_lowat = so->so_snd.sb_hiwat + 1;
+	SOCKBUF_UNLOCK(&so->so_snd);
+
+	while (!STAILQ_EMPTY(queue)) {
+		request = STAILQ_FIRST(queue);
+		size = icl_pdu_size(request);
+		if (available < size) {
+
+			/*
+			 * Set the low watermark, to be checked by
+			 * sowriteable() in icl_soupcall_send()
+			 * to avoid unneccessary wakeups until there
+			 * is enough space for the PDU to fit.
+			 */
+			SOCKBUF_LOCK(&so->so_snd);
+			available = sbspace(&so->so_snd);
+			if (available < size) {
+#if 1
+				ICL_DEBUG("no space to send; "
+				    "have %zd, need %zd",
+				    available, size);
+#endif
+				so->so_snd.sb_lowat = size;
+				SOCKBUF_UNLOCK(&so->so_snd);
+				return;
+			}
+			SOCKBUF_UNLOCK(&so->so_snd);
+		}
+		STAILQ_REMOVE_HEAD(queue, ip_next);
+		error = icl_pdu_finalize(request);
+		if (error != 0) {
+			ICL_DEBUG("failed to finalize PDU; "
+			    "dropping connection");
+			icl_conn_fail(ic);
+			icl_pdu_free(request);
+			return;
+		}
+		if (coalesce) {
+			coalesced = 1;
+			for (;;) {
+				request2 = STAILQ_FIRST(queue);
+				if (request2 == NULL)
+					break;
+				size2 = icl_pdu_size(request2);
+				if (available < size + size2)
+					break;
+				STAILQ_REMOVE_HEAD(queue, ip_next);
+				error = icl_pdu_finalize(request2);
+				if (error != 0) {
+					ICL_DEBUG("failed to finalize PDU; "
+					    "dropping connection");
+					icl_conn_fail(ic);
+					icl_pdu_free(request);
+					icl_pdu_free(request2);
+					return;
+				}
+				m_cat(request->ip_bhs_mbuf, request2->ip_bhs_mbuf);
+				request2->ip_bhs_mbuf = NULL;
+				request->ip_bhs_mbuf->m_pkthdr.len += size2;
+				size += size2;
+				STAILQ_REMOVE_AFTER(queue, request, ip_next);
+				icl_pdu_free(request2);
+				coalesced++;
+			}
+#if 0
+			if (coalesced > 1) {
+				ICL_DEBUG("coalesced %d PDUs into %zd bytes",
+				    coalesced, size);
+			}
+#endif
+		}
+		available -= size;
+		error = sosend(so, NULL, NULL, request->ip_bhs_mbuf,
+		    NULL, MSG_DONTWAIT, curthread);
+		request->ip_bhs_mbuf = NULL; /* Sosend consumes the mbuf. */
+		if (error != 0) {
+			ICL_DEBUG("failed to send PDU, error %d; "
+			    "dropping connection", error);
+			icl_conn_fail(ic);
+			icl_pdu_free(request);
+			return;
+		}
+		icl_pdu_free(request);
+	}
+}
+
+static void
+icl_send_thread(void *arg)
+{
+	struct icl_conn *ic;
+	struct icl_pdu_stailq queue;
+
+	ic = arg;
+
+	STAILQ_INIT(&queue);
+
+	ICL_CONN_LOCK(ic);
+	for (;;) {
+		for (;;) {
+			/*
+			 * If the local queue is empty, populate it from
+			 * the main one.  This way the icl_conn_send_pdus()
+			 * can go through all the queued PDUs without holding
+			 * any locks.
+			 */
+			if (STAILQ_EMPTY(&queue))
+				STAILQ_SWAP(&ic->ic_to_send, &queue, icl_pdu);
+
+			ic->ic_check_send_space = false;
+			ICL_CONN_UNLOCK(ic);
+			icl_conn_send_pdus(ic, &queue);
+			ICL_CONN_LOCK(ic);
+
+			/*
+			 * The icl_soupcall_send() was called since the last
+			 * call to sbspace(); go around;
+			 */
+			if (ic->ic_check_send_space)
+				continue;
+
+			/*
+			 * Local queue is empty, but we still have PDUs
+			 * in the main one; go around.
+			 */
+			if (STAILQ_EMPTY(&queue) &&
+			    !STAILQ_EMPTY(&ic->ic_to_send))
+				continue;
+
+			/*
+			 * There might be some stuff in the local queue,
+			 * which didn't get sent due to not having enough send
+			 * space.  Wait for socket upcall.
+			 */
+			break;
+		}
+
+		if (ic->ic_disconnecting) {
+			//ICL_DEBUG("terminating");
+			break;
+		}
+
+		cv_wait(&ic->ic_send_cv, ic->ic_lock);
+	}
+
+	/*
+	 * We're exiting; move PDUs back to the main queue, so they can
+	 * get freed properly.  At this point ordering doesn't matter.
+	 */
+	STAILQ_CONCAT(&ic->ic_to_send, &queue);
+
+	ic->ic_send_running = false;
+	cv_signal(&ic->ic_send_cv);
+	ICL_CONN_UNLOCK(ic);
+	kthread_exit();
+}
+
+static int
+icl_soupcall_send(struct socket *so, void *arg, int waitflag)
+{
+	struct icl_conn *ic;
+
+	if (!sowriteable(so))
+		return (SU_OK);
+
+	ic = arg;
+
+	ICL_CONN_LOCK(ic);
+	ic->ic_check_send_space = true;
+	ICL_CONN_UNLOCK(ic);
+
+	cv_signal(&ic->ic_send_cv);
+
+	return (SU_OK);
+}
+
+int
+icl_pdu_append_data(struct icl_pdu *request, const void *addr, size_t len,
+    int flags)
+{
+	struct mbuf *mb, *newmb;
+	size_t copylen, off = 0;
+
+	KASSERT(len > 0, ("len == 0"));
+
+	newmb = m_getm2(NULL, len, flags, MT_DATA, M_PKTHDR);
+	if (newmb == NULL) {
+		ICL_WARN("failed to allocate mbuf for %zd bytes", len);
+		return (ENOMEM);
+	}
+
+	for (mb = newmb; mb != NULL; mb = mb->m_next) {
+		copylen = min(M_TRAILINGSPACE(mb), len - off);
+		memcpy(mtod(mb, char *), (const char *)addr + off, copylen);
+		mb->m_len = copylen;
+		off += copylen;
+	}
+	KASSERT(off == len, ("%s: off != len", __func__));
+
+	if (request->ip_data_mbuf == NULL) {
+		request->ip_data_mbuf = newmb;
+		request->ip_data_len = len;
+	} else {
+		m_cat(request->ip_data_mbuf, newmb);
+		request->ip_data_len += len;
+	}
+
+	return (0);
+}
+
+void
+icl_pdu_get_data(struct icl_pdu *ip, size_t off, void *addr, size_t len)
+{
+
+	m_copydata(ip->ip_data_mbuf, off, len, addr);
+}
+
+void
+icl_pdu_queue(struct icl_pdu *ip)
+{
+	struct icl_conn *ic;
+
+	ic = ip->ip_conn;
+
+	ICL_CONN_LOCK_ASSERT(ic);
+
+	if (ic->ic_disconnecting || ic->ic_socket == NULL) {
+		ICL_DEBUG("icl_pdu_queue on closed connection");
+		icl_pdu_free(ip);
+		return;
+	}
+
+	if (!STAILQ_EMPTY(&ic->ic_to_send)) {
+		STAILQ_INSERT_TAIL(&ic->ic_to_send, ip, ip_next);
+		/*
+		 * If the queue is not empty, someone else had already
+		 * signaled the send thread; no need to do that again,
+		 * just return.
+		 */
+		return;
+	}
+
+	STAILQ_INSERT_TAIL(&ic->ic_to_send, ip, ip_next);
+	cv_signal(&ic->ic_send_cv);
+}
+
+struct icl_conn *
+icl_conn_new(const char *name, struct mtx *lock)
+{
+	struct icl_conn *ic;
+
+	refcount_acquire(&icl_ncons);
+
+	ic = uma_zalloc(icl_conn_zone, M_WAITOK | M_ZERO);
+
+	STAILQ_INIT(&ic->ic_to_send);
+	ic->ic_lock = lock;
+	cv_init(&ic->ic_send_cv, "icl_tx");
+	cv_init(&ic->ic_receive_cv, "icl_rx");
+#ifdef DIAGNOSTIC
+	refcount_init(&ic->ic_outstanding_pdus, 0);
+#endif
+	ic->ic_max_data_segment_length = ICL_MAX_DATA_SEGMENT_LENGTH;
+	ic->ic_name = name;
+
+	return (ic);
+}
+
+void
+icl_conn_free(struct icl_conn *ic)
+{
+
+	cv_destroy(&ic->ic_send_cv);
+	cv_destroy(&ic->ic_receive_cv);
+	uma_zfree(icl_conn_zone, ic);
+	refcount_release(&icl_ncons);
+}
+
+static int
+icl_conn_start(struct icl_conn *ic)
+{
+	size_t minspace;
+	struct sockopt opt;
+	int error, one = 1;
+
+	ICL_CONN_LOCK(ic);
+
+	/*
+	 * XXX: Ugly hack.
+	 */
+	if (ic->ic_socket == NULL) {
+		ICL_CONN_UNLOCK(ic);
+		return (EINVAL);
+	}
+
+	ic->ic_receive_state = ICL_CONN_STATE_BHS;
+	ic->ic_receive_len = sizeof(struct iscsi_bhs);
+	ic->ic_disconnecting = false;
+
+	ICL_CONN_UNLOCK(ic);
+
+	/*
+	 * For sendspace, this is required because the current code cannot
+	 * send a PDU in pieces; thus, the minimum buffer size is equal
+	 * to the maximum PDU size.  "+4" is to account for possible padding.
+	 *
+	 * What we should actually do here is to use autoscaling, but set
+	 * some minimal buffer size to "minspace".  I don't know a way to do
+	 * that, though.
+	 */
+	minspace = sizeof(struct iscsi_bhs) + ic->ic_max_data_segment_length +
+	    ISCSI_HEADER_DIGEST_SIZE + ISCSI_DATA_DIGEST_SIZE + 4;
+	if (sendspace < minspace) {
+		ICL_WARN("kern.icl.sendspace too low; must be at least %zd",
+		    minspace);
+		sendspace = minspace;
+	}
+	if (recvspace < minspace) {
+		ICL_WARN("kern.icl.recvspace too low; must be at least %zd",
+		    minspace);
+		recvspace = minspace;
+	}
+
+	error = soreserve(ic->ic_socket, sendspace, recvspace);
+	if (error != 0) {
+		ICL_WARN("soreserve failed with error %d", error);
+		icl_conn_close(ic);
+		return (error);
+	}
+	ic->ic_socket->so_snd.sb_flags |= SB_AUTOSIZE;
+	ic->ic_socket->so_rcv.sb_flags |= SB_AUTOSIZE;
+
+	/*
+	 * Disable Nagle.
+	 */
+	bzero(&opt, sizeof(opt));
+	opt.sopt_dir = SOPT_SET;
+	opt.sopt_level = IPPROTO_TCP;
+	opt.sopt_name = TCP_NODELAY;
+	opt.sopt_val = &one;
+	opt.sopt_valsize = sizeof(one);
+	error = sosetopt(ic->ic_socket, &opt);
+	if (error != 0) {
+		ICL_WARN("disabling TCP_NODELAY failed with error %d", error);
+		icl_conn_close(ic);
+		return (error);
+	}
+
+	/*
+	 * Register socket upcall, to get notified about incoming PDUs
+	 * and free space to send outgoing ones.
+	 */
+	SOCKBUF_LOCK(&ic->ic_socket->so_snd);
+	soupcall_set(ic->ic_socket, SO_SND, icl_soupcall_send, ic);
+	SOCKBUF_UNLOCK(&ic->ic_socket->so_snd);
+	SOCKBUF_LOCK(&ic->ic_socket->so_rcv);
+	soupcall_set(ic->ic_socket, SO_RCV, icl_soupcall_receive, ic);
+	SOCKBUF_UNLOCK(&ic->ic_socket->so_rcv);
+
+	/*
+	 * Start threads.
+	 */
+	ICL_CONN_LOCK(ic);
+	ic->ic_send_running = ic->ic_receive_running = true;
+	ICL_CONN_UNLOCK(ic);
+	error = kthread_add(icl_send_thread, ic, NULL, NULL, 0, 0, "%stx",
+	    ic->ic_name);
+	if (error != 0) {
+		ICL_WARN("kthread_add(9) failed with error %d", error);
+		ICL_CONN_LOCK(ic);
+		ic->ic_send_running = ic->ic_receive_running = false;
+		cv_signal(&ic->ic_send_cv);
+		ICL_CONN_UNLOCK(ic);
+		icl_conn_close(ic);
+		return (error);
+	}
+	error = kthread_add(icl_receive_thread, ic, NULL, NULL, 0, 0, "%srx",
+	    ic->ic_name);
+	if (error != 0) {
+		ICL_WARN("kthread_add(9) failed with error %d", error);
+		ICL_CONN_LOCK(ic);
+		ic->ic_receive_running = false;
+		cv_signal(&ic->ic_send_cv);
+		ICL_CONN_UNLOCK(ic);
+		icl_conn_close(ic);
+		return (error);
+	}
+
+	return (0);
+}
+
+int
+icl_conn_handoff(struct icl_conn *ic, int fd)
+{
+	struct file *fp;
+	struct socket *so;
+	cap_rights_t rights;
+	int error;
+
+	ICL_CONN_LOCK_ASSERT_NOT(ic);
+
+	/*
+	 * Steal the socket from userland.
+	 */
+	error = fget(curthread, fd,
+	    cap_rights_init(&rights, CAP_SOCK_CLIENT), &fp);
+	if (error != 0)
+		return (error);
+	if (fp->f_type != DTYPE_SOCKET) {
+		fdrop(fp, curthread);
+		return (EINVAL);
+	}
+	so = fp->f_data;
+	if (so->so_type != SOCK_STREAM) {
+		fdrop(fp, curthread);
+		return (EINVAL);
+	}
+
+	ICL_CONN_LOCK(ic);
+
+	if (ic->ic_socket != NULL) {
+		ICL_CONN_UNLOCK(ic);
+		fdrop(fp, curthread);
+		return (EBUSY);
+	}
+
+	ic->ic_socket = fp->f_data;
+	fp->f_ops = &badfileops;
+	fp->f_data = NULL;
+	fdrop(fp, curthread);
+	ICL_CONN_UNLOCK(ic);
+
+	error = icl_conn_start(ic);
+
+	return (error);
+}
+
+void
+icl_conn_close(struct icl_conn *ic)
+{
+	struct icl_pdu *pdu;
+	struct socket *so;
+
+	ICL_CONN_LOCK(ic);
+
+	/*
+	 * Wake up the threads, so they can properly terminate.
+	 */
+	ic->ic_disconnecting = true;
+	while (ic->ic_receive_running || ic->ic_send_running) {
+		cv_signal(&ic->ic_receive_cv);
+		cv_signal(&ic->ic_send_cv);
+		cv_wait(&ic->ic_send_cv, ic->ic_lock);
+	}
+
+	/* Some other thread could close the connection same time. */
+	so = ic->ic_socket;
+	if (so == NULL) {
+		ICL_CONN_UNLOCK(ic);
+		return;
+	}
+	ic->ic_socket = NULL;
+
+	/*
+	 * Deregister socket upcalls.
+	 */
+	ICL_CONN_UNLOCK(ic);
+	SOCKBUF_LOCK(&so->so_snd);
+	if (so->so_snd.sb_upcall != NULL)
+		soupcall_clear(so, SO_SND);
+	SOCKBUF_UNLOCK(&so->so_snd);
+	SOCKBUF_LOCK(&so->so_rcv);
+	if (so->so_rcv.sb_upcall != NULL)
+		soupcall_clear(so, SO_RCV);
+	SOCKBUF_UNLOCK(&so->so_rcv);
+	soclose(so);
+	ICL_CONN_LOCK(ic);
+
+	if (ic->ic_receive_pdu != NULL) {
+		//ICL_DEBUG("freeing partially received PDU");
+		icl_pdu_free(ic->ic_receive_pdu);
+		ic->ic_receive_pdu = NULL;
+	}
+
+	/*
+	 * Remove any outstanding PDUs from the send queue.
+	 */
+	while (!STAILQ_EMPTY(&ic->ic_to_send)) {
+		pdu = STAILQ_FIRST(&ic->ic_to_send);
+		STAILQ_REMOVE_HEAD(&ic->ic_to_send, ip_next);
+		icl_pdu_free(pdu);
+	}
+
+	KASSERT(STAILQ_EMPTY(&ic->ic_to_send),
+	    ("destroying session with non-empty send queue"));
+#ifdef DIAGNOSTIC
+	KASSERT(ic->ic_outstanding_pdus == 0,
+	    ("destroying session with %d outstanding PDUs",
+	     ic->ic_outstanding_pdus));
+#endif
+	ICL_CONN_UNLOCK(ic);
+}
+
+bool
+icl_conn_connected(struct icl_conn *ic)
+{
+	ICL_CONN_LOCK_ASSERT_NOT(ic);
+
+	ICL_CONN_LOCK(ic);
+	if (ic->ic_socket == NULL) {
+		ICL_CONN_UNLOCK(ic);
+		return (false);
+	}
+	if (ic->ic_socket->so_error != 0) {
+		ICL_CONN_UNLOCK(ic);
+		return (false);
+	}
+	ICL_CONN_UNLOCK(ic);
+	return (true);
+}
+
+#ifdef ICL_KERNEL_PROXY
+int
+icl_conn_handoff_sock(struct icl_conn *ic, struct socket *so)
+{
+	int error;
+
+	ICL_CONN_LOCK_ASSERT_NOT(ic);
+
+	if (so->so_type != SOCK_STREAM)
+		return (EINVAL);
+
+	ICL_CONN_LOCK(ic);
+	if (ic->ic_socket != NULL) {
+		ICL_CONN_UNLOCK(ic);
+		return (EBUSY);
+	}
+	ic->ic_socket = so;
+	ICL_CONN_UNLOCK(ic);
+
+	error = icl_conn_start(ic);
+
+	return (error);
+}
+#endif /* ICL_KERNEL_PROXY */
+
+static int
+icl_unload(void)
+{
+
+	if (icl_ncons != 0)
+		return (EBUSY);
+
+	uma_zdestroy(icl_conn_zone);
+	uma_zdestroy(icl_pdu_zone);
+
+	return (0);
+}
+
+static void
+icl_load(void)
+{
+
+	icl_conn_zone = uma_zcreate("icl_conn",
+	    sizeof(struct icl_conn), NULL, NULL, NULL, NULL,
+	    UMA_ALIGN_PTR, 0);
+	icl_pdu_zone = uma_zcreate("icl_pdu",
+	    sizeof(struct icl_pdu), NULL, NULL, NULL, NULL,
+	    UMA_ALIGN_PTR, 0);
+
+	refcount_init(&icl_ncons, 0);
+}
+
+static int
+icl_modevent(module_t mod, int what, void *arg)
+{
+
+	switch (what) {
+	case MOD_LOAD:
+		icl_load();
+		return (0);
+	case MOD_UNLOAD:
+		return (icl_unload());
+	default:
+		return (EINVAL);
+	}
+}
+
+moduledata_t icl_data = {
+	"icl",
+	icl_modevent,
+	0
+};
+
+DECLARE_MODULE(icl, icl_data, SI_SUB_DRIVERS, SI_ORDER_FIRST);
+MODULE_VERSION(icl, 1);


Property changes on: trunk/sys/dev/iscsi/icl.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sys/dev/iscsi/icl.h
===================================================================
--- trunk/sys/dev/iscsi/icl.h	                        (rev 0)
+++ trunk/sys/dev/iscsi/icl.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -0,0 +1,159 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2012 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Edward Tomasz Napierala under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/sys/dev/iscsi/icl.h 276618 2015-01-03 13:36:56Z mav $
+ */
+
+#ifndef ICL_H
+#define	ICL_H
+
+/*
+ * iSCSI Common Layer.  It's used by both the initiator and target to send
+ * and receive iSCSI PDUs.
+ */
+
+struct icl_conn;
+
+struct icl_pdu {
+	STAILQ_ENTRY(icl_pdu)	ip_next;
+	struct icl_conn		*ip_conn;
+	struct iscsi_bhs	*ip_bhs;
+	struct mbuf		*ip_bhs_mbuf;
+	size_t			ip_ahs_len;
+	struct mbuf		*ip_ahs_mbuf;
+	size_t			ip_data_len;
+	struct mbuf		*ip_data_mbuf;
+
+	/*
+	 * User (initiator or provider) private fields.
+	 */
+	uint32_t		ip_prv0;
+	uint32_t		ip_prv1;
+	uint32_t		ip_prv2;
+};
+
+struct icl_pdu		*icl_pdu_new(struct icl_conn *ic, int flags);
+size_t			icl_pdu_data_segment_length(const struct icl_pdu *ip);
+int			icl_pdu_append_data(struct icl_pdu *ip, const void *addr, size_t len, int flags);
+void			icl_pdu_get_data(struct icl_pdu *ip, size_t off, void *addr, size_t len);
+void			icl_pdu_queue(struct icl_pdu *ip);
+void			icl_pdu_free(struct icl_pdu *ip);
+
+#define ICL_CONN_STATE_INVALID		0
+#define ICL_CONN_STATE_BHS		1
+#define ICL_CONN_STATE_AHS		2
+#define ICL_CONN_STATE_HEADER_DIGEST	3
+#define ICL_CONN_STATE_DATA		4
+#define ICL_CONN_STATE_DATA_DIGEST	5
+
+#define	ICL_MAX_DATA_SEGMENT_LENGTH	(128 * 1024)
+
+struct icl_conn {
+	struct mtx		*ic_lock;
+	struct socket		*ic_socket;
+#ifdef DIAGNOSTIC
+	volatile u_int		ic_outstanding_pdus;
+#endif
+	STAILQ_HEAD(, icl_pdu)	ic_to_send;
+	bool			ic_check_send_space;
+	size_t			ic_receive_len;
+	int			ic_receive_state;
+	struct icl_pdu		*ic_receive_pdu;
+	struct cv		ic_send_cv;
+	struct cv		ic_receive_cv;
+	bool			ic_header_crc32c;
+	bool			ic_data_crc32c;
+	bool			ic_send_running;
+	bool			ic_receive_running;
+	size_t			ic_max_data_segment_length;
+	bool			ic_disconnecting;
+	bool			ic_iser;
+	const char		*ic_name;
+
+	void			(*ic_receive)(struct icl_pdu *);
+	void			(*ic_error)(struct icl_conn *);
+
+	/*
+	 * User (initiator or provider) private fields.
+	 */
+	void			*ic_prv0;
+};
+
+struct icl_conn		*icl_conn_new(const char *name, struct mtx *lock);
+void			icl_conn_free(struct icl_conn *ic);
+int			icl_conn_handoff(struct icl_conn *ic, int fd);
+void			icl_conn_close(struct icl_conn *ic);
+bool			icl_conn_connected(struct icl_conn *ic);
+
+#ifdef ICL_KERNEL_PROXY
+
+struct sockaddr;
+struct icl_listen;
+
+struct icl_listen_sock {
+	TAILQ_ENTRY(icl_listen_sock)	ils_next;
+	struct icl_listen		*ils_listen;
+	struct socket			*ils_socket;
+	bool				ils_running;
+	bool				ils_disconnecting;
+	int				ils_id;
+};
+
+struct icl_listen	{
+	TAILQ_HEAD(, icl_listen_sock)	il_sockets;
+	struct sx			il_lock;
+	void				(*il_accept)(struct socket *,
+					    struct sockaddr *, int);
+};
+
+/*
+ * Initiator part.
+ */
+int			icl_conn_connect(struct icl_conn *ic, bool rdma,
+			    int domain, int socktype, int protocol,
+			    struct sockaddr *from_sa, struct sockaddr *to_sa);
+/*
+ * Target part.
+ */
+struct icl_listen	*icl_listen_new(void (*accept_cb)(struct socket *,
+			    struct sockaddr *, int));
+void			icl_listen_free(struct icl_listen *il);
+int			icl_listen_add(struct icl_listen *il, bool rdma,
+			    int domain, int socktype, int protocol,
+			    struct sockaddr *sa, int portal_id);
+int			icl_listen_remove(struct icl_listen *il, struct sockaddr *sa);
+
+/*
+ * This one is not a public API; only to be used by icl_proxy.c.
+ */
+int			icl_conn_handoff_sock(struct icl_conn *ic, struct socket *so);
+
+#endif /* ICL_KERNEL_PROXY */
+
+#endif /* !ICL_H */


Property changes on: trunk/sys/dev/iscsi/icl.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sys/dev/iscsi/icl_proxy.c
===================================================================
--- trunk/sys/dev/iscsi/icl_proxy.c	                        (rev 0)
+++ trunk/sys/dev/iscsi/icl_proxy.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -0,0 +1,404 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2012 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Edward Tomasz Napierala under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+/*-
+ * Copyright (c) 1982, 1986, 1989, 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * sendfile(2) and related extensions:
+ * Copyright (c) 1998, David Greenman. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)uipc_syscalls.c	8.4 (Berkeley) 2/21/94
+ */
+
+/*
+ * iSCSI Common Layer, kernel proxy part.
+ */
+
+#ifdef ICL_KERNEL_PROXY
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/sys/dev/iscsi/icl_proxy.c 280258 2015-03-19 13:37:36Z rwatson $");
+
+#include <sys/param.h>
+#include <sys/capsicum.h>
+#include <sys/condvar.h>
+#include <sys/conf.h>
+#include <sys/kernel.h>
+#include <sys/kthread.h>
+#include <sys/malloc.h>
+#include <sys/proc.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/sx.h>
+#include <sys/systm.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <linux/types.h>
+#include <rdma/rdma_cm.h>
+
+#include <dev/iscsi/icl.h>
+
+static int debug = 1;
+
+#define	ICL_DEBUG(X, ...)					\
+	if (debug > 1) {					\
+		printf("%s: " X "\n", __func__, ## __VA_ARGS__);\
+	} while (0)
+
+#define	ICL_WARN(X, ...)					\
+	if (debug > 0) {					\
+		printf("WARNING: %s: " X "\n",			\
+		    __func__, ## __VA_ARGS__);			\
+	} while (0)
+
+static MALLOC_DEFINE(M_ICL_PROXY, "ICL_PROXY", "iSCSI common layer proxy");
+
+#ifdef ICL_RDMA
+static int	icl_conn_connect_rdma(struct icl_conn *ic, int domain, int socktype,
+    int protocol, struct sockaddr *from_sa, struct sockaddr *to_sa);
+static int	icl_listen_add_rdma(struct icl_listen *il, int domain, int socktype, int protocol,
+    struct sockaddr *sa);
+#endif /* ICL_RDMA */
+
+static int
+icl_conn_connect_tcp(struct icl_conn *ic, int domain, int socktype,
+    int protocol, struct sockaddr *from_sa, struct sockaddr *to_sa)
+{
+	struct socket *so;
+	int error;
+	int interrupted = 0;
+
+	error = socreate(domain, &so, socktype, protocol,
+	    curthread->td_ucred, curthread);
+	if (error != 0)
+		return (error);
+
+	if (from_sa != NULL) {
+		error = sobind(so, from_sa, curthread);
+		if (error != 0) {
+			soclose(so);
+			return (error);
+		}
+	}
+
+	error = soconnect(so, to_sa, curthread);
+	if (error != 0) {
+		soclose(so);
+		return (error);
+	}
+
+	SOCK_LOCK(so);
+	while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
+		error = msleep(&so->so_timeo, SOCK_MTX(so), PSOCK | PCATCH,
+		    "icl_connect", 0);
+		if (error) {
+			if (error == EINTR || error == ERESTART)
+				interrupted = 1;
+			break;
+		}
+	}
+	if (error == 0) {
+		error = so->so_error;
+		so->so_error = 0;
+	}
+	SOCK_UNLOCK(so);
+
+	if (error != 0) {
+		soclose(so);
+		return (error);
+	}
+
+	error = icl_conn_handoff_sock(ic, so);
+	if (error != 0)
+		soclose(so);
+
+	return (error);
+}
+
+int
+icl_conn_connect(struct icl_conn *ic, bool rdma, int domain, int socktype,
+    int protocol, struct sockaddr *from_sa, struct sockaddr *to_sa)
+{
+
+	if (rdma) {
+#ifdef ICL_RDMA
+		return (icl_conn_connect_rdma(ic, domain, socktype, protocol, from_sa, to_sa));
+#else
+		ICL_DEBUG("RDMA not supported");
+		return (EOPNOTSUPP);
+#endif
+	}
+
+	return (icl_conn_connect_tcp(ic, domain, socktype, protocol, from_sa, to_sa));
+}
+
+struct icl_listen *
+icl_listen_new(void (*accept_cb)(struct socket *, struct sockaddr *, int))
+{
+	struct icl_listen *il;
+
+	il = malloc(sizeof(*il), M_ICL_PROXY, M_ZERO | M_WAITOK);
+	TAILQ_INIT(&il->il_sockets);
+	sx_init(&il->il_lock, "icl_listen");
+	il->il_accept = accept_cb;
+
+	return (il);
+}
+
+void
+icl_listen_free(struct icl_listen *il)
+{
+	struct icl_listen_sock *ils;
+
+	sx_xlock(&il->il_lock);
+	while (!TAILQ_EMPTY(&il->il_sockets)) {
+		ils = TAILQ_FIRST(&il->il_sockets);
+		while (ils->ils_running) {
+			ICL_DEBUG("waiting for accept thread to terminate");
+			sx_xunlock(&il->il_lock);
+			ils->ils_disconnecting = true;
+			wakeup(&ils->ils_socket->so_timeo);
+			pause("icl_unlisten", 1 * hz);
+			sx_xlock(&il->il_lock);
+		}
+	
+		TAILQ_REMOVE(&il->il_sockets, ils, ils_next);
+		soclose(ils->ils_socket);
+		free(ils, M_ICL_PROXY);
+	}
+	sx_xunlock(&il->il_lock);
+
+	free(il, M_ICL_PROXY);
+}
+
+/*
+ * XXX: Doing accept in a separate thread in each socket might not be the best way
+ * 	to do stuff, but it's pretty clean and debuggable - and you probably won't
+ * 	have hundreds of listening sockets anyway.
+ */
+static void
+icl_accept_thread(void *arg)
+{
+	struct icl_listen_sock *ils;
+	struct socket *head, *so;
+	struct sockaddr *sa;
+	int error;
+
+	ils = arg;
+	head = ils->ils_socket;
+
+	ils->ils_running = true;
+
+	for (;;) {
+		ACCEPT_LOCK();
+		while (TAILQ_EMPTY(&head->so_comp) && head->so_error == 0 && ils->ils_disconnecting == false) {
+			if (head->so_rcv.sb_state & SBS_CANTRCVMORE) {
+				head->so_error = ECONNABORTED;
+				break;
+			}
+			error = msleep(&head->so_timeo, &accept_mtx, PSOCK | PCATCH,
+			    "accept", 0);
+			if (error) {
+				ACCEPT_UNLOCK();
+				ICL_WARN("msleep failed with error %d", error);
+				continue;
+			}
+			if (ils->ils_disconnecting) {
+				ACCEPT_UNLOCK();
+				ICL_DEBUG("terminating");
+				ils->ils_running = false;
+				kthread_exit();
+				return;
+			}
+		}
+		if (head->so_error) {
+			error = head->so_error;
+			head->so_error = 0;
+			ACCEPT_UNLOCK();
+			ICL_WARN("socket error %d", error);
+			continue;
+		}
+		so = TAILQ_FIRST(&head->so_comp);
+		KASSERT(so != NULL, ("NULL so"));
+		KASSERT(!(so->so_qstate & SQ_INCOMP), ("accept1: so SQ_INCOMP"));
+		KASSERT(so->so_qstate & SQ_COMP, ("accept1: so not SQ_COMP"));
+
+		/*
+		 * Before changing the flags on the socket, we have to bump the
+		 * reference count.  Otherwise, if the protocol calls sofree(),
+		 * the socket will be released due to a zero refcount.
+		 */
+		SOCK_LOCK(so);			/* soref() and so_state update */
+		soref(so);			/* file descriptor reference */
+
+		TAILQ_REMOVE(&head->so_comp, so, so_list);
+		head->so_qlen--;
+		so->so_state |= (head->so_state & SS_NBIO);
+		so->so_qstate &= ~SQ_COMP;
+		so->so_head = NULL;
+
+		SOCK_UNLOCK(so);
+		ACCEPT_UNLOCK();
+
+		sa = NULL;
+		error = soaccept(so, &sa);
+		if (error != 0) {
+			ICL_WARN("soaccept error %d", error);
+			if (sa != NULL)
+				free(sa, M_SONAME);
+			soclose(so);
+			continue;
+		}
+
+		(ils->ils_listen->il_accept)(so, sa, ils->ils_id);
+	}
+}
+
+static int
+icl_listen_add_tcp(struct icl_listen *il, int domain, int socktype,
+    int protocol, struct sockaddr *sa, int portal_id)
+{
+	struct icl_listen_sock *ils;
+	struct socket *so;
+	struct sockopt sopt;
+	int error, one = 1;
+
+	error = socreate(domain, &so, socktype, protocol,
+	    curthread->td_ucred, curthread);
+	if (error != 0) {
+		ICL_WARN("socreate failed with error %d", error);
+		return (error);
+	}
+
+	sopt.sopt_dir = SOPT_SET;
+	sopt.sopt_level = SOL_SOCKET;
+	sopt.sopt_name = SO_REUSEADDR;
+	sopt.sopt_val = &one;
+	sopt.sopt_valsize = sizeof(one);
+	sopt.sopt_td = NULL;
+	error = sosetopt(so, &sopt);
+	if (error != 0) {
+		ICL_WARN("failed to set SO_REUSEADDR with error %d", error);
+		soclose(so);
+		return (error);
+	}
+
+	error = sobind(so, sa, curthread);
+	if (error != 0) {
+		ICL_WARN("sobind failed with error %d", error);
+		soclose(so);
+		return (error);
+	}
+
+	error = solisten(so, -1, curthread);
+	if (error != 0) {
+		ICL_WARN("solisten failed with error %d", error);
+		soclose(so);
+		return (error);
+	}
+
+	ils = malloc(sizeof(*ils), M_ICL_PROXY, M_ZERO | M_WAITOK);
+	ils->ils_listen = il;
+	ils->ils_socket = so;
+	ils->ils_id = portal_id;
+
+	error = kthread_add(icl_accept_thread, ils, NULL, NULL, 0, 0, "iclacc");
+	if (error != 0) {
+		ICL_WARN("kthread_add failed with error %d", error);
+		soclose(so);
+		free(ils, M_ICL_PROXY);
+
+		return (error);
+	}
+
+	sx_xlock(&il->il_lock);
+	TAILQ_INSERT_TAIL(&il->il_sockets, ils, ils_next);
+	sx_xunlock(&il->il_lock);
+
+	return (0);
+}
+
+int
+icl_listen_add(struct icl_listen *il, bool rdma, int domain, int socktype,
+    int protocol, struct sockaddr *sa, int portal_id)
+{
+
+	if (rdma) {
+#ifndef ICL_RDMA
+		ICL_DEBUG("RDMA not supported");
+		return (EOPNOTSUPP);
+#else
+		return (icl_listen_add_rdma(il, domain, socktype, protocol,
+		    sa, portal_id));
+#endif
+	}
+
+
+	return (icl_listen_add_tcp(il, domain, socktype, protocol, sa,
+	    portal_id));
+}
+
+int
+icl_listen_remove(struct icl_listen *il, struct sockaddr *sa)
+{
+
+	/*
+	 * XXX
+	 */
+
+	return (EOPNOTSUPP);
+}
+
+#endif /* ICL_KERNEL_PROXY */


Property changes on: trunk/sys/dev/iscsi/icl_proxy.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sys/dev/iscsi/iscsi.c
===================================================================
--- trunk/sys/dev/iscsi/iscsi.c	                        (rev 0)
+++ trunk/sys/dev/iscsi/iscsi.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -0,0 +1,2496 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2012 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Edward Tomasz Napierala under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/sys/dev/iscsi/iscsi.c 325226 2017-10-31 09:58:51Z avg $");
+
+#include <sys/param.h>
+#include <sys/condvar.h>
+#include <sys/conf.h>
+#include <sys/eventhandler.h>
+#include <sys/file.h>
+#include <sys/kernel.h>
+#include <sys/kthread.h>
+#include <sys/lock.h>
+#include <sys/malloc.h>
+#include <sys/mutex.h>
+#include <sys/module.h>
+#include <sys/sysctl.h>
+#include <sys/systm.h>
+#include <sys/sx.h>
+#include <vm/uma.h>
+
+#include <cam/cam.h>
+#include <cam/cam_ccb.h>
+#include <cam/cam_xpt.h>
+#include <cam/cam_debug.h>
+#include <cam/cam_sim.h>
+#include <cam/cam_xpt_sim.h>
+#include <cam/cam_xpt_periph.h>
+#include <cam/cam_periph.h>
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_message.h>
+
+#include <dev/iscsi/icl.h>
+#include <dev/iscsi/iscsi_ioctl.h>
+#include <dev/iscsi/iscsi_proto.h>
+#include <dev/iscsi/iscsi.h>
+
+#ifdef ICL_KERNEL_PROXY
+#include <sys/socketvar.h>
+#endif
+
+#ifdef ICL_KERNEL_PROXY
+FEATURE(iscsi_kernel_proxy, "iSCSI initiator built with ICL_KERNEL_PROXY");
+#endif
+
+/*
+ * XXX: This is global so the iscsi_unload() can access it.
+ * 	Think about how to do this properly.
+ */
+static struct iscsi_softc	*sc;
+
+SYSCTL_NODE(_kern, OID_AUTO, iscsi, CTLFLAG_RD, 0, "iSCSI initiator");
+static int debug = 1;
+TUNABLE_INT("kern.iscsi.debug", &debug);
+SYSCTL_INT(_kern_iscsi, OID_AUTO, debug, CTLFLAG_RWTUN,
+    &debug, 0, "Enable debug messages");
+static int ping_timeout = 5;
+TUNABLE_INT("kern.iscsi.ping_timeout", &ping_timeout);
+SYSCTL_INT(_kern_iscsi, OID_AUTO, ping_timeout, CTLFLAG_RWTUN, &ping_timeout,
+    0, "Timeout for ping (NOP-Out) requests, in seconds");
+static int iscsid_timeout = 60;
+TUNABLE_INT("kern.iscsi.iscsid_timeout", &iscsid_timeout);
+SYSCTL_INT(_kern_iscsi, OID_AUTO, iscsid_timeout, CTLFLAG_RWTUN, &iscsid_timeout,
+    0, "Time to wait for iscsid(8) to handle reconnection, in seconds");
+static int login_timeout = 60;
+TUNABLE_INT("kern.iscsi.login_timeout", &login_timeout);
+SYSCTL_INT(_kern_iscsi, OID_AUTO, login_timeout, CTLFLAG_RWTUN, &login_timeout,
+    0, "Time to wait for iscsid(8) to finish Login Phase, in seconds");
+static int maxtags = 255;
+TUNABLE_INT("kern.iscsi.maxtags", &maxtags);
+SYSCTL_INT(_kern_iscsi, OID_AUTO, maxtags, CTLFLAG_RWTUN, &maxtags,
+    0, "Max number of IO requests queued");
+static int fail_on_disconnection = 0;
+TUNABLE_INT("kern.iscsi.fail_on_disconnection", &fail_on_disconnection);
+SYSCTL_INT(_kern_iscsi, OID_AUTO, fail_on_disconnection, CTLFLAG_RWTUN,
+    &fail_on_disconnection, 0, "Destroy CAM SIM on connection failure");
+static int fail_on_shutdown = 1;
+SYSCTL_INT(_kern_iscsi, OID_AUTO, fail_on_shutdown, CTLFLAG_RWTUN,
+    &fail_on_shutdown, 0, "Fail disconnected sessions on shutdown");
+
+static MALLOC_DEFINE(M_ISCSI, "iSCSI", "iSCSI initiator");
+static uma_zone_t iscsi_outstanding_zone;
+
+#define	CONN_SESSION(X)	((struct iscsi_session *)X->ic_prv0)
+#define	PDU_SESSION(X)	(CONN_SESSION(X->ip_conn))
+
+#define	ISCSI_DEBUG(X, ...)						\
+	do {								\
+		if (debug > 1) 						\
+			printf("%s: " X "\n", __func__, ## __VA_ARGS__);\
+	} while (0)
+
+#define	ISCSI_WARN(X, ...)						\
+	do {								\
+		if (debug > 0) {					\
+			printf("WARNING: %s: " X "\n",			\
+			    __func__, ## __VA_ARGS__);			\
+		}							\
+	} while (0)
+
+#define	ISCSI_SESSION_DEBUG(S, X, ...)					\
+	do {								\
+		if (debug > 1) {					\
+			printf("%s: %s (%s): " X "\n",			\
+			    __func__, S->is_conf.isc_target_addr,	\
+			    S->is_conf.isc_target, ## __VA_ARGS__);	\
+		}							\
+	} while (0)
+
+#define	ISCSI_SESSION_WARN(S, X, ...)					\
+	do {								\
+		if (debug > 0) {					\
+			printf("WARNING: %s (%s): " X "\n",		\
+			    S->is_conf.isc_target_addr,			\
+			    S->is_conf.isc_target, ## __VA_ARGS__);	\
+		}							\
+	} while (0)
+
+#define ISCSI_SESSION_LOCK(X)		mtx_lock(&X->is_lock)
+#define ISCSI_SESSION_UNLOCK(X)		mtx_unlock(&X->is_lock)
+#define ISCSI_SESSION_LOCK_ASSERT(X)	mtx_assert(&X->is_lock, MA_OWNED)
+#define ISCSI_SESSION_LOCK_ASSERT_NOT(X) mtx_assert(&X->is_lock, MA_NOTOWNED)
+
+static int	iscsi_ioctl(struct cdev *dev, u_long cmd, caddr_t arg,
+		    int mode, struct thread *td);
+
+static struct cdevsw iscsi_cdevsw = {
+     .d_version = D_VERSION,
+     .d_ioctl   = iscsi_ioctl,
+     .d_name    = "iscsi",
+};
+
+static void	iscsi_pdu_queue_locked(struct icl_pdu *request);
+static void	iscsi_pdu_queue(struct icl_pdu *request);
+static void	iscsi_pdu_update_statsn(const struct icl_pdu *response);
+static void	iscsi_pdu_handle_nop_in(struct icl_pdu *response);
+static void	iscsi_pdu_handle_scsi_response(struct icl_pdu *response);
+static void	iscsi_pdu_handle_task_response(struct icl_pdu *response);
+static void	iscsi_pdu_handle_data_in(struct icl_pdu *response);
+static void	iscsi_pdu_handle_logout_response(struct icl_pdu *response);
+static void	iscsi_pdu_handle_r2t(struct icl_pdu *response);
+static void	iscsi_pdu_handle_async_message(struct icl_pdu *response);
+static void	iscsi_pdu_handle_reject(struct icl_pdu *response);
+static void	iscsi_session_reconnect(struct iscsi_session *is);
+static void	iscsi_session_terminate(struct iscsi_session *is);
+static void	iscsi_action(struct cam_sim *sim, union ccb *ccb);
+static void	iscsi_poll(struct cam_sim *sim);
+static struct iscsi_outstanding	*iscsi_outstanding_find(struct iscsi_session *is,
+		    uint32_t initiator_task_tag);
+static struct iscsi_outstanding	*iscsi_outstanding_add(struct iscsi_session *is,
+		    uint32_t initiator_task_tag, union ccb *ccb);
+static void	iscsi_outstanding_remove(struct iscsi_session *is,
+		    struct iscsi_outstanding *io);
+
+static bool
+iscsi_pdu_prepare(struct icl_pdu *request)
+{
+	struct iscsi_session *is;
+	struct iscsi_bhs_scsi_command *bhssc;
+
+	is = PDU_SESSION(request);
+
+	ISCSI_SESSION_LOCK_ASSERT(is);
+
+	/*
+	 * We're only using fields common for all the request
+	 * (initiator -> target) PDUs.
+	 */
+	bhssc = (struct iscsi_bhs_scsi_command *)request->ip_bhs;
+
+	/*
+	 * Data-Out PDU does not contain CmdSN.
+	 */
+	if (bhssc->bhssc_opcode != ISCSI_BHS_OPCODE_SCSI_DATA_OUT) {
+		if (ISCSI_SNGT(is->is_cmdsn, is->is_maxcmdsn) &&
+		    (bhssc->bhssc_opcode & ISCSI_BHS_OPCODE_IMMEDIATE) == 0) {
+			/*
+			 * Current MaxCmdSN prevents us from sending any more
+			 * SCSI Command PDUs to the target; postpone the PDU.
+			 * It will get resent by either iscsi_pdu_queue(),
+			 * or by maintenance thread.
+			 */
+#if 0
+			ISCSI_SESSION_DEBUG(is, "postponing send, CmdSN %u, "
+			    "ExpCmdSN %u, MaxCmdSN %u, opcode 0x%x",
+			    is->is_cmdsn, is->is_expcmdsn, is->is_maxcmdsn,
+			    bhssc->bhssc_opcode);
+#endif
+			return (true);
+		}
+		bhssc->bhssc_cmdsn = htonl(is->is_cmdsn);
+		if ((bhssc->bhssc_opcode & ISCSI_BHS_OPCODE_IMMEDIATE) == 0)
+			is->is_cmdsn++;
+	}
+	bhssc->bhssc_expstatsn = htonl(is->is_statsn + 1);
+
+	return (false);
+}
+
+static void
+iscsi_session_send_postponed(struct iscsi_session *is)
+{
+	struct icl_pdu *request;
+	bool postpone;
+
+	ISCSI_SESSION_LOCK_ASSERT(is);
+
+	if (STAILQ_EMPTY(&is->is_postponed))
+		return;
+	while ((request = STAILQ_FIRST(&is->is_postponed)) != NULL) {
+		postpone = iscsi_pdu_prepare(request);
+		if (postpone)
+			return;
+		STAILQ_REMOVE_HEAD(&is->is_postponed, ip_next);
+		icl_pdu_queue(request);
+	}
+	xpt_release_simq(is->is_sim, 1);
+}
+
+static void
+iscsi_pdu_queue_locked(struct icl_pdu *request)
+{
+	struct iscsi_session *is;
+	bool postpone;
+
+	is = PDU_SESSION(request);
+	ISCSI_SESSION_LOCK_ASSERT(is);
+	iscsi_session_send_postponed(is);
+	postpone = iscsi_pdu_prepare(request);
+	if (postpone) {
+		if (STAILQ_EMPTY(&is->is_postponed))
+			xpt_freeze_simq(is->is_sim, 1);
+		STAILQ_INSERT_TAIL(&is->is_postponed, request, ip_next);
+		return;
+	}
+	icl_pdu_queue(request);
+}
+
+static void
+iscsi_pdu_queue(struct icl_pdu *request)
+{
+	struct iscsi_session *is;
+
+	is = PDU_SESSION(request);
+	ISCSI_SESSION_LOCK(is);
+	iscsi_pdu_queue_locked(request);
+	ISCSI_SESSION_UNLOCK(is);
+}
+
+static void
+iscsi_session_logout(struct iscsi_session *is)
+{
+	struct icl_pdu *request;
+	struct iscsi_bhs_logout_request *bhslr;
+
+	request = icl_pdu_new(is->is_conn, M_NOWAIT);
+	if (request == NULL)
+		return;
+
+	bhslr = (struct iscsi_bhs_logout_request *)request->ip_bhs;
+	bhslr->bhslr_opcode = ISCSI_BHS_OPCODE_LOGOUT_REQUEST;
+	bhslr->bhslr_reason = BHSLR_REASON_CLOSE_SESSION;
+	iscsi_pdu_queue_locked(request);
+}
+
+static void
+iscsi_session_terminate_task(struct iscsi_session *is,
+    struct iscsi_outstanding *io, cam_status status)
+{
+
+	if (io->io_ccb != NULL) {
+		io->io_ccb->ccb_h.status &= ~(CAM_SIM_QUEUED | CAM_STATUS_MASK);
+		io->io_ccb->ccb_h.status |= status;
+		if ((io->io_ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
+			io->io_ccb->ccb_h.status |= CAM_DEV_QFRZN;
+			xpt_freeze_devq(io->io_ccb->ccb_h.path, 1);
+			ISCSI_SESSION_DEBUG(is, "freezing devq");
+		}
+		xpt_done(io->io_ccb);
+	}
+	iscsi_outstanding_remove(is, io);
+}
+
+static void
+iscsi_session_terminate_tasks(struct iscsi_session *is, cam_status status)
+{
+	struct iscsi_outstanding *io, *tmp;
+
+	ISCSI_SESSION_LOCK_ASSERT(is);
+
+	TAILQ_FOREACH_SAFE(io, &is->is_outstanding, io_next, tmp) {
+		iscsi_session_terminate_task(is, io, status);
+	}
+}
+
+static void
+iscsi_session_cleanup(struct iscsi_session *is, bool destroy_sim)
+{
+	struct icl_pdu *pdu;
+
+	ISCSI_SESSION_LOCK_ASSERT(is);
+
+	/*
+	 * Don't queue any new PDUs.
+	 */
+	if (is->is_sim != NULL && is->is_simq_frozen == false) {
+		ISCSI_SESSION_DEBUG(is, "freezing");
+		xpt_freeze_simq(is->is_sim, 1);
+		is->is_simq_frozen = true;
+	}
+
+	/*
+	 * Remove postponed PDUs.
+	 */
+	if (!STAILQ_EMPTY(&is->is_postponed))
+		xpt_release_simq(is->is_sim, 1);
+	while ((pdu = STAILQ_FIRST(&is->is_postponed)) != NULL) {
+		STAILQ_REMOVE_HEAD(&is->is_postponed, ip_next);
+		icl_pdu_free(pdu);
+	}
+
+	if (destroy_sim == false) {
+		/*
+		 * Terminate SCSI tasks, asking CAM to requeue them.
+		 */
+		iscsi_session_terminate_tasks(is, CAM_REQUEUE_REQ);
+		return;
+	}
+
+	iscsi_session_terminate_tasks(is, CAM_DEV_NOT_THERE);
+
+	if (is->is_sim == NULL)
+		return;
+
+	ISCSI_SESSION_DEBUG(is, "deregistering SIM");
+	xpt_async(AC_LOST_DEVICE, is->is_path, NULL);
+
+	if (is->is_simq_frozen) {
+		xpt_release_simq(is->is_sim, 1);
+		is->is_simq_frozen = false;
+	}
+
+	xpt_free_path(is->is_path);
+	is->is_path = NULL;
+	xpt_bus_deregister(cam_sim_path(is->is_sim));
+	cam_sim_free(is->is_sim, TRUE /*free_devq*/);
+	is->is_sim = NULL;
+	is->is_devq = NULL;
+}
+
+static void
+iscsi_maintenance_thread_reconnect(struct iscsi_session *is)
+{
+
+	icl_conn_close(is->is_conn);
+
+	ISCSI_SESSION_LOCK(is);
+
+	is->is_connected = false;
+	is->is_reconnecting = false;
+	is->is_login_phase = false;
+
+#ifdef ICL_KERNEL_PROXY
+	if (is->is_login_pdu != NULL) {
+		icl_pdu_free(is->is_login_pdu);
+		is->is_login_pdu = NULL;
+	}
+	cv_signal(&is->is_login_cv);
+#endif
+ 
+	if (fail_on_disconnection) {
+		ISCSI_SESSION_DEBUG(is, "connection failed, destroying devices");
+		iscsi_session_cleanup(is, true);
+	} else {
+		iscsi_session_cleanup(is, false);
+	}
+ 
+	KASSERT(TAILQ_EMPTY(&is->is_outstanding),
+	    ("destroying session with active tasks"));
+	KASSERT(STAILQ_EMPTY(&is->is_postponed),
+	    ("destroying session with postponed PDUs"));
+
+	/*
+	 * Request immediate reconnection from iscsid(8).
+	 */
+	//ISCSI_SESSION_DEBUG(is, "waking up iscsid(8)");
+	is->is_waiting_for_iscsid = true;
+	strlcpy(is->is_reason, "Waiting for iscsid(8)", sizeof(is->is_reason));
+	is->is_timeout = 0;
+	ISCSI_SESSION_UNLOCK(is);
+	cv_signal(&is->is_softc->sc_cv);
+}
+
+static void
+iscsi_maintenance_thread_terminate(struct iscsi_session *is)
+{
+	struct iscsi_softc *sc;
+
+	sc = is->is_softc;
+	sx_xlock(&sc->sc_lock);
+	TAILQ_REMOVE(&sc->sc_sessions, is, is_next);
+	sx_xunlock(&sc->sc_lock);
+
+	icl_conn_close(is->is_conn);
+	callout_drain(&is->is_callout);
+
+	ISCSI_SESSION_LOCK(is);
+
+	KASSERT(is->is_terminating, ("is_terminating == false"));
+
+#ifdef ICL_KERNEL_PROXY
+	if (is->is_login_pdu != NULL) {
+		icl_pdu_free(is->is_login_pdu);
+		is->is_login_pdu = NULL;
+	}
+	cv_signal(&is->is_login_cv);
+#endif
+
+	iscsi_session_cleanup(is, true);
+
+	KASSERT(TAILQ_EMPTY(&is->is_outstanding),
+	    ("destroying session with active tasks"));
+	KASSERT(STAILQ_EMPTY(&is->is_postponed),
+	    ("destroying session with postponed PDUs"));
+
+	ISCSI_SESSION_UNLOCK(is);
+
+	icl_conn_free(is->is_conn);
+	mtx_destroy(&is->is_lock);
+	cv_destroy(&is->is_maintenance_cv);
+#ifdef ICL_KERNEL_PROXY
+	cv_destroy(&is->is_login_cv);
+#endif
+
+	ISCSI_SESSION_DEBUG(is, "terminated");
+	free(is, M_ISCSI);
+
+	/*
+	 * The iscsi_unload() routine might be waiting.
+	 */
+	cv_signal(&sc->sc_cv);
+}
+
+static void
+iscsi_maintenance_thread(void *arg)
+{
+	struct iscsi_session *is = arg;
+
+	ISCSI_SESSION_LOCK(is);
+	for (;;) {
+		if (is->is_reconnecting == false &&
+		    is->is_terminating == false &&
+		    (STAILQ_EMPTY(&is->is_postponed) ||
+		     ISCSI_SNGT(is->is_cmdsn, is->is_maxcmdsn)))
+			cv_wait(&is->is_maintenance_cv, &is->is_lock);
+
+		/* Terminate supersedes reconnect. */
+		if (is->is_terminating) {
+			ISCSI_SESSION_UNLOCK(is);
+			iscsi_maintenance_thread_terminate(is);
+			kthread_exit();
+			return;
+		}
+
+		if (is->is_reconnecting) {
+			ISCSI_SESSION_UNLOCK(is);
+			iscsi_maintenance_thread_reconnect(is);
+			ISCSI_SESSION_LOCK(is);
+			continue;
+		}
+
+		iscsi_session_send_postponed(is);
+	}
+	ISCSI_SESSION_UNLOCK(is);
+}
+
+static void
+iscsi_session_reconnect(struct iscsi_session *is)
+{
+
+	/*
+	 * XXX: We can't use locking here, because
+	 * 	it's being called from various contexts.
+	 * 	Hope it doesn't break anything.
+	 */
+	if (is->is_reconnecting)
+		return;
+
+	is->is_reconnecting = true;
+	cv_signal(&is->is_maintenance_cv);
+}
+
+static void
+iscsi_session_terminate(struct iscsi_session *is)
+{
+
+	if (is->is_terminating)
+		return;
+
+	is->is_terminating = true;
+
+#if 0
+	iscsi_session_logout(is);
+#endif
+	cv_signal(&is->is_maintenance_cv);
+}
+
+static void
+iscsi_callout(void *context)
+{
+	struct icl_pdu *request;
+	struct iscsi_bhs_nop_out *bhsno;
+	struct iscsi_session *is;
+	bool reconnect_needed = false;
+
+	is = context;
+
+	ISCSI_SESSION_LOCK(is);
+	if (is->is_terminating) {
+		ISCSI_SESSION_UNLOCK(is);
+		return;
+	}
+
+	callout_schedule(&is->is_callout, 1 * hz);
+
+	is->is_timeout++;
+
+	if (is->is_waiting_for_iscsid) {
+		if (iscsid_timeout > 0 && is->is_timeout > iscsid_timeout) {
+			ISCSI_SESSION_WARN(is, "timed out waiting for iscsid(8) "
+			    "for %d seconds; reconnecting",
+			    is->is_timeout);
+			reconnect_needed = true;
+		}
+		goto out;
+	}
+
+	if (is->is_login_phase) {
+		if (login_timeout > 0 && is->is_timeout > login_timeout) {
+			ISCSI_SESSION_WARN(is, "login timed out after %d seconds; "
+			    "reconnecting", is->is_timeout);
+			reconnect_needed = true;
+		}
+		goto out;
+	}
+
+	if (ping_timeout <= 0) {
+		/*
+		 * Pings are disabled.  Don't send NOP-Out in this case.
+		 * Reset the timeout, to avoid triggering reconnection,
+		 * should the user decide to reenable them.
+		 */
+		is->is_timeout = 0;
+		goto out;
+	}
+
+	if (is->is_timeout >= ping_timeout) {
+		ISCSI_SESSION_WARN(is, "no ping reply (NOP-In) after %d seconds; "
+		    "reconnecting", ping_timeout);
+		reconnect_needed = true;
+		goto out;
+	}
+
+	ISCSI_SESSION_UNLOCK(is);
+
+	/*
+	 * If the ping was reset less than one second ago - which means
+	 * that we've received some PDU during the last second - assume
+	 * the traffic flows correctly and don't bother sending a NOP-Out.
+	 *
+	 * (It's 2 - one for one second, and one for incrementing is_timeout
+	 * earlier in this routine.)
+	 */
+	if (is->is_timeout < 2)
+		return;
+
+	request = icl_pdu_new(is->is_conn, M_NOWAIT);
+	if (request == NULL) {
+		ISCSI_SESSION_WARN(is, "failed to allocate PDU");
+		return;
+	}
+	bhsno = (struct iscsi_bhs_nop_out *)request->ip_bhs;
+	bhsno->bhsno_opcode = ISCSI_BHS_OPCODE_NOP_OUT |
+	    ISCSI_BHS_OPCODE_IMMEDIATE;
+	bhsno->bhsno_flags = 0x80;
+	bhsno->bhsno_target_transfer_tag = 0xffffffff;
+	iscsi_pdu_queue(request);
+	return;
+
+out:
+	if (is->is_terminating) {
+		ISCSI_SESSION_UNLOCK(is);
+		return;
+	}
+
+	ISCSI_SESSION_UNLOCK(is);
+
+	if (reconnect_needed)
+		iscsi_session_reconnect(is);
+}
+
+static void
+iscsi_pdu_update_statsn(const struct icl_pdu *response)
+{
+	const struct iscsi_bhs_data_in *bhsdi;
+	struct iscsi_session *is;
+	uint32_t expcmdsn, maxcmdsn, statsn;
+
+	is = PDU_SESSION(response);
+
+	ISCSI_SESSION_LOCK_ASSERT(is);
+
+	/*
+	 * We're only using fields common for all the response
+	 * (target -> initiator) PDUs.
+	 */
+	bhsdi = (const struct iscsi_bhs_data_in *)response->ip_bhs;
+	/*
+	 * Ok, I lied.  In case of Data-In, "The fields StatSN, Status,
+	 * and Residual Count only have meaningful content if the S bit
+	 * is set to 1", so we also need to check the bit specific for
+	 * Data-In PDU.
+	 */
+	if (bhsdi->bhsdi_opcode != ISCSI_BHS_OPCODE_SCSI_DATA_IN ||
+	    (bhsdi->bhsdi_flags & BHSDI_FLAGS_S) != 0) {
+		statsn = ntohl(bhsdi->bhsdi_statsn);
+		if (statsn != is->is_statsn && statsn != (is->is_statsn + 1)) {
+			/* XXX: This is normal situation for MCS */
+			ISCSI_SESSION_WARN(is, "PDU 0x%x StatSN %u != "
+			    "session ExpStatSN %u (or + 1); reconnecting",
+			    bhsdi->bhsdi_opcode, statsn, is->is_statsn);
+			iscsi_session_reconnect(is);
+		}
+		if (ISCSI_SNGT(statsn, is->is_statsn))
+			is->is_statsn = statsn;
+	}
+
+	expcmdsn = ntohl(bhsdi->bhsdi_expcmdsn);
+	maxcmdsn = ntohl(bhsdi->bhsdi_maxcmdsn);
+
+	if (ISCSI_SNLT(maxcmdsn + 1, expcmdsn)) {
+		ISCSI_SESSION_DEBUG(is,
+		    "PDU MaxCmdSN %u + 1 < PDU ExpCmdSN %u; ignoring",
+		    maxcmdsn, expcmdsn);
+	} else {
+		if (ISCSI_SNGT(maxcmdsn, is->is_maxcmdsn)) {
+			is->is_maxcmdsn = maxcmdsn;
+
+			/*
+			 * Command window increased; kick the maintanance thread
+			 * to send out postponed commands.
+			 */
+			if (!STAILQ_EMPTY(&is->is_postponed))
+				cv_signal(&is->is_maintenance_cv);
+		} else if (ISCSI_SNLT(maxcmdsn, is->is_maxcmdsn)) {
+			/* XXX: This is normal situation for MCS */
+			ISCSI_SESSION_DEBUG(is,
+			    "PDU MaxCmdSN %u < session MaxCmdSN %u; ignoring",
+			    maxcmdsn, is->is_maxcmdsn);
+		}
+
+		if (ISCSI_SNGT(expcmdsn, is->is_expcmdsn)) {
+			is->is_expcmdsn = expcmdsn;
+		} else if (ISCSI_SNLT(expcmdsn, is->is_expcmdsn)) {
+			/* XXX: This is normal situation for MCS */
+			ISCSI_SESSION_DEBUG(is,
+			    "PDU ExpCmdSN %u < session ExpCmdSN %u; ignoring",
+			    expcmdsn, is->is_expcmdsn);
+		}
+	}
+
+	/*
+	 * Every incoming PDU - not just NOP-In - resets the ping timer.
+	 * The purpose of the timeout is to reset the connection when it stalls;
+	 * we don't want this to happen when NOP-In or NOP-Out ends up delayed
+	 * in some queue.
+	 */
+	is->is_timeout = 0;
+}
+
+static void
+iscsi_receive_callback(struct icl_pdu *response)
+{
+	struct iscsi_session *is;
+
+	is = PDU_SESSION(response);
+
+	ISCSI_SESSION_LOCK(is);
+
+#ifdef ICL_KERNEL_PROXY
+	if (is->is_login_phase) {
+		if (is->is_login_pdu == NULL)
+			is->is_login_pdu = response;
+		else
+			icl_pdu_free(response);
+		ISCSI_SESSION_UNLOCK(is);
+		cv_signal(&is->is_login_cv);
+		return;
+	}
+#endif
+
+	iscsi_pdu_update_statsn(response);
+	
+	/*
+	 * The handling routine is responsible for freeing the PDU
+	 * when it's no longer needed.
+	 */
+	switch (response->ip_bhs->bhs_opcode) {
+	case ISCSI_BHS_OPCODE_NOP_IN:
+		iscsi_pdu_handle_nop_in(response);
+		ISCSI_SESSION_UNLOCK(is);
+		break;
+	case ISCSI_BHS_OPCODE_SCSI_RESPONSE:
+		iscsi_pdu_handle_scsi_response(response);
+		/* Session lock dropped inside. */
+		ISCSI_SESSION_LOCK_ASSERT_NOT(is);
+		break;
+	case ISCSI_BHS_OPCODE_TASK_RESPONSE:
+		iscsi_pdu_handle_task_response(response);
+		ISCSI_SESSION_UNLOCK(is);
+		break;
+	case ISCSI_BHS_OPCODE_SCSI_DATA_IN:
+		iscsi_pdu_handle_data_in(response);
+		/* Session lock dropped inside. */
+		ISCSI_SESSION_LOCK_ASSERT_NOT(is);
+		break;
+	case ISCSI_BHS_OPCODE_LOGOUT_RESPONSE:
+		iscsi_pdu_handle_logout_response(response);
+		ISCSI_SESSION_UNLOCK(is);
+		break;
+	case ISCSI_BHS_OPCODE_R2T:
+		iscsi_pdu_handle_r2t(response);
+		ISCSI_SESSION_UNLOCK(is);
+		break;
+	case ISCSI_BHS_OPCODE_ASYNC_MESSAGE:
+		iscsi_pdu_handle_async_message(response);
+		ISCSI_SESSION_UNLOCK(is);
+		break;
+	case ISCSI_BHS_OPCODE_REJECT:
+		iscsi_pdu_handle_reject(response);
+		ISCSI_SESSION_UNLOCK(is);
+		break;
+	default:
+		ISCSI_SESSION_WARN(is, "received PDU with unsupported "
+		    "opcode 0x%x; reconnecting",
+		    response->ip_bhs->bhs_opcode);
+		iscsi_session_reconnect(is);
+		ISCSI_SESSION_UNLOCK(is);
+		icl_pdu_free(response);
+	}
+}
+
+static void
+iscsi_error_callback(struct icl_conn *ic)
+{
+	struct iscsi_session *is;
+
+	is = CONN_SESSION(ic);
+
+	ISCSI_SESSION_WARN(is, "connection error; reconnecting");
+	iscsi_session_reconnect(is);
+}
+
+static void
+iscsi_pdu_handle_nop_in(struct icl_pdu *response)
+{
+	struct iscsi_session *is;
+	struct iscsi_bhs_nop_out *bhsno;
+	struct iscsi_bhs_nop_in *bhsni;
+	struct icl_pdu *request;
+	void *data = NULL;
+	size_t datasize;
+	int error;
+
+	is = PDU_SESSION(response);
+	bhsni = (struct iscsi_bhs_nop_in *)response->ip_bhs;
+
+	if (bhsni->bhsni_target_transfer_tag == 0xffffffff) {
+		/*
+		 * Nothing to do; iscsi_pdu_update_statsn() already
+		 * zeroed the timeout.
+		 */
+		icl_pdu_free(response);
+		return;
+	}
+
+	datasize = icl_pdu_data_segment_length(response);
+	if (datasize > 0) {
+		data = malloc(datasize, M_ISCSI, M_NOWAIT | M_ZERO);
+		if (data == NULL) {
+			ISCSI_SESSION_WARN(is, "failed to allocate memory; "
+			    "reconnecting");
+			icl_pdu_free(response);
+			iscsi_session_reconnect(is);
+			return;
+		}
+		icl_pdu_get_data(response, 0, data, datasize);
+	}
+
+	request = icl_pdu_new(response->ip_conn, M_NOWAIT);
+	if (request == NULL) {
+		ISCSI_SESSION_WARN(is, "failed to allocate memory; "
+		    "reconnecting");
+		free(data, M_ISCSI);
+		icl_pdu_free(response);
+		iscsi_session_reconnect(is);
+		return;
+	}
+	bhsno = (struct iscsi_bhs_nop_out *)request->ip_bhs;
+	bhsno->bhsno_opcode = ISCSI_BHS_OPCODE_NOP_OUT |
+	    ISCSI_BHS_OPCODE_IMMEDIATE;
+	bhsno->bhsno_flags = 0x80;
+	bhsno->bhsno_initiator_task_tag = 0xffffffff;
+	bhsno->bhsno_target_transfer_tag = bhsni->bhsni_target_transfer_tag;
+	if (datasize > 0) {
+		error = icl_pdu_append_data(request, data, datasize, M_NOWAIT);
+		if (error != 0) {
+			ISCSI_SESSION_WARN(is, "failed to allocate memory; "
+			    "reconnecting");
+			free(data, M_ISCSI);
+			icl_pdu_free(request);
+			icl_pdu_free(response);
+			iscsi_session_reconnect(is);
+			return;
+		}
+		free(data, M_ISCSI);
+	}
+
+	icl_pdu_free(response);
+	iscsi_pdu_queue_locked(request);
+}
+
+static void
+iscsi_pdu_handle_scsi_response(struct icl_pdu *response)
+{
+	struct iscsi_bhs_scsi_response *bhssr;
+	struct iscsi_outstanding *io;
+	struct iscsi_session *is;
+	union ccb *ccb;
+	struct ccb_scsiio *csio;
+	size_t data_segment_len, received;
+	uint16_t sense_len;
+
+	is = PDU_SESSION(response);
+
+	bhssr = (struct iscsi_bhs_scsi_response *)response->ip_bhs;
+	io = iscsi_outstanding_find(is, bhssr->bhssr_initiator_task_tag);
+	if (io == NULL || io->io_ccb == NULL) {
+		ISCSI_SESSION_WARN(is, "bad itt 0x%x", bhssr->bhssr_initiator_task_tag);
+		icl_pdu_free(response);
+		iscsi_session_reconnect(is);
+		ISCSI_SESSION_UNLOCK(is);
+		return;
+	}
+
+	ccb = io->io_ccb;
+	received = io->io_received;
+	iscsi_outstanding_remove(is, io);
+	ISCSI_SESSION_UNLOCK(is);
+
+	if (bhssr->bhssr_response != BHSSR_RESPONSE_COMMAND_COMPLETED) {
+		ISCSI_SESSION_WARN(is, "service response 0x%x", bhssr->bhssr_response);
+ 		if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
+ 			xpt_freeze_devq(ccb->ccb_h.path, 1);
+			ISCSI_SESSION_DEBUG(is, "freezing devq");
+		}
+ 		ccb->ccb_h.status = CAM_REQ_CMP_ERR | CAM_DEV_QFRZN;
+	} else if (bhssr->bhssr_status == 0) {
+		ccb->ccb_h.status = CAM_REQ_CMP;
+	} else {
+ 		if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
+ 			xpt_freeze_devq(ccb->ccb_h.path, 1);
+			ISCSI_SESSION_DEBUG(is, "freezing devq");
+		}
+ 		ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR | CAM_DEV_QFRZN;
+		ccb->csio.scsi_status = bhssr->bhssr_status;
+	}
+
+	csio = &ccb->csio;
+	data_segment_len = icl_pdu_data_segment_length(response);
+	if (data_segment_len > 0) {
+		if (data_segment_len < sizeof(sense_len)) {
+			ISCSI_SESSION_WARN(is, "truncated data segment (%zd bytes)",
+			    data_segment_len);
+			if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
+				xpt_freeze_devq(ccb->ccb_h.path, 1);
+				ISCSI_SESSION_DEBUG(is, "freezing devq");
+			}
+			ccb->ccb_h.status = CAM_REQ_CMP_ERR | CAM_DEV_QFRZN;
+			goto out;
+		}
+		icl_pdu_get_data(response, 0, &sense_len, sizeof(sense_len));
+		sense_len = ntohs(sense_len);
+#if 0
+		ISCSI_SESSION_DEBUG(is, "sense_len %d, data len %zd",
+		    sense_len, data_segment_len);
+#endif
+		if (sizeof(sense_len) + sense_len > data_segment_len) {
+			ISCSI_SESSION_WARN(is, "truncated data segment "
+			    "(%zd bytes, should be %zd)",
+			    data_segment_len, sizeof(sense_len) + sense_len);
+			if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
+				xpt_freeze_devq(ccb->ccb_h.path, 1);
+				ISCSI_SESSION_DEBUG(is, "freezing devq");
+			}
+			ccb->ccb_h.status = CAM_REQ_CMP_ERR | CAM_DEV_QFRZN;
+			goto out;
+		} else if (sizeof(sense_len) + sense_len < data_segment_len)
+			ISCSI_SESSION_WARN(is, "oversize data segment "
+			    "(%zd bytes, should be %zd)",
+			    data_segment_len, sizeof(sense_len) + sense_len);
+		if (sense_len > csio->sense_len) {
+			ISCSI_SESSION_DEBUG(is, "truncating sense from %d to %d",
+			    sense_len, csio->sense_len);
+			sense_len = csio->sense_len;
+		}
+		icl_pdu_get_data(response, sizeof(sense_len), &csio->sense_data, sense_len);
+		csio->sense_resid = csio->sense_len - sense_len;
+		ccb->ccb_h.status |= CAM_AUTOSNS_VALID;
+	}
+
+out:
+	if (bhssr->bhssr_flags & BHSSR_FLAGS_RESIDUAL_UNDERFLOW)
+		csio->resid = ntohl(bhssr->bhssr_residual_count);
+
+	if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
+		KASSERT(received <= csio->dxfer_len,
+		    ("received > csio->dxfer_len"));
+		if (received < csio->dxfer_len) {
+			if (csio->resid != csio->dxfer_len - received) {
+				ISCSI_SESSION_WARN(is, "underflow mismatch: "
+				    "target indicates %d, we calculated %zd",
+				    csio->resid, csio->dxfer_len - received);
+			}
+			csio->resid = csio->dxfer_len - received;
+		}
+	}
+
+	xpt_done(ccb);
+	icl_pdu_free(response);
+}
+
+static void
+iscsi_pdu_handle_task_response(struct icl_pdu *response)
+{
+	struct iscsi_bhs_task_management_response *bhstmr;
+	struct iscsi_outstanding *io, *aio;
+	struct iscsi_session *is;
+
+	is = PDU_SESSION(response);
+
+	bhstmr = (struct iscsi_bhs_task_management_response *)response->ip_bhs;
+	io = iscsi_outstanding_find(is, bhstmr->bhstmr_initiator_task_tag);
+	if (io == NULL || io->io_ccb != NULL) {
+		ISCSI_SESSION_WARN(is, "bad itt 0x%x",
+		    bhstmr->bhstmr_initiator_task_tag);
+		icl_pdu_free(response);
+		iscsi_session_reconnect(is);
+		return;
+	}
+
+	if (bhstmr->bhstmr_response != BHSTMR_RESPONSE_FUNCTION_COMPLETE) {
+		ISCSI_SESSION_WARN(is, "task response 0x%x",
+		    bhstmr->bhstmr_response);
+	} else {
+		aio = iscsi_outstanding_find(is, io->io_datasn);
+		if (aio != NULL && aio->io_ccb != NULL)
+			iscsi_session_terminate_task(is, aio, CAM_REQ_ABORTED);
+	}
+
+	iscsi_outstanding_remove(is, io);
+	icl_pdu_free(response);
+}
+
+static void
+iscsi_pdu_handle_data_in(struct icl_pdu *response)
+{
+	struct iscsi_bhs_data_in *bhsdi;
+	struct iscsi_outstanding *io;
+	struct iscsi_session *is;
+	union ccb *ccb;
+	struct ccb_scsiio *csio;
+	size_t data_segment_len, received, oreceived;
+	
+	is = PDU_SESSION(response);
+	bhsdi = (struct iscsi_bhs_data_in *)response->ip_bhs;
+	io = iscsi_outstanding_find(is, bhsdi->bhsdi_initiator_task_tag);
+	if (io == NULL || io->io_ccb == NULL) {
+		ISCSI_SESSION_WARN(is, "bad itt 0x%x", bhsdi->bhsdi_initiator_task_tag);
+		icl_pdu_free(response);
+		iscsi_session_reconnect(is);
+		ISCSI_SESSION_UNLOCK(is);
+		return;
+	}
+
+	data_segment_len = icl_pdu_data_segment_length(response);
+	if (data_segment_len == 0) {
+		/*
+		 * "The sending of 0 length data segments should be avoided,
+		 * but initiators and targets MUST be able to properly receive
+		 * 0 length data segments."
+		 */
+		ISCSI_SESSION_UNLOCK(is);
+		icl_pdu_free(response);
+		return;
+	}
+
+	/*
+	 * We need to track this for security reasons - without it, malicious target
+	 * could respond to SCSI READ without sending Data-In PDUs, which would result
+	 * in read operation on the initiator side returning random kernel data.
+	 */
+	if (ntohl(bhsdi->bhsdi_buffer_offset) != io->io_received) {
+		ISCSI_SESSION_WARN(is, "data out of order; expected offset %zd, got %zd",
+		    io->io_received, (size_t)ntohl(bhsdi->bhsdi_buffer_offset));
+		icl_pdu_free(response);
+		iscsi_session_reconnect(is);
+		ISCSI_SESSION_UNLOCK(is);
+		return;
+	}
+
+	ccb = io->io_ccb;
+	csio = &ccb->csio;
+
+	if (io->io_received + data_segment_len > csio->dxfer_len) {
+		ISCSI_SESSION_WARN(is, "oversize data segment (%zd bytes "
+		    "at offset %zd, buffer is %d)",
+		    data_segment_len, io->io_received, csio->dxfer_len);
+		icl_pdu_free(response);
+		iscsi_session_reconnect(is);
+		ISCSI_SESSION_UNLOCK(is);
+		return;
+	}
+
+	oreceived = io->io_received;
+	io->io_received += data_segment_len;
+	received = io->io_received;
+	if ((bhsdi->bhsdi_flags & BHSDI_FLAGS_S) != 0)
+		iscsi_outstanding_remove(is, io);
+	ISCSI_SESSION_UNLOCK(is);
+
+	icl_pdu_get_data(response, 0, csio->data_ptr + oreceived, data_segment_len);
+
+	/*
+	 * XXX: Check DataSN.
+	 * XXX: Check F.
+	 */
+	if ((bhsdi->bhsdi_flags & BHSDI_FLAGS_S) == 0) {
+		/*
+		 * Nothing more to do.
+		 */
+		icl_pdu_free(response);
+		return;
+	}
+
+	//ISCSI_SESSION_DEBUG(is, "got S flag; status 0x%x", bhsdi->bhsdi_status);
+	if (bhsdi->bhsdi_status == 0) {
+		ccb->ccb_h.status = CAM_REQ_CMP;
+	} else {
+		if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
+			xpt_freeze_devq(ccb->ccb_h.path, 1);
+			ISCSI_SESSION_DEBUG(is, "freezing devq");
+		}
+		ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR | CAM_DEV_QFRZN;
+		csio->scsi_status = bhsdi->bhsdi_status;
+	}
+
+	if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
+		KASSERT(received <= csio->dxfer_len,
+		    ("received > csio->dxfer_len"));
+		if (received < csio->dxfer_len) {
+			csio->resid = ntohl(bhsdi->bhsdi_residual_count);
+			if (csio->resid != csio->dxfer_len - received) {
+				ISCSI_SESSION_WARN(is, "underflow mismatch: "
+				    "target indicates %d, we calculated %zd",
+				    csio->resid, csio->dxfer_len - received);
+			}
+			csio->resid = csio->dxfer_len - received;
+		}
+	}
+
+	xpt_done(ccb);
+	icl_pdu_free(response);
+}
+
+static void
+iscsi_pdu_handle_logout_response(struct icl_pdu *response)
+{
+
+	ISCSI_SESSION_DEBUG(PDU_SESSION(response), "logout response");
+	icl_pdu_free(response);
+}
+
+static void
+iscsi_pdu_handle_r2t(struct icl_pdu *response)
+{
+	struct icl_pdu *request;
+	struct iscsi_session *is;
+	struct iscsi_bhs_r2t *bhsr2t;
+	struct iscsi_bhs_data_out *bhsdo;
+	struct iscsi_outstanding *io;
+	struct ccb_scsiio *csio;
+	size_t off, len, total_len;
+	int error;
+
+	is = PDU_SESSION(response);
+
+	bhsr2t = (struct iscsi_bhs_r2t *)response->ip_bhs;
+	io = iscsi_outstanding_find(is, bhsr2t->bhsr2t_initiator_task_tag);
+	if (io == NULL || io->io_ccb == NULL) {
+		ISCSI_SESSION_WARN(is, "bad itt 0x%x; reconnecting",
+		    bhsr2t->bhsr2t_initiator_task_tag);
+		icl_pdu_free(response);
+		iscsi_session_reconnect(is);
+		return;
+	}
+
+	csio = &io->io_ccb->csio;
+
+	if ((csio->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_OUT) {
+		ISCSI_SESSION_WARN(is, "received R2T for read command; reconnecting");
+		icl_pdu_free(response);
+		iscsi_session_reconnect(is);
+		return;
+	}
+
+	/*
+	 * XXX: Verify R2TSN.
+	 */
+
+	io->io_datasn = 0;
+
+	off = ntohl(bhsr2t->bhsr2t_buffer_offset);
+	if (off > csio->dxfer_len) {
+		ISCSI_SESSION_WARN(is, "target requested invalid offset "
+		    "%zd, buffer is is %d; reconnecting", off, csio->dxfer_len);
+		icl_pdu_free(response);
+		iscsi_session_reconnect(is);
+		return;
+	}
+
+	total_len = ntohl(bhsr2t->bhsr2t_desired_data_transfer_length);
+	if (total_len == 0 || total_len > csio->dxfer_len) {
+		ISCSI_SESSION_WARN(is, "target requested invalid length "
+		    "%zd, buffer is %d; reconnecting", total_len, csio->dxfer_len);
+		icl_pdu_free(response);
+		iscsi_session_reconnect(is);
+		return;
+	}
+
+	//ISCSI_SESSION_DEBUG(is, "r2t; off %zd, len %zd", off, total_len);
+
+	for (;;) {
+		len = total_len;
+
+		if (len > is->is_max_data_segment_length)
+			len = is->is_max_data_segment_length;
+
+		if (off + len > csio->dxfer_len) {
+			ISCSI_SESSION_WARN(is, "target requested invalid "
+			    "length/offset %zd, buffer is %d; reconnecting",
+			    off + len, csio->dxfer_len);
+			icl_pdu_free(response);
+			iscsi_session_reconnect(is);
+			return;
+		}
+
+		request = icl_pdu_new(response->ip_conn, M_NOWAIT);
+		if (request == NULL) {
+			icl_pdu_free(response);
+			iscsi_session_reconnect(is);
+			return;
+		}
+
+		bhsdo = (struct iscsi_bhs_data_out *)request->ip_bhs;
+		bhsdo->bhsdo_opcode = ISCSI_BHS_OPCODE_SCSI_DATA_OUT;
+		bhsdo->bhsdo_lun = bhsr2t->bhsr2t_lun;
+		bhsdo->bhsdo_initiator_task_tag =
+		    bhsr2t->bhsr2t_initiator_task_tag;
+		bhsdo->bhsdo_target_transfer_tag =
+		    bhsr2t->bhsr2t_target_transfer_tag;
+		bhsdo->bhsdo_datasn = htonl(io->io_datasn++);
+		bhsdo->bhsdo_buffer_offset = htonl(off);
+		error = icl_pdu_append_data(request, csio->data_ptr + off, len,
+		    M_NOWAIT);
+		if (error != 0) {
+			ISCSI_SESSION_WARN(is, "failed to allocate memory; "
+			    "reconnecting");
+			icl_pdu_free(request);
+			icl_pdu_free(response);
+			iscsi_session_reconnect(is);
+			return;
+		}
+
+		off += len;
+		total_len -= len;
+
+		if (total_len == 0) {
+			bhsdo->bhsdo_flags |= BHSDO_FLAGS_F;
+			//ISCSI_SESSION_DEBUG(is, "setting F, off %zd", off);
+		} else {
+			//ISCSI_SESSION_DEBUG(is, "not finished, off %zd", off);
+		}
+
+		iscsi_pdu_queue_locked(request);
+
+		if (total_len == 0)
+			break;
+	}
+
+	icl_pdu_free(response);
+}
+
+static void
+iscsi_pdu_handle_async_message(struct icl_pdu *response)
+{
+	struct iscsi_bhs_asynchronous_message *bhsam;
+	struct iscsi_session *is;
+
+	is = PDU_SESSION(response);
+	bhsam = (struct iscsi_bhs_asynchronous_message *)response->ip_bhs;
+	switch (bhsam->bhsam_async_event) {
+	case BHSAM_EVENT_TARGET_REQUESTS_LOGOUT:
+		ISCSI_SESSION_WARN(is, "target requests logout; removing session");
+		iscsi_session_logout(is);
+		iscsi_session_terminate(is);
+		break;
+	case BHSAM_EVENT_TARGET_TERMINATES_CONNECTION:
+		ISCSI_SESSION_WARN(is, "target indicates it will drop drop the connection");
+		break;
+	case BHSAM_EVENT_TARGET_TERMINATES_SESSION:
+		ISCSI_SESSION_WARN(is, "target indicates it will drop drop the session");
+		break;
+	default:
+		/*
+		 * XXX: Technically, we're obligated to also handle
+		 * 	parameter renegotiation.
+		 */
+		ISCSI_SESSION_WARN(is, "ignoring AsyncEvent %d", bhsam->bhsam_async_event);
+		break;
+	}
+
+	icl_pdu_free(response);
+}
+
+static void
+iscsi_pdu_handle_reject(struct icl_pdu *response)
+{
+	struct iscsi_bhs_reject *bhsr;
+	struct iscsi_session *is;
+
+	is = PDU_SESSION(response);
+	bhsr = (struct iscsi_bhs_reject *)response->ip_bhs;
+	ISCSI_SESSION_WARN(is, "received Reject PDU, reason 0x%x; protocol error?",
+	    bhsr->bhsr_reason);
+
+	icl_pdu_free(response);
+}
+
+static int
+iscsi_ioctl_daemon_wait(struct iscsi_softc *sc,
+    struct iscsi_daemon_request *request)
+{
+	struct iscsi_session *is;
+	int error;
+
+	sx_slock(&sc->sc_lock);
+	for (;;) {
+		TAILQ_FOREACH(is, &sc->sc_sessions, is_next) {
+			ISCSI_SESSION_LOCK(is);
+			if (is->is_waiting_for_iscsid)
+				break;
+			ISCSI_SESSION_UNLOCK(is);
+		}
+
+		if (is == NULL) {
+			/*
+			 * No session requires attention from iscsid(8); wait.
+			 */
+			error = cv_wait_sig(&sc->sc_cv, &sc->sc_lock);
+			if (error != 0) {
+				sx_sunlock(&sc->sc_lock);
+				return (error);
+			}
+			continue;
+		}
+
+		is->is_waiting_for_iscsid = false;
+		is->is_login_phase = true;
+		is->is_reason[0] = '\0';
+		ISCSI_SESSION_UNLOCK(is);
+
+		request->idr_session_id = is->is_id;
+		memcpy(&request->idr_isid, &is->is_isid,
+		    sizeof(request->idr_isid));
+		request->idr_tsih = 0;	/* New or reinstated session. */
+		memcpy(&request->idr_conf, &is->is_conf,
+		    sizeof(request->idr_conf));
+
+		sx_sunlock(&sc->sc_lock);
+		return (0);
+	}
+}
+
+static int
+iscsi_ioctl_daemon_handoff(struct iscsi_softc *sc,
+    struct iscsi_daemon_handoff *handoff)
+{
+	struct iscsi_session *is;
+	int error;
+
+	sx_slock(&sc->sc_lock);
+
+	/*
+	 * Find the session to hand off socket to.
+	 */
+	TAILQ_FOREACH(is, &sc->sc_sessions, is_next) {
+		if (is->is_id == handoff->idh_session_id)
+			break;
+	}
+	if (is == NULL) {
+		sx_sunlock(&sc->sc_lock);
+		return (ESRCH);
+	}
+	ISCSI_SESSION_LOCK(is);
+	if (is->is_conf.isc_discovery || is->is_terminating) {
+		ISCSI_SESSION_UNLOCK(is);
+		sx_sunlock(&sc->sc_lock);
+		return (EINVAL);
+	}
+	if (is->is_connected) {
+		/*
+		 * This might have happened because another iscsid(8)
+		 * instance handed off the connection in the meantime.
+		 * Just return.
+		 */
+		ISCSI_SESSION_WARN(is, "handoff on already connected "
+		    "session");
+		ISCSI_SESSION_UNLOCK(is);
+		sx_sunlock(&sc->sc_lock);
+		return (EBUSY);
+	}
+
+	strlcpy(is->is_target_alias, handoff->idh_target_alias,
+	    sizeof(is->is_target_alias));
+	is->is_tsih = handoff->idh_tsih;
+	is->is_statsn = handoff->idh_statsn;
+	is->is_initial_r2t = handoff->idh_initial_r2t;
+	is->is_immediate_data = handoff->idh_immediate_data;
+	is->is_max_data_segment_length = handoff->idh_max_data_segment_length;
+	is->is_max_burst_length = handoff->idh_max_burst_length;
+	is->is_first_burst_length = handoff->idh_first_burst_length;
+
+	if (handoff->idh_header_digest == ISCSI_DIGEST_CRC32C)
+		is->is_conn->ic_header_crc32c = true;
+	else
+		is->is_conn->ic_header_crc32c = false;
+	if (handoff->idh_data_digest == ISCSI_DIGEST_CRC32C)
+		is->is_conn->ic_data_crc32c = true;
+	else
+		is->is_conn->ic_data_crc32c = false;
+
+	is->is_cmdsn = 0;
+	is->is_expcmdsn = 0;
+	is->is_maxcmdsn = 0;
+	is->is_waiting_for_iscsid = false;
+	is->is_login_phase = false;
+	is->is_timeout = 0;
+	is->is_connected = true;
+	is->is_reason[0] = '\0';
+
+	ISCSI_SESSION_UNLOCK(is);
+
+#ifdef ICL_KERNEL_PROXY
+	if (handoff->idh_socket != 0) {
+#endif
+		/*
+		 * Handoff without using ICL proxy.
+		 */
+		error = icl_conn_handoff(is->is_conn, handoff->idh_socket);
+		if (error != 0) {
+			sx_sunlock(&sc->sc_lock);
+			iscsi_session_terminate(is);
+			return (error);
+		}
+#ifdef ICL_KERNEL_PROXY
+	}
+#endif
+
+	sx_sunlock(&sc->sc_lock);
+
+	if (is->is_sim != NULL) {
+		/*
+		 * When reconnecting, there already is SIM allocated for the session.
+		 */
+		KASSERT(is->is_simq_frozen, ("reconnect without frozen simq"));
+		ISCSI_SESSION_LOCK(is);
+		ISCSI_SESSION_DEBUG(is, "releasing");
+		xpt_release_simq(is->is_sim, 1);
+		is->is_simq_frozen = false;
+		ISCSI_SESSION_UNLOCK(is);
+
+	} else {
+		ISCSI_SESSION_LOCK(is);
+		is->is_devq = cam_simq_alloc(maxtags);
+		if (is->is_devq == NULL) {
+			ISCSI_SESSION_WARN(is, "failed to allocate simq");
+			iscsi_session_terminate(is);
+			return (ENOMEM);
+		}
+
+		is->is_sim = cam_sim_alloc(iscsi_action, iscsi_poll, "iscsi",
+		    is, is->is_id /* unit */, &is->is_lock,
+		    1, maxtags, is->is_devq);
+		if (is->is_sim == NULL) {
+			ISCSI_SESSION_UNLOCK(is);
+			ISCSI_SESSION_WARN(is, "failed to allocate SIM");
+			cam_simq_free(is->is_devq);
+			iscsi_session_terminate(is);
+			return (ENOMEM);
+		}
+
+		error = xpt_bus_register(is->is_sim, NULL, 0);
+		if (error != 0) {
+			ISCSI_SESSION_UNLOCK(is);
+			ISCSI_SESSION_WARN(is, "failed to register bus");
+			iscsi_session_terminate(is);
+			return (ENOMEM);
+		}
+
+		error = xpt_create_path(&is->is_path, /*periph*/NULL,
+		    cam_sim_path(is->is_sim), CAM_TARGET_WILDCARD,
+		    CAM_LUN_WILDCARD);
+		if (error != CAM_REQ_CMP) {
+			ISCSI_SESSION_UNLOCK(is);
+			ISCSI_SESSION_WARN(is, "failed to create path");
+			iscsi_session_terminate(is);
+			return (ENOMEM);
+		}
+		ISCSI_SESSION_UNLOCK(is);
+	}
+
+	return (0);
+}
+
+static int
+iscsi_ioctl_daemon_fail(struct iscsi_softc *sc,
+    struct iscsi_daemon_fail *fail)
+{
+	struct iscsi_session *is;
+
+	sx_slock(&sc->sc_lock);
+
+	TAILQ_FOREACH(is, &sc->sc_sessions, is_next) {
+		if (is->is_id == fail->idf_session_id)
+			break;
+	}
+	if (is == NULL) {
+		sx_sunlock(&sc->sc_lock);
+		return (ESRCH);
+	}
+	ISCSI_SESSION_LOCK(is);
+	ISCSI_SESSION_DEBUG(is, "iscsid(8) failed: %s",
+	    fail->idf_reason);
+	strlcpy(is->is_reason, fail->idf_reason, sizeof(is->is_reason));
+	//is->is_waiting_for_iscsid = false;
+	//is->is_login_phase = true;
+	//iscsi_session_reconnect(is);
+	ISCSI_SESSION_UNLOCK(is);
+	sx_sunlock(&sc->sc_lock);
+
+	return (0);
+}
+
+#ifdef ICL_KERNEL_PROXY
+static int
+iscsi_ioctl_daemon_connect(struct iscsi_softc *sc,
+    struct iscsi_daemon_connect *idc)
+{
+	struct iscsi_session *is;
+	struct sockaddr *from_sa, *to_sa;
+	int error;
+
+	sx_slock(&sc->sc_lock);
+	TAILQ_FOREACH(is, &sc->sc_sessions, is_next) {
+		if (is->is_id == idc->idc_session_id)
+			break;
+	}
+	if (is == NULL) {
+		sx_sunlock(&sc->sc_lock);
+		return (ESRCH);
+	}
+	sx_sunlock(&sc->sc_lock);
+
+	if (idc->idc_from_addrlen > 0) {
+		error = getsockaddr(&from_sa, (void *)idc->idc_from_addr, idc->idc_from_addrlen);
+		if (error != 0) {
+			ISCSI_SESSION_WARN(is,
+			    "getsockaddr failed with error %d", error);
+			return (error);
+		}
+	} else {
+		from_sa = NULL;
+	}
+	error = getsockaddr(&to_sa, (void *)idc->idc_to_addr, idc->idc_to_addrlen);
+	if (error != 0) {
+		ISCSI_SESSION_WARN(is, "getsockaddr failed with error %d",
+		    error);
+		free(from_sa, M_SONAME);
+		return (error);
+	}
+
+	ISCSI_SESSION_LOCK(is);
+	is->is_waiting_for_iscsid = false;
+	is->is_login_phase = true;
+	is->is_timeout = 0;
+	ISCSI_SESSION_UNLOCK(is);
+
+	error = icl_conn_connect(is->is_conn, idc->idc_iser, idc->idc_domain,
+	    idc->idc_socktype, idc->idc_protocol, from_sa, to_sa);
+	free(from_sa, M_SONAME);
+	free(to_sa, M_SONAME);
+
+	/*
+	 * Digests are always disabled during login phase.
+	 */
+	is->is_conn->ic_header_crc32c = false;
+	is->is_conn->ic_data_crc32c = false;
+
+	return (error);
+}
+
+static int
+iscsi_ioctl_daemon_send(struct iscsi_softc *sc,
+    struct iscsi_daemon_send *ids)
+{
+	struct iscsi_session *is;
+	struct icl_pdu *ip;
+	size_t datalen;
+	void *data;
+	int error;
+
+	sx_slock(&sc->sc_lock);
+	TAILQ_FOREACH(is, &sc->sc_sessions, is_next) {
+		if (is->is_id == ids->ids_session_id)
+			break;
+	}
+	if (is == NULL) {
+		sx_sunlock(&sc->sc_lock);
+		return (ESRCH);
+	}
+	sx_sunlock(&sc->sc_lock);
+
+	if (is->is_login_phase == false)
+		return (EBUSY);
+
+	if (is->is_terminating || is->is_reconnecting)
+		return (EIO);
+
+	datalen = ids->ids_data_segment_len;
+	if (datalen > ISCSI_MAX_DATA_SEGMENT_LENGTH)
+		return (EINVAL);
+	if (datalen > 0) {
+		data = malloc(datalen, M_ISCSI, M_WAITOK);
+		error = copyin(ids->ids_data_segment, data, datalen);
+		if (error != 0) {
+			free(data, M_ISCSI);
+			return (error);
+		}
+	}
+
+	ip = icl_pdu_new(is->is_conn, M_WAITOK);
+	memcpy(ip->ip_bhs, ids->ids_bhs, sizeof(*ip->ip_bhs));
+	if (datalen > 0) {
+		error = icl_pdu_append_data(ip, data, datalen, M_WAITOK);
+		KASSERT(error == 0, ("icl_pdu_append_data(..., M_WAITOK) failed"));
+		free(data, M_ISCSI);
+	}
+	icl_pdu_queue(ip);
+
+	return (0);
+}
+
+static int
+iscsi_ioctl_daemon_receive(struct iscsi_softc *sc,
+    struct iscsi_daemon_receive *idr)
+{
+	struct iscsi_session *is;
+	struct icl_pdu *ip;
+	void *data;
+
+	sx_slock(&sc->sc_lock);
+	TAILQ_FOREACH(is, &sc->sc_sessions, is_next) {
+		if (is->is_id == idr->idr_session_id)
+			break;
+	}
+	if (is == NULL) {
+		sx_sunlock(&sc->sc_lock);
+		return (ESRCH);
+	}
+	sx_sunlock(&sc->sc_lock);
+
+	if (is->is_login_phase == false)
+		return (EBUSY);
+
+	ISCSI_SESSION_LOCK(is);
+	while (is->is_login_pdu == NULL &&
+	    is->is_terminating == false &&
+	    is->is_reconnecting == false)
+		cv_wait(&is->is_login_cv, &is->is_lock);
+	if (is->is_terminating || is->is_reconnecting) {
+		ISCSI_SESSION_UNLOCK(is);
+		return (EIO);
+	}
+	ip = is->is_login_pdu;
+	is->is_login_pdu = NULL;
+	ISCSI_SESSION_UNLOCK(is);
+
+	if (ip->ip_data_len > idr->idr_data_segment_len) {
+		icl_pdu_free(ip);
+		return (EMSGSIZE);
+	}
+
+	copyout(ip->ip_bhs, idr->idr_bhs, sizeof(*ip->ip_bhs));
+	if (ip->ip_data_len > 0) {
+		data = malloc(ip->ip_data_len, M_ISCSI, M_WAITOK);
+		icl_pdu_get_data(ip, 0, data, ip->ip_data_len);
+		copyout(data, idr->idr_data_segment, ip->ip_data_len);
+		free(data, M_ISCSI);
+	}
+
+	icl_pdu_free(ip);
+
+	return (0);
+}
+#endif /* ICL_KERNEL_PROXY */
+
+static void
+iscsi_sanitize_session_conf(struct iscsi_session_conf *isc)
+{
+	/*
+	 * Just make sure all the fields are null-terminated.
+	 *
+	 * XXX: This is not particularly secure.  We should
+	 * 	create our own conf and then copy in relevant
+	 * 	fields.
+	 */
+	isc->isc_initiator[ISCSI_NAME_LEN - 1] = '\0';
+	isc->isc_initiator_addr[ISCSI_ADDR_LEN - 1] = '\0';
+	isc->isc_initiator_alias[ISCSI_ALIAS_LEN - 1] = '\0';
+	isc->isc_target[ISCSI_NAME_LEN - 1] = '\0';
+	isc->isc_target_addr[ISCSI_ADDR_LEN - 1] = '\0';
+	isc->isc_user[ISCSI_NAME_LEN - 1] = '\0';
+	isc->isc_secret[ISCSI_SECRET_LEN - 1] = '\0';
+	isc->isc_mutual_user[ISCSI_NAME_LEN - 1] = '\0';
+	isc->isc_mutual_secret[ISCSI_SECRET_LEN - 1] = '\0';
+}
+
+static bool
+iscsi_valid_session_conf(const struct iscsi_session_conf *isc)
+{
+
+	if (isc->isc_initiator[0] == '\0') {
+		ISCSI_DEBUG("empty isc_initiator");
+		return (false);
+	}
+
+	if (isc->isc_target_addr[0] == '\0') {
+		ISCSI_DEBUG("empty isc_target_addr");
+		return (false);
+	}
+
+	if (isc->isc_discovery != 0 && isc->isc_target[0] != 0) {
+		ISCSI_DEBUG("non-empty isc_target for discovery session");
+		return (false);
+	}
+
+	if (isc->isc_discovery == 0 && isc->isc_target[0] == 0) {
+		ISCSI_DEBUG("empty isc_target for non-discovery session");
+		return (false);
+	}
+
+	return (true);
+}
+
+static int
+iscsi_ioctl_session_add(struct iscsi_softc *sc, struct iscsi_session_add *isa)
+{
+	struct iscsi_session *is;
+	const struct iscsi_session *is2;
+	int error;
+
+	iscsi_sanitize_session_conf(&isa->isa_conf);
+	if (iscsi_valid_session_conf(&isa->isa_conf) == false)
+		return (EINVAL);
+
+	is = malloc(sizeof(*is), M_ISCSI, M_ZERO | M_WAITOK);
+	memcpy(&is->is_conf, &isa->isa_conf, sizeof(is->is_conf));
+
+	sx_xlock(&sc->sc_lock);
+
+	/*
+	 * Prevent duplicates.
+	 */
+	TAILQ_FOREACH(is2, &sc->sc_sessions, is_next) {
+		if (!!is->is_conf.isc_discovery !=
+		    !!is2->is_conf.isc_discovery)
+			continue;
+
+		if (strcmp(is->is_conf.isc_target_addr,
+		    is2->is_conf.isc_target_addr) != 0)
+			continue;
+
+		if (is->is_conf.isc_discovery == 0 &&
+		    strcmp(is->is_conf.isc_target,
+		    is2->is_conf.isc_target) != 0)
+			continue;
+
+		sx_xunlock(&sc->sc_lock);
+		free(is, M_ISCSI);
+		return (EBUSY);
+	}
+
+	is->is_conn = icl_conn_new("iscsi", &is->is_lock);
+	is->is_conn->ic_receive = iscsi_receive_callback;
+	is->is_conn->ic_error = iscsi_error_callback;
+	is->is_conn->ic_prv0 = is;
+	TAILQ_INIT(&is->is_outstanding);
+	STAILQ_INIT(&is->is_postponed);
+	mtx_init(&is->is_lock, "iscsi_lock", NULL, MTX_DEF);
+	cv_init(&is->is_maintenance_cv, "iscsi_mt");
+#ifdef ICL_KERNEL_PROXY
+	cv_init(&is->is_login_cv, "iscsi_login");
+#endif
+
+	is->is_softc = sc;
+	sc->sc_last_session_id++;
+	is->is_id = sc->sc_last_session_id;
+	is->is_isid[0] = 0x80; /* RFC 3720, 10.12.5: 10b, "Random" ISID. */
+	arc4rand(&is->is_isid[1], 5, 0);
+	is->is_tsih = 0;
+	callout_init(&is->is_callout, 1);
+
+	error = kthread_add(iscsi_maintenance_thread, is, NULL, NULL, 0, 0, "iscsimt");
+	if (error != 0) {
+		ISCSI_SESSION_WARN(is, "kthread_add(9) failed with error %d", error);
+		sx_xunlock(&sc->sc_lock);
+		return (error);
+	}
+
+	callout_reset(&is->is_callout, 1 * hz, iscsi_callout, is);
+	TAILQ_INSERT_TAIL(&sc->sc_sessions, is, is_next);
+
+	/*
+	 * Trigger immediate reconnection.
+	 */
+	ISCSI_SESSION_LOCK(is);
+	is->is_waiting_for_iscsid = true;
+	strlcpy(is->is_reason, "Waiting for iscsid(8)", sizeof(is->is_reason));
+	ISCSI_SESSION_UNLOCK(is);
+	cv_signal(&sc->sc_cv);
+
+	sx_xunlock(&sc->sc_lock);
+
+	return (0);
+}
+
+static bool
+iscsi_session_conf_matches(unsigned int id1, const struct iscsi_session_conf *c1,
+    unsigned int id2, const struct iscsi_session_conf *c2)
+{
+
+	if (id2 != 0 && id2 != id1)
+		return (false);
+	if (c2->isc_target[0] != '\0' &&
+	    strcmp(c1->isc_target, c2->isc_target) != 0)
+		return (false);
+	if (c2->isc_target_addr[0] != '\0' &&
+	    strcmp(c1->isc_target_addr, c2->isc_target_addr) != 0)
+		return (false);
+	return (true);
+}
+
+static int
+iscsi_ioctl_session_remove(struct iscsi_softc *sc,
+    struct iscsi_session_remove *isr)
+{
+	struct iscsi_session *is, *tmp;
+	bool found = false;
+
+	iscsi_sanitize_session_conf(&isr->isr_conf);
+
+	sx_xlock(&sc->sc_lock);
+	TAILQ_FOREACH_SAFE(is, &sc->sc_sessions, is_next, tmp) {
+		ISCSI_SESSION_LOCK(is);
+		if (iscsi_session_conf_matches(is->is_id, &is->is_conf,
+		    isr->isr_session_id, &isr->isr_conf)) {
+			found = true;
+			iscsi_session_logout(is);
+			iscsi_session_terminate(is);
+		}
+		ISCSI_SESSION_UNLOCK(is);
+	}
+	sx_xunlock(&sc->sc_lock);
+
+	if (!found)
+		return (ESRCH);
+
+	return (0);
+}
+
+static int
+iscsi_ioctl_session_list(struct iscsi_softc *sc, struct iscsi_session_list *isl)
+{
+	int error;
+	unsigned int i = 0;
+	struct iscsi_session *is;
+	struct iscsi_session_state iss;
+
+	sx_slock(&sc->sc_lock);
+	TAILQ_FOREACH(is, &sc->sc_sessions, is_next) {
+		if (i >= isl->isl_nentries) {
+			sx_sunlock(&sc->sc_lock);
+			return (EMSGSIZE);
+		}
+		memset(&iss, 0, sizeof(iss));
+		memcpy(&iss.iss_conf, &is->is_conf, sizeof(iss.iss_conf));
+		iss.iss_id = is->is_id;
+		strlcpy(iss.iss_target_alias, is->is_target_alias, sizeof(iss.iss_target_alias));
+		strlcpy(iss.iss_reason, is->is_reason, sizeof(iss.iss_reason));
+
+		if (is->is_conn->ic_header_crc32c)
+			iss.iss_header_digest = ISCSI_DIGEST_CRC32C;
+		else
+			iss.iss_header_digest = ISCSI_DIGEST_NONE;
+
+		if (is->is_conn->ic_data_crc32c)
+			iss.iss_data_digest = ISCSI_DIGEST_CRC32C;
+		else
+			iss.iss_data_digest = ISCSI_DIGEST_NONE;
+
+		iss.iss_max_data_segment_length = is->is_max_data_segment_length;
+		iss.iss_immediate_data = is->is_immediate_data;
+		iss.iss_connected = is->is_connected;
+	
+		error = copyout(&iss, isl->isl_pstates + i, sizeof(iss));
+		if (error != 0) {
+			sx_sunlock(&sc->sc_lock);
+			return (error);
+		}
+		i++;
+	}
+	sx_sunlock(&sc->sc_lock);
+
+	isl->isl_nentries = i;
+
+	return (0);
+}
+
+static int
+iscsi_ioctl_session_modify(struct iscsi_softc *sc,
+    struct iscsi_session_modify *ism)
+{
+	struct iscsi_session *is;
+
+	iscsi_sanitize_session_conf(&ism->ism_conf);
+	if (iscsi_valid_session_conf(&ism->ism_conf) == false)
+		return (EINVAL);
+
+	sx_xlock(&sc->sc_lock);
+	TAILQ_FOREACH(is, &sc->sc_sessions, is_next) {
+		ISCSI_SESSION_LOCK(is);
+		if (is->is_id == ism->ism_session_id)
+			break;
+		ISCSI_SESSION_UNLOCK(is);
+	}
+	if (is == NULL) {
+		sx_xunlock(&sc->sc_lock);
+		return (ESRCH);
+	}
+	sx_xunlock(&sc->sc_lock);
+
+	memcpy(&is->is_conf, &ism->ism_conf, sizeof(is->is_conf));
+	ISCSI_SESSION_UNLOCK(is);
+
+	iscsi_session_reconnect(is);
+
+	return (0);
+}
+
+static int
+iscsi_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int mode,
+    struct thread *td)
+{
+	struct iscsi_softc *sc;
+
+	sc = dev->si_drv1;
+
+	switch (cmd) {
+	case ISCSIDWAIT:
+		return (iscsi_ioctl_daemon_wait(sc,
+		    (struct iscsi_daemon_request *)arg));
+	case ISCSIDHANDOFF:
+		return (iscsi_ioctl_daemon_handoff(sc,
+		    (struct iscsi_daemon_handoff *)arg));
+	case ISCSIDFAIL:
+		return (iscsi_ioctl_daemon_fail(sc,
+		    (struct iscsi_daemon_fail *)arg));
+#ifdef ICL_KERNEL_PROXY
+	case ISCSIDCONNECT:
+		return (iscsi_ioctl_daemon_connect(sc,
+		    (struct iscsi_daemon_connect *)arg));
+	case ISCSIDSEND:
+		return (iscsi_ioctl_daemon_send(sc,
+		    (struct iscsi_daemon_send *)arg));
+	case ISCSIDRECEIVE:
+		return (iscsi_ioctl_daemon_receive(sc,
+		    (struct iscsi_daemon_receive *)arg));
+#endif /* ICL_KERNEL_PROXY */
+	case ISCSISADD:
+		return (iscsi_ioctl_session_add(sc,
+		    (struct iscsi_session_add *)arg));
+	case ISCSISREMOVE:
+		return (iscsi_ioctl_session_remove(sc,
+		    (struct iscsi_session_remove *)arg));
+	case ISCSISLIST:
+		return (iscsi_ioctl_session_list(sc,
+		    (struct iscsi_session_list *)arg));
+	case ISCSISMODIFY:
+		return (iscsi_ioctl_session_modify(sc,
+		    (struct iscsi_session_modify *)arg));
+	default:
+		return (EINVAL);
+	}
+}
+
+static uint64_t
+iscsi_encode_lun(uint32_t lun)
+{
+	uint8_t encoded[8];
+	uint64_t result;
+
+	memset(encoded, 0, sizeof(encoded));
+
+	if (lun < 256) {
+		/*
+		 * Peripheral device addressing.
+		 */
+		encoded[1] = lun;
+	} else if (lun < 16384) {
+		/*
+		 * Flat space addressing.
+		 */
+		encoded[0] = 0x40;
+		encoded[0] |= (lun >> 8) & 0x3f;
+		encoded[1] = lun & 0xff;
+	} else {
+		/*
+		 * Extended flat space addressing.
+		 */
+		encoded[0] = 0xd2;
+		encoded[1] = lun >> 16;
+		encoded[2] = lun >> 8;
+		encoded[3] = lun;
+	}
+
+	memcpy(&result, encoded, sizeof(result));
+	return (result);
+}
+
+static struct iscsi_outstanding *
+iscsi_outstanding_find(struct iscsi_session *is, uint32_t initiator_task_tag)
+{
+	struct iscsi_outstanding *io;
+
+	ISCSI_SESSION_LOCK_ASSERT(is);
+
+	TAILQ_FOREACH(io, &is->is_outstanding, io_next) {
+		if (io->io_initiator_task_tag == initiator_task_tag)
+			return (io);
+	}
+	return (NULL);
+}
+
+static struct iscsi_outstanding *
+iscsi_outstanding_find_ccb(struct iscsi_session *is, union ccb *ccb)
+{
+	struct iscsi_outstanding *io;
+
+	ISCSI_SESSION_LOCK_ASSERT(is);
+
+	TAILQ_FOREACH(io, &is->is_outstanding, io_next) {
+		if (io->io_ccb == ccb)
+			return (io);
+	}
+	return (NULL);
+}
+
+static struct iscsi_outstanding *
+iscsi_outstanding_add(struct iscsi_session *is,
+    uint32_t initiator_task_tag, union ccb *ccb)
+{
+	struct iscsi_outstanding *io;
+
+	ISCSI_SESSION_LOCK_ASSERT(is);
+
+	KASSERT(iscsi_outstanding_find(is, initiator_task_tag) == NULL,
+	    ("initiator_task_tag 0x%x already added", initiator_task_tag));
+
+	io = uma_zalloc(iscsi_outstanding_zone, M_NOWAIT | M_ZERO);
+	if (io == NULL) {
+		ISCSI_SESSION_WARN(is, "failed to allocate %zd bytes", sizeof(*io));
+		return (NULL);
+	}
+	io->io_initiator_task_tag = initiator_task_tag;
+	io->io_ccb = ccb;
+	TAILQ_INSERT_TAIL(&is->is_outstanding, io, io_next);
+	return (io);
+}
+
+static void
+iscsi_outstanding_remove(struct iscsi_session *is, struct iscsi_outstanding *io)
+{
+
+	ISCSI_SESSION_LOCK_ASSERT(is);
+
+	TAILQ_REMOVE(&is->is_outstanding, io, io_next);
+	uma_zfree(iscsi_outstanding_zone, io);
+}
+
+static void
+iscsi_action_abort(struct iscsi_session *is, union ccb *ccb)
+{
+	struct icl_pdu *request;
+	struct iscsi_bhs_task_management_request *bhstmr;
+	struct ccb_abort *cab = &ccb->cab;
+	struct iscsi_outstanding *io, *aio;
+
+	ISCSI_SESSION_LOCK_ASSERT(is);
+
+#if 0
+	KASSERT(is->is_login_phase == false, ("%s called during Login Phase", __func__));
+#else
+	if (is->is_login_phase) {
+		ccb->ccb_h.status = CAM_REQ_ABORTED;
+		xpt_done(ccb);
+		return;
+	}
+#endif
+
+	aio = iscsi_outstanding_find_ccb(is, cab->abort_ccb);
+	if (aio == NULL) {
+		ccb->ccb_h.status = CAM_REQ_CMP;
+		xpt_done(ccb);
+		return;
+	}
+
+	request = icl_pdu_new(is->is_conn, M_NOWAIT);
+	if (request == NULL) {
+		ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
+		xpt_done(ccb);
+		return;
+	}
+
+	bhstmr = (struct iscsi_bhs_task_management_request *)request->ip_bhs;
+	bhstmr->bhstmr_opcode = ISCSI_BHS_OPCODE_TASK_REQUEST;
+	bhstmr->bhstmr_function = 0x80 | BHSTMR_FUNCTION_ABORT_TASK;
+
+	bhstmr->bhstmr_lun = iscsi_encode_lun(ccb->ccb_h.target_lun);
+	bhstmr->bhstmr_initiator_task_tag = is->is_initiator_task_tag;
+	is->is_initiator_task_tag++;
+	bhstmr->bhstmr_referenced_task_tag = aio->io_initiator_task_tag;
+
+	io = iscsi_outstanding_add(is, bhstmr->bhstmr_initiator_task_tag, NULL);
+	if (io == NULL) {
+		icl_pdu_free(request);
+		ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
+		xpt_done(ccb);
+		return;
+	}
+	io->io_datasn = aio->io_initiator_task_tag;
+	iscsi_pdu_queue_locked(request);
+}
+
+static void
+iscsi_action_scsiio(struct iscsi_session *is, union ccb *ccb)
+{
+	struct icl_pdu *request;
+	struct iscsi_bhs_scsi_command *bhssc;
+	struct ccb_scsiio *csio;
+	struct iscsi_outstanding *io;
+	size_t len;
+	int error;
+
+	ISCSI_SESSION_LOCK_ASSERT(is);
+
+#if 0
+	KASSERT(is->is_login_phase == false, ("%s called during Login Phase", __func__));
+#else
+	if (is->is_login_phase) {
+		ISCSI_SESSION_DEBUG(is, "called during login phase");
+		if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
+			xpt_freeze_devq(ccb->ccb_h.path, 1);
+			ISCSI_SESSION_DEBUG(is, "freezing devq");
+		}
+		ccb->ccb_h.status = CAM_REQ_ABORTED | CAM_DEV_QFRZN;
+		xpt_done(ccb);
+		return;
+	}
+#endif
+
+	request = icl_pdu_new(is->is_conn, M_NOWAIT);
+	if (request == NULL) {
+		if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
+			xpt_freeze_devq(ccb->ccb_h.path, 1);
+			ISCSI_SESSION_DEBUG(is, "freezing devq");
+		}
+		ccb->ccb_h.status = CAM_RESRC_UNAVAIL | CAM_DEV_QFRZN;
+		xpt_done(ccb);
+		return;
+	}
+
+	csio = &ccb->csio;
+	bhssc = (struct iscsi_bhs_scsi_command *)request->ip_bhs;
+	bhssc->bhssc_opcode = ISCSI_BHS_OPCODE_SCSI_COMMAND;
+	bhssc->bhssc_flags |= BHSSC_FLAGS_F;
+	switch (csio->ccb_h.flags & CAM_DIR_MASK) {
+	case CAM_DIR_IN:
+		bhssc->bhssc_flags |= BHSSC_FLAGS_R;
+		break;
+	case CAM_DIR_OUT:
+		bhssc->bhssc_flags |= BHSSC_FLAGS_W;
+		break;
+	}
+
+	if ((ccb->ccb_h.flags & CAM_TAG_ACTION_VALID) != 0) {
+		switch (csio->tag_action) {
+		case MSG_HEAD_OF_Q_TAG:
+			bhssc->bhssc_flags |= BHSSC_FLAGS_ATTR_HOQ;
+			break;
+		case MSG_ORDERED_Q_TAG:
+			bhssc->bhssc_flags |= BHSSC_FLAGS_ATTR_ORDERED;
+			break;
+		case MSG_ACA_TASK:
+			bhssc->bhssc_flags |= BHSSC_FLAGS_ATTR_ACA;
+			break;
+		case MSG_SIMPLE_Q_TAG:
+		default:
+			bhssc->bhssc_flags |= BHSSC_FLAGS_ATTR_SIMPLE;
+			break;
+		}
+	} else
+		bhssc->bhssc_flags |= BHSSC_FLAGS_ATTR_UNTAGGED;
+
+	bhssc->bhssc_lun = iscsi_encode_lun(csio->ccb_h.target_lun);
+	bhssc->bhssc_initiator_task_tag = is->is_initiator_task_tag;
+	is->is_initiator_task_tag++;
+	bhssc->bhssc_expected_data_transfer_length = htonl(csio->dxfer_len);
+	KASSERT(csio->cdb_len <= sizeof(bhssc->bhssc_cdb),
+	    ("unsupported CDB size %zd", (size_t)csio->cdb_len));
+
+	if (csio->ccb_h.flags & CAM_CDB_POINTER)
+		memcpy(&bhssc->bhssc_cdb, csio->cdb_io.cdb_ptr, csio->cdb_len);
+	else
+		memcpy(&bhssc->bhssc_cdb, csio->cdb_io.cdb_bytes, csio->cdb_len);
+
+	io = iscsi_outstanding_add(is, bhssc->bhssc_initiator_task_tag, ccb);
+	if (io == NULL) {
+		icl_pdu_free(request);
+		if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
+			xpt_freeze_devq(ccb->ccb_h.path, 1);
+			ISCSI_SESSION_DEBUG(is, "freezing devq");
+		}
+		ccb->ccb_h.status = CAM_RESRC_UNAVAIL | CAM_DEV_QFRZN;
+		xpt_done(ccb);
+		return;
+	}
+
+	if (is->is_immediate_data &&
+	    (csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) {
+		len = csio->dxfer_len;
+		//ISCSI_SESSION_DEBUG(is, "adding %zd of immediate data", len);
+		if (len > is->is_first_burst_length) {
+			ISCSI_SESSION_DEBUG(is, "len %zd -> %zd", len, is->is_first_burst_length);
+			len = is->is_first_burst_length;
+		}
+		if (len > is->is_max_data_segment_length) {
+			ISCSI_SESSION_DEBUG(is, "len %zd -> %zd", len, is->is_max_data_segment_length);
+			len = is->is_max_data_segment_length;
+		}
+
+		error = icl_pdu_append_data(request, csio->data_ptr, len, M_NOWAIT);
+		if (error != 0) {
+			icl_pdu_free(request);
+			if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
+				xpt_freeze_devq(ccb->ccb_h.path, 1);
+				ISCSI_SESSION_DEBUG(is, "freezing devq");
+			}
+			ccb->ccb_h.status = CAM_RESRC_UNAVAIL | CAM_DEV_QFRZN;
+			xpt_done(ccb);
+			return;
+		}
+	}
+	iscsi_pdu_queue_locked(request);
+}
+
+static void
+iscsi_action(struct cam_sim *sim, union ccb *ccb)
+{
+	struct iscsi_session *is;
+
+	is = cam_sim_softc(sim);
+
+	ISCSI_SESSION_LOCK_ASSERT(is);
+
+	if (is->is_terminating ||
+	    (is->is_connected == false && fail_on_disconnection)) {
+		ccb->ccb_h.status = CAM_DEV_NOT_THERE;
+		xpt_done(ccb);
+		return;
+	}
+
+	switch (ccb->ccb_h.func_code) {
+	case XPT_PATH_INQ:
+	{
+		struct ccb_pathinq *cpi = &ccb->cpi;
+
+		cpi->version_num = 1;
+		cpi->hba_inquiry = PI_TAG_ABLE;
+		cpi->target_sprt = 0;
+		//cpi->hba_misc = PIM_NOBUSRESET;
+		cpi->hba_misc = 0;
+		cpi->hba_eng_cnt = 0;
+		cpi->max_target = 0;
+		cpi->max_lun = 255;
+		//cpi->initiator_id = 0; /* XXX */
+		cpi->initiator_id = 64; /* XXX */
+		strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
+		strlcpy(cpi->hba_vid, "iSCSI", HBA_IDLEN);
+		strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
+		cpi->unit_number = cam_sim_unit(sim);
+		cpi->bus_id = cam_sim_bus(sim);
+		cpi->base_transfer_speed = 150000; /* XXX */
+		cpi->transport = XPORT_ISCSI;
+		cpi->transport_version = 0;
+		cpi->protocol = PROTO_SCSI;
+		cpi->protocol_version = SCSI_REV_SPC3;
+		cpi->maxio = MAXPHYS;
+		cpi->ccb_h.status = CAM_REQ_CMP;
+		break;
+	}
+	case XPT_GET_TRAN_SETTINGS:
+	{
+		struct ccb_trans_settings	*cts;
+		struct ccb_trans_settings_scsi	*scsi;
+
+		cts = &ccb->cts;
+		scsi = &cts->proto_specific.scsi;
+
+		cts->protocol = PROTO_SCSI;
+		cts->protocol_version = SCSI_REV_SPC3;
+		cts->transport = XPORT_ISCSI;
+		cts->transport_version = 0;
+		scsi->valid = CTS_SCSI_VALID_TQ;
+		scsi->flags = CTS_SCSI_FLAGS_TAG_ENB;
+		cts->ccb_h.status = CAM_REQ_CMP;
+		break;
+	}
+	case XPT_CALC_GEOMETRY:
+		cam_calc_geometry(&ccb->ccg, /*extended*/1);
+		ccb->ccb_h.status = CAM_REQ_CMP;
+		break;
+#if 0
+	/*
+	 * XXX: What's the point?
+	 */
+	case XPT_RESET_BUS:
+	case XPT_TERM_IO:
+		ISCSI_SESSION_DEBUG(is, "faking success for reset, abort, or term_io");
+		ccb->ccb_h.status = CAM_REQ_CMP;
+		break;
+#endif
+	case XPT_ABORT:
+		iscsi_action_abort(is, ccb);
+		return;
+	case XPT_SCSI_IO:
+		iscsi_action_scsiio(is, ccb);
+		return;
+	default:
+#if 0
+		ISCSI_SESSION_DEBUG(is, "got unsupported code 0x%x", ccb->ccb_h.func_code);
+#endif
+		ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
+		break;
+	}
+	xpt_done(ccb);
+}
+
+static void
+iscsi_poll(struct cam_sim *sim)
+{
+
+	KASSERT(0, ("%s: you're not supposed to be here", __func__));
+}
+
+static void
+iscsi_terminate_sessions(struct iscsi_softc *sc)
+{
+	struct iscsi_session *is;
+
+	sx_slock(&sc->sc_lock);
+	TAILQ_FOREACH(is, &sc->sc_sessions, is_next)
+		iscsi_session_terminate(is);
+	while(!TAILQ_EMPTY(&sc->sc_sessions)) {
+		ISCSI_DEBUG("waiting for sessions to terminate");
+		cv_wait(&sc->sc_cv, &sc->sc_lock);
+	}
+	ISCSI_DEBUG("all sessions terminated");
+	sx_sunlock(&sc->sc_lock);
+}
+
+static void
+iscsi_shutdown_pre(struct iscsi_softc *sc)
+{
+	struct iscsi_session *is;
+
+	if (!fail_on_shutdown)
+		return;
+
+	/*
+	 * If we have any sessions waiting for reconnection, request
+	 * maintenance thread to fail them immediately instead of waiting
+	 * for reconnect timeout.
+	 *
+	 * This prevents LUNs with mounted filesystems that are supported
+	 * by disconnected iSCSI sessions from hanging, however it will
+	 * fail all queued BIOs.
+	 */
+	ISCSI_DEBUG("forcing failing all disconnected sessions due to shutdown");
+
+	fail_on_disconnection = 1;
+
+	sx_slock(&sc->sc_lock);
+	TAILQ_FOREACH(is, &sc->sc_sessions, is_next) {
+		ISCSI_SESSION_LOCK(is);
+		if (!is->is_connected) {
+			ISCSI_SESSION_DEBUG(is, "force failing disconnected session early");
+			iscsi_session_reconnect(is);
+		}
+		ISCSI_SESSION_UNLOCK(is);
+	}
+	sx_sunlock(&sc->sc_lock);
+}
+
+static void
+iscsi_shutdown_post(struct iscsi_softc *sc)
+{
+
+	if (panicstr == NULL) {
+		ISCSI_DEBUG("removing all sessions due to shutdown");
+		iscsi_terminate_sessions(sc);
+	}
+}
+
+static int
+iscsi_load(void)
+{
+	int error;
+
+	sc = malloc(sizeof(*sc), M_ISCSI, M_ZERO | M_WAITOK);
+	sx_init(&sc->sc_lock, "iscsi");
+	TAILQ_INIT(&sc->sc_sessions);
+	cv_init(&sc->sc_cv, "iscsi_cv");
+
+	iscsi_outstanding_zone = uma_zcreate("iscsi_outstanding",
+	    sizeof(struct iscsi_outstanding), NULL, NULL, NULL, NULL,
+	    UMA_ALIGN_PTR, 0);
+
+	error = make_dev_p(MAKEDEV_CHECKNAME, &sc->sc_cdev, &iscsi_cdevsw,
+	    NULL, UID_ROOT, GID_WHEEL, 0600, "iscsi");
+	if (error != 0) {
+		ISCSI_WARN("failed to create device node, error %d", error);
+		return (error);
+	}
+	sc->sc_cdev->si_drv1 = sc;
+
+	sc->sc_shutdown_pre_eh = EVENTHANDLER_REGISTER(shutdown_pre_sync,
+	    iscsi_shutdown_pre, sc, SHUTDOWN_PRI_FIRST);
+	/*
+	 * shutdown_post_sync needs to run after filesystem shutdown and before
+	 * CAM shutdown - otherwise when rebooting with an iSCSI session that is
+	 * disconnected but has outstanding requests, dashutdown() will hang on
+	 * cam_periph_runccb().
+	 */
+	sc->sc_shutdown_post_eh = EVENTHANDLER_REGISTER(shutdown_post_sync,
+	    iscsi_shutdown_post, sc, SHUTDOWN_PRI_DEFAULT - 1);
+
+	return (0);
+}
+
+static int
+iscsi_unload(void)
+{
+
+	if (sc->sc_cdev != NULL) {
+		ISCSI_DEBUG("removing device node");
+		destroy_dev(sc->sc_cdev);
+		ISCSI_DEBUG("device node removed");
+	}
+
+	if (sc->sc_shutdown_pre_eh != NULL)
+		EVENTHANDLER_DEREGISTER(shutdown_pre_sync, sc->sc_shutdown_pre_eh);
+	if (sc->sc_shutdown_post_eh != NULL)
+		EVENTHANDLER_DEREGISTER(shutdown_post_sync, sc->sc_shutdown_post_eh);
+
+	iscsi_terminate_sessions(sc);
+
+	uma_zdestroy(iscsi_outstanding_zone);
+	sx_destroy(&sc->sc_lock);
+	cv_destroy(&sc->sc_cv);
+	free(sc, M_ISCSI);
+	return (0);
+}
+
+static int
+iscsi_quiesce(void)
+{
+	sx_slock(&sc->sc_lock);
+	if (!TAILQ_EMPTY(&sc->sc_sessions)) {
+		sx_sunlock(&sc->sc_lock);
+		return (EBUSY);
+	}
+	sx_sunlock(&sc->sc_lock);
+	return (0);
+}
+
+static int
+iscsi_modevent(module_t mod, int what, void *arg)
+{
+	int error;
+
+	switch (what) {
+	case MOD_LOAD:
+		error = iscsi_load();
+		break;
+	case MOD_UNLOAD:
+		error = iscsi_unload();
+		break;
+	case MOD_QUIESCE:
+		error = iscsi_quiesce();
+		break;
+	default:
+		error = EINVAL;
+		break;
+	}
+	return (error);
+}
+
+moduledata_t iscsi_data = {
+	"iscsi",
+	iscsi_modevent,
+	0
+};
+
+DECLARE_MODULE(iscsi, iscsi_data, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
+MODULE_DEPEND(iscsi, cam, 1, 1, 1);
+MODULE_DEPEND(iscsi, icl, 1, 1, 1);


Property changes on: trunk/sys/dev/iscsi/iscsi.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sys/dev/iscsi/iscsi.h
===================================================================
--- trunk/sys/dev/iscsi/iscsi.h	                        (rev 0)
+++ trunk/sys/dev/iscsi/iscsi.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -0,0 +1,138 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2012 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Edward Tomasz Napierala under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/sys/dev/iscsi/iscsi.h 311401 2017-01-05 11:17:09Z mav $
+ */
+
+#ifndef ISCSI_H
+#define	ISCSI_H
+
+struct iscsi_softc;
+struct icl_conn;
+
+#define	ISCSI_NAME_LEN		224	/* 223 bytes, by RFC 3720, + '\0' */
+#define	ISCSI_ADDR_LEN		47	/* INET6_ADDRSTRLEN + '\0' */
+#define	ISCSI_SECRET_LEN	17	/* 16 + '\0' */
+
+struct iscsi_outstanding {
+	TAILQ_ENTRY(iscsi_outstanding)	io_next;
+	union ccb			*io_ccb;
+	size_t				io_received;
+	uint32_t			io_initiator_task_tag;
+	uint32_t			io_datasn;
+};
+
+struct iscsi_session {
+	TAILQ_ENTRY(iscsi_session)	is_next;
+
+	struct icl_conn			*is_conn;
+	struct mtx			is_lock;
+
+	uint32_t			is_statsn;
+	uint32_t			is_cmdsn;
+	uint32_t			is_expcmdsn;
+	uint32_t			is_maxcmdsn;
+	uint32_t			is_initiator_task_tag;
+	int				is_header_digest;
+	int				is_data_digest;
+	int				is_initial_r2t;
+	size_t				is_max_burst_length;
+	size_t				is_first_burst_length;
+	uint8_t				is_isid[6];
+	uint16_t			is_tsih;
+	bool				is_immediate_data;
+	size_t				is_max_data_segment_length;
+	char				is_target_alias[ISCSI_ALIAS_LEN];
+
+	TAILQ_HEAD(, iscsi_outstanding)	is_outstanding;
+	STAILQ_HEAD(, icl_pdu)		is_postponed;
+
+	struct callout			is_callout;
+	unsigned int			is_timeout;
+
+	/*
+	 * XXX: This could be rewritten using a single variable,
+	 * 	but somehow it results in uglier code. 
+	 */
+	/*
+	 * We're waiting for iscsid(8); after iscsid_timeout
+	 * expires, kernel will wake up an iscsid(8) to handle
+	 * the session.
+	 */
+	bool				is_waiting_for_iscsid;
+
+	/*
+	 * Some iscsid(8) instance is handling the session;
+	 * after login_timeout expires, kernel will wake up
+	 * another iscsid(8) to handle the session.
+	 */
+	bool				is_login_phase;
+
+	/*
+	 * We're in the process of removing the iSCSI session.
+	 */
+	bool				is_terminating;
+
+	/*
+	 * We're waiting for the maintenance thread to do some
+	 * reconnection tasks.
+	 */
+	bool				is_reconnecting;
+
+	bool				is_connected;
+
+	struct cam_devq			*is_devq;
+	struct cam_sim			*is_sim;
+	struct cam_path			*is_path;
+	struct cv			is_maintenance_cv;
+	struct iscsi_softc		*is_softc;
+	unsigned int			is_id;
+	struct iscsi_session_conf	is_conf;
+	bool				is_simq_frozen;
+
+	char				is_reason[ISCSI_REASON_LEN];
+
+#ifdef ICL_KERNEL_PROXY
+	struct cv			is_login_cv;
+	struct icl_pdu			*is_login_pdu;
+#endif
+};
+
+struct iscsi_softc {
+	device_t			sc_dev;
+	struct sx			sc_lock;
+	struct cdev			*sc_cdev;
+	TAILQ_HEAD(, iscsi_session)	sc_sessions;
+	struct cv			sc_cv;
+	unsigned int			sc_last_session_id;
+	eventhandler_tag		sc_shutdown_pre_eh;
+	eventhandler_tag		sc_shutdown_post_eh;
+};
+
+#endif /* !ISCSI_H */


Property changes on: trunk/sys/dev/iscsi/iscsi.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sys/dev/iscsi/iscsi_ioctl.h
===================================================================
--- trunk/sys/dev/iscsi/iscsi_ioctl.h	                        (rev 0)
+++ trunk/sys/dev/iscsi/iscsi_ioctl.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -0,0 +1,217 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2012 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Edward Tomasz Napierala under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/sys/dev/iscsi/iscsi_ioctl.h 269065 2014-07-24 15:31:45Z mav $
+ */
+
+#ifndef ISCSI_IOCTL_H
+#define	ISCSI_IOCTL_H
+
+#ifdef ICL_KERNEL_PROXY
+#include <sys/socket.h>
+#endif
+
+#define	ISCSI_PATH		"/dev/iscsi"
+#define	ISCSI_MAX_DATA_SEGMENT_LENGTH	(128 * 1024)
+
+#define	ISCSI_NAME_LEN		224	/* 223 bytes, by RFC 3720, + '\0' */
+#define	ISCSI_ADDR_LEN		47	/* INET6_ADDRSTRLEN + '\0' */
+#define	ISCSI_ALIAS_LEN		256	/* XXX: Where did it come from? */
+#define	ISCSI_SECRET_LEN	17	/* 16 + '\0' */
+#define	ISCSI_REASON_LEN	64
+
+#define	ISCSI_DIGEST_NONE	0
+#define	ISCSI_DIGEST_CRC32C	1
+
+/*
+ * Session configuration, set when adding the session.
+ */
+struct iscsi_session_conf {
+	char 		isc_initiator[ISCSI_NAME_LEN];
+	char		isc_initiator_addr[ISCSI_ADDR_LEN];
+	char		isc_initiator_alias[ISCSI_ALIAS_LEN];
+	char 		isc_target[ISCSI_NAME_LEN];
+	char		isc_target_addr[ISCSI_ADDR_LEN];
+	char		isc_user[ISCSI_NAME_LEN];
+	char		isc_secret[ISCSI_SECRET_LEN];
+	char		isc_mutual_user[ISCSI_NAME_LEN];
+	char		isc_mutual_secret[ISCSI_SECRET_LEN];
+	int		isc_discovery;
+	int		isc_header_digest;
+	int		isc_data_digest;
+	int		isc_iser;
+	int		isc_spare[4];
+};
+
+/*
+ * Session state, negotiated by iscsid(8) and queried by iscsictl(8).
+ */
+struct iscsi_session_state {
+	struct iscsi_session_conf	iss_conf;
+	unsigned int	iss_id;
+	char		iss_target_alias[ISCSI_ALIAS_LEN];
+	int		iss_header_digest;
+	int		iss_data_digest;
+	int		iss_max_data_segment_length;
+	int		iss_immediate_data;
+	int		iss_connected;
+	char		iss_reason[ISCSI_REASON_LEN];
+	int		iss_spare[4];
+};
+
+/*
+ * For use with iscsid(8).
+ */
+
+struct iscsi_daemon_request {
+	unsigned int			idr_session_id;
+	struct iscsi_session_conf	idr_conf;
+	uint8_t				idr_isid[6];
+	uint16_t			idr_tsih;
+	uint16_t			idr_spare_cid;
+	int				idr_spare[4];
+};
+
+struct iscsi_daemon_handoff {
+	unsigned int			idh_session_id;
+	int				idh_socket;
+	char				idh_target_alias[ISCSI_ALIAS_LEN];
+	uint8_t				idh_spare_isid[6];
+	uint16_t			idh_tsih;
+	uint16_t			idh_spare_cid;
+	uint32_t			idh_statsn;
+	int				idh_header_digest;
+	int				idh_data_digest;
+	int				idh_initial_r2t;
+	int				idh_immediate_data;
+	size_t				idh_max_data_segment_length;
+	size_t				idh_max_burst_length;
+	size_t				idh_first_burst_length;
+	int				idh_spare[4];
+};
+
+struct iscsi_daemon_fail {
+	unsigned int			idf_session_id;
+	char				idf_reason[ISCSI_REASON_LEN];
+	int				idf_spare[4];
+};
+
+#define	ISCSIDWAIT	_IOR('I', 0x01, struct iscsi_daemon_request)
+#define	ISCSIDHANDOFF	_IOW('I', 0x02, struct iscsi_daemon_handoff)
+#define	ISCSIDFAIL	_IOW('I', 0x03, struct iscsi_daemon_fail)
+
+#ifdef ICL_KERNEL_PROXY
+
+/*
+ * When ICL_KERNEL_PROXY is not defined, the iscsid(8) is responsible
+ * for creating the socket, connecting, and performing Login Phase using
+ * the socket in the usual userspace way, and then passing the socket
+ * file descriptor to the kernel part using ISCSIDHANDOFF.
+ *
+ * When ICL_KERNEL_PROXY is defined, the iscsid(8) creates the session
+ * using ISCSICONNECT, performs Login Phase using ISCSISEND/ISCSIRECEIVE
+ * instead of read(2)/write(2), and then calls ISCSIDHANDOFF with
+ * idh_socket set to 0.
+ *
+ * The purpose of ICL_KERNEL_PROXY is to workaround the fact that,
+ * at this time, it's not possible to do iWARP (RDMA) in userspace.
+ */
+
+struct iscsi_daemon_connect {
+	int				idc_session_id;
+	int				idc_iser;
+	int				idc_domain;
+	int				idc_socktype;
+	int				idc_protocol;
+	struct sockaddr			*idc_from_addr;
+	socklen_t			idc_from_addrlen;
+	struct sockaddr			*idc_to_addr;
+	socklen_t			idc_to_addrlen;
+	int				idc_spare[4];
+};
+
+struct iscsi_daemon_send {
+	int				ids_session_id;
+	void				*ids_bhs;
+	size_t				ids_spare;
+	void				*ids_spare2;
+	size_t				ids_data_segment_len;
+	void				*ids_data_segment;
+	int				ids_spare3[4];
+};
+
+struct iscsi_daemon_receive {
+	int				idr_session_id;
+	void				*idr_bhs;
+	size_t				idr_spare;
+	void				*idr_spare2;
+	size_t				idr_data_segment_len;
+	void				*idr_data_segment;
+	int				idr_spare3[4];
+};
+
+#define	ISCSIDCONNECT	_IOWR('I', 0x04, struct iscsi_daemon_connect)
+#define	ISCSIDSEND	_IOWR('I', 0x05, struct iscsi_daemon_send)
+#define	ISCSIDRECEIVE	_IOWR('I', 0x06, struct iscsi_daemon_receive)
+
+#endif /* ICL_KERNEL_PROXY */
+
+/*
+ * For use with iscsictl(8).
+ */
+
+struct iscsi_session_add {
+	struct iscsi_session_conf	isa_conf;
+	int				isa_spare[4];
+};
+
+struct iscsi_session_remove {
+	unsigned int			isr_session_id;
+	struct iscsi_session_conf	isr_conf;
+	int				isr_spare[4];
+};
+
+struct iscsi_session_list {
+	unsigned int			isl_nentries;
+	struct iscsi_session_state	*isl_pstates;
+	int				isl_spare[4];
+};
+
+struct iscsi_session_modify {
+	unsigned int			ism_session_id;
+	struct iscsi_session_conf	ism_conf;
+	int				ism_spare[4];
+};
+
+#define	ISCSISADD	_IOW('I', 0x11, struct iscsi_session_add)
+#define	ISCSISREMOVE	_IOW('I', 0x12, struct iscsi_session_remove)
+#define	ISCSISLIST	_IOWR('I', 0x13, struct iscsi_session_list)
+#define	ISCSISMODIFY	_IOWR('I', 0x14, struct iscsi_session_modify)
+
+#endif /* !ISCSI_IOCTL_H */


Property changes on: trunk/sys/dev/iscsi/iscsi_ioctl.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sys/dev/iscsi/iscsi_proto.h
===================================================================
--- trunk/sys/dev/iscsi/iscsi_proto.h	                        (rev 0)
+++ trunk/sys/dev/iscsi/iscsi_proto.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -0,0 +1,457 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2012 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Edward Tomasz Napierala under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/sys/dev/iscsi/iscsi_proto.h 278439 2015-02-09 09:08:55Z mav $
+ */
+
+#ifndef ISCSI_PROTO_H
+#define	ISCSI_PROTO_H
+
+#ifndef CTASSERT
+#define CTASSERT(x)		_CTASSERT(x, __LINE__)
+#define _CTASSERT(x, y)		__CTASSERT(x, y)
+#define __CTASSERT(x, y)	typedef char __assert_ ## y [(x) ? 1 : -1]
+#endif
+
+#define	ISCSI_SNGT(x, y)	((int32_t)(x) - (int32_t)(y) > 0)
+#define	ISCSI_SNLT(x, y)	((int32_t)(x) - (int32_t)(y) < 0)
+
+#define	ISCSI_BHS_SIZE			48
+#define	ISCSI_HEADER_DIGEST_SIZE	4
+#define	ISCSI_DATA_DIGEST_SIZE		4
+
+#define	ISCSI_BHS_OPCODE_IMMEDIATE	0x40
+
+#define	ISCSI_BHS_OPCODE_NOP_OUT	0x00
+#define	ISCSI_BHS_OPCODE_SCSI_COMMAND	0x01
+#define	ISCSI_BHS_OPCODE_TASK_REQUEST	0x02
+#define	ISCSI_BHS_OPCODE_LOGIN_REQUEST	0x03
+#define	ISCSI_BHS_OPCODE_TEXT_REQUEST	0x04
+#define	ISCSI_BHS_OPCODE_SCSI_DATA_OUT	0x05
+#define	ISCSI_BHS_OPCODE_LOGOUT_REQUEST	0x06
+
+#define	ISCSI_BHS_OPCODE_NOP_IN		0x20
+#define	ISCSI_BHS_OPCODE_SCSI_RESPONSE	0x21
+#define	ISCSI_BHS_OPCODE_TASK_RESPONSE	0x22
+#define	ISCSI_BHS_OPCODE_LOGIN_RESPONSE	0x23
+#define	ISCSI_BHS_OPCODE_TEXT_RESPONSE	0x24
+#define	ISCSI_BHS_OPCODE_SCSI_DATA_IN	0x25
+#define	ISCSI_BHS_OPCODE_LOGOUT_RESPONSE	0x26
+#define	ISCSI_BHS_OPCODE_R2T		0x31
+#define	ISCSI_BHS_OPCODE_ASYNC_MESSAGE	0x32
+#define	ISCSI_BHS_OPCODE_REJECT		0x3f
+
+struct iscsi_bhs {
+	uint8_t		bhs_opcode;
+	uint8_t		bhs_opcode_specific1[3];
+	uint8_t		bhs_total_ahs_len;
+	uint8_t		bhs_data_segment_len[3];
+	uint64_t	bhs_lun;
+	uint8_t		bhs_inititator_task_tag[4];
+	uint8_t		bhs_opcode_specific4[28];
+};
+CTASSERT(sizeof(struct iscsi_bhs) == ISCSI_BHS_SIZE);
+
+#define	BHSSC_FLAGS_F		0x80
+#define	BHSSC_FLAGS_R		0x40
+#define	BHSSC_FLAGS_W		0x20
+#define	BHSSC_FLAGS_ATTR	0x07
+
+#define	BHSSC_FLAGS_ATTR_UNTAGGED	0
+#define	BHSSC_FLAGS_ATTR_SIMPLE		1
+#define	BHSSC_FLAGS_ATTR_ORDERED	2
+#define	BHSSC_FLAGS_ATTR_HOQ		3
+#define	BHSSC_FLAGS_ATTR_ACA		4
+
+struct iscsi_bhs_scsi_command {
+	uint8_t		bhssc_opcode;
+	uint8_t		bhssc_flags;
+	uint8_t		bhssc_reserved[2];
+	uint8_t		bhssc_total_ahs_len;
+	uint8_t		bhssc_data_segment_len[3];
+	uint64_t	bhssc_lun;
+	uint32_t	bhssc_initiator_task_tag;
+	uint32_t	bhssc_expected_data_transfer_length;
+	uint32_t	bhssc_cmdsn;
+	uint32_t	bhssc_expstatsn;
+	uint8_t		bhssc_cdb[16];
+};
+CTASSERT(sizeof(struct iscsi_bhs_scsi_command) == ISCSI_BHS_SIZE);
+
+#define	BHSSR_FLAGS_RESIDUAL_UNDERFLOW		0x02
+#define	BHSSR_FLAGS_RESIDUAL_OVERFLOW		0x04
+
+#define	BHSSR_RESPONSE_COMMAND_COMPLETED	0x00
+
+struct iscsi_bhs_scsi_response {
+	uint8_t		bhssr_opcode;
+	uint8_t		bhssr_flags;
+	uint8_t		bhssr_response;
+	uint8_t		bhssr_status;
+	uint8_t		bhssr_total_ahs_len;
+	uint8_t		bhssr_data_segment_len[3];
+	uint16_t	bhssr_status_qualifier;
+	uint16_t	bhssr_reserved;
+	uint32_t	bhssr_reserved2;
+	uint32_t	bhssr_initiator_task_tag;
+	uint32_t	bhssr_snack_tag;
+	uint32_t	bhssr_statsn;
+	uint32_t	bhssr_expcmdsn;
+	uint32_t	bhssr_maxcmdsn;
+	uint32_t	bhssr_expdatasn;
+	uint32_t	bhssr_bidirectional_read_residual_count;
+	uint32_t	bhssr_residual_count;
+};
+CTASSERT(sizeof(struct iscsi_bhs_scsi_response) == ISCSI_BHS_SIZE);
+
+#define	BHSTMR_FUNCTION_ABORT_TASK		1
+#define	BHSTMR_FUNCTION_ABORT_TASK_SET		2
+#define	BHSTMR_FUNCTION_CLEAR_ACA		3
+#define	BHSTMR_FUNCTION_CLEAR_TASK_SET		4
+#define	BHSTMR_FUNCTION_LOGICAL_UNIT_RESET	5
+#define	BHSTMR_FUNCTION_TARGET_WARM_RESET	6
+#define	BHSTMR_FUNCTION_TARGET_COLD_RESET	7
+#define	BHSTMR_FUNCTION_TASK_REASSIGN		8
+#define	BHSTMR_FUNCTION_QUERY_TASK		9
+#define	BHSTMR_FUNCTION_QUERY_TASK_SET		10
+#define	BHSTMR_FUNCTION_I_T_NEXUS_RESET		11
+#define	BHSTMR_FUNCTION_QUERY_ASYNC_EVENT	12
+
+struct iscsi_bhs_task_management_request {
+	uint8_t		bhstmr_opcode;
+	uint8_t		bhstmr_function;
+	uint8_t		bhstmr_reserved[2];
+	uint8_t		bhstmr_total_ahs_len;
+	uint8_t		bhstmr_data_segment_len[3];
+	uint64_t	bhstmr_lun;
+	uint32_t	bhstmr_initiator_task_tag;
+	uint32_t	bhstmr_referenced_task_tag;
+	uint32_t	bhstmr_cmdsn;
+	uint32_t	bhstmr_expstatsn;
+	uint32_t	bhstmr_refcmdsn;
+	uint32_t	bhstmr_expdatasn;
+	uint64_t	bhstmr_reserved2;
+};
+CTASSERT(sizeof(struct iscsi_bhs_task_management_request) == ISCSI_BHS_SIZE);
+
+#define	BHSTMR_RESPONSE_FUNCTION_COMPLETE	0
+#define	BHSTMR_RESPONSE_TASK_DOES_NOT_EXIST	1
+#define	BHSTMR_RESPONSE_LUN_DOES_NOT_EXIST	2
+#define	BHSTMR_RESPONSE_TASK_STILL_ALLEGIANT	3
+#define	BHSTMR_RESPONSE_TASK_ALL_REASS_NOT_SUPP	4
+#define	BHSTMR_RESPONSE_FUNCTION_NOT_SUPPORTED	5
+#define	BHSTMR_RESPONSE_FUNCTION_AUTH_FAIL	6
+#define	BHSTMR_RESPONSE_FUNCTION_SUCCEEDED	7
+#define	BHSTMR_RESPONSE_FUNCTION_REJECTED	255
+
+struct iscsi_bhs_task_management_response {
+	uint8_t		bhstmr_opcode;
+	uint8_t		bhstmr_flags;
+	uint8_t		bhstmr_response;
+	uint8_t		bhstmr_reserved;
+	uint8_t		bhstmr_total_ahs_len;
+	uint8_t		bhstmr_data_segment_len[3];
+	uint8_t		bhstmr_additional_reponse_information[3];
+	uint8_t		bhstmr_reserved2[5];
+	uint32_t	bhstmr_initiator_task_tag;
+	uint32_t	bhstmr_reserved3;
+	uint32_t	bhstmr_statsn;
+	uint32_t	bhstmr_expcmdsn;
+	uint32_t	bhstmr_maxcmdsn;
+	uint8_t		bhstmr_reserved4[12];
+};
+CTASSERT(sizeof(struct iscsi_bhs_task_management_response) == ISCSI_BHS_SIZE);
+
+#define	BHSLR_FLAGS_TRANSIT		0x80
+#define	BHSLR_FLAGS_CONTINUE		0x40
+
+#define	BHSLR_STAGE_SECURITY_NEGOTIATION	0
+#define	BHSLR_STAGE_OPERATIONAL_NEGOTIATION	1
+#define	BHSLR_STAGE_FULL_FEATURE_PHASE		3 /* Yes, 3. */
+
+struct iscsi_bhs_login_request {
+	uint8_t		bhslr_opcode;
+	uint8_t		bhslr_flags;
+	uint8_t		bhslr_version_max;
+	uint8_t		bhslr_version_min;
+	uint8_t		bhslr_total_ahs_len;
+	uint8_t		bhslr_data_segment_len[3];
+	uint8_t		bhslr_isid[6];
+	uint16_t	bhslr_tsih;
+	uint32_t	bhslr_initiator_task_tag;
+	uint16_t	bhslr_cid;
+	uint16_t	bhslr_reserved;
+	uint32_t	bhslr_cmdsn;
+	uint32_t	bhslr_expstatsn;
+	uint8_t		bhslr_reserved2[16];
+};
+CTASSERT(sizeof(struct iscsi_bhs_login_request) == ISCSI_BHS_SIZE);
+
+struct iscsi_bhs_login_response {
+	uint8_t		bhslr_opcode;
+	uint8_t		bhslr_flags;
+	uint8_t		bhslr_version_max;
+	uint8_t		bhslr_version_active;
+	uint8_t		bhslr_total_ahs_len;
+	uint8_t		bhslr_data_segment_len[3];
+	uint8_t		bhslr_isid[6];
+	uint16_t	bhslr_tsih;
+	uint32_t	bhslr_initiator_task_tag;
+	uint32_t	bhslr_reserved;
+	uint32_t	bhslr_statsn;
+	uint32_t	bhslr_expcmdsn;
+	uint32_t	bhslr_maxcmdsn;
+	uint8_t		bhslr_status_class;
+	uint8_t		bhslr_status_detail;
+	uint16_t	bhslr_reserved2;
+	uint8_t		bhslr_reserved3[8];
+};
+CTASSERT(sizeof(struct iscsi_bhs_login_response) == ISCSI_BHS_SIZE);
+
+#define	BHSTR_FLAGS_FINAL		0x80
+#define	BHSTR_FLAGS_CONTINUE		0x40
+
+struct iscsi_bhs_text_request {
+	uint8_t		bhstr_opcode;
+	uint8_t		bhstr_flags;
+	uint16_t	bhstr_reserved;
+	uint8_t		bhstr_total_ahs_len;
+	uint8_t		bhstr_data_segment_len[3];
+	uint64_t	bhstr_lun;
+	uint32_t	bhstr_initiator_task_tag;
+	uint32_t	bhstr_target_transfer_tag;
+	uint32_t	bhstr_cmdsn;
+	uint32_t	bhstr_expstatsn;
+	uint8_t		bhstr_reserved2[16];
+};
+CTASSERT(sizeof(struct iscsi_bhs_text_request) == ISCSI_BHS_SIZE);
+
+struct iscsi_bhs_text_response {
+	uint8_t		bhstr_opcode;
+	uint8_t		bhstr_flags;
+	uint16_t	bhstr_reserved;
+	uint8_t		bhstr_total_ahs_len;
+	uint8_t		bhstr_data_segment_len[3];
+	uint64_t	bhstr_lun;
+	uint32_t	bhstr_initiator_task_tag;
+	uint32_t	bhstr_target_transfer_tag;
+	uint32_t	bhstr_statsn;
+	uint32_t	bhstr_expcmdsn;
+	uint32_t	bhstr_maxcmdsn;
+	uint8_t		bhstr_reserved2[12];
+};
+CTASSERT(sizeof(struct iscsi_bhs_text_response) == ISCSI_BHS_SIZE);
+
+#define	BHSDO_FLAGS_F	0x80
+
+struct iscsi_bhs_data_out {
+	uint8_t		bhsdo_opcode;
+	uint8_t		bhsdo_flags;
+	uint8_t		bhsdo_reserved[2];
+	uint8_t		bhsdo_total_ahs_len;
+	uint8_t		bhsdo_data_segment_len[3];
+	uint64_t	bhsdo_lun;
+	uint32_t	bhsdo_initiator_task_tag;
+	uint32_t	bhsdo_target_transfer_tag;
+	uint32_t	bhsdo_reserved2;
+	uint32_t	bhsdo_expstatsn;
+	uint32_t	bhsdo_reserved3;
+	uint32_t	bhsdo_datasn;
+	uint32_t	bhsdo_buffer_offset;
+	uint32_t	bhsdo_reserved4;
+};
+CTASSERT(sizeof(struct iscsi_bhs_data_out) == ISCSI_BHS_SIZE);
+
+#define	BHSDI_FLAGS_F	0x80
+#define	BHSDI_FLAGS_A	0x40
+#define	BHSDI_FLAGS_O	0x04
+#define	BHSDI_FLAGS_U	0x02
+#define	BHSDI_FLAGS_S	0x01
+
+struct iscsi_bhs_data_in {
+	uint8_t		bhsdi_opcode;
+	uint8_t		bhsdi_flags;
+	uint8_t		bhsdi_reserved;
+	uint8_t		bhsdi_status;
+	uint8_t		bhsdi_total_ahs_len;
+	uint8_t		bhsdi_data_segment_len[3];
+	uint64_t	bhsdi_lun;
+	uint32_t	bhsdi_initiator_task_tag;
+	uint32_t	bhsdi_target_transfer_tag;
+	uint32_t	bhsdi_statsn;
+	uint32_t	bhsdi_expcmdsn;
+	uint32_t	bhsdi_maxcmdsn;
+	uint32_t	bhsdi_datasn;
+	uint32_t	bhsdi_buffer_offset;
+	uint32_t	bhsdi_residual_count;
+};
+CTASSERT(sizeof(struct iscsi_bhs_data_in) == ISCSI_BHS_SIZE);
+
+struct iscsi_bhs_r2t {
+	uint8_t		bhsr2t_opcode;
+	uint8_t		bhsr2t_flags;
+	uint16_t	bhsr2t_reserved;
+	uint8_t		bhsr2t_total_ahs_len;
+	uint8_t		bhsr2t_data_segment_len[3];
+	uint64_t	bhsr2t_lun;
+	uint32_t	bhsr2t_initiator_task_tag;
+	uint32_t	bhsr2t_target_transfer_tag;
+	uint32_t	bhsr2t_statsn;
+	uint32_t	bhsr2t_expcmdsn;
+	uint32_t	bhsr2t_maxcmdsn;
+	uint32_t	bhsr2t_r2tsn;
+	uint32_t	bhsr2t_buffer_offset;
+	uint32_t	bhsr2t_desired_data_transfer_length;
+};
+CTASSERT(sizeof(struct iscsi_bhs_r2t) == ISCSI_BHS_SIZE);
+
+struct iscsi_bhs_nop_out {
+	uint8_t		bhsno_opcode;
+	uint8_t		bhsno_flags;
+	uint16_t	bhsno_reserved;
+	uint8_t		bhsno_total_ahs_len;
+	uint8_t		bhsno_data_segment_len[3];
+	uint64_t	bhsno_lun;
+	uint32_t	bhsno_initiator_task_tag;
+	uint32_t	bhsno_target_transfer_tag;
+	uint32_t	bhsno_cmdsn;
+	uint32_t	bhsno_expstatsn;
+	uint8_t		bhsno_reserved2[16];
+};
+CTASSERT(sizeof(struct iscsi_bhs_nop_out) == ISCSI_BHS_SIZE);
+
+struct iscsi_bhs_nop_in {
+	uint8_t		bhsni_opcode;
+	uint8_t		bhsni_flags;
+	uint16_t	bhsni_reserved;
+	uint8_t		bhsni_total_ahs_len;
+	uint8_t		bhsni_data_segment_len[3];
+	uint64_t	bhsni_lun;
+	uint32_t	bhsni_initiator_task_tag;
+	uint32_t	bhsni_target_transfer_tag;
+	uint32_t	bhsni_statsn;
+	uint32_t	bhsni_expcmdsn;
+	uint32_t	bhsni_maxcmdsn;
+	uint8_t		bhsno_reserved2[12];
+};
+CTASSERT(sizeof(struct iscsi_bhs_nop_in) == ISCSI_BHS_SIZE);
+
+#define	BHSLR_REASON_CLOSE_SESSION		0
+#define	BHSLR_REASON_CLOSE_CONNECTION		1
+#define	BHSLR_REASON_REMOVE_FOR_RECOVERY	2
+
+struct iscsi_bhs_logout_request {
+	uint8_t		bhslr_opcode;
+	uint8_t		bhslr_reason;
+	uint16_t	bhslr_reserved;
+	uint8_t		bhslr_total_ahs_len;
+	uint8_t		bhslr_data_segment_len[3];
+	uint64_t	bhslr_reserved2;
+	uint32_t	bhslr_initiator_task_tag;
+	uint16_t	bhslr_cid;
+	uint16_t	bhslr_reserved3;
+	uint32_t	bhslr_cmdsn;
+	uint32_t	bhslr_expstatsn;
+	uint8_t		bhslr_reserved4[16];
+};
+CTASSERT(sizeof(struct iscsi_bhs_logout_request) == ISCSI_BHS_SIZE);
+
+#define	BHSLR_RESPONSE_CLOSED_SUCCESSFULLY	0
+#define	BHSLR_RESPONSE_RECOVERY_NOT_SUPPORTED	2
+
+struct iscsi_bhs_logout_response {
+	uint8_t		bhslr_opcode;
+	uint8_t		bhslr_flags;
+	uint8_t		bhslr_response;
+	uint8_t		bhslr_reserved;
+	uint8_t		bhslr_total_ahs_len;
+	uint8_t		bhslr_data_segment_len[3];
+	uint64_t	bhslr_reserved2;
+	uint32_t	bhslr_initiator_task_tag;
+	uint32_t	bhslr_reserved3;
+	uint32_t	bhslr_statsn;
+	uint32_t	bhslr_expcmdsn;
+	uint32_t	bhslr_maxcmdsn;
+	uint32_t	bhslr_reserved4;
+	uint16_t	bhslr_time2wait;
+	uint16_t	bhslr_time2retain;
+	uint32_t	bhslr_reserved5;
+};
+CTASSERT(sizeof(struct iscsi_bhs_logout_response) == ISCSI_BHS_SIZE);
+
+#define	BHSAM_EVENT_TARGET_REQUESTS_LOGOUT		1
+#define	BHSAM_EVENT_TARGET_TERMINATES_CONNECTION	2
+#define	BHSAM_EVENT_TARGET_TERMINATES_SESSION		3
+
+struct iscsi_bhs_asynchronous_message {
+	uint8_t		bhsam_opcode;
+	uint8_t		bhsam_flags;
+	uint16_t	bhsam_reserved;
+	uint8_t		bhsam_total_ahs_len;
+	uint8_t		bhsam_data_segment_len[3];
+	uint64_t	bhsam_lun;
+	uint32_t	bhsam_0xffffffff;
+	uint32_t	bhsam_reserved2;
+	uint32_t	bhsam_statsn;
+	uint32_t	bhsam_expcmdsn;
+	uint32_t	bhsam_maxcmdsn;
+	uint8_t		bhsam_async_event;
+	uint8_t		bhsam_async_vcode;
+	uint16_t	bhsam_parameter1;
+	uint16_t	bhsam_parameter2;
+	uint16_t	bhsam_parameter3;
+	uint32_t	bhsam_reserved3;
+};
+CTASSERT(sizeof(struct iscsi_bhs_asynchronous_message) == ISCSI_BHS_SIZE);
+
+#define BHSSR_REASON_DATA_DIGEST_ERROR	0x02
+#define BHSSR_PROTOCOL_ERROR		0x04
+#define BHSSR_COMMAND_NOT_SUPPORTED	0x05
+#define BHSSR_INVALID_PDU_FIELD		0x09
+
+struct iscsi_bhs_reject {
+	uint8_t		bhsr_opcode;
+	uint8_t		bhsr_flags;
+	uint8_t		bhsr_reason;
+	uint8_t		bhsr_reserved;
+	uint8_t		bhsr_total_ahs_len;
+	uint8_t		bhsr_data_segment_len[3];
+	uint64_t	bhsr_reserved2;
+	uint32_t	bhsr_0xffffffff;
+	uint32_t	bhsr_reserved3;
+	uint32_t	bhsr_statsn;
+	uint32_t	bhsr_expcmdsn;
+	uint32_t	bhsr_maxcmdsn;
+	uint32_t	bhsr_datasn_r2tsn;
+	uint32_t	bhsr_reserved4;
+	uint32_t	bhsr_reserved5;
+};
+CTASSERT(sizeof(struct iscsi_bhs_reject) == ISCSI_BHS_SIZE);
+
+#endif /* !ISCSI_PROTO_H */


Property changes on: trunk/sys/dev/iscsi/iscsi_proto.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sys/dev/iscsi_initiator/isc_cam.c
===================================================================
--- trunk/sys/dev/iscsi_initiator/isc_cam.c	                        (rev 0)
+++ trunk/sys/dev/iscsi_initiator/isc_cam.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -0,0 +1,380 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2005-2010 Daniel Braniss <danny at cs.huji.ac.il>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+/*
+ | $Id: isc_cam.c 998 2009-12-20 10:32:45Z danny $
+ */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/sys/dev/iscsi_initiator/isc_cam.c 315813 2017-03-23 06:41:13Z mav $");
+
+#include "opt_iscsi_initiator.h"
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/callout.h>
+#if __FreeBSD_version >= 700000
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#endif
+#include <sys/conf.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/uio.h>
+#include <sys/sysctl.h>
+#include <sys/sx.h>
+
+#include <cam/cam.h>
+#include <cam/cam_ccb.h>
+#include <cam/cam_sim.h>
+#include <cam/cam_xpt_sim.h>
+#include <cam/cam_periph.h>
+
+#include <dev/iscsi_initiator/iscsi.h>
+#include <dev/iscsi_initiator/iscsivar.h>
+
+static void
+_inq(struct cam_sim *sim, union ccb *ccb)
+{
+     struct ccb_pathinq *cpi = &ccb->cpi;
+     isc_session_t *sp = cam_sim_softc(sim);
+
+     debug_called(8);
+     debug(3, "sid=%d target=%d lun=%d", sp->sid, ccb->ccb_h.target_id, ccb->ccb_h.target_lun);
+
+     cpi->version_num = 1; /* XXX??? */
+     cpi->hba_inquiry = PI_SDTR_ABLE | PI_TAG_ABLE | PI_WIDE_32;
+     cpi->target_sprt = 0;
+     cpi->hba_misc = 0;
+     cpi->hba_eng_cnt = 0;
+     cpi->max_target = 0; //ISCSI_MAX_TARGETS - 1;
+     cpi->initiator_id = ISCSI_MAX_TARGETS;
+     cpi->max_lun = sp->opt.maxluns - 1;
+     cpi->bus_id = cam_sim_bus(sim);
+     cpi->base_transfer_speed = 3300; // 40000; // XXX:
+     strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
+     strlcpy(cpi->hba_vid, "iSCSI", HBA_IDLEN);
+     strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
+     cpi->unit_number = cam_sim_unit(sim);
+     cpi->ccb_h.status = CAM_REQ_CMP;
+#if defined(KNOB_VALID_ADDRESS)
+     cpi->transport = XPORT_ISCSI;
+     cpi->transport_version = 0;
+#endif
+}
+
+static __inline int
+_scsi_encap(struct cam_sim *sim, union ccb *ccb)
+{
+     int		ret;
+
+#if __FreeBSD_version < 700000
+     ret = scsi_encap(sim, ccb);
+#else
+     isc_session_t	*sp = cam_sim_softc(sim);
+
+     mtx_unlock(&sp->cam_mtx);
+     ret = scsi_encap(sim, ccb);
+     mtx_lock(&sp->cam_mtx);
+#endif
+     return ret;
+}
+
+void
+ic_lost_target(isc_session_t *sp, int target)
+{
+     debug_called(8);
+     sdebug(2, "lost target=%d", target);
+
+     if(sp->cam_path != NULL) {
+	  mtx_lock(&sp->cam_mtx);
+	  xpt_async(AC_LOST_DEVICE, sp->cam_path, NULL);
+	  xpt_free_path(sp->cam_path);
+	  mtx_unlock(&sp->cam_mtx);
+	  sp->cam_path = 0; // XXX
+     }
+}
+
+static void
+scan_callback(struct cam_periph *periph, union ccb *ccb)
+{
+     isc_session_t *sp = (isc_session_t *)ccb->ccb_h.spriv_ptr0;
+
+     debug_called(8);
+
+     xpt_free_ccb(ccb);
+
+     if(sp->flags & ISC_SCANWAIT) {
+	  sp->flags &= ~ISC_SCANWAIT;
+	  wakeup(sp);
+     }
+}
+
+static int
+ic_scan(isc_session_t *sp)
+{
+     union ccb	*ccb;
+
+     debug_called(8);
+     sdebug(2, "scanning sid=%d", sp->sid);
+
+     sp->flags &= ~ISC_CAMDEVS;
+     sp->flags |= ISC_SCANWAIT;
+
+     ccb = xpt_alloc_ccb();
+     ccb->ccb_h.path		= sp->cam_path;
+     ccb->ccb_h.cbfcnp		= scan_callback;
+     ccb->ccb_h.spriv_ptr0	= sp;
+
+     xpt_rescan(ccb);
+
+     while(sp->flags & ISC_SCANWAIT)
+	  tsleep(sp, PRIBIO, "ffp", 5*hz); // the timeout time should
+					    // be configurable
+     sdebug(2, "# of luns=%d", sp->target_nluns);
+
+     if(sp->target_nluns > 0) {
+	  sp->flags |= ISC_CAMDEVS;
+	  return 0;
+     }
+
+     return ENODEV;
+}
+
+static void
+ic_action(struct cam_sim *sim, union ccb *ccb)
+{
+     isc_session_t	*sp = cam_sim_softc(sim);
+     struct ccb_hdr	*ccb_h = &ccb->ccb_h;
+
+     debug_called(8);
+
+     ccb_h->spriv_ptr0 = sp;
+     sdebug(4, "func_code=0x%x flags=0x%x status=0x%x target=%d lun=%d retry_count=%d timeout=%d",
+	   ccb_h->func_code, ccb->ccb_h.flags, ccb->ccb_h.status,
+	   ccb->ccb_h.target_id, ccb->ccb_h.target_lun, 
+	   ccb->ccb_h.retry_count, ccb_h->timeout);
+     if(sp == NULL) {
+	  xdebug("sp == NULL! cannot happen");
+	  return;
+     }	  
+     switch(ccb_h->func_code) {
+     case XPT_PATH_INQ:
+	  _inq(sim, ccb);
+	  break;
+
+     case XPT_RESET_BUS: // (can just be a stub that does nothing and completes)
+     {
+	  struct ccb_pathinq *cpi = &ccb->cpi;
+
+	  debug(3, "XPT_RESET_BUS");
+	  cpi->ccb_h.status = CAM_REQ_CMP;
+	  break;
+     }
+
+     case XPT_SCSI_IO: 
+     {
+	  struct ccb_scsiio* csio = &ccb->csio;
+
+	  debug(4, "XPT_SCSI_IO cmd=0x%x", csio->cdb_io.cdb_bytes[0]);
+	  if(sp == NULL) {
+	       ccb_h->status = CAM_REQ_INVALID; //CAM_NO_NEXUS;
+	       debug(4, "xpt_done.status=%d", ccb_h->status);
+	       break;
+	  }
+	  if(ccb_h->target_lun == CAM_LUN_WILDCARD) {
+	       debug(3, "target=%d: bad lun (-1)", ccb_h->target_id);
+	       ccb_h->status = CAM_LUN_INVALID;
+	       break;
+	  }
+	  if(_scsi_encap(sim, ccb) != 0)
+	       return;
+	  break;
+     }
+ 
+     case XPT_CALC_GEOMETRY:
+     {
+	  struct	ccb_calc_geometry *ccg;
+
+	  ccg = &ccb->ccg;
+	  debug(4, "sid=%d target=%d lun=%d XPT_CALC_GEOMETRY vsize=%jd bsize=%d",
+		sp->sid, ccb->ccb_h.target_id, ccb->ccb_h.target_lun,
+		ccg->volume_size, ccg->block_size);
+	  if(ccg->block_size == 0 ||
+	     (ccg->volume_size < ccg->block_size)) {
+	       // print error message  ...
+	       /* XXX: what error is appropiate? */
+	       break;
+	  } 
+	  else {
+	       int	lun, *off, boff;
+
+	       lun = ccb->ccb_h.target_lun;
+	       if(lun > ISCSI_MAX_LUNS) {
+		    // XXX: 
+		    xdebug("lun %d > ISCSI_MAX_LUNS!\n", lun);
+		    lun %= ISCSI_MAX_LUNS;
+	       }
+	       off = &sp->target_lun[lun / (sizeof(int)*8)];
+	       boff = BIT(lun % (sizeof(int)*8));
+	       debug(4, "sp->target_nluns=%d *off=%x boff=%x",
+		     sp->target_nluns, *off, boff);
+
+	       if((*off & boff) == 0) {
+		    sp->target_nluns++;
+		    *off |= boff;
+	       }
+	       cam_calc_geometry(ccg, /*extended*/1);
+	  }
+	  break;
+     }
+
+     case XPT_GET_TRAN_SETTINGS:
+     default:
+	  ccb_h->status = CAM_REQ_INVALID;
+	  break;
+     }
+#if __FreeBSD_version < 700000
+     XPT_DONE(sp, ccb);
+#else
+     xpt_done(ccb);
+#endif
+     return;
+}
+
+static void
+ic_poll(struct cam_sim *sim)
+{
+     debug_called(4);
+
+}
+
+int
+ic_getCamVals(isc_session_t *sp, iscsi_cam_t *cp)
+{
+     debug_called(8);
+
+     if(sp && sp->cam_sim) {
+	  cp->path_id = cam_sim_path(sp->cam_sim);
+	  cp->target_id = 0;
+	  cp->target_nluns = ISCSI_MAX_LUNS; // XXX: -1?
+	  return 0;
+     }
+     return ENXIO;
+}
+
+void
+ic_destroy(isc_session_t *sp )
+{
+     debug_called(8);
+
+     if(sp->cam_path != NULL) {
+	  sdebug(2, "name=%s unit=%d",
+		 cam_sim_name(sp->cam_sim), cam_sim_unit(sp->cam_sim));
+	  CAM_LOCK(sp);
+#if 0
+	  xpt_async(AC_LOST_DEVICE, sp->cam_path, NULL);
+#else
+	  xpt_async(XPT_RESET_BUS, sp->cam_path, NULL);
+#endif
+	  xpt_free_path(sp->cam_path);
+	  xpt_bus_deregister(cam_sim_path(sp->cam_sim));
+	  cam_sim_free(sp->cam_sim, TRUE /*free_devq*/);
+
+	  CAM_UNLOCK(sp);
+	  sdebug(2, "done");
+     }
+}
+
+int
+ic_init(isc_session_t *sp)
+{
+     struct cam_sim	*sim;
+     struct cam_devq	*devq;
+
+     debug_called(8);
+
+     if((devq = cam_simq_alloc(256)) == NULL)
+	  return ENOMEM;
+
+#if __FreeBSD_version >= 700000
+     mtx_init(&sp->cam_mtx, "isc-cam", NULL, MTX_DEF);
+#else
+     isp->cam_mtx = Giant;
+#endif
+     sim = cam_sim_alloc(ic_action,
+			 ic_poll,
+			 "iscsi",
+			 sp,
+			 sp->sid,	// unit
+#if __FreeBSD_version >= 700000
+			 &sp->cam_mtx,
+#endif
+			 1,		// max_dev_transactions
+			 0,		// max_tagged_dev_transactions
+			 devq);
+     if(sim == NULL) {
+	  cam_simq_free(devq);
+#if __FreeBSD_version >= 700000
+	  mtx_destroy(&sp->cam_mtx);
+#endif
+	  return ENXIO;
+     }
+
+     CAM_LOCK(sp);
+     if(xpt_bus_register(sim,
+#if __FreeBSD_version >= 700000
+			 NULL,
+#endif
+			 0/*bus_number*/) != CAM_SUCCESS) {
+
+	  cam_sim_free(sim, /*free_devq*/TRUE);
+	  CAM_UNLOCK(sp);
+#if __FreeBSD_version >= 700000
+	  mtx_destroy(&sp->cam_mtx);
+#endif
+	  return ENXIO;
+     }
+     sp->cam_sim = sim;
+     if(xpt_create_path(&sp->cam_path, NULL, cam_sim_path(sp->cam_sim),
+	    CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
+	  xpt_bus_deregister(cam_sim_path(sp->cam_sim));
+	  cam_sim_free(sim, /*free_devq*/TRUE);
+	  CAM_UNLOCK(sp);
+#if __FreeBSD_version >= 700000
+	  mtx_destroy(&sp->cam_mtx);
+#endif
+	  return ENXIO;
+     }
+     CAM_UNLOCK(sp);
+
+     sdebug(1, "cam subsystem initialized");
+
+     ic_scan(sp);
+
+     return 0;
+}


Property changes on: trunk/sys/dev/iscsi_initiator/isc_cam.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sys/dev/iscsi_initiator/isc_sm.c
===================================================================
--- trunk/sys/dev/iscsi_initiator/isc_sm.c	                        (rev 0)
+++ trunk/sys/dev/iscsi_initiator/isc_sm.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -0,0 +1,787 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2005-2010 Daniel Braniss <danny at cs.huji.ac.il>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+/*
+ | iSCSI - Session Manager
+ | $Id: isc_sm.c 743 2009-08-08 10:54:53Z danny $
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/sys/dev/iscsi_initiator/isc_sm.c 254657 2013-08-22 14:02:34Z trasz $");
+
+#include "opt_iscsi_initiator.h"
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/conf.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/ctype.h>
+#include <sys/errno.h>
+#include <sys/sysctl.h>
+#include <sys/file.h>
+#include <sys/uio.h>
+#include <sys/socketvar.h>
+#include <sys/socket.h>
+#include <sys/protosw.h>
+#include <sys/proc.h>
+#include <sys/ioccom.h>
+#include <sys/queue.h>
+#include <sys/kthread.h>
+#include <sys/syslog.h>
+#include <sys/mbuf.h>
+#include <sys/bus.h>
+#include <sys/sx.h>
+
+#include <cam/cam.h>
+#include <cam/cam_ccb.h>
+#include <cam/cam_sim.h>
+#include <cam/cam_xpt_sim.h>
+#include <cam/cam_periph.h>
+
+#include <dev/iscsi_initiator/iscsi.h>
+#include <dev/iscsi_initiator/iscsivar.h>
+
+static void
+_async(isc_session_t *sp, pduq_t *pq)
+{
+     debug_called(8);
+
+     iscsi_async(sp, pq);
+
+     pdu_free(sp->isc, pq);
+}
+
+static void
+_reject(isc_session_t *sp, pduq_t *pq)
+{
+     pduq_t	*opq;
+     pdu_t	*pdu;
+     reject_t	*reject;
+     int	itt;
+
+     debug_called(8);
+     pdu = mtod(pq->mp, pdu_t *);
+     itt = pdu->ipdu.bhs.itt;
+     reject = &pq->pdu.ipdu.reject;
+     sdebug(2, "itt=%x reason=0x%x", ntohl(itt), reject->reason);
+     opq = i_search_hld(sp, itt, 0);
+     if(opq != NULL)
+	  iscsi_reject(sp, opq, pq);
+     else {
+	  switch(pq->pdu.ipdu.bhs.opcode) {
+	  case ISCSI_LOGOUT_CMD: // XXX: wasabi does this - can't figure out why
+	       sdebug(2, "ISCSI_LOGOUT_CMD ...");
+	       break;
+	  default:
+	       xdebug("%d] we lost something itt=%x",
+		      sp->sid, ntohl(pq->pdu.ipdu.bhs.itt));
+	  }
+     }
+     pdu_free(sp->isc, pq);
+}
+
+static void
+_r2t(isc_session_t *sp, pduq_t *pq)
+{
+     pduq_t	*opq;
+
+     debug_called(8);
+     opq = i_search_hld(sp, pq->pdu.ipdu.bhs.itt, 1);
+     if(opq != NULL) {
+	  iscsi_r2t(sp, opq, pq);
+     } 
+     else {
+	  r2t_t		*r2t = &pq->pdu.ipdu.r2t;
+
+	  xdebug("%d] we lost something itt=%x r2tSN=%d bo=%x ddtl=%x",
+		 sp->sid, ntohl(pq->pdu.ipdu.bhs.itt),
+		 ntohl(r2t->r2tSN), ntohl(r2t->bo), ntohl(r2t->ddtl));
+     }
+     pdu_free(sp->isc, pq);
+}
+
+static void
+_scsi_rsp(isc_session_t *sp, pduq_t *pq)
+{
+     pduq_t	*opq;
+
+     debug_called(8);
+     opq = i_search_hld(sp, pq->pdu.ipdu.bhs.itt, 0);
+     debug(5, "itt=%x pq=%p opq=%p", ntohl(pq->pdu.ipdu.bhs.itt), pq, opq);
+     if(opq != NULL) {
+	  iscsi_done(sp, opq, pq);
+	  i_acked_hld(sp, &pq->pdu);
+     }
+     else
+	  xdebug("%d] we lost something itt=%x",
+		 sp->sid, ntohl(pq->pdu.ipdu.bhs.itt));
+     pdu_free(sp->isc, pq);
+}
+
+static void
+_read_data(isc_session_t *sp, pduq_t *pq)
+{
+     pduq_t		*opq;
+
+     debug_called(8);
+     opq = i_search_hld(sp, pq->pdu.ipdu.bhs.itt, 1);
+     if(opq != NULL) {
+	  if(scsi_decap(sp, opq, pq) != 1) {
+	       i_remove_hld(sp, opq); // done
+	       pdu_free(sp->isc, opq);
+	  }
+     }
+     else
+	  xdebug("%d] we lost something itt=%x",
+		 sp->sid, ntohl(pq->pdu.ipdu.bhs.itt));
+     pdu_free(sp->isc, pq);
+}
+/*
+ | this is a kludge,
+ | the jury is not back with a veredict, user or kernel
+ */
+static void
+_nop_out(isc_session_t *sp)
+{
+     pduq_t	*pq;
+     nop_out_t	*nop_out;
+
+     debug_called(8);
+
+     sdebug(4, "cws=%d", sp->cws);
+     if(sp->cws == 0) {
+	  /*
+	   | only send a nop if window is closed.
+	   */
+	  if((pq = pdu_alloc(sp->isc, M_NOWAIT)) == NULL)
+	       // I guess we ran out of resources
+	       return;
+	  nop_out = &pq->pdu.ipdu.nop_out;
+	  nop_out->opcode = ISCSI_NOP_OUT;
+	  nop_out->itt = htonl(sp->sn.itt);
+	  nop_out->ttt = -1;
+	  nop_out->I = 1;
+	  nop_out->F = 1;
+	  if(isc_qout(sp, pq) != 0) {
+	       sdebug(1, "failed");
+	       pdu_free(sp->isc, pq);
+	  }
+     }
+}
+
+static void
+_nop_in(isc_session_t *sp, pduq_t *pq)
+{
+     pdu_t	*pp = &pq->pdu;
+     nop_in_t	*nop_in = &pp->ipdu.nop_in;
+     bhs_t	*bhs = &pp->ipdu.bhs;
+
+     debug_called(8);
+
+     sdebug(5, "itt=%x ttt=%x", htonl(nop_in->itt), htonl(nop_in->ttt));
+     if(nop_in->itt == -1) {
+	  if(pp->ds_len != 0) {
+	       /*
+		| according to RFC 3720 this should be zero
+		| what to do if not?
+		*/
+	       xdebug("%d] dslen not zero", sp->sid);
+	  }
+	  if(nop_in->ttt != -1) {
+	       nop_out_t	*nop_out;
+	       /*
+		| target wants a nop_out
+	        */
+	       bhs->opcode = ISCSI_NOP_OUT;
+	       bhs->I = 1;
+	       bhs->F = 1;
+	       /*
+		| we are reusing the pdu, so bhs->ttt == nop_in->ttt;
+		| and need to zero out 'Reserved'
+		| small cludge here.
+	        */
+	       nop_out = &pp->ipdu.nop_out;
+	       nop_out->sn.maxcmd = 0;
+	       memset(nop_out->mbz, 0, sizeof(nop_out->mbz));
+	       (void)isc_qout(sp, pq); //XXX: should check return?
+	       return;
+	  }
+	  //else {
+	       // just making noise?
+	       // see 10.9.1: target does not want and answer.
+	  //}
+
+     } else
+     if(nop_in->ttt == -1) {
+	  /*
+	   | it is an answer to a nop_in from us
+	   */
+	  if(nop_in->itt != -1) {
+#ifdef ISC_WAIT4PING
+	       // XXX: MUTEX please
+	       if(sp->flags & ISC_WAIT4PING) {
+		    i_nqueue_rsp(sp, pq);
+		    wakeup(&sp->rsp);
+		    return;
+	       }
+#endif
+	  }
+     }
+     /*
+      | drop it
+      */
+     pdu_free(sp->isc, pq);
+     return;
+}
+
+int
+i_prepPDU(isc_session_t *sp, pduq_t *pq)
+{
+     size_t	len, n;
+     pdu_t	*pp = &pq->pdu;
+     bhs_t	*bhp = &pp->ipdu.bhs;
+
+     len = sizeof(bhs_t);
+     if(pp->ahs_len) {
+	  len += pp->ahs_len;
+	  bhp->AHSLength =  pp->ahs_len / 4;
+     }
+     if(ISOK2DIG(sp->hdrDigest, pp))
+	  len += 4;
+     if(pp->ds_len) {
+	  n = pp->ds_len;
+	  len += n;
+#if BYTE_ORDER == LITTLE_ENDIAN
+	  bhp->DSLength = ((n & 0x00ff0000) >> 16)
+	       | (n & 0x0000ff00)
+	       | ((n & 0x000000ff) << 16);
+#else
+	  bhp->DSLength = n;
+#endif
+	  if(len & 03) {
+	       n = 4 - (len & 03);
+	       len += n;
+	  }
+	  if(ISOK2DIG(sp->dataDigest, pp))
+	       len += 4;
+     }
+
+     pq->len = len;
+     len -= sizeof(bhs_t);
+     if(sp->opt.maxBurstLength && (len > sp->opt.maxBurstLength)) {
+	  xdebug("%d] pdu len=%zd > %d",
+		 sp->sid, len, sp->opt.maxBurstLength);
+	  // XXX: when this happens it used to hang ...
+	  return E2BIG;
+     }
+     return 0;
+}
+
+int
+isc_qout(isc_session_t *sp, pduq_t *pq)
+{
+     int error = 0;
+
+     debug_called(8);
+
+     if(pq->len == 0 && (error = i_prepPDU(sp, pq)))
+	  return error;
+
+     if(pq->pdu.ipdu.bhs.I)
+	  i_nqueue_isnd(sp, pq);
+     else
+     if(pq->pdu.ipdu.data_out.opcode == ISCSI_WRITE_DATA)
+	  i_nqueue_wsnd(sp, pq);
+     else
+	  i_nqueue_csnd(sp, pq);
+
+     sdebug(5, "enqued: pq=%p", pq);
+
+     mtx_lock(&sp->io_mtx);
+     sp->flags |= ISC_OQNOTEMPTY;
+     if(sp->flags & ISC_OWAITING)
+	  wakeup(&sp->flags);
+     mtx_unlock(&sp->io_mtx);
+
+     return error;
+}
+/*
+ | called when a fullPhase is restarted
+ */
+void
+ism_restart(isc_session_t *sp)
+{
+     int lastcmd;
+
+     sdebug(2, "restart ...");
+     lastcmd = iscsi_requeue(sp);
+#if 0
+     if(lastcmd != sp->sn.cmd) {
+	  sdebug(1, "resetting CmdSN to=%d (from %d)", lastcmd, sp->sn.cmd);
+	  sp->sn.cmd = lastcmd;
+     }
+#endif
+     mtx_lock(&sp->io_mtx);
+     if(sp->flags & ISC_OWAITING) {
+	  wakeup(&sp->flags);
+     }
+     mtx_unlock(&sp->io_mtx);
+
+     sdebug(2, "restarted sn.cmd=0x%x lastcmd=0x%x", sp->sn.cmd, lastcmd);
+}
+
+void
+ism_recv(isc_session_t *sp, pduq_t *pq)
+{
+     bhs_t	*bhs;
+     int	statSN;
+
+     debug_called(8);
+
+     bhs = &pq->pdu.ipdu.bhs;
+     statSN = ntohl(bhs->OpcodeSpecificFields[1]);
+
+#ifdef notyet
+     if(sp->sn.expCmd != sn->cmd) {
+	  sdebug(1, "we lost something ... exp=0x%x cmd=0x%x",
+		 sn->expCmd, sn->cmd);
+     }
+#endif
+     sdebug(5, "opcode=0x%x itt=0x%x stat#0x%x maxcmd=0x%0x",
+	    bhs->opcode, ntohl(bhs->itt), statSN, sp->sn.maxCmd);
+
+     switch(bhs->opcode) {
+     case ISCSI_READ_DATA: {
+	  data_in_t 	*cmd = &pq->pdu.ipdu.data_in;
+
+	  if(cmd->S == 0)
+	       break;
+     }
+
+     default:
+	  if(statSN > (sp->sn.stat + 1)) {
+	       sdebug(1, "we lost some rec=0x%x exp=0x%x",
+		      statSN, sp->sn.stat);
+	       // XXX: must do some error recovery here.
+	  }
+	  sp->sn.stat = statSN;
+     }
+
+     switch(bhs->opcode) {
+     case ISCSI_LOGIN_RSP:
+     case ISCSI_TEXT_RSP:
+     case ISCSI_LOGOUT_RSP:
+	  i_nqueue_rsp(sp, pq);
+	  wakeup(&sp->rsp);
+	  sdebug(3, "wakeup rsp");
+	  break;
+
+     case ISCSI_NOP_IN:		_nop_in(sp, pq);	break;
+     case ISCSI_SCSI_RSP:	_scsi_rsp(sp, pq);	break;
+     case ISCSI_READ_DATA:	_read_data(sp, pq);	break;
+     case ISCSI_R2T:		_r2t(sp, pq);		break;
+     case ISCSI_REJECT:		_reject(sp, pq);	break;
+     case ISCSI_ASYNC:		_async(sp, pq);		break;
+
+     case ISCSI_TASK_RSP:
+     default:
+	  sdebug(1, "opcode=0x%x itt=0x%x not implemented yet",
+		 bhs->opcode, ntohl(bhs->itt));
+	  break;
+     }
+}
+
+/*
+ | go through the out queues looking for work
+ | if either nothing to do, or window is closed
+ | return.
+ */
+static int
+proc_out(isc_session_t *sp)
+{
+     sn_t	*sn = &sp->sn;
+     pduq_t	*pq;
+     int	error, which;
+
+     debug_called(8);
+     error = 0;
+
+     while(sp->flags & ISC_LINK_UP) {
+	  pdu_t *pp;
+	  bhs_t	*bhs;
+	  /*
+	   | check if there is outstanding work in:
+	   | 1- the Immediate queue
+	   | 2- the R2T queue
+	   | 3- the cmd queue, only if the command window allows it.
+	   */
+	  which = BIT(0) | BIT(1);
+	  if(SNA_GT(sn->cmd, sn->maxCmd) == 0) // if(sn->maxCmd - sn->smc + 1) > 0
+	       which |= BIT(2);
+
+	  sdebug(4, "which=%d sn->maxCmd=%d sn->cmd=%d", which, sn->maxCmd, sn->cmd);
+
+	  if((pq = i_dqueue_snd(sp, which)) == NULL)
+	       break;
+	  sdebug(4, "pq=%p", pq);
+
+	  pp = &pq->pdu;
+	  bhs = &pp->ipdu.bhs;
+	  switch(bhs->opcode) {
+	  case ISCSI_SCSI_CMD:
+	       sn->itt++;
+	       bhs->itt = htonl(sn->itt);
+
+	  case ISCSI_LOGIN_CMD:
+	  case ISCSI_TEXT_CMD:
+	  case ISCSI_LOGOUT_CMD:
+	  case ISCSI_SNACK:
+	  case ISCSI_NOP_OUT:
+	  case ISCSI_TASK_CMD:
+	       bhs->CmdSN = htonl(sn->cmd);
+	       if(bhs->I == 0)
+		    sn->cmd++;
+
+	  case ISCSI_WRITE_DATA:
+	       bhs->ExpStSN = htonl(sn->stat + 1);
+	       break;
+
+	  default:
+	       // XXX: can this happen?
+	       xdebug("bad opcode=0x%x sn(cmd=0x%x expCmd=0x%x maxCmd=0x%x expStat=0x%x itt=0x%x)",
+		      bhs->opcode,
+		      sn->cmd, sn->expCmd, sn->maxCmd, sn->expStat, sn->itt);
+	       // XXX: and now?
+	  }
+
+	  sdebug(4, "opcode=0x%x sn(cmd=0x%x expCmd=0x%x maxCmd=0x%x expStat=0x%x itt=0x%x)",
+		bhs->opcode,
+		sn->cmd, sn->expCmd, sn->maxCmd, sn->expStat, sn->itt);
+
+	  if(bhs->opcode != ISCSI_NOP_OUT)
+	       /*
+		| enqued till ack is received
+		| note: sosend(...) does not mean the packet left
+		| the host so that freeing resources has to wait
+	        */
+	       i_nqueue_hld(sp, pq);
+
+	  error = isc_sendPDU(sp, pq);
+	  if(bhs->opcode == ISCSI_NOP_OUT)
+	       pdu_free(sp->isc, pq);
+	  if(error) {
+	       xdebug("error=%d opcode=0x%x ccb=%p itt=%x",
+		      error, bhs->opcode, pq->ccb, ntohl(bhs->itt));
+	       i_remove_hld(sp, pq);
+	       switch(error) {
+	       case EPIPE:
+		    sp->flags &= ~ISC_LINK_UP;
+
+	       case EAGAIN:
+		    xdebug("requed");
+		    i_rqueue_pdu(sp, pq);
+		    break;
+
+	       default:
+		    if(pq->ccb) {
+			 xdebug("back to cam");
+			 pq->ccb->ccb_h.status |= CAM_REQUEUE_REQ; // some better error?
+			 XPT_DONE(sp, pq->ccb);
+			 pdu_free(sp->isc, pq);
+		    }
+		    else
+			 xdebug("we lost it!");
+	       }
+	  }
+     }
+     return error;
+}
+
+/*
+ | survives link breakdowns.
+ */
+static void
+ism_out(void *vp)
+{
+     isc_session_t 	*sp = (isc_session_t *)vp;
+     int		error;
+
+     debug_called(8);
+
+     sp->flags |= ISC_SM_RUNNING;
+     sdebug(3, "started sp->flags=%x", sp->flags);
+     do {
+	  if((sp->flags & ISC_HOLD) == 0) {
+	       error = proc_out(sp);
+	       if(error) {
+		    sdebug(3, "error=%d", error);
+	       }
+	  }
+	  mtx_lock(&sp->io_mtx);
+	  if((sp->flags & ISC_LINK_UP) == 0) {
+	       sdebug(3, "ISC_LINK_UP==0, sp->flags=%x ", sp->flags);
+	       if(sp->soc != NULL)
+		    sdebug(3, "so_state=%x", sp->soc->so_state);
+	       wakeup(&sp->soc);
+	  }
+
+	  if(!(sp->flags & ISC_OQNOTEMPTY)) {
+	       sp->flags |= ISC_OWAITING;
+	       if(msleep(&sp->flags, &sp->io_mtx, PRIBIO, "isc_proc", hz*30) == EWOULDBLOCK) {
+		    if(sp->flags & ISC_CON_RUNNING)
+			 _nop_out(sp);
+	       }
+	       sp->flags &= ~ISC_OWAITING;
+	  }
+	  sp->flags &= ~ISC_OQNOTEMPTY;
+	  mtx_unlock(&sp->io_mtx);
+     } while(sp->flags & ISC_SM_RUN);
+
+     sp->flags &= ~ISC_SM_RUNNING;
+     sdebug(3, "dropped ISC_SM_RUNNING");
+
+     wakeup(&sp->soc);
+     wakeup(sp); // XXX: do we need this one?
+
+#if __FreeBSD_version >= 700000
+     destroy_dev(sp->dev);
+#endif
+
+     debug(3, "terminated sp=%p sp->sid=%d", sp, sp->sid);
+
+#if __FreeBSD_version >= 800000
+     kproc_exit(0);
+#else
+     kthread_exit(0);
+#endif
+}
+
+#if 0
+static int
+isc_dump_options(SYSCTL_HANDLER_ARGS)
+{
+     int error;
+     isc_session_t *sp;
+     char	buf[1024], *bp;
+
+     sp = (isc_session_t *)arg1;
+     bp = buf;
+     sprintf(bp, "targetname='%s'", sp->opt.targetName);
+     bp += strlen(bp);
+     sprintf(bp, " targetname='%s'", sp->opt.targetAddress);
+     error = SYSCTL_OUT(req, buf, strlen(buf));
+     return error;
+}
+#endif
+
+static int
+isc_dump_stats(SYSCTL_HANDLER_ARGS)
+{
+     isc_session_t	*sp;
+     struct isc_softc	*sc;
+     char	buf[1024], *bp;
+     int 	error, n;
+
+     sp = (isc_session_t *)arg1;
+     sc = sp->isc;
+
+     bp = buf;
+     n = sizeof(buf);
+     snprintf(bp, n, "recv=%d sent=%d", sp->stats.nrecv, sp->stats.nsent);
+     bp += strlen(bp);
+     n -= strlen(bp);
+     snprintf(bp, n, " flags=0x%08x pdus-alloc=%d pdus-max=%d", 
+		  sp->flags, sc->npdu_alloc, sc->npdu_max);
+     bp += strlen(bp);
+     n -= strlen(bp);
+     snprintf(bp, n, " cws=%d cmd=%x exp=%x max=%x stat=%x itt=%x",
+		  sp->cws, sp->sn.cmd, sp->sn.expCmd, sp->sn.maxCmd, sp->sn.stat, sp->sn.itt);
+     error = SYSCTL_OUT(req, buf, strlen(buf));
+     return error;
+}
+
+static int
+isc_sysctl_targetName(SYSCTL_HANDLER_ARGS)
+{
+     char	buf[128], **cp;
+     int 	error;
+
+     cp = (char **)arg1;
+     snprintf(buf, sizeof(buf), "%s", *cp);
+     error = SYSCTL_OUT(req, buf, strlen(buf));
+     return error;
+}
+     
+static int
+isc_sysctl_targetAddress(SYSCTL_HANDLER_ARGS)
+{
+     char	buf[128], **cp;
+     int 	error;
+
+     cp = (char **)arg1;
+     snprintf(buf, sizeof(buf), "%s", *cp);
+     error = SYSCTL_OUT(req, buf, strlen(buf));
+     return error;
+}
+     
+static void
+isc_add_sysctls(isc_session_t *sp)
+{
+     debug_called(8);
+     sdebug(6, "sid=%d %s", sp->sid, devtoname(sp->dev));
+
+     sysctl_ctx_init(&sp->clist);
+     sp->oid = SYSCTL_ADD_NODE(&sp->clist,
+			       SYSCTL_CHILDREN(sp->isc->oid),
+			       OID_AUTO,
+			       devtoname(sp->dev) + 5, // iscsi0
+			       CTLFLAG_RD,
+			       0,
+			       "initiator");
+     SYSCTL_ADD_PROC(&sp->clist,
+		     SYSCTL_CHILDREN(sp->oid),
+		     OID_AUTO,
+		     "targetname",
+		     CTLTYPE_STRING | CTLFLAG_RD,
+		     (void *)&sp->opt.targetName, 0,
+		     isc_sysctl_targetName, "A", "target name");
+
+     SYSCTL_ADD_PROC(&sp->clist,
+		     SYSCTL_CHILDREN(sp->oid),
+		     OID_AUTO,
+		     "targeaddress",
+		     CTLTYPE_STRING | CTLFLAG_RD,
+		     (void *)&sp->opt.targetAddress, 0,
+		     isc_sysctl_targetAddress, "A", "target address");
+
+     SYSCTL_ADD_PROC(&sp->clist,
+		     SYSCTL_CHILDREN(sp->oid),
+		     OID_AUTO,
+		     "stats",
+		     CTLTYPE_STRING | CTLFLAG_RD,
+		     (void *)sp, 0,
+		     isc_dump_stats, "A", "statistics");
+
+     SYSCTL_ADD_INT(&sp->clist,
+		     SYSCTL_CHILDREN(sp->oid),
+		     OID_AUTO,
+		     "douio",
+		     CTLFLAG_RW,
+		     &sp->douio, 0, "enable uio on read");
+}
+
+void
+ism_stop(isc_session_t *sp)
+{
+     struct isc_softc *sc = sp->isc;
+     int	n;
+
+     debug_called(8);
+     sdebug(2, "terminating");
+     /*
+      | first stop the receiver
+      */
+     isc_stop_receiver(sp);
+     /*
+      | now stop the xmitter
+      */
+     n = 5;
+     sp->flags &= ~ISC_SM_RUN;
+     while(n-- && (sp->flags & ISC_SM_RUNNING)) {
+	  sdebug(2, "n=%d", n);
+	  wakeup(&sp->flags);
+	  tsleep(sp, PRIBIO, "-", 5*hz);
+     }
+     sdebug(2, "final n=%d", n);
+     sp->flags &= ~ISC_FFPHASE;
+     
+     iscsi_cleanup(sp);
+
+     (void)i_pdu_flush(sp);
+
+     ic_destroy(sp);
+
+     sx_xlock(&sc->unit_sx);
+     free_unr(sc->unit, sp->sid);
+     sx_xunlock(&sc->unit_sx);
+
+     mtx_lock(&sc->isc_mtx);
+     TAILQ_REMOVE(&sc->isc_sess, sp, sp_link);
+     sc->nsess--;
+     mtx_unlock(&sc->isc_mtx);
+
+#if __FreeBSD_version < 700000
+     destroy_dev(sp->dev);
+#endif
+
+     mtx_destroy(&sp->rsp_mtx);
+     mtx_destroy(&sp->rsv_mtx);
+     mtx_destroy(&sp->hld_mtx);
+     mtx_destroy(&sp->snd_mtx);
+     mtx_destroy(&sp->io_mtx);
+
+     i_freeopt(&sp->opt);
+
+     if(sysctl_ctx_free(&sp->clist))
+	  xdebug("sysctl_ctx_free failed");
+
+     free(sp, M_ISCSI);
+}
+
+int
+ism_start(isc_session_t *sp)
+{
+     debug_called(8);
+    /*
+     | now is a good time to do some initialization
+     */
+     TAILQ_INIT(&sp->rsp);
+     TAILQ_INIT(&sp->rsv);
+     TAILQ_INIT(&sp->csnd);
+     TAILQ_INIT(&sp->isnd);
+     TAILQ_INIT(&sp->wsnd);
+     TAILQ_INIT(&sp->hld);
+
+     mtx_init(&sp->rsv_mtx, "iscsi-rsv", NULL, MTX_DEF);
+     mtx_init(&sp->rsp_mtx, "iscsi-rsp", NULL, MTX_DEF);
+     mtx_init(&sp->snd_mtx, "iscsi-snd", NULL, MTX_DEF);
+     mtx_init(&sp->hld_mtx, "iscsi-hld", NULL, MTX_DEF);
+     mtx_init(&sp->io_mtx, "iscsi-io", NULL, MTX_DEF);
+
+     isc_add_sysctls(sp);
+
+     sp->flags |= ISC_SM_RUN;
+
+     debug(4, "starting ism_proc: sp->sid=%d", sp->sid);
+
+#if __FreeBSD_version >= 800000
+     return kproc_create(ism_out, sp, &sp->stp, 0, 0, "isc_out %d", sp->sid);
+#else
+     return kthread_create(ism_out, sp, &sp->stp, 0, 0, "isc_out %d", sp->sid);
+#endif
+}


Property changes on: trunk/sys/dev/iscsi_initiator/isc_sm.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sys/dev/iscsi_initiator/isc_soc.c
===================================================================
--- trunk/sys/dev/iscsi_initiator/isc_soc.c	                        (rev 0)
+++ trunk/sys/dev/iscsi_initiator/isc_soc.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -0,0 +1,703 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2005-2010 Daniel Braniss <danny at cs.huji.ac.il>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+/*
+ | $Id: isc_soc.c 998 2009-12-20 10:32:45Z danny $
+ */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/sys/dev/iscsi_initiator/isc_soc.c 254842 2013-08-25 10:57:09Z andre $");
+
+#include "opt_iscsi_initiator.h"
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/conf.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/ctype.h>
+#include <sys/errno.h>
+#include <sys/sysctl.h>
+#include <sys/file.h>
+#include <sys/uio.h>
+#include <sys/socketvar.h>
+#include <sys/socket.h>
+#include <sys/protosw.h>
+#include <sys/proc.h>
+#include <sys/ioccom.h>
+#include <sys/queue.h>
+#include <sys/kthread.h>
+#include <sys/syslog.h>
+#include <sys/mbuf.h>
+#include <sys/user.h>
+
+#include <cam/cam.h>
+#include <cam/cam_ccb.h>
+
+#include <dev/iscsi_initiator/iscsi.h>
+#include <dev/iscsi_initiator/iscsivar.h>
+
+#ifndef NO_USE_MBUF
+#define USE_MBUF
+#endif
+
+#ifdef USE_MBUF
+static int ou_refcnt = 0;
+/*
+ | function for freeing external storage for mbuf
+ */
+static int
+ext_free(struct mbuf *m, void *a, void *b)
+{
+     pduq_t *pq = b;
+
+     if(pq->buf != NULL) {
+	  debug(3, "ou_refcnt=%d a=%p b=%p", ou_refcnt, a, pq->buf);
+	  free(pq->buf, M_ISCSIBUF);
+	  pq->buf = NULL;
+     }
+     return (EXT_FREE_OK);
+}
+
+int
+isc_sendPDU(isc_session_t *sp, pduq_t *pq)
+{
+     struct mbuf *mh, **mp;
+     pdu_t	*pp = &pq->pdu;
+     int	len, error;
+
+     debug_called(8);
+     /* 
+      | mbuf for the iSCSI header
+      */
+     MGETHDR(mh, M_WAITOK, MT_DATA);
+     mh->m_pkthdr.rcvif = NULL;
+     mh->m_next = NULL;
+     mh->m_len = sizeof(union ipdu_u);
+
+     if(ISOK2DIG(sp->hdrDigest, pp)) {
+	  pp->hdr_dig = sp->hdrDigest(&pp->ipdu, sizeof(union ipdu_u), 0);
+	  mh->m_len += sizeof(pp->hdr_dig);
+	  if(pp->ahs_len) {
+	       debug(2, "ahs_len=%d", pp->ahs_len);
+	       pp->hdr_dig = sp->hdrDigest(&pp->ahs_addr, pp->ahs_len, pp->hdr_dig);
+	  }
+	  debug(3, "pp->hdr_dig=%04x", htonl(pp->hdr_dig));
+     }
+     if(pp->ahs_len) {
+          /* 
+	   | Add any AHS to the iSCSI hdr mbuf
+	   */
+	  if((mh->m_len + pp->ahs_len) < MHLEN) {
+	       MH_ALIGN(mh, mh->m_len + pp->ahs_len);
+	       bcopy(&pp->ipdu, mh->m_data, mh->m_len);
+	       bcopy(pp->ahs_addr, mh->m_data + mh->m_len, pp->ahs_len);
+	       mh->m_len += pp->ahs_len;
+	  }
+	  else
+	       panic("len AHS=%d too big, not impleneted yet", pp->ahs_len);
+     }
+     else {
+	  MH_ALIGN(mh, mh->m_len);
+	  bcopy(&pp->ipdu, mh->m_data, mh->m_len);
+     }
+     mh->m_pkthdr.len = mh->m_len;
+     mp = &mh->m_next;
+     if(pp->ds_len && pq->pdu.ds_addr) {
+          struct mbuf *md;
+          int	off = 0;
+
+          len = pp->ds_len;
+          while(len > 0) {
+	       int l;
+
+	       MGET(md, M_WAITOK, MT_DATA);
+	       md->m_ext.ref_cnt = &ou_refcnt;
+	       l = min(MCLBYTES, len);
+	       debug(4, "setting ext_free(arg=%p len/l=%d/%d)", pq->buf, len, l);
+	       MEXTADD(md, pp->ds_addr + off, l, ext_free, 
+#if __FreeBSD_version >= 800000
+		       pp->ds_addr + off,
+#endif
+		       pq, 0, EXT_EXTREF);
+	       md->m_len = l;
+	       md->m_next = NULL;
+	       mh->m_pkthdr.len += l;
+	       *mp = md;
+	       mp = &md->m_next;
+	       len -= l;
+	       off += l;
+          }
+	  if(((pp->ds_len & 03) != 0) || ISOK2DIG(sp->dataDigest, pp)) {
+	       MGET(md, M_WAITOK, MT_DATA);
+	       if(pp->ds_len & 03)
+		    len = 4 - (pp->ds_len & 03);
+	       else
+		    len = 0;
+	       md->m_len = len;
+	       if(ISOK2DIG(sp->dataDigest, pp))
+		    md->m_len += sizeof(pp->ds_dig);
+	       M_ALIGN(md, md->m_len);
+	       if(ISOK2DIG(sp->dataDigest, pp)) {
+		    pp->ds_dig = sp->dataDigest(pp->ds_addr, pp->ds_len, 0);
+		    if(len) {
+			 bzero(md->m_data, len); // RFC says SHOULD be 0
+			 pp->ds_dig = sp->dataDigest(md->m_data, len, pp->ds_dig);
+		    }
+		    bcopy(&pp->ds_dig, md->m_data+len, sizeof(pp->ds_dig));
+	       }
+	       md->m_next = NULL;
+	       mh->m_pkthdr.len += md->m_len;
+	       *mp = md;
+	  }
+     }
+     if((error = sosend(sp->soc, NULL, NULL, mh, 0, 0, sp->td)) != 0) {
+	  sdebug(2, "error=%d", error);
+	  return error;
+     }
+     sp->stats.nsent++;
+     getbintime(&sp->stats.t_sent);
+     return 0;
+}
+#else /* NO_USE_MBUF */
+int
+isc_sendPDU(isc_session_t *sp, pduq_t *pq)
+{
+     struct uio *uio = &pq->uio;
+     struct iovec *iv;
+     pdu_t	*pp = &pq->pdu;
+     int	len, error;
+
+     debug_called(8);
+
+     bzero(uio, sizeof(struct uio));
+     uio->uio_rw = UIO_WRITE;
+     uio->uio_segflg = UIO_SYSSPACE;
+     uio->uio_td = sp->td;
+     uio->uio_iov = iv = pq->iov;
+
+     iv->iov_base = &pp->ipdu;
+     iv->iov_len = sizeof(union ipdu_u);
+     uio->uio_resid = iv->iov_len;
+     iv++;
+     if(ISOK2DIG(sp->hdrDigest, pp))
+	  pq->pdu.hdr_dig = sp->hdrDigest(&pp->ipdu, sizeof(union ipdu_u), 0);
+     if(pp->ahs_len) {
+	  iv->iov_base = pp->ahs_addr;
+	  iv->iov_len = pp->ahs_len;
+	  uio->uio_resid += iv->iov_len;
+	  iv++;
+	  if(ISOK2DIG(sp->hdrDigest, pp))
+	       pp->hdr_dig = sp->hdrDigest(&pp->ahs_addr, pp->ahs_len, pp->hdr_dig);
+     }
+     if(ISOK2DIG(sp->hdrDigest, pp)) {
+	  debug(3, "hdr_dig=%04x", htonl(pp->hdr_dig));
+	  iv->iov_base = &pp->hdr_dig;
+	  iv->iov_len = sizeof(int);
+	  uio->uio_resid += iv->iov_len ;
+	  iv++;
+     }
+     if(pq->pdu.ds_addr &&  pp->ds_len) {
+	  iv->iov_base = pp->ds_addr;
+	  iv->iov_len = pp->ds_len;
+	  while(iv->iov_len & 03) // the specs say it must be int alligned
+	       iv->iov_len++;
+	  uio->uio_resid += iv->iov_len ;
+	  iv++;
+	  if(ISOK2DIG(sp->dataDigest, pp)) {
+	       pp->ds_dig = sp->dataDigest(pp->ds, pp->ds_len, 0);
+	       iv->iov_base = &pp->ds_dig;
+	       iv->iov_len = sizeof(pp->ds_dig);
+	       uio->uio_resid += iv->iov_len ;
+	       iv++;
+	  }
+     }
+     uio->uio_iovcnt = iv - pq->iov;
+     sdebug(4, "pq->len=%d uio->uio_resid=%d  uio->uio_iovcnt=%d", pq->len,
+	    uio->uio_resid,
+	    uio->uio_iovcnt);
+
+     sdebug(4, "opcode=%x iovcnt=%d uio_resid=%d itt=%x",
+	    pp->ipdu.bhs.opcode, uio->uio_iovcnt, uio->uio_resid,
+	    ntohl(pp->ipdu.bhs.itt));
+     sdebug(5, "sp=%p sp->soc=%p uio=%p sp->td=%p",
+	    sp, sp->soc, uio, sp->td);
+     do {
+	  len = uio->uio_resid;
+	  error = sosend(sp->soc, NULL, uio, 0, 0, 0, sp->td);
+	  if(uio->uio_resid == 0 || error || len == uio->uio_resid) {
+	       if(uio->uio_resid) {
+		    sdebug(2, "uio->uio_resid=%d uio->uio_iovcnt=%d error=%d len=%d",
+			   uio->uio_resid, uio->uio_iovcnt, error, len);
+		    if(error == 0)
+			 error = EAGAIN; // 35
+	       }
+	       break;
+	  }
+	  /*
+	   | XXX: untested code
+	   */
+	  sdebug(1, "uio->uio_resid=%d uio->uio_iovcnt=%d",
+		 uio->uio_resid, uio->uio_iovcnt);
+	  iv = uio->uio_iov;
+	  len -= uio->uio_resid;
+	  while(uio->uio_iovcnt > 0) {
+	       if(iv->iov_len > len) {
+		    caddr_t bp = (caddr_t)iv->iov_base;
+
+		    iv->iov_len -= len;
+		    iv->iov_base = (void *)&bp[len];
+		    break;
+	       }
+	       len -= iv->iov_len;
+	       uio->uio_iovcnt--;
+	       uio->uio_iov++;
+	       iv++;
+	  }
+     } while(uio->uio_resid);
+
+     if(error == 0) {
+	  sp->stats.nsent++;
+	  getbintime(&sp->stats.t_sent);
+     }
+
+     return error;
+}
+#endif /* USE_MBUF */
+
+/*
+ | wait till a PDU header is received
+ | from the socket.
+ */
+/*
+   The format of the BHS is:
+
+   Byte/     0       |       1       |       2       |       3       |
+      /              |               |               |               |
+     |0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|
+     +---------------+---------------+---------------+---------------+
+    0|.|I| Opcode    |F|  Opcode-specific fields                     |
+     +---------------+---------------+---------------+---------------+
+    4|TotalAHSLength | DataSegmentLength                             |
+     +---------------+---------------+---------------+---------------+
+    8| LUN or Opcode-specific fields                                 |
+     +                                                               +
+   12|                                                               |
+     +---------------+---------------+---------------+---------------+
+   16| Initiator Task Tag                                            |
+     +---------------+---------------+---------------+---------------+
+   20/ Opcode-specific fields                                        /
+    +/                                                               /
+     +---------------+---------------+---------------+---------------+
+   48
+ */
+static __inline int
+so_getbhs(isc_session_t *sp)
+{
+     bhs_t *bhs		= &sp->bhs;
+     struct uio		*uio = &sp->uio;
+     struct iovec	*iov = &sp->iov;
+     int		error, flags;
+
+     debug_called(8);
+
+     iov->iov_base	= bhs;
+     iov->iov_len	= sizeof(bhs_t);
+
+     uio->uio_iov	= iov;
+     uio->uio_iovcnt	= 1;
+     uio->uio_rw	= UIO_READ;
+     uio->uio_segflg	= UIO_SYSSPACE;
+     uio->uio_td	= curthread; // why ...
+     uio->uio_resid	= sizeof(bhs_t);
+
+     flags = MSG_WAITALL;
+     error = soreceive(sp->soc, NULL, uio, 0, 0, &flags);
+
+     if(error)
+	  debug(2, 
+#if __FreeBSD_version > 800000
+		"error=%d so_error=%d uio->uio_resid=%zd iov.iov_len=%zd",
+#else
+		"error=%d so_error=%d uio->uio_resid=%d iov.iov_len=%zd",
+#endif
+		error,
+		sp->soc->so_error, uio->uio_resid, iov->iov_len);
+     if(!error && (uio->uio_resid > 0)) {
+	  error = EPIPE; // was EAGAIN
+	  debug(2,
+#if __FreeBSD_version > 800000
+		"error=%d so_error=%d uio->uio_resid=%zd iov.iov_len=%zd so_state=%x",
+#else
+		"error=%d so_error=%d uio->uio_resid=%d iov.iov_len=%zd so_state=%x",
+#endif
+		error,
+		sp->soc->so_error, uio->uio_resid, iov->iov_len, sp->soc->so_state);
+     }
+     return error;
+}
+
+/*
+ | so_recv gets called when 
+ | an iSCSI header has been received.
+ | Note: the designers had no intentions 
+ |       in making programmer's life easy.
+ */
+static int
+so_recv(isc_session_t *sp, pduq_t *pq)
+{
+     sn_t		*sn = &sp->sn;
+     struct uio		*uio = &pq->uio;
+     pdu_t		*pp = &pq->pdu;
+     bhs_t		*bhs = &pp->ipdu.bhs;
+     struct iovec	*iov = pq->iov;
+     int		error;
+     u_int		len;
+     u_int		max, exp;
+     int		flags = MSG_WAITALL;
+
+     debug_called(8);
+     /*
+      | now calculate how much data should be in the buffer
+      */
+     uio->uio_iov	= iov;
+     uio->uio_iovcnt	= 0;
+     len = 0;
+     if(bhs->AHSLength) {
+	  debug(2, "bhs->AHSLength=%d", bhs->AHSLength);
+	  pp->ahs_len = bhs->AHSLength * 4;
+	  len += pp->ahs_len;
+	  pp->ahs_addr = malloc(pp->ahs_len, M_TEMP, M_WAITOK); // XXX: could get stuck here
+	  iov->iov_base = pp->ahs_addr;
+	  iov->iov_len = pp->ahs_len;
+	  uio->uio_iovcnt++;
+	  iov++;
+     }
+     if(ISOK2DIG(sp->hdrDigest, pp)) {
+	  len += sizeof(pp->hdr_dig);
+	  iov->iov_base = &pp->hdr_dig;
+	  iov->iov_len = sizeof(pp->hdr_dig);
+	  uio->uio_iovcnt++;
+     }
+     if(len) {
+	  uio->uio_rw		= UIO_READ;
+	  uio->uio_segflg	= UIO_SYSSPACE;
+	  uio->uio_resid	= len;
+	  uio->uio_td		= sp->td; // why ...
+	  error = soreceive(sp->soc, NULL, uio, NULL, NULL, &flags);
+	  //if(error == EAGAIN)
+	  // XXX: this needs work! it hangs iscontrol
+	  if(error || uio->uio_resid) {
+	       debug(2, 
+#if __FreeBSD_version > 800000
+		     "len=%d error=%d uio->uio_resid=%zd",
+#else
+		     "len=%d error=%d uio->uio_resid=%d",
+#endif
+		     len, error, uio->uio_resid);
+	       goto out;
+	  }
+	  if(ISOK2DIG(sp->hdrDigest, pp)) {
+	       bhs_t	*bhs;
+	       u_int	digest;
+	       
+	       bhs = (bhs_t *)&pp->ipdu;
+	       digest = sp->hdrDigest(bhs, sizeof(bhs_t), 0);
+	       if(pp->ahs_len)
+		    digest = sp->hdrDigest(pp->ahs_addr, pp->ahs_len, digest);
+	       if(pp->hdr_dig != digest) {
+		    debug(2, "bad header digest: received=%x calculated=%x", pp->hdr_dig, digest);
+		    // XXX: now what?
+		    error = EIO;
+		    goto out;
+	       }
+	  }
+	  if(pp->ahs_len) {
+	       debug(2, "ahs len=%x type=%x spec=%x",
+		     pp->ahs_addr->len, pp->ahs_addr->type, pp->ahs_addr->spec);
+	       // XXX: till I figure out what to do with this
+	       free(pp->ahs_addr, M_TEMP);
+	  }
+	  pq->len += len; // XXX: who needs this?
+	  bzero(uio, sizeof(struct uio));
+	  len = 0;
+     }
+
+     if(bhs->DSLength) {
+	  len = bhs->DSLength;
+#if BYTE_ORDER == LITTLE_ENDIAN
+	  len = ((len & 0x00ff0000) >> 16)
+	       | (len & 0x0000ff00)
+	       | ((len & 0x000000ff) << 16);
+#endif
+	  pp->ds_len = len;
+	  if((sp->opt.maxRecvDataSegmentLength > 0) && (len > sp->opt.maxRecvDataSegmentLength)) {
+	       xdebug("impossible PDU length(%d) opt.maxRecvDataSegmentLength=%d",
+		      len, sp->opt.maxRecvDataSegmentLength);
+	       log(LOG_ERR,
+		   "so_recv: impossible PDU length(%d) from iSCSI %s/%s\n",
+		   len, sp->opt.targetAddress, sp->opt.targetName);
+	       /*
+		| XXX: this will really screwup the stream.
+		| should clear up the buffer till a valid header
+		| is found, or just close connection ...
+		| should read the RFC.
+	        */
+	       error = E2BIG;
+	       goto out;
+	  }
+	  while(len & 03)
+	       len++;
+	  if(ISOK2DIG(sp->dataDigest, pp))
+	       len += 4;
+	  uio->uio_resid = len;
+	  uio->uio_td = sp->td; // why ...
+	  pq->len += len; // XXX: do we need this?
+	  error = soreceive(sp->soc, NULL, uio, &pq->mp, NULL, &flags);
+	  //if(error == EAGAIN)
+	  // XXX: this needs work! it hangs iscontrol
+	  if(error || uio->uio_resid)
+	       goto out;
+          if(ISOK2DIG(sp->dataDigest, pp)) {
+	       struct mbuf *m;
+	       u_int    digest, ds_len, cnt;
+
+	       // get the received digest
+	       m_copydata(pq->mp,
+			  len - sizeof(pp->ds_dig),
+			  sizeof(pp->ds_dig),
+			  (caddr_t)&pp->ds_dig);
+	       // calculate all mbufs 
+	       digest = 0;
+	       ds_len = len - sizeof(pp->ds_dig);
+	       for(m = pq->mp; m != NULL; m = m->m_next) {
+		    cnt = MIN(ds_len, m->m_len);
+		    digest = sp->dataDigest(mtod(m, char *), cnt, digest);
+		    ds_len -= cnt;
+		    if(ds_len == 0)
+			 break;
+	       }
+	       if(digest != pp->ds_dig) {
+		    sdebug(1, "bad data digest: received=%x calculated=%x", pp->ds_dig, digest);
+		    error = EIO; // XXX: find a better error
+		    goto out;
+	       }
+	       KASSERT(ds_len == 0, ("ds_len not zero"));
+	  }
+     }
+     sdebug(6, "len=%d] opcode=0x%x ahs_len=0x%x ds_len=0x%x",
+	    pq->len, bhs->opcode, pp->ahs_len, pp->ds_len);
+
+     max = ntohl(bhs->MaxCmdSN);
+     exp = ntohl(bhs->ExpStSN);
+     if(max < exp - 1 &&
+	max > exp - _MAXINCR) {
+	  sdebug(2,  "bad cmd window size");
+	  error = EIO; // XXX: for now;
+	  goto out; // error
+     }
+     if(SNA_GT(max, sn->maxCmd))
+	  sn->maxCmd = max;
+     if(SNA_GT(exp, sn->expCmd))
+	  sn->expCmd = exp;
+     /*
+      | remove from the holding queue packets
+      | that have been acked and don't need
+      | further processing.
+      */
+     i_acked_hld(sp, NULL);
+
+     sp->cws = sn->maxCmd - sn->expCmd + 1;
+
+     return 0;
+
+ out:
+     // XXX: need some work here
+     if(pp->ahs_len) {
+	  // XXX: till I figure out what to do with this
+	  free(pp->ahs_addr, M_TEMP);
+     }
+     xdebug("have a problem, error=%d", error);
+     pdu_free(sp->isc, pq);
+     if(!error && uio->uio_resid > 0)
+	  error = EPIPE;
+     return error;
+}
+
+/*
+ | wait for something to arrive.
+ | and if the pdu is without errors, process it.
+ */
+static int
+so_input(isc_session_t *sp)
+{
+     pduq_t		*pq;
+     int		error;
+
+     debug_called(8);
+     /*
+      | first read in the iSCSI header
+      */
+     error = so_getbhs(sp);
+     if(error == 0) {
+	  /*
+	   | now read the rest.
+	   */
+	  pq = pdu_alloc(sp->isc, M_NOWAIT); 
+	  if(pq == NULL) { // XXX: might cause a deadlock ...
+	       debug(2, "out of pdus, wait");
+	       pq = pdu_alloc(sp->isc, M_WAITOK);  // OK to WAIT
+	  }
+	  pq->pdu.ipdu.bhs = sp->bhs;
+	  pq->len = sizeof(bhs_t);	// so far only the header was read
+	  error = so_recv(sp, pq);
+	  if(error != 0) {
+	       error += 0x800; // XXX: just to see the error.
+	       // terminal error
+	       // XXX: close connection and exit
+	  }
+	  else {
+	       sp->stats.nrecv++;
+	       getbintime(&sp->stats.t_recv);
+	       ism_recv(sp, pq);
+	  }
+     }
+     return error;
+}
+
+/*
+ | one per active (connected) session.
+ | this thread is responsible for reading
+ | in packets from the target.
+ */
+static void
+isc_in(void *vp)
+{
+     isc_session_t	*sp = (isc_session_t *)vp;
+     struct socket	*so = sp->soc;
+     int		error;
+
+     debug_called(8);
+
+     sp->flags |= ISC_CON_RUNNING;
+     error = 0;
+     while((sp->flags & (ISC_CON_RUN | ISC_LINK_UP)) == (ISC_CON_RUN | ISC_LINK_UP)) {
+	  // XXX: hunting ...
+	  if(sp->soc == NULL || !(so->so_state & SS_ISCONNECTED)) {
+	       debug(2, "sp->soc=%p", sp->soc);
+	       break;
+	  }
+	  error = so_input(sp);
+	  if(error == 0) {
+	       mtx_lock(&sp->io_mtx);
+	       if(sp->flags & ISC_OWAITING) {
+		    wakeup(&sp->flags);
+	       }
+	       mtx_unlock(&sp->io_mtx);
+	  } else if(error == EPIPE) {
+	       break;
+	  }
+	  else if(error == EAGAIN) {
+	       if(so->so_state & SS_ISCONNECTED) 
+		    // there seems to be a problem in 6.0 ...
+		    tsleep(sp, PRIBIO, "isc_soc", 2*hz);
+	  }
+     }
+     sdebug(2, "terminated, flags=%x so_count=%d so_state=%x error=%d proc=%p",
+	    sp->flags, so->so_count, so->so_state, error, sp->proc);
+     if((sp->proc != NULL) && sp->signal) {
+	  PROC_LOCK(sp->proc);
+	  kern_psignal(sp->proc, sp->signal);
+	  PROC_UNLOCK(sp->proc);
+	  sp->flags |= ISC_SIGNALED;
+	  sdebug(2, "pid=%d signaled(%d)", sp->proc->p_pid, sp->signal);
+     }
+     else {
+	  // we have to do something ourselves
+	  // like closing this session ...
+     }
+     /*
+      | we've been terminated
+      */
+     // do we need this mutex ...?
+     mtx_lock(&sp->io_mtx);
+     sp->flags &= ~(ISC_CON_RUNNING | ISC_LINK_UP);
+     wakeup(&sp->soc);
+     mtx_unlock(&sp->io_mtx);
+
+     sdebug(2, "dropped ISC_CON_RUNNING");
+#if __FreeBSD_version >= 800000
+     kproc_exit(0);
+#else
+     kthread_exit(0);
+#endif
+}
+
+void
+isc_stop_receiver(isc_session_t *sp)
+{
+     int	n;
+
+     debug_called(8);
+     sdebug(3, "sp=%p sp->soc=%p", sp, sp? sp->soc: 0);
+     mtx_lock(&sp->io_mtx);
+     sp->flags &= ~ISC_LINK_UP;
+     msleep(&sp->soc, &sp->io_mtx, PRIBIO|PDROP, "isc_stpc", 5*hz);
+
+     soshutdown(sp->soc, SHUT_RD);
+
+     mtx_lock(&sp->io_mtx);
+     sdebug(3, "soshutdown");
+     sp->flags &= ~ISC_CON_RUN;
+     n = 2;
+     while(n-- && (sp->flags & ISC_CON_RUNNING)) {
+	  sdebug(3, "waiting n=%d... flags=%x", n, sp->flags);
+	  msleep(&sp->soc, &sp->io_mtx, PRIBIO, "isc_stpc", 5*hz);
+     }
+     mtx_unlock(&sp->io_mtx);
+
+     if(sp->fp != NULL)
+	  fdrop(sp->fp, sp->td);
+     fputsock(sp->soc);
+     sp->soc = NULL;
+     sp->fp = NULL;
+
+     sdebug(3, "done");
+}
+
+void
+isc_start_receiver(isc_session_t *sp)
+{
+     debug_called(8);
+
+     sp->flags |= ISC_CON_RUN | ISC_LINK_UP;
+#if __FreeBSD_version >= 800000
+     kproc_create
+#else
+     kthread_create
+#endif
+	  (isc_in, sp, &sp->soc_proc, 0, 0, "isc_in %d", sp->sid);
+}


Property changes on: trunk/sys/dev/iscsi_initiator/isc_soc.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sys/dev/iscsi_initiator/isc_subr.c
===================================================================
--- trunk/sys/dev/iscsi_initiator/isc_subr.c	                        (rev 0)
+++ trunk/sys/dev/iscsi_initiator/isc_subr.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -0,0 +1,270 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2005-2011 Daniel Braniss <danny at cs.huji.ac.il>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+/*
+ | iSCSI
+ | $Id: isc_subr.c 560 2009-05-07 07:37:49Z danny $
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/sys/dev/iscsi_initiator/isc_subr.c 254657 2013-08-22 14:02:34Z trasz $");
+
+#include "opt_iscsi_initiator.h"
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/conf.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/ctype.h>
+#include <sys/errno.h>
+#include <sys/sysctl.h>
+#include <sys/file.h>
+#include <sys/uio.h>
+#include <sys/socketvar.h>
+#include <sys/socket.h>
+#include <sys/protosw.h>
+#include <sys/proc.h>
+#include <sys/ioccom.h>
+#include <sys/queue.h>
+#include <sys/kthread.h>
+#include <sys/syslog.h>
+#include <sys/mbuf.h>
+#include <sys/libkern.h>
+
+#include <dev/iscsi_initiator/iscsi.h>
+#include <dev/iscsi_initiator/iscsivar.h>
+
+static MALLOC_DEFINE(M_ISC, "iSC", "iSCSI driver options");
+
+static char *
+i_strdupin(char *s, size_t maxlen)
+{
+     size_t	len;
+     char	*p, *q;
+
+     p = malloc(maxlen, M_ISC, M_WAITOK);
+     if(copyinstr(s, p, maxlen, &len)) {
+	  free(p, M_ISC);
+	  return NULL;
+     }
+     q = malloc(len, M_ISC, M_WAITOK);
+     bcopy(p, q, len);
+     free(p, M_ISC);
+
+     return q;
+}
+#if __FreeBSD_version < 800000
+/*****************************************************************/
+/*                                                               */
+/* CRC LOOKUP TABLE                                              */
+/* ================                                              */
+/* The following CRC lookup table was generated automagically    */
+/* by the Rocksoft^tm Model CRC Algorithm Table Generation       */
+/* Program V1.0 using the following model parameters:            */
+/*                                                               */
+/*    Width   : 4 bytes.                                         */
+/*    Poly    : 0x1EDC6F41L                                      */
+/*    Reverse : TRUE.                                            */
+/*                                                               */
+/* For more information on the Rocksoft^tm Model CRC Algorithm,  */
+/* see the document titled "A Painless Guide to CRC Error        */
+/* Detection Algorithms" by Ross Williams                        */
+/* (ross at guest.adelaide.edu.au.). This document is likely to be  */
+/* in the FTP archive "ftp.adelaide.edu.au/pub/rocksoft".        */
+/*                                                               */
+/*****************************************************************/
+
+static uint32_t crc32Table[256] = {
+    0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L,
+    0xC79A971FL, 0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL,
+    0x8AD958CFL, 0x78B2DBCCL, 0x6BE22838L, 0x9989AB3BL,
+    0x4D43CFD0L, 0xBF284CD3L, 0xAC78BF27L, 0x5E133C24L,
+    0x105EC76FL, 0xE235446CL, 0xF165B798L, 0x030E349BL,
+    0xD7C45070L, 0x25AFD373L, 0x36FF2087L, 0xC494A384L,
+    0x9A879FA0L, 0x68EC1CA3L, 0x7BBCEF57L, 0x89D76C54L,
+    0x5D1D08BFL, 0xAF768BBCL, 0xBC267848L, 0x4E4DFB4BL,
+    0x20BD8EDEL, 0xD2D60DDDL, 0xC186FE29L, 0x33ED7D2AL,
+    0xE72719C1L, 0x154C9AC2L, 0x061C6936L, 0xF477EA35L,
+    0xAA64D611L, 0x580F5512L, 0x4B5FA6E6L, 0xB93425E5L,
+    0x6DFE410EL, 0x9F95C20DL, 0x8CC531F9L, 0x7EAEB2FAL,
+    0x30E349B1L, 0xC288CAB2L, 0xD1D83946L, 0x23B3BA45L,
+    0xF779DEAEL, 0x05125DADL, 0x1642AE59L, 0xE4292D5AL,
+    0xBA3A117EL, 0x4851927DL, 0x5B016189L, 0xA96AE28AL,
+    0x7DA08661L, 0x8FCB0562L, 0x9C9BF696L, 0x6EF07595L,
+    0x417B1DBCL, 0xB3109EBFL, 0xA0406D4BL, 0x522BEE48L,
+    0x86E18AA3L, 0x748A09A0L, 0x67DAFA54L, 0x95B17957L,
+    0xCBA24573L, 0x39C9C670L, 0x2A993584L, 0xD8F2B687L,
+    0x0C38D26CL, 0xFE53516FL, 0xED03A29BL, 0x1F682198L,
+    0x5125DAD3L, 0xA34E59D0L, 0xB01EAA24L, 0x42752927L,
+    0x96BF4DCCL, 0x64D4CECFL, 0x77843D3BL, 0x85EFBE38L,
+    0xDBFC821CL, 0x2997011FL, 0x3AC7F2EBL, 0xC8AC71E8L,
+    0x1C661503L, 0xEE0D9600L, 0xFD5D65F4L, 0x0F36E6F7L,
+    0x61C69362L, 0x93AD1061L, 0x80FDE395L, 0x72966096L,
+    0xA65C047DL, 0x5437877EL, 0x4767748AL, 0xB50CF789L,
+    0xEB1FCBADL, 0x197448AEL, 0x0A24BB5AL, 0xF84F3859L,
+    0x2C855CB2L, 0xDEEEDFB1L, 0xCDBE2C45L, 0x3FD5AF46L,
+    0x7198540DL, 0x83F3D70EL, 0x90A324FAL, 0x62C8A7F9L,
+    0xB602C312L, 0x44694011L, 0x5739B3E5L, 0xA55230E6L,
+    0xFB410CC2L, 0x092A8FC1L, 0x1A7A7C35L, 0xE811FF36L,
+    0x3CDB9BDDL, 0xCEB018DEL, 0xDDE0EB2AL, 0x2F8B6829L,
+    0x82F63B78L, 0x709DB87BL, 0x63CD4B8FL, 0x91A6C88CL,
+    0x456CAC67L, 0xB7072F64L, 0xA457DC90L, 0x563C5F93L,
+    0x082F63B7L, 0xFA44E0B4L, 0xE9141340L, 0x1B7F9043L,
+    0xCFB5F4A8L, 0x3DDE77ABL, 0x2E8E845FL, 0xDCE5075CL,
+    0x92A8FC17L, 0x60C37F14L, 0x73938CE0L, 0x81F80FE3L,
+    0x55326B08L, 0xA759E80BL, 0xB4091BFFL, 0x466298FCL,
+    0x1871A4D8L, 0xEA1A27DBL, 0xF94AD42FL, 0x0B21572CL,
+    0xDFEB33C7L, 0x2D80B0C4L, 0x3ED04330L, 0xCCBBC033L,
+    0xA24BB5A6L, 0x502036A5L, 0x4370C551L, 0xB11B4652L,
+    0x65D122B9L, 0x97BAA1BAL, 0x84EA524EL, 0x7681D14DL,
+    0x2892ED69L, 0xDAF96E6AL, 0xC9A99D9EL, 0x3BC21E9DL,
+    0xEF087A76L, 0x1D63F975L, 0x0E330A81L, 0xFC588982L,
+    0xB21572C9L, 0x407EF1CAL, 0x532E023EL, 0xA145813DL,
+    0x758FE5D6L, 0x87E466D5L, 0x94B49521L, 0x66DF1622L,
+    0x38CC2A06L, 0xCAA7A905L, 0xD9F75AF1L, 0x2B9CD9F2L,
+    0xFF56BD19L, 0x0D3D3E1AL, 0x1E6DCDEEL, 0xEC064EEDL,
+    0xC38D26C4L, 0x31E6A5C7L, 0x22B65633L, 0xD0DDD530L,
+    0x0417B1DBL, 0xF67C32D8L, 0xE52CC12CL, 0x1747422FL,
+    0x49547E0BL, 0xBB3FFD08L, 0xA86F0EFCL, 0x5A048DFFL,
+    0x8ECEE914L, 0x7CA56A17L, 0x6FF599E3L, 0x9D9E1AE0L,
+    0xD3D3E1ABL, 0x21B862A8L, 0x32E8915CL, 0xC083125FL,
+    0x144976B4L, 0xE622F5B7L, 0xF5720643L, 0x07198540L,
+    0x590AB964L, 0xAB613A67L, 0xB831C993L, 0x4A5A4A90L,
+    0x9E902E7BL, 0x6CFBAD78L, 0x7FAB5E8CL, 0x8DC0DD8FL,
+    0xE330A81AL, 0x115B2B19L, 0x020BD8EDL, 0xF0605BEEL,
+    0x24AA3F05L, 0xD6C1BC06L, 0xC5914FF2L, 0x37FACCF1L,
+    0x69E9F0D5L, 0x9B8273D6L, 0x88D28022L, 0x7AB90321L,
+    0xAE7367CAL, 0x5C18E4C9L, 0x4F48173DL, 0xBD23943EL,
+    0xF36E6F75L, 0x0105EC76L, 0x12551F82L, 0xE03E9C81L,
+    0x34F4F86AL, 0xC69F7B69L, 0xD5CF889DL, 0x27A40B9EL,
+    0x79B737BAL, 0x8BDCB4B9L, 0x988C474DL, 0x6AE7C44EL,
+    0xBE2DA0A5L, 0x4C4623A6L, 0x5F16D052L, 0xAD7D5351L
+};
+
+static __inline int
+calculate_crc32c(uint32_t crc, const void *buf, size_t size)
+{
+     const uint8_t *p = buf;
+
+     while (size--)
+	  crc = crc32Table[(crc ^ *p++) & 0xff] ^ (crc >> 8);
+     return crc;
+}
+#endif
+
+static uint32_t
+i_crc32c(const void *buf, size_t size, uint32_t crc)
+{
+     crc = crc ^ 0xffffffff;
+     crc = calculate_crc32c(crc, buf, size);
+     crc = crc ^ 0xffffffff;
+     return crc;
+}
+
+/*
+ | XXX: not finished coding
+ */
+int
+i_setopt(isc_session_t *sp, isc_opt_t *opt)
+{
+     if(opt->maxRecvDataSegmentLength > 0) {
+	  sp->opt.maxRecvDataSegmentLength = opt->maxRecvDataSegmentLength;
+	  sdebug(2, "maxRecvDataSegmentLength=%d", sp->opt.maxRecvDataSegmentLength);
+     }
+     if(opt->maxXmitDataSegmentLength > 0) {
+	  // danny's RFC
+	  sp->opt.maxXmitDataSegmentLength = opt->maxXmitDataSegmentLength;
+	  sdebug(2, "opt.maXmitDataSegmentLength=%d", sp->opt.maxXmitDataSegmentLength);
+     }
+     if(opt->maxBurstLength != 0) {
+	  sp->opt.maxBurstLength = opt->maxBurstLength;
+	  sdebug(2, "opt.maxBurstLength=%d", sp->opt.maxBurstLength);
+     }
+
+     if(opt->targetAddress != NULL) {
+	  if(sp->opt.targetAddress != NULL)
+	       free(sp->opt.targetAddress, M_ISC);
+	  sp->opt.targetAddress = i_strdupin(opt->targetAddress, 128);
+	  sdebug(2, "opt.targetAddress='%s'", sp->opt.targetAddress);
+     }
+     if(opt->targetName != NULL) {
+	  if(sp->opt.targetName != NULL)
+	       free(sp->opt.targetName, M_ISC);
+	  sp->opt.targetName = i_strdupin(opt->targetName, 128);
+	  sdebug(2, "opt.targetName='%s'", sp->opt.targetName);
+     }
+     if(opt->initiatorName != NULL) {
+	  if(sp->opt.initiatorName != NULL)
+	       free(sp->opt.initiatorName, M_ISC);
+	  sp->opt.initiatorName = i_strdupin(opt->initiatorName, 128);
+	  sdebug(2, "opt.initiatorName='%s'", sp->opt.initiatorName);
+     }
+
+     if(opt->maxluns > 0) {
+	  if(opt->maxluns > ISCSI_MAX_LUNS)
+	       sp->opt.maxluns = ISCSI_MAX_LUNS; // silently chop it down ...
+	  sp->opt.maxluns = opt->maxluns;
+	  sdebug(2, "opt.maxluns=%d", sp->opt.maxluns);
+     }
+
+     if(opt->headerDigest != NULL) {
+	  sdebug(2, "opt.headerDigest='%s'", opt->headerDigest);
+	  if(strcmp(opt->headerDigest, "CRC32C") == 0) {
+	       sp->hdrDigest = (digest_t *)i_crc32c;
+	       sdebug(2, "opt.headerDigest set");
+	  }
+     }
+     if(opt->dataDigest != NULL) {
+	  sdebug(2, "opt.dataDigest='%s'", opt->headerDigest);
+	  if(strcmp(opt->dataDigest, "CRC32C") == 0) {
+	       sp->dataDigest = (digest_t *)i_crc32c;
+	       sdebug(2, "opt.dataDigest set");
+	  }
+     }
+
+     return 0;
+}
+
+void
+i_freeopt(isc_opt_t *opt)
+{
+     debug_called(8);
+
+     if(opt->targetAddress != NULL) {
+	  free(opt->targetAddress, M_ISC);
+	  opt->targetAddress = NULL;
+     }
+     if(opt->targetName != NULL) {
+	  free(opt->targetName, M_ISC);
+	  opt->targetName = NULL;
+     }
+     if(opt->initiatorName != NULL) {
+	  free(opt->initiatorName, M_ISC);
+	  opt->initiatorName = NULL;
+     }
+}


Property changes on: trunk/sys/dev/iscsi_initiator/isc_subr.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sys/dev/iscsi_initiator/iscsi.c
===================================================================
--- trunk/sys/dev/iscsi_initiator/iscsi.c	                        (rev 0)
+++ trunk/sys/dev/iscsi_initiator/iscsi.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -0,0 +1,886 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2005-2011 Daniel Braniss <danny at cs.huji.ac.il>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+/*
+ | $Id: iscsi.c 752 2009-08-20 11:23:28Z danny $
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/sys/dev/iscsi_initiator/iscsi.c 299621 2016-05-13 08:36:33Z ngie $");
+
+#include "opt_iscsi_initiator.h"
+
+#include <sys/param.h>
+#include <sys/capsicum.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/conf.h>
+#include <sys/bus.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/ctype.h>
+#include <sys/errno.h>
+#include <sys/sysctl.h>
+#include <sys/file.h>
+#include <sys/uio.h>
+#include <sys/socketvar.h>
+#include <sys/socket.h>
+#include <sys/protosw.h>
+#include <sys/proc.h>
+#include <sys/ioccom.h>
+#include <sys/queue.h>
+#include <sys/kthread.h>
+#include <sys/mbuf.h>
+#include <sys/syslog.h>
+#include <vm/uma.h>
+#include <sys/sx.h>
+
+#include <dev/iscsi_initiator/iscsi.h>
+#include <dev/iscsi_initiator/iscsivar.h>
+static char *iscsi_driver_version = "2.3.1";
+
+static struct isc_softc *isc;
+
+MALLOC_DEFINE(M_ISCSI, "iSCSI", "iSCSI driver");
+MALLOC_DEFINE(M_ISCSIBUF, "iSCbuf", "iSCSI buffers");
+static MALLOC_DEFINE(M_TMP, "iSCtmp", "iSCSI tmp");
+
+#ifdef ISCSI_INITIATOR_DEBUG
+int iscsi_debug = ISCSI_INITIATOR_DEBUG;
+SYSCTL_INT(_debug, OID_AUTO, iscsi_initiator, CTLFLAG_RW, &iscsi_debug, 0,
+	"iSCSI driver debug flag");
+
+struct mtx iscsi_dbg_mtx;
+#endif
+
+static int max_sessions = MAX_SESSIONS;
+SYSCTL_INT(_net, OID_AUTO, iscsi_initiator_max_sessions, CTLFLAG_RDTUN, &max_sessions, MAX_SESSIONS,
+	   "Max sessions allowed");
+static int max_pdus = MAX_PDUS;
+SYSCTL_INT(_net, OID_AUTO, iscsi_initiator_max_pdus, CTLFLAG_RDTUN, &max_pdus, MAX_PDUS,
+	   "Max pdu pool");
+
+static char isid[6+1] = {
+     0x80,
+     'D',
+     'I',
+     'B',
+     '0',
+     '0',
+     0
+};
+
+static int	i_create_session(struct cdev *dev, int *ndev);
+
+static int	i_ping(struct cdev *dev);
+static int	i_send(struct cdev *dev, caddr_t arg, struct thread *td);
+static int	i_recv(struct cdev *dev, caddr_t arg, struct thread *td);
+static int	i_setsoc(isc_session_t *sp, int fd, struct thread *td);
+static int	i_fullfeature(struct cdev *dev, int flag);
+
+static d_open_t iscsi_open;
+static d_close_t iscsi_close;
+static d_ioctl_t iscsi_ioctl;
+#ifdef ISCSI_INITIATOR_DEBUG
+static d_read_t iscsi_read;
+#endif
+
+static struct cdevsw iscsi_cdevsw = {
+     .d_version = D_VERSION,
+     .d_open	= iscsi_open,
+     .d_close	= iscsi_close,
+     .d_ioctl	= iscsi_ioctl,
+#ifdef ISCSI_INITIATOR_DEBUG
+     .d_read	= iscsi_read,
+#endif
+     .d_name	= "iSCSI",
+};
+
+static int
+iscsi_open(struct cdev *dev, int flags, int otype, struct thread *td)
+{
+     debug_called(8);
+
+     debug(7, "dev=%d", dev2unit(dev));
+
+     if(dev2unit(dev) > max_sessions) {
+	  // should not happen
+          return ENODEV;
+     }
+     return 0;
+}
+
+static int
+iscsi_close(struct cdev *dev, int flag, int otyp, struct thread *td)
+{
+     isc_session_t	*sp;
+
+     debug_called(8);
+
+     debug(3, "session=%d flag=%x", dev2unit(dev), flag);
+
+     if(dev2unit(dev) == max_sessions) {
+	  return 0;
+     }
+     sp = dev->si_drv2;
+     if(sp != NULL) {
+	  sdebug(3, "sp->flags=%x", sp->flags );
+	  /*
+	   | if still in full phase, this probably means
+	   | that something went realy bad.
+	   | it could be a result from 'shutdown', in which case
+	   | we will ignore it (so buffers can be flushed).
+	   | the problem is that there is no way of differentiating
+	   | between a shutdown procedure and 'iscontrol' dying.
+	   */
+	  if(sp->flags & ISC_FFPHASE)
+	       // delay in case this is a shutdown.
+	       tsleep(sp, PRIBIO, "isc-cls", 60*hz);
+	  ism_stop(sp);
+     }
+     debug(2, "done");
+     return 0;
+}
+
+static int
+iscsi_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int mode, struct thread *td)
+{
+     struct isc_softc	*sc;
+     isc_session_t	*sp;
+     isc_opt_t		*opt;
+     int		error;
+
+     debug_called(8);
+
+     error = 0;
+     if(dev2unit(dev) == max_sessions) {
+	  /*
+	   | non Session commands
+	   */
+	  sc = dev->si_drv1;
+	  if(sc == NULL)
+	       return ENXIO;
+
+	  switch(cmd) {
+	  case ISCSISETSES:
+	       error = i_create_session(dev, (int *)arg);
+	       if(error == 0)
+		    break;
+
+	  default:
+	       error = ENXIO;
+	  }
+	  return error;
+     }
+     /*
+      | session commands
+      */
+     sp = dev->si_drv2;
+     if(sp == NULL)
+	  return ENXIO;
+
+     sdebug(6, "dev=%d cmd=%d", dev2unit(dev), (int)(cmd & 0xff));
+
+     switch(cmd) {
+     case ISCSISETSOC:
+	  error = i_setsoc(sp, *(u_int *)arg, td);
+	  break;
+
+     case ISCSISETOPT:
+	  opt = (isc_opt_t *)arg;
+	  error = i_setopt(sp, opt);
+	  break;
+
+     case ISCSISEND:
+	  error = i_send(dev, arg, td);
+	  break;
+
+     case ISCSIRECV:
+	  error = i_recv(dev, arg, td);
+	  break;
+
+     case ISCSIPING:
+	  error = i_ping(dev);
+	  break;
+
+     case ISCSISTART:
+	  error = sp->soc == NULL? ENOTCONN: i_fullfeature(dev, 1);
+	  if(error == 0) {
+	       sp->proc = td->td_proc;
+	       SYSCTL_ADD_INT(&sp->clist, SYSCTL_CHILDREN(sp->oid),
+			       OID_AUTO, "pid", CTLFLAG_RD,
+			       &sp->proc->p_pid, sizeof(pid_t), "control process id");
+	  }
+	  break;
+
+     case ISCSIRESTART:
+	  error = sp->soc == NULL? ENOTCONN: i_fullfeature(dev, 2);
+	  break;
+
+     case ISCSISTOP:
+	  error = i_fullfeature(dev, 0);
+	  break;
+	  
+     case ISCSISIGNAL: {
+	  int sig = *(int *)arg;
+
+	  if(sig < 0 || sig > _SIG_MAXSIG)
+	       error = EINVAL;
+	  else
+		sp->signal = sig;
+	  break;
+     }
+
+     case ISCSIGETCAM: {
+	  iscsi_cam_t *cp = (iscsi_cam_t *)arg;
+
+	  error = ic_getCamVals(sp, cp);
+	  break;
+     }
+
+     default:
+	  error = ENOIOCTL;
+     }
+
+     return error;
+}
+
+static int
+iscsi_read(struct cdev *dev, struct uio *uio, int ioflag)
+{
+#ifdef  ISCSI_INITIATOR_DEBUG
+     struct isc_softc	*sc;
+     isc_session_t	*sp;
+     pduq_t 		*pq;
+     char		buf[1024];
+
+     sc = dev->si_drv1;
+     sp = dev->si_drv2;
+     if(dev2unit(dev) == max_sessions) {
+	  sprintf(buf, "/----- Session ------/\n");
+	  uiomove(buf, strlen(buf), uio);
+	  int	i = 0;
+
+	  TAILQ_FOREACH(sp, &sc->isc_sess, sp_link) {
+	       if(uio->uio_resid == 0)
+		    return 0;
+	       sprintf(buf, "%03d] '%s' '%s'\n", i++, sp->opt.targetAddress, sp->opt.targetName);
+	       uiomove(buf, strlen(buf), uio);
+	  }
+	  sprintf(buf, "free npdu_alloc=%d, npdu_max=%d\n", sc->npdu_alloc, sc->npdu_max);
+	  uiomove(buf, strlen(buf), uio);
+     }
+     else {
+	  int	i = 0;
+	  struct socket	*so = sp->soc;
+#define pukeit(i, pq) do {\
+	       sprintf(buf, "%03d] %06x %02x %06x %06x %jd\n",\
+		       i, ntohl(pq->pdu.ipdu.bhs.CmdSN),\
+		       pq->pdu.ipdu.bhs.opcode, ntohl(pq->pdu.ipdu.bhs.itt),\
+		       ntohl(pq->pdu.ipdu.bhs.ExpStSN),\
+		       (intmax_t)pq->ts.sec);\
+	       } while(0)
+
+	  sprintf(buf, "%d/%d /---- hld -----/\n", sp->stats.nhld, sp->stats.max_hld);
+	  uiomove(buf, strlen(buf), uio);
+	  TAILQ_FOREACH(pq, &sp->hld, pq_link) {
+	       if(uio->uio_resid == 0)
+		    return 0;
+	       pukeit(i, pq); i++;
+	       uiomove(buf, strlen(buf), uio);
+	  }
+	  sprintf(buf, "%d/%d /---- rsp -----/\n", sp->stats.nrsp, sp->stats.max_rsp);
+	  uiomove(buf, strlen(buf), uio);
+	  i = 0;
+	  TAILQ_FOREACH(pq, &sp->rsp, pq_link) {
+	       if(uio->uio_resid == 0)
+		    return 0;
+	       pukeit(i, pq); i++;
+	       uiomove(buf, strlen(buf), uio);
+	  }
+	  sprintf(buf, "%d/%d /---- csnd -----/\n", sp->stats.ncsnd, sp->stats.max_csnd);
+	  i = 0;
+	  uiomove(buf, strlen(buf), uio);
+	  TAILQ_FOREACH(pq, &sp->csnd, pq_link) {
+	       if(uio->uio_resid == 0)
+		    return 0;
+	       pukeit(i, pq); i++;
+	       uiomove(buf, strlen(buf), uio);
+	  }
+	  sprintf(buf, "%d/%d /---- wsnd -----/\n", sp->stats.nwsnd, sp->stats.max_wsnd);
+	  i = 0;
+	  uiomove(buf, strlen(buf), uio);
+	  TAILQ_FOREACH(pq, &sp->wsnd, pq_link) {
+	       if(uio->uio_resid == 0)
+		    return 0;
+	       pukeit(i, pq); i++;
+	       uiomove(buf, strlen(buf), uio);
+	  }
+	  sprintf(buf, "%d/%d /---- isnd -----/\n", sp->stats.nisnd, sp->stats.max_isnd);
+	  i = 0;
+	  uiomove(buf, strlen(buf), uio);
+	  TAILQ_FOREACH(pq, &sp->isnd, pq_link) {
+	       if(uio->uio_resid == 0)
+		    return 0;
+	       pukeit(i, pq); i++;
+	       uiomove(buf, strlen(buf), uio);
+	  }
+
+	  sprintf(buf, "/---- Stats ---/\n");
+	  uiomove(buf, strlen(buf), uio);
+
+	  sprintf(buf, "recv=%d sent=%d\n", sp->stats.nrecv, sp->stats.nsent);
+	  uiomove(buf, strlen(buf), uio);
+
+	  sprintf(buf, "flags=%x pdus: alloc=%d max=%d\n", 
+		  sp->flags, sc->npdu_alloc, sc->npdu_max);
+	  uiomove(buf, strlen(buf), uio);
+
+	  sprintf(buf, "cws=%d last cmd=%x exp=%x max=%x stat=%x itt=%x\n",
+		  sp->cws, sp->sn.cmd, sp->sn.expCmd, sp->sn.maxCmd, sp->sn.stat, sp->sn.itt);
+	  uiomove(buf, strlen(buf), uio);
+
+	  sprintf(buf, "/---- socket -----/\nso_count=%d so_state=%x\n", so->so_count, so->so_state);
+	  uiomove(buf, strlen(buf), uio);
+
+     }
+#endif
+     return 0;
+}
+
+static int
+i_ping(struct cdev *dev)
+{
+     return 0;
+}
+/*
+ | low level I/O
+ */
+static int
+i_setsoc(isc_session_t *sp, int fd, struct thread *td)
+{
+     cap_rights_t rights;
+     int error = 0;
+
+     if(sp->soc != NULL)
+	  isc_stop_receiver(sp);
+
+     error = fget(td, fd, cap_rights_init(&rights, CAP_SOCK_CLIENT), &sp->fp);
+     if(error)
+	  return error;
+
+     error = fgetsock(td, fd, cap_rights_init(&rights, CAP_SOCK_CLIENT),
+        &sp->soc, 0);
+     if(error == 0) {
+	  sp->td = td;
+	  isc_start_receiver(sp);
+     }
+     else {
+	  fdrop(sp->fp, td);
+	  sp->fp = NULL;
+     }
+
+     return error;
+}
+
+static int
+i_send(struct cdev *dev, caddr_t arg, struct thread *td)
+{
+     isc_session_t	*sp = dev->si_drv2;
+     caddr_t		bp;
+     pduq_t		*pq;
+     pdu_t		*pp;
+     int		n, error;
+
+     debug_called(8);
+
+     if(sp->soc == NULL)
+	  return ENOTCONN;
+
+     if((pq = pdu_alloc(sp->isc, M_NOWAIT)) == NULL)
+	  return EAGAIN;
+     pp = &pq->pdu;
+     pq->pdu = *(pdu_t *)arg;
+     if((error = i_prepPDU(sp, pq)) != 0)
+	  goto out;
+
+     bp = NULL;
+     if((pq->len - sizeof(union ipdu_u)) > 0) {
+	  pq->buf = bp = malloc(pq->len - sizeof(union ipdu_u), M_ISCSIBUF, M_NOWAIT);
+	  if(pq->buf == NULL) {
+	       error = EAGAIN;
+	       goto out;
+	  }
+     }
+     else
+	  pq->buf = NULL; // just in case?
+
+     sdebug(2, "len=%d ahs_len=%d ds_len=%d buf=%zu@%p",
+	    pq->len, pp->ahs_len, pp->ds_len, pq->len - sizeof(union ipdu_u), bp);
+
+     if(pp->ahs_len) {
+	  // XXX: never tested, looks suspicious
+	  n = pp->ahs_len;
+	  error = copyin(pp->ahs_addr, bp, n);
+	  if(error != 0) {
+	       sdebug(3, "copyin ahs: error=%d", error);
+	       goto out;
+	  }
+	  pp->ahs_addr = (ahs_t *)bp;
+	  bp += n;
+     }
+     if(pp->ds_len) {
+	  n = pp->ds_len;
+	  error = copyin(pp->ds_addr, bp, n);
+	  if(error != 0) {
+	       sdebug(3, "copyin ds: error=%d", error);
+	       goto out;
+	  }
+	  pp->ds_addr = bp;
+	  bp += n;
+	  while(n & 03) {
+	       n++;
+	       *bp++ = 0;
+	  }
+     }
+
+     error = isc_qout(sp, pq);
+     if(error == 0)
+	  wakeup(&sp->flags); // XXX: to 'push' proc_out ...
+out:
+     if(error)
+	  pdu_free(sp->isc, pq);
+
+     return error;
+}
+
+static int
+i_recv(struct cdev *dev, caddr_t arg, struct thread *td)
+{
+     isc_session_t	*sp = dev->si_drv2;
+     pduq_t		*pq;
+     pdu_t		*pp, *up;
+     caddr_t		bp;
+     int		error, mustfree, cnt;
+     size_t		need, have, n;
+
+     debug_called(8);
+
+     if(sp == NULL)
+	  return EIO;
+
+     if(sp->soc == NULL)
+	  return ENOTCONN;
+     cnt = 6;     // XXX: maybe the user can request a time out?
+     mtx_lock(&sp->rsp_mtx);
+     while((pq = TAILQ_FIRST(&sp->rsp)) == NULL) {
+	  msleep(&sp->rsp, &sp->rsp_mtx, PRIBIO, "isc_rsp", hz*10);
+	  if(cnt-- == 0) break; // XXX: for now, needs work
+     }
+     if(pq != NULL) {
+	  sp->stats.nrsp--;
+	  TAILQ_REMOVE(&sp->rsp, pq, pq_link);
+     }
+     mtx_unlock(&sp->rsp_mtx);
+
+     sdebug(6, "cnt=%d", cnt);
+
+     if(pq == NULL) {
+	  error = ENOTCONN;
+	  sdebug(3, "error=%d sp->flags=%x ", error, sp->flags);
+	  return error;
+     }
+     up = (pdu_t *)arg;
+     pp = &pq->pdu;
+     up->ipdu = pp->ipdu;
+     n = 0;
+     up->ds_len = 0;
+     up->ahs_len = 0;
+     error = 0;
+
+     if(pq->mp) {
+	  u_int	len;
+
+	  // Grr...
+	  len = 0;
+	  if(pp->ahs_len) {
+	       len += pp->ahs_len;
+	  }
+	  if(pp->ds_len) {
+	       len += pp->ds_len;
+	  }
+
+	  mustfree = 0;
+	  if(len > pq->mp->m_len) {
+	       mustfree++;
+	       bp = malloc(len, M_TMP, M_WAITOK);
+	       sdebug(4, "need mbufcopy: %d", len);
+	       i_mbufcopy(pq->mp, bp, len);
+	  } 
+	  else
+	       bp = mtod(pq->mp, caddr_t);
+
+	  if(pp->ahs_len) {
+	       need = pp->ahs_len;
+	       n = MIN(up->ahs_size, need);
+	       error = copyout(bp, (caddr_t)up->ahs_addr, n);
+	       up->ahs_len = n;
+	       bp += need;
+	  }
+	  if(!error && pp->ds_len) {
+	       need = pp->ds_len;
+	       if((have = up->ds_size) == 0) {
+		    have = up->ahs_size - n;
+		    up->ds_addr = (caddr_t)up->ahs_addr + n;
+	       }
+	       n = MIN(have, need);
+	       error = copyout(bp, (caddr_t)up->ds_addr, n);
+	       up->ds_len = n;
+	  }
+
+	  if(mustfree)
+	       free(bp, M_TMP);
+     }
+
+     sdebug(6, "len=%d ahs_len=%d ds_len=%d", pq->len, pp->ahs_len, pp->ds_len);
+
+     pdu_free(sp->isc, pq);
+
+     return error;
+}
+
+static int
+i_fullfeature(struct cdev *dev, int flag)
+{
+     isc_session_t	*sp = dev->si_drv2;
+     int		error;
+
+     sdebug(2, "flag=%d", flag);
+
+     error = 0;
+     switch(flag) {
+     case 0: // stop
+         sp->flags &= ~ISC_FFPHASE;
+         break;
+     case 1: // start
+         sp->flags |= ISC_FFPHASE;
+         error = ic_init(sp);
+         break;
+     case 2: // restart
+         sp->flags |= ISC_FFPHASE;
+         ism_restart(sp);
+         break;
+     }
+     return error;
+}
+
+static int
+i_create_session(struct cdev *dev, int *ndev)
+{ 
+     struct isc_softc	*sc = dev->si_drv1;
+     isc_session_t	*sp;
+     int		error, n;
+
+     debug_called(8);
+
+     sp = malloc(sizeof(isc_session_t), M_ISCSI, M_WAITOK | M_ZERO);
+     if(sp == NULL)
+	  return ENOMEM;
+
+     sx_xlock(&sc->unit_sx);
+     if((n = alloc_unr(sc->unit)) < 0) {
+	  sx_unlock(&sc->unit_sx);
+	  free(sp, M_ISCSI);
+	  xdebug("too many sessions!");
+	  return EPERM;
+     }
+     sx_unlock(&sc->unit_sx);
+
+     mtx_lock(&sc->isc_mtx);
+     TAILQ_INSERT_TAIL(&sc->isc_sess, sp, sp_link);
+     isc->nsess++;
+     mtx_unlock(&sc->isc_mtx);
+
+     sp->dev = make_dev(&iscsi_cdevsw, n, UID_ROOT, GID_WHEEL, 0600, "iscsi%d", n);
+     *ndev = sp->sid = n;
+     sp->isc = sc;
+     sp->dev->si_drv1 = sc;
+     sp->dev->si_drv2 = sp;
+
+     sp->opt.maxRecvDataSegmentLength = 8192;
+     sp->opt.maxXmitDataSegmentLength = 8192;
+     sp->opt.maxBurstLength = 65536;	// 64k
+     sp->opt.maxluns = ISCSI_MAX_LUNS;
+
+     error = ism_start(sp);
+
+     return error;
+}
+
+#ifdef notused
+static void
+iscsi_counters(isc_session_t *sp)
+{
+     int	h, r, s;
+     pduq_t	*pq;
+
+#define _puke(i, pq) do {\
+	       debug(2, "%03d] %06x %02x %x %ld %jd %x\n",\
+		       i, ntohl( pq->pdu.ipdu.bhs.CmdSN), \
+		       pq->pdu.ipdu.bhs.opcode, ntohl(pq->pdu.ipdu.bhs.itt),\
+		       (long)pq->ts.sec, pq->ts.frac, pq->flags);\
+	       } while(0)
+
+     h = r = s = 0; 
+     TAILQ_FOREACH(pq, &sp->hld, pq_link) {
+	  _puke(h, pq);
+	  h++;
+     }
+     TAILQ_FOREACH(pq, &sp->rsp, pq_link) r++;
+     TAILQ_FOREACH(pq, &sp->csnd, pq_link) s++;
+     TAILQ_FOREACH(pq, &sp->wsnd, pq_link) s++;
+     TAILQ_FOREACH(pq, &sp->isnd, pq_link) s++;
+     debug(2, "hld=%d rsp=%d snd=%d", h, r, s);
+}
+#endif
+
+static void
+iscsi_shutdown(void *v)
+{
+     struct isc_softc	*sc = v;
+     isc_session_t	*sp;
+     int	n;
+
+     debug_called(8);
+     if(sc == NULL) {
+	  xdebug("sc is NULL!");
+	  return;
+     }
+#ifdef DO_EVENTHANDLER
+     if(sc->eh == NULL)
+	  debug(2, "sc->eh is NULL");
+     else {
+	  EVENTHANDLER_DEREGISTER(shutdown_pre_sync, sc->eh);
+	  debug(2, "done n=%d", sc->nsess);
+     }
+#endif
+     n = 0;
+     TAILQ_FOREACH(sp, &sc->isc_sess, sp_link) {
+	  debug(2, "%2d] sp->flags=0x%08x", n, sp->flags);
+	  n++;
+     }
+     debug(2, "done");
+}
+
+static void
+free_pdus(struct isc_softc *sc)
+{
+     debug_called(8);
+
+     if(sc->pdu_zone != NULL) {
+	  uma_zdestroy(sc->pdu_zone);
+	  sc->pdu_zone = NULL;
+     }
+}
+
+static int
+iscsi_start(void)
+{
+     debug_called(8);
+
+     TUNABLE_INT_FETCH("net.iscsi_initiator.max_sessions", &max_sessions);
+     TUNABLE_INT_FETCH("net.iscsi_initiator.max_pdus", &max_pdus);
+
+     isc =  malloc(sizeof(struct isc_softc), M_ISCSI, M_ZERO|M_WAITOK);
+     mtx_init(&isc->isc_mtx, "iscsi-isc", NULL, MTX_DEF);
+
+     TAILQ_INIT(&isc->isc_sess);
+     /*
+      | now init the free pdu list
+      */
+     isc->pdu_zone = uma_zcreate("pdu", sizeof(pduq_t),
+				 NULL, NULL, NULL, NULL,
+				 0, 0);
+     uma_zone_set_max(isc->pdu_zone, max_pdus);
+     isc->unit = new_unrhdr(0, max_sessions-1, NULL);
+     sx_init(&isc->unit_sx, "iscsi sx");
+
+#ifdef DO_EVENTHANDLER
+     if((isc->eh = EVENTHANDLER_REGISTER(shutdown_pre_sync, iscsi_shutdown,
+					sc, SHUTDOWN_PRI_DEFAULT-1)) == NULL)
+	  xdebug("shutdown event registration failed\n");
+#endif
+     /*
+      | sysctl stuff
+      */
+     sysctl_ctx_init(&isc->clist);
+     isc->oid = SYSCTL_ADD_NODE(&isc->clist,
+			       SYSCTL_STATIC_CHILDREN(_net),
+			       OID_AUTO,
+			       "iscsi_initiator",
+			       CTLFLAG_RD,
+			       0,
+			       "iSCSI Subsystem");
+
+     SYSCTL_ADD_STRING(&isc->clist,
+		       SYSCTL_CHILDREN(isc->oid),
+		       OID_AUTO,
+		       "driver_version",
+		       CTLFLAG_RD,
+		       iscsi_driver_version,
+		       0,
+		       "iscsi driver version");
+ 
+     SYSCTL_ADD_STRING(&isc->clist,
+		       SYSCTL_CHILDREN(isc->oid),
+		       OID_AUTO,
+		       "isid",
+		       CTLFLAG_RW,
+		       isid,
+		       6+1,
+		       "initiator part of the Session Identifier");
+
+     SYSCTL_ADD_INT(&isc->clist,
+		    SYSCTL_CHILDREN(isc->oid),
+		    OID_AUTO,
+		    "sessions",
+		    CTLFLAG_RD,
+		    &isc->nsess,
+		    sizeof(isc->nsess),
+		    "number of active session");
+
+#ifdef ISCSI_INITIATOR_DEBUG
+     mtx_init(&iscsi_dbg_mtx, "iscsi_dbg", NULL, MTX_DEF);
+#endif
+
+     isc->dev = make_dev_credf(MAKEDEV_CHECKNAME, &iscsi_cdevsw, max_sessions,
+			       NULL, UID_ROOT, GID_WHEEL, 0600, "iscsi");
+     if (isc->dev == NULL) {
+	  xdebug("iscsi_initiator: make_dev_credf failed");
+	  return (EEXIST);
+     }
+     isc->dev->si_drv1 = isc;
+
+     printf("iscsi: version %s\n", iscsi_driver_version);
+     return (0);
+}
+
+/*
+ | Notes:
+ |	unload SHOULD fail if there is activity
+ |	activity: there is/are active session/s
+ */
+static void
+iscsi_stop(void)
+{
+     isc_session_t	*sp, *sp_tmp;
+
+     debug_called(8);
+
+     /*
+      | go through all the sessions
+      | Note: close should have done this ...
+      */
+     TAILQ_FOREACH_SAFE(sp, &isc->isc_sess, sp_link, sp_tmp) {
+	  //XXX: check for activity ...
+	  ism_stop(sp);
+     }
+     mtx_destroy(&isc->isc_mtx);
+     sx_destroy(&isc->unit_sx);
+
+     free_pdus(isc);
+
+     if(isc->dev)
+	  destroy_dev(isc->dev);
+
+     if(sysctl_ctx_free(&isc->clist))
+	  xdebug("sysctl_ctx_free failed");
+
+     iscsi_shutdown(isc); // XXX: check EVENTHANDLER_ ...
+
+#ifdef ISCSI_INITIATOR_DEBUG
+     mtx_destroy(&iscsi_dbg_mtx);
+#endif
+
+     free(isc, M_ISCSI);
+}
+
+static int
+iscsi_modevent(module_t mod, int what, void *arg)
+{
+     int error = 0;
+
+     debug_called(8);
+
+     switch(what) {
+     case MOD_LOAD:
+	  error = iscsi_start();
+	  break;
+
+     case MOD_QUIESCE:
+	  if(isc->nsess) {
+	       xdebug("iscsi module busy(nsess=%d), cannot unload", isc->nsess);
+	       log(LOG_ERR, "iscsi module busy, cannot unload");
+	  }
+	  return isc->nsess;
+
+     case MOD_SHUTDOWN:
+	  break;
+
+     case MOD_UNLOAD:
+	  iscsi_stop();
+	  break;
+
+     default:
+	  break;
+     }
+     return (error);
+}
+
+moduledata_t iscsi_mod = {
+         "iscsi_initiator",
+         (modeventhand_t) iscsi_modevent,
+         0
+};
+
+#ifdef ISCSI_ROOT
+static void
+iscsi_rootconf(void)
+{
+#if 0
+	nfs_setup_diskless();
+	if (nfs_diskless_valid)
+		rootdevnames[0] = "nfs:";
+#endif
+	printf("** iscsi_rootconf **\n");
+}
+
+SYSINIT(cpu_rootconf1, SI_SUB_ROOT_CONF, SI_ORDER_FIRST, iscsi_rootconf, NULL)
+#endif
+
+DECLARE_MODULE(iscsi_initiator, iscsi_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
+MODULE_DEPEND(iscsi_initiator, cam, 1, 1, 1);


Property changes on: trunk/sys/dev/iscsi_initiator/iscsi.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sys/dev/iscsi_initiator/iscsi.h
===================================================================
--- trunk/sys/dev/iscsi_initiator/iscsi.h	                        (rev 0)
+++ trunk/sys/dev/iscsi_initiator/iscsi.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -0,0 +1,501 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2005-2010 Daniel Braniss <danny at cs.huji.ac.il>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/sys/dev/iscsi_initiator/iscsi.h 211095 2010-08-09 12:36:36Z des $
+ */
+/*
+ | $Id: iscsi.h 743 2009-08-08 10:54:53Z danny $
+ */
+#define	TRUE	1
+#define FALSE	0
+#ifndef _KERNEL
+typedef int boolean_t;
+#endif
+
+#include <cam/cam.h>
+
+#define ISCSIDEV	"iscsi"
+#define ISCSI_MAX_TARGETS	64
+/*
+ | iSCSI commands
+ */
+
+/*
+ | Initiator Opcodes:
+ */
+#define ISCSI_NOP_OUT		0x00
+#define ISCSI_SCSI_CMD		0x01
+#define ISCSI_TASK_CMD		0x02
+#define ISCSI_LOGIN_CMD		0x03
+#define ISCSI_TEXT_CMD		0x04
+#define ISCSI_WRITE_DATA	0x05
+#define ISCSI_LOGOUT_CMD	0x06
+#define ISCSI_SNACK		0x10
+/*
+ | Target Opcodes:
+ */
+#define ISCSI_NOP_IN		0x20
+#define ISCSI_SCSI_RSP		0x21
+#define ISCSI_TASK_RSP		0x22
+#define ISCSI_LOGIN_RSP		0x23
+#define ISCSI_TEXT_RSP		0x24
+#define ISCSI_READ_DATA		0x25
+#define ISCSI_LOGOUT_RSP	0x26
+#define ISCSI_R2T		0x31
+#define ISCSI_ASYNC		0x32
+#define ISCSI_REJECT		0x3f
+/*
+ | PDU stuff
+ */
+/*
+ | BHS Basic Header Segment
+ */
+typedef struct bhs {
+     // the order is network byte order!
+     u_char	opcode:6;
+     u_char	I:1;
+     u_char	_:1;
+     u_char	__:7;
+     u_char	F:1;			// Final bit
+     u_char	___[2];
+
+     u_int	AHSLength:8;		// in 4byte words
+     u_int	DSLength:24;		// in bytes
+
+     u_int	LUN[2];			// or Opcode-specific fields
+     u_int	itt;
+     u_int	OpcodeSpecificFields[7];
+#define	CmdSN		OpcodeSpecificFields[1]
+#define	ExpStSN		OpcodeSpecificFields[2]
+#define MaxCmdSN	OpcodeSpecificFields[3]
+} bhs_t;
+
+typedef struct ahs {
+     u_int	len:16;
+     u_int	type:8;
+     u_int	spec:8;
+     char	data[0];
+} ahs_t;
+
+typedef struct {
+     // Sequence Numbers
+     // (computers were invented to count, right?)
+     int	cmd;
+     int	expcmd;
+     int	maxcmd;
+} req_sn_t;
+
+typedef struct {
+     // Sequence Numbers
+     // (computers were invented to count, right?)
+     int	stat;
+     int	expcmd;
+     int	maxcmd;
+} rsp_sn_t;
+
+typedef struct scsi_req {
+     u_char	opcode:6; // 0x01
+     u_char	I:1;
+     u_char	_:1;
+
+     u_char	attr:3;
+     u_char	_0:2;
+     u_char	W:1;
+     u_char	R:1;
+     u_char	F:1;
+#define		iSCSI_TASK_UNTAGGED	0
+#define		iSCSI_TASK_SIMPLE	1
+#define		iSCSI_TASK_ORDER	2
+#define		iSCSI_TASK_HOFQ		3
+#define		iSCSI_TASK_ACA		4
+     char	_1[2];
+     int	len;
+     int	lun[2];
+     int	itt;
+     int	edtlen;		// expectect data transfere length
+     int	cmdSN;
+     int	extStatSN;
+     int	cdb[4];
+} scsi_req_t;
+
+typedef struct scsi_rsp {
+     char	opcode;	// 0x21
+     u_char	flag;
+     u_char	response;
+     u_char	status;
+
+     int	len;
+     int	_[2];
+     int	itt;
+     int	stag;
+     rsp_sn_t	sn;
+     int	expdatasn;
+     int	bdrcnt;	// bidirectional residual count
+     int	rcnt;	// residual count
+} scsi_rsp_t;
+
+typedef struct nop_out {
+     // the order is network byte order!
+     u_char	opcode:6;
+     u_char	I:1;
+     u_char	_:1;
+     u_char	__:7;
+     u_char	F:1;			// Final bit
+     u_char	___[2];
+
+     u_int	len;
+     u_int	lun[2];
+     u_int	itt;
+     u_int	ttt;
+     req_sn_t	sn;
+     u_int	mbz[3];
+} nop_out_t; 
+
+typedef struct nop_in {
+     // the order is network byte order!
+     u_char	opcode:6;
+     u_char	I:1;
+     u_char	_:1;
+     u_char	__:7;
+     u_char	F:1;			// Final bit
+     u_char	___[2];
+
+     u_int	len;
+     u_int	lun[2];
+     u_int	itt;
+     u_int	ttt;
+     rsp_sn_t	sn;
+     u_int	____[2];
+     
+} nop_in_t;
+
+typedef struct r2t {
+     u_char	opcode:6;
+     u_char	I:1;
+     u_char	_:1;
+     u_char	__:7;
+     u_char	F:1;			// Final bit
+     u_char	___[2];  
+
+     u_int	len;
+     u_int	lun[2];
+     u_int	itt;
+     u_int	ttt;
+     rsp_sn_t	sn;
+     u_int	r2tSN;
+     u_int	bo;
+     u_int	ddtl;
+} r2t_t;
+
+typedef struct data_out {
+     u_char	opcode:6;
+     u_char	I:1;
+     u_char	_:1;
+     u_char	__:7;
+     u_char	F:1;			// Final bit
+     u_char	___[2];  
+
+     u_int	len;
+     u_int	lun[2];
+     u_int	itt;
+     u_int	ttt;
+     rsp_sn_t	sn;
+     u_int	dsn;	// data seq. number
+     u_int	bo;
+     u_int	____;
+} data_out_t;
+
+typedef struct data_in {
+     u_char	opcode:6;
+     u_char	I:1;
+     u_char	_:1;
+
+     u_char	S:1;
+     u_char	U:1;
+     u_char	O:1;
+     u_char	__:3;
+     u_char	A:1;
+     u_char	F:1;			// Final bit
+     u_char	___[1]; 
+     u_char	status;
+
+     u_int	len;
+     u_int	lun[2];
+     u_int	itt;
+     u_int	ttt;
+     rsp_sn_t	sn;
+     u_int	dataSN;
+     u_int	bo;
+     u_int	____;
+} data_in_t;
+
+typedef struct reject {
+     u_char	opcode:6;
+     u_char	_:2;
+     u_char	F:1;
+     u_char	__:7;
+     u_char	reason;
+     u_char	___;
+
+     u_int	len;
+     u_int	____[2];
+     u_int	tt[2];	// must be -1
+     rsp_sn_t	sn;
+     u_int	dataSN;	// or R2TSN or reserved
+     u_int	_____[2];
+} reject_t;
+
+typedef struct async {
+     u_char	opcode:6;
+     u_char	_:2;
+     u_char	F:1;
+     u_char	__:7;
+     u_char	___[2];
+
+     u_int	len;
+     u_int	lun[2];
+     u_int	itt;	// must be -1
+     u_int	____;
+     rsp_sn_t	sn;
+
+     u_char	asyncEvent;
+     u_char	asyncVCode;
+     u_char	param1[2];
+     u_char	param2[2];
+     u_char	param3[2];
+
+     u_int	_____;
+     
+} async_t;  
+
+typedef struct login_req {
+     char	cmd;	// 0x03
+
+     u_char	NSG:2;
+     u_char	CSG:2;
+     u_char	_:2;
+     u_char	C:1;
+     u_char	T:1;
+
+     char	v_max;
+     char	v_min;
+
+     int	len;	// remapped via standard bhs
+     char	isid[6];
+     short	tsih;
+     int	itt;	// Initiator Task Tag;
+
+     int	CID:16;
+     int	rsv:16;
+
+     int	cmdSN;
+     int	expStatSN;
+     int	unused[4];
+} login_req_t;
+
+typedef struct login_rsp {
+     char	cmd;	// 0x23
+     u_char	NSG:2;
+     u_char	CSG:2;
+     u_char	_1:2;
+     u_char	C:1;
+     u_char	T:1;
+
+     char	v_max;
+     char	v_act;
+
+     int	len;	// remapped via standard bhs
+     char	isid[6];
+     short	tsih;
+     int	itt;	// Initiator Task Tag;
+     int	_2;
+     rsp_sn_t	sn;
+     int	status:16;
+     int	_3:16;
+     int	_4[2];
+} login_rsp_t;
+
+typedef struct text_req {
+     char	cmd;	// 0x04
+
+     u_char	_1:6;
+     u_char	C:1;	// Continuation 
+     u_char	F:1;	// Final
+     char	_2[2];
+
+     int	len;
+     int	itt;		// Initiator Task Tag
+     int	LUN[2];
+     int	ttt;		// Target Transfer Tag
+     int	cmdSN;
+     int	expStatSN;
+     int	unused[4];
+} text_req_t;
+
+typedef struct logout_req {
+     char	cmd;	// 0x06
+     char	reason;	// 0 - close session
+     			// 1 - close connection
+     			// 2 - remove the connection for recovery
+     char	_2[2];
+
+     int	len;
+     int	_r[2];
+     int	itt;	// Initiator Task Tag;
+
+     u_int	CID:16;
+     u_int	rsv:16;
+
+     int	cmdSN;
+     int	expStatSN;
+     int	unused[4];
+} logout_req_t;
+
+typedef struct logout_rsp {
+     char	cmd;	// 0x26
+     char	cbits;
+     char	_1[2];
+     int	len;
+     int	_2[2];
+     int	itt;
+     int	_3;
+     rsp_sn_t	sn;
+     short	time2wait;
+     short	time2retain;
+     int	_4;
+} logout_rsp_t;
+
+union ipdu_u {
+     bhs_t	bhs;
+     scsi_req_t	scsi_req;
+     scsi_rsp_t	scsi_rsp;
+     nop_out_t	nop_out;
+     nop_in_t	nop_in;
+     r2t_t	r2t;
+     data_out_t	data_out;
+     data_in_t	data_in;
+     reject_t	reject;
+     async_t	async;
+};
+
+/*
+ | Sequence Numbers
+ */
+typedef struct {
+     u_int	itt;
+     u_int      cmd;
+     u_int      expCmd;
+     u_int      maxCmd;
+     u_int      stat;
+     u_int      expStat;
+     u_int      data;
+} sn_t;
+
+/*
+ | in-core version of a Protocol Data Unit
+ */
+typedef struct {
+     union ipdu_u	ipdu;
+     u_int		hdr_dig;	// header digest
+
+     ahs_t		*ahs_addr;
+     u_int		ahs_len;
+     u_int		ahs_size;	// the allocated size
+
+     u_char		*ds_addr;
+     u_int		ds_len;
+     u_int		ds_size;	// the allocated size
+     u_int		ds_dig;		// data digest
+} pdu_t;
+
+typedef struct opvals {
+     int	port;
+     int	tags;
+     int	maxluns;
+     int	sockbufsize;
+
+     int	maxConnections;
+     int	maxRecvDataSegmentLength;
+     int	maxXmitDataSegmentLength; // pseudo ...
+     int	maxBurstLength;
+     int	firstBurstLength;
+     int	defaultTime2Wait;
+     int	defaultTime2Retain;
+     int	maxOutstandingR2T;
+     int	errorRecoveryLevel;
+     int	targetPortalGroupTag;
+
+     boolean_t	initialR2T;
+     boolean_t	immediateData;
+     boolean_t	dataPDUInOrder;
+     boolean_t	dataSequenceInOrder;
+     char	*headerDigest;
+     char	*dataDigest;
+     char	*sessionType;
+     char	*sendTargets;
+     char	*targetAddress;
+     char	*targetAlias;
+     char	*targetName;
+     char	*initiatorName;
+     char	*initiatorAlias;
+     char	*authMethod;
+     char	*chapSecret;
+     char	*chapIName;
+     char	*chapDigest;
+     char	*tgtChapName;
+     char	*tgtChapSecret;
+     int	tgtChallengeLen;
+     u_char	tgtChapID;
+     char	*tgtChapDigest;
+     char	*iqn;
+     char	*pidfile;
+} isc_opt_t;
+
+/*
+ | ioctl
+ */
+#define ISCSISETSES	_IOR('i', 1, int)
+#define ISCSISETSOC	_IOW('i', 2, int)
+#define ISCSISETOPT	_IOW('i', 5, isc_opt_t)
+#define ISCSIGETOPT	_IOR('i', 6, isc_opt_t)
+
+#define ISCSISEND	_IOW('i', 10, pdu_t)
+#define ISCSIRECV	_IOWR('i', 11, pdu_t)
+
+#define ISCSIPING	_IO('i', 20)
+#define ISCSISIGNAL	_IOW('i', 21, int *)
+
+#define ISCSISTART	_IO('i', 30)
+#define ISCSIRESTART	_IO('i', 31)
+#define ISCSISTOP	_IO('i', 32)
+
+typedef struct iscsi_cam {
+     path_id_t		path_id;
+     target_id_t	target_id;
+     int		target_nluns;
+} iscsi_cam_t;
+
+#define ISCSIGETCAM	_IOR('i', 33, iscsi_cam_t)


Property changes on: trunk/sys/dev/iscsi_initiator/iscsi.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sys/dev/iscsi_initiator/iscsi_subr.c
===================================================================
--- trunk/sys/dev/iscsi_initiator/iscsi_subr.c	                        (rev 0)
+++ trunk/sys/dev/iscsi_initiator/iscsi_subr.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -0,0 +1,609 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2005-2010 Daniel Braniss <danny at cs.huji.ac.il>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+/*
+ | $Id: iscsi_subr.c 743 2009-08-08 10:54:53Z danny $
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/sys/dev/iscsi_initiator/iscsi_subr.c 254657 2013-08-22 14:02:34Z trasz $");
+
+#include "opt_iscsi_initiator.h"
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/callout.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/kthread.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/uio.h>
+#include <sys/sysctl.h>
+#include <sys/sx.h>
+
+#include <cam/cam.h>
+#include <cam/cam_ccb.h>
+#include <cam/cam_sim.h>
+#include <cam/cam_xpt_sim.h>
+#include <cam/cam_periph.h>
+#include <cam/scsi/scsi_message.h>
+#include <sys/eventhandler.h>
+
+#include <dev/iscsi_initiator/iscsi.h>
+#include <dev/iscsi_initiator/iscsivar.h>
+
+/*
+ | Interface to the SCSI layer
+ */
+void
+iscsi_r2t(isc_session_t *sp, pduq_t *opq, pduq_t *pq)
+{
+     union ccb 		*ccb = opq->ccb;
+     struct ccb_scsiio	*csio = &ccb->csio;
+     pdu_t		*opp = &opq->pdu;
+     bhs_t		*bhp = &opp->ipdu.bhs;
+     r2t_t		*r2t = &pq->pdu.ipdu.r2t;
+     pduq_t	*wpq;
+     int	error;
+
+     debug_called(8);
+     sdebug(4, "itt=%x r2tSN=%d bo=%x ddtl=%x W=%d", ntohl(r2t->itt),
+	   ntohl(r2t->r2tSN), ntohl(r2t->bo), ntohl(r2t->ddtl), opp->ipdu.scsi_req.W);
+
+     switch(bhp->opcode) {
+     case ISCSI_SCSI_CMD:
+	  if(opp->ipdu.scsi_req.W) {
+	       data_out_t	*cmd;
+	       u_int		ddtl = ntohl(r2t->ddtl);
+	       u_int		edtl = ntohl(opp->ipdu.scsi_req.edtlen);
+	       u_int		bleft, bs, dsn, bo;
+	       caddr_t		bp = csio->data_ptr;
+
+	       bo = ntohl(r2t->bo);
+	       bp += MIN(bo, edtl - ddtl);
+	       bleft = ddtl;
+
+	       if(sp->opt.maxXmitDataSegmentLength > 0) // danny's RFC
+		    bs = MIN(sp->opt.maxXmitDataSegmentLength, ddtl);
+	       else
+		    bs = ddtl;
+	       dsn = 0;
+	       sdebug(4, "edtl=%x ddtl=%x bo=%x dsn=%x bs=%x maxX=%x",
+		      edtl, ddtl, bo, dsn, bs, sp->opt.maxXmitDataSegmentLength);
+	       while(bleft > 0) {
+		    wpq = pdu_alloc(sp->isc, M_NOWAIT); // testing ...
+		    if(wpq == NULL) {
+			 sdebug(3, "itt=%x r2tSN=%d bo=%x ddtl=%x W=%d", ntohl(r2t->itt),
+				ntohl(r2t->r2tSN), ntohl(r2t->bo), ntohl(r2t->ddtl), opp->ipdu.scsi_req.W);
+			 sdebug(1, "npdu_max=%d npdu_alloc=%d", sp->isc->npdu_max, sp->isc->npdu_alloc);
+
+			 while((wpq = pdu_alloc(sp->isc, M_NOWAIT)) == NULL) {
+			      sdebug(2, "waiting...");
+#if __FreeBSD_version >= 700000
+			      pause("isc_r2t", 5*hz);
+#else
+			      tsleep(sp->isc, 0, "isc_r2t", 5*hz);
+#endif
+			 }
+		    }
+		    cmd = &wpq->pdu.ipdu.data_out;
+		    cmd->opcode = ISCSI_WRITE_DATA;
+		    cmd->lun[0]	= r2t->lun[0];
+		    cmd->lun[1]	= r2t->lun[1];
+		    cmd->ttt	= r2t->ttt;
+		    cmd->itt	= r2t->itt;
+
+		    cmd->dsn	= htonl(dsn);
+		    cmd->bo	= htonl(bo);
+
+		    cmd->F 	= (bs < bleft)? 0: 1; // is this the last one?
+		    bs = MIN(bs, bleft);
+		    
+		    wpq->pdu.ds_len	= bs;
+		    wpq->pdu.ds_addr	= bp;
+		    
+		    error = isc_qout(sp, wpq);
+		    sdebug(6, "bs=%x bo=%x bp=%p dsn=%x error=%d", bs, bo, bp, dsn, error);
+		    if(error)
+			 break;
+		    bo += bs;
+		    bp += bs;
+		    bleft -= bs;
+		    dsn++;
+	       }
+	  }
+	  break;
+
+     default:
+	  // XXX: should not happen ...
+	  xdebug("huh? opcode=0x%x", bhp->opcode);
+     }
+}
+
+static int
+getSenseData(u_int status, union ccb *ccb, pduq_t *pq)
+{
+     pdu_t		*pp = &pq->pdu;
+     struct		ccb_scsiio *scsi = (struct ccb_scsiio *)ccb;
+     struct		scsi_sense_data *sense = &scsi->sense_data;
+     struct mbuf	*m = pq->mp;
+     scsi_rsp_t		*cmd = &pp->ipdu.scsi_rsp;
+     caddr_t		bp;
+     int		sense_len, mustfree = 0;
+     int                error_code, sense_key, asc, ascq;
+
+     bp = mtod(pq->mp, caddr_t);
+     if((sense_len = scsi_2btoul(bp)) == 0)
+	  return 0;
+     debug(4, "sense_len=%d", sense_len);
+     /*
+      | according to the specs, the sense data cannot
+      | be larger than 252 ...
+      */
+     if(sense_len > m->m_len) {
+	  bp = malloc(sense_len, M_ISCSI, M_WAITOK);
+	  debug(3, "calling i_mbufcopy(len=%d)", sense_len);
+	  i_mbufcopy(pq->mp, bp, sense_len);
+	  mustfree++;
+     }
+     scsi->scsi_status = status;
+
+     bcopy(bp+2, sense, min(sense_len, scsi->sense_len));
+     scsi->sense_resid = 0;
+     if(cmd->flag & (BIT(1)|BIT(2)))
+	  scsi->sense_resid = ntohl(pp->ipdu.scsi_rsp.rcnt);
+     scsi_extract_sense_len(sense, scsi->sense_len - scsi->sense_resid,
+       &error_code, &sense_key, &asc, &ascq, /*show_errors*/ 1);
+
+     debug(3, "sense_len=%d rcnt=%d sense_resid=%d dsl=%d error_code=%x flags=%x",
+	   sense_len,
+	   ntohl(pp->ipdu.scsi_rsp.rcnt), scsi->sense_resid,
+	   pp->ds_len, error_code, sense_key);
+
+     if(mustfree)
+	  free(bp, M_ISCSI);
+
+     return 1;
+}
+
+/*
+ | Some information is from SAM draft.
+ */
+static void
+_scsi_done(isc_session_t *sp, u_int response, u_int status, union ccb *ccb, pduq_t *pq)
+{
+     struct ccb_hdr	*ccb_h = &ccb->ccb_h;
+
+     debug_called(8);
+
+     if(status || response) {
+	  sdebug(3, "response=%x status=%x ccb=%p pq=%p", response, status, ccb, pq);
+	  if(pq != NULL)
+	       sdebug(3, "mp=%p buf=%p len=%d", pq->mp, pq->buf, pq->len);
+     }
+     ccb_h->status = 0;
+     switch(response) {
+     case 0: // Command Completed at Target
+	  switch(status) {
+	  case 0:	// Good, all is ok
+	       ccb_h->status = CAM_REQ_CMP;
+	       break;
+	       
+	  case 0x02: 	// Check Condition
+	       if((pq != NULL) && (pq->mp != NULL) && getSenseData(status, ccb, pq))
+		    ccb_h->status |= CAM_AUTOSNS_VALID;
+
+	  case 0x14:	// Intermediate-Condition Met
+	  case 0x10:	// Intermediate
+	  case 0x04:	// Condition Met
+	       ccb_h->status |= CAM_SCSI_STATUS_ERROR;
+	       break;
+
+	  case 0x08:
+	       ccb_h->status = CAM_BUSY;
+	       break;
+
+	  case 0x18: // Reservation Conflict
+	  case 0x28: // Task Set Full
+	       ccb_h->status = CAM_REQUEUE_REQ;
+	       break;
+	  default:
+	       //case 0x22: // Command Terminated
+	       //case 0x30: // ACA Active
+	       //case 0x40: // Task Aborted
+	       ccb_h->status = CAM_REQ_CMP_ERR; //CAM_REQ_ABORTED;
+	  }
+	  break;
+
+     default:
+	  if((response >= 0x80) && (response <= 0xFF)) {
+	       // Vendor specific ...
+	  }
+     case 1: // target failure
+	  ccb_h->status = CAM_REQ_CMP_ERR; //CAM_REQ_ABORTED;
+	  break;
+     }
+     sdebug(5, "ccb_h->status=%x", ccb_h->status);
+
+     XPT_DONE(sp, ccb);
+}
+
+/*
+ | returns the lowest cmdseq that was not acked
+ */
+int
+iscsi_requeue(isc_session_t *sp)
+{
+     pduq_t	*pq;
+     u_int	i, n, last;
+
+     debug_called(8);
+     i = last = 0;
+     sp->flags |= ISC_HOLD;
+     while((pq = i_dqueue_hld(sp)) != NULL) {
+	  i++;
+	  if(pq->ccb != NULL) {
+	       _scsi_done(sp, 0, 0x28, pq->ccb, NULL);
+	       n = ntohl(pq->pdu.ipdu.bhs.CmdSN);
+	       if(last==0 || (last > n))
+		    last = n;
+	       sdebug(2, "last=%x n=%x", last, n);
+	  }
+	  pdu_free(sp->isc, pq);
+     }
+     sp->flags &= ~ISC_HOLD;
+     return i? last: sp->sn.cmd;
+}
+
+int
+i_pdu_flush(isc_session_t *sp)
+{
+     int	n = 0;
+     pduq_t	*pq;
+
+     debug_called(8);
+     while((pq = i_dqueue_rsp(sp)) != NULL) {
+	  pdu_free(sp->isc, pq);
+	  n++;
+     }
+     while((pq = i_dqueue_rsv(sp)) != NULL) {
+	  pdu_free(sp->isc, pq);
+	  n++;
+     }
+     while((pq = i_dqueue_snd(sp, -1)) != NULL) {
+	  pdu_free(sp->isc, pq);
+	  n++;
+     }
+     while((pq = i_dqueue_hld(sp)) != NULL) {
+	  pdu_free(sp->isc, pq);
+	  n++;
+     }
+     while((pq = i_dqueue_wsnd(sp)) != NULL) {
+	  pdu_free(sp->isc, pq);
+	  n++;
+     }
+     if(n != 0)
+	  xdebug("%d pdus recovered, should have been ZERO!", n);
+     return n;
+}
+/*
+ | called from ism_destroy.
+ */
+void
+iscsi_cleanup(isc_session_t *sp)
+{
+     pduq_t *pq, *pqtmp;
+
+     debug_called(8);
+
+     TAILQ_FOREACH_SAFE(pq, &sp->hld, pq_link, pqtmp) {
+	  sdebug(3, "hld pq=%p", pq);
+	  if(pq->ccb)
+	       _scsi_done(sp, 1, 0x40, pq->ccb, NULL);
+	  TAILQ_REMOVE(&sp->hld, pq, pq_link);
+	  if(pq->buf) {
+	       free(pq->buf, M_ISCSIBUF);
+	       pq->buf = NULL;
+	  }
+	  pdu_free(sp->isc, pq);
+     }
+     while((pq = i_dqueue_snd(sp, BIT(0)|BIT(1)|BIT(2))) != NULL) {
+	  sdebug(3, "pq=%p", pq);
+	  if(pq->ccb)
+	       _scsi_done(sp, 1, 0x40, pq->ccb, NULL);
+	  if(pq->buf) {
+	       free(pq->buf, M_ISCSIBUF);
+	       pq->buf = NULL;
+	  }
+	  pdu_free(sp->isc, pq);
+     }
+
+     wakeup(&sp->rsp);
+}
+
+void
+iscsi_done(isc_session_t *sp, pduq_t *opq, pduq_t *pq)
+{
+     pdu_t		*pp = &pq->pdu;
+     scsi_rsp_t		*cmd = &pp->ipdu.scsi_rsp;
+
+     debug_called(8);
+
+     _scsi_done(sp, cmd->response, cmd->status, opq->ccb, pq);
+
+     pdu_free(sp->isc, opq);
+}
+
+// see RFC 3720, 10.9.1 page 146
+/*
+ | NOTE:
+ | the call to isc_stop_receiver is a kludge,
+ | instead, it should be handled by the userland controller,
+ | but that means that there should be a better way, other than
+ | sending a signal. Somehow, this packet should be supplied to
+ | the userland via read.
+ */
+void
+iscsi_async(isc_session_t *sp, pduq_t *pq)
+{
+     pdu_t		*pp = &pq->pdu;
+     async_t		*cmd = &pp->ipdu.async;
+
+     debug_called(8);
+
+     sdebug(3, "asyncevent=0x%x asyncVCode=0x%0x", cmd->asyncEvent, cmd->asyncVCode);
+     switch(cmd->asyncEvent) {
+     case 0: // check status ...
+	  break;
+
+     case 1: // target request logout
+	  isc_stop_receiver(sp);	// XXX: temporary solution
+	  break;
+
+     case 2: // target indicates it wants to drop connection
+	  isc_stop_receiver(sp);	// XXX: temporary solution
+	  break;
+
+     case 3: // target indicates it will drop all connections.
+	  isc_stop_receiver(sp);	// XXX: temporary solution
+	  break;
+
+     case 4: // target request parameter negotiation
+	  break;
+
+     default:
+	  break;
+     }
+}
+
+void
+iscsi_reject(isc_session_t *sp, pduq_t *opq, pduq_t *pq)
+{
+     union ccb 		*ccb = opq->ccb;
+     //reject_t		*reject = &pq->pdu.ipdu.reject;
+
+     debug_called(8);
+     //XXX: check RFC 10.17.1 (page 176)
+     ccb->ccb_h.status = CAM_REQ_ABORTED;
+     XPT_DONE(sp, ccb);
+ 
+     pdu_free(sp->isc, opq);
+}
+
+/*
+ | deal with lun
+ */
+static int
+dwl(isc_session_t *sp, int lun, u_char *lp)
+{
+     debug_called(8);
+     sdebug(4, "lun=%d", lun);
+     /*
+      | mapping LUN to iSCSI LUN
+      | check the SAM-2 specs
+      | hint: maxLUNS is a small number, cam's LUN is 32bits
+      | iSCSI is 64bits, scsi is ?
+      */
+     // XXX: check if this will pass the endian test
+     if(lun < 256) {
+	  lp[0] = 0;
+	  lp[1] = lun;
+     } else
+     if(lun < 16384) {
+	  lp[0] = (1 << 5) | ((lun >> 8) & 0x3f);
+	  lp[1] = lun & 0xff;
+     } 
+     else {
+	  xdebug("lun %d: is unsupported!", lun);
+	  return -1;
+     }
+
+     return 0;
+}
+
+/*
+ | encapsulate the scsi command and 
+ */
+int
+scsi_encap(struct cam_sim *sim, union ccb *ccb)
+{
+     isc_session_t	*sp = cam_sim_softc(sim);
+     struct ccb_scsiio	*csio = &ccb->csio;
+     struct ccb_hdr	*ccb_h = &ccb->ccb_h;
+     pduq_t		*pq;
+     scsi_req_t		*cmd;
+
+     debug_called(8);
+
+     debug(4, "ccb->sp=%p", ccb_h->spriv_ptr0);
+     sp = ccb_h->spriv_ptr0;
+
+     if((pq = pdu_alloc(sp->isc, M_NOWAIT)) == NULL) {
+	  debug(2, "ccb->sp=%p", ccb_h->spriv_ptr0);
+	  sdebug(1, "pdu_alloc failed sc->npdu_max=%d npdu_alloc=%d",
+		 sp->isc->npdu_max, sp->isc->npdu_alloc);
+	  while((pq = pdu_alloc(sp->isc, M_NOWAIT)) == NULL) {
+	       sdebug(2, "waiting...");
+#if __FreeBSD_version >= 700000
+	       pause("isc_encap", 5*hz);
+#else
+	       tsleep(sp->isc, 0, "isc_encap", 5*hz);
+#endif
+	  }
+     }
+     cmd = &pq->pdu.ipdu.scsi_req;
+     cmd->opcode = ISCSI_SCSI_CMD;
+     cmd->F = 1;
+#if 0
+// this breaks at least Isilon's iscsi target.
+     /*
+      | map tag option, default is UNTAGGED
+      */
+     switch(csio->tag_action) {
+     case MSG_SIMPLE_Q_TAG:	cmd->attr = iSCSI_TASK_SIMPLE;	break;
+     case MSG_HEAD_OF_Q_TAG:	cmd->attr = iSCSI_TASK_HOFQ;	break;
+     case MSG_ORDERED_Q_TAG:	cmd->attr = iSCSI_TASK_ORDER;	break;
+     case MSG_ACA_TASK:		cmd->attr = iSCSI_TASK_ACA;	break;
+     }
+#else
+     cmd->attr = iSCSI_TASK_SIMPLE;
+#endif
+
+     dwl(sp, ccb_h->target_lun, (u_char *)&cmd->lun);
+
+     if((ccb_h->flags & CAM_CDB_POINTER) != 0) {
+	  if((ccb_h->flags & CAM_CDB_PHYS) == 0) {
+	       if(csio->cdb_len > 16) {
+		    sdebug(3, "oversize cdb %d > 16", csio->cdb_len);
+		    goto invalid;
+	       }
+	  }
+	  else {
+	       sdebug(3, "not phys");
+	       goto invalid;
+	  }
+     }
+
+     if(csio->cdb_len > sizeof(cmd->cdb))
+	  xdebug("guevalt! %d > %ld", csio->cdb_len, (long)sizeof(cmd->cdb));
+
+     memcpy(cmd->cdb,
+	    ccb_h->flags & CAM_CDB_POINTER? csio->cdb_io.cdb_ptr: csio->cdb_io.cdb_bytes,
+	    csio->cdb_len);
+
+     cmd->W = (ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT;
+     cmd->R = (ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN;
+     cmd->edtlen = htonl(csio->dxfer_len);
+
+     pq->ccb = ccb;
+     /*
+      | place it in the out queue
+      */
+     if(isc_qout(sp, pq) == 0)
+	  return 1; 
+ invalid:
+     ccb->ccb_h.status = CAM_REQ_INVALID;
+     pdu_free(sp->isc, pq);
+
+     return 0;
+}
+
+int
+scsi_decap(isc_session_t *sp, pduq_t *opq, pduq_t *pq)
+{
+     union ccb 		*ccb = opq->ccb;
+     struct ccb_scsiio	*csio = &ccb->csio;
+     pdu_t		*opp = &opq->pdu;
+     bhs_t		*bhp = &opp->ipdu.bhs;
+     
+     debug_called(8);
+     sdebug(6, "pq=%p opq=%p bhp->opcode=0x%x len=%d",
+	    pq, opq, bhp->opcode, pq->pdu.ds_len);
+     if(ccb == NULL) {
+	  sdebug(1, "itt=0x%x pq=%p opq=%p bhp->opcode=0x%x len=%d",
+		 ntohl(pq->pdu.ipdu.bhs.itt),
+		 pq, opq, bhp->opcode, pq->pdu.ds_len);
+	  xdebug("%d] ccb == NULL!", sp->sid);
+	  return 0;
+     }
+     if(pq->pdu.ds_len != 0) {
+	  switch(bhp->opcode) {
+	  case ISCSI_SCSI_CMD: {
+	       scsi_req_t *cmd = &opp->ipdu.scsi_req;
+	       sdebug(5, "itt=0x%x opcode=%x R=%d",
+		      ntohl(pq->pdu.ipdu.bhs.itt),
+		      pq->pdu.ipdu.bhs.opcode, cmd->R);
+
+	       switch(pq->pdu.ipdu.bhs.opcode) {
+	       case ISCSI_READ_DATA: // SCSI Data in
+	       {
+		    caddr_t	bp = NULL; // = mtod(pq->mp, caddr_t);
+		    data_in_t 	*rcmd = &pq->pdu.ipdu.data_in;
+
+		    if(cmd->R) {
+			 sdebug(5, "copy to=%p from=%p l1=%d l2=%d mp@%p",
+				csio->data_ptr, bp? mtod(pq->mp, caddr_t): 0,
+				ntohl(cmd->edtlen), pq->pdu.ds_len, pq->mp);
+			 if(ntohl(cmd->edtlen) >= pq->pdu.ds_len) {
+			      int	offset, len = pq->pdu.ds_len;
+
+			      if(pq->mp != NULL) {
+				   caddr_t		dp;
+
+				   offset = ntohl(rcmd->bo);
+				   dp = csio->data_ptr + offset;
+				   i_mbufcopy(pq->mp, dp, len);
+			      }
+			 }
+			 else {
+			      xdebug("edtlen=%d < ds_len=%d",
+				     ntohl(cmd->edtlen), pq->pdu.ds_len);
+			 }
+		    }
+		    if(rcmd->S) {
+			 /*
+			  | contains also the SCSI Status
+			  */
+			 _scsi_done(sp, 0, rcmd->status, opq->ccb, NULL);
+			 return 0;
+		    } else
+			 return 1;
+	       }
+	       break;
+	       }
+	  }
+	  default:
+	       sdebug(3, "opcode=%02x", bhp->opcode);
+	       break;
+	  }
+     }
+     /*
+      | XXX: error ...
+      */
+     return 1;
+}


Property changes on: trunk/sys/dev/iscsi_initiator/iscsi_subr.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sys/dev/iscsi_initiator/iscsivar.h
===================================================================
--- trunk/sys/dev/iscsi_initiator/iscsivar.h	                        (rev 0)
+++ trunk/sys/dev/iscsi_initiator/iscsivar.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -0,0 +1,600 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2005-2011 Daniel Braniss <danny at cs.huji.ac.il>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/sys/dev/iscsi_initiator/iscsivar.h 234233 2012-04-13 18:21:56Z jpaetzel $
+ */
+
+/*
+ | $Id: iscsivar.h 743 2009-08-08 10:54:53Z danny $
+ */
+#define ISCSI_MAX_LUNS		128	// don't touch this
+#if ISCSI_MAX_LUNS > 8
+/*
+ | for this to work 
+ | sysctl kern.cam.cam_srch_hi=1
+ */
+#endif
+
+#ifndef ISCSI_INITIATOR_DEBUG
+#define ISCSI_INITIATOR_DEBUG 1
+#endif
+
+#ifdef ISCSI_INITIATOR_DEBUG
+extern int iscsi_debug;
+#define debug(level, fmt, args...)	do {if(level <= iscsi_debug)\
+	printf("%s: " fmt "\n", __func__ , ##args);} while(0)
+#define sdebug(level, fmt, args...)	do {if(level <= iscsi_debug)\
+     	printf("%d] %s: " fmt "\n", sp->sid, __func__ , ##args);} while(0)
+#define debug_called(level)		do {if(level <= iscsi_debug)\
+	printf("%s: called\n",  __func__);} while(0)
+#else
+#define debug(level, fmt, args...)
+#define debug_called(level)
+#define sdebug(level, fmt, args...)
+#endif /* ISCSI_INITIATOR_DEBUG */
+
+#define xdebug(fmt, args...)	printf(">>> %s: " fmt "\n", __func__ , ##args)
+
+#define MAX_SESSIONS	ISCSI_MAX_TARGETS
+#define MAX_PDUS	(MAX_SESSIONS*256) // XXX: at the moment this is arbitrary
+
+typedef uint32_t digest_t(const void *, int len, uint32_t ocrc);
+
+MALLOC_DECLARE(M_ISCSI);
+MALLOC_DECLARE(M_ISCSIBUF);
+
+#define ISOK2DIG(dig, pp)	((dig != NULL) && ((pp->ipdu.bhs.opcode & 0x1f) != ISCSI_LOGIN_CMD))
+
+#ifndef BIT
+#define BIT(n)	(1 <<(n))
+#endif
+
+#define ISC_SM_RUN	BIT(0)
+#define ISC_SM_RUNNING	BIT(1)
+
+#define ISC_LINK_UP	BIT(2)
+#define ISC_CON_RUN	BIT(3)
+#define ISC_CON_RUNNING	BIT(4)
+#define ISC_KILL	BIT(5)
+#define ISC_OQNOTEMPTY	BIT(6)
+#define ISC_OWAITING	BIT(7)
+#define ISC_FFPHASE	BIT(8)
+
+#define ISC_CAMDEVS	BIT(9)
+#define ISC_SCANWAIT	BIT(10)
+
+#define ISC_MEMWAIT	BIT(11)
+#define ISC_SIGNALED	BIT(12)
+
+#define ISC_HOLD	BIT(15)
+#define ISC_HOLDED	BIT(16)
+
+#define ISC_SHUTDOWN	BIT(31)
+
+/*
+ | some stats
+ */
+struct i_stats {
+     int	npdu;	// number of pdus malloc'ed.
+     int	nrecv;	// unprocessed received pdus
+     int	nsent;	// sent pdus
+
+     int	nrsp, max_rsp;
+     int	nrsv, max_rsv;
+     int	ncsnd, max_csnd;
+     int	nisnd, max_isnd;
+     int	nwsnd, max_wsnd;
+     int	nhld, max_hld;
+
+     struct bintime t_sent;
+     struct bintime t_recv;
+};
+
+/*
+ | one per 'session'
+ */
+
+typedef TAILQ_HEAD(, pduq) queue_t;
+
+typedef struct isc_session {
+     TAILQ_ENTRY(isc_session)	sp_link;
+     int		flags;
+     struct cdev	*dev;
+     struct socket	*soc;
+     struct file	*fp;
+     struct thread	*td;
+
+     struct proc 	*proc; // the userland process
+     int		signal;
+     struct proc 	*soc_proc;
+     struct proc	*stp;	// the sm thread
+
+     struct isc_softc	*isc;
+
+     digest_t   	*hdrDigest;     // the digest alg. if any
+     digest_t   	*dataDigest;    // the digest alg. if any
+
+     int		sid;		// Session ID
+     sn_t       	sn;             // sequence number stuff;
+     int		cws;		// current window size
+
+     int		target_nluns; // this and target_lun are
+				      // hopefully temporal till I
+				      // figure out a better way.
+     int		target_lun[ISCSI_MAX_LUNS/(sizeof(int)*8) + 1];
+
+     struct mtx		rsp_mtx;
+     struct mtx		rsv_mtx;
+     struct mtx		snd_mtx;
+     struct mtx		hld_mtx;
+     struct mtx		io_mtx;
+     queue_t		rsp;
+     queue_t		rsv;
+     queue_t		csnd;
+     queue_t		isnd;
+     queue_t		wsnd;
+     queue_t		hld;				
+
+     isc_opt_t		opt;	// negotiable values
+
+     struct i_stats	stats;
+     bhs_t		bhs;
+     struct uio		uio;
+     struct iovec	iov;
+     /*
+      | cam stuff
+      */
+     struct cam_sim	*cam_sim;
+     struct cam_path	*cam_path;
+     struct mtx		cam_mtx;
+     /*
+      | sysctl stuff
+      */
+     struct sysctl_ctx_list	clist;
+     struct sysctl_oid	*oid;
+     int	douio;	//XXX: turn on/off uio on read
+} isc_session_t;
+
+typedef struct pduq {
+     TAILQ_ENTRY(pduq)	pq_link;
+
+     caddr_t		buf;
+     u_int		len;	// the total length of the pdu
+     pdu_t		pdu;
+     union ccb		*ccb;
+
+     struct uio		uio;
+     struct iovec	iov[5];	// XXX: careful ...
+     struct mbuf	*mp;
+     struct bintime	ts;
+     queue_t		*pduq;		
+} pduq_t;
+/*
+ */
+struct isc_softc {
+     struct mtx		isc_mtx;
+     TAILQ_HEAD(,isc_session)	isc_sess;
+     int		nsess;
+     struct cdev	*dev;
+     char		isid[6];	// Initiator Session ID (48 bits)
+     struct unrhdr	*unit;
+     struct sx 		unit_sx;
+
+     uma_zone_t		pdu_zone;	// pool of free pdu's
+     TAILQ_HEAD(,pduq)	freepdu;
+
+#ifdef  ISCSI_INITIATOR_DEBUG
+     int		 npdu_alloc, npdu_max; // for instrumentation
+#endif
+#ifdef DO_EVENTHANDLER
+     eventhandler_tag	eh;
+#endif
+     /*
+      | sysctl stuff
+      */
+     struct sysctl_ctx_list	clist;
+     struct sysctl_oid		*oid;
+};
+
+#ifdef  ISCSI_INITIATOR_DEBUG
+extern struct mtx iscsi_dbg_mtx;
+#endif
+
+void	isc_start_receiver(isc_session_t *sp);
+void	isc_stop_receiver(isc_session_t *sp);
+
+int	isc_sendPDU(isc_session_t *sp, pduq_t *pq);
+int	isc_qout(isc_session_t *sp, pduq_t *pq);
+int	i_prepPDU(isc_session_t *sp, pduq_t *pq);
+
+int	ism_fullfeature(struct cdev *dev, int flag);
+
+int	i_pdu_flush(isc_session_t *sc);
+int	i_setopt(isc_session_t *sp, isc_opt_t *opt);
+void	i_freeopt(isc_opt_t *opt);
+
+int	ic_init(isc_session_t *sp);
+void	ic_destroy(isc_session_t *sp);
+void	ic_lost_target(isc_session_t *sp, int target);
+int	ic_getCamVals(isc_session_t *sp, iscsi_cam_t *cp);
+
+void	ism_recv(isc_session_t *sp, pduq_t *pq);
+int	ism_start(isc_session_t *sp);
+void	ism_restart(isc_session_t *sp);
+void	ism_stop(isc_session_t *sp);
+
+int	scsi_encap(struct cam_sim *sim, union ccb *ccb);
+int	scsi_decap(isc_session_t *sp, pduq_t *opq, pduq_t *pq);
+void	iscsi_r2t(isc_session_t *sp, pduq_t *opq, pduq_t *pq);
+void	iscsi_done(isc_session_t *sp, pduq_t *opq, pduq_t *pq);
+void	iscsi_reject(isc_session_t *sp, pduq_t *opq, pduq_t *pq);
+void	iscsi_async(isc_session_t *sp,  pduq_t *pq);
+void	iscsi_cleanup(isc_session_t *sp);
+int	iscsi_requeue(isc_session_t *sp);
+
+// Serial Number Arithmetic
+#define _MAXINCR	0x7FFFFFFF	// 2 ^ 31 - 1
+#define SNA_GT(i1, i2)	((i1 != i2) && (\
+	(i1 < i2 && i2 - i1 > _MAXINCR) ||\
+	(i1 > i2 && i1 - i2 < _MAXINCR))?1: 0)
+
+/*
+ | inlines
+ */
+#ifdef _CAM_CAM_XPT_SIM_H
+
+#if __FreeBSD_version <  600000
+#define CAM_LOCK(arg)
+#define CAM_ULOCK(arg)
+
+static __inline void
+XPT_DONE(isc_session_t *sp, union ccb *ccb)
+{
+     mtx_lock(&Giant);
+     xpt_done(ccb);
+     mtx_unlock(&Giant);
+}
+#elif __FreeBSD_version >= 700000
+#define CAM_LOCK(arg)	mtx_lock(&arg->cam_mtx)
+#define CAM_UNLOCK(arg)	mtx_unlock(&arg->cam_mtx)
+
+static __inline void
+XPT_DONE(isc_session_t *sp, union ccb *ccb)
+{
+     CAM_LOCK(sp);
+     xpt_done(ccb);
+     CAM_UNLOCK(sp);
+}
+#else
+//__FreeBSD_version >= 600000
+#define CAM_LOCK(arg)
+#define CAM_UNLOCK(arg)
+#define XPT_DONE(ignore, arg)	xpt_done(arg)
+#endif
+
+#endif /* _CAM_CAM_XPT_SIM_H */
+
+static __inline pduq_t *
+pdu_alloc(struct isc_softc *isc, int wait)
+{
+     pduq_t	*pq;
+
+     pq = (pduq_t *)uma_zalloc(isc->pdu_zone, wait /* M_WAITOK or M_NOWAIT*/);
+     if(pq == NULL) {
+	  debug(7, "out of mem");
+	  return NULL;
+     }
+#ifdef ISCSI_INITIATOR_DEBUG
+     mtx_lock(&iscsi_dbg_mtx);
+     isc->npdu_alloc++;
+     if(isc->npdu_alloc > isc->npdu_max)
+	  isc->npdu_max = isc->npdu_alloc;
+     mtx_unlock(&iscsi_dbg_mtx);
+#endif
+     memset(pq, 0, sizeof(pduq_t));
+
+     return pq;
+}
+
+static __inline void
+pdu_free(struct isc_softc *isc, pduq_t *pq)
+{
+     if(pq->mp)
+	  m_freem(pq->mp);
+#ifdef NO_USE_MBUF
+     if(pq->buf != NULL)
+	  free(pq->buf, M_ISCSIBUF);
+#endif
+     uma_zfree(isc->pdu_zone, pq);
+#ifdef ISCSI_INITIATOR_DEBUG
+     mtx_lock(&iscsi_dbg_mtx);
+     isc->npdu_alloc--;
+     mtx_unlock(&iscsi_dbg_mtx);
+#endif
+}
+
+static __inline void
+i_nqueue_rsp(isc_session_t *sp, pduq_t *pq)
+{
+     mtx_lock(&sp->rsp_mtx);
+     if(++sp->stats.nrsp > sp->stats.max_rsp)
+	  sp->stats.max_rsp = sp->stats.nrsp;
+     TAILQ_INSERT_TAIL(&sp->rsp, pq, pq_link);
+     mtx_unlock(&sp->rsp_mtx);
+}
+
+static __inline pduq_t *
+i_dqueue_rsp(isc_session_t *sp)
+{
+     pduq_t *pq;
+
+     mtx_lock(&sp->rsp_mtx);
+     if((pq = TAILQ_FIRST(&sp->rsp)) != NULL) {
+	  sp->stats.nrsp--;
+	  TAILQ_REMOVE(&sp->rsp, pq, pq_link);
+     }
+     mtx_unlock(&sp->rsp_mtx);
+
+     return pq;
+}
+
+static __inline void
+i_nqueue_rsv(isc_session_t *sp, pduq_t *pq)
+{
+     mtx_lock(&sp->rsv_mtx);
+     if(++sp->stats.nrsv > sp->stats.max_rsv)
+	  sp->stats.max_rsv = sp->stats.nrsv;
+     TAILQ_INSERT_TAIL(&sp->rsv, pq, pq_link);
+     mtx_unlock(&sp->rsv_mtx);
+}
+
+static __inline pduq_t *
+i_dqueue_rsv(isc_session_t *sp)
+{
+     pduq_t *pq;
+
+     mtx_lock(&sp->rsv_mtx);
+     if((pq = TAILQ_FIRST(&sp->rsv)) != NULL) {
+	  sp->stats.nrsv--;
+	  TAILQ_REMOVE(&sp->rsv, pq, pq_link);
+     }
+     mtx_unlock(&sp->rsv_mtx);
+
+     return pq;
+}
+
+static __inline void
+i_nqueue_csnd(isc_session_t *sp, pduq_t *pq)
+{
+     mtx_lock(&sp->snd_mtx);
+     if(++sp->stats.ncsnd > sp->stats.max_csnd)
+	  sp->stats.max_csnd = sp->stats.ncsnd;
+     TAILQ_INSERT_TAIL(&sp->csnd, pq, pq_link);
+     mtx_unlock(&sp->snd_mtx);
+}
+
+static __inline pduq_t *
+i_dqueue_csnd(isc_session_t *sp)
+{
+     pduq_t *pq;
+
+     mtx_lock(&sp->snd_mtx);
+     if((pq = TAILQ_FIRST(&sp->csnd)) != NULL) {
+	  sp->stats.ncsnd--;
+	  TAILQ_REMOVE(&sp->csnd, pq, pq_link);
+     }
+     mtx_unlock(&sp->snd_mtx);
+
+     return pq;
+}
+
+static __inline void
+i_nqueue_isnd(isc_session_t *sp, pduq_t *pq)
+{
+     mtx_lock(&sp->snd_mtx);
+     if(++sp->stats.nisnd > sp->stats.max_isnd)
+	  sp->stats.max_isnd = sp->stats.nisnd;
+     TAILQ_INSERT_TAIL(&sp->isnd, pq, pq_link);
+     mtx_unlock(&sp->snd_mtx);
+}
+
+static __inline pduq_t *
+i_dqueue_isnd(isc_session_t *sp)
+{
+     pduq_t *pq;
+
+     mtx_lock(&sp->snd_mtx);
+     if((pq = TAILQ_FIRST(&sp->isnd)) != NULL) {
+	  sp->stats.nisnd--;
+	  TAILQ_REMOVE(&sp->isnd, pq, pq_link);
+     }
+     mtx_unlock(&sp->snd_mtx);
+
+     return pq;
+}
+
+static __inline void
+i_nqueue_wsnd(isc_session_t *sp, pduq_t *pq)
+{
+     mtx_lock(&sp->snd_mtx);
+     if(++sp->stats.nwsnd > sp->stats.max_wsnd)
+	  sp->stats.max_wsnd = sp->stats.nwsnd;
+     TAILQ_INSERT_TAIL(&sp->wsnd, pq, pq_link);
+     mtx_unlock(&sp->snd_mtx);
+}
+
+static __inline pduq_t *
+i_dqueue_wsnd(isc_session_t *sp)
+{
+     pduq_t *pq;
+
+     mtx_lock(&sp->snd_mtx);
+     if((pq = TAILQ_FIRST(&sp->wsnd)) != NULL) {
+	  sp->stats.nwsnd--;
+	  TAILQ_REMOVE(&sp->wsnd, pq, pq_link);
+     }
+     mtx_unlock(&sp->snd_mtx);
+
+     return pq;
+}
+
+static __inline pduq_t *
+i_dqueue_snd(isc_session_t *sp, int which)
+{
+     pduq_t *pq;
+
+     pq = NULL;
+     mtx_lock(&sp->snd_mtx);
+     if((which & BIT(0)) && (pq = TAILQ_FIRST(&sp->isnd)) != NULL) {
+	  sp->stats.nisnd--;
+	  TAILQ_REMOVE(&sp->isnd, pq, pq_link);
+	  pq->pduq = &sp->isnd;	// remember where you came from
+     } else
+     if((which & BIT(1)) && (pq = TAILQ_FIRST(&sp->wsnd)) != NULL) {
+	  sp->stats.nwsnd--;
+	  TAILQ_REMOVE(&sp->wsnd, pq, pq_link);
+	  pq->pduq = &sp->wsnd;	// remember where you came from
+     } else
+     if((which & BIT(2)) && (pq = TAILQ_FIRST(&sp->csnd)) != NULL) {
+	  sp->stats.ncsnd--;
+	  TAILQ_REMOVE(&sp->csnd, pq, pq_link);
+	  pq->pduq = &sp->csnd;	// remember where you came from
+     }
+     mtx_unlock(&sp->snd_mtx);
+
+     return pq;
+}
+
+static __inline void
+i_rqueue_pdu(isc_session_t *sp, pduq_t *pq)
+{
+     mtx_lock(&sp->snd_mtx);
+     KASSERT(pq->pduq != NULL, ("pq->pduq is NULL"));
+     TAILQ_INSERT_TAIL(pq->pduq, pq, pq_link);
+     mtx_unlock(&sp->snd_mtx);     
+}
+
+/*
+ | Waiting for ACK (or something :-)
+ */
+static __inline void
+i_nqueue_hld(isc_session_t *sp, pduq_t *pq)
+{
+     getbintime(&pq->ts);
+     mtx_lock(&sp->hld_mtx);
+     if(++sp->stats.nhld > sp->stats.max_hld)
+	  sp->stats.max_hld = sp->stats.nhld;
+     TAILQ_INSERT_TAIL(&sp->hld, pq, pq_link);
+     mtx_unlock(&sp->hld_mtx);
+     return;
+}
+
+static __inline void
+i_remove_hld(isc_session_t *sp, pduq_t *pq)
+{
+     mtx_lock(&sp->hld_mtx);
+     sp->stats.nhld--;
+     TAILQ_REMOVE(&sp->hld, pq, pq_link);
+     mtx_unlock(&sp->hld_mtx);
+}
+
+static __inline pduq_t *
+i_dqueue_hld(isc_session_t *sp)
+{
+     pduq_t *pq;
+
+     mtx_lock(&sp->hld_mtx);
+     if((pq = TAILQ_FIRST(&sp->hld)) != NULL) {
+	  sp->stats.nhld--;
+	  TAILQ_REMOVE(&sp->hld, pq, pq_link);
+     }
+     mtx_unlock(&sp->hld_mtx);
+
+     return pq;
+}
+
+static __inline pduq_t *
+i_search_hld(isc_session_t *sp, int itt, int keep)
+{
+     pduq_t	*pq, *tmp;
+
+     pq = NULL;
+
+     mtx_lock(&sp->hld_mtx);
+     TAILQ_FOREACH_SAFE(pq, &sp->hld, pq_link, tmp) {
+	  if(pq->pdu.ipdu.bhs.itt == itt) {
+	       if(!keep) {
+		    sp->stats.nhld--;
+		    TAILQ_REMOVE(&sp->hld, pq, pq_link);
+	       }
+	       break;
+	  }
+     }
+     mtx_unlock(&sp->hld_mtx);
+
+     return pq;
+}
+
+static __inline void
+i_acked_hld(isc_session_t *sp, pdu_t *op)
+{
+     pduq_t	*pq, *tmp;
+     u_int exp = sp->sn.expCmd;
+     
+     pq = NULL;
+     mtx_lock(&sp->hld_mtx);
+     TAILQ_FOREACH_SAFE(pq, &sp->hld, pq_link, tmp) {
+	  if((op && op->ipdu.bhs.itt == pq->pdu.ipdu.bhs.itt)
+	     || (pq->ccb == NULL
+		 && (pq->pdu.ipdu.bhs.opcode != ISCSI_WRITE_DATA)
+		 && SNA_GT(exp, ntohl(pq->pdu.ipdu.bhs.ExpStSN)))) {
+	       sp->stats.nhld--;
+	       TAILQ_REMOVE(&sp->hld, pq, pq_link);
+	       pdu_free(sp->isc, pq);
+	  }
+     }
+     mtx_unlock(&sp->hld_mtx);
+}
+
+static __inline void
+i_mbufcopy(struct mbuf *mp, caddr_t dp, int len)
+{
+     struct mbuf *m;
+     caddr_t bp;
+
+     for(m = mp; m != NULL; m = m->m_next) {
+	  bp = mtod(m, caddr_t);
+	  /*
+	   | the pdu is word (4 octed) aligned
+	   | so len <= packet
+	   */
+	  memcpy(dp, bp, MIN(len, m->m_len));
+	  dp += m->m_len;
+	  len -= m->m_len;
+	  if(len <= 0)
+	       break;
+     }
+}


Property changes on: trunk/sys/dev/iscsi_initiator/iscsivar.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/sys/dev/iwi/if_iwi.c
===================================================================
--- trunk/sys/dev/iwi/if_iwi.c	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/iwi/if_iwi.c	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2004, 2005
  *      Damien Bergamini <damien.bergamini at free.fr>. All rights reserved.
@@ -28,6 +29,7 @@
  */
 
 #include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/sys/dev/iwi/if_iwi.c 264954 2014-04-25 22:19:18Z marius $");
 
 /*-
  * Intel(R) PRO/Wireless 2200BG/2225BG/2915ABG driver
@@ -218,7 +220,7 @@
 	DEVMETHOD(device_suspend,	iwi_suspend),
 	DEVMETHOD(device_resume,	iwi_resume),
 
-	{ 0, 0 }
+	DEVMETHOD_END
 };
 
 static driver_t iwi_driver = {
@@ -229,7 +231,7 @@
 
 static devclass_t iwi_devclass;
 
-DRIVER_MODULE(iwi, pci, iwi_driver, iwi_devclass, 0, 0);
+DRIVER_MODULE(iwi, pci, iwi_driver, iwi_devclass, NULL, NULL);
 
 MODULE_VERSION(iwi, 1);
 
@@ -256,15 +258,12 @@
 		if (pci_get_vendor(dev) == ident->vendor &&
 		    pci_get_device(dev) == ident->device) {
 			device_set_desc(dev, ident->name);
-			return 0;
+			return (BUS_PROBE_DEFAULT);
 		}
 	}
 	return ENXIO;
 }
 
-/* Base Address Register */
-#define IWI_PCI_BAR0	0x10
-
 static int
 iwi_attach(device_t dev)
 {
@@ -299,20 +298,13 @@
 	callout_init_mtx(&sc->sc_wdtimer, &sc->sc_mtx, 0);
 	callout_init_mtx(&sc->sc_rftimer, &sc->sc_mtx, 0);
 
-	if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) {
-		device_printf(dev, "chip is in D%d power mode "
-		    "-- setting to D0\n", pci_get_powerstate(dev));
-		pci_set_powerstate(dev, PCI_POWERSTATE_D0);
-	}
-
 	pci_write_config(dev, 0x41, 0, 1);
 
 	/* enable bus-mastering */
 	pci_enable_busmaster(dev);
 
-	sc->mem_rid = IWI_PCI_BAR0;
-	sc->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mem_rid,
-	    RF_ACTIVE);
+	i = PCIR_BAR(0);
+	sc->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &i, RF_ACTIVE);
 	if (sc->mem == NULL) {
 		device_printf(dev, "could not allocate memory resource\n");
 		goto fail;
@@ -321,8 +313,8 @@
 	sc->sc_st = rman_get_bustag(sc->mem);
 	sc->sc_sh = rman_get_bushandle(sc->mem);
 
-	sc->irq_rid = 0;
-	sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid,
+	i = 0;
+	sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &i,
 	    RF_ACTIVE | RF_SHAREABLE);
 	if (sc->irq == NULL) {
 		device_printf(dev, "could not allocate interrupt resource\n");
@@ -458,6 +450,8 @@
 	struct ifnet *ifp = sc->sc_ifp;
 	struct ieee80211com *ic = ifp->if_l2com;
 
+	bus_teardown_intr(dev, sc->irq, sc->sc_ih);
+
 	/* NB: do early to drain any pending tasks */
 	ieee80211_draintask(ic, &sc->sc_radiontask);
 	ieee80211_draintask(ic, &sc->sc_radiofftask);
@@ -479,10 +473,10 @@
 	iwi_free_tx_ring(sc, &sc->txq[3]);
 	iwi_free_rx_ring(sc, &sc->rxq);
 
-	bus_teardown_intr(dev, sc->irq, sc->sc_ih);
-	bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, sc->irq);
+	bus_release_resource(dev, SYS_RES_IRQ, rman_get_rid(sc->irq), sc->irq);
 
-	bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem);
+	bus_release_resource(dev, SYS_RES_MEMORY, rman_get_rid(sc->mem),
+	    sc->mem);
 
 	delete_unrhdr(sc->sc_unr);
 
@@ -1848,7 +1842,7 @@
 	} else
 		staid = 0;
 
-	if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
+	if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) {
 		k = ieee80211_crypto_encap(ni, m0);
 		if (k == NULL) {
 			m_freem(m0);

Modified: trunk/sys/dev/iwi/if_iwireg.h
===================================================================
--- trunk/sys/dev/iwi/if_iwireg.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/iwi/if_iwireg.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,6 @@
+/* $MidnightBSD$ */
+/*	$FreeBSD: stable/10/sys/dev/iwi/if_iwireg.h 170530 2007-06-11 03:36:55Z sam $	*/
+
 /*-
  * Copyright (c) 2004, 2005
  *      Damien Bergamini <damien.bergamini at free.fr>. All rights reserved.

Modified: trunk/sys/dev/iwi/if_iwivar.h
===================================================================
--- trunk/sys/dev/iwi/if_iwivar.h	2018-05-27 23:40:15 UTC (rev 10101)
+++ trunk/sys/dev/iwi/if_iwivar.h	2018-05-27 23:40:39 UTC (rev 10102)
@@ -1,3 +1,6 @@
+/* $MidnightBSD$ */
+/*	$FreeBSD: stable/10/sys/dev/iwi/if_iwivar.h 264954 2014-04-25 22:19:18Z marius $	*/
+
 /*-
  * Copyright (c) 2004, 2005
  *      Damien Bergamini <damien.bergamini at free.fr>. All rights reserved.
@@ -151,8 +154,6 @@
 	bus_space_tag_t		sc_st;
 	bus_space_handle_t	sc_sh;
 	void 			*sc_ih;
-	int			mem_rid;
-	int			irq_rid;
 
 	/*
 	 * The card needs external firmware images to work, which is made of a



More information about the Midnightbsd-cvs mailing list