xref: /openbmc/linux/drivers/misc/mei/client.h (revision 331e4187)
190e0b5f1STomas Winkler /*
290e0b5f1STomas Winkler  *
390e0b5f1STomas Winkler  * Intel Management Engine Interface (Intel MEI) Linux driver
490e0b5f1STomas Winkler  * Copyright (c) 2003-2012, Intel Corporation.
590e0b5f1STomas Winkler  *
690e0b5f1STomas Winkler  * This program is free software; you can redistribute it and/or modify it
790e0b5f1STomas Winkler  * under the terms and conditions of the GNU General Public License,
890e0b5f1STomas Winkler  * version 2, as published by the Free Software Foundation.
990e0b5f1STomas Winkler  *
1090e0b5f1STomas Winkler  * This program is distributed in the hope it will be useful, but WITHOUT
1190e0b5f1STomas Winkler  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1290e0b5f1STomas Winkler  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
1390e0b5f1STomas Winkler  * more details.
1490e0b5f1STomas Winkler  *
1590e0b5f1STomas Winkler  */
1690e0b5f1STomas Winkler 
1790e0b5f1STomas Winkler #ifndef _MEI_CLIENT_H_
1890e0b5f1STomas Winkler #define _MEI_CLIENT_H_
1990e0b5f1STomas Winkler 
2090e0b5f1STomas Winkler #include <linux/types.h>
2190e0b5f1STomas Winkler #include <linux/watchdog.h>
2290e0b5f1STomas Winkler #include <linux/poll.h>
2390e0b5f1STomas Winkler #include <linux/mei.h>
2490e0b5f1STomas Winkler 
2590e0b5f1STomas Winkler #include "mei_dev.h"
2690e0b5f1STomas Winkler 
2779563db9STomas Winkler /*
2879563db9STomas Winkler  * reference counting base function
2979563db9STomas Winkler  */
3079563db9STomas Winkler void mei_me_cl_init(struct mei_me_client *me_cl);
3179563db9STomas Winkler void mei_me_cl_put(struct mei_me_client *me_cl);
3279563db9STomas Winkler struct mei_me_client *mei_me_cl_get(struct mei_me_client *me_cl);
33d880f329STomas Winkler 
34b7d88514STomas Winkler void mei_me_cl_add(struct mei_device *dev, struct mei_me_client *me_cl);
35b7d88514STomas Winkler void mei_me_cl_del(struct mei_device *dev, struct mei_me_client *me_cl);
36b7d88514STomas Winkler 
37b7d88514STomas Winkler struct mei_me_client *mei_me_cl_by_uuid(struct mei_device *dev,
3879563db9STomas Winkler 					const uuid_le *uuid);
3979563db9STomas Winkler struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
40d880f329STomas Winkler struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev,
41d880f329STomas Winkler 					   const uuid_le *uuid, u8 client_id);
4279563db9STomas Winkler void mei_me_cl_rm_by_uuid(struct mei_device *dev, const uuid_le *uuid);
4379563db9STomas Winkler void mei_me_cl_rm_by_uuid_id(struct mei_device *dev,
4479563db9STomas Winkler 			     const uuid_le *uuid, u8 id);
4579563db9STomas Winkler void mei_me_cl_rm_all(struct mei_device *dev);
4690e0b5f1STomas Winkler 
4790e0b5f1STomas Winkler /*
4890e0b5f1STomas Winkler  * MEI IO Functions
4990e0b5f1STomas Winkler  */
5090e0b5f1STomas Winkler struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp);
5190e0b5f1STomas Winkler void mei_io_cb_free(struct mei_cl_cb *priv_cb);
5290e0b5f1STomas Winkler int mei_io_cb_alloc_req_buf(struct mei_cl_cb *cb, size_t length);
5390e0b5f1STomas Winkler int mei_io_cb_alloc_resp_buf(struct mei_cl_cb *cb, size_t length);
5490e0b5f1STomas Winkler 
5590e0b5f1STomas Winkler 
5690e0b5f1STomas Winkler /**
5790e0b5f1STomas Winkler  * mei_io_list_init - Sets up a queue list.
5890e0b5f1STomas Winkler  *
5990e0b5f1STomas Winkler  * @list: An instance cl callback structure
6090e0b5f1STomas Winkler  */
6190e0b5f1STomas Winkler static inline void mei_io_list_init(struct mei_cl_cb *list)
6290e0b5f1STomas Winkler {
6390e0b5f1STomas Winkler 	INIT_LIST_HEAD(&list->list);
6490e0b5f1STomas Winkler }
655456796bSAlexander Usyskin void mei_io_list_flush(struct mei_cl_cb *list, struct mei_cl *cl);
665456796bSAlexander Usyskin 
6790e0b5f1STomas Winkler /*
6890e0b5f1STomas Winkler  * MEI Host Client Functions
6990e0b5f1STomas Winkler  */
7090e0b5f1STomas Winkler 
7190e0b5f1STomas Winkler struct mei_cl *mei_cl_allocate(struct mei_device *dev);
7290e0b5f1STomas Winkler void mei_cl_init(struct mei_cl *cl, struct mei_device *dev);
7390e0b5f1STomas Winkler 
7490e0b5f1STomas Winkler 
75781d0d89STomas Winkler int mei_cl_link(struct mei_cl *cl, int id);
7690e0b5f1STomas Winkler int mei_cl_unlink(struct mei_cl *cl);
7790e0b5f1STomas Winkler 
7890e0b5f1STomas Winkler int mei_cl_flush_queues(struct mei_cl *cl);
7990e0b5f1STomas Winkler struct mei_cl_cb *mei_cl_find_read_cb(struct mei_cl *cl);
8090e0b5f1STomas Winkler 
8190e0b5f1STomas Winkler 
8290e0b5f1STomas Winkler int mei_cl_flow_ctrl_creds(struct mei_cl *cl);
8390e0b5f1STomas Winkler 
8490e0b5f1STomas Winkler int mei_cl_flow_ctrl_reduce(struct mei_cl *cl);
8590e0b5f1STomas Winkler /*
8690e0b5f1STomas Winkler  *  MEI input output function prototype
8790e0b5f1STomas Winkler  */
88b950ac1dSTomas Winkler static inline bool mei_cl_is_connected(struct mei_cl *cl)
89b950ac1dSTomas Winkler {
901adc1674STomas Winkler 	return  cl->dev &&
91b950ac1dSTomas Winkler 		cl->dev->dev_state == MEI_DEV_ENABLED &&
921adc1674STomas Winkler 		cl->state == MEI_FILE_CONNECTED;
93b950ac1dSTomas Winkler }
94e2b31644STomas Winkler static inline bool mei_cl_is_transitioning(struct mei_cl *cl)
95e2b31644STomas Winkler {
961adc1674STomas Winkler 	return  MEI_FILE_INITIALIZING == cl->state ||
97e2b31644STomas Winkler 		MEI_FILE_DISCONNECTED == cl->state ||
981adc1674STomas Winkler 		MEI_FILE_DISCONNECTING == cl->state;
99e2b31644STomas Winkler }
100b950ac1dSTomas Winkler 
10190e0b5f1STomas Winkler bool mei_cl_is_other_connecting(struct mei_cl *cl);
10290e0b5f1STomas Winkler int mei_cl_disconnect(struct mei_cl *cl);
10390e0b5f1STomas Winkler int mei_cl_connect(struct mei_cl *cl, struct file *file);
104fcb136e1STomas Winkler int mei_cl_read_start(struct mei_cl *cl, size_t length);
105331e4187STomas Winkler int mei_cl_irq_read_msg(struct mei_cl *cl, struct mei_msg_hdr *hdr,
106331e4187STomas Winkler 			struct mei_cl_cb *cmpl_list);
1074234a6deSTomas Winkler int mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb, bool blocking);
1089d098192STomas Winkler int mei_cl_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb,
1099d098192STomas Winkler 		     struct mei_cl_cb *cmpl_list);
11021767546STomas Winkler 
111db086fa9STomas Winkler void mei_cl_complete(struct mei_cl *cl, struct mei_cl_cb *cb);
11290e0b5f1STomas Winkler 
11390e0b5f1STomas Winkler void mei_host_client_init(struct work_struct *work);
11490e0b5f1STomas Winkler 
11590e0b5f1STomas Winkler 
1164234a6deSTomas Winkler 
117074b4c01STomas Winkler void mei_cl_all_disconnect(struct mei_device *dev);
1185290801cSTomas Winkler void mei_cl_all_wakeup(struct mei_device *dev);
119074b4c01STomas Winkler void mei_cl_all_write_clear(struct mei_device *dev);
120074b4c01STomas Winkler 
121c0abffbdSAlexander Usyskin #define MEI_CL_FMT "cl:host=%02d me=%02d "
122c0abffbdSAlexander Usyskin #define MEI_CL_PRM(cl) (cl)->host_client_id, (cl)->me_client_id
123c0abffbdSAlexander Usyskin 
124c0abffbdSAlexander Usyskin #define cl_dbg(dev, cl, format, arg...) \
1252bf94cabSTomas Winkler 	dev_dbg((dev)->dev, MEI_CL_FMT format, MEI_CL_PRM(cl), ##arg)
126c0abffbdSAlexander Usyskin 
127c0abffbdSAlexander Usyskin #define cl_err(dev, cl, format, arg...) \
1282bf94cabSTomas Winkler 	dev_err((dev)->dev, MEI_CL_FMT format, MEI_CL_PRM(cl), ##arg)
129c0abffbdSAlexander Usyskin 
13090e0b5f1STomas Winkler #endif /* _MEI_CLIENT_H_ */
131