Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include "cam_req_mgr_debug.h" |
| 14 | |
| 15 | #define MAX_SESS_INFO_LINE_BUFF_LEN 256 |
| 16 | |
| 17 | static char sess_info_buffer[MAX_SESS_INFO_LINE_BUFF_LEN]; |
| 18 | |
| 19 | static int cam_req_mgr_debug_set_bubble_recovery(void *data, u64 val) |
| 20 | { |
| 21 | struct cam_req_mgr_core_device *core_dev = data; |
| 22 | struct cam_req_mgr_core_session *session; |
| 23 | int rc = 0; |
| 24 | |
| 25 | mutex_lock(&core_dev->crm_lock); |
| 26 | |
| 27 | if (!list_empty(&core_dev->session_head)) { |
| 28 | list_for_each_entry(session, |
| 29 | &core_dev->session_head, entry) { |
| 30 | session->force_err_recovery = val; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | mutex_unlock(&core_dev->crm_lock); |
| 35 | |
| 36 | return rc; |
| 37 | } |
| 38 | |
| 39 | static int cam_req_mgr_debug_get_bubble_recovery(void *data, u64 *val) |
| 40 | { |
| 41 | struct cam_req_mgr_core_device *core_dev = data; |
| 42 | struct cam_req_mgr_core_session *session; |
| 43 | |
| 44 | mutex_lock(&core_dev->crm_lock); |
| 45 | |
| 46 | if (!list_empty(&core_dev->session_head)) { |
| 47 | session = list_first_entry(&core_dev->session_head, |
| 48 | struct cam_req_mgr_core_session, |
| 49 | entry); |
| 50 | *val = session->force_err_recovery; |
| 51 | } |
| 52 | mutex_unlock(&core_dev->crm_lock); |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | DEFINE_SIMPLE_ATTRIBUTE(bubble_recovery, cam_req_mgr_debug_get_bubble_recovery, |
| 58 | cam_req_mgr_debug_set_bubble_recovery, "%lld\n"); |
| 59 | |
| 60 | static int session_info_open(struct inode *inode, struct file *file) |
| 61 | { |
| 62 | file->private_data = inode->i_private; |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | static ssize_t session_info_read(struct file *t_file, char *t_char, |
| 67 | size_t t_size_t, loff_t *t_loff_t) |
| 68 | { |
| 69 | int i; |
| 70 | char *out_buffer = sess_info_buffer; |
| 71 | char line_buffer[MAX_SESS_INFO_LINE_BUFF_LEN] = {0}; |
| 72 | struct cam_req_mgr_core_device *core_dev = |
| 73 | (struct cam_req_mgr_core_device *) t_file->private_data; |
| 74 | struct cam_req_mgr_core_session *session; |
| 75 | |
| 76 | memset(out_buffer, 0, MAX_SESS_INFO_LINE_BUFF_LEN); |
| 77 | |
| 78 | mutex_lock(&core_dev->crm_lock); |
| 79 | |
| 80 | if (!list_empty(&core_dev->session_head)) { |
| 81 | list_for_each_entry(session, |
| 82 | &core_dev->session_head, entry) { |
| 83 | snprintf(line_buffer, sizeof(line_buffer), |
| 84 | "session_hdl = %x \t" |
| 85 | "num_links = %d\n", |
| 86 | session->session_hdl, session->num_links); |
| 87 | strlcat(out_buffer, line_buffer, |
| 88 | sizeof(sess_info_buffer)); |
| 89 | for (i = 0; i < session->num_links; i++) { |
| 90 | snprintf(line_buffer, sizeof(line_buffer), |
| 91 | "link_hdl[%d] = 0x%x, num_devs connected = %d\n", |
| 92 | i, session->links[i]->link_hdl, |
| 93 | session->links[i]->num_devs); |
| 94 | strlcat(out_buffer, line_buffer, |
| 95 | sizeof(sess_info_buffer)); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | mutex_unlock(&core_dev->crm_lock); |
| 101 | |
| 102 | return simple_read_from_buffer(t_char, t_size_t, |
| 103 | t_loff_t, out_buffer, strlen(out_buffer)); |
| 104 | } |
| 105 | |
| 106 | static ssize_t session_info_write(struct file *t_file, |
| 107 | const char *t_char, size_t t_size_t, loff_t *t_loff_t) |
| 108 | { |
| 109 | memset(sess_info_buffer, 0, MAX_SESS_INFO_LINE_BUFF_LEN); |
| 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static const struct file_operations session_info = { |
| 115 | .open = session_info_open, |
| 116 | .read = session_info_read, |
| 117 | .write = session_info_write, |
| 118 | }; |
| 119 | |
| 120 | int cam_req_mgr_debug_register(struct cam_req_mgr_core_device *core_dev) |
| 121 | { |
| 122 | struct dentry *debugfs_root; |
| 123 | char dirname[32] = {0}; |
| 124 | |
| 125 | snprintf(dirname, sizeof(dirname), "cam_req_mgr"); |
| 126 | debugfs_root = debugfs_create_dir(dirname, NULL); |
| 127 | if (!debugfs_root) |
| 128 | return -ENOMEM; |
| 129 | |
| 130 | if (!debugfs_create_file("sessions_info", 0644, |
| 131 | debugfs_root, core_dev, &session_info)) |
| 132 | return -ENOMEM; |
| 133 | |
| 134 | if (!debugfs_create_file("bubble_recovery", 0644, |
| 135 | debugfs_root, core_dev, &bubble_recovery)) |
| 136 | return -ENOMEM; |
| 137 | |
| 138 | return 0; |
| 139 | } |