xref: /kernel/linux/linux-5.10/drivers/misc/mei/hw.h (revision 8c2ecf20)
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (c) 2003-2020, Intel Corporation. All rights reserved
4 * Intel Management Engine Interface (Intel MEI) Linux driver
5 */
6
7#ifndef _MEI_HW_TYPES_H_
8#define _MEI_HW_TYPES_H_
9
10#include <linux/uuid.h>
11
12/*
13 * Timeouts in Seconds
14 */
15#define MEI_HW_READY_TIMEOUT        2  /* Timeout on ready message */
16#define MEI_CONNECT_TIMEOUT         3  /* HPS: at least 2 seconds */
17
18#define MEI_CL_CONNECT_TIMEOUT     15  /* HPS: Client Connect Timeout */
19#define MEI_CLIENTS_INIT_TIMEOUT   15  /* HPS: Clients Enumeration Timeout */
20
21#define MEI_PGI_TIMEOUT             1  /* PG Isolation time response 1 sec */
22#define MEI_D0I3_TIMEOUT            5  /* D0i3 set/unset max response time */
23#define MEI_HBM_TIMEOUT             1  /* 1 second */
24
25/*
26 * MEI Version
27 */
28#define HBM_MINOR_VERSION                   2
29#define HBM_MAJOR_VERSION                   2
30
31/*
32 * MEI version with PGI support
33 */
34#define HBM_MINOR_VERSION_PGI               1
35#define HBM_MAJOR_VERSION_PGI               1
36
37/*
38 * MEI version with Dynamic clients support
39 */
40#define HBM_MINOR_VERSION_DC               0
41#define HBM_MAJOR_VERSION_DC               2
42
43/*
44 * MEI version with immediate reply to enum request support
45 */
46#define HBM_MINOR_VERSION_IE               0
47#define HBM_MAJOR_VERSION_IE               2
48
49/*
50 * MEI version with disconnect on connection timeout support
51 */
52#define HBM_MINOR_VERSION_DOT              0
53#define HBM_MAJOR_VERSION_DOT              2
54
55/*
56 * MEI version with notification support
57 */
58#define HBM_MINOR_VERSION_EV               0
59#define HBM_MAJOR_VERSION_EV               2
60
61/*
62 * MEI version with fixed address client support
63 */
64#define HBM_MINOR_VERSION_FA               0
65#define HBM_MAJOR_VERSION_FA               2
66
67/*
68 * MEI version with OS ver message support
69 */
70#define HBM_MINOR_VERSION_OS               0
71#define HBM_MAJOR_VERSION_OS               2
72
73/*
74 * MEI version with dma ring support
75 */
76#define HBM_MINOR_VERSION_DR               1
77#define HBM_MAJOR_VERSION_DR               2
78
79/*
80 * MEI version with vm tag support
81 */
82#define HBM_MINOR_VERSION_VT               2
83#define HBM_MAJOR_VERSION_VT               2
84
85/*
86 * MEI version with capabilities message support
87 */
88#define HBM_MINOR_VERSION_CAP              2
89#define HBM_MAJOR_VERSION_CAP              2
90
91/* Host bus message command opcode */
92#define MEI_HBM_CMD_OP_MSK                  0x7f
93/* Host bus message command RESPONSE */
94#define MEI_HBM_CMD_RES_MSK                 0x80
95
96/*
97 * MEI Bus Message Command IDs
98 */
99#define HOST_START_REQ_CMD                  0x01
100#define HOST_START_RES_CMD                  0x81
101
102#define HOST_STOP_REQ_CMD                   0x02
103#define HOST_STOP_RES_CMD                   0x82
104
105#define ME_STOP_REQ_CMD                     0x03
106
107#define HOST_ENUM_REQ_CMD                   0x04
108#define HOST_ENUM_RES_CMD                   0x84
109
110#define HOST_CLIENT_PROPERTIES_REQ_CMD      0x05
111#define HOST_CLIENT_PROPERTIES_RES_CMD      0x85
112
113#define CLIENT_CONNECT_REQ_CMD              0x06
114#define CLIENT_CONNECT_RES_CMD              0x86
115
116#define CLIENT_DISCONNECT_REQ_CMD           0x07
117#define CLIENT_DISCONNECT_RES_CMD           0x87
118
119#define MEI_FLOW_CONTROL_CMD                0x08
120
121#define MEI_PG_ISOLATION_ENTRY_REQ_CMD      0x0a
122#define MEI_PG_ISOLATION_ENTRY_RES_CMD      0x8a
123#define MEI_PG_ISOLATION_EXIT_REQ_CMD       0x0b
124#define MEI_PG_ISOLATION_EXIT_RES_CMD       0x8b
125
126#define MEI_HBM_ADD_CLIENT_REQ_CMD          0x0f
127#define MEI_HBM_ADD_CLIENT_RES_CMD          0x8f
128
129#define MEI_HBM_NOTIFY_REQ_CMD              0x10
130#define MEI_HBM_NOTIFY_RES_CMD              0x90
131#define MEI_HBM_NOTIFICATION_CMD            0x11
132
133#define MEI_HBM_DMA_SETUP_REQ_CMD           0x12
134#define MEI_HBM_DMA_SETUP_RES_CMD           0x92
135
136#define MEI_HBM_CAPABILITIES_REQ_CMD        0x13
137#define MEI_HBM_CAPABILITIES_RES_CMD        0x93
138
139/*
140 * MEI Stop Reason
141 * used by hbm_host_stop_request.reason
142 */
143enum mei_stop_reason_types {
144	DRIVER_STOP_REQUEST = 0x00,
145	DEVICE_D1_ENTRY = 0x01,
146	DEVICE_D2_ENTRY = 0x02,
147	DEVICE_D3_ENTRY = 0x03,
148	SYSTEM_S1_ENTRY = 0x04,
149	SYSTEM_S2_ENTRY = 0x05,
150	SYSTEM_S3_ENTRY = 0x06,
151	SYSTEM_S4_ENTRY = 0x07,
152	SYSTEM_S5_ENTRY = 0x08
153};
154
155
156/**
157 * enum mei_hbm_status  - mei host bus messages return values
158 *
159 * @MEI_HBMS_SUCCESS           : status success
160 * @MEI_HBMS_CLIENT_NOT_FOUND  : client not found
161 * @MEI_HBMS_ALREADY_EXISTS    : connection already established
162 * @MEI_HBMS_REJECTED          : connection is rejected
163 * @MEI_HBMS_INVALID_PARAMETER : invalid parameter
164 * @MEI_HBMS_NOT_ALLOWED       : operation not allowed
165 * @MEI_HBMS_ALREADY_STARTED   : system is already started
166 * @MEI_HBMS_NOT_STARTED       : system not started
167 *
168 * @MEI_HBMS_MAX               : sentinel
169 */
170enum mei_hbm_status {
171	MEI_HBMS_SUCCESS           = 0,
172	MEI_HBMS_CLIENT_NOT_FOUND  = 1,
173	MEI_HBMS_ALREADY_EXISTS    = 2,
174	MEI_HBMS_REJECTED          = 3,
175	MEI_HBMS_INVALID_PARAMETER = 4,
176	MEI_HBMS_NOT_ALLOWED       = 5,
177	MEI_HBMS_ALREADY_STARTED   = 6,
178	MEI_HBMS_NOT_STARTED       = 7,
179
180	MEI_HBMS_MAX
181};
182
183
184/*
185 * Client Connect Status
186 * used by hbm_client_connect_response.status
187 */
188enum mei_cl_connect_status {
189	MEI_CL_CONN_SUCCESS          = MEI_HBMS_SUCCESS,
190	MEI_CL_CONN_NOT_FOUND        = MEI_HBMS_CLIENT_NOT_FOUND,
191	MEI_CL_CONN_ALREADY_STARTED  = MEI_HBMS_ALREADY_EXISTS,
192	MEI_CL_CONN_OUT_OF_RESOURCES = MEI_HBMS_REJECTED,
193	MEI_CL_CONN_MESSAGE_SMALL    = MEI_HBMS_INVALID_PARAMETER,
194	MEI_CL_CONN_NOT_ALLOWED      = MEI_HBMS_NOT_ALLOWED,
195};
196
197/*
198 * Client Disconnect Status
199 */
200enum mei_cl_disconnect_status {
201	MEI_CL_DISCONN_SUCCESS = MEI_HBMS_SUCCESS
202};
203
204/**
205 * enum mei_ext_hdr_type - extended header type used in
206 *    extended header TLV
207 *
208 * @MEI_EXT_HDR_NONE: sentinel
209 * @MEI_EXT_HDR_VTAG: vtag header
210 */
211enum mei_ext_hdr_type {
212	MEI_EXT_HDR_NONE = 0,
213	MEI_EXT_HDR_VTAG = 1,
214};
215
216/**
217 * struct mei_ext_hdr - extend header descriptor (TLV)
218 * @type: enum mei_ext_hdr_type
219 * @length: length excluding descriptor
220 * @ext_payload: payload of the specific extended header
221 * @hdr: place holder for actual header
222 */
223struct mei_ext_hdr {
224	u8 type;
225	u8 length;
226	u8 ext_payload[2];
227	u8 hdr[];
228};
229
230/**
231 * struct mei_ext_meta_hdr - extend header meta data
232 * @count: number of headers
233 * @size: total size of the extended header list excluding meta header
234 * @reserved: reserved
235 * @hdrs: extended headers TLV list
236 */
237struct mei_ext_meta_hdr {
238	u8 count;
239	u8 size;
240	u8 reserved[2];
241	struct mei_ext_hdr hdrs[];
242};
243
244/*
245 * Extended header iterator functions
246 */
247/**
248 * mei_ext_hdr - extended header iterator begin
249 *
250 * @meta: meta header of the extended header list
251 *
252 * Return:
253 *     The first extended header
254 */
255static inline struct mei_ext_hdr *mei_ext_begin(struct mei_ext_meta_hdr *meta)
256{
257	return meta->hdrs;
258}
259
260/**
261 * mei_ext_last - check if the ext is the last one in the TLV list
262 *
263 * @meta: meta header of the extended header list
264 * @ext: a meta header on the list
265 *
266 * Return: true if ext is the last header on the list
267 */
268static inline bool mei_ext_last(struct mei_ext_meta_hdr *meta,
269				struct mei_ext_hdr *ext)
270{
271	return (u8 *)ext >= (u8 *)meta + sizeof(*meta) + (meta->size * 4);
272}
273
274/**
275 *mei_ext_next - following extended header on the TLV list
276 *
277 * @ext: current extend header
278 *
279 * Context: The function does not check for the overflows,
280 *          one should call mei_ext_last before.
281 *
282 * Return: The following extend header after @ext
283 */
284static inline struct mei_ext_hdr *mei_ext_next(struct mei_ext_hdr *ext)
285{
286	return (struct mei_ext_hdr *)(ext->hdr + (ext->length * 4));
287}
288
289/**
290 * struct mei_msg_hdr - MEI BUS Interface Section
291 *
292 * @me_addr: device address
293 * @host_addr: host address
294 * @length: message length
295 * @reserved: reserved
296 * @extended: message has extended header
297 * @dma_ring: message is on dma ring
298 * @internal: message is internal
299 * @msg_complete: last packet of the message
300 * @extension: extension of the header
301 */
302struct mei_msg_hdr {
303	u32 me_addr:8;
304	u32 host_addr:8;
305	u32 length:9;
306	u32 reserved:3;
307	u32 extended:1;
308	u32 dma_ring:1;
309	u32 internal:1;
310	u32 msg_complete:1;
311	u32 extension[];
312} __packed;
313
314/* The length is up to 9 bits */
315#define MEI_MSG_MAX_LEN_MASK GENMASK(9, 0)
316
317struct mei_bus_message {
318	u8 hbm_cmd;
319	u8 data[];
320} __packed;
321
322/**
323 * struct hbm_cl_cmd - client specific host bus command
324 *	CONNECT, DISCONNECT, and FlOW CONTROL
325 *
326 * @hbm_cmd: bus message command header
327 * @me_addr: address of the client in ME
328 * @host_addr: address of the client in the driver
329 * @data: generic data
330 */
331struct mei_hbm_cl_cmd {
332	u8 hbm_cmd;
333	u8 me_addr;
334	u8 host_addr;
335	u8 data;
336};
337
338struct hbm_version {
339	u8 minor_version;
340	u8 major_version;
341} __packed;
342
343struct hbm_host_version_request {
344	u8 hbm_cmd;
345	u8 reserved;
346	struct hbm_version host_version;
347} __packed;
348
349struct hbm_host_version_response {
350	u8 hbm_cmd;
351	u8 host_version_supported;
352	struct hbm_version me_max_version;
353} __packed;
354
355struct hbm_host_stop_request {
356	u8 hbm_cmd;
357	u8 reason;
358	u8 reserved[2];
359} __packed;
360
361struct hbm_host_stop_response {
362	u8 hbm_cmd;
363	u8 reserved[3];
364} __packed;
365
366struct hbm_me_stop_request {
367	u8 hbm_cmd;
368	u8 reason;
369	u8 reserved[2];
370} __packed;
371
372/**
373 * enum hbm_host_enum_flags - enumeration request flags (HBM version >= 2.0)
374 *
375 * @MEI_HBM_ENUM_F_ALLOW_ADD: allow dynamic clients add
376 * @MEI_HBM_ENUM_F_IMMEDIATE_ENUM: allow FW to send answer immediately
377 */
378enum hbm_host_enum_flags {
379	MEI_HBM_ENUM_F_ALLOW_ADD = BIT(0),
380	MEI_HBM_ENUM_F_IMMEDIATE_ENUM = BIT(1),
381};
382
383/**
384 * struct hbm_host_enum_request - enumeration request from host to fw
385 *
386 * @hbm_cmd : bus message command header
387 * @flags   : request flags
388 * @reserved: reserved
389 */
390struct hbm_host_enum_request {
391	u8 hbm_cmd;
392	u8 flags;
393	u8 reserved[2];
394} __packed;
395
396struct hbm_host_enum_response {
397	u8 hbm_cmd;
398	u8 reserved[3];
399	u8 valid_addresses[32];
400} __packed;
401
402/**
403 * struct mei_client_properties - mei client properties
404 *
405 * @protocol_name: guid of the client
406 * @protocol_version: client protocol version
407 * @max_number_of_connections: number of possible connections.
408 * @fixed_address: fixed me address (0 if the client is dynamic)
409 * @single_recv_buf: 1 if all connections share a single receive buffer.
410 * @vt_supported: the client support vtag
411 * @reserved: reserved
412 * @max_msg_length: MTU of the client
413 */
414struct mei_client_properties {
415	uuid_le protocol_name;
416	u8 protocol_version;
417	u8 max_number_of_connections;
418	u8 fixed_address;
419	u8 single_recv_buf:1;
420	u8 vt_supported:1;
421	u8 reserved:6;
422	u32 max_msg_length;
423} __packed;
424
425struct hbm_props_request {
426	u8 hbm_cmd;
427	u8 me_addr;
428	u8 reserved[2];
429} __packed;
430
431struct hbm_props_response {
432	u8 hbm_cmd;
433	u8 me_addr;
434	u8 status;
435	u8 reserved;
436	struct mei_client_properties client_properties;
437} __packed;
438
439/**
440 * struct hbm_add_client_request - request to add a client
441 *     might be sent by fw after enumeration has already completed
442 *
443 * @hbm_cmd: bus message command header
444 * @me_addr: address of the client in ME
445 * @reserved: reserved
446 * @client_properties: client properties
447 */
448struct hbm_add_client_request {
449	u8 hbm_cmd;
450	u8 me_addr;
451	u8 reserved[2];
452	struct mei_client_properties client_properties;
453} __packed;
454
455/**
456 * struct hbm_add_client_response - response to add a client
457 *     sent by the host to report client addition status to fw
458 *
459 * @hbm_cmd: bus message command header
460 * @me_addr: address of the client in ME
461 * @status: if HBMS_SUCCESS then the client can now accept connections.
462 * @reserved: reserved
463 */
464struct hbm_add_client_response {
465	u8 hbm_cmd;
466	u8 me_addr;
467	u8 status;
468	u8 reserved;
469} __packed;
470
471/**
472 * struct hbm_power_gate - power gate request/response
473 *
474 * @hbm_cmd: bus message command header
475 * @reserved: reserved
476 */
477struct hbm_power_gate {
478	u8 hbm_cmd;
479	u8 reserved[3];
480} __packed;
481
482/**
483 * struct hbm_client_connect_request - connect/disconnect request
484 *
485 * @hbm_cmd: bus message command header
486 * @me_addr: address of the client in ME
487 * @host_addr: address of the client in the driver
488 * @reserved: reserved
489 */
490struct hbm_client_connect_request {
491	u8 hbm_cmd;
492	u8 me_addr;
493	u8 host_addr;
494	u8 reserved;
495} __packed;
496
497/**
498 * struct hbm_client_connect_response - connect/disconnect response
499 *
500 * @hbm_cmd: bus message command header
501 * @me_addr: address of the client in ME
502 * @host_addr: address of the client in the driver
503 * @status: status of the request
504 */
505struct hbm_client_connect_response {
506	u8 hbm_cmd;
507	u8 me_addr;
508	u8 host_addr;
509	u8 status;
510} __packed;
511
512
513#define MEI_FC_MESSAGE_RESERVED_LENGTH           5
514
515struct hbm_flow_control {
516	u8 hbm_cmd;
517	u8 me_addr;
518	u8 host_addr;
519	u8 reserved[MEI_FC_MESSAGE_RESERVED_LENGTH];
520} __packed;
521
522#define MEI_HBM_NOTIFICATION_START 1
523#define MEI_HBM_NOTIFICATION_STOP  0
524/**
525 * struct hbm_notification_request - start/stop notification request
526 *
527 * @hbm_cmd: bus message command header
528 * @me_addr: address of the client in ME
529 * @host_addr: address of the client in the driver
530 * @start:  start = 1 or stop = 0 asynchronous notifications
531 */
532struct hbm_notification_request {
533	u8 hbm_cmd;
534	u8 me_addr;
535	u8 host_addr;
536	u8 start;
537} __packed;
538
539/**
540 * struct hbm_notification_response - start/stop notification response
541 *
542 * @hbm_cmd: bus message command header
543 * @me_addr: address of the client in ME
544 * @host_addr: - address of the client in the driver
545 * @status: (mei_hbm_status) response status for the request
546 *  - MEI_HBMS_SUCCESS: successful stop/start
547 *  - MEI_HBMS_CLIENT_NOT_FOUND: if the connection could not be found.
548 *  - MEI_HBMS_ALREADY_STARTED: for start requests for a previously
549 *                         started notification.
550 *  - MEI_HBMS_NOT_STARTED: for stop request for a connected client for whom
551 *                         asynchronous notifications are currently disabled.
552 *
553 * @start:  start = 1 or stop = 0 asynchronous notifications
554 * @reserved: reserved
555 */
556struct hbm_notification_response {
557	u8 hbm_cmd;
558	u8 me_addr;
559	u8 host_addr;
560	u8 status;
561	u8 start;
562	u8 reserved[3];
563} __packed;
564
565/**
566 * struct hbm_notification - notification event
567 *
568 * @hbm_cmd: bus message command header
569 * @me_addr:  address of the client in ME
570 * @host_addr:  address of the client in the driver
571 * @reserved: reserved for alignment
572 */
573struct hbm_notification {
574	u8 hbm_cmd;
575	u8 me_addr;
576	u8 host_addr;
577	u8 reserved;
578} __packed;
579
580/**
581 * struct hbm_dma_mem_dscr - dma ring
582 *
583 * @addr_hi: the high 32bits of 64 bit address
584 * @addr_lo: the low  32bits of 64 bit address
585 * @size   : size in bytes (must be power of 2)
586 */
587struct hbm_dma_mem_dscr {
588	u32 addr_hi;
589	u32 addr_lo;
590	u32 size;
591} __packed;
592
593enum {
594	DMA_DSCR_HOST = 0,
595	DMA_DSCR_DEVICE = 1,
596	DMA_DSCR_CTRL = 2,
597	DMA_DSCR_NUM,
598};
599
600/**
601 * struct hbm_dma_setup_request - dma setup request
602 *
603 * @hbm_cmd: bus message command header
604 * @reserved: reserved for alignment
605 * @dma_dscr: dma descriptor for HOST, DEVICE, and CTRL
606 */
607struct hbm_dma_setup_request {
608	u8 hbm_cmd;
609	u8 reserved[3];
610	struct hbm_dma_mem_dscr dma_dscr[DMA_DSCR_NUM];
611} __packed;
612
613/**
614 * struct hbm_dma_setup_response - dma setup response
615 *
616 * @hbm_cmd: bus message command header
617 * @status: 0 on success; otherwise DMA setup failed.
618 * @reserved: reserved for alignment
619 */
620struct hbm_dma_setup_response {
621	u8 hbm_cmd;
622	u8 status;
623	u8 reserved[2];
624} __packed;
625
626/**
627 * struct mei_dma_ring_ctrl - dma ring control block
628 *
629 * @hbuf_wr_idx: host circular buffer write index in slots
630 * @reserved1: reserved for alignment
631 * @hbuf_rd_idx: host circular buffer read index in slots
632 * @reserved2: reserved for alignment
633 * @dbuf_wr_idx: device circular buffer write index in slots
634 * @reserved3: reserved for alignment
635 * @dbuf_rd_idx: device circular buffer read index in slots
636 * @reserved4: reserved for alignment
637 */
638struct hbm_dma_ring_ctrl {
639	u32 hbuf_wr_idx;
640	u32 reserved1;
641	u32 hbuf_rd_idx;
642	u32 reserved2;
643	u32 dbuf_wr_idx;
644	u32 reserved3;
645	u32 dbuf_rd_idx;
646	u32 reserved4;
647} __packed;
648
649/* virtual tag supported */
650#define HBM_CAP_VT BIT(0)
651
652/**
653 * struct hbm_capability_request - capability request from host to fw
654 *
655 * @hbm_cmd : bus message command header
656 * @capability_requested: bitmask of capabilities requested by host
657 */
658struct hbm_capability_request {
659	u8 hbm_cmd;
660	u8 capability_requested[3];
661} __packed;
662
663/**
664 * struct hbm_capability_response - capability response from fw to host
665 *
666 * @hbm_cmd : bus message command header
667 * @capability_granted: bitmask of capabilities granted by FW
668 */
669struct hbm_capability_response {
670	u8 hbm_cmd;
671	u8 capability_granted[3];
672} __packed;
673
674#endif
675