<commit_before>
/*
 * Streamer tape driver for 386bsd and FreeBSD.
 * Supports Archive and Wangtek compatible QIC-02/QIC-36 boards.
 *
 * Copyright (C) 1993 by:
 *      <NAME>       <<EMAIL>>
 *      <NAME>      <<EMAIL>>
 *
 * This software is distributed with NO WARRANTIES, not even the implied
 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Authors grant any other persons or organisations permission to use
 * or modify this software as long as this message is kept with the software,
 * all derivative works or modified versions.
 *
 * This driver is derived from the old 386bsd Wangtek streamer tape driver,
 * made by <NAME> at CMU, based on Intel sources.
 * Authors thank <NAME>, CMU and Intel and retain here
 * the original CMU copyright notice.
 *
 * Version 1.3, Thu Nov 11 12:09:13 MSK 1993
 * $Id: wt.c,v 1.39 1997/03/24 11:24:14 bde Exp $
 *
 */

/*
 * Code for MTERASE added by <NAME> (<EMAIL>) 95/09/02.
 * This was very easy due to the excellent structure and clear coding
 * of the original driver.
 */

/*
 * Copyright (c) 1989 Carnegie-Mellon University.
 * All rights reserved.
 *
 * Authors: <NAME>
 *
 * Permission to use, copy, modify and distribute this software and
 * its documentation is hereby granted, provided that both the copyright
 * notice and this permission notice appear in all copies of the
 * software, derivative works or modified versions, and any portions
 * thereof, and that both notices appear in supporting documentation.
 *
 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
 *
 * Carnegie Mellon requests users of this software to return to
 *
 *  Software Distribution Coordinator  or  <EMAIL>
 *  School of Computer Science
 *  Carnegie Mellon University
 *  Pittsburgh PA 15213-3890
 *
 * any improvements or extensions that they make and grant Carnegie the
 * rights to redistribute these changes.
 */

#include "wt.h"
#if NWT > 0

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/buf.h>
#include <sys/fcntl.h>
#include <sys/malloc.h>
#include <sys/mtio.h>
#include <sys/conf.h>
#ifdef DEVFS
#include <sys/devfsext.h>
#endif /*DEVFS*/

#include <machine/clock.h>

#include <i386/isa/isa_device.h>
#include <i386/isa/wtreg.h>


/*
 * Uncomment this to enable internal device tracing.
 */
#define TRACE(s)                /* printf s */

#define WTPRI                   (PZERO+10)      /* sleep priority */

/*
 * Wangtek controller ports
 */
#define WT_CTLPORT(base)        ((base)+0)      /* control, write only */
#define WT_STATPORT(base)       ((base)+0)      /* status, read only */
#define WT_CMDPORT(base)        ((base)+1)      /* command, write only */
#define WT_DATAPORT(base)       ((base)+1)      /* data, read only */
#define WT_NPORT                2               /* 2 i/o ports */

/* status port bits */
#define WT_BUSY                 0x01            /* not ready bit define */
#define WT_NOEXCEP              0x02            /* no exception bit define */
#define WT_RESETMASK            0x07            /* to check after reset */
#define WT_RESETVAL             0x05            /* state after reset */

/* control port bits */
#define WT_ONLINE               0x01            /* device selected */
#define WT_RESET                0x02            /* reset command */
#define WT_REQUEST              0x04            /* request command */
#define WT_IEN                  0x08            /* enable dma */

/*
 * Archive controller ports
 */
#define AV_DATAPORT(base)       ((base)+0)      /* data, read only */
#define AV_CMDPORT(base)        ((base)+0)      /* command, write only */
#define AV_STATPORT(base)       ((base)+1)      /* status, read only */
#define AV_CTLPORT(base)        ((base)+1)      /* control, write only */
#define AV_SDMAPORT(base)       ((base)+2)      /* start dma */
#define AV_RDMAPORT(base)       ((base)+3)      /* reset dma */
#define AV_NPORT                4               /* 4 i/o ports */

/* status port bits */
#define AV_BUSY                 0x40            /* not ready bit define */
#define AV_NOEXCEP              0x20            /* no exception bit define */
#define AV_RESETMASK            0xf8            /* to check after reset */
#define AV_RESETVAL             0x50            /* state after reset */

/* control port bits */
#define AV_RESET                0x80            /* reset command */
#define AV_REQUEST              0x40            /* request command */
#define AV_IEN                  0x20            /* enable interrupts */

enum wttype {
	UNKNOWN = 0,                    /* unknown type, driver disabled */
	ARCHIVE,                        /* Archive Viper SC499, SC402 etc */
	WANGTEK,                        /* Wangtek */
};

typedef struct {
	unsigned short err;             /* code for error encountered */
	unsigned short ercnt;           /* number of error blocks */
	unsigned short urcnt;           /* number of underruns */
} wtstatus_t;

typedef struct {
	enum wttype type;               /* type of controller */
	unsigned unit;                  /* unit number */
	unsigned port;                  /* base i/o port */
	unsigned chan;                  /* dma channel number, 1..3 */
	unsigned flags;                 /* state of tape drive */
	unsigned dens;                  /* tape density */
	int bsize;                      /* tape block size */
	void *buf;                      /* internal i/o buffer */

	void *dmavaddr;                 /* virtual address of dma i/o buffer */
	unsigned dmatotal;              /* size of i/o buffer */
	unsigned dmaflags;              /* i/o direction, B_READ or B_WRITE */
	unsigned dmacount;              /* resulting length of dma i/o */

	wtstatus_t error;               /* status of controller */

	unsigned short DATAPORT, CMDPORT, STATPORT, CTLPORT, SDMAPORT, RDMAPORT;
	unsigned char BUSY, NOEXCEP, RESETMASK, RESETVAL;
	unsigned char ONLINE, RESET, REQUEST, IEN;
#ifdef	DEVFS<commit_msg>Fixed pedantic syntax error (trailing comma in enum).<commit_after>
/*
 * Streamer tape driver for 386bsd and FreeBSD.
 * Supports Archive and Wangtek compatible QIC-02/QIC-36 boards.
 *
 * Copyright (C) 1993 by:
 *      <NAME>       <<EMAIL>>
 *      <NAME>      <<EMAIL>>
 *
 * This software is distributed with NO WARRANTIES, not even the implied
 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Authors grant any other persons or organisations permission to use
 * or modify this software as long as this message is kept with the software,
 * all derivative works or modified versions.
 *
 * This driver is derived from the old 386bsd Wangtek streamer tape driver,
 * made by <NAME> at CMU, based on Intel sources.
 * Authors thank <NAME>, CMU and Intel and retain here
 * the original CMU copyright notice.
 *
 * Version 1.3, Thu Nov 11 12:09:13 MSK 1993
 * $Id: wt.c,v 1.40 1997/07/20 14:10:18 bde Exp $
 *
 */

/*
 * Code for MTERASE added by <NAME> (<EMAIL>) 95/09/02.
 * This was very easy due to the excellent structure and clear coding
 * of the original driver.
 */

/*
 * Copyright (c) 1989 Carnegie-Mellon University.
 * All rights reserved.
 *
 * Authors: <NAME>
 *
 * Permission to use, copy, modify and distribute this software and
 * its documentation is hereby granted, provided that both the copyright
 * notice and this permission notice appear in all copies of the
 * software, derivative works or modified versions, and any portions
 * thereof, and that both notices appear in supporting documentation.
 *
 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
 *
 * Carnegie Mellon requests users of this software to return to
 *
 *  Software Distribution Coordinator  or  <EMAIL>
 *  School of Computer Science
 *  Carnegie Mellon University
 *  Pittsburgh PA 15213-3890
 *
 * any improvements or extensions that they make and grant Carnegie the
 * rights to redistribute these changes.
 */

#include "wt.h"
#if NWT > 0

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/buf.h>
#include <sys/fcntl.h>
#include <sys/malloc.h>
#include <sys/mtio.h>
#include <sys/conf.h>
#ifdef DEVFS
#include <sys/devfsext.h>
#endif /*DEVFS*/

#include <machine/clock.h>

#include <i386/isa/isa_device.h>
#include <i386/isa/wtreg.h>


/*
 * Uncomment this to enable internal device tracing.
 */
#define TRACE(s)                /* printf s */

#define WTPRI                   (PZERO+10)      /* sleep priority */

/*
 * Wangtek controller ports
 */
#define WT_CTLPORT(base)        ((base)+0)      /* control, write only */
#define WT_STATPORT(base)       ((base)+0)      /* status, read only */
#define WT_CMDPORT(base)        ((base)+1)      /* command, write only */
#define WT_DATAPORT(base)       ((base)+1)      /* data, read only */
#define WT_NPORT                2               /* 2 i/o ports */

/* status port bits */
#define WT_BUSY                 0x01            /* not ready bit define */
#define WT_NOEXCEP              0x02            /* no exception bit define */
#define WT_RESETMASK            0x07            /* to check after reset */
#define WT_RESETVAL             0x05            /* state after reset */

/* control port bits */
#define WT_ONLINE               0x01            /* device selected */
#define WT_RESET                0x02            /* reset command */
#define WT_REQUEST              0x04            /* request command */
#define WT_IEN                  0x08            /* enable dma */

/*
 * Archive controller ports
 */
#define AV_DATAPORT(base)       ((base)+0)      /* data, read only */
#define AV_CMDPORT(base)        ((base)+0)      /* command, write only */
#define AV_STATPORT(base)       ((base)+1)      /* status, read only */
#define AV_CTLPORT(base)        ((base)+1)      /* control, write only */
#define AV_SDMAPORT(base)       ((base)+2)      /* start dma */
#define AV_RDMAPORT(base)       ((base)+3)      /* reset dma */
#define AV_NPORT                4               /* 4 i/o ports */

/* status port bits */
#define AV_BUSY                 0x40            /* not ready bit define */
#define AV_NOEXCEP              0x20            /* no exception bit define */
#define AV_RESETMASK            0xf8            /* to check after reset */
#define AV_RESETVAL             0x50            /* state after reset */

/* control port bits */
#define AV_RESET                0x80            /* reset command */
#define AV_REQUEST              0x40            /* request command */
#define AV_IEN                  0x20            /* enable interrupts */

enum wttype {
	UNKNOWN = 0,                    /* unknown type, driver disabled */
	ARCHIVE,                        /* Archive Viper SC499, SC402 etc */
	WANGTEK                         /* Wangtek */
};

typedef struct {
	unsigned short err;             /* code for error encountered */
	unsigned short ercnt;           /* number of error blocks */
	unsigned short urcnt;           /* number of underruns */
} wtstatus_t;

typedef struct {
	enum wttype type;               /* type of controller */
	unsigned unit;                  /* unit number */
	unsigned port;                  /* base i/o port */
	unsigned chan;                  /* dma channel number, 1..3 */
	unsigned flags;                 /* state of tape drive */
	unsigned dens;                  /* tape density */
	int bsize;                      /* tape block size */
	void *buf;                      /* internal i/o buffer */

	void *dmavaddr;                 /* virtual address of dma i/o buffer */
	unsigned dmatotal;              /* size of i/o buffer */
	unsigned dmaflags;              /* i/o direction, B_READ or B_WRITE */
	unsigned dmacount;              /* resulting length of dma i/o */

	wtstatus_t error;               /* status of controller */

	unsigned short DATAPORT, CMDPORT, STATPORT, CTLPORT, SDMAPORT, RDMAPORT;
	unsigned char BUSY, NOEXCEP, RESETMASK, RESETVAL;
	unsigned char ONLINE, RESET, REQUEST, IEN;
#ifdef	DEVFS
{'fraction_non_alphanumeric': 0.10032733224222586, 'fraction_numerical': 0.022913256955810146, 'mean_word_length': 2.0220079129574677, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6769039', 'n_tokens_mistral': 3718, 'n_tokens_neox': 3434, 'n_words': 1290}