Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (c) 2003-2018, Intel Corporation. All rights reserved.
0004  * Intel Management Engine Interface (Intel MEI) Linux driver
0005  */
0006 
0007 #ifndef _MEI_CLIENT_H_
0008 #define _MEI_CLIENT_H_
0009 
0010 #include <linux/types.h>
0011 #include <linux/poll.h>
0012 #include <linux/mei.h>
0013 
0014 #include "mei_dev.h"
0015 
0016 /*
0017  * reference counting base function
0018  */
0019 void mei_me_cl_init(struct mei_me_client *me_cl);
0020 void mei_me_cl_put(struct mei_me_client *me_cl);
0021 struct mei_me_client *mei_me_cl_get(struct mei_me_client *me_cl);
0022 
0023 void mei_me_cl_add(struct mei_device *dev, struct mei_me_client *me_cl);
0024 void mei_me_cl_del(struct mei_device *dev, struct mei_me_client *me_cl);
0025 
0026 struct mei_me_client *mei_me_cl_by_uuid(struct mei_device *dev,
0027                     const uuid_le *uuid);
0028 struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
0029 struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev,
0030                        const uuid_le *uuid, u8 client_id);
0031 void mei_me_cl_rm_by_uuid(struct mei_device *dev, const uuid_le *uuid);
0032 void mei_me_cl_rm_by_uuid_id(struct mei_device *dev,
0033                  const uuid_le *uuid, u8 id);
0034 void mei_me_cl_rm_all(struct mei_device *dev);
0035 
0036 /**
0037  * mei_me_cl_is_active - check whether me client is active in the fw
0038  *
0039  * @me_cl: me client
0040  *
0041  * Return: true if the me client is active in the firmware
0042  */
0043 static inline bool mei_me_cl_is_active(const struct mei_me_client *me_cl)
0044 {
0045     return !list_empty_careful(&me_cl->list);
0046 }
0047 
0048 /**
0049  * mei_me_cl_uuid - return me client protocol name (uuid)
0050  *
0051  * @me_cl: me client
0052  *
0053  * Return: me client protocol name
0054  */
0055 static inline const uuid_le *mei_me_cl_uuid(const struct mei_me_client *me_cl)
0056 {
0057     return &me_cl->props.protocol_name;
0058 }
0059 
0060 /**
0061  * mei_me_cl_ver - return me client protocol version
0062  *
0063  * @me_cl: me client
0064  *
0065  * Return: me client protocol version
0066  */
0067 static inline u8 mei_me_cl_ver(const struct mei_me_client *me_cl)
0068 {
0069     return me_cl->props.protocol_version;
0070 }
0071 
0072 /**
0073  * mei_me_cl_max_conn - return me client max number of connections
0074  *
0075  * @me_cl: me client
0076  *
0077  * Return: me client max number of connections
0078  */
0079 static inline u8 mei_me_cl_max_conn(const struct mei_me_client *me_cl)
0080 {
0081     return me_cl->props.max_number_of_connections;
0082 }
0083 
0084 /**
0085  * mei_me_cl_fixed - return me client fixed address, if any
0086  *
0087  * @me_cl: me client
0088  *
0089  * Return: me client fixed address
0090  */
0091 static inline u8 mei_me_cl_fixed(const struct mei_me_client *me_cl)
0092 {
0093     return me_cl->props.fixed_address;
0094 }
0095 
0096 /**
0097  * mei_me_cl_vt - return me client vtag supported status
0098  *
0099  * @me_cl: me client
0100  *
0101  * Return: true if me client supports vt tagging
0102  */
0103 static inline bool mei_me_cl_vt(const struct mei_me_client *me_cl)
0104 {
0105     return me_cl->props.vt_supported == 1;
0106 }
0107 
0108 /**
0109  * mei_me_cl_max_len - return me client max msg length
0110  *
0111  * @me_cl: me client
0112  *
0113  * Return: me client max msg length
0114  */
0115 static inline u32 mei_me_cl_max_len(const struct mei_me_client *me_cl)
0116 {
0117     return me_cl->props.max_msg_length;
0118 }
0119 
0120 /*
0121  * MEI IO Functions
0122  */
0123 void mei_io_cb_free(struct mei_cl_cb *priv_cb);
0124 
0125 /*
0126  * MEI Host Client Functions
0127  */
0128 
0129 struct mei_cl *mei_cl_allocate(struct mei_device *dev);
0130 
0131 int mei_cl_link(struct mei_cl *cl);
0132 int mei_cl_unlink(struct mei_cl *cl);
0133 
0134 struct mei_cl *mei_cl_alloc_linked(struct mei_device *dev);
0135 
0136 struct mei_cl_cb *mei_cl_read_cb(struct mei_cl *cl, const struct file *fp);
0137 
0138 void mei_cl_add_rd_completed(struct mei_cl *cl, struct mei_cl_cb *cb);
0139 void mei_cl_del_rd_completed(struct mei_cl *cl, struct mei_cl_cb *cb);
0140 
0141 struct mei_cl_cb *mei_cl_alloc_cb(struct mei_cl *cl, size_t length,
0142                   enum mei_cb_file_ops type,
0143                   const struct file *fp);
0144 struct mei_cl_cb *mei_cl_enqueue_ctrl_wr_cb(struct mei_cl *cl, size_t length,
0145                         enum mei_cb_file_ops type,
0146                         const struct file *fp);
0147 int mei_cl_flush_queues(struct mei_cl *cl, const struct file *fp);
0148 
0149 struct mei_cl_vtag *mei_cl_vtag_alloc(struct file *fp, u8 vtag);
0150 const struct file *mei_cl_fp_by_vtag(const struct mei_cl *cl, u8 vtag);
0151 int mei_cl_vt_support_check(const struct mei_cl *cl);
0152 /*
0153  *  MEI input output function prototype
0154  */
0155 
0156 /**
0157  * mei_cl_is_connected - host client is connected
0158  *
0159  * @cl: host client
0160  *
0161  * Return: true if the host client is connected
0162  */
0163 static inline bool mei_cl_is_connected(const struct mei_cl *cl)
0164 {
0165     return  cl->state == MEI_FILE_CONNECTED;
0166 }
0167 
0168 /**
0169  * mei_cl_me_id - me client id
0170  *
0171  * @cl: host client
0172  *
0173  * Return: me client id or 0 if client is not connected
0174  */
0175 static inline u8 mei_cl_me_id(const struct mei_cl *cl)
0176 {
0177     return cl->me_cl ? cl->me_cl->client_id : 0;
0178 }
0179 
0180 /**
0181  * mei_cl_mtu - maximal message that client can send and receive
0182  *
0183  * @cl: host client
0184  *
0185  * Return: mtu or 0 if client is not connected
0186  */
0187 static inline size_t mei_cl_mtu(const struct mei_cl *cl)
0188 {
0189     return cl->me_cl ? cl->me_cl->props.max_msg_length : 0;
0190 }
0191 
0192 /**
0193  * mei_cl_is_fixed_address - check whether the me client uses fixed address
0194  *
0195  * @cl: host client
0196  *
0197  * Return: true if the client is connected and it has fixed me address
0198  */
0199 static inline bool mei_cl_is_fixed_address(const struct mei_cl *cl)
0200 {
0201     return cl->me_cl && cl->me_cl->props.fixed_address;
0202 }
0203 
0204 /**
0205  * mei_cl_is_single_recv_buf- check whether the me client
0206  *       uses single receiving buffer
0207  *
0208  * @cl: host client
0209  *
0210  * Return: true if single_recv_buf == 1; 0 otherwise
0211  */
0212 static inline bool mei_cl_is_single_recv_buf(const struct mei_cl *cl)
0213 {
0214     return cl->me_cl->props.single_recv_buf;
0215 }
0216 
0217 /**
0218  * mei_cl_uuid -  client's uuid
0219  *
0220  * @cl: host client
0221  *
0222  * Return: return uuid of connected me client
0223  */
0224 static inline const uuid_le *mei_cl_uuid(const struct mei_cl *cl)
0225 {
0226     return mei_me_cl_uuid(cl->me_cl);
0227 }
0228 
0229 /**
0230  * mei_cl_host_addr - client's host address
0231  *
0232  * @cl: host client
0233  *
0234  * Return: 0 for fixed address client, host address for dynamic client
0235  */
0236 static inline u8 mei_cl_host_addr(const struct mei_cl *cl)
0237 {
0238     return  mei_cl_is_fixed_address(cl) ? 0 : cl->host_client_id;
0239 }
0240 
0241 int mei_cl_disconnect(struct mei_cl *cl);
0242 int mei_cl_irq_disconnect(struct mei_cl *cl, struct mei_cl_cb *cb,
0243               struct list_head *cmpl_list);
0244 int mei_cl_connect(struct mei_cl *cl, struct mei_me_client *me_cl,
0245            const struct file *file);
0246 int mei_cl_irq_connect(struct mei_cl *cl, struct mei_cl_cb *cb,
0247                struct list_head *cmpl_list);
0248 int mei_cl_read_start(struct mei_cl *cl, size_t length, const struct file *fp);
0249 ssize_t mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb);
0250 int mei_cl_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb,
0251              struct list_head *cmpl_list);
0252 
0253 void mei_cl_complete(struct mei_cl *cl, struct mei_cl_cb *cb);
0254 
0255 void mei_host_client_init(struct mei_device *dev);
0256 
0257 u8 mei_cl_notify_fop2req(enum mei_cb_file_ops fop);
0258 enum mei_cb_file_ops mei_cl_notify_req2fop(u8 request);
0259 int mei_cl_notify_request(struct mei_cl *cl,
0260               const struct file *file, u8 request);
0261 int mei_cl_irq_notify(struct mei_cl *cl, struct mei_cl_cb *cb,
0262               struct list_head *cmpl_list);
0263 int mei_cl_notify_get(struct mei_cl *cl, bool block, bool *notify_ev);
0264 void mei_cl_notify(struct mei_cl *cl);
0265 
0266 void mei_cl_all_disconnect(struct mei_device *dev);
0267 
0268 int mei_cl_irq_dma_map(struct mei_cl *cl, struct mei_cl_cb *cb,
0269                struct list_head *cmpl_list);
0270 int mei_cl_irq_dma_unmap(struct mei_cl *cl, struct mei_cl_cb *cb,
0271              struct list_head *cmpl_list);
0272 int mei_cl_dma_alloc_and_map(struct mei_cl *cl, const struct file *fp,
0273                  u8 buffer_id, size_t size);
0274 int mei_cl_dma_unmap(struct mei_cl *cl, const struct file *fp);
0275 
0276 #define MEI_CL_FMT "cl:host=%02d me=%02d "
0277 #define MEI_CL_PRM(cl) (cl)->host_client_id, mei_cl_me_id(cl)
0278 
0279 #define cl_dbg(dev, cl, format, arg...) \
0280     dev_dbg((dev)->dev, MEI_CL_FMT format, MEI_CL_PRM(cl), ##arg)
0281 
0282 #define cl_warn(dev, cl, format, arg...) \
0283     dev_warn((dev)->dev, MEI_CL_FMT format, MEI_CL_PRM(cl), ##arg)
0284 
0285 #define cl_err(dev, cl, format, arg...) \
0286     dev_err((dev)->dev, MEI_CL_FMT format, MEI_CL_PRM(cl), ##arg)
0287 
0288 #endif /* _MEI_CLIENT_H_ */