xref: /freebsd/sys/dev/tws/tws_user.h (revision 4928135658a9d0eaee37003df6137ab363fcb0b4)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2010, LSI Corp.
5  * All rights reserved.
6  * Author : Manjunath Ranganathaiah
7  * Support: freebsdraid@lsi.com
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in
17  *    the documentation and/or other materials provided with the
18  *    distribution.
19  * 3. Neither the name of the <ORGANIZATION> nor the names of its
20  *    contributors may be used to endorse or promote products derived
21  *    from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $FreeBSD$
37  */
38 
39 #define TWS_AEN_NOT_RETRIEVED        0x1
40 #define TWS_AEN_RETRIEVED            0x2
41 
42 #define TWS_AEN_NO_EVENTS            0x1003  /* No more events */
43 #define TWS_AEN_OVERFLOW             0x1004  /* AEN overflow occurred */
44 
45 #define TWS_IOCTL_LOCK_NOT_HELD      0x1001   /* Not locked */
46 #define TWS_IOCTL_LOCK_ALREADY_HELD  0x1002   /* Already locked */
47 
48 #define TWS_IOCTL_LOCK_HELD          0x1
49 #define TWS_IOCTL_LOCK_FREE          0x0
50 
51 #pragma pack(1)
52 
53 /* Structure used to handle GET/RELEASE LOCK ioctls. */
54 struct tws_lock_packet {
55     u_int32_t       timeout_msec;
56     u_int32_t       time_remaining_msec;
57     u_int32_t       force_flag;
58 };
59 
60 /* Structure used to handle GET COMPATIBILITY INFO ioctl. */
61 struct tws_compatibility_packet {
62     u_int8_t    driver_version[32];/* driver version */
63     u_int16_t   working_srl;    /* driver & firmware negotiated srl */
64     u_int16_t   working_branch; /* branch # of the firmware that the
65                                     driver is compatible with */
66     u_int16_t   working_build;  /* build # of the firmware that the
67                                         driver is compatible with */
68     u_int16_t   driver_srl_high;/* highest driver supported srl */
69     u_int16_t   driver_branch_high;/* highest driver supported branch */
70     u_int16_t   driver_build_high;/* highest driver supported build */
71     u_int16_t   driver_srl_low;/* lowest driver supported srl */
72     u_int16_t   driver_branch_low;/* lowest driver supported branch */
73     u_int16_t   driver_build_low;/* lowest driver supported build */
74     u_int16_t   fw_on_ctlr_srl; /* srl of running firmware */
75     u_int16_t   fw_on_ctlr_branch;/* branch # of running firmware */
76     u_int16_t   fw_on_ctlr_build;/* build # of running firmware */
77 };
78 
79 
80 /* Driver understandable part of the ioctl packet built by the API. */
81 struct tws_driver_packet {
82     u_int32_t       control_code;
83     u_int32_t       status;
84     u_int32_t       unique_id;
85     u_int32_t       sequence_id;
86     u_int32_t       os_status;
87     u_int32_t       buffer_length;
88 };
89 
90 /* ioctl packet built by the API. */
91 struct tws_ioctl_packet {
92     struct tws_driver_packet      driver_pkt;
93     char                          padding[488];
94     struct tws_command_packet     cmd_pkt;
95     char                          data_buf[1];
96 };
97 
98 #pragma pack()
99 
100 
101 #pragma pack(1)
102 /*
103  * We need the structure below to ensure that the first byte of
104  * data_buf is not overwritten by the kernel, after we return
105  * from the ioctl call.  Note that cmd_pkt has been reduced
106  * to an array of 1024 bytes even though it's actually 2048 bytes
107  * in size.  This is because, we don't expect requests from user
108  * land requiring 2048 (273 sg elements) byte cmd pkts.
109  */
110 struct tws_ioctl_no_data_buf {
111     struct tws_driver_packet     driver_pkt;
112     void                         *pdata; /* points to data_buf */
113     char                         padding[488 - sizeof(void *)];
114     struct tws_command_packet    cmd_pkt;
115 };
116 
117 #pragma pack()
118 
119 
120 #include <sys/ioccom.h>
121 
122 #pragma pack(1)
123 
124 struct tws_ioctl_with_payload {
125     struct tws_driver_packet     driver_pkt;
126     char                         padding[488];
127     struct tws_command_packet    cmd_pkt;
128     union {
129         struct tws_event_packet               event_pkt;
130         struct tws_lock_packet                lock_pkt;
131         struct tws_compatibility_packet       compat_pkt;
132         char                                  data_buf[1];
133     } payload;
134 };
135 
136 #pragma pack()
137 
138 /* ioctl cmds */
139 
140 #define TWS_IOCTL_SCAN_BUS                            \
141         _IO('T', 200)
142 #define TWS_IOCTL_FIRMWARE_PASS_THROUGH               \
143         _IOWR('T', 202, struct tws_ioctl_no_data_buf)
144 #define TWS_IOCTL_GET_FIRST_EVENT                     \
145         _IOWR('T', 203, struct tws_ioctl_with_payload)
146 #define TWS_IOCTL_GET_LAST_EVENT                      \
147         _IOWR('T', 204, struct tws_ioctl_with_payload)
148 #define TWS_IOCTL_GET_NEXT_EVENT                      \
149         _IOWR('T', 205, struct tws_ioctl_with_payload)
150 #define TWS_IOCTL_GET_PREVIOUS_EVENT                  \
151         _IOWR('T', 206, struct tws_ioctl_with_payload)
152 #define TWS_IOCTL_GET_LOCK                            \
153         _IOWR('T', 207, struct tws_ioctl_with_payload)
154 #define TWS_IOCTL_RELEASE_LOCK                        \
155         _IOWR('T', 208, struct tws_ioctl_with_payload)
156 #define TWS_IOCTL_GET_COMPATIBILITY_INFO              \
157         _IOWR('T', 209, struct tws_ioctl_with_payload)
158 
159