示例#1
0
/*
 * read the requested number of bytes/lines from the scanner
 */
static int
mustek_read(struct ss_softc *ss, struct buf *bp)
{
	struct mustek_read_cmd cmd;
	struct scsipi_xfer *xs;
	struct scsipi_periph *periph = ss->sc_periph;
	u_long lines_to_read;
	int error;

	SC_DEBUG(periph, SCSIPI_DB1, ("mustek_read: start\n"));

	memset(&cmd, 0, sizeof(cmd));
	cmd.opcode = MUSTEK_READ;

	/* instead of the bytes, the mustek wants the number of lines */
	lines_to_read = bp->b_bcount /
	    ((ss->sio.scan_pixels_per_line * ss->sio.scan_bits_per_pixel) / 8);
	SC_DEBUG(periph, SCSIPI_DB1, ("mustek_read: read %ld lines\n",
	    lines_to_read));
	_lto3b(lines_to_read, cmd.length);

	/*
	 * go ask the adapter to do all this for us
	 */
	xs = scsipi_make_xs(periph,
	    (struct scsipi_generic *) &cmd, sizeof(cmd),
	    (u_char *) bp->b_data, bp->b_bcount,
	    MUSTEK_RETRIES, 10000, bp,
	    XS_CTL_NOSLEEP | XS_CTL_ASYNC | XS_CTL_DATA_IN);
	if (xs == NULL) {
		/*
		 * out of memory. Keep this buffer in the queue, and
		 * retry later.
		 */
		callout_reset(&ss->sc_callout, hz / 2, ssrestart,
		    periph);
		return(0);
	}
#ifdef DIAGNOSTIC
	if (BUFQ_GET(ss->buf_queue) != bp)
		panic("ssstart(): dequeued wrong buf");
#else
	BUFQ_GET(ss->buf_queue);
#endif
	error = scsipi_execute_xs(xs);
	/* with a scsipi_xfer preallocated, scsipi_command can't fail */
	KASSERT(error == 0);
	ss->sio.scan_lines -= lines_to_read;
#if 0
	if (ss->sio.scan_lines < 0)
		ss->sio.scan_lines = 0;
#endif
	ss->sio.scan_window_size -= bp->b_bcount;
#if 0
	if (ss->sio.scan_window_size < 0)
		ss->sio.scan_window_size = 0;
#endif
	return (0);
}
示例#2
0
static int
scanjet_read(struct ss_softc *ss, struct buf *bp)
{
	struct scsi_rw_scanner cmd;
	struct scsipi_xfer *xs;
	struct scsipi_periph *periph = ss->sc_periph;
	int error;

	/*
	 *  Fill out the scsi command
	 */
	memset(&cmd, 0, sizeof(cmd));
	cmd.opcode = READ;

	/*
	 * Handle "fixed-block-mode" tape drives by using the
	 * block count instead of the length.
	 */
	_lto3b(bp->b_bcount, cmd.len);

	/*
	 * go ask the adapter to do all this for us
	 */
	xs = scsipi_make_xs(periph,
	    (struct scsipi_generic *) &cmd, sizeof(cmd),
	    (u_char *) bp->b_data, bp->b_bcount,
	    SCANJET_RETRIES, 100000, bp,
	    XS_CTL_NOSLEEP | XS_CTL_ASYNC | XS_CTL_DATA_IN);
	if (xs == NULL) {
		/*
		 * out of memory. Keep this buffer in the queue, and
		 * retry later.
		 */
		callout_reset(&ss->sc_callout, hz / 2, ssrestart,
		    periph);
		return(0);
	}
#ifdef DIAGNOSTIC
	if (BUFQ_GET(ss->buf_queue) != bp)
		panic("ssstart(): dequeued wrong buf");
#else
	BUFQ_GET(ss->buf_queue);
#endif
	error = scsipi_execute_xs(xs);
	/* with a scsipi_xfer preallocated, scsipi_command can't fail */
	KASSERT(error == 0);
	ss->sio.scan_window_size -= bp->b_bcount;
#if 0
	if (ss->sio.scan_window_size < 0)
		ss->sio.scan_window_size = 0;
#endif
	return (0);
}
示例#3
0
int
scsipi_command(struct scsipi_periph *periph, struct scsipi_generic *cmd,
    int cmdlen, u_char *data_addr, int datalen, int retries, int timeout,
    struct buf *bp, int flags)
{
	struct scsipi_xfer *xs;

	xs = scsipi_make_xs(periph, cmd, cmdlen, data_addr, datalen, retries,
	    timeout, bp, flags);
	if (!xs)
		return (ENOMEM);

	return (scsipi_execute_xs(xs));
}
示例#4
0
int
scsipi_command(struct scsipi_periph *periph, struct scsipi_generic *cmd,
               int cmdlen, u_char *data_addr, int datalen, int retries, int timeout,
               struct buf *bp, int flags)
{
    struct scsipi_xfer *xs;
    int rc;

    /*
     * execute unlocked to allow waiting for memory
     */
    xs = scsipi_make_xs_unlocked(periph, cmd, cmdlen, data_addr, datalen, retries,
                                 timeout, bp, flags);
    if (!xs)
        return (ENOMEM);

    mutex_enter(chan_mtx(periph->periph_channel));
    rc = scsipi_execute_xs(xs);
    mutex_exit(chan_mtx(periph->periph_channel));

    return rc;
}