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.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
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
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.
53 #include <sys/cdefs.h>
54 __FBSDID("$FreeBSD$");
59 * @brief This file contains the protected interface structures, constants,
60 * and methods for the SCIF_SAS_STP_REMOTE_DEVICE object.
63 #include <dev/isci/scil/scif_sas_stp_remote_device.h>
64 #include <dev/isci/scil/scif_sas_remote_device.h>
65 #include <dev/isci/scil/scif_sas_domain.h>
66 #include <dev/isci/scil/scif_sas_controller.h>
67 #include <dev/isci/scil/scif_sas_logger.h>
68 #include <dev/isci/scil/intel_sat.h>
71 * @brief This method performs SATA/STP specific construction of the
72 * STP remote device object.
74 * @param[in] device This parameter specifies the STP remote device
75 * object to be constructed.
79 void scif_sas_stp_remote_device_construct(
80 SCIF_SAS_REMOTE_DEVICE_T * device
83 sati_device_construct(
84 &device->protocol_device.stp_device.sati_device,
85 device->domain->controller->user_parameters.sas.is_sata_ncq_enabled,
86 (U8) device->domain->controller->user_parameters.sas.max_ncq_depth,
87 device->domain->controller->user_parameters.sas.ignore_fua
90 device->protocol_device.stp_device.s_active = 0;
94 * @brief This method attempts to allocate a valid NCQ tag from the list
95 * of available tags in the remote device.
97 * @todo Attempt to find a CLZ like instruction to optimize this routine
98 * down into a few instructions. I know there is one like it for IA.
100 * @param[in] fw_device This parameter specifies the remote device
101 * for which to allocate an available NCQ tag.
103 * @return Return an available NCQ tag.
104 * @retval 0-31 These values indicate an available tag was successfully
106 * @return SCIF_SAS_STP_INVALID_NCQ_TAG This value indicates that there are
107 * no available NCQ tags.
109 U8 scif_sas_stp_remote_device_allocate_ncq_tag(
110 SCIF_SAS_REMOTE_DEVICE_T * fw_device
117 sci_base_object_get_logger(fw_device),
118 SCIF_LOG_OBJECT_REMOTE_DEVICE | SCIF_LOG_OBJECT_IO_REQUEST,
119 "scif_sas_stp_remote_device_allocate_ncq_tag(0x%x)\n",
123 // Try to find an unused NCQ tag.
124 while ( (fw_device->protocol_device.stp_device.s_active & tag_mask)
125 && (ncq_tag < fw_device->protocol_device.stp_device.sati_device.ncq_depth) )
131 // Check to see if we were able to find an available NCQ tag.
132 if (ncq_tag < fw_device->protocol_device.stp_device.sati_device.ncq_depth)
135 sci_base_object_get_logger(fw_device),
136 SCIF_LOG_OBJECT_REMOTE_DEVICE | SCIF_LOG_OBJECT_IO_REQUEST,
137 "RemoteDevice:0x%x NcqTag:0x%x successful NCQ TAG allocation\n",
141 fw_device->protocol_device.stp_device.s_active |= tag_mask;
146 sci_base_object_get_logger(fw_device),
147 SCIF_LOG_OBJECT_REMOTE_DEVICE | SCIF_LOG_OBJECT_IO_REQUEST,
148 "RemoteDevice:0x%x unable to allocate NCQ TAG\n",
152 // All NCQ tags are in use.
153 return SCIF_SAS_INVALID_NCQ_TAG;
157 * @brief This method removes the specified tag from the list of
158 * outstanding tags. It doesn't return any values.
160 * @param[in] fw_device This parameter specifies the remote device for
161 * which to free an NCQ tag.
162 * @param[in] ncq_tag This parameter specifies the NCQ tag that is
167 void scif_sas_stp_remote_device_free_ncq_tag(
168 struct SCIF_SAS_REMOTE_DEVICE * fw_device,
173 sci_base_object_get_logger(fw_device),
174 SCIF_LOG_OBJECT_REMOTE_DEVICE | SCIF_LOG_OBJECT_IO_REQUEST,
175 "RemoteDevice:0x%x NcqTag:0x%x freeing NCQ TAG\n",
179 fw_device->protocol_device.stp_device.s_active &= ~(1 << ncq_tag);
182 struct SCIF_SAS_REQUEST *
183 scif_sas_stp_remote_device_get_request_by_ncq_tag(
184 struct SCIF_SAS_REMOTE_DEVICE * fw_device,
188 SCIF_SAS_DOMAIN_T * fw_domain = fw_device->domain;
189 SCI_FAST_LIST_ELEMENT_T * pending_request_element;
190 SCIF_SAS_REQUEST_T * pending_request = NULL;
191 SCIF_SAS_REQUEST_T * matching_request = NULL;
193 pending_request_element = fw_domain->request_list.list_head;
195 while (pending_request_element != NULL)
198 (SCIF_SAS_REQUEST_T*) sci_fast_list_get_object(pending_request_element);
200 // The current element may be deleted from the list becasue of
201 // IO completion so advance to the next element early
202 pending_request_element = sci_fast_list_get_next(pending_request_element);
205 (pending_request->device == fw_device) &&
206 (pending_request->stp.sequence.protocol == SAT_PROTOCOL_FPDMA) &&
207 (pending_request->stp.ncq_tag == ncq_tag)
210 matching_request = pending_request;
214 return matching_request;