1 /* 2 * Copyright (c) 2017-2018 Cavium, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * POSSIBILITY OF SUCH DAMAGE. 26 * 27 * $FreeBSD$ 28 * 29 */ 30 31 #ifndef __STORAGE_COMMON__ 32 #define __STORAGE_COMMON__ 33 /*********************/ 34 /* SCSI CONSTANTS */ 35 /*********************/ 36 37 38 #define SCSI_MAX_NUM_OF_CMDQS (NUM_OF_GLOBAL_QUEUES / 2) 39 // Each Resource ID is one-one-valued mapped by the driver to a BDQ Resource ID (for instance per port) 40 #define BDQ_NUM_RESOURCES (4) 41 42 // ID 0 : RQ, ID 1 : IMMEDIATE_DATA, ID 2 : TQ 43 #define BDQ_ID_RQ (0) 44 #define BDQ_ID_IMM_DATA (1) 45 #define BDQ_ID_TQ (2) 46 #define BDQ_NUM_IDS (3) 47 48 #define SCSI_NUM_SGES_SLOW_SGL_THR 8 49 50 #define BDQ_MAX_EXTERNAL_RING_SIZE (1<<15) 51 52 /* SCSI op codes */ 53 #define SCSI_OPCODE_COMPARE_AND_WRITE (0x89) 54 #define SCSI_OPCODE_READ_10 (0x28) 55 #define SCSI_OPCODE_WRITE_6 (0x0A) 56 #define SCSI_OPCODE_WRITE_10 (0x2A) 57 #define SCSI_OPCODE_WRITE_12 (0xAA) 58 #define SCSI_OPCODE_WRITE_16 (0x8A) 59 #define SCSI_OPCODE_WRITE_AND_VERIFY_10 (0x2E) 60 #define SCSI_OPCODE_WRITE_AND_VERIFY_12 (0xAE) 61 #define SCSI_OPCODE_WRITE_AND_VERIFY_16 (0x8E) 62 63 /* 64 * iSCSI Drv opaque 65 */ 66 struct iscsi_drv_opaque 67 { 68 __le16 reserved_zero[3]; 69 __le16 opaque; 70 }; 71 72 73 /* 74 * Scsi 2B/8B opaque union 75 */ 76 union scsi_opaque 77 { 78 struct regpair fcoe_opaque /* 8 Bytes opaque */; 79 struct iscsi_drv_opaque iscsi_opaque /* 2 Bytes opaque */; 80 }; 81 82 /* 83 * SCSI buffer descriptor 84 */ 85 struct scsi_bd 86 { 87 struct regpair address /* Physical Address of buffer */; 88 union scsi_opaque opaque /* Driver Metadata (preferably Virtual Address of buffer) */; 89 }; 90 91 92 /* 93 * Scsi Drv BDQ struct 94 */ 95 struct scsi_bdq_ram_drv_data 96 { 97 __le16 external_producer /* BDQ External Producer; updated by driver when it loads BDs to External Ring */; 98 __le16 reserved0[3]; 99 }; 100 101 102 /* 103 * SCSI SGE entry 104 */ 105 struct scsi_sge 106 { 107 struct regpair sge_addr /* SGE address */; 108 __le32 sge_len /* SGE length */; 109 __le32 reserved; 110 }; 111 112 /* 113 * Cached SGEs section 114 */ 115 struct scsi_cached_sges 116 { 117 struct scsi_sge sge[4] /* Cached SGEs section */; 118 }; 119 120 121 /* 122 * Scsi Drv CMDQ struct 123 */ 124 struct scsi_drv_cmdq 125 { 126 __le16 cmdq_cons /* CMDQ consumer - updated by driver when CMDQ is consumed */; 127 __le16 reserved0; 128 __le32 reserved1; 129 }; 130 131 132 /* 133 * Common SCSI init params passed by driver to FW in function init ramrod 134 */ 135 struct scsi_init_func_params 136 { 137 __le16 num_tasks /* Number of tasks in global task list */; 138 u8 log_page_size /* log of page size value */; 139 u8 debug_mode /* Use iscsi_debug_mode enum */; 140 u8 reserved2[12]; 141 }; 142 143 144 /* 145 * SCSI RQ/CQ/CMDQ firmware function init parameters 146 */ 147 struct scsi_init_func_queues 148 { 149 struct regpair glbl_q_params_addr /* Global Qs (CQ/RQ/CMDQ) params host address */; 150 __le16 rq_buffer_size /* The buffer size of RQ BDQ */; 151 __le16 cq_num_entries /* CQ num entries */; 152 __le16 cmdq_num_entries /* CMDQ num entries */; 153 u8 bdq_resource_id /* Each function-init Ramrod maps its funciton ID to a BDQ function ID, each BDQ function ID contains per-BDQ-ID BDQs */; 154 u8 q_validity; 155 #define SCSI_INIT_FUNC_QUEUES_RQ_VALID_MASK 0x1 156 #define SCSI_INIT_FUNC_QUEUES_RQ_VALID_SHIFT 0 157 #define SCSI_INIT_FUNC_QUEUES_IMM_DATA_VALID_MASK 0x1 158 #define SCSI_INIT_FUNC_QUEUES_IMM_DATA_VALID_SHIFT 1 159 #define SCSI_INIT_FUNC_QUEUES_CMD_VALID_MASK 0x1 160 #define SCSI_INIT_FUNC_QUEUES_CMD_VALID_SHIFT 2 161 #define SCSI_INIT_FUNC_QUEUES_TQ_VALID_MASK 0x1 162 #define SCSI_INIT_FUNC_QUEUES_TQ_VALID_SHIFT 3 163 #define SCSI_INIT_FUNC_QUEUES_SOC_EN_MASK 0x1 /* This bit is valid if TQ is enabled for this function, SOC option enabled/disabled */ 164 #define SCSI_INIT_FUNC_QUEUES_SOC_EN_SHIFT 4 165 #define SCSI_INIT_FUNC_QUEUES_SOC_NUM_OF_BLOCKS_LOG_MASK 0x7 /* Relevant for TQe SOC option - num of blocks in SGE - log */ 166 #define SCSI_INIT_FUNC_QUEUES_SOC_NUM_OF_BLOCKS_LOG_SHIFT 5 167 __le16 cq_cmdq_sb_num_arr[SCSI_MAX_NUM_OF_CMDQS] /* CQ/CMDQ status block number array */; 168 u8 num_queues /* Number of continuous global queues used */; 169 u8 queue_relative_offset /* offset of continuous global queues used */; 170 u8 cq_sb_pi /* Protocol Index of CQ in status block (CQ consumer) */; 171 u8 cmdq_sb_pi /* Protocol Index of CMDQ in status block (CMDQ consumer) */; 172 u8 bdq_pbl_num_entries[BDQ_NUM_IDS] /* Per BDQ ID, the PBL page size (number of entries in PBL) */; 173 u8 reserved1 /* reserved */; 174 struct regpair bdq_pbl_base_address[BDQ_NUM_IDS] /* Per BDQ ID, the PBL page Base Address */; 175 __le16 bdq_xoff_threshold[BDQ_NUM_IDS] /* BDQ XOFF threshold - when number of entries will be below that TH, it will send XOFF */; 176 __le16 cmdq_xoff_threshold /* CMDQ XOFF threshold - when number of entries will be below that TH, it will send XOFF */; 177 __le16 bdq_xon_threshold[BDQ_NUM_IDS] /* BDQ XON threshold - when number of entries will be above that TH, it will send XON */; 178 __le16 cmdq_xon_threshold /* CMDQ XON threshold - when number of entries will be above that TH, it will send XON */; 179 }; 180 181 182 183 /* 184 * Scsi Drv BDQ Data struct (2 BDQ IDs: 0 - RQ, 1 - Immediate Data) 185 */ 186 struct scsi_ram_per_bdq_resource_drv_data 187 { 188 struct scsi_bdq_ram_drv_data drv_data_per_bdq_id[BDQ_NUM_IDS] /* External ring data */; 189 }; 190 191 192 193 /* 194 * SCSI SGL types 195 */ 196 enum scsi_sgl_mode 197 { 198 SCSI_TX_SLOW_SGL /* Slow-SGL: More than SCSI_NUM_SGES_SLOW_SGL_THR SGEs and there is at least 1 middle SGE than is smaller than a page size. May be only at TX */, 199 SCSI_FAST_SGL /* Fast SGL: Less than SCSI_NUM_SGES_SLOW_SGL_THR SGEs or all middle SGEs are at least a page size */, 200 MAX_SCSI_SGL_MODE 201 }; 202 203 204 /* 205 * SCSI SGL parameters 206 */ 207 struct scsi_sgl_params 208 { 209 struct regpair sgl_addr /* SGL base address */; 210 __le32 sgl_total_length /* SGL total legnth (bytes) */; 211 __le32 sge_offset /* Offset in SGE (bytes) */; 212 __le16 sgl_num_sges /* Number of SGLs sges */; 213 u8 sgl_index /* SGL index */; 214 u8 reserved; 215 }; 216 217 218 /* 219 * SCSI terminate connection params 220 */ 221 struct scsi_terminate_extra_params 222 { 223 __le16 unsolicited_cq_count /* Counts number of CQ placements done due to arrival of unsolicited packets on this connection */; 224 __le16 cmdq_count /* Counts number of CMDQ placements on this connection */; 225 u8 reserved[4]; 226 }; 227 228 229 /* 230 * SCSI Task Queue Element 231 */ 232 struct scsi_tqe 233 { 234 __le16 itid /* Physical Address of buffer */; 235 }; 236 237 #endif /* __STORAGE_COMMON__ */ 238