xref: /freebsd/sys/dev/mpr/mpr_ioctl.h (revision 95eb4b873b6a8b527c5bd78d7191975dfca38998)
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 /*-
33  * Copyright (c) 2011-2015 LSI Corp.
34  * Copyright (c) 2013-2016 Avago Technologies
35  * Copyright 2000-2020 Broadcom Inc.
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  * Broadcom Inc. (LSI) MPT-Fusion Host Adapter FreeBSD
60  */
61 
62 #ifndef _MPR_IOCTL_H_
63 #define	_MPR_IOCTL_H_
64 
65 #include <dev/mpr/mpi/mpi2_type.h>
66 #include <dev/mpr/mpi/mpi2.h>
67 #include <dev/mpr/mpi/mpi2_cnfg.h>
68 #include <dev/mpr/mpi/mpi2_sas.h>
69 
70 /*
71  * For the read header requests, the header should include the page
72  * type or extended page type, page number, and page version.  The
73  * buffer and length are unused.  The completed header is returned in
74  * the 'header' member.
75  *
76  * For the read page and write page requests, 'buf' should point to a
77  * buffer of 'len' bytes which holds the entire page (including the
78  * header).
79  *
80  * All requests specify the page address in 'page_address'.
81  */
82 struct mpr_cfg_page_req {
83 	MPI2_CONFIG_PAGE_HEADER header;
84 	uint32_t page_address;
85 	void	*buf;
86 	int	len;
87 	uint16_t ioc_status;
88 };
89 
90 struct mpr_ext_cfg_page_req {
91 	MPI2_CONFIG_EXTENDED_PAGE_HEADER header;
92 	uint32_t page_address;
93 	void	*buf;
94 	int	len;
95 	uint16_t ioc_status;
96 };
97 
98 struct mpr_raid_action {
99 	uint8_t action;
100 	uint8_t volume_bus;
101 	uint8_t volume_id;
102 	uint8_t phys_disk_num;
103 	uint32_t action_data_word;
104 	void *buf;
105 	int len;
106 	uint32_t volume_status;
107 	uint32_t action_data[4];
108 	uint16_t action_status;
109 	uint16_t ioc_status;
110 	uint8_t write;
111 };
112 
113 struct mpr_usr_command {
114 	void *req;
115 	uint32_t req_len;
116 	void *rpl;
117 	uint32_t rpl_len;
118 	void *buf;
119 	int len;
120 	uint32_t flags;
121 };
122 
123 typedef struct mpr_pci_bits
124 {
125 	union {
126 		struct {
127 			uint32_t	DeviceNumber	:5;
128 			uint32_t	FunctionNumber	:3;
129 			uint32_t	BusNumber	:24;
130 		} bits;
131 		uint32_t	AsDWORD;
132 	} u;
133 	uint32_t	PciSegmentId;
134 } mpr_pci_bits_t;
135 
136 /*
137  *  The following is the MPRIOCTL_GET_ADAPTER_DATA data structure.  This data
138  *  structure is setup so that we hopefully are properly aligned for both
139  *  32-bit and 64-bit mode applications.
140  *
141  *  Adapter Type - Value = 6 = SCSI Protocol through SAS-3 adapter
142  *
143  *  MPI Port Number - The PCI Function number for this device
144  *
145  *  PCI Device HW Id - The PCI device number for this device
146  *
147  */
148 #define	MPRIOCTL_ADAPTER_TYPE_SAS3		6
149 #define	MPRIOCTL_ADAPTER_TYPE_SAS35		7
150 typedef struct mpr_adapter_data
151 {
152 	uint32_t	StructureLength;
153 	uint32_t	AdapterType;
154 	uint32_t	MpiPortNumber;
155 	uint32_t	PCIDeviceHwId;
156 	uint32_t	PCIDeviceHwRev;
157 	uint32_t	SubSystemId;
158 	uint32_t	SubsystemVendorId;
159 	uint32_t	Reserved1;
160 	uint32_t	MpiFirmwareVersion;
161 	uint32_t	BiosVersion;
162 	uint8_t		DriverVersion[32];
163 	uint8_t		Reserved2;
164 	uint8_t		ScsiId;
165 	uint16_t	Reserved3;
166 	mpr_pci_bits_t	PciInformation;
167 } mpr_adapter_data_t;
168 
169 typedef struct mpr_update_flash
170 {
171 	uint64_t	PtrBuffer;
172 	uint32_t	ImageChecksum;
173 	uint32_t	ImageOffset;
174 	uint32_t	ImageSize;
175 	uint32_t	ImageType;
176 } mpr_update_flash_t;
177 
178 #define	MPR_PASS_THRU_DIRECTION_NONE	0
179 #define	MPR_PASS_THRU_DIRECTION_READ	1
180 #define	MPR_PASS_THRU_DIRECTION_WRITE	2
181 #define	MPR_PASS_THRU_DIRECTION_BOTH	3
182 
183 typedef struct mpr_pass_thru
184 {
185 	uint64_t	PtrRequest;
186 	uint64_t	PtrReply;
187 	uint64_t	PtrData;
188 	uint32_t	RequestSize;
189 	uint32_t	ReplySize;
190 	uint32_t	DataSize;
191 	uint32_t	DataDirection;
192 	uint64_t	PtrDataOut;
193 	uint32_t	DataOutSize;
194 	uint32_t	Timeout;
195 } mpr_pass_thru_t;
196 
197 /*
198  * Event queue defines
199  */
200 #define	MPR_EVENT_QUEUE_SIZE		(200) /* Max Events stored in driver */
201 #define	MPR_MAX_EVENT_DATA_LENGTH	(48) /* Size of each event in Dwords */
202 
203 typedef struct mpr_event_query
204 {
205 	uint16_t	Entries;
206 	uint16_t	Reserved;
207 	uint32_t	Types[4];
208 } mpr_event_query_t;
209 
210 typedef struct mpr_event_enable
211 {
212 	uint32_t	Types[4];
213 } mpr_event_enable_t;
214 
215 /*
216  * Event record entry for ioctl.
217  */
218 typedef struct mpr_event_entry
219 {
220 	uint32_t	Type;
221 	uint32_t	Number;
222 	uint32_t	Data[MPR_MAX_EVENT_DATA_LENGTH];
223 } mpr_event_entry_t;
224 
225 typedef struct mpr_event_report
226 {
227 	uint32_t	Size;
228 	uint64_t	PtrEvents;
229 } mpr_event_report_t;
230 
231 typedef struct mpr_pci_info
232 {
233 	uint32_t	BusNumber;
234 	uint8_t		DeviceNumber;
235 	uint8_t		FunctionNumber;
236 	uint16_t	InterruptVector;
237 	uint8_t		PciHeader[256];
238 } mpr_pci_info_t;
239 
240 typedef struct mpr_diag_action
241 {
242 	uint32_t	Action;
243 	uint32_t	Length;
244 	uint64_t	PtrDiagAction;
245 	uint32_t	ReturnCode;
246 } mpr_diag_action_t;
247 
248 #define	MPR_FW_DIAGNOSTIC_UID_NOT_FOUND	(0xFF)
249 
250 #define	MPR_FW_DIAG_NEW				(0x806E6577)
251 
252 #define	MPR_FW_DIAG_TYPE_REGISTER		(0x00000001)
253 #define	MPR_FW_DIAG_TYPE_UNREGISTER		(0x00000002)
254 #define	MPR_FW_DIAG_TYPE_QUERY			(0x00000003)
255 #define	MPR_FW_DIAG_TYPE_READ_BUFFER		(0x00000004)
256 #define	MPR_FW_DIAG_TYPE_RELEASE		(0x00000005)
257 
258 #define	MPR_FW_DIAG_INVALID_UID			(0x00000000)
259 
260 #define MPR_DIAG_SUCCESS			0
261 #define MPR_DIAG_FAILURE			1
262 
263 #define	MPR_FW_DIAG_ERROR_SUCCESS		(0x00000000)
264 #define	MPR_FW_DIAG_ERROR_FAILURE		(0x00000001)
265 #define	MPR_FW_DIAG_ERROR_INVALID_PARAMETER	(0x00000002)
266 #define	MPR_FW_DIAG_ERROR_POST_FAILED		(0x00000010)
267 #define	MPR_FW_DIAG_ERROR_INVALID_UID		(0x00000011)
268 #define	MPR_FW_DIAG_ERROR_RELEASE_FAILED	(0x00000012)
269 #define	MPR_FW_DIAG_ERROR_NO_BUFFER		(0x00000013)
270 #define	MPR_FW_DIAG_ERROR_ALREADY_RELEASED	(0x00000014)
271 
272 typedef struct mpr_fw_diag_register
273 {
274 	uint8_t		ExtendedType;
275 	uint8_t		BufferType;
276 	uint16_t	ApplicationFlags;
277 	uint32_t	DiagnosticFlags;
278 	uint32_t	ProductSpecific[23];
279 	uint32_t	RequestedBufferSize;
280 	uint32_t	UniqueId;
281 } mpr_fw_diag_register_t;
282 
283 typedef struct mpr_fw_diag_unregister
284 {
285 	uint32_t	UniqueId;
286 } mpr_fw_diag_unregister_t;
287 
288 #define	MPR_FW_DIAG_FLAG_APP_OWNED		(0x0001)
289 #define	MPR_FW_DIAG_FLAG_BUFFER_VALID		(0x0002)
290 #define	MPR_FW_DIAG_FLAG_FW_BUFFER_ACCESS	(0x0004)
291 
292 typedef struct mpr_fw_diag_query
293 {
294 	uint8_t		ExtendedType;
295 	uint8_t		BufferType;
296 	uint16_t	ApplicationFlags;
297 	uint32_t	DiagnosticFlags;
298 	uint32_t	ProductSpecific[23];
299 	uint32_t	TotalBufferSize;
300 	uint32_t	DriverAddedBufferSize;
301 	uint32_t	UniqueId;
302 } mpr_fw_diag_query_t;
303 
304 typedef struct mpr_fw_diag_release
305 {
306 	uint32_t	UniqueId;
307 } mpr_fw_diag_release_t;
308 
309 #define	MPR_FW_DIAG_FLAG_REREGISTER	(0x0001)
310 #define	MPR_FW_DIAG_FLAG_FORCE_RELEASE	(0x0002)
311 
312 typedef struct mpr_diag_read_buffer
313 {
314 	uint8_t		Status;
315 	uint8_t		Reserved;
316 	uint16_t	Flags;
317 	uint32_t	StartingOffset;
318 	uint32_t	BytesToRead;
319 	uint32_t	UniqueId;
320 	uint64_t	PtrDataBuffer;
321 } mpr_diag_read_buffer_t;
322 
323 /*
324  * Register Access
325  */
326 #define	REG_IO_READ	1
327 #define	REG_IO_WRITE	2
328 #define	REG_MEM_READ	3
329 #define	REG_MEM_WRITE	4
330 
331 typedef struct mpr_reg_access
332 {
333 	uint32_t	Command;
334 	uint32_t	RegOffset;
335 	uint32_t	RegData;
336 } mpr_reg_access_t;
337 
338 typedef struct mpr_btdh_mapping
339 {
340 	uint16_t	TargetID;
341 	uint16_t	Bus;
342 	uint16_t	DevHandle;
343 	uint16_t	Reserved;
344 } mpr_btdh_mapping_t;
345 
346 #define MPRIO_MPR_COMMAND_FLAG_VERBOSE	0x01
347 #define MPRIO_MPR_COMMAND_FLAG_DEBUG	0x02
348 #define	MPRIO_READ_CFG_HEADER	_IOWR('M', 200, struct mpr_cfg_page_req)
349 #define	MPRIO_READ_CFG_PAGE	_IOWR('M', 201, struct mpr_cfg_page_req)
350 #define	MPRIO_READ_EXT_CFG_HEADER _IOWR('M', 202, struct mpr_ext_cfg_page_req)
351 #define	MPRIO_READ_EXT_CFG_PAGE	_IOWR('M', 203, struct mpr_ext_cfg_page_req)
352 #define	MPRIO_WRITE_CFG_PAGE	_IOWR('M', 204, struct mpr_cfg_page_req)
353 #define	MPRIO_RAID_ACTION	_IOWR('M', 205, struct mpr_raid_action)
354 #define	MPRIO_MPR_COMMAND	_IOWR('M', 210, struct mpr_usr_command)
355 
356 #ifndef MPTIOCTL
357 #define	MPTIOCTL			('I')
358 #define	MPTIOCTL_GET_ADAPTER_DATA	_IOWR(MPTIOCTL, 1,\
359     struct mpr_adapter_data)
360 #define	MPTIOCTL_UPDATE_FLASH		_IOWR(MPTIOCTL, 2,\
361     struct mpr_update_flash)
362 #define	MPTIOCTL_RESET_ADAPTER		_IO(MPTIOCTL, 3)
363 #define	MPTIOCTL_PASS_THRU		_IOWR(MPTIOCTL, 4,\
364     struct mpr_pass_thru)
365 #define	MPTIOCTL_EVENT_QUERY		_IOWR(MPTIOCTL, 5,\
366     struct mpr_event_query)
367 #define	MPTIOCTL_EVENT_ENABLE		_IOWR(MPTIOCTL, 6,\
368     struct mpr_event_enable)
369 #define	MPTIOCTL_EVENT_REPORT		_IOWR(MPTIOCTL, 7,\
370     struct mpr_event_report)
371 #define	MPTIOCTL_GET_PCI_INFO		_IOWR(MPTIOCTL, 8,\
372     struct mpr_pci_info)
373 #define	MPTIOCTL_DIAG_ACTION		_IOWR(MPTIOCTL, 9,\
374     struct mpr_diag_action)
375 #define	MPTIOCTL_REG_ACCESS		_IOWR(MPTIOCTL, 10,\
376     struct mpr_reg_access)
377 #define	MPTIOCTL_BTDH_MAPPING		_IOWR(MPTIOCTL, 11,\
378     struct mpr_btdh_mapping)
379 #endif /* MPTIOCTL */
380 
381 #endif /* !_MPR_IOCTL_H_ */
382