ctl_frontend.h revision 288731
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 288731 2015-10-05 08:55:59Z 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, 44284797Smav CTL_PORT_STATUS_ONLINE = 0x01 45229997Sken} ctl_port_status; 46229997Sken 47268677Smavtypedef int (*fe_init_t)(void); 48268677Smavtypedef void (*fe_shutdown_t)(void); 49229997Skentypedef void (*port_func_t)(void *onoff_arg); 50268688Smavtypedef int (*port_info_func_t)(void *onoff_arg, struct sbuf *sb); 51284798Smavtypedef int (*lun_func_t)(void *arg, int lun_id); 52254759Strasztypedef int (*fe_ioctl_t)(struct cdev *dev, u_long cmd, caddr_t addr, int flag, 53254759Strasz struct thread *td); 54229997Sken 55268677Smav#define CTL_FRONTEND_DECLARE(name, driver) \ 56268677Smav static int name ## _modevent(module_t mod, int type, void *data) \ 57268677Smav { \ 58268677Smav switch (type) { \ 59268677Smav case MOD_LOAD: \ 60268677Smav ctl_frontend_register( \ 61268677Smav (struct ctl_frontend *)data); \ 62268677Smav break; \ 63268677Smav case MOD_UNLOAD: \ 64268677Smav printf(#name " module unload - not possible for this module type\n"); \ 65268677Smav return EINVAL; \ 66268677Smav default: \ 67268677Smav return EOPNOTSUPP; \ 68268677Smav } \ 69268677Smav return 0; \ 70268677Smav } \ 71268677Smav static moduledata_t name ## _mod = { \ 72268677Smav #name, \ 73268677Smav name ## _modevent, \ 74268677Smav (void *)&driver \ 75268677Smav }; \ 76268677Smav DECLARE_MODULE(name, name ## _mod, SI_SUB_CONFIGURE, SI_ORDER_FOURTH); \ 77268677Smav MODULE_DEPEND(name, ctl, 1, 1, 1); \ 78268677Smav MODULE_DEPEND(name, cam, 1, 1, 1) 79268677Smav 80268692Smavstruct ctl_wwpn_iid { 81268692Smav int in_use; 82268692Smav time_t last_use; 83268692Smav uint64_t wwpn; 84268692Smav char *name; 85268692Smav}; 86268692Smav 87229997Sken/* 88229997Sken * The ctl_frontend structure is the registration mechanism between a FETD 89229997Sken * (Front End Target Driver) and the CTL layer. Here is a description of 90229997Sken * the fields: 91229997Sken * 92229997Sken * port_type: This field tells CTL what kind of front end it is 93229997Sken * dealing with. This field serves two purposes. 94229997Sken * The first is to let CTL know whether the frontend 95229997Sken * in question is inside the main CTL module (i.e. 96229997Sken * the ioctl front end), and therefore its module 97229997Sken * reference count shouldn't be incremented. The 98229997Sken * CTL ioctl front end should continue to use the 99229997Sken * CTL_PORT_IOCTL argument as long as it is part of 100229997Sken * the main CTL module. The second is to let CTL 101229997Sken * know what kind of front end it is dealing with, so 102229997Sken * it can return the proper inquiry data for that 103229997Sken * particular port. 104229997Sken * 105229997Sken * num_requested_ctl_io: This is the number of ctl_io structures that the 106229997Sken * front end needs for its pool. This should 107229997Sken * generally be the maximum number of outstanding 108229997Sken * transactions that the FETD can handle. The CTL 109229997Sken * layer will add a few to this to account for 110229997Sken * ctl_io buffers queued for pending sense data. 111229997Sken * (Pending sense only gets queued if the FETD 112229997Sken * doesn't support autosense. e.g. non-packetized 113229997Sken * parallel SCSI doesn't support autosense.) 114229997Sken * 115229997Sken * port_name: A string describing the FETD. e.g. "LSI 1030T U320" 116229997Sken * or whatever you want to use to describe the driver. 117229997Sken * 118229997Sken * 119229997Sken * physical_port: This is the physical port number of this 120229997Sken * particular port within the driver/hardware. This 121229997Sken * number is hardware/driver specific. 122229997Sken * virtual_port: This is the virtual port number of this 123229997Sken * particular port. This is for things like NP-IV. 124229997Sken * 125229997Sken * port_online(): This function is called, with onoff_arg as its 126229997Sken * argument, by the CTL layer when it wants the FETD 127229997Sken * to start responding to selections on the specified 128288731Smav * target ID. 129229997Sken * 130229997Sken * port_offline(): This function is called, with onoff_arg as its 131229997Sken * argument, by the CTL layer when it wants the FETD 132229997Sken * to stop responding to selection on the specified 133288731Smav * target ID. 134229997Sken * 135229997Sken * onoff_arg: This is supplied as an argument to port_online() 136229997Sken * and port_offline(). This is specified by the 137229997Sken * FETD. 138229997Sken * 139229997Sken * lun_enable(): This function is called, with targ_lun_arg, a target 140229997Sken * ID and a LUN ID as its arguments, by CTL when it 141229997Sken * wants the FETD to enable a particular LUN. If the 142229997Sken * FETD doesn't really know about LUNs, it should 143229997Sken * just ignore this call and return 0. If the FETD 144229997Sken * cannot enable the requested LUN for some reason, the 145229997Sken * FETD should return non-zero status. 146229997Sken * 147229997Sken * lun_disable(): This function is called, with targ_lun_arg, a target 148229997Sken * ID and LUN ID as its arguments, by CTL when it 149229997Sken * wants the FETD to disable a particular LUN. If the 150229997Sken * FETD doesn't really know about LUNs, it should just 151229997Sken * ignore this call and return 0. If the FETD cannot 152229997Sken * disable the requested LUN for some reason, the 153229997Sken * FETD should return non-zero status. 154229997Sken * 155229997Sken * targ_lun_arg: This is supplied as an argument to the targ/lun 156229997Sken * enable/disable() functions. This is specified by 157229997Sken * the FETD. 158229997Sken * 159229997Sken * fe_datamove(): This function is called one or more times per I/O 160229997Sken * by the CTL layer to tell the FETD to initiate a 161229997Sken * DMA to or from the data buffer(s) specified by 162229997Sken * the passed-in ctl_io structure. 163229997Sken * 164229997Sken * fe_done(): This function is called by the CTL layer when a 165229997Sken * particular SCSI I/O or task management command has 166229997Sken * completed. For SCSI I/O requests (CTL_IO_SCSI), 167229997Sken * sense data is always supplied if the status is 168229997Sken * CTL_SCSI_ERROR and the SCSI status byte is 169229997Sken * SCSI_STATUS_CHECK_COND. If the FETD doesn't 170229997Sken * support autosense, the sense should be queued 171229997Sken * back to the CTL layer via ctl_queue_sense(). 172229997Sken * 173229997Sken * fe_dump(): This function, if it exists, is called by CTL 174229997Sken * to request a dump of any debugging information or 175229997Sken * state to the console. 176229997Sken * 177229997Sken * max_targets: The maximum number of targets that we can create 178229997Sken * per-port. 179229997Sken * 180229997Sken * max_target_id: The highest target ID that we can use. 181229997Sken * 182229997Sken * targ_port: The CTL layer assigns a "port number" to every 183229997Sken * FETD. This port number should be passed back in 184229997Sken * in the header of every ctl_io that is queued to 185229997Sken * the CTL layer. This enables us to determine 186229997Sken * which bus the command came in on. 187229997Sken * 188229997Sken * ctl_pool_ref: Memory pool reference used by the FETD in calls to 189229997Sken * ctl_alloc_io(). 190229997Sken * 191229997Sken * max_initiators: Maximum number of initiators that the FETD is 192229997Sken * allowed to have. Initiators should be numbered 193229997Sken * from 0 to max_initiators - 1. This value will 194229997Sken * typically be 16, and thus not a problem for 195229997Sken * parallel SCSI. This may present issues for Fibre 196229997Sken * Channel. 197229997Sken * 198229997Sken * wwnn World Wide Node Name to be used by the FETD. 199229997Sken * Note that this is set *after* registration. It 200229997Sken * will be set prior to the online function getting 201229997Sken * called. 202229997Sken * 203229997Sken * wwpn World Wide Port Name to be used by the FETD. 204229997Sken * Note that this is set *after* registration. It 205229997Sken * will be set prior to the online function getting 206229997Sken * called. 207229997Sken * 208229997Sken * status: Used by CTL to keep track of per-FETD state. 209229997Sken * 210229997Sken * links: Linked list pointers, used by CTL. The FETD 211229997Sken * shouldn't touch this field. 212229997Sken */ 213268677Smavstruct ctl_port { 214268677Smav struct ctl_frontend *frontend; 215229997Sken ctl_port_type port_type; /* passed to CTL */ 216229997Sken int num_requested_ctl_io; /* passed to CTL */ 217229997Sken char *port_name; /* passed to CTL */ 218229997Sken int physical_port; /* passed to CTL */ 219229997Sken int virtual_port; /* passed to CTL */ 220229997Sken port_func_t port_online; /* passed to CTL */ 221229997Sken port_func_t port_offline; /* passed to CTL */ 222268688Smav port_info_func_t port_info; /* passed to CTL */ 223229997Sken void *onoff_arg; /* passed to CTL */ 224229997Sken lun_func_t lun_enable; /* passed to CTL */ 225229997Sken lun_func_t lun_disable; /* passed to CTL */ 226279002Smav uint32_t *lun_map; /* passed to CTL */ 227229997Sken void *targ_lun_arg; /* passed to CTL */ 228229997Sken void (*fe_datamove)(union ctl_io *io); /* passed to CTL */ 229229997Sken void (*fe_done)(union ctl_io *io); /* passed to CTL */ 230229997Sken int max_targets; /* passed to CTL */ 231229997Sken int max_target_id; /* passed to CTL */ 232229997Sken int32_t targ_port; /* passed back to FETD */ 233229997Sken void *ctl_pool_ref; /* passed back to FETD */ 234229997Sken uint32_t max_initiators; /* passed back to FETD */ 235268692Smav struct ctl_wwpn_iid *wwpn_iid; /* used by CTL */ 236229997Sken uint64_t wwnn; /* set by CTL before online */ 237229997Sken uint64_t wwpn; /* set by CTL before online */ 238229997Sken ctl_port_status status; /* used by CTL */ 239268682Smav ctl_options_t options; /* passed to CTL */ 240268683Smav struct ctl_devid *port_devid; /* passed to CTL */ 241268683Smav struct ctl_devid *target_devid; /* passed to CTL */ 242269296Smav struct ctl_devid *init_devid; /* passed to CTL */ 243268677Smav STAILQ_ENTRY(ctl_port) fe_links; /* used by CTL */ 244268677Smav STAILQ_ENTRY(ctl_port) links; /* used by CTL */ 245268677Smav}; 246268677Smav 247268677Smavstruct ctl_frontend { 248268682Smav char name[CTL_DRIVER_NAME_LEN]; /* passed to CTL */ 249268677Smav fe_init_t init; /* passed to CTL */ 250268677Smav fe_ioctl_t ioctl; /* passed to CTL */ 251268677Smav void (*fe_dump)(void); /* passed to CTL */ 252268677Smav fe_shutdown_t shutdown; /* passed to CTL */ 253268677Smav STAILQ_HEAD(, ctl_port) port_list; /* used by CTL */ 254229997Sken STAILQ_ENTRY(ctl_frontend) links; /* used by CTL */ 255229997Sken}; 256229997Sken 257229997Sken/* 258229997Sken * This may block until resources are allocated. Called at FETD module load 259229997Sken * time. Returns 0 for success, non-zero for failure. 260229997Sken */ 261268677Smavint ctl_frontend_register(struct ctl_frontend *fe); 262229997Sken 263229997Sken/* 264229997Sken * Called at FETD module unload time. 265229997Sken * Returns 0 for success, non-zero for failure. 266229997Sken */ 267229997Skenint ctl_frontend_deregister(struct ctl_frontend *fe); 268229997Sken 269229997Sken/* 270268680Smav * Find the frontend by its name. Returns NULL if not found. 271268680Smav */ 272268680Smavstruct ctl_frontend * ctl_frontend_find(char *frontend_name); 273268680Smav 274268680Smav/* 275268677Smav * This may block until resources are allocated. Called at FETD module load 276268677Smav * time. Returns 0 for success, non-zero for failure. 277268677Smav */ 278275493Smavint ctl_port_register(struct ctl_port *port); 279268677Smav 280268677Smav/* 281268677Smav * Called at FETD module unload time. 282268677Smav * Returns 0 for success, non-zero for failure. 283268677Smav */ 284268692Smavint ctl_port_deregister(struct ctl_port *port); 285268677Smav 286268677Smav/* 287229997Sken * Called to set the WWNN and WWPN for a particular frontend. 288229997Sken */ 289268677Smavvoid ctl_port_set_wwns(struct ctl_port *port, int wwnn_valid, 290229997Sken uint64_t wwnn, int wwpn_valid, uint64_t wwpn); 291229997Sken 292229997Sken/* 293229997Sken * Called to bring a particular frontend online. 294229997Sken */ 295268677Smavvoid ctl_port_online(struct ctl_port *fe); 296229997Sken 297229997Sken/* 298229997Sken * Called to take a particular frontend offline. 299229997Sken */ 300268677Smavvoid ctl_port_offline(struct ctl_port *fe); 301229997Sken 302229997Sken/* 303229997Sken * This routine queues I/O and task management requests from the FETD to the 304229997Sken * CTL layer. Returns immediately. Returns 0 for success, non-zero for 305229997Sken * failure. 306229997Sken */ 307229997Skenint ctl_queue(union ctl_io *io); 308229997Sken 309229997Sken/* 310229997Sken * This routine is used if the front end interface doesn't support 311229997Sken * autosense (e.g. non-packetized parallel SCSI). This will queue the 312229997Sken * scsiio structure back to a per-lun pending sense queue. This MUST be 313229997Sken * called BEFORE any request sense can get queued to the CTL layer -- I 314229997Sken * need it in the queue in order to service the request. The scsiio 315229997Sken * structure passed in here will be freed by the CTL layer when sense is 316229997Sken * retrieved by the initiator. Returns 0 for success, non-zero for failure. 317229997Sken */ 318229997Skenint ctl_queue_sense(union ctl_io *io); 319229997Sken 320229997Sken/* 321268692Smav * This routine adds an initiator to CTL's port database. 322229997Sken * The iid field should be the same as the iid passed in the nexus of each 323229997Sken * ctl_io from this initiator. 324268692Smav * The WWPN should be the FC WWPN, if available. 325229997Sken */ 326268692Smavint ctl_add_initiator(struct ctl_port *port, int iid, uint64_t wwpn, char *name); 327229997Sken 328229997Sken/* 329268692Smav * This routine will remove an initiator from CTL's port database. 330268692Smav * The iid field should be the same as the iid passed in the nexus of each 331268692Smav * ctl_io from this initiator. 332229997Sken */ 333268692Smavint ctl_remove_initiator(struct ctl_port *port, int iid); 334229997Sken 335229997Sken#endif /* _CTL_FRONTEND_H_ */ 336