xref: /freebsd/sys/dev/mpr/mpr_ioctl.h (revision 0e97acdf58fe27b09c4824a474b0344daf997c5f)
1 /*-
2  * Copyright (c) 2008 Yahoo!, Inc.
3  * All rights reserved.
4  * Written by: John Baldwin <jhb@FreeBSD.org>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the author nor the names of any co-contributors
15  *    may be used to endorse or promote products derived from this software
16  *    without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  * LSI MPT-Fusion Host Adapter FreeBSD userland interface
31  *
32  * $FreeBSD$
33  */
34 /*-
35  * Copyright (c) 2011-2014 LSI Corp.
36  * All rights reserved.
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  *
47  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
48  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
51  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57  * SUCH DAMAGE.
58  *
59  * LSI MPT-Fusion Host Adapter FreeBSD
60  *
61  * $FreeBSD$
62  */
63 
64 #ifndef _MPR_IOCTL_H_
65 #define	_MPR_IOCTL_H_
66 
67 #include <dev/mpr/mpi/mpi2_type.h>
68 #include <dev/mpr/mpi/mpi2.h>
69 #include <dev/mpr/mpi/mpi2_cnfg.h>
70 #include <dev/mpr/mpi/mpi2_sas.h>
71 
72 /*
73  * For the read header requests, the header should include the page
74  * type or extended page type, page number, and page version.  The
75  * buffer and length are unused.  The completed header is returned in
76  * the 'header' member.
77  *
78  * For the read page and write page requests, 'buf' should point to a
79  * buffer of 'len' bytes which holds the entire page (including the
80  * header).
81  *
82  * All requests specify the page address in 'page_address'.
83  */
84 struct mpr_cfg_page_req {
85 	MPI2_CONFIG_PAGE_HEADER header;
86 	uint32_t page_address;
87 	void	*buf;
88 	int	len;
89 	uint16_t ioc_status;
90 };
91 
92 struct mpr_ext_cfg_page_req {
93 	MPI2_CONFIG_EXTENDED_PAGE_HEADER header;
94 	uint32_t page_address;
95 	void	*buf;
96 	int	len;
97 	uint16_t ioc_status;
98 };
99 
100 struct mpr_raid_action {
101 	uint8_t action;
102 	uint8_t volume_bus;
103 	uint8_t volume_id;
104 	uint8_t phys_disk_num;
105 	uint32_t action_data_word;
106 	void *buf;
107 	int len;
108 	uint32_t volume_status;
109 	uint32_t action_data[4];
110 	uint16_t action_status;
111 	uint16_t ioc_status;
112 	uint8_t write;
113 };
114 
115 struct mpr_usr_command {
116 	void *req;
117 	uint32_t req_len;
118 	void *rpl;
119 	uint32_t rpl_len;
120 	void *buf;
121 	int len;
122 	uint32_t flags;
123 };
124 
125 typedef struct mpr_pci_bits
126 {
127 	union {
128 		struct {
129 			uint32_t	DeviceNumber	:5;
130 			uint32_t	FunctionNumber	:3;
131 			uint32_t	BusNumber	:24;
132 		} bits;
133 		uint32_t	AsDWORD;
134 	} u;
135 	uint32_t	PciSegmentId;
136 } mpr_pci_bits_t;
137 
138 /*
139  *  The following is the MPRIOCTL_GET_ADAPTER_DATA data structure.  This data
140  *  structure is setup so that we hopefully are properly aligned for both
141  *  32-bit and 64-bit mode applications.
142  *
143  *  Adapter Type - Value = 6 = SCSI Protocol through SAS-3 adapter
144  *
145  *  MPI Port Number - The PCI Function number for this device
146  *
147  *  PCI Device HW Id - The PCI device number for this device
148  *
149  */
150 #define	MPRIOCTL_ADAPTER_TYPE_SAS3		6
151 typedef struct mpr_adapter_data
152 {
153 	uint32_t	StructureLength;
154 	uint32_t	AdapterType;
155 	uint32_t	MpiPortNumber;
156 	uint32_t	PCIDeviceHwId;
157 	uint32_t	PCIDeviceHwRev;
158 	uint32_t	SubSystemId;
159 	uint32_t	SubsystemVendorId;
160 	uint32_t	Reserved1;
161 	uint32_t	MpiFirmwareVersion;
162 	uint32_t	BiosVersion;
163 	uint8_t		DriverVersion[32];
164 	uint8_t		Reserved2;
165 	uint8_t		ScsiId;
166 	uint16_t	Reserved3;
167 	mpr_pci_bits_t	PciInformation;
168 } mpr_adapter_data_t;
169 
170 
171 typedef struct mpr_update_flash
172 {
173 	uint64_t	PtrBuffer;
174 	uint32_t	ImageChecksum;
175 	uint32_t	ImageOffset;
176 	uint32_t	ImageSize;
177 	uint32_t	ImageType;
178 } mpr_update_flash_t;
179 
180 
181 #define	MPR_PASS_THRU_DIRECTION_NONE	0
182 #define	MPR_PASS_THRU_DIRECTION_READ	1
183 #define	MPR_PASS_THRU_DIRECTION_WRITE	2
184 #define	MPR_PASS_THRU_DIRECTION_BOTH	3
185 
186 typedef struct mpr_pass_thru
187 {
188 	uint64_t	PtrRequest;
189 	uint64_t	PtrReply;
190 	uint64_t	PtrData;
191 	uint32_t	RequestSize;
192 	uint32_t	ReplySize;
193 	uint32_t	DataSize;
194 	uint32_t	DataDirection;
195 	uint64_t	PtrDataOut;
196 	uint32_t	DataOutSize;
197 	uint32_t	Timeout;
198 } mpr_pass_thru_t;
199 
200 
201 /*
202  * Event queue defines
203  */
204 #define	MPR_EVENT_QUEUE_SIZE		(50) /* Max Events stored in driver */
205 #define	MPR_MAX_EVENT_DATA_LENGTH	(48) /* Size of each event in Dwords */
206 
207 typedef struct mpr_event_query
208 {
209 	uint16_t	Entries;
210 	uint16_t	Reserved;
211 	uint32_t	Types[4];
212 } mpr_event_query_t;
213 
214 typedef struct mpr_event_enable
215 {
216 	uint32_t	Types[4];
217 } mpr_event_enable_t;
218 
219 /*
220  * Event record entry for ioctl.
221  */
222 typedef struct mpr_event_entry
223 {
224 	uint32_t	Type;
225 	uint32_t	Number;
226 	uint32_t	Data[MPR_MAX_EVENT_DATA_LENGTH];
227 } mpr_event_entry_t;
228 
229 typedef struct mpr_event_report
230 {
231 	uint32_t	Size;
232 	uint64_t	PtrEvents;
233 } mpr_event_report_t;
234 
235 
236 typedef struct mpr_pci_info
237 {
238 	uint32_t	BusNumber;
239 	uint8_t		DeviceNumber;
240 	uint8_t		FunctionNumber;
241 	uint16_t	InterruptVector;
242 	uint8_t		PciHeader[256];
243 } mpr_pci_info_t;
244 
245 
246 typedef struct mpr_diag_action
247 {
248 	uint32_t	Action;
249 	uint32_t	Length;
250 	uint64_t	PtrDiagAction;
251 	uint32_t	ReturnCode;
252 } mpr_diag_action_t;
253 
254 #define	MPR_FW_DIAGNOSTIC_UID_NOT_FOUND	(0xFF)
255 
256 #define	MPR_FW_DIAG_NEW				(0x806E6577)
257 
258 #define	MPR_FW_DIAG_TYPE_REGISTER		(0x00000001)
259 #define	MPR_FW_DIAG_TYPE_UNREGISTER		(0x00000002)
260 #define	MPR_FW_DIAG_TYPE_QUERY			(0x00000003)
261 #define	MPR_FW_DIAG_TYPE_READ_BUFFER		(0x00000004)
262 #define	MPR_FW_DIAG_TYPE_RELEASE		(0x00000005)
263 
264 #define	MPR_FW_DIAG_INVALID_UID			(0x00000000)
265 
266 #define MPR_DIAG_SUCCESS			0
267 #define MPR_DIAG_FAILURE			1
268 
269 #define	MPR_FW_DIAG_ERROR_SUCCESS		(0x00000000)
270 #define	MPR_FW_DIAG_ERROR_FAILURE		(0x00000001)
271 #define	MPR_FW_DIAG_ERROR_INVALID_PARAMETER	(0x00000002)
272 #define	MPR_FW_DIAG_ERROR_POST_FAILED		(0x00000010)
273 #define	MPR_FW_DIAG_ERROR_INVALID_UID		(0x00000011)
274 #define	MPR_FW_DIAG_ERROR_RELEASE_FAILED	(0x00000012)
275 #define	MPR_FW_DIAG_ERROR_NO_BUFFER		(0x00000013)
276 #define	MPR_FW_DIAG_ERROR_ALREADY_RELEASED	(0x00000014)
277 
278 
279 typedef struct mpr_fw_diag_register
280 {
281 	uint8_t		ExtendedType;
282 	uint8_t		BufferType;
283 	uint16_t	ApplicationFlags;
284 	uint32_t	DiagnosticFlags;
285 	uint32_t	ProductSpecific[23];
286 	uint32_t	RequestedBufferSize;
287 	uint32_t	UniqueId;
288 } mpr_fw_diag_register_t;
289 
290 typedef struct mpr_fw_diag_unregister
291 {
292 	uint32_t	UniqueId;
293 } mpr_fw_diag_unregister_t;
294 
295 #define	MPR_FW_DIAG_FLAG_APP_OWNED		(0x0001)
296 #define	MPR_FW_DIAG_FLAG_BUFFER_VALID		(0x0002)
297 #define	MPR_FW_DIAG_FLAG_FW_BUFFER_ACCESS	(0x0004)
298 
299 typedef struct mpr_fw_diag_query
300 {
301 	uint8_t		ExtendedType;
302 	uint8_t		BufferType;
303 	uint16_t	ApplicationFlags;
304 	uint32_t	DiagnosticFlags;
305 	uint32_t	ProductSpecific[23];
306 	uint32_t	TotalBufferSize;
307 	uint32_t	DriverAddedBufferSize;
308 	uint32_t	UniqueId;
309 } mpr_fw_diag_query_t;
310 
311 typedef struct mpr_fw_diag_release
312 {
313 	uint32_t	UniqueId;
314 } mpr_fw_diag_release_t;
315 
316 #define	MPR_FW_DIAG_FLAG_REREGISTER	(0x0001)
317 #define	MPR_FW_DIAG_FLAG_FORCE_RELEASE	(0x0002)
318 
319 typedef struct mpr_diag_read_buffer
320 {
321 	uint8_t		Status;
322 	uint8_t		Reserved;
323 	uint16_t	Flags;
324 	uint32_t	StartingOffset;
325 	uint32_t	BytesToRead;
326 	uint32_t	UniqueId;
327 	uint64_t	PtrDataBuffer;
328 } mpr_diag_read_buffer_t;
329 
330 /*
331  * Register Access
332  */
333 #define	REG_IO_READ	1
334 #define	REG_IO_WRITE	2
335 #define	REG_MEM_READ	3
336 #define	REG_MEM_WRITE	4
337 
338 typedef struct mpr_reg_access
339 {
340 	uint32_t	Command;
341 	uint32_t	RegOffset;
342 	uint32_t	RegData;
343 } mpr_reg_access_t;
344 
345 typedef struct mpr_btdh_mapping
346 {
347 	uint16_t	TargetID;
348 	uint16_t	Bus;
349 	uint16_t	DevHandle;
350 	uint16_t	Reserved;
351 } mpr_btdh_mapping_t;
352 
353 #define MPRIO_MPR_COMMAND_FLAG_VERBOSE	0x01
354 #define MPRIO_MPR_COMMAND_FLAG_DEBUG	0x02
355 #define	MPRIO_READ_CFG_HEADER	_IOWR('M', 200, struct mpr_cfg_page_req)
356 #define	MPRIO_READ_CFG_PAGE	_IOWR('M', 201, struct mpr_cfg_page_req)
357 #define	MPRIO_READ_EXT_CFG_HEADER _IOWR('M', 202, struct mpr_ext_cfg_page_req)
358 #define	MPRIO_READ_EXT_CFG_PAGE	_IOWR('M', 203, struct mpr_ext_cfg_page_req)
359 #define	MPRIO_WRITE_CFG_PAGE	_IOWR('M', 204, struct mpr_cfg_page_req)
360 #define	MPRIO_RAID_ACTION	_IOWR('M', 205, struct mpr_raid_action)
361 #define	MPRIO_MPR_COMMAND	_IOWR('M', 210, struct mpr_usr_command)
362 
363 #define	MPTIOCTL			('I')
364 #define	MPTIOCTL_GET_ADAPTER_DATA	_IOWR(MPTIOCTL, 1,\
365     struct mpr_adapter_data)
366 #define	MPTIOCTL_UPDATE_FLASH		_IOWR(MPTIOCTL, 2,\
367     struct mpr_update_flash)
368 #define	MPTIOCTL_RESET_ADAPTER		_IO(MPTIOCTL, 3)
369 #define	MPTIOCTL_PASS_THRU		_IOWR(MPTIOCTL, 4,\
370     struct mpr_pass_thru)
371 #define	MPTIOCTL_EVENT_QUERY		_IOWR(MPTIOCTL, 5,\
372     struct mpr_event_query)
373 #define	MPTIOCTL_EVENT_ENABLE		_IOWR(MPTIOCTL, 6,\
374     struct mpr_event_enable)
375 #define	MPTIOCTL_EVENT_REPORT		_IOWR(MPTIOCTL, 7,\
376     struct mpr_event_report)
377 #define	MPTIOCTL_GET_PCI_INFO		_IOWR(MPTIOCTL, 8,\
378     struct mpr_pci_info)
379 #define	MPTIOCTL_DIAG_ACTION		_IOWR(MPTIOCTL, 9,\
380     struct mpr_diag_action)
381 #define	MPTIOCTL_REG_ACCESS		_IOWR(MPTIOCTL, 10,\
382     struct mpr_reg_access)
383 #define	MPTIOCTL_BTDH_MAPPING		_IOWR(MPTIOCTL, 11,\
384     struct mpr_btdh_mapping)
385 
386 #endif /* !_MPR_IOCTL_H_ */
387