xref: /freebsd/sys/dev/mpr/mpr_ioctl.h (revision 732a02b4e77866604a120a275c082bb6221bd2ff)
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 
174 typedef struct mpr_update_flash
175 {
176 	uint64_t	PtrBuffer;
177 	uint32_t	ImageChecksum;
178 	uint32_t	ImageOffset;
179 	uint32_t	ImageSize;
180 	uint32_t	ImageType;
181 } mpr_update_flash_t;
182 
183 
184 #define	MPR_PASS_THRU_DIRECTION_NONE	0
185 #define	MPR_PASS_THRU_DIRECTION_READ	1
186 #define	MPR_PASS_THRU_DIRECTION_WRITE	2
187 #define	MPR_PASS_THRU_DIRECTION_BOTH	3
188 
189 typedef struct mpr_pass_thru
190 {
191 	uint64_t	PtrRequest;
192 	uint64_t	PtrReply;
193 	uint64_t	PtrData;
194 	uint32_t	RequestSize;
195 	uint32_t	ReplySize;
196 	uint32_t	DataSize;
197 	uint32_t	DataDirection;
198 	uint64_t	PtrDataOut;
199 	uint32_t	DataOutSize;
200 	uint32_t	Timeout;
201 } mpr_pass_thru_t;
202 
203 
204 /*
205  * Event queue defines
206  */
207 #define	MPR_EVENT_QUEUE_SIZE		(200) /* Max Events stored in driver */
208 #define	MPR_MAX_EVENT_DATA_LENGTH	(48) /* Size of each event in Dwords */
209 
210 typedef struct mpr_event_query
211 {
212 	uint16_t	Entries;
213 	uint16_t	Reserved;
214 	uint32_t	Types[4];
215 } mpr_event_query_t;
216 
217 typedef struct mpr_event_enable
218 {
219 	uint32_t	Types[4];
220 } mpr_event_enable_t;
221 
222 /*
223  * Event record entry for ioctl.
224  */
225 typedef struct mpr_event_entry
226 {
227 	uint32_t	Type;
228 	uint32_t	Number;
229 	uint32_t	Data[MPR_MAX_EVENT_DATA_LENGTH];
230 } mpr_event_entry_t;
231 
232 typedef struct mpr_event_report
233 {
234 	uint32_t	Size;
235 	uint64_t	PtrEvents;
236 } mpr_event_report_t;
237 
238 
239 typedef struct mpr_pci_info
240 {
241 	uint32_t	BusNumber;
242 	uint8_t		DeviceNumber;
243 	uint8_t		FunctionNumber;
244 	uint16_t	InterruptVector;
245 	uint8_t		PciHeader[256];
246 } mpr_pci_info_t;
247 
248 
249 typedef struct mpr_diag_action
250 {
251 	uint32_t	Action;
252 	uint32_t	Length;
253 	uint64_t	PtrDiagAction;
254 	uint32_t	ReturnCode;
255 } mpr_diag_action_t;
256 
257 #define	MPR_FW_DIAGNOSTIC_UID_NOT_FOUND	(0xFF)
258 
259 #define	MPR_FW_DIAG_NEW				(0x806E6577)
260 
261 #define	MPR_FW_DIAG_TYPE_REGISTER		(0x00000001)
262 #define	MPR_FW_DIAG_TYPE_UNREGISTER		(0x00000002)
263 #define	MPR_FW_DIAG_TYPE_QUERY			(0x00000003)
264 #define	MPR_FW_DIAG_TYPE_READ_BUFFER		(0x00000004)
265 #define	MPR_FW_DIAG_TYPE_RELEASE		(0x00000005)
266 
267 #define	MPR_FW_DIAG_INVALID_UID			(0x00000000)
268 
269 #define MPR_DIAG_SUCCESS			0
270 #define MPR_DIAG_FAILURE			1
271 
272 #define	MPR_FW_DIAG_ERROR_SUCCESS		(0x00000000)
273 #define	MPR_FW_DIAG_ERROR_FAILURE		(0x00000001)
274 #define	MPR_FW_DIAG_ERROR_INVALID_PARAMETER	(0x00000002)
275 #define	MPR_FW_DIAG_ERROR_POST_FAILED		(0x00000010)
276 #define	MPR_FW_DIAG_ERROR_INVALID_UID		(0x00000011)
277 #define	MPR_FW_DIAG_ERROR_RELEASE_FAILED	(0x00000012)
278 #define	MPR_FW_DIAG_ERROR_NO_BUFFER		(0x00000013)
279 #define	MPR_FW_DIAG_ERROR_ALREADY_RELEASED	(0x00000014)
280 
281 
282 typedef struct mpr_fw_diag_register
283 {
284 	uint8_t		ExtendedType;
285 	uint8_t		BufferType;
286 	uint16_t	ApplicationFlags;
287 	uint32_t	DiagnosticFlags;
288 	uint32_t	ProductSpecific[23];
289 	uint32_t	RequestedBufferSize;
290 	uint32_t	UniqueId;
291 } mpr_fw_diag_register_t;
292 
293 typedef struct mpr_fw_diag_unregister
294 {
295 	uint32_t	UniqueId;
296 } mpr_fw_diag_unregister_t;
297 
298 #define	MPR_FW_DIAG_FLAG_APP_OWNED		(0x0001)
299 #define	MPR_FW_DIAG_FLAG_BUFFER_VALID		(0x0002)
300 #define	MPR_FW_DIAG_FLAG_FW_BUFFER_ACCESS	(0x0004)
301 
302 typedef struct mpr_fw_diag_query
303 {
304 	uint8_t		ExtendedType;
305 	uint8_t		BufferType;
306 	uint16_t	ApplicationFlags;
307 	uint32_t	DiagnosticFlags;
308 	uint32_t	ProductSpecific[23];
309 	uint32_t	TotalBufferSize;
310 	uint32_t	DriverAddedBufferSize;
311 	uint32_t	UniqueId;
312 } mpr_fw_diag_query_t;
313 
314 typedef struct mpr_fw_diag_release
315 {
316 	uint32_t	UniqueId;
317 } mpr_fw_diag_release_t;
318 
319 #define	MPR_FW_DIAG_FLAG_REREGISTER	(0x0001)
320 #define	MPR_FW_DIAG_FLAG_FORCE_RELEASE	(0x0002)
321 
322 typedef struct mpr_diag_read_buffer
323 {
324 	uint8_t		Status;
325 	uint8_t		Reserved;
326 	uint16_t	Flags;
327 	uint32_t	StartingOffset;
328 	uint32_t	BytesToRead;
329 	uint32_t	UniqueId;
330 	uint64_t	PtrDataBuffer;
331 } mpr_diag_read_buffer_t;
332 
333 /*
334  * Register Access
335  */
336 #define	REG_IO_READ	1
337 #define	REG_IO_WRITE	2
338 #define	REG_MEM_READ	3
339 #define	REG_MEM_WRITE	4
340 
341 typedef struct mpr_reg_access
342 {
343 	uint32_t	Command;
344 	uint32_t	RegOffset;
345 	uint32_t	RegData;
346 } mpr_reg_access_t;
347 
348 typedef struct mpr_btdh_mapping
349 {
350 	uint16_t	TargetID;
351 	uint16_t	Bus;
352 	uint16_t	DevHandle;
353 	uint16_t	Reserved;
354 } mpr_btdh_mapping_t;
355 
356 #define MPRIO_MPR_COMMAND_FLAG_VERBOSE	0x01
357 #define MPRIO_MPR_COMMAND_FLAG_DEBUG	0x02
358 #define	MPRIO_READ_CFG_HEADER	_IOWR('M', 200, struct mpr_cfg_page_req)
359 #define	MPRIO_READ_CFG_PAGE	_IOWR('M', 201, struct mpr_cfg_page_req)
360 #define	MPRIO_READ_EXT_CFG_HEADER _IOWR('M', 202, struct mpr_ext_cfg_page_req)
361 #define	MPRIO_READ_EXT_CFG_PAGE	_IOWR('M', 203, struct mpr_ext_cfg_page_req)
362 #define	MPRIO_WRITE_CFG_PAGE	_IOWR('M', 204, struct mpr_cfg_page_req)
363 #define	MPRIO_RAID_ACTION	_IOWR('M', 205, struct mpr_raid_action)
364 #define	MPRIO_MPR_COMMAND	_IOWR('M', 210, struct mpr_usr_command)
365 
366 #ifndef MPTIOCTL
367 #define	MPTIOCTL			('I')
368 #define	MPTIOCTL_GET_ADAPTER_DATA	_IOWR(MPTIOCTL, 1,\
369     struct mpr_adapter_data)
370 #define	MPTIOCTL_UPDATE_FLASH		_IOWR(MPTIOCTL, 2,\
371     struct mpr_update_flash)
372 #define	MPTIOCTL_RESET_ADAPTER		_IO(MPTIOCTL, 3)
373 #define	MPTIOCTL_PASS_THRU		_IOWR(MPTIOCTL, 4,\
374     struct mpr_pass_thru)
375 #define	MPTIOCTL_EVENT_QUERY		_IOWR(MPTIOCTL, 5,\
376     struct mpr_event_query)
377 #define	MPTIOCTL_EVENT_ENABLE		_IOWR(MPTIOCTL, 6,\
378     struct mpr_event_enable)
379 #define	MPTIOCTL_EVENT_REPORT		_IOWR(MPTIOCTL, 7,\
380     struct mpr_event_report)
381 #define	MPTIOCTL_GET_PCI_INFO		_IOWR(MPTIOCTL, 8,\
382     struct mpr_pci_info)
383 #define	MPTIOCTL_DIAG_ACTION		_IOWR(MPTIOCTL, 9,\
384     struct mpr_diag_action)
385 #define	MPTIOCTL_REG_ACCESS		_IOWR(MPTIOCTL, 10,\
386     struct mpr_reg_access)
387 #define	MPTIOCTL_BTDH_MAPPING		_IOWR(MPTIOCTL, 11,\
388     struct mpr_btdh_mapping)
389 #endif /* MPTIOCTL */
390 
391 #endif /* !_MPR_IOCTL_H_ */
392