PERFORCE change 163445 for review
Marius Strobl
marius at FreeBSD.org
Wed Jun 3 20:47:34 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=163445
Change 163445 by marius at flak on 2009/06/03 20:46:59
- As intended increase sc_txwin by number of TX descriptors actually
used instead of just by one.
- Add missing BUS_DMASYNC_PREREAD before returning RX descriptors to
the hardware but don't BUS_DMASYNC_POSTREAD if we're not going to
use it.
- Avoid recursive locking when cas_free() is called via m_freem(9)
from within this driver.
- Use MEXTADD(9) with M_RDONLY in order to avoid the kernel using
the mbuf for other purposes.
- Fix some minor nits.
Affected files ...
.. //depot/projects/usiii/dev/cas/if_cas.c#4 edit
.. //depot/projects/usiii/dev/cas/if_casreg.h#5 edit
.. //depot/projects/usiii/dev/cas/if_casvar.h#4 edit
Differences ...
==== //depot/projects/usiii/dev/cas/if_cas.c#4 (text+ko) ====
@@ -117,7 +117,7 @@
* According to documentation, the hardware has support for basic TCP
* checksum offloading only, in practice this can be also used for UDP
* however (i.e. the problem of previous Sun NICs that a checksum of 0x0
- * was not converted to 0xffff no longer exists).
+ * is not converted to 0xffff no longer exists).
*/
#define CAS_CSUM_FEATURES (CSUM_TCP | CSUM_UDP)
@@ -1238,7 +1238,7 @@
CTR3(KTR_CAS, "%s: start of frame at segment %d, TX %d",
__func__, seg, nexttx);
#endif
- if (++sc->sc_txwin > CAS_NTXSEGS * 2 / 3) {
+ if (sc->sc_txwin += nsegs > CAS_NTXSEGS * 2 / 3) {
sc->sc_txwin = 0;
sc->sc_txdescs[txs->txs_firstdesc].cd_flags |=
htole64(cflags | CAS_TD_START_OF_FRAME | CAS_TD_INT_ME);
@@ -1668,10 +1668,10 @@
#endif
rxds = &sc->sc_rxdsoft[idx];
MGETHDR(m, M_DONTWAIT, MT_DATA);
- bus_dmamap_sync(sc->sc_rdmatag, rxds->rxds_dmamap,
- BUS_DMASYNC_POSTREAD);
if (m != NULL) {
refcount_acquire(&rxds->rxds_refcount);
+ bus_dmamap_sync(sc->sc_rdmatag,
+ rxds->rxds_dmamap, BUS_DMASYNC_POSTREAD);
MEXTADD(m, (caddr_t)rxds->rxds_buf +
off * 256 + ETHER_ALIGN, len, cas_free,
#if __FreeBSD_version < 800016
@@ -1679,7 +1679,7 @@
#else
sc, (void *)(uintptr_t)idx,
#endif
- 0, EXT_NET_DRV);
+ M_RDONLY, EXT_NET_DRV);
if ((m->m_flags & M_EXT) == 0) {
m_freem(m);
m = NULL;
@@ -1711,12 +1711,12 @@
#endif
rxds = &sc->sc_rxdsoft[idx];
MGETHDR(m, M_DONTWAIT, MT_DATA);
- bus_dmamap_sync(sc->sc_rdmatag, rxds->rxds_dmamap,
- BUS_DMASYNC_POSTREAD);
if (m != NULL) {
refcount_acquire(&rxds->rxds_refcount);
off += ETHER_ALIGN;
m->m_len = min(CAS_PAGE_SIZE - off, len);
+ bus_dmamap_sync(sc->sc_rdmatag,
+ rxds->rxds_dmamap, BUS_DMASYNC_POSTREAD);
MEXTADD(m, (caddr_t)rxds->rxds_buf + off,
m->m_len, cas_free,
#if __FreeBSD_version < 800016
@@ -1724,7 +1724,7 @@
#else
sc, (void *)(uintptr_t)idx,
#endif
- 0, EXT_NET_DRV);
+ M_RDONLY, EXT_NET_DRV);
if ((m->m_flags & M_EXT) == 0) {
m_freem(m);
m = NULL;
@@ -1744,13 +1744,13 @@
#endif
rxds2 = &sc->sc_rxdsoft[idx2];
MGET(m2, M_DONTWAIT, MT_DATA);
- bus_dmamap_sync(sc->sc_rdmatag,
- rxds2->rxds_dmamap,
- BUS_DMASYNC_POSTREAD);
if (m2 != NULL) {
refcount_acquire(
&rxds2->rxds_refcount);
m2->m_len = len - m->m_len;
+ bus_dmamap_sync(sc->sc_rdmatag,
+ rxds2->rxds_dmamap,
+ BUS_DMASYNC_POSTREAD);
MEXTADD(m2, (caddr_t)rxds2->rxds_buf,
m2->m_len, cas_free,
#if __FreeBSD_version < 800016
@@ -1758,7 +1758,7 @@
#else
sc, (void *)(uintptr_t)idx2,
#endif
- 0, EXT_NET_DRV);
+ M_RDONLY, EXT_NET_DRV);
if ((m2->m_flags & M_EXT) == 0) {
m_freem(m2);
m2 = NULL;
@@ -1817,7 +1817,7 @@
{
struct cas_rxdsoft *rxds;
struct cas_softc *sc;
- u_int idx;
+ u_int idx, locked;
#if __FreeBSD_version < 800016
rxds = arg2;
@@ -1831,9 +1831,15 @@
if (refcount_release(&rxds->rxds_refcount) == 0)
return;
- CAS_LOCK(sc);
+ /*
+ * NB: this function can be called via m_freem(9) within
+ * this driver!
+ */
+ if ((locked = CAS_LOCK_OWNED(sc)) == 0)
+ CAS_LOCK(sc);
cas_add_rxdesc(sc, idx);
- CAS_UNLOCK(sc);
+ if (locked == 0)
+ CAS_UNLOCK(sc);
}
static inline void
@@ -1842,6 +1848,8 @@
CAS_LOCK_ASSERT(sc, MA_OWNED);
+ bus_dmamap_sync(sc->sc_rdmatag, sc->sc_rxdsoft[idx].rxds_dmamap,
+ BUS_DMASYNC_PREREAD);
CAS_UPDATE_RXDESC(sc, sc->sc_rxdptr, idx);
sc->sc_rxdptr = CAS_NEXTRXDESC(sc->sc_rxdptr);
==== //depot/projects/usiii/dev/cas/if_casreg.h#5 (text+ko) ====
@@ -3,7 +3,6 @@
* Copyright (c) 2008 Marius Strobl <marius at FreeBSD.org>
* All rights reserved.
*
- *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -26,7 +25,7 @@
* SUCH DAMAGE.
*
* from: NetBSD: gemreg.h,v 1.8 2005/12/11 12:21:26 christos Exp
- * from: FreeBSD: if_gemvar.h 174987 2007-12-30 01:32:03Z marius
+ * from: FreeBSD: if_gemreg.h 174987 2007-12-30 01:32:03Z marius
*
* $FreeBSD$
*/
@@ -39,7 +38,7 @@
* DP83065 Saturn Gigabit Ethernet controllers
*/
-/* glocal resources */
+/* global resources */
#define CAS_CAW 0x0004 /* core arbitration weight */
#define CAS_INF_BURST 0x0008 /* infinite burst enable */
#define CAS_STATUS 0x000c /* interrupt status */
@@ -420,7 +419,7 @@
#define CAS_RX_RED_10K_12K_MASK 0xff000000 /* 10K < FIFO threshold < 12K */
#define CAS_RX_RED_10K_12K_SHFT 24
-/* CAS_RX_FF_IPP_MASK and CAS_RX_FF_FIFO_MASK is in 8 bytes granularity. */
+/* CAS_RX_FF_IPP_MASK and CAS_RX_FF_FIFO_MASK are in 8 bytes granularity. */
#define CAS_RX_FF_PKT_MASK 0x000000ff /* # of packets in RX FIFO */
#define CAS_RX_FF_PKT_SHFT 0
#define CAS_RX_FF_IPP_MASK 0x0007ff00 /* IPP FIFO level */
@@ -828,8 +827,7 @@
#define CAS_PCS_CONF_JS_NORM 0x00000000 /* jitter study - normal op. */
#define CAS_PCS_CONF_JS_HF 0x00000008 /* jitter study - HF test */
#define CAS_PCS_CONF_JS_LF 0x00000010 /* jitter study - LF test */
-#define CAS_PCS_CONF_JS_MASK \
- (CAS_PCS_CONF_JS_HF | CAS_PCS_CONF_JS_LF)
+#define CAS_PCS_CONF_JS_MASK (CAS_PCS_CONF_JS_HF | CAS_PCS_CONF_JS_LF)
#define CAS_PCS_CONF_ANEG_TO 0x00000020 /* auto-neg. timer override */
#define CAS_PCS_SM_TX_CTRL_MASK 0x0000000f /* TX control state */
==== //depot/projects/usiii/dev/cas/if_casvar.h#4 (text+ko) ====
@@ -239,9 +239,8 @@
#if __FreeBSD_version < 800016
#define CAS_INIT_RXDESC(sc, d, s) \
do { \
- struct cas_rxdsoft *__rxds; \
+ struct cas_rxdsoft *__rxds = &(sc)->sc_rxdsoft[(s)]; \
\
- __rxds = &(sc)->sc_rxdsoft[(s)]; \
__rxds->rxds_sc = (sc); \
__rxds->rxds_idx = (s); \
__CAS_UPDATE_RXDESC(&(sc)->sc_rxdescs[(d)], __rxds, (s)); \
@@ -256,5 +255,6 @@
#define CAS_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
#define CAS_LOCK_ASSERT(_sc, _what) mtx_assert(&(_sc)->sc_mtx, (_what))
#define CAS_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_mtx)
+#define CAS_LOCK_OWNED(_sc) mtx_owned(&(_sc)->sc_mtx)
#endif
More information about the p4-projects
mailing list