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