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