From owner-svn-src-all@freebsd.org Sun Aug 30 21:54:34 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A4DD39C6958; Sun, 30 Aug 2015 21:54:34 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 897C71C1A; Sun, 30 Aug 2015 21:54:34 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t7ULsYSm070456; Sun, 30 Aug 2015 21:54:34 GMT (envelope-from adrian@FreeBSD.org) Received: (from adrian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t7ULsXaT070453; Sun, 30 Aug 2015 21:54:33 GMT (envelope-from adrian@FreeBSD.org) Message-Id: <201508302154.t7ULsXaT070453@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: adrian set sender to adrian@FreeBSD.org using -f From: Adrian Chadd Date: Sun, 30 Aug 2015 21:54:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r287312 - head/sys/dev/iwn X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Aug 2015 21:54:34 -0000 Author: adrian Date: Sun Aug 30 21:54:33 2015 New Revision: 287312 URL: https://svnweb.freebsd.org/changeset/base/287312 Log: 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. Modified: head/sys/dev/iwn/if_iwn.c head/sys/dev/iwn/if_iwn_ioctl.h head/sys/dev/iwn/if_iwnvar.h Modified: head/sys/dev/iwn/if_iwn.c ============================================================================== --- head/sys/dev/iwn/if_iwn.c Sun Aug 30 20:59:19 2015 (r287311) +++ head/sys/dev/iwn/if_iwn.c Sun Aug 30 21:54:33 2015 (r287312) @@ -39,11 +39,13 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include #include #include +#include #include #include @@ -378,6 +380,19 @@ MODULE_DEPEND(iwn, firmware, 1, 1, 1); MODULE_DEPEND(iwn, pci, 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 iwn_probe(device_t dev) { @@ -704,6 +719,15 @@ iwn_attach(device_t dev) if (bootverbose) ieee80211_announce(ic); 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; fail: iwn_detach(dev); @@ -1416,6 +1440,11 @@ iwn_detach(device_t dev) bus_release_resource(dev, SYS_RES_MEMORY, 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__); IWN_LOCK_DESTROY(sc); return 0; @@ -4999,18 +5028,37 @@ iwn_watchdog(void *arg) } 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; - int error = 0; - + + return (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) { case SIOCGIWNSTATS: + d = (struct iwn_ioctl_data *) data; IWN_LOCK(sc); /* XXX validate permissions/memory/etc? */ - error = copyout(&sc->last_stat, ifr->ifr_data, - sizeof(struct iwn_stats)); + rc = copyout(&sc->last_stat, d->dst_addr, sizeof(struct iwn_stats)); IWN_UNLOCK(sc); break; case SIOCZIWNSTATS: @@ -5019,10 +5067,17 @@ iwn_ioctl(struct ieee80211com *ic, u_lon IWN_UNLOCK(sc); break; default: - error = ENOTTY; + rc = EINVAL; break; } - return (error); + return (rc); +} + +static int +iwn_ioctl(struct ieee80211com *ic, u_long cmd, void *data) +{ + + return (ENOTTY); } static void @@ -8979,3 +9034,5 @@ iwn_debug_register(struct iwn_softc *sc) DPRINTF(sc, IWN_DEBUG_REGISTER,"%s","\n"); } #endif + + Modified: head/sys/dev/iwn/if_iwn_ioctl.h ============================================================================== --- head/sys/dev/iwn/if_iwn_ioctl.h Sun Aug 30 20:59:19 2015 (r287311) +++ head/sys/dev/iwn/if_iwn_ioctl.h Sun Aug 30 21:54:33 2015 (r287312) @@ -18,8 +18,13 @@ #ifndef __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? */ -#define SIOCGIWNSTATS _IOWR('i', 145, struct ifreq) -#define SIOCZIWNSTATS _IOWR('i', 146, struct ifreq) +#define SIOCGIWNSTATS _IOWR('f', 145, struct iwn_ioctl_data) +#define SIOCZIWNSTATS _IOWR('f', 146, struct iwn_ioctl_data) #endif /* __IF_IWN_IOCTL_H__ */ Modified: head/sys/dev/iwn/if_iwnvar.h ============================================================================== --- head/sys/dev/iwn/if_iwnvar.h Sun Aug 30 20:59:19 2015 (r287311) +++ head/sys/dev/iwn/if_iwnvar.h Sun Aug 30 21:54:33 2015 (r287312) @@ -235,6 +235,7 @@ struct iwn_vap { struct iwn_softc { device_t sc_dev; int sc_debug; + struct cdev *sc_cdev; struct mtx sc_mtx; struct ieee80211com sc_ic; struct mbufq sc_snd;