net80211: reuse TICKS_2_MSEC / MSEC_2_TICKS macros from sys/time.h

Replace in-place implementation with system-wide one; since it
guarantees non-zero result drop all less-than-one checks from
drivers and net80211.

MFC after:	2 weeks
This commit is contained in:
Andriy Voskoboinyk 2019-01-25 01:05:18 +00:00
parent 60315f8f9d
commit 9df9e9361c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=343417
8 changed files with 13 additions and 31 deletions

View File

@ -118,6 +118,6 @@ rtwn_pci_delay(struct rtwn_softc *sc, int usec)
DELAY(usec);
else {
(void) mtx_sleep(sc, &sc->sc_mtx, 0, "rtwn_pci",
MAX(msecs_to_ticks(usec / 1000), 1));
msecs_to_ticks(usec / 1000));
}
}

View File

@ -172,8 +172,6 @@ rtwn_usb_delay(struct rtwn_softc *sc, int usec)
/* 1ms delay as default is too big. */
if (usec < 1000)
DELAY(usec);
else {
usb_pause_mtx(&sc->sc_mtx,
MAX(msecs_to_ticks(usec / 1000), 1));
}
else
usb_pause_mtx(&sc->sc_mtx, msecs_to_ticks(usec / 1000));
}

View File

@ -102,15 +102,13 @@ static void
amrr_setinterval(const struct ieee80211vap *vap, int msecs)
{
struct ieee80211_amrr *amrr = vap->iv_rs;
int t;
if (!amrr)
return;
if (msecs < 100)
msecs = 100;
t = msecs_to_ticks(msecs);
amrr->amrr_interval = (t < 1) ? 1 : t;
amrr->amrr_interval = msecs_to_ticks(msecs);
}
static void

View File

@ -136,13 +136,12 @@ int
ieee80211_sysctl_msecs_ticks(SYSCTL_HANDLER_ARGS)
{
int msecs = ticks_to_msecs(*(int *)arg1);
int error, t;
int error;
error = sysctl_handle_int(oidp, &msecs, 0, req);
if (error || !req->newptr)
return error;
t = msecs_to_ticks(msecs);
*(int *)arg1 = (t < 1) ? 1 : t;
*(int *)arg1 = msecs_to_ticks(msecs);
return 0;
}
@ -347,9 +346,6 @@ ieee80211_com_vdetach(struct ieee80211vap *vap)
int sleep_time;
sleep_time = msecs_to_ticks(250);
if (sleep_time == 0)
sleep_time = 1;
atomic_set_32(&vap->iv_com_state, IEEE80211_COM_DETACHED);
while (MS(atomic_load_32(&vap->iv_com_state), IEEE80211_COM_REF) != 0)
pause("comref", sleep_time);

View File

@ -38,6 +38,7 @@
#include <sys/rwlock.h>
#include <sys/sysctl.h>
#include <sys/taskqueue.h>
#include <sys/time.h>
/*
* Common state locking definitions.
@ -249,9 +250,8 @@ void ieee80211_vap_destroy(struct ieee80211vap *);
(((_ifp)->if_flags & IFF_UP) && \
((_ifp)->if_drv_flags & IFF_DRV_RUNNING))
/* XXX TODO: cap these at 1, as hz may not be 1000 */
#define msecs_to_ticks(ms) (((ms)*hz)/1000)
#define ticks_to_msecs(t) (1000*(t) / hz)
#define msecs_to_ticks(ms) MSEC_2_TICKS(ms)
#define ticks_to_msecs(t) TICKS_2_MSEC(t)
#define ticks_to_secs(t) ((t) / hz)
#define ieee80211_time_after(a,b) ((long)(b) - (long)(a) < 0)

View File

@ -2515,20 +2515,12 @@ ieee80211_scanreq(struct ieee80211vap *vap, struct ieee80211_scan_req *sr)
sr->sr_duration > IEEE80211_IOC_SCAN_DURATION_MAX)
return EINVAL;
sr->sr_duration = msecs_to_ticks(sr->sr_duration);
if (sr->sr_duration < 1)
sr->sr_duration = 1;
}
/* convert min/max channel dwell */
if (sr->sr_mindwell != 0) {
if (sr->sr_mindwell != 0)
sr->sr_mindwell = msecs_to_ticks(sr->sr_mindwell);
if (sr->sr_mindwell < 1)
sr->sr_mindwell = 1;
}
if (sr->sr_maxdwell != 0) {
if (sr->sr_maxdwell != 0)
sr->sr_maxdwell = msecs_to_ticks(sr->sr_maxdwell);
if (sr->sr_maxdwell < 1)
sr->sr_maxdwell = 1;
}
/* NB: silently reduce ssid count to what is supported */
if (sr->sr_nssid > IEEE80211_SCAN_MAX_SSID)
sr->sr_nssid = IEEE80211_SCAN_MAX_SSID;

View File

@ -117,15 +117,13 @@ static void
rssadapt_setinterval(const struct ieee80211vap *vap, int msecs)
{
struct ieee80211_rssadapt *rs = vap->iv_rs;
int t;
if (!rs)
return;
if (msecs < 100)
msecs = 100;
t = msecs_to_ticks(msecs);
rs->interval = (t < 1) ? 1 : t;
rs->interval = msecs_to_ticks(msecs);
}
static void

View File

@ -294,7 +294,7 @@ ieee80211_scan_dump(struct ieee80211_scan_state *ss)
if_printf(vap->iv_ifp, "scan set ");
ieee80211_scan_dump_channels(ss);
printf(" dwell min %lums max %lums\n",
printf(" dwell min %ums max %ums\n",
ticks_to_msecs(ss->ss_mindwell), ticks_to_msecs(ss->ss_maxdwell));
}
#endif /* IEEE80211_DEBUG */