blob: b9a2e89720b9ebb4ac9f2fdfa64c2ed8dbf97049 [file] [log] [blame]
Eric Holmberg8ed30f22012-05-10 19:16:51 -06001/* drivers/tty/smux_private.h
2 *
Eric Holmberg371b4622013-05-21 18:04:50 -06003 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Eric Holmberg8ed30f22012-05-10 19:16:51 -06004 *
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
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 */
15#ifndef SMUX_PRIVATE_H
16#define SMUX_PRIVATE_H
17
18#define SMUX_MAX_PKT_SIZE 8192
Eric Holmbergffddd4c2012-06-08 12:37:51 -060019#define SMUX_BROADCAST_LCID 0xFF
Eric Holmberg8ed30f22012-05-10 19:16:51 -060020
21/* SMUX Protocol Characters */
22#define SMUX_MAGIC 0x33FC
23#define SMUX_MAGIC_WORD1 0xFC
24#define SMUX_MAGIC_WORD2 0x33
25#define SMUX_WAKEUP_REQ 0xFD
26#define SMUX_WAKEUP_ACK 0xFE
27
28/* Unit testing characters */
29#define SMUX_UT_ECHO_REQ 0xF0
30#define SMUX_UT_ECHO_ACK_OK 0xF1
31#define SMUX_UT_ECHO_ACK_FAIL 0xF2
32
Eric Holmbergb8435c82012-06-05 14:51:29 -060033/* Maximum number of packets in retry queue */
Eric Holmberg0ab6fc12012-08-28 11:54:45 -060034#define SMUX_RX_RETRY_MAX_PKTS 128
35#define SMUX_RX_WM_HIGH 4
36#define SMUX_RX_WM_LOW 0
37#define SMUX_TX_WM_LOW 2
38#define SMUX_TX_WM_HIGH 4
Eric Holmbergb8435c82012-06-05 14:51:29 -060039
Eric Holmberg8ed30f22012-05-10 19:16:51 -060040struct tty_struct;
41
Eric Holmberg9d890672012-06-13 17:58:13 -060042/**
43 * Logical Channel Structure. One instance per channel.
44 *
45 * Locking Hierarchy
46 * Each lock has a postfix that describes the locking level. If multiple locks
47 * are required, only increasing lock hierarchy numbers may be locked which
48 * ensures avoiding a deadlock.
49 *
50 * Locking Example
51 * If state_lock_lhb1 is currently held and the TX list needs to be
52 * manipulated, then tx_lock_lhb2 may be locked since it's locking hierarchy
53 * is greater. However, if tx_lock_lhb2 is held, then state_lock_lhb1 may
54 * not be acquired since it would result in a deadlock.
55 *
56 * Note that the Line Discipline locks (*_lha) should always be acquired
57 * before the logical channel locks.
58 */
59struct smux_lch_t {
60 /* channel state */
61 spinlock_t state_lock_lhb1;
62 uint8_t lcid;
63 unsigned local_state;
64 unsigned local_mode;
65 uint8_t local_tiocm;
66 unsigned options;
67
68 unsigned remote_state;
69 unsigned remote_mode;
70 uint8_t remote_tiocm;
71
72 int tx_flow_control;
73 int rx_flow_control_auto;
74 int rx_flow_control_client;
75
76 /* client callbacks and private data */
77 void *priv;
78 void (*notify)(void *priv, int event_type, const void *metadata);
79 int (*get_rx_buffer)(void *priv, void **pkt_priv, void **buffer,
80 int size);
81
82 /* RX Info */
83 struct list_head rx_retry_queue;
84 unsigned rx_retry_queue_cnt;
85 struct delayed_work rx_retry_work;
86
87 /* TX Info */
88 spinlock_t tx_lock_lhb2;
89 struct list_head tx_queue;
90 struct list_head tx_ready_list;
91 unsigned tx_pending_data_cnt;
92 unsigned notify_lwm;
93};
94
95/* Each instance of smux_lch_t */
96extern struct smux_lch_t smux_lch[SMUX_NUM_LOGICAL_CHANNELS];
97
Eric Holmberg8ed30f22012-05-10 19:16:51 -060098/* Packet header. */
99struct smux_hdr_t {
100 uint16_t magic;
101 uint8_t flags;
102 uint8_t cmd;
103 uint8_t pad_len;
104 uint8_t lcid;
105 uint16_t payload_len;
106};
107
108/* Internal packet structure. */
109struct smux_pkt_t {
110 struct smux_hdr_t hdr;
111 int allocated;
112 unsigned char *payload;
113 int free_payload;
114 struct list_head list;
115 void *priv;
116};
117
118/* SMUX Packet Commands */
119enum {
120 SMUX_CMD_DATA = 0x0,
121 SMUX_CMD_OPEN_LCH = 0x1,
122 SMUX_CMD_CLOSE_LCH = 0x2,
123 SMUX_CMD_STATUS = 0x3,
124 SMUX_CMD_PWR_CTL = 0x4,
Eric Holmberg371b4622013-05-21 18:04:50 -0600125 SMUX_CMD_DELAY = 0x5,
Eric Holmberg8ed30f22012-05-10 19:16:51 -0600126
127 SMUX_CMD_BYTE, /* for internal usage */
128 SMUX_NUM_COMMANDS
129};
130
131/* Open command flags */
132enum {
133 SMUX_CMD_OPEN_ACK = 1 << 0,
134 SMUX_CMD_OPEN_POWER_COLLAPSE = 1 << 1,
135 SMUX_CMD_OPEN_REMOTE_LOOPBACK = 1 << 2,
136};
137
138/* Close command flags */
139enum {
140 SMUX_CMD_CLOSE_ACK = 1 << 0,
141};
142
143/* Power command flags */
144enum {
145 SMUX_CMD_PWR_CTL_ACK = 1 << 0,
Eric Holmberg8ed30f22012-05-10 19:16:51 -0600146};
147
148/* Local logical channel states */
149enum {
150 SMUX_LCH_LOCAL_CLOSED,
151 SMUX_LCH_LOCAL_OPENING,
152 SMUX_LCH_LOCAL_OPENED,
153 SMUX_LCH_LOCAL_CLOSING,
154};
155
156/* Remote logical channel states */
157enum {
158 SMUX_LCH_REMOTE_CLOSED,
159 SMUX_LCH_REMOTE_OPENED,
160};
161
Eric Holmberg9d890672012-06-13 17:58:13 -0600162/* Enum used to report various undefined actions */
163enum {
164 SMUX_UNDEF_LONG,
165 SMUX_UNDEF_SHORT,
166};
167
168long msm_smux_tiocm_get_atomic(struct smux_lch_t *ch);
169const char *local_lch_state(unsigned state);
170const char *remote_lch_state(unsigned state);
171const char *lch_mode(unsigned mode);
Eric Holmberg8ed30f22012-05-10 19:16:51 -0600172
173int smux_assert_lch_id(uint32_t lcid);
174void smux_init_pkt(struct smux_pkt_t *pkt);
175struct smux_pkt_t *smux_alloc_pkt(void);
176int smux_alloc_pkt_payload(struct smux_pkt_t *pkt);
177void smux_free_pkt(struct smux_pkt_t *pkt);
178int smux_serialize(struct smux_pkt_t *pkt, char *out,
179 unsigned int *out_len);
180
181void smux_rx_state_machine(const unsigned char *data, int len, int flag);
182void smuxld_receive_buf(struct tty_struct *tty, const unsigned char *cp,
183 char *fp, int count);
Eric Holmberg0a81e8f2012-08-28 13:51:14 -0600184bool smux_remote_is_active(void);
Eric Holmberg371b4622013-05-21 18:04:50 -0600185void smux_set_loopback_data_reply_delay(uint32_t ms);
186void smux_get_wakeup_counts(int *local_cnt, int *remote_cnt);
Eric Holmberg8ed30f22012-05-10 19:16:51 -0600187
188/* testing parameters */
189extern int smux_byte_loopback;
190extern int smux_simulate_wakeup_delay;
191
192#endif /* SMUX_PRIVATE_H */