xref: /OK3568_Linux_fs/kernel/drivers/misc/ibmasm/dot_command.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * IBM ASM Service Processor Device Driver
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) IBM Corporation, 2004
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Author: Max Asböck <amax@us.ibm.com>
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #ifndef __DOT_COMMAND_H__
11*4882a593Smuzhiyun #define __DOT_COMMAND_H__
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun /*
14*4882a593Smuzhiyun  * dot commands are the protocol used to communicate with the service
15*4882a593Smuzhiyun  * processor.
16*4882a593Smuzhiyun  * They consist of header, a command of variable length and data of
17*4882a593Smuzhiyun  * variable length.
18*4882a593Smuzhiyun  */
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun /* dot command types */
21*4882a593Smuzhiyun #define sp_write		0
22*4882a593Smuzhiyun #define sp_write_next		1
23*4882a593Smuzhiyun #define sp_read			2
24*4882a593Smuzhiyun #define sp_read_next		3
25*4882a593Smuzhiyun #define sp_command_response	4
26*4882a593Smuzhiyun #define sp_event		5
27*4882a593Smuzhiyun #define sp_heartbeat		6
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #pragma pack(1)
30*4882a593Smuzhiyun struct dot_command_header {
31*4882a593Smuzhiyun 	u8	type;
32*4882a593Smuzhiyun 	u8	command_size;
33*4882a593Smuzhiyun 	u16	data_size;
34*4882a593Smuzhiyun 	u8	status;
35*4882a593Smuzhiyun 	u8	reserved;
36*4882a593Smuzhiyun };
37*4882a593Smuzhiyun #pragma pack()
38*4882a593Smuzhiyun 
get_dot_command_size(void * buffer)39*4882a593Smuzhiyun static inline size_t get_dot_command_size(void *buffer)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun 	struct dot_command_header *cmd = (struct dot_command_header *)buffer;
42*4882a593Smuzhiyun 	return sizeof(struct dot_command_header) + cmd->command_size + cmd->data_size;
43*4882a593Smuzhiyun }
44*4882a593Smuzhiyun 
get_dot_command_timeout(void * buffer)45*4882a593Smuzhiyun static inline unsigned int get_dot_command_timeout(void *buffer)
46*4882a593Smuzhiyun {
47*4882a593Smuzhiyun 	struct dot_command_header *header = (struct dot_command_header *)buffer;
48*4882a593Smuzhiyun 	unsigned char *cmd = buffer + sizeof(struct dot_command_header);
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun 	/* dot commands 6.3.1, 7.1 and 8.x need a longer timeout */
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun 	if (header->command_size == 3) {
53*4882a593Smuzhiyun 		if ((cmd[0] == 6) && (cmd[1] == 3) && (cmd[2] == 1))
54*4882a593Smuzhiyun 			return IBMASM_CMD_TIMEOUT_EXTRA;
55*4882a593Smuzhiyun 	} else if (header->command_size == 2) {
56*4882a593Smuzhiyun 		if ((cmd[0] == 7) && (cmd[1] == 1))
57*4882a593Smuzhiyun 			return IBMASM_CMD_TIMEOUT_EXTRA;
58*4882a593Smuzhiyun 		if (cmd[0] == 8)
59*4882a593Smuzhiyun 			return IBMASM_CMD_TIMEOUT_EXTRA;
60*4882a593Smuzhiyun 	}
61*4882a593Smuzhiyun 	return IBMASM_CMD_TIMEOUT_NORMAL;
62*4882a593Smuzhiyun }
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun #endif /* __DOT_COMMAND_H__ */
65