]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/dev/isci/scil/scif_sas_high_priority_request_queue.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / dev / isci / scil / scif_sas_high_priority_request_queue.c
1 /*-
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.
4  *
5  * GPL LICENSE SUMMARY
6  *
7  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8  *
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.
12  *
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.
17  *
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.
23  *
24  * BSD LICENSE
25  *
26  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without
30  * modification, are permitted provided that the following conditions
31  * are met:
32  *
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
38  *     distribution.
39  *
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.
51  */
52
53 #include <sys/cdefs.h>
54 __FBSDID("$FreeBSD$");
55
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  */
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  */
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