11.12Schuck/*	$NetBSD: xdvar.h,v 1.12 2011/02/01 20:19:32 chuck Exp $	*/
21.1Sgwr
31.1Sgwr/*
41.1Sgwr * Copyright (c) 1995 Charles D. Cranor
51.1Sgwr * All rights reserved.
61.1Sgwr *
71.1Sgwr * Redistribution and use in source and binary forms, with or without
81.1Sgwr * modification, are permitted provided that the following conditions
91.1Sgwr * are met:
101.1Sgwr * 1. Redistributions of source code must retain the above copyright
111.1Sgwr *    notice, this list of conditions and the following disclaimer.
121.1Sgwr * 2. Redistributions in binary form must reproduce the above copyright
131.1Sgwr *    notice, this list of conditions and the following disclaimer in the
141.1Sgwr *    documentation and/or other materials provided with the distribution.
151.1Sgwr *
161.1Sgwr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
171.1Sgwr * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
181.1Sgwr * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
191.1Sgwr * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
201.1Sgwr * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
211.1Sgwr * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
221.1Sgwr * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
231.1Sgwr * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
241.1Sgwr * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
251.1Sgwr * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
261.1Sgwr */
271.1Sgwr
281.1Sgwr/*
291.4Sgwr * x d v a r . h
301.1Sgwr *
311.4Sgwr * this file defines the software structure we use to control the
321.1Sgwr * 753/7053.
331.1Sgwr *
341.12Schuck * author: Chuck Cranor <chuck@netbsd>
351.1Sgwr */
361.1Sgwr
371.7Sthorpej#include <sys/callout.h>
381.7Sthorpej
391.1Sgwr/*
401.1Sgwr * i/o request: wrapper for hardware's iopb data structure
411.1Sgwr */
421.1Sgwr
431.1Sgwrstruct xd_iorq {
441.11Stsutsui	struct xd_iopb *iopb;	/* address of matching iopb */
451.11Stsutsui	struct xdc_softc *xdc;	/* who we are working with */
461.11Stsutsui	struct xd_softc *xd;	/* which disk */
471.11Stsutsui	int ttl;		/* time to live */
481.11Stsutsui	int mode;		/* current mode (state+other data) */
491.11Stsutsui	int tries;		/* number of times we have tried it */
501.11Stsutsui	int errno;		/* error number if we fail */
511.11Stsutsui	int lasterror;		/* last error we got */
521.11Stsutsui	int blockno;		/* starting block no for this xfer */
531.11Stsutsui	int sectcnt;		/* number of sectors in xfer */
541.11Stsutsui	char *dbuf;		/* KVA of data buffer (advances) */
551.11Stsutsui	char *dbufbase;		/* base of dbuf */
561.11Stsutsui	struct buf *buf;	/* for NORM */
571.1Sgwr};
581.1Sgwr
591.1Sgwr/*
601.1Sgwr * state
611.1Sgwr */
621.1Sgwr
631.11Stsutsui#define XD_SUB_MASK 0xf0	/* mask bits for state */
641.11Stsutsui#define XD_SUB_FREE 0x00	/* free */
651.11Stsutsui#define XD_SUB_NORM 0x10	/* normal I/O request */
661.11Stsutsui#define XD_SUB_WAIT 0x20	/* normal I/O request in the
671.11Stsutsui				   context of a process */
681.11Stsutsui#define XD_SUB_POLL 0x30	/* polled mode */
691.11Stsutsui#define XD_SUB_DONE 0x40	/* not active, but can't be free'd yet */
701.11Stsutsui#define XD_SUB_NOQ  0x50	/* don't queue, just submit (internal) */
711.1Sgwr
721.1Sgwr#define XD_STATE(X) ((X) & XD_SUB_MASK) /* extract state from mode */
731.1Sgwr#define XD_NEWSTATE(OLD, NEW) (((OLD) & ~XD_SUB_MASK) |(NEW)) /* new state */
741.1Sgwr
751.1Sgwr
761.1Sgwr/*
771.1Sgwr * other mode data
781.1Sgwr */
791.1Sgwr
801.11Stsutsui#define XD_MODE_VERBO 0x08	/* print error messages */
811.11Stsutsui#define XD_MODE_B144  0x04	/* handling a bad144 sector */
821.1Sgwr
831.1Sgwr
841.1Sgwr/*
851.1Sgwr * software timers and flags
861.1Sgwr */
871.1Sgwr
881.11Stsutsui#define XDC_SUBWAITLIM	4	/* max number of "done" IOPBs there can be
891.11Stsutsui				   where we still allow a SUB_WAIT command */
901.11Stsutsui#define XDC_TICKCNT	(5*hz)	/* call xdc_tick on this interval (5 sec) */
911.11Stsutsui#define XDC_MAXTTL	2	/* max number of xd ticks to live */
921.11Stsutsui#define XDC_NOUNIT	(-1)	/* for xdcmd: no unit number */
931.1Sgwr
941.1Sgwr/*
951.1Sgwr * a "xd_softc" structure contains per-disk state info.
961.1Sgwr */
971.1Sgwr
981.1Sgwrstruct xd_softc {
991.11Stsutsui	device_t sc_dev;		/* device struct, reqd by autoconf */
1001.11Stsutsui	struct disk sc_dk;		/* generic disk info */
1011.11Stsutsui	struct xdc_softc *parent;	/* parent */
1021.11Stsutsui	u_short flags;			/* flags */
1031.11Stsutsui	u_short state;			/* device state */
1041.11Stsutsui	int xd_drive;			/* unit number */
1051.11Stsutsui	/* geometry */
1061.11Stsutsui	u_short ncyl, acyl, pcyl;	/* number of cyl's */
1071.11Stsutsui	u_short sectpercyl;		/* nhead*nsect */
1081.11Stsutsui	u_char nhead;			/* number of heads */
1091.11Stsutsui	u_char nsect;			/* number of sectors per track */
1101.11Stsutsui	u_char hw_spt;		      /* as above, but includes spare sectors */
1111.11Stsutsui	struct dkbad dkb;               /* bad144 sectors */
1121.1Sgwr};
1131.1Sgwr
1141.1Sgwr/*
1151.1Sgwr * flags
1161.1Sgwr */
1171.1Sgwr
1181.11Stsutsui#define XD_WLABEL 0x0001	/* write label */
1191.1Sgwr/*
1201.1Sgwr * state
1211.1Sgwr */
1221.1Sgwr
1231.11Stsutsui#define XD_DRIVE_UNKNOWN	0	/* never talked to it */
1241.11Stsutsui#define XD_DRIVE_ATTACHING	1	/* attach in progress */
1251.11Stsutsui#define XD_DRIVE_NOLABEL	2	/* drive on-line, no label */
1261.11Stsutsui#define XD_DRIVE_ONLINE		3	/* drive is on-line */
1271.1Sgwr
1281.1Sgwr/*
1291.1Sgwr * a "xdc_softc" structure contains per-disk-controller state info,
1301.1Sgwr * including a list of active controllers.
1311.1Sgwr */
1321.1Sgwr
1331.1Sgwrstruct xdc_softc {
1341.11Stsutsui	device_t sc_dev;		/* device struct, reqd by autoconf */
1351.11Stsutsui	struct evcnt sc_intrcnt;	/* event counter (for vmstat -i) */
1361.7Sthorpej
1371.11Stsutsui	struct callout sc_tick_ch;
1381.1Sgwr
1391.11Stsutsui	struct xdc *xdc;		/* vaddr of vme registers */
1401.1Sgwr
1411.11Stsutsui	int bustype;			/* from attach args */
1421.11Stsutsui	int ipl;			/* interrupt level */
1431.11Stsutsui	int vector;			/* interrupt vector */
1441.11Stsutsui
1451.11Stsutsui	struct xd_softc *sc_drives[XDC_MAXDEV]; /* drives on this controller */
1461.11Stsutsui
1471.11Stsutsui	struct xd_iorq *reqs;		/* i/o requests */
1481.11Stsutsui	struct xd_iopb *iopbase;	/* iopb base addr (maps iopb->iorq) */
1491.11Stsutsui	struct xd_iopb *dvmaiopb;	/* iopb base in DVMA space, not kvm */
1501.11Stsutsui	struct bufq_state *sc_wq;	/* queue'd IOPBs for this controller */
1511.11Stsutsui	char freereq[XDC_MAXIOPB];	/* free list (stack) */
1521.11Stsutsui	char waitq[XDC_MAXIOPB];	/* wait queue */
1531.11Stsutsui	u_char nfree;			/* number of iopbs free */
1541.11Stsutsui	u_char nrun;			/* number running */
1551.11Stsutsui	u_char nwait;			/* number of waiting iopbs */
1561.11Stsutsui	u_char ndone;			/* number of done IORQs */
1571.11Stsutsui	u_char waithead;		/* head of queue */
1581.11Stsutsui	u_char waitend;			/* end of queue */
1591.1Sgwr};
1601.1Sgwr
1611.1Sgwr/*
1621.1Sgwr * reset blast modes
1631.1Sgwr */
1641.1Sgwr
1651.11Stsutsui#define XD_RSET_NONE	(-1)	/* restart all requests */
1661.11Stsutsui#define XD_RSET_ALL	(-2)	/* don't restart anything */
167