xref: /openbmc/linux/drivers/misc/ibmvmc.h (revision 0545810f)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * linux/drivers/misc/ibmvmc.h
4  *
5  * IBM Power Systems Virtual Management Channel Support.
6  *
7  * Copyright (c) 2004, 2018 IBM Corp.
8  *   Dave Engebretsen engebret@us.ibm.com
9  *   Steven Royer seroyer@linux.vnet.ibm.com
10  *   Adam Reznechek adreznec@linux.vnet.ibm.com
11  *   Bryant G. Ly <bryantly@linux.vnet.ibm.com>
12  */
13 #ifndef IBMVMC_H
14 #define IBMVMC_H
15 
16 #include <linux/types.h>
17 #include <linux/cdev.h>
18 
19 #include <asm/vio.h>
20 
21 #define IBMVMC_PROTOCOL_VERSION    0x0101
22 
23 #define MIN_BUF_POOL_SIZE 16
24 #define MIN_HMCS          1
25 #define MIN_MTU           4096
26 #define MAX_BUF_POOL_SIZE 64
27 #define MAX_HMCS          2
28 #define MAX_MTU           (4 * 4096)
29 #define DEFAULT_BUF_POOL_SIZE 32
30 #define DEFAULT_HMCS          1
31 #define DEFAULT_MTU           4096
32 #define HMC_ID_LEN        32
33 
34 #define VMC_INVALID_BUFFER_ID 0xFFFF
35 
36 /* ioctl numbers */
37 #define VMC_BASE	     0xCC
38 #define VMC_IOCTL_SETHMCID   _IOW(VMC_BASE, 0x00, unsigned char *)
39 #define VMC_IOCTL_QUERY      _IOR(VMC_BASE, 0x01, struct ibmvmc_query_struct)
40 #define VMC_IOCTL_REQUESTVMC _IOR(VMC_BASE, 0x02, u32)
41 
42 #define VMC_MSG_CAP          0x01
43 #define VMC_MSG_CAP_RESP     0x81
44 #define VMC_MSG_OPEN         0x02
45 #define VMC_MSG_OPEN_RESP    0x82
46 #define VMC_MSG_CLOSE        0x03
47 #define VMC_MSG_CLOSE_RESP   0x83
48 #define VMC_MSG_ADD_BUF      0x04
49 #define VMC_MSG_ADD_BUF_RESP 0x84
50 #define VMC_MSG_REM_BUF      0x05
51 #define VMC_MSG_REM_BUF_RESP 0x85
52 #define VMC_MSG_SIGNAL       0x06
53 
54 #define VMC_MSG_SUCCESS 0
55 #define VMC_MSG_INVALID_HMC_INDEX 1
56 #define VMC_MSG_INVALID_BUFFER_ID 2
57 #define VMC_MSG_CLOSED_HMC        3
58 #define VMC_MSG_INTERFACE_FAILURE 4
59 #define VMC_MSG_NO_BUFFER         5
60 
61 #define VMC_BUF_OWNER_ALPHA 0
62 #define VMC_BUF_OWNER_HV    1
63 
64 enum ibmvmc_states {
65 	ibmvmc_state_sched_reset  = -1,
66 	ibmvmc_state_initial      = 0,
67 	ibmvmc_state_crqinit      = 1,
68 	ibmvmc_state_capabilities = 2,
69 	ibmvmc_state_ready        = 3,
70 	ibmvmc_state_failed       = 4,
71 };
72 
73 enum ibmhmc_states {
74 	/* HMC connection not established */
75 	ibmhmc_state_free    = 0,
76 
77 	/* HMC connection established (open called) */
78 	ibmhmc_state_initial = 1,
79 
80 	/* open msg sent to HV, due to ioctl(1) call */
81 	ibmhmc_state_opening = 2,
82 
83 	/* HMC connection ready, open resp msg from HV */
84 	ibmhmc_state_ready   = 3,
85 
86 	/* HMC connection failure */
87 	ibmhmc_state_failed  = 4,
88 };
89 
90 struct ibmvmc_buffer {
91 	u8 valid;	/* 1 when DMA storage allocated to buffer          */
92 	u8 free;	/* 1 when buffer available for the Alpha Partition */
93 	u8 owner;
94 	u16 id;
95 	u32 size;
96 	u32 msg_len;
97 	dma_addr_t dma_addr_local;
98 	dma_addr_t dma_addr_remote;
99 	void *real_addr_local;
100 };
101 
102 struct ibmvmc_admin_crq_msg {
103 	u8 valid;	/* RPA Defined           */
104 	u8 type;	/* ibmvmc msg type       */
105 	u8 status;	/* Response msg status. Zero is success and on failure,
106 			 * either 1 - General Failure, or 2 - Invalid Version is
107 			 * returned.
108 			 */
109 	u8 rsvd[2];
110 	u8 max_hmc;	/* Max # of independent HMC connections supported */
111 	__be16 pool_size;	/* Maximum number of buffers supported per HMC
112 				 * connection
113 				 */
114 	__be32 max_mtu;		/* Maximum message size supported (bytes) */
115 	__be16 crq_size;	/* # of entries available in the CRQ for the
116 				 * source partition. The target partition must
117 				 * limit the number of outstanding messages to
118 				 * one half or less.
119 				 */
120 	__be16 version;	/* Indicates the code level of the management partition
121 			 * or the hypervisor with the high-order byte
122 			 * indicating a major version and the low-order byte
123 			 * indicating a minor version.
124 			 */
125 };
126 
127 struct ibmvmc_crq_msg {
128 	u8 valid;     /* RPA Defined           */
129 	u8 type;      /* ibmvmc msg type       */
130 	u8 status;    /* Response msg status   */
131 	union {
132 		u8 rsvd;  /* Reserved              */
133 		u8 owner;
134 	} var1;
135 	u8 hmc_session;	/* Session Identifier for the current VMC connection */
136 	u8 hmc_index;	/* A unique HMC Idx would be used if multiple management
137 			 * applications running concurrently were desired
138 			 */
139 	union {
140 		__be16 rsvd;
141 		__be16 buffer_id;
142 	} var2;
143 	__be32 rsvd;
144 	union {
145 		__be32 rsvd;
146 		__be32 lioba;
147 		__be32 msg_len;
148 	} var3;
149 };
150 
151 /* an RPA command/response transport queue */
152 struct crq_queue {
153 	struct ibmvmc_crq_msg *msgs;
154 	int size, cur;
155 	dma_addr_t msg_token;
156 	spinlock_t lock;
157 };
158 
159 /* VMC server adapter settings */
160 struct crq_server_adapter {
161 	struct device *dev;
162 	struct crq_queue queue;
163 	u32 liobn;
164 	u32 riobn;
165 	struct tasklet_struct work_task;
166 	wait_queue_head_t reset_wait_queue;
167 	struct task_struct *reset_task;
168 };
169 
170 /* Driver wide settings */
171 struct ibmvmc_struct {
172 	u32 state;
173 	u32 max_mtu;
174 	u32 max_buffer_pool_size;
175 	u32 max_hmc_index;
176 	struct crq_server_adapter *adapter;
177 	struct cdev cdev;
178 	u32 vmc_drc_index;
179 };
180 
181 struct ibmvmc_file_session;
182 
183 /* Connection specific settings */
184 struct ibmvmc_hmc {
185 	u8 session;
186 	u8 index;
187 	u32 state;
188 	struct crq_server_adapter *adapter;
189 	spinlock_t lock;
190 	unsigned char hmc_id[HMC_ID_LEN];
191 	struct ibmvmc_buffer buffer[MAX_BUF_POOL_SIZE];
192 	unsigned short queue_outbound_msgs[MAX_BUF_POOL_SIZE];
193 	int queue_head, queue_tail;
194 	struct ibmvmc_file_session *file_session;
195 };
196 
197 struct ibmvmc_file_session {
198 	struct file *file;
199 	struct ibmvmc_hmc *hmc;
200 	bool valid;
201 };
202 
203 struct ibmvmc_query_struct {
204 	int have_vmc;
205 	int state;
206 	int vmc_drc_index;
207 };
208 
209 #endif /* __IBMVMC_H */
210