Merge from vendor branch BINUTILS:
[dragonfly.git] / sys / sys / syslink_msg.h
1 /*
2  * Copyright (c) 2004-2006 The DragonFly Project.  All rights reserved.
3  * 
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
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  * 
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
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  * 
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  * $DragonFly: src/sys/sys/syslink_msg.h,v 1.6 2007/04/03 20:21:19 dillon Exp $
35  */
36 /*
37  * The syslink infrastructure implements an optimized RPC mechanism across a 
38  * communications link.  Endpoints, defined by a sysid, are typically 
39  * associated with system structures but do not have to be.
40  *
41  * This header file is primarily responsible for the formatting of message
42  * traffic over a syslink.
43  */
44
45 #ifndef _SYS_SYSLINK_MSG_H_
46 #define _SYS_SYSLINK_MSG_H_
47
48 #ifndef _SYS_TYPES_H_
49 #include <sys/types.h>
50 #endif
51 #ifndef _MACHINE_ATOMIC_H_
52 #include <machine/atomic.h>
53 #endif
54
55 typedef u_int32_t       sl_msgid_t;     /* transaction sequencing */
56 typedef u_int16_t       sl_cmd_t;       /* command or error */
57 typedef sl_cmd_t        sl_error_t;     
58 typedef u_int16_t       sl_itemid_t;    /* item id */
59 typedef u_int16_t       sl_reclen_t;    /* item length */
60
61 #define SL_ALIGN        8               /* 8-byte alignment */
62 #define SL_ALIGNMASK    (SL_ALIGN - 1)
63
64 /*
65  * Stream or FIFO based messaging structures.
66  * 
67  * The reclen is the actual record length in bytes prior to alignment.
68  * The reclen must be aligned to obtain the actual size of a syslink_msg
69  * or syslink_item structure.  Note that the reclen includes structural
70  * headers (i.e. it does not represent just the data payload, it represents
71  * the entire structure).
72  *
73  * Sessions are identified with a session id.  The session id is a rendezvous
74  * id that associates physical and logical routing information with a single
75  * sysid, allowing us to both avoid storing the source and target logical id
76  * in the syslink message AND ALSO providing a unique session id and validator
77  * which manages the abstracted connection between two entities.  Otherwise
78  * the syslink message would become bloated with five sysid fields instead
79  * of the three we have now.
80  *
81  * Link layer communications is accomplished by specifying a target physical
82  * address of 0.
83  *
84  * The target physical address is deconstructed as the message hops across
85  * the mesh.  All 0's, or all 0's remaining indicates a link layer message
86  * to be processed by the syslink route node itself.  All 1's indicates
87  * a broadcast message.  Broadcast messages also require special attention.
88  * Sending a message to a target address of 0 basically sends it to the
89  * directly connected syslink node. 
90  *
91  * The source physical address normally starts out as 0 and is constructed
92  * as the message hops across the mesh.  The target can use the constructed
93  * source address to respond to the originator of the message (as it must
94  * if it has not knowledge about the session id).  A target with knowledge
95  * of the session id has the option of forging its own return both.
96  */
97
98 /*
99  * Raw protocol structures
100  */
101 struct syslink_msg {
102         sl_cmd_t        sm_cmd;         /* protocol command code */
103         sl_reclen_t     sm_bytes;       /* unaligned size of message */
104         sl_msgid_t      sm_msgid;       /* message transaction control */
105         /* minimum syslink_msg size is 8 bytes (special PAD) */
106         sysid_t         sm_sessid;      /* session id */
107         sysid_t         sm_srcphysid;   /* originating physical id */
108         sysid_t         sm_dstphysid;   /* target physical id */
109 };
110
111 #define SL_MIN_MESSAGE_SIZE     offsetof(struct syslink_msg, sm_sessid)
112
113 #define SL_MSGID_REPLY          0x80000000      /* command vs reply */
114 #define SL_MSGID_ORIG           0x40000000      /* originator transaction */
115                                                 /* (else target transaction) */
116 #define SL_MSGID_BEG            0x20000000      /* first msg in transaction */
117 #define SL_MSGID_END            0x10000000      /* last msg in transaction */
118 #define SL_MSGID_STRUCTURED     0x08000000      /* contains structured data */
119 #define SL_MSGID_COMPLETE       0x04000000      /* msg not under construction */
120 #define SL_MSGID_TRANS_MASK     0x00FFFF00      /* transaction id */
121 #define SL_MSGID_SEQ_MASK       0x000000FF      /* sequence no within trans */
122
123 #define SLMSG_ALIGN(bytes)      (((bytes) + 7) & ~7)
124
125 /*
126  * Syslink message commands (16 bits, bit 15 must be 0)
127  *
128  * Commands 0x0000-0x001F are reserved for the universal link layer, but
129  * except for 0x0000 (which is a PAD message), must still be properly
130  * routed.
131  *
132  * Commands 0x0020-0x002F are reserved for the universal protocol
133  * identification layer.
134  *
135  * Commands 0x0100-0x7FFF are protocol commands.
136  *
137  * The command field is the error return field with bit 15 set in the
138  * reply.
139  */
140 #define SL_CMD_PAD              0x0000
141 #define SL_CMD_LINK_MESH        0x0001  /* mesh construction */
142 #define SL_CMD_LINK_REG         0x0002  /* register logical id */
143 #define SL_CMD_LINK_DEREG       0x0003  /* unregister logical id */
144 #define SL_CMD_LINK_ID          0x0004  /* link level identification */
145
146 #define SL_CMD_PROT_ID          0x0010  /* protocol & device ident */
147
148 /*
149  * Message elements for structured messages.  If SL_MSGID_STRUCTURED is
150  * set the syslink message contains zero or more syslink_elm structures
151  * laid side by side.  Each syslink_elm structure may or may not be 
152  * structured (i.e. recursive).  
153  *
154  * Most of the same SL_MSGID_* bits apply.  The first structured element
155  * will have SL_MSGID_BEG set, the last will have SL_MSGID_END set (if
156  * there is only one element, both bits will be set in that element).  If
157  * the payload is structured, SL_MSGID_STRUCTURED will be set.
158  *
159  * syslink_elm's may use the TRANS and SEQ bits in the msgid for other
160  * purposes.   A syslink_elm is considered to be a PAD if se_cmd == 0.
161  */
162 struct syslink_elm {
163         sl_cmd_t        se_cmd;
164         sl_reclen_t     se_bytes;
165         sl_msgid_t      se_msgid;
166         /* extended by data */
167 };
168
169 typedef struct syslink_msg      *syslink_msg_t;
170 typedef struct syslink_elm      *syslink_elm_t;
171
172 #endif
173