Date: Tue, 12 May 2020 02:20:27 +0000 (UTC) From: Adrian Chadd <adrian@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r360953 - in head/sys: contrib/dev/ath/ath_hal/ar9300 dev/ath/ath_hal Message-ID: <202005120220.04C2KRWW022682@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: adrian Date: Tue May 12 02:20:27 2020 New Revision: 360953 URL: https://svnweb.freebsd.org/changeset/base/360953 Log: [ath_hal] [ath_hal_ar9300] Fix endian macros to work in and out of kernel tree. Yes, people shouldn't use bitfields in C for structure parsing. If someone ever wants a cleanup task then it'd be great to remove them from this vendor code and other places in the ar9285/ar9287 HALs. Alas, here we are. AH_BYTE_ORDER wasn't defined and neither were the two values it could be. So when compiling ath_ee_print_9300 it'd default to the big endian struct layout and get a WHOLE lot of stuff wrong. So: * move AH_BYTE_ORDER into ath_hal/ah.h where it can be used by everyone. * ensure that AH_BYTE_ORDER is actually defined before using it! This should work on both big and little endian platforms. Modified: head/sys/contrib/dev/ath/ath_hal/ar9300/ar9300.h head/sys/contrib/dev/ath/ath_hal/ar9300/ar9300eep.h head/sys/dev/ath/ath_hal/ah.h Modified: head/sys/contrib/dev/ath/ath_hal/ar9300/ar9300.h ============================================================================== --- head/sys/contrib/dev/ath/ath_hal/ar9300/ar9300.h Tue May 12 01:47:33 2020 (r360952) +++ head/sys/contrib/dev/ath/ath_hal/ar9300/ar9300.h Tue May 12 02:20:27 2020 (r360953) @@ -19,18 +19,14 @@ #include "ar9300_freebsd_inc.h" -#define AH_BIG_ENDIAN 4321 -#define AH_LITTLE_ENDIAN 1234 - -#if _BYTE_ORDER == _BIG_ENDIAN -#define AH_BYTE_ORDER AH_BIG_ENDIAN -#else -#define AH_BYTE_ORDER AH_LITTLE_ENDIAN -#endif - /* XXX doesn't belong here */ #define AR_EEPROM_MODAL_SPURS 5 +/* Ensure that AH_BYTE_ORDER is defined */ +#ifndef AH_BYTE_ORDER +#error AH_BYTE_ORDER needs to be defined! +#endif + /* * (a) this should be N(a), * (b) FreeBSD does define nitems, @@ -43,9 +39,7 @@ #include "ah_devid.h" #include "ar9300eep.h" /* For Eeprom definitions */ - #define AR9300_MAGIC 0x19741014 - /* MAC register values */ Modified: head/sys/contrib/dev/ath/ath_hal/ar9300/ar9300eep.h ============================================================================== --- head/sys/contrib/dev/ath/ath_hal/ar9300/ar9300eep.h Tue May 12 01:47:33 2020 (r360952) +++ head/sys/contrib/dev/ath/ath_hal/ar9300/ar9300eep.h Tue May 12 02:20:27 2020 (r360953) @@ -18,13 +18,17 @@ #define _ATH_AR9300_EEP_H_ #include "opt_ah.h" - #include "ah.h" #if defined(WIN32) || defined(WIN64) #pragma pack (push, ar9300, 1) #endif +/* Ensure that AH_BYTE_ORDER is defined */ +#ifndef AH_BYTE_ORDER +#error AH_BYTE_ORDER needs to be defined! +#endif + /* FreeBSD extras - should be in ah_eeprom.h ? */ #define AR_EEPROM_EEPCAP_COMPRESS_DIS 0x0001 #define AR_EEPROM_EEPCAP_AES_DIS 0x0002 @@ -345,11 +349,13 @@ typedef struct CalCtlEdgePwr { u_int8_t flag :2, t_power :6; } __packed CAL_CTL_EDGE_PWR; -#else +#elif AH_BYTE_ORDER == AH_LITTLE_ENDIAN typedef struct CalCtlEdgePwr { u_int8_t t_power :6, flag :2; } __packed CAL_CTL_EDGE_PWR; +#else +#error AH_BYTE_ORDER undefined! #endif typedef struct ospCalCtlData_5G { Modified: head/sys/dev/ath/ath_hal/ah.h ============================================================================== --- head/sys/dev/ath/ath_hal/ah.h Tue May 12 01:47:33 2020 (r360952) +++ head/sys/dev/ath/ath_hal/ah.h Tue May 12 02:20:27 2020 (r360953) @@ -33,6 +33,18 @@ #include "ah_osdep.h" /* + * Endianness macros; used by various structures and code. + */ +#define AH_BIG_ENDIAN 4321 +#define AH_LITTLE_ENDIAN 1234 + +#if _BYTE_ORDER == _BIG_ENDIAN +#define AH_BYTE_ORDER AH_BIG_ENDIAN +#else +#define AH_BYTE_ORDER AH_LITTLE_ENDIAN +#endif + +/* * The maximum number of TX/RX chains supported. * This is intended to be used by various statistics gathering operations * (NF, RSSI, EVM).
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005120220.04C2KRWW022682>