1/*- 2 * Copyright 2009 Scott Long 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 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions, and the following disclaimer, 10 * without modification, immediately at the beginning of the file. 11 * 2. The name of the author may not be used to endorse or promote products 12 * derived from this software without specific prior written permission. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD: releng/10.3/sys/cam/cam_xpt_internal.h 278974 2015-02-18 23:08:13Z ken $ 27 */ 28 29#ifndef _CAM_CAM_XPT_INTERNAL_H 30#define _CAM_CAM_XPT_INTERNAL_H 1 31 32#include <sys/taskqueue.h> 33 34/* Forward Declarations */ 35struct cam_eb; 36struct cam_et; 37struct cam_ed; 38 39typedef struct cam_ed * (*xpt_alloc_device_func)(struct cam_eb *bus, 40 struct cam_et *target, 41 lun_id_t lun_id); 42typedef void (*xpt_release_device_func)(struct cam_ed *device); 43typedef void (*xpt_action_func)(union ccb *start_ccb); 44typedef void (*xpt_dev_async_func)(u_int32_t async_code, 45 struct cam_eb *bus, 46 struct cam_et *target, 47 struct cam_ed *device, 48 void *async_arg); 49typedef void (*xpt_announce_periph_func)(struct cam_periph *periph); 50 51struct xpt_xport { 52 xpt_alloc_device_func alloc_device; 53 xpt_release_device_func reldev; 54 xpt_action_func action; 55 xpt_dev_async_func async; 56 xpt_announce_periph_func announce; 57}; 58 59/* 60 * The CAM EDT (Existing Device Table) contains the device information for 61 * all devices for all busses in the system. The table contains a 62 * cam_ed structure for each device on the bus. 63 */ 64struct cam_ed { 65 cam_pinfo devq_entry; 66 TAILQ_ENTRY(cam_ed) links; 67 struct cam_et *target; 68 struct cam_sim *sim; 69 lun_id_t lun_id; 70 struct cam_ccbq ccbq; /* Queue of pending ccbs */ 71 struct async_list asyncs; /* Async callback info for this B/T/L */ 72 struct periph_list periphs; /* All attached devices */ 73 u_int generation; /* Generation number */ 74 void *quirk; /* Oddities about this device */ 75 u_int maxtags; 76 u_int mintags; 77 cam_proto protocol; 78 u_int protocol_version; 79 cam_xport transport; 80 u_int transport_version; 81 struct scsi_inquiry_data inq_data; 82 uint8_t *supported_vpds; 83 uint8_t supported_vpds_len; 84 uint32_t device_id_len; 85 uint8_t *device_id; 86 uint32_t ext_inq_len; 87 uint8_t *ext_inq; 88 uint8_t physpath_len; 89 uint8_t *physpath; /* physical path string form */ 90 uint32_t rcap_len; 91 uint8_t *rcap_buf; 92 struct ata_params ident_data; 93 u_int8_t inq_flags; /* 94 * Current settings for inquiry flags. 95 * This allows us to override settings 96 * like disconnection and tagged 97 * queuing for a device. 98 */ 99 u_int8_t queue_flags; /* Queue flags from the control page */ 100 u_int8_t serial_num_len; 101 u_int8_t *serial_num; 102 u_int32_t flags; 103#define CAM_DEV_UNCONFIGURED 0x01 104#define CAM_DEV_REL_TIMEOUT_PENDING 0x02 105#define CAM_DEV_REL_ON_COMPLETE 0x04 106#define CAM_DEV_REL_ON_QUEUE_EMPTY 0x08 107#define CAM_DEV_TAG_AFTER_COUNT 0x20 108#define CAM_DEV_INQUIRY_DATA_VALID 0x40 109#define CAM_DEV_IN_DV 0x80 110#define CAM_DEV_DV_HIT_BOTTOM 0x100 111#define CAM_DEV_IDENTIFY_DATA_VALID 0x200 112 u_int32_t tag_delay_count; 113#define CAM_TAG_DELAY_COUNT 5 114 u_int32_t tag_saved_openings; 115 u_int32_t refcount; 116 struct callout callout; 117 STAILQ_ENTRY(cam_ed) highpowerq_entry; 118 struct mtx device_mtx; 119 struct task device_destroy_task; 120}; 121 122/* 123 * Each target is represented by an ET (Existing Target). These 124 * entries are created when a target is successfully probed with an 125 * identify, and removed when a device fails to respond after a number 126 * of retries, or a bus rescan finds the device missing. 127 */ 128struct cam_et { 129 TAILQ_HEAD(, cam_ed) ed_entries; 130 TAILQ_ENTRY(cam_et) links; 131 struct cam_eb *bus; 132 target_id_t target_id; 133 u_int32_t refcount; 134 u_int generation; 135 struct timeval last_reset; 136 u_int rpl_size; 137 struct scsi_report_luns_data *luns; 138 struct mtx luns_mtx; /* Protection for luns field. */ 139}; 140 141/* 142 * Each bus is represented by an EB (Existing Bus). These entries 143 * are created by calls to xpt_bus_register and deleted by calls to 144 * xpt_bus_deregister. 145 */ 146struct cam_eb { 147 TAILQ_HEAD(, cam_et) et_entries; 148 TAILQ_ENTRY(cam_eb) links; 149 path_id_t path_id; 150 struct cam_sim *sim; 151 struct timeval last_reset; 152 u_int32_t flags; 153#define CAM_EB_RUNQ_SCHEDULED 0x01 154 u_int32_t refcount; 155 u_int generation; 156 device_t parent_dev; 157 struct xpt_xport *xport; 158 struct mtx eb_mtx; /* Bus topology mutex. */ 159}; 160 161struct cam_path { 162 struct cam_periph *periph; 163 struct cam_eb *bus; 164 struct cam_et *target; 165 struct cam_ed *device; 166}; 167 168struct xpt_xport * scsi_get_xport(void); 169struct xpt_xport * ata_get_xport(void); 170 171struct cam_ed * xpt_alloc_device(struct cam_eb *bus, 172 struct cam_et *target, 173 lun_id_t lun_id); 174void xpt_acquire_device(struct cam_ed *device); 175void xpt_release_device(struct cam_ed *device); 176u_int32_t xpt_dev_ccbq_resize(struct cam_path *path, int newopenings); 177void xpt_start_tags(struct cam_path *path); 178void xpt_stop_tags(struct cam_path *path); 179 180MALLOC_DECLARE(M_CAMXPT); 181 182#endif 183