git: dd56711e8353 - main - firewire: replace magic numbers with named constants
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 20 Jul 2026 22:50:22 UTC
The branch main has been updated by adrian:
URL: https://cgit.FreeBSD.org/src/commit/?id=dd56711e83533ffe40f3f54b01565537f85381cc
commit dd56711e83533ffe40f3f54b01565537f85381cc
Author: Abdelkader Boudih <freebsd@seuros.com>
AuthorDate: 2026-07-20 22:48:42 +0000
Commit: Adrian Chadd <adrian@FreeBSD.org>
CommitDate: 2026-07-20 22:48:44 +0000
firewire: replace magic numbers with named constants
No functional change.
Reviewed by: adrian
Differential Revision: https://reviews.freebsd.org/D58311
---
sys/dev/firewire/firewire.c | 57 ++++++++++++++++++++++++++++--------------
sys/dev/firewire/firewirereg.h | 15 +++++++++--
sys/dev/firewire/fwdev.c | 2 +-
sys/dev/firewire/fwisound.c | 2 +-
sys/dev/firewire/fwisound.h | 7 +++---
sys/dev/firewire/fwmem.c | 5 ++--
sys/dev/firewire/fwohci.c | 40 ++++++++++++++++++-----------
sys/dev/firewire/fwohci_pci.c | 10 +++++---
sys/dev/firewire/if_fwe.c | 6 ++---
sys/dev/firewire/if_fwip.c | 20 +++++++++------
sys/dev/firewire/sbp.c | 3 ++-
sys/dev/firewire/sbp_targ.c | 3 ++-
12 files changed, 112 insertions(+), 58 deletions(-)
diff --git a/sys/dev/firewire/firewire.c b/sys/dev/firewire/firewire.c
index e4624485e0c0..038ae1d1ba53 100644
--- a/sys/dev/firewire/firewire.c
+++ b/sys/dev/firewire/firewire.c
@@ -77,6 +77,23 @@ MALLOC_DEFINE(M_FWXFER, "fw_xfer", "XFER/FireWire");
#define FW_MAXASYRTY 4
+/* Split timeout: 800 cycles (see IEEE 1394-1995 8.3.2.2.2) */
+#define FW_SPLIT_TIMEOUT_CYCLES 800
+/* Default available isochronous bandwidth units (IEEE 1394-1995 Table 8-4) */
+#define FW_BANDWIDTH_AVAILABLE 4915
+/* ROM header size in quads: bus info block (4) + CRC quad (1) */
+#define FW_ROM_HEADER_QUADS 5
+/* Maximum retries when exploring a remote node's CSR ROM */
+#define FW_EXPLORE_MAX_RETRIES 3
+/* maxrec value encoding 512-byte payload (2^(maxrec+1) = 512 => maxrec=8) */
+#define FW_MAXREC_512 8
+
+/* PHY configuration packet bit fields (IEEE 1394-1995 4.3.4.1) */
+#define FW_PHY_ROOT_BIT (1 << 23)
+#define FW_PHY_ROOT_SHIFT 24
+#define FW_PHY_GAP_BIT (1 << 22)
+#define FW_PHY_GAP_SHIFT 16
+
devclass_t firewire_devclass;
static void firewire_identify(driver_t *, device_t);
@@ -608,7 +625,7 @@ fw_drain_txq(struct firewire_comm *fc)
FW_GUNLOCK(fc);
mtx_lock(&fc->tlabel_lock);
- for (i = 0; i < 0x40; i++)
+ for (i = 0; i < FW_NUM_TLABELS; i++)
while ((xfer = STAILQ_FIRST(&fc->tlabels[i])) != NULL) {
if (firewire_debug)
printf("tl=%d flag=%d\n", i, xfer->flag);
@@ -638,18 +655,18 @@ fw_reset_csr(struct firewire_comm *fc)
fc->max_node = -1;
- for (i = 2; i < 0x100 / 4 - 2; i++) {
+ for (i = 2; i < FW_MAX_NODES - 2; i++) {
CSRARC(fc, SPED_MAP + i * 4) = 0;
}
CSRARC(fc, STATE_CLEAR) = 1 << 23 | 0 << 17 | 1 << 16 | 1 << 15 | 1 << 14;
CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
CSRARC(fc, RESET_START) = 0;
CSRARC(fc, SPLIT_TIMEOUT_HI) = 0;
- CSRARC(fc, SPLIT_TIMEOUT_LO) = 800 << 19;
+ CSRARC(fc, SPLIT_TIMEOUT_LO) = FW_SPLIT_TIMEOUT_CYCLES << 19;
CSRARC(fc, CYCLE_TIME) = 0x0;
CSRARC(fc, BUS_TIME) = 0x0;
- CSRARC(fc, BUS_MGR_ID) = 0x3f;
- CSRARC(fc, BANDWIDTH_AV) = 4915;
+ CSRARC(fc, BUS_MGR_ID) = FW_NO_BUS_MANAGER;
+ CSRARC(fc, BANDWIDTH_AV) = FW_BANDWIDTH_AVAILABLE;
CSRARC(fc, CHANNELS_AV_HI) = 0xffffffff;
CSRARC(fc, CHANNELS_AV_LO) = 0xffffffff;
CSRARC(fc, IP_CHANNELS) = (1U << 31);
@@ -870,7 +887,7 @@ void fw_init(struct firewire_comm *fc)
/* Initialize Async handlers */
STAILQ_INIT(&fc->binds);
- for (i = 0; i < 0x40; i++) {
+ for (i = 0; i < FW_NUM_TLABELS; i++) {
STAILQ_INIT(&fc->tlabels[i]);
}
@@ -1248,9 +1265,11 @@ fw_phy_config(struct firewire_comm *fc, int root_node, int gap_count)
fp = &xfer->send.hdr;
fp->mode.ld[1] = 0;
if (root_node >= 0)
- fp->mode.ld[1] |= (1 << 23) | (root_node & 0x3f) << 24;
+ fp->mode.ld[1] |= FW_PHY_ROOT_BIT |
+ (root_node & FW_NODE_MASK) << FW_PHY_ROOT_SHIFT;
if (gap_count >= 0)
- fp->mode.ld[1] |= (1 << 22) | (gap_count & 0x3f) << 16;
+ fp->mode.ld[1] |= FW_PHY_GAP_BIT |
+ (gap_count & FW_NODE_MASK) << FW_PHY_GAP_SHIFT;
fp->mode.ld[2] = ~fp->mode.ld[1];
fp->mode.common.tcode |= FWTCODE_PHY;
@@ -1303,7 +1322,7 @@ void fw_sidrcv(struct firewire_comm *fc, uint32_t *sid, u_int len)
u_int i, j, node, c_port = 0, i_branch = 0;
fc->sid_cnt = len / (sizeof(uint32_t) * 2);
- fc->max_node = fc->nodeid & 0x3f;
+ fc->max_node = fc->nodeid & FW_NODE_MASK;
CSRARC(fc, NODE_IDS) = ((uint32_t)fc->nodeid) << 16;
fc->status = FWBUSCYMELECT;
fc->topology_map->crc_len = 2;
@@ -1311,7 +1330,7 @@ void fw_sidrcv(struct firewire_comm *fc, uint32_t *sid, u_int len)
fc->topology_map->self_id_count = 0;
fc->topology_map->node_count= 0;
fc->speed_map->generation++;
- fc->speed_map->crc_len = 1 + (64 * 64 + 3) / 4;
+ fc->speed_map->crc_len = 1 + (FW_MAX_NODES * FW_MAX_NODES + 3) / 4;
self_id = &fc->topology_map->self_id[0];
for (i = 0; i < fc->sid_cnt; i++) {
if (sid[1] != ~sid[0]) {
@@ -1377,7 +1396,7 @@ void fw_sidrcv(struct firewire_comm *fc, uint32_t *sid, u_int len)
(fc->irm == -1) ? "Not IRM capable" : "cable IRM",
fc->irm, (fc->irm == fc->nodeid) ? " (me) " : "");
- if (try_bmr && (fc->irm != -1) && (CSRARC(fc, BUS_MGR_ID) == 0x3f)) {
+ if (try_bmr && (fc->irm != -1) && (CSRARC(fc, BUS_MGR_ID) == FW_NO_BUS_MANAGER)) {
if (fc->irm == fc->nodeid) {
fc->status = FWBUSMGRDONE;
CSRARC(fc, BUS_MGR_ID) = fc->set_bmr(fc, fc->irm);
@@ -1633,7 +1652,7 @@ fw_explore_node(struct fw_device *dfwdev)
fwdev->dst = node;
fwdev->status = FWDEVINIT;
/* unchanged ? */
- if (bcmp(&csr[0], &fwdev->csrrom[0], sizeof(uint32_t) * 5) == 0) {
+ if (bcmp(&csr[0], &fwdev->csrrom[0], sizeof(uint32_t) * FW_ROM_HEADER_QUADS) == 0) {
if (!STAILQ_EMPTY(&fwdev->units)) {
if (firewire_debug)
device_printf(fc->dev,
@@ -1651,7 +1670,7 @@ fw_explore_node(struct fw_device *dfwdev)
bzero(&fwdev->csrrom[0], CROMSIZE);
/* copy first quad and bus info block */
- bcopy(&csr[0], &fwdev->csrrom[0], sizeof(uint32_t) * 5);
+ bcopy(&csr[0], &fwdev->csrrom[0], sizeof(uint32_t) * FW_ROM_HEADER_QUADS);
fwdev->rommax = CSRROMOFF + sizeof(uint32_t) * 4;
err = fw_explore_csrblock(fwdev, 0x14, 1); /* root directory */
@@ -1690,7 +1709,7 @@ static void
fw_explore(struct firewire_comm *fc)
{
int node, err, i, todo, todo2, trys;
- char nodes[63];
+ char nodes[FW_MAX_NODES - 1];
struct fw_device dfwdev;
union fw_self_id *fwsid;
@@ -1698,7 +1717,7 @@ fw_explore(struct firewire_comm *fc)
/* setup dummy fwdev */
dfwdev.fc = fc;
dfwdev.speed = 0;
- dfwdev.maxrec = 8; /* 512 */
+ dfwdev.maxrec = FW_MAXREC_512;
dfwdev.status = FWDEVINIT;
for (node = 0; node <= fc->max_node; node++) {
@@ -1725,7 +1744,7 @@ fw_explore(struct firewire_comm *fc)
nodes[todo++] = node;
}
- for (trys = 0; todo > 0 && trys < 3; trys++) {
+ for (trys = 0; todo > 0 && trys < FW_EXPLORE_MAX_RETRIES; trys++) {
todo2 = 0;
for (i = 0; i < todo; i++) {
dfwdev.dst = nodes[i];
@@ -1977,11 +1996,11 @@ fw_get_tlabel(struct firewire_comm *fc, struct fw_xfer *xfer)
u_int dst, new_tlabel;
struct fw_xfer *txfer;
- dst = xfer->send.hdr.mode.hdr.dst & 0x3f;
+ dst = xfer->send.hdr.mode.hdr.dst & FW_NODE_MASK;
mtx_lock(&fc->tlabel_lock);
- new_tlabel = (fc->last_tlabel[dst] + 1) & 0x3f;
+ new_tlabel = (fc->last_tlabel[dst] + 1) & FW_TLABEL_MASK;
STAILQ_FOREACH(txfer, &fc->tlabels[new_tlabel], tlabel)
- if ((txfer->send.hdr.mode.hdr.dst & 0x3f) == dst)
+ if ((txfer->send.hdr.mode.hdr.dst & FW_NODE_MASK) == dst)
break;
if (txfer == NULL) {
fc->last_tlabel[dst] = new_tlabel;
diff --git a/sys/dev/firewire/firewirereg.h b/sys/dev/firewire/firewirereg.h
index 656b7e2a448e..f4043987c3fe 100644
--- a/sys/dev/firewire/firewirereg.h
+++ b/sys/dev/firewire/firewirereg.h
@@ -98,6 +98,17 @@ struct firewire_softc {
#define FW_MAX_DEVCH FW_MAX_DMACH
#define FW_XFERTIMEOUT 1
+/* 6-bit transaction label space (IEEE 1394 6.2.4.2) */
+#define FW_NUM_TLABELS 0x40
+#define FW_TLABEL_MASK 0x3f
+
+/* 6-bit node ID fields */
+#define FW_MAX_NODES 64
+#define FW_NODE_MASK 0x3f
+
+/* BUS_MGR_ID register value when no bus manager is elected */
+#define FW_NO_BUS_MANAGER 0x3f
+
struct firewire_dev_comm {
device_t dev;
struct firewire_comm *fc;
@@ -145,8 +156,8 @@ struct firewire_comm {
struct fw_eui64 eui;
struct fw_xferq
*arq, *atq, *ars, *ats, *it[FW_MAX_DMACH],*ir[FW_MAX_DMACH];
- struct fw_xferlist tlabels[0x40];
- u_char last_tlabel[0x40];
+ struct fw_xferlist tlabels[FW_NUM_TLABELS];
+ u_char last_tlabel[FW_NUM_TLABELS];
struct mtx tlabel_lock;
STAILQ_HEAD(, fw_bind) binds;
STAILQ_HEAD(, fw_device) devices;
diff --git a/sys/dev/firewire/fwdev.c b/sys/dev/firewire/fwdev.c
index cea5ad3075ad..03e9eec5172c 100644
--- a/sys/dev/firewire/fwdev.c
+++ b/sys/dev/firewire/fwdev.c
@@ -408,7 +408,7 @@ fw_write_async(struct fw_drv1 *d, struct uio *uio, int ioflag)
xfer->fc = d->fc;
xfer->sc = NULL;
xfer->hand = fw_xferwake;
- xfer->send.spd = 2 /* XXX */;
+ xfer->send.spd = FWSPD_S400;
if ((err = fw_asyreq(xfer->fc, -1, xfer)))
goto out;
diff --git a/sys/dev/firewire/fwisound.c b/sys/dev/firewire/fwisound.c
index 12a32fb25aab..da04ae9f034b 100644
--- a/sys/dev/firewire/fwisound.c
+++ b/sys/dev/firewire/fwisound.c
@@ -381,7 +381,7 @@ fwisound_iso_input(struct fw_xferq *xferq)
}
sample_count = ntohl(pay->sample_count);
- if (sample_count == 0 || sample_count > 475) {
+ if (sample_count == 0 || sample_count > FWISOUND_MAX_SAMPLES) {
m_freem(m);
continue;
}
diff --git a/sys/dev/firewire/fwisound.h b/sys/dev/firewire/fwisound.h
index 47a9790e074c..02108237c8e8 100644
--- a/sys/dev/firewire/fwisound.h
+++ b/sys/dev/firewire/fwisound.h
@@ -32,17 +32,18 @@
#define FWISOUND_AUDIO_ENABLE (1u << 31)
#define FWISOUND_RATE_48000 (1u << 31)
+#define FWISOUND_MAX_SAMPLES 475 /* max samples per ISO packet */
+#define FWISOUND_SIGNATURE 0x73676874u /* "sght" */
+
/* Apple FireWire audio ISO payload. */
struct fwisound_payload {
uint32_t sample_count; /* samples in this packet */
uint32_t signature; /* 0x73676874 = "sght" */
uint32_t sample_total; /* running total (drop detect)*/
uint32_t reserved;
- int16_t samples[2 * 475]; /* stereo S16BE; *2 valid */
+ int16_t samples[2 * FWISOUND_MAX_SAMPLES]; /* stereo S16BE */
};
-#define FWISOUND_SIGNATURE 0x73676874u /* "sght" */
-
/* ISO DMA parameters */
#define FWISOUND_ISO_CHANNEL 1
#define FWISOUND_ISO_NCHUNK 64
diff --git a/sys/dev/firewire/fwmem.c b/sys/dev/firewire/fwmem.c
index e2d114f69661..6941fc8ec513 100644
--- a/sys/dev/firewire/fwmem.c
+++ b/sys/dev/firewire/fwmem.c
@@ -61,7 +61,7 @@
#include <dev/firewire/firewirereg.h>
#include <dev/firewire/fwmem.h>
-static int fwmem_speed = 2, fwmem_debug = 0;
+static int fwmem_speed = FWSPD_S400, fwmem_debug = 0;
static struct fw_eui64 fwmem_eui64;
SYSCTL_DECL(_hw_firewire);
static SYSCTL_NODE(_hw_firewire, OID_AUTO, fwmem,
@@ -78,7 +78,8 @@ SYSCTL_INT(_debug, OID_AUTO, fwmem_debug, CTLFLAG_RW, &fwmem_debug, 0,
static MALLOC_DEFINE(M_FWMEM, "fwmem", "fwmem/FireWire");
-#define MAXLEN (512 << fwmem_speed)
+#define FW_MAXPKT_S100 512 /* S100 max async payload */
+#define MAXLEN (FW_MAXPKT_S100 << fwmem_speed)
struct fwmem_softc {
struct fw_eui64 eui;
diff --git a/sys/dev/firewire/fwohci.c b/sys/dev/firewire/fwohci.c
index 1d5a4d686d81..dad9ff03ab6d 100644
--- a/sys/dev/firewire/fwohci.c
+++ b/sys/dev/firewire/fwohci.c
@@ -84,10 +84,20 @@ char fwohcicode[32][0x20]= {
"Undef", "Undef", "Undef", "ack tardy",
"Undef", "ack data_err", "ack type_err", ""};
-#define MAX_SPEED 3
+#define MAX_SPEED FWSPD_S800
extern char *linkspeed[];
uint32_t tagbit[4] = {1 << 28, 1 << 29, 1 << 30, 1 << 31};
+/* OHCI-local timing and protocol constants */
+#define FWOHCI_PHY_DELAY 100 /* us delay after PHY register write */
+#define FWOHCI_PHY_POLL_LIMIT 1000 /* poll iterations for bus manager CSR */
+#define FW_MAXREC_BASE 8 /* maxrec = speed + FW_MAXREC_BASE */
+#define FWOHCI_ATRETRY_MAX 0x0f /* max AT retries (phy/resp/req) */
+#define FW_CYCLES_PER_SEC 8000 /* ISO cycles per second */
+#define FW_CYCLETIMER_CYCLE_SHIFT 12 /* shift to extract cycle from cycletimer */
+#define FW_CYCLETIMER_CYCLE_MASK 0x7fff /* mask after shift (2-bit sec + 13-bit cycle) */
+#define FWOHCI_MAX_CYCLE_LOST 10 /* max CYC_LOST events before disabling */
+
static struct tcode_info tinfo[] = {
/* hdr_len block flag valid_response */
/* 0 WREQQ */ {16, FWTI_REQ | FWTI_TLABEL, FWTCODE_WRES},
@@ -271,7 +281,7 @@ fwphy_wrdata(struct fwohci_softc *sc, uint32_t addr, uint32_t data)
fun = (PHYDEV_WRCMD | (addr << PHYDEV_REGADDR) |
(data << PHYDEV_WRDATA));
OWRITE(sc, OHCI_PHYACCESS, fun);
- DELAY(100);
+ DELAY(FWOHCI_PHY_DELAY);
return (fwphy_rddata(sc, addr));
}
@@ -291,10 +301,10 @@ fwohci_set_bus_manager(struct firewire_comm *fc, u_int node)
OWRITE(sc, OHCI_CSR_DATA, node);
OWRITE(sc, OHCI_CSR_COMP, 0x3f);
OWRITE(sc, OHCI_CSR_CONT, OHCI_BUS_MANAGER_ID);
- for (i = 0; !(OREAD(sc, OHCI_CSR_CONT) & (1<<31)) && (i < 1000); i++)
+ for (i = 0; !(OREAD(sc, OHCI_CSR_CONT) & (1<<31)) && (i < FWOHCI_PHY_POLL_LIMIT); i++)
DELAY(10);
bm = OREAD(sc, OHCI_CSR_DATA);
- if ((bm & 0x3f) == 0x3f)
+ if ((bm & FW_NODE_MASK) == FW_NO_BUS_MANAGER)
bm = node;
if (firewire_debug)
device_printf(sc->fc.dev, "%s: %d->%d (loop=%d)\n",
@@ -537,7 +547,7 @@ fwohci_reset(struct fwohci_softc *sc, device_t dev)
device_printf(dev, "Link %s, max_rec %d bytes.\n",
linkspeed[speed], MAXREC(max_rec));
/* XXX fix max_rec */
- sc->fc.maxrec = sc->fc.speed + 8;
+ sc->fc.maxrec = sc->fc.speed + FW_MAXREC_BASE;
if (max_rec != sc->fc.maxrec) {
reg2 = (reg2 & 0xffff0fff) | (sc->fc.maxrec << 12);
device_printf(dev, "max_rec %d -> %d\n",
@@ -571,7 +581,7 @@ fwohci_reset(struct fwohci_softc *sc, device_t dev)
/* AT Retries */
OWRITE(sc, FWOHCI_RETRY,
/* CycleLimit PhyRespRetries ATRespRetries ATReqRetries */
- (0xffff << 16) | (0x0f << 8) | (0x0f << 4) | 0x0f);
+ (0xffff << 16) | (FWOHCI_ATRETRY_MAX << 8) | (FWOHCI_ATRETRY_MAX << 4) | FWOHCI_ATRETRY_MAX);
sc->atrq.top = STAILQ_FIRST(&sc->atrq.db_trq);
sc->atrs.top = STAILQ_FIRST(&sc->atrs.db_trq);
@@ -905,7 +915,7 @@ txloop:
hdr_len = 12;
ld[1] = fp->mode.ld[1];
ld[2] = fp->mode.ld[2];
- ohcifp->mode.common.spd = 0;
+ ohcifp->mode.common.spd = FWSPD_S100;
ohcifp->mode.common.tcode = FWOHCITCODE_PHY;
} else {
ohcifp->mode.asycomm.dst = fp->mode.hdr.dst;
@@ -1450,14 +1460,14 @@ fwohci_next_cycle(struct firewire_comm *fc, int cycle_now)
#define CYCLE_MOD 0x10
#define CYCLE_DELAY 8 /* min delay to start DMA */
cycle = cycle + CYCLE_DELAY;
- if (cycle >= 8000) {
+ if (cycle >= FW_CYCLES_PER_SEC) {
sec++;
- cycle -= 8000;
+ cycle -= FW_CYCLES_PER_SEC;
}
cycle = roundup2(cycle, CYCLE_MOD);
- if (cycle >= 8000) {
+ if (cycle >= FW_CYCLES_PER_SEC) {
sec++;
- if (cycle == 8000)
+ if (cycle == FW_CYCLES_PER_SEC)
cycle = 0;
else
cycle = CYCLE_MOD;
@@ -1541,7 +1551,7 @@ fwohci_itxbuf_enable(struct firewire_comm *fc, int dmach)
OWRITE(sc, OHCI_ITCTLCLR(dmach), 0xffff0000);
/* 2bit second + 13bit cycle */
- cycle_now = (fc->cyctimer(fc) >> 12) & 0x7fff;
+ cycle_now = (fc->cyctimer(fc) >> FW_CYCLETIMER_CYCLE_SHIFT) & FW_CYCLETIMER_CYCLE_MASK;
cycle_match = fwohci_next_cycle(fc, cycle_now);
OWRITE(sc, OHCI_ITCTL(dmach),
@@ -1900,7 +1910,7 @@ fwohci_intr_dma(struct fwohci_softc *sc, uint32_t stat, int count)
if (stat & OHCI_INT_CYC_LOST) {
if (sc->cycle_lost >= 0)
sc->cycle_lost++;
- if (sc->cycle_lost > 10) {
+ if (sc->cycle_lost > FWOHCI_MAX_CYCLE_LOST) {
sc->cycle_lost = -1;
OWRITE(sc, FWOHCI_INTMASKCLR, OHCI_INT_CYC_LOST);
device_printf(fc->dev, "too many cycles lost, "
@@ -2439,10 +2449,10 @@ fwohci_txbufdb(struct fwohci_softc *sc, int dmach, struct fw_bulkxfer *bulkxfer)
fp = (struct fw_pkt *)db_tr->buf;
ohcifp = (struct fwohci_txpkthdr *) db[1].db.immed;
ohcifp->mode.ld[0] = fp->mode.ld[0];
- ohcifp->mode.common.spd = 0 & 0x7;
+ ohcifp->mode.common.spd = FWSPD_S100;
ohcifp->mode.stream.len = fp->mode.stream.len;
ohcifp->mode.stream.chtag = chtag;
- ohcifp->mode.stream.tcode = 0xa;
+ ohcifp->mode.stream.tcode = FWTCODE_STREAM;
#if BYTE_ORDER == BIG_ENDIAN
FWOHCI_DMA_WRITE(db[1].db.immed[0], db[1].db.immed[0]);
FWOHCI_DMA_WRITE(db[1].db.immed[1], db[1].db.immed[1]);
diff --git a/sys/dev/firewire/fwohci_pci.c b/sys/dev/firewire/fwohci_pci.c
index 609651aad849..d15e4deafb1d 100644
--- a/sys/dev/firewire/fwohci_pci.c
+++ b/sys/dev/firewire/fwohci_pci.c
@@ -60,6 +60,10 @@
#include <dev/firewire/fwohcireg.h>
#include <dev/firewire/fwohcivar.h>
+#define FWOHCI_DMA_MAXSIZE 0x100000 /* 1MB */
+#define FWOHCI_DMA_NSEG 0x20 /* 32 segments */
+#define FWOHCI_DMA_MAXSEGSZ 0x8000 /* 32KB per segment */
+
static int fwohci_pci_attach(device_t self);
static int fwohci_pci_detach(device_t self);
@@ -284,9 +288,9 @@ fwohci_pci_attach(device_t self)
#endif
/*highaddr*/BUS_SPACE_MAXADDR,
/*filter*/NULL, /*filterarg*/NULL,
- /*maxsize*/0x100000,
- /*nsegments*/0x20,
- /*maxsegsz*/0x8000,
+ /*maxsize*/FWOHCI_DMA_MAXSIZE,
+ /*nsegments*/FWOHCI_DMA_NSEG,
+ /*maxsegsz*/FWOHCI_DMA_MAXSEGSZ,
/*flags*/BUS_DMA_ALLOCNOW,
/*lockfunc*/busdma_lock_mutex,
/*lockarg*/FW_GMTX(&sc->fc),
diff --git a/sys/dev/firewire/if_fwe.c b/sys/dev/firewire/if_fwe.c
index bf7ed29fc5b4..322410b140c4 100644
--- a/sys/dev/firewire/if_fwe.c
+++ b/sys/dev/firewire/if_fwe.c
@@ -78,7 +78,7 @@ static void fwe_as_input (struct fw_xferq *);
static int fwedebug = 0;
static int stream_ch = 1;
-static int tx_speed = 2;
+static int tx_speed = FWSPD_S400;
static int rx_queue_len = FWMAXQUEUE;
static MALLOC_DEFINE(M_FWE, "if_fwe", "Ethernet over FireWire interface");
@@ -269,7 +269,7 @@ fwe_init(void *arg)
FWEDEBUG(ifp, "initializing\n");
- /* XXX keep promiscoud mode */
+ /* keep promiscuous mode */
if_setflagbits(ifp, IFF_PROMISC, 0);
fc = fwe->fd.fc;
@@ -338,7 +338,7 @@ fwe_ioctl(if_t ifp, u_long cmd, caddr_t data)
if (if_getdrvflags(ifp) & IFF_DRV_RUNNING)
fwe_stop(fwe);
}
- /* XXX keep promiscoud mode */
+ /* keep promiscuous mode */
if_setflagbits(ifp, IFF_PROMISC, 0);
break;
case SIOCADDMULTI:
diff --git a/sys/dev/firewire/if_fwip.c b/sys/dev/firewire/if_fwip.c
index 103ccf75b863..23e2e619a14e 100644
--- a/sys/dev/firewire/if_fwip.c
+++ b/sys/dev/firewire/if_fwip.c
@@ -91,9 +91,15 @@ static void fwip_start_send (void *, int);
static void fwip_stream_input (struct fw_xferq *);
static void fwip_unicast_input(struct fw_xfer *);
+/* tag field: bits [7:6] = 0b11 (broadcast), channel field: bits [5:0] = 31 */
+#define FWXFERQ_TAG_ALL (3 << 6)
+#define FW_IP_CHANNEL 31
+/* GASP header: specifier_hi + specifier_lo/version + payload */
+#define FW_GASP_HDR_LEN (3 * sizeof(uint32_t))
+
static int fwipdebug = 0;
-static int broadcast_channel = 0xc0 | 0x1f; /* tag | channel(XXX) */
-static int tx_speed = 2;
+static int broadcast_channel = FWXFERQ_TAG_ALL | FW_IP_CHANNEL;
+static int tx_speed = FWSPD_S400;
static int rx_queue_len = FWMAXQUEUE;
static MALLOC_DEFINE(M_FWIP, "if_fwip", "IP over FireWire interface");
@@ -548,9 +554,9 @@ fwip_async_output(struct fwip_softc *fwip, if_t ifp)
fp->mode.stream.chtag = broadcast_channel;
fp->mode.stream.tcode = FWTCODE_STREAM;
fp->mode.stream.sy = 0;
- xfer->send.spd = 0;
+ xfer->send.spd = FWSPD_S100;
p[0] = htonl(nodeid << 16);
- p[1] = htonl((0x5e << 24) | 1);
+ p[1] = htonl((CSRVAL_IETF << 24) | 1);
} else {
/*
* Unicast packets are sent as block writes to the
@@ -702,7 +708,7 @@ fwip_stream_input(struct fw_xferq *xferq)
* version.
*/
p = mtod(m, uint32_t *);
- if ((((ntohl(p[1]) & 0xffff) << 8) | ntohl(p[2]) >> 24) != 0x00005e
+ if ((((ntohl(p[1]) & 0xffff) << 8) | ntohl(p[2]) >> 24) != CSRVAL_IETF
|| (ntohl(p[2]) & 0xffffff) != 1) {
FWIPDEBUG(ifp, "Unrecognised GASP header %#08x %#08x\n",
ntohl(p[1]), ntohl(p[2]));
@@ -724,7 +730,7 @@ fwip_stream_input(struct fw_xferq *xferq)
struct fw_device *fd;
uint32_t *p = (uint32_t *) (mtag + 1);
fd = fw_noderesolve_nodeid(fwip->fd.fc,
- src & 0x3f);
+ src & FW_NODE_MASK);
if (fd) {
p[0] = htonl(fd->eui.hi);
p[1] = htonl(fd->eui.lo);
@@ -739,7 +745,7 @@ fwip_stream_input(struct fw_xferq *xferq)
/*
* Trim off the GASP header
*/
- m_adj(m, 3*sizeof(uint32_t));
+ m_adj(m, FW_GASP_HDR_LEN);
m->m_pkthdr.rcvif = ifp;
firewire_input(ifp, m, src);
if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
diff --git a/sys/dev/firewire/sbp.c b/sys/dev/firewire/sbp.c
index 81f4ac50f5cf..8d5ad7e2ad8c 100644
--- a/sys/dev/firewire/sbp.c
+++ b/sys/dev/firewire/sbp.c
@@ -74,6 +74,7 @@
#define SBP_LOGIN_SIZE sizeof(struct sbp_login_res)
#define SBP_QUEUE_LEN ((SBP_DMA_SIZE - SBP_LOGIN_SIZE) / sizeof(struct sbp_ocb))
#define SBP_NUM_OCB (SBP_QUEUE_LEN * SBP_NUM_TARGETS)
+#define SBP_MAX_XFER 5 /* max concurrent xfers per target */
/*
* STATUS FIFO addressing
@@ -1287,7 +1288,7 @@ sbp_write_cmd(struct sbp_dev *sdev, int tcode, int offset)
target = sdev->target;
xfer = STAILQ_FIRST(&target->xferlist);
if (xfer == NULL) {
- if (target->n_xfer > 5 /* XXX */) {
+ if (target->n_xfer > SBP_MAX_XFER) {
printf("sbp: no more xfer for this target\n");
return (NULL);
}
diff --git a/sys/dev/firewire/sbp_targ.c b/sys/dev/firewire/sbp_targ.c
index 5c0897a2b570..120159ffdedb 100644
--- a/sys/dev/firewire/sbp_targ.c
+++ b/sys/dev/firewire/sbp_targ.c
@@ -82,6 +82,7 @@
#define SBP_TARG_BIND_END (((u_int64_t)SBP_TARG_BIND_HI << 32) | \
SBP_TARG_BIND_LO(MAX_LOGINS))
#define SBP_TARG_LOGIN_ID(lo) (((lo) - SBP_TARG_BIND_LO(0))/0x20)
+#define SBP_TARG_MAX_CHUNK 2048 /* max DMA chunk per xfer */
#define FETCH_MGM 0
#define FETCH_CMD 1
@@ -931,7 +932,7 @@ sbp_targ_xfer_buf(struct orb_info *orbi, u_int offset,
while (size > 0) {
/* XXX assume dst_lo + off doesn't overflow */
- len = MIN(size, 2048 /* XXX */);
+ len = MIN(size, SBP_TARG_MAX_CHUNK);
size -= len;
orbi->refcount ++;
if (ccb_dir == CAM_DIR_OUT) {