1/*
2 * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved.
3 * Copyright (c) 2002-2012 Mellanox Technologies LTD. All rights reserved.
4 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses.  You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 *     Redistribution and use in source and binary forms, with or
13 *     without modification, are permitted provided that the following
14 *     conditions are met:
15 *
16 *      - Redistributions of source code must retain the above
17 *        copyright notice, this list of conditions and the following
18 *        disclaimer.
19 *
20 *      - Redistributions in binary form must reproduce the above
21 *        copyright notice, this list of conditions and the following
22 *        disclaimer in the documentation and/or other materials
23 *        provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 *
34 */
35
36/*
37 * Abstract:
38 *    Declaration of OSM QoS Policy data types and functions.
39 *
40 * Author:
41 *    Yevgeny Kliteynik, Mellanox
42 */
43
44#ifndef OSM_QOS_POLICY_H
45#define OSM_QOS_POLICY_H
46
47#include <iba/ib_types.h>
48#include <complib/cl_list.h>
49#include <opensm/st.h>
50#include <opensm/osm_port.h>
51#include <opensm/osm_partition.h>
52
53#define YYSTYPE char *
54#define OSM_QOS_POLICY_MAX_PORTS_ON_SWITCH  128
55#define OSM_QOS_POLICY_DEFAULT_LEVEL_NAME   "default"
56
57#define OSM_QOS_POLICY_ULP_SDP_SERVICE_ID   0x0000000000010000ULL
58#define OSM_QOS_POLICY_ULP_RDS_SERVICE_ID   0x0000000001060000ULL
59#define OSM_QOS_POLICY_ULP_RDS_PORT         0x48CA
60#define OSM_QOS_POLICY_ULP_ISER_SERVICE_ID  0x0000000001060000ULL
61#define OSM_QOS_POLICY_ULP_ISER_PORT        0x0CBC
62
63#define OSM_QOS_POLICY_NODE_TYPE_CA        (((uint8_t)1)<<IB_NODE_TYPE_CA)
64#define OSM_QOS_POLICY_NODE_TYPE_SWITCH    (((uint8_t)1)<<IB_NODE_TYPE_SWITCH)
65#define OSM_QOS_POLICY_NODE_TYPE_ROUTER    (((uint8_t)1)<<IB_NODE_TYPE_ROUTER)
66
67/***************************************************/
68
69typedef struct osm_qos_port {
70	cl_map_item_t map_item;
71	osm_physp_t * p_physp;
72} osm_qos_port_t;
73
74typedef struct osm_qos_port_group {
75	char *name;			/* single string (this port group name) */
76	char *use;			/* single string (description) */
77	uint8_t node_types;		/* node types bitmask */
78	cl_qmap_t port_map;
79} osm_qos_port_group_t;
80
81/***************************************************/
82
83typedef struct osm_qos_vlarb_scope {
84	cl_list_t group_list;		/* list of group names (strings) */
85	cl_list_t across_list;		/* list of 'across' group names (strings) */
86	cl_list_t vlarb_high_list;	/* list of num pairs (n:m,...), 32-bit values */
87	cl_list_t vlarb_low_list;	/* list of num pairs (n:m,...), 32-bit values */
88	uint32_t vl_high_limit;		/* single integer */
89	boolean_t vl_high_limit_set;
90} osm_qos_vlarb_scope_t;
91
92/***************************************************/
93
94typedef struct osm_qos_sl2vl_scope {
95	cl_list_t group_list;		/* list of strings (port group names) */
96	boolean_t from[OSM_QOS_POLICY_MAX_PORTS_ON_SWITCH];
97	boolean_t to[OSM_QOS_POLICY_MAX_PORTS_ON_SWITCH];
98	cl_list_t across_from_list;	/* list of strings (port group names) */
99	cl_list_t across_to_list;	/* list of strings (port group names) */
100	uint8_t sl2vl_table[16];	/* array of sl2vl values */
101	boolean_t sl2vl_table_set;
102} osm_qos_sl2vl_scope_t;
103
104/***************************************************/
105
106typedef struct osm_qos_level {
107	char *use;
108	char *name;
109	uint8_t sl;
110	boolean_t sl_set;
111	uint8_t mtu_limit;
112	boolean_t mtu_limit_set;
113	uint8_t rate_limit;
114	boolean_t rate_limit_set;
115	uint8_t pkt_life;
116	boolean_t pkt_life_set;
117	uint64_t **path_bits_range_arr;	/* array of bit ranges (real values are 32bits) */
118	unsigned path_bits_range_len;	/* num of bit ranges in the array */
119	uint64_t **pkey_range_arr;	/* array of PKey ranges (real values are 16bits) */
120	unsigned pkey_range_len;
121} osm_qos_level_t;
122
123
124/***************************************************/
125
126typedef struct osm_qos_match_rule {
127	char *use;
128	cl_list_t source_list;			/* list of strings */
129	cl_list_t source_group_list;		/* list of pointers to relevant port-group */
130	cl_list_t destination_list;		/* list of strings */
131	cl_list_t destination_group_list;	/* list of pointers to relevant port-group */
132	char *qos_level_name;
133	osm_qos_level_t *p_qos_level;
134	uint64_t **service_id_range_arr;	/* array of SID ranges (64-bit values) */
135	unsigned service_id_range_len;
136	uint64_t **qos_class_range_arr;		/* array of QoS Class ranges (real values are 16bits) */
137	unsigned qos_class_range_len;
138	uint64_t **pkey_range_arr;		/* array of PKey ranges (real values are 16bits) */
139	unsigned pkey_range_len;
140} osm_qos_match_rule_t;
141
142/***************************************************/
143
144typedef struct osm_qos_policy {
145	cl_list_t port_groups;			/* list of osm_qos_port_group_t */
146	cl_list_t sl2vl_tables;			/* list of osm_qos_sl2vl_scope_t */
147	cl_list_t vlarb_tables;			/* list of osm_qos_vlarb_scope_t */
148	cl_list_t qos_levels;			/* list of osm_qos_level_t */
149	cl_list_t qos_match_rules;		/* list of osm_qos_match_rule_t */
150	osm_qos_level_t *p_default_qos_level;	/* default QoS level */
151	osm_subn_t *p_subn;			/* osm subnet object */
152	st_table * p_node_hash;			/* node by name hash */
153} osm_qos_policy_t;
154
155/***************************************************/
156
157osm_qos_port_t *osm_qos_policy_port_create(osm_physp_t * p_physp);
158osm_qos_port_group_t * osm_qos_policy_port_group_create();
159void osm_qos_policy_port_group_destroy(osm_qos_port_group_t * p_port_group);
160
161osm_qos_vlarb_scope_t * osm_qos_policy_vlarb_scope_create();
162void osm_qos_policy_vlarb_scope_destroy(osm_qos_vlarb_scope_t * p_vlarb_scope);
163
164osm_qos_sl2vl_scope_t * osm_qos_policy_sl2vl_scope_create();
165void osm_qos_policy_sl2vl_scope_destroy(osm_qos_sl2vl_scope_t * p_sl2vl_scope);
166
167osm_qos_level_t * osm_qos_policy_qos_level_create();
168void osm_qos_policy_qos_level_destroy(osm_qos_level_t * p_qos_level);
169
170boolean_t osm_qos_level_has_pkey(IN const osm_qos_level_t * p_qos_level,
171				 IN ib_net16_t pkey);
172
173ib_net16_t osm_qos_level_get_shared_pkey(IN const osm_qos_level_t * p_qos_level,
174					 IN const osm_physp_t * p_src_physp,
175					 IN const osm_physp_t * p_dest_physp,
176					 IN const boolean_t allow_both_pkeys);
177
178osm_qos_match_rule_t * osm_qos_policy_match_rule_create();
179void osm_qos_policy_match_rule_destroy(osm_qos_match_rule_t * p_match_rule);
180
181osm_qos_policy_t * osm_qos_policy_create(osm_subn_t * p_subn);
182void osm_qos_policy_destroy(osm_qos_policy_t * p_qos_policy);
183int osm_qos_policy_validate(osm_qos_policy_t * p_qos_policy, osm_log_t * p_log);
184
185osm_qos_level_t * osm_qos_policy_get_qos_level_by_pr(
186	IN const osm_qos_policy_t * p_qos_policy,
187	IN const ib_path_rec_t * p_pr,
188	IN const osm_physp_t * p_src_physp,
189	IN const osm_physp_t * p_dest_physp,
190	IN ib_net64_t comp_mask);
191
192osm_qos_level_t * osm_qos_policy_get_qos_level_by_mpr(
193	IN const osm_qos_policy_t * p_qos_policy,
194	IN const ib_multipath_rec_t * p_mpr,
195	IN const osm_physp_t * p_src_physp,
196	IN const osm_physp_t * p_dest_physp,
197	IN ib_net64_t comp_mask);
198
199/***************************************************/
200
201int osm_qos_parse_policy_file(IN osm_subn_t * p_subn);
202
203/***************************************************/
204
205#endif				/* ifndef OSM_QOS_POLICY_H */
206