Eric Holmberg | 8ed30f2 | 2012-05-10 19:16:51 -0600 | [diff] [blame] | 1 | /* drivers/tty/smux_private.h |
| 2 | * |
Eric Holmberg | 371b462 | 2013-05-21 18:04:50 -0600 | [diff] [blame] | 3 | * Copyright (c) 2012-2013, 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 | 0ab6fc1 | 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 | 9d89067 | 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, |
Eric Holmberg | 371b462 | 2013-05-21 18:04:50 -0600 | [diff] [blame] | 125 | SMUX_CMD_DELAY = 0x5, |
Eric Holmberg | 8ed30f2 | 2012-05-10 19:16:51 -0600 | [diff] [blame] | 126 | |
| 127 | SMUX_CMD_BYTE, /* for internal usage */ |
| 128 | SMUX_NUM_COMMANDS |
| 129 | }; |
| 130 | |
| 131 | /* Open command flags */ |
| 132 | enum { |
| 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 */ |
| 139 | enum { |
| 140 | SMUX_CMD_CLOSE_ACK = 1 << 0, |
| 141 | }; |
| 142 | |
| 143 | /* Power command flags */ |
| 144 | enum { |
| 145 | SMUX_CMD_PWR_CTL_ACK = 1 << 0, |
Eric Holmberg | 8ed30f2 | 2012-05-10 19:16:51 -0600 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | /* Local logical channel states */ |
| 149 | enum { |
| 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 */ |
| 157 | enum { |
| 158 | SMUX_LCH_REMOTE_CLOSED, |
| 159 | SMUX_LCH_REMOTE_OPENED, |
| 160 | }; |
| 161 | |
Eric Holmberg | 9d89067 | 2012-06-13 17:58:13 -0600 | [diff] [blame] | 162 | /* Enum used to report various undefined actions */ |
| 163 | enum { |
| 164 | SMUX_UNDEF_LONG, |
| 165 | SMUX_UNDEF_SHORT, |
| 166 | }; |
| 167 | |
| 168 | long msm_smux_tiocm_get_atomic(struct smux_lch_t *ch); |
| 169 | const char *local_lch_state(unsigned state); |
| 170 | const char *remote_lch_state(unsigned state); |
| 171 | const char *lch_mode(unsigned mode); |
Eric Holmberg | 8ed30f2 | 2012-05-10 19:16:51 -0600 | [diff] [blame] | 172 | |
| 173 | int smux_assert_lch_id(uint32_t lcid); |
| 174 | void smux_init_pkt(struct smux_pkt_t *pkt); |
| 175 | struct smux_pkt_t *smux_alloc_pkt(void); |
| 176 | int smux_alloc_pkt_payload(struct smux_pkt_t *pkt); |
| 177 | void smux_free_pkt(struct smux_pkt_t *pkt); |
| 178 | int smux_serialize(struct smux_pkt_t *pkt, char *out, |
| 179 | unsigned int *out_len); |
| 180 | |
| 181 | void smux_rx_state_machine(const unsigned char *data, int len, int flag); |
| 182 | void smuxld_receive_buf(struct tty_struct *tty, const unsigned char *cp, |
| 183 | char *fp, int count); |
Eric Holmberg | 0a81e8f | 2012-08-28 13:51:14 -0600 | [diff] [blame] | 184 | bool smux_remote_is_active(void); |
Eric Holmberg | 371b462 | 2013-05-21 18:04:50 -0600 | [diff] [blame] | 185 | void smux_set_loopback_data_reply_delay(uint32_t ms); |
| 186 | void smux_get_wakeup_counts(int *local_cnt, int *remote_cnt); |
Eric Holmberg | 8ed30f2 | 2012-05-10 19:16:51 -0600 | [diff] [blame] | 187 | |
| 188 | /* testing parameters */ |
| 189 | extern int smux_byte_loopback; |
| 190 | extern int smux_simulate_wakeup_delay; |
| 191 | |
| 192 | #endif /* SMUX_PRIVATE_H */ |