caif_hsi.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Copyright (C) ST-Ericsson AB 2010
  3. * Contact: Sjur Brendeland / sjur.brandeland@stericsson.com
  4. * Author: Daniel Martensson / daniel.martensson@stericsson.com
  5. * Dmitry.Tarnyagin / dmitry.tarnyagin@stericsson.com
  6. * License terms: GNU General Public License (GPL) version 2
  7. */
  8. #ifndef CAIF_HSI_H_
  9. #define CAIF_HSI_H_
  10. #include <net/caif/caif_layer.h>
  11. #include <net/caif/caif_device.h>
  12. #include <linux/atomic.h>
  13. /*
  14. * Maximum number of CAIF frames that can reside in the same HSI frame.
  15. */
  16. #define CFHSI_MAX_PKTS 15
  17. /*
  18. * Maximum number of bytes used for the frame that can be embedded in the
  19. * HSI descriptor.
  20. */
  21. #define CFHSI_MAX_EMB_FRM_SZ 96
  22. /*
  23. * Decides if HSI buffers should be prefilled with 0xFF pattern for easier
  24. * debugging. Both TX and RX buffers will be filled before the transfer.
  25. */
  26. #define CFHSI_DBG_PREFILL 0
  27. /* Structure describing a HSI packet descriptor. */
  28. #pragma pack(1) /* Byte alignment. */
  29. struct cfhsi_desc {
  30. u8 header;
  31. u8 offset;
  32. u16 cffrm_len[CFHSI_MAX_PKTS];
  33. u8 emb_frm[CFHSI_MAX_EMB_FRM_SZ];
  34. };
  35. #pragma pack() /* Default alignment. */
  36. /* Size of the complete HSI packet descriptor. */
  37. #define CFHSI_DESC_SZ (sizeof(struct cfhsi_desc))
  38. /*
  39. * Size of the complete HSI packet descriptor excluding the optional embedded
  40. * CAIF frame.
  41. */
  42. #define CFHSI_DESC_SHORT_SZ (CFHSI_DESC_SZ - CFHSI_MAX_EMB_FRM_SZ)
  43. /*
  44. * Maximum bytes transferred in one transfer.
  45. */
  46. #define CFHSI_MAX_CAIF_FRAME_SZ 4096
  47. #define CFHSI_MAX_PAYLOAD_SZ (CFHSI_MAX_PKTS * CFHSI_MAX_CAIF_FRAME_SZ)
  48. /* Size of the complete HSI TX buffer. */
  49. #define CFHSI_BUF_SZ_TX (CFHSI_DESC_SZ + CFHSI_MAX_PAYLOAD_SZ)
  50. /* Size of the complete HSI RX buffer. */
  51. #define CFHSI_BUF_SZ_RX ((2 * CFHSI_DESC_SZ) + CFHSI_MAX_PAYLOAD_SZ)
  52. /* Bitmasks for the HSI descriptor. */
  53. #define CFHSI_PIGGY_DESC (0x01 << 7)
  54. #define CFHSI_TX_STATE_IDLE 0
  55. #define CFHSI_TX_STATE_XFER 1
  56. #define CFHSI_RX_STATE_DESC 0
  57. #define CFHSI_RX_STATE_PAYLOAD 1
  58. /* Bitmasks for power management. */
  59. #define CFHSI_WAKE_UP 0
  60. #define CFHSI_WAKE_UP_ACK 1
  61. #define CFHSI_WAKE_DOWN_ACK 2
  62. #define CFHSI_AWAKE 3
  63. #define CFHSI_WAKELOCK_HELD 4
  64. #define CFHSI_SHUTDOWN 5
  65. #define CFHSI_FLUSH_FIFO 6
  66. #ifndef CFHSI_INACTIVITY_TOUT
  67. #define CFHSI_INACTIVITY_TOUT (1 * HZ)
  68. #endif /* CFHSI_INACTIVITY_TOUT */
  69. #ifndef CFHSI_WAKE_TOUT
  70. #define CFHSI_WAKE_TOUT (3 * HZ)
  71. #endif /* CFHSI_WAKE_TOUT */
  72. #ifndef CFHSI_MAX_RX_RETRIES
  73. #define CFHSI_MAX_RX_RETRIES (10 * HZ)
  74. #endif
  75. /* Structure implemented by the CAIF HSI driver. */
  76. struct cfhsi_cb_ops {
  77. void (*tx_done_cb) (struct cfhsi_cb_ops *drv);
  78. void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
  79. void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
  80. void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
  81. };
  82. /* Structure implemented by HSI device. */
  83. struct cfhsi_ops {
  84. int (*cfhsi_up) (struct cfhsi_ops *dev);
  85. int (*cfhsi_down) (struct cfhsi_ops *dev);
  86. int (*cfhsi_tx) (u8 *ptr, int len, struct cfhsi_ops *dev);
  87. int (*cfhsi_rx) (u8 *ptr, int len, struct cfhsi_ops *dev);
  88. int (*cfhsi_wake_up) (struct cfhsi_ops *dev);
  89. int (*cfhsi_wake_down) (struct cfhsi_ops *dev);
  90. int (*cfhsi_get_peer_wake) (struct cfhsi_ops *dev, bool *status);
  91. int (*cfhsi_fifo_occupancy) (struct cfhsi_ops *dev, size_t *occupancy);
  92. int (*cfhsi_rx_cancel)(struct cfhsi_ops *dev);
  93. struct cfhsi_cb_ops *cb_ops;
  94. };
  95. /* Structure holds status of received CAIF frames processing */
  96. struct cfhsi_rx_state {
  97. int state;
  98. int nfrms;
  99. int pld_len;
  100. int retries;
  101. bool piggy_desc;
  102. };
  103. /* Priority mapping */
  104. enum {
  105. CFHSI_PRIO_CTL = 0,
  106. CFHSI_PRIO_VI,
  107. CFHSI_PRIO_VO,
  108. CFHSI_PRIO_BEBK,
  109. CFHSI_PRIO_LAST,
  110. };
  111. struct cfhsi_config {
  112. u32 inactivity_timeout;
  113. u32 aggregation_timeout;
  114. u32 head_align;
  115. u32 tail_align;
  116. u32 q_high_mark;
  117. u32 q_low_mark;
  118. };
  119. /* Structure implemented by CAIF HSI drivers. */
  120. struct cfhsi {
  121. struct caif_dev_common cfdev;
  122. struct net_device *ndev;
  123. struct platform_device *pdev;
  124. struct sk_buff_head qhead[CFHSI_PRIO_LAST];
  125. struct cfhsi_cb_ops cb_ops;
  126. struct cfhsi_ops *ops;
  127. int tx_state;
  128. struct cfhsi_rx_state rx_state;
  129. struct cfhsi_config cfg;
  130. int rx_len;
  131. u8 *rx_ptr;
  132. u8 *tx_buf;
  133. u8 *rx_buf;
  134. u8 *rx_flip_buf;
  135. spinlock_t lock;
  136. int flow_off_sent;
  137. struct list_head list;
  138. struct work_struct wake_up_work;
  139. struct work_struct wake_down_work;
  140. struct work_struct out_of_sync_work;
  141. struct workqueue_struct *wq;
  142. wait_queue_head_t wake_up_wait;
  143. wait_queue_head_t wake_down_wait;
  144. wait_queue_head_t flush_fifo_wait;
  145. struct timer_list inactivity_timer;
  146. struct timer_list rx_slowpath_timer;
  147. /* TX aggregation */
  148. int aggregation_len;
  149. struct timer_list aggregation_timer;
  150. unsigned long bits;
  151. };
  152. extern struct platform_driver cfhsi_driver;
  153. /**
  154. * enum ifla_caif_hsi - CAIF HSI NetlinkRT parameters.
  155. * @IFLA_CAIF_HSI_INACTIVITY_TOUT: Inactivity timeout before
  156. * taking the HSI wakeline down, in milliseconds.
  157. * When using RT Netlink to create, destroy or configure a CAIF HSI interface,
  158. * enum ifla_caif_hsi is used to specify the configuration attributes.
  159. */
  160. enum ifla_caif_hsi {
  161. __IFLA_CAIF_HSI_UNSPEC,
  162. __IFLA_CAIF_HSI_INACTIVITY_TOUT,
  163. __IFLA_CAIF_HSI_AGGREGATION_TOUT,
  164. __IFLA_CAIF_HSI_HEAD_ALIGN,
  165. __IFLA_CAIF_HSI_TAIL_ALIGN,
  166. __IFLA_CAIF_HSI_QHIGH_WATERMARK,
  167. __IFLA_CAIF_HSI_QLOW_WATERMARK,
  168. __IFLA_CAIF_HSI_MAX
  169. };
  170. extern struct cfhsi_ops *cfhsi_get_ops(void);
  171. #endif /* CAIF_HSI_H_ */