162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * This file is provided under a dual BSD/GPLv2 license.  When using or
362306a36Sopenharmony_ci * redistributing this file, you may do so under either license.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * GPL LICENSE SUMMARY
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
1062306a36Sopenharmony_ci * it under the terms of version 2 of the GNU General Public License as
1162306a36Sopenharmony_ci * published by the Free Software Foundation.
1262306a36Sopenharmony_ci *
1362306a36Sopenharmony_ci * This program is distributed in the hope that it will be useful, but
1462306a36Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of
1562306a36Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1662306a36Sopenharmony_ci * General Public License for more details.
1762306a36Sopenharmony_ci *
1862306a36Sopenharmony_ci * You should have received a copy of the GNU General Public License
1962306a36Sopenharmony_ci * along with this program; if not, write to the Free Software
2062306a36Sopenharmony_ci * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
2162306a36Sopenharmony_ci * The full GNU General Public License is included in this distribution
2262306a36Sopenharmony_ci * in the file called LICENSE.GPL.
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci * BSD LICENSE
2562306a36Sopenharmony_ci *
2662306a36Sopenharmony_ci * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
2762306a36Sopenharmony_ci * All rights reserved.
2862306a36Sopenharmony_ci *
2962306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
3062306a36Sopenharmony_ci * modification, are permitted provided that the following conditions
3162306a36Sopenharmony_ci * are met:
3262306a36Sopenharmony_ci *
3362306a36Sopenharmony_ci *   * Redistributions of source code must retain the above copyright
3462306a36Sopenharmony_ci *     notice, this list of conditions and the following disclaimer.
3562306a36Sopenharmony_ci *   * Redistributions in binary form must reproduce the above copyright
3662306a36Sopenharmony_ci *     notice, this list of conditions and the following disclaimer in
3762306a36Sopenharmony_ci *     the documentation and/or other materials provided with the
3862306a36Sopenharmony_ci *     distribution.
3962306a36Sopenharmony_ci *   * Neither the name of Intel Corporation nor the names of its
4062306a36Sopenharmony_ci *     contributors may be used to endorse or promote products derived
4162306a36Sopenharmony_ci *     from this software without specific prior written permission.
4262306a36Sopenharmony_ci *
4362306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4462306a36Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4562306a36Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4662306a36Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4762306a36Sopenharmony_ci * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4862306a36Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4962306a36Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
5062306a36Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
5162306a36Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
5262306a36Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5362306a36Sopenharmony_ci * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5462306a36Sopenharmony_ci */
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci#ifndef __ISCI_H__
5762306a36Sopenharmony_ci#define __ISCI_H__
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci#include <linux/interrupt.h>
6062306a36Sopenharmony_ci#include <linux/types.h>
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci#define DRV_NAME "isci"
6362306a36Sopenharmony_ci#define SCI_PCI_BAR_COUNT 2
6462306a36Sopenharmony_ci#define SCI_NUM_MSI_X_INT 2
6562306a36Sopenharmony_ci#define SCI_SMU_BAR       0
6662306a36Sopenharmony_ci#define SCI_SMU_BAR_SIZE  (16*1024)
6762306a36Sopenharmony_ci#define SCI_SCU_BAR       1
6862306a36Sopenharmony_ci#define SCI_SCU_BAR_SIZE  (4*1024*1024)
6962306a36Sopenharmony_ci#define SCI_IO_SPACE_BAR0 2
7062306a36Sopenharmony_ci#define SCI_IO_SPACE_BAR1 3
7162306a36Sopenharmony_ci#define ISCI_CAN_QUEUE_VAL 250 /* < SCI_MAX_IO_REQUESTS ? */
7262306a36Sopenharmony_ci#define SCIC_CONTROLLER_STOP_TIMEOUT 5000
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci#define SCI_CONTROLLER_INVALID_IO_TAG 0xFFFF
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci#define SCI_MAX_PHYS  (4UL)
7762306a36Sopenharmony_ci#define SCI_MAX_PORTS SCI_MAX_PHYS
7862306a36Sopenharmony_ci#define SCI_MAX_SMP_PHYS  (384) /* not silicon constrained */
7962306a36Sopenharmony_ci#define SCI_MAX_REMOTE_DEVICES (256UL)
8062306a36Sopenharmony_ci#define SCI_MAX_IO_REQUESTS (256UL)
8162306a36Sopenharmony_ci#define SCI_MAX_SEQ (16)
8262306a36Sopenharmony_ci#define SCI_MAX_MSIX_MESSAGES  (2)
8362306a36Sopenharmony_ci#define SCI_MAX_SCATTER_GATHER_ELEMENTS 130 /* not silicon constrained */
8462306a36Sopenharmony_ci#define SCI_MAX_CONTROLLERS 2
8562306a36Sopenharmony_ci#define SCI_MAX_DOMAINS  SCI_MAX_PORTS
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci#define SCU_MAX_CRITICAL_NOTIFICATIONS    (384)
8862306a36Sopenharmony_ci#define SCU_MAX_EVENTS_SHIFT		  (7)
8962306a36Sopenharmony_ci#define SCU_MAX_EVENTS                    (1 << SCU_MAX_EVENTS_SHIFT)
9062306a36Sopenharmony_ci#define SCU_MAX_UNSOLICITED_FRAMES        (128)
9162306a36Sopenharmony_ci#define SCU_MAX_COMPLETION_QUEUE_SCRATCH  (128)
9262306a36Sopenharmony_ci#define SCU_MAX_COMPLETION_QUEUE_ENTRIES  (SCU_MAX_CRITICAL_NOTIFICATIONS \
9362306a36Sopenharmony_ci					   + SCU_MAX_EVENTS \
9462306a36Sopenharmony_ci					   + SCU_MAX_UNSOLICITED_FRAMES	\
9562306a36Sopenharmony_ci					   + SCI_MAX_IO_REQUESTS \
9662306a36Sopenharmony_ci					   + SCU_MAX_COMPLETION_QUEUE_SCRATCH)
9762306a36Sopenharmony_ci#define SCU_MAX_COMPLETION_QUEUE_SHIFT	  (ilog2(SCU_MAX_COMPLETION_QUEUE_ENTRIES))
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci#define SCU_ABSOLUTE_MAX_UNSOLICITED_FRAMES (4096)
10062306a36Sopenharmony_ci#define SCU_UNSOLICITED_FRAME_BUFFER_SIZE   (1024U)
10162306a36Sopenharmony_ci#define SCU_INVALID_FRAME_INDEX             (0xFFFF)
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci#define SCU_IO_REQUEST_MAX_SGE_SIZE         (0x00FFFFFF)
10462306a36Sopenharmony_ci#define SCU_IO_REQUEST_MAX_TRANSFER_LENGTH  (0x00FFFFFF)
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_cistatic inline void check_sizes(void)
10762306a36Sopenharmony_ci{
10862306a36Sopenharmony_ci	BUILD_BUG_ON_NOT_POWER_OF_2(SCU_MAX_EVENTS);
10962306a36Sopenharmony_ci	BUILD_BUG_ON(SCU_MAX_UNSOLICITED_FRAMES <= 8);
11062306a36Sopenharmony_ci	BUILD_BUG_ON_NOT_POWER_OF_2(SCU_MAX_UNSOLICITED_FRAMES);
11162306a36Sopenharmony_ci	BUILD_BUG_ON_NOT_POWER_OF_2(SCU_MAX_COMPLETION_QUEUE_ENTRIES);
11262306a36Sopenharmony_ci	BUILD_BUG_ON(SCU_MAX_UNSOLICITED_FRAMES > SCU_ABSOLUTE_MAX_UNSOLICITED_FRAMES);
11362306a36Sopenharmony_ci	BUILD_BUG_ON_NOT_POWER_OF_2(SCI_MAX_IO_REQUESTS);
11462306a36Sopenharmony_ci	BUILD_BUG_ON_NOT_POWER_OF_2(SCI_MAX_SEQ);
11562306a36Sopenharmony_ci}
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci/**
11862306a36Sopenharmony_ci * enum sci_status - This is the general return status enumeration for non-IO,
11962306a36Sopenharmony_ci *    non-task management related SCI interface methods.
12062306a36Sopenharmony_ci *
12162306a36Sopenharmony_ci *
12262306a36Sopenharmony_ci */
12362306a36Sopenharmony_cienum sci_status {
12462306a36Sopenharmony_ci	/**
12562306a36Sopenharmony_ci	 * This member indicates successful completion.
12662306a36Sopenharmony_ci	 */
12762306a36Sopenharmony_ci	SCI_SUCCESS = 0,
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci	/**
13062306a36Sopenharmony_ci	 * This value indicates that the calling method completed successfully,
13162306a36Sopenharmony_ci	 * but that the IO may have completed before having it's start method
13262306a36Sopenharmony_ci	 * invoked.  This occurs during SAT translation for requests that do
13362306a36Sopenharmony_ci	 * not require an IO to the target or for any other requests that may
13462306a36Sopenharmony_ci	 * be completed without having to submit IO.
13562306a36Sopenharmony_ci	 */
13662306a36Sopenharmony_ci	SCI_SUCCESS_IO_COMPLETE_BEFORE_START,
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci	/**
13962306a36Sopenharmony_ci	 *  This Value indicates that the SCU hardware returned an early response
14062306a36Sopenharmony_ci	 *  because the io request specified more data than is returned by the
14162306a36Sopenharmony_ci	 *  target device (mode pages, inquiry data, etc.). The completion routine
14262306a36Sopenharmony_ci	 *  will handle this case to get the actual number of bytes transferred.
14362306a36Sopenharmony_ci	 */
14462306a36Sopenharmony_ci	SCI_SUCCESS_IO_DONE_EARLY,
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci	/**
14762306a36Sopenharmony_ci	 * This member indicates that the object for which a state change is
14862306a36Sopenharmony_ci	 * being requested is already in said state.
14962306a36Sopenharmony_ci	 */
15062306a36Sopenharmony_ci	SCI_WARNING_ALREADY_IN_STATE,
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci	/**
15362306a36Sopenharmony_ci	 * This member indicates interrupt coalescence timer may cause SAS
15462306a36Sopenharmony_ci	 * specification compliance issues (i.e. SMP target mode response
15562306a36Sopenharmony_ci	 * frames must be returned within 1.9 milliseconds).
15662306a36Sopenharmony_ci	 */
15762306a36Sopenharmony_ci	SCI_WARNING_TIMER_CONFLICT,
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci	/**
16062306a36Sopenharmony_ci	 * This field indicates a sequence of action is not completed yet. Mostly,
16162306a36Sopenharmony_ci	 * this status is used when multiple ATA commands are needed in a SATI translation.
16262306a36Sopenharmony_ci	 */
16362306a36Sopenharmony_ci	SCI_WARNING_SEQUENCE_INCOMPLETE,
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci	/**
16662306a36Sopenharmony_ci	 * This member indicates that there was a general failure.
16762306a36Sopenharmony_ci	 */
16862306a36Sopenharmony_ci	SCI_FAILURE,
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ci	/**
17162306a36Sopenharmony_ci	 * This member indicates that the SCI implementation is unable to complete
17262306a36Sopenharmony_ci	 * an operation due to a critical flaw the prevents any further operation
17362306a36Sopenharmony_ci	 * (i.e. an invalid pointer).
17462306a36Sopenharmony_ci	 */
17562306a36Sopenharmony_ci	SCI_FATAL_ERROR,
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci	/**
17862306a36Sopenharmony_ci	 * This member indicates the calling function failed, because the state
17962306a36Sopenharmony_ci	 * of the controller is in a state that prevents successful completion.
18062306a36Sopenharmony_ci	 */
18162306a36Sopenharmony_ci	SCI_FAILURE_INVALID_STATE,
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ci	/**
18462306a36Sopenharmony_ci	 * This member indicates the calling function failed, because there is
18562306a36Sopenharmony_ci	 * insufficient resources/memory to complete the request.
18662306a36Sopenharmony_ci	 */
18762306a36Sopenharmony_ci	SCI_FAILURE_INSUFFICIENT_RESOURCES,
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci	/**
19062306a36Sopenharmony_ci	 * This member indicates the calling function failed, because the
19162306a36Sopenharmony_ci	 * controller object required for the operation can't be located.
19262306a36Sopenharmony_ci	 */
19362306a36Sopenharmony_ci	SCI_FAILURE_CONTROLLER_NOT_FOUND,
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_ci	/**
19662306a36Sopenharmony_ci	 * This member indicates the calling function failed, because the
19762306a36Sopenharmony_ci	 * discovered controller type is not supported by the library.
19862306a36Sopenharmony_ci	 */
19962306a36Sopenharmony_ci	SCI_FAILURE_UNSUPPORTED_CONTROLLER_TYPE,
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_ci	/**
20262306a36Sopenharmony_ci	 * This member indicates the calling function failed, because the
20362306a36Sopenharmony_ci	 * requested initialization data version isn't supported.
20462306a36Sopenharmony_ci	 */
20562306a36Sopenharmony_ci	SCI_FAILURE_UNSUPPORTED_INIT_DATA_VERSION,
20662306a36Sopenharmony_ci
20762306a36Sopenharmony_ci	/**
20862306a36Sopenharmony_ci	 * This member indicates the calling function failed, because the
20962306a36Sopenharmony_ci	 * requested configuration of SAS Phys into SAS Ports is not supported.
21062306a36Sopenharmony_ci	 */
21162306a36Sopenharmony_ci	SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION,
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_ci	/**
21462306a36Sopenharmony_ci	 * This member indicates the calling function failed, because the
21562306a36Sopenharmony_ci	 * requested protocol is not supported by the remote device, port,
21662306a36Sopenharmony_ci	 * or controller.
21762306a36Sopenharmony_ci	 */
21862306a36Sopenharmony_ci	SCI_FAILURE_UNSUPPORTED_PROTOCOL,
21962306a36Sopenharmony_ci
22062306a36Sopenharmony_ci	/**
22162306a36Sopenharmony_ci	 * This member indicates the calling function failed, because the
22262306a36Sopenharmony_ci	 * requested information type is not supported by the SCI implementation.
22362306a36Sopenharmony_ci	 */
22462306a36Sopenharmony_ci	SCI_FAILURE_UNSUPPORTED_INFORMATION_TYPE,
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_ci	/**
22762306a36Sopenharmony_ci	 * This member indicates the calling function failed, because the
22862306a36Sopenharmony_ci	 * device already exists.
22962306a36Sopenharmony_ci	 */
23062306a36Sopenharmony_ci	SCI_FAILURE_DEVICE_EXISTS,
23162306a36Sopenharmony_ci
23262306a36Sopenharmony_ci	/**
23362306a36Sopenharmony_ci	 * This member indicates the calling function failed, because adding
23462306a36Sopenharmony_ci	 * a phy to the object is not possible.
23562306a36Sopenharmony_ci	 */
23662306a36Sopenharmony_ci	SCI_FAILURE_ADDING_PHY_UNSUPPORTED,
23762306a36Sopenharmony_ci
23862306a36Sopenharmony_ci	/**
23962306a36Sopenharmony_ci	 * This member indicates the calling function failed, because the
24062306a36Sopenharmony_ci	 * requested information type is not supported by the SCI implementation.
24162306a36Sopenharmony_ci	 */
24262306a36Sopenharmony_ci	SCI_FAILURE_UNSUPPORTED_INFORMATION_FIELD,
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ci	/**
24562306a36Sopenharmony_ci	 * This member indicates the calling function failed, because the SCI
24662306a36Sopenharmony_ci	 * implementation does not support the supplied time limit.
24762306a36Sopenharmony_ci	 */
24862306a36Sopenharmony_ci	SCI_FAILURE_UNSUPPORTED_TIME_LIMIT,
24962306a36Sopenharmony_ci
25062306a36Sopenharmony_ci	/**
25162306a36Sopenharmony_ci	 * This member indicates the calling method failed, because the SCI
25262306a36Sopenharmony_ci	 * implementation does not contain the specified Phy.
25362306a36Sopenharmony_ci	 */
25462306a36Sopenharmony_ci	SCI_FAILURE_INVALID_PHY,
25562306a36Sopenharmony_ci
25662306a36Sopenharmony_ci	/**
25762306a36Sopenharmony_ci	 * This member indicates the calling method failed, because the SCI
25862306a36Sopenharmony_ci	 * implementation does not contain the specified Port.
25962306a36Sopenharmony_ci	 */
26062306a36Sopenharmony_ci	SCI_FAILURE_INVALID_PORT,
26162306a36Sopenharmony_ci
26262306a36Sopenharmony_ci	/**
26362306a36Sopenharmony_ci	 * This member indicates the calling method was partly successful
26462306a36Sopenharmony_ci	 * The port was reset but not all phys in port are operational
26562306a36Sopenharmony_ci	 */
26662306a36Sopenharmony_ci	SCI_FAILURE_RESET_PORT_PARTIAL_SUCCESS,
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_ci	/**
26962306a36Sopenharmony_ci	 * This member indicates that calling method failed
27062306a36Sopenharmony_ci	 * The port reset did not complete because none of the phys are operational
27162306a36Sopenharmony_ci	 */
27262306a36Sopenharmony_ci	SCI_FAILURE_RESET_PORT_FAILURE,
27362306a36Sopenharmony_ci
27462306a36Sopenharmony_ci	/**
27562306a36Sopenharmony_ci	 * This member indicates the calling method failed, because the SCI
27662306a36Sopenharmony_ci	 * implementation does not contain the specified remote device.
27762306a36Sopenharmony_ci	 */
27862306a36Sopenharmony_ci	SCI_FAILURE_INVALID_REMOTE_DEVICE,
27962306a36Sopenharmony_ci
28062306a36Sopenharmony_ci	/**
28162306a36Sopenharmony_ci	 * This member indicates the calling method failed, because the remote
28262306a36Sopenharmony_ci	 * device is in a bad state and requires a reset.
28362306a36Sopenharmony_ci	 */
28462306a36Sopenharmony_ci	SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED,
28562306a36Sopenharmony_ci
28662306a36Sopenharmony_ci	/**
28762306a36Sopenharmony_ci	 * This member indicates the calling method failed, because the SCI
28862306a36Sopenharmony_ci	 * implementation does not contain or support the specified IO tag.
28962306a36Sopenharmony_ci	 */
29062306a36Sopenharmony_ci	SCI_FAILURE_INVALID_IO_TAG,
29162306a36Sopenharmony_ci
29262306a36Sopenharmony_ci	/**
29362306a36Sopenharmony_ci	 * This member indicates that the operation failed and the user should
29462306a36Sopenharmony_ci	 * check the response data associated with the IO.
29562306a36Sopenharmony_ci	 */
29662306a36Sopenharmony_ci	SCI_FAILURE_IO_RESPONSE_VALID,
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_ci	/**
29962306a36Sopenharmony_ci	 * This member indicates that the operation failed, the failure is
30062306a36Sopenharmony_ci	 * controller implementation specific, and the response data associated
30162306a36Sopenharmony_ci	 * with the request is not valid.  You can query for the controller
30262306a36Sopenharmony_ci	 * specific error information via sci_controller_get_request_status()
30362306a36Sopenharmony_ci	 */
30462306a36Sopenharmony_ci	SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR,
30562306a36Sopenharmony_ci
30662306a36Sopenharmony_ci	/**
30762306a36Sopenharmony_ci	 * This member indicated that the operation failed because the
30862306a36Sopenharmony_ci	 * user requested this IO to be terminated.
30962306a36Sopenharmony_ci	 */
31062306a36Sopenharmony_ci	SCI_FAILURE_IO_TERMINATED,
31162306a36Sopenharmony_ci
31262306a36Sopenharmony_ci	/**
31362306a36Sopenharmony_ci	 * This member indicates that the operation failed and the associated
31462306a36Sopenharmony_ci	 * request requires a SCSI abort task to be sent to the target.
31562306a36Sopenharmony_ci	 */
31662306a36Sopenharmony_ci	SCI_FAILURE_IO_REQUIRES_SCSI_ABORT,
31762306a36Sopenharmony_ci
31862306a36Sopenharmony_ci	/**
31962306a36Sopenharmony_ci	 * This member indicates that the operation failed because the supplied
32062306a36Sopenharmony_ci	 * device could not be located.
32162306a36Sopenharmony_ci	 */
32262306a36Sopenharmony_ci	SCI_FAILURE_DEVICE_NOT_FOUND,
32362306a36Sopenharmony_ci
32462306a36Sopenharmony_ci	/**
32562306a36Sopenharmony_ci	 * This member indicates that the operation failed because the
32662306a36Sopenharmony_ci	 * objects association is required and is not correctly set.
32762306a36Sopenharmony_ci	 */
32862306a36Sopenharmony_ci	SCI_FAILURE_INVALID_ASSOCIATION,
32962306a36Sopenharmony_ci
33062306a36Sopenharmony_ci	/**
33162306a36Sopenharmony_ci	 * This member indicates that the operation failed, because a timeout
33262306a36Sopenharmony_ci	 * occurred.
33362306a36Sopenharmony_ci	 */
33462306a36Sopenharmony_ci	SCI_FAILURE_TIMEOUT,
33562306a36Sopenharmony_ci
33662306a36Sopenharmony_ci	/**
33762306a36Sopenharmony_ci	 * This member indicates that the operation failed, because the user
33862306a36Sopenharmony_ci	 * specified a value that is either invalid or not supported.
33962306a36Sopenharmony_ci	 */
34062306a36Sopenharmony_ci	SCI_FAILURE_INVALID_PARAMETER_VALUE,
34162306a36Sopenharmony_ci
34262306a36Sopenharmony_ci	/**
34362306a36Sopenharmony_ci	 * This value indicates that the operation failed, because the number
34462306a36Sopenharmony_ci	 * of messages (MSI-X) is not supported.
34562306a36Sopenharmony_ci	 */
34662306a36Sopenharmony_ci	SCI_FAILURE_UNSUPPORTED_MESSAGE_COUNT,
34762306a36Sopenharmony_ci
34862306a36Sopenharmony_ci	/**
34962306a36Sopenharmony_ci	 * This value indicates that the method failed due to a lack of
35062306a36Sopenharmony_ci	 * available NCQ tags.
35162306a36Sopenharmony_ci	 */
35262306a36Sopenharmony_ci	SCI_FAILURE_NO_NCQ_TAG_AVAILABLE,
35362306a36Sopenharmony_ci
35462306a36Sopenharmony_ci	/**
35562306a36Sopenharmony_ci	 * This value indicates that a protocol violation has occurred on the
35662306a36Sopenharmony_ci	 * link.
35762306a36Sopenharmony_ci	 */
35862306a36Sopenharmony_ci	SCI_FAILURE_PROTOCOL_VIOLATION,
35962306a36Sopenharmony_ci
36062306a36Sopenharmony_ci	/**
36162306a36Sopenharmony_ci	 * This value indicates a failure condition that retry may help to clear.
36262306a36Sopenharmony_ci	 */
36362306a36Sopenharmony_ci	SCI_FAILURE_RETRY_REQUIRED,
36462306a36Sopenharmony_ci
36562306a36Sopenharmony_ci	/**
36662306a36Sopenharmony_ci	 * This field indicates the retry limit was reached when a retry is attempted
36762306a36Sopenharmony_ci	 */
36862306a36Sopenharmony_ci	SCI_FAILURE_RETRY_LIMIT_REACHED,
36962306a36Sopenharmony_ci
37062306a36Sopenharmony_ci	/**
37162306a36Sopenharmony_ci	 * This member indicates the calling method was partly successful.
37262306a36Sopenharmony_ci	 * Mostly, this status is used when a LUN_RESET issued to an expander attached
37362306a36Sopenharmony_ci	 * STP device in READY NCQ substate needs to have RNC suspended/resumed
37462306a36Sopenharmony_ci	 * before posting TC.
37562306a36Sopenharmony_ci	 */
37662306a36Sopenharmony_ci	SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS,
37762306a36Sopenharmony_ci
37862306a36Sopenharmony_ci	/**
37962306a36Sopenharmony_ci	 * This field indicates an illegal phy connection based on the routing attribute
38062306a36Sopenharmony_ci	 * of both expander phy attached to each other.
38162306a36Sopenharmony_ci	 */
38262306a36Sopenharmony_ci	SCI_FAILURE_ILLEGAL_ROUTING_ATTRIBUTE_CONFIGURATION,
38362306a36Sopenharmony_ci
38462306a36Sopenharmony_ci	/**
38562306a36Sopenharmony_ci	 * This field indicates a CONFIG ROUTE INFO command has a response with function result
38662306a36Sopenharmony_ci	 * INDEX DOES NOT EXIST, usually means exceeding max route index.
38762306a36Sopenharmony_ci	 */
38862306a36Sopenharmony_ci	SCI_FAILURE_EXCEED_MAX_ROUTE_INDEX,
38962306a36Sopenharmony_ci
39062306a36Sopenharmony_ci	/**
39162306a36Sopenharmony_ci	 * This value indicates that an unsupported PCI device ID has been
39262306a36Sopenharmony_ci	 * specified.  This indicates that attempts to invoke
39362306a36Sopenharmony_ci	 * sci_library_allocate_controller() will fail.
39462306a36Sopenharmony_ci	 */
39562306a36Sopenharmony_ci	SCI_FAILURE_UNSUPPORTED_PCI_DEVICE_ID
39662306a36Sopenharmony_ci
39762306a36Sopenharmony_ci};
39862306a36Sopenharmony_ci
39962306a36Sopenharmony_ci/**
40062306a36Sopenharmony_ci * enum sci_io_status - This enumeration depicts all of the possible IO
40162306a36Sopenharmony_ci *    completion status values.  Each value in this enumeration maps directly
40262306a36Sopenharmony_ci *    to a value in the enum sci_status enumeration.  Please refer to that
40362306a36Sopenharmony_ci *    enumeration for detailed comments concerning what the status represents.
40462306a36Sopenharmony_ci *
40562306a36Sopenharmony_ci * Add the API to retrieve the SCU status from the core. Check to see that the
40662306a36Sopenharmony_ci * following status are properly handled: - SCI_IO_FAILURE_UNSUPPORTED_PROTOCOL
40762306a36Sopenharmony_ci * - SCI_IO_FAILURE_INVALID_IO_TAG
40862306a36Sopenharmony_ci */
40962306a36Sopenharmony_cienum sci_io_status {
41062306a36Sopenharmony_ci	SCI_IO_SUCCESS                         = SCI_SUCCESS,
41162306a36Sopenharmony_ci	SCI_IO_FAILURE                         = SCI_FAILURE,
41262306a36Sopenharmony_ci	SCI_IO_SUCCESS_COMPLETE_BEFORE_START   = SCI_SUCCESS_IO_COMPLETE_BEFORE_START,
41362306a36Sopenharmony_ci	SCI_IO_SUCCESS_IO_DONE_EARLY           = SCI_SUCCESS_IO_DONE_EARLY,
41462306a36Sopenharmony_ci	SCI_IO_FAILURE_INVALID_STATE           = SCI_FAILURE_INVALID_STATE,
41562306a36Sopenharmony_ci	SCI_IO_FAILURE_INSUFFICIENT_RESOURCES  = SCI_FAILURE_INSUFFICIENT_RESOURCES,
41662306a36Sopenharmony_ci	SCI_IO_FAILURE_UNSUPPORTED_PROTOCOL    = SCI_FAILURE_UNSUPPORTED_PROTOCOL,
41762306a36Sopenharmony_ci	SCI_IO_FAILURE_RESPONSE_VALID          = SCI_FAILURE_IO_RESPONSE_VALID,
41862306a36Sopenharmony_ci	SCI_IO_FAILURE_CONTROLLER_SPECIFIC_ERR = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR,
41962306a36Sopenharmony_ci	SCI_IO_FAILURE_TERMINATED              = SCI_FAILURE_IO_TERMINATED,
42062306a36Sopenharmony_ci	SCI_IO_FAILURE_REQUIRES_SCSI_ABORT     = SCI_FAILURE_IO_REQUIRES_SCSI_ABORT,
42162306a36Sopenharmony_ci	SCI_IO_FAILURE_INVALID_PARAMETER_VALUE = SCI_FAILURE_INVALID_PARAMETER_VALUE,
42262306a36Sopenharmony_ci	SCI_IO_FAILURE_NO_NCQ_TAG_AVAILABLE    = SCI_FAILURE_NO_NCQ_TAG_AVAILABLE,
42362306a36Sopenharmony_ci	SCI_IO_FAILURE_PROTOCOL_VIOLATION      = SCI_FAILURE_PROTOCOL_VIOLATION,
42462306a36Sopenharmony_ci
42562306a36Sopenharmony_ci	SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED = SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED,
42662306a36Sopenharmony_ci
42762306a36Sopenharmony_ci	SCI_IO_FAILURE_RETRY_REQUIRED      = SCI_FAILURE_RETRY_REQUIRED,
42862306a36Sopenharmony_ci	SCI_IO_FAILURE_RETRY_LIMIT_REACHED = SCI_FAILURE_RETRY_LIMIT_REACHED,
42962306a36Sopenharmony_ci	SCI_IO_FAILURE_INVALID_REMOTE_DEVICE = SCI_FAILURE_INVALID_REMOTE_DEVICE
43062306a36Sopenharmony_ci};
43162306a36Sopenharmony_ci
43262306a36Sopenharmony_ci/**
43362306a36Sopenharmony_ci * enum sci_task_status - This enumeration depicts all of the possible task
43462306a36Sopenharmony_ci *    completion status values.  Each value in this enumeration maps directly
43562306a36Sopenharmony_ci *    to a value in the enum sci_status enumeration.  Please refer to that
43662306a36Sopenharmony_ci *    enumeration for detailed comments concerning what the status represents.
43762306a36Sopenharmony_ci *
43862306a36Sopenharmony_ci * Check to see that the following status are properly handled:
43962306a36Sopenharmony_ci */
44062306a36Sopenharmony_cienum sci_task_status {
44162306a36Sopenharmony_ci	SCI_TASK_SUCCESS                         = SCI_SUCCESS,
44262306a36Sopenharmony_ci	SCI_TASK_FAILURE                         = SCI_FAILURE,
44362306a36Sopenharmony_ci	SCI_TASK_FAILURE_INVALID_STATE           = SCI_FAILURE_INVALID_STATE,
44462306a36Sopenharmony_ci	SCI_TASK_FAILURE_INSUFFICIENT_RESOURCES  = SCI_FAILURE_INSUFFICIENT_RESOURCES,
44562306a36Sopenharmony_ci	SCI_TASK_FAILURE_UNSUPPORTED_PROTOCOL    = SCI_FAILURE_UNSUPPORTED_PROTOCOL,
44662306a36Sopenharmony_ci	SCI_TASK_FAILURE_INVALID_TAG             = SCI_FAILURE_INVALID_IO_TAG,
44762306a36Sopenharmony_ci	SCI_TASK_FAILURE_RESPONSE_VALID          = SCI_FAILURE_IO_RESPONSE_VALID,
44862306a36Sopenharmony_ci	SCI_TASK_FAILURE_CONTROLLER_SPECIFIC_ERR = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR,
44962306a36Sopenharmony_ci	SCI_TASK_FAILURE_TERMINATED              = SCI_FAILURE_IO_TERMINATED,
45062306a36Sopenharmony_ci	SCI_TASK_FAILURE_INVALID_PARAMETER_VALUE = SCI_FAILURE_INVALID_PARAMETER_VALUE,
45162306a36Sopenharmony_ci
45262306a36Sopenharmony_ci	SCI_TASK_FAILURE_REMOTE_DEVICE_RESET_REQUIRED = SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED,
45362306a36Sopenharmony_ci	SCI_TASK_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS = SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS
45462306a36Sopenharmony_ci
45562306a36Sopenharmony_ci};
45662306a36Sopenharmony_ci
45762306a36Sopenharmony_ci/**
45862306a36Sopenharmony_ci * sci_swab32_cpy - convert between scsi and scu-hardware byte format
45962306a36Sopenharmony_ci * @dest: receive the 4-byte endian swapped version of src
46062306a36Sopenharmony_ci * @src: word aligned source buffer
46162306a36Sopenharmony_ci *
46262306a36Sopenharmony_ci * scu hardware handles SSP/SMP control, response, and unidentified
46362306a36Sopenharmony_ci * frames in "big endian dword" order.  Regardless of host endian this
46462306a36Sopenharmony_ci * is always a swab32()-per-dword conversion of the standard definition,
46562306a36Sopenharmony_ci * i.e. single byte fields swapped and multi-byte fields in little-
46662306a36Sopenharmony_ci * endian
46762306a36Sopenharmony_ci */
46862306a36Sopenharmony_cistatic inline void sci_swab32_cpy(void *_dest, void *_src, ssize_t word_cnt)
46962306a36Sopenharmony_ci{
47062306a36Sopenharmony_ci	u32 *dest = _dest, *src = _src;
47162306a36Sopenharmony_ci
47262306a36Sopenharmony_ci	while (--word_cnt >= 0)
47362306a36Sopenharmony_ci		dest[word_cnt] = swab32(src[word_cnt]);
47462306a36Sopenharmony_ci}
47562306a36Sopenharmony_ci
47662306a36Sopenharmony_ciextern unsigned char no_outbound_task_to;
47762306a36Sopenharmony_ciextern u16 ssp_max_occ_to;
47862306a36Sopenharmony_ciextern u16 stp_max_occ_to;
47962306a36Sopenharmony_ciextern u16 ssp_inactive_to;
48062306a36Sopenharmony_ciextern u16 stp_inactive_to;
48162306a36Sopenharmony_ciextern unsigned char phy_gen;
48262306a36Sopenharmony_ciextern unsigned char max_concurr_spinup;
48362306a36Sopenharmony_ciextern uint cable_selection_override;
48462306a36Sopenharmony_ci
48562306a36Sopenharmony_ciirqreturn_t isci_msix_isr(int vec, void *data);
48662306a36Sopenharmony_ciirqreturn_t isci_intx_isr(int vec, void *data);
48762306a36Sopenharmony_ciirqreturn_t isci_error_isr(int vec, void *data);
48862306a36Sopenharmony_ci
48962306a36Sopenharmony_ci/*
49062306a36Sopenharmony_ci * Each timer is associated with a cancellation flag that is set when
49162306a36Sopenharmony_ci * del_timer() is called and checked in the timer callback function. This
49262306a36Sopenharmony_ci * is needed since del_timer_sync() cannot be called with sci_lock held.
49362306a36Sopenharmony_ci * For deinit however, del_timer_sync() is used without holding the lock.
49462306a36Sopenharmony_ci */
49562306a36Sopenharmony_cistruct sci_timer {
49662306a36Sopenharmony_ci	struct timer_list	timer;
49762306a36Sopenharmony_ci	bool			cancel;
49862306a36Sopenharmony_ci};
49962306a36Sopenharmony_ci
50062306a36Sopenharmony_cistatic inline
50162306a36Sopenharmony_civoid sci_init_timer(struct sci_timer *tmr, void (*fn)(struct timer_list *t))
50262306a36Sopenharmony_ci{
50362306a36Sopenharmony_ci	tmr->cancel = false;
50462306a36Sopenharmony_ci	timer_setup(&tmr->timer, fn, 0);
50562306a36Sopenharmony_ci}
50662306a36Sopenharmony_ci
50762306a36Sopenharmony_cistatic inline void sci_mod_timer(struct sci_timer *tmr, unsigned long msec)
50862306a36Sopenharmony_ci{
50962306a36Sopenharmony_ci	tmr->cancel = false;
51062306a36Sopenharmony_ci	mod_timer(&tmr->timer, jiffies + msecs_to_jiffies(msec));
51162306a36Sopenharmony_ci}
51262306a36Sopenharmony_ci
51362306a36Sopenharmony_cistatic inline void sci_del_timer(struct sci_timer *tmr)
51462306a36Sopenharmony_ci{
51562306a36Sopenharmony_ci	tmr->cancel = true;
51662306a36Sopenharmony_ci	del_timer(&tmr->timer);
51762306a36Sopenharmony_ci}
51862306a36Sopenharmony_ci
51962306a36Sopenharmony_cistruct sci_base_state_machine {
52062306a36Sopenharmony_ci	const struct sci_base_state *state_table;
52162306a36Sopenharmony_ci	u32 initial_state_id;
52262306a36Sopenharmony_ci	u32 current_state_id;
52362306a36Sopenharmony_ci	u32 previous_state_id;
52462306a36Sopenharmony_ci};
52562306a36Sopenharmony_ci
52662306a36Sopenharmony_citypedef void (*sci_state_transition_t)(struct sci_base_state_machine *sm);
52762306a36Sopenharmony_ci
52862306a36Sopenharmony_cistruct sci_base_state {
52962306a36Sopenharmony_ci	sci_state_transition_t enter_state;	/* Called on state entry */
53062306a36Sopenharmony_ci	sci_state_transition_t exit_state;	/* Called on state exit */
53162306a36Sopenharmony_ci};
53262306a36Sopenharmony_ci
53362306a36Sopenharmony_ciextern void sci_init_sm(struct sci_base_state_machine *sm,
53462306a36Sopenharmony_ci			const struct sci_base_state *state_table,
53562306a36Sopenharmony_ci			u32 initial_state);
53662306a36Sopenharmony_ciextern void sci_change_state(struct sci_base_state_machine *sm, u32 next_state);
53762306a36Sopenharmony_ci#endif  /* __ISCI_H__ */
538