ldc.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef _SPARC64_LDC_H
  2. #define _SPARC64_LDC_H
  3. #include <asm/hypervisor.h>
  4. extern int ldom_domaining_enabled;
  5. /* The event handler will be evoked when link state changes
  6. * or data becomes available on the receive side.
  7. *
  8. * For non-RAW links, if the LDC_EVENT_RESET event arrives the
  9. * driver should reset all of it's internal state and reinvoke
  10. * ldc_connect() to try and bring the link up again.
  11. *
  12. * For RAW links, ldc_connect() is not used. Instead the driver
  13. * just waits for the LDC_EVENT_UP event.
  14. */
  15. struct ldc_channel_config {
  16. void (*event)(void *arg, int event);
  17. u32 mtu;
  18. unsigned int rx_irq;
  19. unsigned int tx_irq;
  20. u8 mode;
  21. #define LDC_MODE_RAW 0x00
  22. #define LDC_MODE_UNRELIABLE 0x01
  23. #define LDC_MODE_RESERVED 0x02
  24. #define LDC_MODE_STREAM 0x03
  25. u8 debug;
  26. #define LDC_DEBUG_HS 0x01
  27. #define LDC_DEBUG_STATE 0x02
  28. #define LDC_DEBUG_RX 0x04
  29. #define LDC_DEBUG_TX 0x08
  30. #define LDC_DEBUG_DATA 0x10
  31. };
  32. #define LDC_EVENT_RESET 0x01
  33. #define LDC_EVENT_UP 0x02
  34. #define LDC_EVENT_DATA_READY 0x04
  35. #define LDC_STATE_INVALID 0x00
  36. #define LDC_STATE_INIT 0x01
  37. #define LDC_STATE_BOUND 0x02
  38. #define LDC_STATE_READY 0x03
  39. #define LDC_STATE_CONNECTED 0x04
  40. struct ldc_channel;
  41. /* Allocate state for a channel. */
  42. extern struct ldc_channel *ldc_alloc(unsigned long id,
  43. const struct ldc_channel_config *cfgp,
  44. void *event_arg);
  45. /* Shut down and free state for a channel. */
  46. extern void ldc_free(struct ldc_channel *lp);
  47. /* Register TX and RX queues of the link with the hypervisor. */
  48. extern int ldc_bind(struct ldc_channel *lp, const char *name);
  49. /* For non-RAW protocols we need to complete a handshake before
  50. * communication can proceed. ldc_connect() does that, if the
  51. * handshake completes successfully, an LDC_EVENT_UP event will
  52. * be sent up to the driver.
  53. */
  54. extern int ldc_connect(struct ldc_channel *lp);
  55. extern int ldc_disconnect(struct ldc_channel *lp);
  56. extern int ldc_state(struct ldc_channel *lp);
  57. /* Read and write operations. Only valid when the link is up. */
  58. extern int ldc_write(struct ldc_channel *lp, const void *buf,
  59. unsigned int size);
  60. extern int ldc_read(struct ldc_channel *lp, void *buf, unsigned int size);
  61. #define LDC_MAP_SHADOW 0x01
  62. #define LDC_MAP_DIRECT 0x02
  63. #define LDC_MAP_IO 0x04
  64. #define LDC_MAP_R 0x08
  65. #define LDC_MAP_W 0x10
  66. #define LDC_MAP_X 0x20
  67. #define LDC_MAP_RW (LDC_MAP_R | LDC_MAP_W)
  68. #define LDC_MAP_RWX (LDC_MAP_R | LDC_MAP_W | LDC_MAP_X)
  69. #define LDC_MAP_ALL 0x03f
  70. struct ldc_trans_cookie {
  71. u64 cookie_addr;
  72. u64 cookie_size;
  73. };
  74. struct scatterlist;
  75. extern int ldc_map_sg(struct ldc_channel *lp,
  76. struct scatterlist *sg, int num_sg,
  77. struct ldc_trans_cookie *cookies, int ncookies,
  78. unsigned int map_perm);
  79. extern int ldc_map_single(struct ldc_channel *lp,
  80. void *buf, unsigned int len,
  81. struct ldc_trans_cookie *cookies, int ncookies,
  82. unsigned int map_perm);
  83. extern void ldc_unmap(struct ldc_channel *lp, struct ldc_trans_cookie *cookies,
  84. int ncookies);
  85. extern int ldc_copy(struct ldc_channel *lp, int copy_dir,
  86. void *buf, unsigned int len, unsigned long offset,
  87. struct ldc_trans_cookie *cookies, int ncookies);
  88. static inline int ldc_get_dring_entry(struct ldc_channel *lp,
  89. void *buf, unsigned int len,
  90. unsigned long offset,
  91. struct ldc_trans_cookie *cookies,
  92. int ncookies)
  93. {
  94. return ldc_copy(lp, LDC_COPY_IN, buf, len, offset, cookies, ncookies);
  95. }
  96. static inline int ldc_put_dring_entry(struct ldc_channel *lp,
  97. void *buf, unsigned int len,
  98. unsigned long offset,
  99. struct ldc_trans_cookie *cookies,
  100. int ncookies)
  101. {
  102. return ldc_copy(lp, LDC_COPY_OUT, buf, len, offset, cookies, ncookies);
  103. }
  104. extern void *ldc_alloc_exp_dring(struct ldc_channel *lp, unsigned int len,
  105. struct ldc_trans_cookie *cookies,
  106. int *ncookies, unsigned int map_perm);
  107. extern void ldc_free_exp_dring(struct ldc_channel *lp, void *buf,
  108. unsigned int len,
  109. struct ldc_trans_cookie *cookies, int ncookies);
  110. #endif /* _SPARC64_LDC_H */