/*
* Copyright (c) 1995 Leo Weppelman.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Definitions for idstat register
*/
#define SC_S_RST 0x80 /* R - RST is set */
#define SC_S_BSY 0x40 /* R - BSY is set */
#define SC_S_REQ 0x20 /* R - REQ is set */
#define SC_S_MSG 0x10 /* R - MSG is set */
#define SC_S_CD 0x08 /* R - C/D is set */
#define SC_S_IO 0x04 /* R - I/O is set */
#define SC_S_SEL 0x02 /* R - SEL is set */
#define SC_S_PAR 0x01 /* R - Parity bit */
/*
* Definitions for dmastat register
*/
#define SC_END_DMA 0x80 /* R - End of DMA */
#define SC_DMA_REQ 0x40 /* R - DMA request */
#define SC_PAR_ERR 0x20 /* R - Parity error */
#define SC_IRQ_SET 0x10 /* R - IRQ is active */
#define SC_PHS_MTCH 0x08 /* R - Phase Match */
#define SC_BSY_ERR 0x04 /* R - Busy error */
#define SC_ATN_STAT 0x02 /* R - State of ATN line */
#define SC_ACK_STAT 0x01 /* R - State of ACK line */
#define SC_S_SEND 0x00 /* W - Start DMA output */
#define SC_CLINT { /* Clear interrupts */ \
int i = GET_5380_REG(NCR5380_IRCV); \
}
/*
* Definition of SCSI-bus phases. The values are determined by signals
* on the SCSI-bus. DO NOT CHANGE!
* The values must be used to index the pointers in SCSI-PARMS.
*/
#define NR_PHASE 8
#define PH_DATAOUT 0
#define PH_DATAIN 1
#define PH_CMD 2
#define PH_STATUS 3
#define PH_RES1 4
#define PH_RES2 5
#define PH_MSGOUT 6
#define PH_MSGIN 7
/*
* Some (pre-SCSI2) devices don't support select with ATN.
* If the device responds to select with ATN by going into
* command phase (ignoring ATN), then we flag it in the
* following bitmask.
* We also keep track of which devices have been selected
* before. This allows us to not even try raising ATN if
* the target doesn't respond to it the first time.
*/
u_int8_t sc_noselatn;
u_int8_t sc_selected;
};
/*
* Max. number of DMA-chains per request
*/
#define MAXDMAIO (MAXPHYS/PAGE_SIZE + 1)
/*
* Some requests are not contiguous in physical memory. We need to break them
* up into contiguous parts for DMA.
*/
struct dma_chain {
u_int dm_count;
u_long dm_addr;
};
/*
* Define our issue, free and disconnect queue's.
*/
typedef struct req_q {
struct req_q *next; /* next in free, issue or discon queue */
struct req_q *link; /* next linked command to execute */
struct scsipi_xfer *xs; /* request from high-level driver */
u_short dr_flag; /* driver state */
uint8_t phase; /* current SCSI phase */
uint8_t msgout; /* message to send when requested */
uint8_t targ_id; /* target for command */
uint8_t targ_lun; /* lun for command */
uint8_t status; /* returned status byte */
uint8_t message; /* returned message byte */
uint8_t *bounceb; /* allocated bounce buffer */
uint8_t *bouncerp; /* bounce read-pointer */
struct dma_chain dm_chain[MAXDMAIO];
struct dma_chain *dm_cur; /* current DMA-request */
struct dma_chain *dm_last; /* last DMA-request */
long xdata_len; /* length of transfer */
uint8_t *xdata_ptr; /* virtual address of transfer */
struct scsipi_generic xcmd; /* command to execute */
int xcmd_len; /* command length */
} SC_REQ;
/*
* Values for dr_flag:
*/
#define DRIVER_IN_DMA 0x01 /* Non-polled DMA activated */
#define DRIVER_AUTOSEN 0x02 /* Doing automatic sense */
#define DRIVER_NOINT 0x04 /* We are booting: no interrupts */
#define DRIVER_DMAOK 0x08 /* DMA can be used on this request */
#define DRIVER_BOUNCING 0x10 /* Using the bounce buffer */
#define DRIVER_LINKCHK 0x20 /* Doing the linked command check */
static SC_REQ *issue_q = NULL; /* Commands waiting to be issued*/
static SC_REQ *discon_q = NULL; /* Commands disconnected */
static SC_REQ *connected = NULL; /* Command currently connected */