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.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
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
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.
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.
55 #include <linux/device.h>
61 #include "probe_roms.h"
62 #include "remote_device.h"
64 #include "scic_sds_port_configuration_agent.h"
65 #include "scu_completion_codes.h"
66 #include "scu_event_codes.h"
67 #include "registers.h"
68 #include "scu_remote_node_context.h"
69 #include "scu_task_context.h"
70 #include "scu_unsolicited_frame.h"
73 #define SCU_CONTEXT_RAM_INIT_STALL_TIME 200
76 * smu_dcc_get_max_ports() -
78 * This macro returns the maximum number of logical ports supported by the
79 * hardware. The caller passes in the value read from the device context
80 * capacity register and this macro will mash and shift the value appropriately.
82 #define smu_dcc_get_max_ports(dcc_value) \
84 (((dcc_value) & SMU_DEVICE_CONTEXT_CAPACITY_MAX_LP_MASK) \
85 >> SMU_DEVICE_CONTEXT_CAPACITY_MAX_LP_SHIFT) + 1 \
89 * smu_dcc_get_max_task_context() -
91 * This macro returns the maximum number of task contexts supported by the
92 * hardware. The caller passes in the value read from the device context
93 * capacity register and this macro will mash and shift the value appropriately.
95 #define smu_dcc_get_max_task_context(dcc_value) \
97 (((dcc_value) & SMU_DEVICE_CONTEXT_CAPACITY_MAX_TC_MASK) \
98 >> SMU_DEVICE_CONTEXT_CAPACITY_MAX_TC_SHIFT) + 1 \
102 * smu_dcc_get_max_remote_node_context() -
104 * This macro returns the maximum number of remote node contexts supported by
105 * the hardware. The caller passes in the value read from the device context
106 * capacity register and this macro will mash and shift the value appropriately.
108 #define smu_dcc_get_max_remote_node_context(dcc_value) \
110 (((dcc_value) & SMU_DEVICE_CONTEXT_CAPACITY_MAX_RNC_MASK) \
111 >> SMU_DEVICE_CONTEXT_CAPACITY_MAX_RNC_SHIFT) + 1 \
115 #define SCIC_SDS_CONTROLLER_MIN_TIMER_COUNT 3
116 #define SCIC_SDS_CONTROLLER_MAX_TIMER_COUNT 3
121 * The number of milliseconds to wait for a phy to start.
123 #define SCIC_SDS_CONTROLLER_PHY_START_TIMEOUT 100
128 * The number of milliseconds to wait while a given phy is consuming power
129 * before allowing another set of phys to consume power. Ultimately, this will
130 * be specified by OEM parameter.
132 #define SCIC_SDS_CONTROLLER_POWER_CONTROL_INTERVAL 500
135 * NORMALIZE_PUT_POINTER() -
137 * This macro will normalize the completion queue put pointer so its value can
138 * be used as an array inde
140 #define NORMALIZE_PUT_POINTER(x) \
141 ((x) & SMU_COMPLETION_QUEUE_PUT_POINTER_MASK)
145 * NORMALIZE_EVENT_POINTER() -
147 * This macro will normalize the completion queue event entry so its value can
148 * be used as an index.
150 #define NORMALIZE_EVENT_POINTER(x) \
152 ((x) & SMU_COMPLETION_QUEUE_GET_EVENT_POINTER_MASK) \
153 >> SMU_COMPLETION_QUEUE_GET_EVENT_POINTER_SHIFT \
157 * INCREMENT_COMPLETION_QUEUE_GET() -
159 * This macro will increment the controllers completion queue index value and
160 * possibly toggle the cycle bit if the completion queue index wraps back to 0.
162 #define INCREMENT_COMPLETION_QUEUE_GET(controller, index, cycle) \
163 INCREMENT_QUEUE_GET(\
166 (controller)->completion_queue_entries, \
171 * INCREMENT_EVENT_QUEUE_GET() -
173 * This macro will increment the controllers event queue index value and
174 * possibly toggle the event cycle bit if the event queue index wraps back to 0.
176 #define INCREMENT_EVENT_QUEUE_GET(controller, index, cycle) \
177 INCREMENT_QUEUE_GET(\
180 (controller)->completion_event_entries, \
181 SMU_CQGR_EVENT_CYCLE_BIT \
186 * NORMALIZE_GET_POINTER() -
188 * This macro will normalize the completion queue get pointer so its value can
189 * be used as an index into an array
191 #define NORMALIZE_GET_POINTER(x) \
192 ((x) & SMU_COMPLETION_QUEUE_GET_POINTER_MASK)
195 * NORMALIZE_GET_POINTER_CYCLE_BIT() -
197 * This macro will normalize the completion queue cycle pointer so it matches
198 * the completion queue cycle bit
200 #define NORMALIZE_GET_POINTER_CYCLE_BIT(x) \
201 ((SMU_CQGR_CYCLE_BIT & (x)) << (31 - SMU_COMPLETION_QUEUE_GET_CYCLE_BIT_SHIFT))
204 * COMPLETION_QUEUE_CYCLE_BIT() -
206 * This macro will return the cycle bit of the completion queue entry
208 #define COMPLETION_QUEUE_CYCLE_BIT(x) ((x) & 0x80000000)
210 static bool scic_sds_controller_completion_queue_has_entries(
211 struct scic_sds_controller
*scic
)
213 u32 get_value
= scic
->completion_queue_get
;
214 u32 get_index
= get_value
& SMU_COMPLETION_QUEUE_GET_POINTER_MASK
;
216 if (NORMALIZE_GET_POINTER_CYCLE_BIT(get_value
) ==
217 COMPLETION_QUEUE_CYCLE_BIT(scic
->completion_queue
[get_index
]))
223 static bool scic_sds_controller_isr(struct scic_sds_controller
*scic
)
225 if (scic_sds_controller_completion_queue_has_entries(scic
)) {
229 * we have a spurious interrupt it could be that we have already
230 * emptied the completion queue from a previous interrupt */
231 writel(SMU_ISR_COMPLETION
, &scic
->smu_registers
->interrupt_status
);
234 * There is a race in the hardware that could cause us not to be notified
235 * of an interrupt completion if we do not take this step. We will mask
236 * then unmask the interrupts so if there is another interrupt pending
237 * the clearing of the interrupt source we get the next interrupt message. */
238 writel(0xFF000000, &scic
->smu_registers
->interrupt_mask
);
239 writel(0, &scic
->smu_registers
->interrupt_mask
);
245 irqreturn_t
isci_msix_isr(int vec
, void *data
)
247 struct isci_host
*ihost
= data
;
249 if (scic_sds_controller_isr(&ihost
->sci
))
250 tasklet_schedule(&ihost
->completion_tasklet
);
255 static bool scic_sds_controller_error_isr(struct scic_sds_controller
*scic
)
257 u32 interrupt_status
;
260 readl(&scic
->smu_registers
->interrupt_status
);
261 interrupt_status
&= (SMU_ISR_QUEUE_ERROR
| SMU_ISR_QUEUE_SUSPEND
);
263 if (interrupt_status
!= 0) {
265 * There is an error interrupt pending so let it through and handle
271 * There is a race in the hardware that could cause us not to be notified
272 * of an interrupt completion if we do not take this step. We will mask
273 * then unmask the error interrupts so if there was another interrupt
274 * pending we will be notified.
275 * Could we write the value of (SMU_ISR_QUEUE_ERROR | SMU_ISR_QUEUE_SUSPEND)? */
276 writel(0xff, &scic
->smu_registers
->interrupt_mask
);
277 writel(0, &scic
->smu_registers
->interrupt_mask
);
282 static void scic_sds_controller_task_completion(struct scic_sds_controller
*scic
,
283 u32 completion_entry
)
286 struct scic_sds_request
*io_request
;
288 index
= SCU_GET_COMPLETION_INDEX(completion_entry
);
289 io_request
= scic
->io_request_table
[index
];
291 /* Make sure that we really want to process this IO request */
294 && (io_request
->io_tag
!= SCI_CONTROLLER_INVALID_IO_TAG
)
296 scic_sds_io_tag_get_sequence(io_request
->io_tag
)
297 == scic
->io_request_sequence
[index
]
300 /* Yep this is a valid io request pass it along to the io request handler */
301 scic_sds_io_request_tc_completion(io_request
, completion_entry
);
305 static void scic_sds_controller_sdma_completion(struct scic_sds_controller
*scic
,
306 u32 completion_entry
)
309 struct scic_sds_request
*io_request
;
310 struct scic_sds_remote_device
*device
;
312 index
= SCU_GET_COMPLETION_INDEX(completion_entry
);
314 switch (scu_get_command_request_type(completion_entry
)) {
315 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
:
316 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_DUMP_TC
:
317 io_request
= scic
->io_request_table
[index
];
318 dev_warn(scic_to_dev(scic
),
319 "%s: SCIC SDS Completion type SDMA %x for io request "
324 /* @todo For a post TC operation we need to fail the IO
329 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_DUMP_RNC
:
330 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_OTHER_RNC
:
331 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_RNC
:
332 device
= scic
->device_table
[index
];
333 dev_warn(scic_to_dev(scic
),
334 "%s: SCIC SDS Completion type SDMA %x for remote "
339 /* @todo For a port RNC operation we need to fail the
345 dev_warn(scic_to_dev(scic
),
346 "%s: SCIC SDS Completion unknown SDMA completion "
355 static void scic_sds_controller_unsolicited_frame(struct scic_sds_controller
*scic
,
356 u32 completion_entry
)
361 struct isci_host
*ihost
= scic_to_ihost(scic
);
362 struct scu_unsolicited_frame_header
*frame_header
;
363 struct scic_sds_phy
*phy
;
364 struct scic_sds_remote_device
*device
;
366 enum sci_status result
= SCI_FAILURE
;
368 frame_index
= SCU_GET_FRAME_INDEX(completion_entry
);
370 frame_header
= scic
->uf_control
.buffers
.array
[frame_index
].header
;
371 scic
->uf_control
.buffers
.array
[frame_index
].state
= UNSOLICITED_FRAME_IN_USE
;
373 if (SCU_GET_FRAME_ERROR(completion_entry
)) {
375 * / @todo If the IAF frame or SIGNATURE FIS frame has an error will
376 * / this cause a problem? We expect the phy initialization will
377 * / fail if there is an error in the frame. */
378 scic_sds_controller_release_frame(scic
, frame_index
);
382 if (frame_header
->is_address_frame
) {
383 index
= SCU_GET_PROTOCOL_ENGINE_INDEX(completion_entry
);
384 phy
= &ihost
->phys
[index
].sci
;
385 result
= scic_sds_phy_frame_handler(phy
, frame_index
);
388 index
= SCU_GET_COMPLETION_INDEX(completion_entry
);
390 if (index
== SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
) {
392 * This is a signature fis or a frame from a direct attached SATA
393 * device that has not yet been created. In either case forwared
394 * the frame to the PE and let it take care of the frame data. */
395 index
= SCU_GET_PROTOCOL_ENGINE_INDEX(completion_entry
);
396 phy
= &ihost
->phys
[index
].sci
;
397 result
= scic_sds_phy_frame_handler(phy
, frame_index
);
399 if (index
< scic
->remote_node_entries
)
400 device
= scic
->device_table
[index
];
405 result
= scic_sds_remote_device_frame_handler(device
, frame_index
);
407 scic_sds_controller_release_frame(scic
, frame_index
);
411 if (result
!= SCI_SUCCESS
) {
413 * / @todo Is there any reason to report some additional error message
414 * / when we get this failure notifiction? */
418 static void scic_sds_controller_event_completion(struct scic_sds_controller
*scic
,
419 u32 completion_entry
)
421 struct isci_host
*ihost
= scic_to_ihost(scic
);
422 struct scic_sds_request
*io_request
;
423 struct scic_sds_remote_device
*device
;
424 struct scic_sds_phy
*phy
;
427 index
= SCU_GET_COMPLETION_INDEX(completion_entry
);
429 switch (scu_get_event_type(completion_entry
)) {
430 case SCU_EVENT_TYPE_SMU_COMMAND_ERROR
:
431 /* / @todo The driver did something wrong and we need to fix the condtion. */
432 dev_err(scic_to_dev(scic
),
433 "%s: SCIC Controller 0x%p received SMU command error "
440 case SCU_EVENT_TYPE_SMU_PCQ_ERROR
:
441 case SCU_EVENT_TYPE_SMU_ERROR
:
442 case SCU_EVENT_TYPE_FATAL_MEMORY_ERROR
:
444 * / @todo This is a hardware failure and its likely that we want to
445 * / reset the controller. */
446 dev_err(scic_to_dev(scic
),
447 "%s: SCIC Controller 0x%p received fatal controller "
454 case SCU_EVENT_TYPE_TRANSPORT_ERROR
:
455 io_request
= scic
->io_request_table
[index
];
456 scic_sds_io_request_event_handler(io_request
, completion_entry
);
459 case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT
:
460 switch (scu_get_event_specifier(completion_entry
)) {
461 case SCU_EVENT_SPECIFIC_SMP_RESPONSE_NO_PE
:
462 case SCU_EVENT_SPECIFIC_TASK_TIMEOUT
:
463 io_request
= scic
->io_request_table
[index
];
464 if (io_request
!= NULL
)
465 scic_sds_io_request_event_handler(io_request
, completion_entry
);
467 dev_warn(scic_to_dev(scic
),
468 "%s: SCIC Controller 0x%p received "
469 "event 0x%x for io request object "
470 "that doesnt exist.\n",
477 case SCU_EVENT_SPECIFIC_IT_NEXUS_TIMEOUT
:
478 device
= scic
->device_table
[index
];
480 scic_sds_remote_device_event_handler(device
, completion_entry
);
482 dev_warn(scic_to_dev(scic
),
483 "%s: SCIC Controller 0x%p received "
484 "event 0x%x for remote device object "
485 "that doesnt exist.\n",
494 case SCU_EVENT_TYPE_BROADCAST_CHANGE
:
496 * direct the broadcast change event to the phy first and then let
497 * the phy redirect the broadcast change to the port object */
498 case SCU_EVENT_TYPE_ERR_CNT_EVENT
:
500 * direct error counter event to the phy object since that is where
501 * we get the event notification. This is a type 4 event. */
502 case SCU_EVENT_TYPE_OSSP_EVENT
:
503 index
= SCU_GET_PROTOCOL_ENGINE_INDEX(completion_entry
);
504 phy
= &ihost
->phys
[index
].sci
;
505 scic_sds_phy_event_handler(phy
, completion_entry
);
508 case SCU_EVENT_TYPE_RNC_SUSPEND_TX
:
509 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX
:
510 case SCU_EVENT_TYPE_RNC_OPS_MISC
:
511 if (index
< scic
->remote_node_entries
) {
512 device
= scic
->device_table
[index
];
515 scic_sds_remote_device_event_handler(device
, completion_entry
);
517 dev_err(scic_to_dev(scic
),
518 "%s: SCIC Controller 0x%p received event 0x%x "
519 "for remote device object 0x%0x that doesnt "
529 dev_warn(scic_to_dev(scic
),
530 "%s: SCIC Controller received unknown event code %x\n",
539 static void scic_sds_controller_process_completions(struct scic_sds_controller
*scic
)
541 u32 completion_count
= 0;
542 u32 completion_entry
;
548 dev_dbg(scic_to_dev(scic
),
549 "%s: completion queue begining get:0x%08x\n",
551 scic
->completion_queue_get
);
553 /* Get the component parts of the completion queue */
554 get_index
= NORMALIZE_GET_POINTER(scic
->completion_queue_get
);
555 get_cycle
= SMU_CQGR_CYCLE_BIT
& scic
->completion_queue_get
;
557 event_index
= NORMALIZE_EVENT_POINTER(scic
->completion_queue_get
);
558 event_cycle
= SMU_CQGR_EVENT_CYCLE_BIT
& scic
->completion_queue_get
;
561 NORMALIZE_GET_POINTER_CYCLE_BIT(get_cycle
)
562 == COMPLETION_QUEUE_CYCLE_BIT(scic
->completion_queue
[get_index
])
566 completion_entry
= scic
->completion_queue
[get_index
];
567 INCREMENT_COMPLETION_QUEUE_GET(scic
, get_index
, get_cycle
);
569 dev_dbg(scic_to_dev(scic
),
570 "%s: completion queue entry:0x%08x\n",
574 switch (SCU_GET_COMPLETION_TYPE(completion_entry
)) {
575 case SCU_COMPLETION_TYPE_TASK
:
576 scic_sds_controller_task_completion(scic
, completion_entry
);
579 case SCU_COMPLETION_TYPE_SDMA
:
580 scic_sds_controller_sdma_completion(scic
, completion_entry
);
583 case SCU_COMPLETION_TYPE_UFI
:
584 scic_sds_controller_unsolicited_frame(scic
, completion_entry
);
587 case SCU_COMPLETION_TYPE_EVENT
:
588 INCREMENT_EVENT_QUEUE_GET(scic
, event_index
, event_cycle
);
589 scic_sds_controller_event_completion(scic
, completion_entry
);
592 case SCU_COMPLETION_TYPE_NOTIFY
:
594 * Presently we do the same thing with a notify event that we do with the
595 * other event codes. */
596 INCREMENT_EVENT_QUEUE_GET(scic
, event_index
, event_cycle
);
597 scic_sds_controller_event_completion(scic
, completion_entry
);
601 dev_warn(scic_to_dev(scic
),
602 "%s: SCIC Controller received unknown "
603 "completion type %x\n",
610 /* Update the get register if we completed one or more entries */
611 if (completion_count
> 0) {
612 scic
->completion_queue_get
=
613 SMU_CQGR_GEN_BIT(ENABLE
) |
614 SMU_CQGR_GEN_BIT(EVENT_ENABLE
) |
616 SMU_CQGR_GEN_VAL(EVENT_POINTER
, event_index
) |
618 SMU_CQGR_GEN_VAL(POINTER
, get_index
);
620 writel(scic
->completion_queue_get
,
621 &scic
->smu_registers
->completion_queue_get
);
625 dev_dbg(scic_to_dev(scic
),
626 "%s: completion queue ending get:0x%08x\n",
628 scic
->completion_queue_get
);
632 static void scic_sds_controller_error_handler(struct scic_sds_controller
*scic
)
634 u32 interrupt_status
;
637 readl(&scic
->smu_registers
->interrupt_status
);
639 if ((interrupt_status
& SMU_ISR_QUEUE_SUSPEND
) &&
640 scic_sds_controller_completion_queue_has_entries(scic
)) {
642 scic_sds_controller_process_completions(scic
);
643 writel(SMU_ISR_QUEUE_SUSPEND
, &scic
->smu_registers
->interrupt_status
);
645 dev_err(scic_to_dev(scic
), "%s: status: %#x\n", __func__
,
648 sci_base_state_machine_change_state(&scic
->state_machine
,
649 SCI_BASE_CONTROLLER_STATE_FAILED
);
654 /* If we dont process any completions I am not sure that we want to do this.
655 * We are in the middle of a hardware fault and should probably be reset.
657 writel(0, &scic
->smu_registers
->interrupt_mask
);
660 irqreturn_t
isci_intx_isr(int vec
, void *data
)
662 irqreturn_t ret
= IRQ_NONE
;
663 struct isci_host
*ihost
= data
;
664 struct scic_sds_controller
*scic
= &ihost
->sci
;
666 if (scic_sds_controller_isr(scic
)) {
667 writel(SMU_ISR_COMPLETION
, &scic
->smu_registers
->interrupt_status
);
668 tasklet_schedule(&ihost
->completion_tasklet
);
670 } else if (scic_sds_controller_error_isr(scic
)) {
671 spin_lock(&ihost
->scic_lock
);
672 scic_sds_controller_error_handler(scic
);
673 spin_unlock(&ihost
->scic_lock
);
680 irqreturn_t
isci_error_isr(int vec
, void *data
)
682 struct isci_host
*ihost
= data
;
684 if (scic_sds_controller_error_isr(&ihost
->sci
))
685 scic_sds_controller_error_handler(&ihost
->sci
);
691 * isci_host_start_complete() - This function is called by the core library,
692 * through the ISCI Module, to indicate controller start status.
693 * @isci_host: This parameter specifies the ISCI host object
694 * @completion_status: This parameter specifies the completion status from the
698 static void isci_host_start_complete(struct isci_host
*ihost
, enum sci_status completion_status
)
700 if (completion_status
!= SCI_SUCCESS
)
701 dev_info(&ihost
->pdev
->dev
,
702 "controller start timed out, continuing...\n");
703 isci_host_change_state(ihost
, isci_ready
);
704 clear_bit(IHOST_START_PENDING
, &ihost
->flags
);
705 wake_up(&ihost
->eventq
);
708 int isci_host_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
710 struct isci_host
*ihost
= SHOST_TO_SAS_HA(shost
)->lldd_ha
;
712 if (test_bit(IHOST_START_PENDING
, &ihost
->flags
))
715 /* todo: use sas_flush_discovery once it is upstream */
716 scsi_flush_work(shost
);
718 scsi_flush_work(shost
);
720 dev_dbg(&ihost
->pdev
->dev
,
721 "%s: ihost->status = %d, time = %ld\n",
722 __func__
, isci_host_get_state(ihost
), time
);
729 * scic_controller_get_suggested_start_timeout() - This method returns the
730 * suggested scic_controller_start() timeout amount. The user is free to
731 * use any timeout value, but this method provides the suggested minimum
732 * start timeout value. The returned value is based upon empirical
733 * information determined as a result of interoperability testing.
734 * @controller: the handle to the controller object for which to return the
735 * suggested start timeout.
737 * This method returns the number of milliseconds for the suggested start
740 static u32
scic_controller_get_suggested_start_timeout(
741 struct scic_sds_controller
*sc
)
743 /* Validate the user supplied parameters. */
748 * The suggested minimum timeout value for a controller start operation:
750 * Signature FIS Timeout
751 * + Phy Start Timeout
752 * + Number of Phy Spin Up Intervals
753 * ---------------------------------
754 * Number of milliseconds for the controller start operation.
756 * NOTE: The number of phy spin up intervals will be equivalent
757 * to the number of phys divided by the number phys allowed
758 * per interval - 1 (once OEM parameters are supported).
759 * Currently we assume only 1 phy per interval. */
761 return SCIC_SDS_SIGNATURE_FIS_TIMEOUT
762 + SCIC_SDS_CONTROLLER_PHY_START_TIMEOUT
763 + ((SCI_MAX_PHYS
- 1) * SCIC_SDS_CONTROLLER_POWER_CONTROL_INTERVAL
);
766 static void scic_controller_enable_interrupts(
767 struct scic_sds_controller
*scic
)
769 BUG_ON(scic
->smu_registers
== NULL
);
770 writel(0, &scic
->smu_registers
->interrupt_mask
);
773 void scic_controller_disable_interrupts(
774 struct scic_sds_controller
*scic
)
776 BUG_ON(scic
->smu_registers
== NULL
);
777 writel(0xffffffff, &scic
->smu_registers
->interrupt_mask
);
780 static void scic_sds_controller_enable_port_task_scheduler(
781 struct scic_sds_controller
*scic
)
783 u32 port_task_scheduler_value
;
785 port_task_scheduler_value
=
786 readl(&scic
->scu_registers
->peg0
.ptsg
.control
);
787 port_task_scheduler_value
|=
788 (SCU_PTSGCR_GEN_BIT(ETM_ENABLE
) |
789 SCU_PTSGCR_GEN_BIT(PTSG_ENABLE
));
790 writel(port_task_scheduler_value
,
791 &scic
->scu_registers
->peg0
.ptsg
.control
);
794 static void scic_sds_controller_assign_task_entries(struct scic_sds_controller
*scic
)
799 * Assign all the TCs to function 0
800 * TODO: Do we actually need to read this register to write it back?
804 readl(&scic
->smu_registers
->task_context_assignment
[0]);
806 task_assignment
|= (SMU_TCA_GEN_VAL(STARTING
, 0)) |
807 (SMU_TCA_GEN_VAL(ENDING
, scic
->task_context_entries
- 1)) |
808 (SMU_TCA_GEN_BIT(RANGE_CHECK_ENABLE
));
810 writel(task_assignment
,
811 &scic
->smu_registers
->task_context_assignment
[0]);
815 static void scic_sds_controller_initialize_completion_queue(struct scic_sds_controller
*scic
)
818 u32 completion_queue_control_value
;
819 u32 completion_queue_get_value
;
820 u32 completion_queue_put_value
;
822 scic
->completion_queue_get
= 0;
824 completion_queue_control_value
= (
825 SMU_CQC_QUEUE_LIMIT_SET(scic
->completion_queue_entries
- 1)
826 | SMU_CQC_EVENT_LIMIT_SET(scic
->completion_event_entries
- 1)
829 writel(completion_queue_control_value
,
830 &scic
->smu_registers
->completion_queue_control
);
833 /* Set the completion queue get pointer and enable the queue */
834 completion_queue_get_value
= (
835 (SMU_CQGR_GEN_VAL(POINTER
, 0))
836 | (SMU_CQGR_GEN_VAL(EVENT_POINTER
, 0))
837 | (SMU_CQGR_GEN_BIT(ENABLE
))
838 | (SMU_CQGR_GEN_BIT(EVENT_ENABLE
))
841 writel(completion_queue_get_value
,
842 &scic
->smu_registers
->completion_queue_get
);
844 /* Set the completion queue put pointer */
845 completion_queue_put_value
= (
846 (SMU_CQPR_GEN_VAL(POINTER
, 0))
847 | (SMU_CQPR_GEN_VAL(EVENT_POINTER
, 0))
850 writel(completion_queue_put_value
,
851 &scic
->smu_registers
->completion_queue_put
);
853 /* Initialize the cycle bit of the completion queue entries */
854 for (index
= 0; index
< scic
->completion_queue_entries
; index
++) {
856 * If get.cycle_bit != completion_queue.cycle_bit
857 * its not a valid completion queue entry
858 * so at system start all entries are invalid */
859 scic
->completion_queue
[index
] = 0x80000000;
863 static void scic_sds_controller_initialize_unsolicited_frame_queue(struct scic_sds_controller
*scic
)
865 u32 frame_queue_control_value
;
866 u32 frame_queue_get_value
;
867 u32 frame_queue_put_value
;
869 /* Write the queue size */
870 frame_queue_control_value
=
871 SCU_UFQC_GEN_VAL(QUEUE_SIZE
,
872 scic
->uf_control
.address_table
.count
);
874 writel(frame_queue_control_value
,
875 &scic
->scu_registers
->sdma
.unsolicited_frame_queue_control
);
877 /* Setup the get pointer for the unsolicited frame queue */
878 frame_queue_get_value
= (
879 SCU_UFQGP_GEN_VAL(POINTER
, 0)
880 | SCU_UFQGP_GEN_BIT(ENABLE_BIT
)
883 writel(frame_queue_get_value
,
884 &scic
->scu_registers
->sdma
.unsolicited_frame_get_pointer
);
885 /* Setup the put pointer for the unsolicited frame queue */
886 frame_queue_put_value
= SCU_UFQPP_GEN_VAL(POINTER
, 0);
887 writel(frame_queue_put_value
,
888 &scic
->scu_registers
->sdma
.unsolicited_frame_put_pointer
);
892 * This method will attempt to transition into the ready state for the
893 * controller and indicate that the controller start operation has completed
894 * if all criteria are met.
895 * @scic: This parameter indicates the controller object for which
896 * to transition to ready.
897 * @status: This parameter indicates the status value to be pass into the call
898 * to scic_cb_controller_start_complete().
902 static void scic_sds_controller_transition_to_ready(
903 struct scic_sds_controller
*scic
,
904 enum sci_status status
)
906 struct isci_host
*ihost
= scic_to_ihost(scic
);
908 if (scic
->state_machine
.current_state_id
==
909 SCI_BASE_CONTROLLER_STATE_STARTING
) {
911 * We move into the ready state, because some of the phys/ports
912 * may be up and operational.
914 sci_base_state_machine_change_state(&scic
->state_machine
,
915 SCI_BASE_CONTROLLER_STATE_READY
);
917 isci_host_start_complete(ihost
, status
);
921 static void scic_sds_controller_phy_timer_stop(struct scic_sds_controller
*scic
)
923 isci_timer_stop(scic
->phy_startup_timer
);
925 scic
->phy_startup_timer_pending
= false;
928 static void scic_sds_controller_phy_timer_start(struct scic_sds_controller
*scic
)
930 isci_timer_start(scic
->phy_startup_timer
,
931 SCIC_SDS_CONTROLLER_PHY_START_TIMEOUT
);
933 scic
->phy_startup_timer_pending
= true;
937 * scic_sds_controller_start_next_phy - start phy
940 * If all the phys have been started, then attempt to transition the
941 * controller to the READY state and inform the user
942 * (scic_cb_controller_start_complete()).
944 static enum sci_status
scic_sds_controller_start_next_phy(struct scic_sds_controller
*scic
)
946 struct isci_host
*ihost
= scic_to_ihost(scic
);
947 struct scic_sds_oem_params
*oem
= &scic
->oem_parameters
.sds1
;
948 struct scic_sds_phy
*sci_phy
;
949 enum sci_status status
;
951 status
= SCI_SUCCESS
;
953 if (scic
->phy_startup_timer_pending
)
956 if (scic
->next_phy_to_start
>= SCI_MAX_PHYS
) {
957 bool is_controller_start_complete
= true;
961 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
962 sci_phy
= &ihost
->phys
[index
].sci
;
963 state
= sci_phy
->state_machine
.current_state_id
;
965 if (!scic_sds_phy_get_port(sci_phy
))
968 /* The controller start operation is complete iff:
969 * - all links have been given an opportunity to start
970 * - have no indication of a connected device
971 * - have an indication of a connected device and it has
972 * finished the link training process.
974 if ((sci_phy
->is_in_link_training
== false &&
975 state
== SCI_BASE_PHY_STATE_INITIAL
) ||
976 (sci_phy
->is_in_link_training
== false &&
977 state
== SCI_BASE_PHY_STATE_STOPPED
) ||
978 (sci_phy
->is_in_link_training
== true &&
979 state
== SCI_BASE_PHY_STATE_STARTING
)) {
980 is_controller_start_complete
= false;
986 * The controller has successfully finished the start process.
987 * Inform the SCI Core user and transition to the READY state. */
988 if (is_controller_start_complete
== true) {
989 scic_sds_controller_transition_to_ready(scic
, SCI_SUCCESS
);
990 scic_sds_controller_phy_timer_stop(scic
);
993 sci_phy
= &ihost
->phys
[scic
->next_phy_to_start
].sci
;
995 if (oem
->controller
.mode_type
== SCIC_PORT_MANUAL_CONFIGURATION_MODE
) {
996 if (scic_sds_phy_get_port(sci_phy
) == NULL
) {
997 scic
->next_phy_to_start
++;
999 /* Caution recursion ahead be forwarned
1001 * The PHY was never added to a PORT in MPC mode
1002 * so start the next phy in sequence This phy
1003 * will never go link up and will not draw power
1004 * the OEM parameters either configured the phy
1005 * incorrectly for the PORT or it was never
1006 * assigned to a PORT
1008 return scic_sds_controller_start_next_phy(scic
);
1012 status
= scic_sds_phy_start(sci_phy
);
1014 if (status
== SCI_SUCCESS
) {
1015 scic_sds_controller_phy_timer_start(scic
);
1017 dev_warn(scic_to_dev(scic
),
1018 "%s: Controller stop operation failed "
1019 "to stop phy %d because of status "
1022 ihost
->phys
[scic
->next_phy_to_start
].sci
.phy_index
,
1026 scic
->next_phy_to_start
++;
1032 static void scic_sds_controller_phy_startup_timeout_handler(void *_scic
)
1034 struct scic_sds_controller
*scic
= _scic
;
1035 enum sci_status status
;
1037 scic
->phy_startup_timer_pending
= false;
1038 status
= SCI_FAILURE
;
1039 while (status
!= SCI_SUCCESS
)
1040 status
= scic_sds_controller_start_next_phy(scic
);
1043 static enum sci_status
scic_controller_start(struct scic_sds_controller
*scic
,
1046 struct isci_host
*ihost
= scic_to_ihost(scic
);
1047 enum sci_status result
;
1050 if (scic
->state_machine
.current_state_id
!=
1051 SCI_BASE_CONTROLLER_STATE_INITIALIZED
) {
1052 dev_warn(scic_to_dev(scic
),
1053 "SCIC Controller start operation requested in "
1055 return SCI_FAILURE_INVALID_STATE
;
1058 /* Build the TCi free pool */
1059 sci_pool_initialize(scic
->tci_pool
);
1060 for (index
= 0; index
< scic
->task_context_entries
; index
++)
1061 sci_pool_put(scic
->tci_pool
, index
);
1063 /* Build the RNi free pool */
1064 scic_sds_remote_node_table_initialize(
1065 &scic
->available_remote_nodes
,
1066 scic
->remote_node_entries
);
1069 * Before anything else lets make sure we will not be
1070 * interrupted by the hardware.
1072 scic_controller_disable_interrupts(scic
);
1074 /* Enable the port task scheduler */
1075 scic_sds_controller_enable_port_task_scheduler(scic
);
1077 /* Assign all the task entries to scic physical function */
1078 scic_sds_controller_assign_task_entries(scic
);
1080 /* Now initialize the completion queue */
1081 scic_sds_controller_initialize_completion_queue(scic
);
1083 /* Initialize the unsolicited frame queue for use */
1084 scic_sds_controller_initialize_unsolicited_frame_queue(scic
);
1086 /* Start all of the ports on this controller */
1087 for (index
= 0; index
< scic
->logical_port_entries
; index
++) {
1088 struct scic_sds_port
*sci_port
= &ihost
->ports
[index
].sci
;
1090 result
= sci_port
->state_handlers
->start_handler(sci_port
);
1095 scic_sds_controller_start_next_phy(scic
);
1097 isci_timer_start(scic
->timeout_timer
, timeout
);
1099 sci_base_state_machine_change_state(&scic
->state_machine
,
1100 SCI_BASE_CONTROLLER_STATE_STARTING
);
1105 void isci_host_scan_start(struct Scsi_Host
*shost
)
1107 struct isci_host
*ihost
= SHOST_TO_SAS_HA(shost
)->lldd_ha
;
1108 unsigned long tmo
= scic_controller_get_suggested_start_timeout(&ihost
->sci
);
1110 set_bit(IHOST_START_PENDING
, &ihost
->flags
);
1112 spin_lock_irq(&ihost
->scic_lock
);
1113 scic_controller_start(&ihost
->sci
, tmo
);
1114 scic_controller_enable_interrupts(&ihost
->sci
);
1115 spin_unlock_irq(&ihost
->scic_lock
);
1118 static void isci_host_stop_complete(struct isci_host
*ihost
, enum sci_status completion_status
)
1120 isci_host_change_state(ihost
, isci_stopped
);
1121 scic_controller_disable_interrupts(&ihost
->sci
);
1122 clear_bit(IHOST_STOP_PENDING
, &ihost
->flags
);
1123 wake_up(&ihost
->eventq
);
1126 static void scic_sds_controller_completion_handler(struct scic_sds_controller
*scic
)
1128 /* Empty out the completion queue */
1129 if (scic_sds_controller_completion_queue_has_entries(scic
))
1130 scic_sds_controller_process_completions(scic
);
1132 /* Clear the interrupt and enable all interrupts again */
1133 writel(SMU_ISR_COMPLETION
, &scic
->smu_registers
->interrupt_status
);
1134 /* Could we write the value of SMU_ISR_COMPLETION? */
1135 writel(0xFF000000, &scic
->smu_registers
->interrupt_mask
);
1136 writel(0, &scic
->smu_registers
->interrupt_mask
);
1140 * isci_host_completion_routine() - This function is the delayed service
1141 * routine that calls the sci core library's completion handler. It's
1142 * scheduled as a tasklet from the interrupt service routine when interrupts
1143 * in use, or set as the timeout function in polled mode.
1144 * @data: This parameter specifies the ISCI host object
1147 static void isci_host_completion_routine(unsigned long data
)
1149 struct isci_host
*isci_host
= (struct isci_host
*)data
;
1150 struct list_head completed_request_list
;
1151 struct list_head errored_request_list
;
1152 struct list_head
*current_position
;
1153 struct list_head
*next_position
;
1154 struct isci_request
*request
;
1155 struct isci_request
*next_request
;
1156 struct sas_task
*task
;
1158 INIT_LIST_HEAD(&completed_request_list
);
1159 INIT_LIST_HEAD(&errored_request_list
);
1161 spin_lock_irq(&isci_host
->scic_lock
);
1163 scic_sds_controller_completion_handler(&isci_host
->sci
);
1165 /* Take the lists of completed I/Os from the host. */
1167 list_splice_init(&isci_host
->requests_to_complete
,
1168 &completed_request_list
);
1170 /* Take the list of errored I/Os from the host. */
1171 list_splice_init(&isci_host
->requests_to_errorback
,
1172 &errored_request_list
);
1174 spin_unlock_irq(&isci_host
->scic_lock
);
1176 /* Process any completions in the lists. */
1177 list_for_each_safe(current_position
, next_position
,
1178 &completed_request_list
) {
1180 request
= list_entry(current_position
, struct isci_request
,
1182 task
= isci_request_access_task(request
);
1184 /* Normal notification (task_done) */
1185 dev_dbg(&isci_host
->pdev
->dev
,
1186 "%s: Normal - request/task = %p/%p\n",
1191 /* Return the task to libsas */
1194 task
->lldd_task
= NULL
;
1195 if (!(task
->task_state_flags
& SAS_TASK_STATE_ABORTED
)) {
1197 /* If the task is already in the abort path,
1198 * the task_done callback cannot be called.
1200 task
->task_done(task
);
1203 /* Free the request object. */
1204 isci_request_free(isci_host
, request
);
1206 list_for_each_entry_safe(request
, next_request
, &errored_request_list
,
1209 task
= isci_request_access_task(request
);
1211 /* Use sas_task_abort */
1212 dev_warn(&isci_host
->pdev
->dev
,
1213 "%s: Error - request/task = %p/%p\n",
1220 /* Put the task into the abort path if it's not there
1223 if (!(task
->task_state_flags
& SAS_TASK_STATE_ABORTED
))
1224 sas_task_abort(task
);
1227 /* This is a case where the request has completed with a
1228 * status such that it needed further target servicing,
1229 * but the sas_task reference has already been removed
1230 * from the request. Since it was errored, it was not
1231 * being aborted, so there is nothing to do except free
1235 spin_lock_irq(&isci_host
->scic_lock
);
1236 /* Remove the request from the remote device's list
1237 * of pending requests.
1239 list_del_init(&request
->dev_node
);
1240 spin_unlock_irq(&isci_host
->scic_lock
);
1242 /* Free the request object. */
1243 isci_request_free(isci_host
, request
);
1250 * scic_controller_stop() - This method will stop an individual controller
1251 * object.This method will invoke the associated user callback upon
1252 * completion. The completion callback is called when the following
1253 * conditions are met: -# the method return status is SCI_SUCCESS. -# the
1254 * controller has been quiesced. This method will ensure that all IO
1255 * requests are quiesced, phys are stopped, and all additional operation by
1256 * the hardware is halted.
1257 * @controller: the handle to the controller object to stop.
1258 * @timeout: This parameter specifies the number of milliseconds in which the
1259 * stop operation should complete.
1261 * The controller must be in the STARTED or STOPPED state. Indicate if the
1262 * controller stop method succeeded or failed in some way. SCI_SUCCESS if the
1263 * stop operation successfully began. SCI_WARNING_ALREADY_IN_STATE if the
1264 * controller is already in the STOPPED state. SCI_FAILURE_INVALID_STATE if the
1265 * controller is not either in the STARTED or STOPPED states.
1267 static enum sci_status
scic_controller_stop(struct scic_sds_controller
*scic
,
1270 if (scic
->state_machine
.current_state_id
!=
1271 SCI_BASE_CONTROLLER_STATE_READY
) {
1272 dev_warn(scic_to_dev(scic
),
1273 "SCIC Controller stop operation requested in "
1275 return SCI_FAILURE_INVALID_STATE
;
1278 isci_timer_start(scic
->timeout_timer
, timeout
);
1279 sci_base_state_machine_change_state(&scic
->state_machine
,
1280 SCI_BASE_CONTROLLER_STATE_STOPPING
);
1285 * scic_controller_reset() - This method will reset the supplied core
1286 * controller regardless of the state of said controller. This operation is
1287 * considered destructive. In other words, all current operations are wiped
1288 * out. No IO completions for outstanding devices occur. Outstanding IO
1289 * requests are not aborted or completed at the actual remote device.
1290 * @controller: the handle to the controller object to reset.
1292 * Indicate if the controller reset method succeeded or failed in some way.
1293 * SCI_SUCCESS if the reset operation successfully started. SCI_FATAL_ERROR if
1294 * the controller reset operation is unable to complete.
1296 static enum sci_status
scic_controller_reset(struct scic_sds_controller
*scic
)
1298 switch (scic
->state_machine
.current_state_id
) {
1299 case SCI_BASE_CONTROLLER_STATE_RESET
:
1300 case SCI_BASE_CONTROLLER_STATE_READY
:
1301 case SCI_BASE_CONTROLLER_STATE_STOPPED
:
1302 case SCI_BASE_CONTROLLER_STATE_FAILED
:
1304 * The reset operation is not a graceful cleanup, just
1305 * perform the state transition.
1307 sci_base_state_machine_change_state(&scic
->state_machine
,
1308 SCI_BASE_CONTROLLER_STATE_RESETTING
);
1311 dev_warn(scic_to_dev(scic
),
1312 "SCIC Controller reset operation requested in "
1314 return SCI_FAILURE_INVALID_STATE
;
1318 void isci_host_deinit(struct isci_host
*ihost
)
1322 isci_host_change_state(ihost
, isci_stopping
);
1323 for (i
= 0; i
< SCI_MAX_PORTS
; i
++) {
1324 struct isci_port
*iport
= &ihost
->ports
[i
];
1325 struct isci_remote_device
*idev
, *d
;
1327 list_for_each_entry_safe(idev
, d
, &iport
->remote_dev_list
, node
) {
1328 isci_remote_device_change_state(idev
, isci_stopping
);
1329 isci_remote_device_stop(ihost
, idev
);
1333 set_bit(IHOST_STOP_PENDING
, &ihost
->flags
);
1335 spin_lock_irq(&ihost
->scic_lock
);
1336 scic_controller_stop(&ihost
->sci
, SCIC_CONTROLLER_STOP_TIMEOUT
);
1337 spin_unlock_irq(&ihost
->scic_lock
);
1339 wait_for_stop(ihost
);
1340 scic_controller_reset(&ihost
->sci
);
1341 isci_timer_list_destroy(ihost
);
1344 static void __iomem
*scu_base(struct isci_host
*isci_host
)
1346 struct pci_dev
*pdev
= isci_host
->pdev
;
1347 int id
= isci_host
->id
;
1349 return pcim_iomap_table(pdev
)[SCI_SCU_BAR
* 2] + SCI_SCU_BAR_SIZE
* id
;
1352 static void __iomem
*smu_base(struct isci_host
*isci_host
)
1354 struct pci_dev
*pdev
= isci_host
->pdev
;
1355 int id
= isci_host
->id
;
1357 return pcim_iomap_table(pdev
)[SCI_SMU_BAR
* 2] + SCI_SMU_BAR_SIZE
* id
;
1360 static void isci_user_parameters_get(
1361 struct isci_host
*isci_host
,
1362 union scic_user_parameters
*scic_user_params
)
1364 struct scic_sds_user_parameters
*u
= &scic_user_params
->sds1
;
1367 for (i
= 0; i
< SCI_MAX_PHYS
; i
++) {
1368 struct sci_phy_user_params
*u_phy
= &u
->phys
[i
];
1370 u_phy
->max_speed_generation
= phy_gen
;
1372 /* we are not exporting these for now */
1373 u_phy
->align_insertion_frequency
= 0x7f;
1374 u_phy
->in_connection_align_insertion_frequency
= 0xff;
1375 u_phy
->notify_enable_spin_up_insertion_frequency
= 0x33;
1378 u
->stp_inactivity_timeout
= stp_inactive_to
;
1379 u
->ssp_inactivity_timeout
= ssp_inactive_to
;
1380 u
->stp_max_occupancy_timeout
= stp_max_occ_to
;
1381 u
->ssp_max_occupancy_timeout
= ssp_max_occ_to
;
1382 u
->no_outbound_task_timeout
= no_outbound_task_to
;
1383 u
->max_number_concurrent_device_spin_up
= max_concurr_spinup
;
1386 static void scic_sds_controller_initial_state_enter(void *object
)
1388 struct scic_sds_controller
*scic
= object
;
1390 sci_base_state_machine_change_state(&scic
->state_machine
,
1391 SCI_BASE_CONTROLLER_STATE_RESET
);
1394 static inline void scic_sds_controller_starting_state_exit(void *object
)
1396 struct scic_sds_controller
*scic
= object
;
1398 isci_timer_stop(scic
->timeout_timer
);
1401 #define INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_LOWER_BOUND_NS 853
1402 #define INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_UPPER_BOUND_NS 1280
1403 #define INTERRUPT_COALESCE_TIMEOUT_MAX_US 2700000
1404 #define INTERRUPT_COALESCE_NUMBER_MAX 256
1405 #define INTERRUPT_COALESCE_TIMEOUT_ENCODE_MIN 7
1406 #define INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX 28
1409 * scic_controller_set_interrupt_coalescence() - This method allows the user to
1410 * configure the interrupt coalescence.
1411 * @controller: This parameter represents the handle to the controller object
1412 * for which its interrupt coalesce register is overridden.
1413 * @coalesce_number: Used to control the number of entries in the Completion
1414 * Queue before an interrupt is generated. If the number of entries exceed
1415 * this number, an interrupt will be generated. The valid range of the input
1416 * is [0, 256]. A setting of 0 results in coalescing being disabled.
1417 * @coalesce_timeout: Timeout value in microseconds. The valid range of the
1418 * input is [0, 2700000] . A setting of 0 is allowed and results in no
1419 * interrupt coalescing timeout.
1421 * Indicate if the user successfully set the interrupt coalesce parameters.
1422 * SCI_SUCCESS The user successfully updated the interrutp coalescence.
1423 * SCI_FAILURE_INVALID_PARAMETER_VALUE The user input value is out of range.
1425 static enum sci_status
scic_controller_set_interrupt_coalescence(
1426 struct scic_sds_controller
*scic_controller
,
1427 u32 coalesce_number
,
1428 u32 coalesce_timeout
)
1430 u8 timeout_encode
= 0;
1434 /* Check if the input parameters fall in the range. */
1435 if (coalesce_number
> INTERRUPT_COALESCE_NUMBER_MAX
)
1436 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
1439 * Defined encoding for interrupt coalescing timeout:
1440 * Value Min Max Units
1441 * ----- --- --- -----
1471 * Others Undefined */
1474 * Use the table above to decide the encode of interrupt coalescing timeout
1475 * value for register writing. */
1476 if (coalesce_timeout
== 0)
1479 /* make the timeout value in unit of (10 ns). */
1480 coalesce_timeout
= coalesce_timeout
* 100;
1481 min
= INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_LOWER_BOUND_NS
/ 10;
1482 max
= INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_UPPER_BOUND_NS
/ 10;
1484 /* get the encode of timeout for register writing. */
1485 for (timeout_encode
= INTERRUPT_COALESCE_TIMEOUT_ENCODE_MIN
;
1486 timeout_encode
<= INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX
;
1488 if (min
<= coalesce_timeout
&& max
> coalesce_timeout
)
1490 else if (coalesce_timeout
>= max
&& coalesce_timeout
< min
* 2
1491 && coalesce_timeout
<= INTERRUPT_COALESCE_TIMEOUT_MAX_US
* 100) {
1492 if ((coalesce_timeout
- max
) < (2 * min
- coalesce_timeout
))
1504 if (timeout_encode
== INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX
+ 1)
1505 /* the value is out of range. */
1506 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
1509 writel(SMU_ICC_GEN_VAL(NUMBER
, coalesce_number
) |
1510 SMU_ICC_GEN_VAL(TIMER
, timeout_encode
),
1511 &scic_controller
->smu_registers
->interrupt_coalesce_control
);
1514 scic_controller
->interrupt_coalesce_number
= (u16
)coalesce_number
;
1515 scic_controller
->interrupt_coalesce_timeout
= coalesce_timeout
/ 100;
1521 static void scic_sds_controller_ready_state_enter(void *object
)
1523 struct scic_sds_controller
*scic
= object
;
1525 /* set the default interrupt coalescence number and timeout value. */
1526 scic_controller_set_interrupt_coalescence(scic
, 0x10, 250);
1529 static void scic_sds_controller_ready_state_exit(void *object
)
1531 struct scic_sds_controller
*scic
= object
;
1533 /* disable interrupt coalescence. */
1534 scic_controller_set_interrupt_coalescence(scic
, 0, 0);
1537 static enum sci_status
scic_sds_controller_stop_phys(struct scic_sds_controller
*scic
)
1540 enum sci_status status
;
1541 enum sci_status phy_status
;
1542 struct isci_host
*ihost
= scic_to_ihost(scic
);
1544 status
= SCI_SUCCESS
;
1546 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1547 phy_status
= scic_sds_phy_stop(&ihost
->phys
[index
].sci
);
1549 if (phy_status
!= SCI_SUCCESS
&&
1550 phy_status
!= SCI_FAILURE_INVALID_STATE
) {
1551 status
= SCI_FAILURE
;
1553 dev_warn(scic_to_dev(scic
),
1554 "%s: Controller stop operation failed to stop "
1555 "phy %d because of status %d.\n",
1557 ihost
->phys
[index
].sci
.phy_index
, phy_status
);
1564 static enum sci_status
scic_sds_controller_stop_ports(struct scic_sds_controller
*scic
)
1567 enum sci_status port_status
;
1568 enum sci_status status
= SCI_SUCCESS
;
1569 struct isci_host
*ihost
= scic_to_ihost(scic
);
1571 for (index
= 0; index
< scic
->logical_port_entries
; index
++) {
1572 struct scic_sds_port
*sci_port
= &ihost
->ports
[index
].sci
;
1573 scic_sds_port_handler_t stop
;
1575 stop
= sci_port
->state_handlers
->stop_handler
;
1576 port_status
= stop(sci_port
);
1578 if ((port_status
!= SCI_SUCCESS
) &&
1579 (port_status
!= SCI_FAILURE_INVALID_STATE
)) {
1580 status
= SCI_FAILURE
;
1582 dev_warn(scic_to_dev(scic
),
1583 "%s: Controller stop operation failed to "
1584 "stop port %d because of status %d.\n",
1586 sci_port
->logical_port_index
,
1594 static enum sci_status
scic_sds_controller_stop_devices(struct scic_sds_controller
*scic
)
1597 enum sci_status status
;
1598 enum sci_status device_status
;
1600 status
= SCI_SUCCESS
;
1602 for (index
= 0; index
< scic
->remote_node_entries
; index
++) {
1603 if (scic
->device_table
[index
] != NULL
) {
1604 /* / @todo What timeout value do we want to provide to this request? */
1605 device_status
= scic_remote_device_stop(scic
->device_table
[index
], 0);
1607 if ((device_status
!= SCI_SUCCESS
) &&
1608 (device_status
!= SCI_FAILURE_INVALID_STATE
)) {
1609 dev_warn(scic_to_dev(scic
),
1610 "%s: Controller stop operation failed "
1611 "to stop device 0x%p because of "
1614 scic
->device_table
[index
], device_status
);
1622 static void scic_sds_controller_stopping_state_enter(void *object
)
1624 struct scic_sds_controller
*scic
= object
;
1626 /* Stop all of the components for this controller */
1627 scic_sds_controller_stop_phys(scic
);
1628 scic_sds_controller_stop_ports(scic
);
1629 scic_sds_controller_stop_devices(scic
);
1632 static void scic_sds_controller_stopping_state_exit(void *object
)
1634 struct scic_sds_controller
*scic
= object
;
1636 isci_timer_stop(scic
->timeout_timer
);
1641 * scic_sds_controller_reset_hardware() -
1643 * This method will reset the controller hardware.
1645 static void scic_sds_controller_reset_hardware(struct scic_sds_controller
*scic
)
1647 /* Disable interrupts so we dont take any spurious interrupts */
1648 scic_controller_disable_interrupts(scic
);
1651 writel(0xFFFFFFFF, &scic
->smu_registers
->soft_reset_control
);
1653 /* Delay for 1ms to before clearing the CQP and UFQPR. */
1656 /* The write to the CQGR clears the CQP */
1657 writel(0x00000000, &scic
->smu_registers
->completion_queue_get
);
1659 /* The write to the UFQGP clears the UFQPR */
1660 writel(0, &scic
->scu_registers
->sdma
.unsolicited_frame_get_pointer
);
1663 static void scic_sds_controller_resetting_state_enter(void *object
)
1665 struct scic_sds_controller
*scic
= object
;
1667 scic_sds_controller_reset_hardware(scic
);
1668 sci_base_state_machine_change_state(&scic
->state_machine
,
1669 SCI_BASE_CONTROLLER_STATE_RESET
);
1672 static const struct sci_base_state scic_sds_controller_state_table
[] = {
1673 [SCI_BASE_CONTROLLER_STATE_INITIAL
] = {
1674 .enter_state
= scic_sds_controller_initial_state_enter
,
1676 [SCI_BASE_CONTROLLER_STATE_RESET
] = {},
1677 [SCI_BASE_CONTROLLER_STATE_INITIALIZING
] = {},
1678 [SCI_BASE_CONTROLLER_STATE_INITIALIZED
] = {},
1679 [SCI_BASE_CONTROLLER_STATE_STARTING
] = {
1680 .exit_state
= scic_sds_controller_starting_state_exit
,
1682 [SCI_BASE_CONTROLLER_STATE_READY
] = {
1683 .enter_state
= scic_sds_controller_ready_state_enter
,
1684 .exit_state
= scic_sds_controller_ready_state_exit
,
1686 [SCI_BASE_CONTROLLER_STATE_RESETTING
] = {
1687 .enter_state
= scic_sds_controller_resetting_state_enter
,
1689 [SCI_BASE_CONTROLLER_STATE_STOPPING
] = {
1690 .enter_state
= scic_sds_controller_stopping_state_enter
,
1691 .exit_state
= scic_sds_controller_stopping_state_exit
,
1693 [SCI_BASE_CONTROLLER_STATE_STOPPED
] = {},
1694 [SCI_BASE_CONTROLLER_STATE_FAILED
] = {}
1697 static void scic_sds_controller_set_default_config_parameters(struct scic_sds_controller
*scic
)
1699 /* these defaults are overridden by the platform / firmware */
1700 struct isci_host
*ihost
= scic_to_ihost(scic
);
1703 /* Default to APC mode. */
1704 scic
->oem_parameters
.sds1
.controller
.mode_type
= SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE
;
1706 /* Default to APC mode. */
1707 scic
->oem_parameters
.sds1
.controller
.max_concurrent_dev_spin_up
= 1;
1709 /* Default to no SSC operation. */
1710 scic
->oem_parameters
.sds1
.controller
.do_enable_ssc
= false;
1712 /* Initialize all of the port parameter information to narrow ports. */
1713 for (index
= 0; index
< SCI_MAX_PORTS
; index
++) {
1714 scic
->oem_parameters
.sds1
.ports
[index
].phy_mask
= 0;
1717 /* Initialize all of the phy parameter information. */
1718 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1719 /* Default to 6G (i.e. Gen 3) for now. */
1720 scic
->user_parameters
.sds1
.phys
[index
].max_speed_generation
= 3;
1722 /* the frequencies cannot be 0 */
1723 scic
->user_parameters
.sds1
.phys
[index
].align_insertion_frequency
= 0x7f;
1724 scic
->user_parameters
.sds1
.phys
[index
].in_connection_align_insertion_frequency
= 0xff;
1725 scic
->user_parameters
.sds1
.phys
[index
].notify_enable_spin_up_insertion_frequency
= 0x33;
1728 * Previous Vitesse based expanders had a arbitration issue that
1729 * is worked around by having the upper 32-bits of SAS address
1730 * with a value greater then the Vitesse company identifier.
1731 * Hence, usage of 0x5FCFFFFF. */
1732 scic
->oem_parameters
.sds1
.phys
[index
].sas_address
.low
= 0x1 + ihost
->id
;
1733 scic
->oem_parameters
.sds1
.phys
[index
].sas_address
.high
= 0x5FCFFFFF;
1736 scic
->user_parameters
.sds1
.stp_inactivity_timeout
= 5;
1737 scic
->user_parameters
.sds1
.ssp_inactivity_timeout
= 5;
1738 scic
->user_parameters
.sds1
.stp_max_occupancy_timeout
= 5;
1739 scic
->user_parameters
.sds1
.ssp_max_occupancy_timeout
= 20;
1740 scic
->user_parameters
.sds1
.no_outbound_task_timeout
= 20;
1746 * scic_controller_construct() - This method will attempt to construct a
1747 * controller object utilizing the supplied parameter information.
1748 * @c: This parameter specifies the controller to be constructed.
1749 * @scu_base: mapped base address of the scu registers
1750 * @smu_base: mapped base address of the smu registers
1752 * Indicate if the controller was successfully constructed or if it failed in
1753 * some way. SCI_SUCCESS This value is returned if the controller was
1754 * successfully constructed. SCI_WARNING_TIMER_CONFLICT This value is returned
1755 * if the interrupt coalescence timer may cause SAS compliance issues for SMP
1756 * Target mode response processing. SCI_FAILURE_UNSUPPORTED_CONTROLLER_TYPE
1757 * This value is returned if the controller does not support the supplied type.
1758 * SCI_FAILURE_UNSUPPORTED_INIT_DATA_VERSION This value is returned if the
1759 * controller does not support the supplied initialization data version.
1761 static enum sci_status
scic_controller_construct(struct scic_sds_controller
*scic
,
1762 void __iomem
*scu_base
,
1763 void __iomem
*smu_base
)
1765 struct isci_host
*ihost
= scic_to_ihost(scic
);
1768 sci_base_state_machine_construct(&scic
->state_machine
,
1769 scic
, scic_sds_controller_state_table
,
1770 SCI_BASE_CONTROLLER_STATE_INITIAL
);
1772 sci_base_state_machine_start(&scic
->state_machine
);
1774 scic
->scu_registers
= scu_base
;
1775 scic
->smu_registers
= smu_base
;
1777 scic_sds_port_configuration_agent_construct(&scic
->port_agent
);
1779 /* Construct the ports for this controller */
1780 for (i
= 0; i
< SCI_MAX_PORTS
; i
++)
1781 scic_sds_port_construct(&ihost
->ports
[i
].sci
, i
, scic
);
1782 scic_sds_port_construct(&ihost
->ports
[i
].sci
, SCIC_SDS_DUMMY_PORT
, scic
);
1784 /* Construct the phys for this controller */
1785 for (i
= 0; i
< SCI_MAX_PHYS
; i
++) {
1786 /* Add all the PHYs to the dummy port */
1787 scic_sds_phy_construct(&ihost
->phys
[i
].sci
,
1788 &ihost
->ports
[SCI_MAX_PORTS
].sci
, i
);
1791 scic
->invalid_phy_mask
= 0;
1793 /* Set the default maximum values */
1794 scic
->completion_event_entries
= SCU_EVENT_COUNT
;
1795 scic
->completion_queue_entries
= SCU_COMPLETION_QUEUE_COUNT
;
1796 scic
->remote_node_entries
= SCI_MAX_REMOTE_DEVICES
;
1797 scic
->logical_port_entries
= SCI_MAX_PORTS
;
1798 scic
->task_context_entries
= SCU_IO_REQUEST_COUNT
;
1799 scic
->uf_control
.buffers
.count
= SCU_UNSOLICITED_FRAME_COUNT
;
1800 scic
->uf_control
.address_table
.count
= SCU_UNSOLICITED_FRAME_COUNT
;
1802 /* Initialize the User and OEM parameters to default values. */
1803 scic_sds_controller_set_default_config_parameters(scic
);
1805 return scic_controller_reset(scic
);
1808 int scic_oem_parameters_validate(struct scic_sds_oem_params
*oem
)
1812 for (i
= 0; i
< SCI_MAX_PORTS
; i
++)
1813 if (oem
->ports
[i
].phy_mask
> SCIC_SDS_PARM_PHY_MASK_MAX
)
1816 for (i
= 0; i
< SCI_MAX_PHYS
; i
++)
1817 if (oem
->phys
[i
].sas_address
.high
== 0 &&
1818 oem
->phys
[i
].sas_address
.low
== 0)
1821 if (oem
->controller
.mode_type
== SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE
) {
1822 for (i
= 0; i
< SCI_MAX_PHYS
; i
++)
1823 if (oem
->ports
[i
].phy_mask
!= 0)
1825 } else if (oem
->controller
.mode_type
== SCIC_PORT_MANUAL_CONFIGURATION_MODE
) {
1828 for (i
= 0; i
< SCI_MAX_PHYS
; i
++)
1829 phy_mask
|= oem
->ports
[i
].phy_mask
;
1836 if (oem
->controller
.max_concurrent_dev_spin_up
> MAX_CONCURRENT_DEVICE_SPIN_UP_COUNT
)
1842 static enum sci_status
scic_oem_parameters_set(struct scic_sds_controller
*scic
,
1843 union scic_oem_parameters
*scic_parms
)
1845 u32 state
= scic
->state_machine
.current_state_id
;
1847 if (state
== SCI_BASE_CONTROLLER_STATE_RESET
||
1848 state
== SCI_BASE_CONTROLLER_STATE_INITIALIZING
||
1849 state
== SCI_BASE_CONTROLLER_STATE_INITIALIZED
) {
1851 if (scic_oem_parameters_validate(&scic_parms
->sds1
))
1852 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
1853 scic
->oem_parameters
.sds1
= scic_parms
->sds1
;
1858 return SCI_FAILURE_INVALID_STATE
;
1861 void scic_oem_parameters_get(
1862 struct scic_sds_controller
*scic
,
1863 union scic_oem_parameters
*scic_parms
)
1865 memcpy(scic_parms
, (&scic
->oem_parameters
), sizeof(*scic_parms
));
1868 static void scic_sds_controller_timeout_handler(void *_scic
)
1870 struct scic_sds_controller
*scic
= _scic
;
1871 struct isci_host
*ihost
= scic_to_ihost(scic
);
1872 struct sci_base_state_machine
*sm
= &scic
->state_machine
;
1874 if (sm
->current_state_id
== SCI_BASE_CONTROLLER_STATE_STARTING
)
1875 scic_sds_controller_transition_to_ready(scic
, SCI_FAILURE_TIMEOUT
);
1876 else if (sm
->current_state_id
== SCI_BASE_CONTROLLER_STATE_STOPPING
) {
1877 sci_base_state_machine_change_state(sm
, SCI_BASE_CONTROLLER_STATE_FAILED
);
1878 isci_host_stop_complete(ihost
, SCI_FAILURE_TIMEOUT
);
1879 } else /* / @todo Now what do we want to do in this case? */
1880 dev_err(scic_to_dev(scic
),
1881 "%s: Controller timer fired when controller was not "
1882 "in a state being timed.\n",
1886 static enum sci_status
scic_sds_controller_initialize_phy_startup(struct scic_sds_controller
*scic
)
1888 struct isci_host
*ihost
= scic_to_ihost(scic
);
1890 scic
->phy_startup_timer
= isci_timer_create(ihost
,
1892 scic_sds_controller_phy_startup_timeout_handler
);
1894 if (scic
->phy_startup_timer
== NULL
)
1895 return SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1897 scic
->next_phy_to_start
= 0;
1898 scic
->phy_startup_timer_pending
= false;
1904 static void scic_sds_controller_power_control_timer_start(struct scic_sds_controller
*scic
)
1906 isci_timer_start(scic
->power_control
.timer
,
1907 SCIC_SDS_CONTROLLER_POWER_CONTROL_INTERVAL
);
1909 scic
->power_control
.timer_started
= true;
1912 static void scic_sds_controller_power_control_timer_stop(struct scic_sds_controller
*scic
)
1914 if (scic
->power_control
.timer_started
) {
1915 isci_timer_stop(scic
->power_control
.timer
);
1916 scic
->power_control
.timer_started
= false;
1920 static void scic_sds_controller_power_control_timer_restart(struct scic_sds_controller
*scic
)
1922 scic_sds_controller_power_control_timer_stop(scic
);
1923 scic_sds_controller_power_control_timer_start(scic
);
1926 static void scic_sds_controller_power_control_timer_handler(
1929 struct scic_sds_controller
*scic
;
1931 scic
= (struct scic_sds_controller
*)controller
;
1933 scic
->power_control
.phys_granted_power
= 0;
1935 if (scic
->power_control
.phys_waiting
== 0) {
1936 scic
->power_control
.timer_started
= false;
1938 struct scic_sds_phy
*sci_phy
= NULL
;
1943 && (scic
->power_control
.phys_waiting
!= 0);
1945 if (scic
->power_control
.requesters
[i
] != NULL
) {
1946 if (scic
->power_control
.phys_granted_power
<
1947 scic
->oem_parameters
.sds1
.controller
.max_concurrent_dev_spin_up
) {
1948 sci_phy
= scic
->power_control
.requesters
[i
];
1949 scic
->power_control
.requesters
[i
] = NULL
;
1950 scic
->power_control
.phys_waiting
--;
1951 scic
->power_control
.phys_granted_power
++;
1952 scic_sds_phy_consume_power_handler(sci_phy
);
1960 * It doesn't matter if the power list is empty, we need to start the
1961 * timer in case another phy becomes ready.
1963 scic_sds_controller_power_control_timer_start(scic
);
1968 * This method inserts the phy in the stagger spinup control queue.
1973 void scic_sds_controller_power_control_queue_insert(
1974 struct scic_sds_controller
*scic
,
1975 struct scic_sds_phy
*sci_phy
)
1977 BUG_ON(sci_phy
== NULL
);
1979 if (scic
->power_control
.phys_granted_power
<
1980 scic
->oem_parameters
.sds1
.controller
.max_concurrent_dev_spin_up
) {
1981 scic
->power_control
.phys_granted_power
++;
1982 scic_sds_phy_consume_power_handler(sci_phy
);
1985 * stop and start the power_control timer. When the timer fires, the
1986 * no_of_phys_granted_power will be set to 0
1988 scic_sds_controller_power_control_timer_restart(scic
);
1990 /* Add the phy in the waiting list */
1991 scic
->power_control
.requesters
[sci_phy
->phy_index
] = sci_phy
;
1992 scic
->power_control
.phys_waiting
++;
1997 * This method removes the phy from the stagger spinup control queue.
2002 void scic_sds_controller_power_control_queue_remove(
2003 struct scic_sds_controller
*scic
,
2004 struct scic_sds_phy
*sci_phy
)
2006 BUG_ON(sci_phy
== NULL
);
2008 if (scic
->power_control
.requesters
[sci_phy
->phy_index
] != NULL
) {
2009 scic
->power_control
.phys_waiting
--;
2012 scic
->power_control
.requesters
[sci_phy
->phy_index
] = NULL
;
2015 #define AFE_REGISTER_WRITE_DELAY 10
2017 /* Initialize the AFE for this phy index. We need to read the AFE setup from
2018 * the OEM parameters
2020 static void scic_sds_controller_afe_initialization(struct scic_sds_controller
*scic
)
2022 const struct scic_sds_oem_params
*oem
= &scic
->oem_parameters
.sds1
;
2026 /* Clear DFX Status registers */
2027 writel(0x0081000f, &scic
->scu_registers
->afe
.afe_dfx_master_control0
);
2028 udelay(AFE_REGISTER_WRITE_DELAY
);
2031 /* PM Rx Equalization Save, PM SPhy Rx Acknowledgement
2032 * Timer, PM Stagger Timer */
2033 writel(0x0007BFFF, &scic
->scu_registers
->afe
.afe_pmsn_master_control2
);
2034 udelay(AFE_REGISTER_WRITE_DELAY
);
2037 /* Configure bias currents to normal */
2039 writel(0x00005500, &scic
->scu_registers
->afe
.afe_bias_control
);
2041 writel(0x00005A00, &scic
->scu_registers
->afe
.afe_bias_control
);
2043 writel(0x00005F00, &scic
->scu_registers
->afe
.afe_bias_control
);
2045 udelay(AFE_REGISTER_WRITE_DELAY
);
2049 writel(0x80040A08, &scic
->scu_registers
->afe
.afe_pll_control0
);
2051 writel(0x80040908, &scic
->scu_registers
->afe
.afe_pll_control0
);
2053 udelay(AFE_REGISTER_WRITE_DELAY
);
2055 /* Wait for the PLL to lock */
2057 afe_status
= readl(&scic
->scu_registers
->afe
.afe_common_block_status
);
2058 udelay(AFE_REGISTER_WRITE_DELAY
);
2059 } while ((afe_status
& 0x00001000) == 0);
2061 if (is_a0() || is_a2()) {
2062 /* Shorten SAS SNW lock time (RxLock timer value from 76 us to 50 us) */
2063 writel(0x7bcc96ad, &scic
->scu_registers
->afe
.afe_pmsn_master_control0
);
2064 udelay(AFE_REGISTER_WRITE_DELAY
);
2067 for (phy_id
= 0; phy_id
< SCI_MAX_PHYS
; phy_id
++) {
2068 const struct sci_phy_oem_params
*oem_phy
= &oem
->phys
[phy_id
];
2071 /* Configure transmitter SSC parameters */
2072 writel(0x00030000, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_tx_ssc_control
);
2073 udelay(AFE_REGISTER_WRITE_DELAY
);
2076 * All defaults, except the Receive Word Alignament/Comma Detect
2077 * Enable....(0xe800) */
2078 writel(0x00004512, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_xcvr_control0
);
2079 udelay(AFE_REGISTER_WRITE_DELAY
);
2081 writel(0x0050100F, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_xcvr_control1
);
2082 udelay(AFE_REGISTER_WRITE_DELAY
);
2086 * Power up TX and RX out from power down (PWRDNTX and PWRDNRX)
2087 * & increase TX int & ext bias 20%....(0xe85c) */
2089 writel(0x000003D4, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_channel_control
);
2091 writel(0x000003F0, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_channel_control
);
2093 /* Power down TX and RX (PWRDNTX and PWRDNRX) */
2094 writel(0x000003d7, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_channel_control
);
2095 udelay(AFE_REGISTER_WRITE_DELAY
);
2098 * Power up TX and RX out from power down (PWRDNTX and PWRDNRX)
2099 * & increase TX int & ext bias 20%....(0xe85c) */
2100 writel(0x000003d4, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_channel_control
);
2102 udelay(AFE_REGISTER_WRITE_DELAY
);
2104 if (is_a0() || is_a2()) {
2105 /* Enable TX equalization (0xe824) */
2106 writel(0x00040000, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_tx_control
);
2107 udelay(AFE_REGISTER_WRITE_DELAY
);
2111 * RDPI=0x0(RX Power On), RXOOBDETPDNC=0x0, TPD=0x0(TX Power On),
2112 * RDD=0x0(RX Detect Enabled) ....(0xe800) */
2113 writel(0x00004100, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_xcvr_control0
);
2114 udelay(AFE_REGISTER_WRITE_DELAY
);
2116 /* Leave DFE/FFE on */
2118 writel(0x3F09983F, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_rx_ssc_control0
);
2120 writel(0x3F11103F, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_rx_ssc_control0
);
2122 writel(0x3F11103F, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_rx_ssc_control0
);
2123 udelay(AFE_REGISTER_WRITE_DELAY
);
2124 /* Enable TX equalization (0xe824) */
2125 writel(0x00040000, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_tx_control
);
2127 udelay(AFE_REGISTER_WRITE_DELAY
);
2129 writel(oem_phy
->afe_tx_amp_control0
,
2130 &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_tx_amp_control0
);
2131 udelay(AFE_REGISTER_WRITE_DELAY
);
2133 writel(oem_phy
->afe_tx_amp_control1
,
2134 &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_tx_amp_control1
);
2135 udelay(AFE_REGISTER_WRITE_DELAY
);
2137 writel(oem_phy
->afe_tx_amp_control2
,
2138 &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_tx_amp_control2
);
2139 udelay(AFE_REGISTER_WRITE_DELAY
);
2141 writel(oem_phy
->afe_tx_amp_control3
,
2142 &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_tx_amp_control3
);
2143 udelay(AFE_REGISTER_WRITE_DELAY
);
2146 /* Transfer control to the PEs */
2147 writel(0x00010f00, &scic
->scu_registers
->afe
.afe_dfx_master_control0
);
2148 udelay(AFE_REGISTER_WRITE_DELAY
);
2151 static enum sci_status
scic_controller_set_mode(struct scic_sds_controller
*scic
,
2152 enum sci_controller_mode operating_mode
)
2154 enum sci_status status
= SCI_SUCCESS
;
2156 if ((scic
->state_machine
.current_state_id
==
2157 SCI_BASE_CONTROLLER_STATE_INITIALIZING
) ||
2158 (scic
->state_machine
.current_state_id
==
2159 SCI_BASE_CONTROLLER_STATE_INITIALIZED
)) {
2160 switch (operating_mode
) {
2161 case SCI_MODE_SPEED
:
2162 scic
->remote_node_entries
= SCI_MAX_REMOTE_DEVICES
;
2163 scic
->task_context_entries
= SCU_IO_REQUEST_COUNT
;
2164 scic
->uf_control
.buffers
.count
=
2165 SCU_UNSOLICITED_FRAME_COUNT
;
2166 scic
->completion_event_entries
= SCU_EVENT_COUNT
;
2167 scic
->completion_queue_entries
=
2168 SCU_COMPLETION_QUEUE_COUNT
;
2172 scic
->remote_node_entries
= SCI_MIN_REMOTE_DEVICES
;
2173 scic
->task_context_entries
= SCI_MIN_IO_REQUESTS
;
2174 scic
->uf_control
.buffers
.count
=
2175 SCU_MIN_UNSOLICITED_FRAMES
;
2176 scic
->completion_event_entries
= SCU_MIN_EVENTS
;
2177 scic
->completion_queue_entries
=
2178 SCU_MIN_COMPLETION_QUEUE_ENTRIES
;
2182 status
= SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2186 status
= SCI_FAILURE_INVALID_STATE
;
2191 static void scic_sds_controller_initialize_power_control(struct scic_sds_controller
*scic
)
2193 struct isci_host
*ihost
= scic_to_ihost(scic
);
2194 scic
->power_control
.timer
= isci_timer_create(ihost
,
2196 scic_sds_controller_power_control_timer_handler
);
2198 memset(scic
->power_control
.requesters
, 0,
2199 sizeof(scic
->power_control
.requesters
));
2201 scic
->power_control
.phys_waiting
= 0;
2202 scic
->power_control
.phys_granted_power
= 0;
2205 static enum sci_status
scic_controller_initialize(struct scic_sds_controller
*scic
)
2207 struct sci_base_state_machine
*sm
= &scic
->state_machine
;
2208 enum sci_status result
= SCI_SUCCESS
;
2209 struct isci_host
*ihost
= scic_to_ihost(scic
);
2212 if (scic
->state_machine
.current_state_id
!=
2213 SCI_BASE_CONTROLLER_STATE_RESET
) {
2214 dev_warn(scic_to_dev(scic
),
2215 "SCIC Controller initialize operation requested "
2216 "in invalid state\n");
2217 return SCI_FAILURE_INVALID_STATE
;
2220 sci_base_state_machine_change_state(sm
, SCI_BASE_CONTROLLER_STATE_INITIALIZING
);
2222 scic
->timeout_timer
= isci_timer_create(ihost
, scic
,
2223 scic_sds_controller_timeout_handler
);
2225 scic_sds_controller_initialize_phy_startup(scic
);
2227 scic_sds_controller_initialize_power_control(scic
);
2230 * There is nothing to do here for B0 since we do not have to
2231 * program the AFE registers.
2232 * / @todo The AFE settings are supposed to be correct for the B0 but
2233 * / presently they seem to be wrong. */
2234 scic_sds_controller_afe_initialization(scic
);
2236 if (result
== SCI_SUCCESS
) {
2240 /* Take the hardware out of reset */
2241 writel(0, &scic
->smu_registers
->soft_reset_control
);
2244 * / @todo Provide meaningfull error code for hardware failure
2245 * result = SCI_FAILURE_CONTROLLER_HARDWARE; */
2246 result
= SCI_FAILURE
;
2247 terminate_loop
= 100;
2249 while (terminate_loop
-- && (result
!= SCI_SUCCESS
)) {
2250 /* Loop until the hardware reports success */
2251 udelay(SCU_CONTEXT_RAM_INIT_STALL_TIME
);
2252 status
= readl(&scic
->smu_registers
->control_status
);
2254 if ((status
& SCU_RAM_INIT_COMPLETED
) ==
2255 SCU_RAM_INIT_COMPLETED
)
2256 result
= SCI_SUCCESS
;
2260 if (result
== SCI_SUCCESS
) {
2261 u32 max_supported_ports
;
2262 u32 max_supported_devices
;
2263 u32 max_supported_io_requests
;
2264 u32 device_context_capacity
;
2267 * Determine what are the actaul device capacities that the
2268 * hardware will support */
2269 device_context_capacity
=
2270 readl(&scic
->smu_registers
->device_context_capacity
);
2273 max_supported_ports
= smu_dcc_get_max_ports(device_context_capacity
);
2274 max_supported_devices
= smu_dcc_get_max_remote_node_context(device_context_capacity
);
2275 max_supported_io_requests
= smu_dcc_get_max_task_context(device_context_capacity
);
2278 * Make all PEs that are unassigned match up with the
2281 for (index
= 0; index
< max_supported_ports
; index
++) {
2282 struct scu_port_task_scheduler_group_registers __iomem
2283 *ptsg
= &scic
->scu_registers
->peg0
.ptsg
;
2285 writel(index
, &ptsg
->protocol_engine
[index
]);
2288 /* Record the smaller of the two capacity values */
2289 scic
->logical_port_entries
=
2290 min(max_supported_ports
, scic
->logical_port_entries
);
2292 scic
->task_context_entries
=
2293 min(max_supported_io_requests
,
2294 scic
->task_context_entries
);
2296 scic
->remote_node_entries
=
2297 min(max_supported_devices
, scic
->remote_node_entries
);
2300 * Now that we have the correct hardware reported minimum values
2301 * build the MDL for the controller. Default to a performance
2304 scic_controller_set_mode(scic
, SCI_MODE_SPEED
);
2307 /* Initialize hardware PCI Relaxed ordering in DMA engines */
2308 if (result
== SCI_SUCCESS
) {
2309 u32 dma_configuration
;
2311 /* Configure the payload DMA */
2313 readl(&scic
->scu_registers
->sdma
.pdma_configuration
);
2314 dma_configuration
|=
2315 SCU_PDMACR_GEN_BIT(PCI_RELAXED_ORDERING_ENABLE
);
2316 writel(dma_configuration
,
2317 &scic
->scu_registers
->sdma
.pdma_configuration
);
2319 /* Configure the control DMA */
2321 readl(&scic
->scu_registers
->sdma
.cdma_configuration
);
2322 dma_configuration
|=
2323 SCU_CDMACR_GEN_BIT(PCI_RELAXED_ORDERING_ENABLE
);
2324 writel(dma_configuration
,
2325 &scic
->scu_registers
->sdma
.cdma_configuration
);
2329 * Initialize the PHYs before the PORTs because the PHY registers
2330 * are accessed during the port initialization.
2332 if (result
== SCI_SUCCESS
) {
2333 /* Initialize the phys */
2335 (result
== SCI_SUCCESS
) && (index
< SCI_MAX_PHYS
);
2337 result
= scic_sds_phy_initialize(
2338 &ihost
->phys
[index
].sci
,
2339 &scic
->scu_registers
->peg0
.pe
[index
].tl
,
2340 &scic
->scu_registers
->peg0
.pe
[index
].ll
);
2344 if (result
== SCI_SUCCESS
) {
2345 /* Initialize the logical ports */
2347 (index
< scic
->logical_port_entries
) &&
2348 (result
== SCI_SUCCESS
);
2350 result
= scic_sds_port_initialize(
2351 &ihost
->ports
[index
].sci
,
2352 &scic
->scu_registers
->peg0
.ptsg
.port
[index
],
2353 &scic
->scu_registers
->peg0
.ptsg
.protocol_engine
,
2354 &scic
->scu_registers
->peg0
.viit
[index
]);
2358 if (result
== SCI_SUCCESS
)
2359 result
= scic_sds_port_configuration_agent_initialize(
2363 /* Advance the controller state machine */
2364 if (result
== SCI_SUCCESS
)
2365 state
= SCI_BASE_CONTROLLER_STATE_INITIALIZED
;
2367 state
= SCI_BASE_CONTROLLER_STATE_FAILED
;
2368 sci_base_state_machine_change_state(sm
, state
);
2373 static enum sci_status
scic_user_parameters_set(
2374 struct scic_sds_controller
*scic
,
2375 union scic_user_parameters
*scic_parms
)
2377 u32 state
= scic
->state_machine
.current_state_id
;
2379 if (state
== SCI_BASE_CONTROLLER_STATE_RESET
||
2380 state
== SCI_BASE_CONTROLLER_STATE_INITIALIZING
||
2381 state
== SCI_BASE_CONTROLLER_STATE_INITIALIZED
) {
2385 * Validate the user parameters. If they are not legal, then
2388 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
2389 struct sci_phy_user_params
*user_phy
;
2391 user_phy
= &scic_parms
->sds1
.phys
[index
];
2393 if (!((user_phy
->max_speed_generation
<=
2394 SCIC_SDS_PARM_MAX_SPEED
) &&
2395 (user_phy
->max_speed_generation
>
2396 SCIC_SDS_PARM_NO_SPEED
)))
2397 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2399 if (user_phy
->in_connection_align_insertion_frequency
<
2401 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2403 if ((user_phy
->in_connection_align_insertion_frequency
<
2405 (user_phy
->align_insertion_frequency
== 0) ||
2407 notify_enable_spin_up_insertion_frequency
==
2409 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2412 if ((scic_parms
->sds1
.stp_inactivity_timeout
== 0) ||
2413 (scic_parms
->sds1
.ssp_inactivity_timeout
== 0) ||
2414 (scic_parms
->sds1
.stp_max_occupancy_timeout
== 0) ||
2415 (scic_parms
->sds1
.ssp_max_occupancy_timeout
== 0) ||
2416 (scic_parms
->sds1
.no_outbound_task_timeout
== 0))
2417 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2419 memcpy(&scic
->user_parameters
, scic_parms
, sizeof(*scic_parms
));
2424 return SCI_FAILURE_INVALID_STATE
;
2427 static int scic_controller_mem_init(struct scic_sds_controller
*scic
)
2429 struct device
*dev
= scic_to_dev(scic
);
2430 dma_addr_t dma_handle
;
2431 enum sci_status result
;
2433 scic
->completion_queue
= dmam_alloc_coherent(dev
,
2434 scic
->completion_queue_entries
* sizeof(u32
),
2435 &dma_handle
, GFP_KERNEL
);
2436 if (!scic
->completion_queue
)
2439 writel(lower_32_bits(dma_handle
),
2440 &scic
->smu_registers
->completion_queue_lower
);
2441 writel(upper_32_bits(dma_handle
),
2442 &scic
->smu_registers
->completion_queue_upper
);
2444 scic
->remote_node_context_table
= dmam_alloc_coherent(dev
,
2445 scic
->remote_node_entries
*
2446 sizeof(union scu_remote_node_context
),
2447 &dma_handle
, GFP_KERNEL
);
2448 if (!scic
->remote_node_context_table
)
2451 writel(lower_32_bits(dma_handle
),
2452 &scic
->smu_registers
->remote_node_context_lower
);
2453 writel(upper_32_bits(dma_handle
),
2454 &scic
->smu_registers
->remote_node_context_upper
);
2456 scic
->task_context_table
= dmam_alloc_coherent(dev
,
2457 scic
->task_context_entries
*
2458 sizeof(struct scu_task_context
),
2459 &dma_handle
, GFP_KERNEL
);
2460 if (!scic
->task_context_table
)
2463 writel(lower_32_bits(dma_handle
),
2464 &scic
->smu_registers
->host_task_table_lower
);
2465 writel(upper_32_bits(dma_handle
),
2466 &scic
->smu_registers
->host_task_table_upper
);
2468 result
= scic_sds_unsolicited_frame_control_construct(scic
);
2473 * Inform the silicon as to the location of the UF headers and
2476 writel(lower_32_bits(scic
->uf_control
.headers
.physical_address
),
2477 &scic
->scu_registers
->sdma
.uf_header_base_address_lower
);
2478 writel(upper_32_bits(scic
->uf_control
.headers
.physical_address
),
2479 &scic
->scu_registers
->sdma
.uf_header_base_address_upper
);
2481 writel(lower_32_bits(scic
->uf_control
.address_table
.physical_address
),
2482 &scic
->scu_registers
->sdma
.uf_address_table_lower
);
2483 writel(upper_32_bits(scic
->uf_control
.address_table
.physical_address
),
2484 &scic
->scu_registers
->sdma
.uf_address_table_upper
);
2489 int isci_host_init(struct isci_host
*isci_host
)
2492 enum sci_status status
;
2493 union scic_oem_parameters oem
;
2494 union scic_user_parameters scic_user_params
;
2495 struct isci_pci_info
*pci_info
= to_pci_info(isci_host
->pdev
);
2497 isci_timer_list_construct(isci_host
);
2499 spin_lock_init(&isci_host
->state_lock
);
2500 spin_lock_init(&isci_host
->scic_lock
);
2501 spin_lock_init(&isci_host
->queue_lock
);
2502 init_waitqueue_head(&isci_host
->eventq
);
2504 isci_host_change_state(isci_host
, isci_starting
);
2505 isci_host
->can_queue
= ISCI_CAN_QUEUE_VAL
;
2507 status
= scic_controller_construct(&isci_host
->sci
, scu_base(isci_host
),
2508 smu_base(isci_host
));
2510 if (status
!= SCI_SUCCESS
) {
2511 dev_err(&isci_host
->pdev
->dev
,
2512 "%s: scic_controller_construct failed - status = %x\n",
2518 isci_host
->sas_ha
.dev
= &isci_host
->pdev
->dev
;
2519 isci_host
->sas_ha
.lldd_ha
= isci_host
;
2522 * grab initial values stored in the controller object for OEM and USER
2525 isci_user_parameters_get(isci_host
, &scic_user_params
);
2526 status
= scic_user_parameters_set(&isci_host
->sci
,
2528 if (status
!= SCI_SUCCESS
) {
2529 dev_warn(&isci_host
->pdev
->dev
,
2530 "%s: scic_user_parameters_set failed\n",
2535 scic_oem_parameters_get(&isci_host
->sci
, &oem
);
2537 /* grab any OEM parameters specified in orom */
2538 if (pci_info
->orom
) {
2539 status
= isci_parse_oem_parameters(&oem
,
2542 if (status
!= SCI_SUCCESS
) {
2543 dev_warn(&isci_host
->pdev
->dev
,
2544 "parsing firmware oem parameters failed\n");
2549 status
= scic_oem_parameters_set(&isci_host
->sci
, &oem
);
2550 if (status
!= SCI_SUCCESS
) {
2551 dev_warn(&isci_host
->pdev
->dev
,
2552 "%s: scic_oem_parameters_set failed\n",
2557 tasklet_init(&isci_host
->completion_tasklet
,
2558 isci_host_completion_routine
, (unsigned long)isci_host
);
2560 INIT_LIST_HEAD(&isci_host
->requests_to_complete
);
2561 INIT_LIST_HEAD(&isci_host
->requests_to_errorback
);
2563 spin_lock_irq(&isci_host
->scic_lock
);
2564 status
= scic_controller_initialize(&isci_host
->sci
);
2565 spin_unlock_irq(&isci_host
->scic_lock
);
2566 if (status
!= SCI_SUCCESS
) {
2567 dev_warn(&isci_host
->pdev
->dev
,
2568 "%s: scic_controller_initialize failed -"
2574 err
= scic_controller_mem_init(&isci_host
->sci
);
2578 isci_host
->dma_pool
= dmam_pool_create(DRV_NAME
, &isci_host
->pdev
->dev
,
2579 sizeof(struct isci_request
),
2580 SLAB_HWCACHE_ALIGN
, 0);
2582 if (!isci_host
->dma_pool
)
2585 for (i
= 0; i
< SCI_MAX_PORTS
; i
++)
2586 isci_port_init(&isci_host
->ports
[i
], isci_host
, i
);
2588 for (i
= 0; i
< SCI_MAX_PHYS
; i
++)
2589 isci_phy_init(&isci_host
->phys
[i
], isci_host
, i
);
2591 for (i
= 0; i
< SCI_MAX_REMOTE_DEVICES
; i
++) {
2592 struct isci_remote_device
*idev
= &isci_host
->devices
[i
];
2594 INIT_LIST_HEAD(&idev
->reqs_in_process
);
2595 INIT_LIST_HEAD(&idev
->node
);
2596 spin_lock_init(&idev
->state_lock
);
2602 void scic_sds_controller_link_up(struct scic_sds_controller
*scic
,
2603 struct scic_sds_port
*port
, struct scic_sds_phy
*phy
)
2605 switch (scic
->state_machine
.current_state_id
) {
2606 case SCI_BASE_CONTROLLER_STATE_STARTING
:
2607 scic_sds_controller_phy_timer_stop(scic
);
2608 scic
->port_agent
.link_up_handler(scic
, &scic
->port_agent
,
2610 scic_sds_controller_start_next_phy(scic
);
2612 case SCI_BASE_CONTROLLER_STATE_READY
:
2613 scic
->port_agent
.link_up_handler(scic
, &scic
->port_agent
,
2617 dev_dbg(scic_to_dev(scic
),
2618 "%s: SCIC Controller linkup event from phy %d in "
2619 "unexpected state %d\n", __func__
, phy
->phy_index
,
2620 scic
->state_machine
.current_state_id
);
2624 void scic_sds_controller_link_down(struct scic_sds_controller
*scic
,
2625 struct scic_sds_port
*port
, struct scic_sds_phy
*phy
)
2627 switch (scic
->state_machine
.current_state_id
) {
2628 case SCI_BASE_CONTROLLER_STATE_STARTING
:
2629 case SCI_BASE_CONTROLLER_STATE_READY
:
2630 scic
->port_agent
.link_down_handler(scic
, &scic
->port_agent
,
2634 dev_dbg(scic_to_dev(scic
),
2635 "%s: SCIC Controller linkdown event from phy %d in "
2636 "unexpected state %d\n",
2639 scic
->state_machine
.current_state_id
);
2644 * This is a helper method to determine if any remote devices on this
2645 * controller are still in the stopping state.
2648 static bool scic_sds_controller_has_remote_devices_stopping(
2649 struct scic_sds_controller
*controller
)
2653 for (index
= 0; index
< controller
->remote_node_entries
; index
++) {
2654 if ((controller
->device_table
[index
] != NULL
) &&
2655 (controller
->device_table
[index
]->state_machine
.current_state_id
2656 == SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
))
2664 * This method is called by the remote device to inform the controller
2665 * object that the remote device has stopped.
2667 void scic_sds_controller_remote_device_stopped(struct scic_sds_controller
*scic
,
2668 struct scic_sds_remote_device
*sci_dev
)
2670 if (scic
->state_machine
.current_state_id
!=
2671 SCI_BASE_CONTROLLER_STATE_STOPPING
) {
2672 dev_dbg(scic_to_dev(scic
),
2673 "SCIC Controller 0x%p remote device stopped event "
2674 "from device 0x%p in unexpected state %d\n",
2676 scic
->state_machine
.current_state_id
);
2680 if (!scic_sds_controller_has_remote_devices_stopping(scic
)) {
2681 sci_base_state_machine_change_state(&scic
->state_machine
,
2682 SCI_BASE_CONTROLLER_STATE_STOPPED
);
2687 * This method will write to the SCU PCP register the request value. The method
2688 * is used to suspend/resume ports, devices, and phys.
2693 void scic_sds_controller_post_request(
2694 struct scic_sds_controller
*scic
,
2697 dev_dbg(scic_to_dev(scic
),
2698 "%s: SCIC Controller 0x%p post request 0x%08x\n",
2703 writel(request
, &scic
->smu_registers
->post_context_port
);
2707 * This method will copy the soft copy of the task context into the physical
2708 * memory accessible by the controller.
2709 * @scic: This parameter specifies the controller for which to copy
2711 * @sci_req: This parameter specifies the request for which the task
2712 * context is being copied.
2714 * After this call is made the SCIC_SDS_IO_REQUEST object will always point to
2715 * the physical memory version of the task context. Thus, all subsequent
2716 * updates to the task context are performed in the TC table (i.e. DMAable
2719 void scic_sds_controller_copy_task_context(
2720 struct scic_sds_controller
*scic
,
2721 struct scic_sds_request
*sci_req
)
2723 struct scu_task_context
*task_context_buffer
;
2725 task_context_buffer
= scic_sds_controller_get_task_context_buffer(
2726 scic
, sci_req
->io_tag
);
2728 memcpy(task_context_buffer
,
2729 sci_req
->task_context_buffer
,
2730 offsetof(struct scu_task_context
, sgl_snapshot_ac
));
2733 * Now that the soft copy of the TC has been copied into the TC
2734 * table accessible by the silicon. Thus, any further changes to
2735 * the TC (e.g. TC termination) occur in the appropriate location. */
2736 sci_req
->task_context_buffer
= task_context_buffer
;
2740 * This method returns the task context buffer for the given io tag.
2744 * struct scu_task_context*
2746 struct scu_task_context
*scic_sds_controller_get_task_context_buffer(
2747 struct scic_sds_controller
*scic
,
2750 u16 task_index
= scic_sds_io_tag_get_index(io_tag
);
2752 if (task_index
< scic
->task_context_entries
) {
2753 return &scic
->task_context_table
[task_index
];
2759 struct scic_sds_request
*scic_request_by_tag(struct scic_sds_controller
*scic
,
2765 task_index
= scic_sds_io_tag_get_index(io_tag
);
2767 if (task_index
< scic
->task_context_entries
) {
2768 if (scic
->io_request_table
[task_index
] != NULL
) {
2769 task_sequence
= scic_sds_io_tag_get_sequence(io_tag
);
2771 if (task_sequence
== scic
->io_request_sequence
[task_index
]) {
2772 return scic
->io_request_table
[task_index
];
2781 * This method allocates remote node index and the reserves the remote node
2782 * context space for use. This method can fail if there are no more remote
2783 * node index available.
2784 * @scic: This is the controller object which contains the set of
2785 * free remote node ids
2786 * @sci_dev: This is the device object which is requesting the a remote node
2788 * @node_id: This is the remote node id that is assinged to the device if one
2791 * enum sci_status SCI_FAILURE_OUT_OF_RESOURCES if there are no available remote
2792 * node index available.
2794 enum sci_status
scic_sds_controller_allocate_remote_node_context(
2795 struct scic_sds_controller
*scic
,
2796 struct scic_sds_remote_device
*sci_dev
,
2800 u32 remote_node_count
= scic_sds_remote_device_node_count(sci_dev
);
2802 node_index
= scic_sds_remote_node_table_allocate_remote_node(
2803 &scic
->available_remote_nodes
, remote_node_count
2806 if (node_index
!= SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
) {
2807 scic
->device_table
[node_index
] = sci_dev
;
2809 *node_id
= node_index
;
2814 return SCI_FAILURE_INSUFFICIENT_RESOURCES
;
2818 * This method frees the remote node index back to the available pool. Once
2819 * this is done the remote node context buffer is no longer valid and can
2826 void scic_sds_controller_free_remote_node_context(
2827 struct scic_sds_controller
*scic
,
2828 struct scic_sds_remote_device
*sci_dev
,
2831 u32 remote_node_count
= scic_sds_remote_device_node_count(sci_dev
);
2833 if (scic
->device_table
[node_id
] == sci_dev
) {
2834 scic
->device_table
[node_id
] = NULL
;
2836 scic_sds_remote_node_table_release_remote_node_index(
2837 &scic
->available_remote_nodes
, remote_node_count
, node_id
2843 * This method returns the union scu_remote_node_context for the specified remote
2848 * union scu_remote_node_context*
2850 union scu_remote_node_context
*scic_sds_controller_get_remote_node_context_buffer(
2851 struct scic_sds_controller
*scic
,
2855 (node_id
< scic
->remote_node_entries
)
2856 && (scic
->device_table
[node_id
] != NULL
)
2858 return &scic
->remote_node_context_table
[node_id
];
2866 * @resposne_buffer: This is the buffer into which the D2H register FIS will be
2868 * @frame_header: This is the frame header returned by the hardware.
2869 * @frame_buffer: This is the frame buffer returned by the hardware.
2871 * This method will combind the frame header and frame buffer to create a SATA
2872 * D2H register FIS none
2874 void scic_sds_controller_copy_sata_response(
2875 void *response_buffer
,
2879 memcpy(response_buffer
, frame_header
, sizeof(u32
));
2881 memcpy(response_buffer
+ sizeof(u32
),
2883 sizeof(struct dev_to_host_fis
) - sizeof(u32
));
2887 * This method releases the frame once this is done the frame is available for
2888 * re-use by the hardware. The data contained in the frame header and frame
2889 * buffer is no longer valid. The UF queue get pointer is only updated if UF
2890 * control indicates this is appropriate.
2895 void scic_sds_controller_release_frame(
2896 struct scic_sds_controller
*scic
,
2899 if (scic_sds_unsolicited_frame_control_release_frame(
2900 &scic
->uf_control
, frame_index
) == true)
2901 writel(scic
->uf_control
.get
,
2902 &scic
->scu_registers
->sdma
.unsolicited_frame_get_pointer
);
2906 * scic_controller_start_io() - This method is called by the SCI user to
2907 * send/start an IO request. If the method invocation is successful, then
2908 * the IO request has been queued to the hardware for processing.
2909 * @controller: the handle to the controller object for which to start an IO
2911 * @remote_device: the handle to the remote device object for which to start an
2913 * @io_request: the handle to the io request object to start.
2914 * @io_tag: This parameter specifies a previously allocated IO tag that the
2915 * user desires to be utilized for this request. This parameter is optional.
2916 * The user is allowed to supply SCI_CONTROLLER_INVALID_IO_TAG as the value
2917 * for this parameter.
2919 * - IO tags are a protected resource. It is incumbent upon the SCI Core user
2920 * to ensure that each of the methods that may allocate or free available IO
2921 * tags are handled in a mutually exclusive manner. This method is one of said
2922 * methods requiring proper critical code section protection (e.g. semaphore,
2923 * spin-lock, etc.). - For SATA, the user is required to manage NCQ tags. As a
2924 * result, it is expected the user will have set the NCQ tag field in the host
2925 * to device register FIS prior to calling this method. There is also a
2926 * requirement for the user to call scic_stp_io_set_ncq_tag() prior to invoking
2927 * the scic_controller_start_io() method. scic_controller_allocate_tag() for
2928 * more information on allocating a tag. Indicate if the controller
2929 * successfully started the IO request. SCI_SUCCESS if the IO request was
2930 * successfully started. Determine the failure situations and return values.
2932 enum sci_status
scic_controller_start_io(
2933 struct scic_sds_controller
*scic
,
2934 struct scic_sds_remote_device
*rdev
,
2935 struct scic_sds_request
*req
,
2938 enum sci_status status
;
2940 if (scic
->state_machine
.current_state_id
!=
2941 SCI_BASE_CONTROLLER_STATE_READY
) {
2942 dev_warn(scic_to_dev(scic
), "invalid state to start I/O");
2943 return SCI_FAILURE_INVALID_STATE
;
2946 status
= scic_sds_remote_device_start_io(scic
, rdev
, req
);
2947 if (status
!= SCI_SUCCESS
)
2950 scic
->io_request_table
[scic_sds_io_tag_get_index(req
->io_tag
)] = req
;
2951 scic_sds_controller_post_request(scic
, scic_sds_request_get_post_context(req
));
2956 * scic_controller_terminate_request() - This method is called by the SCI Core
2957 * user to terminate an ongoing (i.e. started) core IO request. This does
2958 * not abort the IO request at the target, but rather removes the IO request
2959 * from the host controller.
2960 * @controller: the handle to the controller object for which to terminate a
2962 * @remote_device: the handle to the remote device object for which to
2963 * terminate a request.
2964 * @request: the handle to the io or task management request object to
2967 * Indicate if the controller successfully began the terminate process for the
2968 * IO request. SCI_SUCCESS if the terminate process was successfully started
2969 * for the request. Determine the failure situations and return values.
2971 enum sci_status
scic_controller_terminate_request(
2972 struct scic_sds_controller
*scic
,
2973 struct scic_sds_remote_device
*rdev
,
2974 struct scic_sds_request
*req
)
2976 enum sci_status status
;
2978 if (scic
->state_machine
.current_state_id
!=
2979 SCI_BASE_CONTROLLER_STATE_READY
) {
2980 dev_warn(scic_to_dev(scic
),
2981 "invalid state to terminate request\n");
2982 return SCI_FAILURE_INVALID_STATE
;
2985 status
= scic_sds_io_request_terminate(req
);
2986 if (status
!= SCI_SUCCESS
)
2990 * Utilize the original post context command and or in the POST_TC_ABORT
2993 scic_sds_controller_post_request(scic
,
2994 scic_sds_request_get_post_context(req
) |
2995 SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT
);
3000 * scic_controller_complete_io() - This method will perform core specific
3001 * completion operations for an IO request. After this method is invoked,
3002 * the user should consider the IO request as invalid until it is properly
3003 * reused (i.e. re-constructed).
3004 * @controller: The handle to the controller object for which to complete the
3006 * @remote_device: The handle to the remote device object for which to complete
3008 * @io_request: the handle to the io request object to complete.
3010 * - IO tags are a protected resource. It is incumbent upon the SCI Core user
3011 * to ensure that each of the methods that may allocate or free available IO
3012 * tags are handled in a mutually exclusive manner. This method is one of said
3013 * methods requiring proper critical code section protection (e.g. semaphore,
3014 * spin-lock, etc.). - If the IO tag for a request was allocated, by the SCI
3015 * Core user, using the scic_controller_allocate_io_tag() method, then it is
3016 * the responsibility of the caller to invoke the scic_controller_free_io_tag()
3017 * method to free the tag (i.e. this method will not free the IO tag). Indicate
3018 * if the controller successfully completed the IO request. SCI_SUCCESS if the
3019 * completion process was successful.
3021 enum sci_status
scic_controller_complete_io(
3022 struct scic_sds_controller
*scic
,
3023 struct scic_sds_remote_device
*rdev
,
3024 struct scic_sds_request
*request
)
3026 enum sci_status status
;
3029 switch (scic
->state_machine
.current_state_id
) {
3030 case SCI_BASE_CONTROLLER_STATE_STOPPING
:
3031 /* XXX: Implement this function */
3033 case SCI_BASE_CONTROLLER_STATE_READY
:
3034 status
= scic_sds_remote_device_complete_io(scic
, rdev
, request
);
3035 if (status
!= SCI_SUCCESS
)
3038 index
= scic_sds_io_tag_get_index(request
->io_tag
);
3039 scic
->io_request_table
[index
] = NULL
;
3042 dev_warn(scic_to_dev(scic
), "invalid state to complete I/O");
3043 return SCI_FAILURE_INVALID_STATE
;
3048 enum sci_status
scic_controller_continue_io(struct scic_sds_request
*sci_req
)
3050 struct scic_sds_controller
*scic
= sci_req
->owning_controller
;
3052 if (scic
->state_machine
.current_state_id
!=
3053 SCI_BASE_CONTROLLER_STATE_READY
) {
3054 dev_warn(scic_to_dev(scic
), "invalid state to continue I/O");
3055 return SCI_FAILURE_INVALID_STATE
;
3058 scic
->io_request_table
[scic_sds_io_tag_get_index(sci_req
->io_tag
)] = sci_req
;
3059 scic_sds_controller_post_request(scic
, scic_sds_request_get_post_context(sci_req
));
3064 * scic_controller_start_task() - This method is called by the SCIC user to
3065 * send/start a framework task management request.
3066 * @controller: the handle to the controller object for which to start the task
3067 * management request.
3068 * @remote_device: the handle to the remote device object for which to start
3069 * the task management request.
3070 * @task_request: the handle to the task request object to start.
3071 * @io_tag: This parameter specifies a previously allocated IO tag that the
3072 * user desires to be utilized for this request. Note this not the io_tag
3073 * of the request being managed. It is to be utilized for the task request
3074 * itself. This parameter is optional. The user is allowed to supply
3075 * SCI_CONTROLLER_INVALID_IO_TAG as the value for this parameter.
3077 * - IO tags are a protected resource. It is incumbent upon the SCI Core user
3078 * to ensure that each of the methods that may allocate or free available IO
3079 * tags are handled in a mutually exclusive manner. This method is one of said
3080 * methods requiring proper critical code section protection (e.g. semaphore,
3081 * spin-lock, etc.). - The user must synchronize this task with completion
3082 * queue processing. If they are not synchronized then it is possible for the
3083 * io requests that are being managed by the task request can complete before
3084 * starting the task request. scic_controller_allocate_tag() for more
3085 * information on allocating a tag. Indicate if the controller successfully
3086 * started the IO request. SCI_TASK_SUCCESS if the task request was
3087 * successfully started. SCI_TASK_FAILURE_REQUIRES_SCSI_ABORT This value is
3088 * returned if there is/are task(s) outstanding that require termination or
3089 * completion before this request can succeed.
3091 enum sci_task_status
scic_controller_start_task(
3092 struct scic_sds_controller
*scic
,
3093 struct scic_sds_remote_device
*rdev
,
3094 struct scic_sds_request
*req
,
3097 enum sci_status status
;
3099 if (scic
->state_machine
.current_state_id
!=
3100 SCI_BASE_CONTROLLER_STATE_READY
) {
3101 dev_warn(scic_to_dev(scic
),
3102 "%s: SCIC Controller starting task from invalid "
3105 return SCI_TASK_FAILURE_INVALID_STATE
;
3108 status
= scic_sds_remote_device_start_task(scic
, rdev
, req
);
3110 case SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS
:
3111 scic
->io_request_table
[scic_sds_io_tag_get_index(req
->io_tag
)] = req
;
3114 * We will let framework know this task request started successfully,
3115 * although core is still woring on starting the request (to post tc when
3120 scic
->io_request_table
[scic_sds_io_tag_get_index(req
->io_tag
)] = req
;
3122 scic_sds_controller_post_request(scic
,
3123 scic_sds_request_get_post_context(req
));
3133 * scic_controller_allocate_io_tag() - This method will allocate a tag from the
3134 * pool of free IO tags. Direct allocation of IO tags by the SCI Core user
3135 * is optional. The scic_controller_start_io() method will allocate an IO
3136 * tag if this method is not utilized and the tag is not supplied to the IO
3137 * construct routine. Direct allocation of IO tags may provide additional
3138 * performance improvements in environments capable of supporting this usage
3139 * model. Additionally, direct allocation of IO tags also provides
3140 * additional flexibility to the SCI Core user. Specifically, the user may
3141 * retain IO tags across the lives of multiple IO requests.
3142 * @controller: the handle to the controller object for which to allocate the
3145 * IO tags are a protected resource. It is incumbent upon the SCI Core user to
3146 * ensure that each of the methods that may allocate or free available IO tags
3147 * are handled in a mutually exclusive manner. This method is one of said
3148 * methods requiring proper critical code section protection (e.g. semaphore,
3149 * spin-lock, etc.). An unsigned integer representing an available IO tag.
3150 * SCI_CONTROLLER_INVALID_IO_TAG This value is returned if there are no
3151 * currently available tags to be allocated. All return other values indicate a
3154 u16
scic_controller_allocate_io_tag(
3155 struct scic_sds_controller
*scic
)
3160 if (!sci_pool_empty(scic
->tci_pool
)) {
3161 sci_pool_get(scic
->tci_pool
, task_context
);
3163 sequence_count
= scic
->io_request_sequence
[task_context
];
3165 return scic_sds_io_tag_construct(sequence_count
, task_context
);
3168 return SCI_CONTROLLER_INVALID_IO_TAG
;
3172 * scic_controller_free_io_tag() - This method will free an IO tag to the pool
3173 * of free IO tags. This method provides the SCI Core user more flexibility
3174 * with regards to IO tags. The user may desire to keep an IO tag after an
3175 * IO request has completed, because they plan on re-using the tag for a
3176 * subsequent IO request. This method is only legal if the tag was
3177 * allocated via scic_controller_allocate_io_tag().
3178 * @controller: This parameter specifies the handle to the controller object
3179 * for which to free/return the tag.
3180 * @io_tag: This parameter represents the tag to be freed to the pool of
3183 * - IO tags are a protected resource. It is incumbent upon the SCI Core user
3184 * to ensure that each of the methods that may allocate or free available IO
3185 * tags are handled in a mutually exclusive manner. This method is one of said
3186 * methods requiring proper critical code section protection (e.g. semaphore,
3187 * spin-lock, etc.). - If the IO tag for a request was allocated, by the SCI
3188 * Core user, using the scic_controller_allocate_io_tag() method, then it is
3189 * the responsibility of the caller to invoke this method to free the tag. This
3190 * method returns an indication of whether the tag was successfully put back
3191 * (freed) to the pool of available tags. SCI_SUCCESS This return value
3192 * indicates the tag was successfully placed into the pool of available IO
3193 * tags. SCI_FAILURE_INVALID_IO_TAG This value is returned if the supplied tag
3194 * is not a valid IO tag value.
3196 enum sci_status
scic_controller_free_io_tag(
3197 struct scic_sds_controller
*scic
,
3203 BUG_ON(io_tag
== SCI_CONTROLLER_INVALID_IO_TAG
);
3205 sequence
= scic_sds_io_tag_get_sequence(io_tag
);
3206 index
= scic_sds_io_tag_get_index(io_tag
);
3208 if (!sci_pool_full(scic
->tci_pool
)) {
3209 if (sequence
== scic
->io_request_sequence
[index
]) {
3210 scic_sds_io_sequence_increment(
3211 scic
->io_request_sequence
[index
]);
3213 sci_pool_put(scic
->tci_pool
, index
);
3219 return SCI_FAILURE_INVALID_IO_TAG
;