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 #ifndef __OCS_CAM_H__ 35 #define __OCS_CAM_H__ 36 37 #include <cam/cam.h> 38 #include <cam/cam_sim.h> 39 #include <cam/cam_ccb.h> 40 #include <cam/cam_periph.h> 41 #include <cam/cam_xpt_sim.h> 42 43 #include <cam/scsi/scsi_message.h> 44 45 46 #define ccb_ocs_ptr spriv_ptr0 47 #define ccb_io_ptr spriv_ptr1 48 49 typedef STAILQ_HEAD(ocs_hdr_list_s, ccb_hdr) ocs_hdr_list_t; 50 51 typedef struct ocs_tgt_resource_s { 52 ocs_hdr_list_t atio; 53 ocs_hdr_list_t inot; 54 uint8_t enabled; 55 56 lun_id_t lun; 57 } ocs_tgt_resource_t; 58 59 /* Common SCSI Domain structure declarations */ 60 61 typedef struct { 62 } ocs_scsi_tgt_domain_t; 63 64 typedef struct { 65 } ocs_scsi_ini_domain_t; 66 67 /* Common SCSI SLI port structure declarations */ 68 69 typedef struct { 70 } ocs_scsi_tgt_sport_t; 71 72 typedef struct { 73 } ocs_scsi_ini_sport_t; 74 75 /* Common IO structure declarations */ 76 77 typedef enum { 78 OCS_CAM_IO_FREE, /* IO unused (SIM) */ 79 OCS_CAM_IO_COMMAND, /* ATIO returned to BE (CTL) */ 80 OCS_CAM_IO_DATA, /* data phase (SIM) */ 81 OCS_CAM_IO_DATA_DONE, /* CTIO returned to BE (CTL) */ 82 OCS_CAM_IO_RESP, /* send response (SIM) */ 83 OCS_CAM_IO_MAX 84 } ocs_cam_io_state_t; 85 86 typedef struct { 87 bus_dmamap_t dmap; 88 uint64_t lun; /* target_lun */ 89 void *app; /** application specific pointer */ 90 ocs_cam_io_state_t state; 91 bool sendresp; 92 uint32_t flags; 93 #define OCS_CAM_IO_F_DMAPPED BIT(0) /* associated buffer bus_dmamap'd */ 94 #define OCS_CAM_IO_F_ABORT_RECV BIT(1) /* received ABORT TASK */ 95 #define OCS_CAM_IO_F_ABORT_DEV BIT(2) /* abort WQE pending */ 96 #define OCS_CAM_IO_F_ABORT_TMF BIT(3) /* TMF response sent */ 97 #define OCS_CAM_IO_F_ABORT_NOTIFY BIT(4) /* XPT_NOTIFY sent to CTL */ 98 #define OCS_CAM_IO_F_ABORT_CAM BIT(5) /* received ABORT or CTIO from CAM */ 99 } ocs_scsi_tgt_io_t; 100 101 typedef struct { 102 } ocs_scsi_ini_io_t; 103 104 struct ocs_lun_crn { 105 uint64_t lun; /* target_lun */ 106 uint8_t crnseed; /* next command reference number */ 107 }; 108 109 /* Common NODE structure declarations */ 110 typedef struct { 111 struct ocs_lun_crn *lun_crn[OCS_MAX_LUN]; 112 } ocs_scsi_ini_node_t; 113 114 typedef struct { 115 uint32_t busy_sent; 116 } ocs_scsi_tgt_node_t; 117 118 extern int32_t ocs_cam_attach(ocs_t *ocs); 119 extern int32_t ocs_cam_detach(ocs_t *ocs); 120 121 #endif /* __OCS_CAM_H__ */ 122 123