Home | History | Annotate | Line # | Download | only in ic
isp_tpublic.h revision 1.14.32.1
      1  1.14.32.1     mjf /* $NetBSD: isp_tpublic.h,v 1.14.32.1 2007/07/11 20:05:57 mjf Exp $ */
      2        1.4  mjacob /*
      3  1.14.32.1     mjf  * Copyright (c) 1997-2006 by Matthew Jacob
      4        1.1  mjacob  * All rights reserved.
      5        1.1  mjacob  *
      6        1.1  mjacob  * Redistribution and use in source and binary forms, with or without
      7        1.1  mjacob  * modification, are permitted provided that the following conditions
      8        1.1  mjacob  * are met:
      9  1.14.32.1     mjf  *
     10        1.1  mjacob  * 1. Redistributions of source code must retain the above copyright
     11  1.14.32.1     mjf  *    notice, this list of conditions and the following disclaimer.
     12  1.14.32.1     mjf  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.14.32.1     mjf  *    notice, this list of conditions and the following disclaimer in the
     14  1.14.32.1     mjf  *    documentation and/or other materials provided with the distribution.
     15  1.14.32.1     mjf  *
     16  1.14.32.1     mjf  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17        1.1  mjacob  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18        1.1  mjacob  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  1.14.32.1     mjf  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
     20  1.14.32.1     mjf  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21        1.1  mjacob  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22        1.1  mjacob  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23        1.1  mjacob  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24        1.1  mjacob  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25        1.1  mjacob  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26        1.1  mjacob  * SUCH DAMAGE.
     27        1.1  mjacob  */
     28  1.14.32.1     mjf /*
     29  1.14.32.1     mjf  * Host Adapter Public Target Interface Structures && Routines
     30  1.14.32.1     mjf  */
     31  1.14.32.1     mjf 
     32  1.14.32.1     mjf #ifndef    _ISP_TPUBLIC_H
     33  1.14.32.1     mjf #define    _ISP_TPUBLIC_H    1
     34        1.1  mjacob 
     35        1.1  mjacob /*
     36  1.14.32.1     mjf  * Action codes set by the MD target driver for
     37  1.14.32.1     mjf  * the external layer to figure out what to do with.
     38        1.1  mjacob  */
     39  1.14.32.1     mjf typedef enum {
     40  1.14.32.1     mjf     QOUT_HBA_REG=0,     /* the argument is a pointer to a hba_register_t */
     41  1.14.32.1     mjf     QOUT_ENABLE,        /* the argument is a pointer to a enadis_t */
     42  1.14.32.1     mjf     QOUT_DISABLE,       /* the argument is a pointer to a enadis_t */
     43  1.14.32.1     mjf     QOUT_TMD_START,     /* the argument is a pointer to a tmd_cmd_t */
     44  1.14.32.1     mjf     QOUT_TMD_DONE,      /* the argument is a pointer to a tmd_cmd_t */
     45  1.14.32.1     mjf     QOUT_NOTIFY,        /* the argument is a pointer to a tmd_notify_t */
     46  1.14.32.1     mjf     QOUT_HBA_UNREG      /* the argument is a pointer to a hba_register_t */
     47  1.14.32.1     mjf } tact_e;
     48        1.1  mjacob 
     49  1.14.32.1     mjf /*
     50  1.14.32.1     mjf  * Action codes set by the external layer for the
     51  1.14.32.1     mjf  * MD driver to figure out what to do with.
     52  1.14.32.1     mjf  */
     53  1.14.32.1     mjf typedef enum {
     54  1.14.32.1     mjf     QIN_HBA_REG=99,     /* the argument is a pointer to a hba_register_t */
     55  1.14.32.1     mjf     QIN_GETINFO,        /* the argument is a pointer to a info_t */
     56  1.14.32.1     mjf     QIN_SETINFO,        /* the argument is a pointer to a info_t */
     57  1.14.32.1     mjf     QIN_GETDLIST,       /* the argument is a pointer to a fc_dlist_t */
     58  1.14.32.1     mjf     QIN_ENABLE,         /* the argument is a pointer to a enadis_t */
     59  1.14.32.1     mjf     QIN_DISABLE,        /* the argument is a pointer to a enadis_t */
     60  1.14.32.1     mjf     QIN_TMD_CONT,       /* the argument is a pointer to a tmd_cmd_t */
     61  1.14.32.1     mjf     QIN_TMD_FIN,        /* the argument is a pointer to a tmd_cmd_t */
     62  1.14.32.1     mjf     QIN_NOTIFY_ACK,     /* the argument is a pointer to a tmd_notify_t */
     63  1.14.32.1     mjf     QIN_HBA_UNREG,      /* the argument is a pointer to a hba_register_t */
     64  1.14.32.1     mjf } qact_e;
     65  1.14.32.1     mjf 
     66  1.14.32.1     mjf /*
     67  1.14.32.1     mjf  * This structure is used to register to other software modules the
     68  1.14.32.1     mjf  * binding of an HBA identifier, driver name and instance and the
     69  1.14.32.1     mjf  * lun width capapbilities of this target driver. It's up to each
     70  1.14.32.1     mjf  * platform to figure out how it wants to do this, but a typical
     71  1.14.32.1     mjf  * sequence would be for the MD layer to find some external module's
     72  1.14.32.1     mjf  * entry point and start by sending a QOUT_HBA_REG with info filled
     73  1.14.32.1     mjf  * in, and the external module to call back with a QIN_HBA_REG that
     74  1.14.32.1     mjf  * passes back the corresponding information.
     75  1.14.32.1     mjf  */
     76  1.14.32.1     mjf #define    QR_VERSION    16
     77  1.14.32.1     mjf typedef struct {
     78  1.14.32.1     mjf     /* NB: tags from here to r_version must never change */
     79  1.14.32.1     mjf     void *                  r_identity;
     80  1.14.32.1     mjf     void                    (*r_action)(qact_e, void *);
     81  1.14.32.1     mjf     char                    r_name[8];
     82  1.14.32.1     mjf     int                     r_inst;
     83  1.14.32.1     mjf     int                     r_version;
     84  1.14.32.1     mjf     uint32_t                r_locator;
     85  1.14.32.1     mjf     uint32_t                r_nchannels;
     86  1.14.32.1     mjf     enum { R_FC, R_SPI }    r_type;
     87  1.14.32.1     mjf     void *                  r_private;
     88  1.14.32.1     mjf } hba_register_t;
     89  1.14.32.1     mjf 
     90  1.14.32.1     mjf /*
     91  1.14.32.1     mjf  * An information structure that is used to get or set per-channel transport layer parameters.
     92  1.14.32.1     mjf  */
     93  1.14.32.1     mjf typedef struct {
     94  1.14.32.1     mjf     void *                  i_identity;
     95  1.14.32.1     mjf     enum { I_FC, I_SPI }    i_type;
     96  1.14.32.1     mjf     int                     i_channel;
     97  1.14.32.1     mjf     int                     i_error;
     98  1.14.32.1     mjf     union {
     99  1.14.32.1     mjf         struct {
    100  1.14.32.1     mjf             uint64_t    wwnn_nvram;
    101  1.14.32.1     mjf             uint64_t    wwpn_nvram;
    102  1.14.32.1     mjf             uint64_t    wwnn;
    103  1.14.32.1     mjf             uint64_t    wwpn;
    104  1.14.32.1     mjf         } fc;
    105  1.14.32.1     mjf         struct {
    106  1.14.32.1     mjf             int         iid;
    107  1.14.32.1     mjf         } spi;
    108  1.14.32.1     mjf     }                       i_id;
    109  1.14.32.1     mjf } info_t;
    110  1.14.32.1     mjf 
    111  1.14.32.1     mjf /*
    112  1.14.32.1     mjf  * An information structure to return a list of logged in WWPNs. FC specific.
    113  1.14.32.1     mjf  */
    114        1.1  mjacob typedef struct {
    115  1.14.32.1     mjf     void *                  d_identity;
    116  1.14.32.1     mjf     int                     d_channel;
    117  1.14.32.1     mjf     int                     d_error;
    118  1.14.32.1     mjf     int                     d_count;
    119  1.14.32.1     mjf     uint64_t *              d_wwpns;
    120  1.14.32.1     mjf } fc_dlist_t;
    121  1.14.32.1     mjf /*
    122  1.14.32.1     mjf  * Notify structure
    123  1.14.32.1     mjf  */
    124  1.14.32.1     mjf typedef enum {
    125  1.14.32.1     mjf     NT_ABORT_TASK=0x1000,
    126  1.14.32.1     mjf     NT_ABORT_TASK_SET,
    127  1.14.32.1     mjf     NT_CLEAR_ACA,
    128  1.14.32.1     mjf     NT_CLEAR_TASK_SET,
    129  1.14.32.1     mjf     NT_LUN_RESET,
    130  1.14.32.1     mjf     NT_TARGET_RESET,
    131  1.14.32.1     mjf     NT_BUS_RESET,
    132  1.14.32.1     mjf     NT_LIP_RESET,
    133  1.14.32.1     mjf     NT_LINK_UP,
    134  1.14.32.1     mjf     NT_LINK_DOWN,
    135  1.14.32.1     mjf     NT_LOGOUT,
    136  1.14.32.1     mjf     NT_HBA_RESET
    137  1.14.32.1     mjf } tmd_ncode_t;
    138  1.14.32.1     mjf 
    139  1.14.32.1     mjf typedef struct tmd_notify {
    140  1.14.32.1     mjf     void *      nt_hba;         /* HBA tag */
    141  1.14.32.1     mjf     uint64_t    nt_iid;         /* inititator id */
    142  1.14.32.1     mjf     uint64_t    nt_tgt;         /* target id */
    143  1.14.32.1     mjf     uint16_t    nt_lun;         /* logical unit */
    144  1.14.32.1     mjf     uint16_t                : 15,
    145  1.14.32.1     mjf                 nt_need_ack : 1;    /* this notify needs an ACK */
    146  1.14.32.1     mjf     uint64_t    nt_tagval;      /* tag value */
    147  1.14.32.1     mjf     uint32_t    nt_channel;     /* channel id */
    148  1.14.32.1     mjf     tmd_ncode_t nt_ncode;       /* action */
    149  1.14.32.1     mjf     void *      nt_lreserved;
    150  1.14.32.1     mjf     void *      nt_hreserved;
    151  1.14.32.1     mjf } tmd_notify_t;
    152  1.14.32.1     mjf #define LUN_ANY     0xffff
    153  1.14.32.1     mjf #define TGT_ANY     ((uint64_t) -1)
    154  1.14.32.1     mjf #define INI_ANY     ((uint64_t) -1)
    155  1.14.32.1     mjf #define TAG_ANY     ((uint64_t) 0)
    156  1.14.32.1     mjf #define MATCH_TMD(tmd, iid, lun, tag)                   \
    157  1.14.32.1     mjf     (                                                   \
    158  1.14.32.1     mjf         (tmd) &&                                        \
    159  1.14.32.1     mjf         (iid == INI_ANY || iid == tmd->cd_iid) &&       \
    160  1.14.32.1     mjf         (lun == LUN_ANY || lun == tmd->cd_lun) &&       \
    161  1.14.32.1     mjf         (tag == TAG_ANY || tag == tmd->cd_tagval)       \
    162  1.14.32.1     mjf     )
    163        1.1  mjacob 
    164  1.14.32.1     mjf /*
    165  1.14.32.1     mjf  * A word about ENABLE/DISABLE: the argument is a pointer to a enadis_t
    166  1.14.32.1     mjf  * with en_hba, en_iid, en_chan, en_tgt and en_lun filled out.
    167  1.14.32.1     mjf  *
    168  1.14.32.1     mjf  * If an error occurs in either enabling or disabling the described lun
    169  1.14.32.1     mjf  * cd_error is set with an appropriate non-zero value.
    170  1.14.32.1     mjf  */
    171        1.1  mjacob typedef struct {
    172  1.14.32.1     mjf     void *          en_private;     /* for outer layer usage */
    173  1.14.32.1     mjf     void *          en_hba;         /* HBA tag */
    174  1.14.32.1     mjf     uint64_t        en_iid;         /* initiator ID */
    175  1.14.32.1     mjf     uint64_t        en_tgt;         /* target id */
    176  1.14.32.1     mjf     uint16_t        en_lun;         /* logical unit */
    177  1.14.32.1     mjf     uint16_t        en_chan;        /* channel on card */
    178  1.14.32.1     mjf     int             en_error;
    179  1.14.32.1     mjf } enadis_t;
    180        1.1  mjacob 
    181        1.1  mjacob /*
    182        1.3      he  * Suggested Software Target Mode Command Handling structure.
    183        1.1  mjacob  *
    184        1.3      he  * A note about terminology:
    185        1.3      he  *
    186        1.3      he  *   MD stands for "Machine Dependent".
    187        1.3      he  *
    188        1.3      he  *    This driver is structured in three layers: Outer MD, core, and inner MD.
    189        1.3      he  *    The latter also is bus dependent (i.e., is cognizant of PCI bus issues
    190        1.3      he  *    as well as platform issues).
    191        1.3      he  *
    192        1.3      he  *
    193        1.3      he  *   "Outer Layer" means "Other Module"
    194        1.3      he  *
    195        1.3      he  *    Some additional module that actually implements SCSI target command
    196        1.3      he  *    policy is the recipient of incoming commands and the source of the
    197        1.3      he  *    disposition for them.
    198        1.3      he  *
    199        1.3      he  * The command structure below is one suggested possible MD command structure,
    200        1.3      he  * but since the handling of thbis is entirely in the MD layer, there is
    201        1.3      he  * no explicit or implicit requirement that it be used.
    202        1.1  mjacob  *
    203        1.1  mjacob  * The cd_private tag should be used by the MD layer to keep a free list
    204        1.1  mjacob  * of these structures. Code outside of this driver can then use this
    205        1.9  mjacob  * to identify it's own unit structures. That is, when not on the MD
    206        1.1  mjacob  * layer's freelist, the MD layer should shove into it the identifier
    207        1.1  mjacob  * that the outer layer has for it- passed in on an initial QIN_HBA_REG
    208        1.1  mjacob  * call (see below).
    209        1.1  mjacob  *
    210        1.1  mjacob  * The cd_hba tag is a tag that uniquely identifies the HBA this target
    211        1.1  mjacob  * mode command is coming from. The outer layer has to pass this back
    212        1.1  mjacob  * unchanged to avoid chaos.
    213        1.1  mjacob  *
    214  1.14.32.1     mjf  * The cd_iid, cd_tgt, cd_lun and cd_port tags are used to identify the
    215        1.1  mjacob  * id of the initiator who sent us a command, the target claim to be, the
    216  1.14.32.1     mjf  * lun on the target we claim to be, and the port instance (for multiple
    217  1.14.32.1     mjf  * port host adapters) that this applies to (consider it an extra port
    218        1.1  mjacob  * parameter). The iid, tgt and lun values are deliberately chosen to be
    219        1.1  mjacob  * fat so that, for example, World Wide Names can be used instead of
    220  1.14.32.1     mjf  * the units that the firmware uses (in the case where the MD
    221        1.1  mjacob  * layer maintains a port database, for example).
    222        1.1  mjacob  *
    223  1.14.32.1     mjf  * The cd_tagtype field specifies what kind of command tag type, if
    224  1.14.32.1     mjf  * any, has been sent with the command. Note that the Outer Layer
    225  1.14.32.1     mjf  * still needs to pass the tag handle through unchanged even
    226  1.14.32.1     mjf  * if the tag type is CD_UNTAGGED.
    227        1.1  mjacob  *
    228        1.1  mjacob  * The cd_cdb contains storage for the passed in command descriptor block.
    229  1.14.32.1     mjf  * There is no need to define length as the callee should be able to
    230  1.14.32.1     mjf  * figure this out.
    231        1.1  mjacob  *
    232        1.1  mjacob  * The tag cd_lflags are the flags set by the MD driver when it gets
    233        1.1  mjacob  * command incoming or when it needs to inform any outside entities
    234        1.1  mjacob  * that the last requested action failed.
    235        1.1  mjacob  *
    236        1.1  mjacob  * The tag cd_hflags should be set by any outside software to indicate
    237        1.1  mjacob  * the validity of sense and status fields (defined below) and to indicate
    238        1.1  mjacob  * the direction data is expected to move. It is an error to have both
    239        1.1  mjacob  * CDFH_DATA_IN and CDFH_DATA_OUT set.
    240        1.1  mjacob  *
    241        1.1  mjacob  * If the CDFH_STSVALID flag is set, the command should be completed (after
    242        1.1  mjacob  * sending any data and/or status). If CDFH_SNSVALID is set and the MD layer
    243        1.1  mjacob  * can also handle sending the associated sense data (either back with an
    244        1.1  mjacob  * FCP RESPONSE IU for Fibre Channel or otherwise automatically handling a
    245        1.1  mjacob  * REQUEST SENSE from the initator for this target/lun), the MD layer will
    246        1.1  mjacob  * set the CDFL_SENTSENSE flag on successful transmission of the sense data.
    247        1.1  mjacob  * It is an error for the CDFH_SNSVALID bit to be set and CDFH_STSVALID not
    248        1.1  mjacob  * to be set. It is an error for the CDFH_SNSVALID be set and the associated
    249        1.1  mjacob  * SCSI status (cd_scsi_status) not be set to CHECK CONDITON.
    250  1.14.32.1     mjf  *
    251        1.1  mjacob  * The tag cd_data points to a data segment to either be filled or
    252        1.1  mjacob  * read from depending on the direction of data movement. The tag
    253        1.1  mjacob  * is undefined if no data direction is set. The MD layer and outer
    254  1.14.32.1     mjf  * layers must agree on the meaning of cd_data and it is specifically
    255  1.14.32.1     mjf  * not defined here.
    256        1.1  mjacob  *
    257        1.1  mjacob  * The tag cd_totlen is the total data amount expected to be moved
    258  1.14.32.1     mjf  * over the life of the command. It may be set by the MD layer, possibly
    259        1.3      he  * from the datalen field of an FCP CMND IU unit. If it shows up in the outer
    260        1.3      he  * layers set to zero and the CDB indicates data should be moved, the outer
    261        1.3      he  * layer should set it to the amount expected to be moved.
    262        1.1  mjacob  *
    263        1.2  mjacob  * The tag cd_resid should be the total residual of data not transferred.
    264  1.14.32.1     mjf  * The outer layers need to set this at the begining of command processing
    265        1.2  mjacob  * to equal cd_totlen. As data is successfully moved, this value is decreased.
    266        1.2  mjacob  * At the end of a command, any nonzero residual indicates the number of bytes
    267  1.14.32.1     mjf  * requested by the command but not moved.
    268        1.1  mjacob  *
    269        1.1  mjacob  * The tag cd_xfrlen is the length of the currently active data transfer.
    270        1.1  mjacob  * This allows several interations between any outside software and the
    271        1.1  mjacob  * MD layer to move data.
    272        1.1  mjacob  *
    273        1.1  mjacob  * The reason that total length and total residual have to be tracked
    274  1.14.32.1     mjf  * is to keep track of relative offset.
    275        1.1  mjacob  *
    276        1.1  mjacob  * The tags cd_sense and cd_scsi_status are pretty obvious.
    277        1.1  mjacob  *
    278        1.1  mjacob  * The tag cd_error is to communicate between the MD layer and outer software
    279        1.1  mjacob  * the current error conditions.
    280        1.1  mjacob  *
    281       1.10  mjacob  * The tag cd_lreserved, cd_hreserved are scratch areas for use for the MD
    282       1.10  mjacob  * and outer layers respectively.
    283  1.14.32.1     mjf  *
    284        1.1  mjacob  */
    285        1.1  mjacob 
    286  1.14.32.1     mjf #ifndef    TMD_CDBLEN
    287  1.14.32.1     mjf #define    TMD_CDBLEN       16
    288       1.10  mjacob #endif
    289  1.14.32.1     mjf #ifndef    TMD_SENSELEN
    290  1.14.32.1     mjf #define    TMD_SENSELEN     18
    291        1.1  mjacob #endif
    292  1.14.32.1     mjf #ifndef    QCDS
    293  1.14.32.1     mjf #define    QCDS             (sizeof (void *))
    294        1.1  mjacob #endif
    295        1.1  mjacob 
    296        1.1  mjacob typedef struct tmd_cmd {
    297  1.14.32.1     mjf     void *              cd_private; /* private data pointer */
    298  1.14.32.1     mjf     void *              cd_hba;     /* HBA tag */
    299  1.14.32.1     mjf     void *              cd_data;    /* 'pointer' to data */
    300  1.14.32.1     mjf     uint64_t            cd_iid;     /* initiator ID */
    301  1.14.32.1     mjf     uint64_t            cd_tgt;     /* target id */
    302  1.14.32.1     mjf     uint8_t             cd_lun[8];  /* logical unit */
    303  1.14.32.1     mjf     uint64_t            cd_tagval;  /* tag value */
    304  1.14.32.1     mjf     uint32_t            cd_channel; /* channel index */
    305  1.14.32.1     mjf     uint32_t            cd_lflags;  /* flags lower level sets */
    306  1.14.32.1     mjf     uint32_t            cd_hflags;  /* flags higher level sets */
    307  1.14.32.1     mjf     uint32_t            cd_totlen;  /* total data load */
    308  1.14.32.1     mjf     uint32_t            cd_resid;   /* total data residual */
    309  1.14.32.1     mjf     uint32_t            cd_xfrlen;  /* current data load */
    310  1.14.32.1     mjf     int32_t             cd_error;   /* current error */
    311  1.14.32.1     mjf     uint8_t             cd_tagtype; /* tag type */
    312  1.14.32.1     mjf     uint8_t             cd_scsi_status;
    313  1.14.32.1     mjf     uint8_t             cd_sense[TMD_SENSELEN];
    314  1.14.32.1     mjf     uint8_t             cd_cdb[TMD_CDBLEN];
    315  1.14.32.1     mjf     union {
    316  1.14.32.1     mjf         void *          ptrs[QCDS / sizeof (void *)];
    317  1.14.32.1     mjf         uint64_t        llongs[QCDS / sizeof (uint64_t)];
    318  1.14.32.1     mjf         uint32_t        longs[QCDS / sizeof (uint32_t)];
    319  1.14.32.1     mjf         uint16_t        shorts[QCDS / sizeof (uint16_t)];
    320  1.14.32.1     mjf         uint8_t         bytes[QCDS];
    321  1.14.32.1     mjf     } cd_lreserved[4], cd_hreserved[4];
    322        1.1  mjacob } tmd_cmd_t;
    323        1.1  mjacob 
    324  1.14.32.1     mjf /* defined tags */
    325  1.14.32.1     mjf #define CD_UNTAGGED     0
    326  1.14.32.1     mjf #define CD_SIMPLE_TAG   1
    327  1.14.32.1     mjf #define CD_ORDERED_TAG  2
    328  1.14.32.1     mjf #define CD_HEAD_TAG     3
    329  1.14.32.1     mjf #define CD_ACA_TAG      4
    330  1.14.32.1     mjf 
    331  1.14.32.1     mjf #ifndef    TMD_SIZE
    332  1.14.32.1     mjf #define    TMD_SIZE     (sizeof (tmd_cmd_t))
    333       1.10  mjacob #endif
    334       1.10  mjacob 
    335  1.14.32.1     mjf #define L0LUN_TO_FLATLUN(lptr)              ((((lptr)[0] & 0x3f) << 8) | ((lptr)[1]))
    336  1.14.32.1     mjf #define FLATLUN_TO_L0LUN(lptr, lun)                 \
    337  1.14.32.1     mjf     (lptr)[1] = lun & 0xff;                         \
    338  1.14.32.1     mjf     if (sizeof (lun) == 1) {                        \
    339  1.14.32.1     mjf         (lptr)[0] = 0;                              \
    340  1.14.32.1     mjf     } else {                                        \
    341  1.14.32.1     mjf         uint16_t nl = lun;                          \
    342  1.14.32.1     mjf         if (nl == LUN_ANY) {                        \
    343  1.14.32.1     mjf             (lptr)[0] = (nl >> 8) & 0xff;           \
    344  1.14.32.1     mjf         } else if (nl < 256) {                      \
    345  1.14.32.1     mjf             (lptr)[0] = 0;                          \
    346  1.14.32.1     mjf         } else {                                    \
    347  1.14.32.1     mjf             (lptr)[0] = 0x40 | ((nl >> 8) & 0x3f);  \
    348  1.14.32.1     mjf         }                                           \
    349  1.14.32.1     mjf     }                                               \
    350  1.14.32.1     mjf     memset(&(lptr)[2], 0, 6)
    351  1.14.32.1     mjf 
    352       1.10  mjacob /*
    353       1.10  mjacob  * Note that NODISC (obviously) doesn't apply to non-SPI transport.
    354       1.10  mjacob  *
    355       1.10  mjacob  * Note that knowing the data direction and lengh at the time of receipt of
    356       1.10  mjacob  * a command from the initiator is a feature only of Fibre Channel.
    357       1.10  mjacob  *
    358       1.10  mjacob  * The CDFL_BIDIR is in anticipation of the adoption of some newer
    359       1.10  mjacob  * features required by OSD.
    360       1.10  mjacob  *
    361       1.10  mjacob  * The principle selector for MD layer to know whether data is to
    362       1.10  mjacob  * be transferred in any QOUT_TMD_CONT call is cd_xfrlen- the
    363       1.10  mjacob  * flags CDFH_DATA_IN and CDFH_DATA_OUT define which direction.
    364       1.10  mjacob  */
    365  1.14.32.1     mjf #define    CDFL_SNSVALID        0x01            /* sense data (from f/w) good */
    366  1.14.32.1     mjf #define    CDFL_SENTSTATUS      0x02            /* last action sent status */
    367  1.14.32.1     mjf #define    CDFL_DATA_IN         0x04            /* target (us) -> initiator (them) */
    368  1.14.32.1     mjf #define    CDFL_DATA_OUT        0x08            /* initiator (them) -> target (us) */
    369  1.14.32.1     mjf #define    CDFL_BIDIR           0x0C            /* bidirectional data */
    370  1.14.32.1     mjf #define    CDFL_ERROR           0x10            /* last action ended in error */
    371  1.14.32.1     mjf #define    CDFL_NODISC          0x20            /* disconnects disabled */
    372  1.14.32.1     mjf #define    CDFL_SENTSENSE       0x40            /* last action sent sense data */
    373  1.14.32.1     mjf #define    CDFL_BUSY            0x80            /* this command is not on a free list */
    374  1.14.32.1     mjf #define    CDFL_PRIVATE         0xFF000000      /* private layer flags */
    375  1.14.32.1     mjf 
    376  1.14.32.1     mjf #define    CDFH_SNSVALID        0x01            /* sense data (from outer layer) good */
    377  1.14.32.1     mjf #define    CDFH_STSVALID        0x02            /* status valid */
    378  1.14.32.1     mjf #define    CDFH_DATA_IN         0x04            /* target (us) -> initiator (them) */
    379  1.14.32.1     mjf #define    CDFH_DATA_OUT        0x08            /* initiator (them) -> target (us) */
    380  1.14.32.1     mjf #define    CDFH_DATA_MASK       0x0C            /* mask to cover data direction */
    381  1.14.32.1     mjf #define    CDFH_PRIVATE         0xFF000000      /* private layer flags */
    382        1.1  mjacob 
    383       1.10  mjacob 
    384        1.1  mjacob /*
    385        1.1  mjacob  * A word about the START/CONT/DONE/FIN dance:
    386        1.1  mjacob  *
    387  1.14.32.1     mjf  *    When the HBA is enabled for receiving commands, one may show up
    388  1.14.32.1     mjf  *    without notice. When that happens, the MD target mode driver
    389  1.14.32.1     mjf  *    gets a tmd_cmd_t, fills it with the info that just arrived, and
    390  1.14.32.1     mjf  *    calls the outer layer with a QOUT_TMD_START code and pointer to
    391  1.14.32.1     mjf  *    the tmd_cmd_t.
    392  1.14.32.1     mjf  *
    393  1.14.32.1     mjf  *    The outer layer decodes the command, fetches data, prepares stuff,
    394  1.14.32.1     mjf  *    whatever, and starts by passing back the pointer with a QIN_TMD_CONT
    395  1.14.32.1     mjf  *    code which causes the MD target mode driver to generate CTIOs to
    396  1.14.32.1     mjf  *    satisfy whatever action needs to be taken. When those CTIOs complete,
    397  1.14.32.1     mjf  *    the MD target driver sends the pointer to the cmd_tmd_t back with
    398  1.14.32.1     mjf  *    a QOUT_TMD_DONE code. This repeats for as long as necessary. These
    399  1.14.32.1     mjf  *    may not be done in parallel- they are sequential operations.
    400  1.14.32.1     mjf  *
    401  1.14.32.1     mjf  *    The outer layer signals it wants to end the command by settings within
    402  1.14.32.1     mjf  *    the tmd_cmd_t itself. When the final QIN_TMD_CONT is reported completed,
    403  1.14.32.1     mjf  *    the outer layer frees the tmd_cmd_t by sending the pointer to it
    404  1.14.32.1     mjf  *    back with a QIN_TMD_FIN code.
    405        1.1  mjacob  *
    406  1.14.32.1     mjf  *    The graph looks like:
    407        1.1  mjacob  *
    408  1.14.32.1     mjf  *    QOUT_TMD_START -> [ QIN_TMD_CONT -> QOUT_TMD_DONE ] * -> QIN_TMD_FIN.
    409        1.3      he  *
    410        1.3      he  */
    411        1.3      he 
    412        1.3      he /*
    413       1.10  mjacob  * Target handler functions.
    414       1.10  mjacob  *
    415       1.10  mjacob  * The MD target handler function (the outer layer calls this)
    416       1.10  mjacob  * should be be prototyped like:
    417       1.10  mjacob  *
    418  1.14.32.1     mjf  *    void target_action(qact_e, void *arg)
    419       1.10  mjacob  *
    420       1.10  mjacob  * The outer layer target handler function (the MD layer calls this)
    421       1.10  mjacob  * should be be prototyped like:
    422       1.10  mjacob  *
    423  1.14.32.1     mjf  *    void scsi_target_handler(tact_e, void *arg)
    424  1.14.32.1     mjf  */
    425  1.14.32.1     mjf #endif    /* _ISP_TPUBLIC_H */
    426  1.14.32.1     mjf /*
    427  1.14.32.1     mjf  * vim:ts=4:sw=4:expandtab
    428       1.10  mjacob  */
    429