cam_xpt_internal.h revision 199178
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 199178 2009-11-11 11:10:36Z mav $ 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); 47195534Sscottltypedef void (*xpt_announce_periph_func)(struct cam_periph *periph, 48195534Sscottl char *announce_string); 49195534Sscottl 50195534Sscottlstruct xpt_xport { 51195534Sscottl xpt_alloc_device_func alloc_device; 52195534Sscottl xpt_release_device_func reldev; 53195534Sscottl xpt_action_func action; 54195534Sscottl xpt_dev_async_func async; 55195534Sscottl xpt_announce_periph_func announce; 56195534Sscottl}; 57195534Sscottl 58195534Sscottl/* 59195534Sscottl * Structure for queueing a device in a run queue. 60195534Sscottl * There is one run queue for allocating new ccbs, 61195534Sscottl * and another for sending ccbs to the controller. 62195534Sscottl */ 63195534Sscottlstruct cam_ed_qinfo { 64195534Sscottl cam_pinfo pinfo; 65195534Sscottl struct cam_ed *device; 66195534Sscottl}; 67195534Sscottl 68195534Sscottl/* 69195534Sscottl * The CAM EDT (Existing Device Table) contains the device information for 70195534Sscottl * all devices for all busses in the system. The table contains a 71195534Sscottl * cam_ed structure for each device on the bus. 72195534Sscottl */ 73195534Sscottlstruct cam_ed { 74195534Sscottl TAILQ_ENTRY(cam_ed) links; 75195534Sscottl struct cam_ed_qinfo alloc_ccb_entry; 76195534Sscottl struct cam_ed_qinfo send_ccb_entry; 77195534Sscottl struct cam_et *target; 78195534Sscottl struct cam_sim *sim; 79195534Sscottl lun_id_t lun_id; 80195534Sscottl struct camq drvq; /* 81195534Sscottl * Queue of type drivers wanting to do 82195534Sscottl * work on this device. 83195534Sscottl */ 84195534Sscottl struct cam_ccbq ccbq; /* Queue of pending ccbs */ 85195534Sscottl struct async_list asyncs; /* Async callback info for this B/T/L */ 86195534Sscottl struct periph_list periphs; /* All attached devices */ 87195534Sscottl u_int generation; /* Generation number */ 88195534Sscottl struct cam_periph *owner; /* Peripheral driver's ownership tag */ 89195534Sscottl void *quirk; /* Oddities about this device */ 90195534Sscottl u_int maxtags; 91195534Sscottl u_int mintags; 92195534Sscottl cam_proto protocol; 93195534Sscottl u_int protocol_version; 94195534Sscottl cam_xport transport; 95195534Sscottl u_int transport_version; 96195534Sscottl struct scsi_inquiry_data inq_data; 97195534Sscottl struct ata_params ident_data; 98195534Sscottl u_int8_t inq_flags; /* 99195534Sscottl * Current settings for inquiry flags. 100195534Sscottl * This allows us to override settings 101195534Sscottl * like disconnection and tagged 102195534Sscottl * queuing for a device. 103195534Sscottl */ 104195534Sscottl u_int8_t queue_flags; /* Queue flags from the control page */ 105195534Sscottl u_int8_t serial_num_len; 106195534Sscottl u_int8_t *serial_num; 107195534Sscottl u_int32_t flags; 108195534Sscottl#define CAM_DEV_UNCONFIGURED 0x01 109195534Sscottl#define CAM_DEV_REL_TIMEOUT_PENDING 0x02 110195534Sscottl#define CAM_DEV_REL_ON_COMPLETE 0x04 111195534Sscottl#define CAM_DEV_REL_ON_QUEUE_EMPTY 0x08 112195534Sscottl#define CAM_DEV_RESIZE_QUEUE_NEEDED 0x10 113195534Sscottl#define CAM_DEV_TAG_AFTER_COUNT 0x20 114195534Sscottl#define CAM_DEV_INQUIRY_DATA_VALID 0x40 115195534Sscottl#define CAM_DEV_IN_DV 0x80 116195534Sscottl#define CAM_DEV_DV_HIT_BOTTOM 0x100 117198331Smav#define CAM_DEV_IDENTIFY_DATA_VALID 0x200 118195534Sscottl u_int32_t tag_delay_count; 119195534Sscottl#define CAM_TAG_DELAY_COUNT 5 120195534Sscottl u_int32_t tag_saved_openings; 121195534Sscottl u_int32_t refcount; 122195534Sscottl struct callout callout; 123195534Sscottl}; 124195534Sscottl 125195534Sscottl/* 126195534Sscottl * Each target is represented by an ET (Existing Target). These 127195534Sscottl * entries are created when a target is successfully probed with an 128195534Sscottl * identify, and removed when a device fails to respond after a number 129195534Sscottl * of retries, or a bus rescan finds the device missing. 130195534Sscottl */ 131195534Sscottlstruct cam_et { 132195534Sscottl TAILQ_HEAD(, cam_ed) ed_entries; 133195534Sscottl TAILQ_ENTRY(cam_et) links; 134195534Sscottl struct cam_eb *bus; 135195534Sscottl target_id_t target_id; 136195534Sscottl u_int32_t refcount; 137195534Sscottl u_int generation; 138195534Sscottl struct timeval last_reset; 139195534Sscottl}; 140195534Sscottl 141195534Sscottl/* 142195534Sscottl * Each bus is represented by an EB (Existing Bus). These entries 143195534Sscottl * are created by calls to xpt_bus_register and deleted by calls to 144195534Sscottl * xpt_bus_deregister. 145195534Sscottl */ 146195534Sscottlstruct cam_eb { 147195534Sscottl TAILQ_HEAD(, cam_et) et_entries; 148195534Sscottl TAILQ_ENTRY(cam_eb) links; 149195534Sscottl path_id_t path_id; 150195534Sscottl struct cam_sim *sim; 151195534Sscottl struct timeval last_reset; 152195534Sscottl u_int32_t flags; 153195534Sscottl#define CAM_EB_RUNQ_SCHEDULED 0x01 154195534Sscottl u_int32_t refcount; 155195534Sscottl u_int generation; 156195534Sscottl device_t parent_dev; 157195534Sscottl struct xpt_xport *xport; 158195534Sscottl}; 159195534Sscottl 160195534Sscottlstruct cam_path { 161195534Sscottl struct cam_periph *periph; 162195534Sscottl struct cam_eb *bus; 163195534Sscottl struct cam_et *target; 164195534Sscottl struct cam_ed *device; 165195534Sscottl}; 166195534Sscottl 167195534Sscottlstruct xpt_xport * scsi_get_xport(void); 168195534Sscottlstruct xpt_xport * ata_get_xport(void); 169195534Sscottl 170195534Sscottlstruct cam_ed * xpt_alloc_device(struct cam_eb *bus, 171195534Sscottl struct cam_et *target, 172195534Sscottl lun_id_t lun_id); 173198748Smavvoid xpt_acquire_device(struct cam_ed *device); 174198748Smavvoid xpt_release_device(struct cam_ed *device); 175195534Sscottlvoid xpt_run_dev_sendq(struct cam_eb *bus); 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