1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 *
21 *
22 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25/*
26 * SAS Common Structures and Definitions
27 * sas2r14, simplified/reduced
28 */
29#ifndef	_SAS_H
30#define	_SAS_H
31#ifdef	__cplusplus
32extern "C" {
33#endif
34
35#include <sys/sysmacros.h>
36/*
37 * SAS Address Frames
38 * Trailing 4 byte CRC not included.
39 */
40typedef struct {
41	DECL_BITFIELD3(
42	    address_frame_type		:4,
43	    device_type			:3,
44	    reserved0			:1);
45	DECL_BITFIELD2(
46	    reason			:4,
47	    reserved1			:4);
48	DECL_BITFIELD5(
49	    restricted0			:1,
50	    smp_ini_port		:1,
51	    stp_ini_port		:1,
52	    ssp_ini_port		:1,
53	    reserved2			:4);
54	DECL_BITFIELD5(
55	    restricted1			:1,
56	    smp_tgt_port		:1,
57	    stp_tgt_port		:1,
58	    ssp_tgt_port		:1,
59	    reserved3			:4);
60	uint8_t		device_name[8];
61	uint8_t		sas_address[8];
62	uint8_t		phy_identifier;
63	DECL_BITFIELD4(
64	    break_reply_capable		:1,
65	    requested_inside_zpsds	:1,
66	    inside_zpsds_persistent	:1,
67	    reserved4			:5);
68	uint8_t		reserved5[6];
69} sas_identify_af_t;
70
71typedef struct {
72	DECL_BITFIELD3(
73	    address_frame_type		:4,
74	    protocol			:3,
75	    ini_port			:1);
76	DECL_BITFIELD2(
77	    connection_rate		:4,
78	    features			:4);
79	uint16_t 	itag;			/* initiator connection tag */
80	uint8_t 	sas_dst[8];		/* destination sas address */
81	uint8_t 	sas_src[8];		/* source sas address */
82	uint8_t 	src_zone_group;		/* source zone group  */
83	uint8_t 	path_block_count;	/* pathway blocked count */
84	uint16_t	arb_wait_time;		/* arbitration wait time */
85	uint8_t 	compat[4];		/* 'more' compatible features */
86} sas_open_af_t;
87
88#define	SAS_AF_IDENTIFY			0
89#define	SAS_AF_OPEN			1
90
91#define	SAS_IF_DTYPE_ENDPOINT		1
92#define	SAS_IF_DTYPE_EDGE		2
93#define	SAS_IF_DTYPE_FANOUT		3	/* obsolete */
94
95#define	SAS_OF_PROTO_SMP		0
96#define	SAS_OF_PROTO_SSP		1
97#define	SAS_OF_PROTO_STP		2
98
99#define	SAS_SSP_SUPPORT			0x8
100#define	SAS_STP_SUPPORT			0x4
101#define	SAS_SMP_SUPPORT			0x2
102
103
104#define	SAS_CONNRATE_1_5_GBPS		0x8
105#define	SAS_CONNRATE_3_0_GBPS		0x9
106#define	SAS_CONNRATE_6_0_GBPS		0xA
107
108#define	SAS_SATA_SUPPORT		0x1
109#define	SAS_ATTACHED_NAME_OFFSET	52	/* SAS-2 only */
110
111/*
112 * SSP Definitions
113 */
114typedef struct {
115	uint8_t		lun[8];
116	uint8_t		reserved0;
117	DECL_BITFIELD3(
118	    task_attribute	:2,
119	    command_priority	:4,
120	    enable_first_burst	:1);
121	uint8_t		reserved1;
122	DECL_BITFIELD2(
123	    reserved2		:2,
124	    addi_cdb_len	:6);
125	uint8_t		cdb[16];
126	/* additional cdb bytes go here, followed by 4 byte CRC */
127} sas_ssp_cmd_iu_t;
128
129#define	SAS_CMD_TASK_ATTR_SIMPLE	0x00
130#define	SAS_CMD_TASK_ATTR_HEAD		0x01
131#define	SAS_CMD_TASK_ATTR_ORDERED	0x02
132#define	SAS_CMD_TASK_ATTR_ACA		0x04
133
134typedef struct {
135	uint8_t		reserved0[8];
136	uint16_t	status_qualifier;
137	DECL_BITFIELD2(
138	    datapres		:2,
139	    reserved1		:6);
140	uint8_t		status;
141	uint8_t		reserved2[4];
142	uint32_t	sense_data_length;
143	uint32_t	response_data_length;
144	uint8_t		rspd[];
145	/* response data followed by sense data goes here */
146} sas_ssp_rsp_iu_t;
147
148/* length of bytes up to response data */
149#define	SAS_RSP_HDR_SIZE		24
150
151#define	SAS_RSP_DATAPRES_NO_DATA	0x00
152#define	SAS_RSP_DATAPRES_RESPONSE_DATA	0x01
153#define	SAS_RSP_DATAPRES_SENSE_DATA	0x02
154
155/*
156 * When the RSP IU is type RESPONSE_DATA,
157 * the first 4 bytes of response data should
158 * be a Big Endian representation of one of
159 * these codes.
160 */
161#define	SAS_RSP_TMF_COMPLETE		0x00
162#define	SAS_RSP_INVALID_FRAME		0x02
163#define	SAS_RSP_TMF_NOT_SUPPORTED	0x04
164#define	SAS_RSP_TMF_FAILED		0x05
165#define	SAS_RSP_TMF_SUCCEEDED		0x08
166#define	SAS_RSP_TMF_INCORRECT_LUN	0x09
167#define	SAS_RSP_OVERLAPPED_OIPTTA	0x0A
168
169/*
170 * Task Management Functions- should be in a SAM definition file
171 */
172#define	SAS_ABORT_TASK			0x01
173#define	SAS_ABORT_TASK_SET		0x02
174#define	SAS_CLEAR_TASK_SET		0x04
175#define	SAS_LOGICAL_UNIT_RESET		0x08
176#define	SAS_I_T_NEXUS_RESET		0x10
177#define	SAS_CLEAR_ACA			0x40
178#define	SAS_QUERY_TASK			0x80
179#define	SAS_QUERY_TASK_SET		0x81
180#define	SAS_QUERY_UNIT_ATTENTION	0x82
181
182/*
183 * PHY size changed from SAS1.1 to SAS2.
184 */
185#define	SAS_PHYNUM_MAX			127
186#define	SAS_PHYNUM_MASK			0x7f
187
188#define	SAS2_PHYNUM_MAX			254
189#define	SAS2_PHYNUM_MASK		0xff
190
191
192/*
193 * Maximum SMP payload size, including CRC
194 */
195#define	SAS_SMP_MAX_PAYLOAD		1032
196#ifdef	__cplusplus
197}
198#endif
199#endif	/* _SAS_H */
200