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 implementation of the SCIF_SAS_SMP_PHY
65 #include <dev/isci/scil/scif_sas_controller.h>
66 #include <dev/isci/scil/scif_sas_smp_phy.h>
67 #include <dev/isci/scil/scif_sas_smp_remote_device.h>
69 //******************************************************************************
71 //* P U B L I C M E T H O D S
73 //******************************************************************************
76 * @brief This routine constructs a smp phy object for an expander phy and insert
77 * to owning expander device's smp_phy_list.
78 * @param[in] this_smp_phy The memory space to store a phy
79 * @param[in] owning_device The smp remote device that owns this smp phy.
80 * @param[in] expander_phy_id The expander phy id for this_smp_phy.
83 void scif_sas_smp_phy_construct(
84 SCIF_SAS_SMP_PHY_T * this_smp_phy,
85 SCIF_SAS_REMOTE_DEVICE_T * owning_device,
89 memset(this_smp_phy, 0, sizeof(SCIF_SAS_SMP_PHY_T));
91 this_smp_phy->phy_identifier = expander_phy_id;
92 this_smp_phy->owning_device = owning_device;
94 sci_fast_list_element_init((this_smp_phy), (&this_smp_phy->list_element));
96 //insert to owning device's smp phy list.
97 sci_fast_list_insert_tail(
98 (&owning_device->protocol_device.smp_device.smp_phy_list),
99 (&this_smp_phy->list_element)
104 * @brief This routine destructs a smp phy object for an expander phy and free the smp
105 * phy to controller's smp phy memory.
106 * @param[in] this_smp_phy The smp phy to be destructed.
110 void scif_sas_smp_phy_destruct(
111 SCIF_SAS_SMP_PHY_T * this_smp_phy
114 SCIF_SAS_REMOTE_DEVICE_T * owning_device = this_smp_phy->owning_device;
115 SCIF_SAS_CONTROLLER_T * fw_controller = owning_device->domain->controller;
117 if ( ( this_smp_phy->attached_device_type == SMP_EDGE_EXPANDER_DEVICE
118 || this_smp_phy->attached_device_type == SMP_FANOUT_EXPANDER_DEVICE)
119 && this_smp_phy->u.attached_phy != NULL )
121 //update the counterpart phy from the other smp phy list.
122 this_smp_phy->u.attached_phy->attached_device_type = SMP_NO_DEVICE_ATTACHED;
123 this_smp_phy->u.attached_phy->u.attached_phy = NULL;
126 //remove curr_smp_phy
127 sci_fast_list_remove_element(&this_smp_phy->list_element);
128 scif_sas_controller_free_smp_phy(fw_controller, this_smp_phy);
133 * @brief This routine save a smp phy information based on discover response.
135 * @param[in] this_smp_phy The memory space to store a phy
136 * @param[in] attached_device A possible direct attached device to this phy.
138 * @param[in] discover_response The smp DISCOVER response for this_smp_phy.
141 void scif_sas_smp_phy_save_information(
142 SCIF_SAS_SMP_PHY_T * this_smp_phy,
143 SCIF_SAS_REMOTE_DEVICE_T * attached_device,
144 SMP_RESPONSE_DISCOVER_T * discover_response
147 ASSERT (this_smp_phy->owning_device != NULL);
148 ASSERT (this_smp_phy->phy_identifier == discover_response->phy_identifier);
150 this_smp_phy->attached_device_type = (U8)discover_response->u2.sas1_1.attached_device_type;
151 this_smp_phy->routing_attribute = (U8)discover_response->routing_attribute;
152 this_smp_phy->attached_sas_address = discover_response->attached_sas_address;
153 this_smp_phy->config_route_table_index_anchor = 0;
155 if (this_smp_phy->attached_device_type != SMP_EDGE_EXPANDER_DEVICE
156 && this_smp_phy->attached_device_type != SMP_FANOUT_EXPANDER_DEVICE)
158 //note, end_device field could be an end device, or a NULL value, but can't be expander device.
159 this_smp_phy->u.end_device = attached_device;
163 //if attached device type is expander, we will set u.attached_phy later when the
164 //the attached expander finish its discover on attached_phy.
170 * @brief This routine constructs a smp phy object for an expander phy.
171 * @param[in] this_smp_phy The memory space to store a phy
172 * @param[in] owning_device The smp remote device that owns this smp phy.
173 * @param[in] discover_response The smp DISCOVER response for this_smp_phy.
175 * @return Whether a smp phy has an attached phy and the pair of phy are set
176 * set to each other as attached phy successfully.
178 SCI_STATUS scif_sas_smp_phy_set_attached_phy(
179 SCIF_SAS_SMP_PHY_T * this_smp_phy,
180 U8 attached_phy_identifier,
181 SCIF_SAS_REMOTE_DEVICE_T * attached_remote_device
184 //find the attached phy from its owning device by attached_phy_id.
185 SCIF_SAS_SMP_PHY_T * attached_smp_phy =
186 (SCIF_SAS_SMP_PHY_T *)scif_sas_smp_remote_device_find_smp_phy_by_id(
187 attached_phy_identifier,
188 &attached_remote_device->protocol_device.smp_device);
190 if (attached_smp_phy != NULL)
192 this_smp_phy->u.attached_phy = attached_smp_phy;
193 attached_smp_phy->u.attached_phy = this_smp_phy;
203 * @brief This method verify the routing attributes of a phy connection per
206 * @param[in] this_smp_phy One smp phy belongs to a smp phy connection.
207 * @param[in] attached_smp_phy One smp phy belongs to a smp phy connection.
209 * @return Whether routing attributes of a phy connection is legal.
210 * @retval SCI_SUCCESS indicates a good phy connection.
211 * SCI_FAILURE indicates a illegal phy connection.
213 SCI_STATUS scif_sas_smp_phy_verify_routing_attribute(
214 SCIF_SAS_SMP_PHY_T * this_smp_phy,
215 SCIF_SAS_SMP_PHY_T * attached_smp_phy
218 SCI_STATUS status = SCI_SUCCESS;
220 //expander phy with direct routing attribute can only connect to
221 //phy with direct routing attribute.
222 if ( this_smp_phy->routing_attribute == DIRECT_ROUTING_ATTRIBUTE
223 || attached_smp_phy->routing_attribute == DIRECT_ROUTING_ATTRIBUTE )
225 if ( (this_smp_phy->routing_attribute | attached_smp_phy->routing_attribute)
226 != DIRECT_ROUTING_ATTRIBUTE )
227 status = SCI_FAILURE;
230 if (this_smp_phy->routing_attribute == TABLE_ROUTING_ATTRIBUTE
231 && attached_smp_phy->routing_attribute == TABLE_ROUTING_ATTRIBUTE)
233 if ( ! this_smp_phy->owning_device->protocol_device.smp_device.is_table_to_table_supported
234 || !attached_smp_phy->owning_device->protocol_device.smp_device.is_table_to_table_supported )
235 status = SCI_FAILURE;
243 * @brief This method find The next smp phy that is in the smp phy list and
244 * resides in the same wide port as this_smp_phy.
246 * @param[in] this_smp_phy The smp phy whose neighbor phy that is in the same
247 * same wide port is to be find.
249 * @return The next smp phy that is in the smp phy list and resides in the same
250 * wide port as this_smp_phy.
252 SCIF_SAS_SMP_PHY_T * scif_sas_smp_phy_find_next_phy_in_wide_port(
253 SCIF_SAS_SMP_PHY_T * this_smp_phy
256 SCI_FAST_LIST_ELEMENT_T * next_phy_element = sci_fast_list_get_next(
257 &(this_smp_phy->list_element) );
259 SCIF_SAS_SMP_PHY_T * next_phy;
261 while (next_phy_element != NULL)
263 next_phy = (SCIF_SAS_SMP_PHY_T *)sci_fast_list_get_object(next_phy_element);
265 next_phy_element = sci_fast_list_get_next( &(next_phy->list_element));
267 if (next_phy->attached_sas_address.high == this_smp_phy->attached_sas_address.high
268 &&next_phy->attached_sas_address.low == this_smp_phy->attached_sas_address.low)
277 * @brief This method find the smp phy that resides in the middle of the same
278 * wide port as this_smp_phy.
280 * @param[in] this_smp_phy The smp phy who is the lowest order phy in a wide
283 * @return The next smp phy that is in the smp phy list and resides in the same
284 * wide port as this_smp_phy.
286 SCIF_SAS_SMP_PHY_T * scif_sas_smp_phy_find_middle_phy_in_wide_port(
287 SCIF_SAS_SMP_PHY_T * this_smp_phy
290 SCIF_SAS_SMP_PHY_T * next_phy =
291 scif_sas_smp_phy_find_next_phy_in_wide_port(this_smp_phy);
292 SCIF_SAS_SMP_PHY_T * middle_phy = this_smp_phy;
294 //currently we assume a wide port could not be wider than X4. so the
295 //second phy is always the correct answer for x2, x3 or x4 wide port.
296 //For a narrow port, phy0 is the middle phy.
297 if (next_phy != NULL)
299 middle_phy = next_phy;
301 scif_sas_smp_phy_find_next_phy_in_wide_port(next_phy);
304 if (next_phy != NULL)
305 middle_phy = next_phy;
312 * @brief This method find the smp phy that is the hishest order phy
313 * in the same wide port as this_smp_phy.
315 * @param[in] this_smp_phy The smp phy who is the lowest order phy in a wide
318 * @return The next smp phy that is in the smp phy list and resides in the same
319 * wide port as this_smp_phy.
321 SCIF_SAS_SMP_PHY_T * scif_sas_smp_phy_find_highest_phy_in_wide_port(
322 SCIF_SAS_SMP_PHY_T * this_smp_phy
325 SCIF_SAS_SMP_PHY_T * next_phy =
326 scif_sas_smp_phy_find_next_phy_in_wide_port(this_smp_phy);
327 SCIF_SAS_SMP_PHY_T * highest_phy = this_smp_phy;
329 while(next_phy != NULL )
331 highest_phy = next_phy;
333 scif_sas_smp_phy_find_next_phy_in_wide_port(next_phy);