ctl_frontend.h revision 268688
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: stable/10/sys/cam/ctl/ctl_frontend.h 268688 2014-07-15 17:10:48Z mav $ 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 49268677Smavtypedef int (*fe_init_t)(void); 50268677Smavtypedef void (*fe_shutdown_t)(void); 51229997Skentypedef void (*port_func_t)(void *onoff_arg); 52268688Smavtypedef int (*port_info_func_t)(void *onoff_arg, struct sbuf *sb); 53229997Skentypedef int (*lun_func_t)(void *arg, struct ctl_id targ_id, int lun_id); 54268685Smavtypedef uint32_t (*lun_map_func_t)(void *arg, uint32_t lun_id); 55254759Strasztypedef int (*fe_ioctl_t)(struct cdev *dev, u_long cmd, caddr_t addr, int flag, 56254759Strasz struct thread *td); 57229997Sken 58268677Smav#define CTL_FRONTEND_DECLARE(name, driver) \ 59268677Smav static int name ## _modevent(module_t mod, int type, void *data) \ 60268677Smav { \ 61268677Smav switch (type) { \ 62268677Smav case MOD_LOAD: \ 63268677Smav ctl_frontend_register( \ 64268677Smav (struct ctl_frontend *)data); \ 65268677Smav break; \ 66268677Smav case MOD_UNLOAD: \ 67268677Smav printf(#name " module unload - not possible for this module type\n"); \ 68268677Smav return EINVAL; \ 69268677Smav default: \ 70268677Smav return EOPNOTSUPP; \ 71268677Smav } \ 72268677Smav return 0; \ 73268677Smav } \ 74268677Smav static moduledata_t name ## _mod = { \ 75268677Smav #name, \ 76268677Smav name ## _modevent, \ 77268677Smav (void *)&driver \ 78268677Smav }; \ 79268677Smav DECLARE_MODULE(name, name ## _mod, SI_SUB_CONFIGURE, SI_ORDER_FOURTH); \ 80268677Smav MODULE_DEPEND(name, ctl, 1, 1, 1); \ 81268677Smav MODULE_DEPEND(name, cam, 1, 1, 1) 82268677Smav 83229997Sken/* 84229997Sken * The ctl_frontend structure is the registration mechanism between a FETD 85229997Sken * (Front End Target Driver) and the CTL layer. Here is a description of 86229997Sken * the fields: 87229997Sken * 88229997Sken * port_type: This field tells CTL what kind of front end it is 89229997Sken * dealing with. This field serves two purposes. 90229997Sken * The first is to let CTL know whether the frontend 91229997Sken * in question is inside the main CTL module (i.e. 92229997Sken * the ioctl front end), and therefore its module 93229997Sken * reference count shouldn't be incremented. The 94229997Sken * CTL ioctl front end should continue to use the 95229997Sken * CTL_PORT_IOCTL argument as long as it is part of 96229997Sken * the main CTL module. The second is to let CTL 97229997Sken * know what kind of front end it is dealing with, so 98229997Sken * it can return the proper inquiry data for that 99229997Sken * particular port. 100229997Sken * 101229997Sken * num_requested_ctl_io: This is the number of ctl_io structures that the 102229997Sken * front end needs for its pool. This should 103229997Sken * generally be the maximum number of outstanding 104229997Sken * transactions that the FETD can handle. The CTL 105229997Sken * layer will add a few to this to account for 106229997Sken * ctl_io buffers queued for pending sense data. 107229997Sken * (Pending sense only gets queued if the FETD 108229997Sken * doesn't support autosense. e.g. non-packetized 109229997Sken * parallel SCSI doesn't support autosense.) 110229997Sken * 111229997Sken * port_name: A string describing the FETD. e.g. "LSI 1030T U320" 112229997Sken * or whatever you want to use to describe the driver. 113229997Sken * 114229997Sken * 115229997Sken * physical_port: This is the physical port number of this 116229997Sken * particular port within the driver/hardware. This 117229997Sken * number is hardware/driver specific. 118229997Sken * virtual_port: This is the virtual port number of this 119229997Sken * particular port. This is for things like NP-IV. 120229997Sken * 121229997Sken * port_online(): This function is called, with onoff_arg as its 122229997Sken * argument, by the CTL layer when it wants the FETD 123229997Sken * to start responding to selections on the specified 124229997Sken * target ID. (targ_target) 125229997Sken * 126229997Sken * port_offline(): This function is called, with onoff_arg as its 127229997Sken * argument, by the CTL layer when it wants the FETD 128229997Sken * to stop responding to selection on the specified 129229997Sken * target ID. (targ_target) 130229997Sken * 131229997Sken * onoff_arg: This is supplied as an argument to port_online() 132229997Sken * and port_offline(). This is specified by the 133229997Sken * FETD. 134229997Sken * 135229997Sken * lun_enable(): This function is called, with targ_lun_arg, a target 136229997Sken * ID and a LUN ID as its arguments, by CTL when it 137229997Sken * wants the FETD to enable a particular LUN. If the 138229997Sken * FETD doesn't really know about LUNs, it should 139229997Sken * just ignore this call and return 0. If the FETD 140229997Sken * cannot enable the requested LUN for some reason, the 141229997Sken * FETD should return non-zero status. 142229997Sken * 143229997Sken * lun_disable(): This function is called, with targ_lun_arg, a target 144229997Sken * ID and LUN ID as its arguments, by CTL when it 145229997Sken * wants the FETD to disable a particular LUN. If the 146229997Sken * FETD doesn't really know about LUNs, it should just 147229997Sken * ignore this call and return 0. If the FETD cannot 148229997Sken * disable the requested LUN for some reason, the 149229997Sken * FETD should return non-zero status. 150229997Sken * 151229997Sken * targ_lun_arg: This is supplied as an argument to the targ/lun 152229997Sken * enable/disable() functions. This is specified by 153229997Sken * the FETD. 154229997Sken * 155229997Sken * fe_datamove(): This function is called one or more times per I/O 156229997Sken * by the CTL layer to tell the FETD to initiate a 157229997Sken * DMA to or from the data buffer(s) specified by 158229997Sken * the passed-in ctl_io structure. 159229997Sken * 160229997Sken * fe_done(): This function is called by the CTL layer when a 161229997Sken * particular SCSI I/O or task management command has 162229997Sken * completed. For SCSI I/O requests (CTL_IO_SCSI), 163229997Sken * sense data is always supplied if the status is 164229997Sken * CTL_SCSI_ERROR and the SCSI status byte is 165229997Sken * SCSI_STATUS_CHECK_COND. If the FETD doesn't 166229997Sken * support autosense, the sense should be queued 167229997Sken * back to the CTL layer via ctl_queue_sense(). 168229997Sken * 169229997Sken * fe_dump(): This function, if it exists, is called by CTL 170229997Sken * to request a dump of any debugging information or 171229997Sken * state to the console. 172229997Sken * 173229997Sken * max_targets: The maximum number of targets that we can create 174229997Sken * per-port. 175229997Sken * 176229997Sken * max_target_id: The highest target ID that we can use. 177229997Sken * 178229997Sken * targ_port: The CTL layer assigns a "port number" to every 179229997Sken * FETD. This port number should be passed back in 180229997Sken * in the header of every ctl_io that is queued to 181229997Sken * the CTL layer. This enables us to determine 182229997Sken * which bus the command came in on. 183229997Sken * 184229997Sken * ctl_pool_ref: Memory pool reference used by the FETD in calls to 185229997Sken * ctl_alloc_io(). 186229997Sken * 187229997Sken * max_initiators: Maximum number of initiators that the FETD is 188229997Sken * allowed to have. Initiators should be numbered 189229997Sken * from 0 to max_initiators - 1. This value will 190229997Sken * typically be 16, and thus not a problem for 191229997Sken * parallel SCSI. This may present issues for Fibre 192229997Sken * Channel. 193229997Sken * 194229997Sken * wwnn World Wide Node Name to be used by the FETD. 195229997Sken * Note that this is set *after* registration. It 196229997Sken * will be set prior to the online function getting 197229997Sken * called. 198229997Sken * 199229997Sken * wwpn World Wide Port Name to be used by the FETD. 200229997Sken * Note that this is set *after* registration. It 201229997Sken * will be set prior to the online function getting 202229997Sken * called. 203229997Sken * 204229997Sken * status: Used by CTL to keep track of per-FETD state. 205229997Sken * 206229997Sken * links: Linked list pointers, used by CTL. The FETD 207229997Sken * shouldn't touch this field. 208229997Sken */ 209268677Smavstruct ctl_port { 210268677Smav struct ctl_frontend *frontend; 211229997Sken ctl_port_type port_type; /* passed to CTL */ 212229997Sken int num_requested_ctl_io; /* passed to CTL */ 213229997Sken char *port_name; /* passed to CTL */ 214229997Sken int physical_port; /* passed to CTL */ 215229997Sken int virtual_port; /* passed to CTL */ 216229997Sken port_func_t port_online; /* passed to CTL */ 217229997Sken port_func_t port_offline; /* passed to CTL */ 218268688Smav port_info_func_t port_info; /* passed to CTL */ 219229997Sken void *onoff_arg; /* passed to CTL */ 220229997Sken lun_func_t lun_enable; /* passed to CTL */ 221229997Sken lun_func_t lun_disable; /* passed to CTL */ 222268685Smav lun_map_func_t lun_map; /* passed to CTL */ 223229997Sken void *targ_lun_arg; /* passed to CTL */ 224229997Sken void (*fe_datamove)(union ctl_io *io); /* passed to CTL */ 225229997Sken void (*fe_done)(union ctl_io *io); /* passed to CTL */ 226229997Sken int max_targets; /* passed to CTL */ 227229997Sken int max_target_id; /* passed to CTL */ 228229997Sken int32_t targ_port; /* passed back to FETD */ 229229997Sken void *ctl_pool_ref; /* passed back to FETD */ 230229997Sken uint32_t max_initiators; /* passed back to FETD */ 231229997Sken uint64_t wwnn; /* set by CTL before online */ 232229997Sken uint64_t wwpn; /* set by CTL before online */ 233229997Sken ctl_port_status status; /* used by CTL */ 234268682Smav ctl_options_t options; /* passed to CTL */ 235268683Smav struct ctl_devid *port_devid; /* passed to CTL */ 236268683Smav struct ctl_devid *target_devid; /* passed to CTL */ 237268677Smav STAILQ_ENTRY(ctl_port) fe_links; /* used by CTL */ 238268677Smav STAILQ_ENTRY(ctl_port) links; /* used by CTL */ 239268677Smav}; 240268677Smav 241268677Smavstruct ctl_frontend { 242268682Smav char name[CTL_DRIVER_NAME_LEN]; /* passed to CTL */ 243268677Smav fe_init_t init; /* passed to CTL */ 244268677Smav fe_ioctl_t ioctl; /* passed to CTL */ 245268677Smav void (*fe_dump)(void); /* passed to CTL */ 246268677Smav fe_shutdown_t shutdown; /* passed to CTL */ 247268677Smav STAILQ_HEAD(, ctl_port) port_list; /* used by CTL */ 248229997Sken STAILQ_ENTRY(ctl_frontend) links; /* used by CTL */ 249229997Sken}; 250229997Sken 251229997Sken/* 252229997Sken * This may block until resources are allocated. Called at FETD module load 253229997Sken * time. Returns 0 for success, non-zero for failure. 254229997Sken */ 255268677Smavint ctl_frontend_register(struct ctl_frontend *fe); 256229997Sken 257229997Sken/* 258229997Sken * Called at FETD module unload time. 259229997Sken * Returns 0 for success, non-zero for failure. 260229997Sken */ 261229997Skenint ctl_frontend_deregister(struct ctl_frontend *fe); 262229997Sken 263229997Sken/* 264268680Smav * Find the frontend by its name. Returns NULL if not found. 265268680Smav */ 266268680Smavstruct ctl_frontend * ctl_frontend_find(char *frontend_name); 267268680Smav 268268680Smav/* 269268677Smav * This may block until resources are allocated. Called at FETD module load 270268677Smav * time. Returns 0 for success, non-zero for failure. 271268677Smav */ 272268677Smavint ctl_port_register(struct ctl_port *fe, int master_SC); 273268677Smav 274268677Smav/* 275268677Smav * Called at FETD module unload time. 276268677Smav * Returns 0 for success, non-zero for failure. 277268677Smav */ 278268677Smavint ctl_port_deregister(struct ctl_port *fe); 279268677Smav 280268677Smav/* 281229997Sken * Called to set the WWNN and WWPN for a particular frontend. 282229997Sken */ 283268677Smavvoid ctl_port_set_wwns(struct ctl_port *port, int wwnn_valid, 284229997Sken uint64_t wwnn, int wwpn_valid, uint64_t wwpn); 285229997Sken 286229997Sken/* 287229997Sken * Called to bring a particular frontend online. 288229997Sken */ 289268677Smavvoid ctl_port_online(struct ctl_port *fe); 290229997Sken 291229997Sken/* 292229997Sken * Called to take a particular frontend offline. 293229997Sken */ 294268677Smavvoid ctl_port_offline(struct ctl_port *fe); 295229997Sken 296229997Sken/* 297229997Sken * This routine queues I/O and task management requests from the FETD to the 298229997Sken * CTL layer. Returns immediately. Returns 0 for success, non-zero for 299229997Sken * failure. 300229997Sken */ 301229997Skenint ctl_queue(union ctl_io *io); 302229997Sken 303229997Sken/* 304229997Sken * This routine is used if the front end interface doesn't support 305229997Sken * autosense (e.g. non-packetized parallel SCSI). This will queue the 306229997Sken * scsiio structure back to a per-lun pending sense queue. This MUST be 307229997Sken * called BEFORE any request sense can get queued to the CTL layer -- I 308229997Sken * need it in the queue in order to service the request. The scsiio 309229997Sken * structure passed in here will be freed by the CTL layer when sense is 310229997Sken * retrieved by the initiator. Returns 0 for success, non-zero for failure. 311229997Sken */ 312229997Skenint ctl_queue_sense(union ctl_io *io); 313229997Sken 314229997Sken/* 315229997Sken * This routine adds an initiator to CTL's port database. The WWPN should 316229997Sken * be the FC WWPN, if available. The targ_port field should be the same as 317229997Sken * the targ_port passed back from CTL in the ctl_frontend structure above. 318229997Sken * The iid field should be the same as the iid passed in the nexus of each 319229997Sken * ctl_io from this initiator. 320229997Sken */ 321229997Skenint ctl_add_initiator(uint64_t wwpn, int32_t targ_port, uint32_t iid); 322229997Sken 323229997Sken/* 324229997Sken * This routine will remove an initiator from CTL's port database. The 325229997Sken * targ_port field should be the same as the targ_port passed back in the 326229997Sken * ctl_frontend structure above. The iid field should be the same as the 327229997Sken * iid passed in the nexus of each ctl_io from this initiator. 328229997Sken */ 329229997Skenint 330229997Skenctl_remove_initiator(int32_t targ_port, uint32_t iid); 331229997Sken 332229997Sken#endif /* _CTL_FRONTEND_H_ */ 333