client.h 7.7 KB

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