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 enum sci_status 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 if (this_controller->phy_startup_timer == NULL) {
265 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
267 this_controller->next_phy_to_start = 0;
268 this_controller->phy_startup_timer_pending = false;
277 * This method initializes the power control operations for the controller
280 void scic_sds_controller_initialize_power_control(
281 struct scic_sds_controller *this_controller)
283 this_controller->power_control.timer = isci_event_timer_create(
285 scic_sds_controller_power_control_timer_handler,
290 this_controller->power_control.requesters,
292 sizeof(this_controller->power_control.requesters)
295 this_controller->power_control.phys_waiting = 0;
298 /* --------------------------------------------------------------------------- */
300 #define SCU_REMOTE_NODE_CONTEXT_ALIGNMENT (32)
301 #define SCU_TASK_CONTEXT_ALIGNMENT (256)
302 #define SCU_UNSOLICITED_FRAME_ADDRESS_ALIGNMENT (64)
303 #define SCU_UNSOLICITED_FRAME_BUFFER_ALIGNMENT (1024)
304 #define SCU_UNSOLICITED_FRAME_HEADER_ALIGNMENT (64)
306 /* --------------------------------------------------------------------------- */
309 * This method builds the memory descriptor table for this controller.
310 * @this_controller: This parameter specifies the controller object for which
311 * to build the memory table.
314 void scic_sds_controller_build_memory_descriptor_table(
315 struct scic_sds_controller *this_controller)
317 sci_base_mde_construct(
318 &this_controller->memory_descriptors[SCU_MDE_COMPLETION_QUEUE],
319 SCU_COMPLETION_RAM_ALIGNMENT,
320 (sizeof(u32) * this_controller->completion_queue_entries),
321 (SCI_MDE_ATTRIBUTE_CACHEABLE | SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS)
324 sci_base_mde_construct(
325 &this_controller->memory_descriptors[SCU_MDE_REMOTE_NODE_CONTEXT],
326 SCU_REMOTE_NODE_CONTEXT_ALIGNMENT,
327 this_controller->remote_node_entries * sizeof(union scu_remote_node_context),
328 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
331 sci_base_mde_construct(
332 &this_controller->memory_descriptors[SCU_MDE_TASK_CONTEXT],
333 SCU_TASK_CONTEXT_ALIGNMENT,
334 this_controller->task_context_entries * sizeof(struct scu_task_context),
335 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
339 * The UF buffer address table size must be programmed to a power
340 * of 2. Find the first power of 2 that is equal to or greater then
341 * the number of unsolicited frame buffers to be utilized. */
342 scic_sds_unsolicited_frame_control_set_address_table_count(
343 &this_controller->uf_control
346 sci_base_mde_construct(
347 &this_controller->memory_descriptors[SCU_MDE_UF_BUFFER],
348 SCU_UNSOLICITED_FRAME_BUFFER_ALIGNMENT,
349 scic_sds_unsolicited_frame_control_get_mde_size(this_controller->uf_control),
350 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
355 * This method validates the driver supplied memory descriptor table.
360 enum sci_status scic_sds_controller_validate_memory_descriptor_table(
361 struct scic_sds_controller *this_controller)
365 mde_list_valid = sci_base_mde_is_valid(
366 &this_controller->memory_descriptors[SCU_MDE_COMPLETION_QUEUE],
367 SCU_COMPLETION_RAM_ALIGNMENT,
368 (sizeof(u32) * this_controller->completion_queue_entries),
369 (SCI_MDE_ATTRIBUTE_CACHEABLE | SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS)
372 if (mde_list_valid == false)
373 return SCI_FAILURE_UNSUPPORTED_INFORMATION_FIELD;
375 mde_list_valid = sci_base_mde_is_valid(
376 &this_controller->memory_descriptors[SCU_MDE_REMOTE_NODE_CONTEXT],
377 SCU_REMOTE_NODE_CONTEXT_ALIGNMENT,
378 this_controller->remote_node_entries * sizeof(union scu_remote_node_context),
379 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
382 if (mde_list_valid == false)
383 return SCI_FAILURE_UNSUPPORTED_INFORMATION_FIELD;
385 mde_list_valid = sci_base_mde_is_valid(
386 &this_controller->memory_descriptors[SCU_MDE_TASK_CONTEXT],
387 SCU_TASK_CONTEXT_ALIGNMENT,
388 this_controller->task_context_entries * sizeof(struct scu_task_context),
389 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
392 if (mde_list_valid == false)
393 return SCI_FAILURE_UNSUPPORTED_INFORMATION_FIELD;
395 mde_list_valid = sci_base_mde_is_valid(
396 &this_controller->memory_descriptors[SCU_MDE_UF_BUFFER],
397 SCU_UNSOLICITED_FRAME_BUFFER_ALIGNMENT,
398 scic_sds_unsolicited_frame_control_get_mde_size(this_controller->uf_control),
399 SCI_MDE_ATTRIBUTE_PHYSICALLY_CONTIGUOUS
402 if (mde_list_valid == false)
403 return SCI_FAILURE_UNSUPPORTED_INFORMATION_FIELD;
409 * This method initializes the controller with the physical memory addresses
410 * that are used to communicate with the driver.
414 void scic_sds_controller_ram_initialization(
415 struct scic_sds_controller *this_controller)
417 struct sci_physical_memory_descriptor *mde;
420 * The completion queue is actually placed in cacheable memory
421 * Therefore it no longer comes out of memory in the MDL. */
422 mde = &this_controller->memory_descriptors[SCU_MDE_COMPLETION_QUEUE];
423 this_controller->completion_queue = (u32 *)mde->virtual_address;
424 SMU_CQBAR_WRITE(this_controller, mde->physical_address);
427 * Program the location of the Remote Node Context table
429 mde = &this_controller->memory_descriptors[SCU_MDE_REMOTE_NODE_CONTEXT];
430 this_controller->remote_node_context_table = (union scu_remote_node_context *)
431 mde->virtual_address;
432 SMU_RNCBAR_WRITE(this_controller, mde->physical_address);
434 /* Program the location of the Task Context table into the SCU. */
435 mde = &this_controller->memory_descriptors[SCU_MDE_TASK_CONTEXT];
436 this_controller->task_context_table = (struct scu_task_context *)
437 mde->virtual_address;
438 SMU_HTTBAR_WRITE(this_controller, mde->physical_address);
440 mde = &this_controller->memory_descriptors[SCU_MDE_UF_BUFFER];
441 scic_sds_unsolicited_frame_control_construct(
442 &this_controller->uf_control, mde, this_controller
446 * Inform the silicon as to the location of the UF headers and
450 this_controller->uf_control.headers.physical_address);
453 this_controller->uf_control.address_table.physical_address);
457 * This method initializes the task context data for the controller.
461 void scic_sds_controller_assign_task_entries(
462 struct scic_sds_controller *this_controller)
467 * Assign all the TCs to function 0
468 * TODO: Do we actually need to read this register to write it back? */
469 task_assignment = SMU_TCA_READ(this_controller, 0);
474 | (SMU_TCA_GEN_VAL(STARTING, 0))
475 | (SMU_TCA_GEN_VAL(ENDING, this_controller->task_context_entries - 1))
476 | (SMU_TCA_GEN_BIT(RANGE_CHECK_ENABLE))
479 SMU_TCA_WRITE(this_controller, 0, task_assignment);
483 * This method initializes the hardware completion queue.
487 void scic_sds_controller_initialize_completion_queue(
488 struct scic_sds_controller *this_controller)
491 u32 completion_queue_control_value;
492 u32 completion_queue_get_value;
493 u32 completion_queue_put_value;
495 this_controller->completion_queue_get = 0;
497 completion_queue_control_value = (
498 SMU_CQC_QUEUE_LIMIT_SET(this_controller->completion_queue_entries - 1)
499 | SMU_CQC_EVENT_LIMIT_SET(this_controller->completion_event_entries - 1)
502 SMU_CQC_WRITE(this_controller, completion_queue_control_value);
504 /* Set the completion queue get pointer and enable the queue */
505 completion_queue_get_value = (
506 (SMU_CQGR_GEN_VAL(POINTER, 0))
507 | (SMU_CQGR_GEN_VAL(EVENT_POINTER, 0))
508 | (SMU_CQGR_GEN_BIT(ENABLE))
509 | (SMU_CQGR_GEN_BIT(EVENT_ENABLE))
512 SMU_CQGR_WRITE(this_controller, completion_queue_get_value);
514 /* Set the completion queue put pointer */
515 completion_queue_put_value = (
516 (SMU_CQPR_GEN_VAL(POINTER, 0))
517 | (SMU_CQPR_GEN_VAL(EVENT_POINTER, 0))
520 SMU_CQPR_WRITE(this_controller, completion_queue_put_value);
522 /* Initialize the cycle bit of the completion queue entries */
523 for (index = 0; index < this_controller->completion_queue_entries; index++) {
525 * If get.cycle_bit != completion_queue.cycle_bit
526 * its not a valid completion queue entry
527 * so at system start all entries are invalid */
528 this_controller->completion_queue[index] = 0x80000000;
533 * This method initializes the hardware unsolicited frame queue.
537 void scic_sds_controller_initialize_unsolicited_frame_queue(
538 struct scic_sds_controller *this_controller)
540 u32 frame_queue_control_value;
541 u32 frame_queue_get_value;
542 u32 frame_queue_put_value;
544 /* Write the queue size */
545 frame_queue_control_value =
546 SCU_UFQC_GEN_VAL(QUEUE_SIZE, this_controller->uf_control.address_table.count);
548 SCU_UFQC_WRITE(this_controller, frame_queue_control_value);
550 /* Setup the get pointer for the unsolicited frame queue */
551 frame_queue_get_value = (
552 SCU_UFQGP_GEN_VAL(POINTER, 0)
553 | SCU_UFQGP_GEN_BIT(ENABLE_BIT)
556 SCU_UFQGP_WRITE(this_controller, frame_queue_get_value);
558 /* Setup the put pointer for the unsolicited frame queue */
559 frame_queue_put_value = SCU_UFQPP_GEN_VAL(POINTER, 0);
561 SCU_UFQPP_WRITE(this_controller, frame_queue_put_value);
565 * This method enables the hardware port task scheduler.
569 void scic_sds_controller_enable_port_task_scheduler(
570 struct scic_sds_controller *this_controller)
572 u32 port_task_scheduler_value;
574 port_task_scheduler_value = SCU_PTSGCR_READ(this_controller);
576 port_task_scheduler_value |=
577 (SCU_PTSGCR_GEN_BIT(ETM_ENABLE) | SCU_PTSGCR_GEN_BIT(PTSG_ENABLE));
579 SCU_PTSGCR_WRITE(this_controller, port_task_scheduler_value);
582 /* --------------------------------------------------------------------------- */
587 * This macro is used to delay between writes to the AFE registers during AFE
590 #define AFE_REGISTER_WRITE_DELAY 10
592 /* Initialize the AFE for this phy index. We need to read the AFE setup from
593 * the OEM parameters none
595 void scic_sds_controller_afe_initialization(struct scic_sds_controller *scic)
600 /* Clear DFX Status registers */
601 scu_afe_register_write(scic, afe_dfx_master_control0, 0x0081000f);
602 udelay(AFE_REGISTER_WRITE_DELAY);
604 /* Configure bias currents to normal */
606 scu_afe_register_write(scic, afe_bias_control, 0x00005500);
608 scu_afe_register_write(scic, afe_bias_control, 0x00005A00);
610 udelay(AFE_REGISTER_WRITE_DELAY);
614 scu_afe_register_write(scic, afe_pll_control0, 0x80040A08);
616 scu_afe_register_write(scic, afe_pll_control0, 0x80040908);
618 udelay(AFE_REGISTER_WRITE_DELAY);
620 /* Wait for the PLL to lock */
622 afe_status = scu_afe_register_read(
623 scic, afe_common_block_status);
624 udelay(AFE_REGISTER_WRITE_DELAY);
625 } while ((afe_status & 0x00001000) == 0);
628 /* Shorten SAS SNW lock time (RxLock timer value from 76 us to 50 us) */
629 scu_afe_register_write(scic, afe_pmsn_master_control0, 0x7bcc96ad);
630 udelay(AFE_REGISTER_WRITE_DELAY);
633 for (phy_id = 0; phy_id < SCI_MAX_PHYS; phy_id++) {
635 /* Configure transmitter SSC parameters */
636 scu_afe_txreg_write(scic, phy_id, afe_tx_ssc_control, 0x00030000);
637 udelay(AFE_REGISTER_WRITE_DELAY);
640 * All defaults, except the Receive Word Alignament/Comma Detect
641 * Enable....(0xe800) */
642 scu_afe_txreg_write(scic, phy_id, afe_xcvr_control0, 0x00004512);
643 udelay(AFE_REGISTER_WRITE_DELAY);
645 scu_afe_txreg_write(scic, phy_id, afe_xcvr_control1, 0x0050100F);
646 udelay(AFE_REGISTER_WRITE_DELAY);
650 * Power up TX and RX out from power down (PWRDNTX and PWRDNRX)
651 * & increase TX int & ext bias 20%....(0xe85c) */
653 scu_afe_txreg_write(scic, phy_id, afe_channel_control, 0x000003D4);
655 scu_afe_txreg_write(scic, phy_id, afe_channel_control, 0x000003F0);
657 /* Power down TX and RX (PWRDNTX and PWRDNRX) */
658 scu_afe_txreg_write(scic, phy_id, afe_channel_control, 0x000003d7);
659 udelay(AFE_REGISTER_WRITE_DELAY);
662 * Power up TX and RX out from power down (PWRDNTX and PWRDNRX)
663 * & increase TX int & ext bias 20%....(0xe85c) */
664 scu_afe_txreg_write(scic, phy_id, afe_channel_control, 0x000003d4);
666 udelay(AFE_REGISTER_WRITE_DELAY);
668 if (is_a0() || is_a2()) {
669 /* Enable TX equalization (0xe824) */
670 scu_afe_txreg_write(scic, phy_id, afe_tx_control, 0x00040000);
671 udelay(AFE_REGISTER_WRITE_DELAY);
675 * RDPI=0x0(RX Power On), RXOOBDETPDNC=0x0, TPD=0x0(TX Power On),
676 * RDD=0x0(RX Detect Enabled) ....(0xe800) */
677 scu_afe_txreg_write(scic, phy_id, afe_xcvr_control0, 0x00004100);
678 udelay(AFE_REGISTER_WRITE_DELAY);
680 /* Leave DFE/FFE on */
682 scu_afe_txreg_write(scic, phy_id, afe_rx_ssc_control0, 0x3F09983F);
684 scu_afe_txreg_write(scic, phy_id, afe_rx_ssc_control0, 0x3F11103F);
686 scu_afe_txreg_write(scic, phy_id, afe_rx_ssc_control0, 0x3F11103F);
687 udelay(AFE_REGISTER_WRITE_DELAY);
688 /* Enable TX equalization (0xe824) */
689 scu_afe_txreg_write(scic, phy_id, afe_tx_control, 0x00040000);
691 udelay(AFE_REGISTER_WRITE_DELAY);
693 scu_afe_txreg_write(scic, phy_id, afe_tx_amp_control0, 0x000E7C03);
694 udelay(AFE_REGISTER_WRITE_DELAY);
696 scu_afe_txreg_write(scic, phy_id, afe_tx_amp_control1, 0x000E7C03);
697 udelay(AFE_REGISTER_WRITE_DELAY);
699 scu_afe_txreg_write(scic, phy_id, afe_tx_amp_control2, 0x000E7C03);
700 udelay(AFE_REGISTER_WRITE_DELAY);
702 scu_afe_txreg_write(scic, phy_id, afe_tx_amp_control3, 0x000E7C03);
703 udelay(AFE_REGISTER_WRITE_DELAY);
706 /* Transfer control to the PEs */
707 scu_afe_register_write(scic, afe_dfx_master_control0, 0x00010f00);
708 udelay(AFE_REGISTER_WRITE_DELAY);
712 * ****************************************************************************-
713 * * SCIC SDS Controller Internal Start/Stop Routines
714 * ****************************************************************************- */
718 * This method will attempt to transition into the ready state for the
719 * controller and indicate that the controller start operation has completed
720 * if all criteria are met.
721 * @this_controller: This parameter indicates the controller object for which
722 * to transition to ready.
723 * @status: This parameter indicates the status value to be pass into the call
724 * to scic_cb_controller_start_complete().
728 static void scic_sds_controller_transition_to_ready(
729 struct scic_sds_controller *this_controller,
730 enum sci_status status)
732 if (this_controller->parent.state_machine.current_state_id
733 == SCI_BASE_CONTROLLER_STATE_STARTING) {
735 * We move into the ready state, because some of the phys/ports
736 * may be up and operational. */
737 sci_base_state_machine_change_state(
738 scic_sds_controller_get_base_state_machine(this_controller),
739 SCI_BASE_CONTROLLER_STATE_READY
742 isci_event_controller_start_complete(this_controller, status);
747 * This method is the general timeout handler for the controller. It will take
748 * the correct timetout action based on the current controller state
750 void scic_sds_controller_timeout_handler(
751 struct scic_sds_controller *scic)
753 enum sci_base_controller_states current_state;
755 current_state = sci_base_state_machine_get_state(
756 scic_sds_controller_get_base_state_machine(scic));
758 if (current_state == SCI_BASE_CONTROLLER_STATE_STARTING) {
759 scic_sds_controller_transition_to_ready(
760 scic, SCI_FAILURE_TIMEOUT);
761 } else if (current_state == SCI_BASE_CONTROLLER_STATE_STOPPING) {
762 sci_base_state_machine_change_state(
763 scic_sds_controller_get_base_state_machine(scic),
764 SCI_BASE_CONTROLLER_STATE_FAILED);
765 isci_event_controller_stop_complete(scic, SCI_FAILURE_TIMEOUT);
766 } else /* / @todo Now what do we want to do in this case? */
767 dev_err(scic_to_dev(scic),
768 "%s: Controller timer fired when controller was not "
769 "in a state being timed.\n",
774 * scic_sds_controller_get_port_configuration_mode
775 * @this_controller: This is the controller to use to determine if we are using
776 * manual or automatic port configuration.
778 * SCIC_PORT_CONFIGURATION_MODE
780 enum SCIC_PORT_CONFIGURATION_MODE scic_sds_controller_get_port_configuration_mode(
781 struct scic_sds_controller *this_controller)
784 enum SCIC_PORT_CONFIGURATION_MODE mode;
786 mode = SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE;
788 for (index = 0; index < SCI_MAX_PORTS; index++) {
789 if (this_controller->oem_parameters.sds1.ports[index].phy_mask != 0) {
790 mode = SCIC_PORT_MANUAL_CONFIGURATION_MODE;
798 enum sci_status scic_sds_controller_stop_ports(struct scic_sds_controller *scic)
801 enum sci_status port_status;
802 enum sci_status status = SCI_SUCCESS;
804 for (index = 0; index < scic->logical_port_entries; index++) {
805 struct scic_sds_port *sci_port = &scic->port_table[index];
806 SCI_BASE_PORT_HANDLER_T stop;
808 stop = sci_port->state_handlers->parent.stop_handler;
809 port_status = stop(&sci_port->parent);
811 if ((port_status != SCI_SUCCESS) &&
812 (port_status != SCI_FAILURE_INVALID_STATE)) {
813 status = SCI_FAILURE;
815 dev_warn(scic_to_dev(scic),
816 "%s: Controller stop operation failed to "
817 "stop port %d because of status %d.\n",
819 sci_port->logical_port_index,
832 static void scic_sds_controller_phy_timer_start(
833 struct scic_sds_controller *this_controller)
835 isci_event_timer_start(
837 this_controller->phy_startup_timer,
838 SCIC_SDS_CONTROLLER_PHY_START_TIMEOUT
841 this_controller->phy_startup_timer_pending = true;
849 void scic_sds_controller_phy_timer_stop(
850 struct scic_sds_controller *this_controller)
852 isci_event_timer_stop(
854 this_controller->phy_startup_timer
857 this_controller->phy_startup_timer_pending = false;
861 * This method is called internally by the controller object to start the next
862 * phy on the controller. If all the phys have been starte, then this
863 * method will attempt to transition the controller to the READY state and
864 * inform the user (scic_cb_controller_start_complete()).
865 * @this_controller: This parameter specifies the controller object for which
866 * to start the next phy.
870 enum sci_status scic_sds_controller_start_next_phy(
871 struct scic_sds_controller *this_controller)
873 enum sci_status status;
875 status = SCI_SUCCESS;
877 if (this_controller->phy_startup_timer_pending == false) {
878 if (this_controller->next_phy_to_start == SCI_MAX_PHYS) {
879 bool is_controller_start_complete = true;
880 struct scic_sds_phy *the_phy;
883 for (index = 0; index < SCI_MAX_PHYS; index++) {
884 the_phy = &this_controller->phy_table[index];
886 if (scic_sds_phy_get_port(the_phy) != NULL) {
888 * The controller start operation is complete if and only
890 * - all links have been given an opportunity to start
891 * - have no indication of a connected device
892 * - have an indication of a connected device and it has
893 * finished the link training process.
897 (the_phy->is_in_link_training == false)
898 && (the_phy->parent.state_machine.current_state_id
899 == SCI_BASE_PHY_STATE_INITIAL)
902 (the_phy->is_in_link_training == false)
903 && (the_phy->parent.state_machine.current_state_id
904 == SCI_BASE_PHY_STATE_STOPPED)
907 (the_phy->is_in_link_training == true)
908 && (the_phy->parent.state_machine.current_state_id
909 == SCI_BASE_PHY_STATE_STARTING)
912 is_controller_start_complete = false;
919 * The controller has successfully finished the start process.
920 * Inform the SCI Core user and transition to the READY state. */
921 if (is_controller_start_complete == true) {
922 scic_sds_controller_transition_to_ready(
923 this_controller, SCI_SUCCESS
925 scic_sds_controller_phy_timer_stop(this_controller);
928 struct scic_sds_phy *the_phy;
930 the_phy = &this_controller->phy_table[this_controller->next_phy_to_start];
933 scic_sds_controller_get_port_configuration_mode(this_controller)
934 == SCIC_PORT_MANUAL_CONFIGURATION_MODE
936 if (scic_sds_phy_get_port(the_phy) == NULL) {
937 this_controller->next_phy_to_start++;
940 * Caution recursion ahead be forwarned
942 * The PHY was never added to a PORT in MPC mode so start the next phy in sequence
943 * This phy will never go link up and will not draw power the OEM parameters either
944 * configured the phy incorrectly for the PORT or it was never assigned to a PORT */
945 return scic_sds_controller_start_next_phy(this_controller);
949 status = scic_sds_phy_start(the_phy);
951 if (status == SCI_SUCCESS) {
952 scic_sds_controller_phy_timer_start(this_controller);
954 dev_warn(scic_to_dev(this_controller),
955 "%s: Controller stop operation failed "
956 "to stop phy %d because of status "
959 this_controller->phy_table[this_controller->next_phy_to_start].phy_index,
963 this_controller->next_phy_to_start++;
976 enum sci_status scic_sds_controller_stop_phys(
977 struct scic_sds_controller *this_controller)
980 enum sci_status status;
981 enum sci_status phy_status;
983 status = SCI_SUCCESS;
985 for (index = 0; index < SCI_MAX_PHYS; index++) {
986 phy_status = scic_sds_phy_stop(&this_controller->phy_table[index]);
989 (phy_status != SCI_SUCCESS)
990 && (phy_status != SCI_FAILURE_INVALID_STATE)
992 status = SCI_FAILURE;
994 dev_warn(scic_to_dev(this_controller),
995 "%s: Controller stop operation failed to stop "
996 "phy %d because of status %d.\n",
998 this_controller->phy_table[index].phy_index, phy_status);
1011 enum sci_status scic_sds_controller_stop_devices(
1012 struct scic_sds_controller *this_controller)
1015 enum sci_status status;
1016 enum sci_status device_status;
1018 status = SCI_SUCCESS;
1020 for (index = 0; index < this_controller->remote_node_entries; index++) {
1021 if (this_controller->device_table[index] != NULL) {
1022 /* / @todo What timeout value do we want to provide to this request? */
1023 device_status = scic_remote_device_stop(this_controller->device_table[index], 0);
1025 if ((device_status != SCI_SUCCESS) &&
1026 (device_status != SCI_FAILURE_INVALID_STATE)) {
1027 dev_warn(scic_to_dev(this_controller),
1028 "%s: Controller stop operation failed "
1029 "to stop device 0x%p because of "
1032 this_controller->device_table[index], device_status);
1041 * ****************************************************************************-
1042 * * SCIC SDS Controller Power Control (Staggered Spinup)
1043 * ****************************************************************************- */
1048 * This method starts the power control timer for this controller object.
1050 static void scic_sds_controller_power_control_timer_start(
1051 struct scic_sds_controller *this_controller)
1053 isci_event_timer_start(
1054 this_controller, this_controller->power_control.timer,
1055 SCIC_SDS_CONTROLLER_POWER_CONTROL_INTERVAL
1058 this_controller->power_control.timer_started = true;
1066 static void scic_sds_controller_power_control_timer_handler(
1069 struct scic_sds_controller *this_controller;
1071 this_controller = (struct scic_sds_controller *)controller;
1073 if (this_controller->power_control.phys_waiting == 0) {
1074 this_controller->power_control.timer_started = false;
1076 struct scic_sds_phy *the_phy = NULL;
1081 && (this_controller->power_control.phys_waiting != 0);
1083 if (this_controller->power_control.requesters[i] != NULL) {
1084 the_phy = this_controller->power_control.requesters[i];
1085 this_controller->power_control.requesters[i] = NULL;
1086 this_controller->power_control.phys_waiting--;
1092 * It doesn't matter if the power list is empty, we need to start the
1093 * timer in case another phy becomes ready. */
1094 scic_sds_controller_power_control_timer_start(this_controller);
1096 scic_sds_phy_consume_power_handler(the_phy);
1101 * This method inserts the phy in the stagger spinup control queue.
1106 void scic_sds_controller_power_control_queue_insert(
1107 struct scic_sds_controller *this_controller,
1108 struct scic_sds_phy *the_phy)
1110 BUG_ON(the_phy == NULL);
1113 (this_controller->power_control.timer_started)
1114 && (this_controller->power_control.requesters[the_phy->phy_index] == NULL)
1116 this_controller->power_control.requesters[the_phy->phy_index] = the_phy;
1117 this_controller->power_control.phys_waiting++;
1119 scic_sds_controller_power_control_timer_start(this_controller);
1120 scic_sds_phy_consume_power_handler(the_phy);
1125 * This method removes the phy from the stagger spinup control queue.
1130 void scic_sds_controller_power_control_queue_remove(
1131 struct scic_sds_controller *this_controller,
1132 struct scic_sds_phy *the_phy)
1134 BUG_ON(the_phy == NULL);
1136 if (this_controller->power_control.requesters[the_phy->phy_index] != NULL) {
1137 this_controller->power_control.phys_waiting--;
1140 this_controller->power_control.requesters[the_phy->phy_index] = NULL;
1144 * ****************************************************************************-
1145 * * SCIC SDS Controller Completion Routines
1146 * ****************************************************************************- */
1149 * This method returns a true value if the completion queue has entries that
1153 * bool true if the completion queue has entries to process false if the
1154 * completion queue has no entries to process
1156 static bool scic_sds_controller_completion_queue_has_entries(
1157 struct scic_sds_controller *this_controller)
1159 u32 get_value = this_controller->completion_queue_get;
1160 u32 get_index = get_value & SMU_COMPLETION_QUEUE_GET_POINTER_MASK;
1163 NORMALIZE_GET_POINTER_CYCLE_BIT(get_value)
1164 == COMPLETION_QUEUE_CYCLE_BIT(this_controller->completion_queue[get_index])
1172 /* --------------------------------------------------------------------------- */
1175 * This method processes a task completion notification. This is called from
1176 * within the controller completion handler.
1178 * @completion_entry:
1181 static void scic_sds_controller_task_completion(
1182 struct scic_sds_controller *this_controller,
1183 u32 completion_entry)
1186 struct scic_sds_request *io_request;
1188 index = SCU_GET_COMPLETION_INDEX(completion_entry);
1189 io_request = this_controller->io_request_table[index];
1191 /* Make sure that we really want to process this IO request */
1193 (io_request != NULL)
1194 && (io_request->io_tag != SCI_CONTROLLER_INVALID_IO_TAG)
1196 scic_sds_io_tag_get_sequence(io_request->io_tag)
1197 == this_controller->io_request_sequence[index]
1200 /* Yep this is a valid io request pass it along to the io request handler */
1201 scic_sds_io_request_tc_completion(io_request, completion_entry);
1206 * This method processes an SDMA completion event. This is called from within
1207 * the controller completion handler.
1209 * @completion_entry:
1212 static void scic_sds_controller_sdma_completion(
1213 struct scic_sds_controller *this_controller,
1214 u32 completion_entry)
1217 struct scic_sds_request *io_request;
1218 struct scic_sds_remote_device *device;
1220 index = SCU_GET_COMPLETION_INDEX(completion_entry);
1222 switch (scu_get_command_request_type(completion_entry)) {
1223 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC:
1224 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_DUMP_TC:
1225 io_request = this_controller->io_request_table[index];
1226 dev_warn(scic_to_dev(this_controller),
1227 "%s: SCIC SDS Completion type SDMA %x for io request "
1232 /* @todo For a post TC operation we need to fail the IO
1237 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_DUMP_RNC:
1238 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_OTHER_RNC:
1239 case SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_RNC:
1240 device = this_controller->device_table[index];
1241 dev_warn(scic_to_dev(this_controller),
1242 "%s: SCIC SDS Completion type SDMA %x for remote "
1247 /* @todo For a port RNC operation we need to fail the
1253 dev_warn(scic_to_dev(this_controller),
1254 "%s: SCIC SDS Completion unknown SDMA completion "
1266 * @completion_entry:
1268 * This method processes an unsolicited frame message. This is called from
1269 * within the controller completion handler. none
1271 static void scic_sds_controller_unsolicited_frame(
1272 struct scic_sds_controller *this_controller,
1273 u32 completion_entry)
1278 struct scu_unsolicited_frame_header *frame_header;
1279 struct scic_sds_phy *phy;
1280 struct scic_sds_remote_device *device;
1282 enum sci_status result = SCI_FAILURE;
1284 frame_index = SCU_GET_FRAME_INDEX(completion_entry);
1287 = this_controller->uf_control.buffers.array[frame_index].header;
1288 this_controller->uf_control.buffers.array[frame_index].state
1289 = UNSOLICITED_FRAME_IN_USE;
1291 if (SCU_GET_FRAME_ERROR(completion_entry)) {
1293 * / @todo If the IAF frame or SIGNATURE FIS frame has an error will
1294 * / this cause a problem? We expect the phy initialization will
1295 * / fail if there is an error in the frame. */
1296 scic_sds_controller_release_frame(this_controller, frame_index);
1300 if (frame_header->is_address_frame) {
1301 index = SCU_GET_PROTOCOL_ENGINE_INDEX(completion_entry);
1302 phy = &this_controller->phy_table[index];
1304 result = scic_sds_phy_frame_handler(phy, frame_index);
1308 index = SCU_GET_COMPLETION_INDEX(completion_entry);
1310 if (index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX) {
1312 * This is a signature fis or a frame from a direct attached SATA
1313 * device that has not yet been created. In either case forwared
1314 * the frame to the PE and let it take care of the frame data. */
1315 index = SCU_GET_PROTOCOL_ENGINE_INDEX(completion_entry);
1316 phy = &this_controller->phy_table[index];
1317 result = scic_sds_phy_frame_handler(phy, frame_index);
1319 if (index < this_controller->remote_node_entries)
1320 device = this_controller->device_table[index];
1325 result = scic_sds_remote_device_frame_handler(device, frame_index);
1327 scic_sds_controller_release_frame(this_controller, frame_index);
1331 if (result != SCI_SUCCESS) {
1333 * / @todo Is there any reason to report some additional error message
1334 * / when we get this failure notifiction? */
1339 * This method processes an event completion entry. This is called from within
1340 * the controller completion handler.
1342 * @completion_entry:
1345 static void scic_sds_controller_event_completion(
1346 struct scic_sds_controller *this_controller,
1347 u32 completion_entry)
1350 struct scic_sds_request *io_request;
1351 struct scic_sds_remote_device *device;
1352 struct scic_sds_phy *phy;
1354 index = SCU_GET_COMPLETION_INDEX(completion_entry);
1356 switch (scu_get_event_type(completion_entry)) {
1357 case SCU_EVENT_TYPE_SMU_COMMAND_ERROR:
1358 /* / @todo The driver did something wrong and we need to fix the condtion. */
1359 dev_err(scic_to_dev(this_controller),
1360 "%s: SCIC Controller 0x%p received SMU command error "
1367 case SCU_EVENT_TYPE_SMU_PCQ_ERROR:
1368 case SCU_EVENT_TYPE_SMU_ERROR:
1369 case SCU_EVENT_TYPE_FATAL_MEMORY_ERROR:
1371 * / @todo This is a hardware failure and its likely that we want to
1372 * / reset the controller. */
1373 dev_err(scic_to_dev(this_controller),
1374 "%s: SCIC Controller 0x%p received fatal controller "
1381 case SCU_EVENT_TYPE_TRANSPORT_ERROR:
1382 io_request = this_controller->io_request_table[index];
1383 scic_sds_io_request_event_handler(io_request, completion_entry);
1386 case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT:
1387 switch (scu_get_event_specifier(completion_entry)) {
1388 case SCU_EVENT_SPECIFIC_SMP_RESPONSE_NO_PE:
1389 case SCU_EVENT_SPECIFIC_TASK_TIMEOUT:
1390 io_request = this_controller->io_request_table[index];
1391 if (io_request != NULL)
1392 scic_sds_io_request_event_handler(io_request, completion_entry);
1394 dev_warn(scic_to_dev(this_controller),
1395 "%s: SCIC Controller 0x%p received "
1396 "event 0x%x for io request object "
1397 "that doesnt exist.\n",
1404 case SCU_EVENT_SPECIFIC_IT_NEXUS_TIMEOUT:
1405 device = this_controller->device_table[index];
1407 scic_sds_remote_device_event_handler(device, completion_entry);
1409 dev_warn(scic_to_dev(this_controller),
1410 "%s: SCIC Controller 0x%p received "
1411 "event 0x%x for remote device object "
1412 "that doesnt exist.\n",
1421 case SCU_EVENT_TYPE_BROADCAST_CHANGE:
1423 * direct the broadcast change event to the phy first and then let
1424 * the phy redirect the broadcast change to the port object */
1425 case SCU_EVENT_TYPE_ERR_CNT_EVENT:
1427 * direct error counter event to the phy object since that is where
1428 * we get the event notification. This is a type 4 event. */
1429 case SCU_EVENT_TYPE_OSSP_EVENT:
1430 index = SCU_GET_PROTOCOL_ENGINE_INDEX(completion_entry);
1431 phy = &this_controller->phy_table[index];
1432 scic_sds_phy_event_handler(phy, completion_entry);
1435 case SCU_EVENT_TYPE_RNC_SUSPEND_TX:
1436 case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX:
1437 case SCU_EVENT_TYPE_RNC_OPS_MISC:
1438 if (index < this_controller->remote_node_entries) {
1439 device = this_controller->device_table[index];
1442 scic_sds_remote_device_event_handler(device, completion_entry);
1444 dev_err(scic_to_dev(this_controller),
1445 "%s: SCIC Controller 0x%p received event 0x%x "
1446 "for remote device object 0x%0x that doesnt "
1456 dev_warn(scic_to_dev(this_controller),
1457 "%s: SCIC Controller received unknown event code %x\n",
1465 * This method is a private routine for processing the completion queue entries.
1469 static void scic_sds_controller_process_completions(
1470 struct scic_sds_controller *this_controller)
1472 u32 completion_count = 0;
1473 u32 completion_entry;
1479 dev_dbg(scic_to_dev(this_controller),
1480 "%s: completion queue begining get:0x%08x\n",
1482 this_controller->completion_queue_get);
1484 /* Get the component parts of the completion queue */
1485 get_index = NORMALIZE_GET_POINTER(this_controller->completion_queue_get);
1486 get_cycle = SMU_CQGR_CYCLE_BIT & this_controller->completion_queue_get;
1488 event_index = NORMALIZE_EVENT_POINTER(this_controller->completion_queue_get);
1489 event_cycle = SMU_CQGR_EVENT_CYCLE_BIT & this_controller->completion_queue_get;
1492 NORMALIZE_GET_POINTER_CYCLE_BIT(get_cycle)
1493 == COMPLETION_QUEUE_CYCLE_BIT(this_controller->completion_queue[get_index])
1497 completion_entry = this_controller->completion_queue[get_index];
1498 INCREMENT_COMPLETION_QUEUE_GET(this_controller, get_index, get_cycle);
1500 dev_dbg(scic_to_dev(this_controller),
1501 "%s: completion queue entry:0x%08x\n",
1505 switch (SCU_GET_COMPLETION_TYPE(completion_entry)) {
1506 case SCU_COMPLETION_TYPE_TASK:
1507 scic_sds_controller_task_completion(this_controller, completion_entry);
1510 case SCU_COMPLETION_TYPE_SDMA:
1511 scic_sds_controller_sdma_completion(this_controller, completion_entry);
1514 case SCU_COMPLETION_TYPE_UFI:
1515 scic_sds_controller_unsolicited_frame(this_controller, completion_entry);
1518 case SCU_COMPLETION_TYPE_EVENT:
1519 INCREMENT_EVENT_QUEUE_GET(this_controller, event_index, event_cycle);
1520 scic_sds_controller_event_completion(this_controller, completion_entry);
1523 case SCU_COMPLETION_TYPE_NOTIFY:
1525 * Presently we do the same thing with a notify event that we do with the
1526 * other event codes. */
1527 INCREMENT_EVENT_QUEUE_GET(this_controller, event_index, event_cycle);
1528 scic_sds_controller_event_completion(this_controller, completion_entry);
1532 dev_warn(scic_to_dev(this_controller),
1533 "%s: SCIC Controller received unknown "
1534 "completion type %x\n",
1541 /* Update the get register if we completed one or more entries */
1542 if (completion_count > 0) {
1543 this_controller->completion_queue_get =
1544 SMU_CQGR_GEN_BIT(ENABLE)
1545 | SMU_CQGR_GEN_BIT(EVENT_ENABLE)
1546 | event_cycle | SMU_CQGR_GEN_VAL(EVENT_POINTER, event_index)
1547 | get_cycle | SMU_CQGR_GEN_VAL(POINTER, get_index);
1549 SMU_CQGR_WRITE(this_controller,
1550 this_controller->completion_queue_get);
1553 dev_dbg(scic_to_dev(this_controller),
1554 "%s: completion queue ending get:0x%08x\n",
1556 this_controller->completion_queue_get);
1560 bool scic_sds_controller_isr(struct scic_sds_controller *scic)
1562 if (scic_sds_controller_completion_queue_has_entries(scic)) {
1566 * we have a spurious interrupt it could be that we have already
1567 * emptied the completion queue from a previous interrupt */
1568 SMU_ISR_WRITE(scic, SMU_ISR_COMPLETION);
1571 * There is a race in the hardware that could cause us not to be notified
1572 * of an interrupt completion if we do not take this step. We will mask
1573 * then unmask the interrupts so if there is another interrupt pending
1574 * the clearing of the interrupt source we get the next interrupt message. */
1575 SMU_IMR_WRITE(scic, 0xFF000000);
1576 SMU_IMR_WRITE(scic, 0x00000000);
1582 void scic_sds_controller_completion_handler(struct scic_sds_controller *scic)
1584 /* Empty out the completion queue */
1585 if (scic_sds_controller_completion_queue_has_entries(scic))
1586 scic_sds_controller_process_completions(scic);
1588 /* Clear the interrupt and enable all interrupts again */
1589 SMU_ISR_WRITE(scic, SMU_ISR_COMPLETION);
1590 /* Could we write the value of SMU_ISR_COMPLETION? */
1591 SMU_IMR_WRITE(scic, 0xFF000000);
1592 SMU_IMR_WRITE(scic, 0x00000000);
1595 bool scic_sds_controller_error_isr(struct scic_sds_controller *scic)
1597 u32 interrupt_status;
1599 interrupt_status = SMU_ISR_READ(scic);
1601 interrupt_status &= (SMU_ISR_QUEUE_ERROR | SMU_ISR_QUEUE_SUSPEND);
1603 if (interrupt_status != 0) {
1605 * There is an error interrupt pending so let it through and handle
1606 * in the callback */
1611 * There is a race in the hardware that could cause us not to be notified
1612 * of an interrupt completion if we do not take this step. We will mask
1613 * then unmask the error interrupts so if there was another interrupt
1614 * pending we will be notified.
1615 * Could we write the value of (SMU_ISR_QUEUE_ERROR | SMU_ISR_QUEUE_SUSPEND)? */
1616 SMU_IMR_WRITE(scic, 0x000000FF);
1617 SMU_IMR_WRITE(scic, 0x00000000);
1622 void scic_sds_controller_error_handler(struct scic_sds_controller *scic)
1624 u32 interrupt_status;
1626 interrupt_status = SMU_ISR_READ(scic);
1628 if ((interrupt_status & SMU_ISR_QUEUE_SUSPEND) &&
1629 scic_sds_controller_completion_queue_has_entries(scic)) {
1631 scic_sds_controller_process_completions(scic);
1632 SMU_ISR_WRITE(scic, SMU_ISR_QUEUE_SUSPEND);
1635 dev_err(scic_to_dev(scic), "%s: status: %#x\n", __func__,
1638 sci_base_state_machine_change_state(
1639 scic_sds_controller_get_base_state_machine(scic),
1640 SCI_BASE_CONTROLLER_STATE_FAILED);
1646 * If we dont process any completions I am not sure that we want to do this.
1647 * We are in the middle of a hardware fault and should probably be reset. */
1648 SMU_IMR_WRITE(scic, 0x00000000);
1652 u32 scic_sds_controller_get_object_size(void)
1654 return sizeof(struct scic_sds_controller);
1658 void scic_sds_controller_link_up(
1659 struct scic_sds_controller *scic,
1660 struct scic_sds_port *sci_port,
1661 struct scic_sds_phy *sci_phy)
1663 scic_sds_controller_phy_handler_t link_up;
1666 state = scic->parent.state_machine.current_state_id;
1667 link_up = scic_sds_controller_state_handler_table[state].link_up;
1670 link_up(scic, sci_port, sci_phy);
1672 dev_dbg(scic_to_dev(scic),
1673 "%s: SCIC Controller linkup event from phy %d in "
1674 "unexpected state %d\n",
1677 sci_base_state_machine_get_state(
1678 scic_sds_controller_get_base_state_machine(
1683 void scic_sds_controller_link_down(
1684 struct scic_sds_controller *scic,
1685 struct scic_sds_port *sci_port,
1686 struct scic_sds_phy *sci_phy)
1689 scic_sds_controller_phy_handler_t link_down;
1691 state = scic->parent.state_machine.current_state_id;
1692 link_down = scic_sds_controller_state_handler_table[state].link_down;
1695 link_down(scic, sci_port, sci_phy);
1697 dev_dbg(scic_to_dev(scic),
1698 "%s: SCIC Controller linkdown event from phy %d in "
1699 "unexpected state %d\n",
1701 sci_phy->phy_index, state);
1705 * This method is called by the remote device to inform the controller
1706 * that this remote device has started.
1710 void scic_sds_controller_remote_device_started(struct scic_sds_controller *scic,
1711 struct scic_sds_remote_device *sci_dev)
1714 scic_sds_controller_device_handler_t started;
1716 state = scic->parent.state_machine.current_state_id;
1717 started = scic_sds_controller_state_handler_table[state].remote_device_started_handler;
1720 started(scic, sci_dev);
1722 dev_dbg(scic_to_dev(scic),
1723 "%s: SCIC Controller 0x%p remote device started event "
1724 "from device 0x%p in unexpected state %d\n",
1725 __func__, scic, sci_dev, state);
1730 * This is a helper method to determine if any remote devices on this
1731 * controller are still in the stopping state.
1734 bool scic_sds_controller_has_remote_devices_stopping(
1735 struct scic_sds_controller *this_controller)
1739 for (index = 0; index < this_controller->remote_node_entries; index++) {
1740 if ((this_controller->device_table[index] != NULL) &&
1741 (this_controller->device_table[index]->parent.state_machine.current_state_id
1742 == SCI_BASE_REMOTE_DEVICE_STATE_STOPPING))
1750 * This method is called by the remote device to inform the controller
1751 * object that the remote device has stopped.
1755 void scic_sds_controller_remote_device_stopped(struct scic_sds_controller *scic,
1756 struct scic_sds_remote_device *sci_dev)
1760 scic_sds_controller_device_handler_t stopped;
1762 state = scic->parent.state_machine.current_state_id;
1763 stopped = scic_sds_controller_state_handler_table[state].remote_device_stopped_handler;
1766 stopped(scic, sci_dev);
1768 dev_dbg(scic_to_dev(scic),
1769 "%s: SCIC Controller 0x%p remote device stopped event "
1770 "from device 0x%p in unexpected state %d\n",
1771 __func__, scic, sci_dev, state);
1778 * This method will write to the SCU PCP register the request value. The method
1779 * is used to suspend/resume ports, devices, and phys.
1784 void scic_sds_controller_post_request(
1785 struct scic_sds_controller *this_controller,
1788 dev_dbg(scic_to_dev(this_controller),
1789 "%s: SCIC Controller 0x%p post request 0x%08x\n",
1794 SMU_PCP_WRITE(this_controller, request);
1798 * This method will copy the soft copy of the task context into the physical
1799 * memory accessible by the controller.
1800 * @this_controller: This parameter specifies the controller for which to copy
1802 * @this_request: This parameter specifies the request for which the task
1803 * context is being copied.
1805 * After this call is made the SCIC_SDS_IO_REQUEST object will always point to
1806 * the physical memory version of the task context. Thus, all subsequent
1807 * updates to the task context are performed in the TC table (i.e. DMAable
1810 void scic_sds_controller_copy_task_context(
1811 struct scic_sds_controller *this_controller,
1812 struct scic_sds_request *this_request)
1814 struct scu_task_context *task_context_buffer;
1816 task_context_buffer = scic_sds_controller_get_task_context_buffer(
1817 this_controller, this_request->io_tag
1821 task_context_buffer,
1822 this_request->task_context_buffer,
1823 SCI_FIELD_OFFSET(struct scu_task_context, sgl_snapshot_ac)
1827 * Now that the soft copy of the TC has been copied into the TC
1828 * table accessible by the silicon. Thus, any further changes to
1829 * the TC (e.g. TC termination) occur in the appropriate location. */
1830 this_request->task_context_buffer = task_context_buffer;
1834 * This method returns the task context buffer for the given io tag.
1838 * struct scu_task_context*
1840 struct scu_task_context *scic_sds_controller_get_task_context_buffer(
1841 struct scic_sds_controller *this_controller,
1844 u16 task_index = scic_sds_io_tag_get_index(io_tag);
1846 if (task_index < this_controller->task_context_entries) {
1847 return &this_controller->task_context_table[task_index];
1854 * This method returnst the sequence value from the io tag value
1862 * This method returns the IO request associated with the tag value
1866 * SCIC_SDS_IO_REQUEST_T* NULL if there is no valid IO request at the tag value
1868 struct scic_sds_request *scic_sds_controller_get_io_request_from_tag(
1869 struct scic_sds_controller *this_controller,
1875 task_index = scic_sds_io_tag_get_index(io_tag);
1877 if (task_index < this_controller->task_context_entries) {
1878 if (this_controller->io_request_table[task_index] != NULL) {
1879 task_sequence = scic_sds_io_tag_get_sequence(io_tag);
1881 if (task_sequence == this_controller->io_request_sequence[task_index]) {
1882 return this_controller->io_request_table[task_index];
1891 * This method allocates remote node index and the reserves the remote node
1892 * context space for use. This method can fail if there are no more remote
1893 * node index available.
1894 * @this_controller: This is the controller object which contains the set of
1895 * free remote node ids
1896 * @the_devce: This is the device object which is requesting the a remote node
1898 * @node_id: This is the remote node id that is assinged to the device if one
1901 * enum sci_status SCI_FAILURE_OUT_OF_RESOURCES if there are no available remote
1902 * node index available.
1904 enum sci_status scic_sds_controller_allocate_remote_node_context(
1905 struct scic_sds_controller *this_controller,
1906 struct scic_sds_remote_device *the_device,
1910 u32 remote_node_count = scic_sds_remote_device_node_count(the_device);
1912 node_index = scic_sds_remote_node_table_allocate_remote_node(
1913 &this_controller->available_remote_nodes, remote_node_count
1916 if (node_index != SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX) {
1917 this_controller->device_table[node_index] = the_device;
1919 *node_id = node_index;
1924 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
1928 * This method frees the remote node index back to the available pool. Once
1929 * this is done the remote node context buffer is no longer valid and can
1936 void scic_sds_controller_free_remote_node_context(
1937 struct scic_sds_controller *this_controller,
1938 struct scic_sds_remote_device *the_device,
1941 u32 remote_node_count = scic_sds_remote_device_node_count(the_device);
1943 if (this_controller->device_table[node_id] == the_device) {
1944 this_controller->device_table[node_id] = NULL;
1946 scic_sds_remote_node_table_release_remote_node_index(
1947 &this_controller->available_remote_nodes, remote_node_count, node_id
1953 * This method returns the union scu_remote_node_context for the specified remote
1958 * union scu_remote_node_context*
1960 union scu_remote_node_context *scic_sds_controller_get_remote_node_context_buffer(
1961 struct scic_sds_controller *this_controller,
1965 (node_id < this_controller->remote_node_entries)
1966 && (this_controller->device_table[node_id] != NULL)
1968 return &this_controller->remote_node_context_table[node_id];
1976 * @resposne_buffer: This is the buffer into which the D2H register FIS will be
1978 * @frame_header: This is the frame header returned by the hardware.
1979 * @frame_buffer: This is the frame buffer returned by the hardware.
1981 * This method will combind the frame header and frame buffer to create a SATA
1982 * D2H register FIS none
1984 void scic_sds_controller_copy_sata_response(
1985 void *response_buffer,
1996 (char *)((char *)response_buffer + sizeof(u32)),
1998 sizeof(struct sata_fis_reg_d2h) - sizeof(u32)
2003 * This method releases the frame once this is done the frame is available for
2004 * re-use by the hardware. The data contained in the frame header and frame
2005 * buffer is no longer valid. The UF queue get pointer is only updated if UF
2006 * control indicates this is appropriate.
2011 void scic_sds_controller_release_frame(
2012 struct scic_sds_controller *this_controller,
2015 if (scic_sds_unsolicited_frame_control_release_frame(
2016 &this_controller->uf_control, frame_index) == true)
2017 SCU_UFQGP_WRITE(this_controller, this_controller->uf_control.get);
2021 * This method sets user parameters and OEM parameters to default values.
2022 * Users can override these values utilizing the scic_user_parameters_set()
2023 * and scic_oem_parameters_set() methods.
2024 * @controller: This parameter specifies the controller for which to set the
2025 * configuration parameters to their default values.
2028 static void scic_sds_controller_set_default_config_parameters(struct scic_sds_controller *scic)
2032 /* Default to no SSC operation. */
2033 scic->oem_parameters.sds1.controller.do_enable_ssc = false;
2035 /* Initialize all of the port parameter information to narrow ports. */
2036 for (index = 0; index < SCI_MAX_PORTS; index++) {
2037 scic->oem_parameters.sds1.ports[index].phy_mask = 0;
2040 /* Initialize all of the phy parameter information. */
2041 for (index = 0; index < SCI_MAX_PHYS; index++) {
2042 /* Default to 6G (i.e. Gen 3) for now. */
2043 scic->user_parameters.sds1.phys[index].max_speed_generation = 3;
2045 /* the frequencies cannot be 0 */
2046 scic->user_parameters.sds1.phys[index].align_insertion_frequency = 0x7f;
2047 scic->user_parameters.sds1.phys[index].in_connection_align_insertion_frequency = 0xff;
2048 scic->user_parameters.sds1.phys[index].notify_enable_spin_up_insertion_frequency = 0x33;
2051 * Previous Vitesse based expanders had a arbitration issue that
2052 * is worked around by having the upper 32-bits of SAS address
2053 * with a value greater then the Vitesse company identifier.
2054 * Hence, usage of 0x5FCFFFFF. */
2055 scic->oem_parameters.sds1.phys[index].sas_address.low = 0x00000001;
2056 scic->oem_parameters.sds1.phys[index].sas_address.high = 0x5FCFFFFF;
2059 scic->user_parameters.sds1.stp_inactivity_timeout = 5;
2060 scic->user_parameters.sds1.ssp_inactivity_timeout = 5;
2061 scic->user_parameters.sds1.stp_max_occupancy_timeout = 5;
2062 scic->user_parameters.sds1.ssp_max_occupancy_timeout = 20;
2063 scic->user_parameters.sds1.no_outbound_task_timeout = 20;
2067 enum sci_status scic_controller_construct(struct scic_sds_controller *controller,
2068 void __iomem *scu_base,
2069 void __iomem *smu_base)
2073 sci_base_controller_construct(
2074 &controller->parent,
2075 scic_sds_controller_state_table,
2076 controller->memory_descriptors,
2077 ARRAY_SIZE(controller->memory_descriptors),
2081 controller->scu_registers = scu_base;
2082 controller->smu_registers = smu_base;
2084 scic_sds_port_configuration_agent_construct(&controller->port_agent);
2086 /* Construct the ports for this controller */
2087 for (index = 0; index < SCI_MAX_PORTS; index++)
2088 scic_sds_port_construct(&controller->port_table[index],
2090 scic_sds_port_construct(&controller->port_table[index],
2091 SCIC_SDS_DUMMY_PORT, controller);
2093 /* Construct the phys for this controller */
2094 for (index = 0; index < SCI_MAX_PHYS; index++) {
2095 /* Add all the PHYs to the dummy port */
2096 scic_sds_phy_construct(
2097 &controller->phy_table[index],
2098 &controller->port_table[SCI_MAX_PORTS],
2103 controller->invalid_phy_mask = 0;
2105 /* Set the default maximum values */
2106 controller->completion_event_entries = SCU_EVENT_COUNT;
2107 controller->completion_queue_entries = SCU_COMPLETION_QUEUE_COUNT;
2108 controller->remote_node_entries = SCI_MAX_REMOTE_DEVICES;
2109 controller->logical_port_entries = SCI_MAX_PORTS;
2110 controller->task_context_entries = SCU_IO_REQUEST_COUNT;
2111 controller->uf_control.buffers.count = SCU_UNSOLICITED_FRAME_COUNT;
2112 controller->uf_control.address_table.count = SCU_UNSOLICITED_FRAME_COUNT;
2114 /* Initialize the User and OEM parameters to default values. */
2115 scic_sds_controller_set_default_config_parameters(controller);
2117 return scic_controller_reset(controller);
2120 /* --------------------------------------------------------------------------- */
2122 enum sci_status scic_controller_initialize(
2123 struct scic_sds_controller *scic)
2125 enum sci_status status = SCI_FAILURE_INVALID_STATE;
2126 sci_base_controller_handler_t initialize;
2129 state = scic->parent.state_machine.current_state_id;
2130 initialize = scic_sds_controller_state_handler_table[state].base.initialize;
2133 status = initialize(&scic->parent);
2135 dev_warn(scic_to_dev(scic),
2136 "%s: SCIC Controller initialize operation requested "
2137 "in invalid state %d\n",
2139 sci_base_state_machine_get_state(
2140 scic_sds_controller_get_base_state_machine(
2146 /* --------------------------------------------------------------------------- */
2148 u32 scic_controller_get_suggested_start_timeout(
2149 struct scic_sds_controller *sc)
2151 /* Validate the user supplied parameters. */
2156 * The suggested minimum timeout value for a controller start operation:
2158 * Signature FIS Timeout
2159 * + Phy Start Timeout
2160 * + Number of Phy Spin Up Intervals
2161 * ---------------------------------
2162 * Number of milliseconds for the controller start operation.
2164 * NOTE: The number of phy spin up intervals will be equivalent
2165 * to the number of phys divided by the number phys allowed
2166 * per interval - 1 (once OEM parameters are supported).
2167 * Currently we assume only 1 phy per interval. */
2169 return SCIC_SDS_SIGNATURE_FIS_TIMEOUT
2170 + SCIC_SDS_CONTROLLER_PHY_START_TIMEOUT
2171 + ((SCI_MAX_PHYS - 1) * SCIC_SDS_CONTROLLER_POWER_CONTROL_INTERVAL);
2174 /* --------------------------------------------------------------------------- */
2176 enum sci_status scic_controller_start(
2177 struct scic_sds_controller *scic,
2180 enum sci_status status = SCI_FAILURE_INVALID_STATE;
2181 sci_base_controller_timed_handler_t start;
2184 state = scic->parent.state_machine.current_state_id;
2185 start = scic_sds_controller_state_handler_table[state].base.start;
2188 status = start(&scic->parent, timeout);
2190 dev_warn(scic_to_dev(scic),
2191 "%s: SCIC Controller start operation requested in "
2192 "invalid state %d\n",
2194 sci_base_state_machine_get_state(
2195 scic_sds_controller_get_base_state_machine(
2201 /* --------------------------------------------------------------------------- */
2203 enum sci_status scic_controller_stop(
2204 struct scic_sds_controller *scic,
2207 enum sci_status status = SCI_FAILURE_INVALID_STATE;
2208 sci_base_controller_timed_handler_t stop;
2211 state = scic->parent.state_machine.current_state_id;
2212 stop = scic_sds_controller_state_handler_table[state].base.stop;
2215 status = stop(&scic->parent, timeout);
2217 dev_warn(scic_to_dev(scic),
2218 "%s: SCIC Controller stop operation requested in "
2219 "invalid state %d\n",
2221 sci_base_state_machine_get_state(
2222 scic_sds_controller_get_base_state_machine(
2228 /* --------------------------------------------------------------------------- */
2230 enum sci_status scic_controller_reset(
2231 struct scic_sds_controller *scic)
2233 enum sci_status status = SCI_FAILURE_INVALID_STATE;
2234 sci_base_controller_handler_t reset;
2237 state = scic->parent.state_machine.current_state_id;
2238 reset = scic_sds_controller_state_handler_table[state].base.reset;
2241 status = reset(&scic->parent);
2243 dev_warn(scic_to_dev(scic),
2244 "%s: SCIC Controller reset operation requested in "
2245 "invalid state %d\n",
2247 sci_base_state_machine_get_state(
2248 scic_sds_controller_get_base_state_machine(
2254 enum sci_io_status scic_controller_start_io(
2255 struct scic_sds_controller *scic,
2256 struct scic_sds_remote_device *remote_device,
2257 struct scic_sds_request *io_request,
2261 sci_base_controller_start_request_handler_t start_io;
2263 state = scic->parent.state_machine.current_state_id;
2264 start_io = scic_sds_controller_state_handler_table[state].base.start_io;
2266 return start_io(&scic->parent,
2267 (struct sci_base_remote_device *) remote_device,
2268 (struct sci_base_request *)io_request, io_tag);
2271 /* --------------------------------------------------------------------------- */
2273 enum sci_status scic_controller_terminate_request(
2274 struct scic_sds_controller *scic,
2275 struct scic_sds_remote_device *remote_device,
2276 struct scic_sds_request *request)
2278 sci_base_controller_request_handler_t terminate_request;
2281 state = scic->parent.state_machine.current_state_id;
2282 terminate_request = scic_sds_controller_state_handler_table[state].terminate_request;
2284 return terminate_request(&scic->parent,
2285 (struct sci_base_remote_device *)remote_device,
2286 (struct sci_base_request *)request);
2289 /* --------------------------------------------------------------------------- */
2291 enum sci_status scic_controller_complete_io(
2292 struct scic_sds_controller *scic,
2293 struct scic_sds_remote_device *remote_device,
2294 struct scic_sds_request *io_request)
2297 sci_base_controller_request_handler_t complete_io;
2299 state = scic->parent.state_machine.current_state_id;
2300 complete_io = scic_sds_controller_state_handler_table[state].base.complete_io;
2302 return complete_io(&scic->parent,
2303 (struct sci_base_remote_device *)remote_device,
2304 (struct sci_base_request *)io_request);
2307 /* --------------------------------------------------------------------------- */
2310 enum sci_task_status scic_controller_start_task(
2311 struct scic_sds_controller *scic,
2312 struct scic_sds_remote_device *remote_device,
2313 struct scic_sds_request *task_request,
2317 sci_base_controller_start_request_handler_t start_task;
2318 enum sci_task_status status = SCI_TASK_FAILURE_INVALID_STATE;
2320 state = scic->parent.state_machine.current_state_id;
2321 start_task = scic_sds_controller_state_handler_table[state].base.start_task;
2324 status = start_task(&scic->parent,
2325 (struct sci_base_remote_device *)remote_device,
2326 (struct sci_base_request *)task_request,
2329 dev_warn(scic_to_dev(scic),
2330 "%s: SCIC Controller starting task from invalid "
2337 /* --------------------------------------------------------------------------- */
2339 enum sci_status scic_controller_complete_task(
2340 struct scic_sds_controller *scic,
2341 struct scic_sds_remote_device *remote_device,
2342 struct scic_sds_request *task_request)
2345 sci_base_controller_request_handler_t complete_task;
2346 enum sci_status status = SCI_FAILURE_INVALID_STATE;
2348 state = scic->parent.state_machine.current_state_id;
2349 complete_task = scic_sds_controller_state_handler_table[state].base.complete_task;
2352 status = complete_task(&scic->parent,
2353 (struct sci_base_remote_device *)remote_device,
2354 (struct sci_base_request *)task_request);
2356 dev_warn(scic_to_dev(scic),
2357 "%s: SCIC Controller completing task from invalid "
2365 /* --------------------------------------------------------------------------- */
2367 enum sci_status scic_controller_get_port_handle(
2368 struct scic_sds_controller *scic,
2370 struct scic_sds_port **port_handle)
2372 if (port_index < scic->logical_port_entries) {
2373 *port_handle = &scic->port_table[port_index];
2378 return SCI_FAILURE_INVALID_PORT;
2381 /* --------------------------------------------------------------------------- */
2383 enum sci_status scic_controller_get_phy_handle(
2384 struct scic_sds_controller *scic,
2386 struct scic_sds_phy **phy_handle)
2388 if (phy_index < ARRAY_SIZE(scic->phy_table)) {
2389 *phy_handle = &scic->phy_table[phy_index];
2394 dev_err(scic_to_dev(scic),
2395 "%s: Controller:0x%p PhyId:0x%x invalid phy index\n",
2396 __func__, scic, phy_index);
2398 return SCI_FAILURE_INVALID_PHY;
2401 /* --------------------------------------------------------------------------- */
2403 u16 scic_controller_allocate_io_tag(
2404 struct scic_sds_controller *scic)
2409 if (!sci_pool_empty(scic->tci_pool)) {
2410 sci_pool_get(scic->tci_pool, task_context);
2412 sequence_count = scic->io_request_sequence[task_context];
2414 return scic_sds_io_tag_construct(sequence_count, task_context);
2417 return SCI_CONTROLLER_INVALID_IO_TAG;
2420 /* --------------------------------------------------------------------------- */
2422 enum sci_status scic_controller_free_io_tag(
2423 struct scic_sds_controller *scic,
2429 BUG_ON(io_tag == SCI_CONTROLLER_INVALID_IO_TAG);
2431 sequence = scic_sds_io_tag_get_sequence(io_tag);
2432 index = scic_sds_io_tag_get_index(io_tag);
2434 if (!sci_pool_full(scic->tci_pool)) {
2435 if (sequence == scic->io_request_sequence[index]) {
2436 scic_sds_io_sequence_increment(
2437 scic->io_request_sequence[index]);
2439 sci_pool_put(scic->tci_pool, index);
2445 return SCI_FAILURE_INVALID_IO_TAG;
2448 /* --------------------------------------------------------------------------- */
2450 void scic_controller_enable_interrupts(
2451 struct scic_sds_controller *scic)
2453 BUG_ON(scic->smu_registers == NULL);
2454 SMU_IMR_WRITE(scic, 0x00000000);
2457 /* --------------------------------------------------------------------------- */
2459 void scic_controller_disable_interrupts(
2460 struct scic_sds_controller *scic)
2462 BUG_ON(scic->smu_registers == NULL);
2463 SMU_IMR_WRITE(scic, 0xffffffff);
2466 /* --------------------------------------------------------------------------- */
2468 enum sci_status scic_controller_set_mode(
2469 struct scic_sds_controller *scic,
2470 enum sci_controller_mode operating_mode)
2472 enum sci_status status = SCI_SUCCESS;
2474 if ((scic->parent.state_machine.current_state_id ==
2475 SCI_BASE_CONTROLLER_STATE_INITIALIZING) ||
2476 (scic->parent.state_machine.current_state_id ==
2477 SCI_BASE_CONTROLLER_STATE_INITIALIZED)) {
2478 switch (operating_mode) {
2479 case SCI_MODE_SPEED:
2480 scic->remote_node_entries = SCI_MAX_REMOTE_DEVICES;
2481 scic->task_context_entries = SCU_IO_REQUEST_COUNT;
2482 scic->uf_control.buffers.count =
2483 SCU_UNSOLICITED_FRAME_COUNT;
2484 scic->completion_event_entries = SCU_EVENT_COUNT;
2485 scic->completion_queue_entries =
2486 SCU_COMPLETION_QUEUE_COUNT;
2487 scic_sds_controller_build_memory_descriptor_table(scic);
2491 scic->remote_node_entries = SCI_MIN_REMOTE_DEVICES;
2492 scic->task_context_entries = SCI_MIN_IO_REQUESTS;
2493 scic->uf_control.buffers.count =
2494 SCU_MIN_UNSOLICITED_FRAMES;
2495 scic->completion_event_entries = SCU_MIN_EVENTS;
2496 scic->completion_queue_entries =
2497 SCU_MIN_COMPLETION_QUEUE_ENTRIES;
2498 scic_sds_controller_build_memory_descriptor_table(scic);
2502 status = SCI_FAILURE_INVALID_PARAMETER_VALUE;
2506 status = SCI_FAILURE_INVALID_STATE;
2512 * scic_sds_controller_reset_hardware() -
2514 * This method will reset the controller hardware.
2516 void scic_sds_controller_reset_hardware(
2517 struct scic_sds_controller *scic)
2519 /* Disable interrupts so we dont take any spurious interrupts */
2520 scic_controller_disable_interrupts(scic);
2523 SMU_SMUSRCR_WRITE(scic, 0xFFFFFFFF);
2525 /* Delay for 1ms to before clearing the CQP and UFQPR. */
2528 /* The write to the CQGR clears the CQP */
2529 SMU_CQGR_WRITE(scic, 0x00000000);
2531 /* The write to the UFQGP clears the UFQPR */
2532 SCU_UFQGP_WRITE(scic, 0x00000000);
2535 /* --------------------------------------------------------------------------- */
2537 enum sci_status scic_user_parameters_set(
2538 struct scic_sds_controller *scic,
2539 union scic_user_parameters *scic_parms)
2542 (scic->parent.state_machine.current_state_id
2543 == SCI_BASE_CONTROLLER_STATE_RESET)
2544 || (scic->parent.state_machine.current_state_id
2545 == SCI_BASE_CONTROLLER_STATE_INITIALIZING)
2546 || (scic->parent.state_machine.current_state_id
2547 == SCI_BASE_CONTROLLER_STATE_INITIALIZED)
2552 * Validate the user parameters. If they are not legal, then
2553 * return a failure. */
2554 for (index = 0; index < SCI_MAX_PHYS; index++) {
2555 if (!(scic_parms->sds1.phys[index].max_speed_generation
2556 <= SCIC_SDS_PARM_MAX_SPEED
2557 && scic_parms->sds1.phys[index].max_speed_generation
2558 > SCIC_SDS_PARM_NO_SPEED))
2559 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
2561 if (scic_parms->sds1.phys[index].in_connection_align_insertion_frequency < 3)
2562 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
2564 (scic_parms->sds1.phys[index].in_connection_align_insertion_frequency < 3) ||
2565 (scic_parms->sds1.phys[index].align_insertion_frequency == 0) ||
2566 (scic_parms->sds1.phys[index].notify_enable_spin_up_insertion_frequency == 0)
2568 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
2571 if ((scic_parms->sds1.stp_inactivity_timeout == 0) ||
2572 (scic_parms->sds1.ssp_inactivity_timeout == 0) ||
2573 (scic_parms->sds1.stp_max_occupancy_timeout == 0) ||
2574 (scic_parms->sds1.ssp_max_occupancy_timeout == 0) ||
2575 (scic_parms->sds1.no_outbound_task_timeout == 0))
2576 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
2578 memcpy(&scic->user_parameters, scic_parms, sizeof(*scic_parms));
2583 return SCI_FAILURE_INVALID_STATE;
2586 /* --------------------------------------------------------------------------- */
2588 void scic_user_parameters_get(
2589 struct scic_sds_controller *scic,
2590 union scic_user_parameters *scic_parms)
2592 memcpy(scic_parms, (&scic->user_parameters), sizeof(*scic_parms));
2595 /* --------------------------------------------------------------------------- */
2597 enum sci_status scic_oem_parameters_set(
2598 struct scic_sds_controller *scic,
2599 union scic_oem_parameters *scic_parms)
2602 (scic->parent.state_machine.current_state_id
2603 == SCI_BASE_CONTROLLER_STATE_RESET)
2604 || (scic->parent.state_machine.current_state_id
2605 == SCI_BASE_CONTROLLER_STATE_INITIALIZING)
2606 || (scic->parent.state_machine.current_state_id
2607 == SCI_BASE_CONTROLLER_STATE_INITIALIZED)
2612 * Validate the oem parameters. If they are not legal, then
2613 * return a failure. */
2614 for (index = 0; index < SCI_MAX_PORTS; index++) {
2615 if (scic_parms->sds1.ports[index].phy_mask > SCIC_SDS_PARM_PHY_MASK_MAX) {
2616 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
2620 for (index = 0; index < SCI_MAX_PHYS; index++) {
2622 scic_parms->sds1.phys[index].sas_address.high == 0
2623 && scic_parms->sds1.phys[index].sas_address.low == 0
2625 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
2629 memcpy(&scic->oem_parameters, scic_parms, sizeof(*scic_parms));
2633 return SCI_FAILURE_INVALID_STATE;
2636 /* --------------------------------------------------------------------------- */
2638 void scic_oem_parameters_get(
2639 struct scic_sds_controller *scic,
2640 union scic_oem_parameters *scic_parms)
2642 memcpy(scic_parms, (&scic->oem_parameters), sizeof(*scic_parms));
2645 /* --------------------------------------------------------------------------- */
2648 #define INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_LOWER_BOUND_NS 853
2649 #define INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_UPPER_BOUND_NS 1280
2650 #define INTERRUPT_COALESCE_TIMEOUT_MAX_US 2700000
2651 #define INTERRUPT_COALESCE_NUMBER_MAX 256
2652 #define INTERRUPT_COALESCE_TIMEOUT_ENCODE_MIN 7
2653 #define INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX 28
2655 enum sci_status scic_controller_set_interrupt_coalescence(
2656 struct scic_sds_controller *scic_controller,
2657 u32 coalesce_number,
2658 u32 coalesce_timeout)
2660 u8 timeout_encode = 0;
2664 /* Check if the input parameters fall in the range. */
2665 if (coalesce_number > INTERRUPT_COALESCE_NUMBER_MAX)
2666 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
2669 * Defined encoding for interrupt coalescing timeout:
2670 * Value Min Max Units
2671 * ----- --- --- -----
2701 * Others Undefined */
2704 * Use the table above to decide the encode of interrupt coalescing timeout
2705 * value for register writing. */
2706 if (coalesce_timeout == 0)
2709 /* make the timeout value in unit of (10 ns). */
2710 coalesce_timeout = coalesce_timeout * 100;
2711 min = INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_LOWER_BOUND_NS / 10;
2712 max = INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_UPPER_BOUND_NS / 10;
2714 /* get the encode of timeout for register writing. */
2715 for (timeout_encode = INTERRUPT_COALESCE_TIMEOUT_ENCODE_MIN;
2716 timeout_encode <= INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX;
2718 if (min <= coalesce_timeout && max > coalesce_timeout)
2720 else if (coalesce_timeout >= max && coalesce_timeout < min * 2
2721 && coalesce_timeout <= INTERRUPT_COALESCE_TIMEOUT_MAX_US * 100) {
2722 if ((coalesce_timeout - max) < (2 * min - coalesce_timeout))
2734 if (timeout_encode == INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX + 1)
2735 /* the value is out of range. */
2736 return SCI_FAILURE_INVALID_PARAMETER_VALUE;
2741 (SMU_ICC_GEN_VAL(NUMBER, coalesce_number) |
2742 SMU_ICC_GEN_VAL(TIMER, timeout_encode))
2745 scic_controller->interrupt_coalesce_number = (u16)coalesce_number;
2746 scic_controller->interrupt_coalesce_timeout = coalesce_timeout / 100;
2752 struct scic_sds_controller *scic_controller_alloc(struct device *dev)
2754 return devm_kzalloc(dev, sizeof(struct scic_sds_controller), GFP_KERNEL);
2758 * *****************************************************************************
2759 * * DEFAULT STATE HANDLERS
2760 * ***************************************************************************** */
2764 * @controller: This is struct sci_base_controller object which is cast into a
2765 * struct scic_sds_controller object.
2766 * @remote_device: This is struct sci_base_remote_device which, if it was used, would
2767 * be cast to a struct scic_sds_remote_device.
2768 * @io_request: This is the struct sci_base_request which, if it was used, would be
2769 * cast to a SCIC_SDS_IO_REQUEST.
2770 * @io_tag: This is the IO tag to be assigned to the IO request or
2771 * SCI_CONTROLLER_INVALID_IO_TAG.
2773 * This method is called when the struct scic_sds_controller default start io/task
2774 * handler is in place. - Issue a warning message enum sci_status
2775 * SCI_FAILURE_INVALID_STATE
2777 static enum sci_status scic_sds_controller_default_start_operation_handler(
2778 struct sci_base_controller *controller,
2779 struct sci_base_remote_device *remote_device,
2780 struct sci_base_request *io_request,
2783 struct scic_sds_controller *this_controller;
2785 this_controller = (struct scic_sds_controller *)controller;
2787 dev_warn(scic_to_dev(this_controller),
2788 "%s: SCIC Controller requested to start an io/task from "
2789 "invalid state %d\n",
2791 sci_base_state_machine_get_state(
2792 scic_sds_controller_get_base_state_machine(
2795 return SCI_FAILURE_INVALID_STATE;
2800 * @controller: This is struct sci_base_controller object which is cast into a
2801 * struct scic_sds_controller object.
2802 * @remote_device: This is struct sci_base_remote_device which, if it was used, would
2803 * be cast to a struct scic_sds_remote_device.
2804 * @io_request: This is the struct sci_base_request which, if it was used, would be
2805 * cast to a SCIC_SDS_IO_REQUEST.
2807 * This method is called when the struct scic_sds_controller default request handler
2808 * is in place. - Issue a warning message enum sci_status SCI_FAILURE_INVALID_STATE
2810 static enum sci_status scic_sds_controller_default_request_handler(
2811 struct sci_base_controller *controller,
2812 struct sci_base_remote_device *remote_device,
2813 struct sci_base_request *io_request)
2815 struct scic_sds_controller *this_controller;
2817 this_controller = (struct scic_sds_controller *)controller;
2819 dev_warn(scic_to_dev(this_controller),
2820 "%s: SCIC Controller request operation from invalid state %d\n",
2822 sci_base_state_machine_get_state(
2823 scic_sds_controller_get_base_state_machine(
2826 return SCI_FAILURE_INVALID_STATE;
2830 * *****************************************************************************
2831 * * GENERAL (COMMON) STATE HANDLERS
2832 * ***************************************************************************** */
2836 * @controller: The struct sci_base_controller object which is cast into a
2837 * struct scic_sds_controller object.
2839 * This method is called when the struct scic_sds_controller is in the ready state
2840 * reset handler is in place. - Transition to
2841 * SCI_BASE_CONTROLLER_STATE_RESETTING enum sci_status SCI_SUCCESS
2843 static enum sci_status scic_sds_controller_general_reset_handler(
2844 struct sci_base_controller *controller)
2846 struct scic_sds_controller *this_controller;
2848 this_controller = (struct scic_sds_controller *)controller;
2851 * The reset operation is not a graceful cleanup just perform the state
2853 sci_base_state_machine_change_state(
2854 scic_sds_controller_get_base_state_machine(this_controller),
2855 SCI_BASE_CONTROLLER_STATE_RESETTING
2862 * *****************************************************************************
2863 * * RESET STATE HANDLERS
2864 * ***************************************************************************** */
2868 * @controller: This is the struct sci_base_controller object which is cast into a
2869 * struct scic_sds_controller object.
2871 * This method is the struct scic_sds_controller initialize handler for the reset
2872 * state. - Currently this function does nothing enum sci_status SCI_FAILURE This
2873 * function is not yet implemented and is a valid request from the reset state.
2875 static enum sci_status scic_sds_controller_reset_state_initialize_handler(
2876 struct sci_base_controller *controller)
2879 enum sci_status result = SCI_SUCCESS;
2880 struct scic_sds_controller *this_controller;
2882 this_controller = (struct scic_sds_controller *)controller;
2884 sci_base_state_machine_change_state(
2885 scic_sds_controller_get_base_state_machine(this_controller),
2886 SCI_BASE_CONTROLLER_STATE_INITIALIZING
2889 this_controller->timeout_timer = isci_event_timer_create(
2891 (void (*)(void *))scic_sds_controller_timeout_handler,
2892 (void (*)(void *))controller);
2894 scic_sds_controller_initialize_phy_startup(this_controller);
2896 scic_sds_controller_initialize_power_control(this_controller);
2899 * There is nothing to do here for B0 since we do not have to
2900 * program the AFE registers.
2901 * / @todo The AFE settings are supposed to be correct for the B0 but
2902 * / presently they seem to be wrong. */
2903 scic_sds_controller_afe_initialization(this_controller);
2905 if (SCI_SUCCESS == result) {
2909 /* Take the hardware out of reset */
2910 SMU_SMUSRCR_WRITE(this_controller, 0x00000000);
2913 * / @todo Provide meaningfull error code for hardware failure
2914 * result = SCI_FAILURE_CONTROLLER_HARDWARE; */
2915 result = SCI_FAILURE;
2916 terminate_loop = 100;
2918 while (terminate_loop-- && (result != SCI_SUCCESS)) {
2919 /* Loop until the hardware reports success */
2920 udelay(SCU_CONTEXT_RAM_INIT_STALL_TIME);
2921 status = SMU_SMUCSR_READ(this_controller);
2923 if ((status & SCU_RAM_INIT_COMPLETED) == SCU_RAM_INIT_COMPLETED) {
2924 result = SCI_SUCCESS;
2929 if (result == SCI_SUCCESS) {
2930 u32 max_supported_ports;
2931 u32 max_supported_devices;
2932 u32 max_supported_io_requests;
2933 u32 device_context_capacity;
2936 * Determine what are the actaul device capacities that the
2937 * hardware will support */
2938 device_context_capacity = SMU_DCC_READ(this_controller);
2940 max_supported_ports =
2941 smu_dcc_get_max_ports(device_context_capacity);
2942 max_supported_devices =
2943 smu_dcc_get_max_remote_node_context(device_context_capacity);
2944 max_supported_io_requests =
2945 smu_dcc_get_max_task_context(device_context_capacity);
2947 /* Make all PEs that are unassigned match up with the logical ports */
2948 for (index = 0; index < max_supported_ports; index++) {
2951 this_controller->scu_registers->peg0.ptsg.protocol_engine[index],
2956 /* Record the smaller of the two capacity values */
2957 this_controller->logical_port_entries =
2958 min(max_supported_ports, this_controller->logical_port_entries);
2960 this_controller->task_context_entries =
2961 min(max_supported_io_requests, this_controller->task_context_entries);
2963 this_controller->remote_node_entries =
2964 min(max_supported_devices, this_controller->remote_node_entries);
2967 * Now that we have the correct hardware reported minimum values
2968 * build the MDL for the controller. Default to a performance
2970 scic_controller_set_mode(this_controller, SCI_MODE_SPEED);
2973 /* Initialize hardware PCI Relaxed ordering in DMA engines */
2974 if (result == SCI_SUCCESS) {
2975 u32 dma_configuration;
2977 /* Configure the payload DMA */
2978 dma_configuration = SCU_PDMACR_READ(this_controller);
2979 dma_configuration |= SCU_PDMACR_GEN_BIT(PCI_RELAXED_ORDERING_ENABLE);
2980 SCU_PDMACR_WRITE(this_controller, dma_configuration);
2982 /* Configure the control DMA */
2983 dma_configuration = SCU_CDMACR_READ(this_controller);
2984 dma_configuration |= SCU_CDMACR_GEN_BIT(PCI_RELAXED_ORDERING_ENABLE);
2985 SCU_CDMACR_WRITE(this_controller, dma_configuration);
2989 * Initialize the PHYs before the PORTs because the PHY registers
2990 * are accessed during the port initialization. */
2991 if (result == SCI_SUCCESS) {
2992 /* Initialize the phys */
2994 (result == SCI_SUCCESS) && (index < SCI_MAX_PHYS);
2996 result = scic_sds_phy_initialize(
2997 &this_controller->phy_table[index],
2998 &this_controller->scu_registers->peg0.pe[index].tl,
2999 &this_controller->scu_registers->peg0.pe[index].ll
3004 if (result == SCI_SUCCESS) {
3005 /* Initialize the logical ports */
3007 (index < this_controller->logical_port_entries)
3008 && (result == SCI_SUCCESS);
3010 result = scic_sds_port_initialize(
3011 &this_controller->port_table[index],
3012 &this_controller->scu_registers->peg0.ptsg.port[index],
3013 &this_controller->scu_registers->peg0.ptsg.protocol_engine,
3014 &this_controller->scu_registers->peg0.viit[index]
3019 if (SCI_SUCCESS == result) {
3020 result = scic_sds_port_configuration_agent_initialize(
3022 &this_controller->port_agent
3026 /* Advance the controller state machine */
3027 if (result == SCI_SUCCESS) {
3028 sci_base_state_machine_change_state(
3029 scic_sds_controller_get_base_state_machine(this_controller),
3030 SCI_BASE_CONTROLLER_STATE_INITIALIZED
3033 sci_base_state_machine_change_state(
3034 scic_sds_controller_get_base_state_machine(this_controller),
3035 SCI_BASE_CONTROLLER_STATE_FAILED
3043 * *****************************************************************************
3044 * * INITIALIZED STATE HANDLERS
3045 * ***************************************************************************** */
3049 * @controller: This is the struct sci_base_controller object which is cast into a
3050 * struct scic_sds_controller object.
3051 * @timeout: This is the allowed time for the controller object to reach the
3054 * This method is the struct scic_sds_controller start handler for the initialized
3055 * state. - Validate we have a good memory descriptor table - Initialze the
3056 * physical memory before programming the hardware - Program the SCU hardware
3057 * with the physical memory addresses passed in the memory descriptor table. -
3058 * Initialzie the TCi pool - Initialize the RNi pool - Initialize the
3059 * completion queue - Initialize the unsolicited frame data - Take the SCU port
3060 * task scheduler out of reset - Start the first phy object. - Transition to
3061 * SCI_BASE_CONTROLLER_STATE_STARTING. enum sci_status SCI_SUCCESS if all of the
3062 * controller start operations complete
3063 * SCI_FAILURE_UNSUPPORTED_INFORMATION_FIELD if one or more of the memory
3064 * descriptor fields is invalid.
3066 static enum sci_status scic_sds_controller_initialized_state_start_handler(
3067 struct sci_base_controller *controller,
3071 enum sci_status result;
3072 struct scic_sds_controller *this_controller;
3074 this_controller = (struct scic_sds_controller *)controller;
3076 /* Make sure that the SCI User filled in the memory descriptor table correctly */
3077 result = scic_sds_controller_validate_memory_descriptor_table(this_controller);
3079 if (result == SCI_SUCCESS) {
3080 /* The memory descriptor list looks good so program the hardware */
3081 scic_sds_controller_ram_initialization(this_controller);
3084 if (result == SCI_SUCCESS) {
3085 /* Build the TCi free pool */
3086 sci_pool_initialize(this_controller->tci_pool);
3087 for (index = 0; index < this_controller->task_context_entries; index++) {
3088 sci_pool_put(this_controller->tci_pool, index);
3091 /* Build the RNi free pool */
3092 scic_sds_remote_node_table_initialize(
3093 &this_controller->available_remote_nodes,
3094 this_controller->remote_node_entries
3098 if (result == SCI_SUCCESS) {
3100 * Before anything else lets make sure we will not be interrupted
3101 * by the hardware. */
3102 scic_controller_disable_interrupts(this_controller);
3104 /* Enable the port task scheduler */
3105 scic_sds_controller_enable_port_task_scheduler(this_controller);
3107 /* Assign all the task entries to this controller physical function */
3108 scic_sds_controller_assign_task_entries(this_controller);
3110 /* Now initialze the completion queue */
3111 scic_sds_controller_initialize_completion_queue(this_controller);
3113 /* Initialize the unsolicited frame queue for use */
3114 scic_sds_controller_initialize_unsolicited_frame_queue(this_controller);
3117 /* Start all of the ports on this controller */
3118 for (index = 0; index < this_controller->logical_port_entries &&
3119 result == SCI_SUCCESS; index++) {
3120 struct scic_sds_port *sci_port = &this_controller->port_table[index];
3122 result = sci_port->state_handlers->parent.start_handler(&sci_port->parent);
3125 if (result == SCI_SUCCESS) {
3126 scic_sds_controller_start_next_phy(this_controller);
3128 isci_event_timer_start(this_controller,
3129 this_controller->timeout_timer,
3132 sci_base_state_machine_change_state(
3133 scic_sds_controller_get_base_state_machine(this_controller),
3134 SCI_BASE_CONTROLLER_STATE_STARTING
3142 * *****************************************************************************
3143 * * INITIALIZED STATE HANDLERS
3144 * ***************************************************************************** */
3148 * @controller: This is struct scic_sds_controller which receives the link up
3150 * @port: This is struct scic_sds_port with which the phy is associated.
3151 * @phy: This is the struct scic_sds_phy which has gone link up.
3153 * This method is called when the struct scic_sds_controller is in the starting state
3154 * link up handler is called. This method will perform the following: - Stop
3155 * the phy timer - Start the next phy - Report the link up condition to the
3158 static void scic_sds_controller_starting_state_link_up_handler(
3159 struct scic_sds_controller *this_controller,
3160 struct scic_sds_port *port,
3161 struct scic_sds_phy *phy)
3163 scic_sds_controller_phy_timer_stop(this_controller);
3165 this_controller->port_agent.link_up_handler(
3166 this_controller, &this_controller->port_agent, port, phy
3168 /* scic_sds_port_link_up(port, phy); */
3170 scic_sds_controller_start_next_phy(this_controller);
3175 * @controller: This is struct scic_sds_controller which receives the link down
3177 * @port: This is struct scic_sds_port with which the phy is associated.
3178 * @phy: This is the struct scic_sds_phy which has gone link down.
3180 * This method is called when the struct scic_sds_controller is in the starting state
3181 * link down handler is called. - Report the link down condition to the port
3184 static void scic_sds_controller_starting_state_link_down_handler(
3185 struct scic_sds_controller *this_controller,
3186 struct scic_sds_port *port,
3187 struct scic_sds_phy *phy)
3189 this_controller->port_agent.link_down_handler(
3190 this_controller, &this_controller->port_agent, port, phy
3192 /* scic_sds_port_link_down(port, phy); */
3196 * *****************************************************************************
3197 * * READY STATE HANDLERS
3198 * ***************************************************************************** */
3202 * @controller: The struct sci_base_controller object which is cast into a
3203 * struct scic_sds_controller object.
3204 * @timeout: The timeout for when the stop operation should report a failure.
3206 * This method is called when the struct scic_sds_controller is in the ready state
3207 * stop handler is called. - Start the timeout timer - Transition to
3208 * SCI_BASE_CONTROLLER_STATE_STOPPING. enum sci_status SCI_SUCCESS
3210 static enum sci_status scic_sds_controller_ready_state_stop_handler(
3211 struct sci_base_controller *controller,
3214 struct scic_sds_controller *this_controller;
3216 this_controller = (struct scic_sds_controller *)controller;
3218 isci_event_timer_start(this_controller,
3219 this_controller->timeout_timer,
3222 sci_base_state_machine_change_state(
3223 scic_sds_controller_get_base_state_machine(this_controller),
3224 SCI_BASE_CONTROLLER_STATE_STOPPING
3232 * @controller: This is struct sci_base_controller object which is cast into a
3233 * struct scic_sds_controller object.
3234 * @remote_device: This is struct sci_base_remote_device which is cast to a
3235 * struct scic_sds_remote_device object.
3236 * @io_request: This is the struct sci_base_request which is cast to a
3237 * SCIC_SDS_IO_REQUEST object.
3238 * @io_tag: This is the IO tag to be assigned to the IO request or
3239 * SCI_CONTROLLER_INVALID_IO_TAG.
3241 * This method is called when the struct scic_sds_controller is in the ready state and
3242 * the start io handler is called. - Start the io request on the remote device
3243 * - if successful - assign the io_request to the io_request_table - post the
3244 * request to the hardware enum sci_status SCI_SUCCESS if the start io operation
3245 * succeeds SCI_FAILURE_INSUFFICIENT_RESOURCES if the IO tag could not be
3246 * allocated for the io request. SCI_FAILURE_INVALID_STATE if one or more
3247 * objects are not in a valid state to accept io requests. How does the io_tag
3248 * parameter get assigned to the io request?
3250 static enum sci_status scic_sds_controller_ready_state_start_io_handler(
3251 struct sci_base_controller *controller,
3252 struct sci_base_remote_device *remote_device,
3253 struct sci_base_request *io_request,
3256 enum sci_status status;
3258 struct scic_sds_controller *this_controller;
3259 struct scic_sds_request *the_request;
3260 struct scic_sds_remote_device *the_device;
3262 this_controller = (struct scic_sds_controller *)controller;
3263 the_request = (struct scic_sds_request *)io_request;
3264 the_device = (struct scic_sds_remote_device *)remote_device;
3266 status = scic_sds_remote_device_start_io(this_controller, the_device, the_request);
3268 if (status == SCI_SUCCESS) {
3269 this_controller->io_request_table[
3270 scic_sds_io_tag_get_index(the_request->io_tag)] = the_request;
3272 scic_sds_controller_post_request(
3274 scic_sds_request_get_post_context(the_request)
3283 * @controller: This is struct sci_base_controller object which is cast into a
3284 * struct scic_sds_controller object.
3285 * @remote_device: This is struct sci_base_remote_device which is cast to a
3286 * struct scic_sds_remote_device object.
3287 * @io_request: This is the struct sci_base_request which is cast to a
3288 * SCIC_SDS_IO_REQUEST object.
3290 * This method is called when the struct scic_sds_controller is in the ready state and
3291 * the complete io handler is called. - Complete the io request on the remote
3292 * device - if successful - remove the io_request to the io_request_table
3293 * enum sci_status SCI_SUCCESS if the start io operation succeeds
3294 * SCI_FAILURE_INVALID_STATE if one or more objects are not in a valid state to
3295 * accept io requests.
3297 static enum sci_status scic_sds_controller_ready_state_complete_io_handler(
3298 struct sci_base_controller *controller,
3299 struct sci_base_remote_device *remote_device,
3300 struct sci_base_request *io_request)
3303 enum sci_status status;
3304 struct scic_sds_controller *this_controller;
3305 struct scic_sds_request *the_request;
3306 struct scic_sds_remote_device *the_device;
3308 this_controller = (struct scic_sds_controller *)controller;
3309 the_request = (struct scic_sds_request *)io_request;
3310 the_device = (struct scic_sds_remote_device *)remote_device;
3312 status = scic_sds_remote_device_complete_io(
3313 this_controller, the_device, the_request);
3315 if (status == SCI_SUCCESS) {
3316 index = scic_sds_io_tag_get_index(the_request->io_tag);
3317 this_controller->io_request_table[index] = NULL;
3325 * @controller: This is struct sci_base_controller object which is cast into a
3326 * struct scic_sds_controller object.
3327 * @remote_device: This is struct sci_base_remote_device which is cast to a
3328 * struct scic_sds_remote_device object.
3329 * @io_request: This is the struct sci_base_request which is cast to a
3330 * SCIC_SDS_IO_REQUEST object.
3332 * This method is called when the struct scic_sds_controller is in the ready state and
3333 * the continue io handler is called. enum sci_status
3335 static enum sci_status scic_sds_controller_ready_state_continue_io_handler(
3336 struct sci_base_controller *controller,
3337 struct sci_base_remote_device *remote_device,
3338 struct sci_base_request *io_request)
3340 struct scic_sds_controller *this_controller;
3341 struct scic_sds_request *the_request;
3343 the_request = (struct scic_sds_request *)io_request;
3344 this_controller = (struct scic_sds_controller *)controller;
3346 this_controller->io_request_table[
3347 scic_sds_io_tag_get_index(the_request->io_tag)] = the_request;
3349 scic_sds_controller_post_request(
3351 scic_sds_request_get_post_context(the_request)
3359 * @controller: This is struct sci_base_controller object which is cast into a
3360 * struct scic_sds_controller object.
3361 * @remote_device: This is struct sci_base_remote_device which is cast to a
3362 * struct scic_sds_remote_device object.
3363 * @io_request: This is the struct sci_base_request which is cast to a
3364 * SCIC_SDS_IO_REQUEST object.
3365 * @task_tag: This is the task tag to be assigned to the task request or
3366 * SCI_CONTROLLER_INVALID_IO_TAG.
3368 * This method is called when the struct scic_sds_controller is in the ready state and
3369 * the start task handler is called. - The remote device is requested to start
3370 * the task request - if successful - assign the task to the io_request_table -
3371 * post the request to the SCU hardware enum sci_status SCI_SUCCESS if the start io
3372 * operation succeeds SCI_FAILURE_INSUFFICIENT_RESOURCES if the IO tag could
3373 * not be allocated for the io request. SCI_FAILURE_INVALID_STATE if one or
3374 * more objects are not in a valid state to accept io requests. How does the io
3375 * tag get assigned in this code path?
3377 static enum sci_status scic_sds_controller_ready_state_start_task_handler(
3378 struct sci_base_controller *controller,
3379 struct sci_base_remote_device *remote_device,
3380 struct sci_base_request *io_request,
3383 struct scic_sds_controller *this_controller = (struct scic_sds_controller *)
3385 struct scic_sds_request *the_request = (struct scic_sds_request *)
3387 struct scic_sds_remote_device *the_device = (struct scic_sds_remote_device *)
3389 enum sci_status status;
3391 status = scic_sds_remote_device_start_task(
3392 this_controller, the_device, the_request
3395 if (status == SCI_SUCCESS) {
3396 this_controller->io_request_table[
3397 scic_sds_io_tag_get_index(the_request->io_tag)] = the_request;
3399 scic_sds_controller_post_request(
3401 scic_sds_request_get_post_context(the_request)
3403 } else if (status == SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS) {
3404 this_controller->io_request_table[
3405 scic_sds_io_tag_get_index(the_request->io_tag)] = the_request;
3408 * We will let framework know this task request started successfully,
3409 * although core is still woring on starting the request (to post tc when
3410 * RNC is resumed.) */
3411 status = SCI_SUCCESS;
3418 * @controller: This is struct sci_base_controller object which is cast into a
3419 * struct scic_sds_controller object.
3420 * @remote_device: This is struct sci_base_remote_device which is cast to a
3421 * struct scic_sds_remote_device object.
3422 * @io_request: This is the struct sci_base_request which is cast to a
3423 * SCIC_SDS_IO_REQUEST object.
3425 * This method is called when the struct scic_sds_controller is in the ready state and
3426 * the terminate request handler is called. - call the io request terminate
3427 * function - if successful - post the terminate request to the SCU hardware
3428 * enum sci_status SCI_SUCCESS if the start io operation succeeds
3429 * SCI_FAILURE_INVALID_STATE if one or more objects are not in a valid state to
3430 * accept io requests.
3432 static enum sci_status scic_sds_controller_ready_state_terminate_request_handler(
3433 struct sci_base_controller *controller,
3434 struct sci_base_remote_device *remote_device,
3435 struct sci_base_request *io_request)
3437 struct scic_sds_controller *this_controller = (struct scic_sds_controller *)
3439 struct scic_sds_request *the_request = (struct scic_sds_request *)
3441 enum sci_status status;
3443 status = scic_sds_io_request_terminate(the_request);
3444 if (status == SCI_SUCCESS) {
3446 * Utilize the original post context command and or in the POST_TC_ABORT
3447 * request sub-type. */
3448 scic_sds_controller_post_request(
3450 scic_sds_request_get_post_context(the_request)
3451 | SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT
3460 * @controller: This is struct scic_sds_controller which receives the link up
3462 * @port: This is struct scic_sds_port with which the phy is associated.
3463 * @phy: This is the struct scic_sds_phy which has gone link up.
3465 * This method is called when the struct scic_sds_controller is in the starting state
3466 * link up handler is called. This method will perform the following: - Stop
3467 * the phy timer - Start the next phy - Report the link up condition to the
3470 static void scic_sds_controller_ready_state_link_up_handler(
3471 struct scic_sds_controller *this_controller,
3472 struct scic_sds_port *port,
3473 struct scic_sds_phy *phy)
3475 this_controller->port_agent.link_up_handler(
3476 this_controller, &this_controller->port_agent, port, phy
3482 * @controller: This is struct scic_sds_controller which receives the link down
3484 * @port: This is struct scic_sds_port with which the phy is associated.
3485 * @phy: This is the struct scic_sds_phy which has gone link down.
3487 * This method is called when the struct scic_sds_controller is in the starting state
3488 * link down handler is called. - Report the link down condition to the port
3491 static void scic_sds_controller_ready_state_link_down_handler(
3492 struct scic_sds_controller *this_controller,
3493 struct scic_sds_port *port,
3494 struct scic_sds_phy *phy)
3496 this_controller->port_agent.link_down_handler(
3497 this_controller, &this_controller->port_agent, port, phy
3502 * *****************************************************************************
3503 * * STOPPING STATE HANDLERS
3504 * ***************************************************************************** */
3508 * @controller: This is struct sci_base_controller object which is cast into a
3509 * struct scic_sds_controller object.
3510 * @remote_device: This is struct sci_base_remote_device which is cast to a
3511 * struct scic_sds_remote_device object.
3512 * @io_request: This is the struct sci_base_request which is cast to a
3513 * SCIC_SDS_IO_REQUEST object.
3515 * This method is called when the struct scic_sds_controller is in a stopping state
3516 * and the complete io handler is called. - This function is not yet
3517 * implemented enum sci_status SCI_FAILURE
3519 static enum sci_status scic_sds_controller_stopping_state_complete_io_handler(
3520 struct sci_base_controller *controller,
3521 struct sci_base_remote_device *remote_device,
3522 struct sci_base_request *io_request)
3524 struct scic_sds_controller *this_controller;
3526 this_controller = (struct scic_sds_controller *)controller;
3528 /* / @todo Implement this function */
3534 * @controller: This is struct sci_base_controller object which is cast into a
3535 * struct scic_sds_controller object.
3536 * @remote_device: This is struct sci_base_remote_device which is cast to a
3537 * struct scic_sds_remote_device object.
3539 * This method is called when the struct scic_sds_controller is in a stopping state
3540 * and the remote device has stopped.
3542 void scic_sds_controller_stopping_state_device_stopped_handler(
3543 struct scic_sds_controller *controller,
3544 struct scic_sds_remote_device *remote_device
3547 if (!scic_sds_controller_has_remote_devices_stopping(controller)) {
3548 sci_base_state_machine_change_state(
3549 &controller->parent.state_machine,
3550 SCI_BASE_CONTROLLER_STATE_STOPPED
3555 const struct scic_sds_controller_state_handler scic_sds_controller_state_handler_table[] = {
3556 [SCI_BASE_CONTROLLER_STATE_INITIAL] = {
3557 .base.start_io = scic_sds_controller_default_start_operation_handler,
3558 .base.complete_io = scic_sds_controller_default_request_handler,
3559 .base.continue_io = scic_sds_controller_default_request_handler,
3560 .terminate_request = scic_sds_controller_default_request_handler,
3562 [SCI_BASE_CONTROLLER_STATE_RESET] = {
3563 .base.reset = scic_sds_controller_general_reset_handler,
3564 .base.initialize = scic_sds_controller_reset_state_initialize_handler,
3565 .base.start_io = scic_sds_controller_default_start_operation_handler,
3566 .base.complete_io = scic_sds_controller_default_request_handler,
3567 .base.continue_io = scic_sds_controller_default_request_handler,
3568 .terminate_request = scic_sds_controller_default_request_handler,
3570 [SCI_BASE_CONTROLLER_STATE_INITIALIZING] = {
3571 .base.start_io = scic_sds_controller_default_start_operation_handler,
3572 .base.complete_io = scic_sds_controller_default_request_handler,
3573 .base.continue_io = scic_sds_controller_default_request_handler,
3574 .terminate_request = scic_sds_controller_default_request_handler,
3576 [SCI_BASE_CONTROLLER_STATE_INITIALIZED] = {
3577 .base.start = scic_sds_controller_initialized_state_start_handler,
3578 .base.start_io = scic_sds_controller_default_start_operation_handler,
3579 .base.complete_io = scic_sds_controller_default_request_handler,
3580 .base.continue_io = scic_sds_controller_default_request_handler,
3581 .terminate_request = scic_sds_controller_default_request_handler,
3583 [SCI_BASE_CONTROLLER_STATE_STARTING] = {
3584 .base.start_io = scic_sds_controller_default_start_operation_handler,
3585 .base.complete_io = scic_sds_controller_default_request_handler,
3586 .base.continue_io = scic_sds_controller_default_request_handler,
3587 .terminate_request = scic_sds_controller_default_request_handler,
3588 .link_up = scic_sds_controller_starting_state_link_up_handler,
3589 .link_down = scic_sds_controller_starting_state_link_down_handler
3591 [SCI_BASE_CONTROLLER_STATE_READY] = {
3592 .base.stop = scic_sds_controller_ready_state_stop_handler,
3593 .base.reset = scic_sds_controller_general_reset_handler,
3594 .base.start_io = scic_sds_controller_ready_state_start_io_handler,
3595 .base.complete_io = scic_sds_controller_ready_state_complete_io_handler,
3596 .base.continue_io = scic_sds_controller_ready_state_continue_io_handler,
3597 .base.start_task = scic_sds_controller_ready_state_start_task_handler,
3598 .base.complete_task = scic_sds_controller_ready_state_complete_io_handler,
3599 .terminate_request = scic_sds_controller_ready_state_terminate_request_handler,
3600 .link_up = scic_sds_controller_ready_state_link_up_handler,
3601 .link_down = scic_sds_controller_ready_state_link_down_handler
3603 [SCI_BASE_CONTROLLER_STATE_RESETTING] = {
3604 .base.start_io = scic_sds_controller_default_start_operation_handler,
3605 .base.complete_io = scic_sds_controller_default_request_handler,
3606 .base.continue_io = scic_sds_controller_default_request_handler,
3607 .terminate_request = scic_sds_controller_default_request_handler,
3609 [SCI_BASE_CONTROLLER_STATE_STOPPING] = {
3610 .base.start_io = scic_sds_controller_default_start_operation_handler,
3611 .base.complete_io = scic_sds_controller_stopping_state_complete_io_handler,
3612 .base.continue_io = scic_sds_controller_default_request_handler,
3613 .terminate_request = scic_sds_controller_default_request_handler,
3614 .remote_device_stopped_handler = scic_sds_controller_stopping_state_device_stopped_handler,
3616 [SCI_BASE_CONTROLLER_STATE_STOPPED] = {
3617 .base.reset = scic_sds_controller_general_reset_handler,
3618 .base.start_io = scic_sds_controller_default_start_operation_handler,
3619 .base.complete_io = scic_sds_controller_default_request_handler,
3620 .base.continue_io = scic_sds_controller_default_request_handler,
3621 .terminate_request = scic_sds_controller_default_request_handler,
3623 [SCI_BASE_CONTROLLER_STATE_FAILED] = {
3624 .base.reset = scic_sds_controller_general_reset_handler,
3625 .base.start_io = scic_sds_controller_default_start_operation_handler,
3626 .base.complete_io = scic_sds_controller_default_request_handler,
3627 .base.continue_io = scic_sds_controller_default_request_handler,
3628 .terminate_request = scic_sds_controller_default_request_handler,
3634 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3637 * This method implements the actions taken by the struct scic_sds_controller on entry
3638 * to the SCI_BASE_CONTROLLER_STATE_INITIAL. - Set the state handlers to the
3639 * controllers initial state. none This function should initialze the
3640 * controller object.
3642 static void scic_sds_controller_initial_state_enter(
3643 struct sci_base_object *object)
3645 struct scic_sds_controller *this_controller;
3647 this_controller = (struct scic_sds_controller *)object;
3649 sci_base_state_machine_change_state(
3650 &this_controller->parent.state_machine, SCI_BASE_CONTROLLER_STATE_RESET);
3655 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3658 * This method implements the actions taken by the struct scic_sds_controller on exit
3659 * from the SCI_BASE_CONTROLLER_STATE_STARTING. - This function stops the
3660 * controller starting timeout timer. none
3662 static void scic_sds_controller_starting_state_exit(
3663 struct sci_base_object *object)
3665 struct scic_sds_controller *scic = (struct scic_sds_controller *)object;
3667 isci_event_timer_stop(scic, scic->timeout_timer);
3672 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3675 * This method implements the actions taken by the struct scic_sds_controller on entry
3676 * to the SCI_BASE_CONTROLLER_STATE_READY. - Set the state handlers to the
3677 * controllers ready state. none
3679 static void scic_sds_controller_ready_state_enter(
3680 struct sci_base_object *object)
3682 struct scic_sds_controller *this_controller;
3684 this_controller = (struct scic_sds_controller *)object;
3686 /* set the default interrupt coalescence number and timeout value. */
3687 scic_controller_set_interrupt_coalescence(
3688 this_controller, 0x10, 250);
3693 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3696 * This method implements the actions taken by the struct scic_sds_controller on exit
3697 * from the SCI_BASE_CONTROLLER_STATE_READY. - This function does nothing. none
3699 static void scic_sds_controller_ready_state_exit(
3700 struct sci_base_object *object)
3702 struct scic_sds_controller *this_controller;
3704 this_controller = (struct scic_sds_controller *)object;
3706 /* disable interrupt coalescence. */
3707 scic_controller_set_interrupt_coalescence(this_controller, 0, 0);
3712 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3715 * This method implements the actions taken by the struct scic_sds_controller on entry
3716 * to the SCI_BASE_CONTROLLER_STATE_READY. - Set the state handlers to the
3717 * controllers ready state. - Stop the phys on this controller - Stop the ports
3718 * on this controller - Stop all of the remote devices on this controller none
3720 static void scic_sds_controller_stopping_state_enter(
3721 struct sci_base_object *object)
3723 struct scic_sds_controller *this_controller;
3725 this_controller = (struct scic_sds_controller *)object;
3727 /* Stop all of the components for this controller */
3728 scic_sds_controller_stop_phys(this_controller);
3729 scic_sds_controller_stop_ports(this_controller);
3730 scic_sds_controller_stop_devices(this_controller);
3735 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3738 * This method implements the actions taken by the struct scic_sds_controller on exit
3739 * from the SCI_BASE_CONTROLLER_STATE_STOPPING. - This function stops the
3740 * controller stopping timeout timer. none
3742 static void scic_sds_controller_stopping_state_exit(
3743 struct sci_base_object *object)
3745 struct scic_sds_controller *this_controller;
3747 this_controller = (struct scic_sds_controller *)object;
3749 isci_event_timer_stop(this_controller, this_controller->timeout_timer);
3754 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
3757 * This method implements the actions taken by the struct scic_sds_controller on entry
3758 * to the SCI_BASE_CONTROLLER_STATE_RESETTING. - Set the state handlers to the
3759 * controllers resetting state. - Write to the SCU hardware reset register to
3760 * force a reset - Transition to the SCI_BASE_CONTROLLER_STATE_RESET none
3762 static void scic_sds_controller_resetting_state_enter(
3763 struct sci_base_object *object)
3765 struct scic_sds_controller *this_controller;
3767 this_controller = (struct scic_sds_controller *)object;
3769 scic_sds_controller_reset_hardware(this_controller);
3771 sci_base_state_machine_change_state(
3772 scic_sds_controller_get_base_state_machine(this_controller),
3773 SCI_BASE_CONTROLLER_STATE_RESET
3777 /* --------------------------------------------------------------------------- */
3779 const struct sci_base_state scic_sds_controller_state_table[] = {
3780 [SCI_BASE_CONTROLLER_STATE_INITIAL] = {
3781 .enter_state = scic_sds_controller_initial_state_enter,
3783 [SCI_BASE_CONTROLLER_STATE_RESET] = {},
3784 [SCI_BASE_CONTROLLER_STATE_INITIALIZING] = {},
3785 [SCI_BASE_CONTROLLER_STATE_INITIALIZED] = {},
3786 [SCI_BASE_CONTROLLER_STATE_STARTING] = {
3787 .exit_state = scic_sds_controller_starting_state_exit,
3789 [SCI_BASE_CONTROLLER_STATE_READY] = {
3790 .enter_state = scic_sds_controller_ready_state_enter,
3791 .exit_state = scic_sds_controller_ready_state_exit,
3793 [SCI_BASE_CONTROLLER_STATE_RESETTING] = {
3794 .enter_state = scic_sds_controller_resetting_state_enter,
3796 [SCI_BASE_CONTROLLER_STATE_STOPPING] = {
3797 .enter_state = scic_sds_controller_stopping_state_enter,
3798 .exit_state = scic_sds_controller_stopping_state_exit,
3800 [SCI_BASE_CONTROLLER_STATE_STOPPED] = {},
3801 [SCI_BASE_CONTROLLER_STATE_FAILED] = {}