]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/cam/cam_xpt_internal.h
Merge libc++ trunk r300890, and update build glue.
[FreeBSD/FreeBSD.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 #include <sys/taskqueue.h>
33
34 /* Forward Declarations */
35 struct cam_eb;
36 struct cam_et;
37 struct cam_ed;
38
39 typedef struct cam_ed * (*xpt_alloc_device_func)(struct cam_eb *bus,
40                                                  struct cam_et *target,
41                                                  lun_id_t lun_id);
42 typedef void (*xpt_release_device_func)(struct cam_ed *device);
43 typedef void (*xpt_action_func)(union ccb *start_ccb);
44 typedef 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);
49 typedef void (*xpt_announce_periph_func)(struct cam_periph *periph);
50 typedef void (*xpt_announce_periph_sbuf_func)(struct cam_periph *periph, struct sbuf *sbuf);
51
52 struct xpt_xport_ops {
53         xpt_alloc_device_func   alloc_device;
54         xpt_release_device_func reldev;
55         xpt_action_func         action;
56         xpt_dev_async_func      async;
57         xpt_announce_periph_func announce;
58         xpt_announce_periph_sbuf_func announce_sbuf;
59 };
60
61 struct xpt_xport {
62         cam_xport               xport;
63         const char              *name;
64         struct xpt_xport_ops    *ops;
65 };
66
67 SET_DECLARE(cam_xpt_xport_set, struct xpt_xport);
68 #define CAM_XPT_XPORT(data)                             \
69         DATA_SET(cam_xpt_xport_set, data)
70
71 typedef void (*xpt_proto_announce_func)(struct cam_ed *);
72 typedef void (*xpt_proto_announce_sbuf_func)(struct cam_ed *, struct sbuf *);
73 typedef void (*xpt_proto_debug_out_func)(union ccb *);
74
75 struct xpt_proto_ops {
76         xpt_proto_announce_func announce;
77         xpt_proto_announce_sbuf_func    announce_sbuf;
78         xpt_proto_announce_func denounce;
79         xpt_proto_announce_sbuf_func    denounce_sbuf;
80         xpt_proto_debug_out_func debug_out;
81 };
82
83 struct xpt_proto {
84         cam_proto               proto;
85         const char              *name;
86         struct xpt_proto_ops    *ops;
87 };
88
89 SET_DECLARE(cam_xpt_proto_set, struct xpt_proto);
90 #define CAM_XPT_PROTO(data)                             \
91         DATA_SET(cam_xpt_proto_set, data)
92
93
94 /*
95  * The CAM EDT (Existing Device Table) contains the device information for
96  * all devices for all buses in the system.  The table contains a
97  * cam_ed structure for each device on the bus.
98  */
99 struct cam_ed {
100         cam_pinfo        devq_entry;
101         TAILQ_ENTRY(cam_ed) links;
102         struct  cam_et   *target;
103         struct  cam_sim  *sim;
104         lun_id_t         lun_id;
105         struct  cam_ccbq ccbq;          /* Queue of pending ccbs */
106         struct  async_list asyncs;      /* Async callback info for this B/T/L */
107         struct  periph_list periphs;    /* All attached devices */
108         u_int   generation;             /* Generation number */
109         void             *quirk;        /* Oddities about this device */
110         u_int            maxtags;
111         u_int            mintags;
112         cam_proto        protocol;
113         u_int            protocol_version;
114         cam_xport        transport;
115         u_int            transport_version;
116         struct           scsi_inquiry_data inq_data;
117         uint8_t          *supported_vpds;
118         uint8_t          supported_vpds_len;
119         uint32_t         device_id_len;
120         uint8_t          *device_id;
121         uint32_t         ext_inq_len;
122         uint8_t          *ext_inq;
123         uint8_t          physpath_len;
124         uint8_t          *physpath;     /* physical path string form */
125         uint32_t         rcap_len;
126         uint8_t          *rcap_buf;
127         struct           ata_params ident_data;
128         u_int8_t         inq_flags;     /*
129                                          * Current settings for inquiry flags.
130                                          * This allows us to override settings
131                                          * like disconnection and tagged
132                                          * queuing for a device.
133                                          */
134         u_int8_t         queue_flags;   /* Queue flags from the control page */
135         u_int8_t         serial_num_len;
136         u_int8_t        *serial_num;
137         u_int32_t        flags;
138 #define CAM_DEV_UNCONFIGURED            0x01
139 #define CAM_DEV_REL_TIMEOUT_PENDING     0x02
140 #define CAM_DEV_REL_ON_COMPLETE         0x04
141 #define CAM_DEV_REL_ON_QUEUE_EMPTY      0x08
142 #define CAM_DEV_TAG_AFTER_COUNT         0x20
143 #define CAM_DEV_INQUIRY_DATA_VALID      0x40
144 #define CAM_DEV_IN_DV                   0x80
145 #define CAM_DEV_DV_HIT_BOTTOM           0x100
146 #define CAM_DEV_IDENTIFY_DATA_VALID     0x200
147         u_int32_t        tag_delay_count;
148 #define CAM_TAG_DELAY_COUNT             5
149         u_int32_t        tag_saved_openings;
150         u_int32_t        refcount;
151         struct callout   callout;
152         STAILQ_ENTRY(cam_ed) highpowerq_entry;
153         struct mtx       device_mtx;
154         struct task      device_destroy_task;
155         const struct     nvme_controller_data *nvme_cdata;
156         const struct     nvme_namespace_data *nvme_data;
157 };
158
159 /*
160  * Each target is represented by an ET (Existing Target).  These
161  * entries are created when a target is successfully probed with an
162  * identify, and removed when a device fails to respond after a number
163  * of retries, or a bus rescan finds the device missing.
164  */
165 struct cam_et {
166         TAILQ_HEAD(, cam_ed) ed_entries;
167         TAILQ_ENTRY(cam_et) links;
168         struct  cam_eb  *bus;
169         target_id_t     target_id;
170         u_int32_t       refcount;
171         u_int           generation;
172         struct          timeval last_reset;
173         u_int           rpl_size;
174         struct scsi_report_luns_data *luns;
175         struct mtx      luns_mtx;       /* Protection for luns field. */
176 };
177
178 /*
179  * Each bus is represented by an EB (Existing Bus).  These entries
180  * are created by calls to xpt_bus_register and deleted by calls to
181  * xpt_bus_deregister.
182  */
183 struct cam_eb {
184         TAILQ_HEAD(, cam_et) et_entries;
185         TAILQ_ENTRY(cam_eb)  links;
186         path_id_t            path_id;
187         struct cam_sim       *sim;
188         struct timeval       last_reset;
189         u_int32_t            flags;
190 #define CAM_EB_RUNQ_SCHEDULED   0x01
191         u_int32_t            refcount;
192         u_int                generation;
193         device_t             parent_dev;
194         struct xpt_xport     *xport;
195         struct mtx           eb_mtx;    /* Bus topology mutex. */
196 };
197
198 struct cam_path {
199         struct cam_periph *periph;
200         struct cam_eb     *bus;
201         struct cam_et     *target;
202         struct cam_ed     *device;
203 };
204
205 struct cam_ed *         xpt_alloc_device(struct cam_eb *bus,
206                                          struct cam_et *target,
207                                          lun_id_t lun_id);
208 void                    xpt_acquire_device(struct cam_ed *device);
209 void                    xpt_release_device(struct cam_ed *device);
210 u_int32_t               xpt_dev_ccbq_resize(struct cam_path *path, int newopenings);
211 void                    xpt_start_tags(struct cam_path *path);
212 void                    xpt_stop_tags(struct cam_path *path);
213
214 MALLOC_DECLARE(M_CAMXPT);
215
216 #endif