isci: unify phy data structures
[deliverable/linux.git] / drivers / scsi / isci / core / scic_sds_port_configuration_agent.c
CommitLineData
6f231dda
DW
1/*
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.
4 *
5 * GPL LICENSE SUMMARY
6 *
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8 *
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.
12 *
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.
17 *
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.
23 *
24 * BSD LICENSE
25 *
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 *
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
38 * distribution.
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.
42 *
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.
54 */
55
56/**
57 * This file contains the implementation for the public and protected methods
58 * for the port configuration agent.
59 *
60 *
61 */
62
63#include "sci_environment.h"
64#include "scic_controller.h"
65#include "scic_sds_controller.h"
66#include "scic_sds_port_configuration_agent.h"
67
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)
71
72enum SCIC_SDS_APC_ACTIVITY {
73 SCIC_SDS_APC_SKIP_PHY,
74 SCIC_SDS_APC_ADD_PHY,
75 SCIC_SDS_APC_START_TIMER,
76
77 SCIC_SDS_APC_ACTIVITY_MAX
78};
79
80/*
81 * ******************************************************************************
82 * General port configuration agent routines
83 * ****************************************************************************** */
84
85/**
86 *
87 * @address_one: A SAS Address to be compared.
88 * @address_two: A SAS Address to be compared.
89 *
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
95 */
96static s32 sci_sas_address_compare(
97 struct sci_sas_address address_one,
98 struct sci_sas_address address_two)
99{
100 if (address_one.high > address_two.high) {
101 return 1;
102 } else if (address_one.high < address_two.high) {
103 return -1;
104 } else if (address_one.low > address_two.low) {
105 return 1;
106 } else if (address_one.low < address_two.low) {
107 return -1;
108 }
109
110 /* The two SAS Address must be identical */
111 return 0;
112}
113
114/**
115 *
116 * @controller: The controller object used for the port search.
117 * @phy: The phy object to match.
118 *
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
a7e536c7 121 * address. The port address or the NULL if there is no matching
6f231dda 122 * port. port address if the port can be found to match the phy.
a7e536c7 123 * NULL if there is no matching port for the phy.
6f231dda
DW
124 */
125static struct scic_sds_port *scic_sds_port_configuration_agent_find_port(
ed30c275 126 struct scic_sds_controller *scic,
6f231dda
DW
127 struct scic_sds_phy *phy)
128{
ed30c275 129 u8 i;
6f231dda
DW
130 struct sci_sas_address port_sas_address;
131 struct sci_sas_address port_attached_device_address;
132 struct sci_sas_address phy_sas_address;
133 struct sci_sas_address phy_attached_device_address;
134
135 /*
136 * Since this phy can be a member of a wide port check to see if one or
137 * more phys match the sent and received SAS address as this phy in which
ed30c275
EN
138 * case it should participate in the same port.
139 */
6f231dda
DW
140 scic_sds_phy_get_sas_address(phy, &phy_sas_address);
141 scic_sds_phy_get_attached_sas_address(phy, &phy_attached_device_address);
142
ed30c275
EN
143 for (i = 0; i < scic->logical_port_entries; i++) {
144 struct scic_sds_port *port = &scic->port_table[i];
6f231dda 145
ed30c275
EN
146 scic_sds_port_get_sas_address(port, &port_sas_address);
147 scic_sds_port_get_attached_sas_address(port, &port_attached_device_address);
6f231dda 148
ed30c275
EN
149 if ((sci_sas_address_compare(port_sas_address, phy_sas_address) == 0) &&
150 (sci_sas_address_compare(port_attached_device_address, phy_attached_device_address) == 0))
151 return port;
6f231dda
DW
152 }
153
a7e536c7 154 return NULL;
6f231dda
DW
155}
156
157/**
158 *
159 * @controller: This is the controller object that contains the port agent
160 * @port_agent: This is the port configruation agent for the controller.
161 *
162 * This routine will validate the port configuration is correct for the SCU
163 * hardware. The SCU hardware allows for port configurations as follows. LP0
164 * -> (PE0), (PE0, PE1), (PE0, PE1, PE2, PE3) LP1 -> (PE1) LP2 -> (PE2), (PE2,
165 * PE3) LP3 -> (PE3) enum sci_status SCI_SUCCESS the port configuration is valid for
166 * this port configuration agent. SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
167 * the port configuration is not valid for this port configuration agent.
168 */
169static enum sci_status scic_sds_port_configuration_agent_validate_ports(
170 struct scic_sds_controller *controller,
171 struct scic_sds_port_configuration_agent *port_agent)
172{
4b33981a 173 struct isci_host *ihost = scic_to_ihost(controller);
6f231dda
DW
174 struct sci_sas_address first_address;
175 struct sci_sas_address second_address;
176
177 /*
178 * Sanity check the max ranges for all the phys the max index
179 * is always equal to the port range index */
4b33981a
DW
180 if (port_agent->phy_valid_port_range[0].max_index != 0 ||
181 port_agent->phy_valid_port_range[1].max_index != 1 ||
182 port_agent->phy_valid_port_range[2].max_index != 2 ||
183 port_agent->phy_valid_port_range[3].max_index != 3)
6f231dda 184 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
6f231dda
DW
185
186 /*
187 * This is a request to configure a single x4 port or at least attempt
188 * to make all the phys into a single port */
4b33981a
DW
189 if (port_agent->phy_valid_port_range[0].min_index == 0 &&
190 port_agent->phy_valid_port_range[1].min_index == 0 &&
191 port_agent->phy_valid_port_range[2].min_index == 0 &&
192 port_agent->phy_valid_port_range[3].min_index == 0)
6f231dda 193 return SCI_SUCCESS;
6f231dda
DW
194
195 /*
196 * This is a degenerate case where phy 1 and phy 2 are assigned
197 * to the same port this is explicitly disallowed by the hardware
198 * unless they are part of the same x4 port and this condition was
199 * already checked above. */
200 if (port_agent->phy_valid_port_range[2].min_index == 1) {
201 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
202 }
203
204 /*
205 * PE0 and PE3 can never have the same SAS Address unless they
206 * are part of the same x4 wide port and we have already checked
207 * for this condition. */
4b33981a
DW
208 scic_sds_phy_get_sas_address(&ihost->phys[0].sci, &first_address);
209 scic_sds_phy_get_sas_address(&ihost->phys[3].sci, &second_address);
6f231dda
DW
210
211 if (sci_sas_address_compare(first_address, second_address) == 0) {
212 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
213 }
214
215 /*
216 * PE0 and PE1 are configured into a 2x1 ports make sure that the
217 * SAS Address for PE0 and PE2 are different since they can not be
218 * part of the same port. */
4b33981a
DW
219 if (port_agent->phy_valid_port_range[0].min_index == 0 &&
220 port_agent->phy_valid_port_range[1].min_index == 1) {
221 scic_sds_phy_get_sas_address(&ihost->phys[0].sci, &first_address);
222 scic_sds_phy_get_sas_address(&ihost->phys[2].sci, &second_address);
6f231dda
DW
223
224 if (sci_sas_address_compare(first_address, second_address) == 0) {
225 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
226 }
227 }
228
229 /*
230 * PE2 and PE3 are configured into a 2x1 ports make sure that the
231 * SAS Address for PE1 and PE3 are different since they can not be
232 * part of the same port. */
4b33981a
DW
233 if (port_agent->phy_valid_port_range[2].min_index == 2 &&
234 port_agent->phy_valid_port_range[3].min_index == 3) {
235 scic_sds_phy_get_sas_address(&ihost->phys[1].sci, &first_address);
236 scic_sds_phy_get_sas_address(&ihost->phys[3].sci, &second_address);
6f231dda
DW
237
238 if (sci_sas_address_compare(first_address, second_address) == 0) {
239 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
240 }
241 }
242
243 return SCI_SUCCESS;
244}
245
246/*
247 * ******************************************************************************
248 * Manual port configuration agent routines
249 * ****************************************************************************** */
250
251/**
252 *
253 *
254 * This routine will verify that all of the phys in the same port are using the
255 * same SAS address.
256 */
257static enum sci_status scic_sds_mpc_agent_validate_phy_configuration(
258 struct scic_sds_controller *controller,
259 struct scic_sds_port_configuration_agent *port_agent)
260{
4b33981a 261 struct isci_host *ihost = scic_to_ihost(controller);
6f231dda
DW
262 u32 phy_mask;
263 u32 assigned_phy_mask;
264 struct sci_sas_address sas_address;
265 struct sci_sas_address phy_assigned_address;
266 u8 port_index;
267 u8 phy_index;
268
269 assigned_phy_mask = 0;
270 sas_address.high = 0;
271 sas_address.low = 0;
272
273 for (port_index = 0; port_index < SCI_MAX_PORTS; port_index++) {
274 phy_mask = controller->oem_parameters.sds1.ports[port_index].phy_mask;
275
4b33981a
DW
276 if (!phy_mask)
277 continue;
278 /*
279 * Make sure that one or more of the phys were not already assinged to
280 * a different port. */
281 if ((phy_mask & ~assigned_phy_mask) == 0) {
282 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
283 }
6f231dda 284
4b33981a
DW
285 /* Find the starting phy index for this round through the loop */
286 for (phy_index = 0; phy_index < SCI_MAX_PHYS; phy_index++) {
287 if ((phy_mask & (1 << phy_index)) == 0)
288 continue;
289 scic_sds_phy_get_sas_address(&ihost->phys[phy_index].sci,
290 &sas_address);
6f231dda 291
4b33981a
DW
292 /*
293 * The phy_index can be used as the starting point for the
294 * port range since the hardware starts all logical ports
295 * the same as the PE index. */
296 port_agent->phy_valid_port_range[phy_index].min_index = port_index;
297 port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
6f231dda 298
4b33981a
DW
299 if (phy_index != port_index) {
300 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
6f231dda
DW
301 }
302
4b33981a
DW
303 break;
304 }
6f231dda 305
4b33981a
DW
306 /*
307 * See how many additional phys are being added to this logical port.
308 * Note: We have not moved the current phy_index so we will actually
309 * compare the startting phy with itself.
310 * This is expected and required to add the phy to the port. */
311 while (phy_index < SCI_MAX_PHYS) {
312 if ((phy_mask & (1 << phy_index)) == 0)
313 continue;
314 scic_sds_phy_get_sas_address(&ihost->phys[phy_index].sci,
315 &phy_assigned_address);
316
317 if (sci_sas_address_compare(sas_address, phy_assigned_address) != 0) {
318 /*
319 * The phy mask specified that this phy is part of the same port
320 * as the starting phy and it is not so fail this configuration */
321 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
322 }
6f231dda 323
4b33981a
DW
324 port_agent->phy_valid_port_range[phy_index].min_index = port_index;
325 port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
6f231dda 326
4b33981a
DW
327 scic_sds_port_add_phy(&controller->port_table[port_index],
328 &ihost->phys[phy_index].sci);
6f231dda 329
4b33981a 330 assigned_phy_mask |= (1 << phy_index);
6f231dda 331 }
4b33981a
DW
332
333 phy_index++;
6f231dda
DW
334 }
335
336 return scic_sds_port_configuration_agent_validate_ports(controller, port_agent);
337}
338
339/**
340 *
341 *
342 * This timer routine is used to allow the SCI User to rediscover or change
343 * device objects before a new series of link up notifications because a link
344 * down has allowed a better port configuration.
345 */
4b33981a 346static void scic_sds_mpc_agent_timeout_handler(void *object)
6f231dda
DW
347{
348 u8 index;
4b33981a
DW
349 struct scic_sds_controller *scic = object;
350 struct isci_host *ihost = scic_to_ihost(scic);
351 struct scic_sds_port_configuration_agent *port_agent = &scic->port_agent;
6f231dda
DW
352 u16 configure_phy_mask;
353
354 port_agent->timer_pending = false;
355
356 /* Find the mask of phys that are reported read but as yet unconfigured into a port */
357 configure_phy_mask = ~port_agent->phy_configured_mask & port_agent->phy_ready_mask;
358
359 for (index = 0; index < SCI_MAX_PHYS; index++) {
4b33981a
DW
360 struct scic_sds_phy *sci_phy = &ihost->phys[index].sci;
361
6f231dda 362 if (configure_phy_mask & (1 << index)) {
4b33981a
DW
363 port_agent->link_up_handler(scic, port_agent,
364 scic_sds_phy_get_port(sci_phy),
365 sci_phy);
6f231dda
DW
366 }
367 }
368}
369
370/**
371 *
372 * @controller: This is the controller object that receives the link up
373 * notification.
374 * @port: This is the port object associated with the phy. If the is no
a7e536c7 375 * associated port this is an NULL.
6f231dda
DW
376 * @phy: This is the phy object which has gone ready.
377 *
378 * This method handles the manual port configuration link up notifications.
379 * Since all ports and phys are associate at initialization time we just turn
380 * around and notifiy the port object that there is a link up. If this PHY is
381 * not associated with a port there is no action taken. Is it possible to get a
382 * link up notification from a phy that has no assocoated port?
383 */
384static void scic_sds_mpc_agent_link_up(
385 struct scic_sds_controller *controller,
386 struct scic_sds_port_configuration_agent *port_agent,
387 struct scic_sds_port *port,
388 struct scic_sds_phy *phy)
389{
390 /*
391 * If the port has an invalid handle then the phy was not assigned to
392 * a port. This is because the phy was not given the same SAS Address
393 * as the other PHYs in the port. */
a7e536c7 394 if (port != NULL) {
6f231dda
DW
395 port_agent->phy_ready_mask |= (1 << scic_sds_phy_get_index(phy));
396
397 scic_sds_port_link_up(port, phy);
398
399 if ((port->active_phy_mask & (1 << scic_sds_phy_get_index(phy))) != 0) {
400 port_agent->phy_configured_mask |= (1 << scic_sds_phy_get_index(phy));
401 }
402 }
403}
404
405/**
406 *
407 * @controller: This is the controller object that receives the link down
408 * notification.
409 * @port: This is the port object associated with the phy. If the is no
a7e536c7 410 * associated port this is an NULL. The port is an invalid
6f231dda
DW
411 * handle only if the phy was never port of this port. This happens when
412 * the phy is not broadcasting the same SAS address as the other phys in the
413 * assigned port.
414 * @phy: This is the phy object which has gone link down.
415 *
09d7da13 416 * This function handles the manual port configuration link down notifications.
6f231dda
DW
417 * Since all ports and phys are associated at initialization time we just turn
418 * around and notifiy the port object of the link down event. If this PHY is
419 * not associated with a port there is no action taken. Is it possible to get a
420 * link down notification from a phy that has no assocoated port?
421 */
422static void scic_sds_mpc_agent_link_down(
09d7da13 423 struct scic_sds_controller *scic,
6f231dda 424 struct scic_sds_port_configuration_agent *port_agent,
09d7da13
DJ
425 struct scic_sds_port *sci_port,
426 struct scic_sds_phy *sci_phy)
6f231dda 427{
09d7da13 428 if (sci_port != NULL) {
6f231dda 429 /*
09d7da13
DJ
430 * If we can form a new port from the remainder of the phys
431 * then we want to start the timer to allow the SCI User to
432 * cleanup old devices and rediscover the port before
433 * rebuilding the port with the phys that remain in the ready
434 * state.
435 */
436 port_agent->phy_ready_mask &=
437 ~(1 << scic_sds_phy_get_index(sci_phy));
438 port_agent->phy_configured_mask &=
439 ~(1 << scic_sds_phy_get_index(sci_phy));
6f231dda
DW
440
441 /*
09d7da13
DJ
442 * Check to see if there are more phys waiting to be
443 * configured into a port. If there are allow the SCI User
444 * to tear down this port, if necessary, and then reconstruct
445 * the port after the timeout.
446 */
447 if ((port_agent->phy_configured_mask == 0x0000) &&
448 (port_agent->phy_ready_mask != 0x0000) &&
449 !port_agent->timer_pending) {
6f231dda
DW
450 port_agent->timer_pending = true;
451
09d7da13
DJ
452 isci_timer_start(port_agent->timer,
453 SCIC_SDS_MPC_RECONFIGURATION_TIMEOUT);
6f231dda
DW
454 }
455
09d7da13 456 scic_sds_port_link_down(sci_port, sci_phy);
6f231dda
DW
457 }
458}
459
460/*
461 * ******************************************************************************
462 * Automatic port configuration agent routines
463 * ****************************************************************************** */
464
465/**
466 *
467 *
468 * This routine will verify that the phys are assigned a valid SAS address for
469 * automatic port configuration mode.
470 */
471static enum sci_status scic_sds_apc_agent_validate_phy_configuration(
472 struct scic_sds_controller *controller,
473 struct scic_sds_port_configuration_agent *port_agent)
474{
475 u8 phy_index;
476 u8 port_index;
477 struct sci_sas_address sas_address;
478 struct sci_sas_address phy_assigned_address;
4b33981a 479 struct isci_host *ihost = scic_to_ihost(controller);
6f231dda
DW
480
481 phy_index = 0;
482
483 while (phy_index < SCI_MAX_PHYS) {
484 port_index = phy_index;
485
486 /* Get the assigned SAS Address for the first PHY on the controller. */
4b33981a
DW
487 scic_sds_phy_get_sas_address(&ihost->phys[phy_index].sci,
488 &sas_address);
6f231dda
DW
489
490 while (++phy_index < SCI_MAX_PHYS) {
4b33981a
DW
491 scic_sds_phy_get_sas_address(&ihost->phys[phy_index].sci,
492 &phy_assigned_address);
6f231dda
DW
493
494 /* Verify each of the SAS address are all the same for every PHY */
495 if (sci_sas_address_compare(sas_address, phy_assigned_address) == 0) {
496 port_agent->phy_valid_port_range[phy_index].min_index = port_index;
497 port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
498 } else {
499 port_agent->phy_valid_port_range[phy_index].min_index = phy_index;
500 port_agent->phy_valid_port_range[phy_index].max_index = phy_index;
501 break;
502 }
503 }
504 }
505
506 return scic_sds_port_configuration_agent_validate_ports(controller, port_agent);
507}
508
509/**
510 *
511 * @controller: This is the controller that to which the port agent is assigned.
512 * @port_agent: This is the port agent that is requesting the timer start
513 * operation.
514 * @phy: This is the phy that has caused the timer operation to be scheduled.
515 *
516 * This routine will restart the automatic port configuration timeout timer for
517 * the next time period. This could be caused by either a link down event or a
518 * link up event where we can not yet tell to which port a phy belongs.
519 */
09d7da13
DJ
520static inline void scic_sds_apc_agent_start_timer(
521 struct scic_sds_controller *scic,
6f231dda 522 struct scic_sds_port_configuration_agent *port_agent,
09d7da13 523 struct scic_sds_phy *sci_phy,
6f231dda
DW
524 u32 timeout)
525{
09d7da13
DJ
526 if (port_agent->timer_pending)
527 isci_timer_stop(port_agent->timer);
6f231dda
DW
528
529 port_agent->timer_pending = true;
530
09d7da13 531 isci_timer_start(port_agent->timer, timeout);
6f231dda
DW
532}
533
534/**
535 *
536 * @controller: This is the controller object that receives the link up
537 * notification.
538 * @phy: This is the phy object which has gone link up.
539 *
540 * This method handles the automatic port configuration for link up
541 * notifications.
542 */
543static void scic_sds_apc_agent_configure_ports(
544 struct scic_sds_controller *controller,
545 struct scic_sds_port_configuration_agent *port_agent,
546 struct scic_sds_phy *phy,
547 bool start_timer)
548{
549 u8 port_index;
550 enum sci_status status;
551 struct scic_sds_port *port;
6f231dda
DW
552 enum SCIC_SDS_APC_ACTIVITY apc_activity = SCIC_SDS_APC_SKIP_PHY;
553
554 port = scic_sds_port_configuration_agent_find_port(controller, phy);
555
a7e536c7 556 if (port != NULL) {
6f231dda
DW
557 if (scic_sds_port_is_valid_phy_assignment(port, phy->phy_index))
558 apc_activity = SCIC_SDS_APC_ADD_PHY;
559 else
560 apc_activity = SCIC_SDS_APC_SKIP_PHY;
561 } else {
562 /*
563 * There is no matching Port for this PHY so lets search through the
564 * Ports and see if we can add the PHY to its own port or maybe start
565 * the timer and wait to see if a wider port can be made.
566 *
567 * Note the break when we reach the condition of the port id == phy id */
568 for (
569 port_index = port_agent->phy_valid_port_range[phy->phy_index].min_index;
570 port_index <= port_agent->phy_valid_port_range[phy->phy_index].max_index;
571 port_index++
572 ) {
6f231dda 573
ed30c275 574 port = &controller->port_table[port_index];
6f231dda
DW
575
576 /* First we must make sure that this PHY can be added to this Port. */
577 if (scic_sds_port_is_valid_phy_assignment(port, phy->phy_index)) {
578 /*
579 * Port contains a PHY with a greater PHY ID than the current
580 * PHY that has gone link up. This phy can not be part of any
581 * port so skip it and move on. */
582 if (port->active_phy_mask > (1 << phy->phy_index)) {
583 apc_activity = SCIC_SDS_APC_SKIP_PHY;
584 break;
585 }
586
587 /*
588 * We have reached the end of our Port list and have not found
589 * any reason why we should not either add the PHY to the port
590 * or wait for more phys to become active. */
591 if (port->physical_port_index == phy->phy_index) {
592 /*
593 * The Port either has no active PHYs.
594 * Consider that if the port had any active PHYs we would have
595 * or active PHYs with
596 * a lower PHY Id than this PHY. */
597 if (apc_activity != SCIC_SDS_APC_START_TIMER) {
598 apc_activity = SCIC_SDS_APC_ADD_PHY;
599 }
600
601 break;
602 }
603
604 /*
605 * The current Port has no active PHYs and this PHY could be part
606 * of this Port. Since we dont know as yet setup to start the
607 * timer and see if there is a better configuration. */
608 if (port->active_phy_mask == 0) {
609 apc_activity = SCIC_SDS_APC_START_TIMER;
610 }
611 } else if (port->active_phy_mask != 0) {
612 /*
613 * The Port has an active phy and the current Phy can not
614 * participate in this port so skip the PHY and see if
615 * there is a better configuration. */
616 apc_activity = SCIC_SDS_APC_SKIP_PHY;
617 }
618 }
619 }
620
621 /*
622 * Check to see if the start timer operations should instead map to an
623 * add phy operation. This is caused because we have been waiting to
624 * add a phy to a port but could not becuase the automatic port
625 * configuration engine had a choice of possible ports for the phy.
626 * Since we have gone through a timeout we are going to restrict the
627 * choice to the smallest possible port. */
628 if (
629 (start_timer == false)
630 && (apc_activity == SCIC_SDS_APC_START_TIMER)
631 ) {
632 apc_activity = SCIC_SDS_APC_ADD_PHY;
633 }
634
635 switch (apc_activity) {
636 case SCIC_SDS_APC_ADD_PHY:
637 status = scic_sds_port_add_phy(port, phy);
638
639 if (status == SCI_SUCCESS) {
640 port_agent->phy_configured_mask |= (1 << phy->phy_index);
641 }
642 break;
643
644 case SCIC_SDS_APC_START_TIMER:
645 scic_sds_apc_agent_start_timer(
646 controller, port_agent, phy, SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION
647 );
648 break;
649
650 case SCIC_SDS_APC_SKIP_PHY:
651 default:
652 /* do nothing the PHY can not be made part of a port at this time. */
653 break;
654 }
655}
656
657/**
b3824292
PS
658 * scic_sds_apc_agent_link_up - handle apc link up events
659 * @scic: This is the controller object that receives the link up
6f231dda 660 * notification.
b3824292 661 * @sci_port: This is the port object associated with the phy. If the is no
a7e536c7 662 * associated port this is an NULL.
b3824292 663 * @sci_phy: This is the phy object which has gone link up.
6f231dda
DW
664 *
665 * This method handles the automatic port configuration for link up
666 * notifications. Is it possible to get a link down notification from a phy
667 * that has no assocoated port?
668 */
b3824292
PS
669static void scic_sds_apc_agent_link_up(struct scic_sds_controller *scic,
670 struct scic_sds_port_configuration_agent *port_agent,
671 struct scic_sds_port *sci_port,
672 struct scic_sds_phy *sci_phy)
6f231dda 673{
b3824292 674 u8 phy_index = sci_phy->phy_index;
6f231dda 675
b3824292
PS
676 if (!sci_port) {
677 /* the phy is not the part of this port */
678 port_agent->phy_ready_mask |= 1 << phy_index;
679 scic_sds_apc_agent_configure_ports(scic, port_agent, sci_phy, true);
680 } else {
681 /* the phy is already the part of the port */
41e2b905 682 u32 port_state = sci_port->state_machine.current_state_id;
b3824292
PS
683
684 /* if the PORT'S state is resetting then the link up is from
685 * port hard reset in this case, we need to tell the port
686 * that link up is recieved
687 */
688 BUG_ON(port_state != SCI_BASE_PORT_STATE_RESETTING);
689 port_agent->phy_ready_mask |= 1 << phy_index;
690 scic_sds_port_link_up(sci_port, sci_phy);
691 }
6f231dda
DW
692}
693
694/**
695 *
696 * @controller: This is the controller object that receives the link down
697 * notification.
698 * @port: This is the port object associated with the phy. If the is no
a7e536c7 699 * associated port this is an NULL.
6f231dda
DW
700 * @phy: This is the phy object which has gone link down.
701 *
702 * This method handles the automatic port configuration link down
703 * notifications. not associated with a port there is no action taken. Is it
704 * possible to get a link down notification from a phy that has no assocoated
705 * port?
706 */
707static void scic_sds_apc_agent_link_down(
708 struct scic_sds_controller *controller,
709 struct scic_sds_port_configuration_agent *port_agent,
710 struct scic_sds_port *port,
711 struct scic_sds_phy *phy)
712{
713 port_agent->phy_ready_mask &= ~(1 << scic_sds_phy_get_index(phy));
714
a7e536c7 715 if (port != NULL) {
6f231dda
DW
716 if (port_agent->phy_configured_mask & (1 << phy->phy_index)) {
717 enum sci_status status;
718
719 status = scic_sds_port_remove_phy(port, phy);
720
721 if (status == SCI_SUCCESS) {
722 port_agent->phy_configured_mask &= ~(1 << phy->phy_index);
723 }
724 }
725 }
726}
727
4b33981a
DW
728/* configure the phys into ports when the timer fires */
729static void scic_sds_apc_agent_timeout_handler(void *object)
6f231dda
DW
730{
731 u32 index;
732 struct scic_sds_port_configuration_agent *port_agent;
4b33981a
DW
733 struct scic_sds_controller *scic = object;
734 struct isci_host *ihost = scic_to_ihost(scic);
6f231dda
DW
735 u16 configure_phy_mask;
736
4b33981a 737 port_agent = scic_sds_controller_get_port_configuration_agent(scic);
6f231dda
DW
738
739 port_agent->timer_pending = false;
740
741 configure_phy_mask = ~port_agent->phy_configured_mask & port_agent->phy_ready_mask;
742
4b33981a
DW
743 if (!configure_phy_mask)
744 return;
745
746 for (index = 0; index < SCI_MAX_PHYS; index++) {
747 if ((configure_phy_mask & (1 << index)) == 0)
748 continue;
749
750 scic_sds_apc_agent_configure_ports(scic, port_agent,
751 &ihost->phys[index].sci, false);
6f231dda
DW
752 }
753}
754
755/*
756 * ******************************************************************************
757 * Public port configuration agent routines
758 * ****************************************************************************** */
759
760/**
761 *
762 *
763 * This method will construct the port configuration agent for operation. This
764 * call is universal for both manual port configuration and automatic port
765 * configuration modes.
766 */
767void scic_sds_port_configuration_agent_construct(
768 struct scic_sds_port_configuration_agent *port_agent)
769{
770 u32 index;
771
772 port_agent->phy_configured_mask = 0x00;
773 port_agent->phy_ready_mask = 0x00;
774
775 port_agent->link_up_handler = NULL;
776 port_agent->link_down_handler = NULL;
777
778 port_agent->timer_pending = false;
779 port_agent->timer = NULL;
780
781 for (index = 0; index < SCI_MAX_PORTS; index++) {
782 port_agent->phy_valid_port_range[index].min_index = 0;
783 port_agent->phy_valid_port_range[index].max_index = 0;
784 }
785}
786
6f231dda 787enum sci_status scic_sds_port_configuration_agent_initialize(
09d7da13 788 struct scic_sds_controller *scic,
6f231dda
DW
789 struct scic_sds_port_configuration_agent *port_agent)
790{
791 enum sci_status status = SCI_SUCCESS;
de728b7d 792 enum scic_port_configuration_mode mode;
cc3dbd0a 793 struct isci_host *ihost = scic_to_ihost(scic);
6f231dda 794
09d7da13 795 mode = scic->oem_parameters.sds1.controller.mode_type;
6f231dda
DW
796
797 if (mode == SCIC_PORT_MANUAL_CONFIGURATION_MODE) {
09d7da13
DJ
798 status = scic_sds_mpc_agent_validate_phy_configuration(
799 scic, port_agent);
6f231dda
DW
800
801 port_agent->link_up_handler = scic_sds_mpc_agent_link_up;
802 port_agent->link_down_handler = scic_sds_mpc_agent_link_down;
803
09d7da13
DJ
804 port_agent->timer = isci_timer_create(
805 ihost,
806 scic,
807 scic_sds_mpc_agent_timeout_handler);
6f231dda 808 } else {
09d7da13
DJ
809 status = scic_sds_apc_agent_validate_phy_configuration(
810 scic, port_agent);
6f231dda
DW
811
812 port_agent->link_up_handler = scic_sds_apc_agent_link_up;
813 port_agent->link_down_handler = scic_sds_apc_agent_link_down;
814
09d7da13
DJ
815 port_agent->timer = isci_timer_create(
816 ihost,
817 scic,
818 scic_sds_apc_agent_timeout_handler);
6f231dda
DW
819 }
820
821 /* Make sure we have actually gotten a timer */
822 if ((status == SCI_SUCCESS) && (port_agent->timer == NULL)) {
09d7da13 823 dev_err(scic_to_dev(scic),
6f231dda
DW
824 "%s: Controller 0x%p automatic port configuration "
825 "agent could not get timer.\n",
826 __func__,
09d7da13 827 scic);
6f231dda
DW
828
829 status = SCI_FAILURE;
830 }
831
832 return status;
833}
This page took 0.069125 seconds and 5 git commands to generate.