Initial commit: Linux kernel 4.19 for Unplugged OS

This commit is contained in:
ziv committed 2025-10-06 13:52:42 +00:00
commit d30235b04c
80519 files changed
+35800681

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
config MTK_CONN_MD
tristate "Support mtk connsys modem config"
default y if MTK_CONN_LTE_IDC_SUPPORT
help
It is used to config whether IDC feature
is supported or not.
When IDC feature is required,
this config must be enabled to support
SW IDC message exchange.
Usually if a project support both LTE and Wi-Fi,
IDC feature is necessary to avoid interference between LTE and Wi-Fi.
+42
View File
@@ -0,0 +1,42 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# CONN-MD Bridge Driver
# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
ccflags-y += -I$(srctree)/drivers/misc/mediatek/eccci/$(MTK_PLATFORM)
ccflags-y += -I$(srctree)/drivers/misc/mediatek/eccci/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/dual_ccci/
ccflags-y += -I$(src)/include/
obj-$(CONFIG_MTK_CONN_MD) += conn_md_drv.o
conn_md_drv-objs := conn_md.o
conn_md_drv-objs += conn_md_exp.o
conn_md_drv-objs += conn_md_log.o
conn_md_drv-objs += conn_md_dump.o
conn_md_drv-objs += conn_md_dbg.o
conn_md_drv-objs += conn_md_test.o
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C
endif
+671
View File
@@ -0,0 +1,671 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include "conn_md.h"
#include "conn_md_dbg.h"
#include <linux/sched/clock.h>
/*global data structure defination*/
struct conn_md_struct g_conn_md;
static struct conn_md_log_msg_info g_log_msg_info;
static int _conn_md_del_msg_by_uid(uint32 u_id);
static int conn_md_dmp_msg(struct conn_md_queue *p_msg_list, uint32 src_id,
uint32 dst_id);
static unsigned long conn_md_log_msg_interval_ms(
struct conn_md_time_struct *p_begin,
struct conn_md_time_struct *p_end)
{
long long diff_sec;
long diff_msec;
diff_sec = p_end->sec - p_begin->sec;
diff_msec = (p_end->msec - p_begin->msec);
if (diff_msec < 0) {
diff_msec += 1000;
diff_sec -= 1;
}
return (diff_sec * 1000 + diff_msec);
}
static void conn_md_get_local_time(struct conn_md_time_struct *time)
{
time->sec = local_clock();
time->msec = do_div(time->sec, 1000000000) / 1000000;
}
static void conn_md_log_add_msg(struct conn_md_time_struct *cur_time)
{
char buf[CONN_MD_MSG_TIME_LENGTH];
int msg_buf_size, remain_size;
if (g_log_msg_info.msg_total == 0)
g_log_msg_info.msg_begin_time = *cur_time;
if (snprintf(buf, CONN_MD_MSG_TIME_LENGTH, " %llu.%03lu", cur_time->sec,
cur_time->msec) < 0)
return;
msg_buf_size = strlen(buf);
remain_size = CONN_MD_BUF_SIZE - strlen(g_log_msg_info.msg_buf) - 1;
if (remain_size >= msg_buf_size) {
strncat(g_log_msg_info.msg_buf, buf, msg_buf_size);
g_log_msg_info.msg_total++;
} else {
CONN_MD_ERR_FUNC("buff full, %s (remain %d), cant add %s (%d)",
g_log_msg_info.msg_buf, remain_size, buf,
msg_buf_size);
}
}
#define CONN_MD_LOG_MSG_HEAD_NAME "send message to Modem,"
#define CONN_MD_LOG_MSG_MAX_INTERVAL_MS 1000
static void conn_md_log_print_msg(struct conn_md_time_struct *cur_time)
{
unsigned long interval;
if (g_log_msg_info.msg_total > 0) {
interval = conn_md_log_msg_interval_ms(
&g_log_msg_info.msg_begin_time, cur_time);
if ((g_log_msg_info.msg_total == CONN_MD_MSG_MAX_NUM ||
interval > CONN_MD_LOG_MSG_MAX_INTERVAL_MS)) {
CONN_MD_INFO_FUNC("%s%s\n", CONN_MD_LOG_MSG_HEAD_NAME,
g_log_msg_info.msg_buf);
g_log_msg_info.msg_buf[0] = '\0';
g_log_msg_info.msg_total = 0;
}
}
}
static void conn_md_log_msg_time(uint32 dest_id)
{
struct conn_md_time_struct cur_time;
conn_md_get_local_time(&cur_time);
if (dest_id == MD_MOD_EL1)
conn_md_log_add_msg(&cur_time);
conn_md_log_print_msg(&cur_time);
}
int conn_md_add_user(uint32 u_id, struct conn_md_bridge_ops *p_ops)
{
struct conn_md_user *p_user = NULL;
struct list_head *pos = NULL;
struct conn_md_struct *p_conn_md = &g_conn_md;
struct conn_md_user_list *p_user_list = &p_conn_md->user_list;
/*lock user_list_lock */
mutex_lock(&p_user_list->lock);
/*check if earlier uid reged or not */
list_for_each(pos, &p_user_list->list) {
p_user = container_of(pos, struct conn_md_user, entry);
if (p_user->u_id == u_id) {
/*if yes */
/*print warning information */
CONN_MD_WARN_FUNC("uid (0x%08x) registered, updating\n",
u_id);
break;
}
p_user = NULL;
}
if (p_user == NULL) {
/*memory allocation for user information */
p_user = kmalloc(sizeof(struct conn_md_user), GFP_ATOMIC);
if (p_user == NULL) {
CONN_MD_ERR_FUNC("kmalloc failed\n");
mutex_unlock(&p_user_list->lock);
return CONN_MD_ERR_OTHERS;
}
INIT_LIST_HEAD(&p_user->entry);
list_add_tail(&p_user->entry, &p_user_list->list);
p_user->u_id = u_id;
p_user->state = USER_REGED;
}
/*anyway, write user info to target uid */
memcpy(&p_user->ops, p_ops, sizeof(struct conn_md_bridge_ops));
p_user->state = USER_ENABLED;
CONN_MD_WARN_FUNC("uid (0x%08x) is added to user list successfully\n",
p_user->u_id);
/*unlock user_list lock */
mutex_unlock(&p_user_list->lock);
return 0;
}
int conn_md_del_user(uint32 u_id)
{
int i_ret = -1;
struct conn_md_user *p_user = NULL;
struct list_head *pos = NULL;
struct conn_md_struct *p_conn_md = &g_conn_md;
struct conn_md_user_list *p_user_list = &p_conn_md->user_list;
/*lock user_list_lock */
mutex_lock(&p_user_list->lock);
/*check if earlier uid reged or not */
list_for_each(pos, &p_user_list->list) {
p_user = container_of(pos, struct conn_md_user, entry);
if (p_user->u_id == u_id) {
/*if yes */
/*print information */
CONN_MD_INFO_FUNC("uid(0x%08x) registered, delete it\n",
u_id);
break;
}
p_user = NULL;
}
if (p_user == NULL) {
i_ret = CONN_MD_ERR_INVALID_PARAM;
/*print warning information */
CONN_MD_WARN_FUNC("uid (0x%08x) not found in user list..\n",
u_id);
} else {
/*delete user info from user info list of target uid */
list_del(pos);
kfree(p_user);
p_user_list->counter--;
CONN_MD_INFO_FUNC("uid (0x%08x) is deleted\n", u_id);
i_ret = 0;
}
/*unlock user_list lock */
mutex_unlock(&p_user_list->lock);
/*search all message enquued in p_msg_list */
/* and delete them before delete user */
_conn_md_del_msg_by_uid(u_id);
return i_ret;
}
int conn_md_dmp_msg(struct conn_md_queue *p_msg_list, uint32 src_id,
uint32 dst_id)
{
#define MAX_LENGTH_PER_PACKAGE 8
struct list_head *pos = NULL;
struct conn_md_msg *p_msg = NULL;
int i = 0;
int counter = 0;
if (p_msg_list == NULL) {
CONN_MD_ERR_FUNC("invalid parameter, p_msg_list is NULL\n");
return CONN_MD_ERR_INVALID_PARAM;
}
mutex_lock(&p_msg_list->lock);
list_for_each(pos, &p_msg_list->list) {
p_msg = container_of(pos, struct conn_md_msg, entry);
if (((src_id == 0) || (src_id == p_msg->ilm.src_mod_id)) &&
((dst_id == 0) || (dst_id == p_msg->ilm.dest_mod_id))) {
counter++;
CONN_MD_INFO_FUNC
("p_msg:%p, src:0x%08x, dest:0x%08x, msg_len:%d\n",
p_msg, p_msg->ilm.src_mod_id,
p_msg->ilm.dest_mod_id,
p_msg->local_para.msg_len);
for (i = 0; (i < p_msg->local_para.msg_len) &&
(i < MAX_LENGTH_PER_PACKAGE); i++) {
CONN_MD_INFO_FUNC("%02x ",
p_msg->local_para.data[i]);
if (7 == (i % 8))
CONN_MD_INFO_FUNC("\n");
}
CONN_MD_INFO_FUNC("\n");
}
}
mutex_unlock(&p_msg_list->lock);
CONN_MD_INFO_FUNC("%d messages found in message list\n", counter);
return 0;
}
int _conn_md_del_msg_by_uid(uint32 u_id)
{
struct conn_md_struct *p_conn_md = &g_conn_md;
struct conn_md_queue *p_msg_list = &p_conn_md->msg_queue;
struct list_head *pos = NULL;
struct conn_md_msg *p_msg = NULL;
int flag = 1;
CONN_MD_TRC_FUNC();
mutex_lock(&p_msg_list->lock);
while (flag) {
/*set flat to 0 before search message */
flag = 0;
list_for_each(pos, &p_msg_list->list) {
p_msg = container_of(pos, struct conn_md_msg, entry);
if ((p_msg->ilm.dest_mod_id == u_id) ||
(p_msg->ilm.src_mod_id == u_id)) {
flag = 1;
CONN_MD_DBG_FUNC
("uid(0x%08x)found,dest(0x%08x),src(0x%08x)\n",
u_id, p_msg->ilm.dest_mod_id,
p_msg->ilm.src_mod_id);
break;
}
}
if (flag == 1) {
p_msg_list->counter--;
list_del(pos);
kfree(p_msg);
CONN_MD_DBG_FUNC("dequeued in queue list_counter:%d\n",
p_msg_list->counter);
}
}
mutex_unlock(&p_msg_list->lock);
CONN_MD_TRC_FUNC();
return 0;
}
int conn_md_send_msg(struct ipc_ilm *ilm)
{
struct conn_md_struct *p_conn_md = &g_conn_md;
struct conn_md_queue *p_msg_list = &p_conn_md->msg_queue;
uint32 msg_str_len = 0;
struct local_para *p_local_para = NULL;
struct conn_md_msg *p_new_msg = NULL;
uint32 msg_info_len = ilm->local_para_ptr->msg_len;
CONN_MD_DBG_FUNC("ilm:%p, msg_len:%d\n", ilm,
ilm->local_para_ptr->msg_len);
/*malloc message structure for this msg */
msg_str_len = sizeof(struct conn_md_msg) + msg_info_len;
p_new_msg = kmalloc(msg_str_len, GFP_ATOMIC);
if (p_new_msg != NULL) {
CONN_MD_DBG_FUNC("p_new_msg:%p\n", p_new_msg);
/*copy message from ilm */
memcpy(p_new_msg, ilm, sizeof(struct ipc_ilm));
p_local_para = &p_new_msg->local_para;
p_new_msg->ilm.local_para_ptr = p_local_para;
/*copy local_para_ptr structure */
memcpy(p_local_para, ilm->local_para_ptr,
sizeof(struct local_para));
/*copy data from local_para_ptr structure */
memcpy(p_local_para->data, ilm->local_para_ptr->data,
msg_info_len - sizeof(struct local_para));
CONN_MD_DBG_FUNC("p_local_para:%p, msg_len:%d\n",
p_local_para, p_local_para->msg_len);
INIT_LIST_HEAD(&p_new_msg->entry);
/*lock tx queue lock */
mutex_lock(&p_msg_list->lock);
/*enqueue tx message */
list_add_tail(&p_new_msg->entry, &p_msg_list->list);
p_msg_list->counter++;
/*unlock queue lock */
mutex_unlock(&p_msg_list->lock);
CONN_MD_DBG_FUNC
("enqueue new message ist succeed, msg counter:%d\n",
p_msg_list->counter);
conn_md_dmp_in(ilm, MSG_ENQUEUE, p_conn_md->p_msg_dmp_sys);
CONN_MD_DBG_FUNC("begin to wake up conn-md-thread\n");
/*wakeup conn-md thread to handle tx message */
complete(&p_conn_md->tx_comp);
CONN_MD_DBG_FUNC("wake up conn-md-thread done\n");
} else {
CONN_MD_ERR_FUNC("kmalloc for new message structure failed\n");
}
return 0;
}
#define ACT_QUEUE_DBG 0
static int conn_md_thread(void *p_data)
{
struct conn_md_struct *p_conn_md = (struct conn_md_struct *) p_data;
struct conn_md_queue *p_act_queue = &p_conn_md->act_queue;
struct conn_md_queue *p_msg_queue = &p_conn_md->msg_queue;
struct list_head *pos = NULL;
struct conn_md_msg *p_msg = NULL;
struct conn_md_user *p_user = NULL;
struct list_head *p_user_pos = NULL;
struct conn_md_user_list *p_user_list = &p_conn_md->user_list;
struct ipc_ilm *p_cur_ilm = NULL;
while (1) {
if (wait_for_completion_interruptible(&p_conn_md->tx_comp))
CONN_MD_WARN_FUNC("wait_for_completion is interrupted.\n");
if (kthread_should_stop()) {
CONN_MD_WARN_FUNC("conn-md-thread stopping ...\n");
break;
}
/*check if p_conn_md->msg_queue is empty or not */
mutex_lock(&p_msg_queue->lock);
if (!list_empty(&p_msg_queue->list)) {
mutex_lock(&p_act_queue->lock);
if (!list_empty(&p_act_queue->list)) {
/* warning message, this should never happen */
CONN_MD_ERR_FUNC
("this should never happen!!!--*-!!!\n");
}
/*ignore case of p_act_queue is not empty */
list_replace_init(&p_msg_queue->list,
&p_act_queue->list);
mutex_unlock(&p_act_queue->lock);
} else {
/*warning message */
CONN_MD_DBG_FUNC("no msg queued in msg queue...\n");
}
mutex_unlock(&p_msg_queue->lock);
mutex_lock(&p_act_queue->lock);
/*dequeue from p_act_queue */
list_for_each(pos, &p_act_queue->list) {
p_msg = container_of(pos, struct conn_md_msg, entry);
p_cur_ilm = &p_msg->ilm;
if (p_cur_ilm == NULL) {
#if (ACT_QUEUE_DBG == 1)
/*free message structure */
list_del(pos);
kfree(p_msg);
p_act_queue->counter++;
CONN_MD_DBG_FUNC("dequeue act_q counter:%d\n",
p_act_queue->counter);
#endif
continue;
}
conn_md_dmp_in(p_cur_ilm, MSG_DEQUEUE,
p_conn_md->p_msg_dmp_sys);
mutex_lock(&p_user_list->lock);
/*check if src module is enabled or not */
list_for_each(p_user_pos, &p_user_list->list) {
p_user = container_of(p_user_pos,
struct conn_md_user, entry);
if (p_user->u_id == p_cur_ilm->src_mod_id &&
p_user->state == USER_ENABLED) {
/*src module id is enabled already */
CONN_MD_DBG_FUNC
("source user id (0x%08x) found\n",
p_cur_ilm->src_mod_id);
break;
}
p_user = NULL;
}
if (p_user == NULL) {
mutex_unlock(&p_user_list->lock);
CONN_MD_WARN_FUNC
("user (0x%08x) is ready, drop ilm msg\n",
p_cur_ilm->src_mod_id);
#if (ACT_QUEUE_DBG == 1)
/*free message structure */
list_del(pos);
kfree(p_msg);
p_act_queue->counter++;
CONN_MD_DBG_FUNC("dequeued act_q counter:%d\n",
p_act_queue->counter);
#endif
continue;
}
/*check if destination module is enabled or not */
list_for_each(p_user_pos, &p_user_list->list) {
p_user = container_of(p_user_pos,
struct conn_md_user, entry);
if (p_user->u_id == p_cur_ilm->dest_mod_id &&
p_user->state == USER_ENABLED) {
CONN_MD_DBG_FUNC
("target user id (0x%08x) found\n",
p_cur_ilm->dest_mod_id);
/*src module id is enabled already */
break;
}
p_user = NULL;
}
if (p_user == NULL) {
mutex_unlock(&p_user_list->lock);
CONN_MD_WARN_FUNC
("user (0x%08x) not ready, drop ilm msg\n",
p_cur_ilm->dest_mod_id);
#if (ACT_QUEUE_DBG == 1)
/*free message structure */
list_del(pos);
kfree(p_msg);
p_act_queue->counter++;
CONN_MD_DBG_FUNC("dequeue act_que counter:%d\n",
p_act_queue->counter);
#endif
continue;
}
CONN_MD_DBG_FUNC(
"p_cur_ilm:%p, local_para_ptr:%p, msg_len:%d\n",
p_cur_ilm, &p_cur_ilm->local_para_ptr,
p_cur_ilm->local_para_ptr->msg_len);
CONN_MD_DBG_FUNC("send message to user id(0x%08x)\n",
p_cur_ilm->dest_mod_id);
conn_md_log_msg_time(p_cur_ilm->dest_mod_id);
(*(p_user->ops.rx_cb)) (p_cur_ilm);
CONN_MD_DBG_FUNC("message sent user id(0x%08x)done\n",
p_cur_ilm->dest_mod_id);
mutex_unlock(&p_user_list->lock);
#if (ACT_QUEUE_DBG == 1)
/*free message structure */
list_del(pos);
kfree(p_msg);
CONN_MD_DBG_FUNC("message structure freed\n");
p_act_queue->counter++;
CONN_MD_DBG_FUNC("dequeued in act queue counter:%d\n",
p_act_queue->counter);
#endif
}
p_msg = NULL;
while (!list_empty(&p_act_queue->list)) {
list_for_each(pos, &p_act_queue->list) {
p_msg = container_of(pos,
struct conn_md_msg, entry);
/*free message structure */
list_del(pos);
kfree(p_msg);
p_msg = NULL;
CONN_MD_DBG_FUNC("message structure freed\n");
p_act_queue->counter++;
CONN_MD_DBG_FUNC("dequeue act_que counter:%d\n",
p_act_queue->counter);
break;
}
}
mutex_unlock(&p_act_queue->lock);
}
CONN_MD_WARN_FUNC("conn-md-thread stopped.\n");
return 0;
}
int conn_md_dmp_msg_queued(uint32 src_id, uint32 dst_id)
{
return conn_md_dmp_msg(&g_conn_md.msg_queue, src_id, dst_id);
}
int conn_md_dmp_msg_active(uint32 src_id, uint32 dst_id)
{
return conn_md_dmp_msg(&g_conn_md.act_queue, src_id, dst_id);
}
int conn_md_dmp_msg_logged(uint32 src_id, uint32 dst_id)
{
return conn_md_dmp_out(g_conn_md.p_msg_dmp_sys, src_id, dst_id);
}
static int __init conn_md_init(void)
{
int i_ret = 0;
struct conn_md_queue *p_queue = NULL;
struct conn_md_user_list *p_user_list = NULL;
CONN_MD_TRC_FUNC();
/*init message queue structure */
p_queue = &g_conn_md.msg_queue;
INIT_LIST_HEAD(&(p_queue->list));
mutex_init(&(p_queue->lock));
p_queue->counter = 0;
CONN_MD_INFO_FUNC("init message queue list succeed\n");
/*init active queue structure */
p_queue = &g_conn_md.act_queue;
INIT_LIST_HEAD(&(p_queue->list));
mutex_init(&(p_queue->lock));
p_queue->counter = 0;
CONN_MD_INFO_FUNC("init active queue list succeed\n");
/*init user_list structure */
p_user_list = &g_conn_md.user_list;
INIT_LIST_HEAD(&(p_user_list->list));
mutex_init(&(p_user_list->lock));
p_user_list->counter = 0;
CONN_MD_INFO_FUNC("init user information list succeed\n");
g_conn_md.p_msg_dmp_sys = conn_md_dmp_init();
if (g_conn_md.p_msg_dmp_sys == NULL)
CONN_MD_WARN_FUNC("conn_md_dmp_init failed\n");
else
CONN_MD_INFO_FUNC("conn_md_dmp_init succeed\n");
/*init proc interface */
conn_md_dbg_init();
/*create conn-md thread */
init_completion(&g_conn_md.tx_comp);
g_conn_md.p_task = kthread_create(conn_md_thread, &g_conn_md,
"conn-md-thread");
if (g_conn_md.p_task == NULL) {
CONN_MD_ERR_FUNC("create conn_md_thread fail\n");
i_ret = -ENOMEM;
conn_md_dmp_deinit(g_conn_md.p_msg_dmp_sys);
goto conn_md_err;
}
CONN_MD_INFO_FUNC("create conn_md_thread succeed, wakeup it\n");
/*wakeup conn_md_thread */
wake_up_process(g_conn_md.p_task);
conn_md_err:
CONN_MD_TRC_FUNC();
return i_ret;
}
static void conn_md_exit(void)
{
struct conn_md_struct *p_conn_md = &g_conn_md;
struct conn_md_queue *p_queue = NULL;
struct conn_md_user_list *p_user_list = &p_conn_md->user_list;
struct list_head *pos = NULL;
struct conn_md_user *p_user = NULL;
struct conn_md_msg *p_msg = NULL;
CONN_MD_TRC_FUNC();
/*terminate conn-md thread */
if (p_conn_md->p_task != NULL) {
CONN_MD_INFO_FUNC("signaling conn-md-thread to stop ...\n");
kthread_stop(p_conn_md->p_task);
}
/*delete user_list structure if user list is not empty */
mutex_lock(&p_user_list->lock);
list_for_each(pos, &p_user_list->list) {
p_user = container_of(pos, struct conn_md_user, entry);
list_del(pos);
kfree(p_user);
}
p_user_list->counter = 0;
mutex_unlock(&p_user_list->lock);
mutex_destroy(&p_user_list->lock);
/*delete queue structure if message queue list is empty */
p_queue = &p_conn_md->msg_queue;
mutex_lock(&p_queue->lock);
list_for_each(pos, &p_queue->list) {
p_msg = container_of(pos, struct conn_md_msg, entry);
list_del(pos);
kfree(p_msg);
}
p_queue->counter = 0;
mutex_unlock(&p_queue->lock);
mutex_destroy(&p_queue->lock);
/*delete queue structure if active queue list is empty */
p_queue = &p_conn_md->act_queue;
mutex_lock(&p_queue->lock);
list_for_each(pos, &p_queue->list) {
p_msg = container_of(pos, struct conn_md_msg, entry);
list_del(pos);
kfree(p_msg);
}
p_queue->counter = 0;
mutex_unlock(&p_queue->lock);
mutex_destroy(&p_queue->lock);
if (p_conn_md->p_msg_dmp_sys != NULL)
conn_md_dmp_deinit(p_conn_md->p_msg_dmp_sys);
CONN_MD_TRC_FUNC();
}
/*---------------------------------------------------------------------------*/
/*
* module_init(conn_md_init);
* module_exit(conn_md_exit);
*/
subsys_initcall(conn_md_init);
module_exit(conn_md_exit);
/*---------------------------------------------------------------------------*/
MODULE_AUTHOR("MBJ/WCN/SE/SS1/Chaozhong.Liang");
MODULE_DESCRIPTION("MTK CONN-MD Bridge Driver$1.0$");
MODULE_LICENSE("GPL");
/*---------------------------------------------------------------------------*/
+167
View File
@@ -0,0 +1,167 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#define DFT_TAG "[CONN_MD_DMP]"
#include "conn_md_log.h"
#include "conn_md_dbg.h"
#include "conn_md.h"
#include <linux/version.h>
#define USE_NEW_PROC_FS_FLAG 1
#define CONN_MD_DBG_PROCNAME "driver/conn_md_dbg"
static struct proc_dir_entry *gConnMdDbgEntry;
#if USE_NEW_PROC_FS_FLAG
static const struct file_operations conn_md_dbg_fops = {
.read = conn_md_dbg_read,
.write = conn_md_dbg_write,
};
#endif
static int conn_md_test_dbg(int par1, int par2, int par3);
static int conn_md_dbg_set_log_lvl(int par1, int par2, int par3);
static int conn_md_dbg_dmp_msg_log(int par1, int par2, int par3);
static const conn_md_dev_dbg_func conn_md_dbg_func[] = {
conn_md_test_dbg,
conn_md_dbg_set_log_lvl,
conn_md_dbg_dmp_msg_log,
NULL,
};
int conn_md_dbg_dmp_msg_log(int par1, int par2, int par3)
{
return conn_md_dmp_msg_logged(par2, par3);
}
int conn_md_dbg_set_log_lvl(int par1, int par2, int par3)
{
return conn_md_log_set_lvl(par2);
}
#if USE_NEW_PROC_FS_FLAG
ssize_t conn_md_dbg_read(struct file *filp, char __user *buf,
size_t count, loff_t *f_pos)
{
return 0;
}
#else
static int conn_md_dbg_read(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
int len = 0;
return len;
}
#endif
#if USE_NEW_PROC_FS_FLAG
ssize_t conn_md_dbg_write(struct file *filp, const char __user *buffer,
size_t count, loff_t *f_pos)
#else
static int conn_md_dbg_write(struct file *file, const char *buffer,
unsigned long count, void *data)
#endif
{
char buf[256];
char *pBuf;
unsigned long len = count;
unsigned long x = 0;
long y = 0;
long z = 0;
long i;
char *pToken = NULL;
char *pDelimiter = " \t";
CONN_MD_INFO_FUNC("write parameter len = %d\n\r", (int)len);
if (len >= sizeof(buf)) {
CONN_MD_ERR_FUNC("input handling fail!\n");
len = sizeof(buf) - 1;
return -1;
}
if (copy_from_user(buf, buffer, len))
return -EFAULT;
buf[len] = '\0';
CONN_MD_INFO_FUNC("write parameter data = %s\n\r", buf);
pBuf = buf;
pToken = strsep(&pBuf, pDelimiter);
if (pToken != NULL)
i = kstrtol(pToken, 16, &x);
else
x = 0;
pToken = strsep(&pBuf, "\t\n ");
if (pToken != NULL)
i = kstrtol(pToken, 16, &y);
else
y = 0;
pToken = strsep(&pBuf, "\t\n ");
if (pToken != NULL)
i = kstrtol(pToken, 16, &z);
else
z = 0;
CONN_MD_INFO_FUNC("x(0x%08lx), y(0x%08lx), z(0x%08lx)\n\r", x, y, z);
if (ARRAY_SIZE(conn_md_dbg_func) > x && NULL != conn_md_dbg_func[x])
(*conn_md_dbg_func[x]) (x, y, z);
else
CONN_MD_WARN_FUNC("no handler for command id(0x%08lx)\n\r", x);
return len;
}
int conn_md_test_dbg(int par1, int par2, int par3)
{
return conn_md_test();
}
int conn_md_dbg_init(void)
{
#if USE_NEW_PROC_FS_FLAG
gConnMdDbgEntry = proc_create(CONN_MD_DBG_PROCNAME, 0664,
NULL, &conn_md_dbg_fops);
if (gConnMdDbgEntry == NULL) {
CONN_MD_ERR_FUNC("Unable to create /proc entry\n\r");
return -1;
}
#else
gConnMdDbgEntry = create_proc_entry(CONN_MD_DBG_PROCNAME, 0664, NULL);
if (gConnMdDbgEntry == NULL) {
CONN_MD_ERR_FUNC("Unable to create /proc entry\n\r");
return -1;
}
gConnMdDbgEntry->read_proc = conn_md_dbg_read;
gConnMdDbgEntry->write_proc = conn_md_dbg_write;
#endif
return 0;
}
int conn_md_dbg_deinit(void)
{
#if USE_NEW_PROC_FS_FLAG
if (gConnMdDbgEntry != NULL)
proc_remove(gConnMdDbgEntry);
#else
if (gConnMdDbgEntry != NULL) {
remove_proc_entry(CONN_MD_DBG_PROCNAME, NULL);
return -1;
}
#endif
return 0;
}
@@ -0,0 +1,170 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#define DFT_TAG "[CONN_MD_DMP]"
#include "conn_md_log.h"
#include "conn_md_dump.h"
struct conn_md_dmp_msg_log *conn_md_dmp_init(void)
{
uint32 msg_log_size = sizeof(struct conn_md_dmp_msg_log);
struct conn_md_dmp_msg_log *p_msg_log = vmalloc(msg_log_size);
if (p_msg_log != NULL) {
CONN_MD_INFO_FUNC("alloc msg_log memory done, size:0x%08x\n",
msg_log_size);
memset(p_msg_log, 0, msg_log_size);
mutex_init(&p_msg_log->lock);
} else {
CONN_MD_ERR_FUNC("alloc memory for msg log system failed\n");
}
return p_msg_log;
}
int conn_md_dmp_deinit(struct conn_md_dmp_msg_log *p_log)
{
int i_ret = -1;
if (p_log != NULL) {
CONN_MD_INFO_FUNC("valid buffer pointer:%p.\n", p_log);
mutex_destroy(&p_log->lock);
vfree(p_log);
i_ret = 0;
} else {
CONN_MD_WARN_FUNC("invalid log buffer pointer\n");
i_ret = CONN_MD_ERR_INVALID_PARAM;
}
return i_ret;
}
int __conn_md_dmp_in(struct ipc_ilm *p_ilm, enum conn_md_msg_type msg_type,
struct conn_md_dmp_msg_log *p_msg_log)
{
struct timeval now;
struct conn_md_dmp_msg_str *p_msg = NULL;
/*get current time */
do_gettimeofday(&now);
mutex_lock(&p_msg_log->lock);
p_msg = &p_msg_log->msg[p_msg_log->in];
/*Log timestamp */
p_msg->sec = now.tv_sec;
p_msg->usec = now.tv_usec;
p_msg->type = msg_type;
/*Log p_ilm */
memcpy(&p_msg->ilm, p_ilm, sizeof(struct ipc_ilm));
/*Log msg length */
p_msg->msg_len = p_ilm->local_para_ptr->msg_len
- sizeof(struct local_para);
/*Log msg content */
memcpy(&p_msg->data, p_ilm->local_para_ptr->data,
p_msg->msg_len > LENGTH_PER_PACKAGE ? LENGTH_PER_PACKAGE :
p_msg->msg_len);
/*update in size and index */
if (p_msg_log->size >= NUMBER_OF_MSG_LOGGED)
p_msg_log->size = NUMBER_OF_MSG_LOGGED;
else
p_msg_log->size++;
p_msg_log->in++;
p_msg_log->in %= NUMBER_OF_MSG_LOGGED;
mutex_unlock(&p_msg_log->lock);
CONN_MD_DBG_FUNC("msg type:%d enqueued succeed\n", msg_type);
return 0;
}
int conn_md_dmp_in(struct ipc_ilm *p_ilm, enum conn_md_msg_type msg_type,
struct conn_md_dmp_msg_log *p_msg_log)
{
int i_ret = -1;
if (p_ilm == NULL ||
p_ilm->local_para_ptr == NULL ||
p_ilm->local_para_ptr->msg_len == 0 ||
(msg_type != MSG_ENQUEUE && msg_type != MSG_DEQUEUE)) {
CONN_MD_WARN_FUNC("invalid parameter\n");
i_ret = CONN_MD_ERR_INVALID_PARAM;
} else {
i_ret = __conn_md_dmp_in(p_ilm, msg_type, p_msg_log);
}
return i_ret;
}
int __conn_md_dmp_msg_filter(struct conn_md_dmp_msg_str *p_msg,
uint32 src_id, uint32 dst_id)
{
struct ipc_ilm *p_ilm = &p_msg->ilm;
int i = 0;
if (((src_id == 0) || (src_id == p_ilm->src_mod_id)) &&
((dst_id == 0) || (dst_id == p_ilm->dest_mod_id))) {
__conn_md_log_print(DFT_TAG
"%d.%ds,<%s>src:0x%08x,dst:0x%08x,msg_len:%d,dump_len:%d:\n",
p_msg->sec, p_msg->usec,
(p_msg->type == MSG_ENQUEUE ? "enqueue" : "dequeue"),
p_msg->ilm.src_mod_id, p_msg->ilm.dest_mod_id, p_msg->msg_len,
(p_msg->msg_len <= LENGTH_PER_PACKAGE ? p_msg->msg_len :
LENGTH_PER_PACKAGE));
for (i = 0; (i < p_msg->msg_len) && (i < LENGTH_PER_PACKAGE);
i++) {
__conn_md_log_print("%02x ", p_msg->data[i]);
if (7 == (i % 8))
__conn_md_log_print("\n");
}
__conn_md_log_print("\n");
}
return 0;
}
int conn_md_dmp_out(struct conn_md_dmp_msg_log *p_msg_log,
uint32 src_id, uint32 dst_id)
{
int i_ret = 0;
int size = 0;
int in = 0;
int out = 0;
struct conn_md_dmp_msg_str *p_msg = NULL;
if (p_msg_log == NULL) {
CONN_MD_WARN_FUNC("invalid parameter, p_msg_log is NULL\n");
return CONN_MD_ERR_INVALID_PARAM;
}
mutex_lock(&p_msg_log->lock);
size = p_msg_log->size;
mutex_unlock(&p_msg_log->lock);
CONN_MD_INFO_FUNC("dump msg <src_id:0x%08x, dst_id:0x%08x> start\n",
src_id, dst_id);
if (size == NUMBER_OF_MSG_LOGGED)
out = in;
else
out = 0;
while (size--) {
p_msg = &p_msg_log->msg[out];
__conn_md_dmp_msg_filter(p_msg, src_id, dst_id);
out++;
out %= NUMBER_OF_MSG_LOGGED;
}
mutex_unlock(&p_msg_log->lock);
CONN_MD_INFO_FUNC("dump msg <src_id:0x%08x, dst_id:0x%08x> finished\n",
src_id, dst_id);
return i_ret;
}
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#define DFT_TAG "[CONN_MD_EXP]"
#include "conn_md_exp.h"
#include "conn_md_log.h"
#include "conn_md.h"
int mtk_conn_md_bridge_reg(uint32 u_id, struct conn_md_bridge_ops *p_ops)
{
int i_ret = -1;
/*sanity check */
if (NULL != p_ops && NULL != p_ops->rx_cb) {
/*add user */
i_ret = conn_md_add_user(u_id, p_ops);
} else {
CONN_MD_ERR_FUNC("ERROR, u_id(0x%08x)\n", u_id);
CONN_MD_ERR_FUNC("ERROR, p_ops(%p), rx_cb(%p)\n",
p_ops, NULL == p_ops ? NULL : p_ops->rx_cb);
i_ret = CONN_MD_ERR_INVALID_PARAM;
}
return i_ret;
}
EXPORT_SYMBOL(mtk_conn_md_bridge_reg);
int mtk_conn_md_bridge_unreg(uint32 u_id)
{
int i_ret = -1;
/*delete user */
i_ret = conn_md_del_user(u_id);
return 0;
}
EXPORT_SYMBOL(mtk_conn_md_bridge_unreg);
int mtk_conn_md_bridge_send_msg(struct ipc_ilm *ilm)
{
int i_ret = -1;
/*sanity check */
if (NULL != ilm && NULL != ilm->local_para_ptr) {
/*send data */
i_ret = conn_md_send_msg(ilm);
} else {
CONN_MD_ERR_FUNC("ERROR, ilm(%p),local_para_ptr(%p)\n",
ilm, ilm == NULL ? NULL : ilm->local_para_ptr);
i_ret = CONN_MD_ERR_INVALID_PARAM;
}
return 0;
}
EXPORT_SYMBOL(mtk_conn_md_bridge_send_msg);
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include "conn_md_log.h"
int g_conn_md_dbg_lvl = CONN_MD_LOG_INFO;
/*Log defination*/
int __conn_md_log_print(const char *str, ...)
{
va_list args;
int ret;
char temp_sring[DBG_LOG_STR_SIZE];
va_start(args, str);
ret = vsnprintf(temp_sring, DBG_LOG_STR_SIZE, str, args);
va_end(args);
if (ret > 0)
pr_info("%s", temp_sring);
return ret;
}
int __conn_md_get_log_lvl(void)
{
/* return CONN_MD_LOG_INFO; */
return g_conn_md_dbg_lvl;
}
#define CONN_MD_LOG_LOUD 4
#define CONN_MD_LOG_DBG 3
#define CONN_MD_LOG_INFO 2
#define CONN_MD_LOG_WARN 1
#define CONN_MD_LOG_ERR 0
int conn_md_log_set_lvl(int log_lvl)
{
/* return CONN_MD_LOG_INFO; */
g_conn_md_dbg_lvl = log_lvl;
if (g_conn_md_dbg_lvl > CONN_MD_LOG_LOUD) {
CONN_MD_ERR_FUNC("log_lvl(%d) is too big, round to %d\n",
log_lvl, CONN_MD_LOG_LOUD);
g_conn_md_dbg_lvl = CONN_MD_LOG_LOUD;
}
if (g_conn_md_dbg_lvl < CONN_MD_LOG_ERR) {
CONN_MD_ERR_FUNC("log_lvl(%d) is too small, round to %d\n",
log_lvl, CONN_MD_LOG_ERR);
g_conn_md_dbg_lvl = CONN_MD_LOG_ERR;
}
return g_conn_md_dbg_lvl;
}
@@ -0,0 +1,148 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#define DFT_TAG "[CONN_MD_EXP]"
#include "conn_md_log.h"
#include "conn_md_exp.h"
#include "conn_md.h"
struct conn_md_bridge_ops g_ops;
static int conn_md_test_rx_cb(struct ipc_ilm *ilm);
int conn_md_test(void)
{
#define PACKAGE_SIZE 100
struct ipc_ilm ilm;
struct local_para *p_buf_str;
int i = 0;
int msg_len = 0;
p_buf_str = kmalloc(sizeof(struct local_para) + PACKAGE_SIZE,
GFP_ATOMIC);
if (p_buf_str == NULL) {
CONN_MD_ERR_FUNC("kmalloc for local para structure failed.\n");
return -1;
}
p_buf_str->msg_len = PACKAGE_SIZE;
for (i = 0; i < PACKAGE_SIZE; i++)
p_buf_str->data[i] = i;
ilm.local_para_ptr = p_buf_str;
g_ops.rx_cb = conn_md_test_rx_cb;
mtk_conn_md_bridge_reg(0x800001, &g_ops);
mtk_conn_md_bridge_reg(0x800005, &g_ops);
mtk_conn_md_bridge_reg(0x800009, &g_ops);
ilm.dest_mod_id = 0x800005;
ilm.src_mod_id = 0x800001;
ilm.msg_id = 0;
mtk_conn_md_bridge_send_msg(&ilm);
ilm.dest_mod_id = 0x800005;
ilm.src_mod_id = 0x800009;
ilm.msg_id++;
msg_len += 10;
msg_len = ((msg_len >= PACKAGE_SIZE) ? PACKAGE_SIZE : msg_len);
ilm.local_para_ptr->msg_len = msg_len;
mtk_conn_md_bridge_send_msg(&ilm);
ilm.dest_mod_id = 0x800001;
ilm.src_mod_id = 0x800009;
ilm.msg_id++;
msg_len += 10;
msg_len = ((msg_len >= PACKAGE_SIZE) ? PACKAGE_SIZE : msg_len);
ilm.local_para_ptr->msg_len = msg_len;
mtk_conn_md_bridge_send_msg(&ilm);
ilm.dest_mod_id = 0x80000a;
ilm.src_mod_id = 0x800009;
ilm.msg_id++;
msg_len += 10;
msg_len = ((msg_len >= PACKAGE_SIZE) ? PACKAGE_SIZE : msg_len);
ilm.local_para_ptr->msg_len = msg_len;
mtk_conn_md_bridge_send_msg(&ilm);
ilm.dest_mod_id = 0x800009;
ilm.src_mod_id = 0x80000a;
ilm.msg_id++;
msg_len += 10;
msg_len = ((msg_len >= PACKAGE_SIZE) ? PACKAGE_SIZE : msg_len);
ilm.local_para_ptr->msg_len = msg_len;
mtk_conn_md_bridge_send_msg(&ilm);
ilm.dest_mod_id = 0x800005;
ilm.src_mod_id = 0x800001;
ilm.msg_id++;
msg_len += 10;
msg_len = ((msg_len >= PACKAGE_SIZE) ? PACKAGE_SIZE : msg_len);
ilm.local_para_ptr->msg_len = msg_len;
mtk_conn_md_bridge_send_msg(&ilm);
ilm.dest_mod_id = 0x800001;
ilm.src_mod_id = 0x800005;
ilm.msg_id++;
msg_len += 10;
msg_len = ((msg_len >= PACKAGE_SIZE) ? PACKAGE_SIZE : msg_len);
ilm.local_para_ptr->msg_len = msg_len;
mtk_conn_md_bridge_send_msg(&ilm);
ilm.dest_mod_id = 0x800001;
ilm.src_mod_id = 0x80000a;
ilm.msg_id++;
msg_len += 10;
msg_len = ((msg_len >= PACKAGE_SIZE) ? PACKAGE_SIZE : msg_len);
ilm.local_para_ptr->msg_len = msg_len;
mtk_conn_md_bridge_send_msg(&ilm);
kfree(p_buf_str);
p_buf_str = NULL;
conn_md_dmp_msg_queued(0, 0x80000a);
mtk_conn_md_bridge_unreg(0x800001);
conn_md_dmp_msg_queued(0, 0);
conn_md_dmp_msg_active(0, 0);
mtk_conn_md_bridge_unreg(0x800009);
mtk_conn_md_bridge_unreg(0x80000a);
conn_md_dmp_msg_queued(0, 0);
conn_md_dmp_msg_active(0, 0);
conn_md_dmp_msg_logged(0x800009, 0x800001);
conn_md_dmp_msg_logged(0x800009, 0);
conn_md_dmp_msg_logged(0, 0);
conn_md_dmp_msg_logged(0x80000a, 0);
return 0;
}
static int conn_md_test_rx_cb(struct ipc_ilm *ilm)
{
int i = 0;
pr_info("%s, ilm:0x%p\n", __func__, ilm);
pr_info("%s, ilm:src_id(%d), dst_id(%d), msg_id(%d)\n", __func__,
ilm->src_mod_id, ilm->dest_mod_id, ilm->msg_id);
pr_info("%s, local_para_ptr:0x%p, msg_len:%d\n",
__func__, ilm->local_para_ptr,
ilm->local_para_ptr->msg_len);
for (i = 0; i < ilm->local_para_ptr->msg_len; i++) {
pr_info("%d ", ilm->local_para_ptr->data[i]);
if ((i != 0) && (((1 + i) % 8) == 0))
pr_info("\n");
}
return 0;
}
@@ -0,0 +1,80 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __CONN_MD_H_
#define __CONN_MD_H_
#include "conn_md_exp.h"
#include "conn_md_dump.h"
/*-----------------------Data Structure Definition-----------------------*/
enum user_state {
USER_MIN,
USER_REGED,
USER_ENABLED,
USER_DISABLED,
USER_UNREGED,
USER_MAX,
};
struct conn_md_user {
uint32 u_id;
enum user_state state;
struct conn_md_bridge_ops ops;
struct list_head entry;
};
struct conn_md_msg {
struct ipc_ilm ilm;
struct list_head entry;
struct local_para local_para;
};
struct conn_md_queue {
struct list_head list;
struct mutex lock;
uint32 counter;
};
struct conn_md_user_list {
uint32 counter;
struct list_head list;
struct mutex lock; /*lock for user add/delete/check */
};
struct conn_md_struct {
/*con-md-thread used for tx queue handle */
struct task_struct *p_task;
struct completion tx_comp;
struct conn_md_user_list user_list;
struct conn_md_queue act_queue;
struct conn_md_queue msg_queue;
struct conn_md_dmp_msg_log *p_msg_dmp_sys;
};
struct conn_md_time_struct {
unsigned long long sec;
unsigned long msec;
};
#define CONN_MD_MSG_MAX_NUM 5
#define CONN_MD_MSG_TIME_LENGTH 16
#define CONN_MD_BUF_SIZE (CONN_MD_MSG_MAX_NUM * CONN_MD_MSG_TIME_LENGTH)
struct conn_md_log_msg_info {
struct conn_md_time_struct msg_begin_time;
int msg_total;
char msg_buf[CONN_MD_BUF_SIZE];
};
extern int conn_md_send_msg(struct ipc_ilm *ilm);
extern int conn_md_del_user(uint32 u_id);
extern int conn_md_add_user(uint32 u_id, struct conn_md_bridge_ops *p_ops);
extern int conn_md_dmp_msg_logged(uint32 src_id, uint32 dst_id);
extern int conn_md_dmp_msg_active(uint32 src_id, uint32 dst_id);
extern int conn_md_dmp_msg_queued(uint32 src_id, uint32 dst_id);
#endif
@@ -0,0 +1,18 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __CONN_MD_DBG_H_
#define __CONN_MD_DBG_H_
typedef int (*conn_md_dev_dbg_func) (int par1, int par2, int par3);
extern int conn_md_dbg_init(void);
extern int conn_md_test(void);
ssize_t conn_md_dbg_read(struct file *filp, char __user *buf,
size_t count, loff_t *f_pos);
ssize_t conn_md_dbg_write(struct file *filp, const char __user *buf,
size_t count, loff_t *f_pos);
#endif/*__CONN_MD_DBG_H_*/
@@ -0,0 +1,47 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __CONN_MD_DUMP_H_
#define __CONN_MD_DUMP_H_
#include "conn_md_log.h"
#include "conn_md_exp.h"
#define LENGTH_PER_PACKAGE 8
#define NUMBER_OF_MSG_LOGGED 16
enum conn_md_msg_type {
MSG_ENQUEUE = 1,
MSG_DEQUEUE = 2,
MSG_EN_DE_QUEUE = 3,
};
struct conn_md_dmp_msg_str {
unsigned int sec;
unsigned int usec;
enum conn_md_msg_type type;
struct ipc_ilm ilm;
uint16 msg_len;
uint8 data[LENGTH_PER_PACKAGE];
};
struct conn_md_dmp_msg_log {
struct conn_md_dmp_msg_str msg[NUMBER_OF_MSG_LOGGED];
uint16 in;
uint16 out;
uint32 size;
struct mutex lock;
};
extern struct conn_md_dmp_msg_log *conn_md_dmp_init(void);
extern int conn_md_dmp_deinit(struct conn_md_dmp_msg_log *p_log);
extern int conn_md_dmp_in(struct ipc_ilm *p_ilm,
enum conn_md_msg_type msg_type,
struct conn_md_dmp_msg_log *p_msg_log);
extern int conn_md_dmp_out(struct conn_md_dmp_msg_log *p_msg_log,
uint32 src_id, uint32 dst_id);
#endif
@@ -0,0 +1,48 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __CONN_MD_EXP_H_
#define __CONN_MD_EXP_H_
#include "port_ipc.h" /*mediatek/kernel/drivers/eccci */
#include "ccci_ipc_task_ID.h" /*mediatek/kernel/drivers/eccci */
#define uint32 unsigned int
#define uint8 unsigned char
#define uint16 unsigned short
#ifdef CHAR
#undef CHAR
#endif
/*
* Provide a common conn_md_ipc_ilm_t definition for wmt_drv.ko to reference,
* this decouples wmt_drv.ko away from ECCCI's ipc_ilm definition, as its
* naming varies between different Kernel versions currently.
* If in future the fields in this struct varies as well, we could either:
* 1. Redefine entire struct from conn_md, or
* 2. Let wmt_drv.ko handles the difference via:
* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
*/
#define conn_md_ipc_ilm_t struct ipc_ilm
enum CONN_MD_ERR_CODE {
CONN_MD_ERR_NO_ERR = 0,
CONN_MD_ERR_DEF_ERR = -1,
CONN_MD_ERR_INVALID_PARAM = -2,
CONN_MD_ERR_OTHERS = -4,
};
/*For IDC test*/
typedef int (*conn_md_msg_rx_cb) (struct ipc_ilm *ilm);
struct conn_md_bridge_ops {
conn_md_msg_rx_cb rx_cb;
};
extern int mtk_conn_md_bridge_reg(uint32 u_id,
struct conn_md_bridge_ops *p_ops);
extern int mtk_conn_md_bridge_unreg(uint32 u_id);
extern int mtk_conn_md_bridge_send_msg(struct ipc_ilm *ilm);
#endif /*__CONN_MD_EXP_H_*/
@@ -0,0 +1,94 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __CONN_MD_LOG_H_
#define __CONN_MD_LOG_H_
#include <linux/module.h>
#include <linux/types.h>
#include <linux/mutex.h>
#include <linux/spinlock.h>
#include <linux/atomic.h>
#include <linux/list.h>
#include <linux/dma-mapping.h>
#include <linux/vmalloc.h>
#include <linux/sched.h>
#include <linux/kthread.h>
#include <linux/workqueue.h>
#include <linux/interrupt.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/string.h>
#include <linux/time.h> /* gettimeofday */
#include <linux/vmalloc.h>
#include <linux/mm.h>
#include <linux/device.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/completion.h>
#include <linux/slab.h>
#include <linux/proc_fs.h>
#include <linux/kernel.h>
#define DBG_LOG_STR_SIZE 256
extern int g_conn_md_dbg_lvl;
extern int __conn_md_get_log_lvl(void);
extern int conn_md_log_set_lvl(int log_lvl);
extern int __conn_md_log_print(const char *str, ...);
#define CONN_MD_LOG_LOUD 4
#define CONN_MD_LOG_DBG 3
#define CONN_MD_LOG_INFO 2
#define CONN_MD_LOG_WARN 1
#define CONN_MD_LOG_ERR 0
#ifndef DFT_TAG
#define DFT_TAG "[CONN-MD-DFT]"
#endif
#define CONN_MD_LOUD_FUNC(fmt, arg ...) \
do { \
if (__conn_md_get_log_lvl() >= CONN_MD_LOG_LOUD) \
__conn_md_log_print(DFT_TAG "[L]%s:" fmt, \
__func__, ## arg); \
} while (0)
#define CONN_MD_INFO_FUNC(fmt, arg ...) \
do { \
if (__conn_md_get_log_lvl() >= CONN_MD_LOG_INFO)\
__conn_md_log_print(DFT_TAG "[I]%s:" fmt, \
__func__, ## arg); \
} while (0)
#define CONN_MD_WARN_FUNC(fmt, arg ...) \
do { \
if (__conn_md_get_log_lvl() >= CONN_MD_LOG_WARN)\
__conn_md_log_print(DFT_TAG "[W]%s:" fmt, \
__func__, ## arg); \
} while (0)
#define CONN_MD_ERR_FUNC(fmt, arg ...)\
do {\
if (__conn_md_get_log_lvl() >= CONN_MD_LOG_ERR)\
__conn_md_log_print(DFT_TAG "[E]%s(%d):" fmt,\
__func__, __LINE__, ## arg);\
} while (0)
#define CONN_MD_DBG_FUNC(fmt, arg ...) \
do { \
if (__conn_md_get_log_lvl() >= CONN_MD_LOG_DBG) \
__conn_md_log_print(DFT_TAG "[D]%s:" fmt, \
__func__, ## arg); \
} while (0)
#define CONN_MD_TRC_FUNC(f) \
do { \
if (__conn_md_get_log_lvl() >= CONN_MD_LOG_DBG) \
__conn_md_log_print(DFT_TAG "<%s> <%d>\n", \
__func__, __LINE__); \
} while (0)
#endif