summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2009-07-22 21:32:51 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2009-07-22 21:32:51 +0000
commit15cdd92be12097f8167f317f8112f1f4fd4e1198 (patch)
tree3dd11e8e9236cc50beccf1830302abeb911b15d3
parentf7d8374cdd6f173c7e15b3496758f6d0f49d57d5 (diff)
Add big-endian platform support to sis(4). Tested to not break anything on
sokeris by mk@, and to work on sparc64 by brad@ and on sgi by yours truly.
-rw-r--r--sys/dev/pci/if_sis.c76
-rw-r--r--sys/dev/pci/if_sisreg.h9
2 files changed, 45 insertions, 40 deletions
diff --git a/sys/dev/pci/if_sis.c b/sys/dev/pci/if_sis.c
index f4c68f4d996..bc8a6d9cfa6 100644
--- a/sys/dev/pci/if_sis.c
+++ b/sys/dev/pci/if_sis.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_sis.c,v 1.93 2009/06/22 22:14:21 claudio Exp $ */
+/* $OpenBSD: if_sis.c,v 1.94 2009/07/22 21:32:50 miod Exp $ */
/*
* Copyright (c) 1997, 1998, 1999
* Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
@@ -307,7 +307,7 @@ sis_read_eeprom(struct sis_softc *sc, caddr_t dest,
sis_eeprom_getword(sc, off + i, &word);
ptr = (u_int16_t *)(dest + (i * 2));
if (swap)
- *ptr = ntohs(word);
+ *ptr = letoh16(word);
else
*ptr = word;
}
@@ -344,11 +344,11 @@ sis_read_mac(struct sis_softc *sc, struct pci_attach_args *pa)
SIS_CLRBIT(sc, SIS_RXFILT_CTL, SIS_RXFILTCTL_ENABLE);
CSR_WRITE_4(sc, SIS_RXFILT_CTL, SIS_FILTADDR_PAR0);
- enaddr[0] = CSR_READ_4(sc, SIS_RXFILT_DATA) & 0xffff;
+ enaddr[0] = letoh16(CSR_READ_4(sc, SIS_RXFILT_DATA) & 0xffff);
CSR_WRITE_4(sc, SIS_RXFILT_CTL, SIS_FILTADDR_PAR1);
- enaddr[1] = CSR_READ_4(sc, SIS_RXFILT_DATA) & 0xffff;
+ enaddr[1] = letoh16(CSR_READ_4(sc, SIS_RXFILT_DATA) & 0xffff);
CSR_WRITE_4(sc, SIS_RXFILT_CTL, SIS_FILTADDR_PAR2);
- enaddr[2] = CSR_READ_4(sc, SIS_RXFILT_DATA) & 0xffff;
+ enaddr[2] = letoh16(CSR_READ_4(sc, SIS_RXFILT_DATA) & 0xffff);
SIS_SETBIT(sc, SIS_RXFILT_CTL, SIS_RXFILTCTL_ENABLE);
}
@@ -363,7 +363,7 @@ sis_read96x_mac(struct sis_softc *sc)
for (i = 0; i < 2000; i++) {
if ((CSR_READ_4(sc, SIS_EECTL) & SIS96x_EECTL_GNT)) {
sis_read_eeprom(sc, (caddr_t)&sc->arpcom.ac_enaddr,
- SIS_EE_NODEADDR, 3, 0);
+ SIS_EE_NODEADDR, 3, 1);
break;
} else
DELAY(1);
@@ -1000,7 +1000,8 @@ sis_attach(struct device *parent, struct device *self, void *aux)
{
u_int16_t tmp[4];
- sis_read_eeprom(sc, (caddr_t)&tmp, NS_EE_NODEADDR,4,0);
+ sis_read_eeprom(sc, (caddr_t)&tmp, NS_EE_NODEADDR,
+ 4, 0);
/* Shift everything over one bit. */
tmp[3] = tmp[3] >> 1;
@@ -1011,9 +1012,9 @@ sis_attach(struct device *parent, struct device *self, void *aux)
tmp[1] |= tmp[0] << 15;
/* Now reverse all the bits. */
- tmp[3] = sis_reverse(tmp[3]);
- tmp[2] = sis_reverse(tmp[2]);
- tmp[1] = sis_reverse(tmp[1]);
+ tmp[3] = letoh16(sis_reverse(tmp[3]));
+ tmp[2] = letoh16(sis_reverse(tmp[2]));
+ tmp[1] = letoh16(sis_reverse(tmp[1]));
bcopy((char *)&tmp[1], sc->arpcom.ac_enaddr,
ETHER_ADDR_LEN);
@@ -1051,7 +1052,7 @@ sis_attach(struct device *parent, struct device *self, void *aux)
sis_read_mac(sc, pa);
else
sis_read_eeprom(sc, (caddr_t)&sc->arpcom.ac_enaddr,
- SIS_EE_NODEADDR, 3, 0);
+ SIS_EE_NODEADDR, 3, 1);
break;
}
@@ -1176,8 +1177,8 @@ sis_ring_init(struct sis_softc *sc)
nexti = i + 1;
ld->sis_tx_list[i].sis_nextdesc = &ld->sis_tx_list[nexti];
ld->sis_tx_list[i].sis_next =
- sc->sc_listmap->dm_segs[0].ds_addr +
- offsetof(struct sis_list_data, sis_tx_list[nexti]);
+ htole32(sc->sc_listmap->dm_segs[0].ds_addr +
+ offsetof(struct sis_list_data, sis_tx_list[nexti]));
ld->sis_tx_list[i].sis_mbuf = NULL;
ld->sis_tx_list[i].sis_ptr = 0;
ld->sis_tx_list[i].sis_ctl = 0;
@@ -1192,8 +1193,8 @@ sis_ring_init(struct sis_softc *sc)
nexti = i + 1;
ld->sis_rx_list[i].sis_nextdesc = &ld->sis_rx_list[nexti];
ld->sis_rx_list[i].sis_next =
- sc->sc_listmap->dm_segs[0].ds_addr +
- offsetof(struct sis_list_data, sis_rx_list[nexti]);
+ htole32(sc->sc_listmap->dm_segs[0].ds_addr +
+ offsetof(struct sis_list_data, sis_rx_list[nexti]));
ld->sis_rx_list[i].sis_ctl = 0;
}
@@ -1253,8 +1254,8 @@ sis_newbuf(struct sis_softc *sc, struct sis_desc *c)
BUS_DMASYNC_PREREAD);
c->sis_mbuf = m_new;
- c->sis_ptr = c->map->dm_segs[0].ds_addr;
- c->sis_ctl = ETHER_MAX_DIX_LEN;
+ c->sis_ptr = htole32(c->map->dm_segs[0].ds_addr);
+ c->sis_ctl = htole32(ETHER_MAX_DIX_LEN);
bus_dmamap_sync(sc->sc_dmat, sc->sc_listmap,
((caddr_t)c - sc->sc_listkva), sizeof(struct sis_desc),
@@ -1287,7 +1288,7 @@ sis_rxeof(struct sis_softc *sc)
if (!SIS_OWNDESC(cur_rx))
break;
- rxstat = cur_rx->sis_rxstat;
+ rxstat = letoh32(cur_rx->sis_rxstat);
m = cur_rx->sis_mbuf;
cur_rx->sis_mbuf = NULL;
total_len = SIS_RXBYTES(cur_rx);
@@ -1364,7 +1365,7 @@ void
sis_txeof(struct sis_softc *sc)
{
struct ifnet *ifp;
- u_int32_t idx;
+ u_int32_t idx, ctl, txstat;
ifp = &sc->arpcom.ac_if;
@@ -1384,19 +1385,22 @@ sis_txeof(struct sis_softc *sc)
if (SIS_OWNDESC(cur_tx))
break;
- if (cur_tx->sis_ctl & SIS_CMDSTS_MORE)
+ ctl = letoh32(cur_tx->sis_ctl);
+
+ if (ctl & SIS_CMDSTS_MORE)
continue;
- if (!(cur_tx->sis_ctl & SIS_CMDSTS_PKT_OK)) {
+ txstat = letoh32(cur_tx->sis_txstat);
+
+ if (!(ctl & SIS_CMDSTS_PKT_OK)) {
ifp->if_oerrors++;
- if (cur_tx->sis_txstat & SIS_TXSTAT_EXCESSCOLLS)
+ if (txstat & SIS_TXSTAT_EXCESSCOLLS)
ifp->if_collisions++;
- if (cur_tx->sis_txstat & SIS_TXSTAT_OUTOFWINCOLL)
+ if (txstat & SIS_TXSTAT_OUTOFWINCOLL)
ifp->if_collisions++;
}
- ifp->if_collisions +=
- (cur_tx->sis_txstat & SIS_TXSTAT_COLLCNT) >> 16;
+ ifp->if_collisions += (txstat & SIS_TXSTAT_COLLCNT) >> 16;
ifp->if_opackets++;
if (cur_tx->map->dm_nsegs != 0) {
@@ -1542,10 +1546,10 @@ sis_encap(struct sis_softc *sc, struct mbuf *m_head, u_int32_t *txidx)
if ((SIS_TX_LIST_CNT - (sc->sis_cdata.sis_tx_cnt + i)) < 2)
return(ENOBUFS);
f = &sc->sis_ldata->sis_tx_list[frag];
- f->sis_ctl = SIS_CMDSTS_MORE | map->dm_segs[i].ds_len;
- f->sis_ptr = map->dm_segs[i].ds_addr;
+ f->sis_ctl = htole32(SIS_CMDSTS_MORE | map->dm_segs[i].ds_len);
+ f->sis_ptr = htole32(map->dm_segs[i].ds_addr);
if (i != 0)
- f->sis_ctl |= SIS_CMDSTS_OWN;
+ f->sis_ctl |= htole32(SIS_CMDSTS_OWN);
cur = frag;
SIS_INC(frag, SIS_TX_LIST_CNT);
}
@@ -1554,8 +1558,8 @@ sis_encap(struct sis_softc *sc, struct mbuf *m_head, u_int32_t *txidx)
BUS_DMASYNC_PREWRITE);
sc->sis_ldata->sis_tx_list[cur].sis_mbuf = m_head;
- sc->sis_ldata->sis_tx_list[cur].sis_ctl &= ~SIS_CMDSTS_MORE;
- sc->sis_ldata->sis_tx_list[*txidx].sis_ctl |= SIS_CMDSTS_OWN;
+ sc->sis_ldata->sis_tx_list[cur].sis_ctl &= ~htole32(SIS_CMDSTS_MORE);
+ sc->sis_ldata->sis_tx_list[*txidx].sis_ctl |= htole32(SIS_CMDSTS_OWN);
sc->sis_cdata.sis_tx_cnt += i;
*txidx = frag;
@@ -1655,23 +1659,23 @@ sis_init(void *xsc)
if (sc->sis_type == SIS_TYPE_83815) {
CSR_WRITE_4(sc, SIS_RXFILT_CTL, NS_FILTADDR_PAR0);
CSR_WRITE_4(sc, SIS_RXFILT_DATA,
- ((u_int16_t *)sc->arpcom.ac_enaddr)[0]);
+ htole16(((u_int16_t *)sc->arpcom.ac_enaddr)[0]));
CSR_WRITE_4(sc, SIS_RXFILT_CTL, NS_FILTADDR_PAR1);
CSR_WRITE_4(sc, SIS_RXFILT_DATA,
- ((u_int16_t *)sc->arpcom.ac_enaddr)[1]);
+ htole16(((u_int16_t *)sc->arpcom.ac_enaddr)[1]));
CSR_WRITE_4(sc, SIS_RXFILT_CTL, NS_FILTADDR_PAR2);
CSR_WRITE_4(sc, SIS_RXFILT_DATA,
- ((u_int16_t *)sc->arpcom.ac_enaddr)[2]);
+ htole16(((u_int16_t *)sc->arpcom.ac_enaddr)[2]));
} else {
CSR_WRITE_4(sc, SIS_RXFILT_CTL, SIS_FILTADDR_PAR0);
CSR_WRITE_4(sc, SIS_RXFILT_DATA,
- ((u_int16_t *)sc->arpcom.ac_enaddr)[0]);
+ htole16(((u_int16_t *)sc->arpcom.ac_enaddr)[0]));
CSR_WRITE_4(sc, SIS_RXFILT_CTL, SIS_FILTADDR_PAR1);
CSR_WRITE_4(sc, SIS_RXFILT_DATA,
- ((u_int16_t *)sc->arpcom.ac_enaddr)[1]);
+ htole16(((u_int16_t *)sc->arpcom.ac_enaddr)[1]));
CSR_WRITE_4(sc, SIS_RXFILT_CTL, SIS_FILTADDR_PAR2);
CSR_WRITE_4(sc, SIS_RXFILT_DATA,
- ((u_int16_t *)sc->arpcom.ac_enaddr)[2]);
+ htole16(((u_int16_t *)sc->arpcom.ac_enaddr)[2]));
}
/* Init circular TX/RX lists. */
diff --git a/sys/dev/pci/if_sisreg.h b/sys/dev/pci/if_sisreg.h
index 6a2d745f691..0aa4aff3841 100644
--- a/sys/dev/pci/if_sisreg.h
+++ b/sys/dev/pci/if_sisreg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_sisreg.h,v 1.30 2009/06/04 18:12:56 sthen Exp $ */
+/* $OpenBSD: if_sisreg.h,v 1.31 2009/07/22 21:32:50 miod Exp $ */
/*
* Copyright (c) 1997, 1998, 1999
* Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
@@ -340,10 +340,11 @@ struct sis_desc {
#define SIS_CMDSTS_MORE 0x40000000
#define SIS_CMDSTS_OWN 0x80000000
-#define SIS_LASTDESC(x) (!((x)->sis_ctl & SIS_CMDSTS_MORE)))
-#define SIS_OWNDESC(x) ((x)->sis_ctl & SIS_CMDSTS_OWN)
+#define SIS_LASTDESC(x) (!(letoh32((x)->sis_ctl) & SIS_CMDSTS_MORE)))
+#define SIS_OWNDESC(x) (letoh32((x)->sis_ctl) & SIS_CMDSTS_OWN)
#define SIS_INC(x, y) (x) = ((x) == ((y)-1)) ? 0 : (x)+1
-#define SIS_RXBYTES(x) (((x)->sis_ctl & SIS_CMDSTS_BUFLEN) - ETHER_CRC_LEN)
+#define SIS_RXBYTES(x) \
+ ((letoh32((x)->sis_ctl) & SIS_CMDSTS_BUFLEN) - ETHER_CRC_LEN)
#define SIS_RXSTAT_COLL 0x00010000
#define SIS_RXSTAT_LOOPBK 0x00020000