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