1995-05-30 08:16:23 +00:00
|
|
|
/*
|
1995-03-04 20:51:10 +00:00
|
|
|
* pt: Processor Type driver.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995, HD Associates, Inc.
|
|
|
|
* PO Box 276
|
|
|
|
* Pepperell, MA 01463
|
|
|
|
* 508 433 5266
|
|
|
|
* dufault@hda.com
|
|
|
|
*
|
|
|
|
* This code is contributed to the University of California at Berkeley:
|
|
|
|
*
|
|
|
|
* 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 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.
|
|
|
|
*
|
1998-06-17 14:13:15 +00:00
|
|
|
* $Id: pt.c,v 1.27 1998/01/24 02:54:49 eivind Exp $
|
1995-03-04 20:51:10 +00:00
|
|
|
*/
|
|
|
|
|
1996-01-05 20:12:53 +00:00
|
|
|
#include "opt_bounce.h"
|
1998-01-24 02:54:56 +00:00
|
|
|
#include "opt_devfs.h"
|
1996-07-14 10:46:56 +00:00
|
|
|
#include "opt_scsi.h"
|
1996-01-05 20:12:53 +00:00
|
|
|
|
1995-03-04 20:51:10 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/buf.h>
|
1995-11-29 10:49:16 +00:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#ifdef DEVFS
|
|
|
|
#include <sys/devfsext.h>
|
|
|
|
#endif /*DEVFS*/
|
1995-12-08 11:19:42 +00:00
|
|
|
#include <scsi/scsiconf.h>
|
1997-03-23 06:33:55 +00:00
|
|
|
#include <scsi/scsi_debug.h>
|
|
|
|
#include <scsi/scsi_driver.h>
|
1995-12-08 11:19:42 +00:00
|
|
|
|
1998-06-17 14:13:15 +00:00
|
|
|
#include "ioconf.h"
|
|
|
|
|
1995-03-04 20:51:10 +00:00
|
|
|
struct scsi_data {
|
1995-11-19 22:22:35 +00:00
|
|
|
struct buf_queue_head buf_queue;
|
1998-01-06 08:28:46 +00:00
|
|
|
#ifdef DEVFS
|
|
|
|
void *devfs_data_tok;
|
|
|
|
void *devfs_ctl_tok;
|
|
|
|
#endif
|
1995-03-04 20:51:10 +00:00
|
|
|
};
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static d_open_t ptopen;
|
|
|
|
static d_close_t ptclose;
|
|
|
|
static d_ioctl_t ptioctl;
|
|
|
|
static d_strategy_t ptstrategy;
|
|
|
|
|
|
|
|
#define CDEV_MAJOR 61
|
1995-12-08 23:23:00 +00:00
|
|
|
static struct cdevsw pt_cdevsw =
|
1995-12-08 11:19:42 +00:00
|
|
|
{ ptopen, ptclose, rawread, rawwrite, /*61*/
|
|
|
|
ptioctl, nostop, nullreset, nodevtotty,/* pt */
|
|
|
|
seltrue, nommap, ptstrategy, "pt", NULL, -1 };
|
|
|
|
|
1995-03-04 20:51:10 +00:00
|
|
|
SCSI_DEVICE_ENTRIES(pt)
|
|
|
|
|
1996-03-10 07:13:15 +00:00
|
|
|
static void ptstart(u_int32_t unit, u_int32_t flags);
|
1995-12-14 19:51:15 +00:00
|
|
|
static void pt_strategy(struct buf *bp, struct scsi_link *sc_link);
|
|
|
|
static int pt_sense(struct scsi_xfer *scsi_xfer);
|
1995-12-08 11:19:42 +00:00
|
|
|
|
1995-12-14 09:55:16 +00:00
|
|
|
static struct scsi_device pt_switch =
|
1995-03-04 20:51:10 +00:00
|
|
|
{
|
1995-04-14 15:10:44 +00:00
|
|
|
pt_sense,
|
1995-03-04 20:51:10 +00:00
|
|
|
ptstart, /* we have a queue, and this is how we service it */
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
"pt",
|
|
|
|
0,
|
|
|
|
{0, 0},
|
|
|
|
SDEV_ONCE_ONLY, /* Only one open allowed */
|
1997-05-21 19:35:11 +00:00
|
|
|
ptattach,
|
1995-03-04 20:51:10 +00:00
|
|
|
"Processor",
|
|
|
|
ptopen,
|
|
|
|
sizeof(struct scsi_data),
|
|
|
|
T_PROCESSOR,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
pt_strategy,
|
|
|
|
};
|
1995-12-14 19:51:15 +00:00
|
|
|
|
1997-05-21 19:35:11 +00:00
|
|
|
static errval
|
|
|
|
ptattach(struct scsi_link *sc_link)
|
|
|
|
{
|
|
|
|
struct scsi_data *pt = sc_link->sd;
|
|
|
|
|
1997-09-21 22:03:22 +00:00
|
|
|
bufq_init(&pt->buf_queue);
|
1998-01-06 08:28:46 +00:00
|
|
|
|
|
|
|
#ifdef DEVFS
|
|
|
|
pt->devfs_data_tok = devfs_add_devswf(&pt_cdevsw,
|
|
|
|
sc_link->dev_unit,
|
|
|
|
DV_CHR,
|
|
|
|
UID_ROOT, GID_WHEEL, 0600,
|
|
|
|
"pt%d", sc_link->dev_unit);
|
|
|
|
pt->devfs_ctl_tok = devfs_add_devswf(&pt_cdevsw,
|
|
|
|
sc_link->dev_unit | SCSI_CONTROL_MASK,
|
|
|
|
DV_CHR,
|
|
|
|
UID_ROOT, GID_WHEEL, 0600,
|
|
|
|
"pt%d.ctl", sc_link->dev_unit);
|
|
|
|
#endif
|
1997-05-21 19:35:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-03-04 20:51:10 +00:00
|
|
|
/*
|
|
|
|
* ptstart looks to see if there is a buf waiting for the device
|
|
|
|
* and that the device is not already busy. If both are true,
|
|
|
|
* It dequeues the buf and creates a scsi command to perform the
|
|
|
|
* transfer required. The transfer request will call scsi_done
|
|
|
|
* on completion, which will in turn call this routine again
|
|
|
|
* so that the next queued transfer is performed.
|
|
|
|
* The bufs are queued by the strategy routine (ptstrategy)
|
|
|
|
*
|
|
|
|
* This routine is also called after other non-queued requests
|
|
|
|
* have been made of the scsi driver, to ensure that the queue
|
|
|
|
* continues to be drained.
|
|
|
|
* ptstart() is called at splbio
|
|
|
|
*/
|
1995-12-14 09:55:16 +00:00
|
|
|
static void
|
1995-04-23 22:07:56 +00:00
|
|
|
ptstart(unit, flags)
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t unit;
|
|
|
|
u_int32_t flags;
|
1995-03-04 20:51:10 +00:00
|
|
|
{
|
|
|
|
struct scsi_link *sc_link = SCSI_LINK(&pt_switch, unit);
|
|
|
|
struct scsi_data *pt = sc_link->sd;
|
|
|
|
register struct buf *bp = 0;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
#define PROCESSOR_SEND 0x0A
|
|
|
|
#define PROCESSOR_RECEIVE 0x08
|
|
|
|
u_char op_code;
|
|
|
|
u_char byte2;
|
|
|
|
u_char len[3];
|
|
|
|
u_char control;
|
|
|
|
} cmd;
|
|
|
|
|
|
|
|
|
|
|
|
SC_DEBUG(sc_link, SDEV_DB2, ("ptstart "));
|
|
|
|
/*
|
|
|
|
* See if there is a buf to do and we are not already
|
|
|
|
* doing one
|
|
|
|
*/
|
|
|
|
while (sc_link->opennings != 0) {
|
|
|
|
|
|
|
|
/* if a special awaits, let it proceed first */
|
|
|
|
if (sc_link->flags & SDEV_WAITING) {
|
|
|
|
sc_link->flags &= ~SDEV_WAITING;
|
|
|
|
wakeup((caddr_t)sc_link);
|
|
|
|
return;
|
|
|
|
}
|
1995-11-19 22:22:35 +00:00
|
|
|
|
1997-09-21 22:03:22 +00:00
|
|
|
bp = bufq_first(&pt->buf_queue);
|
1995-11-19 22:22:35 +00:00
|
|
|
if (bp == NULL) { /* yes, an assign */
|
|
|
|
return;
|
1995-03-04 20:51:10 +00:00
|
|
|
}
|
1997-09-21 22:03:22 +00:00
|
|
|
bufq_remove(&pt->buf_queue, bp);
|
1995-03-04 20:51:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill out the scsi command
|
|
|
|
*/
|
|
|
|
bzero(&cmd, sizeof(cmd));
|
|
|
|
if ((bp->b_flags & B_READ) == B_WRITE) {
|
|
|
|
cmd.op_code = PROCESSOR_SEND;
|
1995-04-23 22:07:56 +00:00
|
|
|
flags |= SCSI_DATA_OUT;
|
1995-03-04 20:51:10 +00:00
|
|
|
} else {
|
|
|
|
cmd.op_code = PROCESSOR_RECEIVE;
|
1995-04-23 22:07:56 +00:00
|
|
|
flags |= SCSI_DATA_IN;
|
1995-03-04 20:51:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
scsi_uto3b(bp->b_bcount, cmd.len);
|
|
|
|
/*
|
|
|
|
* go ask the adapter to do all this for us
|
|
|
|
*/
|
|
|
|
if (scsi_scsi_cmd(sc_link,
|
|
|
|
(struct scsi_generic *) &cmd,
|
|
|
|
sizeof(cmd),
|
1997-12-02 21:07:20 +00:00
|
|
|
(u_char *) bp->b_data,
|
1995-03-04 20:51:10 +00:00
|
|
|
bp->b_bcount,
|
1995-04-14 15:10:44 +00:00
|
|
|
0,
|
|
|
|
10000,
|
1995-03-04 20:51:10 +00:00
|
|
|
bp,
|
1995-04-23 22:07:56 +00:00
|
|
|
flags) == SUCCESSFULLY_QUEUED) {
|
1995-03-04 20:51:10 +00:00
|
|
|
} else {
|
1995-04-14 15:10:44 +00:00
|
|
|
printf("pt%ld: oops not queued\n", unit);
|
1995-03-04 20:51:10 +00:00
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = EIO;
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
} /* go back and see if we can cram more work in.. */
|
|
|
|
}
|
|
|
|
|
1995-12-14 09:55:16 +00:00
|
|
|
static void
|
1995-03-04 20:51:10 +00:00
|
|
|
pt_strategy(struct buf *bp, struct scsi_link *sc_link)
|
|
|
|
{
|
|
|
|
unsigned char unit;
|
1996-03-10 07:13:15 +00:00
|
|
|
u_int32_t opri;
|
1995-03-04 20:51:10 +00:00
|
|
|
struct scsi_data *pt;
|
|
|
|
|
1995-05-03 18:09:20 +00:00
|
|
|
unit = minor((bp->b_dev));
|
1995-03-04 20:51:10 +00:00
|
|
|
pt = sc_link->sd;
|
|
|
|
|
|
|
|
opri = splbio();
|
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
/*
|
1995-03-04 20:51:10 +00:00
|
|
|
* Use a bounce buffer if necessary
|
1995-05-30 08:16:23 +00:00
|
|
|
*/
|
1995-03-04 20:51:10 +00:00
|
|
|
#ifdef BOUNCE_BUFFERS
|
|
|
|
if (sc_link->flags & SDEV_BOUNCE)
|
|
|
|
vm_bounce_alloc(bp);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Place it in the queue of activities for this tape
|
|
|
|
* at the end (a bit silly because we only have one user..
|
|
|
|
* (but it could fork() ))
|
|
|
|
*/
|
1997-09-21 22:03:22 +00:00
|
|
|
bufq_insert_tail(&pt->buf_queue, bp);
|
1995-03-04 20:51:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell the device to get going on the transfer if it's
|
|
|
|
* not doing anything, otherwise just wait for completion
|
|
|
|
* (All a bit silly if we're only allowing 1 open but..)
|
|
|
|
*/
|
1995-04-23 22:07:56 +00:00
|
|
|
ptstart(unit, 0);
|
1995-03-04 20:51:10 +00:00
|
|
|
|
|
|
|
splx(opri);
|
|
|
|
return;
|
|
|
|
}
|
1995-04-14 15:10:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* sense handler: Called to determine what to do when the
|
|
|
|
* device returns a CHECK CONDITION.
|
|
|
|
*
|
|
|
|
* For the processor type devices we try to handle the "info" field.
|
|
|
|
*/
|
|
|
|
|
1995-12-14 09:55:16 +00:00
|
|
|
static int
|
|
|
|
pt_sense(struct scsi_xfer *xs)
|
1995-04-14 15:10:44 +00:00
|
|
|
{
|
|
|
|
struct scsi_sense_data *sense = &(xs->sense);
|
|
|
|
struct buf *bp;
|
|
|
|
|
|
|
|
long resid;
|
|
|
|
|
|
|
|
if ((sense->error_code & SSD_ERRCODE_VALID) == 0 ||
|
|
|
|
(sense->ext.extended.flags & SSD_ILI) == 0) {
|
|
|
|
return SCSIRET_CONTINUE; /* let the default handler handle it */
|
|
|
|
}
|
|
|
|
|
1996-03-10 18:17:54 +00:00
|
|
|
resid = ntohl(*((int32_t *) sense->ext.extended.info));
|
1995-04-14 15:10:44 +00:00
|
|
|
|
|
|
|
bp = xs->bp;
|
|
|
|
|
|
|
|
if (resid < 0) {
|
|
|
|
/* It synthesized data in order to fill our request.
|
|
|
|
* Move resid back to cover this.
|
|
|
|
*/
|
|
|
|
xs->resid = -resid;
|
|
|
|
xs->flags |= SCSI_RESID_VALID;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* It wanted to send more data. We can't really do anything
|
|
|
|
* about this.
|
|
|
|
*/
|
|
|
|
return SCSIRET_CONTINUE;
|
|
|
|
}
|
|
|
|
}
|
1995-11-29 10:49:16 +00:00
|
|
|
|
|
|
|
static pt_devsw_installed = 0;
|
|
|
|
|
1998-01-06 08:28:46 +00:00
|
|
|
static void
|
|
|
|
pt_drvinit(void *unused)
|
1995-11-29 10:49:16 +00:00
|
|
|
{
|
|
|
|
dev_t dev;
|
|
|
|
|
1998-01-06 08:28:46 +00:00
|
|
|
if ( ! pt_devsw_installed ) {
|
1995-12-08 11:19:42 +00:00
|
|
|
dev = makedev(CDEV_MAJOR, 0);
|
|
|
|
cdevsw_add(&dev,&pt_cdevsw, NULL);
|
1995-11-29 10:49:16 +00:00
|
|
|
pt_devsw_installed = 1;
|
1998-01-06 08:28:46 +00:00
|
|
|
}
|
1995-11-29 10:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SYSINIT(ptdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,pt_drvinit,NULL)
|
|
|
|
|
|
|
|
|