1331766Sken/*- 2331766Sken * Copyright (c) 2017 Broadcom. All rights reserved. 3331766Sken * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries. 4331766Sken * 5331766Sken * Redistribution and use in source and binary forms, with or without 6331766Sken * modification, are permitted provided that the following conditions are met: 7331766Sken * 8331766Sken * 1. Redistributions of source code must retain the above copyright notice, 9331766Sken * this list of conditions and the following disclaimer. 10331766Sken * 11331766Sken * 2. Redistributions in binary form must reproduce the above copyright notice, 12331766Sken * this list of conditions and the following disclaimer in the documentation 13331766Sken * and/or other materials provided with the distribution. 14331766Sken * 15331766Sken * 3. Neither the name of the copyright holder nor the names of its contributors 16331766Sken * may be used to endorse or promote products derived from this software 17331766Sken * without specific prior written permission. 18331766Sken * 19331766Sken * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20331766Sken * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21331766Sken * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22331766Sken * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23331766Sken * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24331766Sken * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25331766Sken * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26331766Sken * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27331766Sken * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28331766Sken * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29331766Sken * POSSIBILITY OF SUCH DAMAGE. 30331766Sken * 31331766Sken * $FreeBSD: stable/11/sys/dev/ocs_fc/ocs.h 344054 2019-02-12 17:05:59Z ram $ 32331766Sken */ 33331766Sken 34331766Sken/** 35331766Sken * @file 36331766Sken * OCS bsd driver common include file 37331766Sken */ 38331766Sken 39331766Sken 40331766Sken#if !defined(__OCS_H__) 41331766Sken#define __OCS_H__ 42331766Sken 43331766Sken#include "ocs_os.h" 44331766Sken#include "ocs_utils.h" 45331766Sken 46331766Sken#include "ocs_hw.h" 47331766Sken#include "ocs_scsi.h" 48331766Sken#include "ocs_io.h" 49331766Sken 50331766Sken#include "version.h" 51331766Sken 52331766Sken#define DRV_NAME "ocs_fc" 53331766Sken#define DRV_VERSION \ 54331766Sken STR_BE_MAJOR "." STR_BE_MINOR "." STR_BE_BUILD "." STR_BE_BRANCH 55331766Sken 56331766Sken/** 57331766Sken * @brief Interrupt context 58331766Sken */ 59331766Skentypedef struct ocs_intr_ctx_s { 60331766Sken uint32_t vec; /** Zero based interrupt vector */ 61331766Sken void *softc; /** software context for interrupt */ 62331766Sken char name[64]; /** label for this context */ 63331766Sken} ocs_intr_ctx_t; 64331766Sken 65344014Sramtypedef struct ocs_fc_rport_db_s { 66344014Sram uint32_t node_id; 67344014Sram uint32_t state; 68344014Sram uint8_t is_target; 69344014Sram uint8_t is_initiator; 70344014Sram 71344014Sram uint32_t port_id; 72344014Sram uint64_t wwnn; 73344014Sram uint64_t wwpn; 74344014Sram uint32_t gone_timer; 75344014Sram 76344014Sram} ocs_fc_target_t; 77344014Sram 78344014Sram#define OCS_TGT_STATE_NONE 0 /* Empty DB slot */ 79344014Sram#define OCS_TGT_STATE_VALID 1 /* Valid*/ 80344014Sram#define OCS_TGT_STATE_LOST 2 /* LOST*/ 81344014Sram 82331766Skentypedef struct ocs_fcport_s { 83344014Sram ocs_t *ocs; 84344014Sram struct cam_sim *sim; 85344014Sram struct cam_path *path; 86344014Sram uint32_t role; 87344054Sram uint32_t fc_id; 88331766Sken 89344014Sram ocs_fc_target_t tgt[OCS_MAX_TARGETS]; 90344014Sram int lost_device_time; 91344014Sram struct callout ldt; /* device lost timer */ 92344014Sram struct task ltask; 93344014Sram 94344014Sram ocs_tgt_resource_t targ_rsrc_wildcard; 95344014Sram ocs_tgt_resource_t targ_rsrc[OCS_MAX_LUN]; 96331766Sken ocs_vport_spec_t *vport; 97331766Sken} ocs_fcport; 98331766Sken 99331766Sken#define FCPORT(ocs, chan) (&((ocs_fcport *)(ocs)->fcports)[(chan)]) 100331766Sken 101331766Sken/** 102331766Sken * @brief Driver's context 103331766Sken */ 104331766Sken 105331766Skenstruct ocs_softc { 106331766Sken 107331766Sken device_t dev; 108331766Sken struct cdev *cdev; 109331766Sken 110331766Sken ocs_pci_reg_t reg[PCI_MAX_BAR]; 111331766Sken 112331766Sken uint32_t instance_index; 113331766Sken const char *desc; 114331766Sken 115331766Sken uint32_t irqid; 116331766Sken struct resource *irq; 117331766Sken void *tag; 118331766Sken 119331766Sken ocs_intr_ctx_t intr_ctx; 120331766Sken uint32_t n_vec; 121331766Sken 122331766Sken bus_dma_tag_t dmat; /** Parent DMA tag */ 123331766Sken bus_dma_tag_t buf_dmat;/** IO buffer DMA tag */ 124331766Sken char display_name[OCS_DISPLAY_NAME_LENGTH]; 125331766Sken uint16_t pci_vendor; 126331766Sken uint16_t pci_device; 127331766Sken uint16_t pci_subsystem_vendor; 128331766Sken uint16_t pci_subsystem_device; 129331766Sken char businfo[16]; 130331766Sken const char *driver_version; 131331766Sken const char *fw_version; 132331766Sken const char *model; 133331766Sken 134331766Sken ocs_hw_t hw; 135331766Sken 136331766Sken ocs_rlock_t lock; /**< device wide lock */ 137331766Sken 138331766Sken ocs_xport_e ocs_xport; 139331766Sken ocs_xport_t *xport; /**< pointer to transport object */ 140331766Sken ocs_domain_t *domain; 141331766Sken ocs_list_t domain_list; 142331766Sken uint32_t domain_instance_count; 143331766Sken void (*domain_list_empty_cb)(ocs_t *ocs, void *arg); 144331766Sken void *domain_list_empty_cb_arg; 145331766Sken 146331766Sken uint8_t enable_ini; 147331766Sken uint8_t enable_tgt; 148331766Sken uint8_t fc_type; 149331766Sken int ctrlmask; 150331766Sken uint8_t explicit_buffer_list; 151331766Sken uint8_t external_loopback; 152331766Sken uint8_t skip_hw_teardown; 153331766Sken int speed; 154331766Sken int topology; 155331766Sken int ethernet_license; 156331766Sken int num_scsi_ios; 157331766Sken uint8_t enable_hlm; 158331766Sken uint32_t hlm_group_size; 159331766Sken uint32_t max_isr_time_msec; /*>> Maximum ISR time */ 160331766Sken uint32_t auto_xfer_rdy_size; /*>> Max sized write to use auto xfer rdy*/ 161331766Sken uint8_t esoc; 162331766Sken int logmask; 163331766Sken char *hw_war_version; 164331766Sken uint32_t num_vports; 165331766Sken uint32_t target_io_timer_sec; 166331766Sken uint32_t hw_bounce; 167331766Sken uint8_t rq_threads; 168331766Sken uint8_t rq_selection_policy; 169331766Sken uint8_t rr_quanta; 170331766Sken char *filter_def; 171331766Sken uint32_t max_remote_nodes; 172331766Sken 173331766Sken /* 174331766Sken * tgt_rscn_delay - delay in kicking off RSCN processing 175331766Sken * (nameserver queries) after receiving an RSCN on the target. 176331766Sken * This prevents thrashing of nameserver requests due to a huge burst of 177331766Sken * RSCNs received in a short period of time. 178331766Sken * Note: this is only valid when target RSCN handling is enabled -- see 179331766Sken * ctrlmask. 180331766Sken */ 181331766Sken time_t tgt_rscn_delay_msec; /*>> minimum target RSCN delay */ 182331766Sken 183331766Sken /* 184331766Sken * tgt_rscn_period - determines maximum frequency when processing 185331766Sken * back-to-back RSCNs; e.g. if this value is 30, there will never be 186331766Sken * any more than 1 RSCN handling per 30s window. This prevents 187331766Sken * initiators on a faulty link generating many RSCN from causing the 188331766Sken * target to continually query the nameserver. 189331766Sken * Note: This is only valid when target RSCN handling is enabled 190331766Sken */ 191331766Sken time_t tgt_rscn_period_msec; /*>> minimum target RSCN period */ 192331766Sken 193331766Sken uint32_t enable_task_set_full; 194331766Sken uint32_t io_in_use; 195331766Sken uint32_t io_high_watermark; /**< used to send task set full */ 196344014Sram struct mtx sim_lock; 197331766Sken uint32_t config_tgt:1, /**< Configured to support target mode */ 198331766Sken config_ini:1; /**< Configured to support initiator mode */ 199331766Sken 200331766Sken 201331766Sken uint32_t nodedb_mask; /**< Node debugging mask */ 202331766Sken 203331766Sken char modeldesc[64]; 204331766Sken char serialnum[64]; 205331766Sken char fwrev[64]; 206331766Sken char sli_intf[9]; 207331766Sken 208331766Sken ocs_ramlog_t *ramlog; 209331766Sken ocs_textbuf_t ddump_saved; 210331766Sken 211331766Sken ocs_mgmt_functions_t *mgmt_functions; 212331766Sken ocs_mgmt_functions_t *tgt_mgmt_functions; 213331766Sken ocs_mgmt_functions_t *ini_mgmt_functions; 214331766Sken 215331766Sken ocs_err_injection_e err_injection; 216331766Sken uint32_t cmd_err_inject; 217331766Sken time_t delay_value_msec; 218331766Sken 219331766Sken bool attached; 220331766Sken struct mtx dbg_lock; 221331766Sken 222331766Sken struct cam_devq *devq; 223331766Sken ocs_fcport *fcports; 224331766Sken 225331766Sken void* tgt_ocs; 226331766Sken}; 227331766Sken 228331766Skenstatic inline void 229331766Skenocs_device_lock_init(ocs_t *ocs) 230331766Sken{ 231331766Sken ocs_rlock_init(ocs, &ocs->lock, "ocsdevicelock"); 232331766Sken} 233331766Sken 234331766Skenstatic inline int32_t 235331766Skenocs_device_lock_try(ocs_t *ocs) 236331766Sken{ 237331766Sken return ocs_rlock_try(&ocs->lock); 238331766Sken} 239331766Sken 240331766Skenstatic inline void 241331766Skenocs_device_lock(ocs_t *ocs) 242331766Sken{ 243331766Sken ocs_rlock_acquire(&ocs->lock); 244331766Sken} 245331766Sken 246331766Skenstatic inline void 247331766Skenocs_device_unlock(ocs_t *ocs) 248331766Sken{ 249331766Sken ocs_rlock_release(&ocs->lock); 250331766Sken} 251331766Sken 252331766Skenstatic inline void 253331766Skenocs_device_lock_free(ocs_t *ocs) 254331766Sken{ 255331766Sken ocs_rlock_free(&ocs->lock); 256331766Sken} 257331766Sken 258331766Skenextern int32_t ocs_device_detach(ocs_t *ocs); 259331766Sken 260331766Skenextern int32_t ocs_device_attach(ocs_t *ocs); 261331766Sken 262331766Sken#define ocs_is_initiator_enabled() (ocs->enable_ini) 263331766Sken#define ocs_is_target_enabled() (ocs->enable_tgt) 264331766Sken 265331766Sken#include "ocs_xport.h" 266331766Sken#include "ocs_domain.h" 267331766Sken#include "ocs_sport.h" 268331766Sken#include "ocs_node.h" 269331766Sken#include "ocs_unsol.h" 270331766Sken#include "ocs_scsi.h" 271331766Sken#include "ocs_ioctl.h" 272331766Sken 273331766Skenstatic inline ocs_io_t * 274331766Skenocs_io_alloc(ocs_t *ocs) 275331766Sken{ 276331766Sken return ocs_io_pool_io_alloc(ocs->xport->io_pool); 277331766Sken} 278331766Sken 279331766Skenstatic inline void 280331766Skenocs_io_free(ocs_t *ocs, ocs_io_t *io) 281331766Sken{ 282331766Sken ocs_io_pool_io_free(ocs->xport->io_pool, io); 283331766Sken} 284331766Sken 285331766Sken#endif /* __OCS_H__ */ 286