Manoj Prabhu B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 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 | #ifndef DIAGFWD_PERIPHERAL_H |
| 14 | #define DIAGFWD_PERIPHERAL_H |
| 15 | |
| 16 | #define PERIPHERAL_BUF_SZ 16384 |
| 17 | #define MAX_PERIPHERAL_BUF_SZ 32768 |
| 18 | #define MAX_PERIPHERAL_HDLC_BUF_SZ 65539 |
| 19 | |
| 20 | #define TRANSPORT_UNKNOWN -1 |
| 21 | #define TRANSPORT_SOCKET 0 |
| 22 | #define TRANSPORT_GLINK 1 |
| 23 | #define NUM_TRANSPORT 2 |
| 24 | #define NUM_WRITE_BUFFERS 2 |
| 25 | #define PERIPHERAL_MASK(x) \ |
| 26 | ((x == PERIPHERAL_MODEM) ? DIAG_CON_MPSS : \ |
| 27 | ((x == PERIPHERAL_LPASS) ? DIAG_CON_LPASS : \ |
| 28 | ((x == PERIPHERAL_WCNSS) ? DIAG_CON_WCNSS : \ |
| 29 | ((x == PERIPHERAL_SENSORS) ? DIAG_CON_SENSORS : \ |
Sreelakshmi Gownipalli | 588a31d | 2016-11-02 13:33:43 -0700 | [diff] [blame] | 30 | ((x == PERIPHERAL_WDSP) ? DIAG_CON_WDSP : \ |
| 31 | ((x == PERIPHERAL_CDSP) ? DIAG_CON_CDSP : 0)))))) \ |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 32 | |
| 33 | #define PERIPHERAL_STRING(x) \ |
| 34 | ((x == PERIPHERAL_MODEM) ? "MODEM" : \ |
| 35 | ((x == PERIPHERAL_LPASS) ? "LPASS" : \ |
| 36 | ((x == PERIPHERAL_WCNSS) ? "WCNSS" : \ |
| 37 | ((x == PERIPHERAL_SENSORS) ? "SENSORS" : \ |
Sreelakshmi Gownipalli | 588a31d | 2016-11-02 13:33:43 -0700 | [diff] [blame] | 38 | ((x == PERIPHERAL_WDSP) ? "WDSP" : \ |
| 39 | ((x == PERIPHERAL_CDSP) ? "CDSP" : "UNKNOWN")))))) \ |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 40 | |
| 41 | struct diagfwd_buf_t { |
| 42 | unsigned char *data; |
| 43 | unsigned char *data_raw; |
| 44 | uint32_t len; |
| 45 | uint32_t len_raw; |
| 46 | atomic_t in_busy; |
| 47 | int ctxt; |
| 48 | }; |
| 49 | |
| 50 | struct diag_channel_ops { |
| 51 | void (*open)(struct diagfwd_info *fwd_info); |
| 52 | void (*close)(struct diagfwd_info *fwd_info); |
| 53 | void (*read_done)(struct diagfwd_info *fwd_info, |
| 54 | unsigned char *buf, int len); |
| 55 | }; |
| 56 | |
| 57 | struct diag_peripheral_ops { |
| 58 | void (*open)(void *ctxt); |
| 59 | void (*close)(void *ctxt); |
| 60 | int (*write)(void *ctxt, unsigned char *buf, int len); |
| 61 | int (*read)(void *ctxt, unsigned char *buf, int len); |
| 62 | void (*queue_read)(void *ctxt); |
| 63 | }; |
| 64 | |
Manoj Prabhu B | 90e1f50 | 2017-11-02 20:01:45 +0530 | [diff] [blame] | 65 | struct diag_id_info { |
| 66 | uint8_t diagid_val; |
| 67 | uint8_t pd; |
| 68 | char *reg_str; |
| 69 | }; |
| 70 | |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 71 | struct diagfwd_info { |
| 72 | uint8_t peripheral; |
| 73 | uint8_t type; |
| 74 | uint8_t transport; |
| 75 | uint8_t inited; |
| 76 | uint8_t ch_open; |
Manoj Prabhu B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 77 | uint8_t num_pd; |
Manoj Prabhu B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 78 | int cpd_len_1; |
| 79 | int cpd_len_2; |
| 80 | int upd_len[MAX_PERIPHERAL_UPD][2]; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 81 | atomic_t opened; |
| 82 | unsigned long read_bytes; |
| 83 | unsigned long write_bytes; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 84 | spinlock_t write_buf_lock; |
Sreelakshmi Gownipalli | ae6c8e8 | 2016-11-29 16:01:13 -0800 | [diff] [blame] | 85 | struct mutex buf_mutex; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 86 | struct mutex data_mutex; |
| 87 | void *ctxt; |
Manoj Prabhu B | 90e1f50 | 2017-11-02 20:01:45 +0530 | [diff] [blame] | 88 | struct diag_id_info root_diag_id; |
| 89 | struct diag_id_info upd_diag_id[MAX_PERIPHERAL_UPD]; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 90 | struct diagfwd_buf_t *buf_1; |
| 91 | struct diagfwd_buf_t *buf_2; |
Manoj Prabhu B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 92 | struct diagfwd_buf_t *buf_upd[MAX_PERIPHERAL_UPD][2]; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 93 | struct diagfwd_buf_t *buf_ptr[NUM_WRITE_BUFFERS]; |
| 94 | struct diag_peripheral_ops *p_ops; |
| 95 | struct diag_channel_ops *c_ops; |
| 96 | }; |
| 97 | |
| 98 | extern struct diagfwd_info peripheral_info[NUM_TYPES][NUM_PERIPHERALS]; |
| 99 | |
| 100 | int diagfwd_peripheral_init(void); |
| 101 | void diagfwd_peripheral_exit(void); |
| 102 | |
| 103 | void diagfwd_close_transport(uint8_t transport, uint8_t peripheral); |
| 104 | |
| 105 | void diagfwd_open(uint8_t peripheral, uint8_t type); |
| 106 | void diagfwd_early_open(uint8_t peripheral); |
| 107 | |
| 108 | void diagfwd_late_open(struct diagfwd_info *fwd_info); |
| 109 | void diagfwd_close(uint8_t peripheral, uint8_t type); |
Manoj Prabhu B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 110 | |
| 111 | int diag_md_get_peripheral(int ctxt); |
| 112 | |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 113 | int diagfwd_register(uint8_t transport, uint8_t peripheral, uint8_t type, |
| 114 | void *ctxt, struct diag_peripheral_ops *ops, |
| 115 | struct diagfwd_info **fwd_ctxt); |
| 116 | int diagfwd_cntl_register(uint8_t transport, uint8_t peripheral, void *ctxt, |
| 117 | struct diag_peripheral_ops *ops, |
| 118 | struct diagfwd_info **fwd_ctxt); |
| 119 | void diagfwd_deregister(uint8_t peripheral, uint8_t type, void *ctxt); |
| 120 | |
| 121 | int diagfwd_write(uint8_t peripheral, uint8_t type, void *buf, int len); |
Hardik Arya | 53bf345 | 2017-09-06 15:34:19 +0530 | [diff] [blame] | 122 | void diagfwd_write_done(uint8_t peripheral, uint8_t type, int buf_num); |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 123 | void diagfwd_buffers_init(struct diagfwd_info *fwd_info); |
| 124 | |
| 125 | /* |
| 126 | * The following functions are called by the channels |
| 127 | */ |
| 128 | int diagfwd_channel_open(struct diagfwd_info *fwd_info); |
| 129 | int diagfwd_channel_close(struct diagfwd_info *fwd_info); |
| 130 | void diagfwd_channel_read(struct diagfwd_info *fwd_info); |
| 131 | int diagfwd_channel_read_done(struct diagfwd_info *fwd_info, |
| 132 | unsigned char *buf, uint32_t len); |
| 133 | int diagfwd_write_buffer_done(struct diagfwd_info *fwd_info, const void *ptr); |
| 134 | |
| 135 | #endif |