1219820Sjeff/*
2219820Sjeff * Copyright (c) 2001-2005 Mellanox Technologies LTD. All rights reserved.
3219820Sjeff * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
4219820Sjeff *
5219820Sjeff * This software is available to you under a choice of one of two
6219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
7219820Sjeff * General Public License (GPL) Version 2, available from the file
8219820Sjeff * COPYING in the main directory of this source tree, or the
9219820Sjeff * OpenIB.org BSD license below:
10219820Sjeff *
11219820Sjeff *     Redistribution and use in source and binary forms, with or
12219820Sjeff *     without modification, are permitted provided that the following
13219820Sjeff *     conditions are met:
14219820Sjeff *
15219820Sjeff *      - Redistributions of source code must retain the above
16219820Sjeff *        copyright notice, this list of conditions and the following
17219820Sjeff *        disclaimer.
18219820Sjeff *
19219820Sjeff *      - Redistributions in binary form must reproduce the above
20219820Sjeff *        copyright notice, this list of conditions and the following
21219820Sjeff *        disclaimer in the documentation and/or other materials
22219820Sjeff *        provided with the distribution.
23219820Sjeff *
24219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31219820Sjeff * SOFTWARE.
32219820Sjeff *
33219820Sjeff */
34219820Sjeff
35219820Sjeff/*
36219820Sjeff *    mad.h -
37219820Sjeff *      Header file for common special QP resources creation code.
38219820Sjeff *
39219820Sjeff *  Creation date:
40219820Sjeff *
41219820Sjeff *  Version: osmt_mtl_regular_qp.h,v 1.2 2003/03/20 16:05:10 eitan
42219820Sjeff *
43219820Sjeff *  Authors:
44219820Sjeff *    Elazar Raab
45219820Sjeff *
46219820Sjeff *  Changes:
47219820Sjeff */
48219820Sjeff
49219820Sjeff#ifndef H_MAD_H
50219820Sjeff#define H_MAD_H
51219820Sjeff
52219820Sjeff#include <vapi.h>
53219820Sjeff#include <evapi.h>
54219820Sjeff#include <vapi_common.h>
55219820Sjeff#include <ib_defs.h>
56219820Sjeff
57219820Sjeff#if defined(MAD_IN) || defined(MAD_OUT)
58219820Sjeff#error MACROS MAD_IN and MAD_OUT are in use, do not override
59219820Sjeff#endif
60219820Sjeff#define MAD_IN
61219820Sjeff#define MAD_OUT
62219820Sjeff
63219820Sjeff/* HCA Constants */
64219820Sjeff#define HCA_ID     "mt21108_pci0"
65219820Sjeff#define GRH_LEN 40
66219820Sjeff#define KNOWN_QP1_QKEY 0x80010000
67219820Sjeff
68219820Sjeff#define MAX_OUTS_SQ   2		/* Max. buffers posted for requests in SQ */
69219820Sjeff#define MAX_OUTS_RQ   5		/* Max. buffers posted for responses in RQ */
70219820Sjeff
71219820Sjeff#define MAX_POLL_CNT    300
72219820Sjeff#define POLL_SLEEP      1	/* for usleep */
73219820Sjeff
74219820Sjeff#define MAD_SIZE  		256	/* MADs are always 256B */
75219820Sjeff#define MAD_ATTR_OFFSET 16
76219820Sjeff#define MAD_TID_OFFSET  8
77219820Sjeff
78219820Sjeff/* Verbs SQP resources handles */
79219820Sjefftypedef struct {
80219820Sjeff	VAPI_hca_id_t hca_id;	/*id of HCA */
81219820Sjeff	u_int8_t port_num;	/* the port num to use */
82219820Sjeff	VAPI_hca_hndl_t hca_hndl;	/*handle of HCA */
83219820Sjeff	VAPI_qp_hndl_t qp_hndl;	/*handle of QP I use */
84219820Sjeff	VAPI_mr_hndl_t mr_hndl;	/*handle of memory region */
85219820Sjeff	VAPI_cq_hndl_t rq_cq_hndl, sq_cq_hndl;	/*handle of send & receive completion Queues */
86219820Sjeff	VAPI_pd_hndl_t pd_hndl;	/*handle of Partition Domain */
87219820Sjeff	/* VAPI_ud_av_hndl_t   av_hndl; */
88219820Sjeff	IB_lid_t slid;
89219820Sjeff	 /*LID*/ void *buf_ptr;	/*mem buffer for outstanding pkts */
90219820Sjeff	MT_size_t buf_size;	/*size of mem buffer for outstanding pkts */
91219820Sjeff
92219820Sjeff	u_int32_t max_outs_sq;	/*max # of outstanding pkts in send queue */
93219820Sjeff	u_int32_t max_outs_rq;	/*max # of outstanding pkts in receive queue */
94219820Sjeff
95219820Sjeff	IB_rkey_t l_key;	/*my l_key for memory regions */
96219820Sjeff	VAPI_qkey_t qkey;	/*my qkey */
97219820Sjeff
98219820Sjeff	EVAPI_compl_handler_hndl_t rq_cq_eventh, sq_cq_eventh;	/* event handlers for polling */
99219820Sjeff
100219820Sjeff	bool is_sqp;		/* relate to union below - my QP */
101219820Sjeff	union {
102219820Sjeff		VAPI_special_qp_t sqp_type;
103219820Sjeff		VAPI_qp_num_t qp_num;
104219820Sjeff	} qp_id;
105219820Sjeff	void *wait_q;
106219820Sjeff} osmt_mtl_mad_res_t;
107219820Sjeff
108219820Sjeff/* init an osmt_mtl_mad_res_t with all resources initialized (use functions below) */
109219820SjeffVAPI_ret_t osmt_mtl_init(osmt_mtl_mad_res_t * res	/*pointer to res (resources) struct */
110219820Sjeff    );
111219820SjeffVAPI_ret_t osmt_mtl_init_opened_hca(osmt_mtl_mad_res_t * res	/*pointer to res (resources) struct */
112219820Sjeff    );
113219820Sjeff
114219820Sjeff/* Cleanup all resources of (which are valid) in res */
115219820SjeffVAPI_ret_t osmt_mtl_mad_cleanup(osmt_mtl_mad_res_t * res	/*pointer to res (resources) struct */
116219820Sjeff    );
117219820Sjeff
118219820Sjeff/* create CQs and QP as given in res->is_sqp (if TRUE, get special QP) */
119219820SjeffVAPI_ret_t osmt_mtl_get_qp_resources(osmt_mtl_mad_res_t * res	/*pointer to res (resources) struct */
120219820Sjeff    );
121219820Sjeff
122219820Sjeff/* move QP to RTS state */
123219820SjeffVAPI_ret_t osmt_mtl_mad_qp_init(osmt_mtl_mad_res_t * res	/*max number of outstanding packets allowed in send queue */
124219820Sjeff    );
125219820Sjeff
126219820Sjeff/* create and register res->buf_ptr */
127219820SjeffVAPI_ret_t osmt_mtl_mad_create_mr(osmt_mtl_mad_res_t * res	/*pointer to res (resources) struct */
128219820Sjeff    );
129219820Sjeff
130219820SjeffVAPI_ret_t osmt_mtl_create_av(osmt_mtl_mad_res_t * res,	/* pointer to res (resources) struct */
131219820Sjeff			      int16_t dlid,	/*destination lid */
132219820Sjeff			      VAPI_ud_av_hndl_t * avh_p	/* address vectr handle to update */
133219820Sjeff    );
134219820Sjeff
135219820Sjeff/* Send MAD to given dest QP*/
136219820SjeffVAPI_ret_t osmt_mtl_mad_send(osmt_mtl_mad_res_t * res,	/*pointer to res (resources) struct */
137219820Sjeff			     VAPI_wr_id_t id,	/*wqe ID */
138219820Sjeff			     void *mad,	/*mad buffer to send */
139219820Sjeff			     VAPI_qp_num_t dest_qp,	/*destination QP */
140219820Sjeff			     IB_sl_t sl,	/*Service Level */
141219820Sjeff			     u_int32_t dest_qkey,	/*Destination QP KEY */
142219820Sjeff			     VAPI_ud_av_hndl_t avh	/* address vectr handle to use */
143219820Sjeff    );
144219820Sjeff
145219820Sjeff/* post buffers to RQ. returns num of buffers actually posted */
146219820Sjeffint osmt_mtl_mad_post_recv_bufs(osmt_mtl_mad_res_t * res,	/*pointer to res (resources) struct */
147219820Sjeff				void *buf_array,	/*array of receive buffers */
148219820Sjeff				u_int32_t num_o_bufs,	/*number of receive buffers */
149219820Sjeff				u_int32_t size,	/* size of expected receive packet - MAD */
150219820Sjeff				VAPI_wr_id_t start_id	/* start id for receive buffers */
151219820Sjeff    );
152219820Sjeff
153219820Sjeff/* Poll given CQ for completion max_poll times (POLL_SLEEP [usec] delays). result in wc_desc_p. */
154219820SjeffVAPI_ret_t osmt_mtl_mad_poll4cqe(VAPI_hca_hndl_t hca,	/*handle for HCA */
155219820Sjeff				 VAPI_cq_hndl_t cq,	/*handle for Completion Queue - Rcv/Send  */
156219820Sjeff				 VAPI_wc_desc_t * wc_desc_p,	/*handle of cqe */
157219820Sjeff				 u_int32_t max_poll,	/*number of polling iterations */
158219820Sjeff				 u_int32_t poll_sleep,	/*timeout for each polling    */
159219820Sjeff				 VAPI_ud_av_hndl_t * avh_p	/* address vectopr handle to cleanup */
160219820Sjeff    );
161219820Sjeff
162219820Sjeff#endif
163