blob: 07e922abbf978af9c28b0d27119f3408f6cb8096 [file] [log] [blame]
Shad Ansari2f7f9be2017-06-07 13:34:53 -07001/*
2<:copyright-BRCM:2016:DUAL/GPL:standard
3
4 Broadcom Proprietary and Confidential.(c) 2016 Broadcom
5 All Rights Reserved
6
7Unless you and Broadcom execute a separate written software license
8agreement governing use of this software, this software is licensed
9to you under the terms of the GNU General Public License version 2
10(the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php,
11with the following added to such license:
12
13 As a special exception, the copyright holders of this software give
14 you permission to link this software with independent modules, and
15 to copy and distribute the resulting executable under terms of your
16 choice, provided that you also meet, for each linked independent
17 module, the terms and conditions of the license of that module.
18 An independent module is a module which is not derived from this
19 software. The special exception does not apply to any modifications
20 of the software.
21
22Not withstanding the above, under no circumstances may you combine
23this software in any way with any other Broadcom software provided
24under a license other than the GPL, without Broadcom's express prior
25written consent.
26
27:>
28 */
29#ifndef BCMBAL_APICLI_HELPERS_H_
30#define BCMBAL_APICLI_HELPERS_H_
31
32#include <bcmcli.h>
33#include <bal_api.h>
34#include "bal_api_cli_types.h"
35
36/* Mac name length */
37#define BCMBAL_APICLI_MAX_PARM_NAME_LENGTH BCMCLI_MAX_SEARCH_SUBSTR_LENGTH
38
39/* Max help string length */
40#define BCMBAL_APICLI_MAX_PARM_HELP_LENGTH 128
41
42typedef enum bcmbal_apicli_field_descr_flags
43{
44 BCMBAL_APICLI_FIELD_DESCR_FLAGS_NONE = 0,
45 BCMBAL_APICLI_FIELD_DESCR_FLAGS_PRESENCE_MASK = (1 << 0) /* field is a 'presence mask' for a structure */
46} bcmbal_apicli_field_descr_flags;
47
48typedef struct bcmbal_apicli_type_descr bcmbal_apicli_type_descr;
49
50/* Structure field descriptor */
51typedef struct bcmbal_apicli_field_descr
52{
53 const char *name; /* Field name */
54 const char *descr; /* Field description */
55 const char *cli_name; /* Short CLI name. can be missing */
56 bcmbal_apicli_type_descr *type; /* Field type */
57 uint16_t offset; /* Offset from the beginning of the type structure */
58 bcmbal_apicli_field_descr_flags flags;
59} bcmbal_apicli_field_descr;
60
61/* Data type descriptor */
62struct bcmbal_apicli_type_descr
63{
64 const char *name; /* Type name */
65 const char *descr; /* Type description. can be missing */
66 const char *cli_name; /* Short CLI name. can be missing */
67 bcmbal_apicli_base_type_id base_type; /* Base type: snum, unum, string, ip, enum, etc. */
68 uint32_t min_val; /* Min value for range check */
69 uint32_t max_val; /* Max value for range check */
70 uint16_t size; /* Size */
71
72 /* The following union is qualified by the base_type and contains additional
73 * info for array, enum, struct, union */
74 union
75 {
76 bcmcli_enum_val *e; /* enum value array Contains num_elements+1 values. The last value has name=NULL */
77 struct
78 {
79 uint16_t num_fields; /* number of elements in the following structure */
80 bcmbal_apicli_field_descr *fields; /* Structure field array. Contains num_elements values */
81 } s;
82 struct
83 {
84 uint16_t num_common_fields; /* number of non-union fields at the start of the struct */
85 bcmbal_apicli_field_descr *common_fields; /* common field array. Contains num_elements values */
86 uint16_t classifier_idx; /* index of the classifier field within common_fields */
87 bcmbal_apicli_field_descr *union_fields; /* sub-struct fields under the union (name == NULL if no fields present)
88 (one per enum entry in the classifier type, plus one for default) */
89 } u;
90 struct
91 {
92 bcmbal_apicli_type_descr *elem_type; /* Array element type */
93 uint8_t len_size; /* Byte width of array length field (at start of struct) */
94 uint16_t max_size; /* Max array size */
95 } arr_dyn;
96 struct
97 {
98 bcmbal_apicli_type_descr *elem_type; /* Array element type */
99 uint16_t size; /* Fixed array size */
100 } arr_fixed;
101 } x;
102};
103
104/* Property descriptor.
105 * The 1st 5 fields are exactly the same as in bcmbal_apicli_field_descr
106 * ToDo: replace with bcmbal_apicli_field_descr substructure.
107 * Requires changes in code generator
108 */
109typedef struct
110{
111 const char *name; /* C name */
112 const char *descr; /* Property description */
113 const char *cli_name; /* CLI name */
114 bcmbal_apicli_type_descr *type; /* Type reference */
115 uint16_t offset; /* Offset in generated per-group structure */
116 uint16_t property; /* Property id in per-object management group */
117 bcmbal_apicli_prop_access_id access; /* Access */
118} bcmbal_apicli_prop_descr;
119
120/* All APIs return
121 * BCM_ERR_OK - ok
122 * BCM_ERR_NOENT - if id is in range, but doesn't correspond to any value (a hole)
123 * BCM_ERR_RANGE - id is out of range
124 */
125
126/* Get object name by id */
127bcmos_errno bcmbal_apicli_object_name(bcmbal_obj_id obj, const char **name, const char **descr);
128
129/* Get object structure size */
130bcmos_errno bcmbal_apicli_object_struct_size(bcmbal_obj_id obj, bcmbal_mgt_group group, uint16_t subgroup, uint32_t *key_size, uint32_t *key_offset, uint32_t *data_size, uint32_t *data_offset);
131
132/* Get object subgroup (e.g. specific indication) name and description */
133bcmos_errno bcmbal_apicli_object_subgroup_name(bcmbal_obj_id obj, bcmbal_mgt_group group, uint16_t subgroup, const char **name, const char **descr);
134
135/* Get property by object, mgt_group, subgroup (e.g. specific indication), property_id */
136bcmos_errno bcmbal_apicli_object_property(bcmbal_obj_id obj, bcmbal_mgt_group group, uint16_t subgroup, uint16_t prop, const bcmbal_apicli_prop_descr **descr);
137
138/* Get the number of subgroups present for a given group */
139static inline uint16_t bcmbal_apicli_get_subgroup_count(bcmbal_obj_id obj, bcmbal_mgt_group group)
140{
141 uint16_t count = 0;
142 uint32_t dummy;
143 while (bcmbal_apicli_object_struct_size(obj, group, count, &dummy, &dummy, &dummy, &dummy) != BCM_ERR_RANGE)
144 {
145 ++count;
146 }
147
148 return count;
149}
150
151/* Dump a single property */
152bcmos_errno bcmbal_apicli_dump_prop(bcmcli_session *session, const bcmbal_apicli_prop_descr *pd, void *prop_data);
153
154/* Dump a single property value in C initializer format */
155bcmos_errno bcmbal_apicli_dump_prop_initializer(bcmcli_session *session, const bcmbal_apicli_prop_descr *pd, void *prop_data);
156
157/* Dump message */
158bcmos_errno bcmbal_apicli_msg_dump(bcmcli_session *session, bcmbal_obj *msg);
159
160/* Message group name */
161const char *bcmbal_apicli_mgt_group_to_str(bcmbal_mgt_group group);
162
163/* Convert an enum value to the corresponding string */
164#define BCMOLT_ENUM_STRING_VAL(enum_name, value) bcmcli_enum_stringval(enum_name ## _string_table, (value))
165
166/* Enum string tables */
167extern bcmcli_enum_val bcmbal_access_terminal_cfg_id_string_table[];
168extern bcmcli_enum_val bcmbal_access_terminal_ind_id_string_table[];
169extern bcmcli_enum_val bcmbal_access_terminal_key_id_string_table[];
170extern bcmcli_enum_val bcmbal_action_id_string_table[];
171extern bcmcli_enum_val bcmbal_action_cmd_id_string_table[];
172extern bcmcli_enum_val bcmbal_classifier_id_string_table[];
173extern bcmcli_enum_val bcmbal_pkt_tag_type_string_table[];
174extern bcmcli_enum_val bcmbal_control_string_table[];
175extern bcmcli_enum_val bcmbal_dest_type_string_table[];
176extern bcmcli_enum_val bcmbal_ds_miss_mode_string_table[];
177extern bcmcli_enum_val bcmbal_extra_bw_eligibility_type_string_table[];
178extern bcmcli_enum_val bcmbal_flow_cfg_id_string_table[];
179extern bcmcli_enum_val bcmbal_flow_ind_id_string_table[];
180extern bcmcli_enum_val bcmbal_flow_key_id_string_table[];
181extern bcmcli_enum_val bcmbal_flow_stat_id_string_table[];
182extern bcmcli_enum_val bcmbal_flow_type_string_table[];
183extern bcmcli_enum_val bcmbal_group_cfg_id_string_table[];
184extern bcmcli_enum_val bcmbal_group_key_id_string_table[];
185extern bcmcli_enum_val bcmbal_group_member_cmd_string_table[];
186extern bcmcli_enum_val bcmbal_group_owner_string_table[];
187extern bcmcli_enum_val bcmbal_interface_cfg_id_string_table[];
188extern bcmcli_enum_val bcmbal_interface_ind_id_string_table[];
189extern bcmcli_enum_val bcmbal_interface_key_id_string_table[];
190extern bcmcli_enum_val bcmbal_interface_stat_id_string_table[];
191extern bcmcli_enum_val bcmbal_intf_type_string_table[];
192extern bcmcli_enum_val bcmbal_iwf_mode_string_table[];
193extern bcmcli_enum_val bcmbal_packet_cfg_id_string_table[];
194extern bcmcli_enum_val bcmbal_packet_ind_id_string_table[];
195extern bcmcli_enum_val bcmbal_packet_key_id_string_table[];
196extern bcmcli_enum_val bcmbal_sla_id_string_table[];
197extern bcmcli_enum_val bcmbal_state_string_table[];
198extern bcmcli_enum_val bcmbal_status_string_table[];
199extern bcmcli_enum_val bcmbal_subscriber_terminal_cfg_id_string_table[];
200extern bcmcli_enum_val bcmbal_subscriber_terminal_ind_id_string_table[];
201extern bcmcli_enum_val bcmbal_subscriber_terminal_key_id_string_table[];
202extern bcmcli_enum_val bcmbal_subscriber_terminal_stat_id_string_table[];
203extern bcmcli_enum_val bcmbal_tm_bac_type_string_table[];
204extern bcmcli_enum_val bcmbal_tm_creation_mode_string_table[];
205extern bcmcli_enum_val bcmbal_tm_queue_cfg_id_string_table[];
206extern bcmcli_enum_val bcmbal_tm_queue_ind_id_string_table[];
207extern bcmcli_enum_val bcmbal_tm_queue_key_id_string_table[];
208extern bcmcli_enum_val bcmbal_tm_queue_stat_id_string_table[];
209extern bcmcli_enum_val bcmbal_tm_sched_cfg_id_string_table[];
210extern bcmcli_enum_val bcmbal_tm_sched_child_type_string_table[];
211extern bcmcli_enum_val bcmbal_tm_sched_dir_string_table[];
212extern bcmcli_enum_val bcmbal_tm_sched_ind_id_string_table[];
213extern bcmcli_enum_val bcmbal_tm_sched_key_id_string_table[];
214extern bcmcli_enum_val bcmbal_tm_sched_owner_type_string_table[];
215extern bcmcli_enum_val bcmbal_tm_sched_owner_agg_port_id_string_table[];
216extern bcmcli_enum_val bcmbal_tm_sched_parent_id_string_table[];
217extern bcmcli_enum_val bcmbal_tm_sched_type_string_table[];
218extern bcmcli_enum_val bcmbal_tm_shaping_id_string_table[];
219extern bcmcli_enum_val bcmbal_tm_tcont_sla_id_string_table[];
220extern bcmcli_enum_val bcmbal_trx_type_string_table[];
221#endif /* BCMBAL_APICLI_HELPERS_H_ */