1195534Sscottl/*- 2195534Sscottl * Copyright 2009 Scott Long 3195534Sscottl * All rights reserved. 4195534Sscottl * 5195534Sscottl * Redistribution and use in source and binary forms, with or without 6195534Sscottl * modification, are permitted provided that the following conditions 7195534Sscottl * are met: 8195534Sscottl * 1. Redistributions of source code must retain the above copyright 9195534Sscottl * notice, this list of conditions, and the following disclaimer, 10195534Sscottl * without modification, immediately at the beginning of the file. 11195534Sscottl * 2. The name of the author may not be used to endorse or promote products 12195534Sscottl * derived from this software without specific prior written permission. 13195534Sscottl * 14195534Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15195534Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16195534Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17195534Sscottl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 18195534Sscottl * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19195534Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20195534Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21195534Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22195534Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23195534Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24195534Sscottl * SUCH DAMAGE. 25195534Sscottl * 26195534Sscottl * $FreeBSD$ 27195534Sscottl */ 28195534Sscottl 29195534Sscottl#ifndef _CAM_CAM_XPT_INTERNAL_H 30195534Sscottl#define _CAM_CAM_XPT_INTERNAL_H 1 31195534Sscottl 32195534Sscottl/* Forward Declarations */ 33195534Sscottlstruct cam_eb; 34195534Sscottlstruct cam_et; 35195534Sscottlstruct cam_ed; 36195534Sscottl 37195534Sscottltypedef struct cam_ed * (*xpt_alloc_device_func)(struct cam_eb *bus, 38195534Sscottl struct cam_et *target, 39195534Sscottl lun_id_t lun_id); 40198748Smavtypedef void (*xpt_release_device_func)(struct cam_ed *device); 41195534Sscottltypedef void (*xpt_action_func)(union ccb *start_ccb); 42195534Sscottltypedef void (*xpt_dev_async_func)(u_int32_t async_code, 43195534Sscottl struct cam_eb *bus, 44195534Sscottl struct cam_et *target, 45195534Sscottl struct cam_ed *device, 46195534Sscottl void *async_arg); 47204220Smavtypedef void (*xpt_announce_periph_func)(struct cam_periph *periph); 48195534Sscottl 49195534Sscottlstruct xpt_xport { 50195534Sscottl xpt_alloc_device_func alloc_device; 51195534Sscottl xpt_release_device_func reldev; 52195534Sscottl xpt_action_func action; 53195534Sscottl xpt_dev_async_func async; 54195534Sscottl xpt_announce_periph_func announce; 55195534Sscottl}; 56195534Sscottl 57195534Sscottl/* 58195534Sscottl * Structure for queueing a device in a run queue. 59195534Sscottl * There is one run queue for allocating new ccbs, 60195534Sscottl * and another for sending ccbs to the controller. 61195534Sscottl */ 62195534Sscottlstruct cam_ed_qinfo { 63195534Sscottl cam_pinfo pinfo; 64195534Sscottl struct cam_ed *device; 65195534Sscottl}; 66195534Sscottl 67195534Sscottl/* 68195534Sscottl * The CAM EDT (Existing Device Table) contains the device information for 69195534Sscottl * all devices for all busses in the system. The table contains a 70195534Sscottl * cam_ed structure for each device on the bus. 71195534Sscottl */ 72195534Sscottlstruct cam_ed { 73195534Sscottl TAILQ_ENTRY(cam_ed) links; 74249466Smav struct cam_ed_qinfo devq_entry; 75195534Sscottl struct cam_et *target; 76195534Sscottl struct cam_sim *sim; 77195534Sscottl lun_id_t lun_id; 78195534Sscottl struct camq drvq; /* 79195534Sscottl * Queue of type drivers wanting to do 80195534Sscottl * work on this device. 81195534Sscottl */ 82195534Sscottl struct cam_ccbq ccbq; /* Queue of pending ccbs */ 83195534Sscottl struct async_list asyncs; /* Async callback info for this B/T/L */ 84195534Sscottl struct periph_list periphs; /* All attached devices */ 85195534Sscottl u_int generation; /* Generation number */ 86195534Sscottl void *quirk; /* Oddities about this device */ 87195534Sscottl u_int maxtags; 88195534Sscottl u_int mintags; 89195534Sscottl cam_proto protocol; 90195534Sscottl u_int protocol_version; 91195534Sscottl cam_xport transport; 92195534Sscottl u_int transport_version; 93195534Sscottl struct scsi_inquiry_data inq_data; 94216088Sken uint8_t *supported_vpds; 95216088Sken uint8_t supported_vpds_len; 96216088Sken uint32_t device_id_len; 97216088Sken uint8_t *device_id; 98223081Sgibbs uint8_t physpath_len; 99223081Sgibbs uint8_t *physpath; /* physical path string form */ 100230590Sken uint32_t rcap_len; 101230590Sken uint8_t *rcap_buf; 102195534Sscottl struct ata_params ident_data; 103195534Sscottl u_int8_t inq_flags; /* 104195534Sscottl * Current settings for inquiry flags. 105195534Sscottl * This allows us to override settings 106195534Sscottl * like disconnection and tagged 107195534Sscottl * queuing for a device. 108195534Sscottl */ 109195534Sscottl u_int8_t queue_flags; /* Queue flags from the control page */ 110195534Sscottl u_int8_t serial_num_len; 111195534Sscottl u_int8_t *serial_num; 112195534Sscottl u_int32_t flags; 113195534Sscottl#define CAM_DEV_UNCONFIGURED 0x01 114195534Sscottl#define CAM_DEV_REL_TIMEOUT_PENDING 0x02 115195534Sscottl#define CAM_DEV_REL_ON_COMPLETE 0x04 116195534Sscottl#define CAM_DEV_REL_ON_QUEUE_EMPTY 0x08 117195534Sscottl#define CAM_DEV_TAG_AFTER_COUNT 0x20 118195534Sscottl#define CAM_DEV_INQUIRY_DATA_VALID 0x40 119195534Sscottl#define CAM_DEV_IN_DV 0x80 120195534Sscottl#define CAM_DEV_DV_HIT_BOTTOM 0x100 121198331Smav#define CAM_DEV_IDENTIFY_DATA_VALID 0x200 122195534Sscottl u_int32_t tag_delay_count; 123195534Sscottl#define CAM_TAG_DELAY_COUNT 5 124195534Sscottl u_int32_t tag_saved_openings; 125195534Sscottl u_int32_t refcount; 126195534Sscottl struct callout callout; 127253958Smav STAILQ_ENTRY(cam_ed) highpowerq_entry; 128195534Sscottl}; 129195534Sscottl 130195534Sscottl/* 131195534Sscottl * Each target is represented by an ET (Existing Target). These 132195534Sscottl * entries are created when a target is successfully probed with an 133195534Sscottl * identify, and removed when a device fails to respond after a number 134195534Sscottl * of retries, or a bus rescan finds the device missing. 135195534Sscottl */ 136195534Sscottlstruct cam_et { 137195534Sscottl TAILQ_HEAD(, cam_ed) ed_entries; 138195534Sscottl TAILQ_ENTRY(cam_et) links; 139195534Sscottl struct cam_eb *bus; 140195534Sscottl target_id_t target_id; 141195534Sscottl u_int32_t refcount; 142195534Sscottl u_int generation; 143195534Sscottl struct timeval last_reset; 144208911Smjacob u_int rpl_size; 145208911Smjacob struct scsi_report_luns_data *luns; 146195534Sscottl}; 147195534Sscottl 148195534Sscottl/* 149195534Sscottl * Each bus is represented by an EB (Existing Bus). These entries 150195534Sscottl * are created by calls to xpt_bus_register and deleted by calls to 151195534Sscottl * xpt_bus_deregister. 152195534Sscottl */ 153195534Sscottlstruct cam_eb { 154195534Sscottl TAILQ_HEAD(, cam_et) et_entries; 155195534Sscottl TAILQ_ENTRY(cam_eb) links; 156195534Sscottl path_id_t path_id; 157195534Sscottl struct cam_sim *sim; 158195534Sscottl struct timeval last_reset; 159195534Sscottl u_int32_t flags; 160195534Sscottl#define CAM_EB_RUNQ_SCHEDULED 0x01 161195534Sscottl u_int32_t refcount; 162195534Sscottl u_int generation; 163195534Sscottl device_t parent_dev; 164195534Sscottl struct xpt_xport *xport; 165195534Sscottl}; 166195534Sscottl 167195534Sscottlstruct cam_path { 168195534Sscottl struct cam_periph *periph; 169195534Sscottl struct cam_eb *bus; 170195534Sscottl struct cam_et *target; 171195534Sscottl struct cam_ed *device; 172195534Sscottl}; 173195534Sscottl 174195534Sscottlstruct xpt_xport * scsi_get_xport(void); 175195534Sscottlstruct xpt_xport * ata_get_xport(void); 176195534Sscottl 177195534Sscottlstruct cam_ed * xpt_alloc_device(struct cam_eb *bus, 178195534Sscottl struct cam_et *target, 179195534Sscottl lun_id_t lun_id); 180198748Smavvoid xpt_acquire_device(struct cam_ed *device); 181198748Smavvoid xpt_release_device(struct cam_ed *device); 182195534Sscottlint xpt_schedule_dev(struct camq *queue, cam_pinfo *dev_pinfo, 183195534Sscottl u_int32_t new_priority); 184195534Sscottlu_int32_t xpt_dev_ccbq_resize(struct cam_path *path, int newopenings); 185199178Smavvoid xpt_start_tags(struct cam_path *path); 186199178Smavvoid xpt_stop_tags(struct cam_path *path); 187195534Sscottl 188195534SscottlMALLOC_DECLARE(M_CAMXPT); 189195534Sscottl 190195534Sscottl#endif 191