/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2002-2009 Sam Leffler, Errno Consulting4* 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#ifndef __IF_ATH_TSF_H__31#define __IF_ATH_TSF_H__3233/*34* Extend 15-bit time stamp from rx descriptor to35* a full 64-bit TSF using the specified TSF.36*/37static __inline u_int64_t38ath_extend_tsf15(u_int32_t rstamp, u_int64_t tsf)39{40if ((tsf & 0x7fff) < rstamp)41tsf -= 0x8000;4243return ((tsf &~ 0x7fff) | rstamp);44}4546/*47* Extend 32-bit time stamp from rx descriptor to48* a full 64-bit TSF using the specified TSF.49*/50static __inline u_int64_t51ath_extend_tsf32(u_int32_t rstamp, u_int64_t tsf)52{53u_int32_t tsf_low = tsf & 0xffffffff;54u_int64_t tsf64 = (tsf & ~0xffffffffULL) | rstamp;5556if (rstamp > tsf_low && (rstamp - tsf_low > 0x10000000))57tsf64 -= 0x100000000ULL;5859if (rstamp < tsf_low && (tsf_low - rstamp > 0x10000000))60tsf64 += 0x100000000ULL;6162return tsf64;63}6465/*66* Extend the TSF from the RX descriptor to a full 64 bit TSF.67* Earlier hardware versions only wrote the low 15 bits of the68* TSF into the RX descriptor; later versions (AR5416 and up)69* include the 32 bit TSF value.70*/71static __inline u_int64_t72ath_extend_tsf(struct ath_softc *sc, u_int32_t rstamp, u_int64_t tsf)73{74if (sc->sc_rxtsf32)75return ath_extend_tsf32(rstamp, tsf);76else77return ath_extend_tsf15(rstamp, tsf);78}7980#endif818283