xref: /illumos-gate/usr/src/uts/common/sys/1394/ixl1394.h (revision f17620a4f72a29025a22655ba8735ccd20ae174f)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1999-2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef	_SYS_1394_IXL1394_H
28 #define	_SYS_1394_IXL1394_H
29 
30 /*
31  * ixl1394.h
32  *    Contains all defines and structures necessary for Isochronous Transfer
33  *    Language (IXL) programs. IXL programs are used to specify the transmission
34  *    or receipt of isochronous packets for an isochronous channel.
35  */
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 #include <sys/note.h>
42 
43 /*
44  * Error codes for IXL program compilation and dynamic update
45  * Comments indicate which are source of error
46  * NOTE: Make sure IXL1394_COMP_ERR_LAST is updated if a new error code is
47  * added. t1394_errmsg.c uses *FIRST and *LAST as bounds checks.
48  */
49 #define	IXL1394_EMEM_ALLOC_FAIL		(-301)	/* compile only */
50 #define	IXL1394_EBAD_IXL_OPCODE		(-302)	/* compile only */
51 #define	IXL1394_EFRAGMENT_OFLO		(-303)	/* compile only */
52 #define	IXL1394_ENO_DATA_PKTS		(-304)	/* compile only */
53 #define	IXL1394_EMISPLACED_RECV		(-305)	/* compile only */
54 #define	IXL1394_EMISPLACED_SEND		(-306)	/* compile only */
55 #define	IXL1394_EPKT_HDR_MISSING	(-307)	/* compile & update */
56 #define	IXL1394_ENULL_BUFFER_ADDR	(-308)	/* compile only */
57 #define	IXL1394_EPKTSIZE_MAX_OFLO	(-309)	/* compile & update */
58 #define	IXL1394_EPKTSIZE_RATIO		(-310)	/* compile only */
59 #define	IXL1394_EUNAPPLIED_SET_CMD	(-311)	/* compile only */
60 #define	IXL1394_EDUPLICATE_SET_CMD	(-312)	/* compile only */
61 #define	IXL1394_EJUMP_NOT_TO_LABEL	(-313)	/* compile & update */
62 #define	IXL1394_EUPDATE_DISALLOWED	(-314)	/* compile & update */
63 #define	IXL1394_EBAD_SKIPMODE		(-315)	/* compile & update */
64 #define	IXL1394_EWRONG_XR_CMD_MODE	(-316)	/* compile only */
65 #define	IXL1394_EINTERNAL_ERROR		(-317)	/* compile & update */
66 #define	IXL1394_ENOT_IMPLEMENTED	(-318)	/* compile only */
67 #define	IXL1394_EOPCODE_MISMATCH	(-319)	/* update only */
68 #define	IXL1394_EOPCODE_DISALLOWED	(-320)	/* update only */
69 #define	IXL1394_EBAD_SKIP_LABEL		(-321)	/* update only */
70 #define	IXL1394_EXFER_BUF_MISSING	(-322)	/* update only */
71 #define	IXL1394_EXFER_BUF_CNT_DIFF	(-323)	/* update only */
72 #define	IXL1394_EORIG_IXL_CORRUPTED	(-324)	/* update only */
73 #define	IXL1394_ECOUNT_MISMATCH		(-325)	/* update only */
74 #define	IXL1394_EPRE_UPD_DMALOST	(-326)	/* update only */
75 #define	IXL1394_EPOST_UPD_DMALOST	(-327)	/* update only */
76 #define	IXL1394_ERISK_PROHIBITS_UPD	(-328)	/* update only */
77 
78 #define	IXL1394_COMP_ERR_FIRST		IXL1394_EMEM_ALLOC_FAIL
79 #define	IXL1394_COMP_ERR_LAST		IXL1394_ERISK_PROHIBITS_UPD
80 
81 #define	IXL1394_ENO_DMA_RESRCS		(-200)
82 
83 
84 /*
85  * IXL command opcodes
86  *
87  * IXL opcodes contain a unique opcode identifier and various flags to
88  * speed compilation.
89  */
90 
91 /* 5 flag bits at high end of opcode field. */
92 #define	IXL1394_OPF_MASK	0xF800
93 #define	IXL1394_OPF_UPDATE	0x8000	/* cmd update allowed during exec */
94 #define	IXL1394_OPF_ONRECV	0x4000	/* cmd is allowed on recv */
95 #define	IXL1394_OPF_ONXMIT	0x2000	/* cmd is allowed on xmit */
96 #define	IXL1394_OPF_ENDSXFER	0x1000	/* cmd ends cur pkt xfer build */
97 #define	IXL1394_OPF_ISXFER	0x0800	/* cmd is data transfer command */
98 
99 /* Useful flag composites. */
100 #define	IXL1394_OPF_ONXFER	(IXL1394_OPF_ONXMIT | IXL1394_OPF_ONRECV)
101 #define	IXL1394_OPF_ONXFER_ENDS (IXL1394_OPF_ONXFER | IXL1394_OPF_ENDSXFER)
102 #define	IXL1394_OPF_ONRECV_ENDS (IXL1394_OPF_ONRECV | IXL1394_OPF_ENDSXFER)
103 #define	IXL1394_OPF_ONXMIT_ENDS (IXL1394_OPF_ONXMIT | IXL1394_OPF_ENDSXFER)
104 
105 /* 2 type bits whose contents are interpreted based on isxr setting */
106 #define	IXL1394_OPTY_MASK		0x0600
107 
108 /* type bits when isxfer == 0 */
109 #define	IXL1394_OPTY_OTHER		0x0000
110 
111 /* type bits when isxr == 1 */
112 #define	IXL1394_OPTY_XFER_PKT		(0x0000 | IXL1394_OPF_ISXFER)
113 #define	IXL1394_OPTY_XFER_PKT_ST	(0x0200 | IXL1394_OPF_ISXFER)
114 #define	IXL1394_OPTY_XFER_BUF_ST	(0x0400 | IXL1394_OPF_ISXFER)
115 #define	IXL1394_OPTY_XFER_SPCL_ST	(0x0600 | IXL1394_OPF_ISXFER)
116 
117 /*
118  * IXL Command Opcodes.
119  */
120 #define	IXL1394_OP_LABEL    (1 | IXL1394_OPTY_OTHER | IXL1394_OPF_ONXFER_ENDS)
121 #define	IXL1394_OP_JUMP	    (2 | IXL1394_OPTY_OTHER | IXL1394_OPF_ONXFER_ENDS)
122 #define	IXL1394_OP_CALLBACK (3 | IXL1394_OPTY_OTHER | IXL1394_OPF_ONXFER)
123 #define	IXL1394_OP_RECV_PKT (4 | IXL1394_OPTY_XFER_PKT | IXL1394_OPF_ONRECV)
124 #define	IXL1394_OP_RECV_PKT_ST \
125 		(5 | IXL1394_OPTY_XFER_PKT_ST |	IXL1394_OPF_ONRECV_ENDS)
126 #define	IXL1394_OP_RECV_BUF \
127 		(6 | IXL1394_OPTY_XFER_BUF_ST |	IXL1394_OPF_ONRECV_ENDS)
128 #define	IXL1394_OP_SEND_PKT (7 | IXL1394_OPTY_XFER_PKT | IXL1394_OPF_ONXMIT)
129 #define	IXL1394_OP_SEND_PKT_ST \
130 		(8 | IXL1394_OPTY_XFER_PKT_ST |	IXL1394_OPF_ONXMIT_ENDS)
131 #define	IXL1394_OP_SEND_PKT_WHDR_ST \
132 		(9  | IXL1394_OPTY_XFER_PKT_ST | IXL1394_OPF_ONXMIT_ENDS)
133 #define	IXL1394_OP_SEND_BUF \
134 		(10 | IXL1394_OPTY_XFER_BUF_ST | IXL1394_OPF_ONXMIT_ENDS)
135 #define	IXL1394_OP_SEND_HDR_ONLY \
136 		(12 | IXL1394_OPTY_XFER_SPCL_ST | IXL1394_OPF_ONXMIT_ENDS)
137 #define	IXL1394_OP_SEND_NO_PKT \
138 		(13 | IXL1394_OPTY_XFER_SPCL_ST | IXL1394_OPF_ONXMIT_ENDS)
139 #define	IXL1394_OP_STORE_TIMESTAMP \
140 		(14 | IXL1394_OPTY_OTHER | IXL1394_OPF_ONXFER)
141 #define	IXL1394_OP_SET_TAGSYNC \
142 		(15 | IXL1394_OPTY_OTHER | IXL1394_OPF_ONXMIT_ENDS)
143 #define	IXL1394_OP_SET_SKIPMODE \
144 		(16 | IXL1394_OPTY_OTHER | IXL1394_OPF_ONXMIT_ENDS)
145 #define	IXL1394_OP_SET_SYNCWAIT \
146 		(17 | IXL1394_OPTY_OTHER | IXL1394_OPF_ONRECV_ENDS)
147 
148 /*
149  * The dynamic UPDATE versions of each updatable command.
150  */
151 #define	IXL1394_OP_JUMP_U	(IXL1394_OP_JUMP | IXL1394_OPF_UPDATE)
152 #define	IXL1394_OP_CALLBACK_U	(IXL1394_OP_CALLBACK | IXL1394_OPF_UPDATE)
153 #define	IXL1394_OP_RECV_PKT_U	(IXL1394_OP_RECV_PKT | IXL1394_OPF_UPDATE)
154 #define	IXL1394_OP_RECV_PKT_ST_U (IXL1394_OP_RECV_PKT_ST | IXL1394_OPF_UPDATE)
155 #define	IXL1394_OP_RECV_BUF_U	(IXL1394_OP_RECV_BUF | IXL1394_OPF_UPDATE)
156 #define	IXL1394_OP_SEND_PKT_U	(IXL1394_OP_SEND_PKT | IXL1394_OPF_UPDATE)
157 #define	IXL1394_OP_SEND_PKT_ST_U (IXL1394_OP_SEND_PKT_ST | IXL1394_OPF_UPDATE)
158 #define	IXL1394_OP_SEND_PKT_WHDR_ST_U (IXL1394_OP_SEND_PKT_WHDR_ST |	\
159 	    IXL1394_OPF_UPDATE)
160 #define	IXL1394_OP_SEND_BUF_U	(IXL1394_OP_SEND_BUF | IXL1394_OPF_UPDATE)
161 #define	IXL1394_OP_SET_TAGSYNC_U (IXL1394_OP_SET_TAGSYNC | IXL1394_OPF_UPDATE)
162 #define	IXL1394_OP_SET_SKIPMODE_U (IXL1394_OP_SET_SKIPMODE | IXL1394_OPF_UPDATE)
163 
164 
165 /* Opaque type for the ixl private data */
166 typedef struct ixl_priv_handle	*ixl1394_priv_t;
167 
168 /* IXL1394_OP_SET_SKIPMODE values (used only with isoch transmit) */
169 typedef enum {
170 	IXL1394_SKIP_TO_SELF	= 0,
171 	IXL1394_SKIP_TO_NEXT	= 1,
172 	IXL1394_SKIP_TO_STOP	= 2,
173 	IXL1394_SKIP_TO_LABEL	= 3
174 } ixl1394_skip_t;
175 
176 /*
177  * IXL Program Command Primitives
178  */
179 
180 /* The general command format.  The operands vary depending on the opcode */
181 typedef struct ixl1394_command {
182 	struct ixl1394_command	*next_ixlp;
183 	ixl1394_priv_t		compiler_privatep;
184 	uint16_t		compiler_resv;
185 	uint16_t		ixl_opcode;
186 	uint32_t		operands[1];
187 } ixl1394_command_t;
188 
189 _NOTE(SCHEME_PROTECTS_DATA("Single thread modifies", \
190 	ixl1394_command::compiler_privatep \
191 	ixl1394_command::compiler_resv))
192 
193 /*
194  * command structure used for a DDI_DMA bound buffer. For portability,
195  * set this _dmac_ll to the buffer's allocated and bound
196  * ddi_dma_cookie_t's _dmac_ll.
197  */
198 typedef union ixl1394_buf_u {
199 	uint64_t		_dmac_ll;	/* 64-bit DMA address */
200 	uint32_t		_dmac_la[2];	/* 2 x 32-bit address */
201 } ixl1394_buf_t;
202 
203 /* shorthand access to IXL command buffers.  similar to defs in dditypes.h */
204 #define	ixldmac_laddr	_dmac_ll
205 #ifdef _LONG_LONG_HTOL
206 #define	ixldmac_notused	_dmac_la[0]
207 #define	ixldmac_addr	_dmac_la[1]
208 #else
209 #define	ixldmac_addr	_dmac_la[0]
210 #define	ixldmac_notused	_dmac_la[1]
211 #endif
212 
213 
214 /*
215  * ixl1394_xfer_pkt
216  * Specifies a packet fragment.
217  * Used with IXL1394_OP_SEND_PKT_ST, IXL1394_OP_SEND_PKT_WHDR_ST,
218  * IXL1394_OP_SEND_PKT, IXL1394_OP_RECV_PKT_ST and IXL1394_OP_RECV_PKT.
219  */
220 typedef struct ixl1394_xfer_pkt {
221 	ixl1394_command_t	*next_ixlp;
222 	ixl1394_priv_t		compiler_privatep;
223 	uint16_t		compiler_resv;
224 	uint16_t		ixl_opcode;
225 	uint16_t		size;		/* bytes in ixl_buf */
226 	uint16_t		resv;
227 	ixl1394_buf_t		ixl_buf;	/* ddi_dma bound address */
228 	caddr_t			mem_bufp;	/* kernel virtual addr */
229 } ixl1394_xfer_pkt_t;
230 
231 _NOTE(SCHEME_PROTECTS_DATA("Single thread modifies", \
232 	ixl1394_xfer_pkt::ixl_buf._dmac_ll \
233         ixl1394_xfer_pkt::ixl_buf._dmac_la \
234         ixl1394_xfer_pkt::mem_bufp \
235         ixl1394_xfer_pkt::size))
236 
237 /*
238  * ixl1394_xfer_buf
239  * Specifies a buffer of multiple packets.
240  * Used with IXL1394_OP_SEND_BUF and IXL1394_OP_RECV_BUF.
241  */
242 typedef struct ixl1394_xfer_buf {
243 	ixl1394_command_t	*next_ixlp;
244 	ixl1394_priv_t		compiler_privatep;
245 	uint16_t		compiler_resv;
246 	uint16_t		ixl_opcode;
247 	uint16_t		size;		/* bytes in ixl_buf */
248 	uint16_t		pkt_size;	/* bytes in each packet */
249 	ixl1394_buf_t		ixl_buf;	/* ddi_dma bound address */
250 	caddr_t			mem_bufp;	/* kernel (not bound) addrss */
251 } ixl1394_xfer_buf_t;
252 
253 _NOTE(SCHEME_PROTECTS_DATA("Single thread modifies", \
254 	ixl1394_xfer_buf::compiler_privatep \
255 	ixl1394_xfer_buf::ixl_buf._dmac_ll \
256 	ixl1394_xfer_buf::ixl_buf._dmac_la \
257 	ixl1394_xfer_buf::mem_bufp \
258 	ixl1394_xfer_buf::pkt_size \
259 	ixl1394_xfer_buf::size))
260 
261 /*
262  * ixl1394_xmit_special
263  * Specifies how many cycles are to be skipped before the next packet
264  * is sent.  Specifies number of header only packets to be sent, next.
265  * Used with IXL1394_OP_SEND_HDR_ONLY and IXL1394_OP_SEND_NO_PKT.
266  */
267 typedef struct ixl1394_xmit_special {
268 	ixl1394_command_t	*next_ixlp;
269 	ixl1394_priv_t		compiler_privatep;
270 	uint16_t		compiler_resv;
271 	uint16_t		ixl_opcode;
272 	uint16_t		count;
273 	uint16_t		resv;
274 } ixl1394_xmit_special_t;
275 
276 /*
277  * ixl1394_callback
278  * Specifies a callback function and callback data.
279  * When the callback is invoked, it is passed the addr of this IXL
280  * command, which it can use to retrieve the arg it has stored in
281  * this struct. Used with IXL1394_OP_CALLBACK.
282  */
283 typedef struct ixl1394_callback {
284 	ixl1394_command_t   *next_ixlp;
285 	ixl1394_priv_t	    compiler_privatep;
286 	uint16_t	    compiler_resv;
287 	uint16_t	    ixl_opcode;
288 	void		    (*callback)(opaque_t, struct ixl1394_callback *);
289 	opaque_t	    callback_arg;
290 } ixl1394_callback_t;
291 
292 _NOTE(SCHEME_PROTECTS_DATA("Single thread modifies", \
293         ixl1394_callback::callback \
294 	ixl1394_callback::callback_arg))
295 
296 /*
297  * ixl1394_label
298  * Specifies a label (location) which can be used as the target of a jump.
299  * Used with IXL1394_OP_LABEL.
300  */
301 typedef struct ixl1394_label {
302 	ixl1394_command_t	*next_ixlp;
303 	ixl1394_priv_t		compiler_privatep;
304 	uint16_t		compiler_resv;
305 	uint16_t		ixl_opcode;
306 } ixl1394_label_t;
307 
308 /*
309  * ixl1394_jump
310  * Specifies a label (location) which can then be used as the target of a jump.
311  * Used with IXL1394_OP_JUMP.
312  */
313 typedef struct ixl1394_jump {
314 	ixl1394_command_t	*next_ixlp;
315 	ixl1394_priv_t		compiler_privatep;
316 	uint16_t		compiler_resv;
317 	uint16_t		ixl_opcode;
318 	ixl1394_command_t	*label;
319 } ixl1394_jump_t;
320 
321 _NOTE(SCHEME_PROTECTS_DATA("Single thread modifies", \
322 	ixl1394_jump::label))
323 
324 /*
325  * ixl1394_set_tagsync
326  * Specifies the tag and sync bits used for the port.
327  * Used with IXL1394_OP_SET_TAGSYNC.
328  */
329 typedef struct ixl1394_set_tagsync {
330 	ixl1394_command_t	*next_ixlp;
331 	ixl1394_priv_t		compiler_privatep;
332 	uint16_t		compiler_resv;
333 	uint16_t		ixl_opcode;
334 	uint16_t		tag;
335 	uint16_t		sync;
336 } ixl1394_set_tagsync_t;
337 
338 _NOTE(SCHEME_PROTECTS_DATA("Single thread modifies", \
339 	ixl1394_set_tagsync::sync \
340 	ixl1394_set_tagsync::tag))
341 
342 /*
343  * ixl1394_set_skipmode
344  * Specifies the tag and sync bits used for the port.
345  * Used with IXL1394_OP_SET_SKIPMODE.
346  */
347 typedef struct ixl1394_set_skipmode {
348 	ixl1394_command_t	*next_ixlp;
349 	ixl1394_priv_t		compiler_privatep;
350 	uint16_t		compiler_resv;
351 	uint16_t		ixl_opcode;
352 	ixl1394_command_t 	*label;
353 	ixl1394_skip_t		skipmode;
354 } ixl1394_set_skipmode_t;
355 
356 _NOTE(SCHEME_PROTECTS_DATA("Single thread modifies", \
357 	ixl1394_set_skipmode::compiler_privatep \
358 	ixl1394_set_skipmode::label \
359 	ixl1394_set_skipmode::skipmode))
360 
361 /*
362  * ixl1394_set_syncwait
363  * Specifies that next receive is to wait for sync before accepting input.
364  * Used with IXL1394_OP_SET_SYNCWAIT.
365  */
366 typedef struct ixl1394_set_syncwait {
367 	ixl1394_command_t	*next_ixlp;
368 	ixl1394_priv_t		compiler_privatep;
369 	uint16_t		compiler_resv;
370 	uint16_t		ixl_opcode;
371 } ixl1394_set_syncwait_t;
372 
373 /*
374  * ixl1394_store_timestamp
375  * Specifies that the timestamp value of the most recently sent
376  * packet be stored into the timestamp field of this ixl command.
377  * Used with IXL1394_OP_STORE_TIMESTAMP.
378  */
379 typedef struct ixl1394_store_timestamp {
380 	ixl1394_command_t	*next_ixlp;
381 	ixl1394_priv_t		compiler_privatep;
382 	uint16_t		compiler_resv;
383 	uint16_t		ixl_opcode;
384 	uint16_t		timestamp;
385 	uint16_t		resv;
386 } ixl1394_store_timestamp_t;
387 
388 _NOTE(SCHEME_PROTECTS_DATA("Single thread modifies", \
389 	ixl1394_store_timestamp::timestamp))
390 
391 /*
392  * Macros for extracting isochronous packet header fields when receiving
393  * packets via IXL1394_OP_RECV_PKT_ST or IXL1394_OP_RECV_BUF with
394  * ID1394_RECV_HEADERS mode enabled.
395  * The argument to each macro is a quadlet of data.
396  * Prior to using the macro, target drivers first retrieve this quadlet from
397  * bound memory by using ddi_get32(9F).
398  */
399 
400 /*
401  * timestamp is the first quadlet in an IXL1394_OP_RECV_PKT_ST packet, and is
402  * the last quadlet (after the data payload) in an IXL1394_OP_RECV_BUF packet.
403  */
404 #define	IXL1394_GET_IR_TIMESTAMP(PKT_QUADLET) ((PKT_QUADLET) & 0x0000FFFF)
405 
406 /*
407  * the following macros apply to the second quadlet in an
408  * IXL1394_OP_RECV_PKT_ST packet, and the first quadlet in an
409  * IXL1394_OP_RECV_BUF packet.
410  */
411 #define	IXL1394_GET_IR_DATALEN(PKT_QUADLET) (((PKT_QUADLET) & 0xFFFF0000) >> 16)
412 #define	IXL1394_GET_IR_TAG(PKT_QUADLET)	    (((PKT_QUADLET) & 0x0000C000) >> 14)
413 #define	IXL1394_GET_IR_CHAN(PKT_QUADLET)    (((PKT_QUADLET) & 0x00003F00) >> 8)
414 #define	IXL1394_GET_IR_SYNC(PKT_QUADLET)    ((PKT_QUADLET) & 0x0000000F)
415 
416 #ifdef __cplusplus
417 }
418 #endif
419 
420 #endif	/* _SYS_1394_IXL1394_H */
421