1 /*
2 * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include "oam_main.h"
20 #include "hi_types_base.h"
21 #ifdef __cplusplus
22 #if __cplusplus
23 extern "C" {
24 #endif
25 #endif
26
27 /* ****************************************************************************
28 2 全局变量定义
29 **************************************************************************** */
30 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
31 static struct kobject *g_sysfs_hi110x_oam = HI_NULL;
32 #endif
33
34 /* ****************************************************************************
35 3 函数实现
36 **************************************************************************** */
37 /* ****************************************************************************
38 功能描述 : OAM模块初始化总入口,包含OAM模块内部所有特性的初始化。
39 返 回 值 : 初始化返回值,成功或失败原因
40 **************************************************************************** */
41 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
log_level_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)42 static ssize_t log_level_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
43 {
44 if (buf == HI_NULL) {
45 return -HI_FAIL;
46 }
47
48 return snprintf_s(buf, PAGE_SIZE, PAGE_SIZE - 1,
49 "loglevel: \n"
50 " 0 close log \n"
51 " 1 ERROR \n"
52 " 2 WARN \n"
53 " 3 INFO \n");
54 }
55
store_log_level_set(struct device * dev,struct kobj_attribute * attr,const char * buf,size_t count)56 STATIC ssize_t store_log_level_set(struct device *dev, struct kobj_attribute *attr, const char *buf, size_t count)
57 {
58 hi_s32 input;
59 if (buf == HI_NULL) {
60 return -HI_FAIL;
61 }
62
63 input = oal_atoi(buf);
64 if (input < 0 || input > 5) { /* input must range [0 5] */
65 return -HI_FAIL;
66 }
67
68 g_level_log = (hi_u32)input;
69 return count;
70 }
71
72 STATIC struct kobj_attribute g_oam_host_log_attr =
73 __ATTR(loglevel, 0664, (void *)log_level_show, (void *)store_log_level_set); /* mode 0664 */
74
75 static struct attribute *g_oam_log_attrs[] = {
76 &g_oam_host_log_attr.attr,
77 #ifdef _SDIO_TEST
78 &oam_sdio_test_attr.attr,
79 #endif
80 NULL
81 };
82
83 static struct attribute_group g_oam_state_group = {
84 .attrs = g_oam_log_attrs,
85 };
86
oam_user_ctrl_init(void)87 hi_s32 oam_user_ctrl_init(void)
88 {
89 hi_s32 ret;
90 g_sysfs_hi110x_oam = kobject_create_and_add("hi3881_debug", HI_NULL);
91 if (g_sysfs_hi110x_oam == HI_NULL) {
92 oam_print_err("kobject_create_and_add fail!ret=%d", -ENOMEM);
93 return -ENOMEM;
94 }
95
96 ret = sysfs_create_group(g_sysfs_hi110x_oam, &g_oam_state_group);
97 if (ret) {
98 oam_print_err("sysfs_create_group fail!ret=%d", ret);
99 }
100 return ret;
101 }
102
oam_user_ctrl_exit(hi_void)103 static hi_s32 oam_user_ctrl_exit(hi_void)
104 {
105 if (g_sysfs_hi110x_oam != HI_NULL) {
106 sysfs_remove_group(g_sysfs_hi110x_oam, &g_oam_state_group);
107 kobject_put(g_sysfs_hi110x_oam);
108 }
109 return HI_SUCCESS;
110 }
111 #endif
112
oam_main_init(hi_void)113 hi_s32 oam_main_init(hi_void)
114 {
115 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
116 hi_s32 ret = oam_user_ctrl_init();
117 if (ret != HI_SUCCESS) {
118 return ret;
119 }
120 #endif
121 printk("oam_main_init SUCCESSFULLY!\r\n");
122 return HI_SUCCESS;
123 }
124
125 #if (_PRE_MULTI_CORE_MODE_OFFLOAD_DMAC == _PRE_MULTI_CORE_MODE)
126 /* ****************************************************************************
127 功能描述 : OAM模块卸载
128 返 回 值 : 模块卸载返回值,成功或失败原因
129 **************************************************************************** */
oam_main_exit(hi_void)130 hi_void oam_main_exit(hi_void)
131 {
132 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
133 hi_s32 ret = oam_user_ctrl_exit();
134 if (ret != HI_SUCCESS) {
135 oam_warning_log0(0, 0, "oam_main_exit:: oam_user_ctrl_exit fail!");
136 }
137 #endif
138 return;
139 }
140 #endif
141
142 #ifdef __cplusplus
143 #if __cplusplus
144 }
145 #endif
146 #endif
147