2 * SPDX-License-Identifier: BSD-2-Clause
6 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * 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
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <dev/isci/isci.h>
38 #include <sys/sysctl.h>
40 #include <dev/isci/scil/scif_controller.h>
41 #include <dev/isci/scil/scic_phy.h>
44 isci_sysctl_coalesce_timeout(SYSCTL_HANDLER_ARGS)
46 struct isci_softc *isci = (struct isci_softc *)arg1;
47 int error = sysctl_handle_int(oidp, &isci->coalesce_timeout, 0, req);
53 for (i = 0; i < isci->controller_count; i++)
54 scif_controller_set_interrupt_coalescence(
55 isci->controllers[i].scif_controller_handle,
56 isci->coalesce_number, isci->coalesce_timeout);
62 isci_sysctl_coalesce_number(SYSCTL_HANDLER_ARGS)
64 struct isci_softc *isci = (struct isci_softc *)arg1;
65 int error = sysctl_handle_int(oidp, &isci->coalesce_number, 0, req);
71 for (i = 0; i < isci->controller_count; i++)
72 scif_controller_set_interrupt_coalescence(
73 isci->controllers[i].scif_controller_handle,
74 isci->coalesce_number, isci->coalesce_timeout);
80 isci_sysctl_reset_remote_devices(struct ISCI_CONTROLLER *controller,
81 uint32_t remote_devices_to_be_reset)
85 while (remote_devices_to_be_reset != 0) {
86 if (remote_devices_to_be_reset & 0x1) {
87 struct ISCI_REMOTE_DEVICE *remote_device =
88 controller->remote_device[i];
90 if (remote_device != NULL) {
91 mtx_lock(&controller->lock);
92 isci_remote_device_reset(remote_device, NULL);
93 mtx_unlock(&controller->lock);
96 remote_devices_to_be_reset >>= 1;
102 isci_sysctl_reset_remote_device_on_controller0(SYSCTL_HANDLER_ARGS)
104 struct isci_softc *isci = (struct isci_softc *)arg1;
105 uint32_t remote_devices_to_be_reset = 0;
106 struct ISCI_CONTROLLER *controller = &isci->controllers[0];
107 int error = sysctl_handle_int(oidp, &remote_devices_to_be_reset, 0, req);
109 if (error || remote_devices_to_be_reset == 0)
112 isci_sysctl_reset_remote_devices(controller, remote_devices_to_be_reset);
118 isci_sysctl_reset_remote_device_on_controller1(SYSCTL_HANDLER_ARGS)
120 struct isci_softc *isci = (struct isci_softc *)arg1;
121 uint32_t remote_devices_to_be_reset = 0;
122 struct ISCI_CONTROLLER *controller = &isci->controllers[1];
124 sysctl_handle_int(oidp, &remote_devices_to_be_reset, 0, req);
126 if (error || remote_devices_to_be_reset == 0)
129 isci_sysctl_reset_remote_devices(controller,
130 remote_devices_to_be_reset);
136 isci_sysctl_stop(struct ISCI_CONTROLLER *controller, uint32_t phy_to_be_stopped)
138 SCI_PHY_HANDLE_T phy_handle = NULL;
140 scic_controller_get_phy_handle(
141 scif_controller_get_scic_handle(controller->scif_controller_handle),
142 phy_to_be_stopped, &phy_handle);
144 scic_phy_stop(phy_handle);
148 isci_sysctl_stop_phy(SYSCTL_HANDLER_ARGS)
150 struct isci_softc *isci = (struct isci_softc *)arg1;
151 uint32_t phy_to_be_stopped = 0xff;
152 uint32_t controller_index, phy_index;
153 int error = sysctl_handle_int(oidp, &phy_to_be_stopped, 0, req);
155 controller_index = phy_to_be_stopped / SCI_MAX_PHYS;
156 phy_index = phy_to_be_stopped % SCI_MAX_PHYS;
158 if(error || controller_index >= isci->controller_count)
161 isci_sysctl_stop(&isci->controllers[controller_index], phy_index);
167 isci_sysctl_start(struct ISCI_CONTROLLER *controller,
168 uint32_t phy_to_be_started)
170 SCI_PHY_HANDLE_T phy_handle = NULL;
172 scic_controller_get_phy_handle(
173 scif_controller_get_scic_handle(controller->scif_controller_handle),
174 phy_to_be_started, &phy_handle);
176 scic_phy_start(phy_handle);
180 isci_sysctl_start_phy(SYSCTL_HANDLER_ARGS)
182 struct isci_softc *isci = (struct isci_softc *)arg1;
183 uint32_t phy_to_be_started = 0xff;
184 uint32_t controller_index, phy_index;
185 int error = sysctl_handle_int(oidp, &phy_to_be_started, 0, req);
187 controller_index = phy_to_be_started / SCI_MAX_PHYS;
188 phy_index = phy_to_be_started % SCI_MAX_PHYS;
190 if(error || controller_index >= isci->controller_count)
193 isci_sysctl_start(&isci->controllers[controller_index], phy_index);
199 isci_sysctl_log_frozen_lun_masks(SYSCTL_HANDLER_ARGS)
201 struct isci_softc *isci = (struct isci_softc *)arg1;
202 struct ISCI_REMOTE_DEVICE *device;
203 int32_t log_frozen_devices = 0;
206 error = sysctl_handle_int(oidp, &log_frozen_devices, 0, req);
208 if (error || log_frozen_devices == 0)
211 for (i = 0; i < isci->controller_count; i++) {
212 for (j = 0; j < SCI_MAX_REMOTE_DEVICES; j++) {
213 device = isci->controllers[i].remote_device[j];
218 device_printf(isci->device,
219 "controller %d device %3d frozen_lun_mask 0x%02x\n",
220 i, j, device->frozen_lun_mask);
228 isci_sysctl_fail_on_task_timeout(SYSCTL_HANDLER_ARGS)
230 struct isci_softc *isci = (struct isci_softc *)arg1;
231 int32_t fail_on_timeout;
234 fail_on_timeout = isci->controllers[0].fail_on_task_timeout;
235 error = sysctl_handle_int(oidp, &fail_on_timeout, 0, req);
237 if (error || req->newptr == NULL)
240 for (i = 0; i < isci->controller_count; i++)
241 isci->controllers[i].fail_on_task_timeout = fail_on_timeout;
246 void isci_sysctl_initialize(struct isci_softc *isci)
248 struct sysctl_ctx_list *sysctl_ctx = device_get_sysctl_ctx(isci->device);
249 struct sysctl_oid *sysctl_tree = device_get_sysctl_tree(isci->device);
251 SYSCTL_ADD_PROC(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree), OID_AUTO,
252 "coalesce_timeout", CTLTYPE_UINT | CTLFLAG_RW, isci, 0,
253 isci_sysctl_coalesce_timeout, "IU",
254 "Interrupt coalescing timeout (in microseconds)");
256 SYSCTL_ADD_PROC(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree), OID_AUTO,
257 "coalesce_number", CTLTYPE_UINT | CTLFLAG_RW, isci, 0,
258 isci_sysctl_coalesce_number, "IU",
259 "Interrupt coalescing number");
261 SYSCTL_ADD_PROC(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree), OID_AUTO,
262 "reset_remote_device_on_controller0", CTLTYPE_UINT| CTLFLAG_RW,
263 isci, 0, isci_sysctl_reset_remote_device_on_controller0, "IU",
264 "Reset remote device on controller 0");
266 SYSCTL_ADD_PROC(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree), OID_AUTO,
267 "reset_remote_device_on_controller1", CTLTYPE_UINT| CTLFLAG_RW,
268 isci, 0, isci_sysctl_reset_remote_device_on_controller1, "IU",
269 "Reset remote device on controller 1");
271 SYSCTL_ADD_PROC(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree), OID_AUTO,
272 "stop_phy", CTLTYPE_UINT| CTLFLAG_RW, isci, 0, isci_sysctl_stop_phy,
273 "IU", "Stop PHY on a controller");
275 SYSCTL_ADD_PROC(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree), OID_AUTO,
276 "start_phy", CTLTYPE_UINT| CTLFLAG_RW, isci, 0,
277 isci_sysctl_start_phy, "IU", "Start PHY on a controller");
279 SYSCTL_ADD_PROC(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree), OID_AUTO,
280 "log_frozen_lun_masks", CTLTYPE_UINT| CTLFLAG_RW, isci, 0,
281 isci_sysctl_log_frozen_lun_masks, "IU",
282 "Log frozen lun masks to kernel log");
284 SYSCTL_ADD_PROC(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree), OID_AUTO,
285 "fail_on_task_timeout", CTLTYPE_UINT | CTLFLAG_RW, isci, 0,
286 isci_sysctl_fail_on_task_timeout, "IU",
287 "Fail a command that has encountered a task management timeout");