summaryrefslogtreecommitdiffstats
path: root/sys/dev
diff options
context:
space:
mode:
authormarius <marius@FreeBSD.org>2008-07-22 13:51:21 +0000
committermarius <marius@FreeBSD.org>2008-07-22 13:51:21 +0000
commit9bda798c14571cd281479a4b1f94548075fdfd72 (patch)
tree408f271b0c51f34496ef51e5045a0e034c880a74 /sys/dev
parentd3860f979e7346edf26705009a3ed709e9d92c51 (diff)
downloadFreeBSD-src-9bda798c14571cd281479a4b1f94548075fdfd72.zip
FreeBSD-src-9bda798c14571cd281479a4b1f94548075fdfd72.tar.gz
o Fix style(9) bugs and similar nits.
o Merge ncr53c9x.c from NetBSD: 1.115: fix variable shadowing 1.118: __inline -> inline 1.121: fix empty if
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/esp/esp_sbus.c51
-rw-r--r--sys/dev/esp/ncr53c9x.c699
-rw-r--r--sys/dev/esp/ncr53c9xvar.h199
3 files changed, 477 insertions, 472 deletions
diff --git a/sys/dev/esp/esp_sbus.c b/sys/dev/esp/esp_sbus.c
index c7b9b7b..962dab1 100644
--- a/sys/dev/esp/esp_sbus.c
+++ b/sys/dev/esp/esp_sbus.c
@@ -158,19 +158,19 @@ MODULE_DEPEND(esp, sbus, 1, 1, 1);
MODULE_DEPEND(esp, cam, 1, 1, 1);
/*
- * Functions and the switch for the MI code.
+ * Functions and the switch for the MI code
*/
-static u_char esp_read_reg(struct ncr53c9x_softc *, int);
-static void esp_write_reg(struct ncr53c9x_softc *, int, u_char);
-static int esp_dma_isintr(struct ncr53c9x_softc *);
-static void esp_dma_reset(struct ncr53c9x_softc *);
-static int esp_dma_intr(struct ncr53c9x_softc *);
-static int esp_dma_setup(struct ncr53c9x_softc *, caddr_t *, size_t *,
- int, size_t *);
-static void esp_dma_go(struct ncr53c9x_softc *);
-static void esp_dma_stop(struct ncr53c9x_softc *);
-static int esp_dma_isactive(struct ncr53c9x_softc *);
-static int espattach(struct esp_softc *, struct ncr53c9x_glue *);
+static u_char esp_read_reg(struct ncr53c9x_softc *sc, int reg);
+static void esp_write_reg(struct ncr53c9x_softc *sc, int reg, u_char v);
+static int esp_dma_isintr(struct ncr53c9x_softc *sc);
+static void esp_dma_reset(struct ncr53c9x_softc *sc);
+static int esp_dma_intr(struct ncr53c9x_softc *sc);
+static int esp_dma_setup(struct ncr53c9x_softc *sc, caddr_t *addr,
+ size_t *len, int datain, size_t *dmasize);
+static void esp_dma_go(struct ncr53c9x_softc *sc);
+static void esp_dma_stop(struct ncr53c9x_softc *sc);
+static int esp_dma_isactive(struct ncr53c9x_softc *sc);
+static int espattach(struct esp_softc *esc, struct ncr53c9x_glue *gluep);
static struct ncr53c9x_glue esp_sbus_glue = {
esp_read_reg,
@@ -311,7 +311,7 @@ esp_sbus_attach(device_t dev)
esc->sc_regh = rman_get_bushandle(esc->sc_res);
} else {
/*
- * Search accompanying DMA engine. It should have been
+ * Search accompanying DMA engine. It should have been
* already attached otherwise there isn't much we can do.
*/
if (device_get_children(device_get_parent(dev), &children,
@@ -498,9 +498,6 @@ esp_resume(device_t dev)
return (ENXIO);
}
-/*
- * Attach this instance, and then all the sub-devices
- */
static int
espattach(struct esp_softc *esc, struct ncr53c9x_glue *gluep)
{
@@ -530,7 +527,7 @@ espattach(struct esp_softc *esc, struct ncr53c9x_glue *gluep)
*/
/*
- * Read the part-unique ID code of the SCSI chip. The contained
+ * Read the part-unique ID code of the SCSI chip. The contained
* value is only valid if all of the following conditions are met:
* - After power-up or chip reset.
* - Before any value is written to this register.
@@ -570,7 +567,7 @@ espattach(struct esp_softc *esc, struct ncr53c9x_glue *gluep)
(NCRCFG3_CDB | NCRCFG3_FCLK)) {
sc->sc_rev = NCR_VARIANT_ESP100A;
} else {
- /* NCRCFG2_FE enables > 64K transfers */
+ /* NCRCFG2_FE enables > 64K transfers. */
sc->sc_cfg2 |= NCRCFG2_FE;
sc->sc_cfg3 = 0;
NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
@@ -581,15 +578,18 @@ espattach(struct esp_softc *esc, struct ncr53c9x_glue *gluep)
case 0x00:
sc->sc_rev = NCR_VARIANT_FAS100A;
break;
+
case 0x02:
if ((uid & 0x07) == 0x02)
sc->sc_rev = NCR_VARIANT_FAS216;
else
sc->sc_rev = NCR_VARIANT_FAS236;
break;
+
case 0x0a:
sc->sc_rev = NCR_VARIANT_FAS366;
break;
+
default:
/*
* We could just treat unknown chips
@@ -660,10 +660,10 @@ espattach(struct esp_softc *esc, struct ncr53c9x_glue *gluep)
/*
* The onboard SCSI chips in Sun Ultra 1 are actually
* documented to be NCR53C9X which use NCRCFG3_FCLK and
- * NCRCFG3_FSCSI. BSD/OS however probes these chips as
+ * NCRCFG3_FSCSI. BSD/OS however probes these chips as
* FAS100A and uses NCRF9XCFG3_FCLK and NCRF9XCFG3_FSCSI
* instead which seems to be correct as otherwise sync
- * negotiation just doesn't work. Using NCRF9XCFG3_FCLK
+ * negotiation just doesn't work. Using NCRF9XCFG3_FCLK
* and NCRF9XCFG3_FSCSI with these chips in fact also
* yields Fast-SCSI speed.
*/
@@ -683,7 +683,7 @@ espattach(struct esp_softc *esc, struct ncr53c9x_glue *gluep)
/* Limit minsync due to unsolved performance issues. */
sc->sc_maxsync = sc->sc_minsync;
- /* Establish interrupt channel */
+ /* Establish interrupt channel. */
esc->sc_irqrid = 0;
if ((esc->sc_irqres = bus_alloc_resource_any(esc->sc_dev, SYS_RES_IRQ,
&esc->sc_irqrid, RF_SHAREABLE|RF_ACTIVE)) == NULL) {
@@ -697,7 +697,7 @@ espattach(struct esp_softc *esc, struct ncr53c9x_glue *gluep)
goto fail_ires;
}
- /* Turn on target selection using the `DMA' method */
+ /* Turn on target selection using the `DMA' method. */
if (sc->sc_rev != NCR_VARIANT_FAS366)
sc->sc_features |= NCR_F_DMASELECT;
@@ -720,7 +720,7 @@ espattach(struct esp_softc *esc, struct ncr53c9x_glue *gluep)
}
/*
- * Glue functions.
+ * Glue functions
*/
#ifdef ESP_SBUS_DEBUG
@@ -844,11 +844,8 @@ static void
esp_dma_stop(struct ncr53c9x_softc *sc)
{
struct esp_softc *esc = (struct esp_softc *)sc;
- uint32_t csr;
- csr = L64854_GCSR(esc->sc_dma);
- csr &= ~D_EN_DMA;
- L64854_SCSR(esc->sc_dma, csr);
+ L64854_SCSR(esc->sc_dma, L64854_GCSR(esc->sc_dma) & ~D_EN_DMA);
}
static int
diff --git a/sys/dev/esp/ncr53c9x.c b/sys/dev/esp/ncr53c9x.c
index 5492b37..ab94a8c 100644
--- a/sys/dev/esp/ncr53c9x.c
+++ b/sys/dev/esp/ncr53c9x.c
@@ -129,46 +129,54 @@ __FBSDID("$FreeBSD$");
#include <dev/esp/ncr53c9xreg.h>
#include <dev/esp/ncr53c9xvar.h>
-int ncr53c9x_debug = NCR_SHOWMISC /*|NCR_SHOWPHASE|NCR_SHOWTRAC|NCR_SHOWCMDS*/;
+int ncr53c9x_debug =
+ NCR_SHOWMISC /* | NCR_SHOWPHASE | NCR_SHOWTRAC | NCR_SHOWCMDS */;
#ifdef DEBUG
int ncr53c9x_notag = 0;
#endif
-static void ncr53c9x_select(struct ncr53c9x_softc *, struct ncr53c9x_ecb *);
-static int ncr53c9x_reselect(struct ncr53c9x_softc *, int, int, int);
-static void ncr53c9x_scsi_reset(struct ncr53c9x_softc *);
-static void ncr53c9x_poll(struct cam_sim *);
-static void ncr53c9x_sched(struct ncr53c9x_softc *);
-static void ncr53c9x_done(struct ncr53c9x_softc *, struct ncr53c9x_ecb *);
-static void ncr53c9x_msgin(struct ncr53c9x_softc *);
-static void ncr53c9x_msgout(struct ncr53c9x_softc *);
+static void ncr53c9x_abort(struct ncr53c9x_softc *sc,
+ struct ncr53c9x_ecb *ecb);
+static void ncr53c9x_dequeue(struct ncr53c9x_softc *sc,
+ struct ncr53c9x_ecb *ecb);
+static void ncr53c9x_done(struct ncr53c9x_softc *sc,
+ struct ncr53c9x_ecb *ecb);
+static void ncr53c9x_free_ecb(struct ncr53c9x_softc *sc,
+ struct ncr53c9x_ecb *ecb);
+static void ncr53c9x_msgin(struct ncr53c9x_softc *sc);
+static void ncr53c9x_msgout(struct ncr53c9x_softc *sc);
+static void ncr53c9x_poll(struct cam_sim *sim);
+static int ncr53c9x_rdfifo(struct ncr53c9x_softc *sc, int how);
+static int ncr53c9x_reselect(struct ncr53c9x_softc *sc, int message,
+ int tagtype, int tagid);
+static void ncr53c9x_sense(struct ncr53c9x_softc *sc,
+ struct ncr53c9x_ecb *ecb);
+static void ncr53c9x_scsi_reset(struct ncr53c9x_softc *sc);
+static void ncr53c9x_sched(struct ncr53c9x_softc *sc);
+static void ncr53c9x_select(struct ncr53c9x_softc *sc,
+ struct ncr53c9x_ecb *ecb);
static void ncr53c9x_timeout(void *arg);
static void ncr53c9x_watch(void *arg);
-static void ncr53c9x_abort(struct ncr53c9x_softc *, struct ncr53c9x_ecb *);
-static void ncr53c9x_dequeue(struct ncr53c9x_softc *,
- struct ncr53c9x_ecb *);
-static void ncr53c9x_sense(struct ncr53c9x_softc *, struct ncr53c9x_ecb *);
-static void ncr53c9x_free_ecb(struct ncr53c9x_softc *,
- struct ncr53c9x_ecb *);
-static void ncr53c9x_wrfifo(struct ncr53c9x_softc *, u_char *, int);
-static int ncr53c9x_rdfifo(struct ncr53c9x_softc *, int);
-
-static struct ncr53c9x_ecb *ncr53c9x_get_ecb(struct ncr53c9x_softc *);
-static struct ncr53c9x_linfo *ncr53c9x_lunsearch(struct ncr53c9x_tinfo *,
- int64_t lun);
-
-static __inline void ncr53c9x_readregs(struct ncr53c9x_softc *);
-static __inline int ncr53c9x_stp2cpb(struct ncr53c9x_softc *, int);
-static __inline void ncr53c9x_setsync(struct ncr53c9x_softc *,
- struct ncr53c9x_tinfo *);
-
-#define NCR_RDFIFO_START 0
-#define NCR_RDFIFO_CONTINUE 1
-
-#define NCR_SET_COUNT(sc, size) do { \
- NCR_WRITE_REG((sc), NCR_TCL, (size)); \
+static void ncr53c9x_wrfifo(struct ncr53c9x_softc *sc, u_char *p,
+ int len);
+
+static struct ncr53c9x_ecb *ncr53c9x_get_ecb(struct ncr53c9x_softc *sc);
+static struct ncr53c9x_linfo *ncr53c9x_lunsearch(struct ncr53c9x_tinfo *sc,
+ int64_t lun);
+
+static inline void ncr53c9x_readregs(struct ncr53c9x_softc *sc);
+static inline void ncr53c9x_setsync(struct ncr53c9x_softc *sc,
+ struct ncr53c9x_tinfo *ti);
+static inline int ncr53c9x_stp2cpb(struct ncr53c9x_softc *sc,
+ int period);
+
+#define NCR_RDFIFO_START 0
+#define NCR_RDFIFO_CONTINUE 1
+
+#define NCR_SET_COUNT(sc, size) do { \
+ NCR_WRITE_REG((sc), NCR_TCL, (size)); \
NCR_WRITE_REG((sc), NCR_TCM, (size) >> 8); \
- if ((sc->sc_cfg2 & NCRCFG2_FE) || \
+ if ((sc->sc_cfg2 & NCRCFG2_FE) || \
(sc->sc_rev == NCR_VARIANT_FAS366)) { \
NCR_WRITE_REG((sc), NCR_TCH, (size) >> 16); \
} \
@@ -178,8 +186,8 @@ static __inline void ncr53c9x_setsync(struct ncr53c9x_softc *,
} while (0)
#ifndef mstohz
-#define mstohz(ms) \
- (((ms) < 0x20000) ? \
+#define mstohz(ms) \
+ (((ms) < 0x20000) ? \
((ms +0u) / 1000u) * hz : \
((ms +0u) * hz) /1000u)
#endif
@@ -211,6 +219,7 @@ static struct ncr53c9x_linfo *
ncr53c9x_lunsearch(struct ncr53c9x_tinfo *ti, int64_t lun)
{
struct ncr53c9x_linfo *li;
+
LIST_FOREACH(li, &ti->luns, link)
if (li->lun == lun)
return (li);
@@ -248,7 +257,7 @@ ncr53c9x_attach(struct ncr53c9x_softc *sc)
/*
* Allocate SCSI message buffers.
* Front-ends can override allocation to avoid alignment
- * handling in the DMA engines. Note that that ncr53c9x_msgout()
+ * handling in the DMA engines. Note that ncr53c9x_msgout()
* can request a 1 byte DMA transfer.
*/
if (sc->sc_omess == NULL) {
@@ -294,12 +303,12 @@ ncr53c9x_attach(struct ncr53c9x_softc *sc)
sc->sc_ccf = FREQTOCCF(sc->sc_freq);
- /* The value *must not* be == 1. Make it 2 */
+ /* The value *must not* be == 1. Make it 2. */
if (sc->sc_ccf == 1)
sc->sc_ccf = 2;
/*
- * The recommended timeout is 250ms. This register is loaded
+ * The recommended timeout is 250ms. This register is loaded
* with a value calculated as follows, from the docs:
*
* (timout period) x (CLK frequency)
@@ -311,11 +320,11 @@ ncr53c9x_attach(struct ncr53c9x_softc *sc)
*/
sc->sc_timeout = ((250 * 1000) * sc->sc_freq) / (8192 * sc->sc_ccf);
- /* CCF register only has 3 bits; 0 is actually 8 */
+ /* The CCF register only has 3 bits; 0 is actually 8. */
sc->sc_ccf &= 7;
/*
- * Register with CAM
+ * Register with CAM.
*/
devq = cam_simq_alloc(sc->sc_ntarg);
if (devq == NULL) {
@@ -325,8 +334,7 @@ ncr53c9x_attach(struct ncr53c9x_softc *sc)
}
sim = cam_sim_alloc(ncr53c9x_action, ncr53c9x_poll, "esp", sc,
- device_get_unit(sc->sc_dev), &Giant, 1,
- NCR_TAG_DEPTH, devq);
+ device_get_unit(sc->sc_dev), &Giant, 1, NCR_TAG_DEPTH, devq);
if (sim == NULL) {
device_printf(sc->sc_dev, "cannot allocate SIM entry\n");
error = ENOMEM;
@@ -339,8 +347,7 @@ ncr53c9x_attach(struct ncr53c9x_softc *sc)
}
if (xpt_create_path(&path, NULL, cam_sim_path(sim),
- CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD)
- != CAM_REQ_CMP) {
+ CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
device_printf(sc->sc_dev, "cannot create path\n");
error = EIO;
goto fail_bus;
@@ -349,16 +356,19 @@ ncr53c9x_attach(struct ncr53c9x_softc *sc)
sc->sc_sim = sim;
sc->sc_path = path;
- /* Reset state & bus */
+ /* Reset state and bus. */
#if 0
sc->sc_cfflags = sc->sc_dev.dv_cfdata->cf_flags;
+#else
+ sc->sc_cfflags = 0;
#endif
sc->sc_state = 0;
ncr53c9x_init(sc, 1);
TAILQ_INIT(&sc->free_list);
- if ((sc->ecb_array = malloc(sizeof(struct ncr53c9x_ecb) * NCR_TAG_DEPTH,
- M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL) {
+ if ((sc->ecb_array =
+ malloc(sizeof(struct ncr53c9x_ecb) * NCR_TAG_DEPTH, M_DEVBUF,
+ M_NOWAIT | M_ZERO)) == NULL) {
device_printf(sc->sc_dev, "cannot allocate ECB array\n");
error = ENOMEM;
goto fail_path;
@@ -416,8 +426,8 @@ ncr53c9x_detach(struct ncr53c9x_softc *sc)
}
/*
- * This is the generic ncr53c9x reset function. It does not reset the SCSI bus,
- * only this controller, but kills any on-going commands, and also stops
+ * This is the generic ncr53c9x reset function. It does not reset the SCSI
+ * bus, only this controller, but kills any on-going commands, and also stops
* and resets the DMA.
*
* After reset, registers are loaded with the defaults from the attach
@@ -427,20 +437,21 @@ void
ncr53c9x_reset(struct ncr53c9x_softc *sc)
{
- /* reset DMA first */
+ /* Reset DMA first. */
NCRDMA_RESET(sc);
- /* reset SCSI chip */
+ /* Reset SCSI chip. */
NCRCMD(sc, NCRCMD_RSTCHIP);
NCRCMD(sc, NCRCMD_NOP);
DELAY(500);
- /* do these backwards, and fall through */
+ /* Do these backwards, and fall through. */
switch (sc->sc_rev) {
case NCR_VARIANT_ESP406:
case NCR_VARIANT_FAS408:
NCR_WRITE_REG(sc, NCR_CFG5, sc->sc_cfg5 | NCRCFG5_SINT);
NCR_WRITE_REG(sc, NCR_CFG4, sc->sc_cfg4);
+ /* FALLTHROUGH */
case NCR_VARIANT_AM53C974:
case NCR_VARIANT_FAS100A:
case NCR_VARIANT_FAS216:
@@ -450,9 +461,11 @@ ncr53c9x_reset(struct ncr53c9x_softc *sc)
case NCR_VARIANT_ESP200:
sc->sc_features |= NCR_F_HASCFG3;
NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
+ /* FALLTHROUGH */
case NCR_VARIANT_ESP100A:
sc->sc_features |= NCR_F_SELATN3;
NCR_WRITE_REG(sc, NCR_CFG2, sc->sc_cfg2);
+ /* FALLTHROUGH */
case NCR_VARIANT_ESP100:
NCR_WRITE_REG(sc, NCR_CFG1, sc->sc_cfg1);
NCR_WRITE_REG(sc, NCR_CCF, sc->sc_ccf);
@@ -466,7 +479,7 @@ ncr53c9x_reset(struct ncr53c9x_softc *sc)
sc->sc_cfg3 = NCRFASCFG3_FASTCLK | NCRFASCFG3_OBAUTO;
sc->sc_cfg3_fscsi = NCRFASCFG3_FASTSCSI;
NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
- sc->sc_cfg2 = 0; /* NCRCFG2_HMEFE| NCRCFG2_HME32 */
+ sc->sc_cfg2 = 0; /* NCRCFG2_HMEFE | NCRCFG2_HME32 */
NCR_WRITE_REG(sc, NCR_CFG2, sc->sc_cfg2);
NCR_WRITE_REG(sc, NCR_CFG1, sc->sc_cfg1);
NCR_WRITE_REG(sc, NCR_CCF, sc->sc_ccf);
@@ -475,8 +488,8 @@ ncr53c9x_reset(struct ncr53c9x_softc *sc)
break;
default:
- device_printf(sc->sc_dev, "unknown revision code, "
- "assuming ESP100\n");
+ device_printf(sc->sc_dev,
+ "unknown revision code, assuming ESP100\n");
NCR_WRITE_REG(sc, NCR_CFG1, sc->sc_cfg1);
NCR_WRITE_REG(sc, NCR_CCF, sc->sc_ccf);
NCR_WRITE_REG(sc, NCR_SYNCOFF, 0);
@@ -488,7 +501,7 @@ ncr53c9x_reset(struct ncr53c9x_softc *sc)
#if 0
device_printf(sc->sc_dev, "ncr53c9x_reset: revision %d\n",
- sc->sc_rev);
+ sc->sc_rev);
device_printf(sc->sc_dev, "ncr53c9x_reset: cfg1 0x%x, cfg2 0x%x, "
"cfg3 0x%x, ccf 0x%x, timeout 0x%x\n",
sc->sc_cfg1, sc->sc_cfg2, sc->sc_cfg3, sc->sc_ccf, sc->sc_timeout);
@@ -496,7 +509,7 @@ ncr53c9x_reset(struct ncr53c9x_softc *sc)
}
/*
- * Reset the SCSI bus, but not the chip
+ * Reset the SCSI bus, but not the chip.
*/
static void
ncr53c9x_scsi_reset(struct ncr53c9x_softc *sc)
@@ -510,13 +523,14 @@ ncr53c9x_scsi_reset(struct ncr53c9x_softc *sc)
}
/*
- * Initialize ncr53c9x state machine
+ * Initialize ncr53c9x state machine.
*/
void
ncr53c9x_init(struct ncr53c9x_softc *sc, int doreset)
{
struct ncr53c9x_ecb *ecb;
struct ncr53c9x_linfo *li;
+ struct ncr53c9x_tinfo *ti;
int i, r;
NCR_MISC(("[NCR_INIT(%d) %d] ", doreset, sc->sc_state));
@@ -538,13 +552,13 @@ ncr53c9x_init(struct ncr53c9x_softc *sc, int doreset)
ecb->ccb->ccb_h.status = CAM_CMD_TIMEOUT;
ncr53c9x_done(sc, ecb);
}
- /* Cancel outstanding disconnected commands on each LUN */
+ /* Cancel outstanding disconnected commands on each LUN. */
for (r = 0; r < sc->sc_ntarg; r++) {
LIST_FOREACH(li, &sc->sc_tinfo[r].luns, link) {
if ((ecb = li->untagged) != NULL) {
li->untagged = NULL;
/*
- * XXXXXXX
+ * XXX
*
* Should we terminate a command
* that never reached the disk?
@@ -567,7 +581,7 @@ ncr53c9x_init(struct ncr53c9x_softc *sc, int doreset)
}
/*
- * reset the chip to a known state
+ * Reset the chip to a known state.
*/
ncr53c9x_reset(sc);
@@ -576,12 +590,14 @@ ncr53c9x_init(struct ncr53c9x_softc *sc, int doreset)
sc->sc_phase = sc->sc_prevphase = INVALID_PHASE;
for (r = 0; r < sc->sc_ntarg; r++) {
- struct ncr53c9x_tinfo *ti = &sc->sc_tinfo[r];
+ ti = &sc->sc_tinfo[r];
/* XXX - config flags per target: low bits: no reselect; high bits: no synch */
+ ti->flags = ((sc->sc_minsync != 0 &&
+ (sc->sc_cfflags & (1 << ((r & 7) + 8))) == 0) ?
+ 0 : T_SYNCHOFF) |
+ ((sc->sc_cfflags & (1 << (r & 7))) == 0 ?
+ 0 : T_RSELECTOFF);
- ti->flags = ((sc->sc_minsync && !(sc->sc_cfflags & (1<<((r&7)+8))))
- ? 0 : T_SYNCHOFF) |
- ((sc->sc_cfflags & (1<<(r&7))) ? T_RSELECTOFF : 0);
#ifdef DEBUG
if (ncr53c9x_notag)
ti->flags &= ~T_TAG;
@@ -606,15 +622,15 @@ ncr53c9x_init(struct ncr53c9x_softc *sc, int doreset)
* NCR_INTR - so make sure it is the last read.
*
* I think that (from reading the docs) most bits in these registers
- * only make sense when he DMA CSR has an interrupt showing. Call only
+ * only make sense when the DMA CSR has an interrupt showing. Call only
* if an interrupt is pending.
*/
-static __inline void
+static inline void
ncr53c9x_readregs(struct ncr53c9x_softc *sc)
{
sc->sc_espstat = NCR_READ_REG(sc, NCR_STAT);
- /* Only the stepo bits are of interest */
+ /* Only the step bits are of interest. */
sc->sc_espstep = NCR_READ_REG(sc, NCR_STEP) & NCRSTEP_MASK;
if (sc->sc_rev == NCR_VARIANT_FAS366)
@@ -629,9 +645,8 @@ ncr53c9x_readregs(struct ncr53c9x_softc *sc)
* Determine the SCSI bus phase, return either a real SCSI bus phase
* or some pseudo phase we use to detect certain exceptions.
*/
-
sc->sc_phase = (sc->sc_espintr & NCRINTR_DIS) ?
- /* Disconnected */ BUSFREE_PHASE : sc->sc_espstat & NCRSTAT_PHASE;
+ BUSFREE_PHASE : sc->sc_espstat & NCRSTAT_PHASE;
NCR_INTS(("regs[intr=%02x,stat=%02x,step=%02x,stat2=%02x] ",
sc->sc_espintr, sc->sc_espstat, sc->sc_espstep, sc->sc_espstat2));
@@ -640,18 +655,18 @@ ncr53c9x_readregs(struct ncr53c9x_softc *sc)
/*
* Convert Synchronous Transfer Period to chip register Clock Per Byte value.
*/
-static __inline int
+static inline int
ncr53c9x_stp2cpb(struct ncr53c9x_softc *sc, int period)
{
int v;
v = (sc->sc_freq * period) / 250;
if (ncr53c9x_cpb2stp(sc, v) < period)
- /* Correct round-down error */
+ /* Correct round-down error. */
v++;
return (v);
}
-static __inline void
+static inline void
ncr53c9x_setsync(struct ncr53c9x_softc *sc, struct ncr53c9x_tinfo *ti)
{
u_char syncoff, synctp;
@@ -705,20 +720,17 @@ ncr53c9x_setsync(struct ncr53c9x_softc *sc, struct ncr53c9x_tinfo *ti)
static void
ncr53c9x_select(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
{
- int target = ecb->ccb->ccb_h.target_id;
- int lun = ecb->ccb->ccb_h.target_lun;
struct ncr53c9x_tinfo *ti;
- int tiflags;
u_char *cmd;
- int clen;
- int selatn3, selatns;
size_t dmasize;
+ int clen, selatn3, selatns;
+ int lun = ecb->ccb->ccb_h.target_lun;
+ int target = ecb->ccb->ccb_h.target_id;
NCR_TRACE(("[ncr53c9x_select(t%d,l%d,cmd:%x,tag:%x,%x)] ",
target, lun, ecb->cmd.cmd.opcode, ecb->tag[0], ecb->tag[1]));
ti = &sc->sc_tinfo[target];
- tiflags = ti->flags;
sc->sc_state = NCR_SELECTING;
/*
* Schedule the timeout now, the first time we will go away
@@ -730,7 +742,7 @@ ncr53c9x_select(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
/*
* The docs say the target register is never reset, and I
- * can't think of a better place to set it
+ * can't think of a better place to set it.
*/
if (sc->sc_rev == NCR_VARIANT_FAS366) {
NCRCMD(sc, NCRCMD_FLUSH);
@@ -756,9 +768,9 @@ ncr53c9x_select(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
NCR_SET_COUNT(sc, dmasize);
if (sc->sc_rev != NCR_VARIANT_FAS366)
- NCRCMD(sc, NCRCMD_NOP|NCRCMD_DMA);
+ NCRCMD(sc, NCRCMD_NOP | NCRCMD_DMA);
- /* And get the targets attention */
+ /* And get the target's attention */
NCRCMD(sc, NCRCMD_SELNATN | NCRCMD_DMA);
NCRDMA_SETUP(sc, &sc->sc_cmdp, &sc->sc_cmdlen, 0,
&dmasize);
@@ -773,15 +785,15 @@ ncr53c9x_select(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
selatn3 = selatns = 0;
if (ecb->tag[0] != 0) {
if (sc->sc_features & NCR_F_SELATN3)
- /* use SELATN3 to send tag messages */
+ /* Use SELATN3 to send tag messages. */
selatn3 = 1;
else
- /* We don't have SELATN3; use SELATNS to send tags */
+ /* We don't have SELATN3; use SELATNS to send tags. */
selatns = 1;
}
if (ti->flags & T_NEGOTIATE) {
- /* We have to use SELATNS to send sync/wide messages */
+ /* We have to use SELATNS to send sync/wide messages. */
selatn3 = 0;
selatns = 1;
}
@@ -789,34 +801,33 @@ ncr53c9x_select(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
cmd = (u_char *)&ecb->cmd.cmd;
if (selatn3) {
- /* We'll use tags with SELATN3 */
+ /* We'll use tags with SELATN3. */
clen = ecb->clen + 3;
cmd -= 3;
cmd[0] = MSG_IDENTIFY(lun, 1); /* msg[0] */
cmd[1] = ecb->tag[0]; /* msg[1] */
cmd[2] = ecb->tag[1]; /* msg[2] */
} else {
- /* We don't have tags, or will send messages with SELATNS */
+ /* We don't have tags, or will send messages with SELATNS. */
clen = ecb->clen + 1;
cmd -= 1;
- cmd[0] = MSG_IDENTIFY(lun, (tiflags & T_RSELECTOFF) == 0);
+ cmd[0] = MSG_IDENTIFY(lun, (ti->flags & T_RSELECTOFF) == 0);
}
if ((sc->sc_features & NCR_F_DMASELECT) && !selatns) {
-
- /* setup DMA transfer for command */
+ /* Setup DMA transfer for command. */
dmasize = clen;
sc->sc_cmdlen = clen;
sc->sc_cmdp = cmd;
- /* Program the SCSI counter */
+ /* Program the SCSI counter. */
NCR_SET_COUNT(sc, dmasize);
- /* load the count in */
+ /* Load the count in. */
/* if (sc->sc_rev != NCR_VARIANT_FAS366) */
- NCRCMD(sc, NCRCMD_NOP|NCRCMD_DMA);
+ NCRCMD(sc, NCRCMD_NOP | NCRCMD_DMA);
- /* And get the targets attention */
+ /* And get the target's attention. */
if (selatn3) {
sc->sc_msgout = SEND_TAG;
sc->sc_flags |= NCR_ATN;
@@ -833,13 +844,13 @@ ncr53c9x_select(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
* happy for it to disconnect etc.
*/
- /* Now get the command into the FIFO */
+ /* Now get the command into the FIFO. */
ncr53c9x_wrfifo(sc, cmd, clen);
- /* And get the targets attention */
+ /* And get the target's attention. */
if (selatns) {
NCR_MSGS(("SELATNS \n"));
- /* Arbitrate, select and stop after IDENTIFY message */
+ /* Arbitrate, select and stop after IDENTIFY message. */
NCRCMD(sc, NCRCMD_SELATNS);
} else if (selatn3) {
sc->sc_msgout = SEND_TAG;
@@ -855,7 +866,6 @@ ncr53c9x_free_ecb(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
ecb->flags = 0;
TAILQ_INSERT_TAIL(&sc->free_list, ecb, free_links);
- return;
}
static struct ncr53c9x_ecb *
@@ -870,7 +880,7 @@ ncr53c9x_get_ecb(struct ncr53c9x_softc *sc)
TAILQ_REMOVE(&sc->free_list, ecb, free_links);
ecb->flags = ECB_ALLOC;
bzero(&ecb->ccb, sizeof(struct ncr53c9x_ecb) -
- offsetof(struct ncr53c9x_ecb, ccb));
+ offsetof(struct ncr53c9x_ecb, ccb));
}
return (ecb);
}
@@ -880,7 +890,7 @@ ncr53c9x_get_ecb(struct ncr53c9x_softc *sc)
*/
/*
- * Start a SCSI-command
+ * Start a SCSI-command.
* This function is called by the higher level SCSI-driver to queue/run
* SCSI-commands.
*/
@@ -888,8 +898,15 @@ ncr53c9x_get_ecb(struct ncr53c9x_softc *sc)
void
ncr53c9x_action(struct cam_sim *sim, union ccb *ccb)
{
- struct ncr53c9x_softc *sc;
+ struct ccb_pathinq *cpi;
+ struct ccb_scsiio *csio;
+ struct ccb_trans_settings *cts;
+ struct ccb_trans_settings_scsi *scsi;
+ struct ccb_trans_settings_spi *spi;
struct ncr53c9x_ecb *ecb;
+ struct ncr53c9x_softc *sc;
+ struct ncr53c9x_tinfo *ti;
+ int target;
NCR_TRACE(("[ncr53c9x_action %d]", ccb->ccb_h.func_code));
@@ -903,17 +920,17 @@ ncr53c9x_action(struct cam_sim *sim, union ccb *ccb)
mtx_unlock(&sc->sc_lock);
xpt_done(ccb);
return;
+
case XPT_CALC_GEOMETRY:
mtx_unlock(&sc->sc_lock);
cam_calc_geometry(&ccb->ccg, sc->sc_extended_geom);
xpt_done(ccb);
return;
- case XPT_PATH_INQ:
- {
- struct ccb_pathinq *cpi = &ccb->cpi;
+ case XPT_PATH_INQ:
+ cpi = &ccb->cpi;
cpi->version_num = 1;
- cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE;
+ cpi->hba_inquiry = PI_SDTR_ABLE | PI_TAG_ABLE;
cpi->hba_inquiry |=
(sc->sc_rev == NCR_VARIANT_FAS366) ? PI_WIDE_16 : 0;
cpi->target_sprt = 0;
@@ -936,15 +953,12 @@ ncr53c9x_action(struct cam_sim *sim, union ccb *ccb)
mtx_unlock(&sc->sc_lock);
xpt_done(ccb);
return;
- }
+
case XPT_GET_TRAN_SETTINGS:
- {
- struct ccb_trans_settings *cts = &ccb->cts;
- struct ncr53c9x_tinfo *ti = &sc->sc_tinfo[ccb->ccb_h.target_id];
- struct ccb_trans_settings_scsi *scsi =
- &cts->proto_specific.scsi;
- struct ccb_trans_settings_spi *spi =
- &cts->xport_specific.spi;
+ cts = &ccb->cts;
+ ti = &sc->sc_tinfo[ccb->ccb_h.target_id];
+ scsi = &cts->proto_specific.scsi;
+ spi = &cts->xport_specific.spi;
cts->protocol = PROTO_SCSI;
cts->protocol_version = SCSI_REV_2;
@@ -979,25 +993,24 @@ ncr53c9x_action(struct cam_sim *sim, union ccb *ccb)
mtx_unlock(&sc->sc_lock);
xpt_done(ccb);
return;
- }
+
case XPT_ABORT:
printf("XPT_ABORT called\n");
ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
mtx_unlock(&sc->sc_lock);
xpt_done(ccb);
return;
+
case XPT_TERM_IO:
printf("XPT_TERM_IO called\n");
ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
mtx_unlock(&sc->sc_lock);
xpt_done(ccb);
return;
+
case XPT_RESET_DEV:
printf("XPT_RESET_DEV called\n");
case XPT_SCSI_IO:
- {
- struct ccb_scsiio *csio;
-
if (ccb->ccb_h.target_id < 0 ||
ccb->ccb_h.target_id >= sc->sc_ntarg) {
ccb->ccb_h.status = CAM_PATH_INVALID;
@@ -1020,7 +1033,7 @@ ncr53c9x_action(struct cam_sim *sim, union ccb *ccb)
return;
}
- /* Initialize ecb */
+ /* Initialize ecb. */
ecb->ccb = ccb;
ecb->timeout = ccb->ccb_h.timeout;
@@ -1032,10 +1045,10 @@ ncr53c9x_action(struct cam_sim *sim, union ccb *ccb)
csio = &ccb->csio;
if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0)
bcopy(csio->cdb_io.cdb_ptr, &ecb->cmd.cmd,
- csio->cdb_len);
+ csio->cdb_len);
else
bcopy(csio->cdb_io.cdb_bytes, &ecb->cmd.cmd,
- csio->cdb_len);
+ csio->cdb_len);
ecb->clen = csio->cdb_len;
ecb->daddr = csio->data_ptr;
ecb->dleft = csio->dxfer_len;
@@ -1046,19 +1059,14 @@ ncr53c9x_action(struct cam_sim *sim, union ccb *ccb)
ecb->flags |= ECB_READY;
if (sc->sc_state == NCR_IDLE)
ncr53c9x_sched(sc);
-
break;
- }
case XPT_SET_TRAN_SETTINGS:
- {
- struct ccb_trans_settings *cts = &ccb->cts;
- int target = ccb->ccb_h.target_id;
- struct ncr53c9x_tinfo *ti = &sc->sc_tinfo[target];
- struct ccb_trans_settings_scsi *scsi =
- &cts->proto_specific.scsi;
- struct ccb_trans_settings_spi *spi =
- &cts->xport_specific.spi;
+ cts = &ccb->cts;
+ target = ccb->ccb_h.target_id;
+ ti = &sc->sc_tinfo[target];
+ scsi = &cts->proto_specific.scsi;
+ spi = &cts->xport_specific.spi;
if ((scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
if ((sc->sc_cfflags & (1<<((target & 7) + 16))) == 0 &&
@@ -1103,11 +1111,10 @@ ncr53c9x_action(struct cam_sim *sim, union ccb *ccb)
ccb->ccb_h.status = CAM_REQ_CMP;
xpt_done(ccb);
return;
- }
default:
device_printf(sc->sc_dev, "Unhandled function code %d\n",
- ccb->ccb_h.func_code);
+ ccb->ccb_h.func_code);
ccb->ccb_h.status = CAM_PROVIDE_FAIL;
mtx_unlock(&sc->sc_lock);
xpt_done(ccb);
@@ -1137,7 +1144,7 @@ ncr53c9x_poll(struct cam_sim *sim)
*/
/*
- * Schedule a scsi operation. This has now been pulled out of the interrupt
+ * Schedule a SCSI operation. This has now been pulled out of the interrupt
* handler so that we may call it from ncr53c9x_scsipi_request and
* ncr53c9x_done. This may save us an unnecessary interrupt just to get
* things going. Should only be called when state == NCR_IDLE and at bio pl.
@@ -1146,12 +1153,12 @@ static void
ncr53c9x_sched(struct ncr53c9x_softc *sc)
{
struct ncr53c9x_ecb *ecb;
- struct ncr53c9x_tinfo *ti;
struct ncr53c9x_linfo *li;
- int lun;
- int tag;
+ struct ncr53c9x_tinfo *ti;
+ int lun, tag;
NCR_TRACE(("[ncr53c9x_sched] "));
+
if (sc->sc_state != NCR_IDLE)
panic("ncr53c9x_sched: not IDLE (state=%d)", sc->sc_state);
@@ -1182,7 +1189,7 @@ ncr53c9x_sched(struct ncr53c9x_softc *sc)
if (li == NULL) {
/* Initialize LUN info and add to list. */
if ((li = malloc(sizeof(*li),
- M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL) {
+ M_DEVBUF, M_NOWAIT | M_ZERO)) == NULL) {
continue;
}
li->lun = lun;
@@ -1193,17 +1200,20 @@ ncr53c9x_sched(struct ncr53c9x_softc *sc)
}
li->last_used = time_second;
if (tag == 0) {
- /* Try to issue this as an un-tagged command */
+ /* Try to issue this as an untagged command. */
if (li->untagged == NULL)
li->untagged = ecb;
}
if (li->untagged != NULL) {
tag = 0;
if ((li->busy != 1) && li->used == 0) {
- /* We need to issue this untagged command now */
+ /*
+ * We need to issue this untagged command
+ * now.
+ */
ecb = li->untagged;
} else {
- /* Not ready yet */
+ /* not ready, yet */
continue;
}
}
@@ -1227,10 +1237,11 @@ ncr53c9x_sched(struct ncr53c9x_softc *sc)
sc->sc_nexus = ecb;
ncr53c9x_select(sc, ecb);
break;
- } else
+ } else {
NCR_TRACE(("%d:%d busy\n",
ecb->ccb->ccb_h.target_id,
ecb->ccb->ccb_h.target_lun));
+ }
}
}
@@ -1238,9 +1249,9 @@ static void
ncr53c9x_sense(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
{
union ccb *ccb = ecb->ccb;
+ struct ncr53c9x_linfo *li;
struct ncr53c9x_tinfo *ti;
struct scsi_request_sense *ss = (void *)&ecb->cmd.cmd;
- struct ncr53c9x_linfo *li;
int lun;
NCR_TRACE(("requesting sense "));
@@ -1248,7 +1259,7 @@ ncr53c9x_sense(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
lun = ccb->ccb_h.target_lun;
ti = &sc->sc_tinfo[ccb->ccb_h.target_id];
- /* Next, setup a request sense command block */
+ /* Next, setup a REQUEST SENSE command block. */
memset(ss, 0, sizeof(*ss));
ss->opcode = REQUEST_SENSE;
ss->byte2 = ccb->ccb_h.target_lun << SCSI_CMD_LUN_SHIFT;
@@ -1263,7 +1274,7 @@ ncr53c9x_sense(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
if (li->busy)
li->busy = 0;
ncr53c9x_dequeue(sc, ecb);
- li->untagged = ecb; /* must be executed first to fix C/A */
+ li->untagged = ecb; /* Must be executed first to fix C/A. */
li->busy = 2;
if (ecb == sc->sc_nexus) {
ncr53c9x_select(sc, ecb);
@@ -1282,15 +1293,15 @@ static void
ncr53c9x_done(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
{
union ccb *ccb = ecb->ccb;
- struct ncr53c9x_tinfo *ti;
struct ncr53c9x_linfo *li;
+ struct ncr53c9x_tinfo *ti;
int lun;
NCR_TRACE(("[ncr53c9x_done(status:%x)] ", ccb->ccb_h.status));
ti = &sc->sc_tinfo[ccb->ccb_h.target_id];
lun = ccb->ccb_h.target_lun;
- li = TINFO_LUN(ti, lun);
+ li = TINFO_LUN(ti, lun);
untimeout(ncr53c9x_timeout, ecb, ccb->ccb_h.timeout_ch);
@@ -1312,7 +1323,7 @@ ncr53c9x_done(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
if ((ecb->flags & ECB_SENSE) != 0)
ccb->ccb_h.status = CAM_AUTOSENSE_FAIL;
else {
- /* First, save the return values */
+ /* First, save the return values. */
ccb->csio.resid = ecb->dleft;
ncr53c9x_sense(sc, ecb);
return;
@@ -1353,7 +1364,7 @@ ncr53c9x_done(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
}
if (ccb->ccb_h.status == CAM_SEL_TIMEOUT) {
- /* Selection timeout -- discard this LUN if empty */
+ /* Selection timeout -- discard this LUN if empty. */
if (li->untagged == NULL && li->used == 0) {
if (lun < NCR_NLUN)
ti->lun[lun] = NULL;
@@ -1370,8 +1381,8 @@ ncr53c9x_done(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
static void
ncr53c9x_dequeue(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
{
- struct ncr53c9x_tinfo *ti;
struct ncr53c9x_linfo *li;
+ struct ncr53c9x_tinfo *ti;
int64_t lun;
ti = &sc->sc_tinfo[ecb->ccb->ccb_h.target_id];
@@ -1380,7 +1391,7 @@ ncr53c9x_dequeue(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
#ifdef DIAGNOSTIC
if (li == NULL || li->lun != lun)
panic("ncr53c9x_dequeue: lun %qx for ecb %p does not exist",
- (long long) lun, ecb);
+ (long long)lun, ecb);
#endif
if (li->untagged == ecb) {
li->busy = 0;
@@ -1392,8 +1403,7 @@ ncr53c9x_dequeue(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
(li->queued[ecb->tag[1]] != ecb))
panic("ncr53c9x_dequeue: slot %d for lun %qx has %p "
"instead of ecb %p\n", ecb->tag[1],
- (long long) lun,
- li->queued[ecb->tag[1]], ecb);
+ (long long)lun, li->queued[ecb->tag[1]], ecb);
#endif
li->queued[ecb->tag[1]] = NULL;
li->used--;
@@ -1411,16 +1421,15 @@ ncr53c9x_dequeue(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
/*
* Schedule an outgoing message by prioritizing it, and asserting
- * attention on the bus. We can only do this when we are the initiator
+ * attention on the bus. We can only do this when we are the initiator
* else there will be an illegal command interrupt.
*/
-#define ncr53c9x_sched_msgout(m) \
- do { \
- NCR_MSGS(("ncr53c9x_sched_msgout %x %d", m, __LINE__)); \
- NCRCMD(sc, NCRCMD_SETATN); \
- sc->sc_flags |= NCR_ATN; \
- sc->sc_msgpriq |= (m); \
- } while (0)
+#define ncr53c9x_sched_msgout(m) do { \
+ NCR_MSGS(("ncr53c9x_sched_msgout %x %d", m, __LINE__)); \
+ NCRCMD(sc, NCRCMD_SETATN); \
+ sc->sc_flags |= NCR_ATN; \
+ sc->sc_msgpriq |= (m); \
+} while (0)
static void
ncr53c9x_flushfifo(struct ncr53c9x_softc *sc)
@@ -1437,20 +1446,22 @@ ncr53c9x_flushfifo(struct ncr53c9x_softc *sc)
static int
ncr53c9x_rdfifo(struct ncr53c9x_softc *sc, int how)
{
+ u_char *ibuf;
int i, n;
- u_char *buf;
- switch(how) {
+ switch (how) {
case NCR_RDFIFO_START:
- buf = sc->sc_imess;
+ ibuf = sc->sc_imess;
sc->sc_imlen = 0;
break;
+
case NCR_RDFIFO_CONTINUE:
- buf = sc->sc_imess + sc->sc_imlen;
+ ibuf = sc->sc_imess + sc->sc_imlen;
break;
+
default:
panic("ncr53c9x_rdfifo: bad flag");
- break;
+ /* NOTREACHED */
}
/*
@@ -1463,12 +1474,12 @@ ncr53c9x_rdfifo(struct ncr53c9x_softc *sc, int how)
n *= 2;
for (i = 0; i < n; i++)
- buf[i] = NCR_READ_REG(sc, NCR_FIFO);
+ ibuf[i] = NCR_READ_REG(sc, NCR_FIFO);
if (sc->sc_espstat2 & NCRFAS_STAT2_ISHUTTLE) {
NCR_WRITE_REG(sc, NCR_FIFO, 0);
- buf[i++] = NCR_READ_REG(sc, NCR_FIFO);
+ ibuf[i++] = NCR_READ_REG(sc, NCR_FIFO);
NCR_READ_REG(sc, NCR_FIFO);
@@ -1476,28 +1487,23 @@ ncr53c9x_rdfifo(struct ncr53c9x_softc *sc, int how)
}
} else {
for (i = 0; i < n; i++)
- buf[i] = NCR_READ_REG(sc, NCR_FIFO);
+ ibuf[i] = NCR_READ_REG(sc, NCR_FIFO);
}
sc->sc_imlen += i;
#if 0
#ifdef NCR53C9X_DEBUG
- {
- int j;
-
- NCR_TRACE(("\n[rdfifo %s (%d):",
- (how == NCR_RDFIFO_START) ? "start" : "cont",
- (int)sc->sc_imlen));
- if (ncr53c9x_debug & NCR_SHOWTRAC) {
- for (j = 0; j < sc->sc_imlen; j++)
- printf(" %02x", sc->sc_imess[j]);
- printf("]\n");
- }
+ NCR_TRACE(("\n[rdfifo %s (%d):",
+ (how == NCR_RDFIFO_START) ? "start" : "cont", (int)sc->sc_imlen));
+ if (ncr53c9x_debug & NCR_SHOWTRAC) {
+ for (i = 0; i < sc->sc_imlen; i++)
+ printf(" %02x", sc->sc_imess[i]);
+ printf("]\n");
}
#endif
#endif
- return sc->sc_imlen;
+ return (sc->sc_imlen);
}
static void
@@ -1524,12 +1530,12 @@ ncr53c9x_wrfifo(struct ncr53c9x_softc *sc, u_char *p, int len)
static int
ncr53c9x_reselect(struct ncr53c9x_softc *sc, int message, int tagtype,
- int tagid)
+ int tagid)
{
- u_char selid, target, lun;
struct ncr53c9x_ecb *ecb = NULL;
- struct ncr53c9x_tinfo *ti;
struct ncr53c9x_linfo *li;
+ struct ncr53c9x_tinfo *ti;
+ u_char lun, selid, target;
if (sc->sc_rev == NCR_VARIANT_FAS366) {
@@ -1553,7 +1559,7 @@ ncr53c9x_reselect(struct ncr53c9x_softc *sc, int message, int tagtype,
lun = message & 0x07;
/*
- * Search wait queue for disconnected cmd
+ * Search wait queue for disconnected command.
* The list should be short, so I haven't bothered with
* any more sophisticated structures than a simple
* singly linked list.
@@ -1564,14 +1570,14 @@ ncr53c9x_reselect(struct ncr53c9x_softc *sc, int message, int tagtype,
/*
* We can get as far as the LUN with the IDENTIFY
* message. Check to see if we're running an
- * un-tagged command. Otherwise ack the IDENTIFY
+ * untagged command. Otherwise ack the IDENTIFY
* and wait for a tag message.
*/
if (li != NULL) {
if (li->untagged != NULL && li->busy)
ecb = li->untagged;
else if (tagtype != MSG_SIMPLE_Q_TAG) {
- /* Wait for tag to come by */
+ /* Wait for tag to come by. */
sc->sc_state = NCR_IDENTIFIED;
return (0);
} else if (tagtype)
@@ -1609,36 +1615,41 @@ abort:
return (1);
}
-/* From NetBSD. These should go into CAM at some point */
-#define MSG_ISEXTENDED(m) ((m) == MSG_EXTENDED)
-#define MSG_IS1BYTE(m) \
+/* From NetBSD; these should go into CAM at some point. */
+#define MSG_ISEXTENDED(m) ((m) == MSG_EXTENDED)
+#define MSG_IS1BYTE(m) \
((!MSG_ISEXTENDED(m) && (m) < 0x20) || MSG_ISIDENTIFY(m))
-#define MSG_IS2BYTE(m) (((m) & 0xf0) == 0x20)
+#define MSG_IS2BYTE(m) (((m) & 0xf0) == 0x20)
static inline int
__verify_msg_format(u_char *p, int len)
{
if (len == 1 && MSG_IS1BYTE(p[0]))
- return 1;
+ return (1);
if (len == 2 && MSG_IS2BYTE(p[0]))
- return 1;
+ return (1);
if (len >= 3 && MSG_ISEXTENDED(p[0]) &&
len == p[1] + 2)
- return 1;
+ return (1);
- return 0;
+ return (0);
}
/*
* Get an incoming message as initiator.
*
* The SCSI bus must already be in MESSAGE_IN_PHASE and there is a
- * byte in the FIFO
+ * byte in the FIFO.
*/
static void
ncr53c9x_msgin(struct ncr53c9x_softc *sc)
{
+ struct ncr53c9x_ecb *ecb;
+ struct ncr53c9x_linfo *li;
+ struct ncr53c9x_tinfo *ti;
+ u_char *pb;
+ int lun, plen;
NCR_TRACE(("[ncr53c9x_msgin(curmsglen:%ld)] ", (long)sc->sc_imlen));
@@ -1650,7 +1661,7 @@ ncr53c9x_msgin(struct ncr53c9x_softc *sc)
/*
* Prepare for a new message. A message should (according
* to the SCSI standard) be transmitted in one single
- * MESSAGE_IN_PHASE. If we have been in some other phase,
+ * MESSAGE_IN_PHASE. If we have been in some other phase,
* then this is a new message.
*/
if (sc->sc_prevphase != MESSAGE_IN_PHASE &&
@@ -1675,9 +1686,6 @@ ncr53c9x_msgin(struct ncr53c9x_softc *sc)
ncr53c9x_sched_msgout(SEND_REJECT);
sc->sc_flags |= NCR_DROP_MSGI;
} else {
- u_char *pb;
- int plen;
-
switch (sc->sc_state) {
/*
* if received message is the first of reselection
@@ -1687,24 +1695,26 @@ ncr53c9x_msgin(struct ncr53c9x_softc *sc)
pb = sc->sc_imess + 1;
plen = sc->sc_imlen - 1;
break;
+
default:
pb = sc->sc_imess;
plen = sc->sc_imlen;
- break;
}
if (__verify_msg_format(pb, plen))
goto gotit;
}
- /* Ack what we have so far */
+ /* Acknowledge what we have so far. */
NCRCMD(sc, NCRCMD_MSGOK);
return;
gotit:
NCR_MSGS(("gotmsg(%x) state %d", sc->sc_imess[0], sc->sc_state));
- /* We got a complete message, flush the imess, */
- /* XXX nobody uses imlen below */
+ /*
+ * We got a complete message, flush the imess.
+ * XXX nobody uses imlen below.
+ */
sc->sc_imlen = 0;
/*
* Now we should have a complete message (1 byte, 2 byte
@@ -1713,11 +1723,6 @@ gotit:
* NCR_MAX_MSG_LEN. Longer messages will be amputated.
*/
switch (sc->sc_state) {
- struct ncr53c9x_ecb *ecb;
- struct ncr53c9x_tinfo *ti;
- struct ncr53c9x_linfo *li;
- int lun;
-
case NCR_CONNECTED:
ecb = sc->sc_nexus;
ti = &sc->sc_tinfo[ecb->ccb->ccb_h.target_id];
@@ -1808,14 +1813,13 @@ gotit:
sc->sc_state = NCR_DISCONNECT;
/*
- * Mark the fact that all bytes have moved. The
+ * Mark the fact that all bytes have moved. The
* target may not bother to do a SAVE POINTERS
- * at this stage. This flag will set the residual
+ * at this stage. This flag will set the residual
* count to zero on MSG COMPLETE.
*/
if (sc->sc_dleft == 0)
ecb->flags |= ECB_TENTATIVE_DONE;
-
break;
case MSG_SAVEDATAPOINTER:
@@ -1851,7 +1855,8 @@ gotit:
#endif
#endif
ti->flags &= ~T_SYNCMODE;
- if ((sc->sc_flags&NCR_SYNCHNEGO) == 0) {
+ if ((sc->sc_flags & NCR_SYNCHNEGO) ==
+ 0) {
/*
* target initiated negotiation
*/
@@ -1860,11 +1865,12 @@ gotit:
SEND_SDTR);
}
} else {
- int p;
-
- p = ncr53c9x_stp2cpb(sc, ti->period);
- ti->period = ncr53c9x_cpb2stp(sc, p);
- if ((sc->sc_flags&NCR_SYNCHNEGO) == 0) {
+ ti->period =
+ ncr53c9x_cpb2stp(sc,
+ ncr53c9x_stp2cpb(sc,
+ ti->period));
+ if ((sc->sc_flags & NCR_SYNCHNEGO) ==
+ 0) {
/*
* target initiated negotiation
*/
@@ -1877,7 +1883,7 @@ gotit:
ncr53c9x_sched_msgout(
SEND_SDTR);
} else {
- /* we are sync */
+ /* We are sync. */
ti->flags |= T_SYNCMODE;
}
}
@@ -1902,6 +1908,7 @@ gotit:
ncr53c9x_sched_msgout(SEND_WDTR);
ti->flags &= ~(T_WIDE | T_WDTRSENT);
break;
+
default:
xpt_print_path(ecb->ccb->ccb_h.path);
printf("unrecognized MESSAGE EXTENDED;"
@@ -1914,6 +1921,7 @@ gotit:
NCR_MSGS(("ident "));
xpt_print_path(ecb->ccb->ccb_h.path);
printf("unrecognized MESSAGE; sending REJECT\n");
+ /* FALLTHROUGH */
reject:
ncr53c9x_sched_msgout(SEND_REJECT);
break;
@@ -1922,13 +1930,14 @@ gotit:
case NCR_IDENTIFIED:
/*
- * IDENTIFY message was received and queue tag is expected now
+ * IDENTIFY message was received and queue tag is expected
+ * now.
*/
if ((sc->sc_imess[0] != MSG_SIMPLE_Q_TAG) ||
(sc->sc_msgify == 0)) {
device_printf(sc->sc_dev, "TAG reselect without "
"IDENTIFY; MSG %x; sending DEVICE RESET\n",
- sc->sc_imess[0]);
+ sc->sc_imess[0]);
goto reset;
}
(void) ncr53c9x_reselect(sc, sc->sc_msgify,
@@ -1949,20 +1958,20 @@ gotit:
default:
device_printf(sc->sc_dev, "unexpected MESSAGE IN; "
"sending DEVICE RESET\n");
+ /* FALLTHROUGH */
reset:
ncr53c9x_sched_msgout(SEND_DEV_RESET);
break;
abort:
ncr53c9x_sched_msgout(SEND_ABORT);
- break;
}
- /* if we have more messages to send set ATN */
+ /* If we have more messages to send set ATN. */
if (sc->sc_msgpriq)
NCRCMD(sc, NCRCMD_SETATN);
- /* Ack last message byte */
+ /* Acknowledge last message byte. */
NCRCMD(sc, NCRCMD_MSGOK);
/* Done, reset message pointer. */
@@ -1970,9 +1979,8 @@ gotit:
sc->sc_imlen = 0;
}
-
/*
- * Send the highest priority, scheduled message
+ * Send the highest priority, scheduled message.
*/
static void
ncr53c9x_msgout(struct ncr53c9x_softc *sc)
@@ -1980,13 +1988,16 @@ ncr53c9x_msgout(struct ncr53c9x_softc *sc)
struct ncr53c9x_tinfo *ti;
struct ncr53c9x_ecb *ecb;
size_t size;
+#ifdef NCR53C9X_DEBUG
+ int i;
+#endif
NCR_TRACE(("[ncr53c9x_msgout(priq:%x, prevphase:%x)]",
sc->sc_msgpriq, sc->sc_prevphase));
/*
* XXX - the NCR_ATN flag is not in sync with the actual ATN
- * condition on the SCSI bus. The 53c9x chip
+ * condition on the SCSI bus. The 53c9x chip
* automatically turns off ATN before sending the
* message byte. (See also the comment below in the
* default case when picking out a message to send.)
@@ -2010,7 +2021,7 @@ ncr53c9x_msgout(struct ncr53c9x_softc *sc)
}
if (sc->sc_omlen == 0) {
- /* Pick up highest priority message */
+ /* Pick up highest priority message. */
sc->sc_msgout = sc->sc_msgpriq & -sc->sc_msgpriq;
sc->sc_msgoutq |= sc->sc_msgout;
sc->sc_msgpriq &= ~sc->sc_msgout;
@@ -2030,6 +2041,7 @@ ncr53c9x_msgout(struct ncr53c9x_softc *sc)
ncr53c9x_setsync(sc, ti);
}
break;
+
case SEND_WDTR:
ecb = sc->sc_nexus;
ti = &sc->sc_tinfo[ecb->ccb->ccb_h.target_id];
@@ -2039,15 +2051,17 @@ ncr53c9x_msgout(struct ncr53c9x_softc *sc)
sc->sc_omess[3] = ti->width;
sc->sc_omlen = 4;
break;
- case SEND_IDENTIFY:
- if (sc->sc_state != NCR_CONNECTED) {
- device_printf(sc->sc_dev, "at line %d: no "
+
+ case SEND_IDENTIFY:
+ if (sc->sc_state != NCR_CONNECTED) {
+ device_printf(sc->sc_dev, "at line %d: no "
"nexus\n", __LINE__);
- }
- ecb = sc->sc_nexus;
- sc->sc_omess[0] =
- MSG_IDENTIFY(ecb->ccb->ccb_h.target_lun, 0);
- break;
+ }
+ ecb = sc->sc_nexus;
+ sc->sc_omess[0] =
+ MSG_IDENTIFY(ecb->ccb->ccb_h.target_lun, 0);
+ break;
+
case SEND_TAG:
if (sc->sc_state != NCR_CONNECTED) {
device_printf(sc->sc_dev, "at line %d: no "
@@ -2058,6 +2072,7 @@ ncr53c9x_msgout(struct ncr53c9x_softc *sc)
sc->sc_omess[1] = ecb->tag[1];
sc->sc_omlen = 2;
break;
+
case SEND_DEV_RESET:
sc->sc_flags |= NCR_ABORTING;
sc->sc_omess[0] = MSG_BUS_DEV_RESET;
@@ -2065,22 +2080,27 @@ ncr53c9x_msgout(struct ncr53c9x_softc *sc)
ti = &sc->sc_tinfo[ecb->ccb->ccb_h.target_id];
ti->flags &= ~T_SYNCMODE;
if ((ti->flags & T_SYNCHOFF) == 0)
- /* We can re-start sync negotiation */
+ /* We can re-start sync negotiation. */
ti->flags |= T_NEGOTIATE;
break;
+
case SEND_PARITY_ERROR:
sc->sc_omess[0] = MSG_PARITY_ERROR;
break;
+
case SEND_ABORT:
sc->sc_flags |= NCR_ABORTING;
sc->sc_omess[0] = MSG_ABORT;
break;
+
case SEND_INIT_DET_ERR:
sc->sc_omess[0] = MSG_INITIATOR_DET_ERR;
break;
+
case SEND_REJECT:
sc->sc_omess[0] = MSG_MESSAGE_REJECT;
break;
+
default:
/*
* We normally do not get here, since the chip
@@ -2089,7 +2109,7 @@ ncr53c9x_msgout(struct ncr53c9x_softc *sc)
* However, if the target rejects our (multi-byte)
* message early by switching to MSG IN phase
* ATN remains on, so the target may return to
- * MSG OUT phase. If there are no scheduled messages
+ * MSG OUT phase. If there are no scheduled messages
* left we send a NO-OP.
*
* XXX - Note that this leaves no useful purpose for
@@ -2097,15 +2117,12 @@ ncr53c9x_msgout(struct ncr53c9x_softc *sc)
*/
sc->sc_flags &= ~NCR_ATN;
sc->sc_omess[0] = MSG_NOOP;
- break;
}
sc->sc_omp = sc->sc_omess;
}
-#ifdef DEBUG
+#ifdef NCR53C9X_DEBUG
if (ncr53c9x_debug & NCR_SHOWMSGS) {
- int i;
-
NCR_MSGS(("<msgout:"));
for (i = 0; i < sc->sc_omlen; i++)
NCR_MSGS((" %02x", sc->sc_omess[i]));
@@ -2114,21 +2131,21 @@ ncr53c9x_msgout(struct ncr53c9x_softc *sc)
#endif
if (sc->sc_rev == NCR_VARIANT_FAS366) {
/*
- * XXX fifo size
+ * XXX FIFO size
*/
ncr53c9x_flushfifo(sc);
ncr53c9x_wrfifo(sc, sc->sc_omp, sc->sc_omlen);
NCRCMD(sc, NCRCMD_TRANS);
} else {
- /* (re)send the message */
+ /* (Re)send the message. */
size = min(sc->sc_omlen, sc->sc_maxxfer);
NCRDMA_SETUP(sc, &sc->sc_omp, &sc->sc_omlen, 0, &size);
- /* Program the SCSI counter */
+ /* Program the SCSI counter. */
NCR_SET_COUNT(sc, size);
- /* Load the count in and start the message-out transfer */
- NCRCMD(sc, NCRCMD_NOP|NCRCMD_DMA);
- NCRCMD(sc, NCRCMD_TRANS|NCRCMD_DMA);
+ /* Load the count in and start the message-out transfer. */
+ NCRCMD(sc, NCRCMD_NOP | NCRCMD_DMA);
+ NCRCMD(sc, NCRCMD_TRANS | NCRCMD_DMA);
NCRDMA_GO(sc);
}
}
@@ -2136,8 +2153,8 @@ ncr53c9x_msgout(struct ncr53c9x_softc *sc)
/*
* This is the most critical part of the driver, and has to know
* how to deal with *all* error conditions and phases from the SCSI
- * bus. If there are no errors and the DMA was active, then call the
- * DMA pseudo-interrupt handler. If this returns 1, then that was it
+ * bus. If there are no errors and the DMA was active, then call the
+ * DMA pseudo-interrupt handler. If this returns 1, then that was it
* and we can return from here without further processing.
*
* Most of this needs verifying.
@@ -2147,9 +2164,12 @@ ncr53c9x_intr(void *arg)
{
struct ncr53c9x_softc *sc = arg;
struct ncr53c9x_ecb *ecb;
+ struct ncr53c9x_linfo *li;
struct ncr53c9x_tinfo *ti;
+ struct timeval cur, wait;
size_t size;
- int nfifo;
+ int i, nfifo;
+ u_char msg;
NCR_INTS(("[ncr53c9x_intr: state %d]", sc->sc_state));
@@ -2163,22 +2183,21 @@ again:
/*
* At the moment, only a SCSI Bus Reset or Illegal
- * Command are classed as errors. A disconnect is a
+ * Command are classed as errors. A disconnect is a
* valid condition, and we let the code check is the
* "NCR_BUSFREE_OK" flag was set before declaring it
* and error.
*
* Also, the status register tells us about "Gross
- * Errors" and "Parity errors". Only the Gross Error
+ * Errors" and "Parity errors". Only the Gross Error
* is really bad, and the parity errors are dealt
- * with later
+ * with later.
*
* TODO
* If there are too many parity error, go to slow
- * cable mode ?
+ * cable mode?
*/
- /* SCSI Reset */
if ((sc->sc_espintr & NCRINTR_SBR) != 0) {
if ((NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF) != 0) {
NCRCMD(sc, NCRCMD_FLUSH);
@@ -2186,7 +2205,7 @@ again:
}
if (sc->sc_state != NCR_SBR) {
device_printf(sc->sc_dev, "SCSI bus reset\n");
- ncr53c9x_init(sc, 0); /* Restart everything */
+ ncr53c9x_init(sc, 0); /* Restart everything. */
goto out;
}
#if 0
@@ -2202,12 +2221,11 @@ again:
ecb = sc->sc_nexus;
-#define NCRINTR_ERR (NCRINTR_SBR|NCRINTR_ILL)
+#define NCRINTR_ERR (NCRINTR_SBR | NCRINTR_ILL)
if (sc->sc_espintr & NCRINTR_ERR ||
sc->sc_espstat & NCRSTAT_GE) {
-
if ((sc->sc_espstat & NCRSTAT_GE) != 0) {
- /* Gross Error; no target ? */
+ /* Gross Error; no target? */
if (NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF) {
NCRCMD(sc, NCRCMD_FLUSH);
DELAY(1);
@@ -2235,7 +2253,7 @@ again:
sc->sc_flags &= ~NCR_EXPECT_ILLCMD;
goto out;
}
- /* illegal command, out of sync ? */
+ /* Illegal command, out of sync? */
device_printf(sc->sc_dev, "illegal command: 0x%x "
"(state %d, phase %x, prevphase %x)\n",
sc->sc_lastcmd,
@@ -2244,7 +2262,7 @@ again:
NCRCMD(sc, NCRCMD_FLUSH);
DELAY(1);
}
- ncr53c9x_init(sc, 1); /* Restart everything */
+ ncr53c9x_init(sc, 1); /* Restart everything. */
goto out;
}
}
@@ -2258,8 +2276,7 @@ again:
* change is expected.
*/
if (NCRDMA_ISACTIVE(sc)) {
- int r = NCRDMA_INTR(sc);
- if (r == -1) {
+ if (NCRDMA_INTR(sc) == -1) {
device_printf(sc->sc_dev, "DMA error; resetting\n");
ncr53c9x_init(sc, 1);
goto out;
@@ -2299,7 +2316,7 @@ again:
} else if (sc->sc_dleft == 0) {
/*
* The DMA operation was started for
- * a DATA transfer. Print a diagnostic
+ * a DATA transfer. Print a diagnostic
* if the DMA counter and TC bit
* appear to be out of sync.
*
@@ -2342,7 +2359,7 @@ again:
}
/*
* This command must (apparently) be issued within
- * 250mS of a disconnect. So here you are...
+ * 250mS of a disconnect. So here you are...
*/
NCRCMD(sc, NCRCMD_ENSEL);
@@ -2351,12 +2368,9 @@ again:
goto sched;
case NCR_SELECTING:
- {
- struct ncr53c9x_linfo *li;
-
ecb->ccb->ccb_h.status = CAM_SEL_TIMEOUT;
- /* Selection timeout -- discard all LUNs if empty */
+ /* Selection timeout -- discard all LUNs if empty. */
ti = &sc->sc_tinfo[ecb->ccb->ccb_h.target_id];
li = LIST_FIRST(&ti->luns);
while (li != NULL) {
@@ -2366,7 +2380,7 @@ again:
LIST_REMOVE(li, link);
free(li, M_DEVBUF);
/*
- * Restart the search at the beginning
+ * Restart the search at the beginning.
*/
li = LIST_FIRST(&ti->luns);
continue;
@@ -2374,7 +2388,7 @@ again:
li = LIST_NEXT(li, link);
}
goto finish;
- }
+
case NCR_CONNECTED:
if ((sc->sc_flags & NCR_SYNCHNEGO) != 0) {
#ifdef NCR53C9X_DEBUG
@@ -2387,7 +2401,7 @@ again:
ti->flags &= ~(T_NEGOTIATE | T_SYNCMODE);
}
- /* it may be OK to disconnect */
+ /* It may be OK to disconnect. */
if ((sc->sc_flags & NCR_ABORTING) == 0) {
/*
* Section 5.1.1 of the SCSI 2 spec
@@ -2437,17 +2451,16 @@ again:
}
switch (sc->sc_state) {
-
case NCR_SBR:
device_printf(sc->sc_dev, "waiting for Bus Reset to happen\n");
goto out;
case NCR_RESELECTED:
/*
- * we must be continuing a message ?
+ * We must be continuing a message?
*/
device_printf(sc->sc_dev, "unhandled reselect continuation, "
- "state %d, intr %02x\n", sc->sc_state, sc->sc_espintr);
+ "state %d, intr %02x\n", sc->sc_state, sc->sc_espintr);
ncr53c9x_init(sc, 1);
goto out;
break;
@@ -2455,14 +2468,14 @@ again:
case NCR_IDENTIFIED:
ecb = sc->sc_nexus;
if (sc->sc_phase != MESSAGE_IN_PHASE) {
- int i = (NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF);
- /*
+ i = NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF;
+ /*
* Things are seriously screwed up.
- * Pull the brakes, i.e. reset
+ * Pull the brakes, i.e. reset.
*/
device_printf(sc->sc_dev, "target didn't send tag: %d "
- "bytes in fifo\n", i);
- /* Drain and display fifo */
+ "bytes in FIFO\n", i);
+ /* Drain and display FIFO. */
while (i-- > 0)
printf("[%d] ", NCR_READ_REG(sc, NCR_FIFO));
@@ -2512,23 +2525,24 @@ again:
*
* To remedy this situation, pull the Selection ID
* and Identify message from the FIFO directly, and
- * ignore any extraneous fifo contents. Also, set
+ * ignore any extraneous FIFO contents. Also, set
* a flag that allows one Illegal Command Interrupt
* to occur which the chip also generates as a result
* of writing to the FIFO during a reselect.
*/
if (sc->sc_rev == NCR_VARIANT_ESP100) {
- nfifo = NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF;
+ nfifo =
+ NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF;
sc->sc_imess[0] = NCR_READ_REG(sc, NCR_FIFO);
sc->sc_imess[1] = NCR_READ_REG(sc, NCR_FIFO);
sc->sc_imlen = 2;
if (nfifo != 2) {
- /* Flush the rest */
+ /* Flush the rest. */
NCRCMD(sc, NCRCMD_FLUSH);
}
sc->sc_flags |= NCR_EXPECT_ILLCMD;
if (nfifo > 2)
- nfifo = 2; /* We fixed it.. */
+ nfifo = 2; /* We fixed it... */
} else
nfifo = ncr53c9x_rdfifo(sc, NCR_RDFIFO_START);
@@ -2547,7 +2561,7 @@ again:
sc->sc_selid = sc->sc_imess[0];
NCR_INTS(("selid=%02x ", sc->sc_selid));
- /* Handle identify message */
+ /* Handle IDENTIFY message. */
ncr53c9x_msgin(sc);
if (sc->sc_state != NCR_CONNECTED &&
@@ -2559,10 +2573,10 @@ again:
ncr53c9x_init(sc, 1);
goto out;
}
- goto shortcut; /* ie. next phase expected soon */
+ goto shortcut; /* i.e. next phase expected soon */
}
-#define NCRINTR_DONE (NCRINTR_FC|NCRINTR_BS)
+#define NCRINTR_DONE (NCRINTR_FC | NCRINTR_BS)
if ((sc->sc_espintr & NCRINTR_DONE) == NCRINTR_DONE) {
/*
* Arbitration won; examine the `step' register
@@ -2591,10 +2605,11 @@ again:
* Clear ATN and just continue, the
* target should be in the command
* phase.
- * XXXX check for command phase?
+ * XXX check for command phase?
*/
NCRCMD(sc, NCRCMD_RSTATN);
break;
+
case 1:
if ((ti->flags & T_NEGOTIATE) == 0 &&
ecb->tag[0] == 0) {
@@ -2620,15 +2635,16 @@ again:
ncr53c9x_sched_msgout(
SEND_SDTR);
} else {
- /* Could not do ATN3 so send TAG */
+ /* Could not do ATN3 so send TAG. */
ncr53c9x_sched_msgout(SEND_TAG);
}
sc->sc_prevphase = MESSAGE_OUT_PHASE; /* XXXX */
break;
+
case 3:
/*
* Grr, this is supposed to mean
- * "target left command phase prematurely".
+ * "target left command phase prematurely".
* It seems to happen regularly when
* sync mode is on.
* Look at FIFO to see if command went out.
@@ -2636,11 +2652,11 @@ again:
*/
if (sc->sc_features & NCR_F_DMASELECT) {
if (sc->sc_cmdlen == 0)
- /* Hope for the best.. */
+ /* Hope for the best... */
break;
} else if ((NCR_READ_REG(sc, NCR_FFLAG)
& NCRFIFO_FF) == 0) {
- /* Hope for the best.. */
+ /* Hope for the best... */
break;
}
printf("(%s:%d:%d): selection failed;"
@@ -2649,17 +2665,18 @@ again:
device_get_nameunit(sc->sc_dev),
ecb->ccb->ccb_h.target_id,
ecb->ccb->ccb_h.target_lun,
- NCR_READ_REG(sc, NCR_FFLAG)
- & NCRFIFO_FF,
+ NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF,
sc->sc_espintr, sc->sc_espstat,
sc->sc_espstep);
NCRCMD(sc, NCRCMD_FLUSH);
ncr53c9x_sched_msgout(SEND_ABORT);
goto out;
+
case 2:
- /* Select stuck at Command Phase */
+ /* Select stuck at Command Phase. */
NCRCMD(sc, NCRCMD_FLUSH);
break;
+
case 4:
if (sc->sc_features & NCR_F_DMASELECT &&
sc->sc_cmdlen != 0)
@@ -2673,19 +2690,17 @@ again:
sc->sc_espintr,
sc->sc_espstat,
sc->sc_espstep);
- /* So far, everything went fine */
+ /* So far, everything went fine. */
break;
}
- sc->sc_prevphase = INVALID_PHASE; /* ?? */
+ sc->sc_prevphase = INVALID_PHASE; /* ??? */
/* Do an implicit RESTORE POINTERS. */
sc->sc_dp = ecb->daddr;
sc->sc_dleft = ecb->dleft;
sc->sc_state = NCR_CONNECTED;
break;
-
} else {
-
device_printf(sc->sc_dev, "unexpected status after "
"select: [intr %x, stat %x, step %x]\n",
sc->sc_espintr, sc->sc_espstat, sc->sc_espstep);
@@ -2702,8 +2717,6 @@ again:
case NCR_CONNECTED:
if ((sc->sc_flags & NCR_ICCS) != 0) {
/* "Initiate Command Complete Steps" in progress */
- u_char msg;
-
sc->sc_flags &= ~NCR_ICCS;
if (!(sc->sc_espintr & NCRINTR_DONE)) {
@@ -2720,8 +2733,9 @@ again:
msg = sc->sc_imess[sc->sc_imlen - 1];
NCR_PHASE(("<stat:(%x,%x)>", ecb->stat, msg));
if (msg == MSG_CMDCOMPLETE) {
- ecb->dleft = (ecb->flags & ECB_TENTATIVE_DONE)
- ? 0 : sc->sc_dleft;
+ ecb->dleft =
+ (ecb->flags & ECB_TENTATIVE_DONE) ?
+ 0 : sc->sc_dleft;
if ((ecb->flags & ECB_SENSE) == 0)
ecb->ccb->csio.resid = ecb->dleft;
sc->sc_state = NCR_CMDCOMPLETE;
@@ -2730,7 +2744,7 @@ again:
"msg %d\n", msg);
sc->sc_imlen = 0;
NCRCMD(sc, NCRCMD_MSGOK);
- goto shortcut; /* ie. wait for disconnect */
+ goto shortcut; /* i.e. wait for disconnect */
}
break;
@@ -2788,9 +2802,9 @@ msgin:
case COMMAND_PHASE:
/*
- * Send the command block. Normally we don't see this
+ * Send the command block. Normally we don't see this
* phase because the SEL_ATN command takes care of
- * all this. However, we end up here if either the
+ * all this. However, we end up here if either the
* target or we wanted to exchange some more messages
* first (e.g. to start negotiations).
*/
@@ -2802,19 +2816,19 @@ msgin:
/* DELAY(1);*/
}
if (sc->sc_features & NCR_F_DMASELECT) {
- /* setup DMA transfer for command */
+ /* Setup DMA transfer for command. */
size = ecb->clen;
sc->sc_cmdlen = size;
sc->sc_cmdp = (caddr_t)&ecb->cmd.cmd;
NCRDMA_SETUP(sc, &sc->sc_cmdp, &sc->sc_cmdlen,
0, &size);
- /* Program the SCSI counter */
+ /* Program the SCSI counter. */
NCR_SET_COUNT(sc, size);
- /* load the count in */
- NCRCMD(sc, NCRCMD_NOP|NCRCMD_DMA);
+ /* Load the count in. */
+ NCRCMD(sc, NCRCMD_NOP | NCRCMD_DMA);
- /* start the command transfer */
+ /* Start the command transfer. */
NCRCMD(sc, NCRCMD_TRANS | NCRCMD_DMA);
NCRDMA_GO(sc);
} else {
@@ -2825,7 +2839,7 @@ msgin:
break;
case DATA_OUT_PHASE:
- NCR_PHASE(("DATA_OUT_PHASE [%ld] ",(long)sc->sc_dleft));
+ NCR_PHASE(("DATA_OUT_PHASE [%ld] ", (long)sc->sc_dleft));
NCRCMD(sc, NCRCMD_FLUSH);
size = min(sc->sc_dleft, sc->sc_maxxfer);
NCRDMA_SETUP(sc, &sc->sc_dp, &sc->sc_dleft, 0, &size);
@@ -2843,16 +2857,16 @@ msgin:
/* Target returned to data phase: wipe "done" memory */
ecb->flags &= ~ECB_TENTATIVE_DONE;
- /* Program the SCSI counter */
+ /* Program the SCSI counter. */
NCR_SET_COUNT(sc, size);
- /* load the count in */
- NCRCMD(sc, NCRCMD_NOP|NCRCMD_DMA);
+ /* Load the count in. */
+ NCRCMD(sc, NCRCMD_NOP | NCRCMD_DMA);
/*
* Note that if `size' is 0, we've already transceived
* all the bytes we want but we're still in DATA PHASE.
- * Apparently, the device needs padding. Also, a
+ * Apparently, the device needs padding. Also, a
* transfer size of 0 means "maximum" to the chip
* DMA logic.
*/
@@ -2872,7 +2886,8 @@ msgin:
break;
default:
- device_printf(sc->sc_dev, "unexpected bus phase; resetting\n");
+ device_printf(sc->sc_dev,
+ "unexpected bus phase; resetting\n");
goto reset;
}
@@ -2897,35 +2912,28 @@ shortcut:
/*
* The idea is that many of the SCSI operations take very little
* time, and going away and getting interrupted is too high an
- * overhead to pay. For example, selecting, sending a message
+ * overhead to pay. For example, selecting, sending a message
* and command and then doing some work can be done in one "pass".
*
- * The delay is a heuristic. It is 2 when at 20MHz, 2 at 25MHz and 1
+ * The delay is a heuristic. It is 2 when at 20MHz, 2 at 25MHz and 1
* at 40MHz. This needs testing.
*/
- {
- struct timeval wait, cur;
-
- microtime(&wait);
- wait.tv_usec += 50 / sc->sc_freq;
- if (wait.tv_usec > 1000000) {
- wait.tv_sec++;
- wait.tv_usec -= 1000000;
- }
- do {
- if (NCRDMA_ISINTR(sc))
- goto again;
- microtime(&cur);
- } while (cur.tv_sec <= wait.tv_sec &&
- cur.tv_usec <= wait.tv_usec);
- }
+ microtime(&wait);
+ wait.tv_usec += 50 / sc->sc_freq;
+ if (wait.tv_usec > 1000000) {
+ wait.tv_sec++;
+ wait.tv_usec -= 1000000;
+ }
+ do {
+ if (NCRDMA_ISINTR(sc))
+ goto again;
+ microtime(&cur);
+ } while (cur.tv_sec <= wait.tv_sec && cur.tv_usec <= wait.tv_usec);
goto out;
}
static void
-ncr53c9x_abort(sc, ecb)
- struct ncr53c9x_softc *sc;
- struct ncr53c9x_ecb *ecb;
+ncr53c9x_abort(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb)
{
/* 2 secs for the abort */
@@ -2981,17 +2989,16 @@ ncr53c9x_timeout(void *arg)
mtx_lock(&sc->sc_lock);
if (ecb->flags & ECB_ABORT) {
- /* abort timed out */
+ /* Abort timed out. */
printf(" AGAIN\n");
-
ncr53c9x_init(sc, 1);
} else {
- /* abort the operation that has timed out */
+ /* Abort the operation that has timed out. */
printf("\n");
ccb->ccb_h.status = CAM_CMD_TIMEOUT;
ncr53c9x_abort(sc, ecb);
- /* Disable sync mode if stuck in a data phase */
+ /* Disable sync mode if stuck in a data phase. */
if (ecb == sc->sc_nexus &&
(ti->flags & T_SYNCMODE) != 0 &&
(sc->sc_phase & (MSGI|CDI)) == 0) {
@@ -3010,11 +3017,13 @@ static void
ncr53c9x_watch(void *arg)
{
struct ncr53c9x_softc *sc = (struct ncr53c9x_softc *)arg;
- struct ncr53c9x_tinfo *ti;
struct ncr53c9x_linfo *li;
+ struct ncr53c9x_tinfo *ti;
+ time_t old;
int t;
+
/* Delete any structures that have not been used in 10min. */
- time_t old = time_second - (10 * 60);
+ old = time_second - (10 * 60);
mtx_lock(&sc->sc_lock);
for (t = 0; t < sc->sc_ntarg; t++) {
@@ -3028,7 +3037,7 @@ ncr53c9x_watch(void *arg)
ti->lun[li->lun] = NULL;
LIST_REMOVE(li, link);
free(li, M_DEVBUF);
- /* Restart the search at the beginning */
+ /* Restart the search at the beginning. */
li = LIST_FIRST(&ti->luns);
continue;
}
diff --git a/sys/dev/esp/ncr53c9xvar.h b/sys/dev/esp/ncr53c9xvar.h
index c9ac4bb..1c81d92 100644
--- a/sys/dev/esp/ncr53c9xvar.h
+++ b/sys/dev/esp/ncr53c9xvar.h
@@ -69,20 +69,20 @@
/* $FreeBSD$ */
#ifndef _DEV_IC_NCR53C9XVAR_H_
-#define _DEV_IC_NCR53C9XVAR_H_
+#define _DEV_IC_NCR53C9XVAR_H_
#include <sys/lock.h>
/* Set this to 1 for normal debug, or 2 for per-target tracing. */
-/* #define NCR53C9X_DEBUG 2 */
+/* #define NCR53C9X_DEBUG 2 */
/* Wide or differential can have 16 targets */
-#define NCR_NLUN 8
+#define NCR_NLUN 8
#define NCR_ABORT_TIMEOUT 2000 /* time to wait for abort */
#define NCR_SENSE_TIMEOUT 1000 /* time to wait for sense */
-#define FREQTOCCF(freq) (((freq + 4) / 5))
+#define FREQTOCCF(freq) (((freq + 4) / 5))
/*
* NCR 53c9x variants. Note these values are used as indexes into
@@ -104,7 +104,7 @@
#define NCR_VARIANT_MAX 13
/* XXX Max tag depth. Should this be defined in the register header? */
-#define NCR_TAG_DEPTH 256
+#define NCR_TAG_DEPTH 256
/*
* ECB. Holds additional information for each SCSI command Comments: We
@@ -138,7 +138,7 @@ struct ncr53c9x_ecb {
char *daddr; /* Saved data pointer */
int clen; /* Size of command in cmd.cmd */
int dleft; /* Residue */
- u_char stat; /* SCSI status byte */
+ u_char stat; /* SCSI status byte */
u_char tag[2]; /* TAG bytes */
u_char pad[1];
@@ -147,14 +147,14 @@ struct ncr53c9x_ecb {
#endif
};
#if defined(NCR53C9X_DEBUG) && NCR53C9X_DEBUG > 1
-#define ECB_TRACE(ecb, msg, a, b) do { \
+#define ECB_TRACE(ecb, msg, a, b) do { \
const char *f = "[" msg "]"; \
int n = strlen((ecb)->trace); \
if (n < (sizeof((ecb)->trace)-100)) \
- sprintf((ecb)->trace + n, f, a, b); \
+ sprintf((ecb)->trace + n, f, a, b); \
} while(0)
#else
-#define ECB_TRACE(ecb, msg, a, b)
+#define ECB_TRACE(ecb, msg, a, b)
#endif
/*
@@ -186,14 +186,14 @@ struct ncr53c9x_tinfo {
int touts; /* # of timeouts */
int perrs; /* # of parity errors */
int senses; /* # of request sense commands sent */
- u_char flags;
-#define T_NEGOTIATE 0x02 /* (Re)Negotiate synchronous options */
-#define T_SYNCMODE 0x08 /* SYNC mode has been negotiated */
-#define T_SYNCHOFF 0x10 /* SYNC mode for is permanently off */
-#define T_RSELECTOFF 0x20 /* RE-SELECT mode is off */
-#define T_TAG 0x40 /* Turn on TAG QUEUEs */
-#define T_WIDE 0x80 /* Negotiate wide options */
-#define T_WDTRSENT 0x04 /* WDTR message has been sent to */
+ u_char flags;
+#define T_NEGOTIATE 0x02 /* (Re)Negotiate synchronous options */
+#define T_SYNCMODE 0x08 /* SYNC mode has been negotiated */
+#define T_SYNCHOFF 0x10 /* SYNC mode for is permanently off */
+#define T_RSELECTOFF 0x20 /* RE-SELECT mode is off */
+#define T_TAG 0x40 /* Turn on TAG QUEUEs */
+#define T_WIDE 0x80 /* Negotiate wide options */
+#define T_WDTRSENT 0x04 /* WDTR message has been sent to */
u_char period; /* Period suggestion */
u_char offset; /* Offset suggestion */
u_char cfg3; /* per target config 3 */
@@ -204,59 +204,59 @@ struct ncr53c9x_tinfo {
};
/* Look up a lun in a tinfo */
-#define TINFO_LUN(t, l) ( \
+#define TINFO_LUN(t, l) ( \
(((l) < NCR_NLUN) && (((t)->lun[(l)]) != NULL)) \
? ((t)->lun[(l)]) \
: ncr53c9x_lunsearch((t), (int64_t)(l)) \
)
/* Register a linenumber (for debugging) */
-#define LOGLINE(p)
-
-#define NCR_SHOWECBS 0x01
-#define NCR_SHOWINTS 0x02
-#define NCR_SHOWCMDS 0x04
-#define NCR_SHOWMISC 0x08
-#define NCR_SHOWTRAC 0x10
-#define NCR_SHOWSTART 0x20
-#define NCR_SHOWPHASE 0x40
-#define NCR_SHOWDMA 0x80
-#define NCR_SHOWCCMDS 0x100
-#define NCR_SHOWMSGS 0x200
+#define LOGLINE(p)
+
+#define NCR_SHOWECBS 0x01
+#define NCR_SHOWINTS 0x02
+#define NCR_SHOWCMDS 0x04
+#define NCR_SHOWMISC 0x08
+#define NCR_SHOWTRAC 0x10
+#define NCR_SHOWSTART 0x20
+#define NCR_SHOWPHASE 0x40
+#define NCR_SHOWDMA 0x80
+#define NCR_SHOWCCMDS 0x100
+#define NCR_SHOWMSGS 0x200
#ifdef NCR53C9X_DEBUG
extern int ncr53c9x_debug;
-#define NCR_ECBS(str) \
+#define NCR_ECBS(str) \
do {if (ncr53c9x_debug & NCR_SHOWECBS) printf str;} while (0)
-#define NCR_MISC(str) \
+#define NCR_MISC(str) \
do {if (ncr53c9x_debug & NCR_SHOWMISC) printf str;} while (0)
-#define NCR_INTS(str) \
+#define NCR_INTS(str) \
do {if (ncr53c9x_debug & NCR_SHOWINTS) printf str;} while (0)
-#define NCR_TRACE(str) \
+#define NCR_TRACE(str) \
do {if (ncr53c9x_debug & NCR_SHOWTRAC) printf str;} while (0)
-#define NCR_CMDS(str) \
+#define NCR_CMDS(str) \
do {if (ncr53c9x_debug & NCR_SHOWCMDS) printf str;} while (0)
-#define NCR_START(str) \
+#define NCR_START(str) \
do {if (ncr53c9x_debug & NCR_SHOWSTART) printf str;}while (0)
-#define NCR_PHASE(str) \
+#define NCR_PHASE(str) \
do {if (ncr53c9x_debug & NCR_SHOWPHASE) printf str;}while (0)
-#define NCR_DMA(str) \
+#define NCR_DMA(str) \
do {if (ncr53c9x_debug & NCR_SHOWDMA) printf str;}while (0)
-#define NCR_MSGS(str) \
+#define NCR_MSGS(str) \
do {if (ncr53c9x_debug & NCR_SHOWMSGS) printf str;}while (0)
#else
-#define NCR_ECBS(str)
-#define NCR_MISC(str)
-#define NCR_INTS(str)
-#define NCR_TRACE(str)
-#define NCR_CMDS(str)
-#define NCR_START(str)
-#define NCR_PHASE(str)
-#define NCR_DMA(str)
-#define NCR_MSGS(str)
+#define NCR_ECBS(str)
+#define NCR_MISC(str)
+#define NCR_INTS(str)
+#define NCR_TRACE(str)
+#define NCR_CMDS(str)
+#define NCR_START(str)
+#define NCR_PHASE(str)
+#define NCR_DMA(str)
+#define NCR_MSGS(str)
#endif
-#define NCR_MAX_MSG_LEN 8
+#define NCR_MAX_MSG_LEN 8
struct ncr53c9x_softc;
@@ -305,12 +305,11 @@ struct ncr53c9x_softc {
u_char sc_espintr;
u_char sc_espstat;
u_char sc_espstep;
- u_char sc_espstat2;
+ u_char sc_espstat2;
u_char sc_espfflags;
/* Lists of command blocks */
- TAILQ_HEAD(ecb_list, ncr53c9x_ecb)
- ready_list;
+ TAILQ_HEAD(ecb_list, ncr53c9x_ecb) ready_list;
struct ncr53c9x_ecb *sc_nexus; /* Current command */
int sc_ntarg;
@@ -329,7 +328,7 @@ struct ncr53c9x_softc {
u_char sc_lastcmd;
/* Message stuff */
- u_short sc_msgify; /* IDENTIFY message associated with this nexus */
+ u_short sc_msgify; /* IDENTIFY message associated with nexus */
u_short sc_msgout; /* What message is on its way out? */
u_short sc_msgpriq; /* One or more messages to send (encoded) */
u_short sc_msgoutq; /* What messages have been sent so far? */
@@ -365,72 +364,72 @@ struct ncr53c9x_softc {
};
/* values for sc_state */
-#define NCR_IDLE 1 /* Waiting for something to do */
-#define NCR_SELECTING 2 /* SCSI command is arbiting */
-#define NCR_RESELECTED 3 /* Has been reselected */
-#define NCR_IDENTIFIED 4 /* Has gotten IFY but not TAG */
-#define NCR_CONNECTED 5 /* Actively using the SCSI bus */
+#define NCR_IDLE 1 /* Waiting for something to do */
+#define NCR_SELECTING 2 /* SCSI command is arbiting */
+#define NCR_RESELECTED 3 /* Has been reselected */
+#define NCR_IDENTIFIED 4 /* Has gotten IFY but not TAG */
+#define NCR_CONNECTED 5 /* Actively using the SCSI bus */
#define NCR_DISCONNECT 6 /* MSG_DISCONNECT received */
#define NCR_CMDCOMPLETE 7 /* MSG_CMDCOMPLETE received */
#define NCR_CLEANING 8
-#define NCR_SBR 9 /* Expect a SCSI RST because we commanded it */
+#define NCR_SBR 9 /* Expect a SCSI RST because we commanded it */
/* values for sc_flags */
-#define NCR_DROP_MSGI 0x01 /* Discard all msgs (parity err detected) */
-#define NCR_ABORTING 0x02 /* Bailing out */
-#define NCR_DOINGDMA 0x04 /* The FIFO data path is active! */
-#define NCR_SYNCHNEGO 0x08 /* Synch negotiation in progress. */
-#define NCR_ICCS 0x10 /* Expect status phase results */
-#define NCR_WAITI 0x20 /* Waiting for non-DMA data to arrive */
+#define NCR_DROP_MSGI 0x01 /* Discard all msgs (parity err detected) */
+#define NCR_ABORTING 0x02 /* Bailing out */
+#define NCR_DOINGDMA 0x04 /* The FIFO data path is active! */
+#define NCR_SYNCHNEGO 0x08 /* Synch negotiation in progress. */
+#define NCR_ICCS 0x10 /* Expect status phase results */
+#define NCR_WAITI 0x20 /* Waiting for non-DMA data to arrive */
#define NCR_ATN 0x40 /* ATN asserted */
#define NCR_EXPECT_ILLCMD 0x80 /* Expect Illegal Command Interrupt */
/* values for sc_features */
#define NCR_F_HASCFG3 0x01 /* chip has CFG3 register */
#define NCR_F_FASTSCSI 0x02 /* chip supports Fast mode */
-#define NCR_F_DMASELECT 0x04 /* can do dmaselect */
+#define NCR_F_DMASELECT 0x04 /* can do dmaselect */
#define NCR_F_SELATN3 0x08 /* chip supports SELATN3 command */
/* values for sc_msgout */
-#define SEND_DEV_RESET 0x0001
-#define SEND_PARITY_ERROR 0x0002
-#define SEND_INIT_DET_ERR 0x0004
-#define SEND_REJECT 0x0008
-#define SEND_IDENTIFY 0x0010
-#define SEND_ABORT 0x0020
-#define SEND_WDTR 0x0040
-#define SEND_SDTR 0x0080
-#define SEND_TAG 0x0100
+#define SEND_DEV_RESET 0x0001
+#define SEND_PARITY_ERROR 0x0002
+#define SEND_INIT_DET_ERR 0x0004
+#define SEND_REJECT 0x0008
+#define SEND_IDENTIFY 0x0010
+#define SEND_ABORT 0x0020
+#define SEND_WDTR 0x0040
+#define SEND_SDTR 0x0080
+#define SEND_TAG 0x0100
/* SCSI Status codes */
-#define ST_MASK 0x3e /* bit 0,6,7 is reserved */
+#define ST_MASK 0x3e /* bit 0,6,7 is reserved */
/* phase bits */
-#define IOI 0x01
-#define CDI 0x02
-#define MSGI 0x04
+#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 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)
+#define PHASE_MASK (MSGI | CDI | IOI)
/* Some pseudo phases for getphase()*/
-#define BUSFREE_PHASE 0x100 /* Re/Selection no longer valid */
-#define INVALID_PHASE 0x101 /* Re/Selection valid, but no REQ yet */
-#define PSEUDO_PHASE 0x100 /* "pseudo" bit */
+#define BUSFREE_PHASE 0x100 /* Re/Selection no longer valid */
+#define INVALID_PHASE 0x101 /* Re/Selection valid, but no REQ yet */
+#define PSEUDO_PHASE 0x100 /* "pseudo" bit */
/*
* Macros to read and write the chip's registers.
*/
-#define NCR_READ_REG(sc, reg) \
+#define NCR_READ_REG(sc, reg) \
(*(sc)->sc_glue->gl_read_reg)((sc), (reg))
-#define NCR_WRITE_REG(sc, reg, val) \
+#define NCR_WRITE_REG(sc, reg, val) \
(*(sc)->sc_glue->gl_write_reg)((sc), (reg), (val))
#ifdef NCR53C9X_DEBUG
@@ -450,8 +449,8 @@ struct ncr53c9x_softc {
#define NCRDMA_ISINTR(sc) (*(sc)->sc_glue->gl_dma_isintr)((sc))
#define NCRDMA_RESET(sc) (*(sc)->sc_glue->gl_dma_reset)((sc))
#define NCRDMA_INTR(sc) (*(sc)->sc_glue->gl_dma_intr)((sc))
-#define NCRDMA_SETUP(sc, addr, len, datain, dmasize) \
- (*(sc)->sc_glue->gl_dma_setup)((sc), (addr), (len), (datain), (dmasize))
+#define NCRDMA_SETUP(sc, addr, len, datain, dmasize) \
+ (*(sc)->sc_glue->gl_dma_setup)((sc), (addr), (len), (datain), (dmasize))
#define NCRDMA_GO(sc) (*(sc)->sc_glue->gl_dma_go)((sc))
#define NCRDMA_ISACTIVE(sc) (*(sc)->sc_glue->gl_dma_isactive)((sc))
@@ -459,14 +458,14 @@ struct ncr53c9x_softc {
* Macro to convert the chip register Clock Per Byte value to
* Synchronous Transfer Period.
*/
-#define ncr53c9x_cpb2stp(sc, cpb) \
+#define ncr53c9x_cpb2stp(sc, cpb) \
((250 * (cpb)) / (sc)->sc_freq)
-int ncr53c9x_attach(struct ncr53c9x_softc *);
-int ncr53c9x_detach(struct ncr53c9x_softc *);
-void ncr53c9x_action(struct cam_sim *, union ccb *);
-void ncr53c9x_reset(struct ncr53c9x_softc *);
-void ncr53c9x_intr(void *);
-void ncr53c9x_init(struct ncr53c9x_softc *, int);
+int ncr53c9x_attach(struct ncr53c9x_softc *sc);
+int ncr53c9x_detach(struct ncr53c9x_softc *sc);
+void ncr53c9x_action(struct cam_sim *sim, union ccb *ccb);
+void ncr53c9x_reset(struct ncr53c9x_softc *sc);
+void ncr53c9x_intr(void *arg);
+void ncr53c9x_init(struct ncr53c9x_softc *sc, int doreset);
#endif /* _DEV_IC_NCR53C9XVAR_H_ */
OpenPOWER on IntegriCloud