138032Speter/*-
2261370Sgshapiro * SPDX-License-Identifier: BSD-3-Clause
364562Sgshapiro *
438032Speter * Copyright (c) 2001,2002,2003 S��ren Schmidt <sos@FreeBSD.org>
538032Speter * All rights reserved.
638032Speter *
738032Speter * Redistribution and use in source and binary forms, with or without
838032Speter * modification, are permitted provided that the following conditions
938032Speter * are met:
1038032Speter * 1. Redistributions of source code must retain the above copyright
1138032Speter *    notice, this list of conditions and the following disclaimer,
1238032Speter *    without modification, immediately at the beginning of the file.
1338032Speter * 2. Redistributions in binary form must reproduce the above copyright
1464562Sgshapiro *    notice, this list of conditions and the following disclaimer in the
15157001Sgshapiro *    documentation and/or other materials provided with the distribution.
1638032Speter * 3. The name of the author may not be used to endorse or promote products
17266711Sgshapiro *    derived from this software without specific prior written permission.
1864562Sgshapiro *
1938032Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2038032Speter * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2164562Sgshapiro * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2238032Speter * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2394334Sgshapiro * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2494334Sgshapiro * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2594334Sgshapiro * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2694334Sgshapiro * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2790792Sgshapiro * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2864562Sgshapiro * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2990792Sgshapiro */
3064562Sgshapiro
3164562Sgshapiro/* misc defines */
3264562SgshapiroMALLOC_DECLARE(M_PSTIOP);
33141858Sgshapiro#define I2O_IOP_OUTBOUND_FRAME_COUNT	32
34141858Sgshapiro#define I2O_IOP_OUTBOUND_FRAME_SIZE	0x20
3564562Sgshapiro
3664562Sgshapiro/* structure defs */
3790792Sgshapirostruct out_mfa_buf {
3864562Sgshapiro    u_int32_t	buf[I2O_IOP_OUTBOUND_FRAME_SIZE];
3990792Sgshapiro};
40244928Sgshapiro
4164562Sgshapirostruct iop_softc {
4290792Sgshapiro    struct resource		*r_mem;
4390792Sgshapiro    struct resource		*r_irq;
4490792Sgshapiro    caddr_t			ibase;
4590792Sgshapiro    caddr_t			obase;
4690792Sgshapiro    u_int32_t			phys_obase;
4738032Speter    struct i2o_registers	*reg;
4838032Speter    struct i2o_status_get_reply	*status;
4938032Speter    int				lct_count;
5038032Speter    struct i2o_lct_entry	*lct;
5138032Speter    int				ism;
5238032Speter    device_t			dev;
5338032Speter    struct mtx			mtx;
5438032Speter    int				outstanding;
5538032Speter    void			*handle;
5638032Speter    struct intr_config_hook	*iop_delayed_attach;
5738032Speter};
5838032Speter
5938032Speter/* structure at start of IOP shared mem */
6038032Speterstruct i2o_registers {
6138032Speter    volatile u_int32_t	apic_select;
6238032Speter    volatile u_int32_t	reserved0;
6338032Speter    volatile u_int32_t	apic_winreg;
6438032Speter    volatile u_int32_t	reserved1;
6538032Speter    volatile u_int32_t	iqueue_reg0;
6638032Speter    volatile u_int32_t	iqueue_reg1;
6738032Speter    volatile u_int32_t	oqueue_reg0;
6838032Speter    volatile u_int32_t	oqueue_reg1;
6938032Speter    volatile u_int32_t	iqueue_event;
7038032Speter    volatile u_int32_t	iqueue_intr_status;
7138032Speter    volatile u_int32_t	iqueue_intr_mask;
7238032Speter    volatile u_int32_t	oqueue_event;
7338032Speter    volatile u_int32_t	oqueue_intr_status;
7464562Sgshapiro    volatile u_int32_t	oqueue_intr_mask;
7538032Speter#define I2O_OUT_INTR_QUEUE				0x08
7638032Speter#define I2O_OUT_INTR_BELL				0x04
7738032Speter#define I2O_OUT_INTR_MSG1				0x02
7890792Sgshapiro#define I2O_OUT_INTR_MSG0				0x01
7938032Speter
8038032Speter    volatile u_int64_t	reserved2;
8138032Speter    volatile u_int32_t	iqueue;
8238032Speter    volatile u_int32_t	oqueue;
8338032Speter    volatile u_int64_t	reserved3;
8438032Speter    volatile u_int64_t	mac_addr;
8538032Speter    volatile u_int32_t	ip_addr;
8638032Speter    volatile u_int32_t	ip_mask;
8738032Speter};
8838032Speter
8990792Sgshapiro/* Scatter/Gather List management  */
9038032Speterstruct i2o_sgl {
9190792Sgshapiro    u_int32_t		count:24;
9290792Sgshapiro#define I2O_SGL_CNT_MASK				0xffffff
9390792Sgshapiro
9438032Speter    u_int32_t		flags:8;
9590792Sgshapiro#define I2O_SGL_SIMPLE					0x10
9638032Speter#define I2O_SGL_PAGELIST				0x20
9738032Speter#define I2O_SGL_CHAIN					0x30
9838032Speter#define I2O_SGL_ATTRIBUTE				0x7c
9938032Speter#define I2O_SGL_BC0					0x01
10038032Speter#define I2O_SGL_BC1					0x02
10138032Speter#define I2O_SGL_DIR					0x04
10238032Speter#define I2O_SGL_LA					0x08
10338032Speter#define I2O_SGL_EOB					0x40
10438032Speter#define I2O_SGL_END					0x80
10538032Speter
10638032Speter    u_int32_t		phys_addr[1];
10738032Speter} __packed;
10838032Speter
10938032Speter#define I2O_SGL_MAX_SEGS	((I2O_IOP_OUTBOUND_FRAME_SIZE - (8 + 2)) + 1)
11038032Speter
11138032Speter/* i2o command codes */
11238032Speter#define I2O_UTIL_NOP					0x00
11338032Speter#define I2O_UTIL_PARAMS_GET				0x06
11438032Speter#define I2O_UTIL_CLAIM					0x09
11538032Speter#define I2O_UTIL_CONFIG_DIALOG				0x10
11638032Speter#define I2O_UTIL_EVENT_REGISTER				0x13
11738032Speter#define I2O_BSA_BLOCK_READ				0x30
11838032Speter#define I2O_BSA_BLOCK_WRITE				0x31
11938032Speter#define I2O_BSA_CACHE_FLUSH				0x37
12038032Speter#define I2O_EXEC_STATUS_GET				0xa0
12138032Speter#define I2O_EXEC_OUTBOUND_INIT				0xa1
12238032Speter#define I2O_EXEC_LCT_NOTIFY				0xa2
12338032Speter#define I2O_EXEC_SYSTAB_SET				0xa3
12490792Sgshapiro#define I2O_EXEC_IOP_RESET				0xbd
12538032Speter#define I2O_EXEC_SYS_ENABLE				0xd1
126132943Sgshapiro#define I2O_PRIVATE_MESSAGE				0xff
12790792Sgshapiro
12838032Speter/* basic message layout */
12990792Sgshapirostruct i2o_basic_message {
130132943Sgshapiro    u_int8_t		version:4;
13138032Speter    u_int8_t		offset:4;
13238032Speter    u_int8_t		message_flags;
13338032Speter    u_int16_t		message_size;
13438032Speter    u_int32_t		target_address:12;
13538032Speter    u_int32_t		initiator_address:12;
13638032Speter    u_int32_t		function:8;
13738032Speter    u_int32_t		initiator_context;
13838032Speter    u_int32_t		transaction_context;
13938032Speter} __packed;
14038032Speter
14138032Speter/* basic reply layout */
14238032Speterstruct i2o_single_reply {
14338032Speter    u_int8_t		version_offset;
14438032Speter    u_int8_t		message_flags;
14577349Sgshapiro#define I2O_MESSAGE_FLAGS_STATIC			0x01
14677349Sgshapiro#define I2O_MESSAGE_FLAGS_64BIT				0x02
14777349Sgshapiro#define I2O_MESSAGE_FLAGS_MULTIPLE			0x10
14877349Sgshapiro#define I2O_MESSAGE_FLAGS_FAIL				0x20
14977349Sgshapiro#define I2O_MESSAGE_FLAGS_LAST				0x40
15077349Sgshapiro#define I2O_MESSAGE_FLAGS_REPLY				0x80
15177349Sgshapiro
15277349Sgshapiro    u_int16_t		message_size;
15338032Speter    u_int32_t		target_address:12;
15490792Sgshapiro    u_int32_t		initiator_address:12;
15538032Speter    u_int32_t		function:8;
15664562Sgshapiro    u_int32_t		initiator_context;
15777349Sgshapiro    u_int32_t		transaction_context;
15877349Sgshapiro    u_int16_t		detailed_status;
15977349Sgshapiro#define I2O_DETAIL_STATUS_SUCCESS			0x0000
16077349Sgshapiro#define I2O_DETAIL_STATUS_BAD_KEY			0x0002
16164562Sgshapiro#define I2O_DETAIL_STATUS_TCL_ERROR			0x0003
16264562Sgshapiro#define I2O_DETAIL_STATUS_REPLY_BUFFER_FULL		0x0004
16364562Sgshapiro#define I2O_DETAIL_STATUS_NO_SUCH_PAGE			0x0005
16464562Sgshapiro#define I2O_DETAIL_STATUS_INSUFFICIENT_RESOURCE_SOFT	0x0006
16564562Sgshapiro#define I2O_DETAIL_STATUS_INSUFFICIENT_RESOURCE_HARD	0x0007
16664562Sgshapiro#define I2O_DETAIL_STATUS_CHAIN_BUFFER_TOO_LARGE	0x0009
16777349Sgshapiro#define I2O_DETAIL_STATUS_UNSUPPORTED_FUNCTION		0x000a
16864562Sgshapiro#define I2O_DETAIL_STATUS_DEVICE_LOCKED			0x000b
16938032Speter#define I2O_DETAIL_STATUS_DEVICE_RESET			0x000c
17038032Speter#define I2O_DETAIL_STATUS_INAPPROPRIATE_FUNCTION	0x000d
17138032Speter#define I2O_DETAIL_STATUS_INVALID_INITIATOR_ADDRESS	0x000e
17238032Speter#define I2O_DETAIL_STATUS_INVALID_MESSAGE_FLAGS		0x000f
17338032Speter#define I2O_DETAIL_STATUS_INVALID_OFFSET		0x0010
17438032Speter#define I2O_DETAIL_STATUS_INVALID_PARAMETER		0x0011
17564562Sgshapiro#define I2O_DETAIL_STATUS_INVALID_REQUEST		0x0012
17638032Speter#define I2O_DETAIL_STATUS_INVALID_TARGET_ADDRESS	0x0013
17738032Speter#define I2O_DETAIL_STATUS_MESSAGE_TOO_LARGE		0x0014
17838032Speter#define I2O_DETAIL_STATUS_MESSAGE_TOO_SMALL		0x0015
17938032Speter#define I2O_DETAIL_STATUS_MISSING_PARAMETER		0x0016
18038032Speter#define I2O_DETAIL_STATUS_TIMEOUT			0x0017
18138032Speter#define I2O_DETAIL_STATUS_UNKNOWN_ERROR			0x0018
18264562Sgshapiro#define I2O_DETAIL_STATUS_UNKNOWN_FUNCTION		0x0019
18338032Speter#define I2O_DETAIL_STATUS_UNSUPPORTED_VERSION		0x001a
18438032Speter#define I2O_DETAIL_STATUS_DEVICE_BUSY			0x001b
18538032Speter#define I2O_DETAIL_STATUS_DEVICE_NOT_AVAILABLE		0x001c
18690792Sgshapiro
187132943Sgshapiro    u_int8_t		retry_count;
18838032Speter    u_int8_t		status;
18964562Sgshapiro#define I2O_REPLY_STATUS_SUCCESS			0x00
19038032Speter#define I2O_REPLY_STATUS_ABORT_DIRTY			0x01
19138032Speter#define I2O_REPLY_STATUS_ABORT_NO_DATA_TRANSFER		0x02
19238032Speter#define I2O_REPLY_STATUS_ABORT_PARTIAL_TRANSFER		0x03
19338032Speter#define I2O_REPLY_STATUS_ERROR_DIRTY			0x04
19438032Speter#define I2O_REPLY_STATUS_ERROR_NO_DATA_TRANSFER		0x05
19538032Speter#define I2O_REPLY_STATUS_ERROR_PARTIAL_TRANSFER		0x06
19638032Speter#define I2O_REPLY_STATUS_PROCESS_ABORT_DIRTY		0x08
19738032Speter#define I2O_REPLY_STATUS_PROCESS_ABORT_NO_DATA_TRANSFER 0x09
19838032Speter#define I2O_REPLY_STATUS_PROCESS_ABORT_PARTIAL_TRANSFER 0x0a
19938032Speter#define I2O_REPLY_STATUS_TRANSACTION_ERROR		0x0b
20038032Speter#define I2O_REPLY_STATUS_PROGRESS_REPORT		0x80
20138032Speter
20238032Speter    u_int32_t		donecount;
20338032Speter} __packed;
20438032Speter
20538032Speterstruct i2o_fault_reply {
20638032Speter    u_int8_t		version_offset;
20738032Speter    u_int8_t		message_flags;
20838032Speter    u_int16_t		message_size;
20938032Speter    u_int32_t		target_address:12;
21064562Sgshapiro    u_int32_t		initiator_address:12;
21138032Speter    u_int32_t		function:8;
21238032Speter    u_int32_t		initiator_context;
21338032Speter    u_int32_t		transaction_context;
21438032Speter    u_int8_t		lowest_version;
21538032Speter    u_int8_t		highest_version;
21638032Speter    u_int8_t		severity;
21790792Sgshapiro#define I2O_SEVERITY_FORMAT_ERROR			0x01
218132943Sgshapiro#define I2O_SEVERITY_PATH_ERROR				0x02
21938032Speter#define I2O_SEVERITY_PATH_STATE				0x04
22038032Speter#define I2O_SEVERITY_CONGESTION				0x08
22138032Speter
22238032Speter    u_int8_t		failure_code;
22338032Speter#define I2O_FAILURE_CODE_TRANSPORT_SERVICE_SUSPENDED	0x81
22438032Speter#define I2O_FAILURE_CODE_TRANSPORT_SERVICE_TERMINATED	0x82
22538032Speter#define I2O_FAILURE_CODE_TRANSPORT_CONGESTION		0x83
22690792Sgshapiro#define I2O_FAILURE_CODE_TRANSPORT_FAIL			0x84
22790792Sgshapiro#define I2O_FAILURE_CODE_TRANSPORT_STATE_ERROR		0x85
22838032Speter#define I2O_FAILURE_CODE_TRANSPORT_TIME_OUT		0x86
22938032Speter#define I2O_FAILURE_CODE_TRANSPORT_ROUTING_FAILURE	0x87
23038032Speter#define I2O_FAILURE_CODE_TRANSPORT_INVALID_VERSION	0x88
23138032Speter#define I2O_FAILURE_CODE_TRANSPORT_INVALID_OFFSET	0x89
23238032Speter#define I2O_FAILURE_CODE_TRANSPORT_INVALID_MSG_FLAGS	0x8A
23338032Speter#define I2O_FAILURE_CODE_TRANSPORT_FRAME_TOO_SMALL	0x8B
23438032Speter#define I2O_FAILURE_CODE_TRANSPORT_FRAME_TOO_LARGE	0x8C
23590792Sgshapiro#define I2O_FAILURE_CODE_TRANSPORT_INVALID_TARGET_ID	0x8D
236132943Sgshapiro#define I2O_FAILURE_CODE_TRANSPORT_INVALID_INITIATOR_ID 0x8E
23738032Speter#define I2O_FAILURE_CODE_TRANSPORT_INVALID_INITIATOR_CONTEXT	0x8F
23864562Sgshapiro#define I2O_FAILURE_CODE_TRANSPORT_UNKNOWN_FAILURE	0xFF
23938032Speter
24038032Speter    u_int32_t		failing_iop_id:12;
24190792Sgshapiro    u_int32_t		reserved:4;
24238032Speter    u_int32_t		failing_host_unit_id:16;
24338032Speter    u_int32_t		age_limit;
24438032Speter    u_int64_t		preserved_mfa;
24538032Speter} __packed;
24690792Sgshapiro
247132943Sgshapirostruct i2o_exec_iop_reset_message {
24838032Speter    u_int8_t		version_offset;
24938032Speter    u_int8_t		message_flags;
25038032Speter    u_int16_t		message_size;
25138032Speter    u_int32_t		target_address:12;
25238032Speter    u_int32_t		initiator_address:12;
25338032Speter    u_int32_t		function:8;
25438032Speter    u_int8_t		reserved[16];
25590792Sgshapiro    u_int32_t		status_word_low_addr;
25690792Sgshapiro    u_int32_t		status_word_high_addr;
25738032Speter} __packed;
25838032Speter
25938032Speterstruct i2o_exec_status_get_message {
26038032Speter    u_int8_t		version_offset;
26138032Speter    u_int8_t		message_flags;
26238032Speter    u_int16_t		message_size;
26338032Speter    u_int32_t		target_address:12;
26490792Sgshapiro    u_int32_t		initiator_address:12;
26590792Sgshapiro    u_int32_t		function:8;
26638032Speter    u_int8_t		reserved[16];
26738032Speter    u_int32_t		reply_buf_low_addr;
26838032Speter    u_int32_t		reply_buf_high_addr;
26938032Speter    u_int32_t		reply_buf_length;
27038032Speter} __packed;
27138032Speter
27238032Speterstruct i2o_status_get_reply {
27390792Sgshapiro    u_int16_t		organization_id;
27490792Sgshapiro    u_int16_t		reserved;
27538032Speter    u_int32_t		iop_id:12;
27638032Speter    u_int32_t		reserved1:4;
27738032Speter    u_int32_t		host_unit_id:16;
27838032Speter    u_int32_t		segment_number:12;
27938032Speter    u_int32_t		i2o_version:4;
28090792Sgshapiro    u_int32_t		iop_state:8;
28190792Sgshapiro#define I2O_IOP_STATE_INITIALIZING			0x01
28238032Speter#define I2O_IOP_STATE_RESET				0x02
28338032Speter#define I2O_IOP_STATE_HOLD				0x04
28438032Speter#define I2O_IOP_STATE_READY				0x05
28538032Speter#define I2O_IOP_STATE_OPERATIONAL			0x08
28690792Sgshapiro#define I2O_IOP_STATE_FAILED				0x10
28738032Speter#define I2O_IOP_STATE_FAULTED				0x11
28838032Speter
28938032Speter    u_int32_t		messenger_type:8;
29064562Sgshapiro    u_int16_t		inbound_mframe_size;
29164562Sgshapiro    u_int8_t		init_code;
29264562Sgshapiro    u_int8_t		reserved2;
29390792Sgshapiro    u_int32_t		max_inbound_mframes;
29464562Sgshapiro    u_int32_t		current_ibound_mframes;
29564562Sgshapiro    u_int32_t		max_outbound_mframes;
29664562Sgshapiro    u_int8_t		product_idstring[24];
29764562Sgshapiro    u_int32_t		expected_lct_size;
29864562Sgshapiro    u_int32_t		iop_capabilities;
29964562Sgshapiro    u_int32_t		desired_private_memsize;
30064562Sgshapiro    u_int32_t		current_private_memsize;
30164562Sgshapiro    u_int32_t		current_private_membase;
30264562Sgshapiro    u_int32_t		desired_private_iosize;
30364562Sgshapiro    u_int32_t		current_private_iosize;
30464562Sgshapiro    u_int32_t		current_private_iobase;
30564562Sgshapiro    u_int8_t		reserved3[3];
30664562Sgshapiro    u_int8_t		sync_byte;
307132943Sgshapiro} __packed;
308132943Sgshapiro
30964562Sgshapirostruct i2o_exec_init_outqueue_message {
31090792Sgshapiro    u_int8_t		version_offset;
31190792Sgshapiro    u_int8_t		message_flags;
31264562Sgshapiro    u_int16_t		message_size;
31390792Sgshapiro    u_int32_t		target_address:12;
31464562Sgshapiro    u_int32_t		initiator_address:12;
31564562Sgshapiro    u_int32_t		function:8;
31664562Sgshapiro    u_int32_t		initiator_context;
31764562Sgshapiro    u_int32_t		transaction_context;
31864562Sgshapiro    u_int32_t		host_pagesize;
319132943Sgshapiro    u_int8_t		init_code;
32064562Sgshapiro    u_int8_t		reserved;
321132943Sgshapiro    u_int16_t		queue_framesize;
32290792Sgshapiro    struct i2o_sgl	sgl[2];
323132943Sgshapiro} __packed;
32464562Sgshapiro
32564562Sgshapiro#define I2O_EXEC_OUTBOUND_INIT_IN_PROGRESS		0x01
32664562Sgshapiro#define I2O_EXEC_OUTBOUND_INIT_REJECTED			0x02
32764562Sgshapiro#define I2O_EXEC_OUTBOUND_INIT_FAILED			0x03
32864562Sgshapiro#define I2O_EXEC_OUTBOUND_INIT_COMPLETE			0x04
32964562Sgshapiro
33090792Sgshapirostruct i2o_exec_systab_set_message {
33164562Sgshapiro    u_int8_t		version_offset;
33264562Sgshapiro    u_int8_t		message_flags;
33364562Sgshapiro    u_int16_t		message_size;
33464562Sgshapiro    u_int32_t		target_address:12;
33538032Speter    u_int32_t		initiator_address:12;
33638032Speter    u_int32_t		function:8;
33738032Speter    u_int32_t		initiator_context;
33838032Speter    u_int32_t		transaction_context;
33938032Speter    u_int32_t		iop_id:12;
34038032Speter#define I2O_EXEC_SYS_TAB_IOP_ID_LOCAL_IOP		0x000
34138032Speter#define I2O_EXEC_SYS_TAB_IOP_ID_LOCAL_HOST		0x001
34238032Speter#define I2O_EXEC_SYS_TAB_IOP_ID_UNKNOWN_IOP		0xfff
34338032Speter
34464562Sgshapiro    u_int32_t		reserved1:4;
34564562Sgshapiro    u_int32_t		host_unit_id:16;
34638032Speter#define I2O_EXEC_SYS_TAB_HOST_UNIT_ID_LOCAL_UNIT	0x0000
34738032Speter#define I2O_EXEC_SYS_TAB_HOST_UNIT_ID_UNKNOWN_UNIT	0xffff
34890792Sgshapiro
34964562Sgshapiro    u_int32_t		segment_number:12;
35090792Sgshapiro#define I2O_EXEC_SYS_TAB_SEG_NUMBER_LOCAL_SEGMENT	0x000
35138032Speter#define I2O_EXEC_SYS_TAB_SEG_NUMBER_UNKNOWN_SEGMENT	0xfff
35264562Sgshapiro
35364562Sgshapiro    u_int32_t		reserved2:4;
35464562Sgshapiro    u_int32_t		reserved3:8;
35564562Sgshapiro    struct i2o_sgl	sgl[3];
35638032Speter} __packed;
35738032Speter
35890792Sgshapirostruct i2o_exec_systab {
35964562Sgshapiro    u_int8_t		entries;
36090792Sgshapiro    u_int8_t		version;
36138032Speter#define	   I2O_RESOURCE_MANAGER_VERSION			0
36290792Sgshapiro
36390792Sgshapiro    u_int16_t		reserved1;
36490792Sgshapiro    u_int32_t		change_id;
36590792Sgshapiro    u_int64_t		reserved2;
36690792Sgshapiro    u_int16_t		organization_id;
36790792Sgshapiro    u_int16_t		reserved3;
36890792Sgshapiro    u_int32_t		iop_id:12;
36990792Sgshapiro    u_int32_t		reserved4:20;
37090792Sgshapiro    u_int32_t		segment_number:12;
37138032Speter    u_int32_t		i2o_version:4;
37238032Speter    u_int32_t		iop_state:8;
37338032Speter    u_int32_t		messenger_type:8;
37490792Sgshapiro    u_int16_t		inbound_mframe_size;
37590792Sgshapiro    u_int16_t		reserved5;
37638032Speter    u_int32_t		last_changed;
37738032Speter    u_int32_t		iop_capabilities;
37838032Speter    u_int64_t		messenger_info;
37938032Speter} __packed;
38038032Speter
38138032Speterstruct i2o_exec_get_lct_message {
38238032Speter    u_int8_t		version_offset;
38338032Speter    u_int8_t		message_flags;
38438032Speter    u_int16_t		message_size;
38590792Sgshapiro    u_int32_t		target_address:12;
386168515Sgshapiro    u_int32_t		initiator_address:12;
38790792Sgshapiro    u_int32_t		function:8;
38864562Sgshapiro    u_int32_t		initiator_context;
38938032Speter    u_int32_t		transaction_context;
39064562Sgshapiro    u_int32_t		class;
39138032Speter    u_int32_t		last_change_id;
39238032Speter    struct i2o_sgl	sgl;
39390792Sgshapiro} __packed;
39490792Sgshapiro
39590792Sgshapiro#define I2O_TID_IOP					0x000
39638032Speter#define I2O_TID_HOST					0x001
39790792Sgshapiro#define I2O_TID_NONE					0xfff
39890792Sgshapiro
39990792Sgshapirostruct i2o_lct_entry {
40090792Sgshapiro    u_int32_t		entry_size:16;
40190792Sgshapiro    u_int32_t		local_tid:12;
40238032Speter    u_int32_t		reserved:4;
40338032Speter    u_int32_t		change_id;
40490792Sgshapiro    u_int32_t		device_flags;
40538032Speter    u_int32_t		class:12;
40638032Speter#define I2O_CLASS_EXECUTIVE				0x000
40790792Sgshapiro#define I2O_CLASS_DDM					0x001
408132943Sgshapiro#define I2O_CLASS_RANDOM_BLOCK_STORAGE			0x010
40938032Speter#define I2O_CLASS_SEQUENTIAL_STORAGE			0x011
41064562Sgshapiro#define I2O_CLASS_LAN					0x020
41138032Speter#define I2O_CLASS_WAN					0x030
41264562Sgshapiro#define I2O_CLASS_FIBRE_CHANNEL_PORT			0x040
41338032Speter#define I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL		0x041
41490792Sgshapiro#define I2O_CLASS_SCSI_PERIPHERAL			0x051
41590792Sgshapiro#define I2O_CLASS_ATE_PORT				0x060
41638032Speter#define I2O_CLASS_ATE_PERIPHERAL			0x061
41738032Speter#define I2O_CLASS_FLOPPY_CONTROLLER			0x070
41864562Sgshapiro#define I2O_CLASS_FLOPPY_DEVICE				0x071
41990792Sgshapiro#define I2O_CLASS_BUS_ADAPTER_PORT			0x080
42090792Sgshapiro#define I2O_CLASS_MATCH_ANYCLASS			0xffffffff
42190792Sgshapiro
42238032Speter    u_int32_t		class_version:4;
42338032Speter    u_int32_t		class_org:16;
42438032Speter    u_int32_t		sub_class;
42538032Speter#define I2O_SUBCLASS_i960				0x001
42638032Speter#define I2O_SUBCLASS_HDM				0x020
42738032Speter#define I2O_SUBCLASS_ISM				0x021
42864562Sgshapiro
42938032Speter    u_int32_t		user_tid:12;
43090792Sgshapiro    u_int32_t		parent_tid:12;
43190792Sgshapiro    u_int32_t		bios_info:8;
43238032Speter    u_int8_t		identity_tag[8];
43338032Speter    u_int32_t		event_capabilities;
43438032Speter} __packed;
43538032Speter
43638032Speter#define I2O_LCT_ENTRYSIZE (sizeof(struct i2o_lct_entry)/sizeof(u_int32_t))
43738032Speter
43864562Sgshapirostruct i2o_get_lct_reply {
43938032Speter    u_int32_t		table_size:16;
44090792Sgshapiro    u_int32_t		boot_device:12;
44190792Sgshapiro    u_int32_t		lct_version:4;
44238032Speter    u_int32_t		iop_flags;
44338032Speter    u_int32_t		current_change_id;
44438032Speter    struct i2o_lct_entry entry[1];
44538032Speter} __packed;
44638032Speter
44738032Speterstruct i2o_util_get_param_message {
44838032Speter    u_int8_t		version_offset;
44990792Sgshapiro    u_int8_t		message_flags;
45090792Sgshapiro    u_int16_t		message_size;
45138032Speter    u_int32_t		target_address:12;
45238032Speter    u_int32_t		initiator_address:12;
45338032Speter    u_int32_t		function:8;
45438032Speter    u_int32_t		initiator_context;
45590792Sgshapiro    u_int32_t		transaction_context;
45664562Sgshapiro    u_int32_t		operation_flags;
45764562Sgshapiro    struct i2o_sgl	sgl[2];
45864562Sgshapiro} __packed;
45964562Sgshapiro
46064562Sgshapirostruct i2o_get_param_template {
46164562Sgshapiro    u_int16_t		operation;
46264562Sgshapiro#define I2O_PARAMS_OPERATION_FIELD_GET			0x0001
46364562Sgshapiro#define I2O_PARAMS_OPERATION_LIST_GET			0x0002
46464562Sgshapiro#define I2O_PARAMS_OPERATION_MORE_GET			0x0003
46590792Sgshapiro#define I2O_PARAMS_OPERATION_SIZE_GET			0x0004
46664562Sgshapiro#define I2O_PARAMS_OPERATION_TABLE_GET			0x0005
46764562Sgshapiro#define I2O_PARAMS_OPERATION_FIELD_SET			0x0006
46864562Sgshapiro#define I2O_PARAMS_OPERATION_LIST_SET			0x0007
46964562Sgshapiro#define I2O_PARAMS_OPERATION_ROW_ADD			0x0008
47064562Sgshapiro#define I2O_PARAMS_OPERATION_ROW_DELETE			0x0009
47142575Speter#define I2O_PARAMS_OPERATION_TABLE_CLEAR		0x000A
47290792Sgshapiro
47390792Sgshapiro    u_int16_t		group;
47490792Sgshapiro#define I2O_BSA_DEVICE_INFO_GROUP_NO			0x0000
47538032Speter#define I2O_BSA_OPERATIONAL_CONTROL_GROUP_NO		0x0001
47638032Speter#define I2O_BSA_POWER_CONTROL_GROUP_NO			0x0002
47738032Speter#define I2O_BSA_CACHE_CONTROL_GROUP_NO			0x0003
47838032Speter#define I2O_BSA_MEDIA_INFO_GROUP_NO			0x0004
47938032Speter#define I2O_BSA_ERROR_LOG_GROUP_NO			0x0005
48090792Sgshapiro
48138032Speter#define I2O_UTIL_PARAMS_DESCRIPTOR_GROUP_NO		0xF000
48238032Speter#define I2O_UTIL_PHYSICAL_DEVICE_TABLE_GROUP_NO		0xF001
48390792Sgshapiro#define I2O_UTIL_CLAIMED_TABLE_GROUP_NO			0xF002
484132943Sgshapiro#define I2O_UTIL_USER_TABLE_GROUP_NO			0xF003
48538032Speter#define I2O_UTIL_PRIVATE_MESSAGE_EXTENSIONS_GROUP_NO	0xF005
48664562Sgshapiro#define I2O_UTIL_AUTHORIZED_USER_TABLE_GROUP_NO		0xF006
48738032Speter#define I2O_UTIL_DEVICE_IDENTITY_GROUP_NO		0xF100
48838032Speter#define I2O_UTIL_DDM_IDENTITY_GROUP_NO			0xF101
48938032Speter#define I2O_UTIL_USER_INFORMATION_GROUP_NO		0xF102
49038032Speter#define I2O_UTIL_SGL_OPERATING_LIMITS_GROUP_NO		0xF103
49138032Speter#define I2O_UTIL_SENSORS_GROUP_NO			0xF200
49238032Speter
49390792Sgshapiro    u_int16_t		field_count;
49438032Speter    u_int16_t		pad;
49538032Speter} __packed;
49690792Sgshapiro
49771345Sgshapirostruct i2o_get_param_operation {
49838032Speter    u_int16_t		operation_count;
499173340Sgshapiro    u_int16_t		reserved;
50038032Speter    struct i2o_get_param_template operation[1];
50190792Sgshapiro} __packed;
50238032Speter
50338032Speterstruct i2o_get_param_reply {
50471345Sgshapiro    u_int16_t		result_count;
50538032Speter    u_int16_t		reserved;
50638032Speter    u_int16_t		block_size;
50738032Speter    u_int8_t		block_status;
50838032Speter    u_int8_t		error_info_size;
50971345Sgshapiro    u_int32_t		result[1];
51038032Speter} __packed;
51138032Speter
51238032Speterstruct i2o_device_identity {
51338032Speter    u_int32_t		class;
51438032Speter    u_int16_t		owner;
51590792Sgshapiro    u_int16_t		parent;
516132943Sgshapiro    u_int8_t		vendor[16];
517132943Sgshapiro    u_int8_t		product[16];
518132943Sgshapiro    u_int8_t		description[16];
51938032Speter    u_int8_t		revision[8];
52038032Speter    u_int8_t		sn_format;
52190792Sgshapiro    u_int8_t		serial[256];
52290792Sgshapiro} __packed;
52366494Sgshapiro
52466494Sgshapirostruct i2o_bsa_device {
52566494Sgshapiro    u_int8_t		device_type;
52666494Sgshapiro    u_int8_t		path_count;
52766494Sgshapiro    u_int16_t		power_state;
52866494Sgshapiro    u_int32_t		block_size;
52966494Sgshapiro    u_int64_t		capacity;
53090792Sgshapiro    u_int32_t		capabilities;
53190792Sgshapiro    u_int32_t		state;
53290792Sgshapiro} __packed;
53390792Sgshapiro
53490792Sgshapirostruct i2o_util_claim_message {
53590792Sgshapiro    u_int8_t		version_offset;
53638032Speter    u_int8_t		message_flags;
53790792Sgshapiro    u_int16_t		message_size;
53890792Sgshapiro    u_int32_t		target_address:12;
53938032Speter    u_int32_t		initiator_address:12;
54038032Speter    u_int32_t		function:8;
54138032Speter    u_int32_t		initiator_context;
54238032Speter    u_int32_t		transaction_context;
54338032Speter    u_int16_t		claim_flags;
54438032Speter    u_int8_t		reserved;
54538032Speter    u_int8_t		claim_type;
54638032Speter} __packed;
54738032Speter
54838032Speterstruct i2o_util_event_register_message {
54938032Speter    u_int8_t		version_offset;
55090792Sgshapiro    u_int8_t		message_flags;
55138032Speter    u_int16_t		message_size;
55238032Speter    u_int32_t		target_address:12;
55390792Sgshapiro    u_int32_t		initiator_address:12;
55490792Sgshapiro    u_int32_t		function:8;
55590792Sgshapiro    u_int32_t		initiator_context;
556132943Sgshapiro    u_int32_t		transaction_context;
55738032Speter    u_int32_t		event_mask;
55838032Speter} __packed;
55990792Sgshapiro
56090792Sgshapirostruct i2o_util_event_reply_message {
561132943Sgshapiro    u_int8_t		version_offset;
56238032Speter    u_int8_t		message_flags;
56390792Sgshapiro    u_int16_t		message_size;
56438032Speter    u_int32_t		target_address:12;
56538032Speter    u_int32_t		initiator_address:12;
56638032Speter    u_int32_t		function:8;
56738032Speter    u_int32_t		initiator_context;
56838032Speter    u_int32_t		transaction_context;
56938032Speter    u_int32_t		event_mask;
57038032Speter    u_int32_t		event_data[1];
57138032Speter} __packed;
57238032Speter
57338032Speterstruct i2o_util_config_dialog_message {
57464562Sgshapiro    u_int8_t		version_offset;
57538032Speter    u_int8_t		message_flags;
57664562Sgshapiro    u_int16_t		message_size;
57738032Speter    u_int32_t		target_address:12;
57838032Speter    u_int32_t		initiator_address:12;
579203004Sgshapiro    u_int32_t		function:8;
58038032Speter    u_int32_t		initiator_context;
58138032Speter    u_int32_t		transaction_context;
58238032Speter    u_int32_t		page_number;
58338032Speter    struct i2o_sgl	sgl[2];
584203004Sgshapiro} __packed;
58538032Speter
58638032Speterstruct i2o_private_message {
58738032Speter    u_int8_t		version_offset;
58838032Speter    u_int8_t		message_flags;
58938032Speter    u_int16_t		message_size;
59090792Sgshapiro    u_int32_t		target_address:12;
59138032Speter    u_int32_t		initiator_address:12;
59264562Sgshapiro    u_int32_t		function:8;
59338032Speter    u_int32_t		initiator_context;
59438032Speter    u_int32_t		transaction_context;
59538032Speter    u_int16_t		function_code;
59638032Speter    u_int16_t		organization_id;
59738032Speter    struct i2o_sgl	in_sgl;
59838032Speter    struct i2o_sgl	out_sgl;
59938032Speter} __packed;
60038032Speter
60138032Speterstruct i2o_bsa_rw_block_message {
60238032Speter    u_int8_t		version_offset;
60338032Speter    u_int8_t		message_flags;
60438032Speter    u_int16_t		message_size;
60538032Speter    u_int32_t		target_address:12;
606203004Sgshapiro    u_int32_t		initiator_address:12;
60738032Speter    u_int32_t		function:8;
60838032Speter    u_int32_t		initiator_context;
60938032Speter    u_int32_t		transaction_context;
61038032Speter    u_int16_t		control_flags;
61138032Speter    u_int8_t		time_multiplier;
61238032Speter    u_int8_t		fetch_ahead;
61338032Speter    u_int32_t		bytecount;
61438032Speter    u_int64_t		lba;
61538032Speter    struct i2o_sgl	sgl;
61638032Speter} __packed;
61738032Speter
61838032Speterstruct i2o_bsa_cache_flush_message {
619203004Sgshapiro    u_int8_t		version_offset;
62038032Speter    u_int8_t		message_flags;
62138032Speter    u_int16_t		message_size;
62238032Speter    u_int32_t		target_address:12;
62338032Speter    u_int32_t		initiator_address:12;
624132943Sgshapiro    u_int32_t		function:8;
62564562Sgshapiro    u_int32_t		initiator_context;
62638032Speter    u_int32_t		transaction_context;
62764562Sgshapiro    u_int16_t		control_flags;
62864562Sgshapiro    u_int8_t		time_multiplier;
62964562Sgshapiro    u_int8_t		reserved;
63064562Sgshapiro} __packed;
63164562Sgshapiro
63264562Sgshapiro/* prototypes */
63364562Sgshapiroint iop_init(struct iop_softc *);
63464562Sgshapirovoid iop_attach(void *);
63590792Sgshapirovoid iop_intr(void *);
63664562Sgshapiroint iop_reset(struct iop_softc *);
63738032Speterint iop_init_outqueue(struct iop_softc *);
63838032Speterint iop_get_lct(struct iop_softc *);
63938032Speterstruct i2o_get_param_reply *iop_get_util_params(struct iop_softc *,int,int,int);
64064562Sgshapirou_int32_t iop_get_mfa(struct iop_softc *);
64164562Sgshapirovoid iop_free_mfa(struct iop_softc *, int);
64238032Speterint iop_queue_wait_msg(struct iop_softc *, int, struct i2o_basic_message *);
64364562Sgshapiroint iop_create_sgl(struct i2o_basic_message *, caddr_t, int, int);
64438032Speter
64538032Speter/* global prototypes */
64638032Speterint pst_add_raid(struct iop_softc *, struct i2o_lct_entry *);
64738032Speter