xref: /freebsd/sys/dev/ocs_fc/ocs_xport.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1 /*-
2  * Copyright (c) 2017 Broadcom. All rights reserved.
3  * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  *    this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  *    this list of conditions and the following disclaimer in the documentation
13  *    and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /**
33  * @file
34  *
35  */
36 
37 #if !defined(__OCS_XPORT_H__)
38 #define __OCS_XPORT_H__
39 
40 /**
41  * @brief FCFI lookup/pending frames
42  */
43 typedef struct ocs_xport_fcfi_s {
44 	ocs_lock_t	pend_frames_lock;
45 	ocs_list_t	pend_frames;
46 	uint32_t	hold_frames:1;		/*<< hold pending frames */
47 	uint32_t	pend_frames_processed;	/*<< count of pending frames that were processed */
48 } ocs_xport_fcfi_t;
49 
50 /**
51  * @brief Structure to hold the information related to an RQ processing thread used
52  *        to increase 40G performance.
53  */
54 typedef struct ocs_xport_rq_thread_info_s {
55 	ocs_t *ocs;
56 	uint8_t thread_started;
57 	ocs_thread_t thread;
58 	ocs_cbuf_t * seq_cbuf;
59 	char thread_name[64];
60 } ocs_xport_rq_thread_info_t;
61 
62 typedef enum {
63 	OCS_XPORT_PORT_ONLINE=1,
64 	OCS_XPORT_PORT_OFFLINE,
65 	OCS_XPORT_SHUTDOWN,
66 	OCS_XPORT_POST_NODE_EVENT,
67 	OCS_XPORT_WWNN_SET,
68 	OCS_XPORT_WWPN_SET,
69 } ocs_xport_ctrl_e;
70 
71 typedef enum {
72 	OCS_XPORT_PORT_STATUS,
73 	OCS_XPORT_CONFIG_PORT_STATUS,
74 	OCS_XPORT_LINK_SPEED,
75 	OCS_XPORT_IS_SUPPORTED_LINK_SPEED,
76 	OCS_XPORT_LINK_STATISTICS,
77 	OCS_XPORT_LINK_STAT_RESET,
78 	OCS_XPORT_IS_QUIESCED
79 } ocs_xport_status_e;
80 
81 typedef struct ocs_xport_link_stats_s {
82 	uint32_t	rec:1,
83 				gec:1,
84 				w02of:1,
85 				w03of:1,
86 				w04of:1,
87 				w05of:1,
88 				w06of:1,
89 				w07of:1,
90 				w08of:1,
91 				w09of:1,
92 				w10of:1,
93 				w11of:1,
94 				w12of:1,
95 				w13of:1,
96 				w14of:1,
97 				w15of:1,
98 				w16of:1,
99 				w17of:1,
100 				w18of:1,
101 				w19of:1,
102 				w20of:1,
103 				w21of:1,
104 				resv0:8,
105 				clrc:1,
106 				clof:1;
107 	uint32_t	link_failure_error_count;
108 	uint32_t	loss_of_sync_error_count;
109 	uint32_t	loss_of_signal_error_count;
110 	uint32_t	primitive_sequence_error_count;
111 	uint32_t	invalid_transmission_word_error_count;
112 	uint32_t	crc_error_count;
113 	uint32_t	primitive_sequence_event_timeout_count;
114 	uint32_t	elastic_buffer_overrun_error_count;
115 	uint32_t	arbitration_fc_al_timout_count;
116 	uint32_t	advertised_receive_bufftor_to_buffer_credit;
117 	uint32_t	current_receive_buffer_to_buffer_credit;
118 	uint32_t	advertised_transmit_buffer_to_buffer_credit;
119 	uint32_t	current_transmit_buffer_to_buffer_credit;
120 	uint32_t	received_eofa_count;
121 	uint32_t	received_eofdti_count;
122 	uint32_t	received_eofni_count;
123 	uint32_t	received_soff_count;
124 	uint32_t	received_dropped_no_aer_count;
125 	uint32_t	received_dropped_no_available_rpi_resources_count;
126 	uint32_t	received_dropped_no_available_xri_resources_count;
127 } ocs_xport_link_stats_t;
128 
129 typedef struct ocs_xport_host_stats_s {
130 	uint32_t	cc:1,
131 				  :31;
132 	uint32_t	transmit_kbyte_count;
133 	uint32_t	receive_kbyte_count;
134 	uint32_t	transmit_frame_count;
135 	uint32_t	receive_frame_count;
136 	uint32_t	transmit_sequence_count;
137 	uint32_t	receive_sequence_count;
138 	uint32_t	total_exchanges_originator;
139 	uint32_t	total_exchanges_responder;
140 	uint32_t	receive_p_bsy_count;
141 	uint32_t	receive_f_bsy_count;
142 	uint32_t	dropped_frames_due_to_no_rq_buffer_count;
143 	uint32_t	empty_rq_timeout_count;
144 	uint32_t	dropped_frames_due_to_no_xri_count;
145 	uint32_t	empty_xri_pool_count;
146 } ocs_xport_host_stats_t;
147 
148 typedef struct ocs_xport_host_statistics_s {
149 	ocs_sem_t semaphore;
150 	ocs_xport_link_stats_t link_stats;
151 	ocs_xport_host_stats_t host_stats;
152 } ocs_xport_host_statistics_t;
153 
154 typedef union ocs_xport {
155 	uint32_t value;
156 	ocs_xport_host_statistics_t stats;
157 } ocs_xport_stats_t;
158 /**
159  * @brief Transport private values
160  */
161 struct ocs_xport_s {
162 	ocs_t *ocs;
163 	uint64_t req_wwpn;			/*<< wwpn requested by user for primary sport */
164 	uint64_t req_wwnn;			/*<< wwnn requested by user for primary sport */
165 
166 	ocs_xport_fcfi_t fcfi[SLI4_MAX_FCFI];
167 
168 	/* Nodes */
169 	uint32_t nodes_count;			/**< number of allocated nodes */
170 	ocs_node_t **nodes;			/**< array of pointers to nodes */
171 	ocs_list_t nodes_free_list;		/**< linked list of free nodes */
172 
173 	/* Io pool and counts */
174 	ocs_io_pool_t *io_pool;			/**< pointer to IO pool */
175 	ocs_atomic_t io_alloc_failed_count;	/**< used to track how often IO pool is empty */
176 	ocs_lock_t io_pending_lock;		/**< lock for io_pending_list */
177 	ocs_list_t io_pending_list;		/**< list of IOs waiting for HW resources
178 						 **  lock: xport->io_pending_lock
179 						 **  link: ocs_io_t->io_pending_link
180 						 */
181 	ocs_atomic_t io_total_alloc;		/**< count of totals IOS allocated */
182 	ocs_atomic_t io_total_free;		/**< count of totals IOS free'd */
183 	ocs_atomic_t io_total_pending;		/**< count of totals IOS that were pended */
184 	ocs_atomic_t io_active_count;		/**< count of active IOS */
185 	ocs_atomic_t io_pending_count;		/**< count of pending IOS */
186 	ocs_atomic_t io_pending_recursing;	/**< non-zero if ocs_scsi_check_pending is executing */
187 
188 	/* vport */
189 	ocs_list_t vport_list;			/**< list of VPORTS (NPIV) */
190 
191 	/* Port */
192 	uint32_t configured_link_state;		/**< requested link state */
193 
194 	/* RQ processing threads */
195 	uint32_t num_rq_threads;
196 	ocs_xport_rq_thread_info_t *rq_thread_info;
197 
198 	ocs_timer_t     stats_timer;            /**< Timer for Statistics */
199 	ocs_xport_stats_t fc_xport_stats;
200 };
201 
202 extern ocs_xport_t *ocs_xport_alloc(ocs_t *ocs);
203 extern int32_t ocs_xport_attach(ocs_xport_t *xport);
204 extern int32_t ocs_xport_initialize(ocs_xport_t *xport);
205 extern int32_t ocs_xport_detach(ocs_xport_t *xport);
206 extern int32_t ocs_xport_control(ocs_xport_t *xport, ocs_xport_ctrl_e cmd, ...);
207 extern int32_t ocs_xport_status(ocs_xport_t *xport, ocs_xport_status_e cmd, ocs_xport_stats_t *result);
208 extern void ocs_xport_free(ocs_xport_t *xport);
209 
210 #endif
211