Migrate the stats API for iwn(4) into a cdev ioctl, rather than tying

into the vap.

This allows for possible hardware interaction without needing a vap
configured.
This commit is contained in:
Adrian Chadd 2015-08-30 21:54:33 +00:00
parent 61b38905ce
commit 4823a7500b
3 changed files with 74 additions and 11 deletions

View File

@ -39,11 +39,13 @@ __FBSDID("$FreeBSD$");
#include <sys/systm.h> #include <sys/systm.h>
#include <sys/malloc.h> #include <sys/malloc.h>
#include <sys/bus.h> #include <sys/bus.h>
#include <sys/conf.h>
#include <sys/rman.h> #include <sys/rman.h>
#include <sys/endian.h> #include <sys/endian.h>
#include <sys/firmware.h> #include <sys/firmware.h>
#include <sys/limits.h> #include <sys/limits.h>
#include <sys/module.h> #include <sys/module.h>
#include <sys/priv.h>
#include <sys/queue.h> #include <sys/queue.h>
#include <sys/taskqueue.h> #include <sys/taskqueue.h>
@ -378,6 +380,19 @@ MODULE_DEPEND(iwn, firmware, 1, 1, 1);
MODULE_DEPEND(iwn, pci, 1, 1, 1); MODULE_DEPEND(iwn, pci, 1, 1, 1);
MODULE_DEPEND(iwn, wlan, 1, 1, 1); MODULE_DEPEND(iwn, wlan, 1, 1, 1);
static d_ioctl_t iwn_cdev_ioctl;
static d_open_t iwn_cdev_open;
static d_close_t iwn_cdev_close;
static struct cdevsw iwn_cdevsw = {
.d_version = D_VERSION,
.d_flags = 0,
.d_open = iwn_cdev_open,
.d_close = iwn_cdev_close,
.d_ioctl = iwn_cdev_ioctl,
.d_name = "iwn",
};
static int static int
iwn_probe(device_t dev) iwn_probe(device_t dev)
{ {
@ -704,6 +719,15 @@ iwn_attach(device_t dev)
if (bootverbose) if (bootverbose)
ieee80211_announce(ic); ieee80211_announce(ic);
DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__); DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);
/* Add debug ioctl right at the end */
sc->sc_cdev = make_dev(&iwn_cdevsw, device_get_unit(dev),
UID_ROOT, GID_WHEEL, 0600, "%s", device_get_nameunit(dev));
if (sc->sc_cdev == NULL) {
device_printf(dev, "failed to create debug character device\n");
} else {
sc->sc_cdev->si_drv1 = sc;
}
return 0; return 0;
fail: fail:
iwn_detach(dev); iwn_detach(dev);
@ -1416,6 +1440,11 @@ iwn_detach(device_t dev)
bus_release_resource(dev, SYS_RES_MEMORY, bus_release_resource(dev, SYS_RES_MEMORY,
rman_get_rid(sc->mem), sc->mem); rman_get_rid(sc->mem), sc->mem);
if (sc->sc_cdev) {
destroy_dev(sc->sc_cdev);
sc->sc_cdev = NULL;
}
DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n", __func__); DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n", __func__);
IWN_LOCK_DESTROY(sc); IWN_LOCK_DESTROY(sc);
return 0; return 0;
@ -4999,18 +5028,37 @@ iwn_watchdog(void *arg)
} }
static int static int
iwn_ioctl(struct ieee80211com *ic, u_long cmd, void *data) iwn_cdev_open(struct cdev *dev, int flags, int type, struct thread *td)
{ {
struct ifreq *ifr = data;
struct iwn_softc *sc = ic->ic_softc; return (0);
int error = 0; }
static int
iwn_cdev_close(struct cdev *dev, int flags, int type, struct thread *td)
{
return (0);
}
static int
iwn_cdev_ioctl(struct cdev *dev, unsigned long cmd, caddr_t data, int fflag,
struct thread *td)
{
int rc;
struct iwn_softc *sc = dev->si_drv1;
struct iwn_ioctl_data *d;
rc = priv_check(td, PRIV_DRIVER);
if (rc != 0)
return (0);
switch (cmd) { switch (cmd) {
case SIOCGIWNSTATS: case SIOCGIWNSTATS:
d = (struct iwn_ioctl_data *) data;
IWN_LOCK(sc); IWN_LOCK(sc);
/* XXX validate permissions/memory/etc? */ /* XXX validate permissions/memory/etc? */
error = copyout(&sc->last_stat, ifr->ifr_data, rc = copyout(&sc->last_stat, d->dst_addr, sizeof(struct iwn_stats));
sizeof(struct iwn_stats));
IWN_UNLOCK(sc); IWN_UNLOCK(sc);
break; break;
case SIOCZIWNSTATS: case SIOCZIWNSTATS:
@ -5019,10 +5067,17 @@ iwn_ioctl(struct ieee80211com *ic, u_long cmd, void *data)
IWN_UNLOCK(sc); IWN_UNLOCK(sc);
break; break;
default: default:
error = ENOTTY; rc = EINVAL;
break; break;
} }
return (error); return (rc);
}
static int
iwn_ioctl(struct ieee80211com *ic, u_long cmd, void *data)
{
return (ENOTTY);
} }
static void static void
@ -8979,3 +9034,5 @@ iwn_debug_register(struct iwn_softc *sc)
DPRINTF(sc, IWN_DEBUG_REGISTER,"%s","\n"); DPRINTF(sc, IWN_DEBUG_REGISTER,"%s","\n");
} }
#endif #endif

View File

@ -18,8 +18,13 @@
#ifndef __IF_IWN_IOCTL_H__ #ifndef __IF_IWN_IOCTL_H__
#define __IF_IWN_IOCTL_H__ #define __IF_IWN_IOCTL_H__
struct iwn_ioctl_data {
void *dst_addr;
int dst_len;
};
/* XXX how should I pick appropriate ioctl numbers? */ /* XXX how should I pick appropriate ioctl numbers? */
#define SIOCGIWNSTATS _IOWR('i', 145, struct ifreq) #define SIOCGIWNSTATS _IOWR('f', 145, struct iwn_ioctl_data)
#define SIOCZIWNSTATS _IOWR('i', 146, struct ifreq) #define SIOCZIWNSTATS _IOWR('f', 146, struct iwn_ioctl_data)
#endif /* __IF_IWN_IOCTL_H__ */ #endif /* __IF_IWN_IOCTL_H__ */

View File

@ -235,6 +235,7 @@ struct iwn_vap {
struct iwn_softc { struct iwn_softc {
device_t sc_dev; device_t sc_dev;
int sc_debug; int sc_debug;
struct cdev *sc_cdev;
struct mtx sc_mtx; struct mtx sc_mtx;
struct ieee80211com sc_ic; struct ieee80211com sc_ic;
struct mbufq sc_snd; struct mbufq sc_snd;