caif_hsi.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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_drv {
  77. void (*tx_done_cb) (struct cfhsi_drv *drv);
  78. void (*rx_done_cb) (struct cfhsi_drv *drv);
  79. void (*wake_up_cb) (struct cfhsi_drv *drv);
  80. void (*wake_down_cb) (struct cfhsi_drv *drv);
  81. };
  82. /* Structure implemented by HSI device. */
  83. struct cfhsi_dev {
  84. int (*cfhsi_up) (struct cfhsi_dev *dev);
  85. int (*cfhsi_down) (struct cfhsi_dev *dev);
  86. int (*cfhsi_tx) (u8 *ptr, int len, struct cfhsi_dev *dev);
  87. int (*cfhsi_rx) (u8 *ptr, int len, struct cfhsi_dev *dev);
  88. int (*cfhsi_wake_up) (struct cfhsi_dev *dev);
  89. int (*cfhsi_wake_down) (struct cfhsi_dev *dev);
  90. int (*cfhsi_get_peer_wake) (struct cfhsi_dev *dev, bool *status);
  91. int (*cfhsi_fifo_occupancy)(struct cfhsi_dev *dev, size_t *occupancy);
  92. int (*cfhsi_rx_cancel)(struct cfhsi_dev *dev);
  93. struct cfhsi_drv *drv;
  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. /* Structure implemented by CAIF HSI drivers. */
  104. struct cfhsi {
  105. struct caif_dev_common cfdev;
  106. struct net_device *ndev;
  107. struct platform_device *pdev;
  108. struct sk_buff_head qhead;
  109. struct cfhsi_drv drv;
  110. struct cfhsi_dev *dev;
  111. int tx_state;
  112. struct cfhsi_rx_state rx_state;
  113. unsigned long inactivity_timeout;
  114. int rx_len;
  115. u8 *rx_ptr;
  116. u8 *tx_buf;
  117. u8 *rx_buf;
  118. u8 *rx_flip_buf;
  119. spinlock_t lock;
  120. int flow_off_sent;
  121. u32 q_low_mark;
  122. u32 q_high_mark;
  123. struct list_head list;
  124. struct work_struct wake_up_work;
  125. struct work_struct wake_down_work;
  126. struct work_struct out_of_sync_work;
  127. struct workqueue_struct *wq;
  128. wait_queue_head_t wake_up_wait;
  129. wait_queue_head_t wake_down_wait;
  130. wait_queue_head_t flush_fifo_wait;
  131. struct timer_list timer;
  132. struct timer_list rx_slowpath_timer;
  133. unsigned long bits;
  134. };
  135. extern struct platform_driver cfhsi_driver;
  136. #endif /* CAIF_HSI_H_ */