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