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>
57 #include "scic_controller.h"
59 #include "scic_port.h"
60 #include "scic_remote_device.h"
61 #include "scic_sds_controller.h"
62 #include "scic_sds_controller_registers.h"
63 #include "scic_sds_pci.h"
64 #include "scic_sds_phy.h"
65 #include "scic_sds_port_configuration_agent.h"
66 #include "scic_sds_port.h"
67 #include "scic_sds_remote_device.h"
68 #include "scic_sds_request.h"
69 #include "sci_environment.h"
71 #include "scu_completion_codes.h"
72 #include "scu_constants.h"
73 #include "scu_event_codes.h"
74 #include "scu_remote_node_context.h"
75 #include "scu_task_context.h"
76 #include "scu_unsolicited_frame.h"
78 #define SCU_CONTEXT_RAM_INIT_STALL_TIME 200
81 * smu_dcc_get_max_ports() -
83 * This macro returns the maximum number of logical ports supported by the
84 * hardware. The caller passes in the value read from the device context
85 * capacity register and this macro will mash and shift the value appropriately.
87 #define smu_dcc_get_max_ports(dcc_value) \
89 (((dcc_value) & SMU_DEVICE_CONTEXT_CAPACITY_MAX_LP_MASK) \
90 >> SMU_DEVICE_CONTEXT_CAPACITY_MAX_LP_SHIFT) + 1 \
94 * smu_dcc_get_max_task_context() -
96 * This macro returns the maximum number of task contexts supported by the
97 * hardware. The caller passes in the value read from the device context
98 * capacity register and this macro will mash and shift the value appropriately.
100 #define smu_dcc_get_max_task_context(dcc_value) \
102 (((dcc_value) & SMU_DEVICE_CONTEXT_CAPACITY_MAX_TC_MASK) \
103 >> SMU_DEVICE_CONTEXT_CAPACITY_MAX_TC_SHIFT) + 1 \
107 * smu_dcc_get_max_remote_node_context() -
109 * This macro returns the maximum number of remote node contexts supported by
110 * the hardware. The caller passes in the value read from the device context
111 * capacity register and this macro will mash and shift the value appropriately.
113 #define smu_dcc_get_max_remote_node_context(dcc_value) \
115 (((dcc_value) & SMU_DEVICE_CONTEXT_CAPACITY_MAX_RNC_MASK) \
116 >> SMU_DEVICE_CONTEXT_CAPACITY_MAX_RNC_SHIFT) + 1 \
120 static void scic_sds_controller_power_control_timer_handler(
122 #define SCIC_SDS_CONTROLLER_MIN_TIMER_COUNT 3
123 #define SCIC_SDS_CONTROLLER_MAX_TIMER_COUNT 3
128 * The number of milliseconds to wait for a phy to start.
130 #define SCIC_SDS_CONTROLLER_PHY_START_TIMEOUT 100
135 * The number of milliseconds to wait while a given phy is consuming power
136 * before allowing another set of phys to consume power. Ultimately, this will
137 * be specified by OEM parameter.
139 #define SCIC_SDS_CONTROLLER_POWER_CONTROL_INTERVAL 500
142 * COMPLETION_QUEUE_CYCLE_BIT() -
144 * This macro will return the cycle bit of the completion queue entry
146 #define COMPLETION_QUEUE_CYCLE_BIT(x) ((x) & 0x80000000)
149 * NORMALIZE_GET_POINTER() -
151 * This macro will normalize the completion queue get pointer so its value can
152 * be used as an index into an array
154 #define NORMALIZE_GET_POINTER(x) \
155 ((x) & SMU_COMPLETION_QUEUE_GET_POINTER_MASK)
158 * NORMALIZE_PUT_POINTER() -
160 * This macro will normalize the completion queue put pointer so its value can
161 * be used as an array inde
163 #define NORMALIZE_PUT_POINTER(x) \
164 ((x) & SMU_COMPLETION_QUEUE_PUT_POINTER_MASK)
168 * NORMALIZE_GET_POINTER_CYCLE_BIT() -
170 * This macro will normalize the completion queue cycle pointer so it matches
171 * the completion queue cycle bit
173 #define NORMALIZE_GET_POINTER_CYCLE_BIT(x) \
174 ((SMU_CQGR_CYCLE_BIT & (x)) << (31 - SMU_COMPLETION_QUEUE_GET_CYCLE_BIT_SHIFT))
177 * NORMALIZE_EVENT_POINTER() -
179 * This macro will normalize the completion queue event entry so its value can
180 * be used as an index.
182 #define NORMALIZE_EVENT_POINTER(x) \
184 ((x) & SMU_COMPLETION_QUEUE_GET_EVENT_POINTER_MASK) \
185 >> SMU_COMPLETION_QUEUE_GET_EVENT_POINTER_SHIFT \
189 * INCREMENT_COMPLETION_QUEUE_GET() -
191 * This macro will increment the controllers completion queue index value and
192 * possibly toggle the cycle bit if the completion queue index wraps back to 0.
194 #define INCREMENT_COMPLETION_QUEUE_GET(controller, index, cycle) \
195 INCREMENT_QUEUE_GET(\
198 (controller)->completion_queue_entries, \
203 * INCREMENT_EVENT_QUEUE_GET() -
205 * This macro will increment the controllers event queue index value and
206 * possibly toggle the event cycle bit if the event queue index wraps back to 0.
208 #define INCREMENT_EVENT_QUEUE_GET(controller, index, cycle) \
209 INCREMENT_QUEUE_GET(\
212 (controller)->completion_event_entries, \
213 SMU_CQGR_EVENT_CYCLE_BIT \
216 struct sci_base_memory_descriptor_list
*
217 sci_controller_get_memory_descriptor_list_handle(struct scic_sds_controller
*scic
)
219 return &scic
->parent
.mdl
;
222 static void scic_sds_controller_initialize_power_control(struct scic_sds_controller
*scic
)
224 struct isci_host
*ihost
= sci_object_get_association(scic
);
225 scic
->power_control
.timer
= isci_timer_create(ihost
,
227 scic_sds_controller_power_control_timer_handler
);
229 memset(scic
->power_control
.requesters
, 0,
230 sizeof(scic
->power_control
.requesters
));
232 scic
->power_control
.phys_waiting
= 0;
233 scic
->power_control
.phys_granted_power
= 0;
236 #define SCU_REMOTE_NODE_CONTEXT_ALIGNMENT (32)
237 #define SCU_TASK_CONTEXT_ALIGNMENT (256)
238 #define SCU_UNSOLICITED_FRAME_ADDRESS_ALIGNMENT (64)
239 #define SCU_UNSOLICITED_FRAME_BUFFER_ALIGNMENT (1024)
240 #define SCU_UNSOLICITED_FRAME_HEADER_ALIGNMENT (64)
243 * This method builds the memory descriptor table for this controller.
244 * @this_controller: This parameter specifies the controller object for which
245 * to build the memory table.
248 static void scic_sds_controller_build_memory_descriptor_table(
249 struct scic_sds_controller
*this_controller
)
251 sci_base_mde_construct(
252 &this_controller
->memory_descriptors
[SCU_MDE_COMPLETION_QUEUE
],
253 SCU_COMPLETION_RAM_ALIGNMENT
,
254 (sizeof(u32
) * this_controller
->completion_queue_entries
),
255 (SCI_MDE_ATTRIBUTE_CACHEABLE
| SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
)
258 sci_base_mde_construct(
259 &this_controller
->memory_descriptors
[SCU_MDE_REMOTE_NODE_CONTEXT
],
260 SCU_REMOTE_NODE_CONTEXT_ALIGNMENT
,
261 this_controller
->remote_node_entries
* sizeof(union scu_remote_node_context
),
262 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
265 sci_base_mde_construct(
266 &this_controller
->memory_descriptors
[SCU_MDE_TASK_CONTEXT
],
267 SCU_TASK_CONTEXT_ALIGNMENT
,
268 this_controller
->task_context_entries
* sizeof(struct scu_task_context
),
269 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
273 * The UF buffer address table size must be programmed to a power
274 * of 2. Find the first power of 2 that is equal to or greater then
275 * the number of unsolicited frame buffers to be utilized. */
276 scic_sds_unsolicited_frame_control_set_address_table_count(
277 &this_controller
->uf_control
280 sci_base_mde_construct(
281 &this_controller
->memory_descriptors
[SCU_MDE_UF_BUFFER
],
282 SCU_UNSOLICITED_FRAME_BUFFER_ALIGNMENT
,
283 scic_sds_unsolicited_frame_control_get_mde_size(this_controller
->uf_control
),
284 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
289 * This method validates the driver supplied memory descriptor table.
294 static enum sci_status
scic_sds_controller_validate_memory_descriptor_table(
295 struct scic_sds_controller
*this_controller
)
299 mde_list_valid
= sci_base_mde_is_valid(
300 &this_controller
->memory_descriptors
[SCU_MDE_COMPLETION_QUEUE
],
301 SCU_COMPLETION_RAM_ALIGNMENT
,
302 (sizeof(u32
) * this_controller
->completion_queue_entries
),
303 (SCI_MDE_ATTRIBUTE_CACHEABLE
| SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
)
306 if (mde_list_valid
== false)
307 return SCI_FAILURE_UNSUPPORTED_INFORMATION_FIELD
;
309 mde_list_valid
= sci_base_mde_is_valid(
310 &this_controller
->memory_descriptors
[SCU_MDE_REMOTE_NODE_CONTEXT
],
311 SCU_REMOTE_NODE_CONTEXT_ALIGNMENT
,
312 this_controller
->remote_node_entries
* sizeof(union scu_remote_node_context
),
313 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
316 if (mde_list_valid
== false)
317 return SCI_FAILURE_UNSUPPORTED_INFORMATION_FIELD
;
319 mde_list_valid
= sci_base_mde_is_valid(
320 &this_controller
->memory_descriptors
[SCU_MDE_TASK_CONTEXT
],
321 SCU_TASK_CONTEXT_ALIGNMENT
,
322 this_controller
->task_context_entries
* sizeof(struct scu_task_context
),
323 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
326 if (mde_list_valid
== false)
327 return SCI_FAILURE_UNSUPPORTED_INFORMATION_FIELD
;
329 mde_list_valid
= sci_base_mde_is_valid(
330 &this_controller
->memory_descriptors
[SCU_MDE_UF_BUFFER
],
331 SCU_UNSOLICITED_FRAME_BUFFER_ALIGNMENT
,
332 scic_sds_unsolicited_frame_control_get_mde_size(this_controller
->uf_control
),
333 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
336 if (mde_list_valid
== false)
337 return SCI_FAILURE_UNSUPPORTED_INFORMATION_FIELD
;
343 * This method initializes the controller with the physical memory addresses
344 * that are used to communicate with the driver.
348 static void scic_sds_controller_ram_initialization(
349 struct scic_sds_controller
*this_controller
)
351 struct sci_physical_memory_descriptor
*mde
;
354 * The completion queue is actually placed in cacheable memory
355 * Therefore it no longer comes out of memory in the MDL. */
356 mde
= &this_controller
->memory_descriptors
[SCU_MDE_COMPLETION_QUEUE
];
357 this_controller
->completion_queue
= (u32
*)mde
->virtual_address
;
358 SMU_CQBAR_WRITE(this_controller
, mde
->physical_address
);
361 * Program the location of the Remote Node Context table
363 mde
= &this_controller
->memory_descriptors
[SCU_MDE_REMOTE_NODE_CONTEXT
];
364 this_controller
->remote_node_context_table
= (union scu_remote_node_context
*)
365 mde
->virtual_address
;
366 SMU_RNCBAR_WRITE(this_controller
, mde
->physical_address
);
368 /* Program the location of the Task Context table into the SCU. */
369 mde
= &this_controller
->memory_descriptors
[SCU_MDE_TASK_CONTEXT
];
370 this_controller
->task_context_table
= (struct scu_task_context
*)
371 mde
->virtual_address
;
372 SMU_HTTBAR_WRITE(this_controller
, mde
->physical_address
);
374 mde
= &this_controller
->memory_descriptors
[SCU_MDE_UF_BUFFER
];
375 scic_sds_unsolicited_frame_control_construct(
376 &this_controller
->uf_control
, mde
, this_controller
380 * Inform the silicon as to the location of the UF headers and
384 this_controller
->uf_control
.headers
.physical_address
);
387 this_controller
->uf_control
.address_table
.physical_address
);
391 * This method initializes the task context data for the controller.
395 static void scic_sds_controller_assign_task_entries(
396 struct scic_sds_controller
*this_controller
)
401 * Assign all the TCs to function 0
402 * TODO: Do we actually need to read this register to write it back? */
403 task_assignment
= SMU_TCA_READ(this_controller
, 0);
408 | (SMU_TCA_GEN_VAL(STARTING
, 0))
409 | (SMU_TCA_GEN_VAL(ENDING
, this_controller
->task_context_entries
- 1))
410 | (SMU_TCA_GEN_BIT(RANGE_CHECK_ENABLE
))
413 SMU_TCA_WRITE(this_controller
, 0, task_assignment
);
417 * This method initializes the hardware completion queue.
421 static void scic_sds_controller_initialize_completion_queue(
422 struct scic_sds_controller
*this_controller
)
425 u32 completion_queue_control_value
;
426 u32 completion_queue_get_value
;
427 u32 completion_queue_put_value
;
429 this_controller
->completion_queue_get
= 0;
431 completion_queue_control_value
= (
432 SMU_CQC_QUEUE_LIMIT_SET(this_controller
->completion_queue_entries
- 1)
433 | SMU_CQC_EVENT_LIMIT_SET(this_controller
->completion_event_entries
- 1)
436 SMU_CQC_WRITE(this_controller
, completion_queue_control_value
);
438 /* Set the completion queue get pointer and enable the queue */
439 completion_queue_get_value
= (
440 (SMU_CQGR_GEN_VAL(POINTER
, 0))
441 | (SMU_CQGR_GEN_VAL(EVENT_POINTER
, 0))
442 | (SMU_CQGR_GEN_BIT(ENABLE
))
443 | (SMU_CQGR_GEN_BIT(EVENT_ENABLE
))
446 SMU_CQGR_WRITE(this_controller
, completion_queue_get_value
);
448 /* Set the completion queue put pointer */
449 completion_queue_put_value
= (
450 (SMU_CQPR_GEN_VAL(POINTER
, 0))
451 | (SMU_CQPR_GEN_VAL(EVENT_POINTER
, 0))
454 SMU_CQPR_WRITE(this_controller
, completion_queue_put_value
);
456 /* Initialize the cycle bit of the completion queue entries */
457 for (index
= 0; index
< this_controller
->completion_queue_entries
; index
++) {
459 * If get.cycle_bit != completion_queue.cycle_bit
460 * its not a valid completion queue entry
461 * so at system start all entries are invalid */
462 this_controller
->completion_queue
[index
] = 0x80000000;
467 * This method initializes the hardware unsolicited frame queue.
471 static void scic_sds_controller_initialize_unsolicited_frame_queue(
472 struct scic_sds_controller
*this_controller
)
474 u32 frame_queue_control_value
;
475 u32 frame_queue_get_value
;
476 u32 frame_queue_put_value
;
478 /* Write the queue size */
479 frame_queue_control_value
=
480 SCU_UFQC_GEN_VAL(QUEUE_SIZE
, this_controller
->uf_control
.address_table
.count
);
482 SCU_UFQC_WRITE(this_controller
, frame_queue_control_value
);
484 /* Setup the get pointer for the unsolicited frame queue */
485 frame_queue_get_value
= (
486 SCU_UFQGP_GEN_VAL(POINTER
, 0)
487 | SCU_UFQGP_GEN_BIT(ENABLE_BIT
)
490 SCU_UFQGP_WRITE(this_controller
, frame_queue_get_value
);
492 /* Setup the put pointer for the unsolicited frame queue */
493 frame_queue_put_value
= SCU_UFQPP_GEN_VAL(POINTER
, 0);
495 SCU_UFQPP_WRITE(this_controller
, frame_queue_put_value
);
499 * This method enables the hardware port task scheduler.
503 static void scic_sds_controller_enable_port_task_scheduler(
504 struct scic_sds_controller
*this_controller
)
506 u32 port_task_scheduler_value
;
508 port_task_scheduler_value
= SCU_PTSGCR_READ(this_controller
);
510 port_task_scheduler_value
|=
511 (SCU_PTSGCR_GEN_BIT(ETM_ENABLE
) | SCU_PTSGCR_GEN_BIT(PTSG_ENABLE
));
513 SCU_PTSGCR_WRITE(this_controller
, port_task_scheduler_value
);
519 * This macro is used to delay between writes to the AFE registers during AFE
522 #define AFE_REGISTER_WRITE_DELAY 10
524 /* Initialize the AFE for this phy index. We need to read the AFE setup from
525 * the OEM parameters none
527 static void scic_sds_controller_afe_initialization(struct scic_sds_controller
*scic
)
529 const struct scic_sds_oem_params
*oem
= &scic
->oem_parameters
.sds1
;
533 /* Clear DFX Status registers */
534 scu_afe_register_write(scic
, afe_dfx_master_control0
, 0x0081000f);
535 udelay(AFE_REGISTER_WRITE_DELAY
);
537 /* Configure bias currents to normal */
539 scu_afe_register_write(scic
, afe_bias_control
, 0x00005500);
541 scu_afe_register_write(scic
, afe_bias_control
, 0x00005A00);
543 udelay(AFE_REGISTER_WRITE_DELAY
);
547 scu_afe_register_write(scic
, afe_pll_control0
, 0x80040A08);
549 scu_afe_register_write(scic
, afe_pll_control0
, 0x80040908);
551 udelay(AFE_REGISTER_WRITE_DELAY
);
553 /* Wait for the PLL to lock */
555 afe_status
= scu_afe_register_read(
556 scic
, afe_common_block_status
);
557 udelay(AFE_REGISTER_WRITE_DELAY
);
558 } while ((afe_status
& 0x00001000) == 0);
561 /* Shorten SAS SNW lock time (RxLock timer value from 76 us to 50 us) */
562 scu_afe_register_write(scic
, afe_pmsn_master_control0
, 0x7bcc96ad);
563 udelay(AFE_REGISTER_WRITE_DELAY
);
566 for (phy_id
= 0; phy_id
< SCI_MAX_PHYS
; phy_id
++) {
567 const struct sci_phy_oem_params
*oem_phy
= &oem
->phys
[phy_id
];
570 /* Configure transmitter SSC parameters */
571 scu_afe_txreg_write(scic
, phy_id
, afe_tx_ssc_control
, 0x00030000);
572 udelay(AFE_REGISTER_WRITE_DELAY
);
575 * All defaults, except the Receive Word Alignament/Comma Detect
576 * Enable....(0xe800) */
577 scu_afe_txreg_write(scic
, phy_id
, afe_xcvr_control0
, 0x00004512);
578 udelay(AFE_REGISTER_WRITE_DELAY
);
580 scu_afe_txreg_write(scic
, phy_id
, afe_xcvr_control1
, 0x0050100F);
581 udelay(AFE_REGISTER_WRITE_DELAY
);
585 * Power up TX and RX out from power down (PWRDNTX and PWRDNRX)
586 * & increase TX int & ext bias 20%....(0xe85c) */
588 scu_afe_txreg_write(scic
, phy_id
, afe_channel_control
, 0x000003D4);
590 scu_afe_txreg_write(scic
, phy_id
, afe_channel_control
, 0x000003F0);
592 /* Power down TX and RX (PWRDNTX and PWRDNRX) */
593 scu_afe_txreg_write(scic
, phy_id
, afe_channel_control
, 0x000003d7);
594 udelay(AFE_REGISTER_WRITE_DELAY
);
597 * Power up TX and RX out from power down (PWRDNTX and PWRDNRX)
598 * & increase TX int & ext bias 20%....(0xe85c) */
599 scu_afe_txreg_write(scic
, phy_id
, afe_channel_control
, 0x000003d4);
601 udelay(AFE_REGISTER_WRITE_DELAY
);
603 if (is_a0() || is_a2()) {
604 /* Enable TX equalization (0xe824) */
605 scu_afe_txreg_write(scic
, phy_id
, afe_tx_control
, 0x00040000);
606 udelay(AFE_REGISTER_WRITE_DELAY
);
610 * RDPI=0x0(RX Power On), RXOOBDETPDNC=0x0, TPD=0x0(TX Power On),
611 * RDD=0x0(RX Detect Enabled) ....(0xe800) */
612 scu_afe_txreg_write(scic
, phy_id
, afe_xcvr_control0
, 0x00004100);
613 udelay(AFE_REGISTER_WRITE_DELAY
);
615 /* Leave DFE/FFE on */
617 scu_afe_txreg_write(scic
, phy_id
, afe_rx_ssc_control0
, 0x3F09983F);
619 scu_afe_txreg_write(scic
, phy_id
, afe_rx_ssc_control0
, 0x3F11103F);
621 scu_afe_txreg_write(scic
, phy_id
, afe_rx_ssc_control0
, 0x3F11103F);
622 udelay(AFE_REGISTER_WRITE_DELAY
);
623 /* Enable TX equalization (0xe824) */
624 scu_afe_txreg_write(scic
, phy_id
, afe_tx_control
, 0x00040000);
626 udelay(AFE_REGISTER_WRITE_DELAY
);
628 scu_afe_txreg_write(scic
, phy_id
, afe_tx_amp_control0
, oem_phy
->afe_tx_amp_control0
);
629 udelay(AFE_REGISTER_WRITE_DELAY
);
631 scu_afe_txreg_write(scic
, phy_id
, afe_tx_amp_control0
, oem_phy
->afe_tx_amp_control1
);
632 udelay(AFE_REGISTER_WRITE_DELAY
);
634 scu_afe_txreg_write(scic
, phy_id
, afe_tx_amp_control0
, oem_phy
->afe_tx_amp_control2
);
635 udelay(AFE_REGISTER_WRITE_DELAY
);
637 scu_afe_txreg_write(scic
, phy_id
, afe_tx_amp_control0
, oem_phy
->afe_tx_amp_control3
);
638 udelay(AFE_REGISTER_WRITE_DELAY
);
641 /* Transfer control to the PEs */
642 scu_afe_register_write(scic
, afe_dfx_master_control0
, 0x00010f00);
643 udelay(AFE_REGISTER_WRITE_DELAY
);
647 * ****************************************************************************-
648 * * SCIC SDS Controller Internal Start/Stop Routines
649 * ****************************************************************************- */
653 * This method will attempt to transition into the ready state for the
654 * controller and indicate that the controller start operation has completed
655 * if all criteria are met.
656 * @this_controller: This parameter indicates the controller object for which
657 * to transition to ready.
658 * @status: This parameter indicates the status value to be pass into the call
659 * to scic_cb_controller_start_complete().
663 static void scic_sds_controller_transition_to_ready(
664 struct scic_sds_controller
*scic
,
665 enum sci_status status
)
667 struct isci_host
*ihost
= sci_object_get_association(scic
);
669 if (scic
->parent
.state_machine
.current_state_id
==
670 SCI_BASE_CONTROLLER_STATE_STARTING
) {
672 * We move into the ready state, because some of the phys/ports
673 * may be up and operational.
675 sci_base_state_machine_change_state(&scic
->parent
.state_machine
,
676 SCI_BASE_CONTROLLER_STATE_READY
);
678 isci_host_start_complete(ihost
, status
);
682 static void scic_sds_controller_timeout_handler(void *_scic
)
684 struct scic_sds_controller
*scic
= _scic
;
685 struct isci_host
*ihost
= sci_object_get_association(scic
);
686 struct sci_base_state_machine
*sm
= &scic
->parent
.state_machine
;
688 if (sm
->current_state_id
== SCI_BASE_CONTROLLER_STATE_STARTING
)
689 scic_sds_controller_transition_to_ready(scic
, SCI_FAILURE_TIMEOUT
);
690 else if (sm
->current_state_id
== SCI_BASE_CONTROLLER_STATE_STOPPING
) {
691 sci_base_state_machine_change_state(sm
, SCI_BASE_CONTROLLER_STATE_FAILED
);
692 isci_host_stop_complete(ihost
, SCI_FAILURE_TIMEOUT
);
693 } else /* / @todo Now what do we want to do in this case? */
694 dev_err(scic_to_dev(scic
),
695 "%s: Controller timer fired when controller was not "
696 "in a state being timed.\n",
700 static enum sci_status
scic_sds_controller_stop_ports(struct scic_sds_controller
*scic
)
703 enum sci_status port_status
;
704 enum sci_status status
= SCI_SUCCESS
;
706 for (index
= 0; index
< scic
->logical_port_entries
; index
++) {
707 struct scic_sds_port
*sci_port
= &scic
->port_table
[index
];
708 SCI_BASE_PORT_HANDLER_T stop
;
710 stop
= sci_port
->state_handlers
->parent
.stop_handler
;
711 port_status
= stop(&sci_port
->parent
);
713 if ((port_status
!= SCI_SUCCESS
) &&
714 (port_status
!= SCI_FAILURE_INVALID_STATE
)) {
715 status
= SCI_FAILURE
;
717 dev_warn(scic_to_dev(scic
),
718 "%s: Controller stop operation failed to "
719 "stop port %d because of status %d.\n",
721 sci_port
->logical_port_index
,
729 static inline void scic_sds_controller_phy_timer_start(
730 struct scic_sds_controller
*scic
)
732 isci_timer_start(scic
->phy_startup_timer
,
733 SCIC_SDS_CONTROLLER_PHY_START_TIMEOUT
);
735 scic
->phy_startup_timer_pending
= true;
738 static void scic_sds_controller_phy_timer_stop(struct scic_sds_controller
*scic
)
740 isci_timer_stop(scic
->phy_startup_timer
);
742 scic
->phy_startup_timer_pending
= false;
746 * scic_sds_controller_start_next_phy - start phy
749 * If all the phys have been started, then attempt to transition the
750 * controller to the READY state and inform the user
751 * (scic_cb_controller_start_complete()).
753 static enum sci_status
scic_sds_controller_start_next_phy(struct scic_sds_controller
*scic
)
755 struct scic_sds_oem_params
*oem
= &scic
->oem_parameters
.sds1
;
756 struct scic_sds_phy
*sci_phy
;
757 enum sci_status status
;
759 status
= SCI_SUCCESS
;
761 if (scic
->phy_startup_timer_pending
)
764 if (scic
->next_phy_to_start
>= SCI_MAX_PHYS
) {
765 bool is_controller_start_complete
= true;
769 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
770 sci_phy
= &scic
->phy_table
[index
];
771 state
= sci_phy
->parent
.state_machine
.current_state_id
;
773 if (!scic_sds_phy_get_port(sci_phy
))
776 /* The controller start operation is complete iff:
777 * - all links have been given an opportunity to start
778 * - have no indication of a connected device
779 * - have an indication of a connected device and it has
780 * finished the link training process.
782 if ((sci_phy
->is_in_link_training
== false &&
783 state
== SCI_BASE_PHY_STATE_INITIAL
) ||
784 (sci_phy
->is_in_link_training
== false &&
785 state
== SCI_BASE_PHY_STATE_STOPPED
) ||
786 (sci_phy
->is_in_link_training
== true &&
787 state
== SCI_BASE_PHY_STATE_STARTING
)) {
788 is_controller_start_complete
= false;
794 * The controller has successfully finished the start process.
795 * Inform the SCI Core user and transition to the READY state. */
796 if (is_controller_start_complete
== true) {
797 scic_sds_controller_transition_to_ready(scic
, SCI_SUCCESS
);
798 scic_sds_controller_phy_timer_stop(scic
);
801 sci_phy
= &scic
->phy_table
[scic
->next_phy_to_start
];
803 if (oem
->controller
.mode_type
== SCIC_PORT_MANUAL_CONFIGURATION_MODE
) {
804 if (scic_sds_phy_get_port(sci_phy
) == NULL
) {
805 scic
->next_phy_to_start
++;
807 /* Caution recursion ahead be forwarned
809 * The PHY was never added to a PORT in MPC mode
810 * so start the next phy in sequence This phy
811 * will never go link up and will not draw power
812 * the OEM parameters either configured the phy
813 * incorrectly for the PORT or it was never
816 return scic_sds_controller_start_next_phy(scic
);
820 status
= scic_sds_phy_start(sci_phy
);
822 if (status
== SCI_SUCCESS
) {
823 scic_sds_controller_phy_timer_start(scic
);
825 dev_warn(scic_to_dev(scic
),
826 "%s: Controller stop operation failed "
827 "to stop phy %d because of status "
830 scic
->phy_table
[scic
->next_phy_to_start
].phy_index
,
834 scic
->next_phy_to_start
++;
840 static void scic_sds_controller_phy_startup_timeout_handler(void *_scic
)
842 struct scic_sds_controller
*scic
= _scic
;
843 enum sci_status status
;
845 scic
->phy_startup_timer_pending
= false;
846 status
= SCI_FAILURE
;
847 while (status
!= SCI_SUCCESS
)
848 status
= scic_sds_controller_start_next_phy(scic
);
851 static enum sci_status
scic_sds_controller_initialize_phy_startup(struct scic_sds_controller
*scic
)
853 struct isci_host
*ihost
= sci_object_get_association(scic
);
855 scic
->phy_startup_timer
= isci_timer_create(ihost
,
857 scic_sds_controller_phy_startup_timeout_handler
);
859 if (scic
->phy_startup_timer
== NULL
)
860 return SCI_FAILURE_INSUFFICIENT_RESOURCES
;
862 scic
->next_phy_to_start
= 0;
863 scic
->phy_startup_timer_pending
= false;
869 static enum sci_status
scic_sds_controller_stop_phys(struct scic_sds_controller
*scic
)
872 enum sci_status status
;
873 enum sci_status phy_status
;
875 status
= SCI_SUCCESS
;
877 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
878 phy_status
= scic_sds_phy_stop(&scic
->phy_table
[index
]);
881 (phy_status
!= SCI_SUCCESS
)
882 && (phy_status
!= SCI_FAILURE_INVALID_STATE
)
884 status
= SCI_FAILURE
;
886 dev_warn(scic_to_dev(scic
),
887 "%s: Controller stop operation failed to stop "
888 "phy %d because of status %d.\n",
890 scic
->phy_table
[index
].phy_index
, phy_status
);
897 static enum sci_status
scic_sds_controller_stop_devices(struct scic_sds_controller
*scic
)
900 enum sci_status status
;
901 enum sci_status device_status
;
903 status
= SCI_SUCCESS
;
905 for (index
= 0; index
< scic
->remote_node_entries
; index
++) {
906 if (scic
->device_table
[index
] != NULL
) {
907 /* / @todo What timeout value do we want to provide to this request? */
908 device_status
= scic_remote_device_stop(scic
->device_table
[index
], 0);
910 if ((device_status
!= SCI_SUCCESS
) &&
911 (device_status
!= SCI_FAILURE_INVALID_STATE
)) {
912 dev_warn(scic_to_dev(scic
),
913 "%s: Controller stop operation failed "
914 "to stop device 0x%p because of "
917 scic
->device_table
[index
], device_status
);
925 static void scic_sds_controller_power_control_timer_start(struct scic_sds_controller
*scic
)
927 isci_timer_start(scic
->power_control
.timer
,
928 SCIC_SDS_CONTROLLER_POWER_CONTROL_INTERVAL
);
930 scic
->power_control
.timer_started
= true;
933 static void scic_sds_controller_power_control_timer_stop(struct scic_sds_controller
*scic
)
935 if (scic
->power_control
.timer_started
) {
936 isci_timer_stop(scic
->power_control
.timer
);
937 scic
->power_control
.timer_started
= false;
941 static void scic_sds_controller_power_control_timer_restart(struct scic_sds_controller
*scic
)
943 scic_sds_controller_power_control_timer_stop(scic
);
944 scic_sds_controller_power_control_timer_start(scic
);
947 static void scic_sds_controller_power_control_timer_handler(
950 struct scic_sds_controller
*this_controller
;
952 this_controller
= (struct scic_sds_controller
*)controller
;
954 this_controller
->power_control
.phys_granted_power
= 0;
956 if (this_controller
->power_control
.phys_waiting
== 0) {
957 this_controller
->power_control
.timer_started
= false;
959 struct scic_sds_phy
*the_phy
= NULL
;
964 && (this_controller
->power_control
.phys_waiting
!= 0);
966 if (this_controller
->power_control
.requesters
[i
] != NULL
) {
967 if (this_controller
->power_control
.phys_granted_power
<
968 this_controller
->oem_parameters
.sds1
.controller
.max_concurrent_dev_spin_up
) {
969 the_phy
= this_controller
->power_control
.requesters
[i
];
970 this_controller
->power_control
.requesters
[i
] = NULL
;
971 this_controller
->power_control
.phys_waiting
--;
972 this_controller
->power_control
.phys_granted_power
++;
973 scic_sds_phy_consume_power_handler(the_phy
);
981 * It doesn't matter if the power list is empty, we need to start the
982 * timer in case another phy becomes ready.
984 scic_sds_controller_power_control_timer_start(this_controller
);
989 * This method inserts the phy in the stagger spinup control queue.
994 void scic_sds_controller_power_control_queue_insert(
995 struct scic_sds_controller
*this_controller
,
996 struct scic_sds_phy
*the_phy
)
998 BUG_ON(the_phy
== NULL
);
1000 if (this_controller
->power_control
.phys_granted_power
<
1001 this_controller
->oem_parameters
.sds1
.controller
.max_concurrent_dev_spin_up
) {
1002 this_controller
->power_control
.phys_granted_power
++;
1003 scic_sds_phy_consume_power_handler(the_phy
);
1006 * stop and start the power_control timer. When the timer fires, the
1007 * no_of_phys_granted_power will be set to 0
1009 scic_sds_controller_power_control_timer_restart(this_controller
);
1011 /* Add the phy in the waiting list */
1012 this_controller
->power_control
.requesters
[the_phy
->phy_index
] = the_phy
;
1013 this_controller
->power_control
.phys_waiting
++;
1018 * This method removes the phy from the stagger spinup control queue.
1023 void scic_sds_controller_power_control_queue_remove(
1024 struct scic_sds_controller
*this_controller
,
1025 struct scic_sds_phy
*the_phy
)
1027 BUG_ON(the_phy
== NULL
);
1029 if (this_controller
->power_control
.requesters
[the_phy
->phy_index
] != NULL
) {
1030 this_controller
->power_control
.phys_waiting
--;
1033 this_controller
->power_control
.requesters
[the_phy
->phy_index
] = NULL
;
1037 * ****************************************************************************-
1038 * * SCIC SDS Controller Completion Routines
1039 * ****************************************************************************- */
1042 * This method returns a true value if the completion queue has entries that
1046 * bool true if the completion queue has entries to process false if the
1047 * completion queue has no entries to process
1049 static bool scic_sds_controller_completion_queue_has_entries(
1050 struct scic_sds_controller
*this_controller
)
1052 u32 get_value
= this_controller
->completion_queue_get
;
1053 u32 get_index
= get_value
& SMU_COMPLETION_QUEUE_GET_POINTER_MASK
;
1056 NORMALIZE_GET_POINTER_CYCLE_BIT(get_value
)
1057 == COMPLETION_QUEUE_CYCLE_BIT(this_controller
->completion_queue
[get_index
])
1066 * This method processes a task completion notification. This is called from
1067 * within the controller completion handler.
1069 * @completion_entry:
1072 static void scic_sds_controller_task_completion(
1073 struct scic_sds_controller
*this_controller
,
1074 u32 completion_entry
)
1077 struct scic_sds_request
*io_request
;
1079 index
= SCU_GET_COMPLETION_INDEX(completion_entry
);
1080 io_request
= this_controller
->io_request_table
[index
];
1082 /* Make sure that we really want to process this IO request */
1084 (io_request
!= NULL
)
1085 && (io_request
->io_tag
!= SCI_CONTROLLER_INVALID_IO_TAG
)
1087 scic_sds_io_tag_get_sequence(io_request
->io_tag
)
1088 == this_controller
->io_request_sequence
[index
]
1091 /* Yep this is a valid io request pass it along to the io request handler */
1092 scic_sds_io_request_tc_completion(io_request
, completion_entry
);
1097 * This method processes an SDMA completion event. This is called from within
1098 * the controller completion handler.
1100 * @completion_entry:
1103 static void scic_sds_controller_sdma_completion(
1104 struct scic_sds_controller
*this_controller
,
1105 u32 completion_entry
)
1108 struct scic_sds_request
*io_request
;
1109 struct scic_sds_remote_device
*device
;
1111 index
= SCU_GET_COMPLETION_INDEX(completion_entry
);
1113 switch (scu_get_command_request_type(completion_entry
)) {
1114 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
:
1115 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_DUMP_TC
:
1116 io_request
= this_controller
->io_request_table
[index
];
1117 dev_warn(scic_to_dev(this_controller
),
1118 "%s: SCIC SDS Completion type SDMA %x for io request "
1123 /* @todo For a post TC operation we need to fail the IO
1128 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_DUMP_RNC
:
1129 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_OTHER_RNC
:
1130 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_RNC
:
1131 device
= this_controller
->device_table
[index
];
1132 dev_warn(scic_to_dev(this_controller
),
1133 "%s: SCIC SDS Completion type SDMA %x for remote "
1138 /* @todo For a port RNC operation we need to fail the
1144 dev_warn(scic_to_dev(this_controller
),
1145 "%s: SCIC SDS Completion unknown SDMA completion "
1157 * @completion_entry:
1159 * This method processes an unsolicited frame message. This is called from
1160 * within the controller completion handler. none
1162 static void scic_sds_controller_unsolicited_frame(
1163 struct scic_sds_controller
*this_controller
,
1164 u32 completion_entry
)
1169 struct scu_unsolicited_frame_header
*frame_header
;
1170 struct scic_sds_phy
*phy
;
1171 struct scic_sds_remote_device
*device
;
1173 enum sci_status result
= SCI_FAILURE
;
1175 frame_index
= SCU_GET_FRAME_INDEX(completion_entry
);
1178 = this_controller
->uf_control
.buffers
.array
[frame_index
].header
;
1179 this_controller
->uf_control
.buffers
.array
[frame_index
].state
1180 = UNSOLICITED_FRAME_IN_USE
;
1182 if (SCU_GET_FRAME_ERROR(completion_entry
)) {
1184 * / @todo If the IAF frame or SIGNATURE FIS frame has an error will
1185 * / this cause a problem? We expect the phy initialization will
1186 * / fail if there is an error in the frame. */
1187 scic_sds_controller_release_frame(this_controller
, frame_index
);
1191 if (frame_header
->is_address_frame
) {
1192 index
= SCU_GET_PROTOCOL_ENGINE_INDEX(completion_entry
);
1193 phy
= &this_controller
->phy_table
[index
];
1195 result
= scic_sds_phy_frame_handler(phy
, frame_index
);
1199 index
= SCU_GET_COMPLETION_INDEX(completion_entry
);
1201 if (index
== SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
) {
1203 * This is a signature fis or a frame from a direct attached SATA
1204 * device that has not yet been created. In either case forwared
1205 * the frame to the PE and let it take care of the frame data. */
1206 index
= SCU_GET_PROTOCOL_ENGINE_INDEX(completion_entry
);
1207 phy
= &this_controller
->phy_table
[index
];
1208 result
= scic_sds_phy_frame_handler(phy
, frame_index
);
1210 if (index
< this_controller
->remote_node_entries
)
1211 device
= this_controller
->device_table
[index
];
1216 result
= scic_sds_remote_device_frame_handler(device
, frame_index
);
1218 scic_sds_controller_release_frame(this_controller
, frame_index
);
1222 if (result
!= SCI_SUCCESS
) {
1224 * / @todo Is there any reason to report some additional error message
1225 * / when we get this failure notifiction? */
1230 * This method processes an event completion entry. This is called from within
1231 * the controller completion handler.
1233 * @completion_entry:
1236 static void scic_sds_controller_event_completion(
1237 struct scic_sds_controller
*this_controller
,
1238 u32 completion_entry
)
1241 struct scic_sds_request
*io_request
;
1242 struct scic_sds_remote_device
*device
;
1243 struct scic_sds_phy
*phy
;
1245 index
= SCU_GET_COMPLETION_INDEX(completion_entry
);
1247 switch (scu_get_event_type(completion_entry
)) {
1248 case SCU_EVENT_TYPE_SMU_COMMAND_ERROR
:
1249 /* / @todo The driver did something wrong and we need to fix the condtion. */
1250 dev_err(scic_to_dev(this_controller
),
1251 "%s: SCIC Controller 0x%p received SMU command error "
1258 case SCU_EVENT_TYPE_SMU_PCQ_ERROR
:
1259 case SCU_EVENT_TYPE_SMU_ERROR
:
1260 case SCU_EVENT_TYPE_FATAL_MEMORY_ERROR
:
1262 * / @todo This is a hardware failure and its likely that we want to
1263 * / reset the controller. */
1264 dev_err(scic_to_dev(this_controller
),
1265 "%s: SCIC Controller 0x%p received fatal controller "
1272 case SCU_EVENT_TYPE_TRANSPORT_ERROR
:
1273 io_request
= this_controller
->io_request_table
[index
];
1274 scic_sds_io_request_event_handler(io_request
, completion_entry
);
1277 case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT
:
1278 switch (scu_get_event_specifier(completion_entry
)) {
1279 case SCU_EVENT_SPECIFIC_SMP_RESPONSE_NO_PE
:
1280 case SCU_EVENT_SPECIFIC_TASK_TIMEOUT
:
1281 io_request
= this_controller
->io_request_table
[index
];
1282 if (io_request
!= NULL
)
1283 scic_sds_io_request_event_handler(io_request
, completion_entry
);
1285 dev_warn(scic_to_dev(this_controller
),
1286 "%s: SCIC Controller 0x%p received "
1287 "event 0x%x for io request object "
1288 "that doesnt exist.\n",
1295 case SCU_EVENT_SPECIFIC_IT_NEXUS_TIMEOUT
:
1296 device
= this_controller
->device_table
[index
];
1298 scic_sds_remote_device_event_handler(device
, completion_entry
);
1300 dev_warn(scic_to_dev(this_controller
),
1301 "%s: SCIC Controller 0x%p received "
1302 "event 0x%x for remote device object "
1303 "that doesnt exist.\n",
1312 case SCU_EVENT_TYPE_BROADCAST_CHANGE
:
1314 * direct the broadcast change event to the phy first and then let
1315 * the phy redirect the broadcast change to the port object */
1316 case SCU_EVENT_TYPE_ERR_CNT_EVENT
:
1318 * direct error counter event to the phy object since that is where
1319 * we get the event notification. This is a type 4 event. */
1320 case SCU_EVENT_TYPE_OSSP_EVENT
:
1321 index
= SCU_GET_PROTOCOL_ENGINE_INDEX(completion_entry
);
1322 phy
= &this_controller
->phy_table
[index
];
1323 scic_sds_phy_event_handler(phy
, completion_entry
);
1326 case SCU_EVENT_TYPE_RNC_SUSPEND_TX
:
1327 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX
:
1328 case SCU_EVENT_TYPE_RNC_OPS_MISC
:
1329 if (index
< this_controller
->remote_node_entries
) {
1330 device
= this_controller
->device_table
[index
];
1333 scic_sds_remote_device_event_handler(device
, completion_entry
);
1335 dev_err(scic_to_dev(this_controller
),
1336 "%s: SCIC Controller 0x%p received event 0x%x "
1337 "for remote device object 0x%0x that doesnt "
1347 dev_warn(scic_to_dev(this_controller
),
1348 "%s: SCIC Controller received unknown event code %x\n",
1356 * This method is a private routine for processing the completion queue entries.
1360 static void scic_sds_controller_process_completions(
1361 struct scic_sds_controller
*this_controller
)
1363 u32 completion_count
= 0;
1364 u32 completion_entry
;
1370 dev_dbg(scic_to_dev(this_controller
),
1371 "%s: completion queue begining get:0x%08x\n",
1373 this_controller
->completion_queue_get
);
1375 /* Get the component parts of the completion queue */
1376 get_index
= NORMALIZE_GET_POINTER(this_controller
->completion_queue_get
);
1377 get_cycle
= SMU_CQGR_CYCLE_BIT
& this_controller
->completion_queue_get
;
1379 event_index
= NORMALIZE_EVENT_POINTER(this_controller
->completion_queue_get
);
1380 event_cycle
= SMU_CQGR_EVENT_CYCLE_BIT
& this_controller
->completion_queue_get
;
1383 NORMALIZE_GET_POINTER_CYCLE_BIT(get_cycle
)
1384 == COMPLETION_QUEUE_CYCLE_BIT(this_controller
->completion_queue
[get_index
])
1388 completion_entry
= this_controller
->completion_queue
[get_index
];
1389 INCREMENT_COMPLETION_QUEUE_GET(this_controller
, get_index
, get_cycle
);
1391 dev_dbg(scic_to_dev(this_controller
),
1392 "%s: completion queue entry:0x%08x\n",
1396 switch (SCU_GET_COMPLETION_TYPE(completion_entry
)) {
1397 case SCU_COMPLETION_TYPE_TASK
:
1398 scic_sds_controller_task_completion(this_controller
, completion_entry
);
1401 case SCU_COMPLETION_TYPE_SDMA
:
1402 scic_sds_controller_sdma_completion(this_controller
, completion_entry
);
1405 case SCU_COMPLETION_TYPE_UFI
:
1406 scic_sds_controller_unsolicited_frame(this_controller
, completion_entry
);
1409 case SCU_COMPLETION_TYPE_EVENT
:
1410 INCREMENT_EVENT_QUEUE_GET(this_controller
, event_index
, event_cycle
);
1411 scic_sds_controller_event_completion(this_controller
, completion_entry
);
1414 case SCU_COMPLETION_TYPE_NOTIFY
:
1416 * Presently we do the same thing with a notify event that we do with the
1417 * other event codes. */
1418 INCREMENT_EVENT_QUEUE_GET(this_controller
, event_index
, event_cycle
);
1419 scic_sds_controller_event_completion(this_controller
, completion_entry
);
1423 dev_warn(scic_to_dev(this_controller
),
1424 "%s: SCIC Controller received unknown "
1425 "completion type %x\n",
1432 /* Update the get register if we completed one or more entries */
1433 if (completion_count
> 0) {
1434 this_controller
->completion_queue_get
=
1435 SMU_CQGR_GEN_BIT(ENABLE
)
1436 | SMU_CQGR_GEN_BIT(EVENT_ENABLE
)
1437 | event_cycle
| SMU_CQGR_GEN_VAL(EVENT_POINTER
, event_index
)
1438 | get_cycle
| SMU_CQGR_GEN_VAL(POINTER
, get_index
);
1440 SMU_CQGR_WRITE(this_controller
,
1441 this_controller
->completion_queue_get
);
1444 dev_dbg(scic_to_dev(this_controller
),
1445 "%s: completion queue ending get:0x%08x\n",
1447 this_controller
->completion_queue_get
);
1451 bool scic_sds_controller_isr(struct scic_sds_controller
*scic
)
1453 if (scic_sds_controller_completion_queue_has_entries(scic
)) {
1457 * we have a spurious interrupt it could be that we have already
1458 * emptied the completion queue from a previous interrupt */
1459 SMU_ISR_WRITE(scic
, SMU_ISR_COMPLETION
);
1462 * There is a race in the hardware that could cause us not to be notified
1463 * of an interrupt completion if we do not take this step. We will mask
1464 * then unmask the interrupts so if there is another interrupt pending
1465 * the clearing of the interrupt source we get the next interrupt message. */
1466 SMU_IMR_WRITE(scic
, 0xFF000000);
1467 SMU_IMR_WRITE(scic
, 0x00000000);
1473 void scic_sds_controller_completion_handler(struct scic_sds_controller
*scic
)
1475 /* Empty out the completion queue */
1476 if (scic_sds_controller_completion_queue_has_entries(scic
))
1477 scic_sds_controller_process_completions(scic
);
1479 /* Clear the interrupt and enable all interrupts again */
1480 SMU_ISR_WRITE(scic
, SMU_ISR_COMPLETION
);
1481 /* Could we write the value of SMU_ISR_COMPLETION? */
1482 SMU_IMR_WRITE(scic
, 0xFF000000);
1483 SMU_IMR_WRITE(scic
, 0x00000000);
1486 bool scic_sds_controller_error_isr(struct scic_sds_controller
*scic
)
1488 u32 interrupt_status
;
1490 interrupt_status
= SMU_ISR_READ(scic
);
1492 interrupt_status
&= (SMU_ISR_QUEUE_ERROR
| SMU_ISR_QUEUE_SUSPEND
);
1494 if (interrupt_status
!= 0) {
1496 * There is an error interrupt pending so let it through and handle
1497 * in the callback */
1502 * There is a race in the hardware that could cause us not to be notified
1503 * of an interrupt completion if we do not take this step. We will mask
1504 * then unmask the error interrupts so if there was another interrupt
1505 * pending we will be notified.
1506 * Could we write the value of (SMU_ISR_QUEUE_ERROR | SMU_ISR_QUEUE_SUSPEND)? */
1507 SMU_IMR_WRITE(scic
, 0x000000FF);
1508 SMU_IMR_WRITE(scic
, 0x00000000);
1513 void scic_sds_controller_error_handler(struct scic_sds_controller
*scic
)
1515 u32 interrupt_status
;
1517 interrupt_status
= SMU_ISR_READ(scic
);
1519 if ((interrupt_status
& SMU_ISR_QUEUE_SUSPEND
) &&
1520 scic_sds_controller_completion_queue_has_entries(scic
)) {
1522 scic_sds_controller_process_completions(scic
);
1523 SMU_ISR_WRITE(scic
, SMU_ISR_QUEUE_SUSPEND
);
1526 dev_err(scic_to_dev(scic
), "%s: status: %#x\n", __func__
,
1529 sci_base_state_machine_change_state(&scic
->parent
.state_machine
,
1530 SCI_BASE_CONTROLLER_STATE_FAILED
);
1535 /* If we dont process any completions I am not sure that we want to do this.
1536 * We are in the middle of a hardware fault and should probably be reset.
1538 SMU_IMR_WRITE(scic
, 0x00000000);
1544 void scic_sds_controller_link_up(
1545 struct scic_sds_controller
*scic
,
1546 struct scic_sds_port
*sci_port
,
1547 struct scic_sds_phy
*sci_phy
)
1549 scic_sds_controller_phy_handler_t link_up
;
1552 state
= scic
->parent
.state_machine
.current_state_id
;
1553 link_up
= scic_sds_controller_state_handler_table
[state
].link_up
;
1556 link_up(scic
, sci_port
, sci_phy
);
1558 dev_dbg(scic_to_dev(scic
),
1559 "%s: SCIC Controller linkup event from phy %d in "
1560 "unexpected state %d\n", __func__
, sci_phy
->phy_index
,
1565 void scic_sds_controller_link_down(
1566 struct scic_sds_controller
*scic
,
1567 struct scic_sds_port
*sci_port
,
1568 struct scic_sds_phy
*sci_phy
)
1571 scic_sds_controller_phy_handler_t link_down
;
1573 state
= scic
->parent
.state_machine
.current_state_id
;
1574 link_down
= scic_sds_controller_state_handler_table
[state
].link_down
;
1577 link_down(scic
, sci_port
, sci_phy
);
1579 dev_dbg(scic_to_dev(scic
),
1580 "%s: SCIC Controller linkdown event from phy %d in "
1581 "unexpected state %d\n",
1583 sci_phy
->phy_index
, state
);
1587 * This method is called by the remote device to inform the controller
1588 * that this remote device has started.
1592 void scic_sds_controller_remote_device_started(struct scic_sds_controller
*scic
,
1593 struct scic_sds_remote_device
*sci_dev
)
1596 scic_sds_controller_device_handler_t started
;
1598 state
= scic
->parent
.state_machine
.current_state_id
;
1599 started
= scic_sds_controller_state_handler_table
[state
].remote_device_started_handler
;
1602 started(scic
, sci_dev
);
1604 dev_dbg(scic_to_dev(scic
),
1605 "%s: SCIC Controller 0x%p remote device started event "
1606 "from device 0x%p in unexpected state %d\n",
1607 __func__
, scic
, sci_dev
, state
);
1612 * This is a helper method to determine if any remote devices on this
1613 * controller are still in the stopping state.
1616 static bool scic_sds_controller_has_remote_devices_stopping(
1617 struct scic_sds_controller
*this_controller
)
1621 for (index
= 0; index
< this_controller
->remote_node_entries
; index
++) {
1622 if ((this_controller
->device_table
[index
] != NULL
) &&
1623 (this_controller
->device_table
[index
]->parent
.state_machine
.current_state_id
1624 == SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
))
1632 * This method is called by the remote device to inform the controller
1633 * object that the remote device has stopped.
1637 void scic_sds_controller_remote_device_stopped(struct scic_sds_controller
*scic
,
1638 struct scic_sds_remote_device
*sci_dev
)
1642 scic_sds_controller_device_handler_t stopped
;
1644 state
= scic
->parent
.state_machine
.current_state_id
;
1645 stopped
= scic_sds_controller_state_handler_table
[state
].remote_device_stopped_handler
;
1648 stopped(scic
, sci_dev
);
1650 dev_dbg(scic_to_dev(scic
),
1651 "%s: SCIC Controller 0x%p remote device stopped event "
1652 "from device 0x%p in unexpected state %d\n",
1653 __func__
, scic
, sci_dev
, state
);
1660 * This method will write to the SCU PCP register the request value. The method
1661 * is used to suspend/resume ports, devices, and phys.
1666 void scic_sds_controller_post_request(
1667 struct scic_sds_controller
*this_controller
,
1670 dev_dbg(scic_to_dev(this_controller
),
1671 "%s: SCIC Controller 0x%p post request 0x%08x\n",
1676 SMU_PCP_WRITE(this_controller
, request
);
1680 * This method will copy the soft copy of the task context into the physical
1681 * memory accessible by the controller.
1682 * @this_controller: This parameter specifies the controller for which to copy
1684 * @this_request: This parameter specifies the request for which the task
1685 * context is being copied.
1687 * After this call is made the SCIC_SDS_IO_REQUEST object will always point to
1688 * the physical memory version of the task context. Thus, all subsequent
1689 * updates to the task context are performed in the TC table (i.e. DMAable
1692 void scic_sds_controller_copy_task_context(
1693 struct scic_sds_controller
*this_controller
,
1694 struct scic_sds_request
*this_request
)
1696 struct scu_task_context
*task_context_buffer
;
1698 task_context_buffer
= scic_sds_controller_get_task_context_buffer(
1699 this_controller
, this_request
->io_tag
1703 task_context_buffer
,
1704 this_request
->task_context_buffer
,
1705 SCI_FIELD_OFFSET(struct scu_task_context
, sgl_snapshot_ac
)
1709 * Now that the soft copy of the TC has been copied into the TC
1710 * table accessible by the silicon. Thus, any further changes to
1711 * the TC (e.g. TC termination) occur in the appropriate location. */
1712 this_request
->task_context_buffer
= task_context_buffer
;
1716 * This method returns the task context buffer for the given io tag.
1720 * struct scu_task_context*
1722 struct scu_task_context
*scic_sds_controller_get_task_context_buffer(
1723 struct scic_sds_controller
*this_controller
,
1726 u16 task_index
= scic_sds_io_tag_get_index(io_tag
);
1728 if (task_index
< this_controller
->task_context_entries
) {
1729 return &this_controller
->task_context_table
[task_index
];
1736 * This method returnst the sequence value from the io tag value
1744 * This method returns the IO request associated with the tag value
1748 * SCIC_SDS_IO_REQUEST_T* NULL if there is no valid IO request at the tag value
1750 struct scic_sds_request
*scic_sds_controller_get_io_request_from_tag(
1751 struct scic_sds_controller
*this_controller
,
1757 task_index
= scic_sds_io_tag_get_index(io_tag
);
1759 if (task_index
< this_controller
->task_context_entries
) {
1760 if (this_controller
->io_request_table
[task_index
] != NULL
) {
1761 task_sequence
= scic_sds_io_tag_get_sequence(io_tag
);
1763 if (task_sequence
== this_controller
->io_request_sequence
[task_index
]) {
1764 return this_controller
->io_request_table
[task_index
];
1773 * This method allocates remote node index and the reserves the remote node
1774 * context space for use. This method can fail if there are no more remote
1775 * node index available.
1776 * @this_controller: This is the controller object which contains the set of
1777 * free remote node ids
1778 * @the_devce: This is the device object which is requesting the a remote node
1780 * @node_id: This is the remote node id that is assinged to the device if one
1783 * enum sci_status SCI_FAILURE_OUT_OF_RESOURCES if there are no available remote
1784 * node index available.
1786 enum sci_status
scic_sds_controller_allocate_remote_node_context(
1787 struct scic_sds_controller
*this_controller
,
1788 struct scic_sds_remote_device
*the_device
,
1792 u32 remote_node_count
= scic_sds_remote_device_node_count(the_device
);
1794 node_index
= scic_sds_remote_node_table_allocate_remote_node(
1795 &this_controller
->available_remote_nodes
, remote_node_count
1798 if (node_index
!= SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
) {
1799 this_controller
->device_table
[node_index
] = the_device
;
1801 *node_id
= node_index
;
1806 return SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1810 * This method frees the remote node index back to the available pool. Once
1811 * this is done the remote node context buffer is no longer valid and can
1818 void scic_sds_controller_free_remote_node_context(
1819 struct scic_sds_controller
*this_controller
,
1820 struct scic_sds_remote_device
*the_device
,
1823 u32 remote_node_count
= scic_sds_remote_device_node_count(the_device
);
1825 if (this_controller
->device_table
[node_id
] == the_device
) {
1826 this_controller
->device_table
[node_id
] = NULL
;
1828 scic_sds_remote_node_table_release_remote_node_index(
1829 &this_controller
->available_remote_nodes
, remote_node_count
, node_id
1835 * This method returns the union scu_remote_node_context for the specified remote
1840 * union scu_remote_node_context*
1842 union scu_remote_node_context
*scic_sds_controller_get_remote_node_context_buffer(
1843 struct scic_sds_controller
*this_controller
,
1847 (node_id
< this_controller
->remote_node_entries
)
1848 && (this_controller
->device_table
[node_id
] != NULL
)
1850 return &this_controller
->remote_node_context_table
[node_id
];
1858 * @resposne_buffer: This is the buffer into which the D2H register FIS will be
1860 * @frame_header: This is the frame header returned by the hardware.
1861 * @frame_buffer: This is the frame buffer returned by the hardware.
1863 * This method will combind the frame header and frame buffer to create a SATA
1864 * D2H register FIS none
1866 void scic_sds_controller_copy_sata_response(
1867 void *response_buffer
,
1878 (char *)((char *)response_buffer
+ sizeof(u32
)),
1880 sizeof(struct sata_fis_reg_d2h
) - sizeof(u32
)
1885 * This method releases the frame once this is done the frame is available for
1886 * re-use by the hardware. The data contained in the frame header and frame
1887 * buffer is no longer valid. The UF queue get pointer is only updated if UF
1888 * control indicates this is appropriate.
1893 void scic_sds_controller_release_frame(
1894 struct scic_sds_controller
*this_controller
,
1897 if (scic_sds_unsolicited_frame_control_release_frame(
1898 &this_controller
->uf_control
, frame_index
) == true)
1899 SCU_UFQGP_WRITE(this_controller
, this_controller
->uf_control
.get
);
1903 * This method sets user parameters and OEM parameters to default values.
1904 * Users can override these values utilizing the scic_user_parameters_set()
1905 * and scic_oem_parameters_set() methods.
1906 * @scic: This parameter specifies the controller for which to set the
1907 * configuration parameters to their default values.
1910 static void scic_sds_controller_set_default_config_parameters(struct scic_sds_controller
*scic
)
1912 struct isci_host
*ihost
= sci_object_get_association(scic
);
1915 /* Default to APC mode. */
1916 scic
->oem_parameters
.sds1
.controller
.mode_type
= SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE
;
1918 /* Default to APC mode. */
1919 scic
->oem_parameters
.sds1
.controller
.max_concurrent_dev_spin_up
= 1;
1921 /* Default to no SSC operation. */
1922 scic
->oem_parameters
.sds1
.controller
.do_enable_ssc
= false;
1924 /* Initialize all of the port parameter information to narrow ports. */
1925 for (index
= 0; index
< SCI_MAX_PORTS
; index
++) {
1926 scic
->oem_parameters
.sds1
.ports
[index
].phy_mask
= 0;
1929 /* Initialize all of the phy parameter information. */
1930 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1931 /* Default to 6G (i.e. Gen 3) for now. */
1932 scic
->user_parameters
.sds1
.phys
[index
].max_speed_generation
= 3;
1934 /* the frequencies cannot be 0 */
1935 scic
->user_parameters
.sds1
.phys
[index
].align_insertion_frequency
= 0x7f;
1936 scic
->user_parameters
.sds1
.phys
[index
].in_connection_align_insertion_frequency
= 0xff;
1937 scic
->user_parameters
.sds1
.phys
[index
].notify_enable_spin_up_insertion_frequency
= 0x33;
1940 * Previous Vitesse based expanders had a arbitration issue that
1941 * is worked around by having the upper 32-bits of SAS address
1942 * with a value greater then the Vitesse company identifier.
1943 * Hence, usage of 0x5FCFFFFF. */
1944 scic
->oem_parameters
.sds1
.phys
[index
].sas_address
.low
= 0x1 + ihost
->id
;
1945 scic
->oem_parameters
.sds1
.phys
[index
].sas_address
.high
= 0x5FCFFFFF;
1948 scic
->user_parameters
.sds1
.stp_inactivity_timeout
= 5;
1949 scic
->user_parameters
.sds1
.ssp_inactivity_timeout
= 5;
1950 scic
->user_parameters
.sds1
.stp_max_occupancy_timeout
= 5;
1951 scic
->user_parameters
.sds1
.ssp_max_occupancy_timeout
= 20;
1952 scic
->user_parameters
.sds1
.no_outbound_task_timeout
= 20;
1956 * scic_controller_initialize() - This method will initialize the controller
1957 * hardware managed by the supplied core controller object. This method
1958 * will bring the physical controller hardware out of reset and enable the
1959 * core to determine the capabilities of the hardware being managed. Thus,
1960 * the core controller can determine it's exact physical (DMA capable)
1961 * memory requirements.
1962 * @controller: This parameter specifies the controller to be initialized.
1964 * The SCI Core user must have called scic_controller_construct() on the
1965 * supplied controller object previously. Indicate if the controller was
1966 * successfully initialized or if it failed in some way. SCI_SUCCESS This value
1967 * is returned if the controller hardware was successfully initialized.
1969 enum sci_status
scic_controller_initialize(
1970 struct scic_sds_controller
*scic
)
1972 enum sci_status status
= SCI_FAILURE_INVALID_STATE
;
1973 sci_base_controller_handler_t initialize
;
1976 state
= scic
->parent
.state_machine
.current_state_id
;
1977 initialize
= scic_sds_controller_state_handler_table
[state
].base
.initialize
;
1980 status
= initialize(&scic
->parent
);
1982 dev_warn(scic_to_dev(scic
),
1983 "%s: SCIC Controller initialize operation requested "
1984 "in invalid state %d\n", __func__
, state
);
1990 * scic_controller_get_suggested_start_timeout() - This method returns the
1991 * suggested scic_controller_start() timeout amount. The user is free to
1992 * use any timeout value, but this method provides the suggested minimum
1993 * start timeout value. The returned value is based upon empirical
1994 * information determined as a result of interoperability testing.
1995 * @controller: the handle to the controller object for which to return the
1996 * suggested start timeout.
1998 * This method returns the number of milliseconds for the suggested start
1999 * operation timeout.
2001 u32
scic_controller_get_suggested_start_timeout(
2002 struct scic_sds_controller
*sc
)
2004 /* Validate the user supplied parameters. */
2009 * The suggested minimum timeout value for a controller start operation:
2011 * Signature FIS Timeout
2012 * + Phy Start Timeout
2013 * + Number of Phy Spin Up Intervals
2014 * ---------------------------------
2015 * Number of milliseconds for the controller start operation.
2017 * NOTE: The number of phy spin up intervals will be equivalent
2018 * to the number of phys divided by the number phys allowed
2019 * per interval - 1 (once OEM parameters are supported).
2020 * Currently we assume only 1 phy per interval. */
2022 return SCIC_SDS_SIGNATURE_FIS_TIMEOUT
2023 + SCIC_SDS_CONTROLLER_PHY_START_TIMEOUT
2024 + ((SCI_MAX_PHYS
- 1) * SCIC_SDS_CONTROLLER_POWER_CONTROL_INTERVAL
);
2028 * scic_controller_start() - This method will start the supplied core
2029 * controller. This method will start the staggered spin up operation. The
2030 * SCI User completion callback is called when the following conditions are
2031 * met: -# the return status of this method is SCI_SUCCESS. -# after all of
2032 * the phys have successfully started or been given the opportunity to start.
2033 * @controller: the handle to the controller object to start.
2034 * @timeout: This parameter specifies the number of milliseconds in which the
2035 * start operation should complete.
2037 * The SCI Core user must have filled in the physical memory descriptor
2038 * structure via the sci_controller_get_memory_descriptor_list() method. The
2039 * SCI Core user must have invoked the scic_controller_initialize() method
2040 * prior to invoking this method. The controller must be in the INITIALIZED or
2041 * STARTED state. Indicate if the controller start method succeeded or failed
2042 * in some way. SCI_SUCCESS if the start operation succeeded.
2043 * SCI_WARNING_ALREADY_IN_STATE if the controller is already in the STARTED
2044 * state. SCI_FAILURE_INVALID_STATE if the controller is not either in the
2045 * INITIALIZED or STARTED states. SCI_FAILURE_INVALID_MEMORY_DESCRIPTOR if
2046 * there are inconsistent or invalid values in the supplied
2047 * struct sci_physical_memory_descriptor array.
2049 enum sci_status
scic_controller_start(
2050 struct scic_sds_controller
*scic
,
2053 enum sci_status status
= SCI_FAILURE_INVALID_STATE
;
2054 sci_base_controller_timed_handler_t start
;
2057 state
= scic
->parent
.state_machine
.current_state_id
;
2058 start
= scic_sds_controller_state_handler_table
[state
].base
.start
;
2061 status
= start(&scic
->parent
, timeout
);
2063 dev_warn(scic_to_dev(scic
),
2064 "%s: SCIC Controller start operation requested in "
2065 "invalid state %d\n", __func__
, state
);
2071 * scic_controller_stop() - This method will stop an individual controller
2072 * object.This method will invoke the associated user callback upon
2073 * completion. The completion callback is called when the following
2074 * conditions are met: -# the method return status is SCI_SUCCESS. -# the
2075 * controller has been quiesced. This method will ensure that all IO
2076 * requests are quiesced, phys are stopped, and all additional operation by
2077 * the hardware is halted.
2078 * @controller: the handle to the controller object to stop.
2079 * @timeout: This parameter specifies the number of milliseconds in which the
2080 * stop operation should complete.
2082 * The controller must be in the STARTED or STOPPED state. Indicate if the
2083 * controller stop method succeeded or failed in some way. SCI_SUCCESS if the
2084 * stop operation successfully began. SCI_WARNING_ALREADY_IN_STATE if the
2085 * controller is already in the STOPPED state. SCI_FAILURE_INVALID_STATE if the
2086 * controller is not either in the STARTED or STOPPED states.
2088 enum sci_status
scic_controller_stop(
2089 struct scic_sds_controller
*scic
,
2092 enum sci_status status
= SCI_FAILURE_INVALID_STATE
;
2093 sci_base_controller_timed_handler_t stop
;
2096 state
= scic
->parent
.state_machine
.current_state_id
;
2097 stop
= scic_sds_controller_state_handler_table
[state
].base
.stop
;
2100 status
= stop(&scic
->parent
, timeout
);
2102 dev_warn(scic_to_dev(scic
),
2103 "%s: SCIC Controller stop operation requested in "
2104 "invalid state %d\n", __func__
, state
);
2110 * scic_controller_reset() - This method will reset the supplied core
2111 * controller regardless of the state of said controller. This operation is
2112 * considered destructive. In other words, all current operations are wiped
2113 * out. No IO completions for outstanding devices occur. Outstanding IO
2114 * requests are not aborted or completed at the actual remote device.
2115 * @controller: the handle to the controller object to reset.
2117 * Indicate if the controller reset method succeeded or failed in some way.
2118 * SCI_SUCCESS if the reset operation successfully started. SCI_FATAL_ERROR if
2119 * the controller reset operation is unable to complete.
2121 enum sci_status
scic_controller_reset(
2122 struct scic_sds_controller
*scic
)
2124 enum sci_status status
= SCI_FAILURE_INVALID_STATE
;
2125 sci_base_controller_handler_t reset
;
2128 state
= scic
->parent
.state_machine
.current_state_id
;
2129 reset
= scic_sds_controller_state_handler_table
[state
].base
.reset
;
2132 status
= reset(&scic
->parent
);
2134 dev_warn(scic_to_dev(scic
),
2135 "%s: SCIC Controller reset operation requested in "
2136 "invalid state %d\n", __func__
, state
);
2142 * scic_controller_start_io() - This method is called by the SCI user to
2143 * send/start an IO request. If the method invocation is successful, then
2144 * the IO request has been queued to the hardware for processing.
2145 * @controller: the handle to the controller object for which to start an IO
2147 * @remote_device: the handle to the remote device object for which to start an
2149 * @io_request: the handle to the io request object to start.
2150 * @io_tag: This parameter specifies a previously allocated IO tag that the
2151 * user desires to be utilized for this request. This parameter is optional.
2152 * The user is allowed to supply SCI_CONTROLLER_INVALID_IO_TAG as the value
2153 * for this parameter.
2155 * - IO tags are a protected resource. It is incumbent upon the SCI Core user
2156 * to ensure that each of the methods that may allocate or free available IO
2157 * tags are handled in a mutually exclusive manner. This method is one of said
2158 * methods requiring proper critical code section protection (e.g. semaphore,
2159 * spin-lock, etc.). - For SATA, the user is required to manage NCQ tags. As a
2160 * result, it is expected the user will have set the NCQ tag field in the host
2161 * to device register FIS prior to calling this method. There is also a
2162 * requirement for the user to call scic_stp_io_set_ncq_tag() prior to invoking
2163 * the scic_controller_start_io() method. scic_controller_allocate_tag() for
2164 * more information on allocating a tag. Indicate if the controller
2165 * successfully started the IO request. SCI_IO_SUCCESS if the IO request was
2166 * successfully started. Determine the failure situations and return values.
2168 enum sci_io_status
scic_controller_start_io(
2169 struct scic_sds_controller
*scic
,
2170 struct scic_sds_remote_device
*remote_device
,
2171 struct scic_sds_request
*io_request
,
2175 sci_base_controller_start_request_handler_t start_io
;
2177 state
= scic
->parent
.state_machine
.current_state_id
;
2178 start_io
= scic_sds_controller_state_handler_table
[state
].base
.start_io
;
2180 return start_io(&scic
->parent
,
2181 (struct sci_base_remote_device
*) remote_device
,
2182 (struct sci_base_request
*)io_request
, io_tag
);
2186 * scic_controller_terminate_request() - This method is called by the SCI Core
2187 * user to terminate an ongoing (i.e. started) core IO request. This does
2188 * not abort the IO request at the target, but rather removes the IO request
2189 * from the host controller.
2190 * @controller: the handle to the controller object for which to terminate a
2192 * @remote_device: the handle to the remote device object for which to
2193 * terminate a request.
2194 * @request: the handle to the io or task management request object to
2197 * Indicate if the controller successfully began the terminate process for the
2198 * IO request. SCI_SUCCESS if the terminate process was successfully started
2199 * for the request. Determine the failure situations and return values.
2201 enum sci_status
scic_controller_terminate_request(
2202 struct scic_sds_controller
*scic
,
2203 struct scic_sds_remote_device
*remote_device
,
2204 struct scic_sds_request
*request
)
2206 sci_base_controller_request_handler_t terminate_request
;
2209 state
= scic
->parent
.state_machine
.current_state_id
;
2210 terminate_request
= scic_sds_controller_state_handler_table
[state
].terminate_request
;
2212 return terminate_request(&scic
->parent
,
2213 (struct sci_base_remote_device
*)remote_device
,
2214 (struct sci_base_request
*)request
);
2218 * scic_controller_complete_io() - This method will perform core specific
2219 * completion operations for an IO request. After this method is invoked,
2220 * the user should consider the IO request as invalid until it is properly
2221 * reused (i.e. re-constructed).
2222 * @controller: The handle to the controller object for which to complete the
2224 * @remote_device: The handle to the remote device object for which to complete
2226 * @io_request: the handle to the io request object to complete.
2228 * - IO tags are a protected resource. It is incumbent upon the SCI Core user
2229 * to ensure that each of the methods that may allocate or free available IO
2230 * tags are handled in a mutually exclusive manner. This method is one of said
2231 * methods requiring proper critical code section protection (e.g. semaphore,
2232 * spin-lock, etc.). - If the IO tag for a request was allocated, by the SCI
2233 * Core user, using the scic_controller_allocate_io_tag() method, then it is
2234 * the responsibility of the caller to invoke the scic_controller_free_io_tag()
2235 * method to free the tag (i.e. this method will not free the IO tag). Indicate
2236 * if the controller successfully completed the IO request. SCI_SUCCESS if the
2237 * completion process was successful.
2239 enum sci_status
scic_controller_complete_io(
2240 struct scic_sds_controller
*scic
,
2241 struct scic_sds_remote_device
*remote_device
,
2242 struct scic_sds_request
*io_request
)
2245 sci_base_controller_request_handler_t complete_io
;
2247 state
= scic
->parent
.state_machine
.current_state_id
;
2248 complete_io
= scic_sds_controller_state_handler_table
[state
].base
.complete_io
;
2250 return complete_io(&scic
->parent
,
2251 (struct sci_base_remote_device
*)remote_device
,
2252 (struct sci_base_request
*)io_request
);
2256 * scic_controller_start_task() - This method is called by the SCIC user to
2257 * send/start a framework task management request.
2258 * @controller: the handle to the controller object for which to start the task
2259 * management request.
2260 * @remote_device: the handle to the remote device object for which to start
2261 * the task management request.
2262 * @task_request: the handle to the task request object to start.
2263 * @io_tag: This parameter specifies a previously allocated IO tag that the
2264 * user desires to be utilized for this request. Note this not the io_tag
2265 * of the request being managed. It is to be utilized for the task request
2266 * itself. This parameter is optional. The user is allowed to supply
2267 * SCI_CONTROLLER_INVALID_IO_TAG as the value for this parameter.
2269 * - IO tags are a protected resource. It is incumbent upon the SCI Core user
2270 * to ensure that each of the methods that may allocate or free available IO
2271 * tags are handled in a mutually exclusive manner. This method is one of said
2272 * methods requiring proper critical code section protection (e.g. semaphore,
2273 * spin-lock, etc.). - The user must synchronize this task with completion
2274 * queue processing. If they are not synchronized then it is possible for the
2275 * io requests that are being managed by the task request can complete before
2276 * starting the task request. scic_controller_allocate_tag() for more
2277 * information on allocating a tag. Indicate if the controller successfully
2278 * started the IO request. SCI_TASK_SUCCESS if the task request was
2279 * successfully started. SCI_TASK_FAILURE_REQUIRES_SCSI_ABORT This value is
2280 * returned if there is/are task(s) outstanding that require termination or
2281 * completion before this request can succeed.
2283 enum sci_task_status
scic_controller_start_task(
2284 struct scic_sds_controller
*scic
,
2285 struct scic_sds_remote_device
*remote_device
,
2286 struct scic_sds_request
*task_request
,
2290 sci_base_controller_start_request_handler_t start_task
;
2291 enum sci_task_status status
= SCI_TASK_FAILURE_INVALID_STATE
;
2293 state
= scic
->parent
.state_machine
.current_state_id
;
2294 start_task
= scic_sds_controller_state_handler_table
[state
].base
.start_task
;
2297 status
= start_task(&scic
->parent
,
2298 (struct sci_base_remote_device
*)remote_device
,
2299 (struct sci_base_request
*)task_request
,
2302 dev_warn(scic_to_dev(scic
),
2303 "%s: SCIC Controller starting task from invalid "
2311 * scic_controller_complete_task() - This method will perform core specific
2312 * completion operations for task management request. After this method is
2313 * invoked, the user should consider the task request as invalid until it is
2314 * properly reused (i.e. re-constructed).
2315 * @controller: The handle to the controller object for which to complete the
2316 * task management request.
2317 * @remote_device: The handle to the remote device object for which to complete
2318 * the task management request.
2319 * @task_request: the handle to the task management request object to complete.
2321 * Indicate if the controller successfully completed the task management
2322 * request. SCI_SUCCESS if the completion process was successful.
2324 enum sci_status
scic_controller_complete_task(
2325 struct scic_sds_controller
*scic
,
2326 struct scic_sds_remote_device
*remote_device
,
2327 struct scic_sds_request
*task_request
)
2330 sci_base_controller_request_handler_t complete_task
;
2331 enum sci_status status
= SCI_FAILURE_INVALID_STATE
;
2333 state
= scic
->parent
.state_machine
.current_state_id
;
2334 complete_task
= scic_sds_controller_state_handler_table
[state
].base
.complete_task
;
2337 status
= complete_task(&scic
->parent
,
2338 (struct sci_base_remote_device
*)remote_device
,
2339 (struct sci_base_request
*)task_request
);
2341 dev_warn(scic_to_dev(scic
),
2342 "%s: SCIC Controller completing task from invalid "
2351 * scic_controller_get_port_handle() - This method simply provides the user
2352 * with a unique handle for a given SAS/SATA core port index.
2353 * @controller: This parameter represents the handle to the controller object
2354 * from which to retrieve a port (SAS or SATA) handle.
2355 * @port_index: This parameter specifies the port index in the controller for
2356 * which to retrieve the port handle. 0 <= port_index < maximum number of
2358 * @port_handle: This parameter specifies the retrieved port handle to be
2359 * provided to the caller.
2361 * Indicate if the retrieval of the port handle was successful. SCI_SUCCESS
2362 * This value is returned if the retrieval was successful.
2363 * SCI_FAILURE_INVALID_PORT This value is returned if the supplied port id is
2364 * not in the supported range.
2366 enum sci_status
scic_controller_get_port_handle(
2367 struct scic_sds_controller
*scic
,
2369 struct scic_sds_port
**port_handle
)
2371 if (port_index
< scic
->logical_port_entries
) {
2372 *port_handle
= &scic
->port_table
[port_index
];
2377 return SCI_FAILURE_INVALID_PORT
;
2381 * scic_controller_get_phy_handle() - This method simply provides the user with
2382 * a unique handle for a given SAS/SATA phy index/identifier.
2383 * @controller: This parameter represents the handle to the controller object
2384 * from which to retrieve a phy (SAS or SATA) handle.
2385 * @phy_index: This parameter specifies the phy index in the controller for
2386 * which to retrieve the phy handle. 0 <= phy_index < maximum number of phys.
2387 * @phy_handle: This parameter specifies the retrieved phy handle to be
2388 * provided to the caller.
2390 * Indicate if the retrieval of the phy handle was successful. SCI_SUCCESS This
2391 * value is returned if the retrieval was successful. SCI_FAILURE_INVALID_PHY
2392 * This value is returned if the supplied phy id is not in the supported range.
2394 enum sci_status
scic_controller_get_phy_handle(
2395 struct scic_sds_controller
*scic
,
2397 struct scic_sds_phy
**phy_handle
)
2399 if (phy_index
< ARRAY_SIZE(scic
->phy_table
)) {
2400 *phy_handle
= &scic
->phy_table
[phy_index
];
2405 dev_err(scic_to_dev(scic
),
2406 "%s: Controller:0x%p PhyId:0x%x invalid phy index\n",
2407 __func__
, scic
, phy_index
);
2409 return SCI_FAILURE_INVALID_PHY
;
2413 * scic_controller_allocate_io_tag() - This method will allocate a tag from the
2414 * pool of free IO tags. Direct allocation of IO tags by the SCI Core user
2415 * is optional. The scic_controller_start_io() method will allocate an IO
2416 * tag if this method is not utilized and the tag is not supplied to the IO
2417 * construct routine. Direct allocation of IO tags may provide additional
2418 * performance improvements in environments capable of supporting this usage
2419 * model. Additionally, direct allocation of IO tags also provides
2420 * additional flexibility to the SCI Core user. Specifically, the user may
2421 * retain IO tags across the lives of multiple IO requests.
2422 * @controller: the handle to the controller object for which to allocate the
2425 * IO tags are a protected resource. It is incumbent upon the SCI Core user to
2426 * ensure that each of the methods that may allocate or free available IO tags
2427 * are handled in a mutually exclusive manner. This method is one of said
2428 * methods requiring proper critical code section protection (e.g. semaphore,
2429 * spin-lock, etc.). An unsigned integer representing an available IO tag.
2430 * SCI_CONTROLLER_INVALID_IO_TAG This value is returned if there are no
2431 * currently available tags to be allocated. All return other values indicate a
2434 u16
scic_controller_allocate_io_tag(
2435 struct scic_sds_controller
*scic
)
2440 if (!sci_pool_empty(scic
->tci_pool
)) {
2441 sci_pool_get(scic
->tci_pool
, task_context
);
2443 sequence_count
= scic
->io_request_sequence
[task_context
];
2445 return scic_sds_io_tag_construct(sequence_count
, task_context
);
2448 return SCI_CONTROLLER_INVALID_IO_TAG
;
2452 * scic_controller_free_io_tag() - This method will free an IO tag to the pool
2453 * of free IO tags. This method provides the SCI Core user more flexibility
2454 * with regards to IO tags. The user may desire to keep an IO tag after an
2455 * IO request has completed, because they plan on re-using the tag for a
2456 * subsequent IO request. This method is only legal if the tag was
2457 * allocated via scic_controller_allocate_io_tag().
2458 * @controller: This parameter specifies the handle to the controller object
2459 * for which to free/return the tag.
2460 * @io_tag: This parameter represents the tag to be freed to the pool of
2463 * - IO tags are a protected resource. It is incumbent upon the SCI Core user
2464 * to ensure that each of the methods that may allocate or free available IO
2465 * tags are handled in a mutually exclusive manner. This method is one of said
2466 * methods requiring proper critical code section protection (e.g. semaphore,
2467 * spin-lock, etc.). - If the IO tag for a request was allocated, by the SCI
2468 * Core user, using the scic_controller_allocate_io_tag() method, then it is
2469 * the responsibility of the caller to invoke this method to free the tag. This
2470 * method returns an indication of whether the tag was successfully put back
2471 * (freed) to the pool of available tags. SCI_SUCCESS This return value
2472 * indicates the tag was successfully placed into the pool of available IO
2473 * tags. SCI_FAILURE_INVALID_IO_TAG This value is returned if the supplied tag
2474 * is not a valid IO tag value.
2476 enum sci_status
scic_controller_free_io_tag(
2477 struct scic_sds_controller
*scic
,
2483 BUG_ON(io_tag
== SCI_CONTROLLER_INVALID_IO_TAG
);
2485 sequence
= scic_sds_io_tag_get_sequence(io_tag
);
2486 index
= scic_sds_io_tag_get_index(io_tag
);
2488 if (!sci_pool_full(scic
->tci_pool
)) {
2489 if (sequence
== scic
->io_request_sequence
[index
]) {
2490 scic_sds_io_sequence_increment(
2491 scic
->io_request_sequence
[index
]);
2493 sci_pool_put(scic
->tci_pool
, index
);
2499 return SCI_FAILURE_INVALID_IO_TAG
;
2502 void scic_controller_enable_interrupts(
2503 struct scic_sds_controller
*scic
)
2505 BUG_ON(scic
->smu_registers
== NULL
);
2506 SMU_IMR_WRITE(scic
, 0x00000000);
2509 void scic_controller_disable_interrupts(
2510 struct scic_sds_controller
*scic
)
2512 BUG_ON(scic
->smu_registers
== NULL
);
2513 SMU_IMR_WRITE(scic
, 0xffffffff);
2516 static enum sci_status
scic_controller_set_mode(
2517 struct scic_sds_controller
*scic
,
2518 enum sci_controller_mode operating_mode
)
2520 enum sci_status status
= SCI_SUCCESS
;
2522 if ((scic
->parent
.state_machine
.current_state_id
==
2523 SCI_BASE_CONTROLLER_STATE_INITIALIZING
) ||
2524 (scic
->parent
.state_machine
.current_state_id
==
2525 SCI_BASE_CONTROLLER_STATE_INITIALIZED
)) {
2526 switch (operating_mode
) {
2527 case SCI_MODE_SPEED
:
2528 scic
->remote_node_entries
= SCI_MAX_REMOTE_DEVICES
;
2529 scic
->task_context_entries
= SCU_IO_REQUEST_COUNT
;
2530 scic
->uf_control
.buffers
.count
=
2531 SCU_UNSOLICITED_FRAME_COUNT
;
2532 scic
->completion_event_entries
= SCU_EVENT_COUNT
;
2533 scic
->completion_queue_entries
=
2534 SCU_COMPLETION_QUEUE_COUNT
;
2535 scic_sds_controller_build_memory_descriptor_table(scic
);
2539 scic
->remote_node_entries
= SCI_MIN_REMOTE_DEVICES
;
2540 scic
->task_context_entries
= SCI_MIN_IO_REQUESTS
;
2541 scic
->uf_control
.buffers
.count
=
2542 SCU_MIN_UNSOLICITED_FRAMES
;
2543 scic
->completion_event_entries
= SCU_MIN_EVENTS
;
2544 scic
->completion_queue_entries
=
2545 SCU_MIN_COMPLETION_QUEUE_ENTRIES
;
2546 scic_sds_controller_build_memory_descriptor_table(scic
);
2550 status
= SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2554 status
= SCI_FAILURE_INVALID_STATE
;
2560 * scic_sds_controller_reset_hardware() -
2562 * This method will reset the controller hardware.
2564 static void scic_sds_controller_reset_hardware(
2565 struct scic_sds_controller
*scic
)
2567 /* Disable interrupts so we dont take any spurious interrupts */
2568 scic_controller_disable_interrupts(scic
);
2571 SMU_SMUSRCR_WRITE(scic
, 0xFFFFFFFF);
2573 /* Delay for 1ms to before clearing the CQP and UFQPR. */
2576 /* The write to the CQGR clears the CQP */
2577 SMU_CQGR_WRITE(scic
, 0x00000000);
2579 /* The write to the UFQGP clears the UFQPR */
2580 SCU_UFQGP_WRITE(scic
, 0x00000000);
2583 enum sci_status
scic_user_parameters_set(
2584 struct scic_sds_controller
*scic
,
2585 union scic_user_parameters
*scic_parms
)
2587 u32 state
= scic
->parent
.state_machine
.current_state_id
;
2589 if (state
== SCI_BASE_CONTROLLER_STATE_RESET
||
2590 state
== SCI_BASE_CONTROLLER_STATE_INITIALIZING
||
2591 state
== SCI_BASE_CONTROLLER_STATE_INITIALIZED
) {
2595 * Validate the user parameters. If they are not legal, then
2598 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
2599 struct sci_phy_user_params
*user_phy
;
2601 user_phy
= &scic_parms
->sds1
.phys
[index
];
2603 if (!((user_phy
->max_speed_generation
<=
2604 SCIC_SDS_PARM_MAX_SPEED
) &&
2605 (user_phy
->max_speed_generation
>
2606 SCIC_SDS_PARM_NO_SPEED
)))
2607 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2609 if (user_phy
->in_connection_align_insertion_frequency
<
2611 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2613 if ((user_phy
->in_connection_align_insertion_frequency
<
2615 (user_phy
->align_insertion_frequency
== 0) ||
2617 notify_enable_spin_up_insertion_frequency
==
2619 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2622 if ((scic_parms
->sds1
.stp_inactivity_timeout
== 0) ||
2623 (scic_parms
->sds1
.ssp_inactivity_timeout
== 0) ||
2624 (scic_parms
->sds1
.stp_max_occupancy_timeout
== 0) ||
2625 (scic_parms
->sds1
.ssp_max_occupancy_timeout
== 0) ||
2626 (scic_parms
->sds1
.no_outbound_task_timeout
== 0))
2627 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2629 memcpy(&scic
->user_parameters
, scic_parms
, sizeof(*scic_parms
));
2634 return SCI_FAILURE_INVALID_STATE
;
2637 enum sci_status
scic_oem_parameters_set(
2638 struct scic_sds_controller
*scic
,
2639 union scic_oem_parameters
*scic_parms
)
2641 u32 state
= scic
->parent
.state_machine
.current_state_id
;
2643 if (state
== SCI_BASE_CONTROLLER_STATE_RESET
||
2644 state
== SCI_BASE_CONTROLLER_STATE_INITIALIZING
||
2645 state
== SCI_BASE_CONTROLLER_STATE_INITIALIZED
) {
2647 u8 combined_phy_mask
= 0;
2650 * Validate the oem parameters. If they are not legal, then
2651 * return a failure. */
2652 for (index
= 0; index
< SCI_MAX_PORTS
; index
++) {
2653 if (scic_parms
->sds1
.ports
[index
].phy_mask
> SCIC_SDS_PARM_PHY_MASK_MAX
)
2654 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2657 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
2658 if ((scic_parms
->sds1
.phys
[index
].sas_address
.high
== 0) &&
2659 (scic_parms
->sds1
.phys
[index
].sas_address
.low
== 0))
2660 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2663 if (scic_parms
->sds1
.controller
.mode_type
==
2664 SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE
) {
2665 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
2666 if (scic_parms
->sds1
.ports
[index
].phy_mask
!= 0)
2667 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2669 } else if (scic_parms
->sds1
.controller
.mode_type
==
2670 SCIC_PORT_MANUAL_CONFIGURATION_MODE
) {
2671 for (index
= 0; index
< SCI_MAX_PHYS
; index
++)
2672 combined_phy_mask
|= scic_parms
->sds1
.ports
[index
].phy_mask
;
2674 if (combined_phy_mask
== 0)
2675 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2677 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2679 if (scic_parms
->sds1
.controller
.max_concurrent_dev_spin_up
>
2680 MAX_CONCURRENT_DEVICE_SPIN_UP_COUNT
)
2681 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2683 scic
->oem_parameters
.sds1
= scic_parms
->sds1
;
2688 return SCI_FAILURE_INVALID_STATE
;
2691 void scic_oem_parameters_get(
2692 struct scic_sds_controller
*scic
,
2693 union scic_oem_parameters
*scic_parms
)
2695 memcpy(scic_parms
, (&scic
->oem_parameters
), sizeof(*scic_parms
));
2698 #define INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_LOWER_BOUND_NS 853
2699 #define INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_UPPER_BOUND_NS 1280
2700 #define INTERRUPT_COALESCE_TIMEOUT_MAX_US 2700000
2701 #define INTERRUPT_COALESCE_NUMBER_MAX 256
2702 #define INTERRUPT_COALESCE_TIMEOUT_ENCODE_MIN 7
2703 #define INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX 28
2706 * scic_controller_set_interrupt_coalescence() - This method allows the user to
2707 * configure the interrupt coalescence.
2708 * @controller: This parameter represents the handle to the controller object
2709 * for which its interrupt coalesce register is overridden.
2710 * @coalesce_number: Used to control the number of entries in the Completion
2711 * Queue before an interrupt is generated. If the number of entries exceed
2712 * this number, an interrupt will be generated. The valid range of the input
2713 * is [0, 256]. A setting of 0 results in coalescing being disabled.
2714 * @coalesce_timeout: Timeout value in microseconds. The valid range of the
2715 * input is [0, 2700000] . A setting of 0 is allowed and results in no
2716 * interrupt coalescing timeout.
2718 * Indicate if the user successfully set the interrupt coalesce parameters.
2719 * SCI_SUCCESS The user successfully updated the interrutp coalescence.
2720 * SCI_FAILURE_INVALID_PARAMETER_VALUE The user input value is out of range.
2722 static enum sci_status
scic_controller_set_interrupt_coalescence(
2723 struct scic_sds_controller
*scic_controller
,
2724 u32 coalesce_number
,
2725 u32 coalesce_timeout
)
2727 u8 timeout_encode
= 0;
2731 /* Check if the input parameters fall in the range. */
2732 if (coalesce_number
> INTERRUPT_COALESCE_NUMBER_MAX
)
2733 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2736 * Defined encoding for interrupt coalescing timeout:
2737 * Value Min Max Units
2738 * ----- --- --- -----
2768 * Others Undefined */
2771 * Use the table above to decide the encode of interrupt coalescing timeout
2772 * value for register writing. */
2773 if (coalesce_timeout
== 0)
2776 /* make the timeout value in unit of (10 ns). */
2777 coalesce_timeout
= coalesce_timeout
* 100;
2778 min
= INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_LOWER_BOUND_NS
/ 10;
2779 max
= INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_UPPER_BOUND_NS
/ 10;
2781 /* get the encode of timeout for register writing. */
2782 for (timeout_encode
= INTERRUPT_COALESCE_TIMEOUT_ENCODE_MIN
;
2783 timeout_encode
<= INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX
;
2785 if (min
<= coalesce_timeout
&& max
> coalesce_timeout
)
2787 else if (coalesce_timeout
>= max
&& coalesce_timeout
< min
* 2
2788 && coalesce_timeout
<= INTERRUPT_COALESCE_TIMEOUT_MAX_US
* 100) {
2789 if ((coalesce_timeout
- max
) < (2 * min
- coalesce_timeout
))
2801 if (timeout_encode
== INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX
+ 1)
2802 /* the value is out of range. */
2803 return SCI_FAILURE_INVALID_PARAMETER_VALUE
;
2808 (SMU_ICC_GEN_VAL(NUMBER
, coalesce_number
) |
2809 SMU_ICC_GEN_VAL(TIMER
, timeout_encode
))
2812 scic_controller
->interrupt_coalesce_number
= (u16
)coalesce_number
;
2813 scic_controller
->interrupt_coalesce_timeout
= coalesce_timeout
/ 100;
2819 struct scic_sds_controller
*scic_controller_alloc(struct device
*dev
)
2821 return devm_kzalloc(dev
, sizeof(struct scic_sds_controller
), GFP_KERNEL
);
2824 static enum sci_status
default_controller_handler(struct sci_base_controller
*base_scic
,
2827 struct scic_sds_controller
*scic
= container_of(base_scic
, typeof(*scic
), parent
);
2828 u32 state
= base_scic
->state_machine
.current_state_id
;
2830 dev_warn(scic_to_dev(scic
), "%s: invalid state %d\n", func
, state
);
2832 return SCI_FAILURE_INVALID_STATE
;
2835 static enum sci_status
scic_sds_controller_default_start_operation_handler(
2836 struct sci_base_controller
*base_scic
,
2837 struct sci_base_remote_device
*remote_device
,
2838 struct sci_base_request
*io_request
,
2841 return default_controller_handler(base_scic
, __func__
);
2844 static enum sci_status
scic_sds_controller_default_request_handler(
2845 struct sci_base_controller
*base_scic
,
2846 struct sci_base_remote_device
*remote_device
,
2847 struct sci_base_request
*io_request
)
2849 return default_controller_handler(base_scic
, __func__
);
2852 static enum sci_status
scic_sds_controller_general_reset_handler(struct sci_base_controller
*base_scic
)
2854 /* The reset operation is not a graceful cleanup just perform the state
2857 sci_base_state_machine_change_state(&base_scic
->state_machine
,
2858 SCI_BASE_CONTROLLER_STATE_RESETTING
);
2863 static enum sci_status
scic_sds_controller_reset_state_initialize_handler(struct sci_base_controller
*base_scic
)
2865 struct sci_base_state_machine
*sm
= &base_scic
->state_machine
;
2866 enum sci_status result
= SCI_SUCCESS
;
2867 struct scic_sds_controller
*scic
;
2868 struct isci_host
*ihost
;
2871 scic
= container_of(base_scic
, typeof(*scic
), parent
);
2872 ihost
= sci_object_get_association(scic
);
2874 sci_base_state_machine_change_state(sm
, SCI_BASE_CONTROLLER_STATE_INITIALIZING
);
2876 scic
->timeout_timer
= isci_timer_create(ihost
,
2878 scic_sds_controller_timeout_handler
);
2880 scic_sds_controller_initialize_phy_startup(scic
);
2882 scic_sds_controller_initialize_power_control(scic
);
2885 * There is nothing to do here for B0 since we do not have to
2886 * program the AFE registers.
2887 * / @todo The AFE settings are supposed to be correct for the B0 but
2888 * / presently they seem to be wrong. */
2889 scic_sds_controller_afe_initialization(scic
);
2891 if (result
== SCI_SUCCESS
) {
2895 /* Take the hardware out of reset */
2896 SMU_SMUSRCR_WRITE(scic
, 0x00000000);
2899 * / @todo Provide meaningfull error code for hardware failure
2900 * result = SCI_FAILURE_CONTROLLER_HARDWARE; */
2901 result
= SCI_FAILURE
;
2902 terminate_loop
= 100;
2904 while (terminate_loop
-- && (result
!= SCI_SUCCESS
)) {
2905 /* Loop until the hardware reports success */
2906 udelay(SCU_CONTEXT_RAM_INIT_STALL_TIME
);
2907 status
= SMU_SMUCSR_READ(scic
);
2909 if ((status
& SCU_RAM_INIT_COMPLETED
) ==
2910 SCU_RAM_INIT_COMPLETED
)
2911 result
= SCI_SUCCESS
;
2915 if (result
== SCI_SUCCESS
) {
2916 u32 max_supported_ports
;
2917 u32 max_supported_devices
;
2918 u32 max_supported_io_requests
;
2919 u32 device_context_capacity
;
2922 * Determine what are the actaul device capacities that the
2923 * hardware will support */
2924 device_context_capacity
= SMU_DCC_READ(scic
);
2926 max_supported_ports
= smu_dcc_get_max_ports(device_context_capacity
);
2927 max_supported_devices
= smu_dcc_get_max_remote_node_context(device_context_capacity
);
2928 max_supported_io_requests
= smu_dcc_get_max_task_context(device_context_capacity
);
2931 * Make all PEs that are unassigned match up with the
2934 for (index
= 0; index
< max_supported_ports
; index
++) {
2935 struct scu_port_task_scheduler_group_registers
*ptsg
=
2936 &scic
->scu_registers
->peg0
.ptsg
;
2938 scu_register_write(scic
,
2939 ptsg
->protocol_engine
[index
],
2943 /* Record the smaller of the two capacity values */
2944 scic
->logical_port_entries
=
2945 min(max_supported_ports
, scic
->logical_port_entries
);
2947 scic
->task_context_entries
=
2948 min(max_supported_io_requests
,
2949 scic
->task_context_entries
);
2951 scic
->remote_node_entries
=
2952 min(max_supported_devices
, scic
->remote_node_entries
);
2955 * Now that we have the correct hardware reported minimum values
2956 * build the MDL for the controller. Default to a performance
2959 scic_controller_set_mode(scic
, SCI_MODE_SPEED
);
2962 /* Initialize hardware PCI Relaxed ordering in DMA engines */
2963 if (result
== SCI_SUCCESS
) {
2964 u32 dma_configuration
;
2966 /* Configure the payload DMA */
2967 dma_configuration
= SCU_PDMACR_READ(scic
);
2968 dma_configuration
|=
2969 SCU_PDMACR_GEN_BIT(PCI_RELAXED_ORDERING_ENABLE
);
2970 SCU_PDMACR_WRITE(scic
, dma_configuration
);
2972 /* Configure the control DMA */
2973 dma_configuration
= SCU_CDMACR_READ(scic
);
2974 dma_configuration
|=
2975 SCU_CDMACR_GEN_BIT(PCI_RELAXED_ORDERING_ENABLE
);
2976 SCU_CDMACR_WRITE(scic
, dma_configuration
);
2980 * Initialize the PHYs before the PORTs because the PHY registers
2981 * are accessed during the port initialization.
2983 if (result
== SCI_SUCCESS
) {
2984 /* Initialize the phys */
2986 (result
== SCI_SUCCESS
) && (index
< SCI_MAX_PHYS
);
2988 result
= scic_sds_phy_initialize(
2989 &scic
->phy_table
[index
],
2990 &scic
->scu_registers
->peg0
.pe
[index
].tl
,
2991 &scic
->scu_registers
->peg0
.pe
[index
].ll
);
2995 if (result
== SCI_SUCCESS
) {
2996 /* Initialize the logical ports */
2998 (index
< scic
->logical_port_entries
) &&
2999 (result
== SCI_SUCCESS
);
3001 result
= scic_sds_port_initialize(
3002 &scic
->port_table
[index
],
3003 &scic
->scu_registers
->peg0
.ptsg
.port
[index
],
3004 &scic
->scu_registers
->peg0
.ptsg
.protocol_engine
,
3005 &scic
->scu_registers
->peg0
.viit
[index
]);
3009 if (result
== SCI_SUCCESS
)
3010 result
= scic_sds_port_configuration_agent_initialize(
3014 /* Advance the controller state machine */
3015 if (result
== SCI_SUCCESS
)
3016 state
= SCI_BASE_CONTROLLER_STATE_INITIALIZED
;
3018 state
= SCI_BASE_CONTROLLER_STATE_FAILED
;
3019 sci_base_state_machine_change_state(sm
, state
);
3025 * *****************************************************************************
3026 * * INITIALIZED STATE HANDLERS
3027 * ***************************************************************************** */
3031 * @controller: This is the struct sci_base_controller object which is cast
3032 * into a struct scic_sds_controller object.
3033 * @timeout: This is the allowed time for the controller object to reach the
3036 * This function is the struct scic_sds_controller start handler for the
3037 * initialized state.
3038 * - Validate we have a good memory descriptor table - Initialze the
3039 * physical memory before programming the hardware - Program the SCU hardware
3040 * with the physical memory addresses passed in the memory descriptor table. -
3041 * Initialzie the TCi pool - Initialize the RNi pool - Initialize the
3042 * completion queue - Initialize the unsolicited frame data - Take the SCU port
3043 * task scheduler out of reset - Start the first phy object. - Transition to
3044 * SCI_BASE_CONTROLLER_STATE_STARTING. enum sci_status SCI_SUCCESS if all of the
3045 * controller start operations complete
3046 * SCI_FAILURE_UNSUPPORTED_INFORMATION_FIELD if one or more of the memory
3047 * descriptor fields is invalid.
3049 static enum sci_status
scic_sds_controller_initialized_state_start_handler(
3050 struct sci_base_controller
*base_scic
,
3054 enum sci_status result
;
3055 struct scic_sds_controller
*scic
;
3057 scic
= container_of(base_scic
, typeof(*scic
), parent
);
3060 * Make sure that the SCI User filled in the memory descriptor
3063 result
= scic_sds_controller_validate_memory_descriptor_table(scic
);
3065 if (result
== SCI_SUCCESS
) {
3067 * The memory descriptor list looks good so program the
3070 scic_sds_controller_ram_initialization(scic
);
3073 if (result
== SCI_SUCCESS
) {
3074 /* Build the TCi free pool */
3075 sci_pool_initialize(scic
->tci_pool
);
3076 for (index
= 0; index
< scic
->task_context_entries
; index
++)
3077 sci_pool_put(scic
->tci_pool
, index
);
3079 /* Build the RNi free pool */
3080 scic_sds_remote_node_table_initialize(
3081 &scic
->available_remote_nodes
,
3082 scic
->remote_node_entries
);
3085 if (result
== SCI_SUCCESS
) {
3087 * Before anything else lets make sure we will not be
3088 * interrupted by the hardware.
3090 scic_controller_disable_interrupts(scic
);
3092 /* Enable the port task scheduler */
3093 scic_sds_controller_enable_port_task_scheduler(scic
);
3095 /* Assign all the task entries to scic physical function */
3096 scic_sds_controller_assign_task_entries(scic
);
3098 /* Now initialze the completion queue */
3099 scic_sds_controller_initialize_completion_queue(scic
);
3101 /* Initialize the unsolicited frame queue for use */
3102 scic_sds_controller_initialize_unsolicited_frame_queue(scic
);
3105 /* Start all of the ports on this controller */
3107 (index
< scic
->logical_port_entries
) && (result
== SCI_SUCCESS
);
3109 struct scic_sds_port
*sci_port
= &scic
->port_table
[index
];
3111 result
= sci_port
->state_handlers
->parent
.start_handler(
3115 if (result
== SCI_SUCCESS
) {
3116 scic_sds_controller_start_next_phy(scic
);
3118 isci_timer_start(scic
->timeout_timer
, timeout
);
3120 sci_base_state_machine_change_state(&base_scic
->state_machine
,
3121 SCI_BASE_CONTROLLER_STATE_STARTING
);
3128 * *****************************************************************************
3129 * * INITIALIZED STATE HANDLERS
3130 * ***************************************************************************** */
3134 * @controller: This is struct scic_sds_controller which receives the link up
3136 * @port: This is struct scic_sds_port with which the phy is associated.
3137 * @phy: This is the struct scic_sds_phy which has gone link up.
3139 * This method is called when the struct scic_sds_controller is in the starting state
3140 * link up handler is called. This method will perform the following: - Stop
3141 * the phy timer - Start the next phy - Report the link up condition to the
3144 static void scic_sds_controller_starting_state_link_up_handler(
3145 struct scic_sds_controller
*this_controller
,
3146 struct scic_sds_port
*port
,
3147 struct scic_sds_phy
*phy
)
3149 scic_sds_controller_phy_timer_stop(this_controller
);
3151 this_controller
->port_agent
.link_up_handler(
3152 this_controller
, &this_controller
->port_agent
, port
, phy
3154 /* scic_sds_port_link_up(port, phy); */
3156 scic_sds_controller_start_next_phy(this_controller
);
3161 * @controller: This is struct scic_sds_controller which receives the link down
3163 * @port: This is struct scic_sds_port with which the phy is associated.
3164 * @phy: This is the struct scic_sds_phy which has gone link down.
3166 * This method is called when the struct scic_sds_controller is in the starting state
3167 * link down handler is called. - Report the link down condition to the port
3170 static void scic_sds_controller_starting_state_link_down_handler(
3171 struct scic_sds_controller
*this_controller
,
3172 struct scic_sds_port
*port
,
3173 struct scic_sds_phy
*phy
)
3175 this_controller
->port_agent
.link_down_handler(
3176 this_controller
, &this_controller
->port_agent
, port
, phy
3178 /* scic_sds_port_link_down(port, phy); */
3181 static enum sci_status
scic_sds_controller_ready_state_stop_handler(struct sci_base_controller
*base_scic
,
3184 struct scic_sds_controller
*scic
;
3186 scic
= container_of(base_scic
, typeof(*scic
), parent
);
3187 isci_timer_start(scic
->timeout_timer
, timeout
);
3188 sci_base_state_machine_change_state(&base_scic
->state_machine
,
3189 SCI_BASE_CONTROLLER_STATE_STOPPING
);
3196 * @controller: This is struct sci_base_controller object which is cast into a
3197 * struct scic_sds_controller object.
3198 * @remote_device: This is struct sci_base_remote_device which is cast to a
3199 * struct scic_sds_remote_device object.
3200 * @io_request: This is the struct sci_base_request which is cast to a
3201 * SCIC_SDS_IO_REQUEST object.
3202 * @io_tag: This is the IO tag to be assigned to the IO request or
3203 * SCI_CONTROLLER_INVALID_IO_TAG.
3205 * This method is called when the struct scic_sds_controller is in the ready state and
3206 * the start io handler is called. - Start the io request on the remote device
3207 * - if successful - assign the io_request to the io_request_table - post the
3208 * request to the hardware enum sci_status SCI_SUCCESS if the start io operation
3209 * succeeds SCI_FAILURE_INSUFFICIENT_RESOURCES if the IO tag could not be
3210 * allocated for the io request. SCI_FAILURE_INVALID_STATE if one or more
3211 * objects are not in a valid state to accept io requests. How does the io_tag
3212 * parameter get assigned to the io request?
3214 static enum sci_status
scic_sds_controller_ready_state_start_io_handler(
3215 struct sci_base_controller
*controller
,
3216 struct sci_base_remote_device
*remote_device
,
3217 struct sci_base_request
*io_request
,
3220 enum sci_status status
;
3222 struct scic_sds_controller
*this_controller
;
3223 struct scic_sds_request
*the_request
;
3224 struct scic_sds_remote_device
*the_device
;
3226 this_controller
= (struct scic_sds_controller
*)controller
;
3227 the_request
= (struct scic_sds_request
*)io_request
;
3228 the_device
= (struct scic_sds_remote_device
*)remote_device
;
3230 status
= scic_sds_remote_device_start_io(this_controller
, the_device
, the_request
);
3232 if (status
== SCI_SUCCESS
) {
3233 this_controller
->io_request_table
[
3234 scic_sds_io_tag_get_index(the_request
->io_tag
)] = the_request
;
3236 scic_sds_controller_post_request(
3238 scic_sds_request_get_post_context(the_request
)
3247 * @controller: This is struct sci_base_controller object which is cast into a
3248 * struct scic_sds_controller object.
3249 * @remote_device: This is struct sci_base_remote_device which is cast to a
3250 * struct scic_sds_remote_device object.
3251 * @io_request: This is the struct sci_base_request which is cast to a
3252 * SCIC_SDS_IO_REQUEST object.
3254 * This method is called when the struct scic_sds_controller is in the ready state and
3255 * the complete io handler is called. - Complete the io request on the remote
3256 * device - if successful - remove the io_request to the io_request_table
3257 * enum sci_status SCI_SUCCESS if the start io operation succeeds
3258 * SCI_FAILURE_INVALID_STATE if one or more objects are not in a valid state to
3259 * accept io requests.
3261 static enum sci_status
scic_sds_controller_ready_state_complete_io_handler(
3262 struct sci_base_controller
*controller
,
3263 struct sci_base_remote_device
*remote_device
,
3264 struct sci_base_request
*io_request
)
3267 enum sci_status status
;
3268 struct scic_sds_controller
*this_controller
;
3269 struct scic_sds_request
*the_request
;
3270 struct scic_sds_remote_device
*the_device
;
3272 this_controller
= (struct scic_sds_controller
*)controller
;
3273 the_request
= (struct scic_sds_request
*)io_request
;
3274 the_device
= (struct scic_sds_remote_device
*)remote_device
;
3276 status
= scic_sds_remote_device_complete_io(
3277 this_controller
, the_device
, the_request
);
3279 if (status
== SCI_SUCCESS
) {
3280 index
= scic_sds_io_tag_get_index(the_request
->io_tag
);
3281 this_controller
->io_request_table
[index
] = NULL
;
3289 * @controller: This is struct sci_base_controller object which is cast into a
3290 * struct scic_sds_controller object.
3291 * @remote_device: This is struct sci_base_remote_device which is cast to a
3292 * struct scic_sds_remote_device object.
3293 * @io_request: This is the struct sci_base_request which is cast to a
3294 * SCIC_SDS_IO_REQUEST object.
3296 * This method is called when the struct scic_sds_controller is in the ready state and
3297 * the continue io handler is called. enum sci_status
3299 static enum sci_status
scic_sds_controller_ready_state_continue_io_handler(
3300 struct sci_base_controller
*controller
,
3301 struct sci_base_remote_device
*remote_device
,
3302 struct sci_base_request
*io_request
)
3304 struct scic_sds_controller
*this_controller
;
3305 struct scic_sds_request
*the_request
;
3307 the_request
= (struct scic_sds_request
*)io_request
;
3308 this_controller
= (struct scic_sds_controller
*)controller
;
3310 this_controller
->io_request_table
[
3311 scic_sds_io_tag_get_index(the_request
->io_tag
)] = the_request
;
3313 scic_sds_controller_post_request(
3315 scic_sds_request_get_post_context(the_request
)
3323 * @controller: This is struct sci_base_controller object which is cast into a
3324 * struct scic_sds_controller object.
3325 * @remote_device: This is struct sci_base_remote_device which is cast to a
3326 * struct scic_sds_remote_device object.
3327 * @io_request: This is the struct sci_base_request which is cast to a
3328 * SCIC_SDS_IO_REQUEST object.
3329 * @task_tag: This is the task tag to be assigned to the task request or
3330 * SCI_CONTROLLER_INVALID_IO_TAG.
3332 * This method is called when the struct scic_sds_controller is in the ready state and
3333 * the start task handler is called. - The remote device is requested to start
3334 * the task request - if successful - assign the task to the io_request_table -
3335 * post the request to the SCU hardware enum sci_status SCI_SUCCESS if the start io
3336 * operation succeeds SCI_FAILURE_INSUFFICIENT_RESOURCES if the IO tag could
3337 * not be allocated for the io request. SCI_FAILURE_INVALID_STATE if one or
3338 * more objects are not in a valid state to accept io requests. How does the io
3339 * tag get assigned in this code path?
3341 static enum sci_status
scic_sds_controller_ready_state_start_task_handler(
3342 struct sci_base_controller
*controller
,
3343 struct sci_base_remote_device
*remote_device
,
3344 struct sci_base_request
*io_request
,
3347 struct scic_sds_controller
*this_controller
= (struct scic_sds_controller
*)
3349 struct scic_sds_request
*the_request
= (struct scic_sds_request
*)
3351 struct scic_sds_remote_device
*the_device
= (struct scic_sds_remote_device
*)
3353 enum sci_status status
;
3355 status
= scic_sds_remote_device_start_task(
3356 this_controller
, the_device
, the_request
3359 if (status
== SCI_SUCCESS
) {
3360 this_controller
->io_request_table
[
3361 scic_sds_io_tag_get_index(the_request
->io_tag
)] = the_request
;
3363 scic_sds_controller_post_request(
3365 scic_sds_request_get_post_context(the_request
)
3367 } else if (status
== SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS
) {
3368 this_controller
->io_request_table
[
3369 scic_sds_io_tag_get_index(the_request
->io_tag
)] = the_request
;
3372 * We will let framework know this task request started successfully,
3373 * although core is still woring on starting the request (to post tc when
3374 * RNC is resumed.) */
3375 status
= SCI_SUCCESS
;
3382 * @controller: This is struct sci_base_controller object which is cast into a
3383 * struct scic_sds_controller object.
3384 * @remote_device: This is struct sci_base_remote_device which is cast to a
3385 * struct scic_sds_remote_device object.
3386 * @io_request: This is the struct sci_base_request which is cast to a
3387 * SCIC_SDS_IO_REQUEST object.
3389 * This method is called when the struct scic_sds_controller is in the ready state and
3390 * the terminate request handler is called. - call the io request terminate
3391 * function - if successful - post the terminate request to the SCU hardware
3392 * enum sci_status SCI_SUCCESS if the start io operation succeeds
3393 * SCI_FAILURE_INVALID_STATE if one or more objects are not in a valid state to
3394 * accept io requests.
3396 static enum sci_status
scic_sds_controller_ready_state_terminate_request_handler(
3397 struct sci_base_controller
*controller
,
3398 struct sci_base_remote_device
*remote_device
,
3399 struct sci_base_request
*io_request
)
3401 struct scic_sds_controller
*this_controller
= (struct scic_sds_controller
*)
3403 struct scic_sds_request
*the_request
= (struct scic_sds_request
*)
3405 enum sci_status status
;
3407 status
= scic_sds_io_request_terminate(the_request
);
3408 if (status
== SCI_SUCCESS
) {
3410 * Utilize the original post context command and or in the POST_TC_ABORT
3411 * request sub-type. */
3412 scic_sds_controller_post_request(
3414 scic_sds_request_get_post_context(the_request
)
3415 | SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT
3424 * @controller: This is struct scic_sds_controller which receives the link up
3426 * @port: This is struct scic_sds_port with which the phy is associated.
3427 * @phy: This is the struct scic_sds_phy which has gone link up.
3429 * This method is called when the struct scic_sds_controller is in the starting state
3430 * link up handler is called. This method will perform the following: - Stop
3431 * the phy timer - Start the next phy - Report the link up condition to the
3434 static void scic_sds_controller_ready_state_link_up_handler(
3435 struct scic_sds_controller
*this_controller
,
3436 struct scic_sds_port
*port
,
3437 struct scic_sds_phy
*phy
)
3439 this_controller
->port_agent
.link_up_handler(
3440 this_controller
, &this_controller
->port_agent
, port
, phy
3446 * @controller: This is struct scic_sds_controller which receives the link down
3448 * @port: This is struct scic_sds_port with which the phy is associated.
3449 * @phy: This is the struct scic_sds_phy which has gone link down.
3451 * This method is called when the struct scic_sds_controller is in the starting state
3452 * link down handler is called. - Report the link down condition to the port
3455 static void scic_sds_controller_ready_state_link_down_handler(
3456 struct scic_sds_controller
*this_controller
,
3457 struct scic_sds_port
*port
,
3458 struct scic_sds_phy
*phy
)
3460 this_controller
->port_agent
.link_down_handler(
3461 this_controller
, &this_controller
->port_agent
, port
, phy
3466 * *****************************************************************************
3467 * * STOPPING STATE HANDLERS
3468 * ***************************************************************************** */
3472 * @controller: This is struct sci_base_controller object which is cast into a
3473 * struct scic_sds_controller object.
3474 * @remote_device: This is struct sci_base_remote_device which is cast to a
3475 * struct scic_sds_remote_device object.
3476 * @io_request: This is the struct sci_base_request which is cast to a
3477 * SCIC_SDS_IO_REQUEST object.
3479 * This method is called when the struct scic_sds_controller is in a stopping state
3480 * and the complete io handler is called. - This function is not yet
3481 * implemented enum sci_status SCI_FAILURE
3483 static enum sci_status
scic_sds_controller_stopping_state_complete_io_handler(
3484 struct sci_base_controller
*controller
,
3485 struct sci_base_remote_device
*remote_device
,
3486 struct sci_base_request
*io_request
)
3488 struct scic_sds_controller
*this_controller
;
3490 this_controller
= (struct scic_sds_controller
*)controller
;
3492 /* / @todo Implement this function */
3498 * @controller: This is struct sci_base_controller object which is cast into a
3499 * struct scic_sds_controller object.
3500 * @remote_device: This is struct sci_base_remote_device which is cast to a
3501 * struct scic_sds_remote_device object.
3503 * This method is called when the struct scic_sds_controller is in a stopping state
3504 * and the remote device has stopped.
3506 static void scic_sds_controller_stopping_state_device_stopped_handler(
3507 struct scic_sds_controller
*controller
,
3508 struct scic_sds_remote_device
*remote_device
3511 if (!scic_sds_controller_has_remote_devices_stopping(controller
)) {
3512 sci_base_state_machine_change_state(
3513 &controller
->parent
.state_machine
,
3514 SCI_BASE_CONTROLLER_STATE_STOPPED
3519 const struct scic_sds_controller_state_handler scic_sds_controller_state_handler_table
[] = {
3520 [SCI_BASE_CONTROLLER_STATE_INITIAL
] = {
3521 .base
.start_io
= scic_sds_controller_default_start_operation_handler
,
3522 .base
.complete_io
= scic_sds_controller_default_request_handler
,
3523 .base
.continue_io
= scic_sds_controller_default_request_handler
,
3524 .terminate_request
= scic_sds_controller_default_request_handler
,
3526 [SCI_BASE_CONTROLLER_STATE_RESET
] = {
3527 .base
.reset
= scic_sds_controller_general_reset_handler
,
3528 .base
.initialize
= scic_sds_controller_reset_state_initialize_handler
,
3529 .base
.start_io
= scic_sds_controller_default_start_operation_handler
,
3530 .base
.complete_io
= scic_sds_controller_default_request_handler
,
3531 .base
.continue_io
= scic_sds_controller_default_request_handler
,
3532 .terminate_request
= scic_sds_controller_default_request_handler
,
3534 [SCI_BASE_CONTROLLER_STATE_INITIALIZING
] = {
3535 .base
.start_io
= scic_sds_controller_default_start_operation_handler
,
3536 .base
.complete_io
= scic_sds_controller_default_request_handler
,
3537 .base
.continue_io
= scic_sds_controller_default_request_handler
,
3538 .terminate_request
= scic_sds_controller_default_request_handler
,
3540 [SCI_BASE_CONTROLLER_STATE_INITIALIZED
] = {
3541 .base
.start
= scic_sds_controller_initialized_state_start_handler
,
3542 .base
.start_io
= scic_sds_controller_default_start_operation_handler
,
3543 .base
.complete_io
= scic_sds_controller_default_request_handler
,
3544 .base
.continue_io
= scic_sds_controller_default_request_handler
,
3545 .terminate_request
= scic_sds_controller_default_request_handler
,
3547 [SCI_BASE_CONTROLLER_STATE_STARTING
] = {
3548 .base
.start_io
= scic_sds_controller_default_start_operation_handler
,
3549 .base
.complete_io
= scic_sds_controller_default_request_handler
,
3550 .base
.continue_io
= scic_sds_controller_default_request_handler
,
3551 .terminate_request
= scic_sds_controller_default_request_handler
,
3552 .link_up
= scic_sds_controller_starting_state_link_up_handler
,
3553 .link_down
= scic_sds_controller_starting_state_link_down_handler
3555 [SCI_BASE_CONTROLLER_STATE_READY
] = {
3556 .base
.stop
= scic_sds_controller_ready_state_stop_handler
,
3557 .base
.reset
= scic_sds_controller_general_reset_handler
,
3558 .base
.start_io
= scic_sds_controller_ready_state_start_io_handler
,
3559 .base
.complete_io
= scic_sds_controller_ready_state_complete_io_handler
,
3560 .base
.continue_io
= scic_sds_controller_ready_state_continue_io_handler
,
3561 .base
.start_task
= scic_sds_controller_ready_state_start_task_handler
,
3562 .base
.complete_task
= scic_sds_controller_ready_state_complete_io_handler
,
3563 .terminate_request
= scic_sds_controller_ready_state_terminate_request_handler
,
3564 .link_up
= scic_sds_controller_ready_state_link_up_handler
,
3565 .link_down
= scic_sds_controller_ready_state_link_down_handler
3567 [SCI_BASE_CONTROLLER_STATE_RESETTING
] = {
3568 .base
.start_io
= scic_sds_controller_default_start_operation_handler
,
3569 .base
.complete_io
= scic_sds_controller_default_request_handler
,
3570 .base
.continue_io
= scic_sds_controller_default_request_handler
,
3571 .terminate_request
= scic_sds_controller_default_request_handler
,
3573 [SCI_BASE_CONTROLLER_STATE_STOPPING
] = {
3574 .base
.start_io
= scic_sds_controller_default_start_operation_handler
,
3575 .base
.complete_io
= scic_sds_controller_stopping_state_complete_io_handler
,
3576 .base
.continue_io
= scic_sds_controller_default_request_handler
,
3577 .terminate_request
= scic_sds_controller_default_request_handler
,
3578 .remote_device_stopped_handler
= scic_sds_controller_stopping_state_device_stopped_handler
,
3580 [SCI_BASE_CONTROLLER_STATE_STOPPED
] = {
3581 .base
.reset
= scic_sds_controller_general_reset_handler
,
3582 .base
.start_io
= scic_sds_controller_default_start_operation_handler
,
3583 .base
.complete_io
= scic_sds_controller_default_request_handler
,
3584 .base
.continue_io
= scic_sds_controller_default_request_handler
,
3585 .terminate_request
= scic_sds_controller_default_request_handler
,
3587 [SCI_BASE_CONTROLLER_STATE_FAILED
] = {
3588 .base
.reset
= scic_sds_controller_general_reset_handler
,
3589 .base
.start_io
= scic_sds_controller_default_start_operation_handler
,
3590 .base
.complete_io
= scic_sds_controller_default_request_handler
,
3591 .base
.continue_io
= scic_sds_controller_default_request_handler
,
3592 .terminate_request
= scic_sds_controller_default_request_handler
,
3598 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3601 * This method implements the actions taken by the struct scic_sds_controller on entry
3602 * to the SCI_BASE_CONTROLLER_STATE_INITIAL. - Set the state handlers to the
3603 * controllers initial state. none This function should initialze the
3604 * controller object.
3606 static void scic_sds_controller_initial_state_enter(
3607 struct sci_base_object
*object
)
3609 struct scic_sds_controller
*this_controller
;
3611 this_controller
= (struct scic_sds_controller
*)object
;
3613 sci_base_state_machine_change_state(
3614 &this_controller
->parent
.state_machine
, SCI_BASE_CONTROLLER_STATE_RESET
);
3619 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3622 * This method implements the actions taken by the struct scic_sds_controller on exit
3623 * from the SCI_BASE_CONTROLLER_STATE_STARTING. - This function stops the
3624 * controller starting timeout timer. none
3626 static inline void scic_sds_controller_starting_state_exit(
3627 struct sci_base_object
*object
)
3629 struct scic_sds_controller
*scic
= (struct scic_sds_controller
*)object
;
3631 isci_timer_stop(scic
->timeout_timer
);
3636 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3639 * This method implements the actions taken by the struct scic_sds_controller on entry
3640 * to the SCI_BASE_CONTROLLER_STATE_READY. - Set the state handlers to the
3641 * controllers ready state. none
3643 static void scic_sds_controller_ready_state_enter(
3644 struct sci_base_object
*object
)
3646 struct scic_sds_controller
*this_controller
;
3648 this_controller
= (struct scic_sds_controller
*)object
;
3650 /* set the default interrupt coalescence number and timeout value. */
3651 scic_controller_set_interrupt_coalescence(
3652 this_controller
, 0x10, 250);
3657 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3660 * This method implements the actions taken by the struct scic_sds_controller on exit
3661 * from the SCI_BASE_CONTROLLER_STATE_READY. - This function does nothing. none
3663 static void scic_sds_controller_ready_state_exit(
3664 struct sci_base_object
*object
)
3666 struct scic_sds_controller
*this_controller
;
3668 this_controller
= (struct scic_sds_controller
*)object
;
3670 /* disable interrupt coalescence. */
3671 scic_controller_set_interrupt_coalescence(this_controller
, 0, 0);
3676 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3679 * This method implements the actions taken by the struct scic_sds_controller on entry
3680 * to the SCI_BASE_CONTROLLER_STATE_READY. - Set the state handlers to the
3681 * controllers ready state. - Stop the phys on this controller - Stop the ports
3682 * on this controller - Stop all of the remote devices on this controller none
3684 static void scic_sds_controller_stopping_state_enter(
3685 struct sci_base_object
*object
)
3687 struct scic_sds_controller
*this_controller
;
3689 this_controller
= (struct scic_sds_controller
*)object
;
3691 /* Stop all of the components for this controller */
3692 scic_sds_controller_stop_phys(this_controller
);
3693 scic_sds_controller_stop_ports(this_controller
);
3694 scic_sds_controller_stop_devices(this_controller
);
3699 * @object: This is the struct sci_base_object which is cast to a struct
3700 * scic_sds_controller object.
3702 * This funciton implements the actions taken by the struct scic_sds_controller
3703 * on exit from the SCI_BASE_CONTROLLER_STATE_STOPPING. -
3704 * This function stops the controller stopping timeout timer.
3706 static inline void scic_sds_controller_stopping_state_exit(
3707 struct sci_base_object
*object
)
3709 struct scic_sds_controller
*scic
=
3710 (struct scic_sds_controller
*)object
;
3712 isci_timer_stop(scic
->timeout_timer
);
3715 static void scic_sds_controller_resetting_state_enter(struct sci_base_object
*object
)
3717 struct scic_sds_controller
*scic
;
3719 scic
= container_of(object
, typeof(*scic
), parent
.parent
);
3720 scic_sds_controller_reset_hardware(scic
);
3721 sci_base_state_machine_change_state(&scic
->parent
.state_machine
,
3722 SCI_BASE_CONTROLLER_STATE_RESET
);
3725 static const struct sci_base_state scic_sds_controller_state_table
[] = {
3726 [SCI_BASE_CONTROLLER_STATE_INITIAL
] = {
3727 .enter_state
= scic_sds_controller_initial_state_enter
,
3729 [SCI_BASE_CONTROLLER_STATE_RESET
] = {},
3730 [SCI_BASE_CONTROLLER_STATE_INITIALIZING
] = {},
3731 [SCI_BASE_CONTROLLER_STATE_INITIALIZED
] = {},
3732 [SCI_BASE_CONTROLLER_STATE_STARTING
] = {
3733 .exit_state
= scic_sds_controller_starting_state_exit
,
3735 [SCI_BASE_CONTROLLER_STATE_READY
] = {
3736 .enter_state
= scic_sds_controller_ready_state_enter
,
3737 .exit_state
= scic_sds_controller_ready_state_exit
,
3739 [SCI_BASE_CONTROLLER_STATE_RESETTING
] = {
3740 .enter_state
= scic_sds_controller_resetting_state_enter
,
3742 [SCI_BASE_CONTROLLER_STATE_STOPPING
] = {
3743 .enter_state
= scic_sds_controller_stopping_state_enter
,
3744 .exit_state
= scic_sds_controller_stopping_state_exit
,
3746 [SCI_BASE_CONTROLLER_STATE_STOPPED
] = {},
3747 [SCI_BASE_CONTROLLER_STATE_FAILED
] = {}
3751 * scic_controller_construct() - This method will attempt to construct a
3752 * controller object utilizing the supplied parameter information.
3753 * @c: This parameter specifies the controller to be constructed.
3754 * @scu_base: mapped base address of the scu registers
3755 * @smu_base: mapped base address of the smu registers
3757 * Indicate if the controller was successfully constructed or if it failed in
3758 * some way. SCI_SUCCESS This value is returned if the controller was
3759 * successfully constructed. SCI_WARNING_TIMER_CONFLICT This value is returned
3760 * if the interrupt coalescence timer may cause SAS compliance issues for SMP
3761 * Target mode response processing. SCI_FAILURE_UNSUPPORTED_CONTROLLER_TYPE
3762 * This value is returned if the controller does not support the supplied type.
3763 * SCI_FAILURE_UNSUPPORTED_INIT_DATA_VERSION This value is returned if the
3764 * controller does not support the supplied initialization data version.
3766 enum sci_status
scic_controller_construct(struct scic_sds_controller
*scic
,
3767 void __iomem
*scu_base
,
3768 void __iomem
*smu_base
)
3772 sci_base_controller_construct(&scic
->parent
,
3773 scic_sds_controller_state_table
,
3774 scic
->memory_descriptors
,
3775 ARRAY_SIZE(scic
->memory_descriptors
), NULL
);
3777 scic
->scu_registers
= scu_base
;
3778 scic
->smu_registers
= smu_base
;
3780 scic_sds_port_configuration_agent_construct(&scic
->port_agent
);
3782 /* Construct the ports for this controller */
3783 for (i
= 0; i
< SCI_MAX_PORTS
; i
++)
3784 scic_sds_port_construct(&scic
->port_table
[i
], i
, scic
);
3785 scic_sds_port_construct(&scic
->port_table
[i
], SCIC_SDS_DUMMY_PORT
, scic
);
3787 /* Construct the phys for this controller */
3788 for (i
= 0; i
< SCI_MAX_PHYS
; i
++) {
3789 /* Add all the PHYs to the dummy port */
3790 scic_sds_phy_construct(&scic
->phy_table
[i
],
3791 &scic
->port_table
[SCI_MAX_PORTS
], i
);
3794 scic
->invalid_phy_mask
= 0;
3796 /* Set the default maximum values */
3797 scic
->completion_event_entries
= SCU_EVENT_COUNT
;
3798 scic
->completion_queue_entries
= SCU_COMPLETION_QUEUE_COUNT
;
3799 scic
->remote_node_entries
= SCI_MAX_REMOTE_DEVICES
;
3800 scic
->logical_port_entries
= SCI_MAX_PORTS
;
3801 scic
->task_context_entries
= SCU_IO_REQUEST_COUNT
;
3802 scic
->uf_control
.buffers
.count
= SCU_UNSOLICITED_FRAME_COUNT
;
3803 scic
->uf_control
.address_table
.count
= SCU_UNSOLICITED_FRAME_COUNT
;
3805 /* Initialize the User and OEM parameters to default values. */
3806 scic_sds_controller_set_default_config_parameters(scic
);
3808 return scic_controller_reset(scic
);