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.
56 #include <linux/device.h>
58 #include "scic_controller.h"
60 #include "scic_port.h"
61 #include "scic_sds_controller.h"
62 #include "scu_registers.h"
63 #include "scic_sds_phy.h"
64 #include "scic_sds_port_configuration_agent.h"
65 #include "scic_sds_port.h"
66 #include "remote_device.h"
67 #include "scic_sds_request.h"
68 #include "sci_environment.h"
70 #include "scu_completion_codes.h"
71 #include "scu_constants.h"
72 #include "scu_event_codes.h"
73 #include "scu_remote_node_context.h"
74 #include "scu_task_context.h"
75 #include "scu_unsolicited_frame.h"
77 #define SCU_CONTEXT_RAM_INIT_STALL_TIME 200
80 * smu_dcc_get_max_ports() -
82 * This macro returns the maximum number of logical ports supported by the
83 * hardware. The caller passes in the value read from the device context
84 * capacity register and this macro will mash and shift the value appropriately.
86 #define smu_dcc_get_max_ports(dcc_value) \
88 (((dcc_value) & SMU_DEVICE_CONTEXT_CAPACITY_MAX_LP_MASK) \
89 >> SMU_DEVICE_CONTEXT_CAPACITY_MAX_LP_SHIFT) + 1 \
93 * smu_dcc_get_max_task_context() -
95 * This macro returns the maximum number of task contexts supported by the
96 * hardware. The caller passes in the value read from the device context
97 * capacity register and this macro will mash and shift the value appropriately.
99 #define smu_dcc_get_max_task_context(dcc_value) \
101 (((dcc_value) & SMU_DEVICE_CONTEXT_CAPACITY_MAX_TC_MASK) \
102 >> SMU_DEVICE_CONTEXT_CAPACITY_MAX_TC_SHIFT) + 1 \
106 * smu_dcc_get_max_remote_node_context() -
108 * This macro returns the maximum number of remote node contexts supported by
109 * the hardware. The caller passes in the value read from the device context
110 * capacity register and this macro will mash and shift the value appropriately.
112 #define smu_dcc_get_max_remote_node_context(dcc_value) \
114 (((dcc_value) & SMU_DEVICE_CONTEXT_CAPACITY_MAX_RNC_MASK) \
115 >> SMU_DEVICE_CONTEXT_CAPACITY_MAX_RNC_SHIFT) + 1 \
119 static void scic_sds_controller_power_control_timer_handler(
121 #define SCIC_SDS_CONTROLLER_MIN_TIMER_COUNT 3
122 #define SCIC_SDS_CONTROLLER_MAX_TIMER_COUNT 3
127 * The number of milliseconds to wait for a phy to start.
129 #define SCIC_SDS_CONTROLLER_PHY_START_TIMEOUT 100
134 * The number of milliseconds to wait while a given phy is consuming power
135 * before allowing another set of phys to consume power. Ultimately, this will
136 * be specified by OEM parameter.
138 #define SCIC_SDS_CONTROLLER_POWER_CONTROL_INTERVAL 500
141 * COMPLETION_QUEUE_CYCLE_BIT() -
143 * This macro will return the cycle bit of the completion queue entry
145 #define COMPLETION_QUEUE_CYCLE_BIT(x) ((x) & 0x80000000)
148 * NORMALIZE_GET_POINTER() -
150 * This macro will normalize the completion queue get pointer so its value can
151 * be used as an index into an array
153 #define NORMALIZE_GET_POINTER(x) \
154 ((x) & SMU_COMPLETION_QUEUE_GET_POINTER_MASK)
157 * NORMALIZE_PUT_POINTER() -
159 * This macro will normalize the completion queue put pointer so its value can
160 * be used as an array inde
162 #define NORMALIZE_PUT_POINTER(x) \
163 ((x) & SMU_COMPLETION_QUEUE_PUT_POINTER_MASK)
167 * NORMALIZE_GET_POINTER_CYCLE_BIT() -
169 * This macro will normalize the completion queue cycle pointer so it matches
170 * the completion queue cycle bit
172 #define NORMALIZE_GET_POINTER_CYCLE_BIT(x) \
173 ((SMU_CQGR_CYCLE_BIT & (x)) << (31 - SMU_COMPLETION_QUEUE_GET_CYCLE_BIT_SHIFT))
176 * NORMALIZE_EVENT_POINTER() -
178 * This macro will normalize the completion queue event entry so its value can
179 * be used as an index.
181 #define NORMALIZE_EVENT_POINTER(x) \
183 ((x) & SMU_COMPLETION_QUEUE_GET_EVENT_POINTER_MASK) \
184 >> SMU_COMPLETION_QUEUE_GET_EVENT_POINTER_SHIFT \
188 * INCREMENT_COMPLETION_QUEUE_GET() -
190 * This macro will increment the controllers completion queue index value and
191 * possibly toggle the cycle bit if the completion queue index wraps back to 0.
193 #define INCREMENT_COMPLETION_QUEUE_GET(controller, index, cycle) \
194 INCREMENT_QUEUE_GET(\
197 (controller)->completion_queue_entries, \
202 * INCREMENT_EVENT_QUEUE_GET() -
204 * This macro will increment the controllers event queue index value and
205 * possibly toggle the event cycle bit if the event queue index wraps back to 0.
207 #define INCREMENT_EVENT_QUEUE_GET(controller, index, cycle) \
208 INCREMENT_QUEUE_GET(\
211 (controller)->completion_event_entries, \
212 SMU_CQGR_EVENT_CYCLE_BIT \
215 static void scic_sds_controller_initialize_power_control(struct scic_sds_controller
*scic
)
217 struct isci_host
*ihost
= scic_to_ihost(scic
);
218 scic
->power_control
.timer
= isci_timer_create(ihost
,
220 scic_sds_controller_power_control_timer_handler
);
222 memset(scic
->power_control
.requesters
, 0,
223 sizeof(scic
->power_control
.requesters
));
225 scic
->power_control
.phys_waiting
= 0;
226 scic
->power_control
.phys_granted_power
= 0;
229 int scic_controller_mem_init(struct scic_sds_controller
*scic
)
231 struct device
*dev
= scic_to_dev(scic
);
232 dma_addr_t dma_handle
;
233 enum sci_status result
;
235 scic
->completion_queue
= dmam_alloc_coherent(dev
,
236 scic
->completion_queue_entries
* sizeof(u32
),
237 &dma_handle
, GFP_KERNEL
);
238 if (!scic
->completion_queue
)
241 writel(lower_32_bits(dma_handle
),
242 &scic
->smu_registers
->completion_queue_lower
);
243 writel(upper_32_bits(dma_handle
),
244 &scic
->smu_registers
->completion_queue_upper
);
246 scic
->remote_node_context_table
= dmam_alloc_coherent(dev
,
247 scic
->remote_node_entries
*
248 sizeof(union scu_remote_node_context
),
249 &dma_handle
, GFP_KERNEL
);
250 if (!scic
->remote_node_context_table
)
253 writel(lower_32_bits(dma_handle
),
254 &scic
->smu_registers
->remote_node_context_lower
);
255 writel(upper_32_bits(dma_handle
),
256 &scic
->smu_registers
->remote_node_context_upper
);
258 scic
->task_context_table
= dmam_alloc_coherent(dev
,
259 scic
->task_context_entries
*
260 sizeof(struct scu_task_context
),
261 &dma_handle
, GFP_KERNEL
);
262 if (!scic
->task_context_table
)
265 writel(lower_32_bits(dma_handle
),
266 &scic
->smu_registers
->host_task_table_lower
);
267 writel(upper_32_bits(dma_handle
),
268 &scic
->smu_registers
->host_task_table_upper
);
270 result
= scic_sds_unsolicited_frame_control_construct(scic
);
275 * Inform the silicon as to the location of the UF headers and
278 writel(lower_32_bits(scic
->uf_control
.headers
.physical_address
),
279 &scic
->scu_registers
->sdma
.uf_header_base_address_lower
);
280 writel(upper_32_bits(scic
->uf_control
.headers
.physical_address
),
281 &scic
->scu_registers
->sdma
.uf_header_base_address_upper
);
283 writel(lower_32_bits(scic
->uf_control
.address_table
.physical_address
),
284 &scic
->scu_registers
->sdma
.uf_address_table_lower
);
285 writel(upper_32_bits(scic
->uf_control
.address_table
.physical_address
),
286 &scic
->scu_registers
->sdma
.uf_address_table_upper
);
292 * This method initializes the task context data for the controller.
297 scic_sds_controller_assign_task_entries(struct scic_sds_controller
*controller
)
302 * Assign all the TCs to function 0
303 * TODO: Do we actually need to read this register to write it back?
307 readl(&controller
->smu_registers
->task_context_assignment
[0]);
309 task_assignment
|= (SMU_TCA_GEN_VAL(STARTING
, 0)) |
310 (SMU_TCA_GEN_VAL(ENDING
, controller
->task_context_entries
- 1)) |
311 (SMU_TCA_GEN_BIT(RANGE_CHECK_ENABLE
));
313 writel(task_assignment
,
314 &controller
->smu_registers
->task_context_assignment
[0]);
319 * This method initializes the hardware completion queue.
323 static void scic_sds_controller_initialize_completion_queue(
324 struct scic_sds_controller
*scic
)
327 u32 completion_queue_control_value
;
328 u32 completion_queue_get_value
;
329 u32 completion_queue_put_value
;
331 scic
->completion_queue_get
= 0;
333 completion_queue_control_value
= (
334 SMU_CQC_QUEUE_LIMIT_SET(scic
->completion_queue_entries
- 1)
335 | SMU_CQC_EVENT_LIMIT_SET(scic
->completion_event_entries
- 1)
338 writel(completion_queue_control_value
,
339 &scic
->smu_registers
->completion_queue_control
);
342 /* Set the completion queue get pointer and enable the queue */
343 completion_queue_get_value
= (
344 (SMU_CQGR_GEN_VAL(POINTER
, 0))
345 | (SMU_CQGR_GEN_VAL(EVENT_POINTER
, 0))
346 | (SMU_CQGR_GEN_BIT(ENABLE
))
347 | (SMU_CQGR_GEN_BIT(EVENT_ENABLE
))
350 writel(completion_queue_get_value
,
351 &scic
->smu_registers
->completion_queue_get
);
353 /* Set the completion queue put pointer */
354 completion_queue_put_value
= (
355 (SMU_CQPR_GEN_VAL(POINTER
, 0))
356 | (SMU_CQPR_GEN_VAL(EVENT_POINTER
, 0))
359 writel(completion_queue_put_value
,
360 &scic
->smu_registers
->completion_queue_put
);
362 /* Initialize the cycle bit of the completion queue entries */
363 for (index
= 0; index
< scic
->completion_queue_entries
; index
++) {
365 * If get.cycle_bit != completion_queue.cycle_bit
366 * its not a valid completion queue entry
367 * so at system start all entries are invalid */
368 scic
->completion_queue
[index
] = 0x80000000;
373 * This method initializes the hardware unsolicited frame queue.
377 static void scic_sds_controller_initialize_unsolicited_frame_queue(
378 struct scic_sds_controller
*scic
)
380 u32 frame_queue_control_value
;
381 u32 frame_queue_get_value
;
382 u32 frame_queue_put_value
;
384 /* Write the queue size */
385 frame_queue_control_value
=
386 SCU_UFQC_GEN_VAL(QUEUE_SIZE
,
387 scic
->uf_control
.address_table
.count
);
389 writel(frame_queue_control_value
,
390 &scic
->scu_registers
->sdma
.unsolicited_frame_queue_control
);
392 /* Setup the get pointer for the unsolicited frame queue */
393 frame_queue_get_value
= (
394 SCU_UFQGP_GEN_VAL(POINTER
, 0)
395 | SCU_UFQGP_GEN_BIT(ENABLE_BIT
)
398 writel(frame_queue_get_value
,
399 &scic
->scu_registers
->sdma
.unsolicited_frame_get_pointer
);
400 /* Setup the put pointer for the unsolicited frame queue */
401 frame_queue_put_value
= SCU_UFQPP_GEN_VAL(POINTER
, 0);
402 writel(frame_queue_put_value
,
403 &scic
->scu_registers
->sdma
.unsolicited_frame_put_pointer
);
407 * This method enables the hardware port task scheduler.
411 static void scic_sds_controller_enable_port_task_scheduler(
412 struct scic_sds_controller
*scic
)
414 u32 port_task_scheduler_value
;
416 port_task_scheduler_value
=
417 readl(&scic
->scu_registers
->peg0
.ptsg
.control
);
418 port_task_scheduler_value
|=
419 (SCU_PTSGCR_GEN_BIT(ETM_ENABLE
) |
420 SCU_PTSGCR_GEN_BIT(PTSG_ENABLE
));
421 writel(port_task_scheduler_value
,
422 &scic
->scu_registers
->peg0
.ptsg
.control
);
428 * This macro is used to delay between writes to the AFE registers during AFE
431 #define AFE_REGISTER_WRITE_DELAY 10
433 /* Initialize the AFE for this phy index. We need to read the AFE setup from
434 * the OEM parameters none
436 static void scic_sds_controller_afe_initialization(struct scic_sds_controller
*scic
)
438 const struct scic_sds_oem_params
*oem
= &scic
->oem_parameters
.sds1
;
442 /* Clear DFX Status registers */
443 writel(0x0081000f, &scic
->scu_registers
->afe
.afe_dfx_master_control0
);
444 udelay(AFE_REGISTER_WRITE_DELAY
);
447 /* PM Rx Equalization Save, PM SPhy Rx Acknowledgement
448 * Timer, PM Stagger Timer */
449 writel(0x0007BFFF, &scic
->scu_registers
->afe
.afe_pmsn_master_control2
);
450 udelay(AFE_REGISTER_WRITE_DELAY
);
453 /* Configure bias currents to normal */
455 writel(0x00005500, &scic
->scu_registers
->afe
.afe_bias_control
);
457 writel(0x00005A00, &scic
->scu_registers
->afe
.afe_bias_control
);
459 writel(0x00005F00, &scic
->scu_registers
->afe
.afe_bias_control
);
461 udelay(AFE_REGISTER_WRITE_DELAY
);
465 writel(0x80040A08, &scic
->scu_registers
->afe
.afe_pll_control0
);
467 writel(0x80040908, &scic
->scu_registers
->afe
.afe_pll_control0
);
469 udelay(AFE_REGISTER_WRITE_DELAY
);
471 /* Wait for the PLL to lock */
473 afe_status
= readl(&scic
->scu_registers
->afe
.afe_common_block_status
);
474 udelay(AFE_REGISTER_WRITE_DELAY
);
475 } while ((afe_status
& 0x00001000) == 0);
477 if (is_a0() || is_a2()) {
478 /* Shorten SAS SNW lock time (RxLock timer value from 76 us to 50 us) */
479 writel(0x7bcc96ad, &scic
->scu_registers
->afe
.afe_pmsn_master_control0
);
480 udelay(AFE_REGISTER_WRITE_DELAY
);
483 for (phy_id
= 0; phy_id
< SCI_MAX_PHYS
; phy_id
++) {
484 const struct sci_phy_oem_params
*oem_phy
= &oem
->phys
[phy_id
];
487 /* Configure transmitter SSC parameters */
488 writel(0x00030000, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_tx_ssc_control
);
489 udelay(AFE_REGISTER_WRITE_DELAY
);
492 * All defaults, except the Receive Word Alignament/Comma Detect
493 * Enable....(0xe800) */
494 writel(0x00004512, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_xcvr_control0
);
495 udelay(AFE_REGISTER_WRITE_DELAY
);
497 writel(0x0050100F, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_xcvr_control1
);
498 udelay(AFE_REGISTER_WRITE_DELAY
);
502 * Power up TX and RX out from power down (PWRDNTX and PWRDNRX)
503 * & increase TX int & ext bias 20%....(0xe85c) */
505 writel(0x000003D4, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_channel_control
);
507 writel(0x000003F0, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_channel_control
);
509 /* Power down TX and RX (PWRDNTX and PWRDNRX) */
510 writel(0x000003d7, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_channel_control
);
511 udelay(AFE_REGISTER_WRITE_DELAY
);
514 * Power up TX and RX out from power down (PWRDNTX and PWRDNRX)
515 * & increase TX int & ext bias 20%....(0xe85c) */
516 writel(0x000003d4, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_channel_control
);
518 udelay(AFE_REGISTER_WRITE_DELAY
);
520 if (is_a0() || is_a2()) {
521 /* Enable TX equalization (0xe824) */
522 writel(0x00040000, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_tx_control
);
523 udelay(AFE_REGISTER_WRITE_DELAY
);
527 * RDPI=0x0(RX Power On), RXOOBDETPDNC=0x0, TPD=0x0(TX Power On),
528 * RDD=0x0(RX Detect Enabled) ....(0xe800) */
529 writel(0x00004100, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_xcvr_control0
);
530 udelay(AFE_REGISTER_WRITE_DELAY
);
532 /* Leave DFE/FFE on */
534 writel(0x3F09983F, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_rx_ssc_control0
);
536 writel(0x3F11103F, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_rx_ssc_control0
);
538 writel(0x3F11103F, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_rx_ssc_control0
);
539 udelay(AFE_REGISTER_WRITE_DELAY
);
540 /* Enable TX equalization (0xe824) */
541 writel(0x00040000, &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_tx_control
);
543 udelay(AFE_REGISTER_WRITE_DELAY
);
545 writel(oem_phy
->afe_tx_amp_control0
,
546 &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_tx_amp_control0
);
547 udelay(AFE_REGISTER_WRITE_DELAY
);
549 writel(oem_phy
->afe_tx_amp_control1
,
550 &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_tx_amp_control1
);
551 udelay(AFE_REGISTER_WRITE_DELAY
);
553 writel(oem_phy
->afe_tx_amp_control2
,
554 &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_tx_amp_control2
);
555 udelay(AFE_REGISTER_WRITE_DELAY
);
557 writel(oem_phy
->afe_tx_amp_control3
,
558 &scic
->scu_registers
->afe
.scu_afe_xcvr
[phy_id
].afe_tx_amp_control3
);
559 udelay(AFE_REGISTER_WRITE_DELAY
);
562 /* Transfer control to the PEs */
563 writel(0x00010f00, &scic
->scu_registers
->afe
.afe_dfx_master_control0
);
564 udelay(AFE_REGISTER_WRITE_DELAY
);
568 * ****************************************************************************-
569 * * SCIC SDS Controller Internal Start/Stop Routines
570 * ****************************************************************************- */
574 * This method will attempt to transition into the ready state for the
575 * controller and indicate that the controller start operation has completed
576 * if all criteria are met.
577 * @scic: This parameter indicates the controller object for which
578 * to transition to ready.
579 * @status: This parameter indicates the status value to be pass into the call
580 * to scic_cb_controller_start_complete().
584 static void scic_sds_controller_transition_to_ready(
585 struct scic_sds_controller
*scic
,
586 enum sci_status status
)
588 struct isci_host
*ihost
= scic_to_ihost(scic
);
590 if (scic
->state_machine
.current_state_id
==
591 SCI_BASE_CONTROLLER_STATE_STARTING
) {
593 * We move into the ready state, because some of the phys/ports
594 * may be up and operational.
596 sci_base_state_machine_change_state(&scic
->state_machine
,
597 SCI_BASE_CONTROLLER_STATE_READY
);
599 isci_host_start_complete(ihost
, status
);
603 static void scic_sds_controller_timeout_handler(void *_scic
)
605 struct scic_sds_controller
*scic
= _scic
;
606 struct isci_host
*ihost
= scic_to_ihost(scic
);
607 struct sci_base_state_machine
*sm
= &scic
->state_machine
;
609 if (sm
->current_state_id
== SCI_BASE_CONTROLLER_STATE_STARTING
)
610 scic_sds_controller_transition_to_ready(scic
, SCI_FAILURE_TIMEOUT
);
611 else if (sm
->current_state_id
== SCI_BASE_CONTROLLER_STATE_STOPPING
) {
612 sci_base_state_machine_change_state(sm
, SCI_BASE_CONTROLLER_STATE_FAILED
);
613 isci_host_stop_complete(ihost
, SCI_FAILURE_TIMEOUT
);
614 } else /* / @todo Now what do we want to do in this case? */
615 dev_err(scic_to_dev(scic
),
616 "%s: Controller timer fired when controller was not "
617 "in a state being timed.\n",
621 static enum sci_status
scic_sds_controller_stop_ports(struct scic_sds_controller
*scic
)
624 enum sci_status port_status
;
625 enum sci_status status
= SCI_SUCCESS
;
626 struct isci_host
*ihost
= scic_to_ihost(scic
);
628 for (index
= 0; index
< scic
->logical_port_entries
; index
++) {
629 struct scic_sds_port
*sci_port
= &ihost
->ports
[index
].sci
;
630 scic_sds_port_handler_t stop
;
632 stop
= sci_port
->state_handlers
->stop_handler
;
633 port_status
= stop(sci_port
);
635 if ((port_status
!= SCI_SUCCESS
) &&
636 (port_status
!= SCI_FAILURE_INVALID_STATE
)) {
637 status
= SCI_FAILURE
;
639 dev_warn(scic_to_dev(scic
),
640 "%s: Controller stop operation failed to "
641 "stop port %d because of status %d.\n",
643 sci_port
->logical_port_index
,
651 static inline void scic_sds_controller_phy_timer_start(
652 struct scic_sds_controller
*scic
)
654 isci_timer_start(scic
->phy_startup_timer
,
655 SCIC_SDS_CONTROLLER_PHY_START_TIMEOUT
);
657 scic
->phy_startup_timer_pending
= true;
660 static void scic_sds_controller_phy_timer_stop(struct scic_sds_controller
*scic
)
662 isci_timer_stop(scic
->phy_startup_timer
);
664 scic
->phy_startup_timer_pending
= false;
668 * scic_sds_controller_start_next_phy - start phy
671 * If all the phys have been started, then attempt to transition the
672 * controller to the READY state and inform the user
673 * (scic_cb_controller_start_complete()).
675 static enum sci_status
scic_sds_controller_start_next_phy(struct scic_sds_controller
*scic
)
677 struct isci_host
*ihost
= scic_to_ihost(scic
);
678 struct scic_sds_oem_params
*oem
= &scic
->oem_parameters
.sds1
;
679 struct scic_sds_phy
*sci_phy
;
680 enum sci_status status
;
682 status
= SCI_SUCCESS
;
684 if (scic
->phy_startup_timer_pending
)
687 if (scic
->next_phy_to_start
>= SCI_MAX_PHYS
) {
688 bool is_controller_start_complete
= true;
692 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
693 sci_phy
= &ihost
->phys
[index
].sci
;
694 state
= sci_phy
->state_machine
.current_state_id
;
696 if (!scic_sds_phy_get_port(sci_phy
))
699 /* The controller start operation is complete iff:
700 * - all links have been given an opportunity to start
701 * - have no indication of a connected device
702 * - have an indication of a connected device and it has
703 * finished the link training process.
705 if ((sci_phy
->is_in_link_training
== false &&
706 state
== SCI_BASE_PHY_STATE_INITIAL
) ||
707 (sci_phy
->is_in_link_training
== false &&
708 state
== SCI_BASE_PHY_STATE_STOPPED
) ||
709 (sci_phy
->is_in_link_training
== true &&
710 state
== SCI_BASE_PHY_STATE_STARTING
)) {
711 is_controller_start_complete
= false;
717 * The controller has successfully finished the start process.
718 * Inform the SCI Core user and transition to the READY state. */
719 if (is_controller_start_complete
== true) {
720 scic_sds_controller_transition_to_ready(scic
, SCI_SUCCESS
);
721 scic_sds_controller_phy_timer_stop(scic
);
724 sci_phy
= &ihost
->phys
[scic
->next_phy_to_start
].sci
;
726 if (oem
->controller
.mode_type
== SCIC_PORT_MANUAL_CONFIGURATION_MODE
) {
727 if (scic_sds_phy_get_port(sci_phy
) == NULL
) {
728 scic
->next_phy_to_start
++;
730 /* Caution recursion ahead be forwarned
732 * The PHY was never added to a PORT in MPC mode
733 * so start the next phy in sequence This phy
734 * will never go link up and will not draw power
735 * the OEM parameters either configured the phy
736 * incorrectly for the PORT or it was never
739 return scic_sds_controller_start_next_phy(scic
);
743 status
= scic_sds_phy_start(sci_phy
);
745 if (status
== SCI_SUCCESS
) {
746 scic_sds_controller_phy_timer_start(scic
);
748 dev_warn(scic_to_dev(scic
),
749 "%s: Controller stop operation failed "
750 "to stop phy %d because of status "
753 ihost
->phys
[scic
->next_phy_to_start
].sci
.phy_index
,
757 scic
->next_phy_to_start
++;
763 static void scic_sds_controller_phy_startup_timeout_handler(void *_scic
)
765 struct scic_sds_controller
*scic
= _scic
;
766 enum sci_status status
;
768 scic
->phy_startup_timer_pending
= false;
769 status
= SCI_FAILURE
;
770 while (status
!= SCI_SUCCESS
)
771 status
= scic_sds_controller_start_next_phy(scic
);
774 static enum sci_status
scic_sds_controller_initialize_phy_startup(struct scic_sds_controller
*scic
)
776 struct isci_host
*ihost
= scic_to_ihost(scic
);
778 scic
->phy_startup_timer
= isci_timer_create(ihost
,
780 scic_sds_controller_phy_startup_timeout_handler
);
782 if (scic
->phy_startup_timer
== NULL
)
783 return SCI_FAILURE_INSUFFICIENT_RESOURCES
;
785 scic
->next_phy_to_start
= 0;
786 scic
->phy_startup_timer_pending
= false;
792 static enum sci_status
scic_sds_controller_stop_phys(struct scic_sds_controller
*scic
)
795 enum sci_status status
;
796 enum sci_status phy_status
;
797 struct isci_host
*ihost
= scic_to_ihost(scic
);
799 status
= SCI_SUCCESS
;
801 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
802 phy_status
= scic_sds_phy_stop(&ihost
->phys
[index
].sci
);
804 if (phy_status
!= SCI_SUCCESS
&&
805 phy_status
!= SCI_FAILURE_INVALID_STATE
) {
806 status
= SCI_FAILURE
;
808 dev_warn(scic_to_dev(scic
),
809 "%s: Controller stop operation failed to stop "
810 "phy %d because of status %d.\n",
812 ihost
->phys
[index
].sci
.phy_index
, phy_status
);
819 static enum sci_status
scic_sds_controller_stop_devices(struct scic_sds_controller
*scic
)
822 enum sci_status status
;
823 enum sci_status device_status
;
825 status
= SCI_SUCCESS
;
827 for (index
= 0; index
< scic
->remote_node_entries
; index
++) {
828 if (scic
->device_table
[index
] != NULL
) {
829 /* / @todo What timeout value do we want to provide to this request? */
830 device_status
= scic_remote_device_stop(scic
->device_table
[index
], 0);
832 if ((device_status
!= SCI_SUCCESS
) &&
833 (device_status
!= SCI_FAILURE_INVALID_STATE
)) {
834 dev_warn(scic_to_dev(scic
),
835 "%s: Controller stop operation failed "
836 "to stop device 0x%p because of "
839 scic
->device_table
[index
], device_status
);
847 static void scic_sds_controller_power_control_timer_start(struct scic_sds_controller
*scic
)
849 isci_timer_start(scic
->power_control
.timer
,
850 SCIC_SDS_CONTROLLER_POWER_CONTROL_INTERVAL
);
852 scic
->power_control
.timer_started
= true;
855 static void scic_sds_controller_power_control_timer_stop(struct scic_sds_controller
*scic
)
857 if (scic
->power_control
.timer_started
) {
858 isci_timer_stop(scic
->power_control
.timer
);
859 scic
->power_control
.timer_started
= false;
863 static void scic_sds_controller_power_control_timer_restart(struct scic_sds_controller
*scic
)
865 scic_sds_controller_power_control_timer_stop(scic
);
866 scic_sds_controller_power_control_timer_start(scic
);
869 static void scic_sds_controller_power_control_timer_handler(
872 struct scic_sds_controller
*scic
;
874 scic
= (struct scic_sds_controller
*)controller
;
876 scic
->power_control
.phys_granted_power
= 0;
878 if (scic
->power_control
.phys_waiting
== 0) {
879 scic
->power_control
.timer_started
= false;
881 struct scic_sds_phy
*sci_phy
= NULL
;
886 && (scic
->power_control
.phys_waiting
!= 0);
888 if (scic
->power_control
.requesters
[i
] != NULL
) {
889 if (scic
->power_control
.phys_granted_power
<
890 scic
->oem_parameters
.sds1
.controller
.max_concurrent_dev_spin_up
) {
891 sci_phy
= scic
->power_control
.requesters
[i
];
892 scic
->power_control
.requesters
[i
] = NULL
;
893 scic
->power_control
.phys_waiting
--;
894 scic
->power_control
.phys_granted_power
++;
895 scic_sds_phy_consume_power_handler(sci_phy
);
903 * It doesn't matter if the power list is empty, we need to start the
904 * timer in case another phy becomes ready.
906 scic_sds_controller_power_control_timer_start(scic
);
911 * This method inserts the phy in the stagger spinup control queue.
916 void scic_sds_controller_power_control_queue_insert(
917 struct scic_sds_controller
*scic
,
918 struct scic_sds_phy
*sci_phy
)
920 BUG_ON(sci_phy
== NULL
);
922 if (scic
->power_control
.phys_granted_power
<
923 scic
->oem_parameters
.sds1
.controller
.max_concurrent_dev_spin_up
) {
924 scic
->power_control
.phys_granted_power
++;
925 scic_sds_phy_consume_power_handler(sci_phy
);
928 * stop and start the power_control timer. When the timer fires, the
929 * no_of_phys_granted_power will be set to 0
931 scic_sds_controller_power_control_timer_restart(scic
);
933 /* Add the phy in the waiting list */
934 scic
->power_control
.requesters
[sci_phy
->phy_index
] = sci_phy
;
935 scic
->power_control
.phys_waiting
++;
940 * This method removes the phy from the stagger spinup control queue.
945 void scic_sds_controller_power_control_queue_remove(
946 struct scic_sds_controller
*scic
,
947 struct scic_sds_phy
*sci_phy
)
949 BUG_ON(sci_phy
== NULL
);
951 if (scic
->power_control
.requesters
[sci_phy
->phy_index
] != NULL
) {
952 scic
->power_control
.phys_waiting
--;
955 scic
->power_control
.requesters
[sci_phy
->phy_index
] = NULL
;
959 * ****************************************************************************-
960 * * SCIC SDS Controller Completion Routines
961 * ****************************************************************************- */
964 * This method returns a true value if the completion queue has entries that
968 * bool true if the completion queue has entries to process false if the
969 * completion queue has no entries to process
971 static bool scic_sds_controller_completion_queue_has_entries(
972 struct scic_sds_controller
*scic
)
974 u32 get_value
= scic
->completion_queue_get
;
975 u32 get_index
= get_value
& SMU_COMPLETION_QUEUE_GET_POINTER_MASK
;
977 if (NORMALIZE_GET_POINTER_CYCLE_BIT(get_value
) ==
978 COMPLETION_QUEUE_CYCLE_BIT(scic
->completion_queue
[get_index
]))
985 * This method processes a task completion notification. This is called from
986 * within the controller completion handler.
991 static void scic_sds_controller_task_completion(
992 struct scic_sds_controller
*scic
,
993 u32 completion_entry
)
996 struct scic_sds_request
*io_request
;
998 index
= SCU_GET_COMPLETION_INDEX(completion_entry
);
999 io_request
= scic
->io_request_table
[index
];
1001 /* Make sure that we really want to process this IO request */
1003 (io_request
!= NULL
)
1004 && (io_request
->io_tag
!= SCI_CONTROLLER_INVALID_IO_TAG
)
1006 scic_sds_io_tag_get_sequence(io_request
->io_tag
)
1007 == scic
->io_request_sequence
[index
]
1010 /* Yep this is a valid io request pass it along to the io request handler */
1011 scic_sds_io_request_tc_completion(io_request
, completion_entry
);
1016 * This method processes an SDMA completion event. This is called from within
1017 * the controller completion handler.
1019 * @completion_entry:
1022 static void scic_sds_controller_sdma_completion(
1023 struct scic_sds_controller
*scic
,
1024 u32 completion_entry
)
1027 struct scic_sds_request
*io_request
;
1028 struct scic_sds_remote_device
*device
;
1030 index
= SCU_GET_COMPLETION_INDEX(completion_entry
);
1032 switch (scu_get_command_request_type(completion_entry
)) {
1033 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
:
1034 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_DUMP_TC
:
1035 io_request
= scic
->io_request_table
[index
];
1036 dev_warn(scic_to_dev(scic
),
1037 "%s: SCIC SDS Completion type SDMA %x for io request "
1042 /* @todo For a post TC operation we need to fail the IO
1047 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_DUMP_RNC
:
1048 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_OTHER_RNC
:
1049 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_RNC
:
1050 device
= scic
->device_table
[index
];
1051 dev_warn(scic_to_dev(scic
),
1052 "%s: SCIC SDS Completion type SDMA %x for remote "
1057 /* @todo For a port RNC operation we need to fail the
1063 dev_warn(scic_to_dev(scic
),
1064 "%s: SCIC SDS Completion unknown SDMA completion "
1073 static void scic_sds_controller_unsolicited_frame(struct scic_sds_controller
*scic
,
1074 u32 completion_entry
)
1079 struct isci_host
*ihost
= scic_to_ihost(scic
);
1080 struct scu_unsolicited_frame_header
*frame_header
;
1081 struct scic_sds_phy
*phy
;
1082 struct scic_sds_remote_device
*device
;
1084 enum sci_status result
= SCI_FAILURE
;
1086 frame_index
= SCU_GET_FRAME_INDEX(completion_entry
);
1088 frame_header
= scic
->uf_control
.buffers
.array
[frame_index
].header
;
1089 scic
->uf_control
.buffers
.array
[frame_index
].state
= UNSOLICITED_FRAME_IN_USE
;
1091 if (SCU_GET_FRAME_ERROR(completion_entry
)) {
1093 * / @todo If the IAF frame or SIGNATURE FIS frame has an error will
1094 * / this cause a problem? We expect the phy initialization will
1095 * / fail if there is an error in the frame. */
1096 scic_sds_controller_release_frame(scic
, frame_index
);
1100 if (frame_header
->is_address_frame
) {
1101 index
= SCU_GET_PROTOCOL_ENGINE_INDEX(completion_entry
);
1102 phy
= &ihost
->phys
[index
].sci
;
1103 result
= scic_sds_phy_frame_handler(phy
, frame_index
);
1106 index
= SCU_GET_COMPLETION_INDEX(completion_entry
);
1108 if (index
== SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
) {
1110 * This is a signature fis or a frame from a direct attached SATA
1111 * device that has not yet been created. In either case forwared
1112 * the frame to the PE and let it take care of the frame data. */
1113 index
= SCU_GET_PROTOCOL_ENGINE_INDEX(completion_entry
);
1114 phy
= &ihost
->phys
[index
].sci
;
1115 result
= scic_sds_phy_frame_handler(phy
, frame_index
);
1117 if (index
< scic
->remote_node_entries
)
1118 device
= scic
->device_table
[index
];
1123 result
= scic_sds_remote_device_frame_handler(device
, frame_index
);
1125 scic_sds_controller_release_frame(scic
, frame_index
);
1129 if (result
!= SCI_SUCCESS
) {
1131 * / @todo Is there any reason to report some additional error message
1132 * / when we get this failure notifiction? */
1136 static void scic_sds_controller_event_completion(struct scic_sds_controller
*scic
,
1137 u32 completion_entry
)
1139 struct isci_host
*ihost
= scic_to_ihost(scic
);
1140 struct scic_sds_request
*io_request
;
1141 struct scic_sds_remote_device
*device
;
1142 struct scic_sds_phy
*phy
;
1145 index
= SCU_GET_COMPLETION_INDEX(completion_entry
);
1147 switch (scu_get_event_type(completion_entry
)) {
1148 case SCU_EVENT_TYPE_SMU_COMMAND_ERROR
:
1149 /* / @todo The driver did something wrong and we need to fix the condtion. */
1150 dev_err(scic_to_dev(scic
),
1151 "%s: SCIC Controller 0x%p received SMU command error "
1158 case SCU_EVENT_TYPE_SMU_PCQ_ERROR
:
1159 case SCU_EVENT_TYPE_SMU_ERROR
:
1160 case SCU_EVENT_TYPE_FATAL_MEMORY_ERROR
:
1162 * / @todo This is a hardware failure and its likely that we want to
1163 * / reset the controller. */
1164 dev_err(scic_to_dev(scic
),
1165 "%s: SCIC Controller 0x%p received fatal controller "
1172 case SCU_EVENT_TYPE_TRANSPORT_ERROR
:
1173 io_request
= scic
->io_request_table
[index
];
1174 scic_sds_io_request_event_handler(io_request
, completion_entry
);
1177 case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT
:
1178 switch (scu_get_event_specifier(completion_entry
)) {
1179 case SCU_EVENT_SPECIFIC_SMP_RESPONSE_NO_PE
:
1180 case SCU_EVENT_SPECIFIC_TASK_TIMEOUT
:
1181 io_request
= scic
->io_request_table
[index
];
1182 if (io_request
!= NULL
)
1183 scic_sds_io_request_event_handler(io_request
, completion_entry
);
1185 dev_warn(scic_to_dev(scic
),
1186 "%s: SCIC Controller 0x%p received "
1187 "event 0x%x for io request object "
1188 "that doesnt exist.\n",
1195 case SCU_EVENT_SPECIFIC_IT_NEXUS_TIMEOUT
:
1196 device
= scic
->device_table
[index
];
1198 scic_sds_remote_device_event_handler(device
, completion_entry
);
1200 dev_warn(scic_to_dev(scic
),
1201 "%s: SCIC Controller 0x%p received "
1202 "event 0x%x for remote device object "
1203 "that doesnt exist.\n",
1212 case SCU_EVENT_TYPE_BROADCAST_CHANGE
:
1214 * direct the broadcast change event to the phy first and then let
1215 * the phy redirect the broadcast change to the port object */
1216 case SCU_EVENT_TYPE_ERR_CNT_EVENT
:
1218 * direct error counter event to the phy object since that is where
1219 * we get the event notification. This is a type 4 event. */
1220 case SCU_EVENT_TYPE_OSSP_EVENT
:
1221 index
= SCU_GET_PROTOCOL_ENGINE_INDEX(completion_entry
);
1222 phy
= &ihost
->phys
[index
].sci
;
1223 scic_sds_phy_event_handler(phy
, completion_entry
);
1226 case SCU_EVENT_TYPE_RNC_SUSPEND_TX
:
1227 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX
:
1228 case SCU_EVENT_TYPE_RNC_OPS_MISC
:
1229 if (index
< scic
->remote_node_entries
) {
1230 device
= scic
->device_table
[index
];
1233 scic_sds_remote_device_event_handler(device
, completion_entry
);
1235 dev_err(scic_to_dev(scic
),
1236 "%s: SCIC Controller 0x%p received event 0x%x "
1237 "for remote device object 0x%0x that doesnt "
1247 dev_warn(scic_to_dev(scic
),
1248 "%s: SCIC Controller received unknown event code %x\n",
1256 * This method is a private routine for processing the completion queue entries.
1260 static void scic_sds_controller_process_completions(
1261 struct scic_sds_controller
*scic
)
1263 u32 completion_count
= 0;
1264 u32 completion_entry
;
1270 dev_dbg(scic_to_dev(scic
),
1271 "%s: completion queue begining get:0x%08x\n",
1273 scic
->completion_queue_get
);
1275 /* Get the component parts of the completion queue */
1276 get_index
= NORMALIZE_GET_POINTER(scic
->completion_queue_get
);
1277 get_cycle
= SMU_CQGR_CYCLE_BIT
& scic
->completion_queue_get
;
1279 event_index
= NORMALIZE_EVENT_POINTER(scic
->completion_queue_get
);
1280 event_cycle
= SMU_CQGR_EVENT_CYCLE_BIT
& scic
->completion_queue_get
;
1283 NORMALIZE_GET_POINTER_CYCLE_BIT(get_cycle
)
1284 == COMPLETION_QUEUE_CYCLE_BIT(scic
->completion_queue
[get_index
])
1288 completion_entry
= scic
->completion_queue
[get_index
];
1289 INCREMENT_COMPLETION_QUEUE_GET(scic
, get_index
, get_cycle
);
1291 dev_dbg(scic_to_dev(scic
),
1292 "%s: completion queue entry:0x%08x\n",
1296 switch (SCU_GET_COMPLETION_TYPE(completion_entry
)) {
1297 case SCU_COMPLETION_TYPE_TASK
:
1298 scic_sds_controller_task_completion(scic
, completion_entry
);
1301 case SCU_COMPLETION_TYPE_SDMA
:
1302 scic_sds_controller_sdma_completion(scic
, completion_entry
);
1305 case SCU_COMPLETION_TYPE_UFI
:
1306 scic_sds_controller_unsolicited_frame(scic
, completion_entry
);
1309 case SCU_COMPLETION_TYPE_EVENT
:
1310 INCREMENT_EVENT_QUEUE_GET(scic
, event_index
, event_cycle
);
1311 scic_sds_controller_event_completion(scic
, completion_entry
);
1314 case SCU_COMPLETION_TYPE_NOTIFY
:
1316 * Presently we do the same thing with a notify event that we do with the
1317 * other event codes. */
1318 INCREMENT_EVENT_QUEUE_GET(scic
, event_index
, event_cycle
);
1319 scic_sds_controller_event_completion(scic
, completion_entry
);
1323 dev_warn(scic_to_dev(scic
),
1324 "%s: SCIC Controller received unknown "
1325 "completion type %x\n",
1332 /* Update the get register if we completed one or more entries */
1333 if (completion_count
> 0) {
1334 scic
->completion_queue_get
=
1335 SMU_CQGR_GEN_BIT(ENABLE
) |
1336 SMU_CQGR_GEN_BIT(EVENT_ENABLE
) |
1338 SMU_CQGR_GEN_VAL(EVENT_POINTER
, event_index
) |
1340 SMU_CQGR_GEN_VAL(POINTER
, get_index
);
1342 writel(scic
->completion_queue_get
,
1343 &scic
->smu_registers
->completion_queue_get
);
1347 dev_dbg(scic_to_dev(scic
),
1348 "%s: completion queue ending get:0x%08x\n",
1350 scic
->completion_queue_get
);
1354 bool scic_sds_controller_isr(struct scic_sds_controller
*scic
)
1356 if (scic_sds_controller_completion_queue_has_entries(scic
)) {
1360 * we have a spurious interrupt it could be that we have already
1361 * emptied the completion queue from a previous interrupt */
1362 writel(SMU_ISR_COMPLETION
, &scic
->smu_registers
->interrupt_status
);
1365 * There is a race in the hardware that could cause us not to be notified
1366 * of an interrupt completion if we do not take this step. We will mask
1367 * then unmask the interrupts so if there is another interrupt pending
1368 * the clearing of the interrupt source we get the next interrupt message. */
1369 writel(0xFF000000, &scic
->smu_registers
->interrupt_mask
);
1370 writel(0, &scic
->smu_registers
->interrupt_mask
);
1376 void scic_sds_controller_completion_handler(struct scic_sds_controller
*scic
)
1378 /* Empty out the completion queue */
1379 if (scic_sds_controller_completion_queue_has_entries(scic
))
1380 scic_sds_controller_process_completions(scic
);
1382 /* Clear the interrupt and enable all interrupts again */
1383 writel(SMU_ISR_COMPLETION
, &scic
->smu_registers
->interrupt_status
);
1384 /* Could we write the value of SMU_ISR_COMPLETION? */
1385 writel(0xFF000000, &scic
->smu_registers
->interrupt_mask
);
1386 writel(0, &scic
->smu_registers
->interrupt_mask
);
1389 bool scic_sds_controller_error_isr(struct scic_sds_controller
*scic
)
1391 u32 interrupt_status
;
1394 readl(&scic
->smu_registers
->interrupt_status
);
1395 interrupt_status
&= (SMU_ISR_QUEUE_ERROR
| SMU_ISR_QUEUE_SUSPEND
);
1397 if (interrupt_status
!= 0) {
1399 * There is an error interrupt pending so let it through and handle
1400 * in the callback */
1405 * There is a race in the hardware that could cause us not to be notified
1406 * of an interrupt completion if we do not take this step. We will mask
1407 * then unmask the error interrupts so if there was another interrupt
1408 * pending we will be notified.
1409 * Could we write the value of (SMU_ISR_QUEUE_ERROR | SMU_ISR_QUEUE_SUSPEND)? */
1410 writel(0xff, &scic
->smu_registers
->interrupt_mask
);
1411 writel(0, &scic
->smu_registers
->interrupt_mask
);
1416 void scic_sds_controller_error_handler(struct scic_sds_controller
*scic
)
1418 u32 interrupt_status
;
1421 readl(&scic
->smu_registers
->interrupt_status
);
1423 if ((interrupt_status
& SMU_ISR_QUEUE_SUSPEND
) &&
1424 scic_sds_controller_completion_queue_has_entries(scic
)) {
1426 scic_sds_controller_process_completions(scic
);
1427 writel(SMU_ISR_QUEUE_SUSPEND
, &scic
->smu_registers
->interrupt_status
);
1429 dev_err(scic_to_dev(scic
), "%s: status: %#x\n", __func__
,
1432 sci_base_state_machine_change_state(&scic
->state_machine
,
1433 SCI_BASE_CONTROLLER_STATE_FAILED
);
1438 /* If we dont process any completions I am not sure that we want to do this.
1439 * We are in the middle of a hardware fault and should probably be reset.
1441 writel(0, &scic
->smu_registers
->interrupt_mask
);
1447 void scic_sds_controller_link_up(struct scic_sds_controller
*scic
,
1448 struct scic_sds_port
*port
, struct scic_sds_phy
*phy
)
1450 switch (scic
->state_machine
.current_state_id
) {
1451 case SCI_BASE_CONTROLLER_STATE_STARTING
:
1452 scic_sds_controller_phy_timer_stop(scic
);
1453 scic
->port_agent
.link_up_handler(scic
, &scic
->port_agent
,
1455 scic_sds_controller_start_next_phy(scic
);
1457 case SCI_BASE_CONTROLLER_STATE_READY
:
1458 scic
->port_agent
.link_up_handler(scic
, &scic
->port_agent
,
1462 dev_dbg(scic_to_dev(scic
),
1463 "%s: SCIC Controller linkup event from phy %d in "
1464 "unexpected state %d\n", __func__
, phy
->phy_index
,
1465 scic
->state_machine
.current_state_id
);
1469 void scic_sds_controller_link_down(struct scic_sds_controller
*scic
,
1470 struct scic_sds_port
*port
, struct scic_sds_phy
*phy
)
1472 switch (scic
->state_machine
.current_state_id
) {
1473 case SCI_BASE_CONTROLLER_STATE_STARTING
:
1474 case SCI_BASE_CONTROLLER_STATE_READY
:
1475 scic
->port_agent
.link_down_handler(scic
, &scic
->port_agent
,
1479 dev_dbg(scic_to_dev(scic
),
1480 "%s: SCIC Controller linkdown event from phy %d in "
1481 "unexpected state %d\n",
1484 scic
->state_machine
.current_state_id
);
1489 * This is a helper method to determine if any remote devices on this
1490 * controller are still in the stopping state.
1493 static bool scic_sds_controller_has_remote_devices_stopping(
1494 struct scic_sds_controller
*controller
)
1498 for (index
= 0; index
< controller
->remote_node_entries
; index
++) {
1499 if ((controller
->device_table
[index
] != NULL
) &&
1500 (controller
->device_table
[index
]->state_machine
.current_state_id
1501 == SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
))
1509 * This method is called by the remote device to inform the controller
1510 * object that the remote device has stopped.
1512 void scic_sds_controller_remote_device_stopped(struct scic_sds_controller
*scic
,
1513 struct scic_sds_remote_device
*sci_dev
)
1515 if (scic
->state_machine
.current_state_id
!=
1516 SCI_BASE_CONTROLLER_STATE_STOPPING
) {
1517 dev_dbg(scic_to_dev(scic
),
1518 "SCIC Controller 0x%p remote device stopped event "
1519 "from device 0x%p in unexpected state %d\n",
1521 scic
->state_machine
.current_state_id
);
1525 if (!scic_sds_controller_has_remote_devices_stopping(scic
)) {
1526 sci_base_state_machine_change_state(&scic
->state_machine
,
1527 SCI_BASE_CONTROLLER_STATE_STOPPED
);
1532 * This method will write to the SCU PCP register the request value. The method
1533 * is used to suspend/resume ports, devices, and phys.
1538 void scic_sds_controller_post_request(
1539 struct scic_sds_controller
*scic
,
1542 dev_dbg(scic_to_dev(scic
),
1543 "%s: SCIC Controller 0x%p post request 0x%08x\n",
1548 writel(request
, &scic
->smu_registers
->post_context_port
);
1552 * This method will copy the soft copy of the task context into the physical
1553 * memory accessible by the controller.
1554 * @scic: This parameter specifies the controller for which to copy
1556 * @sci_req: This parameter specifies the request for which the task
1557 * context is being copied.
1559 * After this call is made the SCIC_SDS_IO_REQUEST object will always point to
1560 * the physical memory version of the task context. Thus, all subsequent
1561 * updates to the task context are performed in the TC table (i.e. DMAable
1564 void scic_sds_controller_copy_task_context(
1565 struct scic_sds_controller
*scic
,
1566 struct scic_sds_request
*sci_req
)
1568 struct scu_task_context
*task_context_buffer
;
1570 task_context_buffer
= scic_sds_controller_get_task_context_buffer(
1571 scic
, sci_req
->io_tag
);
1573 memcpy(task_context_buffer
,
1574 sci_req
->task_context_buffer
,
1575 SCI_FIELD_OFFSET(struct scu_task_context
, sgl_snapshot_ac
));
1578 * Now that the soft copy of the TC has been copied into the TC
1579 * table accessible by the silicon. Thus, any further changes to
1580 * the TC (e.g. TC termination) occur in the appropriate location. */
1581 sci_req
->task_context_buffer
= task_context_buffer
;
1585 * This method returns the task context buffer for the given io tag.
1589 * struct scu_task_context*
1591 struct scu_task_context
*scic_sds_controller_get_task_context_buffer(
1592 struct scic_sds_controller
*scic
,
1595 u16 task_index
= scic_sds_io_tag_get_index(io_tag
);
1597 if (task_index
< scic
->task_context_entries
) {
1598 return &scic
->task_context_table
[task_index
];
1604 struct scic_sds_request
*scic_request_by_tag(struct scic_sds_controller
*scic
,
1610 task_index
= scic_sds_io_tag_get_index(io_tag
);
1612 if (task_index
< scic
->task_context_entries
) {
1613 if (scic
->io_request_table
[task_index
] != NULL
) {
1614 task_sequence
= scic_sds_io_tag_get_sequence(io_tag
);
1616 if (task_sequence
== scic
->io_request_sequence
[task_index
]) {
1617 return scic
->io_request_table
[task_index
];
1626 * This method allocates remote node index and the reserves the remote node
1627 * context space for use. This method can fail if there are no more remote
1628 * node index available.
1629 * @scic: This is the controller object which contains the set of
1630 * free remote node ids
1631 * @sci_dev: This is the device object which is requesting the a remote node
1633 * @node_id: This is the remote node id that is assinged to the device if one
1636 * enum sci_status SCI_FAILURE_OUT_OF_RESOURCES if there are no available remote
1637 * node index available.
1639 enum sci_status
scic_sds_controller_allocate_remote_node_context(
1640 struct scic_sds_controller
*scic
,
1641 struct scic_sds_remote_device
*sci_dev
,
1645 u32 remote_node_count
= scic_sds_remote_device_node_count(sci_dev
);
1647 node_index
= scic_sds_remote_node_table_allocate_remote_node(
1648 &scic
->available_remote_nodes
, remote_node_count
1651 if (node_index
!= SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
) {
1652 scic
->device_table
[node_index
] = sci_dev
;
1654 *node_id
= node_index
;
1659 return SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1663 * This method frees the remote node index back to the available pool. Once
1664 * this is done the remote node context buffer is no longer valid and can
1671 void scic_sds_controller_free_remote_node_context(
1672 struct scic_sds_controller
*scic
,
1673 struct scic_sds_remote_device
*sci_dev
,
1676 u32 remote_node_count
= scic_sds_remote_device_node_count(sci_dev
);
1678 if (scic
->device_table
[node_id
] == sci_dev
) {
1679 scic
->device_table
[node_id
] = NULL
;
1681 scic_sds_remote_node_table_release_remote_node_index(
1682 &scic
->available_remote_nodes
, remote_node_count
, node_id
1688 * This method returns the union scu_remote_node_context for the specified remote
1693 * union scu_remote_node_context*
1695 union scu_remote_node_context
*scic_sds_controller_get_remote_node_context_buffer(
1696 struct scic_sds_controller
*scic
,
1700 (node_id
< scic
->remote_node_entries
)
1701 && (scic
->device_table
[node_id
] != NULL
)
1703 return &scic
->remote_node_context_table
[node_id
];
1711 * @resposne_buffer: This is the buffer into which the D2H register FIS will be
1713 * @frame_header: This is the frame header returned by the hardware.
1714 * @frame_buffer: This is the frame buffer returned by the hardware.
1716 * This method will combind the frame header and frame buffer to create a SATA
1717 * D2H register FIS none
1719 void scic_sds_controller_copy_sata_response(
1720 void *response_buffer
,
1724 memcpy(response_buffer
, frame_header
, sizeof(u32
));
1726 memcpy(response_buffer
+ sizeof(u32
),
1728 sizeof(struct dev_to_host_fis
) - sizeof(u32
));
1732 * This method releases the frame once this is done the frame is available for
1733 * re-use by the hardware. The data contained in the frame header and frame
1734 * buffer is no longer valid. The UF queue get pointer is only updated if UF
1735 * control indicates this is appropriate.
1740 void scic_sds_controller_release_frame(
1741 struct scic_sds_controller
*scic
,
1744 if (scic_sds_unsolicited_frame_control_release_frame(
1745 &scic
->uf_control
, frame_index
) == true)
1746 writel(scic
->uf_control
.get
,
1747 &scic
->scu_registers
->sdma
.unsolicited_frame_get_pointer
);
1751 * This method sets user parameters and OEM parameters to default values.
1752 * Users can override these values utilizing the scic_user_parameters_set()
1753 * and scic_oem_parameters_set() methods.
1754 * @scic: This parameter specifies the controller for which to set the
1755 * configuration parameters to their default values.
1758 static void scic_sds_controller_set_default_config_parameters(struct scic_sds_controller
*scic
)
1760 struct isci_host
*ihost
= scic_to_ihost(scic
);
1763 /* Default to APC mode. */
1764 scic
->oem_parameters
.sds1
.controller
.mode_type
= SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE
;
1766 /* Default to APC mode. */
1767 scic
->oem_parameters
.sds1
.controller
.max_concurrent_dev_spin_up
= 1;
1769 /* Default to no SSC operation. */
1770 scic
->oem_parameters
.sds1
.controller
.do_enable_ssc
= false;
1772 /* Initialize all of the port parameter information to narrow ports. */
1773 for (index
= 0; index
< SCI_MAX_PORTS
; index
++) {
1774 scic
->oem_parameters
.sds1
.ports
[index
].phy_mask
= 0;
1777 /* Initialize all of the phy parameter information. */
1778 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1779 /* Default to 6G (i.e. Gen 3) for now. */
1780 scic
->user_parameters
.sds1
.phys
[index
].max_speed_generation
= 3;
1782 /* the frequencies cannot be 0 */
1783 scic
->user_parameters
.sds1
.phys
[index
].align_insertion_frequency
= 0x7f;
1784 scic
->user_parameters
.sds1
.phys
[index
].in_connection_align_insertion_frequency
= 0xff;
1785 scic
->user_parameters
.sds1
.phys
[index
].notify_enable_spin_up_insertion_frequency
= 0x33;
1788 * Previous Vitesse based expanders had a arbitration issue that
1789 * is worked around by having the upper 32-bits of SAS address
1790 * with a value greater then the Vitesse company identifier.
1791 * Hence, usage of 0x5FCFFFFF. */
1792 scic
->oem_parameters
.sds1
.phys
[index
].sas_address
.low
= 0x1 + ihost
->id
;
1793 scic
->oem_parameters
.sds1
.phys
[index
].sas_address
.high
= 0x5FCFFFFF;
1796 scic
->user_parameters
.sds1
.stp_inactivity_timeout
= 5;
1797 scic
->user_parameters
.sds1
.ssp_inactivity_timeout
= 5;
1798 scic
->user_parameters
.sds1
.stp_max_occupancy_timeout
= 5;
1799 scic
->user_parameters
.sds1
.ssp_max_occupancy_timeout
= 20;
1800 scic
->user_parameters
.sds1
.no_outbound_task_timeout
= 20;
1804 * scic_controller_get_suggested_start_timeout() - This method returns the
1805 * suggested scic_controller_start() timeout amount. The user is free to
1806 * use any timeout value, but this method provides the suggested minimum
1807 * start timeout value. The returned value is based upon empirical
1808 * information determined as a result of interoperability testing.
1809 * @controller: the handle to the controller object for which to return the
1810 * suggested start timeout.
1812 * This method returns the number of milliseconds for the suggested start
1813 * operation timeout.
1815 u32
scic_controller_get_suggested_start_timeout(
1816 struct scic_sds_controller
*sc
)
1818 /* Validate the user supplied parameters. */
1823 * The suggested minimum timeout value for a controller start operation:
1825 * Signature FIS Timeout
1826 * + Phy Start Timeout
1827 * + Number of Phy Spin Up Intervals
1828 * ---------------------------------
1829 * Number of milliseconds for the controller start operation.
1831 * NOTE: The number of phy spin up intervals will be equivalent
1832 * to the number of phys divided by the number phys allowed
1833 * per interval - 1 (once OEM parameters are supported).
1834 * Currently we assume only 1 phy per interval. */
1836 return SCIC_SDS_SIGNATURE_FIS_TIMEOUT
1837 + SCIC_SDS_CONTROLLER_PHY_START_TIMEOUT
1838 + ((SCI_MAX_PHYS
- 1) * SCIC_SDS_CONTROLLER_POWER_CONTROL_INTERVAL
);
1842 * scic_controller_stop() - This method will stop an individual controller
1843 * object.This method will invoke the associated user callback upon
1844 * completion. The completion callback is called when the following
1845 * conditions are met: -# the method return status is SCI_SUCCESS. -# the
1846 * controller has been quiesced. This method will ensure that all IO
1847 * requests are quiesced, phys are stopped, and all additional operation by
1848 * the hardware is halted.
1849 * @controller: the handle to the controller object to stop.
1850 * @timeout: This parameter specifies the number of milliseconds in which the
1851 * stop operation should complete.
1853 * The controller must be in the STARTED or STOPPED state. Indicate if the
1854 * controller stop method succeeded or failed in some way. SCI_SUCCESS if the
1855 * stop operation successfully began. SCI_WARNING_ALREADY_IN_STATE if the
1856 * controller is already in the STOPPED state. SCI_FAILURE_INVALID_STATE if the
1857 * controller is not either in the STARTED or STOPPED states.
1859 enum sci_status
scic_controller_stop(
1860 struct scic_sds_controller
*scic
,
1863 if (scic
->state_machine
.current_state_id
!=
1864 SCI_BASE_CONTROLLER_STATE_READY
) {
1865 dev_warn(scic_to_dev(scic
),
1866 "SCIC Controller stop operation requested in "
1868 return SCI_FAILURE_INVALID_STATE
;
1871 isci_timer_start(scic
->timeout_timer
, timeout
);
1872 sci_base_state_machine_change_state(&scic
->state_machine
,
1873 SCI_BASE_CONTROLLER_STATE_STOPPING
);
1878 * scic_controller_reset() - This method will reset the supplied core
1879 * controller regardless of the state of said controller. This operation is
1880 * considered destructive. In other words, all current operations are wiped
1881 * out. No IO completions for outstanding devices occur. Outstanding IO
1882 * requests are not aborted or completed at the actual remote device.
1883 * @controller: the handle to the controller object to reset.
1885 * Indicate if the controller reset method succeeded or failed in some way.
1886 * SCI_SUCCESS if the reset operation successfully started. SCI_FATAL_ERROR if
1887 * the controller reset operation is unable to complete.
1889 enum sci_status
scic_controller_reset(
1890 struct scic_sds_controller
*scic
)
1892 switch (scic
->state_machine
.current_state_id
) {
1893 case SCI_BASE_CONTROLLER_STATE_RESET
:
1894 case SCI_BASE_CONTROLLER_STATE_READY
:
1895 case SCI_BASE_CONTROLLER_STATE_STOPPED
:
1896 case SCI_BASE_CONTROLLER_STATE_FAILED
:
1898 * The reset operation is not a graceful cleanup, just
1899 * perform the state transition.
1901 sci_base_state_machine_change_state(&scic
->state_machine
,
1902 SCI_BASE_CONTROLLER_STATE_RESETTING
);
1905 dev_warn(scic_to_dev(scic
),
1906 "SCIC Controller reset operation requested in "
1908 return SCI_FAILURE_INVALID_STATE
;
1913 * scic_controller_start_io() - This method is called by the SCI user to
1914 * send/start an IO request. If the method invocation is successful, then
1915 * the IO request has been queued to the hardware for processing.
1916 * @controller: the handle to the controller object for which to start an IO
1918 * @remote_device: the handle to the remote device object for which to start an
1920 * @io_request: the handle to the io request object to start.
1921 * @io_tag: This parameter specifies a previously allocated IO tag that the
1922 * user desires to be utilized for this request. This parameter is optional.
1923 * The user is allowed to supply SCI_CONTROLLER_INVALID_IO_TAG as the value
1924 * for this parameter.
1926 * - IO tags are a protected resource. It is incumbent upon the SCI Core user
1927 * to ensure that each of the methods that may allocate or free available IO
1928 * tags are handled in a mutually exclusive manner. This method is one of said
1929 * methods requiring proper critical code section protection (e.g. semaphore,
1930 * spin-lock, etc.). - For SATA, the user is required to manage NCQ tags. As a
1931 * result, it is expected the user will have set the NCQ tag field in the host
1932 * to device register FIS prior to calling this method. There is also a
1933 * requirement for the user to call scic_stp_io_set_ncq_tag() prior to invoking
1934 * the scic_controller_start_io() method. scic_controller_allocate_tag() for
1935 * more information on allocating a tag. Indicate if the controller
1936 * successfully started the IO request. SCI_SUCCESS if the IO request was
1937 * successfully started. Determine the failure situations and return values.
1939 enum sci_status
scic_controller_start_io(
1940 struct scic_sds_controller
*scic
,
1941 struct scic_sds_remote_device
*rdev
,
1942 struct scic_sds_request
*req
,
1945 enum sci_status status
;
1947 if (scic
->state_machine
.current_state_id
!=
1948 SCI_BASE_CONTROLLER_STATE_READY
) {
1949 dev_warn(scic_to_dev(scic
), "invalid state to start I/O");
1950 return SCI_FAILURE_INVALID_STATE
;
1953 status
= scic_sds_remote_device_start_io(scic
, rdev
, req
);
1954 if (status
!= SCI_SUCCESS
)
1957 scic
->io_request_table
[scic_sds_io_tag_get_index(req
->io_tag
)] = req
;
1958 scic_sds_controller_post_request(scic
, scic_sds_request_get_post_context(req
));
1963 * scic_controller_terminate_request() - This method is called by the SCI Core
1964 * user to terminate an ongoing (i.e. started) core IO request. This does
1965 * not abort the IO request at the target, but rather removes the IO request
1966 * from the host controller.
1967 * @controller: the handle to the controller object for which to terminate a
1969 * @remote_device: the handle to the remote device object for which to
1970 * terminate a request.
1971 * @request: the handle to the io or task management request object to
1974 * Indicate if the controller successfully began the terminate process for the
1975 * IO request. SCI_SUCCESS if the terminate process was successfully started
1976 * for the request. Determine the failure situations and return values.
1978 enum sci_status
scic_controller_terminate_request(
1979 struct scic_sds_controller
*scic
,
1980 struct scic_sds_remote_device
*rdev
,
1981 struct scic_sds_request
*req
)
1983 enum sci_status status
;
1985 if (scic
->state_machine
.current_state_id
!=
1986 SCI_BASE_CONTROLLER_STATE_READY
) {
1987 dev_warn(scic_to_dev(scic
),
1988 "invalid state to terminate request\n");
1989 return SCI_FAILURE_INVALID_STATE
;
1992 status
= scic_sds_io_request_terminate(req
);
1993 if (status
!= SCI_SUCCESS
)
1997 * Utilize the original post context command and or in the POST_TC_ABORT
2000 scic_sds_controller_post_request(scic
,
2001 scic_sds_request_get_post_context(req
) |
2002 SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT
);
2007 * scic_controller_complete_io() - This method will perform core specific
2008 * completion operations for an IO request. After this method is invoked,
2009 * the user should consider the IO request as invalid until it is properly
2010 * reused (i.e. re-constructed).
2011 * @controller: The handle to the controller object for which to complete the
2013 * @remote_device: The handle to the remote device object for which to complete
2015 * @io_request: the handle to the io request object to complete.
2017 * - IO tags are a protected resource. It is incumbent upon the SCI Core user
2018 * to ensure that each of the methods that may allocate or free available IO
2019 * tags are handled in a mutually exclusive manner. This method is one of said
2020 * methods requiring proper critical code section protection (e.g. semaphore,
2021 * spin-lock, etc.). - If the IO tag for a request was allocated, by the SCI
2022 * Core user, using the scic_controller_allocate_io_tag() method, then it is
2023 * the responsibility of the caller to invoke the scic_controller_free_io_tag()
2024 * method to free the tag (i.e. this method will not free the IO tag). Indicate
2025 * if the controller successfully completed the IO request. SCI_SUCCESS if the
2026 * completion process was successful.
2028 enum sci_status
scic_controller_complete_io(
2029 struct scic_sds_controller
*scic
,
2030 struct scic_sds_remote_device
*rdev
,
2031 struct scic_sds_request
*request
)
2033 enum sci_status status
;
2036 switch (scic
->state_machine
.current_state_id
) {
2037 case SCI_BASE_CONTROLLER_STATE_STOPPING
:
2038 /* XXX: Implement this function */
2040 case SCI_BASE_CONTROLLER_STATE_READY
:
2041 status
= scic_sds_remote_device_complete_io(scic
, rdev
, request
);
2042 if (status
!= SCI_SUCCESS
)
2045 index
= scic_sds_io_tag_get_index(request
->io_tag
);
2046 scic
->io_request_table
[index
] = NULL
;
2049 dev_warn(scic_to_dev(scic
), "invalid state to complete I/O");
2050 return SCI_FAILURE_INVALID_STATE
;
2055 enum sci_status
scic_controller_continue_io(struct scic_sds_request
*sci_req
)
2057 struct scic_sds_controller
*scic
= sci_req
->owning_controller
;
2059 if (scic
->state_machine
.current_state_id
!=
2060 SCI_BASE_CONTROLLER_STATE_READY
) {
2061 dev_warn(scic_to_dev(scic
), "invalid state to continue I/O");
2062 return SCI_FAILURE_INVALID_STATE
;
2065 scic
->io_request_table
[scic_sds_io_tag_get_index(sci_req
->io_tag
)] = sci_req
;
2066 scic_sds_controller_post_request(scic
, scic_sds_request_get_post_context(sci_req
));
2071 * scic_controller_start_task() - This method is called by the SCIC user to
2072 * send/start a framework task management request.
2073 * @controller: the handle to the controller object for which to start the task
2074 * management request.
2075 * @remote_device: the handle to the remote device object for which to start
2076 * the task management request.
2077 * @task_request: the handle to the task request object to start.
2078 * @io_tag: This parameter specifies a previously allocated IO tag that the
2079 * user desires to be utilized for this request. Note this not the io_tag
2080 * of the request being managed. It is to be utilized for the task request
2081 * itself. This parameter is optional. The user is allowed to supply
2082 * SCI_CONTROLLER_INVALID_IO_TAG as the value for this parameter.
2084 * - IO tags are a protected resource. It is incumbent upon the SCI Core user
2085 * to ensure that each of the methods that may allocate or free available IO
2086 * tags are handled in a mutually exclusive manner. This method is one of said
2087 * methods requiring proper critical code section protection (e.g. semaphore,
2088 * spin-lock, etc.). - The user must synchronize this task with completion
2089 * queue processing. If they are not synchronized then it is possible for the
2090 * io requests that are being managed by the task request can complete before
2091 * starting the task request. scic_controller_allocate_tag() for more
2092 * information on allocating a tag. Indicate if the controller successfully
2093 * started the IO request. SCI_TASK_SUCCESS if the task request was
2094 * successfully started. SCI_TASK_FAILURE_REQUIRES_SCSI_ABORT This value is
2095 * returned if there is/are task(s) outstanding that require termination or
2096 * completion before this request can succeed.
2098 enum sci_task_status
scic_controller_start_task(
2099 struct scic_sds_controller
*scic
,
2100 struct scic_sds_remote_device
*rdev
,
2101 struct scic_sds_request
*req
,
2104 enum sci_status status
;
2106 if (scic
->state_machine
.current_state_id
!=
2107 SCI_BASE_CONTROLLER_STATE_READY
) {
2108 dev_warn(scic_to_dev(scic
),
2109 "%s: SCIC Controller starting task from invalid "
2112 return SCI_TASK_FAILURE_INVALID_STATE
;
2115 status
= scic_sds_remote_device_start_task(scic
, rdev
, req
);
2117 case SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS
:
2118 scic
->io_request_table
[scic_sds_io_tag_get_index(req
->io_tag
)] = req
;
2121 * We will let framework know this task request started successfully,
2122 * although core is still woring on starting the request (to post tc when
2127 scic
->io_request_table
[scic_sds_io_tag_get_index(req
->io_tag
)] = req
;
2129 scic_sds_controller_post_request(scic
,
2130 scic_sds_request_get_post_context(req
));
2140 * scic_controller_allocate_io_tag() - This method will allocate a tag from the
2141 * pool of free IO tags. Direct allocation of IO tags by the SCI Core user
2142 * is optional. The scic_controller_start_io() method will allocate an IO
2143 * tag if this method is not utilized and the tag is not supplied to the IO
2144 * construct routine. Direct allocation of IO tags may provide additional
2145 * performance improvements in environments capable of supporting this usage
2146 * model. Additionally, direct allocation of IO tags also provides
2147 * additional flexibility to the SCI Core user. Specifically, the user may
2148 * retain IO tags across the lives of multiple IO requests.
2149 * @controller: the handle to the controller object for which to allocate the
2152 * IO tags are a protected resource. It is incumbent upon the SCI Core user to
2153 * ensure that each of the methods that may allocate or free available IO tags
2154 * are handled in a mutually exclusive manner. This method is one of said
2155 * methods requiring proper critical code section protection (e.g. semaphore,
2156 * spin-lock, etc.). An unsigned integer representing an available IO tag.
2157 * SCI_CONTROLLER_INVALID_IO_TAG This value is returned if there are no
2158 * currently available tags to be allocated. All return other values indicate a
2161 u16
scic_controller_allocate_io_tag(
2162 struct scic_sds_controller
*scic
)
2167 if (!sci_pool_empty(scic
->tci_pool
)) {
2168 sci_pool_get(scic
->tci_pool
, task_context
);
2170 sequence_count
= scic
->io_request_sequence
[task_context
];
2172 return scic_sds_io_tag_construct(sequence_count
, task_context
);
2175 return SCI_CONTROLLER_INVALID_IO_TAG
;
2179 * scic_controller_free_io_tag() - This method will free an IO tag to the pool
2180 * of free IO tags. This method provides the SCI Core user more flexibility
2181 * with regards to IO tags. The user may desire to keep an IO tag after an
2182 * IO request has completed, because they plan on re-using the tag for a
2183 * subsequent IO request. This method is only legal if the tag was
2184 * allocated via scic_controller_allocate_io_tag().
2185 * @controller: This parameter specifies the handle to the controller object
2186 * for which to free/return the tag.
2187 * @io_tag: This parameter represents the tag to be freed to the pool of
2190 * - IO tags are a protected resource. It is incumbent upon the SCI Core user
2191 * to ensure that each of the methods that may allocate or free available IO
2192 * tags are handled in a mutually exclusive manner. This method is one of said
2193 * methods requiring proper critical code section protection (e.g. semaphore,
2194 * spin-lock, etc.). - If the IO tag for a request was allocated, by the SCI
2195 * Core user, using the scic_controller_allocate_io_tag() method, then it is
2196 * the responsibility of the caller to invoke this method to free the tag. This
2197 * method returns an indication of whether the tag was successfully put back
2198 * (freed) to the pool of available tags. SCI_SUCCESS This return value
2199 * indicates the tag was successfully placed into the pool of available IO
2200 * tags. SCI_FAILURE_INVALID_IO_TAG This value is returned if the supplied tag
2201 * is not a valid IO tag value.
2203 enum sci_status
scic_controller_free_io_tag(
2204 struct scic_sds_controller
*scic
,
2210 BUG_ON(io_tag
== SCI_CONTROLLER_INVALID_IO_TAG
);
2212 sequence
= scic_sds_io_tag_get_sequence(io_tag
);
2213 index
= scic_sds_io_tag_get_index(io_tag
);
2215 if (!sci_pool_full(scic
->tci_pool
)) {
2216 if (sequence
== scic
->io_request_sequence
[index
]) {
2217 scic_sds_io_sequence_increment(
2218 scic
->io_request_sequence
[index
]);
2220 sci_pool_put(scic
->tci_pool
, index
);
2226 return SCI_FAILURE_INVALID_IO_TAG
;
2229 void scic_controller_enable_interrupts(
2230 struct scic_sds_controller
*scic
)
2232 BUG_ON(scic
->smu_registers
== NULL
);
2233 writel(0, &scic
->smu_registers
->interrupt_mask
);
2236 void scic_controller_disable_interrupts(
2237 struct scic_sds_controller
*scic
)
2239 BUG_ON(scic
->smu_registers
== NULL
);
2240 writel(0xffffffff, &scic
->smu_registers
->interrupt_mask
);
2243 static enum sci_status
scic_controller_set_mode(
2244 struct scic_sds_controller
*scic
,
2245 enum sci_controller_mode operating_mode
)
2247 enum sci_status status
= SCI_SUCCESS
;
2249 if ((scic
->state_machine
.current_state_id
==
2250 SCI_BASE_CONTROLLER_STATE_INITIALIZING
) ||
2251 (scic
->state_machine
.current_state_id
==
2252 SCI_BASE_CONTROLLER_STATE_INITIALIZED
)) {
2253 switch (operating_mode
) {
2254 case SCI_MODE_SPEED
:
2255 scic
->remote_node_entries
= SCI_MAX_REMOTE_DEVICES
;
2256 scic
->task_context_entries
= SCU_IO_REQUEST_COUNT
;
2257 scic
->uf_control
.buffers
.count
=
2258 SCU_UNSOLICITED_FRAME_COUNT
;
2259 scic
->completion_event_entries
= SCU_EVENT_COUNT
;
2260 scic
->completion_queue_entries
=
2261 SCU_COMPLETION_QUEUE_COUNT
;
2265 scic
->remote_node_entries
= SCI_MIN_REMOTE_DEVICES
;
2266 scic
->task_context_entries
= SCI_MIN_IO_REQUESTS
;
2267 scic
->uf_control
.buffers
.count
=
2268 SCU_MIN_UNSOLICITED_FRAMES
;
2269 scic
->completion_event_entries
= SCU_MIN_EVENTS
;
2270 scic
->completion_queue_entries
=
2271 SCU_MIN_COMPLETION_QUEUE_ENTRIES
;
2275 status
= SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2279 status
= SCI_FAILURE_INVALID_STATE
;
2285 * scic_sds_controller_reset_hardware() -
2287 * This method will reset the controller hardware.
2289 static void scic_sds_controller_reset_hardware(
2290 struct scic_sds_controller
*scic
)
2292 /* Disable interrupts so we dont take any spurious interrupts */
2293 scic_controller_disable_interrupts(scic
);
2296 writel(0xFFFFFFFF, &scic
->smu_registers
->soft_reset_control
);
2298 /* Delay for 1ms to before clearing the CQP and UFQPR. */
2301 /* The write to the CQGR clears the CQP */
2302 writel(0x00000000, &scic
->smu_registers
->completion_queue_get
);
2304 /* The write to the UFQGP clears the UFQPR */
2305 writel(0, &scic
->scu_registers
->sdma
.unsolicited_frame_get_pointer
);
2308 enum sci_status
scic_user_parameters_set(
2309 struct scic_sds_controller
*scic
,
2310 union scic_user_parameters
*scic_parms
)
2312 u32 state
= scic
->state_machine
.current_state_id
;
2314 if (state
== SCI_BASE_CONTROLLER_STATE_RESET
||
2315 state
== SCI_BASE_CONTROLLER_STATE_INITIALIZING
||
2316 state
== SCI_BASE_CONTROLLER_STATE_INITIALIZED
) {
2320 * Validate the user parameters. If they are not legal, then
2323 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
2324 struct sci_phy_user_params
*user_phy
;
2326 user_phy
= &scic_parms
->sds1
.phys
[index
];
2328 if (!((user_phy
->max_speed_generation
<=
2329 SCIC_SDS_PARM_MAX_SPEED
) &&
2330 (user_phy
->max_speed_generation
>
2331 SCIC_SDS_PARM_NO_SPEED
)))
2332 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2334 if (user_phy
->in_connection_align_insertion_frequency
<
2336 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2338 if ((user_phy
->in_connection_align_insertion_frequency
<
2340 (user_phy
->align_insertion_frequency
== 0) ||
2342 notify_enable_spin_up_insertion_frequency
==
2344 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2347 if ((scic_parms
->sds1
.stp_inactivity_timeout
== 0) ||
2348 (scic_parms
->sds1
.ssp_inactivity_timeout
== 0) ||
2349 (scic_parms
->sds1
.stp_max_occupancy_timeout
== 0) ||
2350 (scic_parms
->sds1
.ssp_max_occupancy_timeout
== 0) ||
2351 (scic_parms
->sds1
.no_outbound_task_timeout
== 0))
2352 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2354 memcpy(&scic
->user_parameters
, scic_parms
, sizeof(*scic_parms
));
2359 return SCI_FAILURE_INVALID_STATE
;
2362 int scic_oem_parameters_validate(struct scic_sds_oem_params
*oem
)
2366 for (i
= 0; i
< SCI_MAX_PORTS
; i
++)
2367 if (oem
->ports
[i
].phy_mask
> SCIC_SDS_PARM_PHY_MASK_MAX
)
2370 for (i
= 0; i
< SCI_MAX_PHYS
; i
++)
2371 if (oem
->phys
[i
].sas_address
.high
== 0 &&
2372 oem
->phys
[i
].sas_address
.low
== 0)
2375 if (oem
->controller
.mode_type
== SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE
) {
2376 for (i
= 0; i
< SCI_MAX_PHYS
; i
++)
2377 if (oem
->ports
[i
].phy_mask
!= 0)
2379 } else if (oem
->controller
.mode_type
== SCIC_PORT_MANUAL_CONFIGURATION_MODE
) {
2382 for (i
= 0; i
< SCI_MAX_PHYS
; i
++)
2383 phy_mask
|= oem
->ports
[i
].phy_mask
;
2390 if (oem
->controller
.max_concurrent_dev_spin_up
> MAX_CONCURRENT_DEVICE_SPIN_UP_COUNT
)
2396 enum sci_status
scic_oem_parameters_set(struct scic_sds_controller
*scic
,
2397 union scic_oem_parameters
*scic_parms
)
2399 u32 state
= scic
->state_machine
.current_state_id
;
2401 if (state
== SCI_BASE_CONTROLLER_STATE_RESET
||
2402 state
== SCI_BASE_CONTROLLER_STATE_INITIALIZING
||
2403 state
== SCI_BASE_CONTROLLER_STATE_INITIALIZED
) {
2405 if (scic_oem_parameters_validate(&scic_parms
->sds1
))
2406 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2407 scic
->oem_parameters
.sds1
= scic_parms
->sds1
;
2412 return SCI_FAILURE_INVALID_STATE
;
2415 void scic_oem_parameters_get(
2416 struct scic_sds_controller
*scic
,
2417 union scic_oem_parameters
*scic_parms
)
2419 memcpy(scic_parms
, (&scic
->oem_parameters
), sizeof(*scic_parms
));
2422 #define INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_LOWER_BOUND_NS 853
2423 #define INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_UPPER_BOUND_NS 1280
2424 #define INTERRUPT_COALESCE_TIMEOUT_MAX_US 2700000
2425 #define INTERRUPT_COALESCE_NUMBER_MAX 256
2426 #define INTERRUPT_COALESCE_TIMEOUT_ENCODE_MIN 7
2427 #define INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX 28
2430 * scic_controller_set_interrupt_coalescence() - This method allows the user to
2431 * configure the interrupt coalescence.
2432 * @controller: This parameter represents the handle to the controller object
2433 * for which its interrupt coalesce register is overridden.
2434 * @coalesce_number: Used to control the number of entries in the Completion
2435 * Queue before an interrupt is generated. If the number of entries exceed
2436 * this number, an interrupt will be generated. The valid range of the input
2437 * is [0, 256]. A setting of 0 results in coalescing being disabled.
2438 * @coalesce_timeout: Timeout value in microseconds. The valid range of the
2439 * input is [0, 2700000] . A setting of 0 is allowed and results in no
2440 * interrupt coalescing timeout.
2442 * Indicate if the user successfully set the interrupt coalesce parameters.
2443 * SCI_SUCCESS The user successfully updated the interrutp coalescence.
2444 * SCI_FAILURE_INVALID_PARAMETER_VALUE The user input value is out of range.
2446 static enum sci_status
scic_controller_set_interrupt_coalescence(
2447 struct scic_sds_controller
*scic_controller
,
2448 u32 coalesce_number
,
2449 u32 coalesce_timeout
)
2451 u8 timeout_encode
= 0;
2455 /* Check if the input parameters fall in the range. */
2456 if (coalesce_number
> INTERRUPT_COALESCE_NUMBER_MAX
)
2457 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2460 * Defined encoding for interrupt coalescing timeout:
2461 * Value Min Max Units
2462 * ----- --- --- -----
2492 * Others Undefined */
2495 * Use the table above to decide the encode of interrupt coalescing timeout
2496 * value for register writing. */
2497 if (coalesce_timeout
== 0)
2500 /* make the timeout value in unit of (10 ns). */
2501 coalesce_timeout
= coalesce_timeout
* 100;
2502 min
= INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_LOWER_BOUND_NS
/ 10;
2503 max
= INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_UPPER_BOUND_NS
/ 10;
2505 /* get the encode of timeout for register writing. */
2506 for (timeout_encode
= INTERRUPT_COALESCE_TIMEOUT_ENCODE_MIN
;
2507 timeout_encode
<= INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX
;
2509 if (min
<= coalesce_timeout
&& max
> coalesce_timeout
)
2511 else if (coalesce_timeout
>= max
&& coalesce_timeout
< min
* 2
2512 && coalesce_timeout
<= INTERRUPT_COALESCE_TIMEOUT_MAX_US
* 100) {
2513 if ((coalesce_timeout
- max
) < (2 * min
- coalesce_timeout
))
2525 if (timeout_encode
== INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX
+ 1)
2526 /* the value is out of range. */
2527 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2530 writel(SMU_ICC_GEN_VAL(NUMBER
, coalesce_number
) |
2531 SMU_ICC_GEN_VAL(TIMER
, timeout_encode
),
2532 &scic_controller
->smu_registers
->interrupt_coalesce_control
);
2535 scic_controller
->interrupt_coalesce_number
= (u16
)coalesce_number
;
2536 scic_controller
->interrupt_coalesce_timeout
= coalesce_timeout
/ 100;
2543 enum sci_status
scic_controller_initialize(struct scic_sds_controller
*scic
)
2545 struct sci_base_state_machine
*sm
= &scic
->state_machine
;
2546 enum sci_status result
= SCI_SUCCESS
;
2547 struct isci_host
*ihost
= scic_to_ihost(scic
);
2550 if (scic
->state_machine
.current_state_id
!=
2551 SCI_BASE_CONTROLLER_STATE_RESET
) {
2552 dev_warn(scic_to_dev(scic
),
2553 "SCIC Controller initialize operation requested "
2554 "in invalid state\n");
2555 return SCI_FAILURE_INVALID_STATE
;
2558 sci_base_state_machine_change_state(sm
, SCI_BASE_CONTROLLER_STATE_INITIALIZING
);
2560 scic
->timeout_timer
= isci_timer_create(ihost
,
2562 scic_sds_controller_timeout_handler
);
2564 scic_sds_controller_initialize_phy_startup(scic
);
2566 scic_sds_controller_initialize_power_control(scic
);
2569 * There is nothing to do here for B0 since we do not have to
2570 * program the AFE registers.
2571 * / @todo The AFE settings are supposed to be correct for the B0 but
2572 * / presently they seem to be wrong. */
2573 scic_sds_controller_afe_initialization(scic
);
2575 if (result
== SCI_SUCCESS
) {
2579 /* Take the hardware out of reset */
2580 writel(0, &scic
->smu_registers
->soft_reset_control
);
2583 * / @todo Provide meaningfull error code for hardware failure
2584 * result = SCI_FAILURE_CONTROLLER_HARDWARE; */
2585 result
= SCI_FAILURE
;
2586 terminate_loop
= 100;
2588 while (terminate_loop
-- && (result
!= SCI_SUCCESS
)) {
2589 /* Loop until the hardware reports success */
2590 udelay(SCU_CONTEXT_RAM_INIT_STALL_TIME
);
2591 status
= readl(&scic
->smu_registers
->control_status
);
2593 if ((status
& SCU_RAM_INIT_COMPLETED
) ==
2594 SCU_RAM_INIT_COMPLETED
)
2595 result
= SCI_SUCCESS
;
2599 if (result
== SCI_SUCCESS
) {
2600 u32 max_supported_ports
;
2601 u32 max_supported_devices
;
2602 u32 max_supported_io_requests
;
2603 u32 device_context_capacity
;
2606 * Determine what are the actaul device capacities that the
2607 * hardware will support */
2608 device_context_capacity
=
2609 readl(&scic
->smu_registers
->device_context_capacity
);
2612 max_supported_ports
= smu_dcc_get_max_ports(device_context_capacity
);
2613 max_supported_devices
= smu_dcc_get_max_remote_node_context(device_context_capacity
);
2614 max_supported_io_requests
= smu_dcc_get_max_task_context(device_context_capacity
);
2617 * Make all PEs that are unassigned match up with the
2620 for (index
= 0; index
< max_supported_ports
; index
++) {
2621 struct scu_port_task_scheduler_group_registers __iomem
2622 *ptsg
= &scic
->scu_registers
->peg0
.ptsg
;
2624 writel(index
, &ptsg
->protocol_engine
[index
]);
2627 /* Record the smaller of the two capacity values */
2628 scic
->logical_port_entries
=
2629 min(max_supported_ports
, scic
->logical_port_entries
);
2631 scic
->task_context_entries
=
2632 min(max_supported_io_requests
,
2633 scic
->task_context_entries
);
2635 scic
->remote_node_entries
=
2636 min(max_supported_devices
, scic
->remote_node_entries
);
2639 * Now that we have the correct hardware reported minimum values
2640 * build the MDL for the controller. Default to a performance
2643 scic_controller_set_mode(scic
, SCI_MODE_SPEED
);
2646 /* Initialize hardware PCI Relaxed ordering in DMA engines */
2647 if (result
== SCI_SUCCESS
) {
2648 u32 dma_configuration
;
2650 /* Configure the payload DMA */
2652 readl(&scic
->scu_registers
->sdma
.pdma_configuration
);
2653 dma_configuration
|=
2654 SCU_PDMACR_GEN_BIT(PCI_RELAXED_ORDERING_ENABLE
);
2655 writel(dma_configuration
,
2656 &scic
->scu_registers
->sdma
.pdma_configuration
);
2658 /* Configure the control DMA */
2660 readl(&scic
->scu_registers
->sdma
.cdma_configuration
);
2661 dma_configuration
|=
2662 SCU_CDMACR_GEN_BIT(PCI_RELAXED_ORDERING_ENABLE
);
2663 writel(dma_configuration
,
2664 &scic
->scu_registers
->sdma
.cdma_configuration
);
2668 * Initialize the PHYs before the PORTs because the PHY registers
2669 * are accessed during the port initialization.
2671 if (result
== SCI_SUCCESS
) {
2672 /* Initialize the phys */
2674 (result
== SCI_SUCCESS
) && (index
< SCI_MAX_PHYS
);
2676 result
= scic_sds_phy_initialize(
2677 &ihost
->phys
[index
].sci
,
2678 &scic
->scu_registers
->peg0
.pe
[index
].tl
,
2679 &scic
->scu_registers
->peg0
.pe
[index
].ll
);
2683 if (result
== SCI_SUCCESS
) {
2684 /* Initialize the logical ports */
2686 (index
< scic
->logical_port_entries
) &&
2687 (result
== SCI_SUCCESS
);
2689 result
= scic_sds_port_initialize(
2690 &ihost
->ports
[index
].sci
,
2691 &scic
->scu_registers
->peg0
.ptsg
.port
[index
],
2692 &scic
->scu_registers
->peg0
.ptsg
.protocol_engine
,
2693 &scic
->scu_registers
->peg0
.viit
[index
]);
2697 if (result
== SCI_SUCCESS
)
2698 result
= scic_sds_port_configuration_agent_initialize(
2702 /* Advance the controller state machine */
2703 if (result
== SCI_SUCCESS
)
2704 state
= SCI_BASE_CONTROLLER_STATE_INITIALIZED
;
2706 state
= SCI_BASE_CONTROLLER_STATE_FAILED
;
2707 sci_base_state_machine_change_state(sm
, state
);
2712 enum sci_status
scic_controller_start(struct scic_sds_controller
*scic
,
2715 struct isci_host
*ihost
= scic_to_ihost(scic
);
2716 enum sci_status result
;
2719 if (scic
->state_machine
.current_state_id
!=
2720 SCI_BASE_CONTROLLER_STATE_INITIALIZED
) {
2721 dev_warn(scic_to_dev(scic
),
2722 "SCIC Controller start operation requested in "
2724 return SCI_FAILURE_INVALID_STATE
;
2727 /* Build the TCi free pool */
2728 sci_pool_initialize(scic
->tci_pool
);
2729 for (index
= 0; index
< scic
->task_context_entries
; index
++)
2730 sci_pool_put(scic
->tci_pool
, index
);
2732 /* Build the RNi free pool */
2733 scic_sds_remote_node_table_initialize(
2734 &scic
->available_remote_nodes
,
2735 scic
->remote_node_entries
);
2738 * Before anything else lets make sure we will not be
2739 * interrupted by the hardware.
2741 scic_controller_disable_interrupts(scic
);
2743 /* Enable the port task scheduler */
2744 scic_sds_controller_enable_port_task_scheduler(scic
);
2746 /* Assign all the task entries to scic physical function */
2747 scic_sds_controller_assign_task_entries(scic
);
2749 /* Now initialize the completion queue */
2750 scic_sds_controller_initialize_completion_queue(scic
);
2752 /* Initialize the unsolicited frame queue for use */
2753 scic_sds_controller_initialize_unsolicited_frame_queue(scic
);
2755 /* Start all of the ports on this controller */
2756 for (index
= 0; index
< scic
->logical_port_entries
; index
++) {
2757 struct scic_sds_port
*sci_port
= &ihost
->ports
[index
].sci
;
2759 result
= sci_port
->state_handlers
->start_handler(sci_port
);
2764 scic_sds_controller_start_next_phy(scic
);
2766 isci_timer_start(scic
->timeout_timer
, timeout
);
2768 sci_base_state_machine_change_state(&scic
->state_machine
,
2769 SCI_BASE_CONTROLLER_STATE_STARTING
);
2776 * @object: This is the object which is cast to a struct scic_sds_controller
2779 * This method implements the actions taken by the struct scic_sds_controller on entry
2780 * to the SCI_BASE_CONTROLLER_STATE_INITIAL. - Set the state handlers to the
2781 * controllers initial state. none This function should initialize the
2782 * controller object.
2784 static void scic_sds_controller_initial_state_enter(void *object
)
2786 struct scic_sds_controller
*scic
= object
;
2788 sci_base_state_machine_change_state(&scic
->state_machine
,
2789 SCI_BASE_CONTROLLER_STATE_RESET
);
2794 * @object: This is the object which is cast to a struct scic_sds_controller
2797 * This method implements the actions taken by the struct scic_sds_controller on exit
2798 * from the SCI_BASE_CONTROLLER_STATE_STARTING. - This function stops the
2799 * controller starting timeout timer. none
2801 static inline void scic_sds_controller_starting_state_exit(void *object
)
2803 struct scic_sds_controller
*scic
= object
;
2805 isci_timer_stop(scic
->timeout_timer
);
2810 * @object: This is the object which is cast to a struct scic_sds_controller
2813 * This method implements the actions taken by the struct scic_sds_controller on entry
2814 * to the SCI_BASE_CONTROLLER_STATE_READY. - Set the state handlers to the
2815 * controllers ready state. none
2817 static void scic_sds_controller_ready_state_enter(void *object
)
2819 struct scic_sds_controller
*scic
= object
;
2821 /* set the default interrupt coalescence number and timeout value. */
2822 scic_controller_set_interrupt_coalescence(
2828 * @object: This is the object which is cast to a struct scic_sds_controller
2831 * This method implements the actions taken by the struct scic_sds_controller on exit
2832 * from the SCI_BASE_CONTROLLER_STATE_READY. - This function does nothing. none
2834 static void scic_sds_controller_ready_state_exit(void *object
)
2836 struct scic_sds_controller
*scic
= object
;
2838 /* disable interrupt coalescence. */
2839 scic_controller_set_interrupt_coalescence(scic
, 0, 0);
2844 * @object: This is the object which is cast to a struct scic_sds_controller
2847 * This method implements the actions taken by the struct scic_sds_controller on entry
2848 * to the SCI_BASE_CONTROLLER_STATE_READY. - Set the state handlers to the
2849 * controllers ready state. - Stop the phys on this controller - Stop the ports
2850 * on this controller - Stop all of the remote devices on this controller none
2852 static void scic_sds_controller_stopping_state_enter(void *object
)
2854 struct scic_sds_controller
*scic
= object
;
2856 /* Stop all of the components for this controller */
2857 scic_sds_controller_stop_phys(scic
);
2858 scic_sds_controller_stop_ports(scic
);
2859 scic_sds_controller_stop_devices(scic
);
2864 * @object: This is the object which is cast to a struct
2865 * scic_sds_controller object.
2867 * This function implements the actions taken by the struct scic_sds_controller
2868 * on exit from the SCI_BASE_CONTROLLER_STATE_STOPPING. -
2869 * This function stops the controller stopping timeout timer.
2871 static inline void scic_sds_controller_stopping_state_exit(void *object
)
2873 struct scic_sds_controller
*scic
= object
;
2875 isci_timer_stop(scic
->timeout_timer
);
2878 static void scic_sds_controller_resetting_state_enter(void *object
)
2880 struct scic_sds_controller
*scic
= object
;
2882 scic_sds_controller_reset_hardware(scic
);
2883 sci_base_state_machine_change_state(&scic
->state_machine
,
2884 SCI_BASE_CONTROLLER_STATE_RESET
);
2887 static const struct sci_base_state scic_sds_controller_state_table
[] = {
2888 [SCI_BASE_CONTROLLER_STATE_INITIAL
] = {
2889 .enter_state
= scic_sds_controller_initial_state_enter
,
2891 [SCI_BASE_CONTROLLER_STATE_RESET
] = {},
2892 [SCI_BASE_CONTROLLER_STATE_INITIALIZING
] = {},
2893 [SCI_BASE_CONTROLLER_STATE_INITIALIZED
] = {},
2894 [SCI_BASE_CONTROLLER_STATE_STARTING
] = {
2895 .exit_state
= scic_sds_controller_starting_state_exit
,
2897 [SCI_BASE_CONTROLLER_STATE_READY
] = {
2898 .enter_state
= scic_sds_controller_ready_state_enter
,
2899 .exit_state
= scic_sds_controller_ready_state_exit
,
2901 [SCI_BASE_CONTROLLER_STATE_RESETTING
] = {
2902 .enter_state
= scic_sds_controller_resetting_state_enter
,
2904 [SCI_BASE_CONTROLLER_STATE_STOPPING
] = {
2905 .enter_state
= scic_sds_controller_stopping_state_enter
,
2906 .exit_state
= scic_sds_controller_stopping_state_exit
,
2908 [SCI_BASE_CONTROLLER_STATE_STOPPED
] = {},
2909 [SCI_BASE_CONTROLLER_STATE_FAILED
] = {}
2913 * scic_controller_construct() - This method will attempt to construct a
2914 * controller object utilizing the supplied parameter information.
2915 * @c: This parameter specifies the controller to be constructed.
2916 * @scu_base: mapped base address of the scu registers
2917 * @smu_base: mapped base address of the smu registers
2919 * Indicate if the controller was successfully constructed or if it failed in
2920 * some way. SCI_SUCCESS This value is returned if the controller was
2921 * successfully constructed. SCI_WARNING_TIMER_CONFLICT This value is returned
2922 * if the interrupt coalescence timer may cause SAS compliance issues for SMP
2923 * Target mode response processing. SCI_FAILURE_UNSUPPORTED_CONTROLLER_TYPE
2924 * This value is returned if the controller does not support the supplied type.
2925 * SCI_FAILURE_UNSUPPORTED_INIT_DATA_VERSION This value is returned if the
2926 * controller does not support the supplied initialization data version.
2928 enum sci_status
scic_controller_construct(struct scic_sds_controller
*scic
,
2929 void __iomem
*scu_base
,
2930 void __iomem
*smu_base
)
2932 struct isci_host
*ihost
= scic_to_ihost(scic
);
2935 sci_base_state_machine_construct(&scic
->state_machine
,
2936 scic
, scic_sds_controller_state_table
,
2937 SCI_BASE_CONTROLLER_STATE_INITIAL
);
2939 sci_base_state_machine_start(&scic
->state_machine
);
2941 scic
->scu_registers
= scu_base
;
2942 scic
->smu_registers
= smu_base
;
2944 scic_sds_port_configuration_agent_construct(&scic
->port_agent
);
2946 /* Construct the ports for this controller */
2947 for (i
= 0; i
< SCI_MAX_PORTS
; i
++)
2948 scic_sds_port_construct(&ihost
->ports
[i
].sci
, i
, scic
);
2949 scic_sds_port_construct(&ihost
->ports
[i
].sci
, SCIC_SDS_DUMMY_PORT
, scic
);
2951 /* Construct the phys for this controller */
2952 for (i
= 0; i
< SCI_MAX_PHYS
; i
++) {
2953 /* Add all the PHYs to the dummy port */
2954 scic_sds_phy_construct(&ihost
->phys
[i
].sci
,
2955 &ihost
->ports
[SCI_MAX_PORTS
].sci
, i
);
2958 scic
->invalid_phy_mask
= 0;
2960 /* Set the default maximum values */
2961 scic
->completion_event_entries
= SCU_EVENT_COUNT
;
2962 scic
->completion_queue_entries
= SCU_COMPLETION_QUEUE_COUNT
;
2963 scic
->remote_node_entries
= SCI_MAX_REMOTE_DEVICES
;
2964 scic
->logical_port_entries
= SCI_MAX_PORTS
;
2965 scic
->task_context_entries
= SCU_IO_REQUEST_COUNT
;
2966 scic
->uf_control
.buffers
.count
= SCU_UNSOLICITED_FRAME_COUNT
;
2967 scic
->uf_control
.address_table
.count
= SCU_UNSOLICITED_FRAME_COUNT
;
2969 /* Initialize the User and OEM parameters to default values. */
2970 scic_sds_controller_set_default_config_parameters(scic
);
2972 return scic_controller_reset(scic
);