Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ib_pack.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004 Topspin Corporation. All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses. You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  * Redistribution and use in source and binary forms, with or
11  * without modification, are permitted provided that the following
12  * conditions are met:
13  *
14  * - Redistributions of source code must retain the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer.
17  *
18  * - Redistributions in binary form must reproduce the above
19  * copyright notice, this list of conditions and the following
20  * disclaimer in the documentation and/or other materials
21  * provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32 
33 #ifndef IB_PACK_H
34 #define IB_PACK_H
35 
36 #include <rdma/ib_verbs.h>
37 
38 enum {
45 };
46 
47 struct ib_field {
52  int size_bits;
53  char *field_name;
54 };
55 
56 #define RESERVED \
57  .field_name = "reserved"
58 
59 /*
60  * This macro cleans up the definitions of constants for BTH opcodes.
61  * It is used to define constants such as IB_OPCODE_UD_SEND_ONLY,
62  * which becomes IB_OPCODE_UD + IB_OPCODE_SEND_ONLY, and this gives
63  * the correct value.
64  *
65  * In short, user code should use the constants defined using the
66  * macro rather than worrying about adding together other constants.
67 */
68 #define IB_OPCODE(transport, op) \
69  IB_OPCODE_ ## transport ## _ ## op = \
70  IB_OPCODE_ ## transport + IB_OPCODE_ ## op
71 
72 enum {
73  /* transport types -- just used to define real constants */
74  IB_OPCODE_RC = 0x00,
75  IB_OPCODE_UC = 0x20,
76  IB_OPCODE_RD = 0x40,
77  IB_OPCODE_UD = 0x60,
78 
79  /* operations -- just used to define real constants */
101 
102  /* real constants follow -- see comment about above IB_OPCODE()
103  macro for more details */
104 
105  /* RC */
106  IB_OPCODE(RC, SEND_FIRST),
107  IB_OPCODE(RC, SEND_MIDDLE),
108  IB_OPCODE(RC, SEND_LAST),
109  IB_OPCODE(RC, SEND_LAST_WITH_IMMEDIATE),
110  IB_OPCODE(RC, SEND_ONLY),
111  IB_OPCODE(RC, SEND_ONLY_WITH_IMMEDIATE),
112  IB_OPCODE(RC, RDMA_WRITE_FIRST),
113  IB_OPCODE(RC, RDMA_WRITE_MIDDLE),
114  IB_OPCODE(RC, RDMA_WRITE_LAST),
115  IB_OPCODE(RC, RDMA_WRITE_LAST_WITH_IMMEDIATE),
116  IB_OPCODE(RC, RDMA_WRITE_ONLY),
117  IB_OPCODE(RC, RDMA_WRITE_ONLY_WITH_IMMEDIATE),
118  IB_OPCODE(RC, RDMA_READ_REQUEST),
119  IB_OPCODE(RC, RDMA_READ_RESPONSE_FIRST),
120  IB_OPCODE(RC, RDMA_READ_RESPONSE_MIDDLE),
121  IB_OPCODE(RC, RDMA_READ_RESPONSE_LAST),
122  IB_OPCODE(RC, RDMA_READ_RESPONSE_ONLY),
123  IB_OPCODE(RC, ACKNOWLEDGE),
124  IB_OPCODE(RC, ATOMIC_ACKNOWLEDGE),
125  IB_OPCODE(RC, COMPARE_SWAP),
126  IB_OPCODE(RC, FETCH_ADD),
127 
128  /* UC */
129  IB_OPCODE(UC, SEND_FIRST),
130  IB_OPCODE(UC, SEND_MIDDLE),
131  IB_OPCODE(UC, SEND_LAST),
132  IB_OPCODE(UC, SEND_LAST_WITH_IMMEDIATE),
133  IB_OPCODE(UC, SEND_ONLY),
134  IB_OPCODE(UC, SEND_ONLY_WITH_IMMEDIATE),
135  IB_OPCODE(UC, RDMA_WRITE_FIRST),
136  IB_OPCODE(UC, RDMA_WRITE_MIDDLE),
137  IB_OPCODE(UC, RDMA_WRITE_LAST),
138  IB_OPCODE(UC, RDMA_WRITE_LAST_WITH_IMMEDIATE),
139  IB_OPCODE(UC, RDMA_WRITE_ONLY),
140  IB_OPCODE(UC, RDMA_WRITE_ONLY_WITH_IMMEDIATE),
141 
142  /* RD */
143  IB_OPCODE(RD, SEND_FIRST),
144  IB_OPCODE(RD, SEND_MIDDLE),
145  IB_OPCODE(RD, SEND_LAST),
146  IB_OPCODE(RD, SEND_LAST_WITH_IMMEDIATE),
147  IB_OPCODE(RD, SEND_ONLY),
148  IB_OPCODE(RD, SEND_ONLY_WITH_IMMEDIATE),
149  IB_OPCODE(RD, RDMA_WRITE_FIRST),
150  IB_OPCODE(RD, RDMA_WRITE_MIDDLE),
151  IB_OPCODE(RD, RDMA_WRITE_LAST),
152  IB_OPCODE(RD, RDMA_WRITE_LAST_WITH_IMMEDIATE),
153  IB_OPCODE(RD, RDMA_WRITE_ONLY),
154  IB_OPCODE(RD, RDMA_WRITE_ONLY_WITH_IMMEDIATE),
155  IB_OPCODE(RD, RDMA_READ_REQUEST),
156  IB_OPCODE(RD, RDMA_READ_RESPONSE_FIRST),
157  IB_OPCODE(RD, RDMA_READ_RESPONSE_MIDDLE),
158  IB_OPCODE(RD, RDMA_READ_RESPONSE_LAST),
159  IB_OPCODE(RD, RDMA_READ_RESPONSE_ONLY),
160  IB_OPCODE(RD, ACKNOWLEDGE),
161  IB_OPCODE(RD, ATOMIC_ACKNOWLEDGE),
162  IB_OPCODE(RD, COMPARE_SWAP),
163  IB_OPCODE(RD, FETCH_ADD),
164 
165  /* UD */
166  IB_OPCODE(UD, SEND_ONLY),
167  IB_OPCODE(UD, SEND_ONLY_WITH_IMMEDIATE)
168 };
169 
170 enum {
175 };
176 
185 };
186 
196 };
197 
208 };
209 
213 };
214 
216  u8 dmac_h[4];
217  u8 dmac_l[2];
218  u8 smac_h[2];
219  u8 smac_l[4];
221 };
222 
226 };
227 
228 struct ib_ud_header {
241 };
242 
243 void ib_pack(const struct ib_field *desc,
244  int desc_len,
245  void *structure,
246  void *buf);
247 
248 void ib_unpack(const struct ib_field *desc,
249  int desc_len,
250  void *buf,
251  void *structure);
252 
253 void ib_ud_header_init(int payload_bytes,
254  int lrh_present,
255  int eth_present,
256  int vlan_present,
257  int grh_present,
258  int immediate_present,
259  struct ib_ud_header *header);
260 
262  void *buf);
263 
264 int ib_ud_header_unpack(void *buf,
265  struct ib_ud_header *header);
266 
267 #endif /* IB_PACK_H */