caif_hsi.h 5.2 KB

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