isci: remove mmio wrappers
[deliverable/linux.git] / drivers / scsi / isci / core / scic_sds_port.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#include "intel_sas.h"
57#include "sci_base_port.h"
58#include "scic_controller.h"
59#include "scic_phy.h"
60#include "scic_port.h"
61#include "scic_sds_controller.h"
62#include "scic_sds_phy.h"
6f231dda 63#include "scic_sds_port.h"
6f231dda
DW
64#include "scic_sds_remote_device.h"
65#include "scic_sds_remote_node_context.h"
66#include "scic_sds_request.h"
6f231dda 67#include "sci_environment.h"
bc99aa47 68#include "scu_registers.h"
6f231dda 69
6f231dda
DW
70#define SCIC_SDS_PORT_MIN_TIMER_COUNT (SCI_MAX_PORTS)
71#define SCIC_SDS_PORT_MAX_TIMER_COUNT (SCI_MAX_PORTS)
72
73#define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
a8d4b9fe 74#define SCU_DUMMY_INDEX (0xFFFF)
6f231dda 75
35173d57 76static void sci_base_port_construct(
6f231dda
DW
77 struct sci_base_port *base_port,
78 const struct sci_base_state *state_table)
79{
80 base_port->parent.private = NULL;
81 sci_base_state_machine_construct(
82 &base_port->state_machine,
83 &base_port->parent,
84 state_table,
85 SCI_BASE_PORT_STATE_STOPPED
86 );
87
88 sci_base_state_machine_start(
89 &base_port->state_machine
90 );
91}
92
93/**
94 *
95 * @this_port: This is the port object to which the phy is being assigned.
96 * @phy_index: This is the phy index that is being assigned to the port.
97 *
98 * This method will return a true value if the specified phy can be assigned to
99 * this port The following is a list of phys for each port that are allowed: -
100 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
101 * doesn't preclude all configurations. It merely ensures that a phy is part
102 * of the allowable set of phy identifiers for that port. For example, one
103 * could assign phy 3 to port 0 and no other phys. Please refer to
104 * scic_sds_port_is_phy_mask_valid() for information regarding whether the
105 * phy_mask for a port can be supported. bool true if this is a valid phy
106 * assignment for the port false if this is not a valid phy assignment for the
107 * port
108 */
109bool scic_sds_port_is_valid_phy_assignment(
110 struct scic_sds_port *this_port,
111 u32 phy_index)
112{
113 /* Initialize to invalid value. */
114 u32 existing_phy_index = SCI_MAX_PHYS;
115 u32 index;
116
117 if ((this_port->physical_port_index == 1) && (phy_index != 1)) {
118 return false;
119 }
120
121 if (this_port->physical_port_index == 3 && phy_index != 3) {
122 return false;
123 }
124
125 if (
126 (this_port->physical_port_index == 2)
127 && ((phy_index == 0) || (phy_index == 1))
128 ) {
129 return false;
130 }
131
132 for (index = 0; index < SCI_MAX_PHYS; index++) {
133 if ((this_port->phy_table[index] != NULL)
134 && (index != phy_index)) {
135 existing_phy_index = index;
136 }
137 }
138
139 /*
140 * Ensure that all of the phys in the port are capable of
141 * operating at the same maximum link rate. */
142 if (
143 (existing_phy_index < SCI_MAX_PHYS)
144 && (this_port->owning_controller->user_parameters.sds1.phys[
145 phy_index].max_speed_generation !=
146 this_port->owning_controller->user_parameters.sds1.phys[
147 existing_phy_index].max_speed_generation)
148 )
149 return false;
150
151 return true;
152}
153
154/**
155 * This method requests a list (mask) of the phys contained in the supplied SAS
156 * port.
157 * @this_port: a handle corresponding to the SAS port for which to return the
158 * phy mask.
159 *
160 * Return a bit mask indicating which phys are a part of this port. Each bit
161 * corresponds to a phy identifier (e.g. bit 0 = phy id 0).
162 */
35173d57 163static u32 scic_sds_port_get_phys(struct scic_sds_port *this_port)
6f231dda
DW
164{
165 u32 index;
166 u32 mask;
167
168 mask = 0;
169
170 for (index = 0; index < SCI_MAX_PHYS; index++) {
171 if (this_port->phy_table[index] != NULL) {
172 mask |= (1 << index);
173 }
174 }
175
176 return mask;
177}
178
179/**
180 *
181 * @this_port: This is the port object for which to determine if the phy mask
182 * can be supported.
183 *
184 * This method will return a true value if the port's phy mask can be supported
185 * by the SCU. The following is a list of valid PHY mask configurations for
186 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
187 * - Port 3 - [3] This method returns a boolean indication specifying if the
188 * phy mask can be supported. true if this is a valid phy assignment for the
189 * port false if this is not a valid phy assignment for the port
190 */
35173d57 191static bool scic_sds_port_is_phy_mask_valid(
6f231dda
DW
192 struct scic_sds_port *this_port,
193 u32 phy_mask)
194{
195 if (this_port->physical_port_index == 0) {
196 if (((phy_mask & 0x0F) == 0x0F)
197 || ((phy_mask & 0x03) == 0x03)
198 || ((phy_mask & 0x01) == 0x01)
199 || (phy_mask == 0))
200 return true;
201 } else if (this_port->physical_port_index == 1) {
202 if (((phy_mask & 0x02) == 0x02)
203 || (phy_mask == 0))
204 return true;
205 } else if (this_port->physical_port_index == 2) {
206 if (((phy_mask & 0x0C) == 0x0C)
207 || ((phy_mask & 0x04) == 0x04)
208 || (phy_mask == 0))
209 return true;
210 } else if (this_port->physical_port_index == 3) {
211 if (((phy_mask & 0x08) == 0x08)
212 || (phy_mask == 0))
213 return true;
214 }
215
216 return false;
217}
218
219/**
220 *
221 * @this_port: This parameter specifies the port from which to return a
222 * connected phy.
223 *
224 * This method retrieves a currently active (i.e. connected) phy contained in
225 * the port. Currently, the lowest order phy that is connected is returned.
226 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
227 * returned if there are no currently active (i.e. connected to a remote end
228 * point) phys contained in the port. All other values specify a struct scic_sds_phy
229 * object that is active in the port.
230 */
231static struct scic_sds_phy *scic_sds_port_get_a_connected_phy(
232 struct scic_sds_port *this_port
233 ) {
234 u32 index;
235 struct scic_sds_phy *phy;
236
237 for (index = 0; index < SCI_MAX_PHYS; index++) {
238 /*
239 * Ensure that the phy is both part of the port and currently
240 * connected to the remote end-point. */
241 phy = this_port->phy_table[index];
242 if (
243 (phy != NULL)
244 && scic_sds_port_active_phy(this_port, phy)
245 ) {
246 return phy;
247 }
248 }
249
250 return NULL;
251}
252
253/**
254 * scic_sds_port_set_phy() -
255 * @out]: port The port object to which the phy assignement is being made.
256 * @out]: phy The phy which is being assigned to the port.
257 *
258 * This method attempts to make the assignment of the phy to the port. If
259 * successful the phy is assigned to the ports phy table. bool true if the phy
260 * assignment can be made. false if the phy assignement can not be made. This
261 * is a functional test that only fails if the phy is currently assigned to a
262 * different port.
263 */
35173d57 264static enum sci_status scic_sds_port_set_phy(
6f231dda
DW
265 struct scic_sds_port *port,
266 struct scic_sds_phy *phy)
267{
268 /*
269 * Check to see if we can add this phy to a port
270 * that means that the phy is not part of a port and that the port does
271 * not already have a phy assinged to the phy index. */
272 if (
a7e536c7
EN
273 (port->phy_table[phy->phy_index] == NULL)
274 && (scic_sds_phy_get_port(phy) == NULL)
6f231dda
DW
275 && scic_sds_port_is_valid_phy_assignment(port, phy->phy_index)
276 ) {
277 /*
278 * Phy is being added in the stopped state so we are in MPC mode
279 * make logical port index = physical port index */
280 port->logical_port_index = port->physical_port_index;
281 port->phy_table[phy->phy_index] = phy;
282 scic_sds_phy_set_port(phy, port);
283
284 return SCI_SUCCESS;
285 }
286
287 return SCI_FAILURE;
288}
289
290/**
291 * scic_sds_port_clear_phy() -
292 * @out]: port The port from which the phy is being cleared.
293 * @out]: phy The phy being cleared from the port.
294 *
295 * This method will clear the phy assigned to this port. This method fails if
296 * this phy is not currently assinged to this port. bool true if the phy is
297 * removed from the port. false if this phy is not assined to this port.
298 */
35173d57 299static enum sci_status scic_sds_port_clear_phy(
6f231dda
DW
300 struct scic_sds_port *port,
301 struct scic_sds_phy *phy)
302{
303 /* Make sure that this phy is part of this port */
304 if (
305 (port->phy_table[phy->phy_index] == phy)
306 && (scic_sds_phy_get_port(phy) == port)
307 ) {
308 /* Yep it is assigned to this port so remove it */
309 scic_sds_phy_set_port(
310 phy,
311 &scic_sds_port_get_controller(port)->port_table[SCI_MAX_PORTS]
312 );
313
a7e536c7 314 port->phy_table[phy->phy_index] = NULL;
6f231dda
DW
315
316 return SCI_SUCCESS;
317 }
318
319 return SCI_FAILURE;
320}
321
322/**
323 * scic_sds_port_add_phy() -
324 * @this_port: This parameter specifies the port in which the phy will be added.
325 * @the_phy: This parameter is the phy which is to be added to the port.
326 *
327 * This method will add a PHY to the selected port. This method returns an
328 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other status
329 * is failre to add the phy to the port.
330 */
331enum sci_status scic_sds_port_add_phy(
332 struct scic_sds_port *this_port,
333 struct scic_sds_phy *the_phy)
334{
335 return this_port->state_handlers->parent.add_phy_handler(
336 &this_port->parent, &the_phy->parent);
337}
338
339
340/**
341 * scic_sds_port_remove_phy() -
342 * @this_port: This parameter specifies the port in which the phy will be added.
343 * @the_phy: This parameter is the phy which is to be added to the port.
344 *
345 * This method will remove the PHY from the selected PORT. This method returns
346 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any other
347 * status is failre to add the phy to the port.
348 */
349enum sci_status scic_sds_port_remove_phy(
350 struct scic_sds_port *this_port,
351 struct scic_sds_phy *the_phy)
352{
353 return this_port->state_handlers->parent.remove_phy_handler(
354 &this_port->parent, &the_phy->parent);
355}
356
357/**
358 * This method requests the SAS address for the supplied SAS port from the SCI
359 * implementation.
360 * @this_port: a handle corresponding to the SAS port for which to return the
361 * SAS address.
362 * @sas_address: This parameter specifies a pointer to a SAS address structure
363 * into which the core will copy the SAS address for the port.
364 *
365 */
366void scic_sds_port_get_sas_address(
367 struct scic_sds_port *this_port,
368 struct sci_sas_address *sas_address)
369{
370 u32 index;
371
372 sas_address->high = 0;
373 sas_address->low = 0;
374
375 for (index = 0; index < SCI_MAX_PHYS; index++) {
376 if (this_port->phy_table[index] != NULL) {
377 scic_sds_phy_get_sas_address(this_port->phy_table[index], sas_address);
378 }
379 }
380}
381
382/**
383 * This method will indicate which protocols are supported by this port.
384 * @this_port: a handle corresponding to the SAS port for which to return the
385 * supported protocols.
386 * @protocols: This parameter specifies a pointer to an IAF protocol field
387 * structure into which the core will copy the protocol values for the port.
388 * The values are returned as part of a bit mask in order to allow for
389 * multi-protocol support.
390 *
391 */
392static void scic_sds_port_get_protocols(
393 struct scic_sds_port *this_port,
394 struct sci_sas_identify_address_frame_protocols *protocols)
395{
396 u8 index;
397
398 protocols->u.all = 0;
399
400 for (index = 0; index < SCI_MAX_PHYS; index++) {
401 if (this_port->phy_table[index] != NULL) {
402 scic_sds_phy_get_protocols(this_port->phy_table[index], protocols);
403 }
404 }
405}
406
407/**
408 * This method requests the SAS address for the device directly attached to
409 * this SAS port.
410 * @this_port: a handle corresponding to the SAS port for which to return the
411 * SAS address.
412 * @sas_address: This parameter specifies a pointer to a SAS address structure
413 * into which the core will copy the SAS address for the device directly
414 * attached to the port.
415 *
416 */
417void scic_sds_port_get_attached_sas_address(
418 struct scic_sds_port *this_port,
419 struct sci_sas_address *sas_address)
420{
421 struct sci_sas_identify_address_frame_protocols protocols;
422 struct scic_sds_phy *phy;
423
424 /*
425 * Ensure that the phy is both part of the port and currently
426 * connected to the remote end-point. */
427 phy = scic_sds_port_get_a_connected_phy(this_port);
428 if (phy != NULL) {
429 scic_sds_phy_get_attached_phy_protocols(phy, &protocols);
430
431 if (!protocols.u.bits.stp_target) {
432 scic_sds_phy_get_attached_sas_address(phy, sas_address);
433 } else {
434 scic_sds_phy_get_sas_address(phy, sas_address);
435 sas_address->low += phy->phy_index;
436 }
437 } else {
438 sas_address->high = 0;
439 sas_address->low = 0;
440 }
441}
442
443/**
444 * This method will indicate which protocols are supported by this remote
445 * device.
446 * @this_port: a handle corresponding to the SAS port for which to return the
447 * supported protocols.
448 * @protocols: This parameter specifies a pointer to an IAF protocol field
449 * structure into which the core will copy the protocol values for the port.
450 * The values are returned as part of a bit mask in order to allow for
451 * multi-protocol support.
452 *
453 */
454void scic_sds_port_get_attached_protocols(
455 struct scic_sds_port *this_port,
456 struct sci_sas_identify_address_frame_protocols *protocols)
457{
458 struct scic_sds_phy *phy;
459
460 /*
461 * Ensure that the phy is both part of the port and currently
462 * connected to the remote end-point. */
463 phy = scic_sds_port_get_a_connected_phy(this_port);
464 if (phy != NULL)
465 scic_sds_phy_get_attached_phy_protocols(phy, protocols);
466 else
467 protocols->u.all = 0;
468}
469
470/**
a8d4b9fe 471 * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
6f231dda 472 *
a8d4b9fe
TC
473 * @sci_port: logical port on which we need to create the remote node context
474 * @rni: remote node index for this remote node context.
6f231dda 475 *
a8d4b9fe
TC
476 * This routine will construct a dummy remote node context data structure
477 * This structure will be posted to the hardware to work around a scheduler
478 * error in the hardware.
6f231dda 479 */
35173d57 480static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port *sci_port, u16 rni)
a8d4b9fe
TC
481{
482 union scu_remote_node_context *rnc;
6f231dda 483
a8d4b9fe
TC
484 rnc = &sci_port->owning_controller->remote_node_context_table[rni];
485
486 memset(rnc, 0, sizeof(union scu_remote_node_context));
487
488 rnc->ssp.remote_sas_address_hi = 0;
489 rnc->ssp.remote_sas_address_lo = 0;
490
491 rnc->ssp.remote_node_index = rni;
492 rnc->ssp.remote_node_port_width = 1;
493 rnc->ssp.logical_port_index = sci_port->physical_port_index;
494
495 rnc->ssp.nexus_loss_timer_enable = false;
496 rnc->ssp.check_bit = false;
497 rnc->ssp.is_valid = true;
498 rnc->ssp.is_remote_node_context = true;
499 rnc->ssp.function_number = 0;
500 rnc->ssp.arbitration_wait_time = 0;
501}
6f231dda
DW
502
503/**
a8d4b9fe
TC
504 * scic_sds_port_construct_dummy_task() - create dummy task for si workaround
505 * @sci_port The logical port on which we need to create the
506 * remote node context.
507 * context.
508 * @tci The remote node index for this remote node context.
6f231dda 509 *
a8d4b9fe
TC
510 * This routine will construct a dummy task context data structure. This
511 * structure will be posted to the hardwre to work around a scheduler error
512 * in the hardware.
6f231dda
DW
513 *
514 */
35173d57 515static void scic_sds_port_construct_dummy_task(struct scic_sds_port *sci_port, u16 tci)
a8d4b9fe
TC
516{
517 struct scu_task_context *task_context;
518
519 task_context = scic_sds_controller_get_task_context_buffer(sci_port->owning_controller, tci);
520
521 memset(task_context, 0, sizeof(struct scu_task_context));
522
523 task_context->abort = 0;
524 task_context->priority = 0;
525 task_context->initiator_request = 1;
526 task_context->connection_rate = 1;
527 task_context->protocol_engine_index = 0;
528 task_context->logical_port_index = sci_port->physical_port_index;
529 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
530 task_context->task_index = scic_sds_io_tag_get_index(tci);
531 task_context->valid = SCU_TASK_CONTEXT_VALID;
532 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
533
534 task_context->remote_node_index = sci_port->reserved_rni;
535 task_context->command_code = 0;
536
537 task_context->link_layer_control = 0;
538 task_context->do_not_dma_ssp_good_response = 1;
539 task_context->strict_ordering = 0;
540 task_context->control_frame = 0;
541 task_context->timeout_enable = 0;
542 task_context->block_guard_enable = 0;
543
544 task_context->address_modifier = 0;
545
546 task_context->task_phase = 0x01;
547}
548
35173d57 549static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port *sci_port)
a8d4b9fe
TC
550{
551 struct scic_sds_controller *scic = sci_port->owning_controller;
552
553 if (sci_port->reserved_tci != SCU_DUMMY_INDEX)
554 scic_controller_free_io_tag(scic, sci_port->reserved_tci);
555
556 if (sci_port->reserved_rni != SCU_DUMMY_INDEX)
557 scic_sds_remote_node_table_release_remote_node_index(&scic->available_remote_nodes,
558 1, sci_port->reserved_rni);
559
560 sci_port->reserved_rni = SCU_DUMMY_INDEX;
561 sci_port->reserved_tci = SCU_DUMMY_INDEX;
562}
563
6f231dda
DW
564/**
565 * This method performs initialization of the supplied port. Initialization
566 * includes: - state machine initialization - member variable initialization
567 * - configuring the phy_mask
568 * @this_port:
569 * @transport_layer_registers:
570 * @port_task_scheduler_registers:
571 * @port_configuration_regsiter:
572 *
573 * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
574 * if the phy being added to the port
575 */
576enum sci_status scic_sds_port_initialize(
577 struct scic_sds_port *this_port,
24621466
HD
578 void __iomem *port_task_scheduler_registers,
579 void __iomem *port_configuration_regsiter,
580 void __iomem *viit_registers)
6f231dda 581{
6f231dda
DW
582 this_port->port_task_scheduler_registers = port_task_scheduler_registers;
583 this_port->port_pe_configuration_register = port_configuration_regsiter;
584 this_port->viit_registers = viit_registers;
585
6f231dda
DW
586 return SCI_SUCCESS;
587}
588
589/**
35173d57
DW
590 * scic_port_get_properties() - This method simply returns the properties
591 * regarding the port, such as: physical index, protocols, sas address, etc.
592 * @port: this parameter specifies the port for which to retrieve the physical
593 * index.
594 * @properties: This parameter specifies the properties structure into which to
595 * copy the requested information.
6f231dda 596 *
35173d57
DW
597 * Indicate if the user specified a valid port. SCI_SUCCESS This value is
598 * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
599 * value is returned if the specified port is not valid. When this value is
600 * returned, no data is copied to the properties output parameter.
6f231dda 601 */
6f231dda
DW
602enum sci_status scic_port_get_properties(
603 struct scic_sds_port *port,
604 struct scic_port_properties *prop)
605{
a7e536c7 606 if ((port == NULL) ||
6f231dda
DW
607 (port->logical_port_index == SCIC_SDS_DUMMY_PORT))
608 return SCI_FAILURE_INVALID_PORT;
609
610 prop->index = port->logical_port_index;
611 prop->phy_mask = scic_sds_port_get_phys(port);
612 scic_sds_port_get_sas_address(port, &prop->local.sas_address);
613 scic_sds_port_get_protocols(port, &prop->local.protocols);
614 scic_sds_port_get_attached_sas_address(port, &prop->remote.sas_address);
615 scic_sds_port_get_attached_protocols(port, &prop->remote.protocols);
616
617 return SCI_SUCCESS;
618}
619
35173d57 620/**
de728b7d 621 * scic_port_hard_reset() - perform port hard reset
35173d57
DW
622 * @port: a handle corresponding to the SAS port to be hard reset.
623 * @reset_timeout: This parameter specifies the number of milliseconds in which
624 * the port reset operation should complete.
625 *
de728b7d 626 * The SCI User callback in scic_user_callbacks_t will only be called once for
35173d57
DW
627 * each phy in the SAS Port at completion of the hard reset sequence. Return a
628 * status indicating whether the hard reset started successfully. SCI_SUCCESS
629 * This value is returned if the hard reset operation started successfully.
630 */
6f231dda
DW
631enum sci_status scic_port_hard_reset(
632 struct scic_sds_port *port,
633 u32 reset_timeout)
634{
635 return port->state_handlers->parent.reset_handler(
636 &port->parent, reset_timeout);
637}
638
639/**
6f231dda 640 * This method assigns the direct attached device ID for this port.
24621466
HD
641 *
642 * @param[in] this_port The port for which the direct attached device id is to
643 * be assigned.
644 * @param[in] device_id The direct attached device ID to assign to the port.
645 * This will be the RNi for the device
6f231dda 646 */
24621466 647void scic_sds_port_setup_transports(
6f231dda
DW
648 struct scic_sds_port *this_port,
649 u32 device_id)
650{
24621466 651 u8 index;
6f231dda 652
24621466
HD
653 for (index = 0; index < SCI_MAX_PHYS; index++) {
654 if (this_port->active_phy_mask & (1 << index))
655 scic_sds_phy_setup_transport(this_port->phy_table[index], device_id);
656 }
6f231dda
DW
657}
658
6f231dda
DW
659/**
660 *
661 * @this_port: This is the port on which the phy should be enabled.
662 * @the_phy: This is the specific phy which to enable.
663 * @do_notify_user: This parameter specifies whether to inform the user (via
664 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
665 *
09d7da13
DJ
666 * This function will activate the phy in the port.
667 * Activation includes: - adding
6f231dda
DW
668 * the phy to the port - enabling the Protocol Engine in the silicon. -
669 * notifying the user that the link is up. none
670 */
35173d57
DW
671static void scic_sds_port_activate_phy(struct scic_sds_port *sci_port,
672 struct scic_sds_phy *sci_phy,
673 bool do_notify_user)
6f231dda 674{
35173d57 675 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
6f231dda 676 struct sci_sas_identify_address_frame_protocols protocols;
09d7da13 677 struct isci_host *ihost = sci_object_get_association(scic);
6f231dda 678
09d7da13 679 scic_sds_phy_get_attached_phy_protocols(sci_phy, &protocols);
6f231dda
DW
680
681 /* If this is sata port then the phy has already been resumed */
09d7da13
DJ
682 if (!protocols.u.bits.stp_target)
683 scic_sds_phy_resume(sci_phy);
6f231dda 684
09d7da13 685 sci_port->active_phy_mask |= 1 << sci_phy->phy_index;
6f231dda 686
09d7da13 687 scic_sds_controller_clear_invalid_phy(scic, sci_phy);
6f231dda
DW
688
689 if (do_notify_user == true)
09d7da13 690 isci_port_link_up(ihost, sci_port, sci_phy);
6f231dda
DW
691}
692
09d7da13
DJ
693void scic_sds_port_deactivate_phy(struct scic_sds_port *sci_port,
694 struct scic_sds_phy *sci_phy,
695 bool do_notify_user)
6f231dda 696{
35173d57 697 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
09d7da13
DJ
698 struct isci_port *iport = sci_object_get_association(sci_port);
699 struct isci_host *ihost = sci_object_get_association(scic);
700 struct isci_phy *iphy = sci_object_get_association(sci_phy);
701
702 sci_port->active_phy_mask &= ~(1 << sci_phy->phy_index);
6f231dda 703
09d7da13 704 sci_phy->max_negotiated_speed = SCI_SAS_NO_LINK_RATE;
6f231dda
DW
705
706 /* Re-assign the phy back to the LP as if it were a narrow port */
bc99aa47
CH
707 writel(sci_phy->phy_index,
708 &sci_port->port_pe_configuration_register[sci_phy->phy_index]);
6f231dda
DW
709
710 if (do_notify_user == true)
09d7da13 711 isci_port_link_down(ihost, iphy, iport);
6f231dda
DW
712}
713
714/**
715 *
716 * @this_port: This is the port on which the phy should be disabled.
717 * @the_phy: This is the specific phy which to disabled.
718 *
09d7da13 719 * This function will disable the phy and report that the phy is not valid for
6f231dda
DW
720 * this port object. None
721 */
722static void scic_sds_port_invalid_link_up(
09d7da13
DJ
723 struct scic_sds_port *sci_port,
724 struct scic_sds_phy *sci_phy)
6f231dda 725{
09d7da13
DJ
726 struct scic_sds_controller *scic =
727 scic_sds_port_get_controller(sci_port);
6f231dda
DW
728
729 /*
09d7da13
DJ
730 * Check to see if we have alreay reported this link as bad and if
731 * not go ahead and tell the SCI_USER that we have discovered an
732 * invalid link.
733 */
734 if ((scic->invalid_phy_mask & (1 << sci_phy->phy_index)) == 0) {
735 scic_sds_controller_set_invalid_phy(scic, sci_phy);
736 isci_port_invalid_link_up(scic, sci_port, sci_phy);
6f231dda
DW
737 }
738}
739
35173d57
DW
740/**
741 * scic_sds_port_general_link_up_handler - phy can be assigned to port?
742 * @sci_port: scic_sds_port object for which has a phy that has gone link up.
743 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
744 * @do_notify_user: This parameter specifies whether to inform the user (via
745 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
746 *
747 * Determine if this phy can be assigned to this
748 * port . If the phy is not a valid PHY for
749 * this port then the function will notify the user. A PHY can only be
750 * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
751 * the same port. none
752 */
753static void scic_sds_port_general_link_up_handler(struct scic_sds_port *sci_port,
754 struct scic_sds_phy *sci_phy,
755 bool do_notify_user)
756{
757 struct sci_sas_address port_sas_address;
758 struct sci_sas_address phy_sas_address;
759
760 scic_sds_port_get_attached_sas_address(sci_port, &port_sas_address);
761 scic_sds_phy_get_attached_sas_address(sci_phy, &phy_sas_address);
762
763 /* If the SAS address of the new phy matches the SAS address of
764 * other phys in the port OR this is the first phy in the port,
765 * then activate the phy and allow it to be used for operations
766 * in this port.
767 */
768 if ((phy_sas_address.high == port_sas_address.high &&
769 phy_sas_address.low == port_sas_address.low) ||
770 sci_port->active_phy_mask == 0) {
771 struct sci_base_state_machine *sm = &sci_port->parent.state_machine;
772
773 scic_sds_port_activate_phy(sci_port, sci_phy, do_notify_user);
774 if (sm->current_state_id == SCI_BASE_PORT_STATE_RESETTING)
775 sci_base_state_machine_change_state(sm, SCI_BASE_PORT_STATE_READY);
776 } else
777 scic_sds_port_invalid_link_up(sci_port, sci_phy);
778}
779
780
781
6f231dda
DW
782/**
783 * This method returns false if the port only has a single phy object assigned.
784 * If there are no phys or more than one phy then the method will return
785 * true.
786 * @this_port: The port for which the wide port condition is to be checked.
787 *
788 * bool true Is returned if this is a wide ported port. false Is returned if
789 * this is a narrow port.
790 */
791static bool scic_sds_port_is_wide(struct scic_sds_port *this_port)
792{
793 u32 index;
794 u32 phy_count = 0;
795
796 for (index = 0; index < SCI_MAX_PHYS; index++) {
797 if (this_port->phy_table[index] != NULL) {
798 phy_count++;
799 }
800 }
801
802 return phy_count != 1;
803}
804
805/**
806 * This method is called by the PHY object when the link is detected. if the
807 * port wants the PHY to continue on to the link up state then the port
808 * layer must return true. If the port object returns false the phy object
809 * must halt its attempt to go link up.
810 * @this_port: The port associated with the phy object.
811 * @the_phy: The phy object that is trying to go link up.
812 *
813 * true if the phy object can continue to the link up condition. true Is
814 * returned if this phy can continue to the ready state. false Is returned if
815 * can not continue on to the ready state. This notification is in place for
816 * wide ports and direct attached phys. Since there are no wide ported SATA
817 * devices this could become an invalid port configuration.
818 */
819bool scic_sds_port_link_detected(
820 struct scic_sds_port *this_port,
821 struct scic_sds_phy *the_phy)
822{
823 struct sci_sas_identify_address_frame_protocols protocols;
824
825 scic_sds_phy_get_attached_phy_protocols(the_phy, &protocols);
826
827 if (
828 (this_port->logical_port_index != SCIC_SDS_DUMMY_PORT)
829 && (protocols.u.bits.stp_target)
830 && scic_sds_port_is_wide(this_port)
831 ) {
832 scic_sds_port_invalid_link_up(this_port, the_phy);
833
834 return false;
835 }
836
837 return true;
838}
839
840/**
841 * This method is the entry point for the phy to inform the port that it is now
842 * in a ready state
843 * @this_port:
844 *
845 *
846 */
847void scic_sds_port_link_up(
848 struct scic_sds_port *this_port,
849 struct scic_sds_phy *the_phy)
850{
851 the_phy->is_in_link_training = false;
852
853 this_port->state_handlers->link_up_handler(this_port, the_phy);
854}
855
856/**
857 * This method is the entry point for the phy to inform the port that it is no
858 * longer in a ready state
859 * @this_port:
860 *
861 *
862 */
863void scic_sds_port_link_down(
864 struct scic_sds_port *this_port,
865 struct scic_sds_phy *the_phy)
866{
867 this_port->state_handlers->link_down_handler(this_port, the_phy);
868}
869
870/**
871 * This method is called to start an IO request on this port.
872 * @this_port:
873 * @the_device:
874 * @the_io_request:
875 *
876 * enum sci_status
877 */
878enum sci_status scic_sds_port_start_io(
879 struct scic_sds_port *this_port,
880 struct scic_sds_remote_device *the_device,
881 struct scic_sds_request *the_io_request)
882{
883 return this_port->state_handlers->start_io_handler(
884 this_port, the_device, the_io_request);
885}
886
887/**
888 * This method is called to complete an IO request to the port.
889 * @this_port:
890 * @the_device:
891 * @the_io_request:
892 *
893 * enum sci_status
894 */
895enum sci_status scic_sds_port_complete_io(
896 struct scic_sds_port *this_port,
897 struct scic_sds_remote_device *the_device,
898 struct scic_sds_request *the_io_request)
899{
900 return this_port->state_handlers->complete_io_handler(
901 this_port, the_device, the_io_request);
902}
903
904/**
905 * This method is provided to timeout requests for port operations. Mostly its
906 * for the port reset operation.
907 *
908 *
909 */
910static void scic_sds_port_timeout_handler(void *port)
911{
09d7da13 912 struct scic_sds_port *sci_port = port;
6f231dda
DW
913 u32 current_state;
914
915 current_state = sci_base_state_machine_get_state(
09d7da13 916 &sci_port->parent.state_machine);
6f231dda
DW
917
918 if (current_state == SCI_BASE_PORT_STATE_RESETTING) {
919 /*
09d7da13
DJ
920 * if the port is still in the resetting state then the
921 * timeout fired before the reset completed.
922 */
6f231dda 923 sci_base_state_machine_change_state(
09d7da13
DJ
924 &sci_port->parent.state_machine,
925 SCI_BASE_PORT_STATE_FAILED);
6f231dda
DW
926 } else if (current_state == SCI_BASE_PORT_STATE_STOPPED) {
927 /*
928 * if the port is stopped then the start request failed
09d7da13
DJ
929 * In this case stay in the stopped state.
930 */
931 dev_err(sciport_to_dev(sci_port),
6f231dda
DW
932 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
933 __func__,
09d7da13 934 sci_port);
6f231dda 935 } else if (current_state == SCI_BASE_PORT_STATE_STOPPING) {
09d7da13
DJ
936 /*
937 * if the port is still stopping then the stop has not
938 * completed
939 */
940 isci_port_stop_complete(
941 scic_sds_port_get_controller(sci_port),
942 sci_port,
943 SCI_FAILURE_TIMEOUT);
6f231dda
DW
944 } else {
945 /*
09d7da13
DJ
946 * The port is in the ready state and we have a timer
947 * reporting a timeout this should not happen.
948 */
949 dev_err(sciport_to_dev(sci_port),
6f231dda
DW
950 "%s: SCIC Port 0x%p is processing a timeout operation "
951 "in state %d.\n",
952 __func__,
09d7da13 953 sci_port,
6f231dda
DW
954 current_state);
955 }
956}
957
958/* --------------------------------------------------------------------------- */
959
6f231dda
DW
960/**
961 * This function updates the hardwares VIIT entry for this port.
962 *
963 *
964 */
35173d57 965static void scic_sds_port_update_viit_entry(struct scic_sds_port *this_port)
6f231dda
DW
966{
967 struct sci_sas_address sas_address;
968
969 scic_sds_port_get_sas_address(this_port, &sas_address);
970
bc99aa47
CH
971 writel(sas_address.high,
972 &this_port->viit_registers->initiator_sas_address_hi);
973 writel(sas_address.low,
974 &this_port->viit_registers->initiator_sas_address_lo);
6f231dda
DW
975
976 /* This value get cleared just in case its not already cleared */
bc99aa47 977 writel(0, &this_port->viit_registers->reserved);
6f231dda
DW
978
979 /* We are required to update the status register last */
bc99aa47
CH
980 writel(SCU_VIIT_ENTRY_ID_VIIT |
981 SCU_VIIT_IPPT_INITIATOR |
982 ((1 << this_port->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) |
983 SCU_VIIT_STATUS_ALL_VALID,
984 &this_port->viit_registers->status);
6f231dda
DW
985}
986
987/**
988 * This method returns the maximum allowed speed for data transfers on this
989 * port. This maximum allowed speed evaluates to the maximum speed of the
990 * slowest phy in the port.
991 * @this_port: This parameter specifies the port for which to retrieve the
992 * maximum allowed speed.
993 *
994 * This method returns the maximum negotiated speed of the slowest phy in the
995 * port.
996 */
997enum sci_sas_link_rate scic_sds_port_get_max_allowed_speed(
998 struct scic_sds_port *this_port)
999{
1000 u16 index = 0;
1001 enum sci_sas_link_rate max_allowed_speed = SCI_SAS_600_GB;
1002 struct scic_sds_phy *phy = NULL;
1003
1004 /*
1005 * Loop through all of the phys in this port and find the phy with the
1006 * lowest maximum link rate. */
1007 for (index = 0; index < SCI_MAX_PHYS; index++) {
1008 phy = this_port->phy_table[index];
1009 if (
1010 (phy != NULL)
1011 && (scic_sds_port_active_phy(this_port, phy) == true)
1012 && (phy->max_negotiated_speed < max_allowed_speed)
1013 )
1014 max_allowed_speed = phy->max_negotiated_speed;
1015 }
1016
1017 return max_allowed_speed;
1018}
1019
1020
1021/**
1022 * This method passes the event to core user.
1023 * @this_port: The port that a BCN happens.
1024 * @this_phy: The phy that receives BCN.
1025 *
1026 */
1027void scic_sds_port_broadcast_change_received(
09d7da13
DJ
1028 struct scic_sds_port *sci_port,
1029 struct scic_sds_phy *sci_phy)
6f231dda 1030{
09d7da13
DJ
1031 struct scic_sds_controller *scic = sci_port->owning_controller;
1032 struct isci_host *ihost = sci_object_get_association(scic);
1033
6f231dda 1034 /* notify the user. */
09d7da13 1035 isci_port_bc_change_received(ihost, sci_port, sci_phy);
6f231dda
DW
1036}
1037
1038
1039/**
1040 * This API methhod enables the broadcast change notification from underneath
1041 * hardware.
1042 * @this_port: The port that a BCN had been disabled from.
1043 *
1044 */
1045void scic_port_enable_broadcast_change_notification(
1046 struct scic_sds_port *port)
1047{
1048 struct scic_sds_phy *phy;
1049 u32 register_value;
1050 u8 index;
1051
1052 /* Loop through all of the phys to enable BCN. */
1053 for (index = 0; index < SCI_MAX_PHYS; index++) {
1054 phy = port->phy_table[index];
1055 if (phy != NULL) {
bc99aa47
CH
1056 register_value =
1057 readl(&phy->link_layer_registers->link_layer_control);
6f231dda
DW
1058
1059 /* clear the bit by writing 1. */
bc99aa47
CH
1060 writel(register_value,
1061 &phy->link_layer_registers->link_layer_control);
6f231dda
DW
1062 }
1063 }
1064}
1065
1066/*
1067 * ****************************************************************************
1068 * * READY SUBSTATE HANDLERS
1069 * **************************************************************************** */
1070
1071/**
1072 *
1073 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1074 * object.
1075 *
1076 * This method is the general ready state stop handler for the struct scic_sds_port
1077 * object. This function will transition the ready substate machine to its
1078 * final state. enum sci_status SCI_SUCCESS
1079 */
1080static enum sci_status scic_sds_port_ready_substate_stop_handler(
1081 struct sci_base_port *port)
1082{
1083 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1084
1085 sci_base_state_machine_change_state(
1086 &this_port->parent.state_machine,
1087 SCI_BASE_PORT_STATE_STOPPING
1088 );
1089
1090 return SCI_SUCCESS;
1091}
1092
1093/**
1094 *
1095 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1096 * object.
1097 * @device: This is the struct sci_base_remote_device object which is not used in this
1098 * function.
1099 * @io_request: This is the struct sci_base_request object which is not used in this
1100 * function.
1101 *
1102 * This method is the general ready substate complete io handler for the
1103 * struct scic_sds_port object. This function decrments the outstanding request count
1104 * for this port object. enum sci_status SCI_SUCCESS
1105 */
1106static enum sci_status scic_sds_port_ready_substate_complete_io_handler(
1107 struct scic_sds_port *port,
1108 struct scic_sds_remote_device *device,
1109 struct scic_sds_request *io_request)
1110{
1111 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1112
1113 scic_sds_port_decrement_request_count(this_port);
1114
1115 return SCI_SUCCESS;
1116}
1117
1118static enum sci_status scic_sds_port_ready_substate_add_phy_handler(
1119 struct sci_base_port *port,
1120 struct sci_base_phy *phy)
1121{
1122 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1123 struct scic_sds_phy *this_phy = (struct scic_sds_phy *)phy;
1124 enum sci_status status;
1125
1126 status = scic_sds_port_set_phy(this_port, this_phy);
1127
1128 if (status == SCI_SUCCESS) {
1129 scic_sds_port_general_link_up_handler(this_port, this_phy, true);
1130
1131 this_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1132
1133 sci_base_state_machine_change_state(
1134 &this_port->ready_substate_machine,
1135 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1136 );
1137 }
1138
1139 return status;
1140}
1141
1142
1143static enum sci_status scic_sds_port_ready_substate_remove_phy_handler(
1144 struct sci_base_port *port,
1145 struct sci_base_phy *phy)
1146{
1147 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1148 struct scic_sds_phy *this_phy = (struct scic_sds_phy *)phy;
1149 enum sci_status status;
1150
1151 status = scic_sds_port_clear_phy(this_port, this_phy);
1152
1153 if (status == SCI_SUCCESS) {
1154 scic_sds_port_deactivate_phy(this_port, this_phy, true);
1155
1156 this_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1157
1158 sci_base_state_machine_change_state(
1159 &this_port->ready_substate_machine,
1160 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1161 );
1162 }
1163
1164 return status;
1165}
1166
1167/*
1168 * ****************************************************************************
1169 * * READY SUBSTATE WAITING HANDLERS
1170 * **************************************************************************** */
1171
1172/**
1173 *
1174 * @this_port: This is the struct scic_sds_port object that which has a phy that has
1175 * gone link up.
1176 * @the_phy: This is the struct scic_sds_phy object that has gone link up.
1177 *
1178 * This method is the ready waiting substate link up handler for the
1179 * struct scic_sds_port object. This methos will report the link up condition for
1180 * this port and will transition to the ready operational substate. none
1181 */
1182static void scic_sds_port_ready_waiting_substate_link_up_handler(
1183 struct scic_sds_port *this_port,
1184 struct scic_sds_phy *the_phy)
1185{
1186 /*
1187 * Since this is the first phy going link up for the port we can just enable
1188 * it and continue. */
1189 scic_sds_port_activate_phy(this_port, the_phy, true);
1190
1191 sci_base_state_machine_change_state(
1192 &this_port->ready_substate_machine,
1193 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1194 );
1195}
1196
1197/**
1198 *
1199 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1200 * object.
1201 * @device: This is the struct sci_base_remote_device object which is not used in this
1202 * request.
1203 * @io_request: This is the struct sci_base_request object which is not used in this
1204 * function.
1205 *
1206 * This method is the ready waiting substate start io handler for the
1207 * struct scic_sds_port object. The port object can not accept new requests so the
1208 * request is failed. enum sci_status SCI_FAILURE_INVALID_STATE
1209 */
1210static enum sci_status scic_sds_port_ready_waiting_substate_start_io_handler(
1211 struct scic_sds_port *port,
1212 struct scic_sds_remote_device *device,
1213 struct scic_sds_request *io_request)
1214{
1215 return SCI_FAILURE_INVALID_STATE;
1216}
1217
1218/*
1219 * ****************************************************************************
1220 * * READY SUBSTATE OPERATIONAL HANDLERS
1221 * **************************************************************************** */
1222
1223/**
1224 *
1225 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1226 * object.
1227 * @timeout: This is the timeout for the reset request to complete.
1228 *
1229 * This method will casue the port to reset. enum sci_status SCI_SUCCESS
1230 */
09d7da13
DJ
1231static enum
1232sci_status scic_sds_port_ready_operational_substate_reset_handler(
1233 struct sci_base_port *port,
1234 u32 timeout)
6f231dda
DW
1235{
1236 enum sci_status status = SCI_FAILURE_INVALID_PHY;
1237 u32 phy_index;
09d7da13 1238 struct scic_sds_port *sci_port = (struct scic_sds_port *)port;
a7e536c7 1239 struct scic_sds_phy *selected_phy = NULL;
6f231dda
DW
1240
1241
1242 /* Select a phy on which we can send the hard reset request. */
09d7da13
DJ
1243 for (phy_index = 0;
1244 (phy_index < SCI_MAX_PHYS) && (selected_phy == NULL);
1245 phy_index++) {
1246 selected_phy = sci_port->phy_table[phy_index];
1247
1248 if ((selected_phy != NULL) &&
1249 !scic_sds_port_active_phy(sci_port, selected_phy)) {
1250 /*
1251 * We found a phy but it is not ready select
1252 * different phy
1253 */
a7e536c7 1254 selected_phy = NULL;
6f231dda
DW
1255 }
1256 }
1257
1258 /* If we have a phy then go ahead and start the reset procedure */
a7e536c7 1259 if (selected_phy != NULL) {
6f231dda
DW
1260 status = scic_sds_phy_reset(selected_phy);
1261
1262 if (status == SCI_SUCCESS) {
09d7da13
DJ
1263 isci_timer_start(sci_port->timer_handle, timeout);
1264 sci_port->not_ready_reason =
1265 SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
6f231dda
DW
1266
1267 sci_base_state_machine_change_state(
09d7da13
DJ
1268 &sci_port->parent.state_machine,
1269 SCI_BASE_PORT_STATE_RESETTING);
6f231dda
DW
1270 }
1271 }
1272
1273 return status;
1274}
1275
1276/**
1277 * scic_sds_port_ready_operational_substate_link_up_handler() -
1278 * @this_port: This is the struct scic_sds_port object that which has a phy that has
1279 * gone link up.
1280 * @the_phy: This is the struct scic_sds_phy object that has gone link up.
1281 *
1282 * This method is the ready operational substate link up handler for the
1283 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1284 * gone link up. none
1285 */
1286static void scic_sds_port_ready_operational_substate_link_up_handler(
1287 struct scic_sds_port *this_port,
1288 struct scic_sds_phy *the_phy)
1289{
1290 scic_sds_port_general_link_up_handler(this_port, the_phy, true);
1291}
1292
1293/**
1294 * scic_sds_port_ready_operational_substate_link_down_handler() -
068b2c03 1295 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
6f231dda 1296 * gone link down.
068b2c03 1297 * @sci_phy: This is the struct scic_sds_phy object that has gone link down.
6f231dda
DW
1298 *
1299 * This method is the ready operational substate link down handler for the
1300 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1301 * gone link down and if this is the last phy in the port the port will change
1302 * state to the ready waiting substate. none
1303 */
1304static void scic_sds_port_ready_operational_substate_link_down_handler(
068b2c03
DW
1305 struct scic_sds_port *sci_port,
1306 struct scic_sds_phy *sci_phy)
6f231dda 1307{
068b2c03 1308 scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
6f231dda
DW
1309
1310 /*
1311 * If there are no active phys left in the port, then transition
1312 * the port to the WAITING state until such time as a phy goes
1313 * link up. */
068b2c03
DW
1314 if (sci_port->active_phy_mask == 0)
1315 sci_base_state_machine_change_state(&sci_port->ready_substate_machine,
1316 SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
6f231dda
DW
1317}
1318
1319/**
1320 *
1321 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1322 * object.
1323 * @device: This is the struct sci_base_remote_device object which is not used in this
1324 * function.
1325 * @io_request: This is the struct sci_base_request object which is not used in this
1326 * function.
1327 *
1328 * This method is the ready operational substate start io handler for the
1329 * struct scic_sds_port object. This function incremetns the outstanding request
1330 * count for this port object. enum sci_status SCI_SUCCESS
1331 */
1332static enum sci_status scic_sds_port_ready_operational_substate_start_io_handler(
1333 struct scic_sds_port *port,
1334 struct scic_sds_remote_device *device,
1335 struct scic_sds_request *io_request)
1336{
1337 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1338
1339 scic_sds_port_increment_request_count(this_port);
1340
1341 return SCI_SUCCESS;
1342}
1343
1344/*
1345 * ****************************************************************************
1346 * * READY SUBSTATE OPERATIONAL HANDLERS
1347 * **************************************************************************** */
1348
1349/**
1350 * scic_sds_port_ready_configuring_substate_add_phy_handler() -
1351 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1352 * object.
1353 *
1354 * This is the default method for a port add phy request. It will report a
1355 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1356 */
1357static enum sci_status scic_sds_port_ready_configuring_substate_add_phy_handler(
1358 struct sci_base_port *port,
1359 struct sci_base_phy *phy)
1360{
1361 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1362 struct scic_sds_phy *this_phy = (struct scic_sds_phy *)phy;
1363 enum sci_status status;
1364
1365 status = scic_sds_port_set_phy(this_port, this_phy);
1366
1367 if (status == SCI_SUCCESS) {
1368 scic_sds_port_general_link_up_handler(this_port, this_phy, true);
1369
1370 /*
1371 * Re-enter the configuring state since this may be the last phy in
1372 * the port. */
1373 sci_base_state_machine_change_state(
1374 &this_port->ready_substate_machine,
1375 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1376 );
1377 }
1378
1379 return status;
1380}
1381
1382/**
1383 * scic_sds_port_ready_configuring_substate_remove_phy_handler() -
1384 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1385 * object.
1386 *
1387 * This is the default method for a port remove phy request. It will report a
1388 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1389 */
1390static enum sci_status scic_sds_port_ready_configuring_substate_remove_phy_handler(
1391 struct sci_base_port *port,
1392 struct sci_base_phy *phy)
1393{
1394 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1395 struct scic_sds_phy *this_phy = (struct scic_sds_phy *)phy;
1396 enum sci_status status;
1397
1398 status = scic_sds_port_clear_phy(this_port, this_phy);
1399
1400 if (status == SCI_SUCCESS) {
1401 scic_sds_port_deactivate_phy(this_port, this_phy, true);
1402
1403 /*
1404 * Re-enter the configuring state since this may be the last phy in
1405 * the port. */
1406 sci_base_state_machine_change_state(
1407 &this_port->ready_substate_machine,
1408 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1409 );
1410 }
1411
1412 return status;
1413}
1414
1415/**
1416 * scic_sds_port_ready_configuring_substate_complete_io_handler() -
1417 * @port: This is the port that is being requested to complete the io request.
1418 * @device: This is the device on which the io is completing.
1419 *
1420 * This method will decrement the outstanding request count for this port. If
1421 * the request count goes to 0 then the port can be reprogrammed with its new
1422 * phy data.
1423 */
1424static enum sci_status scic_sds_port_ready_configuring_substate_complete_io_handler(
1425 struct scic_sds_port *port,
1426 struct scic_sds_remote_device *device,
1427 struct scic_sds_request *io_request)
1428{
1429 scic_sds_port_decrement_request_count(port);
1430
1431 if (port->started_request_count == 0) {
1432 sci_base_state_machine_change_state(
1433 &port->ready_substate_machine,
1434 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1435 );
1436 }
1437
1438 return SCI_SUCCESS;
1439}
1440
35173d57
DW
1441static enum sci_status default_port_handler(struct sci_base_port *base_port, const char *func)
1442{
1443 struct scic_sds_port *sci_port;
1444
1445 sci_port = container_of(base_port, typeof(*sci_port), parent);
1446 dev_warn(sciport_to_dev(sci_port),
1447 "%s: in wrong state: %d\n", func,
1448 sci_base_state_machine_get_state(&base_port->state_machine));
1449 return SCI_FAILURE_INVALID_STATE;
1450}
1451
1452static enum sci_status scic_sds_port_default_start_handler(struct sci_base_port *base_port)
1453{
1454 return default_port_handler(base_port, __func__);
1455}
1456
1457static enum sci_status scic_sds_port_default_stop_handler(struct sci_base_port *base_port)
1458{
1459 return default_port_handler(base_port, __func__);
1460}
1461
1462static enum sci_status scic_sds_port_default_destruct_handler(struct sci_base_port *base_port)
1463{
1464 return default_port_handler(base_port, __func__);
1465}
1466
1467static enum sci_status scic_sds_port_default_reset_handler(struct sci_base_port *base_port,
1468 u32 timeout)
1469{
1470 return default_port_handler(base_port, __func__);
1471}
1472
1473static enum sci_status scic_sds_port_default_add_phy_handler(struct sci_base_port *base_port,
1474 struct sci_base_phy *base_phy)
1475{
1476 return default_port_handler(base_port, __func__);
1477}
1478
1479static enum sci_status scic_sds_port_default_remove_phy_handler(struct sci_base_port *base_port,
1480 struct sci_base_phy *base_phy)
1481{
1482 return default_port_handler(base_port, __func__);
1483}
1484
1485/**
1486 * scic_sds_port_default_frame_handler
1487 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1488 * object.
1489 *
1490 * This is the default method for a port unsolicited frame request. It will
1491 * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE Is it even
1492 * possible to receive an unsolicited frame directed to a port object? It
1493 * seems possible if we implementing virtual functions but until then?
1494 */
1495static enum sci_status scic_sds_port_default_frame_handler(struct scic_sds_port *sci_port,
1496 u32 frame_index)
1497{
1498 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
1499
1500 default_port_handler(&sci_port->parent, __func__);
1501 scic_sds_controller_release_frame(scic, frame_index);
1502
1503 return SCI_FAILURE_INVALID_STATE;
1504}
1505
1506static enum sci_status scic_sds_port_default_event_handler(struct scic_sds_port *sci_port,
1507 u32 event_code)
1508{
1509 return default_port_handler(&sci_port->parent, __func__);
1510}
1511
1512static void scic_sds_port_default_link_up_handler(struct scic_sds_port *sci_port,
1513 struct scic_sds_phy *sci_phy)
1514{
1515 default_port_handler(&sci_port->parent, __func__);
1516}
1517
1518static void scic_sds_port_default_link_down_handler(struct scic_sds_port *sci_port,
1519 struct scic_sds_phy *sci_phy)
1520{
1521 default_port_handler(&sci_port->parent, __func__);
1522}
6f231dda 1523
35173d57
DW
1524static enum sci_status scic_sds_port_default_start_io_handler(struct scic_sds_port *sci_port,
1525 struct scic_sds_remote_device *sci_dev,
1526 struct scic_sds_request *sci_req)
1527{
1528 return default_port_handler(&sci_port->parent, __func__);
1529}
1530
1531static enum sci_status scic_sds_port_default_complete_io_handler(struct scic_sds_port *sci_port,
1532 struct scic_sds_remote_device *sci_dev,
1533 struct scic_sds_request *sci_req)
1534{
1535 return default_port_handler(&sci_port->parent, __func__);
1536}
1537
1538
1539
1540static struct scic_sds_port_state_handler
6f231dda
DW
1541scic_sds_port_ready_substate_handler_table[SCIC_SDS_PORT_READY_MAX_SUBSTATES] =
1542{
1543 /* SCIC_SDS_PORT_READY_SUBSTATE_WAITING */
1544 {
1545 {
1546 scic_sds_port_default_start_handler,
1547 scic_sds_port_ready_substate_stop_handler,
1548 scic_sds_port_default_destruct_handler,
1549 scic_sds_port_default_reset_handler,
1550 scic_sds_port_ready_substate_add_phy_handler,
1551 scic_sds_port_default_remove_phy_handler
1552 },
1553 scic_sds_port_default_frame_handler,
1554 scic_sds_port_default_event_handler,
1555 scic_sds_port_ready_waiting_substate_link_up_handler,
1556 scic_sds_port_default_link_down_handler,
1557 scic_sds_port_ready_waiting_substate_start_io_handler,
1558 scic_sds_port_ready_substate_complete_io_handler,
1559 },
1560 /* SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL */
1561 {
1562 {
1563 scic_sds_port_default_start_handler,
1564 scic_sds_port_ready_substate_stop_handler,
1565 scic_sds_port_default_destruct_handler,
1566 scic_sds_port_ready_operational_substate_reset_handler,
1567 scic_sds_port_ready_substate_add_phy_handler,
1568 scic_sds_port_ready_substate_remove_phy_handler
1569 },
1570 scic_sds_port_default_frame_handler,
1571 scic_sds_port_default_event_handler,
1572 scic_sds_port_ready_operational_substate_link_up_handler,
1573 scic_sds_port_ready_operational_substate_link_down_handler,
1574 scic_sds_port_ready_operational_substate_start_io_handler,
1575 scic_sds_port_ready_substate_complete_io_handler
1576 },
1577 /* SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING */
1578 {
1579 {
1580 scic_sds_port_default_start_handler,
1581 scic_sds_port_ready_substate_stop_handler,
1582 scic_sds_port_default_destruct_handler,
1583 scic_sds_port_default_reset_handler,
1584 scic_sds_port_ready_configuring_substate_add_phy_handler,
1585 scic_sds_port_ready_configuring_substate_remove_phy_handler
1586 },
1587 scic_sds_port_default_frame_handler,
1588 scic_sds_port_default_event_handler,
1589 scic_sds_port_default_link_up_handler,
1590 scic_sds_port_default_link_down_handler,
1591 scic_sds_port_default_start_io_handler,
1592 scic_sds_port_ready_configuring_substate_complete_io_handler
1593 }
1594};
1595
6f231dda
DW
1596/**
1597 * scic_sds_port_set_ready_state_handlers() -
1598 *
1599 * This macro sets the port ready substate handlers.
1600 */
1601#define scic_sds_port_set_ready_state_handlers(port, state_id) \
1602 scic_sds_port_set_state_handlers(\
1603 port, &scic_sds_port_ready_substate_handler_table[(state_id)] \
1604 )
1605
1606/*
1607 * ******************************************************************************
1608 * * PORT STATE PRIVATE METHODS
1609 * ****************************************************************************** */
1610
1611/**
1612 *
1613 * @this_port: This is the struct scic_sds_port object to suspend.
1614 *
1615 * This method will susped the port task scheduler for this port object. none
1616 */
bc99aa47
CH
1617static void
1618scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port *port)
6f231dda
DW
1619{
1620 u32 pts_control_value;
6f231dda 1621
bc99aa47 1622 pts_control_value = readl(&port->port_task_scheduler_registers->control);
6f231dda 1623 pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
bc99aa47 1624 writel(pts_control_value, &port->port_task_scheduler_registers->control);
6f231dda
DW
1625}
1626
a8d4b9fe
TC
1627/**
1628 * scic_sds_port_post_dummy_request() - post dummy/workaround request
1629 * @sci_port: port to post task
1630 *
1631 * Prevent the hardware scheduler from posting new requests to the front
1632 * of the scheduler queue causing a starvation problem for currently
1633 * ongoing requests.
1634 *
1635 */
35173d57 1636static void scic_sds_port_post_dummy_request(struct scic_sds_port *sci_port)
a8d4b9fe
TC
1637{
1638 u32 command;
1639 struct scu_task_context *task_context;
1640 struct scic_sds_controller *scic = sci_port->owning_controller;
1641 u16 tci = sci_port->reserved_tci;
1642
1643 task_context = scic_sds_controller_get_task_context_buffer(scic, tci);
1644
1645 task_context->abort = 0;
1646
1647 command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
1648 sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
1649 tci;
1650
1651 scic_sds_controller_post_request(scic, command);
1652}
1653
1654/**
1655 * This routine will abort the dummy request. This will alow the hardware to
1656 * power down parts of the silicon to save power.
1657 *
1658 * @sci_port: The port on which the task must be aborted.
1659 *
1660 */
35173d57 1661static void scic_sds_port_abort_dummy_request(struct scic_sds_port *sci_port)
a8d4b9fe
TC
1662{
1663 struct scic_sds_controller *scic = sci_port->owning_controller;
1664 u16 tci = sci_port->reserved_tci;
1665 struct scu_task_context *tc;
1666 u32 command;
1667
1668 tc = scic_sds_controller_get_task_context_buffer(scic, tci);
1669
1670 tc->abort = 1;
1671
1672 command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
1673 sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
1674 tci;
1675
1676 scic_sds_controller_post_request(scic, command);
1677}
1678
6f231dda
DW
1679/**
1680 *
1681 * @this_port: This is the struct scic_sds_port object to resume.
1682 *
1683 * This method will resume the port task scheduler for this port object. none
1684 */
bc99aa47
CH
1685static void
1686scic_sds_port_resume_port_task_scheduler(struct scic_sds_port *port)
6f231dda
DW
1687{
1688 u32 pts_control_value;
1689
bc99aa47 1690 pts_control_value = readl(&port->port_task_scheduler_registers->control);
6f231dda 1691 pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
bc99aa47 1692 writel(pts_control_value, &port->port_task_scheduler_registers->control);
6f231dda
DW
1693}
1694
1695/*
1696 * ******************************************************************************
1697 * * PORT READY SUBSTATE METHODS
1698 * ****************************************************************************** */
1699
1700/**
1701 *
1702 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1703 *
1704 * This method will perform the actions required by the struct scic_sds_port on
1705 * entering the SCIC_SDS_PORT_READY_SUBSTATE_WAITING. This function checks the
1706 * port for any ready phys. If there is at least one phy in a ready state then
1707 * the port transitions to the ready operational substate. none
1708 */
1709static void scic_sds_port_ready_substate_waiting_enter(
1710 struct sci_base_object *object)
1711{
1712 struct scic_sds_port *this_port = (struct scic_sds_port *)object;
1713
1714 scic_sds_port_set_ready_state_handlers(
1715 this_port, SCIC_SDS_PORT_READY_SUBSTATE_WAITING
1716 );
1717
1718 scic_sds_port_suspend_port_task_scheduler(this_port);
1719
1720 this_port->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
1721
1722 if (this_port->active_phy_mask != 0) {
1723 /* At least one of the phys on the port is ready */
1724 sci_base_state_machine_change_state(
1725 &this_port->ready_substate_machine,
1726 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1727 );
1728 }
1729}
1730
1731/**
1732 *
09d7da13
DJ
1733 * @object: This is the struct sci_base_object which is cast to a
1734 * struct scic_sds_port object.
6f231dda 1735 *
09d7da13
DJ
1736 * This function will perform the actions required by the struct scic_sds_port
1737 * on entering the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function sets
6f231dda
DW
1738 * the state handlers for the port object, notifies the SCI User that the port
1739 * is ready, and resumes port operations. none
1740 */
1741static void scic_sds_port_ready_substate_operational_enter(
1742 struct sci_base_object *object)
1743{
1744 u32 index;
09d7da13
DJ
1745 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
1746 struct scic_sds_controller *scic =
1747 scic_sds_port_get_controller(sci_port);
1748 struct isci_host *ihost = sci_object_get_association(scic);
1749 struct isci_port *iport = sci_object_get_association(sci_port);
6f231dda
DW
1750
1751 scic_sds_port_set_ready_state_handlers(
09d7da13
DJ
1752 sci_port,
1753 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
6f231dda 1754
09d7da13 1755 isci_port_ready(ihost, iport);
6f231dda
DW
1756
1757 for (index = 0; index < SCI_MAX_PHYS; index++) {
bc99aa47
CH
1758 if (sci_port->phy_table[index]) {
1759 writel(sci_port->physical_port_index,
1760 &sci_port->port_pe_configuration_register[
1761 sci_port->phy_table[index]->phy_index]);
1762 }
6f231dda
DW
1763 }
1764
09d7da13 1765 scic_sds_port_update_viit_entry(sci_port);
6f231dda 1766
09d7da13 1767 scic_sds_port_resume_port_task_scheduler(sci_port);
a8d4b9fe 1768
09d7da13
DJ
1769 /*
1770 * Post the dummy task for the port so the hardware can schedule
a8d4b9fe
TC
1771 * io correctly
1772 */
09d7da13 1773 scic_sds_port_post_dummy_request(sci_port);
6f231dda
DW
1774}
1775
1776/**
1777 *
1778 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1779 *
1780 * This method will perform the actions required by the struct scic_sds_port on
1781 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1782 * the port not ready and suspends the port task scheduler. none
1783 */
1784static void scic_sds_port_ready_substate_operational_exit(
1785 struct sci_base_object *object)
1786{
09d7da13
DJ
1787 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
1788 struct scic_sds_controller *scic =
1789 scic_sds_port_get_controller(sci_port);
1790 struct isci_host *ihost = sci_object_get_association(scic);
1791 struct isci_port *iport = sci_object_get_association(sci_port);
6f231dda 1792
09d7da13
DJ
1793 /*
1794 * Kill the dummy task for this port if it has not yet posted
1795 * the hardware will treat this as a NOP and just return abort
1796 * complete.
1797 */
1798 scic_sds_port_abort_dummy_request(sci_port);
27ce51df 1799
09d7da13 1800 isci_port_not_ready(ihost, iport);
6f231dda
DW
1801}
1802
1803/*
1804 * ******************************************************************************
1805 * * PORT READY CONFIGURING METHODS
1806 * ****************************************************************************** */
1807
1808/**
1809 * scic_sds_port_ready_substate_configuring_enter() -
09d7da13
DJ
1810 * @object: This is the struct sci_base_object which is cast to a
1811 * struct scic_sds_port object.
6f231dda
DW
1812 *
1813 * This method will perform the actions required by the struct scic_sds_port on
1814 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1815 * the port not ready and suspends the port task scheduler. none
1816 */
1817static void scic_sds_port_ready_substate_configuring_enter(
1818 struct sci_base_object *object)
1819{
09d7da13
DJ
1820 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
1821 struct scic_sds_controller *scic =
1822 scic_sds_port_get_controller(sci_port);
1823 struct isci_host *ihost = sci_object_get_association(scic);
1824 struct isci_port *iport = sci_object_get_association(sci_port);
6f231dda
DW
1825
1826 scic_sds_port_set_ready_state_handlers(
09d7da13
DJ
1827 sci_port,
1828 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
6f231dda 1829
09d7da13
DJ
1830 if (sci_port->active_phy_mask == 0) {
1831 isci_port_not_ready(ihost, iport);
6f231dda
DW
1832
1833 sci_base_state_machine_change_state(
09d7da13
DJ
1834 &sci_port->ready_substate_machine,
1835 SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
1836 } else if (sci_port->started_request_count == 0)
6f231dda 1837 sci_base_state_machine_change_state(
09d7da13
DJ
1838 &sci_port->ready_substate_machine,
1839 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
6f231dda
DW
1840}
1841
1842static void scic_sds_port_ready_substate_configuring_exit(
1843 struct sci_base_object *object)
1844{
1845 struct scic_sds_port *this_port = (struct scic_sds_port *)object;
1846
1847 scic_sds_port_suspend_port_task_scheduler(this_port);
1848}
1849
1850/* --------------------------------------------------------------------------- */
1851
35173d57 1852static const struct sci_base_state scic_sds_port_ready_substate_table[] = {
6f231dda
DW
1853 [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
1854 .enter_state = scic_sds_port_ready_substate_waiting_enter,
1855 },
1856 [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
1857 .enter_state = scic_sds_port_ready_substate_operational_enter,
1858 .exit_state = scic_sds_port_ready_substate_operational_exit
1859 },
1860 [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
1861 .enter_state = scic_sds_port_ready_substate_configuring_enter,
1862 .exit_state = scic_sds_port_ready_substate_configuring_exit
1863 },
1864};
1865
6f231dda
DW
1866/**
1867 *
1868 * @port: This is the struct scic_sds_port object on which the io request count will
1869 * be decremented.
1870 * @device: This is the struct scic_sds_remote_device object to which the io request
1871 * is being directed. This parameter is not required to complete this
1872 * operation.
1873 * @io_request: This is the request that is being completed on this port
1874 * object. This parameter is not required to complete this operation.
1875 *
1876 * This is a general complete io request handler for the struct scic_sds_port object.
1877 * enum sci_status SCI_SUCCESS
1878 */
1879static enum sci_status scic_sds_port_general_complete_io_handler(
1880 struct scic_sds_port *port,
1881 struct scic_sds_remote_device *device,
1882 struct scic_sds_request *io_request)
1883{
1884 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1885
1886 scic_sds_port_decrement_request_count(this_port);
1887
1888 return SCI_SUCCESS;
1889}
1890
6f231dda 1891/**
a8d4b9fe 1892 * scic_sds_port_stopped_state_start_handler() - stop a port from "started"
6f231dda 1893 *
09d7da13
DJ
1894 * @port: This is the struct sci_base_port object which is cast into a
1895 * struct scic_sds_port object.
6f231dda 1896 *
09d7da13
DJ
1897 * This function takes the struct scic_sds_port from a stopped state and
1898 * attempts to start it. To start a port it must have no assiged devices and
1899 * it must have at least one phy assigned to it. If those conditions are
1900 * met then the port can transition to the ready state.
1901 * enum sci_status
1902 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
1903 * This struct scic_sds_port object could not be started because the port
1904 * configuration is not valid.
1905 * SCI_SUCCESS
1906 * the start request is successful and the struct scic_sds_port object
1907 * has transitioned to the SCI_BASE_PORT_STATE_READY.
6f231dda 1908 */
09d7da13
DJ
1909static enum sci_status
1910scic_sds_port_stopped_state_start_handler(struct sci_base_port *base_port)
6f231dda 1911{
09d7da13
DJ
1912 struct scic_sds_port *sci_port =
1913 container_of(base_port, typeof(*sci_port), parent);
a8d4b9fe 1914 struct scic_sds_controller *scic = sci_port->owning_controller;
09d7da13 1915 struct isci_host *ihost = sci_object_get_association(scic);
a8d4b9fe 1916 enum sci_status status = SCI_SUCCESS;
6f231dda 1917 u32 phy_mask;
6f231dda 1918
a8d4b9fe 1919 if (sci_port->assigned_device_count > 0) {
6f231dda 1920 /*
09d7da13
DJ
1921 * @todo This is a start failure operation because
1922 * there are still devices assigned to this port.
1923 * There must be no devices assigned to a port on a
1924 * start operation.
1925 */
6f231dda
DW
1926 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1927 }
1928
09d7da13
DJ
1929 sci_port->timer_handle =
1930 isci_timer_create(ihost,
1931 sci_port,
1932 scic_sds_port_timeout_handler);
6f231dda 1933
a8d4b9fe
TC
1934 if (!sci_port->timer_handle)
1935 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
6f231dda 1936
a8d4b9fe 1937 if (sci_port->reserved_rni == SCU_DUMMY_INDEX) {
09d7da13
DJ
1938 u16 rni = scic_sds_remote_node_table_allocate_remote_node(
1939 &scic->available_remote_nodes, 1);
a8d4b9fe
TC
1940
1941 if (rni != SCU_DUMMY_INDEX)
1942 scic_sds_port_construct_dummy_rnc(sci_port, rni);
1943 else
1944 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1945 sci_port->reserved_rni = rni;
1946 }
1947
1948 if (sci_port->reserved_tci == SCU_DUMMY_INDEX) {
1949 /* Allocate a TCI and remove the sequence nibble */
1950 u16 tci = scic_controller_allocate_io_tag(scic);
1951
1952 if (tci != SCU_DUMMY_INDEX)
1953 scic_sds_port_construct_dummy_task(sci_port, tci);
1954 else
1955 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1956 sci_port->reserved_tci = tci;
1957 }
1958
1959 if (status == SCI_SUCCESS) {
1960 phy_mask = scic_sds_port_get_phys(sci_port);
1961
1962 /*
1963 * There are one or more phys assigned to this port. Make sure
1964 * the port's phy mask is in fact legal and supported by the
1965 * silicon.
1966 */
1967 if (scic_sds_port_is_phy_mask_valid(sci_port, phy_mask) == true) {
068b2c03
DW
1968 sci_base_state_machine_change_state(&base_port->state_machine,
1969 SCI_BASE_PORT_STATE_READY);
a8d4b9fe
TC
1970
1971 return SCI_SUCCESS;
1972 } else
1973 status = SCI_FAILURE;
6f231dda
DW
1974 }
1975
a8d4b9fe
TC
1976 if (status != SCI_SUCCESS)
1977 scic_sds_port_destroy_dummy_resources(sci_port);
1978
1979 return status;
6f231dda
DW
1980}
1981
1982/**
1983 *
1984 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1985 * object.
1986 *
1987 * This method takes the struct scic_sds_port that is in a stopped state and handles a
1988 * stop request. This function takes no action. enum sci_status SCI_SUCCESS the
1989 * stop request is successful as the struct scic_sds_port object is already stopped.
1990 */
1991static enum sci_status scic_sds_port_stopped_state_stop_handler(
1992 struct sci_base_port *port)
1993{
1994 /* We are already stopped so there is nothing to do here */
1995 return SCI_SUCCESS;
1996}
1997
1998/**
1999 *
2000 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2001 * object.
2002 *
2003 * This method takes the struct scic_sds_port that is in a stopped state and handles
2004 * the destruct request. The stopped state is the only state in which the
2005 * struct scic_sds_port can be destroyed. This function causes the port object to
2006 * transition to the SCI_BASE_PORT_STATE_FINAL. enum sci_status SCI_SUCCESS
2007 */
2008static enum sci_status scic_sds_port_stopped_state_destruct_handler(
2009 struct sci_base_port *port)
2010{
2011 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
2012
2013 sci_base_state_machine_stop(&this_port->parent.state_machine);
2014
2015 return SCI_SUCCESS;
2016}
2017
2018/**
2019 *
2020 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2021 * object.
2022 * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
2023 * object.
2024 *
2025 * This method takes the struct scic_sds_port that is in a stopped state and handles
2026 * the add phy request. In MPC mode the only time a phy can be added to a port
2027 * is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
2028 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
2029 * be added to the port. SCI_SUCCESS if the phy is added to the port.
2030 */
2031static enum sci_status scic_sds_port_stopped_state_add_phy_handler(
2032 struct sci_base_port *port,
2033 struct sci_base_phy *phy)
2034{
2035 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
2036 struct scic_sds_phy *this_phy = (struct scic_sds_phy *)phy;
2037 struct sci_sas_address port_sas_address;
2038
2039 /* Read the port assigned SAS Address if there is one */
2040 scic_sds_port_get_sas_address(this_port, &port_sas_address);
2041
2042 if (port_sas_address.high != 0 && port_sas_address.low != 0) {
2043 struct sci_sas_address phy_sas_address;
2044
2045 /*
2046 * Make sure that the PHY SAS Address matches the SAS Address
2047 * for this port. */
2048 scic_sds_phy_get_sas_address(this_phy, &phy_sas_address);
2049
2050 if (
2051 (port_sas_address.high != phy_sas_address.high)
2052 || (port_sas_address.low != phy_sas_address.low)
2053 ) {
2054 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
2055 }
2056 }
2057
2058 return scic_sds_port_set_phy(this_port, this_phy);
2059}
2060
2061
2062/**
2063 *
2064 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2065 * object.
2066 * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
2067 * object.
2068 *
2069 * This method takes the struct scic_sds_port that is in a stopped state and handles
2070 * the remove phy request. In MPC mode the only time a phy can be removed from
2071 * a port is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
2072 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
2073 * be added to the port. SCI_SUCCESS if the phy is added to the port.
2074 */
2075static enum sci_status scic_sds_port_stopped_state_remove_phy_handler(
2076 struct sci_base_port *port,
2077 struct sci_base_phy *phy)
2078{
2079 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
2080 struct scic_sds_phy *this_phy = (struct scic_sds_phy *)phy;
2081
2082 return scic_sds_port_clear_phy(this_port, this_phy);
2083}
2084
2085/*
2086 * ****************************************************************************
2087 * * READY STATE HANDLERS
2088 * **************************************************************************** */
2089
2090/*
2091 * ****************************************************************************
2092 * * RESETTING STATE HANDLERS
2093 * **************************************************************************** */
2094
2095/*
2096 * ****************************************************************************
2097 * * STOPPING STATE HANDLERS
2098 * **************************************************************************** */
2099
2100/**
2101 *
2102 * @port: This is the struct scic_sds_port object on which the io request count will
2103 * be decremented.
2104 * @device: This is the struct scic_sds_remote_device object to which the io request
2105 * is being directed. This parameter is not required to complete this
2106 * operation.
2107 * @io_request: This is the request that is being completed on this port
2108 * object. This parameter is not required to complete this operation.
2109 *
2110 * This method takes the struct scic_sds_port that is in a stopping state and handles
2111 * the complete io request. Should the request count reach 0 then the port
2112 * object will transition to the stopped state. enum sci_status SCI_SUCCESS
2113 */
2114static enum sci_status scic_sds_port_stopping_state_complete_io_handler(
068b2c03 2115 struct scic_sds_port *sci_port,
6f231dda
DW
2116 struct scic_sds_remote_device *device,
2117 struct scic_sds_request *io_request)
2118{
068b2c03 2119 scic_sds_port_decrement_request_count(sci_port);
6f231dda 2120
068b2c03
DW
2121 if (sci_port->started_request_count == 0) {
2122 sci_base_state_machine_change_state(&sci_port->parent.state_machine,
2123 SCI_BASE_PORT_STATE_STOPPED);
6f231dda
DW
2124 }
2125
2126 return SCI_SUCCESS;
2127}
2128
2129/*
2130 * ****************************************************************************
2131 * * RESETTING STATE HANDLERS
2132 * **************************************************************************** */
2133
2134/**
2135 *
2136 * @port: This is the port object which is being requested to stop.
2137 *
2138 * This method will stop a failed port. This causes a transition to the
2139 * stopping state. enum sci_status SCI_SUCCESS
2140 */
2141static enum sci_status scic_sds_port_reset_state_stop_handler(
2142 struct sci_base_port *port)
2143{
2144 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
2145
2146 sci_base_state_machine_change_state(
2147 &this_port->parent.state_machine,
2148 SCI_BASE_PORT_STATE_STOPPING
2149 );
2150
2151 return SCI_SUCCESS;
2152}
2153
2154/**
2155 *
2156 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2157 * object.
2158 *
2159 * This method will transition a failed port to its ready state. The port
2160 * failed because a hard reset request timed out but at some time later one or
2161 * more phys in the port became ready. enum sci_status SCI_SUCCESS
2162 */
2163static void scic_sds_port_reset_state_link_up_handler(
2164 struct scic_sds_port *this_port,
2165 struct scic_sds_phy *phy)
2166{
2167 /*
2168 * / @todo We should make sure that the phy that has gone link up is the same
2169 * / one on which we sent the reset. It is possible that the phy on
2170 * / which we sent the reset is not the one that has gone link up and we
2171 * / want to make sure that phy being reset comes back. Consider the
2172 * / case where a reset is sent but before the hardware processes the
2173 * / reset it get a link up on the port because of a hot plug event.
2174 * / because of the reset request this phy will go link down almost
2175 * / immediately. */
2176
2177 /*
2178 * In the resetting state we don't notify the user regarding
2179 * link up and link down notifications. */
2180 scic_sds_port_general_link_up_handler(this_port, phy, false);
2181}
2182
2183/**
2184 *
2185 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2186 * object.
2187 *
2188 * This method process link down notifications that occur during a port reset
2189 * operation. Link downs can occur during the reset operation. enum sci_status
2190 * SCI_SUCCESS
2191 */
2192static void scic_sds_port_reset_state_link_down_handler(
2193 struct scic_sds_port *this_port,
2194 struct scic_sds_phy *phy)
2195{
2196 /*
2197 * In the resetting state we don't notify the user regarding
2198 * link up and link down notifications. */
2199 scic_sds_port_deactivate_phy(this_port, phy, false);
2200}
2201
35173d57 2202static struct scic_sds_port_state_handler
6f231dda
DW
2203scic_sds_port_state_handler_table[SCI_BASE_PORT_MAX_STATES] =
2204{
2205 /* SCI_BASE_PORT_STATE_STOPPED */
2206 {
2207 {
2208 scic_sds_port_stopped_state_start_handler,
2209 scic_sds_port_stopped_state_stop_handler,
2210 scic_sds_port_stopped_state_destruct_handler,
2211 scic_sds_port_default_reset_handler,
2212 scic_sds_port_stopped_state_add_phy_handler,
2213 scic_sds_port_stopped_state_remove_phy_handler
2214 },
2215 scic_sds_port_default_frame_handler,
2216 scic_sds_port_default_event_handler,
2217 scic_sds_port_default_link_up_handler,
2218 scic_sds_port_default_link_down_handler,
2219 scic_sds_port_default_start_io_handler,
2220 scic_sds_port_default_complete_io_handler
2221 },
2222 /* SCI_BASE_PORT_STATE_STOPPING */
2223 {
2224 {
2225 scic_sds_port_default_start_handler,
2226 scic_sds_port_default_stop_handler,
2227 scic_sds_port_default_destruct_handler,
2228 scic_sds_port_default_reset_handler,
2229 scic_sds_port_default_add_phy_handler,
2230 scic_sds_port_default_remove_phy_handler
2231 },
2232 scic_sds_port_default_frame_handler,
2233 scic_sds_port_default_event_handler,
2234 scic_sds_port_default_link_up_handler,
2235 scic_sds_port_default_link_down_handler,
2236 scic_sds_port_default_start_io_handler,
2237 scic_sds_port_stopping_state_complete_io_handler
2238 },
2239 /* SCI_BASE_PORT_STATE_READY */
2240 {
2241 {
2242 scic_sds_port_default_start_handler,
2243 scic_sds_port_default_stop_handler,
2244 scic_sds_port_default_destruct_handler,
2245 scic_sds_port_default_reset_handler,
2246 scic_sds_port_default_add_phy_handler,
2247 scic_sds_port_default_remove_phy_handler
2248 },
2249 scic_sds_port_default_frame_handler,
2250 scic_sds_port_default_event_handler,
2251 scic_sds_port_default_link_up_handler,
2252 scic_sds_port_default_link_down_handler,
2253 scic_sds_port_default_start_io_handler,
2254 scic_sds_port_general_complete_io_handler
2255 },
2256 /* SCI_BASE_PORT_STATE_RESETTING */
2257 {
2258 {
2259 scic_sds_port_default_start_handler,
2260 scic_sds_port_reset_state_stop_handler,
2261 scic_sds_port_default_destruct_handler,
2262 scic_sds_port_default_reset_handler,
2263 scic_sds_port_default_add_phy_handler,
2264 scic_sds_port_default_remove_phy_handler
2265 },
2266 scic_sds_port_default_frame_handler,
2267 scic_sds_port_default_event_handler,
2268 scic_sds_port_reset_state_link_up_handler,
2269 scic_sds_port_reset_state_link_down_handler,
2270 scic_sds_port_default_start_io_handler,
2271 scic_sds_port_general_complete_io_handler
2272 },
2273 /* SCI_BASE_PORT_STATE_FAILED */
2274 {
2275 {
2276 scic_sds_port_default_start_handler,
2277 scic_sds_port_default_stop_handler,
2278 scic_sds_port_default_destruct_handler,
2279 scic_sds_port_default_reset_handler,
2280 scic_sds_port_default_add_phy_handler,
2281 scic_sds_port_default_remove_phy_handler
2282 },
2283 scic_sds_port_default_frame_handler,
2284 scic_sds_port_default_event_handler,
2285 scic_sds_port_default_link_up_handler,
2286 scic_sds_port_default_link_down_handler,
2287 scic_sds_port_default_start_io_handler,
2288 scic_sds_port_general_complete_io_handler
2289 }
2290};
2291
2292/*
2293 * ******************************************************************************
2294 * * PORT STATE PRIVATE METHODS
2295 * ****************************************************************************** */
2296
2297/**
2298 *
2299 * @this_port: This is the port object which to suspend.
2300 *
2301 * This method will enable the SCU Port Task Scheduler for this port object but
2302 * will leave the port task scheduler in a suspended state. none
2303 */
bc99aa47
CH
2304static void
2305scic_sds_port_enable_port_task_scheduler(struct scic_sds_port *port)
6f231dda
DW
2306{
2307 u32 pts_control_value;
2308
bc99aa47 2309 pts_control_value = readl(&port->port_task_scheduler_registers->control);
6f231dda 2310 pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
bc99aa47 2311 writel(pts_control_value, &port->port_task_scheduler_registers->control);
6f231dda
DW
2312}
2313
2314/**
2315 *
2316 * @this_port: This is the port object which to resume.
2317 *
2318 * This method will disable the SCU port task scheduler for this port object.
2319 * none
2320 */
bc99aa47
CH
2321static void
2322scic_sds_port_disable_port_task_scheduler(struct scic_sds_port *port)
6f231dda
DW
2323{
2324 u32 pts_control_value;
2325
bc99aa47
CH
2326 pts_control_value = readl(&port->port_task_scheduler_registers->control);
2327 pts_control_value &=
2328 ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND));
2329 writel(pts_control_value, &port->port_task_scheduler_registers->control);
6f231dda
DW
2330}
2331
35173d57 2332static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port *sci_port)
a8d4b9fe
TC
2333{
2334 struct scic_sds_controller *scic = sci_port->owning_controller;
2335 u8 phys_index = sci_port->physical_port_index;
2336 union scu_remote_node_context *rnc;
2337 u16 rni = sci_port->reserved_rni;
2338 u32 command;
2339
2340 rnc = &scic->remote_node_context_table[rni];
2341 rnc->ssp.is_valid = true;
2342
2343 command = SCU_CONTEXT_COMMAND_POST_RNC_32 |
2344 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
2345
2346 scic_sds_controller_post_request(scic, command);
2347
2348 /* ensure hardware has seen the post rnc command and give it
2349 * ample time to act before sending the suspend
2350 */
bc99aa47 2351 readl(&scic->smu_registers->interrupt_status); /* flush */
a8d4b9fe
TC
2352 udelay(10);
2353
2354 command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX |
2355 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
2356
2357 scic_sds_controller_post_request(scic, command);
2358}
2359
35173d57 2360static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port *sci_port)
a8d4b9fe
TC
2361{
2362 struct scic_sds_controller *scic = sci_port->owning_controller;
2363 u8 phys_index = sci_port->physical_port_index;
2364 union scu_remote_node_context *rnc;
2365 u16 rni = sci_port->reserved_rni;
2366 u32 command;
2367
2368 rnc = &scic->remote_node_context_table[rni];
2369
2370 rnc->ssp.is_valid = false;
2371
27ce51df
DW
2372 /* ensure the preceding tc abort request has reached the
2373 * controller and give it ample time to act before posting the rnc
2374 * invalidate
2375 */
bc99aa47 2376 readl(&scic->smu_registers->interrupt_status); /* flush */
27ce51df
DW
2377 udelay(10);
2378
a8d4b9fe
TC
2379 command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
2380 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
2381
2382 scic_sds_controller_post_request(scic, command);
2383}
2384
6f231dda
DW
2385/*
2386 * ******************************************************************************
2387 * * PORT STATE METHODS
2388 * ****************************************************************************** */
2389
2390/**
2391 *
2392 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2393 *
2394 * This method will perform the actions required by the struct scic_sds_port on
2395 * entering the SCI_BASE_PORT_STATE_STOPPED. This function sets the stopped
2396 * state handlers for the struct scic_sds_port object and disables the port task
2397 * scheduler in the hardware. none
2398 */
2399static void scic_sds_port_stopped_state_enter(
2400 struct sci_base_object *object)
2401{
2402 struct scic_sds_port *this_port;
2403
2404 this_port = (struct scic_sds_port *)object;
2405
2406 scic_sds_port_set_base_state_handlers(
2407 this_port, SCI_BASE_PORT_STATE_STOPPED
2408 );
2409
2410 if (
2411 SCI_BASE_PORT_STATE_STOPPING
2412 == this_port->parent.state_machine.previous_state_id
2413 ) {
2414 /*
2415 * If we enter this state becasuse of a request to stop
2416 * the port then we want to disable the hardwares port
2417 * task scheduler. */
2418 scic_sds_port_disable_port_task_scheduler(this_port);
2419 }
2420}
2421
2422/**
2423 *
2424 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2425 *
2426 * This method will perform the actions required by the struct scic_sds_port on
2427 * exiting the SCI_BASE_STATE_STOPPED. This function enables the SCU hardware
2428 * port task scheduler. none
2429 */
2430static void scic_sds_port_stopped_state_exit(
2431 struct sci_base_object *object)
2432{
2433 struct scic_sds_port *this_port;
2434
2435 this_port = (struct scic_sds_port *)object;
2436
2437 /* Enable and suspend the port task scheduler */
2438 scic_sds_port_enable_port_task_scheduler(this_port);
2439}
2440
2441/**
068b2c03
DW
2442 * scic_sds_port_ready_state_enter -
2443 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
6f231dda
DW
2444 *
2445 * This method will perform the actions required by the struct scic_sds_port on
2446 * entering the SCI_BASE_PORT_STATE_READY. This function sets the ready state
09d7da13
DJ
2447 * handlers for the struct scic_sds_port object, reports the port object as
2448 * not ready and starts the ready substate machine. none
6f231dda 2449 */
09d7da13 2450static void scic_sds_port_ready_state_enter(struct sci_base_object *object)
6f231dda 2451{
068b2c03
DW
2452 struct scic_sds_controller *scic;
2453 struct scic_sds_port *sci_port;
2454 struct isci_port *iport;
2455 struct isci_host *ihost;
2456 u32 prev_state;
6f231dda 2457
068b2c03
DW
2458 sci_port = container_of(object, typeof(*sci_port), parent.parent);
2459 scic = scic_sds_port_get_controller(sci_port);
2460 ihost = sci_object_get_association(scic);
2461 iport = sci_object_get_association(sci_port);
6f231dda 2462
068b2c03
DW
2463 /* Put the ready state handlers in place though they will not be there long */
2464 scic_sds_port_set_base_state_handlers(sci_port, SCI_BASE_PORT_STATE_READY);
2465
2466 prev_state = sci_port->parent.state_machine.previous_state_id;
2467 if (prev_state == SCI_BASE_PORT_STATE_RESETTING)
09d7da13 2468 isci_port_hard_reset_complete(iport, SCI_SUCCESS);
068b2c03 2469 else
09d7da13 2470 isci_port_not_ready(ihost, iport);
6f231dda 2471
a8d4b9fe 2472 /* Post and suspend the dummy remote node context for this port. */
09d7da13 2473 scic_sds_port_post_dummy_remote_node(sci_port);
a8d4b9fe 2474
6f231dda 2475 /* Start the ready substate machine */
068b2c03 2476 sci_base_state_machine_start(&sci_port->ready_substate_machine);
6f231dda
DW
2477}
2478
068b2c03 2479static void scic_sds_port_ready_state_exit(struct sci_base_object *object)
6f231dda 2480{
068b2c03 2481 struct scic_sds_port *sci_port;
a8d4b9fe 2482
068b2c03
DW
2483 sci_port = container_of(object, typeof(*sci_port), parent.parent);
2484 sci_base_state_machine_stop(&sci_port->ready_substate_machine);
2485 scic_sds_port_invalidate_dummy_remote_node(sci_port);
6f231dda
DW
2486}
2487
2488/**
2489 *
2490 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2491 *
2492 * This method will perform the actions required by the struct scic_sds_port on
2493 * entering the SCI_BASE_PORT_STATE_RESETTING. This function sets the resetting
2494 * state handlers for the struct scic_sds_port object. none
2495 */
2496static void scic_sds_port_resetting_state_enter(
2497 struct sci_base_object *object)
2498{
2499 struct scic_sds_port *this_port;
2500
2501 this_port = (struct scic_sds_port *)object;
2502
2503 scic_sds_port_set_base_state_handlers(
2504 this_port, SCI_BASE_PORT_STATE_RESETTING
2505 );
6f231dda
DW
2506}
2507
2508/**
2509 *
09d7da13
DJ
2510 * @object: This is the struct sci_base_object which is cast to a
2511 * struct scic_sds_port object.
6f231dda 2512 *
09d7da13
DJ
2513 * This function will perform the actions required by the
2514 * struct scic_sds_port on
6f231dda
DW
2515 * exiting the SCI_BASE_STATE_RESETTING. This function does nothing. none
2516 */
09d7da13 2517static inline void scic_sds_port_resetting_state_exit(
6f231dda
DW
2518 struct sci_base_object *object)
2519{
09d7da13 2520 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
6f231dda 2521
09d7da13 2522 isci_timer_stop(sci_port->timer_handle);
6f231dda
DW
2523}
2524
2525/**
2526 *
2527 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2528 *
2529 * This method will perform the actions required by the struct scic_sds_port on
2530 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2531 * state handlers for the struct scic_sds_port object. none
2532 */
2533static void scic_sds_port_stopping_state_enter(
2534 struct sci_base_object *object)
2535{
2536 struct scic_sds_port *this_port;
2537
2538 this_port = (struct scic_sds_port *)object;
2539
2540 scic_sds_port_set_base_state_handlers(
2541 this_port, SCI_BASE_PORT_STATE_STOPPING
2542 );
2543}
2544
2545/**
2546 *
09d7da13
DJ
2547 * @object: This is the struct sci_base_object which is cast to a
2548 * struct scic_sds_port object.
6f231dda 2549 *
09d7da13
DJ
2550 * This function will perform the actions required by the
2551 * struct scic_sds_port on
6f231dda
DW
2552 * exiting the SCI_BASE_STATE_STOPPING. This function does nothing. none
2553 */
09d7da13
DJ
2554static inline void
2555scic_sds_port_stopping_state_exit(struct sci_base_object *object)
6f231dda 2556{
09d7da13 2557 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
6f231dda 2558
09d7da13 2559 isci_timer_stop(sci_port->timer_handle);
a8d4b9fe 2560
09d7da13 2561 scic_sds_port_destroy_dummy_resources(sci_port);
6f231dda
DW
2562}
2563
2564/**
2565 *
09d7da13
DJ
2566 * @object: This is the struct sci_base_object which is cast to a
2567 * struct scic_sds_port object.
6f231dda 2568 *
09d7da13
DJ
2569 * This function will perform the actions required by the
2570 * struct scic_sds_port on
6f231dda
DW
2571 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2572 * state handlers for the struct scic_sds_port object. none
2573 */
09d7da13 2574static void scic_sds_port_failed_state_enter(struct sci_base_object *object)
6f231dda 2575{
09d7da13
DJ
2576 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
2577 struct isci_port *iport = sci_object_get_association(sci_port);
6f231dda 2578
09d7da13
DJ
2579 scic_sds_port_set_base_state_handlers(sci_port,
2580 SCI_BASE_PORT_STATE_FAILED);
6f231dda 2581
09d7da13 2582 isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT);
6f231dda
DW
2583}
2584
2585/* --------------------------------------------------------------------------- */
2586
35173d57 2587static const struct sci_base_state scic_sds_port_state_table[] = {
6f231dda
DW
2588 [SCI_BASE_PORT_STATE_STOPPED] = {
2589 .enter_state = scic_sds_port_stopped_state_enter,
2590 .exit_state = scic_sds_port_stopped_state_exit
2591 },
2592 [SCI_BASE_PORT_STATE_STOPPING] = {
2593 .enter_state = scic_sds_port_stopping_state_enter,
2594 .exit_state = scic_sds_port_stopping_state_exit
2595 },
2596 [SCI_BASE_PORT_STATE_READY] = {
2597 .enter_state = scic_sds_port_ready_state_enter,
2598 .exit_state = scic_sds_port_ready_state_exit
2599 },
2600 [SCI_BASE_PORT_STATE_RESETTING] = {
2601 .enter_state = scic_sds_port_resetting_state_enter,
2602 .exit_state = scic_sds_port_resetting_state_exit
2603 },
2604 [SCI_BASE_PORT_STATE_FAILED] = {
2605 .enter_state = scic_sds_port_failed_state_enter,
2606 }
2607};
2608
35173d57
DW
2609void scic_sds_port_construct(struct scic_sds_port *sci_port, u8 port_index,
2610 struct scic_sds_controller *scic)
2611{
2612 u32 index;
2613
2614 sci_base_port_construct(&sci_port->parent, scic_sds_port_state_table);
2615
2616 sci_base_state_machine_construct(&sci_port->ready_substate_machine,
2617 &sci_port->parent.parent,
2618 scic_sds_port_ready_substate_table,
2619 SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
2620
2621 sci_port->logical_port_index = SCIC_SDS_DUMMY_PORT;
2622 sci_port->physical_port_index = port_index;
2623 sci_port->active_phy_mask = 0;
2624
2625 sci_port->owning_controller = scic;
2626
2627 sci_port->started_request_count = 0;
2628 sci_port->assigned_device_count = 0;
2629
2630 sci_port->reserved_rni = SCU_DUMMY_INDEX;
2631 sci_port->reserved_tci = SCU_DUMMY_INDEX;
2632
2633 sci_port->timer_handle = NULL;
2634
2635 sci_port->port_task_scheduler_registers = NULL;
2636
2637 for (index = 0; index < SCI_MAX_PHYS; index++)
2638 sci_port->phy_table[index] = NULL;
2639}
This page took 0.141451 seconds and 5 git commands to generate.