1/*-
  2 * SPDX-License-Identifier: BSD-4-Clause
  3 *
  4 * Copyright (c) 2003 Hidetoshi Shimokawa
  5 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
  6 * All rights reserved.
  7 *
  8 * Redistribution and use in source and binary forms, with or without
  9 * modification, are permitted provided that the following conditions
 10 * are met:
 11 * 1. Redistributions of source code must retain the above copyright
 12 *    notice, this list of conditions and the following disclaimer.
 13 * 2. Redistributions in binary form must reproduce the above copyright
 14 *    notice, this list of conditions and the following disclaimer in the
 15 *    documentation and/or other materials provided with the distribution.
 16 * 3. All advertising materials mentioning features or use of this software
 17 *    must display the acknowledgement as bellow:
 18 *
 19 *    This product includes software developed by K. Kobayashi and H. Shimokawa
 20 *
 21 * 4. The name of the author may not be used to endorse or promote products
 22 *    derived from this software without specific prior written permission.
 23 *
 24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 27 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 28 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 32 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 33 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 34 * POSSIBILITY OF SUCH DAMAGE.
 35 * 
 36 *
 37 */
 38
 39#define ORB_NOTIFY	(1U << 31)
 40#define	ORB_FMT_STD	(0 << 29)
 41#define	ORB_FMT_VED	(2 << 29)
 42#define	ORB_FMT_NOP	(3 << 29)
 43#define	ORB_FMT_MSK	(3 << 29)
 44#define	ORB_EXV		(1 << 28)
 45/* */
 46#define	ORB_CMD_IN	(1 << 27)
 47/* */
 48#define	ORB_CMD_SPD(x)	((x) << 24)
 49#define	ORB_CMD_MAXP(x)	((x) << 20)
 50#define	ORB_RCN_TMO(x)	((x) << 20)
 51#define	ORB_CMD_PTBL	(1 << 19)
 52#define	ORB_CMD_PSZ(x)	((x) << 16)
 53
 54#define	ORB_FUN_LGI	(0 << 16)
 55#define	ORB_FUN_QLG	(1 << 16)
 56#define	ORB_FUN_RCN	(3 << 16)
 57#define	ORB_FUN_LGO	(7 << 16)
 58#define	ORB_FUN_ATA	(0xb << 16)
 59#define	ORB_FUN_ATS	(0xc << 16)
 60#define	ORB_FUN_LUR	(0xe << 16)
 61#define	ORB_FUN_RST	(0xf << 16)
 62#define	ORB_FUN_MSK	(0xf << 16)
 63#define	ORB_FUN_RUNQUEUE 0xffff
 64
 65#define ORB_RES_CMPL 0
 66#define ORB_RES_FAIL 1
 67#define ORB_RES_ILLE 2
 68#define ORB_RES_VEND 3
 69
 70#define SBP_DEBUG(x)	if (debug > x) {
 71#define END_DEBUG	}
 72
 73struct ind_ptr {
 74	uint32_t hi,lo;
 75};
 76
 77
 78#define SBP_RECV_LEN 32
 79
 80struct sbp_login_res {
 81	uint16_t	len;
 82	uint16_t	id;
 83	uint16_t	res0;
 84	uint16_t	cmd_hi;
 85	uint32_t	cmd_lo;
 86	uint16_t	res1;
 87	uint16_t	recon_hold;
 88};
 89
 90struct sbp_status {
 91#if BYTE_ORDER == BIG_ENDIAN
 92	uint8_t		src:2,
 93			resp:2,
 94			dead:1,
 95			len:3;
 96#else
 97	uint8_t		len:3,
 98			dead:1,
 99			resp:2,
100			src:2;
101#endif
102	uint8_t		status;
103	uint16_t	orb_hi;
104	uint32_t	orb_lo;
105	uint32_t	data[6];
106};
107/* src */
108#define SRC_NEXT_EXISTS	0
109#define SRC_NO_NEXT	1
110#define SRC_UNSOL	2
111
112/* resp */
113#define SBP_REQ_CMP	0	/* request complete */
114#define SBP_TRANS_FAIL	1	/* transport failure */
115#define SBP_ILLE_REQ	2	/* illegal request */
116#define SBP_VEND_DEP	3	/* vendor dependent */
117
118/* status (resp == 0) */
119/*   0: No additional Information to report */
120/*   1: Request Type not supported */
121/*   2: Speed not supported */
122/*   3: Page size not supported */
123/*   4: Access denied */
124#define STATUS_ACCESS_DENY	4
125#define STATUS_LUR		5
126/*   6: Maximum payload too small */
127/*   7: Reserved for future standardization */
128/*   8: Resource unavailable */
129#define STATUS_RES_UNAVAIL	8
130/*   9: Function Rejected */
131/*  10: Login ID not recognized */
132/*  11: Dummy ORB completed */
133/*  12: Request aborted */
134/* 255: Unspecified error */
135
136/* status (resp == 1) */
137/* Referenced object */
138#define OBJ_ORB		(0 << 6)	/* 0: ORB */
139#define OBJ_DATA	(1 << 6)	/* 1: Data buffer */
140#define OBJ_PT		(2 << 6)	/* 2: Page table */
141#define OBJ_UNSPEC	(3 << 6)	/* 3: Unable to specify */
142/* Serial bus error */
143/* 0: Missing acknowledge */
144/* 1: Reserved; not to be used */
145/* 2: Time-out error */
146#define SBE_TIMEOUT 2
147/* 3: Reserved; not to be used */
148/* 4: Busy retry limit exceeded: ack_busy_X */
149/* 5: Busy retry limit exceeded: ack_busy_A */
150/* 6: Busy retry limit exceeded: ack_busy_B */
151/* 7-A: Reserved for future standardization */
152/* B: Tardy retry limit exceeded */
153/* C: Confilict error */
154/* D: Data error */
155/* E: Type error */
156/* F: Address error */
157
158
159struct sbp_cmd_status {
160#define SBP_SFMT_CURR 0
161#define SBP_SFMT_DEFER 1
162#if BYTE_ORDER == BIG_ENDIAN
163	uint8_t		sfmt:2,
164			status:6;
165	uint8_t		valid:1,
166			mark:1,
167			eom:1,
168			ill_len:1,
169			s_key:4;
170#else
171	uint8_t		status:6,
172			sfmt:2;
173	uint8_t		s_key:4,
174			ill_len:1,
175			eom:1,
176			mark:1,
177			valid:1;
178#endif
179	uint8_t		s_code;
180	uint8_t		s_qlfr;
181	uint32_t	info;
182	uint32_t	cdb;
183	uint8_t		fru;
184	uint8_t		s_keydep[3];
185	uint32_t	vend[2];
186};
187
188#define ORB_FUN_NAMES \
189	/* 0 */ "LOGIN", \
190	/* 1 */ "QUERY LOGINS", \
191	/* 2 */ "Reserved", \
192	/* 3 */ "RECONNECT", \
193	/* 4 */ "SET PASSWORD", \
194	/* 5 */ "Reserved", \
195	/* 6 */ "Reserved", \
196	/* 7 */ "LOGOUT", \
197	/* 8 */ "Reserved", \
198	/* 9 */ "Reserved", \
199	/* A */ "Reserved", \
200	/* B */ "ABORT TASK", \
201	/* C */ "ABORT TASK SET", \
202	/* D */ "Reserved", \
203	/* E */ "LOGICAL UNIT RESET", \
204	/* F */ "TARGET RESET"