isci: remove mmio wrappers
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / scsi / isci / core / scic_sds_controller.h
blobbaf0b9ededecd7894dbad0fc2432478e24a26c0f
1 /*
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.
5 * GPL LICENSE SUMMARY
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.
24 * BSD LICENSE
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
31 * are met:
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
38 * distribution.
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>
60 #include <linux/io.h>
62 /**
63 * This file contains the structures, constants and prototypes used for the
64 * core controller object.
69 #include "sci_pool.h"
70 #include "sci_controller_constants.h"
71 #include "sci_memory_descriptor_list.h"
72 #include "sci_base_controller.h"
73 #include "scic_config_parameters.h"
74 #include "scic_sds_port.h"
75 #include "scic_sds_phy.h"
76 #include "scic_sds_remote_node_table.h"
77 #include "scu_registers.h"
78 #include "scu_constants.h"
79 #include "scu_remote_node_context.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 scic_sds_remote_device;
86 struct scic_sds_request;
87 struct scic_sds_controller;
90 #define SCU_COMPLETION_RAM_ALIGNMENT (64)
92 /**
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 {
99 /**
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.
118 SCU_MDE_UF_BUFFER,
120 SCU_MAX_MDES
125 * struct scic_power_control -
127 * This structure defines the fields for managing power control for direct
128 * attached disk devices.
130 struct scic_power_control {
132 * This field is set when the power control timer is running and cleared when
133 * it is not.
135 bool timer_started;
138 * This field is the handle to the driver timer object. This timer is used to
139 * control when the directed attached disks can consume power.
141 void *timer;
144 * This field is used to keep track of how many phys are put into the
145 * requesters field.
147 u8 phys_waiting;
150 * This field is used to keep track of how many phys have been granted to consume power
152 u8 phys_granted_power;
155 * This field is an array of phys that we are waiting on. The phys are direct
156 * mapped into requesters via struct scic_sds_phy.phy_index
158 struct scic_sds_phy *requesters[SCI_MAX_PHYS];
163 * struct scic_sds_controller -
165 * This structure represents the SCU contoller object.
167 struct scic_sds_controller {
169 * The struct sci_base_controller is the parent object for the struct scic_sds_controller
170 * object.
172 struct sci_base_controller parent;
175 * This field is the driver timer object handler used to time the controller
176 * object start and stop requests.
178 void *timeout_timer;
181 * This field contains the user parameters to be utilized for this
182 * core controller object.
184 union scic_user_parameters user_parameters;
187 * This field contains the OEM parameters to be utilized for this
188 * core controller object.
190 union scic_oem_parameters oem_parameters;
193 * This field contains the port configuration agent for this controller.
195 struct scic_sds_port_configuration_agent port_agent;
198 * This field is the array of port objects that are controlled by this
199 * controller object. There is one dummy port object also contained within
200 * this controller object.
202 struct scic_sds_port port_table[SCI_MAX_PORTS + 1];
205 * This field is the array of phy objects that are controlled by this
206 * controller object.
208 struct scic_sds_phy phy_table[SCI_MAX_PHYS];
211 * This field is the array of device objects that are currently constructed
212 * for this controller object. This table is used as a fast lookup of device
213 * objects that need to handle device completion notifications from the
214 * hardware. The table is RNi based.
216 struct scic_sds_remote_device *device_table[SCI_MAX_REMOTE_DEVICES];
219 * This field is the array of IO request objects that are currently active for
220 * this controller object. This table is used as a fast lookup of the io
221 * request object that need to handle completion queue notifications. The
222 * table is TCi based.
224 struct scic_sds_request *io_request_table[SCI_MAX_IO_REQUESTS];
227 * This field is the free RNi data structure
229 struct scic_remote_node_table available_remote_nodes;
232 * This field is the TCi pool used to manage the task context index.
234 SCI_POOL_CREATE(tci_pool, u16, SCI_MAX_IO_REQUESTS);
237 * This filed is the struct scic_power_control data used to controll when direct
238 * attached devices can consume power.
240 struct scic_power_control power_control;
243 * This field is the array of sequence values for the IO Tag fields. Even
244 * though only 4 bits of the field is used for the sequence the sequence is 16
245 * bits in size so the sequence can be bitwise or'd with the TCi to build the
246 * IO Tag value.
248 u16 io_request_sequence[SCI_MAX_IO_REQUESTS];
251 * This field in the array of sequence values for the RNi. These are used
252 * to control io request build to io request start operations. The sequence
253 * value is recorded into an io request when it is built and is checked on
254 * the io request start operation to make sure that there was not a device
255 * hot plug between the build and start operation.
257 u8 remote_device_sequence[SCI_MAX_REMOTE_DEVICES];
260 * This field is a pointer to the memory allocated by the driver for the task
261 * context table. This data is shared between the hardware and software.
263 struct scu_task_context *task_context_table;
266 * This field is a pointer to the memory allocated by the driver for the
267 * remote node context table. This table is shared between the hardware and
268 * software.
270 union scu_remote_node_context *remote_node_context_table;
273 * This field is the array of physical memory requiremets for this controller
274 * object.
276 struct sci_physical_memory_descriptor memory_descriptors[SCU_MAX_MDES];
279 * This field is a pointer to the completion queue. This memory is
280 * written to by the hardware and read by the software.
282 u32 *completion_queue;
285 * This field is the software copy of the completion queue get pointer. The
286 * controller object writes this value to the hardware after processing the
287 * completion entries.
289 u32 completion_queue_get;
292 * This field is the minimum of the number of hardware supported port entries
293 * and the software requested port entries.
295 u32 logical_port_entries;
298 * This field is the minimum number of hardware supported completion queue
299 * entries and the software requested completion queue entries.
301 u32 completion_queue_entries;
304 * This field is the minimum number of hardware supported event entries and
305 * the software requested event entries.
307 u32 completion_event_entries;
310 * This field is the minimum number of devices supported by the hardware and
311 * the number of devices requested by the software.
313 u32 remote_node_entries;
316 * This field is the minimum number of IO requests supported by the hardware
317 * and the number of IO requests requested by the software.
319 u32 task_context_entries;
322 * This object contains all of the unsolicited frame specific
323 * data utilized by the core controller.
325 struct scic_sds_unsolicited_frame_control uf_control;
327 /* Phy Startup Data */
329 * This field is the driver timer handle for controller phy request startup.
330 * On controller start the controller will start each PHY individually in
331 * order of phy index.
333 void *phy_startup_timer;
336 * This field is set when the phy_startup_timer is running and is cleared when
337 * the phy_startup_timer is stopped.
339 bool phy_startup_timer_pending;
342 * This field is the index of the next phy start. It is initialized to 0 and
343 * increments for each phy index that is started.
345 u32 next_phy_to_start;
348 * This field controlls the invalid link up notifications to the SCI_USER. If
349 * an invalid_link_up notification is reported a bit for the PHY index is set
350 * so further notifications are not made. Once the PHY object reports link up
351 * and is made part of a port then this bit for the PHY index is cleared.
353 u8 invalid_phy_mask;
356 * This field saves the current interrupt coalescing number of the controller.
358 u16 interrupt_coalesce_number;
361 * This field saves the current interrupt coalescing timeout value in microseconds.
363 u32 interrupt_coalesce_timeout;
366 * This field is a pointer to the memory mapped register space for the
367 * struct smu_registers.
369 struct smu_registers __iomem *smu_registers;
372 * This field is a pointer to the memory mapped register space for the
373 * struct scu_registers.
375 struct scu_registers __iomem *scu_registers;
379 typedef void (*scic_sds_controller_phy_handler_t)(struct scic_sds_controller *,
380 struct scic_sds_port *,
381 struct scic_sds_phy *);
383 typedef void (*scic_sds_controller_device_handler_t)(struct scic_sds_controller *,
384 struct scic_sds_remote_device *);
388 * struct scic_sds_controller_state_handler -
390 * This structure contains the SDS core specific definition for the state
391 * handlers.
393 struct scic_sds_controller_state_handler {
394 struct sci_base_controller_state_handler base;
396 sci_base_controller_request_handler_t terminate_request;
397 scic_sds_controller_phy_handler_t link_up;
398 scic_sds_controller_phy_handler_t link_down;
399 scic_sds_controller_device_handler_t device_stopped;
402 extern const struct scic_sds_controller_state_handler
403 scic_sds_controller_state_handler_table[];
406 * INCREMENT_QUEUE_GET() -
408 * This macro will increment the specified index to and if the index wraps to 0
409 * it will toggel the cycle bit.
411 #define INCREMENT_QUEUE_GET(index, cycle, entry_count, bit_toggle) \
413 if ((index) + 1 == entry_count) { \
414 (index) = 0; \
415 (cycle) = (cycle) ^ (bit_toggle); \
416 } else { \
417 index = index + 1; \
422 * scic_sds_controller_get_port_configuration_agent() -
424 * This is a helper macro to get the port configuration agent from the
425 * controller object.
427 #define scic_sds_controller_get_port_configuration_agent(controller) \
428 (&(controller)->port_agent)
431 * scic_sds_controller_get_protocol_engine_group() -
433 * This macro returns the protocol engine group for this controller object.
434 * Presently we only support protocol engine group 0 so just return that
436 #define scic_sds_controller_get_protocol_engine_group(controller) 0
439 * scic_sds_io_tag_construct() -
441 * This macro constructs an IO tag from the sequence and index values.
443 #define scic_sds_io_tag_construct(sequence, task_index) \
444 ((sequence) << 12 | (task_index))
447 * scic_sds_io_tag_get_sequence() -
449 * This macro returns the IO sequence from the IO tag value.
451 #define scic_sds_io_tag_get_sequence(io_tag) \
452 (((io_tag) & 0xF000) >> 12)
455 * scic_sds_io_tag_get_index() -
457 * This macro returns the TCi from the io tag value
459 #define scic_sds_io_tag_get_index(io_tag) \
460 ((io_tag) & 0x0FFF)
463 * scic_sds_io_sequence_increment() -
465 * This is a helper macro to increment the io sequence count. We may find in
466 * the future that it will be faster to store the sequence count in such a way
467 * as we dont perform the shift operation to build io tag values so therefore
468 * need a way to incrment them correctly
470 #define scic_sds_io_sequence_increment(value) \
471 ((value) = (((value) + 1) & 0x000F))
473 #define scic_sds_remote_device_node_count(device) \
476 (device)->target_protocols.u.bits.attached_stp_target \
477 && ((device)->is_direct_attached != true) \
479 ? SCU_STP_REMOTE_NODE_COUNT : SCU_SSP_REMOTE_NODE_COUNT \
483 * scic_sds_controller_set_invalid_phy() -
485 * This macro will set the bit in the invalid phy mask for this controller
486 * object. This is used to control messages reported for invalid link up
487 * notifications.
489 #define scic_sds_controller_set_invalid_phy(controller, phy) \
490 ((controller)->invalid_phy_mask |= (1 << (phy)->phy_index))
493 * scic_sds_controller_clear_invalid_phy() -
495 * This macro will clear the bit in the invalid phy mask for this controller
496 * object. This is used to control messages reported for invalid link up
497 * notifications.
499 #define scic_sds_controller_clear_invalid_phy(controller, phy) \
500 ((controller)->invalid_phy_mask &= ~(1 << (phy)->phy_index))
502 void scic_sds_controller_post_request(
503 struct scic_sds_controller *this_controller,
504 u32 request);
506 void scic_sds_controller_release_frame(
507 struct scic_sds_controller *this_controller,
508 u32 frame_index);
510 void scic_sds_controller_copy_sata_response(
511 void *response_buffer,
512 void *frame_header,
513 void *frame_buffer);
515 enum sci_status scic_sds_controller_allocate_remote_node_context(
516 struct scic_sds_controller *this_controller,
517 struct scic_sds_remote_device *the_device,
518 u16 *node_id);
520 void scic_sds_controller_free_remote_node_context(
521 struct scic_sds_controller *this_controller,
522 struct scic_sds_remote_device *the_device,
523 u16 node_id);
525 union scu_remote_node_context *scic_sds_controller_get_remote_node_context_buffer(
526 struct scic_sds_controller *this_controller,
527 u16 node_id);
529 struct scic_sds_request *scic_sds_controller_get_io_request_from_tag(
530 struct scic_sds_controller *this_controller,
531 u16 io_tag);
534 struct scu_task_context *scic_sds_controller_get_task_context_buffer(
535 struct scic_sds_controller *this_controller,
536 u16 io_tag);
538 void scic_sds_controller_power_control_queue_insert(
539 struct scic_sds_controller *this_controller,
540 struct scic_sds_phy *the_phy);
542 void scic_sds_controller_power_control_queue_remove(
543 struct scic_sds_controller *this_controller,
544 struct scic_sds_phy *the_phy);
546 void scic_sds_controller_link_up(
547 struct scic_sds_controller *this_controller,
548 struct scic_sds_port *the_port,
549 struct scic_sds_phy *the_phy);
551 void scic_sds_controller_link_down(
552 struct scic_sds_controller *this_controller,
553 struct scic_sds_port *the_port,
554 struct scic_sds_phy *the_phy);
556 void scic_sds_controller_remote_device_stopped(
557 struct scic_sds_controller *this_controller,
558 struct scic_sds_remote_device *the_device);
560 void scic_sds_controller_copy_task_context(
561 struct scic_sds_controller *this_controller,
562 struct scic_sds_request *this_request);
564 void scic_sds_controller_register_setup(
565 struct scic_sds_controller *this_controller);
567 #endif /* _SCIC_SDS_CONTROLLER_H_ */