Commit | Line | Data |
---|---|---|
ab841160 OW |
1 | /* |
2 | * | |
3 | * Intel Management Engine Interface (Intel MEI) Linux driver | |
733ba91c | 4 | * Copyright (c) 2003-2012, Intel Corporation. |
ab841160 OW |
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> | |
9ce178e5 | 21 | #include <linux/watchdog.h> |
744f0f2f | 22 | #include <linux/poll.h> |
4f3afe1d | 23 | #include <linux/mei.h> |
e5354107 | 24 | #include <linux/mei_cl_bus.h> |
66ef5ea9 | 25 | |
ab841160 | 26 | #include "hw.h" |
9b0d5efc | 27 | #include "hbm.h" |
ab841160 | 28 | |
ab841160 OW |
29 | /* |
30 | * watch dog definition | |
31 | */ | |
248ffdf7 TW |
32 | #define MEI_WD_HDR_SIZE 4 |
33 | #define MEI_WD_STOP_MSG_SIZE MEI_WD_HDR_SIZE | |
34 | #define MEI_WD_START_MSG_SIZE (MEI_WD_HDR_SIZE + 16) | |
35 | ||
36 | #define MEI_WD_DEFAULT_TIMEOUT 120 /* seconds */ | |
37 | #define MEI_WD_MIN_TIMEOUT 120 /* seconds */ | |
38 | #define MEI_WD_MAX_TIMEOUT 65535 /* seconds */ | |
39 | ||
c216fdeb TW |
40 | #define MEI_WD_STOP_TIMEOUT 10 /* msecs */ |
41 | ||
ab841160 OW |
42 | #define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0) |
43 | ||
edf1eed4 TW |
44 | #define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32)) |
45 | ||
9ce178e5 | 46 | |
ab841160 OW |
47 | /* |
48 | * AMTHI Client UUID | |
49 | */ | |
1a1aca42 | 50 | extern const uuid_le mei_amthif_guid; |
ab841160 OW |
51 | |
52 | /* | |
53 | * Watchdog Client UUID | |
54 | */ | |
55 | extern const uuid_le mei_wd_guid; | |
56 | ||
1e2776c3 TW |
57 | /* |
58 | * Number of Maximum MEI Clients | |
59 | */ | |
60 | #define MEI_CLIENTS_MAX 256 | |
61 | ||
6adb8efb TW |
62 | /* |
63 | * maximum number of consecutive resets | |
64 | */ | |
65 | #define MEI_MAX_CONSEC_RESET 3 | |
66 | ||
ab841160 OW |
67 | /* |
68 | * Number of File descriptors/handles | |
69 | * that can be opened to the driver. | |
70 | * | |
781d0d89 | 71 | * Limit to 255: 256 Total Clients |
83ce0741 | 72 | * minus internal client for MEI Bus Messages |
ab841160 | 73 | */ |
781d0d89 | 74 | #define MEI_MAX_OPEN_HANDLE_COUNT (MEI_CLIENTS_MAX - 1) |
ab841160 | 75 | |
1d3f3da3 TW |
76 | /* |
77 | * Internal Clients Number | |
78 | */ | |
781d0d89 TW |
79 | #define MEI_HOST_CLIENT_ID_ANY (-1) |
80 | #define MEI_HBM_HOST_CLIENT_ID 0 /* not used, just for documentation */ | |
1d3f3da3 TW |
81 | #define MEI_WD_HOST_CLIENT_ID 1 |
82 | #define MEI_IAMTHIF_HOST_CLIENT_ID 2 | |
83 | ||
ab841160 OW |
84 | |
85 | /* File state */ | |
86 | enum file_state { | |
87 | MEI_FILE_INITIALIZING = 0, | |
88 | MEI_FILE_CONNECTING, | |
89 | MEI_FILE_CONNECTED, | |
90 | MEI_FILE_DISCONNECTING, | |
3c666182 TW |
91 | MEI_FILE_DISCONNECT_REPLY, |
92 | MEI_FILE_DISCONNECTED, | |
ab841160 OW |
93 | }; |
94 | ||
95 | /* MEI device states */ | |
b210d750 TW |
96 | enum mei_dev_state { |
97 | MEI_DEV_INITIALIZING = 0, | |
98 | MEI_DEV_INIT_CLIENTS, | |
99 | MEI_DEV_ENABLED, | |
0cfee51c | 100 | MEI_DEV_RESETTING, |
b210d750 | 101 | MEI_DEV_DISABLED, |
b210d750 TW |
102 | MEI_DEV_POWER_DOWN, |
103 | MEI_DEV_POWER_UP | |
ab841160 OW |
104 | }; |
105 | ||
b210d750 TW |
106 | const char *mei_dev_state_str(int state); |
107 | ||
ab841160 OW |
108 | enum iamthif_states { |
109 | MEI_IAMTHIF_IDLE, | |
110 | MEI_IAMTHIF_WRITING, | |
111 | MEI_IAMTHIF_FLOW_CONTROL, | |
112 | MEI_IAMTHIF_READING, | |
113 | MEI_IAMTHIF_READ_COMPLETE | |
114 | }; | |
115 | ||
116 | enum mei_file_transaction_states { | |
117 | MEI_IDLE, | |
118 | MEI_WRITING, | |
119 | MEI_WRITE_COMPLETE, | |
120 | MEI_FLOW_CONTROL, | |
121 | MEI_READING, | |
122 | MEI_READ_COMPLETE | |
123 | }; | |
124 | ||
c216fdeb TW |
125 | enum mei_wd_states { |
126 | MEI_WD_IDLE, | |
127 | MEI_WD_RUNNING, | |
128 | MEI_WD_STOPPING, | |
129 | }; | |
130 | ||
4b8960b4 TW |
131 | /** |
132 | * enum mei_cb_file_ops - file operation associated with the callback | |
ce23139c AU |
133 | * @MEI_FOP_READ: read |
134 | * @MEI_FOP_WRITE: write | |
135 | * @MEI_FOP_CONNECT: connect | |
136 | * @MEI_FOP_DISCONNECT: disconnect | |
137 | * @MEI_FOP_DISCONNECT_RSP: disconnect response | |
4b8960b4 TW |
138 | */ |
139 | enum mei_cb_file_ops { | |
140 | MEI_FOP_READ = 0, | |
141 | MEI_FOP_WRITE, | |
02a7eecc | 142 | MEI_FOP_CONNECT, |
5a8373fb | 143 | MEI_FOP_DISCONNECT, |
6bb948c9 | 144 | MEI_FOP_DISCONNECT_RSP, |
ab841160 OW |
145 | }; |
146 | ||
147 | /* | |
148 | * Intel MEI message data struct | |
149 | */ | |
4234a6de | 150 | struct mei_msg_data { |
ab841160 | 151 | u32 size; |
edf1eed4 | 152 | unsigned char *data; |
f060939d | 153 | }; |
ab841160 | 154 | |
04dd3661 | 155 | /* Maximum number of processed FW status registers */ |
edca5ea3 AU |
156 | #define MEI_FW_STATUS_MAX 6 |
157 | /* Minimal buffer for FW status string (8 bytes in dw + space or '\0') */ | |
158 | #define MEI_FW_STATUS_STR_SZ (MEI_FW_STATUS_MAX * (8 + 1)) | |
159 | ||
04dd3661 AU |
160 | |
161 | /* | |
162 | * struct mei_fw_status - storage of FW status data | |
163 | * | |
a8605ea2 AU |
164 | * @count: number of actually available elements in array |
165 | * @status: FW status registers | |
04dd3661 AU |
166 | */ |
167 | struct mei_fw_status { | |
168 | int count; | |
169 | u32 status[MEI_FW_STATUS_MAX]; | |
170 | }; | |
171 | ||
db7da79d TW |
172 | /** |
173 | * struct mei_me_client - representation of me (fw) client | |
174 | * | |
a8605ea2 | 175 | * @list: link in me client list |
79563db9 | 176 | * @refcnt: struct reference count |
a8605ea2 AU |
177 | * @props: client properties |
178 | * @client_id: me client id | |
179 | * @mei_flow_ctrl_creds: flow control credits | |
a03d77f6 AU |
180 | * @connect_count: number connections to this client |
181 | * @reserved: reserved | |
db7da79d TW |
182 | */ |
183 | struct mei_me_client { | |
5ca2d388 | 184 | struct list_head list; |
79563db9 | 185 | struct kref refcnt; |
db7da79d TW |
186 | struct mei_client_properties props; |
187 | u8 client_id; | |
188 | u8 mei_flow_ctrl_creds; | |
a03d77f6 AU |
189 | u8 connect_count; |
190 | u8 reserved; | |
db7da79d TW |
191 | }; |
192 | ||
ab841160 | 193 | |
db3ed431 TW |
194 | struct mei_cl; |
195 | ||
4b8960b4 | 196 | /** |
db3ed431 TW |
197 | * struct mei_cl_cb - file operation callback structure |
198 | * | |
a8605ea2 AU |
199 | * @list: link in callback queue |
200 | * @cl: file client who is running this operation | |
201 | * @fop_type: file operation type | |
5db7514d | 202 | * @buf: buffer for data associated with the callback |
ce23139c AU |
203 | * @buf_idx: last read index |
204 | * @read_time: last read operation time stamp (iamthif) | |
205 | * @file_object: pointer to file structure | |
3d33ff24 | 206 | * @status: io status of the cb |
ce23139c | 207 | * @internal: communication between driver and FW flag |
8660172e | 208 | * @completed: the transfer or reception has completed |
db3ed431 | 209 | */ |
ab841160 | 210 | struct mei_cl_cb { |
fb601adb | 211 | struct list_head list; |
db3ed431 | 212 | struct mei_cl *cl; |
4b8960b4 | 213 | enum mei_cb_file_ops fop_type; |
5db7514d | 214 | struct mei_msg_data buf; |
ebb108ef | 215 | unsigned long buf_idx; |
ab841160 OW |
216 | unsigned long read_time; |
217 | struct file *file_object; | |
3d33ff24 | 218 | int status; |
479327fc | 219 | u32 internal:1; |
8660172e | 220 | u32 completed:1; |
ab841160 OW |
221 | }; |
222 | ||
ce23139c AU |
223 | /** |
224 | * struct mei_cl - me client host representation | |
225 | * carried in file->private_data | |
226 | * | |
227 | * @link: link in the clients list | |
228 | * @dev: mei parent device | |
229 | * @state: file operation state | |
230 | * @tx_wait: wait queue for tx completion | |
231 | * @rx_wait: wait queue for rx completion | |
232 | * @wait: wait queue for management operation | |
233 | * @status: connection status | |
d49ed64a | 234 | * @me_cl: fw client connected |
ce23139c | 235 | * @host_client_id: host id |
ce23139c AU |
236 | * @mei_flow_ctrl_creds: transmit flow credentials |
237 | * @timer_count: watchdog timer for operation completion | |
d49ed64a | 238 | * @reserved: reserved for alignment |
ce23139c | 239 | * @writing_state: state of the tx |
a9bed610 TW |
240 | * @rd_pending: pending read credits |
241 | * @rd_completed: completed read | |
ce23139c | 242 | * |
b37719c3 | 243 | * @cldev: device on the mei client bus |
ce23139c AU |
244 | * @device_link: link to bus clients |
245 | */ | |
ab841160 OW |
246 | struct mei_cl { |
247 | struct list_head link; | |
248 | struct mei_device *dev; | |
249 | enum file_state state; | |
250 | wait_queue_head_t tx_wait; | |
251 | wait_queue_head_t rx_wait; | |
252 | wait_queue_head_t wait; | |
ab841160 | 253 | int status; |
d49ed64a | 254 | struct mei_me_client *me_cl; |
ab841160 | 255 | u8 host_client_id; |
ab841160 OW |
256 | u8 mei_flow_ctrl_creds; |
257 | u8 timer_count; | |
d49ed64a | 258 | u8 reserved; |
ab841160 | 259 | enum mei_file_transaction_states writing_state; |
a9bed610 TW |
260 | struct list_head rd_pending; |
261 | struct list_head rd_completed; | |
a7b71bc0 SO |
262 | |
263 | /* MEI CL bus data */ | |
b37719c3 | 264 | struct mei_cl_device *cldev; |
a7b71bc0 | 265 | struct list_head device_link; |
ab841160 OW |
266 | }; |
267 | ||
827eef51 TW |
268 | /** struct mei_hw_ops |
269 | * | |
a8605ea2 | 270 | * @host_is_ready : query for host readiness |
827eef51 | 271 | |
a8605ea2 AU |
272 | * @hw_is_ready : query if hw is ready |
273 | * @hw_reset : reset hw | |
274 | * @hw_start : start hw after reset | |
275 | * @hw_config : configure hw | |
827eef51 | 276 | |
a8605ea2 AU |
277 | * @fw_status : get fw status registers |
278 | * @pg_state : power gating state of the device | |
3dc196ea | 279 | * @pg_in_transition : is device now in pg transition |
a8605ea2 | 280 | * @pg_is_enabled : is power gating enabled |
ee7e5afd | 281 | |
a8605ea2 AU |
282 | * @intr_clear : clear pending interrupts |
283 | * @intr_enable : enable interrupts | |
284 | * @intr_disable : disable interrupts | |
827eef51 | 285 | |
a8605ea2 AU |
286 | * @hbuf_free_slots : query for write buffer empty slots |
287 | * @hbuf_is_ready : query if write buffer is empty | |
288 | * @hbuf_max_len : query for write buffer max len | |
827eef51 | 289 | |
a8605ea2 | 290 | * @write : write a message to FW |
827eef51 | 291 | |
a8605ea2 | 292 | * @rdbuf_full_slots : query how many slots are filled |
827eef51 | 293 | |
a8605ea2 AU |
294 | * @read_hdr : get first 4 bytes (header) |
295 | * @read : read a buffer from the FW | |
827eef51 TW |
296 | */ |
297 | struct mei_hw_ops { | |
298 | ||
d63b3095 | 299 | bool (*host_is_ready)(struct mei_device *dev); |
827eef51 | 300 | |
d63b3095 TW |
301 | bool (*hw_is_ready)(struct mei_device *dev); |
302 | int (*hw_reset)(struct mei_device *dev, bool enable); | |
303 | int (*hw_start)(struct mei_device *dev); | |
304 | void (*hw_config)(struct mei_device *dev); | |
827eef51 | 305 | |
1bd30b6a TW |
306 | |
307 | int (*fw_status)(struct mei_device *dev, struct mei_fw_status *fw_sts); | |
964a2331 | 308 | enum mei_pg_state (*pg_state)(struct mei_device *dev); |
3dc196ea | 309 | bool (*pg_in_transition)(struct mei_device *dev); |
ee7e5afd TW |
310 | bool (*pg_is_enabled)(struct mei_device *dev); |
311 | ||
d63b3095 TW |
312 | void (*intr_clear)(struct mei_device *dev); |
313 | void (*intr_enable)(struct mei_device *dev); | |
314 | void (*intr_disable)(struct mei_device *dev); | |
827eef51 | 315 | |
d63b3095 TW |
316 | int (*hbuf_free_slots)(struct mei_device *dev); |
317 | bool (*hbuf_is_ready)(struct mei_device *dev); | |
318 | size_t (*hbuf_max_len)(const struct mei_device *dev); | |
827eef51 TW |
319 | |
320 | int (*write)(struct mei_device *dev, | |
321 | struct mei_msg_hdr *hdr, | |
322 | unsigned char *buf); | |
323 | ||
324 | int (*rdbuf_full_slots)(struct mei_device *dev); | |
325 | ||
326 | u32 (*read_hdr)(const struct mei_device *dev); | |
d63b3095 | 327 | int (*read)(struct mei_device *dev, |
827eef51 TW |
328 | unsigned char *buf, unsigned long len); |
329 | }; | |
330 | ||
e5354107 | 331 | /* MEI bus API*/ |
3e833295 | 332 | |
b37719c3 | 333 | struct mei_cl_device *mei_cl_add_device(struct mei_device *bus, |
d49ed64a AU |
334 | struct mei_me_client *me_cl, |
335 | struct mei_cl *cl, | |
be9b720a | 336 | char *name); |
b37719c3 | 337 | void mei_cl_remove_device(struct mei_cl_device *cldev); |
e46980a1 | 338 | |
be9b720a TW |
339 | ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length, |
340 | bool blocking); | |
39db74ce | 341 | ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length); |
cf3baefb | 342 | void mei_cl_bus_rx_event(struct mei_cl *cl); |
b37719c3 | 343 | void mei_cl_bus_remove_devices(struct mei_device *bus); |
cf3baefb SO |
344 | int mei_cl_bus_init(void); |
345 | void mei_cl_bus_exit(void); | |
b37719c3 | 346 | struct mei_cl *mei_cl_bus_find_cl_by_uuid(struct mei_device *bus, uuid_le uuid); |
cf3baefb | 347 | |
ce23139c | 348 | /** |
964a2331 TW |
349 | * enum mei_pg_event - power gating transition events |
350 | * | |
351 | * @MEI_PG_EVENT_IDLE: the driver is not in power gating transition | |
352 | * @MEI_PG_EVENT_WAIT: the driver is waiting for a pg event to complete | |
353 | * @MEI_PG_EVENT_RECEIVED: the driver received pg event | |
3dc196ea AU |
354 | * @MEI_PG_EVENT_INTR_WAIT: the driver is waiting for a pg event interrupt |
355 | * @MEI_PG_EVENT_INTR_RECEIVED: the driver received pg event interrupt | |
964a2331 TW |
356 | */ |
357 | enum mei_pg_event { | |
358 | MEI_PG_EVENT_IDLE, | |
359 | MEI_PG_EVENT_WAIT, | |
360 | MEI_PG_EVENT_RECEIVED, | |
3dc196ea AU |
361 | MEI_PG_EVENT_INTR_WAIT, |
362 | MEI_PG_EVENT_INTR_RECEIVED, | |
964a2331 TW |
363 | }; |
364 | ||
365 | /** | |
366 | * enum mei_pg_state - device internal power gating state | |
367 | * | |
368 | * @MEI_PG_OFF: device is not power gated - it is active | |
369 | * @MEI_PG_ON: device is power gated - it is in lower power state | |
370 | */ | |
371 | enum mei_pg_state { | |
372 | MEI_PG_OFF = 0, | |
373 | MEI_PG_ON = 1, | |
374 | }; | |
375 | ||
1beeb4b9 AU |
376 | const char *mei_pg_state_str(enum mei_pg_state state); |
377 | ||
24aadc80 | 378 | /** |
5fb54fb4 | 379 | * struct mei_device - MEI private device struct |
ce23139c | 380 | * |
a8605ea2 AU |
381 | * @dev : device on a bus |
382 | * @cdev : character device | |
383 | * @minor : minor number allocated for device | |
f3d8e878 | 384 | * |
ce23139c AU |
385 | * @write_list : write pending list |
386 | * @write_waiting_list : write completion list | |
387 | * @ctrl_wr_list : pending control write list | |
388 | * @ctrl_rd_list : pending control read list | |
bae1cc7d | 389 | * |
ce23139c AU |
390 | * @file_list : list of opened handles |
391 | * @open_handle_count: number of opened handles | |
392 | * | |
393 | * @device_lock : big device lock | |
394 | * @timer_work : MEI timer delayed work (timeouts) | |
395 | * | |
396 | * @recvd_hw_ready : hw ready message received flag | |
397 | * | |
398 | * @wait_hw_ready : wait queue for receive HW ready message form FW | |
399 | * @wait_pg : wait queue for receive PG message from FW | |
400 | * @wait_hbm_start : wait queue for receive HBM start message from FW | |
401 | * @wait_stop_wd : wait queue for receive WD stop message from FW | |
402 | * | |
403 | * @reset_count : number of consecutive resets | |
404 | * @dev_state : device state | |
405 | * @hbm_state : state of host bus message protocol | |
406 | * @init_clients_timer : HBM init handshake timeout | |
bae1cc7d | 407 | * |
a8605ea2 | 408 | * @pg_event : power gating event |
ce23139c AU |
409 | * @pg_domain : runtime PM domain |
410 | * | |
411 | * @rd_msg_buf : control messages buffer | |
412 | * @rd_msg_hdr : read message header storage | |
413 | * | |
a8605ea2 AU |
414 | * @hbuf_depth : depth of hardware host/write buffer is slots |
415 | * @hbuf_is_ready : query if the host host/write buffer is ready | |
416 | * @wr_msg : the buffer for hbm control messages | |
ce23139c AU |
417 | * |
418 | * @version : HBM protocol version in use | |
419 | * @hbm_f_pg_supported : hbm feature pgi protocol | |
420 | * | |
b7d88514 | 421 | * @me_clients_rwsem: rw lock over me_clients list |
ce23139c AU |
422 | * @me_clients : list of FW clients |
423 | * @me_clients_map : FW clients bit map | |
424 | * @host_clients_map : host clients id pool | |
425 | * @me_client_index : last FW client index in enumeration | |
426 | * | |
eeabfcf5 AU |
427 | * @allow_fixed_address: allow user space to connect a fixed client |
428 | * | |
ce23139c AU |
429 | * @wd_cl : watchdog client |
430 | * @wd_state : watchdog client state | |
431 | * @wd_pending : watchdog command is pending | |
432 | * @wd_timeout : watchdog expiration timeout | |
433 | * @wd_data : watchdog message buffer | |
434 | * | |
435 | * @amthif_cmd_list : amthif list for cmd waiting | |
436 | * @amthif_rd_complete_list : amthif list for reading completed cmd data | |
437 | * @iamthif_file_object : file for current amthif operation | |
438 | * @iamthif_cl : amthif host client | |
439 | * @iamthif_current_cb : amthif current operation callback | |
440 | * @iamthif_open_count : number of opened amthif connections | |
ce23139c AU |
441 | * @iamthif_timer : time stamp of current amthif command completion |
442 | * @iamthif_stall_timer : timer to detect amthif hang | |
ce23139c | 443 | * @iamthif_state : amthif processor state |
ce23139c AU |
444 | * @iamthif_canceled : current amthif command is canceled |
445 | * | |
446 | * @init_work : work item for the device init | |
447 | * @reset_work : work item for the device reset | |
448 | * | |
449 | * @device_list : mei client bus list | |
450 | * | |
451 | * @dbgfs_dir : debugfs mei root directory | |
452 | * | |
453 | * @ops: : hw specific operations | |
454 | * @hw : hw specific data | |
24aadc80 | 455 | */ |
ab841160 | 456 | struct mei_device { |
3a7e9b6c | 457 | struct device *dev; |
f3d8e878 AU |
458 | struct cdev cdev; |
459 | int minor; | |
460 | ||
ce23139c AU |
461 | struct mei_cl_cb write_list; |
462 | struct mei_cl_cb write_waiting_list; | |
463 | struct mei_cl_cb ctrl_wr_list; | |
464 | struct mei_cl_cb ctrl_rd_list; | |
ab841160 | 465 | |
ab841160 | 466 | struct list_head file_list; |
eb9af0ac | 467 | long open_handle_count; |
fecb0d58 | 468 | |
ce23139c AU |
469 | struct mutex device_lock; |
470 | struct delayed_work timer_work; | |
aafae7ec TW |
471 | |
472 | bool recvd_hw_ready; | |
ab841160 OW |
473 | /* |
474 | * waiting queue for receive message from FW | |
475 | */ | |
aafae7ec | 476 | wait_queue_head_t wait_hw_ready; |
4fcbc99b | 477 | wait_queue_head_t wait_pg; |
cb02efc3 | 478 | wait_queue_head_t wait_hbm_start; |
ab841160 OW |
479 | wait_queue_head_t wait_stop_wd; |
480 | ||
481 | /* | |
482 | * mei device states | |
483 | */ | |
6adb8efb | 484 | unsigned long reset_count; |
b210d750 | 485 | enum mei_dev_state dev_state; |
9b0d5efc | 486 | enum mei_hbm_state hbm_state; |
ab841160 | 487 | u16 init_clients_timer; |
ab841160 | 488 | |
964a2331 TW |
489 | /* |
490 | * Power Gating support | |
491 | */ | |
492 | enum mei_pg_event pg_event; | |
bbd6d050 | 493 | #ifdef CONFIG_PM |
e13fa90c | 494 | struct dev_pm_domain pg_domain; |
bbd6d050 | 495 | #endif /* CONFIG_PM */ |
964a2331 | 496 | |
ce23139c | 497 | unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; |
ab841160 | 498 | u32 rd_msg_hdr; |
e46f1874 | 499 | |
330dd7da TW |
500 | /* write buffer */ |
501 | u8 hbuf_depth; | |
502 | bool hbuf_is_ready; | |
503 | ||
e46f1874 TW |
504 | /* used for control messages */ |
505 | struct { | |
506 | struct mei_msg_hdr hdr; | |
507 | unsigned char data[128]; | |
508 | } wr_msg; | |
509 | ||
ab841160 | 510 | struct hbm_version version; |
bae1cc7d | 511 | unsigned int hbm_f_pg_supported:1; |
ab841160 | 512 | |
b7d88514 | 513 | struct rw_semaphore me_clients_rwsem; |
5ca2d388 | 514 | struct list_head me_clients; |
ab841160 OW |
515 | DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX); |
516 | DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX); | |
1aee351a | 517 | unsigned long me_client_index; |
ab841160 | 518 | |
eeabfcf5 AU |
519 | u32 allow_fixed_address; |
520 | ||
eb9af0ac | 521 | struct mei_cl wd_cl; |
c216fdeb | 522 | enum mei_wd_states wd_state; |
eb9af0ac | 523 | bool wd_pending; |
c216fdeb | 524 | u16 wd_timeout; |
248ffdf7 | 525 | unsigned char wd_data[MEI_WD_START_MSG_SIZE]; |
ab841160 OW |
526 | |
527 | ||
e773efc4 TW |
528 | /* amthif list for cmd waiting */ |
529 | struct mei_cl_cb amthif_cmd_list; | |
530 | /* driver managed amthif list for reading completed amthif cmd data */ | |
531 | struct mei_cl_cb amthif_rd_complete_list; | |
ab841160 OW |
532 | struct file *iamthif_file_object; |
533 | struct mei_cl iamthif_cl; | |
eb9af0ac | 534 | struct mei_cl_cb *iamthif_current_cb; |
22f96a0e | 535 | long iamthif_open_count; |
ab841160 OW |
536 | unsigned long iamthif_timer; |
537 | u32 iamthif_stall_timer; | |
ab841160 | 538 | enum iamthif_states iamthif_state; |
eb9af0ac | 539 | bool iamthif_canceled; |
c1174c0e SO |
540 | |
541 | struct work_struct init_work; | |
544f9460 | 542 | struct work_struct reset_work; |
827eef51 | 543 | |
a7b71bc0 SO |
544 | /* List of bus devices */ |
545 | struct list_head device_list; | |
546 | ||
30e53bb8 TW |
547 | #if IS_ENABLED(CONFIG_DEBUG_FS) |
548 | struct dentry *dbgfs_dir; | |
549 | #endif /* CONFIG_DEBUG_FS */ | |
550 | ||
551 | ||
827eef51 | 552 | const struct mei_hw_ops *ops; |
52c34561 | 553 | char hw[0] __aligned(sizeof(void *)); |
ab841160 OW |
554 | }; |
555 | ||
3870c320 TW |
556 | static inline unsigned long mei_secs_to_jiffies(unsigned long sec) |
557 | { | |
558 | return msecs_to_jiffies(sec * MSEC_PER_SEC); | |
559 | } | |
560 | ||
c8c8d080 TW |
561 | /** |
562 | * mei_data2slots - get slots - number of (dwords) from a message length | |
563 | * + size of the mei header | |
ce23139c | 564 | * |
a8605ea2 AU |
565 | * @length: size of the messages in bytes |
566 | * | |
567 | * Return: number of slots | |
c8c8d080 TW |
568 | */ |
569 | static inline u32 mei_data2slots(size_t length) | |
570 | { | |
571 | return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, 4); | |
572 | } | |
573 | ||
10ee9074 | 574 | /** |
ce23139c AU |
575 | * mei_slots2data - get data in slots - bytes from slots |
576 | * | |
a8605ea2 | 577 | * @slots: number of available slots |
ce23139c | 578 | * |
a8605ea2 | 579 | * Return: number of bytes in slots |
10ee9074 TW |
580 | */ |
581 | static inline u32 mei_slots2data(int slots) | |
582 | { | |
583 | return slots * 4; | |
584 | } | |
585 | ||
ab841160 OW |
586 | /* |
587 | * mei init function prototypes | |
588 | */ | |
3a7e9b6c TW |
589 | void mei_device_init(struct mei_device *dev, |
590 | struct device *device, | |
591 | const struct mei_hw_ops *hw_ops); | |
33ec0826 | 592 | int mei_reset(struct mei_device *dev); |
c4d589be | 593 | int mei_start(struct mei_device *dev); |
33ec0826 | 594 | int mei_restart(struct mei_device *dev); |
7cb035d9 | 595 | void mei_stop(struct mei_device *dev); |
dc844b0d | 596 | void mei_cancel_work(struct mei_device *dev); |
c95efb74 | 597 | |
c95efb74 TW |
598 | /* |
599 | * MEI interrupt functions prototype | |
ab841160 | 600 | */ |
06ecd645 | 601 | |
a61c6530 | 602 | void mei_timer(struct work_struct *work); |
06ecd645 TW |
603 | int mei_irq_read_handler(struct mei_device *dev, |
604 | struct mei_cl_cb *cmpl_list, s32 *slots); | |
605 | ||
606 | int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list); | |
4c6e22b8 | 607 | void mei_irq_compl_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list); |
ab841160 | 608 | |
19838fb8 TW |
609 | /* |
610 | * AMTHIF - AMT Host Interface Functions | |
611 | */ | |
612 | void mei_amthif_reset_params(struct mei_device *dev); | |
613 | ||
d49ed64a | 614 | int mei_amthif_host_init(struct mei_device *dev, struct mei_me_client *me_cl); |
19838fb8 | 615 | |
19838fb8 | 616 | int mei_amthif_read(struct mei_device *dev, struct file *file, |
744f0f2f TW |
617 | char __user *ubuf, size_t length, loff_t *offset); |
618 | ||
619 | unsigned int mei_amthif_poll(struct mei_device *dev, | |
620 | struct file *file, poll_table *wait); | |
ab841160 | 621 | |
a562d5c2 TW |
622 | int mei_amthif_release(struct mei_device *dev, struct file *file); |
623 | ||
19838fb8 | 624 | struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev, |
ab841160 OW |
625 | struct file *file); |
626 | ||
8660172e TW |
627 | int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb); |
628 | int mei_amthif_run_next_cmd(struct mei_device *dev); | |
9d098192 TW |
629 | int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, |
630 | struct mei_cl_cb *cmpl_list); | |
5ceb46e2 TW |
631 | |
632 | void mei_amthif_complete(struct mei_device *dev, struct mei_cl_cb *cb); | |
db4756fd | 633 | int mei_amthif_irq_read_msg(struct mei_cl *cl, |
5ceb46e2 TW |
634 | struct mei_msg_hdr *mei_hdr, |
635 | struct mei_cl_cb *complete_list); | |
636 | int mei_amthif_irq_read(struct mei_device *dev, s32 *slots); | |
637 | ||
59fcd7c6 SO |
638 | /* |
639 | * NFC functions | |
640 | */ | |
d49ed64a | 641 | int mei_nfc_host_init(struct mei_device *dev, struct mei_me_client *me_cl); |
dc844b0d | 642 | void mei_nfc_host_exit(struct mei_device *dev); |
59fcd7c6 SO |
643 | |
644 | /* | |
645 | * NFC Client UUID | |
646 | */ | |
647 | extern const uuid_le mei_nfc_guid; | |
19838fb8 | 648 | |
37e7d6e7 TW |
649 | int mei_wd_send(struct mei_device *dev); |
650 | int mei_wd_stop(struct mei_device *dev); | |
d49ed64a | 651 | int mei_wd_host_init(struct mei_device *dev, struct mei_me_client *me_cl); |
37e7d6e7 TW |
652 | /* |
653 | * mei_watchdog_register - Registering watchdog interface | |
654 | * once we got connection to the WD Client | |
a8605ea2 | 655 | * @dev: mei device |
37e7d6e7 | 656 | */ |
64092858 | 657 | int mei_watchdog_register(struct mei_device *dev); |
37e7d6e7 TW |
658 | /* |
659 | * mei_watchdog_unregister - Unregistering watchdog interface | |
a8605ea2 | 660 | * @dev: mei device |
37e7d6e7 TW |
661 | */ |
662 | void mei_watchdog_unregister(struct mei_device *dev); | |
663 | ||
ab841160 OW |
664 | /* |
665 | * Register Access Function | |
666 | */ | |
667 | ||
8d929d48 | 668 | |
827eef51 TW |
669 | static inline void mei_hw_config(struct mei_device *dev) |
670 | { | |
671 | dev->ops->hw_config(dev); | |
672 | } | |
ee7e5afd | 673 | |
964a2331 TW |
674 | static inline enum mei_pg_state mei_pg_state(struct mei_device *dev) |
675 | { | |
676 | return dev->ops->pg_state(dev); | |
677 | } | |
678 | ||
3dc196ea AU |
679 | static inline bool mei_pg_in_transition(struct mei_device *dev) |
680 | { | |
681 | return dev->ops->pg_in_transition(dev); | |
682 | } | |
683 | ||
ee7e5afd TW |
684 | static inline bool mei_pg_is_enabled(struct mei_device *dev) |
685 | { | |
686 | return dev->ops->pg_is_enabled(dev); | |
687 | } | |
688 | ||
c20c68d5 | 689 | static inline int mei_hw_reset(struct mei_device *dev, bool enable) |
827eef51 | 690 | { |
c20c68d5 | 691 | return dev->ops->hw_reset(dev, enable); |
827eef51 TW |
692 | } |
693 | ||
9049f793 | 694 | static inline int mei_hw_start(struct mei_device *dev) |
aafae7ec | 695 | { |
9049f793 | 696 | return dev->ops->hw_start(dev); |
aafae7ec TW |
697 | } |
698 | ||
827eef51 TW |
699 | static inline void mei_clear_interrupts(struct mei_device *dev) |
700 | { | |
701 | dev->ops->intr_clear(dev); | |
702 | } | |
703 | ||
704 | static inline void mei_enable_interrupts(struct mei_device *dev) | |
705 | { | |
706 | dev->ops->intr_enable(dev); | |
707 | } | |
ab841160 | 708 | |
827eef51 TW |
709 | static inline void mei_disable_interrupts(struct mei_device *dev) |
710 | { | |
711 | dev->ops->intr_disable(dev); | |
712 | } | |
ab841160 | 713 | |
827eef51 TW |
714 | static inline bool mei_host_is_ready(struct mei_device *dev) |
715 | { | |
716 | return dev->ops->host_is_ready(dev); | |
717 | } | |
718 | static inline bool mei_hw_is_ready(struct mei_device *dev) | |
719 | { | |
720 | return dev->ops->hw_is_ready(dev); | |
721 | } | |
e7e0c231 | 722 | |
827eef51 TW |
723 | static inline bool mei_hbuf_is_ready(struct mei_device *dev) |
724 | { | |
725 | return dev->ops->hbuf_is_ready(dev); | |
726 | } | |
ab841160 | 727 | |
827eef51 TW |
728 | static inline int mei_hbuf_empty_slots(struct mei_device *dev) |
729 | { | |
730 | return dev->ops->hbuf_free_slots(dev); | |
731 | } | |
115ba28c | 732 | |
827eef51 TW |
733 | static inline size_t mei_hbuf_max_len(const struct mei_device *dev) |
734 | { | |
735 | return dev->ops->hbuf_max_len(dev); | |
736 | } | |
3a65dd4e | 737 | |
827eef51 TW |
738 | static inline int mei_write_message(struct mei_device *dev, |
739 | struct mei_msg_hdr *hdr, | |
740 | unsigned char *buf) | |
741 | { | |
742 | return dev->ops->write(dev, hdr, buf); | |
743 | } | |
744 | ||
745 | static inline u32 mei_read_hdr(const struct mei_device *dev) | |
746 | { | |
747 | return dev->ops->read_hdr(dev); | |
748 | } | |
749 | ||
750 | static inline void mei_read_slots(struct mei_device *dev, | |
751 | unsigned char *buf, unsigned long len) | |
752 | { | |
753 | dev->ops->read(dev, buf, len); | |
754 | } | |
755 | ||
756 | static inline int mei_count_full_read_slots(struct mei_device *dev) | |
757 | { | |
758 | return dev->ops->rdbuf_full_slots(dev); | |
759 | } | |
5bd64714 | 760 | |
1bd30b6a TW |
761 | static inline int mei_fw_status(struct mei_device *dev, |
762 | struct mei_fw_status *fw_status) | |
763 | { | |
764 | return dev->ops->fw_status(dev, fw_status); | |
765 | } | |
04dd3661 | 766 | |
6aae48ff TW |
767 | bool mei_hbuf_acquire(struct mei_device *dev); |
768 | ||
a532bbed TW |
769 | bool mei_write_is_idle(struct mei_device *dev); |
770 | ||
30e53bb8 TW |
771 | #if IS_ENABLED(CONFIG_DEBUG_FS) |
772 | int mei_dbgfs_register(struct mei_device *dev, const char *name); | |
773 | void mei_dbgfs_deregister(struct mei_device *dev); | |
774 | #else | |
775 | static inline int mei_dbgfs_register(struct mei_device *dev, const char *name) | |
776 | { | |
777 | return 0; | |
778 | } | |
779 | static inline void mei_dbgfs_deregister(struct mei_device *dev) {} | |
780 | #endif /* CONFIG_DEBUG_FS */ | |
781 | ||
f3d8e878 | 782 | int mei_register(struct mei_device *dev, struct device *parent); |
30e53bb8 | 783 | void mei_deregister(struct mei_device *dev); |
2703d4b2 | 784 | |
479327fc | 785 | #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d internal=%1d comp=%1d" |
15d4acc5 TW |
786 | #define MEI_HDR_PRM(hdr) \ |
787 | (hdr)->host_addr, (hdr)->me_addr, \ | |
479327fc | 788 | (hdr)->length, (hdr)->internal, (hdr)->msg_complete |
15d4acc5 | 789 | |
edca5ea3 AU |
790 | ssize_t mei_fw_status2str(struct mei_fw_status *fw_sts, char *buf, size_t len); |
791 | /** | |
792 | * mei_fw_status_str - fetch and convert fw status registers to printable string | |
793 | * | |
794 | * @dev: the device structure | |
795 | * @buf: string buffer at minimal size MEI_FW_STATUS_STR_SZ | |
796 | * @len: buffer len must be >= MEI_FW_STATUS_STR_SZ | |
797 | * | |
798 | * Return: number of bytes written or < 0 on failure | |
799 | */ | |
800 | static inline ssize_t mei_fw_status_str(struct mei_device *dev, | |
801 | char *buf, size_t len) | |
802 | { | |
803 | struct mei_fw_status fw_status; | |
804 | int ret; | |
805 | ||
806 | buf[0] = '\0'; | |
807 | ||
808 | ret = mei_fw_status(dev, &fw_status); | |
809 | if (ret) | |
810 | return ret; | |
811 | ||
812 | ret = mei_fw_status2str(&fw_status, buf, MEI_FW_STATUS_STR_SZ); | |
813 | ||
814 | return ret; | |
815 | } | |
816 | ||
817 | ||
ab841160 | 818 | #endif |