4 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <dev/isci/isci.h>
36 #include <cam/cam_periph.h>
37 #include <cam/cam_xpt_periph.h>
39 #include <dev/isci/scil/scif_task_request.h>
40 #include <dev/isci/scil/scif_controller.h>
41 #include <dev/isci/scil/scif_domain.h>
42 #include <dev/isci/scil/scif_user_callback.h>
44 #include <dev/isci/scil/scic_port.h>
45 #include <dev/isci/scil/scic_phy.h>
48 * @brief This callback method informs the framework user that the remote
49 * device is ready and capable of processing IO requests.
51 * @param[in] controller This parameter specifies the controller object
52 * with which this callback is associated.
53 * @param[in] domain This parameter specifies the domain object with
54 * which this callback is associated.
55 * @param[in] remote_device This parameter specifies the device object with
56 * which this callback is associated.
61 scif_cb_remote_device_ready(SCI_CONTROLLER_HANDLE_T controller,
62 SCI_DOMAIN_HANDLE_T domain, SCI_REMOTE_DEVICE_HANDLE_T remote_device)
64 struct ISCI_REMOTE_DEVICE *isci_remote_device =
65 sci_object_get_association(remote_device);
66 struct ISCI_CONTROLLER *isci_controller =
67 sci_object_get_association(controller);
68 uint32_t device_index = isci_remote_device->index;
70 if (isci_controller->remote_device[device_index] == NULL) {
71 /* This new device is now ready, so put it in the controller's
72 * remote device list so it is visible to CAM.
74 isci_controller->remote_device[device_index] =
77 if (isci_controller->has_been_scanned) {
78 /* The sim object has been scanned at least once
79 * already. In that case, create a CCB to instruct
80 * CAM to rescan this device.
81 * If the sim object has not been scanned, this device
82 * will get scanned as part of the initial scan.
84 union ccb *ccb = xpt_alloc_ccb_nowait();
86 xpt_create_path(&ccb->ccb_h.path, NULL,
87 cam_sim_path(isci_controller->sim),
88 isci_remote_device->index, CAM_LUN_WILDCARD);
94 isci_remote_device_release_device_queue(isci_remote_device);
98 * @brief This callback method informs the framework user that the remote
99 * device is not ready. Thus, it is incapable of processing IO
102 * @param[in] controller This parameter specifies the controller object
103 * with which this callback is associated.
104 * @param[in] domain This parameter specifies the domain object with
105 * which this callback is associated.
106 * @param[in] remote_device This parameter specifies the device object with
107 * which this callback is associated.
112 scif_cb_remote_device_not_ready(SCI_CONTROLLER_HANDLE_T controller,
113 SCI_DOMAIN_HANDLE_T domain, SCI_REMOTE_DEVICE_HANDLE_T remote_device)
119 * @brief This callback method informs the framework user that the remote
120 * device failed. This typically occurs shortly after the device
121 * has been discovered, during the configuration phase for the device.
123 * @param[in] controller This parameter specifies the controller object
124 * with which this callback is associated.
125 * @param[in] domain This parameter specifies the domain object with
126 * which this callback is associated.
127 * @param[in] remote_device This parameter specifies the device object with
128 * which this callback is associated.
129 * @param[in] status This parameter specifies the specific failure condition
130 * associated with this device failure.
135 scif_cb_remote_device_failed(SCI_CONTROLLER_HANDLE_T controller,
136 SCI_DOMAIN_HANDLE_T domain, SCI_REMOTE_DEVICE_HANDLE_T remote_device,
143 isci_remote_device_reset(struct ISCI_REMOTE_DEVICE *remote_device,
146 struct ISCI_CONTROLLER *controller = remote_device->domain->controller;
147 struct ISCI_REQUEST *request;
148 struct ISCI_TASK_REQUEST *task_request;
151 if (remote_device->is_resetting == TRUE) {
152 /* device is already being reset, so return immediately */
156 if (sci_pool_empty(controller->request_pool)) {
157 /* No requests are available in our request pool. If this reset is tied
158 * to a CCB, ask CAM to requeue it. Otherwise, we need to put it on our
159 * pending device reset list, so that the reset will occur when a request
163 sci_fast_list_insert_tail(
164 &controller->pending_device_reset_list,
165 &remote_device->pending_device_reset_element);
167 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
168 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
174 isci_log_message(0, "ISCI",
175 "Sending reset to device on controller %d domain %d CAM index %d\n",
176 controller->index, remote_device->domain->index,
180 sci_pool_get(controller->request_pool, request);
181 task_request = (struct ISCI_TASK_REQUEST *)request;
183 task_request->parent.remote_device_handle = remote_device->sci_object;
184 task_request->ccb = ccb;
186 remote_device->is_resetting = TRUE;
188 status = (SCI_STATUS) scif_task_request_construct(
189 controller->scif_controller_handle, remote_device->sci_object,
190 SCI_CONTROLLER_INVALID_IO_TAG, (void *)task_request,
191 (void *)((char*)task_request + sizeof(struct ISCI_TASK_REQUEST)),
192 &task_request->sci_object);
194 if (status != SCI_SUCCESS) {
195 isci_task_request_complete(controller->scif_controller_handle,
196 remote_device->sci_object, task_request->sci_object,
197 (SCI_TASK_STATUS)status);
201 status = (SCI_STATUS)scif_controller_start_task(
202 controller->scif_controller_handle, remote_device->sci_object,
203 task_request->sci_object, SCI_CONTROLLER_INVALID_IO_TAG);
205 if (status != SCI_SUCCESS) {
206 isci_task_request_complete(
207 controller->scif_controller_handle,
208 remote_device->sci_object, task_request->sci_object,
209 (SCI_TASK_STATUS)status);
215 isci_remote_device_get_bitrate(struct ISCI_REMOTE_DEVICE *remote_device)
217 struct ISCI_DOMAIN *domain = remote_device->domain;
218 struct ISCI_CONTROLLER *controller = domain->controller;
219 SCI_PORT_HANDLE_T port_handle;
220 SCIC_PORT_PROPERTIES_T port_properties;
222 SCI_PHY_HANDLE_T phy_handle;
223 SCIC_PHY_PROPERTIES_T phy_properties;
225 /* get a handle to the port associated with this remote device's
228 port_handle = scif_domain_get_scic_port_handle(domain->sci_object);
229 scic_port_get_properties(port_handle, &port_properties);
231 /* get the lowest numbered phy in the port */
233 while ((port_properties.phy_mask != 0) &&
234 !(port_properties.phy_mask & 0x1)) {
237 port_properties.phy_mask >>= 1;
240 /* get the properties for the lowest numbered phy */
241 scic_controller_get_phy_handle(
242 scif_controller_get_scic_handle(controller->scif_controller_handle),
243 phy_index, &phy_handle);
244 scic_phy_get_properties(phy_handle, &phy_properties);
246 switch (phy_properties.negotiated_link_rate) {
259 isci_remote_device_freeze_lun_queue(struct ISCI_REMOTE_DEVICE *remote_device,
262 if (!(remote_device->frozen_lun_mask & (1 << lun))) {
263 struct cam_path *path;
265 xpt_create_path(&path, NULL,
266 cam_sim_path(remote_device->domain->controller->sim),
267 remote_device->index, lun);
268 xpt_freeze_devq(path, 1);
270 remote_device->frozen_lun_mask |= (1 << lun);
275 isci_remote_device_release_lun_queue(struct ISCI_REMOTE_DEVICE *remote_device,
278 if (remote_device->frozen_lun_mask & (1 << lun)) {
279 struct cam_path *path;
281 remote_device->frozen_lun_mask &= ~(1 << lun);
282 xpt_create_path(&path, NULL,
283 cam_sim_path(remote_device->domain->controller->sim),
284 remote_device->index, lun);
285 xpt_release_devq(path, 1, TRUE);
291 isci_remote_device_release_device_queue(
292 struct ISCI_REMOTE_DEVICE *device)
294 if (TAILQ_EMPTY(&device->queued_ccbs)) {
297 for (lun = 0; lun < ISCI_MAX_LUN; lun++)
298 isci_remote_device_release_lun_queue(device, lun);
301 * We cannot unfreeze the devq, because there are still
302 * CCBs in our internal queue that need to be processed
303 * first. Mark this device, and the controller, so that
304 * the first CCB in this device's internal queue will be
305 * resubmitted after the current completion context
308 device->release_queued_ccb = TRUE;
309 device->domain->controller->release_queued_ccbs = TRUE;
311 isci_log_message(1, "ISCI", "schedule %p for release\n",