1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3 *
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.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
10 *
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.
14 *
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.
19 *
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.
25 *
26 * BSD LICENSE
27 *
28 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29 * All rights reserved.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 *
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
40 * distribution.
41 *
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.
53 */
54
55 #include <sys/cdefs.h>
56 /**
57 * @file
58 *
59 * @brief This file contains all of method implementations specific to
60 * the high priority request queue (HPRQ). See the
61 * scif_sas_high_priority_request_queue.h file for additional
62 * information.
63 */
64
65 #include <dev/isci/scil/scif_sas_high_priority_request_queue.h>
66
67 #include <dev/isci/scil/scif_sas_logger.h>
68 #include <dev/isci/scil/scif_sas_io_request.h>
69 #include <dev/isci/scil/scif_sas_controller.h>
70
71 /**
72 * @brief This method initializes the fields of the HPRQ. It should be
73 * called during the construction of the object containing or
74 * utilizing it (i.e. SCIF_SAS_CONTROLLER).
75 *
76 * @param[in] fw_hprq This parameter specific the high priority request
77 * queue object being constructed.
78 *
79 * @return none
80 */
scif_sas_high_priority_request_queue_construct(SCIF_SAS_HIGH_PRIORITY_REQUEST_QUEUE_T * fw_hprq,SCI_BASE_LOGGER_T * logger)81 void scif_sas_high_priority_request_queue_construct(
82 SCIF_SAS_HIGH_PRIORITY_REQUEST_QUEUE_T * fw_hprq,
83 SCI_BASE_LOGGER_T * logger
84 )
85 {
86 SCIF_LOG_TRACE((
87 logger,
88 SCIF_LOG_OBJECT_CONTROLLER | SCIF_LOG_OBJECT_DOMAIN_DISCOVERY,
89 "scif_sas_high_priority_request_queue_construct(0x%x,0x%x) enter\n",
90 fw_hprq, logger
91 ));
92
93 sci_base_object_construct((SCI_BASE_OBJECT_T*) &fw_hprq->lock, logger);
94 fw_hprq->lock.level = SCI_LOCK_LEVEL_NONE;
95
96 sci_pool_initialize(fw_hprq->pool);
97 }
98
99 /**
100 * @brief This method will ensure all internal requests destined for
101 * devices contained in the supplied domain are properly removed
102 * from the high priority request queue.
103 *
104 * @param[in] fw_hprq This parameter specifies the high priority request
105 * queue object for which to attempt to remove elements.
106 * @param[in] fw_domain This parameter specifies the domain for which to
107 * remove all high priority requests.
108 *
109 * @return none
110 */
scif_sas_high_priority_request_queue_purge_domain(SCIF_SAS_HIGH_PRIORITY_REQUEST_QUEUE_T * fw_hprq,SCIF_SAS_DOMAIN_T * fw_domain)111 void scif_sas_high_priority_request_queue_purge_domain(
112 SCIF_SAS_HIGH_PRIORITY_REQUEST_QUEUE_T * fw_hprq,
113 SCIF_SAS_DOMAIN_T * fw_domain
114 )
115 {
116 SCIF_SAS_IO_REQUEST_T * fw_io;
117 POINTER_UINT io_address;
118 U32 index;
119 U32 element_count;
120
121 SCIF_LOG_TRACE((
122 sci_base_object_get_logger(&fw_hprq->lock),
123 SCIF_LOG_OBJECT_CONTROLLER | SCIF_LOG_OBJECT_DOMAIN_DISCOVERY,
124 "scif_sas_high_priority_request_queue_purge_domain(0x%x,0x%x) enter\n",
125 fw_hprq, fw_domain
126 ));
127
128 element_count = sci_pool_count(fw_hprq->pool);
129
130 scif_cb_lock_acquire(fw_domain->controller, &fw_hprq->lock);
131
132 for (index = 0; index < element_count; index++)
133 {
134 sci_pool_get(fw_hprq->pool, io_address);
135
136 fw_io = (SCIF_SAS_IO_REQUEST_T*) io_address;
137
138 // If the high priority request is not intended for this domain,
139 // then it can be left in the pool.
140 if (fw_io->parent.device->domain != fw_domain)
141 {
142 sci_pool_put(fw_hprq->pool, io_address);
143 }
144 else
145 {
146 if (fw_io->parent.is_internal)
147 {
148 SCIF_SAS_INTERNAL_IO_REQUEST_T * fw_internal_io =
149 (SCIF_SAS_INTERNAL_IO_REQUEST_T *)fw_io;
150
151 // The request was intended for a device in the domain. Put it
152 // back in the pool of freely available internal request memory
153 // objects. The internal IO's timer is to be destoyed.
154 scif_sas_internal_io_request_destruct(fw_domain->controller, fw_internal_io);
155 }
156 }
157 }
158
159 scif_cb_lock_release(fw_domain->controller, &fw_hprq->lock);
160 }
161
162