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>
63 * This file contains the structures, constants and prototypes used for the
64 * core controller object.
70 #include "sci_controller_constants.h"
71 #include "sci_base_state.h"
72 #include "sci_base_state_machine.h"
73 #include "scic_config_parameters.h"
74 #include "scic_sds_port.h"
75 #include "scic_sds_phy.h"
76 #include "remote_node_table.h"
77 #include "remote_device.h"
78 #include "scu_registers.h"
79 #include "scu_constants.h"
80 #include "scu_task_context.h"
81 #include "scu_unsolicited_frame.h"
82 #include "scic_sds_unsolicited_frame_control.h"
83 #include "scic_sds_port_configuration_agent.h"
85 struct sci_base_remote_device
;
86 struct scic_sds_remote_device
;
87 struct scic_sds_request
;
88 struct scic_sds_controller
;
91 * struct scic_power_control -
93 * This structure defines the fields for managing power control for direct
94 * attached disk devices.
96 struct scic_power_control
{
98 * This field is set when the power control timer is running and cleared when
104 * This field is the handle to the driver timer object. This timer is used to
105 * control when the directed attached disks can consume power.
110 * This field is used to keep track of how many phys are put into the
116 * This field is used to keep track of how many phys have been granted to consume power
118 u8 phys_granted_power
;
121 * This field is an array of phys that we are waiting on. The phys are direct
122 * mapped into requesters via struct scic_sds_phy.phy_index
124 struct scic_sds_phy
*requesters
[SCI_MAX_PHYS
];
129 * struct scic_sds_controller -
131 * This structure represents the SCU controller object.
133 struct scic_sds_controller
{
135 * This field contains the information for the base controller state
138 struct sci_base_state_machine state_machine
;
141 * This field is the driver timer object handler used to time the controller
142 * object start and stop requests.
147 * This field contains the user parameters to be utilized for this
148 * core controller object.
150 union scic_user_parameters user_parameters
;
153 * This field contains the OEM parameters to be utilized for this
154 * core controller object.
156 union scic_oem_parameters oem_parameters
;
159 * This field contains the port configuration agent for this controller.
161 struct scic_sds_port_configuration_agent port_agent
;
164 * This field is the array of device objects that are currently constructed
165 * for this controller object. This table is used as a fast lookup of device
166 * objects that need to handle device completion notifications from the
167 * hardware. The table is RNi based.
169 struct scic_sds_remote_device
*device_table
[SCI_MAX_REMOTE_DEVICES
];
172 * This field is the array of IO request objects that are currently active for
173 * this controller object. This table is used as a fast lookup of the io
174 * request object that need to handle completion queue notifications. The
175 * table is TCi based.
177 struct scic_sds_request
*io_request_table
[SCI_MAX_IO_REQUESTS
];
180 * This field is the free RNi data structure
182 struct scic_remote_node_table available_remote_nodes
;
185 * This field is the TCi pool used to manage the task context index.
187 SCI_POOL_CREATE(tci_pool
, u16
, SCI_MAX_IO_REQUESTS
);
190 * This filed is the struct scic_power_control data used to controll when direct
191 * attached devices can consume power.
193 struct scic_power_control power_control
;
196 * This field is the array of sequence values for the IO Tag fields. Even
197 * though only 4 bits of the field is used for the sequence the sequence is 16
198 * bits in size so the sequence can be bitwise or'd with the TCi to build the
201 u16 io_request_sequence
[SCI_MAX_IO_REQUESTS
];
204 * This field in the array of sequence values for the RNi. These are used
205 * to control io request build to io request start operations. The sequence
206 * value is recorded into an io request when it is built and is checked on
207 * the io request start operation to make sure that there was not a device
208 * hot plug between the build and start operation.
210 u8 remote_device_sequence
[SCI_MAX_REMOTE_DEVICES
];
213 * This field is a pointer to the memory allocated by the driver for the task
214 * context table. This data is shared between the hardware and software.
216 struct scu_task_context
*task_context_table
;
219 * This field is a pointer to the memory allocated by the driver for the
220 * remote node context table. This table is shared between the hardware and
223 union scu_remote_node_context
*remote_node_context_table
;
226 * This field is a pointer to the completion queue. This memory is
227 * written to by the hardware and read by the software.
229 u32
*completion_queue
;
232 * This field is the software copy of the completion queue get pointer. The
233 * controller object writes this value to the hardware after processing the
234 * completion entries.
236 u32 completion_queue_get
;
239 * This field is the minimum of the number of hardware supported port entries
240 * and the software requested port entries.
242 u32 logical_port_entries
;
245 * This field is the minimum number of hardware supported completion queue
246 * entries and the software requested completion queue entries.
248 u32 completion_queue_entries
;
251 * This field is the minimum number of hardware supported event entries and
252 * the software requested event entries.
254 u32 completion_event_entries
;
257 * This field is the minimum number of devices supported by the hardware and
258 * the number of devices requested by the software.
260 u32 remote_node_entries
;
263 * This field is the minimum number of IO requests supported by the hardware
264 * and the number of IO requests requested by the software.
266 u32 task_context_entries
;
269 * This object contains all of the unsolicited frame specific
270 * data utilized by the core controller.
272 struct scic_sds_unsolicited_frame_control uf_control
;
274 /* Phy Startup Data */
276 * This field is the driver timer handle for controller phy request startup.
277 * On controller start the controller will start each PHY individually in
278 * order of phy index.
280 void *phy_startup_timer
;
283 * This field is set when the phy_startup_timer is running and is cleared when
284 * the phy_startup_timer is stopped.
286 bool phy_startup_timer_pending
;
289 * This field is the index of the next phy start. It is initialized to 0 and
290 * increments for each phy index that is started.
292 u32 next_phy_to_start
;
295 * This field controlls the invalid link up notifications to the SCI_USER. If
296 * an invalid_link_up notification is reported a bit for the PHY index is set
297 * so further notifications are not made. Once the PHY object reports link up
298 * and is made part of a port then this bit for the PHY index is cleared.
303 * This field saves the current interrupt coalescing number of the controller.
305 u16 interrupt_coalesce_number
;
308 * This field saves the current interrupt coalescing timeout value in microseconds.
310 u32 interrupt_coalesce_timeout
;
313 * This field is a pointer to the memory mapped register space for the
314 * struct smu_registers.
316 struct smu_registers __iomem
*smu_registers
;
319 * This field is a pointer to the memory mapped register space for the
320 * struct scu_registers.
322 struct scu_registers __iomem
*scu_registers
;
327 * enum scic_sds_controller_states - This enumeration depicts all the states
328 * for the common controller state machine.
330 enum scic_sds_controller_states
{
332 * Simply the initial state for the base controller state machine.
334 SCI_BASE_CONTROLLER_STATE_INITIAL
= 0,
337 * This state indicates that the controller is reset. The memory for
338 * the controller is in it's initial state, but the controller requires
340 * This state is entered from the INITIAL state.
341 * This state is entered from the RESETTING state.
343 SCI_BASE_CONTROLLER_STATE_RESET
,
346 * This state is typically an action state that indicates the controller
347 * is in the process of initialization. In this state no new IO operations
349 * This state is entered from the RESET state.
351 SCI_BASE_CONTROLLER_STATE_INITIALIZING
,
354 * This state indicates that the controller has been successfully
355 * initialized. In this state no new IO operations are permitted.
356 * This state is entered from the INITIALIZING state.
358 SCI_BASE_CONTROLLER_STATE_INITIALIZED
,
361 * This state indicates the the controller is in the process of becoming
362 * ready (i.e. starting). In this state no new IO operations are permitted.
363 * This state is entered from the INITIALIZED state.
365 SCI_BASE_CONTROLLER_STATE_STARTING
,
368 * This state indicates the controller is now ready. Thus, the user
369 * is able to perform IO operations on the controller.
370 * This state is entered from the STARTING state.
372 SCI_BASE_CONTROLLER_STATE_READY
,
375 * This state is typically an action state that indicates the controller
376 * is in the process of resetting. Thus, the user is unable to perform
377 * IO operations on the controller. A reset is considered destructive in
379 * This state is entered from the READY state.
380 * This state is entered from the FAILED state.
381 * This state is entered from the STOPPED state.
383 SCI_BASE_CONTROLLER_STATE_RESETTING
,
386 * This state indicates that the controller is in the process of stopping.
387 * In this state no new IO operations are permitted, but existing IO
388 * operations are allowed to complete.
389 * This state is entered from the READY state.
391 SCI_BASE_CONTROLLER_STATE_STOPPING
,
394 * This state indicates that the controller has successfully been stopped.
395 * In this state no new IO operations are permitted.
396 * This state is entered from the STOPPING state.
398 SCI_BASE_CONTROLLER_STATE_STOPPED
,
401 * This state indicates that the controller could not successfully be
402 * initialized. In this state no new IO operations are permitted.
403 * This state is entered from the INITIALIZING state.
404 * This state is entered from the STARTING state.
405 * This state is entered from the STOPPING state.
406 * This state is entered from the RESETTING state.
408 SCI_BASE_CONTROLLER_STATE_FAILED
,
410 SCI_BASE_CONTROLLER_MAX_STATES
415 * INCREMENT_QUEUE_GET() -
417 * This macro will increment the specified index to and if the index wraps to 0
418 * it will toggel the cycle bit.
420 #define INCREMENT_QUEUE_GET(index, cycle, entry_count, bit_toggle) \
422 if ((index) + 1 == entry_count) { \
424 (cycle) = (cycle) ^ (bit_toggle); \
431 * scic_sds_controller_get_port_configuration_agent() -
433 * This is a helper macro to get the port configuration agent from the
436 #define scic_sds_controller_get_port_configuration_agent(controller) \
437 (&(controller)->port_agent)
440 * scic_sds_controller_get_protocol_engine_group() -
442 * This macro returns the protocol engine group for this controller object.
443 * Presently we only support protocol engine group 0 so just return that
445 #define scic_sds_controller_get_protocol_engine_group(controller) 0
448 * scic_sds_io_tag_construct() -
450 * This macro constructs an IO tag from the sequence and index values.
452 #define scic_sds_io_tag_construct(sequence, task_index) \
453 ((sequence) << 12 | (task_index))
456 * scic_sds_io_tag_get_sequence() -
458 * This macro returns the IO sequence from the IO tag value.
460 #define scic_sds_io_tag_get_sequence(io_tag) \
461 (((io_tag) & 0xF000) >> 12)
464 * scic_sds_io_tag_get_index() -
466 * This macro returns the TCi from the io tag value
468 #define scic_sds_io_tag_get_index(io_tag) \
472 * scic_sds_io_sequence_increment() -
474 * This is a helper macro to increment the io sequence count. We may find in
475 * the future that it will be faster to store the sequence count in such a way
476 * as we dont perform the shift operation to build io tag values so therefore
477 * need a way to incrment them correctly
479 #define scic_sds_io_sequence_increment(value) \
480 ((value) = (((value) + 1) & 0x000F))
482 /* expander attached sata devices require 3 rnc slots */
483 static inline int scic_sds_remote_device_node_count(struct scic_sds_remote_device
*sci_dev
)
485 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
487 if ((dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
)) &&
488 !sci_dev
->is_direct_attached
)
489 return SCU_STP_REMOTE_NODE_COUNT
;
490 return SCU_SSP_REMOTE_NODE_COUNT
;
494 * scic_sds_controller_set_invalid_phy() -
496 * This macro will set the bit in the invalid phy mask for this controller
497 * object. This is used to control messages reported for invalid link up
500 #define scic_sds_controller_set_invalid_phy(controller, phy) \
501 ((controller)->invalid_phy_mask |= (1 << (phy)->phy_index))
504 * scic_sds_controller_clear_invalid_phy() -
506 * This macro will clear the bit in the invalid phy mask for this controller
507 * object. This is used to control messages reported for invalid link up
510 #define scic_sds_controller_clear_invalid_phy(controller, phy) \
511 ((controller)->invalid_phy_mask &= ~(1 << (phy)->phy_index))
513 void scic_sds_controller_post_request(
514 struct scic_sds_controller
*this_controller
,
517 void scic_sds_controller_release_frame(
518 struct scic_sds_controller
*this_controller
,
521 void scic_sds_controller_copy_sata_response(
522 void *response_buffer
,
526 enum sci_status
scic_sds_controller_allocate_remote_node_context(
527 struct scic_sds_controller
*this_controller
,
528 struct scic_sds_remote_device
*sci_dev
,
531 void scic_sds_controller_free_remote_node_context(
532 struct scic_sds_controller
*this_controller
,
533 struct scic_sds_remote_device
*sci_dev
,
536 union scu_remote_node_context
*scic_sds_controller_get_remote_node_context_buffer(
537 struct scic_sds_controller
*this_controller
,
540 struct scic_sds_request
*scic_request_by_tag(struct scic_sds_controller
*scic
,
543 struct scu_task_context
*scic_sds_controller_get_task_context_buffer(
544 struct scic_sds_controller
*this_controller
,
547 void scic_sds_controller_power_control_queue_insert(
548 struct scic_sds_controller
*this_controller
,
549 struct scic_sds_phy
*sci_phy
);
551 void scic_sds_controller_power_control_queue_remove(
552 struct scic_sds_controller
*this_controller
,
553 struct scic_sds_phy
*sci_phy
);
555 void scic_sds_controller_link_up(
556 struct scic_sds_controller
*this_controller
,
557 struct scic_sds_port
*sci_port
,
558 struct scic_sds_phy
*sci_phy
);
560 void scic_sds_controller_link_down(
561 struct scic_sds_controller
*this_controller
,
562 struct scic_sds_port
*sci_port
,
563 struct scic_sds_phy
*sci_phy
);
565 void scic_sds_controller_remote_device_stopped(
566 struct scic_sds_controller
*this_controller
,
567 struct scic_sds_remote_device
*sci_dev
);
569 void scic_sds_controller_copy_task_context(
570 struct scic_sds_controller
*this_controller
,
571 struct scic_sds_request
*this_request
);
573 void scic_sds_controller_register_setup(
574 struct scic_sds_controller
*this_controller
);
576 enum sci_status
scic_controller_continue_io(struct scic_sds_request
*sci_req
);
578 #endif /* _SCIC_SDS_CONTROLLER_H_ */