ctl_frontend.h revision 268676
1139823Simp/*- 2122702Sandre * Copyright (c) 2003 Silicon Graphics International Corp. 3122702Sandre * All rights reserved. 4122702Sandre * 5122702Sandre * Redistribution and use in source and binary forms, with or without 6122702Sandre * modification, are permitted provided that the following conditions 7122702Sandre * are met: 8122702Sandre * 1. Redistributions of source code must retain the above copyright 9122702Sandre * notice, this list of conditions, and the following disclaimer, 10122702Sandre * without modification. 11122702Sandre * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12122702Sandre * substantially similar to the "NO WARRANTY" disclaimer below 13122702Sandre * ("Disclaimer") and any redistribution must be conditioned upon 14122702Sandre * including a substantially similar Disclaimer requirement for further 15122702Sandre * binary redistribution. 16122702Sandre * 17122702Sandre * NO WARRANTY 18122702Sandre * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19122702Sandre * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20122702Sandre * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 21122702Sandre * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22122702Sandre * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23122702Sandre * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24122702Sandre * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25122702Sandre * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26122702Sandre * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 27122702Sandre * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28122702Sandre * POSSIBILITY OF SUCH DAMAGES. 29122702Sandre * 30122702Sandre * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_frontend.h#2 $ 31122702Sandre * $FreeBSD: stable/10/sys/cam/ctl/ctl_frontend.h 268676 2014-07-15 16:55:13Z mav $ 32122702Sandre */ 33122702Sandre/* 34122702Sandre * CAM Target Layer front end registration hooks 35148324Skeramida * 36122702Sandre * Author: Ken Merry <ken@FreeBSD.org> 37122759Sandre */ 38122759Sandre 39122759Sandre#ifndef _CTL_FRONTEND_H_ 40122759Sandre#define _CTL_FRONTEND_H_ 41122702Sandre 42148324Skeramidatypedef enum { 43122702Sandre CTL_PORT_STATUS_NONE = 0x00, 44148324Skeramida CTL_PORT_STATUS_ONLINE = 0x01, 45122702Sandre CTL_PORT_STATUS_TARG_ONLINE = 0x02, 46122702Sandre CTL_PORT_STATUS_LUN_ONLINE = 0x04 47122702Sandre} ctl_port_status; 48122702Sandre 49122702Sandretypedef void (*port_func_t)(void *onoff_arg); 50122702Sandretypedef int (*targ_func_t)(void *arg, struct ctl_id targ_id); 51122702Sandretypedef int (*lun_func_t)(void *arg, struct ctl_id targ_id, int lun_id); 52122702Sandretypedef int (*fe_ioctl_t)(struct cdev *dev, u_long cmd, caddr_t addr, int flag, 53122702Sandre struct thread *td); 54122702Sandretypedef int (*fe_devid_t)(struct ctl_scsiio *ctsio, int alloc_len); 55122702Sandre 56122702Sandre/* 57122702Sandre * The ctl_frontend structure is the registration mechanism between a FETD 58122702Sandre * (Front End Target Driver) and the CTL layer. Here is a description of 59148324Skeramida * the fields: 60122702Sandre * 61122702Sandre * port_type: This field tells CTL what kind of front end it is 62122702Sandre * dealing with. This field serves two purposes. 63122702Sandre * The first is to let CTL know whether the frontend 64148324Skeramida * in question is inside the main CTL module (i.e. 65148324Skeramida * the ioctl front end), and therefore its module 66148324Skeramida * reference count shouldn't be incremented. The 67148324Skeramida * CTL ioctl front end should continue to use the 68148324Skeramida * CTL_PORT_IOCTL argument as long as it is part of 69122702Sandre * the main CTL module. The second is to let CTL 70122702Sandre * know what kind of front end it is dealing with, so 71122702Sandre * it can return the proper inquiry data for that 72122702Sandre * particular port. 73122702Sandre * 74122702Sandre * num_requested_ctl_io: This is the number of ctl_io structures that the 75122702Sandre * front end needs for its pool. This should 76172467Ssilby * generally be the maximum number of outstanding 77172467Ssilby * transactions that the FETD can handle. The CTL 78172467Ssilby * layer will add a few to this to account for 79122702Sandre * ctl_io buffers queued for pending sense data. 80122702Sandre * (Pending sense only gets queued if the FETD 81122702Sandre * doesn't support autosense. e.g. non-packetized 82122702Sandre * parallel SCSI doesn't support autosense.) 83122702Sandre * 84122702Sandre * port_name: A string describing the FETD. e.g. "LSI 1030T U320" 85122702Sandre * or whatever you want to use to describe the driver. 86122702Sandre * 87122702Sandre * 88122702Sandre * physical_port: This is the physical port number of this 89122702Sandre * particular port within the driver/hardware. This 90181803Sbz * number is hardware/driver specific. 91122702Sandre * virtual_port: This is the virtual port number of this 92122702Sandre * particular port. This is for things like NP-IV. 93122702Sandre * 94122702Sandre * port_online(): This function is called, with onoff_arg as its 95122702Sandre * argument, by the CTL layer when it wants the FETD 96122702Sandre * to start responding to selections on the specified 97122702Sandre * target ID. (targ_target) 98122702Sandre * 99122702Sandre * port_offline(): This function is called, with onoff_arg as its 100122702Sandre * argument, by the CTL layer when it wants the FETD 101122702Sandre * to stop responding to selection on the specified 102122702Sandre * target ID. (targ_target) 103122702Sandre * 104122702Sandre * onoff_arg: This is supplied as an argument to port_online() 105152592Sandre * and port_offline(). This is specified by the 106185571Sbz * FETD. 107122702Sandre * 108122702Sandre * lun_enable(): This function is called, with targ_lun_arg, a target 109122702Sandre * ID and a LUN ID as its arguments, by CTL when it 110185088Szec * wants the FETD to enable a particular LUN. If the 111185088Szec * FETD doesn't really know about LUNs, it should 112185088Szec * just ignore this call and return 0. If the FETD 113183550Szec * cannot enable the requested LUN for some reason, the 114183550Szec * FETD should return non-zero status. 115122702Sandre * 116128872Sandre * lun_disable(): This function is called, with targ_lun_arg, a target 117133497Sandre * ID and LUN ID as its arguments, by CTL when it 118128872Sandre * wants the FETD to disable a particular LUN. If the 119183550Szec * FETD doesn't really know about LUNs, it should just 120128872Sandre * ignore this call and return 0. If the FETD cannot 121128872Sandre * disable the requested LUN for some reason, the 122128872Sandre * FETD should return non-zero status. 123128872Sandre * 124128872Sandre * targ_lun_arg: This is supplied as an argument to the targ/lun 125128872Sandre * enable/disable() functions. This is specified by 126128872Sandre * the FETD. 127128872Sandre * 128128872Sandre * fe_datamove(): This function is called one or more times per I/O 129128872Sandre * by the CTL layer to tell the FETD to initiate a 130133497Sandre * DMA to or from the data buffer(s) specified by 131186119Sqingli * the passed-in ctl_io structure. 132128872Sandre * 133128872Sandre * fe_done(): This function is called by the CTL layer when a 134128872Sandre * particular SCSI I/O or task management command has 135128872Sandre * completed. For SCSI I/O requests (CTL_IO_SCSI), 136128872Sandre * sense data is always supplied if the status is 137128872Sandre * CTL_SCSI_ERROR and the SCSI status byte is 138128872Sandre * SCSI_STATUS_CHECK_COND. If the FETD doesn't 139148887Srwatson * support autosense, the sense should be queued 140128872Sandre * back to the CTL layer via ctl_queue_sense(). 141128872Sandre * 142128872Sandre * fe_dump(): This function, if it exists, is called by CTL 143190951Srwatson * to request a dump of any debugging information or 144190951Srwatson * state to the console. 145128872Sandre * 146128872Sandre * max_targets: The maximum number of targets that we can create 147145863Sandre * per-port. 148128872Sandre * 149128872Sandre * max_target_id: The highest target ID that we can use. 150128872Sandre * 151128872Sandre * targ_port: The CTL layer assigns a "port number" to every 152128872Sandre * FETD. This port number should be passed back in 153122702Sandre * in the header of every ctl_io that is queued to 154122702Sandre * the CTL layer. This enables us to determine 155122702Sandre * which bus the command came in on. 156122702Sandre * 157122702Sandre * ctl_pool_ref: Memory pool reference used by the FETD in calls to 158122702Sandre * ctl_alloc_io(). 159122702Sandre * 160154518Sandre * max_initiators: Maximum number of initiators that the FETD is 161122702Sandre * allowed to have. Initiators should be numbered 162122702Sandre * from 0 to max_initiators - 1. This value will 163183550Szec * typically be 16, and thus not a problem for 164122702Sandre * parallel SCSI. This may present issues for Fibre 165122702Sandre * Channel. 166122702Sandre * 167122702Sandre * wwnn World Wide Node Name to be used by the FETD. 168128872Sandre * Note that this is set *after* registration. It 169133497Sandre * will be set prior to the online function getting 170128872Sandre * called. 171122702Sandre * 172133920Sandre * wwpn World Wide Port Name to be used by the FETD. 173133920Sandre * Note that this is set *after* registration. It 174133920Sandre * will be set prior to the online function getting 175133920Sandre * called. 176122702Sandre * 177122702Sandre * status: Used by CTL to keep track of per-FETD state. 178122702Sandre * 179122702Sandre * links: Linked list pointers, used by CTL. The FETD 180181803Sbz * shouldn't touch this field. 181154518Sandre */ 182122702Sandrestruct ctl_frontend { 183122702Sandre ctl_port_type port_type; /* passed to CTL */ 184122702Sandre int num_requested_ctl_io; /* passed to CTL */ 185122702Sandre char *port_name; /* passed to CTL */ 186191148Skmacy int physical_port; /* passed to CTL */ 187128872Sandre int virtual_port; /* passed to CTL */ 188122702Sandre port_func_t port_online; /* passed to CTL */ 189122702Sandre port_func_t port_offline; /* passed to CTL */ 190122702Sandre void *onoff_arg; /* passed to CTL */ 191122702Sandre lun_func_t lun_enable; /* passed to CTL */ 192122702Sandre lun_func_t lun_disable; /* passed to CTL */ 193122702Sandre fe_ioctl_t ioctl; /* passed to CTL */ 194122702Sandre fe_devid_t devid; /* passed to CTL */ 195122702Sandre void *targ_lun_arg; /* passed to CTL */ 196190951Srwatson void (*fe_datamove)(union ctl_io *io); /* passed to CTL */ 197122702Sandre void (*fe_done)(union ctl_io *io); /* passed to CTL */ 198122702Sandre void (*fe_dump)(void); /* passed to CTL */ 199122702Sandre int max_targets; /* passed to CTL */ 200122702Sandre int max_target_id; /* passed to CTL */ 201122702Sandre int32_t targ_port; /* passed back to FETD */ 202122702Sandre void *ctl_pool_ref; /* passed back to FETD */ 203122702Sandre uint32_t max_initiators; /* passed back to FETD */ 204137302Sandre uint64_t wwnn; /* set by CTL before online */ 205190951Srwatson uint64_t wwpn; /* set by CTL before online */ 206154518Sandre ctl_port_status status; /* used by CTL */ 207122702Sandre STAILQ_ENTRY(ctl_frontend) links; /* used by CTL */ 208122702Sandre}; 209122702Sandre 210122702Sandre/* 211122702Sandre * This may block until resources are allocated. Called at FETD module load 212122702Sandre * time. Returns 0 for success, non-zero for failure. 213122702Sandre */ 214122702Sandreint ctl_frontend_register(struct ctl_frontend *fe, int master_SC); 215190951Srwatson 216122702Sandre/* 217122702Sandre * Called at FETD module unload time. 218122702Sandre * Returns 0 for success, non-zero for failure. 219122702Sandre */ 220122702Sandreint ctl_frontend_deregister(struct ctl_frontend *fe); 221122702Sandre 222122702Sandre/* 223122702Sandre * Called to set the WWNN and WWPN for a particular frontend. 224190951Srwatson */ 225122702Sandrevoid ctl_frontend_set_wwns(struct ctl_frontend *fe, int wwnn_valid, 226122702Sandre uint64_t wwnn, int wwpn_valid, uint64_t wwpn); 227122702Sandre 228154518Sandre/* 229190951Srwatson * Called to bring a particular frontend online. 230154518Sandre */ 231122702Sandrevoid ctl_frontend_online(struct ctl_frontend *fe); 232122702Sandre 233122702Sandre/* 234122702Sandre * Called to take a particular frontend offline. 235122702Sandre */ 236122702Sandrevoid ctl_frontend_offline(struct ctl_frontend *fe); 237122702Sandre 238122702Sandre/* 239122702Sandre * This routine queues I/O and task management requests from the FETD to the 240122702Sandre * CTL layer. Returns immediately. Returns 0 for success, non-zero for 241122702Sandre * failure. 242122702Sandre */ 243122702Sandreint ctl_queue(union ctl_io *io); 244122702Sandre 245122702Sandre/* 246122702Sandre * This routine is used if the front end interface doesn't support 247190951Srwatson * autosense (e.g. non-packetized parallel SCSI). This will queue the 248122702Sandre * scsiio structure back to a per-lun pending sense queue. This MUST be 249122702Sandre * called BEFORE any request sense can get queued to the CTL layer -- I 250136690Sandre * need it in the queue in order to service the request. The scsiio 251136690Sandre * structure passed in here will be freed by the CTL layer when sense is 252148324Skeramida * retrieved by the initiator. Returns 0 for success, non-zero for failure. 253136690Sandre */ 254122702Sandreint ctl_queue_sense(union ctl_io *io); 255122702Sandre 256128872Sandre/* 257122702Sandre * This routine adds an initiator to CTL's port database. The WWPN should 258122702Sandre * be the FC WWPN, if available. The targ_port field should be the same as 259122702Sandre * the targ_port passed back from CTL in the ctl_frontend structure above. 260122702Sandre * The iid field should be the same as the iid passed in the nexus of each 261128872Sandre * ctl_io from this initiator. 262190951Srwatson */ 263122702Sandreint ctl_add_initiator(uint64_t wwpn, int32_t targ_port, uint32_t iid); 264122702Sandre 265122702Sandre/* 266122702Sandre * This routine will remove an initiator from CTL's port database. The 267122702Sandre * targ_port field should be the same as the targ_port passed back in the 268122702Sandre * ctl_frontend structure above. The iid field should be the same as the 269128872Sandre * iid passed in the nexus of each ctl_io from this initiator. 270122702Sandre */ 271128872Sandreint 272128872Sandrectl_remove_initiator(int32_t targ_port, uint32_t iid); 273122702Sandre 274128872Sandre#endif /* _CTL_FRONTEND_H_ */ 275122702Sandre