Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Sep 2015 02:49:00 +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: r288088 - head/sys/dev/usb/wlan
Message-ID:  <201509220249.t8M2n0Br084040@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: adrian
Date: Tue Sep 22 02:48:59 2015
New Revision: 288088
URL: https://svnweb.freebsd.org/changeset/base/288088

Log:
  net80211 & wireless drivers: remove duplicate defines (noop)
  
  - IEEE80211_DIR_DSTODS(wh) -> IEEE80211_IS_DSTODS(wh).
  - N(a) -> nitems(a).
  - Remove LE_READ_2(p)/LE_READ_4(p) definitions (and include ieee80211_input.h instead).
  - <drvname>_TXOP_TO_US(txop) -> IEEE80211_TXOP_TO_US(txop).
  - Put IEEE80211_RV(v) into ieee80211_proto.h and remove local RV(v) definitions.
  
  Submitted by:   Andriy Voskoboinyk <s3erios@gmail.com>
  Differential Revision:  https://reviews.freebsd.org/D3705

Modified:
  head/sys/dev/usb/wlan/if_uath.c
  head/sys/dev/usb/wlan/if_uathvar.h
  head/sys/dev/usb/wlan/if_ural.c
  head/sys/dev/usb/wlan/if_urtw.c
  head/sys/dev/usb/wlan/if_urtwn.c
  head/sys/dev/usb/wlan/if_urtwnreg.h
  head/sys/dev/usb/wlan/if_zyd.c

Modified: head/sys/dev/usb/wlan/if_uath.c
==============================================================================
--- head/sys/dev/usb/wlan/if_uath.c	Tue Sep 22 02:44:59 2015	(r288087)
+++ head/sys/dev/usb/wlan/if_uath.c	Tue Sep 22 02:48:59 2015	(r288088)
@@ -102,6 +102,7 @@ __FBSDID("$FreeBSD$");
 #endif
 
 #include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_input.h>
 #include <net80211/ieee80211_regdomain.h>
 #include <net80211/ieee80211_radiotap.h>
 
@@ -156,15 +157,6 @@ enum {
 } while (0)
 #endif
 
-/* unaligned little endian access */
-#define LE_READ_2(p)							\
-	((u_int16_t)							\
-	 ((((u_int8_t *)(p))[0]      ) | (((u_int8_t *)(p))[1] <<  8)))
-#define LE_READ_4(p)							\
-	((u_int32_t)							\
-	 ((((u_int8_t *)(p))[0]      ) | (((u_int8_t *)(p))[1] <<  8) |	\
-	  (((u_int8_t *)(p))[2] << 16) | (((u_int8_t *)(p))[3] << 24)))
-
 /* recognized device vendors/products */
 static const STRUCT_USB_HOST_ID uath_devs[] = {
 #define	UATH_DEV(v,p) { USB_VP(USB_VENDOR_##v, USB_PRODUCT_##v##_##p) }
@@ -599,7 +591,6 @@ uath_dump_cmd(const uint8_t *buf, int le
 static const char *
 uath_codename(int code)
 {
-#define	N(a)	(sizeof(a)/sizeof(a[0]))
 	static const char *names[] = {
 	    "0x00",
 	    "HOST_AVAILABLE",
@@ -662,13 +653,12 @@ uath_codename(int code)
 	};
 	static char buf[8];
 
-	if (code < N(names))
+	if (code < nitems(names))
 		return names[code];
 	if (code == WDCMSG_SET_DEFAULT_KEY)
 		return "SET_DEFAULT_KEY";
 	snprintf(buf, sizeof(buf), "0x%02x", code);
 	return buf;
-#undef N
 }
 #endif
 
@@ -1486,7 +1476,7 @@ uath_wme_init(struct uath_softc *sc)
 		qinfo.attr.aifs		= htobe32(uath_wme_11g[ac].aifsn);
 		qinfo.attr.logcwmin	= htobe32(uath_wme_11g[ac].logcwmin);
 		qinfo.attr.logcwmax	= htobe32(uath_wme_11g[ac].logcwmax);
-		qinfo.attr.bursttime	= htobe32(UATH_TXOP_TO_US(
+		qinfo.attr.bursttime	= htobe32(IEEE80211_TXOP_TO_US(
 					    uath_wme_11g[ac].txop));
 		qinfo.attr.mode		= htobe32(uath_wme_11g[ac].acm);/*XXX? */
 		qinfo.attr.qflags	= htobe32(1);	/* XXX? */

Modified: head/sys/dev/usb/wlan/if_uathvar.h
==============================================================================
--- head/sys/dev/usb/wlan/if_uathvar.h	Tue Sep 22 02:44:59 2015	(r288087)
+++ head/sys/dev/usb/wlan/if_uathvar.h	Tue Sep 22 02:48:59 2015	(r288088)
@@ -102,7 +102,6 @@ struct uath_wme_settings {
 	uint8_t				logcwmin;
 	uint8_t				logcwmax;
 	uint16_t			txop;
-#define	UATH_TXOP_TO_US(txop)		((txop) << 5)
 	uint8_t				acm;
 };
 

Modified: head/sys/dev/usb/wlan/if_ural.c
==============================================================================
--- head/sys/dev/usb/wlan/if_ural.c	Tue Sep 22 02:44:59 2015	(r288087)
+++ head/sys/dev/usb/wlan/if_ural.c	Tue Sep 22 02:48:59 2015	(r288088)
@@ -1929,7 +1929,6 @@ ural_read_eeprom(struct ural_softc *sc)
 static int
 ural_bbp_init(struct ural_softc *sc)
 {
-#define N(a)	((int)(sizeof (a) / sizeof ((a)[0])))
 	int i, ntries;
 
 	/* wait for BBP to be ready */
@@ -1945,7 +1944,7 @@ ural_bbp_init(struct ural_softc *sc)
 	}
 
 	/* initialize BBP registers to default values */
-	for (i = 0; i < N(ural_def_bbp); i++)
+	for (i = 0; i < nitems(ural_def_bbp); i++)
 		ural_bbp_write(sc, ural_def_bbp[i].reg, ural_def_bbp[i].val);
 
 #if 0
@@ -1958,7 +1957,6 @@ ural_bbp_init(struct ural_softc *sc)
 #endif
 
 	return 0;
-#undef N
 }
 
 static void
@@ -2013,7 +2011,6 @@ ural_set_rxantenna(struct ural_softc *sc
 static void
 ural_init(struct ural_softc *sc)
 {
-#define N(a)	((int)(sizeof (a) / sizeof ((a)[0])))
 	struct ieee80211com *ic = &sc->sc_ic;
 	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
 	uint16_t tmp;
@@ -2027,7 +2024,7 @@ ural_init(struct ural_softc *sc)
 	ural_stop(sc);
 
 	/* initialize MAC registers to default values */
-	for (i = 0; i < N(ural_def_mac); i++)
+	for (i = 0; i < nitems(ural_def_mac); i++)
 		ural_write(sc, ural_def_mac[i].reg, ural_def_mac[i].val);
 
 	/* wait for BBP and RF to wake up (this can take a long time!) */
@@ -2086,7 +2083,6 @@ ural_init(struct ural_softc *sc)
 	return;
 
 fail:	ural_stop(sc);
-#undef N
 }
 
 static void

Modified: head/sys/dev/usb/wlan/if_urtw.c
==============================================================================
--- head/sys/dev/usb/wlan/if_urtw.c	Tue Sep 22 02:44:59 2015	(r288087)
+++ head/sys/dev/usb/wlan/if_urtw.c	Tue Sep 22 02:48:59 2015	(r288088)
@@ -1093,7 +1093,6 @@ fail:
 static usb_error_t
 urtw_adapter_start_b(struct urtw_softc *sc)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	uint8_t data8;
 	usb_error_t error;
 
@@ -1176,7 +1175,6 @@ urtw_adapter_start_b(struct urtw_softc *
 	urtw_write16_m(sc, 0x1ec, 0x800);	/* RX MAX SIZE */
 fail:
 	return (error);
-#undef N
 }
 
 static usb_error_t
@@ -1914,31 +1912,27 @@ fail:
 static uint16_t
 urtw_rate2rtl(uint32_t rate)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	int i;
 
-	for (i = 0; i < N(urtw_ratetable); i++) {
+	for (i = 0; i < nitems(urtw_ratetable); i++) {
 		if (rate == urtw_ratetable[i].reg)
 			return urtw_ratetable[i].val;
 	}
 
 	return (3);
-#undef N
 }
 
 static uint16_t
 urtw_rtl2rate(uint32_t rate)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	int i;
 
-	for (i = 0; i < N(urtw_ratetable); i++) {
+	for (i = 0; i < nitems(urtw_ratetable); i++) {
 		if (rate == urtw_ratetable[i].val)
 			return urtw_ratetable[i].reg;
 	}
 
 	return (0);
-#undef N
 }
 
 static usb_error_t
@@ -2458,7 +2452,6 @@ fail:
 static usb_error_t
 urtw_8225_rf_init(struct urtw_softc *sc)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	int i;
 	uint16_t data;
 	usb_error_t error;
@@ -2489,7 +2482,7 @@ urtw_8225_rf_init(struct urtw_softc *sc)
 		goto fail;
 	usb_pause_mtx(&sc->sc_mtx, 1000);
 
-	for (i = 0; i < N(urtw_8225_rf_part1); i++) {
+	for (i = 0; i < nitems(urtw_8225_rf_part1); i++) {
 		urtw_8225_write(sc, urtw_8225_rf_part1[i].reg,
 		    urtw_8225_rf_part1[i].val);
 		usb_pause_mtx(&sc->sc_mtx, 1);
@@ -2521,7 +2514,7 @@ urtw_8225_rf_init(struct urtw_softc *sc)
 		usb_pause_mtx(&sc->sc_mtx, 1);
 	}
 
-	for (i = 0; i < N(urtw_8225_rf_part2); i++) {
+	for (i = 0; i < nitems(urtw_8225_rf_part2); i++) {
 		urtw_8187_write_phy_ofdm(sc, urtw_8225_rf_part2[i].reg,
 		    urtw_8225_rf_part2[i].val);
 		usb_pause_mtx(&sc->sc_mtx, 1);
@@ -2531,7 +2524,7 @@ urtw_8225_rf_init(struct urtw_softc *sc)
 	if (error)
 		goto fail;
 
-	for (i = 0; i < N(urtw_8225_rf_part3); i++) {
+	for (i = 0; i < nitems(urtw_8225_rf_part3); i++) {
 		urtw_8187_write_phy_cck(sc, urtw_8225_rf_part3[i].reg,
 		    urtw_8225_rf_part3[i].val);
 		usb_pause_mtx(&sc->sc_mtx, 1);
@@ -2557,7 +2550,6 @@ urtw_8225_rf_init(struct urtw_softc *sc)
 	error = urtw_8225_rf_set_chan(sc, 1);
 fail:
 	return (error);
-#undef N
 }
 
 static usb_error_t
@@ -2841,7 +2833,6 @@ fail:
 static usb_error_t
 urtw_8225v2_rf_init(struct urtw_softc *sc)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	int i;
 	uint16_t data;
 	uint32_t data32;
@@ -2874,7 +2865,7 @@ urtw_8225v2_rf_init(struct urtw_softc *s
 
 	usb_pause_mtx(&sc->sc_mtx, 500);
 
-	for (i = 0; i < N(urtw_8225v2_rf_part1); i++) {
+	for (i = 0; i < nitems(urtw_8225v2_rf_part1); i++) {
 		urtw_8225_write(sc, urtw_8225v2_rf_part1[i].reg,
 		    urtw_8225v2_rf_part1[i].val);
 	}
@@ -2929,7 +2920,7 @@ urtw_8225v2_rf_init(struct urtw_softc *s
 		urtw_8187_write_phy_ofdm(sc, 0xa, (uint8_t)i + 0x80);
 	}
 
-	for (i = 0; i < N(urtw_8225v2_rf_part2); i++) {
+	for (i = 0; i < nitems(urtw_8225v2_rf_part2); i++) {
 		urtw_8187_write_phy_ofdm(sc, urtw_8225v2_rf_part2[i].reg,
 		    urtw_8225v2_rf_part2[i].val);
 	}
@@ -2938,7 +2929,7 @@ urtw_8225v2_rf_init(struct urtw_softc *s
 	if (error)
 		goto fail;
 
-	for (i = 0; i < N(urtw_8225v2_rf_part3); i++) {
+	for (i = 0; i < nitems(urtw_8225v2_rf_part3); i++) {
 		urtw_8187_write_phy_cck(sc, urtw_8225v2_rf_part3[i].reg,
 		    urtw_8225v2_rf_part3[i].val);
 	}
@@ -2961,7 +2952,6 @@ urtw_8225v2_rf_init(struct urtw_softc *s
 	error = urtw_8225_rf_set_chan(sc, 1);
 fail:
 	return (error);
-#undef N
 }
 
 static usb_error_t
@@ -3329,7 +3319,6 @@ urtw_8225v2b_rf_init(struct urtw_softc *
 
 fail:
 	return (error);
-#undef N
 }
 
 static usb_error_t

Modified: head/sys/dev/usb/wlan/if_urtwn.c
==============================================================================
--- head/sys/dev/usb/wlan/if_urtwn.c	Tue Sep 22 02:44:59 2015	(r288087)
+++ head/sys/dev/usb/wlan/if_urtwn.c	Tue Sep 22 02:48:59 2015	(r288088)
@@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$");
 #include <netinet/ip.h>
 
 #include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_input.h>
 #include <net80211/ieee80211_regdomain.h>
 #include <net80211/ieee80211_radiotap.h>
 #include <net80211/ieee80211_ratectl.h>
@@ -83,8 +84,7 @@ SYSCTL_INT(_hw_usb_urtwn, OID_AUTO, debu
 #endif
 
 #define	URTWN_RSSI(r)  (r) - 110
-#define	IEEE80211_HAS_ADDR4(wh)	\
-	(((wh)->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS)
+#define	IEEE80211_HAS_ADDR4(wh)	IEEE80211_IS_DSTODS(wh)
 
 /* various supported device vendors/products */
 static const STRUCT_USB_HOST_ID urtwn_devs[] = {

Modified: head/sys/dev/usb/wlan/if_urtwnreg.h
==============================================================================
--- head/sys/dev/usb/wlan/if_urtwnreg.h	Tue Sep 22 02:44:59 2015	(r288087)
+++ head/sys/dev/usb/wlan/if_urtwnreg.h	Tue Sep 22 02:48:59 2015	(r288088)
@@ -801,10 +801,6 @@
 #define R92C_RAID_11B	6
 
 
-/* Macros to access unaligned little-endian memory. */
-#define LE_READ_2(x)	((x)[0] | (x)[1] << 8)
-#define LE_READ_4(x)	((x)[0] | (x)[1] << 8 | (x)[2] << 16 | (x)[3] << 24)
-
 /*
  * Macros to access subfields in registers.
  */

Modified: head/sys/dev/usb/wlan/if_zyd.c
==============================================================================
--- head/sys/dev/usb/wlan/if_zyd.c	Tue Sep 22 02:44:59 2015	(r288087)
+++ head/sys/dev/usb/wlan/if_zyd.c	Tue Sep 22 02:48:59 2015	(r288088)
@@ -930,25 +930,23 @@ fail:
 static int
 zyd_rfmd_init(struct zyd_rf *rf)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	struct zyd_softc *sc = rf->rf_sc;
 	static const struct zyd_phy_pair phyini[] = ZYD_RFMD_PHY;
 	static const uint32_t rfini[] = ZYD_RFMD_RF;
 	int i, error;
 
 	/* init RF-dependent PHY registers */
-	for (i = 0; i < N(phyini); i++) {
+	for (i = 0; i < nitems(phyini); i++) {
 		zyd_write16_m(sc, phyini[i].reg, phyini[i].val);
 	}
 
 	/* init RFMD radio */
-	for (i = 0; i < N(rfini); i++) {
+	for (i = 0; i < nitems(rfini); i++) {
 		if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
 			return (error);
 	}
 fail:
 	return (error);
-#undef N
 }
 
 static int
@@ -989,7 +987,6 @@ fail:
 static int
 zyd_al2230_init(struct zyd_rf *rf)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	struct zyd_softc *sc = rf->rf_sc;
 	static const struct zyd_phy_pair phyini[] = ZYD_AL2230_PHY;
 	static const struct zyd_phy_pair phy2230s[] = ZYD_AL2230S_PHY_INIT;
@@ -1003,16 +1000,16 @@ zyd_al2230_init(struct zyd_rf *rf)
 	int i, error;
 
 	/* init RF-dependent PHY registers */
-	for (i = 0; i < N(phyini); i++)
+	for (i = 0; i < nitems(phyini); i++)
 		zyd_write16_m(sc, phyini[i].reg, phyini[i].val);
 
 	if (sc->sc_rfrev == ZYD_RF_AL2230S || sc->sc_al2230s != 0) {
-		for (i = 0; i < N(phy2230s); i++)
+		for (i = 0; i < nitems(phy2230s); i++)
 			zyd_write16_m(sc, phy2230s[i].reg, phy2230s[i].val);
 	}
 
 	/* init AL2230 radio */
-	for (i = 0; i < N(rfini1); i++) {
+	for (i = 0; i < nitems(rfini1); i++) {
 		error = zyd_rfwrite(sc, rfini1[i]);
 		if (error != 0)
 			goto fail;
@@ -1025,34 +1022,32 @@ zyd_al2230_init(struct zyd_rf *rf)
 	if (error != 0)
 		goto fail;
 
-	for (i = 0; i < N(rfini2); i++) {
+	for (i = 0; i < nitems(rfini2); i++) {
 		error = zyd_rfwrite(sc, rfini2[i]);
 		if (error != 0)
 			goto fail;
 	}
 
-	for (i = 0; i < N(phypll); i++)
+	for (i = 0; i < nitems(phypll); i++)
 		zyd_write16_m(sc, phypll[i].reg, phypll[i].val);
 
-	for (i = 0; i < N(rfini3); i++) {
+	for (i = 0; i < nitems(rfini3); i++) {
 		error = zyd_rfwrite(sc, rfini3[i]);
 		if (error != 0)
 			goto fail;
 	}
 fail:
 	return (error);
-#undef N
 }
 
 static int
 zyd_al2230_fini(struct zyd_rf *rf)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	int error, i;
 	struct zyd_softc *sc = rf->rf_sc;
 	static const struct zyd_phy_pair phy[] = ZYD_AL2230_PHY_FINI_PART1;
 
-	for (i = 0; i < N(phy); i++)
+	for (i = 0; i < nitems(phy); i++)
 		zyd_write16_m(sc, phy[i].reg, phy[i].val);
 
 	if (sc->sc_newphy != 0)
@@ -1061,13 +1056,11 @@ zyd_al2230_fini(struct zyd_rf *rf)
 	zyd_write16_m(sc, ZYD_CR203, 0x6);
 fail:
 	return (error);
-#undef N
 }
 
 static int
 zyd_al2230_init_b(struct zyd_rf *rf)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	struct zyd_softc *sc = rf->rf_sc;
 	static const struct zyd_phy_pair phy1[] = ZYD_AL2230_PHY_PART1;
 	static const struct zyd_phy_pair phy2[] = ZYD_AL2230_PHY_PART2;
@@ -1080,15 +1073,15 @@ zyd_al2230_init_b(struct zyd_rf *rf)
 	static const uint32_t zyd_al2230_chtable[][3] = ZYD_AL2230_CHANTABLE;
 	int i, error;
 
-	for (i = 0; i < N(phy1); i++)
+	for (i = 0; i < nitems(phy1); i++)
 		zyd_write16_m(sc, phy1[i].reg, phy1[i].val);
 
 	/* init RF-dependent PHY registers */
-	for (i = 0; i < N(phyini); i++)
+	for (i = 0; i < nitems(phyini); i++)
 		zyd_write16_m(sc, phyini[i].reg, phyini[i].val);
 
 	if (sc->sc_rfrev == ZYD_RF_AL2230S || sc->sc_al2230s != 0) {
-		for (i = 0; i < N(phy2230s); i++)
+		for (i = 0; i < nitems(phy2230s); i++)
 			zyd_write16_m(sc, phy2230s[i].reg, phy2230s[i].val);
 	}
 
@@ -1098,7 +1091,7 @@ zyd_al2230_init_b(struct zyd_rf *rf)
 			return (error);
 	}
 
-	for (i = 0; i < N(rfini_part1); i++) {
+	for (i = 0; i < nitems(rfini_part1); i++) {
 		error = zyd_rfwrite_cr(sc, rfini_part1[i]);
 		if (error != 0)
 			return (error);
@@ -1111,28 +1104,27 @@ zyd_al2230_init_b(struct zyd_rf *rf)
 	if (error != 0)
 		goto fail;
 
-	for (i = 0; i < N(rfini_part2); i++) {
+	for (i = 0; i < nitems(rfini_part2); i++) {
 		error = zyd_rfwrite_cr(sc, rfini_part2[i]);
 		if (error != 0)
 			return (error);
 	}
 
-	for (i = 0; i < N(phy2); i++)
+	for (i = 0; i < nitems(phy2); i++)
 		zyd_write16_m(sc, phy2[i].reg, phy2[i].val);
 
-	for (i = 0; i < N(rfini_part3); i++) {
+	for (i = 0; i < nitems(rfini_part3); i++) {
 		error = zyd_rfwrite_cr(sc, rfini_part3[i]);
 		if (error != 0)
 			return (error);
 	}
 
-	for (i = 0; i < N(phy3); i++)
+	for (i = 0; i < nitems(phy3); i++)
 		zyd_write16_m(sc, phy3[i].reg, phy3[i].val);
 
 	error = zyd_al2230_fini(rf);
 fail:
 	return (error);
-#undef N
 }
 
 static int
@@ -1150,7 +1142,6 @@ fail:
 static int
 zyd_al2230_set_channel(struct zyd_rf *rf, uint8_t chan)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	int error, i;
 	struct zyd_softc *sc = rf->rf_sc;
 	static const struct zyd_phy_pair phy1[] = {
@@ -1170,17 +1161,15 @@ zyd_al2230_set_channel(struct zyd_rf *rf
 	if (error != 0)
 		goto fail;
 
-	for (i = 0; i < N(phy1); i++)
+	for (i = 0; i < nitems(phy1); i++)
 		zyd_write16_m(sc, phy1[i].reg, phy1[i].val);
 fail:
 	return (error);
-#undef N
 }
 
 static int
 zyd_al2230_set_channel_b(struct zyd_rf *rf, uint8_t chan)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	int error, i;
 	struct zyd_softc *sc = rf->rf_sc;
 	static const struct zyd_phy_pair phy1[] = ZYD_AL2230_PHY_PART1;
@@ -1188,7 +1177,7 @@ zyd_al2230_set_channel_b(struct zyd_rf *
 		uint32_t	r1, r2, r3;
 	} rfprog[] = ZYD_AL2230_CHANTABLE_B;
 
-	for (i = 0; i < N(phy1); i++)
+	for (i = 0; i < nitems(phy1); i++)
 		zyd_write16_m(sc, phy1[i].reg, phy1[i].val);
 
 	error = zyd_rfwrite_cr(sc, rfprog[chan - 1].r1);
@@ -1203,7 +1192,6 @@ zyd_al2230_set_channel_b(struct zyd_rf *
 	error = zyd_al2230_fini(rf);
 fail:
 	return (error);
-#undef N
 }
 
 #define	ZYD_AL2230_PHY_BANDEDGE6					\
@@ -1215,7 +1203,6 @@ fail:
 static int
 zyd_al2230_bandedge6(struct zyd_rf *rf, struct ieee80211_channel *c)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	int error = 0, i;
 	struct zyd_softc *sc = rf->rf_sc;
 	struct ieee80211com *ic = &sc->sc_ic;
@@ -1225,11 +1212,10 @@ zyd_al2230_bandedge6(struct zyd_rf *rf, 
 	if (chan == 1 || chan == 11)
 		r[0].val = 0x12;
 	
-	for (i = 0; i < N(r); i++)
+	for (i = 0; i < nitems(r); i++)
 		zyd_write16_m(sc, r[i].reg, r[i].val);
 fail:
 	return (error);
-#undef N
 }
 
 /*
@@ -1238,7 +1224,6 @@ fail:
 static int
 zyd_al7230B_init(struct zyd_rf *rf)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	struct zyd_softc *sc = rf->rf_sc;
 	static const struct zyd_phy_pair phyini_1[] = ZYD_AL7230B_PHY_1;
 	static const struct zyd_phy_pair phyini_2[] = ZYD_AL7230B_PHY_2;
@@ -1250,29 +1235,28 @@ zyd_al7230B_init(struct zyd_rf *rf)
 	/* for AL7230B, PHY and RF need to be initialized in "phases" */
 
 	/* init RF-dependent PHY registers, part one */
-	for (i = 0; i < N(phyini_1); i++)
+	for (i = 0; i < nitems(phyini_1); i++)
 		zyd_write16_m(sc, phyini_1[i].reg, phyini_1[i].val);
 
 	/* init AL7230B radio, part one */
-	for (i = 0; i < N(rfini_1); i++) {
+	for (i = 0; i < nitems(rfini_1); i++) {
 		if ((error = zyd_rfwrite(sc, rfini_1[i])) != 0)
 			return (error);
 	}
 	/* init RF-dependent PHY registers, part two */
-	for (i = 0; i < N(phyini_2); i++)
+	for (i = 0; i < nitems(phyini_2); i++)
 		zyd_write16_m(sc, phyini_2[i].reg, phyini_2[i].val);
 
 	/* init AL7230B radio, part two */
-	for (i = 0; i < N(rfini_2); i++) {
+	for (i = 0; i < nitems(rfini_2); i++) {
 		if ((error = zyd_rfwrite(sc, rfini_2[i])) != 0)
 			return (error);
 	}
 	/* init RF-dependent PHY registers, part three */
-	for (i = 0; i < N(phyini_3); i++)
+	for (i = 0; i < nitems(phyini_3); i++)
 		zyd_write16_m(sc, phyini_3[i].reg, phyini_3[i].val);
 fail:
 	return (error);
-#undef N
 }
 
 static int
@@ -1290,7 +1274,6 @@ fail:
 static int
 zyd_al7230B_set_channel(struct zyd_rf *rf, uint8_t chan)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	struct zyd_softc *sc = rf->rf_sc;
 	static const struct {
 		uint32_t	r1, r2;
@@ -1301,7 +1284,7 @@ zyd_al7230B_set_channel(struct zyd_rf *r
 	zyd_write16_m(sc, ZYD_CR240, 0x57);
 	zyd_write16_m(sc, ZYD_CR251, 0x2f);
 
-	for (i = 0; i < N(rfsc); i++) {
+	for (i = 0; i < nitems(rfsc); i++) {
 		if ((error = zyd_rfwrite(sc, rfsc[i])) != 0)
 			return (error);
 	}
@@ -1327,7 +1310,6 @@ zyd_al7230B_set_channel(struct zyd_rf *r
 	zyd_write16_m(sc, ZYD_CR240, 0x08);
 fail:
 	return (error);
-#undef N
 }
 
 /*
@@ -1336,7 +1318,6 @@ fail:
 static int
 zyd_al2210_init(struct zyd_rf *rf)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	struct zyd_softc *sc = rf->rf_sc;
 	static const struct zyd_phy_pair phyini[] = ZYD_AL2210_PHY;
 	static const uint32_t rfini[] = ZYD_AL2210_RF;
@@ -1346,11 +1327,11 @@ zyd_al2210_init(struct zyd_rf *rf)
 	zyd_write32_m(sc, ZYD_CR18, 2);
 
 	/* init RF-dependent PHY registers */
-	for (i = 0; i < N(phyini); i++)
+	for (i = 0; i < nitems(phyini); i++)
 		zyd_write16_m(sc, phyini[i].reg, phyini[i].val);
 
 	/* init AL2210 radio */
-	for (i = 0; i < N(rfini); i++) {
+	for (i = 0; i < nitems(rfini); i++) {
 		if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
 			return (error);
 	}
@@ -1364,7 +1345,6 @@ zyd_al2210_init(struct zyd_rf *rf)
 	zyd_write32_m(sc, ZYD_CR18, 3);
 fail:
 	return (error);
-#undef N
 }
 
 static int
@@ -1409,7 +1389,6 @@ static int
 zyd_gct_init(struct zyd_rf *rf)
 {
 #define	ZYD_GCT_INTR_REG	0x85c1
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	struct zyd_softc *sc = rf->rf_sc;
 	static const struct zyd_phy_pair phyini[] = ZYD_GCT_PHY;
 	static const uint32_t rfini[] = ZYD_GCT_RF;
@@ -1418,11 +1397,11 @@ zyd_gct_init(struct zyd_rf *rf)
 	uint16_t data;
 
 	/* init RF-dependent PHY registers */
-	for (i = 0; i < N(phyini); i++)
+	for (i = 0; i < nitems(phyini); i++)
 		zyd_write16_m(sc, phyini[i].reg, phyini[i].val);
 
 	/* init cgt radio */
-	for (i = 0; i < N(rfini); i++) {
+	for (i = 0; i < nitems(rfini); i++) {
 		if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
 			return (error);
 	}
@@ -1431,7 +1410,7 @@ zyd_gct_init(struct zyd_rf *rf)
 	if (error != 0)
 		return (error);
 
-	for (i = 0; i < (int)(N(vco) - 1); i++) {
+	for (i = 0; i < (int)(nitems(vco) - 1); i++) {
 		error = zyd_gct_set_channel_synth(rf, 1, 0);
 		if (error != 0)
 			goto fail;
@@ -1458,26 +1437,23 @@ zyd_gct_init(struct zyd_rf *rf)
 	zyd_write16_m(sc, ZYD_CR203, 0x6);
 fail:
 	return (error);
-#undef N
 #undef ZYD_GCT_INTR_REG
 }
 
 static int
 zyd_gct_mode(struct zyd_rf *rf)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	struct zyd_softc *sc = rf->rf_sc;
 	static const uint32_t mode[] = {
 		0x25f98, 0x25f9a, 0x25f94, 0x27fd4
 	};
 	int i, error;
 
-	for (i = 0; i < N(mode); i++) {
+	for (i = 0; i < nitems(mode); i++) {
 		if ((error = zyd_rfwrite(sc, mode[i])) != 0)
 			break;
 	}
 	return (error);
-#undef N
 }
 
 static int
@@ -1524,7 +1500,6 @@ fail:
 static int
 zyd_gct_set_channel(struct zyd_rf *rf, uint8_t chan)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	int error, i;
 	struct zyd_softc *sc = rf->rf_sc;
 	static const struct zyd_phy_pair cmd[] = {
@@ -1543,7 +1518,7 @@ zyd_gct_set_channel(struct zyd_rf *rf, u
 	error = zyd_gct_mode(rf);
 	if (error != 0)
 		return (error);
-	for (i = 0; i < N(cmd); i++)
+	for (i = 0; i < nitems(cmd); i++)
 		zyd_write16_m(sc, cmd[i].reg, cmd[i].val);
 	error = zyd_gct_txgain(rf, chan);
 	if (error != 0)
@@ -1551,25 +1526,22 @@ zyd_gct_set_channel(struct zyd_rf *rf, u
 	zyd_write16_m(sc, ZYD_CR203, 0x6);
 fail:
 	return (error);
-#undef N
 }
 
 static int
 zyd_gct_txgain(struct zyd_rf *rf, uint8_t chan)
 {
-#define N(a)	(sizeof(a) / sizeof((a)[0]))
 	struct zyd_softc *sc = rf->rf_sc;
 	static uint32_t txgain[] = ZYD_GCT_TXGAIN;
 	uint8_t idx = sc->sc_pwrint[chan - 1];
 
-	if (idx >= N(txgain)) {
+	if (idx >= nitems(txgain)) {
 		device_printf(sc->sc_dev, "could not set TX gain (%d %#x)\n",
 		    chan, idx);
 		return 0;
 	}
 
 	return zyd_rfwrite(sc, 0x700000 | txgain[idx]);
-#undef N
 }
 
 /*
@@ -1578,7 +1550,6 @@ zyd_gct_txgain(struct zyd_rf *rf, uint8_
 static int
 zyd_maxim2_init(struct zyd_rf *rf)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	struct zyd_softc *sc = rf->rf_sc;
 	static const struct zyd_phy_pair phyini[] = ZYD_MAXIM2_PHY;
 	static const uint32_t rfini[] = ZYD_MAXIM2_RF;
@@ -1586,14 +1557,14 @@ zyd_maxim2_init(struct zyd_rf *rf)
 	int i, error;
 
 	/* init RF-dependent PHY registers */
-	for (i = 0; i < N(phyini); i++)
+	for (i = 0; i < nitems(phyini); i++)
 		zyd_write16_m(sc, phyini[i].reg, phyini[i].val);
 
 	zyd_read16_m(sc, ZYD_CR203, &tmp);
 	zyd_write16_m(sc, ZYD_CR203, tmp & ~(1 << 4));
 
 	/* init maxim2 radio */
-	for (i = 0; i < N(rfini); i++) {
+	for (i = 0; i < nitems(rfini); i++) {
 		if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
 			return (error);
 	}
@@ -1601,7 +1572,6 @@ zyd_maxim2_init(struct zyd_rf *rf)
 	zyd_write16_m(sc, ZYD_CR203, tmp | (1 << 4));
 fail:
 	return (error);
-#undef N
 }
 
 static int
@@ -1615,7 +1585,6 @@ zyd_maxim2_switch_radio(struct zyd_rf *r
 static int
 zyd_maxim2_set_channel(struct zyd_rf *rf, uint8_t chan)
 {
-#define N(a)	((int)(sizeof(a) / sizeof((a)[0])))
 	struct zyd_softc *sc = rf->rf_sc;
 	static const struct zyd_phy_pair phyini[] = ZYD_MAXIM2_PHY;
 	static const uint32_t rfini[] = ZYD_MAXIM2_RF;
@@ -1631,7 +1600,7 @@ zyd_maxim2_set_channel(struct zyd_rf *rf
 	 */
 
 	/* init RF-dependent PHY registers */
-	for (i = 0; i < N(phyini); i++)
+	for (i = 0; i < nitems(phyini); i++)
 		zyd_write16_m(sc, phyini[i].reg, phyini[i].val);
 
 	zyd_read16_m(sc, ZYD_CR203, &tmp);
@@ -1646,7 +1615,7 @@ zyd_maxim2_set_channel(struct zyd_rf *rf
 		goto fail;
 
 	/* init maxim2 radio - skipping the two first values */
-	for (i = 2; i < N(rfini); i++) {
+	for (i = 2; i < nitems(rfini); i++) {
 		if ((error = zyd_rfwrite(sc, rfini[i])) != 0)
 			return (error);
 	}
@@ -1654,7 +1623,6 @@ zyd_maxim2_set_channel(struct zyd_rf *rf
 	zyd_write16_m(sc, ZYD_CR203, tmp | (1 << 4));
 fail:
 	return (error);
-#undef N
 }
 
 static int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201509220249.t8M2n0Br084040>