summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorDamien Bergamini <damien@cvs.openbsd.org>2008-11-25 21:43:58 +0000
committerDamien Bergamini <damien@cvs.openbsd.org>2008-11-25 21:43:58 +0000
commitd69871e8580da6ee2c3f62ac8cea87938e65dedc (patch)
tree8a81b4cb39645cdba8edecc1eb0226ecf4f04160 /sys
parentb15ff47f94d82c81611a7806f710066b190b8ecb (diff)
use shiny new m_defrag() and nitems() instead of rolling our own.
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/ic/rt2560.c30
-rw-r--r--sys/dev/ic/rt2661.c32
-rw-r--r--sys/dev/ic/rt2860.c35
-rw-r--r--sys/dev/pci/if_ipw.c27
-rw-r--r--sys/dev/pci/if_iwi.c22
-rw-r--r--sys/dev/pci/if_iwn.c23
-rw-r--r--sys/dev/pci/if_wpi.c19
7 files changed, 25 insertions, 163 deletions
diff --git a/sys/dev/ic/rt2560.c b/sys/dev/ic/rt2560.c
index e8f9cafdf05..4981fc06a59 100644
--- a/sys/dev/ic/rt2560.c
+++ b/sys/dev/ic/rt2560.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rt2560.c,v 1.39 2008/08/27 09:05:03 damien Exp $ */
+/* $OpenBSD: rt2560.c,v 1.40 2008/11/25 21:43:57 damien Exp $ */
/*-
* Copyright (c) 2005, 2006
@@ -1699,7 +1699,6 @@ rt2560_tx_data(struct rt2560_softc *sc, struct mbuf *m0,
struct rt2560_tx_data *data;
struct ieee80211_frame *wh;
struct ieee80211_key *k;
- struct mbuf *mnew;
uint16_t dur;
uint32_t flags = 0;
int pktlen, rate, needcts = 0, needrts = 0, error;
@@ -1828,27 +1827,10 @@ rt2560_tx_data(struct rt2560_softc *sc, struct mbuf *m0,
}
if (error != 0) {
/* too many fragments, linearize */
-
- MGETHDR(mnew, M_DONTWAIT, MT_DATA);
- if (mnew == NULL) {
+ if (m_defrag(m0, M_DONTWAIT) != 0) {
m_freem(m0);
return ENOMEM;
}
- M_DUP_PKTHDR(mnew, m0);
- if (m0->m_pkthdr.len > MHLEN) {
- MCLGET(mnew, M_DONTWAIT);
- if (!(mnew->m_flags & M_EXT)) {
- m_freem(m0);
- m_freem(mnew);
- return ENOMEM;
- }
- }
-
- m_copydata(m0, 0, m0->m_pkthdr.len, mtod(mnew, caddr_t));
- m_freem(m0);
- mnew->m_len = mnew->m_pkthdr.len;
- m0 = mnew;
-
error = bus_dmamap_load_mbuf(sc->sc_dmat, data->map, m0,
BUS_DMA_NOWAIT);
if (error != 0) {
@@ -2551,7 +2533,6 @@ rt2560_read_eeprom(struct rt2560_softc *sc)
int
rt2560_bbp_init(struct rt2560_softc *sc)
{
-#define N(a) (sizeof (a) / sizeof ((a)[0]))
int i, ntries;
/* wait for BBP to be ready */
@@ -2566,7 +2547,7 @@ rt2560_bbp_init(struct rt2560_softc *sc)
}
/* initialize BBP registers to default values */
- for (i = 0; i < N(rt2560_def_bbp); i++) {
+ for (i = 0; i < nitems(rt2560_def_bbp); i++) {
rt2560_bbp_write(sc, rt2560_def_bbp[i].reg,
rt2560_def_bbp[i].val);
}
@@ -2580,13 +2561,11 @@ rt2560_bbp_init(struct rt2560_softc *sc)
#endif
return 0;
-#undef N
}
int
rt2560_init(struct ifnet *ifp)
{
-#define N(a) (sizeof (a) / sizeof ((a)[0]))
struct rt2560_softc *sc = ifp->if_softc;
struct ieee80211com *ic = &sc->sc_ic;
uint32_t tmp;
@@ -2624,7 +2603,7 @@ rt2560_init(struct ifnet *ifp)
RAL_WRITE(sc, RT2560_RXCSR2, sc->rxq.physaddr);
/* initialize MAC registers to default values */
- for (i = 0; i < N(rt2560_def_mac); i++)
+ for (i = 0; i < nitems(rt2560_def_mac); i++)
RAL_WRITE(sc, rt2560_def_mac[i].reg, rt2560_def_mac[i].val);
IEEE80211_ADDR_COPY(ic->ic_myaddr, LLADDR(ifp->if_sadl));
@@ -2683,7 +2662,6 @@ rt2560_init(struct ifnet *ifp)
ieee80211_new_state(ic, IEEE80211_S_SCAN, -1);
return 0;
-#undef N
}
void
diff --git a/sys/dev/ic/rt2661.c b/sys/dev/ic/rt2661.c
index a105b8f79f1..c22fd40b010 100644
--- a/sys/dev/ic/rt2661.c
+++ b/sys/dev/ic/rt2661.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rt2661.c,v 1.44 2008/08/27 09:05:03 damien Exp $ */
+/* $OpenBSD: rt2661.c,v 1.45 2008/11/25 21:43:57 damien Exp $ */
/*-
* Copyright (c) 2006
@@ -1546,7 +1546,6 @@ rt2661_tx_data(struct rt2661_softc *sc, struct mbuf *m0,
struct rt2661_tx_data *data;
struct ieee80211_frame *wh;
struct ieee80211_key *k;
- struct mbuf *mnew;
uint16_t dur;
uint32_t flags = 0;
int pktlen, rate, needcts = 0, needrts = 0, error;
@@ -1672,27 +1671,10 @@ rt2661_tx_data(struct rt2661_softc *sc, struct mbuf *m0,
}
if (error != 0) {
/* too many fragments, linearize */
-
- MGETHDR(mnew, M_DONTWAIT, MT_DATA);
- if (mnew == NULL) {
+ if (m_defrag(m0, M_DONTWAIT) != 0) {
m_freem(m0);
return ENOMEM;
}
- M_DUP_PKTHDR(mnew, m0);
- if (m0->m_pkthdr.len > MHLEN) {
- MCLGET(mnew, M_DONTWAIT);
- if (!(mnew->m_flags & M_EXT)) {
- m_freem(m0);
- m_freem(mnew);
- return ENOMEM;
- }
- }
-
- m_copydata(m0, 0, m0->m_pkthdr.len, mtod(mnew, caddr_t));
- m_freem(m0);
- mnew->m_len = mnew->m_pkthdr.len;
- m0 = mnew;
-
error = bus_dmamap_load_mbuf(sc->sc_dmat, data->map, m0,
BUS_DMA_NOWAIT);
if (error != 0) {
@@ -2387,7 +2369,6 @@ rt2661_read_eeprom(struct rt2661_softc *sc)
int
rt2661_bbp_init(struct rt2661_softc *sc)
{
-#define N(a) (sizeof (a) / sizeof ((a)[0]))
int i, ntries;
/* wait for BBP to be ready */
@@ -2403,7 +2384,7 @@ rt2661_bbp_init(struct rt2661_softc *sc)
}
/* initialize BBP registers to default values */
- for (i = 0; i < N(rt2661_def_bbp); i++) {
+ for (i = 0; i < nitems(rt2661_def_bbp); i++) {
rt2661_bbp_write(sc, rt2661_def_bbp[i].reg,
rt2661_def_bbp[i].val);
}
@@ -2416,13 +2397,11 @@ rt2661_bbp_init(struct rt2661_softc *sc)
}
return 0;
-#undef N
}
int
rt2661_init(struct ifnet *ifp)
{
-#define N(a) (sizeof (a) / sizeof ((a)[0]))
struct rt2661_softc *sc = ifp->if_softc;
struct ieee80211com *ic = &sc->sc_ic;
const char *name = NULL; /* make lint happy */
@@ -2515,7 +2494,7 @@ rt2661_init(struct ifnet *ifp)
RAL_WRITE(sc, RT2661_RX_CNTL_CSR, 2);
/* initialize MAC registers to default values */
- for (i = 0; i < N(rt2661_def_mac); i++)
+ for (i = 0; i < nitems(rt2661_def_mac); i++)
RAL_WRITE(sc, rt2661_def_mac[i].reg, rt2661_def_mac[i].val);
IEEE80211_ADDR_COPY(ic->ic_myaddr, LLADDR(ifp->if_sadl));
@@ -2566,7 +2545,7 @@ rt2661_init(struct ifnet *ifp)
RAL_WRITE(sc, RT2661_TXRX_CSR0, tmp);
/* clear STA registers */
- RAL_READ_REGION_4(sc, RT2661_STA_CSR0, sta, N(sta));
+ RAL_READ_REGION_4(sc, RT2661_STA_CSR0, sta, nitems(sta));
/* initialize ASIC */
RAL_WRITE(sc, RT2661_MAC_CSR1, 4);
@@ -2590,7 +2569,6 @@ rt2661_init(struct ifnet *ifp)
ieee80211_new_state(ic, IEEE80211_S_RUN, -1);
return 0;
-#undef N
}
void
diff --git a/sys/dev/ic/rt2860.c b/sys/dev/ic/rt2860.c
index c73bc281d6f..c8cc331dc2e 100644
--- a/sys/dev/ic/rt2860.c
+++ b/sys/dev/ic/rt2860.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rt2860.c,v 1.19 2008/08/27 09:05:03 damien Exp $ */
+/* $OpenBSD: rt2860.c,v 1.20 2008/11/25 21:43:57 damien Exp $ */
/*-
* Copyright (c) 2007,2008
@@ -170,7 +170,6 @@ static const struct rfprog {
int
rt2860_attach(void *xsc, int id)
{
-#define N(a) (sizeof (a) / sizeof ((a)[0]))
struct rt2860_softc *sc = xsc;
struct ieee80211com *ic = &sc->sc_ic;
struct ifnet *ifp = &ic->ic_if;
@@ -255,7 +254,7 @@ rt2860_attach(void *xsc, int id)
ieee80211_std_rateset_11a;
/* set supported .11a channels */
- for (i = 14; i < N(rt2860_rf2850); i++) {
+ for (i = 14; i < nitems(rt2860_rf2850); i++) {
uint8_t chan = rt2860_rf2850[i].chan;
ic->ic_channels[chan].ic_freq =
ieee80211_ieee2mhz(chan, IEEE80211_CHAN_5GHZ);
@@ -333,7 +332,6 @@ fail2: rt2860_free_rx_ring(sc, &sc->rxq);
fail1: while (--qid >= 0)
rt2860_free_tx_ring(sc, &sc->txq[qid]);
return error;
-#undef N
}
int
@@ -1488,27 +1486,10 @@ rt2860_tx_data(struct rt2860_softc *sc, struct mbuf *m0,
}
}
if (error != 0) { /* too many fragments, linearize */
- struct mbuf *m1;
-
- MGETHDR(m1, M_DONTWAIT, MT_DATA);
- if (m1 == NULL) {
+ if (m_defrag(m0, M_DONTWAIT) != 0) {
m_freem(m0);
return ENOMEM;
}
- M_DUP_PKTHDR(m1, m0);
- if (m0->m_pkthdr.len > MHLEN) {
- MCLGET(m1, M_DONTWAIT);
- if (!(m1->m_flags & M_EXT)) {
- m_freem(m0);
- m_freem(m1);
- return ENOMEM;
- }
- }
- m_copydata(m0, 0, m0->m_pkthdr.len, mtod(m1, caddr_t));
- m1->m_len = m1->m_pkthdr.len;
- m_freem(m0);
- m0 = m1;
-
error = bus_dmamap_load_mbuf(sc->sc_dmat, data->map, m0,
BUS_DMA_NOWAIT);
if (error != 0) {
@@ -2322,7 +2303,6 @@ rt2860_get_rf(uint8_t rev)
int
rt2860_read_eeprom(struct rt2860_softc *sc)
{
-#define N(a) (sizeof (a) / sizeof ((a)[0]))
struct ieee80211com *ic = &sc->sc_ic;
uint16_t val;
int8_t delta_2ghz, delta_5ghz;
@@ -2579,13 +2559,11 @@ rt2860_read_eeprom(struct rt2860_softc *sc)
}
return 0;
-#undef N
}
int
rt2860_bbp_init(struct rt2860_softc *sc)
{
-#define N(a) (sizeof (a) / sizeof ((a)[0]))
int i, ntries;
/* wait for BBP to wake up */
@@ -2601,7 +2579,7 @@ rt2860_bbp_init(struct rt2860_softc *sc)
}
/* initialize BBP registers to default values */
- for (i = 0; i < N(rt2860_def_bbp); i++) {
+ for (i = 0; i < nitems(rt2860_def_bbp); i++) {
rt2860_mcu_bbp_write(sc, rt2860_def_bbp[i].reg,
rt2860_def_bbp[i].val);
}
@@ -2613,13 +2591,11 @@ rt2860_bbp_init(struct rt2860_softc *sc)
}
return 0;
-#undef N
}
int
rt2860_init(struct ifnet *ifp)
{
-#define N(a) (sizeof (a) / sizeof ((a)[0]))
struct rt2860_softc *sc = ifp->if_softc;
struct ieee80211com *ic = &sc->sc_ic;
uint32_t tmp;
@@ -2693,7 +2669,7 @@ rt2860_init(struct ifnet *ifp)
RAL_WRITE(sc, RT2860_MAC_SYS_CTRL, RT2860_BBP_HRST | RT2860_MAC_SRST);
RAL_WRITE(sc, RT2860_MAC_SYS_CTRL, 0);
- for (i = 0; i < N(rt2860_def_mac); i++)
+ for (i = 0; i < nitems(rt2860_def_mac); i++)
RAL_WRITE(sc, rt2860_def_mac[i].reg, rt2860_def_mac[i].val);
/* wait while MAC is busy */
@@ -2857,7 +2833,6 @@ rt2860_init(struct ifnet *ifp)
ieee80211_new_state(ic, IEEE80211_S_RUN, -1);
return 0;
-#undef N
}
void
diff --git a/sys/dev/pci/if_ipw.c b/sys/dev/pci/if_ipw.c
index 52f30ff4c9d..3df6e44fd83 100644
--- a/sys/dev/pci/if_ipw.c
+++ b/sys/dev/pci/if_ipw.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ipw.c,v 1.80 2008/09/03 19:43:59 damien Exp $ */
+/* $OpenBSD: if_ipw.c,v 1.81 2008/11/25 21:43:57 damien Exp $ */
/*-
* Copyright (c) 2004-2008
@@ -610,7 +610,6 @@ ipw_media_change(struct ifnet *ifp)
void
ipw_media_status(struct ifnet *ifp, struct ifmediareq *imr)
{
-#define N(a) (sizeof (a) / sizeof (a[0]))
struct ipw_softc *sc = ifp->if_softc;
struct ieee80211com *ic = &sc->sc_ic;
static const struct {
@@ -635,8 +634,8 @@ ipw_media_status(struct ifnet *ifp, struct ifmediareq *imr)
val &= 0xf;
/* convert rate to 802.11 rate */
- for (i = 0; i < N(rates) && rates[i].val != val; i++);
- rate = (i < N(rates)) ? rates[i].rate : 0;
+ for (i = 0; i < nitems(rates) && rates[i].val != val; i++);
+ rate = (i < nitems(rates)) ? rates[i].rate : 0;
imr->ifm_active |= IFM_IEEE80211_11B;
imr->ifm_active |= ieee80211_rate2media(ic, rate, IEEE80211_MODE_11B);
@@ -655,7 +654,6 @@ ipw_media_status(struct ifnet *ifp, struct ifmediareq *imr)
/* should not get there */
break;
}
-#undef N
}
int
@@ -1132,7 +1130,6 @@ ipw_tx_start(struct ifnet *ifp, struct mbuf *m, struct ieee80211_node *ni)
struct ipw_soft_bd *sbd;
struct ipw_soft_hdr *shdr;
struct ipw_soft_buf *sbuf;
- struct mbuf *mnew;
int error, i;
wh = mtod(m, struct ieee80211_frame *);
@@ -1194,26 +1191,10 @@ ipw_tx_start(struct ifnet *ifp, struct mbuf *m, struct ieee80211_node *ni)
}
if (error != 0) {
/* too many fragments, linearize */
-
- MGETHDR(mnew, M_DONTWAIT, MT_DATA);
- if (mnew == NULL) {
+ if (m_defrag(m, M_DONTWAIT) != 0) {
m_freem(m);
return ENOMEM;
}
- M_DUP_PKTHDR(mnew, m);
- if (m->m_pkthdr.len > MHLEN) {
- MCLGET(mnew, M_DONTWAIT);
- if (!(mnew->m_flags & M_EXT)) {
- m_freem(m);
- m_freem(mnew);
- return ENOMEM;
- }
- }
- m_copydata(m, 0, m->m_pkthdr.len, mtod(mnew, caddr_t));
- m_freem(m);
- mnew->m_len = mnew->m_pkthdr.len;
- m = mnew;
-
error = bus_dmamap_load_mbuf(sc->sc_dmat, sbuf->map, m,
BUS_DMA_NOWAIT);
if (error != 0) {
diff --git a/sys/dev/pci/if_iwi.c b/sys/dev/pci/if_iwi.c
index 64dc8c74db1..69a826cfc92 100644
--- a/sys/dev/pci/if_iwi.c
+++ b/sys/dev/pci/if_iwi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_iwi.c,v 1.94 2008/09/04 15:59:52 damien Exp $ */
+/* $OpenBSD: if_iwi.c,v 1.95 2008/11/25 21:43:57 damien Exp $ */
/*-
* Copyright (c) 2004-2008
@@ -1236,7 +1236,6 @@ iwi_tx_start(struct ifnet *ifp, struct mbuf *m0, struct ieee80211_node *ni)
struct iwi_tx_data *data;
struct iwi_tx_desc *desc;
struct iwi_tx_ring *txq = &sc->txq[0];
- struct mbuf *mnew;
int hdrlen, error, i, station = 0;
wh = mtod(m0, struct ieee80211_frame *);
@@ -1300,27 +1299,10 @@ iwi_tx_start(struct ifnet *ifp, struct mbuf *m0, struct ieee80211_node *ni)
}
if (error != 0) {
/* too many fragments, linearize */
-
- MGETHDR(mnew, M_DONTWAIT, MT_DATA);
- if (mnew == NULL) {
+ if (m_defrag(m0, M_DONTWAIT) != 0) {
m_freem(m0);
return ENOMEM;
}
- M_DUP_PKTHDR(mnew, m0);
- if (m0->m_pkthdr.len > MHLEN) {
- MCLGET(mnew, M_DONTWAIT);
- if (!(mnew->m_flags & M_EXT)) {
- m_freem(m0);
- m_freem(mnew);
- return ENOMEM;
- }
- }
-
- m_copydata(m0, 0, m0->m_pkthdr.len, mtod(mnew, caddr_t));
- m_freem(m0);
- mnew->m_len = mnew->m_pkthdr.len;
- m0 = mnew;
-
error = bus_dmamap_load_mbuf(sc->sc_dmat, data->map, m0,
BUS_DMA_NOWAIT);
if (error != 0) {
diff --git a/sys/dev/pci/if_iwn.c b/sys/dev/pci/if_iwn.c
index e60825b5877..1933e9515ba 100644
--- a/sys/dev/pci/if_iwn.c
+++ b/sys/dev/pci/if_iwn.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_iwn.c,v 1.38 2008/11/25 17:06:27 damien Exp $ */
+/* $OpenBSD: if_iwn.c,v 1.39 2008/11/25 21:43:57 damien Exp $ */
/*-
* Copyright (c) 2007, 2008
@@ -2144,7 +2144,6 @@ iwn_wakeup_intr(struct iwn_softc *sc)
void
iwn_fatal_intr(struct iwn_softc *sc)
{
-#define N(a) (sizeof (a) / sizeof ((a)[0]))
const struct iwn_hal *hal = sc->sc_hal;
struct iwn_fw_dump dump;
int i;
@@ -2174,7 +2173,7 @@ iwn_fatal_intr(struct iwn_softc *sc)
}
printf("firmware error log:\n");
printf(" error type = \"%s\" (0x%08X)\n",
- (dump.id < N(iwn_fw_errmsg)) ?
+ (dump.id < nitems(iwn_fw_errmsg)) ?
iwn_fw_errmsg[dump.id] : "UNKNOWN",
dump.id);
printf(" program counter = 0x%08X\n", dump.pc);
@@ -2196,7 +2195,6 @@ iwn_fatal_intr(struct iwn_softc *sc)
}
printf(" rx ring: cur=%d\n", sc->rxq.cur);
printf(" 802.11 state %d\n", sc->sc_ic.ic_state);
-#undef N
}
int
@@ -2334,7 +2332,6 @@ iwn_tx(struct iwn_softc *sc, struct mbuf *m, struct ieee80211_node *ni)
struct ieee80211_frame *wh;
struct ieee80211_key *k = NULL;
enum ieee80211_edca_ac ac;
- struct mbuf *m1;
uint32_t flags;
uint16_t qos;
u_int hdrlen;
@@ -2549,24 +2546,10 @@ iwn_tx(struct iwn_softc *sc, struct mbuf *m, struct ieee80211_node *ni)
}
if (error != 0) {
/* Too many DMA segments, linearize mbuf. */
- MGETHDR(m1, M_DONTWAIT, MT_DATA);
- if (m1 == NULL) {
+ if (m_defrag(m, M_DONTWAIT) != 0) {
m_freem(m);
return ENOMEM;
}
- if (m->m_pkthdr.len > MHLEN) {
- MCLGET(m1, M_DONTWAIT);
- if (!(m1->m_flags & M_EXT)) {
- m_freem(m);
- m_freem(m1);
- return ENOMEM;
- }
- }
- m_copydata(m, 0, m->m_pkthdr.len, mtod(m1, caddr_t));
- m1->m_len = m1->m_pkthdr.len = m->m_pkthdr.len;
- m_freem(m);
- m = m1;
-
error = bus_dmamap_load_mbuf(sc->sc_dmat, data->map, m,
BUS_DMA_NOWAIT);
if (error != 0) {
diff --git a/sys/dev/pci/if_wpi.c b/sys/dev/pci/if_wpi.c
index 3cdbf8af0ed..730ae5d9ab3 100644
--- a/sys/dev/pci/if_wpi.c
+++ b/sys/dev/pci/if_wpi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_wpi.c,v 1.74 2008/11/25 17:06:26 damien Exp $ */
+/* $OpenBSD: if_wpi.c,v 1.75 2008/11/25 21:43:57 damien Exp $ */
/*-
* Copyright (c) 2006-2008
@@ -1675,7 +1675,6 @@ wpi_tx(struct wpi_softc *sc, struct mbuf *m, struct ieee80211_node *ni)
struct ieee80211_frame *wh;
struct ieee80211_key *k = NULL;
enum ieee80211_edca_ac ac;
- struct mbuf *m1;
uint32_t flags;
uint16_t qos;
u_int hdrlen;
@@ -1851,24 +1850,10 @@ wpi_tx(struct wpi_softc *sc, struct mbuf *m, struct ieee80211_node *ni)
}
if (error != 0) {
/* Too many DMA segments, linearize mbuf. */
- MGETHDR(m1, M_DONTWAIT, MT_DATA);
- if (m1 == NULL) {
+ if (m_defrag(m, M_DONTWAIT) != 0) {
m_freem(m);
return ENOMEM;
}
- if (m->m_pkthdr.len > MHLEN) {
- MCLGET(m1, M_DONTWAIT);
- if (!(m1->m_flags & M_EXT)) {
- m_freem(m);
- m_freem(m1);
- return ENOMEM;
- }
- }
- m_copydata(m, 0, m->m_pkthdr.len, mtod(m1, caddr_t));
- m1->m_len = m1->m_pkthdr.len = m->m_pkthdr.len;
- m_freem(m);
- m = m1;
-
error = bus_dmamap_load_mbuf(sc->sc_dmat, data->map, m,
BUS_DMA_NOWAIT);
if (error != 0) {