client.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2003-2018, Intel Corporation. All rights reserved.
  4. * Intel Management Engine Interface (Intel MEI) Linux driver
  5. */
  6. #ifndef _MEI_CLIENT_H_
  7. #define _MEI_CLIENT_H_
  8. #include <linux/types.h>
  9. #include <linux/poll.h>
  10. #include <linux/mei.h>
  11. #include "mei_dev.h"
  12. /*
  13. * reference counting base function
  14. */
  15. void mei_me_cl_init(struct mei_me_client *me_cl);
  16. void mei_me_cl_put(struct mei_me_client *me_cl);
  17. struct mei_me_client *mei_me_cl_get(struct mei_me_client *me_cl);
  18. void mei_me_cl_add(struct mei_device *dev, struct mei_me_client *me_cl);
  19. void mei_me_cl_del(struct mei_device *dev, struct mei_me_client *me_cl);
  20. struct mei_me_client *mei_me_cl_by_uuid(struct mei_device *dev,
  21. const uuid_le *uuid);
  22. struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
  23. struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev,
  24. const uuid_le *uuid, u8 client_id);
  25. void mei_me_cl_rm_by_uuid(struct mei_device *dev, const uuid_le *uuid);
  26. void mei_me_cl_rm_all(struct mei_device *dev);
  27. /**
  28. * mei_me_cl_is_active - check whether me client is active in the fw
  29. *
  30. * @me_cl: me client
  31. *
  32. * Return: true if the me client is active in the firmware
  33. */
  34. static inline bool mei_me_cl_is_active(const struct mei_me_client *me_cl)
  35. {
  36. return !list_empty_careful(&me_cl->list);
  37. }
  38. /**
  39. * mei_me_cl_uuid - return me client protocol name (uuid)
  40. *
  41. * @me_cl: me client
  42. *
  43. * Return: me client protocol name
  44. */
  45. static inline const uuid_le *mei_me_cl_uuid(const struct mei_me_client *me_cl)
  46. {
  47. return &me_cl->props.protocol_name;
  48. }
  49. /**
  50. * mei_me_cl_ver - return me client protocol version
  51. *
  52. * @me_cl: me client
  53. *
  54. * Return: me client protocol version
  55. */
  56. static inline u8 mei_me_cl_ver(const struct mei_me_client *me_cl)
  57. {
  58. return me_cl->props.protocol_version;
  59. }
  60. /**
  61. * mei_me_cl_max_conn - return me client max number of connections
  62. *
  63. * @me_cl: me client
  64. *
  65. * Return: me client max number of connections
  66. */
  67. static inline u8 mei_me_cl_max_conn(const struct mei_me_client *me_cl)
  68. {
  69. return me_cl->props.max_number_of_connections;
  70. }
  71. /**
  72. * mei_me_cl_fixed - return me client fixed address, if any
  73. *
  74. * @me_cl: me client
  75. *
  76. * Return: me client fixed address
  77. */
  78. static inline u8 mei_me_cl_fixed(const struct mei_me_client *me_cl)
  79. {
  80. return me_cl->props.fixed_address;
  81. }
  82. /**
  83. * mei_me_cl_vt - return me client vtag supported status
  84. *
  85. * @me_cl: me client
  86. *
  87. * Return: true if me client supports vt tagging
  88. */
  89. static inline bool mei_me_cl_vt(const struct mei_me_client *me_cl)
  90. {
  91. return me_cl->props.vt_supported == 1;
  92. }
  93. /**
  94. * mei_me_cl_max_len - return me client max msg length
  95. *
  96. * @me_cl: me client
  97. *
  98. * Return: me client max msg length
  99. */
  100. static inline u32 mei_me_cl_max_len(const struct mei_me_client *me_cl)
  101. {
  102. return me_cl->props.max_msg_length;
  103. }
  104. /*
  105. * MEI IO Functions
  106. */
  107. void mei_io_cb_free(struct mei_cl_cb *priv_cb);
  108. /*
  109. * MEI Host Client Functions
  110. */
  111. struct mei_cl *mei_cl_allocate(struct mei_device *dev);
  112. int mei_cl_link(struct mei_cl *cl);
  113. int mei_cl_unlink(struct mei_cl *cl);
  114. struct mei_cl *mei_cl_alloc_linked(struct mei_device *dev);
  115. struct mei_cl_cb *mei_cl_read_cb(struct mei_cl *cl, const struct file *fp);
  116. void mei_cl_add_rd_completed(struct mei_cl *cl, struct mei_cl_cb *cb);
  117. void mei_cl_del_rd_completed(struct mei_cl *cl, struct mei_cl_cb *cb);
  118. struct mei_cl_cb *mei_cl_alloc_cb(struct mei_cl *cl, size_t length,
  119. enum mei_cb_file_ops type,
  120. const struct file *fp);
  121. struct mei_cl_cb *mei_cl_enqueue_ctrl_wr_cb(struct mei_cl *cl, size_t length,
  122. enum mei_cb_file_ops type,
  123. const struct file *fp);
  124. int mei_cl_flush_queues(struct mei_cl *cl, const struct file *fp);
  125. struct mei_cl_vtag *mei_cl_vtag_alloc(struct file *fp, u8 vtag);
  126. const struct file *mei_cl_fp_by_vtag(const struct mei_cl *cl, u8 vtag);
  127. int mei_cl_vt_support_check(const struct mei_cl *cl);
  128. /*
  129. * MEI input output function prototype
  130. */
  131. /**
  132. * mei_cl_is_connected - host client is connected
  133. *
  134. * @cl: host client
  135. *
  136. * Return: true if the host client is connected
  137. */
  138. static inline bool mei_cl_is_connected(const struct mei_cl *cl)
  139. {
  140. return cl->state == MEI_FILE_CONNECTED;
  141. }
  142. /**
  143. * mei_cl_me_id - me client id
  144. *
  145. * @cl: host client
  146. *
  147. * Return: me client id or 0 if client is not connected
  148. */
  149. static inline u8 mei_cl_me_id(const struct mei_cl *cl)
  150. {
  151. return cl->me_cl ? cl->me_cl->client_id : 0;
  152. }
  153. /**
  154. * mei_cl_mtu - maximal message that client can send and receive
  155. *
  156. * @cl: host client
  157. *
  158. * Return: mtu or 0 if client is not connected
  159. */
  160. static inline size_t mei_cl_mtu(const struct mei_cl *cl)
  161. {
  162. return cl->me_cl ? cl->me_cl->props.max_msg_length : 0;
  163. }
  164. /**
  165. * mei_cl_is_fixed_address - check whether the me client uses fixed address
  166. *
  167. * @cl: host client
  168. *
  169. * Return: true if the client is connected and it has fixed me address
  170. */
  171. static inline bool mei_cl_is_fixed_address(const struct mei_cl *cl)
  172. {
  173. return cl->me_cl && cl->me_cl->props.fixed_address;
  174. }
  175. /**
  176. * mei_cl_is_single_recv_buf- check whether the me client
  177. * uses single receiving buffer
  178. *
  179. * @cl: host client
  180. *
  181. * Return: true if single_recv_buf == 1; 0 otherwise
  182. */
  183. static inline bool mei_cl_is_single_recv_buf(const struct mei_cl *cl)
  184. {
  185. return cl->me_cl->props.single_recv_buf;
  186. }
  187. /**
  188. * mei_cl_uuid - client's uuid
  189. *
  190. * @cl: host client
  191. *
  192. * Return: return uuid of connected me client
  193. */
  194. static inline const uuid_le *mei_cl_uuid(const struct mei_cl *cl)
  195. {
  196. return mei_me_cl_uuid(cl->me_cl);
  197. }
  198. /**
  199. * mei_cl_host_addr - client's host address
  200. *
  201. * @cl: host client
  202. *
  203. * Return: 0 for fixed address client, host address for dynamic client
  204. */
  205. static inline u8 mei_cl_host_addr(const struct mei_cl *cl)
  206. {
  207. return mei_cl_is_fixed_address(cl) ? 0 : cl->host_client_id;
  208. }
  209. int mei_cl_disconnect(struct mei_cl *cl);
  210. int mei_cl_irq_disconnect(struct mei_cl *cl, struct mei_cl_cb *cb,
  211. struct list_head *cmpl_list);
  212. int mei_cl_connect(struct mei_cl *cl, struct mei_me_client *me_cl,
  213. const struct file *file);
  214. int mei_cl_irq_connect(struct mei_cl *cl, struct mei_cl_cb *cb,
  215. struct list_head *cmpl_list);
  216. int mei_cl_read_start(struct mei_cl *cl, size_t length, const struct file *fp);
  217. ssize_t mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb, unsigned long timeout);
  218. int mei_cl_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb,
  219. struct list_head *cmpl_list);
  220. void mei_cl_complete(struct mei_cl *cl, struct mei_cl_cb *cb);
  221. void mei_host_client_init(struct mei_device *dev);
  222. u8 mei_cl_notify_fop2req(enum mei_cb_file_ops fop);
  223. enum mei_cb_file_ops mei_cl_notify_req2fop(u8 request);
  224. int mei_cl_notify_request(struct mei_cl *cl,
  225. const struct file *file, u8 request);
  226. int mei_cl_irq_notify(struct mei_cl *cl, struct mei_cl_cb *cb,
  227. struct list_head *cmpl_list);
  228. int mei_cl_notify_get(struct mei_cl *cl, bool block, bool *notify_ev);
  229. void mei_cl_notify(struct mei_cl *cl);
  230. void mei_cl_all_disconnect(struct mei_device *dev);
  231. int mei_cl_irq_dma_map(struct mei_cl *cl, struct mei_cl_cb *cb,
  232. struct list_head *cmpl_list);
  233. int mei_cl_irq_dma_unmap(struct mei_cl *cl, struct mei_cl_cb *cb,
  234. struct list_head *cmpl_list);
  235. int mei_cl_dma_alloc_and_map(struct mei_cl *cl, const struct file *fp,
  236. u8 buffer_id, size_t size);
  237. int mei_cl_dma_unmap(struct mei_cl *cl, const struct file *fp);
  238. #define MEI_CL_FMT "cl:host=%02d me=%02d "
  239. #define MEI_CL_PRM(cl) (cl)->host_client_id, mei_cl_me_id(cl)
  240. #define cl_dbg(dev, cl, format, arg...) \
  241. dev_dbg(&(dev)->dev, MEI_CL_FMT format, MEI_CL_PRM(cl), ##arg)
  242. #define cl_warn(dev, cl, format, arg...) \
  243. dev_warn(&(dev)->dev, MEI_CL_FMT format, MEI_CL_PRM(cl), ##arg)
  244. #define cl_err(dev, cl, format, arg...) \
  245. dev_err(&(dev)->dev, MEI_CL_FMT format, MEI_CL_PRM(cl), ##arg)
  246. #endif /* _MEI_CLIENT_H_ */