blob: b3a7f12803f5c552fb8d6756f766f64d22b49dc5 [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
Dan Williamsffe191c2011-06-29 13:09:25 -070080 * @ready_exit: several states constitute 'ready'. When exiting ready we
81 * need to take extra port-teardown actions that are
82 * skipped when exiting to another 'ready' state.
83 * @logical_port_index: software port index
84 * @physical_port_index: hardware port index
85 * @active_phy_mask: identifies phy members
86 * @reserved_tag:
87 * @reserved_rni: reserver for port task scheduler workaround
88 * @started_request_count: reference count for outstanding commands
89 * @not_ready_reason: set during state transitions and notified
90 * @timer: timeout start/stop operations
Dan Williams6f231dd2011-07-02 22:56:22 -070091 */
92struct isci_port {
Dan Williams6f231dd2011-07-02 22:56:22 -070093 enum isci_status status;
94 struct isci_host *isci_host;
95 struct asd_sas_port sas_port;
96 struct list_head remote_dev_list;
Dan Williams6f231dd2011-07-02 22:56:22 -070097 spinlock_t state_lock;
98 struct list_head domain_dev_list;
99 struct completion start_complete;
100 struct completion hard_reset_complete;
101 enum sci_status hard_reset_status;
Dan Williamsffe191c2011-06-29 13:09:25 -0700102 struct sci_base_state_machine sm;
103 bool ready_exit;
104 u8 logical_port_index;
105 u8 physical_port_index;
106 u8 active_phy_mask;
Jeff Skirvin8e35a132011-10-27 15:05:32 -0700107 u8 last_active_phy;
Dan Williamsffe191c2011-06-29 13:09:25 -0700108 u16 reserved_rni;
109 u16 reserved_tag;
110 u32 started_request_count;
111 u32 assigned_device_count;
112 u32 not_ready_reason;
113 struct isci_phy *phy_table[SCI_MAX_PHYS];
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700114 struct isci_host *owning_controller;
Dan Williamsffe191c2011-06-29 13:09:25 -0700115 struct sci_timer timer;
116 struct scu_port_task_scheduler_registers __iomem *port_task_scheduler_registers;
117 /* XXX rework: only one register, no need to replicate per-port */
118 u32 __iomem *port_pe_configuration_register;
119 struct scu_viit_entry __iomem *viit_registers;
Dan Williams6f231dd2011-07-02 22:56:22 -0700120};
121
Dan Williams89a73012011-06-30 19:14:33 -0700122enum sci_port_not_ready_reason_code {
Dan Williamse2f8db52011-05-10 02:28:46 -0700123 SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS,
124 SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED,
125 SCIC_PORT_NOT_READY_INVALID_PORT_CONFIGURATION,
126 SCIC_PORT_NOT_READY_RECONFIGURING,
127
128 SCIC_PORT_NOT_READY_REASON_CODE_MAX
129};
130
Dan Williams89a73012011-06-30 19:14:33 -0700131struct sci_port_end_point_properties {
Dan Williamse2f8db52011-05-10 02:28:46 -0700132 struct sci_sas_address sas_address;
Dan Williams89a73012011-06-30 19:14:33 -0700133 struct sci_phy_proto protocols;
Dan Williamse2f8db52011-05-10 02:28:46 -0700134};
135
Dan Williams89a73012011-06-30 19:14:33 -0700136struct sci_port_properties {
Dan Williamse2f8db52011-05-10 02:28:46 -0700137 u32 index;
Dan Williams89a73012011-06-30 19:14:33 -0700138 struct sci_port_end_point_properties local;
139 struct sci_port_end_point_properties remote;
Dan Williamse2f8db52011-05-10 02:28:46 -0700140 u32 phy_mask;
141};
142
143/**
Dan Williams89a73012011-06-30 19:14:33 -0700144 * enum sci_port_states - This enumeration depicts all the states for the
Dan Williamse2f8db52011-05-10 02:28:46 -0700145 * common port state machine.
146 *
147 *
148 */
Dan Williams89a73012011-06-30 19:14:33 -0700149enum sci_port_states {
Dan Williamse2f8db52011-05-10 02:28:46 -0700150 /**
151 * This state indicates that the port has successfully been stopped.
152 * In this state no new IO operations are permitted.
153 * This state is entered from the STOPPING state.
154 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000155 SCI_PORT_STOPPED,
Dan Williamse2f8db52011-05-10 02:28:46 -0700156
157 /**
158 * This state indicates that the port is in the process of stopping.
159 * In this state no new IO operations are permitted, but existing IO
160 * operations are allowed to complete.
161 * This state is entered from the READY state.
162 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000163 SCI_PORT_STOPPING,
Dan Williamse2f8db52011-05-10 02:28:46 -0700164
165 /**
166 * This state indicates the port is now ready. Thus, the user is
167 * able to perform IO operations on this port.
168 * This state is entered from the STARTING state.
169 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000170 SCI_PORT_READY,
Dan Williamse2f8db52011-05-10 02:28:46 -0700171
172 /**
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000173 * The substate where the port is started and ready but has no
174 * active phys.
175 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000176 SCI_PORT_SUB_WAITING,
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000177
178 /**
179 * The substate where the port is started and ready and there is
180 * at least one phy operational.
181 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000182 SCI_PORT_SUB_OPERATIONAL,
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000183
184 /**
185 * The substate where the port is started and there was an
186 * add/remove phy event. This state is only used in Automatic
187 * Port Configuration Mode (APC)
188 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000189 SCI_PORT_SUB_CONFIGURING,
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000190
191 /**
Dan Williamse2f8db52011-05-10 02:28:46 -0700192 * This state indicates the port is in the process of performing a hard
193 * reset. Thus, the user is unable to perform IO operations on this
194 * port.
195 * This state is entered from the READY state.
196 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000197 SCI_PORT_RESETTING,
Dan Williamse2f8db52011-05-10 02:28:46 -0700198
199 /**
200 * This state indicates the port has failed a reset request. This state
201 * is entered when a port reset request times out.
202 * This state is entered from the RESETTING state.
203 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000204 SCI_PORT_FAILED,
Dan Williamse2f8db52011-05-10 02:28:46 -0700205
Dan Williamse2f8db52011-05-10 02:28:46 -0700206
207};
208
Dan Williams89a73012011-06-30 19:14:33 -0700209static inline void sci_port_decrement_request_count(struct isci_port *iport)
Dan Williamse2f8db52011-05-10 02:28:46 -0700210{
Dan Williamsffe191c2011-06-29 13:09:25 -0700211 if (WARN_ONCE(iport->started_request_count == 0,
Dan Williamse2f8db52011-05-10 02:28:46 -0700212 "%s: tried to decrement started_request_count past 0!?",
213 __func__))
214 /* pass */;
215 else
Dan Williamsffe191c2011-06-29 13:09:25 -0700216 iport->started_request_count--;
Dan Williamse2f8db52011-05-10 02:28:46 -0700217}
218
Dan Williams89a73012011-06-30 19:14:33 -0700219#define sci_port_active_phy(port, phy) \
Dan Williamse2f8db52011-05-10 02:28:46 -0700220 (((port)->active_phy_mask & (1 << (phy)->phy_index)) != 0)
221
Dan Williams89a73012011-06-30 19:14:33 -0700222void sci_port_construct(
Dan Williamsffe191c2011-06-29 13:09:25 -0700223 struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700224 u8 port_index,
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700225 struct isci_host *ihost);
Dan Williamse2f8db52011-05-10 02:28:46 -0700226
Dan Williams89a73012011-06-30 19:14:33 -0700227enum sci_status sci_port_start(struct isci_port *iport);
228enum sci_status sci_port_stop(struct isci_port *iport);
Dan Williamse2f8db52011-05-10 02:28:46 -0700229
Dan Williams89a73012011-06-30 19:14:33 -0700230enum sci_status sci_port_add_phy(
Dan Williamsffe191c2011-06-29 13:09:25 -0700231 struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700232 struct isci_phy *iphy);
Dan Williamse2f8db52011-05-10 02:28:46 -0700233
Dan Williams89a73012011-06-30 19:14:33 -0700234enum sci_status sci_port_remove_phy(
Dan Williamsffe191c2011-06-29 13:09:25 -0700235 struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700236 struct isci_phy *iphy);
Dan Williamse2f8db52011-05-10 02:28:46 -0700237
Dan Williams89a73012011-06-30 19:14:33 -0700238void sci_port_setup_transports(
Dan Williamsffe191c2011-06-29 13:09:25 -0700239 struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700240 u32 device_id);
241
Jeff Skirvin61aaff42011-06-21 12:16:33 -0700242void isci_port_bcn_enable(struct isci_host *, struct isci_port *);
Dan Williamse2f8db52011-05-10 02:28:46 -0700243
Dan Williams89a73012011-06-30 19:14:33 -0700244void sci_port_deactivate_phy(
Dan Williamsffe191c2011-06-29 13:09:25 -0700245 struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700246 struct isci_phy *iphy,
Dan Williamse2f8db52011-05-10 02:28:46 -0700247 bool do_notify_user);
248
Dan Williams89a73012011-06-30 19:14:33 -0700249bool sci_port_link_detected(
Dan Williamsffe191c2011-06-29 13:09:25 -0700250 struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700251 struct isci_phy *iphy);
Dan Williamse2f8db52011-05-10 02:28:46 -0700252
Bartek Nowakowski7e629842012-01-04 01:33:20 -0800253enum sci_status sci_port_get_properties(
254 struct isci_port *iport,
255 struct sci_port_properties *prop);
256
Dan Williams89a73012011-06-30 19:14:33 -0700257enum sci_status sci_port_link_up(struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700258 struct isci_phy *iphy);
Dan Williams89a73012011-06-30 19:14:33 -0700259enum sci_status sci_port_link_down(struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700260 struct isci_phy *iphy);
Dan Williamse2f8db52011-05-10 02:28:46 -0700261
Dan Williams5076a1a2011-06-27 14:57:03 -0700262struct isci_request;
Dan Williams78a6f062011-06-30 16:31:37 -0700263struct isci_remote_device;
Dan Williams89a73012011-06-30 19:14:33 -0700264enum sci_status sci_port_start_io(
Dan Williamsffe191c2011-06-29 13:09:25 -0700265 struct isci_port *iport,
Dan Williams78a6f062011-06-30 16:31:37 -0700266 struct isci_remote_device *idev,
Dan Williams5076a1a2011-06-27 14:57:03 -0700267 struct isci_request *ireq);
Dan Williamse2f8db52011-05-10 02:28:46 -0700268
Dan Williams89a73012011-06-30 19:14:33 -0700269enum sci_status sci_port_complete_io(
Dan Williamsffe191c2011-06-29 13:09:25 -0700270 struct isci_port *iport,
Dan Williams78a6f062011-06-30 16:31:37 -0700271 struct isci_remote_device *idev,
Dan Williams5076a1a2011-06-27 14:57:03 -0700272 struct isci_request *ireq);
Dan Williamse2f8db52011-05-10 02:28:46 -0700273
Dan Williams89a73012011-06-30 19:14:33 -0700274enum sas_linkrate sci_port_get_max_allowed_speed(
Dan Williamsffe191c2011-06-29 13:09:25 -0700275 struct isci_port *iport);
Dan Williamse2f8db52011-05-10 02:28:46 -0700276
Dan Williams89a73012011-06-30 19:14:33 -0700277void sci_port_broadcast_change_received(
Dan Williamsffe191c2011-06-29 13:09:25 -0700278 struct isci_port *iport,
Dan Williams85280952011-06-28 15:05:53 -0700279 struct isci_phy *iphy);
Dan Williamse2f8db52011-05-10 02:28:46 -0700280
Dan Williams89a73012011-06-30 19:14:33 -0700281bool sci_port_is_valid_phy_assignment(
Dan Williamsffe191c2011-06-29 13:09:25 -0700282 struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700283 u32 phy_index);
284
Dan Williams89a73012011-06-30 19:14:33 -0700285void sci_port_get_sas_address(
Dan Williamsffe191c2011-06-29 13:09:25 -0700286 struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700287 struct sci_sas_address *sas_address);
288
Dan Williams89a73012011-06-30 19:14:33 -0700289void sci_port_get_attached_sas_address(
Dan Williamsffe191c2011-06-29 13:09:25 -0700290 struct isci_port *iport,
Dan Williamse2f8db52011-05-10 02:28:46 -0700291 struct sci_sas_address *sas_address);
292
Dan Williams6f231dd2011-07-02 22:56:22 -0700293enum isci_status isci_port_get_state(
294 struct isci_port *isci_port);
295
Dan Williamse2f8db52011-05-10 02:28:46 -0700296void isci_port_formed(struct asd_sas_phy *);
297void isci_port_deformed(struct asd_sas_phy *);
Dan Williams6f231dd2011-07-02 22:56:22 -0700298
299void isci_port_init(
300 struct isci_port *port,
301 struct isci_host *host,
302 int index);
303
Dan Williams4393aa42011-03-31 13:10:44 -0700304int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
305 struct isci_phy *iphy);
Dan Williams6f231dd2011-07-02 22:56:22 -0700306#endif /* !defined(_ISCI_PORT_H_) */