Home | History | Annotate | Line # | Download | only in ic
isp_tpublic.h revision 1.2
      1  1.2  mjacob /* $NetBSD: isp_tpublic.h,v 1.2 2000/02/19 01:50:03 mjacob Exp $ */
      2  1.1  mjacob /*
      3  1.1  mjacob  * Qlogic ISP Host Adapter Public Target Interface Structures && Routines
      4  1.1  mjacob  *---------------------------------------
      5  1.1  mjacob  * Copyright (c) 2000 by Matthew Jacob
      6  1.1  mjacob  * All rights reserved.
      7  1.1  mjacob  *
      8  1.1  mjacob  * Redistribution and use in source and binary forms, with or without
      9  1.1  mjacob  * modification, are permitted provided that the following conditions
     10  1.1  mjacob  * are met:
     11  1.1  mjacob  * 1. Redistributions of source code must retain the above copyright
     12  1.1  mjacob  *    notice, this list of conditions, and the following disclaimer,
     13  1.1  mjacob  *    without modification, immediately at the beginning of the file.
     14  1.1  mjacob  * 2. The name of the author may not be used to endorse or promote products
     15  1.1  mjacob  *    derived from this software without specific prior written permission.
     16  1.1  mjacob  *
     17  1.1  mjacob  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     18  1.1  mjacob  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     19  1.1  mjacob  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     20  1.1  mjacob  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     21  1.1  mjacob  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22  1.1  mjacob  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     23  1.1  mjacob  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24  1.1  mjacob  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     25  1.1  mjacob  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     26  1.1  mjacob  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27  1.1  mjacob  * SUCH DAMAGE.
     28  1.1  mjacob  *
     29  1.1  mjacob  * Matthew Jacob
     30  1.1  mjacob  * Feral Software
     31  1.1  mjacob  * mjacob (at) feral.com
     32  1.1  mjacob  */
     33  1.1  mjacob 
     34  1.1  mjacob /*
     35  1.1  mjacob  * Required software target mode message and event handling structures.
     36  1.1  mjacob  *
     37  1.1  mjacob  * The message and event structures are used by the MI layer
     38  1.1  mjacob  * to propagate messages and events upstream.
     39  1.1  mjacob  */
     40  1.1  mjacob 
     41  1.1  mjacob #ifndef	IN_MSGLEN
     42  1.1  mjacob #define	IN_MSGLEN	8
     43  1.1  mjacob #endif
     44  1.1  mjacob typedef struct {
     45  1.1  mjacob 	void *		nt_hba;			/* HBA tag */
     46  1.1  mjacob 	u_int64_t	nt_iid;			/* inititator id */
     47  1.1  mjacob 	u_int64_t	nt_tgt;			/* target id */
     48  1.1  mjacob 	u_int64_t	nt_lun;			/* logical unit */
     49  1.1  mjacob 	u_int8_t	nt_bus;			/* bus */
     50  1.1  mjacob 	u_int8_t	nt_tagtype;		/* tag type */
     51  1.1  mjacob 	u_int16_t	nt_tagval;		/* tag value */
     52  1.1  mjacob 	u_int8_t	nt_msg[IN_MSGLEN];	/* message content */
     53  1.1  mjacob } tmd_msg_t;
     54  1.1  mjacob 
     55  1.1  mjacob typedef struct {
     56  1.1  mjacob 	void *		ev_hba;			/* HBA tag */
     57  1.1  mjacob 	u_int16_t	ev_bus;			/* bus */
     58  1.1  mjacob 	u_int16_t	ev_event;		/* type of async event */
     59  1.1  mjacob } tmd_event_t;
     60  1.1  mjacob 
     61  1.1  mjacob /*
     62  1.1  mjacob  * Suggested software target mode command handling structure.
     63  1.1  mjacob  *
     64  1.1  mjacob  * The command structure is one suggested possible MD command structure,
     65  1.1  mjacob  * but since the handling of thbis is entirely in the MD layer, there
     66  1.1  mjacob  * is no requirement that it be used.
     67  1.1  mjacob  *
     68  1.1  mjacob  * The cd_private tag should be used by the MD layer to keep a free list
     69  1.1  mjacob  * of these structures. Code outside of this driver can then use this
     70  1.1  mjacob  * as an to identify it's own unit structures. That is, when not on the MD
     71  1.1  mjacob  * layer's freelist, the MD layer should shove into it the identifier
     72  1.1  mjacob  * that the outer layer has for it- passed in on an initial QIN_HBA_REG
     73  1.1  mjacob  * call (see below).
     74  1.1  mjacob  *
     75  1.1  mjacob  * The cd_hba tag is a tag that uniquely identifies the HBA this target
     76  1.1  mjacob  * mode command is coming from. The outer layer has to pass this back
     77  1.1  mjacob  * unchanged to avoid chaos.
     78  1.1  mjacob  *
     79  1.1  mjacob  * The cd_iid, cd_tgt, cd_lun and cd_bus tags are used to identify the
     80  1.1  mjacob  * id of the initiator who sent us a command, the target claim to be, the
     81  1.1  mjacob  * lun on the target we claim to be, and the bus instance (for multiple
     82  1.1  mjacob  * bus host adapters) that this applies to (consider it an extra Port
     83  1.1  mjacob  * parameter). The iid, tgt and lun values are deliberately chosen to be
     84  1.1  mjacob  * fat so that, for example, World Wide Names can be used instead of
     85  1.1  mjacob  * the units that the Qlogic firmware uses (in the case where the MD
     86  1.1  mjacob  * layer maintains a port database, for example).
     87  1.1  mjacob  *
     88  1.1  mjacob  * The cd_tagtype field specifies what kind of command tag has been
     89  1.1  mjacob  * sent with the command. The cd_tagval is the tag's value.
     90  1.1  mjacob  *
     91  1.1  mjacob  * N.B.: when the MD layer sends this command to outside software
     92  1.1  mjacob  * the outside software likely *MUST* return the same cd_tagval that
     93  1.1  mjacob  * was in place because this value is likely what the Qlogic f/w uses
     94  1.1  mjacob  * to identify a command.
     95  1.1  mjacob  *
     96  1.1  mjacob  * The cd_cdb contains storage for the passed in command descriptor block.
     97  1.1  mjacob  * This is the maximum size we can get out of the Qlogic f/w. There's no
     98  1.1  mjacob  * passed in length because whoever decodes the command to act upon it
     99  1.1  mjacob  * will know what the appropriate length is.
    100  1.1  mjacob  *
    101  1.1  mjacob  * The tag cd_lflags are the flags set by the MD driver when it gets
    102  1.1  mjacob  * command incoming or when it needs to inform any outside entities
    103  1.1  mjacob  * that the last requested action failed.
    104  1.1  mjacob  *
    105  1.1  mjacob  * The tag cd_hflags should be set by any outside software to indicate
    106  1.1  mjacob  * the validity of sense and status fields (defined below) and to indicate
    107  1.1  mjacob  * the direction data is expected to move. It is an error to have both
    108  1.1  mjacob  * CDFH_DATA_IN and CDFH_DATA_OUT set.
    109  1.1  mjacob  *
    110  1.1  mjacob  * If the CDFH_STSVALID flag is set, the command should be completed (after
    111  1.1  mjacob  * sending any data and/or status). If CDFH_SNSVALID is set and the MD layer
    112  1.1  mjacob  * can also handle sending the associated sense data (either back with an
    113  1.1  mjacob  * FCP RESPONSE IU for Fibre Channel or otherwise automatically handling a
    114  1.1  mjacob  * REQUEST SENSE from the initator for this target/lun), the MD layer will
    115  1.1  mjacob  * set the CDFL_SENTSENSE flag on successful transmission of the sense data.
    116  1.1  mjacob  * It is an error for the CDFH_SNSVALID bit to be set and CDFH_STSVALID not
    117  1.1  mjacob  * to be set. It is an error for the CDFH_SNSVALID be set and the associated
    118  1.1  mjacob  * SCSI status (cd_scsi_status) not be set to CHECK CONDITON.
    119  1.1  mjacob  *
    120  1.1  mjacob  * The tag cd_data points to a data segment to either be filled or
    121  1.1  mjacob  * read from depending on the direction of data movement. The tag
    122  1.1  mjacob  * is undefined if no data direction is set. The MD layer and outer
    123  1.1  mjacob  * layers must agree on the meaning of cd_data.
    124  1.1  mjacob  *
    125  1.1  mjacob  * The tag cd_totlen is the total data amount expected to be moved
    126  1.1  mjacob  * over the life of the command. It may be set by the MD layer,
    127  1.1  mjacob  * for example, from the datalen field of an FCP CMND IU unit. If
    128  1.1  mjacob  * it shows up in the outer layers set to zero and the CDB indicates
    129  1.1  mjacob  * data should be moved, the outer layer should set it to the amount
    130  1.1  mjacob  * expected to be moved.
    131  1.1  mjacob  *
    132  1.2  mjacob  * The tag cd_resid should be the total residual of data not transferred.
    133  1.2  mjacob  * The outer layers need to set this at the begining of command processing
    134  1.2  mjacob  * to equal cd_totlen. As data is successfully moved, this value is decreased.
    135  1.2  mjacob  * At the end of a command, any nonzero residual indicates the number of bytes
    136  1.2  mjacob  * requested but not moved.
    137  1.1  mjacob  *
    138  1.1  mjacob  * The tag cd_xfrlen is the length of the currently active data transfer.
    139  1.1  mjacob  * This allows several interations between any outside software and the
    140  1.1  mjacob  * MD layer to move data.
    141  1.1  mjacob  *
    142  1.1  mjacob  * The reason that total length and total residual have to be tracked
    143  1.1  mjacob  * is that fibre channel FCP DATA IU units have to have a relative
    144  1.1  mjacob  * offset field.
    145  1.1  mjacob  *
    146  1.1  mjacob  * N.B.: there is no necessary 1-to-1 correspondence between any one
    147  1.1  mjacob  * data transfer segment and the number of CTIOs that will be generated
    148  1.1  mjacob  * satisfy the current data transfer segment. It's not also possible to
    149  1.1  mjacob  * predict how big a transfer can be before it will be 'too big'. Be
    150  1.1  mjacob  * reasonable- a 64KB transfer is 'reasonable'. A 1MB transfer may not
    151  1.1  mjacob  * be. A 32MB transfer is unreasonable. The problem here has to do with
    152  1.1  mjacob  * how CTIOs can be used to map passed data pointers. In systems which
    153  1.1  mjacob  * have page based scatter-gather requirements, each PAGESIZEd chunk will
    154  1.1  mjacob  * consume one data segment descriptor- you get 3 or 4 of them per CTIO.
    155  1.1  mjacob  * The size of the REQUEST QUEUE you drop a CTIO onto is finite (typically
    156  1.1  mjacob  * it's 256, but on some systems it's even smaller, and note you have to
    157  1.1  mjacob  * sure this queue with the initiator side of this driver).
    158  1.1  mjacob  *
    159  1.1  mjacob  * The tags cd_sense and cd_scsi_status are pretty obvious.
    160  1.1  mjacob  *
    161  1.1  mjacob  * The tag cd_error is to communicate between the MD layer and outer software
    162  1.1  mjacob  * the current error conditions.
    163  1.1  mjacob  *
    164  1.1  mjacob  * The tag cd_reserved pads out the structure to 128 bytes.
    165  1.1  mjacob  */
    166  1.1  mjacob 
    167  1.1  mjacob #ifndef	_LP64
    168  1.1  mjacob #if	defined(__alpha__) || defined(__sparcv9cpu) || defined(__sparc_v9__)
    169  1.1  mjacob #define	_LP64
    170  1.1  mjacob #endif
    171  1.1  mjacob #endif
    172  1.1  mjacob 
    173  1.1  mjacob #ifndef	_TMD_PAD_LEN
    174  1.1  mjacob #ifdef	_LP64
    175  1.1  mjacob #define	_TMD_PAD_LEN	12
    176  1.1  mjacob #else
    177  1.1  mjacob #define	_TMD_PAD_LEN	24
    178  1.1  mjacob #endif
    179  1.1  mjacob #endif
    180  1.1  mjacob #ifndef	ATIO_CDBLEN
    181  1.1  mjacob #define	ATIO_CDBLEN	26
    182  1.1  mjacob #endif
    183  1.1  mjacob #ifndef	QLTM_SENSELEN
    184  1.1  mjacob #define	QLTM_SENSELEN	18
    185  1.1  mjacob #endif
    186  1.1  mjacob typedef struct tmd_cmd {
    187  1.1  mjacob 	void *			cd_private;	/* layer private data */
    188  1.1  mjacob 	void *			cd_hba;		/* HBA tag */
    189  1.1  mjacob 	void *			cd_data;	/* 'pointer' to data */
    190  1.1  mjacob 	u_int64_t		cd_iid;		/* initiator ID */
    191  1.1  mjacob 	u_int64_t		cd_tgt;		/* target id */
    192  1.1  mjacob 	u_int64_t		cd_lun;		/* logical unit */
    193  1.1  mjacob 	u_int8_t		cd_bus;		/* bus */
    194  1.1  mjacob 	u_int8_t		cd_tagtype;	/* tag type */
    195  1.1  mjacob 	u_int16_t		cd_tagval;	/* tag value */
    196  1.1  mjacob 	u_int8_t		cd_cdb[ATIO_CDBLEN];	/* Command */
    197  1.1  mjacob 	u_int8_t		cd_lflags;	/* flags lower level sets */
    198  1.1  mjacob 	u_int8_t		cd_hflags;	/* flags higher level sets */
    199  1.1  mjacob 	u_int32_t		cd_totlen;	/* total data requirement */
    200  1.1  mjacob 	u_int32_t		cd_resid;	/* total data residual */
    201  1.1  mjacob 	u_int32_t		cd_xfrlen;	/* current data requirement */
    202  1.1  mjacob 	int32_t			cd_error;	/* current error */
    203  1.1  mjacob 	u_int8_t		cd_sense[QLTM_SENSELEN];
    204  1.1  mjacob 	u_int16_t		cd_scsi_status;	/* closing SCSI status */
    205  1.1  mjacob 	u_int8_t		cd_reserved[_TMD_PAD_LEN];
    206  1.1  mjacob } tmd_cmd_t;
    207  1.1  mjacob 
    208  1.1  mjacob #define	CDFL_BUSY	0x01		/* this command is not on a free list */
    209  1.1  mjacob #define	CDFL_NODISC	0x02		/* disconnect not allowed */
    210  1.1  mjacob #define	CDFL_SENTSENSE	0x04		/* last action sent sense data */
    211  1.1  mjacob #define	CDFL_ERROR	0x08		/* last action ended in error */
    212  1.1  mjacob #define	CDFL_PRIVATE_0	0x80		/* private layer flags */
    213  1.1  mjacob 
    214  1.1  mjacob #define	CDFH_SNSVALID	0x01		/* sense data valid */
    215  1.1  mjacob #define	CDFH_STSVALID	0x02		/* status valid */
    216  1.1  mjacob #define	CDFH_NODATA	0x00		/* no data transfer expected */
    217  1.1  mjacob #define	CDFH_DATA_IN	0x04		/* target (us) -> initiator (them) */
    218  1.1  mjacob #define	CDFH_DATA_OUT	0x08		/* initiator (them) -> target (us) */
    219  1.1  mjacob #define	CDFH_DATA_MASK	0x0C		/* mask to cover data direction */
    220  1.1  mjacob #define	CDFH_PRIVATE_0	0x80		/* private layer flags */
    221  1.1  mjacob 
    222  1.1  mjacob /*
    223  1.1  mjacob  * Action codes set by the Qlogic MD target driver for
    224  1.1  mjacob  * the external layer to figure out what to do with.
    225  1.1  mjacob  */
    226  1.1  mjacob typedef enum {
    227  1.1  mjacob 	QOUT_HBA_REG=0,	/* the argument is a pointer to a hba_register_t */
    228  1.1  mjacob 	QOUT_TMD_START,	/* the argument is a pointer to a tmd_cmd_t */
    229  1.1  mjacob 	QOUT_TMD_DONE,	/* the argument is a pointer to a tmd_cmd_t */
    230  1.1  mjacob 	QOUT_TEVENT,	/* the argument is a pointer to a tmd_event_t */
    231  1.1  mjacob 	QOUT_TMSG,	/* the argument is a pointer to a tmd_msg_t */
    232  1.1  mjacob 	QOUT_HBA_UNREG	/* the argument is a pointer to a hba_register_t */
    233  1.1  mjacob } tact_e;
    234  1.1  mjacob 
    235  1.1  mjacob /*
    236  1.1  mjacob  * Action codes set by the external layer for the
    237  1.1  mjacob  * MD Qlogic driver to figure out what to do with.
    238  1.1  mjacob  */
    239  1.1  mjacob typedef enum {
    240  1.1  mjacob 	QIN_HBA_REG=6,	/* the argument is a pointer to a hba_register_t */
    241  1.1  mjacob 	QIN_TMD_CONT,	/* the argument is a pointer to a tmd_cmd_t */
    242  1.1  mjacob 	QIN_TMD_FIN,	/* the argument is a pointer to a done tmd_cmd_t */
    243  1.1  mjacob 	QIN_HBA_UNREG	/* the argument is a pointer to a hba_register_t */
    244  1.1  mjacob } qact_e;
    245  1.1  mjacob 
    246  1.1  mjacob /*
    247  1.1  mjacob  * A word about the START/CONT/DONE/FIN dance:
    248  1.1  mjacob  *
    249  1.1  mjacob  *	When the HBA is enabled for receiving commands, one may	show up
    250  1.1  mjacob  *	without notice. When that happens, the Qlogic target mode driver
    251  1.1  mjacob  *	gets a tmd_cmd_t, fills it with the info that just arrived, and
    252  1.1  mjacob  *	calls the outer layer with a QIN_TMD_START code and pointer to
    253  1.1  mjacob  *	the tmd_cmd_t.
    254  1.1  mjacob  *
    255  1.1  mjacob  *	The outer layer decodes the command, fetches data, prepares stuff,
    256  1.1  mjacob  *	whatever, and starts by passing back the pointer with a QIN_TMD_CONT
    257  1.1  mjacob  *	code which causes the Qlogic target mode driver to generate CTIOs to
    258  1.1  mjacob  *	satisfy whatever action needs to be taken. When those CTIOs complete,
    259  1.1  mjacob  *	the Qlogic target driver sends the pointer to the cmd_tmd_t back with
    260  1.1  mjacob  *	a QOUT_TMD_DONE code. This repeats for as long as necessary.
    261  1.1  mjacob  *
    262  1.1  mjacob  *	The outer layer signals it wants to end the command by settings within
    263  1.1  mjacob  *	the tmd_cmd_t itself. When the final QIN_TMD_CONT is reported completed,
    264  1.1  mjacob  *	the outer layer frees the tmd_cmd_t by sending the pointer to it
    265  1.1  mjacob  *	back with a QIN_TMD_FIN code.
    266  1.1  mjacob  *
    267  1.1  mjacob  *	The graph looks like:
    268  1.1  mjacob  *
    269  1.1  mjacob  *	QOUT_TMD_START -> [ QIN_TMD_CONT -> QOUT_TMD_DONE ] * -> QIN_TMD_FIN.
    270  1.1  mjacob  */
    271  1.1  mjacob 
    272  1.1  mjacob /*
    273  1.1  mjacob  * Target handler functions.
    274  1.1  mjacob  * The MD target handler function (the outer layer calls this)
    275  1.1  mjacob  * should be be prototyped like:
    276  1.1  mjacob  *
    277  1.1  mjacob  *	void target_action(qact_e, void *arg)
    278  1.1  mjacob  *
    279  1.1  mjacob  * The outer layer target handler function (the MD layer calls this)
    280  1.1  mjacob  * should be be prototyped like:
    281  1.1  mjacob  *
    282  1.1  mjacob  *	void system_action(tact_e, void *arg)
    283  1.1  mjacob  */
    284  1.1  mjacob 
    285  1.1  mjacob /*
    286  1.1  mjacob  * This structure is used to register to other software modules the
    287  1.1  mjacob  * binding of an HBA identifier, driver name and instance and the
    288  1.1  mjacob  * lun width capapbilities of this target driver. It's up to each
    289  1.1  mjacob  * platform to figure out how it wants to do this, but a typical
    290  1.1  mjacob  * sequence would be for the MD layer to find some external module's
    291  1.1  mjacob  * entry point and start by sending a QOUT_HBA_REG with info filled
    292  1.1  mjacob  * in, and the external module to call back with a QIN_HBA_REG that
    293  1.1  mjacob  * passes back the corresponding information.
    294  1.1  mjacob  */
    295  1.1  mjacob typedef struct {
    296  1.1  mjacob 	void *	r_identity;
    297  1.1  mjacob 	char	r_name[8];
    298  1.1  mjacob 	int	r_inst;
    299  1.1  mjacob 	int	r_lunwidth;
    300  1.1  mjacob 	void   (*r_action) __P((int, void *));
    301  1.1  mjacob } hba_register_t;
    302