1 /*        $NetBSD: mbavar.h,v 1.14 2017/05/22 17:13:09 ragge Exp $ */
2 /*
3  * Copyright (c) 1994 Ludd, University of Lule}, Sweden
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #include <sys/device.h>
28 #include <machine/scb.h>
29 
30 #define MBCR_INIT   1
31 #define   MBCR_IE             (1<<2)
32 #define   MBDS_DPR  (1<<8)
33 #define   MBSR_NED  (1<<18)
34 #define   MBDT_MOH  (1<<13)
35 #define   MBDT_TYPE 511
36 #define MBDT_TAP    (1<<14)
37 
38 #define   CLOSED              0
39 #define   WANTOPEN  1
40 #define   RDLABEL             2
41 #define   OPEN                3
42 #define   OPENRAW             4
43 
44 #define   MAXMBADEV 8         /* Max units per MBA */
45 
46 /*
47  * Devices that have different device drivers.
48  */
49 enum      mb_devices {
50           MB_UK,    /* unknown */
51           MB_RP,    /* RM/RP disk */
52           MB_TU,    /* TM03 based tape, ex. TU45 or TU77 */
53           MB_MT     /* TU78 tape */
54 };
55 
56 /*
57  * Current state of the adapter.
58  */
59 enum    sc_state {
60           SC_AUTOCONF,
61           SC_ACTIVE,
62           SC_IDLE
63 };
64 
65 /*
66  * Return value after a finished data transfer, from device driver.
67  */
68 enum      xfer_action {
69           XFER_RESTART,
70           XFER_FINISH
71 };
72 
73 /*
74  * Info passed do unit device driver during autoconfig.
75  */
76 struct    mba_attach_args {
77           int       ma_unit;
78         int         ma_type;
79           const char          *ma_name;
80           enum      mb_devices ma_devtyp;
81           bus_space_tag_t ma_iot;
82           bus_space_handle_t ma_ioh;
83 };
84 
85 /*
86  * Common struct used to communicate between the mba device driver
87  * and the unit device driver.
88  */
89 struct    mba_device {
90           STAILQ_ENTRY(mba_device) md_link; /* linked list of runnable devices */
91           void (*md_start)(struct mba_device *);
92                                         /* Start routine to be called by mbastart. */
93           int (*md_attn)(struct mba_device *);
94                                         /* Routine to be called after attn intr */
95           enum xfer_action (*md_finish)(struct mba_device *, int, int *);
96                                         /* Call after xfer finish */
97           void *md_softc;               /* Backpointer to this units softc. */
98           struct mba_softc *md_mba;
99           struct bufq_state *md_q;      /* queue of I/O requests */
100 };
101 
102 struct    mba_softc {
103           device_t sc_dev;
104           bus_space_tag_t sc_iot;
105           bus_space_handle_t sc_ioh;
106           STAILQ_HEAD(,mba_device) sc_xfers;
107           struct evcnt sc_intrcnt;
108           enum sc_state sc_state;
109           struct mba_device *sc_md[MAXMBADEV];
110 };
111 
112 struct  mbaunit {
113           int     nr;
114           const char    *name;
115           enum      mb_devices devtyp;
116 };
117 
118 /* Common prototypes */
119 void      mbaqueue(struct mba_device *);
120 
121