1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
14 */
15
16 #include <sys/types.h>
17 #include <sys/sysmacros.h>
18 #include <sys/cmn_err.h>
19 #include <sys/ddi.h>
20 #include <sys/sunddi.h>
21
22 #include "krrp_protocol.h"
23
24 static struct {
25 const char *str;
26 krrp_opcode_t opcode;
27 } opcodes_str[] = {
28 #define KRRP_OPCODE_EXPAND(enum_name) \
29 {"KRRP_OPCODE_"#enum_name, KRRP_OPCODE_##enum_name},
30 KRRP_OPCODES_DATA_MAP(KRRP_OPCODE_EXPAND)
31 KRRP_OPCODES_CTRL_MAP(KRRP_OPCODE_EXPAND)
32 #undef KRRP_OPCODE_EXPAND
33 };
34
35 static size_t opcodes_str_sz = sizeof (opcodes_str) / sizeof (opcodes_str[0]);
36
37 const char *
38 krrp_protocol_opcode_str(krrp_opcode_t opcode)
39 {
40 size_t i;
41
42 for (i = 0; i < opcodes_str_sz; i++) {
43 if (opcodes_str[i].opcode == opcode)
44 return (opcodes_str[i].str);
45 }
46
47 return ("KRRP_OPCODE_UNKNOWN");
48 }