isci: uplevel state machine
[deliverable/linux.git] / drivers / scsi / isci / core / scic_sds_port.h
1 /*
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
56 #ifndef _SCIC_SDS_PORT_H_
57 #define _SCIC_SDS_PORT_H_
58
59 #include <linux/kernel.h>
60 #include "isci.h"
61 #include "sas.h"
62 #include "registers.h"
63 #include "state_machine.h"
64
65 struct scic_sds_controller;
66 struct scic_sds_phy;
67 struct scic_sds_remote_device;
68 struct scic_sds_request;
69
70 #define SCIC_SDS_DUMMY_PORT 0xFF
71
72 /**
73 * enum SCIC_SDS_PORT_READY_SUBSTATES -
74 *
75 * This enumeration depicts all of the states for the core port ready substate
76 * machine.
77 */
78 enum scic_sds_port_ready_substates {
79 /**
80 * The substate where the port is started and ready but has no
81 * active phys.
82 */
83 SCIC_SDS_PORT_READY_SUBSTATE_WAITING,
84
85 /**
86 * The substate where the port is started and ready and there is
87 * at least one phy operational.
88 */
89 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL,
90
91 /**
92 * The substate where the port is started and there was an
93 * add/remove phy event. This state is only used in Automatic
94 * Port Configuration Mode (APC)
95 */
96 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING,
97
98 SCIC_SDS_PORT_READY_MAX_SUBSTATES
99 };
100
101 /**
102 * enum scic_sds_port_states - This enumeration depicts all the states for the
103 * common port state machine.
104 *
105 *
106 */
107 enum scic_sds_port_states {
108 /**
109 * This state indicates that the port has successfully been stopped.
110 * In this state no new IO operations are permitted.
111 * This state is entered from the STOPPING state.
112 */
113 SCI_BASE_PORT_STATE_STOPPED,
114
115 /**
116 * This state indicates that the port is in the process of stopping.
117 * In this state no new IO operations are permitted, but existing IO
118 * operations are allowed to complete.
119 * This state is entered from the READY state.
120 */
121 SCI_BASE_PORT_STATE_STOPPING,
122
123 /**
124 * This state indicates the port is now ready. Thus, the user is
125 * able to perform IO operations on this port.
126 * This state is entered from the STARTING state.
127 */
128 SCI_BASE_PORT_STATE_READY,
129
130 /**
131 * This state indicates the port is in the process of performing a hard
132 * reset. Thus, the user is unable to perform IO operations on this
133 * port.
134 * This state is entered from the READY state.
135 */
136 SCI_BASE_PORT_STATE_RESETTING,
137
138 /**
139 * This state indicates the port has failed a reset request. This state
140 * is entered when a port reset request times out.
141 * This state is entered from the RESETTING state.
142 */
143 SCI_BASE_PORT_STATE_FAILED,
144
145 SCI_BASE_PORT_MAX_STATES
146
147 };
148
149 /**
150 * struct scic_sds_port
151 *
152 * The core port object provides the the abstraction for an SCU port.
153 */
154 struct scic_sds_port {
155
156 /**
157 * This field contains the information for the base port state machine.
158 */
159 struct sci_base_state_machine state_machine;
160
161 /**
162 * This field is the port index that is reported to the SCI USER.
163 * This allows the actual hardware physical port to change without
164 * the SCI USER getting a different answer for the get port index.
165 */
166 u8 logical_port_index;
167
168 /**
169 * This field is the port index used to program the SCU hardware.
170 */
171 u8 physical_port_index;
172
173 /**
174 * This field contains the active phy mask for the port.
175 * This mask is used in conjunction with the phy state to determine
176 * which phy to select for some port operations.
177 */
178 u8 active_phy_mask;
179
180 u16 reserved_rni;
181 u16 reserved_tci;
182
183 /**
184 * This field contains the count of the io requests started on this port
185 * object. It is used to control controller shutdown.
186 */
187 u32 started_request_count;
188
189 /**
190 * This field contains the number of devices assigned to this port.
191 * It is used to control port start requests.
192 */
193 u32 assigned_device_count;
194
195 /**
196 * This field contains the reason for the port not going ready. It is
197 * assigned in the state handlers and used in the state transition.
198 */
199 u32 not_ready_reason;
200
201 /**
202 * This field is the table of phys assigned to the port.
203 */
204 struct scic_sds_phy *phy_table[SCI_MAX_PHYS];
205
206 /**
207 * This field is a pointer back to the controller that owns this
208 * port object.
209 */
210 struct scic_sds_controller *owning_controller;
211
212 /**
213 * This field contains the port start/stop timer handle.
214 */
215 void *timer_handle;
216
217 /**
218 * This field points to the current set of state handlers for this port
219 * object. These state handlers are assigned at each enter state of
220 * the state machine.
221 */
222 struct scic_sds_port_state_handler *state_handlers;
223
224 /**
225 * This field is the ready substate machine for the port.
226 */
227 struct sci_base_state_machine ready_substate_machine;
228
229 /* / Memory mapped hardware register space */
230
231 /**
232 * This field is the pointer to the port task scheduler registers
233 * for the SCU hardware.
234 */
235 struct scu_port_task_scheduler_registers __iomem
236 *port_task_scheduler_registers;
237
238 /**
239 * This field is identical for all port objects and points to the port
240 * task scheduler group PE configuration registers.
241 * It is used to assign PEs to a port.
242 */
243 u32 __iomem *port_pe_configuration_register;
244
245 /**
246 * This field is the VIIT register space for ths port object.
247 */
248 struct scu_viit_entry __iomem *viit_registers;
249
250 };
251
252 typedef enum sci_status (*scic_sds_port_handler_t)(struct scic_sds_port *);
253
254 typedef enum sci_status (*scic_sds_port_phy_handler_t)(struct scic_sds_port *,
255 struct scic_sds_phy *);
256
257 typedef enum sci_status (*scic_sds_port_reset_handler_t)(struct scic_sds_port *,
258 u32 timeout);
259
260 typedef enum sci_status (*scic_sds_port_event_handler_t)(struct scic_sds_port *, u32);
261
262 typedef enum sci_status (*scic_sds_port_frame_handler_t)(struct scic_sds_port *, u32);
263
264 typedef void (*scic_sds_port_link_handler_t)(struct scic_sds_port *, struct scic_sds_phy *);
265
266 typedef enum sci_status (*scic_sds_port_io_request_handler_t)(struct scic_sds_port *,
267 struct scic_sds_remote_device *,
268 struct scic_sds_request *);
269
270 struct scic_sds_port_state_handler {
271 /**
272 * The start_handler specifies the method invoked when a user
273 * attempts to start a port.
274 */
275 scic_sds_port_handler_t start_handler;
276
277 /**
278 * The stop_handler specifies the method invoked when a user
279 * attempts to stop a port.
280 */
281 scic_sds_port_handler_t stop_handler;
282
283 /**
284 * The destruct_handler specifies the method invoked when attempting to
285 * destruct a port.
286 */
287 scic_sds_port_handler_t destruct_handler;
288
289 /**
290 * The reset_handler specifies the method invoked when a user
291 * attempts to hard reset a port.
292 */
293 scic_sds_port_reset_handler_t reset_handler;
294
295 /**
296 * The add_phy_handler specifies the method invoked when a user
297 * attempts to add another phy into the port.
298 */
299 scic_sds_port_phy_handler_t add_phy_handler;
300
301 /**
302 * The remove_phy_handler specifies the method invoked when a user
303 * attempts to remove a phy from the port.
304 */
305 scic_sds_port_phy_handler_t remove_phy_handler;
306
307 scic_sds_port_frame_handler_t frame_handler;
308 scic_sds_port_event_handler_t event_handler;
309
310 scic_sds_port_link_handler_t link_up_handler;
311 scic_sds_port_link_handler_t link_down_handler;
312
313 scic_sds_port_io_request_handler_t start_io_handler;
314 scic_sds_port_io_request_handler_t complete_io_handler;
315
316 };
317
318 /**
319 * scic_sds_port_get_controller() -
320 *
321 * Helper macro to get the owning controller of this port
322 */
323 #define scic_sds_port_get_controller(this_port) \
324 ((this_port)->owning_controller)
325
326 /**
327 * scic_sds_port_set_base_state_handlers() -
328 *
329 * This macro will change the state handlers to those of the specified state id
330 */
331 #define scic_sds_port_set_base_state_handlers(this_port, state_id) \
332 scic_sds_port_set_state_handlers(\
333 (this_port), &scic_sds_port_state_handler_table[(state_id)])
334
335 /**
336 * scic_sds_port_set_state_handlers() -
337 *
338 * Helper macro to set the port object state handlers
339 */
340 #define scic_sds_port_set_state_handlers(this_port, handlers) \
341 ((this_port)->state_handlers = (handlers))
342
343 /**
344 * scic_sds_port_get_index() -
345 *
346 * This macro returns the physical port index for this port object
347 */
348 #define scic_sds_port_get_index(this_port) \
349 ((this_port)->physical_port_index)
350
351
352 static inline void scic_sds_port_decrement_request_count(struct scic_sds_port *sci_port)
353 {
354 if (WARN_ONCE(sci_port->started_request_count == 0,
355 "%s: tried to decrement started_request_count past 0!?",
356 __func__))
357 /* pass */;
358 else
359 sci_port->started_request_count--;
360 }
361
362 #define scic_sds_port_active_phy(port, phy) \
363 (((port)->active_phy_mask & (1 << (phy)->phy_index)) != 0)
364
365 void scic_sds_port_construct(
366 struct scic_sds_port *sci_port,
367 u8 port_index,
368 struct scic_sds_controller *scic);
369
370 enum sci_status scic_sds_port_initialize(
371 struct scic_sds_port *sci_port,
372 void __iomem *port_task_scheduler_registers,
373 void __iomem *port_configuration_regsiter,
374 void __iomem *viit_registers);
375
376 enum sci_status scic_sds_port_add_phy(
377 struct scic_sds_port *sci_port,
378 struct scic_sds_phy *sci_phy);
379
380 enum sci_status scic_sds_port_remove_phy(
381 struct scic_sds_port *sci_port,
382 struct scic_sds_phy *sci_phy);
383
384 void scic_sds_port_setup_transports(
385 struct scic_sds_port *sci_port,
386 u32 device_id);
387
388
389 void scic_sds_port_deactivate_phy(
390 struct scic_sds_port *sci_port,
391 struct scic_sds_phy *sci_phy,
392 bool do_notify_user);
393
394 bool scic_sds_port_link_detected(
395 struct scic_sds_port *sci_port,
396 struct scic_sds_phy *sci_phy);
397
398 void scic_sds_port_link_up(
399 struct scic_sds_port *sci_port,
400 struct scic_sds_phy *sci_phy);
401
402 void scic_sds_port_link_down(
403 struct scic_sds_port *sci_port,
404 struct scic_sds_phy *sci_phy);
405
406 enum sci_status scic_sds_port_start_io(
407 struct scic_sds_port *sci_port,
408 struct scic_sds_remote_device *sci_dev,
409 struct scic_sds_request *sci_req);
410
411 enum sci_status scic_sds_port_complete_io(
412 struct scic_sds_port *sci_port,
413 struct scic_sds_remote_device *sci_dev,
414 struct scic_sds_request *sci_req);
415
416 enum sas_linkrate scic_sds_port_get_max_allowed_speed(
417 struct scic_sds_port *sci_port);
418
419 void scic_sds_port_broadcast_change_received(
420 struct scic_sds_port *sci_port,
421 struct scic_sds_phy *sci_phy);
422
423 bool scic_sds_port_is_valid_phy_assignment(
424 struct scic_sds_port *sci_port,
425 u32 phy_index);
426
427 void scic_sds_port_get_sas_address(
428 struct scic_sds_port *sci_port,
429 struct sci_sas_address *sas_address);
430
431 void scic_sds_port_get_attached_sas_address(
432 struct scic_sds_port *sci_port,
433 struct sci_sas_address *sas_address);
434
435 #endif /* _SCIC_SDS_PORT_H_ */
This page took 0.048484 seconds and 5 git commands to generate.