xref: /freebsd/sys/dev/ocs_fc/ocs_xport.h (revision 848ee2a3a8b47c9905fc51fefcf60eb371edbb98)
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  * $FreeBSD$
32  */
33 
34 /**
35  * @file
36  *
37  */
38 
39 #if !defined(__OCS_XPORT_H__)
40 #define __OCS_XPORT_H__
41 
42 /**
43  * @brief FCFI lookup/pending frames
44  */
45 typedef struct ocs_xport_fcfi_s {
46 	ocs_lock_t	pend_frames_lock;
47 	ocs_list_t	pend_frames;
48 	uint32_t	hold_frames:1;		/*<< hold pending frames */
49 	uint32_t	pend_frames_processed;	/*<< count of pending frames that were processed */
50 } ocs_xport_fcfi_t;
51 
52 /**
53  * @brief Structure to hold the information related to an RQ processing thread used
54  *        to increase 40G performance.
55  */
56 typedef struct ocs_xport_rq_thread_info_s {
57 	ocs_t *ocs;
58 	uint8_t thread_started;
59 	ocs_thread_t thread;
60 	ocs_cbuf_t * seq_cbuf;
61 	char thread_name[64];
62 } ocs_xport_rq_thread_info_t;
63 
64 typedef enum {
65 	OCS_XPORT_PORT_ONLINE=1,
66 	OCS_XPORT_PORT_OFFLINE,
67 	OCS_XPORT_SHUTDOWN,
68 	OCS_XPORT_POST_NODE_EVENT,
69 	OCS_XPORT_WWNN_SET,
70 	OCS_XPORT_WWPN_SET,
71 } ocs_xport_ctrl_e;
72 
73 typedef enum {
74 	OCS_XPORT_PORT_STATUS,
75 	OCS_XPORT_CONFIG_PORT_STATUS,
76 	OCS_XPORT_LINK_SPEED,
77 	OCS_XPORT_IS_SUPPORTED_LINK_SPEED,
78 	OCS_XPORT_LINK_STATISTICS,
79 	OCS_XPORT_LINK_STAT_RESET,
80 	OCS_XPORT_IS_QUIESCED
81 } ocs_xport_status_e;
82 
83 typedef struct ocs_xport_link_stats_s {
84 	uint32_t	rec:1,
85 				gec:1,
86 				w02of:1,
87 				w03of:1,
88 				w04of:1,
89 				w05of:1,
90 				w06of:1,
91 				w07of:1,
92 				w08of:1,
93 				w09of:1,
94 				w10of:1,
95 				w11of:1,
96 				w12of:1,
97 				w13of:1,
98 				w14of:1,
99 				w15of:1,
100 				w16of:1,
101 				w17of:1,
102 				w18of:1,
103 				w19of:1,
104 				w20of:1,
105 				w21of:1,
106 				resv0:8,
107 				clrc:1,
108 				clof:1;
109 	uint32_t	link_failure_error_count;
110 	uint32_t	loss_of_sync_error_count;
111 	uint32_t	loss_of_signal_error_count;
112 	uint32_t	primitive_sequence_error_count;
113 	uint32_t	invalid_transmission_word_error_count;
114 	uint32_t	crc_error_count;
115 	uint32_t	primitive_sequence_event_timeout_count;
116 	uint32_t	elastic_buffer_overrun_error_count;
117 	uint32_t	arbitration_fc_al_timout_count;
118 	uint32_t	advertised_receive_bufftor_to_buffer_credit;
119 	uint32_t	current_receive_buffer_to_buffer_credit;
120 	uint32_t	advertised_transmit_buffer_to_buffer_credit;
121 	uint32_t	current_transmit_buffer_to_buffer_credit;
122 	uint32_t	received_eofa_count;
123 	uint32_t	received_eofdti_count;
124 	uint32_t	received_eofni_count;
125 	uint32_t	received_soff_count;
126 	uint32_t	received_dropped_no_aer_count;
127 	uint32_t	received_dropped_no_available_rpi_resources_count;
128 	uint32_t	received_dropped_no_available_xri_resources_count;
129 } ocs_xport_link_stats_t;
130 
131 typedef struct ocs_xport_host_stats_s {
132 	uint32_t	cc:1,
133 				  :31;
134 	uint32_t	transmit_kbyte_count;
135 	uint32_t	receive_kbyte_count;
136 	uint32_t	transmit_frame_count;
137 	uint32_t	receive_frame_count;
138 	uint32_t	transmit_sequence_count;
139 	uint32_t	receive_sequence_count;
140 	uint32_t	total_exchanges_originator;
141 	uint32_t	total_exchanges_responder;
142 	uint32_t	receive_p_bsy_count;
143 	uint32_t	receive_f_bsy_count;
144 	uint32_t	dropped_frames_due_to_no_rq_buffer_count;
145 	uint32_t	empty_rq_timeout_count;
146 	uint32_t	dropped_frames_due_to_no_xri_count;
147 	uint32_t	empty_xri_pool_count;
148 } ocs_xport_host_stats_t;
149 
150 typedef struct ocs_xport_host_statistics_s {
151 	ocs_sem_t semaphore;
152 	ocs_xport_link_stats_t link_stats;
153 	ocs_xport_host_stats_t host_stats;
154 } ocs_xport_host_statistics_t;
155 
156 typedef union ocs_xport {
157 	uint32_t value;
158 	ocs_xport_host_statistics_t stats;
159 } ocs_xport_stats_t;
160 /**
161  * @brief Transport private values
162  */
163 struct ocs_xport_s {
164 	ocs_t *ocs;
165 	uint64_t req_wwpn;			/*<< wwpn requested by user for primary sport */
166 	uint64_t req_wwnn;			/*<< wwnn requested by user for primary sport */
167 
168 	ocs_xport_fcfi_t fcfi[SLI4_MAX_FCFI];
169 
170 	/* Nodes */
171 	uint32_t nodes_count;			/**< number of allocated nodes */
172 	ocs_node_t **nodes;			/**< array of pointers to nodes */
173 	ocs_list_t nodes_free_list;		/**< linked list of free nodes */
174 
175 	/* Io pool and counts */
176 	ocs_io_pool_t *io_pool;			/**< pointer to IO pool */
177 	ocs_atomic_t io_alloc_failed_count;	/**< used to track how often IO pool is empty */
178 	ocs_lock_t io_pending_lock;		/**< lock for io_pending_list */
179 	ocs_list_t io_pending_list;		/**< list of IOs waiting for HW resources
180 						 **  lock: xport->io_pending_lock
181 						 **  link: ocs_io_t->io_pending_link
182 						 */
183 	ocs_atomic_t io_total_alloc;		/**< count of totals IOS allocated */
184 	ocs_atomic_t io_total_free;		/**< count of totals IOS free'd */
185 	ocs_atomic_t io_total_pending;		/**< count of totals IOS that were pended */
186 	ocs_atomic_t io_active_count;		/**< count of active IOS */
187 	ocs_atomic_t io_pending_count;		/**< count of pending IOS */
188 	ocs_atomic_t io_pending_recursing;	/**< non-zero if ocs_scsi_check_pending is executing */
189 
190 	/* vport */
191 	ocs_list_t vport_list;			/**< list of VPORTS (NPIV) */
192 
193 	/* Port */
194 	uint32_t configured_link_state;		/**< requested link state */
195 
196 	/* RQ processing threads */
197 	uint32_t num_rq_threads;
198 	ocs_xport_rq_thread_info_t *rq_thread_info;
199 
200 	ocs_timer_t     stats_timer;            /**< Timer for Statistics */
201 	ocs_xport_stats_t fc_xport_stats;
202 };
203 
204 extern ocs_xport_t *ocs_xport_alloc(ocs_t *ocs);
205 extern int32_t ocs_xport_attach(ocs_xport_t *xport);
206 extern int32_t ocs_xport_initialize(ocs_xport_t *xport);
207 extern int32_t ocs_xport_detach(ocs_xport_t *xport);
208 extern int32_t ocs_xport_control(ocs_xport_t *xport, ocs_xport_ctrl_e cmd, ...);
209 extern int32_t ocs_xport_status(ocs_xport_t *xport, ocs_xport_status_e cmd, ocs_xport_stats_t *result);
210 extern void ocs_xport_free(ocs_xport_t *xport);
211 
212 #endif
213