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 * This file contains the implementation for the public and protected methods
58 * for the port configuration agent.
63 #include "sci_environment.h"
64 #include "scic_controller.h"
65 #include "scic_sds_controller.h"
66 #include "scic_sds_port_configuration_agent.h"
68 #define SCIC_SDS_MPC_RECONFIGURATION_TIMEOUT (10)
69 #define SCIC_SDS_APC_RECONFIGURATION_TIMEOUT (10)
70 #define SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION (100)
72 enum SCIC_SDS_APC_ACTIVITY {
73 SCIC_SDS_APC_SKIP_PHY,
75 SCIC_SDS_APC_START_TIMER,
77 SCIC_SDS_APC_ACTIVITY_MAX
81 * ******************************************************************************
82 * General port configuration agent routines
83 * ****************************************************************************** */
87 * @address_one: A SAS Address to be compared.
88 * @address_two: A SAS Address to be compared.
90 * Compare the two SAS Address and if SAS Address One is greater than SAS
91 * Address Two then return > 0 else if SAS Address One is less than SAS Address
92 * Two return < 0 Otherwise they are the same return 0 A signed value of x > 0
93 * > y where x is returned for Address One > Address Two y is returned for
94 * Address One < Address Two 0 is returned ofr Address One = Address Two
96 static s32 sci_sas_address_compare(
97 struct sci_sas_address address_one,
98 struct sci_sas_address address_two)
100 if (address_one.high > address_two.high) {
102 } else if (address_one.high < address_two.high) {
104 } else if (address_one.low > address_two.low) {
106 } else if (address_one.low < address_two.low) {
110 /* The two SAS Address must be identical */
116 * @controller: The controller object used for the port search.
117 * @phy: The phy object to match.
119 * This routine will find a matching port for the phy. This means that the
120 * port and phy both have the same broadcast sas address and same received sas
121 * address. The port address or the NULL if there is no matching
122 * port. port address if the port can be found to match the phy.
123 * NULL if there is no matching port for the phy.
125 static struct scic_sds_port *scic_sds_port_configuration_agent_find_port(
126 struct scic_sds_controller *controller,
127 struct scic_sds_phy *phy)
130 struct scic_sds_port *port_handle;
131 struct sci_sas_address port_sas_address;
132 struct sci_sas_address port_attached_device_address;
133 struct sci_sas_address phy_sas_address;
134 struct sci_sas_address phy_attached_device_address;
137 * Since this phy can be a member of a wide port check to see if one or
138 * more phys match the sent and received SAS address as this phy in which
139 * case it should participate in the same port. */
140 scic_sds_phy_get_sas_address(phy, &phy_sas_address);
141 scic_sds_phy_get_attached_sas_address(phy, &phy_attached_device_address);
143 for (port_index = 0; port_index < SCI_MAX_PORTS; port_index++) {
144 if (scic_controller_get_port_handle(controller, port_index, &port_handle) == SCI_SUCCESS) {
145 struct scic_sds_port *port = (struct scic_sds_port *)port_handle;
147 scic_sds_port_get_sas_address(port, &port_sas_address);
148 scic_sds_port_get_attached_sas_address(port, &port_attached_device_address);
151 (sci_sas_address_compare(port_sas_address, phy_sas_address) == 0)
152 && (sci_sas_address_compare(port_attached_device_address, phy_attached_device_address) == 0)
164 * @controller: This is the controller object that contains the port agent
165 * @port_agent: This is the port configruation agent for the controller.
167 * This routine will validate the port configuration is correct for the SCU
168 * hardware. The SCU hardware allows for port configurations as follows. LP0
169 * -> (PE0), (PE0, PE1), (PE0, PE1, PE2, PE3) LP1 -> (PE1) LP2 -> (PE2), (PE2,
170 * PE3) LP3 -> (PE3) enum sci_status SCI_SUCCESS the port configuration is valid for
171 * this port configuration agent. SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
172 * the port configuration is not valid for this port configuration agent.
174 static enum sci_status scic_sds_port_configuration_agent_validate_ports(
175 struct scic_sds_controller *controller,
176 struct scic_sds_port_configuration_agent *port_agent)
178 struct sci_sas_address first_address;
179 struct sci_sas_address second_address;
182 * Sanity check the max ranges for all the phys the max index
183 * is always equal to the port range index */
185 (port_agent->phy_valid_port_range[0].max_index != 0)
186 || (port_agent->phy_valid_port_range[1].max_index != 1)
187 || (port_agent->phy_valid_port_range[2].max_index != 2)
188 || (port_agent->phy_valid_port_range[3].max_index != 3)
190 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
194 * This is a request to configure a single x4 port or at least attempt
195 * to make all the phys into a single port */
197 (port_agent->phy_valid_port_range[0].min_index == 0)
198 && (port_agent->phy_valid_port_range[1].min_index == 0)
199 && (port_agent->phy_valid_port_range[2].min_index == 0)
200 && (port_agent->phy_valid_port_range[3].min_index == 0)
206 * This is a degenerate case where phy 1 and phy 2 are assigned
207 * to the same port this is explicitly disallowed by the hardware
208 * unless they are part of the same x4 port and this condition was
209 * already checked above. */
210 if (port_agent->phy_valid_port_range[2].min_index == 1) {
211 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
215 * PE0 and PE3 can never have the same SAS Address unless they
216 * are part of the same x4 wide port and we have already checked
217 * for this condition. */
218 scic_sds_phy_get_sas_address(&controller->phy_table[0], &first_address);
219 scic_sds_phy_get_sas_address(&controller->phy_table[3], &second_address);
221 if (sci_sas_address_compare(first_address, second_address) == 0) {
222 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
226 * PE0 and PE1 are configured into a 2x1 ports make sure that the
227 * SAS Address for PE0 and PE2 are different since they can not be
228 * part of the same port. */
230 (port_agent->phy_valid_port_range[0].min_index == 0)
231 && (port_agent->phy_valid_port_range[1].min_index == 1)
233 scic_sds_phy_get_sas_address(&controller->phy_table[0], &first_address);
234 scic_sds_phy_get_sas_address(&controller->phy_table[2], &second_address);
236 if (sci_sas_address_compare(first_address, second_address) == 0) {
237 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
242 * PE2 and PE3 are configured into a 2x1 ports make sure that the
243 * SAS Address for PE1 and PE3 are different since they can not be
244 * part of the same port. */
246 (port_agent->phy_valid_port_range[2].min_index == 2)
247 && (port_agent->phy_valid_port_range[3].min_index == 3)
249 scic_sds_phy_get_sas_address(&controller->phy_table[1], &first_address);
250 scic_sds_phy_get_sas_address(&controller->phy_table[3], &second_address);
252 if (sci_sas_address_compare(first_address, second_address) == 0) {
253 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
261 * ******************************************************************************
262 * Manual port configuration agent routines
263 * ****************************************************************************** */
268 * This routine will verify that all of the phys in the same port are using the
271 static enum sci_status scic_sds_mpc_agent_validate_phy_configuration(
272 struct scic_sds_controller *controller,
273 struct scic_sds_port_configuration_agent *port_agent)
276 u32 assigned_phy_mask;
277 struct sci_sas_address sas_address;
278 struct sci_sas_address phy_assigned_address;
282 assigned_phy_mask = 0;
283 sas_address.high = 0;
286 for (port_index = 0; port_index < SCI_MAX_PORTS; port_index++) {
287 phy_mask = controller->oem_parameters.sds1.ports[port_index].phy_mask;
291 * Make sure that one or more of the phys were not already assinged to
292 * a different port. */
293 if ((phy_mask & ~assigned_phy_mask) == 0) {
294 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
297 /* Find the starting phy index for this round through the loop */
298 for (phy_index = 0; phy_index < SCI_MAX_PHYS; phy_index++) {
299 if ((1 << phy_index) & phy_mask) {
300 scic_sds_phy_get_sas_address(
301 &controller->phy_table[phy_index], &sas_address
305 * The phy_index can be used as the starting point for the
306 * port range since the hardware starts all logical ports
307 * the same as the PE index. */
308 port_agent->phy_valid_port_range[phy_index].min_index = port_index;
309 port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
311 if (phy_index != port_index) {
312 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
320 * See how many additional phys are being added to this logical port.
321 * Note: We have not moved the current phy_index so we will actually
322 * compare the startting phy with itself.
323 * This is expected and required to add the phy to the port. */
324 while (phy_index < SCI_MAX_PHYS) {
325 if ((1 << phy_index) & phy_mask) {
326 scic_sds_phy_get_sas_address(
327 &controller->phy_table[phy_index], &phy_assigned_address
330 if (sci_sas_address_compare(sas_address, phy_assigned_address) != 0) {
332 * The phy mask specified that this phy is part of the same port
333 * as the starting phy and it is not so fail this configuration */
334 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
337 port_agent->phy_valid_port_range[phy_index].min_index = port_index;
338 port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
340 scic_sds_port_add_phy(
341 &controller->port_table[port_index],
342 &controller->phy_table[phy_index]
345 assigned_phy_mask |= (1 << phy_index);
353 return scic_sds_port_configuration_agent_validate_ports(controller, port_agent);
359 * This timer routine is used to allow the SCI User to rediscover or change
360 * device objects before a new series of link up notifications because a link
361 * down has allowed a better port configuration.
363 static void scic_sds_mpc_agent_timeout_handler(
367 struct scic_sds_controller *controller = (struct scic_sds_controller *)object;
368 struct scic_sds_port_configuration_agent *port_agent = &controller->port_agent;
369 u16 configure_phy_mask;
371 port_agent->timer_pending = false;
373 /* Find the mask of phys that are reported read but as yet unconfigured into a port */
374 configure_phy_mask = ~port_agent->phy_configured_mask & port_agent->phy_ready_mask;
376 for (index = 0; index < SCI_MAX_PHYS; index++) {
377 if (configure_phy_mask & (1 << index)) {
378 port_agent->link_up_handler(
381 scic_sds_phy_get_port(&controller->phy_table[index]),
382 &controller->phy_table[index]
390 * @controller: This is the controller object that receives the link up
392 * @port: This is the port object associated with the phy. If the is no
393 * associated port this is an NULL.
394 * @phy: This is the phy object which has gone ready.
396 * This method handles the manual port configuration link up notifications.
397 * Since all ports and phys are associate at initialization time we just turn
398 * around and notifiy the port object that there is a link up. If this PHY is
399 * not associated with a port there is no action taken. Is it possible to get a
400 * link up notification from a phy that has no assocoated port?
402 static void scic_sds_mpc_agent_link_up(
403 struct scic_sds_controller *controller,
404 struct scic_sds_port_configuration_agent *port_agent,
405 struct scic_sds_port *port,
406 struct scic_sds_phy *phy)
409 * If the port has an invalid handle then the phy was not assigned to
410 * a port. This is because the phy was not given the same SAS Address
411 * as the other PHYs in the port. */
413 port_agent->phy_ready_mask |= (1 << scic_sds_phy_get_index(phy));
415 scic_sds_port_link_up(port, phy);
417 if ((port->active_phy_mask & (1 << scic_sds_phy_get_index(phy))) != 0) {
418 port_agent->phy_configured_mask |= (1 << scic_sds_phy_get_index(phy));
425 * @controller: This is the controller object that receives the link down
427 * @port: This is the port object associated with the phy. If the is no
428 * associated port this is an NULL. The port is an invalid
429 * handle only if the phy was never port of this port. This happens when
430 * the phy is not broadcasting the same SAS address as the other phys in the
432 * @phy: This is the phy object which has gone link down.
434 * This method handles the manual port configuration link down notifications.
435 * Since all ports and phys are associated at initialization time we just turn
436 * around and notifiy the port object of the link down event. If this PHY is
437 * not associated with a port there is no action taken. Is it possible to get a
438 * link down notification from a phy that has no assocoated port?
440 static void scic_sds_mpc_agent_link_down(
441 struct scic_sds_controller *controller,
442 struct scic_sds_port_configuration_agent *port_agent,
443 struct scic_sds_port *port,
444 struct scic_sds_phy *phy)
448 * If we can form a new port from the remainder of the phys then we want
449 * to start the timer to allow the SCI User to cleanup old devices and
450 * rediscover the port before rebuilding the port with the phys that
451 * remain in the ready state. */
452 port_agent->phy_ready_mask &= ~(1 << scic_sds_phy_get_index(phy));
453 port_agent->phy_configured_mask &= ~(1 << scic_sds_phy_get_index(phy));
456 * Check to see if there are more phys waiting to be configured into a port.
457 * If there are allow the SCI User to tear down this port, if necessary, and
458 * then reconstruc the port after the timeout. */
460 (port_agent->phy_configured_mask == 0x0000)
461 && (port_agent->phy_ready_mask != 0x0000)
462 && !port_agent->timer_pending
464 port_agent->timer_pending = true;
466 isci_event_timer_start(
469 SCIC_SDS_MPC_RECONFIGURATION_TIMEOUT
473 scic_sds_port_link_down(port, phy);
478 * ******************************************************************************
479 * Automatic port configuration agent routines
480 * ****************************************************************************** */
485 * This routine will verify that the phys are assigned a valid SAS address for
486 * automatic port configuration mode.
488 static enum sci_status scic_sds_apc_agent_validate_phy_configuration(
489 struct scic_sds_controller *controller,
490 struct scic_sds_port_configuration_agent *port_agent)
494 struct sci_sas_address sas_address;
495 struct sci_sas_address phy_assigned_address;
499 while (phy_index < SCI_MAX_PHYS) {
500 port_index = phy_index;
502 /* Get the assigned SAS Address for the first PHY on the controller. */
503 scic_sds_phy_get_sas_address(
504 &controller->phy_table[phy_index], &sas_address
507 while (++phy_index < SCI_MAX_PHYS) {
508 scic_sds_phy_get_sas_address(
509 &controller->phy_table[phy_index], &phy_assigned_address
512 /* Verify each of the SAS address are all the same for every PHY */
513 if (sci_sas_address_compare(sas_address, phy_assigned_address) == 0) {
514 port_agent->phy_valid_port_range[phy_index].min_index = port_index;
515 port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
517 port_agent->phy_valid_port_range[phy_index].min_index = phy_index;
518 port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
524 return scic_sds_port_configuration_agent_validate_ports(controller, port_agent);
529 * @controller: This is the controller that to which the port agent is assigned.
530 * @port_agent: This is the port agent that is requesting the timer start
532 * @phy: This is the phy that has caused the timer operation to be scheduled.
534 * This routine will restart the automatic port configuration timeout timer for
535 * the next time period. This could be caused by either a link down event or a
536 * link up event where we can not yet tell to which port a phy belongs.
538 static void scic_sds_apc_agent_start_timer(
539 struct scic_sds_controller *controller,
540 struct scic_sds_port_configuration_agent *port_agent,
541 struct scic_sds_phy *phy,
544 if (port_agent->timer_pending) {
545 isci_event_timer_stop(controller, port_agent->timer);
548 port_agent->timer_pending = true;
550 isci_event_timer_start(controller, port_agent->timer, timeout);
555 * @controller: This is the controller object that receives the link up
557 * @phy: This is the phy object which has gone link up.
559 * This method handles the automatic port configuration for link up
562 static void scic_sds_apc_agent_configure_ports(
563 struct scic_sds_controller *controller,
564 struct scic_sds_port_configuration_agent *port_agent,
565 struct scic_sds_phy *phy,
569 enum sci_status status;
570 struct scic_sds_port *port;
571 struct scic_sds_port *port_handle;
572 enum SCIC_SDS_APC_ACTIVITY apc_activity = SCIC_SDS_APC_SKIP_PHY;
574 port = scic_sds_port_configuration_agent_find_port(controller, phy);
577 if (scic_sds_port_is_valid_phy_assignment(port, phy->phy_index))
578 apc_activity = SCIC_SDS_APC_ADD_PHY;
580 apc_activity = SCIC_SDS_APC_SKIP_PHY;
583 * There is no matching Port for this PHY so lets search through the
584 * Ports and see if we can add the PHY to its own port or maybe start
585 * the timer and wait to see if a wider port can be made.
587 * Note the break when we reach the condition of the port id == phy id */
589 port_index = port_agent->phy_valid_port_range[phy->phy_index].min_index;
590 port_index <= port_agent->phy_valid_port_range[phy->phy_index].max_index;
593 scic_controller_get_port_handle(controller, port_index, &port_handle);
595 port = (struct scic_sds_port *)port_handle;
597 /* First we must make sure that this PHY can be added to this Port. */
598 if (scic_sds_port_is_valid_phy_assignment(port, phy->phy_index)) {
600 * Port contains a PHY with a greater PHY ID than the current
601 * PHY that has gone link up. This phy can not be part of any
602 * port so skip it and move on. */
603 if (port->active_phy_mask > (1 << phy->phy_index)) {
604 apc_activity = SCIC_SDS_APC_SKIP_PHY;
609 * We have reached the end of our Port list and have not found
610 * any reason why we should not either add the PHY to the port
611 * or wait for more phys to become active. */
612 if (port->physical_port_index == phy->phy_index) {
614 * The Port either has no active PHYs.
615 * Consider that if the port had any active PHYs we would have
616 * or active PHYs with
617 * a lower PHY Id than this PHY. */
618 if (apc_activity != SCIC_SDS_APC_START_TIMER) {
619 apc_activity = SCIC_SDS_APC_ADD_PHY;
626 * The current Port has no active PHYs and this PHY could be part
627 * of this Port. Since we dont know as yet setup to start the
628 * timer and see if there is a better configuration. */
629 if (port->active_phy_mask == 0) {
630 apc_activity = SCIC_SDS_APC_START_TIMER;
632 } else if (port->active_phy_mask != 0) {
634 * The Port has an active phy and the current Phy can not
635 * participate in this port so skip the PHY and see if
636 * there is a better configuration. */
637 apc_activity = SCIC_SDS_APC_SKIP_PHY;
643 * Check to see if the start timer operations should instead map to an
644 * add phy operation. This is caused because we have been waiting to
645 * add a phy to a port but could not becuase the automatic port
646 * configuration engine had a choice of possible ports for the phy.
647 * Since we have gone through a timeout we are going to restrict the
648 * choice to the smallest possible port. */
650 (start_timer == false)
651 && (apc_activity == SCIC_SDS_APC_START_TIMER)
653 apc_activity = SCIC_SDS_APC_ADD_PHY;
656 switch (apc_activity) {
657 case SCIC_SDS_APC_ADD_PHY:
658 status = scic_sds_port_add_phy(port, phy);
660 if (status == SCI_SUCCESS) {
661 port_agent->phy_configured_mask |= (1 << phy->phy_index);
665 case SCIC_SDS_APC_START_TIMER:
666 scic_sds_apc_agent_start_timer(
667 controller, port_agent, phy, SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION
671 case SCIC_SDS_APC_SKIP_PHY:
673 /* do nothing the PHY can not be made part of a port at this time. */
679 * scic_sds_apc_agent_link_up - handle apc link up events
680 * @scic: This is the controller object that receives the link up
682 * @sci_port: This is the port object associated with the phy. If the is no
683 * associated port this is an NULL.
684 * @sci_phy: This is the phy object which has gone link up.
686 * This method handles the automatic port configuration for link up
687 * notifications. Is it possible to get a link down notification from a phy
688 * that has no assocoated port?
690 static void scic_sds_apc_agent_link_up(struct scic_sds_controller *scic,
691 struct scic_sds_port_configuration_agent *port_agent,
692 struct scic_sds_port *sci_port,
693 struct scic_sds_phy *sci_phy)
695 u8 phy_index = sci_phy->phy_index;
698 /* the phy is not the part of this port */
699 port_agent->phy_ready_mask |= 1 << phy_index;
700 scic_sds_apc_agent_configure_ports(scic, port_agent, sci_phy, true);
702 /* the phy is already the part of the port */
703 u32 port_state = sci_port->parent.state_machine.current_state_id;
705 /* if the PORT'S state is resetting then the link up is from
706 * port hard reset in this case, we need to tell the port
707 * that link up is recieved
709 BUG_ON(port_state != SCI_BASE_PORT_STATE_RESETTING);
710 port_agent->phy_ready_mask |= 1 << phy_index;
711 scic_sds_port_link_up(sci_port, sci_phy);
717 * @controller: This is the controller object that receives the link down
719 * @port: This is the port object associated with the phy. If the is no
720 * associated port this is an NULL.
721 * @phy: This is the phy object which has gone link down.
723 * This method handles the automatic port configuration link down
724 * notifications. not associated with a port there is no action taken. Is it
725 * possible to get a link down notification from a phy that has no assocoated
728 static void scic_sds_apc_agent_link_down(
729 struct scic_sds_controller *controller,
730 struct scic_sds_port_configuration_agent *port_agent,
731 struct scic_sds_port *port,
732 struct scic_sds_phy *phy)
734 port_agent->phy_ready_mask &= ~(1 << scic_sds_phy_get_index(phy));
737 if (port_agent->phy_configured_mask & (1 << phy->phy_index)) {
738 enum sci_status status;
740 status = scic_sds_port_remove_phy(port, phy);
742 if (status == SCI_SUCCESS) {
743 port_agent->phy_configured_mask &= ~(1 << phy->phy_index);
752 * This routine will try to configure the phys into ports when the timer fires.
754 static void scic_sds_apc_agent_timeout_handler(
758 struct scic_sds_port_configuration_agent *port_agent;
759 struct scic_sds_controller *controller = (struct scic_sds_controller *)object;
760 u16 configure_phy_mask;
762 port_agent = scic_sds_controller_get_port_configuration_agent(controller);
764 port_agent->timer_pending = false;
766 configure_phy_mask = ~port_agent->phy_configured_mask & port_agent->phy_ready_mask;
768 if (configure_phy_mask != 0x00) {
769 for (index = 0; index < SCI_MAX_PHYS; index++) {
770 if (configure_phy_mask & (1 << index)) {
771 scic_sds_apc_agent_configure_ports(
772 controller, port_agent, &controller->phy_table[index], false
780 * ******************************************************************************
781 * Public port configuration agent routines
782 * ****************************************************************************** */
787 * This method will construct the port configuration agent for operation. This
788 * call is universal for both manual port configuration and automatic port
789 * configuration modes.
791 void scic_sds_port_configuration_agent_construct(
792 struct scic_sds_port_configuration_agent *port_agent)
796 port_agent->phy_configured_mask = 0x00;
797 port_agent->phy_ready_mask = 0x00;
799 port_agent->link_up_handler = NULL;
800 port_agent->link_down_handler = NULL;
802 port_agent->timer_pending = false;
803 port_agent->timer = NULL;
805 for (index = 0; index < SCI_MAX_PORTS; index++) {
806 port_agent->phy_valid_port_range[index].min_index = 0;
807 port_agent->phy_valid_port_range[index].max_index = 0;
813 * @controller: This is the controller object for which the port agent is being
816 * This method will construct the port configuration agent for this controller.
818 enum sci_status scic_sds_port_configuration_agent_initialize(
819 struct scic_sds_controller *controller,
820 struct scic_sds_port_configuration_agent *port_agent)
822 enum sci_status status = SCI_SUCCESS;
823 enum SCIC_PORT_CONFIGURATION_MODE mode;
825 mode = controller->oem_parameters.sds1.controller.mode_type;
827 if (mode == SCIC_PORT_MANUAL_CONFIGURATION_MODE) {
828 status = scic_sds_mpc_agent_validate_phy_configuration(controller, port_agent);
830 port_agent->link_up_handler = scic_sds_mpc_agent_link_up;
831 port_agent->link_down_handler = scic_sds_mpc_agent_link_down;
833 port_agent->timer = isci_event_timer_create(
835 scic_sds_mpc_agent_timeout_handler,
839 status = scic_sds_apc_agent_validate_phy_configuration(controller, port_agent);
841 port_agent->link_up_handler = scic_sds_apc_agent_link_up;
842 port_agent->link_down_handler = scic_sds_apc_agent_link_down;
844 port_agent->timer = isci_event_timer_create(
846 scic_sds_apc_agent_timeout_handler,
851 /* Make sure we have actually gotten a timer */
852 if ((status == SCI_SUCCESS) && (port_agent->timer == NULL)) {
853 dev_err(scic_to_dev(controller),
854 "%s: Controller 0x%p automatic port configuration "
855 "agent could not get timer.\n",
859 status = SCI_FAILURE;