xref: /freebsd/sys/dev/mps/mps_ioctl.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2008 Yahoo!, Inc.
5  * All rights reserved.
6  * Written by: John Baldwin <jhb@FreeBSD.org>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the author nor the names of any co-contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  * Avago Technologies (LSI) MPT-Fusion Host Adapter FreeBSD userland interface
33  */
34 /*-
35  * Copyright (c) 2011-2015 LSI Corp.
36  * Copyright (c) 2013-2015 Avago Technologies
37  * All rights reserved.
38  *
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions
41  * are met:
42  * 1. Redistributions of source code must retain the above copyright
43  *    notice, this list of conditions and the following disclaimer.
44  * 2. Redistributions in binary form must reproduce the above copyright
45  *    notice, this list of conditions and the following disclaimer in the
46  *    documentation and/or other materials provided with the distribution.
47  *
48  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
49  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
52  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58  * SUCH DAMAGE.
59  *
60  * Avago Technologies (LSI) MPT-Fusion Host Adapter FreeBSD
61  */
62 
63 #ifndef _MPS_IOCTL_H_
64 #define	_MPS_IOCTL_H_
65 
66 #include <dev/mps/mpi/mpi2_type.h>
67 #include <dev/mps/mpi/mpi2.h>
68 #include <dev/mps/mpi/mpi2_cnfg.h>
69 #include <dev/mps/mpi/mpi2_sas.h>
70 
71 /*
72  * For the read header requests, the header should include the page
73  * type or extended page type, page number, and page version.  The
74  * buffer and length are unused.  The completed header is returned in
75  * the 'header' member.
76  *
77  * For the read page and write page requests, 'buf' should point to a
78  * buffer of 'len' bytes which holds the entire page (including the
79  * header).
80  *
81  * All requests specify the page address in 'page_address'.
82  */
83 struct mps_cfg_page_req {
84 	MPI2_CONFIG_PAGE_HEADER header;
85 	uint32_t page_address;
86 	void	*buf;
87 	int	len;
88 	uint16_t ioc_status;
89 };
90 
91 struct mps_ext_cfg_page_req {
92 	MPI2_CONFIG_EXTENDED_PAGE_HEADER header;
93 	uint32_t page_address;
94 	void	*buf;
95 	int	len;
96 	uint16_t ioc_status;
97 };
98 
99 struct mps_raid_action {
100 	uint8_t action;
101 	uint8_t volume_bus;
102 	uint8_t volume_id;
103 	uint8_t phys_disk_num;
104 	uint32_t action_data_word;
105 	void *buf;
106 	int len;
107 	uint32_t volume_status;
108 	uint32_t action_data[4];
109 	uint16_t action_status;
110 	uint16_t ioc_status;
111 	uint8_t write;
112 };
113 
114 struct mps_usr_command {
115 	void *req;
116 	uint32_t req_len;
117 	void *rpl;
118 	uint32_t rpl_len;
119 	void *buf;
120 	int len;
121 	uint32_t flags;
122 };
123 
124 typedef struct mps_pci_bits
125 {
126 	union {
127 		struct {
128 			uint32_t	DeviceNumber	:5;
129 			uint32_t	FunctionNumber	:3;
130 			uint32_t	BusNumber	:24;
131 		} bits;
132 		uint32_t	AsDWORD;
133 	} u;
134 	uint32_t	PciSegmentId;
135 } mps_pci_bits_t;
136 
137 /*
138  *  The following is the MPSIOCTL_GET_ADAPTER_DATA data structure.  This data
139  *  structure is setup so that we hopefully are properly aligned for both
140  *  32-bit and 64-bit mode applications.
141  *
142  *  Adapter Type - Value = 4 = SCSI Protocol through SAS-2 adapter
143  *
144  *  MPI Port Number - The PCI Function number for this device
145  *
146  *  PCI Device HW Id - The PCI device number for this device
147  *
148  */
149 #define	MPSIOCTL_ADAPTER_TYPE_SAS2		4
150 #define	MPSIOCTL_ADAPTER_TYPE_SAS2_SSS6200	5
151 typedef struct mps_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 	mps_pci_bits_t	PciInformation;
168 } mps_adapter_data_t;
169 
170 typedef struct mps_update_flash
171 {
172 	uint64_t	PtrBuffer;
173 	uint32_t	ImageChecksum;
174 	uint32_t	ImageOffset;
175 	uint32_t	ImageSize;
176 	uint32_t	ImageType;
177 } mps_update_flash_t;
178 
179 #define	MPS_PASS_THRU_DIRECTION_NONE	0
180 #define	MPS_PASS_THRU_DIRECTION_READ	1
181 #define	MPS_PASS_THRU_DIRECTION_WRITE	2
182 #define	MPS_PASS_THRU_DIRECTION_BOTH	3
183 
184 typedef struct mps_pass_thru
185 {
186 	uint64_t	PtrRequest;
187 	uint64_t	PtrReply;
188 	uint64_t	PtrData;
189 	uint32_t	RequestSize;
190 	uint32_t	ReplySize;
191 	uint32_t	DataSize;
192 	uint32_t	DataDirection;
193 	uint64_t	PtrDataOut;
194 	uint32_t	DataOutSize;
195 	uint32_t	Timeout;
196 } mps_pass_thru_t;
197 
198 /*
199  * Event queue defines
200  */
201 #define	MPS_EVENT_QUEUE_SIZE		(50) /* Max Events stored in driver */
202 #define	MPS_MAX_EVENT_DATA_LENGTH	(48) /* Size of each event in Dwords */
203 
204 typedef struct mps_event_query
205 {
206 	uint16_t	Entries;
207 	uint16_t	Reserved;
208 	uint32_t	Types[4];
209 } mps_event_query_t;
210 
211 typedef struct mps_event_enable
212 {
213 	uint32_t	Types[4];
214 } mps_event_enable_t;
215 
216 /*
217  * Event record entry for ioctl.
218  */
219 typedef struct mps_event_entry
220 {
221 	uint32_t	Type;
222 	uint32_t	Number;
223 	uint32_t	Data[MPS_MAX_EVENT_DATA_LENGTH];
224 } mps_event_entry_t;
225 
226 typedef struct mps_event_report
227 {
228 	uint32_t	Size;
229 	uint64_t	PtrEvents;
230 } mps_event_report_t;
231 
232 typedef struct mps_pci_info
233 {
234 	uint32_t	BusNumber;
235 	uint8_t		DeviceNumber;
236 	uint8_t		FunctionNumber;
237 	uint16_t	InterruptVector;
238 	uint8_t		PciHeader[256];
239 } mps_pci_info_t;
240 
241 typedef struct mps_diag_action
242 {
243 	uint32_t	Action;
244 	uint32_t	Length;
245 	uint64_t	PtrDiagAction;
246 	uint32_t	ReturnCode;
247 } mps_diag_action_t;
248 
249 #define	MPS_FW_DIAGNOSTIC_UID_NOT_FOUND	(0xFF)
250 
251 #define	MPS_FW_DIAG_NEW				(0x806E6577)
252 
253 #define	MPS_FW_DIAG_TYPE_REGISTER		(0x00000001)
254 #define	MPS_FW_DIAG_TYPE_UNREGISTER		(0x00000002)
255 #define	MPS_FW_DIAG_TYPE_QUERY			(0x00000003)
256 #define	MPS_FW_DIAG_TYPE_READ_BUFFER		(0x00000004)
257 #define	MPS_FW_DIAG_TYPE_RELEASE		(0x00000005)
258 
259 #define	MPS_FW_DIAG_INVALID_UID			(0x00000000)
260 
261 #define MPS_DIAG_SUCCESS			0
262 #define MPS_DIAG_FAILURE			1
263 
264 #define	MPS_FW_DIAG_ERROR_SUCCESS		(0x00000000)
265 #define	MPS_FW_DIAG_ERROR_FAILURE		(0x00000001)
266 #define	MPS_FW_DIAG_ERROR_INVALID_PARAMETER	(0x00000002)
267 #define	MPS_FW_DIAG_ERROR_POST_FAILED		(0x00000010)
268 #define	MPS_FW_DIAG_ERROR_INVALID_UID		(0x00000011)
269 #define	MPS_FW_DIAG_ERROR_RELEASE_FAILED	(0x00000012)
270 #define	MPS_FW_DIAG_ERROR_NO_BUFFER		(0x00000013)
271 #define	MPS_FW_DIAG_ERROR_ALREADY_RELEASED	(0x00000014)
272 
273 typedef struct mps_fw_diag_register
274 {
275 	uint8_t		ExtendedType;
276 	uint8_t		BufferType;
277 	uint16_t	ApplicationFlags;
278 	uint32_t	DiagnosticFlags;
279 	uint32_t	ProductSpecific[23];
280 	uint32_t	RequestedBufferSize;
281 	uint32_t	UniqueId;
282 } mps_fw_diag_register_t;
283 
284 typedef struct mps_fw_diag_unregister
285 {
286 	uint32_t	UniqueId;
287 } mps_fw_diag_unregister_t;
288 
289 #define	MPS_FW_DIAG_FLAG_APP_OWNED		(0x0001)
290 #define	MPS_FW_DIAG_FLAG_BUFFER_VALID		(0x0002)
291 #define	MPS_FW_DIAG_FLAG_FW_BUFFER_ACCESS	(0x0004)
292 
293 typedef struct mps_fw_diag_query
294 {
295 	uint8_t		ExtendedType;
296 	uint8_t		BufferType;
297 	uint16_t	ApplicationFlags;
298 	uint32_t	DiagnosticFlags;
299 	uint32_t	ProductSpecific[23];
300 	uint32_t	TotalBufferSize;
301 	uint32_t	DriverAddedBufferSize;
302 	uint32_t	UniqueId;
303 } mps_fw_diag_query_t;
304 
305 typedef struct mps_fw_diag_release
306 {
307 	uint32_t	UniqueId;
308 } mps_fw_diag_release_t;
309 
310 #define	MPS_FW_DIAG_FLAG_REREGISTER	(0x0001)
311 #define	MPS_FW_DIAG_FLAG_FORCE_RELEASE	(0x0002)
312 
313 typedef struct mps_diag_read_buffer
314 {
315 	uint8_t		Status;
316 	uint8_t		Reserved;
317 	uint16_t	Flags;
318 	uint32_t	StartingOffset;
319 	uint32_t	BytesToRead;
320 	uint32_t	UniqueId;
321 	uint64_t	PtrDataBuffer;
322 } mps_diag_read_buffer_t;
323 
324 /*
325  * Register Access
326  */
327 #define	REG_IO_READ	1
328 #define	REG_IO_WRITE	2
329 #define	REG_MEM_READ	3
330 #define	REG_MEM_WRITE	4
331 
332 typedef struct mps_reg_access
333 {
334 	uint32_t	Command;
335 	uint32_t	RegOffset;
336 	uint32_t	RegData;
337 } mps_reg_access_t;
338 
339 typedef struct mps_btdh_mapping
340 {
341 	uint16_t	TargetID;
342 	uint16_t	Bus;
343 	uint16_t	DevHandle;
344 	uint16_t	Reserved;
345 } mps_btdh_mapping_t;
346 
347 #define MPSIO_MPS_COMMAND_FLAG_VERBOSE	0x01
348 #define MPSIO_MPS_COMMAND_FLAG_DEBUG	0x02
349 #define	MPSIO_READ_CFG_HEADER	_IOWR('M', 200, struct mps_cfg_page_req)
350 #define	MPSIO_READ_CFG_PAGE	_IOWR('M', 201, struct mps_cfg_page_req)
351 #define	MPSIO_READ_EXT_CFG_HEADER _IOWR('M', 202, struct mps_ext_cfg_page_req)
352 #define	MPSIO_READ_EXT_CFG_PAGE	_IOWR('M', 203, struct mps_ext_cfg_page_req)
353 #define	MPSIO_WRITE_CFG_PAGE	_IOWR('M', 204, struct mps_cfg_page_req)
354 #define	MPSIO_RAID_ACTION	_IOWR('M', 205, struct mps_raid_action)
355 #define	MPSIO_MPS_COMMAND	_IOWR('M', 210, struct mps_usr_command)
356 
357 #ifndef MPTIOCTL
358 #define	MPTIOCTL			('I')
359 #define	MPTIOCTL_GET_ADAPTER_DATA	_IOWR(MPTIOCTL, 1,\
360     struct mps_adapter_data)
361 #define	MPTIOCTL_UPDATE_FLASH		_IOWR(MPTIOCTL, 2,\
362     struct mps_update_flash)
363 #define	MPTIOCTL_RESET_ADAPTER		_IO(MPTIOCTL, 3)
364 #define	MPTIOCTL_PASS_THRU		_IOWR(MPTIOCTL, 4,\
365     struct mps_pass_thru)
366 #define	MPTIOCTL_EVENT_QUERY		_IOWR(MPTIOCTL, 5,\
367     struct mps_event_query)
368 #define	MPTIOCTL_EVENT_ENABLE		_IOWR(MPTIOCTL, 6,\
369     struct mps_event_enable)
370 #define	MPTIOCTL_EVENT_REPORT		_IOWR(MPTIOCTL, 7,\
371     struct mps_event_report)
372 #define	MPTIOCTL_GET_PCI_INFO		_IOWR(MPTIOCTL, 8,\
373     struct mps_pci_info)
374 #define	MPTIOCTL_DIAG_ACTION		_IOWR(MPTIOCTL, 9,\
375     struct mps_diag_action)
376 #define	MPTIOCTL_REG_ACCESS		_IOWR(MPTIOCTL, 10,\
377     struct mps_reg_access)
378 #define	MPTIOCTL_BTDH_MAPPING		_IOWR(MPTIOCTL, 11,\
379     struct mps_btdh_mapping)
380 #endif /* MPTIOCTL */
381 
382 #endif /* !_MPS_IOCTL_H_ */
383