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 bsd driver common include file 37 */ 38 39 40 #if !defined(__OCS_H__) 41 #define __OCS_H__ 42 43 #include "ocs_os.h" 44 #include "ocs_utils.h" 45 46 #include "ocs_hw.h" 47 #include "ocs_scsi.h" 48 #include "ocs_io.h" 49 50 #include "version.h" 51 52 #define DRV_NAME "ocs_fc" 53 #define DRV_VERSION \ 54 STR_BE_MAJOR "." STR_BE_MINOR "." STR_BE_BUILD "." STR_BE_BRANCH 55 56 /** 57 * @brief Interrupt context 58 */ 59 typedef struct ocs_intr_ctx_s { 60 uint32_t vec; /** Zero based interrupt vector */ 61 void *softc; /** software context for interrupt */ 62 char name[64]; /** label for this context */ 63 } ocs_intr_ctx_t; 64 65 typedef struct ocs_fcport_s { 66 struct cam_sim *sim; 67 struct cam_path *path; 68 uint32_t role; 69 70 ocs_tgt_resource_t targ_rsrc_wildcard; 71 ocs_tgt_resource_t targ_rsrc[OCS_MAX_LUN]; 72 ocs_vport_spec_t *vport; 73 } ocs_fcport; 74 75 #define FCPORT(ocs, chan) (&((ocs_fcport *)(ocs)->fcports)[(chan)]) 76 77 /** 78 * @brief Driver's context 79 */ 80 81 struct ocs_softc { 82 83 device_t dev; 84 struct cdev *cdev; 85 86 ocs_pci_reg_t reg[PCI_MAX_BAR]; 87 88 uint32_t instance_index; 89 const char *desc; 90 91 uint32_t irqid; 92 struct resource *irq; 93 void *tag; 94 95 ocs_intr_ctx_t intr_ctx; 96 uint32_t n_vec; 97 98 bus_dma_tag_t dmat; /** Parent DMA tag */ 99 bus_dma_tag_t buf_dmat;/** IO buffer DMA tag */ 100 char display_name[OCS_DISPLAY_NAME_LENGTH]; 101 uint16_t pci_vendor; 102 uint16_t pci_device; 103 uint16_t pci_subsystem_vendor; 104 uint16_t pci_subsystem_device; 105 char businfo[16]; 106 const char *driver_version; 107 const char *fw_version; 108 const char *model; 109 110 ocs_hw_t hw; 111 112 ocs_rlock_t lock; /**< device wide lock */ 113 114 ocs_xport_e ocs_xport; 115 ocs_xport_t *xport; /**< pointer to transport object */ 116 ocs_domain_t *domain; 117 ocs_list_t domain_list; 118 uint32_t domain_instance_count; 119 void (*domain_list_empty_cb)(ocs_t *ocs, void *arg); 120 void *domain_list_empty_cb_arg; 121 122 uint8_t enable_ini; 123 uint8_t enable_tgt; 124 uint8_t fc_type; 125 int ctrlmask; 126 uint8_t explicit_buffer_list; 127 uint8_t external_loopback; 128 uint8_t skip_hw_teardown; 129 int speed; 130 int topology; 131 int ethernet_license; 132 int num_scsi_ios; 133 uint8_t enable_hlm; 134 uint32_t hlm_group_size; 135 uint32_t max_isr_time_msec; /*>> Maximum ISR time */ 136 uint32_t auto_xfer_rdy_size; /*>> Max sized write to use auto xfer rdy*/ 137 uint8_t esoc; 138 int logmask; 139 char *hw_war_version; 140 uint32_t num_vports; 141 uint32_t target_io_timer_sec; 142 uint32_t hw_bounce; 143 uint8_t rq_threads; 144 uint8_t rq_selection_policy; 145 uint8_t rr_quanta; 146 char *filter_def; 147 uint32_t max_remote_nodes; 148 149 /* 150 * tgt_rscn_delay - delay in kicking off RSCN processing 151 * (nameserver queries) after receiving an RSCN on the target. 152 * This prevents thrashing of nameserver requests due to a huge burst of 153 * RSCNs received in a short period of time. 154 * Note: this is only valid when target RSCN handling is enabled -- see 155 * ctrlmask. 156 */ 157 time_t tgt_rscn_delay_msec; /*>> minimum target RSCN delay */ 158 159 /* 160 * tgt_rscn_period - determines maximum frequency when processing 161 * back-to-back RSCNs; e.g. if this value is 30, there will never be 162 * any more than 1 RSCN handling per 30s window. This prevents 163 * initiators on a faulty link generating many RSCN from causing the 164 * target to continually query the nameserver. 165 * Note: This is only valid when target RSCN handling is enabled 166 */ 167 time_t tgt_rscn_period_msec; /*>> minimum target RSCN period */ 168 169 uint32_t enable_task_set_full; 170 uint32_t io_in_use; 171 uint32_t io_high_watermark; /**< used to send task set full */ 172 struct mtx sim_lock; 173 uint32_t config_tgt:1, /**< Configured to support target mode */ 174 config_ini:1; /**< Configured to support initiator mode */ 175 176 177 uint32_t nodedb_mask; /**< Node debugging mask */ 178 179 char modeldesc[64]; 180 char serialnum[64]; 181 char fwrev[64]; 182 char sli_intf[9]; 183 184 ocs_ramlog_t *ramlog; 185 ocs_textbuf_t ddump_saved; 186 187 ocs_mgmt_functions_t *mgmt_functions; 188 ocs_mgmt_functions_t *tgt_mgmt_functions; 189 ocs_mgmt_functions_t *ini_mgmt_functions; 190 191 ocs_err_injection_e err_injection; 192 uint32_t cmd_err_inject; 193 time_t delay_value_msec; 194 195 bool attached; 196 struct mtx dbg_lock; 197 198 struct cam_devq *devq; 199 ocs_fcport *fcports; 200 201 void* tgt_ocs; 202 }; 203 204 static inline void 205 ocs_device_lock_init(ocs_t *ocs) 206 { 207 ocs_rlock_init(ocs, &ocs->lock, "ocsdevicelock"); 208 } 209 210 static inline int32_t 211 ocs_device_lock_try(ocs_t *ocs) 212 { 213 return ocs_rlock_try(&ocs->lock); 214 } 215 216 static inline void 217 ocs_device_lock(ocs_t *ocs) 218 { 219 ocs_rlock_acquire(&ocs->lock); 220 } 221 222 static inline void 223 ocs_device_unlock(ocs_t *ocs) 224 { 225 ocs_rlock_release(&ocs->lock); 226 } 227 228 static inline void 229 ocs_device_lock_free(ocs_t *ocs) 230 { 231 ocs_rlock_free(&ocs->lock); 232 } 233 234 extern int32_t ocs_device_detach(ocs_t *ocs); 235 236 extern int32_t ocs_device_attach(ocs_t *ocs); 237 238 #define ocs_is_initiator_enabled() (ocs->enable_ini) 239 #define ocs_is_target_enabled() (ocs->enable_tgt) 240 241 #include "ocs_xport.h" 242 #include "ocs_domain.h" 243 #include "ocs_sport.h" 244 #include "ocs_node.h" 245 #include "ocs_unsol.h" 246 #include "ocs_scsi.h" 247 #include "ocs_ioctl.h" 248 249 static inline ocs_io_t * 250 ocs_io_alloc(ocs_t *ocs) 251 { 252 return ocs_io_pool_io_alloc(ocs->xport->io_pool); 253 } 254 255 static inline void 256 ocs_io_free(ocs_t *ocs, ocs_io_t *io) 257 { 258 ocs_io_pool_io_free(ocs->xport->io_pool, io); 259 } 260 261 #endif /* __OCS_H__ */ 262