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
39 * * Neither the name of Intel Corporation nor the names of its
40 * contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 #include "scic_sds_port_configuration_agent.h"
60 #define SCIC_SDS_MPC_RECONFIGURATION_TIMEOUT (10)
61 #define SCIC_SDS_APC_RECONFIGURATION_TIMEOUT (10)
62 #define SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION (100)
64 enum SCIC_SDS_APC_ACTIVITY {
65 SCIC_SDS_APC_SKIP_PHY,
67 SCIC_SDS_APC_START_TIMER,
69 SCIC_SDS_APC_ACTIVITY_MAX
73 * ******************************************************************************
74 * General port configuration agent routines
75 * ****************************************************************************** */
79 * @address_one: A SAS Address to be compared.
80 * @address_two: A SAS Address to be compared.
82 * Compare the two SAS Address and if SAS Address One is greater than SAS
83 * Address Two then return > 0 else if SAS Address One is less than SAS Address
84 * Two return < 0 Otherwise they are the same return 0 A signed value of x > 0
85 * > y where x is returned for Address One > Address Two y is returned for
86 * Address One < Address Two 0 is returned ofr Address One = Address Two
88 static s32 sci_sas_address_compare(
89 struct sci_sas_address address_one,
90 struct sci_sas_address address_two)
92 if (address_one.high > address_two.high) {
94 } else if (address_one.high < address_two.high) {
96 } else if (address_one.low > address_two.low) {
98 } else if (address_one.low < address_two.low) {
102 /* The two SAS Address must be identical */
108 * @controller: The controller object used for the port search.
109 * @phy: The phy object to match.
111 * This routine will find a matching port for the phy. This means that the
112 * port and phy both have the same broadcast sas address and same received sas
113 * address. The port address or the NULL if there is no matching
114 * port. port address if the port can be found to match the phy.
115 * NULL if there is no matching port for the phy.
117 static struct scic_sds_port *scic_sds_port_configuration_agent_find_port(
118 struct scic_sds_controller *scic,
119 struct scic_sds_phy *phy)
122 struct sci_sas_address port_sas_address;
123 struct sci_sas_address port_attached_device_address;
124 struct sci_sas_address phy_sas_address;
125 struct sci_sas_address phy_attached_device_address;
128 * Since this phy can be a member of a wide port check to see if one or
129 * more phys match the sent and received SAS address as this phy in which
130 * case it should participate in the same port.
132 scic_sds_phy_get_sas_address(phy, &phy_sas_address);
133 scic_sds_phy_get_attached_sas_address(phy, &phy_attached_device_address);
135 for (i = 0; i < scic->logical_port_entries; i++) {
136 struct isci_host *ihost = scic_to_ihost(scic);
137 struct scic_sds_port *sci_port = &ihost->ports[i].sci;
139 scic_sds_port_get_sas_address(sci_port, &port_sas_address);
140 scic_sds_port_get_attached_sas_address(sci_port, &port_attached_device_address);
142 if (sci_sas_address_compare(port_sas_address, phy_sas_address) == 0 &&
143 sci_sas_address_compare(port_attached_device_address, phy_attached_device_address) == 0)
152 * @controller: This is the controller object that contains the port agent
153 * @port_agent: This is the port configruation agent for the controller.
155 * This routine will validate the port configuration is correct for the SCU
156 * hardware. The SCU hardware allows for port configurations as follows. LP0
157 * -> (PE0), (PE0, PE1), (PE0, PE1, PE2, PE3) LP1 -> (PE1) LP2 -> (PE2), (PE2,
158 * PE3) LP3 -> (PE3) enum sci_status SCI_SUCCESS the port configuration is valid for
159 * this port configuration agent. SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
160 * the port configuration is not valid for this port configuration agent.
162 static enum sci_status scic_sds_port_configuration_agent_validate_ports(
163 struct scic_sds_controller *controller,
164 struct scic_sds_port_configuration_agent *port_agent)
166 struct isci_host *ihost = scic_to_ihost(controller);
167 struct sci_sas_address first_address;
168 struct sci_sas_address second_address;
171 * Sanity check the max ranges for all the phys the max index
172 * is always equal to the port range index */
173 if (port_agent->phy_valid_port_range[0].max_index != 0 ||
174 port_agent->phy_valid_port_range[1].max_index != 1 ||
175 port_agent->phy_valid_port_range[2].max_index != 2 ||
176 port_agent->phy_valid_port_range[3].max_index != 3)
177 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
180 * This is a request to configure a single x4 port or at least attempt
181 * to make all the phys into a single port */
182 if (port_agent->phy_valid_port_range[0].min_index == 0 &&
183 port_agent->phy_valid_port_range[1].min_index == 0 &&
184 port_agent->phy_valid_port_range[2].min_index == 0 &&
185 port_agent->phy_valid_port_range[3].min_index == 0)
189 * This is a degenerate case where phy 1 and phy 2 are assigned
190 * to the same port this is explicitly disallowed by the hardware
191 * unless they are part of the same x4 port and this condition was
192 * already checked above. */
193 if (port_agent->phy_valid_port_range[2].min_index == 1) {
194 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
198 * PE0 and PE3 can never have the same SAS Address unless they
199 * are part of the same x4 wide port and we have already checked
200 * for this condition. */
201 scic_sds_phy_get_sas_address(&ihost->phys[0].sci, &first_address);
202 scic_sds_phy_get_sas_address(&ihost->phys[3].sci, &second_address);
204 if (sci_sas_address_compare(first_address, second_address) == 0) {
205 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
209 * PE0 and PE1 are configured into a 2x1 ports make sure that the
210 * SAS Address for PE0 and PE2 are different since they can not be
211 * part of the same port. */
212 if (port_agent->phy_valid_port_range[0].min_index == 0 &&
213 port_agent->phy_valid_port_range[1].min_index == 1) {
214 scic_sds_phy_get_sas_address(&ihost->phys[0].sci, &first_address);
215 scic_sds_phy_get_sas_address(&ihost->phys[2].sci, &second_address);
217 if (sci_sas_address_compare(first_address, second_address) == 0) {
218 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
223 * PE2 and PE3 are configured into a 2x1 ports make sure that the
224 * SAS Address for PE1 and PE3 are different since they can not be
225 * part of the same port. */
226 if (port_agent->phy_valid_port_range[2].min_index == 2 &&
227 port_agent->phy_valid_port_range[3].min_index == 3) {
228 scic_sds_phy_get_sas_address(&ihost->phys[1].sci, &first_address);
229 scic_sds_phy_get_sas_address(&ihost->phys[3].sci, &second_address);
231 if (sci_sas_address_compare(first_address, second_address) == 0) {
232 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
240 * ******************************************************************************
241 * Manual port configuration agent routines
242 * ****************************************************************************** */
247 * This routine will verify that all of the phys in the same port are using the
250 static enum sci_status scic_sds_mpc_agent_validate_phy_configuration(
251 struct scic_sds_controller *controller,
252 struct scic_sds_port_configuration_agent *port_agent)
254 struct isci_host *ihost = scic_to_ihost(controller);
256 u32 assigned_phy_mask;
257 struct sci_sas_address sas_address;
258 struct sci_sas_address phy_assigned_address;
262 assigned_phy_mask = 0;
263 sas_address.high = 0;
266 for (port_index = 0; port_index < SCI_MAX_PORTS; port_index++) {
267 phy_mask = controller->oem_parameters.sds1.ports[port_index].phy_mask;
272 * Make sure that one or more of the phys were not already assinged to
273 * a different port. */
274 if ((phy_mask & ~assigned_phy_mask) == 0) {
275 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
278 /* Find the starting phy index for this round through the loop */
279 for (phy_index = 0; phy_index < SCI_MAX_PHYS; phy_index++) {
280 if ((phy_mask & (1 << phy_index)) == 0)
282 scic_sds_phy_get_sas_address(&ihost->phys[phy_index].sci,
286 * The phy_index can be used as the starting point for the
287 * port range since the hardware starts all logical ports
288 * the same as the PE index. */
289 port_agent->phy_valid_port_range[phy_index].min_index = port_index;
290 port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
292 if (phy_index != port_index) {
293 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
300 * See how many additional phys are being added to this logical port.
301 * Note: We have not moved the current phy_index so we will actually
302 * compare the startting phy with itself.
303 * This is expected and required to add the phy to the port. */
304 while (phy_index < SCI_MAX_PHYS) {
305 if ((phy_mask & (1 << phy_index)) == 0)
307 scic_sds_phy_get_sas_address(&ihost->phys[phy_index].sci,
308 &phy_assigned_address);
310 if (sci_sas_address_compare(sas_address, phy_assigned_address) != 0) {
312 * The phy mask specified that this phy is part of the same port
313 * as the starting phy and it is not so fail this configuration */
314 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
317 port_agent->phy_valid_port_range[phy_index].min_index = port_index;
318 port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
320 scic_sds_port_add_phy(&ihost->ports[port_index].sci,
321 &ihost->phys[phy_index].sci);
323 assigned_phy_mask |= (1 << phy_index);
329 return scic_sds_port_configuration_agent_validate_ports(controller, port_agent);
335 * This timer routine is used to allow the SCI User to rediscover or change
336 * device objects before a new series of link up notifications because a link
337 * down has allowed a better port configuration.
339 static void scic_sds_mpc_agent_timeout_handler(void *object)
342 struct scic_sds_controller *scic = object;
343 struct isci_host *ihost = scic_to_ihost(scic);
344 struct scic_sds_port_configuration_agent *port_agent = &scic->port_agent;
345 u16 configure_phy_mask;
347 port_agent->timer_pending = false;
349 /* Find the mask of phys that are reported read but as yet unconfigured into a port */
350 configure_phy_mask = ~port_agent->phy_configured_mask & port_agent->phy_ready_mask;
352 for (index = 0; index < SCI_MAX_PHYS; index++) {
353 struct scic_sds_phy *sci_phy = &ihost->phys[index].sci;
355 if (configure_phy_mask & (1 << index)) {
356 port_agent->link_up_handler(scic, port_agent,
357 scic_sds_phy_get_port(sci_phy),
365 * @controller: This is the controller object that receives the link up
367 * @port: This is the port object associated with the phy. If the is no
368 * associated port this is an NULL.
369 * @phy: This is the phy object which has gone ready.
371 * This method handles the manual port configuration link up notifications.
372 * Since all ports and phys are associate at initialization time we just turn
373 * around and notifiy the port object that there is a link up. If this PHY is
374 * not associated with a port there is no action taken. Is it possible to get a
375 * link up notification from a phy that has no assocoated port?
377 static void scic_sds_mpc_agent_link_up(
378 struct scic_sds_controller *controller,
379 struct scic_sds_port_configuration_agent *port_agent,
380 struct scic_sds_port *port,
381 struct scic_sds_phy *phy)
384 * If the port has an invalid handle then the phy was not assigned to
385 * a port. This is because the phy was not given the same SAS Address
386 * as the other PHYs in the port. */
388 port_agent->phy_ready_mask |= (1 << scic_sds_phy_get_index(phy));
390 scic_sds_port_link_up(port, phy);
392 if ((port->active_phy_mask & (1 << scic_sds_phy_get_index(phy))) != 0) {
393 port_agent->phy_configured_mask |= (1 << scic_sds_phy_get_index(phy));
400 * @controller: This is the controller object that receives the link down
402 * @port: This is the port object associated with the phy. If the is no
403 * associated port this is an NULL. The port is an invalid
404 * handle only if the phy was never port of this port. This happens when
405 * the phy is not broadcasting the same SAS address as the other phys in the
407 * @phy: This is the phy object which has gone link down.
409 * This function handles the manual port configuration link down notifications.
410 * Since all ports and phys are associated at initialization time we just turn
411 * around and notifiy the port object of the link down event. If this PHY is
412 * not associated with a port there is no action taken. Is it possible to get a
413 * link down notification from a phy that has no assocoated port?
415 static void scic_sds_mpc_agent_link_down(
416 struct scic_sds_controller *scic,
417 struct scic_sds_port_configuration_agent *port_agent,
418 struct scic_sds_port *sci_port,
419 struct scic_sds_phy *sci_phy)
421 if (sci_port != NULL) {
423 * If we can form a new port from the remainder of the phys
424 * then we want to start the timer to allow the SCI User to
425 * cleanup old devices and rediscover the port before
426 * rebuilding the port with the phys that remain in the ready
429 port_agent->phy_ready_mask &=
430 ~(1 << scic_sds_phy_get_index(sci_phy));
431 port_agent->phy_configured_mask &=
432 ~(1 << scic_sds_phy_get_index(sci_phy));
435 * Check to see if there are more phys waiting to be
436 * configured into a port. If there are allow the SCI User
437 * to tear down this port, if necessary, and then reconstruct
438 * the port after the timeout.
440 if ((port_agent->phy_configured_mask == 0x0000) &&
441 (port_agent->phy_ready_mask != 0x0000) &&
442 !port_agent->timer_pending) {
443 port_agent->timer_pending = true;
445 isci_timer_start(port_agent->timer,
446 SCIC_SDS_MPC_RECONFIGURATION_TIMEOUT);
449 scic_sds_port_link_down(sci_port, sci_phy);
454 * ******************************************************************************
455 * Automatic port configuration agent routines
456 * ****************************************************************************** */
461 * This routine will verify that the phys are assigned a valid SAS address for
462 * automatic port configuration mode.
464 static enum sci_status scic_sds_apc_agent_validate_phy_configuration(
465 struct scic_sds_controller *controller,
466 struct scic_sds_port_configuration_agent *port_agent)
470 struct sci_sas_address sas_address;
471 struct sci_sas_address phy_assigned_address;
472 struct isci_host *ihost = scic_to_ihost(controller);
476 while (phy_index < SCI_MAX_PHYS) {
477 port_index = phy_index;
479 /* Get the assigned SAS Address for the first PHY on the controller. */
480 scic_sds_phy_get_sas_address(&ihost->phys[phy_index].sci,
483 while (++phy_index < SCI_MAX_PHYS) {
484 scic_sds_phy_get_sas_address(&ihost->phys[phy_index].sci,
485 &phy_assigned_address);
487 /* Verify each of the SAS address are all the same for every PHY */
488 if (sci_sas_address_compare(sas_address, phy_assigned_address) == 0) {
489 port_agent->phy_valid_port_range[phy_index].min_index = port_index;
490 port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
492 port_agent->phy_valid_port_range[phy_index].min_index = phy_index;
493 port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
499 return scic_sds_port_configuration_agent_validate_ports(controller, port_agent);
504 * @controller: This is the controller that to which the port agent is assigned.
505 * @port_agent: This is the port agent that is requesting the timer start
507 * @phy: This is the phy that has caused the timer operation to be scheduled.
509 * This routine will restart the automatic port configuration timeout timer for
510 * the next time period. This could be caused by either a link down event or a
511 * link up event where we can not yet tell to which port a phy belongs.
513 static inline void scic_sds_apc_agent_start_timer(
514 struct scic_sds_controller *scic,
515 struct scic_sds_port_configuration_agent *port_agent,
516 struct scic_sds_phy *sci_phy,
519 if (port_agent->timer_pending)
520 isci_timer_stop(port_agent->timer);
522 port_agent->timer_pending = true;
524 isci_timer_start(port_agent->timer, timeout);
529 * @controller: This is the controller object that receives the link up
531 * @phy: This is the phy object which has gone link up.
533 * This method handles the automatic port configuration for link up
536 static void scic_sds_apc_agent_configure_ports(
537 struct scic_sds_controller *controller,
538 struct scic_sds_port_configuration_agent *port_agent,
539 struct scic_sds_phy *phy,
543 enum sci_status status;
544 struct scic_sds_port *port;
545 enum SCIC_SDS_APC_ACTIVITY apc_activity = SCIC_SDS_APC_SKIP_PHY;
546 struct isci_host *ihost = scic_to_ihost(controller);
548 port = scic_sds_port_configuration_agent_find_port(controller, phy);
551 if (scic_sds_port_is_valid_phy_assignment(port, phy->phy_index))
552 apc_activity = SCIC_SDS_APC_ADD_PHY;
554 apc_activity = SCIC_SDS_APC_SKIP_PHY;
557 * There is no matching Port for this PHY so lets search through the
558 * Ports and see if we can add the PHY to its own port or maybe start
559 * the timer and wait to see if a wider port can be made.
561 * Note the break when we reach the condition of the port id == phy id */
563 port_index = port_agent->phy_valid_port_range[phy->phy_index].min_index;
564 port_index <= port_agent->phy_valid_port_range[phy->phy_index].max_index;
568 port = &ihost->ports[port_index].sci;
570 /* First we must make sure that this PHY can be added to this Port. */
571 if (scic_sds_port_is_valid_phy_assignment(port, phy->phy_index)) {
573 * Port contains a PHY with a greater PHY ID than the current
574 * PHY that has gone link up. This phy can not be part of any
575 * port so skip it and move on. */
576 if (port->active_phy_mask > (1 << phy->phy_index)) {
577 apc_activity = SCIC_SDS_APC_SKIP_PHY;
582 * We have reached the end of our Port list and have not found
583 * any reason why we should not either add the PHY to the port
584 * or wait for more phys to become active. */
585 if (port->physical_port_index == phy->phy_index) {
587 * The Port either has no active PHYs.
588 * Consider that if the port had any active PHYs we would have
589 * or active PHYs with
590 * a lower PHY Id than this PHY. */
591 if (apc_activity != SCIC_SDS_APC_START_TIMER) {
592 apc_activity = SCIC_SDS_APC_ADD_PHY;
599 * The current Port has no active PHYs and this PHY could be part
600 * of this Port. Since we dont know as yet setup to start the
601 * timer and see if there is a better configuration. */
602 if (port->active_phy_mask == 0) {
603 apc_activity = SCIC_SDS_APC_START_TIMER;
605 } else if (port->active_phy_mask != 0) {
607 * The Port has an active phy and the current Phy can not
608 * participate in this port so skip the PHY and see if
609 * there is a better configuration. */
610 apc_activity = SCIC_SDS_APC_SKIP_PHY;
616 * Check to see if the start timer operations should instead map to an
617 * add phy operation. This is caused because we have been waiting to
618 * add a phy to a port but could not becuase the automatic port
619 * configuration engine had a choice of possible ports for the phy.
620 * Since we have gone through a timeout we are going to restrict the
621 * choice to the smallest possible port. */
623 (start_timer == false)
624 && (apc_activity == SCIC_SDS_APC_START_TIMER)
626 apc_activity = SCIC_SDS_APC_ADD_PHY;
629 switch (apc_activity) {
630 case SCIC_SDS_APC_ADD_PHY:
631 status = scic_sds_port_add_phy(port, phy);
633 if (status == SCI_SUCCESS) {
634 port_agent->phy_configured_mask |= (1 << phy->phy_index);
638 case SCIC_SDS_APC_START_TIMER:
639 scic_sds_apc_agent_start_timer(
640 controller, port_agent, phy, SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION
644 case SCIC_SDS_APC_SKIP_PHY:
646 /* do nothing the PHY can not be made part of a port at this time. */
652 * scic_sds_apc_agent_link_up - handle apc link up events
653 * @scic: This is the controller object that receives the link up
655 * @sci_port: This is the port object associated with the phy. If the is no
656 * associated port this is an NULL.
657 * @sci_phy: This is the phy object which has gone link up.
659 * This method handles the automatic port configuration for link up
660 * notifications. Is it possible to get a link down notification from a phy
661 * that has no assocoated port?
663 static void scic_sds_apc_agent_link_up(struct scic_sds_controller *scic,
664 struct scic_sds_port_configuration_agent *port_agent,
665 struct scic_sds_port *sci_port,
666 struct scic_sds_phy *sci_phy)
668 u8 phy_index = sci_phy->phy_index;
671 /* the phy is not the part of this port */
672 port_agent->phy_ready_mask |= 1 << phy_index;
673 scic_sds_apc_agent_configure_ports(scic, port_agent, sci_phy, true);
675 /* the phy is already the part of the port */
676 u32 port_state = sci_port->state_machine.current_state_id;
678 /* if the PORT'S state is resetting then the link up is from
679 * port hard reset in this case, we need to tell the port
680 * that link up is recieved
682 BUG_ON(port_state != SCI_BASE_PORT_STATE_RESETTING);
683 port_agent->phy_ready_mask |= 1 << phy_index;
684 scic_sds_port_link_up(sci_port, sci_phy);
690 * @controller: This is the controller object that receives the link down
692 * @port: This is the port object associated with the phy. If the is no
693 * associated port this is an NULL.
694 * @phy: This is the phy object which has gone link down.
696 * This method handles the automatic port configuration link down
697 * notifications. not associated with a port there is no action taken. Is it
698 * possible to get a link down notification from a phy that has no assocoated
701 static void scic_sds_apc_agent_link_down(
702 struct scic_sds_controller *controller,
703 struct scic_sds_port_configuration_agent *port_agent,
704 struct scic_sds_port *port,
705 struct scic_sds_phy *phy)
707 port_agent->phy_ready_mask &= ~(1 << scic_sds_phy_get_index(phy));
710 if (port_agent->phy_configured_mask & (1 << phy->phy_index)) {
711 enum sci_status status;
713 status = scic_sds_port_remove_phy(port, phy);
715 if (status == SCI_SUCCESS) {
716 port_agent->phy_configured_mask &= ~(1 << phy->phy_index);
722 /* configure the phys into ports when the timer fires */
723 static void scic_sds_apc_agent_timeout_handler(void *object)
726 struct scic_sds_port_configuration_agent *port_agent;
727 struct scic_sds_controller *scic = object;
728 struct isci_host *ihost = scic_to_ihost(scic);
729 u16 configure_phy_mask;
731 port_agent = scic_sds_controller_get_port_configuration_agent(scic);
733 port_agent->timer_pending = false;
735 configure_phy_mask = ~port_agent->phy_configured_mask & port_agent->phy_ready_mask;
737 if (!configure_phy_mask)
740 for (index = 0; index < SCI_MAX_PHYS; index++) {
741 if ((configure_phy_mask & (1 << index)) == 0)
744 scic_sds_apc_agent_configure_ports(scic, port_agent,
745 &ihost->phys[index].sci, false);
750 * ******************************************************************************
751 * Public port configuration agent routines
752 * ****************************************************************************** */
757 * This method will construct the port configuration agent for operation. This
758 * call is universal for both manual port configuration and automatic port
759 * configuration modes.
761 void scic_sds_port_configuration_agent_construct(
762 struct scic_sds_port_configuration_agent *port_agent)
766 port_agent->phy_configured_mask = 0x00;
767 port_agent->phy_ready_mask = 0x00;
769 port_agent->link_up_handler = NULL;
770 port_agent->link_down_handler = NULL;
772 port_agent->timer_pending = false;
773 port_agent->timer = NULL;
775 for (index = 0; index < SCI_MAX_PORTS; index++) {
776 port_agent->phy_valid_port_range[index].min_index = 0;
777 port_agent->phy_valid_port_range[index].max_index = 0;
781 enum sci_status scic_sds_port_configuration_agent_initialize(
782 struct scic_sds_controller *scic,
783 struct scic_sds_port_configuration_agent *port_agent)
785 enum sci_status status = SCI_SUCCESS;
786 enum scic_port_configuration_mode mode;
787 struct isci_host *ihost = scic_to_ihost(scic);
789 mode = scic->oem_parameters.sds1.controller.mode_type;
791 if (mode == SCIC_PORT_MANUAL_CONFIGURATION_MODE) {
792 status = scic_sds_mpc_agent_validate_phy_configuration(
795 port_agent->link_up_handler = scic_sds_mpc_agent_link_up;
796 port_agent->link_down_handler = scic_sds_mpc_agent_link_down;
798 port_agent->timer = isci_timer_create(
801 scic_sds_mpc_agent_timeout_handler);
803 status = scic_sds_apc_agent_validate_phy_configuration(
806 port_agent->link_up_handler = scic_sds_apc_agent_link_up;
807 port_agent->link_down_handler = scic_sds_apc_agent_link_down;
809 port_agent->timer = isci_timer_create(
812 scic_sds_apc_agent_timeout_handler);
815 /* Make sure we have actually gotten a timer */
816 if ((status == SCI_SUCCESS) && (port_agent->timer == NULL)) {
817 dev_err(scic_to_dev(scic),
818 "%s: Controller 0x%p automatic port configuration "
819 "agent could not get timer.\n",
823 status = SCI_FAILURE;