Shad Ansari | 2f7f9be | 2017-06-07 13:34:53 -0700 | [diff] [blame^] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * <:copyright-BRCM:2016:DUAL/GPL:standard |
| 4 | * |
| 5 | * Copyright (c) 2016 Broadcom |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * Unless you and Broadcom execute a separate written software license |
| 9 | * agreement governing use of this software, this software is licensed |
| 10 | * to you under the terms of the GNU General Public License version 2 |
| 11 | * (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php, |
| 12 | * with the following added to such license: |
| 13 | * |
| 14 | * As a special exception, the copyright holders of this software give |
| 15 | * you permission to link this software with independent modules, and |
| 16 | * to copy and distribute the resulting executable under terms of your |
| 17 | * choice, provided that you also meet, for each linked independent |
| 18 | * module, the terms and conditions of the license of that module. |
| 19 | * An independent module is a module which is not derived from this |
| 20 | * software. The special exception does not apply to any modifications |
| 21 | * of the software. |
| 22 | * |
| 23 | * Not withstanding the above, under no circumstances may you combine |
| 24 | * this software in any way with any other Broadcom software provided |
| 25 | * under a license other than the GPL, without Broadcom's express prior |
| 26 | * written consent. |
| 27 | * |
| 28 | * :> |
| 29 | * |
| 30 | *****************************************************************************/ |
| 31 | |
| 32 | #include <bcm_dev_log.h> |
| 33 | #include <bcmcli.h> |
| 34 | #include <bal_objs.h> |
| 35 | #include <bal_api.h> |
| 36 | #include <bcm_topo.h> |
| 37 | #include "rsc_mgr.h" |
| 38 | #include "rsc_mgr_common.h" |
| 39 | #include "rsc_mgr_cli.h" |
| 40 | |
| 41 | static bcmos_errno rsc_mgr_cli_cmd_init(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 42 | { |
| 43 | return rsc_mgr_init(); |
| 44 | } |
| 45 | |
| 46 | static bcmos_errno rsc_mgr_cli_cmd_base_alloc_id_set(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 47 | { |
| 48 | bcmbal_intf_id access_int_id = (bcmbal_intf_id)bcmcli_find_named_parm(session, "key.access_int_id")->value.unumber; |
| 49 | bcmbal_aggregation_port_id min_data_agg_port_id = (bcmbal_aggregation_port_id)bcmcli_find_named_parm(session, "min_data_agg_port_id")->value.unumber; |
| 50 | |
| 51 | return rsc_mgr_access_int_base_alloc_id_set(access_int_id, min_data_agg_port_id); |
| 52 | } |
| 53 | |
| 54 | static bcmos_errno rsc_mgr_cli_cmd_base_gem_set(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 55 | { |
| 56 | bcmbal_intf_id access_int_id = (bcmbal_intf_id)bcmcli_find_named_parm(session, "key.access_int_id")->value.unumber; |
| 57 | bcmbal_service_port_id min_data_svc_port_id = (bcmbal_service_port_id)bcmcli_find_named_parm(session, "min_data_svc_port_id")->value.unumber; |
| 58 | |
| 59 | return rsc_mgr_access_int_base_gem_set(access_int_id, min_data_svc_port_id); |
| 60 | } |
| 61 | |
| 62 | static bcmos_errno rsc_mgr_cli_cmd_alloc_id_alloc(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 63 | { |
| 64 | bcmbal_intf_id access_int_id = (bcmbal_intf_id)bcmcli_find_named_parm(session, "key.access_int_id")->value.unumber; |
| 65 | bcmcli_cmd_parm *agg_port_id_parm = bcmcli_find_named_parm(session, "agg_port_id"); |
| 66 | bcmbal_aggregation_port_id agg_port_id = 0; |
| 67 | uint32_t range_size = (uint32_t)bcmcli_find_named_parm(session, "range_size")->value.unumber; |
| 68 | uint32_t ref_count; |
| 69 | bcmos_errno rc; |
| 70 | |
| 71 | if (agg_port_id_parm) |
| 72 | agg_port_id = (bcmbal_aggregation_port_id)agg_port_id_parm->value.unumber; |
| 73 | |
| 74 | rc = rsc_mgr_alloc_id_alloc(access_int_id, &agg_port_id, range_size, NULL); |
| 75 | if (rc != BCM_ERR_OK) |
| 76 | return rc; |
| 77 | |
| 78 | rc = rsc_mgr_alloc_id_get_ref_count(access_int_id, agg_port_id, &ref_count); |
| 79 | if (rc != BCM_ERR_OK) |
| 80 | return rc; |
| 81 | |
| 82 | bcmcli_session_print(session, "Allocated alloc ID=%u (ref_count=%u)\n", agg_port_id, ref_count); |
| 83 | |
| 84 | return BCM_ERR_OK; |
| 85 | } |
| 86 | |
| 87 | static bcmos_errno rsc_mgr_cli_cmd_alloc_id_free(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 88 | { |
| 89 | bcmbal_intf_id access_int_id = (bcmbal_intf_id)bcmcli_find_named_parm(session, "key.access_int_id")->value.unumber; |
| 90 | bcmbal_aggregation_port_id agg_port_id = (bcmbal_aggregation_port_id)bcmcli_find_named_parm(session, "agg_port_id")->value.unumber; |
| 91 | uint32_t ref_count; |
| 92 | bcmos_errno rc; |
| 93 | |
| 94 | rc = rsc_mgr_alloc_id_get_ref_count(access_int_id, agg_port_id, &ref_count); |
| 95 | if (rc != BCM_ERR_OK) |
| 96 | return rc; |
| 97 | |
| 98 | rc = rsc_mgr_alloc_id_free(access_int_id, agg_port_id, NULL); |
| 99 | if (rc != BCM_ERR_OK) |
| 100 | return rc; |
| 101 | |
| 102 | bcmcli_session_print(session, "Freed alloc ID=%u (ref_count=%u)\n", agg_port_id, ref_count - 1); |
| 103 | |
| 104 | return BCM_ERR_OK; |
| 105 | } |
| 106 | |
| 107 | static bcmos_errno rsc_mgr_cli_cmd_gem_alloc(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 108 | { |
| 109 | bcmbal_intf_id access_int_id = (bcmbal_intf_id)bcmcli_find_named_parm(session, "key.access_int_id")->value.unumber; |
| 110 | bcmcli_cmd_parm *svc_port_id_parm = bcmcli_find_named_parm(session, "svc_port_id"); |
| 111 | bcmbal_service_port_id svc_port_id = 0; |
| 112 | uint32_t range_size = (uint32_t)bcmcli_find_named_parm(session, "range_size")->value.unumber; |
| 113 | rsc_mgr_obj_type gem_type = (rsc_mgr_obj_type)bcmcli_find_named_parm(session, "gem_type")->value.enum_val; |
| 114 | uint32_t ref_count; |
| 115 | bcmos_errno rc; |
| 116 | |
| 117 | if (svc_port_id_parm) |
| 118 | svc_port_id = (bcmbal_service_port_id)svc_port_id_parm->value.unumber; |
| 119 | |
| 120 | if (RSC_MGR_OBJ_TYPE_GEM_PORT_MULTICAST == gem_type) |
| 121 | rc = rsc_mgr_gem_alloc_multicast(access_int_id, &svc_port_id, range_size, NULL); |
| 122 | else if (RSC_MGR_OBJ_TYPE_GEM_PORT_BROADCAST == gem_type) |
| 123 | rc = rsc_mgr_gem_alloc_broadcast(access_int_id, &svc_port_id, range_size, NULL); |
| 124 | else |
| 125 | rc = rsc_mgr_gem_alloc_unicast(access_int_id, &svc_port_id, range_size, NULL); |
| 126 | |
| 127 | if (rc != BCM_ERR_OK) |
| 128 | return rc; |
| 129 | |
| 130 | rc = rsc_mgr_gem_get_ref_count(access_int_id, svc_port_id, &ref_count); |
| 131 | if (rc != BCM_ERR_OK) |
| 132 | return rc; |
| 133 | |
| 134 | bcmcli_session_print(session, "Allocated GEM port=%u (ref_count=%u)\n", svc_port_id, ref_count); |
| 135 | |
| 136 | return BCM_ERR_OK; |
| 137 | } |
| 138 | |
| 139 | static bcmos_errno rsc_mgr_cli_cmd_gem_free(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 140 | { |
| 141 | bcmbal_intf_id access_int_id = (bcmbal_intf_id)bcmcli_find_named_parm(session, "key.access_int_id")->value.unumber; |
| 142 | bcmbal_service_port_id svc_port_id = (bcmbal_service_port_id)bcmcli_find_named_parm(session, "svc_port_id")->value.unumber; |
| 143 | uint32_t ref_count; |
| 144 | bcmos_errno rc; |
| 145 | |
| 146 | rc = rsc_mgr_gem_get_ref_count(access_int_id, svc_port_id, &ref_count); |
| 147 | if (rc != BCM_ERR_OK) |
| 148 | return rc; |
| 149 | |
| 150 | rc = rsc_mgr_gem_free(access_int_id, svc_port_id, NULL); |
| 151 | if (rc != BCM_ERR_OK) |
| 152 | return rc; |
| 153 | |
| 154 | bcmcli_session_print(session, "Freed GEM port=%u (ref_count=%u)\n", svc_port_id, ref_count - 1); |
| 155 | |
| 156 | return BCM_ERR_OK; |
| 157 | } |
| 158 | /*allocates a new tm node auto id |
| 159 | no inputs parameters are used */ |
| 160 | static bcmos_errno rsc_mgr_cli_cmd_tm_sched_auto_alloc(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 161 | { |
| 162 | bcmbal_tm_sched_id tm_sched_auto_id = 0; |
| 163 | bcmos_errno rc; |
| 164 | |
| 165 | rc = _rsc_mgr_tm_sched_auto_id_alloc(&tm_sched_auto_id); |
| 166 | if (rc != BCM_ERR_OK) |
| 167 | return rc; |
| 168 | |
| 169 | |
| 170 | bcmcli_session_print(session, "Allocated TM SCHED AUTO ID %u \n", tm_sched_auto_id); |
| 171 | |
| 172 | return BCM_ERR_OK; |
| 173 | } |
| 174 | |
| 175 | static bcmos_errno rsc_mgr_cli_cmd_tm_sched_auto_free(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 176 | { |
| 177 | bcmbal_tm_sched_id tm_sched_auto_id = (bcmbal_tm_sched_id)bcmcli_find_named_parm(session, "tm_sched_auto_id")->value.unumber; |
| 178 | uint32_t ref_count; |
| 179 | bcmos_errno rc; |
| 180 | |
| 181 | rc = _rsc_mgr_tm_sched_auto_id_get_ref_count(tm_sched_auto_id, &ref_count); |
| 182 | |
| 183 | if (rc != BCM_ERR_OK) |
| 184 | return rc; |
| 185 | |
| 186 | rc = _rsc_mgr_tm_sched_auto_id_free(tm_sched_auto_id); |
| 187 | if (rc != BCM_ERR_OK) |
| 188 | return rc; |
| 189 | |
| 190 | bcmcli_session_print(session, "Freed TM NODE AUTO ID %u (ref_count=%u)\n", tm_sched_auto_id, ref_count - 1); |
| 191 | |
| 192 | return BCM_ERR_OK; |
| 193 | } |
| 194 | |
| 195 | static void rsc_mgr_show_objs_list(bcmcli_session *session, bcmbal_intf_id access_int_id, rsc_mgr_obj_rsc *obj_rsc, |
| 196 | rsc_mgr_obj_list *obj_list) |
| 197 | { |
| 198 | rsc_mgr_obj *obj_iter; |
| 199 | |
| 200 | TAILQ_FOREACH(obj_iter, obj_list, list) |
| 201 | { |
| 202 | if (obj_iter->range_size == 1) |
| 203 | { |
| 204 | bcmcli_session_print(session, "\t%s=%u (obj_type=%s, ref_count=%u)\n", |
| 205 | obj_rsc->obj_name, obj_iter->id, RSC_MGR_OBJ_TYPE_STR(obj_iter->type), obj_iter->ref_count); |
| 206 | } |
| 207 | else |
| 208 | { |
| 209 | bcmcli_session_print(session, "\t%s=%u .. %u (obj_type=%s, ref_count=%u)\n", |
| 210 | obj_rsc->obj_name, obj_iter->id, obj_iter->id + obj_iter->range_size - 1, RSC_MGR_OBJ_TYPE_STR(obj_iter->type), obj_iter->ref_count); |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | static void rsc_mgr_show_objs(bcmcli_session *session, bcmbal_intf_id access_int_id, rsc_mgr_obj_rsc *obj_rsc) |
| 216 | { |
| 217 | bcmcli_session_print(session, "Base data %s=%u\n", obj_rsc->obj_name, obj_rsc->min_data_obj_id); |
| 218 | bcmcli_session_print(session, "Allocated %ss:\n", obj_rsc->obj_name); |
| 219 | rsc_mgr_show_objs_list(session, access_int_id, obj_rsc, &obj_rsc->allocated_objs); |
| 220 | bcmcli_session_print(session, "Free %ss:\n", obj_rsc->obj_name); |
| 221 | rsc_mgr_show_objs_list(session, access_int_id, obj_rsc, &obj_rsc->free_objs); |
| 222 | } |
| 223 | |
| 224 | static bcmos_errno rsc_mgr_show(bcmcli_session *session, bcmbal_intf_id access_int_id) |
| 225 | { |
| 226 | bcmos_errno rc; |
| 227 | rsc_mgr_topo_pon_context *topo_context; |
| 228 | |
| 229 | rc = rsc_mgr_init_validate(); |
| 230 | if (rc != BCM_ERR_OK) |
| 231 | { |
| 232 | BCM_LOG(ERROR, rsc_mgr_log_id, "Resource manager is uninitialized\n"); |
| 233 | return rc; |
| 234 | } |
| 235 | |
| 236 | if (!bcm_topo_pon_is_valid(access_int_id)) |
| 237 | return BCM_ERR_PARM; |
| 238 | |
| 239 | topo_context = RSC_MGR_PON_TOPO_CONTEXT(access_int_id); |
| 240 | rsc_mgr_show_objs(session, access_int_id, &topo_context->alloc_ids); |
| 241 | rsc_mgr_show_objs(session, access_int_id, &topo_context->gems); |
| 242 | |
| 243 | return BCM_ERR_OK; |
| 244 | } |
| 245 | |
| 246 | static bcmos_errno rsc_mgr_cli_cmd_show(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 247 | { |
| 248 | bcmbal_intf_id access_int_id = (bcmbal_intf_id)bcmcli_find_named_parm(session, "key.access_int_id")->value.unumber; |
| 249 | |
| 250 | return rsc_mgr_show(session, access_int_id); |
| 251 | } |
| 252 | |
| 253 | void rsc_mgr_cli_init(bcmcli_entry *cli_dir) |
| 254 | { |
| 255 | bcmcli_entry *dbg_dir; |
| 256 | |
| 257 | static bcmcli_enum_val rsc_mgr_cli_enum_gem_type_table[] = |
| 258 | { |
| 259 | { .name = "unicast", .val = RSC_MGR_OBJ_TYPE_GEM_PORT_UNICAST }, |
| 260 | { .name = "multicast", .val = RSC_MGR_OBJ_TYPE_GEM_PORT_MULTICAST }, |
| 261 | { .name = "broadcast", .val = RSC_MGR_OBJ_TYPE_GEM_PORT_BROADCAST }, |
| 262 | BCMCLI_ENUM_LAST |
| 263 | }; |
| 264 | |
| 265 | dbg_dir = bcmcli_dir_add(cli_dir, "rsc_mgr", "BAL resource manager API access", BCMCLI_ACCESS_ADMIN, NULL); |
| 266 | |
| 267 | BCMCLI_MAKE_CMD(dbg_dir, "init", "Initialize resource manager for a specific access terminal", rsc_mgr_cli_cmd_init, |
| 268 | BCMCLI_MAKE_PARM_RANGE("key.access_term_id", "access terminal identifier", BCMCLI_PARM_UNUMBER, 0, 0, MAX_SUPPORTED_OLTS)); |
| 269 | |
| 270 | BCMCLI_MAKE_CMD(dbg_dir, "base_alloc_id_set", "Set the base alloc ID for an access interface", rsc_mgr_cli_cmd_base_alloc_id_set, |
| 271 | BCMCLI_MAKE_PARM_RANGE("key.access_term_id", "access terminal identifier", BCMCLI_PARM_UNUMBER, 0, 0, MAX_SUPPORTED_OLTS), |
| 272 | BCMCLI_MAKE_PARM("key.access_int_id", "access interface identifier", BCMCLI_PARM_UNUMBER, 0), |
| 273 | BCMCLI_MAKE_PARM("min_data_agg_port_id", "minimal data aggregation port ID", BCMCLI_PARM_UNUMBER, 0)); |
| 274 | |
| 275 | BCMCLI_MAKE_CMD(dbg_dir, "base_gem_set", "Set the base GEM port for an access interface", rsc_mgr_cli_cmd_base_gem_set, |
| 276 | BCMCLI_MAKE_PARM_RANGE("key.access_term_id", "access terminal identifier", BCMCLI_PARM_UNUMBER, 0, 0, MAX_SUPPORTED_OLTS), |
| 277 | BCMCLI_MAKE_PARM("key.access_int_id", "access interface identifier", BCMCLI_PARM_UNUMBER, 0), |
| 278 | BCMCLI_MAKE_PARM("min_data_svc_port_id", "minimal data service port ID", BCMCLI_PARM_UNUMBER, 0)); |
| 279 | |
| 280 | BCMCLI_MAKE_CMD(dbg_dir, "alloc_id_alloc", "Allocate an alloc ID range or reuse an existing alloc ID range", rsc_mgr_cli_cmd_alloc_id_alloc, |
| 281 | BCMCLI_MAKE_PARM_RANGE("key.access_term_id", "access terminal identifier", BCMCLI_PARM_UNUMBER, 0, 0, MAX_SUPPORTED_OLTS), |
| 282 | BCMCLI_MAKE_PARM("key.access_int_id", "access interface identifier", BCMCLI_PARM_UNUMBER, 0), |
| 283 | BCMCLI_MAKE_PARM("agg_port_id", "aggregation port ID (if omitted a new alloc ID is allocated, otherwise we reuse an existing alloc ID)", |
| 284 | BCMCLI_PARM_UNUMBER, BCMCLI_PARM_FLAG_OPTIONAL), |
| 285 | BCMCLI_MAKE_PARM_RANGE("range_size", "range size", BCMCLI_PARM_UNUMBER, 0, RSC_MGR_MIN_RANGE_SIZE, RSC_MGR_MAX_RANGE_SIZE)); |
| 286 | |
| 287 | BCMCLI_MAKE_CMD(dbg_dir, "alloc_id_free", "Free an alloc ID range", rsc_mgr_cli_cmd_alloc_id_free, |
| 288 | BCMCLI_MAKE_PARM_RANGE("key.access_term_id", "access terminal identifier", BCMCLI_PARM_UNUMBER, 0, 0, MAX_SUPPORTED_OLTS), |
| 289 | BCMCLI_MAKE_PARM("key.access_int_id", "access interface identifier", BCMCLI_PARM_UNUMBER, 0), |
| 290 | BCMCLI_MAKE_PARM("agg_port_id", "base of alloc ID range", BCMCLI_PARM_UNUMBER, 0)); |
| 291 | |
| 292 | BCMCLI_MAKE_CMD(dbg_dir, "gem_alloc", "Allocate a GEM port range or reuse an existing GEM port range", rsc_mgr_cli_cmd_gem_alloc, |
| 293 | BCMCLI_MAKE_PARM_RANGE("key.access_term_id", "access terminal identifier", BCMCLI_PARM_UNUMBER, 0, 0, MAX_SUPPORTED_OLTS), |
| 294 | BCMCLI_MAKE_PARM("key.access_int_id", "access interface identifier", BCMCLI_PARM_UNUMBER, 0), |
| 295 | BCMCLI_MAKE_PARM("svc_port_id", "service port ID (if omitted a new GEM port is allocated, otherwise we reuse an existing GEM port)", |
| 296 | BCMCLI_PARM_UNUMBER, BCMCLI_PARM_FLAG_OPTIONAL), |
| 297 | BCMCLI_MAKE_PARM_RANGE("range_size", "range size", BCMCLI_PARM_UNUMBER, 0, RSC_MGR_MIN_RANGE_SIZE, RSC_MGR_MAX_RANGE_SIZE), |
| 298 | BCMCLI_MAKE_PARM_ENUM("gem_type", "GEM type", rsc_mgr_cli_enum_gem_type_table, 0)); |
| 299 | |
| 300 | BCMCLI_MAKE_CMD(dbg_dir, "gem_free", "Free a GEM port range", rsc_mgr_cli_cmd_gem_free, |
| 301 | BCMCLI_MAKE_PARM_RANGE("key.access_term_id", "access terminal identifier", BCMCLI_PARM_UNUMBER, 0, 0, MAX_SUPPORTED_OLTS), |
| 302 | BCMCLI_MAKE_PARM("key.access_int_id", "access interface identifier", BCMCLI_PARM_UNUMBER, 0), |
| 303 | BCMCLI_MAKE_PARM("svc_port_id", "base of GEM port range", BCMCLI_PARM_UNUMBER, 0)); |
| 304 | |
| 305 | BCMCLI_MAKE_CMD_NOPARM(dbg_dir, "tm_sched_auto_id_alloc", "Allocate a tm node auto id or reuse an existing id", rsc_mgr_cli_cmd_tm_sched_auto_alloc); |
| 306 | |
| 307 | BCMCLI_MAKE_CMD(dbg_dir, "tm_sched_auto_id_free", "Free a tm node auto id", rsc_mgr_cli_cmd_tm_sched_auto_free, |
| 308 | BCMCLI_MAKE_PARM("tm_sched_auto_id", "tm node auto id to be free", BCMCLI_PARM_UNUMBER, 0)); |
| 309 | |
| 310 | |
| 311 | BCMCLI_MAKE_CMD(dbg_dir, "show", "Show the database of the resource manager", rsc_mgr_cli_cmd_show, |
| 312 | BCMCLI_MAKE_PARM_RANGE("key.access_term_id", "access terminal identifier", BCMCLI_PARM_UNUMBER, 0, 0, MAX_SUPPORTED_OLTS), |
| 313 | BCMCLI_MAKE_PARM("key.access_int_id", "access interface identifier", BCMCLI_PARM_UNUMBER, 0)); |
| 314 | } |
| 315 | |