Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Intel Management Engine Interface (Intel MEI) Linux driver |
Tomas Winkler | 733ba91 | 2012-02-09 19:25:53 +0200 | [diff] [blame] | 4 | * Copyright (c) 2003-2012, Intel Corporation. |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #ifndef _MEI_DEV_H_ |
| 18 | #define _MEI_DEV_H_ |
| 19 | |
| 20 | #include <linux/types.h> |
Oren Weil | 9ce178e | 2011-09-07 09:03:09 +0300 | [diff] [blame] | 21 | #include <linux/watchdog.h> |
Tomas Winkler | 4f3afe1 | 2012-05-09 16:38:59 +0300 | [diff] [blame] | 22 | #include <linux/mei.h> |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 23 | #include "hw.h" |
| 24 | |
| 25 | /* |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 26 | * watch dog definition |
| 27 | */ |
Tomas Winkler | 248ffdf | 2012-08-16 19:39:42 +0300 | [diff] [blame] | 28 | #define MEI_WD_HDR_SIZE 4 |
| 29 | #define MEI_WD_STOP_MSG_SIZE MEI_WD_HDR_SIZE |
| 30 | #define MEI_WD_START_MSG_SIZE (MEI_WD_HDR_SIZE + 16) |
| 31 | |
| 32 | #define MEI_WD_DEFAULT_TIMEOUT 120 /* seconds */ |
| 33 | #define MEI_WD_MIN_TIMEOUT 120 /* seconds */ |
| 34 | #define MEI_WD_MAX_TIMEOUT 65535 /* seconds */ |
| 35 | |
Tomas Winkler | c216fde | 2012-08-16 19:39:43 +0300 | [diff] [blame] | 36 | #define MEI_WD_STOP_TIMEOUT 10 /* msecs */ |
| 37 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 38 | #define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0) |
| 39 | |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 40 | #define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32)) |
| 41 | |
Oren Weil | 9ce178e | 2011-09-07 09:03:09 +0300 | [diff] [blame] | 42 | |
| 43 | /* |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 44 | * AMTHI Client UUID |
| 45 | */ |
| 46 | extern const uuid_le mei_amthi_guid; |
| 47 | |
| 48 | /* |
| 49 | * Watchdog Client UUID |
| 50 | */ |
| 51 | extern const uuid_le mei_wd_guid; |
| 52 | |
| 53 | /* |
| 54 | * Watchdog independence state message |
| 55 | */ |
| 56 | extern const u8 mei_wd_state_independence_msg[3][4]; |
| 57 | |
| 58 | /* |
Tomas Winkler | 1e2776c | 2012-08-24 00:35:58 +0300 | [diff] [blame] | 59 | * Number of Maximum MEI Clients |
| 60 | */ |
| 61 | #define MEI_CLIENTS_MAX 256 |
| 62 | |
| 63 | /* |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 64 | * Number of File descriptors/handles |
| 65 | * that can be opened to the driver. |
| 66 | * |
Tomas Winkler | 1e2776c | 2012-08-24 00:35:58 +0300 | [diff] [blame] | 67 | * Limit to 253: 256 Total Clients |
| 68 | * minus internal client for MEI Bus Messags |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 69 | * minus internal client for AMTHI |
| 70 | * minus internal client for Watchdog |
| 71 | */ |
Tomas Winkler | 1e2776c | 2012-08-24 00:35:58 +0300 | [diff] [blame] | 72 | #define MEI_MAX_OPEN_HANDLE_COUNT (MEI_CLIENTS_MAX - 3) |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 73 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 74 | |
| 75 | /* File state */ |
| 76 | enum file_state { |
| 77 | MEI_FILE_INITIALIZING = 0, |
| 78 | MEI_FILE_CONNECTING, |
| 79 | MEI_FILE_CONNECTED, |
| 80 | MEI_FILE_DISCONNECTING, |
| 81 | MEI_FILE_DISCONNECTED |
| 82 | }; |
| 83 | |
| 84 | /* MEI device states */ |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 85 | enum mei_dev_state { |
| 86 | MEI_DEV_INITIALIZING = 0, |
| 87 | MEI_DEV_INIT_CLIENTS, |
| 88 | MEI_DEV_ENABLED, |
| 89 | MEI_DEV_RESETING, |
| 90 | MEI_DEV_DISABLED, |
| 91 | MEI_DEV_RECOVERING_FROM_RESET, |
| 92 | MEI_DEV_POWER_DOWN, |
| 93 | MEI_DEV_POWER_UP |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 94 | }; |
| 95 | |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 96 | const char *mei_dev_state_str(int state); |
| 97 | |
Justin P. Mattock | 5f9092f3 | 2012-03-12 07:18:09 -0700 | [diff] [blame] | 98 | /* init clients states*/ |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 99 | enum mei_init_clients_states { |
| 100 | MEI_START_MESSAGE = 0, |
| 101 | MEI_ENUM_CLIENTS_MESSAGE, |
| 102 | MEI_CLIENT_PROPERTIES_MESSAGE |
| 103 | }; |
| 104 | |
| 105 | enum iamthif_states { |
| 106 | MEI_IAMTHIF_IDLE, |
| 107 | MEI_IAMTHIF_WRITING, |
| 108 | MEI_IAMTHIF_FLOW_CONTROL, |
| 109 | MEI_IAMTHIF_READING, |
| 110 | MEI_IAMTHIF_READ_COMPLETE |
| 111 | }; |
| 112 | |
| 113 | enum mei_file_transaction_states { |
| 114 | MEI_IDLE, |
| 115 | MEI_WRITING, |
| 116 | MEI_WRITE_COMPLETE, |
| 117 | MEI_FLOW_CONTROL, |
| 118 | MEI_READING, |
| 119 | MEI_READ_COMPLETE |
| 120 | }; |
| 121 | |
Tomas Winkler | c216fde | 2012-08-16 19:39:43 +0300 | [diff] [blame] | 122 | enum mei_wd_states { |
| 123 | MEI_WD_IDLE, |
| 124 | MEI_WD_RUNNING, |
| 125 | MEI_WD_STOPPING, |
| 126 | }; |
| 127 | |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 128 | /** |
| 129 | * enum mei_cb_file_ops - file operation associated with the callback |
| 130 | * @MEI_FOP_READ - read |
| 131 | * @MEI_FOP_WRITE - write |
| 132 | * @MEI_FOP_IOCTL - ioctl |
| 133 | * @MEI_FOP_OPEN - open |
| 134 | * @MEI_FOP_CLOSE - close |
| 135 | */ |
| 136 | enum mei_cb_file_ops { |
| 137 | MEI_FOP_READ = 0, |
| 138 | MEI_FOP_WRITE, |
| 139 | MEI_FOP_IOCTL, |
| 140 | MEI_FOP_OPEN, |
| 141 | MEI_FOP_CLOSE |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | /* |
| 145 | * Intel MEI message data struct |
| 146 | */ |
| 147 | struct mei_message_data { |
| 148 | u32 size; |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 149 | unsigned char *data; |
Tomas Winkler | f060939 | 2012-09-11 00:43:21 +0300 | [diff] [blame] | 150 | }; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 151 | |
| 152 | |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 153 | struct mei_cl; |
| 154 | |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 155 | /** |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 156 | * struct mei_cl_cb - file operation callback structure |
| 157 | * |
| 158 | * @cl - file client who is running this operation |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 159 | * @fop_type - file operation type |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 160 | */ |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 161 | struct mei_cl_cb { |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 162 | struct list_head list; |
Tomas Winkler | db3ed43 | 2012-11-11 17:37:59 +0200 | [diff] [blame] | 163 | struct mei_cl *cl; |
Tomas Winkler | 4b8960b | 2012-11-11 17:38:00 +0200 | [diff] [blame] | 164 | enum mei_cb_file_ops fop_type; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 165 | struct mei_message_data request_buffer; |
| 166 | struct mei_message_data response_buffer; |
Tomas Winkler | ebb108ef | 2012-10-09 16:50:16 +0200 | [diff] [blame] | 167 | unsigned long buf_idx; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 168 | unsigned long read_time; |
| 169 | struct file *file_object; |
| 170 | }; |
| 171 | |
| 172 | /* MEI client instance carried as file->pirvate_data*/ |
| 173 | struct mei_cl { |
| 174 | struct list_head link; |
| 175 | struct mei_device *dev; |
| 176 | enum file_state state; |
| 177 | wait_queue_head_t tx_wait; |
| 178 | wait_queue_head_t rx_wait; |
| 179 | wait_queue_head_t wait; |
| 180 | int read_pending; |
| 181 | int status; |
| 182 | /* ID of client connected */ |
| 183 | u8 host_client_id; |
| 184 | u8 me_client_id; |
| 185 | u8 mei_flow_ctrl_creds; |
| 186 | u8 timer_count; |
| 187 | enum mei_file_transaction_states reading_state; |
| 188 | enum mei_file_transaction_states writing_state; |
| 189 | int sm_state; |
| 190 | struct mei_cl_cb *read_cb; |
| 191 | }; |
| 192 | |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame] | 193 | /** |
| 194 | * struct mei_deive - MEI private device struct |
| 195 | * @hbuf_depth - depth of host(write) buffer |
| 196 | */ |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 197 | struct mei_device { |
| 198 | struct pci_dev *pdev; /* pointer to pci device struct */ |
| 199 | /* |
| 200 | * lists of queues |
| 201 | */ |
Tomas Winkler | e773efc | 2012-11-11 17:37:58 +0200 | [diff] [blame] | 202 | /* array of pointers to aio lists */ |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 203 | struct mei_cl_cb read_list; /* driver read queue */ |
| 204 | struct mei_cl_cb write_list; /* driver write queue */ |
| 205 | struct mei_cl_cb write_waiting_list; /* write waiting queue */ |
| 206 | struct mei_cl_cb ctrl_wr_list; /* managed write IOCTL list */ |
| 207 | struct mei_cl_cb ctrl_rd_list; /* managed read IOCTL list */ |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 208 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 209 | /* |
| 210 | * list of files |
| 211 | */ |
| 212 | struct list_head file_list; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 213 | long open_handle_count; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 214 | /* |
| 215 | * memory of device |
| 216 | */ |
| 217 | unsigned int mem_base; |
| 218 | unsigned int mem_length; |
| 219 | void __iomem *mem_addr; |
| 220 | /* |
| 221 | * lock for the device |
| 222 | */ |
| 223 | struct mutex device_lock; /* device lock */ |
Oren Weil | a61c653 | 2011-09-07 09:03:13 +0300 | [diff] [blame] | 224 | struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */ |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 225 | bool recvd_msg; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 226 | /* |
| 227 | * hw states of host and fw(ME) |
| 228 | */ |
| 229 | u32 host_hw_state; |
| 230 | u32 me_hw_state; |
Tomas Winkler | 24aadc8 | 2012-06-25 23:46:27 +0300 | [diff] [blame] | 231 | u8 hbuf_depth; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 232 | /* |
| 233 | * waiting queue for receive message from FW |
| 234 | */ |
| 235 | wait_queue_head_t wait_recvd_msg; |
| 236 | wait_queue_head_t wait_stop_wd; |
| 237 | |
| 238 | /* |
| 239 | * mei device states |
| 240 | */ |
Tomas Winkler | b210d75 | 2012-08-07 00:03:56 +0300 | [diff] [blame] | 241 | enum mei_dev_state dev_state; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 242 | enum mei_init_clients_states init_clients_state; |
| 243 | u16 init_clients_timer; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 244 | bool need_reset; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 245 | |
| 246 | u32 extra_write_index; |
Tomas Winkler | edf1eed | 2012-02-09 19:25:54 +0200 | [diff] [blame] | 247 | unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */ |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 248 | u32 wr_msg_buf[128]; /* used for control messages */ |
| 249 | u32 ext_msg_buf[8]; /* for control responses */ |
| 250 | u32 rd_msg_hdr; |
| 251 | |
| 252 | struct hbm_version version; |
| 253 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 254 | struct mei_me_client *me_clients; /* Note: memory has to be allocated */ |
| 255 | DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX); |
| 256 | DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX); |
Tomas Winkler | cf9673d | 2011-06-06 10:44:33 +0300 | [diff] [blame] | 257 | u8 me_clients_num; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 258 | u8 me_client_presentation_num; |
| 259 | u8 me_client_index; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 260 | bool mei_host_buffer_is_empty; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 261 | |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 262 | struct mei_cl wd_cl; |
Tomas Winkler | c216fde | 2012-08-16 19:39:43 +0300 | [diff] [blame] | 263 | enum mei_wd_states wd_state; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 264 | bool wd_pending; |
Tomas Winkler | c216fde | 2012-08-16 19:39:43 +0300 | [diff] [blame] | 265 | u16 wd_timeout; |
Tomas Winkler | 248ffdf | 2012-08-16 19:39:42 +0300 | [diff] [blame] | 266 | unsigned char wd_data[MEI_WD_START_MSG_SIZE]; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 267 | |
| 268 | |
Tomas Winkler | e773efc | 2012-11-11 17:37:58 +0200 | [diff] [blame] | 269 | /* amthif list for cmd waiting */ |
| 270 | struct mei_cl_cb amthif_cmd_list; |
| 271 | /* driver managed amthif list for reading completed amthif cmd data */ |
| 272 | struct mei_cl_cb amthif_rd_complete_list; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 273 | struct file *iamthif_file_object; |
| 274 | struct mei_cl iamthif_cl; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 275 | struct mei_cl_cb *iamthif_current_cb; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 276 | int iamthif_mtu; |
| 277 | unsigned long iamthif_timer; |
| 278 | u32 iamthif_stall_timer; |
| 279 | unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */ |
| 280 | u32 iamthif_msg_buf_size; |
| 281 | u32 iamthif_msg_buf_index; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 282 | enum iamthif_states iamthif_state; |
Tomas Winkler | eb9af0a | 2011-05-25 17:28:22 +0300 | [diff] [blame] | 283 | bool iamthif_flow_control_pending; |
| 284 | bool iamthif_ioctl; |
| 285 | bool iamthif_canceled; |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 286 | }; |
| 287 | |
Tomas Winkler | 3870c32 | 2012-11-01 21:17:14 +0200 | [diff] [blame] | 288 | static inline unsigned long mei_secs_to_jiffies(unsigned long sec) |
| 289 | { |
| 290 | return msecs_to_jiffies(sec * MSEC_PER_SEC); |
| 291 | } |
| 292 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 293 | |
| 294 | /* |
| 295 | * mei init function prototypes |
| 296 | */ |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 297 | struct mei_device *mei_device_init(struct pci_dev *pdev); |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 298 | void mei_reset(struct mei_device *dev, int interrupts); |
| 299 | int mei_hw_init(struct mei_device *dev); |
| 300 | int mei_task_initialize_clients(void *data); |
| 301 | int mei_initialize_clients(struct mei_device *dev); |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 302 | int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl); |
Tomas Winkler | 106fb49 | 2011-05-25 17:28:20 +0300 | [diff] [blame] | 303 | void mei_remove_client_from_file_list(struct mei_device *dev, u8 host_client_id); |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 304 | void mei_allocate_me_clients_storage(struct mei_device *dev); |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 305 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 306 | |
Tomas Winkler | 07b509b | 2012-07-23 14:05:39 +0300 | [diff] [blame] | 307 | int mei_me_cl_update_filext(struct mei_device *dev, struct mei_cl *cl, |
| 308 | const uuid_le *cguid, u8 host_client_id); |
| 309 | int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid); |
| 310 | int mei_me_cl_by_id(struct mei_device *dev, u8 client_id); |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 311 | |
| 312 | /* |
Tomas Winkler | 601a1ef | 2012-10-09 16:50:20 +0200 | [diff] [blame] | 313 | * MEI IO Functions |
Tomas Winkler | 0288c7c | 2011-06-06 10:44:34 +0300 | [diff] [blame] | 314 | */ |
Tomas Winkler | 664df38 | 2012-10-11 16:35:08 +0200 | [diff] [blame] | 315 | struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp); |
Tomas Winkler | 601a1ef | 2012-10-09 16:50:20 +0200 | [diff] [blame] | 316 | void mei_io_cb_free(struct mei_cl_cb *priv_cb); |
Tomas Winkler | 664df38 | 2012-10-11 16:35:08 +0200 | [diff] [blame] | 317 | int mei_io_cb_alloc_req_buf(struct mei_cl_cb *cb, size_t length); |
| 318 | int mei_io_cb_alloc_resp_buf(struct mei_cl_cb *cb, size_t length); |
| 319 | |
Tomas Winkler | 601a1ef | 2012-10-09 16:50:20 +0200 | [diff] [blame] | 320 | |
Tomas Winkler | fb601ad | 2012-10-15 12:06:48 +0200 | [diff] [blame] | 321 | /** |
| 322 | * mei_io_list_init - Sets up a queue list. |
| 323 | * |
| 324 | * @list: An instance cl callback structure |
| 325 | */ |
| 326 | static inline void mei_io_list_init(struct mei_cl_cb *list) |
| 327 | { |
| 328 | INIT_LIST_HEAD(&list->list); |
| 329 | } |
| 330 | void mei_io_list_flush(struct mei_cl_cb *list, struct mei_cl *cl); |
Tomas Winkler | 0288c7c | 2011-06-06 10:44:34 +0300 | [diff] [blame] | 331 | |
| 332 | /* |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 333 | * MEI ME Client Functions |
| 334 | */ |
| 335 | |
| 336 | struct mei_cl *mei_cl_allocate(struct mei_device *dev); |
Tomas Winkler | 0288c7c | 2011-06-06 10:44:34 +0300 | [diff] [blame] | 337 | void mei_cl_init(struct mei_cl *cl, struct mei_device *dev); |
| 338 | int mei_cl_flush_queues(struct mei_cl *cl); |
| 339 | /** |
| 340 | * mei_cl_cmp_id - tells if file private data have same id |
| 341 | * |
| 342 | * @fe1: private data of 1. file object |
| 343 | * @fe2: private data of 2. file object |
| 344 | * |
| 345 | * returns true - if ids are the same and not NULL |
| 346 | */ |
| 347 | static inline bool mei_cl_cmp_id(const struct mei_cl *cl1, |
| 348 | const struct mei_cl *cl2) |
| 349 | { |
| 350 | return cl1 && cl2 && |
| 351 | (cl1->host_client_id == cl2->host_client_id) && |
| 352 | (cl1->me_client_id == cl2->me_client_id); |
| 353 | } |
| 354 | |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 355 | |
| 356 | |
| 357 | /* |
| 358 | * MEI Host Client Functions |
| 359 | */ |
| 360 | void mei_host_start_message(struct mei_device *dev); |
| 361 | void mei_host_enum_clients_message(struct mei_device *dev); |
Oren Weil | abc51b6 | 2011-09-21 16:45:30 +0300 | [diff] [blame] | 362 | int mei_host_client_properties(struct mei_device *dev); |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 363 | |
| 364 | /* |
| 365 | * MEI interrupt functions prototype |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 366 | */ |
| 367 | irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id); |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 368 | irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id); |
Oren Weil | a61c653 | 2011-09-07 09:03:13 +0300 | [diff] [blame] | 369 | void mei_timer(struct work_struct *work); |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 370 | |
| 371 | /* |
Tomas Winkler | c95efb7 | 2011-05-25 17:28:21 +0300 | [diff] [blame] | 372 | * MEI input output function prototype |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 373 | */ |
| 374 | int mei_ioctl_connect_client(struct file *file, |
| 375 | struct mei_connect_client_data *data); |
| 376 | |
| 377 | int mei_start_read(struct mei_device *dev, struct mei_cl *cl); |
| 378 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 379 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 380 | /* |
| 381 | * AMTHIF - AMT Host Interface Functions |
| 382 | */ |
| 383 | void mei_amthif_reset_params(struct mei_device *dev); |
| 384 | |
| 385 | void mei_amthif_host_init(struct mei_device *dev); |
| 386 | |
| 387 | int mei_amthif_write(struct mei_device *dev, struct mei_cl_cb *priv_cb); |
| 388 | |
| 389 | int mei_amthif_read(struct mei_device *dev, struct file *file, |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 390 | char __user *ubuf, size_t length, loff_t *offset); |
| 391 | |
Tomas Winkler | a562d5c | 2012-11-11 17:38:01 +0200 | [diff] [blame^] | 392 | int mei_amthif_release(struct mei_device *dev, struct file *file); |
| 393 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 394 | struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev, |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 395 | struct file *file); |
| 396 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 397 | void mei_amthif_run_next_cmd(struct mei_device *dev); |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 398 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 399 | |
Tomas Winkler | 19838fb | 2012-11-01 21:17:15 +0200 | [diff] [blame] | 400 | int mei_amthif_read_message(struct mei_cl_cb *complete_list, |
| 401 | struct mei_device *dev, struct mei_msg_hdr *mei_hdr); |
| 402 | |
| 403 | int mei_amthif_irq_process_completed(struct mei_device *dev, s32 *slots, |
| 404 | struct mei_cl_cb *cb_pos, |
| 405 | struct mei_cl *cl, |
| 406 | struct mei_cl_cb *cmpl_list); |
| 407 | |
| 408 | void mei_amthif_complete(struct mei_device *dev, struct mei_cl_cb *cb); |
| 409 | int mei_amthif_irq_read_message(struct mei_cl_cb *complete_list, |
| 410 | struct mei_device *dev, struct mei_msg_hdr *mei_hdr); |
| 411 | int mei_amthif_irq_read(struct mei_device *dev, s32 *slots); |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 412 | |
| 413 | /* |
| 414 | * Register Access Function |
| 415 | */ |
| 416 | |
| 417 | /** |
| 418 | * mei_reg_read - Reads 32bit data from the mei device |
| 419 | * |
| 420 | * @dev: the device structure |
| 421 | * @offset: offset from which to read the data |
| 422 | * |
Oren Weil | 92eb401 | 2011-09-07 09:03:08 +0300 | [diff] [blame] | 423 | * returns register value (u32) |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 424 | */ |
Tomas Winkler | 4a0d6a7 | 2012-07-04 19:24:49 +0300 | [diff] [blame] | 425 | static inline u32 mei_reg_read(const struct mei_device *dev, |
| 426 | unsigned long offset) |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 427 | { |
| 428 | return ioread32(dev->mem_addr + offset); |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * mei_reg_write - Writes 32bit data to the mei device |
| 433 | * |
| 434 | * @dev: the device structure |
| 435 | * @offset: offset from which to write the data |
Oren Weil | 92eb401 | 2011-09-07 09:03:08 +0300 | [diff] [blame] | 436 | * @value: register value to write (u32) |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 437 | */ |
Tomas Winkler | 4a0d6a7 | 2012-07-04 19:24:49 +0300 | [diff] [blame] | 438 | static inline void mei_reg_write(const struct mei_device *dev, |
| 439 | unsigned long offset, u32 value) |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 440 | { |
| 441 | iowrite32(value, dev->mem_addr + offset); |
| 442 | } |
| 443 | |
| 444 | /** |
| 445 | * mei_hcsr_read - Reads 32bit data from the host CSR |
| 446 | * |
| 447 | * @dev: the device structure |
| 448 | * |
| 449 | * returns the byte read. |
| 450 | */ |
Tomas Winkler | 4a0d6a7 | 2012-07-04 19:24:49 +0300 | [diff] [blame] | 451 | static inline u32 mei_hcsr_read(const struct mei_device *dev) |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 452 | { |
| 453 | return mei_reg_read(dev, H_CSR); |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * mei_mecsr_read - Reads 32bit data from the ME CSR |
| 458 | * |
| 459 | * @dev: the device structure |
| 460 | * |
| 461 | * returns ME_CSR_HA register value (u32) |
| 462 | */ |
Tomas Winkler | 4a0d6a7 | 2012-07-04 19:24:49 +0300 | [diff] [blame] | 463 | static inline u32 mei_mecsr_read(const struct mei_device *dev) |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 464 | { |
| 465 | return mei_reg_read(dev, ME_CSR_HA); |
| 466 | } |
| 467 | |
| 468 | /** |
| 469 | * get_me_cb_rw - Reads 32bit data from the mei ME_CB_RW register |
| 470 | * |
| 471 | * @dev: the device structure |
| 472 | * |
| 473 | * returns ME_CB_RW register value (u32) |
| 474 | */ |
Tomas Winkler | 4a0d6a7 | 2012-07-04 19:24:49 +0300 | [diff] [blame] | 475 | static inline u32 mei_mecbrw_read(const struct mei_device *dev) |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 476 | { |
| 477 | return mei_reg_read(dev, ME_CB_RW); |
| 478 | } |
| 479 | |
| 480 | |
| 481 | /* |
| 482 | * mei interface function prototypes |
| 483 | */ |
| 484 | void mei_hcsr_set(struct mei_device *dev); |
| 485 | void mei_csr_clear_his(struct mei_device *dev); |
| 486 | |
| 487 | void mei_enable_interrupts(struct mei_device *dev); |
| 488 | void mei_disable_interrupts(struct mei_device *dev); |
| 489 | |
Oren Weil | ab84116 | 2011-05-15 13:43:41 +0300 | [diff] [blame] | 490 | #endif |