blob: 6ddce320df45fd0a04a01221317e6a3854bed2b0 [file] [log] [blame]
Manoj Prabhu B571cf422017-08-08 19:01:41 +05301/* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -07002 *
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 Gownipalli588a31d2016-11-02 13:33:43 -070030 ((x == PERIPHERAL_WDSP) ? DIAG_CON_WDSP : \
31 ((x == PERIPHERAL_CDSP) ? DIAG_CON_CDSP : 0)))))) \
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070032
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 Gownipalli588a31d2016-11-02 13:33:43 -070038 ((x == PERIPHERAL_WDSP) ? "WDSP" : \
39 ((x == PERIPHERAL_CDSP) ? "CDSP" : "UNKNOWN")))))) \
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070040
41struct 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
50struct 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
57struct 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 B90e1f502017-11-02 20:01:45 +053065struct diag_id_info {
66 uint8_t diagid_val;
67 uint8_t pd;
68 char *reg_str;
69};
70
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070071struct 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 B571cf422017-08-08 19:01:41 +053077 uint8_t num_pd;
Manoj Prabhu B571cf422017-08-08 19:01:41 +053078 int cpd_len_1;
79 int cpd_len_2;
80 int upd_len[MAX_PERIPHERAL_UPD][2];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070081 atomic_t opened;
82 unsigned long read_bytes;
83 unsigned long write_bytes;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070084 spinlock_t write_buf_lock;
Sreelakshmi Gownipalliae6c8e82016-11-29 16:01:13 -080085 struct mutex buf_mutex;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070086 struct mutex data_mutex;
87 void *ctxt;
Manoj Prabhu B90e1f502017-11-02 20:01:45 +053088 struct diag_id_info root_diag_id;
89 struct diag_id_info upd_diag_id[MAX_PERIPHERAL_UPD];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070090 struct diagfwd_buf_t *buf_1;
91 struct diagfwd_buf_t *buf_2;
Manoj Prabhu B571cf422017-08-08 19:01:41 +053092 struct diagfwd_buf_t *buf_upd[MAX_PERIPHERAL_UPD][2];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070093 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
98extern struct diagfwd_info peripheral_info[NUM_TYPES][NUM_PERIPHERALS];
99
100int diagfwd_peripheral_init(void);
101void diagfwd_peripheral_exit(void);
102
103void diagfwd_close_transport(uint8_t transport, uint8_t peripheral);
104
105void diagfwd_open(uint8_t peripheral, uint8_t type);
106void diagfwd_early_open(uint8_t peripheral);
107
108void diagfwd_late_open(struct diagfwd_info *fwd_info);
109void diagfwd_close(uint8_t peripheral, uint8_t type);
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530110
111int diag_md_get_peripheral(int ctxt);
112
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700113int 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);
116int diagfwd_cntl_register(uint8_t transport, uint8_t peripheral, void *ctxt,
117 struct diag_peripheral_ops *ops,
118 struct diagfwd_info **fwd_ctxt);
119void diagfwd_deregister(uint8_t peripheral, uint8_t type, void *ctxt);
120
121int diagfwd_write(uint8_t peripheral, uint8_t type, void *buf, int len);
Hardik Arya53bf3452017-09-06 15:34:19 +0530122void diagfwd_write_done(uint8_t peripheral, uint8_t type, int buf_num);
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700123void diagfwd_buffers_init(struct diagfwd_info *fwd_info);
124
125/*
126 * The following functions are called by the channels
127 */
128int diagfwd_channel_open(struct diagfwd_info *fwd_info);
129int diagfwd_channel_close(struct diagfwd_info *fwd_info);
130void diagfwd_channel_read(struct diagfwd_info *fwd_info);
131int diagfwd_channel_read_done(struct diagfwd_info *fwd_info,
132 unsigned char *buf, uint32_t len);
133int diagfwd_write_buffer_done(struct diagfwd_info *fwd_info, const void *ptr);
134
135#endif