1139749Simp/*-
2122526Ssimokawa * Copyright (c) 2003 Hidetoshi Shimokawa
3122526Ssimokawa * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
4120660Ssimokawa * All rights reserved.
5120660Ssimokawa *
6120660Ssimokawa * Redistribution and use in source and binary forms, with or without
7120660Ssimokawa * modification, are permitted provided that the following conditions
8120660Ssimokawa * are met:
9120660Ssimokawa * 1. Redistributions of source code must retain the above copyright
10120660Ssimokawa *    notice, this list of conditions and the following disclaimer.
11120660Ssimokawa * 2. Redistributions in binary form must reproduce the above copyright
12120660Ssimokawa *    notice, this list of conditions and the following disclaimer in the
13120660Ssimokawa *    documentation and/or other materials provided with the distribution.
14120660Ssimokawa * 3. All advertising materials mentioning features or use of this software
15120660Ssimokawa *    must display the acknowledgement as bellow:
16120660Ssimokawa *
17120660Ssimokawa *    This product includes software developed by K. Kobayashi and H. Shimokawa
18120660Ssimokawa *
19120660Ssimokawa * 4. The name of the author may not be used to endorse or promote products
20120660Ssimokawa *    derived from this software without specific prior written permission.
21120660Ssimokawa *
22120660Ssimokawa * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23120660Ssimokawa * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24120660Ssimokawa * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25120660Ssimokawa * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26120660Ssimokawa * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27120660Ssimokawa * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28120660Ssimokawa * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29120660Ssimokawa * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30120660Ssimokawa * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31120660Ssimokawa * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32120660Ssimokawa * POSSIBILITY OF SUCH DAMAGE.
33120660Ssimokawa *
34120660Ssimokawa * $FreeBSD$
35120660Ssimokawa *
36120660Ssimokawa */
37120660Ssimokawa
38120660Ssimokawa#define ORB_NOTIFY	(1 << 31)
39120660Ssimokawa#define	ORB_FMT_STD	(0 << 29)
40120660Ssimokawa#define	ORB_FMT_VED	(2 << 29)
41120660Ssimokawa#define	ORB_FMT_NOP	(3 << 29)
42120660Ssimokawa#define	ORB_FMT_MSK	(3 << 29)
43120660Ssimokawa#define	ORB_EXV		(1 << 28)
44120660Ssimokawa/* */
45120660Ssimokawa#define	ORB_CMD_IN	(1 << 27)
46120660Ssimokawa/* */
47120660Ssimokawa#define	ORB_CMD_SPD(x)	((x) << 24)
48120660Ssimokawa#define	ORB_CMD_MAXP(x)	((x) << 20)
49120660Ssimokawa#define	ORB_RCN_TMO(x)	((x) << 20)
50120660Ssimokawa#define	ORB_CMD_PTBL	(1 << 19)
51120660Ssimokawa#define	ORB_CMD_PSZ(x)	((x) << 16)
52120660Ssimokawa
53120660Ssimokawa#define	ORB_FUN_LGI	(0 << 16)
54120660Ssimokawa#define	ORB_FUN_QLG	(1 << 16)
55120660Ssimokawa#define	ORB_FUN_RCN	(3 << 16)
56120660Ssimokawa#define	ORB_FUN_LGO	(7 << 16)
57120660Ssimokawa#define	ORB_FUN_ATA	(0xb << 16)
58120660Ssimokawa#define	ORB_FUN_ATS	(0xc << 16)
59120660Ssimokawa#define	ORB_FUN_LUR	(0xe << 16)
60120660Ssimokawa#define	ORB_FUN_RST	(0xf << 16)
61120660Ssimokawa#define	ORB_FUN_MSK	(0xf << 16)
62120660Ssimokawa#define	ORB_FUN_RUNQUEUE 0xffff
63120660Ssimokawa
64120660Ssimokawa#define ORB_RES_CMPL 0
65120660Ssimokawa#define ORB_RES_FAIL 1
66120660Ssimokawa#define ORB_RES_ILLE 2
67120660Ssimokawa#define ORB_RES_VEND 3
68120660Ssimokawa
69120660Ssimokawa#define SBP_DEBUG(x)	if (debug > x) {
70120660Ssimokawa#define END_DEBUG	}
71120660Ssimokawa
72120660Ssimokawastruct ind_ptr {
73129585Sdfr	uint32_t hi,lo;
74120660Ssimokawa};
75120660Ssimokawa
76120660Ssimokawa
77120660Ssimokawa#define SBP_RECV_LEN 32
78120660Ssimokawa
79120660Ssimokawastruct sbp_login_res{
80129585Sdfr	uint16_t	len;
81129585Sdfr	uint16_t	id;
82129585Sdfr	uint16_t	res0;
83129585Sdfr	uint16_t	cmd_hi;
84129585Sdfr	uint32_t	cmd_lo;
85129585Sdfr	uint16_t	res1;
86129585Sdfr	uint16_t	recon_hold;
87120660Ssimokawa};
88120660Ssimokawa
89120660Ssimokawastruct sbp_status{
90120660Ssimokawa#if BYTE_ORDER == BIG_ENDIAN
91129585Sdfr	uint8_t		src:2,
92120660Ssimokawa			resp:2,
93120660Ssimokawa			dead:1,
94120660Ssimokawa			len:3;
95120660Ssimokawa#else
96129585Sdfr	uint8_t		len:3,
97120660Ssimokawa			dead:1,
98120660Ssimokawa			resp:2,
99120660Ssimokawa			src:2;
100120660Ssimokawa#endif
101129585Sdfr	uint8_t		status;
102129585Sdfr	uint16_t	orb_hi;
103129585Sdfr	uint32_t	orb_lo;
104129585Sdfr	uint32_t	data[6];
105120660Ssimokawa};
106120660Ssimokawa/* src */
107120660Ssimokawa#define SRC_NEXT_EXISTS	0
108120660Ssimokawa#define SRC_NO_NEXT	1
109120660Ssimokawa#define SRC_UNSOL	2
110120660Ssimokawa
111120660Ssimokawa/* resp */
112120660Ssimokawa#define SBP_REQ_CMP	0	/* request complete */
113120660Ssimokawa#define SBP_TRANS_FAIL	1	/* transport failure */
114120660Ssimokawa#define SBP_ILLE_REQ	2	/* illegal request */
115120660Ssimokawa#define SBP_VEND_DEP	3	/* vendor dependent */
116120660Ssimokawa
117120660Ssimokawa/* status (resp == 0) */
118120660Ssimokawa/*   0: No additional Information to report */
119120660Ssimokawa/*   1: Request Type not supported */
120120660Ssimokawa/*   2: Speed not supported */
121120660Ssimokawa/*   3: Page size not supported */
122120660Ssimokawa/*   4: Access denied */
123120660Ssimokawa#define STATUS_ACCESS_DENY	4
124190792Ssbruno#define STATUS_LUR		5
125120660Ssimokawa/*   6: Maximum payload too small */
126120660Ssimokawa/*   7: Reserved for future standardization */
127120660Ssimokawa/*   8: Resource unavailabe */
128123430Ssimokawa#define STATUS_RES_UNAVAIL	8
129120660Ssimokawa/*   9: Function Rejected */
130120660Ssimokawa/*  10: Login ID not recognized */
131120660Ssimokawa/*  11: Dummy ORB completed */
132120660Ssimokawa/*  12: Request aborted */
133120660Ssimokawa/* 255: Unspecified error */
134120660Ssimokawa
135120660Ssimokawa/* status (resp == 1) */
136120660Ssimokawa/* Referenced object */
137120660Ssimokawa#define OBJ_ORB		(0 << 6)	/* 0: ORB */
138120660Ssimokawa#define OBJ_DATA	(1 << 6)	/* 1: Data buffer */
139120660Ssimokawa#define OBJ_PT		(2 << 6)	/* 2: Page table */
140120660Ssimokawa#define OBJ_UNSPEC	(3 << 6)	/* 3: Unable to specify */
141120660Ssimokawa/* Serial bus error */
142120660Ssimokawa/* 0: Missing acknowledge */
143120660Ssimokawa/* 1: Reserved; not to be used */
144120660Ssimokawa/* 2: Time-out error */
145120660Ssimokawa#define SBE_TIMEOUT 2
146120660Ssimokawa/* 3: Reserved; not to be used */
147120660Ssimokawa/* 4: Busy retry limit exceeded: ack_busy_X */
148120660Ssimokawa/* 5: Busy retry limit exceeded: ack_busy_A */
149120660Ssimokawa/* 6: Busy retry limit exceeded: ack_busy_B */
150120660Ssimokawa/* 7-A: Reserved for future standardization */
151120660Ssimokawa/* B: Tardy retry limit exceeded */
152120660Ssimokawa/* C: Confilict error */
153120660Ssimokawa/* D: Data error */
154120660Ssimokawa/* E: Type error */
155120660Ssimokawa/* F: Address error */
156120660Ssimokawa
157120660Ssimokawa
158120660Ssimokawastruct sbp_cmd_status{
159120660Ssimokawa#define SBP_SFMT_CURR 0
160120660Ssimokawa#define SBP_SFMT_DEFER 1
161120660Ssimokawa#if BYTE_ORDER == BIG_ENDIAN
162129585Sdfr	uint8_t		sfmt:2,
163120660Ssimokawa			status:6;
164129585Sdfr	uint8_t		valid:1,
165120660Ssimokawa			mark:1,
166120660Ssimokawa			eom:1,
167120660Ssimokawa			ill_len:1,
168120660Ssimokawa			s_key:4;
169120660Ssimokawa#else
170129585Sdfr	uint8_t		status:6,
171120660Ssimokawa			sfmt:2;
172129585Sdfr	uint8_t		s_key:4,
173120660Ssimokawa			ill_len:1,
174120660Ssimokawa			eom:1,
175120660Ssimokawa			mark:1,
176120660Ssimokawa			valid:1;
177120660Ssimokawa#endif
178129585Sdfr	uint8_t		s_code;
179129585Sdfr	uint8_t		s_qlfr;
180129585Sdfr	uint32_t	info;
181129585Sdfr	uint32_t	cdb;
182129585Sdfr	uint8_t		fru;
183129585Sdfr	uint8_t		s_keydep[3];
184129585Sdfr	uint32_t	vend[2];
185120660Ssimokawa};
186120660Ssimokawa
187120660Ssimokawa#define ORB_FUN_NAMES \
188120660Ssimokawa	/* 0 */ "LOGIN", \
189120660Ssimokawa	/* 1 */ "QUERY LOGINS", \
190120660Ssimokawa	/* 2 */ "Reserved", \
191120660Ssimokawa	/* 3 */ "RECONNECT", \
192120660Ssimokawa	/* 4 */ "SET PASSWORD", \
193120660Ssimokawa	/* 5 */ "Reserved", \
194120660Ssimokawa	/* 6 */ "Reserved", \
195120660Ssimokawa	/* 7 */ "LOGOUT", \
196120660Ssimokawa	/* 8 */ "Reserved", \
197120660Ssimokawa	/* 9 */ "Reserved", \
198120660Ssimokawa	/* A */ "Reserved", \
199120660Ssimokawa	/* B */ "ABORT TASK", \
200120660Ssimokawa	/* C */ "ABORT TASK SET", \
201120660Ssimokawa	/* D */ "Reserved", \
202120660Ssimokawa	/* E */ "LOGICAL UNIT RESET", \
203120660Ssimokawa	/* F */ "TARGET RESET"
204