diff options
author | Damien Bergamini <damien@cvs.openbsd.org> | 2008-11-25 21:43:58 +0000 |
---|---|---|
committer | Damien Bergamini <damien@cvs.openbsd.org> | 2008-11-25 21:43:58 +0000 |
commit | d69871e8580da6ee2c3f62ac8cea87938e65dedc (patch) | |
tree | 8a81b4cb39645cdba8edecc1eb0226ecf4f04160 /sys/dev/ic | |
parent | b15ff47f94d82c81611a7806f710066b190b8ecb (diff) |
use shiny new m_defrag() and nitems() instead of rolling our own.
Diffstat (limited to 'sys/dev/ic')
-rw-r--r-- | sys/dev/ic/rt2560.c | 30 | ||||
-rw-r--r-- | sys/dev/ic/rt2661.c | 32 | ||||
-rw-r--r-- | sys/dev/ic/rt2860.c | 35 |
3 files changed, 14 insertions, 83 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 |