Home | History | Annotate | Line # | Download | only in vsa
hdc9224.c revision 1.54.4.1
      1  1.54.4.1     skrll /*	$NetBSD: hdc9224.c,v 1.54.4.1 2015/04/06 15:18:04 skrll Exp $ */
      2       1.1     ragge /*
      3       1.1     ragge  * Copyright (c) 1996 Ludd, University of Lule}, Sweden.
      4       1.1     ragge  * All rights reserved.
      5       1.1     ragge  *
      6       1.1     ragge  * This code is derived from software contributed to Ludd by Bertram Barth.
      7       1.1     ragge  *
      8       1.1     ragge  * Redistribution and use in source and binary forms, with or without
      9       1.1     ragge  * modification, are permitted provided that the following conditions
     10       1.1     ragge  * are met:
     11       1.1     ragge  * 1. Redistributions of source code must retain the above copyright
     12       1.1     ragge  *    notice, this list of conditions and the following disclaimer.
     13       1.1     ragge  * 2. Redistributions in binary form must reproduce the above copyright
     14       1.1     ragge  *    notice, this list of conditions and the following disclaimer in the
     15       1.1     ragge  *    documentation and/or other materials provided with the distribution.
     16       1.1     ragge  * 3. All advertising materials mentioning features or use of this software
     17       1.1     ragge  *    must display the following acknowledgement:
     18       1.1     ragge  *	This product includes software developed at Ludd, University of
     19       1.1     ragge  *	Lule}, Sweden and its contributors.
     20       1.1     ragge  * 4. The name of the author may not be used to endorse or promote products
     21       1.1     ragge  *    derived from this software without specific prior written permission
     22       1.1     ragge  *
     23       1.1     ragge  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24       1.1     ragge  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25       1.1     ragge  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26       1.1     ragge  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27       1.1     ragge  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28       1.1     ragge  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29       1.1     ragge  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30       1.1     ragge  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31       1.1     ragge  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32       1.1     ragge  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33       1.1     ragge  */
     34       1.1     ragge 
     35       1.1     ragge /*
     36       1.1     ragge  * with much help from (in alphabetical order):
     37       1.1     ragge  *	Jeremy
     38       1.1     ragge  *	Roger Ivie
     39       1.1     ragge  *	Rick Macklem
     40       1.1     ragge  *	Mike Young
     41      1.10     ragge  *
     42      1.10     ragge  * Rewritten by Ragge 25 Jun 2000. New features:
     43      1.10     ragge  *	- Uses interrupts instead of polling to signal ready.
     44      1.10     ragge  *	- Can cooperate with the SCSI routines WRT. the DMA area.
     45      1.10     ragge  *
     46      1.10     ragge  * TODO:
     47      1.10     ragge  *	- Floppy support missing.
     48      1.10     ragge  *	- Bad block forwarding missing.
     49      1.10     ragge  *	- Statistics collection.
     50       1.1     ragge  */
     51      1.10     ragge #undef	RDDEBUG
     52      1.30     lukem 
     53      1.30     lukem #include <sys/cdefs.h>
     54  1.54.4.1     skrll __KERNEL_RCSID(0, "$NetBSD: hdc9224.c,v 1.54.4.1 2015/04/06 15:18:04 skrll Exp $");
     55       1.1     ragge 
     56       1.1     ragge #include <sys/param.h>
     57       1.1     ragge #include <sys/systm.h>
     58       1.1     ragge #include <sys/buf.h>
     59      1.31      yamt #include <sys/bufq.h>
     60      1.51      matt #include <sys/cpu.h>
     61      1.51      matt #include <sys/conf.h>
     62       1.1     ragge #include <sys/device.h>
     63       1.1     ragge #include <sys/disklabel.h>
     64       1.1     ragge #include <sys/disk.h>
     65      1.51      matt #include <sys/file.h>
     66      1.51      matt #include <sys/ioctl.h>
     67      1.51      matt #include <sys/proc.h>
     68      1.51      matt #include <sys/stat.h>
     69       1.1     ragge #include <sys/syslog.h>
     70       1.1     ragge 
     71      1.13       mrg #include <uvm/uvm_extern.h>
     72      1.10     ragge 
     73      1.10     ragge #include <ufs/ufs/dinode.h> /* For BBSIZE */
     74      1.10     ragge #include <ufs/ffs/fs.h>
     75      1.10     ragge 
     76       1.1     ragge #include <machine/sid.h>
     77       1.1     ragge #include <machine/ka410.h>
     78       1.1     ragge #include <machine/vsbus.h>
     79       1.6     ragge #include <machine/rpb.h>
     80      1.10     ragge #include <machine/scb.h>
     81      1.10     ragge 
     82      1.10     ragge #include <dev/mscp/mscp.h> /* For DEC disk encoding */
     83       1.1     ragge 
     84       1.1     ragge #include <vax/vsa/hdc9224.h>
     85       1.1     ragge 
     86      1.10     ragge #include "ioconf.h"
     87      1.10     ragge #include "locators.h"
     88       1.1     ragge 
     89       1.1     ragge 
     90       1.1     ragge /*
     91       1.1     ragge  * on-disk geometry block
     92       1.1     ragge  */
     93       1.1     ragge #define _aP	__attribute__ ((packed))	/* force byte-alignment */
     94       1.1     ragge struct rdgeom {
     95      1.10     ragge 	char mbz[10];		/* 10 bytes of zero */
     96      1.10     ragge 	long xbn_count _aP;	/* number of XBNs */
     97      1.10     ragge 	long dbn_count _aP;	/* number of DBNs */
     98      1.10     ragge 	long lbn_count _aP;	/* number of LBNs (Logical-Block-Numbers) */
     99      1.10     ragge 	long rbn_count _aP;	/* number of RBNs (Replacement-Block-Numbers) */
    100      1.10     ragge 	short nspt;		/* number of sectors per track */
    101      1.10     ragge 	short ntracks;		/* number of tracks */
    102      1.10     ragge 	short ncylinders;	/* number of cylinders */
    103      1.10     ragge 	short precomp;		/* first cylinder for write precompensation */
    104      1.10     ragge 	short reduced;		/* first cylinder for reduced write current */
    105      1.10     ragge 	short seek_rate;	/* seek rate or zero for buffered seeks */
    106      1.10     ragge 	short crc_eec;		/* 0 if CRC, 1 if ECC is being used */
    107      1.10     ragge 	short rct;		/* "replacement control table" (RCT) */
    108      1.10     ragge 	short rct_ncopies;	/* number of copies of the RCT */
    109      1.10     ragge 	long	media_id _aP;	/* media identifier */
    110      1.10     ragge 	short interleave;	/* sector-to-sector interleave */
    111      1.10     ragge 	short headskew;		/* head-to-head skew */
    112      1.10     ragge 	short cylskew;		/* cylinder-to-cylinder skew */
    113      1.10     ragge 	short gap0_size;	/* size of GAP 0 in the MFM format */
    114      1.10     ragge 	short gap1_size;	/* size of GAP 1 in the MFM format */
    115      1.10     ragge 	short gap2_size;	/* size of GAP 2 in the MFM format */
    116      1.10     ragge 	short gap3_size;	/* size of GAP 3 in the MFM format */
    117      1.10     ragge 	short sync_value;	/* sync value used when formatting */
    118      1.10     ragge 	char	reserved[32];	/* reserved for use by the RQDX formatter */
    119      1.10     ragge 	short serial_number;	/* serial number */
    120       1.1     ragge #if 0	/* we don't need these 412 useless bytes ... */
    121      1.10     ragge 	char	fill[412-2];	/* Filler bytes to the end of the block */
    122      1.10     ragge 	short checksum;	/* checksum over the XBN */
    123       1.1     ragge #endif
    124       1.1     ragge };
    125       1.1     ragge 
    126       1.1     ragge /*
    127       1.1     ragge  * Software status
    128       1.1     ragge  */
    129       1.1     ragge struct	rdsoftc {
    130      1.44      matt 	device_t sc_dev;		/* must be here! (pseudo-OOP:) */
    131      1.44      matt 	struct hdcsoftc *sc_hdc;
    132      1.10     ragge 	struct disk sc_disk;		/* disklabel etc. */
    133      1.10     ragge 	struct rdgeom sc_xbn;		/* on-disk geometry information */
    134      1.10     ragge 	int sc_drive;		/* physical unit number */
    135       1.1     ragge };
    136       1.1     ragge 
    137       1.1     ragge struct	hdcsoftc {
    138      1.44      matt 	device_t sc_dev;		/* must be here (pseudo-OOP:) */
    139      1.10     ragge 	struct evcnt sc_intrcnt;
    140      1.10     ragge 	struct vsbus_dma sc_vd;
    141      1.10     ragge 	vaddr_t sc_regs;		/* register addresses */
    142      1.32      yamt 	struct bufq_state *sc_q;
    143      1.10     ragge 	struct buf *sc_active;
    144       1.1     ragge 	struct hdc9224_UDCreg sc_creg;	/* (command) registers to be written */
    145       1.1     ragge 	struct hdc9224_UDCreg sc_sreg;	/* (status) registers being read */
    146      1.38  christos 	void *	sc_dmabase;		/* */
    147      1.10     ragge 	int	sc_dmasize;
    148      1.38  christos 	void *sc_bufaddr;		/* Current in-core address */
    149      1.10     ragge 	int sc_diskblk;			/* Current block on disk */
    150      1.10     ragge 	int sc_bytecnt;			/* How much left to transfer */
    151      1.10     ragge 	int sc_xfer;			/* Current transfer size */
    152      1.12     ragge 	int sc_retries;
    153      1.10     ragge 	volatile u_char sc_status;	/* last status from interrupt */
    154      1.12     ragge 	char sc_intbit;
    155      1.10     ragge };
    156      1.10     ragge 
    157      1.10     ragge struct hdc_attach_args {
    158      1.10     ragge 	int ha_drive;
    159       1.1     ragge };
    160       1.1     ragge 
    161       1.1     ragge /*
    162      1.10     ragge  * prototypes for (almost) all the internal routines
    163       1.1     ragge  */
    164      1.43      matt static	int hdcmatch(device_t, cfdata_t, void *);
    165      1.43      matt static	void hdcattach(device_t, device_t, void *);
    166      1.10     ragge static	int hdcprint(void *, const char *);
    167      1.43      matt static	int rdmatch(device_t, cfdata_t, void *);
    168      1.43      matt static	void rdattach(device_t, device_t, void *);
    169      1.10     ragge static	void hdcintr(void *);
    170      1.10     ragge static	int hdc_command(struct hdcsoftc *, int);
    171      1.10     ragge static	void rd_readgeom(struct hdcsoftc *, struct rdsoftc *);
    172      1.10     ragge #ifdef RDDEBUG
    173      1.10     ragge static	void hdc_printgeom( struct rdgeom *);
    174      1.10     ragge #endif
    175      1.10     ragge static	void hdc_writeregs(struct hdcsoftc *);
    176      1.10     ragge static	void hdcstart(struct hdcsoftc *, struct buf *);
    177      1.10     ragge static	int hdc_rdselect(struct hdcsoftc *, int);
    178      1.10     ragge static	void rdmakelabel(struct disklabel *, struct rdgeom *);
    179      1.10     ragge static	void hdc_writeregs(struct hdcsoftc *);
    180      1.10     ragge static	void hdc_readregs(struct hdcsoftc *);
    181      1.10     ragge static	void hdc_qstart(void *);
    182      1.10     ragge 
    183      1.44      matt CFATTACH_DECL_NEW(hdc, sizeof(struct hdcsoftc),
    184      1.23   thorpej     hdcmatch, hdcattach, NULL, NULL);
    185       1.1     ragge 
    186      1.44      matt CFATTACH_DECL_NEW(rd, sizeof(struct rdsoftc),
    187      1.23   thorpej     rdmatch, rdattach, NULL, NULL);
    188       1.7   thorpej 
    189      1.43      matt static dev_type_open(rdopen);
    190      1.43      matt static dev_type_close(rdclose);
    191      1.43      matt static dev_type_read(rdread);
    192      1.43      matt static dev_type_write(rdwrite);
    193      1.43      matt static dev_type_ioctl(rdioctl);
    194      1.43      matt static dev_type_strategy(rdstrategy);
    195      1.43      matt static dev_type_size(rdpsize);
    196      1.19   gehenna 
    197      1.19   gehenna const struct bdevsw rd_bdevsw = {
    198      1.43      matt 	.d_open = rdopen,
    199      1.43      matt 	.d_close = rdclose,
    200      1.43      matt 	.d_strategy = rdstrategy,
    201      1.43      matt 	.d_ioctl = rdioctl,
    202      1.43      matt 	.d_dump = nulldump,
    203      1.43      matt 	.d_psize = rdpsize,
    204      1.53  dholland 	.d_discard = nodiscard,
    205      1.43      matt 	.d_flag = D_DISK
    206      1.19   gehenna };
    207      1.19   gehenna 
    208      1.19   gehenna const struct cdevsw rd_cdevsw = {
    209      1.43      matt 	.d_open = rdopen,
    210      1.43      matt 	.d_close = rdclose,
    211      1.43      matt 	.d_read = rdread,
    212      1.43      matt 	.d_write = rdwrite,
    213      1.43      matt 	.d_ioctl = rdioctl,
    214      1.43      matt 	.d_stop = nostop,
    215      1.43      matt 	.d_tty = notty,
    216      1.43      matt 	.d_poll = nopoll,
    217      1.43      matt 	.d_mmap = nommap,
    218      1.43      matt 	.d_kqfilter = nokqfilter,
    219      1.54  dholland 	.d_discard = nodiscard,
    220      1.43      matt 	.d_flag = D_DISK
    221      1.19   gehenna };
    222       1.1     ragge 
    223      1.10     ragge /* At least 0.7 uS between register accesses */
    224      1.10     ragge static int rd_dmasize, inq = 0;
    225      1.44      matt static volatile int u;
    226      1.34     perry #define	WAIT	__asm("movl %0,%0;movl %0,%0;movl %0,%0; movl %0,%0" :: "m"(u))
    227      1.10     ragge 
    228      1.10     ragge #define	HDC_WREG(x)	*(volatile char *)(sc->sc_regs) = (x)
    229      1.10     ragge #define	HDC_RREG	*(volatile char *)(sc->sc_regs)
    230      1.10     ragge #define	HDC_WCMD(x)	*(volatile char *)(sc->sc_regs + 4) = (x)
    231      1.10     ragge #define	HDC_RSTAT	*(volatile char *)(sc->sc_regs + 4)
    232       1.1     ragge 
    233       1.1     ragge /*
    234       1.1     ragge  * new-config's hdcmatch() is similiar to old-config's hdcprobe(),
    235       1.1     ragge  * thus we probe for the existence of the controller and reset it.
    236       1.1     ragge  * NB: we can't initialize the controller yet, since space for hdcsoftc
    237       1.1     ragge  *     is not yet allocated. Thus we do this in hdcattach()...
    238       1.1     ragge  */
    239       1.1     ragge int
    240      1.43      matt hdcmatch(device_t parent, cfdata_t cf, void *aux)
    241       1.1     ragge {
    242      1.43      matt 	struct vsbus_attach_args * const va = aux;
    243      1.43      matt 	volatile char * const hdc_csr = (volatile char *)va->va_addr;
    244      1.10     ragge 	int i;
    245       1.1     ragge 
    246      1.10     ragge 	u = 8; /* !!! - GCC */
    247       1.1     ragge 
    248      1.10     ragge 	if (vax_boardtype == VAX_BTYP_49 || vax_boardtype == VAX_BTYP_46
    249      1.14     ragge 	    || vax_boardtype == VAX_BTYP_48 || vax_boardtype == VAX_BTYP_53)
    250      1.10     ragge 		return 0;
    251      1.10     ragge 
    252      1.10     ragge 	hdc_csr[4] = DKC_CMD_RESET; /* reset chip */
    253      1.10     ragge 	for (i = 0; i < 1000; i++) {
    254      1.10     ragge 		DELAY(1000);
    255      1.10     ragge 		if (hdc_csr[4] & DKC_ST_DONE)
    256      1.10     ragge 			break;
    257       1.1     ragge 	}
    258      1.10     ragge 	if (i == 100)
    259      1.10     ragge 		return 0; /* No response to reset */
    260       1.1     ragge 
    261      1.10     ragge 	hdc_csr[4] = DKC_CMD_SETREGPTR|UDC_TERM;
    262      1.10     ragge 	WAIT;
    263      1.10     ragge 	hdc_csr[0] = UDC_TC_CRCPRE|UDC_TC_INTDONE;
    264      1.10     ragge 	WAIT;
    265      1.10     ragge 	hdc_csr[4] = DKC_CMD_DRDESELECT; /* Should be harmless */
    266      1.10     ragge 	DELAY(1000);
    267       1.1     ragge 	return (1);
    268       1.1     ragge }
    269       1.1     ragge 
    270       1.1     ragge int
    271      1.10     ragge hdcprint(void *aux, const char *name)
    272       1.1     ragge {
    273      1.43      matt 	struct hdc_attach_args * const ha = aux;
    274       1.1     ragge 
    275      1.10     ragge 	if (name)
    276      1.25   thorpej 		aprint_normal ("RD?? at %s drive %d", name, ha->ha_drive);
    277      1.10     ragge 	return UNCONF;
    278       1.1     ragge }
    279       1.1     ragge 
    280       1.1     ragge /*
    281       1.1     ragge  * hdc_attach() probes for all possible devices
    282       1.1     ragge  */
    283       1.1     ragge void
    284      1.43      matt hdcattach(device_t parent, device_t self, void *aux)
    285       1.1     ragge {
    286      1.43      matt 	struct vsbus_attach_args * const va = aux;
    287      1.43      matt 	struct hdcsoftc * const sc = device_private(self);
    288       1.1     ragge 	struct hdc_attach_args ha;
    289      1.10     ragge 	int status, i;
    290       1.1     ragge 
    291      1.43      matt 	aprint_normal("\n");
    292      1.44      matt 
    293      1.44      matt 	sc->sc_dev = self;
    294      1.44      matt 
    295       1.1     ragge 	/*
    296      1.10     ragge 	 * Get interrupt vector, enable instrumentation.
    297       1.1     ragge 	 */
    298      1.10     ragge 	scb_vecalloc(va->va_cvec, hdcintr, sc, SCB_ISTACK, &sc->sc_intrcnt);
    299      1.10     ragge 	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
    300      1.43      matt 	    device_xname(self), "intr");
    301      1.10     ragge 
    302      1.10     ragge 	sc->sc_regs = vax_map_physmem(va->va_paddr, 1);
    303      1.38  christos 	sc->sc_dmabase = (void *)va->va_dmaaddr;
    304      1.10     ragge 	sc->sc_dmasize = va->va_dmasize;
    305      1.12     ragge 	sc->sc_intbit = va->va_maskno;
    306      1.10     ragge 	rd_dmasize = min(MAXPHYS, sc->sc_dmasize); /* Used in rd_minphys */
    307      1.10     ragge 
    308      1.10     ragge 	sc->sc_vd.vd_go = hdc_qstart;
    309      1.10     ragge 	sc->sc_vd.vd_arg = sc;
    310      1.10     ragge 	/*
    311      1.10     ragge 	 * Reset controller.
    312      1.10     ragge 	 */
    313      1.10     ragge 	HDC_WCMD(DKC_CMD_RESET);
    314      1.10     ragge 	DELAY(1000);
    315      1.10     ragge 	status = HDC_RSTAT;
    316      1.10     ragge 	if (status != (DKC_ST_DONE|DKC_TC_SUCCESS)) {
    317      1.43      matt 		aprint_error_dev(self, "RESET failed,  status 0x%x\n", status);
    318      1.10     ragge 		return;
    319      1.10     ragge 	}
    320      1.32      yamt 	bufq_alloc(&sc->sc_q, "disksort", BUFQ_SORT_CYLINDER);
    321      1.10     ragge 
    322      1.10     ragge 	/*
    323      1.10     ragge 	 * now probe for all possible hard drives
    324      1.10     ragge 	 */
    325      1.10     ragge 	for (i = 0; i < 4; i++) {
    326      1.10     ragge 		if (i == 2) /* Floppy, needs special handling */
    327      1.10     ragge 			continue;
    328      1.10     ragge 		HDC_WCMD(DKC_CMD_DRSELECT | i);
    329      1.10     ragge 		DELAY(1000);
    330      1.10     ragge 		status = HDC_RSTAT;
    331      1.10     ragge 		ha.ha_drive = i;
    332      1.10     ragge 		if ((status & DKC_ST_TERMCOD) == DKC_TC_SUCCESS)
    333      1.10     ragge 			config_found(self, (void *)&ha, hdcprint);
    334       1.1     ragge 	}
    335       1.1     ragge }
    336       1.1     ragge 
    337       1.1     ragge /*
    338       1.1     ragge  * rdmatch() probes for the existence of a RD-type disk/floppy
    339       1.1     ragge  */
    340       1.1     ragge int
    341      1.43      matt rdmatch(device_t parent, cfdata_t cf, void *aux)
    342       1.1     ragge {
    343      1.43      matt 	struct hdc_attach_args * const ha = aux;
    344       1.1     ragge 
    345      1.10     ragge 	if (cf->cf_loc[HDCCF_DRIVE] != HDCCF_DRIVE_DEFAULT &&
    346      1.10     ragge 	    cf->cf_loc[HDCCF_DRIVE] != ha->ha_drive)
    347      1.10     ragge 		return 0;
    348       1.1     ragge 
    349      1.10     ragge 	if (ha->ha_drive == 2) /* Always floppy, not supported */
    350      1.10     ragge 		return 0;
    351       1.1     ragge 
    352      1.10     ragge 	return 1;
    353      1.10     ragge }
    354       1.1     ragge 
    355       1.1     ragge void
    356      1.43      matt rdattach(device_t parent, device_t self, void *aux)
    357       1.1     ragge {
    358      1.43      matt 	struct hdcsoftc * const sc = device_private(parent);
    359      1.43      matt 	struct rdsoftc * const rd = device_private(self);
    360      1.43      matt 	struct hdc_attach_args * const ha = aux;
    361      1.10     ragge 	struct disklabel *dl;
    362      1.27       dsl 	const char *msg;
    363       1.1     ragge 
    364      1.44      matt 	rd->sc_dev = self;
    365       1.1     ragge 	rd->sc_drive = ha->ha_drive;
    366      1.44      matt 	rd->sc_hdc = sc;
    367       1.1     ragge 	/*
    368       1.1     ragge 	 * Initialize and attach the disk structure.
    369       1.1     ragge 	 */
    370      1.44      matt 	disk_init(&rd->sc_disk, device_xname(rd->sc_dev), NULL);
    371      1.10     ragge 	disk_attach(&rd->sc_disk);
    372      1.10     ragge 
    373       1.1     ragge 	/*
    374       1.1     ragge 	 * if it's not a floppy then evaluate the on-disk geometry.
    375      1.16       wiz 	 * if necessary correct the label...
    376       1.1     ragge 	 */
    377      1.10     ragge 	rd_readgeom(sc, rd);
    378      1.10     ragge 	disk_printtype(rd->sc_drive, rd->sc_xbn.media_id);
    379      1.10     ragge 	dl = rd->sc_disk.dk_label;
    380      1.10     ragge 	rdmakelabel(dl, &rd->sc_xbn);
    381      1.19   gehenna 	msg = readdisklabel(MAKEDISKDEV(cdevsw_lookup_major(&rd_cdevsw),
    382      1.44      matt 					device_unit(rd->sc_dev), RAW_PART),
    383      1.19   gehenna 			    rdstrategy, dl, NULL);
    384      1.10     ragge 	if (msg)
    385      1.43      matt 		aprint_normal_dev(self, "%s: size %u sectors",
    386      1.43      matt 		    msg, dl->d_secperunit);
    387      1.43      matt 	else
    388      1.43      matt 		aprint_normal_dev(self, "size %u sectors\n", dl->d_secperunit);
    389      1.10     ragge #ifdef RDDEBUG
    390      1.10     ragge 	hdc_printgeom(&rd->sc_xbn);
    391      1.10     ragge #endif
    392      1.10     ragge }
    393      1.10     ragge 
    394      1.10     ragge void
    395      1.10     ragge hdcintr(void *arg)
    396      1.10     ragge {
    397      1.43      matt 	struct hdcsoftc * const sc = arg;
    398      1.10     ragge 	struct buf *bp;
    399      1.10     ragge 
    400      1.10     ragge 	sc->sc_status = HDC_RSTAT;
    401      1.10     ragge 	if (sc->sc_active == 0)
    402      1.10     ragge 		return; /* Complain? */
    403      1.10     ragge 
    404      1.10     ragge 	if ((sc->sc_status & (DKC_ST_INTPEND|DKC_ST_DONE)) !=
    405      1.10     ragge 	    (DKC_ST_INTPEND|DKC_ST_DONE))
    406      1.10     ragge 		return; /* Why spurious ints sometimes??? */
    407      1.10     ragge 
    408      1.10     ragge 	bp = sc->sc_active;
    409      1.10     ragge 	sc->sc_active = 0;
    410      1.10     ragge 	if ((sc->sc_status & DKC_ST_TERMCOD) != DKC_TC_SUCCESS) {
    411      1.10     ragge 		int i;
    412      1.10     ragge 		u_char *g = (u_char *)&sc->sc_sreg;
    413      1.12     ragge 
    414      1.12     ragge 		if (sc->sc_retries++ < 3) { /* Allow 3 retries */
    415      1.12     ragge 			hdcstart(sc, bp);
    416      1.12     ragge 			return;
    417      1.12     ragge 		}
    418      1.44      matt 		aprint_error_dev(sc->sc_dev, "failed, status 0x%x\n",
    419      1.43      matt 		    sc->sc_status);
    420      1.10     ragge 		hdc_readregs(sc);
    421      1.10     ragge 		for (i = 0; i < 10; i++)
    422      1.43      matt 			aprint_error("%i: %x\n", i, g[i]);
    423      1.10     ragge 		bp->b_error = ENXIO;
    424      1.10     ragge 		bp->b_resid = bp->b_bcount;
    425      1.10     ragge 		biodone(bp);
    426      1.10     ragge 		vsbus_dma_intr();
    427      1.10     ragge 		return;
    428      1.10     ragge 	}
    429      1.10     ragge 
    430      1.10     ragge 	if (bp->b_flags & B_READ) {
    431      1.10     ragge 		vsbus_copytoproc(bp->b_proc, sc->sc_dmabase, sc->sc_bufaddr,
    432      1.10     ragge 		    sc->sc_xfer);
    433      1.10     ragge 	}
    434      1.12     ragge 	sc->sc_diskblk += (sc->sc_xfer/DEV_BSIZE);
    435      1.12     ragge 	sc->sc_bytecnt -= sc->sc_xfer;
    436      1.39  christos 	sc->sc_bufaddr = (char *)sc->sc_bufaddr + sc->sc_xfer;
    437      1.10     ragge 
    438      1.10     ragge 	if (sc->sc_bytecnt == 0) { /* Finished transfer */
    439      1.10     ragge 		biodone(bp);
    440      1.10     ragge 		vsbus_dma_intr();
    441      1.10     ragge 	} else
    442      1.10     ragge 		hdcstart(sc, bp);
    443       1.1     ragge }
    444       1.1     ragge 
    445       1.1     ragge /*
    446      1.10     ragge  *
    447       1.1     ragge  */
    448       1.1     ragge void
    449      1.10     ragge rdstrategy(struct buf *bp)
    450       1.1     ragge {
    451      1.10     ragge 	struct rdsoftc *rd;
    452      1.10     ragge 	struct hdcsoftc *sc;
    453      1.10     ragge 	struct disklabel *lp;
    454      1.43      matt 	int s;
    455       1.1     ragge 
    456      1.43      matt 	if ((rd = device_lookup_private(&rd_cd, DISKUNIT(bp->b_dev))) == NULL) {
    457      1.10     ragge 		bp->b_error = ENXIO;
    458      1.10     ragge 		goto done;
    459      1.10     ragge 	}
    460      1.44      matt 	sc = rd->sc_hdc;
    461       1.1     ragge 
    462      1.10     ragge 	lp = rd->sc_disk.dk_label;
    463      1.28   thorpej 	if ((bounds_check_with_label(&rd->sc_disk, bp, 1)) <= 0)
    464      1.10     ragge 		goto done;
    465       1.1     ragge 
    466       1.1     ragge 	if (bp->b_bcount == 0)
    467       1.1     ragge 		goto done;
    468      1.10     ragge 
    469      1.10     ragge 	bp->b_rawblkno =
    470      1.10     ragge 	    bp->b_blkno + lp->d_partitions[DISKPART(bp->b_dev)].p_offset;
    471      1.10     ragge 	bp->b_cylinder = bp->b_rawblkno / lp->d_secpercyl;
    472      1.10     ragge 
    473      1.15   thorpej 	s = splbio();
    474      1.45      yamt 	bufq_put(sc->sc_q, bp);
    475      1.10     ragge 	if (inq == 0) {
    476      1.10     ragge 		inq = 1;
    477      1.10     ragge 		vsbus_dma_start(&sc->sc_vd);
    478      1.10     ragge 	}
    479      1.10     ragge 	splx(s);
    480      1.10     ragge 	return;
    481      1.10     ragge 
    482      1.10     ragge done:	biodone(bp);
    483       1.1     ragge }
    484       1.1     ragge 
    485      1.10     ragge void
    486      1.10     ragge hdc_qstart(void *arg)
    487       1.1     ragge {
    488      1.43      matt 	struct hdcsoftc * const sc = arg;
    489       1.1     ragge 
    490      1.10     ragge 	inq = 0;
    491       1.1     ragge 
    492      1.10     ragge 	hdcstart(sc, 0);
    493      1.45      yamt 	if (bufq_peek(sc->sc_q)) {
    494      1.10     ragge 		vsbus_dma_start(&sc->sc_vd); /* More to go */
    495      1.10     ragge 		inq = 1;
    496      1.10     ragge 	}
    497      1.10     ragge }
    498       1.1     ragge 
    499      1.10     ragge void
    500      1.10     ragge hdcstart(struct hdcsoftc *sc, struct buf *ob)
    501      1.10     ragge {
    502      1.43      matt 	struct hdc9224_UDCreg * const p = &sc->sc_creg;
    503      1.10     ragge 	struct disklabel *lp;
    504      1.10     ragge 	struct rdsoftc *rd;
    505      1.10     ragge 	struct buf *bp;
    506      1.10     ragge 	int cn, sn, tn, bn, blks;
    507       1.1     ragge 
    508      1.10     ragge 	if (sc->sc_active)
    509      1.10     ragge 		return; /* Already doing something */
    510       1.1     ragge 
    511      1.10     ragge 	if (ob == 0) {
    512      1.45      yamt 		bp = bufq_get(sc->sc_q);
    513      1.10     ragge 		if (bp == NULL)
    514      1.10     ragge 			return; /* Nothing to do */
    515      1.10     ragge 		sc->sc_bufaddr = bp->b_data;
    516      1.10     ragge 		sc->sc_diskblk = bp->b_rawblkno;
    517      1.10     ragge 		sc->sc_bytecnt = bp->b_bcount;
    518      1.12     ragge 		sc->sc_retries = 0;
    519      1.10     ragge 		bp->b_resid = 0;
    520      1.10     ragge 	} else
    521      1.10     ragge 		bp = ob;
    522      1.10     ragge 
    523      1.43      matt 	rd = device_lookup_private(&rd_cd, DISKUNIT(bp->b_dev));
    524      1.10     ragge 	hdc_rdselect(sc, rd->sc_drive);
    525      1.10     ragge 	sc->sc_active = bp;
    526      1.10     ragge 
    527      1.10     ragge 	bn = sc->sc_diskblk;
    528      1.10     ragge 	lp = rd->sc_disk.dk_label;
    529      1.10     ragge         if (bn) {
    530      1.10     ragge                 cn = bn / lp->d_secpercyl;
    531      1.10     ragge                 sn = bn % lp->d_secpercyl;
    532      1.10     ragge                 tn = sn / lp->d_nsectors;
    533      1.10     ragge                 sn = sn % lp->d_nsectors;
    534      1.10     ragge         } else
    535      1.10     ragge                 cn = sn = tn = 0;
    536      1.10     ragge 
    537      1.10     ragge 	cn++; /* first cylinder is reserved */
    538      1.10     ragge 
    539      1.47    cegger 	memset(p, 0, sizeof(struct hdc9224_UDCreg));
    540      1.10     ragge 
    541      1.10     ragge 	/*
    542      1.10     ragge 	 * Tricky thing: the controller do itself only increase the sector
    543      1.10     ragge 	 * number, not the track or cylinder number. Therefore the driver
    544      1.10     ragge 	 * is not allowed to have transfers that crosses track boundaries.
    545      1.10     ragge 	 */
    546      1.10     ragge 	blks = sc->sc_bytecnt/DEV_BSIZE;
    547      1.10     ragge 	if ((sn + blks) > lp->d_nsectors)
    548      1.10     ragge 		blks = lp->d_nsectors - sn;
    549      1.10     ragge 
    550      1.10     ragge 	p->udc_dsect = sn;
    551      1.10     ragge 	p->udc_dcyl = cn & 0xff;
    552      1.10     ragge 	p->udc_dhead = ((cn >> 4) & 0x70) | tn;
    553      1.10     ragge 	p->udc_scnt = blks;
    554      1.10     ragge 
    555      1.10     ragge 	p->udc_rtcnt = UDC_RC_RTRYCNT;
    556      1.10     ragge 	p->udc_mode = UDC_MD_HDD;
    557      1.10     ragge 	p->udc_term = UDC_TC_CRCPRE|UDC_TC_INTDONE|UDC_TC_TDELDAT|UDC_TC_TWRFLT;
    558      1.10     ragge 	hdc_writeregs(sc);
    559      1.10     ragge 
    560      1.10     ragge 	/* Count up vars */
    561      1.10     ragge 	sc->sc_xfer = blks * DEV_BSIZE;
    562      1.12     ragge 
    563      1.52    martin 	(void)HDC_RSTAT; /* Avoid pending interrupts */
    564      1.12     ragge 	WAIT;
    565      1.12     ragge 	vsbus_clrintr(sc->sc_intbit); /* Clear pending int's */
    566      1.10     ragge 
    567      1.10     ragge 	if (bp->b_flags & B_READ) {
    568      1.10     ragge 		HDC_WCMD(DKC_CMD_READ_HDD);
    569      1.10     ragge 	} else {
    570      1.10     ragge 		vsbus_copyfromproc(bp->b_proc, sc->sc_bufaddr, sc->sc_dmabase,
    571      1.10     ragge 		    sc->sc_xfer);
    572      1.10     ragge 		HDC_WCMD(DKC_CMD_WRITE_HDD);
    573      1.10     ragge 	}
    574      1.10     ragge }
    575       1.1     ragge 
    576      1.10     ragge void
    577      1.10     ragge rd_readgeom(struct hdcsoftc *sc, struct rdsoftc *rd)
    578      1.10     ragge {
    579      1.43      matt 	struct hdc9224_UDCreg * const p = &sc->sc_creg;
    580       1.1     ragge 
    581      1.10     ragge 	hdc_rdselect(sc, rd->sc_drive);		/* select drive right now */
    582       1.1     ragge 
    583      1.43      matt 	memset(p, 0, sizeof(*p));
    584       1.1     ragge 
    585      1.10     ragge 	p->udc_scnt  = 1;
    586      1.10     ragge 	p->udc_rtcnt = UDC_RC_RTRYCNT;
    587      1.10     ragge 	p->udc_mode  = UDC_MD_HDD;
    588      1.10     ragge 	p->udc_term  = UDC_TC_CRCPRE|UDC_TC_INTDONE|UDC_TC_TDELDAT|UDC_TC_TWPROT;
    589      1.10     ragge 	hdc_writeregs(sc);
    590      1.10     ragge 	sc->sc_status = 0;
    591      1.10     ragge 	HDC_WCMD(DKC_CMD_READ_HDD|2);
    592      1.10     ragge 	while ((sc->sc_status & DKC_ST_INTPEND) == 0)
    593      1.10     ragge 		;
    594      1.49    cegger 	memcpy(&rd->sc_xbn, sc->sc_dmabase, sizeof(struct rdgeom));
    595       1.1     ragge }
    596       1.1     ragge 
    597      1.10     ragge #ifdef RDDEBUG
    598       1.1     ragge /*
    599       1.1     ragge  * display the contents of the on-disk geometry structure
    600       1.1     ragge  */
    601       1.9     ragge void
    602      1.46       dsl hdc_printgeom(struct rdgeom *p)
    603       1.1     ragge {
    604       1.9     ragge 	printf ("**DiskData**	 XBNs: %ld, DBNs: %ld, LBNs: %ld, RBNs: %ld\n",
    605       1.1     ragge 		p->xbn_count, p->dbn_count, p->lbn_count, p->rbn_count);
    606       1.4  christos 	printf ("sec/track: %d, tracks: %d, cyl: %d, precomp/reduced: %d/%d\n",
    607       1.1     ragge 		p->nspt, p->ntracks, p->ncylinders, p->precomp, p->reduced);
    608       1.4  christos 	printf ("seek-rate: %d, crc/eec: %s, RCT: %d, RCT-copies: %d\n",
    609       1.1     ragge 		p->seek_rate, p->crc_eec?"EEC":"CRC", p->rct, p->rct_ncopies);
    610      1.10     ragge 	printf ("media-ID: %lx, interleave: %d, headskew: %d, cylskew: %d\n",
    611      1.10     ragge 		p->media_id, p->interleave, p->headskew, p->cylskew);
    612       1.4  christos 	printf ("gap0: %d, gap1: %d, gap2: %d, gap3: %d, sync-value: %d\n",
    613       1.1     ragge 		p->gap0_size, p->gap1_size, p->gap2_size, p->gap3_size,
    614       1.1     ragge 		p->sync_value);
    615       1.1     ragge }
    616       1.1     ragge #endif
    617       1.1     ragge 
    618       1.1     ragge /*
    619      1.10     ragge  * Return the size of a partition, if known, or -1 if not.
    620       1.1     ragge  */
    621       1.1     ragge int
    622      1.43      matt rdpsize(dev_t dev)
    623       1.1     ragge {
    624      1.43      matt 	struct rdsoftc * const rd = device_lookup_private(&rd_cd, DISKUNIT(dev));
    625      1.43      matt 	const int part = DISKPART(dev);
    626       1.1     ragge 
    627      1.43      matt 	if (rd == NULL || part >= rd->sc_disk.dk_label->d_npartitions)
    628      1.10     ragge 		return -1;
    629      1.43      matt 
    630      1.43      matt 	return rd->sc_disk.dk_label->d_partitions[part].p_size *
    631      1.10     ragge 	    (rd->sc_disk.dk_label->d_secsize / DEV_BSIZE);
    632       1.1     ragge }
    633       1.1     ragge 
    634       1.1     ragge /*
    635       1.1     ragge  *
    636       1.1     ragge  */
    637       1.1     ragge int
    638      1.33  christos rdopen(dev_t dev, int flag, int fmt, struct lwp *l)
    639       1.1     ragge {
    640      1.43      matt 	struct rdsoftc * const rd = device_lookup_private(&rd_cd, DISKUNIT(dev));
    641      1.43      matt 	const int part = DISKPART(dev);
    642       1.1     ragge 
    643      1.43      matt 	if (rd == NULL || part >= rd->sc_disk.dk_label->d_npartitions)
    644       1.1     ragge 		return ENXIO;
    645      1.10     ragge 
    646      1.10     ragge 	switch (fmt) {
    647      1.10     ragge 	case S_IFCHR:
    648      1.10     ragge 		rd->sc_disk.dk_copenmask |= (1 << part);
    649      1.10     ragge 		break;
    650      1.10     ragge 	case S_IFBLK:
    651      1.10     ragge 		rd->sc_disk.dk_bopenmask |= (1 << part);
    652      1.10     ragge 		break;
    653       1.1     ragge 	}
    654      1.10     ragge 	rd->sc_disk.dk_openmask =
    655      1.10     ragge 	    rd->sc_disk.dk_copenmask | rd->sc_disk.dk_bopenmask;
    656       1.1     ragge 
    657      1.10     ragge 	return 0;
    658       1.1     ragge }
    659       1.1     ragge 
    660       1.1     ragge /*
    661       1.1     ragge  *
    662       1.1     ragge  */
    663       1.1     ragge int
    664      1.33  christos rdclose(dev_t dev, int flag, int fmt, struct lwp *l)
    665       1.1     ragge {
    666      1.43      matt 	struct rdsoftc * const rd = device_lookup_private(&rd_cd, DISKUNIT(dev));
    667      1.43      matt 	const int part = DISKPART(dev);
    668      1.10     ragge 
    669      1.10     ragge 	switch (fmt) {
    670      1.10     ragge 	case S_IFCHR:
    671      1.10     ragge 		rd->sc_disk.dk_copenmask &= ~(1 << part);
    672      1.10     ragge 		break;
    673      1.10     ragge 	case S_IFBLK:
    674      1.10     ragge 		rd->sc_disk.dk_bopenmask &= ~(1 << part);
    675      1.10     ragge 		break;
    676      1.10     ragge 	}
    677      1.10     ragge 	rd->sc_disk.dk_openmask =
    678      1.10     ragge 	    rd->sc_disk.dk_copenmask | rd->sc_disk.dk_bopenmask;
    679      1.10     ragge 
    680       1.1     ragge 	return (0);
    681       1.1     ragge }
    682       1.1     ragge 
    683       1.1     ragge /*
    684       1.1     ragge  *
    685       1.1     ragge  */
    686       1.1     ragge int
    687      1.38  christos rdioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
    688       1.1     ragge {
    689      1.43      matt 	struct rdsoftc * const rd = device_lookup_private(&rd_cd, DISKUNIT(dev));
    690      1.43      matt 	struct disklabel * const lp = rd->sc_disk.dk_label;
    691  1.54.4.1     skrll 	int error;
    692       1.1     ragge 
    693  1.54.4.1     skrll 	error = disk_ioctl(&rd->sc_disk, dev, cmd, addr, flag, l);
    694  1.54.4.1     skrll 	if (error != EPASSTHROUGH)
    695  1.54.4.1     skrll 		return error;
    696  1.54.4.1     skrll 	else
    697  1.54.4.1     skrll 		error = 0;
    698       1.1     ragge 
    699  1.54.4.1     skrll 	switch (cmd) {
    700       1.1     ragge 	case DIOCWDINFO:
    701       1.1     ragge 	case DIOCSDINFO:
    702       1.1     ragge 		if ((flag & FWRITE) == 0)
    703       1.1     ragge 			return EBADF;
    704      1.43      matt 		error = (cmd == DIOCSDINFO ?
    705      1.43      matt 		    setdisklabel(lp, (struct disklabel *)addr, 0, 0) :
    706      1.43      matt 		    writedisklabel(dev, rdstrategy, lp, 0));
    707      1.10     ragge 		break;
    708       1.1     ragge 
    709      1.10     ragge 	case DIOCGDEFLABEL:
    710      1.43      matt 		memset(lp, 0, sizeof(*lp));
    711      1.10     ragge 		rdmakelabel(lp, &rd->sc_xbn);
    712      1.10     ragge 		break;
    713       1.1     ragge 
    714       1.1     ragge 	case DIOCWLABEL:
    715       1.1     ragge 		if ((flag & FWRITE) == 0)
    716      1.43      matt 			error = EBADF;
    717      1.10     ragge 		break;
    718      1.10     ragge 
    719       1.1     ragge 	default:
    720      1.43      matt 		error = ENOTTY;
    721       1.1     ragge 	}
    722      1.43      matt 	return error;
    723       1.1     ragge }
    724       1.1     ragge 
    725       1.1     ragge /*
    726       1.1     ragge  *
    727       1.1     ragge  */
    728       1.1     ragge int
    729      1.10     ragge rdread(dev_t dev, struct uio *uio, int flag)
    730       1.1     ragge {
    731      1.10     ragge 	return (physio (rdstrategy, NULL, dev, B_READ, minphys, uio));
    732       1.1     ragge }
    733       1.1     ragge 
    734       1.1     ragge /*
    735       1.1     ragge  *
    736       1.1     ragge  */
    737       1.1     ragge int
    738      1.10     ragge rdwrite(dev_t dev, struct uio *uio, int flag)
    739       1.1     ragge {
    740      1.10     ragge 	return (physio (rdstrategy, NULL, dev, B_WRITE, minphys, uio));
    741       1.1     ragge }
    742       1.1     ragge 
    743       1.1     ragge /*
    744       1.1     ragge  * we have to wait 0.7 usec between two accesses to any of the
    745       1.1     ragge  * dkc-registers, on a VS2000 with 1 MIPS, this is roughly one
    746       1.1     ragge  * instruction. Thus the loop-overhead will be enough...
    747       1.1     ragge  */
    748      1.10     ragge static void
    749      1.10     ragge hdc_readregs(struct hdcsoftc *sc)
    750       1.1     ragge {
    751       1.1     ragge 	int i;
    752       1.1     ragge 	char *p;
    753       1.1     ragge 
    754      1.10     ragge 	HDC_WCMD(DKC_CMD_SETREGPTR);
    755      1.10     ragge 	WAIT;
    756       1.1     ragge 	p = (void*)&sc->sc_sreg;
    757      1.10     ragge 	for (i=0; i<10; i++) {
    758      1.10     ragge 		*p++ = HDC_RREG;	/* dkc_reg auto-increments */
    759      1.10     ragge 		WAIT;
    760      1.10     ragge 	}
    761       1.1     ragge }
    762       1.1     ragge 
    763      1.10     ragge static void
    764      1.10     ragge hdc_writeregs(struct hdcsoftc *sc)
    765       1.1     ragge {
    766       1.1     ragge 	int i;
    767       1.1     ragge 	char *p;
    768       1.1     ragge 
    769      1.10     ragge 	HDC_WCMD(DKC_CMD_SETREGPTR);
    770       1.1     ragge 	p = (void*)&sc->sc_creg;
    771      1.10     ragge 	for (i=0; i<10; i++) {
    772      1.10     ragge 		HDC_WREG(*p++);	/* dkc_reg auto-increments */
    773      1.10     ragge 		WAIT;
    774      1.10     ragge 	}
    775       1.1     ragge }
    776       1.1     ragge 
    777       1.1     ragge /*
    778       1.1     ragge  * hdc_command() issues a command and polls the intreq-register
    779       1.1     ragge  * to find when command has completed
    780       1.1     ragge  */
    781       1.1     ragge int
    782      1.10     ragge hdc_command(struct hdcsoftc *sc, int cmd)
    783       1.1     ragge {
    784       1.1     ragge 	hdc_writeregs(sc);		/* write the prepared registers */
    785      1.10     ragge 	HDC_WCMD(cmd);
    786      1.10     ragge 	WAIT;
    787       1.1     ragge 	return (0);
    788       1.1     ragge }
    789       1.1     ragge 
    790       1.1     ragge int
    791      1.10     ragge hdc_rdselect(struct hdcsoftc *sc, int unit)
    792       1.1     ragge {
    793      1.43      matt 	struct hdc9224_UDCreg * const p = &sc->sc_creg;
    794       1.1     ragge 	int error;
    795       1.1     ragge 
    796       1.1     ragge 	/*
    797       1.1     ragge 	 * bring "creg" in some known-to-work state and
    798       1.1     ragge 	 * select the drive with the DRIVE SELECT command.
    799       1.1     ragge 	 */
    800      1.43      matt 	memset(p, 0, sizeof(*p));
    801       1.1     ragge 
    802       1.1     ragge 	p->udc_rtcnt = UDC_RC_HDD_READ;
    803       1.1     ragge 	p->udc_mode  = UDC_MD_HDD;
    804       1.1     ragge 	p->udc_term  = UDC_TC_HDD;
    805       1.1     ragge 
    806      1.10     ragge 	error = hdc_command(sc, DKC_CMD_DRSEL_HDD | unit);
    807      1.10     ragge 
    808      1.43      matt 	return error;
    809       1.1     ragge }
    810       1.1     ragge 
    811      1.10     ragge void
    812      1.10     ragge rdmakelabel(struct disklabel *dl, struct rdgeom *g)
    813       1.1     ragge {
    814      1.10     ragge 	int n, p = 0;
    815       1.1     ragge 
    816      1.10     ragge 	dl->d_bbsize = BBSIZE;
    817      1.26        he 	dl->d_sbsize = SBLOCKSIZE;
    818      1.10     ragge 	dl->d_typename[p++] = MSCP_MID_CHAR(2, g->media_id);
    819      1.10     ragge 	dl->d_typename[p++] = MSCP_MID_CHAR(1, g->media_id);
    820      1.10     ragge 	if (MSCP_MID_ECH(0, g->media_id))
    821      1.10     ragge 		dl->d_typename[p++] = MSCP_MID_CHAR(0, g->media_id);
    822      1.10     ragge 	n = MSCP_MID_NUM(g->media_id);
    823      1.10     ragge 	if (n > 99) {
    824      1.10     ragge 		dl->d_typename[p++] = '1';
    825      1.10     ragge 		n -= 100;
    826      1.10     ragge 	}
    827      1.10     ragge 	if (n > 9) {
    828      1.10     ragge 		dl->d_typename[p++] = (n / 10) + '0';
    829      1.10     ragge 		n %= 10;
    830      1.10     ragge 	}
    831      1.10     ragge 	dl->d_typename[p++] = n + '0';
    832      1.10     ragge 	dl->d_typename[p] = 0;
    833  1.54.4.1     skrll 	dl->d_type = DKTYPE_MSCP; /* XXX - what to use here??? */
    834      1.10     ragge 	dl->d_rpm = 3600;
    835      1.10     ragge 	dl->d_secsize = DEV_BSIZE;
    836      1.10     ragge 
    837      1.10     ragge 	dl->d_secperunit = g->lbn_count;
    838      1.10     ragge 	dl->d_nsectors = g->nspt;
    839      1.10     ragge 	dl->d_ntracks = g->ntracks;
    840      1.10     ragge 	dl->d_secpercyl = dl->d_nsectors * dl->d_ntracks;
    841      1.10     ragge 	dl->d_ncylinders = dl->d_secperunit / dl->d_secpercyl;
    842      1.10     ragge 
    843      1.10     ragge 	dl->d_npartitions = MAXPARTITIONS;
    844      1.10     ragge 	dl->d_partitions[0].p_size = dl->d_partitions[2].p_size =
    845      1.10     ragge 	    dl->d_secperunit;
    846      1.10     ragge 	dl->d_partitions[0].p_offset = dl->d_partitions[2].p_offset = 0;
    847      1.10     ragge 	dl->d_interleave = dl->d_headswitch = 1;
    848      1.10     ragge 	dl->d_magic = dl->d_magic2 = DISKMAGIC;
    849      1.10     ragge 	dl->d_checksum = dkcksum(dl);
    850       1.1     ragge }
    851