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