cam_xpt_internal.h revision 208911
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: head/sys/cam/cam_xpt_internal.h 208911 2010-06-08 16:17:25Z mjacob $ 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; 74195534Sscottl struct cam_ed_qinfo alloc_ccb_entry; 75195534Sscottl struct cam_ed_qinfo send_ccb_entry; 76195534Sscottl struct cam_et *target; 77195534Sscottl struct cam_sim *sim; 78195534Sscottl lun_id_t lun_id; 79195534Sscottl struct camq drvq; /* 80195534Sscottl * Queue of type drivers wanting to do 81195534Sscottl * work on this device. 82195534Sscottl */ 83195534Sscottl struct cam_ccbq ccbq; /* Queue of pending ccbs */ 84195534Sscottl struct async_list asyncs; /* Async callback info for this B/T/L */ 85195534Sscottl struct periph_list periphs; /* All attached devices */ 86195534Sscottl u_int generation; /* Generation number */ 87195534Sscottl struct cam_periph *owner; /* Peripheral driver's ownership tag */ 88195534Sscottl void *quirk; /* Oddities about this device */ 89195534Sscottl u_int maxtags; 90195534Sscottl u_int mintags; 91195534Sscottl cam_proto protocol; 92195534Sscottl u_int protocol_version; 93195534Sscottl cam_xport transport; 94195534Sscottl u_int transport_version; 95195534Sscottl struct scsi_inquiry_data inq_data; 96195534Sscottl struct ata_params ident_data; 97195534Sscottl u_int8_t inq_flags; /* 98195534Sscottl * Current settings for inquiry flags. 99195534Sscottl * This allows us to override settings 100195534Sscottl * like disconnection and tagged 101195534Sscottl * queuing for a device. 102195534Sscottl */ 103195534Sscottl u_int8_t queue_flags; /* Queue flags from the control page */ 104195534Sscottl u_int8_t serial_num_len; 105195534Sscottl u_int8_t *serial_num; 106195534Sscottl u_int32_t flags; 107195534Sscottl#define CAM_DEV_UNCONFIGURED 0x01 108195534Sscottl#define CAM_DEV_REL_TIMEOUT_PENDING 0x02 109195534Sscottl#define CAM_DEV_REL_ON_COMPLETE 0x04 110195534Sscottl#define CAM_DEV_REL_ON_QUEUE_EMPTY 0x08 111195534Sscottl#define CAM_DEV_RESIZE_QUEUE_NEEDED 0x10 112195534Sscottl#define CAM_DEV_TAG_AFTER_COUNT 0x20 113195534Sscottl#define CAM_DEV_INQUIRY_DATA_VALID 0x40 114195534Sscottl#define CAM_DEV_IN_DV 0x80 115195534Sscottl#define CAM_DEV_DV_HIT_BOTTOM 0x100 116198331Smav#define CAM_DEV_IDENTIFY_DATA_VALID 0x200 117195534Sscottl u_int32_t tag_delay_count; 118195534Sscottl#define CAM_TAG_DELAY_COUNT 5 119195534Sscottl u_int32_t tag_saved_openings; 120195534Sscottl u_int32_t refcount; 121195534Sscottl struct callout callout; 122195534Sscottl}; 123195534Sscottl 124195534Sscottl/* 125195534Sscottl * Each target is represented by an ET (Existing Target). These 126195534Sscottl * entries are created when a target is successfully probed with an 127195534Sscottl * identify, and removed when a device fails to respond after a number 128195534Sscottl * of retries, or a bus rescan finds the device missing. 129195534Sscottl */ 130195534Sscottlstruct cam_et { 131195534Sscottl TAILQ_HEAD(, cam_ed) ed_entries; 132195534Sscottl TAILQ_ENTRY(cam_et) links; 133195534Sscottl struct cam_eb *bus; 134195534Sscottl target_id_t target_id; 135195534Sscottl u_int32_t refcount; 136195534Sscottl u_int generation; 137195534Sscottl struct timeval last_reset; 138208911Smjacob u_int rpl_size; 139208911Smjacob struct scsi_report_luns_data *luns; 140195534Sscottl}; 141195534Sscottl 142195534Sscottl/* 143195534Sscottl * Each bus is represented by an EB (Existing Bus). These entries 144195534Sscottl * are created by calls to xpt_bus_register and deleted by calls to 145195534Sscottl * xpt_bus_deregister. 146195534Sscottl */ 147195534Sscottlstruct cam_eb { 148195534Sscottl TAILQ_HEAD(, cam_et) et_entries; 149195534Sscottl TAILQ_ENTRY(cam_eb) links; 150195534Sscottl path_id_t path_id; 151195534Sscottl struct cam_sim *sim; 152195534Sscottl struct timeval last_reset; 153195534Sscottl u_int32_t flags; 154195534Sscottl#define CAM_EB_RUNQ_SCHEDULED 0x01 155195534Sscottl u_int32_t refcount; 156195534Sscottl u_int generation; 157195534Sscottl device_t parent_dev; 158195534Sscottl struct xpt_xport *xport; 159195534Sscottl}; 160195534Sscottl 161195534Sscottlstruct cam_path { 162195534Sscottl struct cam_periph *periph; 163195534Sscottl struct cam_eb *bus; 164195534Sscottl struct cam_et *target; 165195534Sscottl struct cam_ed *device; 166195534Sscottl}; 167195534Sscottl 168195534Sscottlstruct xpt_xport * scsi_get_xport(void); 169195534Sscottlstruct xpt_xport * ata_get_xport(void); 170195534Sscottl 171195534Sscottlstruct cam_ed * xpt_alloc_device(struct cam_eb *bus, 172195534Sscottl struct cam_et *target, 173195534Sscottl lun_id_t lun_id); 174198748Smavvoid xpt_acquire_device(struct cam_ed *device); 175198748Smavvoid xpt_release_device(struct cam_ed *device); 176195534Sscottlint xpt_schedule_dev(struct camq *queue, cam_pinfo *dev_pinfo, 177195534Sscottl u_int32_t new_priority); 178195534Sscottlu_int32_t xpt_dev_ccbq_resize(struct cam_path *path, int newopenings); 179199178Smavvoid xpt_start_tags(struct cam_path *path); 180199178Smavvoid xpt_stop_tags(struct cam_path *path); 181195534Sscottl 182195534SscottlMALLOC_DECLARE(M_CAMXPT); 183195534Sscottl 184195534Sscottl#endif 185