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