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