1229997Sken/*- 2229997Sken * Copyright (c) 2003 Silicon Graphics International Corp. 3229997Sken * All rights reserved. 4229997Sken * 5229997Sken * Redistribution and use in source and binary forms, with or without 6229997Sken * modification, are permitted provided that the following conditions 7229997Sken * are met: 8229997Sken * 1. Redistributions of source code must retain the above copyright 9229997Sken * notice, this list of conditions, and the following disclaimer, 10229997Sken * without modification. 11229997Sken * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12229997Sken * substantially similar to the "NO WARRANTY" disclaimer below 13229997Sken * ("Disclaimer") and any redistribution must be conditioned upon 14229997Sken * including a substantially similar Disclaimer requirement for further 15229997Sken * binary redistribution. 16229997Sken * 17229997Sken * NO WARRANTY 18229997Sken * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19229997Sken * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20229997Sken * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 21229997Sken * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22229997Sken * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23229997Sken * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24229997Sken * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25229997Sken * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26229997Sken * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 27229997Sken * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28229997Sken * POSSIBILITY OF SUCH DAMAGES. 29229997Sken * 30229997Sken * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_frontend.h#2 $ 31229997Sken * $FreeBSD$ 32229997Sken */ 33229997Sken/* 34229997Sken * CAM Target Layer front end registration hooks 35229997Sken * 36229997Sken * Author: Ken Merry <ken@FreeBSD.org> 37229997Sken */ 38229997Sken 39229997Sken#ifndef _CTL_FRONTEND_H_ 40229997Sken#define _CTL_FRONTEND_H_ 41229997Sken 42229997Skentypedef enum { 43229997Sken CTL_PORT_STATUS_NONE = 0x00, 44229997Sken CTL_PORT_STATUS_ONLINE = 0x01, 45229997Sken CTL_PORT_STATUS_TARG_ONLINE = 0x02, 46229997Sken CTL_PORT_STATUS_LUN_ONLINE = 0x04 47229997Sken} ctl_port_status; 48229997Sken 49229997Skentypedef void (*port_func_t)(void *onoff_arg); 50229997Skentypedef int (*targ_func_t)(void *arg, struct ctl_id targ_id); 51229997Skentypedef int (*lun_func_t)(void *arg, struct ctl_id targ_id, int lun_id); 52254759Strasztypedef int (*fe_ioctl_t)(struct cdev *dev, u_long cmd, caddr_t addr, int flag, 53254759Strasz struct thread *td); 54254759Strasztypedef int (*fe_devid_t)(struct ctl_scsiio *ctsio, int alloc_len); 55229997Sken 56229997Sken/* 57229997Sken * The ctl_frontend structure is the registration mechanism between a FETD 58229997Sken * (Front End Target Driver) and the CTL layer. Here is a description of 59229997Sken * the fields: 60229997Sken * 61229997Sken * port_type: This field tells CTL what kind of front end it is 62229997Sken * dealing with. This field serves two purposes. 63229997Sken * The first is to let CTL know whether the frontend 64229997Sken * in question is inside the main CTL module (i.e. 65229997Sken * the ioctl front end), and therefore its module 66229997Sken * reference count shouldn't be incremented. The 67229997Sken * CTL ioctl front end should continue to use the 68229997Sken * CTL_PORT_IOCTL argument as long as it is part of 69229997Sken * the main CTL module. The second is to let CTL 70229997Sken * know what kind of front end it is dealing with, so 71229997Sken * it can return the proper inquiry data for that 72229997Sken * particular port. 73229997Sken * 74229997Sken * num_requested_ctl_io: This is the number of ctl_io structures that the 75229997Sken * front end needs for its pool. This should 76229997Sken * generally be the maximum number of outstanding 77229997Sken * transactions that the FETD can handle. The CTL 78229997Sken * layer will add a few to this to account for 79229997Sken * ctl_io buffers queued for pending sense data. 80229997Sken * (Pending sense only gets queued if the FETD 81229997Sken * doesn't support autosense. e.g. non-packetized 82229997Sken * parallel SCSI doesn't support autosense.) 83229997Sken * 84229997Sken * port_name: A string describing the FETD. e.g. "LSI 1030T U320" 85229997Sken * or whatever you want to use to describe the driver. 86229997Sken * 87229997Sken * 88229997Sken * physical_port: This is the physical port number of this 89229997Sken * particular port within the driver/hardware. This 90229997Sken * number is hardware/driver specific. 91229997Sken * virtual_port: This is the virtual port number of this 92229997Sken * particular port. This is for things like NP-IV. 93229997Sken * 94229997Sken * port_online(): This function is called, with onoff_arg as its 95229997Sken * argument, by the CTL layer when it wants the FETD 96229997Sken * to start responding to selections on the specified 97229997Sken * target ID. (targ_target) 98229997Sken * 99229997Sken * port_offline(): This function is called, with onoff_arg as its 100229997Sken * argument, by the CTL layer when it wants the FETD 101229997Sken * to stop responding to selection on the specified 102229997Sken * target ID. (targ_target) 103229997Sken * 104229997Sken * onoff_arg: This is supplied as an argument to port_online() 105229997Sken * and port_offline(). This is specified by the 106229997Sken * FETD. 107229997Sken * 108229997Sken * targ_enable(): This function is called, with targ_lun_arg and a 109229997Sken * target ID as its arguments, by CTL when it wants 110229997Sken * the FETD to enable a particular target. targ_enable() 111229997Sken * will always be called for a particular target ID 112229997Sken * before any LUN is enabled for that target. If the 113229997Sken * FETD does not support enabling targets, but rather 114229997Sken * LUNs, it should ignore this call and return 0. If 115229997Sken * the FETD does support enabling targets, it should 116229997Sken * return 0 for success and non-zero if it cannot 117229997Sken * enable the given target. 118229997Sken * 119229997Sken * TODO: Add the ability to specify a WWID here. 120229997Sken * 121229997Sken * targ_disable(): This function is called, with targ_lun_arg and a 122229997Sken * target ID as its arguments, by CTL when it wants 123229997Sken * the FETD to disable a particular target. 124229997Sken * targ_disable() will always be called for a 125229997Sken * particular target ID after all LUNs are disabled 126229997Sken * on that particular target. If the FETD does not 127229997Sken * support enabling targets, it should ignore this 128229997Sken * call and return 0. If the FETD does support 129229997Sken * enabling targets, it should return 0 for success, 130229997Sken * and non-zero if it cannot disable the given target. 131229997Sken * 132229997Sken * lun_enable(): This function is called, with targ_lun_arg, a target 133229997Sken * ID and a LUN ID as its arguments, by CTL when it 134229997Sken * wants the FETD to enable a particular LUN. If the 135229997Sken * FETD doesn't really know about LUNs, it should 136229997Sken * just ignore this call and return 0. If the FETD 137229997Sken * cannot enable the requested LUN for some reason, the 138229997Sken * FETD should return non-zero status. 139229997Sken * 140229997Sken * lun_disable(): This function is called, with targ_lun_arg, a target 141229997Sken * ID and LUN ID as its arguments, by CTL when it 142229997Sken * wants the FETD to disable a particular LUN. If the 143229997Sken * FETD doesn't really know about LUNs, it should just 144229997Sken * ignore this call and return 0. If the FETD cannot 145229997Sken * disable the requested LUN for some reason, the 146229997Sken * FETD should return non-zero status. 147229997Sken * 148229997Sken * targ_lun_arg: This is supplied as an argument to the targ/lun 149229997Sken * enable/disable() functions. This is specified by 150229997Sken * the FETD. 151229997Sken * 152229997Sken * fe_datamove(): This function is called one or more times per I/O 153229997Sken * by the CTL layer to tell the FETD to initiate a 154229997Sken * DMA to or from the data buffer(s) specified by 155229997Sken * the passed-in ctl_io structure. 156229997Sken * 157229997Sken * fe_done(): This function is called by the CTL layer when a 158229997Sken * particular SCSI I/O or task management command has 159229997Sken * completed. For SCSI I/O requests (CTL_IO_SCSI), 160229997Sken * sense data is always supplied if the status is 161229997Sken * CTL_SCSI_ERROR and the SCSI status byte is 162229997Sken * SCSI_STATUS_CHECK_COND. If the FETD doesn't 163229997Sken * support autosense, the sense should be queued 164229997Sken * back to the CTL layer via ctl_queue_sense(). 165229997Sken * 166229997Sken * fe_dump(): This function, if it exists, is called by CTL 167229997Sken * to request a dump of any debugging information or 168229997Sken * state to the console. 169229997Sken * 170229997Sken * max_targets: The maximum number of targets that we can create 171229997Sken * per-port. 172229997Sken * 173229997Sken * max_target_id: The highest target ID that we can use. 174229997Sken * 175229997Sken * targ_port: The CTL layer assigns a "port number" to every 176229997Sken * FETD. This port number should be passed back in 177229997Sken * in the header of every ctl_io that is queued to 178229997Sken * the CTL layer. This enables us to determine 179229997Sken * which bus the command came in on. 180229997Sken * 181229997Sken * ctl_pool_ref: Memory pool reference used by the FETD in calls to 182229997Sken * ctl_alloc_io(). 183229997Sken * 184229997Sken * max_initiators: Maximum number of initiators that the FETD is 185229997Sken * allowed to have. Initiators should be numbered 186229997Sken * from 0 to max_initiators - 1. This value will 187229997Sken * typically be 16, and thus not a problem for 188229997Sken * parallel SCSI. This may present issues for Fibre 189229997Sken * Channel. 190229997Sken * 191229997Sken * wwnn World Wide Node Name to be used by the FETD. 192229997Sken * Note that this is set *after* registration. It 193229997Sken * will be set prior to the online function getting 194229997Sken * called. 195229997Sken * 196229997Sken * wwpn World Wide Port Name to be used by the FETD. 197229997Sken * Note that this is set *after* registration. It 198229997Sken * will be set prior to the online function getting 199229997Sken * called. 200229997Sken * 201229997Sken * status: Used by CTL to keep track of per-FETD state. 202229997Sken * 203229997Sken * links: Linked list pointers, used by CTL. The FETD 204229997Sken * shouldn't touch this field. 205229997Sken */ 206229997Skenstruct ctl_frontend { 207229997Sken ctl_port_type port_type; /* passed to CTL */ 208229997Sken int num_requested_ctl_io; /* passed to CTL */ 209229997Sken char *port_name; /* passed to CTL */ 210229997Sken int physical_port; /* passed to CTL */ 211229997Sken int virtual_port; /* passed to CTL */ 212229997Sken port_func_t port_online; /* passed to CTL */ 213229997Sken port_func_t port_offline; /* passed to CTL */ 214229997Sken void *onoff_arg; /* passed to CTL */ 215229997Sken targ_func_t targ_enable; /* passed to CTL */ 216229997Sken targ_func_t targ_disable; /* passed to CTL */ 217229997Sken lun_func_t lun_enable; /* passed to CTL */ 218229997Sken lun_func_t lun_disable; /* passed to CTL */ 219254759Strasz fe_ioctl_t ioctl; /* passed to CTL */ 220254759Strasz fe_devid_t devid; /* passed to CTL */ 221229997Sken void *targ_lun_arg; /* passed to CTL */ 222229997Sken void (*fe_datamove)(union ctl_io *io); /* passed to CTL */ 223229997Sken void (*fe_done)(union ctl_io *io); /* passed to CTL */ 224229997Sken void (*fe_dump)(void); /* passed to CTL */ 225229997Sken int max_targets; /* passed to CTL */ 226229997Sken int max_target_id; /* passed to CTL */ 227229997Sken int32_t targ_port; /* passed back to FETD */ 228229997Sken void *ctl_pool_ref; /* passed back to FETD */ 229229997Sken uint32_t max_initiators; /* passed back to FETD */ 230229997Sken uint64_t wwnn; /* set by CTL before online */ 231229997Sken uint64_t wwpn; /* set by CTL before online */ 232229997Sken ctl_port_status status; /* used by CTL */ 233229997Sken STAILQ_ENTRY(ctl_frontend) links; /* used by CTL */ 234229997Sken}; 235229997Sken 236229997Sken/* 237229997Sken * This may block until resources are allocated. Called at FETD module load 238229997Sken * time. Returns 0 for success, non-zero for failure. 239229997Sken */ 240229997Skenint ctl_frontend_register(struct ctl_frontend *fe, int master_SC); 241229997Sken 242229997Sken/* 243229997Sken * Called at FETD module unload time. 244229997Sken * Returns 0 for success, non-zero for failure. 245229997Sken */ 246229997Skenint ctl_frontend_deregister(struct ctl_frontend *fe); 247229997Sken 248229997Sken/* 249229997Sken * Called to set the WWNN and WWPN for a particular frontend. 250229997Sken */ 251229997Skenvoid ctl_frontend_set_wwns(struct ctl_frontend *fe, int wwnn_valid, 252229997Sken uint64_t wwnn, int wwpn_valid, uint64_t wwpn); 253229997Sken 254229997Sken/* 255229997Sken * Called to bring a particular frontend online. 256229997Sken */ 257229997Skenvoid ctl_frontend_online(struct ctl_frontend *fe); 258229997Sken 259229997Sken/* 260229997Sken * Called to take a particular frontend offline. 261229997Sken */ 262229997Skenvoid ctl_frontend_offline(struct ctl_frontend *fe); 263229997Sken 264229997Sken/* 265229997Sken * This routine queues I/O and task management requests from the FETD to the 266229997Sken * CTL layer. Returns immediately. Returns 0 for success, non-zero for 267229997Sken * failure. 268229997Sken */ 269229997Skenint ctl_queue(union ctl_io *io); 270229997Sken 271229997Sken/* 272229997Sken * This routine is used if the front end interface doesn't support 273229997Sken * autosense (e.g. non-packetized parallel SCSI). This will queue the 274229997Sken * scsiio structure back to a per-lun pending sense queue. This MUST be 275229997Sken * called BEFORE any request sense can get queued to the CTL layer -- I 276229997Sken * need it in the queue in order to service the request. The scsiio 277229997Sken * structure passed in here will be freed by the CTL layer when sense is 278229997Sken * retrieved by the initiator. Returns 0 for success, non-zero for failure. 279229997Sken */ 280229997Skenint ctl_queue_sense(union ctl_io *io); 281229997Sken 282229997Sken/* 283229997Sken * This routine adds an initiator to CTL's port database. The WWPN should 284229997Sken * be the FC WWPN, if available. The targ_port field should be the same as 285229997Sken * the targ_port passed back from CTL in the ctl_frontend structure above. 286229997Sken * The iid field should be the same as the iid passed in the nexus of each 287229997Sken * ctl_io from this initiator. 288229997Sken */ 289229997Skenint ctl_add_initiator(uint64_t wwpn, int32_t targ_port, uint32_t iid); 290229997Sken 291229997Sken/* 292229997Sken * This routine will remove an initiator from CTL's port database. The 293229997Sken * targ_port field should be the same as the targ_port passed back in the 294229997Sken * ctl_frontend structure above. The iid field should be the same as the 295229997Sken * iid passed in the nexus of each ctl_io from this initiator. 296229997Sken */ 297229997Skenint 298229997Skenctl_remove_initiator(int32_t targ_port, uint32_t iid); 299229997Sken 300229997Sken#endif /* _CTL_FRONTEND_H_ */ 301