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_CONTROLLER_H_
57 #define _SCIC_CONTROLLER_H_
60 * This file contains all of the interface methods that can be called by an
61 * SCIC user on a controller object.
67 #include "sci_types.h"
68 #include "sci_status.h"
69 #include "sci_controller.h"
70 #include "scic_config_parameters.h"
72 struct scic_sds_request;
75 struct scic_sds_remote_device;
78 * enum _SCIC_INTERRUPT_TYPE - This enumeration depicts the various types of
79 * interrupts that are potentially supported by a SCI Core implementation.
83 enum scic_interrupt_type {
84 SCIC_LEGACY_LINE_INTERRUPT_TYPE,
85 SCIC_MSIX_INTERRUPT_TYPE,
88 * This enumeration value indicates the use of polling.
95 * This method is called by the SCI user in order to have the SCI
96 * implementation handle the interrupt. This method performs minimal
97 * processing to allow for streamlined interrupt time usage.
99 * SCIC_CONTROLLER_INTERRUPT_HANDLER true: returned if there is an interrupt to
100 * process and it was processed. false: returned if no interrupt was processed.
102 typedef bool (*SCIC_CONTROLLER_INTERRUPT_HANDLER)(
103 struct scic_sds_controller *controller
107 * This method is called by the SCI user to process completions generated as a
108 * result of a previously handled interrupt. This method will result in the
109 * completion of IO requests and handling of other controller generated
110 * events. This method should be called some time after the interrupt
113 * Most, if not all, of the user callback APIs are invoked from within this
114 * API. As a result, the user should be cognizent of the operating level at
115 * which they invoke this API.
117 typedef void (*SCIC_CONTROLLER_COMPLETION_HANDLER)(
118 struct scic_sds_controller *controller
122 * struct scic_controller_handler_methods - This structure contains an
123 * interrupt handler and completion handler function pointers.
127 struct scic_controller_handler_methods {
128 SCIC_CONTROLLER_INTERRUPT_HANDLER interrupt_handler;
129 SCIC_CONTROLLER_COMPLETION_HANDLER completion_handler;
134 * scic_controller_construct() - This method will attempt to construct a
135 * controller object utilizing the supplied parameter information.
136 * @c: This parameter specifies the controller to be constructed.
137 * @scu_base: mapped base address of the scu registers
138 * @smu_base: mapped base address of the smu registers
140 * Indicate if the controller was successfully constructed or if it failed in
141 * some way. SCI_SUCCESS This value is returned if the controller was
142 * successfully constructed. SCI_WARNING_TIMER_CONFLICT This value is returned
143 * if the interrupt coalescence timer may cause SAS compliance issues for SMP
144 * Target mode response processing. SCI_FAILURE_UNSUPPORTED_CONTROLLER_TYPE
145 * This value is returned if the controller does not support the supplied type.
146 * SCI_FAILURE_UNSUPPORTED_INIT_DATA_VERSION This value is returned if the
147 * controller does not support the supplied initialization data version.
149 enum sci_status scic_controller_construct(struct scic_sds_controller *c,
150 void __iomem *scu_base,
151 void __iomem *smu_base);
154 * scic_controller_enable_interrupts() - This method will enable all controller
156 * @controller: This parameter specifies the controller for which to enable
160 void scic_controller_enable_interrupts(
161 struct scic_sds_controller *controller);
164 * scic_controller_disable_interrupts() - This method will disable all
165 * controller interrupts.
166 * @controller: This parameter specifies the controller for which to disable
170 void scic_controller_disable_interrupts(
171 struct scic_sds_controller *controller);
174 * scic_controller_get_handler_methods() - This method will return provide
175 * function pointers for the interrupt handler and completion handler. The
176 * interrupt handler is expected to be invoked at interrupt time. The
177 * completion handler is scheduled to run as a result of the interrupt
178 * handler. The completion handler performs the bulk work for processing
180 * @interrupt_type: This parameter informs the core which type of
181 * interrupt/completion methods are being requested. These are the types:
182 * SCIC_LEGACY_LINE_INTERRUPT_TYPE, SCIC_MSIX_INTERRUPT_TYPE,
183 * SCIC_NO_INTERRUPTS (POLLING)
184 * @message_count: This parameter informs the core the number of MSI-X messages
185 * to be utilized. This parameter must be 0 when requesting legacy line
187 * @handler_methods: The caller provides a pointer to a buffer of type
188 * struct scic_controller_handler_methods. The size depends on the combination of
189 * the interrupt_type and message_count input parameters:
190 * SCIC_LEGACY_LINE_INTERRUPT_TYPE: - size =
191 * sizeof(struct scic_controller_handler_methods) SCIC_MSIX_INTERRUPT_TYPE:
192 * sizeof(struct scic_controller_handler_methods)
193 * @handler_methods: SCIC fills out the caller's buffer with the appropriate
194 * interrupt and completion handlers based on the info provided in the
195 * interrupt_type and message_count input parameters. For
196 * SCIC_LEGACY_LINE_INTERRUPT_TYPE, the buffer receives a single
197 * struct scic_controller_handler_methods element regardless that the
198 * message_count parameter is zero. For SCIC_MSIX_INTERRUPT_TYPE, the buffer
199 * receives an array of elements of type struct scic_controller_handler_methods
200 * where the array size is equivalent to the message_count parameter. The
201 * array is zero-relative where entry zero corresponds to message-vector
202 * zero, entry one corresponds to message-vector one, and so forth.
204 * Indicate if the handler retrieval operation was successful. SCI_SUCCESS This
205 * value is returned if retrieval succeeded.
206 * SCI_FAILURE_UNSUPPORTED_MESSAGE_COUNT This value is returned if the user
207 * supplied an unsupported number of MSI-X messages. For legacy line interrupts
208 * the only valid value is 0.
210 enum sci_status scic_controller_get_handler_methods(
211 enum scic_interrupt_type interrupt_type,
213 struct scic_controller_handler_methods *handler_methods);
216 * scic_controller_initialize() - This method will initialize the controller
217 * hardware managed by the supplied core controller object. This method
218 * will bring the physical controller hardware out of reset and enable the
219 * core to determine the capabilities of the hardware being managed. Thus,
220 * the core controller can determine it's exact physical (DMA capable)
221 * memory requirements.
222 * @controller: This parameter specifies the controller to be initialized.
224 * The SCI Core user must have called scic_controller_construct() on the
225 * supplied controller object previously. Indicate if the controller was
226 * successfully initialized or if it failed in some way. SCI_SUCCESS This value
227 * is returned if the controller hardware was successfully initialized.
229 enum sci_status scic_controller_initialize(
230 struct scic_sds_controller *controller);
233 * scic_controller_get_suggested_start_timeout() - This method returns the
234 * suggested scic_controller_start() timeout amount. The user is free to
235 * use any timeout value, but this method provides the suggested minimum
236 * start timeout value. The returned value is based upon empirical
237 * information determined as a result of interoperability testing.
238 * @controller: the handle to the controller object for which to return the
239 * suggested start timeout.
241 * This method returns the number of milliseconds for the suggested start
244 u32 scic_controller_get_suggested_start_timeout(
245 struct scic_sds_controller *controller);
248 * scic_controller_start() - This method will start the supplied core
249 * controller. This method will start the staggered spin up operation. The
250 * SCI User completion callback is called when the following conditions are
251 * met: -# the return status of this method is SCI_SUCCESS. -# after all of
252 * the phys have successfully started or been given the opportunity to start.
253 * @controller: the handle to the controller object to start.
254 * @timeout: This parameter specifies the number of milliseconds in which the
255 * start operation should complete.
257 * The SCI Core user must have filled in the physical memory descriptor
258 * structure via the sci_controller_get_memory_descriptor_list() method. The
259 * SCI Core user must have invoked the scic_controller_initialize() method
260 * prior to invoking this method. The controller must be in the INITIALIZED or
261 * STARTED state. Indicate if the controller start method succeeded or failed
262 * in some way. SCI_SUCCESS if the start operation succeeded.
263 * SCI_WARNING_ALREADY_IN_STATE if the controller is already in the STARTED
264 * state. SCI_FAILURE_INVALID_STATE if the controller is not either in the
265 * INITIALIZED or STARTED states. SCI_FAILURE_INVALID_MEMORY_DESCRIPTOR if
266 * there are inconsistent or invalid values in the supplied
267 * struct sci_physical_memory_descriptor array.
269 enum sci_status scic_controller_start(
270 struct scic_sds_controller *controller,
274 * scic_controller_stop() - This method will stop an individual controller
275 * object.This method will invoke the associated user callback upon
276 * completion. The completion callback is called when the following
277 * conditions are met: -# the method return status is SCI_SUCCESS. -# the
278 * controller has been quiesced. This method will ensure that all IO
279 * requests are quiesced, phys are stopped, and all additional operation by
280 * the hardware is halted.
281 * @controller: the handle to the controller object to stop.
282 * @timeout: This parameter specifies the number of milliseconds in which the
283 * stop operation should complete.
285 * The controller must be in the STARTED or STOPPED state. Indicate if the
286 * controller stop method succeeded or failed in some way. SCI_SUCCESS if the
287 * stop operation successfully began. SCI_WARNING_ALREADY_IN_STATE if the
288 * controller is already in the STOPPED state. SCI_FAILURE_INVALID_STATE if the
289 * controller is not either in the STARTED or STOPPED states.
291 enum sci_status scic_controller_stop(
292 struct scic_sds_controller *controller,
296 * scic_controller_reset() - This method will reset the supplied core
297 * controller regardless of the state of said controller. This operation is
298 * considered destructive. In other words, all current operations are wiped
299 * out. No IO completions for outstanding devices occur. Outstanding IO
300 * requests are not aborted or completed at the actual remote device.
301 * @controller: the handle to the controller object to reset.
303 * Indicate if the controller reset method succeeded or failed in some way.
304 * SCI_SUCCESS if the reset operation successfully started. SCI_FATAL_ERROR if
305 * the controller reset operation is unable to complete.
307 enum sci_status scic_controller_reset(
308 struct scic_sds_controller *controller);
311 * scic_controller_start_io() - This method is called by the SCI user to
312 * send/start an IO request. If the method invocation is successful, then
313 * the IO request has been queued to the hardware for processing.
314 * @controller: the handle to the controller object for which to start an IO
316 * @remote_device: the handle to the remote device object for which to start an
318 * @io_request: the handle to the io request object to start.
319 * @io_tag: This parameter specifies a previously allocated IO tag that the
320 * user desires to be utilized for this request. This parameter is optional.
321 * The user is allowed to supply SCI_CONTROLLER_INVALID_IO_TAG as the value
322 * for this parameter.
324 * - IO tags are a protected resource. It is incumbent upon the SCI Core user
325 * to ensure that each of the methods that may allocate or free available IO
326 * tags are handled in a mutually exclusive manner. This method is one of said
327 * methods requiring proper critical code section protection (e.g. semaphore,
328 * spin-lock, etc.). - For SATA, the user is required to manage NCQ tags. As a
329 * result, it is expected the user will have set the NCQ tag field in the host
330 * to device register FIS prior to calling this method. There is also a
331 * requirement for the user to call scic_stp_io_set_ncq_tag() prior to invoking
332 * the scic_controller_start_io() method. scic_controller_allocate_tag() for
333 * more information on allocating a tag. Indicate if the controller
334 * successfully started the IO request. SCI_IO_SUCCESS if the IO request was
335 * successfully started. Determine the failure situations and return values.
337 enum sci_io_status scic_controller_start_io(
338 struct scic_sds_controller *controller,
339 struct scic_sds_remote_device *remote_device,
340 struct scic_sds_request *io_request,
345 * scic_controller_start_task() - This method is called by the SCIC user to
346 * send/start a framework task management request.
347 * @controller: the handle to the controller object for which to start the task
348 * management request.
349 * @remote_device: the handle to the remote device object for which to start
350 * the task management request.
351 * @task_request: the handle to the task request object to start.
352 * @io_tag: This parameter specifies a previously allocated IO tag that the
353 * user desires to be utilized for this request. Note this not the io_tag
354 * of the request being managed. It is to be utilized for the task request
355 * itself. This parameter is optional. The user is allowed to supply
356 * SCI_CONTROLLER_INVALID_IO_TAG as the value for this parameter.
358 * - IO tags are a protected resource. It is incumbent upon the SCI Core user
359 * to ensure that each of the methods that may allocate or free available IO
360 * tags are handled in a mutually exclusive manner. This method is one of said
361 * methods requiring proper critical code section protection (e.g. semaphore,
362 * spin-lock, etc.). - The user must synchronize this task with completion
363 * queue processing. If they are not synchronized then it is possible for the
364 * io requests that are being managed by the task request can complete before
365 * starting the task request. scic_controller_allocate_tag() for more
366 * information on allocating a tag. Indicate if the controller successfully
367 * started the IO request. SCI_TASK_SUCCESS if the task request was
368 * successfully started. SCI_TASK_FAILURE_REQUIRES_SCSI_ABORT This value is
369 * returned if there is/are task(s) outstanding that require termination or
370 * completion before this request can succeed.
372 enum sci_task_status scic_controller_start_task(
373 struct scic_sds_controller *controller,
374 struct scic_sds_remote_device *remote_device,
375 struct scic_sds_request *task_request,
379 * scic_controller_complete_task() - This method will perform core specific
380 * completion operations for task management request. After this method is
381 * invoked, the user should consider the task request as invalid until it is
382 * properly reused (i.e. re-constructed).
383 * @controller: The handle to the controller object for which to complete the
384 * task management request.
385 * @remote_device: The handle to the remote device object for which to complete
386 * the task management request.
387 * @task_request: the handle to the task management request object to complete.
389 * Indicate if the controller successfully completed the task management
390 * request. SCI_SUCCESS if the completion process was successful.
392 enum sci_status scic_controller_complete_task(
393 struct scic_sds_controller *controller,
394 struct scic_sds_remote_device *remote_device,
395 struct scic_sds_request *task_request);
399 * scic_controller_terminate_request() - This method is called by the SCI Core
400 * user to terminate an ongoing (i.e. started) core IO request. This does
401 * not abort the IO request at the target, but rather removes the IO request
402 * from the host controller.
403 * @controller: the handle to the controller object for which to terminate a
405 * @remote_device: the handle to the remote device object for which to
406 * terminate a request.
407 * @request: the handle to the io or task management request object to
410 * Indicate if the controller successfully began the terminate process for the
411 * IO request. SCI_SUCCESS if the terminate process was successfully started
412 * for the request. Determine the failure situations and return values.
414 enum sci_status scic_controller_terminate_request(
415 struct scic_sds_controller *controller,
416 struct scic_sds_remote_device *remote_device,
417 struct scic_sds_request *request);
420 * scic_controller_complete_io() - This method will perform core specific
421 * completion operations for an IO request. After this method is invoked,
422 * the user should consider the IO request as invalid until it is properly
423 * reused (i.e. re-constructed).
424 * @controller: The handle to the controller object for which to complete the
426 * @remote_device: The handle to the remote device object for which to complete
428 * @io_request: the handle to the io request object to complete.
430 * - IO tags are a protected resource. It is incumbent upon the SCI Core user
431 * to ensure that each of the methods that may allocate or free available IO
432 * tags are handled in a mutually exclusive manner. This method is one of said
433 * methods requiring proper critical code section protection (e.g. semaphore,
434 * spin-lock, etc.). - If the IO tag for a request was allocated, by the SCI
435 * Core user, using the scic_controller_allocate_io_tag() method, then it is
436 * the responsibility of the caller to invoke the scic_controller_free_io_tag()
437 * method to free the tag (i.e. this method will not free the IO tag). Indicate
438 * if the controller successfully completed the IO request. SCI_SUCCESS if the
439 * completion process was successful.
441 enum sci_status scic_controller_complete_io(
442 struct scic_sds_controller *controller,
443 struct scic_sds_remote_device *remote_device,
444 struct scic_sds_request *io_request);
448 * scic_controller_get_port_handle() - This method simply provides the user
449 * with a unique handle for a given SAS/SATA core port index.
450 * @controller: This parameter represents the handle to the controller object
451 * from which to retrieve a port (SAS or SATA) handle.
452 * @port_index: This parameter specifies the port index in the controller for
453 * which to retrieve the port handle. 0 <= port_index < maximum number of
455 * @port_handle: This parameter specifies the retrieved port handle to be
456 * provided to the caller.
458 * Indicate if the retrieval of the port handle was successful. SCI_SUCCESS
459 * This value is returned if the retrieval was successful.
460 * SCI_FAILURE_INVALID_PORT This value is returned if the supplied port id is
461 * not in the supported range.
463 enum sci_status scic_controller_get_port_handle(
464 struct scic_sds_controller *controller,
466 struct scic_sds_port **port_handle);
469 * scic_controller_get_phy_handle() - This method simply provides the user with
470 * a unique handle for a given SAS/SATA phy index/identifier.
471 * @controller: This parameter represents the handle to the controller object
472 * from which to retrieve a phy (SAS or SATA) handle.
473 * @phy_index: This parameter specifies the phy index in the controller for
474 * which to retrieve the phy handle. 0 <= phy_index < maximum number of phys.
475 * @phy_handle: This parameter specifies the retrieved phy handle to be
476 * provided to the caller.
478 * Indicate if the retrieval of the phy handle was successful. SCI_SUCCESS This
479 * value is returned if the retrieval was successful. SCI_FAILURE_INVALID_PHY
480 * This value is returned if the supplied phy id is not in the supported range.
482 enum sci_status scic_controller_get_phy_handle(
483 struct scic_sds_controller *controller,
485 struct scic_sds_phy **phy_handle);
488 * scic_controller_allocate_io_tag() - This method will allocate a tag from the
489 * pool of free IO tags. Direct allocation of IO tags by the SCI Core user
490 * is optional. The scic_controller_start_io() method will allocate an IO
491 * tag if this method is not utilized and the tag is not supplied to the IO
492 * construct routine. Direct allocation of IO tags may provide additional
493 * performance improvements in environments capable of supporting this usage
494 * model. Additionally, direct allocation of IO tags also provides
495 * additional flexibility to the SCI Core user. Specifically, the user may
496 * retain IO tags across the lives of multiple IO requests.
497 * @controller: the handle to the controller object for which to allocate the
500 * IO tags are a protected resource. It is incumbent upon the SCI Core user to
501 * ensure that each of the methods that may allocate or free available IO tags
502 * are handled in a mutually exclusive manner. This method is one of said
503 * methods requiring proper critical code section protection (e.g. semaphore,
504 * spin-lock, etc.). An unsigned integer representing an available IO tag.
505 * SCI_CONTROLLER_INVALID_IO_TAG This value is returned if there are no
506 * currently available tags to be allocated. All return other values indicate a
509 u16 scic_controller_allocate_io_tag(
510 struct scic_sds_controller *controller);
513 * scic_controller_free_io_tag() - This method will free an IO tag to the pool
514 * of free IO tags. This method provides the SCI Core user more flexibility
515 * with regards to IO tags. The user may desire to keep an IO tag after an
516 * IO request has completed, because they plan on re-using the tag for a
517 * subsequent IO request. This method is only legal if the tag was
518 * allocated via scic_controller_allocate_io_tag().
519 * @controller: This parameter specifies the handle to the controller object
520 * for which to free/return the tag.
521 * @io_tag: This parameter represents the tag to be freed to the pool of
524 * - IO tags are a protected resource. It is incumbent upon the SCI Core user
525 * to ensure that each of the methods that may allocate or free available IO
526 * tags are handled in a mutually exclusive manner. This method is one of said
527 * methods requiring proper critical code section protection (e.g. semaphore,
528 * spin-lock, etc.). - If the IO tag for a request was allocated, by the SCI
529 * Core user, using the scic_controller_allocate_io_tag() method, then it is
530 * the responsibility of the caller to invoke this method to free the tag. This
531 * method returns an indication of whether the tag was successfully put back
532 * (freed) to the pool of available tags. SCI_SUCCESS This return value
533 * indicates the tag was successfully placed into the pool of available IO
534 * tags. SCI_FAILURE_INVALID_IO_TAG This value is returned if the supplied tag
535 * is not a valid IO tag value.
537 enum sci_status scic_controller_free_io_tag(
538 struct scic_sds_controller *controller,
545 * scic_controller_set_mode() - This method allows the user to configure the
546 * SCI core into either a performance mode or a memory savings mode.
547 * @controller: This parameter represents the handle to the controller object
548 * for which to update the operating mode.
549 * @mode: This parameter specifies the new mode for the controller.
551 * Indicate if the user successfully change the operating mode of the
552 * controller. SCI_SUCCESS The user successfully updated the mode.
554 enum sci_status scic_controller_set_mode(
555 struct scic_sds_controller *controller,
556 enum sci_controller_mode mode);
560 * scic_controller_set_interrupt_coalescence() - This method allows the user to
561 * configure the interrupt coalescence.
562 * @controller: This parameter represents the handle to the controller object
563 * for which its interrupt coalesce register is overridden.
564 * @coalesce_number: Used to control the number of entries in the Completion
565 * Queue before an interrupt is generated. If the number of entries exceed
566 * this number, an interrupt will be generated. The valid range of the input
567 * is [0, 256]. A setting of 0 results in coalescing being disabled.
568 * @coalesce_timeout: Timeout value in microseconds. The valid range of the
569 * input is [0, 2700000] . A setting of 0 is allowed and results in no
570 * interrupt coalescing timeout.
572 * Indicate if the user successfully set the interrupt coalesce parameters.
573 * SCI_SUCCESS The user successfully updated the interrutp coalescence.
574 * SCI_FAILURE_INVALID_PARAMETER_VALUE The user input value is out of range.
576 enum sci_status scic_controller_set_interrupt_coalescence(
577 struct scic_sds_controller *controller,
579 u32 coalesce_timeout);
582 struct scic_sds_controller *scic_controller_alloc(struct device *dev);
585 #endif /* _SCIC_CONTROLLER_H_ */