1996-03-09 01:03:26 +03:00
|
|
|
/* $NetBSD: aha1742.c,v 1.57 1996/03/08 22:03:26 cgd Exp $ */
|
1994-10-27 07:14:23 +03:00
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
/*
|
1994-03-29 08:30:15 +04:00
|
|
|
* Copyright (c) 1994 Charles Hannum. 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Charles Hannum.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Originally written by Julian Elischer (julian@tfs.com)
|
1993-03-21 21:04:42 +03:00
|
|
|
* for TRW Financial Systems for use under the MACH(2.5) operating system.
|
|
|
|
*
|
|
|
|
* TRW Financial Systems, in accordance with their agreement with Carnegie
|
|
|
|
* Mellon University, makes this software available to CMU to distribute
|
|
|
|
* or use in any manner that they see fit as long as this message is kept with
|
|
|
|
* the software. For this reason TFS also grants any other persons or
|
|
|
|
* organisations permission to use or modify this software.
|
|
|
|
*
|
|
|
|
* TFS supplies this software to be publicly redistributed
|
|
|
|
* on the understanding that TFS is not responsible for the correct
|
|
|
|
* functioning of this software in any circumstances.
|
1993-05-22 11:56:12 +04:00
|
|
|
*
|
1994-03-29 08:30:15 +04:00
|
|
|
* commenced: Sun Sep 27 18:14:01 PDT 1992
|
1993-03-21 21:04:42 +03:00
|
|
|
*/
|
|
|
|
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1994-03-29 08:30:15 +04:00
|
|
|
#include <sys/kernel.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
1994-03-29 08:30:15 +04:00
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/user.h>
|
|
|
|
|
1996-03-09 01:03:26 +03:00
|
|
|
#include <machine/bus.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
|
1995-04-17 16:06:30 +04:00
|
|
|
#include <dev/eisa/eisareg.h>
|
|
|
|
#include <dev/eisa/eisavar.h>
|
1996-02-27 03:20:54 +03:00
|
|
|
#include <dev/eisa/eisadevs.h>
|
1995-04-17 16:06:30 +04:00
|
|
|
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <scsi/scsi_all.h>
|
|
|
|
#include <scsi/scsiconf.h>
|
|
|
|
|
1995-09-26 22:31:15 +03:00
|
|
|
#ifndef DDB
|
1994-12-28 22:42:47 +03:00
|
|
|
#define Debugger() panic("should call debugger here (aha1742.c)")
|
1995-09-26 22:31:15 +03:00
|
|
|
#endif /* ! DDB */
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
typedef u_long physaddr;
|
1994-12-28 22:42:47 +03:00
|
|
|
typedef u_long physlen;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
#define KVTOPHYS(x) vtophys(x)
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
#define AHB_ECB_MAX 32 /* store up to 32 ECBs at one time */
|
|
|
|
#define ECB_HASH_SIZE 32 /* hash table size for phystokv */
|
|
|
|
#define ECB_HASH_SHIFT 9
|
|
|
|
#define ECB_HASH(x) ((((long)(x))>>ECB_HASH_SHIFT) & (ECB_HASH_SIZE - 1))
|
1993-04-12 12:17:23 +04:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
#define AHB_NSEG 33 /* number of dma segments supported */
|
1993-04-12 12:17:23 +04:00
|
|
|
|
|
|
|
/*
|
1994-07-28 06:39:21 +04:00
|
|
|
* EISA registers (offset from slot base)
|
1993-04-12 12:17:23 +04:00
|
|
|
*/
|
1994-07-28 06:39:21 +04:00
|
|
|
#define EISA_VENDOR 0x0c80 /* vendor ID (2 ports) */
|
|
|
|
#define EISA_MODEL 0x0c82 /* model number (2 ports) */
|
|
|
|
#define EISA_CONTROL 0x0c84
|
|
|
|
#define EISA_RESET 0x04
|
|
|
|
#define EISA_ERROR 0x02
|
|
|
|
#define EISA_ENABLE 0x01
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
|
|
|
* AHA1740 EISA board mode registers (Offset from slot base)
|
|
|
|
*/
|
1993-03-21 21:04:42 +03:00
|
|
|
#define PORTADDR 0xCC0
|
|
|
|
#define PORTADDR_ENHANCED 0x80
|
|
|
|
#define BIOSADDR 0xCC1
|
|
|
|
#define INTDEF 0xCC2
|
|
|
|
#define SCSIDEF 0xCC3
|
|
|
|
#define BUSDEF 0xCC4
|
|
|
|
#define RESV0 0xCC5
|
|
|
|
#define RESV1 0xCC6
|
|
|
|
#define RESV2 0xCC7
|
1994-03-29 08:30:15 +04:00
|
|
|
/**** bit definitions for INTDEF ****/
|
1993-03-21 21:04:42 +03:00
|
|
|
#define INT9 0x00
|
|
|
|
#define INT10 0x01
|
|
|
|
#define INT11 0x02
|
|
|
|
#define INT12 0x03
|
|
|
|
#define INT14 0x05
|
|
|
|
#define INT15 0x06
|
1994-03-29 08:30:15 +04:00
|
|
|
#define INTHIGH 0x08 /* int high=ACTIVE (else edge) */
|
1993-03-21 21:04:42 +03:00
|
|
|
#define INTEN 0x10
|
1994-03-29 08:30:15 +04:00
|
|
|
/**** bit definitions for SCSIDEF ****/
|
|
|
|
#define HSCSIID 0x0F /* our SCSI ID */
|
|
|
|
#define RSTPWR 0x10 /* reset scsi bus on power up or reset */
|
|
|
|
/**** bit definitions for BUSDEF ****/
|
|
|
|
#define B0uS 0x00 /* give up bus immediatly */
|
|
|
|
#define B4uS 0x01 /* delay 4uSec. */
|
1993-03-21 21:04:42 +03:00
|
|
|
#define B8uS 0x02
|
1993-04-12 12:17:23 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* AHA1740 ENHANCED mode mailbox control regs (Offset from slot base)
|
|
|
|
*/
|
1993-03-21 21:04:42 +03:00
|
|
|
#define MBOXOUT0 0xCD0
|
|
|
|
#define MBOXOUT1 0xCD1
|
|
|
|
#define MBOXOUT2 0xCD2
|
|
|
|
#define MBOXOUT3 0xCD3
|
|
|
|
|
|
|
|
#define ATTN 0xCD4
|
|
|
|
#define G2CNTRL 0xCD5
|
|
|
|
#define G2INTST 0xCD6
|
|
|
|
#define G2STAT 0xCD7
|
|
|
|
|
|
|
|
#define MBOXIN0 0xCD8
|
|
|
|
#define MBOXIN1 0xCD9
|
|
|
|
#define MBOXIN2 0xCDA
|
|
|
|
#define MBOXIN3 0xCDB
|
|
|
|
|
|
|
|
#define G2STAT2 0xCDC
|
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
|
|
|
* Bit definitions for the 5 control/status registers
|
|
|
|
*/
|
1993-03-21 21:04:42 +03:00
|
|
|
#define ATTN_TARGET 0x0F
|
|
|
|
#define ATTN_OPCODE 0xF0
|
|
|
|
#define OP_IMMED 0x10
|
|
|
|
#define AHB_TARG_RESET 0x80
|
|
|
|
#define OP_START_ECB 0x40
|
|
|
|
#define OP_ABORT_ECB 0x50
|
|
|
|
|
|
|
|
#define G2CNTRL_SET_HOST_READY 0x20
|
|
|
|
#define G2CNTRL_CLEAR_EISA_INT 0x40
|
|
|
|
#define G2CNTRL_HARD_RESET 0x80
|
|
|
|
|
|
|
|
#define G2INTST_TARGET 0x0F
|
|
|
|
#define G2INTST_INT_STAT 0xF0
|
|
|
|
#define AHB_ECB_OK 0x10
|
|
|
|
#define AHB_ECB_RECOVERED 0x50
|
|
|
|
#define AHB_HW_ERR 0x70
|
|
|
|
#define AHB_IMMED_OK 0xA0
|
|
|
|
#define AHB_ECB_ERR 0xC0
|
|
|
|
#define AHB_ASN 0xD0 /* for target mode */
|
|
|
|
#define AHB_IMMED_ERR 0xE0
|
|
|
|
|
|
|
|
#define G2STAT_BUSY 0x01
|
|
|
|
#define G2STAT_INT_PEND 0x02
|
|
|
|
#define G2STAT_MBOX_EMPTY 0x04
|
|
|
|
|
|
|
|
#define G2STAT2_HOST_READY 0x01
|
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
struct ahb_dma_seg {
|
1994-12-28 22:42:47 +03:00
|
|
|
physaddr seg_addr;
|
|
|
|
physlen seg_len;
|
1993-03-21 21:04:42 +03:00
|
|
|
};
|
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
struct ahb_ecb_status {
|
1994-03-29 08:30:15 +04:00
|
|
|
u_short status;
|
|
|
|
#define ST_DON 0x0001
|
|
|
|
#define ST_DU 0x0002
|
|
|
|
#define ST_QF 0x0008
|
|
|
|
#define ST_SC 0x0010
|
|
|
|
#define ST_DO 0x0020
|
|
|
|
#define ST_CH 0x0040
|
|
|
|
#define ST_INT 0x0080
|
|
|
|
#define ST_ASA 0x0100
|
|
|
|
#define ST_SNS 0x0200
|
|
|
|
#define ST_INI 0x0800
|
|
|
|
#define ST_ME 0x1000
|
|
|
|
#define ST_ECA 0x4000
|
1994-12-28 22:42:47 +03:00
|
|
|
u_char host_stat;
|
1994-03-29 08:30:15 +04:00
|
|
|
#define HS_OK 0x00
|
|
|
|
#define HS_CMD_ABORTED_HOST 0x04
|
|
|
|
#define HS_CMD_ABORTED_ADAPTER 0x05
|
|
|
|
#define HS_TIMED_OUT 0x11
|
|
|
|
#define HS_HARDWARE_ERR 0x20
|
|
|
|
#define HS_SCSI_RESET_ADAPTER 0x22
|
|
|
|
#define HS_SCSI_RESET_INCOMING 0x23
|
1994-12-28 22:42:47 +03:00
|
|
|
u_char target_stat;
|
1994-03-29 08:30:15 +04:00
|
|
|
u_long resid_count;
|
|
|
|
u_long resid_addr;
|
|
|
|
u_short addit_status;
|
|
|
|
u_char sense_len;
|
|
|
|
u_char unused[9];
|
|
|
|
u_char cdb[6];
|
1993-03-21 21:04:42 +03:00
|
|
|
};
|
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ahb_ecb {
|
1994-03-29 08:30:15 +04:00
|
|
|
u_char opcode;
|
|
|
|
#define ECB_SCSI_OP 0x01
|
|
|
|
u_char:4;
|
|
|
|
u_char options:3;
|
|
|
|
u_char:1;
|
|
|
|
short opt1;
|
|
|
|
#define ECB_CNE 0x0001
|
|
|
|
#define ECB_DI 0x0080
|
|
|
|
#define ECB_SES 0x0400
|
|
|
|
#define ECB_S_G 0x1000
|
|
|
|
#define ECB_DSB 0x4000
|
|
|
|
#define ECB_ARS 0x8000
|
|
|
|
short opt2;
|
|
|
|
#define ECB_LUN 0x0007
|
|
|
|
#define ECB_TAG 0x0008
|
|
|
|
#define ECB_TT 0x0030
|
|
|
|
#define ECB_ND 0x0040
|
|
|
|
#define ECB_DAT 0x0100
|
|
|
|
#define ECB_DIR 0x0200
|
|
|
|
#define ECB_ST 0x0400
|
|
|
|
#define ECB_CHK 0x0800
|
|
|
|
#define ECB_REC 0x4000
|
|
|
|
#define ECB_NRB 0x8000
|
|
|
|
u_short unused1;
|
1994-12-28 22:42:47 +03:00
|
|
|
physaddr data_addr;
|
|
|
|
physlen data_length;
|
1994-03-29 08:30:15 +04:00
|
|
|
physaddr status;
|
1994-12-28 22:42:47 +03:00
|
|
|
physaddr link_addr;
|
1994-03-29 08:30:15 +04:00
|
|
|
short unused2;
|
|
|
|
short unused3;
|
1994-12-28 22:42:47 +03:00
|
|
|
physaddr sense_ptr;
|
|
|
|
u_char req_sense_length;
|
|
|
|
u_char scsi_cmd_length;
|
1994-03-29 08:30:15 +04:00
|
|
|
short cksum;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct scsi_generic scsi_cmd;
|
1993-03-21 21:04:42 +03:00
|
|
|
/*-----------------end of hardware supported fields----------------*/
|
1994-12-28 22:42:47 +03:00
|
|
|
TAILQ_ENTRY(ahb_ecb) chain;
|
|
|
|
struct ahb_ecb *nexthash;
|
|
|
|
long hashkey;
|
1994-03-29 08:30:15 +04:00
|
|
|
struct scsi_xfer *xs; /* the scsi_xfer for this cmd */
|
1994-12-28 22:42:47 +03:00
|
|
|
int flags;
|
1993-03-21 21:04:42 +03:00
|
|
|
#define ECB_FREE 0
|
|
|
|
#define ECB_ACTIVE 1
|
|
|
|
#define ECB_ABORTED 2
|
|
|
|
#define ECB_IMMED 4
|
|
|
|
#define ECB_IMMED_FAIL 8
|
1994-03-29 08:30:15 +04:00
|
|
|
struct ahb_dma_seg ahb_dma[AHB_NSEG];
|
|
|
|
struct ahb_ecb_status ecb_status;
|
|
|
|
struct scsi_sense_data ecb_sense;
|
1993-03-21 21:04:42 +03:00
|
|
|
};
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
struct ahb_softc {
|
|
|
|
struct device sc_dev;
|
|
|
|
struct isadev sc_id;
|
1995-04-17 16:06:30 +04:00
|
|
|
void *sc_ih;
|
1996-03-09 01:03:26 +03:00
|
|
|
bus_chipset_tag_t sc_bc;
|
|
|
|
bus_io_handle_t sc_ioh;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
int sc_irq;
|
|
|
|
|
|
|
|
struct ahb_ecb *immed_ecb; /* an outstanding immediete command */
|
|
|
|
struct ahb_ecb *ecbhash[ECB_HASH_SIZE];
|
|
|
|
TAILQ_HEAD(, ahb_ecb) free_ecb;
|
1994-03-29 08:30:15 +04:00
|
|
|
int numecbs;
|
1994-07-27 17:14:14 +04:00
|
|
|
int ahb_scsi_dev; /* our scsi id */
|
1994-12-28 22:42:47 +03:00
|
|
|
struct scsi_link sc_link;
|
1994-03-29 08:30:15 +04:00
|
|
|
};
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
void ahb_send_mbox __P((struct ahb_softc *, int, struct ahb_ecb *));
|
|
|
|
int ahb_poll __P((struct ahb_softc *, struct scsi_xfer *, int));
|
1994-03-29 08:30:15 +04:00
|
|
|
void ahb_send_immed __P((struct ahb_softc *, int, u_long));
|
1995-04-17 16:06:30 +04:00
|
|
|
int ahbintr __P((void *));
|
1994-12-28 22:42:47 +03:00
|
|
|
void ahb_done __P((struct ahb_softc *, struct ahb_ecb *));
|
|
|
|
void ahb_free_ecb __P((struct ahb_softc *, struct ahb_ecb *, int));
|
|
|
|
struct ahb_ecb *ahb_get_ecb __P((struct ahb_softc *, int));
|
|
|
|
struct ahb_ecb *ahb_ecb_phys_kv __P((struct ahb_softc *, physaddr));
|
1996-03-09 01:03:26 +03:00
|
|
|
int ahb_find __P((bus_chipset_tag_t, bus_io_handle_t, struct ahb_softc *));
|
1994-03-29 08:30:15 +04:00
|
|
|
void ahb_init __P((struct ahb_softc *));
|
1995-08-13 00:30:45 +04:00
|
|
|
void ahbminphys __P((struct buf *));
|
1994-03-29 08:30:15 +04:00
|
|
|
int ahb_scsi_cmd __P((struct scsi_xfer *));
|
1994-05-05 09:35:42 +04:00
|
|
|
void ahb_timeout __P((void *));
|
1994-12-28 22:42:47 +03:00
|
|
|
void ahb_print_ecb __P((struct ahb_ecb *));
|
1994-03-29 08:30:15 +04:00
|
|
|
void ahb_print_active_ecb __P((struct ahb_softc *));
|
|
|
|
|
|
|
|
#define MAX_SLOTS 15
|
|
|
|
static ahb_slot = 0; /* slot last board was found in */
|
|
|
|
int ahb_debug = 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
#define AHB_SHOWECBS 0x01
|
|
|
|
#define AHB_SHOWINTS 0x02
|
|
|
|
#define AHB_SHOWCMDS 0x04
|
|
|
|
#define AHB_SHOWMISC 0x08
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
struct scsi_adapter ahb_switch = {
|
|
|
|
ahb_scsi_cmd,
|
|
|
|
ahbminphys,
|
|
|
|
0,
|
|
|
|
0,
|
1993-04-12 12:17:23 +04:00
|
|
|
};
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/* the below structure is so we have a default dev struct for our link struct */
|
|
|
|
struct scsi_device ahb_dev = {
|
|
|
|
NULL, /* Use default error handler */
|
|
|
|
NULL, /* have a queue, served by this */
|
|
|
|
NULL, /* have no async handler */
|
|
|
|
NULL, /* Use default 'done' routine */
|
|
|
|
};
|
|
|
|
|
1996-02-28 23:29:48 +03:00
|
|
|
int ahbmatch __P((struct device *, void *, void *));
|
|
|
|
void ahbattach __P((struct device *, struct device *, void *));
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
struct cfdriver ahbcd = {
|
1996-02-27 03:20:54 +03:00
|
|
|
NULL, "ahb", ahbmatch, ahbattach, DV_DULL, sizeof(struct ahb_softc)
|
1994-03-29 08:30:15 +04:00
|
|
|
};
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
|
|
|
* Function to send a command out through a mailbox
|
|
|
|
*/
|
|
|
|
void
|
1994-12-28 22:42:47 +03:00
|
|
|
ahb_send_mbox(ahb, opcode, ecb)
|
1994-03-29 08:30:15 +04:00
|
|
|
struct ahb_softc *ahb;
|
1994-12-28 22:42:47 +03:00
|
|
|
int opcode;
|
|
|
|
struct ahb_ecb *ecb;
|
1993-04-12 12:17:23 +04:00
|
|
|
{
|
1996-03-09 01:03:26 +03:00
|
|
|
bus_chipset_tag_t bc = ahb->sc_bc;
|
|
|
|
bus_io_handle_t ioh = ahb->sc_ioh;
|
1994-04-05 12:53:00 +04:00
|
|
|
int wait = 300; /* 1ms should be enough */
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
while (--wait) {
|
1996-03-09 01:03:26 +03:00
|
|
|
if ((bus_io_read_1(bc, ioh, G2STAT) & (G2STAT_BUSY | G2STAT_MBOX_EMPTY))
|
1994-03-29 08:30:15 +04:00
|
|
|
== (G2STAT_MBOX_EMPTY))
|
|
|
|
break;
|
|
|
|
delay(10);
|
|
|
|
}
|
|
|
|
if (!wait) {
|
|
|
|
printf("%s: board not responding\n", ahb->sc_dev.dv_xname);
|
1993-03-21 21:04:42 +03:00
|
|
|
Debugger();
|
|
|
|
}
|
|
|
|
|
1996-03-09 01:03:26 +03:00
|
|
|
bus_io_write_4(bc, ioh, MBOXOUT0, KVTOPHYS(ecb)); /* don't know this will work */
|
|
|
|
bus_io_write_1(bc, ioh, ATTN, opcode | ecb->xs->sc_link->target);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
|
|
|
* Function to poll for command completion when in poll mode
|
|
|
|
*/
|
|
|
|
int
|
1994-12-28 22:42:47 +03:00
|
|
|
ahb_poll(ahb, xs, count)
|
1994-03-29 08:30:15 +04:00
|
|
|
struct ahb_softc *ahb;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct scsi_xfer *xs;
|
|
|
|
int count;
|
1994-03-29 08:30:15 +04:00
|
|
|
{ /* in msec */
|
1996-03-09 01:03:26 +03:00
|
|
|
bus_chipset_tag_t bc = ahb->sc_bc;
|
|
|
|
bus_io_handle_t ioh = ahb->sc_ioh;
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
while (count) {
|
|
|
|
/*
|
|
|
|
* If we had interrupts enabled, would we
|
|
|
|
* have got an interrupt?
|
|
|
|
*/
|
1996-03-09 01:03:26 +03:00
|
|
|
if (bus_io_read_1(bc, ioh, G2STAT) & G2STAT_INT_PEND)
|
1994-12-28 22:42:47 +03:00
|
|
|
ahbintr(ahb);
|
|
|
|
if (xs->flags & ITSDONE)
|
|
|
|
return 0;
|
1994-03-29 08:30:15 +04:00
|
|
|
delay(1000);
|
1994-12-28 22:42:47 +03:00
|
|
|
count--;
|
1994-03-29 08:30:15 +04:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
return 1;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
|
|
|
* Function to send an immediate type command to the adapter
|
|
|
|
*/
|
|
|
|
void
|
1994-03-29 08:30:15 +04:00
|
|
|
ahb_send_immed(ahb, target, cmd)
|
|
|
|
struct ahb_softc *ahb;
|
|
|
|
int target;
|
|
|
|
u_long cmd;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1996-03-09 01:03:26 +03:00
|
|
|
bus_chipset_tag_t bc = ahb->sc_bc;
|
|
|
|
bus_io_handle_t ioh = ahb->sc_ioh;
|
1994-03-29 08:30:15 +04:00
|
|
|
int wait = 100; /* 1 ms enough? */
|
|
|
|
|
|
|
|
while (--wait) {
|
1996-03-09 01:03:26 +03:00
|
|
|
if ((bus_io_read_1(bc, ioh, G2STAT) & (G2STAT_BUSY | G2STAT_MBOX_EMPTY))
|
1994-03-29 08:30:15 +04:00
|
|
|
== (G2STAT_MBOX_EMPTY))
|
|
|
|
break;
|
|
|
|
delay(10);
|
|
|
|
}
|
|
|
|
if (!wait) {
|
|
|
|
printf("%s: board not responding\n", ahb->sc_dev.dv_xname);
|
1993-03-21 21:04:42 +03:00
|
|
|
Debugger();
|
|
|
|
}
|
|
|
|
|
1996-03-09 01:03:26 +03:00
|
|
|
bus_io_write_4(bc, ioh, MBOXOUT0, cmd); /* don't know this will work */
|
|
|
|
bus_io_write_1(bc, ioh, G2CNTRL, G2CNTRL_SET_HOST_READY);
|
|
|
|
bus_io_write_1(bc, ioh, ATTN, OP_IMMED | target);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
1994-03-29 08:30:15 +04:00
|
|
|
* Check the slots looking for a board we recognise
|
1993-04-12 12:17:23 +04:00
|
|
|
* If we find one, note it's address (slot) and call
|
|
|
|
* the actual probe routine to check it out.
|
|
|
|
*/
|
|
|
|
int
|
1996-02-28 23:29:48 +03:00
|
|
|
ahbmatch(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
void *match, *aux;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1996-02-27 03:31:30 +03:00
|
|
|
struct eisa_attach_args *ea = aux;
|
1996-03-09 01:03:26 +03:00
|
|
|
bus_chipset_tag_t bc = ea->ea_bc;
|
|
|
|
bus_io_handle_t ioh;
|
|
|
|
int rv;
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1996-02-27 03:20:54 +03:00
|
|
|
/* must match one of our known ID strings */
|
1996-02-27 03:31:30 +03:00
|
|
|
if (strcmp(ea->ea_idstring, "ADP0000") &&
|
|
|
|
strcmp(ea->ea_idstring, "ADP0001") &&
|
|
|
|
strcmp(ea->ea_idstring, "ADP0002") &&
|
|
|
|
strcmp(ea->ea_idstring, "ADP0400"))
|
1996-02-27 03:20:54 +03:00
|
|
|
return (0);
|
1994-07-28 06:39:21 +04:00
|
|
|
|
1996-03-09 01:03:26 +03:00
|
|
|
if (bus_io_map(bc, EISA_SLOT_ADDR(ea->ea_slot), EISA_SLOT_SIZE, &ioh))
|
|
|
|
return (0);
|
|
|
|
|
1994-08-23 01:53:23 +04:00
|
|
|
#ifdef notyet
|
1996-02-27 03:20:54 +03:00
|
|
|
/* This won't compile as-is, anyway. */
|
1996-03-09 01:03:26 +03:00
|
|
|
bus_io_write_1(bc, ioh, EISA_CONTROL, EISA_ENABLE | EISA_RESET);
|
1996-02-27 03:20:54 +03:00
|
|
|
delay(10);
|
1996-03-09 01:03:26 +03:00
|
|
|
bus_io_write_1(bc, ioh, EISA_CONTROL, EISA_ENABLE);
|
1996-02-27 03:20:54 +03:00
|
|
|
/* Wait for reset? */
|
|
|
|
delay(1000);
|
1994-08-23 01:53:23 +04:00
|
|
|
#endif
|
1994-07-28 06:39:21 +04:00
|
|
|
|
1996-03-09 01:03:26 +03:00
|
|
|
rv = !ahb_find(bc, ioh, NULL);
|
1993-04-12 12:17:23 +04:00
|
|
|
|
1996-03-09 01:03:26 +03:00
|
|
|
bus_io_unmap(ea->ea_bc, ioh, EISA_SLOT_SIZE);
|
|
|
|
|
|
|
|
return (rv);
|
1994-03-29 08:30:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ahbprint()
|
|
|
|
{
|
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
|
|
|
* Attach all the sub-devices we can find
|
|
|
|
*/
|
1994-03-29 08:30:15 +04:00
|
|
|
void
|
|
|
|
ahbattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1996-02-27 03:31:30 +03:00
|
|
|
struct eisa_attach_args *ea = aux;
|
1994-03-29 08:30:15 +04:00
|
|
|
struct ahb_softc *ahb = (void *)self;
|
1996-03-09 01:03:26 +03:00
|
|
|
bus_chipset_tag_t bc = ea->ea_bc;
|
|
|
|
bus_io_handle_t ioh;
|
1996-02-27 03:20:54 +03:00
|
|
|
char *model;
|
|
|
|
|
1996-03-09 01:03:26 +03:00
|
|
|
ahb->sc_bc = bc;
|
|
|
|
if (bus_io_map(bc, EISA_SLOT_ADDR(ea->ea_slot), EISA_SLOT_SIZE, &ioh))
|
|
|
|
panic("ahbattach: could not map I/O addresses");
|
|
|
|
ahb->sc_ioh = ioh;
|
|
|
|
if (ahb_find(bc, ioh, ahb))
|
1996-02-27 03:20:54 +03:00
|
|
|
panic("ahbattach: ahb_find failed!");
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
ahb_init(ahb);
|
1994-12-28 22:42:47 +03:00
|
|
|
TAILQ_INIT(&ahb->free_ecb);
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* fill in the prototype scsi_link.
|
|
|
|
*/
|
|
|
|
ahb->sc_link.adapter_softc = ahb;
|
1994-12-28 22:42:47 +03:00
|
|
|
ahb->sc_link.adapter_target = ahb->ahb_scsi_dev;
|
1994-03-29 08:30:15 +04:00
|
|
|
ahb->sc_link.adapter = &ahb_switch;
|
|
|
|
ahb->sc_link.device = &ahb_dev;
|
1994-12-28 22:42:47 +03:00
|
|
|
ahb->sc_link.openings = 2;
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1996-02-27 03:31:30 +03:00
|
|
|
if (!strcmp(ea->ea_idstring, "ADP0000"))
|
1996-02-27 03:20:54 +03:00
|
|
|
model = EISA_PRODUCT_ADP0000;
|
1996-02-27 03:31:30 +03:00
|
|
|
else if (!strcmp(ea->ea_idstring, "ADP0001"))
|
1996-02-27 03:20:54 +03:00
|
|
|
model = EISA_PRODUCT_ADP0001;
|
1996-02-27 03:31:30 +03:00
|
|
|
else if (!strcmp(ea->ea_idstring, "ADP0002"))
|
1996-02-27 03:20:54 +03:00
|
|
|
model = EISA_PRODUCT_ADP0002;
|
1996-02-27 03:31:30 +03:00
|
|
|
else if (!strcmp(ea->ea_idstring, "ADP0400"))
|
1996-02-27 03:20:54 +03:00
|
|
|
model = EISA_PRODUCT_ADP0400;
|
|
|
|
else
|
|
|
|
model = "unknown model!";
|
|
|
|
printf(" irq %d: %s\n", ahb->sc_irq, model);
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
#ifdef NEWCONFIG
|
|
|
|
isa_establish(&ahb->sc_id, &ahb->sc_dev);
|
1994-04-07 10:48:19 +04:00
|
|
|
#endif
|
1996-02-27 03:20:54 +03:00
|
|
|
ahb->sc_ih = eisa_intr_establish(ahb->sc_irq, IST_LEVEL, IPL_BIO,
|
1995-12-24 05:29:35 +03:00
|
|
|
ahbintr, ahb);
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ask the adapter what subunits are present
|
|
|
|
*/
|
|
|
|
config_found(self, &ahb->sc_link, ahbprint);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
|
|
|
* Catch an interrupt from the adaptor
|
|
|
|
*/
|
|
|
|
int
|
1995-04-17 16:06:30 +04:00
|
|
|
ahbintr(arg)
|
|
|
|
void *arg;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1995-04-17 16:06:30 +04:00
|
|
|
struct ahb_softc *ahb = arg;
|
1996-03-09 01:03:26 +03:00
|
|
|
bus_chipset_tag_t bc = ahb->sc_bc;
|
|
|
|
bus_io_handle_t ioh = ahb->sc_ioh;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ahb_ecb *ecb;
|
|
|
|
u_char ahbstat;
|
1994-03-29 08:30:15 +04:00
|
|
|
u_long mboxval;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
#ifdef AHBDEBUG
|
1994-12-28 22:42:47 +03:00
|
|
|
printf("%s: ahbintr ", ahb->sc_dev.dv_xname);
|
|
|
|
#endif /* AHBDEBUG */
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1996-03-09 01:03:26 +03:00
|
|
|
if ((bus_io_read_1(bc, ioh, G2STAT) & G2STAT_INT_PEND) == 0)
|
1994-04-08 22:22:15 +04:00
|
|
|
return 0;
|
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
for (;;) {
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* First get all the information and then
|
1993-04-12 12:17:23 +04:00
|
|
|
* acknowlege the interrupt
|
|
|
|
*/
|
1996-03-09 01:03:26 +03:00
|
|
|
ahbstat = bus_io_read_1(bc, ioh, G2INTST);
|
|
|
|
mboxval = bus_io_read_4(bc, ioh, MBOXIN0);
|
|
|
|
bus_io_write_1(bc, ioh, G2CNTRL, G2CNTRL_CLEAR_EISA_INT);
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
#ifdef AHBDEBUG
|
|
|
|
printf("status = 0x%x ", ahbstat);
|
|
|
|
#endif /*AHBDEBUG */
|
1993-04-12 12:17:23 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the completed operation
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
switch (ahbstat & G2INTST_INT_STAT) {
|
|
|
|
case AHB_ECB_OK:
|
|
|
|
case AHB_ECB_RECOVERED:
|
|
|
|
case AHB_ECB_ERR:
|
1994-03-29 08:30:15 +04:00
|
|
|
ecb = ahb_ecb_phys_kv(ahb, mboxval);
|
1994-12-28 22:42:47 +03:00
|
|
|
if (!ecb) {
|
|
|
|
printf("%s: BAD ECB RETURNED!\n",
|
|
|
|
ahb->sc_dev.dv_xname);
|
|
|
|
continue; /* whatever it was, it'll timeout */
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AHB_IMMED_ERR:
|
|
|
|
ecb->flags |= ECB_IMMED_FAIL;
|
|
|
|
case AHB_IMMED_OK:
|
|
|
|
ecb = ahb->immed_ecb;
|
|
|
|
ahb->immed_ecb = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("%s: unexpected interrupt %x\n",
|
|
|
|
ahb->sc_dev.dv_xname, ahbstat);
|
|
|
|
ecb = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ecb) {
|
1994-03-29 08:30:15 +04:00
|
|
|
#ifdef AHBDEBUG
|
|
|
|
if (ahb_debug & AHB_SHOWCMDS)
|
|
|
|
show_scsi_cmd(ecb->xs);
|
|
|
|
if ((ahb_debug & AHB_SHOWECBS) && ecb)
|
|
|
|
printf("<int ecb(%x)>", ecb);
|
|
|
|
#endif /*AHBDEBUG */
|
1994-05-05 11:41:44 +04:00
|
|
|
untimeout(ahb_timeout, ecb);
|
1994-12-28 22:42:47 +03:00
|
|
|
ahb_done(ahb, ecb);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
|
1996-03-09 01:03:26 +03:00
|
|
|
if ((bus_io_read_1(bc, ioh, G2STAT) & G2STAT_INT_PEND) == 0)
|
1994-12-28 22:42:47 +03:00
|
|
|
return 1;
|
|
|
|
}
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
1994-03-29 08:30:15 +04:00
|
|
|
* We have a ecb which has been processed by the adaptor, now we look to see
|
|
|
|
* how the operation went.
|
1993-04-12 12:17:23 +04:00
|
|
|
*/
|
|
|
|
void
|
1994-12-28 22:42:47 +03:00
|
|
|
ahb_done(ahb, ecb)
|
1994-03-29 08:30:15 +04:00
|
|
|
struct ahb_softc *ahb;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ahb_ecb *ecb;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:30:15 +04:00
|
|
|
struct ahb_ecb_status *stat = &ecb->ecb_status;
|
|
|
|
struct scsi_sense_data *s1, *s2;
|
1993-04-12 12:17:23 +04:00
|
|
|
struct scsi_xfer *xs = ecb->xs;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
SC_DEBUG(xs->sc_link, SDEV_DB2, ("ahb_done\n"));
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
|
|
|
* Otherwise, put the results of the operation
|
|
|
|
* into the xfer and call whoever started it
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
if ((xs->flags & INUSE) == 0) {
|
|
|
|
printf("%s: exiting but not in use!\n", ahb->sc_dev.dv_xname);
|
|
|
|
Debugger();
|
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
if (ecb->flags & ECB_IMMED) {
|
|
|
|
if (ecb->flags & ECB_IMMED_FAIL)
|
1993-03-21 21:04:42 +03:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
goto done;
|
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
if (xs->error == XS_NOERROR) {
|
|
|
|
if (stat->host_stat != HS_OK) {
|
|
|
|
switch (stat->host_stat) {
|
1993-04-12 12:17:23 +04:00
|
|
|
case HS_SCSI_RESET_ADAPTER:
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
1993-04-12 12:17:23 +04:00
|
|
|
case HS_SCSI_RESET_INCOMING:
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
1994-12-28 22:42:47 +03:00
|
|
|
case HS_CMD_ABORTED_HOST:
|
|
|
|
case HS_CMD_ABORTED_ADAPTER:
|
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
1994-03-29 08:30:15 +04:00
|
|
|
case HS_TIMED_OUT: /* No response */
|
1994-12-28 22:42:47 +03:00
|
|
|
xs->error = XS_SELTIMEOUT;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
1994-03-29 08:30:15 +04:00
|
|
|
default: /* Other scsi protocol messes */
|
1994-12-28 22:42:47 +03:00
|
|
|
printf("%s: host_stat %x\n",
|
|
|
|
ahb->sc_dev.dv_xname, stat->host_stat);
|
1993-03-21 21:04:42 +03:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
} else if (stat->target_stat != SCSI_OK) {
|
|
|
|
switch (stat->target_stat) {
|
|
|
|
case SCSI_CHECK:
|
|
|
|
s1 = &ecb->ecb_sense;
|
|
|
|
s2 = &xs->sense;
|
1993-04-12 12:17:23 +04:00
|
|
|
*s2 = *s1;
|
1993-03-21 21:04:42 +03:00
|
|
|
xs->error = XS_SENSE;
|
|
|
|
break;
|
1994-12-28 22:42:47 +03:00
|
|
|
case SCSI_BUSY:
|
1993-03-21 21:04:42 +03:00
|
|
|
xs->error = XS_BUSY;
|
|
|
|
break;
|
|
|
|
default:
|
1994-12-28 22:42:47 +03:00
|
|
|
printf("%s: target_stat %x\n",
|
|
|
|
ahb->sc_dev.dv_xname, stat->target_stat);
|
1993-03-21 21:04:42 +03:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
} else
|
|
|
|
xs->resid = 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
done:
|
1993-04-12 12:17:23 +04:00
|
|
|
xs->flags |= ITSDONE;
|
1994-03-29 08:30:15 +04:00
|
|
|
ahb_free_ecb(ahb, ecb, xs->flags);
|
|
|
|
scsi_done(xs);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* A ecb (and hence a mbx-out is put onto the
|
1993-04-12 12:17:23 +04:00
|
|
|
* free list.
|
|
|
|
*/
|
|
|
|
void
|
1994-03-29 08:30:15 +04:00
|
|
|
ahb_free_ecb(ahb, ecb, flags)
|
|
|
|
struct ahb_softc *ahb;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ahb_ecb *ecb;
|
1994-03-29 08:30:15 +04:00
|
|
|
int flags;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1995-08-13 02:58:01 +04:00
|
|
|
int s;
|
1993-04-12 12:17:23 +04:00
|
|
|
|
1995-08-13 02:58:01 +04:00
|
|
|
s = splbio();
|
1993-03-21 21:04:42 +03:00
|
|
|
|
|
|
|
ecb->flags = ECB_FREE;
|
1994-12-28 22:42:47 +03:00
|
|
|
TAILQ_INSERT_HEAD(&ahb->free_ecb, ecb, chain);
|
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
1995-10-03 23:58:56 +03:00
|
|
|
* If there were none, wake anybody waiting for one to come free,
|
|
|
|
* starting with queued entries.
|
1993-04-12 12:17:23 +04:00
|
|
|
*/
|
1995-10-03 23:58:56 +03:00
|
|
|
if (ecb->chain.tqe_next == 0)
|
1994-12-28 22:42:47 +03:00
|
|
|
wakeup(&ahb->free_ecb);
|
1993-04-12 12:17:23 +04:00
|
|
|
|
1995-08-13 02:58:01 +04:00
|
|
|
splx(s);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1995-10-03 23:58:56 +03:00
|
|
|
static inline void
|
|
|
|
ahb_init_ecb(ahb, ecb)
|
|
|
|
struct ahb_softc *ahb;
|
|
|
|
struct ahb_ecb *ecb;
|
|
|
|
{
|
|
|
|
int hashnum;
|
|
|
|
|
|
|
|
bzero(ecb, sizeof(struct ahb_ecb));
|
|
|
|
/*
|
|
|
|
* put in the phystokv hash table
|
|
|
|
* Never gets taken out.
|
|
|
|
*/
|
|
|
|
ecb->hashkey = KVTOPHYS(ecb);
|
1995-10-04 03:35:07 +03:00
|
|
|
hashnum = ECB_HASH(ecb->hashkey);
|
1995-10-03 23:58:56 +03:00
|
|
|
ecb->nexthash = ahb->ecbhash[hashnum];
|
|
|
|
ahb->ecbhash[hashnum] = ecb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
ahb_reset_ecb(ahb, ecb)
|
|
|
|
struct ahb_softc *ahb;
|
|
|
|
struct ahb_ecb *ecb;
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* Get a free ecb
|
1994-03-29 08:30:15 +04:00
|
|
|
*
|
|
|
|
* If there are none, see if we can allocate a new one. If so, put it in the
|
|
|
|
* hash table too otherwise either return an error or sleep.
|
1993-04-12 12:17:23 +04:00
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ahb_ecb *
|
1994-03-29 08:30:15 +04:00
|
|
|
ahb_get_ecb(ahb, flags)
|
|
|
|
struct ahb_softc *ahb;
|
|
|
|
int flags;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ahb_ecb *ecb;
|
1995-10-03 23:58:56 +03:00
|
|
|
int s;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1995-08-13 02:58:01 +04:00
|
|
|
s = splbio();
|
1993-04-12 12:17:23 +04:00
|
|
|
|
|
|
|
/*
|
1994-03-29 08:30:15 +04:00
|
|
|
* If we can and have to, sleep waiting for one to come free
|
|
|
|
* but only if we can't allocate a new one.
|
1993-04-12 12:17:23 +04:00
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
for (;;) {
|
|
|
|
ecb = ahb->free_ecb.tqh_first;
|
|
|
|
if (ecb) {
|
|
|
|
TAILQ_REMOVE(&ahb->free_ecb, ecb, chain);
|
|
|
|
break;
|
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
if (ahb->numecbs < AHB_ECB_MAX) {
|
1994-12-28 22:42:47 +03:00
|
|
|
if (ecb = (struct ahb_ecb *) malloc(sizeof(struct ahb_ecb),
|
|
|
|
M_TEMP, M_NOWAIT)) {
|
1995-10-03 23:58:56 +03:00
|
|
|
ahb_init_ecb(ahb, ecb);
|
1994-03-29 08:30:15 +04:00
|
|
|
ahb->numecbs++;
|
|
|
|
} else {
|
1994-12-28 22:42:47 +03:00
|
|
|
printf("%s: can't malloc ecb\n",
|
|
|
|
ahb->sc_dev.dv_xname);
|
1995-10-03 23:58:56 +03:00
|
|
|
goto out;
|
1994-03-29 08:30:15 +04:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
break;
|
1994-03-29 08:30:15 +04:00
|
|
|
}
|
1995-10-03 23:58:56 +03:00
|
|
|
if ((flags & SCSI_NOSLEEP) != 0)
|
|
|
|
goto out;
|
|
|
|
tsleep(&ahb->free_ecb, PRIBIO, "ahbecb", 0);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1995-10-03 23:58:56 +03:00
|
|
|
ahb_reset_ecb(ahb, ecb);
|
|
|
|
ecb->flags = ECB_ACTIVE;
|
|
|
|
|
|
|
|
out:
|
1995-08-13 02:58:01 +04:00
|
|
|
splx(s);
|
1994-12-28 22:42:47 +03:00
|
|
|
return ecb;
|
1994-03-29 08:30:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* given a physical address, find the ecb that it corresponds to.
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ahb_ecb *
|
1994-03-29 08:30:15 +04:00
|
|
|
ahb_ecb_phys_kv(ahb, ecb_phys)
|
|
|
|
struct ahb_softc *ahb;
|
|
|
|
physaddr ecb_phys;
|
|
|
|
{
|
|
|
|
int hashnum = ECB_HASH(ecb_phys);
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ahb_ecb *ecb = ahb->ecbhash[hashnum];
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
while (ecb) {
|
|
|
|
if (ecb->hashkey == ecb_phys)
|
1994-03-29 08:30:15 +04:00
|
|
|
break;
|
1994-12-28 22:42:47 +03:00
|
|
|
ecb = ecb->nexthash;
|
1994-03-29 08:30:15 +04:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
return ecb;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
|
|
|
* Start the board, ready for normal operation
|
|
|
|
*/
|
|
|
|
int
|
1996-03-09 01:03:26 +03:00
|
|
|
ahb_find(bc, ioh, ahb)
|
|
|
|
bus_chipset_tag_t bc;
|
|
|
|
bus_io_handle_t ioh;
|
1994-03-29 08:30:15 +04:00
|
|
|
struct ahb_softc *ahb;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:30:15 +04:00
|
|
|
u_char intdef;
|
1996-02-27 03:20:54 +03:00
|
|
|
int i, irq, busid;
|
1994-03-29 08:30:15 +04:00
|
|
|
int wait = 1000; /* 1 sec enough? */
|
1993-04-12 12:17:23 +04:00
|
|
|
|
1996-03-09 01:03:26 +03:00
|
|
|
bus_io_write_1(bc, ioh, PORTADDR, PORTADDR_ENHANCED);
|
1994-07-28 06:39:21 +04:00
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
#define NO_NO 1
|
|
|
|
#ifdef NO_NO
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* reset board, If it doesn't respond, assume
|
1993-04-12 12:17:23 +04:00
|
|
|
* that it's not there.. good for the probe
|
|
|
|
*/
|
1996-03-09 01:03:26 +03:00
|
|
|
bus_io_write_1(bc, ioh, G2CNTRL, G2CNTRL_HARD_RESET);
|
1994-03-29 08:30:15 +04:00
|
|
|
delay(1000);
|
1996-03-09 01:03:26 +03:00
|
|
|
bus_io_write_1(bc, ioh, G2CNTRL, 0);
|
1994-03-29 08:30:15 +04:00
|
|
|
delay(10000);
|
|
|
|
while (--wait) {
|
1996-03-09 01:03:26 +03:00
|
|
|
if ((bus_io_read_1(bc, ioh, G2STAT) & G2STAT_BUSY) == 0)
|
1994-03-29 08:30:15 +04:00
|
|
|
break;
|
|
|
|
delay(1000);
|
|
|
|
}
|
|
|
|
if (!wait) {
|
1996-02-27 03:20:54 +03:00
|
|
|
#ifdef AHBDEBUG
|
1993-03-21 21:04:42 +03:00
|
|
|
if (ahb_debug & AHB_SHOWMISC)
|
1994-03-29 08:30:15 +04:00
|
|
|
printf("ahb_find: No answer from aha1742 board\n");
|
|
|
|
#endif /*AHBDEBUG */
|
|
|
|
return ENXIO;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1996-03-09 01:03:26 +03:00
|
|
|
i = bus_io_read_1(bc, ioh, MBOXIN0);
|
1994-03-29 08:30:15 +04:00
|
|
|
if (i) {
|
|
|
|
printf("self test failed, val = 0x%x\n", i);
|
|
|
|
return EIO;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-07-28 06:39:21 +04:00
|
|
|
|
|
|
|
/* Set it again, just to be sure. */
|
1996-03-09 01:03:26 +03:00
|
|
|
bus_io_write_1(bc, ioh, PORTADDR, PORTADDR_ENHANCED);
|
1993-03-21 21:04:42 +03:00
|
|
|
#endif
|
1993-04-12 12:17:23 +04:00
|
|
|
|
1996-03-09 01:03:26 +03:00
|
|
|
while (bus_io_read_1(bc, ioh, G2STAT) & G2STAT_INT_PEND) {
|
1993-03-21 21:04:42 +03:00
|
|
|
printf(".");
|
1996-03-09 01:03:26 +03:00
|
|
|
bus_io_write_1(bc, ioh, G2CNTRL, G2CNTRL_CLEAR_EISA_INT);
|
1994-03-29 08:30:15 +04:00
|
|
|
delay(10000);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1996-03-09 01:03:26 +03:00
|
|
|
intdef = bus_io_read_1(bc, ioh, INTDEF);
|
1994-03-29 08:30:15 +04:00
|
|
|
switch (intdef & 0x07) {
|
1993-04-12 12:17:23 +04:00
|
|
|
case INT9:
|
1996-02-27 03:20:54 +03:00
|
|
|
irq = 9;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
1993-04-12 12:17:23 +04:00
|
|
|
case INT10:
|
1996-02-27 03:20:54 +03:00
|
|
|
irq = 10;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
1993-04-12 12:17:23 +04:00
|
|
|
case INT11:
|
1996-02-27 03:20:54 +03:00
|
|
|
irq = 11;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
1993-04-12 12:17:23 +04:00
|
|
|
case INT12:
|
1996-02-27 03:20:54 +03:00
|
|
|
irq = 12;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
1993-04-12 12:17:23 +04:00
|
|
|
case INT14:
|
1996-02-27 03:20:54 +03:00
|
|
|
irq = 14;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
1993-04-12 12:17:23 +04:00
|
|
|
case INT15:
|
1996-02-27 03:20:54 +03:00
|
|
|
irq = 15;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
|
|
|
default:
|
1994-03-29 08:30:15 +04:00
|
|
|
printf("illegal int setting %x\n", intdef);
|
|
|
|
return EIO;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1993-04-12 12:17:23 +04:00
|
|
|
|
1996-03-09 01:03:26 +03:00
|
|
|
bus_io_write_1(bc, ioh, INTDEF, (intdef | INTEN)); /* make sure we can interrupt */
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/* who are we on the scsi bus? */
|
1996-03-09 01:03:26 +03:00
|
|
|
busid = (bus_io_read_1(bc, ioh, SCSIDEF) & HSCSIID);
|
1996-02-27 03:20:54 +03:00
|
|
|
|
|
|
|
/* if we want to fill in softc, do so now */
|
|
|
|
if (ahb != NULL) {
|
|
|
|
ahb->sc_irq = irq;
|
|
|
|
ahb->ahb_scsi_dev = busid;
|
|
|
|
}
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
|
|
|
* Note that we are going and return (to probe)
|
|
|
|
*/
|
|
|
|
return 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
void
|
1994-03-29 08:30:15 +04:00
|
|
|
ahb_init(ahb)
|
|
|
|
struct ahb_softc *ahb;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
1995-08-13 00:30:45 +04:00
|
|
|
void
|
1994-03-29 08:30:15 +04:00
|
|
|
ahbminphys(bp)
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (bp->b_bcount > ((AHB_NSEG - 1) << PGSHIFT))
|
|
|
|
bp->b_bcount = ((AHB_NSEG - 1) << PGSHIFT);
|
1995-08-13 00:30:45 +04:00
|
|
|
minphys(bp);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1993-04-12 12:17:23 +04:00
|
|
|
|
|
|
|
/*
|
1994-03-29 08:30:15 +04:00
|
|
|
* start a scsi operation given the command and the data address. Also needs
|
|
|
|
* the unit, target and lu.
|
1993-04-12 12:17:23 +04:00
|
|
|
*/
|
1995-08-13 00:30:45 +04:00
|
|
|
int
|
1994-03-29 08:30:15 +04:00
|
|
|
ahb_scsi_cmd(xs)
|
|
|
|
struct scsi_xfer *xs;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:30:15 +04:00
|
|
|
struct scsi_link *sc_link = xs->sc_link;
|
|
|
|
struct ahb_softc *ahb = sc_link->adapter_softc;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ahb_ecb *ecb;
|
1993-03-21 21:04:42 +03:00
|
|
|
struct ahb_dma_seg *sg;
|
1994-03-29 08:30:15 +04:00
|
|
|
int seg; /* scatter gather seg being worked on */
|
1994-12-28 22:42:47 +03:00
|
|
|
u_long thiskv, thisphys, nextphys;
|
1994-03-29 08:30:15 +04:00
|
|
|
int bytes_this_seg, bytes_this_page, datalen, flags;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct iovec *iovp;
|
1994-03-29 08:30:15 +04:00
|
|
|
int s;
|
|
|
|
|
|
|
|
SC_DEBUG(sc_link, SDEV_DB2, ("ahb_scsi_cmd\n"));
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
|
|
|
* get a ecb (mbox-out) to use. If the transfer
|
|
|
|
* is from a buf (possibly from interrupt time)
|
|
|
|
* then we can't allow it to sleep
|
|
|
|
*/
|
1993-03-21 21:04:42 +03:00
|
|
|
flags = xs->flags;
|
1995-01-13 17:46:44 +03:00
|
|
|
if ((flags & (ITSDONE|INUSE)) != INUSE) {
|
|
|
|
printf("%s: done or not in use?\n", ahb->sc_dev.dv_xname);
|
1993-03-21 21:04:42 +03:00
|
|
|
xs->flags &= ~ITSDONE;
|
|
|
|
xs->flags |= INUSE;
|
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
if ((ecb = ahb_get_ecb(ahb, flags)) == NULL) {
|
1993-03-21 21:04:42 +03:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
1994-03-29 08:30:15 +04:00
|
|
|
return TRY_AGAIN_LATER;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
ecb->xs = xs;
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
|
|
|
* If it's a reset, we need to do an 'immediate'
|
1994-12-28 22:42:47 +03:00
|
|
|
* command, and store its ecb for later
|
1995-08-13 00:30:45 +04:00
|
|
|
* if there is already an immediate waiting,
|
1993-04-12 12:17:23 +04:00
|
|
|
* then WE must wait
|
|
|
|
*/
|
1994-03-29 08:30:15 +04:00
|
|
|
if (flags & SCSI_RESET) {
|
1993-03-21 21:04:42 +03:00
|
|
|
ecb->flags |= ECB_IMMED;
|
1994-03-29 08:30:15 +04:00
|
|
|
if (ahb->immed_ecb)
|
|
|
|
return TRY_AGAIN_LATER;
|
|
|
|
ahb->immed_ecb = ecb;
|
1994-12-28 22:42:47 +03:00
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
ahb_send_immed(ahb, sc_link->target, AHB_TARG_RESET);
|
|
|
|
|
|
|
|
if ((flags & SCSI_POLL) == 0) {
|
1994-05-05 11:41:44 +04:00
|
|
|
timeout(ahb_timeout, ecb, (xs->timeout * hz) / 1000);
|
1993-03-21 21:04:42 +03:00
|
|
|
splx(s);
|
1994-03-29 08:30:15 +04:00
|
|
|
return SUCCESSFULLY_QUEUED;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we can't use interrupts, poll on completion
|
|
|
|
*/
|
|
|
|
if (ahb_poll(ahb, xs, xs->timeout))
|
|
|
|
ahb_timeout(ecb);
|
|
|
|
return COMPLETE;
|
1993-04-12 12:17:23 +04:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
|
|
|
* Put all the arguments for the xfer in the ecb
|
|
|
|
*/
|
1993-03-21 21:04:42 +03:00
|
|
|
ecb->opcode = ECB_SCSI_OP;
|
1994-03-29 08:30:15 +04:00
|
|
|
ecb->opt1 = ECB_SES | ECB_DSB | ECB_ARS;
|
|
|
|
if (xs->datalen)
|
1993-03-21 21:04:42 +03:00
|
|
|
ecb->opt1 |= ECB_S_G;
|
1994-03-29 08:30:15 +04:00
|
|
|
ecb->opt2 = sc_link->lun | ECB_NRB;
|
1994-12-28 22:42:47 +03:00
|
|
|
ecb->scsi_cmd_length = xs->cmdlen;
|
|
|
|
ecb->sense_ptr = KVTOPHYS(&ecb->ecb_sense);
|
|
|
|
ecb->req_sense_length = sizeof(ecb->ecb_sense);
|
1994-03-29 08:30:15 +04:00
|
|
|
ecb->status = KVTOPHYS(&ecb->ecb_status);
|
1995-01-18 07:20:16 +03:00
|
|
|
ecb->ecb_status.host_stat = 0x00;
|
|
|
|
ecb->ecb_status.target_stat = 0x00;
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
if (xs->datalen && (flags & SCSI_RESET) == 0) {
|
|
|
|
ecb->data_addr = KVTOPHYS(ecb->ahb_dma);
|
1994-03-29 08:30:15 +04:00
|
|
|
sg = ecb->ahb_dma;
|
|
|
|
seg = 0;
|
|
|
|
#ifdef TFS
|
|
|
|
if (flags & SCSI_DATA_UIO) {
|
|
|
|
iovp = ((struct uio *) xs->data)->uio_iov;
|
|
|
|
datalen = ((struct uio *) xs->data)->uio_iovcnt;
|
1993-03-21 21:04:42 +03:00
|
|
|
xs->datalen = 0;
|
1994-03-29 08:30:15 +04:00
|
|
|
while (datalen && seg < AHB_NSEG) {
|
1994-12-28 22:42:47 +03:00
|
|
|
sg->seg_addr = (physaddr)iovp->iov_base;
|
|
|
|
sg->seg_len = iovp->iov_len;
|
|
|
|
xs->datalen += iovp->iov_len;
|
1994-03-29 08:30:15 +04:00
|
|
|
SC_DEBUGN(sc_link, SDEV_DB4, ("(0x%x@0x%x)",
|
1994-12-28 22:42:47 +03:00
|
|
|
iovp->iov_len, iovp->iov_base));
|
1993-03-21 21:04:42 +03:00
|
|
|
sg++;
|
|
|
|
iovp++;
|
|
|
|
seg++;
|
|
|
|
datalen--;
|
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif /*TFS */
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Set up the scatter gather block
|
|
|
|
*/
|
|
|
|
SC_DEBUG(sc_link, SDEV_DB4,
|
1994-12-28 22:42:47 +03:00
|
|
|
("%d @0x%x:- ", xs->datalen, xs->data));
|
1994-03-29 08:30:15 +04:00
|
|
|
datalen = xs->datalen;
|
1995-04-13 08:16:16 +04:00
|
|
|
thiskv = (long) xs->data;
|
1994-03-29 08:30:15 +04:00
|
|
|
thisphys = KVTOPHYS(thiskv);
|
1993-04-12 12:17:23 +04:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
while (datalen && seg < AHB_NSEG) {
|
|
|
|
bytes_this_seg = 0;
|
1993-04-12 12:17:23 +04:00
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
/* put in the base address */
|
1994-12-28 22:42:47 +03:00
|
|
|
sg->seg_addr = thisphys;
|
1993-04-12 12:17:23 +04:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
SC_DEBUGN(sc_link, SDEV_DB4, ("0x%x", thisphys));
|
1993-04-12 12:17:23 +04:00
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
/* do it at least once */
|
1993-04-12 12:17:23 +04:00
|
|
|
nextphys = thisphys;
|
1994-12-28 22:42:47 +03:00
|
|
|
while (datalen && thisphys == nextphys) {
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* This page is contiguous (physically)
|
|
|
|
* with the the last, just extend the
|
|
|
|
* length
|
|
|
|
*/
|
|
|
|
/* how far to the end of the page */
|
|
|
|
nextphys = (thisphys & ~PGOFSET) + NBPG;
|
|
|
|
bytes_this_page = nextphys - thisphys;
|
|
|
|
/**** or the data ****/
|
|
|
|
bytes_this_page = min(bytes_this_page,
|
|
|
|
datalen);
|
|
|
|
bytes_this_seg += bytes_this_page;
|
|
|
|
datalen -= bytes_this_page;
|
1993-04-12 12:17:23 +04:00
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
/* get more ready for the next page */
|
1994-03-29 08:30:15 +04:00
|
|
|
thiskv = (thiskv & ~PGOFSET) + NBPG;
|
|
|
|
if (datalen)
|
1993-03-21 21:04:42 +03:00
|
|
|
thisphys = KVTOPHYS(thiskv);
|
|
|
|
}
|
1993-04-12 12:17:23 +04:00
|
|
|
/*
|
1995-08-13 00:30:45 +04:00
|
|
|
* next page isn't contiguous, finish the seg
|
1993-04-12 12:17:23 +04:00
|
|
|
*/
|
1994-03-29 08:30:15 +04:00
|
|
|
SC_DEBUGN(sc_link, SDEV_DB4,
|
1994-12-28 22:42:47 +03:00
|
|
|
("(0x%x)", bytes_this_seg));
|
|
|
|
sg->seg_len = bytes_this_seg;
|
1993-03-21 21:04:42 +03:00
|
|
|
sg++;
|
|
|
|
seg++;
|
|
|
|
}
|
1993-04-12 12:17:23 +04:00
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
/*end of iov/kv decision */
|
1994-12-28 22:42:47 +03:00
|
|
|
ecb->data_length = seg * sizeof(struct ahb_dma_seg);
|
1994-03-29 08:30:15 +04:00
|
|
|
SC_DEBUGN(sc_link, SDEV_DB4, ("\n"));
|
1993-04-12 12:17:23 +04:00
|
|
|
if (datalen) {
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* there's still data, must have run out of segs!
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
printf("%s: ahb_scsi_cmd, more than %d dma segs\n",
|
|
|
|
ahb->sc_dev.dv_xname, AHB_NSEG);
|
1993-03-21 21:04:42 +03:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
1994-03-29 08:30:15 +04:00
|
|
|
ahb_free_ecb(ahb, ecb, flags);
|
1994-12-28 22:42:47 +03:00
|
|
|
return COMPLETE;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
} else { /* No data xfer, use non S/G values */
|
1994-12-28 22:42:47 +03:00
|
|
|
ecb->data_addr = (physaddr)0;
|
|
|
|
ecb->data_length = 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
ecb->link_addr = (physaddr)0;
|
1993-04-12 12:17:23 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Put the scsi command in the ecb and start it
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
if ((flags & SCSI_RESET) == 0)
|
|
|
|
bcopy(xs->cmd, &ecb->scsi_cmd, ecb->scsi_cmd_length);
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
ahb_send_mbox(ahb, OP_START_ECB, ecb);
|
1993-04-12 12:17:23 +04:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* Usually return SUCCESSFULLY QUEUED
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
if ((flags & SCSI_POLL) == 0) {
|
1994-05-05 09:35:42 +04:00
|
|
|
timeout(ahb_timeout, ecb, (xs->timeout * hz) / 1000);
|
1993-03-21 21:04:42 +03:00
|
|
|
splx(s);
|
1994-03-29 08:30:15 +04:00
|
|
|
return SUCCESSFULLY_QUEUED;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1993-04-12 12:17:23 +04:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
splx(s);
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* If we can't use interrupts, poll on completion
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
if (ahb_poll(ahb, xs, xs->timeout)) {
|
|
|
|
ahb_timeout(ecb);
|
|
|
|
if (ahb_poll(ahb, xs, 2000))
|
|
|
|
ahb_timeout(ecb);
|
|
|
|
}
|
1993-04-12 12:17:23 +04:00
|
|
|
return COMPLETE;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
void
|
1994-03-29 08:30:15 +04:00
|
|
|
ahb_timeout(arg)
|
1994-05-05 09:35:42 +04:00
|
|
|
void *arg;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ahb_ecb *ecb = arg;
|
|
|
|
struct scsi_xfer *xs = ecb->xs;
|
|
|
|
struct scsi_link *sc_link = xs->sc_link;
|
|
|
|
struct ahb_softc *ahb = sc_link->adapter_softc;
|
|
|
|
int s;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
sc_print_addr(sc_link);
|
|
|
|
printf("timed out");
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
s = splbio();
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
if (ecb->flags & ECB_IMMED) {
|
1994-12-28 22:42:47 +03:00
|
|
|
printf("\n");
|
1994-03-29 08:30:15 +04:00
|
|
|
ecb->xs->retries = 0; /* I MEAN IT ! */
|
|
|
|
ecb->flags |= ECB_IMMED_FAIL;
|
1994-12-28 22:42:47 +03:00
|
|
|
ahb_done(ahb, ecb);
|
1994-03-29 08:30:15 +04:00
|
|
|
splx(s);
|
|
|
|
return;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* If it has been through before, then
|
|
|
|
* a previous abort has failed, don't
|
|
|
|
* try abort again
|
|
|
|
*/
|
|
|
|
if (ecb->flags == ECB_ABORTED) {
|
1994-12-28 22:42:47 +03:00
|
|
|
/* abort timed out */
|
|
|
|
printf(" AGAIN\n");
|
1994-03-29 08:30:15 +04:00
|
|
|
ecb->xs->retries = 0; /* I MEAN IT ! */
|
1994-12-28 22:42:47 +03:00
|
|
|
ahb_done(ahb, ecb);
|
|
|
|
} else {
|
|
|
|
/* abort the operation that has timed out */
|
1993-04-12 12:17:23 +04:00
|
|
|
printf("\n");
|
1994-12-28 22:42:47 +03:00
|
|
|
ecb->xs->error = XS_TIMEOUT;
|
1994-03-29 08:30:15 +04:00
|
|
|
ecb->flags = ECB_ABORTED;
|
1994-12-28 22:42:47 +03:00
|
|
|
ahb_send_mbox(ahb, OP_ABORT_ECB, ecb);
|
|
|
|
/* 2 secs for the abort */
|
|
|
|
if ((xs->flags & SCSI_POLL) == 0)
|
|
|
|
timeout(ahb_timeout, ecb, 2 * hz);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
splx(s);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1993-04-12 12:17:23 +04:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
#ifdef AHBDEBUG
|
1993-04-12 12:17:23 +04:00
|
|
|
void
|
1994-03-29 08:30:15 +04:00
|
|
|
ahb_print_ecb(ecb)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ahb_ecb *ecb;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:30:15 +04:00
|
|
|
printf("ecb:%x op:%x cmdlen:%d senlen:%d\n",
|
|
|
|
ecb, ecb->opcode, ecb->cdblen, ecb->senselen);
|
|
|
|
printf(" datlen:%d hstat:%x tstat:%x flags:%x\n",
|
1994-12-28 22:42:47 +03:00
|
|
|
ecb->datalen, ecb->ecb_status.host_stat,
|
|
|
|
ecb->ecb_status.target_stat, ecb->flags);
|
1994-03-29 08:30:15 +04:00
|
|
|
show_scsi_cmd(ecb->xs);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1993-04-12 12:17:23 +04:00
|
|
|
void
|
1994-03-29 08:30:15 +04:00
|
|
|
ahb_print_active_ecb(ahb)
|
|
|
|
struct ahb_softc *ahb;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-12-28 22:42:47 +03:00
|
|
|
struct ahb_ecb *ecb;
|
1994-03-29 08:30:15 +04:00
|
|
|
int i = 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
while (i++ < ECB_HASH_SIZE) {
|
1994-04-21 02:39:33 +04:00
|
|
|
ecb = ahb->ecb_hash_list[i];
|
1994-03-29 08:30:15 +04:00
|
|
|
while (ecb) {
|
|
|
|
if (ecb->flags != ECB_FREE)
|
|
|
|
ahb_print_ecb(ecb);
|
1994-04-21 02:39:33 +04:00
|
|
|
ecb = ecb->hash_list;
|
1994-03-29 08:30:15 +04:00
|
|
|
}
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
#endif /* AHBDEBUG */
|