2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
9 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
23 * The full GNU General Public License is included in this distribution
24 * in the file called LICENSE.GPL.
28 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
35 * * Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * * Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in
39 * the documentation and/or other materials provided with the
42 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 #include <sys/cdefs.h>
56 __FBSDID("$FreeBSD$");
61 * @brief This file contains the protected interface structures, constants,
62 * and methods for the SCIF_SAS_STP_REMOTE_DEVICE object.
65 #include <dev/isci/scil/scif_sas_stp_remote_device.h>
66 #include <dev/isci/scil/scif_sas_remote_device.h>
67 #include <dev/isci/scil/scif_sas_domain.h>
68 #include <dev/isci/scil/scif_sas_controller.h>
69 #include <dev/isci/scil/scif_sas_logger.h>
70 #include <dev/isci/scil/intel_sat.h>
73 * @brief This method performs SATA/STP specific construction of the
74 * STP remote device object.
76 * @param[in] device This parameter specifies the STP remote device
77 * object to be constructed.
81 void scif_sas_stp_remote_device_construct(
82 SCIF_SAS_REMOTE_DEVICE_T * device
85 sati_device_construct(
86 &device->protocol_device.stp_device.sati_device,
87 device->domain->controller->user_parameters.sas.is_sata_ncq_enabled,
88 (U8) device->domain->controller->user_parameters.sas.max_ncq_depth,
89 device->domain->controller->user_parameters.sas.ignore_fua
92 device->protocol_device.stp_device.s_active = 0;
96 * @brief This method attempts to allocate a valid NCQ tag from the list
97 * of available tags in the remote device.
99 * @todo Attempt to find a CLZ like instruction to optimize this routine
100 * down into a few instructions. I know there is one like it for IA.
102 * @param[in] fw_device This parameter specifies the remote device
103 * for which to allocate an available NCQ tag.
105 * @return Return an available NCQ tag.
106 * @retval 0-31 These values indicate an available tag was successfully
108 * @return SCIF_SAS_STP_INVALID_NCQ_TAG This value indicates that there are
109 * no available NCQ tags.
111 U8 scif_sas_stp_remote_device_allocate_ncq_tag(
112 SCIF_SAS_REMOTE_DEVICE_T * fw_device
119 sci_base_object_get_logger(fw_device),
120 SCIF_LOG_OBJECT_REMOTE_DEVICE | SCIF_LOG_OBJECT_IO_REQUEST,
121 "scif_sas_stp_remote_device_allocate_ncq_tag(0x%x)\n",
125 // Try to find an unused NCQ tag.
126 while ( (fw_device->protocol_device.stp_device.s_active & tag_mask)
127 && (ncq_tag < fw_device->protocol_device.stp_device.sati_device.ncq_depth) )
133 // Check to see if we were able to find an available NCQ tag.
134 if (ncq_tag < fw_device->protocol_device.stp_device.sati_device.ncq_depth)
137 sci_base_object_get_logger(fw_device),
138 SCIF_LOG_OBJECT_REMOTE_DEVICE | SCIF_LOG_OBJECT_IO_REQUEST,
139 "RemoteDevice:0x%x NcqTag:0x%x successful NCQ TAG allocation\n",
143 fw_device->protocol_device.stp_device.s_active |= tag_mask;
148 sci_base_object_get_logger(fw_device),
149 SCIF_LOG_OBJECT_REMOTE_DEVICE | SCIF_LOG_OBJECT_IO_REQUEST,
150 "RemoteDevice:0x%x unable to allocate NCQ TAG\n",
154 // All NCQ tags are in use.
155 return SCIF_SAS_INVALID_NCQ_TAG;
159 * @brief This method removes the specified tag from the list of
160 * outstanding tags. It doesn't return any values.
162 * @param[in] fw_device This parameter specifies the remote device for
163 * which to free an NCQ tag.
164 * @param[in] ncq_tag This parameter specifies the NCQ tag that is
169 void scif_sas_stp_remote_device_free_ncq_tag(
170 struct SCIF_SAS_REMOTE_DEVICE * fw_device,
175 sci_base_object_get_logger(fw_device),
176 SCIF_LOG_OBJECT_REMOTE_DEVICE | SCIF_LOG_OBJECT_IO_REQUEST,
177 "RemoteDevice:0x%x NcqTag:0x%x freeing NCQ TAG\n",
181 fw_device->protocol_device.stp_device.s_active &= ~(1 << ncq_tag);
184 struct SCIF_SAS_REQUEST *
185 scif_sas_stp_remote_device_get_request_by_ncq_tag(
186 struct SCIF_SAS_REMOTE_DEVICE * fw_device,
190 SCIF_SAS_DOMAIN_T * fw_domain = fw_device->domain;
191 SCI_FAST_LIST_ELEMENT_T * pending_request_element;
192 SCIF_SAS_REQUEST_T * pending_request = NULL;
193 SCIF_SAS_REQUEST_T * matching_request = NULL;
195 pending_request_element = fw_domain->request_list.list_head;
197 while (pending_request_element != NULL)
200 (SCIF_SAS_REQUEST_T*) sci_fast_list_get_object(pending_request_element);
202 // The current element may be deleted from the list because of
203 // IO completion so advance to the next element early
204 pending_request_element = sci_fast_list_get_next(pending_request_element);
207 (pending_request->device == fw_device) &&
208 (pending_request->stp.sequence.protocol == SAT_PROTOCOL_FPDMA) &&
209 (pending_request->stp.ncq_tag == ncq_tag)
212 matching_request = pending_request;
216 return matching_request;