Add PC-Card/ISA SCSI host adpater drivers from NetBSD/pc98

(a NetBSD port for NEC PC-98x1 machines). They are ncv for NCR 53C500,
nsp for Workbit Ninja SCSI-3, and stg for TMC 18C30 and 18C50.

I thank NetBSD/pc98 and bsd-nomads people.

Obtained from:	NetBSD/pc98
This commit is contained in:
Noriaki Mitsunaga 2000-10-23 12:55:51 +00:00
parent 1e832bf81d
commit ae94720d12
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=67468
29 changed files with 10072 additions and 0 deletions

View File

@ -94,6 +94,10 @@ device bt
device aha 1
device aic
device ncv # NCR 53C500
device nsp # Workbit Ninja SCSI-3
device stg # TMC 18C30/18C50
# RAID controllers interfaced to the SCSI subsystem
device asr # DPT SmartRAID V, VI and Adaptec SCSI RAID
device dpt # DPT Smartcache III, IV - See NOTES for options!

58
sys/cam/scsi/scsi_dvcfg.h Normal file
View File

@ -0,0 +1,58 @@
/* $FreeBSD$ */
/* $NecBSD: scsi_dvcfg.h,v 1.4 1998/03/14 07:05:06 kmatsuda Exp $ */
/* $NetBSD$ */
/*
* [NetBSD for NEC PC-98 series]
* Copyright (c) 1994, 1995, 1996, 1997, 1998
* NetBSD/pc98 porting staff. All rights reserved.
* Copyright (c) 1994, 1995, 1996, 1997, 1998
* Naofumi HONDA. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#ifndef _SCSI_DVCFG_H_
#define _SCSI_DVCFG_H_
/* common dvcfg flags defitions for bs, ncv, stg */
#define DVF_SCSI_SYNC 0x01
#define DVF_SCSI_DISC 0x02
#define DVF_SCSI_WAIT 0x04
#define DVF_SCSI_LINK 0x08
#define DVF_SCSI_QTAG 0x10
#define DVF_SCSI_SP0 0x100
#define DVF_SCSI_NOPARITY 0x200
#define DVF_SCSI_SAVESP 0x400
#define DVF_SCSI_SP1 0x800
#define DVF_SCSI_PERIOD(XXX) (((XXX) >> 24) & 0xff)
#define DVF_SCSI_OFFSET(XXX) (((XXX) >> 16) & 0xff)
#define DVF_SCSI_SYNCMASK 0xffff0000
#define DVF_SCSI_DEFCFG (DVF_SCSI_SYNC | DVF_SCSI_NOPARITY | DVF_SCSI_SYNCMASK)
#define DVF_SCSI_BITS "\020\13fssp\12noparity\11nosat\005qtag\004cmdlnk\003wait\002disc\001sync"
#endif /* !_SCSI_DVCFG_H_ */

2590
sys/cam/scsi/scsi_low.c Normal file

File diff suppressed because it is too large Load Diff

615
sys/cam/scsi/scsi_low.h Normal file
View File

@ -0,0 +1,615 @@
/* $FreeBSD$ */
/* $NecBSD: scsi_low.h,v 1.24 1999/07/23 21:00:05 honda Exp $ */
/* $NetBSD$ */
#define SCSI_LOW_DIAGNOSTIC
/*
* [NetBSD for NEC PC-98 series]
* Copyright (c) 1995, 1996, 1997, 1998
* NetBSD/pc98 porting staff. All rights reserved.
* Copyright (c) 1995, 1996, 1997, 1998
* Naofumi HONDA. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#ifndef _SCSI_LOW_H_
#define _SCSI_LOW_H_
#ifdef __NetBSD__
#include <i386/Cbus/dev/scsi_dvcfg.h>
#endif
#ifdef __FreeBSD__
#include <sys/device_port.h>
#define CAM
#include <cam/cam.h>
#include <cam/cam_ccb.h>
#include <cam/cam_sim.h>
#include <cam/cam_xpt_sim.h>
#include <cam/cam_debug.h>
#include <cam/scsi/scsi_dvcfg.h>
#endif
/* user configuration flags defs */
#define SCSI_LOW_SYNC DVF_SCSI_SYNC
#define SCSI_LOW_DISC DVF_SCSI_DISC
#define SCSI_LOW_WAIT DVF_SCSI_WAIT
#define SCSI_LOW_LINK DVF_SCSI_LINK
#define SCSI_LOW_QTAG DVF_SCSI_QTAG
#define SCSI_LOW_NOPARITY DVF_SCSI_NOPARITY
#define SCSI_LOW_SAVESP DVF_SCSI_SAVESP
#define SCSI_LOW_DEFCFG DVF_SCSI_DEFCFG
#define SCSI_LOW_BITS DVF_SCSI_BITS
#define SCSI_LOW_PERIOD(n) DVF_SCSI_PERIOD(n)
#define SCSI_LOW_OFFSET(n) DVF_SCSI_OFFSET(n)
/* host scsi id and targets macro */
#ifndef SCSI_LOW_NTARGETS
#define SCSI_LOW_NTARGETS 8
#endif /* SCSI_LOW_NTARGETS */
#define SCSI_LOW_NCCB 32
#define SCSI_LOW_MAX_MSGLEN 16
#define SCSI_LOW_MAX_RETRY 3
/* timeout control macro */
#define SCSI_LOW_MIN_TOUT 24
#define SCSI_LOW_TIMEOUT_CHECK_INTERVAL 4
#define SCSI_LOW_POWDOWN_TC 15
#define SCSI_LOW_MAX_PHCHANGES 256
/* max synch period */
#ifndef SCSI_LOW_MAX_SYNCH_SPEED
#define SCSI_LOW_MAX_SYNCH_SPEED (100) /* 10.0M */
#endif /* !SCSI_LOW_MAX_SYNCH_SPEED */
/*************************************************
* Scsi Data Pointer
*************************************************/
/* scsi pointer */
struct sc_p {
u_int8_t *scp_data;
int scp_datalen;
u_int8_t *scp_cmd;
int scp_cmdlen;
u_int scp_direction;
#define SCSI_LOW_RWUNK (-1)
#define SCSI_LOW_WRITE 0
#define SCSI_LOW_READ 1
};
#define SCSI_LOW_SETUP_PHASE(ti, phase) \
{ \
if ((ti)->ti_phase != (phase)) \
{ \
(ti)->ti_ophase = ti->ti_phase; \
(ti)->ti_phase = (phase); \
} \
}
#define SCSI_LOW_SETUP_MSGPHASE(slp, PHASE) \
{ \
(slp)->sl_msgphase = (PHASE); \
}
#define SCSI_LOW_TARGET_ASSERT_ATN(slp) \
{ \
(ti)->ti_tflags |= TARG_ASSERT_ATN; \
}
/*************************************************
* Command Control Block Structure
*************************************************/
typedef int scsi_low_tag_t;
struct targ_info;
#define SCSI_LOW_UNKLUN ((u_int) -1)
#define SCSI_LOW_UNKTAG ((scsi_low_tag_t) -1)
struct slccb {
TAILQ_ENTRY(slccb) ccb_chain;
#ifdef CAM
union ccb *ccb;
struct buf *bp;
#else
struct scsipi_xfer *xs; /* scsi upper */
#endif
struct targ_info *ti; /* targ_info */
struct lun_info *li; /* lun info */
scsi_low_tag_t ccb_tag; /* tag */
/*****************************************
* Scsi data pointers (original and saved)
*****************************************/
struct sc_p ccb_scp; /* given */
struct sc_p ccb_sscp; /* saved scsi data pointer */
#ifdef SCSI_LOW_SUPPORT_USER_MSGOUT
u_int8_t msgout[SCSI_LOW_MAX_MSGLEN]; /* scsi msgout */
u_int msgoutlen;
#endif /* SCSI_LOW_SUPPORT_USER_MSGOUT */
/*****************************************
* Error or Timeout counters
*****************************************/
u_int ccb_flags;
#define CCB_SENSE 0x01
u_int ccb_error;
int ccb_rcnt; /* retry counter */
int ccb_tc; /* timer counter */
int ccb_tcmax; /* max timeout */
/*****************************************
* Sense data buffer
*****************************************/
#ifdef __NetBSD__
struct scsipi_sense ccb_sense_cmd;
struct scsipi_sense_data ccb_sense;
#endif
#ifdef __FreeBSD__
struct scsi_sense ccb_sense_cmd;
struct scsi_sense_data ccb_sense;
#endif
};
/* ccb assert */
#ifdef __NetBSD__
#include <dev/isa/ccbque.h>
#endif
#ifdef __FreeBSD__
#include <i386/isa/ccbque.h>
#endif
GENERIC_CCB_ASSERT(scsi_low, slccb)
/*************************************************
* Target structures
*************************************************/
struct scsi_low_softc;
TAILQ_HEAD(targ_info_tab, targ_info);
LIST_HEAD(lun_info_tab, lun_info);
struct lun_info {
int li_lun;
struct targ_info *li_ti; /* my target */
LIST_ENTRY(lun_info) lun_chain; /* targ_info link */
int li_disc; /* num disconnects */
int li_maxnexus;
/*
* lun state
*/
#define UNIT_SLEEP 0x00
#define UNIT_START 0x01
#define UNIT_SYNCH 0x02
#define UNIT_WIDE 0x03
#define UNIT_OK 0x04
#define UNIT_NEGSTART UNIT_SYNCH
u_int li_state; /* target lun state */
u_int li_maxstate; /* max state */
/*
* lun control flags
*/
u_int li_flags; /* real control flags */
u_int li_cfgflags; /* given target cfgflags */
u_int li_quirks; /* given target quirk */
/*
* lun synch and wide data
*/
struct synch {
u_int8_t offset;
u_int8_t period;
} li_maxsynch; /* synch data */
u_int li_width;
};
struct targ_info {
TAILQ_ENTRY(targ_info) ti_chain; /* targ_info link */
struct scsi_low_softc *ti_sc; /* our softc */
u_int ti_id; /* scsi id */
/*
* Lun chain
*/
struct lun_info_tab ti_litab; /* lun chain */
/*
* Nexus
*/
struct slccb *ti_nexus; /* current nexus */
struct lun_info *ti_li; /* current nexus lun_info */
/*
* Target status
*/
#define TARG_ASSERT_ATN 0x01
u_int ti_tflags; /* target state I */
/*
* Scsi phase control
*/
struct slccbtab ti_discq; /* disconnect queue */
#define PH_NULL 0x00
#define PH_ARBSTART 0x01
#define PH_SELSTART 0x02
#define PH_SELECTED 0x03
#define PH_CMD 0x04
#define PH_DATA 0x05
#define PH_MSGIN 0x06
#define PH_MSGOUT 0x07
#define PH_STAT 0x08
#define PH_DISC 0x09
#define PH_RESEL 0x0a
u_int ti_phase; /* scsi phase */
u_int ti_ophase; /* old scsi phase */
/*
* Status in
*/
u_int8_t ti_status; /* status in */
/*
* Msg in
*/
u_int ti_msginptr; /* msgin ptr */
u_int ti_msginlen; /* expected msg length */
u_int8_t ti_msgin[SCSI_LOW_MAX_MSGLEN]; /* msgin buffer */
u_int ti_sphase;
#ifdef SCSI_LOW_DIAGNOSTIC
#define MSGIN_HISTORY_LEN 5
u_int8_t ti_msgin_history[MSGIN_HISTORY_LEN];
int ti_msgin_hist_pointer;
#endif /* SCSI_LOW_DIAGNOSTIC */
/*
* Msg out
*/
u_int ti_msgflags; /* msgs to be asserted */
u_int ti_omsgflags; /* msgs asserted */
u_int ti_emsgflags; /* a msg currently asserted */
#define SCSI_LOW_MSG_RESET 0x00000001
#define SCSI_LOW_MSG_ABORT 0x00000002
#define SCSI_LOW_MSG_REJECT 0x00000004
#define SCSI_LOW_MSG_PARITY 0x00000008
#define SCSI_LOW_MSG_ERROR 0x00000010
#define SCSI_LOW_MSG_IDENTIFY 0x00000020
#define SCSI_LOW_MSG_SYNCH 0x00000040
#define SCSI_LOW_MSG_WIDE 0x00000080
#define SCSI_LOW_MSG_USER 0x00000100
#define SCSI_LOW_MSG_NOOP 0x00000200
#define SCSI_LOW_MSG_ALL 0xffffffff
/* msgout buffer */
u_int8_t ti_msgoutstr[SCSI_LOW_MAX_MSGLEN]; /* scsi msgout */
u_int ti_msgoutlen; /* msgout strlen */
/*
* lun info size.
*/
int ti_lunsize;
};
/*************************************************
* COMMON HEADER STRUCTURE
*************************************************/
struct scsi_low_softc;
typedef struct scsi_low_softc *sc_low_t;
#define SCSI_LOW_START_OK 0
#define SCSI_LOW_START_FAIL 1
#define SC_LOW_INIT_T (int (*) __P((sc_low_t, int)))
#define SC_LOW_BUSRST_T (void (*) __P((sc_low_t)))
#define SC_LOW_LUN_INIT_T (int (*) __P((sc_low_t, struct targ_info *, struct lun_info *)))
#define SC_LOW_SELECT_T (int (*) __P((sc_low_t, struct slccb *)))
#define SC_LOW_ATTEN_T (void (*) __P((sc_low_t)))
#define SC_LOW_NEXUS_T (int (*) __P((sc_low_t, struct targ_info *)))
#define SC_LOW_MSG_T (int (*) __P((sc_low_t, struct targ_info *, u_int)))
#define SC_LOW_POLL_T (int (*) __P((void *)))
#define SC_LOW_POWER_T (int (*) __P((sc_low_t, u_int)))
struct scsi_low_funcs {
int (*scsi_low_init) __P((sc_low_t, int));
void (*scsi_low_bus_reset) __P((sc_low_t));
int (*scsi_low_lun_init) __P((sc_low_t, struct targ_info *, struct lun_info *));
int (*scsi_low_start_bus) __P((sc_low_t, struct slccb *));
int (*scsi_low_establish_nexus) __P((sc_low_t, struct targ_info *));
void (*scsi_low_attention) __P((sc_low_t));
int (*scsi_low_msg) __P((sc_low_t, struct targ_info *, u_int));
int (*scsi_low_poll) __P((void *));
#define SCSI_LOW_POWDOWN 1
#define SCSI_LOW_ENGAGE 2
int (*scsi_low_power) __P((sc_low_t, u_int));
};
/*************************************************
* SCSI LOW SOFTC
*************************************************/
struct scsi_low_softc {
DEVPORT_DEVICE sl_dev;
u_char sl_xname[16];
/* upper interface */
#ifdef CAM
struct cam_sim *sim;
struct cam_path *path;
#else
struct scsipi_link sl_link;
#endif
/* my targets */
struct targ_info *sl_ti[SCSI_LOW_NTARGETS];
struct targ_info_tab sl_titab;
/* current active nexus */
int sl_nexus_call;
struct targ_info *sl_nexus;
/* ccb start queue */
struct slccbtab sl_start;
/* retry limit and phase change counter */
int sl_max_retry;
int sl_ph_count;
/* selection & total num disconnect targets */
int sl_disc;
struct targ_info *sl_selid;
/* scsi phased suggested by scsi msg */
u_int sl_msgphase;
#define MSGPH_NULL 0x00 /* no msg */
#define MSGPH_DISC 0x01 /* disconnect msg */
#define MSGPH_CMDC 0x02 /* cmd complete msg */
/* error */
#define FATALIO 0x01 /* generic io error & retry io */
#define ABORTIO 0x02 /* generic io error & terminate io */
#define TIMEOUTIO 0x04 /* watch dog timeout */
#define SELTIMEOUTIO 0x08 /* selection timeout */
#define PDMAERR 0x10 /* dma xfer error */
#define MSGERR 0x20 /* msgsys error */
#define PARITYERR 0x40 /* parity error */
#define BUSYERR 0x80 /* target busy error */
#define CMDREJECT 0x100 /* cmd reject error */
#define SCSI_LOW_ERRORBITS "\020\009cmdrej\008busy\007parity\006msgerr\005pdmaerr\004seltimeout\003timeout\002abort\001fatal"
u_int sl_error; /* error flags */
/* current scsi data pointer */
struct sc_p sl_scp;
/* power control */
u_int sl_active; /* host is busy state */
int sl_powc; /* power down timer counter */
u_int sl_rstep; /* resume step */
/* configuration flags */
u_int sl_flags;
#define HW_POWDOWN 0x01
#define HW_RESUME 0x02
#define HW_PDMASTART 0x04
#define HW_INACTIVE 0x08
#define HW_POWERCTRL 0x10
u_int sl_cfgflags;
#define CFG_NODISC 0x01
#define CFG_NOPARITY 0x02
#define CFG_NOATTEN 0x04
#define CFG_ASYNC 0x08
#define CFG_MSGUNIFY 0x10
/* host informations */
u_int sl_hostid;
int sl_nluns;
int sl_ntargs;
int sl_openings;
/* interface functions */
struct scsi_low_funcs *sl_funcs;
#if defined(i386)
u_int sl_irq; /* XXX */
#endif /* i386 */
#ifdef __FreeBSD__
struct callout_handle engage_ch;
struct callout_handle timeout_ch;
#ifdef SCSI_LOW_POWFUNC
struct callout_handle recover_ch;
#endif
#endif /* __FreeBSD__ */
};
/*************************************************
* SCSI LOW service functions
*************************************************/
/*
* Scsi low attachment function.
*/
int scsi_low_attach __P((struct scsi_low_softc *, int, int, int, int));
int scsi_low_dettach __P((struct scsi_low_softc *));
/*
* Scsi phase "bus service" functions.
* These functions are corresponding to each scsi bus phaeses.
*/
/* nexus abort (selection failed) */
void scsi_low_clear_nexus __P((struct scsi_low_softc *, struct targ_info *));
/* msgout phase */
int scsi_low_msgout __P((struct scsi_low_softc *, struct targ_info *));
/* msgin phase */
void scsi_low_msgin __P((struct scsi_low_softc *, struct targ_info *, u_int8_t));
/* data phase */
int scsi_low_data __P((struct scsi_low_softc *, struct targ_info *, struct buf **, int));
/* cmd phase */
int scsi_low_cmd __P((struct scsi_low_softc *, struct targ_info *));
/* reselection phase */
struct targ_info *scsi_low_reselected __P((struct scsi_low_softc *, u_int));
/* disconnection phase */
int scsi_low_disconnected __P((struct scsi_low_softc *, struct targ_info *));
/*
* Scsi bus restart function.
* Canncel all established nexuses => scsi system initialized => restart jobs.
*/
#define SCSI_LOW_RESTART_HARD 1
#define SCSI_LOW_RESTART_SOFT 0
int scsi_low_restart __P((struct scsi_low_softc *, int, u_char *));
/*
* Scsi utility fucntions
*/
/* print current status */
void scsi_low_print __P((struct scsi_low_softc *, struct targ_info *));
/* timeout utility (only in used scsi_low_pisa) */
void scsi_low_timeout __P((void *));
#define SCSI2_RESET_DELAY 5000000
#define TWIDDLEWAIT 10000
/* bus reset utility */
void scsi_low_bus_reset __P((struct scsi_low_softc *));
/*************************************************
* Inline utility
*************************************************/
static __inline u_int8_t scsi_low_identify __P((struct targ_info *ti));
static __inline void scsi_low_attention __P((struct scsi_low_softc *, struct targ_info *));
static __inline int scsi_low_is_msgout_continue __P((struct targ_info *));
static __inline int scsi_low_assert_msg __P((struct scsi_low_softc *, struct targ_info *, u_int, int));
static __inline void scsi_low_arbit_win __P((struct scsi_low_softc *, struct targ_info *));
static __inline int
scsi_low_is_msgout_continue(ti)
struct targ_info *ti;
{
return (ti->ti_msgflags != 0);
}
static __inline u_int8_t
scsi_low_identify(ti)
struct targ_info *ti;
{
u_int8_t msg;
struct lun_info *li = ti->ti_li;
msg = (li->li_flags & SCSI_LOW_DISC) ? 0xc0 : 0x80;
msg |= li->li_lun;
return msg;
}
#define ID_MSG_SETUP(ti) (scsi_low_identify(ti))
static __inline void
scsi_low_attention(slp, ti)
struct scsi_low_softc *slp;
struct targ_info *ti;
{
(*slp->sl_funcs->scsi_low_attention) (slp);
SCSI_LOW_TARGET_ASSERT_ATN(slp);
}
static __inline int
scsi_low_assert_msg(slp, ti, msg, now)
struct scsi_low_softc *slp;
struct targ_info *ti;
u_int msg;
int now;
{
ti->ti_msgflags |= msg;
if (now != 0)
scsi_low_attention(slp, ti);
return 0;
}
static __inline void
scsi_low_arbit_win(slp, ti)
struct scsi_low_softc *slp;
struct targ_info *ti;
{
slp->sl_selid = NULL;
}
/*************************************************
* Message out defs
*************************************************/
/* XXX: use scsi_message.h */
#define ST_GOOD 0x00
#define ST_CHKCOND 0x02
#define ST_MET 0x04
#define ST_BUSY 0x08
#define ST_INTERGOOD 0x10
#define ST_INTERMET 0x14
#define ST_CONFLICT 0x18
#define ST_QUEFULL 0x28
#define MSG_COMP 0x00
#define MSG_EXTEND 0x01
#define MKMSG_EXTEND(XLEN, XCODE) ((((u_int)(XLEN)) << NBBY) | ((u_int)(XCODE)))
#define MSG_EXTEND_MDPCODE 0x00
#define MSG_EXTEND_MDPLEN 0x05
#define MSG_EXTEND_SYNCHCODE 0x01
#define MSG_EXTEND_SYNCHLEN 0x03
#define MSG_EXTEND_WIDECODE 0x03
#define MSG_EXTEND_WIDELEN 0x02
#define MSG_SAVESP 0x02
#define MSG_RESTORESP 0x03
#define MSG_DISCON 0x04
#define MSG_I_ERROR 0x05
#define MSG_ABORT 0x06
#define MSG_REJECT 0x07
#define MSG_NOOP 0x08
#define MSG_PARITY 0x09
#define MSG_LCOMP 0x0a
#define MSG_LCOMP_F 0x0b
#define MSG_RESET 0x0c
#ifdef __FreeBSD__
#undef MSG_IDENTIFY
#endif
#define MSG_IDENTIFY 0x80
#define OS_DEPEND(s) (s)
#endif /* !_SCSI_LOW_H_ */

View File

@ -0,0 +1,181 @@
/* $FreeBSD$ */
/* $NecBSD: scsi_low_pisa.c,v 1.13 1998/11/26 14:26:11 honda Exp $ */
/* $NetBSD$ */
/*
* [NetBSD for NEC PC-98 series]
* Copyright (c) 1995, 1996, 1997, 1998
* NetBSD/pc98 porting staff. All rights reserved.
* Copyright (c) 1995, 1996, 1997, 1998
* Naofumi HONDA. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/disklabel.h>
#if defined(__FreeBSD__) && __FreeBSD_version >= 500001
#include <sys/bio.h>
#endif
#include <sys/buf.h>
#include <sys/queue.h>
#include <sys/malloc.h>
#include <sys/device_port.h>
#include <sys/errno.h>
#include <vm/vm.h>
#include <machine/bus.h>
#ifdef __NetBSD__
#include <machine/intr.h>
#endif
#ifdef __NetBSD__
#include <dev/isa/isareg.h>
#include <dev/isa/isavar.h>
#include <dev/isa/pisaif.h>
#endif
#include <machine/dvcfg.h>
#ifdef __NetBSD__
#include <dev/scsipi/scsi_all.h>
#include <dev/scsipi/scsipi_all.h>
#include <dev/scsipi/scsiconf.h>
#include <dev/scsipi/scsi_disk.h>
#include <i386/Cbus/dev/scsi_low.h>
#include <i386/Cbus/dev/scsi_low_pisa.h>
#define SCSIBUS_RESCAN
#else
#ifdef __FreeBSD__
#include <i386/isa/isa_device.h>
#include <i386/isa/icu.h>
#include <cam/scsi/scsi_low.h>
#include <cam/scsi/scsi_low_pisa.h>
#endif
#endif
#ifdef __FreeBSD__
int
scsi_low_deactivate(struct scsi_low_softc *sc)
{
#else
#ifdef __NetBSD__
int
scsi_low_deactivate(dh)
pisa_device_handle_t dh;
{
struct scsi_low_softc *sc = PISA_DEV_SOFTC(dh);
#endif
#endif
sc->sl_flags |= HW_INACTIVE;
#ifdef __NetBSD__
#ifdef SCSI_LOW_POWFUNC
untimeout(scsi_low_recover, sc);
#endif /* SCSI_LOW_POWFUNC */
untimeout(scsi_low_timeout, sc);
#else
#ifdef __FreeBSD__
#ifdef SCSI_LOW_POWFUNC
untimeout(scsi_low_recover, sc, sc->recover_ch);
#endif /* SCSI_LOW_POWFUNC */
untimeout(scsi_low_timeout, sc, sc->timeout_ch);
#endif
#endif
return 0;
}
#ifdef __FreeBSD__
int
scsi_low_activate(struct scsi_low_softc *sc, struct isa_device *dev)
{
#else
#ifdef __NetBSD__
int
scsi_low_activate(dh)
pisa_device_handle_t dh;
{
struct scsi_low_softc *sc = PISA_DEV_SOFTC(dh);
slot_device_res_t dr = PISA_RES_DR(dh);
#endif
#endif
int error;
sc->sl_flags &= ~HW_INACTIVE;
#ifdef __FreeBSD__
sc->sl_cfgflags = ((sc->sl_cfgflags << 16) | ((dev->id_flags) & 0xffff));
#else /* __NetBSD__ */
sc->sl_cfgflags = DVCFG_MKCFG(DVCFG_MAJOR(sc->sl_cfgflags), \
DVCFG_MINOR(PISA_DR_DVCFG(dr)));
sc->sl_irq = PISA_DR_IRQ(dr);
#endif
if ((error = scsi_low_restart(sc, SCSI_LOW_RESTART_HARD, NULL)) != 0)
{
sc->sl_flags |= HW_INACTIVE;
return error;
}
#ifdef __FreeBSD__
sc->timeout_ch =
#endif
timeout(scsi_low_timeout, sc, SCSI_LOW_TIMEOUT_CHECK_INTERVAL * hz);
/* rescan the scsi bus */
#ifdef SCSIBUS_RESCAN
if (PISA_RES_EVENT(dh) == PISA_EVENT_INSERT &&
sc->sl_start.tqh_first == NULL)
scsi_probe_busses((int) sc->sl_link.scsipi_scsi.scsibus, -1, -1);
#endif
return 0;
}
#ifdef __NetBSD__
int
scsi_low_notify(dh, ev)
pisa_device_handle_t dh;
pisa_event_t ev;
{
struct scsi_low_softc *sc = PISA_DEV_SOFTC(dh);
switch(ev)
{
case PISA_EVENT_QUERY_SUSPEND:
if (sc->sl_start.tqh_first != NULL)
return SD_EVENT_STATUS_BUSY;
break;
default:
break;
}
return 0;
}
#endif

View File

@ -0,0 +1,46 @@
/* $FreeBSD$ */
/* $NecBSD: scsi_low_pisa.h,v 1.3 1999/04/15 01:35:57 kmatsuda Exp $ */
/* $NetBSD$ */
/*
* [NetBSD for NEC PC-98 series]
* Copyright (c) 1998
* NetBSD/pc98 porting staff. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#ifndef _SCSI_LOW_PISA_H_
#define _SCSI_LOW_PISA_H_
#ifdef __NetBSD__
int scsi_low_activate __P((pisa_device_handle_t));
int scsi_low_deactivate __P((pisa_device_handle_t));
int scsi_low_notify __P((pisa_device_handle_t, pisa_event_t));
#endif
#ifdef __FreeBSD__
int scsi_low_activate __P((struct scsi_low_softc *, struct isa_device *));
int scsi_low_deactivate __P((struct scsi_low_softc *));
#endif
#endif /* !_SCSI_LOW_PISA_H_ */

View File

@ -0,0 +1,89 @@
/* $FreeBSD$ */
/* $NecBSD: physio_proc.h,v 3.4 1999/07/23 20:47:03 honda Exp $ */
/* $NetBSD$ */
/*
* [NetBSD for NEC PC-98 series]
* Copyright (c) 1998
* NetBSD/pc98 porting staff. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#ifndef _I386_PHYSIO_PROC_H_
#define _I386_PHYSIO_PROC_H_
#include <sys/buf.h>
#include <sys/queue.h>
struct physio_proc;
TAILQ_HEAD(physio_proc_head, physio_proc);
struct physio_proc_head physio_proc_freet, physio_proc_busyt;
struct physio_proc {
TAILQ_ENTRY(physio_proc) pp_chain;
struct proc *pp_proc;
};
static __inline struct physio_proc *physio_proc_enter __P((struct buf *));
static __inline void physio_proc_leave __P((struct physio_proc *));
static __inline struct physio_proc *
physio_proc_enter(bp)
struct buf *bp;
{
struct physio_proc *pp;
int s;
if (bp == NULL || (bp->b_flags & B_PHYS) == 0)
return NULL;
if ((pp = physio_proc_freet.tqh_first) == NULL)
return NULL;
s = splstatclock();
TAILQ_REMOVE(&physio_proc_freet, pp, pp_chain);
#if !defined(__FreeBSD__) || __FreeBSD_version < 400001
pp->pp_proc = bp->b_proc;
#endif
TAILQ_INSERT_TAIL(&physio_proc_busyt, pp, pp_chain);
splx(s);
return pp;
}
static __inline void
physio_proc_leave(pp)
struct physio_proc *pp;
{
int s;
if (pp == NULL)
return;
s = splstatclock();
TAILQ_REMOVE(&physio_proc_busyt, pp, pp_chain);
TAILQ_INSERT_TAIL(&physio_proc_freet, pp, pp_chain);
pp->pp_proc = NULL;
splx(s);
}
void physio_proc_init __P((void));
#endif /* _I386_PHYSIO_PROC_H_ */

View File

@ -1263,10 +1263,13 @@ options AML_DEBUG
# ISP 12160 Ultra3 SCSI,
# Qlogic ISP 2100 and ISP 2200 Fibre Channel host adapters.
# ncr: NCR 53C810, 53C825 self-contained SCSI host adapters.
# ncv: NCR 53C500 based SCSI host adapters.
# nsp: Workbit Ninja SCSI-3 based PC Card SCSI host adapters.
# sym: Symbios/Logic 53C8XX family of PCI-SCSI I/O processors:
# 53C810, 53C810A, 53C815, 53C825, 53C825A, 53C860, 53C875,
# 53C876, 53C885, 53C895, 53C895A, 53C896, 53C897, 53C1510D,
# 53C1010-33, 53C1010-66.
# stg: TMC 18C30, 18C50 based SCSI host adapters.
#
# Note that the order is important in order for Buslogic ISA/EISA cards to be
@ -1287,7 +1290,10 @@ device amd
device isp
device ispfw
device ncr
device ncv
device nsp
device sym
device stg
# The aic7xxx driver will attempt to use memory mapped I/O for all PCI
# controllers that have it configured only if this option is set. Unfortunately,

View File

@ -27,6 +27,12 @@ cam/scsi/scsi_all.c optional scbus
cam/scsi/scsi_cd.c optional cd
cam/scsi/scsi_ch.c optional ch
cam/scsi/scsi_da.c optional da
cam/scsi/scsi_low.c optional ncv
cam/scsi/scsi_low.c optional nsp
cam/scsi/scsi_low.c optional stg
cam/scsi/scsi_low_pisa.c optional ncv
cam/scsi/scsi_low_pisa.c optional nsp
cam/scsi/scsi_low_pisa.c optional stg
cam/scsi/scsi_pass.c optional pass
cam/scsi/scsi_pt.c optional pt
cam/scsi/scsi_sa.c optional sa
@ -216,6 +222,10 @@ dev/lnc/if_lnc.c count lnc
dev/lnc/if_lnc_isa.c optional lnc isa
dev/lnc/if_lnc_pc98.c optional lnc isa
dev/lnc/if_lnc_pci.c optional lnc pci
dev/ncv/ncr53c500.c optional ncv
dev/ncv/ncr53c500_pccard.c optional ncv card
dev/nsp/nsp.c optional nsp
dev/nsp/nsp_pccard.c optional nsp card
dev/mca/mca_bus.c optional mca
dev/md/md.c optional md
dev/mii/amphy.c optional miibus
@ -339,6 +349,9 @@ dev/sound/pcm/mixer.c optional pcm
dev/sound/pcm/sound.c optional pcm
#dev/sound/usb/upcm.c optional pcm usb
dev/streams/streams.c optional streams
dev/stg/tmc18c30.c optional stg
dev/stg/tmc18c30_pccard.c optional stg card
dev/stg/tmc18c30_isa.c optional stg isa
dev/sym/sym_hipd.c optional sym \
dependency "$S/dev/sym/sym_{conf,defs}.h"
dev/tdfx/tdfx_pci.c optional tdfx

1197
sys/dev/ncv/ncr53c500.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,414 @@
/* $FreeBSD$ */
/* $NecBSD: ncr53c500_pisa.c,v 1.28 1998/11/26 01:59:11 honda Exp $ */
/* $NetBSD$ */
/*
* [Ported for FreeBSD]
* Copyright (c) 2000
* Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe.
* All rights reserved.
* [NetBSD for NEC PC-98 series]
* Copyright (c) 1995, 1996, 1997, 1998
* NetBSD/pc98 porting staff. All rights reserved.
* Copyright (c) 1995, 1996, 1997, 1998
* Naofumi HONDA. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/disklabel.h>
#if defined(__FreeBSD__) && __FreeBSD_version >= 500001
#include <sys/bio.h>
#endif
#include <sys/buf.h>
#include <sys/queue.h>
#include <sys/malloc.h>
#include <sys/errno.h>
#include <vm/vm.h>
#include <machine/bus.h>
#include <machine/bus_pio.h>
#include <i386/isa/isa_device.h>
#include <machine/dvcfg.h>
#if defined(__FreeBSD__) && __FreeBSD_version < 400001
static struct ncv_softc *ncv_get_softc(int);
extern struct ncv_softc *ncvdata[];
#define DEVPORT_ALLOCSOFTCFUNC ncv_get_softc
#define DEVPORT_SOFTCARRAY ncvdata
#endif
#include <sys/device_port.h>
#include <cam/scsi/scsi_low.h>
#include <cam/scsi/scsi_low_pisa.h>
#include <dev/ncv/ncr53c500reg.h>
#include <dev/ncv/ncr53c500hw.h>
#include <dev/ncv/ncr53c500var.h>
#if defined(__NetBSD__) || (defined(__FreeBSD__) && __FreeBSD_version < 400001)
#include "ncv.h"
#endif
#define KME_KXLC004_01 0x1
#define OFFSET_KME_KXLC004_01 0x10
/* pccard support */
#include "apm.h"
#if NAPM > 0
#include <machine/apm_bios.h>
#endif /* NAPM > 0 */
#include "card.h"
#if NCARD > 0
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/select.h>
#include <pccard/cardinfo.h>
#include <pccard/slot.h>
static int ncvprobe(DEVPORT_PDEVICE devi);
static int ncvattach(DEVPORT_PDEVICE devi);
static int ncv_card_intr __P((DEVPORT_PDEVICE));
static void ncv_card_unload __P((DEVPORT_PDEVICE));
#if defined(__FreeBSD__) && __FreeBSD_version < 400001
static int ncv_card_init __P((DEVPORT_PDEVICE));
#endif
#if defined(__FreeBSD__) && __FreeBSD_version >= 400001
/*
* Additional code for FreeBSD new-bus PCCard frontend
*/
static void
ncv_pccard_intr(void * arg)
{
ncvintr(arg);
}
static void
ncv_release_resource(DEVPORT_PDEVICE dev)
{
struct ncv_softc *sc = device_get_softc(dev);
if (sc->ncv_intrhand) {
bus_teardown_intr(dev, sc->irq_res, sc->ncv_intrhand);
}
if (sc->port_res) {
bus_release_resource(dev, SYS_RES_IOPORT,
sc->port_rid, sc->port_res);
}
if (sc->irq_res) {
bus_release_resource(dev, SYS_RES_IRQ,
sc->irq_rid, sc->irq_res);
}
if (sc->mem_res) {
bus_release_resource(dev, SYS_RES_MEMORY,
sc->mem_rid, sc->mem_res);
}
}
static int
ncv_alloc_resource(DEVPORT_PDEVICE dev)
{
struct ncv_softc *sc = device_get_softc(dev);
u_int32_t flags = DEVPORT_PDEVFLAGS(dev);
u_int iobase = DEVPORT_PDEVIOBASE(dev);
u_long maddr, msize;
int error;
bus_addr_t offset = 0;
if(flags & KME_KXLC004_01)
offset = OFFSET_KME_KXLC004_01;
sc->port_rid = 0;
sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid,
iobase+offset, ~0, NCVIOSZ, RF_ACTIVE);
if (sc->port_res == NULL) {
ncv_release_resource(dev);
return(ENOMEM);
}
sc->irq_rid = 0;
sc->irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irq_rid,
0, ~0, 1, RF_ACTIVE);
if (sc->irq_res == NULL) {
ncv_release_resource(dev);
return(ENOMEM);
}
error = bus_get_resource(dev, SYS_RES_MEMORY, 0, &maddr, &msize);
if (error) {
return(0); /* XXX */
}
/* no need to allocate memory if not configured */
if (maddr == 0 || msize == 0) {
return(0);
}
sc->mem_rid = 0;
sc->mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->mem_rid,
0, ~0, msize, RF_ACTIVE);
if (sc->mem_res == NULL) {
ncv_release_resource(dev);
return(ENOMEM);
}
return(0);
}
static int
ncv_pccard_probe(DEVPORT_PDEVICE dev)
{
struct ncv_softc *sc = device_get_softc(dev);
int error;
bzero(sc, sizeof(struct ncv_softc));
error = ncv_alloc_resource(dev);
if (error) {
return(error);
}
if (ncvprobe(dev) == 0) {
ncv_release_resource(dev);
return(ENXIO);
}
ncv_release_resource(dev);
return(0);
}
static int
ncv_pccard_attach(DEVPORT_PDEVICE dev)
{
struct ncv_softc *sc = device_get_softc(dev);
int error;
error = ncv_alloc_resource(dev);
if (error) {
return(error);
}
error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM,
ncv_pccard_intr, (void *)sc, &sc->ncv_intrhand);
if (error) {
ncv_release_resource(dev);
return(error);
}
if (ncvattach(dev) == 0) {
ncv_release_resource(dev);
return(ENXIO);
}
return(0);
}
static void
ncv_pccard_detach(DEVPORT_PDEVICE dev)
{
ncv_card_unload(dev);
ncv_release_resource(dev);
}
static device_method_t ncv_pccard_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, ncv_pccard_probe),
DEVMETHOD(device_attach, ncv_pccard_attach),
DEVMETHOD(device_detach, ncv_pccard_detach),
{ 0, 0 }
};
static driver_t ncv_pccard_driver = {
"ncv",
ncv_pccard_methods,
sizeof(struct ncv_softc),
};
static devclass_t ncv_devclass;
DRIVER_MODULE(ncv, pccard, ncv_pccard_driver, ncv_devclass, 0, 0);
#else
PCCARD_MODULE(ncv, ncv_card_init, ncv_card_unload, ncv_card_intr, 0, cam_imask);
#endif
#if defined(__FreeBSD__) && __FreeBSD_version < 400001
static struct ncv_softc *
ncv_get_softc(int unit)
{
struct ncv_softc *sc;
if (unit >= NNCV) {
return(NULL);
}
if (ncvdata[unit] == NULL) {
sc = malloc(sizeof(struct ncv_softc), M_TEMP,M_NOWAIT);
if (sc == NULL) {
printf("ncv_get_softc: cannot malloc!\n");
return(NULL);
}
ncvdata[unit] = sc;
} else {
sc = ncvdata[unit];
}
return(sc);
}
static int
ncv_card_init(DEVPORT_PDEVICE devi)
{
int unit = DEVPORT_PDEVUNIT(devi);
if (NNCV <= unit)
return (ENODEV);
if (ncvprobe(devi) == 0)
return (ENXIO);
if (ncvattach(devi) == 0)
return (ENXIO);
return (0);
}
#endif
static void
ncv_card_unload(DEVPORT_PDEVICE devi)
{
struct ncv_softc *sc = DEVPORT_PDEVGET_SOFTC(devi);
printf("%s: unload\n", sc->sc_sclow.sl_xname);
scsi_low_deactivate((struct scsi_low_softc *)sc);
scsi_low_dettach(&sc->sc_sclow);
}
static int
ncv_card_intr(DEVPORT_PDEVICE devi)
{
ncvintr(DEVPORT_PDEVGET_SOFTC(devi));
return 1;
}
static int
ncvprobe(DEVPORT_PDEVICE devi)
{
int rv;
struct ncv_softc *sc = device_get_softc(devi);
u_int32_t flags = DEVPORT_PDEVFLAGS(devi);
#if defined(__FreeBSD__) && __FreeBSD_version >= 400001
rv = ncvprobesubr(rman_get_bustag(sc->port_res),
rman_get_bushandle(sc->port_res),
flags, NCV_HOSTID);
#else
bus_addr_t offset = 0;
u_int iobase = DEVPORT_PDEVIOBASE(devi);
if(flags & KME_KXLC004_01)
offset = OFFSET_KME_KXLC004_01;
rv = ncvprobesubr(I386_BUS_SPACE_IO,
iobase + offset,
flags, NCV_HOSTID);
#endif
return rv;
}
static int
ncvattach(DEVPORT_PDEVICE devi)
{
struct ncv_softc *sc;
struct scsi_low_softc *slp;
u_int32_t flags = DEVPORT_PDEVFLAGS(devi);
#if defined(__FreeBSD__) && __FreeBSD_version < 400001
int unit = DEVPORT_PDEVUNIT(devi);
bus_addr_t offset = 0;
u_int iobase = DEVPORT_PDEVIOBASE(devi);
#endif
char dvname[16]; /* SCSI_LOW_DVNAME_LEN */
strcpy(dvname, "ncv");
#if defined(__FreeBSD__) && __FreeBSD_version < 400001
if (unit >= NNCV)
{
printf("%s: unit number too high\n", dvname);
return (0);
}
if (iobase == 0)
{
printf("%s: no ioaddr is given\n", dvname);
return (0);
}
if(flags & KME_KXLC004_01)
offset = OFFSET_KME_KXLC004_01;
#endif
sc = DEVPORT_PDEVALLOC_SOFTC(devi);
if (sc == NULL) {
return(0);
}
slp = &sc->sc_sclow;
#if defined(__FreeBSD__) && __FreeBSD_version >= 400001
slp->sl_dev = devi;
sc->sc_iot = rman_get_bustag(sc->port_res);
sc->sc_ioh = rman_get_bushandle(sc->port_res);
#else
bzero(sc, sizeof(struct ncv_softc));
strcpy(slp->sl_dev.dv_xname, dvname);
slp->sl_dev.dv_unit = unit;
sc->sc_iot = I386_BUS_SPACE_IO;
sc->sc_ioh = iobase + offset;
#endif
slp->sl_hostid = NCV_HOSTID;
slp->sl_cfgflags = flags;
ncvattachsubr(sc);
sc->sc_ih = ncvintr;
return(NCVIOSZ);
}
#endif /* NCARD */

67
sys/dev/ncv/ncr53c500hw.h Normal file
View File

@ -0,0 +1,67 @@
/* $FreeBSD$ */
/* $NecBSD: ncr53c500hw.h,v 1.6 1998/11/26 01:59:12 honda Exp $ */
/* $NetBSD$ */
/*
* [NetBSD for NEC PC-98 series]
* Copyright (c) 1996, 1997, 1998
* NetBSD/pc98 porting staff. All rights reserved.
* Copyright (c) 1996, 1997, 1998
* Naofumi HONDA. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#ifndef __NCR53C500HW_H_
#define __NCR53C500HW_H_
#include <machine/dvcfg.h>
#define NCV_HOSTID 7
#define NCV_NTARGETS 8
#define NCV_NLUNS 8
struct ncv_hw {
/* configuration images */
u_int8_t cfg1;
u_int8_t cfg2;
u_int8_t cfg3;
u_int8_t cfg4;
u_int8_t cfg5;
/* synch */
u_int8_t clk;
u_int8_t mperiod;
u_int8_t moffset;
};
/* dvcfg */
#define NCV_C5IMG(flags) ((DVCFG_MAJOR(flags) >> 8) & 0xff)
#define NCV_CLKFACTOR(flags) (DVCFG_MAJOR(flags) & 0x0f)
#define NCVHWCFG_MAX10M 0x01
#define NCVHWCFG_SCSI1 0x02
#define NCVHWCFG_SLOW 0x04
#define NCVHWCFG_FIFOBUG 0x08
#define NCV_SPECIAL(flags) ((DVCFG_MAJOR(flags) >> 4) & 0x0f)
#endif /* !__NCR53C500HW_H_ */

View File

@ -0,0 +1,47 @@
/* $FreeBSD$ */
/* $NecBSD: ncr53c500hwtab.h,v 1.2 1998/11/26 01:59:13 honda Exp $ */
/* $NetBSD$ */
/*
* [NetBSD for NEC PC-98 series]
* Copyright (c) 1996, 1997, 1998
* NetBSD/pc98 porting staff. All rights reserved.
* Copyright (c) 1996, 1997, 1998
* Naofumi HONDA. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
static struct ncv_hw ncv_template = {
NCV_HOSTID,
C2_FE | C2_SCSI2,
C3_FCLK,
C4_ANE,
0x80,
CLK_40M_F,
200 / 4,
15,
};

192
sys/dev/ncv/ncr53c500reg.h Normal file
View File

@ -0,0 +1,192 @@
/* $FreeBSD$ */
/* $NecBSD: ncr53c500reg.h,v 1.5 1998/12/26 11:50:01 honda Exp $ */
/* $NetBSD$ */
/*
* [NetBSD for NEC PC-98 series]
* Copyright (c) 1995, 1996, 1997, 1998
* NetBSD/pc98 porting staff. All rights reserved.
* Copyright (c) 1995, 1996, 1997, 1998
* Naofumi HONDA. All rights reserved.
* Copyright (c) 1995, 1996, 1997, 1998
* Kouichi Matsuda. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#ifndef _NCR53C500REG_H_
#define _NCR53C500REG_H_
/* Control Register Set 0 */
#define NCVIOSZ 0x10
#define cr0_tclsb 0x00 /* RW - Transfer Count Low */
#define cr0_tcmsb 0x01 /* RW - Transfer Count Mid */
#define cr0_sfifo 0x02 /* RW - FIFO data */
#define cr0_cmd 0x03 /* RW - Command (2 deep) */
#define cr0_stat 0x04 /* RO - Status */
#define cr0_dstid 0x04 /* WO - Select/Reselect Bus ID */
#define cr0_istat 0x05 /* RO - Interrupt */
#define cr0_srtout 0x05 /* WO - Select/Reselect Timeout */
#define cr0_seq 0x06 /* RO - Sequence Step */
#define cr0_period 0x06 /* WO - Synch Transfer Period */
#define cr0_sffl 0x07 /* RO - FIFO FLags */
#define cr0_offs 0x07 /* WO - Synch Ofset */
#define cr0_cfg1 0x08 /* RW - Configuration #1 */
#define cr0_clk 0x09 /* WO - Clock Conversion Factor */
#define cr0_tst 0x0a /* WO - Test (Chip Test Only) */
#define cr0_cfg2 0x0b /* RW - Configuration #2 */
#define cr0_cfg3 0x0c /* RW - Configuration #3 */
#define cr0_cfg4 0x0d /* RW - Configuration #4 */
#define cr0_tchsb 0x0e /* RW - Transfer Count High */
#define cr0_fifo_bottom 0x0f /* WO - FIFO bottom */
/* Control Register Set 1 */
#define cr1_jumper 0x00 /* RW - Jumper Sense Port */
#define cr1_sram_ptr 0x01 /* RW - SRAM Address Pointer */
#define cr1_sram_data 0x02 /* RW - SRAM Data */
#define cr1_fdata 0x04 /* RW - PIO FIFO */
#define cr1_fstat 0x08 /* RW - PIO Status */
#define cr1_atacmd 0x09 /* RW - ATA Command/Status */
#define cr1_ataerr 0x0a /* RW - ATA Features/Error */
#define cr1_pflag 0x0b /* RW - PIO Flag Interrupt Enable */
#define cr1_cfg5 0x0d /* RW - Configuration #5 */
#define cr1_sig 0x0e /* RO - Signature */
#define cr1_cfg6 0x0f /* RW - Configuration #6 */
/* atacmd (MPS110 ONLY) */
#define ATACMD_POWDOWN 0x2d
#define ATACMD_ENGAGE 0x24
/* cr0_sffl regster */
#define CR0_SFFLR_BMASK 0x1f /* scsi fifo byte mask */
/* cfg4 */
#define C4_ANE 0x04
/* cfg3 */
#define C3_NULL 0x00
#define C3_FCLK 0x08 /* Fast SCSI */
#define C3_FSCSI 0x10 /* Fast Clock (>25Mhz) */
/* cfg2 */
#define C2_SCSI2 0x08 /* SCSI-2 Enable */
#define C2_FE 0x40 /* Features Enable */
/* cfg1 */
#define C1_SLOW 0x80 /* Slow Cable Mode */
#define C1_SRR 0x40 /* SCSI Reset Rep Int Dis */
#define C1_PARENB 0x10 /* Enable Parity Check */
/* clk factor */
#define CLK_40M_F 0x00
#define CLK_25M_F 0x05
#define CLK_30M_F 0x06
#define CLK_35M_F 0x07
/* interrupt status register */
#define INTR_SBR 0x80 /* SCSI Bus Reset */
#define INTR_ILL 0x40 /* Illegal Command */
#define INTR_DIS 0x20 /* Disconnect */
#define INTR_BS 0x10 /* Bus Service */
#define INTR_FC 0x08 /* Function Complete */
#define INTR_RESEL 0x04 /* Reselected */
#define INTR_SELATN 0x02 /* Select with ATN */
#define INTR_SEL 0x01 /* Selected */
#define INTR_RESELECT (INTR_RESEL | INTR_FC)
/* status register */
#define STAT_INT 0x80 /* Interrupt */
#define STAT_GE 0x40 /* Gross Error */
#define STAT_PE 0x20 /* Parity Error */
#define STAT_TC 0x10 /* Terminal Count */
/* phase bits */
#define IOI 0x01
#define CDI 0x02
#define MSGI 0x04
/* Information transfer phases */
#define DATA_OUT_PHASE (0)
#define DATA_IN_PHASE (IOI)
#define COMMAND_PHASE (CDI)
#define STATUS_PHASE (CDI|IOI)
#define MESSAGE_OUT_PHASE (MSGI|CDI)
#define MESSAGE_IN_PHASE (MSGI|CDI|IOI)
#define PHASE_MASK (MSGI|CDI|IOI)
/* fifo status register */
#define FIFO_SMASK 0x1e
#define FIFO_E 0x10 /* fifo empty */
#define FIFO_B 0x00 /* there exists any */
#define FIFO_1 0x08 /* 1/3 <= bytes < 2/3 */
#define FIFO_2 0x04 /* 2/3 <= bytes < full */
#define FIFO_F 0x02 /* full */
#define FIFO_EN 0x01 /* fifo direction */
#define FIFO_BRK 0x40 /* phase miss */
#define FIFO_F_SZ 128
#define FIFO_1_SZ 44
#define FIFO_2_SZ 84
/* pflags */
#define PFR_WRITE 0x01
/* Commands */
#define CMD_DMA 0x80 /* DMA Bit */
#define CMD_NOP 0x00 /* No Operation */
#define CMD_FLUSH 0x01 /* Flush FIFO */
#define CMD_RSTCHIP 0x02 /* Reset Chip */
#define CMD_RSTSCSI 0x03 /* Reset SCSI Bus */
#define CMD_RESEL 0x40 /* Reselect Sequence */
#define CMD_SELNATN 0x41 /* Select without ATN */
#define CMD_SELATN 0x42 /* Select with ATN */
#define CMD_SELATNS 0x43 /* Select with ATN & Stop */
#define CMD_ENSEL 0x44 /* Enable (Re)Selection */
#define CMD_DISSEL 0x45 /* Disable (Re)Selection */
#define CMD_SELATN3 0x46 /* Select with ATN3 */
#define CMD_RESEL3 0x47 /* Reselect3 Sequence */
#define CMD_SNDMSG 0x20 /* Send Message */
#define CMD_SNDSTAT 0x21 /* Send Status */
#define CMD_SNDDATA 0x22 /* Send Data */
#define CMD_DISCSEQ 0x23 /* Disconnect Sequence */
#define CMD_TERMSEQ 0x24 /* Terminate Sequence */
#define CMD_TCCS 0x25 /* Target Command Comp Seq */
#define CMD_DISC 0x27 /* Disconnect */
#define CMD_RECMSG 0x28 /* Receive Message */
#define CMD_RECCMD 0x29 /* Receive Command */
#define CMD_RECDATA 0x2a /* Receive Data */
#define CMD_RECCSEQ 0x2b /* Receive Command Sequence */
#define CMD_ABORT 0x04 /* Target Abort DMA */
#define CMD_TRANS 0x10 /* Transfer Information */
#define CMD_ICCS 0x11 /* Initiator Cmd Comp Seq */
#define CMD_MSGOK 0x12 /* Message Accepted */
#define CMD_TRPAD 0x18 /* Transfer Pad */
#define CMD_SETATN 0x1a /* Set ATN */
#define CMD_RSTATN 0x1b /* Reset ATN */
/* Default timeout */
#define SEL_TOUT 0xa3
#endif /* !_NCR53C500REG_H_ */

View File

@ -0,0 +1,90 @@
/* $FreeBSD$ */
/* $NecBSD: ncr53c500var.h,v 1.11 1998/11/28 18:42:42 honda Exp $ */
/* $NetBSD$ */
/*
* [NetBSD for NEC PC-98 series]
* Copyright (c) 1995, 1996, 1997, 1998
* NetBSD/pc98 porting staff. All rights reserved.
* Copyright (c) 1995, 1996, 1997, 1998
* Naofumi HONDA. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#ifndef _NCR53C500VAR_H_
#define _NCR53C500VAR_H_
/*****************************************************************
* Host adapter structure
*****************************************************************/
struct ncv_softc {
struct scsi_low_softc sc_sclow; /* generic data */
bus_space_tag_t sc_iot;
bus_space_tag_t sc_memt;
bus_space_handle_t sc_ioh;
void *sc_ih;
int sc_selstop; /* sel atn stop asserted */
int sc_compseq; /* completion seq cmd asserted */
int sc_tdatalen; /* temp xfer data len */
struct ncv_hw sc_hw; /* hardware register images */
#if defined (__FreeBSD__) && __FreeBSD_version >= 400001
int port_rid;
int irq_rid;
int mem_rid;
struct resource *port_res;
struct resource *irq_res;
struct resource *mem_res;
void *ncv_intrhand;
#endif
};
/*****************************************************************
* Lun information
*****************************************************************/
struct ncv_lun_info {
struct lun_info nli_li;
u_int8_t nli_reg_cfg3; /* cfg3 images per lun */
u_int8_t nli_reg_offset; /* synch offset register per lun */
u_int8_t nli_reg_period; /* synch period register per lun */
};
/*****************************************************************
* Proto
*****************************************************************/
int ncvprobesubr __P((bus_space_tag_t, bus_space_handle_t ioh, u_int, int));
void ncvattachsubr __P((struct ncv_softc *));
int ncvprint __P((void *, const char *));
int ncvintr __P((void *));
#if defined(i386)
#define SOFT_INTR_REQUIRED(slp) (softintr((slp)->sl_irq))
#else /* !i386 */
#define SOFT_INTR_REQUIRED(slp)
#endif /* !i386 */
#endif /* !_NCR53C500VAR_H_ */

1373
sys/dev/nsp/nsp.c Normal file

File diff suppressed because it is too large Load Diff

414
sys/dev/nsp/nsp_pccard.c Normal file
View File

@ -0,0 +1,414 @@
/* $FreeBSD$ */
/* $NecBSD: nsp_pisa.c,v 1.4 1999/04/15 01:35:54 kmatsuda Exp $ */
/* $NetBSD$ */
/*
* [Ported for FreeBSD]
* Copyright (c) 2000
* Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe.
* All rights reserved.
* [NetBSD for NEC PC-98 series]
* Copyright (c) 1998
* NetBSD/pc98 porting staff. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/disklabel.h>
#if defined(__FreeBSD__) && __FreeBSD_version >= 500001
#include <sys/bio.h>
#endif
#include <sys/buf.h>
#include <sys/queue.h>
#include <sys/malloc.h>
#include <sys/errno.h>
#include <vm/vm.h>
#include <machine/bus.h>
#include <i386/isa/isa_device.h>
#include <machine/dvcfg.h>
#if defined(__FreeBSD__) && __FreeBSD_version < 400001
static struct nsp_softc *nsp_get_softc(int);
extern struct nsp_softc *nspdata[];
#define DEVPORT_ALLOCSOFTCFUNC nsp_get_softc
#define DEVPORT_SOFTCARRAY nspdata
#endif
#include <sys/device_port.h>
#include <cam/scsi/scsi_low.h>
#include <cam/scsi/scsi_low_pisa.h>
#include <dev/nsp/nspreg.h>
#include <dev/nsp/nspvar.h>
#if defined(__NetBSD__) || (defined(__FreeBSD__) && __FreeBSD_version < 400001)
#include "nsp.h"
#endif
#define NSP_HOSTID 7
/* pccard support */
#include "apm.h"
#if NAPM > 0
#include <machine/apm_bios.h>
#endif
#include "card.h"
#if NCARD > 0
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/select.h>
#include <pccard/cardinfo.h>
#include <pccard/slot.h>
#define PIO_MODE 1 /* pd_flags */
static int nspprobe(DEVPORT_PDEVICE devi);
static int nspattach(DEVPORT_PDEVICE devi);
static int nsp_card_intr __P((DEVPORT_PDEVICE));
static void nsp_card_unload __P((DEVPORT_PDEVICE));
#if defined(__FreeBSD__) && __FreeBSD_version < 400001
static int nsp_card_init __P((DEVPORT_PDEVICE));
#endif
#if defined(__FreeBSD__) && __FreeBSD_version >= 400001
/*
* Additional code for FreeBSD new-bus PCCard frontend
*/
static void
nsp_pccard_intr(void * arg)
{
nspintr(arg);
}
static void
nsp_release_resource(DEVPORT_PDEVICE dev)
{
struct nsp_softc *sc = device_get_softc(dev);
if (sc->nsp_intrhand) {
bus_teardown_intr(dev, sc->irq_res, sc->nsp_intrhand);
}
if (sc->port_res) {
bus_release_resource(dev, SYS_RES_IOPORT,
sc->port_rid, sc->port_res);
}
if (sc->irq_res) {
bus_release_resource(dev, SYS_RES_IRQ,
sc->irq_rid, sc->irq_res);
}
if (sc->mem_res) {
bus_release_resource(dev, SYS_RES_MEMORY,
sc->mem_rid, sc->mem_res);
}
}
static int
nsp_alloc_resource(DEVPORT_PDEVICE dev)
{
struct nsp_softc *sc = device_get_softc(dev);
u_long maddr, msize;
int error;
sc->port_rid = 0;
sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid,
0, ~0, NSP_IOSIZE,RF_ACTIVE);
if (sc->port_res == NULL) {
nsp_release_resource(dev);
return(ENOMEM);
}
sc->irq_rid = 0;
sc->irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irq_rid,
0, ~0, 1, RF_ACTIVE);
if (sc->irq_res == NULL) {
nsp_release_resource(dev);
return(ENOMEM);
}
/* no need to allocate memory if PIO mode */
if ((DEVPORT_PDEVFLAGS(dev) & PIO_MODE) != 0) {
return(0);
}
error = bus_get_resource(dev, SYS_RES_MEMORY, 0, &maddr, &msize);
if (error) {
return(0); /* XXX */
}
/* no need to allocate memory if not configured */
if (maddr == 0 || msize == 0) {
return(0);
}
sc->mem_rid = 0;
sc->mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->mem_rid,
0, ~0, msize, RF_ACTIVE);
if (sc->mem_res == NULL) {
nsp_release_resource(dev);
return(ENOMEM);
}
return(0);
}
static int
nsp_pccard_probe(DEVPORT_PDEVICE dev)
{
struct nsp_softc *sc = device_get_softc(dev);
int error;
bzero(sc, sizeof(struct nsp_softc));
error = nsp_alloc_resource(dev);
if (error) {
return(error);
}
if (nspprobe(dev) == 0) {
nsp_release_resource(dev);
return(ENXIO);
}
nsp_release_resource(dev);
return(0);
}
static int
nsp_pccard_attach(DEVPORT_PDEVICE dev)
{
struct nsp_softc *sc = device_get_softc(dev);
int error;
error = nsp_alloc_resource(dev);
if (error) {
return(error);
}
error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM,
nsp_pccard_intr, (void *)sc, &sc->nsp_intrhand);
if (error) {
nsp_release_resource(dev);
return(error);
}
if (nspattach(dev) == 0) {
nsp_release_resource(dev);
return(ENXIO);
}
return(0);
}
static void
nsp_pccard_detach(DEVPORT_PDEVICE dev)
{
nsp_card_unload(dev);
nsp_release_resource(dev);
}
static device_method_t nsp_pccard_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, nsp_pccard_probe),
DEVMETHOD(device_attach, nsp_pccard_attach),
DEVMETHOD(device_detach, nsp_pccard_detach),
{ 0, 0 }
};
static driver_t nsp_pccard_driver = {
"nsp",
nsp_pccard_methods,
sizeof(struct nsp_softc),
};
static devclass_t nsp_devclass;
DRIVER_MODULE(nsp, pccard, nsp_pccard_driver, nsp_devclass, 0, 0);
#else
PCCARD_MODULE(nsp, nsp_card_init,nsp_card_unload, nsp_card_intr,0, cam_imask);
#endif
#if defined(__FreeBSD__) && __FreeBSD_version < 400001
static struct nsp_softc *
nsp_get_softc(int unit)
{
struct nsp_softc *sc;
if (unit >= NNSP) {
return(NULL);
}
if (nspdata[unit] == NULL) {
sc = malloc(sizeof(struct nsp_softc), M_TEMP,M_NOWAIT);
if (sc == NULL) {
printf("nsp_get_softc: cannot malloc!\n");
return(NULL);
}
nspdata[unit] = sc;
} else {
sc = nspdata[unit];
}
return(sc);
}
static int
nsp_card_init(DEVPORT_PDEVICE devi)
{
int unit = DEVPORT_PDEVUNIT(devi);
if (NNSP <= unit)
return (ENODEV);
if (nspprobe(devi) == 0)
return (ENXIO);
if (nspattach(devi) == 0)
return (ENXIO);
return (0);
}
#endif
static void
nsp_card_unload(DEVPORT_PDEVICE devi)
{
struct nsp_softc *sc = DEVPORT_PDEVGET_SOFTC(devi);
printf("%s: unload\n",sc->sc_sclow.sl_xname);
scsi_low_deactivate((struct scsi_low_softc *)sc);
scsi_low_dettach(&sc->sc_sclow);
}
static int
nsp_card_intr(DEVPORT_PDEVICE devi)
{
nspintr(DEVPORT_PDEVGET_SOFTC(devi));
return 1;
}
static int
nspprobe(DEVPORT_PDEVICE devi)
{
int rv;
#if defined(__FreeBSD__) && __FreeBSD_version >= 400001
struct nsp_softc *sc = device_get_softc(devi);
rv = nspprobesubr(rman_get_bustag(sc->port_res),
rman_get_bushandle(sc->port_res),
DEVPORT_PDEVFLAGS(devi));
#else
rv = nspprobesubr(I386_BUS_SPACE_IO,
DEVPORT_PDEVIOBASE(devi), DEVPORT_PDEVFLAGS(devi));
#endif
return rv;
}
static int
nspattach(DEVPORT_PDEVICE devi)
{
#if defined(__FreeBSD__) && __FreeBSD_version < 400001
int unit = DEVPORT_PDEVUNIT(devi);
#endif
struct nsp_softc *sc;
struct scsi_low_softc *slp;
u_int32_t flags = DEVPORT_PDEVFLAGS(devi);
u_int iobase = DEVPORT_PDEVIOBASE(devi);
char dvname[16];
strcpy(dvname,"nsp");
#if defined(__FreeBSD__) && __FreeBSD_version < 400001
if (unit >= NNSP)
{
printf("%s: unit number too high\n",dvname);
return(0);
}
#endif
if (iobase == 0)
{
printf("%s: no ioaddr is given\n", dvname);
return (0);
}
sc = DEVPORT_PDEVALLOC_SOFTC(devi);
if (sc == NULL) {
return (0);
}
slp = &sc->sc_sclow;
#if defined(__FreeBSD__) && __FreeBSD_version >= 400001
slp->sl_dev = devi;
sc->sc_iot = rman_get_bustag(sc->port_res);
sc->sc_ioh = rman_get_bushandle(sc->port_res);
#else
bzero(sc, sizeof(struct nsp_softc));
strcpy(slp->sl_dev.dv_xname, dvname);
slp->sl_dev.dv_unit = unit;
sc->sc_iot = I386_BUS_SPACE_IO;
sc->sc_ioh = iobase;
#endif
if((flags & PIO_MODE) == 0) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 400001
sc->sc_memt = rman_get_bustag(sc->mem_res);
sc->sc_memh = rman_get_bushandle(sc->mem_res);
#else
sc->sc_memt = I386_BUS_SPACE_MEM;
sc->sc_memh = (bus_space_handle_t)DEVPORT_PDEVMADDR(devi);
#endif
} else {
sc->sc_memh = 0;
}
/* slp->sl_irq = devi->pd_irq; */
sc->sc_iclkdiv = CLKDIVR_20M;
sc->sc_clkdiv = CLKDIVR_40M;
slp->sl_hostid = NSP_HOSTID;
slp->sl_cfgflags = flags;
nspattachsubr(sc);
sc->sc_ih = nspintr;
return(NSP_IOSIZE);
}
#endif /* NCARD>0 */

201
sys/dev/nsp/nspreg.h Normal file
View File

@ -0,0 +1,201 @@
/* $FreeBSD$ */
/* $NecBSD: nspreg.h,v 1.4 1999/04/15 01:35:55 kmatsuda Exp $ */
/* $NetBSD$ */
/*
* [NetBSD for NEC PC-98 series]
* Copyright (c) 1998
* NetBSD/pc98 porting staff. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#ifndef _NSPREG_H_
#define _NSPREG_H_
/* base registers */
#define nsp_irqcr 0
#define IRQCR_RESCL 0x01
#define IRQCR_PHCL 0x02
#define IRQCR_TIMERCL 0x04
#define IRQCR_FIFOCL 0x08
#define IRQCR_SCSIIDIS 0x10
#define IRQCR_EXTIDIS 0x20
#define IRQCR_TIMERIDIS 0x40
#define IRQCR_FIFOIDIS 0x80
#define IRQCR_ALLMASK 0xff
#define IRQCR_IRQDIS 0xf0
#define nsp_irqsr 0
#define IRQSR_SCSI 0x01
#define IRQSR_EXT 0x02
#define IRQSR_TIMER 0x04
#define IRQSR_FIFO 0x08
#define IRQSR_MASK 0x0f
#define nsp_ifselr 1
#define IFSELR_IFSEL 0x01
#define IFSELR_REGSEL 0x04
#define nsp_fifosr 1
#define FIFOSR_CHIPREVM 0x0f
#define FIFOSR_CHIPIDM 0x70
#define FIFOSR_FULLEMP 0x80
#define nsp_idxr 2
#define nsp_datar 3
#define nsp_fifodr 4
/* indexed registers */
#define NSPR_EXTBUSC 0x10
#define NSPR_CLKDIVR 0x11
#define CLKDIVR_40M 0x02
#define CLKDIVR_20M 0x01
#define NSPR_TERMPWRC 0x13
#define TERMPWRC_POWON 0x01
#define NSPR_SCIENR 0x15
#define SCIENR_SCCHG 0x01
#define SCIENR_RESEL 0x10
#define SCIENR_FIFO 0x20
#define SCIENR_RST 0x40
#define NSPR_IRQPHS 0x16
#define IRQPHS_LMSG 0x01
#define IRQPHS_LIO 0x02
#define IRQPHS_LCD 0x04
#define IRQPHS_LBF 0x08
#define IRQPHS_PCHG 0x10
#define IRQPHS_RSEL 0x20
#define IRQPHS_FIFO 0x40
#define IRQPHS_RST 0x80
#define NSPR_TIMERCNT 0x17
#define NSPR_SCBUSCR 0x18
#define SCBUSCR_SEL 0x01
#define SCBUSCR_RST 0x02
#define SCBUSCR_DOUT 0x04
#define SCBUSCR_ATN 0x08
#define SCBUSCR_ACK 0x10
#define SCBUSCR_BSY 0x20
#define SCBUSCR_ADIR 0x40
#define SCBUSCR_ACKEN 0x80
#define NSPR_SCBUSMON 0x19
#define SCBUSMON_MSG 0x01
#define SCBUSMON_IO 0x02
#define SCBUSMON_CD 0x04
#define SCBUSMON_BSY 0x08
#define SCBUSMON_ACK 0x10
#define SCBUSMON_REQ 0x20
#define SCBUSMON_SEL 0x40
#define SCBUSMON_ATN 0x80
#define NSPR_SETARBIT 0x1A
#define NSPR_ARBITS 0x1A
#define ARBITS_EXEC 0x01
#define ARBITS_CLR 0x02
#define ARBITS_WIN 0x02
#define ARBITS_FAIL 0x04
#define ARBITS_RESEL 0x08
#define NSPR_PARITYR 0x1B /* (W/R) */
#define NSPR_CMDCR 0x1C /* (W) */
#define CMDCR_PTCLR 0x01
#define CMDCR_EXEC 0x02
#define NSPR_RESELR 0x1C /* (R) */
#define NSPR_CMDDR 0x1D /* (W/R) */
#define NSPR_PTCLRR 0x1E /* (W) */
#define PTCLRR_PT 0x01
#define PTCLRR_ACK 0x02
#define PTCLRR_REQ 0x04
#define PTCLRR_HOST 0x08
#define PTCLRR_RSS 0x30
#define NSPR_XFERCR 0x1E /* (R) */
#define NSPR_XFERMR 0x20
#define XFERMR_MEM8 0x01
#define XFERMR_MEM32 0x02
#define XFERMR_ADR24 0x04
#define XFERMR_ADR32 0x08
#define XFERMR_IO8 0x10
#define XFERMR_IO32 0x20
#define XFERMR_XEN 0x40
#define XFERMR_FIFOEN 0x80
#define NSPR_SYNCR 0x21
#define SYNCR_OFFM 0x0f
#define SYNCR_PERM 0xf0
#define SYNCR_PERS 4
#define NSPR_DATA 0x22
#define NSPR_DATAACK 0x23
#define NSPR_OCR 0x26
#define OCR_ROMEN 0x01
#define OCR_TERMPWROUT 0x02
#define OCR_TERMPWRS 0x04
#define NSPR_ACKWIDTH 0x27
/* SCBUSMON phase defs */
#define SCBUSMON_FREE 0
#define SCBUSMON_CMD \
(SCBUSMON_BSY | SCBUSMON_CD | SCBUSMON_REQ)
#define SCBUSMON_MSGIN \
(SCBUSMON_BSY | SCBUSMON_MSG | SCBUSMON_IO | SCBUSMON_CD | SCBUSMON_REQ)
#define SCBUSMON_MSGOUT \
(SCBUSMON_BSY | SCBUSMON_MSG | SCBUSMON_CD | SCBUSMON_REQ)
#define SCBUSMON_DATAIN \
(SCBUSMON_BSY | SCBUSMON_IO | SCBUSMON_REQ)
#define SCBUSMON_DATAOUT \
(SCBUSMON_BSY | SCBUSMON_REQ)
#define SCBUSMON_STATUS \
(SCBUSMON_BSY | SCBUSMON_IO | SCBUSMON_CD | SCBUSMON_REQ)
#define SCBUSMON_RESELECT \
(SCBUSMON_SEL | SCBUSMON_IO)
#define SCBUSMON_PHMASK \
(SCBUSMON_SEL | SCBUSMON_CD | SCBUSMON_MSG | SCBUSMON_IO)
/* SCSI phase */
#define PHASE_CMD (SCBUSMON_CMD & SCBUSMON_PHMASK)
#define PHASE_DATAIN (SCBUSMON_DATAIN & SCBUSMON_PHMASK)
#define PHASE_DATAOUT (SCBUSMON_DATAOUT & SCBUSMON_PHMASK)
#define PHASE_STATUS (SCBUSMON_STATUS & SCBUSMON_PHMASK)
#define PHASE_MSGIN (SCBUSMON_MSGIN & SCBUSMON_PHMASK)
#define PHASE_MSGOUT (SCBUSMON_MSGOUT & SCBUSMON_PHMASK)
#define PHASE_SEL (SCBUSMON_SEL | SCBUSMON_IO)
/* Size */
#define NSP_MEMSIZE NBPG
#define NSP_IOSIZE 16
#define NSP_BUFFER_SIZE 512
#endif /* !_NSPREG_H_ */

102
sys/dev/nsp/nspvar.h Normal file
View File

@ -0,0 +1,102 @@
/* $FreeBSD$ */
/* $NecBSD: nspvar.h,v 1.7 1999/04/15 01:35:55 kmatsuda Exp $ */
/* $NetBSD$ */
/*
* [NetBSD for NEC PC-98 series]
* Copyright (c) 1998
* NetBSD/pc98 porting staff. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#ifndef _NSPVAR_H_
#define _NSPVAR_H_
/*****************************************************************
* Host adapter structure
*****************************************************************/
struct nsp_softc {
struct scsi_low_softc sc_sclow; /* generic data */
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
bus_space_tag_t sc_memt;
bus_space_handle_t sc_memh;
void *sc_ih;
int sc_seltout; /* selection timeout counter */
int sc_timer; /* timer start */
int sc_xmode;
#define NSP_HIGH_SMIT 2 /* write address data mode */
#define NSP_MID_SMIT 1 /* mem access */
#define NSP_PIO 0 /* io access */
u_int sc_idbit; /* host id bit pattern */
u_int sc_mask; /* bus width mask */
u_int sc_cnt; /* fifo R/W count (host) */
u_int8_t sc_iclkdiv; /* scsi chip clock divisor */
u_int8_t sc_clkdiv; /* asic chip clock divisor */
u_int8_t sc_xfermr; /* fifo control reg */
u_int8_t sc_icr; /* interrupt control reg */
u_int8_t sc_busc; /* busc registers */
u_long sc_ringp; /* data buffer ring pointer */
#if defined (__FreeBSD__) && __FreeBSD_version >= 400001
int port_rid;
int irq_rid;
int mem_rid;
struct resource *port_res;
struct resource *irq_res;
struct resource *mem_res;
void *nsp_intrhand;
#endif
};
/*****************************************************************
* Lun information
*****************************************************************/
struct nsp_lun_info {
struct lun_info nli_li; /* generic lun info */
u_int8_t nli_reg_syncr; /* sync registers per devices */
u_int8_t nli_reg_ackwidth; /* ackwidth per devices */
};
/*****************************************************************
* Proto
*****************************************************************/
int nspprobesubr __P((bus_space_tag_t, bus_space_handle_t, u_int));
void nspattachsubr __P((struct nsp_softc *));
int nspprint __P((void *, const char *));
int nspintr __P((void *));
#if defined(i386)
#define SOFT_INTR_REQUIRED(slp) (softintr((slp)->sl_irq))
#else /* !i386 */
#define SOFT_INTR_REQUIRED(slp)
#endif /* !i386 */
#endif /* !_NSPVAR_H_ */

1218
sys/dev/stg/tmc18c30.c Normal file

File diff suppressed because it is too large Load Diff

298
sys/dev/stg/tmc18c30_isa.c Normal file
View File

@ -0,0 +1,298 @@
/* $FreeBSD$ */
/* $NecBSD: tmc18c30_pisa.c,v 1.22 1998/11/26 01:59:21 honda Exp $ */
/* $NetBSD$ */
/*
* [Ported for FreeBSD]
* Copyright (c) 2000
* Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe.
* All rights reserved.
* [NetBSD for NEC PC-98 series]
* Copyright (c) 1996, 1997, 1998
* NetBSD/pc98 porting staff. All rights reserved.
* Copyright (c) 1996, 1997, 1998
* Naofumi HONDA. All rights reserved.
* Copyright (c) 1996, 1997, 1998
* Kouichi Matsuda. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/bus.h>
#include <sys/disklabel.h>
#if defined(__FreeBSD__) && __FreeBSD_version >= 500001
#include <sys/bio.h>
#endif
#include <sys/buf.h>
#include <sys/queue.h>
#include <sys/malloc.h>
#include <sys/errno.h>
#include <vm/vm.h>
#include <machine/bus_pio.h>
#include <machine/bus.h>
#include <machine/resource.h>
#include <sys/rman.h>
#include <isa/isavar.h>
#include <machine/dvcfg.h>
#include <sys/device_port.h>
#include <cam/scsi/scsi_low.h>
#include <isa/isa_common.h>
#include <cam/scsi/scsi_low_pisa.h>
#include <dev/stg/tmc18c30reg.h>
#include <dev/stg/tmc18c30var.h>
#define STG_HOSTID 7
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/select.h>
static int stgprobe(device_t devi);
static int stgattach(device_t devi);
static void stg_isa_unload __P((device_t));
static void
stg_isa_intr(void * arg)
{
stgintr(arg);
}
static void
stg_release_resource(device_t dev)
{
struct stg_softc *sc = device_get_softc(dev);
if (sc->stg_intrhand) {
bus_teardown_intr(dev, sc->irq_res, sc->stg_intrhand);
}
if (sc->port_res) {
bus_release_resource(dev, SYS_RES_IOPORT,
sc->port_rid, sc->port_res);
}
if (sc->irq_res) {
bus_release_resource(dev, SYS_RES_IRQ,
sc->irq_rid, sc->irq_res);
}
if (sc->mem_res) {
bus_release_resource(dev, SYS_RES_MEMORY,
sc->mem_rid, sc->mem_res);
}
}
static int
stg_alloc_resource(device_t dev)
{
struct stg_softc *sc = device_get_softc(dev);
u_long maddr, msize;
int error;
sc->port_rid = 0;
sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid,
0, ~0, STGIOSZ, RF_ACTIVE);
if (sc->port_res == NULL) {
stg_release_resource(dev);
return(ENOMEM);
}
sc->irq_rid = 0;
sc->irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irq_rid,
0, ~0, 1, RF_ACTIVE);
if (sc->irq_res == NULL) {
stg_release_resource(dev);
return(ENOMEM);
}
error = bus_get_resource(dev, SYS_RES_MEMORY, 0, &maddr, &msize);
if (error) {
return(0); /* XXX */
}
/* no need to allocate memory if not configured */
if (maddr == 0 || msize == 0) {
return(0);
}
sc->mem_rid = 0;
sc->mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->mem_rid,
0, ~0, msize, RF_ACTIVE);
if (sc->mem_res == NULL) {
stg_release_resource(dev);
return(ENOMEM);
}
return(0);
}
static int
stg_isa_probe(device_t dev)
{
struct stg_softc *sc = device_get_softc(dev);
int error;
bzero(sc, sizeof(struct stg_softc));
error = stg_alloc_resource(dev);
if (error) {
return(error);
}
if (stgprobe(dev) == 0) {
stg_release_resource(dev);
return(ENXIO);
}
stg_release_resource(dev);
return(0);
}
static int
stg_isa_attach(device_t dev)
{
struct stg_softc *sc = device_get_softc(dev);
int error;
error = stg_alloc_resource(dev);
if (error) {
return(error);
}
error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM,
stg_isa_intr, (void *)sc, &sc->stg_intrhand);
if (error) {
stg_release_resource(dev);
return(error);
}
if (stgattach(dev) == 0) {
stg_release_resource(dev);
return(ENXIO);
}
return(0);
}
static void
stg_isa_detach(device_t dev)
{
stg_isa_unload(dev);
stg_release_resource(dev);
}
static device_method_t stg_isa_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, stg_isa_probe),
DEVMETHOD(device_attach, stg_isa_attach),
DEVMETHOD(device_detach, stg_isa_detach),
{ 0, 0 }
};
static driver_t stg_isa_driver = {
"stg",
stg_isa_methods,
sizeof(struct stg_softc),
};
static devclass_t stg_devclass;
DRIVER_MODULE(stg, isa, stg_isa_driver, stg_devclass, 0, 0);
static void
stg_isa_unload(device_t devi)
{
struct stg_softc *sc = device_get_softc(devi);
printf("%s: unload\n",sc->sc_sclow.sl_xname);
scsi_low_deactivate((struct scsi_low_softc *)sc);
scsi_low_dettach(&sc->sc_sclow);
}
static int
stgprobe(device_t devi)
{
int rv;
struct stg_softc *sc = device_get_softc(devi);
rv = stgprobesubr(rman_get_bustag(sc->port_res),
rman_get_bushandle(sc->port_res),
device_get_flags(devi));
return rv;
}
static int
stgattach(device_t devi)
{
struct stg_softc *sc;
struct scsi_low_softc *slp;
u_int32_t flags = device_get_flags(devi);
u_int iobase = bus_get_resource_start(devi, SYS_RES_IOPORT, 0);
char dvname[16];
strcpy(dvname,"stg");
if (iobase == 0)
{
printf("%s: no ioaddr is given\n", dvname);
return (0);
}
sc = device_get_softc(devi);
if (sc == NULL) {
return(0);
}
slp = &sc->sc_sclow;
slp->sl_dev = devi;
sc->sc_iot = rman_get_bustag(sc->port_res);
sc->sc_ioh = rman_get_bushandle(sc->port_res);
slp->sl_hostid = STG_HOSTID;
slp->sl_cfgflags = flags;
stgattachsubr(sc);
sc->sc_ih = stgintr;
printf("stg%d",device_get_unit(devi));
return(STGIOSZ);
}

View File

@ -0,0 +1,399 @@
/* $FreeBSD$ */
/* $NecBSD: tmc18c30_pisa.c,v 1.22 1998/11/26 01:59:21 honda Exp $ */
/* $NetBSD$ */
/*
* [Ported for FreeBSD]
* Copyright (c) 2000
* Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe.
* All rights reserved.
* [NetBSD for NEC PC-98 series]
* Copyright (c) 1996, 1997, 1998
* NetBSD/pc98 porting staff. All rights reserved.
* Copyright (c) 1996, 1997, 1998
* Naofumi HONDA. All rights reserved.
* Copyright (c) 1996, 1997, 1998
* Kouichi Matsuda. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/disklabel.h>
#if defined(__FreeBSD__) && __FreeBSD_version >= 500001
#include <sys/bio.h>
#endif
#include <sys/buf.h>
#include <sys/queue.h>
#include <sys/malloc.h>
#include <sys/errno.h>
#include <vm/vm.h>
#include <machine/bus.h>
#include <machine/bus_pio.h>
#include <i386/isa/isa_device.h>
#include <machine/dvcfg.h>
#if defined(__FreeBSD__) && __FreeBSD_version < 400001
static struct stg_softc *stg_get_softc(int);
extern struct stg_softc *stgdata[];
#define DEVPORT_ALLOCSOFTCFUNC stg_get_softc
#define DEVPORT_SOFTCARRAY stgdata
#endif
#include <sys/device_port.h>
#include <cam/scsi/scsi_low.h>
#include <cam/scsi/scsi_low_pisa.h>
#include <dev/stg/tmc18c30reg.h>
#include <dev/stg/tmc18c30var.h>
#if defined(__FreeBSD__) && __FreeBSD_version < 400001
#include "stg.h"
#endif
#define STG_HOSTID 7
/* pccard support */
#include "apm.h"
#if NAPM > 0
#include <machine/apm_bios.h>
#endif
#include "card.h"
#if NCARD > 0
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/select.h>
#include <pccard/cardinfo.h>
#include <pccard/slot.h>
static int stgprobe(DEVPORT_PDEVICE devi);
static int stgattach(DEVPORT_PDEVICE devi);
static int stg_card_intr __P((DEVPORT_PDEVICE));
static void stg_card_unload __P((DEVPORT_PDEVICE));
#if defined(__FreeBSD__) && __FreeBSD_version < 400001
static int stg_card_init __P((DEVPORT_PDEVICE));
#endif
#if defined(__FreeBSD__) && __FreeBSD_version >= 400001
/*
* Additional code for FreeBSD new-bus PCCard frontend
*/
static void
stg_pccard_intr(void * arg)
{
stgintr(arg);
}
static void
stg_release_resource(DEVPORT_PDEVICE dev)
{
struct stg_softc *sc = device_get_softc(dev);
if (sc->stg_intrhand) {
bus_teardown_intr(dev, sc->irq_res, sc->stg_intrhand);
}
if (sc->port_res) {
bus_release_resource(dev, SYS_RES_IOPORT,
sc->port_rid, sc->port_res);
}
if (sc->irq_res) {
bus_release_resource(dev, SYS_RES_IRQ,
sc->irq_rid, sc->irq_res);
}
if (sc->mem_res) {
bus_release_resource(dev, SYS_RES_MEMORY,
sc->mem_rid, sc->mem_res);
}
}
static int
stg_alloc_resource(DEVPORT_PDEVICE dev)
{
struct stg_softc *sc = device_get_softc(dev);
u_long maddr, msize;
int error;
sc->port_rid = 0;
sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid,
0, ~0, STGIOSZ, RF_ACTIVE);
if (sc->port_res == NULL) {
stg_release_resource(dev);
return(ENOMEM);
}
sc->irq_rid = 0;
sc->irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irq_rid,
0, ~0, 1, RF_ACTIVE);
if (sc->irq_res == NULL) {
stg_release_resource(dev);
return(ENOMEM);
}
error = bus_get_resource(dev, SYS_RES_MEMORY, 0, &maddr, &msize);
if (error) {
return(0); /* XXX */
}
/* no need to allocate memory if not configured */
if (maddr == 0 || msize == 0) {
return(0);
}
sc->mem_rid = 0;
sc->mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->mem_rid,
0, ~0, msize, RF_ACTIVE);
if (sc->mem_res == NULL) {
stg_release_resource(dev);
return(ENOMEM);
}
return(0);
}
static int
stg_pccard_probe(DEVPORT_PDEVICE dev)
{
struct stg_softc *sc = device_get_softc(dev);
int error;
bzero(sc, sizeof(struct stg_softc));
error = stg_alloc_resource(dev);
if (error) {
return(error);
}
if (stgprobe(dev) == 0) {
stg_release_resource(dev);
return(ENXIO);
}
stg_release_resource(dev);
return(0);
}
static int
stg_pccard_attach(DEVPORT_PDEVICE dev)
{
struct stg_softc *sc = device_get_softc(dev);
int error;
error = stg_alloc_resource(dev);
if (error) {
return(error);
}
error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM,
stg_pccard_intr, (void *)sc, &sc->stg_intrhand);
if (error) {
stg_release_resource(dev);
return(error);
}
if (stgattach(dev) == 0) {
stg_release_resource(dev);
return(ENXIO);
}
return(0);
}
static void
stg_pccard_detach(DEVPORT_PDEVICE dev)
{
stg_card_unload(dev);
stg_release_resource(dev);
}
static device_method_t stg_pccard_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, stg_pccard_probe),
DEVMETHOD(device_attach, stg_pccard_attach),
DEVMETHOD(device_detach, stg_pccard_detach),
{ 0, 0 }
};
static driver_t stg_pccard_driver = {
"stg",
stg_pccard_methods,
sizeof(struct stg_softc),
};
static devclass_t stg_devclass;
DRIVER_MODULE(stg, pccard, stg_pccard_driver, stg_devclass, 0, 0);
#else
PCCARD_MODULE(stg, stg_card_init,stg_card_unload, stg_card_intr, 0, cam_imask);
#endif
#if defined(__FreeBSD__) && __FreeBSD_version < 400001
static struct stg_softc *
stg_get_softc(int unit)
{
struct stg_softc *sc;
if (unit >= NSTG) {
return(NULL);
}
if (stgdata[unit] == NULL) {
sc = malloc(sizeof(struct stg_softc), M_TEMP,M_NOWAIT);
if (sc == NULL) {
printf("stg_get_softc: cannot malloc!\n");
return(NULL);
}
stgdata[unit] = sc;
} else {
sc = stgdata[unit];
}
return(sc);
}
static int
stg_card_init(DEVPORT_PDEVICE devi)
{
int unit = DEVPORT_PDEVUNIT(devi);
if (NSTG <= unit)
return (ENODEV);
printf("probe stg\n");
if (stgprobe(devi) == 0)
return (ENXIO);
printf("attach stg\n");
if (stgattach(devi) == 0)
return (ENXIO);
return (0);
}
#endif
static void
stg_card_unload(DEVPORT_PDEVICE devi)
{
struct stg_softc *sc = DEVPORT_PDEVGET_SOFTC(devi);
printf("%s: unload\n",sc->sc_sclow.sl_xname);
scsi_low_deactivate((struct scsi_low_softc *)sc);
scsi_low_dettach(&sc->sc_sclow);
}
static int
stg_card_intr(DEVPORT_PDEVICE devi)
{
stgintr(DEVPORT_PDEVGET_SOFTC(devi));
return 1;
}
static int
stgprobe(DEVPORT_PDEVICE devi)
{
int rv;
#if defined(__FreeBSD__) && __FreeBSD_version >= 400001
struct stg_softc *sc = device_get_softc(devi);
rv = stgprobesubr(rman_get_bustag(sc->port_res),
rman_get_bushandle(sc->port_res),
DEVPORT_PDEVFLAGS(devi));
#else
rv = stgprobesubr(I386_BUS_SPACE_IO,
DEVPORT_PDEVIOBASE(devi), DEVPORT_PDEVFLAGS(devi));
#endif
return rv;
}
static int
stgattach(DEVPORT_PDEVICE devi)
{
int unit = DEVPORT_PDEVUNIT(devi);
struct stg_softc *sc;
struct scsi_low_softc *slp;
u_int32_t flags = DEVPORT_PDEVFLAGS(devi);
u_int iobase = DEVPORT_PDEVIOBASE(devi);
char dvname[16];
strcpy(dvname,"stg");
#if defined(__FreeBSD__) && __FreeBSD_version < 400001
if (unit >= NSTG)
{
printf("%s: unit number too high\n",dvname);
return (0);
}
#endif
if (iobase == 0)
{
printf("%s: no ioaddr is given\n", dvname);
return (0);
}
sc = DEVPORT_PDEVALLOC_SOFTC(devi);
if (sc == NULL) {
return(0);
}
slp = &sc->sc_sclow;
#if defined(__FreeBSD__) && __FreeBSD_version >= 400001
slp->sl_dev = devi;
sc->sc_iot = rman_get_bustag(sc->port_res);
sc->sc_ioh = rman_get_bushandle(sc->port_res);
#else
bzero(sc, sizeof(struct stg_softc));
strcpy(slp->sl_dev.dv_xname, dvname);
slp->sl_dev.dv_unit = unit;
sc->sc_iot = I386_BUS_SPACE_IO;
sc->sc_ioh = iobase;
#endif
slp->sl_hostid = STG_HOSTID;
slp->sl_cfgflags = flags;
stgattachsubr(sc);
sc->sc_ih = stgintr;
printf("stg%d",DEVPORT_PDEVUNIT(devi));
return(STGIOSZ);
}
#endif /* NCARD>0 */

144
sys/dev/stg/tmc18c30reg.h Normal file
View File

@ -0,0 +1,144 @@
/* $FreeBSD$ */
/* $NecBSD: tmc18c30reg.h,v 1.4 1998/03/14 07:05:23 kmatsuda Exp $ */
/* $NetBSD$ */
/*
* [NetBSD for NEC PC-98 series]
* Copyright (c) 1996, 1997, 1998
* NetBSD/pc98 porting staff. All rights reserved.
* Copyright (c) 1996, 1997, 1998
* Kouichi Matsuda. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#ifndef _TMC18C30REG_H_
#define _TMC18C30REG_H_
#define tmc_wdata 0x00
#define tmc_rdata 0x00
#define tmc_bctl 0x01
#define BCTL_BUSFREE 0x00
#define BCTL_RST 0x01
#define BCTL_SEL 0x02
#define BCTL_BSY 0x04
#define BCTL_ATN 0x08
#define BCTL_IO 0x10
#define BCTL_CD 0x20
#define BCTL_MSG 0x40
#define BCTL_BUSEN 0x80
#define tmc_bstat 0x01
#define BSTAT_BSY 0x01
#define BSTAT_MSG 0x02
#define BSTAT_IO 0x04
#define BSTAT_CMD 0x08
#define BSTAT_REQ 0x10
#define BSTAT_SEL 0x20
#define BSTAT_ACK 0x40
#define BSTAT_PHMASK (BSTAT_MSG | BSTAT_IO | BSTAT_CMD)
#define tmc_ictl 0x02
#define ICTL_FIFO 0x10
#define ICTL_ARBIT 0x20
#define ICTL_SEL 0x40
#define ICTL_CD 0x80
#define ICTL_ALLINT (ICTL_ARBIT | ICTL_CD | ICTL_SEL)
#define tmc_astat 0x02
#define ASTAT_INT 0x01
#define ASTAT_ARBIT 0x02
#define ASTAT_PARERR 0x04
#define ASTAT_SCSIRST 0x08
#define ASTAT_STATMASK 0x0f
#define ASTAT_FIFODIR 0x10
#define ASTAT_FIFOEN 0x20
#define ASTAT_PARENB 0x40
#define ASTAT_BUSEN 0x80
#define tmc_ssctl 0x03
#define SSCTL_FSYNCHEN 0x40
#define SSCTL_SYNCHEN 0x80
#define tmc_fstat 0x03
#define tmc_fctl 0x04
#define FCTL_CLRFIFO 0x01
#define FCTL_ARBIT 0x04
#define FCTL_PARENB 0x08
#define FCTL_INTEN 0x10
#define FCTL_CLRINT 0x20
#define FCTL_FIFOW 0x40
#define FCTL_FIFOEN 0x80
#define tmc_icnd 0x04
#define tmc_mctl 0x05
#define tmc_idlsb 0x05
#define tmc_idmsb 0x06
#define tmc_wlb 0x07
#define tmc_rlb 0x07
#define tmc_scsiid 0x08
#define tmc_sdna 0x08
#define tmc_istat 0x09
#define ISTAT_INTEN 0x08
#define ISTAT_FIFO 0x10
#define ISTAT_ARBIT 0x20
#define ISTAT_SEL 0x40
#define ISTAT_CD 0x80
#define tmc_cfg1 0x0a
#define tmc_ioctl 0x0b
#define tmc_cfg2 0x0b
#define tmc_wfifo 0x0c
#define tmc_rfifo 0x0c
#define tmc_fdcnt 0x0e
/* Information transfer phases */
#define BUSFREE_PHASE 0x00
#define DATA_OUT_PHASE (BSTAT_BSY)
#define DATA_IN_PHASE (BSTAT_BSY|BSTAT_IO)
#define COMMAND_PHASE (BSTAT_CMD|BSTAT_BSY)
#define STATUS_PHASE (BSTAT_CMD|BSTAT_BSY|BSTAT_IO)
#define MESSAGE_OUT_PHASE (BSTAT_CMD|BSTAT_MSG|BSTAT_BSY)
#define MESSAGE_IN_PHASE (BSTAT_CMD|BSTAT_MSG|BSTAT_BSY|BSTAT_IO)
#define PHASE_RESELECTED (BSTAT_SEL|BSTAT_IO)
#define PHASE_MASK 0x2f
#define RESEL_PHASE_MASK 0x2e
/* chip type */
#define TMCCHIP_UNK 0x00
#define TMCCHIP_1800 0x01
#define TMCCHIP_18C50 0x02
#define TMCCHIP_18C30 0x03
#define STGIOSZ 0x10
#endif /* !_TMC18C30REG_H_ */

99
sys/dev/stg/tmc18c30var.h Normal file
View File

@ -0,0 +1,99 @@
/* $FreeBSD$ */
/* $NecBSD: tmc18c30var.h,v 1.12 1998/11/30 00:08:30 honda Exp $ */
/* $NetBSD$ */
/*
* [NetBSD for NEC PC-98 series]
* Copyright (c) 1996, 1997, 1998
* NetBSD/pc98 porting staff. All rights reserved.
* Copyright (c) 1996, 1997, 1998
* Naofumi HONDA. All rights reserved.
* Copyright (c) 1996, 1997, 1998
* Kouichi Matsuda. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#ifndef _TMC18C30VAR_H_
#define _TMC18C30VAR_H_
/*****************************************************************
* Host adapter structure
*****************************************************************/
struct stg_softc {
struct scsi_low_softc sc_sclow; /* generic data */
bus_space_tag_t sc_iot;
bus_space_tag_t sc_memt;
bus_space_handle_t sc_ioh;
void *sc_ih;
u_int sc_chip; /* chip type */
u_int sc_fsz; /* fifo size */
u_int sc_idbit; /* host id bit */
u_int8_t sc_fcb; /* fifo intr thread */
u_int8_t sc_fcWinit; /* write flags */
u_int8_t sc_fcRinit; /* read flags */
u_int8_t sc_fcsp; /* special control flags */
u_int8_t sc_icinit; /* interrupt masks */
u_int8_t sc_busc; /* default bus control register */
u_int8_t sc_imsg; /* identify msg required */
u_int8_t sc_busimg; /* bus control register image */
#if defined (__FreeBSD__) && __FreeBSD_version >= 400001
int port_rid;
int irq_rid;
int mem_rid;
struct resource *port_res;
struct resource *irq_res;
struct resource *mem_res;
void *stg_intrhand;
#endif
};
/*****************************************************************
* Lun information
*****************************************************************/
struct stg_lun_info {
struct lun_info sli_li; /* generic data */
u_int8_t sli_reg_synch; /* synch register per lun */
};
/*****************************************************************
* Proto
*****************************************************************/
int stgprobesubr __P((bus_space_tag_t, bus_space_handle_t, u_int));
void stgattachsubr __P((struct stg_softc *));
int stgprint __P((void *, const char *));
int stgintr __P((void *));
#if defined(i386)
#define SOFT_INTR_REQUIRED(slp) (softintr((slp)->sl_irq))
#else /* !i386 */
#define SOFT_INTR_REQUIRED(slp)
#endif /* !i386 */
#endif /* !_TMC18C30VAR_H_ */

View File

@ -94,6 +94,10 @@ device bt
device aha 1
device aic
device ncv # NCR 53C500
device nsp # Workbit Ninja SCSI-3
device stg # TMC 18C30/18C50
# RAID controllers interfaced to the SCSI subsystem
device asr # DPT SmartRAID V, VI and Adaptec SCSI RAID
device dpt # DPT Smartcache III, IV - See NOTES for options!

View File

@ -1263,10 +1263,13 @@ options AML_DEBUG
# ISP 12160 Ultra3 SCSI,
# Qlogic ISP 2100 and ISP 2200 Fibre Channel host adapters.
# ncr: NCR 53C810, 53C825 self-contained SCSI host adapters.
# ncv: NCR 53C500 based SCSI host adapters.
# nsp: Workbit Ninja SCSI-3 based PC Card SCSI host adapters.
# sym: Symbios/Logic 53C8XX family of PCI-SCSI I/O processors:
# 53C810, 53C810A, 53C815, 53C825, 53C825A, 53C860, 53C875,
# 53C876, 53C885, 53C895, 53C895A, 53C896, 53C897, 53C1510D,
# 53C1010-33, 53C1010-66.
# stg: TMC 18C30, 18C50 based SCSI host adapters.
#
# Note that the order is important in order for Buslogic ISA/EISA cards to be
@ -1287,7 +1290,10 @@ device amd
device isp
device ispfw
device ncr
device ncv
device nsp
device sym
device stg
# The aic7xxx driver will attempt to use memory mapped I/O for all PCI
# controllers that have it configured only if this option is set. Unfortunately,

View File

@ -338,6 +338,7 @@ static DEV_INFO device_info[] = {
{"aic", "Adaptec 152x SCSI and compatible SCSI cards", 0, CLS_STORAGE},
{"nca", "ProAudio Spectrum SCSI and compatibles", 0, CLS_STORAGE},
{"sea", "Seagate ST01/ST02 SCSI and compatibles", 0, CLS_STORAGE},
{"stg", "TMC 18C30/18C50 based SCSI cards", 0, CLS_STORAGE},
{"ata", "ATA/ATAPI compatible disk controller", 0, CLS_STORAGE},
{"fdc", "Floppy disk controller", FLG_FIXED, CLS_STORAGE},
{"mcd", "Mitsumi CD-ROM", 0, CLS_STORAGE},

View File

@ -0,0 +1,89 @@
/* $FreeBSD$ */
/* $NecBSD: physio_proc.h,v 3.4 1999/07/23 20:47:03 honda Exp $ */
/* $NetBSD$ */
/*
* [NetBSD for NEC PC-98 series]
* Copyright (c) 1998
* NetBSD/pc98 porting staff. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#ifndef _I386_PHYSIO_PROC_H_
#define _I386_PHYSIO_PROC_H_
#include <sys/buf.h>
#include <sys/queue.h>
struct physio_proc;
TAILQ_HEAD(physio_proc_head, physio_proc);
struct physio_proc_head physio_proc_freet, physio_proc_busyt;
struct physio_proc {
TAILQ_ENTRY(physio_proc) pp_chain;
struct proc *pp_proc;
};
static __inline struct physio_proc *physio_proc_enter __P((struct buf *));
static __inline void physio_proc_leave __P((struct physio_proc *));
static __inline struct physio_proc *
physio_proc_enter(bp)
struct buf *bp;
{
struct physio_proc *pp;
int s;
if (bp == NULL || (bp->b_flags & B_PHYS) == 0)
return NULL;
if ((pp = physio_proc_freet.tqh_first) == NULL)
return NULL;
s = splstatclock();
TAILQ_REMOVE(&physio_proc_freet, pp, pp_chain);
#if !defined(__FreeBSD__) || __FreeBSD_version < 400001
pp->pp_proc = bp->b_proc;
#endif
TAILQ_INSERT_TAIL(&physio_proc_busyt, pp, pp_chain);
splx(s);
return pp;
}
static __inline void
physio_proc_leave(pp)
struct physio_proc *pp;
{
int s;
if (pp == NULL)
return;
s = splstatclock();
TAILQ_REMOVE(&physio_proc_busyt, pp, pp_chain);
TAILQ_INSERT_TAIL(&physio_proc_freet, pp, pp_chain);
pp->pp_proc = NULL;
splx(s);
}
void physio_proc_init __P((void));
#endif /* _I386_PHYSIO_PROC_H_ */

115
sys/sys/device_port.h Normal file
View File

@ -0,0 +1,115 @@
/*-
* Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
* Copyright (c) 1999 Takanori Watanabe <takawata@jp.FreeBSD.org>
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*
* $FreeBSD$
*/
#if defined(__NetBSD__)
# include <sys/device.h>
#elif defined(__FreeBSD__)
# if __FreeBSD_version >= 400001
# include <sys/module.h>
# include <sys/bus.h>
# else
# include <sys/device.h>
# endif
#endif
/*
* Macro's to cope with the differences between operating systems and versions.
*/
#if defined(__NetBSD__)
# define DEVPORT_DEVICE struct device
# define DEVPORT_DEVNAME(dev) (dev).dv_xname
# define DEVPORT_DEVUNIT(dev) (dev).dv_unit
#elif defined(__FreeBSD__)
/*
* FreeBSD (compatibility for struct device)
*/
#if __FreeBSD_version >= 400001
# define DEVPORT_DEVICE device_t
# define DEVPORT_DEVNAME(dev) device_get_name(dev)
# define DEVPORT_DEVUNIT(dev) device_get_unit(dev)
# define DEVPORT_ALLOC_SOFTC(dev) device_get_softc(dev)
# define DEVPORT_GET_SOFTC(dev) device_get_softc(dev)
# define UNCONF 1 /* print " not configured\n" */
#else
# define DEVPORT_DEVICE struct device
# define DEVPORT_DEVNAME(dev) (dev).dv_xname
# define DEVPORT_DEVUNIT(dev) (dev).dv_unit
# ifdef DEVPORT_ALLOCSOFTCFUNC
# define DEVPORT_ALLOC_SOFTC(dev) (DEVPORT_ALLOCSOFTCFUNC)((dev).dv_unit)
# else
# define DEVPORT_ALLOC_SOFTC(dev) DEVPORT_ALLOCSOFTCFUNC_is_not_defined_prior_than_device_port_h
# endif
# ifdef DEVPORT_SOFTCARRAY
# define DEVPORT_GET_SOFTC(dev) (DEVPORT_SOFTCARRAY)[(dev).dv_unit]
# else
# define DEVPORT_GET_SOFTC(dev) DEVPORT_SOFTCARRAY_is_not_defined_prior_than_device_port_h
# endif
#endif
/*
* PC-Card device driver (compatibility for struct pccard_devinfo *)
*/
#if __FreeBSD_version >= 400001
# define DEVPORT_PDEVICE device_t
# define DEVPORT_PDEVUNIT(pdev) device_get_unit(pdev)
# define DEVPORT_PDEVFLAGS(pdev) device_get_flags(pdev)
# define DEVPORT_PDEVIOBASE(pdev) bus_get_resource_start(pdev, SYS_RES_IOPORT, 0)
# define DEVPORT_PDEVIRQ(pdev) bus_get_resource_start(pdev, SYS_RES_IRQ, 0)
# define DEVPORT_PDEVMADDR(pdev) bus_get_resource_start(pdev, SYS_RES_MEMORY, 0)
# define DEVPORT_PDEVALLOC_SOFTC(pdev) device_get_softc(pdev)
# define DEVPORT_PDEVGET_SOFTC(pdev) device_get_softc(pdev)
#else
# define DEVPORT_PDEVICE struct pccard_devinfo *
# define DEVPORT_PDEVUNIT(pdev) (pdev)->pd_unit
# define DEVPORT_PDEVFLAGS(pdev) (pdev)->pd_flags
# define DEVPORT_PDEVIOBASE(pdev) (pdev)->pd_iobase
# define DEVPORT_PDEVIRQ(pdev) (pdev)->pd_irq
# define DEVPORT_PDEVMADDR(pdev) (pdev)->pd_maddr
# ifdef DEVPORT_ALLOCSOFTCFUNC
# define DEVPORT_PDEVALLOC_SOFTC(pdev) (DEVPORT_ALLOCSOFTCFUNC)((pdev)->pd_unit)
# else
# define DEVPORT_PDEVALLOC_SOFTC(pdev) DEVPORT_ALLOCSOFTCFUNC_is_not_defined_prior_than_device_port_h
# endif
# ifdef DEVPORT_SOFTCARRAY
# define DEVPORT_PDEVGET_SOFTC(pdev) (DEVPORT_SOFTCARRAY)[(pdev)->pd_unit]
# else
# define DEVPORT_PDEVGET_SOFTC(pdev) DEVPORT_SOFTCARRAY_is_not_defined_prior_than_device_port_h
# endif
#endif
#endif /* __FreeBSD__ */