xref: /linux/drivers/scsi/mpt3sas/mpt3sas_ctl.h (revision e0bf6c5ca2d3281f231c5f0c9bf145e9513644de)
1 /*
2  * Management Module Support for MPT (Message Passing Technology) based
3  * controllers
4  *
5  * This code is based on drivers/scsi/mpt3sas/mpt3sas_ctl.h
6  * Copyright (C) 2012-2014  LSI Corporation
7  * Copyright (C) 2013-2014 Avago Technologies
8  *  (mailto: MPT-FusionLinux.pdl@avagotech.com)
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * NO WARRANTY
21  * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
22  * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
23  * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
24  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
25  * solely responsible for determining the appropriateness of using and
26  * distributing the Program and assumes all risks associated with its
27  * exercise of rights under this Agreement, including but not limited to
28  * the risks and costs of program errors, damage to or loss of data,
29  * programs or equipment, and unavailability or interruption of operations.
30 
31  * DISCLAIMER OF LIABILITY
32  * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
33  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34  * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
38  * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 
40  * You should have received a copy of the GNU General Public License
41  * along with this program; if not, write to the Free Software
42  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
43  * USA.
44  */
45 
46 #ifndef MPT3SAS_CTL_H_INCLUDED
47 #define MPT3SAS_CTL_H_INCLUDED
48 
49 #ifdef __KERNEL__
50 #include <linux/miscdevice.h>
51 #endif
52 
53 
54 #ifndef MPT3SAS_MINOR
55 #define MPT3SAS_MINOR		(MPT_MINOR + 2)
56 #endif
57 #define MPT3SAS_DEV_NAME	"mpt3ctl"
58 #define MPT3_MAGIC_NUMBER	'L'
59 #define MPT3_IOCTL_DEFAULT_TIMEOUT (10) /* in seconds */
60 
61 /**
62  * IOCTL opcodes
63  */
64 #define MPT3IOCINFO	_IOWR(MPT3_MAGIC_NUMBER, 17, \
65 	struct mpt3_ioctl_iocinfo)
66 #define MPT3COMMAND	_IOWR(MPT3_MAGIC_NUMBER, 20, \
67 	struct mpt3_ioctl_command)
68 #ifdef CONFIG_COMPAT
69 #define MPT3COMMAND32	_IOWR(MPT3_MAGIC_NUMBER, 20, \
70 	struct mpt3_ioctl_command32)
71 #endif
72 #define MPT3EVENTQUERY	_IOWR(MPT3_MAGIC_NUMBER, 21, \
73 	struct mpt3_ioctl_eventquery)
74 #define MPT3EVENTENABLE	_IOWR(MPT3_MAGIC_NUMBER, 22, \
75 	struct mpt3_ioctl_eventenable)
76 #define MPT3EVENTREPORT	_IOWR(MPT3_MAGIC_NUMBER, 23, \
77 	struct mpt3_ioctl_eventreport)
78 #define MPT3HARDRESET	_IOWR(MPT3_MAGIC_NUMBER, 24, \
79 	struct mpt3_ioctl_diag_reset)
80 #define MPT3BTDHMAPPING	_IOWR(MPT3_MAGIC_NUMBER, 31, \
81 	struct mpt3_ioctl_btdh_mapping)
82 
83 /* diag buffer support */
84 #define MPT3DIAGREGISTER _IOWR(MPT3_MAGIC_NUMBER, 26, \
85 	struct mpt3_diag_register)
86 #define MPT3DIAGRELEASE	_IOWR(MPT3_MAGIC_NUMBER, 27, \
87 	struct mpt3_diag_release)
88 #define MPT3DIAGUNREGISTER _IOWR(MPT3_MAGIC_NUMBER, 28, \
89 	struct mpt3_diag_unregister)
90 #define MPT3DIAGQUERY	_IOWR(MPT3_MAGIC_NUMBER, 29, \
91 	struct mpt3_diag_query)
92 #define MPT3DIAGREADBUFFER _IOWR(MPT3_MAGIC_NUMBER, 30, \
93 	struct mpt3_diag_read_buffer)
94 
95 /**
96  * struct mpt3_ioctl_header - main header structure
97  * @ioc_number -  IOC unit number
98  * @port_number - IOC port number
99  * @max_data_size - maximum number bytes to transfer on read
100  */
101 struct mpt3_ioctl_header {
102 	uint32_t ioc_number;
103 	uint32_t port_number;
104 	uint32_t max_data_size;
105 };
106 
107 /**
108  * struct mpt3_ioctl_diag_reset - diagnostic reset
109  * @hdr - generic header
110  */
111 struct mpt3_ioctl_diag_reset {
112 	struct mpt3_ioctl_header hdr;
113 };
114 
115 
116 /**
117  * struct mpt3_ioctl_pci_info - pci device info
118  * @device - pci device id
119  * @function - pci function id
120  * @bus - pci bus id
121  * @segment_id - pci segment id
122  */
123 struct mpt3_ioctl_pci_info {
124 	union {
125 		struct {
126 			uint32_t device:5;
127 			uint32_t function:3;
128 			uint32_t bus:24;
129 		} bits;
130 		uint32_t  word;
131 	} u;
132 	uint32_t segment_id;
133 };
134 
135 
136 #define MPT2_IOCTL_INTERFACE_SCSI	(0x00)
137 #define MPT2_IOCTL_INTERFACE_FC		(0x01)
138 #define MPT2_IOCTL_INTERFACE_FC_IP	(0x02)
139 #define MPT2_IOCTL_INTERFACE_SAS	(0x03)
140 #define MPT2_IOCTL_INTERFACE_SAS2	(0x04)
141 #define MPT3_IOCTL_INTERFACE_SAS3	(0x06)
142 #define MPT2_IOCTL_VERSION_LENGTH	(32)
143 
144 /**
145  * struct mpt3_ioctl_iocinfo - generic controller info
146  * @hdr - generic header
147  * @adapter_type - type of adapter (spi, fc, sas)
148  * @port_number - port number
149  * @pci_id - PCI Id
150  * @hw_rev - hardware revision
151  * @sub_system_device - PCI subsystem Device ID
152  * @sub_system_vendor - PCI subsystem Vendor ID
153  * @rsvd0 - reserved
154  * @firmware_version - firmware version
155  * @bios_version - BIOS version
156  * @driver_version - driver version - 32 ASCII characters
157  * @rsvd1 - reserved
158  * @scsi_id - scsi id of adapter 0
159  * @rsvd2 - reserved
160  * @pci_information - pci info (2nd revision)
161  */
162 struct mpt3_ioctl_iocinfo {
163 	struct mpt3_ioctl_header hdr;
164 	uint32_t adapter_type;
165 	uint32_t port_number;
166 	uint32_t pci_id;
167 	uint32_t hw_rev;
168 	uint32_t subsystem_device;
169 	uint32_t subsystem_vendor;
170 	uint32_t rsvd0;
171 	uint32_t firmware_version;
172 	uint32_t bios_version;
173 	uint8_t driver_version[MPT2_IOCTL_VERSION_LENGTH];
174 	uint8_t rsvd1;
175 	uint8_t scsi_id;
176 	uint16_t rsvd2;
177 	struct mpt3_ioctl_pci_info pci_information;
178 };
179 
180 
181 /* number of event log entries */
182 #define MPT3SAS_CTL_EVENT_LOG_SIZE (50)
183 
184 /**
185  * struct mpt3_ioctl_eventquery - query event count and type
186  * @hdr - generic header
187  * @event_entries - number of events returned by get_event_report
188  * @rsvd - reserved
189  * @event_types - type of events currently being captured
190  */
191 struct mpt3_ioctl_eventquery {
192 	struct mpt3_ioctl_header hdr;
193 	uint16_t event_entries;
194 	uint16_t rsvd;
195 	uint32_t event_types[MPI2_EVENT_NOTIFY_EVENTMASK_WORDS];
196 };
197 
198 /**
199  * struct mpt3_ioctl_eventenable - enable/disable event capturing
200  * @hdr - generic header
201  * @event_types - toggle off/on type of events to be captured
202  */
203 struct mpt3_ioctl_eventenable {
204 	struct mpt3_ioctl_header hdr;
205 	uint32_t event_types[4];
206 };
207 
208 #define MPT3_EVENT_DATA_SIZE (192)
209 /**
210  * struct MPT3_IOCTL_EVENTS -
211  * @event - the event that was reported
212  * @context - unique value for each event assigned by driver
213  * @data - event data returned in fw reply message
214  */
215 struct MPT3_IOCTL_EVENTS {
216 	uint32_t event;
217 	uint32_t context;
218 	uint8_t data[MPT3_EVENT_DATA_SIZE];
219 };
220 
221 /**
222  * struct mpt3_ioctl_eventreport - returing event log
223  * @hdr - generic header
224  * @event_data - (see struct MPT3_IOCTL_EVENTS)
225  */
226 struct mpt3_ioctl_eventreport {
227 	struct mpt3_ioctl_header hdr;
228 	struct MPT3_IOCTL_EVENTS event_data[1];
229 };
230 
231 /**
232  * struct mpt3_ioctl_command - generic mpt firmware passthru ioctl
233  * @hdr - generic header
234  * @timeout - command timeout in seconds. (if zero then use driver default
235  *  value).
236  * @reply_frame_buf_ptr - reply location
237  * @data_in_buf_ptr - destination for read
238  * @data_out_buf_ptr - data source for write
239  * @sense_data_ptr - sense data location
240  * @max_reply_bytes - maximum number of reply bytes to be sent to app.
241  * @data_in_size - number bytes for data transfer in (read)
242  * @data_out_size - number bytes for data transfer out (write)
243  * @max_sense_bytes - maximum number of bytes for auto sense buffers
244  * @data_sge_offset - offset in words from the start of the request message to
245  * the first SGL
246  * @mf[1];
247  */
248 struct mpt3_ioctl_command {
249 	struct mpt3_ioctl_header hdr;
250 	uint32_t timeout;
251 	void __user *reply_frame_buf_ptr;
252 	void __user *data_in_buf_ptr;
253 	void __user *data_out_buf_ptr;
254 	void __user *sense_data_ptr;
255 	uint32_t max_reply_bytes;
256 	uint32_t data_in_size;
257 	uint32_t data_out_size;
258 	uint32_t max_sense_bytes;
259 	uint32_t data_sge_offset;
260 	uint8_t mf[1];
261 };
262 
263 #ifdef CONFIG_COMPAT
264 struct mpt3_ioctl_command32 {
265 	struct mpt3_ioctl_header hdr;
266 	uint32_t timeout;
267 	uint32_t reply_frame_buf_ptr;
268 	uint32_t data_in_buf_ptr;
269 	uint32_t data_out_buf_ptr;
270 	uint32_t sense_data_ptr;
271 	uint32_t max_reply_bytes;
272 	uint32_t data_in_size;
273 	uint32_t data_out_size;
274 	uint32_t max_sense_bytes;
275 	uint32_t data_sge_offset;
276 	uint8_t mf[1];
277 };
278 #endif
279 
280 /**
281  * struct mpt3_ioctl_btdh_mapping - mapping info
282  * @hdr - generic header
283  * @id - target device identification number
284  * @bus - SCSI bus number that the target device exists on
285  * @handle - device handle for the target device
286  * @rsvd - reserved
287  *
288  * To obtain a bus/id the application sets
289  * handle to valid handle, and bus/id to 0xFFFF.
290  *
291  * To obtain the device handle the application sets
292  * bus/id valid value, and the handle to 0xFFFF.
293  */
294 struct mpt3_ioctl_btdh_mapping {
295 	struct mpt3_ioctl_header hdr;
296 	uint32_t id;
297 	uint32_t bus;
298 	uint16_t handle;
299 	uint16_t rsvd;
300 };
301 
302 
303 
304 /* application flags for mpt3_diag_register, mpt3_diag_query */
305 #define MPT3_APP_FLAGS_APP_OWNED	(0x0001)
306 #define MPT3_APP_FLAGS_BUFFER_VALID	(0x0002)
307 #define MPT3_APP_FLAGS_FW_BUFFER_ACCESS	(0x0004)
308 
309 /* flags for mpt3_diag_read_buffer */
310 #define MPT3_FLAGS_REREGISTER		(0x0001)
311 
312 #define MPT3_PRODUCT_SPECIFIC_DWORDS		23
313 
314 /**
315  * struct mpt3_diag_register - application register with driver
316  * @hdr - generic header
317  * @reserved -
318  * @buffer_type - specifies either TRACE, SNAPSHOT, or EXTENDED
319  * @application_flags - misc flags
320  * @diagnostic_flags - specifies flags affecting command processing
321  * @product_specific - product specific information
322  * @requested_buffer_size - buffers size in bytes
323  * @unique_id - tag specified by application that is used to signal ownership
324  *  of the buffer.
325  *
326  * This will allow the driver to setup any required buffers that will be
327  * needed by firmware to communicate with the driver.
328  */
329 struct mpt3_diag_register {
330 	struct mpt3_ioctl_header hdr;
331 	uint8_t reserved;
332 	uint8_t buffer_type;
333 	uint16_t application_flags;
334 	uint32_t diagnostic_flags;
335 	uint32_t product_specific[MPT3_PRODUCT_SPECIFIC_DWORDS];
336 	uint32_t requested_buffer_size;
337 	uint32_t unique_id;
338 };
339 
340 /**
341  * struct mpt3_diag_unregister - application unregister with driver
342  * @hdr - generic header
343  * @unique_id - tag uniquely identifies the buffer to be unregistered
344  *
345  * This will allow the driver to cleanup any memory allocated for diag
346  * messages and to free up any resources.
347  */
348 struct mpt3_diag_unregister {
349 	struct mpt3_ioctl_header hdr;
350 	uint32_t unique_id;
351 };
352 
353 /**
354  * struct mpt3_diag_query - query relevant info associated with diag buffers
355  * @hdr - generic header
356  * @reserved -
357  * @buffer_type - specifies either TRACE, SNAPSHOT, or EXTENDED
358  * @application_flags - misc flags
359  * @diagnostic_flags - specifies flags affecting command processing
360  * @product_specific - product specific information
361  * @total_buffer_size - diag buffer size in bytes
362  * @driver_added_buffer_size - size of extra space appended to end of buffer
363  * @unique_id - unique id associated with this buffer.
364  *
365  * The application will send only buffer_type and unique_id.  Driver will
366  * inspect unique_id first, if valid, fill in all the info.  If unique_id is
367  * 0x00, the driver will return info specified by Buffer Type.
368  */
369 struct mpt3_diag_query {
370 	struct mpt3_ioctl_header hdr;
371 	uint8_t reserved;
372 	uint8_t buffer_type;
373 	uint16_t application_flags;
374 	uint32_t diagnostic_flags;
375 	uint32_t product_specific[MPT3_PRODUCT_SPECIFIC_DWORDS];
376 	uint32_t total_buffer_size;
377 	uint32_t driver_added_buffer_size;
378 	uint32_t unique_id;
379 };
380 
381 /**
382  * struct mpt3_diag_release -  request to send Diag Release Message to firmware
383  * @hdr - generic header
384  * @unique_id - tag uniquely identifies the buffer to be released
385  *
386  * This allows ownership of the specified buffer to returned to the driver,
387  * allowing an application to read the buffer without fear that firmware is
388  * overwritting information in the buffer.
389  */
390 struct mpt3_diag_release {
391 	struct mpt3_ioctl_header hdr;
392 	uint32_t unique_id;
393 };
394 
395 /**
396  * struct mpt3_diag_read_buffer - request for copy of the diag buffer
397  * @hdr - generic header
398  * @status -
399  * @reserved -
400  * @flags - misc flags
401  * @starting_offset - starting offset within drivers buffer where to start
402  *  reading data at into the specified application buffer
403  * @bytes_to_read - number of bytes to copy from the drivers buffer into the
404  *  application buffer starting at starting_offset.
405  * @unique_id - unique id associated with this buffer.
406  * @diagnostic_data - data payload
407  */
408 struct mpt3_diag_read_buffer {
409 	struct mpt3_ioctl_header hdr;
410 	uint8_t status;
411 	uint8_t reserved;
412 	uint16_t flags;
413 	uint32_t starting_offset;
414 	uint32_t bytes_to_read;
415 	uint32_t unique_id;
416 	uint32_t diagnostic_data[1];
417 };
418 
419 #endif /* MPT3SAS_CTL_H_INCLUDED */
420