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