From 1739e9d7c5d581c15d1ae331d83352f8998a6a83 Mon Sep 17 00:00:00 2001 From: Christian Lamparter Date: Sat, 23 Nov 2013 14:52:14 +0100 Subject: [PATCH 1/1] carl9170: rename radar pattern generator into pattern generator Radar has become sort of a "buzzword" for DFS. This patch will hopefully help to avoid any confusion about the topic. Signed-off-by: Christian Lamparter --- carlfw/Kconfig | 2 +- carlfw/include/carl9170.h | 8 +- carlfw/include/fwdsc.h | 6 +- carlfw/include/pattern_generator.h | 14 +-- carlfw/src/fw.c | 17 ++-- carlfw/src/main.c | 2 +- carlfw/src/pattern_generator.c | 32 +++--- include/pattern.h | 156 +++++++++++++++++++++++++++++ include/shared/fwdesc.h | 29 +++--- tools/src/fwinfo.c | 20 ++-- tools/src/fwprepare.c | 46 ++++----- 11 files changed, 244 insertions(+), 88 deletions(-) create mode 100644 include/pattern.h diff --git a/carlfw/Kconfig b/carlfw/Kconfig index caa3848..1612973 100644 --- a/carlfw/Kconfig +++ b/carlfw/Kconfig @@ -87,7 +87,7 @@ config CARL9170FW_EXPERIMENTAL config CARL9170FW_PATTERN_GENERATOR def_bool n - prompt "Radar pattern generator" + prompt "Pattern generator" depends on CARL9170FW_EXPERIMENTAL ---help--- With this option enabled, the firmware can generate random diff --git a/carlfw/include/carl9170.h b/carlfw/include/carl9170.h index 26a0975..d12bb98 100644 --- a/carlfw/include/carl9170.h +++ b/carlfw/include/carl9170.h @@ -141,11 +141,11 @@ struct firmware_context_struct { unsigned int queued_bar; -#ifdef CONFIG_CARL9170FW_RADAR - unsigned int soft_radar, - radar_last, +#if defined(CONFIG_CARL9170FW_PATTERN_GENERATOR) + unsigned int soft_pattern, + pattern_last, pattern_index; -#endif /* CONFIG_CARL9170FW_RADAR */ +#endif /* CONFIG_CARL9170FW_PATTERN_GENERATOR */ } wlan; struct { diff --git a/carlfw/include/fwdsc.h b/carlfw/include/fwdsc.h index 6ae6563..2e1d1dd 100644 --- a/carlfw/include/fwdsc.h +++ b/carlfw/include/fwdsc.h @@ -35,9 +35,9 @@ struct carl9170_firmware_descriptor { struct carl9170fw_wol_desc wol; #endif /* CONFIG_CARL9170FW_WOL */ struct carl9170fw_motd_desc motd; -#ifdef CONFIG_CARL9170FW_RADAR - struct carl9170fw_radar_desc radar; -#endif /* CONFIG_CARL9170FW_RADAR */ +#if defined(CONFIG_CARL9170FW_PATTERN_GENERATOR) + struct carl9170fw_pattern_desc pattern; +#endif /* CONFIG_CARL9170FW_PATTERN_GENERATOR */ struct carl9170fw_dbg_desc dbg; struct carl9170fw_last_desc last; } __packed; diff --git a/carlfw/include/pattern_generator.h b/carlfw/include/pattern_generator.h index e08f9fc..98e9c90 100644 --- a/carlfw/include/pattern_generator.h +++ b/carlfw/include/pattern_generator.h @@ -20,8 +20,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef __CARL9170FW_RADAR_H -#define __CARL9170FW_RADAR_H +#ifndef __CARL9170FW_PATTERN_GENERATOR_H +#define __CARL9170FW_PATTERN_GENERATOR_H #include "generated/autoconf.h" #include "types.h" @@ -29,14 +29,14 @@ #include "fwdesc.h" #include "pattern.h" -#if defined(CARL9170FW_PATTERN_GENERATOR) -void radar_pattern_generator(void); +#if defined(CONFIG_CARL9170FW_PATTERN_GENERATOR) +void pattern_generator(void); #else -static inline void radar_pattern_generator(void) +static inline void pattern_generator(void) { } -#endif +#endif /* CONFIG_CARL9170FW_PATTERN_GENERATOR */ -#endif /* __CARL9170FW_RADAR_H */ +#endif /* __CARL9170FW_PATTERN_GENERATOR_H */ diff --git a/carlfw/src/fw.c b/carlfw/src/fw.c index a999e2d..a98b735 100644 --- a/carlfw/src/fw.c +++ b/carlfw/src/fw.c @@ -65,9 +65,9 @@ const struct carl9170_firmware_descriptor __section(fwdsc) __visible carl9170fw_ #ifdef CONFIG_CARL9170FW_WOL BIT(CARL9170FW_WOL) | #endif /* CONFIG_CARL9170FW_WOL */ -#ifdef CONFIG_CARL9170FW_RADAR - BIT(CARL9170FW_RADAR_PATTERN_GENERATOR) | -#endif /* CONFIG_CARL9170FW_RADAR */ +#if defined(CONFIG_CARL9170FW_PATTERN_GENERATOR) + BIT(CARL9170FW_PATTERN_GENERATOR) | +#endif /* CONFIG_CARL9170FW_PATTERN_GENERATOR */ (0)), .miniboot_size = cpu_to_le16(0), @@ -101,12 +101,11 @@ const struct carl9170_firmware_descriptor __section(fwdsc) __visible carl9170fw_ .desc = "Community AR9170 Linux", .release = CARL9170FW_VERSION_GIT), - -#if defined(CARL9170FW_PATTERN_GENERATOR) - FILL(radar, RADAR, - .soft_radar = cpu_to_le32(&fw.wlan.soft_radar), - .num_radars = __CARL9170FW_NUM_RADARS, - .radars = { /* filled by the fwprepare tool */ }, +#if defined(CONFIG_CARL9170FW_PATTERN_GENERATOR) + FILL(pattern, PATTERN, + .soft_pattern = cpu_to_le32(&fw.wlan.soft_pattern), + .num_patterns = __CARL9170FW_NUM_PATTERNS, + .patterns = { /* filled by the fwprepare tool */ }, ), #endif /* CONFIG_CARL9170FW_RADAR */ diff --git a/carlfw/src/main.c b/carlfw/src/main.c index fc44d50..b24d905 100644 --- a/carlfw/src/main.c +++ b/carlfw/src/main.c @@ -127,7 +127,7 @@ static void __noreturn main_loop(void) tally_update(); - radar_pattern_generator(); + pattern_generator(); } } diff --git a/carlfw/src/pattern_generator.c b/carlfw/src/pattern_generator.c index 79cad0b..58119de 100644 --- a/carlfw/src/pattern_generator.c +++ b/carlfw/src/pattern_generator.c @@ -22,33 +22,35 @@ #include "carl9170.h" #include "pattern_generator.h" +#include "fwdsc.h" +#include "timer.h" -#if defined(CARL9170FW_PATTERN_GENERATOR) +#if defined(CONFIG_CARL9170FW_PATTERN_GENERATOR) -void radar_pattern_generator(void) +void pattern_generator(void) { if (fw.phy.state == CARL9170_PHY_ON) { - if (likely(fw.wlan.soft_radar == NO_RADAR || - fw.wlan.soft_radar >= __CARL9170FW_NUM_RADARS)) + if (likely(fw.wlan.soft_pattern == NO_PATTERN || + fw.wlan.soft_pattern >= __CARL9170FW_NUM_PATTERNS)) return; - const struct radar_info *radar = &radars[fw.wlan.soft_radar]; - if (radar->pulses >= fw.wlan.pattern_index) { + const struct pattern_info *pattern = &patterns[fw.wlan.soft_pattern]; + if (pattern->pulses >= fw.wlan.pattern_index) { fw.wlan.pattern_index = 0; } - if (radar->pulses > fw.wlan.pattern_index) { - const struct radar_info_pattern *pattern = &radar->pattern[fw.wlan.pattern_index]; - if (is_after_usecs(fw.wlan.radar_last, pattern->pulse_interval)) { - fw.wlan.radar_last = get_clock_counter(); - set(0x1C3BC0, pattern->pulse_pattern); - set(0x1C3BBC, pattern->pulse_mode); - udelay(pattern->pulse_width); - set(0x1C3BBC, ~pattern->pulse_mode); + if (pattern->pulses > fw.wlan.pattern_index) { + const struct pattern_pulse_info *ppi = &pattern->pattern[fw.wlan.pattern_index]; + if (is_after_usecs(fw.wlan.pattern_last, ppi->pulse_interval)) { + fw.wlan.pattern_last = get_clock_counter(); + set(0x1C3BC0, ppi->pulse_pattern); + set(0x1C3BBC, ppi->pulse_mode); + udelay(ppi->pulse_width); + set(0x1C3BBC, ~ppi->pulse_mode); fw.wlan.pattern_index++; } } } } -#endif /* CONFIG_CARL9170FW_RADAR */ +#endif /* CONFIG_CONFIG_CARL9170FW_RADAR */ diff --git a/include/pattern.h b/include/pattern.h new file mode 100644 index 0000000..ba9e88f --- /dev/null +++ b/include/pattern.h @@ -0,0 +1,156 @@ +/* + * carl9170 firmware - used by the ar9170 wireless device + * + * Pattern pulse definitions + * + * Copyright 2012 Christian Lamparter + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __CARL9170FW_PATTERN_H +#define __CARL9170FW_PATTERN_H + +#include "types.h" +#include "compiler.h" +#include "fwdesc.h" + +enum PATTERN_TYPE { + NO_PATTERN = 0, + ONE_KHZ, + TEN_KHZ, + + ONE_TWO_KHZ, + + FCC1, + FCC4, + + ETSIFIXED, + + /* keep last */ + __CARL9170FW_NUM_PATTERNS +}; + +struct pattern_pulse_info { + unsigned int pulse_width; + unsigned int pulse_interval; + uint32_t pulse_pattern; + uint32_t pulse_mode; +}; + +struct pattern_info { + unsigned int pulses; + const struct pattern_pulse_info *pattern; +}; + +static const struct pattern_pulse_info pattern_NO_PATTERN[0] = { }; +static const struct pattern_pulse_info pattern_ONE_KHZ[] = { + { + .pulse_width = 1, + .pulse_interval = 1000, + .pulse_pattern = 0xa7438080, + .pulse_mode = 0x5f01, + }, +}; + +static const struct pattern_pulse_info pattern_TEN_KHZ[] = { + { + .pulse_width = 1, + .pulse_interval = 100, + .pulse_pattern = 0x436f0001, + .pulse_mode = 0x5f01, + }, +}; + +static const struct pattern_pulse_info pattern_ONE_TWO_KHZ[] = { + { + .pulse_width = 1, + .pulse_interval = 1000, + .pulse_pattern = 0xa7438080, + .pulse_mode = 0x5f01, + }, + + { + .pulse_width = 10, + .pulse_interval = 500, + .pulse_pattern = 0xa7431001, + .pulse_mode = 0x5f01, + }, +}; + +/* + * Data taken from: + * + */ + +/* FCC Test Signal 1 - 1us pulse, 1428 us interval */ +static const struct pattern_pulse_info pattern_FCC1[] = { + { + .pulse_width = 1, + .pulse_interval = 1428, + .pulse_pattern = 0xa7438080, + .pulse_mode = 0x5f01, + }, +}; + +/* FCC Test Signal 4 - 11-20us pulse, 200-500 us interval */ +static const struct pattern_pulse_info pattern_FCC4[] = { + { + .pulse_width = 11, + .pulse_interval = 200, + .pulse_pattern = 0xf3128008, + .pulse_mode = 0x5f01, + }, +}; + +/* ETSI Test Signal 1 (Fixed) - 1us Pulse, 750 us interval */ +static const struct pattern_pulse_info pattern_ETSIFIXED[] = { + { + .pulse_width = 1, + .pulse_interval = 750, + .pulse_pattern = 0x8a5f8080, + .pulse_mode = 0x5f01, + }, +}; + + +#define ADD_RADAR(name) [name] = { .pulses = ARRAY_SIZE(pattern_## name), .pattern = pattern_## name } + +static const struct pattern_info patterns[__CARL9170FW_NUM_PATTERNS] = { + ADD_RADAR(NO_PATTERN), + ADD_RADAR(ONE_KHZ), + ADD_RADAR(TEN_KHZ), + ADD_RADAR(ONE_TWO_KHZ), + ADD_RADAR(FCC1), + ADD_RADAR(FCC4), + ADD_RADAR(ETSIFIXED), +}; + +#define MAP_ENTRY(idx) [idx] = { .index = idx, .name = # idx , } +#define NAMED_MAP_ENTRY(idx, named) [idx] = {.index = idx, .name = named, } + +static const struct carl9170fw_pattern_map_entry pattern_names[__CARL9170FW_NUM_PATTERNS] = { + MAP_ENTRY(NO_PATTERN), + MAP_ENTRY(ONE_KHZ), + MAP_ENTRY(TEN_KHZ), + MAP_ENTRY(ONE_TWO_KHZ), + + MAP_ENTRY(FCC1), + MAP_ENTRY(FCC4), + + MAP_ENTRY(ETSIFIXED), +}; + +#endif /* __CARL9170FW_PATTERN_H */ diff --git a/include/shared/fwdesc.h b/include/shared/fwdesc.h index f73373e..424a4e7 100644 --- a/include/shared/fwdesc.h +++ b/include/shared/fwdesc.h @@ -78,8 +78,8 @@ enum carl9170fw_feature_list { /* HW (ANI, CCA, MIB) tally counters */ CARL9170FW_HW_COUNTERS, - /* Radar pattern generator */ - CARL9170FW_RADAR_PATTERN_GENERATOR, + /* Pattern generator */ + CARL9170FW_PATTERN_GENERATOR, /* Firmware will pass BA when BARs are queued */ CARL9170FW_RX_BA_FILTER, @@ -95,7 +95,7 @@ enum carl9170fw_feature_list { #define CHK_MAGIC "CHK\0" #define TXSQ_MAGIC "TXSQ" #define WOL_MAGIC "WOL\0" -#define RADAR_MAGIC "RDR\0" +#define PATTERN_MAGIC "RDR\0" #define LAST_MAGIC "LAST" #define CARL9170FW_SET_DAY(d) (((d) - 1) % 31) @@ -180,24 +180,23 @@ struct carl9170fw_dbg_desc { #define CARL9170FW_DBG_DESC_SIZE \ (sizeof(struct carl9170fw_dbg_desc)) -#define CARL9170FW_RADAR_MAP_NAME_LEN 15 -struct carl9170fw_radar_map_entry { +#define CARL9170FW_PATTERN_MAP_NAME_LEN 15 +struct carl9170fw_pattern_map_entry { u8 index; - char name[CARL9170FW_RADAR_MAP_NAME_LEN]; + char name[CARL9170FW_PATTERN_MAP_NAME_LEN]; } __packed; -#define CARL9170FW_RADAR_DESC_MIN_VER 1 -#define CARL9170FW_RADAR_DESC_CUR_VER 1 -struct carl9170fw_radar_desc { +#define CARL9170FW_PATTERN_DESC_MIN_VER 1 +#define CARL9170FW_PATTERN_DESC_CUR_VER 1 +struct carl9170fw_pattern_desc { struct carl9170fw_desc_head head; - __le32 soft_radar; - __le32 num_radars; - struct carl9170fw_radar_map_entry radars[0]; - /* Put your debugging definitions here */ + __le32 soft_pattern; + __le32 num_patterns; + struct carl9170fw_pattern_map_entry patterns[0]; } __packed; -#define CARL9170FW_RADAR_DESC_SIZE \ - (sizeof(struct carl9170fw_radar_desc)) +#define CARL9170FW_PATTERN_DESC_SIZE \ + (sizeof(struct carl9170fw_pattern_desc)) #define CARL9170FW_CHK_DESC_MIN_VER 1 #define CARL9170FW_CHK_DESC_CUR_VER 2 diff --git a/tools/src/fwinfo.c b/tools/src/fwinfo.c index b2441f7..3547041 100644 --- a/tools/src/fwinfo.c +++ b/tools/src/fwinfo.c @@ -69,7 +69,7 @@ static const struct feature_list known_otus_features_v1[] = { CHECK_FOR_FEATURE(CARL9170FW_FIXED_5GHZ_PSM), CHECK_FOR_FEATURE(CARL9170FW_HW_COUNTERS), CHECK_FOR_FEATURE(CARL9170FW_RX_BA_FILTER), - CHECK_FOR_FEATURE(CARL9170FW_RADAR_PATTERN_GENERATOR), + CHECK_FOR_FEATURE(CARL9170FW_PATTERN_GENERATOR), }; static void check_feature_list(const struct carl9170fw_desc_head *head, @@ -208,18 +208,18 @@ static void show_chk_desc(const struct carl9170fw_desc_head *head, le32_to_cpu(chk->fw_crc32)); } -static void show_radar_desc(const struct carl9170fw_desc_head *head, +static void show_pattern_desc(const struct carl9170fw_desc_head *head, struct carlfw *fw __unused) { - const struct carl9170fw_radar_desc *radar = (const void *) head; - const struct carl9170fw_radar_map_entry *map = radar->radars; - int map_entries = (head->length - sizeof(*radar)) / sizeof(*map); + const struct carl9170fw_pattern_desc *pattern = (const void *) head; + const struct carl9170fw_pattern_map_entry *map = pattern->patterns; + int map_entries = (head->length - sizeof(*pattern)) / sizeof(*map); int i; - fprintf(stdout, "\tRadar index register: %08x\n", - le32_to_cpu(radar->soft_radar)); - fprintf(stdout, "\tNumber of supported radar patterns: %08x\n", - le32_to_cpu(radar->num_radars)); + fprintf(stdout, "\tPattern index register: %08x\n", + le32_to_cpu(pattern->soft_pattern)); + fprintf(stdout, "\tNumber of supported patterns: %08x\n", + le32_to_cpu(pattern->num_patterns)); for (i = 0; i < map_entries; i++) { fprintf(stdout, "\t\tindex:0x%x, description:%s\n", @@ -257,7 +257,7 @@ static const struct { ADD_HANDLER(FIX, show_fix_desc), ADD_HANDLER(CHK, show_chk_desc), ADD_HANDLER(WOL, show_wol_desc), - ADD_HANDLER(RADAR, show_radar_desc), + ADD_HANDLER(PATTERN, show_pattern_desc), ADD_HANDLER(LAST, show_last_desc), }; diff --git a/tools/src/fwprepare.c b/tools/src/fwprepare.c index eb8a5f8..7bf3542 100644 --- a/tools/src/fwprepare.c +++ b/tools/src/fwprepare.c @@ -43,10 +43,10 @@ static void checksum_help(void) fprintf(stderr, "\n"); } -static int add_radars(struct carlfw *fw) { +static int add_patterns(struct carlfw *fw) { const struct carl9170fw_otus_desc *otus_desc = NULL; - struct carl9170fw_radar_desc *radar_desc = NULL; - int radars_to_add; + struct carl9170fw_pattern_desc *pattern_desc = NULL; + int to_add; otus_desc = carlfw_find_desc(fw, (uint8_t *) OTUS_MAGIC, sizeof(*otus_desc), @@ -56,46 +56,46 @@ static int add_radars(struct carlfw *fw) { return -1; } - if (!carl9170fw_supports(otus_desc->feature_set, CARL9170FW_RADAR_PATTERN_GENERATOR)) { + if (!carl9170fw_supports(otus_desc->feature_set, CARL9170FW_PATTERN_GENERATOR)) { return 0; } - radar_desc = carlfw_find_desc(fw, (uint8_t *) RADAR_MAGIC, - sizeof(*radar_desc), - CARL9170FW_RADAR_DESC_CUR_VER); + pattern_desc = carlfw_find_desc(fw, (uint8_t *) PATTERN_MAGIC, + sizeof(*pattern_desc), + CARL9170FW_PATTERN_DESC_CUR_VER); - if (!radar_desc) { - fprintf(stderr, "Firmware has radar pattern feature set, but " - "can't find a valid radar descriptor\n"); + if (!pattern_desc) { + fprintf(stderr, "Firmware has the pattern generator feature set, but " + "can't find a valid pattern descriptor\n"); return 0; } - radars_to_add = radar_desc->num_radars - - ((radar_desc->head.length - sizeof(*radar_desc)) / - sizeof(struct carl9170fw_radar_map_entry)); - if (radars_to_add == 0) { + to_add = pattern_desc->num_patterns - + ((pattern_desc->head.length - sizeof(*pattern_desc)) / + sizeof(struct carl9170fw_pattern_map_entry)); + if (to_add == 0) { /* been there, done that */ return 0; } - if (radars_to_add == __CARL9170FW_NUM_RADARS) { - struct carl9170fw_radar_desc *tmp; + if (to_add == __CARL9170FW_NUM_PATTERNS) { + struct carl9170fw_pattern_desc *tmp; unsigned int len, map_len; - map_len = sizeof(struct carl9170fw_radar_map_entry) * radars_to_add; + map_len = sizeof(struct carl9170fw_pattern_map_entry) * to_add; len = sizeof(*tmp) + map_len; tmp = malloc(len); if (!tmp) return -ENOMEM; - radar_desc = carlfw_desc_mod_len(fw, &radar_desc->head, map_len); - if (IS_ERR_OR_NULL(radar_desc)) - return (int) PTR_ERR(radar_desc); + pattern_desc = carlfw_desc_mod_len(fw, &pattern_desc->head, map_len); + if (IS_ERR_OR_NULL(pattern_desc)) + return (int) PTR_ERR(pattern_desc); - memcpy(&radar_desc->radars, radar_names, map_len); + memcpy(&pattern_desc->patterns, pattern_names, map_len); return 0; } else { - fprintf(stderr, "don't know what you did, but congrats you broke it!"); + fprintf(stderr, "No idea, what you just did. But congrats: you broke it!"); return -EINVAL; } } @@ -127,7 +127,7 @@ int main(int argc, char *args[]) goto out; } - err = add_radars(fw); + err = add_patterns(fw); if (err) goto out; -- 2.31.1