blob: 4c901c0bd2eeebd64ffc1473c268fa1c6195a973 [file] [log] [blame]
Eric Holmberg8ed30f22012-05-10 19:16:51 -06001/* drivers/tty/smux_private.h
2 *
3 * Copyright (c) 2012, Code Aurora Forum. All rights reserved.
4 *
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 Holmberg06519d52012-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
42/* Packet header. */
43struct smux_hdr_t {
44 uint16_t magic;
45 uint8_t flags;
46 uint8_t cmd;
47 uint8_t pad_len;
48 uint8_t lcid;
49 uint16_t payload_len;
50};
51
52/* Internal packet structure. */
53struct smux_pkt_t {
54 struct smux_hdr_t hdr;
55 int allocated;
56 unsigned char *payload;
57 int free_payload;
58 struct list_head list;
59 void *priv;
60};
61
62/* SMUX Packet Commands */
63enum {
64 SMUX_CMD_DATA = 0x0,
65 SMUX_CMD_OPEN_LCH = 0x1,
66 SMUX_CMD_CLOSE_LCH = 0x2,
67 SMUX_CMD_STATUS = 0x3,
68 SMUX_CMD_PWR_CTL = 0x4,
69
70 SMUX_CMD_BYTE, /* for internal usage */
71 SMUX_NUM_COMMANDS
72};
73
74/* Open command flags */
75enum {
76 SMUX_CMD_OPEN_ACK = 1 << 0,
77 SMUX_CMD_OPEN_POWER_COLLAPSE = 1 << 1,
78 SMUX_CMD_OPEN_REMOTE_LOOPBACK = 1 << 2,
79};
80
81/* Close command flags */
82enum {
83 SMUX_CMD_CLOSE_ACK = 1 << 0,
84};
85
86/* Power command flags */
87enum {
88 SMUX_CMD_PWR_CTL_ACK = 1 << 0,
Eric Holmberg8ed30f22012-05-10 19:16:51 -060089};
90
91/* Local logical channel states */
92enum {
93 SMUX_LCH_LOCAL_CLOSED,
94 SMUX_LCH_LOCAL_OPENING,
95 SMUX_LCH_LOCAL_OPENED,
96 SMUX_LCH_LOCAL_CLOSING,
97};
98
99/* Remote logical channel states */
100enum {
101 SMUX_LCH_REMOTE_CLOSED,
102 SMUX_LCH_REMOTE_OPENED,
103};
104
105
106int smux_assert_lch_id(uint32_t lcid);
107void smux_init_pkt(struct smux_pkt_t *pkt);
108struct smux_pkt_t *smux_alloc_pkt(void);
109int smux_alloc_pkt_payload(struct smux_pkt_t *pkt);
110void smux_free_pkt(struct smux_pkt_t *pkt);
111int smux_serialize(struct smux_pkt_t *pkt, char *out,
112 unsigned int *out_len);
113
114void smux_rx_state_machine(const unsigned char *data, int len, int flag);
115void smuxld_receive_buf(struct tty_struct *tty, const unsigned char *cp,
116 char *fp, int count);
117
118/* testing parameters */
119extern int smux_byte_loopback;
120extern int smux_simulate_wakeup_delay;
121
122#endif /* SMUX_PRIVATE_H */