xref: /freebsd/sys/dev/axgbe/xgbe_osdep.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
17113afc8SEmmanuel Vadot /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
37113afc8SEmmanuel Vadot  *
47113afc8SEmmanuel Vadot  * Copyright (c) 2020 Advanced Micro Devices, Inc.
57113afc8SEmmanuel Vadot  *
67113afc8SEmmanuel Vadot  * Redistribution and use in source and binary forms, with or without
77113afc8SEmmanuel Vadot  * modification, are permitted provided that the following conditions
87113afc8SEmmanuel Vadot  * are met:
97113afc8SEmmanuel Vadot  * 1. Redistributions of source code must retain the above copyright
107113afc8SEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer.
117113afc8SEmmanuel Vadot  * 2. Redistributions in binary form must reproduce the above copyright
127113afc8SEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer in the
137113afc8SEmmanuel Vadot  *    documentation and/or other materials provided with the distribution.
147113afc8SEmmanuel Vadot  *
157113afc8SEmmanuel Vadot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
167113afc8SEmmanuel Vadot  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
177113afc8SEmmanuel Vadot  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
187113afc8SEmmanuel Vadot  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
197113afc8SEmmanuel Vadot  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
207113afc8SEmmanuel Vadot  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
217113afc8SEmmanuel Vadot  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
227113afc8SEmmanuel Vadot  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
237113afc8SEmmanuel Vadot  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
247113afc8SEmmanuel Vadot  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
257113afc8SEmmanuel Vadot  * SUCH DAMAGE.
267113afc8SEmmanuel Vadot  *
277113afc8SEmmanuel Vadot  * Contact Information :
287113afc8SEmmanuel Vadot  * Rajesh Kumar <rajesh1.kumar@amd.com>
297113afc8SEmmanuel Vadot  *
307113afc8SEmmanuel Vadot  */
317113afc8SEmmanuel Vadot 
327113afc8SEmmanuel Vadot #include <sys/cdefs.h>
337113afc8SEmmanuel Vadot #include "xgbe.h"
347113afc8SEmmanuel Vadot #include "xgbe_osdep.h"
357113afc8SEmmanuel Vadot 
367113afc8SEmmanuel Vadot /* Bit Reversal - http://aggregate.org/MAGIC/#Bit%20Reversal */
bitrev32(uint32_t x)377113afc8SEmmanuel Vadot uint32_t bitrev32(uint32_t x)
387113afc8SEmmanuel Vadot {
397113afc8SEmmanuel Vadot         x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
407113afc8SEmmanuel Vadot         x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
417113afc8SEmmanuel Vadot         x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));
427113afc8SEmmanuel Vadot         x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));
437113afc8SEmmanuel Vadot 
447113afc8SEmmanuel Vadot         return ((x >> 16) | (x << 16));
457113afc8SEmmanuel Vadot }
46