11.14Schs/*	$NetBSD: xyvar.h,v 1.14 2012/10/27 17:18:39 chs Exp $	*/
21.1Spk
31.1Spk/*
41.1Spk * Copyright (c) 1995 Charles D. Cranor
51.1Spk * All rights reserved.
61.1Spk *
71.1Spk * Redistribution and use in source and binary forms, with or without
81.1Spk * modification, are permitted provided that the following conditions
91.1Spk * are met:
101.1Spk * 1. Redistributions of source code must retain the above copyright
111.1Spk *    notice, this list of conditions and the following disclaimer.
121.1Spk * 2. Redistributions in binary form must reproduce the above copyright
131.1Spk *    notice, this list of conditions and the following disclaimer in the
141.1Spk *    documentation and/or other materials provided with the distribution.
151.1Spk *
161.1Spk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
171.1Spk * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
181.1Spk * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
191.1Spk * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
201.1Spk * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
211.1Spk * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
221.1Spk * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
231.1Spk * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
241.1Spk * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
251.1Spk * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
261.1Spk */
271.1Spk
281.1Spk/*
291.1Spk * x y v a r . h
301.1Spk *
311.1Spk * this file defines the software structure we use to control the
321.1Spk * 450/451.
331.1Spk *
341.13Schuck * author: Chuck Cranor <chuck@netbsd>
351.1Spk */
361.1Spk
371.6Sthorpej#include <sys/callout.h>
381.6Sthorpej
391.1Spk/*
401.1Spk * i/o request: wrapper for hardware's iopb data structure
411.1Spk */
421.1Spkstruct xy_iorq {
431.3Spk	struct xy_iopb *iopb;	/* address of matching iopb */
441.3Spk	struct xy_iopb *dmaiopb;/* DMA address of above */
451.3Spk	struct xyc_softc *xyc;	/* who we are working with */
461.3Spk	struct xy_softc *xy;	/* which disk */
471.3Spk	int ttl;		/* time to live */
481.3Spk	int mode;		/* current mode (state+other data) */
491.3Spk	int tries;		/* number of times we have tried it */
501.12Schristos	int errnum;		/* error number if we fail */
511.3Spk	int lasterror;		/* last error we got */
521.3Spk	int blockno;		/* starting block no for this xfer */
531.3Spk	int sectcnt;		/* number of sectors in xfer */
541.3Spk	char *dbuf;		/* KVA of data buffer (advances) */
551.3Spk	struct buf *buf;	/* for NORM */
561.3Spk	bus_dmamap_t dmamap;	/* DMA I/O handle */
571.1Spk};
581.1Spk
591.1Spk/*
601.1Spk * state
611.1Spk */
621.3Spk#define XY_SUB_MASK	0xf0	/* mask bits for state */
631.3Spk#define XY_SUB_FREE	0x00	/* free */
641.3Spk#define XY_SUB_NORM	0x10	/* normal I/O request */
651.3Spk#define XY_SUB_WAIT	0x20	/* normal I/O request in the
661.3Spk                                   context of a process */
671.3Spk#define XY_SUB_POLL	0x30	/* polled mode */
681.3Spk#define XY_SUB_DONE	0x40	/* not active, but can't be free'd yet */
691.3Spk#define XY_SUB_NOQ	0x50	/* don't queue, just submit (internal) */
701.1Spk
711.1Spk#define XY_STATE(X) ((X) & XY_SUB_MASK) /* extract state from mode */
721.1Spk#define XY_NEWSTATE(OLD, NEW) (((OLD) & ~XY_SUB_MASK) |(NEW)) /* new state */
731.1Spk
741.1Spk
751.1Spk/*
761.1Spk * other mode data
771.1Spk */
781.3Spk#define XY_MODE_VERBO	0x08	/* print error messages */
791.3Spk#define XY_MODE_B144	0x04	/* handling a bad144 sector */
801.1Spk
811.1Spk
821.1Spk/*
831.1Spk * software timers and flags
841.1Spk */
851.3Spk#define XYC_SUBWAITLIM	4	/* max number of "done" IOPBs there can be
861.3Spk				   where we still allow a SUB_WAIT command */
871.3Spk#define XYC_TICKCNT	(5*hz)	/* call xyc_tick on this interval (5 sec) */
881.3Spk#define XYC_MAXTTL	2	/* max number of xy ticks to live */
891.3Spk#define XYC_NOUNIT	(-1)	/* for xycmd: no unit number */
901.1Spk
911.1Spk/*
921.1Spk * a "xy_softc" structure contains per-disk state info.
931.1Spk */
941.1Spkstruct xy_softc {
951.14Schs	device_t sc_dev;	/* device struct, reqd by autoconf */
961.3Spk	struct disk sc_dk;	/* generic disk info */
971.3Spk	struct xyc_softc *parent;/* parent */
981.3Spk	u_short flags;		/* flags */
991.3Spk	u_short state;		/* device state */
1001.3Spk	int xy_drive;		/* unit number */
1011.3Spk	int drive_type;		/* drive type (as per disk) */
1021.3Spk
1031.3Spk	/* geometry */
1041.3Spk	u_short ncyl, acyl, pcyl;	/* number of cyl's */
1051.3Spk	u_short sectpercyl;	/* nhead*nsect */
1061.3Spk	u_char nhead;		/* number of heads */
1071.3Spk	u_char nsect;		/* number of sectors per track */
1081.3Spk	u_char hw_spt;		/* as above, but includes spare sectors */
1091.3Spk	struct xy_iorq *xyrq;	/* this disk's ioreq structure */
1101.10Syamt	struct bufq_state *xyq;	/* queued I/O requests */
1111.3Spk	struct dkbad dkb;	/* bad144 sectors */
1121.1Spk};
1131.1Spk
1141.1Spk/*
1151.1Spk * flags
1161.1Spk */
1171.1Spk
1181.1Spk#define XY_WLABEL 0x0001           /* write label */
1191.1Spk/*
1201.1Spk * state
1211.1Spk */
1221.1Spk
1231.1Spk#define XY_DRIVE_UNKNOWN 0         /* never talked to it */
1241.1Spk#define XY_DRIVE_ATTACHING 1       /* attach in progress */
1251.1Spk#define XY_DRIVE_NOLABEL 2         /* drive on-line, no label */
1261.1Spk#define XY_DRIVE_ONLINE  3         /* drive is on-line */
1271.1Spk
1281.1Spk/*
1291.1Spk * a "xyc_softc" structure contains per-disk-controller state info,
1301.1Spk * including a list of active controllers.
1311.1Spk */
1321.1Spk
1331.1Spkstruct xyc_softc {
1341.14Schs	device_t sc_dev;		/* device struct, reqd by autoconf */
1351.7Spk	struct evcnt sc_intrcnt;	/* event counter (for vmstat -i) */
1361.6Sthorpej
1371.6Sthorpej	struct callout sc_tick_ch;
1381.2Spk
1391.7Spk	struct xyc *xyc;		/* vaddr of vme registers */
1401.2Spk
1411.2Spk	struct xy_softc *sc_drives[XYC_MAXDEV]; /* drives on this controller */
1421.7Spk	int ipl;			/* interrupt level */
1431.7Spk	int vector;			/* interrupt vector */
1441.7Spk	bus_dma_tag_t dmatag;		/* Bus DMA tag */
1451.7Spk
1461.7Spk	struct xy_iorq *reqs;		/* i/o requests */
1471.7Spk	struct xy_iopb *iopbase;	/* iopb base addr (maps iopb->iorq) */
1481.7Spk	struct xy_iopb *dvmaiopb;	/* iopb base in DVMA space, not kvm */
1491.7Spk	bus_dmamap_t iopmap;		/* IOPB DMA handle */
1501.7Spk	bus_dmamap_t auxmap;		/* auxiliary DMA handle */
1511.1Spk
1521.7Spk	struct xy_iorq *ciorq;		/* controller's iorq */
1531.7Spk	struct xy_iopb *ciopb;		/* controller's iopb */
1541.1Spk
1551.7Spk	int xy_hand;			/* hand */
1561.2Spk	struct xy_iorq *xy_chain[XYC_MAXIOPB];
1571.7Spk					/* current chain */
1581.7Spk	int no_ols;			/* disable overlap seek for stupid 450s */
1591.1Spk};
1601.1Spk
1611.1Spk/*
1621.1Spk * reset blast modes
1631.1Spk */
1641.1Spk
1651.1Spk#define XY_RSET_NONE (struct xy_iorq *)(-1)   /* restart all requests */
1661.1Spk#define XY_RSET_ALL  (struct xy_iorq *)(-2)   /* don't restart anything */
167