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;
223 * ****************************************************************************-
224 * * SCIC SDS Controller Initialization Methods
225 * ****************************************************************************- */
228 * This timer is used to start another phy after we have given up on the
229 * previous phy to transition to the ready state.
233 static void scic_sds_controller_phy_startup_timeout_handler(
236 enum sci_status status;
237 struct scic_sds_controller *this_controller;
239 this_controller = (struct scic_sds_controller *)controller;
241 this_controller->phy_startup_timer_pending = false;
243 status = SCI_FAILURE;
245 while (status != SCI_SUCCESS) {
246 status = scic_sds_controller_start_next_phy(this_controller);
253 * This method initializes the phy startup operations for controller start.
255 void scic_sds_controller_initialize_phy_startup(
256 struct scic_sds_controller *this_controller)
258 this_controller->phy_startup_timer = isci_event_timer_create(
260 scic_sds_controller_phy_startup_timeout_handler,
264 this_controller->next_phy_to_start = 0;
265 this_controller->phy_startup_timer_pending = false;
271 * This method initializes the power control operations for the controller
274 void scic_sds_controller_initialize_power_control(
275 struct scic_sds_controller *this_controller)
277 this_controller->power_control.timer = isci_event_timer_create(
279 scic_sds_controller_power_control_timer_handler,
284 this_controller->power_control.requesters,
286 sizeof(this_controller->power_control.requesters)
289 this_controller->power_control.phys_waiting = 0;
292 /* --------------------------------------------------------------------------- */
294 #define SCU_REMOTE_NODE_CONTEXT_ALIGNMENT (32)
295 #define SCU_TASK_CONTEXT_ALIGNMENT (256)
296 #define SCU_UNSOLICITED_FRAME_ADDRESS_ALIGNMENT (64)
297 #define SCU_UNSOLICITED_FRAME_BUFFER_ALIGNMENT (1024)
298 #define SCU_UNSOLICITED_FRAME_HEADER_ALIGNMENT (64)
300 /* --------------------------------------------------------------------------- */
303 * This method builds the memory descriptor table for this controller.
304 * @this_controller: This parameter specifies the controller object for which
305 * to build the memory table.
308 static void scic_sds_controller_build_memory_descriptor_table(
309 struct scic_sds_controller *this_controller)
311 sci_base_mde_construct(
312 &this_controller->memory_descriptors[SCU_MDE_COMPLETION_QUEUE],
313 SCU_COMPLETION_RAM_ALIGNMENT,
314 (sizeof(u32) * this_controller->completion_queue_entries),
315 (SCI_MDE_ATTRIBUTE_CACHEABLE | SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS)
318 sci_base_mde_construct(
319 &this_controller->memory_descriptors[SCU_MDE_REMOTE_NODE_CONTEXT],
320 SCU_REMOTE_NODE_CONTEXT_ALIGNMENT,
321 this_controller->remote_node_entries * sizeof(union scu_remote_node_context),
322 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
325 sci_base_mde_construct(
326 &this_controller->memory_descriptors[SCU_MDE_TASK_CONTEXT],
327 SCU_TASK_CONTEXT_ALIGNMENT,
328 this_controller->task_context_entries * sizeof(struct scu_task_context),
329 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
333 * The UF buffer address table size must be programmed to a power
334 * of 2. Find the first power of 2 that is equal to or greater then
335 * the number of unsolicited frame buffers to be utilized. */
336 scic_sds_unsolicited_frame_control_set_address_table_count(
337 &this_controller->uf_control
340 sci_base_mde_construct(
341 &this_controller->memory_descriptors[SCU_MDE_UF_BUFFER],
342 SCU_UNSOLICITED_FRAME_BUFFER_ALIGNMENT,
343 scic_sds_unsolicited_frame_control_get_mde_size(this_controller->uf_control),
344 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
349 * This method validates the driver supplied memory descriptor table.
354 enum sci_status scic_sds_controller_validate_memory_descriptor_table(
355 struct scic_sds_controller *this_controller)
359 mde_list_valid = sci_base_mde_is_valid(
360 &this_controller->memory_descriptors[SCU_MDE_COMPLETION_QUEUE],
361 SCU_COMPLETION_RAM_ALIGNMENT,
362 (sizeof(u32) * this_controller->completion_queue_entries),
363 (SCI_MDE_ATTRIBUTE_CACHEABLE | SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS)
366 if (mde_list_valid == false)
367 return SCI_FAILURE_UNSUPPORTED_INFORMATION_FIELD;
369 mde_list_valid = sci_base_mde_is_valid(
370 &this_controller->memory_descriptors[SCU_MDE_REMOTE_NODE_CONTEXT],
371 SCU_REMOTE_NODE_CONTEXT_ALIGNMENT,
372 this_controller->remote_node_entries * sizeof(union scu_remote_node_context),
373 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
376 if (mde_list_valid == false)
377 return SCI_FAILURE_UNSUPPORTED_INFORMATION_FIELD;
379 mde_list_valid = sci_base_mde_is_valid(
380 &this_controller->memory_descriptors[SCU_MDE_TASK_CONTEXT],
381 SCU_TASK_CONTEXT_ALIGNMENT,
382 this_controller->task_context_entries * sizeof(struct scu_task_context),
383 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
386 if (mde_list_valid == false)
387 return SCI_FAILURE_UNSUPPORTED_INFORMATION_FIELD;
389 mde_list_valid = sci_base_mde_is_valid(
390 &this_controller->memory_descriptors[SCU_MDE_UF_BUFFER],
391 SCU_UNSOLICITED_FRAME_BUFFER_ALIGNMENT,
392 scic_sds_unsolicited_frame_control_get_mde_size(this_controller->uf_control),
393 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
396 if (mde_list_valid == false)
397 return SCI_FAILURE_UNSUPPORTED_INFORMATION_FIELD;
403 * This method initializes the controller with the physical memory addresses
404 * that are used to communicate with the driver.
408 void scic_sds_controller_ram_initialization(
409 struct scic_sds_controller *this_controller)
411 struct sci_physical_memory_descriptor *mde;
414 * The completion queue is actually placed in cacheable memory
415 * Therefore it no longer comes out of memory in the MDL. */
416 mde = &this_controller->memory_descriptors[SCU_MDE_COMPLETION_QUEUE];
417 this_controller->completion_queue = (u32 *)mde->virtual_address;
418 SMU_CQBAR_WRITE(this_controller, mde->physical_address);
421 * Program the location of the Remote Node Context table
423 mde = &this_controller->memory_descriptors[SCU_MDE_REMOTE_NODE_CONTEXT];
424 this_controller->remote_node_context_table = (union scu_remote_node_context *)
425 mde->virtual_address;
426 SMU_RNCBAR_WRITE(this_controller, mde->physical_address);
428 /* Program the location of the Task Context table into the SCU. */
429 mde = &this_controller->memory_descriptors[SCU_MDE_TASK_CONTEXT];
430 this_controller->task_context_table = (struct scu_task_context *)
431 mde->virtual_address;
432 SMU_HTTBAR_WRITE(this_controller, mde->physical_address);
434 mde = &this_controller->memory_descriptors[SCU_MDE_UF_BUFFER];
435 scic_sds_unsolicited_frame_control_construct(
436 &this_controller->uf_control, mde, this_controller
440 * Inform the silicon as to the location of the UF headers and
444 this_controller->uf_control.headers.physical_address);
447 this_controller->uf_control.address_table.physical_address);
451 * This method initializes the task context data for the controller.
455 void scic_sds_controller_assign_task_entries(
456 struct scic_sds_controller *this_controller)
461 * Assign all the TCs to function 0
462 * TODO: Do we actually need to read this register to write it back? */
463 task_assignment = SMU_TCA_READ(this_controller, 0);
468 | (SMU_TCA_GEN_VAL(STARTING, 0))
469 | (SMU_TCA_GEN_VAL(ENDING, this_controller->task_context_entries - 1))
470 | (SMU_TCA_GEN_BIT(RANGE_CHECK_ENABLE))
473 SMU_TCA_WRITE(this_controller, 0, task_assignment);
477 * This method initializes the hardware completion queue.
481 void scic_sds_controller_initialize_completion_queue(
482 struct scic_sds_controller *this_controller)
485 u32 completion_queue_control_value;
486 u32 completion_queue_get_value;
487 u32 completion_queue_put_value;
489 this_controller->completion_queue_get = 0;
491 completion_queue_control_value = (
492 SMU_CQC_QUEUE_LIMIT_SET(this_controller->completion_queue_entries - 1)
493 | SMU_CQC_EVENT_LIMIT_SET(this_controller->completion_event_entries - 1)
496 SMU_CQC_WRITE(this_controller, completion_queue_control_value);
498 /* Set the completion queue get pointer and enable the queue */
499 completion_queue_get_value = (
500 (SMU_CQGR_GEN_VAL(POINTER, 0))
501 | (SMU_CQGR_GEN_VAL(EVENT_POINTER, 0))
502 | (SMU_CQGR_GEN_BIT(ENABLE))
503 | (SMU_CQGR_GEN_BIT(EVENT_ENABLE))
506 SMU_CQGR_WRITE(this_controller, completion_queue_get_value);
508 /* Set the completion queue put pointer */
509 completion_queue_put_value = (
510 (SMU_CQPR_GEN_VAL(POINTER, 0))
511 | (SMU_CQPR_GEN_VAL(EVENT_POINTER, 0))
514 SMU_CQPR_WRITE(this_controller, completion_queue_put_value);
516 /* Initialize the cycle bit of the completion queue entries */
517 for (index = 0; index < this_controller->completion_queue_entries; index++) {
519 * If get.cycle_bit != completion_queue.cycle_bit
520 * its not a valid completion queue entry
521 * so at system start all entries are invalid */
522 this_controller->completion_queue[index] = 0x80000000;
527 * This method initializes the hardware unsolicited frame queue.
531 void scic_sds_controller_initialize_unsolicited_frame_queue(
532 struct scic_sds_controller *this_controller)
534 u32 frame_queue_control_value;
535 u32 frame_queue_get_value;
536 u32 frame_queue_put_value;
538 /* Write the queue size */
539 frame_queue_control_value =
540 SCU_UFQC_GEN_VAL(QUEUE_SIZE, this_controller->uf_control.address_table.count);
542 SCU_UFQC_WRITE(this_controller, frame_queue_control_value);
544 /* Setup the get pointer for the unsolicited frame queue */
545 frame_queue_get_value = (
546 SCU_UFQGP_GEN_VAL(POINTER, 0)
547 | SCU_UFQGP_GEN_BIT(ENABLE_BIT)
550 SCU_UFQGP_WRITE(this_controller, frame_queue_get_value);
552 /* Setup the put pointer for the unsolicited frame queue */
553 frame_queue_put_value = SCU_UFQPP_GEN_VAL(POINTER, 0);
555 SCU_UFQPP_WRITE(this_controller, frame_queue_put_value);
559 * This method enables the hardware port task scheduler.
563 void scic_sds_controller_enable_port_task_scheduler(
564 struct scic_sds_controller *this_controller)
566 u32 port_task_scheduler_value;
568 port_task_scheduler_value = SCU_PTSGCR_READ(this_controller);
570 port_task_scheduler_value |=
571 (SCU_PTSGCR_GEN_BIT(ETM_ENABLE) | SCU_PTSGCR_GEN_BIT(PTSG_ENABLE));
573 SCU_PTSGCR_WRITE(this_controller, port_task_scheduler_value);
576 /* --------------------------------------------------------------------------- */
581 * This macro is used to delay between writes to the AFE registers during AFE
584 #define AFE_REGISTER_WRITE_DELAY 10
586 /* Initialize the AFE for this phy index. We need to read the AFE setup from
587 * the OEM parameters none
589 void scic_sds_controller_afe_initialization(struct scic_sds_controller *scic)
594 /* Clear DFX Status registers */
595 scu_afe_register_write(scic, afe_dfx_master_control0, 0x0081000f);
596 udelay(AFE_REGISTER_WRITE_DELAY);
598 /* Configure bias currents to normal */
600 scu_afe_register_write(scic, afe_bias_control, 0x00005500);
602 scu_afe_register_write(scic, afe_bias_control, 0x00005A00);
604 udelay(AFE_REGISTER_WRITE_DELAY);
608 scu_afe_register_write(scic, afe_pll_control0, 0x80040A08);
610 scu_afe_register_write(scic, afe_pll_control0, 0x80040908);
612 udelay(AFE_REGISTER_WRITE_DELAY);
614 /* Wait for the PLL to lock */
616 afe_status = scu_afe_register_read(
617 scic, afe_common_block_status);
618 udelay(AFE_REGISTER_WRITE_DELAY);
619 } while ((afe_status & 0x00001000) == 0);
622 /* Shorten SAS SNW lock time (RxLock timer value from 76 us to 50 us) */
623 scu_afe_register_write(scic, afe_pmsn_master_control0, 0x7bcc96ad);
624 udelay(AFE_REGISTER_WRITE_DELAY);
627 for (phy_id = 0; phy_id < SCI_MAX_PHYS; phy_id++) {
629 /* Configure transmitter SSC parameters */
630 scu_afe_txreg_write(scic, phy_id, afe_tx_ssc_control, 0x00030000);
631 udelay(AFE_REGISTER_WRITE_DELAY);
634 * All defaults, except the Receive Word Alignament/Comma Detect
635 * Enable....(0xe800) */
636 scu_afe_txreg_write(scic, phy_id, afe_xcvr_control0, 0x00004512);
637 udelay(AFE_REGISTER_WRITE_DELAY);
639 scu_afe_txreg_write(scic, phy_id, afe_xcvr_control1, 0x0050100F);
640 udelay(AFE_REGISTER_WRITE_DELAY);
644 * Power up TX and RX out from power down (PWRDNTX and PWRDNRX)
645 * & increase TX int & ext bias 20%....(0xe85c) */
647 scu_afe_txreg_write(scic, phy_id, afe_channel_control, 0x000003D4);
649 scu_afe_txreg_write(scic, phy_id, afe_channel_control, 0x000003F0);
651 /* Power down TX and RX (PWRDNTX and PWRDNRX) */
652 scu_afe_txreg_write(scic, phy_id, afe_channel_control, 0x000003d7);
653 udelay(AFE_REGISTER_WRITE_DELAY);
656 * Power up TX and RX out from power down (PWRDNTX and PWRDNRX)
657 * & increase TX int & ext bias 20%....(0xe85c) */
658 scu_afe_txreg_write(scic, phy_id, afe_channel_control, 0x000003d4);
660 udelay(AFE_REGISTER_WRITE_DELAY);
662 if (is_a0() || is_a2()) {
663 /* Enable TX equalization (0xe824) */
664 scu_afe_txreg_write(scic, phy_id, afe_tx_control, 0x00040000);
665 udelay(AFE_REGISTER_WRITE_DELAY);
669 * RDPI=0x0(RX Power On), RXOOBDETPDNC=0x0, TPD=0x0(TX Power On),
670 * RDD=0x0(RX Detect Enabled) ....(0xe800) */
671 scu_afe_txreg_write(scic, phy_id, afe_xcvr_control0, 0x00004100);
672 udelay(AFE_REGISTER_WRITE_DELAY);
674 /* Leave DFE/FFE on */
676 scu_afe_txreg_write(scic, phy_id, afe_rx_ssc_control0, 0x3F09983F);
678 scu_afe_txreg_write(scic, phy_id, afe_rx_ssc_control0, 0x3F11103F);
680 scu_afe_txreg_write(scic, phy_id, afe_rx_ssc_control0, 0x3F11103F);
681 udelay(AFE_REGISTER_WRITE_DELAY);
682 /* Enable TX equalization (0xe824) */
683 scu_afe_txreg_write(scic, phy_id, afe_tx_control, 0x00040000);
685 udelay(AFE_REGISTER_WRITE_DELAY);
687 scu_afe_txreg_write(scic, phy_id, afe_tx_amp_control0, 0x000E7C03);
688 udelay(AFE_REGISTER_WRITE_DELAY);
690 scu_afe_txreg_write(scic, phy_id, afe_tx_amp_control1, 0x000E7C03);
691 udelay(AFE_REGISTER_WRITE_DELAY);
693 scu_afe_txreg_write(scic, phy_id, afe_tx_amp_control2, 0x000E7C03);
694 udelay(AFE_REGISTER_WRITE_DELAY);
696 scu_afe_txreg_write(scic, phy_id, afe_tx_amp_control3, 0x000E7C03);
697 udelay(AFE_REGISTER_WRITE_DELAY);
700 /* Transfer control to the PEs */
701 scu_afe_register_write(scic, afe_dfx_master_control0, 0x00010f00);
702 udelay(AFE_REGISTER_WRITE_DELAY);
706 * ****************************************************************************-
707 * * SCIC SDS Controller Internal Start/Stop Routines
708 * ****************************************************************************- */
712 * This method will attempt to transition into the ready state for the
713 * controller and indicate that the controller start operation has completed
714 * if all criteria are met.
715 * @this_controller: This parameter indicates the controller object for which
716 * to transition to ready.
717 * @status: This parameter indicates the status value to be pass into the call
718 * to scic_cb_controller_start_complete().
722 static void scic_sds_controller_transition_to_ready(
723 struct scic_sds_controller *this_controller,
724 enum sci_status status)
726 if (this_controller->parent.state_machine.current_state_id
727 == SCI_BASE_CONTROLLER_STATE_STARTING) {
729 * We move into the ready state, because some of the phys/ports
730 * may be up and operational. */
731 sci_base_state_machine_change_state(
732 scic_sds_controller_get_base_state_machine(this_controller),
733 SCI_BASE_CONTROLLER_STATE_READY
736 isci_event_controller_start_complete(this_controller, status);
741 * This method is the general timeout handler for the controller. It will take
742 * the correct timetout action based on the current controller state
744 void scic_sds_controller_timeout_handler(
745 struct scic_sds_controller *scic)
747 enum sci_base_controller_states current_state;
749 current_state = sci_base_state_machine_get_state(
750 scic_sds_controller_get_base_state_machine(scic));
752 if (current_state == SCI_BASE_CONTROLLER_STATE_STARTING) {
753 scic_sds_controller_transition_to_ready(
754 scic, SCI_FAILURE_TIMEOUT);
755 } else if (current_state == SCI_BASE_CONTROLLER_STATE_STOPPING) {
756 sci_base_state_machine_change_state(
757 scic_sds_controller_get_base_state_machine(scic),
758 SCI_BASE_CONTROLLER_STATE_FAILED);
759 isci_event_controller_stop_complete(scic, SCI_FAILURE_TIMEOUT);
760 } else /* / @todo Now what do we want to do in this case? */
761 dev_err(scic_to_dev(scic),
762 "%s: Controller timer fired when controller was not "
763 "in a state being timed.\n",
768 * scic_sds_controller_get_port_configuration_mode
769 * @this_controller: This is the controller to use to determine if we are using
770 * manual or automatic port configuration.
772 * SCIC_PORT_CONFIGURATION_MODE
774 enum SCIC_PORT_CONFIGURATION_MODE scic_sds_controller_get_port_configuration_mode(
775 struct scic_sds_controller *this_controller)
778 enum SCIC_PORT_CONFIGURATION_MODE mode;
780 mode = SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE;
782 for (index = 0; index < SCI_MAX_PORTS; index++) {
783 if (this_controller->oem_parameters.sds1.ports[index].phy_mask != 0) {
784 mode = SCIC_PORT_MANUAL_CONFIGURATION_MODE;
792 enum sci_status scic_sds_controller_stop_ports(struct scic_sds_controller *scic)
795 enum sci_status port_status;
796 enum sci_status status = SCI_SUCCESS;
798 for (index = 0; index < scic->logical_port_entries; index++) {
799 struct scic_sds_port *sci_port = &scic->port_table[index];
800 SCI_BASE_PORT_HANDLER_T stop;
802 stop = sci_port->state_handlers->parent.stop_handler;
803 port_status = stop(&sci_port->parent);
805 if ((port_status != SCI_SUCCESS) &&
806 (port_status != SCI_FAILURE_INVALID_STATE)) {
807 status = SCI_FAILURE;
809 dev_warn(scic_to_dev(scic),
810 "%s: Controller stop operation failed to "
811 "stop port %d because of status %d.\n",
813 sci_port->logical_port_index,
826 static void scic_sds_controller_phy_timer_start(
827 struct scic_sds_controller *this_controller)
829 isci_event_timer_start(
831 this_controller->phy_startup_timer,
832 SCIC_SDS_CONTROLLER_PHY_START_TIMEOUT
835 this_controller->phy_startup_timer_pending = true;
843 void scic_sds_controller_phy_timer_stop(
844 struct scic_sds_controller *this_controller)
846 isci_event_timer_stop(
848 this_controller->phy_startup_timer
851 this_controller->phy_startup_timer_pending = false;
855 * This method is called internally by the controller object to start the next
856 * phy on the controller. If all the phys have been starte, then this
857 * method will attempt to transition the controller to the READY state and
858 * inform the user (scic_cb_controller_start_complete()).
859 * @this_controller: This parameter specifies the controller object for which
860 * to start the next phy.
864 enum sci_status scic_sds_controller_start_next_phy(
865 struct scic_sds_controller *this_controller)
867 enum sci_status status;
869 status = SCI_SUCCESS;
871 if (this_controller->phy_startup_timer_pending == false) {
872 if (this_controller->next_phy_to_start == SCI_MAX_PHYS) {
873 bool is_controller_start_complete = true;
874 struct scic_sds_phy *the_phy;
877 for (index = 0; index < SCI_MAX_PHYS; index++) {
878 the_phy = &this_controller->phy_table[index];
880 if (scic_sds_phy_get_port(the_phy) != NULL) {
882 * The controller start operation is complete if and only
884 * - all links have been given an opportunity to start
885 * - have no indication of a connected device
886 * - have an indication of a connected device and it has
887 * finished the link training process.
891 (the_phy->is_in_link_training == false)
892 && (the_phy->parent.state_machine.current_state_id
893 == SCI_BASE_PHY_STATE_INITIAL)
896 (the_phy->is_in_link_training == false)
897 && (the_phy->parent.state_machine.current_state_id
898 == SCI_BASE_PHY_STATE_STOPPED)
901 (the_phy->is_in_link_training == true)
902 && (the_phy->parent.state_machine.current_state_id
903 == SCI_BASE_PHY_STATE_STARTING)
906 is_controller_start_complete = false;
913 * The controller has successfully finished the start process.
914 * Inform the SCI Core user and transition to the READY state. */
915 if (is_controller_start_complete == true) {
916 scic_sds_controller_transition_to_ready(
917 this_controller, SCI_SUCCESS
919 scic_sds_controller_phy_timer_stop(this_controller);
922 struct scic_sds_phy *the_phy;
924 the_phy = &this_controller->phy_table[this_controller->next_phy_to_start];
927 scic_sds_controller_get_port_configuration_mode(this_controller)
928 == SCIC_PORT_MANUAL_CONFIGURATION_MODE
930 if (scic_sds_phy_get_port(the_phy) == NULL) {
931 this_controller->next_phy_to_start++;
934 * Caution recursion ahead be forwarned
936 * The PHY was never added to a PORT in MPC mode so start the next phy in sequence
937 * This phy will never go link up and will not draw power the OEM parameters either
938 * configured the phy incorrectly for the PORT or it was never assigned to a PORT */
939 return scic_sds_controller_start_next_phy(this_controller);
943 status = scic_sds_phy_start(the_phy);
945 if (status == SCI_SUCCESS) {
946 scic_sds_controller_phy_timer_start(this_controller);
948 dev_warn(scic_to_dev(this_controller),
949 "%s: Controller stop operation failed "
950 "to stop phy %d because of status "
953 this_controller->phy_table[this_controller->next_phy_to_start].phy_index,
957 this_controller->next_phy_to_start++;
970 enum sci_status scic_sds_controller_stop_phys(
971 struct scic_sds_controller *this_controller)
974 enum sci_status status;
975 enum sci_status phy_status;
977 status = SCI_SUCCESS;
979 for (index = 0; index < SCI_MAX_PHYS; index++) {
980 phy_status = scic_sds_phy_stop(&this_controller->phy_table[index]);
983 (phy_status != SCI_SUCCESS)
984 && (phy_status != SCI_FAILURE_INVALID_STATE)
986 status = SCI_FAILURE;
988 dev_warn(scic_to_dev(this_controller),
989 "%s: Controller stop operation failed to stop "
990 "phy %d because of status %d.\n",
992 this_controller->phy_table[index].phy_index, phy_status);
1005 enum sci_status scic_sds_controller_stop_devices(
1006 struct scic_sds_controller *this_controller)
1009 enum sci_status status;
1010 enum sci_status device_status;
1012 status = SCI_SUCCESS;
1014 for (index = 0; index < this_controller->remote_node_entries; index++) {
1015 if (this_controller->device_table[index] != NULL) {
1016 /* / @todo What timeout value do we want to provide to this request? */
1017 device_status = scic_remote_device_stop(this_controller->device_table[index], 0);
1019 if ((device_status != SCI_SUCCESS) &&
1020 (device_status != SCI_FAILURE_INVALID_STATE)) {
1021 dev_warn(scic_to_dev(this_controller),
1022 "%s: Controller stop operation failed "
1023 "to stop device 0x%p because of "
1026 this_controller->device_table[index], device_status);
1035 * ****************************************************************************-
1036 * * SCIC SDS Controller Power Control (Staggered Spinup)
1037 * ****************************************************************************- */
1042 * This method starts the power control timer for this controller object.
1044 static void scic_sds_controller_power_control_timer_start(
1045 struct scic_sds_controller *this_controller)
1047 isci_event_timer_start(
1048 this_controller, this_controller->power_control.timer,
1049 SCIC_SDS_CONTROLLER_POWER_CONTROL_INTERVAL
1052 this_controller->power_control.timer_started = true;
1060 static void scic_sds_controller_power_control_timer_handler(
1063 struct scic_sds_controller *this_controller;
1065 this_controller = (struct scic_sds_controller *)controller;
1067 if (this_controller->power_control.phys_waiting == 0) {
1068 this_controller->power_control.timer_started = false;
1070 struct scic_sds_phy *the_phy = NULL;
1075 && (this_controller->power_control.phys_waiting != 0);
1077 if (this_controller->power_control.requesters[i] != NULL) {
1078 the_phy = this_controller->power_control.requesters[i];
1079 this_controller->power_control.requesters[i] = NULL;
1080 this_controller->power_control.phys_waiting--;
1086 * It doesn't matter if the power list is empty, we need to start the
1087 * timer in case another phy becomes ready. */
1088 scic_sds_controller_power_control_timer_start(this_controller);
1090 scic_sds_phy_consume_power_handler(the_phy);
1095 * This method inserts the phy in the stagger spinup control queue.
1100 void scic_sds_controller_power_control_queue_insert(
1101 struct scic_sds_controller *this_controller,
1102 struct scic_sds_phy *the_phy)
1104 BUG_ON(the_phy == NULL);
1107 (this_controller->power_control.timer_started)
1108 && (this_controller->power_control.requesters[the_phy->phy_index] == NULL)
1110 this_controller->power_control.requesters[the_phy->phy_index] = the_phy;
1111 this_controller->power_control.phys_waiting++;
1113 scic_sds_controller_power_control_timer_start(this_controller);
1114 scic_sds_phy_consume_power_handler(the_phy);
1119 * This method removes the phy from the stagger spinup control queue.
1124 void scic_sds_controller_power_control_queue_remove(
1125 struct scic_sds_controller *this_controller,
1126 struct scic_sds_phy *the_phy)
1128 BUG_ON(the_phy == NULL);
1130 if (this_controller->power_control.requesters[the_phy->phy_index] != NULL) {
1131 this_controller->power_control.phys_waiting--;
1134 this_controller->power_control.requesters[the_phy->phy_index] = NULL;
1138 * ****************************************************************************-
1139 * * SCIC SDS Controller Completion Routines
1140 * ****************************************************************************- */
1143 * This method returns a true value if the completion queue has entries that
1147 * bool true if the completion queue has entries to process false if the
1148 * completion queue has no entries to process
1150 static bool scic_sds_controller_completion_queue_has_entries(
1151 struct scic_sds_controller *this_controller)
1153 u32 get_value = this_controller->completion_queue_get;
1154 u32 get_index = get_value & SMU_COMPLETION_QUEUE_GET_POINTER_MASK;
1157 NORMALIZE_GET_POINTER_CYCLE_BIT(get_value)
1158 == COMPLETION_QUEUE_CYCLE_BIT(this_controller->completion_queue[get_index])
1166 /* --------------------------------------------------------------------------- */
1169 * This method processes a task completion notification. This is called from
1170 * within the controller completion handler.
1172 * @completion_entry:
1175 static void scic_sds_controller_task_completion(
1176 struct scic_sds_controller *this_controller,
1177 u32 completion_entry)
1180 struct scic_sds_request *io_request;
1182 index = SCU_GET_COMPLETION_INDEX(completion_entry);
1183 io_request = this_controller->io_request_table[index];
1185 /* Make sure that we really want to process this IO request */
1187 (io_request != NULL)
1188 && (io_request->io_tag != SCI_CONTROLLER_INVALID_IO_TAG)
1190 scic_sds_io_tag_get_sequence(io_request->io_tag)
1191 == this_controller->io_request_sequence[index]
1194 /* Yep this is a valid io request pass it along to the io request handler */
1195 scic_sds_io_request_tc_completion(io_request, completion_entry);
1200 * This method processes an SDMA completion event. This is called from within
1201 * the controller completion handler.
1203 * @completion_entry:
1206 static void scic_sds_controller_sdma_completion(
1207 struct scic_sds_controller *this_controller,
1208 u32 completion_entry)
1211 struct scic_sds_request *io_request;
1212 struct scic_sds_remote_device *device;
1214 index = SCU_GET_COMPLETION_INDEX(completion_entry);
1216 switch (scu_get_command_request_type(completion_entry)) {
1217 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC:
1218 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_DUMP_TC:
1219 io_request = this_controller->io_request_table[index];
1220 dev_warn(scic_to_dev(this_controller),
1221 "%s: SCIC SDS Completion type SDMA %x for io request "
1226 /* @todo For a post TC operation we need to fail the IO
1231 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_DUMP_RNC:
1232 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_OTHER_RNC:
1233 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_RNC:
1234 device = this_controller->device_table[index];
1235 dev_warn(scic_to_dev(this_controller),
1236 "%s: SCIC SDS Completion type SDMA %x for remote "
1241 /* @todo For a port RNC operation we need to fail the
1247 dev_warn(scic_to_dev(this_controller),
1248 "%s: SCIC SDS Completion unknown SDMA completion "
1260 * @completion_entry:
1262 * This method processes an unsolicited frame message. This is called from
1263 * within the controller completion handler. none
1265 static void scic_sds_controller_unsolicited_frame(
1266 struct scic_sds_controller *this_controller,
1267 u32 completion_entry)
1272 struct scu_unsolicited_frame_header *frame_header;
1273 struct scic_sds_phy *phy;
1274 struct scic_sds_remote_device *device;
1276 enum sci_status result = SCI_FAILURE;
1278 frame_index = SCU_GET_FRAME_INDEX(completion_entry);
1281 = this_controller->uf_control.buffers.array[frame_index].header;
1282 this_controller->uf_control.buffers.array[frame_index].state
1283 = UNSOLICITED_FRAME_IN_USE;
1285 if (SCU_GET_FRAME_ERROR(completion_entry)) {
1287 * / @todo If the IAF frame or SIGNATURE FIS frame has an error will
1288 * / this cause a problem? We expect the phy initialization will
1289 * / fail if there is an error in the frame. */
1290 scic_sds_controller_release_frame(this_controller, frame_index);
1294 if (frame_header->is_address_frame) {
1295 index = SCU_GET_PROTOCOL_ENGINE_INDEX(completion_entry);
1296 phy = &this_controller->phy_table[index];
1298 result = scic_sds_phy_frame_handler(phy, frame_index);
1302 index = SCU_GET_COMPLETION_INDEX(completion_entry);
1304 if (index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX) {
1306 * This is a signature fis or a frame from a direct attached SATA
1307 * device that has not yet been created. In either case forwared
1308 * the frame to the PE and let it take care of the frame data. */
1309 index = SCU_GET_PROTOCOL_ENGINE_INDEX(completion_entry);
1310 phy = &this_controller->phy_table[index];
1311 result = scic_sds_phy_frame_handler(phy, frame_index);
1313 if (index < this_controller->remote_node_entries)
1314 device = this_controller->device_table[index];
1319 result = scic_sds_remote_device_frame_handler(device, frame_index);
1321 scic_sds_controller_release_frame(this_controller, frame_index);
1325 if (result != SCI_SUCCESS) {
1327 * / @todo Is there any reason to report some additional error message
1328 * / when we get this failure notifiction? */
1333 * This method processes an event completion entry. This is called from within
1334 * the controller completion handler.
1336 * @completion_entry:
1339 static void scic_sds_controller_event_completion(
1340 struct scic_sds_controller *this_controller,
1341 u32 completion_entry)
1344 struct scic_sds_request *io_request;
1345 struct scic_sds_remote_device *device;
1346 struct scic_sds_phy *phy;
1348 index = SCU_GET_COMPLETION_INDEX(completion_entry);
1350 switch (scu_get_event_type(completion_entry)) {
1351 case SCU_EVENT_TYPE_SMU_COMMAND_ERROR:
1352 /* / @todo The driver did something wrong and we need to fix the condtion. */
1353 dev_err(scic_to_dev(this_controller),
1354 "%s: SCIC Controller 0x%p received SMU command error "
1361 case SCU_EVENT_TYPE_SMU_PCQ_ERROR:
1362 case SCU_EVENT_TYPE_SMU_ERROR:
1363 case SCU_EVENT_TYPE_FATAL_MEMORY_ERROR:
1365 * / @todo This is a hardware failure and its likely that we want to
1366 * / reset the controller. */
1367 dev_err(scic_to_dev(this_controller),
1368 "%s: SCIC Controller 0x%p received fatal controller "
1375 case SCU_EVENT_TYPE_TRANSPORT_ERROR:
1376 io_request = this_controller->io_request_table[index];
1377 scic_sds_io_request_event_handler(io_request, completion_entry);
1380 case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT:
1381 switch (scu_get_event_specifier(completion_entry)) {
1382 case SCU_EVENT_SPECIFIC_SMP_RESPONSE_NO_PE:
1383 case SCU_EVENT_SPECIFIC_TASK_TIMEOUT:
1384 io_request = this_controller->io_request_table[index];
1385 if (io_request != NULL)
1386 scic_sds_io_request_event_handler(io_request, completion_entry);
1388 dev_warn(scic_to_dev(this_controller),
1389 "%s: SCIC Controller 0x%p received "
1390 "event 0x%x for io request object "
1391 "that doesnt exist.\n",
1398 case SCU_EVENT_SPECIFIC_IT_NEXUS_TIMEOUT:
1399 device = this_controller->device_table[index];
1401 scic_sds_remote_device_event_handler(device, completion_entry);
1403 dev_warn(scic_to_dev(this_controller),
1404 "%s: SCIC Controller 0x%p received "
1405 "event 0x%x for remote device object "
1406 "that doesnt exist.\n",
1415 case SCU_EVENT_TYPE_BROADCAST_CHANGE:
1417 * direct the broadcast change event to the phy first and then let
1418 * the phy redirect the broadcast change to the port object */
1419 case SCU_EVENT_TYPE_ERR_CNT_EVENT:
1421 * direct error counter event to the phy object since that is where
1422 * we get the event notification. This is a type 4 event. */
1423 case SCU_EVENT_TYPE_OSSP_EVENT:
1424 index = SCU_GET_PROTOCOL_ENGINE_INDEX(completion_entry);
1425 phy = &this_controller->phy_table[index];
1426 scic_sds_phy_event_handler(phy, completion_entry);
1429 case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
1430 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
1431 case SCU_EVENT_TYPE_RNC_OPS_MISC:
1432 if (index < this_controller->remote_node_entries) {
1433 device = this_controller->device_table[index];
1436 scic_sds_remote_device_event_handler(device, completion_entry);
1438 dev_err(scic_to_dev(this_controller),
1439 "%s: SCIC Controller 0x%p received event 0x%x "
1440 "for remote device object 0x%0x that doesnt "
1450 dev_warn(scic_to_dev(this_controller),
1451 "%s: SCIC Controller received unknown event code %x\n",
1459 * This method is a private routine for processing the completion queue entries.
1463 static void scic_sds_controller_process_completions(
1464 struct scic_sds_controller *this_controller)
1466 u32 completion_count = 0;
1467 u32 completion_entry;
1473 dev_dbg(scic_to_dev(this_controller),
1474 "%s: completion queue begining get:0x%08x\n",
1476 this_controller->completion_queue_get);
1478 /* Get the component parts of the completion queue */
1479 get_index = NORMALIZE_GET_POINTER(this_controller->completion_queue_get);
1480 get_cycle = SMU_CQGR_CYCLE_BIT & this_controller->completion_queue_get;
1482 event_index = NORMALIZE_EVENT_POINTER(this_controller->completion_queue_get);
1483 event_cycle = SMU_CQGR_EVENT_CYCLE_BIT & this_controller->completion_queue_get;
1486 NORMALIZE_GET_POINTER_CYCLE_BIT(get_cycle)
1487 == COMPLETION_QUEUE_CYCLE_BIT(this_controller->completion_queue[get_index])
1491 completion_entry = this_controller->completion_queue[get_index];
1492 INCREMENT_COMPLETION_QUEUE_GET(this_controller, get_index, get_cycle);
1494 dev_dbg(scic_to_dev(this_controller),
1495 "%s: completion queue entry:0x%08x\n",
1499 switch (SCU_GET_COMPLETION_TYPE(completion_entry)) {
1500 case SCU_COMPLETION_TYPE_TASK:
1501 scic_sds_controller_task_completion(this_controller, completion_entry);
1504 case SCU_COMPLETION_TYPE_SDMA:
1505 scic_sds_controller_sdma_completion(this_controller, completion_entry);
1508 case SCU_COMPLETION_TYPE_UFI:
1509 scic_sds_controller_unsolicited_frame(this_controller, completion_entry);
1512 case SCU_COMPLETION_TYPE_EVENT:
1513 INCREMENT_EVENT_QUEUE_GET(this_controller, event_index, event_cycle);
1514 scic_sds_controller_event_completion(this_controller, completion_entry);
1517 case SCU_COMPLETION_TYPE_NOTIFY:
1519 * Presently we do the same thing with a notify event that we do with the
1520 * other event codes. */
1521 INCREMENT_EVENT_QUEUE_GET(this_controller, event_index, event_cycle);
1522 scic_sds_controller_event_completion(this_controller, completion_entry);
1526 dev_warn(scic_to_dev(this_controller),
1527 "%s: SCIC Controller received unknown "
1528 "completion type %x\n",
1535 /* Update the get register if we completed one or more entries */
1536 if (completion_count > 0) {
1537 this_controller->completion_queue_get =
1538 SMU_CQGR_GEN_BIT(ENABLE)
1539 | SMU_CQGR_GEN_BIT(EVENT_ENABLE)
1540 | event_cycle | SMU_CQGR_GEN_VAL(EVENT_POINTER, event_index)
1541 | get_cycle | SMU_CQGR_GEN_VAL(POINTER, get_index);
1543 SMU_CQGR_WRITE(this_controller,
1544 this_controller->completion_queue_get);
1547 dev_dbg(scic_to_dev(this_controller),
1548 "%s: completion queue ending get:0x%08x\n",
1550 this_controller->completion_queue_get);
1554 bool scic_sds_controller_isr(struct scic_sds_controller *scic)
1556 if (scic_sds_controller_completion_queue_has_entries(scic)) {
1560 * we have a spurious interrupt it could be that we have already
1561 * emptied the completion queue from a previous interrupt */
1562 SMU_ISR_WRITE(scic, SMU_ISR_COMPLETION);
1565 * There is a race in the hardware that could cause us not to be notified
1566 * of an interrupt completion if we do not take this step. We will mask
1567 * then unmask the interrupts so if there is another interrupt pending
1568 * the clearing of the interrupt source we get the next interrupt message. */
1569 SMU_IMR_WRITE(scic, 0xFF000000);
1570 SMU_IMR_WRITE(scic, 0x00000000);
1576 void scic_sds_controller_completion_handler(struct scic_sds_controller *scic)
1578 /* Empty out the completion queue */
1579 if (scic_sds_controller_completion_queue_has_entries(scic))
1580 scic_sds_controller_process_completions(scic);
1582 /* Clear the interrupt and enable all interrupts again */
1583 SMU_ISR_WRITE(scic, SMU_ISR_COMPLETION);
1584 /* Could we write the value of SMU_ISR_COMPLETION? */
1585 SMU_IMR_WRITE(scic, 0xFF000000);
1586 SMU_IMR_WRITE(scic, 0x00000000);
1589 bool scic_sds_controller_error_isr(struct scic_sds_controller *scic)
1591 u32 interrupt_status;
1593 interrupt_status = SMU_ISR_READ(scic);
1595 interrupt_status &= (SMU_ISR_QUEUE_ERROR | SMU_ISR_QUEUE_SUSPEND);
1597 if (interrupt_status != 0) {
1599 * There is an error interrupt pending so let it through and handle
1600 * in the callback */
1605 * There is a race in the hardware that could cause us not to be notified
1606 * of an interrupt completion if we do not take this step. We will mask
1607 * then unmask the error interrupts so if there was another interrupt
1608 * pending we will be notified.
1609 * Could we write the value of (SMU_ISR_QUEUE_ERROR | SMU_ISR_QUEUE_SUSPEND)? */
1610 SMU_IMR_WRITE(scic, 0x000000FF);
1611 SMU_IMR_WRITE(scic, 0x00000000);
1616 void scic_sds_controller_error_handler(struct scic_sds_controller *scic)
1618 u32 interrupt_status;
1620 interrupt_status = SMU_ISR_READ(scic);
1622 if ((interrupt_status & SMU_ISR_QUEUE_SUSPEND) &&
1623 scic_sds_controller_completion_queue_has_entries(scic)) {
1625 scic_sds_controller_process_completions(scic);
1626 SMU_ISR_WRITE(scic, SMU_ISR_QUEUE_SUSPEND);
1629 dev_err(scic_to_dev(scic), "%s: status: %#x\n", __func__,
1632 sci_base_state_machine_change_state(
1633 scic_sds_controller_get_base_state_machine(scic),
1634 SCI_BASE_CONTROLLER_STATE_FAILED);
1640 * If we dont process any completions I am not sure that we want to do this.
1641 * We are in the middle of a hardware fault and should probably be reset. */
1642 SMU_IMR_WRITE(scic, 0x00000000);
1646 u32 scic_sds_controller_get_object_size(void)
1648 return sizeof(struct scic_sds_controller);
1652 void scic_sds_controller_link_up(
1653 struct scic_sds_controller *scic,
1654 struct scic_sds_port *sci_port,
1655 struct scic_sds_phy *sci_phy)
1657 scic_sds_controller_phy_handler_t link_up;
1660 state = scic->parent.state_machine.current_state_id;
1661 link_up = scic_sds_controller_state_handler_table[state].link_up;
1664 link_up(scic, sci_port, sci_phy);
1666 dev_warn(scic_to_dev(scic),
1667 "%s: SCIC Controller linkup event from phy %d in "
1668 "unexpected state %d\n",
1671 sci_base_state_machine_get_state(
1672 scic_sds_controller_get_base_state_machine(
1677 void scic_sds_controller_link_down(
1678 struct scic_sds_controller *scic,
1679 struct scic_sds_port *sci_port,
1680 struct scic_sds_phy *sci_phy)
1683 scic_sds_controller_phy_handler_t link_down;
1685 state = scic->parent.state_machine.current_state_id;
1686 link_down = scic_sds_controller_state_handler_table[state].link_down;
1689 link_down(scic, sci_port, sci_phy);
1691 dev_warn(scic_to_dev(scic),
1692 "%s: SCIC Controller linkdown event from phy %d in "
1693 "unexpected state %d\n",
1696 sci_base_state_machine_get_state(
1697 scic_sds_controller_get_base_state_machine(
1702 * This method will write to the SCU PCP register the request value. The method
1703 * is used to suspend/resume ports, devices, and phys.
1708 void scic_sds_controller_post_request(
1709 struct scic_sds_controller *this_controller,
1712 dev_dbg(scic_to_dev(this_controller),
1713 "%s: SCIC Controller 0x%p post request 0x%08x\n",
1718 SMU_PCP_WRITE(this_controller, request);
1722 * This method will copy the soft copy of the task context into the physical
1723 * memory accessible by the controller.
1724 * @this_controller: This parameter specifies the controller for which to copy
1726 * @this_request: This parameter specifies the request for which the task
1727 * context is being copied.
1729 * After this call is made the SCIC_SDS_IO_REQUEST object will always point to
1730 * the physical memory version of the task context. Thus, all subsequent
1731 * updates to the task context are performed in the TC table (i.e. DMAable
1734 void scic_sds_controller_copy_task_context(
1735 struct scic_sds_controller *this_controller,
1736 struct scic_sds_request *this_request)
1738 struct scu_task_context *task_context_buffer;
1740 task_context_buffer = scic_sds_controller_get_task_context_buffer(
1741 this_controller, this_request->io_tag
1745 task_context_buffer,
1746 this_request->task_context_buffer,
1747 SCI_FIELD_OFFSET(struct scu_task_context, sgl_snapshot_ac)
1751 * Now that the soft copy of the TC has been copied into the TC
1752 * table accessible by the silicon. Thus, any further changes to
1753 * the TC (e.g. TC termination) occur in the appropriate location. */
1754 this_request->task_context_buffer = task_context_buffer;
1758 * This method returns the task context buffer for the given io tag.
1762 * struct scu_task_context*
1764 struct scu_task_context *scic_sds_controller_get_task_context_buffer(
1765 struct scic_sds_controller *this_controller,
1768 u16 task_index = scic_sds_io_tag_get_index(io_tag);
1770 if (task_index < this_controller->task_context_entries) {
1771 return &this_controller->task_context_table[task_index];
1778 * This method returnst the sequence value from the io tag value
1786 * This method returns the IO request associated with the tag value
1790 * SCIC_SDS_IO_REQUEST_T* NULL if there is no valid IO request at the tag value
1792 struct scic_sds_request *scic_sds_controller_get_io_request_from_tag(
1793 struct scic_sds_controller *this_controller,
1799 task_index = scic_sds_io_tag_get_index(io_tag);
1801 if (task_index < this_controller->task_context_entries) {
1802 if (this_controller->io_request_table[task_index] != NULL) {
1803 task_sequence = scic_sds_io_tag_get_sequence(io_tag);
1805 if (task_sequence == this_controller->io_request_sequence[task_index]) {
1806 return this_controller->io_request_table[task_index];
1815 * This method allocates remote node index and the reserves the remote node
1816 * context space for use. This method can fail if there are no more remote
1817 * node index available.
1818 * @this_controller: This is the controller object which contains the set of
1819 * free remote node ids
1820 * @the_devce: This is the device object which is requesting the a remote node
1822 * @node_id: This is the remote node id that is assinged to the device if one
1825 * enum sci_status SCI_FAILURE_OUT_OF_RESOURCES if there are no available remote
1826 * node index available.
1828 enum sci_status scic_sds_controller_allocate_remote_node_context(
1829 struct scic_sds_controller *this_controller,
1830 struct scic_sds_remote_device *the_device,
1834 u32 remote_node_count = scic_sds_remote_device_node_count(the_device);
1836 node_index = scic_sds_remote_node_table_allocate_remote_node(
1837 &this_controller->available_remote_nodes, remote_node_count
1840 if (node_index != SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX) {
1841 this_controller->device_table[node_index] = the_device;
1843 *node_id = node_index;
1848 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
1852 * This method frees the remote node index back to the available pool. Once
1853 * this is done the remote node context buffer is no longer valid and can
1860 void scic_sds_controller_free_remote_node_context(
1861 struct scic_sds_controller *this_controller,
1862 struct scic_sds_remote_device *the_device,
1865 u32 remote_node_count = scic_sds_remote_device_node_count(the_device);
1867 if (this_controller->device_table[node_id] == the_device) {
1868 this_controller->device_table[node_id] = NULL;
1870 scic_sds_remote_node_table_release_remote_node_index(
1871 &this_controller->available_remote_nodes, remote_node_count, node_id
1877 * This method returns the union scu_remote_node_context for the specified remote
1882 * union scu_remote_node_context*
1884 union scu_remote_node_context *scic_sds_controller_get_remote_node_context_buffer(
1885 struct scic_sds_controller *this_controller,
1889 (node_id < this_controller->remote_node_entries)
1890 && (this_controller->device_table[node_id] != NULL)
1892 return &this_controller->remote_node_context_table[node_id];
1900 * @resposne_buffer: This is the buffer into which the D2H register FIS will be
1902 * @frame_header: This is the frame header returned by the hardware.
1903 * @frame_buffer: This is the frame buffer returned by the hardware.
1905 * This method will combind the frame header and frame buffer to create a SATA
1906 * D2H register FIS none
1908 void scic_sds_controller_copy_sata_response(
1909 void *response_buffer,
1920 (char *)((char *)response_buffer + sizeof(u32)),
1922 sizeof(struct sata_fis_reg_d2h) - sizeof(u32)
1927 * This method releases the frame once this is done the frame is available for
1928 * re-use by the hardware. The data contained in the frame header and frame
1929 * buffer is no longer valid. The UF queue get pointer is only updated if UF
1930 * control indicates this is appropriate.
1935 void scic_sds_controller_release_frame(
1936 struct scic_sds_controller *this_controller,
1939 if (scic_sds_unsolicited_frame_control_release_frame(
1940 &this_controller->uf_control, frame_index) == true)
1941 SCU_UFQGP_WRITE(this_controller, this_controller->uf_control.get);
1945 * This method sets user parameters and OEM parameters to default values.
1946 * Users can override these values utilizing the scic_user_parameters_set()
1947 * and scic_oem_parameters_set() methods.
1948 * @controller: This parameter specifies the controller for which to set the
1949 * configuration parameters to their default values.
1952 static void scic_sds_controller_set_default_config_parameters(struct scic_sds_controller *scic)
1956 /* Default to no SSC operation. */
1957 scic->oem_parameters.sds1.controller.do_enable_ssc = false;
1959 /* Initialize all of the port parameter information to narrow ports. */
1960 for (index = 0; index < SCI_MAX_PORTS; index++) {
1961 scic->oem_parameters.sds1.ports[index].phy_mask = 0;
1964 /* Initialize all of the phy parameter information. */
1965 for (index = 0; index < SCI_MAX_PHYS; index++) {
1967 * Default to 3G (i.e. Gen 2) for now. User can override if
1969 scic->user_parameters.sds1.phys[index].max_speed_generation = 2;
1971 /* the frequencies cannot be 0 */
1972 scic->user_parameters.sds1.phys[index].align_insertion_frequency = 0x7f;
1973 scic->user_parameters.sds1.phys[index].in_connection_align_insertion_frequency = 0xff;
1974 scic->user_parameters.sds1.phys[index].notify_enable_spin_up_insertion_frequency = 0x33;
1977 * Previous Vitesse based expanders had a arbitration issue that
1978 * is worked around by having the upper 32-bits of SAS address
1979 * with a value greater then the Vitesse company identifier.
1980 * Hence, usage of 0x5FCFFFFF. */
1981 scic->oem_parameters.sds1.phys[index].sas_address.low = 0x00000001;
1982 scic->oem_parameters.sds1.phys[index].sas_address.high = 0x5FCFFFFF;
1985 scic->user_parameters.sds1.stp_inactivity_timeout = 5;
1986 scic->user_parameters.sds1.ssp_inactivity_timeout = 5;
1987 scic->user_parameters.sds1.stp_max_occupancy_timeout = 5;
1988 scic->user_parameters.sds1.ssp_max_occupancy_timeout = 20;
1989 scic->user_parameters.sds1.no_outbound_task_timeout = 20;
1993 enum sci_status scic_controller_construct(struct scic_sds_controller *controller,
1994 void __iomem *scu_base,
1995 void __iomem *smu_base)
1999 sci_base_controller_construct(
2000 &controller->parent,
2001 scic_sds_controller_state_table,
2002 controller->memory_descriptors,
2003 ARRAY_SIZE(controller->memory_descriptors),
2007 controller->scu_registers = scu_base;
2008 controller->smu_registers = smu_base;
2010 scic_sds_port_configuration_agent_construct(&controller->port_agent);
2012 /* Construct the ports for this controller */
2013 for (index = 0; index < SCI_MAX_PORTS; index++)
2014 scic_sds_port_construct(&controller->port_table[index],
2016 scic_sds_port_construct(&controller->port_table[index],
2017 SCIC_SDS_DUMMY_PORT, controller);
2019 /* Construct the phys for this controller */
2020 for (index = 0; index < SCI_MAX_PHYS; index++) {
2021 /* Add all the PHYs to the dummy port */
2022 scic_sds_phy_construct(
2023 &controller->phy_table[index],
2024 &controller->port_table[SCI_MAX_PORTS],
2029 controller->invalid_phy_mask = 0;
2031 /* Set the default maximum values */
2032 controller->completion_event_entries = SCU_EVENT_COUNT;
2033 controller->completion_queue_entries = SCU_COMPLETION_QUEUE_COUNT;
2034 controller->remote_node_entries = SCI_MAX_REMOTE_DEVICES;
2035 controller->logical_port_entries = SCI_MAX_PORTS;
2036 controller->task_context_entries = SCU_IO_REQUEST_COUNT;
2037 controller->uf_control.buffers.count = SCU_UNSOLICITED_FRAME_COUNT;
2038 controller->uf_control.address_table.count = SCU_UNSOLICITED_FRAME_COUNT;
2040 /* Initialize the User and OEM parameters to default values. */
2041 scic_sds_controller_set_default_config_parameters(controller);
2046 /* --------------------------------------------------------------------------- */
2048 enum sci_status scic_controller_initialize(
2049 struct scic_sds_controller *scic)
2051 enum sci_status status = SCI_FAILURE_INVALID_STATE;
2052 sci_base_controller_handler_t initialize;
2055 state = scic->parent.state_machine.current_state_id;
2056 initialize = scic_sds_controller_state_handler_table[state].base.initialize;
2059 status = initialize(&scic->parent);
2061 dev_warn(scic_to_dev(scic),
2062 "%s: SCIC Controller initialize operation requested "
2063 "in invalid state %d\n",
2065 sci_base_state_machine_get_state(
2066 scic_sds_controller_get_base_state_machine(
2072 /* --------------------------------------------------------------------------- */
2074 u32 scic_controller_get_suggested_start_timeout(
2075 struct scic_sds_controller *sc)
2077 /* Validate the user supplied parameters. */
2082 * The suggested minimum timeout value for a controller start operation:
2084 * Signature FIS Timeout
2085 * + Phy Start Timeout
2086 * + Number of Phy Spin Up Intervals
2087 * ---------------------------------
2088 * Number of milliseconds for the controller start operation.
2090 * NOTE: The number of phy spin up intervals will be equivalent
2091 * to the number of phys divided by the number phys allowed
2092 * per interval - 1 (once OEM parameters are supported).
2093 * Currently we assume only 1 phy per interval. */
2095 return SCIC_SDS_SIGNATURE_FIS_TIMEOUT
2096 + SCIC_SDS_CONTROLLER_PHY_START_TIMEOUT
2097 + ((SCI_MAX_PHYS - 1) * SCIC_SDS_CONTROLLER_POWER_CONTROL_INTERVAL);
2100 /* --------------------------------------------------------------------------- */
2102 enum sci_status scic_controller_start(
2103 struct scic_sds_controller *scic,
2106 enum sci_status status = SCI_FAILURE_INVALID_STATE;
2107 sci_base_controller_timed_handler_t start;
2110 state = scic->parent.state_machine.current_state_id;
2111 start = scic_sds_controller_state_handler_table[state].base.start;
2114 status = start(&scic->parent, timeout);
2116 dev_warn(scic_to_dev(scic),
2117 "%s: SCIC Controller start operation requested in "
2118 "invalid state %d\n",
2120 sci_base_state_machine_get_state(
2121 scic_sds_controller_get_base_state_machine(
2127 /* --------------------------------------------------------------------------- */
2129 enum sci_status scic_controller_stop(
2130 struct scic_sds_controller *scic,
2133 enum sci_status status = SCI_FAILURE_INVALID_STATE;
2134 sci_base_controller_timed_handler_t stop;
2137 state = scic->parent.state_machine.current_state_id;
2138 stop = scic_sds_controller_state_handler_table[state].base.stop;
2141 status = stop(&scic->parent, timeout);
2143 dev_warn(scic_to_dev(scic),
2144 "%s: SCIC Controller stop operation requested in "
2145 "invalid state %d\n",
2147 sci_base_state_machine_get_state(
2148 scic_sds_controller_get_base_state_machine(
2154 /* --------------------------------------------------------------------------- */
2156 enum sci_status scic_controller_reset(
2157 struct scic_sds_controller *scic)
2159 enum sci_status status = SCI_FAILURE_INVALID_STATE;
2160 sci_base_controller_handler_t reset;
2163 state = scic->parent.state_machine.current_state_id;
2164 reset = scic_sds_controller_state_handler_table[state].base.reset;
2167 status = reset(&scic->parent);
2169 dev_warn(scic_to_dev(scic),
2170 "%s: SCIC Controller reset operation requested in "
2171 "invalid state %d\n",
2173 sci_base_state_machine_get_state(
2174 scic_sds_controller_get_base_state_machine(
2180 enum sci_io_status scic_controller_start_io(
2181 struct scic_sds_controller *scic,
2182 struct scic_sds_remote_device *remote_device,
2183 struct scic_sds_request *io_request,
2187 sci_base_controller_start_request_handler_t start_io;
2189 state = scic->parent.state_machine.current_state_id;
2190 start_io = scic_sds_controller_state_handler_table[state].base.start_io;
2192 return start_io(&scic->parent,
2193 (struct sci_base_remote_device *) remote_device,
2194 (struct sci_base_request *)io_request, io_tag);
2197 /* --------------------------------------------------------------------------- */
2199 enum sci_status scic_controller_terminate_request(
2200 struct scic_sds_controller *scic,
2201 struct scic_sds_remote_device *remote_device,
2202 struct scic_sds_request *request)
2204 sci_base_controller_request_handler_t terminate_request;
2207 state = scic->parent.state_machine.current_state_id;
2208 terminate_request = scic_sds_controller_state_handler_table[state].terminate_request;
2210 return terminate_request(&scic->parent,
2211 (struct sci_base_remote_device *)remote_device,
2212 (struct sci_base_request *)request);
2215 /* --------------------------------------------------------------------------- */
2217 enum sci_status scic_controller_complete_io(
2218 struct scic_sds_controller *scic,
2219 struct scic_sds_remote_device *remote_device,
2220 struct scic_sds_request *io_request)
2223 sci_base_controller_request_handler_t complete_io;
2225 state = scic->parent.state_machine.current_state_id;
2226 complete_io = scic_sds_controller_state_handler_table[state].base.complete_io;
2228 return complete_io(&scic->parent,
2229 (struct sci_base_remote_device *)remote_device,
2230 (struct sci_base_request *)io_request);
2233 /* --------------------------------------------------------------------------- */
2236 enum sci_task_status scic_controller_start_task(
2237 struct scic_sds_controller *scic,
2238 struct scic_sds_remote_device *remote_device,
2239 struct scic_sds_request *task_request,
2243 sci_base_controller_start_request_handler_t start_task;
2244 enum sci_task_status status = SCI_TASK_FAILURE_INVALID_STATE;
2246 state = scic->parent.state_machine.current_state_id;
2247 start_task = scic_sds_controller_state_handler_table[state].base.start_task;
2250 status = start_task(&scic->parent,
2251 (struct sci_base_remote_device *)remote_device,
2252 (struct sci_base_request *)task_request,
2255 dev_warn(scic_to_dev(scic),
2256 "%s: SCIC Controller starting task from invalid "
2263 /* --------------------------------------------------------------------------- */
2265 enum sci_status scic_controller_complete_task(
2266 struct scic_sds_controller *scic,
2267 struct scic_sds_remote_device *remote_device,
2268 struct scic_sds_request *task_request)
2271 sci_base_controller_request_handler_t complete_task;
2272 enum sci_status status = SCI_FAILURE_INVALID_STATE;
2274 state = scic->parent.state_machine.current_state_id;
2275 complete_task = scic_sds_controller_state_handler_table[state].base.complete_task;
2278 status = complete_task(&scic->parent,
2279 (struct sci_base_remote_device *)remote_device,
2280 (struct sci_base_request *)task_request);
2282 dev_warn(scic_to_dev(scic),
2283 "%s: SCIC Controller completing task from invalid "
2291 /* --------------------------------------------------------------------------- */
2293 enum sci_status scic_controller_get_port_handle(
2294 struct scic_sds_controller *scic,
2296 struct scic_sds_port **port_handle)
2298 if (port_index < scic->logical_port_entries) {
2299 *port_handle = &scic->port_table[port_index];
2304 return SCI_FAILURE_INVALID_PORT;
2307 /* --------------------------------------------------------------------------- */
2309 enum sci_status scic_controller_get_phy_handle(
2310 struct scic_sds_controller *scic,
2312 struct scic_sds_phy **phy_handle)
2314 if (phy_index < ARRAY_SIZE(scic->phy_table)) {
2315 *phy_handle = &scic->phy_table[phy_index];
2320 dev_err(scic_to_dev(scic),
2321 "%s: Controller:0x%p PhyId:0x%x invalid phy index\n",
2322 __func__, scic, phy_index);
2324 return SCI_FAILURE_INVALID_PHY;
2327 /* --------------------------------------------------------------------------- */
2329 u16 scic_controller_allocate_io_tag(
2330 struct scic_sds_controller *scic)
2335 if (!sci_pool_empty(scic->tci_pool)) {
2336 sci_pool_get(scic->tci_pool, task_context);
2338 sequence_count = scic->io_request_sequence[task_context];
2340 return scic_sds_io_tag_construct(sequence_count, task_context);
2343 return SCI_CONTROLLER_INVALID_IO_TAG;
2346 /* --------------------------------------------------------------------------- */
2348 enum sci_status scic_controller_free_io_tag(
2349 struct scic_sds_controller *scic,
2355 BUG_ON(io_tag == SCI_CONTROLLER_INVALID_IO_TAG);
2357 sequence = scic_sds_io_tag_get_sequence(io_tag);
2358 index = scic_sds_io_tag_get_index(io_tag);
2360 if (!sci_pool_full(scic->tci_pool)) {
2361 if (sequence == scic->io_request_sequence[index]) {
2362 scic_sds_io_sequence_increment(
2363 scic->io_request_sequence[index]);
2365 sci_pool_put(scic->tci_pool, index);
2371 return SCI_FAILURE_INVALID_IO_TAG;
2374 /* --------------------------------------------------------------------------- */
2376 void scic_controller_enable_interrupts(
2377 struct scic_sds_controller *scic)
2379 BUG_ON(scic->smu_registers == NULL);
2380 SMU_IMR_WRITE(scic, 0x00000000);
2383 /* --------------------------------------------------------------------------- */
2385 void scic_controller_disable_interrupts(
2386 struct scic_sds_controller *scic)
2388 BUG_ON(scic->smu_registers == NULL);
2389 SMU_IMR_WRITE(scic, 0xffffffff);
2392 /* --------------------------------------------------------------------------- */
2394 enum sci_status scic_controller_set_mode(
2395 struct scic_sds_controller *scic,
2396 enum sci_controller_mode operating_mode)
2398 enum sci_status status = SCI_SUCCESS;
2400 if ((scic->parent.state_machine.current_state_id ==
2401 SCI_BASE_CONTROLLER_STATE_INITIALIZING) ||
2402 (scic->parent.state_machine.current_state_id ==
2403 SCI_BASE_CONTROLLER_STATE_INITIALIZED)) {
2404 switch (operating_mode) {
2405 case SCI_MODE_SPEED:
2406 scic->remote_node_entries = SCI_MAX_REMOTE_DEVICES;
2407 scic->task_context_entries = SCU_IO_REQUEST_COUNT;
2408 scic->uf_control.buffers.count =
2409 SCU_UNSOLICITED_FRAME_COUNT;
2410 scic->completion_event_entries = SCU_EVENT_COUNT;
2411 scic->completion_queue_entries =
2412 SCU_COMPLETION_QUEUE_COUNT;
2413 scic_sds_controller_build_memory_descriptor_table(scic);
2417 scic->remote_node_entries = SCI_MIN_REMOTE_DEVICES;
2418 scic->task_context_entries = SCI_MIN_IO_REQUESTS;
2419 scic->uf_control.buffers.count =
2420 SCU_MIN_UNSOLICITED_FRAMES;
2421 scic->completion_event_entries = SCU_MIN_EVENTS;
2422 scic->completion_queue_entries =
2423 SCU_MIN_COMPLETION_QUEUE_ENTRIES;
2424 scic_sds_controller_build_memory_descriptor_table(scic);
2428 status = SCI_FAILURE_INVALID_PARAMETER_VALUE;
2432 status = SCI_FAILURE_INVALID_STATE;
2438 * scic_sds_controller_reset_hardware() -
2440 * This method will reset the controller hardware.
2442 void scic_sds_controller_reset_hardware(
2443 struct scic_sds_controller *scic)
2445 /* Disable interrupts so we dont take any spurious interrupts */
2446 scic_controller_disable_interrupts(scic);
2449 SMU_SMUSRCR_WRITE(scic, 0xFFFFFFFF);
2451 /* Delay for 1ms to before clearing the CQP and UFQPR. */
2454 /* The write to the CQGR clears the CQP */
2455 SMU_CQGR_WRITE(scic, 0x00000000);
2457 /* The write to the UFQGP clears the UFQPR */
2458 SCU_UFQGP_WRITE(scic, 0x00000000);
2461 /* --------------------------------------------------------------------------- */
2463 enum sci_status scic_user_parameters_set(
2464 struct scic_sds_controller *scic,
2465 union scic_user_parameters *scic_parms)
2468 (scic->parent.state_machine.current_state_id
2469 == SCI_BASE_CONTROLLER_STATE_RESET)
2470 || (scic->parent.state_machine.current_state_id
2471 == SCI_BASE_CONTROLLER_STATE_INITIALIZING)
2472 || (scic->parent.state_machine.current_state_id
2473 == SCI_BASE_CONTROLLER_STATE_INITIALIZED)
2478 * Validate the user parameters. If they are not legal, then
2479 * return a failure. */
2480 for (index = 0; index < SCI_MAX_PHYS; index++) {
2481 if (!(scic_parms->sds1.phys[index].max_speed_generation
2482 <= SCIC_SDS_PARM_MAX_SPEED
2483 && scic_parms->sds1.phys[index].max_speed_generation
2484 > SCIC_SDS_PARM_NO_SPEED))
2485 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
2487 if (scic_parms->sds1.phys[index].in_connection_align_insertion_frequency < 3)
2488 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
2490 (scic_parms->sds1.phys[index].in_connection_align_insertion_frequency < 3) ||
2491 (scic_parms->sds1.phys[index].align_insertion_frequency == 0) ||
2492 (scic_parms->sds1.phys[index].notify_enable_spin_up_insertion_frequency == 0)
2494 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
2497 if ((scic_parms->sds1.stp_inactivity_timeout == 0) ||
2498 (scic_parms->sds1.ssp_inactivity_timeout == 0) ||
2499 (scic_parms->sds1.stp_max_occupancy_timeout == 0) ||
2500 (scic_parms->sds1.ssp_max_occupancy_timeout == 0) ||
2501 (scic_parms->sds1.no_outbound_task_timeout == 0))
2502 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
2504 memcpy(&scic->user_parameters, scic_parms, sizeof(*scic_parms));
2509 return SCI_FAILURE_INVALID_STATE;
2512 /* --------------------------------------------------------------------------- */
2514 void scic_user_parameters_get(
2515 struct scic_sds_controller *scic,
2516 union scic_user_parameters *scic_parms)
2518 memcpy(scic_parms, (&scic->user_parameters), sizeof(*scic_parms));
2521 /* --------------------------------------------------------------------------- */
2523 enum sci_status scic_oem_parameters_set(
2524 struct scic_sds_controller *scic,
2525 union scic_oem_parameters *scic_parms)
2528 (scic->parent.state_machine.current_state_id
2529 == SCI_BASE_CONTROLLER_STATE_RESET)
2530 || (scic->parent.state_machine.current_state_id
2531 == SCI_BASE_CONTROLLER_STATE_INITIALIZING)
2532 || (scic->parent.state_machine.current_state_id
2533 == SCI_BASE_CONTROLLER_STATE_INITIALIZED)
2538 * Validate the oem parameters. If they are not legal, then
2539 * return a failure. */
2540 for (index = 0; index < SCI_MAX_PORTS; index++) {
2541 if (scic_parms->sds1.ports[index].phy_mask > SCIC_SDS_PARM_PHY_MASK_MAX) {
2542 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
2546 for (index = 0; index < SCI_MAX_PHYS; index++) {
2548 scic_parms->sds1.phys[index].sas_address.high == 0
2549 && scic_parms->sds1.phys[index].sas_address.low == 0
2551 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
2555 memcpy(&scic->oem_parameters, scic_parms, sizeof(*scic_parms));
2559 return SCI_FAILURE_INVALID_STATE;
2562 /* --------------------------------------------------------------------------- */
2564 void scic_oem_parameters_get(
2565 struct scic_sds_controller *scic,
2566 union scic_oem_parameters *scic_parms)
2568 memcpy(scic_parms, (&scic->oem_parameters), sizeof(*scic_parms));
2571 /* --------------------------------------------------------------------------- */
2574 #define INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_LOWER_BOUND_NS 853
2575 #define INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_UPPER_BOUND_NS 1280
2576 #define INTERRUPT_COALESCE_TIMEOUT_MAX_US 2700000
2577 #define INTERRUPT_COALESCE_NUMBER_MAX 256
2578 #define INTERRUPT_COALESCE_TIMEOUT_ENCODE_MIN 7
2579 #define INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX 28
2581 enum sci_status scic_controller_set_interrupt_coalescence(
2582 struct scic_sds_controller *scic_controller,
2583 u32 coalesce_number,
2584 u32 coalesce_timeout)
2586 u8 timeout_encode = 0;
2590 /* Check if the input parameters fall in the range. */
2591 if (coalesce_number > INTERRUPT_COALESCE_NUMBER_MAX)
2592 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
2595 * Defined encoding for interrupt coalescing timeout:
2596 * Value Min Max Units
2597 * ----- --- --- -----
2627 * Others Undefined */
2630 * Use the table above to decide the encode of interrupt coalescing timeout
2631 * value for register writing. */
2632 if (coalesce_timeout == 0)
2635 /* make the timeout value in unit of (10 ns). */
2636 coalesce_timeout = coalesce_timeout * 100;
2637 min = INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_LOWER_BOUND_NS / 10;
2638 max = INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_UPPER_BOUND_NS / 10;
2640 /* get the encode of timeout for register writing. */
2641 for (timeout_encode = INTERRUPT_COALESCE_TIMEOUT_ENCODE_MIN;
2642 timeout_encode <= INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX;
2644 if (min <= coalesce_timeout && max > coalesce_timeout)
2646 else if (coalesce_timeout >= max && coalesce_timeout < min * 2
2647 && coalesce_timeout <= INTERRUPT_COALESCE_TIMEOUT_MAX_US * 100) {
2648 if ((coalesce_timeout - max) < (2 * min - coalesce_timeout))
2660 if (timeout_encode == INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX + 1)
2661 /* the value is out of range. */
2662 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
2667 (SMU_ICC_GEN_VAL(NUMBER, coalesce_number) |
2668 SMU_ICC_GEN_VAL(TIMER, timeout_encode))
2671 scic_controller->interrupt_coalesce_number = (u16)coalesce_number;
2672 scic_controller->interrupt_coalesce_timeout = coalesce_timeout / 100;
2678 struct scic_sds_controller *scic_controller_alloc(struct device *dev)
2680 return devm_kzalloc(dev, sizeof(struct scic_sds_controller), GFP_KERNEL);
2684 * *****************************************************************************
2685 * * DEFAULT STATE HANDLERS
2686 * ***************************************************************************** */
2690 * @controller: This is struct sci_base_controller object which is cast into a
2691 * struct scic_sds_controller object.
2692 * @remote_device: This is struct sci_base_remote_device which, if it was used, would
2693 * be cast to a struct scic_sds_remote_device.
2694 * @io_request: This is the struct sci_base_request which, if it was used, would be
2695 * cast to a SCIC_SDS_IO_REQUEST.
2696 * @io_tag: This is the IO tag to be assigned to the IO request or
2697 * SCI_CONTROLLER_INVALID_IO_TAG.
2699 * This method is called when the struct scic_sds_controller default start io/task
2700 * handler is in place. - Issue a warning message enum sci_status
2701 * SCI_FAILURE_INVALID_STATE
2703 static enum sci_status scic_sds_controller_default_start_operation_handler(
2704 struct sci_base_controller *controller,
2705 struct sci_base_remote_device *remote_device,
2706 struct sci_base_request *io_request,
2709 struct scic_sds_controller *this_controller;
2711 this_controller = (struct scic_sds_controller *)controller;
2713 dev_warn(scic_to_dev(this_controller),
2714 "%s: SCIC Controller requested to start an io/task from "
2715 "invalid state %d\n",
2717 sci_base_state_machine_get_state(
2718 scic_sds_controller_get_base_state_machine(
2721 return SCI_FAILURE_INVALID_STATE;
2726 * @controller: This is struct sci_base_controller object which is cast into a
2727 * struct scic_sds_controller object.
2728 * @remote_device: This is struct sci_base_remote_device which, if it was used, would
2729 * be cast to a struct scic_sds_remote_device.
2730 * @io_request: This is the struct sci_base_request which, if it was used, would be
2731 * cast to a SCIC_SDS_IO_REQUEST.
2733 * This method is called when the struct scic_sds_controller default request handler
2734 * is in place. - Issue a warning message enum sci_status SCI_FAILURE_INVALID_STATE
2736 static enum sci_status scic_sds_controller_default_request_handler(
2737 struct sci_base_controller *controller,
2738 struct sci_base_remote_device *remote_device,
2739 struct sci_base_request *io_request)
2741 struct scic_sds_controller *this_controller;
2743 this_controller = (struct scic_sds_controller *)controller;
2745 dev_warn(scic_to_dev(this_controller),
2746 "%s: SCIC Controller request operation from invalid state %d\n",
2748 sci_base_state_machine_get_state(
2749 scic_sds_controller_get_base_state_machine(
2752 return SCI_FAILURE_INVALID_STATE;
2756 * *****************************************************************************
2757 * * GENERAL (COMMON) STATE HANDLERS
2758 * ***************************************************************************** */
2762 * @controller: The struct sci_base_controller object which is cast into a
2763 * struct scic_sds_controller object.
2765 * This method is called when the struct scic_sds_controller is in the ready state
2766 * reset handler is in place. - Transition to
2767 * SCI_BASE_CONTROLLER_STATE_RESETTING enum sci_status SCI_SUCCESS
2769 static enum sci_status scic_sds_controller_general_reset_handler(
2770 struct sci_base_controller *controller)
2772 struct scic_sds_controller *this_controller;
2774 this_controller = (struct scic_sds_controller *)controller;
2777 * The reset operation is not a graceful cleanup just perform the state
2779 sci_base_state_machine_change_state(
2780 scic_sds_controller_get_base_state_machine(this_controller),
2781 SCI_BASE_CONTROLLER_STATE_RESETTING
2788 * *****************************************************************************
2789 * * RESET STATE HANDLERS
2790 * ***************************************************************************** */
2794 * @controller: This is the struct sci_base_controller object which is cast into a
2795 * struct scic_sds_controller object.
2797 * This method is the struct scic_sds_controller initialize handler for the reset
2798 * state. - Currently this function does nothing enum sci_status SCI_FAILURE This
2799 * function is not yet implemented and is a valid request from the reset state.
2801 static enum sci_status scic_sds_controller_reset_state_initialize_handler(
2802 struct sci_base_controller *controller)
2805 enum sci_status result = SCI_SUCCESS;
2806 struct scic_sds_controller *this_controller;
2808 this_controller = (struct scic_sds_controller *)controller;
2810 sci_base_state_machine_change_state(
2811 scic_sds_controller_get_base_state_machine(this_controller),
2812 SCI_BASE_CONTROLLER_STATE_INITIALIZING
2815 this_controller->timeout_timer = isci_event_timer_create(
2817 (void (*)(void *))scic_sds_controller_timeout_handler,
2818 (void (*)(void *))controller);
2820 scic_sds_controller_initialize_phy_startup(this_controller);
2822 scic_sds_controller_initialize_power_control(this_controller);
2825 * There is nothing to do here for B0 since we do not have to
2826 * program the AFE registers.
2827 * / @todo The AFE settings are supposed to be correct for the B0 but
2828 * / presently they seem to be wrong. */
2829 scic_sds_controller_afe_initialization(this_controller);
2831 if (SCI_SUCCESS == result) {
2835 /* Take the hardware out of reset */
2836 SMU_SMUSRCR_WRITE(this_controller, 0x00000000);
2839 * / @todo Provide meaningfull error code for hardware failure
2840 * result = SCI_FAILURE_CONTROLLER_HARDWARE; */
2841 result = SCI_FAILURE;
2842 terminate_loop = 100;
2844 while (terminate_loop-- && (result != SCI_SUCCESS)) {
2845 /* Loop until the hardware reports success */
2846 udelay(SCU_CONTEXT_RAM_INIT_STALL_TIME);
2847 status = SMU_SMUCSR_READ(this_controller);
2849 if ((status & SCU_RAM_INIT_COMPLETED) == SCU_RAM_INIT_COMPLETED) {
2850 result = SCI_SUCCESS;
2855 if (result == SCI_SUCCESS) {
2856 u32 max_supported_ports;
2857 u32 max_supported_devices;
2858 u32 max_supported_io_requests;
2859 u32 device_context_capacity;
2862 * Determine what are the actaul device capacities that the
2863 * hardware will support */
2864 device_context_capacity = SMU_DCC_READ(this_controller);
2866 max_supported_ports =
2867 smu_dcc_get_max_ports(device_context_capacity);
2868 max_supported_devices =
2869 smu_dcc_get_max_remote_node_context(device_context_capacity);
2870 max_supported_io_requests =
2871 smu_dcc_get_max_task_context(device_context_capacity);
2873 /* Make all PEs that are unassigned match up with the logical ports */
2874 for (index = 0; index < max_supported_ports; index++) {
2877 this_controller->scu_registers->peg0.ptsg.protocol_engine[index],
2882 /* Record the smaller of the two capacity values */
2883 this_controller->logical_port_entries =
2884 min(max_supported_ports, this_controller->logical_port_entries);
2886 this_controller->task_context_entries =
2887 min(max_supported_io_requests, this_controller->task_context_entries);
2889 this_controller->remote_node_entries =
2890 min(max_supported_devices, this_controller->remote_node_entries);
2893 * Now that we have the correct hardware reported minimum values
2894 * build the MDL for the controller. Default to a performance
2896 scic_controller_set_mode(this_controller, SCI_MODE_SPEED);
2899 /* Initialize hardware PCI Relaxed ordering in DMA engines */
2900 if (result == SCI_SUCCESS) {
2901 u32 dma_configuration;
2903 /* Configure the payload DMA */
2904 dma_configuration = SCU_PDMACR_READ(this_controller);
2905 dma_configuration |= SCU_PDMACR_GEN_BIT(PCI_RELAXED_ORDERING_ENABLE);
2906 SCU_PDMACR_WRITE(this_controller, dma_configuration);
2908 /* Configure the control DMA */
2909 dma_configuration = SCU_CDMACR_READ(this_controller);
2910 dma_configuration |= SCU_CDMACR_GEN_BIT(PCI_RELAXED_ORDERING_ENABLE);
2911 SCU_CDMACR_WRITE(this_controller, dma_configuration);
2915 * Initialize the PHYs before the PORTs because the PHY registers
2916 * are accessed during the port initialization. */
2917 if (result == SCI_SUCCESS) {
2918 /* Initialize the phys */
2920 (result == SCI_SUCCESS) && (index < SCI_MAX_PHYS);
2922 result = scic_sds_phy_initialize(
2923 &this_controller->phy_table[index],
2924 &this_controller->scu_registers->peg0.pe[index].tl,
2925 &this_controller->scu_registers->peg0.pe[index].ll
2930 if (result == SCI_SUCCESS) {
2931 /* Initialize the logical ports */
2933 (index < this_controller->logical_port_entries)
2934 && (result == SCI_SUCCESS);
2936 result = scic_sds_port_initialize(
2937 &this_controller->port_table[index],
2938 &this_controller->scu_registers->peg0.ptsg.port[index],
2939 &this_controller->scu_registers->peg0.ptsg.protocol_engine,
2940 &this_controller->scu_registers->peg0.viit[index]
2945 if (SCI_SUCCESS == result) {
2946 result = scic_sds_port_configuration_agent_initialize(
2948 &this_controller->port_agent
2952 /* Advance the controller state machine */
2953 if (result == SCI_SUCCESS) {
2954 sci_base_state_machine_change_state(
2955 scic_sds_controller_get_base_state_machine(this_controller),
2956 SCI_BASE_CONTROLLER_STATE_INITIALIZED
2959 sci_base_state_machine_change_state(
2960 scic_sds_controller_get_base_state_machine(this_controller),
2961 SCI_BASE_CONTROLLER_STATE_FAILED
2969 * *****************************************************************************
2970 * * INITIALIZED STATE HANDLERS
2971 * ***************************************************************************** */
2975 * @controller: This is the struct sci_base_controller object which is cast into a
2976 * struct scic_sds_controller object.
2977 * @timeout: This is the allowed time for the controller object to reach the
2980 * This method is the struct scic_sds_controller start handler for the initialized
2981 * state. - Validate we have a good memory descriptor table - Initialze the
2982 * physical memory before programming the hardware - Program the SCU hardware
2983 * with the physical memory addresses passed in the memory descriptor table. -
2984 * Initialzie the TCi pool - Initialize the RNi pool - Initialize the
2985 * completion queue - Initialize the unsolicited frame data - Take the SCU port
2986 * task scheduler out of reset - Start the first phy object. - Transition to
2987 * SCI_BASE_CONTROLLER_STATE_STARTING. enum sci_status SCI_SUCCESS if all of the
2988 * controller start operations complete
2989 * SCI_FAILURE_UNSUPPORTED_INFORMATION_FIELD if one or more of the memory
2990 * descriptor fields is invalid.
2992 static enum sci_status scic_sds_controller_initialized_state_start_handler(
2993 struct sci_base_controller *controller,
2997 enum sci_status result;
2998 struct scic_sds_controller *this_controller;
3000 this_controller = (struct scic_sds_controller *)controller;
3002 /* Make sure that the SCI User filled in the memory descriptor table correctly */
3003 result = scic_sds_controller_validate_memory_descriptor_table(this_controller);
3005 if (result == SCI_SUCCESS) {
3006 /* The memory descriptor list looks good so program the hardware */
3007 scic_sds_controller_ram_initialization(this_controller);
3010 if (result == SCI_SUCCESS) {
3011 /* Build the TCi free pool */
3012 sci_pool_initialize(this_controller->tci_pool);
3013 for (index = 0; index < this_controller->task_context_entries; index++) {
3014 sci_pool_put(this_controller->tci_pool, index);
3017 /* Build the RNi free pool */
3018 scic_sds_remote_node_table_initialize(
3019 &this_controller->available_remote_nodes,
3020 this_controller->remote_node_entries
3024 if (result == SCI_SUCCESS) {
3026 * Before anything else lets make sure we will not be interrupted
3027 * by the hardware. */
3028 scic_controller_disable_interrupts(this_controller);
3030 /* Enable the port task scheduler */
3031 scic_sds_controller_enable_port_task_scheduler(this_controller);
3033 /* Assign all the task entries to this controller physical function */
3034 scic_sds_controller_assign_task_entries(this_controller);
3036 /* Now initialze the completion queue */
3037 scic_sds_controller_initialize_completion_queue(this_controller);
3039 /* Initialize the unsolicited frame queue for use */
3040 scic_sds_controller_initialize_unsolicited_frame_queue(this_controller);
3043 /* Start all of the ports on this controller */
3044 for (index = 0; index < this_controller->logical_port_entries &&
3045 result == SCI_SUCCESS; index++) {
3046 struct scic_sds_port *sci_port = &this_controller->port_table[index];
3048 result = sci_port->state_handlers->parent.start_handler(&sci_port->parent);
3051 if (result == SCI_SUCCESS) {
3052 scic_sds_controller_start_next_phy(this_controller);
3054 isci_event_timer_start(this_controller,
3055 this_controller->timeout_timer,
3058 sci_base_state_machine_change_state(
3059 scic_sds_controller_get_base_state_machine(this_controller),
3060 SCI_BASE_CONTROLLER_STATE_STARTING
3068 * *****************************************************************************
3069 * * INITIALIZED STATE HANDLERS
3070 * ***************************************************************************** */
3074 * @controller: This is struct scic_sds_controller which receives the link up
3076 * @port: This is struct scic_sds_port with which the phy is associated.
3077 * @phy: This is the struct scic_sds_phy which has gone link up.
3079 * This method is called when the struct scic_sds_controller is in the starting state
3080 * link up handler is called. This method will perform the following: - Stop
3081 * the phy timer - Start the next phy - Report the link up condition to the
3084 static void scic_sds_controller_starting_state_link_up_handler(
3085 struct scic_sds_controller *this_controller,
3086 struct scic_sds_port *port,
3087 struct scic_sds_phy *phy)
3089 scic_sds_controller_phy_timer_stop(this_controller);
3091 this_controller->port_agent.link_up_handler(
3092 this_controller, &this_controller->port_agent, port, phy
3094 /* scic_sds_port_link_up(port, phy); */
3096 scic_sds_controller_start_next_phy(this_controller);
3101 * @controller: This is struct scic_sds_controller which receives the link down
3103 * @port: This is struct scic_sds_port with which the phy is associated.
3104 * @phy: This is the struct scic_sds_phy which has gone link down.
3106 * This method is called when the struct scic_sds_controller is in the starting state
3107 * link down handler is called. - Report the link down condition to the port
3110 static void scic_sds_controller_starting_state_link_down_handler(
3111 struct scic_sds_controller *this_controller,
3112 struct scic_sds_port *port,
3113 struct scic_sds_phy *phy)
3115 this_controller->port_agent.link_down_handler(
3116 this_controller, &this_controller->port_agent, port, phy
3118 /* scic_sds_port_link_down(port, phy); */
3122 * *****************************************************************************
3123 * * READY STATE HANDLERS
3124 * ***************************************************************************** */
3128 * @controller: The struct sci_base_controller object which is cast into a
3129 * struct scic_sds_controller object.
3130 * @timeout: The timeout for when the stop operation should report a failure.
3132 * This method is called when the struct scic_sds_controller is in the ready state
3133 * stop handler is called. - Start the timeout timer - Transition to
3134 * SCI_BASE_CONTROLLER_STATE_STOPPING. enum sci_status SCI_SUCCESS
3136 static enum sci_status scic_sds_controller_ready_state_stop_handler(
3137 struct sci_base_controller *controller,
3140 struct scic_sds_controller *this_controller;
3142 this_controller = (struct scic_sds_controller *)controller;
3144 isci_event_timer_start(this_controller,
3145 this_controller->timeout_timer,
3148 sci_base_state_machine_change_state(
3149 scic_sds_controller_get_base_state_machine(this_controller),
3150 SCI_BASE_CONTROLLER_STATE_STOPPING
3158 * @controller: This is struct sci_base_controller object which is cast into a
3159 * struct scic_sds_controller object.
3160 * @remote_device: This is struct sci_base_remote_device which is cast to a
3161 * struct scic_sds_remote_device object.
3162 * @io_request: This is the struct sci_base_request which is cast to a
3163 * SCIC_SDS_IO_REQUEST object.
3164 * @io_tag: This is the IO tag to be assigned to the IO request or
3165 * SCI_CONTROLLER_INVALID_IO_TAG.
3167 * This method is called when the struct scic_sds_controller is in the ready state and
3168 * the start io handler is called. - Start the io request on the remote device
3169 * - if successful - assign the io_request to the io_request_table - post the
3170 * request to the hardware enum sci_status SCI_SUCCESS if the start io operation
3171 * succeeds SCI_FAILURE_INSUFFICIENT_RESOURCES if the IO tag could not be
3172 * allocated for the io request. SCI_FAILURE_INVALID_STATE if one or more
3173 * objects are not in a valid state to accept io requests. How does the io_tag
3174 * parameter get assigned to the io request?
3176 static enum sci_status scic_sds_controller_ready_state_start_io_handler(
3177 struct sci_base_controller *controller,
3178 struct sci_base_remote_device *remote_device,
3179 struct sci_base_request *io_request,
3182 enum sci_status status;
3184 struct scic_sds_controller *this_controller;
3185 struct scic_sds_request *the_request;
3186 struct scic_sds_remote_device *the_device;
3188 this_controller = (struct scic_sds_controller *)controller;
3189 the_request = (struct scic_sds_request *)io_request;
3190 the_device = (struct scic_sds_remote_device *)remote_device;
3192 status = scic_sds_remote_device_start_io(this_controller, the_device, the_request);
3194 if (status == SCI_SUCCESS) {
3195 this_controller->io_request_table[
3196 scic_sds_io_tag_get_index(the_request->io_tag)] = the_request;
3198 scic_sds_controller_post_request(
3200 scic_sds_request_get_post_context(the_request)
3209 * @controller: This is struct sci_base_controller object which is cast into a
3210 * struct scic_sds_controller object.
3211 * @remote_device: This is struct sci_base_remote_device which is cast to a
3212 * struct scic_sds_remote_device object.
3213 * @io_request: This is the struct sci_base_request which is cast to a
3214 * SCIC_SDS_IO_REQUEST object.
3216 * This method is called when the struct scic_sds_controller is in the ready state and
3217 * the complete io handler is called. - Complete the io request on the remote
3218 * device - if successful - remove the io_request to the io_request_table
3219 * enum sci_status SCI_SUCCESS if the start io operation succeeds
3220 * SCI_FAILURE_INVALID_STATE if one or more objects are not in a valid state to
3221 * accept io requests.
3223 static enum sci_status scic_sds_controller_ready_state_complete_io_handler(
3224 struct sci_base_controller *controller,
3225 struct sci_base_remote_device *remote_device,
3226 struct sci_base_request *io_request)
3229 enum sci_status status;
3230 struct scic_sds_controller *this_controller;
3231 struct scic_sds_request *the_request;
3232 struct scic_sds_remote_device *the_device;
3234 this_controller = (struct scic_sds_controller *)controller;
3235 the_request = (struct scic_sds_request *)io_request;
3236 the_device = (struct scic_sds_remote_device *)remote_device;
3238 status = scic_sds_remote_device_complete_io(
3239 this_controller, the_device, the_request);
3241 if (status == SCI_SUCCESS) {
3242 index = scic_sds_io_tag_get_index(the_request->io_tag);
3243 this_controller->io_request_table[index] = NULL;
3251 * @controller: This is struct sci_base_controller object which is cast into a
3252 * struct scic_sds_controller object.
3253 * @remote_device: This is struct sci_base_remote_device which is cast to a
3254 * struct scic_sds_remote_device object.
3255 * @io_request: This is the struct sci_base_request which is cast to a
3256 * SCIC_SDS_IO_REQUEST object.
3258 * This method is called when the struct scic_sds_controller is in the ready state and
3259 * the continue io handler is called. enum sci_status
3261 static enum sci_status scic_sds_controller_ready_state_continue_io_handler(
3262 struct sci_base_controller *controller,
3263 struct sci_base_remote_device *remote_device,
3264 struct sci_base_request *io_request)
3266 struct scic_sds_controller *this_controller;
3267 struct scic_sds_request *the_request;
3269 the_request = (struct scic_sds_request *)io_request;
3270 this_controller = (struct scic_sds_controller *)controller;
3272 this_controller->io_request_table[
3273 scic_sds_io_tag_get_index(the_request->io_tag)] = the_request;
3275 scic_sds_controller_post_request(
3277 scic_sds_request_get_post_context(the_request)
3285 * @controller: This is struct sci_base_controller object which is cast into a
3286 * struct scic_sds_controller object.
3287 * @remote_device: This is struct sci_base_remote_device which is cast to a
3288 * struct scic_sds_remote_device object.
3289 * @io_request: This is the struct sci_base_request which is cast to a
3290 * SCIC_SDS_IO_REQUEST object.
3291 * @task_tag: This is the task tag to be assigned to the task request or
3292 * SCI_CONTROLLER_INVALID_IO_TAG.
3294 * This method is called when the struct scic_sds_controller is in the ready state and
3295 * the start task handler is called. - The remote device is requested to start
3296 * the task request - if successful - assign the task to the io_request_table -
3297 * post the request to the SCU hardware enum sci_status SCI_SUCCESS if the start io
3298 * operation succeeds SCI_FAILURE_INSUFFICIENT_RESOURCES if the IO tag could
3299 * not be allocated for the io request. SCI_FAILURE_INVALID_STATE if one or
3300 * more objects are not in a valid state to accept io requests. How does the io
3301 * tag get assigned in this code path?
3303 static enum sci_status scic_sds_controller_ready_state_start_task_handler(
3304 struct sci_base_controller *controller,
3305 struct sci_base_remote_device *remote_device,
3306 struct sci_base_request *io_request,
3309 struct scic_sds_controller *this_controller = (struct scic_sds_controller *)
3311 struct scic_sds_request *the_request = (struct scic_sds_request *)
3313 struct scic_sds_remote_device *the_device = (struct scic_sds_remote_device *)
3315 enum sci_status status;
3317 status = scic_sds_remote_device_start_task(
3318 this_controller, the_device, the_request
3321 if (status == SCI_SUCCESS) {
3322 this_controller->io_request_table[
3323 scic_sds_io_tag_get_index(the_request->io_tag)] = the_request;
3325 scic_sds_controller_post_request(
3327 scic_sds_request_get_post_context(the_request)
3329 } else if (status == SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS) {
3330 this_controller->io_request_table[
3331 scic_sds_io_tag_get_index(the_request->io_tag)] = the_request;
3334 * We will let framework know this task request started successfully,
3335 * although core is still woring on starting the request (to post tc when
3336 * RNC is resumed.) */
3337 status = SCI_SUCCESS;
3344 * @controller: This is struct sci_base_controller object which is cast into a
3345 * struct scic_sds_controller object.
3346 * @remote_device: This is struct sci_base_remote_device which is cast to a
3347 * struct scic_sds_remote_device object.
3348 * @io_request: This is the struct sci_base_request which is cast to a
3349 * SCIC_SDS_IO_REQUEST object.
3351 * This method is called when the struct scic_sds_controller is in the ready state and
3352 * the terminate request handler is called. - call the io request terminate
3353 * function - if successful - post the terminate request to the SCU hardware
3354 * enum sci_status SCI_SUCCESS if the start io operation succeeds
3355 * SCI_FAILURE_INVALID_STATE if one or more objects are not in a valid state to
3356 * accept io requests.
3358 static enum sci_status scic_sds_controller_ready_state_terminate_request_handler(
3359 struct sci_base_controller *controller,
3360 struct sci_base_remote_device *remote_device,
3361 struct sci_base_request *io_request)
3363 struct scic_sds_controller *this_controller = (struct scic_sds_controller *)
3365 struct scic_sds_request *the_request = (struct scic_sds_request *)
3367 enum sci_status status;
3369 status = scic_sds_io_request_terminate(the_request);
3370 if (status == SCI_SUCCESS) {
3372 * Utilize the original post context command and or in the POST_TC_ABORT
3373 * request sub-type. */
3374 scic_sds_controller_post_request(
3376 scic_sds_request_get_post_context(the_request)
3377 | SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT
3386 * @controller: This is struct scic_sds_controller which receives the link up
3388 * @port: This is struct scic_sds_port with which the phy is associated.
3389 * @phy: This is the struct scic_sds_phy which has gone link up.
3391 * This method is called when the struct scic_sds_controller is in the starting state
3392 * link up handler is called. This method will perform the following: - Stop
3393 * the phy timer - Start the next phy - Report the link up condition to the
3396 static void scic_sds_controller_ready_state_link_up_handler(
3397 struct scic_sds_controller *this_controller,
3398 struct scic_sds_port *port,
3399 struct scic_sds_phy *phy)
3401 this_controller->port_agent.link_up_handler(
3402 this_controller, &this_controller->port_agent, port, phy
3408 * @controller: This is struct scic_sds_controller which receives the link down
3410 * @port: This is struct scic_sds_port with which the phy is associated.
3411 * @phy: This is the struct scic_sds_phy which has gone link down.
3413 * This method is called when the struct scic_sds_controller is in the starting state
3414 * link down handler is called. - Report the link down condition to the port
3417 static void scic_sds_controller_ready_state_link_down_handler(
3418 struct scic_sds_controller *this_controller,
3419 struct scic_sds_port *port,
3420 struct scic_sds_phy *phy)
3422 this_controller->port_agent.link_down_handler(
3423 this_controller, &this_controller->port_agent, port, phy
3428 * *****************************************************************************
3429 * * STOPPING STATE HANDLERS
3430 * ***************************************************************************** */
3434 * @controller: This is struct sci_base_controller object which is cast into a
3435 * struct scic_sds_controller object.
3436 * @remote_device: This is struct sci_base_remote_device which is cast to a
3437 * struct scic_sds_remote_device object.
3438 * @io_request: This is the struct sci_base_request which is cast to a
3439 * SCIC_SDS_IO_REQUEST object.
3441 * This method is called when the struct scic_sds_controller is in a stopping state
3442 * and the complete io handler is called. - This function is not yet
3443 * implemented enum sci_status SCI_FAILURE
3445 static enum sci_status scic_sds_controller_stopping_state_complete_io_handler(
3446 struct sci_base_controller *controller,
3447 struct sci_base_remote_device *remote_device,
3448 struct sci_base_request *io_request)
3450 struct scic_sds_controller *this_controller;
3452 this_controller = (struct scic_sds_controller *)controller;
3454 /* / @todo Implement this function */
3460 * @controller: This is struct sci_base_controller object which is cast into a
3461 * struct scic_sds_controller object.
3462 * @remote_device: This is struct sci_base_remote_device which is cast to a
3463 * struct scic_sds_remote_device object.
3464 * @io_request: This is the struct sci_base_request which is cast to a
3465 * SCIC_SDS_IO_REQUEST object.
3467 * This method is called when the struct scic_sds_controller is in a stopping state
3468 * and the complete task handler is called. - This function is not yet
3469 * implemented enum sci_status SCI_FAILURE
3473 * *****************************************************************************
3474 * * STOPPED STATE HANDLERS
3475 * ***************************************************************************** */
3478 * *****************************************************************************
3479 * * FAILED STATE HANDLERS
3480 * ***************************************************************************** */
3482 const struct scic_sds_controller_state_handler scic_sds_controller_state_handler_table[] = {
3483 [SCI_BASE_CONTROLLER_STATE_INITIAL] = {
3484 .base.start_io = scic_sds_controller_default_start_operation_handler,
3485 .base.complete_io = scic_sds_controller_default_request_handler,
3486 .base.continue_io = scic_sds_controller_default_request_handler,
3487 .terminate_request = scic_sds_controller_default_request_handler,
3489 [SCI_BASE_CONTROLLER_STATE_RESET] = {
3490 .base.initialize = scic_sds_controller_reset_state_initialize_handler,
3491 .base.start_io = scic_sds_controller_default_start_operation_handler,
3492 .base.complete_io = scic_sds_controller_default_request_handler,
3493 .base.continue_io = scic_sds_controller_default_request_handler,
3494 .terminate_request = scic_sds_controller_default_request_handler,
3496 [SCI_BASE_CONTROLLER_STATE_INITIALIZING] = {
3497 .base.start_io = scic_sds_controller_default_start_operation_handler,
3498 .base.complete_io = scic_sds_controller_default_request_handler,
3499 .base.continue_io = scic_sds_controller_default_request_handler,
3500 .terminate_request = scic_sds_controller_default_request_handler,
3502 [SCI_BASE_CONTROLLER_STATE_INITIALIZED] = {
3503 .base.start = scic_sds_controller_initialized_state_start_handler,
3504 .base.start_io = scic_sds_controller_default_start_operation_handler,
3505 .base.complete_io = scic_sds_controller_default_request_handler,
3506 .base.continue_io = scic_sds_controller_default_request_handler,
3507 .terminate_request = scic_sds_controller_default_request_handler,
3509 [SCI_BASE_CONTROLLER_STATE_STARTING] = {
3510 .base.start_io = scic_sds_controller_default_start_operation_handler,
3511 .base.complete_io = scic_sds_controller_default_request_handler,
3512 .base.continue_io = scic_sds_controller_default_request_handler,
3513 .terminate_request = scic_sds_controller_default_request_handler,
3514 .link_up = scic_sds_controller_starting_state_link_up_handler,
3515 .link_down = scic_sds_controller_starting_state_link_down_handler
3517 [SCI_BASE_CONTROLLER_STATE_READY] = {
3518 .base.stop = scic_sds_controller_ready_state_stop_handler,
3519 .base.reset = scic_sds_controller_general_reset_handler,
3520 .base.start_io = scic_sds_controller_ready_state_start_io_handler,
3521 .base.complete_io = scic_sds_controller_ready_state_complete_io_handler,
3522 .base.continue_io = scic_sds_controller_ready_state_continue_io_handler,
3523 .base.start_task = scic_sds_controller_ready_state_start_task_handler,
3524 .base.complete_task = scic_sds_controller_ready_state_complete_io_handler,
3525 .terminate_request = scic_sds_controller_ready_state_terminate_request_handler,
3526 .link_up = scic_sds_controller_ready_state_link_up_handler,
3527 .link_down = scic_sds_controller_ready_state_link_down_handler
3529 [SCI_BASE_CONTROLLER_STATE_RESETTING] = {
3530 .base.start_io = scic_sds_controller_default_start_operation_handler,
3531 .base.complete_io = scic_sds_controller_default_request_handler,
3532 .base.continue_io = scic_sds_controller_default_request_handler,
3533 .terminate_request = scic_sds_controller_default_request_handler,
3535 [SCI_BASE_CONTROLLER_STATE_STOPPING] = {
3536 .base.start_io = scic_sds_controller_default_start_operation_handler,
3537 .base.complete_io = scic_sds_controller_stopping_state_complete_io_handler,
3538 .base.continue_io = scic_sds_controller_default_request_handler,
3539 .terminate_request = scic_sds_controller_default_request_handler,
3541 [SCI_BASE_CONTROLLER_STATE_STOPPED] = {
3542 .base.reset = scic_sds_controller_general_reset_handler,
3543 .base.start_io = scic_sds_controller_default_start_operation_handler,
3544 .base.complete_io = scic_sds_controller_default_request_handler,
3545 .base.continue_io = scic_sds_controller_default_request_handler,
3546 .terminate_request = scic_sds_controller_default_request_handler,
3548 [SCI_BASE_CONTROLLER_STATE_FAILED] = {
3549 .base.reset = scic_sds_controller_general_reset_handler,
3550 .base.start_io = scic_sds_controller_default_start_operation_handler,
3551 .base.complete_io = scic_sds_controller_default_request_handler,
3552 .base.continue_io = scic_sds_controller_default_request_handler,
3553 .terminate_request = scic_sds_controller_default_request_handler,
3559 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3562 * This method implements the actions taken by the struct scic_sds_controller on entry
3563 * to the SCI_BASE_CONTROLLER_STATE_INITIAL. - Set the state handlers to the
3564 * controllers initial state. none This function should initialze the
3565 * controller object.
3567 static void scic_sds_controller_initial_state_enter(
3568 struct sci_base_object *object)
3570 struct scic_sds_controller *this_controller;
3572 this_controller = (struct scic_sds_controller *)object;
3574 sci_base_state_machine_change_state(
3575 &this_controller->parent.state_machine, SCI_BASE_CONTROLLER_STATE_RESET);
3580 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3583 * This method implements the actions taken by the struct scic_sds_controller on exit
3584 * from the SCI_BASE_CONTROLLER_STATE_STARTING. - This function stops the
3585 * controller starting timeout timer. none
3587 static void scic_sds_controller_starting_state_exit(
3588 struct sci_base_object *object)
3590 struct scic_sds_controller *scic = (struct scic_sds_controller *)object;
3592 isci_event_timer_stop(scic, scic->timeout_timer);
3597 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3600 * This method implements the actions taken by the struct scic_sds_controller on entry
3601 * to the SCI_BASE_CONTROLLER_STATE_READY. - Set the state handlers to the
3602 * controllers ready state. none
3604 static void scic_sds_controller_ready_state_enter(
3605 struct sci_base_object *object)
3607 struct scic_sds_controller *this_controller;
3609 this_controller = (struct scic_sds_controller *)object;
3611 /* set the default interrupt coalescence number and timeout value. */
3612 scic_controller_set_interrupt_coalescence(
3613 this_controller, 0x10, 250);
3618 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3621 * This method implements the actions taken by the struct scic_sds_controller on exit
3622 * from the SCI_BASE_CONTROLLER_STATE_READY. - This function does nothing. none
3624 static void scic_sds_controller_ready_state_exit(
3625 struct sci_base_object *object)
3627 struct scic_sds_controller *this_controller;
3629 this_controller = (struct scic_sds_controller *)object;
3631 /* disable interrupt coalescence. */
3632 scic_controller_set_interrupt_coalescence(this_controller, 0, 0);
3637 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3640 * This method implements the actions taken by the struct scic_sds_controller on entry
3641 * to the SCI_BASE_CONTROLLER_STATE_READY. - Set the state handlers to the
3642 * controllers ready state. - Stop the phys on this controller - Stop the ports
3643 * on this controller - Stop all of the remote devices on this controller none
3645 static void scic_sds_controller_stopping_state_enter(
3646 struct sci_base_object *object)
3648 struct scic_sds_controller *this_controller;
3650 this_controller = (struct scic_sds_controller *)object;
3652 /* Stop all of the components for this controller */
3653 scic_sds_controller_stop_phys(this_controller);
3654 scic_sds_controller_stop_ports(this_controller);
3655 scic_sds_controller_stop_devices(this_controller);
3660 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3663 * This method implements the actions taken by the struct scic_sds_controller on exit
3664 * from the SCI_BASE_CONTROLLER_STATE_STOPPING. - This function stops the
3665 * controller stopping timeout timer. none
3667 static void scic_sds_controller_stopping_state_exit(
3668 struct sci_base_object *object)
3670 struct scic_sds_controller *this_controller;
3672 this_controller = (struct scic_sds_controller *)object;
3674 isci_event_timer_stop(this_controller, this_controller->timeout_timer);
3679 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3682 * This method implements the actions taken by the struct scic_sds_controller on entry
3683 * to the SCI_BASE_CONTROLLER_STATE_RESETTING. - Set the state handlers to the
3684 * controllers resetting state. - Write to the SCU hardware reset register to
3685 * force a reset - Transition to the SCI_BASE_CONTROLLER_STATE_RESET none
3687 static void scic_sds_controller_resetting_state_enter(
3688 struct sci_base_object *object)
3690 struct scic_sds_controller *this_controller;
3692 this_controller = (struct scic_sds_controller *)object;
3694 scic_sds_controller_reset_hardware(this_controller);
3696 sci_base_state_machine_change_state(
3697 scic_sds_controller_get_base_state_machine(this_controller),
3698 SCI_BASE_CONTROLLER_STATE_RESET
3702 /* --------------------------------------------------------------------------- */
3704 const struct sci_base_state scic_sds_controller_state_table[] = {
3705 [SCI_BASE_CONTROLLER_STATE_INITIAL] = {
3706 .enter_state = scic_sds_controller_initial_state_enter,
3708 [SCI_BASE_CONTROLLER_STATE_RESET] = {},
3709 [SCI_BASE_CONTROLLER_STATE_INITIALIZING] = {},
3710 [SCI_BASE_CONTROLLER_STATE_INITIALIZED] = {},
3711 [SCI_BASE_CONTROLLER_STATE_STARTING] = {
3712 .exit_state = scic_sds_controller_starting_state_exit,
3714 [SCI_BASE_CONTROLLER_STATE_READY] = {
3715 .enter_state = scic_sds_controller_ready_state_enter,
3716 .exit_state = scic_sds_controller_ready_state_exit,
3718 [SCI_BASE_CONTROLLER_STATE_RESETTING] = {
3719 .enter_state = scic_sds_controller_resetting_state_enter,
3721 [SCI_BASE_CONTROLLER_STATE_STOPPING] = {
3722 .enter_state = scic_sds_controller_stopping_state_enter,
3723 .exit_state = scic_sds_controller_stopping_state_exit,
3725 [SCI_BASE_CONTROLLER_STATE_STOPPED] = {},
3726 [SCI_BASE_CONTROLLER_STATE_FAILED] = {}