| Eric Holmberg | 8ed30f2 | 2012-05-10 19:16:51 -0600 | [diff] [blame] | 1 | /* drivers/tty/smux_private.h |
| 2 | * |
| Duy Truong | e833aca | 2013-02-12 13:35:08 -0800 | [diff] [blame] | 3 | * Copyright (c) 2012, The Linux Foundation. All rights reserved. |
| Eric Holmberg | 8ed30f2 | 2012-05-10 19:16:51 -0600 | [diff] [blame] | 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 Holmberg | ffddd4c | 2012-06-08 12:37:51 -0600 | [diff] [blame] | 19 | #define SMUX_BROADCAST_LCID 0xFF |
| Eric Holmberg | 8ed30f2 | 2012-05-10 19:16:51 -0600 | [diff] [blame] | 20 | |
| 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 Holmberg | b8435c8 | 2012-06-05 14:51:29 -0600 | [diff] [blame] | 33 | /* Maximum number of packets in retry queue */ |
| Eric Holmberg | 06519d5 | 2012-08-28 11:54:45 -0600 | [diff] [blame] | 34 | #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 Holmberg | b8435c8 | 2012-06-05 14:51:29 -0600 | [diff] [blame] | 39 | |
| Eric Holmberg | 8ed30f2 | 2012-05-10 19:16:51 -0600 | [diff] [blame] | 40 | struct tty_struct; |
| 41 | |
| Eric Holmberg | f44a8cc | 2012-06-13 17:58:13 -0600 | [diff] [blame] | 42 | /** |
| 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 | */ |
| 59 | struct 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 */ |
| 96 | extern struct smux_lch_t smux_lch[SMUX_NUM_LOGICAL_CHANNELS]; |
| 97 | |
| Eric Holmberg | 8ed30f2 | 2012-05-10 19:16:51 -0600 | [diff] [blame] | 98 | /* Packet header. */ |
| 99 | struct 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. */ |
| 109 | struct 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 */ |
| 119 | enum { |
| 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, |
| 125 | |
| 126 | SMUX_CMD_BYTE, /* for internal usage */ |
| 127 | SMUX_NUM_COMMANDS |
| 128 | }; |
| 129 | |
| 130 | /* Open command flags */ |
| 131 | enum { |
| 132 | SMUX_CMD_OPEN_ACK = 1 << 0, |
| 133 | SMUX_CMD_OPEN_POWER_COLLAPSE = 1 << 1, |
| 134 | SMUX_CMD_OPEN_REMOTE_LOOPBACK = 1 << 2, |
| 135 | }; |
| 136 | |
| 137 | /* Close command flags */ |
| 138 | enum { |
| 139 | SMUX_CMD_CLOSE_ACK = 1 << 0, |
| 140 | }; |
| 141 | |
| 142 | /* Power command flags */ |
| 143 | enum { |
| 144 | SMUX_CMD_PWR_CTL_ACK = 1 << 0, |
| Eric Holmberg | 8ed30f2 | 2012-05-10 19:16:51 -0600 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | /* Local logical channel states */ |
| 148 | enum { |
| 149 | SMUX_LCH_LOCAL_CLOSED, |
| 150 | SMUX_LCH_LOCAL_OPENING, |
| 151 | SMUX_LCH_LOCAL_OPENED, |
| 152 | SMUX_LCH_LOCAL_CLOSING, |
| 153 | }; |
| 154 | |
| 155 | /* Remote logical channel states */ |
| 156 | enum { |
| 157 | SMUX_LCH_REMOTE_CLOSED, |
| 158 | SMUX_LCH_REMOTE_OPENED, |
| 159 | }; |
| 160 | |
| Eric Holmberg | f44a8cc | 2012-06-13 17:58:13 -0600 | [diff] [blame] | 161 | /* Enum used to report various undefined actions */ |
| 162 | enum { |
| 163 | SMUX_UNDEF_LONG, |
| 164 | SMUX_UNDEF_SHORT, |
| 165 | }; |
| 166 | |
| 167 | long msm_smux_tiocm_get_atomic(struct smux_lch_t *ch); |
| 168 | const char *local_lch_state(unsigned state); |
| 169 | const char *remote_lch_state(unsigned state); |
| 170 | const char *lch_mode(unsigned mode); |
| Eric Holmberg | 8ed30f2 | 2012-05-10 19:16:51 -0600 | [diff] [blame] | 171 | |
| 172 | int smux_assert_lch_id(uint32_t lcid); |
| 173 | void smux_init_pkt(struct smux_pkt_t *pkt); |
| 174 | struct smux_pkt_t *smux_alloc_pkt(void); |
| 175 | int smux_alloc_pkt_payload(struct smux_pkt_t *pkt); |
| 176 | void smux_free_pkt(struct smux_pkt_t *pkt); |
| 177 | int smux_serialize(struct smux_pkt_t *pkt, char *out, |
| 178 | unsigned int *out_len); |
| 179 | |
| 180 | void smux_rx_state_machine(const unsigned char *data, int len, int flag); |
| 181 | void smuxld_receive_buf(struct tty_struct *tty, const unsigned char *cp, |
| 182 | char *fp, int count); |
| Eric Holmberg | f3f3459 | 2012-08-28 13:51:14 -0600 | [diff] [blame] | 183 | bool smux_remote_is_active(void); |
| Eric Holmberg | 8ed30f2 | 2012-05-10 19:16:51 -0600 | [diff] [blame] | 184 | |
| 185 | /* testing parameters */ |
| 186 | extern int smux_byte_loopback; |
| 187 | extern int smux_simulate_wakeup_delay; |
| 188 | |
| 189 | #endif /* SMUX_PRIVATE_H */ |