isci: unify port data structures
[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_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"
84
85 struct sci_base_remote_device;
86 struct scic_sds_remote_device;
87 struct scic_sds_request;
88 struct scic_sds_controller;
89
90 /**
91 * struct scic_power_control -
92 *
93 * This structure defines the fields for managing power control for direct
94 * attached disk devices.
95 */
96 struct scic_power_control {
97 /**
98 * This field is set when the power control timer is running and cleared when
99 * it is not.
100 */
101 bool timer_started;
102
103 /**
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.
106 */
107 void *timer;
108
109 /**
110 * This field is used to keep track of how many phys are put into the
111 * requesters field.
112 */
113 u8 phys_waiting;
114
115 /**
116 * This field is used to keep track of how many phys have been granted to consume power
117 */
118 u8 phys_granted_power;
119
120 /**
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
123 */
124 struct scic_sds_phy *requesters[SCI_MAX_PHYS];
125
126 };
127
128 /**
129 * struct scic_sds_controller -
130 *
131 * This structure represents the SCU controller object.
132 */
133 struct scic_sds_controller {
134 /**
135 * This field contains the information for the base controller state
136 * machine.
137 */
138 struct sci_base_state_machine state_machine;
139
140 /**
141 * This field is the driver timer object handler used to time the controller
142 * object start and stop requests.
143 */
144 void *timeout_timer;
145
146 /**
147 * This field contains the user parameters to be utilized for this
148 * core controller object.
149 */
150 union scic_user_parameters user_parameters;
151
152 /**
153 * This field contains the OEM parameters to be utilized for this
154 * core controller object.
155 */
156 union scic_oem_parameters oem_parameters;
157
158 /**
159 * This field contains the port configuration agent for this controller.
160 */
161 struct scic_sds_port_configuration_agent port_agent;
162
163 /**
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.
168 */
169 struct scic_sds_remote_device *device_table[SCI_MAX_REMOTE_DEVICES];
170
171 /**
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.
176 */
177 struct scic_sds_request *io_request_table[SCI_MAX_IO_REQUESTS];
178
179 /**
180 * This field is the free RNi data structure
181 */
182 struct scic_remote_node_table available_remote_nodes;
183
184 /**
185 * This field is the TCi pool used to manage the task context index.
186 */
187 SCI_POOL_CREATE(tci_pool, u16, SCI_MAX_IO_REQUESTS);
188
189 /**
190 * This filed is the struct scic_power_control data used to controll when direct
191 * attached devices can consume power.
192 */
193 struct scic_power_control power_control;
194
195 /**
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
199 * IO Tag value.
200 */
201 u16 io_request_sequence[SCI_MAX_IO_REQUESTS];
202
203 /**
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.
209 */
210 u8 remote_device_sequence[SCI_MAX_REMOTE_DEVICES];
211
212 /**
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.
215 */
216 struct scu_task_context *task_context_table;
217
218 /**
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
221 * software.
222 */
223 union scu_remote_node_context *remote_node_context_table;
224
225 /**
226 * This field is a pointer to the completion queue. This memory is
227 * written to by the hardware and read by the software.
228 */
229 u32 *completion_queue;
230
231 /**
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.
235 */
236 u32 completion_queue_get;
237
238 /**
239 * This field is the minimum of the number of hardware supported port entries
240 * and the software requested port entries.
241 */
242 u32 logical_port_entries;
243
244 /**
245 * This field is the minimum number of hardware supported completion queue
246 * entries and the software requested completion queue entries.
247 */
248 u32 completion_queue_entries;
249
250 /**
251 * This field is the minimum number of hardware supported event entries and
252 * the software requested event entries.
253 */
254 u32 completion_event_entries;
255
256 /**
257 * This field is the minimum number of devices supported by the hardware and
258 * the number of devices requested by the software.
259 */
260 u32 remote_node_entries;
261
262 /**
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.
265 */
266 u32 task_context_entries;
267
268 /**
269 * This object contains all of the unsolicited frame specific
270 * data utilized by the core controller.
271 */
272 struct scic_sds_unsolicited_frame_control uf_control;
273
274 /* Phy Startup Data */
275 /**
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.
279 */
280 void *phy_startup_timer;
281
282 /**
283 * This field is set when the phy_startup_timer is running and is cleared when
284 * the phy_startup_timer is stopped.
285 */
286 bool phy_startup_timer_pending;
287
288 /**
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.
291 */
292 u32 next_phy_to_start;
293
294 /**
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.
299 */
300 u8 invalid_phy_mask;
301
302 /*
303 * This field saves the current interrupt coalescing number of the controller.
304 */
305 u16 interrupt_coalesce_number;
306
307 /*
308 * This field saves the current interrupt coalescing timeout value in microseconds.
309 */
310 u32 interrupt_coalesce_timeout;
311
312 /**
313 * This field is a pointer to the memory mapped register space for the
314 * struct smu_registers.
315 */
316 struct smu_registers __iomem *smu_registers;
317
318 /**
319 * This field is a pointer to the memory mapped register space for the
320 * struct scu_registers.
321 */
322 struct scu_registers __iomem *scu_registers;
323
324 };
325
326 /**
327 * enum scic_sds_controller_states - This enumeration depicts all the states
328 * for the common controller state machine.
329 */
330 enum scic_sds_controller_states {
331 /**
332 * Simply the initial state for the base controller state machine.
333 */
334 SCI_BASE_CONTROLLER_STATE_INITIAL = 0,
335
336 /**
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
339 * initialization.
340 * This state is entered from the INITIAL state.
341 * This state is entered from the RESETTING state.
342 */
343 SCI_BASE_CONTROLLER_STATE_RESET,
344
345 /**
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
348 * are permitted.
349 * This state is entered from the RESET state.
350 */
351 SCI_BASE_CONTROLLER_STATE_INITIALIZING,
352
353 /**
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.
357 */
358 SCI_BASE_CONTROLLER_STATE_INITIALIZED,
359
360 /**
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.
364 */
365 SCI_BASE_CONTROLLER_STATE_STARTING,
366
367 /**
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.
371 */
372 SCI_BASE_CONTROLLER_STATE_READY,
373
374 /**
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
378 * most cases.
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.
382 */
383 SCI_BASE_CONTROLLER_STATE_RESETTING,
384
385 /**
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.
390 */
391 SCI_BASE_CONTROLLER_STATE_STOPPING,
392
393 /**
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.
397 */
398 SCI_BASE_CONTROLLER_STATE_STOPPED,
399
400 /**
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.
407 */
408 SCI_BASE_CONTROLLER_STATE_FAILED,
409
410 SCI_BASE_CONTROLLER_MAX_STATES
411
412 };
413
414 /**
415 * INCREMENT_QUEUE_GET() -
416 *
417 * This macro will increment the specified index to and if the index wraps to 0
418 * it will toggel the cycle bit.
419 */
420 #define INCREMENT_QUEUE_GET(index, cycle, entry_count, bit_toggle) \
421 { \
422 if ((index) + 1 == entry_count) { \
423 (index) = 0; \
424 (cycle) = (cycle) ^ (bit_toggle); \
425 } else { \
426 index = index + 1; \
427 } \
428 }
429
430 /**
431 * scic_sds_controller_get_port_configuration_agent() -
432 *
433 * This is a helper macro to get the port configuration agent from the
434 * controller object.
435 */
436 #define scic_sds_controller_get_port_configuration_agent(controller) \
437 (&(controller)->port_agent)
438
439 /**
440 * scic_sds_controller_get_protocol_engine_group() -
441 *
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
444 */
445 #define scic_sds_controller_get_protocol_engine_group(controller) 0
446
447 /**
448 * scic_sds_io_tag_construct() -
449 *
450 * This macro constructs an IO tag from the sequence and index values.
451 */
452 #define scic_sds_io_tag_construct(sequence, task_index) \
453 ((sequence) << 12 | (task_index))
454
455 /**
456 * scic_sds_io_tag_get_sequence() -
457 *
458 * This macro returns the IO sequence from the IO tag value.
459 */
460 #define scic_sds_io_tag_get_sequence(io_tag) \
461 (((io_tag) & 0xF000) >> 12)
462
463 /**
464 * scic_sds_io_tag_get_index() -
465 *
466 * This macro returns the TCi from the io tag value
467 */
468 #define scic_sds_io_tag_get_index(io_tag) \
469 ((io_tag) & 0x0FFF)
470
471 /**
472 * scic_sds_io_sequence_increment() -
473 *
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
478 */
479 #define scic_sds_io_sequence_increment(value) \
480 ((value) = (((value) + 1) & 0x000F))
481
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)
484 {
485 struct domain_device *dev = sci_dev_to_domain(sci_dev);
486
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;
491 }
492
493 /**
494 * scic_sds_controller_set_invalid_phy() -
495 *
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
498 * notifications.
499 */
500 #define scic_sds_controller_set_invalid_phy(controller, phy) \
501 ((controller)->invalid_phy_mask |= (1 << (phy)->phy_index))
502
503 /**
504 * scic_sds_controller_clear_invalid_phy() -
505 *
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
508 * notifications.
509 */
510 #define scic_sds_controller_clear_invalid_phy(controller, phy) \
511 ((controller)->invalid_phy_mask &= ~(1 << (phy)->phy_index))
512
513 void scic_sds_controller_post_request(
514 struct scic_sds_controller *this_controller,
515 u32 request);
516
517 void scic_sds_controller_release_frame(
518 struct scic_sds_controller *this_controller,
519 u32 frame_index);
520
521 void scic_sds_controller_copy_sata_response(
522 void *response_buffer,
523 void *frame_header,
524 void *frame_buffer);
525
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,
529 u16 *node_id);
530
531 void scic_sds_controller_free_remote_node_context(
532 struct scic_sds_controller *this_controller,
533 struct scic_sds_remote_device *sci_dev,
534 u16 node_id);
535
536 union scu_remote_node_context *scic_sds_controller_get_remote_node_context_buffer(
537 struct scic_sds_controller *this_controller,
538 u16 node_id);
539
540 struct scic_sds_request *scic_request_by_tag(struct scic_sds_controller *scic,
541 u16 io_tag);
542
543 struct scu_task_context *scic_sds_controller_get_task_context_buffer(
544 struct scic_sds_controller *this_controller,
545 u16 io_tag);
546
547 void scic_sds_controller_power_control_queue_insert(
548 struct scic_sds_controller *this_controller,
549 struct scic_sds_phy *sci_phy);
550
551 void scic_sds_controller_power_control_queue_remove(
552 struct scic_sds_controller *this_controller,
553 struct scic_sds_phy *sci_phy);
554
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);
559
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);
564
565 void scic_sds_controller_remote_device_stopped(
566 struct scic_sds_controller *this_controller,
567 struct scic_sds_remote_device *sci_dev);
568
569 void scic_sds_controller_copy_task_context(
570 struct scic_sds_controller *this_controller,
571 struct scic_sds_request *this_request);
572
573 void scic_sds_controller_register_setup(
574 struct scic_sds_controller *this_controller);
575
576 enum sci_status scic_controller_continue_io(struct scic_sds_request *sci_req);
577
578 #endif /* _SCIC_SDS_CONTROLLER_H_ */
This page took 0.043157 seconds and 5 git commands to generate.