]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/cam/ctl/ctl_frontend.h
MFC r268291:
[FreeBSD/stable/10.git] / sys / cam / ctl / ctl_frontend.h
1 /*-
2  * Copyright (c) 2003 Silicon Graphics International Corp.
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.
11  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12  *    substantially similar to the "NO WARRANTY" disclaimer below
13  *    ("Disclaimer") and any redistribution must be conditioned upon
14  *    including a substantially similar Disclaimer requirement for further
15  *    binary redistribution.
16  *
17  * NO WARRANTY
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGES.
29  *
30  * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_frontend.h#2 $
31  * $FreeBSD$
32  */
33 /*
34  * CAM Target Layer front end registration hooks
35  *
36  * Author: Ken Merry <ken@FreeBSD.org>
37  */
38
39 #ifndef _CTL_FRONTEND_H_
40 #define _CTL_FRONTEND_H_
41
42 typedef enum {
43         CTL_PORT_STATUS_NONE            = 0x00,
44         CTL_PORT_STATUS_ONLINE          = 0x01,
45         CTL_PORT_STATUS_TARG_ONLINE     = 0x02,
46         CTL_PORT_STATUS_LUN_ONLINE      = 0x04
47 } ctl_port_status;
48
49 typedef int (*fe_init_t)(void);
50 typedef void (*fe_shutdown_t)(void);
51 typedef void (*port_func_t)(void *onoff_arg);
52 typedef int (*targ_func_t)(void *arg, struct ctl_id targ_id);
53 typedef int (*lun_func_t)(void *arg, struct ctl_id targ_id, int lun_id);
54 typedef int (*fe_ioctl_t)(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
55                           struct thread *td);
56 typedef int (*fe_devid_t)(struct ctl_scsiio *ctsio, int alloc_len);
57
58 #define CTL_FRONTEND_DECLARE(name, driver) \
59         static int name ## _modevent(module_t mod, int type, void *data) \
60         { \
61                 switch (type) { \
62                 case MOD_LOAD: \
63                         ctl_frontend_register( \
64                                 (struct ctl_frontend *)data); \
65                         break; \
66                 case MOD_UNLOAD: \
67                         printf(#name " module unload - not possible for this module type\n"); \
68                         return EINVAL; \
69                 default: \
70                         return EOPNOTSUPP; \
71                 } \
72                 return 0; \
73         } \
74         static moduledata_t name ## _mod = { \
75                 #name, \
76                 name ## _modevent, \
77                 (void *)&driver \
78         }; \
79         DECLARE_MODULE(name, name ## _mod, SI_SUB_CONFIGURE, SI_ORDER_FOURTH); \
80         MODULE_DEPEND(name, ctl, 1, 1, 1); \
81         MODULE_DEPEND(name, cam, 1, 1, 1)
82
83 /*
84  * The ctl_frontend structure is the registration mechanism between a FETD
85  * (Front End Target Driver) and the CTL layer.  Here is a description of
86  * the fields:
87  *
88  * port_type:             This field tells CTL what kind of front end it is
89  *                        dealing with.  This field serves two purposes.
90  *                        The first is to let CTL know whether the frontend
91  *                        in question is inside the main CTL module (i.e.
92  *                        the ioctl front end), and therefore its module
93  *                        reference count shouldn't be incremented.  The
94  *                        CTL ioctl front end should continue to use the
95  *                        CTL_PORT_IOCTL argument as long as it is part of
96  *                        the main CTL module.  The second is to let CTL
97  *                        know what kind of front end it is dealing with, so
98  *                        it can return the proper inquiry data for that
99  *                        particular port.
100  *
101  * num_requested_ctl_io:  This is the number of ctl_io structures that the
102  *                        front end needs for its pool.  This should
103  *                        generally be the maximum number of outstanding
104  *                        transactions that the FETD can handle.  The CTL
105  *                        layer will add a few to this to account for
106  *                        ctl_io buffers queued for pending sense data.
107  *                        (Pending sense only gets queued if the FETD
108  *                        doesn't support autosense.  e.g. non-packetized
109  *                        parallel SCSI doesn't support autosense.)
110  *
111  * port_name:             A string describing the FETD.  e.g. "LSI 1030T U320"
112  *                        or whatever you want to use to describe the driver.
113  *
114  *
115  * physical_port:         This is the physical port number of this
116  *                        particular port within the driver/hardware.  This
117  *                        number is hardware/driver specific.
118  * virtual_port:          This is the virtual port number of this
119  *                        particular port.  This is for things like NP-IV.
120  * 
121  * port_online():         This function is called, with onoff_arg as its
122  *                        argument, by the CTL layer when it wants the FETD
123  *                        to start responding to selections on the specified
124  *                        target ID.  (targ_target)
125  *
126  * port_offline():        This function is called, with onoff_arg as its
127  *                        argument, by the CTL layer when it wants the FETD
128  *                        to stop responding to selection on the specified
129  *                        target ID.  (targ_target)
130  *
131  * onoff_arg:             This is supplied as an argument to port_online()
132  *                        and port_offline().  This is specified by the
133  *                        FETD.
134  *
135  * lun_enable():          This function is called, with targ_lun_arg, a target
136  *                        ID and a LUN ID as its arguments, by CTL when it
137  *                        wants the FETD to enable a particular LUN.  If the
138  *                        FETD doesn't really know about LUNs, it should
139  *                        just ignore this call and return 0.  If the FETD
140  *                        cannot enable the requested LUN for some reason, the
141  *                        FETD should return non-zero status.
142  *
143  * lun_disable():         This function is called, with targ_lun_arg, a target
144  *                        ID and LUN ID as its arguments, by CTL when it
145  *                        wants the FETD to disable a particular LUN.  If the
146  *                        FETD doesn't really know about LUNs, it should just
147  *                        ignore this call and return 0.  If the FETD cannot
148  *                        disable the requested LUN for some reason, the
149  *                        FETD should return non-zero status.
150  *
151  * targ_lun_arg:          This is supplied as an argument to the targ/lun
152  *                        enable/disable() functions.  This is specified by
153  *                        the FETD.
154  *
155  * fe_datamove():         This function is called one or more times per I/O
156  *                        by the CTL layer to tell the FETD to initiate a
157  *                        DMA to or from the data buffer(s) specified by
158  *                        the passed-in ctl_io structure.
159  *
160  * fe_done():             This function is called by the CTL layer when a
161  *                        particular SCSI I/O or task management command has
162  *                        completed.  For SCSI I/O requests (CTL_IO_SCSI),
163  *                        sense data is always supplied if the status is
164  *                        CTL_SCSI_ERROR and the SCSI status byte is
165  *                        SCSI_STATUS_CHECK_COND.  If the FETD doesn't
166  *                        support autosense, the sense should be queued
167  *                        back to the CTL layer via ctl_queue_sense().
168  *
169  * fe_dump():             This function, if it exists, is called by CTL
170  *                        to request a dump of any debugging information or
171  *                        state to the console.
172  *
173  * max_targets:           The maximum number of targets that we can create
174  *                        per-port.
175  *
176  * max_target_id:         The highest target ID that we can use.
177  *
178  * targ_port:             The CTL layer assigns a "port number" to every
179  *                        FETD.  This port number should be passed back in
180  *                        in the header of every ctl_io that is queued to
181  *                        the CTL layer.  This enables us to determine
182  *                        which bus the command came in on.
183  *
184  * ctl_pool_ref:          Memory pool reference used by the FETD in calls to
185  *                        ctl_alloc_io().
186  *
187  * max_initiators:        Maximum number of initiators that the FETD is
188  *                        allowed to have.  Initiators should be numbered
189  *                        from 0 to max_initiators - 1.  This value will
190  *                        typically be 16, and thus not a problem for
191  *                        parallel SCSI.  This may present issues for Fibre
192  *                        Channel.
193  *
194  * wwnn                   World Wide Node Name to be used by the FETD.
195  *                        Note that this is set *after* registration.  It
196  *                        will be set prior to the online function getting
197  *                        called.
198  *
199  * wwpn                   World Wide Port Name to be used by the FETD.
200  *                        Note that this is set *after* registration.  It
201  *                        will be set prior to the online function getting
202  *                        called.
203  *
204  * status:                Used by CTL to keep track of per-FETD state.
205  *
206  * links:                 Linked list pointers, used by CTL.  The FETD
207  *                        shouldn't touch this field.
208  */
209 struct ctl_port {
210         struct ctl_frontend *frontend;
211         ctl_port_type   port_type;              /* passed to CTL */
212         int             num_requested_ctl_io;   /* passed to CTL */
213         char            *port_name;             /* passed to CTL */
214         int             physical_port;          /* passed to CTL */
215         int             virtual_port;           /* passed to CTL */
216         port_func_t     port_online;            /* passed to CTL */
217         port_func_t     port_offline;           /* passed to CTL */
218         void            *onoff_arg;             /* passed to CTL */
219         lun_func_t      lun_enable;             /* passed to CTL */
220         lun_func_t      lun_disable;            /* passed to CTL */
221         fe_devid_t      devid;                  /* passed to CTL */
222         void            *targ_lun_arg;          /* passed to CTL */
223         void            (*fe_datamove)(union ctl_io *io); /* passed to CTL */
224         void            (*fe_done)(union ctl_io *io); /* passed to CTL */
225         int             max_targets;            /* passed to CTL */
226         int             max_target_id;          /* passed to CTL */
227         int32_t         targ_port;              /* passed back to FETD */
228         void            *ctl_pool_ref;          /* passed back to FETD */
229         uint32_t        max_initiators;         /* passed back to FETD */
230         uint64_t        wwnn;                   /* set by CTL before online */
231         uint64_t        wwpn;                   /* set by CTL before online */
232         ctl_port_status status;                 /* used by CTL */
233         ctl_options_t   options;                /* passed to CTL */
234         STAILQ_ENTRY(ctl_port) fe_links;        /* used by CTL */
235         STAILQ_ENTRY(ctl_port) links;           /* used by CTL */
236 };
237
238 struct ctl_frontend {
239         char            name[CTL_DRIVER_NAME_LEN];      /* passed to CTL */
240         fe_init_t       init;                   /* passed to CTL */
241         fe_ioctl_t      ioctl;                  /* passed to CTL */
242         void            (*fe_dump)(void);       /* passed to CTL */
243         fe_shutdown_t   shutdown;               /* passed to CTL */
244         STAILQ_HEAD(, ctl_port) port_list;      /* used by CTL */
245         STAILQ_ENTRY(ctl_frontend) links;       /* used by CTL */
246 };
247
248 /*
249  * This may block until resources are allocated.  Called at FETD module load
250  * time. Returns 0 for success, non-zero for failure.
251  */
252 int ctl_frontend_register(struct ctl_frontend *fe);
253
254 /*
255  * Called at FETD module unload time.
256  * Returns 0 for success, non-zero for failure.
257  */
258 int ctl_frontend_deregister(struct ctl_frontend *fe);
259
260 /*
261  * Find the frontend by its name. Returns NULL if not found.
262  */
263 struct ctl_frontend * ctl_frontend_find(char *frontend_name);
264
265 /*
266  * This may block until resources are allocated.  Called at FETD module load
267  * time. Returns 0 for success, non-zero for failure.
268  */
269 int ctl_port_register(struct ctl_port *fe, int master_SC);
270
271 /*
272  * Called at FETD module unload time.
273  * Returns 0 for success, non-zero for failure.
274  */
275 int ctl_port_deregister(struct ctl_port *fe);
276
277 /*
278  * Called to set the WWNN and WWPN for a particular frontend.
279  */
280 void ctl_port_set_wwns(struct ctl_port *port, int wwnn_valid,
281                            uint64_t wwnn, int wwpn_valid, uint64_t wwpn);
282
283 /*
284  * Called to bring a particular frontend online.
285  */
286 void ctl_port_online(struct ctl_port *fe);
287
288 /*
289  * Called to take a particular frontend offline.
290  */
291 void ctl_port_offline(struct ctl_port *fe);
292
293 /*
294  * This routine queues I/O and task management requests from the FETD to the
295  * CTL layer.  Returns immediately.  Returns 0 for success, non-zero for
296  * failure.
297  */
298 int ctl_queue(union ctl_io *io);
299
300 /*
301  * This routine is used if the front end interface doesn't support
302  * autosense (e.g. non-packetized parallel SCSI).  This will queue the
303  * scsiio structure back to a per-lun pending sense queue.  This MUST be
304  * called BEFORE any request sense can get queued to the CTL layer -- I
305  * need it in the queue in order to service the request.  The scsiio
306  * structure passed in here will be freed by the CTL layer when sense is
307  * retrieved by the initiator.  Returns 0 for success, non-zero for failure.
308  */
309 int ctl_queue_sense(union ctl_io *io);
310
311 /*
312  * This routine adds an initiator to CTL's port database.  The WWPN should
313  * be the FC WWPN, if available.  The targ_port field should be the same as
314  * the targ_port passed back from CTL in the ctl_frontend structure above.
315  * The iid field should be the same as the iid passed in the nexus of each
316  * ctl_io from this initiator.
317  */
318 int ctl_add_initiator(uint64_t wwpn, int32_t targ_port, uint32_t iid);
319
320 /*
321  * This routine will remove an initiator from CTL's port database.  The
322  * targ_port field should be the same as the targ_port passed back in the
323  * ctl_frontend structure above.  The iid field should be the same as the
324  * iid passed in the nexus of each ctl_io from this initiator.
325  */
326 int
327 ctl_remove_initiator(int32_t targ_port, uint32_t iid);
328
329 #endif  /* _CTL_FRONTEND_H_ */