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 * Common declartaions for the driver's IOCTL interface 37 */ 38 39 #if !defined(__OCS_IOCTL_H__) 40 #define __OCS_IOCTL_H__ 41 42 /** 43 * @brief OCS test ioctl 44 * 45 * Simple structure for testing the IOCTL interface 46 */ 47 48 typedef struct { 49 char string[32]; /**< fixed string buffer */ 50 } ocs_ioctl_test_t; 51 52 /** 53 * @brief DRIVER_INFO ioctl structure 54 * 55 * Structure is returned whtn the OCS_IOCTL_CMD_DRIVER_INFO is issued by a user space program. 56 */ 57 58 typedef struct { 59 uint16_t pci_vendor; /**< PCI vender ID value (binary) */ 60 uint16_t pci_device; /**< PCI device ID value (binary) */ 61 char businfo[16]; /**< Bus information (text) */ 62 uint32_t sli_intf; /**< SLI_INTF register value (binary) */ 63 char desc[64]; /**< description (text) */ 64 char fw_rev[32]; /**< firmware revision (text) */ 65 union { 66 struct { 67 uint8_t wwnn[8]; /**< WWNN (binary) */ 68 uint8_t wwpn[8]; /**< WWPN (binary) */ 69 } fc; 70 struct { 71 uint8_t mac_addr[6]; /**< MAC address (binary) */ 72 uint8_t reserved[10]; 73 } iscsi; 74 } hw_addr; 75 char serialnum[32]; /**< board serial number (text) */ 76 } ocs_ioctl_driver_info_t; 77 78 #define ELXU_BSD_MAGIC 0x30584c45 79 80 /** 81 * @brief IOCTL_CMD_IOCTL_ELXU_MBOX ioctl structure 82 * 83 * Structure used to submit elxsdkutil mailbox requests for firmware download and 84 * dump file retrieveal. 85 */ 86 87 typedef struct { 88 uint32_t magic; /**< magic number */ 89 uint32_t size; /**< size of MBX command */ 90 uint8_t payload[256]; /**< MBX command in/out payload buffer */ 91 uint64_t in_addr; /**< user space address of input buffer */ 92 uint64_t in_bytes; /**< length of user space input buffer in bytes */ 93 uint64_t out_addr; /**< user space address of output buffer */ 94 uint64_t out_bytes; /**< length of user space output buffer in bytes */ 95 } ocs_ioctl_elxu_mbox_t; 96 97 enum { 98 ocs_ioctl_scsi_cmd_loop, /**< Start command loop */ 99 ocs_ioctl_scsi_cmd_loop_wait, /**< Start command loop and wait for completion */ 100 ocs_ioctl_scsi_cmd_stop, /**< Stop command loop */ 101 ocs_ioctl_scsi_cmd, /**< Start one command */ 102 ocs_ioctl_scsi_cmd_wait, /**< Wait for a command to complete */ 103 ocs_ioctl_scsi_cmd_abort, /**< Start an abort */ 104 ocs_ioctl_scsi_cmd_tmf, /**< Start a tmf */ 105 ocs_ioctl_els_send, /**< Start an ELS */ 106 ocs_ioctl_tgt_logout, /**< logout of a target */ 107 ocs_ioctl_scsi_cmd_wait_any, /**< Wait for any command to complete */ 108 }; 109 110 enum { 111 ocs_ioctl_scsi_cmd_rd = (1U << 0), /**< direction is read */ 112 ocs_ioctl_scsi_cmd_wr = (1U << 1), /**< direction is write */ 113 }; 114 115 /** 116 * @brief OCS_IOCTL_CMD_SCSI_CMD ioctl command structure 117 */ 118 119 typedef enum { 120 DIF_OP_DISABLE = 0, 121 DIF_OP_IN_NODIF_OUT_CRC, 122 DIF_OP_IN_CRC_OUT_NODIF, 123 DIF_OP_IN_NODIF_OUT_CHKSUM, 124 DIF_OP_IN_CHKSUM_OUT_NODIF, 125 DIF_OP_IN_CRC_OUT_CRC, 126 DIF_OP_IN_CHKSUM_OUT_CHKSUM, 127 DIF_OP_IN_CRC_OUT_CHKSUM, 128 DIF_OP_IN_CHKSUM_OUT_CRC, 129 DIF_OP_IN_RAW_OUT_RAW, 130 } dif_op_t; 131 132 #define DIF_OP_PASS_THRU DIF_OP_IN_CRC_OUT_CRC 133 #define DIF_OP_STRIP DIF_OP_IN_CRC_OUT_NODIF 134 #define DIF_OP_INSERT DIF_OP_IN_NODIF_OUT_CRC 135 136 typedef struct { 137 dif_op_t dif_op; 138 uint32_t 139 check_ref_tag:1, /* check reference tag on initiator writes */ 140 check_app_tag:1, /* check application tag on initiator writes */ 141 check_guard:1, /* check CRC on initiator writes */ 142 dif_separate:1; /* use DIF separate transfers */ 143 uint32_t ref_tag; /* DIF reference tag */ 144 uint16_t app_tag; /* DIF application tag */ 145 uint32_t blocksize; /* DIF blocksize */ 146 } dif_info_t; 147 148 typedef struct { 149 int command; /**< SCSI command request command */ 150 uint32_t target_idx; /**< Target device index */ 151 uint32_t dir; /**< rd or wr */ 152 uint32_t lun; /**< lun value */ 153 int32_t tmf; /**< TMF */ 154 uint8_t cdb[32]; /**< SCSI CDB */ 155 uint32_t cdb_len; /**< SCSI CDB length in bytes */ 156 uint32_t els_cmd; /**< ELS command */ 157 uint32_t flags; /**< command flags */ 158 uint32_t queue_depth; /**< queue depth for command looping */ 159 uint32_t payload_length; /**< payload length for command */ 160 uint32_t dif_payload_length; /**< DIF payload length for command if separate */ 161 uint32_t io_count; /**< command count for looping */ 162 uint32_t io_timeout; /**< IO timeout in seconds (0 = no timeout) */ 163 164 uint32_t directio; /**< If set, DMA to and from user buffers */ 165 166 uint32_t first_burst:1; /**< If true send IO writes with first burst */ 167 uint32_t first_burst_size; /**< If first burst is enabled, then this size */ 168 169 int32_t wait_timeout_usec; /**< Wait timeout (usec) for wait, wait_any */ 170 171 /* T10-PI */ 172 dif_info_t dif; /* DIF info */ 173 174 /* user space buffers */ 175 void *payload; /**< pointer to user space payload buffer */ 176 void *dif_payload; /**< pointer to DIF block data if separate */ 177 uint8_t scsi_status; /**< SCSI status */ 178 uint16_t scsi_status_qualifier; /**< SCSI status qualifier */ 179 void *sense_data; /**< pointer to sense data buffer */ 180 uint32_t sense_data_length; /**< length of sense data buffer (call=buffer leng, return=data written) */ 181 int32_t residual; /**< residual */ 182 uint32_t tag_to_abort; /**< tag to abort for an abort task request */ 183 184 /* return value */ 185 int32_t status; /**< returned status */ 186 uint32_t data_transferred; /**< updated with data transferred */ 187 uint32_t tag; /**< returned unique I/O context tag */ 188 189 /* for scsi loop */ 190 uint32_t submit_count; /**< count of submitted IOs */ 191 uint32_t complete_count; /**< count of completed IOs */ 192 } ocs_ioctl_scsi_cmd_t; 193 194 /** 195 * @brief coredump helper function command values 196 */ 197 198 typedef enum { 199 OCS_ECD_HELPER_CFG_READ8, 200 OCS_ECD_HELPER_CFG_READ16, 201 OCS_ECD_HELPER_CFG_READ32, 202 OCS_ECD_HELPER_CFG_WRITE8, 203 OCS_ECD_HELPER_CFG_WRITE16, 204 OCS_ECD_HELPER_CFG_WRITE32, 205 OCS_ECD_HELPER_BAR_READ8, 206 OCS_ECD_HELPER_BAR_READ16, 207 OCS_ECD_HELPER_BAR_READ32, 208 OCS_ECD_HELPER_BAR_WRITE8, 209 OCS_ECD_HELPER_BAR_WRITE16, 210 OCS_ECD_HELPER_BAR_WRITE32, 211 } ocs_ecd_helper_cmd_t; 212 213 /** 214 * @brief OCS_IOCTL_CMD_ECD_HELPER ioctl structure 215 */ 216 217 typedef struct { 218 ocs_ecd_helper_cmd_t cmd; /*<< coredump helper function command */ 219 uint32_t bar; /*<< BAR value to use */ 220 uint32_t offset; /*<< offset value to use */ 221 uint32_t data; /*<< 32 bit data value to write or return read data in */ 222 int status; /*<< status of helper function request */ 223 } ocs_ioctl_ecd_helper_t; 224 225 /** 226 * @brief OCS_IOCTL_CMD_VPORT ioctl structure 227 */ 228 229 typedef struct { 230 uint32_t domain_index; /*<< domain instance index */ 231 uint32_t req_create:1, /*<< 1 = create vport, zero = remove vport */ 232 enable_ini:1, /*<< 1 = enable vport as an initiator */ 233 enable_tgt:1; /*<< 1 = enable vport as a target */ 234 uint64_t wwpn; /*<< wwpn to create or delete */ 235 uint64_t wwnn; /*<< wwnn to create or delete */ 236 int status; /*<< status of helper function request */ 237 } ocs_ioctl_vport_t; 238 239 /** 240 * @brief connection info ioctl structure 241 * 242 * Structure is returned when the OCS_IOCTL_CMD_CONNECTION_INFO is issued by a user space program. 243 */ 244 typedef struct { 245 uint32_t connection_handle; 246 uint16_t connection_id; 247 uint8_t source_ip_type; 248 uint8_t source_ip[16]; 249 uint16_t source_port; 250 uint8_t dest_ip_type; 251 uint8_t dest_ip[16]; 252 uint16_t dest_port; 253 } ocs_ioctl_connection_info_t; 254 255 typedef struct { 256 uint32_t max_connections; 257 uint32_t num_connections; 258 ocs_ioctl_connection_info_t *connections; 259 } ocs_ioctl_connections_t; 260 261 /** 262 * @brief driver-dump actions 263 */ 264 265 typedef enum { 266 OCS_IOCTL_DDUMP_GET, 267 OCS_IOCTL_DDUMP_GET_SAVED, 268 OCS_IOCTL_DDUMP_CLR_SAVED, 269 } ocs_ddump_action_t; 270 271 #define OCS_IOCTL_DDUMP_FLAGS_WQES (1U << 0) 272 #define OCS_IOCTL_DDUMP_FLAGS_CQES (1U << 1) 273 #define OCS_IOCTL_DDUMP_FLAGS_MQES (1U << 2) 274 #define OCS_IOCTL_DDUMP_FLAGS_RQES (1U << 3) 275 #define OCS_IOCTL_DDUMP_FLAGS_EQES (1U << 4) 276 277 typedef struct { 278 ocs_ddump_action_t action; 279 uint32_t flags; 280 uint32_t q_entries; 281 } ocs_ioctl_ddump_arg_t; 282 283 /** 284 * @brief OCS_CTL_CMD_GET_DDUMP ioctl structure 285 */ 286 287 typedef struct { 288 ocs_ioctl_ddump_arg_t args; /*<< arguments for ddump */ 289 uint8_t *user_buffer; /*<< pointer to user space buffer */ 290 uint32_t user_buffer_len; /*<< length in bytes of user space buffer */ 291 uint32_t bytes_written; /*<< number of bytes written */ 292 } ocs_ioctl_ddump_t; 293 294 /** 295 * @brief OCS_CTL_CMD_GET_STATUS, OCS_CTL_CMD_GET_CONFIG 296 */ 297 298 typedef struct { 299 uint8_t *user_buffer; /*<< pointer to user space buffer */ 300 uint32_t user_buffer_len; /*<< length in bytes of user space buffer */ 301 uint32_t bytes_written; /*<< number of bytes written */ 302 } ocs_ioctl_mgmt_buffer_t; 303 304 typedef struct { 305 uint8_t *name; /*<< Input: name of property to retrieve */ 306 uint8_t *value; /*<< Output: user space buffer in which to place the response */ 307 uint32_t value_length; /*<< Input: size of the user space buffer */ 308 } ocs_ioctl_cmd_get_t; 309 310 typedef struct { 311 uint8_t *name; /*<< Input: name of property to set */ 312 uint8_t *value; /*<< Input: user space buffer which contains the new value */ 313 int32_t result; /*<< Output: result */ 314 } ocs_ioctl_cmd_set_t; 315 316 typedef struct { 317 uint8_t *name; /*<< Input: name of action to execute */ 318 void *arg_in; /*<< Input: pointer to argument in user space */ 319 uint32_t arg_in_length; /*<< Input: size of arg_in in bytes */ 320 void *arg_out; /*<< Output: pointer to argument from kernel to user */ 321 uint32_t arg_out_length; /*<< Input: size of arg_out in bytes */ 322 int32_t result; /*<< Output: result */ 323 } ocs_ioctl_action_t; 324 325 #define FC_HEADER_LEN 24 326 typedef struct { 327 uint8_t fc_header[FC_HEADER_LEN]; /*<< FC Header to send */ 328 uint8_t *payload; /*<< payload */ 329 uint32_t payload_len; /*<< payload length (bytes) */ 330 uint8_t sof; /*<< SOF value */ 331 uint8_t eof; /*<< EOF Value */ 332 } ocs_ioctl_send_frame_t; 333 334 /** 335 * @brief linkcfg strings 336 */ 337 #define OCS_CONFIG_LINKCFG_4X10G "ETH_4x10G" 338 #define OCS_CONFIG_LINKCFG_1X40G "ETH_1x40G" 339 #define OCS_CONFIG_LINKCFG_2X16G "FC_2x16G" 340 #define OCS_CONFIG_LINKCFG_4X8G "FC_4x8G" 341 #define OCS_CONFIG_LINKCFG_4X1G "FC_4x1G" 342 #define OCS_CONFIG_LINKCFG_2X10G "ETH_2x10G" 343 #define OCS_CONFIG_LINKCFG_2X10G_2X8G "ETH_2x10G_FC_2x8G" 344 #define OCS_CONFIG_LINKCFG_UNKNOWN "UNKNOWN" 345 346 #define OCS_IOCTL_CMD_BASE 'o' 347 #define OCS_IOCTL_CMD_TEST _IOWR(OCS_IOCTL_CMD_BASE, 1, ocs_ioctl_test_t) 348 #define OCS_IOCTL_CMD_ELXU_MBOX _IOWR(OCS_IOCTL_CMD_BASE, 2, ocs_ioctl_elxu_mbox_t) 349 #define OCS_IOCTL_CMD_SCSI_CMD _IOWR(OCS_IOCTL_CMD_BASE, 3, ocs_ioctl_scsi_cmd_t) 350 #define OCS_IOCTL_CMD_DRIVER_INFO _IOWR(OCS_IOCTL_CMD_BASE, 4, ocs_ioctl_driver_info_t) 351 #define OCS_IOCTL_CMD_ECD_HELPER _IOWR(OCS_IOCTL_CMD_BASE, 5, ocs_ioctl_ecd_helper_t) 352 #define OCS_IOCTL_CMD_CONNECTION_INFO _IOWR(OCS_IOCTL_CMD_BASE, 6, ocs_ioctl_connection_info_t) 353 #define OCS_IOCTL_CMD_VPORT _IOWR(OCS_IOCTL_CMD_BASE, 7, ocs_ioctl_vport_t) 354 #define OCS_IOCTL_CMD_GET_DDUMP _IOWR(OCS_IOCTL_CMD_BASE, 8, ocs_ioctl_ddump_t) 355 #define OCS_IOCTL_CMD_MGMT_GET _IOWR(OCS_IOCTL_CMD_BASE, 9, ocs_ioctl_cmd_get_t) 356 #define OCS_IOCTL_CMD_MGMT_GET_ALL _IOWR(OCS_IOCTL_CMD_BASE, 10, ocs_ioctl_mgmt_buffer_t) 357 #define OCS_IOCTL_CMD_MGMT_SET _IOWR(OCS_IOCTL_CMD_BASE, 11, ocs_ioctl_cmd_set_t) 358 #define OCS_IOCTL_CMD_MGMT_LIST _IOWR(OCS_IOCTL_CMD_BASE, 12, ocs_ioctl_mgmt_buffer_t) 359 #define OCS_IOCTL_CMD_MGMT_EXEC _IOWR(OCS_IOCTL_CMD_BASE, 13, ocs_ioctl_action_t) 360 #define OCS_IOCTL_CMD_LINK_ONLINE _IOWR(OCS_IOCTL_CMD_BASE, 16, int) 361 #define OCS_IOCTL_CMD_GEN_DUMP _IOWR(OCS_IOCTL_CMD_BASE, 17, int) 362 #define OCS_IOCTL_CMD_UNLOAD _IO(OCS_IOCTL_CMD_BASE, 18) 363 #define OCS_IOCTL_CMD_SEND_FRAME _IOWR(OCS_IOCTL_CMD_BASE, 19, ocs_ioctl_send_frame_t) 364 365 366 extern void ocs_info_get_xport_address(ocs_t *ocs, ocs_ioctl_driver_info_t *info); 367 extern int32_t ocs_device_ioctl_xport(ocs_t *ocs, unsigned int cmd, unsigned long arg); 368 #endif 369