1192890Sedwin/*- 2192890Sedwin * SPDX-License-Identifier: BSD-2-Clause 3192890Sedwin * 4192890Sedwin * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting 5192890Sedwin * All rights reserved. 630829Scharnier * 730829Scharnier * Redistribution and use in source and binary forms, with or without 850479Speter * modification, are permitted provided that the following conditions 9198831Sedwin * are met: 1030829Scharnier * 1. Redistributions of source code must retain the above copyright 1130829Scharnier * notice, this list of conditions and the following disclaimer, 122702Swollman * without modification. 132702Swollman * 2. Redistributions in binary form must reproduce at minimum a disclaimer 142702Swollman * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 152702Swollman * redistribution must be conditioned upon including a substantially 162702Swollman * similar Disclaimer requirement for further binary redistribution. 172702Swollman * 1830829Scharnier * NO WARRANTY 1930829Scharnier * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2030829Scharnier * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2130829Scharnier * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 2230829Scharnier * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 2330829Scharnier * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 2430829Scharnier * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25192625Sedwin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26192625Sedwin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 27192625Sedwin * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28192625Sedwin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 29192625Sedwin * THE POSSIBILITY OF SUCH DAMAGES. 302702Swollman */ 31192625Sedwin#ifndef __IF_ATH_TSF_H__ 32192625Sedwin#define __IF_ATH_TSF_H__ 33192625Sedwin 34192625Sedwin/* 35192625Sedwin * Extend 15-bit time stamp from rx descriptor to 36192625Sedwin * a full 64-bit TSF using the specified TSF. 37192625Sedwin */ 38192625Sedwinstatic __inline u_int64_t 392702Swollmanath_extend_tsf15(u_int32_t rstamp, u_int64_t tsf) 402702Swollman{ 412702Swollman if ((tsf & 0x7fff) < rstamp) 422702Swollman tsf -= 0x8000; 432702Swollman 442702Swollman return ((tsf &~ 0x7fff) | rstamp); 452702Swollman} 462702Swollman 472702Swollman/* 482702Swollman * Extend 32-bit time stamp from rx descriptor to 492702Swollman * a full 64-bit TSF using the specified TSF. 502702Swollman */ 512702Swollmanstatic __inline u_int64_t 522702Swollmanath_extend_tsf32(u_int32_t rstamp, u_int64_t tsf) 532702Swollman{ 542702Swollman u_int32_t tsf_low = tsf & 0xffffffff; 552702Swollman u_int64_t tsf64 = (tsf & ~0xffffffffULL) | rstamp; 562702Swollman 572702Swollman if (rstamp > tsf_low && (rstamp - tsf_low > 0x10000000)) 582702Swollman tsf64 -= 0x100000000ULL; 592702Swollman 602702Swollman if (rstamp < tsf_low && (tsf_low - rstamp > 0x10000000)) 612702Swollman tsf64 += 0x100000000ULL; 622702Swollman 632702Swollman return tsf64; 642702Swollman} 652702Swollman 662702Swollman/* 672702Swollman * Extend the TSF from the RX descriptor to a full 64 bit TSF. 682702Swollman * Earlier hardware versions only wrote the low 15 bits of the 692702Swollman * TSF into the RX descriptor; later versions (AR5416 and up) 702702Swollman * include the 32 bit TSF value. 712702Swollman */ 722702Swollmanstatic __inline u_int64_t 732702Swollmanath_extend_tsf(struct ath_softc *sc, u_int32_t rstamp, u_int64_t tsf) 742702Swollman{ 752702Swollman if (sc->sc_rxtsf32) 762702Swollman return ath_extend_tsf32(rstamp, tsf); 772702Swollman else 782702Swollman return ath_extend_tsf15(rstamp, tsf); 792702Swollman} 802702Swollman 812702Swollman#endif 822702Swollman