xref: /linux/drivers/char/ipmi/kcs_bmc.h (revision faae6e391eda73a5b9870c78349064282a625bfa)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2015-2018, Intel Corporation.
4  */
5 
6 #ifndef __KCS_BMC_H__
7 #define __KCS_BMC_H__
8 
9 #include <linux/miscdevice.h>
10 
11 #include "kcs_bmc_client.h"
12 
13 #define KCS_BMC_STR_OBF		BIT(0)
14 #define KCS_BMC_STR_IBF		BIT(1)
15 #define KCS_BMC_STR_CMD_DAT	BIT(3)
16 
17 /* Different phases of the KCS BMC module.
18  *  KCS_PHASE_IDLE:
19  *            BMC should not be expecting nor sending any data.
20  *  KCS_PHASE_WRITE_START:
21  *            BMC is receiving a WRITE_START command from system software.
22  *  KCS_PHASE_WRITE_DATA:
23  *            BMC is receiving a data byte from system software.
24  *  KCS_PHASE_WRITE_END_CMD:
25  *            BMC is waiting a last data byte from system software.
26  *  KCS_PHASE_WRITE_DONE:
27  *            BMC has received the whole request from system software.
28  *  KCS_PHASE_WAIT_READ:
29  *            BMC is waiting the response from the upper IPMI service.
30  *  KCS_PHASE_READ:
31  *            BMC is transferring the response to system software.
32  *  KCS_PHASE_ABORT_ERROR1:
33  *            BMC is waiting error status request from system software.
34  *  KCS_PHASE_ABORT_ERROR2:
35  *            BMC is waiting for idle status afer error from system software.
36  *  KCS_PHASE_ERROR:
37  *            BMC has detected a protocol violation at the interface level.
38  */
39 enum kcs_phases {
40 	KCS_PHASE_IDLE,
41 
42 	KCS_PHASE_WRITE_START,
43 	KCS_PHASE_WRITE_DATA,
44 	KCS_PHASE_WRITE_END_CMD,
45 	KCS_PHASE_WRITE_DONE,
46 
47 	KCS_PHASE_WAIT_READ,
48 	KCS_PHASE_READ,
49 
50 	KCS_PHASE_ABORT_ERROR1,
51 	KCS_PHASE_ABORT_ERROR2,
52 	KCS_PHASE_ERROR
53 };
54 
55 /* IPMI 2.0 - Table 9-4, KCS Interface Status Codes */
56 enum kcs_errors {
57 	KCS_NO_ERROR                = 0x00,
58 	KCS_ABORTED_BY_COMMAND      = 0x01,
59 	KCS_ILLEGAL_CONTROL_CODE    = 0x02,
60 	KCS_LENGTH_ERROR            = 0x06,
61 	KCS_UNSPECIFIED_ERROR       = 0xFF
62 };
63 
64 /* IPMI 2.0 - 9.5, KCS Interface Registers
65  * @idr: Input Data Register
66  * @odr: Output Data Register
67  * @str: Status Register
68  */
69 struct kcs_ioreg {
70 	u32 idr;
71 	u32 odr;
72 	u32 str;
73 };
74 
75 struct kcs_bmc_device_ops;
76 
77 struct kcs_bmc {
78 	struct device *dev;
79 
80 	const struct kcs_bmc_device_ops *ops;
81 
82 	struct kcs_bmc_client client;
83 
84 	spinlock_t lock;
85 
86 	u32 channel;
87 	int running;
88 
89 	struct kcs_ioreg ioreg;
90 
91 	enum kcs_phases phase;
92 	enum kcs_errors error;
93 
94 	wait_queue_head_t queue;
95 	bool data_in_avail;
96 	int  data_in_idx;
97 	u8  *data_in;
98 
99 	int  data_out_idx;
100 	int  data_out_len;
101 	u8  *data_out;
102 
103 	struct mutex mutex;
104 	u8 *kbuffer;
105 
106 	struct miscdevice miscdev;
107 };
108 #endif /* __KCS_BMC_H__ */
109