1 /*
2  * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved.
3  * Copyright (c) 2002-2008 Mellanox Technologies LTD. All rights reserved.
4  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5  * Copyright (c) 2012 Lawrence Livermore National Lab.  All rights reserved.
6  *
7  * This software is available to you under a choice of one of two
8  * licenses.  You may choose to be licensed under the terms of the GNU
9  * General Public License (GPL) Version 2, available from the file
10  * COPYING in the main directory of this source tree, or the
11  * OpenIB.org BSD license below:
12  *
13  *     Redistribution and use in source and binary forms, with or
14  *     without modification, are permitted provided that the following
15  *     conditions are met:
16  *
17  *      - Redistributions of source code must retain the above
18  *        copyright notice, this list of conditions and the following
19  *        disclaimer.
20  *
21  *      - Redistributions in binary form must reproduce the above
22  *        copyright notice, this list of conditions and the following
23  *        disclaimer in the documentation and/or other materials
24  *        provided with the distribution.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33  * SOFTWARE.
34  *
35  */
36 
37 /*
38  * Abstract:
39  *    OSM Congestion Control types and prototypes
40  *
41  * Author:
42  *    Albert Chu, LLNL
43  */
44 
45 #ifndef OSM_CONGESTION_CONTROL_H
46 #define OSM_CONGESTION_CONTROL_H
47 
48 #include <iba/ib_types.h>
49 #include <complib/cl_types_osd.h>
50 #include <complib/cl_dispatcher.h>
51 #include <opensm/osm_subnet.h>
52 #include <opensm/osm_log.h>
53 #include <opensm/osm_sm.h>
54 #include <opensm/osm_opensm.h>
55 #include <opensm/osm_base.h>
56 
57 /****s* OpenSM: Base/OSM_DEFAULT_CC_KEY
58  * NAME
59  *       OSM_DEFAULT_CC_KEY
60  *
61  * DESCRIPTION
62  *       Congestion Control Key used by OpenSM.
63  *
64  * SYNOPSIS
65  */
66 #define OSM_DEFAULT_CC_KEY 0
67 
68 #define OSM_CC_DEFAULT_MAX_OUTSTANDING_QUERIES 500
69 
70 #define OSM_CC_TIMEOUT_COUNT_THRESHOLD 3
71 
72 /****s* OpenSM: CongestionControl/osm_congestion_control_t
73 *  This object should be treated as opaque and should
74 *  be manipulated only through the provided functions.
75 */
76 typedef struct osm_congestion_control {
77 	struct osm_opensm *osm;
78 	osm_subn_t *subn;
79 	osm_sm_t *sm;
80 	osm_log_t *log;
81 	osm_mad_pool_t *mad_pool;
82 	atomic32_t trans_id;
83 	osm_vendor_t *vendor;
84 	osm_bind_handle_t bind_handle;
85 	cl_disp_reg_handle_t cc_disp_h;
86 	ib_net64_t port_guid;
87 	atomic32_t outstanding_mads;
88 	atomic32_t outstanding_mads_on_wire;
89 	cl_qlist_t mad_queue;
90 	cl_spinlock_t mad_queue_lock;
91 	cl_event_t cc_poller_wakeup;
92 	cl_event_t outstanding_mads_done_event;
93 	cl_event_t sig_mads_on_wire_continue;
94 	cl_thread_t cc_poller;
95 	osm_thread_state_t thread_state;
96 	ib_sw_cong_setting_t sw_cong_setting;
97 	ib_ca_cong_setting_t ca_cong_setting;
98 	ib_cc_tbl_t cc_tbl[OSM_CCT_ENTRY_MAD_BLOCKS];
99 	unsigned int cc_tbl_mads;
100 } osm_congestion_control_t;
101 /*
102 * FIELDS
103 *       subn
104 *             Subnet object for this subnet.
105 *
106 *       log
107 *             Pointer to the log object.
108 *
109 *       mad_pool
110 *             Pointer to the MAD pool.
111 *
112 *       mad_ctrl
113 *             Mad Controller
114 *********/
115 
116 struct osm_opensm;
117 
118 int osm_congestion_control_setup(struct osm_opensm *osm);
119 
120 int osm_congestion_control_wait_pending_transactions(struct osm_opensm *osm);
121 
122 ib_api_status_t osm_congestion_control_init(osm_congestion_control_t * p_cc,
123 					    struct osm_opensm *osm,
124 					    const osm_subn_opt_t * p_opt);
125 
126 ib_api_status_t osm_congestion_control_bind(osm_congestion_control_t * p_cc,
127 					    ib_net64_t port_guid);
128 
129 void osm_congestion_control_shutdown(osm_congestion_control_t * p_cc);
130 
131 void osm_congestion_control_destroy(osm_congestion_control_t * p_cc);
132 
133 
134 #endif				/* ifndef OSM_CONGESTION_CONTROL_H */
135