]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/cam/cam_xpt_internal.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / cam / cam_xpt_internal.h
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$
27  */
28
29 #ifndef _CAM_CAM_XPT_INTERNAL_H
30 #define _CAM_CAM_XPT_INTERNAL_H 1
31
32 /* Forward Declarations */
33 struct cam_eb;
34 struct cam_et;
35 struct cam_ed;
36
37 typedef struct cam_ed * (*xpt_alloc_device_func)(struct cam_eb *bus,
38                                                  struct cam_et *target,
39                                                  lun_id_t lun_id);
40 typedef void (*xpt_release_device_func)(struct cam_ed *device);
41 typedef void (*xpt_action_func)(union ccb *start_ccb);
42 typedef void (*xpt_dev_async_func)(u_int32_t async_code,
43                                    struct cam_eb *bus,
44                                    struct cam_et *target,
45                                    struct cam_ed *device,
46                                    void *async_arg);
47 typedef void (*xpt_announce_periph_func)(struct cam_periph *periph);
48
49 struct xpt_xport {
50         xpt_alloc_device_func   alloc_device;
51         xpt_release_device_func reldev;
52         xpt_action_func         action;
53         xpt_dev_async_func      async;
54         xpt_announce_periph_func announce;
55 };
56
57 /*
58  * Structure for queueing a device in a run queue.
59  * There is one run queue for allocating new ccbs,
60  * and another for sending ccbs to the controller.
61  */
62 struct cam_ed_qinfo {
63         cam_pinfo pinfo;
64         struct    cam_ed *device;
65 };
66
67 /*
68  * The CAM EDT (Existing Device Table) contains the device information for
69  * all devices for all busses in the system.  The table contains a
70  * cam_ed structure for each device on the bus.
71  */
72 struct cam_ed {
73         TAILQ_ENTRY(cam_ed) links;
74         struct  cam_ed_qinfo devq_entry;
75         struct  cam_et   *target;
76         struct  cam_sim  *sim;
77         lun_id_t         lun_id;
78         struct  camq drvq;              /*
79                                          * Queue of type drivers wanting to do
80                                          * work on this device.
81                                          */
82         struct  cam_ccbq ccbq;          /* Queue of pending ccbs */
83         struct  async_list asyncs;      /* Async callback info for this B/T/L */
84         struct  periph_list periphs;    /* All attached devices */
85         u_int   generation;             /* Generation number */
86         void             *quirk;        /* Oddities about this device */
87         u_int            maxtags;
88         u_int            mintags;
89         cam_proto        protocol;
90         u_int            protocol_version;
91         cam_xport        transport;
92         u_int            transport_version;
93         struct           scsi_inquiry_data inq_data;
94         uint8_t          *supported_vpds;
95         uint8_t          supported_vpds_len;
96         uint32_t         device_id_len;
97         uint8_t          *device_id;
98         uint8_t          physpath_len;
99         uint8_t          *physpath;     /* physical path string form */
100         uint32_t         rcap_len;
101         uint8_t          *rcap_buf;
102         struct           ata_params ident_data;
103         u_int8_t         inq_flags;     /*
104                                          * Current settings for inquiry flags.
105                                          * This allows us to override settings
106                                          * like disconnection and tagged
107                                          * queuing for a device.
108                                          */
109         u_int8_t         queue_flags;   /* Queue flags from the control page */
110         u_int8_t         serial_num_len;
111         u_int8_t        *serial_num;
112         u_int32_t        flags;
113 #define CAM_DEV_UNCONFIGURED            0x01
114 #define CAM_DEV_REL_TIMEOUT_PENDING     0x02
115 #define CAM_DEV_REL_ON_COMPLETE         0x04
116 #define CAM_DEV_REL_ON_QUEUE_EMPTY      0x08
117 #define CAM_DEV_TAG_AFTER_COUNT         0x20
118 #define CAM_DEV_INQUIRY_DATA_VALID      0x40
119 #define CAM_DEV_IN_DV                   0x80
120 #define CAM_DEV_DV_HIT_BOTTOM           0x100
121 #define CAM_DEV_IDENTIFY_DATA_VALID     0x200
122         u_int32_t        tag_delay_count;
123 #define CAM_TAG_DELAY_COUNT             5
124         u_int32_t        tag_saved_openings;
125         u_int32_t        refcount;
126         struct callout   callout;
127         STAILQ_ENTRY(cam_ed) highpowerq_entry;
128 };
129
130 /*
131  * Each target is represented by an ET (Existing Target).  These
132  * entries are created when a target is successfully probed with an
133  * identify, and removed when a device fails to respond after a number
134  * of retries, or a bus rescan finds the device missing.
135  */
136 struct cam_et {
137         TAILQ_HEAD(, cam_ed) ed_entries;
138         TAILQ_ENTRY(cam_et) links;
139         struct  cam_eb  *bus;
140         target_id_t     target_id;
141         u_int32_t       refcount;
142         u_int           generation;
143         struct          timeval last_reset;
144         u_int           rpl_size;
145         struct scsi_report_luns_data *luns;
146 };
147
148 /*
149  * Each bus is represented by an EB (Existing Bus).  These entries
150  * are created by calls to xpt_bus_register and deleted by calls to
151  * xpt_bus_deregister.
152  */
153 struct cam_eb {
154         TAILQ_HEAD(, cam_et) et_entries;
155         TAILQ_ENTRY(cam_eb)  links;
156         path_id_t            path_id;
157         struct cam_sim       *sim;
158         struct timeval       last_reset;
159         u_int32_t            flags;
160 #define CAM_EB_RUNQ_SCHEDULED   0x01
161         u_int32_t            refcount;
162         u_int                generation;
163         device_t             parent_dev;
164         struct xpt_xport     *xport;
165 };
166
167 struct cam_path {
168         struct cam_periph *periph;
169         struct cam_eb     *bus;
170         struct cam_et     *target;
171         struct cam_ed     *device;
172 };
173
174 struct xpt_xport *      scsi_get_xport(void);
175 struct xpt_xport *      ata_get_xport(void);
176
177 struct cam_ed *         xpt_alloc_device(struct cam_eb *bus,
178                                          struct cam_et *target,
179                                          lun_id_t lun_id);
180 void                    xpt_acquire_device(struct cam_ed *device);
181 void                    xpt_release_device(struct cam_ed *device);
182 int                     xpt_schedule_dev(struct camq *queue, cam_pinfo *dev_pinfo,
183                                          u_int32_t new_priority);
184 u_int32_t               xpt_dev_ccbq_resize(struct cam_path *path, int newopenings);
185 void                    xpt_start_tags(struct cam_path *path);
186 void                    xpt_stop_tags(struct cam_path *path);
187
188 MALLOC_DECLARE(M_CAMXPT);
189
190 #endif