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.
59 #define SCIC_SDS_MPC_RECONFIGURATION_TIMEOUT (10)
60 #define SCIC_SDS_APC_RECONFIGURATION_TIMEOUT (10)
61 #define SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION (100)
63 enum SCIC_SDS_APC_ACTIVITY {
64 SCIC_SDS_APC_SKIP_PHY,
66 SCIC_SDS_APC_START_TIMER,
68 SCIC_SDS_APC_ACTIVITY_MAX
72 * ******************************************************************************
73 * General port configuration agent routines
74 * ****************************************************************************** */
78 * @address_one: A SAS Address to be compared.
79 * @address_two: A SAS Address to be compared.
81 * Compare the two SAS Address and if SAS Address One is greater than SAS
82 * Address Two then return > 0 else if SAS Address One is less than SAS Address
83 * Two return < 0 Otherwise they are the same return 0 A signed value of x > 0
84 * > y where x is returned for Address One > Address Two y is returned for
85 * Address One < Address Two 0 is returned ofr Address One = Address Two
87 static s32 sci_sas_address_compare(
88 struct sci_sas_address address_one,
89 struct sci_sas_address address_two)
91 if (address_one.high > address_two.high) {
93 } else if (address_one.high < address_two.high) {
95 } else if (address_one.low > address_two.low) {
97 } else if (address_one.low < address_two.low) {
101 /* The two SAS Address must be identical */
107 * @controller: The controller object used for the port search.
108 * @phy: The phy object to match.
110 * This routine will find a matching port for the phy. This means that the
111 * port and phy both have the same broadcast sas address and same received sas
112 * address. The port address or the NULL if there is no matching
113 * port. port address if the port can be found to match the phy.
114 * NULL if there is no matching port for the phy.
116 static struct scic_sds_port *scic_sds_port_configuration_agent_find_port(
117 struct scic_sds_controller *scic,
118 struct scic_sds_phy *phy)
121 struct sci_sas_address port_sas_address;
122 struct sci_sas_address port_attached_device_address;
123 struct sci_sas_address phy_sas_address;
124 struct sci_sas_address phy_attached_device_address;
127 * Since this phy can be a member of a wide port check to see if one or
128 * more phys match the sent and received SAS address as this phy in which
129 * case it should participate in the same port.
131 scic_sds_phy_get_sas_address(phy, &phy_sas_address);
132 scic_sds_phy_get_attached_sas_address(phy, &phy_attached_device_address);
134 for (i = 0; i < scic->logical_port_entries; i++) {
135 struct isci_host *ihost = scic_to_ihost(scic);
136 struct scic_sds_port *sci_port = &ihost->ports[i].sci;
138 scic_sds_port_get_sas_address(sci_port, &port_sas_address);
139 scic_sds_port_get_attached_sas_address(sci_port, &port_attached_device_address);
141 if (sci_sas_address_compare(port_sas_address, phy_sas_address) == 0 &&
142 sci_sas_address_compare(port_attached_device_address, phy_attached_device_address) == 0)
151 * @controller: This is the controller object that contains the port agent
152 * @port_agent: This is the port configruation agent for the controller.
154 * This routine will validate the port configuration is correct for the SCU
155 * hardware. The SCU hardware allows for port configurations as follows. LP0
156 * -> (PE0), (PE0, PE1), (PE0, PE1, PE2, PE3) LP1 -> (PE1) LP2 -> (PE2), (PE2,
157 * PE3) LP3 -> (PE3) enum sci_status SCI_SUCCESS the port configuration is valid for
158 * this port configuration agent. SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
159 * the port configuration is not valid for this port configuration agent.
161 static enum sci_status scic_sds_port_configuration_agent_validate_ports(
162 struct scic_sds_controller *controller,
163 struct scic_sds_port_configuration_agent *port_agent)
165 struct isci_host *ihost = scic_to_ihost(controller);
166 struct sci_sas_address first_address;
167 struct sci_sas_address second_address;
170 * Sanity check the max ranges for all the phys the max index
171 * is always equal to the port range index */
172 if (port_agent->phy_valid_port_range[0].max_index != 0 ||
173 port_agent->phy_valid_port_range[1].max_index != 1 ||
174 port_agent->phy_valid_port_range[2].max_index != 2 ||
175 port_agent->phy_valid_port_range[3].max_index != 3)
176 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
179 * This is a request to configure a single x4 port or at least attempt
180 * to make all the phys into a single port */
181 if (port_agent->phy_valid_port_range[0].min_index == 0 &&
182 port_agent->phy_valid_port_range[1].min_index == 0 &&
183 port_agent->phy_valid_port_range[2].min_index == 0 &&
184 port_agent->phy_valid_port_range[3].min_index == 0)
188 * This is a degenerate case where phy 1 and phy 2 are assigned
189 * to the same port this is explicitly disallowed by the hardware
190 * unless they are part of the same x4 port and this condition was
191 * already checked above. */
192 if (port_agent->phy_valid_port_range[2].min_index == 1) {
193 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
197 * PE0 and PE3 can never have the same SAS Address unless they
198 * are part of the same x4 wide port and we have already checked
199 * for this condition. */
200 scic_sds_phy_get_sas_address(&ihost->phys[0].sci, &first_address);
201 scic_sds_phy_get_sas_address(&ihost->phys[3].sci, &second_address);
203 if (sci_sas_address_compare(first_address, second_address) == 0) {
204 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
208 * PE0 and PE1 are configured into a 2x1 ports make sure that the
209 * SAS Address for PE0 and PE2 are different since they can not be
210 * part of the same port. */
211 if (port_agent->phy_valid_port_range[0].min_index == 0 &&
212 port_agent->phy_valid_port_range[1].min_index == 1) {
213 scic_sds_phy_get_sas_address(&ihost->phys[0].sci, &first_address);
214 scic_sds_phy_get_sas_address(&ihost->phys[2].sci, &second_address);
216 if (sci_sas_address_compare(first_address, second_address) == 0) {
217 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
222 * PE2 and PE3 are configured into a 2x1 ports make sure that the
223 * SAS Address for PE1 and PE3 are different since they can not be
224 * part of the same port. */
225 if (port_agent->phy_valid_port_range[2].min_index == 2 &&
226 port_agent->phy_valid_port_range[3].min_index == 3) {
227 scic_sds_phy_get_sas_address(&ihost->phys[1].sci, &first_address);
228 scic_sds_phy_get_sas_address(&ihost->phys[3].sci, &second_address);
230 if (sci_sas_address_compare(first_address, second_address) == 0) {
231 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
239 * ******************************************************************************
240 * Manual port configuration agent routines
241 * ****************************************************************************** */
246 * This routine will verify that all of the phys in the same port are using the
249 static enum sci_status scic_sds_mpc_agent_validate_phy_configuration(
250 struct scic_sds_controller *controller,
251 struct scic_sds_port_configuration_agent *port_agent)
253 struct isci_host *ihost = scic_to_ihost(controller);
255 u32 assigned_phy_mask;
256 struct sci_sas_address sas_address;
257 struct sci_sas_address phy_assigned_address;
261 assigned_phy_mask = 0;
262 sas_address.high = 0;
265 for (port_index = 0; port_index < SCI_MAX_PORTS; port_index++) {
266 phy_mask = controller->oem_parameters.sds1.ports[port_index].phy_mask;
271 * Make sure that one or more of the phys were not already assinged to
272 * a different port. */
273 if ((phy_mask & ~assigned_phy_mask) == 0) {
274 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
277 /* Find the starting phy index for this round through the loop */
278 for (phy_index = 0; phy_index < SCI_MAX_PHYS; phy_index++) {
279 if ((phy_mask & (1 << phy_index)) == 0)
281 scic_sds_phy_get_sas_address(&ihost->phys[phy_index].sci,
285 * The phy_index can be used as the starting point for the
286 * port range since the hardware starts all logical ports
287 * the same as the PE index. */
288 port_agent->phy_valid_port_range[phy_index].min_index = port_index;
289 port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
291 if (phy_index != port_index) {
292 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
299 * See how many additional phys are being added to this logical port.
300 * Note: We have not moved the current phy_index so we will actually
301 * compare the startting phy with itself.
302 * This is expected and required to add the phy to the port. */
303 while (phy_index < SCI_MAX_PHYS) {
304 if ((phy_mask & (1 << phy_index)) == 0)
306 scic_sds_phy_get_sas_address(&ihost->phys[phy_index].sci,
307 &phy_assigned_address);
309 if (sci_sas_address_compare(sas_address, phy_assigned_address) != 0) {
311 * The phy mask specified that this phy is part of the same port
312 * as the starting phy and it is not so fail this configuration */
313 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
316 port_agent->phy_valid_port_range[phy_index].min_index = port_index;
317 port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
319 scic_sds_port_add_phy(&ihost->ports[port_index].sci,
320 &ihost->phys[phy_index].sci);
322 assigned_phy_mask |= (1 << phy_index);
328 return scic_sds_port_configuration_agent_validate_ports(controller, port_agent);
334 * This timer routine is used to allow the SCI User to rediscover or change
335 * device objects before a new series of link up notifications because a link
336 * down has allowed a better port configuration.
338 static void scic_sds_mpc_agent_timeout_handler(void *object)
341 struct scic_sds_controller *scic = object;
342 struct isci_host *ihost = scic_to_ihost(scic);
343 struct scic_sds_port_configuration_agent *port_agent = &scic->port_agent;
344 u16 configure_phy_mask;
346 port_agent->timer_pending = false;
348 /* Find the mask of phys that are reported read but as yet unconfigured into a port */
349 configure_phy_mask = ~port_agent->phy_configured_mask & port_agent->phy_ready_mask;
351 for (index = 0; index < SCI_MAX_PHYS; index++) {
352 struct scic_sds_phy *sci_phy = &ihost->phys[index].sci;
354 if (configure_phy_mask & (1 << index)) {
355 port_agent->link_up_handler(scic, port_agent,
356 scic_sds_phy_get_port(sci_phy),
364 * @controller: This is the controller object that receives the link up
366 * @port: This is the port object associated with the phy. If the is no
367 * associated port this is an NULL.
368 * @phy: This is the phy object which has gone ready.
370 * This method handles the manual port configuration link up notifications.
371 * Since all ports and phys are associate at initialization time we just turn
372 * around and notifiy the port object that there is a link up. If this PHY is
373 * not associated with a port there is no action taken. Is it possible to get a
374 * link up notification from a phy that has no assocoated port?
376 static void scic_sds_mpc_agent_link_up(
377 struct scic_sds_controller *controller,
378 struct scic_sds_port_configuration_agent *port_agent,
379 struct scic_sds_port *port,
380 struct scic_sds_phy *phy)
383 * If the port has an invalid handle then the phy was not assigned to
384 * a port. This is because the phy was not given the same SAS Address
385 * as the other PHYs in the port. */
387 port_agent->phy_ready_mask |= (1 << scic_sds_phy_get_index(phy));
389 scic_sds_port_link_up(port, phy);
391 if ((port->active_phy_mask & (1 << scic_sds_phy_get_index(phy))) != 0) {
392 port_agent->phy_configured_mask |= (1 << scic_sds_phy_get_index(phy));
399 * @controller: This is the controller object that receives the link down
401 * @port: This is the port object associated with the phy. If the is no
402 * associated port this is an NULL. The port is an invalid
403 * handle only if the phy was never port of this port. This happens when
404 * the phy is not broadcasting the same SAS address as the other phys in the
406 * @phy: This is the phy object which has gone link down.
408 * This function handles the manual port configuration link down notifications.
409 * Since all ports and phys are associated at initialization time we just turn
410 * around and notifiy the port object of the link down event. If this PHY is
411 * not associated with a port there is no action taken. Is it possible to get a
412 * link down notification from a phy that has no assocoated port?
414 static void scic_sds_mpc_agent_link_down(
415 struct scic_sds_controller *scic,
416 struct scic_sds_port_configuration_agent *port_agent,
417 struct scic_sds_port *sci_port,
418 struct scic_sds_phy *sci_phy)
420 if (sci_port != NULL) {
422 * If we can form a new port from the remainder of the phys
423 * then we want to start the timer to allow the SCI User to
424 * cleanup old devices and rediscover the port before
425 * rebuilding the port with the phys that remain in the ready
428 port_agent->phy_ready_mask &=
429 ~(1 << scic_sds_phy_get_index(sci_phy));
430 port_agent->phy_configured_mask &=
431 ~(1 << scic_sds_phy_get_index(sci_phy));
434 * Check to see if there are more phys waiting to be
435 * configured into a port. If there are allow the SCI User
436 * to tear down this port, if necessary, and then reconstruct
437 * the port after the timeout.
439 if ((port_agent->phy_configured_mask == 0x0000) &&
440 (port_agent->phy_ready_mask != 0x0000) &&
441 !port_agent->timer_pending) {
442 port_agent->timer_pending = true;
444 isci_timer_start(port_agent->timer,
445 SCIC_SDS_MPC_RECONFIGURATION_TIMEOUT);
448 scic_sds_port_link_down(sci_port, sci_phy);
453 * ******************************************************************************
454 * Automatic port configuration agent routines
455 * ****************************************************************************** */
460 * This routine will verify that the phys are assigned a valid SAS address for
461 * automatic port configuration mode.
463 static enum sci_status scic_sds_apc_agent_validate_phy_configuration(
464 struct scic_sds_controller *controller,
465 struct scic_sds_port_configuration_agent *port_agent)
469 struct sci_sas_address sas_address;
470 struct sci_sas_address phy_assigned_address;
471 struct isci_host *ihost = scic_to_ihost(controller);
475 while (phy_index < SCI_MAX_PHYS) {
476 port_index = phy_index;
478 /* Get the assigned SAS Address for the first PHY on the controller. */
479 scic_sds_phy_get_sas_address(&ihost->phys[phy_index].sci,
482 while (++phy_index < SCI_MAX_PHYS) {
483 scic_sds_phy_get_sas_address(&ihost->phys[phy_index].sci,
484 &phy_assigned_address);
486 /* Verify each of the SAS address are all the same for every PHY */
487 if (sci_sas_address_compare(sas_address, phy_assigned_address) == 0) {
488 port_agent->phy_valid_port_range[phy_index].min_index = port_index;
489 port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
491 port_agent->phy_valid_port_range[phy_index].min_index = phy_index;
492 port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
498 return scic_sds_port_configuration_agent_validate_ports(controller, port_agent);
503 * @controller: This is the controller that to which the port agent is assigned.
504 * @port_agent: This is the port agent that is requesting the timer start
506 * @phy: This is the phy that has caused the timer operation to be scheduled.
508 * This routine will restart the automatic port configuration timeout timer for
509 * the next time period. This could be caused by either a link down event or a
510 * link up event where we can not yet tell to which port a phy belongs.
512 static inline void scic_sds_apc_agent_start_timer(
513 struct scic_sds_controller *scic,
514 struct scic_sds_port_configuration_agent *port_agent,
515 struct scic_sds_phy *sci_phy,
518 if (port_agent->timer_pending)
519 isci_timer_stop(port_agent->timer);
521 port_agent->timer_pending = true;
523 isci_timer_start(port_agent->timer, timeout);
528 * @controller: This is the controller object that receives the link up
530 * @phy: This is the phy object which has gone link up.
532 * This method handles the automatic port configuration for link up
535 static void scic_sds_apc_agent_configure_ports(
536 struct scic_sds_controller *controller,
537 struct scic_sds_port_configuration_agent *port_agent,
538 struct scic_sds_phy *phy,
542 enum sci_status status;
543 struct scic_sds_port *port;
544 enum SCIC_SDS_APC_ACTIVITY apc_activity = SCIC_SDS_APC_SKIP_PHY;
545 struct isci_host *ihost = scic_to_ihost(controller);
547 port = scic_sds_port_configuration_agent_find_port(controller, phy);
550 if (scic_sds_port_is_valid_phy_assignment(port, phy->phy_index))
551 apc_activity = SCIC_SDS_APC_ADD_PHY;
553 apc_activity = SCIC_SDS_APC_SKIP_PHY;
556 * There is no matching Port for this PHY so lets search through the
557 * Ports and see if we can add the PHY to its own port or maybe start
558 * the timer and wait to see if a wider port can be made.
560 * Note the break when we reach the condition of the port id == phy id */
562 port_index = port_agent->phy_valid_port_range[phy->phy_index].min_index;
563 port_index <= port_agent->phy_valid_port_range[phy->phy_index].max_index;
567 port = &ihost->ports[port_index].sci;
569 /* First we must make sure that this PHY can be added to this Port. */
570 if (scic_sds_port_is_valid_phy_assignment(port, phy->phy_index)) {
572 * Port contains a PHY with a greater PHY ID than the current
573 * PHY that has gone link up. This phy can not be part of any
574 * port so skip it and move on. */
575 if (port->active_phy_mask > (1 << phy->phy_index)) {
576 apc_activity = SCIC_SDS_APC_SKIP_PHY;
581 * We have reached the end of our Port list and have not found
582 * any reason why we should not either add the PHY to the port
583 * or wait for more phys to become active. */
584 if (port->physical_port_index == phy->phy_index) {
586 * The Port either has no active PHYs.
587 * Consider that if the port had any active PHYs we would have
588 * or active PHYs with
589 * a lower PHY Id than this PHY. */
590 if (apc_activity != SCIC_SDS_APC_START_TIMER) {
591 apc_activity = SCIC_SDS_APC_ADD_PHY;
598 * The current Port has no active PHYs and this PHY could be part
599 * of this Port. Since we dont know as yet setup to start the
600 * timer and see if there is a better configuration. */
601 if (port->active_phy_mask == 0) {
602 apc_activity = SCIC_SDS_APC_START_TIMER;
604 } else if (port->active_phy_mask != 0) {
606 * The Port has an active phy and the current Phy can not
607 * participate in this port so skip the PHY and see if
608 * there is a better configuration. */
609 apc_activity = SCIC_SDS_APC_SKIP_PHY;
615 * Check to see if the start timer operations should instead map to an
616 * add phy operation. This is caused because we have been waiting to
617 * add a phy to a port but could not becuase the automatic port
618 * configuration engine had a choice of possible ports for the phy.
619 * Since we have gone through a timeout we are going to restrict the
620 * choice to the smallest possible port. */
622 (start_timer == false)
623 && (apc_activity == SCIC_SDS_APC_START_TIMER)
625 apc_activity = SCIC_SDS_APC_ADD_PHY;
628 switch (apc_activity) {
629 case SCIC_SDS_APC_ADD_PHY:
630 status = scic_sds_port_add_phy(port, phy);
632 if (status == SCI_SUCCESS) {
633 port_agent->phy_configured_mask |= (1 << phy->phy_index);
637 case SCIC_SDS_APC_START_TIMER:
638 scic_sds_apc_agent_start_timer(
639 controller, port_agent, phy, SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION
643 case SCIC_SDS_APC_SKIP_PHY:
645 /* do nothing the PHY can not be made part of a port at this time. */
651 * scic_sds_apc_agent_link_up - handle apc link up events
652 * @scic: This is the controller object that receives the link up
654 * @sci_port: This is the port object associated with the phy. If the is no
655 * associated port this is an NULL.
656 * @sci_phy: This is the phy object which has gone link up.
658 * This method handles the automatic port configuration for link up
659 * notifications. Is it possible to get a link down notification from a phy
660 * that has no assocoated port?
662 static void scic_sds_apc_agent_link_up(struct scic_sds_controller *scic,
663 struct scic_sds_port_configuration_agent *port_agent,
664 struct scic_sds_port *sci_port,
665 struct scic_sds_phy *sci_phy)
667 u8 phy_index = sci_phy->phy_index;
670 /* the phy is not the part of this port */
671 port_agent->phy_ready_mask |= 1 << phy_index;
672 scic_sds_apc_agent_configure_ports(scic, port_agent, sci_phy, true);
674 /* the phy is already the part of the port */
675 u32 port_state = sci_port->state_machine.current_state_id;
677 /* if the PORT'S state is resetting then the link up is from
678 * port hard reset in this case, we need to tell the port
679 * that link up is recieved
681 BUG_ON(port_state != SCI_BASE_PORT_STATE_RESETTING);
682 port_agent->phy_ready_mask |= 1 << phy_index;
683 scic_sds_port_link_up(sci_port, sci_phy);
689 * @controller: This is the controller object that receives the link down
691 * @port: This is the port object associated with the phy. If the is no
692 * associated port this is an NULL.
693 * @phy: This is the phy object which has gone link down.
695 * This method handles the automatic port configuration link down
696 * notifications. not associated with a port there is no action taken. Is it
697 * possible to get a link down notification from a phy that has no assocoated
700 static void scic_sds_apc_agent_link_down(
701 struct scic_sds_controller *controller,
702 struct scic_sds_port_configuration_agent *port_agent,
703 struct scic_sds_port *port,
704 struct scic_sds_phy *phy)
706 port_agent->phy_ready_mask &= ~(1 << scic_sds_phy_get_index(phy));
709 if (port_agent->phy_configured_mask & (1 << phy->phy_index)) {
710 enum sci_status status;
712 status = scic_sds_port_remove_phy(port, phy);
714 if (status == SCI_SUCCESS) {
715 port_agent->phy_configured_mask &= ~(1 << phy->phy_index);
721 /* configure the phys into ports when the timer fires */
722 static void scic_sds_apc_agent_timeout_handler(void *object)
725 struct scic_sds_port_configuration_agent *port_agent;
726 struct scic_sds_controller *scic = object;
727 struct isci_host *ihost = scic_to_ihost(scic);
728 u16 configure_phy_mask;
730 port_agent = scic_sds_controller_get_port_configuration_agent(scic);
732 port_agent->timer_pending = false;
734 configure_phy_mask = ~port_agent->phy_configured_mask & port_agent->phy_ready_mask;
736 if (!configure_phy_mask)
739 for (index = 0; index < SCI_MAX_PHYS; index++) {
740 if ((configure_phy_mask & (1 << index)) == 0)
743 scic_sds_apc_agent_configure_ports(scic, port_agent,
744 &ihost->phys[index].sci, false);
749 * ******************************************************************************
750 * Public port configuration agent routines
751 * ****************************************************************************** */
756 * This method will construct the port configuration agent for operation. This
757 * call is universal for both manual port configuration and automatic port
758 * configuration modes.
760 void scic_sds_port_configuration_agent_construct(
761 struct scic_sds_port_configuration_agent *port_agent)
765 port_agent->phy_configured_mask = 0x00;
766 port_agent->phy_ready_mask = 0x00;
768 port_agent->link_up_handler = NULL;
769 port_agent->link_down_handler = NULL;
771 port_agent->timer_pending = false;
772 port_agent->timer = NULL;
774 for (index = 0; index < SCI_MAX_PORTS; index++) {
775 port_agent->phy_valid_port_range[index].min_index = 0;
776 port_agent->phy_valid_port_range[index].max_index = 0;
780 enum sci_status scic_sds_port_configuration_agent_initialize(
781 struct scic_sds_controller *scic,
782 struct scic_sds_port_configuration_agent *port_agent)
784 enum sci_status status = SCI_SUCCESS;
785 enum scic_port_configuration_mode mode;
786 struct isci_host *ihost = scic_to_ihost(scic);
788 mode = scic->oem_parameters.sds1.controller.mode_type;
790 if (mode == SCIC_PORT_MANUAL_CONFIGURATION_MODE) {
791 status = scic_sds_mpc_agent_validate_phy_configuration(
794 port_agent->link_up_handler = scic_sds_mpc_agent_link_up;
795 port_agent->link_down_handler = scic_sds_mpc_agent_link_down;
797 port_agent->timer = isci_timer_create(
800 scic_sds_mpc_agent_timeout_handler);
802 status = scic_sds_apc_agent_validate_phy_configuration(
805 port_agent->link_up_handler = scic_sds_apc_agent_link_up;
806 port_agent->link_down_handler = scic_sds_apc_agent_link_down;
808 port_agent->timer = isci_timer_create(
811 scic_sds_apc_agent_timeout_handler);
814 /* Make sure we have actually gotten a timer */
815 if ((status == SCI_SUCCESS) && (port_agent->timer == NULL)) {
816 dev_err(scic_to_dev(scic),
817 "%s: Controller 0x%p automatic port configuration "
818 "agent could not get timer.\n",
822 status = SCI_FAILURE;