caif_hsi.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. /* TODO: 4096 is temporary... */
  47. #define CFHSI_MAX_PAYLOAD_SZ (CFHSI_MAX_PKTS * 4096)
  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_PENDING_RX 4
  64. #define CFHSI_SHUTDOWN 6
  65. #define CFHSI_FLUSH_FIFO 7
  66. #ifndef CFHSI_INACTIVITY_TOUT
  67. #define CFHSI_INACTIVITY_TOUT (1 * HZ)
  68. #endif /* CFHSI_INACTIVITY_TOUT */
  69. #ifndef CFHSI_WAKEUP_TOUT
  70. #define CFHSI_WAKEUP_TOUT (3 * HZ)
  71. #endif /* CFHSI_WAKEUP_TOUT */
  72. /* Structure implemented by the CAIF HSI driver. */
  73. struct cfhsi_drv {
  74. void (*tx_done_cb) (struct cfhsi_drv *drv);
  75. void (*rx_done_cb) (struct cfhsi_drv *drv);
  76. void (*wake_up_cb) (struct cfhsi_drv *drv);
  77. void (*wake_down_cb) (struct cfhsi_drv *drv);
  78. };
  79. /* Structure implemented by HSI device. */
  80. struct cfhsi_dev {
  81. int (*cfhsi_up) (struct cfhsi_dev *dev);
  82. int (*cfhsi_down) (struct cfhsi_dev *dev);
  83. int (*cfhsi_tx) (u8 *ptr, int len, struct cfhsi_dev *dev);
  84. int (*cfhsi_rx) (u8 *ptr, int len, struct cfhsi_dev *dev);
  85. int (*cfhsi_wake_up) (struct cfhsi_dev *dev);
  86. int (*cfhsi_wake_down) (struct cfhsi_dev *dev);
  87. int (*cfhsi_fifo_occupancy)(struct cfhsi_dev *dev, size_t *occupancy);
  88. int (*cfhsi_rx_cancel)(struct cfhsi_dev *dev);
  89. struct cfhsi_drv *drv;
  90. };
  91. /* Structure implemented by CAIF HSI drivers. */
  92. struct cfhsi {
  93. struct caif_dev_common cfdev;
  94. struct net_device *ndev;
  95. struct platform_device *pdev;
  96. struct sk_buff_head qhead;
  97. struct cfhsi_drv drv;
  98. struct cfhsi_dev *dev;
  99. int tx_state;
  100. int rx_state;
  101. int rx_len;
  102. u8 *rx_ptr;
  103. u8 *tx_buf;
  104. u8 *rx_buf;
  105. spinlock_t lock;
  106. int flow_off_sent;
  107. u32 q_low_mark;
  108. u32 q_high_mark;
  109. struct list_head list;
  110. struct work_struct wake_up_work;
  111. struct work_struct wake_down_work;
  112. struct work_struct rx_done_work;
  113. struct work_struct tx_done_work;
  114. struct workqueue_struct *wq;
  115. wait_queue_head_t wake_up_wait;
  116. wait_queue_head_t wake_down_wait;
  117. wait_queue_head_t flush_fifo_wait;
  118. struct timer_list timer;
  119. unsigned long bits;
  120. };
  121. extern struct platform_driver cfhsi_driver;
  122. #endif /* CAIF_HSI_H_ */