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