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.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
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
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.
53 #include <sys/cdefs.h>
54 __FBSDID("$FreeBSD$");
59 * @brief This file contains the implementation of the SCIF_SAS_SMP_PHY
63 #include <dev/isci/scil/scif_sas_controller.h>
64 #include <dev/isci/scil/scif_sas_smp_phy.h>
65 #include <dev/isci/scil/scif_sas_smp_remote_device.h>
67 //******************************************************************************
69 //* P U B L I C M E T H O D S
71 //******************************************************************************
74 * @brief This routine constructs a smp phy object for an expander phy and insert
75 * to owning expander device's smp_phy_list.
76 * @param[in] this_smp_phy The memory space to store a phy
77 * @param[in] owning_device The smp remote device that owns this smp phy.
78 * @param[in] expander_phy_id The expander phy id for this_smp_phy.
81 void scif_sas_smp_phy_construct(
82 SCIF_SAS_SMP_PHY_T * this_smp_phy,
83 SCIF_SAS_REMOTE_DEVICE_T * owning_device,
87 memset(this_smp_phy, 0, sizeof(SCIF_SAS_SMP_PHY_T));
89 this_smp_phy->phy_identifier = expander_phy_id;
90 this_smp_phy->owning_device = owning_device;
92 sci_fast_list_element_init((this_smp_phy), (&this_smp_phy->list_element));
94 //insert to owning device's smp phy list.
95 sci_fast_list_insert_tail(
96 (&owning_device->protocol_device.smp_device.smp_phy_list),
97 (&this_smp_phy->list_element)
102 * @brief This routine destructs a smp phy object for an expander phy and free the smp
103 * phy to controller's smp phy memory.
104 * @param[in] this_smp_phy The smp phy to be destructed.
108 void scif_sas_smp_phy_destruct(
109 SCIF_SAS_SMP_PHY_T * this_smp_phy
112 SCIF_SAS_REMOTE_DEVICE_T * owning_device = this_smp_phy->owning_device;
113 SCIF_SAS_CONTROLLER_T * fw_controller = owning_device->domain->controller;
115 if ( ( this_smp_phy->attached_device_type == SMP_EDGE_EXPANDER_DEVICE
116 || this_smp_phy->attached_device_type == SMP_FANOUT_EXPANDER_DEVICE)
117 && this_smp_phy->u.attached_phy != NULL )
119 //update the counterpart phy from the other smp phy list.
120 this_smp_phy->u.attached_phy->attached_device_type = SMP_NO_DEVICE_ATTACHED;
121 this_smp_phy->u.attached_phy->u.attached_phy = NULL;
124 //remove curr_smp_phy
125 sci_fast_list_remove_element(&this_smp_phy->list_element);
126 scif_sas_controller_free_smp_phy(fw_controller, this_smp_phy);
131 * @brief This routine save a smp phy information based on discover response.
133 * @param[in] this_smp_phy The memory space to store a phy
134 * @param[in] attached_device A possible direct attached device to this phy.
136 * @param[in] discover_response The smp DISCOVER response for this_smp_phy.
139 void scif_sas_smp_phy_save_information(
140 SCIF_SAS_SMP_PHY_T * this_smp_phy,
141 SCIF_SAS_REMOTE_DEVICE_T * attached_device,
142 SMP_RESPONSE_DISCOVER_T * discover_response
145 ASSERT (this_smp_phy->owning_device != NULL);
146 ASSERT (this_smp_phy->phy_identifier == discover_response->phy_identifier);
148 this_smp_phy->attached_device_type = (U8)discover_response->u2.sas1_1.attached_device_type;
149 this_smp_phy->routing_attribute = (U8)discover_response->routing_attribute;
150 this_smp_phy->attached_sas_address = discover_response->attached_sas_address;
151 this_smp_phy->config_route_table_index_anchor = 0;
153 if (this_smp_phy->attached_device_type != SMP_EDGE_EXPANDER_DEVICE
154 && this_smp_phy->attached_device_type != SMP_FANOUT_EXPANDER_DEVICE)
156 //note, end_device field could be an end device, or a NULL value, but can't be expander device.
157 this_smp_phy->u.end_device = attached_device;
161 //if attached device type is expander, we will set u.attached_phy later when the
162 //the attached expander finish its discover on attached_phy.
168 * @brief This routine constructs a smp phy object for an expander phy.
169 * @param[in] this_smp_phy The memory space to store a phy
170 * @param[in] owning_device The smp remote device that owns this smp phy.
171 * @param[in] discover_response The smp DISCOVER response for this_smp_phy.
173 * @return Whether a smp phy has an attached phy and the pair of phy are set
174 * set to each other as attached phy successfully.
176 SCI_STATUS scif_sas_smp_phy_set_attached_phy(
177 SCIF_SAS_SMP_PHY_T * this_smp_phy,
178 U8 attached_phy_identifier,
179 SCIF_SAS_REMOTE_DEVICE_T * attached_remote_device
182 //find the attached phy from its owning device by attached_phy_id.
183 SCIF_SAS_SMP_PHY_T * attached_smp_phy =
184 (SCIF_SAS_SMP_PHY_T *)scif_sas_smp_remote_device_find_smp_phy_by_id(
185 attached_phy_identifier,
186 &attached_remote_device->protocol_device.smp_device);
188 if (attached_smp_phy != NULL)
190 this_smp_phy->u.attached_phy = attached_smp_phy;
191 attached_smp_phy->u.attached_phy = this_smp_phy;
201 * @brief This method verify the routing attributes of a phy connection per
204 * @param[in] this_smp_phy One smp phy belongs to a smp phy connection.
205 * @param[in] attached_smp_phy One smp phy belongs to a smp phy connection.
207 * @return Whether routing attributes of a phy connection is legal.
208 * @retval SCI_SUCCESS indicates a good phy connection.
209 * SCI_FAILURE indicates a illegal phy connection.
211 SCI_STATUS scif_sas_smp_phy_verify_routing_attribute(
212 SCIF_SAS_SMP_PHY_T * this_smp_phy,
213 SCIF_SAS_SMP_PHY_T * attached_smp_phy
216 SCI_STATUS status = SCI_SUCCESS;
218 //expander phy with direct routing attribute can only connect to
219 //phy with direct routing attribute.
220 if ( this_smp_phy->routing_attribute == DIRECT_ROUTING_ATTRIBUTE
221 || attached_smp_phy->routing_attribute == DIRECT_ROUTING_ATTRIBUTE )
223 if ( (this_smp_phy->routing_attribute | attached_smp_phy->routing_attribute)
224 != DIRECT_ROUTING_ATTRIBUTE )
225 status = SCI_FAILURE;
228 if (this_smp_phy->routing_attribute == TABLE_ROUTING_ATTRIBUTE
229 && attached_smp_phy->routing_attribute == TABLE_ROUTING_ATTRIBUTE)
231 if ( ! this_smp_phy->owning_device->protocol_device.smp_device.is_table_to_table_supported
232 || !attached_smp_phy->owning_device->protocol_device.smp_device.is_table_to_table_supported )
233 status = SCI_FAILURE;
241 * @brief This method find The next smp phy that is in the smp phy list and
242 * resides in the same wide port as this_smp_phy.
244 * @param[in] this_smp_phy The smp phy whose neighbor phy that is in the same
245 * same wide port is to be find.
247 * @return The next smp phy that is in the smp phy list and resides in the same
248 * wide port as this_smp_phy.
250 SCIF_SAS_SMP_PHY_T * scif_sas_smp_phy_find_next_phy_in_wide_port(
251 SCIF_SAS_SMP_PHY_T * this_smp_phy
254 SCI_FAST_LIST_ELEMENT_T * next_phy_element = sci_fast_list_get_next(
255 &(this_smp_phy->list_element) );
257 SCIF_SAS_SMP_PHY_T * next_phy;
259 while (next_phy_element != NULL)
261 next_phy = (SCIF_SAS_SMP_PHY_T *)sci_fast_list_get_object(next_phy_element);
263 next_phy_element = sci_fast_list_get_next( &(next_phy->list_element));
265 if (next_phy->attached_sas_address.high == this_smp_phy->attached_sas_address.high
266 &&next_phy->attached_sas_address.low == this_smp_phy->attached_sas_address.low)
275 * @brief This method find the smp phy that resides in the middle of the same
276 * wide port as this_smp_phy.
278 * @param[in] this_smp_phy The smp phy who is the lowest order phy in a wide
281 * @return The next smp phy that is in the smp phy list and resides in the same
282 * wide port as this_smp_phy.
284 SCIF_SAS_SMP_PHY_T * scif_sas_smp_phy_find_middle_phy_in_wide_port(
285 SCIF_SAS_SMP_PHY_T * this_smp_phy
288 SCIF_SAS_SMP_PHY_T * next_phy =
289 scif_sas_smp_phy_find_next_phy_in_wide_port(this_smp_phy);
290 SCIF_SAS_SMP_PHY_T * middle_phy = this_smp_phy;
292 //currently we assume a wide port could not be wider than X4. so the
293 //second phy is always the correct answer for x2, x3 or x4 wide port.
294 //For a narrow port, phy0 is the middle phy.
295 if (next_phy != NULL)
297 middle_phy = next_phy;
299 scif_sas_smp_phy_find_next_phy_in_wide_port(next_phy);
302 if (next_phy != NULL)
303 middle_phy = next_phy;
310 * @brief This method find the smp phy that is the hishest order phy
311 * in the same wide port as this_smp_phy.
313 * @param[in] this_smp_phy The smp phy who is the lowest order phy in a wide
316 * @return The next smp phy that is in the smp phy list and resides in the same
317 * wide port as this_smp_phy.
319 SCIF_SAS_SMP_PHY_T * scif_sas_smp_phy_find_highest_phy_in_wide_port(
320 SCIF_SAS_SMP_PHY_T * this_smp_phy
323 SCIF_SAS_SMP_PHY_T * next_phy =
324 scif_sas_smp_phy_find_next_phy_in_wide_port(this_smp_phy);
325 SCIF_SAS_SMP_PHY_T * highest_phy = this_smp_phy;
327 while(next_phy != NULL )
329 highest_phy = next_phy;
331 scif_sas_smp_phy_find_next_phy_in_wide_port(next_phy);