xref: /freebsd/sys/dev/isci/scil/scic_sds_sgpio.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
1f11c7f63SJim Harris /*-
2*718cf2ccSPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3*718cf2ccSPedro F. Giffuni  *
4f11c7f63SJim Harris  * This file is provided under a dual BSD/GPLv2 license.  When using or
5f11c7f63SJim Harris  * redistributing this file, you may do so under either license.
6f11c7f63SJim Harris  *
7f11c7f63SJim Harris  * GPL LICENSE SUMMARY
8f11c7f63SJim Harris  *
9f11c7f63SJim Harris  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
10f11c7f63SJim Harris  *
11f11c7f63SJim Harris  * This program is free software; you can redistribute it and/or modify
12f11c7f63SJim Harris  * it under the terms of version 2 of the GNU General Public License as
13f11c7f63SJim Harris  * published by the Free Software Foundation.
14f11c7f63SJim Harris  *
15f11c7f63SJim Harris  * This program is distributed in the hope that it will be useful, but
16f11c7f63SJim Harris  * WITHOUT ANY WARRANTY; without even the implied warranty of
17f11c7f63SJim Harris  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18f11c7f63SJim Harris  * General Public License for more details.
19f11c7f63SJim Harris  *
20f11c7f63SJim Harris  * You should have received a copy of the GNU General Public License
21f11c7f63SJim Harris  * along with this program; if not, write to the Free Software
22f11c7f63SJim Harris  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
23f11c7f63SJim Harris  * The full GNU General Public License is included in this distribution
24f11c7f63SJim Harris  * in the file called LICENSE.GPL.
25f11c7f63SJim Harris  *
26f11c7f63SJim Harris  * BSD LICENSE
27f11c7f63SJim Harris  *
28f11c7f63SJim Harris  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29f11c7f63SJim Harris  * All rights reserved.
30f11c7f63SJim Harris  *
31f11c7f63SJim Harris  * Redistribution and use in source and binary forms, with or without
32f11c7f63SJim Harris  * modification, are permitted provided that the following conditions
33f11c7f63SJim Harris  * are met:
34f11c7f63SJim Harris  *
35f11c7f63SJim Harris  *   * Redistributions of source code must retain the above copyright
36f11c7f63SJim Harris  *     notice, this list of conditions and the following disclaimer.
37f11c7f63SJim Harris  *   * Redistributions in binary form must reproduce the above copyright
38f11c7f63SJim Harris  *     notice, this list of conditions and the following disclaimer in
39f11c7f63SJim Harris  *     the documentation and/or other materials provided with the
40f11c7f63SJim Harris  *     distribution.
41f11c7f63SJim Harris  *
42f11c7f63SJim Harris  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43f11c7f63SJim Harris  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44f11c7f63SJim Harris  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45f11c7f63SJim Harris  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46f11c7f63SJim Harris  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47f11c7f63SJim Harris  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48f11c7f63SJim Harris  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49f11c7f63SJim Harris  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50f11c7f63SJim Harris  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51f11c7f63SJim Harris  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52f11c7f63SJim Harris  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53f11c7f63SJim Harris  */
54f11c7f63SJim Harris 
55f11c7f63SJim Harris #include <sys/cdefs.h>
56f11c7f63SJim Harris /**
57f11c7f63SJim Harris * @file
58f11c7f63SJim Harris *
59f11c7f63SJim Harris * @brief This file contains the implementation of the SGPIO register inteface
60f11c7f63SJim Harris *        methods.
61f11c7f63SJim Harris */
62f11c7f63SJim Harris 
63f11c7f63SJim Harris #include <dev/isci/scil/scic_sgpio.h>
64f11c7f63SJim Harris #include <dev/isci/scil/scic_sds_controller_registers.h>
65f11c7f63SJim Harris #include <dev/isci/scil/scic_user_callback.h>
66f11c7f63SJim Harris 
67f11c7f63SJim Harris /**
68f11c7f63SJim Harris  * @brief Function writes Value to the
69f11c7f63SJim Harris  *        SGPIO Output Data Select Register (SGODSR) for phys specified by
70f11c7f63SJim Harris  *        phy_mask paremeter
71f11c7f63SJim Harris  *
72f11c7f63SJim Harris  * @param[in] SCIC_SDS_CONTROLLER_T controller
73f11c7f63SJim Harris  * @param[in] phy_mask - This field is a bit mask that specifies the phys
74f11c7f63SJim Harris  *                       to be updated.
75f11c7f63SJim Harris  * @param[in] value - Value for write
76f11c7f63SJim Harris  *
77f11c7f63SJim Harris  * @return none
78f11c7f63SJim Harris  */
79f11c7f63SJim Harris static
scic_sgpio_write_SGODSR_register(SCIC_SDS_CONTROLLER_T * controller,U32 phy_mask,U32 value)80f11c7f63SJim Harris void scic_sgpio_write_SGODSR_register(
81f11c7f63SJim Harris    SCIC_SDS_CONTROLLER_T *controller,
82f11c7f63SJim Harris    U32 phy_mask,
83f11c7f63SJim Harris    U32 value
84f11c7f63SJim Harris )
85f11c7f63SJim Harris {
86f11c7f63SJim Harris    U8 phy_index;
87f11c7f63SJim Harris 
88f11c7f63SJim Harris    for (phy_index = 0; phy_index < SCI_MAX_PHYS; phy_index++)
89f11c7f63SJim Harris    {
90f11c7f63SJim Harris       if (phy_mask >> phy_index & 1)
91f11c7f63SJim Harris       {
92f11c7f63SJim Harris           scu_sgpio_peg0_register_write(
93f11c7f63SJim Harris              controller, output_data_select[phy_index], value
94f11c7f63SJim Harris           );
95f11c7f63SJim Harris       }
96f11c7f63SJim Harris    }
97f11c7f63SJim Harris }
98f11c7f63SJim Harris 
scic_sgpio_set_vendor_code(SCI_CONTROLLER_HANDLE_T controller,U8 vendor_specific_sequence)99f11c7f63SJim Harris void scic_sgpio_set_vendor_code(
100f11c7f63SJim Harris    SCI_CONTROLLER_HANDLE_T controller,
101f11c7f63SJim Harris    U8 vendor_specific_sequence
102f11c7f63SJim Harris )
103f11c7f63SJim Harris {
104f11c7f63SJim Harris    SCIC_SDS_CONTROLLER_T * core_controller = (SCIC_SDS_CONTROLLER_T *) controller;
105f11c7f63SJim Harris 
106f11c7f63SJim Harris    scu_sgpio_peg0_register_write(
107f11c7f63SJim Harris       core_controller, vendor_specific_code, vendor_specific_sequence);
108f11c7f63SJim Harris }
109f11c7f63SJim Harris 
scic_sgpio_set_blink_patterns(SCI_CONTROLLER_HANDLE_T controller,U8 pattern_a_low,U8 pattern_a_high,U8 pattern_b_low,U8 pattern_b_high)110f11c7f63SJim Harris void scic_sgpio_set_blink_patterns(
111f11c7f63SJim Harris    SCI_CONTROLLER_HANDLE_T controller,
112f11c7f63SJim Harris    U8 pattern_a_low,
113f11c7f63SJim Harris    U8 pattern_a_high,
114f11c7f63SJim Harris    U8 pattern_b_low,
115f11c7f63SJim Harris    U8 pattern_b_high
116f11c7f63SJim Harris )
117f11c7f63SJim Harris {
118f11c7f63SJim Harris    U32 value;
119f11c7f63SJim Harris    SCIC_SDS_CONTROLLER_T * core_controller = (SCIC_SDS_CONTROLLER_T *) controller;
120f11c7f63SJim Harris 
121f11c7f63SJim Harris    value = (pattern_b_high << 12) + (pattern_b_low << 8) + (pattern_a_high << 4) + pattern_a_low;
122f11c7f63SJim Harris 
123f11c7f63SJim Harris    scu_sgpio_peg0_register_write(
124f11c7f63SJim Harris       core_controller, blink_rate, value);
125f11c7f63SJim Harris }
126f11c7f63SJim Harris 
scic_sgpio_set_functionality(SCI_CONTROLLER_HANDLE_T controller,BOOL sgpio_mode)127f11c7f63SJim Harris void scic_sgpio_set_functionality(
128f11c7f63SJim Harris    SCI_CONTROLLER_HANDLE_T controller,
129f11c7f63SJim Harris    BOOL sgpio_mode
130f11c7f63SJim Harris )
131f11c7f63SJim Harris {
132f11c7f63SJim Harris    U32 value = DISABLE_SGPIO_FUNCTIONALITY;
133f11c7f63SJim Harris    SCIC_SDS_CONTROLLER_T * core_controller = (SCIC_SDS_CONTROLLER_T *) controller;
134f11c7f63SJim Harris 
135f11c7f63SJim Harris    if(sgpio_mode)
136f11c7f63SJim Harris    {
137f11c7f63SJim Harris       value = ENABLE_SGPIO_FUNCTIONALITY;
138f11c7f63SJim Harris    }
139f11c7f63SJim Harris 
140f11c7f63SJim Harris    scu_sgpio_peg0_register_write(
141f11c7f63SJim Harris       core_controller, interface_control, value);
142f11c7f63SJim Harris }
143f11c7f63SJim Harris 
scic_sgpio_apply_led_blink_pattern(SCI_CONTROLLER_HANDLE_T controller,U32 phy_mask,BOOL error,BOOL locate,BOOL activity,U8 pattern_selection)144f11c7f63SJim Harris void scic_sgpio_apply_led_blink_pattern(
145f11c7f63SJim Harris    SCI_CONTROLLER_HANDLE_T controller,
146f11c7f63SJim Harris    U32 phy_mask,
147f11c7f63SJim Harris    BOOL error,
148f11c7f63SJim Harris    BOOL locate,
149f11c7f63SJim Harris    BOOL activity,
150f11c7f63SJim Harris    U8 pattern_selection
151f11c7f63SJim Harris )
152f11c7f63SJim Harris {
153f11c7f63SJim Harris    U32 output_value = 0;
154f11c7f63SJim Harris 
155f11c7f63SJim Harris    SCIC_SDS_CONTROLLER_T * core_controller = (SCIC_SDS_CONTROLLER_T *) controller;
156f11c7f63SJim Harris 
157f11c7f63SJim Harris    // Start with all LEDs turned off
158f11c7f63SJim Harris    output_value = (SGODSR_INVERT_BIT <<  SGODSR_ERROR_LED_SHIFT)
159f11c7f63SJim Harris                      | (SGODSR_INVERT_BIT <<  SGODSR_LOCATE_LED_SHIFT)
160f11c7f63SJim Harris                      | (SGODSR_INVERT_BIT << SGODSR_ACTIVITY_LED_SHIFT);
161f11c7f63SJim Harris 
162f11c7f63SJim Harris    if(error)
163f11c7f63SJim Harris    {  //apply pattern to error LED
164f11c7f63SJim Harris       output_value |= pattern_selection << SGODSR_ERROR_LED_SHIFT;
165f11c7f63SJim Harris       output_value &= ~(SGODSR_INVERT_BIT <<  SGODSR_ERROR_LED_SHIFT);
166f11c7f63SJim Harris    }
167f11c7f63SJim Harris    if(locate)
168f11c7f63SJim Harris    {  //apply pattern to locate LED
169f11c7f63SJim Harris       output_value |= pattern_selection << SGODSR_LOCATE_LED_SHIFT;
170f11c7f63SJim Harris       output_value &= ~(SGODSR_INVERT_BIT <<  SGODSR_LOCATE_LED_SHIFT);
171f11c7f63SJim Harris    }
172f11c7f63SJim Harris    if(activity)
173f11c7f63SJim Harris    {  //apply pattern to activity LED
174f11c7f63SJim Harris       output_value |= pattern_selection << SGODSR_ACTIVITY_LED_SHIFT;
175f11c7f63SJim Harris       output_value &= ~(SGODSR_INVERT_BIT << SGODSR_ACTIVITY_LED_SHIFT);
176f11c7f63SJim Harris    }
177f11c7f63SJim Harris 
178f11c7f63SJim Harris    scic_sgpio_write_SGODSR_register(core_controller, phy_mask, output_value);
179f11c7f63SJim Harris }
180f11c7f63SJim Harris 
scic_sgpio_set_led_blink_pattern(SCI_CONTROLLER_HANDLE_T controller,SCI_PORT_HANDLE_T port_handle,BOOL error,BOOL locate,BOOL activity,U8 pattern_selection)181f11c7f63SJim Harris void scic_sgpio_set_led_blink_pattern(
182f11c7f63SJim Harris    SCI_CONTROLLER_HANDLE_T controller,
183f11c7f63SJim Harris    SCI_PORT_HANDLE_T port_handle,
184f11c7f63SJim Harris    BOOL error,
185f11c7f63SJim Harris    BOOL locate,
186f11c7f63SJim Harris    BOOL activity,
187f11c7f63SJim Harris    U8 pattern_selection
188f11c7f63SJim Harris )
189f11c7f63SJim Harris {
190f11c7f63SJim Harris    U32 phy_mask;
191f11c7f63SJim Harris 
192f11c7f63SJim Harris    SCIC_SDS_PORT_T * port = (SCIC_SDS_PORT_T *) port_handle;
193f11c7f63SJim Harris 
194f11c7f63SJim Harris    phy_mask = scic_sds_port_get_phys(port);
195f11c7f63SJim Harris 
196f11c7f63SJim Harris    scic_sgpio_apply_led_blink_pattern(
197f11c7f63SJim Harris            controller, phy_mask, error, locate, activity, pattern_selection);
198f11c7f63SJim Harris }
199f11c7f63SJim Harris 
scic_sgpio_update_led_state(SCI_CONTROLLER_HANDLE_T controller,U32 phy_mask,BOOL error,BOOL locate,BOOL activity)200f11c7f63SJim Harris void scic_sgpio_update_led_state(
201f11c7f63SJim Harris    SCI_CONTROLLER_HANDLE_T controller,
202f11c7f63SJim Harris    U32 phy_mask,
203f11c7f63SJim Harris    BOOL error,
204f11c7f63SJim Harris    BOOL locate,
205f11c7f63SJim Harris    BOOL activity
206f11c7f63SJim Harris )
207f11c7f63SJim Harris {
208f11c7f63SJim Harris    U32 output_value;
209f11c7f63SJim Harris 
210f11c7f63SJim Harris    SCIC_SDS_CONTROLLER_T * core_controller = (SCIC_SDS_CONTROLLER_T *) controller;
211f11c7f63SJim Harris 
212f11c7f63SJim Harris    // Start with all LEDs turned on
213f11c7f63SJim Harris    output_value = 0x00000000;
214f11c7f63SJim Harris 
215f11c7f63SJim Harris    if(!error)
216f11c7f63SJim Harris    {  //turn off error LED
217f11c7f63SJim Harris       output_value |= SGODSR_INVERT_BIT <<  SGODSR_ERROR_LED_SHIFT;
218f11c7f63SJim Harris    }
219f11c7f63SJim Harris    if(!locate)
220f11c7f63SJim Harris    {  //turn off locate LED
221f11c7f63SJim Harris       output_value |= SGODSR_INVERT_BIT <<  SGODSR_LOCATE_LED_SHIFT;
222f11c7f63SJim Harris    }
223f11c7f63SJim Harris    if(!activity)
224f11c7f63SJim Harris    {  //turn off activity LED
225f11c7f63SJim Harris       output_value |= SGODSR_INVERT_BIT <<  SGODSR_ACTIVITY_LED_SHIFT;
226f11c7f63SJim Harris    }
227f11c7f63SJim Harris 
228f11c7f63SJim Harris    scic_sgpio_write_SGODSR_register(core_controller, phy_mask, output_value);
229f11c7f63SJim Harris }
230f11c7f63SJim Harris 
scic_sgpio_set_led_state(SCI_CONTROLLER_HANDLE_T controller,SCI_PORT_HANDLE_T port_handle,BOOL error,BOOL locate,BOOL activity)231f11c7f63SJim Harris void scic_sgpio_set_led_state(
232f11c7f63SJim Harris    SCI_CONTROLLER_HANDLE_T controller,
233f11c7f63SJim Harris    SCI_PORT_HANDLE_T port_handle,
234f11c7f63SJim Harris    BOOL error,
235f11c7f63SJim Harris    BOOL locate,
236f11c7f63SJim Harris    BOOL activity
237f11c7f63SJim Harris )
238f11c7f63SJim Harris {
239f11c7f63SJim Harris    U32 phy_mask;
240f11c7f63SJim Harris 
241f11c7f63SJim Harris    SCIC_SDS_PORT_T * port = (SCIC_SDS_PORT_T *) port_handle;
242f11c7f63SJim Harris 
243f11c7f63SJim Harris    phy_mask = scic_sds_port_get_phys(port);
244f11c7f63SJim Harris 
245f11c7f63SJim Harris    scic_sgpio_update_led_state(controller, phy_mask, error, locate, activity);
246f11c7f63SJim Harris }
247f11c7f63SJim Harris 
scic_sgpio_set_to_hardware_control(SCI_CONTROLLER_HANDLE_T controller,BOOL is_hardware_controlled)248f11c7f63SJim Harris void scic_sgpio_set_to_hardware_control(
249f11c7f63SJim Harris    SCI_CONTROLLER_HANDLE_T controller,
250f11c7f63SJim Harris    BOOL is_hardware_controlled
251f11c7f63SJim Harris )
252f11c7f63SJim Harris {
253f11c7f63SJim Harris    SCIC_SDS_CONTROLLER_T * core_controller = (SCIC_SDS_CONTROLLER_T *) controller;
254f11c7f63SJim Harris    U8 i;
255f11c7f63SJim Harris    U32 output_value;
256f11c7f63SJim Harris 
257f11c7f63SJim Harris    //turn on hardware control for LED's
258f11c7f63SJim Harris    if(is_hardware_controlled)
259f11c7f63SJim Harris    {
260f11c7f63SJim Harris       output_value = SGPIO_HARDWARE_CONTROL;
261f11c7f63SJim Harris    }
262f11c7f63SJim Harris    else //turn off hardware control
263f11c7f63SJim Harris    {
264f11c7f63SJim Harris       output_value = SGPIO_SOFTWARE_CONTROL;
265f11c7f63SJim Harris    }
266f11c7f63SJim Harris 
267f11c7f63SJim Harris    for(i = 0; i < SCI_MAX_PHYS; i++)
268f11c7f63SJim Harris    {
269f11c7f63SJim Harris       scu_sgpio_peg0_register_write(
270f11c7f63SJim Harris          core_controller, output_data_select[i], output_value);
271f11c7f63SJim Harris    }
272f11c7f63SJim Harris }
273f11c7f63SJim Harris 
scic_sgpio_read(SCI_CONTROLLER_HANDLE_T controller)274f11c7f63SJim Harris U32 scic_sgpio_read(
275f11c7f63SJim Harris    SCI_CONTROLLER_HANDLE_T controller
276f11c7f63SJim Harris )
277f11c7f63SJim Harris {
278f11c7f63SJim Harris    //Not supported in the SCU hardware returning 0xFFFFFFFF
279f11c7f63SJim Harris    return 0xffffffff;
280f11c7f63SJim Harris }
281f11c7f63SJim Harris 
scic_sgpio_hardware_initialize(SCI_CONTROLLER_HANDLE_T controller)282f11c7f63SJim Harris void scic_sgpio_hardware_initialize(
283f11c7f63SJim Harris    SCI_CONTROLLER_HANDLE_T controller
284f11c7f63SJim Harris )
285f11c7f63SJim Harris {
286f11c7f63SJim Harris    scic_sgpio_set_functionality(controller, TRUE);
287f11c7f63SJim Harris    scic_sgpio_set_to_hardware_control(controller, TRUE);
288f11c7f63SJim Harris    scic_sgpio_set_vendor_code(controller, 0x00);
289f11c7f63SJim Harris }
290f11c7f63SJim Harris 
scic_sgpio_initialize(SCI_CONTROLLER_HANDLE_T controller)291f11c7f63SJim Harris void scic_sgpio_initialize(
292f11c7f63SJim Harris    SCI_CONTROLLER_HANDLE_T controller
293f11c7f63SJim Harris )
294f11c7f63SJim Harris {
295f11c7f63SJim Harris    scic_sgpio_set_functionality(controller, TRUE);
296f11c7f63SJim Harris    scic_sgpio_set_to_hardware_control(controller, FALSE);
297f11c7f63SJim Harris    scic_sgpio_set_vendor_code(controller, 0x00);
298f11c7f63SJim Harris }
299