scif_sas_high_priority_request_queue.c revision 230557
1271294Sngie/*-
2271294Sngie * This file is provided under a dual BSD/GPLv2 license.  When using or
3271294Sngie * redistributing this file, you may do so under either license.
4271294Sngie *
5271294Sngie * GPL LICENSE SUMMARY
6271294Sngie *
7271294Sngie * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8271294Sngie *
9271294Sngie * This program is free software; you can redistribute it and/or modify
10271294Sngie * it under the terms of version 2 of the GNU General Public License as
11271294Sngie * published by the Free Software Foundation.
12271294Sngie *
13271294Sngie * This program is distributed in the hope that it will be useful, but
14271294Sngie * WITHOUT ANY WARRANTY; without even the implied warranty of
15271294Sngie * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16271294Sngie * General Public License for more details.
17271294Sngie *
18271294Sngie * You should have received a copy of the GNU General Public License
19271294Sngie * along with this program; if not, write to the Free Software
20271294Sngie * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21271294Sngie * The full GNU General Public License is included in this distribution
22271294Sngie * in the file called LICENSE.GPL.
23271294Sngie *
24271294Sngie * BSD LICENSE
25271294Sngie *
26271294Sngie * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27271294Sngie * All rights reserved.
28271294Sngie *
29271294Sngie * Redistribution and use in source and binary forms, with or without
30271294Sngie * modification, are permitted provided that the following conditions
31271294Sngie * are met:
32271294Sngie *
33271294Sngie *   * Redistributions of source code must retain the above copyright
34271294Sngie *     notice, this list of conditions and the following disclaimer.
35271294Sngie *   * Redistributions in binary form must reproduce the above copyright
36271294Sngie *     notice, this list of conditions and the following disclaimer in
37271294Sngie *     the documentation and/or other materials provided with the
38271294Sngie *     distribution.
39271294Sngie *
40271294Sngie * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41271294Sngie * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42271294Sngie * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43271294Sngie * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44271294Sngie * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45271294Sngie * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46271294Sngie * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47271294Sngie * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48271294Sngie * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49271294Sngie * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50271294Sngie * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51271294Sngie */
52271294Sngie
53271294Sngie#include <sys/cdefs.h>
54271294Sngie__FBSDID("$FreeBSD$");
55271294Sngie
56271294Sngie/**
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 */
81void 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 */
111void 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