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