2002-10-02 20:02:08 +04:00
|
|
|
/* $NetBSD: hdc9224.c,v 1.23 2002/10/02 16:02:37 thorpej Exp $ */
|
1996-07-20 22:55:09 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1996 Ludd, University of Lule}, Sweden.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Ludd by Bertram Barth.
|
|
|
|
*
|
|
|
|
* 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 at Ludd, University of
|
|
|
|
* Lule}, Sweden and its contributors.
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* with much help from (in alphabetical order):
|
|
|
|
* Jeremy
|
|
|
|
* Roger Ivie
|
|
|
|
* Rick Macklem
|
|
|
|
* Mike Young
|
2000-06-25 20:00:43 +04:00
|
|
|
*
|
|
|
|
* Rewritten by Ragge 25 Jun 2000. New features:
|
|
|
|
* - Uses interrupts instead of polling to signal ready.
|
|
|
|
* - Can cooperate with the SCSI routines WRT. the DMA area.
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* - Floppy support missing.
|
|
|
|
* - Bad block forwarding missing.
|
|
|
|
* - Statistics collection.
|
1996-07-20 22:55:09 +04:00
|
|
|
*/
|
2000-06-25 20:00:43 +04:00
|
|
|
#undef RDDEBUG
|
1996-07-20 22:55:09 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/user.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/dkstat.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/disk.h>
|
|
|
|
#include <sys/syslog.h>
|
1997-03-15 19:32:16 +03:00
|
|
|
#include <sys/reboot.h>
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-29 11:07:52 +04:00
|
|
|
#include <uvm/uvm_extern.h>
|
2000-06-25 20:00:43 +04:00
|
|
|
|
|
|
|
#include <ufs/ufs/dinode.h> /* For BBSIZE */
|
|
|
|
#include <ufs/ffs/fs.h>
|
|
|
|
|
1996-07-20 22:55:09 +04:00
|
|
|
#include <machine/pte.h>
|
|
|
|
#include <machine/sid.h>
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/uvax.h>
|
|
|
|
#include <machine/ka410.h>
|
|
|
|
#include <machine/vsbus.h>
|
1997-03-15 19:32:16 +03:00
|
|
|
#include <machine/rpb.h>
|
2000-06-25 20:00:43 +04:00
|
|
|
#include <machine/scb.h>
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
#include <dev/mscp/mscp.h> /* For DEC disk encoding */
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
#include <vax/vsa/hdc9224.h>
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
#include "ioconf.h"
|
|
|
|
#include "locators.h"
|
1996-07-20 22:55:09 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* on-disk geometry block
|
|
|
|
*/
|
|
|
|
#define _aP __attribute__ ((packed)) /* force byte-alignment */
|
|
|
|
struct rdgeom {
|
2000-06-25 20:00:43 +04:00
|
|
|
char mbz[10]; /* 10 bytes of zero */
|
|
|
|
long xbn_count _aP; /* number of XBNs */
|
|
|
|
long dbn_count _aP; /* number of DBNs */
|
|
|
|
long lbn_count _aP; /* number of LBNs (Logical-Block-Numbers) */
|
|
|
|
long rbn_count _aP; /* number of RBNs (Replacement-Block-Numbers) */
|
|
|
|
short nspt; /* number of sectors per track */
|
|
|
|
short ntracks; /* number of tracks */
|
|
|
|
short ncylinders; /* number of cylinders */
|
|
|
|
short precomp; /* first cylinder for write precompensation */
|
|
|
|
short reduced; /* first cylinder for reduced write current */
|
|
|
|
short seek_rate; /* seek rate or zero for buffered seeks */
|
|
|
|
short crc_eec; /* 0 if CRC, 1 if ECC is being used */
|
|
|
|
short rct; /* "replacement control table" (RCT) */
|
|
|
|
short rct_ncopies; /* number of copies of the RCT */
|
|
|
|
long media_id _aP; /* media identifier */
|
|
|
|
short interleave; /* sector-to-sector interleave */
|
|
|
|
short headskew; /* head-to-head skew */
|
|
|
|
short cylskew; /* cylinder-to-cylinder skew */
|
|
|
|
short gap0_size; /* size of GAP 0 in the MFM format */
|
|
|
|
short gap1_size; /* size of GAP 1 in the MFM format */
|
|
|
|
short gap2_size; /* size of GAP 2 in the MFM format */
|
|
|
|
short gap3_size; /* size of GAP 3 in the MFM format */
|
|
|
|
short sync_value; /* sync value used when formatting */
|
|
|
|
char reserved[32]; /* reserved for use by the RQDX formatter */
|
|
|
|
short serial_number; /* serial number */
|
1996-07-20 22:55:09 +04:00
|
|
|
#if 0 /* we don't need these 412 useless bytes ... */
|
2000-06-25 20:00:43 +04:00
|
|
|
char fill[412-2]; /* Filler bytes to the end of the block */
|
|
|
|
short checksum; /* checksum over the XBN */
|
1996-07-20 22:55:09 +04:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Software status
|
|
|
|
*/
|
|
|
|
struct rdsoftc {
|
2000-06-25 20:00:43 +04:00
|
|
|
struct device sc_dev; /* must be here! (pseudo-OOP:) */
|
|
|
|
struct disk sc_disk; /* disklabel etc. */
|
|
|
|
struct rdgeom sc_xbn; /* on-disk geometry information */
|
|
|
|
int sc_drive; /* physical unit number */
|
1996-07-20 22:55:09 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct hdcsoftc {
|
|
|
|
struct device sc_dev; /* must be here (pseudo-OOP:) */
|
2000-06-25 20:00:43 +04:00
|
|
|
struct evcnt sc_intrcnt;
|
|
|
|
struct vsbus_dma sc_vd;
|
|
|
|
vaddr_t sc_regs; /* register addresses */
|
2002-07-23 01:48:36 +04:00
|
|
|
struct bufq_state sc_q;
|
2000-06-25 20:00:43 +04:00
|
|
|
struct buf *sc_active;
|
1996-07-20 22:55:09 +04:00
|
|
|
struct hdc9224_UDCreg sc_creg; /* (command) registers to be written */
|
|
|
|
struct hdc9224_UDCreg sc_sreg; /* (status) registers being read */
|
2000-06-25 20:00:43 +04:00
|
|
|
caddr_t sc_dmabase; /* */
|
|
|
|
int sc_dmasize;
|
|
|
|
caddr_t sc_bufaddr; /* Current in-core address */
|
|
|
|
int sc_diskblk; /* Current block on disk */
|
|
|
|
int sc_bytecnt; /* How much left to transfer */
|
|
|
|
int sc_xfer; /* Current transfer size */
|
2000-06-27 22:46:17 +04:00
|
|
|
int sc_retries;
|
2000-06-25 20:00:43 +04:00
|
|
|
volatile u_char sc_status; /* last status from interrupt */
|
2000-06-27 22:46:17 +04:00
|
|
|
char sc_intbit;
|
2000-06-25 20:00:43 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct hdc_attach_args {
|
|
|
|
int ha_drive;
|
1996-07-20 22:55:09 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2000-06-25 20:00:43 +04:00
|
|
|
* prototypes for (almost) all the internal routines
|
1996-07-20 22:55:09 +04:00
|
|
|
*/
|
2000-06-25 20:00:43 +04:00
|
|
|
static int hdcmatch(struct device *, struct cfdata *, void *);
|
|
|
|
static void hdcattach(struct device *, struct device *, void *);
|
|
|
|
static int hdcprint(void *, const char *);
|
|
|
|
static int rdmatch(struct device *, struct cfdata *, void *);
|
|
|
|
static void rdattach(struct device *, struct device *, void *);
|
|
|
|
static void hdcintr(void *);
|
|
|
|
static int hdc_command(struct hdcsoftc *, int);
|
|
|
|
static void rd_readgeom(struct hdcsoftc *, struct rdsoftc *);
|
|
|
|
#ifdef RDDEBUG
|
|
|
|
static void hdc_printgeom( struct rdgeom *);
|
|
|
|
#endif
|
|
|
|
static void hdc_writeregs(struct hdcsoftc *);
|
|
|
|
static void hdcstart(struct hdcsoftc *, struct buf *);
|
|
|
|
static int hdc_rdselect(struct hdcsoftc *, int);
|
|
|
|
static void rdmakelabel(struct disklabel *, struct rdgeom *);
|
|
|
|
static void hdc_writeregs(struct hdcsoftc *);
|
|
|
|
static void hdc_readregs(struct hdcsoftc *);
|
|
|
|
static void hdc_qstart(void *);
|
|
|
|
|
2002-10-01 09:18:59 +04:00
|
|
|
CFATTACH_DECL(hdc, sizeof(struct hdcsoftc),
|
2002-10-02 20:02:08 +04:00
|
|
|
hdcmatch, hdcattach, NULL, NULL);
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2002-10-01 09:18:59 +04:00
|
|
|
CFATTACH_DECL(rd, sizeof(struct rdsoftc),
|
2002-10-02 20:02:08 +04:00
|
|
|
rdmatch, rdattach, NULL, NULL);
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dev_type_open(rdopen);
|
|
|
|
dev_type_close(rdclose);
|
|
|
|
dev_type_read(rdread);
|
|
|
|
dev_type_write(rdwrite);
|
|
|
|
dev_type_ioctl(rdioctl);
|
|
|
|
dev_type_strategy(rdstrategy);
|
|
|
|
dev_type_size(rdsize);
|
|
|
|
|
|
|
|
const struct bdevsw rd_bdevsw = {
|
|
|
|
rdopen, rdclose, rdstrategy, rdioctl, nulldump, rdsize, D_DISK
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct cdevsw rd_cdevsw = {
|
|
|
|
rdopen, rdclose, rdread, rdwrite, rdioctl,
|
|
|
|
nostop, notty, nopoll, nommap, D_DISK
|
|
|
|
};
|
1998-01-12 23:52:29 +03:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
/* At least 0.7 uS between register accesses */
|
|
|
|
static int rd_dmasize, inq = 0;
|
|
|
|
static int u;
|
2001-11-09 08:31:44 +03:00
|
|
|
#define WAIT asm("movl %0,%0;movl %0,%0;movl %0,%0; movl %0,%0" :: "m"(u))
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
#define HDC_WREG(x) *(volatile char *)(sc->sc_regs) = (x)
|
|
|
|
#define HDC_RREG *(volatile char *)(sc->sc_regs)
|
|
|
|
#define HDC_WCMD(x) *(volatile char *)(sc->sc_regs + 4) = (x)
|
|
|
|
#define HDC_RSTAT *(volatile char *)(sc->sc_regs + 4)
|
1996-07-20 22:55:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* new-config's hdcmatch() is similiar to old-config's hdcprobe(),
|
|
|
|
* thus we probe for the existence of the controller and reset it.
|
|
|
|
* NB: we can't initialize the controller yet, since space for hdcsoftc
|
|
|
|
* is not yet allocated. Thus we do this in hdcattach()...
|
|
|
|
*/
|
|
|
|
int
|
2000-06-25 20:00:43 +04:00
|
|
|
hdcmatch(struct device *parent, struct cfdata *cf, void *aux)
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
2000-06-25 20:00:43 +04:00
|
|
|
struct vsbus_attach_args *va = aux;
|
|
|
|
volatile char *hdc_csr = (char *)va->va_addr;
|
|
|
|
int i;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
u = 8; /* !!! - GCC */
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
if (vax_boardtype == VAX_BTYP_49 || vax_boardtype == VAX_BTYP_46
|
2001-02-04 23:36:26 +03:00
|
|
|
|| vax_boardtype == VAX_BTYP_48 || vax_boardtype == VAX_BTYP_53)
|
2000-06-25 20:00:43 +04:00
|
|
|
return 0;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
hdc_csr[4] = DKC_CMD_RESET; /* reset chip */
|
|
|
|
for (i = 0; i < 1000; i++) {
|
|
|
|
DELAY(1000);
|
|
|
|
if (hdc_csr[4] & DKC_ST_DONE)
|
|
|
|
break;
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
2000-06-25 20:00:43 +04:00
|
|
|
if (i == 100)
|
|
|
|
return 0; /* No response to reset */
|
|
|
|
|
|
|
|
hdc_csr[4] = DKC_CMD_SETREGPTR|UDC_TERM;
|
|
|
|
WAIT;
|
|
|
|
hdc_csr[0] = UDC_TC_CRCPRE|UDC_TC_INTDONE;
|
|
|
|
WAIT;
|
|
|
|
hdc_csr[4] = DKC_CMD_DRDESELECT; /* Should be harmless */
|
|
|
|
DELAY(1000);
|
1996-07-20 22:55:09 +04:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-06-25 20:00:43 +04:00
|
|
|
hdcprint(void *aux, const char *name)
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
|
|
|
struct hdc_attach_args *ha = aux;
|
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
if (name)
|
|
|
|
printf ("RD?? at %s drive %d", name, ha->ha_drive);
|
|
|
|
return UNCONF;
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hdc_attach() probes for all possible devices
|
|
|
|
*/
|
|
|
|
void
|
2000-06-25 20:00:43 +04:00
|
|
|
hdcattach(struct device *parent, struct device *self, void *aux)
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
2000-06-25 20:00:43 +04:00
|
|
|
struct vsbus_attach_args *va = aux;
|
|
|
|
struct hdcsoftc *sc = (void *)self;
|
1996-07-20 22:55:09 +04:00
|
|
|
struct hdc_attach_args ha;
|
2000-06-25 20:00:43 +04:00
|
|
|
int status, i;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
1996-10-13 07:29:05 +04:00
|
|
|
printf ("\n");
|
1996-07-20 22:55:09 +04:00
|
|
|
/*
|
2000-06-25 20:00:43 +04:00
|
|
|
* Get interrupt vector, enable instrumentation.
|
1996-07-20 22:55:09 +04:00
|
|
|
*/
|
2000-06-25 20:00:43 +04:00
|
|
|
scb_vecalloc(va->va_cvec, hdcintr, sc, SCB_ISTACK, &sc->sc_intrcnt);
|
|
|
|
evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
|
|
|
|
self->dv_xname, "intr");
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
sc->sc_regs = vax_map_physmem(va->va_paddr, 1);
|
|
|
|
sc->sc_dmabase = (caddr_t)va->va_dmaaddr;
|
|
|
|
sc->sc_dmasize = va->va_dmasize;
|
2000-06-27 22:46:17 +04:00
|
|
|
sc->sc_intbit = va->va_maskno;
|
2000-06-25 20:00:43 +04:00
|
|
|
rd_dmasize = min(MAXPHYS, sc->sc_dmasize); /* Used in rd_minphys */
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
sc->sc_vd.vd_go = hdc_qstart;
|
|
|
|
sc->sc_vd.vd_arg = sc;
|
1996-07-20 22:55:09 +04:00
|
|
|
/*
|
2000-06-25 20:00:43 +04:00
|
|
|
* Reset controller.
|
1996-07-20 22:55:09 +04:00
|
|
|
*/
|
2000-06-25 20:00:43 +04:00
|
|
|
HDC_WCMD(DKC_CMD_RESET);
|
|
|
|
DELAY(1000);
|
|
|
|
status = HDC_RSTAT;
|
|
|
|
if (status != (DKC_ST_DONE|DKC_TC_SUCCESS)) {
|
|
|
|
printf("%s: RESET failed, status 0x%x\n",
|
|
|
|
sc->sc_dev.dv_xname, status);
|
|
|
|
return;
|
|
|
|
}
|
2002-07-23 01:48:36 +04:00
|
|
|
bufq_alloc(&sc->sc_q, BUFQ_DISKSORT|BUFQ_SORT_CYLINDER);
|
1996-07-20 22:55:09 +04:00
|
|
|
|
|
|
|
/*
|
2000-06-25 20:00:43 +04:00
|
|
|
* now probe for all possible hard drives
|
1996-07-20 22:55:09 +04:00
|
|
|
*/
|
2000-06-25 20:00:43 +04:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (i == 2) /* Floppy, needs special handling */
|
|
|
|
continue;
|
|
|
|
HDC_WCMD(DKC_CMD_DRSELECT | i);
|
|
|
|
DELAY(1000);
|
|
|
|
status = HDC_RSTAT;
|
|
|
|
ha.ha_drive = i;
|
|
|
|
if ((status & DKC_ST_TERMCOD) == DKC_TC_SUCCESS)
|
|
|
|
config_found(self, (void *)&ha, hdcprint);
|
|
|
|
}
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rdmatch() probes for the existence of a RD-type disk/floppy
|
|
|
|
*/
|
|
|
|
int
|
1998-01-24 17:16:11 +03:00
|
|
|
rdmatch(parent, cf, aux)
|
1996-07-20 22:55:09 +04:00
|
|
|
struct device *parent;
|
1998-01-24 17:16:11 +03:00
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
|
|
|
struct hdc_attach_args *ha = aux;
|
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
if (cf->cf_loc[HDCCF_DRIVE] != HDCCF_DRIVE_DEFAULT &&
|
|
|
|
cf->cf_loc[HDCCF_DRIVE] != ha->ha_drive)
|
|
|
|
return 0;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
if (ha->ha_drive == 2) /* Always floppy, not supported */
|
|
|
|
return 0;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
return 1;
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-06-25 20:00:43 +04:00
|
|
|
rdattach(struct device *parent, struct device *self, void *aux)
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
2000-06-25 20:00:43 +04:00
|
|
|
struct hdcsoftc *sc = (void*)parent;
|
1996-07-20 22:55:09 +04:00
|
|
|
struct rdsoftc *rd = (void*)self;
|
|
|
|
struct hdc_attach_args *ha = aux;
|
2000-06-25 20:00:43 +04:00
|
|
|
struct disklabel *dl;
|
|
|
|
char *msg;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
|
|
|
rd->sc_drive = ha->ha_drive;
|
|
|
|
/*
|
|
|
|
* Initialize and attach the disk structure.
|
|
|
|
*/
|
2000-06-25 20:00:43 +04:00
|
|
|
rd->sc_disk.dk_name = rd->sc_dev.dv_xname;
|
|
|
|
disk_attach(&rd->sc_disk);
|
|
|
|
|
1996-07-20 22:55:09 +04:00
|
|
|
/*
|
|
|
|
* if it's not a floppy then evaluate the on-disk geometry.
|
2001-07-26 19:05:07 +04:00
|
|
|
* if necessary correct the label...
|
1996-07-20 22:55:09 +04:00
|
|
|
*/
|
2000-06-25 20:00:43 +04:00
|
|
|
rd_readgeom(sc, rd);
|
|
|
|
disk_printtype(rd->sc_drive, rd->sc_xbn.media_id);
|
|
|
|
dl = rd->sc_disk.dk_label;
|
|
|
|
rdmakelabel(dl, &rd->sc_xbn);
|
|
|
|
printf("%s", rd->sc_dev.dv_xname);
|
2002-09-06 17:18:43 +04:00
|
|
|
msg = readdisklabel(MAKEDISKDEV(cdevsw_lookup_major(&rd_cdevsw),
|
|
|
|
rd->sc_dev.dv_unit, RAW_PART),
|
|
|
|
rdstrategy, dl, NULL);
|
2000-06-25 20:00:43 +04:00
|
|
|
if (msg)
|
|
|
|
printf(": %s", msg);
|
|
|
|
printf(": size %d sectors\n", dl->d_secperunit);
|
|
|
|
#ifdef RDDEBUG
|
|
|
|
hdc_printgeom(&rd->sc_xbn);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
hdcintr(void *arg)
|
|
|
|
{
|
|
|
|
struct hdcsoftc *sc = arg;
|
|
|
|
struct buf *bp;
|
|
|
|
|
|
|
|
sc->sc_status = HDC_RSTAT;
|
|
|
|
if (sc->sc_active == 0)
|
|
|
|
return; /* Complain? */
|
|
|
|
|
|
|
|
if ((sc->sc_status & (DKC_ST_INTPEND|DKC_ST_DONE)) !=
|
|
|
|
(DKC_ST_INTPEND|DKC_ST_DONE))
|
|
|
|
return; /* Why spurious ints sometimes??? */
|
|
|
|
|
|
|
|
bp = sc->sc_active;
|
|
|
|
sc->sc_active = 0;
|
|
|
|
if ((sc->sc_status & DKC_ST_TERMCOD) != DKC_TC_SUCCESS) {
|
|
|
|
int i;
|
|
|
|
u_char *g = (u_char *)&sc->sc_sreg;
|
2000-06-27 22:46:17 +04:00
|
|
|
|
|
|
|
if (sc->sc_retries++ < 3) { /* Allow 3 retries */
|
|
|
|
hdcstart(sc, bp);
|
|
|
|
return;
|
|
|
|
}
|
2000-06-25 20:00:43 +04:00
|
|
|
printf("%s: failed, status 0x%x\n",
|
|
|
|
sc->sc_dev.dv_xname, sc->sc_status);
|
|
|
|
hdc_readregs(sc);
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
printf("%i: %x\n", i, g[i]);
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = ENXIO;
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
biodone(bp);
|
|
|
|
vsbus_dma_intr();
|
|
|
|
return;
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
2000-06-25 20:00:43 +04:00
|
|
|
|
|
|
|
if (bp->b_flags & B_READ) {
|
|
|
|
vsbus_copytoproc(bp->b_proc, sc->sc_dmabase, sc->sc_bufaddr,
|
|
|
|
sc->sc_xfer);
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
2000-06-27 22:46:17 +04:00
|
|
|
sc->sc_diskblk += (sc->sc_xfer/DEV_BSIZE);
|
|
|
|
sc->sc_bytecnt -= sc->sc_xfer;
|
2000-06-25 20:00:43 +04:00
|
|
|
sc->sc_bufaddr += sc->sc_xfer;
|
|
|
|
|
|
|
|
if (sc->sc_bytecnt == 0) { /* Finished transfer */
|
|
|
|
biodone(bp);
|
|
|
|
vsbus_dma_intr();
|
|
|
|
} else
|
|
|
|
hdcstart(sc, bp);
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-06-25 20:00:43 +04:00
|
|
|
*
|
1996-07-20 22:55:09 +04:00
|
|
|
*/
|
|
|
|
void
|
2000-06-25 20:00:43 +04:00
|
|
|
rdstrategy(struct buf *bp)
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
2000-06-25 20:00:43 +04:00
|
|
|
struct rdsoftc *rd;
|
|
|
|
struct hdcsoftc *sc;
|
|
|
|
struct disklabel *lp;
|
|
|
|
int unit, s;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
unit = DISKUNIT(bp->b_dev);
|
|
|
|
if (unit > rd_cd.cd_ndevs || (rd = rd_cd.cd_devs[unit]) == NULL) {
|
|
|
|
bp->b_error = ENXIO;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
sc = (void *)rd->sc_dev.dv_parent;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
lp = rd->sc_disk.dk_label;
|
|
|
|
if ((bounds_check_with_label(bp, lp, 1)) <= 0)
|
|
|
|
goto done;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
|
|
|
if (bp->b_bcount == 0)
|
|
|
|
goto done;
|
1997-03-09 18:55:58 +03:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
bp->b_rawblkno =
|
|
|
|
bp->b_blkno + lp->d_partitions[DISKPART(bp->b_dev)].p_offset;
|
|
|
|
bp->b_cylinder = bp->b_rawblkno / lp->d_secpercyl;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2001-04-12 22:34:56 +04:00
|
|
|
s = splbio();
|
2002-07-23 01:48:36 +04:00
|
|
|
BUFQ_PUT(&sc->sc_q, bp);
|
2000-06-25 20:00:43 +04:00
|
|
|
if (inq == 0) {
|
|
|
|
inq = 1;
|
|
|
|
vsbus_dma_start(&sc->sc_vd);
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
|
|
|
|
done: biodone(bp);
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
void
|
|
|
|
hdc_qstart(void *arg)
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
2000-06-25 20:00:43 +04:00
|
|
|
struct hdcsoftc *sc = arg;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
inq = 0;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
hdcstart(sc, 0);
|
2002-07-23 01:48:36 +04:00
|
|
|
if (BUFQ_PEEK(&sc->sc_q)) {
|
2000-06-25 20:00:43 +04:00
|
|
|
vsbus_dma_start(&sc->sc_vd); /* More to go */
|
|
|
|
inq = 1;
|
|
|
|
}
|
|
|
|
}
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
void
|
|
|
|
hdcstart(struct hdcsoftc *sc, struct buf *ob)
|
|
|
|
{
|
|
|
|
struct hdc9224_UDCreg *p = &sc->sc_creg;
|
|
|
|
struct disklabel *lp;
|
|
|
|
struct rdsoftc *rd;
|
|
|
|
struct buf *bp;
|
|
|
|
int cn, sn, tn, bn, blks;
|
2000-06-27 22:46:17 +04:00
|
|
|
volatile char ch;
|
2000-06-25 20:00:43 +04:00
|
|
|
|
|
|
|
if (sc->sc_active)
|
|
|
|
return; /* Already doing something */
|
|
|
|
|
|
|
|
|
|
|
|
if (ob == 0) {
|
2002-07-23 01:48:36 +04:00
|
|
|
bp = BUFQ_GET(&sc->sc_q);
|
2000-06-25 20:00:43 +04:00
|
|
|
if (bp == NULL)
|
|
|
|
return; /* Nothing to do */
|
|
|
|
sc->sc_bufaddr = bp->b_data;
|
|
|
|
sc->sc_diskblk = bp->b_rawblkno;
|
|
|
|
sc->sc_bytecnt = bp->b_bcount;
|
2000-06-27 22:46:17 +04:00
|
|
|
sc->sc_retries = 0;
|
2000-06-25 20:00:43 +04:00
|
|
|
bp->b_resid = 0;
|
|
|
|
} else
|
|
|
|
bp = ob;
|
|
|
|
|
|
|
|
rd = rd_cd.cd_devs[DISKUNIT(bp->b_dev)];
|
|
|
|
hdc_rdselect(sc, rd->sc_drive);
|
|
|
|
sc->sc_active = bp;
|
|
|
|
|
|
|
|
bn = sc->sc_diskblk;
|
|
|
|
lp = rd->sc_disk.dk_label;
|
|
|
|
if (bn) {
|
|
|
|
cn = bn / lp->d_secpercyl;
|
|
|
|
sn = bn % lp->d_secpercyl;
|
|
|
|
tn = sn / lp->d_nsectors;
|
|
|
|
sn = sn % lp->d_nsectors;
|
|
|
|
} else
|
|
|
|
cn = sn = tn = 0;
|
|
|
|
|
|
|
|
cn++; /* first cylinder is reserved */
|
|
|
|
|
|
|
|
bzero(p, sizeof(struct hdc9224_UDCreg));
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
/*
|
|
|
|
* Tricky thing: the controller do itself only increase the sector
|
|
|
|
* number, not the track or cylinder number. Therefore the driver
|
|
|
|
* is not allowed to have transfers that crosses track boundaries.
|
|
|
|
*/
|
|
|
|
blks = sc->sc_bytecnt/DEV_BSIZE;
|
|
|
|
if ((sn + blks) > lp->d_nsectors)
|
|
|
|
blks = lp->d_nsectors - sn;
|
|
|
|
|
|
|
|
p->udc_dsect = sn;
|
|
|
|
p->udc_dcyl = cn & 0xff;
|
|
|
|
p->udc_dhead = ((cn >> 4) & 0x70) | tn;
|
|
|
|
p->udc_scnt = blks;
|
|
|
|
|
|
|
|
p->udc_rtcnt = UDC_RC_RTRYCNT;
|
|
|
|
p->udc_mode = UDC_MD_HDD;
|
|
|
|
p->udc_term = UDC_TC_CRCPRE|UDC_TC_INTDONE|UDC_TC_TDELDAT|UDC_TC_TWRFLT;
|
|
|
|
hdc_writeregs(sc);
|
|
|
|
|
|
|
|
/* Count up vars */
|
|
|
|
sc->sc_xfer = blks * DEV_BSIZE;
|
2000-06-27 22:46:17 +04:00
|
|
|
|
|
|
|
ch = HDC_RSTAT; /* Avoid pending interrupts */
|
|
|
|
WAIT;
|
|
|
|
vsbus_clrintr(sc->sc_intbit); /* Clear pending int's */
|
2000-06-25 20:00:43 +04:00
|
|
|
|
|
|
|
if (bp->b_flags & B_READ) {
|
|
|
|
HDC_WCMD(DKC_CMD_READ_HDD);
|
|
|
|
} else {
|
|
|
|
vsbus_copyfromproc(bp->b_proc, sc->sc_bufaddr, sc->sc_dmabase,
|
|
|
|
sc->sc_xfer);
|
|
|
|
HDC_WCMD(DKC_CMD_WRITE_HDD);
|
|
|
|
}
|
|
|
|
}
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
void
|
|
|
|
rd_readgeom(struct hdcsoftc *sc, struct rdsoftc *rd)
|
|
|
|
{
|
|
|
|
struct hdc9224_UDCreg *p = &sc->sc_creg;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
hdc_rdselect(sc, rd->sc_drive); /* select drive right now */
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
bzero(p, sizeof(struct hdc9224_UDCreg));
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
p->udc_scnt = 1;
|
|
|
|
p->udc_rtcnt = UDC_RC_RTRYCNT;
|
|
|
|
p->udc_mode = UDC_MD_HDD;
|
|
|
|
p->udc_term = UDC_TC_CRCPRE|UDC_TC_INTDONE|UDC_TC_TDELDAT|UDC_TC_TWPROT;
|
|
|
|
hdc_writeregs(sc);
|
|
|
|
sc->sc_status = 0;
|
|
|
|
HDC_WCMD(DKC_CMD_READ_HDD|2);
|
|
|
|
while ((sc->sc_status & DKC_ST_INTPEND) == 0)
|
|
|
|
;
|
|
|
|
bcopy(sc->sc_dmabase, &rd->sc_xbn, sizeof(struct rdgeom));
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
#ifdef RDDEBUG
|
1996-07-20 22:55:09 +04:00
|
|
|
/*
|
|
|
|
* display the contents of the on-disk geometry structure
|
|
|
|
*/
|
1998-04-13 16:15:56 +04:00
|
|
|
void
|
1996-07-20 22:55:09 +04:00
|
|
|
hdc_printgeom(p)
|
|
|
|
struct rdgeom *p;
|
|
|
|
{
|
1998-04-13 16:15:56 +04:00
|
|
|
printf ("**DiskData** XBNs: %ld, DBNs: %ld, LBNs: %ld, RBNs: %ld\n",
|
1996-07-20 22:55:09 +04:00
|
|
|
p->xbn_count, p->dbn_count, p->lbn_count, p->rbn_count);
|
1996-10-13 07:29:05 +04:00
|
|
|
printf ("sec/track: %d, tracks: %d, cyl: %d, precomp/reduced: %d/%d\n",
|
1996-07-20 22:55:09 +04:00
|
|
|
p->nspt, p->ntracks, p->ncylinders, p->precomp, p->reduced);
|
1996-10-13 07:29:05 +04:00
|
|
|
printf ("seek-rate: %d, crc/eec: %s, RCT: %d, RCT-copies: %d\n",
|
1996-07-20 22:55:09 +04:00
|
|
|
p->seek_rate, p->crc_eec?"EEC":"CRC", p->rct, p->rct_ncopies);
|
2000-06-25 20:00:43 +04:00
|
|
|
printf ("media-ID: %lx, interleave: %d, headskew: %d, cylskew: %d\n",
|
|
|
|
p->media_id, p->interleave, p->headskew, p->cylskew);
|
1996-10-13 07:29:05 +04:00
|
|
|
printf ("gap0: %d, gap1: %d, gap2: %d, gap3: %d, sync-value: %d\n",
|
1996-07-20 22:55:09 +04:00
|
|
|
p->gap0_size, p->gap1_size, p->gap2_size, p->gap3_size,
|
|
|
|
p->sync_value);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the size of a partition, if known, or -1 if not.
|
|
|
|
*/
|
1998-04-13 16:15:56 +04:00
|
|
|
int
|
2000-06-25 20:00:43 +04:00
|
|
|
rdsize(dev_t dev)
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
2000-06-25 20:00:43 +04:00
|
|
|
struct rdsoftc *rd;
|
|
|
|
int unit = DISKUNIT(dev);
|
1996-07-20 22:55:09 +04:00
|
|
|
int size;
|
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
if (unit >= rd_cd.cd_ndevs || rd_cd.cd_devs[unit] == 0)
|
|
|
|
return -1;
|
|
|
|
rd = rd_cd.cd_devs[unit];
|
|
|
|
size = rd->sc_disk.dk_label->d_partitions[DISKPART(dev)].p_size *
|
|
|
|
(rd->sc_disk.dk_label->d_secsize / DEV_BSIZE);
|
1996-07-20 22:55:09 +04:00
|
|
|
|
|
|
|
return (size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int
|
2000-06-25 20:00:43 +04:00
|
|
|
rdopen(dev_t dev, int flag, int fmt, struct proc *p)
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
|
|
|
struct rdsoftc *rd;
|
2000-06-25 20:00:43 +04:00
|
|
|
int unit, part;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
unit = DISKUNIT(dev);
|
|
|
|
if (unit >= rd_cd.cd_ndevs)
|
1996-07-20 22:55:09 +04:00
|
|
|
return ENXIO;
|
|
|
|
rd = rd_cd.cd_devs[unit];
|
2000-06-25 20:00:43 +04:00
|
|
|
if (rd == 0)
|
|
|
|
return ENXIO;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
part = DISKPART(dev);
|
|
|
|
if (part >= rd->sc_disk.dk_label->d_npartitions)
|
|
|
|
return ENXIO;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
switch (fmt) {
|
|
|
|
case S_IFCHR:
|
|
|
|
rd->sc_disk.dk_copenmask |= (1 << part);
|
|
|
|
break;
|
|
|
|
case S_IFBLK:
|
|
|
|
rd->sc_disk.dk_bopenmask |= (1 << part);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rd->sc_disk.dk_openmask =
|
|
|
|
rd->sc_disk.dk_copenmask | rd->sc_disk.dk_bopenmask;
|
|
|
|
|
|
|
|
return 0;
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int
|
2000-06-25 20:00:43 +04:00
|
|
|
rdclose(dev_t dev, int flag, int fmt, struct proc *p)
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
2000-06-25 20:00:43 +04:00
|
|
|
struct rdsoftc *rd;
|
|
|
|
int part;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
rd = rd_cd.cd_devs[DISKUNIT(dev)];
|
|
|
|
part = DISKPART(dev);
|
|
|
|
|
|
|
|
switch (fmt) {
|
|
|
|
case S_IFCHR:
|
|
|
|
rd->sc_disk.dk_copenmask &= ~(1 << part);
|
|
|
|
break;
|
|
|
|
case S_IFBLK:
|
|
|
|
rd->sc_disk.dk_bopenmask &= ~(1 << part);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rd->sc_disk.dk_openmask =
|
|
|
|
rd->sc_disk.dk_copenmask | rd->sc_disk.dk_bopenmask;
|
|
|
|
|
|
|
|
return (0);
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int
|
2000-06-25 20:00:43 +04:00
|
|
|
rdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
2000-06-25 20:00:43 +04:00
|
|
|
struct rdsoftc *rd = rd_cd.cd_devs[DISKUNIT(dev)];
|
|
|
|
struct disklabel *lp = rd->sc_disk.dk_label;
|
|
|
|
int err = 0;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case DIOCGDINFO:
|
2000-06-25 20:00:43 +04:00
|
|
|
bcopy(lp, addr, sizeof (struct disklabel));
|
|
|
|
break;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
|
|
|
case DIOCGPART:
|
2000-06-25 20:00:43 +04:00
|
|
|
((struct partinfo *)addr)->disklab = lp;
|
|
|
|
((struct partinfo *)addr)->part =
|
|
|
|
&lp->d_partitions[DISKPART(dev)];
|
|
|
|
break;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
|
|
|
case DIOCWDINFO:
|
|
|
|
case DIOCSDINFO:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return EBADF;
|
2000-06-25 20:00:43 +04:00
|
|
|
else
|
|
|
|
err = (cmd == DIOCSDINFO ?
|
|
|
|
setdisklabel(lp, (struct disklabel *)addr, 0, 0) :
|
|
|
|
writedisklabel(dev, rdstrategy, lp, 0));
|
|
|
|
break;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
case DIOCGDEFLABEL:
|
|
|
|
bzero(lp, sizeof(struct disklabel));
|
|
|
|
rdmakelabel(lp, &rd->sc_xbn);
|
|
|
|
break;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
|
|
|
case DIOCWLABEL:
|
|
|
|
if ((flag & FWRITE) == 0)
|
2000-06-25 20:00:43 +04:00
|
|
|
err = EBADF;
|
|
|
|
break;
|
|
|
|
|
1996-07-20 22:55:09 +04:00
|
|
|
default:
|
2000-06-25 20:00:43 +04:00
|
|
|
err = ENOTTY;
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
2000-06-25 20:00:43 +04:00
|
|
|
return err;
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int
|
2000-06-25 20:00:43 +04:00
|
|
|
rdread(dev_t dev, struct uio *uio, int flag)
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
2000-06-25 20:00:43 +04:00
|
|
|
return (physio (rdstrategy, NULL, dev, B_READ, minphys, uio));
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int
|
2000-06-25 20:00:43 +04:00
|
|
|
rdwrite(dev_t dev, struct uio *uio, int flag)
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
2000-06-25 20:00:43 +04:00
|
|
|
return (physio (rdstrategy, NULL, dev, B_WRITE, minphys, uio));
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we have to wait 0.7 usec between two accesses to any of the
|
|
|
|
* dkc-registers, on a VS2000 with 1 MIPS, this is roughly one
|
|
|
|
* instruction. Thus the loop-overhead will be enough...
|
|
|
|
*/
|
2000-06-25 20:00:43 +04:00
|
|
|
static void
|
|
|
|
hdc_readregs(struct hdcsoftc *sc)
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *p;
|
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
HDC_WCMD(DKC_CMD_SETREGPTR);
|
|
|
|
WAIT;
|
1996-07-20 22:55:09 +04:00
|
|
|
p = (void*)&sc->sc_sreg;
|
2000-06-25 20:00:43 +04:00
|
|
|
for (i=0; i<10; i++) {
|
|
|
|
*p++ = HDC_RREG; /* dkc_reg auto-increments */
|
|
|
|
WAIT;
|
|
|
|
}
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
static void
|
|
|
|
hdc_writeregs(struct hdcsoftc *sc)
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *p;
|
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
HDC_WCMD(DKC_CMD_SETREGPTR);
|
1996-07-20 22:55:09 +04:00
|
|
|
p = (void*)&sc->sc_creg;
|
2000-06-25 20:00:43 +04:00
|
|
|
for (i=0; i<10; i++) {
|
|
|
|
HDC_WREG(*p++); /* dkc_reg auto-increments */
|
|
|
|
WAIT;
|
|
|
|
}
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hdc_command() issues a command and polls the intreq-register
|
|
|
|
* to find when command has completed
|
|
|
|
*/
|
|
|
|
int
|
2000-06-25 20:00:43 +04:00
|
|
|
hdc_command(struct hdcsoftc *sc, int cmd)
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
|
|
|
hdc_writeregs(sc); /* write the prepared registers */
|
2000-06-25 20:00:43 +04:00
|
|
|
HDC_WCMD(cmd);
|
|
|
|
WAIT;
|
1996-07-20 22:55:09 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-06-25 20:00:43 +04:00
|
|
|
hdc_rdselect(struct hdcsoftc *sc, int unit)
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
2000-06-25 20:00:43 +04:00
|
|
|
struct hdc9224_UDCreg *p = &sc->sc_creg;
|
1996-07-20 22:55:09 +04:00
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bring "creg" in some known-to-work state and
|
|
|
|
* select the drive with the DRIVE SELECT command.
|
|
|
|
*/
|
2000-06-25 20:00:43 +04:00
|
|
|
bzero(p, sizeof(struct hdc9224_UDCreg));
|
1996-07-20 22:55:09 +04:00
|
|
|
|
|
|
|
p->udc_rtcnt = UDC_RC_HDD_READ;
|
|
|
|
p->udc_mode = UDC_MD_HDD;
|
|
|
|
p->udc_term = UDC_TC_HDD;
|
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
error = hdc_command(sc, DKC_CMD_DRSEL_HDD | unit);
|
|
|
|
|
1996-07-20 22:55:09 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2000-06-25 20:00:43 +04:00
|
|
|
void
|
|
|
|
rdmakelabel(struct disklabel *dl, struct rdgeom *g)
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
2000-06-25 20:00:43 +04:00
|
|
|
int n, p = 0;
|
|
|
|
|
|
|
|
dl->d_bbsize = BBSIZE;
|
|
|
|
dl->d_sbsize = SBSIZE;
|
|
|
|
dl->d_typename[p++] = MSCP_MID_CHAR(2, g->media_id);
|
|
|
|
dl->d_typename[p++] = MSCP_MID_CHAR(1, g->media_id);
|
|
|
|
if (MSCP_MID_ECH(0, g->media_id))
|
|
|
|
dl->d_typename[p++] = MSCP_MID_CHAR(0, g->media_id);
|
|
|
|
n = MSCP_MID_NUM(g->media_id);
|
|
|
|
if (n > 99) {
|
|
|
|
dl->d_typename[p++] = '1';
|
|
|
|
n -= 100;
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
2000-06-25 20:00:43 +04:00
|
|
|
if (n > 9) {
|
|
|
|
dl->d_typename[p++] = (n / 10) + '0';
|
|
|
|
n %= 10;
|
|
|
|
}
|
|
|
|
dl->d_typename[p++] = n + '0';
|
|
|
|
dl->d_typename[p] = 0;
|
|
|
|
dl->d_type = DTYPE_MSCP; /* XXX - what to use here??? */
|
|
|
|
dl->d_rpm = 3600;
|
|
|
|
dl->d_secsize = DEV_BSIZE;
|
|
|
|
|
|
|
|
dl->d_secperunit = g->lbn_count;
|
|
|
|
dl->d_nsectors = g->nspt;
|
|
|
|
dl->d_ntracks = g->ntracks;
|
|
|
|
dl->d_secpercyl = dl->d_nsectors * dl->d_ntracks;
|
|
|
|
dl->d_ncylinders = dl->d_secperunit / dl->d_secpercyl;
|
|
|
|
|
|
|
|
dl->d_npartitions = MAXPARTITIONS;
|
|
|
|
dl->d_partitions[0].p_size = dl->d_partitions[2].p_size =
|
|
|
|
dl->d_secperunit;
|
|
|
|
dl->d_partitions[0].p_offset = dl->d_partitions[2].p_offset = 0;
|
|
|
|
dl->d_interleave = dl->d_headswitch = 1;
|
|
|
|
dl->d_magic = dl->d_magic2 = DISKMAGIC;
|
|
|
|
dl->d_checksum = dkcksum(dl);
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|