Path: blob/main/sys/dev/ath/ath_dfs/null/dfs_null.c
39586 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2011 Adrian Chadd, Xenion Pty Ltd4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer,11* without modification.12* 2. Redistributions in binary form must reproduce at minimum a disclaimer13* similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any14* redistribution must be conditioned upon including a substantially15* similar Disclaimer requirement for further binary redistribution.16*17* NO WARRANTY18* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20* LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY21* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL22* THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,23* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF24* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS25* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER26* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)27* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF28* THE POSSIBILITY OF SUCH DAMAGES.29*/30#include <sys/cdefs.h>31/*32* This implements an empty DFS module.33*/34#include "opt_ath.h"35#include "opt_inet.h"36#include "opt_wlan.h"3738#include <sys/param.h>39#include <sys/systm.h>40#include <sys/sysctl.h>41#include <sys/kernel.h>42#include <sys/lock.h>43#include <sys/malloc.h>44#include <sys/mutex.h>45#include <sys/errno.h>4647#include <machine/bus.h>48#include <machine/resource.h>49#include <sys/bus.h>5051#include <sys/socket.h>5253#include <net/if.h>54#include <net/if_var.h>55#include <net/if_media.h>56#include <net/if_arp.h>57#include <net/ethernet.h> /* XXX for ether_sprintf */5859#include <net80211/ieee80211_var.h>6061#include <net/bpf.h>6263#ifdef INET64#include <netinet/in.h>65#include <netinet/if_ether.h>66#endif6768#include <dev/ath/if_athvar.h>69#include <dev/ath/if_athdfs.h>7071#include <dev/ath/ath_hal/ah_desc.h>7273/*74* Methods which are required75*/7677/*78* Attach DFS to the given interface79*/80int81ath_dfs_attach(struct ath_softc *sc)82{83return (1);84}8586/*87* Detach DFS from the given interface88*/89int90ath_dfs_detach(struct ath_softc *sc)91{92return (1);93}9495/*96* Enable radar check. Return 1 if the driver should97* enable radar PHY errors, or 0 if not.98*/99int100ath_dfs_radar_enable(struct ath_softc *sc, struct ieee80211_channel *chan)101{102#if 1103HAL_PHYERR_PARAM pe;104105/* Check if the hardware supports radar reporting */106/* XXX TODO: migrate HAL_CAP_RADAR/HAL_CAP_AR to somewhere public! */107if (ath_hal_getcapability(sc->sc_ah,108HAL_CAP_PHYDIAG, 0, NULL) != HAL_OK)109return (0);110111/* Check if the current channel is radar-enabled */112if (! IEEE80211_IS_CHAN_DFS(chan))113return (0);114115/* Fetch the default parameters */116memset(&pe, '\0', sizeof(pe));117if (! ath_hal_getdfsdefaultthresh(sc->sc_ah, &pe))118return (0);119120/* Enable radar PHY error reporting */121sc->sc_dodfs = 1;122123/* Tell the hardware to enable radar reporting */124pe.pe_enabled = 1;125126/* Flip on extension channel events only if doing HT40 */127if (IEEE80211_IS_CHAN_HT40(chan))128pe.pe_extchannel = 1;129else130pe.pe_extchannel = 0;131132ath_hal_enabledfs(sc->sc_ah, &pe);133134/*135* Disable strong signal fast diversity - needed for136* AR5212 and similar PHYs for reliable short pulse137* duration.138*/139(void) ath_hal_setcapability(sc->sc_ah, HAL_CAP_DIVERSITY, 2, 0, NULL);140141return (1);142#else143return (0);144#endif145}146147/*148* Explicity disable radar reporting.149*150* Return 0 if it was disabled, < 0 on error.151*/152int153ath_dfs_radar_disable(struct ath_softc *sc)154{155#if 1156HAL_PHYERR_PARAM pe;157158(void) ath_hal_getdfsthresh(sc->sc_ah, &pe);159pe.pe_enabled = 0;160(void) ath_hal_enabledfs(sc->sc_ah, &pe);161return (0);162#else163return (0);164#endif165}166167/*168* Process DFS related PHY errors169*170* The mbuf is not "ours" and if we want a copy, we have171* to take a copy. It'll be freed after this function returns.172*/173void174ath_dfs_process_phy_err(struct ath_softc *sc, struct mbuf *m,175uint64_t tsf, struct ath_rx_status *rxstat)176{177178}179180/*181* Process the radar events and determine whether a DFS event has occurred.182*183* This is designed to run outside of the RX processing path.184* The RX path will call ath_dfs_tasklet_needed() to see whether185* the task/callback running this routine needs to be called.186*/187int188ath_dfs_process_radar_event(struct ath_softc *sc,189struct ieee80211_channel *chan)190{191return (0);192}193194/*195* Determine whether the DFS check task needs to be queued.196*197* This is called in the RX task when the current batch of packets198* have been received. It will return whether there are any radar199* events for ath_dfs_process_radar_event() to handle.200*/201int202ath_dfs_tasklet_needed(struct ath_softc *sc, struct ieee80211_channel *chan)203{204return (0);205}206207/*208* Handle ioctl requests from the diagnostic interface.209*210* The initial part of this code resembles ath_ioctl_diag();211* it's likely a good idea to reduce duplication between212* these two routines.213*/214int215ath_ioctl_phyerr(struct ath_softc *sc, struct ath_diag *ad)216{217unsigned int id = ad->ad_id & ATH_DIAG_ID;218void *indata = NULL;219void *outdata = NULL;220u_int32_t insize = ad->ad_in_size;221u_int32_t outsize = ad->ad_out_size;222int error = 0;223HAL_PHYERR_PARAM peout;224HAL_PHYERR_PARAM *pe;225226if (ad->ad_id & ATH_DIAG_IN) {227/*228* Copy in data.229*/230indata = malloc(insize, M_TEMP, M_NOWAIT);231if (indata == NULL) {232error = ENOMEM;233goto bad;234}235error = copyin(ad->ad_in_data, indata, insize);236if (error)237goto bad;238}239if (ad->ad_id & ATH_DIAG_DYN) {240/*241* Allocate a buffer for the results (otherwise the HAL242* returns a pointer to a buffer where we can read the243* results). Note that we depend on the HAL leaving this244* pointer for us to use below in reclaiming the buffer;245* may want to be more defensive.246*/247outdata = malloc(outsize, M_TEMP, M_NOWAIT);248if (outdata == NULL) {249error = ENOMEM;250goto bad;251}252}253switch (id) {254case DFS_SET_THRESH:255if (insize < sizeof(HAL_PHYERR_PARAM)) {256error = EINVAL;257break;258}259pe = (HAL_PHYERR_PARAM *) indata;260ath_hal_enabledfs(sc->sc_ah, pe);261break;262case DFS_GET_THRESH:263memset(&peout, 0, sizeof(peout));264outsize = sizeof(HAL_PHYERR_PARAM);265ath_hal_getdfsthresh(sc->sc_ah, &peout);266pe = (HAL_PHYERR_PARAM *) outdata;267memcpy(pe, &peout, sizeof(*pe));268break;269default:270error = EINVAL;271}272if (outsize < ad->ad_out_size)273ad->ad_out_size = outsize;274if (outdata && copyout(outdata, ad->ad_out_data, ad->ad_out_size))275error = EFAULT;276bad:277if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)278free(indata, M_TEMP);279if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)280free(outdata, M_TEMP);281return (error);282}283284/*285* Get the current DFS thresholds from the HAL286*/287int288ath_dfs_get_thresholds(struct ath_softc *sc, HAL_PHYERR_PARAM *param)289{290ath_hal_getdfsthresh(sc->sc_ah, param);291return (1);292}293294295