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