smux_private.h 4.9 KB

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