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