2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
9 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
23 * The full GNU General Public License is included in this distribution
24 * in the file called LICENSE.GPL.
28 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
35 * * Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * * Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in
39 * the documentation and/or other materials provided with the
42 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 #ifndef _SCIC_SDS_PORT_H_
57 #define _SCIC_SDS_PORT_H_
66 * @brief This file contains the structures, constants and prototypes for the
67 * SCIC_SDS_PORT_T object.
70 #include <dev/isci/scil/sci_controller_constants.h>
71 #include <dev/isci/scil/intel_sas.h>
72 #include <dev/isci/scil/sci_base_port.h>
73 #include <dev/isci/scil/sci_base_phy.h>
74 #include <dev/isci/scil/scu_registers.h>
76 #define SCIC_SDS_DUMMY_PORT 0xFF
79 * @enum SCIC_SDS_PORT_READY_SUBSTATES
81 * This enumeration depicts all of the states for the core port ready substate
84 enum SCIC_SDS_PORT_READY_SUBSTATES
87 * The substate where the port is started and ready but has no active phys.
89 SCIC_SDS_PORT_READY_SUBSTATE_WAITING,
92 * The substate where the port is started and ready and there is at least one
95 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL,
98 * The substate where the port is started and there was an add/remove phy
99 * event. This state is only used in Automatic Port Configuration Mode (APC)
101 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING,
103 SCIC_SDS_PORT_READY_MAX_SUBSTATES
106 struct SCIC_SDS_CONTROLLER;
108 struct SCIC_SDS_REMOTE_DEVICE;
109 struct SCIC_SDS_REQUEST;
112 * @struct SCIC_SDS_PORT
114 * The core port object provides the abstraction for an SCU port.
116 typedef struct SCIC_SDS_PORT
119 * This field is the oommon base port object.
121 SCI_BASE_PORT_T parent;
124 * This field is the port index that is reported to the SCI USER. This allows
125 * the actual hardware physical port to change without the SCI USER getting a
126 * different answer for the get port index.
128 U8 logical_port_index;
131 * This field is the port index used to program the SCU hardware.
133 U8 physical_port_index;
136 * This field contains the active phy mask for the port. This mask is used in
137 * conjunction with the phy state to determine which phy to select for some
143 * This field contains the phy mask for the port that are already part of the port.
151 * This field contains the count of the io requests started on this port
152 * object. It is used to control controller shutdown.
154 U32 started_request_count;
157 * This field contains the number of devices assigned to this port. It is
158 * used to control port start requests.
160 U32 assigned_device_count;
163 * This field contains the reason for the port not going ready. It is
164 * assigned in the state handlers and used in the state transition.
166 U32 not_ready_reason;
169 * This field is the table of phys assigned to the port.
171 struct SCIC_SDS_PHY *phy_table[SCI_MAX_PHYS];
174 * This field is a pointer back to the controller that owns this port object.
176 struct SCIC_SDS_CONTROLLER *owning_controller;
179 * This field contains the port start/stop timer handle.
184 * This field points to the current set of state handlers for this port
185 * object. These state handlers are assigned at each enter state of the state
188 struct SCIC_SDS_PORT_STATE_HANDLER *state_handlers;
191 * This field is the ready substate machine for the port.
193 SCI_BASE_STATE_MACHINE_T ready_substate_machine;
197 * This field is the ready substate machine logger. It logs each state
198 * transition request in the ready substate machine.
200 SCI_BASE_STATE_MACHINE_LOGGER_T ready_substate_machine_logger;
203 /// Memory mapped hardware register space
206 * This field is the pointer to the port task scheduler registers for the SCU
209 SCU_PORT_TASK_SCHEDULER_REGISTERS_T *port_task_scheduler_registers;
212 * This field is identical for all port objects and points to the port task
213 * scheduler group PE configuration registers. It is used to assign PEs to a
216 SCU_PORT_PE_CONFIGURATION_REGISTER_T *port_pe_configuration_register;
219 * This field is the VIIT register space for this port object.
221 SCU_VIIT_ENTRY_T *viit_registers;
226 typedef SCI_STATUS (*SCIC_SDS_PORT_EVENT_HANDLER_T)(struct SCIC_SDS_PORT *, U32);
228 typedef SCI_STATUS (*SCIC_SDS_PORT_FRAME_HANDLER_T)(struct SCIC_SDS_PORT *, U32);
230 typedef void (*SCIC_SDS_PORT_LINK_HANDLER_T)(struct SCIC_SDS_PORT *, struct SCIC_SDS_PHY *);
232 typedef SCI_STATUS (*SCIC_SDS_PORT_IO_REQUEST_HANDLER_T)(
233 struct SCIC_SDS_PORT *,
234 struct SCIC_SDS_REMOTE_DEVICE *,
235 struct SCIC_SDS_REQUEST *);
237 typedef struct SCIC_SDS_PORT_STATE_HANDLER
239 SCI_BASE_PORT_STATE_HANDLER_T parent;
241 SCIC_SDS_PORT_FRAME_HANDLER_T frame_handler;
242 SCIC_SDS_PORT_EVENT_HANDLER_T event_handler;
244 SCIC_SDS_PORT_LINK_HANDLER_T link_up_handler;
245 SCIC_SDS_PORT_LINK_HANDLER_T link_down_handler;
247 SCIC_SDS_PORT_IO_REQUEST_HANDLER_T start_io_handler;
248 SCIC_SDS_PORT_IO_REQUEST_HANDLER_T complete_io_handler;
250 } SCIC_SDS_PORT_STATE_HANDLER_T;
252 extern SCI_BASE_STATE_T scic_sds_port_state_table[];
253 extern SCI_BASE_STATE_T scic_sds_port_ready_substate_table[];
255 extern SCIC_SDS_PORT_STATE_HANDLER_T scic_sds_port_state_handler_table[];
256 extern SCIC_SDS_PORT_STATE_HANDLER_T scic_sds_port_ready_substate_handler_table[];
259 * Helper macro to get the owning controller of this port
261 #define scic_sds_port_get_controller(this_port) \
262 ((this_port)->owning_controller)
265 * Helper macro to get the base state machine for this port
267 #define scic_sds_port_get_base_state_machine(this_port) \
268 (&(this_port)->parent.state_machine)
271 * This macro will change the state handlers to those of the specified state
274 #define scic_sds_port_set_base_state_handlers(this_port, state_id) \
275 scic_sds_port_set_state_handlers( \
276 (this_port), &scic_sds_port_state_handler_table[(state_id)])
279 * Helper macro to get the ready substate machine for this port
281 #define scic_sds_port_get_ready_substate_machine(this_port) \
282 (&(this_port)->ready_substate_machine)
285 * Helper macro to set the port object state handlers
287 #define scic_sds_port_set_state_handlers(this_port, handlers) \
288 ((this_port)->state_handlers = (handlers))
291 * This macro returns the physical port index for this port object
293 #define scic_sds_port_get_index(this_port) \
294 ((this_port)->physical_port_index)
297 * Helper macro to increment the started request count
299 #define scic_sds_port_increment_request_count(this_port) \
300 ((this_port)->started_request_count++)
302 #ifdef SCIC_DEBUG_ENABLED
304 * @brief This method decrements the started io request count. The method
305 * will not decrment the started io request count below 0 and will
306 * log a debug message if this is attempted.
308 * @param[in] this_port
310 void scic_sds_port_decrement_request_count(
311 SCIC_SDS_PORT_T *this_port
315 * Helper macro to decrement the started io request count. The macro will
316 * not decrement the started io request count below 0.
318 #define scic_sds_port_decrement_request_count(this_port) \
320 (this_port)->started_request_count = ( \
321 ((this_port)->started_request_count == 0) ? \
322 (this_port)->started_request_count : \
323 ((this_port)->started_request_count - 1) \
329 * Helper macro to write the phys port assignment
331 #define scic_sds_port_write_phy_assignment(port, phy) \
332 SCU_PCSPExCR_WRITE( \
335 (port)->physical_port_index \
339 * Helper macro to read the phys port assignment
341 #define scic_sds_port_read_phy_assignment(port, phy) \
347 #define scic_sds_port_active_phy(port, phy) \
348 (((port)->active_phy_mask & (1 << (phy)->phy_index)) != 0)
350 // ---------------------------------------------------------------------------
352 U32 scic_sds_port_get_object_size(void);
354 U32 scic_sds_port_get_min_timer_count(void);
356 U32 scic_sds_port_get_max_timer_count(void);
358 // ---------------------------------------------------------------------------
361 void scic_sds_port_initialize_state_logging(
362 SCIC_SDS_PORT_T *this_port
365 #define scic_sds_port_initialize_state_logging(x)
368 // ---------------------------------------------------------------------------
370 void scic_sds_port_construct(
371 SCIC_SDS_PORT_T *this_port,
373 struct SCIC_SDS_CONTROLLER *owning_controller
376 SCI_STATUS scic_sds_port_initialize(
377 SCIC_SDS_PORT_T *this_port,
378 void *port_task_scheduler_registers,
379 void *port_configuration_regsiter,
383 // ---------------------------------------------------------------------------
385 SCI_STATUS scic_sds_port_add_phy(
386 struct SCIC_SDS_PORT * this_port,
387 struct SCIC_SDS_PHY * the_phy
390 SCI_STATUS scic_sds_port_remove_phy(
391 struct SCIC_SDS_PORT * this_port,
392 struct SCIC_SDS_PHY * the_phy
395 void scic_sds_port_setup_transports(
396 SCIC_SDS_PORT_T * this_port,
400 void scic_sds_port_activate_phy(
401 SCIC_SDS_PORT_T *this_port,
402 struct SCIC_SDS_PHY *phy,
407 void scic_sds_port_deactivate_phy(
408 SCIC_SDS_PORT_T *this_port,
409 struct SCIC_SDS_PHY *phy,
413 struct SCIC_SDS_PHY * scic_sds_port_get_a_connected_phy(
414 SCIC_SDS_PORT_T * this_port
417 void scic_sds_port_invalid_link_up(
418 SCIC_SDS_PORT_T *this_port,
419 struct SCIC_SDS_PHY *phy
422 void scic_sds_port_general_link_up_handler(
423 SCIC_SDS_PORT_T *this_port,
424 struct SCIC_SDS_PHY *the_phy,
429 BOOL scic_sds_port_link_detected(
430 SCIC_SDS_PORT_T *this_port,
431 struct SCIC_SDS_PHY *phy
434 void scic_sds_port_link_up(
435 SCIC_SDS_PORT_T *this_port,
436 struct SCIC_SDS_PHY *phy
439 void scic_sds_port_link_down(
440 SCIC_SDS_PORT_T *this_port,
441 struct SCIC_SDS_PHY *phy
444 // ---------------------------------------------------------------------------
446 void scic_sds_port_timeout_handler(
450 // ---------------------------------------------------------------------------
452 SCI_STATUS scic_sds_port_start_io(
453 SCIC_SDS_PORT_T *this_port,
454 struct SCIC_SDS_REMOTE_DEVICE *the_device,
455 struct SCIC_SDS_REQUEST *the_io_request
458 SCI_STATUS scic_sds_port_complete_io(
459 SCIC_SDS_PORT_T *this_port,
460 struct SCIC_SDS_REMOTE_DEVICE *the_device,
461 struct SCIC_SDS_REQUEST *the_io_request
464 // ---------------------------------------------------------------------------
466 void scic_sds_port_update_viit_entry(
467 SCIC_SDS_PORT_T *this_port
470 // ---------------------------------------------------------------------------
472 SCI_STATUS scic_sds_port_default_start_handler(
473 SCI_BASE_PORT_T *port
476 SCI_STATUS scic_sds_port_default_stop_handler(
477 SCI_BASE_PORT_T *port
480 SCI_STATUS scic_sds_port_default_destruct_handler(
481 SCI_BASE_PORT_T *port
484 SCI_STATUS scic_sds_port_default_reset_handler(
485 SCI_BASE_PORT_T * port,
489 SCI_STATUS scic_sds_port_default_add_phy_handler(
490 SCI_BASE_PORT_T *port,
494 SCI_STATUS scic_sds_port_default_remove_phy_handler(
495 SCI_BASE_PORT_T *port,
499 SCI_STATUS scic_sds_port_default_frame_handler(
500 struct SCIC_SDS_PORT * port,
504 SCI_STATUS scic_sds_port_default_event_handler(
505 struct SCIC_SDS_PORT * port,
509 void scic_sds_port_default_link_up_handler(
510 struct SCIC_SDS_PORT *this_port,
511 struct SCIC_SDS_PHY *phy
514 void scic_sds_port_default_link_down_handler(
515 struct SCIC_SDS_PORT *this_port,
516 struct SCIC_SDS_PHY *phy
519 SCI_STATUS scic_sds_port_default_start_io_handler(
520 struct SCIC_SDS_PORT *port,
521 struct SCIC_SDS_REMOTE_DEVICE *device,
522 struct SCIC_SDS_REQUEST *io_request
525 SCI_STATUS scic_sds_port_default_complete_io_handler(
526 struct SCIC_SDS_PORT *port,
527 struct SCIC_SDS_REMOTE_DEVICE *device,
528 struct SCIC_SDS_REQUEST *io_request
531 SCI_SAS_LINK_RATE scic_sds_port_get_max_allowed_speed(
532 SCIC_SDS_PORT_T * this_port
535 void scic_sds_port_broadcast_change_received(
536 struct SCIC_SDS_PORT * this_port,
537 struct SCIC_SDS_PHY * this_phy
540 BOOL scic_sds_port_is_valid_phy_assignment(
541 SCIC_SDS_PORT_T *this_port,
545 BOOL scic_sds_port_is_phy_mask_valid(
546 SCIC_SDS_PORT_T * this_port,
550 U32 scic_sds_port_get_phys(
551 SCIC_SDS_PORT_T * this_port
554 void scic_sds_port_get_sas_address(
555 SCIC_SDS_PORT_T * this_port,
556 SCI_SAS_ADDRESS_T * sas_address
559 void scic_sds_port_get_attached_sas_address(
560 SCIC_SDS_PORT_T * this_port,
561 SCI_SAS_ADDRESS_T * sas_address
564 void scic_sds_port_get_attached_protocols(
565 SCIC_SDS_PORT_T * this_port,
566 SCI_SAS_IDENTIFY_ADDRESS_FRAME_PROTOCOLS_T * protocols
569 SCI_STATUS scic_sds_port_set_phy(
570 struct SCIC_SDS_PORT *port,
571 struct SCIC_SDS_PHY *phy
574 SCI_STATUS scic_sds_port_clear_phy(
575 struct SCIC_SDS_PORT *port,
576 struct SCIC_SDS_PHY *phy
579 void scic_sds_port_suspend_port_task_scheduler(
580 SCIC_SDS_PORT_T *this_port
583 void scic_sds_port_resume_port_task_scheduler(
584 SCIC_SDS_PORT_T *this_port
587 void scic_sds_port_release_resource(
588 struct SCIC_SDS_CONTROLLER * controller,
589 struct SCIC_SDS_PORT * port
594 #endif // __cplusplus
597 #endif // _SCIC_SDS_PORT_H_