isci: unify constants
[deliverable/linux.git] / drivers / scsi / isci / core / scic_sds_controller.h
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.
4 *
5 * GPL LICENSE SUMMARY
6 *
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8 *
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.
12 *
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.
17 *
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.
23 *
24 * BSD LICENSE
25 *
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 *
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.
42 *
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.
54 */
55
56 #ifndef _SCIC_SDS_CONTROLLER_H_
57 #define _SCIC_SDS_CONTROLLER_H_
58
59 #include <linux/string.h>
60 #include <linux/io.h>
61
62 /**
63 * This file contains the structures, constants and prototypes used for the
64 * core controller object.
65 *
66 *
67 */
68
69 #include "sci_pool.h"
70 #include "sci_base_state.h"
71 #include "sci_base_state_machine.h"
72 #include "scic_config_parameters.h"
73 #include "scic_sds_port.h"
74 #include "scic_sds_phy.h"
75 #include "remote_node_table.h"
76 #include "remote_device.h"
77 #include "scu_registers.h"
78 #include "scu_task_context.h"
79 #include "scu_unsolicited_frame.h"
80 #include "scic_sds_unsolicited_frame_control.h"
81 #include "scic_sds_port_configuration_agent.h"
82
83 struct sci_base_remote_device;
84 struct scic_sds_remote_device;
85 struct scic_sds_request;
86 struct scic_sds_controller;
87
88 /**
89 * struct scic_power_control -
90 *
91 * This structure defines the fields for managing power control for direct
92 * attached disk devices.
93 */
94 struct scic_power_control {
95 /**
96 * This field is set when the power control timer is running and cleared when
97 * it is not.
98 */
99 bool timer_started;
100
101 /**
102 * This field is the handle to the driver timer object. This timer is used to
103 * control when the directed attached disks can consume power.
104 */
105 void *timer;
106
107 /**
108 * This field is used to keep track of how many phys are put into the
109 * requesters field.
110 */
111 u8 phys_waiting;
112
113 /**
114 * This field is used to keep track of how many phys have been granted to consume power
115 */
116 u8 phys_granted_power;
117
118 /**
119 * This field is an array of phys that we are waiting on. The phys are direct
120 * mapped into requesters via struct scic_sds_phy.phy_index
121 */
122 struct scic_sds_phy *requesters[SCI_MAX_PHYS];
123
124 };
125
126 /**
127 * struct scic_sds_controller -
128 *
129 * This structure represents the SCU controller object.
130 */
131 struct scic_sds_controller {
132 /**
133 * This field contains the information for the base controller state
134 * machine.
135 */
136 struct sci_base_state_machine state_machine;
137
138 /**
139 * This field is the driver timer object handler used to time the controller
140 * object start and stop requests.
141 */
142 void *timeout_timer;
143
144 /**
145 * This field contains the user parameters to be utilized for this
146 * core controller object.
147 */
148 union scic_user_parameters user_parameters;
149
150 /**
151 * This field contains the OEM parameters to be utilized for this
152 * core controller object.
153 */
154 union scic_oem_parameters oem_parameters;
155
156 /**
157 * This field contains the port configuration agent for this controller.
158 */
159 struct scic_sds_port_configuration_agent port_agent;
160
161 /**
162 * This field is the array of device objects that are currently constructed
163 * for this controller object. This table is used as a fast lookup of device
164 * objects that need to handle device completion notifications from the
165 * hardware. The table is RNi based.
166 */
167 struct scic_sds_remote_device *device_table[SCI_MAX_REMOTE_DEVICES];
168
169 /**
170 * This field is the array of IO request objects that are currently active for
171 * this controller object. This table is used as a fast lookup of the io
172 * request object that need to handle completion queue notifications. The
173 * table is TCi based.
174 */
175 struct scic_sds_request *io_request_table[SCI_MAX_IO_REQUESTS];
176
177 /**
178 * This field is the free RNi data structure
179 */
180 struct scic_remote_node_table available_remote_nodes;
181
182 /**
183 * This field is the TCi pool used to manage the task context index.
184 */
185 SCI_POOL_CREATE(tci_pool, u16, SCI_MAX_IO_REQUESTS);
186
187 /**
188 * This filed is the struct scic_power_control data used to controll when direct
189 * attached devices can consume power.
190 */
191 struct scic_power_control power_control;
192
193 /**
194 * This field is the array of sequence values for the IO Tag fields. Even
195 * though only 4 bits of the field is used for the sequence the sequence is 16
196 * bits in size so the sequence can be bitwise or'd with the TCi to build the
197 * IO Tag value.
198 */
199 u16 io_request_sequence[SCI_MAX_IO_REQUESTS];
200
201 /**
202 * This field in the array of sequence values for the RNi. These are used
203 * to control io request build to io request start operations. The sequence
204 * value is recorded into an io request when it is built and is checked on
205 * the io request start operation to make sure that there was not a device
206 * hot plug between the build and start operation.
207 */
208 u8 remote_device_sequence[SCI_MAX_REMOTE_DEVICES];
209
210 /**
211 * This field is a pointer to the memory allocated by the driver for the task
212 * context table. This data is shared between the hardware and software.
213 */
214 struct scu_task_context *task_context_table;
215
216 /**
217 * This field is a pointer to the memory allocated by the driver for the
218 * remote node context table. This table is shared between the hardware and
219 * software.
220 */
221 union scu_remote_node_context *remote_node_context_table;
222
223 /**
224 * This field is a pointer to the completion queue. This memory is
225 * written to by the hardware and read by the software.
226 */
227 u32 *completion_queue;
228
229 /**
230 * This field is the software copy of the completion queue get pointer. The
231 * controller object writes this value to the hardware after processing the
232 * completion entries.
233 */
234 u32 completion_queue_get;
235
236 /**
237 * This field is the minimum of the number of hardware supported port entries
238 * and the software requested port entries.
239 */
240 u32 logical_port_entries;
241
242 /**
243 * This field is the minimum number of hardware supported completion queue
244 * entries and the software requested completion queue entries.
245 */
246 u32 completion_queue_entries;
247
248 /**
249 * This field is the minimum number of hardware supported event entries and
250 * the software requested event entries.
251 */
252 u32 completion_event_entries;
253
254 /**
255 * This field is the minimum number of devices supported by the hardware and
256 * the number of devices requested by the software.
257 */
258 u32 remote_node_entries;
259
260 /**
261 * This field is the minimum number of IO requests supported by the hardware
262 * and the number of IO requests requested by the software.
263 */
264 u32 task_context_entries;
265
266 /**
267 * This object contains all of the unsolicited frame specific
268 * data utilized by the core controller.
269 */
270 struct scic_sds_unsolicited_frame_control uf_control;
271
272 /* Phy Startup Data */
273 /**
274 * This field is the driver timer handle for controller phy request startup.
275 * On controller start the controller will start each PHY individually in
276 * order of phy index.
277 */
278 void *phy_startup_timer;
279
280 /**
281 * This field is set when the phy_startup_timer is running and is cleared when
282 * the phy_startup_timer is stopped.
283 */
284 bool phy_startup_timer_pending;
285
286 /**
287 * This field is the index of the next phy start. It is initialized to 0 and
288 * increments for each phy index that is started.
289 */
290 u32 next_phy_to_start;
291
292 /**
293 * This field controlls the invalid link up notifications to the SCI_USER. If
294 * an invalid_link_up notification is reported a bit for the PHY index is set
295 * so further notifications are not made. Once the PHY object reports link up
296 * and is made part of a port then this bit for the PHY index is cleared.
297 */
298 u8 invalid_phy_mask;
299
300 /*
301 * This field saves the current interrupt coalescing number of the controller.
302 */
303 u16 interrupt_coalesce_number;
304
305 /*
306 * This field saves the current interrupt coalescing timeout value in microseconds.
307 */
308 u32 interrupt_coalesce_timeout;
309
310 /**
311 * This field is a pointer to the memory mapped register space for the
312 * struct smu_registers.
313 */
314 struct smu_registers __iomem *smu_registers;
315
316 /**
317 * This field is a pointer to the memory mapped register space for the
318 * struct scu_registers.
319 */
320 struct scu_registers __iomem *scu_registers;
321
322 };
323
324 /**
325 * enum scic_sds_controller_states - This enumeration depicts all the states
326 * for the common controller state machine.
327 */
328 enum scic_sds_controller_states {
329 /**
330 * Simply the initial state for the base controller state machine.
331 */
332 SCI_BASE_CONTROLLER_STATE_INITIAL = 0,
333
334 /**
335 * This state indicates that the controller is reset. The memory for
336 * the controller is in it's initial state, but the controller requires
337 * initialization.
338 * This state is entered from the INITIAL state.
339 * This state is entered from the RESETTING state.
340 */
341 SCI_BASE_CONTROLLER_STATE_RESET,
342
343 /**
344 * This state is typically an action state that indicates the controller
345 * is in the process of initialization. In this state no new IO operations
346 * are permitted.
347 * This state is entered from the RESET state.
348 */
349 SCI_BASE_CONTROLLER_STATE_INITIALIZING,
350
351 /**
352 * This state indicates that the controller has been successfully
353 * initialized. In this state no new IO operations are permitted.
354 * This state is entered from the INITIALIZING state.
355 */
356 SCI_BASE_CONTROLLER_STATE_INITIALIZED,
357
358 /**
359 * This state indicates the the controller is in the process of becoming
360 * ready (i.e. starting). In this state no new IO operations are permitted.
361 * This state is entered from the INITIALIZED state.
362 */
363 SCI_BASE_CONTROLLER_STATE_STARTING,
364
365 /**
366 * This state indicates the controller is now ready. Thus, the user
367 * is able to perform IO operations on the controller.
368 * This state is entered from the STARTING state.
369 */
370 SCI_BASE_CONTROLLER_STATE_READY,
371
372 /**
373 * This state is typically an action state that indicates the controller
374 * is in the process of resetting. Thus, the user is unable to perform
375 * IO operations on the controller. A reset is considered destructive in
376 * most cases.
377 * This state is entered from the READY state.
378 * This state is entered from the FAILED state.
379 * This state is entered from the STOPPED state.
380 */
381 SCI_BASE_CONTROLLER_STATE_RESETTING,
382
383 /**
384 * This state indicates that the controller is in the process of stopping.
385 * In this state no new IO operations are permitted, but existing IO
386 * operations are allowed to complete.
387 * This state is entered from the READY state.
388 */
389 SCI_BASE_CONTROLLER_STATE_STOPPING,
390
391 /**
392 * This state indicates that the controller has successfully been stopped.
393 * In this state no new IO operations are permitted.
394 * This state is entered from the STOPPING state.
395 */
396 SCI_BASE_CONTROLLER_STATE_STOPPED,
397
398 /**
399 * This state indicates that the controller could not successfully be
400 * initialized. In this state no new IO operations are permitted.
401 * This state is entered from the INITIALIZING state.
402 * This state is entered from the STARTING state.
403 * This state is entered from the STOPPING state.
404 * This state is entered from the RESETTING state.
405 */
406 SCI_BASE_CONTROLLER_STATE_FAILED,
407
408 SCI_BASE_CONTROLLER_MAX_STATES
409
410 };
411
412 /**
413 * INCREMENT_QUEUE_GET() -
414 *
415 * This macro will increment the specified index to and if the index wraps to 0
416 * it will toggel the cycle bit.
417 */
418 #define INCREMENT_QUEUE_GET(index, cycle, entry_count, bit_toggle) \
419 { \
420 if ((index) + 1 == entry_count) { \
421 (index) = 0; \
422 (cycle) = (cycle) ^ (bit_toggle); \
423 } else { \
424 index = index + 1; \
425 } \
426 }
427
428 /**
429 * scic_sds_controller_get_port_configuration_agent() -
430 *
431 * This is a helper macro to get the port configuration agent from the
432 * controller object.
433 */
434 #define scic_sds_controller_get_port_configuration_agent(controller) \
435 (&(controller)->port_agent)
436
437 /**
438 * scic_sds_controller_get_protocol_engine_group() -
439 *
440 * This macro returns the protocol engine group for this controller object.
441 * Presently we only support protocol engine group 0 so just return that
442 */
443 #define scic_sds_controller_get_protocol_engine_group(controller) 0
444
445 /**
446 * scic_sds_io_tag_construct() -
447 *
448 * This macro constructs an IO tag from the sequence and index values.
449 */
450 #define scic_sds_io_tag_construct(sequence, task_index) \
451 ((sequence) << 12 | (task_index))
452
453 /**
454 * scic_sds_io_tag_get_sequence() -
455 *
456 * This macro returns the IO sequence from the IO tag value.
457 */
458 #define scic_sds_io_tag_get_sequence(io_tag) \
459 (((io_tag) & 0xF000) >> 12)
460
461 /**
462 * scic_sds_io_tag_get_index() -
463 *
464 * This macro returns the TCi from the io tag value
465 */
466 #define scic_sds_io_tag_get_index(io_tag) \
467 ((io_tag) & 0x0FFF)
468
469 /**
470 * scic_sds_io_sequence_increment() -
471 *
472 * This is a helper macro to increment the io sequence count. We may find in
473 * the future that it will be faster to store the sequence count in such a way
474 * as we dont perform the shift operation to build io tag values so therefore
475 * need a way to incrment them correctly
476 */
477 #define scic_sds_io_sequence_increment(value) \
478 ((value) = (((value) + 1) & 0x000F))
479
480 /* expander attached sata devices require 3 rnc slots */
481 static inline int scic_sds_remote_device_node_count(struct scic_sds_remote_device *sci_dev)
482 {
483 struct domain_device *dev = sci_dev_to_domain(sci_dev);
484
485 if ((dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) &&
486 !sci_dev->is_direct_attached)
487 return SCU_STP_REMOTE_NODE_COUNT;
488 return SCU_SSP_REMOTE_NODE_COUNT;
489 }
490
491 /**
492 * scic_sds_controller_set_invalid_phy() -
493 *
494 * This macro will set the bit in the invalid phy mask for this controller
495 * object. This is used to control messages reported for invalid link up
496 * notifications.
497 */
498 #define scic_sds_controller_set_invalid_phy(controller, phy) \
499 ((controller)->invalid_phy_mask |= (1 << (phy)->phy_index))
500
501 /**
502 * scic_sds_controller_clear_invalid_phy() -
503 *
504 * This macro will clear the bit in the invalid phy mask for this controller
505 * object. This is used to control messages reported for invalid link up
506 * notifications.
507 */
508 #define scic_sds_controller_clear_invalid_phy(controller, phy) \
509 ((controller)->invalid_phy_mask &= ~(1 << (phy)->phy_index))
510
511 void scic_sds_controller_post_request(
512 struct scic_sds_controller *this_controller,
513 u32 request);
514
515 void scic_sds_controller_release_frame(
516 struct scic_sds_controller *this_controller,
517 u32 frame_index);
518
519 void scic_sds_controller_copy_sata_response(
520 void *response_buffer,
521 void *frame_header,
522 void *frame_buffer);
523
524 enum sci_status scic_sds_controller_allocate_remote_node_context(
525 struct scic_sds_controller *this_controller,
526 struct scic_sds_remote_device *sci_dev,
527 u16 *node_id);
528
529 void scic_sds_controller_free_remote_node_context(
530 struct scic_sds_controller *this_controller,
531 struct scic_sds_remote_device *sci_dev,
532 u16 node_id);
533
534 union scu_remote_node_context *scic_sds_controller_get_remote_node_context_buffer(
535 struct scic_sds_controller *this_controller,
536 u16 node_id);
537
538 struct scic_sds_request *scic_request_by_tag(struct scic_sds_controller *scic,
539 u16 io_tag);
540
541 struct scu_task_context *scic_sds_controller_get_task_context_buffer(
542 struct scic_sds_controller *this_controller,
543 u16 io_tag);
544
545 void scic_sds_controller_power_control_queue_insert(
546 struct scic_sds_controller *this_controller,
547 struct scic_sds_phy *sci_phy);
548
549 void scic_sds_controller_power_control_queue_remove(
550 struct scic_sds_controller *this_controller,
551 struct scic_sds_phy *sci_phy);
552
553 void scic_sds_controller_link_up(
554 struct scic_sds_controller *this_controller,
555 struct scic_sds_port *sci_port,
556 struct scic_sds_phy *sci_phy);
557
558 void scic_sds_controller_link_down(
559 struct scic_sds_controller *this_controller,
560 struct scic_sds_port *sci_port,
561 struct scic_sds_phy *sci_phy);
562
563 void scic_sds_controller_remote_device_stopped(
564 struct scic_sds_controller *this_controller,
565 struct scic_sds_remote_device *sci_dev);
566
567 void scic_sds_controller_copy_task_context(
568 struct scic_sds_controller *this_controller,
569 struct scic_sds_request *this_request);
570
571 void scic_sds_controller_register_setup(
572 struct scic_sds_controller *this_controller);
573
574 enum sci_status scic_controller_continue_io(struct scic_sds_request *sci_req);
575
576 #endif /* _SCIC_SDS_CONTROLLER_H_ */
This page took 0.051793 seconds and 5 git commands to generate.