ldc.h 4.4 KB

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