Shad Ansari | 2f7f9be | 2017-06-07 13:34:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | <:copyright-BRCM:2016:DUAL/GPL:standard |
| 3 | |
| 4 | Broadcom Proprietary and Confidential.(c) 2016 Broadcom |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Unless you and Broadcom execute a separate written software license |
| 8 | agreement governing use of this software, this software is licensed |
| 9 | to you under the terms of the GNU General Public License version 2 |
| 10 | (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php, |
| 11 | with 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 | |
| 22 | Not withstanding the above, under no circumstances may you combine |
| 23 | this software in any way with any other Broadcom software provided |
| 24 | under a license other than the GPL, without Broadcom's express prior |
| 25 | written consent. |
| 26 | |
| 27 | :> |
| 28 | */ |
| 29 | |
| 30 | #include <bcmos_system.h> |
| 31 | #include <bcm_dev_log.h> |
| 32 | #include <bcm_dev_log_task_internal.h> |
| 33 | |
| 34 | /* We don't support dev_log CLI in linux kernel space */ |
| 35 | #ifndef __KERNEL__ |
| 36 | |
| 37 | /* Dev log CLI session supports receiving long lines - we shall simply split them into shorter log messages. */ |
| 38 | #define DEV_LOG_CLI_SESSION_MAX_MSG_SIZE (MAX_DEV_LOG_STRING_NET_SIZE * 10) |
| 39 | |
| 40 | enum |
| 41 | { |
| 42 | ID_BY_INDEX, |
| 43 | ID_BY_NAME, |
| 44 | }; |
| 45 | |
| 46 | static bcmos_errno bcm_dev_log_file_print(uint32_t file_index, int32_t xi_msgs_num, bcm_dev_log_print_cb xi_print_callback, void *arg, bcmos_bool clear) |
| 47 | { |
| 48 | bcm_dev_log_file *file; |
| 49 | char log_string[MAX_DEV_LOG_STRING_SIZE]; |
| 50 | int length; |
| 51 | uint32_t num_msgs; |
| 52 | uint32_t i; |
| 53 | uint32_t offset = 0; |
| 54 | bcmos_errno err = BCM_ERR_OK; |
| 55 | |
| 56 | file = bcm_dev_log_file_get(file_index); |
| 57 | if (!file) |
| 58 | return BCM_ERR_PARM; |
| 59 | |
| 60 | num_msgs = bcm_dev_log_get_num_of_messages(file); |
| 61 | if (xi_msgs_num && xi_msgs_num < num_msgs) |
| 62 | num_msgs = xi_msgs_num; |
| 63 | |
| 64 | DEV_LOG_INFO_PRINTF("file=%p, print %d msgs from file (orig: %d)\n", (void *)file, (int)num_msgs, (int)xi_msgs_num); |
| 65 | |
| 66 | /* Print file */ |
| 67 | for (i = 0; (i < xi_msgs_num) || !xi_msgs_num; i++) |
| 68 | { |
| 69 | /* Read from file */ |
| 70 | length = bcm_dev_log_file_read(file, &offset, log_string, sizeof(log_string)); |
| 71 | if (!length) |
| 72 | break; |
| 73 | xi_print_callback(arg, log_string); |
| 74 | } |
| 75 | |
| 76 | if (clear == BCMOS_TRUE) |
| 77 | err = bcm_dev_log_file_clear(file); |
| 78 | |
| 79 | return err; |
| 80 | } |
| 81 | |
| 82 | static const char *dev_log_str_style(bcm_dev_log_style style) |
| 83 | { |
| 84 | static const char *strings[] = |
| 85 | { |
| 86 | [BCM_DEV_LOG_STYLE_NORMAL] = "NORMAL", |
| 87 | [BCM_DEV_LOG_STYLE_BOLD] = "BOLD", |
| 88 | [BCM_DEV_LOG_STYLE_UNDERLINE] = "UNDERLINE", |
| 89 | [BCM_DEV_LOG_STYLE_BLINK] = "BLINK", |
| 90 | [BCM_DEV_LOG_STYLE_REVERSE_VIDEO] = "REVERSE_VIDEO", |
| 91 | }; |
| 92 | return strings[style > BCM_DEV_LOG_STYLE_REVERSE_VIDEO ? BCM_DEV_LOG_STYLE_REVERSE_VIDEO : style]; |
| 93 | } |
| 94 | #ifdef TRIGGER_LOGGER_FEATURE |
| 95 | static void bcm_dev_log_cli_session_print_features(bcmcli_session *session, const char *tabs, const dev_log_id_parm *id_parm) |
| 96 | { |
| 97 | bcmcli_session_print(session, |
| 98 | "%sthrottle : level = %c, threshold = %-5u\n", |
| 99 | tabs, |
| 100 | log_level_str[id_parm->throttle_log_level], |
| 101 | id_parm->throttle.threshold); |
| 102 | |
| 103 | bcmcli_session_print(session, |
| 104 | "%strigger : level = %c, start = %-5u, stop = %-5u, repeat = %-5u\n", |
| 105 | tabs, |
| 106 | log_level_str[id_parm->trigger_log_level], |
| 107 | id_parm->trigger.start_threshold, |
| 108 | id_parm->trigger.stop_threshold, |
| 109 | id_parm->trigger.repeat_threshold); |
| 110 | } |
| 111 | #endif |
| 112 | |
| 113 | static void bcm_dev_log_cli_session_print_id_parm(bcmcli_session *session, const char *tabs, const dev_log_id_parm *id_parm) |
| 114 | { |
| 115 | bcmcli_session_print(session, |
| 116 | "name=%16s, log_type=%u, default_log_type=%u, log_level_print=%c (%u), log_level_save=%c (%u), default_log_level=%c (%u), style=%s (%u), lost_msg_cnt=%u, print_skipped_count=%u\n", |
| 117 | id_parm->name, |
| 118 | id_parm->log_type, |
| 119 | id_parm->default_log_type, |
| 120 | log_level_str[id_parm->log_level_print], |
| 121 | id_parm->log_level_print, |
| 122 | log_level_str[id_parm->log_level_save], |
| 123 | id_parm->log_level_save, |
| 124 | log_level_str[id_parm->default_log_level], |
| 125 | id_parm->default_log_level, |
| 126 | dev_log_str_style(id_parm->style), |
| 127 | id_parm->style, |
| 128 | id_parm->lost_msg_cnt, |
| 129 | id_parm->print_skipped_count); |
| 130 | bcmcli_session_print(session, |
| 131 | "%scounters = {%c %-5u,%c %-5u,%c %-5u,%c %-5u,%c %-5u,%c %-5u}\n", |
| 132 | tabs, |
| 133 | log_level_str[DEV_LOG_LEVEL_NO_LOG], |
| 134 | id_parm->counters[DEV_LOG_LEVEL_NO_LOG], |
| 135 | log_level_str[DEV_LOG_LEVEL_FATAL], |
| 136 | id_parm->counters[DEV_LOG_LEVEL_FATAL], |
| 137 | log_level_str[DEV_LOG_LEVEL_ERROR], |
| 138 | id_parm->counters[DEV_LOG_LEVEL_ERROR], |
| 139 | log_level_str[DEV_LOG_LEVEL_WARNING], |
| 140 | id_parm->counters[DEV_LOG_LEVEL_WARNING], |
| 141 | log_level_str[DEV_LOG_LEVEL_INFO], |
| 142 | id_parm->counters[DEV_LOG_LEVEL_INFO], |
| 143 | log_level_str[DEV_LOG_LEVEL_DEBUG], |
| 144 | id_parm->counters[DEV_LOG_LEVEL_DEBUG]); |
| 145 | #ifdef TRIGGER_LOGGER_FEATURE |
| 146 | bcm_dev_log_cli_session_print_features(session, tabs, id_parm); |
| 147 | #endif |
| 148 | } |
| 149 | |
| 150 | static bcmos_errno bcm_dev_log_cli_print_dev_log( |
| 151 | bcmcli_session *session, |
| 152 | const bcmcli_cmd_parm parm[], |
| 153 | uint16_t n_parms) |
| 154 | { |
| 155 | uint32_t i; |
| 156 | bcm_dev_log_file *file; |
| 157 | |
| 158 | for (i = 0; i < DEV_LOG_MAX_FILES; i++) |
| 159 | { |
| 160 | file = bcm_dev_log_file_get(i); |
| 161 | if (!file) |
| 162 | continue; |
| 163 | bcmcli_session_print(session, TAB "file[%u]:\n", i); |
| 164 | bcmcli_session_print(session, TAB2 "max_msgs = %u\n", bcm_dev_log_get_num_of_messages(file)); |
| 165 | bcmcli_session_print(session, TAB2 "file_parm:\n"); |
| 166 | bcmcli_session_print(session, TAB3 "start_addr = %p\n", dev_log.files[i].file_parm.start_addr); |
| 167 | bcmcli_session_print(session, TAB3 "size = %u\n", dev_log.files[i].file_parm.size); |
| 168 | bcmcli_session_print(session, TAB3 "read_cb = %p\n", (void *)dev_log.files[i].file_parm.read_cb); |
| 169 | bcmcli_session_print(session, TAB3 "write_cb = %p\n", (void *)dev_log.files[i].file_parm.write_cb); |
| 170 | bcmcli_session_print(session, TAB3 "flags = %x\n", dev_log.files[i].file_parm.flags); |
| 171 | } |
| 172 | bcmcli_session_print(session, TAB "state = %u\n", dev_log.state); |
| 173 | bcmcli_session_print(session, TAB "msg_count = %u\n", dev_log.msg_count); |
| 174 | bcmcli_session_print(session, TAB "save_queue:\n"); |
| 175 | bcmcli_session_print(session, TAB2 "is_waiting = %u\n", dev_log.save_queue.is_waiting); |
| 176 | bcmcli_session_print(session, TAB "print_queue:\n"); |
| 177 | bcmcli_session_print(session, TAB2 "is_waiting = %u\n", dev_log.print_queue.is_waiting); |
| 178 | bcmcli_session_print(session, TAB "save_task:\n"); |
| 179 | bcmcli_session_print(session, TAB2 "active_modules = %u\n", dev_log.save_task.active_modules); |
| 180 | bcmcli_session_print(session, TAB2 "current_module = %u\n", dev_log.save_task.current_module); |
| 181 | bcmcli_session_print(session, TAB "print_task:\n"); |
| 182 | bcmcli_session_print(session, TAB2 "active_modules = %u\n", dev_log.print_task.active_modules); |
| 183 | bcmcli_session_print(session, TAB2 "current_module = %u\n", dev_log.print_task.current_module); |
| 184 | |
| 185 | bcmcli_session_print(session, TAB "num_ids = %u\n", dev_log.num_ids); |
| 186 | bcmcli_session_print(session, TAB "ids[]:\n"); |
| 187 | for (i = 0; i < dev_log.num_ids; i++) |
| 188 | { |
| 189 | bcmcli_session_print(session, TAB2 "ids[%2u]: ", i); |
| 190 | bcm_dev_log_cli_session_print_id_parm(session, TAB3, &dev_log.ids[i]); |
| 191 | } |
| 192 | |
| 193 | for (i = 0; i < log_name_table_index; i++) |
| 194 | { |
| 195 | if (logs_names[i].first_instance == LOG_NAME_NO_INSTANCE) |
| 196 | { |
| 197 | bcmcli_session_print(session, TAB2 "%s\n", logs_names[i].name); |
| 198 | } |
| 199 | else |
| 200 | { |
| 201 | bcmcli_session_print(session, TAB2 "%s %d - %d\n", logs_names[i].name, logs_names[i].first_instance, logs_names[i].last_instance); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | return BCM_ERR_OK; |
| 206 | } |
| 207 | |
| 208 | static bcmos_errno bcm_dev_log_cli_logger_control(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 209 | { |
| 210 | bcm_dev_log_set_control(parm[0].value.unumber != 0); |
| 211 | return BCM_ERR_OK; |
| 212 | } |
| 213 | |
| 214 | static bcmos_errno bcm_dev_log_cli_file_print(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 215 | { |
| 216 | return bcm_dev_log_file_print( |
| 217 | parm[0].value.unumber, |
| 218 | 0, |
| 219 | (bcm_dev_log_print_cb)bcmcli_session_print, |
| 220 | session, |
| 221 | (bcmos_bool)parm[1].value.unumber); |
| 222 | } |
| 223 | |
| 224 | static bcmos_errno bcm_dev_log_cli_file_clear(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 225 | { |
| 226 | bcm_dev_log_file *file = bcm_dev_log_file_get(parm[0].value.unumber); |
| 227 | if (!file) |
| 228 | return BCM_ERR_PARM; |
| 229 | return bcm_dev_log_file_clear(file); |
| 230 | } |
| 231 | |
| 232 | static bcmos_errno bcm_dev_log_cli_file_set_flags(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 233 | { |
| 234 | dev_log.files[parm[0].value.unumber].file_parm.flags |= (bcm_dev_log_file_flags)parm[1].value.unumber; |
| 235 | return BCM_ERR_OK; |
| 236 | } |
| 237 | |
| 238 | static bcmos_errno bcm_dev_log_cli_file_reset_flags(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 239 | { |
| 240 | dev_log.files[parm[0].value.unumber].file_parm.flags = 0; |
| 241 | return BCM_ERR_OK; |
| 242 | } |
| 243 | |
| 244 | static bcmos_errno bcm_dev_log_cli_id_get(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 245 | { |
| 246 | dev_log_id id; |
| 247 | dev_log_id_parm id_parm; |
| 248 | bcmos_errno err; |
| 249 | |
| 250 | id = parm[0].value.unumber == ID_BY_INDEX ? bcm_dev_log_id_get_by_index(parm[1].value.unumber) : |
| 251 | bcm_dev_log_id_get_by_name(parm[1].value.string); |
| 252 | if (id == DEV_LOG_INVALID_ID) |
| 253 | return BCM_ERR_NOENT; |
| 254 | |
| 255 | err = bcm_dev_log_id_get(id, &id_parm); |
| 256 | if (err) |
| 257 | { |
| 258 | bcmcli_session_print(session, "Error: can get id (err: %d)\n", err); |
| 259 | return err; |
| 260 | } |
| 261 | |
| 262 | bcm_dev_log_cli_session_print_id_parm(session, TAB, &id_parm); |
| 263 | |
| 264 | return BCM_ERR_OK; |
| 265 | } |
| 266 | |
| 267 | static bcmos_errno bcm_dev_log_cli_id_set_type(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 268 | { |
| 269 | dev_log_id id; |
| 270 | |
| 271 | id = bcm_dev_log_id_get_by_index(parm[0].value.unumber); |
| 272 | if (id == DEV_LOG_INVALID_ID) |
| 273 | return BCM_ERR_NOENT; |
| 274 | |
| 275 | return bcm_dev_log_id_set_type(id, (bcm_dev_log_id_type)parm[1].value.unumber); |
| 276 | } |
| 277 | |
| 278 | static bcmos_errno bcm_dev_log_cli_id_set_level(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 279 | { |
| 280 | dev_log_id id; |
| 281 | |
| 282 | id = bcm_dev_log_id_get_by_index(parm[0].value.unumber); |
| 283 | if (id == DEV_LOG_INVALID_ID) |
| 284 | return BCM_ERR_NOENT; |
| 285 | |
| 286 | return bcm_dev_log_id_set_level( |
| 287 | id, |
| 288 | (bcm_dev_log_level)parm[1].value.unumber, |
| 289 | (bcm_dev_log_level)parm[2].value.unumber); |
| 290 | } |
| 291 | |
| 292 | static bcmos_errno bcm_dev_log_cli_name_set_level(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 293 | { |
| 294 | dev_log_id id; |
| 295 | |
| 296 | id = bcm_dev_log_id_get_by_name(parm[0].value.string); |
| 297 | if (id == DEV_LOG_INVALID_ID) |
| 298 | { |
| 299 | return BCM_ERR_NOENT; |
| 300 | } |
| 301 | |
| 302 | return bcm_dev_log_id_set_level( |
| 303 | id, |
| 304 | (bcm_dev_log_level)parm[1].value.unumber, |
| 305 | (bcm_dev_log_level)parm[2].value.unumber); |
| 306 | } |
| 307 | |
| 308 | static bcmos_errno bcm_dev_log_cli_id_set_to_default(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 309 | { |
| 310 | dev_log_id id; |
| 311 | |
| 312 | id = bcm_dev_log_id_get_by_index(parm[0].value.unumber); |
| 313 | if (id == DEV_LOG_INVALID_ID) |
| 314 | return BCM_ERR_NOENT; |
| 315 | |
| 316 | return bcm_dev_log_id_set_levels_and_type_to_default(id); |
| 317 | } |
| 318 | |
| 319 | static bcmos_errno bcm_dev_log_cli_id_set_style(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 320 | { |
| 321 | dev_log_id id; |
| 322 | bcm_dev_log_style style; |
| 323 | |
| 324 | id = bcm_dev_log_id_get_by_index(bcmcli_find_named_parm(session, "index")->value.unumber); |
| 325 | if (id == DEV_LOG_INVALID_ID) |
| 326 | return BCM_ERR_NOENT; |
| 327 | style = (bcm_dev_log_style)bcmcli_find_named_parm(session, "style")->value.unumber; |
| 328 | |
| 329 | return bcm_dev_log_id_set_style(id, style); |
| 330 | } |
| 331 | |
| 332 | static bcmos_errno bcm_dev_log_cli_id_clear_counters(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 333 | { |
| 334 | dev_log_id id; |
| 335 | |
| 336 | id = bcm_dev_log_id_get_by_index(parm[0].value.unumber); |
| 337 | if (id == DEV_LOG_INVALID_ID) |
| 338 | return BCM_ERR_NOENT; |
| 339 | |
| 340 | return bcm_dev_log_id_clear_counters(id); |
| 341 | } |
| 342 | |
| 343 | static bcmos_errno bcm_dev_log_cli_log(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 344 | { |
| 345 | dev_log_id id; |
| 346 | bcm_dev_log_level log_level; |
| 347 | uint32_t count = 1; |
| 348 | const char *string; |
| 349 | bcmcli_cmd_parm *cmd_parm; |
| 350 | |
| 351 | id = bcm_dev_log_id_get_by_index(parm[0].value.unumber); |
| 352 | if (id == DEV_LOG_INVALID_ID) |
| 353 | return BCM_ERR_NOENT; |
| 354 | |
| 355 | if ((cmd_parm = bcmcli_find_named_parm(session, "count"))) |
| 356 | { |
| 357 | count = cmd_parm->value.unumber; |
| 358 | if (!count) |
| 359 | { |
| 360 | count = 1; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | log_level = (bcm_dev_log_level)parm[1].value.unumber; |
| 365 | string = parm[2].value.string; |
| 366 | |
| 367 | while (count--) |
| 368 | { |
| 369 | bcm_dev_log_log(id, log_level, BCM_LOG_FLAG_NONE, "%5u| Message: %s\n", count, string); |
| 370 | } |
| 371 | |
| 372 | return BCM_ERR_OK; |
| 373 | } |
| 374 | |
| 375 | static bcmos_errno bcm_dev_log_cli_instance_enable( |
| 376 | bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 377 | { |
| 378 | static char log_name[MAX_DEV_LOG_ID_NAME]; |
| 379 | bcmos_bool enable = (bcmos_bool)bcmcli_find_named_parm(session, "enable")->value.unumber; |
| 380 | uint32_t inst = bcmcli_find_named_parm(session, "instance")->value.unumber; |
| 381 | dev_log_id log_id; |
| 382 | bcmos_errno err; |
| 383 | uint32_t i; |
| 384 | |
| 385 | for (i = 0; i < log_name_table_index; i++) |
| 386 | { |
| 387 | if (logs_names[i].first_instance != LOG_NAME_NO_INSTANCE && |
| 388 | inst >= logs_names[i].first_instance && |
| 389 | inst <= logs_names[i].last_instance) |
| 390 | { |
| 391 | snprintf(log_name, sizeof(log_name), "%s%u", logs_names[i].name, inst); |
| 392 | log_id = bcm_dev_log_id_get_by_name(log_name); |
| 393 | if (log_id == DEV_LOG_INVALID_ID) |
| 394 | { |
| 395 | bcmcli_session_print(session, "Error: log ID not found: %s\n", log_name); |
| 396 | return BCM_ERR_INTERNAL; |
| 397 | } |
| 398 | err = bcm_dev_log_id_set_type(log_id, enable ? DEV_LOG_ID_TYPE_BOTH : DEV_LOG_ID_TYPE_NONE); |
| 399 | if (err != BCM_ERR_OK) |
| 400 | { |
| 401 | bcmcli_session_print(session, "Error setting log type: %s\n", bcmos_strerror(err)); |
| 402 | return err; |
| 403 | } |
| 404 | bcmcli_session_print(session, "Log '%s' %s\n", log_name, enable ? "enabled" : "disabled"); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | return BCM_ERR_OK; |
| 409 | } |
| 410 | |
| 411 | #ifdef TRIGGER_LOGGER_FEATURE |
| 412 | static bcmos_errno bcm_dev_log_cli_throttle(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 413 | { |
| 414 | dev_log_id id; |
| 415 | |
| 416 | id = bcm_dev_log_id_get_by_index(parm[0].value.unumber); |
| 417 | if (id == DEV_LOG_INVALID_ID) |
| 418 | return BCM_ERR_NOENT; |
| 419 | |
| 420 | return bcm_dev_log_set_throttle(id, parm[1].value.unumber, parm[2].value.unumber); |
| 421 | } |
| 422 | |
| 423 | static bcmos_errno bcm_dev_log_cli_trigger(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 424 | { |
| 425 | dev_log_id id; |
| 426 | int32_t repeat = 0; |
| 427 | bcmcli_cmd_parm *cmd_parm; |
| 428 | |
| 429 | id = bcm_dev_log_id_get_by_index(parm[0].value.unumber); |
| 430 | if (id == DEV_LOG_INVALID_ID) |
| 431 | return BCM_ERR_NOENT; |
| 432 | |
| 433 | if ((cmd_parm = bcmcli_find_named_parm(session, "repeat"))) |
| 434 | repeat = cmd_parm->value.number; |
| 435 | |
| 436 | return bcm_dev_log_set_trigger(id, parm[1].value.unumber, parm[2].value.unumber, parm[3].value.unumber, repeat); |
| 437 | } |
| 438 | |
| 439 | static bcmos_errno bcm_dev_log_cli_get_features(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms) |
| 440 | { |
| 441 | dev_log_id id; |
| 442 | dev_log_id_parm id_parm; |
| 443 | bcmos_errno err; |
| 444 | |
| 445 | id = bcm_dev_log_id_get_by_index(parm[0].value.unumber); |
| 446 | if (id == DEV_LOG_INVALID_ID) |
| 447 | return BCM_ERR_NOENT; |
| 448 | |
| 449 | err = bcm_dev_log_id_get(id, &id_parm); |
| 450 | if (err) |
| 451 | { |
| 452 | bcmcli_session_print(session, "Error: can get id (err: %d)\n", err); |
| 453 | return err; |
| 454 | } |
| 455 | |
| 456 | bcm_dev_log_cli_session_print_features(session, TAB, &id_parm); |
| 457 | |
| 458 | return BCM_ERR_OK; |
| 459 | } |
| 460 | #endif |
| 461 | |
| 462 | static int dev_log_cli_session_write_cb(bcmcli_session *cli_session, const char *buf, uint32_t size) |
| 463 | { |
| 464 | bcm_dev_log_cli_session *session = bcmcli_session_user_priv(cli_session); |
| 465 | char tmp_str[DEV_LOG_CLI_SESSION_MAX_MSG_SIZE] = {}; |
| 466 | char *p; |
| 467 | uint32_t tmp_str_len; |
| 468 | |
| 469 | strncpy(tmp_str, buf, sizeof(tmp_str) - 1); /* leave room for the terminator */ |
| 470 | |
| 471 | p = tmp_str; |
| 472 | tmp_str_len = strlen(tmp_str); |
| 473 | while (tmp_str_len > session->free_len) |
| 474 | { |
| 475 | /* Not enough space in 'str' for concatenating what's in 'p' -> split it. */ |
| 476 | strncat(session->str, p, session->free_len); |
| 477 | bcm_dev_log_log( |
| 478 | session->log_id, session->log_level, BCM_LOG_FLAG_NO_HEADER | BCM_LOG_FLAG_CALLER_FMT, "%s", session->str); |
| 479 | *session->str = '\0'; |
| 480 | p += session->free_len; |
| 481 | tmp_str_len -= session->free_len; |
| 482 | session->free_len = MAX_DEV_LOG_STRING_NET_SIZE - 1; |
| 483 | } |
| 484 | |
| 485 | /* Enough space in 'str' for concatenating what's in 'p'. */ |
| 486 | strncat(session->str, p, tmp_str_len); |
| 487 | session->free_len -= tmp_str_len; |
| 488 | |
| 489 | /* If the message is not terminated by '\n', do not submit the message to logger yet |
| 490 | * (rather save it, waiting for a later message with '\n'). */ |
| 491 | if (session->str[strlen(session->str) - 1] == '\n') |
| 492 | { |
| 493 | bcm_dev_log_log( |
| 494 | session->log_id, session->log_level, BCM_LOG_FLAG_NO_HEADER | BCM_LOG_FLAG_CALLER_FMT, "%s", session->str); |
| 495 | *session->str = '\0'; |
| 496 | session->free_len = MAX_DEV_LOG_STRING_NET_SIZE - 1; |
| 497 | } |
| 498 | |
| 499 | return size; |
| 500 | } |
| 501 | |
| 502 | bcmos_errno bcm_dev_log_cli_session_create( |
| 503 | dev_log_id log_id, |
| 504 | bcm_dev_log_level log_level, |
| 505 | bcm_dev_log_cli_session **session) |
| 506 | { |
| 507 | bcmos_errno err; |
| 508 | bcmcli_session_parm session_params = { .write = dev_log_cli_session_write_cb }; |
| 509 | |
| 510 | *session = bcmos_calloc(sizeof(bcm_dev_log_cli_session)); |
| 511 | if (*session == NULL) |
| 512 | { |
| 513 | return BCM_ERR_NOMEM; |
| 514 | } |
| 515 | |
| 516 | session_params.user_priv = *session; |
| 517 | err = bcmcli_session_open(&session_params, &((*session)->session)); |
| 518 | if (err != BCM_ERR_OK) |
| 519 | { |
| 520 | bcmos_free(*session); |
| 521 | *session = NULL; |
| 522 | return err; |
| 523 | } |
| 524 | |
| 525 | (*session)->log_id = log_id; |
| 526 | (*session)->log_level = log_level; |
| 527 | (*session)->free_len = MAX_DEV_LOG_STRING_NET_SIZE - 1; |
| 528 | return BCM_ERR_OK; |
| 529 | } |
| 530 | |
| 531 | bcmcli_entry *bcm_dev_log_cli_init(bcmcli_entry *root_dir) |
| 532 | { |
| 533 | bcmcli_entry *dir; |
| 534 | static bcmcli_enum_val enum_table_log_level[] = |
| 535 | { |
| 536 | { .name = "NO_LOG", .val = (long)DEV_LOG_LEVEL_NO_LOG }, |
| 537 | { .name = "FATAL", .val = (long)DEV_LOG_LEVEL_FATAL }, |
| 538 | { .name = "ERROR", .val = (long)DEV_LOG_LEVEL_ERROR }, |
| 539 | { .name = "WARNING", .val = (long)DEV_LOG_LEVEL_WARNING}, |
| 540 | { .name = "INFO", .val = (long)DEV_LOG_LEVEL_INFO }, |
| 541 | { .name = "DEBUG", .val = (long)DEV_LOG_LEVEL_DEBUG }, |
| 542 | BCMCLI_ENUM_LAST |
| 543 | }; |
| 544 | |
| 545 | if ((dir = bcmcli_dir_find(NULL, "logger")) != NULL) |
| 546 | return dir; |
| 547 | |
| 548 | dir = bcmcli_dir_add(root_dir, "logger", "Dev Log", BCMCLI_ACCESS_GUEST, NULL); |
| 549 | |
| 550 | { |
| 551 | BCMCLI_MAKE_CMD_NOPARM(dir, "print_dev_log", "Print Dev log", bcm_dev_log_cli_print_dev_log); |
| 552 | } |
| 553 | { |
| 554 | BCMCLI_MAKE_CMD(dir, "logger_control", "Logger Control", bcm_dev_log_cli_logger_control, |
| 555 | BCMCLI_MAKE_PARM_RANGE("enable", "enable", BCMCLI_PARM_UDECIMAL, 0, 0, 1)); |
| 556 | } |
| 557 | { |
| 558 | BCMCLI_MAKE_CMD(dir, "file_print", "Print logger file", bcm_dev_log_cli_file_print, |
| 559 | BCMCLI_MAKE_PARM("index", "index", BCMCLI_PARM_UDECIMAL, 0), |
| 560 | BCMCLI_MAKE_PARM_RANGE("clear", "clear", BCMCLI_PARM_UDECIMAL, 0, 0, 1)); |
| 561 | } |
| 562 | { |
| 563 | BCMCLI_MAKE_CMD(dir, "file_clear", "Clear file", bcm_dev_log_cli_file_clear, |
| 564 | BCMCLI_MAKE_PARM("index", "index", BCMCLI_PARM_UDECIMAL, 0)); |
| 565 | } |
| 566 | { |
| 567 | static bcmcli_enum_val enum_table_file_flags[] = |
| 568 | { |
| 569 | { .name = "VALID", .val = (long)BCM_DEV_LOG_FILE_FLAG_VALID }, |
| 570 | { .name = "WRAP_AROUND", .val = (long)BCM_DEV_LOG_FILE_FLAG_WRAP_AROUND }, |
| 571 | { .name = "STOP_WHEN_FULL", .val = (long)BCM_DEV_LOG_FILE_FLAG_STOP_WHEN_FULL }, |
| 572 | BCMCLI_ENUM_LAST |
| 573 | }; |
| 574 | BCMCLI_MAKE_CMD(dir, "file_set_flags", "Set file flags", bcm_dev_log_cli_file_set_flags, |
| 575 | BCMCLI_MAKE_PARM_RANGE("index", "index", BCMCLI_PARM_UDECIMAL, 0, 0, DEV_LOG_MAX_FILES-1), |
| 576 | BCMCLI_MAKE_PARM_ENUM("flags", "flags", enum_table_file_flags, 0)); |
| 577 | } |
| 578 | { |
| 579 | BCMCLI_MAKE_CMD(dir, "file_reset_flags", "Reset file flags", bcm_dev_log_cli_file_reset_flags, |
| 580 | BCMCLI_MAKE_PARM_RANGE("index", "index", BCMCLI_PARM_UDECIMAL, 0, 0, DEV_LOG_MAX_FILES-1)); |
| 581 | } |
| 582 | { |
| 583 | static bcmcli_cmd_parm set1[]= |
| 584 | { |
| 585 | BCMCLI_MAKE_PARM("index", "index", BCMCLI_PARM_UDECIMAL, 0), |
| 586 | BCMCLI_PARM_LIST_TERMINATOR |
| 587 | }; |
| 588 | static bcmcli_cmd_parm set2[] = |
| 589 | { |
| 590 | BCMCLI_MAKE_PARM("name", "name", BCMCLI_PARM_STRING, 0), |
| 591 | BCMCLI_PARM_LIST_TERMINATOR |
| 592 | }; |
| 593 | static bcmcli_enum_val selector_table[] = |
| 594 | { |
| 595 | { .name = "by_index", .val = ID_BY_INDEX, .parms = set1 }, |
| 596 | { .name = "by_name", .val = ID_BY_NAME, .parms = set2 }, |
| 597 | BCMCLI_ENUM_LAST |
| 598 | }; |
| 599 | BCMCLI_MAKE_CMD(dir, "id_get", "id_get", bcm_dev_log_cli_id_get, |
| 600 | BCMCLI_MAKE_PARM_SELECTOR("by", "by", selector_table, 0)); |
| 601 | } |
| 602 | { |
| 603 | static bcmcli_enum_val enum_table[] = |
| 604 | { |
| 605 | { .name = "none", .val = (long)DEV_LOG_ID_TYPE_NONE }, |
| 606 | { .name = "print", .val = (long)DEV_LOG_ID_TYPE_PRINT }, |
| 607 | { .name = "save", .val = (long)DEV_LOG_ID_TYPE_SAVE }, |
| 608 | { .name = "both", .val = (long)DEV_LOG_ID_TYPE_BOTH }, |
| 609 | BCMCLI_ENUM_LAST |
| 610 | }; |
| 611 | BCMCLI_MAKE_CMD(dir, "id_set_type", "id_set_type", bcm_dev_log_cli_id_set_type, |
| 612 | BCMCLI_MAKE_PARM("index", "index", BCMCLI_PARM_UDECIMAL, 0), |
| 613 | BCMCLI_MAKE_PARM_ENUM("log_type", "log_type", enum_table, 0)); |
| 614 | } |
| 615 | { |
| 616 | BCMCLI_MAKE_CMD(dir, "id_set_level", "id_set_level", bcm_dev_log_cli_id_set_level, |
| 617 | BCMCLI_MAKE_PARM("index", "index", BCMCLI_PARM_UDECIMAL, 0), |
| 618 | BCMCLI_MAKE_PARM_ENUM("log_level_print", "log_level", enum_table_log_level, 0), |
| 619 | BCMCLI_MAKE_PARM_ENUM("log_level_save", "log_level", enum_table_log_level, 0)); |
| 620 | } |
| 621 | { |
| 622 | BCMCLI_MAKE_CMD(dir, "name_set_level", "name_set_level", bcm_dev_log_cli_name_set_level, |
| 623 | BCMCLI_MAKE_PARM("name", "name", BCMCLI_PARM_STRING, 0), |
| 624 | BCMCLI_MAKE_PARM_ENUM("log_level_print", "log_level", enum_table_log_level, 0), |
| 625 | BCMCLI_MAKE_PARM_ENUM("log_level_save", "log_level", enum_table_log_level, 0)); |
| 626 | } |
| 627 | { |
| 628 | BCMCLI_MAKE_CMD(dir, "id_set_to_default", "id_set_to_default", bcm_dev_log_cli_id_set_to_default, |
| 629 | BCMCLI_MAKE_PARM("index", "index", BCMCLI_PARM_UDECIMAL, 0)); |
| 630 | } |
| 631 | { |
| 632 | static bcmcli_enum_val enum_table_log_style[] = |
| 633 | { |
| 634 | { .name = "normal", .val = (long)BCM_DEV_LOG_STYLE_NORMAL }, |
| 635 | { .name = "bold", .val = (long)BCM_DEV_LOG_STYLE_BOLD }, |
| 636 | { .name = "underline", .val = (long)BCM_DEV_LOG_STYLE_UNDERLINE }, |
| 637 | { .name = "blink", .val = (long)BCM_DEV_LOG_STYLE_BLINK }, |
| 638 | { .name = "reverse_video", .val = (long)BCM_DEV_LOG_STYLE_REVERSE_VIDEO }, |
| 639 | BCMCLI_ENUM_LAST |
| 640 | }; |
| 641 | BCMCLI_MAKE_CMD(dir, "id_set_style", "id_set_style", bcm_dev_log_cli_id_set_style, |
| 642 | BCMCLI_MAKE_PARM("index", "index", BCMCLI_PARM_UDECIMAL, 0), |
| 643 | BCMCLI_MAKE_PARM_ENUM("style", "style", enum_table_log_style, 0)); |
| 644 | } |
| 645 | { |
| 646 | BCMCLI_MAKE_CMD(dir, "id_clear_counters", "id_clear_counters", bcm_dev_log_cli_id_clear_counters, |
| 647 | BCMCLI_MAKE_PARM("index", "index", BCMCLI_PARM_UDECIMAL, 0)); |
| 648 | } |
| 649 | { |
| 650 | BCMCLI_MAKE_CMD(dir, "log", "log", bcm_dev_log_cli_log, |
| 651 | BCMCLI_MAKE_PARM("index", "index", BCMCLI_PARM_UDECIMAL, 0), |
| 652 | BCMCLI_MAKE_PARM_ENUM("log_level_print", "log_level", enum_table_log_level, 0), |
| 653 | BCMCLI_MAKE_PARM("string", "string", BCMCLI_PARM_STRING, 0), |
| 654 | BCMCLI_MAKE_PARM("count", "Number of messages to send", BCMCLI_PARM_UDECIMAL, BCMCLI_PARM_FLAG_OPTIONAL)); |
| 655 | } |
| 656 | { |
| 657 | BCMCLI_MAKE_CMD(dir, "instance_enable", "enable/disable instance number", bcm_dev_log_cli_instance_enable, |
| 658 | BCMCLI_MAKE_PARM_ENUM("enable", "enable", bcmcli_enum_bool_table, 0), |
| 659 | BCMCLI_MAKE_PARM("instance", "instance number", BCMCLI_PARM_UDECIMAL, 0)); |
| 660 | } |
| 661 | #ifdef TRIGGER_LOGGER_FEATURE |
| 662 | { |
| 663 | BCMCLI_MAKE_CMD(dir, "id_set_throttle", "set throttle", bcm_dev_log_cli_throttle, |
| 664 | BCMCLI_MAKE_PARM("index", "index", BCMCLI_PARM_UDECIMAL, 0), |
| 665 | BCMCLI_MAKE_PARM_ENUM("log_level_print", "log_level", enum_table_log_level, 0), |
| 666 | BCMCLI_MAKE_PARM("throttle", "throttle", BCMCLI_PARM_UDECIMAL, 0)); |
| 667 | } |
| 668 | { |
| 669 | BCMCLI_MAKE_CMD(dir, "id_set_trigger", "set trigger", bcm_dev_log_cli_trigger, |
| 670 | BCMCLI_MAKE_PARM("index", "index", BCMCLI_PARM_UDECIMAL, 0), |
| 671 | BCMCLI_MAKE_PARM_ENUM("log_level_print", "log_level", enum_table_log_level, 0), |
| 672 | BCMCLI_MAKE_PARM("start", "start", BCMCLI_PARM_UDECIMAL, 0), |
| 673 | BCMCLI_MAKE_PARM("stop", "stop", BCMCLI_PARM_UDECIMAL, 0), |
| 674 | BCMCLI_MAKE_PARM("repeat", "repeat", BCMCLI_PARM_DECIMAL, BCMCLI_PARM_FLAG_OPTIONAL)); |
| 675 | } |
| 676 | { |
| 677 | BCMCLI_MAKE_CMD(dir, "id_get_feature", "get feature", bcm_dev_log_cli_get_features, |
| 678 | BCMCLI_MAKE_PARM("index", "index", BCMCLI_PARM_UDECIMAL, 0)); |
| 679 | } |
| 680 | #endif |
| 681 | return dir; |
| 682 | } |
| 683 | |
| 684 | #endif /* #ifndef __KERNEL__ */ |