1e2f8db50SDan Williams /*
2e2f8db50SDan Williams * This file is provided under a dual BSD/GPLv2 license. When using or
3e2f8db50SDan Williams * redistributing this file, you may do so under either license.
4e2f8db50SDan Williams *
5e2f8db50SDan Williams * GPL LICENSE SUMMARY
6e2f8db50SDan Williams *
7e2f8db50SDan Williams * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8e2f8db50SDan Williams *
9e2f8db50SDan Williams * This program is free software; you can redistribute it and/or modify
10e2f8db50SDan Williams * it under the terms of version 2 of the GNU General Public License as
11e2f8db50SDan Williams * published by the Free Software Foundation.
12e2f8db50SDan Williams *
13e2f8db50SDan Williams * This program is distributed in the hope that it will be useful, but
14e2f8db50SDan Williams * WITHOUT ANY WARRANTY; without even the implied warranty of
15e2f8db50SDan Williams * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16e2f8db50SDan Williams * General Public License for more details.
17e2f8db50SDan Williams *
18e2f8db50SDan Williams * You should have received a copy of the GNU General Public License
19e2f8db50SDan Williams * along with this program; if not, write to the Free Software
20e2f8db50SDan Williams * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21e2f8db50SDan Williams * The full GNU General Public License is included in this distribution
22e2f8db50SDan Williams * in the file called LICENSE.GPL.
23e2f8db50SDan Williams *
24e2f8db50SDan Williams * BSD LICENSE
25e2f8db50SDan Williams *
26e2f8db50SDan Williams * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27e2f8db50SDan Williams * All rights reserved.
28e2f8db50SDan Williams *
29e2f8db50SDan Williams * Redistribution and use in source and binary forms, with or without
30e2f8db50SDan Williams * modification, are permitted provided that the following conditions
31e2f8db50SDan Williams * are met:
32e2f8db50SDan Williams *
33e2f8db50SDan Williams * * Redistributions of source code must retain the above copyright
34e2f8db50SDan Williams * notice, this list of conditions and the following disclaimer.
35e2f8db50SDan Williams * * Redistributions in binary form must reproduce the above copyright
36e2f8db50SDan Williams * notice, this list of conditions and the following disclaimer in
37e2f8db50SDan Williams * the documentation and/or other materials provided with the
38e2f8db50SDan Williams * distribution.
39e2f8db50SDan Williams * * Neither the name of Intel Corporation nor the names of its
40e2f8db50SDan Williams * contributors may be used to endorse or promote products derived
41e2f8db50SDan Williams * from this software without specific prior written permission.
42e2f8db50SDan Williams *
43e2f8db50SDan Williams * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44e2f8db50SDan Williams * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45e2f8db50SDan Williams * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46e2f8db50SDan Williams * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47e2f8db50SDan Williams * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48e2f8db50SDan Williams * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49e2f8db50SDan Williams * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50e2f8db50SDan Williams * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51e2f8db50SDan Williams * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52e2f8db50SDan Williams * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53e2f8db50SDan Williams * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54e2f8db50SDan Williams */
55e2f8db50SDan Williams
56e2f8db50SDan Williams #include "host.h"
57e2f8db50SDan Williams
58e2f8db50SDan Williams #define SCIC_SDS_MPC_RECONFIGURATION_TIMEOUT (10)
59e2f8db50SDan Williams #define SCIC_SDS_APC_RECONFIGURATION_TIMEOUT (10)
6050a92d93SDan Williams #define SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION (1000)
61e2f8db50SDan Williams
62e2f8db50SDan Williams enum SCIC_SDS_APC_ACTIVITY {
63e2f8db50SDan Williams SCIC_SDS_APC_SKIP_PHY,
64e2f8db50SDan Williams SCIC_SDS_APC_ADD_PHY,
65e2f8db50SDan Williams SCIC_SDS_APC_START_TIMER,
66e2f8db50SDan Williams
67e2f8db50SDan Williams SCIC_SDS_APC_ACTIVITY_MAX
68e2f8db50SDan Williams };
69e2f8db50SDan Williams
70e2f8db50SDan Williams /*
71e2f8db50SDan Williams * ******************************************************************************
72e2f8db50SDan Williams * General port configuration agent routines
73e2f8db50SDan Williams * ****************************************************************************** */
74e2f8db50SDan Williams
75e2f8db50SDan Williams /**
76*29faa5ceSLee Jones * sci_sas_address_compare()
77e2f8db50SDan Williams * @address_one: A SAS Address to be compared.
78e2f8db50SDan Williams * @address_two: A SAS Address to be compared.
79e2f8db50SDan Williams *
80e2f8db50SDan Williams * Compare the two SAS Address and if SAS Address One is greater than SAS
81e2f8db50SDan Williams * Address Two then return > 0 else if SAS Address One is less than SAS Address
82e2f8db50SDan Williams * Two return < 0 Otherwise they are the same return 0 A signed value of x > 0
83e2f8db50SDan Williams * > y where x is returned for Address One > Address Two y is returned for
84e2f8db50SDan Williams * Address One < Address Two 0 is returned ofr Address One = Address Two
85e2f8db50SDan Williams */
sci_sas_address_compare(struct sci_sas_address address_one,struct sci_sas_address address_two)86e2f8db50SDan Williams static s32 sci_sas_address_compare(
87e2f8db50SDan Williams struct sci_sas_address address_one,
88e2f8db50SDan Williams struct sci_sas_address address_two)
89e2f8db50SDan Williams {
90e2f8db50SDan Williams if (address_one.high > address_two.high) {
91e2f8db50SDan Williams return 1;
92e2f8db50SDan Williams } else if (address_one.high < address_two.high) {
93e2f8db50SDan Williams return -1;
94e2f8db50SDan Williams } else if (address_one.low > address_two.low) {
95e2f8db50SDan Williams return 1;
96e2f8db50SDan Williams } else if (address_one.low < address_two.low) {
97e2f8db50SDan Williams return -1;
98e2f8db50SDan Williams }
99e2f8db50SDan Williams
100e2f8db50SDan Williams /* The two SAS Address must be identical */
101e2f8db50SDan Williams return 0;
102e2f8db50SDan Williams }
103e2f8db50SDan Williams
104e2f8db50SDan Williams /**
105*29faa5ceSLee Jones * sci_port_configuration_agent_find_port()
106*29faa5ceSLee Jones * @ihost: The controller object used for the port search.
107*29faa5ceSLee Jones * @iphy: The phy object to match.
108e2f8db50SDan Williams *
109e2f8db50SDan Williams * This routine will find a matching port for the phy. This means that the
110e2f8db50SDan Williams * port and phy both have the same broadcast sas address and same received sas
111e2f8db50SDan Williams * address. The port address or the NULL if there is no matching
112e2f8db50SDan Williams * port. port address if the port can be found to match the phy.
113e2f8db50SDan Williams * NULL if there is no matching port for the phy.
114e2f8db50SDan Williams */
sci_port_configuration_agent_find_port(struct isci_host * ihost,struct isci_phy * iphy)11589a7301fSDan Williams static struct isci_port *sci_port_configuration_agent_find_port(
116d9dcb4baSDan Williams struct isci_host *ihost,
11785280955SDan Williams struct isci_phy *iphy)
118e2f8db50SDan Williams {
119e2f8db50SDan Williams u8 i;
120e2f8db50SDan Williams struct sci_sas_address port_sas_address;
121e2f8db50SDan Williams struct sci_sas_address port_attached_device_address;
122e2f8db50SDan Williams struct sci_sas_address phy_sas_address;
123e2f8db50SDan Williams struct sci_sas_address phy_attached_device_address;
124e2f8db50SDan Williams
125e2f8db50SDan Williams /*
126e2f8db50SDan Williams * Since this phy can be a member of a wide port check to see if one or
127e2f8db50SDan Williams * more phys match the sent and received SAS address as this phy in which
128e2f8db50SDan Williams * case it should participate in the same port.
129e2f8db50SDan Williams */
13089a7301fSDan Williams sci_phy_get_sas_address(iphy, &phy_sas_address);
13189a7301fSDan Williams sci_phy_get_attached_sas_address(iphy, &phy_attached_device_address);
132e2f8db50SDan Williams
133d9dcb4baSDan Williams for (i = 0; i < ihost->logical_port_entries; i++) {
134ffe191c9SDan Williams struct isci_port *iport = &ihost->ports[i];
135e2f8db50SDan Williams
13689a7301fSDan Williams sci_port_get_sas_address(iport, &port_sas_address);
13789a7301fSDan Williams sci_port_get_attached_sas_address(iport, &port_attached_device_address);
138e2f8db50SDan Williams
139e2f8db50SDan Williams if (sci_sas_address_compare(port_sas_address, phy_sas_address) == 0 &&
140e2f8db50SDan Williams sci_sas_address_compare(port_attached_device_address, phy_attached_device_address) == 0)
141ffe191c9SDan Williams return iport;
142e2f8db50SDan Williams }
143e2f8db50SDan Williams
144e2f8db50SDan Williams return NULL;
145e2f8db50SDan Williams }
146e2f8db50SDan Williams
147e2f8db50SDan Williams /**
148*29faa5ceSLee Jones * sci_port_configuration_agent_validate_ports()
149*29faa5ceSLee Jones * @ihost: This is the controller object that contains the port agent
150d44c897cSGeert Uytterhoeven * @port_agent: This is the port configuration agent for the controller.
151e2f8db50SDan Williams *
152e2f8db50SDan Williams * This routine will validate the port configuration is correct for the SCU
153e2f8db50SDan Williams * hardware. The SCU hardware allows for port configurations as follows. LP0
154e2f8db50SDan Williams * -> (PE0), (PE0, PE1), (PE0, PE1, PE2, PE3) LP1 -> (PE1) LP2 -> (PE2), (PE2,
155e2f8db50SDan Williams * PE3) LP3 -> (PE3) enum sci_status SCI_SUCCESS the port configuration is valid for
156e2f8db50SDan Williams * this port configuration agent. SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
157e2f8db50SDan Williams * the port configuration is not valid for this port configuration agent.
158e2f8db50SDan Williams */
sci_port_configuration_agent_validate_ports(struct isci_host * ihost,struct sci_port_configuration_agent * port_agent)15989a7301fSDan Williams static enum sci_status sci_port_configuration_agent_validate_ports(
160d9dcb4baSDan Williams struct isci_host *ihost,
16189a7301fSDan Williams struct sci_port_configuration_agent *port_agent)
162e2f8db50SDan Williams {
163e2f8db50SDan Williams struct sci_sas_address first_address;
164e2f8db50SDan Williams struct sci_sas_address second_address;
165e2f8db50SDan Williams
166e2f8db50SDan Williams /*
167e2f8db50SDan Williams * Sanity check the max ranges for all the phys the max index
168e2f8db50SDan Williams * is always equal to the port range index */
169e2f8db50SDan Williams if (port_agent->phy_valid_port_range[0].max_index != 0 ||
170e2f8db50SDan Williams port_agent->phy_valid_port_range[1].max_index != 1 ||
171e2f8db50SDan Williams port_agent->phy_valid_port_range[2].max_index != 2 ||
172e2f8db50SDan Williams port_agent->phy_valid_port_range[3].max_index != 3)
173e2f8db50SDan Williams return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
174e2f8db50SDan Williams
175e2f8db50SDan Williams /*
176e2f8db50SDan Williams * This is a request to configure a single x4 port or at least attempt
177e2f8db50SDan Williams * to make all the phys into a single port */
178e2f8db50SDan Williams if (port_agent->phy_valid_port_range[0].min_index == 0 &&
179e2f8db50SDan Williams port_agent->phy_valid_port_range[1].min_index == 0 &&
180e2f8db50SDan Williams port_agent->phy_valid_port_range[2].min_index == 0 &&
181e2f8db50SDan Williams port_agent->phy_valid_port_range[3].min_index == 0)
182e2f8db50SDan Williams return SCI_SUCCESS;
183e2f8db50SDan Williams
184e2f8db50SDan Williams /*
185e2f8db50SDan Williams * This is a degenerate case where phy 1 and phy 2 are assigned
186e2f8db50SDan Williams * to the same port this is explicitly disallowed by the hardware
187e2f8db50SDan Williams * unless they are part of the same x4 port and this condition was
188e2f8db50SDan Williams * already checked above. */
189e2f8db50SDan Williams if (port_agent->phy_valid_port_range[2].min_index == 1) {
190e2f8db50SDan Williams return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
191e2f8db50SDan Williams }
192e2f8db50SDan Williams
193e2f8db50SDan Williams /*
194e2f8db50SDan Williams * PE0 and PE3 can never have the same SAS Address unless they
195e2f8db50SDan Williams * are part of the same x4 wide port and we have already checked
196e2f8db50SDan Williams * for this condition. */
19789a7301fSDan Williams sci_phy_get_sas_address(&ihost->phys[0], &first_address);
19889a7301fSDan Williams sci_phy_get_sas_address(&ihost->phys[3], &second_address);
199e2f8db50SDan Williams
200e2f8db50SDan Williams if (sci_sas_address_compare(first_address, second_address) == 0) {
201e2f8db50SDan Williams return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
202e2f8db50SDan Williams }
203e2f8db50SDan Williams
204e2f8db50SDan Williams /*
205e2f8db50SDan Williams * PE0 and PE1 are configured into a 2x1 ports make sure that the
206e2f8db50SDan Williams * SAS Address for PE0 and PE2 are different since they can not be
207e2f8db50SDan Williams * part of the same port. */
208e2f8db50SDan Williams if (port_agent->phy_valid_port_range[0].min_index == 0 &&
209e2f8db50SDan Williams port_agent->phy_valid_port_range[1].min_index == 1) {
21089a7301fSDan Williams sci_phy_get_sas_address(&ihost->phys[0], &first_address);
21189a7301fSDan Williams sci_phy_get_sas_address(&ihost->phys[2], &second_address);
212e2f8db50SDan Williams
213e2f8db50SDan Williams if (sci_sas_address_compare(first_address, second_address) == 0) {
214e2f8db50SDan Williams return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
215e2f8db50SDan Williams }
216e2f8db50SDan Williams }
217e2f8db50SDan Williams
218e2f8db50SDan Williams /*
219e2f8db50SDan Williams * PE2 and PE3 are configured into a 2x1 ports make sure that the
220e2f8db50SDan Williams * SAS Address for PE1 and PE3 are different since they can not be
221e2f8db50SDan Williams * part of the same port. */
222e2f8db50SDan Williams if (port_agent->phy_valid_port_range[2].min_index == 2 &&
223e2f8db50SDan Williams port_agent->phy_valid_port_range[3].min_index == 3) {
22489a7301fSDan Williams sci_phy_get_sas_address(&ihost->phys[1], &first_address);
22589a7301fSDan Williams sci_phy_get_sas_address(&ihost->phys[3], &second_address);
226e2f8db50SDan Williams
227e2f8db50SDan Williams if (sci_sas_address_compare(first_address, second_address) == 0) {
228e2f8db50SDan Williams return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
229e2f8db50SDan Williams }
230e2f8db50SDan Williams }
231e2f8db50SDan Williams
232e2f8db50SDan Williams return SCI_SUCCESS;
233e2f8db50SDan Williams }
234e2f8db50SDan Williams
235e2f8db50SDan Williams /*
236e2f8db50SDan Williams * ******************************************************************************
237e2f8db50SDan Williams * Manual port configuration agent routines
238e2f8db50SDan Williams * ****************************************************************************** */
239e2f8db50SDan Williams
240d9dcb4baSDan Williams /* verify all of the phys in the same port are using the same SAS address */
241d9dcb4baSDan Williams static enum sci_status
sci_mpc_agent_validate_phy_configuration(struct isci_host * ihost,struct sci_port_configuration_agent * port_agent)24289a7301fSDan Williams sci_mpc_agent_validate_phy_configuration(struct isci_host *ihost,
24389a7301fSDan Williams struct sci_port_configuration_agent *port_agent)
244e2f8db50SDan Williams {
245e2f8db50SDan Williams u32 phy_mask;
246e2f8db50SDan Williams u32 assigned_phy_mask;
247e2f8db50SDan Williams struct sci_sas_address sas_address;
248e2f8db50SDan Williams struct sci_sas_address phy_assigned_address;
249e2f8db50SDan Williams u8 port_index;
250e2f8db50SDan Williams u8 phy_index;
251e2f8db50SDan Williams
252e2f8db50SDan Williams assigned_phy_mask = 0;
253e2f8db50SDan Williams sas_address.high = 0;
254e2f8db50SDan Williams sas_address.low = 0;
255e2f8db50SDan Williams
256e2f8db50SDan Williams for (port_index = 0; port_index < SCI_MAX_PORTS; port_index++) {
25789a7301fSDan Williams phy_mask = ihost->oem_parameters.ports[port_index].phy_mask;
258e2f8db50SDan Williams
259e2f8db50SDan Williams if (!phy_mask)
260e2f8db50SDan Williams continue;
261e2f8db50SDan Williams /*
262e2f8db50SDan Williams * Make sure that one or more of the phys were not already assinged to
263e2f8db50SDan Williams * a different port. */
264e2f8db50SDan Williams if ((phy_mask & ~assigned_phy_mask) == 0) {
265e2f8db50SDan Williams return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
266e2f8db50SDan Williams }
267e2f8db50SDan Williams
268e2f8db50SDan Williams /* Find the starting phy index for this round through the loop */
269e2f8db50SDan Williams for (phy_index = 0; phy_index < SCI_MAX_PHYS; phy_index++) {
270e2f8db50SDan Williams if ((phy_mask & (1 << phy_index)) == 0)
271e2f8db50SDan Williams continue;
27289a7301fSDan Williams sci_phy_get_sas_address(&ihost->phys[phy_index],
273e2f8db50SDan Williams &sas_address);
274e2f8db50SDan Williams
275e2f8db50SDan Williams /*
276e2f8db50SDan Williams * The phy_index can be used as the starting point for the
277e2f8db50SDan Williams * port range since the hardware starts all logical ports
278e2f8db50SDan Williams * the same as the PE index. */
279e2f8db50SDan Williams port_agent->phy_valid_port_range[phy_index].min_index = port_index;
280e2f8db50SDan Williams port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
281e2f8db50SDan Williams
282e2f8db50SDan Williams if (phy_index != port_index) {
283e2f8db50SDan Williams return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
284e2f8db50SDan Williams }
285e2f8db50SDan Williams
286e2f8db50SDan Williams break;
287e2f8db50SDan Williams }
288e2f8db50SDan Williams
289e2f8db50SDan Williams /*
290e2f8db50SDan Williams * See how many additional phys are being added to this logical port.
291e2f8db50SDan Williams * Note: We have not moved the current phy_index so we will actually
292e2f8db50SDan Williams * compare the startting phy with itself.
293e2f8db50SDan Williams * This is expected and required to add the phy to the port. */
2944bc83b3fSColin Ian King for (; phy_index < SCI_MAX_PHYS; phy_index++) {
295e2f8db50SDan Williams if ((phy_mask & (1 << phy_index)) == 0)
296e2f8db50SDan Williams continue;
29789a7301fSDan Williams sci_phy_get_sas_address(&ihost->phys[phy_index],
298e2f8db50SDan Williams &phy_assigned_address);
299e2f8db50SDan Williams
300e2f8db50SDan Williams if (sci_sas_address_compare(sas_address, phy_assigned_address) != 0) {
301e2f8db50SDan Williams /*
302e2f8db50SDan Williams * The phy mask specified that this phy is part of the same port
303e2f8db50SDan Williams * as the starting phy and it is not so fail this configuration */
304e2f8db50SDan Williams return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
305e2f8db50SDan Williams }
306e2f8db50SDan Williams
307e2f8db50SDan Williams port_agent->phy_valid_port_range[phy_index].min_index = port_index;
308e2f8db50SDan Williams port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
309e2f8db50SDan Williams
31089a7301fSDan Williams sci_port_add_phy(&ihost->ports[port_index],
31185280955SDan Williams &ihost->phys[phy_index]);
312e2f8db50SDan Williams
313e2f8db50SDan Williams assigned_phy_mask |= (1 << phy_index);
314e2f8db50SDan Williams }
315e2f8db50SDan Williams
316e2f8db50SDan Williams }
317e2f8db50SDan Williams
31889a7301fSDan Williams return sci_port_configuration_agent_validate_ports(ihost, port_agent);
319e2f8db50SDan Williams }
320e2f8db50SDan Williams
mpc_agent_timeout(struct timer_list * t)321b0a2dc66SKees Cook static void mpc_agent_timeout(struct timer_list *t)
322e2f8db50SDan Williams {
323e2f8db50SDan Williams u8 index;
324b0a2dc66SKees Cook struct sci_timer *tmr = from_timer(tmr, t, timer);
32589a7301fSDan Williams struct sci_port_configuration_agent *port_agent;
326ac0eeb4fSEdmund Nadolski struct isci_host *ihost;
327ac0eeb4fSEdmund Nadolski unsigned long flags;
328e2f8db50SDan Williams u16 configure_phy_mask;
329e2f8db50SDan Williams
330ac0eeb4fSEdmund Nadolski port_agent = container_of(tmr, typeof(*port_agent), timer);
331d9dcb4baSDan Williams ihost = container_of(port_agent, typeof(*ihost), port_agent);
332ac0eeb4fSEdmund Nadolski
333ac0eeb4fSEdmund Nadolski spin_lock_irqsave(&ihost->scic_lock, flags);
334ac0eeb4fSEdmund Nadolski
335ac0eeb4fSEdmund Nadolski if (tmr->cancel)
336ac0eeb4fSEdmund Nadolski goto done;
337ac0eeb4fSEdmund Nadolski
338e2f8db50SDan Williams port_agent->timer_pending = false;
339e2f8db50SDan Williams
340e2f8db50SDan Williams /* Find the mask of phys that are reported read but as yet unconfigured into a port */
341e2f8db50SDan Williams configure_phy_mask = ~port_agent->phy_configured_mask & port_agent->phy_ready_mask;
342e2f8db50SDan Williams
343e2f8db50SDan Williams for (index = 0; index < SCI_MAX_PHYS; index++) {
34485280955SDan Williams struct isci_phy *iphy = &ihost->phys[index];
345e2f8db50SDan Williams
346e2f8db50SDan Williams if (configure_phy_mask & (1 << index)) {
347d9dcb4baSDan Williams port_agent->link_up_handler(ihost, port_agent,
34885280955SDan Williams phy_get_non_dummy_port(iphy),
34985280955SDan Williams iphy);
350e2f8db50SDan Williams }
351e2f8db50SDan Williams }
352ac0eeb4fSEdmund Nadolski
353ac0eeb4fSEdmund Nadolski done:
354ac0eeb4fSEdmund Nadolski spin_unlock_irqrestore(&ihost->scic_lock, flags);
355e2f8db50SDan Williams }
356e2f8db50SDan Williams
sci_mpc_agent_link_up(struct isci_host * ihost,struct sci_port_configuration_agent * port_agent,struct isci_port * iport,struct isci_phy * iphy)35789a7301fSDan Williams static void sci_mpc_agent_link_up(struct isci_host *ihost,
35889a7301fSDan Williams struct sci_port_configuration_agent *port_agent,
359ffe191c9SDan Williams struct isci_port *iport,
36085280955SDan Williams struct isci_phy *iphy)
361e2f8db50SDan Williams {
362ffe191c9SDan Williams /* If the port is NULL then the phy was not assigned to a port.
363ffe191c9SDan Williams * This is because the phy was not given the same SAS Address as
364ffe191c9SDan Williams * the other PHYs in the port.
36585280955SDan Williams */
366ffe191c9SDan Williams if (!iport)
367ffe191c9SDan Williams return;
368ffe191c9SDan Williams
36934a99158SDan Williams port_agent->phy_ready_mask |= (1 << iphy->phy_index);
37089a7301fSDan Williams sci_port_link_up(iport, iphy);
37134a99158SDan Williams if ((iport->active_phy_mask & (1 << iphy->phy_index)))
37234a99158SDan Williams port_agent->phy_configured_mask |= (1 << iphy->phy_index);
373e2f8db50SDan Williams }
374e2f8db50SDan Williams
375e2f8db50SDan Williams /**
376*29faa5ceSLee Jones * sci_mpc_agent_link_down()
377*29faa5ceSLee Jones * @ihost: This is the controller object that receives the link down
378e2f8db50SDan Williams * notification.
379*29faa5ceSLee Jones * @port_agent: This is the port configuration agent for the controller.
380*29faa5ceSLee Jones * @iport: This is the port object associated with the phy. If the is no
381e2f8db50SDan Williams * associated port this is an NULL. The port is an invalid
382e2f8db50SDan Williams * handle only if the phy was never port of this port. This happens when
383e2f8db50SDan Williams * the phy is not broadcasting the same SAS address as the other phys in the
384e2f8db50SDan Williams * assigned port.
385*29faa5ceSLee Jones * @iphy: This is the phy object which has gone link down.
386e2f8db50SDan Williams *
387e2f8db50SDan Williams * This function handles the manual port configuration link down notifications.
388e2f8db50SDan Williams * Since all ports and phys are associated at initialization time we just turn
389e2f8db50SDan Williams * around and notifiy the port object of the link down event. If this PHY is
390e2f8db50SDan Williams * not associated with a port there is no action taken. Is it possible to get a
391e2f8db50SDan Williams * link down notification from a phy that has no assocoated port?
392e2f8db50SDan Williams */
sci_mpc_agent_link_down(struct isci_host * ihost,struct sci_port_configuration_agent * port_agent,struct isci_port * iport,struct isci_phy * iphy)39389a7301fSDan Williams static void sci_mpc_agent_link_down(
394d9dcb4baSDan Williams struct isci_host *ihost,
39589a7301fSDan Williams struct sci_port_configuration_agent *port_agent,
396ffe191c9SDan Williams struct isci_port *iport,
39785280955SDan Williams struct isci_phy *iphy)
398e2f8db50SDan Williams {
399ffe191c9SDan Williams if (iport != NULL) {
400e2f8db50SDan Williams /*
401e2f8db50SDan Williams * If we can form a new port from the remainder of the phys
402e2f8db50SDan Williams * then we want to start the timer to allow the SCI User to
403e2f8db50SDan Williams * cleanup old devices and rediscover the port before
404e2f8db50SDan Williams * rebuilding the port with the phys that remain in the ready
405e2f8db50SDan Williams * state.
406e2f8db50SDan Williams */
40734a99158SDan Williams port_agent->phy_ready_mask &= ~(1 << iphy->phy_index);
40834a99158SDan Williams port_agent->phy_configured_mask &= ~(1 << iphy->phy_index);
409e2f8db50SDan Williams
410e2f8db50SDan Williams /*
411e2f8db50SDan Williams * Check to see if there are more phys waiting to be
412e2f8db50SDan Williams * configured into a port. If there are allow the SCI User
413e2f8db50SDan Williams * to tear down this port, if necessary, and then reconstruct
414e2f8db50SDan Williams * the port after the timeout.
415e2f8db50SDan Williams */
416e2f8db50SDan Williams if ((port_agent->phy_configured_mask == 0x0000) &&
417e2f8db50SDan Williams (port_agent->phy_ready_mask != 0x0000) &&
418e2f8db50SDan Williams !port_agent->timer_pending) {
419e2f8db50SDan Williams port_agent->timer_pending = true;
420e2f8db50SDan Williams
421ac0eeb4fSEdmund Nadolski sci_mod_timer(&port_agent->timer,
422e2f8db50SDan Williams SCIC_SDS_MPC_RECONFIGURATION_TIMEOUT);
423e2f8db50SDan Williams }
424e2f8db50SDan Williams
42589a7301fSDan Williams sci_port_link_down(iport, iphy);
426e2f8db50SDan Williams }
427e2f8db50SDan Williams }
428e2f8db50SDan Williams
429d9dcb4baSDan Williams /* verify phys are assigned a valid SAS address for automatic port
430d9dcb4baSDan Williams * configuration mode.
431e2f8db50SDan Williams */
432d9dcb4baSDan Williams static enum sci_status
sci_apc_agent_validate_phy_configuration(struct isci_host * ihost,struct sci_port_configuration_agent * port_agent)43389a7301fSDan Williams sci_apc_agent_validate_phy_configuration(struct isci_host *ihost,
43489a7301fSDan Williams struct sci_port_configuration_agent *port_agent)
435e2f8db50SDan Williams {
436e2f8db50SDan Williams u8 phy_index;
437e2f8db50SDan Williams u8 port_index;
438e2f8db50SDan Williams struct sci_sas_address sas_address;
439e2f8db50SDan Williams struct sci_sas_address phy_assigned_address;
440e2f8db50SDan Williams
441e2f8db50SDan Williams phy_index = 0;
442e2f8db50SDan Williams
443e2f8db50SDan Williams while (phy_index < SCI_MAX_PHYS) {
444e2f8db50SDan Williams port_index = phy_index;
445e2f8db50SDan Williams
446e2f8db50SDan Williams /* Get the assigned SAS Address for the first PHY on the controller. */
44789a7301fSDan Williams sci_phy_get_sas_address(&ihost->phys[phy_index],
448e2f8db50SDan Williams &sas_address);
449e2f8db50SDan Williams
450e2f8db50SDan Williams while (++phy_index < SCI_MAX_PHYS) {
45189a7301fSDan Williams sci_phy_get_sas_address(&ihost->phys[phy_index],
452e2f8db50SDan Williams &phy_assigned_address);
453e2f8db50SDan Williams
454e2f8db50SDan Williams /* Verify each of the SAS address are all the same for every PHY */
455e2f8db50SDan Williams if (sci_sas_address_compare(sas_address, phy_assigned_address) == 0) {
456e2f8db50SDan Williams port_agent->phy_valid_port_range[phy_index].min_index = port_index;
457e2f8db50SDan Williams port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
458e2f8db50SDan Williams } else {
459e2f8db50SDan Williams port_agent->phy_valid_port_range[phy_index].min_index = phy_index;
460e2f8db50SDan Williams port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
461e2f8db50SDan Williams break;
462e2f8db50SDan Williams }
463e2f8db50SDan Williams }
464e2f8db50SDan Williams }
465e2f8db50SDan Williams
46689a7301fSDan Williams return sci_port_configuration_agent_validate_ports(ihost, port_agent);
467e2f8db50SDan Williams }
468e2f8db50SDan Williams
469be778341SMarcin Tomczak /*
470be778341SMarcin Tomczak * This routine will restart the automatic port configuration timeout
471be778341SMarcin Tomczak * timer for the next time period. This could be caused by either a link
472be778341SMarcin Tomczak * down event or a link up event where we can not yet tell to which a phy
473be778341SMarcin Tomczak * belongs.
474be778341SMarcin Tomczak */
sci_apc_agent_start_timer(struct sci_port_configuration_agent * port_agent,u32 timeout)47550a92d93SDan Williams static void sci_apc_agent_start_timer(struct sci_port_configuration_agent *port_agent,
476be778341SMarcin Tomczak u32 timeout)
477be778341SMarcin Tomczak {
478be778341SMarcin Tomczak port_agent->timer_pending = true;
479be778341SMarcin Tomczak sci_mod_timer(&port_agent->timer, timeout);
480be778341SMarcin Tomczak }
481be778341SMarcin Tomczak
sci_apc_agent_configure_ports(struct isci_host * ihost,struct sci_port_configuration_agent * port_agent,struct isci_phy * iphy,bool start_timer)48289a7301fSDan Williams static void sci_apc_agent_configure_ports(struct isci_host *ihost,
48389a7301fSDan Williams struct sci_port_configuration_agent *port_agent,
48485280955SDan Williams struct isci_phy *iphy,
485e2f8db50SDan Williams bool start_timer)
486e2f8db50SDan Williams {
487e2f8db50SDan Williams u8 port_index;
488e2f8db50SDan Williams enum sci_status status;
489ffe191c9SDan Williams struct isci_port *iport;
490e2f8db50SDan Williams enum SCIC_SDS_APC_ACTIVITY apc_activity = SCIC_SDS_APC_SKIP_PHY;
491e2f8db50SDan Williams
49289a7301fSDan Williams iport = sci_port_configuration_agent_find_port(ihost, iphy);
493e2f8db50SDan Williams
494ffe191c9SDan Williams if (iport) {
49589a7301fSDan Williams if (sci_port_is_valid_phy_assignment(iport, iphy->phy_index))
496e2f8db50SDan Williams apc_activity = SCIC_SDS_APC_ADD_PHY;
497e2f8db50SDan Williams else
498e2f8db50SDan Williams apc_activity = SCIC_SDS_APC_SKIP_PHY;
499e2f8db50SDan Williams } else {
500e2f8db50SDan Williams /*
501e2f8db50SDan Williams * There is no matching Port for this PHY so lets search through the
502e2f8db50SDan Williams * Ports and see if we can add the PHY to its own port or maybe start
503e2f8db50SDan Williams * the timer and wait to see if a wider port can be made.
504e2f8db50SDan Williams *
505e2f8db50SDan Williams * Note the break when we reach the condition of the port id == phy id */
506ffe191c9SDan Williams for (port_index = port_agent->phy_valid_port_range[iphy->phy_index].min_index;
50785280955SDan Williams port_index <= port_agent->phy_valid_port_range[iphy->phy_index].max_index;
508ffe191c9SDan Williams port_index++) {
509e2f8db50SDan Williams
510ffe191c9SDan Williams iport = &ihost->ports[port_index];
511e2f8db50SDan Williams
512e2f8db50SDan Williams /* First we must make sure that this PHY can be added to this Port. */
51389a7301fSDan Williams if (sci_port_is_valid_phy_assignment(iport, iphy->phy_index)) {
514e2f8db50SDan Williams /*
515e2f8db50SDan Williams * Port contains a PHY with a greater PHY ID than the current
516e2f8db50SDan Williams * PHY that has gone link up. This phy can not be part of any
517e2f8db50SDan Williams * port so skip it and move on. */
518ffe191c9SDan Williams if (iport->active_phy_mask > (1 << iphy->phy_index)) {
519e2f8db50SDan Williams apc_activity = SCIC_SDS_APC_SKIP_PHY;
520e2f8db50SDan Williams break;
521e2f8db50SDan Williams }
522e2f8db50SDan Williams
523e2f8db50SDan Williams /*
524e2f8db50SDan Williams * We have reached the end of our Port list and have not found
525e2f8db50SDan Williams * any reason why we should not either add the PHY to the port
526e2f8db50SDan Williams * or wait for more phys to become active. */
527ffe191c9SDan Williams if (iport->physical_port_index == iphy->phy_index) {
528e2f8db50SDan Williams /*
529e2f8db50SDan Williams * The Port either has no active PHYs.
530e2f8db50SDan Williams * Consider that if the port had any active PHYs we would have
531e2f8db50SDan Williams * or active PHYs with
532e2f8db50SDan Williams * a lower PHY Id than this PHY. */
533e2f8db50SDan Williams if (apc_activity != SCIC_SDS_APC_START_TIMER) {
534e2f8db50SDan Williams apc_activity = SCIC_SDS_APC_ADD_PHY;
535e2f8db50SDan Williams }
536e2f8db50SDan Williams
537e2f8db50SDan Williams break;
538e2f8db50SDan Williams }
539e2f8db50SDan Williams
540e2f8db50SDan Williams /*
541e2f8db50SDan Williams * The current Port has no active PHYs and this PHY could be part
542e2f8db50SDan Williams * of this Port. Since we dont know as yet setup to start the
543e2f8db50SDan Williams * timer and see if there is a better configuration. */
544ffe191c9SDan Williams if (iport->active_phy_mask == 0) {
545e2f8db50SDan Williams apc_activity = SCIC_SDS_APC_START_TIMER;
546e2f8db50SDan Williams }
547ffe191c9SDan Williams } else if (iport->active_phy_mask != 0) {
548e2f8db50SDan Williams /*
549e2f8db50SDan Williams * The Port has an active phy and the current Phy can not
550e2f8db50SDan Williams * participate in this port so skip the PHY and see if
551e2f8db50SDan Williams * there is a better configuration. */
552e2f8db50SDan Williams apc_activity = SCIC_SDS_APC_SKIP_PHY;
553e2f8db50SDan Williams }
554e2f8db50SDan Williams }
555e2f8db50SDan Williams }
556e2f8db50SDan Williams
557e2f8db50SDan Williams /*
558e2f8db50SDan Williams * Check to see if the start timer operations should instead map to an
559e2f8db50SDan Williams * add phy operation. This is caused because we have been waiting to
560e2f8db50SDan Williams * add a phy to a port but could not becuase the automatic port
561e2f8db50SDan Williams * configuration engine had a choice of possible ports for the phy.
562e2f8db50SDan Williams * Since we have gone through a timeout we are going to restrict the
563e2f8db50SDan Williams * choice to the smallest possible port. */
564e2f8db50SDan Williams if (
565e2f8db50SDan Williams (start_timer == false)
566e2f8db50SDan Williams && (apc_activity == SCIC_SDS_APC_START_TIMER)
567e2f8db50SDan Williams ) {
568e2f8db50SDan Williams apc_activity = SCIC_SDS_APC_ADD_PHY;
569e2f8db50SDan Williams }
570e2f8db50SDan Williams
571e2f8db50SDan Williams switch (apc_activity) {
572e2f8db50SDan Williams case SCIC_SDS_APC_ADD_PHY:
57389a7301fSDan Williams status = sci_port_add_phy(iport, iphy);
574e2f8db50SDan Williams
575e2f8db50SDan Williams if (status == SCI_SUCCESS) {
57685280955SDan Williams port_agent->phy_configured_mask |= (1 << iphy->phy_index);
577e2f8db50SDan Williams }
578e2f8db50SDan Williams break;
579e2f8db50SDan Williams
580e2f8db50SDan Williams case SCIC_SDS_APC_START_TIMER:
581be778341SMarcin Tomczak sci_apc_agent_start_timer(port_agent,
582ac0eeb4fSEdmund Nadolski SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION);
583e2f8db50SDan Williams break;
584e2f8db50SDan Williams
585e2f8db50SDan Williams case SCIC_SDS_APC_SKIP_PHY:
586e2f8db50SDan Williams default:
587e2f8db50SDan Williams /* do nothing the PHY can not be made part of a port at this time. */
588e2f8db50SDan Williams break;
589e2f8db50SDan Williams }
590e2f8db50SDan Williams }
591e2f8db50SDan Williams
592e2f8db50SDan Williams /**
59389a7301fSDan Williams * sci_apc_agent_link_up - handle apc link up events
594*29faa5ceSLee Jones * @ihost: This is the controller object that receives the link up
595e2f8db50SDan Williams * notification.
596*29faa5ceSLee Jones * @port_agent: This is the port configuration agent for the controller.
597*29faa5ceSLee Jones * @iport: This is the port object associated with the phy. If the is no
598e2f8db50SDan Williams * associated port this is an NULL.
599*29faa5ceSLee Jones * @iphy: This is the phy object which has gone link up.
600e2f8db50SDan Williams *
601e2f8db50SDan Williams * This method handles the automatic port configuration for link up
602e2f8db50SDan Williams * notifications. Is it possible to get a link down notification from a phy
603e2f8db50SDan Williams * that has no assocoated port?
604e2f8db50SDan Williams */
sci_apc_agent_link_up(struct isci_host * ihost,struct sci_port_configuration_agent * port_agent,struct isci_port * iport,struct isci_phy * iphy)60589a7301fSDan Williams static void sci_apc_agent_link_up(struct isci_host *ihost,
60689a7301fSDan Williams struct sci_port_configuration_agent *port_agent,
607ffe191c9SDan Williams struct isci_port *iport,
60885280955SDan Williams struct isci_phy *iphy)
609e2f8db50SDan Williams {
61085280955SDan Williams u8 phy_index = iphy->phy_index;
611e2f8db50SDan Williams
612ffe191c9SDan Williams if (!iport) {
613e2f8db50SDan Williams /* the phy is not the part of this port */
614e2f8db50SDan Williams port_agent->phy_ready_mask |= 1 << phy_index;
615be778341SMarcin Tomczak sci_apc_agent_start_timer(port_agent,
616be778341SMarcin Tomczak SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION);
617e2f8db50SDan Williams } else {
618e2f8db50SDan Williams /* the phy is already the part of the port */
619e2f8db50SDan Williams port_agent->phy_ready_mask |= 1 << phy_index;
62089a7301fSDan Williams sci_port_link_up(iport, iphy);
621e2f8db50SDan Williams }
622e2f8db50SDan Williams }
623e2f8db50SDan Williams
624e2f8db50SDan Williams /**
625*29faa5ceSLee Jones * sci_apc_agent_link_down()
626*29faa5ceSLee Jones * @ihost: This is the controller object that receives the link down
627e2f8db50SDan Williams * notification.
628*29faa5ceSLee Jones * @port_agent: This is the port configuration agent for the controller.
629ffe191c9SDan Williams * @iport: This is the port object associated with the phy. If the is no
630e2f8db50SDan Williams * associated port this is an NULL.
631ffe191c9SDan Williams * @iphy: This is the phy object which has gone link down.
632e2f8db50SDan Williams *
633e2f8db50SDan Williams * This method handles the automatic port configuration link down
634e2f8db50SDan Williams * notifications. not associated with a port there is no action taken. Is it
635e2f8db50SDan Williams * possible to get a link down notification from a phy that has no assocoated
636e2f8db50SDan Williams * port?
637e2f8db50SDan Williams */
sci_apc_agent_link_down(struct isci_host * ihost,struct sci_port_configuration_agent * port_agent,struct isci_port * iport,struct isci_phy * iphy)63889a7301fSDan Williams static void sci_apc_agent_link_down(
639d9dcb4baSDan Williams struct isci_host *ihost,
64089a7301fSDan Williams struct sci_port_configuration_agent *port_agent,
641ffe191c9SDan Williams struct isci_port *iport,
64285280955SDan Williams struct isci_phy *iphy)
643e2f8db50SDan Williams {
64434a99158SDan Williams port_agent->phy_ready_mask &= ~(1 << iphy->phy_index);
645e2f8db50SDan Williams
646ffe191c9SDan Williams if (!iport)
647ffe191c9SDan Williams return;
64885280955SDan Williams if (port_agent->phy_configured_mask & (1 << iphy->phy_index)) {
649e2f8db50SDan Williams enum sci_status status;
650e2f8db50SDan Williams
65189a7301fSDan Williams status = sci_port_remove_phy(iport, iphy);
652e2f8db50SDan Williams
653ffe191c9SDan Williams if (status == SCI_SUCCESS)
65485280955SDan Williams port_agent->phy_configured_mask &= ~(1 << iphy->phy_index);
655e2f8db50SDan Williams }
656e2f8db50SDan Williams }
657e2f8db50SDan Williams
658e2f8db50SDan Williams /* configure the phys into ports when the timer fires */
apc_agent_timeout(struct timer_list * t)659b0a2dc66SKees Cook static void apc_agent_timeout(struct timer_list *t)
660e2f8db50SDan Williams {
661e2f8db50SDan Williams u32 index;
662b0a2dc66SKees Cook struct sci_timer *tmr = from_timer(tmr, t, timer);
66389a7301fSDan Williams struct sci_port_configuration_agent *port_agent;
664ac0eeb4fSEdmund Nadolski struct isci_host *ihost;
665ac0eeb4fSEdmund Nadolski unsigned long flags;
666e2f8db50SDan Williams u16 configure_phy_mask;
667e2f8db50SDan Williams
668ac0eeb4fSEdmund Nadolski port_agent = container_of(tmr, typeof(*port_agent), timer);
669d9dcb4baSDan Williams ihost = container_of(port_agent, typeof(*ihost), port_agent);
670ac0eeb4fSEdmund Nadolski
671ac0eeb4fSEdmund Nadolski spin_lock_irqsave(&ihost->scic_lock, flags);
672ac0eeb4fSEdmund Nadolski
673ac0eeb4fSEdmund Nadolski if (tmr->cancel)
674ac0eeb4fSEdmund Nadolski goto done;
675e2f8db50SDan Williams
676e2f8db50SDan Williams port_agent->timer_pending = false;
677e2f8db50SDan Williams
678e2f8db50SDan Williams configure_phy_mask = ~port_agent->phy_configured_mask & port_agent->phy_ready_mask;
679e2f8db50SDan Williams
680e2f8db50SDan Williams if (!configure_phy_mask)
681983d3fddSJeff Skirvin goto done;
682e2f8db50SDan Williams
683e2f8db50SDan Williams for (index = 0; index < SCI_MAX_PHYS; index++) {
684e2f8db50SDan Williams if ((configure_phy_mask & (1 << index)) == 0)
685e2f8db50SDan Williams continue;
686e2f8db50SDan Williams
68789a7301fSDan Williams sci_apc_agent_configure_ports(ihost, port_agent,
68885280955SDan Williams &ihost->phys[index], false);
689e2f8db50SDan Williams }
690ac0eeb4fSEdmund Nadolski
69150a92d93SDan Williams if (is_controller_start_complete(ihost))
69250a92d93SDan Williams sci_controller_transition_to_ready(ihost, SCI_SUCCESS);
69350a92d93SDan Williams
694ac0eeb4fSEdmund Nadolski done:
695ac0eeb4fSEdmund Nadolski spin_unlock_irqrestore(&ihost->scic_lock, flags);
696e2f8db50SDan Williams }
697e2f8db50SDan Williams
698e2f8db50SDan Williams /*
699e2f8db50SDan Williams * ******************************************************************************
700e2f8db50SDan Williams * Public port configuration agent routines
701e2f8db50SDan Williams * ****************************************************************************** */
702e2f8db50SDan Williams
703*29faa5ceSLee Jones /*
704e2f8db50SDan Williams * This method will construct the port configuration agent for operation. This
705e2f8db50SDan Williams * call is universal for both manual port configuration and automatic port
706e2f8db50SDan Williams * configuration modes.
707e2f8db50SDan Williams */
sci_port_configuration_agent_construct(struct sci_port_configuration_agent * port_agent)70889a7301fSDan Williams void sci_port_configuration_agent_construct(
70989a7301fSDan Williams struct sci_port_configuration_agent *port_agent)
710e2f8db50SDan Williams {
711e2f8db50SDan Williams u32 index;
712e2f8db50SDan Williams
713e2f8db50SDan Williams port_agent->phy_configured_mask = 0x00;
714e2f8db50SDan Williams port_agent->phy_ready_mask = 0x00;
715e2f8db50SDan Williams
716e2f8db50SDan Williams port_agent->link_up_handler = NULL;
717e2f8db50SDan Williams port_agent->link_down_handler = NULL;
718e2f8db50SDan Williams
719e2f8db50SDan Williams port_agent->timer_pending = false;
720e2f8db50SDan Williams
721e2f8db50SDan Williams for (index = 0; index < SCI_MAX_PORTS; index++) {
722e2f8db50SDan Williams port_agent->phy_valid_port_range[index].min_index = 0;
723e2f8db50SDan Williams port_agent->phy_valid_port_range[index].max_index = 0;
724e2f8db50SDan Williams }
725e2f8db50SDan Williams }
726e2f8db50SDan Williams
is_port_config_apc(struct isci_host * ihost)72750a92d93SDan Williams bool is_port_config_apc(struct isci_host *ihost)
72850a92d93SDan Williams {
72950a92d93SDan Williams return ihost->port_agent.link_up_handler == sci_apc_agent_link_up;
73050a92d93SDan Williams }
73150a92d93SDan Williams
sci_port_configuration_agent_initialize(struct isci_host * ihost,struct sci_port_configuration_agent * port_agent)73289a7301fSDan Williams enum sci_status sci_port_configuration_agent_initialize(
733d9dcb4baSDan Williams struct isci_host *ihost,
73489a7301fSDan Williams struct sci_port_configuration_agent *port_agent)
735e2f8db50SDan Williams {
736ac0eeb4fSEdmund Nadolski enum sci_status status;
73789a7301fSDan Williams enum sci_port_configuration_mode mode;
738e2f8db50SDan Williams
73989a7301fSDan Williams mode = ihost->oem_parameters.controller.mode_type;
740e2f8db50SDan Williams
741e2f8db50SDan Williams if (mode == SCIC_PORT_MANUAL_CONFIGURATION_MODE) {
74289a7301fSDan Williams status = sci_mpc_agent_validate_phy_configuration(
743d9dcb4baSDan Williams ihost, port_agent);
744e2f8db50SDan Williams
74589a7301fSDan Williams port_agent->link_up_handler = sci_mpc_agent_link_up;
74689a7301fSDan Williams port_agent->link_down_handler = sci_mpc_agent_link_down;
747e2f8db50SDan Williams
748ac0eeb4fSEdmund Nadolski sci_init_timer(&port_agent->timer, mpc_agent_timeout);
749e2f8db50SDan Williams } else {
75089a7301fSDan Williams status = sci_apc_agent_validate_phy_configuration(
751d9dcb4baSDan Williams ihost, port_agent);
752e2f8db50SDan Williams
75389a7301fSDan Williams port_agent->link_up_handler = sci_apc_agent_link_up;
75489a7301fSDan Williams port_agent->link_down_handler = sci_apc_agent_link_down;
755e2f8db50SDan Williams
756ac0eeb4fSEdmund Nadolski sci_init_timer(&port_agent->timer, apc_agent_timeout);
757e2f8db50SDan Williams }
758e2f8db50SDan Williams
759e2f8db50SDan Williams return status;
760e2f8db50SDan Williams }
761