2015-04-26 18:15:19 +03:00
|
|
|
/* $NetBSD: mscp_disk.c,v 1.88 2015/04/26 15:15:20 mlelstv Exp $ */
|
1999-05-29 23:11:41 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1988 Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Chris Torek.
|
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
|
|
|
*
|
|
|
|
* @(#)uda.c 7.32 (Berkeley) 2/13/91
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1996 Ludd, University of Lule}, Sweden.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Chris Torek.
|
|
|
|
*
|
|
|
|
* 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.
|
1999-05-29 23:11:41 +04:00
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
|
|
|
*
|
|
|
|
* @(#)uda.c 7.32 (Berkeley) 2/13/91
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RA disk device driver
|
|
|
|
* RX MSCP floppy disk device driver
|
2012-06-23 00:42:22 +04:00
|
|
|
* RRD MSCP CD device driver
|
1999-05-29 23:11:41 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO
|
|
|
|
* write bad block forwarding code
|
|
|
|
*/
|
|
|
|
|
2001-11-13 10:38:28 +03:00
|
|
|
#include <sys/cdefs.h>
|
2015-04-26 18:15:19 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: mscp_disk.c,v 1.88 2015/04/26 15:15:20 mlelstv Exp $");
|
2001-11-13 10:38:28 +03:00
|
|
|
|
1999-05-29 23:11:41 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/buf.h>
|
2004-10-31 15:52:55 +03:00
|
|
|
#include <sys/bufq.h>
|
1999-05-29 23:11:41 +04:00
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/disk.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/systm.h>
|
2002-09-06 17:18:43 +04:00
|
|
|
#include <sys/conf.h>
|
1999-05-29 23:11:41 +04:00
|
|
|
|
|
|
|
#include <ufs/ufs/dinode.h>
|
|
|
|
#include <ufs/ffs/fs.h>
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/cpu.h>
|
1999-05-29 23:11:41 +04:00
|
|
|
|
1999-06-06 23:16:18 +04:00
|
|
|
#include <dev/mscp/mscp.h>
|
|
|
|
#include <dev/mscp/mscpreg.h>
|
|
|
|
#include <dev/mscp/mscpvar.h>
|
1999-05-29 23:11:41 +04:00
|
|
|
|
|
|
|
#include "locators.h"
|
|
|
|
#include "ioconf.h"
|
|
|
|
#include "ra.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Drive status, per drive
|
|
|
|
*/
|
|
|
|
struct ra_softc {
|
2012-10-27 21:17:22 +04:00
|
|
|
device_t ra_dev; /* Autoconf struct */
|
1999-05-29 23:11:41 +04:00
|
|
|
struct disk ra_disk;
|
|
|
|
int ra_state; /* open/closed state */
|
|
|
|
u_long ra_mediaid; /* media id */
|
|
|
|
int ra_hwunit; /* Hardware unit number */
|
|
|
|
int ra_havelabel; /* true if we have a label */
|
|
|
|
int ra_wlabel; /* label sector is currently writable */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define rx_softc ra_softc
|
2012-06-23 00:42:22 +04:00
|
|
|
#define racd_softc ra_softc
|
1999-05-29 23:11:41 +04:00
|
|
|
|
2012-06-23 00:42:22 +04:00
|
|
|
void raattach(device_t, device_t, void *);
|
2005-02-04 05:10:35 +03:00
|
|
|
int rx_putonline(struct rx_softc *);
|
|
|
|
void rrmakelabel(struct disklabel *, long);
|
2012-06-23 00:42:22 +04:00
|
|
|
int ra_putonline(dev_t, struct ra_softc *);
|
|
|
|
static inline struct ra_softc *mscp_device_lookup(dev_t);
|
1999-05-29 23:11:41 +04:00
|
|
|
|
|
|
|
#if NRA
|
|
|
|
|
2009-05-12 18:28:22 +04:00
|
|
|
int ramatch(device_t, cfdata_t, void *);
|
1999-05-29 23:11:41 +04:00
|
|
|
|
2012-10-27 21:17:22 +04:00
|
|
|
CFATTACH_DECL_NEW(ra, sizeof(struct ra_softc),
|
2012-06-23 00:42:22 +04:00
|
|
|
ramatch, raattach, NULL, NULL);
|
|
|
|
|
|
|
|
#endif /* NRA */
|
|
|
|
|
|
|
|
#if NRA || NRACD || NRX
|
1999-05-29 23:11:41 +04:00
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dev_type_open(raopen);
|
|
|
|
dev_type_close(raclose);
|
|
|
|
dev_type_read(raread);
|
|
|
|
dev_type_write(rawrite);
|
|
|
|
dev_type_ioctl(raioctl);
|
|
|
|
dev_type_strategy(rastrategy);
|
|
|
|
dev_type_dump(radump);
|
|
|
|
dev_type_size(rasize);
|
|
|
|
|
2012-06-23 00:42:22 +04:00
|
|
|
#if NRA
|
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
const struct bdevsw ra_bdevsw = {
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_open = raopen,
|
|
|
|
.d_close = raclose,
|
2014-03-16 09:49:41 +04:00
|
|
|
.d_strategy = rastrategy,
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_ioctl = raioctl,
|
|
|
|
.d_dump = radump,
|
|
|
|
.d_psize = rasize,
|
2014-07-25 12:02:18 +04:00
|
|
|
.d_discard = nodiscard,
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_flag = D_DISK
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct cdevsw ra_cdevsw = {
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_open = raopen,
|
|
|
|
.d_close = raclose,
|
|
|
|
.d_read = raread,
|
|
|
|
.d_write = rawrite,
|
|
|
|
.d_ioctl = raioctl,
|
|
|
|
.d_stop = nostop,
|
|
|
|
.d_tty = notty,
|
|
|
|
.d_poll = nopoll,
|
|
|
|
.d_mmap = nommap,
|
|
|
|
.d_kqfilter = nokqfilter,
|
2014-07-25 12:10:31 +04:00
|
|
|
.d_discard = nodiscard,
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_flag = D_DISK
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
|
|
|
|
2004-09-25 20:44:30 +04:00
|
|
|
static struct dkdriver radkdriver = {
|
2015-04-26 18:15:19 +03:00
|
|
|
.d_strategy = rastrategy,
|
|
|
|
.d_minphys = minphys
|
2004-09-25 20:44:30 +04:00
|
|
|
};
|
|
|
|
|
1999-05-29 23:11:41 +04:00
|
|
|
/*
|
|
|
|
* More driver definitions, for generic MSCP code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2009-05-12 18:28:22 +04:00
|
|
|
ramatch(device_t parent, cfdata_t cf, void *aux)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
|
|
|
struct drive_attach_args *da = aux;
|
|
|
|
struct mscp *mp = da->da_mp;
|
|
|
|
|
|
|
|
if ((da->da_typ & MSCPBUS_DISK) == 0)
|
|
|
|
return 0;
|
|
|
|
if (cf->cf_loc[MSCPBUSCF_DRIVE] != MSCPBUSCF_DRIVE_DEFAULT &&
|
|
|
|
cf->cf_loc[MSCPBUSCF_DRIVE] != mp->mscp_unit)
|
|
|
|
return 0;
|
|
|
|
/*
|
2012-06-23 00:42:22 +04:00
|
|
|
* Check if this disk is a floppy (RX) or cd (RRD)
|
1999-05-29 23:11:41 +04:00
|
|
|
* Seems to be a safe way to test it per Chris Torek.
|
|
|
|
*/
|
|
|
|
if (MSCP_MID_ECH(1, mp->mscp_guse.guse_mediaid) == 'X' - '@')
|
|
|
|
return 0;
|
2012-06-23 00:42:22 +04:00
|
|
|
if (MSCP_MID_ECH(1, mp->mscp_guse.guse_mediaid) == 'R' - '@')
|
|
|
|
return 0;
|
1999-05-29 23:11:41 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-06-23 00:42:22 +04:00
|
|
|
#endif /* NRA */
|
1999-05-29 23:11:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Open a drive.
|
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
2009-03-15 00:04:01 +03:00
|
|
|
raopen(dev_t dev, int flag, int fmt, struct lwp *l)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
2012-06-23 00:42:22 +04:00
|
|
|
struct ra_softc *ra = mscp_device_lookup(dev);
|
|
|
|
int error, part, mask;
|
1999-05-29 23:11:41 +04:00
|
|
|
/*
|
|
|
|
* Make sure this is a reasonable open request.
|
|
|
|
*/
|
2008-06-11 21:32:30 +04:00
|
|
|
if (!ra)
|
1999-05-29 23:11:41 +04:00
|
|
|
return ENXIO;
|
|
|
|
|
2004-09-25 20:44:30 +04:00
|
|
|
part = DISKPART(dev);
|
|
|
|
|
2007-07-21 23:51:47 +04:00
|
|
|
mutex_enter(&ra->ra_disk.dk_openlock);
|
2004-09-25 20:44:30 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If there are wedges, and this is not RAW_PART, then we
|
|
|
|
* need to fail.
|
|
|
|
*/
|
|
|
|
if (ra->ra_disk.dk_nwedges != 0 && part != RAW_PART) {
|
|
|
|
error = EBUSY;
|
|
|
|
goto bad1;
|
|
|
|
}
|
|
|
|
|
1999-05-29 23:11:41 +04:00
|
|
|
/*
|
|
|
|
* If this is the first open; we must first try to put
|
|
|
|
* the disk online (and read the label).
|
|
|
|
*/
|
2004-09-25 20:44:30 +04:00
|
|
|
if (ra->ra_state == DK_CLOSED) {
|
2012-06-23 00:42:22 +04:00
|
|
|
if (ra_putonline(dev, ra) == MSCP_FAILED) {
|
2004-09-25 20:44:30 +04:00
|
|
|
error = ENXIO;
|
|
|
|
goto bad1;
|
|
|
|
}
|
|
|
|
}
|
1999-05-29 23:11:41 +04:00
|
|
|
|
|
|
|
/* If the disk has no label; allow writing everywhere */
|
|
|
|
if (ra->ra_havelabel == 0)
|
|
|
|
ra->ra_wlabel = 1;
|
|
|
|
|
2004-09-25 20:44:30 +04:00
|
|
|
if (part >= ra->ra_disk.dk_label->d_npartitions) {
|
|
|
|
error = ENXIO;
|
|
|
|
goto bad1;
|
|
|
|
}
|
1999-05-29 23:11:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for the state to settle
|
|
|
|
*/
|
|
|
|
#if notyet
|
|
|
|
while (ra->ra_state != DK_OPEN)
|
2007-03-04 08:59:00 +03:00
|
|
|
if ((error = tsleep((void *)ra, (PZERO + 1) | PCATCH,
|
1999-05-29 23:11:41 +04:00
|
|
|
devopn, 0))) {
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mask = 1 << part;
|
|
|
|
|
|
|
|
switch (fmt) {
|
|
|
|
case S_IFCHR:
|
|
|
|
ra->ra_disk.dk_copenmask |= mask;
|
|
|
|
break;
|
|
|
|
case S_IFBLK:
|
|
|
|
ra->ra_disk.dk_bopenmask |= mask;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ra->ra_disk.dk_openmask |= mask;
|
2007-07-21 23:51:47 +04:00
|
|
|
error = 0;
|
2004-09-25 20:44:30 +04:00
|
|
|
bad1:
|
2007-07-21 23:51:47 +04:00
|
|
|
mutex_exit(&ra->ra_disk.dk_openlock);
|
2004-09-25 20:44:30 +04:00
|
|
|
return (error);
|
1999-05-29 23:11:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2009-03-15 00:04:01 +03:00
|
|
|
raclose(dev_t dev, int flags, int fmt, struct lwp *l)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
2012-06-23 00:42:22 +04:00
|
|
|
struct ra_softc *ra = mscp_device_lookup(dev);
|
2007-07-21 23:51:47 +04:00
|
|
|
int mask = (1 << DISKPART(dev));
|
2004-09-25 20:44:30 +04:00
|
|
|
|
2007-07-21 23:51:47 +04:00
|
|
|
mutex_enter(&ra->ra_disk.dk_openlock);
|
1999-05-29 23:11:41 +04:00
|
|
|
|
|
|
|
switch (fmt) {
|
|
|
|
case S_IFCHR:
|
|
|
|
ra->ra_disk.dk_copenmask &= ~mask;
|
|
|
|
break;
|
|
|
|
case S_IFBLK:
|
|
|
|
ra->ra_disk.dk_bopenmask &= ~mask;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ra->ra_disk.dk_openmask =
|
|
|
|
ra->ra_disk.dk_copenmask | ra->ra_disk.dk_bopenmask;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Should wait for I/O to complete on this partition even if
|
|
|
|
* others are open, but wait for work on blkflush().
|
|
|
|
*/
|
|
|
|
#if notyet
|
|
|
|
if (ra->ra_openpart == 0) {
|
2001-04-13 00:13:26 +04:00
|
|
|
s = spluba();
|
2009-01-13 16:33:58 +03:00
|
|
|
while (bufq_peek(udautab[unit]) != NULL)
|
2000-05-27 08:52:27 +04:00
|
|
|
(void) tsleep(&udautab[unit], PZERO - 1,
|
|
|
|
"raclose", 0);
|
1999-05-29 23:11:41 +04:00
|
|
|
splx(s);
|
2012-07-11 20:41:16 +04:00
|
|
|
ra->ra_state = DK_CLOSED;
|
1999-05-29 23:11:41 +04:00
|
|
|
ra->ra_wlabel = 0;
|
|
|
|
}
|
|
|
|
#endif
|
2007-07-21 23:51:47 +04:00
|
|
|
mutex_exit(&ra->ra_disk.dk_openlock);
|
1999-05-29 23:11:41 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Queue a transfer request, and if possible, hand it to the controller.
|
|
|
|
*/
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
rastrategy(struct buf *bp)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
2012-06-23 00:42:22 +04:00
|
|
|
struct ra_softc *ra = mscp_device_lookup(bp->b_dev);
|
2002-07-25 16:13:03 +04:00
|
|
|
int b;
|
|
|
|
|
1999-05-29 23:11:41 +04:00
|
|
|
/*
|
|
|
|
* Make sure this is a reasonable drive to use.
|
|
|
|
*/
|
2012-06-23 00:42:22 +04:00
|
|
|
if (ra == NULL) {
|
1999-05-29 23:11:41 +04:00
|
|
|
bp->b_error = ENXIO;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If drive is open `raw' or reading label, let it at it.
|
|
|
|
*/
|
|
|
|
if (ra->ra_state == DK_RDLABEL) {
|
2002-07-25 16:13:03 +04:00
|
|
|
/* Make some statistics... /bqt */
|
|
|
|
b = splbio();
|
|
|
|
disk_busy(&ra->ra_disk);
|
|
|
|
splx(b);
|
2012-10-27 21:17:22 +04:00
|
|
|
mscp_strategy(bp, device_parent(ra->ra_dev));
|
1999-05-29 23:11:41 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If disk is not online, try to put it online */
|
|
|
|
if (ra->ra_state == DK_CLOSED)
|
2012-06-23 00:42:22 +04:00
|
|
|
if (ra_putonline(bp->b_dev, ra) == MSCP_FAILED) {
|
1999-05-29 23:11:41 +04:00
|
|
|
bp->b_error = EIO;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine the size of the transfer, and make sure it is
|
|
|
|
* within the boundaries of the partition.
|
|
|
|
*/
|
2003-05-11 03:12:28 +04:00
|
|
|
if (bounds_check_with_label(&ra->ra_disk, bp, ra->ra_wlabel) <= 0)
|
1999-05-29 23:11:41 +04:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Make some statistics... /bqt */
|
2002-07-25 16:13:03 +04:00
|
|
|
b = splbio();
|
|
|
|
disk_busy(&ra->ra_disk);
|
|
|
|
splx(b);
|
2012-10-27 21:17:22 +04:00
|
|
|
mscp_strategy(bp, device_parent(ra->ra_dev));
|
1999-05-29 23:11:41 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
done:
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
raread(dev_t dev, struct uio *uio, int flags)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (physio(rastrategy, NULL, dev, B_READ, minphys, uio));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
rawrite(dev_t dev, struct uio *uio, int flags)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (physio(rastrategy, NULL, dev, B_WRITE, minphys, uio));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* I/O controls.
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
raioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct disklabel *lp, *tp;
|
2012-06-23 00:42:22 +04:00
|
|
|
struct ra_softc *ra = mscp_device_lookup(dev);
|
2014-12-31 20:06:48 +03:00
|
|
|
int error;
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
struct disklabel newlabel;
|
|
|
|
#endif
|
1999-05-29 23:11:41 +04:00
|
|
|
|
|
|
|
lp = ra->ra_disk.dk_label;
|
|
|
|
|
2014-12-31 22:52:04 +03:00
|
|
|
error = disk_ioctl(&ra->ra_disk, dev, cmd, data, flag, l);
|
2014-12-31 20:06:48 +03:00
|
|
|
if (error != EPASSTHROUGH)
|
|
|
|
return error;
|
|
|
|
else
|
|
|
|
error = 0;
|
|
|
|
|
1999-05-29 23:11:41 +04:00
|
|
|
switch (cmd) {
|
|
|
|
case DIOCWDINFO:
|
|
|
|
case DIOCSDINFO:
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
case ODIOCWDINFO:
|
|
|
|
case ODIOCSDINFO:
|
2009-09-12 22:01:50 +04:00
|
|
|
if (cmd == ODIOCSDINFO || cmd == ODIOCWDINFO) {
|
2001-01-07 21:09:01 +03:00
|
|
|
memset(&newlabel, 0, sizeof newlabel);
|
|
|
|
memcpy(&newlabel, data, sizeof (struct olddisklabel));
|
|
|
|
tp = &newlabel;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
tp = (struct disklabel *)data;
|
|
|
|
|
1999-05-29 23:11:41 +04:00
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
error = EBADF;
|
|
|
|
else {
|
2007-07-21 23:51:47 +04:00
|
|
|
mutex_enter(&ra->ra_disk.dk_openlock);
|
2001-01-07 21:09:01 +03:00
|
|
|
error = setdisklabel(lp, tp, 0, 0);
|
|
|
|
if ((error == 0) && (cmd == DIOCWDINFO
|
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
|| cmd == ODIOCWDINFO
|
|
|
|
#endif
|
2009-09-12 22:01:50 +04:00
|
|
|
)) {
|
1999-05-29 23:11:41 +04:00
|
|
|
ra->ra_wlabel = 1;
|
|
|
|
error = writedisklabel(dev, rastrategy, lp,0);
|
|
|
|
ra->ra_wlabel = 0;
|
|
|
|
}
|
2007-07-21 23:51:47 +04:00
|
|
|
mutex_exit(&ra->ra_disk.dk_openlock);
|
1999-05-29 23:11:41 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIOCWLABEL:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
error = EBADF;
|
|
|
|
else
|
|
|
|
ra->ra_wlabel = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIOCGDEFLABEL:
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
case ODIOCGDEFLABEL:
|
|
|
|
if (cmd == ODIOCGDEFLABEL)
|
|
|
|
tp = &newlabel;
|
|
|
|
else
|
2012-07-11 02:34:37 +04:00
|
|
|
#endif
|
2012-07-11 20:41:16 +04:00
|
|
|
tp = (struct disklabel *)data;
|
2009-03-18 19:00:08 +03:00
|
|
|
memset(tp, 0, sizeof(struct disklabel));
|
1999-05-29 23:11:41 +04:00
|
|
|
tp->d_secsize = lp->d_secsize;
|
|
|
|
tp->d_nsectors = lp->d_nsectors;
|
|
|
|
tp->d_ntracks = lp->d_ntracks;
|
|
|
|
tp->d_ncylinders = lp->d_ncylinders;
|
|
|
|
tp->d_secpercyl = lp->d_secpercyl;
|
|
|
|
tp->d_secperunit = lp->d_secperunit;
|
2015-01-02 22:42:05 +03:00
|
|
|
tp->d_type = DKTYPE_MSCP;
|
1999-05-29 23:11:41 +04:00
|
|
|
tp->d_rpm = 3600;
|
|
|
|
rrmakelabel(tp, ra->ra_mediaid);
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
if (cmd == ODIOCGDEFLABEL) {
|
|
|
|
if (tp->d_npartitions > OLDMAXPARTITIONS)
|
2001-01-08 05:03:45 +03:00
|
|
|
return ENOTTY;
|
2001-01-07 21:09:01 +03:00
|
|
|
memcpy(data, tp, sizeof (struct olddisklabel));
|
|
|
|
}
|
|
|
|
#endif
|
1999-05-29 23:11:41 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
2012-07-11 02:34:37 +04:00
|
|
|
return (error);
|
1999-05-29 23:11:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
radump(dev_t dev, daddr_t blkno, void *va, size_t size)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the size of a partition, if known, or -1 if not.
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
rasize(dev_t dev)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
2012-06-23 00:42:22 +04:00
|
|
|
struct ra_softc *ra = mscp_device_lookup(dev);
|
1999-05-29 23:11:41 +04:00
|
|
|
|
2008-06-11 21:32:30 +04:00
|
|
|
if (!ra)
|
1999-05-29 23:11:41 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (ra->ra_state == DK_CLOSED)
|
2012-06-23 00:42:22 +04:00
|
|
|
if (ra_putonline(dev, ra) == MSCP_FAILED)
|
1999-05-29 23:11:41 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return ra->ra_disk.dk_label->d_partitions[DISKPART(dev)].p_size *
|
|
|
|
(ra->ra_disk.dk_label->d_secsize / DEV_BSIZE);
|
|
|
|
}
|
|
|
|
|
2012-06-23 00:42:22 +04:00
|
|
|
#endif /* NRA || NRACD || NRX */
|
1999-05-29 23:11:41 +04:00
|
|
|
|
|
|
|
#if NRX
|
|
|
|
|
2009-05-12 18:28:22 +04:00
|
|
|
int rxmatch(device_t, cfdata_t, void *);
|
1999-05-29 23:11:41 +04:00
|
|
|
|
2012-10-27 21:17:22 +04:00
|
|
|
CFATTACH_DECL_NEW(rx, sizeof(struct rx_softc),
|
2012-06-23 00:42:22 +04:00
|
|
|
rxmatch, raattach, NULL, NULL);
|
1999-05-29 23:11:41 +04:00
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dev_type_open(rxopen);
|
|
|
|
dev_type_read(rxread);
|
|
|
|
dev_type_write(rxwrite);
|
|
|
|
dev_type_ioctl(rxioctl);
|
|
|
|
dev_type_strategy(rxstrategy);
|
2012-06-23 00:42:22 +04:00
|
|
|
dev_type_dump(radump);
|
2002-09-06 17:18:43 +04:00
|
|
|
dev_type_size(rxsize);
|
|
|
|
|
|
|
|
const struct bdevsw rx_bdevsw = {
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_open = rxopen,
|
|
|
|
.d_close = nullclose,
|
|
|
|
.d_strategy = rxstrategy,
|
|
|
|
.d_ioctl = rxioctl,
|
|
|
|
.d_dump = radump,
|
|
|
|
.d_psize = rxsize,
|
2014-07-25 12:02:18 +04:00
|
|
|
.d_discard = nodiscard,
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_flag = D_DISK
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct cdevsw rx_cdevsw = {
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_open = rxopen,
|
|
|
|
.d_close = nullclose,
|
|
|
|
.d_read = rxread,
|
|
|
|
.d_write = rxwrite,
|
|
|
|
.d_ioctl = rxioctl,
|
|
|
|
.d_stop = nostop,
|
|
|
|
.d_tty = notty,
|
|
|
|
.d_poll = nopoll,
|
|
|
|
.d_mmap = nommap,
|
|
|
|
.d_kqfilter = nokqfilter,
|
2014-07-25 12:10:31 +04:00
|
|
|
.d_discard = nodiscard,
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_flag = D_DISK
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
|
|
|
|
2004-09-25 20:44:30 +04:00
|
|
|
static struct dkdriver rxdkdriver = {
|
|
|
|
rxstrategy, minphys
|
|
|
|
};
|
|
|
|
|
1999-05-29 23:11:41 +04:00
|
|
|
/*
|
|
|
|
* More driver definitions, for generic MSCP code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2009-05-12 18:28:22 +04:00
|
|
|
rxmatch(device_t parent, cfdata_t cf, void *aux)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
|
|
|
struct drive_attach_args *da = aux;
|
|
|
|
struct mscp *mp = da->da_mp;
|
|
|
|
|
|
|
|
if ((da->da_typ & MSCPBUS_DISK) == 0)
|
|
|
|
return 0;
|
|
|
|
if (cf->cf_loc[MSCPBUSCF_DRIVE] != MSCPBUSCF_DRIVE_DEFAULT &&
|
|
|
|
cf->cf_loc[MSCPBUSCF_DRIVE] != mp->mscp_unit)
|
|
|
|
return 0;
|
|
|
|
/*
|
2012-06-23 00:42:22 +04:00
|
|
|
* Check if this disk is a floppy (RX)
|
1999-05-29 23:11:41 +04:00
|
|
|
* Seems to be a safe way to test it per Chris Torek.
|
|
|
|
*/
|
|
|
|
if (MSCP_MID_ECH(1, mp->mscp_guse.guse_mediaid) == 'X' - '@')
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* NRX */
|
|
|
|
|
2012-06-23 00:42:22 +04:00
|
|
|
#if NRACD
|
|
|
|
|
|
|
|
/* Use almost all ra* routines for racd */
|
|
|
|
|
|
|
|
int racdmatch(device_t, cfdata_t, void *);
|
|
|
|
|
2012-10-27 21:17:22 +04:00
|
|
|
CFATTACH_DECL_NEW(racd, sizeof(struct racd_softc),
|
2012-06-23 00:42:22 +04:00
|
|
|
racdmatch, raattach, NULL, NULL);
|
|
|
|
|
|
|
|
dev_type_open(raopen);
|
|
|
|
dev_type_read(raread);
|
|
|
|
dev_type_write(rawrite);
|
|
|
|
dev_type_ioctl(raioctl);
|
|
|
|
dev_type_strategy(rastrategy);
|
|
|
|
dev_type_dump(radump);
|
|
|
|
dev_type_size(rasize);
|
|
|
|
|
|
|
|
const struct bdevsw racd_bdevsw = {
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_open = raopen,
|
|
|
|
.d_close = nullclose,
|
|
|
|
.d_strategy = rastrategy,
|
|
|
|
.d_ioctl = raioctl,
|
|
|
|
.d_dump = radump,
|
|
|
|
.d_psize = rasize,
|
2014-07-25 12:02:18 +04:00
|
|
|
.d_discard = nodiscard,
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_flag = D_DISK
|
2012-06-23 00:42:22 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct cdevsw racd_cdevsw = {
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_open = raopen,
|
|
|
|
.d_close = nullclose,
|
|
|
|
.d_read = raread,
|
|
|
|
.d_write = rawrite,
|
|
|
|
.d_ioctl = raioctl,
|
|
|
|
.d_stop = nostop,
|
|
|
|
.d_tty = notty,
|
|
|
|
.d_poll = nopoll,
|
|
|
|
.d_mmap = nommap,
|
|
|
|
.d_kqfilter = nokqfilter,
|
2014-07-25 12:10:31 +04:00
|
|
|
.d_discard = nodiscard,
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_flag = D_DISK
|
2012-06-23 00:42:22 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct dkdriver racddkdriver = {
|
|
|
|
rastrategy, minphys
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* More driver definitions, for generic MSCP code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
racdmatch(device_t parent, cfdata_t cf, void *aux)
|
|
|
|
{
|
|
|
|
struct drive_attach_args *da = aux;
|
|
|
|
struct mscp *mp = da->da_mp;
|
|
|
|
|
|
|
|
if ((da->da_typ & MSCPBUS_DISK) == 0)
|
|
|
|
return 0;
|
|
|
|
if (cf->cf_loc[MSCPBUSCF_DRIVE] != MSCPBUSCF_DRIVE_DEFAULT &&
|
|
|
|
cf->cf_loc[MSCPBUSCF_DRIVE] != mp->mscp_unit)
|
|
|
|
return 0;
|
|
|
|
/*
|
|
|
|
* Check if this disk is a CD (RRD)
|
|
|
|
*/
|
|
|
|
if (MSCP_MID_ECH(1, mp->mscp_guse.guse_mediaid) == 'R' - '@')
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* NRACD */
|
|
|
|
|
1999-05-29 23:11:41 +04:00
|
|
|
/*
|
|
|
|
* The attach routine only checks and prints drive type.
|
|
|
|
* Bringing the disk online is done when the disk is accessed
|
2005-02-27 03:26:58 +03:00
|
|
|
* the first time.
|
1999-05-29 23:11:41 +04:00
|
|
|
*/
|
|
|
|
void
|
2012-06-23 00:42:22 +04:00
|
|
|
raattach(device_t parent, device_t self, void *aux)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
2006-03-29 10:51:47 +04:00
|
|
|
struct rx_softc *rx = device_private(self);
|
1999-05-29 23:11:41 +04:00
|
|
|
struct drive_attach_args *da = aux;
|
|
|
|
struct mscp *mp = da->da_mp;
|
2012-10-27 21:17:22 +04:00
|
|
|
struct mscp_softc *mi = device_private(parent);
|
1999-05-29 23:11:41 +04:00
|
|
|
struct disklabel *dl;
|
|
|
|
|
2012-10-27 21:17:22 +04:00
|
|
|
rx->ra_dev = self;
|
1999-05-29 23:11:41 +04:00
|
|
|
rx->ra_mediaid = mp->mscp_guse.guse_mediaid;
|
|
|
|
rx->ra_state = DK_CLOSED;
|
|
|
|
rx->ra_hwunit = mp->mscp_unit;
|
|
|
|
mi->mi_dp[mp->mscp_unit] = self;
|
|
|
|
|
2004-09-25 20:44:30 +04:00
|
|
|
#if NRX
|
|
|
|
if (MSCP_MID_ECH(1, mp->mscp_guse.guse_mediaid) == 'X' - '@')
|
2012-10-27 21:17:22 +04:00
|
|
|
disk_init((struct disk *)&rx->ra_disk, device_xname(rx->ra_dev),
|
2007-10-08 20:41:05 +04:00
|
|
|
&rxdkdriver);
|
2004-09-25 20:44:30 +04:00
|
|
|
#endif
|
2012-06-23 00:42:22 +04:00
|
|
|
#if NRACD
|
|
|
|
if (MSCP_MID_ECH(1, mp->mscp_guse.guse_mediaid) == 'R' - '@')
|
2012-10-27 21:17:22 +04:00
|
|
|
disk_init((struct disk *)&rx->ra_disk, device_xname(rx->ra_dev),
|
2012-06-23 00:42:22 +04:00
|
|
|
&racddkdriver);
|
|
|
|
#endif
|
2004-09-25 20:44:30 +04:00
|
|
|
#if NRA
|
2012-06-23 00:42:22 +04:00
|
|
|
if (MSCP_MID_ECH(1, mp->mscp_guse.guse_mediaid) != 'X' - '@' &&
|
|
|
|
MSCP_MID_ECH(1, mp->mscp_guse.guse_mediaid) != 'R' - '@')
|
2012-10-27 21:17:22 +04:00
|
|
|
disk_init((struct disk *)&rx->ra_disk, device_xname(rx->ra_dev),
|
2007-10-08 20:41:05 +04:00
|
|
|
&radkdriver);
|
2004-09-25 20:44:30 +04:00
|
|
|
#endif
|
2012-10-27 21:17:22 +04:00
|
|
|
disk_attach(&rx->ra_disk);
|
1999-05-29 23:11:41 +04:00
|
|
|
|
|
|
|
/* Fill in what we know. The actual size is gotten later */
|
|
|
|
dl = rx->ra_disk.dk_label;
|
|
|
|
|
|
|
|
dl->d_secsize = DEV_BSIZE;
|
|
|
|
dl->d_nsectors = mp->mscp_guse.guse_nspt;
|
|
|
|
dl->d_ntracks = mp->mscp_guse.guse_ngpc * mp->mscp_guse.guse_group;
|
|
|
|
dl->d_secpercyl = dl->d_nsectors * dl->d_ntracks;
|
|
|
|
disk_printtype(mp->mscp_unit, mp->mscp_guse.guse_mediaid);
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("%s: nspt %d group %d ngpc %d rct %d nrpt %d nrct %d\n",
|
2008-04-09 00:08:49 +04:00
|
|
|
device_xname(self), mp->mscp_guse.guse_nspt, mp->mscp_guse.guse_group,
|
1999-05-29 23:11:41 +04:00
|
|
|
mp->mscp_guse.guse_ngpc, mp->mscp_guse.guse_rctsize,
|
|
|
|
mp->mscp_guse.guse_nrpt, mp->mscp_guse.guse_nrct);
|
|
|
|
#endif
|
2004-09-25 20:44:30 +04:00
|
|
|
if (MSCP_MID_ECH(1, mp->mscp_guse.guse_mediaid) != 'X' - '@') {
|
|
|
|
/*
|
|
|
|
* XXX We should try to discover wedges here, but
|
|
|
|
* XXX that would mean being able to do I/O. Should
|
|
|
|
* XXX use config_defer() here.
|
|
|
|
*/
|
|
|
|
}
|
1999-05-29 23:11:41 +04:00
|
|
|
}
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
/*
|
1999-05-29 23:11:41 +04:00
|
|
|
* (Try to) put the drive online. This is done the first time the
|
|
|
|
* drive is opened, or if it har fallen offline.
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
rx_putonline(struct rx_softc *rx)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
|
|
|
struct mscp *mp;
|
2012-10-27 21:17:22 +04:00
|
|
|
struct mscp_softc *mi = device_private(device_parent(rx->ra_dev));
|
1999-05-29 23:11:41 +04:00
|
|
|
|
|
|
|
rx->ra_state = DK_CLOSED;
|
|
|
|
mp = mscp_getcp(mi, MSCP_WAIT);
|
|
|
|
mp->mscp_opcode = M_OP_ONLINE;
|
|
|
|
mp->mscp_unit = rx->ra_hwunit;
|
|
|
|
mp->mscp_cmdref = 1;
|
|
|
|
*mp->mscp_addr |= MSCP_OWN | MSCP_INT;
|
|
|
|
|
|
|
|
/* Poll away */
|
2013-10-25 20:00:35 +04:00
|
|
|
bus_space_read_2(mi->mi_iot, mi->mi_iph, 0);
|
2006-03-29 08:47:13 +04:00
|
|
|
if (tsleep(&rx->ra_state, PRIBIO, "rxonline", 100*100))
|
1999-05-29 23:11:41 +04:00
|
|
|
rx->ra_state = DK_CLOSED;
|
|
|
|
|
|
|
|
if (rx->ra_state == DK_CLOSED)
|
|
|
|
return MSCP_FAILED;
|
|
|
|
|
|
|
|
return MSCP_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if NRX
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open a drive.
|
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
2009-03-15 00:04:01 +03:00
|
|
|
rxopen(dev_t dev, int flag, int fmt, struct lwp *l)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct rx_softc *rx;
|
1999-05-29 23:11:41 +04:00
|
|
|
int unit;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure this is a reasonable open request.
|
|
|
|
*/
|
|
|
|
unit = DISKUNIT(dev);
|
2008-06-11 21:32:30 +04:00
|
|
|
rx = device_lookup_private(&rx_cd, unit);
|
|
|
|
if (!rx)
|
1999-05-29 23:11:41 +04:00
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is the first open; we must first try to put
|
|
|
|
* the disk online (and read the label).
|
|
|
|
*/
|
|
|
|
if (rx->ra_state == DK_CLOSED)
|
|
|
|
if (rx_putonline(rx) == MSCP_FAILED)
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Queue a transfer request, and if possible, hand it to the controller.
|
|
|
|
*
|
|
|
|
* This routine is broken into two so that the internal version
|
|
|
|
* udastrat1() can be called by the (nonexistent, as yet) bad block
|
|
|
|
* revectoring routine.
|
|
|
|
*/
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
rxstrategy(struct buf *bp)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
int unit;
|
|
|
|
struct rx_softc *rx;
|
2002-07-25 16:13:03 +04:00
|
|
|
int b;
|
1999-05-29 23:11:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure this is a reasonable drive to use.
|
|
|
|
*/
|
|
|
|
unit = DISKUNIT(bp->b_dev);
|
2008-06-11 21:32:30 +04:00
|
|
|
if ((rx = device_lookup_private(&rx_cd, unit)) == NULL) {
|
1999-05-29 23:11:41 +04:00
|
|
|
bp->b_error = ENXIO;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If disk is not online, try to put it online */
|
|
|
|
if (rx->ra_state == DK_CLOSED)
|
|
|
|
if (rx_putonline(rx) == MSCP_FAILED) {
|
|
|
|
bp->b_error = EIO;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine the size of the transfer, and make sure it is
|
|
|
|
* within the boundaries of the partition.
|
|
|
|
*/
|
|
|
|
if (bp->b_blkno >= rx->ra_disk.dk_label->d_secperunit) {
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make some statistics... /bqt */
|
2002-07-25 16:13:03 +04:00
|
|
|
b = splbio();
|
|
|
|
disk_busy(&rx->ra_disk);
|
|
|
|
splx(b);
|
2012-10-27 21:17:22 +04:00
|
|
|
mscp_strategy(bp, device_parent(rx->ra_dev));
|
1999-05-29 23:11:41 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
done:
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
rxread(dev_t dev, struct uio *uio, int flag)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (physio(rxstrategy, NULL, dev, B_READ, minphys, uio));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
rxwrite(dev_t dev, struct uio *uio, int flag)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (physio(rxstrategy, NULL, dev, B_WRITE, minphys, uio));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* I/O controls.
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
rxioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
int unit = DISKUNIT(dev);
|
2008-06-11 21:32:30 +04:00
|
|
|
struct rx_softc *rx = device_lookup_private(&rx_cd, unit);
|
2014-12-31 20:06:48 +03:00
|
|
|
int error;
|
1999-05-29 23:11:41 +04:00
|
|
|
|
2014-12-31 22:52:04 +03:00
|
|
|
error = disk_ioctl(&rx->ra_disk, dev, cmd, data, flag, l);
|
2014-12-31 20:06:48 +03:00
|
|
|
if (error != EPASSTHROUGH)
|
|
|
|
return error;
|
|
|
|
else
|
|
|
|
error = 0;
|
|
|
|
|
1999-05-29 23:11:41 +04:00
|
|
|
switch (cmd) {
|
|
|
|
case DIOCWDINFO:
|
|
|
|
case DIOCSDINFO:
|
|
|
|
case DIOCWLABEL:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
rxsize(dev_t dev)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* NRX */
|
|
|
|
|
2009-05-12 18:28:22 +04:00
|
|
|
void rrdgram(device_t, struct mscp *, struct mscp_softc *);
|
|
|
|
void rriodone(device_t, struct buf *);
|
|
|
|
int rronline(device_t, struct mscp *);
|
|
|
|
int rrgotstatus(device_t, struct mscp *);
|
|
|
|
void rrreplace(device_t, struct mscp *);
|
|
|
|
int rrioerror(device_t, struct mscp *, struct buf *);
|
2005-02-04 05:10:35 +03:00
|
|
|
void rrfillin(struct buf *, struct mscp *);
|
2009-05-12 18:28:22 +04:00
|
|
|
void rrbb(device_t, struct mscp *, struct buf *);
|
1999-05-29 23:11:41 +04:00
|
|
|
|
|
|
|
|
|
|
|
struct mscp_device ra_device = {
|
|
|
|
rrdgram,
|
|
|
|
rriodone,
|
|
|
|
rronline,
|
|
|
|
rrgotstatus,
|
|
|
|
rrreplace,
|
|
|
|
rrioerror,
|
|
|
|
rrbb,
|
|
|
|
rrfillin,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle an error datagram.
|
|
|
|
* This can come from an unconfigured drive as well.
|
2005-02-27 03:26:58 +03:00
|
|
|
*/
|
|
|
|
void
|
2009-05-12 18:28:22 +04:00
|
|
|
rrdgram(device_t usc, struct mscp *mp, struct mscp_softc *mi)
|
2005-02-27 03:26:58 +03:00
|
|
|
{
|
2008-04-09 00:08:49 +04:00
|
|
|
if (mscp_decodeerror(usc == NULL?"unconf disk" : device_xname(usc), mp, mi))
|
2005-02-27 03:26:58 +03:00
|
|
|
return;
|
1999-05-29 23:11:41 +04:00
|
|
|
/*
|
|
|
|
* SDI status information bytes 10 and 11 are the microprocessor
|
|
|
|
* error code and front panel code respectively. These vary per
|
|
|
|
* drive type and are printed purely for field service information.
|
|
|
|
*/
|
2005-02-27 03:26:58 +03:00
|
|
|
if (mp->mscp_format == M_FM_SDI)
|
1999-05-29 23:11:41 +04:00
|
|
|
printf("\tsdi uproc error code 0x%x, front panel code 0x%x\n",
|
|
|
|
mp->mscp_erd.erd_sdistat[10],
|
|
|
|
mp->mscp_erd.erd_sdistat[11]);
|
|
|
|
}
|
|
|
|
|
2012-06-23 00:42:22 +04:00
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
void
|
2009-05-12 18:28:22 +04:00
|
|
|
rriodone(device_t usc, struct buf *bp)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
2012-06-23 00:42:22 +04:00
|
|
|
struct ra_softc *ra = device_private(usc);
|
2002-07-25 16:13:03 +04:00
|
|
|
|
2002-11-01 14:31:50 +03:00
|
|
|
disk_unbusy(&ra->ra_disk, bp->b_bcount, (bp->b_flags & B_READ));
|
1999-05-29 23:11:41 +04:00
|
|
|
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A drive came on line. Check its type and size. Return DONE if
|
|
|
|
* we think the drive is truly on line. In any case, awaken anyone
|
|
|
|
* sleeping on the drive on-line-ness.
|
|
|
|
*/
|
|
|
|
int
|
2009-05-12 18:28:22 +04:00
|
|
|
rronline(device_t usc, struct mscp *mp)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
2012-06-23 00:42:22 +04:00
|
|
|
struct ra_softc *ra = device_private(usc);
|
1999-05-29 23:11:41 +04:00
|
|
|
struct disklabel *dl;
|
|
|
|
|
2012-06-23 00:42:22 +04:00
|
|
|
wakeup((void *)&ra->ra_state);
|
1999-05-29 23:11:41 +04:00
|
|
|
if ((mp->mscp_status & M_ST_MASK) != M_ST_SUCCESS) {
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(usc, "attempt to bring on line failed: ");
|
1999-05-29 23:11:41 +04:00
|
|
|
mscp_printevent(mp);
|
|
|
|
return (MSCP_FAILED);
|
|
|
|
}
|
|
|
|
|
2012-06-23 00:42:22 +04:00
|
|
|
ra->ra_state = DK_OPEN;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2012-06-23 00:42:22 +04:00
|
|
|
dl = ra->ra_disk.dk_label;
|
1999-05-29 23:11:41 +04:00
|
|
|
dl->d_secperunit = (daddr_t)mp->mscp_onle.onle_unitsize;
|
|
|
|
|
|
|
|
if (dl->d_secpercyl) {
|
|
|
|
dl->d_ncylinders = dl->d_secperunit/dl->d_secpercyl;
|
2015-01-02 22:42:05 +03:00
|
|
|
dl->d_type = DKTYPE_MSCP;
|
1999-05-29 23:11:41 +04:00
|
|
|
dl->d_rpm = 3600;
|
|
|
|
} else {
|
2015-01-02 22:42:05 +03:00
|
|
|
dl->d_type = DKTYPE_FLOPPY;
|
1999-05-29 23:11:41 +04:00
|
|
|
dl->d_rpm = 300;
|
|
|
|
}
|
2012-06-23 00:42:22 +04:00
|
|
|
rrmakelabel(dl, ra->ra_mediaid);
|
1999-05-29 23:11:41 +04:00
|
|
|
|
|
|
|
return (MSCP_DONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
rrmakelabel(struct disklabel *dl, long type)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
|
|
|
int n, p = 0;
|
|
|
|
|
|
|
|
dl->d_bbsize = BBSIZE;
|
2003-04-03 00:32:01 +04:00
|
|
|
dl->d_sbsize = SBLOCKSIZE;
|
1999-05-29 23:11:41 +04:00
|
|
|
|
|
|
|
/* Create the disk name for disklabel. Phew... */
|
|
|
|
dl->d_typename[p++] = MSCP_MID_CHAR(2, type);
|
|
|
|
dl->d_typename[p++] = MSCP_MID_CHAR(1, type);
|
|
|
|
if (MSCP_MID_ECH(0, type))
|
|
|
|
dl->d_typename[p++] = MSCP_MID_CHAR(0, type);
|
|
|
|
n = MSCP_MID_NUM(type);
|
|
|
|
if (n > 99) {
|
|
|
|
dl->d_typename[p++] = '1';
|
|
|
|
n -= 100;
|
|
|
|
}
|
|
|
|
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_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);
|
|
|
|
}
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
/*
|
1999-05-29 23:11:41 +04:00
|
|
|
* We got some (configured) unit's status. Return DONE if it succeeded.
|
|
|
|
*/
|
|
|
|
int
|
2009-05-12 18:28:22 +04:00
|
|
|
rrgotstatus(device_t usc, struct mscp *mp)
|
2005-02-27 03:26:58 +03:00
|
|
|
{
|
1999-05-29 23:11:41 +04:00
|
|
|
if ((mp->mscp_status & M_ST_MASK) != M_ST_SUCCESS) {
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(usc, "attempt to get status failed: ");
|
1999-05-29 23:11:41 +04:00
|
|
|
mscp_printevent(mp);
|
|
|
|
return (MSCP_FAILED);
|
|
|
|
}
|
|
|
|
/* record for (future) bad block forwarding and whatever else */
|
|
|
|
#ifdef notyet
|
|
|
|
uda_rasave(ui->ui_unit, mp, 1);
|
|
|
|
#endif
|
|
|
|
return (MSCP_DONE);
|
|
|
|
}
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
/*
|
1999-05-29 23:11:41 +04:00
|
|
|
* A replace operation finished.
|
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
2005-02-27 03:26:58 +03:00
|
|
|
void
|
2009-05-12 18:28:22 +04:00
|
|
|
rrreplace(device_t usc, struct mscp *mp)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
panic("udareplace");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A transfer failed. We get a chance to fix or restart it.
|
|
|
|
* Need to write the bad block forwaring code first....
|
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
2005-02-27 03:26:58 +03:00
|
|
|
int
|
2009-05-12 18:28:22 +04:00
|
|
|
rrioerror(device_t usc, struct mscp *mp, struct buf *bp)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
2012-06-23 00:42:22 +04:00
|
|
|
struct ra_softc *ra = device_private(usc);
|
1999-05-29 23:11:41 +04:00
|
|
|
int code = mp->mscp_event;
|
|
|
|
|
|
|
|
switch (code & M_ST_MASK) {
|
|
|
|
/* The unit has fallen offline. Try to figure out why. */
|
|
|
|
case M_ST_OFFLINE:
|
|
|
|
bp->b_error = EIO;
|
|
|
|
ra->ra_state = DK_CLOSED;
|
|
|
|
if (code & M_OFFLINE_UNMOUNTED)
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(usc, "not mounted/spun down\n");
|
1999-05-29 23:11:41 +04:00
|
|
|
if (code & M_OFFLINE_DUPLICATE)
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(usc, "duplicate unit number!!!\n");
|
1999-05-29 23:11:41 +04:00
|
|
|
return MSCP_DONE;
|
|
|
|
|
|
|
|
case M_ST_AVAILABLE:
|
|
|
|
ra->ra_state = DK_CLOSED; /* Force another online */
|
|
|
|
return MSCP_DONE;
|
|
|
|
|
|
|
|
default:
|
2008-04-09 00:08:49 +04:00
|
|
|
printf("%s:", device_xname(usc));
|
1999-05-29 23:11:41 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (MSCP_FAILED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill in disk addresses in a mscp packet waiting for transfer.
|
|
|
|
*/
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
rrfillin(struct buf *bp, struct mscp *mp)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
2012-06-23 00:42:22 +04:00
|
|
|
struct ra_softc *ra;
|
1999-05-29 23:11:41 +04:00
|
|
|
struct disklabel *lp;
|
|
|
|
int part = DISKPART(bp->b_dev);
|
|
|
|
|
2012-06-23 00:42:22 +04:00
|
|
|
ra = mscp_device_lookup(bp->b_dev);
|
|
|
|
lp = ra->ra_disk.dk_label;
|
1999-05-29 23:11:41 +04:00
|
|
|
|
|
|
|
mp->mscp_seq.seq_lbn = lp->d_partitions[part].p_offset + bp->b_blkno;
|
2012-06-23 00:42:22 +04:00
|
|
|
mp->mscp_unit = ra->ra_hwunit;
|
1999-05-29 23:11:41 +04:00
|
|
|
mp->mscp_seq.seq_bytecount = bp->b_bcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A bad block related operation finished.
|
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
2009-05-12 18:28:22 +04:00
|
|
|
rrbb(device_t usc, struct mscp *mp, struct buf *bp)
|
1999-05-29 23:11:41 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
panic("udabb");
|
|
|
|
}
|
2012-06-23 00:42:22 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* (Try to) put the drive online. This is done the first time the
|
|
|
|
* drive is opened, or if it has fallen offline.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ra_putonline(dev_t dev, struct ra_softc *ra)
|
|
|
|
{
|
|
|
|
struct disklabel *dl;
|
|
|
|
const char *msg;
|
|
|
|
|
|
|
|
if (rx_putonline(ra) != MSCP_DONE)
|
|
|
|
return MSCP_FAILED;
|
|
|
|
|
|
|
|
dl = ra->ra_disk.dk_label;
|
|
|
|
|
|
|
|
ra->ra_state = DK_RDLABEL;
|
2012-10-27 21:17:22 +04:00
|
|
|
printf("%s", device_xname(ra->ra_dev));
|
2012-06-23 00:42:22 +04:00
|
|
|
if ((msg = readdisklabel(
|
2012-10-27 21:17:22 +04:00
|
|
|
MAKEDISKDEV(major(dev), device_unit(ra->ra_dev), RAW_PART),
|
2012-06-23 00:42:22 +04:00
|
|
|
rastrategy, dl, NULL)) == NULL) {
|
|
|
|
ra->ra_havelabel = 1;
|
|
|
|
ra->ra_state = DK_OPEN;
|
|
|
|
}
|
|
|
|
#if NRACD
|
|
|
|
else if (cdevsw_lookup(dev) == &racd_cdevsw) {
|
|
|
|
dl->d_partitions[0].p_offset = 0;
|
|
|
|
dl->d_partitions[0].p_size = dl->d_secperunit;
|
|
|
|
dl->d_partitions[0].p_fstype = FS_ISO9660;
|
|
|
|
}
|
|
|
|
#endif /* NRACD */
|
|
|
|
else {
|
|
|
|
printf(": %s", msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(": size %d sectors\n", dl->d_secperunit);
|
|
|
|
|
|
|
|
return MSCP_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline struct ra_softc *
|
|
|
|
mscp_device_lookup(dev_t dev)
|
|
|
|
{
|
|
|
|
struct ra_softc *ra;
|
|
|
|
int unit;
|
|
|
|
|
|
|
|
unit = DISKUNIT(dev);
|
|
|
|
#if NRA
|
|
|
|
if (cdevsw_lookup(dev) == &ra_cdevsw)
|
|
|
|
ra = device_lookup_private(&ra_cd, unit);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#if NRACD
|
|
|
|
if (cdevsw_lookup(dev) == &racd_cdevsw)
|
|
|
|
ra = device_lookup_private(&racd_cd, unit);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#if NRX
|
|
|
|
if (cdevsw_lookup(dev) == &rx_cdevsw)
|
|
|
|
ra = device_lookup_private(&rx_cd, unit);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
panic("mscp_device_lookup: unexpected major %"PRIu32" unit %u",
|
|
|
|
major(dev), unit);
|
|
|
|
return ra;
|
|
|
|
}
|