sbicvar.h revision 1.8
11.8Sbouyer/*	$NetBSD: sbicvar.h,v 1.8 2001/04/25 17:53:17 bouyer Exp $	*/
21.3Sthorpej
31.1Schuck/*
41.1Schuck * Copyright (c) 1990 The Regents of the University of California.
51.1Schuck * All rights reserved.
61.1Schuck *
71.1Schuck * This code is derived from software contributed to Berkeley by
81.1Schuck * Van Jacobson of Lawrence Berkeley Laboratory.
91.1Schuck *
101.1Schuck * Redistribution and use in source and binary forms, with or without
111.1Schuck * modification, are permitted provided that the following conditions
121.1Schuck * are met:
131.1Schuck * 1. Redistributions of source code must retain the above copyright
141.1Schuck *    notice, this list of conditions and the following disclaimer.
151.1Schuck * 2. Redistributions in binary form must reproduce the above copyright
161.1Schuck *    notice, this list of conditions and the following disclaimer in the
171.1Schuck *    documentation and/or other materials provided with the distribution.
181.1Schuck * 3. All advertising materials mentioning features or use of this software
191.1Schuck *    must display the following acknowledgement:
201.1Schuck *  This product includes software developed by the University of
211.1Schuck *  California, Berkeley and its contributors.
221.1Schuck * 4. Neither the name of the University nor the names of its contributors
231.1Schuck *    may be used to endorse or promote products derived from this software
241.1Schuck *    without specific prior written permission.
251.1Schuck *
261.1Schuck * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
271.1Schuck * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
281.1Schuck * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
291.1Schuck * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
301.1Schuck * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
311.1Schuck * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
321.1Schuck * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
331.1Schuck * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
341.1Schuck * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
351.1Schuck * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
361.1Schuck * SUCH DAMAGE.
371.1Schuck *
381.1Schuck *  @(#)scsivar.h   7.1 (Berkeley) 5/8/90
391.1Schuck */
401.1Schuck#ifndef _SBICVAR_H_
411.1Schuck#define _SBICVAR_H_
421.7Sthorpej#include <sys/callout.h>
431.1Schuck#include <sys/malloc.h>
441.1Schuck
451.1Schuck
461.1Schuck/*
471.1Schuck * DMA chains are used for Scatter-Gather DMA.
481.1Schuck */
491.1Schuckstruct  dma_chain {
501.1Schuck    int     dc_count;
511.1Schuck    char    *dc_addr;
521.1Schuck};
531.1Schuck
541.1Schuck/*
551.1Schuck * ACB. Holds additional information for each SCSI command Comments: We
561.1Schuck * need a separate scsi command block because we may need to overwrite it
571.1Schuck * with a request sense command.  Basicly, we refrain from fiddling with
581.1Schuck * the scsi_xfer struct (except do the expected updating of return values).
591.1Schuck * We'll generally update: xs->{flags,resid,error,sense,status} and
601.1Schuck * occasionally xs->retries.
611.1Schuck */
621.1Schuckstruct sbic_acb {
631.1Schuck    TAILQ_ENTRY(sbic_acb)   chain;
641.4Sbouyer    struct scsipi_xfer        *xs;        /* SCSI xfer ctrl block from above */
651.1Schuck    int                     flags;      /* Status */
661.1Schuck#define ACB_FREE        0x00
671.1Schuck#define ACB_ACTIVE      0x01
681.1Schuck#define ACB_DONE        0x04
691.1Schuck#define ACB_BBUF        0x10    /* DMA input needs to be copied from bounce */
701.1Schuck#define ACB_DATAIN      0x20    /* DMA direction flag */
711.1Schuck
721.1Schuck    struct  scsi_generic    cmd;        /* SCSI command block */
731.1Schuck    int                     clen;
741.1Schuck    struct  dma_chain       sc_kv;      /* Virtual address of whole DMA */
751.1Schuck    struct  dma_chain       sc_pa;      /* Physical address of DMA segment */
761.1Schuck    u_long                  sc_tcnt;    /* number of bytes for this DMA */
771.1Schuck    u_short                 sc_dmacmd;  /* Internal data for this DMA */
781.1Schuck    char                    *pa_addr;   /* XXXX initial phys addr */
791.1Schuck};
801.1Schuck
811.1Schuck/*
821.1Schuck * Some info about each (possible) target on the SCSI bus.  This should
831.1Schuck * probably have been a "per target+lunit" structure, but we'll leave it at
841.1Schuck * this for now.  Is there a way to reliably hook it up to sc->fordriver??
851.1Schuck */
861.1Schuckstruct sbic_tinfo {
871.1Schuck    int                     cmds;       /* #commands processed */
881.1Schuck    int                     dconns;     /* #disconnects */
891.1Schuck    int                     lubusy;     /* What local units/subr. are busy? */
901.1Schuck} tinfo_t;
911.1Schuck
921.1Schuckstruct  sbic_softc {
931.1Schuck    struct  device          sc_dev;
941.1Schuck    struct  target_sync {
951.1Schuck        u_char  state;
961.1Schuck        u_char  period;
971.1Schuck        u_char  offset;
981.1Schuck    } sc_sync[8];
991.1Schuck    u_char                  target;     /* Currently active target */
1001.1Schuck    u_char                  lun;
1011.8Sbouyer    struct  scsipi_channel  sc_channel;    /* proto for sub devices */
1021.5Sthorpej    struct  scsipi_adapter  sc_adapter;
1031.1Schuck    sbic_regmap_p           sc_sbicp;   /* the SBIC */
1041.6Sscw    void                   *sc_driver;  /* driver specific field */
1051.1Schuck    int                     sc_ipl;
1061.7Sthorpej
1071.7Sthorpej    struct callout	    sc_timo_ch;
1081.1Schuck
1091.1Schuck    /* Lists of command blocks */
1101.1Schuck    TAILQ_HEAD(acb_list, sbic_acb)  free_list,
1111.1Schuck                                    ready_list,
1121.1Schuck                                    nexus_list;
1131.1Schuck
1141.1Schuck    struct sbic_acb         *sc_nexus;  /* current command */
1151.1Schuck    struct sbic_acb         sc_acb[8];  /* the real command blocks */
1161.1Schuck    struct sbic_tinfo       sc_tinfo[8];
1171.1Schuck
1181.4Sbouyer    struct  scsipi_xfer       *sc_xs;     /* transfer from high level code */
1191.1Schuck    u_char                  sc_flags;
1201.1Schuck    u_char                  sc_stat[2];
1211.1Schuck    u_char                  sc_msg[7];
1221.1Schuck    u_long                  sc_clkfreq;
1231.1Schuck    u_long                  sc_tcnt;    /* number of bytes transfered */
1241.1Schuck    u_short                 sc_dmacmd;  /* used by dma drivers */
1251.1Schuck    u_long                  sc_dmamask; /* dma valid mem mask */
1261.1Schuck#ifdef DEBUG
1271.1Schuck    u_short                 sc_dmatimo; /* dma timeout */
1281.1Schuck#endif
1291.1Schuck    struct  dma_chain       *sc_cur;
1301.1Schuck    struct  dma_chain       *sc_last;
1311.1Schuck    int  (*sc_dmago)        __P((struct sbic_softc *, char *, int, int));
1321.1Schuck    int  (*sc_dmanext)      __P((struct sbic_softc *));
1331.1Schuck    void (*sc_enintr)       __P((struct sbic_softc *));
1341.1Schuck    void (*sc_dmastop)      __P((struct sbic_softc *));
1351.1Schuck};
1361.1Schuck
1371.1Schuck/*
1381.1Schuck * sc_flags
1391.1Schuck */
1401.1Schuck#define SBICF_ALIVE         0x01    /* controller initialized */
1411.1Schuck#define SBICF_DCFLUSH       0x02    /* need flush for overlap after dma finishes */
1421.1Schuck#define SBICF_SELECTED      0x04    /* bus is in selected state. */
1431.1Schuck#define SBICF_ICMD          0x08    /* Immediate command in execution */
1441.1Schuck#define SBICF_BADDMA        0x10    /* controller can only DMA to ztwobus space */
1451.1Schuck#define SBICF_INTR          0x40    /* SBICF interrupt expected */
1461.1Schuck#define SBICF_INDMA         0x80    /* not used yet, DMA I/O in progress */
1471.1Schuck
1481.1Schuck/*
1491.1Schuck * sync states
1501.1Schuck */
1511.1Schuck#define SYNC_START          0   /* no sync handshake started */
1521.1Schuck#define SYNC_SENT           1   /* we sent sync request, no answer yet */
1531.1Schuck#define SYNC_DONE           2   /* target accepted our (or inferior) settings,
1541.1Schuck                                   or it rejected the request and we stay async */
1551.1Schuck
1561.1Schuck#define PHASE               0x07    /* mask for psns/pctl phase */
1571.1Schuck#define DATA_OUT_PHASE      0x00
1581.1Schuck#define DATA_IN_PHASE       0x01
1591.1Schuck#define CMD_PHASE           0x02
1601.1Schuck#define STATUS_PHASE        0x03
1611.1Schuck#define BUS_FREE_PHASE      0x04
1621.1Schuck#define ARB_SEL_PHASE       0x05    /* Fuji chip combines arbitration with sel. */
1631.1Schuck#define MESG_OUT_PHASE      0x06
1641.1Schuck#define MESG_IN_PHASE       0x07
1651.1Schuck
1661.1Schuck#define MSG_CMD_COMPLETE    0x00
1671.1Schuck#define MSG_EXT_MESSAGE     0x01
1681.1Schuck#define MSG_SAVE_DATA_PTR   0x02
1691.1Schuck#define MSG_RESTORE_PTR     0x03
1701.1Schuck#define MSG_DISCONNECT      0x04
1711.1Schuck#define MSG_INIT_DETECT_ERROR   0x05
1721.1Schuck#define MSG_ABORT           0x06
1731.1Schuck#define MSG_REJECT          0x07
1741.1Schuck#define MSG_NOOP            0x08
1751.1Schuck#define MSG_PARITY_ERROR    0x09
1761.1Schuck#define MSG_BUS_DEVICE_RESET    0x0C
1771.1Schuck#define MSG_IDENTIFY        0x80
1781.1Schuck#define MSG_IDENTIFY_DR     0xc0    /* (disconnect/reconnect allowed) */
1791.1Schuck#define MSG_SYNC_REQ        0x01
1801.1Schuck
1811.1Schuck#define MSG_ISIDENTIFY(x)   ((x) & MSG_IDENTIFY)
1821.1Schuck
1831.1Schuck
1841.1Schuck#define STS_CHECKCOND       0x02    /* Check Condition (ie., read sense) */
1851.1Schuck#define STS_CONDMET         0x04    /* Condition Met (ie., search worked) */
1861.1Schuck#define STS_BUSY            0x08
1871.1Schuck#define STS_INTERMED        0x10    /* Intermediate status sent */
1881.1Schuck#define STS_EXT             0x80    /* Extended status valid */
1891.1Schuck
1901.1Schuck
1911.1Schuck/*
1921.1Schuck * States returned by our state machine
1931.1Schuck */
1941.1Schuck
1951.1Schuck#define SBIC_STATE_ERROR    -1
1961.1Schuck#define SBIC_STATE_DONE     0
1971.1Schuck#define SBIC_STATE_RUNNING  1
1981.1Schuck#define SBIC_STATE_DISCONNECT   2
1991.1Schuck
2001.1Schuck
2011.1Schuckstruct buf;
2021.4Sbouyerstruct scsipi_xfer;
2031.1Schuck
2041.1Schuckvoid sbic_minphys __P((struct buf *bp));
2051.8Sbouyervoid sbic_scsi_request __P((struct scsipi_channel *,
2061.8Sbouyer				scsipi_adapter_req_t, void *));
2071.6Sscwvoid sbicinit __P((struct sbic_softc *));
2081.6Sscwint sbicintr __P((struct sbic_softc *));
2091.1Schuck
2101.1Schuck#endif /* _SBICVAR_H_ */
211