Changes from the OpenBSD `ncr' driver to byte-swap the script on big-endian

systems.  Should make this go on e.g. the Apple Network Server.
This commit is contained in:
thorpej 1999-12-05 18:25:18 +00:00
parent 60416909de
commit 389c599f35
2 changed files with 80 additions and 72 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ncr.c,v 1.87 1999/10/08 20:43:45 cgd Exp $ */ /* $NetBSD: ncr.c,v 1.88 1999/12/05 18:25:18 thorpej Exp $ */
/************************************************************************** /**************************************************************************
** **
@ -337,15 +337,15 @@
bus_space_write_4 (np->sc_st, np->sc_sh, (o), (val)) bus_space_write_4 (np->sc_st, np->sc_sh, (o), (val))
#define READSCRIPT_OFF(base, off) \ #define READSCRIPT_OFF(base, off) \
(base ? *((INT32 *)((char *)base + (off))) : \ SCR_BO(base ? *((INT32 *)((char *)base + (off))) : \
bus_space_read_4 (np->ram_tag, np->ram_handle, off)) bus_space_read_4 (np->ram_tag, np->ram_handle, off))
#define WRITESCRIPT_OFF(base, off, val) \ #define WRITESCRIPT_OFF(base, off, val) \
do { \ do { \
if (base) \ if (base) \
*((INT32 *)((char *)base + (off))) = (val); \ *((INT32 *)((char *)base + (off))) = (SCR_BO(val)); \
else \ else \
bus_space_write_4 (np->ram_tag, np->ram_handle, off, val); \ bus_space_write_4 (np->ram_tag, np->ram_handle, off, SCR_BO(val)); \
} while (0) } while (0)
#define READSCRIPT(r) \ #define READSCRIPT(r) \
@ -1518,7 +1518,7 @@ static int read_tekram_eeprom
#if 0 #if 0
static char ident[] = static char ident[] =
"\n$NetBSD: ncr.c,v 1.87 1999/10/08 20:43:45 cgd Exp $\n"; "\n$NetBSD: ncr.c,v 1.88 1999/12/05 18:25:18 thorpej Exp $\n";
#endif #endif
static const u_long ncr_version = NCR_VERSION * 11 static const u_long ncr_version = NCR_VERSION * 11
@ -4274,8 +4274,8 @@ static void ncr_attach (pcici_t config_id, int unit)
** init data structure ** init data structure
*/ */
np->ncb_dma->jump_tcb.l_cmd = SCR_JUMP; np->ncb_dma->jump_tcb.l_cmd = SCR_BO(SCR_JUMP);
np->ncb_dma->jump_tcb.l_paddr = NCB_SCRIPTH_PHYS (np, abort); np->ncb_dma->jump_tcb.l_paddr = SCR_BO(NCB_SCRIPTH_PHYS (np, abort));
/* /*
** Get SCSI addr of host adapter (set by bios?). ** Get SCSI addr of host adapter (set by bios?).
@ -4838,13 +4838,15 @@ static INT32 ncr_start (struct scsipi_xfer * xp)
*/ */
if (flags & XS_CTL_DATA_IN) { if (flags & XS_CTL_DATA_IN) {
cp->phys.header.savep = NCB_SCRIPT_PHYS (np, data_in); bus_addr_t sp = NCB_SCRIPT_PHYS (np, data_in);
cp->phys.header.goalp = cp->phys.header.savep +20 +segments*16; cp->phys.header.savep = SCR_BO(sp);
cp->phys.header.goalp = SCR_BO(sp + 20 + segments * 16);
} else if (flags & XS_CTL_DATA_OUT) { } else if (flags & XS_CTL_DATA_OUT) {
cp->phys.header.savep = NCB_SCRIPT_PHYS (np, data_out); bus_addr_t sp = NCB_SCRIPT_PHYS (np, data_out);
cp->phys.header.goalp = cp->phys.header.savep +20 +segments*16; cp->phys.header.savep = SCR_BO(sp);
cp->phys.header.goalp = SCR_BO(sp + 20 + segments * 16);
} else { } else {
cp->phys.header.savep = NCB_SCRIPT_PHYS (np, no_data); cp->phys.header.savep = SCR_BO(NCB_SCRIPT_PHYS (np, no_data));
cp->phys.header.goalp = cp->phys.header.savep; cp->phys.header.goalp = cp->phys.header.savep;
}; };
cp->phys.header.lastp = cp->phys.header.savep; cp->phys.header.lastp = cp->phys.header.savep;
@ -4873,8 +4875,8 @@ static INT32 ncr_start (struct scsipi_xfer * xp)
/* /*
** Startqueue ** Startqueue
*/ */
cp->phys.header.launch.l_paddr = NCB_SCRIPT_PHYS (np, select); cp->phys.header.launch.l_paddr = SCR_BO(NCB_SCRIPT_PHYS (np, select));
cp->phys.header.launch.l_cmd = SCR_JUMP; cp->phys.header.launch.l_cmd = SCR_BO(SCR_JUMP);
/* /*
** select ** select
*/ */
@ -4884,21 +4886,21 @@ static INT32 ncr_start (struct scsipi_xfer * xp)
/* /*
** message ** message
*/ */
cp->phys.smsg.addr = CCB_PHYS (cp, scsi_smsg); cp->phys.smsg.addr = SCR_BO(CCB_PHYS (cp, scsi_smsg));
cp->phys.smsg.size = msglen; cp->phys.smsg.size = SCR_BO(msglen);
cp->phys.smsg2.addr = CCB_PHYS (cp, scsi_smsg2); cp->phys.smsg2.addr = SCR_BO(CCB_PHYS (cp, scsi_smsg2));
cp->phys.smsg2.size = msglen2; cp->phys.smsg2.size = SCR_BO(msglen2);
/* /*
** command ** command
*/ */
cp->phys.cmd.addr = CCB_PHYS (cp, scsi_cmd); cp->phys.cmd.addr = SCR_BO(CCB_PHYS (cp, scsi_cmd));
cp->phys.cmd.size = xp->cmdlen; cp->phys.cmd.size = SCR_BO(xp->cmdlen);
/* /*
** sense command ** sense command
*/ */
cp->phys.scmd.addr = CCB_PHYS (cp, sensecmd); cp->phys.scmd.addr = SCR_BO(CCB_PHYS (cp, sensecmd));
cp->phys.scmd.size = 6; cp->phys.scmd.size = SCR_BO(6);
/* /*
** patch requested size into sense command ** patch requested size into sense command
*/ */
@ -4910,8 +4912,8 @@ static INT32 ncr_start (struct scsipi_xfer * xp)
/* /*
** sense data ** sense data
*/ */
cp->phys.sense.addr = CCB_PHYS (cp, sense_data); cp->phys.sense.addr = SCR_BO(CCB_PHYS (cp, sense_data));
cp->phys.sense.size = sizeof(struct scsipi_sense_data); cp->phys.sense.size = SCR_BO(sizeof(struct scsipi_sense_data));
/* /*
** status ** status
*/ */
@ -4936,7 +4938,7 @@ static INT32 ncr_start (struct scsipi_xfer * xp)
** reselect pattern and activate this job. ** reselect pattern and activate this job.
*/ */
cp->jump_ccb.l_cmd = (SCR_JUMP ^ IFFALSE (DATA (cp->tag))); cp->jump_ccb.l_cmd = SCR_BO((SCR_JUMP ^ IFFALSE (DATA (cp->tag))));
#ifdef __NetBSD__ #ifdef __NetBSD__
cp->tlimit = mono_time.tv_sec + xp->timeout / 1000 + 2; cp->tlimit = mono_time.tv_sec + xp->timeout / 1000 + 2;
#else #else
@ -4950,8 +4952,8 @@ static INT32 ncr_start (struct scsipi_xfer * xp)
qidx = np->squeueput + 1; qidx = np->squeueput + 1;
if (qidx >= MAX_START) qidx=0; if (qidx >= MAX_START) qidx=0;
np->ncb_dma->squeue [qidx ] = NCB_SCRIPT_PHYS (np, idle); np->ncb_dma->squeue [qidx ] = SCR_BO(NCB_SCRIPT_PHYS (np, idle));
np->ncb_dma->squeue [np->squeueput] = CCB_PHYS (cp, phys); np->ncb_dma->squeue [np->squeueput] = SCR_BO(CCB_PHYS (cp, phys));
np->squeueput = qidx; np->squeueput = qidx;
if(DEBUG_FLAGS & DEBUG_QUEUE) if(DEBUG_FLAGS & DEBUG_QUEUE)
@ -5062,12 +5064,12 @@ void ncr_complete (ncb_p np, ccb_p cp)
/* /*
** No Reselect anymore. ** No Reselect anymore.
*/ */
cp->jump_ccb.l_cmd = (SCR_JUMP); cp->jump_ccb.l_cmd = SCR_BO((SCR_JUMP));
/* /*
** No starting. ** No starting.
*/ */
cp->phys.header.launch.l_paddr= NCB_SCRIPT_PHYS (np, idle); cp->phys.header.launch.l_paddr= SCR_BO(NCB_SCRIPT_PHYS (np, idle));
/* /*
** timestamp ** timestamp
@ -5389,7 +5391,7 @@ void ncr_init (ncb_p np, char * msg, u_long code)
*/ */
for (i=0;i<MAX_START;i++) for (i=0;i<MAX_START;i++)
np -> ncb_dma -> squeue [i] = NCB_SCRIPT_PHYS (np, idle); np -> ncb_dma -> squeue [i] = SCR_BO(NCB_SCRIPT_PHYS (np, idle));
/* /*
** Start at first entry. ** Start at first entry.
@ -5992,13 +5994,13 @@ static void ncr_timeout (void *arg)
** Disable reselect. ** Disable reselect.
** Remove it from startqueue. ** Remove it from startqueue.
*/ */
cp->jump_ccb.l_cmd = (SCR_JUMP); cp->jump_ccb.l_cmd = SCR_BO((SCR_JUMP));
if (cp->phys.header.launch.l_paddr == if (cp->phys.header.launch.l_paddr ==
NCB_SCRIPT_PHYS (np, select)) { SCR_BO(NCB_SCRIPT_PHYS (np, select))) {
printf ("%s: timeout ccb=%p (skip)\n", printf ("%s: timeout ccb=%p (skip)\n",
ncr_name (np), cp); ncr_name (np), cp);
cp->phys.header.launch.l_paddr cp->phys.header.launch.l_paddr
= NCB_SCRIPT_PHYS (np, skip); = SCR_BO(NCB_SCRIPT_PHYS (np, skip));
}; };
switch (cp->host_status) { switch (cp->host_status) {
@ -6009,7 +6011,7 @@ static void ncr_timeout (void *arg)
** still in start queue ? ** still in start queue ?
*/ */
if (cp->phys.header.launch.l_paddr == if (cp->phys.header.launch.l_paddr ==
NCB_SCRIPT_PHYS (np, skip)) SCR_BO(NCB_SCRIPT_PHYS (np, skip)))
continue; continue;
/* fall through */ /* fall through */
@ -6603,8 +6605,8 @@ static void ncr_int_ma (ncb_p np, u_char dstat)
if (cmd & 0x10) { /* Table indirect */ if (cmd & 0x10) { /* Table indirect */
tblp = (u_int32_t *) ((char*) &cp->phys + oadr); tblp = (u_int32_t *) ((char*) &cp->phys + oadr);
olen = tblp[0]; olen = SCR_BO(tblp[0]);
oadr = tblp[1]; oadr = SCR_BO(tblp[1]);
} else { } else {
tblp = (u_int32_t *) 0; tblp = (u_int32_t *) 0;
olen = READSCRIPT_OFF(vdsp_base, vdsp_off) & 0xffffff; olen = READSCRIPT_OFF(vdsp_base, vdsp_off) & 0xffffff;
@ -6646,16 +6648,16 @@ static void ncr_int_ma (ncb_p np, u_char dstat)
*/ */
newcmd = cp->patch; newcmd = cp->patch;
if (cp->phys.header.savep == vtophys (newcmd)) newcmd+=4; if (cp->phys.header.savep == SCR_BO(vtophys (newcmd))) newcmd+=4;
/* /*
** fillin the commands ** fillin the commands
*/ */
newcmd[0] = ((cmd & 0x0f) << 24) | rest; newcmd[0] = SCR_BO(((cmd & 0x0f) << 24) | rest);
newcmd[1] = oadr + olen - rest; newcmd[1] = SCR_BO(oadr + olen - rest);
newcmd[2] = SCR_JUMP; newcmd[2] = SCR_BO(SCR_JUMP);
newcmd[3] = nxtdsp; newcmd[3] = SCR_BO(nxtdsp);
if (DEBUG_FLAGS & DEBUG_PHASE) { if (DEBUG_FLAGS & DEBUG_PHASE) {
PRINT_ADDR(cp->xfer); PRINT_ADDR(cp->xfer);
@ -7203,8 +7205,8 @@ void ncr_int_sir (ncb_p np)
printf ("M_DISCONNECT received, but datapointer not saved:\n" printf ("M_DISCONNECT received, but datapointer not saved:\n"
"\tdata=%x save=%x goal=%x.\n", "\tdata=%x save=%x goal=%x.\n",
(unsigned) INL (nc_temp), (unsigned) INL (nc_temp),
(unsigned) np->ncb_dma->header.savep, SCR_BO((unsigned) np->ncb_dma->header.savep),
(unsigned) np->ncb_dma->header.goalp); SCR_BO((unsigned) np->ncb_dma->header.goalp));
break; break;
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
@ -7428,29 +7430,28 @@ static void ncr_alloc_ccb (ncb_p np, u_long target, u_long lun)
/* /*
** initialize it. ** initialize it.
*/ */
tp->jump_tcb.l_cmd = (SCR_JUMP^IFFALSE (DATA (0x80 + target))); tp->jump_tcb.l_cmd = SCR_BO((SCR_JUMP^IFFALSE (DATA (0x80 + target))));
tp->jump_tcb.l_paddr = np->ncb_dma->jump_tcb.l_paddr; tp->jump_tcb.l_paddr = np->ncb_dma->jump_tcb.l_paddr;
tp->getscr[0] = tp->getscr[0] =
(np->features & FE_PFEN)? SCR_COPY(1) : SCR_COPY_F(1); (np->features & FE_PFEN)? SCR_BO(SCR_COPY(1)) : SCR_BO(SCR_COPY_F(1));
tp->getscr[1] = vtophys (&tp->sval); tp->getscr[1] = SCR_BO(vtophys (&tp->sval));
tp->getscr[2] = np->paddr + offsetof (struct ncr_reg, nc_sxfer); tp->getscr[2] = SCR_BO(np->paddr + offsetof (struct ncr_reg, nc_sxfer));
tp->getscr[3] = tp->getscr[3] = tp->getscr[0];
(np->features & FE_PFEN)? SCR_COPY(1) : SCR_COPY_F(1); tp->getscr[4] = SCR_BO(vtophys (&tp->wval));
tp->getscr[4] = vtophys (&tp->wval); tp->getscr[5] = SCR_BO(np->paddr + offsetof (struct ncr_reg, nc_scntl3));
tp->getscr[5] = np->paddr + offsetof (struct ncr_reg, nc_scntl3);
assert (( (offsetof(struct ncr_reg, nc_sxfer) ^ assert (( (offsetof(struct ncr_reg, nc_sxfer) ^
offsetof(struct tcb , sval )) &3) == 0); offsetof(struct tcb , sval )) &3) == 0);
assert (( (offsetof(struct ncr_reg, nc_scntl3) ^ assert (( (offsetof(struct ncr_reg, nc_scntl3) ^
offsetof(struct tcb , wval )) &3) == 0); offsetof(struct tcb , wval )) &3) == 0);
tp->call_lun.l_cmd = (SCR_CALL); tp->call_lun.l_cmd = SCR_BO((SCR_CALL));
tp->call_lun.l_paddr = NCB_SCRIPT_PHYS (np, resel_lun); tp->call_lun.l_paddr = SCR_BO(NCB_SCRIPT_PHYS (np, resel_lun));
tp->jump_lcb.l_cmd = (SCR_JUMP); tp->jump_lcb.l_cmd = SCR_BO((SCR_JUMP));
tp->jump_lcb.l_paddr = NCB_SCRIPTH_PHYS (np, abort); tp->jump_lcb.l_paddr = SCR_BO(NCB_SCRIPTH_PHYS (np, abort));
np->ncb_dma->jump_tcb.l_paddr = vtophys (&tp->jump_tcb); np->ncb_dma->jump_tcb.l_paddr = SCR_BO(vtophys (&tp->jump_tcb));
tp->usrtags = SCSI_NCR_DFLT_TAGS; tp->usrtags = SCSI_NCR_DFLT_TAGS;
ncr_setmaxtags (tp, tp->usrtags); ncr_setmaxtags (tp, tp->usrtags);
@ -7471,21 +7472,21 @@ static void ncr_alloc_ccb (ncb_p np, u_long target, u_long lun)
** Initialize it ** Initialize it
*/ */
bzero (lp, sizeof (*lp)); bzero (lp, sizeof (*lp));
lp->jump_lcb.l_cmd = (SCR_JUMP ^ IFFALSE (DATA (lun))); lp->jump_lcb.l_cmd = SCR_BO((SCR_JUMP ^ IFFALSE (DATA (lun))));
lp->jump_lcb.l_paddr = tp->jump_lcb.l_paddr; lp->jump_lcb.l_paddr = tp->jump_lcb.l_paddr;
lp->call_tag.l_cmd = (SCR_CALL); lp->call_tag.l_cmd = SCR_BO((SCR_CALL));
lp->call_tag.l_paddr = NCB_SCRIPT_PHYS (np, resel_tag); lp->call_tag.l_paddr = SCR_BO(NCB_SCRIPT_PHYS (np, resel_tag));
lp->jump_ccb.l_cmd = (SCR_JUMP); lp->jump_ccb.l_cmd = SCR_BO((SCR_JUMP));
lp->jump_ccb.l_paddr = NCB_SCRIPTH_PHYS (np, aborttag); lp->jump_ccb.l_paddr = SCR_BO(NCB_SCRIPTH_PHYS (np, aborttag));
lp->actlink = 1; lp->actlink = 1;
/* /*
** Chain into LUN list ** Chain into LUN list
*/ */
tp->jump_lcb.l_paddr = vtophys (&lp->jump_lcb); tp->jump_lcb.l_paddr = SCR_BO(vtophys (&lp->jump_lcb));
tp->lp[lun] = lp; tp->lp[lun] = lp;
} }
@ -7538,11 +7539,11 @@ static void ncr_alloc_ccb (ncb_p np, u_long target, u_long lun)
/* /*
** Chain into reselect list ** Chain into reselect list
*/ */
cp->jump_ccb.l_cmd = SCR_JUMP; cp->jump_ccb.l_cmd = SCR_BO(SCR_JUMP);
cp->jump_ccb.l_paddr = lp->jump_ccb.l_paddr; cp->jump_ccb.l_paddr = lp->jump_ccb.l_paddr;
lp->jump_ccb.l_paddr = CCB_PHYS (cp, jump_ccb); lp->jump_ccb.l_paddr = SCR_BO(CCB_PHYS (cp, jump_ccb));
cp->call_tmp.l_cmd = SCR_CALL; cp->call_tmp.l_cmd = SCR_BO(SCR_CALL);
cp->call_tmp.l_paddr = NCB_SCRIPT_PHYS (np, resel_tmp); cp->call_tmp.l_paddr = SCR_BO(NCB_SCRIPT_PHYS (np, resel_tmp));
/* /*
** Chain into wakeup list ** Chain into wakeup list
@ -7745,8 +7746,8 @@ static int ncr_scatter
(unsigned) segsize, (unsigned) segsize,
(unsigned) datalen); (unsigned) datalen);
phys->data[segment].addr = segaddr; phys->data[segment].addr = SCR_BO(segaddr);
phys->data[segment].size = segsize; phys->data[segment].size = SCR_BO(segsize);
segment++; segment++;
} }
@ -7820,7 +7821,7 @@ static int ncr_snooptest (struct ncb* np)
** Set memory and register. ** Set memory and register.
*/ */
ncr_cache = host_wr; ncr_cache = host_wr;
OUTL (nc_temp, ncr_wr); OUTL (nc_temp, SCR_BO(ncr_wr));
/* /*
** Start script (exchange values) ** Start script (exchange values)
*/ */
@ -7839,8 +7840,8 @@ static int ncr_snooptest (struct ncb* np)
** Read memory and register. ** Read memory and register.
*/ */
host_rd = ncr_cache; host_rd = ncr_cache;
ncr_rd = INL (nc_scratcha); ncr_rd = SCR_BO(INL (nc_scratcha));
ncr_bk = INL (nc_temp); ncr_bk = SCR_BO(INL (nc_temp));
/* /*
** Reset ncr chip ** Reset ncr chip
*/ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: ncrreg.h,v 1.14 1997/09/23 02:27:46 perry Exp $ */ /* $NetBSD: ncrreg.h,v 1.15 1999/12/05 18:25:19 thorpej Exp $ */
/************************************************************************** /**************************************************************************
** **
@ -293,6 +293,13 @@ struct ncr_reg {
typedef U_INT32 ncrcmd; typedef U_INT32 ncrcmd;
#if BYTE_ORDER == BIG_ENDIAN
#define SCR_BO(x) (((x) >> 24) | (((x) >> 8) & 0xff00) | \
((x) << 24) | (((x) & 0xff00) << 8))
#else
#define SCR_BO(x) (x)
#endif
/*----------------------------------------------------------- /*-----------------------------------------------------------
** **
** SCSI phases ** SCSI phases