osmt_mtl_regular_qp.h revision 303975
1/*
2 * Copyright (c) 2001-2005 Mellanox Technologies LTD. All rights reserved.
3 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses.  You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 *     Redistribution and use in source and binary forms, with or
12 *     without modification, are permitted provided that the following
13 *     conditions are met:
14 *
15 *      - Redistributions of source code must retain the above
16 *        copyright notice, this list of conditions and the following
17 *        disclaimer.
18 *
19 *      - Redistributions in binary form must reproduce the above
20 *        copyright notice, this list of conditions and the following
21 *        disclaimer in the documentation and/or other materials
22 *        provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 *
33 */
34
35/*
36 *    mad.h -
37 *      Header file for common special QP resources creation code.
38 *
39 *  Creation date:
40 *
41 *  Version: osmt_mtl_regular_qp.h,v 1.2 2003/03/20 16:05:10 eitan
42 *
43 *  Authors:
44 *    Elazar Raab
45 *
46 *  Changes:
47 */
48
49#ifndef H_MAD_H
50#define H_MAD_H
51
52#include <vapi.h>
53#include <evapi.h>
54#include <vapi_common.h>
55#include <ib_defs.h>
56
57#if defined(MAD_IN) || defined(MAD_OUT)
58#error MACROS MAD_IN and MAD_OUT are in use, do not override
59#endif
60#define MAD_IN
61#define MAD_OUT
62
63/* HCA Constants */
64#define HCA_ID     "mt21108_pci0"
65#define GRH_LEN 40
66#define KNOWN_QP1_QKEY 0x80010000
67
68#define MAX_OUTS_SQ   2		/* Max. buffers posted for requests in SQ */
69#define MAX_OUTS_RQ   5		/* Max. buffers posted for responses in RQ */
70
71#define MAX_POLL_CNT    300
72#define POLL_SLEEP      1	/* for usleep */
73
74#define MAD_SIZE  		256	/* MADs are always 256B */
75#define MAD_ATTR_OFFSET 16
76#define MAD_TID_OFFSET  8
77
78/* Verbs SQP resources handles */
79typedef struct {
80	VAPI_hca_id_t hca_id;	/*id of HCA */
81	u_int8_t port_num;	/* the port num to use */
82	VAPI_hca_hndl_t hca_hndl;	/*handle of HCA */
83	VAPI_qp_hndl_t qp_hndl;	/*handle of QP I use */
84	VAPI_mr_hndl_t mr_hndl;	/*handle of memory region */
85	VAPI_cq_hndl_t rq_cq_hndl, sq_cq_hndl;	/*handle of send & receive completion Queues */
86	VAPI_pd_hndl_t pd_hndl;	/*handle of Partition Domain */
87	/* VAPI_ud_av_hndl_t   av_hndl; */
88	IB_lid_t slid;
89	 /*LID*/ void *buf_ptr;	/*mem buffer for outstanding pkts */
90	MT_size_t buf_size;	/*size of mem buffer for outstanding pkts */
91
92	u_int32_t max_outs_sq;	/*max # of outstanding pkts in send queue */
93	u_int32_t max_outs_rq;	/*max # of outstanding pkts in receive queue */
94
95	IB_rkey_t l_key;	/*my l_key for memory regions */
96	VAPI_qkey_t qkey;	/*my qkey */
97
98	EVAPI_compl_handler_hndl_t rq_cq_eventh, sq_cq_eventh;	/* event handlers for polling */
99
100	bool is_sqp;		/* relate to union below - my QP */
101	union {
102		VAPI_special_qp_t sqp_type;
103		VAPI_qp_num_t qp_num;
104	} qp_id;
105	void *wait_q;
106} osmt_mtl_mad_res_t;
107
108/* init an osmt_mtl_mad_res_t with all resources initialized (use functions below) */
109VAPI_ret_t osmt_mtl_init(osmt_mtl_mad_res_t * res	/*pointer to res (resources) struct */
110    );
111VAPI_ret_t osmt_mtl_init_opened_hca(osmt_mtl_mad_res_t * res	/*pointer to res (resources) struct */
112    );
113
114/* Cleanup all resources of (which are valid) in res */
115VAPI_ret_t osmt_mtl_mad_cleanup(osmt_mtl_mad_res_t * res	/*pointer to res (resources) struct */
116    );
117
118/* create CQs and QP as given in res->is_sqp (if TRUE, get special QP) */
119VAPI_ret_t osmt_mtl_get_qp_resources(osmt_mtl_mad_res_t * res	/*pointer to res (resources) struct */
120    );
121
122/* move QP to RTS state */
123VAPI_ret_t osmt_mtl_mad_qp_init(osmt_mtl_mad_res_t * res	/*max number of outstanding packets allowed in send queue */
124    );
125
126/* create and register res->buf_ptr */
127VAPI_ret_t osmt_mtl_mad_create_mr(osmt_mtl_mad_res_t * res	/*pointer to res (resources) struct */
128    );
129
130VAPI_ret_t osmt_mtl_create_av(osmt_mtl_mad_res_t * res,	/* pointer to res (resources) struct */
131			      int16_t dlid,	/*destination lid */
132			      VAPI_ud_av_hndl_t * avh_p	/* address vectr handle to update */
133    );
134
135/* Send MAD to given dest QP*/
136VAPI_ret_t osmt_mtl_mad_send(osmt_mtl_mad_res_t * res,	/*pointer to res (resources) struct */
137			     VAPI_wr_id_t id,	/*wqe ID */
138			     void *mad,	/*mad buffer to send */
139			     VAPI_qp_num_t dest_qp,	/*destination QP */
140			     IB_sl_t sl,	/*Service Level */
141			     u_int32_t dest_qkey,	/*Destination QP KEY */
142			     VAPI_ud_av_hndl_t avh	/* address vectr handle to use */
143    );
144
145/* post buffers to RQ. returns num of buffers actually posted */
146int osmt_mtl_mad_post_recv_bufs(osmt_mtl_mad_res_t * res,	/*pointer to res (resources) struct */
147				void *buf_array,	/*array of receive buffers */
148				u_int32_t num_o_bufs,	/*number of receive buffers */
149				u_int32_t size,	/* size of expected receive packet - MAD */
150				VAPI_wr_id_t start_id	/* start id for receive buffers */
151    );
152
153/* Poll given CQ for completion max_poll times (POLL_SLEEP [usec] delays). result in wc_desc_p. */
154VAPI_ret_t osmt_mtl_mad_poll4cqe(VAPI_hca_hndl_t hca,	/*handle for HCA */
155				 VAPI_cq_hndl_t cq,	/*handle for Completion Queue - Rcv/Send  */
156				 VAPI_wc_desc_t * wc_desc_p,	/*handle of cqe */
157				 u_int32_t max_poll,	/*number of polling iterations */
158				 u_int32_t poll_sleep,	/*timeout for each polling    */
159				 VAPI_ud_av_hndl_t * avh_p	/* address vectopr handle to cleanup */
160    );
161
162#endif
163