1331766Sken/*-
2331766Sken * Copyright (c) 2017 Broadcom. All rights reserved.
3331766Sken * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
4331766Sken *
5331766Sken * Redistribution and use in source and binary forms, with or without
6331766Sken * modification, are permitted provided that the following conditions are met:
7331766Sken *
8331766Sken * 1. Redistributions of source code must retain the above copyright notice,
9331766Sken *    this list of conditions and the following disclaimer.
10331766Sken *
11331766Sken * 2. Redistributions in binary form must reproduce the above copyright notice,
12331766Sken *    this list of conditions and the following disclaimer in the documentation
13331766Sken *    and/or other materials provided with the distribution.
14331766Sken *
15331766Sken * 3. Neither the name of the copyright holder nor the names of its contributors
16331766Sken *    may be used to endorse or promote products derived from this software
17331766Sken *    without specific prior written permission.
18331766Sken *
19331766Sken * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20331766Sken * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21331766Sken * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22331766Sken * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23331766Sken * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24331766Sken * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25331766Sken * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26331766Sken * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27331766Sken * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28331766Sken * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29331766Sken * POSSIBILITY OF SUCH DAMAGE.
30331766Sken *
31331766Sken * $FreeBSD: stable/11/sys/dev/ocs_fc/ocs_xport.h 331766 2018-03-30 15:28:25Z ken $
32331766Sken */
33331766Sken
34331766Sken/**
35331766Sken * @file
36331766Sken *
37331766Sken */
38331766Sken
39331766Sken#if !defined(__OCS_XPORT_H__)
40331766Sken#define __OCS_XPORT_H__
41331766Sken
42331766Sken/**
43331766Sken * @brief FCFI lookup/pending frames
44331766Sken */
45331766Skentypedef struct ocs_xport_fcfi_s {
46331766Sken	ocs_lock_t	pend_frames_lock;
47331766Sken	ocs_list_t	pend_frames;
48331766Sken	uint32_t	hold_frames:1;		/*<< hold pending frames */
49331766Sken	uint32_t	pend_frames_processed;	/*<< count of pending frames that were processed */
50331766Sken} ocs_xport_fcfi_t;
51331766Sken
52331766Sken/**
53331766Sken * @brief Structure to hold the information related to an RQ processing thread used
54331766Sken *        to increase 40G performance.
55331766Sken */
56331766Skentypedef struct ocs_xport_rq_thread_info_s {
57331766Sken	ocs_t *ocs;
58331766Sken	uint8_t thread_started;
59331766Sken	ocs_thread_t thread;
60331766Sken	ocs_cbuf_t * seq_cbuf;
61331766Sken	char thread_name[64];
62331766Sken} ocs_xport_rq_thread_info_t;
63331766Sken
64331766Skentypedef enum {
65331766Sken	OCS_XPORT_PORT_ONLINE=1,
66331766Sken	OCS_XPORT_PORT_OFFLINE,
67331766Sken	OCS_XPORT_SHUTDOWN,
68331766Sken	OCS_XPORT_POST_NODE_EVENT,
69331766Sken	OCS_XPORT_WWNN_SET,
70331766Sken	OCS_XPORT_WWPN_SET,
71331766Sken} ocs_xport_ctrl_e;
72331766Sken
73331766Skentypedef enum {
74331766Sken	OCS_XPORT_PORT_STATUS,
75331766Sken	OCS_XPORT_CONFIG_PORT_STATUS,
76331766Sken	OCS_XPORT_LINK_SPEED,
77331766Sken	OCS_XPORT_IS_SUPPORTED_LINK_SPEED,
78331766Sken	OCS_XPORT_LINK_STATISTICS,
79331766Sken	OCS_XPORT_LINK_STAT_RESET,
80331766Sken	OCS_XPORT_IS_QUIESCED
81331766Sken} ocs_xport_status_e;
82331766Sken
83331766Skentypedef struct ocs_xport_link_stats_s {
84331766Sken	uint32_t	rec:1,
85331766Sken				gec:1,
86331766Sken				w02of:1,
87331766Sken				w03of:1,
88331766Sken				w04of:1,
89331766Sken				w05of:1,
90331766Sken				w06of:1,
91331766Sken				w07of:1,
92331766Sken				w08of:1,
93331766Sken				w09of:1,
94331766Sken				w10of:1,
95331766Sken				w11of:1,
96331766Sken				w12of:1,
97331766Sken				w13of:1,
98331766Sken				w14of:1,
99331766Sken				w15of:1,
100331766Sken				w16of:1,
101331766Sken				w17of:1,
102331766Sken				w18of:1,
103331766Sken				w19of:1,
104331766Sken				w20of:1,
105331766Sken				w21of:1,
106331766Sken				resv0:8,
107331766Sken				clrc:1,
108331766Sken				clof:1;
109331766Sken	uint32_t	link_failure_error_count;
110331766Sken	uint32_t	loss_of_sync_error_count;
111331766Sken	uint32_t	loss_of_signal_error_count;
112331766Sken	uint32_t	primitive_sequence_error_count;
113331766Sken	uint32_t	invalid_transmission_word_error_count;
114331766Sken	uint32_t	crc_error_count;
115331766Sken	uint32_t	primitive_sequence_event_timeout_count;
116331766Sken	uint32_t	elastic_buffer_overrun_error_count;
117331766Sken	uint32_t	arbitration_fc_al_timout_count;
118331766Sken	uint32_t	advertised_receive_bufftor_to_buffer_credit;
119331766Sken	uint32_t	current_receive_buffer_to_buffer_credit;
120331766Sken	uint32_t	advertised_transmit_buffer_to_buffer_credit;
121331766Sken	uint32_t	current_transmit_buffer_to_buffer_credit;
122331766Sken	uint32_t	received_eofa_count;
123331766Sken	uint32_t	received_eofdti_count;
124331766Sken	uint32_t	received_eofni_count;
125331766Sken	uint32_t	received_soff_count;
126331766Sken	uint32_t	received_dropped_no_aer_count;
127331766Sken	uint32_t	received_dropped_no_available_rpi_resources_count;
128331766Sken	uint32_t	received_dropped_no_available_xri_resources_count;
129331766Sken} ocs_xport_link_stats_t;
130331766Sken
131331766Skentypedef struct ocs_xport_host_stats_s {
132331766Sken	uint32_t	cc:1,
133331766Sken				  :31;
134331766Sken	uint32_t	transmit_kbyte_count;
135331766Sken	uint32_t	receive_kbyte_count;
136331766Sken	uint32_t	transmit_frame_count;
137331766Sken	uint32_t	receive_frame_count;
138331766Sken	uint32_t	transmit_sequence_count;
139331766Sken	uint32_t	receive_sequence_count;
140331766Sken	uint32_t	total_exchanges_originator;
141331766Sken	uint32_t	total_exchanges_responder;
142331766Sken	uint32_t	receive_p_bsy_count;
143331766Sken	uint32_t	receive_f_bsy_count;
144331766Sken	uint32_t	dropped_frames_due_to_no_rq_buffer_count;
145331766Sken	uint32_t	empty_rq_timeout_count;
146331766Sken	uint32_t	dropped_frames_due_to_no_xri_count;
147331766Sken	uint32_t	empty_xri_pool_count;
148331766Sken} ocs_xport_host_stats_t;
149331766Sken
150331766Skentypedef struct ocs_xport_host_statistics_s {
151331766Sken	ocs_sem_t semaphore;
152331766Sken	ocs_xport_link_stats_t link_stats;
153331766Sken	ocs_xport_host_stats_t host_stats;
154331766Sken} ocs_xport_host_statistics_t;
155331766Sken
156331766Skentypedef union ocs_xport {
157331766Sken	uint32_t value;
158331766Sken	ocs_xport_host_statistics_t stats;
159331766Sken} ocs_xport_stats_t;
160331766Sken/**
161331766Sken * @brief Transport private values
162331766Sken */
163331766Skenstruct ocs_xport_s {
164331766Sken	ocs_t *ocs;
165331766Sken	uint64_t req_wwpn;			/*<< wwpn requested by user for primary sport */
166331766Sken	uint64_t req_wwnn;			/*<< wwnn requested by user for primary sport */
167331766Sken
168331766Sken	ocs_xport_fcfi_t fcfi[SLI4_MAX_FCFI];
169331766Sken
170331766Sken	/* Nodes */
171331766Sken	uint32_t nodes_count;			/**< number of allocated nodes */
172331766Sken	ocs_node_t **nodes;			/**< array of pointers to nodes */
173331766Sken	ocs_list_t nodes_free_list;		/**< linked list of free nodes */
174331766Sken
175331766Sken	/* Io pool and counts */
176331766Sken	ocs_io_pool_t *io_pool;			/**< pointer to IO pool */
177331766Sken	ocs_atomic_t io_alloc_failed_count;	/**< used to track how often IO pool is empty */
178331766Sken	ocs_lock_t io_pending_lock;		/**< lock for io_pending_list */
179331766Sken	ocs_list_t io_pending_list;		/**< list of IOs waiting for HW resources
180331766Sken						 **  lock: xport->io_pending_lock
181331766Sken						 **  link: ocs_io_t->io_pending_link
182331766Sken						 */
183331766Sken	ocs_atomic_t io_total_alloc;		/**< count of totals IOS allocated */
184331766Sken	ocs_atomic_t io_total_free;		/**< count of totals IOS free'd */
185331766Sken	ocs_atomic_t io_total_pending;		/**< count of totals IOS that were pended */
186331766Sken	ocs_atomic_t io_active_count;		/**< count of active IOS */
187331766Sken	ocs_atomic_t io_pending_count;		/**< count of pending IOS */
188331766Sken	ocs_atomic_t io_pending_recursing;	/**< non-zero if ocs_scsi_check_pending is executing */
189331766Sken
190331766Sken	/* vport */
191331766Sken	ocs_list_t vport_list;			/**< list of VPORTS (NPIV) */
192331766Sken
193331766Sken	/* Port */
194331766Sken	uint32_t configured_link_state;		/**< requested link state */
195331766Sken
196331766Sken	/* RQ processing threads */
197331766Sken	uint32_t num_rq_threads;
198331766Sken	ocs_xport_rq_thread_info_t *rq_thread_info;
199331766Sken
200331766Sken	ocs_timer_t     stats_timer;            /**< Timer for Statistics */
201331766Sken	ocs_xport_stats_t fc_xport_stats;
202331766Sken};
203331766Sken
204331766Sken
205331766Skenextern ocs_xport_t *ocs_xport_alloc(ocs_t *ocs);
206331766Skenextern int32_t ocs_xport_attach(ocs_xport_t *xport);
207331766Skenextern int32_t ocs_xport_initialize(ocs_xport_t *xport);
208331766Skenextern int32_t ocs_xport_detach(ocs_xport_t *xport);
209331766Skenextern int32_t ocs_xport_control(ocs_xport_t *xport, ocs_xport_ctrl_e cmd, ...);
210331766Skenextern int32_t ocs_xport_status(ocs_xport_t *xport, ocs_xport_status_e cmd, ocs_xport_stats_t *result);
211331766Skenextern void ocs_xport_free(ocs_xport_t *xport);
212331766Sken
213331766Sken#endif
214