xref: /netbsd/sys/dev/ieee1394/iec13213.h (revision 460ae15e)
1 /*	$NetBSD: iec13213.h,v 1.6 2014/03/28 04:09:19 htodd Exp $	*/
2 /*-
3  * Copyright (c) 2003 Hidetoshi Shimokawa
4  * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the acknowledgement as bellow:
17  *
18  *    This product includes software developed by K. Kobayashi and H. Shimokawa
19  *
20  * 4. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  * $FreeBSD: /repoman/r/ncvs/src/sys/dev/firewire/iec13213.h,v 1.14 2005/01/06 01:42:41 imp Exp $
36  *
37  */
38 
39 #ifndef _IEC13213_H_
40 #define _IEC13213_H_
41 
42 #define	STATE_CLEAR	0x0000
43 #define	STATE_SET	0x0004
44 #define	NODE_IDS	0x0008
45 #define	RESET_START	0x000c
46 #define	SPLIT_TIMEOUT_HI	0x0018
47 #define	SPLIT_TIMEOUT_LO	0x001c
48 #define	CYCLE_TIME	0x0200
49 #define	BUS_TIME	0x0204
50 #define	BUSY_TIMEOUT	0x0210
51 #define	PRIORITY_BUDGET 0x0218
52 #define	BUS_MGR_ID	0x021c
53 #define	BANDWIDTH_AV	0x0220
54 #define	CHANNELS_AV_HI	0x0224
55 #define	CHANNELS_AV_LO	0x0228
56 #define	IP_CHANNELS	0x0234
57 
58 #define	CONF_ROM	0x0400
59 
60 #define	TOPO_MAP	0x1000
61 #define	SPED_MAP	0x2000
62 
63 #define CSRTYPE_SHIFT	6
64 #define CSRTYPE_MASK	(3 << CSRTYPE_SHIFT)
65 #define CSRTYPE_I	(0 << CSRTYPE_SHIFT) /* Immediate */
66 #define CSRTYPE_C	(1 << CSRTYPE_SHIFT) /* CSR offset */
67 #define CSRTYPE_L	(2 << CSRTYPE_SHIFT) /* Leaf */
68 #define CSRTYPE_D	(3 << CSRTYPE_SHIFT) /* Directory */
69 
70 /*
71  * CSR keys
72  * 00 - 2F: defined by CSR architecture standards.
73  * 30 - 37: defined by BUS starndards
74  * 38 - 3F: defined by Vendor/Specifier
75  */
76 #define CSRKEY_MASK	0x3f
77 #define CSRKEY_DESC	0x01 /* Descriptor */
78 #define CSRKEY_BDINFO	0x02 /* Bus_Dependent_Info */
79 #define CSRKEY_VENDOR	0x03 /* Vendor */
80 #define CSRKEY_HW	0x04 /* Hardware_Version */
81 #define CSRKEY_MODULE	0x07 /* Module */
82 #define CSRKEY_NCAP	0x0c /* Node_Capabilities */
83 #define CSRKEY_EUI64	0x0d /* EUI_64 */
84 #define CSRKEY_UNIT	0x11 /* Unit */
85 #define CSRKEY_SPEC	0x12 /* Specifier_ID */
86 #define CSRKEY_VER	0x13 /* Version */
87 #define CSRKEY_DINFO	0x14 /* Dependent_Info */
88 #define CSRKEY_ULOC	0x15 /* Unit_Location */
89 #define CSRKEY_MODEL	0x17 /* Model */
90 #define CSRKEY_INST	0x18 /* Instance */
91 #define CSRKEY_KEYW	0x19 /* Keyword */
92 #define CSRKEY_FEAT	0x1a /* Feature */
93 #define CSRKEY_EROM	0x1b /* Extended_ROM */
94 #define CSRKEY_EKSID	0x1c /* Extended_Key_Specifier_ID */
95 #define CSRKEY_EKEY	0x1d /* Extended_Key */
96 #define CSRKEY_EDATA	0x1e /* Extended_Data */
97 #define CSRKEY_MDESC	0x1f /* Modifiable_Descriptor */
98 #define CSRKEY_DID	0x20 /* Directory_ID */
99 #define CSRKEY_REV	0x21 /* Revision */
100 
101 #define CSRKEY_FIRM_VER	0x3c /* Firmware version */
102 #define CSRKEY_UNIT_CH	0x3a /* Unit characteristics */
103 #define CSRKEY_COM_SPEC	0x38 /* Command set revision */
104 #define CSRKEY_COM_SET	0x39 /* Command set */
105 
106 #define CROM_UDIR	(CSRTYPE_D | CSRKEY_UNIT)  /* 0x81 Unit directory */
107 #define CROM_TEXTLEAF	(CSRTYPE_L | CSRKEY_DESC)  /* 0x81 Text leaf */
108 #define CROM_TEXTLEAF2	(CSRTYPE_L | CSRKEY_BDINFO)/* 0x82 Text leaf2 */
109 #define CROM_LUN	(CSRTYPE_I | CSRKEY_DINFO) /* 0x14 Logical unit num. */
110 #define CROM_MGM	(CSRTYPE_C | CSRKEY_DINFO) /* 0x54 Management agent */
111 #define CROM_NODEID	0x8d /* only valid for IEEE 1394-1995 digital camera */
112 
113 #define CSRVAL_VENDOR_PRIVATE	0xacde48
114 #define CSRVAL_1394TA	0x00a02d
115 #define CSRVAL_ANSIT10	0x00609e
116 #define CSRVAL_IETF	0x00005e
117 
118 #define CSR_PROTAVC	0x010001
119 #define CSR_PROTCAL	0x010002
120 #define CSR_PROTEHS	0x010004
121 #define CSR_PROTHAVI	0x010008
122 #define CSR_PROTCAM104	0x000100
123 #define CSR_PROTCAM120	0x000101
124 #define CSR_PROTCAM130	0x000102
125 #define CSR_PROTDPP	0x0a6be2
126 #define CSR_PROTIICP	0x4b661f
127 
128 #define CSRVAL_T10SBP2	0x010483
129 #define CSRVAL_SCSI	0x0104d8
130 
131 struct csrreg {
132 #if BYTE_ORDER == BIG_ENDIAN
133 	uint32_t key:8,
134 		 val:24;
135 #else
136 	uint32_t val:24,
137 		 key:8;
138 #endif
139 };
140 struct csrhdr {
141 #if BYTE_ORDER == BIG_ENDIAN
142 	uint32_t info_len:8,
143 		 crc_len:8,
144 		 crc:16;
145 #else
146 	uint32_t crc:16,
147 		 crc_len:8,
148 		 info_len:8;
149 #endif
150 };
151 struct csrdirectory {
152 	BIT16x2(crc_len, crc);
153 	struct csrreg entry[0];
154 };
155 struct csrtext {
156 	BIT16x2(crc_len, crc);
157 #if BYTE_ORDER == BIG_ENDIAN
158 	uint32_t spec_type:8,
159 		 spec_id:24;
160 #else
161 	uint32_t spec_id:24,
162 		 spec_type:8;
163 #endif
164 	uint32_t lang_id;
165 	uint32_t text[0];
166 };
167 
168 struct bus_info {
169 #define	CSR_BUS_NAME_IEEE1394	0x31333934
170 	uint32_t bus_name;
171 #if BYTE_ORDER == BIG_ENDIAN
172 	uint32_t irmc:1,		/* iso. resource manager capable */
173 		 cmc:1,			/* cycle master capable */
174 		 isc:1,			/* iso. operation support */
175 		 bmc:1,			/* bus manager capable */
176 		 pmc:1,			/* power manager capable */
177 		 :3,
178 		 cyc_clk_acc:8,		/* 0 <= ppm <= 100 */
179 		 max_rec:4,		/* (2 << max_rec) bytes */
180 		 :2,
181 		 max_rom:2,
182 		 generation:4,
183 		 :1,
184 		 link_spd:3;
185 #else
186 	uint32_t link_spd:3,
187 		 :1,
188 		 generation:4,
189 		 max_rom:2,
190 		 :2,
191 		 max_rec:4,		/* (2 << max_rec) bytes */
192 		 cyc_clk_acc:8,		/* 0 <= ppm <= 100 */
193 		 :3,
194 		 pmc:1,			/* power manager capable */
195 		 bmc:1,			/* bus manager capable */
196 		 isc:1,			/* iso. operation support */
197 		 cmc:1,			/* cycle master capable */
198 		 irmc:1;		/* iso. resource manager capable */
199 #endif
200 	struct fw_eui64 eui64;
201 };
202 /* max_rom */
203 #define MAXROM_4	0
204 #define MAXROM_64	1
205 #define MAXROM_1024	2
206 
207 #define CROM_MAX_DEPTH	10
208 struct crom_ptr {
209 	struct csrdirectory *dir;
210 	int index;
211 };
212 
213 struct crom_context {
214 	int depth;
215 	struct crom_ptr stack[CROM_MAX_DEPTH];
216 };
217 
218 void crom_init_context(struct crom_context *, uint32_t *);
219 struct csrreg *crom_get(struct crom_context *);
220 void crom_next(struct crom_context *);
221 void crom_parse_text(struct crom_context *, char *, int);
222 uint16_t crom_crc(uint32_t *r, int);
223 struct csrreg *crom_search_key(struct crom_context *, uint8_t);
224 int crom_has_specver(uint32_t *, uint32_t, uint32_t);
225 
226 #ifndef _KERNEL
227 const char *crom_desc(struct crom_context *, char *, size_t);
228 #endif
229 
230 /* For CROM build */
231 #if defined(_KERNEL) || defined(TEST)
232 #define CROM_MAX_CHUNK_LEN 20
233 struct crom_src {
234 	struct csrhdr hdr;
235 	struct bus_info businfo;
236 	STAILQ_HEAD(, crom_chunk) chunk_list;
237 };
238 
239 struct crom_chunk {
240 	STAILQ_ENTRY(crom_chunk) link;
241 	struct crom_chunk *ref_chunk;
242 	int ref_index;
243 	int offset;
244 	struct {
245 		BIT16x2(crc_len, crc);
246 		uint32_t buf[CROM_MAX_CHUNK_LEN];
247 	} data;
248 };
249 
250 extern int crom_add_quad(struct crom_chunk *, uint32_t);
251 extern int crom_add_entry(struct crom_chunk *, int, int);
252 extern int crom_add_chunk(struct crom_src *src, struct crom_chunk *,
253 					struct crom_chunk *, int);
254 extern int crom_add_simple_text(struct crom_src *src, struct crom_chunk *,
255 					struct crom_chunk *, const char *);
256 extern int crom_load(struct crom_src *, uint32_t *, int);
257 #endif
258 
259 #endif	/* _IEC13213_H_ */
260