1109998Smarkm/*- 2109998Smarkm * Copyright (c) 2017 Broadcom. All rights reserved. 3109998Smarkm * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries. 4109998Smarkm * 5109998Smarkm * Redistribution and use in source and binary forms, with or without 6109998Smarkm * modification, are permitted provided that the following conditions are met: 7109998Smarkm * 8109998Smarkm * 1. Redistributions of source code must retain the above copyright notice, 9109998Smarkm * this list of conditions and the following disclaimer. 10109998Smarkm * 11109998Smarkm * 2. Redistributions in binary form must reproduce the above copyright notice, 12109998Smarkm * this list of conditions and the following disclaimer in the documentation 13109998Smarkm * and/or other materials provided with the distribution. 14109998Smarkm * 15109998Smarkm * 3. Neither the name of the copyright holder nor the names of its contributors 16109998Smarkm * may be used to endorse or promote products derived from this software 17109998Smarkm * without specific prior written permission. 18109998Smarkm * 19109998Smarkm * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20109998Smarkm * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21109998Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22109998Smarkm * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23109998Smarkm * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24109998Smarkm * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25109998Smarkm * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26109998Smarkm * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27109998Smarkm * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28109998Smarkm * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29109998Smarkm * POSSIBILITY OF SUCH DAMAGE. 30109998Smarkm */ 31109998Smarkm 32109998Smarkm/** 33109998Smarkm * @file 34109998Smarkm * OCS bsd driver common include file 35109998Smarkm */ 36109998Smarkm 37109998Smarkm#if !defined(__OCS_H__) 38109998Smarkm#define __OCS_H__ 39109998Smarkm 40109998Smarkm#include "ocs_os.h" 41109998Smarkm#include "ocs_utils.h" 42109998Smarkm 43109998Smarkm#include "ocs_hw.h" 44109998Smarkm#include "ocs_scsi.h" 45109998Smarkm#include "ocs_io.h" 46109998Smarkm 47109998Smarkm#include "version.h" 48109998Smarkm 49109998Smarkm#define DRV_NAME "ocs_fc" 50109998Smarkm#define DRV_VERSION \ 51109998Smarkm STR_BE_MAJOR "." STR_BE_MINOR "." STR_BE_BUILD "." STR_BE_BRANCH 52109998Smarkm 53109998Smarkm/** 54109998Smarkm * @brief Interrupt context 55109998Smarkm */ 56109998Smarkmtypedef struct ocs_intr_ctx_s { 57109998Smarkm uint32_t vec; /** Zero based interrupt vector */ 58109998Smarkm void *softc; /** software context for interrupt */ 59109998Smarkm char name[64]; /** label for this context */ 60109998Smarkm} ocs_intr_ctx_t; 61109998Smarkm 62109998Smarkmtypedef struct ocs_fc_rport_db_s { 63109998Smarkm uint32_t node_id; 64109998Smarkm uint32_t state; 65109998Smarkm uint32_t port_id; 66109998Smarkm uint64_t wwnn; 67109998Smarkm uint64_t wwpn; 68109998Smarkm uint32_t gone_timer; 69109998Smarkm} ocs_fc_target_t; 70109998Smarkm 71109998Smarkm#define OCS_TGT_STATE_NONE 0 /* Empty DB slot */ 72109998Smarkm#define OCS_TGT_STATE_VALID 1 /* Valid*/ 73109998Smarkm#define OCS_TGT_STATE_LOST 2 /* LOST*/ 74109998Smarkm 75109998Smarkmtypedef struct ocs_fcport_s { 76109998Smarkm ocs_t *ocs; 77109998Smarkm struct cam_sim *sim; 78109998Smarkm struct cam_path *path; 79109998Smarkm uint32_t role; 80109998Smarkm uint32_t fc_id; 81109998Smarkm 82109998Smarkm ocs_fc_target_t tgt[OCS_MAX_TARGETS]; 83109998Smarkm int lost_device_time; 84109998Smarkm struct callout ldt; /* device lost timer */ 85109998Smarkm struct task ltask; 86109998Smarkm 87109998Smarkm ocs_tgt_resource_t targ_rsrc_wildcard; 88109998Smarkm ocs_tgt_resource_t targ_rsrc[OCS_MAX_LUN]; 89109998Smarkm ocs_vport_spec_t *vport; 90109998Smarkm} ocs_fcport; 91109998Smarkm 92109998Smarkm#define FCPORT(ocs, chan) (&((ocs_fcport *)(ocs)->fcports)[(chan)]) 93109998Smarkm 94109998Smarkm/** 95109998Smarkm * @brief Driver's context 96109998Smarkm */ 97109998Smarkm 98109998Smarkmstruct ocs_softc { 99109998Smarkm device_t dev; 100109998Smarkm struct cdev *cdev; 101109998Smarkm 102109998Smarkm ocs_pci_reg_t reg[PCI_MAX_BAR]; 103109998Smarkm 104109998Smarkm uint32_t instance_index; 105109998Smarkm const char *desc; 106109998Smarkm 107127128Snectar uint32_t irqid; 108127128Snectar struct resource *irq; 109127128Snectar void *tag; 110127128Snectar 111127128Snectar ocs_intr_ctx_t intr_ctx; 112127128Snectar uint32_t n_vec; 113109998Smarkm 114109998Smarkm bus_dma_tag_t dmat; /** Parent DMA tag */ 115109998Smarkm bus_dma_tag_t buf_dmat;/** IO buffer DMA tag */ 116109998Smarkm char display_name[OCS_DISPLAY_NAME_LENGTH]; 117109998Smarkm uint16_t pci_vendor; 118109998Smarkm uint16_t pci_device; 119109998Smarkm uint16_t pci_subsystem_vendor; 120109998Smarkm uint16_t pci_subsystem_device; 121109998Smarkm char businfo[16]; 122109998Smarkm const char *driver_version; 123109998Smarkm const char *fw_version; 124109998Smarkm const char *model; 125109998Smarkm 126109998Smarkm ocs_hw_t hw; 127109998Smarkm 128109998Smarkm ocs_rlock_t lock; /**< device wide lock */ 129109998Smarkm 130109998Smarkm ocs_xport_e ocs_xport; 131109998Smarkm ocs_xport_t *xport; /**< pointer to transport object */ 132109998Smarkm ocs_domain_t *domain; 133109998Smarkm ocs_list_t domain_list; 134109998Smarkm uint32_t domain_instance_count; 135109998Smarkm void (*domain_list_empty_cb)(ocs_t *ocs, void *arg); 136109998Smarkm void *domain_list_empty_cb_arg; 137109998Smarkm 138109998Smarkm uint8_t enable_ini; 139109998Smarkm uint8_t enable_tgt; 140109998Smarkm uint8_t fc_type; 141109998Smarkm int ctrlmask; 142109998Smarkm uint8_t explicit_buffer_list; 143109998Smarkm uint8_t external_loopback; 144127128Snectar uint8_t skip_hw_teardown; 145109998Smarkm int speed; 146109998Smarkm int topology; 147109998Smarkm int ethernet_license; 148109998Smarkm int num_scsi_ios; 149109998Smarkm uint8_t enable_hlm; 150109998Smarkm uint32_t hlm_group_size; 151109998Smarkm uint32_t max_isr_time_msec; /*>> Maximum ISR time */ 152109998Smarkm uint32_t auto_xfer_rdy_size; /*>> Max sized write to use auto xfer rdy*/ 153109998Smarkm uint8_t esoc; 154109998Smarkm int logmask; 155109998Smarkm char *hw_war_version; 156109998Smarkm uint32_t num_vports; 157109998Smarkm uint32_t target_io_timer_sec; 158109998Smarkm uint32_t hw_bounce; 159109998Smarkm uint8_t rq_threads; 160109998Smarkm uint8_t rq_selection_policy; 161109998Smarkm uint8_t rr_quanta; 162109998Smarkm char *filter_def; 163109998Smarkm uint32_t max_remote_nodes; 164109998Smarkm 165109998Smarkm /* 166109998Smarkm * tgt_rscn_delay - delay in kicking off RSCN processing 167127128Snectar * (nameserver queries) after receiving an RSCN on the target. 168109998Smarkm * This prevents thrashing of nameserver requests due to a huge burst of 169109998Smarkm * RSCNs received in a short period of time. 170 * Note: this is only valid when target RSCN handling is enabled -- see 171 * ctrlmask. 172 */ 173 time_t tgt_rscn_delay_msec; /*>> minimum target RSCN delay */ 174 175 /* 176 * tgt_rscn_period - determines maximum frequency when processing 177 * back-to-back RSCNs; e.g. if this value is 30, there will never be 178 * any more than 1 RSCN handling per 30s window. This prevents 179 * initiators on a faulty link generating many RSCN from causing the 180 * target to continually query the nameserver. 181 * Note: This is only valid when target RSCN handling is enabled 182 */ 183 time_t tgt_rscn_period_msec; /*>> minimum target RSCN period */ 184 185 uint32_t enable_task_set_full; 186 uint32_t io_in_use; 187 uint32_t io_high_watermark; /**< used to send task set full */ 188 struct mtx sim_lock; 189 uint32_t config_tgt:1, /**< Configured to support target mode */ 190 config_ini:1; /**< Configured to support initiator mode */ 191 192 uint32_t nodedb_mask; /**< Node debugging mask */ 193 194 char modeldesc[64]; 195 char serialnum[64]; 196 char fwrev[64]; 197 char sli_intf[9]; 198 199 ocs_ramlog_t *ramlog; 200 ocs_textbuf_t ddump_saved; 201 202 ocs_mgmt_functions_t *mgmt_functions; 203 ocs_mgmt_functions_t *tgt_mgmt_functions; 204 ocs_mgmt_functions_t *ini_mgmt_functions; 205 206 ocs_err_injection_e err_injection; 207 uint32_t cmd_err_inject; 208 time_t delay_value_msec; 209 210 bool attached; 211 struct mtx dbg_lock; 212 213 struct cam_devq *devq; 214 ocs_fcport *fcports; 215 216 void* tgt_ocs; 217}; 218 219static inline void 220ocs_device_lock_init(ocs_t *ocs) 221{ 222 ocs_rlock_init(ocs, &ocs->lock, "ocsdevicelock"); 223} 224 225static inline int32_t 226ocs_device_lock_try(ocs_t *ocs) 227{ 228 return ocs_rlock_try(&ocs->lock); 229} 230 231static inline void 232ocs_device_lock(ocs_t *ocs) 233{ 234 ocs_rlock_acquire(&ocs->lock); 235} 236 237static inline void 238ocs_device_unlock(ocs_t *ocs) 239{ 240 ocs_rlock_release(&ocs->lock); 241} 242 243static inline void 244ocs_device_lock_free(ocs_t *ocs) 245{ 246 ocs_rlock_free(&ocs->lock); 247} 248 249extern int32_t ocs_device_detach(ocs_t *ocs); 250 251extern int32_t ocs_device_attach(ocs_t *ocs); 252 253#define ocs_is_initiator_enabled() (ocs->enable_ini) 254#define ocs_is_target_enabled() (ocs->enable_tgt) 255 256#include "ocs_xport.h" 257#include "ocs_domain.h" 258#include "ocs_sport.h" 259#include "ocs_node.h" 260#include "ocs_unsol.h" 261#include "ocs_scsi.h" 262#include "ocs_ioctl.h" 263 264static inline ocs_io_t * 265ocs_io_alloc(ocs_t *ocs) 266{ 267 return ocs_io_pool_io_alloc(ocs->xport->io_pool); 268} 269 270static inline void 271ocs_io_free(ocs_t *ocs, ocs_io_t *io) 272{ 273 ocs_io_pool_io_free(ocs->xport->io_pool, io); 274} 275 276#endif /* __OCS_H__ */ 277