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 #ifndef _SCIC_SDS_CONTROLLER_H_
57 #define _SCIC_SDS_CONTROLLER_H_
60 * This file contains the structures, constants and prototypes used for the
61 * core controller object.
67 #include "sci_controller_constants.h"
68 #include "sci_memory_descriptor_list.h"
69 #include "sci_base_controller.h"
70 #include "scic_config_parameters.h"
71 #include "scic_sds_port.h"
72 #include "scic_sds_phy.h"
73 #include "scic_sds_remote_node_table.h"
74 #include "scu_registers.h"
75 #include "scu_constants.h"
76 #include "scu_remote_node_context.h"
77 #include "scu_task_context.h"
78 #include "scu_unsolicited_frame.h"
79 #include "scic_sds_unsolicited_frame_control.h"
80 #include "scic_sds_port_configuration_agent.h"
81 #include "scic_sds_pci.h"
83 struct scic_sds_remote_device;
84 struct scic_sds_request;
85 struct scic_sds_controller;
88 #define SCU_COMPLETION_RAM_ALIGNMENT (64)
91 * enum SCIC_SDS_CONTROLLER_MEMORY_DESCRIPTORS -
93 * This enumeration depects the types of MDEs that are going to be created for
94 * the controller object.
96 enum SCIC_SDS_CONTROLLER_MEMORY_DESCRIPTORS {
98 * Completion queue MDE entry
100 SCU_MDE_COMPLETION_QUEUE,
103 * Remote node context MDE entry
105 SCU_MDE_REMOTE_NODE_CONTEXT,
108 * Task context MDE entry
110 SCU_MDE_TASK_CONTEXT,
113 * Unsolicited frame buffer MDE entrys this is the start of the unsolicited
114 * frame buffer entries.
124 * Allowed PORT configuration modes APC Automatic PORT configuration mode is
125 * defined by the OEM configuration parameters providing no PHY_MASK parameters
126 * for any PORT. i.e. There are no phys assigned to any of the ports at start.
127 * MPC Manual PORT configuration mode is defined by the OEM configuration
128 * parameters providing a PHY_MASK value for any PORT. It is assumed that any
129 * PORT with no PHY_MASK is an invalid port and not all PHYs must be assigned.
130 * A PORT_PHY mask that assigns just a single PHY to a port and no other PHYs
131 * being assigned is sufficient to declare manual PORT configuration.
133 enum SCIC_PORT_CONFIGURATION_MODE {
134 SCIC_PORT_MANUAL_CONFIGURATION_MODE,
135 SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE
139 * struct scic_power_control -
141 * This structure defines the fields for managing power control for direct
142 * attached disk devices.
144 struct scic_power_control {
146 * This field is set when the power control timer is running and cleared when
152 * This field is the handle to the driver timer object. This timer is used to
153 * control when the directed attached disks can consume power.
158 * This field is used to keep track of how many phys are put into the
164 * This field is an array of phys that we are waiting on. The phys are direct
165 * mapped into requesters via struct scic_sds_phy.phy_index
167 struct scic_sds_phy *requesters[SCI_MAX_PHYS];
172 * struct scic_sds_controller -
174 * This structure represents the SCU contoller object.
176 struct scic_sds_controller {
178 * The struct sci_base_controller is the parent object for the struct scic_sds_controller
181 struct sci_base_controller parent;
184 * This field is the driver timer object handler used to time the controller
185 * object start and stop requests.
190 * This field contains the user parameters to be utilized for this
191 * core controller object.
193 union scic_user_parameters user_parameters;
196 * This field contains the OEM parameters to be utilized for this
197 * core controller object.
199 union scic_oem_parameters oem_parameters;
202 * This field contains the port configuration agent for this controller.
204 struct scic_sds_port_configuration_agent port_agent;
207 * This field is the array of port objects that are controlled by this
208 * controller object. There is one dummy port object also contained within
209 * this controller object.
211 struct scic_sds_port port_table[SCI_MAX_PORTS + 1];
214 * This field is the array of phy objects that are controlled by this
217 struct scic_sds_phy phy_table[SCI_MAX_PHYS];
220 * This field is the array of device objects that are currently constructed
221 * for this controller object. This table is used as a fast lookup of device
222 * objects that need to handle device completion notifications from the
223 * hardware. The table is RNi based.
225 struct scic_sds_remote_device *device_table[SCI_MAX_REMOTE_DEVICES];
228 * This field is the array of IO request objects that are currently active for
229 * this controller object. This table is used as a fast lookup of the io
230 * request object that need to handle completion queue notifications. The
231 * table is TCi based.
233 struct scic_sds_request *io_request_table[SCI_MAX_IO_REQUESTS];
236 * This field is the free RNi data structure
238 struct scic_remote_node_table available_remote_nodes;
241 * This field is the TCi pool used to manage the task context index.
243 SCI_POOL_CREATE(tci_pool, u16, SCI_MAX_IO_REQUESTS);
246 * This filed is the struct scic_power_control data used to controll when direct
247 * attached devices can consume power.
249 struct scic_power_control power_control;
252 * This field is the array of sequence values for the IO Tag fields. Even
253 * though only 4 bits of the field is used for the sequence the sequence is 16
254 * bits in size so the sequence can be bitwise or'd with the TCi to build the
257 u16 io_request_sequence[SCI_MAX_IO_REQUESTS];
260 * This field in the array of sequence values for the RNi. These are used
261 * to control io request build to io request start operations. The sequence
262 * value is recorded into an io request when it is built and is checked on
263 * the io request start operation to make sure that there was not a device
264 * hot plug between the build and start operation.
266 u8 remote_device_sequence[SCI_MAX_REMOTE_DEVICES];
269 * This field is a pointer to the memory allocated by the driver for the task
270 * context table. This data is shared between the hardware and software.
272 struct scu_task_context *task_context_table;
275 * This field is a pointer to the memory allocated by the driver for the
276 * remote node context table. This table is shared between the hardware and
279 union scu_remote_node_context *remote_node_context_table;
282 * This field is the array of physical memory requiremets for this controller
285 struct sci_physical_memory_descriptor memory_descriptors[SCU_MAX_MDES];
288 * This field is a pointer to the completion queue. This memory is
289 * written to by the hardware and read by the software.
291 u32 *completion_queue;
294 * This field is the software copy of the completion queue get pointer. The
295 * controller object writes this value to the hardware after processing the
296 * completion entries.
298 u32 completion_queue_get;
301 * This field is the minimum of the number of hardware supported port entries
302 * and the software requested port entries.
304 u32 logical_port_entries;
307 * This field is the minimum number of hardware supported completion queue
308 * entries and the software requested completion queue entries.
310 u32 completion_queue_entries;
313 * This field is the minimum number of hardware supported event entries and
314 * the software requested event entries.
316 u32 completion_event_entries;
319 * This field is the minimum number of devices supported by the hardware and
320 * the number of devices requested by the software.
322 u32 remote_node_entries;
325 * This field is the minimum number of IO requests supported by the hardware
326 * and the number of IO requests requested by the software.
328 u32 task_context_entries;
331 * This object contains all of the unsolicited frame specific
332 * data utilized by the core controller.
334 struct scic_sds_unsolicited_frame_control uf_control;
337 * This field records the fact that the controller has encountered a fatal
338 * error and must be reset.
340 bool encountered_fatal_error;
343 * This field specifies that the controller should ignore
344 * completion processing for non-fastpath events. This will
345 * cause the completions to be thrown away.
347 bool restrict_completions;
349 /* Phy Startup Data */
351 * This field is the driver timer handle for controller phy request startup.
352 * On controller start the controller will start each PHY individually in
353 * order of phy index.
355 void *phy_startup_timer;
358 * This field is set when the phy_startup_timer is running and is cleared when
359 * the phy_startup_timer is stopped.
361 bool phy_startup_timer_pending;
364 * This field is the index of the next phy start. It is initialized to 0 and
365 * increments for each phy index that is started.
367 u32 next_phy_to_start;
370 * This field controlls the invalid link up notifications to the SCI_USER. If
371 * an invalid_link_up notification is reported a bit for the PHY index is set
372 * so further notifications are not made. Once the PHY object reports link up
373 * and is made part of a port then this bit for the PHY index is cleared.
378 * This field saves the current interrupt coalescing number of the controller.
380 u16 interrupt_coalesce_number;
383 * This field saves the current interrupt coalescing timeout value in microseconds.
385 u32 interrupt_coalesce_timeout;
388 * This field is a pointer to the memory mapped register space for the
389 * struct smu_registers.
391 struct smu_registers __iomem *smu_registers;
394 * This field is a pointer to the memory mapped register space for the
395 * struct scu_registers.
397 struct scu_registers __iomem *scu_registers;
401 typedef void (*scic_sds_controller_phy_handler_t)(struct scic_sds_controller *,
402 struct scic_sds_port *,
403 struct scic_sds_phy *);
405 * struct scic_sds_controller_state_handler -
407 * This structure contains the SDS core specific definition for the state
410 struct scic_sds_controller_state_handler {
411 struct sci_base_controller_state_handler base;
413 sci_base_controller_request_handler_t terminate_request;
414 scic_sds_controller_phy_handler_t link_up;
415 scic_sds_controller_phy_handler_t link_down;
418 extern const struct scic_sds_controller_state_handler
419 scic_sds_controller_state_handler_table[];
420 extern const struct sci_base_state scic_sds_controller_state_table[];
423 * INCREMENT_QUEUE_GET() -
425 * This macro will increment the specified index to and if the index wraps to 0
426 * it will toggel the cycle bit.
428 #define INCREMENT_QUEUE_GET(index, cycle, entry_count, bit_toggle) \
430 if ((index) + 1 == entry_count) { \
432 (cycle) = (cycle) ^ (bit_toggle); \
439 * scic_sds_controller_get_base_state_machine() -
441 * This is a helper macro that gets the base state machine for the controller
444 #define scic_sds_controller_get_base_state_machine(this_controller) \
445 (&(this_controller)->parent.state_machine)
448 * scic_sds_controller_get_port_configuration_agent() -
450 * This is a helper macro to get the port configuration agent from the
453 #define scic_sds_controller_get_port_configuration_agent(controller) \
454 (&(controller)->port_agent)
457 * smu_register_write() -
459 * This macro writes to the smu_register for this controller
461 #define smu_register_write(controller, reg, value) \
462 scic_sds_pci_write_smu_dword((controller), &(reg), (value))
465 * smu_register_read() -
467 * This macro reads the smu_register for this controller
469 #define smu_register_read(controller, reg) \
470 scic_sds_pci_read_smu_dword((controller), &(reg))
473 * scu_register_write() -
475 * This mcaro writes the scu_register for this controller
477 #define scu_register_write(controller, reg, value) \
478 scic_sds_pci_write_scu_dword((controller), &(reg), (value))
481 * scu_register_read() -
483 * This macro reads the scu_register for this controller
485 #define scu_register_read(controller, reg) \
486 scic_sds_pci_read_scu_dword((controller), &(reg))
489 * scic_sds_controller_get_protocol_engine_group() -
491 * This macro returns the protocol engine group for this controller object.
492 * Presently we only support protocol engine group 0 so just return that
494 #define scic_sds_controller_get_protocol_engine_group(controller) 0
497 * scic_sds_io_tag_construct() -
499 * This macro constructs an IO tag from the sequence and index values.
501 #define scic_sds_io_tag_construct(sequence, task_index) \
502 ((sequence) << 12 | (task_index))
505 * scic_sds_io_tag_get_sequence() -
507 * This macro returns the IO sequence from the IO tag value.
509 #define scic_sds_io_tag_get_sequence(io_tag) \
510 (((io_tag) & 0xF000) >> 12)
513 * scic_sds_io_tag_get_index() -
515 * This macro returns the TCi from the io tag value
517 #define scic_sds_io_tag_get_index(io_tag) \
521 * scic_sds_io_sequence_increment() -
523 * This is a helper macro to increment the io sequence count. We may find in
524 * the future that it will be faster to store the sequence count in such a way
525 * as we dont perform the shift operation to build io tag values so therefore
526 * need a way to incrment them correctly
528 #define scic_sds_io_sequence_increment(value) \
529 ((value) = (((value) + 1) & 0x000F))
531 #define scic_sds_remote_device_node_count(device) \
534 (device)->target_protocols.u.bits.attached_stp_target \
535 && ((device)->is_direct_attached != true) \
537 ? SCU_STP_REMOTE_NODE_COUNT : SCU_SSP_REMOTE_NODE_COUNT \
541 * scic_sds_controller_set_invalid_phy() -
543 * This macro will set the bit in the invalid phy mask for this controller
544 * object. This is used to control messages reported for invalid link up
547 #define scic_sds_controller_set_invalid_phy(controller, phy) \
548 ((controller)->invalid_phy_mask |= (1 << (phy)->phy_index))
551 * scic_sds_controller_clear_invalid_phy() -
553 * This macro will clear the bit in the invalid phy mask for this controller
554 * object. This is used to control messages reported for invalid link up
557 #define scic_sds_controller_clear_invalid_phy(controller, phy) \
558 ((controller)->invalid_phy_mask &= ~(1 << (phy)->phy_index))
560 /* --------------------------------------------------------------------------- */
562 u32 scic_sds_controller_get_object_size(void);
564 /* --------------------------------------------------------------------------- */
567 /* --------------------------------------------------------------------------- */
569 enum SCIC_PORT_CONFIGURATION_MODE scic_sds_controller_get_port_configuration_mode(
570 struct scic_sds_controller *this_controller);
572 /* --------------------------------------------------------------------------- */
574 void scic_sds_controller_post_request(
575 struct scic_sds_controller *this_controller,
578 /* --------------------------------------------------------------------------- */
580 void scic_sds_controller_release_frame(
581 struct scic_sds_controller *this_controller,
584 void scic_sds_controller_copy_sata_response(
585 void *response_buffer,
589 /* --------------------------------------------------------------------------- */
591 enum sci_status scic_sds_controller_allocate_remote_node_context(
592 struct scic_sds_controller *this_controller,
593 struct scic_sds_remote_device *the_device,
596 void scic_sds_controller_free_remote_node_context(
597 struct scic_sds_controller *this_controller,
598 struct scic_sds_remote_device *the_device,
601 union scu_remote_node_context *scic_sds_controller_get_remote_node_context_buffer(
602 struct scic_sds_controller *this_controller,
605 /* --------------------------------------------------------------------------- */
607 struct scic_sds_request *scic_sds_controller_get_io_request_from_tag(
608 struct scic_sds_controller *this_controller,
612 struct scu_task_context *scic_sds_controller_get_task_context_buffer(
613 struct scic_sds_controller *this_controller,
617 * *****************************************************************************
618 * * CORE CONTROLLER POWER CONTROL METHODS
619 * ***************************************************************************** */
622 void scic_sds_controller_power_control_queue_insert(
623 struct scic_sds_controller *this_controller,
624 struct scic_sds_phy *the_phy);
626 void scic_sds_controller_power_control_queue_remove(
627 struct scic_sds_controller *this_controller,
628 struct scic_sds_phy *the_phy);
631 * *****************************************************************************
632 * * CORE CONTROLLER PHY MESSAGE PROCESSING
633 * ***************************************************************************** */
635 void scic_sds_controller_link_up(
636 struct scic_sds_controller *this_controller,
637 struct scic_sds_port *the_port,
638 struct scic_sds_phy *the_phy);
640 void scic_sds_controller_link_down(
641 struct scic_sds_controller *this_controller,
642 struct scic_sds_port *the_port,
643 struct scic_sds_phy *the_phy);
646 * *****************************************************************************
647 * * CORE CONTROLLER PRIVATE METHODS
648 * ***************************************************************************** */
650 enum sci_status scic_sds_controller_validate_memory_descriptor_table(
651 struct scic_sds_controller *this_controller);
653 void scic_sds_controller_ram_initialization(
654 struct scic_sds_controller *this_controller);
656 void scic_sds_controller_assign_task_entries(
657 struct scic_sds_controller *this_controller);
659 void scic_sds_controller_afe_initialization(
660 struct scic_sds_controller *this_controller);
662 void scic_sds_controller_enable_port_task_scheduler(
663 struct scic_sds_controller *this_controller);
665 void scic_sds_controller_initialize_completion_queue(
666 struct scic_sds_controller *this_controller);
668 void scic_sds_controller_initialize_unsolicited_frame_queue(
669 struct scic_sds_controller *this_controller);
671 void scic_sds_controller_phy_timer_stop(
672 struct scic_sds_controller *this_controller);
674 enum sci_status scic_sds_controller_start_next_phy(
675 struct scic_sds_controller *this_controller);
677 enum sci_status scic_sds_controller_stop_phys(
678 struct scic_sds_controller *this_controller);
680 enum sci_status scic_sds_controller_stop_ports(
681 struct scic_sds_controller *this_controller);
683 enum sci_status scic_sds_controller_stop_devices(
684 struct scic_sds_controller *this_controller);
686 void scic_sds_controller_copy_task_context(
687 struct scic_sds_controller *this_controller,
688 struct scic_sds_request *this_request);
690 void scic_sds_controller_timeout_handler(
691 struct scic_sds_controller *controller);
693 void scic_sds_controller_initialize_power_control(
694 struct scic_sds_controller *this_controller);
696 void scic_sds_controller_register_setup(
697 struct scic_sds_controller *this_controller);
699 void scic_sds_controller_reset_hardware(
700 struct scic_sds_controller *this_controller);
703 void scic_sds_controller_initialize_phy_startup(
704 struct scic_sds_controller *this_controller);
706 #endif /* _SCIC_SDS_CONTROLLER_H_ */