16f231dda68080759f1aed3769896e94c73099f0fDan Williams/*
26f231dda68080759f1aed3769896e94c73099f0fDan Williams * This file is provided under a dual BSD/GPLv2 license.  When using or
36f231dda68080759f1aed3769896e94c73099f0fDan Williams * redistributing this file, you may do so under either license.
46f231dda68080759f1aed3769896e94c73099f0fDan Williams *
56f231dda68080759f1aed3769896e94c73099f0fDan Williams * GPL LICENSE SUMMARY
66f231dda68080759f1aed3769896e94c73099f0fDan Williams *
76f231dda68080759f1aed3769896e94c73099f0fDan Williams * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
86f231dda68080759f1aed3769896e94c73099f0fDan Williams *
96f231dda68080759f1aed3769896e94c73099f0fDan Williams * This program is free software; you can redistribute it and/or modify
106f231dda68080759f1aed3769896e94c73099f0fDan Williams * it under the terms of version 2 of the GNU General Public License as
116f231dda68080759f1aed3769896e94c73099f0fDan Williams * published by the Free Software Foundation.
126f231dda68080759f1aed3769896e94c73099f0fDan Williams *
136f231dda68080759f1aed3769896e94c73099f0fDan Williams * This program is distributed in the hope that it will be useful, but
146f231dda68080759f1aed3769896e94c73099f0fDan Williams * WITHOUT ANY WARRANTY; without even the implied warranty of
156f231dda68080759f1aed3769896e94c73099f0fDan Williams * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
166f231dda68080759f1aed3769896e94c73099f0fDan Williams * General Public License for more details.
176f231dda68080759f1aed3769896e94c73099f0fDan Williams *
186f231dda68080759f1aed3769896e94c73099f0fDan Williams * You should have received a copy of the GNU General Public License
196f231dda68080759f1aed3769896e94c73099f0fDan Williams * along with this program; if not, write to the Free Software
206f231dda68080759f1aed3769896e94c73099f0fDan Williams * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
216f231dda68080759f1aed3769896e94c73099f0fDan Williams * The full GNU General Public License is included in this distribution
226f231dda68080759f1aed3769896e94c73099f0fDan Williams * in the file called LICENSE.GPL.
236f231dda68080759f1aed3769896e94c73099f0fDan Williams *
246f231dda68080759f1aed3769896e94c73099f0fDan Williams * BSD LICENSE
256f231dda68080759f1aed3769896e94c73099f0fDan Williams *
266f231dda68080759f1aed3769896e94c73099f0fDan Williams * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
276f231dda68080759f1aed3769896e94c73099f0fDan Williams * All rights reserved.
286f231dda68080759f1aed3769896e94c73099f0fDan Williams *
296f231dda68080759f1aed3769896e94c73099f0fDan Williams * Redistribution and use in source and binary forms, with or without
306f231dda68080759f1aed3769896e94c73099f0fDan Williams * modification, are permitted provided that the following conditions
316f231dda68080759f1aed3769896e94c73099f0fDan Williams * are met:
326f231dda68080759f1aed3769896e94c73099f0fDan Williams *
336f231dda68080759f1aed3769896e94c73099f0fDan Williams *   * Redistributions of source code must retain the above copyright
346f231dda68080759f1aed3769896e94c73099f0fDan Williams *     notice, this list of conditions and the following disclaimer.
356f231dda68080759f1aed3769896e94c73099f0fDan Williams *   * Redistributions in binary form must reproduce the above copyright
366f231dda68080759f1aed3769896e94c73099f0fDan Williams *     notice, this list of conditions and the following disclaimer in
376f231dda68080759f1aed3769896e94c73099f0fDan Williams *     the documentation and/or other materials provided with the
386f231dda68080759f1aed3769896e94c73099f0fDan Williams *     distribution.
396f231dda68080759f1aed3769896e94c73099f0fDan Williams *   * Neither the name of Intel Corporation nor the names of its
406f231dda68080759f1aed3769896e94c73099f0fDan Williams *     contributors may be used to endorse or promote products derived
416f231dda68080759f1aed3769896e94c73099f0fDan Williams *     from this software without specific prior written permission.
426f231dda68080759f1aed3769896e94c73099f0fDan Williams *
436f231dda68080759f1aed3769896e94c73099f0fDan Williams * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
446f231dda68080759f1aed3769896e94c73099f0fDan Williams * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
456f231dda68080759f1aed3769896e94c73099f0fDan Williams * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
466f231dda68080759f1aed3769896e94c73099f0fDan Williams * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
476f231dda68080759f1aed3769896e94c73099f0fDan Williams * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
486f231dda68080759f1aed3769896e94c73099f0fDan Williams * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
496f231dda68080759f1aed3769896e94c73099f0fDan Williams * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
506f231dda68080759f1aed3769896e94c73099f0fDan Williams * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
516f231dda68080759f1aed3769896e94c73099f0fDan Williams * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
526f231dda68080759f1aed3769896e94c73099f0fDan Williams * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
536f231dda68080759f1aed3769896e94c73099f0fDan Williams * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
546f231dda68080759f1aed3769896e94c73099f0fDan Williams */
55ce2b3261b6765c3b80fda95426c73e8d3bb1b035Dan Williams#ifndef _SCI_HOST_H_
566f231dda68080759f1aed3769896e94c73099f0fDan Williams#define _SCI_HOST_H_
576f231dda68080759f1aed3769896e94c73099f0fDan Williams
5811cc51835af0e6fbb2da9cb012bdaaa036497b7fDan Williams#include <scsi/sas_ata.h>
596f231dda68080759f1aed3769896e94c73099f0fDan Williams#include "remote_device.h"
60ce2b3261b6765c3b80fda95426c73e8d3bb1b035Dan Williams#include "phy.h"
6112ef65444de9d387a383b9991960848bed5bbe74Edmund Nadolski#include "isci.h"
62cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams#include "remote_node_table.h"
6363a3a15fb00ef49e50e98ff675094afcd92f113aDan Williams#include "registers.h"
6463a3a15fb00ef49e50e98ff675094afcd92f113aDan Williams#include "unsolicited_frame_control.h"
65e2f8db509fdd354bb7a68c86515e9d2d8909ccc9Dan Williams#include "probe_roms.h"
66cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
675076a1a97e2fa61c847a5fdd4b1991faf7716da6Dan Williamsstruct isci_request;
68cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williamsstruct scu_task_context;
69cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
70e2f8db509fdd354bb7a68c86515e9d2d8909ccc9Dan Williams
71cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams/**
7289a7301f21fb00e753089671eb9e4132aab8ea08Dan Williams * struct sci_power_control -
73cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams *
74cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams * This structure defines the fields for managing power control for direct
75cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams * attached disk devices.
76cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams */
7789a7301f21fb00e753089671eb9e4132aab8ea08Dan Williamsstruct sci_power_control {
78cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	/**
79cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This field is set when the power control timer is running and cleared when
80cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * it is not.
81cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 */
82cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	bool timer_started;
83cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
84cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	/**
850473661a125905240879456567e117ed8a58cf5dEdmund Nadolski	 * Timer to control when the directed attached disks can consume power.
86cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 */
870473661a125905240879456567e117ed8a58cf5dEdmund Nadolski	struct sci_timer timer;
88cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
89cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	/**
90cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This field is used to keep track of how many phys are put into the
91cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * requesters field.
92cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 */
93cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	u8 phys_waiting;
94cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
95cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	/**
96cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This field is used to keep track of how many phys have been granted to consume power
97cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 */
98cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	u8 phys_granted_power;
99cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
100cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	/**
101cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This field is an array of phys that we are waiting on. The phys are direct
10289a7301f21fb00e753089671eb9e4132aab8ea08Dan Williams	 * mapped into requesters via struct sci_phy.phy_index
103cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 */
104852809559e4680ba4768262a6c3d21454fcd460eDan Williams	struct isci_phy *requesters[SCI_MAX_PHYS];
105cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
106cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams};
107cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
10889a7301f21fb00e753089671eb9e4132aab8ea08Dan Williamsstruct sci_port_configuration_agent;
109d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williamstypedef void (*port_config_fn)(struct isci_host *,
11089a7301f21fb00e753089671eb9e4132aab8ea08Dan Williams			       struct sci_port_configuration_agent *,
111ffe191c92ff195d73f9130b1490045ca2dd4c5e0Dan Williams			       struct isci_port *, struct isci_phy *);
11250a92d93148ec073efd2456b007e04ecae452086Dan Williamsbool is_port_config_apc(struct isci_host *ihost);
11350a92d93148ec073efd2456b007e04ecae452086Dan Williamsbool is_controller_start_complete(struct isci_host *ihost);
114e2f8db509fdd354bb7a68c86515e9d2d8909ccc9Dan Williams
11589a7301f21fb00e753089671eb9e4132aab8ea08Dan Williamsstruct sci_port_configuration_agent {
116e2f8db509fdd354bb7a68c86515e9d2d8909ccc9Dan Williams	u16 phy_configured_mask;
117e2f8db509fdd354bb7a68c86515e9d2d8909ccc9Dan Williams	u16 phy_ready_mask;
118e2f8db509fdd354bb7a68c86515e9d2d8909ccc9Dan Williams	struct {
119e2f8db509fdd354bb7a68c86515e9d2d8909ccc9Dan Williams		u8 min_index;
120e2f8db509fdd354bb7a68c86515e9d2d8909ccc9Dan Williams		u8 max_index;
121e2f8db509fdd354bb7a68c86515e9d2d8909ccc9Dan Williams	} phy_valid_port_range[SCI_MAX_PHYS];
122e2f8db509fdd354bb7a68c86515e9d2d8909ccc9Dan Williams	bool timer_pending;
123e2f8db509fdd354bb7a68c86515e9d2d8909ccc9Dan Williams	port_config_fn link_up_handler;
124e2f8db509fdd354bb7a68c86515e9d2d8909ccc9Dan Williams	port_config_fn link_down_handler;
125ac0eeb4f774261d1da21a68169f7ddd4f6c082fcEdmund Nadolski	struct sci_timer	timer;
126e2f8db509fdd354bb7a68c86515e9d2d8909ccc9Dan Williams};
127e2f8db509fdd354bb7a68c86515e9d2d8909ccc9Dan Williams
128cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams/**
129d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams * isci_host - primary host/controller object
130d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams * @timer: timeout start/stop operations
131d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams * @device_table: rni (hw remote node index) to remote device lookup table
132d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams * @available_remote_nodes: rni allocator
133d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams * @power_control: manage device spin up
134d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams * @io_request_sequence: generation number for tci's (task contexts)
135d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams * @task_context_table: hw task context table
136d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams * @remote_node_context_table: hw remote node context table
137d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams * @completion_queue: hw-producer driver-consumer communication ring
138d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams * @completion_queue_get: tracks the driver 'head' of the ring to notify hw
139d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams * @logical_port_entries: min({driver|silicon}-supported-port-count)
140d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams * @remote_node_entries: min({driver|silicon}-supported-node-count)
141d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams * @task_context_entries: min({driver|silicon}-supported-task-count)
142d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams * @phy_timer: phy startup timer
143d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams * @invalid_phy_mask: if an invalid_link_up notification is reported a bit for
144d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams * 		      the phy index is set so further notifications are not
145d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams * 		      made.  Once the phy reports link up and is made part of a
146d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams * 		      port then this bit is cleared.
147d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams
148cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams */
149d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williamsstruct isci_host {
150e301370ac553a9a0ac0d1d25e769b86cf60395b3Edmund Nadolski	struct sci_base_state_machine sm;
151d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams	/* XXX can we time this externally */
1526cb5853d3e252015eaf72d3761491e3da959556dEdmund Nadolski	struct sci_timer timer;
153d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams	/* XXX drop reference module params directly */
15489a7301f21fb00e753089671eb9e4132aab8ea08Dan Williams	struct sci_user_parameters user_parameters;
155d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams	/* XXX no need to be a union */
15689a7301f21fb00e753089671eb9e4132aab8ea08Dan Williams	struct sci_oem_params oem_parameters;
15789a7301f21fb00e753089671eb9e4132aab8ea08Dan Williams	struct sci_port_configuration_agent port_agent;
15878a6f06e0e82125787d7aa308fe28c2c8381540cDan Williams	struct isci_remote_device *device_table[SCI_MAX_REMOTE_DEVICES];
15989a7301f21fb00e753089671eb9e4132aab8ea08Dan Williams	struct sci_remote_node_table available_remote_nodes;
16089a7301f21fb00e753089671eb9e4132aab8ea08Dan Williams	struct sci_power_control power_control;
161dd047c8e2bca22856050dbe0378a37cf44eecc97Dan Williams	u8 io_request_sequence[SCI_MAX_IO_REQUESTS];
162cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	struct scu_task_context *task_context_table;
163abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williams	dma_addr_t tc_dma;
164cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	union scu_remote_node_context *remote_node_context_table;
165abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williams	dma_addr_t rnc_dma;
166cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	u32 *completion_queue;
167abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williams	dma_addr_t cq_dma;
168cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	u32 completion_queue_get;
169cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	u32 logical_port_entries;
170cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	u32 remote_node_entries;
171cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	u32 task_context_entries;
172abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williams	void *ufi_buf;
173abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williams	dma_addr_t ufi_dma;
17489a7301f21fb00e753089671eb9e4132aab8ea08Dan Williams	struct sci_unsolicited_frame_control uf_control;
175cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
176d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams	/* phy startup */
177bb3dbdf6c835a145e46119ed18a920a774694583Edmund Nadolski	struct sci_timer phy_timer;
178d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams	/* XXX kill */
179cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	bool phy_startup_timer_pending;
180cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	u32 next_phy_to_start;
18134a991587a5cc9f78960c2c9beea217866458c41Dan Williams	/* XXX convert to unsigned long and use bitops */
182cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	u8 invalid_phy_mask;
183cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
184d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams	/* TODO attempt dynamic interrupt coalescing scheme */
185cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	u16 interrupt_coalesce_number;
186cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	u32 interrupt_coalesce_timeout;
187cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	struct smu_registers __iomem *smu_registers;
188cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	struct scu_registers __iomem *scu_registers;
189cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
190ac668c69709c7d927015c5cf3d9e87bf4eaaf57dDan Williams	u16 tci_head;
191ac668c69709c7d927015c5cf3d9e87bf4eaaf57dDan Williams	u16 tci_tail;
192ac668c69709c7d927015c5cf3d9e87bf4eaaf57dDan Williams	u16 tci_pool[SCI_MAX_IO_REQUESTS];
193ac668c69709c7d927015c5cf3d9e87bf4eaaf57dDan Williams
1946f231dda68080759f1aed3769896e94c73099f0fDan Williams	int id; /* unique within a given pci device */
1956f231dda68080759f1aed3769896e94c73099f0fDan Williams	struct isci_phy phys[SCI_MAX_PHYS];
196e531381e2f8a68b8737c63c7bb890ad80b2470bdDan Williams	struct isci_port ports[SCI_MAX_PORTS + 1]; /* includes dummy port */
197c132f692085ac624d7c8123df781846c8dcb3166Dan Williams	struct asd_sas_port sas_ports[SCI_MAX_PORTS];
1986f231dda68080759f1aed3769896e94c73099f0fDan Williams	struct sas_ha_struct sas_ha;
1996f231dda68080759f1aed3769896e94c73099f0fDan Williams
2006f231dda68080759f1aed3769896e94c73099f0fDan Williams	struct pci_dev *pdev;
2010cf89d1d27c1bdd0abf1714096f98ea44704dcffDan Williams	#define IHOST_START_PENDING 0
2020cf89d1d27c1bdd0abf1714096f98ea44704dcffDan Williams	#define IHOST_STOP_PENDING 1
2032396a2650a5a39634e3ad6b29e1104944e5ab88fDan Williams	#define IHOST_IRQ_ENABLED 2
2040cf89d1d27c1bdd0abf1714096f98ea44704dcffDan Williams	unsigned long flags;
2050cf89d1d27c1bdd0abf1714096f98ea44704dcffDan Williams	wait_queue_head_t eventq;
2066f231dda68080759f1aed3769896e94c73099f0fDan Williams	struct tasklet_struct completion_tasklet;
2076f231dda68080759f1aed3769896e94c73099f0fDan Williams	spinlock_t scic_lock;
208db0562509800a2d4cb5cb14a66413c30484f165cDan Williams	struct isci_request *reqs[SCI_MAX_IO_REQUESTS];
20957f20f4ed6fb702339be2ef4dea9d15e6a7d0d07Dan Williams	struct isci_remote_device devices[SCI_MAX_REMOTE_DEVICES];
2106f231dda68080759f1aed3769896e94c73099f0fDan Williams};
2116f231dda68080759f1aed3769896e94c73099f0fDan Williams
2126f231dda68080759f1aed3769896e94c73099f0fDan Williams/**
21389a7301f21fb00e753089671eb9e4132aab8ea08Dan Williams * enum sci_controller_states - This enumeration depicts all the states
214cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams *    for the common controller state machine.
215cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams */
21689a7301f21fb00e753089671eb9e4132aab8ea08Dan Williamsenum sci_controller_states {
217cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	/**
218cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * Simply the initial state for the base controller state machine.
219cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 */
220e301370ac553a9a0ac0d1d25e769b86cf60395b3Edmund Nadolski	SCIC_INITIAL = 0,
221cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
222cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	/**
223cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state indicates that the controller is reset.  The memory for
224cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * the controller is in it's initial state, but the controller requires
225cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * initialization.
226cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state is entered from the INITIAL state.
227cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state is entered from the RESETTING state.
228cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 */
229e301370ac553a9a0ac0d1d25e769b86cf60395b3Edmund Nadolski	SCIC_RESET,
230cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
231cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	/**
232cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state is typically an action state that indicates the controller
233cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * is in the process of initialization.  In this state no new IO operations
234cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * are permitted.
235cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state is entered from the RESET state.
236cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 */
237e301370ac553a9a0ac0d1d25e769b86cf60395b3Edmund Nadolski	SCIC_INITIALIZING,
238cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
239cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	/**
240cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state indicates that the controller has been successfully
241cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * initialized.  In this state no new IO operations are permitted.
242cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state is entered from the INITIALIZING state.
243cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 */
244e301370ac553a9a0ac0d1d25e769b86cf60395b3Edmund Nadolski	SCIC_INITIALIZED,
245cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
246cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	/**
247cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state indicates the the controller is in the process of becoming
248cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * ready (i.e. starting).  In this state no new IO operations are permitted.
249cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state is entered from the INITIALIZED state.
250cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 */
251e301370ac553a9a0ac0d1d25e769b86cf60395b3Edmund Nadolski	SCIC_STARTING,
252cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
253cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	/**
254cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state indicates the controller is now ready.  Thus, the user
255cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * is able to perform IO operations on the controller.
256cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state is entered from the STARTING state.
257cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 */
258e301370ac553a9a0ac0d1d25e769b86cf60395b3Edmund Nadolski	SCIC_READY,
259cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
260cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	/**
261cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state is typically an action state that indicates the controller
262cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * is in the process of resetting.  Thus, the user is unable to perform
263cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * IO operations on the controller.  A reset is considered destructive in
264cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * most cases.
265cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state is entered from the READY state.
266cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state is entered from the FAILED state.
267cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state is entered from the STOPPED state.
268cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 */
269e301370ac553a9a0ac0d1d25e769b86cf60395b3Edmund Nadolski	SCIC_RESETTING,
270cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
271cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	/**
272cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state indicates that the controller is in the process of stopping.
273cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * In this state no new IO operations are permitted, but existing IO
274cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * operations are allowed to complete.
275cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state is entered from the READY state.
276cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 */
277e301370ac553a9a0ac0d1d25e769b86cf60395b3Edmund Nadolski	SCIC_STOPPING,
278cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
279cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	/**
280cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state indicates that the controller could not successfully be
281cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * initialized.  In this state no new IO operations are permitted.
282cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state is entered from the INITIALIZING state.
283cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state is entered from the STARTING state.
284cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state is entered from the STOPPING state.
285cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 * This state is entered from the RESETTING state.
286cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	 */
287e301370ac553a9a0ac0d1d25e769b86cf60395b3Edmund Nadolski	SCIC_FAILED,
288cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams};
289cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
290cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams/**
2916f231dda68080759f1aed3769896e94c73099f0fDan Williams * struct isci_pci_info - This class represents the pci function containing the
2926f231dda68080759f1aed3769896e94c73099f0fDan Williams *    controllers. Depending on PCI SKU, there could be up to 2 controllers in
2936f231dda68080759f1aed3769896e94c73099f0fDan Williams *    the PCI function.
2946f231dda68080759f1aed3769896e94c73099f0fDan Williams */
2956f231dda68080759f1aed3769896e94c73099f0fDan Williams#define SCI_MAX_MSIX_INT (SCI_NUM_MSI_X_INT*SCI_MAX_CONTROLLERS)
2966f231dda68080759f1aed3769896e94c73099f0fDan Williams
2976f231dda68080759f1aed3769896e94c73099f0fDan Williamsstruct isci_pci_info {
2986f231dda68080759f1aed3769896e94c73099f0fDan Williams	struct msix_entry msix_entries[SCI_MAX_MSIX_INT];
299b329aff107543c3c4db26c1572405034c3baf906Dan Williams	struct isci_host *hosts[SCI_MAX_CONTROLLERS];
300d044af17aacd03a1f4fced1af4b7570d205c8fd9Dan Williams	struct isci_orom *orom;
3016f231dda68080759f1aed3769896e94c73099f0fDan Williams};
3026f231dda68080759f1aed3769896e94c73099f0fDan Williams
3036f231dda68080759f1aed3769896e94c73099f0fDan Williamsstatic inline struct isci_pci_info *to_pci_info(struct pci_dev *pdev)
3046f231dda68080759f1aed3769896e94c73099f0fDan Williams{
3056f231dda68080759f1aed3769896e94c73099f0fDan Williams	return pci_get_drvdata(pdev);
3066f231dda68080759f1aed3769896e94c73099f0fDan Williams}
3076f231dda68080759f1aed3769896e94c73099f0fDan Williams
308d1dc5e2d21a55538167d7ce82aa147c91c5e6788Dan Williamsstatic inline struct Scsi_Host *to_shost(struct isci_host *ihost)
309d1dc5e2d21a55538167d7ce82aa147c91c5e6788Dan Williams{
310d1dc5e2d21a55538167d7ce82aa147c91c5e6788Dan Williams	return ihost->sas_ha.core.shost;
311d1dc5e2d21a55538167d7ce82aa147c91c5e6788Dan Williams}
312d1dc5e2d21a55538167d7ce82aa147c91c5e6788Dan Williams
313b329aff107543c3c4db26c1572405034c3baf906Dan Williams#define for_each_isci_host(id, ihost, pdev) \
314c59053a23d586675c25d789a7494adfdc02fba57Lukasz Dorau	for (id = 0; id < SCI_MAX_CONTROLLERS && \
315c59053a23d586675c25d789a7494adfdc02fba57Lukasz Dorau	     (ihost = to_pci_info(pdev)->hosts[id]); id++)
3166f231dda68080759f1aed3769896e94c73099f0fDan Williams
3170cf89d1d27c1bdd0abf1714096f98ea44704dcffDan Williamsstatic inline void wait_for_start(struct isci_host *ihost)
3180cf89d1d27c1bdd0abf1714096f98ea44704dcffDan Williams{
3190cf89d1d27c1bdd0abf1714096f98ea44704dcffDan Williams	wait_event(ihost->eventq, !test_bit(IHOST_START_PENDING, &ihost->flags));
3200cf89d1d27c1bdd0abf1714096f98ea44704dcffDan Williams}
3210cf89d1d27c1bdd0abf1714096f98ea44704dcffDan Williams
3220cf89d1d27c1bdd0abf1714096f98ea44704dcffDan Williamsstatic inline void wait_for_stop(struct isci_host *ihost)
3230cf89d1d27c1bdd0abf1714096f98ea44704dcffDan Williams{
3240cf89d1d27c1bdd0abf1714096f98ea44704dcffDan Williams	wait_event(ihost->eventq, !test_bit(IHOST_STOP_PENDING, &ihost->flags));
3250cf89d1d27c1bdd0abf1714096f98ea44704dcffDan Williams}
3260cf89d1d27c1bdd0abf1714096f98ea44704dcffDan Williams
3276ad31fec306d532031b2f778f8656385df1b9d8fDan Williamsstatic inline void wait_for_device_start(struct isci_host *ihost, struct isci_remote_device *idev)
3286ad31fec306d532031b2f778f8656385df1b9d8fDan Williams{
3296ad31fec306d532031b2f778f8656385df1b9d8fDan Williams	wait_event(ihost->eventq, !test_bit(IDEV_START_PENDING, &idev->flags));
3306ad31fec306d532031b2f778f8656385df1b9d8fDan Williams}
3316ad31fec306d532031b2f778f8656385df1b9d8fDan Williams
3326ad31fec306d532031b2f778f8656385df1b9d8fDan Williamsstatic inline void wait_for_device_stop(struct isci_host *ihost, struct isci_remote_device *idev)
3336ad31fec306d532031b2f778f8656385df1b9d8fDan Williams{
334d9c37390c4f02153188a64a7a89fa6798dc3ffc2Dan Williams	wait_event(ihost->eventq, !test_bit(IDEV_STOP_PENDING, &idev->flags));
3356ad31fec306d532031b2f778f8656385df1b9d8fDan Williams}
3360cf89d1d27c1bdd0abf1714096f98ea44704dcffDan Williams
3374393aa4e6b9517a666f0ef6b774fd421a9dc4c68Dan Williamsstatic inline struct isci_host *dev_to_ihost(struct domain_device *dev)
3384393aa4e6b9517a666f0ef6b774fd421a9dc4c68Dan Williams{
3394393aa4e6b9517a666f0ef6b774fd421a9dc4c68Dan Williams	return dev->port->ha->lldd_ha;
3404393aa4e6b9517a666f0ef6b774fd421a9dc4c68Dan Williams}
3416f231dda68080759f1aed3769896e94c73099f0fDan Williams
342de2eb4d5c5c25e8fb75d1e19092f24b83cb7d8d5Jeff Skirvinstatic inline struct isci_host *idev_to_ihost(struct isci_remote_device *idev)
343de2eb4d5c5c25e8fb75d1e19092f24b83cb7d8d5Jeff Skirvin{
344de2eb4d5c5c25e8fb75d1e19092f24b83cb7d8d5Jeff Skirvin	return dev_to_ihost(idev->domain_dev);
345de2eb4d5c5c25e8fb75d1e19092f24b83cb7d8d5Jeff Skirvin}
346de2eb4d5c5c25e8fb75d1e19092f24b83cb7d8d5Jeff Skirvin
34734a991587a5cc9f78960c2c9beea217866458c41Dan Williams/* we always use protocol engine group zero */
34834a991587a5cc9f78960c2c9beea217866458c41Dan Williams#define ISCI_PEG 0
3496f231dda68080759f1aed3769896e94c73099f0fDan Williams
35089a7301f21fb00e753089671eb9e4132aab8ea08Dan Williams/* see sci_controller_io_tag_allocate|free for how seq and tci are built */
351dd047c8e2bca22856050dbe0378a37cf44eecc97Dan Williams#define ISCI_TAG(seq, tci) (((u16) (seq)) << 12 | tci)
352cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
353dd047c8e2bca22856050dbe0378a37cf44eecc97Dan Williams/* these are returned by the hardware, so sanitize them */
354dd047c8e2bca22856050dbe0378a37cf44eecc97Dan Williams#define ISCI_TAG_SEQ(tag) (((tag) >> 12) & (SCI_MAX_SEQ-1))
355dd047c8e2bca22856050dbe0378a37cf44eecc97Dan Williams#define ISCI_TAG_TCI(tag) ((tag) & (SCI_MAX_IO_REQUESTS-1))
356cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
3579b4be528999483d70a1ffc0accd102e477d5a503Dan Williams/* interrupt coalescing baseline: 9 == 3 to 5us interrupt delay per command */
3589b4be528999483d70a1ffc0accd102e477d5a503Dan Williams#define ISCI_COALESCE_BASE 9
3599b4be528999483d70a1ffc0accd102e477d5a503Dan Williams
360cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams/* expander attached sata devices require 3 rnc slots */
36189a7301f21fb00e753089671eb9e4132aab8ea08Dan Williamsstatic inline int sci_remote_device_node_count(struct isci_remote_device *idev)
362cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams{
36378a6f06e0e82125787d7aa308fe28c2c8381540cDan Williams	struct domain_device *dev = idev->domain_dev;
364cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
36511cc51835af0e6fbb2da9cb012bdaaa036497b7fDan Williams	if (dev_is_sata(dev) && dev->parent)
366cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams		return SCU_STP_REMOTE_NODE_COUNT;
367cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	return SCU_SSP_REMOTE_NODE_COUNT;
368cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams}
369cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
370cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams/**
37189a7301f21fb00e753089671eb9e4132aab8ea08Dan Williams * sci_controller_clear_invalid_phy() -
372cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams *
373cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams * This macro will clear the bit in the invalid phy mask for this controller
374cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams * object.  This is used to control messages reported for invalid link up
375cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams * notifications.
376cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams */
37789a7301f21fb00e753089671eb9e4132aab8ea08Dan Williams#define sci_controller_clear_invalid_phy(controller, phy) \
378cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	((controller)->invalid_phy_mask &= ~(1 << (phy)->phy_index))
379cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
38078a6f06e0e82125787d7aa308fe28c2c8381540cDan Williamsstatic inline struct device *scirdev_to_dev(struct isci_remote_device *idev)
381cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams{
382cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	if (!idev || !idev->isci_port || !idev->isci_port->isci_host)
383cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams		return NULL;
384cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
385cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	return &idev->isci_port->isci_host->pdev->dev;
386cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams}
387cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
388dc00c8b6940aa10ab1ce6a4d10b1bfe7b848781bDan Williamsstatic inline bool is_a2(struct pci_dev *pdev)
389cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams{
390dc00c8b6940aa10ab1ce6a4d10b1bfe7b848781bDan Williams	if (pdev->revision < 4)
391dc00c8b6940aa10ab1ce6a4d10b1bfe7b848781bDan Williams		return true;
392dc00c8b6940aa10ab1ce6a4d10b1bfe7b848781bDan Williams	return false;
393cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams}
394cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
395dc00c8b6940aa10ab1ce6a4d10b1bfe7b848781bDan Williamsstatic inline bool is_b0(struct pci_dev *pdev)
396cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams{
397dc00c8b6940aa10ab1ce6a4d10b1bfe7b848781bDan Williams	if (pdev->revision == 4)
398dc00c8b6940aa10ab1ce6a4d10b1bfe7b848781bDan Williams		return true;
399dc00c8b6940aa10ab1ce6a4d10b1bfe7b848781bDan Williams	return false;
400dbb0743a58825d94f1b3fdfa90a8d61dfef88f7bAdam Gruchala}
401dbb0743a58825d94f1b3fdfa90a8d61dfef88f7bAdam Gruchala
402dc00c8b6940aa10ab1ce6a4d10b1bfe7b848781bDan Williamsstatic inline bool is_c0(struct pci_dev *pdev)
403dbb0743a58825d94f1b3fdfa90a8d61dfef88f7bAdam Gruchala{
404afd13a1f2b05157c7621d87dfe89ea6ea9061bd8Jeff Skirvin	if (pdev->revision == 5)
405afd13a1f2b05157c7621d87dfe89ea6ea9061bd8Jeff Skirvin		return true;
406afd13a1f2b05157c7621d87dfe89ea6ea9061bd8Jeff Skirvin	return false;
407afd13a1f2b05157c7621d87dfe89ea6ea9061bd8Jeff Skirvin}
408afd13a1f2b05157c7621d87dfe89ea6ea9061bd8Jeff Skirvin
409afd13a1f2b05157c7621d87dfe89ea6ea9061bd8Jeff Skirvinstatic inline bool is_c1(struct pci_dev *pdev)
410afd13a1f2b05157c7621d87dfe89ea6ea9061bd8Jeff Skirvin{
411afd13a1f2b05157c7621d87dfe89ea6ea9061bd8Jeff Skirvin	if (pdev->revision >= 6)
412dc00c8b6940aa10ab1ce6a4d10b1bfe7b848781bDan Williams		return true;
413dc00c8b6940aa10ab1ce6a4d10b1bfe7b848781bDan Williams	return false;
414cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams}
415cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
4169fee607f0b29adabd72265a847b8e421dff10d66Jeff Skirvinenum cable_selections {
4179fee607f0b29adabd72265a847b8e421dff10d66Jeff Skirvin	short_cable     = 0,
4189fee607f0b29adabd72265a847b8e421dff10d66Jeff Skirvin	long_cable      = 1,
4199fee607f0b29adabd72265a847b8e421dff10d66Jeff Skirvin	medium_cable    = 2,
4209fee607f0b29adabd72265a847b8e421dff10d66Jeff Skirvin	undefined_cable = 3
4219fee607f0b29adabd72265a847b8e421dff10d66Jeff Skirvin};
4229fee607f0b29adabd72265a847b8e421dff10d66Jeff Skirvin
4239fee607f0b29adabd72265a847b8e421dff10d66Jeff Skirvin#define CABLE_OVERRIDE_DISABLED (0x10000)
4249fee607f0b29adabd72265a847b8e421dff10d66Jeff Skirvin
4259fee607f0b29adabd72265a847b8e421dff10d66Jeff Skirvinstatic inline int is_cable_select_overridden(void)
4269fee607f0b29adabd72265a847b8e421dff10d66Jeff Skirvin{
4279fee607f0b29adabd72265a847b8e421dff10d66Jeff Skirvin	return cable_selection_override < CABLE_OVERRIDE_DISABLED;
4289fee607f0b29adabd72265a847b8e421dff10d66Jeff Skirvin}
4299fee607f0b29adabd72265a847b8e421dff10d66Jeff Skirvin
4309fee607f0b29adabd72265a847b8e421dff10d66Jeff Skirvinenum cable_selections decode_cable_selection(struct isci_host *ihost, int phy);
4319fee607f0b29adabd72265a847b8e421dff10d66Jeff Skirvinvoid validate_cable_selections(struct isci_host *ihost);
4329fee607f0b29adabd72265a847b8e421dff10d66Jeff Skirvinchar *lookup_cable_names(enum cable_selections);
4339fee607f0b29adabd72265a847b8e421dff10d66Jeff Skirvin
434ad4f4c1de80abdda5d55315289505598aa78e355Dan Williams/* set hw control for 'activity', even though active enclosures seem to drive
435ad4f4c1de80abdda5d55315289505598aa78e355Dan Williams * the activity led on their own.  Skip setting FSENG control on 'status' due
436ad4f4c1de80abdda5d55315289505598aa78e355Dan Williams * to unexpected operation and 'error' due to not being a supported automatic
437ad4f4c1de80abdda5d55315289505598aa78e355Dan Williams * FSENG output
438ad4f4c1de80abdda5d55315289505598aa78e355Dan Williams */
439ad4f4c1de80abdda5d55315289505598aa78e355Dan Williams#define SGPIO_HW_CONTROL 0x00000443
440ad4f4c1de80abdda5d55315289505598aa78e355Dan Williams
441ad4f4c1de80abdda5d55315289505598aa78e355Dan Williamsstatic inline int isci_gpio_count(struct isci_host *ihost)
442ad4f4c1de80abdda5d55315289505598aa78e355Dan Williams{
443ad4f4c1de80abdda5d55315289505598aa78e355Dan Williams	return ARRAY_SIZE(ihost->scu_registers->peg0.sgpio.output_data_select);
444ad4f4c1de80abdda5d55315289505598aa78e355Dan Williams}
445ad4f4c1de80abdda5d55315289505598aa78e355Dan Williams
44689a7301f21fb00e753089671eb9e4132aab8ea08Dan Williamsvoid sci_controller_post_request(struct isci_host *ihost,
447cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams				      u32 request);
44889a7301f21fb00e753089671eb9e4132aab8ea08Dan Williamsvoid sci_controller_release_frame(struct isci_host *ihost,
449cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams				       u32 frame_index);
45089a7301f21fb00e753089671eb9e4132aab8ea08Dan Williamsvoid sci_controller_copy_sata_response(void *response_buffer,
451cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams					    void *frame_header,
452cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams					    void *frame_buffer);
45389a7301f21fb00e753089671eb9e4132aab8ea08Dan Williamsenum sci_status sci_controller_allocate_remote_node_context(struct isci_host *ihost,
45478a6f06e0e82125787d7aa308fe28c2c8381540cDan Williams								 struct isci_remote_device *idev,
455cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams								 u16 *node_id);
45689a7301f21fb00e753089671eb9e4132aab8ea08Dan Williamsvoid sci_controller_free_remote_node_context(
457d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams	struct isci_host *ihost,
45878a6f06e0e82125787d7aa308fe28c2c8381540cDan Williams	struct isci_remote_device *idev,
459cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams	u16 node_id);
460cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
461abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williamsstruct isci_request *sci_request_by_tag(struct isci_host *ihost, u16 io_tag);
462abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williamsvoid sci_controller_power_control_queue_insert(struct isci_host *ihost,
463abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williams					       struct isci_phy *iphy);
464abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williamsvoid sci_controller_power_control_queue_remove(struct isci_host *ihost,
465abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williams					       struct isci_phy *iphy);
466abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williamsvoid sci_controller_link_up(struct isci_host *ihost, struct isci_port *iport,
467abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williams			    struct isci_phy *iphy);
468abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williamsvoid sci_controller_link_down(struct isci_host *ihost, struct isci_port *iport,
469abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williams			      struct isci_phy *iphy);
470abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williamsvoid sci_controller_remote_device_stopped(struct isci_host *ihost,
471abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williams					  struct isci_remote_device *idev);
472cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
47389a7301f21fb00e753089671eb9e4132aab8ea08Dan Williamsenum sci_status sci_controller_continue_io(struct isci_request *ireq);
474cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williamsint isci_host_scan_finished(struct Scsi_Host *, unsigned long);
475e468dc112f38220ee78bc0de64190eca9812749bArtur Wojcikvoid isci_host_start(struct Scsi_Host *);
476312e0c2455c18716cf640d4336dcb1e9e5053818Dan Williamsu16 isci_alloc_tag(struct isci_host *ihost);
477312e0c2455c18716cf640d4336dcb1e9e5053818Dan Williamsenum sci_status isci_free_tag(struct isci_host *ihost, u16 io_tag);
478312e0c2455c18716cf640d4336dcb1e9e5053818Dan Williamsvoid isci_tci_free(struct isci_host *ihost, u16 tci);
479f8381807ebdfffa34c2c5aa38eda33673d1a7adfJeff Skirvinvoid ireq_done(struct isci_host *ihost, struct isci_request *ireq, struct sas_task *task);
4806f231dda68080759f1aed3769896e94c73099f0fDan Williams
4816f231dda68080759f1aed3769896e94c73099f0fDan Williamsint isci_host_init(struct isci_host *);
482abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williamsvoid isci_host_completion_routine(unsigned long data);
483abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williamsvoid isci_host_deinit(struct isci_host *);
484abec912d71c44bbd642ce12ad98aab76f5a53163Dan Williamsvoid sci_controller_disable_interrupts(struct isci_host *ihost);
485eb608c3cb3f0a6b99252ea6a69fc0d2bbecf1f4fDan Williamsbool sci_controller_has_remote_devices_stopping(struct isci_host *ihost);
48650a92d93148ec073efd2456b007e04ecae452086Dan Williamsvoid sci_controller_transition_to_ready(struct isci_host *ihost, enum sci_status status);
487cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
48889a7301f21fb00e753089671eb9e4132aab8ea08Dan Williamsenum sci_status sci_controller_start_io(
489d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams	struct isci_host *ihost,
49078a6f06e0e82125787d7aa308fe28c2c8381540cDan Williams	struct isci_remote_device *idev,
4915076a1a97e2fa61c847a5fdd4b1991faf7716da6Dan Williams	struct isci_request *ireq);
492cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
49389a7301f21fb00e753089671eb9e4132aab8ea08Dan Williamsenum sci_task_status sci_controller_start_task(
494d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams	struct isci_host *ihost,
49578a6f06e0e82125787d7aa308fe28c2c8381540cDan Williams	struct isci_remote_device *idev,
4965076a1a97e2fa61c847a5fdd4b1991faf7716da6Dan Williams	struct isci_request *ireq);
497cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
49889a7301f21fb00e753089671eb9e4132aab8ea08Dan Williamsenum sci_status sci_controller_terminate_request(
499d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams	struct isci_host *ihost,
50078a6f06e0e82125787d7aa308fe28c2c8381540cDan Williams	struct isci_remote_device *idev,
5015076a1a97e2fa61c847a5fdd4b1991faf7716da6Dan Williams	struct isci_request *ireq);
502cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
50389a7301f21fb00e753089671eb9e4132aab8ea08Dan Williamsenum sci_status sci_controller_complete_io(
504d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams	struct isci_host *ihost,
50578a6f06e0e82125787d7aa308fe28c2c8381540cDan Williams	struct isci_remote_device *idev,
5065076a1a97e2fa61c847a5fdd4b1991faf7716da6Dan Williams	struct isci_request *ireq);
507cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams
50889a7301f21fb00e753089671eb9e4132aab8ea08Dan Williamsvoid sci_port_configuration_agent_construct(
50989a7301f21fb00e753089671eb9e4132aab8ea08Dan Williams	struct sci_port_configuration_agent *port_agent);
510e2f8db509fdd354bb7a68c86515e9d2d8909ccc9Dan Williams
51189a7301f21fb00e753089671eb9e4132aab8ea08Dan Williamsenum sci_status sci_port_configuration_agent_initialize(
512d9dcb4ba791de2a06b19ac47cd61601cf3d4e208Dan Williams	struct isci_host *ihost,
51389a7301f21fb00e753089671eb9e4132aab8ea08Dan Williams	struct sci_port_configuration_agent *port_agent);
514ad4f4c1de80abdda5d55315289505598aa78e355Dan Williams
515ad4f4c1de80abdda5d55315289505598aa78e355Dan Williamsint isci_gpio_write(struct sas_ha_struct *, u8 reg_type, u8 reg_index,
516ad4f4c1de80abdda5d55315289505598aa78e355Dan Williams		    u8 reg_count, u8 *write_data);
517cc9203bf381a465cd115762b9cf7c9a313c874bcDan Williams#endif
518