Reformulate the syslink_msg structure a bit. Instead of trying to create
[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.5 2007/03/24 19:11:15 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  * syslink      - Implements a communications end-point and protocol.  A
42  *                syslink is typically directly embedded in a related
43  *                structure.
44  *
45  * syslink_proto- Specifies a set of RPC functions.
46  *
47  * syslink_desc - Specifies a single RPC function within a protocol.
48  */
49
50 #ifndef _SYS_SYSLINK_MSG_H_
51 #define _SYS_SYSLINK_MSG_H_
52
53 #ifndef _SYS_TYPES_H_
54 #include <sys/types.h>
55 #endif
56 #ifndef _MACHINE_ATOMIC_H_
57 #include <machine/atomic.h>
58 #endif
59
60 typedef u_int32_t       sl_msgid_t;
61 typedef u_int16_t       sl_cmd_t;       /* command or error */
62 typedef u_int16_t       sl_itemid_t;    /* item id */
63 typedef u_int16_t       sl_reclen_t;    /* item length */
64
65 #define SL_ALIGN        8               /* 8-byte alignment */
66 #define SL_ALIGNMASK    (SL_ALIGN - 1)
67
68 /*
69  * Stream or FIFO based messaging structures.
70  * 
71  * The reclen is the actual record length in bytes prior to alignment.
72  * The reclen must be aligned to obtain the actual size of a syslink_msg
73  * or syslink_item structure.  Note that the reclen includes structural
74  * headers (i.e. it does not represent just the data payload, it represents
75  * the entire structure).
76  *
77  * Sessions are identified with a session id.  The session id is a rendezvous
78  * id that associates physical and logical routing information with a single
79  * sysid, allowing us to both avoid storing the source and target logical id
80  * in the syslink message AND ALSO providing a unique session id for an
81  * abstracted connection between two entities.  Otherwise the syslink message
82  * would become bloated with five sysid fields instead of the three we have
83  * now.
84  *
85  * Link layer communications is accomplished by specifying a session id of
86  * 0.
87  */
88
89 /*
90  * Raw protocol structures
91  */
92 struct syslink_msg {
93         sl_cmd_t        sm_cmd;         /* protocol command code */
94         sl_reclen_t     sm_bytes;       /* unaligned size of message */
95         sl_msgid_t      sm_msgid;       /* message transaction control */
96         /* minimum syslink_msg size is 8 bytes (special PAD) */
97         sysid_t         sm_sessid;      /* session id */
98         sysid_t         sm_srcphysid;   /* originating physical id */
99         sysid_t         sm_dstphysid;   /* target physical id */
100 };
101
102 #define SL_MIN_MESSAGE_SIZE     offsetof(struct syslink_msg, sm_sessid)
103
104 #define SL_MSGID_REPLY          0x80000000      /* command vs reply */
105 #define SL_MSGID_ORIG           0x40000000      /* originator transaction */
106                                                 /* (else target transaction) */
107 #define SL_MSGID_BEG            0x20000000      /* first msg in transaction */
108 #define SL_MSGID_END            0x10000000      /* last msg in transaction */
109 #define SL_MSGID_STRUCTURED     0x08000000      /* contains structured data */
110 #define SL_MSGID_TRANS_MASK     0x00FFFF00      /* transaction id */
111 #define SL_MSGID_SEQ_MASK       0x000000FF      /* sequence no within trans */
112
113 #define SLMSG_ALIGN(bytes)      (((bytes) + 7) & ~7)
114
115 /*
116  * Syslink message commands (16 bits, bit 15 must be 0)
117  *
118  * Commands 0x0000-0x001F are reserved for the universal link layer, but
119  * except for 0x0000 (which is a PAD message), must still be properly
120  * routed.
121  *
122  * Commands 0x0020-0x002F are reserved for the universal protocol
123  * identification layer.
124  *
125  * Commands 0x0100-0x7FFF are protocol commands.
126  *
127  * The command field is the error return field with bit 15 set in the
128  * reply.
129  */
130 #define SL_CMD_PAD              0x0000
131 #define SL_CMD_LINK_MESH        0x0001  /* mesh construction */
132 #define SL_CMD_LINK_REG         0x0002  /* register logical id */
133 #define SL_CMD_LINK_DEREG       0x0003  /* unregister logical id */
134 #define SL_CMD_LINK_ID          0x0004  /* link level identification */
135
136 #define SL_CMD_PROT_ID          0x0010  /* protocol & device ident */
137
138 /*
139  * Message elements for structured messages.  If SL_MSGID_STRUCTURED is
140  * set the syslink message contains zero or more syslink_elm structures
141  * laid side by side.  Each syslink_elm structure may or may not be 
142  * structured (i.e. recursive).  
143  *
144  * Most of the same SL_MSGID_* bits apply.  The first structured element
145  * will have SL_MSGID_BEG set, the last will have SL_MSGID_END set (if
146  * there is only one element, both bits will be set in that element).  If
147  * the payload is structured, SL_MSGID_STRUCTURED will be set.
148  *
149  * syslink_elm's may use the TRANS and SEQ bits in the msgid for other
150  * purposes.   A syslink_elm is considered to be a PAD if se_cmd == 0.
151  */
152 struct syslink_elm {
153         sl_cmd_t        se_cmd;
154         sl_reclen_t     se_bytes;
155         sl_msgid_t      se_msgid;
156         /* extended by data */
157 };
158
159 typedef struct syslink_msg      *syslink_msg_t;
160 typedef struct syslink_elm      *syslink_elm_t;
161
162 #endif
163