blob: 861e8f72811bd463130933aee28caaec7e5f318d [file] [log] [blame]
Dan Williams6f231dd2011-07-02 22:56:22 -07001/*
2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
4 *
5 * GPL LICENSE SUMMARY
6 *
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * BSD LICENSE
25 *
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 *
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
38 * distribution.
39 * * Neither the name of Intel Corporation nor the names of its
40 * contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 */
55
Dan Williamse5313812011-05-07 10:11:43 -070056#ifndef _ISCI_PORT_H_
Dan Williams6f231dd2011-07-02 22:56:22 -070057#define _ISCI_PORT_H_
Dan Williamsce2b3262011-05-08 15:49:15 -070058
59#include <scsi/libsas.h>
60#include "isci.h"
Dan Williamse2f8db502011-05-10 02:28:46 -070061#include "sas.h"
62#include "phy.h"
63
64#define SCIC_SDS_DUMMY_PORT 0xFF
Dan Williams6f231dd2011-07-02 22:56:22 -070065
Marcin Tomczak05b080f2012-01-04 01:33:41 -080066#define PF_NOTIFY (1 << 0)
67#define PF_RESUME (1 << 1)
68
Dan Williams6f231dd2011-07-02 22:56:22 -070069struct isci_phy;
70struct isci_host;
Dan Williams6f231dd2011-07-02 22:56:22 -070071
72enum isci_status {
73 isci_freed = 0x00,
74 isci_starting = 0x01,
75 isci_ready = 0x02,
76 isci_ready_for_io = 0x03,
77 isci_stopping = 0x04,
78 isci_stopped = 0x05,
Dan Williams6f231dd2011-07-02 22:56:22 -070079};
80
81/**
Dan Williamsffe191c2011-06-29 13:09:25 -070082 * struct isci_port - isci direct attached sas port object
Dan Williamsffe191c2011-06-29 13:09:25 -070083 * @ready_exit: several states constitute 'ready'. When exiting ready we
84 * need to take extra port-teardown actions that are
85 * skipped when exiting to another 'ready' state.
86 * @logical_port_index: software port index
87 * @physical_port_index: hardware port index
88 * @active_phy_mask: identifies phy members
Marcin Tomczak05b080f2012-01-04 01:33:41 -080089 * @enabled_phy_mask: phy mask for the port
90 * that are already part of the port
Dan Williamsffe191c2011-06-29 13:09:25 -070091 * @reserved_tag:
92 * @reserved_rni: reserver for port task scheduler workaround
93 * @started_request_count: reference count for outstanding commands
94 * @not_ready_reason: set during state transitions and notified
95 * @timer: timeout start/stop operations
Dan Williams6f231dd2011-07-02 22:56:22 -070096 */
97struct isci_port {
Dan Williams6f231dd2011-07-02 22:56:22 -070098 struct isci_host *isci_host;
Dan Williams6f231dd2011-07-02 22:56:22 -070099 struct list_head remote_dev_list;
Dan Williams92776992011-11-30 11:57:34 -0800100 #define IPORT_RESET_PENDING 0
101 unsigned long state;
Dan Williams6f231dd2011-07-02 22:56:22 -0700102 enum sci_status hard_reset_status;
Dan Williamsffe191c2011-06-29 13:09:25 -0700103 struct sci_base_state_machine sm;
104 bool ready_exit;
105 u8 logical_port_index;
106 u8 physical_port_index;
107 u8 active_phy_mask;
Marcin Tomczak05b080f2012-01-04 01:33:41 -0800108 u8 enabled_phy_mask;
Jeff Skirvin8e35a132011-10-27 15:05:32 -0700109 u8 last_active_phy;
Dan Williamsffe191c2011-06-29 13:09:25 -0700110 u16 reserved_rni;
111 u16 reserved_tag;
112 u32 started_request_count;
113 u32 assigned_device_count;
Jeff Skirvin6f488442012-03-08 22:41:48 -0800114 u32 hang_detect_users;
Dan Williamsffe191c2011-06-29 13:09:25 -0700115 u32 not_ready_reason;
116 struct isci_phy *phy_table[SCI_MAX_PHYS];
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700117 struct isci_host *owning_controller;
Dan Williamsffe191c2011-06-29 13:09:25 -0700118 struct sci_timer timer;
119 struct scu_port_task_scheduler_registers __iomem *port_task_scheduler_registers;
120 /* XXX rework: only one register, no need to replicate per-port */
121 u32 __iomem *port_pe_configuration_register;
122 struct scu_viit_entry __iomem *viit_registers;
Dan Williams6f231dd2011-07-02 22:56:22 -0700123};
124
Dan Williams89a73012011-06-30 19:14:33 -0700125enum sci_port_not_ready_reason_code {
Dan Williamse2f8db502011-05-10 02:28:46 -0700126 SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS,
127 SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED,
128 SCIC_PORT_NOT_READY_INVALID_PORT_CONFIGURATION,
129 SCIC_PORT_NOT_READY_RECONFIGURING,
130
131 SCIC_PORT_NOT_READY_REASON_CODE_MAX
132};
133
Dan Williams89a73012011-06-30 19:14:33 -0700134struct sci_port_end_point_properties {
Dan Williamse2f8db502011-05-10 02:28:46 -0700135 struct sci_sas_address sas_address;
Dan Williams89a73012011-06-30 19:14:33 -0700136 struct sci_phy_proto protocols;
Dan Williamse2f8db502011-05-10 02:28:46 -0700137};
138
Dan Williams89a73012011-06-30 19:14:33 -0700139struct sci_port_properties {
Dan Williamse2f8db502011-05-10 02:28:46 -0700140 u32 index;
Dan Williams89a73012011-06-30 19:14:33 -0700141 struct sci_port_end_point_properties local;
142 struct sci_port_end_point_properties remote;
Dan Williamse2f8db502011-05-10 02:28:46 -0700143 u32 phy_mask;
144};
145
146/**
Dan Williamsd7a0ccd2012-02-10 01:18:44 -0800147 * enum sci_port_states - port state machine states
148 * @SCI_PORT_STOPPED: port has successfully been stopped. In this state
149 * no new IO operations are permitted. This state is
150 * entered from the STOPPING state.
151 * @SCI_PORT_STOPPING: port is in the process of stopping. In this
152 * state no new IO operations are permitted, but
153 * existing IO operations are allowed to complete.
154 * This state is entered from the READY state.
155 * @SCI_PORT_READY: port is now ready. Thus, the user is able to
156 * perform IO operations on this port. This state is
157 * entered from the STARTING state.
158 * @SCI_PORT_SUB_WAITING: port is started and ready but has no active
159 * phys.
160 * @SCI_PORT_SUB_OPERATIONAL: port is started and ready and there is at
161 * least one phy operational.
162 * @SCI_PORT_SUB_CONFIGURING: port is started and there was an
163 * add/remove phy event. This state is only
164 * used in Automatic Port Configuration Mode
165 * (APC)
166 * @SCI_PORT_RESETTING: port is in the process of performing a hard
167 * reset. Thus, the user is unable to perform IO
168 * operations on this port. This state is entered
169 * from the READY state.
170 * @SCI_PORT_FAILED: port has failed a reset request. This state is
171 * entered when a port reset request times out. This
172 * state is entered from the RESETTING state.
Dan Williamse2f8db502011-05-10 02:28:46 -0700173 */
Dan Williamsd7a0ccd2012-02-10 01:18:44 -0800174#define PORT_STATES {\
175 C(PORT_STOPPED),\
176 C(PORT_STOPPING),\
177 C(PORT_READY),\
178 C(PORT_SUB_WAITING),\
179 C(PORT_SUB_OPERATIONAL),\
180 C(PORT_SUB_CONFIGURING),\
181 C(PORT_RESETTING),\
182 C(PORT_FAILED),\
183 }
184#undef C
185#define C(a) SCI_##a
186enum sci_port_states PORT_STATES;
187#undef C
Dan Williamse2f8db502011-05-10 02:28:46 -0700188
Dan Williams89a73012011-06-30 19:14:33 -0700189static inline void sci_port_decrement_request_count(struct isci_port *iport)
Dan Williamse2f8db502011-05-10 02:28:46 -0700190{
Dan Williamsffe191c2011-06-29 13:09:25 -0700191 if (WARN_ONCE(iport->started_request_count == 0,
Dan Williamse2f8db502011-05-10 02:28:46 -0700192 "%s: tried to decrement started_request_count past 0!?",
193 __func__))
194 /* pass */;
195 else
Dan Williamsffe191c2011-06-29 13:09:25 -0700196 iport->started_request_count--;
Dan Williamse2f8db502011-05-10 02:28:46 -0700197}
198
Dan Williams89a73012011-06-30 19:14:33 -0700199#define sci_port_active_phy(port, phy) \
Dan Williamse2f8db502011-05-10 02:28:46 -0700200 (((port)->active_phy_mask & (1 << (phy)->phy_index)) != 0)
201
Dan Williams89a73012011-06-30 19:14:33 -0700202void sci_port_construct(
Dan Williamsffe191c2011-06-29 13:09:25 -0700203 struct isci_port *iport,
Dan Williamse2f8db502011-05-10 02:28:46 -0700204 u8 port_index,
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700205 struct isci_host *ihost);
Dan Williamse2f8db502011-05-10 02:28:46 -0700206
Dan Williams89a73012011-06-30 19:14:33 -0700207enum sci_status sci_port_start(struct isci_port *iport);
208enum sci_status sci_port_stop(struct isci_port *iport);
Dan Williamse2f8db502011-05-10 02:28:46 -0700209
Dan Williams89a73012011-06-30 19:14:33 -0700210enum sci_status sci_port_add_phy(
Dan Williamsffe191c2011-06-29 13:09:25 -0700211 struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700212 struct isci_phy *iphy);
Dan Williamse2f8db502011-05-10 02:28:46 -0700213
Dan Williams89a73012011-06-30 19:14:33 -0700214enum sci_status sci_port_remove_phy(
Dan Williamsffe191c2011-06-29 13:09:25 -0700215 struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700216 struct isci_phy *iphy);
Dan Williamse2f8db502011-05-10 02:28:46 -0700217
Dan Williams89a73012011-06-30 19:14:33 -0700218void sci_port_setup_transports(
Dan Williamsffe191c2011-06-29 13:09:25 -0700219 struct isci_port *iport,
Dan Williamse2f8db502011-05-10 02:28:46 -0700220 u32 device_id);
221
Jeff Skirvin61aaff42011-06-21 12:16:33 -0700222void isci_port_bcn_enable(struct isci_host *, struct isci_port *);
Dan Williamse2f8db502011-05-10 02:28:46 -0700223
Dan Williams89a73012011-06-30 19:14:33 -0700224void sci_port_deactivate_phy(
Dan Williamsffe191c2011-06-29 13:09:25 -0700225 struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700226 struct isci_phy *iphy,
Dan Williamse2f8db502011-05-10 02:28:46 -0700227 bool do_notify_user);
228
Dan Williams89a73012011-06-30 19:14:33 -0700229bool sci_port_link_detected(
Dan Williamsffe191c2011-06-29 13:09:25 -0700230 struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700231 struct isci_phy *iphy);
Dan Williamse2f8db502011-05-10 02:28:46 -0700232
Bartek Nowakowski7e629842012-01-04 01:33:20 -0800233enum sci_status sci_port_get_properties(
234 struct isci_port *iport,
235 struct sci_port_properties *prop);
236
Dan Williams89a73012011-06-30 19:14:33 -0700237enum sci_status sci_port_link_up(struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700238 struct isci_phy *iphy);
Dan Williams89a73012011-06-30 19:14:33 -0700239enum sci_status sci_port_link_down(struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700240 struct isci_phy *iphy);
Dan Williamse2f8db502011-05-10 02:28:46 -0700241
Dan Williams5076a1a2011-06-27 14:57:03 -0700242struct isci_request;
Dan Williams78a6f062011-06-30 16:31:37 -0700243struct isci_remote_device;
Dan Williams89a73012011-06-30 19:14:33 -0700244enum sci_status sci_port_start_io(
Dan Williamsffe191c2011-06-29 13:09:25 -0700245 struct isci_port *iport,
Dan Williams78a6f062011-06-30 16:31:37 -0700246 struct isci_remote_device *idev,
Dan Williams5076a1a2011-06-27 14:57:03 -0700247 struct isci_request *ireq);
Dan Williamse2f8db502011-05-10 02:28:46 -0700248
Dan Williams89a73012011-06-30 19:14:33 -0700249enum sci_status sci_port_complete_io(
Dan Williamsffe191c2011-06-29 13:09:25 -0700250 struct isci_port *iport,
Dan Williams78a6f062011-06-30 16:31:37 -0700251 struct isci_remote_device *idev,
Dan Williams5076a1a2011-06-27 14:57:03 -0700252 struct isci_request *ireq);
Dan Williamse2f8db502011-05-10 02:28:46 -0700253
Dan Williams89a73012011-06-30 19:14:33 -0700254enum sas_linkrate sci_port_get_max_allowed_speed(
Dan Williamsffe191c2011-06-29 13:09:25 -0700255 struct isci_port *iport);
Dan Williamse2f8db502011-05-10 02:28:46 -0700256
Dan Williams89a73012011-06-30 19:14:33 -0700257void sci_port_broadcast_change_received(
Dan Williamsffe191c2011-06-29 13:09:25 -0700258 struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700259 struct isci_phy *iphy);
Dan Williamse2f8db502011-05-10 02:28:46 -0700260
Dan Williams89a73012011-06-30 19:14:33 -0700261bool sci_port_is_valid_phy_assignment(
Dan Williamsffe191c2011-06-29 13:09:25 -0700262 struct isci_port *iport,
Dan Williamse2f8db502011-05-10 02:28:46 -0700263 u32 phy_index);
264
Dan Williams89a73012011-06-30 19:14:33 -0700265void sci_port_get_sas_address(
Dan Williamsffe191c2011-06-29 13:09:25 -0700266 struct isci_port *iport,
Dan Williamse2f8db502011-05-10 02:28:46 -0700267 struct sci_sas_address *sas_address);
268
Dan Williams89a73012011-06-30 19:14:33 -0700269void sci_port_get_attached_sas_address(
Dan Williamsffe191c2011-06-29 13:09:25 -0700270 struct isci_port *iport,
Dan Williamse2f8db502011-05-10 02:28:46 -0700271 struct sci_sas_address *sas_address);
272
Jeff Skirvin6f488442012-03-08 22:41:48 -0800273void sci_port_set_hang_detection_timeout(
274 struct isci_port *isci_port,
275 u32 timeout);
276
Dan Williamse2f8db502011-05-10 02:28:46 -0700277void isci_port_formed(struct asd_sas_phy *);
278void isci_port_deformed(struct asd_sas_phy *);
Dan Williams6f231dd2011-07-02 22:56:22 -0700279
Dan Williams4393aa42011-03-31 13:10:44 -0700280int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
281 struct isci_phy *iphy);
Dan Williams687833a2011-11-17 18:01:38 -0800282int isci_ata_check_ready(struct domain_device *dev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700283#endif /* !defined(_ISCI_PORT_H_) */