ldc.h 4.1 KB

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