1 #ifndef _GPXE_INFINIBAND_H
2 #define _GPXE_INFINIBAND_H
11 #include <gpxe/netdevice.h>
13 /** An Infiniband Global Identifier */
18 /** An Infiniband Global Route Header */
19 struct ib_global_route_header {
20 /** IP version, traffic class, and flow label
22 * 4 bits : Version of the GRH
23 * 8 bits : Traffic class
24 * 20 bits : Flow label
26 uint32_t ipver_tclass_flowlabel;
35 /** Destiniation GID */
37 } __attribute__ (( packed ));
39 /** Infiniband MAC address length */
42 /** An Infiniband MAC address */
46 * MSB must be zero; QPNs are only 24-bit.
51 } __attribute__ (( packed ));
53 /** Infiniband link-layer header length */
56 /** An Infiniband link-layer header */
58 /** Network-layer protocol */
60 /** Reserved, must be zero */
62 } __attribute__ (( packed ));
68 struct ib_completion_queue;
70 /** An Infiniband Work Queue */
71 struct ib_work_queue {
72 /** Containing queue pair */
73 struct ib_queue_pair *qp;
74 /** "Is a send queue" flag */
76 /** Associated completion queue */
77 struct ib_completion_queue *cq;
78 /** List of work queues on this completion queue */
79 struct list_head list;
80 /** Number of work queue entries */
81 unsigned int num_wqes;
82 /** Next work queue entry index
84 * This is the index of the next entry to be filled (i.e. the
85 * first empty entry). This value is not bounded by num_wqes;
86 * users must logical-AND with (num_wqes-1) to generate an
89 unsigned long next_idx;
90 /** I/O buffers assigned to work queue */
91 struct io_buffer **iobufs;
92 /** Device private data */
96 /** An Infiniband Queue Pair */
97 struct ib_queue_pair {
98 /** Queue Pair Number */
101 struct ib_work_queue send;
103 struct ib_work_queue recv;
104 /** Device private data */
106 /** Queue owner private data */
110 /** An Infiniband Completion Queue */
111 struct ib_completion_queue {
112 /** Completion queue number */
114 /** Number of completion queue entries */
115 unsigned int num_cqes;
116 /** Next completion queue entry index
118 * This is the index of the next entry to be filled (i.e. the
119 * first empty entry). This value is not bounded by num_wqes;
120 * users must logical-AND with (num_wqes-1) to generate an
123 unsigned long next_idx;
124 /** List of work queues completing to this queue */
125 struct list_head work_queues;
126 /** Device private data */
130 /** An Infiniband completion */
131 struct ib_completion {
134 * If non-zero, then the completion is in error.
136 unsigned int syndrome;
141 /** An Infiniband completion handler
143 * @v ibdev Infiniband device
145 * @v completion Completion
146 * @v iobuf I/O buffer
148 typedef void ( * ib_completer_t ) ( struct ib_device *ibdev,
149 struct ib_queue_pair *qp,
150 struct ib_completion *completion,
151 struct io_buffer *iobuf );
153 /** An Infiniband Address Vector */
154 struct ib_address_vector {
155 /** Destination Queue Pair */
156 unsigned int dest_qp;
159 /** Destination Local ID */
165 /** GID is present */
166 unsigned int gid_present;
172 * Infiniband device operations
174 * These represent a subset of the Infiniband Verbs.
176 struct ib_device_operations {
177 /** Create completion queue
179 * @v ibdev Infiniband device
180 * @v cq Completion queue
181 * @ret rc Return status code
183 int ( * create_cq ) ( struct ib_device *ibdev,
184 struct ib_completion_queue *cq );
185 /** Destroy completion queue
187 * @v ibdev Infiniband device
188 * @v cq Completion queue
190 void ( * destroy_cq ) ( struct ib_device *ibdev,
191 struct ib_completion_queue *cq );
192 /** Create queue pair
194 * @v ibdev Infiniband device
196 * @ret rc Return status code
198 int ( * create_qp ) ( struct ib_device *ibdev,
199 struct ib_queue_pair *qp );
200 /** Destroy queue pair
202 * @v ibdev Infiniband device
205 void ( * destroy_qp ) ( struct ib_device *ibdev,
206 struct ib_queue_pair *qp );
207 /** Post send work queue entry
209 * @v ibdev Infiniband device
211 * @v av Address vector
212 * @v iobuf I/O buffer
213 * @ret rc Return status code
215 * If this method returns success, the I/O buffer remains
216 * owned by the queue pair. If this method returns failure,
217 * the I/O buffer is immediately released; the failure is
218 * interpreted as "failure to enqueue buffer".
220 int ( * post_send ) ( struct ib_device *ibdev,
221 struct ib_queue_pair *qp,
222 struct ib_address_vector *av,
223 struct io_buffer *iobuf );
225 * Post receive work queue entry
227 * @v ibdev Infiniband device
229 * @v iobuf I/O buffer
230 * @ret rc Return status code
232 * If this method returns success, the I/O buffer remains
233 * owned by the queue pair. If this method returns failure,
234 * the I/O buffer is immediately released; the failure is
235 * interpreted as "failure to enqueue buffer".
237 int ( * post_recv ) ( struct ib_device *ibdev,
238 struct ib_queue_pair *qp,
239 struct io_buffer *iobuf );
240 /** Poll completion queue
242 * @v ibdev Infiniband device
243 * @v cq Completion queue
244 * @v complete_send Send completion handler
245 * @v complete_recv Receive completion handler
247 * The completion handler takes ownership of the I/O buffer.
249 void ( * poll_cq ) ( struct ib_device *ibdev,
250 struct ib_completion_queue *cq,
251 ib_completer_t complete_send,
252 ib_completer_t complete_recv );
255 /** An Infiniband device */
257 /** Infiniband operations */
258 struct ib_device_operations *op;
259 /** Device private data */
263 extern struct ib_completion_queue * ib_create_cq ( struct ib_device *ibdev,
264 unsigned int num_cqes );
265 extern void ib_destroy_cq ( struct ib_device *ibdev,
266 struct ib_completion_queue *cq );
267 extern struct ib_queue_pair *
268 ib_create_qp ( struct ib_device *ibdev, unsigned int num_send_wqes,
269 struct ib_completion_queue *send_cq, unsigned int num_recv_wqes,
270 struct ib_completion_queue *recv_cq );
271 extern void ib_destroy_qp ( struct ib_device *ibdev,
272 struct ib_queue_pair *qp );
273 extern struct ib_work_queue * ib_find_wq ( struct ib_completion_queue *cq,
274 unsigned long qpn, int is_send );
278 extern struct ll_protocol infiniband_protocol;
280 extern const char * ib_ntoa ( const void *ll_addr );
283 * Allocate Infiniband device
285 * @v priv_size Size of driver private data
286 * @ret netdev Network device, or NULL
288 static inline struct net_device * alloc_ibdev ( size_t priv_size ) {
289 struct net_device *netdev;
291 netdev = alloc_netdev ( priv_size );
293 netdev->ll_protocol = &infiniband_protocol;
298 #endif /* _GPXE_INFINIBAND_H */