/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2003 Silicon Graphics International Corp.4* Copyright (c) 2014-2017 Alexander Motin <[email protected]>5* All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions, and the following disclaimer,12* without modification.13* 2. Redistributions in binary form must reproduce at minimum a disclaimer14* substantially similar to the "NO WARRANTY" disclaimer below15* ("Disclaimer") and any redistribution must be conditioned upon16* including a substantially similar Disclaimer requirement for further17* binary redistribution.18*19* NO WARRANTY20* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS21* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT22* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR23* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT24* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,28* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING29* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE30* POSSIBILITY OF SUCH DAMAGES.31*32* $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_frontend.h#2 $33*/34/*35* CAM Target Layer front end registration hooks36*37* Author: Ken Merry <[email protected]>38*/3940#ifndef _CTL_FRONTEND_H_41#define _CTL_FRONTEND_H_4243#include <cam/ctl/ctl_ioctl.h>44#include <sys/nv.h>4546typedef enum {47CTL_PORT_STATUS_NONE = 0x00,48CTL_PORT_STATUS_ONLINE = 0x01,49CTL_PORT_STATUS_HA_SHARED = 0x0250} ctl_port_status;5152typedef int (*fe_init_t)(void);53typedef int (*fe_shutdown_t)(void);54typedef void (*port_func_t)(void *onoff_arg);55typedef int (*port_info_func_t)(void *onoff_arg, struct sbuf *sb);56typedef int (*lun_func_t)(void *arg, int lun_id);57typedef int (*fe_ioctl_t)(struct cdev *dev, u_long cmd, caddr_t addr, int flag,58struct thread *td);5960#define CTL_FRONTEND_DECLARE(name, driver) \61static int name ## _modevent(module_t mod, int type, void *data) \62{ \63switch (type) { \64case MOD_LOAD: \65return (ctl_frontend_register( \66(struct ctl_frontend *)data)); \67break; \68case MOD_UNLOAD: \69return (ctl_frontend_deregister( \70(struct ctl_frontend *)data)); \71break; \72default: \73return EOPNOTSUPP; \74} \75return 0; \76} \77static moduledata_t name ## _mod = { \78#name, \79name ## _modevent, \80(void *)&driver \81}; \82DECLARE_MODULE(name, name ## _mod, SI_SUB_CONFIGURE, SI_ORDER_FOURTH); \83MODULE_DEPEND(name, ctl, 1, 1, 1); \84MODULE_DEPEND(name, cam, 1, 1, 1)8586struct ctl_wwpn_iid {87int in_use;88time_t last_use;89uint64_t wwpn;90char *name;91};9293/*94* The ctl_frontend structure is the registration mechanism between a FETD95* (Front End Target Driver) and the CTL layer. Here is a description of96* the fields:97*98* port_type: This field tells CTL what kind of front end it is99* dealing with. This field serves two purposes.100* The first is to let CTL know whether the frontend101* in question is inside the main CTL module (i.e.102* the ioctl front end), and therefore its module103* reference count shouldn't be incremented. The104* CTL ioctl front end should continue to use the105* CTL_PORT_IOCTL argument as long as it is part of106* the main CTL module. The second is to let CTL107* know what kind of front end it is dealing with, so108* it can return the proper inquiry data for that109* particular port.110*111* num_requested_ctl_io: This is the number of ctl_io structures that the112* front end needs for its pool. This should113* generally be the maximum number of outstanding114* transactions that the FETD can handle. The CTL115* layer will add a few to this to account for116* ctl_io buffers queued for pending sense data.117* (Pending sense only gets queued if the FETD118* doesn't support autosense. e.g. non-packetized119* parallel SCSI doesn't support autosense.)120*121* port_name: A string describing the FETD. e.g. "LSI 1030T U320"122* or whatever you want to use to describe the driver.123*124* physical_port: This is the physical port number of this125* particular port within the driver/hardware. This126* number is hardware/driver specific.127* virtual_port: This is the virtual port number of this128* particular port. This is for things like NP-IV.129*130* port_online(): This function is called, with onoff_arg as its131* argument, by the CTL layer when it wants the FETD132* to start responding to selections on the specified133* target ID.134*135* port_offline(): This function is called, with onoff_arg as its136* argument, by the CTL layer when it wants the FETD137* to stop responding to selection on the specified138* target ID.139*140* onoff_arg: This is supplied as an argument to port_online()141* and port_offline(). This is specified by the142* FETD.143*144* lun_enable(): This function is called, with targ_lun_arg, a target145* ID and a LUN ID as its arguments, by CTL when it146* wants the FETD to enable a particular LUN. If the147* FETD doesn't really know about LUNs, it should148* just ignore this call and return 0. If the FETD149* cannot enable the requested LUN for some reason, the150* FETD should return non-zero status.151*152* lun_disable(): This function is called, with targ_lun_arg, a target153* ID and LUN ID as its arguments, by CTL when it154* wants the FETD to disable a particular LUN. If the155* FETD doesn't really know about LUNs, it should just156* ignore this call and return 0. If the FETD cannot157* disable the requested LUN for some reason, the158* FETD should return non-zero status.159*160* targ_lun_arg: This is supplied as an argument to the targ/lun161* enable/disable() functions. This is specified by162* the FETD.163*164* fe_datamove(): This function is called one or more times per I/O165* by the CTL layer to tell the FETD to initiate a166* DMA to or from the data buffer(s) specified by167* the passed-in ctl_io structure.168*169* fe_done(): This function is called by the CTL layer when a170* particular SCSI I/O or task management command has171* completed. For SCSI I/O requests (CTL_IO_SCSI),172* sense data is always supplied if the status is173* CTL_SCSI_ERROR and the SCSI status byte is174* SCSI_STATUS_CHECK_COND. If the FETD doesn't175* support autosense, the sense should be queued176* back to the CTL layer via ctl_queue_sense().177*178* fe_dump(): This function, if it exists, is called by CTL179* to request a dump of any debugging information or180* state to the console.181*182* targ_port: The CTL layer assigns a "port number" to every183* FETD. This port number should be passed back in184* in the header of every ctl_io that is queued to185* the CTL layer. This enables us to determine186* which bus the command came in on.187*188* ctl_pool_ref: Memory pool reference used by the FETD in calls to189* ctl_alloc_io().190*191* max_initiators: Maximum number of initiators that the FETD is192* allowed to have. Initiators should be numbered193* from 0 to max_initiators - 1. This value will194* typically be 16, and thus not a problem for195* parallel SCSI. This may present issues for Fibre196* Channel.197*198* wwnn World Wide Node Name to be used by the FETD.199* Note that this is set *after* registration. It200* will be set prior to the online function getting201* called.202*203* wwpn World Wide Port Name to be used by the FETD.204* Note that this is set *after* registration. It205* will be set prior to the online function getting206* called.207*208* status: Used by CTL to keep track of per-FETD state.209*210* links: Linked list pointers, used by CTL. The FETD211* shouldn't touch this field.212*/213struct ctl_port {214struct ctl_softc *ctl_softc;215struct ctl_frontend *frontend; /* passed to CTL */216ctl_port_type port_type; /* passed to CTL */217int num_requested_ctl_io; /* passed to CTL */218char *port_name; /* passed to CTL */219int physical_port; /* passed to CTL */220int virtual_port; /* passed to CTL */221port_func_t port_online; /* passed to CTL */222port_func_t port_offline; /* passed to CTL */223port_info_func_t port_info; /* passed to CTL */224void *onoff_arg; /* passed to CTL */225lun_func_t lun_enable; /* passed to CTL */226lun_func_t lun_disable; /* passed to CTL */227int lun_map_size; /* passed to CTL */228uint32_t *lun_map; /* passed to CTL */229void *targ_lun_arg; /* passed to CTL */230void (*fe_datamove)(union ctl_io *io); /* passed to CTL */231void (*fe_done)(union ctl_io *io); /* passed to CTL */232int32_t targ_port; /* passed back to FETD */233void *ctl_pool_ref; /* passed back to FETD */234uint32_t max_initiators; /* passed back to FETD */235struct ctl_wwpn_iid *wwpn_iid; /* used by CTL */236uint64_t wwnn; /* set by CTL before online */237uint64_t wwpn; /* set by CTL before online */238ctl_port_status status; /* used by CTL */239nvlist_t *options; /* passed to CTL */240struct ctl_devid *port_devid; /* passed to CTL */241struct ctl_devid *target_devid; /* passed to CTL */242struct ctl_devid *init_devid; /* passed to CTL */243struct ctl_io_stats stats; /* used by CTL */244struct mtx port_lock; /* used by CTL */245STAILQ_ENTRY(ctl_port) fe_links; /* used by CTL */246STAILQ_ENTRY(ctl_port) links; /* used by CTL */247};248249struct ctl_frontend {250char name[CTL_DRIVER_NAME_LEN]; /* passed to CTL */251fe_init_t init; /* passed to CTL */252fe_ioctl_t ioctl; /* passed to CTL */253void (*fe_dump)(void); /* passed to CTL */254fe_shutdown_t shutdown; /* passed to CTL */255STAILQ_HEAD(, ctl_port) port_list; /* used by CTL */256STAILQ_ENTRY(ctl_frontend) links; /* used by CTL */257};258259/*260* This may block until resources are allocated. Called at FETD module load261* time. Returns 0 for success, non-zero for failure.262*/263int ctl_frontend_register(struct ctl_frontend *fe);264265/*266* Called at FETD module unload time.267* Returns 0 for success, non-zero for failure.268*/269int ctl_frontend_deregister(struct ctl_frontend *fe);270271/*272* Find the frontend by its name. Returns NULL if not found.273*/274struct ctl_frontend * ctl_frontend_find(char *frontend_name);275276/*277* This may block until resources are allocated. Called at FETD module load278* time. Returns 0 for success, non-zero for failure.279*/280int ctl_port_register(struct ctl_port *port);281282/*283* Called at FETD module unload time.284* Returns 0 for success, non-zero for failure.285*/286int ctl_port_deregister(struct ctl_port *port);287288/*289* Called to set the WWNN and WWPN for a particular frontend.290*/291void ctl_port_set_wwns(struct ctl_port *port, int wwnn_valid,292uint64_t wwnn, int wwpn_valid, uint64_t wwpn);293294/*295* Called to bring a particular frontend online.296*/297void ctl_port_online(struct ctl_port *fe);298299/*300* Called to take a particular frontend offline.301*/302void ctl_port_offline(struct ctl_port *fe);303304/*305* This routine queues I/O and task management requests from the FETD to the306* CTL layer. Returns immediately. Returns 0 for success, non-zero for307* failure.308*/309int ctl_queue(union ctl_io *io);310311/*312* This routine starts execution of I/O and task management requests from313* the FETD to the CTL layer. May sleep. Returns 0 for success, non-zero314* for failure.315*/316int ctl_run(union ctl_io *io);317318/*319* This routine is used if the front end interface doesn't support320* autosense (e.g. non-packetized parallel SCSI). This will queue the321* scsiio structure back to a per-lun pending sense queue. This MUST be322* called BEFORE any request sense can get queued to the CTL layer -- I323* need it in the queue in order to service the request. The scsiio324* structure passed in here will be freed by the CTL layer when sense is325* retrieved by the initiator. Returns 0 for success, non-zero for failure.326*/327int ctl_queue_sense(union ctl_io *io);328329/*330* This routine adds an initiator to CTL's port database.331* The iid field should be the same as the iid passed in the nexus of each332* ctl_io from this initiator.333* The WWPN should be the FC WWPN, if available.334*/335int ctl_add_initiator(struct ctl_port *port, int iid, uint64_t wwpn, char *name);336337/*338* This routine will remove an initiator from CTL's port database.339* The iid field should be the same as the iid passed in the nexus of each340* ctl_io from this initiator.341*/342int ctl_remove_initiator(struct ctl_port *port, int iid);343344#endif /* _CTL_FRONTEND_H_ */345346347