xref: /freebsd/sys/dev/isci/scil/scic_sgpio.h (revision 09127a36371d5f5ac109ad1063e7fe53ee9bf356)
1 /*-
2  * This file is provided under a dual BSD/GPLv2 license.  When using or
3  * redistributing this file, you may do so under either license.
4  *
5  * GPL LICENSE SUMMARY
6  *
7  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of version 2 of the GNU General Public License as
11  * published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21  * The full GNU General Public License is included in this distribution
22  * in the file called LICENSE.GPL.
23  *
24  * BSD LICENSE
25  *
26  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without
30  * modification, are permitted provided that the following conditions
31  * are met:
32  *
33  *   * Redistributions of source code must retain the above copyright
34  *     notice, this list of conditions and the following disclaimer.
35  *   * Redistributions in binary form must reproduce the above copyright
36  *     notice, this list of conditions and the following disclaimer in
37  *     the documentation and/or other materials provided with the
38  *     distribution.
39  *
40  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51  *
52  * $FreeBSD$
53  */
54 #ifndef _SCIC_SGPIO_H_
55 #define _SCIC_SGPIO_H_
56 
57 /**
58 * @file
59 *
60 * @brief This file contains all of the interface methods that can be called
61 *        by an SCI user on an Serialized General Purpose IO (SGPIO) object.
62 */
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif // __cplusplus
67 
68 #include <dev/isci/scil/sci_types.h>
69 
70 //Programmable Blink Pattern Durations
71 #define SGPIO_BLINK_DURATION_125    0x0
72 #define SGPIO_BLINK_DURATION_250    0x1
73 #define SGPIO_BLINK_DURATION_375    0x2
74 #define SGPIO_BLINK_DURATION_500    0x3
75 #define SGPIO_BLINK_DURATION_625    0x4
76 #define SGPIO_BLINK_DURATION_750    0x5
77 #define SGPIO_BLINK_DURATION_875    0x6
78 #define SGPIO_BLINK_DURATION_1000   0x7
79 #define SGPIO_BLINK_DURATION_1250   0x8
80 #define SGPIO_BLINK_DURATION_1375   0x9
81 #define SGPIO_BLINK_DURATION_1500   0xA
82 #define SGPIO_BLINK_DURATION_1625   0xB
83 #define SGPIO_BLINK_DURATION_1750   0xC
84 #define SGPIO_BLINK_DURATION_1875   0xD
85 #define SGPIO_BLINK_DURATION_2000   0xF
86 
87 #define ENABLE_SGPIO_FUNCTIONALITY  1
88 #define DISABLE_SGPIO_FUNCTIONALITY 0
89 
90 #define SGPIO_HARDWARE_CONTROL      0x00000443
91 #define SGPIO_SOFTWARE_CONTROL      0x00000444
92 
93 #define PHY_0_MASK                  0x01
94 #define PHY_1_MASK                  0x02
95 #define PHY_2_MASK                  0x04
96 #define PHY_3_MASK                  0x08
97 
98 #define SGODSR_INVERT_BIT 0x4
99 
100 #define SGODSR_ERROR_LED_SHIFT 8
101 #define SGODSR_LOCATE_LED_SHIFT 4
102 #define SGODSR_ACTIVITY_LED_SHIFT 0
103 
104 #define SGPIO_BLINK_PATTERN_A 0x1
105 #define SGPIO_BLINK_PATTERN_B 0x2
106 
107 /**
108 * @brief This will set the vendor specific code in the SGPIO Vendor Specific Code
109 *        register that is sent on the sLoad wire at the start of each
110 *        bit stream.
111 *
112 * @param[in] SCI_CONTROLLER_HANDLE_T controller
113 * @param]in] vendor_specific_sequence - Vendor specific sequence set in the
114 *         SGVSCR register.
115 *
116 */
117 void scic_sgpio_set_vendor_code(
118    SCI_CONTROLLER_HANDLE_T controller,
119    U8 vendor_specific_sequence
120 );
121 
122 /**
123 * @brief Use this to set both programmable blink patterns A & B in the
124 *        SGPBR(Programmable Blink Register). Will set identical patterns
125 *        on both SGPIO units.
126 *
127 * @param[in] SCI_CONTROLLER_HANDLE_T controller
128 * @param[in] pattern_a_high - High(LED on) duration time for pattern A
129 * @param[in] pattern_a_low - Low(LED off) duration time for pattern A
130 * @param[in] pattern_b_high - High(LED on) duration time for pattern B
131 * @param[in] pattern_b_low - Low(LED off) duration time for pattern B
132 *
133 */
134 void scic_sgpio_set_blink_patterns(
135    SCI_CONTROLLER_HANDLE_T controller,
136    U8 pattern_a_low,
137    U8 pattern_a_high,
138    U8 pattern_b_low,
139    U8 pattern_b_high
140 );
141 
142 
143 /**
144 * @brief This will set the functionality enable bit in the SGPIO interface
145 *        control register, when set the bus pins will be used for SGPIO
146 *        signaling, if not the bus pins are used for direct led control.
147 *
148 * @param[in] SCI_CONTROLLER_HANDLE_T controller
149 * @param[in] BOOL sgpio_mode - indication for SGPIO signaling.
150 *
151 */
152 void scic_sgpio_set_functionality(
153    SCI_CONTROLLER_HANDLE_T controller,
154    BOOL sgpio_mode
155 );
156 
157 /**
158  * @brief Communicates with hardware to set the blink pattern
159  *        of the error, locate, and activity LED's for phys
160  *        specified by the phy_mask parameter.
161  *        Function intend to be used to LEDs management
162  *        in non-inteligent backplanes.
163  *
164  * @param[in] SCI_CONTROLLER_HANDLE_T controller
165  * @param[in] phy_mask - This field is a bit mask that specifies the phys
166  *                       to be updated.
167  * @param[in] error - If TRUE, apply pattern for the error LED
168  * @param[in] locate - If TRUE, apply pattern for the locate LED
169  * @param[in] activity - If TRUE, apply pattern for the activity LED
170  * @param[in] pattern_selection - One of two patterns (A or B).
171  *            "A" and "B" patterns should be previously defined
172  *            by scic_sgpio_set_blink_patterns()
173  *
174  * @return none
175  */
176 void scic_sgpio_apply_led_blink_pattern(
177    SCI_CONTROLLER_HANDLE_T controller,
178    U32 phy_mask,
179    BOOL error,
180    BOOL locate,
181    BOOL activity,
182    U8 pattern_selection
183 );
184 
185 /**
186  * @brief Communicates with hardware to set the blink pattern
187  *        of the error, locate, and activity LED's for all
188  *        phys in the port. Function intend to be used to LEDs
189  *        management in non-inteligent backplanes.
190  *
191  * @param[in] SCI_CONTROLLER_HANDLE_T controller
192  * @param[in] port_handle - port handle is used to identify SGPIO bay
193  * @param[in] error - If TRUE, apply pattern for the error LED
194  * @param[in] locate - If TRUE, apply pattern for the locate LED
195  * @param[in] activity - If TRUE, apply pattern for the activity LED
196  * @param[in] pattern_selection - One of two patterns (A or B).
197  *            "A" and "B" patterns should be previously defined
198  *            by scic_sgpio_set_blink_patterns()
199  *
200  * @return none
201  */
202 void scic_sgpio_set_led_blink_pattern(
203    SCI_CONTROLLER_HANDLE_T controller,
204    SCI_PORT_HANDLE_T port_handle,
205    BOOL error,
206    BOOL locate,
207    BOOL activity,
208    U8 pattern_selection
209 );
210 
211 /**
212  * @brief Communicates with hardware to set the state of the error, locate,
213  *        and activity LED's.
214  *
215  * @param[in] SCI_CONTROLLER_HANDLE_T controller
216  * @param[in] phy_mask - This field is a bit mask that specifies the phys
217  *                       to be updated.
218  * @param[in] error - State to be set for the error LED
219  * @param[in] locate - State to be set for the locate LED
220  * @param[in] activity - State to be set for the activity LED
221  *
222  * @return none
223  */
224 void scic_sgpio_update_led_state(
225    SCI_CONTROLLER_HANDLE_T controller,
226    U32 phy_mask,
227    BOOL error,
228    BOOL locate,
229    BOOL activity
230 );
231 
232 /**
233  * @brief Communicates with hardware to set the state of the error, locate,
234  *        and activity LED's for all phys in the port.
235  *
236  * @param[in] SCI_CONTROLLER_HANDLE_T controller
237  * @param[in] port_handle - port handle is used to identify SGPIO bay
238  * @param[in] error - State to be set for the error LED
239  * @param[in] locate - State to be set for the locate LED
240  * @param[in] activity - State to be set for the activity LED
241  *
242  * @return none
243  */
244 void scic_sgpio_set_led_state(
245    SCI_CONTROLLER_HANDLE_T controller,
246    SCI_PORT_HANDLE_T port_handle,
247    BOOL error,
248    BOOL locate,
249    BOOL activity
250 );
251 
252 /**
253  * @brief This will set all Activity LED's to hardware controlled
254  *
255  * @param[in] BOOL is_hardware_controlled - indication for the Activity LED's
256  *         to be hardware controlled or driver controlled.
257  * @return none
258  */
259 void scic_sgpio_set_to_hardware_control(
260    SCI_CONTROLLER_HANDLE_T controller,
261    BOOL is_hardware_controlled
262 );
263 
264 /**
265  * @brief Reads and returns the data-in from the SGPIO port for the specified controller.
266  *        Bits 00:02 - Drive 0 input data
267  *        Bits 04:06 - Drive 1 input data
268  *        Bits 08:10 - Drive 2 input data
269  *        Bits 12:14 - Drive 3 input data
270  *
271  * @param[in] SCI_CONTROLLER_HANDLE_T controller
272  * @return U32 - Value read from SGPIO, 0xffffffff indicates hardware not readable
273  */
274 U32 scic_sgpio_read(
275    SCI_CONTROLLER_HANDLE_T controller
276 );
277 
278 /**
279  * @brief Initializes the SCU for Hardware SGPIO LED control.
280  *
281  * @param[in] SCI_CONTROLLER_HANDLE_T controller
282  */
283 void scic_sgpio_hardware_initialize(
284    SCI_CONTROLLER_HANDLE_T controller
285 );
286 /**
287 * @brief Initializes the SCU for Software SGPIO signaling of LED control.
288 *
289 * @param[in] SCI_CONTROLLER_HANDLE_T controller
290 */
291 void scic_sgpio_initialize(
292    SCI_CONTROLLER_HANDLE_T controller
293 );
294 
295 #ifdef __cplusplus
296 }
297 #endif // __cplusplus
298 
299 #endif // _SCIC_SGPIO_H_
300