diff options
author | jhb <jhb@FreeBSD.org> | 2008-08-04 21:14:24 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2008-08-04 21:14:24 +0000 |
commit | 86456c4430d5918f4b6cc1b5e3e7c9bf70f74bd1 (patch) | |
tree | 66af55d001db1b8421e532f726830245c5ba9d43 /sys/dev/iicbus/icee.c | |
parent | 3b547d7c3ff7d40672c49c58d43eeea9f09423a4 (diff) | |
download | FreeBSD-src-86456c4430d5918f4b6cc1b5e3e7c9bf70f74bd1.zip FreeBSD-src-86456c4430d5918f4b6cc1b5e3e7c9bf70f74bd1.tar.gz |
Lock the consumers of the iicbus(4) infrastructure:
- ad7418(4) uses an sx lock instead of a mtx since the iicbus(4) stuff it
calls can sleep (request_bus()). Also, I expanded the locking slightly
to serialize writes to data stored in the softc.
- Similarly, the icee(4) driver now uses an sx lock instead of a mutex.
I also removed the pointless OPENED flag and flags field from the softc.
- The locking for the ic(4) driver was a bit trickier:
- Add a mutex to the softc to protect softc data.
- The driver uses malloc'd buffers that are the size of the interface
MTU to send and receive packets. Previously, these were allocated
every time the interface was brought up and anytime the MTU was
changed, with various races that could result in memory leaks. I
changed this to be a bit simpler and more like other NIC drivers in
that we allocate buffers during attach for the default MTU size and
only reallocate them on MTU changes. The reallocation procedure
goes to some lengths with various flags to not replace either the
the receive or transmit buffers while the driver is busy receiving
or transmitting a packet.
- Store the device_t of the driver in the softc instead of detours into
new-bus using if_dunit from the ifnet and an even more bizarre detour
to get the softc instead of using if_softc.
- Drop the driver mutex when invoking netisr_dispatch() to pass the
packet up to IP.
- Use if_printf().
Diffstat (limited to 'sys/dev/iicbus/icee.c')
-rw-r--r-- | sys/dev/iicbus/icee.c | 32 |
1 files changed, 9 insertions, 23 deletions
diff --git a/sys/dev/iicbus/icee.c b/sys/dev/iicbus/icee.c index 03de150..8e408d8 100644 --- a/sys/dev/iicbus/icee.c +++ b/sys/dev/iicbus/icee.c @@ -33,8 +33,8 @@ __FBSDID("$FreeBSD$"); #include <sys/conf.h> #include <sys/kernel.h> #include <sys/module.h> -#include <sys/mutex.h> #include <sys/resource.h> +#include <sys/sx.h> #include <sys/uio.h> #include <machine/bus.h> #include <dev/iicbus/iiconf.h> @@ -48,24 +48,21 @@ __FBSDID("$FreeBSD$"); struct icee_softc { device_t sc_dev; /* Myself */ - struct mtx sc_mtx; /* basically a perimeter lock */ + struct sx sc_lock; /* basically a perimeter lock */ struct cdev *cdev; /* user interface */ int addr; - int flags; -#define OPENED 1 int size; /* How big am I? */ int type; /* What type 8 or 16 bit? */ int rd_sz; /* What's the read page size */ int wr_sz; /* What's the write page size */ }; -#define ICEE_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) -#define ICEE_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) -#define ICEE_LOCK_INIT(_sc) \ - mtx_init(&_sc->sc_mtx, device_get_nameunit(_sc->sc_dev), "icee", MTX_DEF) -#define ICEE_LOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx); -#define ICEE_ASSERT_LOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_OWNED); -#define ICEE_ASSERT_UNLOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_NOTOWNED); +#define ICEE_LOCK(_sc) sx_xlock(&(_sc)->sc_lock) +#define ICEE_UNLOCK(_sc) sx_xunlock(&(_sc)->sc_lock) +#define ICEE_LOCK_INIT(_sc) sx_init(&_sc->sc_lock, "icee") +#define ICEE_LOCK_DESTROY(_sc) sx_destroy(&_sc->sc_lock); +#define ICEE_ASSERT_LOCKED(_sc) sx_assert(&_sc->sc_lock, SA_XLOCKED); +#define ICEE_ASSERT_UNLOCKED(_sc) sx_assert(&_sc->sc_lock, SA_UNLOCKED); #define CDEV2SOFTC(dev) ((dev)->si_drv1) /* cdev routines */ @@ -77,6 +74,7 @@ static d_write_t icee_write; static struct cdevsw icee_cdevsw = { .d_version = D_VERSION, + .d_flags = D_TRACKCLOSE, .d_open = icee_open, .d_close = icee_close, .d_read = icee_read, @@ -127,26 +125,14 @@ out:; static int icee_open(struct cdev *dev, int oflags, int devtype, struct thread *td) { - struct icee_softc *sc; - sc = CDEV2SOFTC(dev); - ICEE_LOCK(sc); - if (!(sc->flags & OPENED)) { - sc->flags |= OPENED; - } - ICEE_UNLOCK(sc); return (0); } static int icee_close(struct cdev *dev, int fflag, int devtype, struct thread *td) { - struct icee_softc *sc; - sc = CDEV2SOFTC(dev); - ICEE_LOCK(sc); - sc->flags &= ~OPENED; - ICEE_UNLOCK(sc); return (0); } |