/* $NetBSD: hp.c,v 1.54 2017/05/22 17:13:09 ragge Exp $ */
/*
* Copyright (c) 1996 Ludd, University of Lule}, Sweden.
* 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.
*/
/*
* Simple device driver routine for massbuss disks.
* TODO:
* Fix support for Standard DEC BAD144 bad block forwarding.
* Be able to to handle soft/hard transfer errors.
* Handle non-data transfer interrupts.
* Autoconfiguration of disk drives 'on the fly'.
* Handle disk media changes.
* Dual-port operations should be supported.
*/
struct hp_softc {
device_t sc_dev;
struct disk sc_disk;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
struct mba_device sc_md; /* Common struct used by mbaqueue. */
int sc_wlabel; /* Disklabel area is writable */
};
int hpmatch(device_t, cfdata_t, void *);
void hpattach(device_t, device_t, void *);
void hpstart(struct mba_device *);
int hpattn(struct mba_device *);
enum xfer_action hpfinish(struct mba_device *, int, int *);
/*
* Check if this is a disk drive; done by checking type from mbaattach.
*/
int
hpmatch(device_t parent, cfdata_t cf, void *aux)
{
struct mba_attach_args * const ma = aux;
if (cf->cf_loc[MBACF_DRIVE] != MBACF_DRIVE_DEFAULT &&
cf->cf_loc[MBACF_DRIVE] != ma->ma_unit)
return 0;
if (ma->ma_devtyp != MB_RP)
return 0;
return 1;
}
/*
* Disk drive found; fake a disklabel and try to read the real one.
* If the on-disk label can't be read; we lose.
*/
void
hpattach(device_t parent, device_t self, void *aux)
{
struct hp_softc * const sc = device_private(self);
struct mba_softc * const ms = device_private(parent);
struct mba_attach_args * const ma = aux;
struct disklabel *dl;
const char *msg;
/*
* Init the common struct for both the adapter and its slaves.
*/
bufq_alloc(&sc->sc_md.md_q, "disksort", BUFQ_SORT_CYLINDER);
sc->sc_md.md_softc = sc; /* Pointer to this softc */
sc->sc_md.md_mba = ms; /* Pointer to parent softc */
sc->sc_md.md_start = hpstart; /* Disk start routine */
sc->sc_md.md_attn = hpattn; /* Disk attention routine */
sc->sc_md.md_finish = hpfinish; /* Disk xfer finish routine */
int
hpclose(dev_t dev, int flag, int fmt, struct lwp *l)
{
struct hp_softc * const sc = device_lookup_private(&hp_cd, DISKUNIT(dev));
const int part = DISKPART(dev);
/*
* Called when a transfer is finished. Check if transfer went OK,
* Return info about what-to-do-now.
*/
enum xfer_action
hpfinish(struct mba_device *md, int mbasr, int *attn)
{
struct hp_softc * const sc = md->md_softc;
struct buf *bp = bufq_peek(md->md_q);
int er1, er2, bc;
unsigned byte;