blob: bbce0ec583a99c25ebbebc14cdb63e4993063dd0 [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 Williamse2f8db52011-05-10 02:28:46 -070079 * struct scic_sds_port
80 *
81 * The core port object provides the the abstraction for an SCU port.
82 */
83struct scic_sds_port {
Dan Williamse2f8db52011-05-10 02:28:46 -070084 /**
85 * This field contains the information for the base port state machine.
86 */
87 struct sci_base_state_machine state_machine;
88
Piotr Sawickie91f41e2011-05-11 23:52:21 +000089 bool ready_exit;
90
Dan Williamse2f8db52011-05-10 02:28:46 -070091 /**
92 * This field is the port index that is reported to the SCI USER.
93 * This allows the actual hardware physical port to change without
94 * the SCI USER getting a different answer for the get port index.
95 */
96 u8 logical_port_index;
97
98 /**
99 * This field is the port index used to program the SCU hardware.
100 */
101 u8 physical_port_index;
102
103 /**
104 * This field contains the active phy mask for the port.
105 * This mask is used in conjunction with the phy state to determine
106 * which phy to select for some port operations.
107 */
108 u8 active_phy_mask;
109
110 u16 reserved_rni;
111 u16 reserved_tci;
112
113 /**
114 * This field contains the count of the io requests started on this port
115 * object. It is used to control controller shutdown.
116 */
117 u32 started_request_count;
118
119 /**
120 * This field contains the number of devices assigned to this port.
121 * It is used to control port start requests.
122 */
123 u32 assigned_device_count;
124
125 /**
126 * This field contains the reason for the port not going ready. It is
127 * assigned in the state handlers and used in the state transition.
128 */
129 u32 not_ready_reason;
130
131 /**
132 * This field is the table of phys assigned to the port.
133 */
134 struct scic_sds_phy *phy_table[SCI_MAX_PHYS];
135
136 /**
137 * This field is a pointer back to the controller that owns this
138 * port object.
139 */
140 struct scic_sds_controller *owning_controller;
141
142 /**
143 * This field contains the port start/stop timer handle.
144 */
145 void *timer_handle;
146
147 /**
148 * This field points to the current set of state handlers for this port
149 * object. These state handlers are assigned at each enter state of
150 * the state machine.
151 */
152 struct scic_sds_port_state_handler *state_handlers;
153
Dan Williamse2f8db52011-05-10 02:28:46 -0700154 /* / Memory mapped hardware register space */
155
156 /**
157 * This field is the pointer to the port task scheduler registers
158 * for the SCU hardware.
159 */
160 struct scu_port_task_scheduler_registers __iomem
161 *port_task_scheduler_registers;
162
163 /**
164 * This field is identical for all port objects and points to the port
165 * task scheduler group PE configuration registers.
166 * It is used to assign PEs to a port.
167 */
168 u32 __iomem *port_pe_configuration_register;
169
170 /**
171 * This field is the VIIT register space for ths port object.
172 */
173 struct scu_viit_entry __iomem *viit_registers;
Dan Williamse2f8db52011-05-10 02:28:46 -0700174};
175
176
177
178/**
Dan Williams6f231dd2011-07-02 22:56:22 -0700179 * struct isci_port - This class represents the port object used to internally
180 * represent libsas port objects. It also keeps a list of remote device
181 * objects.
182 *
183 *
184 */
185struct isci_port {
Dan Williams6f231dd2011-07-02 22:56:22 -0700186 enum isci_status status;
187 struct isci_host *isci_host;
188 struct asd_sas_port sas_port;
189 struct list_head remote_dev_list;
Dan Williams6f231dd2011-07-02 22:56:22 -0700190 spinlock_t state_lock;
191 struct list_head domain_dev_list;
192 struct completion start_complete;
193 struct completion hard_reset_complete;
194 enum sci_status hard_reset_status;
Dan Williamse5313812011-05-07 10:11:43 -0700195 struct scic_sds_port sci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700196};
197
Dan Williamse5313812011-05-07 10:11:43 -0700198static inline struct isci_port *sci_port_to_iport(struct scic_sds_port *sci_port)
199{
200 struct isci_port *iport = container_of(sci_port, typeof(*iport), sci);
201
202 return iport;
203}
Dan Williams6f231dd2011-07-02 22:56:22 -0700204
Dan Williamse2f8db52011-05-10 02:28:46 -0700205enum scic_port_not_ready_reason_code {
206 SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS,
207 SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED,
208 SCIC_PORT_NOT_READY_INVALID_PORT_CONFIGURATION,
209 SCIC_PORT_NOT_READY_RECONFIGURING,
210
211 SCIC_PORT_NOT_READY_REASON_CODE_MAX
212};
213
214struct scic_port_end_point_properties {
215 struct sci_sas_address sas_address;
216 struct scic_phy_proto protocols;
217};
218
219struct scic_port_properties {
220 u32 index;
221 struct scic_port_end_point_properties local;
222 struct scic_port_end_point_properties remote;
223 u32 phy_mask;
224};
225
226/**
Dan Williamse2f8db52011-05-10 02:28:46 -0700227 * enum scic_sds_port_states - This enumeration depicts all the states for the
228 * common port state machine.
229 *
230 *
231 */
232enum scic_sds_port_states {
233 /**
234 * This state indicates that the port has successfully been stopped.
235 * In this state no new IO operations are permitted.
236 * This state is entered from the STOPPING state.
237 */
238 SCI_BASE_PORT_STATE_STOPPED,
239
240 /**
241 * This state indicates that the port is in the process of stopping.
242 * In this state no new IO operations are permitted, but existing IO
243 * operations are allowed to complete.
244 * This state is entered from the READY state.
245 */
246 SCI_BASE_PORT_STATE_STOPPING,
247
248 /**
249 * This state indicates the port is now ready. Thus, the user is
250 * able to perform IO operations on this port.
251 * This state is entered from the STARTING state.
252 */
253 SCI_BASE_PORT_STATE_READY,
254
255 /**
Piotr Sawickie91f41e2011-05-11 23:52:21 +0000256 * The substate where the port is started and ready but has no
257 * active phys.
258 */
259 SCIC_SDS_PORT_READY_SUBSTATE_WAITING,
260
261 /**
262 * The substate where the port is started and ready and there is
263 * at least one phy operational.
264 */
265 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL,
266
267 /**
268 * The substate where the port is started and there was an
269 * add/remove phy event. This state is only used in Automatic
270 * Port Configuration Mode (APC)
271 */
272 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING,
273
274 /**
Dan Williamse2f8db52011-05-10 02:28:46 -0700275 * This state indicates the port is in the process of performing a hard
276 * reset. Thus, the user is unable to perform IO operations on this
277 * port.
278 * This state is entered from the READY state.
279 */
280 SCI_BASE_PORT_STATE_RESETTING,
281
282 /**
283 * This state indicates the port has failed a reset request. This state
284 * is entered when a port reset request times out.
285 * This state is entered from the RESETTING state.
286 */
287 SCI_BASE_PORT_STATE_FAILED,
288
289 SCI_BASE_PORT_MAX_STATES
290
291};
292
293struct scic_sds_remote_device;
294struct scic_sds_request;
295
296typedef enum sci_status (*scic_sds_port_handler_t)(struct scic_sds_port *);
297
298typedef enum sci_status (*scic_sds_port_phy_handler_t)(struct scic_sds_port *,
299 struct scic_sds_phy *);
300
301typedef enum sci_status (*scic_sds_port_reset_handler_t)(struct scic_sds_port *,
302 u32 timeout);
303
304typedef enum sci_status (*scic_sds_port_event_handler_t)(struct scic_sds_port *, u32);
305
306typedef enum sci_status (*scic_sds_port_frame_handler_t)(struct scic_sds_port *, u32);
307
308typedef void (*scic_sds_port_link_handler_t)(struct scic_sds_port *, struct scic_sds_phy *);
309
310typedef enum sci_status (*scic_sds_port_io_request_handler_t)(struct scic_sds_port *,
311 struct scic_sds_remote_device *,
312 struct scic_sds_request *);
313
314struct scic_sds_port_state_handler {
Dan Williamse2f8db52011-05-10 02:28:46 -0700315 scic_sds_port_io_request_handler_t start_io_handler;
316 scic_sds_port_io_request_handler_t complete_io_handler;
Dan Williamse2f8db52011-05-10 02:28:46 -0700317};
318
319/**
320 * scic_sds_port_get_controller() -
321 *
322 * Helper macro to get the owning controller of this port
323 */
324#define scic_sds_port_get_controller(this_port) \
325 ((this_port)->owning_controller)
326
327/**
328 * scic_sds_port_set_base_state_handlers() -
329 *
330 * This macro will change the state handlers to those of the specified state id
331 */
332#define scic_sds_port_set_base_state_handlers(this_port, state_id) \
333 scic_sds_port_set_state_handlers(\
334 (this_port), &scic_sds_port_state_handler_table[(state_id)])
335
336/**
337 * scic_sds_port_set_state_handlers() -
338 *
339 * Helper macro to set the port object state handlers
340 */
341#define scic_sds_port_set_state_handlers(this_port, handlers) \
342 ((this_port)->state_handlers = (handlers))
343
344/**
345 * scic_sds_port_get_index() -
346 *
347 * This macro returns the physical port index for this port object
348 */
349#define scic_sds_port_get_index(this_port) \
350 ((this_port)->physical_port_index)
351
352
353static inline void scic_sds_port_decrement_request_count(struct scic_sds_port *sci_port)
354{
355 if (WARN_ONCE(sci_port->started_request_count == 0,
356 "%s: tried to decrement started_request_count past 0!?",
357 __func__))
358 /* pass */;
359 else
360 sci_port->started_request_count--;
361}
362
363#define scic_sds_port_active_phy(port, phy) \
364 (((port)->active_phy_mask & (1 << (phy)->phy_index)) != 0)
365
366void scic_sds_port_construct(
367 struct scic_sds_port *sci_port,
368 u8 port_index,
369 struct scic_sds_controller *scic);
370
371enum sci_status scic_sds_port_initialize(
372 struct scic_sds_port *sci_port,
373 void __iomem *port_task_scheduler_registers,
374 void __iomem *port_configuration_regsiter,
375 void __iomem *viit_registers);
376
Piotr Sawickid76f71d2011-05-11 23:52:26 +0000377enum sci_status scic_sds_port_start(struct scic_sds_port *sci_port);
Piotr Sawicki8bc80d32011-05-11 23:52:31 +0000378enum sci_status scic_sds_port_stop(struct scic_sds_port *sci_port);
Piotr Sawickid76f71d2011-05-11 23:52:26 +0000379
Dan Williamse2f8db52011-05-10 02:28:46 -0700380enum sci_status scic_sds_port_add_phy(
381 struct scic_sds_port *sci_port,
382 struct scic_sds_phy *sci_phy);
383
384enum sci_status scic_sds_port_remove_phy(
385 struct scic_sds_port *sci_port,
386 struct scic_sds_phy *sci_phy);
387
388void scic_sds_port_setup_transports(
389 struct scic_sds_port *sci_port,
390 u32 device_id);
391
392
393void scic_sds_port_deactivate_phy(
394 struct scic_sds_port *sci_port,
395 struct scic_sds_phy *sci_phy,
396 bool do_notify_user);
397
398bool scic_sds_port_link_detected(
399 struct scic_sds_port *sci_port,
400 struct scic_sds_phy *sci_phy);
401
Piotr Sawicki051266c2011-05-12 19:10:14 +0000402enum sci_status scic_sds_port_link_up(struct scic_sds_port *sci_port,
403 struct scic_sds_phy *sci_phy);
404enum sci_status scic_sds_port_link_down(struct scic_sds_port *sci_port,
405 struct scic_sds_phy *sci_phy);
Dan Williamse2f8db52011-05-10 02:28:46 -0700406
407enum sci_status scic_sds_port_start_io(
408 struct scic_sds_port *sci_port,
409 struct scic_sds_remote_device *sci_dev,
410 struct scic_sds_request *sci_req);
411
412enum sci_status scic_sds_port_complete_io(
413 struct scic_sds_port *sci_port,
414 struct scic_sds_remote_device *sci_dev,
415 struct scic_sds_request *sci_req);
416
417enum sas_linkrate scic_sds_port_get_max_allowed_speed(
418 struct scic_sds_port *sci_port);
419
420void scic_sds_port_broadcast_change_received(
421 struct scic_sds_port *sci_port,
422 struct scic_sds_phy *sci_phy);
423
424bool scic_sds_port_is_valid_phy_assignment(
425 struct scic_sds_port *sci_port,
426 u32 phy_index);
427
428void scic_sds_port_get_sas_address(
429 struct scic_sds_port *sci_port,
430 struct sci_sas_address *sas_address);
431
432void scic_sds_port_get_attached_sas_address(
433 struct scic_sds_port *sci_port,
434 struct sci_sas_address *sas_address);
435
Dan Williams6f231dd2011-07-02 22:56:22 -0700436enum isci_status isci_port_get_state(
437 struct isci_port *isci_port);
438
Dan Williamse2f8db52011-05-10 02:28:46 -0700439void isci_port_formed(struct asd_sas_phy *);
440void isci_port_deformed(struct asd_sas_phy *);
Dan Williams6f231dd2011-07-02 22:56:22 -0700441
442void isci_port_init(
443 struct isci_port *port,
444 struct isci_host *host,
445 int index);
446
Dan Williams4393aa42011-03-31 13:10:44 -0700447int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
448 struct isci_phy *iphy);
Dan Williams6f231dd2011-07-02 22:56:22 -0700449#endif /* !defined(_ISCI_PORT_H_) */