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_
59 #include <linux/string.h>
62 * This file contains the structures, constants and prototypes used for the
63 * core controller object.
69 #include "sci_controller_constants.h"
70 #include "sci_memory_descriptor_list.h"
71 #include "sci_base_controller.h"
72 #include "scic_config_parameters.h"
73 #include "scic_sds_port.h"
74 #include "scic_sds_phy.h"
75 #include "scic_sds_remote_node_table.h"
76 #include "scu_registers.h"
77 #include "scu_constants.h"
78 #include "scu_remote_node_context.h"
79 #include "scu_task_context.h"
80 #include "scu_unsolicited_frame.h"
81 #include "scic_sds_unsolicited_frame_control.h"
82 #include "scic_sds_port_configuration_agent.h"
83 #include "scic_sds_pci.h"
85 struct scic_sds_remote_device;
86 struct scic_sds_request;
87 struct scic_sds_controller;
90 #define SCU_COMPLETION_RAM_ALIGNMENT (64)
93 * enum SCIC_SDS_CONTROLLER_MEMORY_DESCRIPTORS -
95 * This enumeration depects the types of MDEs that are going to be created for
96 * the controller object.
98 enum SCIC_SDS_CONTROLLER_MEMORY_DESCRIPTORS {
100 * Completion queue MDE entry
102 SCU_MDE_COMPLETION_QUEUE,
105 * Remote node context MDE entry
107 SCU_MDE_REMOTE_NODE_CONTEXT,
110 * Task context MDE entry
112 SCU_MDE_TASK_CONTEXT,
115 * Unsolicited frame buffer MDE entrys this is the start of the unsolicited
116 * frame buffer entries.
127 * Allowed PORT configuration modes APC Automatic PORT configuration mode is
128 * defined by the OEM configuration parameters providing no PHY_MASK parameters
129 * for any PORT. i.e. There are no phys assigned to any of the ports at start.
130 * MPC Manual PORT configuration mode is defined by the OEM configuration
131 * parameters providing a PHY_MASK value for any PORT. It is assumed that any
132 * PORT with no PHY_MASK is an invalid port and not all PHYs must be assigned.
133 * A PORT_PHY mask that assigns just a single PHY to a port and no other PHYs
134 * being assigned is sufficient to declare manual PORT configuration.
136 enum SCIC_PORT_CONFIGURATION_MODE {
137 SCIC_PORT_MANUAL_CONFIGURATION_MODE,
138 SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE
142 * struct scic_power_control -
144 * This structure defines the fields for managing power control for direct
145 * attached disk devices.
147 struct scic_power_control {
149 * This field is set when the power control timer is running and cleared when
155 * This field is the handle to the driver timer object. This timer is used to
156 * control when the directed attached disks can consume power.
161 * This field is used to keep track of how many phys are put into the
167 * This field is an array of phys that we are waiting on. The phys are direct
168 * mapped into requesters via struct scic_sds_phy.phy_index
170 struct scic_sds_phy *requesters[SCI_MAX_PHYS];
175 * struct scic_sds_controller -
177 * This structure represents the SCU contoller object.
179 struct scic_sds_controller {
181 * The struct sci_base_controller is the parent object for the struct scic_sds_controller
184 struct sci_base_controller parent;
187 * This field is the driver timer object handler used to time the controller
188 * object start and stop requests.
193 * This field contains the user parameters to be utilized for this
194 * core controller object.
196 union scic_user_parameters user_parameters;
199 * This field contains the OEM parameters to be utilized for this
200 * core controller object.
202 union scic_oem_parameters oem_parameters;
205 * This field contains the port configuration agent for this controller.
207 struct scic_sds_port_configuration_agent port_agent;
210 * This field is the array of port objects that are controlled by this
211 * controller object. There is one dummy port object also contained within
212 * this controller object.
214 struct scic_sds_port port_table[SCI_MAX_PORTS + 1];
217 * This field is the array of phy objects that are controlled by this
220 struct scic_sds_phy phy_table[SCI_MAX_PHYS];
223 * This field is the array of device objects that are currently constructed
224 * for this controller object. This table is used as a fast lookup of device
225 * objects that need to handle device completion notifications from the
226 * hardware. The table is RNi based.
228 struct scic_sds_remote_device *device_table[SCI_MAX_REMOTE_DEVICES];
231 * This field is the array of IO request objects that are currently active for
232 * this controller object. This table is used as a fast lookup of the io
233 * request object that need to handle completion queue notifications. The
234 * table is TCi based.
236 struct scic_sds_request *io_request_table[SCI_MAX_IO_REQUESTS];
239 * This field is the free RNi data structure
241 struct scic_remote_node_table available_remote_nodes;
244 * This field is the TCi pool used to manage the task context index.
246 SCI_POOL_CREATE(tci_pool, u16, SCI_MAX_IO_REQUESTS);
249 * This filed is the struct scic_power_control data used to controll when direct
250 * attached devices can consume power.
252 struct scic_power_control power_control;
255 * This field is the array of sequence values for the IO Tag fields. Even
256 * though only 4 bits of the field is used for the sequence the sequence is 16
257 * bits in size so the sequence can be bitwise or'd with the TCi to build the
260 u16 io_request_sequence[SCI_MAX_IO_REQUESTS];
263 * This field in the array of sequence values for the RNi. These are used
264 * to control io request build to io request start operations. The sequence
265 * value is recorded into an io request when it is built and is checked on
266 * the io request start operation to make sure that there was not a device
267 * hot plug between the build and start operation.
269 u8 remote_device_sequence[SCI_MAX_REMOTE_DEVICES];
272 * This field is a pointer to the memory allocated by the driver for the task
273 * context table. This data is shared between the hardware and software.
275 struct scu_task_context *task_context_table;
278 * This field is a pointer to the memory allocated by the driver for the
279 * remote node context table. This table is shared between the hardware and
282 union scu_remote_node_context *remote_node_context_table;
285 * This field is the array of physical memory requiremets for this controller
288 struct sci_physical_memory_descriptor memory_descriptors[SCU_MAX_MDES];
291 * This field is a pointer to the completion queue. This memory is
292 * written to by the hardware and read by the software.
294 u32 *completion_queue;
297 * This field is the software copy of the completion queue get pointer. The
298 * controller object writes this value to the hardware after processing the
299 * completion entries.
301 u32 completion_queue_get;
304 * This field is the minimum of the number of hardware supported port entries
305 * and the software requested port entries.
307 u32 logical_port_entries;
310 * This field is the minimum number of hardware supported completion queue
311 * entries and the software requested completion queue entries.
313 u32 completion_queue_entries;
316 * This field is the minimum number of hardware supported event entries and
317 * the software requested event entries.
319 u32 completion_event_entries;
322 * This field is the minimum number of devices supported by the hardware and
323 * the number of devices requested by the software.
325 u32 remote_node_entries;
328 * This field is the minimum number of IO requests supported by the hardware
329 * and the number of IO requests requested by the software.
331 u32 task_context_entries;
334 * This object contains all of the unsolicited frame specific
335 * data utilized by the core controller.
337 struct scic_sds_unsolicited_frame_control uf_control;
339 /* Phy Startup Data */
341 * This field is the driver timer handle for controller phy request startup.
342 * On controller start the controller will start each PHY individually in
343 * order of phy index.
345 void *phy_startup_timer;
348 * This field is set when the phy_startup_timer is running and is cleared when
349 * the phy_startup_timer is stopped.
351 bool phy_startup_timer_pending;
354 * This field is the index of the next phy start. It is initialized to 0 and
355 * increments for each phy index that is started.
357 u32 next_phy_to_start;
360 * This field controlls the invalid link up notifications to the SCI_USER. If
361 * an invalid_link_up notification is reported a bit for the PHY index is set
362 * so further notifications are not made. Once the PHY object reports link up
363 * and is made part of a port then this bit for the PHY index is cleared.
368 * This field saves the current interrupt coalescing number of the controller.
370 u16 interrupt_coalesce_number;
373 * This field saves the current interrupt coalescing timeout value in microseconds.
375 u32 interrupt_coalesce_timeout;
378 * This field is a pointer to the memory mapped register space for the
379 * struct smu_registers.
381 struct smu_registers __iomem *smu_registers;
384 * This field is a pointer to the memory mapped register space for the
385 * struct scu_registers.
387 struct scu_registers __iomem *scu_registers;
391 typedef void (*scic_sds_controller_phy_handler_t)(struct scic_sds_controller *,
392 struct scic_sds_port *,
393 struct scic_sds_phy *);
395 typedef void (*scic_sds_controller_device_handler_t)(struct scic_sds_controller *,
396 struct scic_sds_remote_device *);
400 * struct scic_sds_controller_state_handler -
402 * This structure contains the SDS core specific definition for the state
405 struct scic_sds_controller_state_handler {
406 struct sci_base_controller_state_handler base;
408 sci_base_controller_request_handler_t terminate_request;
409 scic_sds_controller_phy_handler_t link_up;
410 scic_sds_controller_phy_handler_t link_down;
411 scic_sds_controller_device_handler_t remote_device_started_handler;
412 scic_sds_controller_device_handler_t remote_device_stopped_handler;
415 extern const struct scic_sds_controller_state_handler
416 scic_sds_controller_state_handler_table[];
417 extern const struct sci_base_state scic_sds_controller_state_table[];
420 * INCREMENT_QUEUE_GET() -
422 * This macro will increment the specified index to and if the index wraps to 0
423 * it will toggel the cycle bit.
425 #define INCREMENT_QUEUE_GET(index, cycle, entry_count, bit_toggle) \
427 if ((index) + 1 == entry_count) { \
429 (cycle) = (cycle) ^ (bit_toggle); \
436 * scic_sds_controller_get_base_state_machine() -
438 * This is a helper macro that gets the base state machine for the controller
441 #define scic_sds_controller_get_base_state_machine(this_controller) \
442 (&(this_controller)->parent.state_machine)
445 * scic_sds_controller_get_port_configuration_agent() -
447 * This is a helper macro to get the port configuration agent from the
450 #define scic_sds_controller_get_port_configuration_agent(controller) \
451 (&(controller)->port_agent)
454 * smu_register_write() -
456 * This macro writes to the smu_register for this controller
458 #define smu_register_write(controller, reg, value) \
459 scic_sds_pci_write_smu_dword((controller), &(reg), (value))
462 * smu_register_read() -
464 * This macro reads the smu_register for this controller
466 #define smu_register_read(controller, reg) \
467 scic_sds_pci_read_smu_dword((controller), &(reg))
470 * scu_register_write() -
472 * This mcaro writes the scu_register for this controller
474 #define scu_register_write(controller, reg, value) \
475 scic_sds_pci_write_scu_dword((controller), &(reg), (value))
478 * scu_register_read() -
480 * This macro reads the scu_register for this controller
482 #define scu_register_read(controller, reg) \
483 scic_sds_pci_read_scu_dword((controller), &(reg))
486 * scic_sds_controller_get_protocol_engine_group() -
488 * This macro returns the protocol engine group for this controller object.
489 * Presently we only support protocol engine group 0 so just return that
491 #define scic_sds_controller_get_protocol_engine_group(controller) 0
494 * scic_sds_io_tag_construct() -
496 * This macro constructs an IO tag from the sequence and index values.
498 #define scic_sds_io_tag_construct(sequence, task_index) \
499 ((sequence) << 12 | (task_index))
502 * scic_sds_io_tag_get_sequence() -
504 * This macro returns the IO sequence from the IO tag value.
506 #define scic_sds_io_tag_get_sequence(io_tag) \
507 (((io_tag) & 0xF000) >> 12)
510 * scic_sds_io_tag_get_index() -
512 * This macro returns the TCi from the io tag value
514 #define scic_sds_io_tag_get_index(io_tag) \
518 * scic_sds_io_sequence_increment() -
520 * This is a helper macro to increment the io sequence count. We may find in
521 * the future that it will be faster to store the sequence count in such a way
522 * as we dont perform the shift operation to build io tag values so therefore
523 * need a way to incrment them correctly
525 #define scic_sds_io_sequence_increment(value) \
526 ((value) = (((value) + 1) & 0x000F))
528 #define scic_sds_remote_device_node_count(device) \
531 (device)->target_protocols.u.bits.attached_stp_target \
532 && ((device)->is_direct_attached != true) \
534 ? SCU_STP_REMOTE_NODE_COUNT : SCU_SSP_REMOTE_NODE_COUNT \
538 * scic_sds_controller_set_invalid_phy() -
540 * This macro will set the bit in the invalid phy mask for this controller
541 * object. This is used to control messages reported for invalid link up
544 #define scic_sds_controller_set_invalid_phy(controller, phy) \
545 ((controller)->invalid_phy_mask |= (1 << (phy)->phy_index))
548 * scic_sds_controller_clear_invalid_phy() -
550 * This macro will clear the bit in the invalid phy mask for this controller
551 * object. This is used to control messages reported for invalid link up
554 #define scic_sds_controller_clear_invalid_phy(controller, phy) \
555 ((controller)->invalid_phy_mask &= ~(1 << (phy)->phy_index))
557 /* --------------------------------------------------------------------------- */
559 u32 scic_sds_controller_get_object_size(void);
561 /* --------------------------------------------------------------------------- */
564 /* --------------------------------------------------------------------------- */
566 enum SCIC_PORT_CONFIGURATION_MODE scic_sds_controller_get_port_configuration_mode(
567 struct scic_sds_controller *this_controller);
569 /* --------------------------------------------------------------------------- */
571 void scic_sds_controller_post_request(
572 struct scic_sds_controller *this_controller,
575 /* --------------------------------------------------------------------------- */
577 void scic_sds_controller_release_frame(
578 struct scic_sds_controller *this_controller,
581 void scic_sds_controller_copy_sata_response(
582 void *response_buffer,
586 /* --------------------------------------------------------------------------- */
588 enum sci_status scic_sds_controller_allocate_remote_node_context(
589 struct scic_sds_controller *this_controller,
590 struct scic_sds_remote_device *the_device,
593 void scic_sds_controller_free_remote_node_context(
594 struct scic_sds_controller *this_controller,
595 struct scic_sds_remote_device *the_device,
598 union scu_remote_node_context *scic_sds_controller_get_remote_node_context_buffer(
599 struct scic_sds_controller *this_controller,
602 /* --------------------------------------------------------------------------- */
604 struct scic_sds_request *scic_sds_controller_get_io_request_from_tag(
605 struct scic_sds_controller *this_controller,
609 struct scu_task_context *scic_sds_controller_get_task_context_buffer(
610 struct scic_sds_controller *this_controller,
614 * *****************************************************************************
615 * * CORE CONTROLLER POWER CONTROL METHODS
616 * ***************************************************************************** */
619 void scic_sds_controller_power_control_queue_insert(
620 struct scic_sds_controller *this_controller,
621 struct scic_sds_phy *the_phy);
623 void scic_sds_controller_power_control_queue_remove(
624 struct scic_sds_controller *this_controller,
625 struct scic_sds_phy *the_phy);
628 * *****************************************************************************
629 * * CORE CONTROLLER PHY MESSAGE PROCESSING
630 * ***************************************************************************** */
632 void scic_sds_controller_link_up(
633 struct scic_sds_controller *this_controller,
634 struct scic_sds_port *the_port,
635 struct scic_sds_phy *the_phy);
637 void scic_sds_controller_link_down(
638 struct scic_sds_controller *this_controller,
639 struct scic_sds_port *the_port,
640 struct scic_sds_phy *the_phy);
643 * *****************************************************************************
644 * * CORE CONTROLLER REMOTE DEVICE MESSAGE PROCESSING
645 * ***************************************************************************** */
647 bool scic_sds_controller_has_remote_devices_stopping(
648 struct scic_sds_controller *this_controller);
650 void scic_sds_controller_remote_device_started(
651 struct scic_sds_controller *this_controller,
652 struct scic_sds_remote_device *the_device);
654 void scic_sds_controller_remote_device_stopped(
655 struct scic_sds_controller *this_controller,
656 struct scic_sds_remote_device *the_device);
660 * *****************************************************************************
661 * * CORE CONTROLLER PRIVATE METHODS
662 * ***************************************************************************** */
664 enum sci_status scic_sds_controller_validate_memory_descriptor_table(
665 struct scic_sds_controller *this_controller);
667 void scic_sds_controller_ram_initialization(
668 struct scic_sds_controller *this_controller);
670 void scic_sds_controller_assign_task_entries(
671 struct scic_sds_controller *this_controller);
673 void scic_sds_controller_afe_initialization(
674 struct scic_sds_controller *this_controller);
676 void scic_sds_controller_enable_port_task_scheduler(
677 struct scic_sds_controller *this_controller);
679 void scic_sds_controller_initialize_completion_queue(
680 struct scic_sds_controller *this_controller);
682 void scic_sds_controller_initialize_unsolicited_frame_queue(
683 struct scic_sds_controller *this_controller);
685 void scic_sds_controller_phy_timer_stop(
686 struct scic_sds_controller *this_controller);
688 enum sci_status scic_sds_controller_start_next_phy(
689 struct scic_sds_controller *this_controller);
691 enum sci_status scic_sds_controller_stop_phys(
692 struct scic_sds_controller *this_controller);
694 enum sci_status scic_sds_controller_stop_ports(
695 struct scic_sds_controller *this_controller);
697 enum sci_status scic_sds_controller_stop_devices(
698 struct scic_sds_controller *this_controller);
700 void scic_sds_controller_copy_task_context(
701 struct scic_sds_controller *this_controller,
702 struct scic_sds_request *this_request);
704 void scic_sds_controller_timeout_handler(
705 struct scic_sds_controller *controller);
707 void scic_sds_controller_initialize_power_control(
708 struct scic_sds_controller *this_controller);
710 void scic_sds_controller_register_setup(
711 struct scic_sds_controller *this_controller);
713 void scic_sds_controller_reset_hardware(
714 struct scic_sds_controller *this_controller);
716 enum sci_status scic_sds_controller_initialize_phy_startup(
717 struct scic_sds_controller *this_controller);
719 void scic_sds_controller_build_memory_descriptor_table(
720 struct scic_sds_controller *this_controller);
722 #endif /* _SCIC_SDS_CONTROLLER_H_ */