xref: /freebsd/sys/dev/ocs_fc/ocs_drv_fc.h (revision b0d29bc47dba79f6f38e67eabadfb4b32ffd9390)
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  * OCS linux driver common include file
37  */
38 
39 
40 #if !defined(__OCS_DRV_FC_H__)
41 #define __OCS_DRV_FC_H__
42 
43 #define OCS_INCLUDE_FC
44 
45 #include "ocs_os.h"
46 #include "ocs_debug.h"
47 #include "ocs_common.h"
48 #include "ocs_hw.h"
49 #include "ocs_io.h"
50 #include "ocs_pm.h"
51 #include "ocs_xport.h"
52 #include "ocs_stats.h"
53 
54 struct ocs_s {
55 
56 	ocs_os_t ocs_os;
57 	char display_name[OCS_DISPLAY_NAME_LENGTH];
58 	ocs_rlock_t lock;			/*>> Device wide lock */
59 	ocs_list_t domain_list;			/*>> linked list of virtual fabric objects */
60 	ocs_io_pool_t *io_pool;			/**< pointer to IO pool */
61 	ocs_ramlog_t *ramlog;
62 	ocs_drv_t drv_ocs;
63 	ocs_scsi_tgt_t tgt_ocs;
64 	ocs_scsi_ini_t ini_ocs;
65 	ocs_xport_e ocs_xport;
66 	ocs_xport_t *xport;			/*>> Pointer to transport object */
67 	bool enable_ini;
68 	bool enable_tgt;
69 	uint8_t fc_type;
70 	int ctrlmask;
71 	int logmask;
72 	uint32_t max_isr_time_msec;		/*>> Maximum ISR time */
73 	char *hw_war_version;
74 	ocs_pm_context_t pm_context;		/*<< power management context */
75 	ocs_mgmt_functions_t *mgmt_functions;
76 	ocs_mgmt_functions_t *tgt_mgmt_functions;
77 	ocs_mgmt_functions_t *ini_mgmt_functions;
78 	ocs_err_injection_e err_injection;	/**< for error injection testing */
79 	uint32_t cmd_err_inject;		/**< specific cmd to inject error into */
80 	time_t delay_value_msec;		/**< for injecting delays */
81 
82 	const char *desc;
83 	uint32_t instance_index;
84 	uint16_t pci_vendor;
85 	uint16_t pci_device;
86 	uint16_t pci_subsystem_vendor;
87 	uint16_t pci_subsystem_device;
88 	char businfo[OCS_DISPLAY_BUS_INFO_LENGTH];
89 
90 	const char *model;
91 	const char *driver_version;
92 	const char *fw_version;
93 
94 	ocs_hw_t hw;
95 
96 	ocs_domain_t *domain;			/*>> pointer to first (physical) domain (also on domain_list) */
97 	uint32_t domain_instance_count;			/*>> domain instance count */
98 	void (*domain_list_empty_cb)(ocs_t *ocs, void *arg); /*>> domain list empty callback */
99 	void *domain_list_empty_cb_arg;                 /*>> domain list empty callback argument */
100 
101 	bool explicit_buffer_list;
102 	bool external_loopback;
103 	uint32_t num_vports;
104 	uint32_t hw_bounce;
105 	uint32_t rq_threads;
106 	uint32_t rq_selection_policy;
107 	uint32_t rr_quanta;
108 	char *filter_def;
109 	uint32_t max_remote_nodes;
110 
111 	bool soft_wwn_enable;
112 
113 	/*
114 	 * tgt_rscn_delay - delay in kicking off RSCN processing (nameserver queries)
115 	 * after receiving an RSCN on the target. This prevents thrashing of nameserver
116 	 * requests due to a huge burst of RSCNs received in a short period of time
117 	 * Note: this is only valid when target RSCN handling is enabled -- see ctrlmask.
118 	 */
119 	time_t tgt_rscn_delay_msec;		/*>> minimum target RSCN delay */
120 
121 	/*
122 	 * tgt_rscn_period - determines maximum frequency when processing back-to-back
123 	 * RSCNs; e.g. if this value is 30, there will never be any more than 1 RSCN
124 	 * handling per 30s window. This prevents initiators on a faulty link generating
125 	 * many RSCN from causing the target to continually query the nameserver. Note:
126 	 * this is only valid when target RSCN handling is enabled
127 	 */
128 	time_t tgt_rscn_period_msec;		/*>> minimum target RSCN period */
129 
130 	/*
131 	 * Target IO timer value:
132 	 * Zero: target command timeout disabled.
133 	 * Non-zero: Timeout value, in seconds, for target commands
134 	 */
135 	uint32_t target_io_timer_sec;
136 
137 	int speed;
138 	int topology;
139 	int ethernet_license;
140 	int num_scsi_ios;
141 	bool enable_hlm;			/*>> high login mode is enabled */
142 	uint32_t hlm_group_size;		/*>> RPI count for high login mode */
143 	char *wwn_bump;
144 	uint32_t nodedb_mask;			/*>> Node debugging mask */
145 
146 	uint32_t auto_xfer_rdy_size;		/*>> Maximum sized write to use auto xfer rdy */
147         bool  esoc;
148 	uint8_t ocs_req_fw_upgrade;
149 
150 	ocs_textbuf_t ddump_saved;
151 
152 };
153 
154 #define ocs_is_fc_initiator_enabled()	(ocs->enable_ini)
155 #define ocs_is_fc_target_enabled()	(ocs->enable_tgt)
156 
157 static inline void
158 ocs_device_lock_init(ocs_t *ocs)
159 {
160 	ocs_rlock_init(ocs, &ocs->lock, "ocsdevicelock");
161 }
162 static inline void
163 ocs_device_lock_free(ocs_t *ocs)
164 {
165 	ocs_rlock_free(&ocs->lock);
166 }
167 static inline int32_t
168 ocs_device_lock_try(ocs_t *ocs)
169 {
170 	return ocs_rlock_try(&ocs->lock);
171 }
172 static inline void
173 ocs_device_lock(ocs_t *ocs)
174 {
175 	ocs_rlock_acquire(&ocs->lock);
176 }
177 static inline void
178 ocs_device_unlock(ocs_t *ocs)
179 {
180 	ocs_rlock_release(&ocs->lock);
181 }
182 
183 extern ocs_t *ocs_get_instance(uint32_t index);
184 extern int32_t ocs_get_bus_dev_func(ocs_t *ocs, uint8_t* bus, uint8_t* dev, uint8_t* func);
185 
186 static inline ocs_io_t *
187 ocs_io_alloc(ocs_t *ocs)
188 {
189 	return ocs_io_pool_io_alloc(ocs->xport->io_pool);
190 }
191 
192 static inline void
193 ocs_io_free(ocs_t *ocs, ocs_io_t *io)
194 {
195 	ocs_io_pool_io_free(ocs->xport->io_pool, io);
196 }
197 
198 extern void ocs_stop_event_processing(ocs_os_t *ocs_os);
199 extern int32_t ocs_start_event_processing(ocs_os_t *ocs_os);
200 
201 #include "ocs_domain.h"
202 #include "ocs_sport.h"
203 #include "ocs_node.h"
204 #include "ocs_io.h"
205 #include "ocs_unsol.h"
206 #include "ocs_scsi.h"
207 
208 #include "ocs_ioctl.h"
209 #include "ocs_elxu.h"
210 
211 
212 #endif
213