blob: b9bc89bf6519d376eb1c80dc508f548e2461a10d [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 Williamse2f8db52011-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
66struct isci_phy;
67struct isci_host;
Dan Williams6f231dd2011-07-02 22:56:22 -070068
69enum isci_status {
70 isci_freed = 0x00,
71 isci_starting = 0x01,
72 isci_ready = 0x02,
73 isci_ready_for_io = 0x03,
74 isci_stopping = 0x04,
75 isci_stopped = 0x05,
Dan Williams6f231dd2011-07-02 22:56:22 -070076};
77
78/**
Dan Williamsffe191c2011-06-29 13:09:25 -070079 * struct isci_port - isci direct attached sas port object
80 * @event: counts bcns and port stop events (for bcn filtering)
81 * @ready_exit: several states constitute 'ready'. When exiting ready we
82 * need to take extra port-teardown actions that are
83 * skipped when exiting to another 'ready' state.
84 * @logical_port_index: software port index
85 * @physical_port_index: hardware port index
86 * @active_phy_mask: identifies phy members
87 * @reserved_tag:
88 * @reserved_rni: reserver for port task scheduler workaround
89 * @started_request_count: reference count for outstanding commands
90 * @not_ready_reason: set during state transitions and notified
91 * @timer: timeout start/stop operations
Dan Williams6f231dd2011-07-02 22:56:22 -070092 */
93struct isci_port {
Dan Williams6f231dd2011-07-02 22:56:22 -070094 enum isci_status status;
Jeff Skirvin61aaff42011-06-21 12:16:33 -070095 #define IPORT_BCN_BLOCKED 0
96 #define IPORT_BCN_PENDING 1
97 unsigned long flags;
98 atomic_t event;
Dan Williams6f231dd2011-07-02 22:56:22 -070099 struct isci_host *isci_host;
100 struct asd_sas_port sas_port;
101 struct list_head remote_dev_list;
Dan Williams6f231dd2011-07-02 22:56:22 -0700102 spinlock_t state_lock;
103 struct list_head domain_dev_list;
104 struct completion start_complete;
105 struct completion hard_reset_complete;
106 enum sci_status hard_reset_status;
Dan Williamsffe191c2011-06-29 13:09:25 -0700107 struct sci_base_state_machine sm;
108 bool ready_exit;
109 u8 logical_port_index;
110 u8 physical_port_index;
111 u8 active_phy_mask;
112 u16 reserved_rni;
113 u16 reserved_tag;
114 u32 started_request_count;
115 u32 assigned_device_count;
116 u32 not_ready_reason;
117 struct isci_phy *phy_table[SCI_MAX_PHYS];
118 struct scic_sds_controller *owning_controller;
119 struct sci_timer timer;
120 struct scu_port_task_scheduler_registers __iomem *port_task_scheduler_registers;
121 /* XXX rework: only one register, no need to replicate per-port */
122 u32 __iomem *port_pe_configuration_register;
123 struct scu_viit_entry __iomem *viit_registers;
Dan Williams6f231dd2011-07-02 22:56:22 -0700124};
125
Dan Williamse2f8db52011-05-10 02:28:46 -0700126enum scic_port_not_ready_reason_code {
127 SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS,
128 SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED,
129 SCIC_PORT_NOT_READY_INVALID_PORT_CONFIGURATION,
130 SCIC_PORT_NOT_READY_RECONFIGURING,
131
132 SCIC_PORT_NOT_READY_REASON_CODE_MAX
133};
134
135struct scic_port_end_point_properties {
136 struct sci_sas_address sas_address;
137 struct scic_phy_proto protocols;
138};
139
140struct scic_port_properties {
141 u32 index;
142 struct scic_port_end_point_properties local;
143 struct scic_port_end_point_properties remote;
144 u32 phy_mask;
145};
146
147/**
Dan Williamse2f8db52011-05-10 02:28:46 -0700148 * enum scic_sds_port_states - This enumeration depicts all the states for the
149 * common port state machine.
150 *
151 *
152 */
153enum scic_sds_port_states {
154 /**
155 * This state indicates that the port has successfully been stopped.
156 * In this state no new IO operations are permitted.
157 * This state is entered from the STOPPING state.
158 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000159 SCI_PORT_STOPPED,
Dan Williamse2f8db52011-05-10 02:28:46 -0700160
161 /**
162 * This state indicates that the port is in the process of stopping.
163 * In this state no new IO operations are permitted, but existing IO
164 * operations are allowed to complete.
165 * This state is entered from the READY state.
166 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000167 SCI_PORT_STOPPING,
Dan Williamse2f8db52011-05-10 02:28:46 -0700168
169 /**
170 * This state indicates the port is now ready. Thus, the user is
171 * able to perform IO operations on this port.
172 * This state is entered from the STARTING state.
173 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000174 SCI_PORT_READY,
Dan Williamse2f8db52011-05-10 02:28:46 -0700175
176 /**
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000177 * The substate where the port is started and ready but has no
178 * active phys.
179 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000180 SCI_PORT_SUB_WAITING,
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000181
182 /**
183 * The substate where the port is started and ready and there is
184 * at least one phy operational.
185 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000186 SCI_PORT_SUB_OPERATIONAL,
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000187
188 /**
189 * The substate where the port is started and there was an
190 * add/remove phy event. This state is only used in Automatic
191 * Port Configuration Mode (APC)
192 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000193 SCI_PORT_SUB_CONFIGURING,
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000194
195 /**
Dan Williamse2f8db52011-05-10 02:28:46 -0700196 * This state indicates the port is in the process of performing a hard
197 * reset. Thus, the user is unable to perform IO operations on this
198 * port.
199 * This state is entered from the READY state.
200 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000201 SCI_PORT_RESETTING,
Dan Williamse2f8db52011-05-10 02:28:46 -0700202
203 /**
204 * This state indicates the port has failed a reset request. This state
205 * is entered when a port reset request times out.
206 * This state is entered from the RESETTING state.
207 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000208 SCI_PORT_FAILED,
Dan Williamse2f8db52011-05-10 02:28:46 -0700209
Dan Williamse2f8db52011-05-10 02:28:46 -0700210
211};
212
Dan Williamse2f8db52011-05-10 02:28:46 -0700213/**
214 * scic_sds_port_get_controller() -
215 *
216 * Helper macro to get the owning controller of this port
217 */
218#define scic_sds_port_get_controller(this_port) \
219 ((this_port)->owning_controller)
220
221/**
Dan Williamse2f8db52011-05-10 02:28:46 -0700222 * scic_sds_port_get_index() -
223 *
224 * This macro returns the physical port index for this port object
225 */
226#define scic_sds_port_get_index(this_port) \
227 ((this_port)->physical_port_index)
228
229
Dan Williamsffe191c2011-06-29 13:09:25 -0700230static inline void scic_sds_port_decrement_request_count(struct isci_port *iport)
Dan Williamse2f8db52011-05-10 02:28:46 -0700231{
Dan Williamsffe191c2011-06-29 13:09:25 -0700232 if (WARN_ONCE(iport->started_request_count == 0,
Dan Williamse2f8db52011-05-10 02:28:46 -0700233 "%s: tried to decrement started_request_count past 0!?",
234 __func__))
235 /* pass */;
236 else
Dan Williamsffe191c2011-06-29 13:09:25 -0700237 iport->started_request_count--;
Dan Williamse2f8db52011-05-10 02:28:46 -0700238}
239
240#define scic_sds_port_active_phy(port, phy) \
241 (((port)->active_phy_mask & (1 << (phy)->phy_index)) != 0)
242
243void scic_sds_port_construct(
Dan Williamsffe191c2011-06-29 13:09:25 -0700244 struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700245 u8 port_index,
246 struct scic_sds_controller *scic);
247
248enum sci_status scic_sds_port_initialize(
Dan Williamsffe191c2011-06-29 13:09:25 -0700249 struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700250 void __iomem *port_task_scheduler_registers,
251 void __iomem *port_configuration_regsiter,
252 void __iomem *viit_registers);
253
Dan Williamsffe191c2011-06-29 13:09:25 -0700254enum sci_status scic_sds_port_start(struct isci_port *iport);
255enum sci_status scic_sds_port_stop(struct isci_port *iport);
Piotr Sawickid76f71d2011-05-11 23:52:26 +0000256
Dan Williamse2f8db52011-05-10 02:28:46 -0700257enum sci_status scic_sds_port_add_phy(
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 Williamse2f8db52011-05-10 02:28:46 -0700260
261enum sci_status scic_sds_port_remove_phy(
Dan Williamsffe191c2011-06-29 13:09:25 -0700262 struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700263 struct isci_phy *iphy);
Dan Williamse2f8db52011-05-10 02:28:46 -0700264
265void scic_sds_port_setup_transports(
Dan Williamsffe191c2011-06-29 13:09:25 -0700266 struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700267 u32 device_id);
268
Jeff Skirvin61aaff42011-06-21 12:16:33 -0700269void isci_port_bcn_enable(struct isci_host *, struct isci_port *);
Dan Williamse2f8db52011-05-10 02:28:46 -0700270
271void scic_sds_port_deactivate_phy(
Dan Williamsffe191c2011-06-29 13:09:25 -0700272 struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700273 struct isci_phy *iphy,
Dan Williamse2f8db52011-05-10 02:28:46 -0700274 bool do_notify_user);
275
276bool scic_sds_port_link_detected(
Dan Williamsffe191c2011-06-29 13:09:25 -0700277 struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700278 struct isci_phy *iphy);
Dan Williamse2f8db52011-05-10 02:28:46 -0700279
Dan Williamsffe191c2011-06-29 13:09:25 -0700280enum sci_status scic_sds_port_link_up(struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700281 struct isci_phy *iphy);
Dan Williamsffe191c2011-06-29 13:09:25 -0700282enum sci_status scic_sds_port_link_down(struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700283 struct isci_phy *iphy);
Dan Williamse2f8db52011-05-10 02:28:46 -0700284
Dan Williams5076a1a2011-06-27 14:57:03 -0700285struct isci_request;
Dan Williams78a6f062011-06-30 16:31:37 -0700286struct isci_remote_device;
Dan Williamse2f8db52011-05-10 02:28:46 -0700287enum sci_status scic_sds_port_start_io(
Dan Williamsffe191c2011-06-29 13:09:25 -0700288 struct isci_port *iport,
Dan Williams78a6f062011-06-30 16:31:37 -0700289 struct isci_remote_device *idev,
Dan Williams5076a1a2011-06-27 14:57:03 -0700290 struct isci_request *ireq);
Dan Williamse2f8db52011-05-10 02:28:46 -0700291
292enum sci_status scic_sds_port_complete_io(
Dan Williamsffe191c2011-06-29 13:09:25 -0700293 struct isci_port *iport,
Dan Williams78a6f062011-06-30 16:31:37 -0700294 struct isci_remote_device *idev,
Dan Williams5076a1a2011-06-27 14:57:03 -0700295 struct isci_request *ireq);
Dan Williamse2f8db52011-05-10 02:28:46 -0700296
297enum sas_linkrate scic_sds_port_get_max_allowed_speed(
Dan Williamsffe191c2011-06-29 13:09:25 -0700298 struct isci_port *iport);
Dan Williamse2f8db52011-05-10 02:28:46 -0700299
300void scic_sds_port_broadcast_change_received(
Dan Williamsffe191c2011-06-29 13:09:25 -0700301 struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700302 struct isci_phy *iphy);
Dan Williamse2f8db52011-05-10 02:28:46 -0700303
304bool scic_sds_port_is_valid_phy_assignment(
Dan Williamsffe191c2011-06-29 13:09:25 -0700305 struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700306 u32 phy_index);
307
308void scic_sds_port_get_sas_address(
Dan Williamsffe191c2011-06-29 13:09:25 -0700309 struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700310 struct sci_sas_address *sas_address);
311
312void scic_sds_port_get_attached_sas_address(
Dan Williamsffe191c2011-06-29 13:09:25 -0700313 struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700314 struct sci_sas_address *sas_address);
315
Dan Williams6f231dd2011-07-02 22:56:22 -0700316enum isci_status isci_port_get_state(
317 struct isci_port *isci_port);
318
Dan Williamse2f8db52011-05-10 02:28:46 -0700319void isci_port_formed(struct asd_sas_phy *);
320void isci_port_deformed(struct asd_sas_phy *);
Dan Williams6f231dd2011-07-02 22:56:22 -0700321
322void isci_port_init(
323 struct isci_port *port,
324 struct isci_host *host,
325 int index);
326
Dan Williams4393aa42011-03-31 13:10:44 -0700327int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
328 struct isci_phy *iphy);
Dan Williams6f231dd2011-07-02 22:56:22 -0700329#endif /* !defined(_ISCI_PORT_H_) */